Received: by 10.223.176.46 with SMTP id f43csp3263611wra; Mon, 22 Jan 2018 11:02:30 -0800 (PST) X-Google-Smtp-Source: AH8x226NXE31n5wl2aJd8/f+JaNdgpVNtt7sAooET7yy2XXSBapH/qYgRNLbj+XFM0+mHr6NJzU3 X-Received: by 10.36.17.208 with SMTP id 199mr9355487itf.103.1516647750578; Mon, 22 Jan 2018 11:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647750; cv=none; d=google.com; s=arc-20160816; b=eMC0HY8jrOCGX86zS7r6g13iavCzKCpx1IMP/oR5CH4EfN0nDKrVa2F+gvzjkOKIZc feo34L7ooG7sMFuTCEz2ZBewkseL9Fc/HzzY8OdIs6BO5+Q7ap0CpUgS20S1AfTH/jKg C1wcr9PRRnic7UhXvyomhtgav/BRSJrHkSPYkJI76c6us2gbPXX9Yk+hgzHLkAYbwnZD eZFkXtIsuwj3JqW40cfpAoTnbTFaQA4w1bC/H7S7OGslJrdAHmA1coRw8elgljMwUR5D GhVkmjQyGi3W21HGArcmiDf5Nx4TaAXeSdHmIvH8rRsiwdLq9ytamLW0fu8gNsQ1eMPa LATw== 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=aMP8tov7n7/HdBAYcjs88xbJArCeKLtl6I2ar9Jcjs8=; b=n5A+nuEqZo9AIZIN8YwSkV9HTaRtjVtc7+AwMpoDgGnaR4LlCdvT54Nxmf7IUIfQq2 Z4oDsxIUYGv1yi+pf/Xfiu1WH6Z+sIZ0NZazVUxGEDqsTi74zaCCLdzaukb7AnOuWb48 epACN+VEHdydUKh6HK5Uq/iYfYXucE92+PoQ56lyuoRqCUUU795nTG6M5FFN8X4jf6SH fKYlRIkO4/e6KQSmxxK4sPWCvTBOSxyf+/QVZpJqX7RHu4ItRltxTpJlH0Bb5FSOTLCw immgP5corLy/ie90LUgXny+dthtIoZAGVpmaFA/o0M73e8ZfamS0W12uaDkJRQb7vKhX XNZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=D1h5KQsu; 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 f193si6687400itd.38.2018.01.22.11.02.16; Mon, 22 Jan 2018 11:02:30 -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=D1h5KQsu; 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 S1751407AbeAVTAo (ORCPT + 99 others); Mon, 22 Jan 2018 14:00:44 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:44198 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237AbeAVSw5 (ORCPT ); Mon, 22 Jan 2018 13:52:57 -0500 Received: by mail-qt0-f195.google.com with SMTP id l20so22125865qtj.11; Mon, 22 Jan 2018 10:52:56 -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=aMP8tov7n7/HdBAYcjs88xbJArCeKLtl6I2ar9Jcjs8=; b=D1h5KQsuftmK8kq/pYLnytkDhUVFTO1fl88dFMD9GtP5rKbxlINz8fTDzqHSzLkMp7 7rvqZ3C0zZ0+Lxxx3sqd9ktHD0wo+wBAWKx/schjDtAyUiaIY4amArYOKgJW47EdjH9p UzArpCghNEIG5LVYpBdv/tkPLhxEM5VgrLoDx8EOmrKm/gJwguOeY/L2Ew/SQvR5Gw90 cU7auN+fkkhJZYbRA18cHBATEpCSD6Dwj549ktDJTMz/3SJtfZwbyCqWDNsO6i5pHFk9 yyiigbAkdJr/f9+NPWfB99lP5Wms1JFHEfcWZXgYzVFeruQbAEZJbLv1xx/QbTlEHQdg Z0pw== 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=aMP8tov7n7/HdBAYcjs88xbJArCeKLtl6I2ar9Jcjs8=; b=cTy6K94BFJIfyhprJauA3piFoUUg7aT+FI4H2RZYevrGv+mxFmOxaFIzR9rbo8WlMo P+BqomQgYi8Vy96myUQkfvwkKANYgILOkUxBH/p8HodbB96ZvXEZbizyZbhCXtzPav82 gOTEaVX3whkhRDSpKcloNqQZ1VmYe3cWUiPq37R1EQx1WNNsmCv5hsHn24m1O2+vZe8F Maq3O4JELdLXyuBz4DiYV43vGKtM73rZ+iKQoeLVowcXJxrSR2mcJWiuFKe7mxIS0IDY Csp0cfwVNi7m3gl3Lsa//KzXjxtI79pPDd6Zs15YP/LXW/yLtU1qyjlwnlzDgO2tgQuX 8zRw== X-Gm-Message-State: AKwxytd+zmSi2WESK5FpFd8+SB1NXwMayS3ggVWUnzu5SJzcLLhZcJpn pjl4J0cdLt0M+wbt1xGQdGA= X-Received: by 10.200.17.25 with SMTP id c25mr11351816qtj.97.1516647176230; Mon, 22 Jan 2018 10:52:56 -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 o20sm10790061qkl.14.2018.01.22.10.52.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:52:55 -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 v10 03/24] selftests/vm: move generic definitions to header file Date: Mon, 22 Jan 2018 10:51:56 -0800 Message-Id: <1516647137-11174-4-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-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 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