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] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 25 Jan 2021 15:51:08 -0800
From:   Ben Gardon <bgardon@...gle.com>
To:     Sean Christopherson <seanjc@...gle.com>
Cc:     LKML <linux-kernel@...r.kernel.org>, kvm <kvm@...r.kernel.org>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Peter Xu <peterx@...hat.com>, Peter Shier <pshier@...gle.com>,
        Peter Feiner <pfeiner@...gle.com>,
        Junaid Shahid <junaids@...gle.com>,
        Jim Mattson <jmattson@...gle.com>,
        Yulei Zhang <yulei.kernel@...il.com>,
        Wanpeng Li <kernellwp@...il.com>,
        Vitaly Kuznetsov <vkuznets@...hat.com>,
        Xiao Guangrong <xiaoguangrong.eric@...il.com>
Subject: Re: [PATCH 06/24] kvm: x86/mmu: Skip no-op changes in TDP MMU functions

On Wed, Jan 20, 2021 at 11:51 AM Sean Christopherson <seanjc@...gle.com> wrote:
>
> On Tue, Jan 12, 2021, Ben Gardon wrote:
> > Skip setting SPTEs if no change is expected.
> >
> > Reviewed-by: Peter Feiner <pfeiner@...gle.com>
> >
> Nit on all of these, can you remove the extra newline between the Reviewed-by
> and SOB?

Yeah, that line is annoying. I'll make sure it's not there on future patches.

>
> > Signed-off-by: Ben Gardon <bgardon@...gle.com>
> > ---
> >  arch/x86/kvm/mmu/tdp_mmu.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> > index 1987da0da66e..2650fa9fe066 100644
> > --- a/arch/x86/kvm/mmu/tdp_mmu.c
> > +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> > @@ -882,6 +882,9 @@ static bool wrprot_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
> >                   !is_last_spte(iter.old_spte, iter.level))
> >                       continue;
> >
> > +             if (!(iter.old_spte & PT_WRITABLE_MASK))
>
> Include the new check with the existing if statement?  I think it makes sense to
> group all the checks on old_spte.

I agree that' s cleaner. I'll group the checks in the next patch set version.

>
> > +                     continue;
> > +
> >               new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
> >
> >               tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
> > @@ -1079,6 +1082,9 @@ static bool set_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
> >               if (!is_shadow_present_pte(iter.old_spte))
> >                       continue;
> >
> > +             if (iter.old_spte & shadow_dirty_mask)
>
> Same comment here.
>
> > +                     continue;
> > +
>
> Unrelated to this patch, but it got me looking at the code: shouldn't
> clear_dirty_pt_masked() clear the bit in @mask before checking whether or not
> the spte needs to be modified?  That way the early break kicks in after sptes
> are checked, not necessarily written.  E.g.
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 2650fa9fe066..d8eeae910cbf 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -1010,21 +1010,21 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root,
>                     !(mask & (1UL << (iter.gfn - gfn))))
>                         continue;
>
> -               if (wrprot || spte_ad_need_write_protect(iter.old_spte)) {
> -                       if (is_writable_pte(iter.old_spte))
> -                               new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
> -                       else
> -                               continue;
> -               } else {
> -                       if (iter.old_spte & shadow_dirty_mask)
> -                               new_spte = iter.old_spte & ~shadow_dirty_mask;
> -                       else
> -                               continue;
> -               }
> -
> -               tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
> -
>                 mask &= ~(1UL << (iter.gfn - gfn));
> +
> +               if (wrprot || spte_ad_need_write_protect(iter.old_spte)) {
> +                       if (is_writable_pte(iter.old_spte))
> +                               new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
> +                       else
> +                               continue;
> +               } else {
> +                       if (iter.old_spte & shadow_dirty_mask)
> +                               new_spte = iter.old_spte & ~shadow_dirty_mask;
> +                       else
> +                               continue;
> +               }
> +
> +               tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
>         }
>  }
>

Great point, that doesn't work as intended at all. I'll adopt your
proposed fix and include it in a patch after this one in the next
version of the series.

>
> >               new_spte = iter.old_spte | shadow_dirty_mask;
> >
> >               tdp_mmu_set_spte(kvm, &iter, new_spte);
> > --
> > 2.30.0.284.gd98b1dd5eaa7-goog
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ