Re: [PATCH v2 2/2] KVM: x86/mmu: Derive EPT violation RWX bits from EPTE RWX bits

From: Isaku Yamahata
Date: Fri Apr 08 2022 - 17:11:47 EST


On Tue, Mar 29, 2022 at 11:01:07AM +0800,
SU Hang <darcy.sh@xxxxxxxxxxxx> wrote:

> From: Sean Christopherson <seanjc@xxxxxxxxxx>
>
> Derive the mask of RWX bits reported on EPT violations from the mask of
> RWX bits that are shoved into EPT entries; the layout is the same, the
> EPT violation bits are simply shifted by three. Use the new shift and a
> slight copy-paste of the mask derivation instead of completely open
> coding the same to convert between the EPT entry bits and the exit
> qualification when synthesizing a nested EPT Violation.
>
> No functional change intended.
>
> Cc: SU Hang <darcy.sh@xxxxxxxxxxxx>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/include/asm/vmx.h | 7 +------
> arch/x86/kvm/mmu/paging_tmpl.h | 8 +++++++-
> arch/x86/kvm/vmx/vmx.c | 4 +---
> 3 files changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> index 3586d4aeaac7..46bc7072f6a2 100644
> --- a/arch/x86/include/asm/vmx.h
> +++ b/arch/x86/include/asm/vmx.h
> @@ -543,17 +543,12 @@ enum vm_entry_failure_code {
> #define EPT_VIOLATION_ACC_READ_BIT 0
> #define EPT_VIOLATION_ACC_WRITE_BIT 1
> #define EPT_VIOLATION_ACC_INSTR_BIT 2
> -#define EPT_VIOLATION_READABLE_BIT 3
> -#define EPT_VIOLATION_WRITABLE_BIT 4
> -#define EPT_VIOLATION_EXECUTABLE_BIT 5
> #define EPT_VIOLATION_GVA_IS_VALID_BIT 7
> #define EPT_VIOLATION_GVA_TRANSLATED_BIT 8
> #define EPT_VIOLATION_ACC_READ (1 << EPT_VIOLATION_ACC_READ_BIT)
> #define EPT_VIOLATION_ACC_WRITE (1 << EPT_VIOLATION_ACC_WRITE_BIT)
> #define EPT_VIOLATION_ACC_INSTR (1 << EPT_VIOLATION_ACC_INSTR_BIT)
> -#define EPT_VIOLATION_READABLE (1 << EPT_VIOLATION_READABLE_BIT)
> -#define EPT_VIOLATION_WRITABLE (1 << EPT_VIOLATION_WRITABLE_BIT)
> -#define EPT_VIOLATION_EXECUTABLE (1 << EPT_VIOLATION_EXECUTABLE_BIT)
> +#define EPT_VIOLATION_RWX_MASK (VMX_EPT_RWX_MASK << EPT_VIOLATION_RWX_SHIFT)


"#define EPT_VIOLATION_RWX_SHIFT 3" is missing.
It fails to compile.

CC [M] arch/x86/kvm/vmx/vmx.o
In file included from linux/arch/x86/include/asm/virtext.h:18,
from /linux/arch/x86/kvm/vmx/vmx.c:49:
/linux/arch/x86/kvm/vmx/vmx.c: In function 'handle_ept_violation':
/linux/arch/x86/include/asm/vmx.h:551:54: error: 'EPT_VIOLATION_RWX_SHIFT' undeclared (first use in this function); did you mean 'EPT_VIOLATION_RWX_MASK'?
551 | #define EPT_VIOLATION_RWX_MASK (VMX_EPT_RWX_MASK << EPT_VIOLATION_RWX_SHIFT)
| ^~~~~~~~~~~~~~~~~~~~~~~

Thanks,
--
Isaku Yamahata <isaku.yamahata@xxxxxxxxx>