From patchwork Fri Jun 11 16:41:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 12316179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1037DC48BD1 for ; Fri, 11 Jun 2021 16:42:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B82BF613BA for ; Fri, 11 Jun 2021 16:42:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B82BF613BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B07FC6B0070; Fri, 11 Jun 2021 12:42:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADF4C6B0072; Fri, 11 Jun 2021 12:42:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CE306B0073; Fri, 11 Jun 2021 12:42:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 70A7E6B0070 for ; Fri, 11 Jun 2021 12:42:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1823218141EE0 for ; Fri, 11 Jun 2021 16:42:06 +0000 (UTC) X-FDA: 78242010252.06.D2FE309 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf12.hostedemail.com (Postfix) with ESMTP id 6CD2442D for ; Fri, 11 Jun 2021 16:41:53 +0000 (UTC) IronPort-SDR: x3KwvBOnJARW3yBi9YZE1yyYQE29ROMxgI05McTlfS2P7cCZRMduWpLdgq1Z18g67ACRT+K22h Q0pNNEJgIljg== X-IronPort-AV: E=McAfee;i="6200,9189,10012"; a="203727838" X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="203727838" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2021 09:41:58 -0700 IronPort-SDR: NGXCGd65aHXP1eWWzOdd+o+XLlDI9Az4nz+l4W8gWmXHs5ouLVCoQvIjX8mYTnm+TVbAz1FQoL o13WAem5nPZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="470684657" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga004.fm.intel.com with ESMTP; 11 Jun 2021 09:41:58 -0700 Subject: [PATCH 2/4] selftests/vm/pkeys: Handle negative sys_pkey_alloc() return code To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org,Dave Hansen ,tglx@linutronix.de,linuxram@us.ibm.com,sandipan@linux.ibm.com,akpm@linux-foundation.org,fweimer@redhat.com,desnesn@linux.vnet.ibm.com,mingo@kernel.org,bauerman@linux.ibm.com,aneesh.kumar@linux.ibm.com,mpe@ellerman.id.au,mhocko@kernel.org,msuchanek@suse.de,shuah@kernel.org,x86@kernel.org From: Dave Hansen Date: Fri, 11 Jun 2021 09:41:57 -0700 References: <20210611164153.91B76FB8@viggo.jf.intel.com> In-Reply-To: <20210611164153.91B76FB8@viggo.jf.intel.com> Message-Id: <20210611164157.87AB4246@viggo.jf.intel.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6CD2442D Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf12.hostedemail.com: domain of dave.hansen@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=dave.hansen@linux.intel.com X-Stat-Signature: 5jbrtr8eqxyu45x5z1d7cwyz6fppb1xe X-HE-Tag: 1623429713-306974 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dave Hansen The alloc_pkey() sefltest function wraps the sys_pkey_alloc() system call. On success, it updates its "shadow" register value because sys_pkey_alloc() updates the real register. But, the success check is wrong. pkey_alloc() considers any non-zero return code to indicate success where the pkey register will be modified. This fails to take negative return codes into account. Consider only a positive return value as a successful call. Fixes: 5f23f6d082a9 ("x86/pkeys: Add self-tests") Reported-by: Thomas Gleixner Signed-off-by: Dave Hansen Cc: Ram Pai Cc: Sandipan Das Cc: Andrew Morton Cc: Florian Weimer Cc: "Desnes A. Nunes do Rosario" Cc: Ingo Molnar Cc: Thiago Jung Bauermann Cc: "Aneesh Kumar K.V" Cc: Michael Ellerman Cc: Michal Hocko Cc: Michal Suchanek Cc: Shuah Khan Cc: x86@kernel.org --- b/tools/testing/selftests/vm/protection_keys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -puN tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_ret-code tools/testing/selftests/vm/protection_keys.c --- a/tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_ret-code 2021-06-11 09:41:32.448468063 -0700 +++ b/tools/testing/selftests/vm/protection_keys.c 2021-06-11 09:41:32.453468063 -0700 @@ -510,7 +510,7 @@ int alloc_pkey(void) " shadow: 0x%016llx\n", __func__, __LINE__, ret, __read_pkey_reg(), shadow_pkey_reg); - if (ret) { + if (ret > 0) { /* clear both the bits: */ shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, ret, ~PKEY_MASK);