Re: [RFC PATCH 09/18] KVM: x86/mmu: Extend access bitfield in kvm_mmu_page_role

From: Jon Kohler

Date: Mon Dec 22 2025 - 23:24:27 EST




> On May 12, 2025, at 10:14 PM, Jon Kohler <jon@xxxxxxxxxxx> wrote:
>
>> On May 12, 2025, at 2:32 PM, Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>>
>> On Thu, Mar 13, 2025, Jon Kohler wrote:
>>> diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h
>>> index 71d6fe28fafc..d9e22133b6d0 100644
>>> --- a/arch/x86/kvm/mmu/spte.h
>>> +++ b/arch/x86/kvm/mmu/spte.h
>>> @@ -45,7 +45,9 @@ static_assert(SPTE_TDP_AD_ENABLED == 0);
>>> #define ACC_EXEC_MASK 1
>>> #define ACC_WRITE_MASK PT_WRITABLE_MASK
>>> #define ACC_USER_MASK PT_USER_MASK
>>> -#define ACC_ALL (ACC_EXEC_MASK | ACC_WRITE_MASK | ACC_USER_MASK)
>>> +#define ACC_USER_EXEC_MASK (1ULL << 3)
>>> +#define ACC_ALL (ACC_EXEC_MASK | ACC_WRITE_MASK | ACC_USER_MASK | \
>>> + ACC_USER_EXEC_MASK)
>>
>> This is very subtly a massive change, and I'm not convinced its one we want to
>> make. All usage in the non-nested TDP flows is arguably wrong, because KVM should
>> never enable MBEC when using non-nested TDP.
>>
>> And the use in kvm_calc_shadow_ept_root_page_role() is wrong, because the root
>> page role shouldn't include ACC_USER_EXEC_MASK if the associated VMCS doesn't
>> have MBEC. Ditto for the use in kvm_calc_cpu_role().
>>
>> So I'm pretty sure the only bit of this change that is desriable/correct is the
>> usage in kvm_mmu_page_get_access(). (And I guess maybe trace_mark_mmio_spte()?)
>>
>> Off the cuff, I don't know what the best approach is. One thought would be to
>> prep for adding ACC_USER_EXEC_MASK to ACC_ALL by introducing ACC_RWX and using
>> that where KVM really just wants to set RWX permissions. That would free up
>> ACC_ALL for the few cases where KVM really truly wants to capture all access bits.
>
> At first blush, I like this ACC_RWX idea. I’ll chew on that and see what
> trouble I can get in.

Turns out, I got in a fair amount of trouble on this one. In v1, I’ve added a
prep patch that does this; however, I ended up having to revert it to get it to
work. I left the prep patch and the revert in the series to show my work on how
I got to that conclusion, but I’d appreciate some tips on how to resolve it. I
must just be missing something silly.