diff mbox series

[RFC,v4,part-3,04/14] asidrv: Sequence to test ASI access to mapped/unmapped memory

Message ID 20200504150235.12171-5-alexandre.chartre@oracle.com (mailing list archive)
State New, archived
Headers show
Series ASI - Part III (ASI Test Driver and CLI) | expand

Commit Message

Alexandre Chartre May 4, 2020, 3:02 p.m. UTC
Add a sequence to test if ASI exit or not when accessing a mapped
or unmapped memory buffer.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 drivers/staging/asi/asidrv.c | 70 ++++++++++++++++++++++++++++++++++++
 drivers/staging/asi/asidrv.h |  3 ++
 2 files changed, 73 insertions(+)
diff mbox series

Patch

diff --git a/drivers/staging/asi/asidrv.c b/drivers/staging/asi/asidrv.c
index 4f0548edb2f9..4231b56db167 100644
--- a/drivers/staging/asi/asidrv.c
+++ b/drivers/staging/asi/asidrv.c
@@ -14,9 +14,21 @@ 
 
 #include "asidrv.h"
 
+#define ASIDRV_TEST_BUFFER_SIZE	PAGE_SIZE
+
+/* Number of read for mem/memmap test sequence */
+#define ASIDRV_MEM_READ_COUNT		1000
+
+enum asidrv_state {
+	ASIDRV_STATE_NONE,
+	ASIDRV_STATE_INTR_WAITING,
+	ASIDRV_STATE_INTR_RECEIVED,
+};
+
 struct asidrv_test {
 	struct asi		*asi;	/* ASI for testing */
 	struct dpt		*dpt;	/* ASI decorated page-table */
+	char			*buffer; /* buffer for testing */
 };
 
 struct asidrv_sequence {
@@ -42,6 +54,10 @@  static struct asidrv_test *asidrv_test_create(void)
 	if (!test)
 		return NULL;
 
+	test->buffer = kzalloc(ASIDRV_TEST_BUFFER_SIZE, GFP_KERNEL);
+	if (!test->buffer)
+		goto error;
+
 	/*
 	 * Create and fill a decorator page-table to be used with the ASI.
 	 */
@@ -96,6 +112,7 @@  static void asidrv_test_destroy(struct asidrv_test *test)
 	if (test->asi)
 		asi_destroy(test->asi);
 
+	kfree(test->buffer);
 	kfree(test);
 }
 
@@ -143,6 +160,51 @@  static int asidrv_asi_is_active(struct asi *asi)
 	return false;
 }
 
+/*
+ * Memory Buffer Access Test Sequences
+ */
+
+#define OPTNONE __attribute__((optimize(0)))
+
+static enum asidrv_run_error OPTNONE asidrv_mem_run(struct asidrv_test *test)
+{
+	char c;
+	int i, index;
+
+	/*
+	 * Do random reads in the test buffer, and return if the ASI
+	 * becomes inactive.
+	 */
+	for (i = 0; i < ASIDRV_MEM_READ_COUNT; i++) {
+		index = get_cycles() % ASIDRV_TEST_BUFFER_SIZE;
+		c = test->buffer[index];
+		if (!asidrv_asi_is_active(test->asi)) {
+			pr_warn("ASI inactive after reading byte %d at %d\n",
+				i + 1, index);
+			break;
+		}
+	}
+
+	return ASIDRV_RUN_ERR_NONE;
+}
+
+static enum asidrv_run_error asidrv_memmap_setup(struct asidrv_test *test)
+{
+	int err;
+
+	pr_debug("mapping test buffer %px\n", test->buffer);
+	err = dpt_map(test->dpt, test->buffer, ASIDRV_TEST_BUFFER_SIZE);
+	if (err)
+		return ASIDRV_RUN_ERR_MAP_BUFFER;
+
+	return ASIDRV_RUN_ERR_NONE;
+}
+
+static void asidrv_memmap_cleanup(struct asidrv_test *test)
+{
+	dpt_unmap(test->dpt, test->buffer);
+}
+
 /*
  * Printk Test Sequence
  */
@@ -161,6 +223,14 @@  struct asidrv_sequence asidrv_sequences[] = {
 		"printk",
 		NULL, asidrv_printk_run, NULL,
 	},
+	[ASIDRV_SEQ_MEM] = {
+		"mem",
+		NULL, asidrv_mem_run, NULL,
+	},
+	[ASIDRV_SEQ_MEMMAP] = {
+		"memmap",
+		asidrv_memmap_setup, asidrv_mem_run, asidrv_memmap_cleanup,
+	},
 };
 
 static enum asidrv_run_error asidrv_run_init(struct asidrv_test *test)
diff --git a/drivers/staging/asi/asidrv.h b/drivers/staging/asi/asidrv.h
index 33acb058c443..1e820cc64f13 100644
--- a/drivers/staging/asi/asidrv.h
+++ b/drivers/staging/asi/asidrv.h
@@ -8,6 +8,8 @@ 
 enum asidrv_seqnum {
 	ASIDRV_SEQ_NOP,		/* empty sequence */
 	ASIDRV_SEQ_PRINTK,	/* printk sequence */
+	ASIDRV_SEQ_MEM,		/* access unmapped memory */
+	ASIDRV_SEQ_MEMMAP,	/* access mapped memory */
 };
 
 enum asidrv_run_error {
@@ -17,6 +19,7 @@  enum asidrv_run_error {
 	ASIDRV_RUN_ERR_MAP_TASK, /* failed to map current task */
 	ASIDRV_RUN_ERR_ENTER,	/* failed to enter ASI */
 	ASIDRV_RUN_ERR_ACTIVE,	/* ASI is not active after entering ASI */
+	ASIDRV_RUN_ERR_MAP_BUFFER, /* failed to map buffer */
 };
 
 #define ASIDRV_IOCTL_RUN_SEQUENCE	_IOWR('a', 1, struct asidrv_run_param)