Skip to contentSkip to conversation

x86: kvm: Restrict X86_FEATURE_VMMCALL to x86_64 platform

PATCH In review Matthew Whitehead 3 participants 6 messages Jul 30, 2018 – Aug 1, 2018 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: kvm: Restrict X86_FEATURE_VMMCALL to x86_64 platform

early_init_amd() is called on all AMD processors, both 64 and 32 bit. Presently 32 bit processors get the X86_FEATURE_VMMCALL feature set, which they do not support. Add conditionals to restrict it to 64 bit processors.

---
 arch/x86/kernel/cpu/amd.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/amd.c +2 -0
index 38915fbfae73..df06919324cd 100644
@@ -662,12 +662,14 @@ static void early_init_amd(struct cpuinfo_x86 *c)
 	}
 #endif
 
+#ifdef CONFIG_X86_64
 	/*
 	 * This is only needed to tell the kernel whether to use VMCALL
 	 * and VMMCALL.  VMMCALL is never executed except under virt, so
 	 * we can set it unconditionally.
 	 */
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
+#endif
 
 	/* F16h erratum 793, CVE-2013-6885 */
 	if (c->x86 == 0x16 && c->x86_model <= 0xf)
Signature · 1 line
2.16.1
#1 lore raw
Quoted 3 lines · Matthew Whitehead

early_init_amd() is called on all AMD processors, both 64 and 32 bit. Presently 32 bit processors get the X86_FEATURE_VMMCALL feature set, which they do not support. Add conditionals to restrict it to 64 bit processors.

This shouldn't be necessary; for systems that don't have virtualization extensions, the comment explains why setting X86_FEATURE_VMMCALL is safe.

But it is also wrong, because you can run a 32-bit kernel as a guest on a 64-bit processor, and then it should set X86_FEATURE_VMMCALL because the processor has the vmmcall instruction and not Intel's vmcall.

Thanks,

Paolo

Quoted 26 lines
---
 arch/x86/kernel/cpu/amd.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/amd.c +2 -0
index 38915fbfae73..df06919324cd 100644
@@ -662,12 +662,14 @@ static void early_init_amd(struct cpuinfo_x86 *c)
 	}
 #endif
 
+#ifdef CONFIG_X86_64
 	/*
 	 * This is only needed to tell the kernel whether to use VMCALL
 	 * and VMMCALL.  VMMCALL is never executed except under virt, so
 	 * we can set it unconditionally.
 	 */
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
+#endif
 
 	/* F16h erratum 793, CVE-2013-6885 */
 	if (c->x86 == 0x16 && c->x86_model <= 0xf)
#2 lore raw
Quoted 8 lines

This shouldn't be necessary; for systems that don't have virtualization extensions, the comment explains why setting X86_FEATURE_VMMCALL is safe.

But it is also wrong, because you can run a 32-bit kernel as a guest on a 64-bit processor, and then it should set X86_FEATURE_VMMCALL because the processor has the vmmcall instruction and not Intel's vmcall.

Paolo,
I'm running this on a bare metal machine (no virtualization) with a
32-bit AMD i486 class cpu. Should the feature be showing up in /proc/cpuinfo under the 'flags' line? It does on my machine, and it looked wrong to me.

- Matthew

#3 lore raw
Quoted 9 lines · tedheadster
Quoted 8 lines

This shouldn't be necessary; for systems that don't have virtualization extensions, the comment explains why setting X86_FEATURE_VMMCALL is safe.

But it is also wrong, because you can run a 32-bit kernel as a guest on a 64-bit processor, and then it should set X86_FEATURE_VMMCALL because the processor has the vmmcall instruction and not Intel's vmcall.

Quoted 5 lines

Paolo,
I'm running this on a bare metal machine (no virtualization) with a
32-bit AMD i486 class cpu. Should the feature be showing up in /proc/cpuinfo under the 'flags' line? It does on my machine, and it looked wrong to me.

It's a bit silly, but it's not particularly wrong.

Paolo

#4 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · tedheadster
Quoted 8 lines

This shouldn't be necessary; for systems that don't have virtualization extensions, the comment explains why setting X86_FEATURE_VMMCALL is safe.

But it is also wrong, because you can run a 32-bit kernel as a guest on a 64-bit processor, and then it should set X86_FEATURE_VMMCALL because the processor has the vmmcall instruction and not Intel's vmcall.

Quoted 7 lines
Quoted 5 lines

Paolo,
I'm running this on a bare metal machine (no virtualization) with a
32-bit AMD i486 class cpu. Should the feature be showing up in /proc/cpuinfo under the 'flags' line? It does on my machine, and it looked wrong to me.

It's a bit silly, but it's not particularly wrong.

Why is there even a specific feature flag for VMMCALL? Isn't X86_FEATURE_SVM sufficient to differentiate which opcode to use?

--
Brian Gerst

#5 lore raw
Quoted 18 lines · Brian Gerst
Quoted 17 lines · Paolo Bonzini
Quoted 14 lines · tedheadster
Quoted 8 lines

This shouldn't be necessary; for systems that don't have virtualization extensions, the comment explains why setting X86_FEATURE_VMMCALL is safe.

But it is also wrong, because you can run a 32-bit kernel as a guest on a 64-bit processor, and then it should set X86_FEATURE_VMMCALL because the processor has the vmmcall instruction and not Intel's vmcall.

Paolo,
I'm running this on a bare metal machine (no virtualization) with a
32-bit AMD i486 class cpu. Should the feature be showing up in /proc/cpuinfo under the 'flags' line? It does on my machine, and it looked wrong to me.

Quoted 4 lines
Quoted 1 line

It's a bit silly, but it's not particularly wrong.

Why is there even a specific feature flag for VMMCALL? Isn't X86_FEATURE_SVM sufficient to differentiate which opcode to use?

No, X86_FEATURE_SVM is there in the host while X86_FEATURE_VMMCALL is used in the guest.

Paolo