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 DD1F0E7717D for ; Mon, 9 Dec 2024 15:24:46 +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=HfV1MPzGq9XAT2D8DZ5rKOMDGcmwRsvxP6+TFsJEblU=; b=qvsEHnSLrgQegNd/y4iaaup7Ww pJQwdtz3fmjSyXNOO0wee6JljmmgxwiHes0A8xETQ0A/EkLwsICZfUFF5nbTcGYvS8WmYNsCGtnrr QPvv5t9Bb1bsJMTmSjNOpPOmbIC9WVT27UWnBpXVFd8SniwwF6chjs3tjuXiGBSLJkAKI27vbmZuP HaUFXd7k1b70aRun1vEW4+k7RXt94q7feHwRvDs5OY/YAus2mWm7qSywf7fPH1LGoHyvXU0Usnbtf J+YtJ7jTaFH62ddOothU6us2+OqHpwEEs3m51NkAGO/u36HUa7ZBujbU4pR4dyjEx7RJD6LHkbvSY rzDVW5Ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKfch-00000008NW2-35Ak; Mon, 09 Dec 2024 15:24:35 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKfbf-00000008NJN-1OHv for linux-arm-kernel@lists.infradead.org; Mon, 09 Dec 2024 15:23:32 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 132C3A40D18; Mon, 9 Dec 2024 15:21:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4130DC4CED1; Mon, 9 Dec 2024 15:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733757810; bh=KqvUAHtm3J6eCMmXZ+bSvIdzAZallzTuC51lAI5H8dc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MTPHwSWOpruDhkz/BsphPDA+PiRFODp/9H1eta80wwvbMbAm3WM/1ZBERyhSQr9W/ VzFJ1sXm5kOJKtp397D8Cb/Hsm5VdkiLKtBlL+bsmuqke/YfVKIaCuo0HMvCfHqKLY Ue5VcIvwgs3e6wzmHNYRNsH4RAenLMinMrlqogbXrLT5FjzSUzxyt5yYdYzSzAmO9T YF/93YJlLpwL+V6/ekZEjtZGMRfHrk765oz5IpAqqwL9QVAMlsSKZxD56RPpVCFJR0 mbUvjmajrslQ5r3dre95D4Ui6E2sDksr/P9MuuIX3ULVp8j3pKvZlytn9z4C5KbgZc +m8THVr3084Pg== 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 1tKfbb-001vXl-Ou; Mon, 09 Dec 2024 15:23:27 +0000 Date: Mon, 09 Dec 2024 15:23:27 +0000 Message-ID: <8634iwubgw.wl-maz@kernel.org> From: Marc Zyngier To: Ganapatrao Kulkarni Cc: kvmarm , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, christoffer.dall@arm.com, suzuki.poulose@arm.com, will@kernel.org, catalin.marinas@arm.com, coltonlewis@google.com, joey.gouly@arm.com, yuzenghui@huawei.com, darren@os.amperecomputing.com, vishnu@os.amperecomputing.com Subject: Re: [PATCH] KVM: arm64: nv: Set ISTATUS for emulated timers, If timer expired In-Reply-To: <865xntt2kv.wl-maz@kernel.org> References: <20241209053201.339939-1-gankulkarni@os.amperecomputing.com> <867c89tc4q.wl-maz@kernel.org> <865xntt2kv.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: gankulkarni@os.amperecomputing.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, christoffer.dall@arm.com, suzuki.poulose@arm.com, will@kernel.org, catalin.marinas@arm.com, coltonlewis@google.com, joey.gouly@arm.com, yuzenghui@huawei.com, darren@os.amperecomputing.com, vishnu@os.amperecomputing.com 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-20241209_072331_500424_A0BA6A28 X-CRM114-Status: GOOD ( 24.41 ) 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 Mon, 09 Dec 2024 13:20:48 +0000, Marc Zyngier wrote: > > So here's my current guess, since you don't give me the needed > information. For what you describe to happen, I can only see two > possibilities: > > - either your HW doesn't have FEAT_ECV, in which case the guest > directly reads from memory > > - or you are running with something like this patch [1], and we serve > the guest by reading from memory very early, without returning to > the bulk of the emulation code > > In either case, we only publish the updated status if the current IRQ > state is different from the computed output of the timer while > performing the emulation. > > So if you were writing back a status bit set to 0 while the interrupt > was already pending, we'd deliver an interrupt, but not recompute the > status. The guest would consider the interrupt as spurious, not touch > the timer, and we'd never make forward progress. Rinse, repeat. > > Assuming I got the analysis right, it would only be a matter of > hoisting the publication of the status into timer_emulate(), so that > it is made up to date on load. > > Please give the fixup below a go. Plus this on top for a good measure: diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 91bda986c344b..c71193a7bb9c5 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -968,9 +968,6 @@ void kvm_timer_sync_nested(struct kvm_vcpu *vcpu) * which allows trapping of the timer registers even with NV2. * Still, this is still worse than FEAT_NV on its own. Meh. */ - if (cpus_have_final_cap(ARM64_HAS_ECV) || !is_hyp_ctxt(vcpu)) - return; - if (!vcpu_el2_e2h_is_set(vcpu)) { /* * A non-VHE guest hypervisor doesn't have any direct access diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index ff62b8b55b46e..1b8bb30dbb2ff 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1257,7 +1257,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) if (unlikely(!irqchip_in_kernel(vcpu->kvm))) kvm_timer_sync_user(vcpu); - if (vcpu_has_nv(vcpu)) + if (is_hyp_ctxt(vcpu)) kvm_timer_sync_nested(vcpu); kvm_arch_vcpu_ctxsync_fp(vcpu); M. -- Without deviation from the norm, progress is not possible.