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: 10529509 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 1F1FD6020A for ; Tue, 17 Jul 2018 13:50:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 037B729203 for ; Tue, 17 Jul 2018 13:50:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E981529221; Tue, 17 Jul 2018 13:50:49 +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 79BFC29203 for ; Tue, 17 Jul 2018 13:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731753AbeGQOXe (ORCPT ); Tue, 17 Jul 2018 10:23:34 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:36481 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731748AbeGQOXe (ORCPT ); Tue, 17 Jul 2018 10:23:34 -0400 Received: by mail-qk0-f193.google.com with SMTP id a132-v6so518383qkg.3; Tue, 17 Jul 2018 06:50:48 -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=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-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=T8r9Er3E5+y2jbEdCEqvWl9P/F0/Dx/IBruwlgp4gX4=; b=ErULxindWSDrt2xDBjegTCYRmz+tBL1VBZESUNQQ+wWb+e+vz7kibfKE/SBltoWHaD yEMk0v3/N88roahuLJ2T54+zor6d8XUM5fEwczWC2laDgH//aUDlB6p95ZiZDfL5yBpG WkLrVDzrve1coetSBWxbCl6oaAZWFxOL7MpkBkVuhTqcy+nDOwtsPDiw3qwrUssKEv1E PQ8pScVSJgKUMag1m4By31yoVsDj0168dV9j8EhJ3g1fSpR7YLJEoNB5k5Bvkjm2qJKR TIo/Hjwf1dA8vaNZo5IGGB7IDOCp6WUQVo8wO3CfklrnhvXG54OImh1pyI20uylQ3ItO nn2g== X-Gm-Message-State: AOUpUlHsKNRyJ0XIYs/9ta6G4YSFo3EL1uvtQW41m2Nf8whKKHgoDjRo XKN6mXieGe+DX4ake2Jzrkc= 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> 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 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: