public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] x86/cpu: fix invalid MTRR mask values for SEV or TME
@ 2024-01-31 23:09 Paolo Bonzini
  2024-01-31 23:09 ` [PATCH v2 1/2] x86/cpu: allow reducing x86_phys_bits during early_identify_cpu() Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Paolo Bonzini @ 2024-01-31 23:09 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Zixi Chen, Adam Dunlap, Kirill A . Shutemov, Xiaoyao Li,
	Kai Huang, Dave Hansen, Thomas Gleixner, Ingo Molnar, x86, stable

Supersedes: <20240130180400.1698136-1-pbonzini@redhat.com>

MKTME repurposes the high bit of physical address to key id for encryption
key and, even though MAXPHYADDR in CPUID[0x80000008] remains the same,
the valid bits in the MTRR mask register are based on the reduced number
of physical address bits.  This breaks boot on machines that have TME enabled
and do something to cleanup MTRRs, unless "disable_mtrr_cleanup" is
passed on the command line.  The fix is to move the check to early CPU
initialization, which runs before Linux sets up MTRRs.

However, as noticed by Kirill, the patch I sent as v1 actually works only
until Linux 6.6.  In Linux 6.7, commit fbf6449f84bf ("x86/sev-es: Set
x86_virt_bits to the correct value straight away, instead of a two-phase
approach") reorganized the initialization of c->x86_phys_bits in a way
that broke the patch.  But even in 6.7 AMD processors, which did try to
reduce it in this_cpu->c_early_init(c), had their x86_phys_bits value
overwritten by get_cpu_address_sizes(), so that early_identify_cpu()
left the wrong value in x86_phys_bits.  This probably went unnoticed
because on AMD processors you need not apply the reduced MAXPHYADDR to
MTRR masks.

Therefore, this v2 prepends the fix for this issue in commit fbf6449f84bf.
Apologies for the oversight.

Tested on an AMD Epyc machine (where I resorted to dumping mtrr_state) and
on the problematic Intel Emerald Rapids machine.

Thanks,

Paolo

Paolo Bonzini (2):
  x86/cpu: allow reducing x86_phys_bits during early_identify_cpu()
  x86/cpu/intel: Detect TME keyid bits before setting MTRR mask
    registers

 arch/x86/kernel/cpu/common.c |   4 +-
 arch/x86/kernel/cpu/intel.c  | 178 ++++++++++++++++++-----------------
 2 files changed, 93 insertions(+), 89 deletions(-)

-- 
2.43.0


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

end of thread, other threads:[~2024-02-28  0:08 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 23:09 [PATCH v2 0/2] x86/cpu: fix invalid MTRR mask values for SEV or TME Paolo Bonzini
2024-01-31 23:09 ` [PATCH v2 1/2] x86/cpu: allow reducing x86_phys_bits during early_identify_cpu() Paolo Bonzini
2024-02-01  8:33   ` Kirill A . Shutemov
2024-02-01 15:44   ` Huang, Kai
2024-01-31 23:09 ` [PATCH v2 2/2] x86/cpu/intel: Detect TME keyid bits before setting MTRR mask registers Paolo Bonzini
2024-02-01  8:34   ` Kirill A . Shutemov
2024-02-01 15:42   ` Huang, Kai
2024-02-01 18:29 ` [PATCH v2 0/2] x86/cpu: fix invalid MTRR mask values for SEV or TME Dave Hansen
2024-02-01 21:42   ` Dave Hansen
2024-02-01 23:08   ` Paolo Bonzini
2024-02-04 17:21     ` Paolo Bonzini
2024-02-13 15:45       ` Paolo Bonzini
2024-02-13 22:02         ` Dave Hansen
2024-02-13 22:25           ` Paolo Bonzini
2024-02-20 12:22           ` Paolo Bonzini
2024-02-22 18:06             ` Dave Hansen
2024-02-22 18:08               ` Paolo Bonzini
2024-02-26  1:57                 ` Yin Fengwei
2024-02-26 16:21                   ` Dave Hansen
2024-02-27  2:02                     ` Yin Fengwei
2024-02-27  6:08                     ` Yin Fengwei
2024-02-27 13:30                       ` Dave Hansen
2024-02-28  0:07                         ` Yin Fengwei
2024-02-13 17:07     ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox