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

Re: [PATCH v2 5/8] x86/hvm: Context switch MSR_PKRS


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Thu, 12 Jan 2023 16:51:51 +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=GmFi/8tIrTuLpufoIdU6VzhCivSlsrwgl0zjfNXw22A=; b=NtkRN1Ch/LhFVf6ozWbaVMHDcV4J7M/Ll+prlUqPARlvw+Kbttpe7DZtaV3ZH1OuH2QDbiJ2H3jPoZHW96ZkP2ITpM28mVz0yuyOV4XpVQJM4678s2wp1dc3vMOhFliZCu/cslb0i3KZezAS2AaQbnLbwMS9eWO9PhMV5Rg6dAoIiuhxo6v/WY3K7flb0v2cdPz0iNMqetcR2MIm4BaIcmeeHpocJ7D+y8MBZLwboCzNVt9b+eIp7SIXxZ91QzORK/onkopQuY+C6Lj2ykmO8Shff5NfjO1EoAGp2sJVw7weTMqM5Mp1v3aHMybBx6ic8Iv1Mty1H5UBhmGicsHmOw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b6lknO3R0S0CPZRGRNpqBK9JXyCGZAgRgUtkr0N/98AQ6FwFOwT5dGwrSMmcFlmyvV3RBxIbtcqDIZhinNQfjsjxO5/XUI7hCA4f5IdS9A0arg3yfGkDg8phTYFG8PuGDa+b0gPJVXgTI5Hqcxz2Vokn1RDxJP3M1jpqhkxYu1is0V/V/IQ9HmoZWRYdkCnJO167I5P1angXOV62m0ZrHhsSweoiU5ERcrKAP6N0YUVQDf44ndG813AvOB1GxMB54osei5vL6gaBFoIfFtpMJa93XCbMe3c1xEXALQKHD1+N+gFUNwgn1hFrzD+Wrl/1QBx4MxcrNdyxt6ZCrD3syw==
  • 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>, Kevin Tian <kevin.tian@xxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 12 Jan 2023 16:52:17 +0000
  • Ironport-data: A9a23:x1udWqkMkoXWRaVTuYQDV4ro5gy5J0RdPkR7XQ2eYbSJt1+Wr1Gzt xIeWmDUaKqOZWH0fNh3at++/U1Vv5DUn9Y1Twc5qyk9FSMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icf3grHmeIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7auaVA8w5ARkPqgS5QWGzRH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 c5fEStRMDysvvLsypSbafFI2fwTfda+aevzulk4pd3YJdAPZMmaBo/stZpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVw3iea8WDbWUoXiqcF9t0CUv G/ZuU/+BQkXLoe3wjuZ6HO8wOTImEsXXapDTuboqKI00TV/wEQCJTQzcgfj4sKgg1+/WfxzM mE1wgwh+P1aGEuDC4OVsweDiHyOswMYWtFQO/Yn8wzLwa3Riy6GAkAUQzgHb8Yp3Oc1SCIr0 BmVntrvLT1prLCRD3ma89+8vT60fCQYM2IGTSsFVhcepcnuppkpiRDCRcolF7S65uAZAhn1y jGO6SI417MaiJdS073hpA6WxTWxupLOUwg5oB3NWX6o5R94Y4jjYJG07V/c7rBLK4PxokS9g UXoUvO2tIgmZaxhXgTXKAnRNNlFP8q4DQA=
  • Ironport-hdrordr: A9a23:BN6EqqNXqzyzT8BcTgWjsMiBIKoaSvp037BK7S1MoH1uA6mlfq WV9sjzuiWatN98Yh8dcLO7Scu9qBHnlaKdiLN5VduftWHd01dAR7sSjrcKrQeAJ8X/nNQtr5 uJccJFeaDN5Y4Rt7eH3OG6eexQv+Vu6MqT9IPjJ+8Gd3ATV0lnhT0JbTqzIwlNayRtI4E2L5 aY7tovnUvaRZxGBv7LYEXsRoL41qT2qK4=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZJRefeExwWeppzE65VXS63DgRAq6axG6AgAA9twA=
  • Thread-topic: [PATCH v2 5/8] x86/hvm: Context switch MSR_PKRS

On 12/01/2023 1:10 pm, Jan Beulich wrote:
> On 10.01.2023 18:18, Andrew Cooper wrote:
>> +static inline void wrpkrs(uint32_t pkrs)
>> +{
>> +    uint32_t *this_pkrs = &this_cpu(pkrs);
>> +
>> +    if ( *this_pkrs != pkrs )
>> +    {
>> +        *this_pkrs = pkrs;
>> +
>> +        wrmsr_ns(MSR_PKRS, pkrs, 0);
>> +    }
>> +}
>> +
>> +static inline void wrpkrs_and_cache(uint32_t pkrs)
>> +{
>> +    this_cpu(pkrs) = pkrs;
>> +    wrmsr_ns(MSR_PKRS, pkrs, 0);
>> +}
> Just to confirm - there's no anticipation of uses of this in async
> contexts, i.e. there's no concern about the ordering of cache vs hardware
> writes?

No.  The only thing modifying MSR_PKRS does is change how the pagewalk
works for the current thread (specifically, the determination of Access
Rights).  Their is no relevance outside of the core, especially for
Xen's local copy of the register value.

What WRMSRNS does guarantee is that older instructions will complete
before the MSR gets updated, and that subsequent instructions won't
start, so WRMSRNS acts "atomically" with respect to instruction order.

Also remember that not all WRMSRs are serialising.  e.g. the X2APIC MSRs
are explicitly not, and this is an oversight in practice for
MSR_X2APIC_ICR at least.

>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -54,6 +54,7 @@
>>  #include <asm/spec_ctrl.h>
>>  #include <asm/guest.h>
>>  #include <asm/microcode.h>
>> +#include <asm/prot-key.h>
>>  #include <asm/pv/domain.h>
>>  
>>  /* opt_nosmp: If true, secondary processors are ignored. */
>> @@ -1804,6 +1805,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>      if ( opt_invpcid && cpu_has_invpcid )
>>          use_invpcid = true;
>>  
>> +    if ( cpu_has_pks )
>> +        wrpkrs_and_cache(0); /* Must be before setting CR4.PKS */
> Same question here as for PKRU wrt the BSP during S3 resume.

I had reasoned not, but it turns out that I'm wrong.

It's important to reset the cache back to 0 here.  (Handling PKRU is
different - I'll follow up on the other email..)

~Andrew

 


Rackspace

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