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]
Message-ID: <Y5J8ArpcVVyBm3CY@google.com>
Date:   Thu, 8 Dec 2022 16:06:26 -0800
From:   David Matlack <dmatlack@...gle.com>
To:     Vipin Sharma <vipinsh@...gle.com>
Cc:     Sean Christopherson <seanjc@...gle.com>,
        Paolo Bonzini <pbonzini@...hat.com>, KVM <kvm@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Ben Gardon <bgardon@...gle.com>
Subject: Re: [Patch v2 2/2] KVM: x86/mmu: Allocate page table pages on NUMA
 node of underlying pages

On Wed, Dec 07, 2022 at 11:05:09AM -0800, Vipin Sharma wrote:
> By mistake I started replying to just Ben and realized it after few
> exchanges. Adding others. Sorry about that.
> 
> On Wed, Dec 7, 2022 at 10:58 AM Vipin Sharma <vipinsh@...gle.com> wrote:
> >
> > On Tue, Dec 6, 2022 at 11:57 AM Ben Gardon <bgardon@...gle.com> wrote:
> > >
> > > On Tue, Dec 6, 2022 at 11:18 AM Vipin Sharma <vipinsh@...gle.com> wrote:
> > > >
> > > > On Tue, Dec 6, 2022 at 10:17 AM Ben Gardon <bgardon@...gle.com> wrote:
> > > > >
> > > > > On Mon, Dec 5, 2022 at 3:40 PM Vipin Sharma <vipinsh@...gle.com> wrote:
> > > > > >
> > > > > > On Mon, Dec 5, 2022 at 10:17 AM Ben Gardon <bgardon@...gle.com> wrote:
> > > > > > >
> > > > > > > On Thu, Dec 1, 2022 at 11:57 AM Vipin Sharma <vipinsh@...gle.com> wrote:
> > > > > > > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > > > > > > > index 1782c4555d94..4d59c9d48277 100644
> > > > > > > > --- a/virt/kvm/kvm_main.c
> > > > > > > > +++ b/virt/kvm/kvm_main.c
> > > > > > > > @@ -384,6 +384,11 @@ static void kvm_flush_shadow_all(struct kvm *kvm)
> > > > > > > >         kvm_arch_guest_memory_reclaimed(kvm);
> > > > > > > >  }
> > > > > > > >
> > > > > > > > +void * __weak kvm_arch_mmu_get_free_page(int nid, gfp_t gfp_flags)
> > > > > > > > +{
> > > > > > > > +               return (void *)__get_free_page(gfp_flags);
> > > > > > > > +}
> > > > > > > > +
> > > > > > >
> > > > > > > Rather than making this __weak, you could use #ifdef CONFIG_NUMA to
> > > > > > > just put all the code in the arch-neutral function.
> > > > > > >
> > > > > >
> > > > > > I am not sure how it will work. Here, I am trying to keep this feature
> > > > > > only for x86. This function will be used for all architecture except
> > > > > > in x86 where we have different implementation in arch/x86/mmu/mmu.c
> > > > > > So, even if CONFIG_NUMA is defined, we want to keep the same
> > > > > > definition on other architectures.
> > > > > >
> > > > > >
> > > > >
> > > > > Something like:
> > > > >
> > > > > +void * kvm_arch_mmu_get_free_page(int nid, gfp_t gfp_flags)
> > > > > +{
> > > > > +       struct page *spt_page;
> > > > > +       void *address = NULL;
> > > > > +
> > > > > +       #ifdef CONFIG_NUMA
> > > > > +       if (nid != NUMA_NO_NODE) {
> > > > > +               spt_page = alloc_pages_node(nid, gfp, 0);
> > > > > +               if (spt_page) {
> > > > > +                       address = page_address(spt_page);
> > > > > +                       return address;
> > > > > +               }
> > > > > +       }
> > > > > +       #endif // CONFIG_NUMA
> > > > > +       return (void *)__get_free_page(gfp);
> > > > > +}
> > > > >
> > > >
> > > > 'nid' will be 0 not NUMA_NO_NODE for other architectures. In x86, I am
> > > > explicitly setting kvm_mmu_memory_cache->node to NUMA_NO_NODE or
> > > > specific desired nodes. In others architectures it will be 0 as struct
> > > > will be 0 initialized. __weak avoids initializing nid to NUM_NO_NODE
> > > > in other architectures.
> > >
> > > ooh, I see. It might be worth setting it to NUMA_NO_NODE on other
> > > archs as 0 could be kind of misleading.
> >
> > Discussed offline with Ben.
> > Initialization code for cache is in the respective architectures.
> > Using "__weak" avoids touching code in other architectures.

But it's still a bit gross to have node=0 in struct
kvm_mmu_memory_cache for other architectures, even if it doesn't happen
to be misused in this series.

I would just bite the bullet and modify the other architectures. Do it
in a precusor patch where you just add node to struct
kvm_mmu_memory_cache and initialize it to NUMA_NO_NODE across all
architectures, probably with a common macro e.g.

#define INIT_KVM_MMU_MEMORY_CACHE(_cache) do { \
	(_cache)->node = NUMA_NO_NODE; \
} while (0)

Then, you can follow Ben's approach and avoid the __weak function.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ