Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1031483pxf; Thu, 8 Apr 2021 20:39:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhbCMtCjdoUDtMyOxVX7nst1VndvHp2yT7l0WBVNIg0wxd6DxILfBUcIRgIr9fL2OEb3KE X-Received: by 2002:a62:170e:0:b029:1fa:7161:fd71 with SMTP id 14-20020a62170e0000b02901fa7161fd71mr10279427pfx.35.1617939540772; Thu, 08 Apr 2021 20:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617939540; cv=none; d=google.com; s=arc-20160816; b=eKUt22FfqhpKdRka1wGgQ+SzWhMK9HKN6+RTSgYTRsc+KKl1dFfHoZ1fg2rV/h9Htm HgOGWp5hQLwLilE34VvzznVHLLajsapt/aQMD1N0xTUiMOlFO0WSBC6XDdteuBy1l6Q9 lEMnN7iws82v4bNIBDPwA5w4Tp5RQl20A1yVMhEU5GyQ655CjbL6RpCkFgOIw8nF9oEy ze4RB355twh1Gk3bqAqfxik9nEGBCYd/FzeznjILgP8WaGfYx4Fpr2EgKAdg5oYJaYUz LlhjEO4fBymVxvU8ztixaitOHOwKsINulwDDNlutkGTqhoeEeNdjhjzVF9L9I8gEe0Vs UUmA== 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=Xo+tHkH7NWtWZtg7Zb6zp+z55F4+refFcSoRPJEcHrM=; b=R1qIsh67X24KeC6yw7urL+ORLnEdDysD4uYM0PX2hhdArF8TZytAEdsrjfn+mL8vpT f7ZMoco9ybbp5hE8BLmEKEErc0AKUUoeSqMHJ2G1WkHC4aVQIv6ylvQr06viqfbx/0ON +WAN4ykuxSjufqrlpCaRT2GNFOwwlkcZmfDAw0kuTu7YgSct+jCIACW+i+AqZfYKuOLF lmTAJe3dMdcNVzGr7MGJ0hAM7Vu2go9qxPqxHX9760TmP7gmDYImjhbGMpi/HKAQqm7R a8T9zRBJVAyAOHB1tyyOd0xu8AS+79saTk202j7CKsZAc+8YM1jCot+HrsadZBX41Y3x B9dw== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s22si1646524pjz.66.2021.04.08.20.38.48; Thu, 08 Apr 2021 20:39:00 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbhDIDiS (ORCPT + 99 others); Thu, 8 Apr 2021 23:38:18 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15635 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232990AbhDIDiL (ORCPT ); Thu, 8 Apr 2021 23:38:11 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FGkJW4QMSznZ6Z; Fri, 9 Apr 2021 11:34:19 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Fri, 9 Apr 2021 11:36:57 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Alexandru Elisei" , Catalin Marinas , , , , CC: James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , Quentin Perret , , , , Yanan Wang Subject: [PATCH v4 2/2] KVM: arm64: Distinguish cases of memcache allocations completely Date: Fri, 9 Apr 2021 11:36:52 +0800 Message-ID: <20210409033652.28316-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210409033652.28316-1-wangyanan55@huawei.com> References: <20210409033652.28316-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, 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 1eec9f63bc6f..05af40dc60c1 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -810,19 +810,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 @@ -880,6 +867,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; + } + /* * 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