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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE780C001DF for ; Fri, 20 Oct 2023 19:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjJTT4j (ORCPT ); Fri, 20 Oct 2023 15:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjJTT4h (ORCPT ); Fri, 20 Oct 2023 15:56:37 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC01D52 for ; Fri, 20 Oct 2023 12:56:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF468C433C8; Fri, 20 Oct 2023 19:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697831795; bh=NEi38A+ZyZuP2q+k1dwMYaiAkpQJpDIG7wKFG/Rp0bo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vMyItrr9P52VmTSH7jcEA/S41cM3c+IXAHi7ZAhMRZxrya7KCWPCglUC5eYrVbQRG Nz/pIjSGedHyulbaeXMhXlyTMgARY0VABd+ixLMAzLnIjDmq6VEuNlgNzSunusl/II E/Sb6dztaLTfuHnZgYvu1Czak5CaGvzC6gQlVsiUqEyfgk70IxClA3q3Shq/VVSPbo 56Uk5Tpqajet+eoOmuQDZlJ2ytmly3Cyg6NOaSNPLiC/95UaYX50UCptzbHUw+P1Vg lO5ifYv2sB6iMNRtv93g61hDB5dACN7JbRRbEq2ZFKZyz0MkTYGbSBp1yWpCA4unud 86cSmh5chsEUA== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.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 1qtvbl-006Dwn-5a; Fri, 20 Oct 2023 20:56:33 +0100 Date: Fri, 20 Oct 2023 20:56:32 +0100 Message-ID: <87ttql5aq7.wl-maz@kernel.org> From: Marc Zyngier To: Jan Henrik Weinstock Cc: oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Lukas =?UTF-8?B?SsO8bmdlcg==?= Subject: Re: KVM exit to userspace on WFI In-Reply-To: References: 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/28.2 (x86_64-pc-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: jan@mwa.re, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, lukas@mwa.re X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jan, On Fri, 20 Oct 2023 19:45:05 +0100, Jan Henrik Weinstock wrote: > > Hi all, > > I am looking for a way to have KVM_RUN exit back to userspace once the > vcpu encounters a WFI. It seems the kvm_run->request_interrupt_window > flag is currently ignored by arm64. Well, that's consistent with arm64 not being an x86 implementation. We can inject interrupts any time, and there is no notion of "interrupt window". > So my solution thus far is to > patch kvm_handle_wfx in arch/arm64/kvm/handle_exit.c and return to > userspace with KVM_EXIT_IRQ_WINDOW_OPEN - working example attached. > Any chance to get this (or something similar) mainline? Certainly not as such. For start, this won't hit all WFIs, but only those that actively trap. And we don't even *try* to trap WFx in a number of cases (vcpu alone in its run queue and/or direct injection). There isn't even any guarantee that WFx is anything other than a NOP (it is architecturally only a hint), in which case no trap applies. So your "working example" really isn't one, as the architecture doesn't give you a way to do what you're asking for. If you want to cause an exit, writing to 'immediate_exit' and delivering a signal is the way. Thanks, M. -- Without deviation from the norm, progress is not possible.