Skip to content

Commit 98980d7

Browse files
AlisonSchofielddjbw
authored andcommitted
tools/testing/cxl: Add a sysfs attr to test poison inject limits
CXL devices may report a maximum number of addresses that a device allows to be poisoned using poison injection. When cxl_test creates mock CXL memory devices, it defaults to MOCK_INJECT_DEV_MAX==88 for all mocked memdevs. Add a sysfs attribute, poison_inject_max to module cxl_mock_mem so that users can set a custom device injection limit. Fail, and return -EBUSY, if the mock poison list is not empty. /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max A simple usage model is to set the attribute before running a test in order to emulate a device's poison handling. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/0f25b2862b90013545450222d2199e435c6cc11a.1681874357.git.alison.schofield@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 8eac7ea commit 98980d7

1 file changed

Lines changed: 48 additions & 4 deletions

File tree

  • tools/testing/cxl/test

tools/testing/cxl/test/mem.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define MOCK_INJECT_DEV_MAX 8
2020
#define MOCK_INJECT_TEST_MAX 128
2121

22+
static unsigned int poison_inject_dev_max = MOCK_INJECT_DEV_MAX;
23+
2224
static struct cxl_cel_entry mock_cel[] = {
2325
{
2426
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_SUPPORTED_LOGS),
@@ -485,7 +487,7 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
485487
cpu_to_le64(SZ_256M / CXL_CAPACITY_MULTIPLIER),
486488
.total_capacity =
487489
cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
488-
.inject_poison_limit = cpu_to_le16(MOCK_INJECT_DEV_MAX),
490+
.inject_poison_limit = cpu_to_le16(MOCK_INJECT_TEST_MAX),
489491
};
490492

491493
put_unaligned_le24(CXL_POISON_LIST_MAX, id.poison_list_max_mer);
@@ -919,7 +921,7 @@ cxl_get_injected_po(struct cxl_dev_state *cxlds, u64 offset, u64 length)
919921
int nr_records = 0;
920922
u64 dpa;
921923

922-
po = kzalloc(struct_size(po, record, MOCK_INJECT_DEV_MAX), GFP_KERNEL);
924+
po = kzalloc(struct_size(po, record, poison_inject_dev_max), GFP_KERNEL);
923925
if (!po)
924926
return NULL;
925927

@@ -934,7 +936,7 @@ cxl_get_injected_po(struct cxl_dev_state *cxlds, u64 offset, u64 length)
934936
po->record[nr_records].address = cpu_to_le64(dpa);
935937
po->record[nr_records].length = cpu_to_le32(1);
936938
nr_records++;
937-
if (nr_records == MOCK_INJECT_DEV_MAX)
939+
if (nr_records == poison_inject_dev_max)
938940
break;
939941
}
940942

@@ -972,7 +974,7 @@ static bool mock_poison_dev_max_injected(struct cxl_dev_state *cxlds)
972974
if (mock_poison_list[i].cxlds == cxlds)
973975
count++;
974976
}
975-
return (count >= MOCK_INJECT_DEV_MAX);
977+
return (count >= poison_inject_dev_max);
976978
}
977979

978980
static bool mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
@@ -1054,6 +1056,47 @@ static int mock_clear_poison(struct cxl_dev_state *cxlds,
10541056
return 0;
10551057
}
10561058

1059+
static bool mock_poison_list_empty(void)
1060+
{
1061+
for (int i = 0; i < MOCK_INJECT_TEST_MAX; i++) {
1062+
if (mock_poison_list[i].cxlds)
1063+
return false;
1064+
}
1065+
return true;
1066+
}
1067+
1068+
static ssize_t poison_inject_max_show(struct device_driver *drv, char *buf)
1069+
{
1070+
return sysfs_emit(buf, "%u\n", poison_inject_dev_max);
1071+
}
1072+
1073+
static ssize_t poison_inject_max_store(struct device_driver *drv,
1074+
const char *buf, size_t len)
1075+
{
1076+
int val;
1077+
1078+
if (kstrtoint(buf, 0, &val) < 0)
1079+
return -EINVAL;
1080+
1081+
if (!mock_poison_list_empty())
1082+
return -EBUSY;
1083+
1084+
if (val <= MOCK_INJECT_TEST_MAX)
1085+
poison_inject_dev_max = val;
1086+
else
1087+
return -EINVAL;
1088+
1089+
return len;
1090+
}
1091+
1092+
static DRIVER_ATTR_RW(poison_inject_max);
1093+
1094+
static struct attribute *cxl_mock_mem_core_attrs[] = {
1095+
&driver_attr_poison_inject_max.attr,
1096+
NULL
1097+
};
1098+
ATTRIBUTE_GROUPS(cxl_mock_mem_core);
1099+
10571100
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
10581101
{
10591102
struct device *dev = cxlds->dev;
@@ -1262,6 +1305,7 @@ static struct platform_driver cxl_mock_mem_driver = {
12621305
.driver = {
12631306
.name = KBUILD_MODNAME,
12641307
.dev_groups = cxl_mock_mem_groups,
1308+
.groups = cxl_mock_mem_core_groups,
12651309
},
12661310
};
12671311

0 commit comments

Comments
 (0)