Skip to content

Commit 9690b07

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/memdev: Add support for the Clear Poison mailbox command
CXL devices optionally support the CLEAR POISON mailbox command. Add memdev driver support for clearing poison. Per the CXL Specification (3.0 8.2.9.8.4.3), after receiving a valid clear poison request, the device removes the address from the device's Poison List and writes 0 (zero) for 64 bytes starting at address. If the device cannot clear poison from the address, it returns a permanent media error and -ENXIO is returned to the user. Additionally, and per the spec also, it is not an error to clear poison of an address that is not poisoned. If the address is not contained in the device's dpa resource, or is not 64 byte aligned, the driver returns -EINVAL without sending the command to the device. Poison clearing is intended for debug only and will be exposed to userspace through debugfs. Restrict compilation to CONFIG_DEBUG_FS. Implementation note: Although the CXL specification defines the clear command to accept 64 bytes of 'write-data', this implementation always uses zeroes as write-data. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/8682c30ec24bd9c45af5feccb04b02be51e58c0a.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 d2fbc48 commit 9690b07

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

drivers/cxl/core/memdev.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,49 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa)
216216
}
217217
EXPORT_SYMBOL_NS_GPL(cxl_inject_poison, CXL);
218218

219+
int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa)
220+
{
221+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
222+
struct cxl_mbox_clear_poison clear;
223+
struct cxl_mbox_cmd mbox_cmd;
224+
int rc;
225+
226+
if (!IS_ENABLED(CONFIG_DEBUG_FS))
227+
return 0;
228+
229+
rc = down_read_interruptible(&cxl_dpa_rwsem);
230+
if (rc)
231+
return rc;
232+
233+
rc = cxl_validate_poison_dpa(cxlmd, dpa);
234+
if (rc)
235+
goto out;
236+
237+
/*
238+
* In CXL 3.0 Spec 8.2.9.8.4.3, the Clear Poison mailbox command
239+
* is defined to accept 64 bytes of write-data, along with the
240+
* address to clear. This driver uses zeroes as write-data.
241+
*/
242+
clear = (struct cxl_mbox_clear_poison) {
243+
.address = cpu_to_le64(dpa)
244+
};
245+
246+
mbox_cmd = (struct cxl_mbox_cmd) {
247+
.opcode = CXL_MBOX_OP_CLEAR_POISON,
248+
.size_in = sizeof(clear),
249+
.payload_in = &clear,
250+
};
251+
252+
rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
253+
if (rc)
254+
goto out;
255+
out:
256+
up_read(&cxl_dpa_rwsem);
257+
258+
return rc;
259+
}
260+
EXPORT_SYMBOL_NS_GPL(cxl_clear_poison, CXL);
261+
219262
static struct attribute *cxl_memdev_attributes[] = {
220263
&dev_attr_serial.attr,
221264
&dev_attr_firmware_version.attr,

drivers/cxl/cxlmem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,12 @@ struct cxl_mbox_inject_poison {
620620
__le64 address;
621621
};
622622

623+
/* Clear Poison CXL 3.0 Spec 8.2.9.8.4.3 */
624+
struct cxl_mbox_clear_poison {
625+
__le64 address;
626+
u8 write_data[CXL_POISON_LEN_MULT];
627+
} __packed;
628+
623629
/**
624630
* struct cxl_mem_command - Driver representation of a memory device command
625631
* @info: Command information as it exists for the UAPI
@@ -695,6 +701,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
695701
struct cxl_region *cxlr);
696702
int cxl_trigger_poison_list(struct cxl_memdev *cxlmd);
697703
int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa);
704+
int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa);
698705

699706
#ifdef CONFIG_CXL_SUSPEND
700707
void cxl_mem_active_inc(void);

0 commit comments

Comments
 (0)