From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D718FC433EF for ; Fri, 10 Jun 2022 23:35:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C51F8D00F3; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6747B8D00E2; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452AC8D00F3; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1BB938D00E2 for ; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E65C920AE3 for ; Fri, 10 Jun 2022 23:35:39 +0000 (UTC) X-FDA: 79563935598.13.1708585 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id 496AEC0042 for ; Fri, 10 Jun 2022 23:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904138; x=1686440138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ERLwkkEZpG4vAVBowWhSWiEDw3prKfNk8Uv0IINg8GY=; b=eO+CyPoBvEtSia28e0Oig19ljZC2Hugnu0u1cWyrFa9DducPe4+LtOAY 6jpLrhOsn4LU+X3Os6zTXcty41qsm8Y08V8mavpaR9dOIIpJsYCWhgtyc fdiSBcI1ZwUHFTKhcxraI8LzG+QnTw00DCbJ6fbJUccCzCwIxhy15Lk4Y Lr+6gPwCXSFH4hNlxByKIvE1FuCpjDPw1lCcZ1zqSblYf56uRhW983hR7 x7LaiI1J93Z2f93jyDZyTo55TCkPstaK/UvLoaoUpsTZwCNxaOEiGjLkd VEY0r3hrDalSfOayZPKFd/kc3CFLjv8wcoMgdlmeyOVkN9HFc5RRO/Dnz Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="275311572" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="275311572" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="760716836" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:36 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , 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 Message-Id: <20220610233533.3649584-2-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610233533.3649584-1-ira.weiny@intel.com> References: <20220610233533.3649584-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904138; a=rsa-sha256; cv=none; b=ziUnwkLpttSZgSSZyhb2hA/LemgHfeWFlvSCk3M0x/krJzup9n3iwRI4O0w9C9k4pxmLIh JxSui/BW8kkRme6x35FD4m4n97o7MXyYCSO7OS7vntHvpIm17hIYHFvjkuJ/sLx5eaygaQ lGlHLtdTP19rUhpxbL0wzs9Wo1+EJus= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eO+CyPoB; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=ira.weiny@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654904138; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OIxSmmNZgb3ZOAN1Vi1YiiS/qbh9zt4pIJ3I0mK82yI=; b=Gi3Go2jb7pk68kZIwq3XA5QJzbPxKVKxQ4Z478Vi8St8vweVTrNengc5pfvRrxQlIFnfSe Z54geIUrUyC5dGk90VZk6ZnugBrb/z+COyeQPn6BzXy3tTHZpsNRGo7MJNntGu1eeKzzpa MG0zOH/LY5/Ge0iCgK2FQ3eWZc6tkfQ= X-Stat-Signature: j6w14q6th9u8irj1mygon9yej6p5r8g5 X-Rspam-User: X-Rspamd-Queue-Id: 496AEC0042 X-Rspamd-Server: rspam07 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eO+CyPoB; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=ira.weiny@intel.com X-HE-Tag: 1654904138-280943 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Ira Weiny 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 ] --help,-h This help --debug,-d Increase debug level for each -d --iterations,-i repeate test times default: 22 Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- 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 #include #include +#include #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 ]\n", argv0); + printf(" --help,-h This help\n"); + printf(" --debug,-d Increase debug level for each -d\n"); + printf(" --iterations,-i repeate test 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