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

Re: [PATCH] x86/amd: do not expose HWCR.TscFreqSel to guests


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 13 Sep 2023 10:08:27 +0200
  • 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=juF3907G/TaZ8fxiP6f9qUJxjfaM8WA4dQTpVRAIDzE=; b=VzX7IiY9D9YENpXsEXVk/dlfRe/w0Rwm6MqFzz94LFHXx8zl2EPiRuGF8LLviNcUSIY4RpAPVyeIS8y9H9owj+zY4jsf61dXh1LipKKYWcFLgYGLHU44JggnrTavNWEnxoZ6LXWpo7V4K1vkQk4cVhiU0NQiVzWpKhoxas1ucuclQubkjsuD9ZhYYyrFTJhyPXdX0DWMsk56wEEUjM/wBl8QZhevjUZD0e9Y9PHxwmqL2DHtK4sBXOb2Ml0JWGRpB2Lgl9kJqD6vyFg5sdxFrK5UZLOIWfSCKvBiQo1F7CUDR5wvNBplG6cBtDw9KIJFDd/8mnMntL2EoQXYcFgTgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gdwVW7EueMXyUCcik0eZLyrkyb+qsABC4L6aZ/Z14bgKgP0JTR0oRsLXhroCWYv9j7ewPnzDCDHF28oNxMQ+lcpA8C7uymfNdbJLpHTRFxDT/iqSRHW7W8X0ujnX8j4Q7FcxJdSUNElhxpUoEKoDWSvGH2dCUSz6QMozEjR31i+vpb1aDdIk7/uFFvRncG45ZhNlsr//3qmTPixMk65KqBPu8EQ2gXMEPi/IFuQcbagbHrOWjqrQs/aElP5PFCJ36Sm74fe69ErdJDqcA9klJVhJy9imGzjtohg+ixFw2MBe4P8yUagr/Ig/GNApeFHalkLMpwfPBt8JzixEj7y/7Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>, solene@xxxxxxxxxxx, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 13 Sep 2023 08:08:45 +0000
  • Ironport-data: A9a23:IsMt+KNcgiZreObvrR1VlsFynXyQoLVcMsEvi/4bfWQNrUp01zcHn GUdCDjQO/uLZTGhKNwgO4+3/E4HusTQnNQ1TAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CQ6jefQAOOkVIYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/jrRC9H5qyo42tJ5wdmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0v1nLDluq cM9EwI2bBachuCJ0JSbSsA506zPLOGzVG8ekldJ6GiBSNMZG9XESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PdxujCDpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+tqyj23bOUzH2hMG4UPKXhzf5nrhqs/UBQWD44FlK/gKTk0WfrDrqzL GRRoELCt5Ma5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAGRDNcbN0ttOctWCcnk FSOmrvBGjhHoLCTD3WH+d+8tjS2NC4YBWgaaCkOVgdD5MPsyKk2hwjKR8xuE4a0iMP0AjD6x z2WrCk4iK4XhMRN3KK+lXjLjjetjpnPUA8u5w/TU36l7wV2f4qsbcqj7l2z0BpbBIOQT13Eu WdencGbtbgKFcvUzHzLR/gRFra04frDKCfbnVNkA5gm8XKq5mKneodTpjp5IS+FL/o5RNMgW 2eL0Ss52XOZFCLCgXNfC25pN/kX8A==
  • Ironport-hdrordr: A9a23:2eG/HquOCXbhGeYc1+sKVyq07skDe9V00zEX/kB9WHVpm6uj5q WTdZUgpH3JYVMqMxsdcL+7VZVoPkmskaKdjbN8AV7BZmjbURqTXeJfBOLZqlXd8kvFmdK1vp 0BT0ERMrPN5FFB/KHH3DU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Sep 12, 2023 at 05:36:53PM +0100, Andrew Cooper wrote:
> On 12/09/2023 5:35 pm, Andrew Cooper wrote:
> > On 12/09/2023 5:23 pm, Roger Pau Monne wrote:
> >> OpenBSD will attempt to unconditionally access PSTATE0 if HWCR.TscFreqSel 
> >> is
> >> set, and will also attempt to unconditionally access HWCR if the TSC is
> >> reported as Invariant.
> >>
> >> The reasoning for exposing HWCR.TscFreqSel was to avoid Linux from 
> >> printing a
> >> (bogus) warning message, but doing so at the cost of OpenBSD not booting 
> >> is not
> >> a suitable solution.
> >>
> >> In order to fix expose an empty HWCR.
> > At first I was thinking a straight up revert, but AMD's CPUID Faulting
> > is an architectural bit in here so it's worth keeping the register around.
> >
> >> Fixes: 14b95b3b8546 ('x86/AMD: expose HWCR.TscFreqSel to guests')
> >> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> >> ---
> >> Not sure whether we want to expose something when is_cpufreq_controller() 
> >> is
> >> true, seeing as there's a special wrmsr handler for the same MSR in that 
> >> case.
> >> Likely should be done for PV only, but also likely quite bogus.
> >>
> >> Missing reported by as the issue came from the QubesOS tracker.
> > Well - we can at least have a:
> >
> > Link: https://github.com/QubesOS/qubes-issues/issues/8502
> >
> > in the commit message, and it's probably worth asking Solène / Marek
> > (both CC'd) if they want a Reported-by tag.
> >
> >> ---
> >>  xen/arch/x86/msr.c | 8 ++++++--
> >>  1 file changed, 6 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
> >> index 3f0450259cdf..964d500ff8a1 100644
> >> --- a/xen/arch/x86/msr.c
> >> +++ b/xen/arch/x86/msr.c
> >> @@ -240,8 +240,12 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, 
> >> uint64_t *val)
> >>      case MSR_K8_HWCR:
> >>          if ( !(cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
> >>              goto gp_fault;
> >> -        *val = get_cpu_family(cp->basic.raw_fms, NULL, NULL) >= 0x10
> >> -               ? K8_HWCR_TSC_FREQ_SEL : 0;
> >> +        /*
> >> +         * OpenBSD 7.3 accesses HWCR unconditionally if the TSC is 
> >> reported as
> >> +         * Invariant.  Do not set TSC_FREQ_SEL as that would trigger 
> >> OpenBSD to
> >> +         * also poke at PSTATE0.
> >> +         */
> > While this is true, the justification for removing this is because
> > TSC_FREQ_SEL is a model specific bit, not an architectural bit in HWCR.
> >
> > Also because it's addition without writing into the migration stream was
> > bogus irrespective of the specifics of the bit.
> >
> > I'm still of the opinion that it's buggy for OpenBSD to be looking at
> > model specific bits when virtualised, but given my latest reading of the
> > AMD manuals, I think OpenBSD *is* well behaved looking at PSTATE0 if it
> > can see TSC_FREQ_SEL.
> >
> > In some theoretical future where the toolstack better understands MSRs
> > and (non)migratable VMs (which is the QubesOS usecase), then it would in
> > principle be fine to construct a VM which can see the host TSC_FREQ_SEL
> > and PSTATE* values.
> >
> > Preferably with an adjusted comment, Reviewed-by: Andrew Cooper
> > <andrew.cooper3@xxxxxxxxxx>
> 
> Sorry - I meant to be clearer here.  I'd suggest just deleting the
> comment and leaving an unconditional return of 0 (which will become
> conditional when we wire up CPUID Faulting).
> 
> MSR_HWCR *is* an architectural MSR on any 64bit AMD system, so shouldn't
> fault.

Hm, I think it's worth to at least keep a note that if TSC_FREQ_SEL is
exposed PSTATE0 must also be exposed to prevent OpenBSD 7.3 from
panicking.

Thanks, Roger.



 


Rackspace

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