From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66DDBC64E8A for ; Mon, 30 Nov 2020 13:50:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0033A207BC for ; Mon, 30 Nov 2020 13:50:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ksN9oKvC"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cy/lP/cz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0033A207BC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AgUVDMi8xcPm7a9NI2m6mFhZSUkaN8xi0qTC5sBRoZY=; b=ksN9oKvCbAN9P6G2OIpnn165h TfMSGbCx7JfLYO8pDy8momXmtc4akuqEmyRp1W2DLqhCgjidTy8M21JqPTP5xJoXioC9+4TaU3Qd1 tuF0deJQtW9Y7Fj4r+Bca33H+hYc2JzwrVh//gju3BosqPNuxIAlcJ3bbgcxmijhR+FQfSzIlL8dv E9oOOyVUOL3Ak7tZ+rXhlJUjNR8rrY30+5GtPQRTRpR+m0fj+jiOdWDRDBmeo/NPk/WBwJfYVyJlj tFI/eJRKmIbfqt3u4LZ/Ax43ry6QWudMmX0gDd+a+nGahHGU9SFpcf9X/z2Z30dJ3EPUYHuFE1Hj+ 9GD92ed/A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjjYS-0006Nw-4L; Mon, 30 Nov 2020 13:49:24 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjjYO-0006NG-VY for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2020 13:49:21 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07A69206F9; Mon, 30 Nov 2020 13:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606744160; bh=2uoGPoXnC43iKsKDzv0Q4KMQ6DR5H912lU9Q1Pz8A8U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Cy/lP/cz+FfYPEDMpjaPKxh8M17ujOWAxcr5T0nWw5/JG3bMoJTpN28mYnBtCi3wZ xdKj8xVHwldOmrftM3xBuDX9aABurLhy9odovdz2DnQrumhGDGC0QHErsIcGqrkP1n LeSSFWAH6e7YnCuCHBYe4Uzm4hQ1WGwbnXbaGrlU= Date: Mon, 30 Nov 2020 13:49:13 +0000 From: Will Deacon To: Yanan Wang Subject: Re: [RFC PATCH 3/3] KVM: arm64: Add usage of stage 2 fault lookup level in user_mem_abort() Message-ID: <20201130134913.GC24837@willie-the-truck> References: <20201130121847.91808-1-wangyanan55@huawei.com> <20201130121847.91808-4-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201130121847.91808-4-wangyanan55@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_084921_293048_64DE4F88 X-CRM114-Status: GOOD ( 27.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jiangkunkun@huawei.com, Gavin Shan , Suzuki K Poulose , Marc Zyngier , wangjingyi11@huawei.com, Quentin Perret , lushenming@huawei.com, linux-kernel@vger.kernel.org, yezengruan@huawei.com, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , yuzenghui@huawei.com, wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 30, 2020 at 08:18:47PM +0800, Yanan Wang wrote: > If we get a FSC_PERM fault, just using (logging_active && writable) to determine > calling kvm_pgtable_stage2_map(). There will be two more cases we should consider. > > (1) After logging_active is configged back to false from true. When we get a > FSC_PERM fault with write_fault and adjustment of hugepage is needed, we should > merge tables back to a block entry. This case is ignored by still calling > kvm_pgtable_stage2_relax_perms(), which will lead to an endless loop and guest > panic due to soft lockup. > > (2) We use (FSC_PERM && logging_active && writable) to determine collapsing > a block entry into a table by calling kvm_pgtable_stage2_map(). But sometimes > we may only need to relax permissions when trying to write to a page other than > a block. In this condition, using kvm_pgtable_stage2_relax_perms() will be fine. > > The ISS filed bit[1:0] in ESR_EL2 regesiter indicates the stage2 lookup level > at which a D-abort or I-abort occured. By comparing granule of the fault lookup > level with vma_pagesize, we can strictly distinguish conditions of calling > kvm_pgtable_stage2_relax_perms() or kvm_pgtable_stage2_map(), and the above > two cases will be well considered. > > Suggested-by: Keqian Zhu > Signed-off-by: Yanan Wang > --- > arch/arm64/include/asm/esr.h | 1 + > arch/arm64/include/asm/kvm_emulate.h | 5 +++++ > arch/arm64/kvm/mmu.c | 11 +++++++++-- > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h > index 22c81f1edda2..85a3e49f92f4 100644 > --- a/arch/arm64/include/asm/esr.h > +++ b/arch/arm64/include/asm/esr.h > @@ -104,6 +104,7 @@ > /* Shared ISS fault status code(IFSC/DFSC) for Data/Instruction aborts */ > #define ESR_ELx_FSC (0x3F) > #define ESR_ELx_FSC_TYPE (0x3C) > +#define ESR_ELx_FSC_LEVEL (0x03) > #define ESR_ELx_FSC_EXTABT (0x10) > #define ESR_ELx_FSC_SERROR (0x11) > #define ESR_ELx_FSC_ACCESS (0x08) > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 5ef2669ccd6c..2e0e8edf6306 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -350,6 +350,11 @@ static __always_inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vc > return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_TYPE; > } > > +static __always_inline u8 kvm_vcpu_trap_get_fault_level(const struct kvm_vcpu *vcpu) > +{ > + return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_LEVEL; > +{ > + > static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu) > { > switch (kvm_vcpu_trap_get_fault(vcpu)) { > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 1a01da9fdc99..75814a02d189 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -754,10 +754,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > gfn_t gfn; > kvm_pfn_t pfn; > bool logging_active = memslot_is_logging(memslot); > - unsigned long vma_pagesize; > + unsigned long fault_level = kvm_vcpu_trap_get_fault_level(vcpu); > + unsigned long vma_pagesize, fault_granule; > enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; > struct kvm_pgtable *pgt; > > + fault_granule = 1UL << ARM64_HW_PGTABLE_LEVEL_SHIFT(fault_level); I like the idea, but is this macro reliable for stage-2 page-tables, given that we could have a concatenated pgd? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel