Skip to contentSkip to conversation

target/i386: add missing bits to CR4_RESERVED_MASK

PATCH In review Daniel P. Berrangé 3 participants 3 messages Aug 31, 2021 – Sep 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: add missing bits to CR4_RESERVED_MASK

Booting Fedora kernels with -cpu max hangs very early in boot. Disabling the la57 CPUID bit fixes the problem. git bisect traced the regression to

commit 213ff024a2f92020290296cb9dc29c2af3d4a221 (HEAD, refs/bisect/bad)
Author: Lara Lazier <[email protected]>
Date: Wed Jul 21 17:26:50 2021 +0200

target/i386: Added consistency checks for CR4

All MBZ bits in CR4 must be zero. (APM2 15.5) Added reserved bitmask and added checks in both helper_vmrun and helper_write_crN.

Message-Id: <[email protected]>

In this commit CR4_RESERVED_MASK is missing CR4_LA57_MASK and two others. Adding this lets Fedora kernels boot once again.

---
 target/i386/cpu.h | 1 +
 1 file changed, 1 insertion(+)

I don't know the implications of CR4_VMXE_MASK and CR4_SMXE_MASK being missing in CR4_RESERVED_MASK. It didn't cause any ill effects either way, but I added them on the assumption that CR4_RESERVED_MASK was supposed to contain all define bits.

target/i386/cpu.h +1 -0
index 6c50d3ab4f..ce85f1a29d 100644
@@ -257,6 +257,7 @@ typedef enum X86Seg {
                 | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \
                 | CR4_MCE_MASK | CR4_PGE_MASK | CR4_PCE_MASK \
                 | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK |CR4_UMIP_MASK \
+                | CR4_LA57_MASK | CR4_VMXE_MASK | CR4_SMXE_MASK \
                 | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \
                 | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_MASK))
 
Signature · 1 line
2.31.1
Tested-by on v1 1/1
#1 lore raw
Quoted 35 lines · Daniel P. Berrangé

Booting Fedora kernels with -cpu max hangs very early in boot. Disabling the la57 CPUID bit fixes the problem. git bisect traced the regression to

commit 213ff024a2f92020290296cb9dc29c2af3d4a221 (HEAD, refs/bisect/bad)
Author: Lara Lazier <[email protected]>
Date: Wed Jul 21 17:26:50 2021 +0200

target/i386: Added consistency checks for CR4

All MBZ bits in CR4 must be zero. (APM2 15.5) Added reserved bitmask and added checks in both helper_vmrun and helper_write_crN.

Message-Id: <[email protected]>

In this commit CR4_RESERVED_MASK is missing CR4_LA57_MASK and two others. Adding this lets Fedora kernels boot once again.

---
 target/i386/cpu.h | 1 +
 1 file changed, 1 insertion(+)

I don't know the implications of CR4_VMXE_MASK and CR4_SMXE_MASK being missing in CR4_RESERVED_MASK. It didn't cause any ill effects either way, but I added them on the assumption that CR4_RESERVED_MASK was supposed to contain all define bits.

target/i386/cpu.h +0 -0
index 6c50d3ab4f..ce85f1a29d 100644

target/i386/cpu.h typedef enum X86Seg { · line 262

Quoted 6 lines
target/i386/cpu.h +1 -0
@@ -257,6 +257,7 @@ typedef enum X86Seg {
                 | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \
                 | CR4_MCE_MASK | CR4_PGE_MASK | CR4_PCE_MASK \
                 | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK |CR4_UMIP_MASK \
+                | CR4_LA57_MASK | CR4_VMXE_MASK | CR4_SMXE_MASK \
                 | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \
                 | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_MASK))

First thing to say is I tested this locally and it fixes the problem seen in https://bugzilla.redhat.com/show_bug.cgi?id=1999700.
I will also add this patch to Fedora soon. So:

But my question is, does this mean that every time a new CPU feature appears we must remember to update this code?

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
#2 lore raw
Quoted 15 lines · Richard W.M. Jones

target/i386/cpu.h typedef enum X86Seg { · line 262

Quoted 11 lines
target/i386/cpu.h +1 -0
index 6c50d3ab4f..ce85f1a29d 100644
@@ -257,6 +257,7 @@ typedef enum X86Seg {
                  | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \
                  | CR4_MCE_MASK | CR4_PGE_MASK | CR4_PCE_MASK \
                  | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK |CR4_UMIP_MASK \
+                | CR4_LA57_MASK | CR4_VMXE_MASK | CR4_SMXE_MASK \
                  | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \
                  | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_MASK))

First thing to say is I tested this locally and it fixes the problem seen inhttps://bugzilla.redhat.com/show_bug.cgi?id=1999700. I will also add this patch to Fedora soon. So:

Quoted 4 lines

But my question is, does this mean that every time a new CPU feature appears we must remember to update this code?

This is used only by TCG, which explains why VMXE/SMXE were not there; however, LA57 is missing indeed.

New features must be included both here and in cr4_reserved_bits, but only if TCG supports them, otherwise they can be left out. Since VMXE/SMXE are not supported by TCG, they should be either added both here and in cr4_reserved_bits (keyed on env->features[FEAT_1_ECX] & CPUID_EXT_{VMX,SMX} respectively), or they should not be added to CR4_RESERVED_MASK either. On the other hand LA57 is already handled by cr4_reserved_bits, so it is okay to just add it here.

Thanks,

Paolo