From f66452a888e60fec5046c7fbdea1da1fcdaff98b Mon Sep 17 00:00:00 2001 From: Nitesh Venkatesh Date: Mon, 31 Aug 2026 06:32:33 +0000 Subject: [PATCH] crypto: qat - allow KPT disable when service is not asym The KPT (Key Protection Technology) enable sysfs attribute rejects any write when the currently enabled service is not 'asym', including writes that disable KPT. This blocks a legitimate recovery flow: 1. Configure the 'asym' service and enable KPT. 2. Bring the device up, then down. 3. Reconfigure the service to 'sym' and bring the device up. 4. KPT is still reported as enabled, but is not active because the asymmetric service is no longer configured. 5. Bring the device back down so the KPT enable attribute becomes writable. 6. Writing '0' to the KPT enable attribute to clear the stale flag fails with: "KPT can only be enabled when the asymmetric service is enabled" The asym-service check is only meaningful when enabling KPT; disabling must always be permitted so a stale enable flag can be cleared after the service configuration has changed. Parse the user-supplied boolean before the service check and gate the check on the enable direction. Disable requests are now accepted regardless of the currently configured service, provided the device is in the down state (which the attribute already requires for any write). Fixes: fb98254a5eb9 ("crypto: qat - add KPT support for GEN6 devices") Signed-off-by: Nitesh Venkatesh Reviewed-by: Giovanni Cabiddu Reviewed-by: Ahsan Atta Signed-off-by: Herbert Xu --- .../intel/qat/qat_common/adf_sysfs_kpt.c | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/adf_sysfs_kpt.c b/drivers/crypto/intel/qat/qat_common/adf_sysfs_kpt.c index 1f733ae80bdf..a0db98f33f1f 100644 --- a/drivers/crypto/intel/qat/qat_common/adf_sysfs_kpt.c +++ b/drivers/crypto/intel/qat/qat_common/adf_sysfs_kpt.c @@ -31,6 +31,7 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, struct adf_hw_device_data *hw_data; struct adf_accel_dev *accel_dev; bool enable; + int svc; int ret; accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev)); @@ -38,14 +39,25 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, return -EINVAL; if (adf_dev_started(accel_dev)) { - dev_info(dev, "Device qat_dev%d must be down before enabling KPT\n", + dev_info(dev, "Device qat_dev%d must be down before changing KPT state\n", accel_dev->accel_id); return -EINVAL; } - if (adf_get_service_enabled(accel_dev) != SVC_ASYM) { - dev_info(dev, "KPT can only be enabled when the asymmetric service is enabled\n"); - return -EINVAL; + ret = kstrtobool(buf, &enable); + if (ret) + return ret; + + if (enable) { + svc = adf_get_service_enabled(accel_dev); + if (svc < 0) + return svc; + + if (svc != SVC_ASYM) { + dev_info(dev, + "KPT can only be enabled when the asymmetric crypto service is enabled\n"); + return -EINVAL; + } } hw_data = GET_HW_DATA(accel_dev); @@ -59,10 +71,6 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, if (!hw_data->accel_capabilities_mask) return -EINVAL; - ret = kstrtobool(buf, &enable); - if (ret) - return ret; - user_data = GET_KPT_USER_DATA(accel_dev); user_data->enable = enable;