Skip to content

Commit a62b8f8

Browse files
davejiangvinodkoul
authored andcommitted
dmaengine: idxd: add pid to exported sysfs attribute for opened file
Provide the pid of the application for the opened file. This allows the monitor daemon to easily correlate which app opened the file and easily kill the app by pid if that is desired action. 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-16-fenghua.yu@intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 244009b commit a62b8f8

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,11 @@ Description: Show the number of Completion Record (CR) faults failures that this
335335
driver cannot fault in the address for the CR. Typically this is caused
336336
by a bad address programmed in the submitted descriptor or a malicious
337337
submitter is using bad CR address on purpose.
338+
339+
What: /sys/bus/dsa/devices/wq<m>.<n>/dsa<x>\!wq<m>.<n>/file<y>/pid
340+
Date: Sept 14, 2022
341+
KernelVersion: 6.4.0
342+
Contact: dmaengine@vger.kernel.org
343+
Description: Show the process id of the application that opened the file. This is
344+
helpful information for a monitor daemon that wants to kill the
345+
application that opened the file.

drivers/dma/idxd/cdev.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct idxd_user_context {
4949
struct idxd_dev idxd_dev;
5050
u64 counters[COUNTER_MAX];
5151
int id;
52+
pid_t pid;
5253
};
5354

5455
static void idxd_cdev_evl_drain_pasid(struct idxd_wq *wq, u32 pasid);
@@ -78,9 +79,18 @@ static ssize_t cr_fault_failures_show(struct device *dev,
7879
}
7980
static DEVICE_ATTR_RO(cr_fault_failures);
8081

82+
static ssize_t pid_show(struct device *dev, struct device_attribute *attr, char *buf)
83+
{
84+
struct idxd_user_context *ctx = dev_to_uctx(dev);
85+
86+
return sysfs_emit(buf, "%u\n", ctx->pid);
87+
}
88+
static DEVICE_ATTR_RO(pid);
89+
8190
static struct attribute *cdev_file_attributes[] = {
8291
&dev_attr_cr_faults.attr,
8392
&dev_attr_cr_fault_failures.attr,
93+
&dev_attr_pid.attr,
8494
NULL
8595
};
8696

@@ -238,6 +248,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
238248

239249
ctx->wq = wq;
240250
filp->private_data = ctx;
251+
ctx->pid = current->pid;
241252

242253
if (device_user_pasid_enabled(idxd)) {
243254
sva = iommu_sva_bind_device(dev, current->mm);

0 commit comments

Comments
 (0)