dmaengine: idxd: add per wq PRS disable
authorDave Jiang <dave.jiang@intel.com>
Fri, 7 Apr 2023 20:31:43 +0000 (13:31 -0700)
committerVinod Koul <vkoul@kernel.org>
Wed, 12 Apr 2023 17:48:46 +0000 (23:18 +0530)
Add sysfs knob for per wq Page Request Service disable. This knob
disables PRS support for the specific wq. When this bit is set,
it also overrides the wq's block on fault enabling.

Tested-by: Tony Zhu <tony.zhu@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: https://lore.kernel.org/r/20230407203143.2189681-17-fenghua.yu@intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Documentation/ABI/stable/sysfs-driver-dma-idxd
drivers/dma/idxd/device.c
drivers/dma/idxd/idxd.h
drivers/dma/idxd/registers.h
drivers/dma/idxd/sysfs.c

index 5d0df57..534b7a3 100644 (file)
@@ -235,6 +235,16 @@ Contact:   dmaengine@vger.kernel.org
 Description:   Indicate whether ATS disable is turned on for the workqueue.
                0 indicates ATS is on, and 1 indicates ATS is off for the workqueue.
 
+What:          /sys/bus/dsa/devices/wq<m>.<n>/prs_disable
+Date:          Sept 14, 2022
+KernelVersion: 6.4.0
+Contact:       dmaengine@vger.kernel.org
+Description:   Controls whether PRS disable is turned on for the workqueue.
+               0 indicates PRS is on, and 1 indicates PRS is off for the
+               workqueue. This option overrides block_on_fault attribute
+               if set. It's visible only on platforms that support the
+               capability.
+
 What:          /sys/bus/dsa/devices/wq<m>.<n>/occupancy
 Date           May 25, 2021
 KernelVersion: 5.14.0
index fd97b2b..3c80b96 100644 (file)
@@ -967,12 +967,16 @@ static int idxd_wq_config_write(struct idxd_wq *wq)
        wq->wqcfg->priority = wq->priority;
 
        if (idxd->hw.gen_cap.block_on_fault &&
-           test_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags))
+           test_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags) &&
+           !test_bit(WQ_FLAG_PRS_DISABLE, &wq->flags))
                wq->wqcfg->bof = 1;
 
        if (idxd->hw.wq_cap.wq_ats_support)
                wq->wqcfg->wq_ats_disable = test_bit(WQ_FLAG_ATS_DISABLE, &wq->flags);
 
+       if (idxd->hw.wq_cap.wq_prs_support)
+               wq->wqcfg->wq_prs_disable = test_bit(WQ_FLAG_PRS_DISABLE, &wq->flags);
+
        /* bytes 12-15 */
        wq->wqcfg->max_xfer_shift = ilog2(wq->max_xfer_bytes);
        idxd_wqcfg_set_max_batch_shift(idxd->data->type, wq->wqcfg, ilog2(wq->max_batch_size));
index bd544eb..e44b1d4 100644 (file)
@@ -143,6 +143,7 @@ enum idxd_wq_flag {
        WQ_FLAG_DEDICATED = 0,
        WQ_FLAG_BLOCK_ON_FAULT,
        WQ_FLAG_ATS_DISABLE,
+       WQ_FLAG_PRS_DISABLE,
 };
 
 enum idxd_wq_type {
index 9f3959d..7b54a39 100644 (file)
@@ -59,7 +59,8 @@ union wq_cap_reg {
                u64 occupancy:1;
                u64 occupancy_int:1;
                u64 op_config:1;
-               u64 rsvd3:9;
+               u64 wq_prs_support:1;
+               u64 rsvd4:8;
        };
        u64 bits;
 } __packed;
@@ -371,7 +372,7 @@ union wqcfg {
                u32 mode:1;     /* shared or dedicated */
                u32 bof:1;      /* block on fault */
                u32 wq_ats_disable:1;
-               u32 rsvd2:1;
+               u32 wq_prs_disable:1;
                u32 priority:4;
                u32 pasid:20;
                u32 pasid_en:1;
index 465d2e7..293739a 100644 (file)
@@ -822,10 +822,14 @@ static ssize_t wq_block_on_fault_store(struct device *dev,
        if (rc < 0)
                return rc;
 
-       if (bof)
+       if (bof) {
+               if (test_bit(WQ_FLAG_PRS_DISABLE, &wq->flags))
+                       return -EOPNOTSUPP;
+
                set_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags);
-       else
+       } else {
                clear_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags);
+       }
 
        return count;
 }
@@ -1109,6 +1113,44 @@ static ssize_t wq_ats_disable_store(struct device *dev, struct device_attribute
 static struct device_attribute dev_attr_wq_ats_disable =
                __ATTR(ats_disable, 0644, wq_ats_disable_show, wq_ats_disable_store);
 
+static ssize_t wq_prs_disable_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct idxd_wq *wq = confdev_to_wq(dev);
+
+       return sysfs_emit(buf, "%u\n", test_bit(WQ_FLAG_PRS_DISABLE, &wq->flags));
+}
+
+static ssize_t wq_prs_disable_store(struct device *dev, struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct idxd_wq *wq = confdev_to_wq(dev);
+       struct idxd_device *idxd = wq->idxd;
+       bool prs_dis;
+       int rc;
+
+       if (wq->state != IDXD_WQ_DISABLED)
+               return -EPERM;
+
+       if (!idxd->hw.wq_cap.wq_prs_support)
+               return -EOPNOTSUPP;
+
+       rc = kstrtobool(buf, &prs_dis);
+       if (rc < 0)
+               return rc;
+
+       if (prs_dis) {
+               set_bit(WQ_FLAG_PRS_DISABLE, &wq->flags);
+               /* when PRS is disabled, BOF needs to be off as well */
+               clear_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags);
+       } else {
+               clear_bit(WQ_FLAG_PRS_DISABLE, &wq->flags);
+       }
+       return count;
+}
+
+static struct device_attribute dev_attr_wq_prs_disable =
+               __ATTR(prs_disable, 0644, wq_prs_disable_show, wq_prs_disable_store);
+
 static ssize_t wq_occupancy_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct idxd_wq *wq = confdev_to_wq(dev);
@@ -1239,6 +1281,7 @@ static struct attribute *idxd_wq_attributes[] = {
        &dev_attr_wq_max_transfer_size.attr,
        &dev_attr_wq_max_batch_size.attr,
        &dev_attr_wq_ats_disable.attr,
+       &dev_attr_wq_prs_disable.attr,
        &dev_attr_wq_occupancy.attr,
        &dev_attr_wq_enqcmds_retries.attr,
        &dev_attr_wq_op_config.attr,
@@ -1260,6 +1303,13 @@ static bool idxd_wq_attr_max_batch_size_invisible(struct attribute *attr,
               idxd->data->type == IDXD_TYPE_IAX;
 }
 
+static bool idxd_wq_attr_wq_prs_disable_invisible(struct attribute *attr,
+                                                 struct idxd_device *idxd)
+{
+       return attr == &dev_attr_wq_prs_disable.attr &&
+              !idxd->hw.wq_cap.wq_prs_support;
+}
+
 static umode_t idxd_wq_attr_visible(struct kobject *kobj,
                                    struct attribute *attr, int n)
 {
@@ -1273,6 +1323,9 @@ static umode_t idxd_wq_attr_visible(struct kobject *kobj,
        if (idxd_wq_attr_max_batch_size_invisible(attr, idxd))
                return 0;
 
+       if (idxd_wq_attr_wq_prs_disable_invisible(attr, idxd))
+               return 0;
+
        return attr->mode;
 }