From patchwork Tue Jul 17 13:49:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529475 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 9B8D16020A for ; Tue, 17 Jul 2018 13:50:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82D9029087 for ; Tue, 17 Jul 2018 13:50:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7652329221; Tue, 17 Jul 2018 13:50:28 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A68929087 for ; Tue, 17 Jul 2018 13:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731699AbeGQOXN (ORCPT ); Tue, 17 Jul 2018 10:23:13 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:36937 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731691AbeGQOXN (ORCPT ); Tue, 17 Jul 2018 10:23:13 -0400 Received: by mail-qt0-f194.google.com with SMTP id a18-v6so886925qtj.4; Tue, 17 Jul 2018 06:50:26 -0700 (PDT) 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=3Msqigu/NKIbCJKAgSdf6fLoN8lQRyfGKzwl0VZ6Ltg=; b=N4t1v/s/4uP2pxBySXS3TmjfNvrjt+Xt2yyLeqYCkSLlC9zeBkDGU9tQX9TR2u/ZcX wK2lVP1dYIGNfQZvQ8D9jVubRE9qiAJIWmwoQDEoN8yd+7VVsrJRK0F6iguZlMok+/s+ mFqzdeBOpiTxzCbgIeTAnPeh3Zmz7NAR5K4h0SE2Zspcyn5Ey36LwvhVt6y20b1afo3f o8bNLnYy7D2T3yavPH12Pi0aTWOFokbIWG2UnjNQCfTJksvN7GpW2ISaO8bZi4sru2st mUqvx6enH2fmR4nOFHO/Wro9k+b7/mXvFPyvV/LrQKjP60FZoC+iKGRzzSreGeQx48Da 8lew== 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=3Msqigu/NKIbCJKAgSdf6fLoN8lQRyfGKzwl0VZ6Ltg=; b=S6SwRF8QSRwxk+EmwtbHYwzfZ2O5lem5Gi0Qajf6//Jtav8jhzQYEtIU+TIACbfeiJ A5qpjGoUheDxdBfUUmAzc1cINOmCXWL5Jf0fMjm6ASl4DsGwT8PQuBtTeIi4f+u66b40 PrGLYZKBy0jTBf0n4zNJdI406axdD8N6eC4sYBSujJ9UrMfS53xpOtUqA2yU4s8ni5o3 sROxWgUqnAztTe8s3dpQaAOuSkwiOIDIXpA8cz1q6akWz/l/9CZSDXZgSmAbcbOOe/Iw VisrZh0bjWQR2k7+uwrvuGygeDCHzzTcpcGH9Jgx1BMraP7OmQ1N16Oys/Kn78p2ypxD l1WA== X-Gm-Message-State: AOUpUlHYDoZkVSnHi5ruhtNvwrDD3KZFqwurBdov6DxGs5P48hDPa/6U 2XrvtuvRWp2lF9qXgxXjEuY= X-Google-Smtp-Source: AAOMgpdyBmQ1nQbo2J76/zxxOub0hGu1KtCqOFL7EfIoxkumPVxJHOylrmd/XQSR1X0p6DwdCSIueA== X-Received: by 2002:aed:3803:: with SMTP id j3-v6mr1603561qte.353.1531835426238; Tue, 17 Jul 2018 06:50:26 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:25 -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 11/22] selftests/vm: introduce two arch independent abstraction Date: Tue, 17 Jul 2018 06:49:14 -0700 Message-Id: <1531835365-32387-12-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> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP open_hugepage_file() <- opens the huge page file get_start_key() <-- provides the first non-reserved key. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann Reviewed-by: Dave Hansen --- tools/testing/selftests/vm/pkey-helpers.h | 10 ++++++++++ tools/testing/selftests/vm/pkey-x86.h | 1 + tools/testing/selftests/vm/protection_keys.c | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index ada0146..52a1152 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -179,4 +179,14 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write) #define __stringify_1(x...) #x #define __stringify(x...) __stringify_1(x) +static inline int open_hugepage_file(int flag) +{ + return open(HUGEPAGE_FILE, flag); +} + +static inline int get_start_key(void) +{ + return 1; +} + #endif /* _PKEYS_HELPER_H */ diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index 2b3780d..d5fa299 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -48,6 +48,7 @@ #define MB (1<<20) #define pkey_reg_t u32 #define PKEY_REG_FMT "%016x" +#define HUGEPAGE_FILE "/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" static inline u32 pkey_bit_position(int pkey) { diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 2565b4c..2e448e0 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -788,7 +788,7 @@ void setup_hugetlbfs(void) * Now go make sure that we got the pages and that they * are 2M pages. Someone might have made 1G the default. */ - fd = open("/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages", O_RDONLY); + fd = open_hugepage_file(O_RDONLY); if (fd < 0) { perror("opening sysfs 2M hugetlb config"); return; @@ -1075,10 +1075,10 @@ void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) { int err; - int i; + int i = get_start_key(); /* Note: 0 is the default pkey, so don't mess with it */ - for (i = 1; i < NR_PKEYS; i++) { + for (; i < NR_PKEYS; i++) { if (pkey == i) continue;