linux-kernel.vger.kernel.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 02/14] asidrv: Introduce the ASI driver
Date: Mon,  4 May 2020 17:02:23 +0200	[thread overview]
Message-ID: <20200504150235.12171-3-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20200504150235.12171-1-alexandre.chartre@oracle.com>

Introduce the infrastructure for the ASI driver. This driver is meant
for testing ASI. It creates a test ASI, and will allow to run some
test sequences on this ASI.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 drivers/staging/asi/Makefile |   7 ++
 drivers/staging/asi/asidrv.c | 129 +++++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+)
 create mode 100644 drivers/staging/asi/Makefile
 create mode 100644 drivers/staging/asi/asidrv.c

diff --git a/drivers/staging/asi/Makefile b/drivers/staging/asi/Makefile
new file mode 100644
index 000000000000..a48487e48d7c
--- /dev/null
+++ b/drivers/staging/asi/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+#
+# Address Space Isolation (ASI) driver
+#
+obj-m += asi.o
+asi-y := asidrv.o
diff --git a/drivers/staging/asi/asidrv.c b/drivers/staging/asi/asidrv.c
new file mode 100644
index 000000000000..c06e4734e0e5
--- /dev/null
+++ b/drivers/staging/asi/asidrv.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020, Oracle and/or its affiliates.
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include <asm/asi.h>
+#include <asm/dpt.h>
+
+struct asidrv_test {
+	struct asi		*asi;	/* ASI for testing */
+	struct dpt		*dpt;	/* ASI decorated page-table */
+};
+
+static struct asidrv_test *asidrv_test;
+
+static void asidrv_test_destroy(struct asidrv_test *test);
+
+static struct asidrv_test *asidrv_test_create(void)
+{
+	struct asidrv_test *test;
+	int err;
+
+	test = kzalloc(sizeof(*test), GFP_KERNEL);
+	if (!test)
+		return NULL;
+
+	/*
+	 * Create and fill a decorator page-table to be used with the ASI.
+	 */
+	test->dpt = dpt_create(ASI_PGTABLE_MASK);
+	if (!test->dpt)
+		goto error;
+
+	err = asi_init_dpt(test->dpt);
+	if (err)
+		goto error;
+
+	err = DPT_MAP_THIS_MODULE(test->dpt);
+	if (err)
+		goto error;
+
+	/* map the asidrv_test as we will access it during the test */
+	err = dpt_map(test->dpt, test, sizeof(*test));
+	if (err)
+		goto error;
+
+	test->asi = asi_create_test();
+	if (!test->asi)
+		goto error;
+
+	/*
+	 * By default, the ASI structure is not mapped into the ASI. We
+	 * map it so that we can access it and verify the consistency
+	 * of some values (for example the CR3 value).
+	 */
+	err = dpt_map(test->dpt, test->asi, sizeof(*test->asi));
+	if (err)
+		goto error;
+
+	asi_set_pagetable(test->asi, test->dpt->pagetable);
+
+	return test;
+
+error:
+	pr_debug("Failed to create ASI Test\n");
+	asidrv_test_destroy(test);
+	return NULL;
+}
+
+static void asidrv_test_destroy(struct asidrv_test *test)
+{
+	if (!test)
+		return;
+
+	if (test->dpt)
+		dpt_destroy(test->dpt);
+
+	if (test->asi)
+		asi_destroy(test->asi);
+
+	kfree(test);
+}
+
+static const struct file_operations asidrv_fops = {
+	.owner		= THIS_MODULE,
+};
+
+static struct miscdevice asidrv_miscdev = {
+	.minor = MISC_DYNAMIC_MINOR,
+	.name = KBUILD_MODNAME,
+	.fops = &asidrv_fops,
+};
+
+static int __init asidrv_init(void)
+{
+	int err;
+
+	asidrv_test = asidrv_test_create();
+	if (!asidrv_test)
+		return -ENOMEM;
+
+	err = misc_register(&asidrv_miscdev);
+	if (err) {
+		asidrv_test_destroy(asidrv_test);
+		asidrv_test = NULL;
+	}
+
+	return err;
+}
+
+static void __exit asidrv_exit(void)
+{
+	asidrv_test_destroy(asidrv_test);
+	asidrv_test = NULL;
+	misc_deregister(&asidrv_miscdev);
+}
+
+module_init(asidrv_init);
+module_exit(asidrv_exit);
+
+MODULE_AUTHOR("Alexandre Chartre <alexandre.chartre@oracle.com>");
+MODULE_DESCRIPTION("Privileged interface to ASI");
+MODULE_VERSION("1.0");
+MODULE_LICENSE("GPL v2");
-- 
2.18.2


  parent reply	other threads:[~2020-05-04 15:04 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 ` Alexandre Chartre [this message]
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 ` [RFC v4][PATCH part-3 04/14] asidrv: Sequence to test ASI access to mapped/unmapped memory Alexandre Chartre
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-3-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).