Commit a62b8f87 authored by Dave Jiang's avatar Dave Jiang Committed by Vinod Koul

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: default avatarTony Zhu <tony.zhu@intel.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Co-developed-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Link: https://lore.kernel.org/r/20230407203143.2189681-16-fenghua.yu@intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 244009b0
...@@ -335,3 +335,11 @@ Description: Show the number of Completion Record (CR) faults failures that this ...@@ -335,3 +335,11 @@ Description: Show the number of Completion Record (CR) faults failures that this
driver cannot fault in the address for the CR. Typically this is caused driver cannot fault in the address for the CR. Typically this is caused
by a bad address programmed in the submitted descriptor or a malicious by a bad address programmed in the submitted descriptor or a malicious
submitter is using bad CR address on purpose. submitter is using bad CR address on purpose.
What: /sys/bus/dsa/devices/wq<m>.<n>/dsa<x>\!wq<m>.<n>/file<y>/pid
Date: Sept 14, 2022
KernelVersion: 6.4.0
Contact: dmaengine@vger.kernel.org
Description: Show the process id of the application that opened the file. This is
helpful information for a monitor daemon that wants to kill the
application that opened the file.
...@@ -49,6 +49,7 @@ struct idxd_user_context { ...@@ -49,6 +49,7 @@ struct idxd_user_context {
struct idxd_dev idxd_dev; struct idxd_dev idxd_dev;
u64 counters[COUNTER_MAX]; u64 counters[COUNTER_MAX];
int id; int id;
pid_t pid;
}; };
static void idxd_cdev_evl_drain_pasid(struct idxd_wq *wq, u32 pasid); 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, ...@@ -78,9 +79,18 @@ static ssize_t cr_fault_failures_show(struct device *dev,
} }
static DEVICE_ATTR_RO(cr_fault_failures); static DEVICE_ATTR_RO(cr_fault_failures);
static ssize_t pid_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct idxd_user_context *ctx = dev_to_uctx(dev);
return sysfs_emit(buf, "%u\n", ctx->pid);
}
static DEVICE_ATTR_RO(pid);
static struct attribute *cdev_file_attributes[] = { static struct attribute *cdev_file_attributes[] = {
&dev_attr_cr_faults.attr, &dev_attr_cr_faults.attr,
&dev_attr_cr_fault_failures.attr, &dev_attr_cr_fault_failures.attr,
&dev_attr_pid.attr,
NULL NULL
}; };
...@@ -238,6 +248,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) ...@@ -238,6 +248,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
ctx->wq = wq; ctx->wq = wq;
filp->private_data = ctx; filp->private_data = ctx;
ctx->pid = current->pid;
if (device_user_pasid_enabled(idxd)) { if (device_user_pasid_enabled(idxd)) {
sva = iommu_sva_bind_device(dev, current->mm); sva = iommu_sva_bind_device(dev, current->mm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment