Commit Graph

1223776 Commits

Author SHA1 Message Date
Yabin Li f1897b7bd8 newfeature: crypto: ccp: Support SM4 algorithm for hygon ccp.
In order to add SM4 driver for hygon ccp, relating to sm4 mode of
ecb/ecb_hs, cbc/cbc_hs, cfb, ofb and ctr

Signed-off-by: Yabin Li <liyabin@hygon.cn>
Signed-off-by: yangdepei <yangdepei@hygon.cn>
2024-04-12 21:02:07 +08:00
Yabin Li 46f6d0dbdb newfeature: crypto: ccp: Support SM3 algorithm for hygon ccp.
In order to add SM3 driver for hygon ccp, include sm3-hmac.

Signed-off-by: Yabin Li <liyabin@hygon.cn>
Signed-off-by: yangdepei <yangdepei@hygon.cn>
2024-04-12 21:02:07 +08:00
Yabin Li 520f4bfa51 newfeature: crypto: ccp: Support SM2 algorithm for hygon ccp.
In order to add SM2 driver for hygon ccp, relating to
SM2_sign, SM2_verify, SM2_encrypt and SM2_decrypt.

Signed-off-by: Yabin Li <liyabin@hygon.cn>
Signed-off-by: yangdepei <yangdepei@hygon.cn>
2024-04-12 21:02:07 +08:00
Jianping Liu fc5e8fd2fb backport some bugfixes on kunpeng
Merge pull request !132 from hongrongxuan/next
2024-04-12 21:01:07 +08:00
Xiang Chen 1a96b39cbc scsi: sd: try more retries of START_STOP when resuming scsi device
driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9D9AE
CVE: NA

----------------------------------------------------------------------

When sending START_STOP commands to resume scsi_device, it may be
interrupted by exception operations such as host reset or FLR.
Once the command of START_STOP is failed, the runtime_status of
scsi device will be error and it is difficult for user to recover it.
So try more retries to increase robustness as the process of
command SYNCHRONIZE_CACHE in function sd_sync_cache() when suspending
scsi device.

Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: xiabing <xiabing12@h-partners.com>
Signed-off-by: xuezihao <xuezihao@huawei.com>
2024-04-12 21:00:46 +08:00
Zhang Zekun a4ae0ae208 iommu/iova: avoid softlockup in fq_flush_timeout
hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8ZE0I
CVE: NA

--------------------------------

There is a softlockup undering cpu pressure test.
...
pc : _raw_spin_unlock_irqrestore+0x14/0x78
lr : fq_flush_timeout+0x94/0x118
...
Call trace:
 _raw_spin_unlock_irqrestore+0x14/0x78
 call_timer_fn+0x3c/0x1d0
 expire_timers+0xcc/0x190
 run_timer_softirq+0xfc/0x268
 __do_softirq+0x128/0x3dc
 ____do_softirq+0x18/0x30
 call_on_irq_stack+0x24/0x30
 do_softirq_own_stack+0x24/0x38
 irq_exit_rcu+0xc0/0xe8
 el1_interrupt+0x48/0xc0
 el1h_64_irq_handler+0x18/0x28
 el1h_64_irq+0x78/0x80
 __schedule+0xf28/0x12a0
 schedule+0x3c/0x108
 schedule_timeout+0xa0/0x1d0
 pktgen_thread_worker+0x1180/0x15d0
 kthread+0x120/0x130
 ret_from_fork+0x10/0x20

This is because the timer callback fq_flush_timeout may run more than
10ms, and timer may be processed continuously in the softirq so trigger
softlockup. We can use work to deal with fq_ring_free for each cpu which
may take long time, that to avoid triggering softlockup.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Signed-off-by: Zihao Xue <xuezihao@huawei.com>
2024-04-12 21:00:46 +08:00
Niklas Schnelle c441d1bac9 iommu/dma: Allow a single FQ in addition to per-CPU FQs
mainline inclusion
from mainline-v6.7-rc1
commit 32d5bc8b09c7cc48c511809e7c3b1755c7ecc5fa
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I938E2
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=32d5bc8b09c7cc48c511809e7c3b1755c7ecc5fa

--------------------------------

In some virtualized environments, including s390 paged memory guests,
IOTLB flushes are used to update IOMMU shadow tables. Due to this, they
are much more expensive than in typical bare metal environments or
non-paged s390 guests. In addition they may parallelize poorly in
virtualized environments. This changes the trade off for flushing IOVAs
such that minimizing the number of IOTLB flushes trumps any benefit of
cheaper queuing operations or increased paralellism.

In this scenario per-CPU flush queues pose several problems. Firstly
per-CPU memory is often quite limited prohibiting larger queues.
Secondly collecting IOVAs per-CPU but flushing via a global timeout
reduces the number of IOVAs flushed for each timeout especially on s390
where PCI interrupts may not be bound to a specific CPU.

Let's introduce a single flush queue mode that reuses the same queue
logic but only allocates a single global queue. This mode is selected by
dma-iommu if a newly introduced .shadow_on_flush flag is set in struct
dev_iommu. As a first user the s390 IOMMU driver sets this flag during
probe_device. With the unchanged small FQ size and timeouts this setting
is worse than per-CPU queues but a follow up patch will make the FQ size
and timeout variable. Together this allows the common IOVA flushing code
to more closely resemble the global flush behavior used on s390's
previous internal DMA API implementation.

Link: https://lore.kernel.org/all/9a466109-01c5-96b0-bf03-304123f435ee@arm.com/
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> #s390
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Link: https://lore.kernel.org/r/20230928-dma_iommu-v13-5-9e5fc4dacc36@linux.ibm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Jason Zeng <jason.zeng@intel.com>
Signed-off-by: Zihao Xue <xuezihao@huawei.com>
2024-04-12 21:00:46 +08:00
wangwudi f3844ad046 irqchip: gic-v3: Collection table support muti pages
driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7CX6S
CVE: NA

--------------------------------------------------------------------------

Only one page is allocated to the collection table.
Recalculate the page number of collection table based on the number of
CPUs.

Signed-off-by: wangwudi <wangwudi@hisilicon.com>
Signed-off-by: Zihao Xue <xuezihao@huawei.com>
2024-04-12 21:00:42 +08:00
Devyn Liu ccf99c1357 gpio: hisi: Fix format specifier
The hisi_gpio->line is unsigned int so the format specifier
should have been %u not %d.

Signed-off-by: Devyn Liu <liudingyuan@huawei.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Zihao Xue <xuezihao@huawei.com>
2024-04-12 21:00:42 +08:00
Longfang Liu 2dd5feb610 xhci:fix USB xhci controller issue
driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7ZPUX
CVE: NA

----------------------------------------------------------------------

When the current HiSilicon USB xhci controller formats the faulty
U disk, it will trigger a controller exception error. This will
cause errors in the control logic of the xhci controller and
driver software. In the end, all USB devices on the xhci controller
cannot be used.

By introducing a noop command operation, restore the logic of the
xhci controller and driver software, and restore all USB devices
on the xhci controller to normal.

Signed-off-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: JiangShui Yang <yangjiangshui@h-partners.com>
Signed-off-by: Zihao Xue <xuezihao@huawei.com>
2024-04-12 21:00:42 +08:00
Jianping Liu 373d1065cc Loogarch:add steal time hypcall software breakpoint pmu support for loongarch kvm
Merge pull request !135 from lixianglai/next
2024-04-12 20:59:31 +08:00
Song Gao 5773e05369 LoongArch: KVM: Add PMU support
Upstream: no

Add PMU device emulation

Signed-off-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:07 +08:00
Bibo Mao ec943318bc LoongArch: Add steal time support in guest side
Upstream: no

Percpu struct kvm_steal_time is added here, its size is 64 bytes and
also defined as 64 bytes, so that the whole structure is in one physical
page.

When vcpu is onlined, function pv_register_steal_time() is called. This
function will pass physical address of struct kvm_steal_time and tells
hypervisor to enable steal time. When vcpu is offline, physical address
is set as 0 and tells hypervisor to disable steal time.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:07 +08:00
Bibo Mao 64bbfb6b70 LoongArch: KVM: Add steal time support in kvm side
Upstream: no

Steal time feature is added here in kvm side, VM can search supported
features provided by KVM hypervisor, feature KVM_FEATURE_STEAL_TIME
is added here. Like x86, steal time structure is saved in guest memory,
one hypercall function KVM_HCALL_FUNC_NOTIFY is added to notify KVM to
enable the feature.

One cpu attr ioctl command KVM_LOONGARCH_VCPU_PVTIME_CTRL is added to
save and restore base address of steal time structure when VM is migrated.

Since it needs hypercall instruction emulation handling, and it is
dependent on this patchset:
https://lore.kernel.org/all/20240201031950.3225626-1-maobibo@loongson.cn/

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao 314b2aad2a irqchip/loongson-eiointc: Add virt extension support
Upstream: no

With virt eiointc, interrupt can be routed to 256 vcpus

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao e15aaf69eb LoongArch: KVM: Add software breakpoint support
Upstream: no

When VM runs in kvm mode, system will not exit to host mode if
executing general software breakpoint instruction, one trap exception
happens in guest mode rather than host mode. In order to debug guest
kernel on host side, one mechanism should be used to let vm exit to
host mode.

Here one special hypercall code is used for software breakpoint usage,
vm exists to host mode and kvm hypervisor identifies the special hypercall
code and sets exit_reason with KVM_EXIT_DEBUG, and then let qemu handle it.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao 1b2d29d1d8 Documentation: KVM: Add hypercall for LoongArch
Upstream: no

Add documentation topic for using pv_virt when running as a guest
on KVM hypervisor.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao 05e7e13eb9 LoongArch: Add pv ipi support on guest kernel side
Upstream: no

PARAVIRT option and pv ipi is added on guest kernel side, function
pv_ipi_init() is to add ipi sending and ipi receiving hooks. This function
firstly checks whether system runs on VM mode. If kernel runs on VM mode,
it will call function kvm_para_available() to detect current hypervirsor
type. Now only KVM type detection is supported, the paravirt function can
work only if current hypervisor type is KVM, since there is only KVM
supported on LoongArch now.

PV IPI uses virtual IPI sender and virtual IPI receiver function. With
virutal IPI sender, ipi message is stored in DDR memory rather than
emulated HW. IPI multicast is supported, and 128 vcpus can received IPIs
at the same time like X86 KVM method. Hypercall method is used for IPI
sending.

With virtual IPI receiver, HW SW0 is used rather than real IPI HW. Since
VCPU has separate HW SW0 like HW timer, there is no trap in IPI interrupt
acknowledge. And IPI message is stored in DDR, no trap in get IPI message.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao fe60041dc6 LoongArch: KVM: Add pv ipi support on kvm side
Upstream: no

On LoongArch system, ipi hw uses iocsr registers, there is one iocsr
register access on ipi sending, and two iocsr access on ipi receiving
which is ipi interrupt handler. On VM mode all iocsr accessing will
cause VM to trap into hypervisor. So with one ipi hw notification
there will be three times of trap.

PV ipi is added for VM, hypercall instruction is used for ipi sender,
and hypervisor will inject SWI to destination vcpu. During SWI interrupt
handler, only estat CSR register is written to clear irq. Estat CSR
register access will not trap into hypervisor. So with pv ipi supported,
there is one trap with pv ipi sender, and no trap with ipi receiver,
there is only one trap with ipi notification.

Also this patch adds ipi multicast support, the method is similar with
x86. With ipi multicast support, ipi notification can be sent to at most
128 vcpus at one time. It reduces trap times into hypervisor greatly.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao 2c592098d4 LoongArch: KVM: Add vcpu search support from physical cpuid
Upstream: no

Physical cpuid is used for interrupt routing for irqchips such as
ipi/msi/extioi interrupt controller. And physical cpuid is stored
at CSR register LOONGARCH_CSR_CPUID, it can not be changed once vcpu
is created and physical cpuid of two vcpus cannot be the same.

Different irqchips have different size declaration about physical cpuid,
max cpuid value for CSR LOONGARCH_CSR_CPUID on 3A5000 is 512, max cpuid
supported by IPI hardware is 1024, 256 for extioi irqchip, and 65536
for MSI irqchip.

The smallest value from all interrupt controllers is selected now,
and the max cpuid size is defines as 256 by KVM which comes from
extioi irqchip.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao 18d346d3df LoongArch: KVM: Add cpucfg area for kvm hypervisor
Upstream: no

Instruction cpucfg can be used to get processor features. And there
is trap exception when it is executed in VM mode, and also it is
to provide cpu features to VM. On real hardware cpucfg area 0 - 20
is used.  Here one specified area 0x40000000 -- 0x400000ff is used
for KVM hypervisor to privide PV features, and the area can be extended
for other hypervisors in future. This area will never be used for
real HW, it is only used by software.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:06 +08:00
Bibo Mao b85f967ad1 LoongArch: KVM: Add hypercall instruction emulation support
Upstream: no

On LoongArch system, there is hypercall instruction special for
virtualization. When system executes this instruction on host side,
there is illegal instruction exception reported, however it will
trap into host when it is executed in VM mode.

When hypercall is emulated, A0 register is set with value
KVM_HCALL_INVALID_CODE, rather than inject EXCCODE_INE invalid
instruction exception. So VM can continue to executing the next code.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao 1bd43d0ba5 LoongArch/smp: Refine some ipi functions on LoongArch platform
Upstream: no

It is code refine about ipi handling on LoongArch platform, there are
three modifications.
1. Add generic function get_percpu_irq(), replacing some percpu irq
functions such as get_ipi_irq()/get_pmc_irq()/get_timer_irq() with
get_percpu_irq().

2. Change definition about parameter action called by function
loongson_send_ipi_single() and loongson_send_ipi_mask(), and it is
defined as decimal encoding format at ipi sender side. Normal decimal
encoding is used rather than binary bitmap encoding for ipi action, ipi
hw sender uses decimal encoding code, and ipi receiver will get binary
bitmap encoding, the ipi hw will convert it into bitmap in ipi message
buffer.

3. Add structure smp_ops on LoongArch platform so that pv ipi can be used
later.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao e3cb42413a LoongArch: KVM: Set reserved bits as zero in CPUCFG
commit aebd3bd586c6 ("LoongArch: KVM: Set reserved bits as zero in CPUCFG")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

Supported CPUCFG information comes from function _kvm_get_cpucfg_mask().
A bit should be zero if it is reserved by HW or if it is not supported
by KVM.

Also LoongArch software page table walk feature defined in CPUCFG2_LSPW
is supported by KVM, it should be enabled by default.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao 4743fe8152 LoongArch: KVM: Do not restart SW timer when it is expired
commit f66228053e42 ("LoongArch: KVM: Do not restart SW timer when it is expired")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

LoongArch VCPUs have their own separate HW timers. SW timer is to wake
up blocked vcpu thread, rather than HW timer emulation. When blocking
vcpu scheduled out, SW timer is used to wakeup blocked vcpu thread and
injects timer interrupt. It does not care about whether guest timer is
in period mode or oneshot mode, and SW timer needs not to be restarted
since vcpu has been woken.

This patch does not restart SW timer when it is expired.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao 6853303efb LoongArch: KVM: Start SW timer only when vcpu is blocking
commit 8bc15d02d5fd ("LoongArch: KVM: Start SW timer only when vcpu is blocking")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

SW timer is enabled when vcpu thread is scheduled out, and it is to wake
up vcpu from blocked queue. If vcpu thread is scheduled out but is not
blocked, such as it is preempted by other threads, it is not necessary
to enable SW timer. Since vcpu thread is still on running queue if it is
preempted and SW timer is only to wake up vcpu on blocking queue, so SW
timer is not useful in this situation.

This patch enables SW timer only when vcpu is scheduled out and is
blocking.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao cf3632a170 irqchip/loongson-eiointc: Remove explicit interrupt affinity restore on resume
commit 83c0708719f7 ("irqchip/loongson-eiointc: Remove explicit interrupt affinity restore on resume")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

During suspend all CPUs except CPU0 are hot-unpluged and all active
interrupts are migrated to CPU0.

On resume eiointc_router_init() affines all interrupts to CPU0, so the
subsequent explicit interrupt affinity restore is redundant.

Remove it.

[ tglx: Rewrote changelog ]

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240130082722.2912576-4-maobibo@loongson.cn

--------------------------------

During suspend and resume, CPUs except CPU0 can be hot-unpluged and IRQs
will be migrated to CPU0. So it is not necessary to restore irq affinity
for eiointc irq controller when system resumes. This patch removes this
piece of code about irq affinity restoring in function eiointc_resume().

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Bibo Mao bd31d9aed3 irqchip/loongson-eiointc: Skip handling if there is no pending interrupt
commit 3eece72ded7f ("irqchip/loongson-eiointc: Skip handling if there is no pending interrupt")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

It is one simple optimization in the interrupt dispatch function
eiointc_irq_dispatch(). There are 256 IRQs supported for eiointc on
Loongson-3A5000 and Loongson-2K2000 platform, 128 IRQs on Loongson-2K0500
platform, eiointc irq handler reads the bitmap and find pending irqs
when irq happens. So there are several consecutive iocsr_read64
operations for the all bits to find all pending irqs. If the pending
bitmap is zero, it means that there is no pending irq for the this
irq bitmap range, we can skip handling to avoid some useless operations
such as clearing hw ISR.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-04-12 20:59:05 +08:00
Jianping Liu dbd857493a Add Phytium Display Engine support to the OC-6.6
Merge pull request !131 from lishuo/newDC-6.6
2024-04-12 20:57:37 +08:00
lishuo 723ea0b79e DRM: Phytium display DRM doc
phytium inclusion
category: feature
CVE: NA

--------------------------------------------------
    This is Phytium Display Engine support,DC/DP driver patch.

Signed-off-by: Yang Xun <yangxun@phytium.com.cn>
Signed-off-by: Chen Baozi <chenbaozi@phytium.com.cn>
Signed-off-by: lishuo <lishuo@phytium.com.cn>
2024-04-12 20:57:17 +08:00
lishuo 807eac186d DRM: Phytium display DRM driver
phytium inclusion
category: feature
CVE: NA

--------------------------------------------------

    This is Phytium Display Engine support,DC/DP driver patch.

Signed-off-by: Yang Xun <yangxun@phytium.com.cn>
Signed-off-by: Chen Baozi <chenbaozi@phytium.com.cn>
Signed-off-by: lishuo <lishuo@phytium.com.cn>
2024-04-12 20:57:17 +08:00
Jianping Liu a3c2718927 Intel: Backport QuickAssist Technology(QAT) in-tree driver
Merge pull request !129 from AllenShi/next-6.6-qat-gnr-srf
2024-04-12 20:56:19 +08:00
aurelianliu c2cc162e4e drivers/thirdparty: add drivers/thirdparty framework
add thridparty dir

Signed-off-by: aurelianliu <aurelianliu@tencent.com>
2024-04-12 20:55:43 +08:00
Aichun Shi a201060c8c x86: configs: Enable Intel QAT_4XXX as kernel module
Upstream: no

Intel-SIG: no upstream ("x86: configs: Enable Intel QAT_4XXX as kernel module")
Backport to support Intel QAT in-tree driver

Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:43 +08:00
Damian Muszynski 427a913fcb crypto: qat - make ring to service map common for QAT GEN4
commit ed3d95fe788d ("crypto: qat - make ring to service map common for QAT GEN4") upstream

The function get_ring_to_svc_map() is present in both 420xx and
4xxx drivers. Rework the logic to make it generic to GEN4 devices
and move it to qat_common/adf_gen4_hw_data.c.

Intel-SIG: commit ed3d95fe788d ("crypto: qat - make ring to service map common for QAT GEN4)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:43 +08:00
Damian Muszynski 38083cbe23 crypto: qat - fix ring to service map for dcc in 420xx
commit a20a6060e0dd ("crypto: qat - fix ring to service map for dcc in 420xx") upstream

If a device is configured for data compression chaining (dcc), half of the
engines are loaded with the symmetric crypto image and the rest are loaded
with the compression image.
However, in such configuration all rings can handle compression requests.

Fix the ring to service mapping so that when a device is configured for
dcc, the ring to service mapping reports that all rings in a bank can
be used for compression.

Intel-SIG: commit a20a6060e0dd ("crypto: qat - fix ring to service map for dcc in 420xx)"
Backport to support Intel QAT in-tree driver

Fixes: fcf60f4bcf54 ("crypto: qat - add support for 420xx devices")
Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:43 +08:00
Damian Muszynski a35f34d621 crypto: qat - fix ring to service map for dcc in 4xxx
commit df018f82002a ("crypto: qat - fix ring to service map for dcc in 4xxx") upstream

If a device is configured for data compression chaining (dcc), half of the
engines are loaded with the symmetric crypto image and the rest are loaded
with the compression image.
However, in such configuration all rings can handle compression requests.

Fix the ring to service mapping so that when a device is configured for
dcc, the ring to service mapping reports that all rings in a bank can
be used for compression.

Intel-SIG: commit df018f82002a ("crypto: qat - fix ring to service map for dcc in 4xxx)"
Backport to support Intel QAT in-tree driver

Fixes: a238487f7965 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin ffa9080a27 crypto: qat - fix comment structure
commit bca79b9f5639 ("crypto: qat - fix comment structure") upstream

Move comment description to the same line as the function name.

This is to fix the following warning when compiling the QAT driver
using the clang compiler with CC=clang W=2:
    drivers/crypto/intel/qat/qat_common/qat_crypto.c:108: warning: missing initial short description on line:
     * qat_crypto_vf_dev_config()

Intel-SIG: commit bca79b9f5639 ("crypto: qat - fix comment structure)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin 54aa0cd588 crypto: qat - remove unnecessary description from comment
commit ff391345141e ("crypto: qat - remove unnecessary description from comment") upstream

Remove extra description from comments as it is not required.

This is to fix the following warning when compiling the QAT driver
using the clang compiler with CC=clang W=2:
    drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c:65: warning: contents before sections
    drivers/crypto/intel/qat/qat_common/adf_isr.c:380: warning: contents before sections
    drivers/crypto/intel/qat/qat_common/adf_vf_isr.c:298: warning: contents before sections

Intel-SIG: commit ff391345141e ("crypto: qat - remove unnecessary description from comment)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin 88d6133c71 crypto: qat - remove double initialization of value
commit a66cf93ab338 ("crypto: qat - remove double initialization of value") upstream

Remove double initialization of the reg variable.

This is to fix the following warning when compiling the QAT driver
using clang scan-build:
    drivers/crypto/intel/qat/qat_common/adf_gen4_ras.c:1010:6: warning: Value stored to 'reg' during its initialization is never read [deadcode.DeadStores]
     1010 |         u32 reg = ADF_CSR_RD(csr, ADF_GEN4_SSMCPPERR);
          |             ^~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/crypto/intel/qat/qat_common/adf_gen4_ras.c:1109:6: warning: Value stored to 'reg' during its initialization is never read [deadcode.DeadStores]
     1109 |         u32 reg = ADF_CSR_RD(csr, ADF_GEN4_SER_ERR_SSMSH);
          |             ^~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Intel-SIG: commit a66cf93ab338 ("crypto: qat - remove double initialization of value)"
Backport to support Intel QAT in-tree driver

Fixes: 99b1c9826e48 ("crypto: qat - count QAT GEN4 errors")
Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin 0b9bf2d4e0 crypto: qat - avoid division by zero
commit f99fb7d660f7 ("crypto: qat - avoid division by zero") upstream

Check if delta_us is not zero and return -EINVAL if it is.
delta_us is unlikely to be zero as there is a sleep between the reads of
the two timestamps.

This is to fix the following warning when compiling the QAT driver
using clang scan-build:
    drivers/crypto/intel/qat/qat_common/adf_clock.c:87:9: warning: Division by zero [core.DivideZero]
       87 |         temp = DIV_ROUND_CLOSEST_ULL(temp, delta_us);
          |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Intel-SIG: commit f99fb7d660f7 ("crypto: qat - avoid division by zero)"
Backport to support Intel QAT in-tree driver

Fixes: e2980ba57e ("crypto: qat - add measure clock frequency")
Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin cd41e2604d crypto: qat - removed unused macro in adf_cnv_dbgfs.c
commit 9a5dcada14d5 ("crypto: qat - removed unused macro in adf_cnv_dbgfs.c") upstream

This macro was added but never used, remove it.

This is to fix the following warning when compiling the QAT driver
using the clang compiler with CC=clang W=2:
    drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c:19:9: warning: macro is not used [-Wunused-macros]
       19 | #define CNV_SLICE_ERR_MASK              GENMASK(7, 0)
          |         ^

Intel-SIG: commit 9a5dcada14d5 ("crypto: qat - removed unused macro in adf_cnv_dbgfs.c)"
Backport to support Intel QAT in-tree driver

Fixes: d807f0240c71 ("crypto: qat - add cnv_errors debugfs file")
Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Adam Guerin 2dabfd8fcc crypto: qat - remove unused macros in qat_comp_alg.c
commit dfff0e35fa5d ("crypto: qat - remove unused macros in qat_comp_alg.c") upstream

As a result of the removal of qat_zlib_deflate, some defines where not
removed. Remove them.

This is to fix the following warning when compiling the QAT driver
using the clang compiler with CC=clang W=2:
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:21:9: warning: macro is not used [-Wunused-macros]
       21 | #define QAT_RFC_1950_CM_OFFSET 4
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:16:9: warning: macro is not used [-Wunused-macros]
       16 | #define QAT_RFC_1950_HDR_SIZE 2
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:17:9: warning: macro is not used [-Wunused-macros]
       17 | #define QAT_RFC_1950_FOOTER_SIZE 4
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:22:9: warning: macro is not used [-Wunused-macros]
       22 | #define QAT_RFC_1950_DICT_MASK 0x20
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:18:9: warning: macro is not used [-Wunused-macros]
       18 | #define QAT_RFC_1950_CM_DEFLATE 8
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:20:9: warning: macro is not used [-Wunused-macros]
       20 | #define QAT_RFC_1950_CM_MASK 0x0f
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:23:9: warning: macro is not used [-Wunused-macros]
       23 | #define QAT_RFC_1950_COMP_HDR 0x785e
          |         ^
    drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:19:9: warning: macro is not used [-Wunused-macros]
       19 | #define QAT_RFC_1950_CM_DEFLATE_CINFO_32K 7
          |         ^

Intel-SIG: commit dfff0e35fa5d ("crypto: qat - remove unused macros in qat_comp_alg.c)"
Backport to support Intel QAT in-tree driver

Fixes: e9dd20e0e5f6 ("crypto: qat - Remove zlib-deflate")
Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Dan Carpenter 93fcb39c6d crypto: qat - uninitialized variable in adf_hb_error_inject_write()
commit bcc06e1b3dad ("crypto: qat - uninitialized variable in adf_hb_error_inject_write()") upstream

There are a few issues in this code.  If *ppos is non-zero then the
first part of the buffer is not initialized.  We never initialize the
last character of the buffer.  The return is not checked so it's
possible that none of the buffer is initialized.

This is debugfs code which is root only and the impact of these bugs is
very small.  However, it's still worth fixing.  To fix this:
1) Check that *ppos is zero.
2) Use copy_from_user() instead of simple_write_to_buffer().
3) Explicitly add a NUL terminator.

Intel-SIG: commit bcc06e1b3dad ("crypto: qat - uninitialized variable in adf_hb_error_inject_write())"
Backport to support Intel QAT in-tree driver

Fixes: e2b67859ab6e ("crypto: qat - add heartbeat error simulator")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Giovanni Cabiddu 4f2c2217ba Documentation: qat: fix auto_reset section
commit 2ecd43413d76 ("Documentation: qat: fix auto_reset section") upstream

Remove unneeded colon in the auto_reset section.

This resolves the following errors when building the documentation:

    Documentation/ABI/testing/sysfs-driver-qat:146: ERROR: Unexpected indentation.
    Documentation/ABI/testing/sysfs-driver-qat:146: WARNING: Block quote ends without a blank line; unexpected unindent.

Intel-SIG: commit 2ecd43413d76 ("Documentation: qat: fix auto_reset section)"
Backport to support Intel QAT in-tree driver

Fixes: f5419a4239af ("crypto: qat - add auto reset on error")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/linux-kernel/20240212144830.70495d07@canb.auug.org.au/T/
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:42 +08:00
Damian Muszynski 5ab5db9453 crypto: qat - resolve race condition during AER recovery
commit 7d42e097607c ("crypto: qat - resolve race condition during AER recovery") upstream

During the PCI AER system's error recovery process, the kernel driver
may encounter a race condition with freeing the reset_data structure's
memory. If the device restart will take more than 10 seconds the function
scheduling that restart will exit due to a timeout, and the reset_data
structure will be freed. However, this data structure is used for
completion notification after the restart is completed, which leads
to a UAF bug.

This results in a KFENCE bug notice.

  BUG: KFENCE: use-after-free read in adf_device_reset_worker+0x38/0xa0 [intel_qat]
  Use-after-free read at 0x00000000bc56fddf (in kfence-#142):
  adf_device_reset_worker+0x38/0xa0 [intel_qat]
  process_one_work+0x173/0x340

To resolve this race condition, the memory associated to the container
of the work_struct is freed on the worker if the timeout expired,
otherwise on the function that schedules the worker.
The timeout detection can be done by checking if the caller is
still waiting for completion or not by using completion_done() function.

Intel-SIG: commit 7d42e097607c ("crypto: qat - resolve race condition during AER recovery)"
Backport to support Intel QAT in-tree driver

Fixes: d8cba25d2c ("crypto: qat - Intel(R) QAT driver framework")
Cc: <stable@vger.kernel.org>
Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:41 +08:00
Damian Muszynski ae454b4628 crypto: qat - change SLAs cleanup flow at shutdown
commit c2304e1a0b80 ("crypto: qat - change SLAs cleanup flow at shutdown") upstream

The implementation of the Rate Limiting (RL) feature includes the cleanup
of all SLAs during device shutdown. For each SLA, the firmware is notified
of the removal through an admin message, the data structures that take
into account the budgets are updated and the memory is freed.
However, this explicit cleanup is not necessary as (1) the device is
reset, and the firmware state is lost and (2) all RL data structures
are freed anyway.

In addition, if the device is unresponsive, for example after a PCI
AER error is detected, the admin interface might not be available.
This might slow down the shutdown sequence and cause a timeout in
the recovery flows which in turn makes the driver believe that the
device is not recoverable.

Fix by replacing the explicit SLAs removal with just a free of the
SLA data structures.

Intel-SIG: commit c2304e1a0b80 ("crypto: qat - change SLAs cleanup flow at shutdown)"
Backport to support Intel QAT in-tree driver

Fixes: d9fb8408376e ("crypto: qat - add rate limiting feature to qat_4xxx")
Cc: <stable@vger.kernel.org>
Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:41 +08:00
Mun Chun Yep e42aa4724c crypto: qat - improve aer error reset handling
commit 9567d3dc7609 ("crypto: qat - improve aer error reset handling") upstream

Rework the AER reset and recovery flow to take into account root port
integrated devices that gets reset between the error detected and the
slot reset callbacks.

In adf_error_detected() the devices is gracefully shut down. The worker
threads are disabled, the error conditions are notified to listeners and
through PFVF comms and finally the device is reset as part of
adf_dev_down().

In adf_slot_reset(), the device is brought up again. If SRIOV VFs were
enabled before reset, these are re-enabled and VFs are notified of
restarting through PFVF comms.

Intel-SIG: commit 9567d3dc7609 ("crypto: qat - improve aer error reset handling)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Mun Chun Yep <mun.chun.yep@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Markas Rapoportas <markas.rapoportas@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:41 +08:00
Furong Zhou 6b668441c5 crypto: qat - limit heartbeat notifications
commit 750fa7c20e60 ("crypto: qat - limit heartbeat notifications") upstream

When the driver detects an heartbeat failure, it starts the recovery
flow. Set a limit so that the number of events is limited in case the
heartbeat status is read too frequently.

Intel-SIG: commit 750fa7c20e60 ("crypto: qat - limit heartbeat notifications)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Furong Zhou <furong.zhou@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Markas Rapoportas <markas.rapoportas@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Mun Chun Yep <mun.chun.yep@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:41 +08:00
Damian Muszynski df63e74b2d crypto: qat - add auto reset on error
commit f5419a4239af ("crypto: qat - add auto reset on error") upstream

Expose the `auto_reset` sysfs attribute to configure the driver to reset
the device when a fatal error is detected.

When auto reset is enabled, the driver resets the device when it detects
either an heartbeat failure or a fatal error through an interrupt.

This patch is based on earlier work done by Shashank Gupta.

Intel-SIG: commit f5419a4239af ("crypto: qat - add auto reset on error)"
Backport to support Intel QAT in-tree driver

Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Markas Rapoportas <markas.rapoportas@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Mun Chun Yep <mun.chun.yep@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ Aichun Shi: amend commit log ]
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
2024-04-12 20:55:41 +08:00