Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3075019pxb; Mon, 25 Jan 2021 06:24:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzP/ePAfrbvrjpgrZWnSHM8YwdijB96ywDfndq0QVzD/0X23RXBelTlaNGjfxuGcIkp54eo X-Received: by 2002:a17:906:538c:: with SMTP id g12mr540992ejo.248.1611584655489; Mon, 25 Jan 2021 06:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611584655; cv=none; d=google.com; s=arc-20160816; b=wifWQ/zWLqOUsH/hrR3QL9K2ux3S7QrhW0bUPZDOrtfX2wE9hxh9ZdiwBPnN967OV8 LGl1U/8Vev/CfTMtDZLdkA5ZUuI7fknFUbITqJ8bu2oBxP58Ith7b6kxiKkUxcPeoEqu dv30OdMEJ6TIMwFy1BHEe2G4gSYGtsrcEuh7p05u6ypVj5/8a4v4J9j2Nlgvyo4GshJc 6w9Q/4ymv2ignGbRQEFS3+4IYyyQLx3/9N8n9bQYE77MQfOe6Ghe2ZIDCKlfUyGRC7bE jgdOi1fLTSUl06qbu5TBy6+MIueAptTuhmE5Ze8TfwWPgwdbPMb6AVgfxb2pRoILCGji 4ykQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=UKKNk0Djbe/PZ1MnhtMQKGGKvuz9OimjMINX/gwBor0=; b=if0F6mrsxXDAbfyee+j/PpBJLa+jCqQh+6OjZuJ1vMqJY47eFxI4JJKLT2+55oG6pi 44UfoBObkXuAVSoGgjPdmVuCkVsMkqUlLv66PZvpG7TugFfnpM+Mlh51nNkrGPtGpO+H 6KBPEALNLbk4Fl+mb+G4Bvwrj9wuWcT065ruMldAcMeFJ/g5E07TJ/xMMmvBED3b+jZZ hgvsGuNfgtHGnppMhH2V0BjUuG+yNz1vjSIjb1+87yWOAHgvJZrkNjYQDcjJPDAfckqX LuZvOBDez2FeeQ6RgATmvcmUQYV1N7hnLImLpziktUXLBivzSv/3CaEWJ+W/QbIdbsKz r8NA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga14si6144735ejb.267.2021.01.25.06.23.49; Mon, 25 Jan 2021 06:24:15 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729151AbhAYOS0 (ORCPT + 99 others); Mon, 25 Jan 2021 09:18:26 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:11875 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729302AbhAYOLz (ORCPT ); Mon, 25 Jan 2021 09:11:55 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DPWvr4PrPz7Zrr; Mon, 25 Jan 2021 22:09:44 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Mon, 25 Jan 2021 22:10:47 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Catalin Marinas" , James Morse , "Julien Thierry" , Suzuki K Poulose , , , , CC: , , Yanan Wang Subject: [PATCH 1/2] KVM: arm64: Distinguish cases of allocating memcache more precisely Date: Mon, 25 Jan 2021 22:10:43 +0800 Message-ID: <20210125141044.380156-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210125141044.380156-1-wangyanan55@huawei.com> References: <20210125141044.380156-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With a guest translation fault, we don't really need the memcache pages when only installing a new entry to the existing page table or replacing the table entry with a block entry. And with a guest permission fault, we also don't need the memcache pages for a write_fault in dirty-logging time if VMs are not configured with huge mappings. The cases where allocations from memcache are required can be much more precisely distinguished by comparing fault_granule and vma_pagesize. 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 7d2257cc5438..8e8549ea1d70 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -820,19 +820,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 @@ -898,6 +885,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 a guest fault happened exceeds the 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; + } + /* * Under the premise of getting a FSC_PERM fault, we just need to relax * permissions only if vma_pagesize equals fault_granule. Otherwise, -- 2.19.1