Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3200320rwb; Fri, 9 Dec 2022 11:12:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf7O/UZOOgaEXUaw+yIbJMF0Zt0wig9Kg8hDEN5Kkmo39g0hXtiqHWMfAXuH3OgaHOQdRMrv X-Received: by 2002:a05:6402:2411:b0:468:5fa9:68d0 with SMTP id t17-20020a056402241100b004685fa968d0mr6570939eda.6.1670613150583; Fri, 09 Dec 2022 11:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670613150; cv=none; d=google.com; s=arc-20160816; b=Lh2+E4s8Q5pe83ZkkAv8zblZ9wg6BnNILM3TYAshIxJ9Kyd0epS0OEkuXeaKnU1jJk 5bkH2K6Sd9H9BJcBR7ILJzCuxpH1Os2nzyKuke9We8PrE4oMCP7ronkL+NRcg+cIr71G wpX/WAD5EFJGoiJjoky9hYZ204GfuYLvl5bnkXzUWZn378TMJZdccPkeB9Ev2d7uKtTr DhZjZNIsFOmAeTzlwsaJ+yHPd4EFPWot0Rx88cwxwy7BK75iI+1RXMgGel+LiSXWYS+W B5mYvLNjf6i63WBLfDbRjFd/SWMSWJz6KO/J6vK+ELMr1CPnzNRbMS1C5GjSXKTfVade WwVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gaCkzOJ3JcEKzXNq8HvAtVCsHZl4FsYrpyHDMrGZRq0=; b=y8e1P1fs/A8pAkhe/IQoTXQMMuAvxbwQKN5G0k5vEqAfsdpd0st+VFOCZn4tFjukv+ 9t/emon+xbja4kasdb/tDdEOqYisLkDuMPYw1naR6JljQAPiI0Fz2jwxy5eIsii9tIBJ 85//NExat87MGDr+JH0KniMFFWIa6Snwkd90y7707AdIOsDySCy9CKwJgWvalAIG2PEO UCiLQ1+4brfdOWS2dFi60FoiiYA+Nf7ZXMkPZdj06A+zQU5NbQR+CcyKqKRPiuXz40zF rQ3dUkVfmY2pjHeRRdB3Zv4+rKLQjmWAwnsOdFPjXb4BDAJzFKZouBB2P/Ux4kNWpi2Q d3Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DMc3Xh9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f22-20020aa7d856000000b00462c7bbc03esi1894802eds.114.2022.12.09.11.12.13; Fri, 09 Dec 2022 11:12:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DMc3Xh9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiLISse (ORCPT + 74 others); Fri, 9 Dec 2022 13:48:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbiLISsb (ORCPT ); Fri, 9 Dec 2022 13:48:31 -0500 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A097E13DDC for ; Fri, 9 Dec 2022 10:48:30 -0800 (PST) Received: by mail-il1-x132.google.com with SMTP id z18so342876ils.3 for ; Fri, 09 Dec 2022 10:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gaCkzOJ3JcEKzXNq8HvAtVCsHZl4FsYrpyHDMrGZRq0=; b=DMc3Xh9+cHhAWtN5Nh/3gk4FqGEaN/ZkjSd1lVDsz5idjNhS+Y6Zd7S5bnqOTwuumQ cYWXNQ8wBNYsx37bvuTGY8aIFn0PzuHbdpbIrO9x8HTHTW5oL7CxWgiLAD3nnFgYZ3sM Hqxg2XFZVDTAUr5dkJGnVZXoBPharBXdDWb6e9j4L54EXZwzEEYs6lnDkC76Hvv0czG8 UHv0jU14OMQwWFkKaTEnsrH0F/vaRAMf7KP9cFkm/9K0Vf407IX2G4Xk6sTyZiq8KoNN 3KE3JqY3SrKqzoyNO0TbmuS27qPvw+JqqFcZkF5mVLSityyfMZTDGU2bJJ8emd9FP086 HlBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gaCkzOJ3JcEKzXNq8HvAtVCsHZl4FsYrpyHDMrGZRq0=; b=pd2V9mII458/13vjZwnUUt7qNO6PHIKGHH4UNIIJ8NfcB7DhjhjTdNv+/CmVLR3sqy hF6MHwwU3x4xGEo1x5Mqp998h+H78G6fD7nZaEVjQqeqlVHVG8rLBr7A/URC90I7gM/1 PcoTClcyhpxpkb2LQ28qXU2+SBUk3tjosVBixBaXc2H/rbAvgRIiCdS2pF5LR6wv0xMo /34mIrt1xXJ63ukW6a/Z4WzSaku2t3rUL9D2pU5TaR5zlxTZ12qCgF7MLFBG93Iry3uv 4uF4teBOmcFB2J3ptdBcjPfHNbfMWJ6IqgOQ9vs0FydkuQpkNf0GG7XAEVgVQ7iVo6YB 4g3w== X-Gm-Message-State: ANoB5pljCIQjfde4j2ydwoN3NYsZejM5eGILcm39bvzPsc1A+FoMlRss u1Cqyb8Y1C+xOCbJxDFXKvCaVOLkDRuExonk/qE8Qw== X-Received: by 2002:a92:6e12:0:b0:302:abfb:51d5 with SMTP id j18-20020a926e12000000b00302abfb51d5mr37028304ilc.196.1670611709743; Fri, 09 Dec 2022 10:48:29 -0800 (PST) MIME-Version: 1.0 References: <20221201195718.1409782-1-vipinsh@google.com> <20221201195718.1409782-3-vipinsh@google.com> In-Reply-To: From: Vipin Sharma Date: Fri, 9 Dec 2022 10:47:53 -0800 Message-ID: Subject: Re: [Patch v2 2/2] KVM: x86/mmu: Allocate page table pages on NUMA node of underlying pages To: David Matlack Cc: Sean Christopherson , Paolo Bonzini , KVM , Linux Kernel Mailing List , Ben Gardon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 8, 2022 at 4:06 PM David Matlack wrote: > > 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 wrote: > > > > > > On Tue, Dec 6, 2022 at 11:57 AM Ben Gardon wrote: > > > > > > > > On Tue, Dec 6, 2022 at 11:18 AM Vipin Sharma wrote: > > > > > > > > > > On Tue, Dec 6, 2022 at 10:17 AM Ben Gardon wrote: > > > > > > > > > > > > On Mon, Dec 5, 2022 at 3:40 PM Vipin Sharma wrote: > > > > > > > > > > > > > > On Mon, Dec 5, 2022 at 10:17 AM Ben Gardon wrote: > > > > > > > > > > > > > > > > On Thu, Dec 1, 2022 at 11:57 AM Vipin Sharma 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. Okay, 2 votes for NUMA_NO_NODE and 1 for __weak. I will remove the __weak and modify other architecture code.