Received: by 10.213.65.68 with SMTP id h4csp597068imn; Fri, 23 Mar 2018 11:13:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELtRjQ11mrW3APbcwMqmdsuMFUfCjf38iZpUCXLC5YGmKvdxicqBUly1VZ4A0nqFJuMa8UnO X-Received: by 10.101.87.136 with SMTP id b8mr21423104pgr.282.1521828791933; Fri, 23 Mar 2018 11:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521828791; cv=none; d=google.com; s=arc-20160816; b=iyCZFHvujKpNTTYGq4H5wCkqPcAg1H4Y5WLCj39Lf8IBT8nq0UKuITDoLt18RuNrOz Qh01BVKVLlsOycd5smCCFIY3kDEjG2B1oKdT+BwKR/uHoe3FiSkSBJCDW7h8eymXfvKE MZIIdj+WPsoxsX3Okb4OlaIs1g9+RTTLQJe79g71kqc9KFB2EDE51hoZkQ5j+IlL7mF9 RikiUXdrTs3JR529LAlHCGi2p/4yL1UhmSAzUmkapIMPssIL0uQuTWVWFAmUfYuSG2NV EOo0K95h1E+qWDcoBQv9tJi9Tbr38qIPFoRndbvG4zzV/Pa0sI7pUt2ndIEW8QjYCmhW nMEA== 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=0C/JKCW9ANZ8kMFTuxIm6JMpwa6+/78aJuiD/dhifKA=; b=apj7DB0NjdCdGW28Oouj89RjspJGbLwOU+dF5hp8Hhqa2EfCA+oBbspoF7J+hvQOBA +UwQE98GVDHCClE8BGZFf7dXJMc1tZNe+oGdKtetuOwlCiSyKsozDb3Ev/e2zvw5fuOr plyKRPtUi6ozY+ZAMCyjFVA0YPQhObm1Sv+Raa/SdaS5vlEaLEu01SJv0ivrNW+BgU51 brxhmp2QEFUTLEJtB0KFzIc4flLPvvwVd2hcNXqPTNLwadOk3XDG4+2ekI25Ky0cvGHO R3/C8Wu+cNPtLs8z5qBCntzxx/u82G0O6SB9u+IdM4J5nfWVR4Bi53Aqre12Fhk6ymPd 9URw== 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 s184si3774589pgb.0.2018.03.23.11.12.57; Fri, 23 Mar 2018 11:13:11 -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 S1752384AbeCWSLS (ORCPT + 99 others); Fri, 23 Mar 2018 14:11:18 -0400 Received: from mga17.intel.com ([192.55.52.151]:9991 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752326AbeCWSLQ (ORCPT ); Fri, 23 Mar 2018 14:11:16 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Mar 2018 11:11:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,351,1517904000"; d="scan'208";a="28292571" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga006.jf.intel.com with ESMTP; 23 Mar 2018 11:11:15 -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, 23 Mar 2018 11:09:14 -0700 References: <20180323180903.33B17168@viggo.jf.intel.com> In-Reply-To: <20180323180903.33B17168@viggo.jf.intel.com> Message-Id: <20180323180914.58B68408@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-21 15:47:50.910198920 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-03-21 15:47:50.914198920 -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]); _