Skip to content

Commit 7ff6ad1

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/memdev: Add trigger_poison_list sysfs attribute
When a boolean 'true' is written to this attribute the memdev driver retrieves the poison list from the device. The list consists of addresses that are poisoned, or would result in poison if accessed, and the source of the poison. This attribute is only visible for devices supporting the capability. The retrieved errors are logged as kernel events when cxl_poison event tracing is enabled. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/1081cfdc8a349dc754779642d584707e56db26ba.1681838291.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 ddf49d5 commit 7ff6ad1

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,17 @@ Description:
415415
1), and checks that the hardware accepts the commit request.
416416
Reading this value indicates whether the region is committed or
417417
not.
418+
419+
420+
What: /sys/bus/cxl/devices/memX/trigger_poison_list
421+
Date: April, 2023
422+
KernelVersion: v6.4
423+
Contact: linux-cxl@vger.kernel.org
424+
Description:
425+
(WO) When a boolean 'true' is written to this attribute the
426+
memdev driver retrieves the poison list from the device. The
427+
list consists of addresses that are poisoned, or would result
428+
in poison if accessed, and the source of the poison. This
429+
attribute is only visible for devices supporting the
430+
capability. The retrieved errors are logged as kernel
431+
events when cxl_poison event tracing is enabled.

drivers/cxl/core/memdev.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,49 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
106106
}
107107
static DEVICE_ATTR_RO(numa_node);
108108

109+
static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
110+
{
111+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
112+
u64 offset, length;
113+
int rc = 0;
114+
115+
/* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
116+
if (resource_size(&cxlds->pmem_res)) {
117+
offset = cxlds->pmem_res.start;
118+
length = resource_size(&cxlds->pmem_res);
119+
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
120+
if (rc)
121+
return rc;
122+
}
123+
if (resource_size(&cxlds->ram_res)) {
124+
offset = cxlds->ram_res.start;
125+
length = resource_size(&cxlds->ram_res);
126+
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
127+
/*
128+
* Invalid Physical Address is not an error for
129+
* volatile addresses. Device support is optional.
130+
*/
131+
if (rc == -EFAULT)
132+
rc = 0;
133+
}
134+
return rc;
135+
}
136+
137+
int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
138+
{
139+
int rc;
140+
141+
rc = down_read_interruptible(&cxl_dpa_rwsem);
142+
if (rc)
143+
return rc;
144+
145+
rc = cxl_get_poison_by_memdev(cxlmd);
146+
up_read(&cxl_dpa_rwsem);
147+
148+
return rc;
149+
}
150+
EXPORT_SYMBOL_NS_GPL(cxl_trigger_poison_list, CXL);
151+
109152
static struct attribute *cxl_memdev_attributes[] = {
110153
&dev_attr_serial.attr,
111154
&dev_attr_firmware_version.attr,

drivers/cxl/cxlmem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct cxl_mbox_cmd {
145145
C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"), \
146146
C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"), \
147147
C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"), \
148-
C(PADDR, -ENXIO, "physical address specified is invalid"), \
148+
C(PADDR, -EFAULT, "physical address specified is invalid"), \
149149
C(POISONLMT, -ENXIO, "poison injection limit has been reached"), \
150150
C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"), \
151151
C(ABORT, -ENXIO, "background cmd was aborted by device"), \
@@ -688,6 +688,7 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds);
688688
int cxl_poison_state_init(struct cxl_dev_state *cxlds);
689689
int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
690690
struct cxl_region *cxlr);
691+
int cxl_trigger_poison_list(struct cxl_memdev *cxlmd);
691692

692693
#ifdef CONFIG_CXL_SUSPEND
693694
void cxl_mem_active_inc(void);

drivers/cxl/mem.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,53 @@ static int cxl_mem_probe(struct device *dev)
176176
return devm_add_action_or_reset(dev, enable_suspend, NULL);
177177
}
178178

179+
static ssize_t trigger_poison_list_store(struct device *dev,
180+
struct device_attribute *attr,
181+
const char *buf, size_t len)
182+
{
183+
bool trigger;
184+
int rc;
185+
186+
if (kstrtobool(buf, &trigger) || !trigger)
187+
return -EINVAL;
188+
189+
rc = cxl_trigger_poison_list(to_cxl_memdev(dev));
190+
191+
return rc ? rc : len;
192+
}
193+
static DEVICE_ATTR_WO(trigger_poison_list);
194+
195+
static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n)
196+
{
197+
if (a == &dev_attr_trigger_poison_list.attr) {
198+
struct device *dev = kobj_to_dev(kobj);
199+
200+
if (!test_bit(CXL_POISON_ENABLED_LIST,
201+
to_cxl_memdev(dev)->cxlds->poison.enabled_cmds))
202+
return 0;
203+
}
204+
return a->mode;
205+
}
206+
207+
static struct attribute *cxl_mem_attrs[] = {
208+
&dev_attr_trigger_poison_list.attr,
209+
NULL
210+
};
211+
212+
static struct attribute_group cxl_mem_group = {
213+
.attrs = cxl_mem_attrs,
214+
.is_visible = cxl_mem_visible,
215+
};
216+
217+
__ATTRIBUTE_GROUPS(cxl_mem);
218+
179219
static struct cxl_driver cxl_mem_driver = {
180220
.name = "cxl_mem",
181221
.probe = cxl_mem_probe,
182222
.id = CXL_DEVICE_MEMORY_EXPANDER,
223+
.drv = {
224+
.dev_groups = cxl_mem_groups,
225+
},
183226
};
184227

185228
module_cxl_driver(cxl_mem_driver);

0 commit comments

Comments
 (0)