Skip to content

Commit 244009b

Browse files
davejiangvinodkoul
authored andcommitted
dmaengine: idxd: expose fault counters to sysfs
Expose cr_faults and cr_fault_failures counters to the user space. This allows a user app to keep track of how many fault the application is causing with the completion record (CR) and also the number of failures of the CR writeback. Having a high number of cr_fault_failures is bad as the app is submitting descriptors with the CR addresses that are bad. User monitoring daemon may want to consider killing the application as it may be malicious and attempting to flood the device event log. 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-15-fenghua.yu@intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent e6fd6d7 commit 244009b

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Documentation/ABI/stable/sysfs-driver-dma-idxd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,20 @@ Description: Allows control of the number of batch descriptors that can be
318318
1 (1/2 of max value), 2 (1/4 of the max value), and 3 (1/8 of
319319
the max value). It's visible only on platforms that support
320320
the capability.
321+
322+
What: /sys/bus/dsa/devices/wq<m>.<n>/dsa<x>\!wq<m>.<n>/file<y>/cr_faults
323+
Date: Sept 14, 2022
324+
KernelVersion: 6.4.0
325+
Contact: dmaengine@vger.kernel.org
326+
Description: Show the number of Completion Record (CR) faults this application
327+
has caused.
328+
329+
What: /sys/bus/dsa/devices/wq<m>.<n>/dsa<x>\!wq<m>.<n>/file<y>/cr_fault_failures
330+
Date: Sept 14, 2022
331+
KernelVersion: 6.4.0
332+
Contact: dmaengine@vger.kernel.org
333+
Description: Show the number of Completion Record (CR) faults failures that this
334+
application has caused. The failure counter is incremented when the
335+
driver cannot fault in the address for the CR. Typically this is caused
336+
by a bad address programmed in the submitted descriptor or a malicious
337+
submitter is using bad CR address on purpose.

drivers/dma/idxd/cdev.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,51 @@ static inline struct idxd_user_context *dev_to_uctx(struct device *dev)
6161
return container_of(idxd_dev, struct idxd_user_context, idxd_dev);
6262
}
6363

64+
static ssize_t cr_faults_show(struct device *dev, struct device_attribute *attr, char *buf)
65+
{
66+
struct idxd_user_context *ctx = dev_to_uctx(dev);
67+
68+
return sysfs_emit(buf, "%llu\n", ctx->counters[COUNTER_FAULTS]);
69+
}
70+
static DEVICE_ATTR_RO(cr_faults);
71+
72+
static ssize_t cr_fault_failures_show(struct device *dev,
73+
struct device_attribute *attr, char *buf)
74+
{
75+
struct idxd_user_context *ctx = dev_to_uctx(dev);
76+
77+
return sysfs_emit(buf, "%llu\n", ctx->counters[COUNTER_FAULT_FAILS]);
78+
}
79+
static DEVICE_ATTR_RO(cr_fault_failures);
80+
81+
static struct attribute *cdev_file_attributes[] = {
82+
&dev_attr_cr_faults.attr,
83+
&dev_attr_cr_fault_failures.attr,
84+
NULL
85+
};
86+
87+
static umode_t cdev_file_attr_visible(struct kobject *kobj, struct attribute *a, int n)
88+
{
89+
struct device *dev = container_of(kobj, typeof(*dev), kobj);
90+
struct idxd_user_context *ctx = dev_to_uctx(dev);
91+
struct idxd_wq *wq = ctx->wq;
92+
93+
if (!wq_pasid_enabled(wq))
94+
return 0;
95+
96+
return a->mode;
97+
}
98+
99+
static const struct attribute_group cdev_file_attribute_group = {
100+
.attrs = cdev_file_attributes,
101+
.is_visible = cdev_file_attr_visible,
102+
};
103+
104+
static const struct attribute_group *cdev_file_attribute_groups[] = {
105+
&cdev_file_attribute_group,
106+
NULL
107+
};
108+
64109
static void idxd_file_dev_release(struct device *dev)
65110
{
66111
struct idxd_user_context *ctx = dev_to_uctx(dev);
@@ -100,6 +145,7 @@ static void idxd_file_dev_release(struct device *dev)
100145
static struct device_type idxd_cdev_file_type = {
101146
.name = "idxd_file",
102147
.release = idxd_file_dev_release,
148+
.groups = cdev_file_attribute_groups,
103149
};
104150

105151
static void idxd_cdev_dev_release(struct device *dev)

0 commit comments

Comments
 (0)