From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: Re: [PATCH v12 08/22] selftests/vm: clear the bits in shadow reg when a pkey is freed. Date: Fri, 16 Mar 2018 15:10:07 -0700 Message-ID: References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> <1519264541-7621-9-git-send-email-linuxram@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1519264541-7621-9-git-send-email-linuxram@us.ibm.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Ram Pai , shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, arnd@arndb.de List-Id: linux-arch.vger.kernel.org On 02/21/2018 05:55 PM, Ram Pai wrote: > When a key is freed, the key is no more effective. > Clear the bits corresponding to the pkey in the shadow > register. Otherwise it will carry some spurious bits > which can trigger false-positive asserts. ... > diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c > index ca54a95..aaf9f09 100644 > --- a/tools/testing/selftests/vm/protection_keys.c > +++ b/tools/testing/selftests/vm/protection_keys.c > @@ -582,6 +582,9 @@ int alloc_pkey(void) > int sys_pkey_free(unsigned long pkey) > { > int ret = syscall(SYS_pkey_free, pkey); > + > + if (!ret) > + shadow_pkey_reg &= reset_bits(pkey, PKEY_DISABLE_ACCESS); > dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); > return ret; > } Did this cause problems for you in practice? On x86, sys_pkey_free() does not affect PKRU, so this isn't quite right. I'd much rather have the actual tests explicitly clear the PKRU bits and also in the process clear the shadow bits. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com ([192.55.52.115]:50519 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbeCPWKQ (ORCPT ); Fri, 16 Mar 2018 18:10:16 -0400 Subject: Re: [PATCH v12 08/22] selftests/vm: clear the bits in shadow reg when a pkey is freed. References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> <1519264541-7621-9-git-send-email-linuxram@us.ibm.com> From: Dave Hansen Message-ID: Date: Fri, 16 Mar 2018 15:10:07 -0700 MIME-Version: 1.0 In-Reply-To: <1519264541-7621-9-git-send-email-linuxram@us.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Ram Pai , shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, arnd@arndb.de Message-ID: <20180316221007.IzTvSK1aK2btePTNNxt2e6O0oyqvoM1gFgvh4e-ktg8@z> On 02/21/2018 05:55 PM, Ram Pai wrote: > When a key is freed, the key is no more effective. > Clear the bits corresponding to the pkey in the shadow > register. Otherwise it will carry some spurious bits > which can trigger false-positive asserts. ... > diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c > index ca54a95..aaf9f09 100644 > --- a/tools/testing/selftests/vm/protection_keys.c > +++ b/tools/testing/selftests/vm/protection_keys.c > @@ -582,6 +582,9 @@ int alloc_pkey(void) > int sys_pkey_free(unsigned long pkey) > { > int ret = syscall(SYS_pkey_free, pkey); > + > + if (!ret) > + shadow_pkey_reg &= reset_bits(pkey, PKEY_DISABLE_ACCESS); > dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); > return ret; > } Did this cause problems for you in practice? On x86, sys_pkey_free() does not affect PKRU, so this isn't quite right. I'd much rather have the actual tests explicitly clear the PKRU bits and also in the process clear the shadow bits.