lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CABgObfZBGGcj5pYsNpzwLShxLg8nxOdaQNnouRicFudxXZudxg@mail.gmail.com>
Date: Wed, 22 Jan 2025 19:20:55 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: linux-kernel@...r.kernel.org, kvm@...r.kernel.org, yan.y.zhao@...el.com, 
	isaku.yamahata@...el.com, binbin.wu@...ux.intel.com, 
	rick.p.edgecombe@...el.com
Subject: Re: [PATCH v6 09/18] KVM: x86/tdp_mmu: Extract root invalid check
 from tdx_mmu_next_root()

On Sat, Jan 18, 2025 at 2:05 AM Sean Christopherson <seanjc@...gle.com> 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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ