Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp478690pxj; Wed, 2 Jun 2021 04:08:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxNa2BhTSkE4KxARsyQXcyK8CZmqY62NP5kuL51ozDx3GqSe6/cxNxphLE//BmflJxUDtX X-Received: by 2002:a92:2802:: with SMTP id l2mr3379529ilf.298.1622632129734; Wed, 02 Jun 2021 04:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622632129; cv=none; d=google.com; s=arc-20160816; b=CMU9y5+BqXpbAU7vygkaBQ5Mf24fwYgWQvD7WG2SYF3n0+yo2EpqQTYSYSVtKlBeVv cDLT3rNrMpn7wcFg2WzfZ86fIRzaD2vS9NjrySimHbYyAB6RLnn7pwNvkRBI90wFT8WK baaQilK9uKwjA5VCnRfZEIofV7//a6o1aamdRPFIPqWuvd7fN6tlOA8u+bI5yCxm7P+K TgDhXHwK6lbbqpc9PG22+E10Qlt4FvL0QWmicMRx0jxd6ldfR+4If1bZQFSJejXrTx1x yADd6+aqur3c5UiiUi5W/mSt8gdh1LqdLN92nW3YmXkxhxFtbuF+EBN8OPAI5Dww1O4F 9Eng== 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=QwU7eNpnhcnSNsCtdIpNIwPgvGDGJ4+rnF5GomWdPmY=; b=ZZy2K5GZhJW7ECf/hQUn4GimUiDGWpnh10y6gkgdhWxElmI9hTYDfmIOyr0TFYd53z pMe1rXIT/Ra91+sVDSqFRb2WyDckorPIoN2YHNY7yDMHgroQ6ga8/Lj3u3jvYqdLp7fN ymVTUZzO6Bwy18IrCx2b3ciwgxQGMzXHXwCG434ib63wNXfC+I1Aq0isbH/RQpx9V5Dr 1Vb5TKfMIjcKHpKIrhU4SB3pakA3JEGi5D28Z+Z0Pyxev9+LfEHakptVjipFswelFQnT yWWpTejSCLIcUlu0JYnqguVH2GgbThFHDdMhwjGuXhakWfJ+Sla75VUisBSHXFc+tk8o EKUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v1ylLqjA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si11782724ilp.48.2021.06.02.04.08.35; Wed, 02 Jun 2021 04:08:49 -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=@google.com header.s=20161025 header.b=v1ylLqjA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229964AbhFBLJo (ORCPT + 99 others); Wed, 2 Jun 2021 07:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbhFBLJm (ORCPT ); Wed, 2 Jun 2021 07:09:42 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734B1C06174A for ; Wed, 2 Jun 2021 04:07:58 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id a20so1916329wrc.0 for ; Wed, 02 Jun 2021 04:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QwU7eNpnhcnSNsCtdIpNIwPgvGDGJ4+rnF5GomWdPmY=; b=v1ylLqjAdoNf/H7w9k6hQe7WHAc3a2ZesvC3IRvLPZ1+tQRZac+5ne5v5FaCWj+y5C BxBVdNM5skbbGmZhDCRSWRz3Xt0A5h6zb4DZsNKbWib3299MD2oicnmoT1z9oz0cjrJ3 8kR2BfFD3YvzWy5mEPYEPl1uy4R86YjGrT17a/Puup3fQvY8kdPiuiv5h2H48v/v6dA/ 3FCz/EIjFp6BEePGVBUNTN6mngT9AhytfCRfcCjE0KXsPUsm5AoALDbB/jCiNoTbie29 OU2SyFWidQIIf65c44G8BW8zwbZe0H26U29sc2qkBI0unDdkQd9/SpRNhyyJzVXsPmI1 qi0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QwU7eNpnhcnSNsCtdIpNIwPgvGDGJ4+rnF5GomWdPmY=; b=lyE4dLiuIDTe27wsEYnY9IY4uolGe5oa1ejnIdwcxoXJwueOEfVsOqOFPa5Dk8x4+R pEuLOsv4YnGARIOq8xd4KUyWpdnv+x3XxSsgOTOKZ8ZnzPKUIR+ps6feUm39Wej6Slgw fdFE/KNV1juFq6r6vQL4d3h71idBAchAgVWxzZ7GDWJuWeQj/Bttwlm+wNl29hF0zmgM WWmkTszml3XVaflXHWcHzKwt0mDQpN708sKMuV7FxzN9Lo5TN4qoPdX7AqYx3zl/CcTd C/FEJhQZTNcGW6O8jHhIuKqh9x8Lj2Fm0QWVgTdAirg/DQk9UapUb+3Em6QJIB/EQ/xe s2CA== X-Gm-Message-State: AOAM533TkaWvJ71hK2xZOFso6TygwNNI3SNMoXrdBgl5kUzBbtLZOSU0 zpn92gJBbz1/PWI57JyAVbaJFw== X-Received: by 2002:a5d:6082:: with SMTP id w2mr7244022wrt.209.1622632076964; Wed, 02 Jun 2021 04:07:56 -0700 (PDT) Received: from google.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id z11sm6213182wrs.7.2021.06.02.04.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 04:07:56 -0700 (PDT) Date: Wed, 2 Jun 2021 11:07:53 +0000 From: Quentin Perret To: Yanan Wang Cc: Marc Zyngier , Will Deacon , Alexandru Elisei , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, yuzenghui@huawei.com Subject: Re: [PATCH v5 6/6] KVM: arm64: Distinguish cases of memcache allocations completely Message-ID: References: <20210415115032.35760-1-wangyanan55@huawei.com> <20210415115032.35760-7-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210415115032.35760-7-wangyanan55@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday 15 Apr 2021 at 19:50:32 (+0800), Yanan Wang wrote: > With a guest translation fault, the memcache pages are not needed if KVM > is only about to install a new leaf entry into the existing page table. > And with a guest permission fault, the memcache pages are also not needed > for a write_fault in dirty-logging time if KVM is only about to update > the existing leaf entry instead of collapsing a block entry into a table. > > By comparing fault_granule and vma_pagesize, cases that require allocations > from memcache and cases that don't can be distinguished completely. > > Signed-off-by: Yanan Wang > --- > arch/arm64/kvm/mmu.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index aa536392b308..9e35aa5d29f2 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -895,19 +895,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > gfn = fault_ipa >> PAGE_SHIFT; > mmap_read_unlock(current->mm); > > - /* > - * Permission faults just need to update the existing leaf entry, > - * and so normally don't require allocations from the memcache. The > - * only exception to this is when dirty logging is enabled at runtime > - * and a write fault needs to collapse a block entry into a table. > - */ > - if (fault_status != FSC_PERM || (logging_active && write_fault)) { > - ret = kvm_mmu_topup_memory_cache(memcache, > - kvm_mmu_cache_min_pages(kvm)); > - if (ret) > - return ret; > - } > - > mmu_seq = vcpu->kvm->mmu_notifier_seq; > /* > * Ensure the read of mmu_notifier_seq happens before we call > @@ -970,6 +957,18 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > else if (cpus_have_const_cap(ARM64_HAS_CACHE_DIC)) > prot |= KVM_PGTABLE_PROT_X; > > + /* > + * Allocations from the memcache are required only when granule of the > + * lookup level where the guest fault happened exceeds vma_pagesize, > + * which means new page tables will be created in the fault handlers. > + */ > + if (fault_granule > vma_pagesize) { > + ret = kvm_mmu_topup_memory_cache(memcache, > + kvm_mmu_cache_min_pages(kvm)); > + if (ret) > + return ret; > + } You're now doing the top-up in the kvm->mmu_lock critical section. Isn't this more or less what we try to avoid by using a memory cache? Thanks, Quentin