Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp250969pxj; Thu, 3 Jun 2021 05:56:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn3nUKI9IZUKtWk0tR5WfGU+u+ma95XrAIzVi+FUpN4MQDfECgSHX/vJumW1PJoHIe1dyr X-Received: by 2002:a17:906:82c3:: with SMTP id a3mr2198797ejy.230.1622724993940; Thu, 03 Jun 2021 05:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622724993; cv=none; d=google.com; s=arc-20160816; b=N/dwKzGHDwFYWmAispvwcx5vyNieqbXVXQwMO6yJSaol9geIiiyaddVY/XDbw53T2m VHWfwI9ZEwagrft4+eW325uX9tNzTwcRWypx97gU6oW4HEdQP/tymFw/fH7hhTu6fQSo jtX6quI7dvlqkNHk9wjKBZoSjtl/8cEm4zRzQuWa7hOVMmYVjRt9lyChQaX+XmbUSCob ZAmeiUOi5tsM3lcMJOOJ74R7rFmiW/LtzLC0XteO2iRmB0UNoP7UV3H3OGvmPqe8Elhn sIjG8Qwdw7IKmSSbpmm2K1eYjI8iabDiKyVTG+17/QvtJHcG6f/nQUdLgwGYpjxaddg7 AgvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=lDRIpaDo/tIF2tnfrj2fe2NZGGMCQx2jmlPdbZ+Md54=; b=lALmnUYtgAN0ORklLsvruL9lCupor6WGhKVI1oSrwOwNnUbRF9YIeRMuPEllN7XlDX 5J8tL4RV9jZnvOKVxRrhrMMkSswBXUTbxHDNR4IkPxCEC3AtbL5BmICHdUzEAfS2bxpb SK+LAOR2Yl+2FvZal8m7DqkpvHdtWT/VhEo2T1touqVcgM7kxmCk9X6ttUp0+Rb3TbIk nnA2ZAK/+xB+GNnUNh0oW/yLtFpq29bUEoewGDrrGM97Vf5mbStPFnMpSdtuwLbHHTNY 0DnboZm9Qb/LUAC1fYdmXDoHh68clS+Ir2YXk76Nynoo+/XEI9dLv5SaoaxQruToHPHg k6IQ== 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 p17si2397650edq.63.2021.06.03.05.56.11; Thu, 03 Jun 2021 05:56:33 -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 S231211AbhFCMy0 (ORCPT + 99 others); Thu, 3 Jun 2021 08:54:26 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:4293 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbhFCMyZ (ORCPT ); Thu, 3 Jun 2021 08:54:25 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Fwlzt02B3z1BH07; Thu, 3 Jun 2021 20:47:54 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 3 Jun 2021 20:52:38 +0800 Received: from [10.174.187.128] (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Thu, 3 Jun 2021 20:52:37 +0800 Subject: Re: [PATCH v5 6/6] KVM: arm64: Distinguish cases of memcache allocations completely To: Quentin Perret CC: Marc Zyngier , Will Deacon , "Alexandru Elisei" , , , , , Catalin Marinas , James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , , , References: <20210415115032.35760-1-wangyanan55@huawei.com> <20210415115032.35760-7-wangyanan55@huawei.com> From: "wangyanan (Y)" Message-ID: <7412ce3d-1144-e2ba-d897-79b0059be453@huawei.com> Date: Thu, 3 Jun 2021 20:52:36 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggeme702-chm.china.huawei.com (10.1.199.98) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Quentin, On 2021/6/2 19:07, Quentin Perret wrote: > 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? Oh, right! This patch intended to clean up the code and avoid the unnecessary top-ups, but it's a bad idea to do the top-up when holding mmu_lock. I will rearrange this part and keep it where it should be. Thanks, Yanan > Thanks, > Quentin > .