lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200504150235.12171-12-alexandre.chartre@oracle.com>
Date:   Mon,  4 May 2020 17:02:32 +0200
From:   Alexandre Chartre <alexandre.chartre@...cle.com>
To:     tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, hpa@...or.com,
        dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
        x86@...nel.org, linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc:     pbonzini@...hat.com, konrad.wilk@...cle.com,
        jan.setjeeilers@...cle.com, liran.alon@...cle.com,
        junaids@...gle.com, graf@...zon.de, rppt@...ux.vnet.ibm.com,
        kuzuno@...il.com, mgross@...ux.intel.com,
        alexandre.chartre@...cle.com
Subject: [RFC v4][PATCH part-3 11/14] asidrv/asicmd: Introduce the asicmd command

The asicmd command is a userland CLI to interact with the ASI driver
(asidrv), in particular it provides an interface for running ASI
test sequences.

Signed-off-by: Alexandre Chartre <alexandre.chartre@...cle.com>
---
 drivers/staging/asi/Makefile |   6 ++
 drivers/staging/asi/asicmd.c | 120 +++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 drivers/staging/asi/asicmd.c

diff --git a/drivers/staging/asi/Makefile b/drivers/staging/asi/Makefile
index a48487e48d7c..847d4732c229 100644
--- a/drivers/staging/asi/Makefile
+++ b/drivers/staging/asi/Makefile
@@ -5,3 +5,9 @@
 #
 obj-m += asi.o
 asi-y := asidrv.o
+
+#
+# asicmd command
+#
+hostprogs-y := asicmd
+always := $(hostprogs-y)
diff --git a/drivers/staging/asi/asicmd.c b/drivers/staging/asi/asicmd.c
new file mode 100644
index 000000000000..4d6a347a6d29
--- /dev/null
+++ b/drivers/staging/asi/asicmd.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020, Oracle and/or its affiliates.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "asidrv.h"
+
+struct asidrv_test {
+	char		*name;		/* test name */
+	enum asidrv_seqnum seqnum;	/* sequence */
+	bool		asi_active;	/* ASI active at the end of test? */
+	char		*desc;		/* test description */
+};
+
+struct asidrv_test test_list[] = {
+	{ "nop", ASIDRV_SEQ_NOP, true,
+	  "enter/exit ASI and nothing else" },
+};
+
+#define	TEST_LIST_SIZE	(sizeof(test_list) / sizeof(test_list[0]))
+
+static void usage(void)
+{
+	int i;
+
+	printf("Usage: asicmd (<cmd>|<test>...)\n");
+	printf("\n");
+	printf("Commands:\n");
+	printf("  all      - run all tests\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 asidrv_run_test(int fd, struct asidrv_test *test)
+{
+	struct asidrv_run_param rparam;
+	int err;
+
+	printf("Test %s (sequence %d)\n", test->name, test->seqnum);
+
+	rparam.sequence = test->seqnum;
+
+	err = ioctl(fd, ASIDRV_IOCTL_RUN_SEQUENCE, &rparam);
+
+	printf("  - rv = %d ; ", err);
+	if (err < 0) {
+		printf("error %d\n", errno);
+	} else {
+		printf("result = %d ; ", rparam.run_error);
+		printf("%s\n",
+		       rparam.asi_active ? "asi active" : "asi inactive");
+	}
+
+	printf("  - expect = %s\n",
+	       test->asi_active ? "asi active" : "asi inactive");
+
+	if (err < 0)
+		printf("ERROR - error %d\n", errno);
+	else if (rparam.run_error != ASIDRV_RUN_ERR_NONE)
+		printf("TEST ERROR - error %d\n", rparam.run_error);
+	else if (test->asi_active != rparam.asi_active)
+		printf("TEST FAILED - unexpected ASI state\n");
+	else
+		printf("TEST OK\n");
+}
+
+int main(int argc, char *argv[])
+{
+	bool run_all, run;
+	int i, j, fd;
+	char *test;
+
+	if (argc <= 1) {
+		usage();
+		return 2;
+	}
+
+	fd = open("/dev/asi", O_RDONLY);
+	if (fd == -1) {
+		perror("open /dev/asi");
+		return 1;
+	}
+
+	for (i = 1; i < argc; i++) {
+		test = argv[i];
+
+		if (!strcmp(test, "all"))
+			run_all = true;
+		else
+			run_all = false;
+
+		run = false;
+		for (j = 0; j < TEST_LIST_SIZE; j++) {
+			if (run_all || !strcmp(test, test_list[j].name)) {
+				asidrv_run_test(fd, &test_list[j]);
+				run = true;
+			}
+		}
+
+		if (!run)
+			printf("Unknown test '%s'\n", test);
+	}
+
+	close(fd);
+
+	return 0;
+}
-- 
2.18.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ