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: fb98254a5e ("crypto: qat - add KPT support for GEN6 devices")
Signed-off-by: Nitesh Venkatesh <nitesh.venkatesh@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Nitesh Venkatesh 2026-08-31 06:32:33 +00:00 committed by Herbert Xu
parent 9e06d37173
commit f66452a888

View File

@ -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;