Skip to content

Commit cf009d4

Browse files
committed
tools/testing/cxl: Add 'sanitize notifier' support
Allow for cxl_test regression of the sanitize notifier. Reuse the core setup infrastructure, and trigger notifications upon any sanitize submission with a programmable notification delay. Cc: Davidlohr Bueso <dave@stgolabs.net> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 501b3d9 commit cf009d4

File tree

1 file changed

+67
-1
lines changed
  • tools/testing/cxl/test

1 file changed

+67
-1
lines changed

tools/testing/cxl/test/mem.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ static struct cxl_cel_entry mock_cel[] = {
8989
.effect = cpu_to_le16(EFFECT(CONF_CHANGE_COLD_RESET) |
9090
EFFECT(CONF_CHANGE_IMMEDIATE)),
9191
},
92+
{
93+
.opcode = cpu_to_le16(CXL_MBOX_OP_SANITIZE),
94+
.effect = cpu_to_le16(EFFECT(DATA_CHANGE_IMMEDIATE) |
95+
EFFECT(SECURITY_CHANGE_IMMEDIATE) |
96+
EFFECT(BACKGROUND_OP)),
97+
},
9298
};
9399

94100
/* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -152,6 +158,7 @@ struct cxl_mockmem_data {
152158
struct cxl_memdev_state *mds;
153159
u8 event_buf[SZ_4K];
154160
u64 timestamp;
161+
unsigned long sanitize_timeout;
155162
};
156163

157164
static struct mock_event_log *event_find_log(struct device *dev, int log_type)
@@ -567,9 +574,26 @@ static int mock_partition_info(struct cxl_mbox_cmd *cmd)
567574
return 0;
568575
}
569576

577+
void cxl_mockmem_sanitize_work(struct work_struct *work)
578+
{
579+
struct cxl_memdev_state *mds =
580+
container_of(work, typeof(*mds), security.poll_dwork.work);
581+
582+
mutex_lock(&mds->mbox_mutex);
583+
if (mds->security.sanitize_node)
584+
sysfs_notify_dirent(mds->security.sanitize_node);
585+
mds->security.sanitize_active = false;
586+
mutex_unlock(&mds->mbox_mutex);
587+
588+
dev_dbg(mds->cxlds.dev, "sanitize complete\n");
589+
}
590+
570591
static int mock_sanitize(struct cxl_mockmem_data *mdata,
571592
struct cxl_mbox_cmd *cmd)
572593
{
594+
struct cxl_memdev_state *mds = mdata->mds;
595+
int rc = 0;
596+
573597
if (cmd->size_in != 0)
574598
return -EINVAL;
575599

@@ -585,7 +609,16 @@ static int mock_sanitize(struct cxl_mockmem_data *mdata,
585609
return -ENXIO;
586610
}
587611

588-
return 0; /* assume less than 2 secs, no bg */
612+
mutex_lock(&mds->mbox_mutex);
613+
if (schedule_delayed_work(&mds->security.poll_dwork,
614+
msecs_to_jiffies(mdata->sanitize_timeout))) {
615+
mds->security.sanitize_active = true;
616+
dev_dbg(mds->cxlds.dev, "sanitize issued\n");
617+
} else
618+
rc = -EBUSY;
619+
mutex_unlock(&mds->mbox_mutex);
620+
621+
return rc;
589622
}
590623

591624
static int mock_secure_erase(struct cxl_mockmem_data *mdata,
@@ -1419,6 +1452,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
14191452
mds->mbox_send = cxl_mock_mbox_send;
14201453
mds->payload_size = SZ_4K;
14211454
mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf;
1455+
INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work);
14221456

14231457
cxlds = &mds->cxlds;
14241458
cxlds->serial = pdev->id;
@@ -1458,6 +1492,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
14581492
if (rc)
14591493
return rc;
14601494

1495+
rc = devm_cxl_sanitize_setup_notifier(&pdev->dev, cxlmd);
1496+
if (rc)
1497+
return rc;
1498+
14611499
cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
14621500

14631501
return 0;
@@ -1526,10 +1564,38 @@ static ssize_t fw_buf_checksum_show(struct device *dev,
15261564

15271565
static DEVICE_ATTR_RO(fw_buf_checksum);
15281566

1567+
static ssize_t sanitize_timeout_show(struct device *dev,
1568+
struct device_attribute *attr, char *buf)
1569+
{
1570+
struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
1571+
1572+
return sysfs_emit(buf, "%lu\n", mdata->sanitize_timeout);
1573+
}
1574+
1575+
static ssize_t sanitize_timeout_store(struct device *dev,
1576+
struct device_attribute *attr,
1577+
const char *buf, size_t count)
1578+
{
1579+
struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
1580+
unsigned long val;
1581+
int rc;
1582+
1583+
rc = kstrtoul(buf, 0, &val);
1584+
if (rc)
1585+
return rc;
1586+
1587+
mdata->sanitize_timeout = val;
1588+
1589+
return count;
1590+
}
1591+
1592+
static DEVICE_ATTR_RW(sanitize_timeout);
1593+
15291594
static struct attribute *cxl_mock_mem_attrs[] = {
15301595
&dev_attr_security_lock.attr,
15311596
&dev_attr_event_trigger.attr,
15321597
&dev_attr_fw_buf_checksum.attr,
1598+
&dev_attr_sanitize_timeout.attr,
15331599
NULL
15341600
};
15351601
ATTRIBUTE_GROUPS(cxl_mock_mem);

0 commit comments

Comments
 (0)