[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/6] x86/prot-key: Split PKRU infrastructure out of asm/processor.h


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Mon, 9 Jan 2023 14:57:41 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=S/j8qZxd5fo4q8BxZa+uetjPoTsTEamnOrI9iHm6nnQ=; b=hhIA679/9WQdXy3t0NRzNPefOX41VjmU/4EN+C6+vU0nQm7Aw1+Vn8R/g7OtvfqWoI7/Rf5gPj5Joe1F3+BDoGTV6hks3gk3cLVX/dF8e363vTM0TbFZf/JcZdbmUXtPMIoPlJWkEkvx+SKe8MlY988573G4WrwBM8kWkLXmE8CjyeftKOO0UJMzuxMwmCIHwjSKsmsoK0LdNu4z+qNsW7CLk99VV9swZnbmy92Ry+sEc2QTlNM87mvQjZj6jIIiZTi6hsgME4HVkyArl8UMnBqvL9LyB5m4uI03HFLi9hEKaLyuFmbkL27o3qJLsiLC7rC/fh3FEs69ueL+KYVWoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gasRM56Dn463+ByYL/Vj063gtgAzJpLOiWJoN0xc46gh4vrXbzp9TlEdeODii+IfeKg9jx/oDYQzCNtfUdujH1Z06LzwAMnMJIdFQnZynWbrTOQWm4s3Wy+77gA7ljObke85SN9uhIOIr9qO7W1PH0Jpa/51P2ntygVKHYFPTF5RXHtkYAA/iVKVedqfSjg62NuktuXZDZx/k5/oKOs5bvTu7zY19v7iX8cm02yGCHH43OowsOEEEgWnWuoFhJWZtyxWMAgy+UWgObH/HkVSXieTg6r6u1sjKTco4PKR1GjL1oXpisGMdd1AQyqiUfhMhsbL3Kw8ExeegvwymCwsrQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 09 Jan 2023 14:58:02 +0000
  • Ironport-data: A9a23:NQwJ/6zk0Rh5+842AX96t+cVxyrEfRIJ4+MujC+fZmUNrF6WrkUAz 2QdCG/Vb/mMZ2HxfN4nOtiwpxxVsJfXnIVkSQc5+SAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTbaeYUidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw//F+U0HUMja4mtC5QRnPaET5zcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KUJ/2 tYgLgEjVCGaxKGTyYvjeONchP12eaEHPKtH0p1h5RfwKK98BLzmHeDN79Ie2yosjMdTG/qYf 9AedTdkcBXHZVtIJ0sTD5U92uyvgxETcRUB8A7T+fVxvjmVlVMpuFTuGIO9ltiibMNZhEuH4 EnB+Hz0GEoyP92D0zuVtHmrg4cjmAuqAdJKSufpqpaGhnWi1HMCCEAsD2G9/6bk1UGCacllC BILr39GQa8asRbDosPGdx+yrWOAvxUcc8FNCOB84waIooLL5y6JC25CSSROAPQ2uclzSTE02 1uhm9LyGScpoLCTUWia9LqfsXW1Iyd9EIMZTSoNTA9A79y9pog210jLVow6T/bzicDpEzbtx TzMtDI5m7gYkc8M0eO84EzDhDWv4JPOS2bZ+znqY45s1SshDKbNWmBiwQKzASpoRGpBcmS8g Q==
  • Ironport-hdrordr: A9a23:KROsfaioaJy/LUz2+WpEwtMK8XBQX6F13DAbv31ZSRFFG/FwWf re+MjztCWE/Ar5PUtK9+xoV5PhfZqiz+8L3WB8B9aftWrdyRmVxf9ZnOnfKlTbckWVygc379 YCT0ERMqyUMbBw5fyKnjVRe7wbrOVum8qT6ts3AB1WID1CWuVYy0NcNy7eK0txQWB9dO8E/F j33Ls3m9JlE05nHfhSwxM+Lpj+Tqbw5fXbSC9DPQcj9A6NyRuw8dfBYmCl9yZbaSpL3bAhtU PYkwn1j5/Tz82T+1vnzmrO6JYTv9PkxrJ4daqxo/lQECzolgGrIKJ+XLGY1QpF2d2H2RIRid zRpBVlBeRfgkmhBV2dkF/Wwgz91zRr0XP41lOCpnPmraXCNUgHIvsEv5tdbhzar3Utp8t91q Uj5RPli6Zq
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHX8mMDkacqheDKokOTUkSgUg9d2qw81wgAglu5ogA=
  • Thread-topic: [PATCH 2/6] x86/prot-key: Split PKRU infrastructure out of asm/processor.h

On 21/12/2021 11:28 am, Jan Beulich wrote:
> On 16.12.2021 10:54, Andrew Cooper wrote:
>> --- /dev/null
>> +++ b/xen/arch/x86/include/asm/prot-key.h
>> @@ -0,0 +1,45 @@
>> +/******************************************************************************
>> + * arch/x86/include/asm/spec_ctrl.h
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; If not, see <http://www.gnu.org/licenses/>.
>> + *
>> + * Copyright (c) 2021 Citrix Systems Ltd.
>> + */
>> +#ifndef ASM_PROT_KEY_H
>> +#define ASM_PROT_KEY_H
>> +
>> +#include <xen/types.h>
>> +
>> +#define PKEY_AD 1 /* Access Disable */
>> +#define PKEY_WD 2 /* Write Disable */
>> +
>> +#define PKEY_WIDTH 2 /* Two bits per protection key */
>> +
>> +static inline uint32_t rdpkru(void)
>> +{
>> +    uint32_t pkru;
> I agree this wants to be uint32_t (i.e. unlike the original function),
> but I don't see why the function's return type needs to be, the more
> that the sole caller also uses unsigned int for the variable to store
> the result in.

This is thinnest-possible wrapper around an instruction which
architecturally returns exactly 32 bits of data.

It is literally the example that CODING_STYLE uses to demonstrate when
fixed width types should be used.

>> --- a/xen/arch/x86/mm/guest_walk.c
>> +++ b/xen/arch/x86/mm/guest_walk.c
>> @@ -26,7 +26,9 @@
>>  #include <xen/paging.h>
>>  #include <xen/domain_page.h>
>>  #include <xen/sched.h>
>> +
>>  #include <asm/page.h>
>> +#include <asm/prot-key.h>
>>  #include <asm/guest_pt.h>
>>  #include <asm/hvm/emulate.h>
>>  
>> @@ -413,10 +415,11 @@ guest_walk_tables(const struct vcpu *v, struct 
>> p2m_domain *p2m,
>>           guest_pku_enabled(v) )
>>      {
>>          unsigned int pkey = guest_l1e_get_pkey(gw->l1e);
>> -        unsigned int pkru = rdpkru();
>> +        unsigned int pkr = rdpkru();
>> +        unsigned int pk_ar = pkr >> (pkey * PKEY_WIDTH);
> This is correct only because below you only inspect the low two bits.
> Since I don't think masking off the upper bits is really useful here,
> I'd like to suggest to not call the variable "pk_ar". Perhaps
> something as generic as "temp"?

This variable being named pk_ar (or thereabouts) is very important for
clarity below.

I've masked them - seems the compiler is clever enough to undo that even
at -O1.

~Andrew

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.