linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org,
	peterz@infradead.org, x86@kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Cc: pbonzini@redhat.com, konrad.wilk@oracle.com,
	jan.setjeeilers@oracle.com, liran.alon@oracle.com,
	junaids@google.com, graf@amazon.de, rppt@linux.vnet.ibm.com,
	kuzuno@gmail.com, mgross@linux.intel.com,
	alexandre.chartre@oracle.com
Subject: [RFC v4][PATCH part-3 04/14] asidrv: Sequence to test ASI access to mapped/unmapped memory
Date: Mon,  4 May 2020 17:02:25 +0200	[thread overview]
Message-ID: <20200504150235.12171-5-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20200504150235.12171-1-alexandre.chartre@oracle.com>

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 --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)
-- 
2.18.2



  parent reply	other threads:[~2020-05-04 15:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 15:02 [RFC v4][PATCH part-3 00/14] ASI - Part III (ASI Test Driver and CLI) Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 01/14] mm/asi: Define the test ASI type Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 02/14] asidrv: Introduce the ASI driver Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 03/14] asidrv: Introduce the ASIDRV_IOCTL_RUN_SEQUENCE ioctl Alexandre Chartre
2020-05-04 15:02 ` Alexandre Chartre [this message]
2020-05-04 15:02 ` [RFC v4][PATCH part-3 05/14] asidrv: Sequence to test interrupt on ASI Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 06/14] asidrv: Sequence to test NMI " Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 07/14] asidrv: Sequence to test interrupt+NMI " Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 08/14] asidrv: Sequence to test scheduling in/out with ASI Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 09/14] asidrv: Add ioctls to manage ASI page faults Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 10/14] asidrv: Add ioctls to manage ASI mapped VA ranges Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 11/14] asidrv/asicmd: Introduce the asicmd command Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 12/14] asidrv/asicmd: Add more test sequences for testing ASI Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 13/14] asidrv/asicmd: Add options to manage ASI page faults Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 14/14] asidrv/asicmd: Add options to manage ASI mapped VA ranges Alexandre Chartre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200504150235.12171-5-alexandre.chartre@oracle.com \
    --to=alexandre.chartre@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=graf@amazon.de \
    --cc=hpa@zytor.com \
    --cc=jan.setjeeilers@oracle.com \
    --cc=junaids@google.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kuzuno@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liran.alon@oracle.com \
    --cc=luto@kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).