Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp719342pxj; Fri, 11 Jun 2021 09:44:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8lQNxpxdaEXs73kzAXThlzr21LNq0ufn2GD9Vn7PoHFJhyN36fG/+TqXnB5j3JSAqrHSL X-Received: by 2002:a17:906:3042:: with SMTP id d2mr4614311ejd.234.1623429860438; Fri, 11 Jun 2021 09:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623429860; cv=none; d=google.com; s=arc-20160816; b=RJ6S3E1U8q9Z84Bxh8bekO31mh1RjovqTh5XDXxa7zyyGIr5+NWwuSVbmzbqmVKWu1 Jm7qy17iNjIkjfG1Hp5CEMxDMSdviV+cIOpJBNRyc6HqvfTETE695Yhs00wZIvAEPJp7 UhB4Z2id9TYQ3cmanfU9ij4LeuM+9o0aYZGA6VVCnMJc7lCz1zOUFyMWqy+XOFF7Erz0 S1l3D0DwGCvaVAc1t/6JPOMgLGxntifrMLfdECQWcguziuul7+4lFbDPylmhzsGRNfAa BsGogM3NJL+1GlZNT3G1Qa6ZRSlTLZJMLzwSnrRYM8ksmSM4iRaj431tbTIHqTh+d+KV ra6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=kHzbnN4uP0UHqish3IC3NYZBC/j+T4Rnr8xyk4qnk7c=; b=y08mLzo1PYS398toTAzcfuwGb4ZI0lpXfwW60EsSRZGdQMSVhgRetIiZ2uXd/b618h dJS1JhyRGFGRMCWQZ1hdZPcW1+7C0kvTAhOlTKXpVDJeWK+1rwlbwCUcR+QkQqu1/EXU +Z89+k6S9kbsJcNF/MZQE5QCDFApQb6V04LbAmp8oZgGoSzrn8Szs2Lg4UavdPE9rERG lbMoEowsz+nc9LRVtVDnBORPwk8UC8L/ONJwBYXmrYv2xh6hQl6lkexDfkTeKkavtLuV McmGd1HKZPSeFY5DoRx5kuTSJNyqVA8tXtUJ1XMZXk942nqWflPewRCra37Sk76F4cY4 VR4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si5488463edc.575.2021.06.11.09.43.53; Fri, 11 Jun 2021 09:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbhFKQn6 (ORCPT + 99 others); Fri, 11 Jun 2021 12:43:58 -0400 Received: from mga07.intel.com ([134.134.136.100]:18254 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231166AbhFKQn5 (ORCPT ); Fri, 11 Jun 2021 12:43:57 -0400 IronPort-SDR: 7Q45vBrva1qvq4b6t0MCRkjoms+yVZRgQ9RRKJj+Vj5YrNO0+y/FoSwQ+NSOhr1fX6FwjNJwma mdQkjnw61IgQ== X-IronPort-AV: E=McAfee;i="6200,9189,10012"; a="269410294" X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="269410294" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2021 09:41:59 -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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); _