Commit Graph

5688 Commits

Author SHA1 Message Date
Ovidiu Panait
489bfd8f8a crypto: sahara - fix cbc selftest failure
[ Upstream commit 9f10bc28c0 ]

The kernel crypto API requires that all CBC implementations update the IV
buffer to contain the last ciphertext block.

This fixes the following cbc selftest error:
alg: skcipher: sahara-cbc-aes encryption test failed (wrong output IV) on
test vector 0, cfg="in-place (one sglist)"

Fixes: 5de8875281 ("crypto: sahara - Add driver for SAHARA2 accelerator.")
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:16 -08:00
Ovidiu Panait
dd31964d9e crypto: sahara - remove FLAGS_NEW_KEY logic
[ Upstream commit 8fd1834357 ]

Remove the FLAGS_NEW_KEY logic as it has the following issues:
- the wrong key may end up being used when there are multiple data streams:
       t1            t2
    setkey()
    encrypt()
                   setkey()
                   encrypt()

    encrypt() <--- key from t2 is used
- switching between encryption and decryption with the same key is not
  possible, as the hdr flags are only updated when a new setkey() is
  performed

With this change, the key is always sent along with the cryptdata when
performing encryption/decryption operations.

Fixes: 5de8875281 ("crypto: sahara - Add driver for SAHARA2 accelerator.")
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:16 -08:00
Nikita Zhandarovich
8084b788c2 crypto: safexcel - Add error handling for dma_map_sg() calls
[ Upstream commit 87e02063d0 ]

Macro dma_map_sg() may return 0 on error. This patch enables
checks in case of the macro failure and ensures unmapping of
previously mapped buffers with dma_unmap_sg().

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 49186a7d9e ("crypto: inside_secure - Avoid dma map if size is zero")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Reviewed-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:16 -08:00
Dinghao Liu
1e9d707233 crypto: ccp - fix memleak in ccp_init_dm_workarea
[ Upstream commit a1c95dd5bc ]

When dma_map_single() fails, wa->address is supposed to be freed
by the callers of ccp_init_dm_workarea() through ccp_dm_free().
However, many of the call spots don't expect to have to call
ccp_dm_free() on failure of ccp_init_dm_workarea(), which may
lead to a memleak. Let's free wa->address in ccp_init_dm_workarea()
when dma_map_single() fails.

Fixes: 63b945091a ("crypto: ccp - CCP device driver and interface support")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:16 -08:00
Chen Ni
b94f7e34d6 crypto: sa2ul - Return crypto_aead_setkey to transfer the error
[ Upstream commit ce852f1308 ]

Return crypto_aead_setkey() in order to transfer the error if
it fails.

Fixes: d2c8ac187f ("crypto: sa2ul - Add AEAD algorithm support")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:16 -08:00
Gonglei (Arei)
c4c54fce9e crypto: virtio - Handle dataq logic with tasklet
[ Upstream commit fed93fb62e ]

Doing ipsec produces a spinlock recursion warning.
This is due to crypto_finalize_request() being called in the upper half.
Move virtual data queue processing of virtio-crypto driver to tasklet.

Fixes: dbaf0624ff ("crypto: add virtio-crypto driver")
Reported-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: wangyangxin <wangyangxin1@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:15 -08:00
Chanho Park
6d9f17829e crypto: jh7110 - Correct deferred probe return
[ Upstream commit d57343022b ]

This fixes list_add corruption error when the driver is returned
with -EPROBE_DEFER. It is also required to roll back the previous
probe sequences in case of deferred_probe. So, this removes
'err_probe_defer" goto label and just use err_dma_init instead.

Fixes: 42ef0e944b ("crypto: starfive - Add crypto engine support")
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Reviewed-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:15 -08:00
Kshitiz Varshney
3da4363a26 caamhash.c: Added Check for offloading hash operations on CAAM
This commit adds CRYPTO_ALG_KERN_DRIVER_ONLY flag which offloads hash
operations on CAAM hardware.

Signed-off-by: Kshitiz Varshney <kshitiz.varshney@nxp.com>
2024-01-17 10:28:27 +01:00
Longfang Liu
6feb483ab7 crypto: hisilicon/qm - fix EQ/AEQ interrupt issue
[ Upstream commit 5acab6eb59 ]

During hisilicon accelerator live migration operation. In order to
prevent the problem of EQ/AEQ interrupt loss. Migration driver will
trigger an EQ/AEQ doorbell at the end of the migration.

This operation may cause double interruption of EQ/AEQ events.
To ensure that the EQ/AEQ interrupt processing function is normal.
The interrupt handling functionality of EQ/AEQ needs to be updated.
Used to handle repeated interrupts event.

Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-10 17:16:55 +01:00
Svyatoslav Pankratov
bcf6fe34a3 crypto: qat - fix double free during reset
[ Upstream commit 01aed663e6 ]

There is no need to free the reset_data structure if the recovery is
unsuccessful and the reset is synchronous. The function
adf_dev_aer_schedule_reset() handles the cleanup properly. Only
asynchronous resets require such structure to be freed inside the reset
worker.

Fixes: d8cba25d2c ("crypto: qat - Intel(R) QAT driver framework")
Signed-off-by: Svyatoslav Pankratov <svyatoslav.pankratov@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-10 17:16:55 +01:00
Jason Liu
f75d905095 Merge tag 'v6.6.3' into lf-6.6.y
This is the 6.6.3 stable release

* tag 'v6.6.3': (526 commits)
  Linux 6.6.3
  drm/amd/display: Change the DMCUB mailbox memory location from FB to inbox
  drm/amd/display: Clear dpcd_sink_ext_caps if not set
  ...

Signed-off-by: Jason Liu <jason.hui.liu@nxp.com>

 Conflicts:
	arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
	drivers/usb/dwc3/core.c
2023-11-30 09:41:12 -06:00
Jason Liu
6d09067baf Merge tag 'v6.6.2' into lf-6.6.y
This is the 6.6.2 stable release

* tag 'v6.6.2': (634 commits)
  Linux 6.6.2
  btrfs: make found_logical_ret parameter mandatory for function queue_scrub_stripe()
  btrfs: use u64 for buffer sizes in the tree search ioctls
  ...

Signed-off-by: Jason Liu <jason.hui.liu@nxp.com>

Conflicts:
	drivers/clk/imx/clk-imx8mq.c
	drivers/clk/imx/clk-imx8qxp.c
	drivers/media/i2c/ov5640.c
	drivers/misc/pci_endpoint_test.c
2023-11-30 09:40:58 -06:00
Longfang Liu
c7f514e266 crypto: hisilicon/qm - prevent soft lockup in receive loop
[ Upstream commit 33fc506d2a ]

In the scenario where the accelerator business is fully loaded.
When the workqueue receiving messages and performing callback
processing, there are a large number of messages that need to be
received, and there are continuously messages that have been
processed and need to be received.
This will cause the receive loop here to be locked for a long time.
This scenario will cause watchdog timeout problems on OS with kernel
preemption turned off.

The error logs:
watchdog: BUG: soft lockup - CPU#23 stuck for 23s! [kworker/u262:1:1407]
[ 1461.978428][   C23] Call trace:
[ 1461.981890][   C23]  complete+0x8c/0xf0
[ 1461.986031][   C23]  kcryptd_async_done+0x154/0x1f4 [dm_crypt]
[ 1461.992154][   C23]  sec_skcipher_callback+0x7c/0xf4 [hisi_sec2]
[ 1461.998446][   C23]  sec_req_cb+0x104/0x1f4 [hisi_sec2]
[ 1462.003950][   C23]  qm_poll_req_cb+0xcc/0x150 [hisi_qm]
[ 1462.009531][   C23]  qm_work_process+0x60/0xc0 [hisi_qm]
[ 1462.015101][   C23]  process_one_work+0x1c4/0x470
[ 1462.020052][   C23]  worker_thread+0x150/0x3c4
[ 1462.024735][   C23]  kthread+0x108/0x13c
[ 1462.028889][   C23]  ret_from_fork+0x10/0x18

Therefore, it is necessary to add an actively scheduled operation in the
while loop to prevent this problem.
After adding it, no matter whether the OS turns on or off the kernel
preemption function. Neither will cause watchdog timeout issues.

Signed-off-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-28 17:19:44 +00:00
Dong Aisheng
9f2df52de2 Merge remote-tracking branch 'origin/crypto/dcp' into crypto/next
* origin/crypto/dcp:
  LF-7602: Device tree fixup based on compatible string
  DCP: Add AES OTP keys support
  MLK-23746 crypto: dcp - add power management support
  crypto: dcp - check zero-length input
2023-11-22 17:04:00 +08:00
Giovanni Cabiddu
cffe00ff9c crypto: qat - fix deadlock in backlog processing
[ Upstream commit 203b01001c ]

If a request has the flag CRYPTO_TFM_REQ_MAY_BACKLOG set, the function
qat_alg_send_message_maybacklog(), enqueues it in a backlog list if
either (1) there is already at least one request in the backlog list, or
(2) the HW ring is nearly full or (3) the enqueue to the HW ring fails.
If an interrupt occurs right before the lock in qat_alg_backlog_req() is
taken and the backlog queue is being emptied, then there is no request
in the HW queues that can trigger a subsequent interrupt that can clear
the backlog queue. In addition subsequent requests are enqueued to the
backlog list and not sent to the hardware.

Fix it by holding the lock while taking the decision if the request
needs to be included in the backlog queue or not. This synchronizes the
flow with the interrupt handler that drains the backlog queue.

For performance reasons, the logic has been changed to try to enqueue
first without holding the lock.

Fixes: 3868238397 ("crypto: qat - add backlog mechanism")
Reported-by: Mikulas Patocka <mpatocka@redhat.com>
Closes: https://lore.kernel.org/all/af9581e2-58f9-cc19-428f-6f18f1f83d54@redhat.com/T/
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Giovanni Cabiddu
82e4aa18bb crypto: qat - fix ring to service map for QAT GEN4
[ Upstream commit a238487f79 ]

The 4xxx drivers hardcode the ring to service mapping. However, when
additional configurations where added to the driver, the mappings were
not updated. This implies that an incorrect mapping might be reported
through pfvf for certain configurations.

Add an algorithm that computes the correct ring to service mapping based
on the firmware loaded on the device.

Fixes: 0cec19c761 ("crypto: qat - add support for compression for 4xxx")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Tero Kristo <tero.kristo@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Giovanni Cabiddu
04985fb71a crypto: qat - use masks for AE groups
[ Upstream commit f7df2329ee ]

The adf_fw_config structures hardcode a bit mask that represents the
acceleration engines (AEs) where a certain firmware image will have to
be loaded to. Remove the hardcoded masks and replace them with defines.

This does not introduce any functional change.

Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Tero Kristo <tero.kristo@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: a238487f79 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Giovanni Cabiddu
a7be12fbac crypto: qat - refactor fw config related functions
[ Upstream commit 2990d2edac ]

The logic that selects the correct adf_fw_config structure based on the
configured service is replicated twice in the uof_get_name() and
uof_get_ae_mask() functions. Refactor the code so that there is no
replication.

This does not introduce any functional change.

Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Damian Muszynski <damian.muszynski@intel.com>
Reviewed-by: Tero Kristo <tero.kristo@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: a238487f79 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Adam Guerin
2e513f6bc7 crypto: qat - enable dc chaining service
[ Upstream commit 37b14f2dfa ]

QAT GEN4 devices support chained compression operations. These
allow, with a single request to firmware, to hash then compress
data.

Extend the configuration to enable such mode. The cfg_services
operations in sysfs are extended to allow the string "dcc". When
selected, the driver downloads to the device both the symmetric
crypto and the compression firmware images and sends an admin message
to firmware which enables `chained` operations.
In addition, it sets the device's capabilities as the combination
of compression and symmetric crypto capabilities, while excluding
the ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC bit to indicate
that in this mode, symmetric crypto instances are not supported.

When "dcc" is enabled, the device will handle compression requests
as if the "dc" configuration is loaded ("dcc" is a variation of "dc")
and the driver will register the acomp algorithms.

As for the other extended configurations, "dcc" is only available for
qat_4xxx devices and the chaining service will be only accessible from
user space.

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>
Stable-dep-of: a238487f79 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Giovanni Cabiddu
b7284784b8 crypto: qat - consolidate services structure
[ Upstream commit 7171376638 ]

The data structure that associates a service id with its name is
replicated across the driver.
Remove duplication by moving this data structure to a new include file,
adf_cfg_services.h in order to have consistency across the drivers.

Note that the data structure is re-instantiated every time the new
include is added to a compilation unit.

Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: a238487f79 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:23 +01:00
Longfang Liu
4c79c7a4e7 crypto: hisilicon/qm - fix PF queue parameter issue
[ Upstream commit 5831fc1fd4 ]

If the queue isolation feature is enabled, the number of queues
supported by the device changes. When PF is enabled using the
current default number of queues, the default number of queues may
be greater than the number supported by the device. As a result,
the PF fails to be bound to the driver.

After modification, if queue isolation feature is enabled, when
the default queue parameter is greater than the number supported
by the device, the number of enabled queues will be changed to
the number supported by the device, so that the PF and driver
can be properly bound.

Fixes: 8bbecfb402 ("crypto: hisilicon/qm - add queue isolation support for Kunpeng930")
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:20 +01:00
Giovanni Cabiddu
5a600b7964 crypto: qat - increase size of buffers
[ Upstream commit 4e4e2ed22d ]

Increase the size of the buffers used for composing the names used for
the transport debugfs entries and the vector name to avoid a potential
truncation.

This resolves the following errors when compiling the driver with W=1
and KCFLAGS=-Werror on GCC 12.3.1:

    drivers/crypto/intel/qat/qat_common/adf_transport_debug.c: In function ‘adf_ring_debugfs_add’:
    drivers/crypto/intel/qat/qat_common/adf_transport_debug.c💯60: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
    drivers/crypto/intel/qat/qat_common/adf_isr.c: In function ‘adf_isr_resource_alloc’:
    drivers/crypto/intel/qat/qat_common/adf_isr.c:197:47: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 5 [-Werror=format-truncation=]

Fixes: a672a9dc87 ("crypto: qat - Intel(R) QAT transport code")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Damian Muszynski <damian.muszynski@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Gaurav Jain
14d52e6ba2 crypto: caam/jr - fix Chacha20 + Poly1305 self test failure
[ Upstream commit a8d3cdcc09 ]

key buffer is not copied in chachapoly_setkey function,
results in wrong output for encryption/decryption operation.

fix this by memcpy the key in caam_ctx key arrary

Fixes: d6bbd4eea2 ("crypto: caam/jr - add support for Chacha20 + Poly1305")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Gaurav Jain
86b7c8c7b2 crypto: caam/qi2 - fix Chacha20 + Poly1305 self test failure
[ Upstream commit 7b8c6aee0d ]

key buffer is not copied in chachapoly_setkey function,
results in wrong output for encryption/decryption operation.

fix this by memcpy the key in caam_ctx key arrary

Fixes: c10a533679 ("crypto: caam/qi2 - add support for Chacha20 + Poly1305")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Giovanni Cabiddu
55ec67f78c crypto: qat - fix unregistration of compression algorithms
[ Upstream commit 11af152f78 ]

The function adf_dev_init(), through the subsystem qat_compression,
populates the list of list of compression instances
accel_dev->compression_list. If the list of instances is not empty,
the function adf_dev_start() will then call qat_compression_registers()
register the compression algorithms into the crypto framework.

If any of the functions in adf_dev_start() fail, the caller of such
function, in the error path calls adf_dev_down() which in turn call
adf_dev_stop() and adf_dev_shutdown(), see for example the function
state_store in adf_sriov.c.
However, if the registration of compression algorithms is not done,
adf_dev_stop() will try to unregister the algorithms regardless.
This might cause the counter active_devs in qat_compression.c to get
to a negative value.

Add a new state, ADF_STATUS_COMPRESSION_ALGS_REGISTERED, which tracks
if the compression algorithms are registered into the crypto framework.
Then use this to unregister the algorithms if such flag is set. This
ensures that the compression algorithms are only unregistered if
previously registered.

Fixes: 1198ae56c9 ("crypto: qat - expose deflate through acomp api for QAT GEN2")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Adam Guerin <adam.guerin@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Giovanni Cabiddu
fa43d81ad1 crypto: qat - fix unregistration of crypto algorithms
[ Upstream commit 9b2f33a1bf ]

The function adf_dev_init(), through the subsystem qat_crypto, populates
the list of list of crypto instances accel_dev->crypto_list.
If the list of instances is not empty, the function adf_dev_start() will
then call qat_algs_registers() and qat_asym_algs_register() to register
the crypto algorithms into the crypto framework.

If any of the functions in adf_dev_start() fail, the caller of such
function, in the error path calls adf_dev_down() which in turn call
adf_dev_stop() and adf_dev_shutdown(), see for example the function
state_store in adf_sriov.c.
However, if the registration of crypto algorithms is not done,
adf_dev_stop() will try to unregister the algorithms regardless.
This might cause the counter active_devs in qat_algs.c and
qat_asym_algs.c to get to a negative value.

Add a new state, ADF_STATUS_CRYPTO_ALGS_REGISTERED, which tracks if the
crypto algorithms are registered into the crypto framework. Then use
this to unregister the algorithms if such flag is set. This ensures that
the crypto algorithms are only unregistered if previously registered.

Fixes: d8cba25d2c ("crypto: qat - Intel(R) QAT driver framework")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Adam Guerin <adam.guerin@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Giovanni Cabiddu
a44d2b8389 crypto: qat - ignore subsequent state up commands
[ Upstream commit 9c20cb8b18 ]

If the device is already in the up state, a subsequent write of `up` to
the sysfs attribute /sys/bus/pci/devices/<BDF>/qat/state brings the
device down.
Fix this behaviour by ignoring subsequent `up` commands if the device is
already in the up state.

Fixes: 1bdc85550a ("crypto: qat - fix concurrency issue when device state changes")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Adam Guerin <adam.guerin@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Giovanni Cabiddu
3b97788e92 crypto: qat - fix state machines cleanup paths
[ Upstream commit c9ca9756f3 ]

Commit 1bdc85550a ("crypto: qat - fix concurrency issue when device
state changes") introduced the function adf_dev_down() which wraps the
functions adf_dev_stop() and adf_dev_shutdown().
In a subsequent change, the sequence adf_dev_stop() followed by
adf_dev_shutdown() was then replaced across the driver with just a call
to the function adf_dev_down().

The functions adf_dev_stop() and adf_dev_shutdown() are called in error
paths to stop the accelerator and free up resources and can be called
even if the counterparts adf_dev_init() and adf_dev_start() did not
complete successfully.
However, the implementation of adf_dev_down() prevents the stop/shutdown
sequence if the device is found already down.
For example, if adf_dev_init() fails, the device status is not set as
started and therefore a call to adf_dev_down() won't be calling
adf_dev_shutdown() to undo what adf_dev_init() did.

Do not check if a device is started in adf_dev_down() but do the
equivalent check in adf_sysfs.c when handling a DEV_DOWN command from
the user.

Fixes: 2b60f79c7b ("crypto: qat - replace state machine calls")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Adam Guerin <adam.guerin@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:19 +01:00
Christophe JAILLET
00dcb2738b crypto: hisilicon/hpre - Fix a erroneous check after snprintf()
[ Upstream commit c977950146 ]

This error handling looks really strange.
Check if the string has been truncated instead.

Fixes: 02ab994635 ("crypto: hisilicon - Fixed some tiny bugs of HPRE")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:18 +01:00
Mario Limonciello
4c2c057d77 crypto: ccp - Get a free page to use while fetching initial nonce
[ Upstream commit 53f7f779f4 ]

dbc_dev_init() gets a free page from `GFP_KERNEL`, but if that page has
any data in it the first nonce request will fail.
This prevents dynamic boost control from probing. To fix this, explicitly
request a zeroed page with `__GFP_ZERO` to ensure first nonce fetch works.

Fixes: c04cf9e14f ("crypto: ccp - Add support for fetching a nonce for dynamic boost control")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 11:59:18 +01:00
Dong Aisheng
6a286d5ba3 LF-10426 crypto: caam: use new imx8ulp ele compatible string
The ele compatible string has been changed since the commit 99c79d49cb
("LF-10329: arm64: dts: imx8ulp-evk: added nxp secure enclave firmware")
So need update the driver accordingly.

Reviewed-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2023-11-03 14:28:55 +08:00
Kshitiz Varshney
9a5bf4942e LF-7602: Device tree fixup based on compatible string
Updated otp_crypto_key & otp_unique_key device tree fix up.
Earlier, device tree fix up was based on hardcoded address, but now it's
based on compatible string of crypto node:- "fsl,imx28-dcp"

Signed-off-by: Kshitiz Varshney <kshitiz.varshney@nxp.com>
2023-10-30 17:43:50 +08:00
Kshitiz Varshney
35f3816c21 DCP: Add AES OTP keys support
Current DCP driver implementation doesn't support AES OTP CRYPTO_KEY.
otp_unique_key & otp_crypto_key handles are generated by U-boot RNG driver
and on each reboot cycle, device tree fix-up is done using RNG.

OpenSSL application can input device tree fixed up 16 byte number for
crypto operations.

Tested on i.MX6ULL EVK with commands below.

- Encrypt using UNIQUE_KEY:
$ openssl aes-128-ecb -p -nosalt -nopad -K "$(hexdump -v -e '"" 1/1 "%02X"'\
/proc/device-tree/soc/bus@2200000/crypto@2280000/otp_unique_key)" -in  \
openssl_test.txt -out my_encrypted_secret.bin

- Decrypt using UNIQUE_KEY:
$ openssl aes-128-ecb -d -p -nosalt -nopad -K "$(hexdump -v -e '"" 1/1 "%02X"'\
/proc/device-tree/soc/bus@2200000/crypto@2280000/otp_unique_key)" -in  \
my_encrypted_secret.bin -out openssl_decrypt_test.txt

- Encrypt using CRYPTO_KEY:
$ openssl aes-128-ecb -p -nosalt -nopad -K "$(hexdump -v -e '"" 1/1 "%02X"'\
 /proc/device-tree/soc/bus@2200000/crypto@2280000/otp_crypto_key)" -in  \
openssl_test.txt -out my_encrypted_secret.bin

- Decrypt using CRYPTO_KEY:
$ openssl aes-128-ecb -d -p -nosalt -nopad -K "$(hexdump -v -e '"" 1/1 "%02X"'\
 /proc/device-tree/soc/bus@2200000/crypto@2280000/otp_crypto_key)" -in \
my_encrypted_secret.bin -out openssl_decrypt_test.txt

Signed-off-by: Kshitiz Varshney <kshitiz.varshney@nxp.com>
Reviewed by: Gaurav Jain <gaurav.jain@nxp.com>
2023-10-30 17:43:50 +08:00
Dragos Rosioru
86fe34139b MLK-23746 crypto: dcp - add power management support
Added suspend/resume operations for PM support in the DCP driver.
After a suspend/resume cycle DCP would still be in a low-power mode
and have its clocks gated, thus requiring state to be saved beforehand:
- Control register value(DCP_CTRL)
- Channel control register value(DCP_CHANNELCTRL)

Signed-off-by: Dragos Rosioru <dragos.rosioru@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:43:50 +08:00
Horia Geantă
aa3e5c4272 crypto: dcp - check zero-length input
In case of zero-length input for ablkcipher algorithms, IV copying
accesses invalid memory - due to (last_out_len-AES_BLOCK_SIZE)
turning into a big unsigned offset for last_out_len = 0U.

Since zero-length input is allowed for ablkcipher / skcipher algorithms,
make this case a no-op by returning immediately.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:43:50 +08:00
Gaurav Jain
138638223a crypto: caam/jr - fix Chacha20 + Poly1305 self test failure
key buffer is not copied in chachapoly_setkey function,
results in wrong output for encryption/decryption operation.

fix this by memcpy the key in caam_ctx key arrary

Fixes: d6bbd4eea2 ("crypto: caam/jr - add support for Chacha20 + Poly1305")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
2023-10-30 17:37:37 +08:00
Gaurav Jain
e9f5e0c8fb LF-9911 crypto: caam/qi2 - fix Chacha20 + Poly1305 self test failure
key buffer is not copied in chachapoly_setkey function,
results in wrong output for encryption/decryption operation.

fix this by memcpy the key in caam_ctx key arrary

Fixes: c10a533679 ("crypto: caam/qi2 - add support for Chacha20 + Poly1305")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
2023-10-30 17:37:37 +08:00
Meenakshi Aggarwal
b49130a754 LF-10152: crypto:caam suspend/resume crash dump on imx8ulp
Fix PM resume issue on imx8ulp board

Add check for scu_en which will bypass the save/restore
caam state in kernel

Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
2023-10-30 17:37:37 +08:00
Meenakshi Aggarwal
f5ad044909 crypto/caam: compilation error fix
Add changes introduced by
commit-id:623814c0408771399c4209db73f60685f7cf1d14
in non-upstream patches

Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
2023-10-30 17:37:37 +08:00
Meenakshi Aggarwal
30753292bf LF-9578: crypto : caam : Fix crash in self test
Replace non-dma API with dma API

Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
2023-10-30 17:37:37 +08:00
Vabhav Sharma
2ea72d2ba8 LF-6722: drivers/crypto: caam/snvs: SNVS state during linux boot
SNVS HP state is read incorrectly because there is Software dependency
between SECVIO and CAAM driver.

Added code to read SNVS version ID register which contain non-zero
constants to identify the endianness of the device. This register includes
a 16-bit field called IP_ID, and seems to have one of four different values
0x003A, 0x003C, 0x003E or 0x003F.

Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
2023-10-30 17:37:37 +08:00
Vabhav Sharma
4d74b8dc00 LF-6118-3: crypto: caam: read entropy delay from device tree
Read entropy-delay property from device tree for
TRNG configuration.

update the value if entry is missing in DT.

Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com>
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
2023-10-30 17:37:37 +08:00
Pankaj Gupta
2c6d276b53 crypto: caam/qi - use QBMan (NXP) SDK driver
Update caam/qi to work with QBMan from NXP SDK.
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>

Squashed "crypto: caam/qi - fix FD congestion weight" fix.
Signed-off-by: Vlad Pelin <vlad.pelin@nxp.com>

Solved rebase conflicts.

CAAM QI : Reverting the NAPI changes to work with SDK QI:

- Changes from f84754dbc5
  Author: Sebastian Andrzej Siewior bigeasy@linutronix.de
  Date:   Mon Nov 2 00:22:55 2020 +0100

  soc/fsl/qbman: Add an argument to signal if NAPI processing is required.

  typedef enum qman_cb_dqrr_result (*qman_cb_dqrr)(struct qman_portal *qm,
                                          struct qman_fq *fq,
  -                                       const struct qm_dqrr_entry *dqrr);
  +                                       const struct qm_dqrr_entry *dqrr,
  +                                       bool sched_napi);

- reverting the complet commit de3f5d9e27.
  Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  Date:   Mon Nov 2 00:22:57 2020 +0100

    crypto: caam: Replace in_irq() usage.

Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Reviewed-by: Leo Li <leoyang.li@nxp.com>
2023-10-30 17:37:37 +08:00
Pankaj Gupta
d420f224ee MLK-25247 crypto: caam check for inaccess to controller's register page
iMX8ULP have a EdgeLock Enclave(ELE) that control access to
caam controller's register page.
At all, if the ELE release access to CAAM controller's register page,
it will release to secure-world only.

caam driver needs to be aware of ELE f/w presence, since some things
are done differently:

1. clocks are turned on automatically for iMX8ULP.
   there exists the caam clock gating bit,
   but it is not advised to gate the clock at linux,
   as optee-os or any other entity might be using it.

2. there is no access to caam controller's register page

3. as a consequence of "2.", part of the initialization is moved
   in f/w (TF-A etc.), e.g. RNG initialization

Signed-off-by: Varun Sethi <v.sethi@nxp.com>
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
2023-10-30 17:37:37 +08:00
Pankaj Gupta
cc19bb9c41 Revert "MLK-25247 crypto: caam check for inaccess to controller's register page"
This reverts commit d5923eb5d8.
2023-10-30 17:37:37 +08:00
Horia Geantă
04c3c66b00 LF-5355 crypto: caam/qi2 - fix typo in tls algorithm registration
Fix the typos when trying to register tls algorithms:
-"tls11(hmac(sha1),cbc(aes))" uses OP_ALG_ALGSEL_SHA256
instead of OP_ALG_ALGSEL_SHA1
-"tls12(hmac(sha256),cbc(aes))" uses OP_ALG_ALGSEL_SHA1
instead of OP_ALG_ALGSEL_SHA256

Fixes: c3eb2dcfb0 ("crypto: caam - added support for TLS1.1 & TLS1.2")
Verified-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Kshitiz Varshney
ba1b47c47b LF-5095: crypto-caam: Solved 0x00 issue in caam-keygen
Caam-keygen application is passing key value in uint8_t array (in case of
hex input) but kernel is calculating length with the help of strlen()
function.
Hence, replaced strlen() function with actual key_value_len which is a
member variable of structure caam_keygen_cmd (passed by user-space
application to kernel).

Fixes: 3af836d4b3 ("MLK-24420-3 crypto: caam - add ioctl calls for black keys and blobs generation")
Signed-off-by: Kshitiz Varshney <kshitiz.varshney@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Gaurav Jain
a2c4b39b40 LF-4946 crypto: caam: set bus frequency high during hwrng operation.
issue:
when bus frequency set to low, error reported duing hwrng operation.
"Busfreq OPTEE set from 533000000 to 24000000 start..."
"Busfreq OPTEE set to 24000000 done! cpu=0"
"caam_jr 30902000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error"

fix:
TRNG configuration fails to work with low bus frequency(24Mhz).
so request high bus frequency before hwrng operation start
and release high bus frequency after completion of hwrng operation.

Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Varun Sethi <V.Sethi@nxp.com>
Signed-off-by: Horia Geanta <horia.geanta@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Pankaj Gupta
74ca2ec3bd LF-4832 iMX8ULP caam: fix for failure in probe
For iMX8ULP, Nomenclature changes for Secure Enclave
driver, from imx8ulp-s400 to imx-sentnl.

Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Pankaj Gupta
0a756eeb94 crypto: caam - added support for TLS1.1 & TLS1.2
Enabled the support for TLS1.2 algorithms offload

        - aes-128-cbc-hmac-sha256
        - aes-256-cbc-hmac-sha256

Enabled the support of TLS1.1 algorithms offload

        - aes-128-cbc-hmac-sha1
        - aes-256-cbc-hmac-sha1

Support for the obsolete TLS1.0 is removed from the caam
driver.

Signed-off-by: Arun Pathak <arun.pathak@nxp.com>
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
2023-10-30 17:37:36 +08:00
Pankaj Gupta
3796662428 MLK-25247 crypto: caam check for inaccess to controller's register page
iMX8ULP have a S400 that control access to caam controller's register
page.
At all, if the S400 release access to CAAM controller's register page,
it will release to secure-world only.

caam driver needs to be aware of S400 f/w presence, since some things
are done differently:

1. clocks are turned on automatically for iMX8ULP.
there exists the caam clock gating bit, but it is not advised to gate the clock
at linux, as optee-os or any other entity might be using it.

2. there is no access to caam controller's register page

3. as a consequence of "2.", part of the initialization is moved
in f/w (TF-A etc.), e.g. RNG initialization

Signed-off-by: Varun Sethi <v.sethi@nxp.com>
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
2023-10-30 17:37:36 +08:00
Horia Geantă
82c9731a49 LF-3093-2 crypto: caam - fix sm_test in case no job rings available
In case no job rings are available, secure memory structures are not
initialized, since caam_jr_probe()->init_misc_func()->caam_sm_startup()
is not called.
This could happen if all job ring devices bind to the jr uio driver
instead of the caam/jr driver.
Running sm_test in this case will lead to a crash.

Add a check to verify that SM has been initialized - if not the tests
will be skipped.

Reported-by: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
2023-10-30 17:37:36 +08:00
Horia Geantă
16107add45 LF-3093-1 crypto: caam/jr - fix caam-keygen exit / clean-up
Introduction
===

Currently we are facing some limitations in the caam/jr module lifecycle.
There are some discussion in upstream:
Link: https://lore.kernel.org/linux-crypto/20190904023515.7107-13-andrew.smirnov@gmail.com
Link: https://lore.kernel.org/linux-crypto/20191105151353.6522-1-andrew.smirnov@gmail.com
but in the end it all seems to get down to implementations not being able
to gracefully unregister crypto algorithms from crypto API while there are
users / allocated tfms (cra_refcnt > 1).

[*] OTOH functionalities in caam/jr that don't interact with crypto API
(like Secure Memory or black keys / blobs generation) don't face this
limitation.

Issue at hand
===

When unloading the caam_jr module, the .remove callback for the last JR
device exits with -EBUSY (see "Introduction" above) and doesn't perform
the clean-up (crypto algorithms unregistering etc.).

One side effect of this is leeding to an oops, which occurs due to a
corruption in the linked list of "misc devices"
(drivers/char/misc.c - misc_list):
1. caam_jr module is unloaded without calling unregister_algs()->
caam_keygen_exit()->misc_deregister() for the last job ring device;
this leaves a dangling entry in the misc_list double-linked list
2. rng_core module is unloaded and calls misc_deregister(); this implies
removing the corresponding entry in the misc_list; while doing this the
dangling entry is accessed - which leads to an oops since the address is
no longer valid (address points to the caam_jr module address space,
but caam_jr has been previously unloaded).

Fix this by moving the clean-up of non-crypto related functionalities [*]
before crypto related ones.

Fixes: 3af836d4b3 ("MLK-24420-3 crypto: caam - add ioctl calls for black keys and blobs generation")
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
2023-10-30 17:37:36 +08:00
Iuliana Prodan
69afd2d4dd MLK-24420-3 crypto: caam - add ioctl calls for black keys and blobs generation
This patch adds the Kernel support for the caam-keygen user-space
application. It has two IOCTL calls for key and blob generation and
import a black key from a blob.

This support is included in CRYPTO_DEV_FSL_CAAM_TK_API (tagged key
support).

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
(cherry picked from commit 60baeafa83)

Squashed fixes:
dd746ff046 ("MLK-24496 crypto: caam - add tag object header to blob")
b8c49eddfd ("MLK-24517-3 crypto: caam - add null terminator to temporary buffer")
d7c41169bc ("MLK-24517-4 crypto: caam - validate arguments received from user-space")

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Iuliana Prodan
e60fcf9fdb MLK-24420-2 crypto: caam - add support for black keys and blobs
CAAM's Black Key mechanism is intended for protection
of user keys against bus snooping. This automatically
encapsulates and decapsulates cryptographic keys ''on-the-fly''
in an encrypted data structure called a Black Key.
Before a value is copied from a Key Register to memory,
CAAM will automatically encrypt the key as a Black Key
(encrypted key) using the current value in the JDKEKR or
TDKEKR as the encryption key.

CAAM's built-in Blob Protocol provides a method for protecting
user-defined data across system power cycles. CAAM protects data
in a data structure called a Blob, which provides both confidentiality
and integrity protection. The data to be protected is encrypted so that
it can be safely placed into non-volatile storage before the SoC is
powered down.

This patch includes the support to generate a black key from random or
from a plaintext. Also one can encapsulate it into a blob or decapsulate
a black key from a blob.
The key and blob generation descriptors are exported into a separate file,
such that they could be shared with other interfaces (qi, qi2).

This feature has support only for black keys, encapsulated in
black blobs in General Memory.

In caamkeyblob_test.c file is a test that validates the above
operations: create a black key from plaintext or from random,
encapsulate and decapsulate a blob and compare the obtained black key.
This test is configured as a kernel module.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
(cherry picked from commit 84287c5d3b)

Squashed fixes:
9c24012e6b ("MLK-24496 crypto: caam - fix blob encapsulation/decapsulation")
cd078fac33 ("MLK-24517-1 crypto: caam - removed unnecessary validation of black key for blob decapsulation")
8888926c54 ("MLK-24517-2 crypto: caam - removed unnecessary validation of black key for blob encapsulation")
e4b484ce2d ("MLK-24497 crypto: caam - update job descriptor with inline commands")

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Squashed LF commit (rebase-v5.10-rc2/crypto/caam):
035f5933cc45 ("crypto: caam: change kzfree to kfree_sensitive")

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:36 +08:00
Iuliana Prodan
2ca0865718 MLK-24420-1 crypto: caam - update tagged keys functionality and tk transformations for skcipher
Tagged keys are keys that contain metadata indicating what
they are and how to handle them using the new added tag_object API.
A tag object represents the metadata (or simply a header/configuration)
and the actual data (e.g. black key) obtained from hardware.
The support, for tagged keys, to skcipher algorithms, is done by
adding new transformations, with tk prefix to distinguish
between plaintext and tagged keys.
The tk_ transformations can be used directly by their name:
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "skcipher", /* this selects the symmetric cipher */
.salg_name = "tk(cbc(aes))" /* this is the cipher name */
};
or for dm-crypt, e.g. using dmsetup:
dmsetup -v create encrypted --table "0 $(blockdev --getsz /dev/mmcblk2p10)
crypt capi:tk(cbc(aes))-plain :32:logon:seckey 0 /dev/mmcblk2p10 0 1
sector_size:512".
tk_ transformations will know how to handle tagged keys, by loading the
proper settings for KEY command.

The API expects that the object (the actual data) from a tag object
to be a buffer (defined by address and size).

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
(cherry picked from commit 04cab5a13d)

Squashed fix:
9ca04c0a00 ("MLK-24497 crypto: caam - update tagged object functionality by adding red key length")

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Sandeep Malik
01bba8a807 crypto: caam - add CAAM job ring UIO support
This patch add the support for job ring UIO so
that userspace drivers can have access to the
caam job rings

Signed-off-by: Sandeep Malik <Sandeep.Malik@nxp.com>
Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>

crypto: caam - build config changes (squash to UIO)

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Radu Alexe
3a0b71b1ee crypto: caam - add caam_dma device on caam_probe
Dynamically create a platform device for the caam_dma driver
at caam_probe() time.

Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>

Use devres for caam_dma platform device unregistering.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Radu Alexe
36016684ee crypto: caam - add functionality used by the caam_dma driver
The caam_dma is a memcpy DMA driver based on the DMA functionality of
the CAAM hardware block. It creates a DMA channel for each JR of the
CAAM. This patch adds functionality that is used by the caam_dma that is
not yet part of the JR driver.

Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Radu Alexe
1f18c7e6ce crypto: caam/qi2 - add support for TLS 1.0 record
TLS 1.0 descriptors run on SEC 4.x or higher. For now, only
tls10(hmac(sha1),cbc(aes)) algorithm is registered by the driver.

Known limitations:
 - when src == dst - there should be no element in the src scatterlist
   array that contains both associated data and message data.
 - when src != dst - associated data is not copied from source into
   destination.
 - for decryption when src != dst the size of the destination should be
   large enough so that the buffer may contain the decrypted authenc and
padded data.

Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Radu Alexe
ee6a5f5533 crypto: caam/qi - add support for TLS 1.0 record
TLS 1.0 descriptors run on SEC 4.x or higher.
For now, only tls10(hmac(sha1),cbc(aes)) algorithm
is registered by the driver.

Known limitations:
 - when src == dst - there should be no element in the src scatterlist array
   that contains both associated data and message data.
 - when src != dst - associated data is not copied from source into
   destination.
 - for decryption when src != dst the size of the destination should be
   large enough so that the buffer may contain the decrypted authenc and
   padded data.

Signed-off-by: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
2023-10-30 17:37:35 +08:00
Radu Alexe
e12b2fd111 crypto: caam - add support for MOVEB command
CHAs of SEC work natively in BE mode. When moving
data to the alignment blocks, swapping is needed
for LE platforms. This is done by means of the MOVEB
command. This patch adds support
to DCL for this command.

Signed-off-by: Alex Porosanu <alexandru.porosanu@freescale.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
2023-10-30 17:37:35 +08:00
Horia Geantă
0755f82a1f crypto: caam/qi2 - add OPR (Order Preservation) support
During driver upstreaming OPR was removed due to lacking users.
Add OPR back, since in LSDK / LSDK-based ADKs there is at least
one user (ASF / VortiQa IPsec).

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Horia Geantă
ff85b67b3c crypto: caam/qi2 - add (unused) dpseci API
During driver upstreaming all unused dpseci API was trimmed down.
Add the API back to be in sync with files provided by MC f/w release.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Franck LENORMAND
e4a5027bb7 MLK-19801-2 crypto: caam - add support of tagged keys in caamalg
A tagged key is a key which has been tagged with metadata
using tag_object.h API.

We add the support for these keys to caamalg.

For each algo of caamalg which supports tagged keys , it is done by:
 - Creating a modified version of the algo
 - Registering the modified version
 - When the modified transform is used, it gets
   the load parameter of the key.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
(cherry picked from commit 88dee97d985890dbf37cafa7934c476d0ecfd0b3)
(Vipul: Fixed merge conflicts)
Conflicts:
	drivers/crypto/caam/caamalg.c
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
(cherry picked from commit 5adebac40a)

-port from ablkcipher to current skcipher implementation
-since in linux-imx true key_inline was always true: a. simplify
the descriptors and b. use key_cmd_opt to differentiate b/w tk and non-tk
cases
-change commit headline prefix

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Franck LENORMAND
ecbfbf984c MLK-19801-1 crypto: caam - add tag functionality
Add functions to tag an object with metadata(configuration).

It is possible to:
 - create metadata:
	- init_tag_object_header
	- init_blackey_conf
	- set_tag_object_conf
 - retrieve metadata:
	- get_tag_object_conf
	- get_blackey_conf

The API expects an object to be a space a memory
with an address and a size.

The implementation of the tag is currently exposed
but users shouldn't access it directly, they should
use the functions provided.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
(cherry picked from commit ebbb132da8e7f9de7f3d375eff8d87f684feb1eb)
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
(cherry picked from commit 8b6f6b4474)

-make tag functionality depend on JR
-change commit headline prefix

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Steve Cornelius
7cab0da0e4 MLKU-25-3 crypto: caam - add Secure Memory support
This is a squash of the following i.MX BSP commits
(rel_imx_4.19.35_1.1.0_rc2)

1.  ae8175a3f1 ("MLK-9710-10 Add CCM defs for FIFO_STORE instruction")
2.  9512280d06 ("MLK-9769-11 Add SM register defs, and expanded driver-private storage.")
3.  a9dc44de81 ("MLK-9769-10 Add Blob command bitdefs.")
4.  8f6a17b419 ("ENGR00289885 [iMX6Q] Add Secure Memory and SECVIO support.")
5.  c7d4f9db10 ("MLK-9710-11 Add internal key cover and external blob export/import to prototype SM-API")
6.  568e449edf ("MLK-9710-12 Adapt sm_test as a black-key handling example")
7.  f42f12d9cb ("MLK-9710-13 Correct size in BLOB_OVERHEAD definition")
8.  022fc2b33f ("MLK-9710-14 Un-pad cache sizes for blob export/import")
9.  8d3e8c3c4d ("MLK-9710-15 Correct size of padded key buffers")
10. 997fb2ff88 ("MLK-9710-5 Unregister Secure Memory platform device upon shutdown")
11. 5316249198 ("MLK-10897-1 ARM: imx7d: Add CAAM support for i.mx7d")
12. 07566f42a4 ("MLK-11103 Missing register in Secure memory configuration v1")
13. 3004636304 ("MLK-12302 caam: Secure Memory platform device creation crashes")
14. 0e6ed5a819 ("MLK-13779 crypto: caam - initialize kslock spinlock")
15. b1254b6b5f ("Add missing NULL checks in CAAM sm")
16. 61f57509bc ("MLK-17992: caam: sm: Fix compilation warnings")
17. 41cf3d4c58 ("MLK-15473-1: crypto: caam: Add CAAM driver support for iMX8 soc family")
18. bb87424812 ("MLK-17253-1: crypto: caam: Fix computation of SM pages addresses")
19. 308796dfae ("MLK-17253-2: crypto: caam: Use correct memory function for Secure Memory")
20. ba2cb6b5fb ("MLK-17732-2: SM store: Support iMX8QX and iMX8QM")
21. de710d376a ("MLK-17674-1: sm_store remove CONFIG_OF")
22. cfcae64743 ("MLK-17674-2: CAAM SM : get base address from device tree")
23. f49ebbd5ee ("MLK-17992: caam: sm: Fix compilation warnings")
24. 345ead4338 ("MLK-17841: crypto: caam: Correct bugs in Secure Memory")
25. c17811f3ff ("MLK-18082: crypto: caam: sm: Fix encap/decap function to handle errors")
26. 41bcba1d4c ("MLK-18082: crypto: caam: sm: Fix descriptor running functions")
27. b7385ab947 ("MLK-20204: drivers: crypto: caam: sm: Remove deadcode")
28. 1d749430cb ("MLK-20204: drivers: crypto: caam: sm: test: Dealloc keyslot properly")
29. 6a5c2d9d35 ("crypto: caam - lower SM test verbosity")
30. 1a6bc92c0c ("MLK-21617: crypto: caam - update SM test error handling")

Signed-off-by: Dan Douglass <dan.douglass@nxp.com>
Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
Signed-off-by: Steve Cornelius <steve.cornelius@nxp.com>
Signed-off-by: Octavian Purdila <octavian.purdila@nxp.com>
Signed-off-by: Radu Solea <radu.solea@nxp.com>
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Signed-off-by: Aymen Sghaier <aymen.sghaier@nxp.com>
Signed-off-by: Silvano di Ninno <silvano.dininno@nxp.com>

and LF commits (lf-5.4.y-1.0.0-rc2):
31. 4d3a0772bf ("LFV-26 crypto: caam - fix Secure Memory driver init")
32. 97dc4e4fa4 ("LF-63-1 crypto: caam - fix SM test init")

and LF commit (lf-5.4.y-1.0.1-rc1):
33. fabf6de666 ("LF-1602 crypto: caam - fix signals handling in sm_store")

and LF commit (rebase-20200703/crypto/caam):
34. 8d85d700e8d2 ("LF-1116-3 crypto: caam - update the check for the return code of caam_jr_enqueue function")

and LF commit (rebase-20200918/crypto/caam):
35. bfeb0bffc35a ("crypto: caam - build config changes")

and LF commit
36. LF-2487 crypto: caam - fix pointer cast in sm_keystore_slot_import
	( https://linux.nxdi.nxp.com/patchwork/patch/71174/ )

that have been reworked:

4.
-make SM depend on JR
-enable SM, SECVIO only on i.MX SoCs
-fix resource leak - add off_node_put() where needed
-remove unused sm_size

Split commit in three:
1 - SNVS/SECVIO driver
2 - Secure Memory driver
3 - DT changes

11.
Clock handling dropped - logic already upstream.

17.
Keep only Secure Memory related changes.
Changes related to page 0 registers have been added previously.
Other changes are dropped.

21.
Always use first jr in ctrlpriv->jr[] array to access registers
in page 0 (aliased in jr page), irrespective of SCU presence.

35.
Split the patch in three (SECVIO, SM, UIO)

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Horia Geantă
3e0e4550c7 MLKU-38-3 crypto: caam - add SNVS / SECVIO support
This is a squash of the following i.MX BSP commits
(rel_imx_4.19.35_1.1.0_rc2)

1. 8f6a17b419 ("ENGR00289885 [iMX6Q] Add Secure Memory and SECVIO support.")
2. 8433c811e9 ("MLK-9710-18 snvs - make SECVIO module device tree correct")
3. 35bbc34e99 ("MLK-9769-23 Replace SECVIO of_irq_to_resource() with irq_of_parse_and_map()")
4. 3ac6edcd92 ("MLK-11360-01 crypto: caam_snvs: add snvs clock management")
5. 9d9ca7a03e ("MLK-11922 i.mx6: Linux 3.14.28 CAAM & SNVS enabled by default. JTAG, DS-5 attachment causes exceptions")
6. fcdaabf1bb ("MLK-17412-01: Fix secvio driver to have same driver name as DTS")

Signed-off-by: Dan Douglass <dan.douglass@nxp.com>
Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
Signed-off-by: Steve Cornelius <steve.cornelius@nxp.com>
Signed-off-by: Fugang Duan <andy.duan@nxp.com>
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>

and LF commits (lf-5.4.y-1.0.1-rc1):

7. 5560b49b53 ("LF-644 crypto: caam - initialize svlock spinlock")
8. ab44d61204 ("MLK-23774 crypto: caam - fix SNVS / SECVIO building as module")

and LF commits (rebase-20200918/crypto/caam):
9.  35b042de1df6 ("crypto: caam - fix snvs clk prepare+enable")
10. bfeb0bffc35a ("crypto: caam - build config changes")

and LF commit
11. MLK-21689 crypto: caam - make snvs clock optional

that have been reworked:

1.
-make SM depend on JR
-enable SM, SECVIO only on i.MX SoCs
-fix resource leak - add off_node_put() where needed

Split commit in three:
- SNVS/SECVIO driver
- Secure Memory driver
- DT changes

3.
JR changes dropped - no longer needed, already upstream in
commit 549077d7d8 ("crypto: caam - check irq_of_parse_and_map for errors")

4.
Split the patch in two:
-DT bindings changes
-driver changes

5.
Fixed conflicts in imx7d.dtsi - added caam_sm and irq_sec_vio nodes.

10.
Split the patch in three (SECVIO, SM, UIO)

Split commit in 3:
-SECVIO/SNVS driver changes
-SECVIO/SNVS DT changes
-Secure Memory DT changes

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:35 +08:00
Horia Geantă
4122956226 MLKU-114-2 crypto: caam - SCU firmware support
Some i.MX8 processors, e.g. i.MX8QM (QM, QP), i.MX8QX (QXP, DX) have a
System Controller Firmware (SCFW) running on a dedicated Cortex-M core
that provides power, clock, and resource management.

caam driver needs to be aware of SCU f/w presence, since some things
are done differently:

1. clocks are under SCU f/w control and are turned on automatically

2. there is no access to controller's register page (note however that
some registers are aliased in job rings' register pages)

It's worth mentioning that due to this, MCFGR[PS] cannot be read
and driver assumes MCFGR[PS] = b'0 - engine using 32-bit address pointers.
This is in sync with the limitation imposed by the
SECO (Security Controller) ROM and f/w running on a dedicated Cortex-M.

3. as a consequence of "2.", part of the initialization is moved in
other f/w (SCU, TF-A etc.), e.g. RNG initialization

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2023-10-30 17:37:34 +08:00
Horia Geantă
9c82cca5f1 crypto: caam/qi2 - refactor skipcher, aead {en,de}crypt ops
Commit 1984aaeec3 ("crypto: caam - fix return code in completion callbacks")
made changes in the skcipher and aead *_done() callbacks,
practically the *_encrypt_done() and *_decrypt_done() being the same.

Refactor code such that identical code is removed.
After this it makes sense to refactor also skipcher, aead {en,de}crypt ops.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2023-10-30 17:37:34 +08:00
zhenwei pi
fa2e6947aa virtio-crypto: handle config changed by work queue
MST pointed out: config change callback is also handled incorrectly
in this driver, it takes a mutex from interrupt context.

Handle config changed by work queue instead.

Cc: stable@vger.kernel.org
Cc: Gonglei (Arei) <arei.gonglei@huawei.com>
Cc: Halil Pasic <pasic@linux.ibm.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20231007064309.844889-1-pizhenwei@bytedance.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2023-10-18 11:30:06 -04:00
Linus Torvalds
68cf01760b This update includes the following changes:
API:
 
 - Move crypto engine callback from tfm ctx into algorithm object.
 - Fix atomic sleep bug in crypto_destroy_instance.
 - Move lib/mpi into lib/crypto.
 
 Algorithms:
 
 - Add chacha20 and poly1305 implementation for powerpc p10.
 
 Drivers:
 
 - Add AES skcipher and aead support to starfive.
 - Add Dynamic Boost Control support to ccp.
 - Add support for STM32P13 platform to stm32.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEn51F/lCuNhUwmDeSxycdCkmxi6cFAmTsZkMACgkQxycdCkmx
 i6furw//e6kYK1CTOqidPM6nI0KK1Ok204VXu56H0wM4THZ09ZwcbDNKpvI6vjMi
 XZkKthiayl/1okmpRVP0rPqMWDtxajeu6IUAQqqFGUFU8R7AqCDrOd+te+zlSFWG
 16ySNQO47RND0OzNqZ4ojgCC0n9RpP+zOfndmderZ4EnfXSbodwGUwkcuE7Z96cP
 jNoainO2iwlyMZPlVynrw61O3RxGu/s/ch+uY1mV+TyvAAWoOlzt57gYUs3eGduz
 4Ky+0Ubctg3sfBaqA2Hg6GjtAqG/QUssRyj8YgsFMrgXPHDTbLh6abej39wWo4gz
 ZdC7Bm47hV/yfVdWe2iq3/5iqdILEdPBh3fDh6NNsZ1Jlm3aEZpH9rEXm0k4X2MJ
 A9NDAFVj8dAYVZza7+Y8jPc8FNe+HqN9HYip/2K7g68WAJGWnMc9lq9qGwGmg1Gl
 dn6yM27AgH8B+UljWYM9FS1ZFsc8KCudJavRZqA2d0W3rbXVWAoBBp83ii0yX1Nm
 ZPAblAYMZCDeCtrVrDYKLtGn566rfpCrv3R5cppwHLksGJsDxgWrjG47l9uy5HXI
 u05jiXT11R+pjIU2Wv5qsiUIhyvli6AaiFYHIdZ8fWaovPAOdhrCrN3IryvUVHj/
 LqMcnmW1rWGNYN9pqHn0sQZ730ZJIma0klhTZOn8HPJNbiK68X0=
 =LbcA
 -----END PGP SIGNATURE-----

Merge tag 'v6.6-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Pull crypto updates from Herbert Xu:
 "API:
   - Move crypto engine callback from tfm ctx into algorithm object
   - Fix atomic sleep bug in crypto_destroy_instance
   - Move lib/mpi into lib/crypto

  Algorithms:
   - Add chacha20 and poly1305 implementation for powerpc p10

  Drivers:
   - Add AES skcipher and aead support to starfive
   - Add Dynamic Boost Control support to ccp
   - Add support for STM32P13 platform to stm32"

* tag 'v6.6-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (149 commits)
  Revert "dt-bindings: crypto: qcom,prng: Add SM8450"
  crypto: chelsio - Remove unused declarations
  X.509: if signature is unsupported skip validation
  crypto: qat - fix crypto capability detection for 4xxx
  crypto: drivers - Explicitly include correct DT includes
  crypto: engine - Remove crypto_engine_ctx
  crypto: zynqmp - Use new crypto_engine_op interface
  crypto: virtio - Use new crypto_engine_op interface
  crypto: stm32 - Use new crypto_engine_op interface
  crypto: jh7110 - Use new crypto_engine_op interface
  crypto: rk3288 - Use new crypto_engine_op interface
  crypto: omap - Use new crypto_engine_op interface
  crypto: keembay - Use new crypto_engine_op interface
  crypto: sl3516 - Use new crypto_engine_op interface
  crypto: caam - Use new crypto_engine_op interface
  crypto: aspeed - Remove non-standard sha512 algorithms
  crypto: aspeed - Use new crypto_engine_op interface
  crypto: amlogic - Use new crypto_engine_op interface
  crypto: sun8i-ss - Use new crypto_engine_op interface
  crypto: sun8i-ce - Use new crypto_engine_op interface
  ...
2023-08-29 11:23:29 -07:00
Linus Torvalds
e5b7ca09e9 s390 updates for 6.6 merge window
- Add vfio-ap support to pass-through crypto devices to secure execution
   guests
 
 - Add API ordinal 6 support to zcrypt_ep11misc device drive, which is
   required to handle key generate and key derive (e.g. secure key to
   protected key) correctly
 
 - Add missing secure/has_secure sysfs files for the case where it is not
   possible to figure where a system has been booted from. Existing user
   space relies on that these files are always present
 
 - Fix DCSS block device driver list corruption, caused by incorrect
   error handling
 
 - Convert virt_to_pfn() and pfn_to_virt() from defines to static inline
   functions to enforce type checking
 
 - Cleanups, improvements, and minor fixes to the kernel mapping setup
 
 - Fix various virtual vs physical address confusions
 
 - Move pfault code to separate file, since it has nothing to do with
   regular fault handling
 
 - Move s390 documentation to Documentation/arch/ like it has been done
   for other architectures already
 
 - Add HAVE_FUNCTION_GRAPH_RETVAL support
 
 - Factor out the s390_hypfs filesystem and add a new config option for
   it. The filesystem is deprecated and as soon as all users are gone it
   can be removed some time in the not so near future
 
 - Remove support for old CEX2 and CEX3 crypto cards from zcrypt device
   driver
 
 - Add support for user-defined certificates: receive user-defined
   certificates with a diagnose call and provide them via 'cert_store'
   keyring to user space
 
 - Couple of other small fixes and improvements all over the place
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEECMNfWEw3SLnmiLkZIg7DeRspbsIFAmTrqNYACgkQIg7DeRsp
 bsKkUBAApWXr3WCJA2tige34AnFwmskx4sBxl/fgwcwJrC55fED1jKWaiXOM6isv
 P+hqavZnks3gXZdYcD3kxXkNMh+fPNWw7BAL35J5Gu1VShA/jlbTC6ZrvUO3t+Fy
 NsdLvBDbNDdyUzQF7w0Xb0jyIxqhJTRyhLfR5oXES63FHomv2F/vofu4jWR/q+cc
 F9mcnoDeN4zLdssdvl6WtPX4nEY9RpG0QOh67drnxuq+8v7sL8gKN4ti94Rp6vhs
 g4NhNs9xgRIPoOcX2KlSIdFqO9P12jSXZq0G4HcOp8UGQvgU/mS+UG3pQwV3ZJLS
 3/kUJZ4/CwQa1xUFtPGP1/4AngGNOnhT9FCD4KrqjDkRZmLsd5RvURe6L1zQ3vbZ
 KnX7q0Otx4xRVYPlbHb9aP+tC7f3Q10ytBAps616qZoA/2SMss2BLZiiPBpCCvDp
 L+9dRhBGYCP2PSe6H/qGQFfMW+uY7QF+NDcDAT5mX1lS8OVrGJxqM7Q+sY2pMLGo
 5nR16LvM9g6W/ZnsVn0+BWg4CgaPMi+PMfMPxs/o9RG+/0d1AJx1aLSiHdP1pXog
 8/Wg4GaaJ27S4Ers0JUmH7VDO+QkkLvAArstjk8l59r1XslWiBP5USebkxtgu6EQ
 ehAh0+oa432ALq8Rn1FK/X+pWFumbTVf8OPwR8YEjDbeTPIBCqg=
 =ewd9
 -----END PGP SIGNATURE-----

Merge tag 's390-6.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux

Pull s390 updates from Heiko Carstens:

 - Add vfio-ap support to pass-through crypto devices to secure
   execution guests

 - Add API ordinal 6 support to zcrypt_ep11misc device drive, which is
   required to handle key generate and key derive (e.g. secure key to
   protected key) correctly

 - Add missing secure/has_secure sysfs files for the case where it is
   not possible to figure where a system has been booted from. Existing
   user space relies on that these files are always present

 - Fix DCSS block device driver list corruption, caused by incorrect
   error handling

 - Convert virt_to_pfn() and pfn_to_virt() from defines to static inline
   functions to enforce type checking

 - Cleanups, improvements, and minor fixes to the kernel mapping setup

 - Fix various virtual vs physical address confusions

 - Move pfault code to separate file, since it has nothing to do with
   regular fault handling

 - Move s390 documentation to Documentation/arch/ like it has been done
   for other architectures already

 - Add HAVE_FUNCTION_GRAPH_RETVAL support

 - Factor out the s390_hypfs filesystem and add a new config option for
   it. The filesystem is deprecated and as soon as all users are gone it
   can be removed some time in the not so near future

 - Remove support for old CEX2 and CEX3 crypto cards from zcrypt device
   driver

 - Add support for user-defined certificates: receive user-defined
   certificates with a diagnose call and provide them via 'cert_store'
   keyring to user space

 - Couple of other small fixes and improvements all over the place

* tag 's390-6.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (66 commits)
  s390/pci: use builtin_misc_device macro to simplify the code
  s390/vfio-ap: make sure nib is shared
  KVM: s390: export kvm_s390_pv*_is_protected functions
  s390/uv: export uv_pin_shared for direct usage
  s390/vfio-ap: check for TAPQ response codes 0x35 and 0x36
  s390/vfio-ap: handle queue state change in progress on reset
  s390/vfio-ap: use work struct to verify queue reset
  s390/vfio-ap: store entire AP queue status word with the queue object
  s390/vfio-ap: remove upper limit on wait for queue reset to complete
  s390/vfio-ap: allow deconfigured queue to be passed through to a guest
  s390/vfio-ap: wait for response code 05 to clear on queue reset
  s390/vfio-ap: clean up irq resources if possible
  s390/vfio-ap: no need to check the 'E' and 'I' bits in APQSW after TAPQ
  s390/ipl: refactor deprecated strncpy
  s390/ipl: fix virtual vs physical address confusion
  s390/zcrypt_ep11misc: support API ordinal 6 with empty pin-blob
  s390/paes: fix PKEY_TYPE_EP11_AES handling for secure keyblobs
  s390/pkey: fix PKEY_TYPE_EP11_AES handling for sysfs attributes
  s390/pkey: fix PKEY_TYPE_EP11_AES handling in PKEY_VERIFYKEY2 IOCTL
  s390/pkey: fix PKEY_TYPE_EP11_AES handling in PKEY_KBLOB2PROTK[23]
  ...
2023-08-28 17:22:39 -07:00
Yue Haibing
9687daf785 crypto: chelsio - Remove unused declarations
These declarations are not implemented now, remove them.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-25 18:46:55 +08:00
Adam Guerin
fab9516f02 crypto: qat - fix crypto capability detection for 4xxx
When extending the capability detection logic for 4xxx devices the
SMx algorithms were accidentally missed.
Enable these SMx capabilities by default for QAT GEN4 devices.

Check for device variants where the SMx algorithms are explicitly
disabled by the GEN4 hardware. This is indicated in fusectl1
register.
Mask out SM3 and SM4 based on a bit specific to those algorithms.
Mask out SM2 if the PKE slice is not present.

Fixes: 4b44d28c71 ("crypto: qat - extend crypto capability detection for 4xxx")
Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Fiona Trahe <fiona.trahe@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-25 18:46:55 +08:00
Rob Herring
b0cc7491c9 crypto: drivers - Explicitly include correct DT includes
The DT of_device.h and of_platform.h date back to the separate
of_platform_bus_type before it as merged into the regular platform bus.
As part of that merge prepping Arm DT support 13 years ago, they
"temporarily" include each other. They also include platform_device.h
and of.h. As a result, there's a pretty much random mix of those include
files used throughout the tree. In order to detangle these headers and
replace the implicit includes with struct declarations, users need to
explicitly include the correct includes.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-23 11:04:23 +08:00
Herbert Xu
28f860d377 crypto: zynqmp - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
7a2673d70c crypto: virtio - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
d5e6b48f94 crypto: stm32 - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
982213e473 crypto: jh7110 - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
1a15d26c31 crypto: rk3288 - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
03906fba75 crypto: omap - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
530d7b009d crypto: keembay - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:11 +08:00
Herbert Xu
67b7702c5b crypto: sl3516 - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
623814c040 crypto: caam - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
d33a6a3f5a crypto: aspeed - Remove non-standard sha512 algorithms
Algorithms must never be added to a driver unless there is a generic
implementation.  These truncated versions of sha512 slipped through.
Remove them as they are useless.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
304506f299 crypto: aspeed - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
4dd4d5e486 crypto: amlogic - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
4c19e8fb5e crypto: sun8i-ss - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
07e34cd392 crypto: sun8i-ce - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
4ac1a2d88d crypto: caam - Include internal/engine.h
Inlucde internal/engine.h because this driver uses directly
accesses attributes inside struct crypto_engine.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
b7b23ccbda crypto: omap - Include internal/engine.h
Inlucde internal/engine.h because this driver uses directly
accesses attributes inside struct crypto_engine.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
2d6a79cc2a crypto: jh7110 - Include scatterwalk.h for struct scatter_walk
Include crypto/scatterwalk.h explicitly instead of getting it
through random header files.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
1c27c0ca22 crypto: jh7110 - Include crypto/hash.h in header file
The header file jh7110-cryp uses ahash_request without including
crypto/hash.h.  Fix that by adding the inclusion.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
be8b8a950f crypto: zynqmp - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
fc0bdcb830 crypto: virtio - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
6912b79da8 crypto: stm32 - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:10 +08:00
Herbert Xu
50c546d70a crypto: jh1100 - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:09 +08:00
Herbert Xu
c66c17a0f6 crypto: rk3288 - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:09 +08:00
Herbert Xu
c752c01389 crypto: omap - Remove prepare/unprepare request
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2023-08-18 17:01:09 +08:00