From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 921251E4A9; Fri, 8 Mar 2024 17:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709920464; cv=none; b=QfYkj7EPPwr7QgzIvrjtNjrcZS6wszbCJqJeTe/Xgs0KaFXo9jDr2OPGOpEFUm6Gd4lypu1ieumJig/SgW9pAg2l/s/PXxzPtZ5EqNnm6CE60VNFEuAidji4yd+DeAHGsAfu6N8V6Hingy7WE0aZBeY0fpgrIlXJjtAJY7s1Ef0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709920464; c=relaxed/simple; bh=XTDBgV8u300JsMhzl1J3kH/u694G+TtTR7EwriVVNnY=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=EcXrssmuFDONd595P3+J2OLC9iyTbzbQVMhnMUgttCoKpBYS+moQvqqqmxfH0b+qoTVr80VvQJbvhUFnR5HgFp4pYz/MVtYiyyXVmn9MyXD3NR0aWWAeGz/BXlBk741KNeIQ2Pn3Ts66tJErnVytkWPVrtBi5nUSbKfN4aAOoYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fxbPq530; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fxbPq530" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27556C433F1; Fri, 8 Mar 2024 17:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709920464; bh=XTDBgV8u300JsMhzl1J3kH/u694G+TtTR7EwriVVNnY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fxbPq530X418y/lnp+f2Ysg5ehGiPcYvB1590PEmOhg/JgnRwvxDeh1+qS0XE5bYv UXNukxslcG88YyJXAu/G5Aa6s0G0/ap1L8Xbg5zHAqsMDbQ9eZknSM3HDVeY+p4OOB MlAWFNdBRV8iWajZeahsPMFLDVO6BpWwLk6zFjHoONG40w9mqWq4Ecme0FpIsyXZgS hwosj7aMZj4bKbdy9/gWy/XV8mkD/ppH65+TOFD6JHOQgf2LLyTCyj9RgnJ4tDDKPZ ajQ7I/Xfcz+xwjTfmcUq+YMrVO3cdu1oEdCvtAMNk8PpbocVKmiJe+RfmDN13La02L slsIiycvr1ivA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rieQH-00AnhP-Qm; Fri, 08 Mar 2024 17:54:22 +0000 Date: Fri, 08 Mar 2024 17:54:20 +0000 Message-ID: <86h6hg1uer.wl-maz@kernel.org> From: Marc Zyngier To: Joey Gouly Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Will Deacon , Catalin Marinas Subject: Re: [PATCH v2 11/13] KVM: arm64: nv: Add emulation for ERETAx instructions In-Reply-To: <20240308172059.GA1052268@e124191.cambridge.arm.com> References: <20240226100601.2379693-1-maz@kernel.org> <20240226100601.2379693-12-maz@kernel.org> <20240308172059.GA1052268@e124191.cambridge.arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: joey.gouly@arm.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, will@kernel.org, catalin.marinas@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 08 Mar 2024 17:20:59 +0000, Joey Gouly wrote: > > Phew.. [...] > Each function in this file is quite small, but there's certainly a lot of > complexity and background knowledge required to understand them! > > I spent quite some time on each part to see if it matches what I understood > from the Arm ARM. > > Reviewed-by: Joey Gouly Thanks a lot for putting up with it, much appreciated. > A side note / thing I considered. KVM doesn't currently handle ERET exceptions > from EL1. EL1 is ambiguous here. Is that EL1 from the PoV of the guest? > > 1. If an ERETA{A,B} were executed from a nested EL1 guest, that would be > trapped up to Host KVM at EL2. There are two possibilities for that (assuming EL1 from the PoV of a L1 guest): (1) this EL1 guest is itself a guest hypervisor (i.e. we are running an L1 guest which itself is using NV and running an L2 which itself is a hypervisor). In that case, ERET* would have to be trapped to EL2 and re-injected. Note that we do not support NV under NV. Yet... (2) the L2 guest is not a hypervisor (no recursive NV), but the L1 hypervisor has set HFGITR_EL2.ERET==1. We'd have to re-inject the exception into L1, just like in the precedent case. If neither HCR_EL2.NV nor HFGITR_EL2.ERET are set, then no ERET* gets trapped at all. Crucially, when running an L2 guest that doesn't isn't itself a hypervisor (no nested NV), we do not trap ERET* at all. In a way, the NV overhead is mostly when running L1. Once you run L2, the overhead "vanishes", to some extent (as long as you don't exit, because that's where the cost is). > 2. kvm_hyp_handle_eret() returns false since it's not from vEL2. Inside > kvm_handle_eret(), is_hyp_ctxt() is false so the exception is injected into > vEL2 (via kvm_inject_nested_sync()). > > 3. vEL2 gets the exception, kvm_hyp_handle_eret() returns false as before. > Inside kvm_handle_eret(), is_hyp_ctxt() is also false, so > kvm_inject_nested_sync() is called but now errors out since vcpu_has_nv() is > false. > > Is that flow right? Am I missing something? I'm not sure. The cases where ERET gets trapped are really limited to the above two cases. Thanks, M. -- Without deviation from the norm, progress is not possible.