Skip to content

Commit 50d527f

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/mem: Add debugfs attributes for poison inject and clear
Inject and Clear Poison commands are optionally supported by CXL memdev devices and are intended for use in debug environments only. Add debugfs attributes for user access. Documentation/ABI/testing/debugfs-cxl describes the usage. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/0c9ea8e671b8e58465d18722788b60d325c675c7.1681874357.git.alison.schofield@intel.com Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 98b6926 commit 50d527f

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
What: /sys/kernel/debug/cxl/memX/inject_poison
2+
Date: April, 2023
3+
KernelVersion: v6.4
4+
Contact: linux-cxl@vger.kernel.org
5+
Description:
6+
(WO) When a Device Physical Address (DPA) is written to this
7+
attribute, the memdev driver sends an inject poison command to
8+
the device for the specified address. The DPA must be 64-byte
9+
aligned and the length of the injected poison is 64-bytes. If
10+
successful, the device returns poison when the address is
11+
accessed through the CXL.mem bus. Injecting poison adds the
12+
address to the device's Poison List and the error source is set
13+
to Injected. In addition, the device adds a poison creation
14+
event to its internal Informational Event log, updates the
15+
Event Status register, and if configured, interrupts the host.
16+
It is not an error to inject poison into an address that
17+
already has poison present and no error is returned. The
18+
inject_poison attribute is only visible for devices supporting
19+
the capability.
20+
21+
22+
What: /sys/kernel/debug/memX/clear_poison
23+
Date: April, 2023
24+
KernelVersion: v6.4
25+
Contact: linux-cxl@vger.kernel.org
26+
Description:
27+
(WO) When a Device Physical Address (DPA) is written to this
28+
attribute, the memdev driver sends a clear poison command to
29+
the device for the specified address. Clearing poison removes
30+
the address from the device's Poison List and writes 0 (zero)
31+
for 64 bytes starting at address. It is not an error to clear
32+
poison from an address that does not have poison set. If the
33+
device cannot clear poison from the address, -ENXIO is returned.
34+
The clear_poison attribute is only visible for devices
35+
supporting the capability.

drivers/cxl/mem.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd,
9494
return 0;
9595
}
9696

97+
static int cxl_debugfs_poison_inject(void *data, u64 dpa)
98+
{
99+
struct cxl_memdev *cxlmd = data;
100+
101+
return cxl_inject_poison(cxlmd, dpa);
102+
}
103+
104+
DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_inject_fops, NULL,
105+
cxl_debugfs_poison_inject, "%llx\n");
106+
107+
static int cxl_debugfs_poison_clear(void *data, u64 dpa)
108+
{
109+
struct cxl_memdev *cxlmd = data;
110+
111+
return cxl_clear_poison(cxlmd, dpa);
112+
}
113+
114+
DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
115+
cxl_debugfs_poison_clear, "%llx\n");
116+
97117
static int cxl_mem_probe(struct device *dev)
98118
{
99119
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
@@ -117,6 +137,14 @@ static int cxl_mem_probe(struct device *dev)
117137

118138
dentry = cxl_debugfs_create_dir(dev_name(dev));
119139
debugfs_create_devm_seqfile(dev, "dpamem", dentry, cxl_mem_dpa_show);
140+
141+
if (test_bit(CXL_POISON_ENABLED_INJECT, cxlds->poison.enabled_cmds))
142+
debugfs_create_file("inject_poison", 0200, dentry, cxlmd,
143+
&cxl_poison_inject_fops);
144+
if (test_bit(CXL_POISON_ENABLED_CLEAR, cxlds->poison.enabled_cmds))
145+
debugfs_create_file("clear_poison", 0200, dentry, cxlmd,
146+
&cxl_poison_clear_fops);
147+
120148
rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
121149
if (rc)
122150
return rc;

0 commit comments

Comments
 (0)