Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1867388rwb; Thu, 8 Dec 2022 16:44:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KMd3TSY/eBPXiImNh7WLNdbcTYfKVUxXT6BN7mMPyXlc2Vuil09YbL6j1tX4gSvb19x1N X-Received: by 2002:a05:6a20:bb0f:b0:a4:150f:8dd9 with SMTP id fc15-20020a056a20bb0f00b000a4150f8dd9mr4678850pzb.45.1670546694536; Thu, 08 Dec 2022 16:44:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670546694; cv=none; d=google.com; s=arc-20160816; b=xJWNLlBdr7fLtNCWEJRlXuJ/mJX6szBmRZkNbWe99SwY8Yst2FcME4W49ABgXhjJOM x5SUkidc6TON49qFZggBx4X/snhqkXdO0w7UZsPl4Wdy7cbBLocBbuiMJjYSKOent3zk qcXbykmSyRcJexZ98CmsCGAzw6qQKDDk52eDJ9rk2CsXKkEq3P99FTZxUWIL7tLPUQpS UpRCoHqRib8YmcA7ktCF1ICtGu7s+EEEKp8vl3zFguFQBUlBf6PyLs01JcMBkMxoqqLE RaG9DH7+mTZd6Wq+Yt9kX7G/g+F/T8QFgbyz0AfBwxP5WcIHN+GpGP+tA6+6RiTs4+PJ fJGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1aXPgCiWEn4KqpNvDV1bjWt6gr8wgSQNFAq4xiow/SE=; b=LdmL4PmBglp3/Nj80m3ww0A5hLCOqFY4FtOEzHSsHVeTnfDsTiCyfe0b8GHrA8f6UQ 9TsBimLk70RJTYBWYa0+TKorIUElYLroeXkeFFf/wu/uOxsBvZopaNT7EOCEdsleglfZ V+t/RVxJ3NSVCvB+SsUnJc8qfhLLKHkYKQFjFmEdwCfKinDDJc0wuDrAGMgf/VxD+f52 jlqm2TOdLvmj9TByIj3b5NUUDIlpQEXocPGC+0pwozdYNOMtd9rGJYJA4yzlMLeZIHG4 y6ymRlsnpD1eD4rgMyOtXW2Q26U0npxviap2l433wkPLt+3X88uE2/94xnRXx2MeUU2k h2Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RdBqSc6M; 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 y22-20020a634b16000000b0046b3ba2c806si81194pga.145.2022.12.08.16.44.42; Thu, 08 Dec 2022 16:44:54 -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=RdBqSc6M; 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 S229573AbiLIAGe (ORCPT + 73 others); Thu, 8 Dec 2022 19:06:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLIAGc (ORCPT ); Thu, 8 Dec 2022 19:06:32 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679364D5C3 for ; Thu, 8 Dec 2022 16:06:31 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id 6so2451190pgm.6 for ; Thu, 08 Dec 2022 16:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1aXPgCiWEn4KqpNvDV1bjWt6gr8wgSQNFAq4xiow/SE=; b=RdBqSc6M4CRSmpGk02jYZa4dcKFJimgLaChffzjNbU2wVkOQG6eD2WGzanYIohroQY AbeZDovqExaPRQ8s0CnPuprwv5ZjmzOwCGQnWJB4AQP/15y38j/Eb4/CLV1s7R/BzVzG y9Oi5cQWHpGNqq67QlQpPKjko3dGs1ue8Vs5Sf6L1E/j2MZVU3A/eDg71zgCTqoEcGZG dh13GnYgoNVkfEtMKkfOrMvyuqWRxNATkZDVmfCmZCuIBs6Op2F7eHgPRfndb6xsH78Q cNOOU1buHucGHI8MjUcB+piHd96M6DJO1Bbw/ybJGHQ/CkLRTF8a5X7qDfWpJULEyvP1 edTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1aXPgCiWEn4KqpNvDV1bjWt6gr8wgSQNFAq4xiow/SE=; b=fpgSLUBfCEMnvDLwiYkhS9MEuDl3VN8gCRhxJdUg7u2IwhCYeyxWO5eDE/fYgX+etH mCcEzFUmwF9Ap7jG8jsZLniGGIlTfex6YnP+IdngLAs/+JeS/zlneg918MN27sqTx8l3 1MiWoe5ACULP/5+xnkFWqZpuivQA43zuFdAncCq2iaISOoBvicJVUgfHLaeELGXtZXzn 4ye3/u9kUwpnhTzQrMFWLKzlEuPQH04+f74dQs8AaC3CVidAW9XyM7B7Y3seZ8a74bF7 GuVtwjuQzG+B9OgJv83Wgq7XWlfj8RhywI+LRZMZipQQdS2KX1LgWTk2cQODUWO3GHBP m3hQ== X-Gm-Message-State: ANoB5pkXyh8UwIMJPfrGT1xhrC7Mr78RBz1X5wyMSEJy0VgQNhj/BcN0 BdyWf0ip6MrL7EvLDFFcW17REA== X-Received: by 2002:aa7:870a:0:b0:574:f201:660a with SMTP id b10-20020aa7870a000000b00574f201660amr3294647pfo.33.1670544390734; Thu, 08 Dec 2022 16:06:30 -0800 (PST) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id x17-20020aa79411000000b005777fe7681esm78051pfo.20.2022.12.08.16.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 16:06:30 -0800 (PST) Date: Thu, 8 Dec 2022 16:06:26 -0800 From: David Matlack To: Vipin Sharma Cc: Sean Christopherson , Paolo Bonzini , KVM , Linux Kernel Mailing List , Ben Gardon Subject: Re: [Patch v2 2/2] KVM: x86/mmu: Allocate page table pages on NUMA node of underlying pages Message-ID: References: <20221201195718.1409782-1-vipinsh@google.com> <20221201195718.1409782-3-vipinsh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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.