From patchwork Tue Jul 17 13:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529533 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 DB3166020A for ; Tue, 17 Jul 2018 13:51:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF6CC29203 for ; Tue, 17 Jul 2018 13:51:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B35C129221; Tue, 17 Jul 2018 13:51:35 +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 3475029203 for ; Tue, 17 Jul 2018 13:51:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 380516B027D; Tue, 17 Jul 2018 09:50:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2DFCC6B027F; Tue, 17 Jul 2018 09:50:49 -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 0DD436B0280; Tue, 17 Jul 2018 09:50:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id C6D226B027D for ; Tue, 17 Jul 2018 09:50:48 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id w14-v6so843433qkw.2 for ; Tue, 17 Jul 2018 06:50:48 -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=T8r9Er3E5+y2jbEdCEqvWl9P/F0/Dx/IBruwlgp4gX4=; b=K/BOG7jSsKgmIgYso3koYa5n+IYAUqpwz4W32wtzD1chNqEsTJoegJtpzl2iqXCs/Q ZSAFbpKKfWO7OP60+5M+N6D/fItLlaKR5U/ZzpoqmchLVN89ltCzgYECIyJzV6O99BAw Lt73s6Ef8nVXzEsrIOQf1iE79rQfoFdQUqwx2c2Ujytt8lCwdRG2KdaGEDfl9zDcO3Rn 02Bl0NSqz0Lo0XBBugsyLQ1Qmd+Uu9gxzXhqe++kn6F34ojwMB6kBVdXgXqN/BnbJ3c9 zRBFcZ2m5FRoHBY8cKgCoNwpycvSvpKEkiivPwcsLJlkDNCtL2kOWZ5IOJf02K1lO3QD qsVg== X-Gm-Message-State: AOUpUlFxRtEBja71XtPJ3qSi7wSae69j7Ag4yNtPONkUoFBOcWn7lyrC 7UzZW6QcMnLRAibXklag4CGqac32qTR7rHPKRSnr43CjS4JY6aKz0rx1rBG1w3rVYKH8KBNJdsD 2ei+0RvLNfS/ySBTMk4xJuoOgJCOA0FMDUTlPoAGXAHCBf2BE6qVZWAMDDUdzN93h5jXokwszvT /WBcur+GGeH8tcU/5yPj+OydFW19nyc4KUNgRV4ygfd+lYEYUB+E23Cnk2QeJKjQffL4tDov7xk y7UkRgkTfLfShbA/V35aX7j24BBym0OdusLUg2hB8SxIsxLP9Y524u6FQ0uXsfN8U3YH7/nOKDw 1ftp+ybv0HgYj33MGQSfeyNGeFq+sPDObKxhoJWUe3hExQwpaHeSzZFD3Xx60b2kKBlKiBghfQ= = X-Received: by 2002:ac8:2943:: with SMTP id z3-v6mr1574590qtz.149.1531835448595; Tue, 17 Jul 2018 06:50:48 -0700 (PDT) X-Received: by 2002:ac8:2943:: with SMTP id z3-v6mr1574543qtz.149.1531835447875; Tue, 17 Jul 2018 06:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835447; cv=none; d=google.com; s=arc-20160816; b=PCpCQVE2nmWIh91rLSpJzLs0nd/GKCHKq8IS9h4MCUTJJB6Lkw/5VMn6QGdCRGGUXo R0JqxQWNWsWvPrjGRmQH28akuue7tICLoMiApob3uojDf895Xsnu4US2nkagiW9vWEth p8HXKWKwUl2zO8FL2f9MGVI7qXXVYwp5e6AzOl1STzG0O+bTKeAGAjzK2fYYW4TpN25d Ui5AZ9LkxdK0fb3wawfrpZq+YD3z5wMfqlyYemikWSzANaRzQiqprchBYr6oTD4CB32D 2FFVQm79Ub4wu8naXQJa+OsbeS35vz6OJP/zq5futSj4H1m19gd3saTUrDuZn0S9IQiw qkcQ== 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=T8r9Er3E5+y2jbEdCEqvWl9P/F0/Dx/IBruwlgp4gX4=; b=YqNdHYvIN6MhCLge9woOZqpj5102/LeMJRnaaARaQ77FRK0xsJgQX60eeByJAuzmD7 tpPXE1smLB7DEC8Ugrnk0QPfpJ5igYXeIZMYFfomTP575sNGSZX6PPrJaisOiUwVh2Za aKjuR1mNNM16qRVGpP68QPUtrvF7yPn/M3a2vO9lYJv+JSWogs7NLiGr2XDvfq4QDMp1 wOyPz9fyVihp04nGlthzJPzHAvaQ6daHy34576KF4p+wF/7Cdu6OYDuU0c+23cj5lZV1 gnMeKwpsMyCon36y8zz9XAkBcxQpqErwk7ZCoA8aQIqh3cMYEW0CQRFk7lKYZQUrZpVF mpRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hrevH+P4; 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 w6-v6sor499259qka.101.2018.07.17.06.50.47 for (Google Transport Security); Tue, 17 Jul 2018 06:50:47 -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=hrevH+P4; 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=T8r9Er3E5+y2jbEdCEqvWl9P/F0/Dx/IBruwlgp4gX4=; b=hrevH+P4nTlWXCrbADUYBhvh4uscoFVpMSQ2sZV8jb+axARfNezMeWv5iq9YWrLno/ KZpXsQnNGZ5THosR97rdEggkFG/yFR8SmIabdxfw/yRkLGhdFucOoweAy/u07oQnAyrQ 59LDg/14VBSCUNpxFlvP3g+wBMFUdBVT1p70vMaTCGTXyHRmfqz2rhE1Ty3TG23l10wF HIhoWhVEjc2NmOSo+oVeUzUHtHYXVnSiMYKKeOkOaxNEWydTGCILCeBU/cRynFauH4Md GwvuM18a6JWs5GjymqnU3fs/ut1aH2h4QL0qVS3plWhqtoAGF5/pmGMyve/VSAC/MDHF b+tg== X-Google-Smtp-Source: AAOMgpcWAoOb/GbE9cqxxlAkIH7ozxXRcWZvAM00kQeDuxE2KmYVEHMNGymvUqipqDHCZFUmA+dv4Q== X-Received: by 2002:a37:5142:: with SMTP id f63-v6mr1443274qkb.369.1531835447614; Tue, 17 Jul 2018 06:50:47 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:47 -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 21/22] selftests/vm: sub-page allocator Date: Tue, 17 Jul 2018 06:49:24 -0700 Message-Id: <1531835365-32387-22-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 introduce a new allocator that allocates 4k hardware-pages to back 64k linux-page. This allocator is only applicable on powerpc. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann --- tools/testing/selftests/vm/pkey-helpers.h | 6 ++++++ tools/testing/selftests/vm/pkey-powerpc.h | 25 +++++++++++++++++++++++++ tools/testing/selftests/vm/pkey-x86.h | 5 +++++ tools/testing/selftests/vm/protection_keys.c | 1 + 4 files changed, 37 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index 288ccff..a00eee6 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -28,6 +28,9 @@ extern int dprint_in_signal; extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; +extern int test_nr; +extern int iteration_nr; + #ifdef __GNUC__ __attribute__((format(printf, 1, 2))) #endif @@ -78,6 +81,9 @@ static inline void sigsafe_printf(const char *format, ...) void expected_pkey_fault(int pkey); int sys_pkey_alloc(unsigned long flags, u64 init_val); int sys_pkey_free(unsigned long pkey); +int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot, + unsigned long pkey); +void record_pkey_malloc(void *ptr, long size, int prot); #if defined(__i386__) || defined(__x86_64__) /* arch */ #include "pkey-x86.h" diff --git a/tools/testing/selftests/vm/pkey-powerpc.h b/tools/testing/selftests/vm/pkey-powerpc.h index b649e85..ab60f74 100644 --- a/tools/testing/selftests/vm/pkey-powerpc.h +++ b/tools/testing/selftests/vm/pkey-powerpc.h @@ -100,4 +100,29 @@ void expect_fault_on_read_execonly_key(void *p1, int pkey) /* 8-bytes of instruction * 16384bytes = 1 page */ #define __page_o_noops() asm(".rept 16384 ; nop; .endr") +void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) +{ + void *ptr; + int ret; + + dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__, + size, prot, pkey); + pkey_assert(pkey < NR_PKEYS); + ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + pkey_assert(ptr != (void *)-1); + + ret = syscall(__NR_subpage_prot, ptr, size, NULL); + if (ret) { + perror("subpage_perm"); + return PTR_ERR_ENOTSUP; + } + + ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); + pkey_assert(!ret); + record_pkey_malloc(ptr, size, prot); + + dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); + return ptr; +} + #endif /* _PKEYS_POWERPC_H */ diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index 887acf2..a7e4648 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -176,4 +176,9 @@ void expect_fault_on_read_execonly_key(void *p1, int pkey) expected_pkey_fault(pkey); } +void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) +{ + return PTR_ERR_ENOTSUP; +} + #endif /* _PKEYS_X86_H */ diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index ea3cf04..569faf1 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -883,6 +883,7 @@ void setup_hugetlbfs(void) void *(*pkey_malloc[])(long size, int prot, u16 pkey) = { malloc_pkey_with_mprotect, + malloc_pkey_with_mprotect_subpage, malloc_pkey_anon_huge, malloc_pkey_hugetlb /* can not do direct with the pkey_mprotect() API: