Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp708142pxb; Thu, 15 Apr 2021 04:54:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoJiuYEuK5zM9fLmBCEFNfAElmL7kM8mMKwE6dBnv9/xQsaxmJb1F3YrB6CCVpT6pId2Dt X-Received: by 2002:a05:6402:94b:: with SMTP id h11mr3614951edz.180.1618487640650; Thu, 15 Apr 2021 04:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618487640; cv=none; d=google.com; s=arc-20160816; b=aNfWyIjfOa8bp1vLsduqeX1rkDpQczizlvSuIPylUYy6WJyc/4HLzU91jO+Looycwz Y+BDQQA4KIaTGykadqqqiaROiGAx3n8DOe2ROdihS8UgY30lI/IXrOPUBkhWs4GSGg5j jnvOcw1X8o1xyUdQkhHlmEY0b7CaePoW8L/molgobhhViii/5Ys7OfzpOlM6D6dc/Q4u fzXrXRl3sVPkcltV3pB+A5LlKZrcKbMi8Y+na68y254xc+/frjlzO12/L5BcFna6Knd6 zDBcBM7Lq5/bjGhx7g3AwyNsOFHTmSvkuvXQ9ptl1JyjLF0elVAwwqkClV9VmjAoK+Sw I2pw== 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=IukGuNTvROSjhe+Vy2C1r5vX+BRSkKYr1j7bl3RlkkQ=; b=LPl8fYLC+uwpmB75JtIFY48yUPRLE88T5VTOYtOWp+TAFIjMkvck5/52c7hCn2ugjv ObCG/RMDst4ypvEA6l1DpCXY404rL4XynDbCWj9awdAVAAj6OUQSQLmK5UXiXaco8K50 KTXARHlHJoLSTTo3R50Cb1YJnNUGF1HCYxDSn1E1xN8nn8PME4zRB9aeC5zhQKnPtamI oIRxC0ukhg9nyMUBk3gRe9xzIqSzUzP3+bKfENtL9jj+e9J9xGJEyP8I9C0kOiv2bnY1 JeApyvKfXhiT3Rp0C++R19bmk7h7WXGtmoJCckGwpSLagdPpnt5BW/Su1SiE8wiEpa73 h92g== 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 n6si2026815edq.492.2021.04.15.04.53.37; Thu, 15 Apr 2021 04:54: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 S232906AbhDOLvc (ORCPT + 99 others); Thu, 15 Apr 2021 07:51:32 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:16923 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232682AbhDOLvQ (ORCPT ); Thu, 15 Apr 2021 07:51:16 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FLd0W4RGXzlXKt; Thu, 15 Apr 2021 19:48:59 +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; Thu, 15 Apr 2021 19:50:41 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Quentin Perret" , Alexandru Elisei , , , , CC: Catalin Marinas , James Morse , Julien Thierry , "Suzuki K Poulose" , Gavin Shan , , , , Yanan Wang Subject: [PATCH v5 6/6] KVM: arm64: Distinguish cases of memcache allocations completely Date: Thu, 15 Apr 2021 19:50:32 +0800 Message-ID: <20210415115032.35760-7-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210415115032.35760-1-wangyanan55@huawei.com> References: <20210415115032.35760-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 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; + } + /* * Under the premise of getting a FSC_PERM fault, we just need to relax * permissions only if vma_pagesize equals fault_granule. Otherwise, -- 2.23.0