Received: by 10.223.185.116 with SMTP id b49csp1379899wrg; Wed, 21 Feb 2018 17:59:33 -0800 (PST) X-Google-Smtp-Source: AH8x227ljjUY4BRlrz88/N9qkeUkrQhWKNtBBmVSqf/ukvrLbupPL9HwEHBBIiqDVkzW/oWuEePQ X-Received: by 2002:a17:902:61:: with SMTP id 88-v6mr5070135pla.428.1519264773156; Wed, 21 Feb 2018 17:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519264773; cv=none; d=google.com; s=arc-20160816; b=xH5i54XTRVtTHnI56UlhSJhdt0nn2sZ9nIjEjrTaxWq0IMoEXQzl2WwXKjkXzzujb0 HPuHqtLutM5JrlluF3aEsky4dQxK8w/CUet2cJtB0vnzubVNpy/Ko7F8BNOHCl2efi90 ldgbhY1wfw+5h34kGs4Qxdmwpob6HNhmMhK8WGbmsJ++szcAWvqBTEw558dv7p857c/S 34Cz860cA00OFoNuyyVx9H/b5JhExTJprrXqRDk9X/HaODd74LMsboW9SZ/Fc7oquHjD wNHqJsWkaQQoY5TWAURIqnMnbM0qlh4qSjBW95Rb3nq0zfyqdWt3F7yjgGs5e6eztt6h IbAQ== 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=sG7Kw7BOW8vrYchKggektfQWNTwx8TCDdfyt1NuXZts=; b=gd3V8ccR63MkI0OX1itwpeshIDBBY25UeX6pOZODQUgJklE3k2/tlQ48ILFMPWiVzL 45XUXB1xs/5z6e16SgE859r2A4ElyVUeBEleUyfyFVg6dctGqdmQ+zuzKf57K8GxRK+p pwN9qK8HlRfLRAupDu/rA6wWHshREPvgmrwf09mWbopHjv6p6+CRnJpNRDm/OeamxHIh NB5aCcL1HPI+hJtM5YtzDiOSKm0+CT53vN6VMqmy+AHvhjxYCepHFRH02coXUCCETooL 41u0odkazXz4CqQQWtB0tghP0tsOxSZFpfa9kGmAq9mZ239WM558ELuBKInPB7tLXFWm zl9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZKSr4snf; 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 133si147388pfy.347.2018.02.21.17.59.18; Wed, 21 Feb 2018 17:59:33 -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=ZKSr4snf; 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 S1752173AbeBVB5V (ORCPT + 99 others); Wed, 21 Feb 2018 20:57:21 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:42729 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752130AbeBVB5P (ORCPT ); Wed, 21 Feb 2018 20:57:15 -0500 Received: by mail-qk0-f193.google.com with SMTP id b130so4627046qkg.9; Wed, 21 Feb 2018 17:57:14 -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=sG7Kw7BOW8vrYchKggektfQWNTwx8TCDdfyt1NuXZts=; b=ZKSr4snf9pH0xxMotbEe2HulWm/U6Cxcn2b6k/TN7SX01EqvEiA9p0vYNhBZTT/ZMe +DxHVq7ZM8pcMluSNduRFOExvAHbID9yYp3Xal3WYvWUO5iD31fkND1EnuIug7yKy9Hk oVN3rItu4PsB6RB6oi6W9zrKFhGiLfe7pQz1GWQ0vIdp5TxvOeEp9pgdMlFGFrKo/SQ1 Zc/3x6lXGBK7uM+NNmwgbbMVycne6WlOD1qbJ0FV5WiFCTS0nCkcrTi7KiCD8NaLdKKS WllSrcqZ0djPS0wmT/wS9FCp+58JePXEOj8qtYHaH6KLqWZf34rrRl9itvv/cq0kCALx OfgQ== 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=sG7Kw7BOW8vrYchKggektfQWNTwx8TCDdfyt1NuXZts=; b=aJNPF9K+YiCxMwCqjhaRpYa56RYOdN+XcPLzILJKJRq9Cikf8ipg5vtCUbGHHgEUWu WNVardl6HaRM9WlR0Dnts+BK2oe5auKQnKQXimM5ailwjgZ5tnRGxqvFTZ553OuJ1j+Q WHi71qVsBBY200Kf1WTbIuQHY0r/OSXi41c/jGGr4FGUe51AdsMhGLSNPUNpOJ06WY7w ehv1g6Bhd3dXcvkPXW+1itD5ZzcxV5W+fpr67VDSCqEk3tktOBc4QwZGxIgkdaYfOnQh LOJzF0DwHmFNVmEmlCn4zqAsymXMu6WoOdA3jGZnAWOgSYokOoKKSKxg53D7TumoAjBz 0xNA== X-Gm-Message-State: APf1xPBAwgOiMutOQjeXL+JzFJZhP5NBbWeRcVKq5fvT9hT/EVnzTy74 7j9lqozWqfXcB8AVeLRVKBA= X-Received: by 10.55.160.2 with SMTP id j2mr8551132qke.200.1519264634203; Wed, 21 Feb 2018 17:57:14 -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 n29sm14182630qtf.18.2018.02.21.17.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:57:13 -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 v12 16/22] selftests/vm: fix an assertion in test_pkey_alloc_exhaust() Date: Wed, 21 Feb 2018 17:55:35 -0800 Message-Id: <1519264541-7621-17-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-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() cc: Dave Hansen cc: Florian Weimer 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 88ef58f..67f9b0f 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -416,4 +416,18 @@ static inline int get_start_key(void) #endif } +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 58da5a0..aae6771 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