From patchwork Mon Nov 6 08:57:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 834620 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVqRB4rySz9s7h for ; Mon, 6 Nov 2017 22:03:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BXqBo8r4"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yVqRB3dcyzDrK6 for ; Mon, 6 Nov 2017 22:03:02 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BXqBo8r4"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::244; helo=mail-qk0-x244.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BXqBo8r4"; dkim-atps=neutral Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yVmjl3hZpzDr5S for ; Mon, 6 Nov 2017 20:00:27 +1100 (AEDT) Received: by mail-qk0-x244.google.com with SMTP id l194so9994835qke.13 for ; Mon, 06 Nov 2017 01:00:27 -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=k9eDL1BW93C+KXAL0pwEabbmMfxZEWMVxdL8oHjLfzw=; b=BXqBo8r4R/mF91SCN8DWWYgtxvn2v8RghmF/bqfacvAKExT3TkNk5cD+TOi/r8zzDk sWny8nQuon5ecS2hU2HzP9gR5UlB1PPVVmOadgRD8+8UWbO0SZ+aBY9LMWM85hw55Q/x UTFjjjak4zat42grq+gBpCy9djK70Fe/2RuqI+mIQeK8ZpBqO13hyhcvW+aiLAvKGtIb iHhaNb3+ixM108/mMGSF6y8LzX6z0A9yM8InqzyVPNyuWLDSZgSmxmdMeuk9p9lycP3V 5hfCc/dHouBG87dc8vedqCm5mYM+8xmfBy/8lFJ89y/a5o983TNIg67HNDy7uNJhMKEM onBA== 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=k9eDL1BW93C+KXAL0pwEabbmMfxZEWMVxdL8oHjLfzw=; b=DdVTz6MeEQ+C0l+uD+yexEvSIq+zsSKVDzneGCZcNm2RezrXh7RHG2QnmP/kXuOrcu E/dzT7hrTnQhgArE2CCr/4DEtNx5AuB96McTcYGud/UpQdB399QUpAvt2AEKxBkXZcp9 V1jceFDQ5OTQ+feeYYGlsM51+4mJLZlog3LYHimabJdGbf20+VDKpsR12knbI9KBLZb7 Syu2XznviW9Kzc8JB7145JLdBRAECsrLkrx4rvtTehzOUvQO3PAHGMzqPXV2IaRuJLhr Cbqo2LubEpq0TLl8P5ZD+KtXNrcVqANiCw301+pwOKYDW3R0LzsazT/6Yi0QGmaphJiS rvqw== X-Gm-Message-State: AMCzsaUcHTq5AOgmN3q6Wfhn7/wUY7cVd+vofaJfbL48+Whq3AZg8/dK NnmlJNGWImFJfvDUmd66kc0= X-Google-Smtp-Source: ABhQp+TpP50OKs5g3xbFRJzk+INUKQVXY2AiWwLHg4QPr9Br6XgX8VFog8IbqGLfd45aYTUn6lGpIw== X-Received: by 10.55.94.65 with SMTP id s62mr19938577qkb.282.1509958825551; Mon, 06 Nov 2017 01:00:25 -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.01.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 01:00:25 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Subject: [PATCH v9 45/51] selftest/vm: fix an assertion in test_pkey_alloc_exhaust() Date: Mon, 6 Nov 2017 00:57:37 -0800 Message-Id: <1509958663-18737-46-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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, ebiederm@xmission.com, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, linux-kselftest@vger.kernel.org, bauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The maximum number of keys that can be allocated has to take into consideration, that some keys are reserved by the architecture for specific purpose. Hence cannot be allocated. Fix the assertion in test_pkey_alloc_exhaust() Signed-off-by: Ram Pai --- tools/testing/selftests/vm/pkey-helpers.h | 14 ++++++++++++++ tools/testing/selftests/vm/protection_keys.c | 9 ++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index f764d66..3ea3e06 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -388,4 +388,18 @@ static inline int get_start_key(void) #endif /* arch */ } +static inline int arch_reserved_keys(void) +{ +#if defined(__i386__) || defined(__x86_64__) /* arch */ + return NR_RESERVED_PKEYS; +#elif __powerpc64__ /* arch */ + if (sysconf(_SC_PAGESIZE) == 4096) + return NR_RESERVED_PKEYS_4K; + else + return NR_RESERVED_PKEYS_64K; +#else /* arch */ + NOT SUPPORTED +#endif /* arch */ +} + #endif /* _PKEYS_HELPER_H */ diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 4fe42cc..8f0dd94 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1166,12 +1166,11 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey) pkey_assert(i < NR_PKEYS*2); /* - * There are 16 pkeys supported in hardware. One is taken - * up for the default (0) and another can be taken up by - * an execute-only mapping. Ensure that we can allocate - * at least 14 (16-2). + * There are NR_PKEYS pkeys supported in hardware. arch_reserved_keys() + * are reserved. One can be taken up by an execute-only mapping. + * Ensure that we can allocate at least the remaining. */ - pkey_assert(i >= NR_PKEYS-2); + pkey_assert(i >= (NR_PKEYS-arch_reserved_keys()-1)); for (i = 0; i < nr_allocated_pkeys; i++) { err = sys_pkey_free(allocated_pkeys[i]);