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 6993DD3A678 for ; Tue, 29 Oct 2024 17:35: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:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID: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=xzkkuHcJAdCarQ1DZBUjrbYTIlPteyvNO1MGL5JwwK0=; b=oi8Qfm97A4q2zMFpzwl5Px/oNG 7rnNXHLb5zBnMoG7qeUlbTqLmnI9rkg2RungAUzWoMvEXHg82XdW3mbolHkLlsGxE0iXECw58PvbF EudDuYrZOIxds8g+3Ztz5wZgd1ypE/Ht7PqZg5kR1k5K+GU8kiA9zmnI58BWbt0Wjyp/eZwmB5DLR MI95q1/ce42EQvonIfDlQb/3aSZ69K3h7QbX5WU/s4J4MXljxS792t4edF+5mWULCd72PYBu5/39T ymjlrRrKaqO1JR7TfJ3a7VNmPBQeDDN/IXdq2hfvgTnSF2XpSwA8xS8WbcTjav2EPXtvku8scWL08 XSOHo6bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5q88-0000000FHhM-3F0e; Tue, 29 Oct 2024 17:35:44 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5oGM-0000000EwmZ-3AVj for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 15:36:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 5BE7AA42F09; Tue, 29 Oct 2024 15:34:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8EAFC4CEED; Tue, 29 Oct 2024 15:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216164; bh=u4B7caqf4bH9RcgIRvXgFiIuK4JMtpoAxmfZWBghb+A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DogrcRgc+kJY7DLNgDe5WLQ9m8eh1vlx9QExwfy7emgvXbKTnaa7jJ4ERvlwol8ti gwlblgJu/4t4/BJe3lGwD8UqfN0Ydul+iwcKQ/3zsya3jX/8YkJr3BuVwUvM3f8QiP y940Gv/y7bMdIi4SO/Bmyms4ctCg845FUL6dElY9PebiNuvCw/Ob1Cpvcuy3Px1iJJ Ttf/CVc2rUSxKcHy6EyWZNPej1UTUGfJUCQYqm2lPfmAY6WjllSRxAn+VH13SuZaC6 ebd8gTCjcBrrUkB7So3txykL+sTXQTP+lUg9PYhjXA3aJK+WO4HtgR+kbbTZXlxRPr 4ixNh9zfDqXjw== 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 1t5oGI-007yET-6C; Tue, 29 Oct 2024 15:36:02 +0000 Date: Tue, 29 Oct 2024 15:36:01 +0000 Message-ID: <86a5em3ori.wl-maz@kernel.org> From: Marc Zyngier To: Mark Rutland Cc: Ard Biesheuvel , puranjay@kernel.org, Arnd Bergmann , Arnd Bergmann , Alex =?UTF-8?B?QmVubsOp?= =?UTF-8?B?ZQ==?= , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Sumit Garg , puranjay12@gmail.com, Oliver Upton , Suzuki K Poulose , Joey Gouly , Zenghui Yu Subject: Re: Supporting KVM_GUESTDBG_BLOCKIRQ or something similar on ARM64 In-Reply-To: References: <86ed4031zh.wl-maz@kernel.org> <86bjz32q2q.wl-maz@kernel.org> 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.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) 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: mark.rutland@arm.com, ardb@kernel.org, puranjay@kernel.org, arnd@arndb.de, arnd@kernel.org, alex.bennee@linaro.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, sumit.garg@linaro.org, puranjay12@gmail.com, oliver.upton@linux.dev, suzuki.poulose@arm.com, joey.gouly@arm.com, zenghui.yu@linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_083606_973755_F4018DEA X-CRM114-Status: GOOD ( 45.20 ) 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 On Tue, 29 Oct 2024 13:57:53 +0000, Mark Rutland wrote: > > On Tue, Oct 29, 2024 at 11:00:24AM +0100, Ard Biesheuvel wrote: > > On Tue, 29 Oct 2024 at 10:53, Marc Zyngier wrote: > > > > > > On Tue, 29 Oct 2024 08:52:41 +0000, > > > Ard Biesheuvel wrote: > > > > > > > > On Mon, 28 Oct 2024 at 12:23, Marc Zyngier wrote: > > > > > > > > > > > Let's start a discussion about what needs to be done to support this on > > > > > > arm64. > > > > > > > > > > A good start would be to define the semantics of such a flag: > > > > > > > > > > - what should it affect? the vcpu you are single-stepping? all vcpu? > > > > > > > > > > - should userspace to know that interrupts are pending? > > > > > > > > > > - should this result in any effect on the guest's view of time? > > > > > > > > > > - what of interactions on the rest of the system (such as devices)? > > > > > > > > > > > > > Sorry to give a handwavy answer here, but approaching this from a > > > > usability PoV (like what Puranjay is doing), it is really about > > > > adhering to the principle of least surprise for the user. > > > > > > > > So in that sense, it is not really about blocking IRQs at all, as long > > > > as we step over them rather than into them. How that is achieved is > > > > not that relevant from the user PoV, and maybe KVM_GUESTDBG_BLOCKIRQ > > > > is not the right solution for ARM at all. > > > > > > I definitely sympathise with the goal, but there is no simple way to > > > let interrupts through while stepping (which is what your "step over" > > > implies): > > > > > > - the hypervisor (in general) doesn't interact with the guest delivery > > > and handling of interrupts -- this is either very opaque (list > > > registers) or completely invisible (direct injection) > > > > > > - replacing the step with a breakpoint after the stepped instruction > > > requires us to decode the guest instructions to handle branching > > > effects > > > > > > > Yeah, and we still want to take non-IRQ/FIQ exceptions, so this does > > not seem feasible to me. > > > > > One possible mechanism would be to: > > > > > > - while stepping, add breakpoints to the interrupt vectors for the EL > > > we are stepping (3 breakpoints for any of the 4 possible exception > > > groups), > > > > > > - when any interrupt breakpoint hits, clear all 3, place a breakpoint > > > on the instruction that was about to be single-stepped (pointed to > > > by SPSR) > > > > > > - run to completion, until the breakpoint hits > > > > > > - disable the breakpoint, reinstall the previous 3 interrupt > > > breakpoints > > > > > > - single-step, rinse, repeat > > > > > > But then I'm asking myself the question: why is this KVM's job? It > > > seems to me that this is what an external debugger would do when > > > interacting with HW on bare metal. > > > > > > So can we implement this as part of the debugger's state machine? > > > > > > > Which debugger is that? The GDB stub in QEMU? > > > > Setting a one-shot breakpoint on the address in SPSR when taking an > > IRQ exception seems like a reasonable approach to me. > > That doesn't work; an IRQ could be taken in the middle of a common > helper that's also used in IRQ context, so you'd take the breakpoint > within the IRQ. You could try to match a bunch of things like the SP and > so on, but that boils to do a bunch of heuristics rather than something > that's guarnateed to work... Hmmm. Yes, that's a pretty pathological case. > > More generally, the IRQ can preempt the running thread anyway, so: > > * The user cannot use this to trace a kernel thread reliabl , since that > can be switched out behind their back. > > * The user cannot use this to trace a CPU regardless of the running > thread, since they lose anything that happens under an IRQ. These are understood limitations, I expect, and would be a part of the contract between the debugger and the user when deciding to hide asynchronous exceptions. But if those limitations are not deemed acceptable (or not easily implementable by the debugger), then the only option we have is to block IRQ/FIQ the hard way. In a way, this is what the architecture provides when entering Debug state, where all asynchronous exceptions are ignored (H2.4.1). And that brings me back to my earlier set of question... Thanks, M. -- Without deviation from the norm, progress is not possible.