Skip to content

Commit 180ffd3

Browse files
Davidlohr Buesodjbw
authored andcommitted
cxl/mem: Support Secure Erase
Implement support for the non-pmem exclusive secure erase, per CXL specs. Create a write-only 'security/erase' sysfs file to perform the requested operation. As with the sanitation this requires the device being offline and thus no active HPA-DPA decoding. The expectation is that userspace can use it such as: cxl disable-memdev memX echo 1 > /sys/bus/cxl/devices/memX/security/erase cxl enable-memdev memX Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Link: https://lore.kernel.org/r/20230612181038.14421-7-dave@stgolabs.net Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent c5c3921 commit 180ffd3

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ Description:
8585
the device to be not be actively decoding any HPA ranges.
8686

8787

88+
What /sys/bus/cxl/devices/memX/security/erase
89+
Date: June, 2023
90+
KernelVersion: v6.5
91+
Contact: linux-cxl@vger.kernel.org
92+
Description:
93+
(WO) Write a boolean 'true' string value to this attribute to
94+
secure erase user data by changing the media encryption keys for
95+
all user data areas of the device.
96+
97+
8898
What: /sys/bus/cxl/devices/*/devtype
8999
Date: June, 2021
90100
KernelVersion: v5.14

drivers/cxl/core/mbox.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd)
11021102
};
11031103
struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd };
11041104

1105-
if (cmd != CXL_MBOX_OP_SANITIZE)
1105+
if (cmd != CXL_MBOX_OP_SANITIZE && cmd != CXL_MBOX_OP_SECURE_ERASE)
11061106
return -EINVAL;
11071107

11081108
rc = cxl_internal_send_cmd(cxlds, &sec_cmd);
@@ -1120,6 +1120,10 @@ int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd)
11201120
if (sec_out & CXL_PMEM_SEC_STATE_USER_PASS_SET)
11211121
return -EINVAL;
11221122

1123+
if (cmd == CXL_MBOX_OP_SECURE_ERASE &&
1124+
sec_out & CXL_PMEM_SEC_STATE_LOCKED)
1125+
return -EINVAL;
1126+
11231127
rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
11241128
if (rc < 0) {
11251129
dev_err(cxlds->dev, "Failed to sanitize device : %d", rc);

drivers/cxl/core/memdev.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ static ssize_t security_sanitize_store(struct device *dev,
163163
static struct device_attribute dev_attr_security_sanitize =
164164
__ATTR(sanitize, 0200, NULL, security_sanitize_store);
165165

166+
static ssize_t security_erase_store(struct device *dev,
167+
struct device_attribute *attr,
168+
const char *buf, size_t len)
169+
{
170+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
171+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
172+
struct cxl_port *port = dev_get_drvdata(&cxlmd->dev);
173+
ssize_t rc;
174+
bool erase;
175+
176+
if (kstrtobool(buf, &erase) || !erase)
177+
return -EINVAL;
178+
179+
if (!port || !is_cxl_endpoint(port))
180+
return -EINVAL;
181+
182+
/* ensure no regions are mapped to this memdev */
183+
if (port->commit_end != -1)
184+
return -EBUSY;
185+
186+
rc = cxl_mem_sanitize(cxlds, CXL_MBOX_OP_SECURE_ERASE);
187+
188+
return rc ? rc : len;
189+
}
190+
static struct device_attribute dev_attr_security_erase =
191+
__ATTR(erase, 0200, NULL, security_erase_store);
192+
166193
static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
167194
{
168195
struct cxl_dev_state *cxlds = cxlmd->cxlds;
@@ -411,6 +438,7 @@ static struct attribute *cxl_memdev_ram_attributes[] = {
411438
static struct attribute *cxl_memdev_security_attributes[] = {
412439
&dev_attr_security_state.attr,
413440
&dev_attr_security_sanitize.attr,
441+
&dev_attr_security_erase.attr,
414442
NULL,
415443
};
416444

drivers/cxl/cxlmem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ enum cxl_opcode {
388388
CXL_MBOX_OP_SCAN_MEDIA = 0x4304,
389389
CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305,
390390
CXL_MBOX_OP_SANITIZE = 0x4400,
391+
CXL_MBOX_OP_SECURE_ERASE = 0x4401,
391392
CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500,
392393
CXL_MBOX_OP_SET_PASSPHRASE = 0x4501,
393394
CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502,

0 commit comments

Comments
 (0)