Re: [PATCH v6 09/18] KVM: x86/tdp_mmu: Extract root invalid check from tdx_mmu_next_root()

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

 



On Sat, Jan 18, 2025 at 2:05 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> > +static bool tdp_mmu_root_match(struct kvm_mmu_page *root, bool only_valid)
> > +{
> > +     if (only_valid && root->role.invalid)
> > +             return false;
> > +
> > +     return true;
>
> Ugh, this is almost as bad as
>
>         if (x)
>                 return true;
>
>         return false;
>
> Just do
>
>         return !only_valid || root->role.invalid;
>
> And I vote to drop the helper, "match" makes me think about things like roles
> and addresses, not just if a root is valid.

This is not the definitive shape of the function; by the end of the
series it becomes

static bool tdp_mmu_root_match(struct kvm_mmu_page *root,
                               enum kvm_tdp_mmu_root_types types)
{
        if (WARN_ON_ONCE(!(types & KVM_VALID_ROOTS)))
                return false;

        if (root->role.invalid && !(types & KVM_INVALID_ROOTS))
                return false;

        if (likely(!is_mirror_sp(root)))
                return types & KVM_DIRECT_ROOTS;
        return types & KVM_MIRROR_ROOTS;
}

(where the first "if" could also be just a WARN_ON_ONCE without the
anticipated return, since KVM_VALID_ROOTS == KVM_DIRECT_ROOTS |
KVM_MIRROR_ROOTS)

Paolo






[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