Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4214490ybg; Mon, 8 Jun 2020 02:00:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJTajq2OD3UWBEQyDGiNB6bWyMuyPoJ3OeAup+1kHRLq2mIZ9UE6YkojYaJcuKURqlRPfb X-Received: by 2002:a17:906:19c8:: with SMTP id h8mr20729675ejd.512.1591606837575; Mon, 08 Jun 2020 02:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591606837; cv=none; d=google.com; s=arc-20160816; b=pNPU48MwivGzcgEervbMmUZ9dL3hNpKYD6LAs4+oDm6Dcw/NMDP315zon1TEiuJyxj QfEdJASYEdUI0gjnHzXLEqnRGegJVUaOK/B5KlCUrB1TTUoBvc2c3Z8rh1b+9NtnZO4P 4KFyCRb09IV/lrdXS9vcrh2vnnrXxCF9zgfdxhaaoREl6KVIZWCx5ZvYKcTpz6BwW0Tp WfGHzeOcdqBJr8ADqYI4xP8ghqwfQ0O6tkhlgIMKi2CJVV4pldt02B8u4j50ugnsrKwK JP+hmMkDHuCj63kU5nlM76dGAHZJEtZlq3oUMmmn08t3BySvJ2vzYJQDstV9lcVlgtrO 5V5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZhUJIihNsOJBPcBzEUBiE7/iTHmbpkI3L5KiEBlzlAw=; b=JuLHLVzgNt0OeUbYiuYB7RzKCme5+M2VhmEfGEaoh6xbaWcoM5kKbLKClSJa8yO6Tx HXfkExsC1xZcgADXzAxndUgN4IwYkeSwI37fcgublRR5n6tbudYTmcZXYE3Uzjv0hHLC m/rvDBW06znLZBLloM1j1AlXpIqVCkFF59HFMbpsC0DhWPO8/sDY01cC/qcQNvd1Ig5V UfEB1DreFmbvu3tGreBfp/+uuizahHIsdIvD0XyJIfR+XpS2Ks+GzVr+tlfHFjdMcFpC f2MEkxazhyww/UxAQT8Yw0SUaHWVgasq7D3KUjyk3Mm5zws+JiXjlSWtOh6qrwiUtRQ1 4g4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y9+UtojW; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d16si8382647ejp.131.2020.06.08.02.00.13; Mon, 08 Jun 2020 02:00:37 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y9+UtojW; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729166AbgFHI5d (ORCPT + 99 others); Mon, 8 Jun 2020 04:57:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbgFHI5c (ORCPT ); Mon, 8 Jun 2020 04:57:32 -0400 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1BCEC08C5C4; Mon, 8 Jun 2020 01:57:31 -0700 (PDT) Received: by mail-il1-x143.google.com with SMTP id a13so15981423ilh.3; Mon, 08 Jun 2020 01:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZhUJIihNsOJBPcBzEUBiE7/iTHmbpkI3L5KiEBlzlAw=; b=Y9+UtojWa2WvofBKlqksrH2UxqOeor9ywSsTiV/vDSFGtDp5oN9ImT7jixVrCmdrv7 KqNvYCOlvk6+QKy0dRkO4iGrNI1kmjIN/u1NVSqW1i1b/KF63PcNOO/bFR5fou29C499 imfbf9MzdZyRbHyCiRH8irRF8ehZh/IUDpq6TclCsORYbkamGlPncs3p/d40LqM/8v0O +fDZsW+XFyhc934YqXtULIaXiGVuUIDbErtxW3Jcylu0nj4HGVsGOYIqFaPoNNpjmbZy 2J56AZj9w8fwtGQ2NO7AePx8m8uSEytRjzYL5oCw63lDRsB4J+xLIy9/+aw4NX/Oh//i Tqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZhUJIihNsOJBPcBzEUBiE7/iTHmbpkI3L5KiEBlzlAw=; b=WHeY0+r4m4nE9G/x683xsnmbknJAA8PUeEDr7lcw8ojSvRJ5wQf0oknqzk2mmWPqWe kJSh6QZ2GhH+hC1s04BjsnFjokILqb8KpQ4ypHb1e3EEzr84ll27LIE78N/MKdN0KELx a3h6TBa9oOlXQItS/PfgJ8WygUv5B/ecq7ILVEOyT/6NQjh6YeSCyazJd7ph0PFZJyjy mWeu8xsFvuvSt/JGLjQsRazJ0lduRxPib9xHZRVgzGY4F7GXksgEb8G2uvaYHEzLJo2r ZjLwAavJKTTwY6HUn55xrw0appCQJWeK3tyVrp7ezxTIeq9oiP2+FYeTFOECYaxAgueV AufQ== X-Gm-Message-State: AOAM532D6J6vIPVcXqhKHY+epFW5KqrlagWgzAymlGieEptz42As1kom bYhVaMpiZ9bYtDPX5RbPBbOQCnN0YGtHWZ7pVhg= X-Received: by 2002:a92:9f12:: with SMTP id u18mr20674915ili.287.1591606651183; Mon, 08 Jun 2020 01:57:31 -0700 (PDT) MIME-Version: 1.0 References: <20200605213853.14959-1-sean.j.christopherson@intel.com> <20200605213853.14959-22-sean.j.christopherson@intel.com> In-Reply-To: <20200605213853.14959-22-sean.j.christopherson@intel.com> From: Huacai Chen Date: Mon, 8 Jun 2020 16:57:20 +0800 Message-ID: Subject: Re: [PATCH 21/21] KVM: MIPS: Use common KVM implementation of MMU memory caches To: Sean Christopherson Cc: Marc Zyngier , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , James Morse , Julien Thierry , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel , kvmarm@lists.cs.columbia.edu, "open list:MIPS" , kvm , kvm-ppc@vger.kernel.org, LKML , Peter Feiner , Peter Shier , Junaid Shahid , Ben Gardon , Christoffer Dall Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reviewed-by: Huacai Chen On Sat, Jun 6, 2020 at 5:41 AM Sean Christopherson wrote: > > Move to the common MMU memory cache implementation now that the common > code and MIPS's existing code are semantically compatible. > > No functional change intended. > > Suggested-by: Christoffer Dall > Signed-off-by: Sean Christopherson > --- > arch/mips/include/asm/kvm_host.h | 11 --------- > arch/mips/include/asm/kvm_types.h | 2 ++ > arch/mips/kvm/mmu.c | 40 ++++--------------------------- > 3 files changed, 7 insertions(+), 46 deletions(-) > > diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h > index 363e7a89d173..f49617175f60 100644 > --- a/arch/mips/include/asm/kvm_host.h > +++ b/arch/mips/include/asm/kvm_host.h > @@ -335,17 +335,6 @@ struct kvm_mips_tlb { > long tlb_lo[2]; > }; > > -#define KVM_NR_MEM_OBJS 4 > - > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > #define KVM_MIPS_AUX_FPU 0x1 > #define KVM_MIPS_AUX_MSA 0x2 > > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > index 5efeb32a5926..213754d9ef6b 100644 > --- a/arch/mips/include/asm/kvm_types.h > +++ b/arch/mips/include/asm/kvm_types.h > @@ -2,4 +2,6 @@ > #ifndef _ASM_MIPS_KVM_TYPES_H > #define _ASM_MIPS_KVM_TYPES_H > > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 4 > + > #endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c > index 41a4a063a730..d6acd88c0c46 100644 > --- a/arch/mips/kvm/mmu.c > +++ b/arch/mips/kvm/mmu.c > @@ -25,39 +25,9 @@ > #define KVM_MMU_CACHE_MIN_PAGES 2 > #endif > > -static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, int min) > -{ > - void *page; > - > - if (cache->nobjs >= min) > - return 0; > - while (cache->nobjs < ARRAY_SIZE(cache->objects)) { > - page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT); > - if (!page) > - return -ENOMEM; > - cache->objects[cache->nobjs++] = page; > - } > - return 0; > -} > - > -static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc) > -{ > - while (mc->nobjs) > - free_page((unsigned long)mc->objects[--mc->nobjs]); > -} > - > -static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc) > -{ > - void *p; > - > - BUG_ON(!mc || !mc->nobjs); > - p = mc->objects[--mc->nobjs]; > - return p; > -} > - > void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu) > { > - mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); > + kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); > } > > /** > @@ -151,7 +121,7 @@ static pte_t *kvm_mips_walk_pgd(pgd_t *pgd, struct kvm_mmu_memory_cache *cache, > > if (!cache) > return NULL; > - new_pmd = mmu_memory_cache_alloc(cache); > + new_pmd = kvm_mmu_memory_cache_alloc(cache); > pmd_init((unsigned long)new_pmd, > (unsigned long)invalid_pte_table); > pud_populate(NULL, pud, new_pmd); > @@ -162,7 +132,7 @@ static pte_t *kvm_mips_walk_pgd(pgd_t *pgd, struct kvm_mmu_memory_cache *cache, > > if (!cache) > return NULL; > - new_pte = mmu_memory_cache_alloc(cache); > + new_pte = kvm_mmu_memory_cache_alloc(cache); > clear_page(new_pte); > pmd_populate_kernel(NULL, pmd, new_pte); > } > @@ -709,7 +679,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, > goto out; > > /* We need a minimum of cached pages ready for page table creation */ > - err = mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); > + err = kvm_mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); > if (err) > goto out; > > @@ -793,7 +763,7 @@ static pte_t *kvm_trap_emul_pte_for_gva(struct kvm_vcpu *vcpu, > int ret; > > /* We need a minimum of cached pages ready for page table creation */ > - ret = mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); > + ret = kvm_mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); > if (ret) > return NULL; > > -- > 2.26.0 >