From patchwork Tue Jul 17 13:49:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529459 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 A31326020A for ; Tue, 17 Jul 2018 13:50:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89CBA29221 for ; Tue, 17 Jul 2018 13:50:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D6FF28D8A; Tue, 17 Jul 2018 13:50:19 +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=unavailable 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 019B629203 for ; Tue, 17 Jul 2018 13:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D5876B0008; Tue, 17 Jul 2018 09:50:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8095E6B000A; Tue, 17 Jul 2018 09:50:10 -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 60EE76B000C; Tue, 17 Jul 2018 09:50:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by kanga.kvack.org (Postfix) with ESMTP id 3242D6B0008 for ; Tue, 17 Jul 2018 09:50:10 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id i10-v6so750248qtp.13 for ; Tue, 17 Jul 2018 06:50:10 -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=Vbv3jr5XwL0UUQFmtaMj9r9ktMazudyrpuFNS6H6ZcgmMXYaCmWn5OhICtjwzVEL7Y mTwnc8/+ei8Xt1aBgifGUtAsre0eRLJVZDj2Sb/+3dJ6U+KV+iuOd+x6XT9TNPJvCHWd W38E3qbeO05de5+A+ubBZs+4bAQYRnCJ3PQBZ1T8vnmGIQ/40XMsRSWRAbM3qv0AGRxR W67D7caeXkT9SuZdwCdz6lkccOrny0m9q3JwlUDdE82+BkcLPb4j7IcO4I3NjDFk8X7E JFHZ/lj0VW179yurVlVtooZf8qehB8tNXh+7cvwbA5wmRVrJlLeomNoHrth/KClphs/J qYyw== X-Gm-Message-State: AOUpUlF8x/ZLUHI9XFWNFqoSe4uLmgcFXSjDz3B5K6EgPtJjpAVYS/do imm1KP826P5DlXXeVfJDtSjdodo4EEU0jHbYyp+t7MJsYn5yoR76T/NScSTiZw/gnWXMMofPUdN 6FchH1bD2C1VnTaPcX77X/r75ZrdBhIQcOVify4+4wtkmyJyC++kxfGRiJX1HkdTL6riP9+pbkO KZJcfut3tPiFzlu8Dd5GYZjKwd4KJgXKoSshLFh3EM0rBrxo1bvDQaLyU9q18PC9caPV3+oAe6q AEnqfjdfBZqDkQ79mc62ht1ZIU6Zr+9xYi2W0hNT76nHOjQcb+EEYaE3tA9OL9UXrbxCyoIJzJe 9OvAuPhpE4s15Y//Tpgvgq+HfD5lPw6ScqZfmFOBOhDSgO7mGLefgwEH49drBYnq+5u2G+FdUQ= = X-Received: by 2002:a0c:9351:: with SMTP id e17-v6mr1784526qve.4.1531835409996; Tue, 17 Jul 2018 06:50:09 -0700 (PDT) X-Received: by 2002:a0c:9351:: with SMTP id e17-v6mr1784475qve.4.1531835409338; Tue, 17 Jul 2018 06:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835409; cv=none; d=google.com; s=arc-20160816; b=AYAKlOWXRcHUL58pQAniaJ8K3xC6NiLwKgg1nDF4xnXQGiGrVy5/voGNa2MssxK01C 6Sd2rWz7IJvrN2qSuBFdTfmF9KTaUUXuSW+rr3a4LG0gDGnribnjOYK5T4KFouwbl1BY mR1bTuaJk6tlVhbLNpa/JazkfPa6q/sUKUtF2LJrzoHCmmnGRZL1HyyiElL86dwxATHW IracUcsBq3sFWEr7GPJMG656IF9dIwMkBbZfwEMdZeyTSGeZEJTibD35/w7Gha6/dNmz Skzw4n1ZjrMraNKAcfWxy9XYIqEBlf+60vjtymcOzjN80ny0CFXXsopAq2FgxzlO6K6e oVFg== 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=o1l85p9xc9OOO5laIMofFQuFsAwbf7hloGtCN8nFMUIxrfQCHlH9D4LbY7l0w8DPVQ DGxctxVpMcZkEdtT523nTP3346I94e3oGQejg6Gwz0TEL45bqHe8zcy1GL6IUtJjJ6hj EejEbFomD2N3MUh27Mjwne7Pr+oKmNeAGtX/sdtpxyKJzx8hNxd68tQU3IJm22uO/XXw EzWeiv3wxZTwOZDsgisHuI0IqHAAEDMSF9wfkifXU9n1aA2LNLPIkENCLUU2jdw2/Oh3 T1oByM8nEeB7/SBZM5OlBbDh7t81ivBk1qZZY0cVgnAoIqGCF+ZeDf7vdgOo6qblIdTM 0zfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="U/3Df129"; 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 f1-v6sor441624qtc.142.2018.07.17.06.50.09 for (Google Transport Security); Tue, 17 Jul 2018 06:50:09 -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="U/3Df129"; 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=U/3Df129McC441gagt0xqQ454svk8HcxbqvF+H155kRDyLyE1LbGG2uDv3So5Oqvt9 7a9xLfcjx0YeVw/Wp3yvu6uLZSH/UCqbCKgHZdczNMztFi4bAm9nD1FRme5PgY5a6lDT NBbDa3UDSvNkKGS1GcEZnWjOOW2SGup/AVzxbioudsGvwJpQAkuHk7uLlam69BCYWHzU ARswShmVz68FYjnrJV5IAPb9lQedGtScFJV0kJjyZOTxVwl/0bzBHRz/i7KqYfWQYCSn gMN1TKQLt3SSdEbvXB/jkHk3DuEbzpRYIUgh/w9lLvqCF26OZPo2aVRDNNwgKPCJUr6x ozyg== X-Google-Smtp-Source: AAOMgpdc8/2zCu89Jc/4as9TWqGIdeJFwlpr/GYzeHWkUKJ0/ZehxKq6SuYQ/Dlbxqd4w5OQS1aplw== X-Received: by 2002:ac8:3872:: with SMTP id r47-v6mr1572662qtb.69.1531835409039; Tue, 17 Jul 2018 06:50:09 -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 s83-v6sm640937qki.20.2018.07.17.06.50.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:08 -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 v14 03/22] selftests/vm: move generic definitions to header file Date: Tue, 17 Jul 2018 06:49:06 -0700 Message-Id: <1531835365-32387-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> References: <1531835365-32387-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 Acked-by: Dave Hansen --- 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