Re: [RFC PATCH 02/37] KVM: MMU: Move struct kvm_mmu_page_role into common code

Paolo Bonzini
2022-12-12T23:12:06Z

On 12/8/22 20:38, David Matlack wrote:
> +/*
> + * kvm_mmu_page_role tracks the properties of a shadow page (where shadow page
> + * also includes TDP pages) to determine whether or not a page can be used in
> + * the given MMU context.
> + */
> +union kvm_mmu_page_role {
> + u32 word;
> + struct {
> + struct {
> + /* The address space ID mapped by the page. */
> + u16 as_id:8;
> +
> + /* The level of the page in the page table hierarchy. */
> + u16 level:4;
> +
> + /* Whether the page is invalid, i.e. pending destruction. */
> + u16 invalid:1;
> + };
> +
> + /* Architecture-specific properties. */
> + struct kvm_mmu_page_role_arch arch;
> + };
> +};
> +

Have you considered adding a tdp_mmu:1 field to the arch-independent
part? I think that as long as _that_ field is the same, there's no need
to have any overlap between TDP MMU and shadow MMU roles.

I'm not even sure if the x86 TDP MMU needs _any_ other role bit. It
needs of course the above three, and it also needs "direct" but it is
used exactly to mean "is this a TDP MMU page". So we could have

union {
struct {
u32 tdp_mmu:1;
u32 invalid:1;
u32 :6;
u32 level:8;
u32 arch:8;
u32 :8;
} tdp;
/* the first field must be "u32 tdp_mmu:1;" */
struct kvm_mmu_page_role_arch shadow;
};

Paolo