Received: by 10.223.164.200 with SMTP id h8csp930229wrb; Mon, 6 Nov 2017 01:10:24 -0800 (PST) X-Google-Smtp-Source: ABhQp+RaKUcJeqDZ/tO0oqLFW86bdT8TCaU/9xAND3ICCGuxpY28HxndIZL+LiBfdv0pD/wGaQOk X-Received: by 10.84.139.1 with SMTP id 1mr14245592plq.20.1509959424575; Mon, 06 Nov 2017 01:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509959424; cv=none; d=google.com; s=arc-20160816; b=GIVYub1jJxqyyEEEIOqsU2XZ+HHIMIb2tA3Yk/qtNumSdvtrBFbWg5JTxqeSg1b3J+ Wbx+tRQx9YBtnoTpZBnOZnVtSzIdrwYBHXNrygmITRn5Bbsrhg9/Runpcv52h/56IpCy YVuApRvuXdnk3bhPenU20h9mAQ7bI2iPP+nqr0VfyeV5mI2j4JTSKvbo7267np1PQzbb m8VFhkywyLdQ8vsdUklgRphsz45l1DQhHCX/HI2jS3evfH2UPtYZKSsJJzWSWM5lpeIi fx7rf43/T0/mQykKB3fR5LGe3FQKUK422/yzHgdy7Pm8tZCUDEyKBB4noYuajT0BgL/r 5q3A== 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=biLl1AdfsHHUoEEdX/hK/aEE+TWhfXACeQjReospqnY=; b=Jvy91waZGbip9Yj/BCzsSuaqyIuc7xZs8WwKnThFuthejXtdlvFBnFRdWNgghHkG9l R9g4if28j/2uVI/RcH90EhX8plrEl6+nJ011DWfPqlcyDYN3chraQgZx9bfDFF8ah5Gf DdHI/3ExbuSp/FTDKjJJD/vkW0WV4sulsoYJCOBpxeULZX/Zg2a9w3no1s3OzyKM1oC3 LJoPO9LAgW+fznb/6LkSrUfry5piXtzKKNSgVCLkD16DeYaLcsnKS0wgwV//zSwPHIV0 +1e405iHy/d5iPOdgMaQ84wG2kyTibcUE/1SnQKFMrGiLtJqSDgvjZ/XDZoACeYLM1SG Ss4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VKfLW5E0; 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 z14si10836781plh.282.2017.11.06.01.10.10; Mon, 06 Nov 2017 01:10:24 -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=VKfLW5E0; 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 S1751588AbdKFJJa (ORCPT + 98 others); Mon, 6 Nov 2017 04:09:30 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:52929 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752445AbdKFI7z (ORCPT ); Mon, 6 Nov 2017 03:59:55 -0500 Received: by mail-qt0-f193.google.com with SMTP id 31so9995954qtz.9; Mon, 06 Nov 2017 00:59:54 -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=biLl1AdfsHHUoEEdX/hK/aEE+TWhfXACeQjReospqnY=; b=VKfLW5E0V0ge4s8Ph7iDK0oAt6Go0EXBodAVUQrz2rl9F2CXziriN+SDOvfXc2sjHz 2+vcZKWTNKxF0E3RI8Vv0Ox7vEHD9GBRFLSH4Zit0wxBVodDQVtfk5bky0I7zDLFCFcK T0RLw3/Qv1G4EoxokBQB+imQ9o26UKWdiEWPVERDOFotgEX+0h9zQQTQZp8TfchGYoOF XKt2hisWVhAE9iAhGVLTHAjCx6s2bB2ouoYAA4wMUhOCIofGhyj1zIGsfNQDzmWZ91T1 J0yCWoUyp331HL6/rCE+zGOKlnl+ti9KloXhcoe8/3ib0yG9NKCc9We5+4azZh2R4j/N ReHg== 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=biLl1AdfsHHUoEEdX/hK/aEE+TWhfXACeQjReospqnY=; b=TGNBqlGLEzSEydU6VRBGD23rtbC4cA9VsntnhBv+J3qgryEd4wQBwvkW7/QaPUHqBi 9RpFYJdr8sUe1njGwsed/D4cuolrisCEfjrD4yiDyvrsGWyWzrSNH1H1cztVqDW1dZjf yBsi2yWgcZ0Vp9LN6e8jSY2Rp/MdG1NFWTmhjUOLJ/a+KsTTvVXLMg+FD/kc4UJERXSf l4tiCXyyFu3o9Rzgz2rv1pXawC8prPPNRWUOaES0rGNuyfmrcz3LmS30pPOIK1CHlriH ynEFEbUNCXKKZmanRNjvugz3JJyD15b0vVl69uw9aRRf8Ckwc/ZPFpHMN9gzKW4kEgyU Ewfw== X-Gm-Message-State: AMCzsaVz/bi6NuCHZW62yHgjx8ILhZRXgL0YQvzJdpjrMl/xzVk0PHDn fVo5ndC2PPplszVkWKBWfTg= X-Received: by 10.237.59.90 with SMTP id q26mr20752977qte.153.1509958794350; Mon, 06 Nov 2017 00:59:54 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:53 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.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 Subject: [PATCH v9 34/51] selftest/vm: move generic definitions to header file Date: Mon, 6 Nov 2017 00:57:26 -0800 Message-Id: <1509958663-18737-35-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-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 | 54 ---------------------- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index 2d91d34..1b15b54 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 @@ -138,11 +161,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) @@ -220,4 +238,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 27b11e6..dec05e0 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,26 +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__ -#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 - void dump_mem(void *dumpme, int len_bytes) { char *c = (void *)dumpme; @@ -412,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 From 1583308442037330083@xxx Mon Nov 06 09:29:56 +0000 2017 X-GM-THRID: 1580052043957453261 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread