Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp264154pxf; Thu, 8 Apr 2021 02:33:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycGI41SsHi9iuHxJDGt/toGBUX9dscqkMa1kklIicqhFk0bfxJero9WMsgU4HRUdHnsTkV X-Received: by 2002:a17:902:dac2:b029:e6:30a6:4c06 with SMTP id q2-20020a170902dac2b02900e630a64c06mr6897611plx.65.1617874388462; Thu, 08 Apr 2021 02:33:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617874388; cv=none; d=google.com; s=arc-20160816; b=VKQvVfoS7y346Dig9rZIPAt04eUrM4zoV2OdlSrqh1RVl3I8NGcDssG9hV1aEN2+GI g6EPCTMtWXQof5Jl5JGdOsKjYtVAP5kT3AyhfYRqn3VRfAnB8NxiWj62pniVw918Seua 3jMoIedp8v8cN2FhNLrx/Usi9ug+MWKkJ12B+Glq8d606zdUBXLT5WTWKNW1MvjCqy+T YQI3pFK1YfltVKC8iwM4XzzywyvzRVZdNj32mSLPL2VjZpcxK/fcw53rZpCkZ2yA3gvG EcL6bq2SWSrUFsDJParh/HlSDfqOIDdthV8M5hAWTxljbQbIMmUYK6bfBhiVHJJUyo0G DCOw== 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=E8NNIXpgZP4LnCdaqynGgB4BZdx+1n+2wK60HyFCENU=; b=rcZxyrJ3Rvf+WsRO82NG2LRLq4cBd2ypqr0tsjcKftsC5K5kZah9rJpF/NFWjJae3f 5YJEhDW5xxWrH15Feakt8jaJ8XJHe1D43WUvF/9HRL9al3pwt5bVbYYBC4mJZHIv4tVr VruW5Ym3X5mLs9gdvn599Uv8H5W6S5YVWUkUod/39Evk5Yy6VJ5oBGI76QCZSD+LRkql oXkIKAj5jhv/B6D3RB8ppLEtRqgExj5dncfPFBQSOn+ePo9isCqXI02pOY40ui2gsuT2 yNCL3sKd0iipvrur4NN4TEKWXo7vgYgp42KOmkzn+/6HaRZkQV1j49Fbnnnib2OHCGEJ WXEw== 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 k6si1507385plt.139.2021.04.08.02.32.55; Thu, 08 Apr 2021 02:33:08 -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 S230506AbhDHJbg (ORCPT + 99 others); Thu, 8 Apr 2021 05:31:36 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3080 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbhDHJbe (ORCPT ); Thu, 8 Apr 2021 05:31:34 -0400 Received: from DGGEML404-HUB.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FGGBt1gFkzWVRR; Thu, 8 Apr 2021 17:27:50 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by DGGEML404-HUB.china.huawei.com (10.3.17.39) with Microsoft SMTP Server (TLS) id 14.3.498.0; Thu, 8 Apr 2021 17:31:19 +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.2106.2; Thu, 8 Apr 2021 17:31:18 +0800 Subject: Re: [RFC PATCH v3 2/2] KVM: arm64: Distinguish cases of memcache allocations completely To: Alexandru Elisei , Marc Zyngier , Will Deacon , Catalin Marinas , , , , CC: James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , Quentin Perret , , , References: <20210326031654.3716-1-wangyanan55@huawei.com> <20210326031654.3716-3-wangyanan55@huawei.com> <4348b555-2a38-6f00-8ef0-0d5fd801d753@arm.com> From: "wangyanan (Y)" Message-ID: <2f7872af-b5dc-9e81-574d-928849ad473c@huawei.com> Date: Thu, 8 Apr 2021 17:31:18 +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: <4348b555-2a38-6f00-8ef0-0d5fd801d753@arm.com> 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: dggeme704-chm.china.huawei.com (10.1.199.100) 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 On 2021/4/7 23:35, Alexandru Elisei wrote: > Hi Yanan, > > On 3/26/21 3:16 AM, 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 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; >> + } > As I explained in v1 [1], this looks correct to me. I still think that someone > else should have a look, but if Marc decides to pick up this patch as-is, he can > add my Reviewed-by: Alexandru Elisei . Thanks again for this, Alex! Hi Marc, Will, Any thoughts about this patch? Thanks, Yanan > [1] https://lore.kernel.org/lkml/2c65bff2-be7f-b20c-9265-939bc73185b6@arm.com/ > > Thanks, > > Alex > >> + >> /* >> * Under the premise of getting a FSC_PERM fault, we just need to relax >> * permissions only if vma_pagesize equals fault_granule. Otherwise, > .