Received: by 10.223.185.116 with SMTP id b49csp1383309wrg; Wed, 21 Feb 2018 18:03:17 -0800 (PST) X-Google-Smtp-Source: AH8x224y8YoKiNHXC9kE1lrupsUWSMx0HXwCHwFdlLiQTePWZykRKRV35XuX7LGV/EwL2Nv4v9b2 X-Received: by 2002:a17:902:848b:: with SMTP id c11-v6mr5001913plo.372.1519264997334; Wed, 21 Feb 2018 18:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519264997; cv=none; d=google.com; s=arc-20160816; b=AXlie7FdoFlqLfqBTp//BeupHPrNWWeZ0Cge99rGP9Az+BZ8+Q0I9DOwUVLIj5HVkb oRHsWb6X1qyz9tnqlQ354tMFHCzAOR34ahSKvbwgbkYZhH9n2Z4SICpB11ARbmmAR0ce jaaCYe2nqfqIzUM9FLgUdDajheDPjVYAKpi9RwhNgNcK0cb0/w+yoiBSRHhE+EgFNVnY uwhKTdvGmy93rrNJmO53J1Byh/7QPkN+Yi34xHbjgPBVo7zc5UDSc/aBpW3zfNcP11+N i/CpUsKMx78H6iY1tw81H9JJ/Sxc7osEyfT7t/UlQ4mZwh64mEqRx1djJdvPlwKQGZ7c W3DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=q7zu6aoNQQ0O2nQjhvZTapgaPZ6XqZGGWUr8g3SumpQ=; b=s/sYPEAMEH240fDK7wioBJDskeMV2EfZCBZp+4EhtP4YCyPZs6LJ4vJCrqYyGvorcQ rc3pp2npzAL8KoI5r13uAZ8YNF7jplc3WzWQKEfE0PAEInDuwJ4JJXGPHRWAtXFTC3yW nnNfdGt8VyBCnYxsBv4kOr9HQ3+8BxVCodDWK8SuyiNvyQKnvLAynivf+1a1smtlzVZM wB6uPFEDJv55qiRhrPEkdMHjp7Z3oRKAfv9oobnH3R+jilZ7Dyy1XpFW3Crlyy9xoTtv lO0wVKJZ62JsX+GrYVXR6dDi3ed2zrTxrhFt3emkgVne/MSRIYoj/4y8brnrOaKUG+lx xabQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=i6fR41AF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9-v6si2473689pll.229.2018.02.21.18.03.03; Wed, 21 Feb 2018 18:03:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=i6fR41AF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751894AbeBVB42 (ORCPT + 99 others); Wed, 21 Feb 2018 20:56:28 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35945 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751842AbeBVB4X (ORCPT ); Wed, 21 Feb 2018 20:56:23 -0500 Received: by mail-qt0-f196.google.com with SMTP id c7so4509440qtn.3; Wed, 21 Feb 2018 17:56:22 -0800 (PST) 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=q7zu6aoNQQ0O2nQjhvZTapgaPZ6XqZGGWUr8g3SumpQ=; b=i6fR41AFOT3OJkGa14QmAZzWbpG5TzJXc6fOIAagaoiE42fklsg+VVKaiaGNpf/jhI kDNGIQLYLG8jKdVGc0FRa/J37/yNGcvD0D4fzrSVa3QJaDGRkivrBP1k/lMd3I/2+xHM RIZmFepht483cIUdgMytMi8xtLLjvBUjlj+mZM6eIK3WVjUE2EedzqRDfIMIOUUAoy0k jjiZXpBpmUSKtWgyhz3mZ2wFqE+P2ITj9tUo1UzzhBOzClnTaRJ8/Aw6zNFGVbrqAoUj 8dz3uAFLczBlJsP52q5qUVa2dkE7yqnxTwakuUA5Xjs9LaOf7sbY247CTObzqeB/sZkF Xxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=q7zu6aoNQQ0O2nQjhvZTapgaPZ6XqZGGWUr8g3SumpQ=; b=e+Uk3evrCpOGdRhSsqV0GsQSo+Ay0lGkdNh3ZFF6mqwIs6kIM2fzPJ3sKQ3PozdWdM zzjQJOODKgiwOqHmSF7zcz8S9TWrOZD9xz6DbnoKvXVw3agnj6bk/6qhLOWG2qclykf8 Gcnqn3Dz10YE4w52QqXN2jH4/MPQmn7wJt8w/YLyU+JR7tiKPPlxIG37KxfKMlntURv3 a08ctkBCWiIjrT7Y07mRf1V3poFK0rgvd9eIpGzY2jz24eR6FQzPFqe0+kVnF9mMIQip 5Tf5HPYrmJF3WZ0uBt9AX6IjS9Na96aChtexsJMZIQAbPNvKj1JbEQmqZVXhKTFNmZ25 JMig== X-Gm-Message-State: APf1xPCFxd5Ig6f24UrxaNO4R9NejKwLnyfXqNtGEAmpHcU9CV4BNX9S K3qqu+AfZmI0/Ijb5Q5uYUg= X-Received: by 10.200.35.141 with SMTP id q13mr8140559qtq.73.1519264582219; Wed, 21 Feb 2018 17:56:22 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id n29sm14182630qtf.18.2018.02.21.17.56.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:56:21 -0800 (PST) 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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v12 03/22] selftests/vm: move generic definitions to header file Date: Wed, 21 Feb 2018 17:55:22 -0800 Message-Id: <1519264541-7621-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Moved all the generic definition and helper functions to the header file cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai --- tools/testing/selftests/vm/pkey-helpers.h | 62 ++++++++++++++++++++++-- tools/testing/selftests/vm/protection_keys.c | 66 -------------------------- 2 files changed, 57 insertions(+), 71 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index a568166..c1bc761 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -13,8 +13,31 @@ #include #include +/* Define some kernel-like types */ +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +#ifdef __i386__ +#define SYS_mprotect_key 380 +#define SYS_pkey_alloc 381 +#define SYS_pkey_free 382 +#define REG_IP_IDX REG_EIP +#define si_pkey_offset 0x14 +#else +#define SYS_mprotect_key 329 +#define SYS_pkey_alloc 330 +#define SYS_pkey_free 331 +#define REG_IP_IDX REG_RIP +#define si_pkey_offset 0x20 +#endif + #define NR_PKEYS 16 #define PKEY_BITS_PER_PKEY 2 +#define PKEY_DISABLE_ACCESS 0x1 +#define PKEY_DISABLE_WRITE 0x2 +#define HPAGE_SIZE (1UL<<21) #ifndef DEBUG_LEVEL #define DEBUG_LEVEL 0 @@ -141,11 +164,6 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write) dprintf4("pkey_reg now: %08x\n", rdpkey_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) @@ -223,4 +241,38 @@ int pkey_reg_xstate_offset(void) return xstate_offset; } +static inline void __page_o_noops(void) +{ + /* 8-bytes of instruction * 512 bytes = 1 page */ + asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr"); +} + #endif /* _PKEYS_HELPER_H */ + +#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(); \ + assert(condition); \ + } \ +} while (0) +#define raw_assert(cond) assert(cond) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 4aebf12..91bade4 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -49,34 +49,9 @@ int test_nr; 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(); \ - assert(condition); \ - } \ -} while (0) -#define raw_assert(cond) assert(cond) - void cat_into_file(char *str, char *file) { int fd = open(file, O_RDWR); @@ -154,12 +129,6 @@ void abort_hooks(void) #endif } -static inline void __page_o_noops(void) -{ - /* 8-bytes of instruction * 512 bytes = 1 page */ - asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr"); -} - /* * This attempts to have roughly a page of instructions followed by a few * instructions that do a write, and another page of instructions. That @@ -182,38 +151,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 -# define SYS_mprotect_key 380 -#endif -#ifndef SYS_pkey_alloc -# define SYS_pkey_alloc 381 -# define SYS_pkey_free 382 -#endif -#define REG_IP_IDX REG_EIP -#define si_pkey_offset 0x14 - -#else - -#ifndef SYS_mprotect_key -# define SYS_mprotect_key 329 -#endif -#ifndef SYS_pkey_alloc -# define SYS_pkey_alloc 330 -# define SYS_pkey_free 331 -#endif -#define REG_IP_IDX REG_RIP -#define si_pkey_offset 0x20 - -#endif - void dump_mem(void *dumpme, int len_bytes) { char *c = (void *)dumpme; @@ -424,9 +361,6 @@ void dumpit(char *f) close(fd); } -#define PKEY_DISABLE_ACCESS 0x1 -#define PKEY_DISABLE_WRITE 0x2 - u32 pkey_get(int pkey, unsigned long flags) { u32 mask = (PKEY_DISABLE_ACCESS|PKEY_DISABLE_WRITE); -- 1.7.1