Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1965924ybt; Thu, 2 Jul 2020 19:36:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmOmwTW6FFMQUJz06eO6ueVErEele6FdAOPWvYuxssoNg5Tw+kTp8t9vB8HEbDw8ew2xQW X-Received: by 2002:a17:906:2e83:: with SMTP id o3mr26839186eji.261.1593743804809; Thu, 02 Jul 2020 19:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593743804; cv=none; d=google.com; s=arc-20160816; b=hVPngmymR3EJWPOh0KWhLrPZASm6Di+1MfyXEPC17TeEB6GMYwJUeM33segYLKyIr8 lZ4yEg6Oqyc2hQoh3/rJOjmpEEqGlvesy1F6rQnHdIc4ndyIdu4d14VaEfK747jqMZXW FU4HHGEjvooGUwKajK+55xcJTwt4ebNeNOUpN4acfclHd8LIkqAc3XzcewQN4WoAox5H Wy7E+lNaL5NF1ldBcj09HW6WqA1/Pu8f+zz3ZUEKO1CUTFoV4dcZSY7mob2q0KXDD06t TIaB037RdLbYauTb64YMGm0naveUOeQepg9BhCatFmJijnppwWOgPV+QrwqsEAena4IV 6S+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=m9Gjm0kcWSetOYR+LuORv0ftjuvz30sqVmqmow5itas=; b=ytl6plCCqt7zU5vRJrzt0FOD6tjityWCG3WnpBPtG8nGSf5fArodzAPUBtoC5Jc0GE VAaUCi7zML2KzG+z896BFwH9mg9SH5rRQzACiMGiUEaSzb3j2BcMrFRJJ3nUh7kK9GEc 87w5e9MSOzPxXRwswD4VeDTWwHWIZSFO9Am/y1BVPBUtJA4kXpEe4MhWbaeN0TbGvW5X oXyXb5ND0IGwieoh/5qHftY8X9gPD/62nbGKArH/T19qctnbjCkCidlzKmBOT1Ez2fYK gNfk3/luLRrOlY5gnrisChKx+o8PeYWlk0ez9e6LvbO2lsJsgbYvl1u74ENaaBt732pT epTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si6969708ejs.158.2020.07.02.19.36.21; Thu, 02 Jul 2020 19:36:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbgGCCgK (ORCPT + 99 others); Thu, 2 Jul 2020 22:36:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:52027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725937AbgGCCgG (ORCPT ); Thu, 2 Jul 2020 22:36:06 -0400 IronPort-SDR: 27aH5HFC4owY8cC8318GdmaeU6NMdOEdgWzEcV4Px2LgQUzOuhT8j9pRuNjMqI853p5YxcLlhT N0KOuVNM6bcA== X-IronPort-AV: E=McAfee;i="6000,8403,9670"; a="145213958" X-IronPort-AV: E=Sophos;i="5.75,306,1589266800"; d="scan'208";a="145213958" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2020 19:36:05 -0700 IronPort-SDR: Tf2UVjZ6SYjYNjI28qCvFsw5DIp+J6Bn7pYy33T3q37kSEk3EvDJqiJpYD3iFpyJbSP45UgECj mwXx+VAt2qiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,306,1589266800"; d="scan'208";a="278295718" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga003.jf.intel.com with ESMTP; 02 Jul 2020 19:36:04 -0700 From: Sean Christopherson To: Marc Zyngier , Paolo Bonzini , Arnd Bergmann Cc: James Morse , Julien Thierry , Suzuki K Poulose , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , Peter Feiner , Peter Shier , Junaid Shahid , Christoffer Dall Subject: [PATCH v3 01/21] KVM: x86/mmu: Track the associated kmem_cache in the MMU caches Date: Thu, 2 Jul 2020 19:35:25 -0700 Message-Id: <20200703023545.8771-2-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200703023545.8771-1-sean.j.christopherson@intel.com> References: <20200703023545.8771-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Track the kmem_cache used for non-page KVM MMU memory caches instead of passing in the associated kmem_cache when filling the cache. This will allow consolidating code and other cleanups. No functional change intended. Reviewed-by: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu/mmu.c | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index f852ee350beb..71bc32e00d7e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -251,6 +251,7 @@ struct kvm_kernel_irq_routing_entry; */ struct kvm_mmu_memory_cache { int nobjs; + struct kmem_cache *kmem_cache; void *objects[KVM_NR_MEM_OBJS]; }; diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 3dd0af7e7515..2c62cc1d0353 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1060,15 +1060,14 @@ static void walk_shadow_page_lockless_end(struct kvm_vcpu *vcpu) local_irq_enable(); } -static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, - struct kmem_cache *base_cache, int min) +static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, int min) { void *obj; if (cache->nobjs >= min) return 0; while (cache->nobjs < ARRAY_SIZE(cache->objects)) { - obj = kmem_cache_zalloc(base_cache, GFP_KERNEL_ACCOUNT); + obj = kmem_cache_zalloc(cache->kmem_cache, GFP_KERNEL_ACCOUNT); if (!obj) return cache->nobjs >= min ? 0 : -ENOMEM; cache->objects[cache->nobjs++] = obj; @@ -1081,11 +1080,10 @@ static int mmu_memory_cache_free_objects(struct kvm_mmu_memory_cache *cache) return cache->nobjs; } -static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc, - struct kmem_cache *cache) +static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc) { while (mc->nobjs) - kmem_cache_free(cache, mc->objects[--mc->nobjs]); + kmem_cache_free(mc->kmem_cache, mc->objects[--mc->nobjs]); } static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache, @@ -1115,25 +1113,22 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu) int r; r = mmu_topup_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache, - pte_list_desc_cache, 8 + PTE_PREFETCH_NUM); + 8 + PTE_PREFETCH_NUM); if (r) goto out; r = mmu_topup_memory_cache_page(&vcpu->arch.mmu_page_cache, 8); if (r) goto out; - r = mmu_topup_memory_cache(&vcpu->arch.mmu_page_header_cache, - mmu_page_header_cache, 4); + r = mmu_topup_memory_cache(&vcpu->arch.mmu_page_header_cache, 4); out: return r; } static void mmu_free_memory_caches(struct kvm_vcpu *vcpu) { - mmu_free_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache, - pte_list_desc_cache); + mmu_free_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache); mmu_free_memory_cache_page(&vcpu->arch.mmu_page_cache); - mmu_free_memory_cache(&vcpu->arch.mmu_page_header_cache, - mmu_page_header_cache); + mmu_free_memory_cache(&vcpu->arch.mmu_page_header_cache); } static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc) @@ -5679,6 +5674,9 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu) uint i; int ret; + vcpu->arch.mmu_pte_list_desc_cache.kmem_cache = pte_list_desc_cache; + vcpu->arch.mmu_page_header_cache.kmem_cache = mmu_page_header_cache; + vcpu->arch.mmu = &vcpu->arch.root_mmu; vcpu->arch.walk_mmu = &vcpu->arch.root_mmu; -- 2.26.0