Received: by 10.192.165.148 with SMTP id m20csp998973imm; Fri, 27 Apr 2018 10:52:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp9jOgahJU+z9udaSP2IAHxPKHPD58hXyzKHjE+wCUAaEof1UqfClW4s19Z5hSE+pVVhnEf X-Received: by 2002:a17:902:8c91:: with SMTP id t17-v6mr3190340plo.182.1524851521361; Fri, 27 Apr 2018 10:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524851521; cv=none; d=google.com; s=arc-20160816; b=CVcXpxcD4VWMJMLyNSjUFmQcispE1DOQnyXuoDLQVzSLTtl/u9p5DdoMUWzt4Ypp61 vOsnt/b576BDQ6Zh9LsWspINd0f7oWZnDQcLU9g0utRjkbN+D5/uRsaH/AzivmazAr8G MC9VIvJeWMkhoIcvB7MXFaKSPK4KnfofeyY4uIGKmMBqwhcElNKqf4wH8nMfMNyXuwFe Wl+5McYZ0rwBeUGv0kXeGCYBGjdH5L1LGksa2d63X6K7yFtMDk59CN240oipcDGTHzJh U9j0rJxLL+fAm37MNyTkGltr/R89v4Gt1iTJXsfpdMSceczxFPE9TTEngJEBCUkGmwSd hVJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:arc-authentication-results; bh=NSFPJkaTy62ZE4n6cNkFgYgLs+bMyOpph9/0AH0KTF4=; b=asaLo9uGutPIn/Sz/bwaLfU8cJE7ZiDvVLl8EIEBeIGyRbp0gZVQU2NXKiQV5LRG6o vuWoPdydwfUyXOLfv3ViPF//3PWDIx8ludS9GeoVH7r3mHS/lWGxLO1REAL1NML0tKkg PXr5o4r3gC5g25uA5AUa1UMf1GqV33DeGPVceVDIJeDd0vmfW/+wTYgWGevi0jRITqAb F/0I8P+n2iyPTcsGRwZWT2Wcwe21Pyr3gX/npvvqffrbxA2M1Fz38vYSgGryn4+fHyNF 6HHWxenyJWT5zIJJKT3gxt2Lyhx4qa6mpCzeAp4tKRLFvJOPXY3YQrsYMWGilo8tNCYb Rypg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23si1636796pfn.365.2018.04.27.10.51.47; Fri, 27 Apr 2018 10:52:01 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932635AbeD0RuA (ORCPT + 99 others); Fri, 27 Apr 2018 13:50:00 -0400 Received: from mga18.intel.com ([134.134.136.126]:20114 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932571AbeD0Rt4 (ORCPT ); Fri, 27 Apr 2018 13:49:56 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2018 10:49:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,336,1520924400"; d="scan'208";a="41167498" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga002.fm.intel.com with ESMTP; 27 Apr 2018 10:49:54 -0700 Subject: [PATCH 6/9] x86, pkeys, selftests: fix pkey exhaustion test off-by-one To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , linuxram@us.ibm.com, tglx@linutronix.de, dave.hansen@intel.com, mpe@ellerman.id.au, mingo@kernel.org, akpm@linux-foundation.org, shuah@kernel.org From: Dave Hansen Date: Fri, 27 Apr 2018 10:45:36 -0700 References: <20180427174527.0031016C@viggo.jf.intel.com> In-Reply-To: <20180427174527.0031016C@viggo.jf.intel.com> Message-Id: <20180427174536.8C062DF8@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen In our "exhaust all pkeys" test, we make sure that there is the expected number available. Turns out that the test did not cover the execute-only key, but discussed it anyway. It did *not* discuss the test-allocated key. Now that we have a test for the mprotect(PROT_EXEC) case, this off-by-one issue showed itself. Correct the off-by- one and add the explanation for the case we missed. Signed-off-by: Dave Hansen Cc: Ram Pai Cc: Thomas Gleixner Cc: Dave Hansen Cc: Michael Ellermen Cc: Ingo Molnar Cc: Andrew Morton Cc: Shuah Khan --- b/tools/testing/selftests/x86/protection_keys.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-exhaust-off-by-one tools/testing/selftests/x86/protection_keys.c --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-exhaust-off-by-one 2018-03-26 10:22:36.477170190 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-03-26 10:22:36.480170190 -0700 @@ -1155,12 +1155,15 @@ void test_pkey_alloc_exhaust(int *ptr, u 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 16 pkeys supported in hardware. Three are + * allocated by the time we get here: + * 1. The default key (0) + * 2. One possibly consumed by an execute-only mapping. + * 3. One allocated by the test code and passed in via + * 'pkey' to this function. + * Ensure that we can allocate at least another 13 (16-3). */ - pkey_assert(i >= NR_PKEYS-2); + pkey_assert(i >= NR_PKEYS-3); for (i = 0; i < nr_allocated_pkeys; i++) { err = sys_pkey_free(allocated_pkeys[i]); _