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 0BC0FC3DA7F for ; Wed, 31 Jul 2024 14:20:23 +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=wtkltHMOoKscYZMOmVn2PYuxjMfghN0KN4LB2QxwM0c=; b=uR8ISgX+0FpPyQwUcnDkvrJgxt LZJIKvc+YmOQX22zikc9WYPzh/jhJhd1OCmPVrX8MQdW2ljmdTagGDUFxxr4QCTExcVWiGTHuGyIM +CfR/HbXIwJZ3tZhZAxR3Ar6s7I5Qwez7ScAMUSxnzgj3/eAowM7sNBeyvlfsp4lHLuVbQknT0eTr 2PriM+TU0qJMO8X90UKmG6HMbHZherkwcmmKyBW/CFsYhS2w+uDsR2Mdu16zb1TevrDS4cly5KCB7 tYbv2PW7xpBGJBEHjNqyZjvrm1OOYJwMVLO8UbeuE2PORit+FnMwaSb1Me9w/RH+Q070MhVhOF1Z8 fv848AVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZABX-00000001Sdg-3LNQ; Wed, 31 Jul 2024 14:20:11 +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 1sZAB4-00000001SZD-3g4N for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 14:19:44 +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 8A9371007; Wed, 31 Jul 2024 07:20:07 -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 4068B3F5A1; Wed, 31 Jul 2024 07:19:40 -0700 (PDT) Date: Wed, 31 Jul 2024 15:19:37 +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> <86sevp25a7.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86sevp25a7.wl-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_071943_028319_186808DB X-CRM114-Status: GOOD ( 37.71 ) 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 Wed, Jul 31, 2024 at 12:02:24PM +0100, Marc Zyngier wrote: > On Wed, 31 Jul 2024 11:05:05 +0100, > Alexandru Elisei wrote: > > > > 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? > > I don't understand what you are referring to. AT traps and the guest's > HCR_EL2.VM are totally orthogonal, and are (or at least should be) > treated independently. I was referring to what happens when a guest is running at EL1 with virtual stage 2 enabled and that guest performs an AT instruction. If the stage 1 translation tables are not mapped at virtual stage 2, then KVM should inject a data abort in the guest hypervisor. But after thinking about it some more, I guess that's not something that needs AT trapping: if the stage 1 tables are not mapped in the physical stage 2 (because the level 1 hypervisor unmapped them from the virtual stage 2), then KVM will get a data abort, and then inject that back into the guest hypervisor. And as far as I can tell, KVM tracks IPAs becoming unmapped from virtual stage 2 by trapping TLBIs. So everything looks correct to me, sorry for the noise. > > But more importantly, there are a bunch of cases where you have no > other choice but trap, and that what I allude to when I say "because > we multiplex all the S1 translations on a single set of register". > > If I'm running the EL2 part of the guest, and that guest executes an > AT S1E1R while HCR_EL2.{E2H,TGE}={1,0}, it refers to the guest's EL1&0 > translation regime. I can't let the guest execute it, because it would > walk its view of the EL2&0 regime. So we need to trap, evaluate what > the guest is trying to do, and do the walk in the correct context (by > using the instructions or the SW walk). Yes, that looks correct to me. > > > > > - 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? > > This is already handled. The guest's HCR_EL2 is always folded into the > runtime configuration, and the resulting trap handled through the > existing trap routing infrastructure (see d0fc0a2519a6d, which added > the triaging of most traps resulting from HCR_EL2). That explains it then, thanks for digging out the commit id! Alex