Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp893144pxf; Wed, 7 Apr 2021 14:20:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOzrZ9MT8N4EtimeBnydqWfKGuw99znJGTHkH0//ft2oWkfGiQE6eZrodi3FvBP7RN9GFp X-Received: by 2002:a05:6e02:1ca7:: with SMTP id x7mr3562888ill.267.1617830440739; Wed, 07 Apr 2021 14:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617830440; cv=none; d=google.com; s=arc-20160816; b=PcBRH7Gd+aRKPKhMossz8OMj9ZA1aadXAWShSrMlmTxjhZ5BL33jKxkL7sxsfDlxkL ROBFJp9JEcBoOfbmWqCk4sI6pChrNrqgoD/9f0+4FLU0DwyaClWgsjDyj7ik6aFZjbx3 7wGt+ycQkQu9sRVXmptrF248+aYIzjQDvguqZLBxv+3OI/fvabd40piOehh2WaCEYs3s AGvKrfO86CFAMcimGFyWKNr71fBFt/bD9d5wMtebg7h83hBC9Vk3SyPBmu8v1Yi6V2qX L3bQQ+5M7zNCoftQCiGPk9UEAah26EEYPkKNVUrahpqjK5CKCc+k0vlHO4v5NH5/0hQ+ Ro1Q== 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=S5xSgi6Bwn/06uWx0xAgweNn8a1kIklBkEQdXX13Uao=; b=Xih0CdQx9WgG1qQk44G2y22q/4cKJOLAkFn2uw70KYKfVgoyOND1mixol3fx6i78Gy aH8uSi3ytEyxuHrfIYxRTh8YOFTLwcaWAQD4qXF5BwjNipZbG2UsZqgTmOL6gjvuD6H7 /+z6AfZOlVL7W8Qpzn7BYA6ocLYmvmyQM05rFL3uiMHuGzRglWdwecrk6NZoorpk1Yaf AjElXOeUB4yLEWz19//+SqDdaNx1Dt737ydABv0Sv9zczviOCC6XFingJdDLUPL5fQcw 0SJcI497WstdbE75XKRMbmxPsBr/jV4OIbivCRmDJ23av4uZbvU0CA7AD969feUsuTFe S0ww== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si583412ilu.67.2021.04.07.14.20.28; Wed, 07 Apr 2021 14:20:40 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245692AbhDGPfe (ORCPT + 99 others); Wed, 7 Apr 2021 11:35:34 -0400 Received: from foss.arm.com ([217.140.110.172]:59356 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbhDGPfd (ORCPT ); Wed, 7 Apr 2021 11:35:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 470861424; Wed, 7 Apr 2021 08:35:23 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 402603F792; Wed, 7 Apr 2021 08:35:21 -0700 (PDT) Subject: Re: [RFC PATCH v3 2/2] KVM: arm64: Distinguish cases of memcache allocations completely To: Yanan Wang , Marc Zyngier , Will Deacon , Catalin Marinas , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , Quentin Perret , wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, yuzenghui@huawei.com References: <20210326031654.3716-1-wangyanan55@huawei.com> <20210326031654.3716-3-wangyanan55@huawei.com> From: Alexandru Elisei Message-ID: <4348b555-2a38-6f00-8ef0-0d5fd801d753@arm.com> Date: Wed, 7 Apr 2021 16:35:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210326031654.3716-3-wangyanan55@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 . [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,