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

Re: [PATCH] x86/PAT: have pat_enabled() properly reflect state when running on e.g. Xen


  • To: Borislav Petkov <bp@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 6 Jul 2022 08:17:41 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=4/FaPivtjBKo/5QIQwt/UgWd4q1clpHngbxHENytT/I=; b=nv0LtVCwTEVUg2+YlWUsKy4pC88jdBd+9LsbVe2XRF4hwJ8/3y4jqvCX3A5wyqLZvJQ1HmDY4uiAatVPwD/Hw5El/+n4g5ldvABZ2mS5OKkNSsz7wiNGNdKyDChwvZvt94prfb7ycFPKdWBEde4RU753eDDeV1L0VwzsFn6laSeB4gTLUwqx4Fy/xQeedEVPHjTVjhrOnsYR5d7UVhpSP9zh4wGX3/aRIe3mx9KC1B20+hBT0TvbtQVcDXSxGA5MqOnP/Osgrvn2lnnqfSqHwk08/K3fnZcqIQTVQg29qElJxqRJ2iLz1dJgrZTUQp3uQCshSG4J6UXmL97hjtqeig==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fck9NlABHzM6lT7nv/wTqRHrOmJKV1J19XQ6ugs1EEA62cf6pIt2Rxw0UkeO17IXDbLGM6grZjh9snAxoWnELxXQasLBUad2umj0JFG7EMRknz1fEyAKg+fkuL6q4qdgz8bWvvbUDeKS8uhGVAAtOjS+JzwwgTEv9uboGn1+usrMyNDMGH6HPpxURRvu+AMXM1VY4IR7xqypFl2yLl/eitdrL4w9XrSo8i5P+3q5NlsX5yqvxul39iWmsOYUpwC58NQZcDj7GL0PsF1nH6N3/sv5qKHLpqCVICpLNvb+rDNmv4u8APZNTMyq2aG0OpQIzjtnaaYnZXvEk8EuO6nI7A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Lutomirski <luto@xxxxxxxxxx>, "dave.hansen@xxxxxxxxxxxxxxx" <dave.hansen@xxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, lkml <linux-kernel@xxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 06 Jul 2022 06:17:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.07.2022 18:14, Borislav Petkov wrote:
> On Tue, Jul 05, 2022 at 05:56:36PM +0200, Jan Beulich wrote:
>> Re-using pat_disabled like you do in your suggestion below won't
>> work, because mtrr_bp_init() calls pat_disable() when MTRRs
>> appear to be disabled (from the kernel's view). The goal is to
>> honor "nopat" without honoring any other calls to pat_disable().
> 
> Actually, the current goal is to adjust Xen dom0 because:
> 
> 1. it uses the PAT code
> 
> 2. but then it does something special and hides the MTRRs
> 
> which is not something real hardware does.
> 
> So this one-off thing should be prominent, visible and not get in the
> way.
> 
> As to mtrr_bp_init(), can you use X86_FEATURE_XENPV there to detect this
> special case when the kernel is running as dom0 and set stuff there
> accordingly so that it doesn't disable PAT?

Sure, but that alone won't help. There's a beneficial side effect
of running through pat_disable(): That way pat_init() will bail
right away. Without that I'd need to further special case things
there (as under Xen/PV PAT must not be written, only read) and I'd
also need to set pat_bp_enabled and pat_bp_initialized somewhere.
I could of course check X86_FEATURE_XENPV in all the necessary
places, but I was quite certain _that_ wouldn't be liked (nor
would I be convinced this is the right thing to do - see bottom).

> Then you don't have to touch pat_disabled() either but intergrate the
> Xen variant properly...
> 
>> I can probably fiddle with pat_enabled() instead of with
>> init_cache_modes(), but when making the change I had the feeling
>> this might be less liked (as looking more hacky, at least to me).
> 
> Why would that be more hacky?

My view on it, as said. I did actually make several attempts, until
reaching what I then submitted. All earlier ones were quite a bit
more intrusive (see above for an outline).

> I'd much rather check upfront what the kernel is running on and act
> accordingly instead of hooking into random functions and then years
> later wonder why was it done in the first place.

Thank you for putting it that kindly. It was a pretty conscious
decision where to make the changes, after - as said - quite a bit
of trying other variants. History with Xen-specific changes has
taught me to try to keep them as uninvasive and generic as possible.
The more things smelled like Xen-only, the less they were liked.

>> But besides the "where" the other question is: Do you really want
>> me to limit this to Xen/PV, rather than - as I have it now -
>> extending it to any hypervisor, which may behave in similar ways?
> 
> Well, do you know of some other HV which hides MTRRs from the guest?
> 
> I haven't heard of any...

Any decent hypervisor will allow overriding CPUID, so in principle
I'd expect any to permit disabling MTRR to leave a guest to use
the (more modern and less cumbersome) PAT alone.

Jan



 


Rackspace

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