All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/amd: do not expose HWCR.TscFreqSel to guests
@ 2023-09-13 14:52 Roger Pau Monne
  2023-09-14  5:52 ` Jan Beulich
  2023-09-14 12:53 ` Andrew Cooper
  0 siblings, 2 replies; 9+ messages in thread
From: Roger Pau Monne @ 2023-09-13 14:52 UTC (permalink / raw)
  To: xen-devel
  Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper, Wei Liu,
	Solène Rapenne

OpenBSD 7.3 will unconditionally access HWCR if the TSC is reported as
Invariant, and it will then attempt to also unconditionally access PSTATE0 if
HWCR.TscFreqSel is set (currently the case on Xen).

The relation between HWCR.TscFreqSel and PSTATE0 is not clearly written down in
the PPR, but it's natural for OSes to attempt to fetch the P0 frequency if the
TSC increments at the P0 frequency.

Exposing PSTATEn (PSTATE0 at least) with all zeroes is not a suitable solution
because the PstateEn bit is read-write, and OSes could legitimately attempt to
set PstateEn=1 which Xen couldn't handle.

In order to fix expose an empty HWCR, which is an architectural MSR and so must
be accessible.

Note it was not safe to expose the TscFreqSel bit because it is not
architectural, and could change meaning between models.

Reported-by: Solène Rapenne <solene@openbsd.org>
Link: https://github.com/QubesOS/qubes-issues/issues/8502
Fixes: 14b95b3b8546 ('x86/AMD: expose HWCR.TscFreqSel to guests')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 3f0450259cdf..c33dc78cd8f6 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -240,8 +240,7 @@ 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;
+        *val = 0;
         break;
 
     case MSR_VIRT_SPEC_CTRL:
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-14 14:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-13 14:52 [PATCH v2] x86/amd: do not expose HWCR.TscFreqSel to guests Roger Pau Monne
2023-09-14  5:52 ` Jan Beulich
2023-09-14 12:37   ` Roger Pau Monné
2023-09-14 12:49     ` Jan Beulich
2023-09-14 12:57       ` Roger Pau Monné
2023-09-14 13:16         ` Jan Beulich
2023-09-14 13:39           ` Roger Pau Monné
2023-09-14 14:17             ` Jan Beulich
2023-09-14 12:53 ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.