Received: by 10.213.65.68 with SMTP id h4csp1596661imn; Mon, 26 Mar 2018 10:33:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELt9hLCXzTC1ppVUQuVUEDunZUPDTPKIiCpHQ6SmrCbIZ47t1VNINpi5szYeGCsyr3YMi8pP X-Received: by 10.98.110.71 with SMTP id j68mr33519286pfc.93.1522085611307; Mon, 26 Mar 2018 10:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522085611; cv=none; d=google.com; s=arc-20160816; b=FdH0APn2z1yIHuoB3/M3hTRFad9gErscjsazZ1naRbNHQ2xfhjoiGnRBi6G+qfw3TG kLNrqRrfU89yHATytttIVgEpfVMZbvEW0nmKk4vBtXbeQTkhAPmbDYje7M2CdmIezuei DF5/H/yh7sAx8LRHc7MUzM6IaEFcQ/lqP1f1qf0C8ZXEI37uxus1V8HRp9Nk44cx2+Up OMYPUV4jnk7CAT4+YKTSqb5ydLpHCHCHw+RzD3IjWjncvczKtNwHFLKDS0eL40OZazqL DgUX+8n1vQnJumSPQ1i+x2qcnM80wzFE7lw+QOFgCncep1vdQaSSo0iHFPitklQI+MAP N86g== 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=UQcT6Q56Z/WEU+C3WTBi6N4dUx592jkiIov88V5N/nL6kxdqF+9z2P4RgA9KOwNeLG qT7baQnMYOwR8qun2UVfGcZJma7TuFGHtW1tmfzqmq25+Zh1iHVbD2agJPJcUliL+CfF lma7JDldvmi2pwCztFxgN8gw5zXG5pM6bWUh3+eOmuCrCS2PTLWtTl318sTv0zKFQrZt 7B3rOT9NzSbKhrVU+9bS/Zg2iccZxmw44cJbx6kd8bO1YKGvFlaIWbkq5y1qLjcOi+1d EfFrnph5kYD2h5MtxiVdkv36Oet0ImhMVB13lGi7b75ML+Al81G4x5vDIp7MCI/7XQx5 FV2Q== 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 m198si1412090pga.107.2018.03.26.10.33.16; Mon, 26 Mar 2018 10:33:31 -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 S1752831AbeCZRaf (ORCPT + 99 others); Mon, 26 Mar 2018 13:30:35 -0400 Received: from mga12.intel.com ([192.55.52.136]:63598 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751964AbeCZR3n (ORCPT ); Mon, 26 Mar 2018 13:29:43 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2018 10:29:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,365,1517904000"; d="scan'208";a="186135080" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga004.jf.intel.com with ESMTP; 26 Mar 2018 10:29:43 -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: Mon, 26 Mar 2018 10:27:30 -0700 References: <20180326172721.D5B2CBB4@viggo.jf.intel.com> In-Reply-To: <20180326172721.D5B2CBB4@viggo.jf.intel.com> Message-Id: <20180326172730.48EE82DF@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]); _