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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 13 Sep 2023 16:52:20 +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=jJW6Iw8KHl2ZFwdrOSWrwQahsI9S6yNabUtrApUZrTU=; b=c8Oq0Rz604WRlP1bLY4x201ZiGYolDtQb2EUvoCFqs70EJs3KOX8bLW8WXjMgdB4uRe5E3OjPB9HHUEinz1Tlp+lrPW5LMyN/91OlGcoUZmYvlgTI69CvWhvxbZW2ycrxqAQW8SGGP6IBlxPx7twUXaAgUDb9EHUg4qHXimUlvxAatmOZ7672QRmxpvVSCBy4Fr72pjmBGhwYoSacY34m1/Wq53ezKtdOW5q7FDZh+VNoajBGKKn0w+zBWwLVf2O0InQ36cF0z/6oHT54hJNrdOZnYmpDZ+2D/TGa3Bm8QeTt6IBQXxE/8sfIQu/JotA6AC1PJQp3h/2M27WSWFcLQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MklpIv5QZ/QbedSQSyUfhOb7fb/l+vDF8ROilczyfP7wh85RB+4LA19bk8XVC0DTXke5DdoQ1NWPbSUDeN0HMbhQwv3pvmNPdu/RS0DqGrVIgGMCldR6hNLKo9B7mx4cs1HQkjEflZ5Q+3zRmdQhcCDWGrfinbDEJRqqfGW2YRvNjx5WI4Kz9mFMh6rXh4u4tzOcBnvh9xUvHM6V7txPR+uO8OdACqRmfvQU+LzAF7P+vL6kyQ1jEEWogTVjbzwgB7MZfyzFkaadCqW2I+t8VgdqqpGn0XoieZzC6nGdJswrgxmkaXbC5nlGtOYU3OegbAgZfFKXfCkCKk0oFSm6MA==
  • 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>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Solène Rapenne <solene@xxxxxxxxxxx>
  • Delivery-date: Wed, 13 Sep 2023 14:53:01 +0000
  • Ironport-data: A9a23:DZ5Y961v8wo29yRglfbD5eFwkn2cJEfYwER7XKvMYLTBsI5bpzZTm mUWCDuDb/2JNjSkft4gOYW0o0kPup+Bz95jHVRspC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliOfQAOK6UbaYUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8teTb8nuDgNyo4GlD5g1nPqgR1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfD2ZUr dYgcxw0Zy+yiOmy7bCCc/B0mZF2RCXrFNt3VnBI6xj8VK9ja7aTBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxqsy6KklwZPLvFabI5fvSQQspYhACAr 3/u9GXlGBAKcteYzFJp91r13LWUzX2nBtN6+LuQ2aExrQeay34qE0M6V0OwiKGYsg2HYocKQ 6AT0m90xUQoz2S7Q9+4UxCmrXqsuh8HR8EWA+A88BuKyKff/0CeHGdsZjxLZcEitcQ2bSc3z VLPlNTsbRRwtJWFRHTb8a2bxRupPiwYK2IqYjcJSwEe75/kuo5bs/7UZtNqEarwhNulHzj1m mmOtHJn2eVVitMX3aKm+1yBmyirupXCUg8y4EPQQ36h6QR6IoWiYuRE9GTm0BqJF67BJnHpg ZTOs5L2ADwmZX1VqBGwfQ==
  • Ironport-hdrordr: A9a23:3tzwU6tVvXKeoa+OOqI5q3Kh7skD29V00zEX/kB9WHVpmwKj9v xG+85rsyMc6QxhP03I/OrrBEDuex7hHPJOjbX5eI3SPzUPVgOTXf1fBMjZskDd8xSXzJ8j6U 4YSdkBNDSTNzhHZLfBkW2F+o0bsaC6GcmT7I+0854ud3AJV0gH1WhE422gYyhLrWd9a6bRPa Dsl/Zvln6PeWk3cs/+PXUMRe7Fzue77q7OUFopBwMH9ALLtj+j6Kf7Hx+Ety1uKA9n8PMN8X Xljwe83amos+i6xhjAk0ff4o9bgsGJ8KoxOOW8zuYUNxTxgUKTaINtV6bqhkFMnMij5Ew2kN 7FvhcnON4b0QKgQl2I
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxxxxx>
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@xxxxxxxxxx>
---
 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




 


Rackspace

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