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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23280C3DA64 for ; Wed, 31 Jul 2024 10:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3FbMTbCDZHAbUP0ZBRwb7i4YS4NAZE9UyCksHLTY3mc=; b=zE4+nQjqYRhwY9Mcm+7cG1SgFk 3BFcpdJw+fhJusjMwTDnaisfCCxOKD5WarNWsB9EIhP/XvF4d8oq1etnDNQM5DAv1jaBGWCY8R3QG GioPQ+9oCKT5tTTILXQtVoPD/jgaEMxZ35BHb/3zzN0f+/Xxgj+yqsGDjPwAU2o40Ua3BvMy5hquR 9nTICzXYVigCHy2ENxdHnA9J+70B0Jo3XSKf698y2tZBrkjAY/YE51PSdDJ+woEy+/K1guaK5KslS /UTn9zlWM7O2udjDN24o8dC8Aidrx3k2OcftNqDW1qVDHAZzwUt13wjDW/yQf9ihIOGizt6JATu+X w/Zes6yQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZ6DK-00000000fH2-13R8; Wed, 31 Jul 2024 10:05:46 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZ6Cl-00000000fBR-0MUx for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 10:05:15 +0000 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 49EBF1007; Wed, 31 Jul 2024 03:05:35 -0700 (PDT) Received: from raptor (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D7233F5A1; Wed, 31 Jul 2024 03:05:07 -0700 (PDT) Date: Wed, 31 Jul 2024 11:05:05 +0100 From: Alexandru Elisei To: Marc Zyngier Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: Re: [PATCH 00/12] KVM: arm64: nv: Add support for address translation instructions Message-ID: References: <20240625133508.259829-1-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240625133508.259829-1-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_030511_281030_4F8E7E38 X-CRM114-Status: GOOD ( 30.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Marc, On Tue, Jun 25, 2024 at 02:34:59PM +0100, Marc Zyngier wrote: > Another task that a hypervisor supporting NV on arm64 has to deal with > is to emulate the AT instruction, because we multiplex all the S1 > translations on a single set of registers, and the guest S2 is never > truly resident on the CPU. I'm unfamiliar with the state of NV support in KVM, but I thought I would have a look at when AT trapping is enabled. As far as I can tell, it's only enabled in vhe/switch.c::__activate_traps() -> compute_hcr() if is_hyp_ctct(vcpu). Found this by grep'ing for HCR_AT. Assuming the above is correct, I am curious about the following: - The above paragraph mentions guest's stage 2 (and the code takes that into consideration), yet when is_hyp_ctxt() is true it is likely that the guest stage 2 is not enabled. Are you planning to enable the AT trap based on virtual HCR_EL2.VM being set in a later series? - A guest might also set the HCR_EL2.AT bit in the virtual HCR_EL2 register. I suppose I have the same question, injecting the exception back into the guest is going to be handled in another series? Thanks, Alex > > So given that we lie about page tables, we also have to lie about > translation instructions, hence the emulation. Things are made > complicated by the fact that guest S1 page tables can be swapped out, > and that our shadow S2 is likely to be incomplete. So while using AT > to emulate AT is tempting (and useful), it is not going to always > work, and we thus need a fallback in the shape of a SW S1 walker. > > This series is built in 4 basic blocks: > > - Add missing definition and basic reworking > > - Dumb emulation of all relevant AT instructions using AT instructions > > - Add a SW S1 walker that is using our S2 walker > > - Add FEAT_ATS1A support, which is almost trivial > > This has been tested by comparing the output of a HW walker with the > output of the SW one. Obviously, this isn't bullet proof, and I'm > pretty sure there are some nasties in there. > > In a departure from my usual habit, this series is on top of > kvmarm/next, as it depends on the NV S2 shadow code. > > Joey Gouly (1): > KVM: arm64: make kvm_at() take an OP_AT_* > > Marc Zyngier (11): > arm64: Add missing APTable and TCR_ELx.HPD masks > arm64: Add PAR_EL1 field description > KVM: arm64: nv: Turn upper_attr for S2 walk into the full descriptor > KVM: arm64: nv: Honor absence of FEAT_PAN2 > KVM: arm64: nv: Add basic emulation of AT S1E{0,1}{R,W}[P] > KVM: arm64: nv: Add basic emulation of AT S1E2{R,W} > KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W} > KVM: arm64: nv: Make ps_to_output_size() generally available > KVM: arm64: nv: Add SW walker for AT S1 emulation > KVM: arm64: nv: Plumb handling of AT S1* traps from EL2 > KVM: arm64: nv: Add support for FEAT_ATS1A > > arch/arm64/include/asm/kvm_arm.h | 1 + > arch/arm64/include/asm/kvm_asm.h | 6 +- > arch/arm64/include/asm/kvm_nested.h | 18 +- > arch/arm64/include/asm/pgtable-hwdef.h | 7 + > arch/arm64/include/asm/sysreg.h | 19 + > arch/arm64/kvm/Makefile | 2 +- > arch/arm64/kvm/at.c | 1007 ++++++++++++++++++++++++ > arch/arm64/kvm/emulate-nested.c | 2 + > arch/arm64/kvm/hyp/include/hyp/fault.h | 2 +- > arch/arm64/kvm/nested.c | 26 +- > arch/arm64/kvm/sys_regs.c | 60 ++ > 11 files changed, 1125 insertions(+), 25 deletions(-) > create mode 100644 arch/arm64/kvm/at.c > > -- > 2.39.2 > >