From patchwork Thu Jun 14 00:45: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: 10463119 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 C9F98600D0 for ; Thu, 14 Jun 2018 00:48:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB68528988 for ; Thu, 14 Jun 2018 00:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFEAD28BA8; Thu, 14 Jun 2018 00:48:11 +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 EE56728B9D for ; Thu, 14 Jun 2018 00:48:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B81586B028C; Wed, 13 Jun 2018 20:47:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B2F126B028F; Wed, 13 Jun 2018 20:47:31 -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 A462E6B0290; Wed, 13 Jun 2018 20:47:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id 74DCE6B028C for ; Wed, 13 Jun 2018 20:47:31 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id d7-v6so3297793qth.21 for ; Wed, 13 Jun 2018 17:47:31 -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=U9rpyWUYPPHrbN27l6THjIWTwS86AfP9PLaJdEH/s0A=; b=IClvMv5ETbyQUgWAQr2Dq3fDsT3r7mx6yXw7gQgcxbM9HS9vqHlxBzVYtGFO12pPyr 7Wvlzl8HwfA9zpOwv/ZtN0yEyJi0V/JeUWFD0oYQy/ZU/QvmiWo18GXts4faTAAKPsnr HB4AMT3SoDPDnkNA5vNVOzeYexZZbpJhW64yFH7ds4Kom94EUu02rUsd1tGF/4z7jDyX Nna1mDCpFVlcr+5Lw/iJ9zCg/NBUYjpZQtamVAWY+GKqKa7vsC7rhlYd9uq3jaMf/59Q Pd6E6nE7GdQ3+N6cUNlyIonxSrlcCqPPXGQzkpEJ7nNKT6Xg4Q85J8QOx0A4xkIcwGTi UkaQ== X-Gm-Message-State: APt69E3xUU5m8jC9IlbictqAi6NQjNn+jFWOsMBhEzy+aPkmmolJ0WdD QUie555+/ZATz+gQaQTndpQzIqmDHnIzbuka/mUdDv+7HTN5QBHWRz6ofcUeTp7PeJJe+Y5o3ze 1s1hgq2Bvu5gD3gaq7GRA+RstzUSrwUiJVJp7plXcmthdMLaxKCH35Y1QQuWV99rXJpedL38Fbc aKr6KB7bMRZf8c8fTxcKL6R4sz2wxcIwLOuPbYfRF+aE/Ukp7mYN8ln0fo+ChaAwGlaLPZoPHCX AUYyeLZKBGf4zsZzZ68NmNyE0a63W5Im2ch8tUNz8gZqeHtmy0YlcS4BBze0FwccnucMxLYUN7S J69GUZ4RsQ32mEtz3poyFVn+3uJc2fd1DAMdWGxFa0bGxub45I+j6w0mEaHnZB2Ydlrex9hfAg= = X-Received: by 2002:aed:3ed8:: with SMTP id o24-v6mr376553qtf.177.1528937251279; Wed, 13 Jun 2018 17:47:31 -0700 (PDT) X-Received: by 2002:aed:3ed8:: with SMTP id o24-v6mr376517qtf.177.1528937250490; Wed, 13 Jun 2018 17:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937250; cv=none; d=google.com; s=arc-20160816; b=jMWqmvOcRIhenfy4Umi1BrXhTuc9LdQSiXYALKZ+ntBilZXt806LBdcNWAbj61z1kP 5mpODoCkdBLQiAKB0luvFXCPtT59867sj8+Wm50W6vZoaqaudLxJ0SbgKepbBiQ7Caw4 dfomMjlIw6EMYURYtm7KvdDm9+SGCOdFe5hTd+VhYs0LjUg8jvgA/BUObUwW9bWswhGH 56GCNkqcjR7LXvhZeqIuER32UFePa9aPeFyknhoatOsQZN+v2t5HHrxL8iKJ3zPQDtVk S6DaQjQsN7bvE0SXHhWkkfhYDyXS2Cz2bmqYVjyZ8y1zLoSZqUDEictuQmfOworwwB3U 1ARA== 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=U9rpyWUYPPHrbN27l6THjIWTwS86AfP9PLaJdEH/s0A=; b=A0YJ7wh0lkpSJlWGUg7n4zO/XAA0RtXXaOSMJCHgeSWpgOADnbJfK9k3hmNVxONflt h9Pan3Z4FW1Vz8w24X/AUmTwDaIG72lD2PIJUb1exR+ncZHOorT4uatZMVFEOrviyw34 llh8E001y3XQuX2wq66bi7/fHp6dR6uVTuvXgPDx3YCgunZD7L5iMqs6REC9ZsRsMWTC 70B//+1SaQZoAYGh3Pf0zG+aPW5EOsCdhxcGbBHnnbtNN+db+7iRS02jQV8mH+gojOgY dPyyHrnKLJTpReWHv8zOOWv+9Nn3r/MHkyCzpeTb0t9O4D8N7MnRxEQm4gdJt7/6XMk1 U2cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Bzm4S2Nj; 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 q69-v6sor2096124qkl.3.2018.06.13.17.47.30 for (Google Transport Security); Wed, 13 Jun 2018 17:47:30 -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=Bzm4S2Nj; 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=U9rpyWUYPPHrbN27l6THjIWTwS86AfP9PLaJdEH/s0A=; b=Bzm4S2NjXtheX+b8se4tH1cZeRMrhNDw7S1zMdLIIipRdhRQneJXc6YOjCRYbgxu+k lemLCNpZM/ry5TU2/QD6jvEqD7w+bXMfypyDEGXJT8Ip+U2ml+bDs1XaYZoIPZ3pQpLq Knb0R0Bx6n0r+2x69Cp8bhOrfjm90xSYF6jj3I+GjGLUP2zoHMGu+bPMG88gwJ58F/k4 GblHHqt09YCXjp3Sp4dIhKHa+1MuvReqgYxjGTlHYJMDeyEIh1jirG+voQxVjQEaI8OG Le/XVtVmQL1uLbx46cTIj41chbopV9j08P7HQo3b9MS75AU7BvzWM35SoXJYuDwrBqbm HQuA== X-Google-Smtp-Source: ADUXVKJ7jvh958x4gUgBsAeCVbokXS8k9rQtWE1ctherNxTgkZnQWK8R4ahbaLLP2BYALrX9+Gqo+w== X-Received: by 2002:a37:c602:: with SMTP id b2-v6mr321414qkj.413.1528937250274; Wed, 13 Jun 2018 17:47:30 -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 u31-v6sm3225898qtc.28.2018.06.13.17.47.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:29 -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 v13 23/24] selftests/vm: sub-page allocator Date: Wed, 13 Jun 2018 17:45:14 -0700 Message-Id: <1528937115-10132-24-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-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 957f6f6..af44eed 100644 --- a/tools/testing/selftests/vm/pkey-powerpc.h +++ b/tools/testing/selftests/vm/pkey-powerpc.h @@ -98,4 +98,29 @@ void expect_fault_on_read_execonly_key(void *p1, u16 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 6820c10..322da49 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, u16 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 b5a9e6c..cbd87f8 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -887,6 +887,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: