On Tue, Jan 3, 2023 at 10:46 AM Vipin Sharma <vipinsh@xxxxxxxxxx> wrote: > > On Thu, Dec 29, 2022 at 3:12 PM David Matlack <dmatlack@xxxxxxxxxx> wrote: > > > > On Thu, Dec 29, 2022 at 3:08 PM David Matlack <dmatlack@xxxxxxxxxx> wrote: > > > > > > On Wed, Dec 21, 2022 at 06:34:54PM -0800, Vipin Sharma wrote: > > > > Add 'node' variable in kvm_mmu_memory_cache{} to denote which NUMA node > > > > this cache should allocate memory from. Default initialize to > > > > NUMA_NO_NODE in all architectures. > > > > > > > > Signed-off-by: Vipin Sharma <vipinsh@xxxxxxxxxx> > > > > --- > > > > arch/arm64/kvm/arm.c | 2 +- > > > > arch/arm64/kvm/mmu.c | 4 +++- > > > > arch/mips/kvm/mips.c | 2 ++ > > > > arch/riscv/kvm/mmu.c | 2 +- > > > > arch/riscv/kvm/vcpu.c | 2 +- > > > > arch/x86/kvm/mmu/mmu.c | 22 ++++++++++++---------- > > > > include/linux/kvm_host.h | 6 ++++++ > > > > include/linux/kvm_types.h | 2 ++ > > > > 8 files changed, 28 insertions(+), 14 deletions(-) > > > > > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > > > index 9c5573bc4614..52a41f4532e2 100644 > > > > --- a/arch/arm64/kvm/arm.c > > > > +++ b/arch/arm64/kvm/arm.c > > > > @@ -340,7 +340,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) > > > > vcpu->arch.target = -1; > > > > bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES); > > > > > > > > - vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO; > > > > + INIT_KVM_MMU_MEMORY_CACHE(&vcpu->arch.mmu_page_cache, NULL, NUMA_NO_NODE); > > > > > > > > /* > > > > * Default value for the FP state, will be overloaded at load > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > > > index 31d7fa4c7c14..bd07155e17fa 100644 > > > > --- a/arch/arm64/kvm/mmu.c > > > > +++ b/arch/arm64/kvm/mmu.c > > > > @@ -894,12 +894,14 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, > > > > { > > > > phys_addr_t addr; > > > > int ret = 0; > > > > - struct kvm_mmu_memory_cache cache = { .gfp_zero = __GFP_ZERO }; > > > > + struct kvm_mmu_memory_cache cache; > > > > struct kvm_pgtable *pgt = kvm->arch.mmu.pgt; > > > > enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_DEVICE | > > > > KVM_PGTABLE_PROT_R | > > > > (writable ? KVM_PGTABLE_PROT_W : 0); > > > > > > > > + INIT_KVM_MMU_MEMORY_CACHE(&cache, NULL, NUMA_NO_NODE); > > > > > > This is not any better than setting cache.node = NUMA_NO_NODE directly. > > > Yes it's less lines of code, but it's harder to read (what does NULL > > > mean here?), and every user of kvm_mmu_memory_cache still has to know to > > > pass NUMA_NO_NODE. > > > > > > When I originally gave this suggestion, I intended to suggest that > > > INIT_KVM_MMU_MEMORY_CACHE() provide just default initialization. > > > Non-default initialization for gfp_zero, gfp_custom, kmem_cache, and > > > node would remain as they are. > > > > > > Yes this adds some more lines, but keeps things readable, and doesn't > > > every initialization site of kvm_mmu_memory_cache to know what to pass > > > for gfp_zero, node, and kmem_cache. It only needs to set the fields > > > *it* cares about. > > > > And to offset the extra lines to call INIT_KVM_MMU_MEMORY_CACHE(), we > > could finally invert the meaning of gfp_zero so that caches use > > __GFP_ZERO by default. The majority of caches want __GFP_ZERO, so that > > should cut down a bunch of lines. > > > > Can you clarify what you mean by invert? > > Caches which don't want __GFP_ZERO will explicitly set gfp_zero to 0. > Is this what you intend? When I wrote that comment I was thinking you can change `gfp_t gfp_zero` to e.g. `bool skip_gfp_zero` so that the default initialized value (false/0) means "use __GFP_ZERO". However, that's silly once we have INIT_KVM_MMU_MEMORY_CACHE(). We can do what you suggest: set gfp_zero to __GFP_ZERO in INIT_KVM_MMU_MEMORY_CACHE() and then explicitly set it to 0 in caches that don't need __GFP_ZERO.