From: ira.weiny@intel.com
To: linux-api@vger.kernel.org
Cc: Ira Weiny <ira.weiny@intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
Sohil Mehta <sohil.mehta@intel.com>,
x86@kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org
Subject: [RFC PATCH 1/6] testing/pkeys: Add command line options
Date: Fri, 10 Jun 2022 16:35:28 -0700 [thread overview]
Message-ID: <20220610233533.3649584-2-ira.weiny@intel.com> (raw)
In-Reply-To: <20220610233533.3649584-1-ira.weiny@intel.com>
From: Ira Weiny <ira.weiny@intel.com>
It is more convenient to use command line options for debug and
iterations vs changing the code and recompiling.
Add command line options for debug level and number of iterations.
$ ./protection_keys_64 -h
Usage: ./protection_keys_64 [-h,-d,-i <iter>]
--help,-h This help
--debug,-d Increase debug level for each -d
--iterations,-i <iter> repeate test <iter> times
default: 22
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
tools/testing/selftests/vm/pkey-helpers.h | 7 +--
tools/testing/selftests/vm/protection_keys.c | 59 +++++++++++++++++---
2 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h
index 92f3be3dd8e5..7aaac1c8ebca 100644
--- a/tools/testing/selftests/vm/pkey-helpers.h
+++ b/tools/testing/selftests/vm/pkey-helpers.h
@@ -23,9 +23,8 @@
#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
-#ifndef DEBUG_LEVEL
-#define DEBUG_LEVEL 0
-#endif
+extern int debug_level;
+
#define DPRINT_IN_SIGNAL_BUF_SIZE 4096
extern int dprint_in_signal;
extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
@@ -58,7 +57,7 @@ static inline void sigsafe_printf(const char *format, ...)
}
}
#define dprintf_level(level, args...) do { \
- if (level <= DEBUG_LEVEL) \
+ if (level <= debug_level) \
sigsafe_printf(args); \
} while (0)
#define dprintf0(args...) dprintf_level(0, args)
diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
index 291bc1e07842..d0183c381859 100644
--- a/tools/testing/selftests/vm/protection_keys.c
+++ b/tools/testing/selftests/vm/protection_keys.c
@@ -44,9 +44,13 @@
#include <unistd.h>
#include <sys/ptrace.h>
#include <setjmp.h>
+#include <getopt.h>
#include "pkey-helpers.h"
+#define DEFAULT_ITERATIONS 22
+
+int debug_level;
int iteration_nr = 1;
int test_nr;
@@ -361,7 +365,7 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext)
* here.
*/
dprintf1("pkey_reg_xstate_offset: %d\n", pkey_reg_xstate_offset());
- if (DEBUG_LEVEL > 4)
+ if (debug_level > 4)
dump_mem(pkey_reg_ptr - 128, 256);
pkey_assert(*pkey_reg_ptr);
#endif /* arch */
@@ -480,7 +484,7 @@ int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
dprintf2("SYS_mprotect_key sret: %d\n", sret);
dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot);
dprintf2("SYS_mprotect_key failed, errno: %d\n", errno);
- if (DEBUG_LEVEL >= 2)
+ if (debug_level >= 2)
perror("SYS_mprotect_pkey");
}
return sret;
@@ -1116,7 +1120,7 @@ void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey)
pkey_write_deny(pkey);
ret = read(test_fd, ptr, 100);
dprintf1("read ret: %d\n", ret);
- if (ret < 0 && (DEBUG_LEVEL > 0))
+ if (ret < 0 && (debug_level > 0))
perror("verbose read result (OK for this to be bad)");
pkey_assert(ret);
}
@@ -1155,7 +1159,7 @@ void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey)
pkey_write_deny(pkey);
futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL,
&ignored, ignored);
- if (DEBUG_LEVEL > 0)
+ if (debug_level > 0)
perror("futex");
dprintf1("futex() ret: %d\n", futex_ret);
}
@@ -1626,11 +1630,52 @@ void pkey_setup_shadow(void)
shadow_pkey_reg = __read_pkey_reg();
}
-int main(void)
+static void print_help_and_exit(char *argv0)
+{
+ printf("Usage: %s [-h,-d,-i <iter>]\n", argv0);
+ printf(" --help,-h This help\n");
+ printf(" --debug,-d Increase debug level for each -d\n");
+ printf(" --iterations,-i <iter> repeate test <iter> times\n");
+ printf(" default: %d\n", DEFAULT_ITERATIONS);
+ printf("\n");
+}
+
+int main(int argc, char *argv[])
{
- int nr_iterations = 22;
- int pkeys_supported = is_pkeys_supported();
+ int nr_iterations = DEFAULT_ITERATIONS;
+ int pkeys_supported;
+
+ while (1) {
+ static struct option long_options[] = {
+ {"help", no_argument, 0, 'h' },
+ {"debug", no_argument, 0, 'd' },
+ {"iterations", required_argument, 0, 'i' },
+ {0, 0, 0, 0 }
+ };
+ int option_index = 0;
+ int c;
+
+ c = getopt_long(argc, argv, "hdi:", long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_help_and_exit(argv[0]);
+ return 0;
+ case 'd':
+ debug_level++;
+ break;
+ case 'i':
+ nr_iterations = strtoul(optarg, NULL, 0);
+ break;
+ default:
+ print_help_and_exit(argv[0]);
+ exit(-1);
+ }
+ }
+ pkeys_supported = is_pkeys_supported();
srand((unsigned int)time(NULL));
setup_handlers();
--
2.35.1
next prev parent reply other threads:[~2022-06-10 23:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 23:35 [RFC PATCH 0/6] User pkey minor bug fixes ira.weiny
2022-06-10 23:35 ` ira.weiny [this message]
2022-06-13 22:31 ` [RFC PATCH 1/6] testing/pkeys: Add command line options Sohil Mehta
2022-06-13 23:41 ` Ira Weiny
2022-06-10 23:35 ` [RFC PATCH 2/6] testing/pkeys: Don't use uninitialized variable ira.weiny
2022-06-13 22:48 ` Sohil Mehta
2022-06-13 23:59 ` Ira Weiny
2022-06-10 23:35 ` [RFC PATCH 3/6] testing/pkeys: Add additional test for pkey_alloc() ira.weiny
2022-06-16 19:25 ` Sohil Mehta
2022-06-16 20:24 ` Dave Hansen
2022-06-10 23:35 ` [RFC PATCH 4/6] pkeys: Lift pkey hardware check " ira.weiny
2022-06-16 19:31 ` Sohil Mehta
2022-06-10 23:35 ` [RFC PATCH 5/6] pkeys: Up level pkey_free() checks ira.weiny
2022-06-13 9:14 ` Christophe Leroy
2022-06-10 23:35 ` [RFC PATCH 6/6] pkeys: Change mm_pkey_free() to void ira.weiny
2022-06-13 9:17 ` Christophe Leroy
2022-06-13 16:16 ` Ira Weiny
2022-06-13 22:05 ` [RFC PATCH 0/6] User pkey minor bug fixes Sohil Mehta
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=20220610233533.3649584-2-ira.weiny@intel.com \
--to=ira.weiny@intel.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=sohil.mehta@intel.com \
--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).