Received: by 10.223.176.46 with SMTP id f43csp3258249wra; Mon, 22 Jan 2018 10:57:45 -0800 (PST) X-Google-Smtp-Source: AH8x226s939gCpAyK6/u6/soHLuFvWuHpU0Cm/sMGjRhuOvc8GxYYjnfk1Xliod7wkes8PdczoZC X-Received: by 10.36.151.6 with SMTP id k6mr9498878ite.94.1516647465337; Mon, 22 Jan 2018 10:57:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647465; cv=none; d=google.com; s=arc-20160816; b=O3JG0s7eMh9RQz1/Fa8V5q1QPd6Jz/o5SX3so8GrxDsQ7niMARrJhWK/f23iCtMFuq oIs4YHSChXCg5i/hJooZZMHJiGvZHcoEbYFlJ+lM9+ZXyWeF2R+9Uup8s6ZdHS0cIZox NVaYpGvk2sz74X5c/LHozSipENDvm3WB+bM3Gw1txR3Gqt8/HzAP5UffzfD6Yfhwz0AC ryRO/xp3MYA3WdZ80QCwX1n5fQlrAzqGD5jEJfFxvpU7w60I46+aOCBrVrmnpeJvulTE IYx9OHEe3/RTb4apS/CPN2JzMBurpxhkyinich6jqkQIhiEDJrDqt6igwBNFGTXtLhon pecg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BsZHLzcrYXNlVTcVpvafUJYHwtIdwW5p2rcAYyRjhOY=; b=JnnZ4vUq5ePbbhFLCyk9uBPSmVQf2gAkhkxdw3MM15cXOWkgb9xYo+QpPOMBFWcPzo pX+pPAKn3rB6f0mUAOcQMuWPKs3xGuJElLzEFvzuSKVnDq7OmvBFc6Szn/2Gepfo3T4i NvgNUrOrBvfx49EhknoGeUViDGGkqjAwS5hD8USgFrXoZ9HQJy6GfIckFR9YAmMP955g IByVJC4jkkX1CTzJXQN+BHWUdNrRav3xQtzkHOzaBK41lkhZdnAUGGZVfcttA/OAyS6n z3PYx9hcTlMo0483aE+HZdy7e8b2MuUn+uoIB5GoMdKAQm1jiBwkLGT216qj0pAwGBx9 Hn4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=a+rgxpt7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a189si13281073iog.285.2018.01.22.10.57.33; Mon, 22 Jan 2018 10:57:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=a+rgxpt7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751697AbeAVS4h (ORCPT + 99 others); Mon, 22 Jan 2018 13:56:37 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:32781 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751255AbeAVSxf (ORCPT ); Mon, 22 Jan 2018 13:53:35 -0500 Received: by mail-qt0-f196.google.com with SMTP id d8so14861730qtm.0; Mon, 22 Jan 2018 10:53:34 -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=BsZHLzcrYXNlVTcVpvafUJYHwtIdwW5p2rcAYyRjhOY=; b=a+rgxpt7VA3wk4flBwNLCf0bQ8WRci1h8ZvNR0YwUDvHYhKbGZRfi81xI0hufYPvLo lncFCc3eeBThit78LhWrfZ7hpt3KyKp36+qQsTpclT7qO1iq01YKdnqzBlVAeRv/qh6r CBgMSh8N8WrEzGv2svDRztNXdy+l5naoRo2YEmWbeMw6EMVPXTr/GfwUynlNzYCrsiLI PN2jsPg8/W31pveqgLs3/4nCdjq/O0nFLVSQmdliYsWHQBoyxCNNy3Bei8zcC8uYbIXc 5FXbv7sgeEsKSPaKxqvrDqqqZjRAcJiAneDy0MvvE+h2bwE40HkN8kJjNpybKh0XaoBD e0hg== 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=BsZHLzcrYXNlVTcVpvafUJYHwtIdwW5p2rcAYyRjhOY=; b=YGXY36O4KOqKRGLhlYBunKvDKBXMC3FlIoWjJXPuZrX3P+QGfTW7A+5jMp6MOAmZA7 j5PrUOhhO1XyPZiDwUr3xp8WIraAp+1JtOTXoi7HOALCrsc1K2lsbL8lHAE1g8tyM511 lqzPgIqNXymUFdpeMOEkfqy4Oa6q5okQxw0w1TezsnoboYWM0cteDp/qCkdwk0rsrqEN qsi9MDSKqajjzIYculceRkH7olAvlLBrVz14ZRIQSMU+39AcEGKjj/JPPisVO7JX/IOi kO82kfior0iOYiq99OMDbr4sL5i0NV3Dda5QmCWD2Cc53GEPgowS9+CPQF/408QII+6a vG+A== X-Gm-Message-State: AKwxytfnlcHbhh+lwQ8sz4PgGU0xSKiGneele2xiZCbVxlBUazK94iHO UezyGfSvTy4WqRgJsfjz4ZQ= X-Received: by 10.237.48.225 with SMTP id 88mr12898944qtf.340.1516647214597; Mon, 22 Jan 2018 10:53:34 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id o20sm10790061qkl.14.2018.01.22.10.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:53:34 -0800 (PST) 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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v10 16/24] selftests/vm: fix an assertion in test_pkey_alloc_exhaust() Date: Mon, 22 Jan 2018 10:52:09 -0800 Message-Id: <1516647137-11174-17-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 3559527..9d06b4a 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -401,4 +401,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 65e6dd6..33d5839 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1167,12 +1167,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]); -- 1.7.1