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 14/14] asidrv/asicmd: Add options to manage ASI mapped VA ranges
Date: Mon, 4 May 2020 17:02:35 +0200 [thread overview]
Message-ID: <20200504150235.12171-15-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20200504150235.12171-1-alexandre.chartre@oracle.com>
Add options to the asicmd CLI to list, add and clear ASI mapped
VA ranges.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
drivers/staging/asi/asicmd.c | 243 +++++++++++++++++++++++++++++++++++
1 file changed, 243 insertions(+)
diff --git a/drivers/staging/asi/asicmd.c b/drivers/staging/asi/asicmd.c
index 4d7bb9df0fcc..974a3147a313 100644
--- a/drivers/staging/asi/asicmd.c
+++ b/drivers/staging/asi/asicmd.c
@@ -16,6 +16,10 @@
#include "asidrv.h"
+static const char * const page_table_level[] = {
+ "PTE", "PMD", "PUD", "P4D", "PGD"
+};
+
struct asidrv_test {
char *name; /* test name */
enum asidrv_seqnum seqnum; /* sequence */
@@ -56,12 +60,25 @@ static void usage(void)
printf(" fltclr - clear ASI faults\n");
printf(" stkon - show stack on ASI fault\n");
printf(" stkoff - do not show stack on ASI fault\n");
+ printf(" map - list ASI mappings\n");
+ printf(" mapadd - add ASI mappings\n");
+ printf(" mapclr - clear ASI mapping\n");
printf("\n");
printf("Tests:\n");
for (i = 0; i < TEST_LIST_SIZE; i++)
printf(" %-10s - %s\n", test_list[i].name, test_list[i].desc);
}
+static void usage_mapadd(void)
+{
+ printf("usage: asicmd mapadd [percpu:]<addr>:<size>[:<level>]\n");
+}
+
+static void usage_mapclr(void)
+{
+ printf("usage: asicmd mapclr [percpu:]<addr>\n");
+}
+
static void asidrv_run_test(int fd, struct asidrv_test *test)
{
struct asidrv_run_param rparam;
@@ -130,6 +147,210 @@ static int asidrv_fault_list(int fd)
return 0;
}
+static int asidrv_map_list(int fd)
+{
+ struct asidrv_mapping_list *mlist;
+ int level;
+ int i, rv, len = 64;
+
+ mlist = malloc(sizeof(*mlist) +
+ sizeof(struct asidrv_mapping) * len);
+ if (!mlist) {
+ perror("malloc mlist");
+ return -1;
+ }
+
+ mlist->length = len;
+ rv = ioctl(fd, ASIDRV_IOCTL_LIST_MAPPING, mlist);
+ if (rv < 0) {
+ perror("ioctl list mapping");
+ return -1;
+ }
+
+ if (!mlist->length) {
+ printf("ASI has no mapping\n");
+ return 0;
+ }
+
+ printf("%-18s %18s %s\n", "ADDRESS", "SIZE", "LEVEL");
+ for (i = 0; i < mlist->length && i < len; i++) {
+ printf("%#18llx %#18llx ",
+ mlist->mapping[i].addr,
+ mlist->mapping[i].size);
+ level = mlist->mapping[i].level;
+ if (level < 5)
+ printf("%5s\n", page_table_level[level]);
+ else
+ printf("%5d\n", level);
+ }
+ printf("Mapping List: %d/%d\n", i, mlist->length);
+
+ return 0;
+}
+
+static char *asidrv_skip_percpu(char *str, bool *percpup)
+{
+ int len = sizeof("percpu:") - 1;
+
+ if (!strncmp(str, "percpu:", len)) {
+ str += len;
+ *percpup = true;
+ } else {
+ *percpup = false;
+ }
+
+ return str;
+}
+
+static int asidrv_parse_mapping_clear(char *arg, struct asidrv_mapping *mapping)
+{
+ char *s, *end;
+ bool percpu;
+ __u64 addr;
+
+ s = asidrv_skip_percpu(arg, &percpu);
+
+ addr = strtoull(s, &end, 0);
+ if (*end != 0) {
+ printf("invalid mapping address '%s'\n", s);
+ return -1;
+ }
+
+ printf("mapclr %llx%s\n", addr, percpu ? " percpu" : "");
+
+ mapping->addr = addr;
+ mapping->size = 0;
+ mapping->level = 0;
+ mapping->percpu = percpu;
+
+ return 0;
+}
+
+static int asidrv_parse_mapping_add(char *arg, struct asidrv_mapping *mapping)
+{
+ char *s, *end;
+ __u64 addr, size;
+ __u32 level;
+ bool percpu;
+ int i;
+
+ s = asidrv_skip_percpu(arg, &percpu);
+
+ s = strtok(s, ":");
+ if (!s) {
+ printf("mapadd: <addr> not found\n");
+ return -1;
+ }
+
+ addr = strtoull(s, &end, 0);
+ if (*end != 0) {
+ printf("invalid mapping address '%s'\n", s);
+ return -1;
+ }
+
+ s = strtok(NULL, ":");
+ if (!s) {
+ printf("mapadd: <size> not found\n");
+ return -1;
+ }
+ size = strtoull(s, &end, 0);
+ if (*end != 0) {
+ printf("mapadd: invalid size %s\n", s);
+ return -1;
+ }
+
+ s = strtok(NULL, ":");
+ if (!s) {
+ level = 0;
+ } else {
+ /* lookup page table level name */
+ level = -1;
+ for (i = 0; i < 5; i++) {
+ if (!strcasecmp(s, page_table_level[i])) {
+ level = i;
+ break;
+ }
+ }
+ if (level == -1) {
+ level = strtoul(s, &end, 0);
+ if (*end != 0 || level >= 5) {
+ printf("mapadd: invalid level %s\n", s);
+ return -1;
+ }
+ }
+ }
+
+ printf("mapadd %llx/%llx/%u%s\n", addr, size, level,
+ percpu ? " percpu" : "");
+
+ mapping->addr = addr;
+ mapping->size = size;
+ mapping->level = level;
+ mapping->percpu = percpu;
+
+ return 0;
+}
+
+static int asidrv_map_change(int fd, unsigned long cmd, char *arg)
+{
+ struct asidrv_mapping_list *mlist;
+ int i, count, err;
+ char *s;
+
+ count = 0;
+ for (s = arg; s; s = strchr(s + 1, ','))
+ count++;
+
+ mlist = malloc(sizeof(mlist) + sizeof(struct asidrv_mapping) * count);
+ if (!mlist) {
+ perror("malloc mapping list");
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < count; i++) {
+ s = strchr(arg, ',');
+ if (s)
+ s[0] = '\0';
+
+ if (cmd == ASIDRV_IOCTL_ADD_MAPPING) {
+ err = asidrv_parse_mapping_add(arg,
+ &mlist->mapping[i]);
+ } else {
+ err = asidrv_parse_mapping_clear(arg,
+ &mlist->mapping[i]);
+ }
+ if (err)
+ goto done;
+ arg = s + 1;
+ }
+
+ mlist->length = count;
+ err = ioctl(fd, cmd, mlist);
+ if (err < 0) {
+ perror("ioctl mapping");
+ err = errno;
+ } else if (err > 0) {
+ /* partial error */
+ printf("ioctl mapping: partial failure (%d/%d)\n",
+ err, count);
+ for (i = 0; i < count; i++) {
+ printf(" %#llx: ", mlist->mapping[i].addr);
+ if (i < err)
+ printf("done\n");
+ else if (i == err)
+ printf("failed\n");
+ else
+ printf("not done\n");
+ }
+ err = -1;
+ }
+
+done:
+ free(mlist);
+
+ return err;
+}
+
int main(int argc, char *argv[])
{
bool run_all, run;
@@ -172,6 +393,28 @@ int main(int argc, char *argv[])
perror("ioctl log fault sstack");
continue;
+ } else if (!strcmp(test, "map")) {
+ asidrv_map_list(fd);
+ continue;
+
+ } else if (!strcmp(test, "mapadd")) {
+ if (++i >= argc) {
+ usage_mapadd();
+ return 2;
+ }
+ asidrv_map_change(fd, ASIDRV_IOCTL_ADD_MAPPING,
+ argv[i]);
+ continue;
+
+ } else if (!strcmp(test, "mapclr")) {
+ if (++i >= argc) {
+ usage_mapclr();
+ return 2;
+ }
+ asidrv_map_change(fd, ASIDRV_IOCTL_CLEAR_MAPPING,
+ argv[i]);
+ continue;
+
} else if (!strcmp(test, "all")) {
run_all = true;
} else {
--
2.18.2
prev parent reply other threads:[~2020-05-04 15:05 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 ` [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 ` Alexandre Chartre [this message]
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-15-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