From patchwork Thu Dec 22 02:34:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 35580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp97990wrn; Wed, 21 Dec 2022 18:37:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3U4Jxm1TF9X5jk82xb1PBNv3uJ3lYhjB2p4vDJEesBGOrfLhLNsuR+1foxsuOefjhFID0 X-Received: by 2002:a50:ee0d:0:b0:461:568b:fb22 with SMTP id g13-20020a50ee0d000000b00461568bfb22mr3421869eds.8.1671676628750; Wed, 21 Dec 2022 18:37:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671676628; cv=none; d=google.com; s=arc-20160816; b=nlqCZUzAiKLv0F4/PTHWPEZxeFcAAl4G4l+AdyhyYFC1nxRf18eTLqzXfuJlNlo2t2 FjbHgG/A1I9DxtKbRFUKjvYo8n1ntdC8w7HT8A+PrQ7PT1bxejOPdJ715Q4fnIQjwW1J 9Sk4olo+6Pdjx0Q3vHnisSIT+D/Zy5R1cRJZ528gwXS/zBYD47ohmtjGxRUcrBtChJUO fAXxB/DEkj6f2oscWZ8s8Qi9KRYd5uj6HVbLX4cxBWm2K8kJHn6hqgJWPhXDFwGuNz1s rjzK2KqVx8i8qgZQ+4YdB6KC3PffRfK7JA/gOH32ptsojUP0UaCTySxq7yINplwnrKoU 2iDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=bxkmrVszmYtdX56U0+zIQlMbh2VgS2C48ld2l9CYwus=; b=gL0yl8M10UczZaYjU00UC/ECyELfLttjPhd2apUVmPVISgfBS2JjSYRNctgg2ykutI Ly9F7qoy/m6rfdCuHYRGROZO5riWwhYFsyhdVacGKlyja1AllD+sca6/1yXrM9R6H1Zx fzfIusUFRaxYBEkZaavKejrxH29JW0LNldfogwyvz58Svg4TkI6EJxizr2mHpMad7q0S gENuXua1BcjeBspbV8MUY5FrsEYnvje8AncBLNwLV4FqHukpS9wdVgW8Jk4wM0jyLG61 VbMr9dLFLmNjDYzTeIJTG5Tmkgr1WpEmgVTQTC51Sl9qCsF8IrpjIqobjVnmRWwJBmaM vRjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Rn6JhTg0; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020aa7dac1000000b0046bef95b2e6si12923819eds.492.2022.12.21.18.36.45; Wed, 21 Dec 2022 18:37:08 -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=Rn6JhTg0; 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 S234935AbiLVCfV (ORCPT + 99 others); Wed, 21 Dec 2022 21:35:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234975AbiLVCfI (ORCPT ); Wed, 21 Dec 2022 21:35:08 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C6D224BE9 for ; Wed, 21 Dec 2022 18:35:07 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id il11-20020a17090b164b00b00219a4366109so2315685pjb.0 for ; Wed, 21 Dec 2022 18:35:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bxkmrVszmYtdX56U0+zIQlMbh2VgS2C48ld2l9CYwus=; b=Rn6JhTg0zhPlYluWmxYHpBlbM65jcOKT08CTpFfaF7H5DiKsfX4cghOlXKtbXYarOK Rly5XOhtvEYkFNI27R7kdmcDaft+DtQZHjIUVe60dOsihgLsa9smgxM+b5XDJjnQ5ViO Lkw5zbkLDE5ElgM22t1HWQhqSPjJc/A7roPsY0/dbXeUhXDdkCO+aerp6M5Gy8UvxMx9 hry1N1NLcMymvSxaWuZTNy40tIRuVsbU4zETnVIVyXentp2aZLJhf0IN9lIyvdeQEICD jjslMf9GOy2+ihLLAQ7wMggtMTn5Pk6LiRqyldHCiyElR3iBYcg59o/9Nzc9a7CBMBBj D2Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bxkmrVszmYtdX56U0+zIQlMbh2VgS2C48ld2l9CYwus=; b=ucqHjmmPBBcd6XRaqeEXEVvzl6lObI5ylqBFUK0Fw2dIyJCCI5mUQYR844o3YahPNI DgcpLzE03Ycae2WLyQTlDsPYKVpGFcP0+fqVK/Oyu9FOHjZGYxmbk5ZRLKWpdxF62Bwd w06Ci/Jw7ZOEQGxu/HSaHtPrW/XU9NAWs22dTPvzSDlkX5vOFDY0P/dn0O1mqrYhwJeW LtHrr/gJODrZoYEvfLpgMQFRc7+osVDvJexdnQqfcr+GnkW7SUSJ8wqK3FPNCr0q17p4 HQRDqrL1x0eyGThPODqync4Ce67z5g9UzFZmhp+9Zrx2S6SX5GuniHZDHKyW+jkAiWLq ZFfQ== X-Gm-Message-State: AFqh2kpAqvLZlqPTmzM8xkc8MTgUZC/3WhWORevfDaighXwC6Ym2vkPj 6L2S6WFcDQ6rAjfnspOCIk10EHEAyEGS X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a62:1d0c:0:b0:56b:bba4:650a with SMTP id d12-20020a621d0c000000b0056bbba4650amr294643pfd.4.1671676506822; Wed, 21 Dec 2022 18:35:06 -0800 (PST) Date: Wed, 21 Dec 2022 18:34:52 -0800 In-Reply-To: <20221222023457.1764-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221222023457.1764-1-vipinsh@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221222023457.1764-5-vipinsh@google.com> Subject: [Patch v3 4/9] KVM: Add module param to make page tables NUMA aware From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, bgardon@google.com, dmatlack@google.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752879992807634124?= X-GMAIL-MSGID: =?utf-8?q?1752879992807634124?= Add a numa_aware_page_table module param to make page tables NUMA aware. Signed-off-by: Vipin Sharma --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index efd9b38ea9a2..d48064503b88 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1358,6 +1358,8 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu, bool usermode_vcpu_not_eligible); void kvm_flush_remote_tlbs(struct kvm *kvm); +void *kvm_mmu_get_free_page(int nid, gfp_t gfp); + #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min); int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity, int min); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f2d762878b97..d96c8146e9ba 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -93,6 +93,13 @@ unsigned int halt_poll_ns_shrink; module_param(halt_poll_ns_shrink, uint, 0644); EXPORT_SYMBOL_GPL(halt_poll_ns_shrink); +/* + * If possible, allocate page table's pages on the same node the underlying + * physical page is pointing to. + */ +static bool __read_mostly numa_aware_pagetable = true; +module_param_named(numa_aware_pagetable, numa_aware_pagetable, bool, 0644); + /* * Ordering of locks: * @@ -384,6 +391,21 @@ static void kvm_flush_shadow_all(struct kvm *kvm) kvm_arch_guest_memory_reclaimed(kvm); } +void *kvm_mmu_get_free_page(int nid, gfp_t gfp) +{ + #ifdef CONFIG_NUMA + struct page *spt_page; + + if (numa_aware_pagetable) { + spt_page = alloc_pages_node(nid, gfp, 0); + if (spt_page) + return page_address(spt_page); + } + #endif // CONFIG_NUMA + + return (void *)__get_free_page(gfp); +} + #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE static inline void *mmu_memory_cache_alloc_obj(struct kvm_mmu_memory_cache *mc, gfp_t gfp_flags)