Skip to content

Commit 364ee9f

Browse files
weiny2davejiang
authored andcommitted
cxl/test: Enhance event testing
An issue was found in the processing of event logs when the output buffer length was not reset.[1] This bug was not caught with cxl-test for 2 reasons. First, the test harness mbox_send command [mock_get_event()] does not set the output size based on the amount of data returned like the hardware command does. Second, the simplistic event log testing always returned the same number of elements per-get command. Enhance the simulation of the event log mailbox to better match the bug found with real hardware to cover potential regressions. NOTE: These changes will cause cxl-events.sh in ndctl to fail without the fix from Kwangjin. However, no changes to the user space test was required. Therefore ndctl itself will be compatible with old or new kernels once both patches land in the new kernel. [1] Link: https://lore.kernel.org/all/[email protected]/ Cc: Kwangjin Ko <[email protected]> Signed-off-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 54e8dd5 commit 364ee9f

File tree

1 file changed

+15
-4
lines changed
  • tools/testing/cxl/test

1 file changed

+15
-4
lines changed

tools/testing/cxl/test/mem.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static struct {
127127
#define CXL_TEST_EVENT_CNT_MAX 15
128128

129129
/* Set a number of events to return at a time for simulation. */
130-
#define CXL_TEST_EVENT_CNT 3
130+
#define CXL_TEST_EVENT_RET_MAX 4
131131

132132
struct mock_event_log {
133133
u16 clear_idx;
@@ -222,6 +222,12 @@ static void mes_add_event(struct mock_event_store *mes,
222222
log->nr_events++;
223223
}
224224

225+
/*
226+
* Vary the number of events returned to simulate events occuring while the
227+
* logs are being read.
228+
*/
229+
static int ret_limit = 0;
230+
225231
static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
226232
{
227233
struct cxl_get_event_payload *pl;
@@ -233,29 +239,34 @@ static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
233239
if (cmd->size_in != sizeof(log_type))
234240
return -EINVAL;
235241

236-
if (cmd->size_out < struct_size(pl, records, CXL_TEST_EVENT_CNT))
242+
ret_limit = (ret_limit + 1) % CXL_TEST_EVENT_RET_MAX;
243+
if (!ret_limit)
244+
ret_limit = 1;
245+
246+
if (cmd->size_out < struct_size(pl, records, ret_limit))
237247
return -EINVAL;
238248

239249
log_type = *((u8 *)cmd->payload_in);
240250
if (log_type >= CXL_EVENT_TYPE_MAX)
241251
return -EINVAL;
242252

243-
memset(cmd->payload_out, 0, cmd->size_out);
253+
memset(cmd->payload_out, 0, struct_size(pl, records, 0));
244254

245255
log = event_find_log(dev, log_type);
246256
if (!log || event_log_empty(log))
247257
return 0;
248258

249259
pl = cmd->payload_out;
250260

251-
for (i = 0; i < CXL_TEST_EVENT_CNT && !event_log_empty(log); i++) {
261+
for (i = 0; i < ret_limit && !event_log_empty(log); i++) {
252262
memcpy(&pl->records[i], event_get_current(log),
253263
sizeof(pl->records[i]));
254264
pl->records[i].event.generic.hdr.handle =
255265
event_get_cur_event_handle(log);
256266
log->cur_idx++;
257267
}
258268

269+
cmd->size_out = struct_size(pl, records, i);
259270
pl->record_count = cpu_to_le16(i);
260271
if (!event_log_empty(log))
261272
pl->flags |= CXL_GET_EVENT_FLAG_MORE_RECORDS;

0 commit comments

Comments
 (0)