On Wed, May 10, 2023 at 02:06:10PM +0800, Binbin Wu wrote: >Untag address for 64-bit memory/MMIO operand in instruction emulations >and VMExit handlers when LAM is applicable. > >For instruction emulation, untag address in __linearize() before >canonical check. LAM doesn't apply to addresses used for instruction >fetches or to those that specify the targets of jump and call instructions, >use X86EMUL_F_SKIPLAM to skip LAM untag. > >For VMExit handlers related to 64-bit linear address: >- Cases need to untag address > Operand(s) of VMX instructions and INVPCID. > Operand(s) of SGX ENCLS. >- Cases LAM doesn't apply to > Operand of INVLPG. > Linear address in INVPCID descriptor (no change needed). > Linear address in INVVPID descriptor (it has been confirmed, although it is > not called out in LAM spec, no change needed). > >Note: >LAM doesn't apply to the writes to control registers or MSRs. >LAM masking applies before paging, so the faulting linear address in CR2 >doesn't contain the metadata. >The guest linear address saved in VMCS doesn't contain metadata. > >Co-developed-by: Robert Hoo <robert.hu@xxxxxxxxxxxxxxx> >Signed-off-by: Robert Hoo <robert.hu@xxxxxxxxxxxxxxx> >Signed-off-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx> >Tested-by: Xuelian Guo <xuelian.guo@xxxxxxxxx> Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx> >--- a/arch/x86/kvm/kvm_emulate.h >+++ b/arch/x86/kvm/kvm_emulate.h >@@ -230,6 +230,8 @@ struct x86_emulate_ops { > int (*leave_smm)(struct x86_emulate_ctxt *ctxt); > void (*triple_fault)(struct x86_emulate_ctxt *ctxt); > int (*set_xcr)(struct x86_emulate_ctxt *ctxt, u32 index, u64 xcr); >+ >+ void (*untag_addr)(struct x86_emulate_ctxt *ctxt, u64 *addr, u32 flags); Nit: using 'gva_t *' as the second parameter would eliminate the need to cast to 'u64 *' repeatedly.