From patchwork Thu Jun 14 00:44:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DCE0603EE for ; Thu, 14 Jun 2018 00:46:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8007628B9D for ; Thu, 14 Jun 2018 00:46:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74A0D28BA8; Thu, 14 Jun 2018 00:46:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCFC028B9D for ; Thu, 14 Jun 2018 00:46:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 772CE6B0008; Wed, 13 Jun 2018 20:46:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 69B956B000C; Wed, 13 Jun 2018 20:46:52 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 561116B000D; Wed, 13 Jun 2018 20:46:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 2BBDF6B0008 for ; Wed, 13 Jun 2018 20:46:52 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id b6-v6so3283156qtp.18 for ; Wed, 13 Jun 2018 17:46:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=Y9poD5MUyN6G8Z3HW8QL00dyKfFlekJmH4gtYBEktOo=; b=NizMbdH5Vz0h94jv7Er6rQmx+g8SDo0EgKvMISXafsb4GW8qK1+AZIquMDtOj3aNKa MNYfFRC4Ubg2g7FZfO5/Nq+AxFpc1sE+3ecCk2zy9Yn/A43FseKjYZDHbRYM23TUs26A zo4jAkPlhAPtBuOMtPVFpEGKGCAskACLNc2hMJc8srCIlOIBYJw8lo4gPeeNI7g3i8+9 OFEAzD2IkBBAw1IT2kbrLWaFjollepTbZcPTmYFx+6IrItFN6AiOT2fTHuaY/Z4Ay/Ug +WgC/p6ATsXMybFN9Z8TskLqNkk9BPFUvgJeScaLqeHG3Q1ZVVLoLMu3NEyIQTFsf+5z hmXw== X-Gm-Message-State: APt69E0kfwnuZb0l8XnNgVcQKgQMKcZE4b2qv0xEzwOkbAm5tqLGx8+b Q1XpZWRYRxKAExPucouRDKrHCqwzDhkrPzkpiM8Zw+vdirKHeElLW5pYeX3iCInDGoLZCjU6H3/ A51NKNqGDXzT4ARG6WM4SRhjKkJnDkORo3CBlc2R7BKwG5spGbIufIiStYbR1H/2/uiFvgev1Qt EJbe2qHk2BGRviolMGDrBb8cWZ8BxKvL8vPSUOtb3kVNyy277WuTht2us1Ncd3OC/CxNl0QnmYS eXHr5b7CSaTbcSYBAR58uR3O8MFH5rGu+GPl+zP1P331hb/2MArYp+luYZunCuv0SKmIt9h1qw6 MTICfDYNlrVEn94Uq+O1jJroW49G+Kurxbf/MWgDZbcNg9LwSK5jL9Q/0y12f2QKk6X3xhxD+Q= = X-Received: by 2002:a0c:b52c:: with SMTP id d44-v6mr397898qve.34.1528937211918; Wed, 13 Jun 2018 17:46:51 -0700 (PDT) X-Received: by 2002:a0c:b52c:: with SMTP id d44-v6mr397867qve.34.1528937211234; Wed, 13 Jun 2018 17:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937211; cv=none; d=google.com; s=arc-20160816; b=OIQxN5Y2MXqMlS7E0gXgOdOOl0zr3Xd04xKOfZ6WJR+60iFsvsuBNPq+QhJrL42SGr Q2lR1pj6EviIx+FDbTEd/PrKymmPwglj/BnKDPbtP0ZFs6/SQrMKtNZdcvUlwiyQm5AO HK3MfefsiDIrI8ABJygkbnls8sbbST3/8iDMyo2+uEv2yy6mzTR4eJSQyNKpXIlnBiFC 5N0uRsQOWLk3MihpmhOrNTW2IBtBI75fawh1aKrjYawSTdkDWp42I2KtsQMchGorJPmG 9ukacVuhJ4lTBMklIv2v6cLYRI64HY1uOeA0NRaduGN4zkEcXM6rhMU4p+Nkr7yWe3sG VXkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=Y9poD5MUyN6G8Z3HW8QL00dyKfFlekJmH4gtYBEktOo=; b=FoBxpR5AEL6oDWPt1NTGxKHIb04wnE2ePq+0fAoKz4SAzV6dEVoPr6Wa8YAJSx7VJy eBjgYFAM+EI2nCNv5W1Hh0ESwc5XVmlzmwU2G06ZtIEONMON4wIU6R4Asa+7CSWJ5yIU AfxfrYIv8dZt20rJNkJPk2PAnuiPg9emGAJnZDe8L+2hJyBo9LAHCLTUpH4Y4N1Lphwr noK9L0FQmB2cmgmvks90bqGmhQe53lYqQZpNYvYCE7rCnFexmR38rJRZCuE9ZThM/JCN o/Rz3YmuXCXiJpx/ZDbwxl9nCHkzhJApCqbD9Jw6k0ZORGXjgUPXuJ4uqy1U/W85RxMB 0CnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="G/Dfp+bY"; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q68-v6sor2069460qke.157.2018.06.13.17.46.51 for (Google Transport Security); Wed, 13 Jun 2018 17:46:51 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="G/Dfp+bY"; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y9poD5MUyN6G8Z3HW8QL00dyKfFlekJmH4gtYBEktOo=; b=G/Dfp+bYzI/QIOidlfXQOaJTc2AfZb7xASJNH8CAnjZKU9R8o6sy9LZuImBqXiXCCv yQOtFaKVeK5Yf2z5szlEDLtj3clt6JYmFm7LYaCflR9Jp8z3hkQvuaPOmS2phF56dnD8 yWXt5cF7Et2fkla9xM3xlhmj9QZ1ywWQjf8J65FvJx3y0j+Q/Te/FMgzE1zeg6ED88jV 6SYUHKIYGOW+F1UxmcUUcMvgesbNi2CbdUHG8S91Ktu+8O/3KSuoG68DVFO8MYAqwn91 hNzqLkH1CjCmDjwqeJ+4mpppPj5/nRYj/fKrZ+nOBribR82efMsvI+ELYcJ7vCqGyUjI NVQA== X-Google-Smtp-Source: ADUXVKLMJqeacKzbW1sAaQDBYWj7ydYkRg2WhfvpdcwdTb3qgI1U3t+T2bfkmcJ6xpTqmeWATOY4NA== X-Received: by 2002:a37:9505:: with SMTP id x5-v6mr343118qkd.25.1528937210996; Wed, 13 Jun 2018 17:46:50 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id u31-v6sm3225898qtc.28.2018.06.13.17.46.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:46:50 -0700 (PDT) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, mingo@redhat.com, dave.hansen@intel.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, linuxram@us.ibm.com, fweimer@redhat.com, msuchanek@suse.de, aneesh.kumar@linux.vnet.ibm.com Subject: [PATCH v13 03/24] selftests/vm: move generic definitions to header file Date: Wed, 13 Jun 2018 17:44:54 -0700 Message-Id: <1528937115-10132-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP Moved all the generic definition and helper functions to the header file. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann --- tools/testing/selftests/vm/pkey-helpers.h | 35 ++++++++++++++++++++++--- tools/testing/selftests/vm/protection_keys.c | 27 -------------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index d5779be..6ad1bd5 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -13,6 +13,14 @@ #include #include +/* Define some kernel-like types */ +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) + #define NR_PKEYS 16 #define PKEY_BITS_PER_PKEY 2 @@ -53,6 +61,18 @@ static inline void sigsafe_printf(const char *format, ...) #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args) +extern void abort_hooks(void); +#define pkey_assert(condition) do { \ + if (!(condition)) { \ + dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ + __FILE__, __LINE__, \ + test_nr, iteration_nr); \ + dprintf0("errno at assert: %d", errno); \ + abort_hooks(); \ + exit(__LINE__); \ + } \ +} while (0) + extern unsigned int shadow_pkey_reg; static inline unsigned int __read_pkey_reg(void) { @@ -137,11 +157,6 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write) dprintf4("pkey_reg now: %08x\n", read_pkey_reg()); } -#define PROT_PKEY0 0x10 /* protection key value (bit 0) */ -#define PROT_PKEY1 0x20 /* protection key value (bit 1) */ -#define PROT_PKEY2 0x40 /* protection key value (bit 2) */ -#define PROT_PKEY3 0x80 /* protection key value (bit 3) */ - #define PAGE_SIZE 4096 #define MB (1<<20) @@ -219,4 +234,14 @@ int pkey_reg_xstate_offset(void) return xstate_offset; } +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) +#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1)) +#define ALIGN_DOWN(x, align_to) ((x) & ~((align_to)-1)) +#define ALIGN_PTR_UP(p, ptr_align_to) \ + ((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to)) +#define ALIGN_PTR_DOWN(p, ptr_align_to) \ + ((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to)) +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) + #endif /* _PKEYS_HELPER_H */ diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 9f373cc..cad52dc 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -51,31 +51,10 @@ unsigned int shadow_pkey_reg; #define HPAGE_SIZE (1UL<<21) -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) -#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1)) -#define ALIGN_DOWN(x, align_to) ((x) & ~((align_to)-1)) -#define ALIGN_PTR_UP(p, ptr_align_to) ((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to)) -#define ALIGN_PTR_DOWN(p, ptr_align_to) ((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to)) -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - -#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) int dprint_in_signal; char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; -extern void abort_hooks(void); -#define pkey_assert(condition) do { \ - if (!(condition)) { \ - dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ - __FILE__, __LINE__, \ - test_nr, iteration_nr); \ - dprintf0("errno at assert: %d", errno); \ - abort_hooks(); \ - exit(__LINE__); \ - } \ -} while (0) - void cat_into_file(char *str, char *file) { int fd = open(file, O_RDWR); @@ -186,12 +165,6 @@ void lots_o_noops_around_write(int *write_to_me) dprintf3("%s() done\n", __func__); } -/* Define some kernel-like types */ -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t -#define u64 uint64_t - #ifdef __i386__ #ifndef SYS_mprotect_key