Skip to contentSkip to conversation

x86/VT-x: Fix determination of EFER.LMA in vmcs_dump_vcpu()

PATCH In review Andrew Cooper 4 participants 5 messages Apr 9, 2018 – Apr 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/VT-x: Fix determination of EFER.LMA in vmcs_dump_vcpu()

The LMA setting comes from the entry controls.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Juergen Gross <[email protected]>

This arguably wants backporting, so should go into 4.11 at this point. If not, I'll queue it in x86-next for the 4.12 dev window.

---
 xen/arch/x86/hvm/vmx/vmcs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmcs.c +4 -1
index 2c5ef36..70c2fb7 100644
@@ -1788,7 +1788,10 @@ void vmcs_dump_vcpu(struct vcpu *v)
     vmentry_ctl = vmr32(VM_ENTRY_CONTROLS),
     vmexit_ctl = vmr32(VM_EXIT_CONTROLS);
     cr4 = vmr(GUEST_CR4);
-    efer = vmr(GUEST_EFER);
+
+    /* EFER.LMA is read as zero, and is loaded from vmentry_ctl on entry. */
+    BUILD_BUG_ON(VM_ENTRY_IA32E_MODE << 1 != EFER_LMA);
+    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE) << 1);
 
     printk("*** Guest State ***\n");
     printk("CR0: actual=0x%016lx, shadow=0x%016lx, gh_mask=%016lx\n",
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw
In reply to Andrew Cooper

xen/arch/x86/hvm/vmx/vmcs.c void vmcs_dump_vcpu(struct vcpu *v) · line 1794

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 09.04.18 at 19:56, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +4 -1
@@ -1788,7 +1788,10 @@ void vmcs_dump_vcpu(struct vcpu *v)
     vmentry_ctl = vmr32(VM_ENTRY_CONTROLS),
     vmexit_ctl = vmr32(VM_EXIT_CONTROLS);
     cr4 = vmr(GUEST_CR4);
-    efer = vmr(GUEST_EFER);
+
+    /* EFER.LMA is read as zero, and is loaded from vmentry_ctl on entry. */
+    BUILD_BUG_ON(VM_ENTRY_IA32E_MODE << 1 != EFER_LMA);
+    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE) << 1);

I have to admit that - despite the BUILD_BUG_ON() - I dislike the literal 1 here, which would better be
(_EFER_LMA - _VM_ENTRY_IA32E_MODE), albeit the latter doesn't exist, so perhaps

    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE) * (EFER_LMA / VM_ENTRY_IA32E_MODE));

or the same expressed through MASK_EXTR() / MASK_INSR()? But it's the VMX maintainers to judge anyway.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#3 lore raw
Quoted 23 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 4:44 PM

xen/arch/x86/hvm/vmx/vmcs.c void vmcs_dump_vcpu(struct vcpu *v) · line 1792

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 09.04.18 at 19:56, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +2 -1
@@ -1788,7 +1788,10 @@ void vmcs_dump_vcpu(struct vcpu *v)
     vmentry_ctl = vmr32(VM_ENTRY_CONTROLS),
     vmexit_ctl = vmr32(VM_EXIT_CONTROLS);
     cr4 = vmr(GUEST_CR4);
-    efer = vmr(GUEST_EFER);
+
+    /* EFER.LMA is read as zero, and is loaded from vmentry_ctl on entry.

*/

xen/arch/x86/hvm/vmx/vmcs.c void vmcs_dump_vcpu(struct vcpu *v) · line 1794

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    BUILD_BUG_ON(VM_ENTRY_IA32E_MODE << 1 != EFER_LMA);
+    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE)

<< 1);

I have to admit that - despite the BUILD_BUG_ON() - I dislike the literal 1 here, which would better be
(_EFER_LMA - _VM_ENTRY_IA32E_MODE), albeit the latter doesn't exist, so perhaps

Quoted 6 lines
    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE) *

(EFER_LMA / VM_ENTRY_IA32E_MODE));

or the same expressed through MASK_EXTR() / MASK_INSR()? But it's the VMX maintainers to judge anyway.

using 1 is fine to me, with intention well explained with BUILD_BUG_ON. as long as BUILD_BUG_ON is still a valid usage, I'm OK with current one:

Thanks
kevin

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 26 lines · Kevin
Quoted 26 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 4:44 PM

xen/arch/x86/hvm/vmx/vmcs.c void vmcs_dump_vcpu(struct vcpu *v) · line 1792

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 09.04.18 at 19:56, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +2 -1
@@ -1788,7 +1788,10 @@ void vmcs_dump_vcpu(struct vcpu *v)
     vmentry_ctl = vmr32(VM_ENTRY_CONTROLS),
     vmexit_ctl = vmr32(VM_EXIT_CONTROLS);
     cr4 = vmr(GUEST_CR4);
-    efer = vmr(GUEST_EFER);
+
+    /* EFER.LMA is read as zero, and is loaded from vmentry_ctl on entry.

*/

xen/arch/x86/hvm/vmx/vmcs.c void vmcs_dump_vcpu(struct vcpu *v) · line 1794

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    BUILD_BUG_ON(VM_ENTRY_IA32E_MODE << 1 != EFER_LMA);
+    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE)

<< 1);

I have to admit that - despite the BUILD_BUG_ON() - I dislike the literal 1 here, which would better be
(_EFER_LMA - _VM_ENTRY_IA32E_MODE), albeit the latter doesn't exist, so perhaps

    efer = vmr(GUEST_EFER) | ((vmentry_ctl & VM_ENTRY_IA32E_MODE) *

(EFER_LMA / VM_ENTRY_IA32E_MODE));

Quoted 7 lines
Quoted 3 lines

or the same expressed through MASK_EXTR() / MASK_INSR()? But it's the VMX maintainers to judge anyway.

using 1 is fine to me, with intention well explained with BUILD_BUG_ON. as long as BUILD_BUG_ON is still a valid usage, I'm OK with current one:

I tried MASK_EXTR/INSR to begin with, but the code was practically illegible.  The * and / trick is only easy to follow if you know your bit hackary off by heart, and will go silently wrong if the constants happen to change or the operands happen to be the wrong way around.

I'm not a massive fan of the literal 1 either, but it was the most obvious way I could find of expressing the transformation.

Therefore, I'd prefer to keep the patch in this form unless there are serious objections.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel