Re: Question regarding ASM_VMX_VMXON_RAX

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

 



On Tue, 2018-03-27 at 10:50 +0200, David Hildenbrand wrote:
> On 27.03.2018 02:40, Jidong Xiao wrote:
> > 
> > Hi,
> > 
> > The SDM defines the opcode of the VMXON instruction as F3 0F C7 /6,
> > yet in the kernel source code (arch/x86/include/asm/vmx.h) I saw:
> > 
> > #define ASM_VMX_VMXON_RAX         ".byte 0xf3, 0x0f, 0xc7, 0x30"
> > 
> > So what is 0x30 used for? And why there is no "/6"?
> The /6 actually refers to the ModR/M byte if I'm not mistaking.

Yep.

    /digit — A digit between 0 and 7 indicates that the ModR/M byte of
             the instruction uses only the r/m (register or memory)
             operand. The reg field contains the digit that
provides
             an extension to the instruction's opcode.

> It is used to define how the address is passed to the VMXON instruction.
> 0x30 refers to RAX here. So if you would want to pass the address e.g.
> via RBX, you would need 0x33 if I'm not wrong.

Yep again.  0x30 is hardcoding the ModR/M to Mod=00b, Reg=110b (this
is the /6 digit) and R/M=000b, which is equivalent to "VMXON [RAX]";
thus the _RAX at the end of the macro name.

The mnemonic "VMXON m64" in the SDM states that VMXON must have a memory
operand, i.e. Mod=11b will result in a #UD. The other memory Mods (01b
and 10b) are legal for VMXON, but KVM undoubtedly added VMXON prior to
widespread compiler support for VMX, e.g. asm volatile("vmxon...") wasn't
an option.  Hardcoding a specific ModR/M and stuffing the appropriate reg
is a clean and easy method to hand encode an opcode with a /digit field.

Section 3.1 in Vol. 2A of the current SDM has more details.

> > I saw this 0x30 in several other macros as well, such as
> > ASM_VMX_VMCLEAR_RAX and ASM_VMX_VMPTRLD_RAX.
> > 
> > Where in the SDM, can I find some explanation to this 0x30? Thanks.
> Look out for the ModR/M tables.
> 
> > 
> > 
> > -Jidong
> > 
> 



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux