From: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
To: Marc Zyngier <maz@kernel.org>
Cc: kvmarm <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
Subject: Re: [PATCH] KVM: arm64: nv: Set ISTATUS for emulated timers, If timer expired
Date: Tue, 10 Dec 2024 18:18:04 +0530 [thread overview]
Message-ID: <20a6d0d5-2733-4959-a9a1-bc6c2e64111f@os.amperecomputing.com> (raw)
In-Reply-To: <865xntt2kv.wl-maz@kernel.org>
> Please give the fixup below a go.
>
> M.
>
> [1] https://lore.kernel.org/all/20241202172134.384923-6-maz@kernel.org/
>
> From 2bbd6f9b41a20ad573376c20c158ff3c12db5009 Mon Sep 17 00:00:00 2001
> From: Marc Zyngier <maz@kernel.org>
> Date: Mon, 9 Dec 2024 10:58:08 +0000
> Subject: [PATCH] fixup! KVM: arm64: nv: Publish emulated timer interrupt state
> in the in-memory state
>
> ---
> arch/arm64/kvm/arch_timer.c | 32 +++++++++++++-------------------
> 1 file changed, 13 insertions(+), 19 deletions(-)
>
> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index 895f09658ef83..91bda986c344b 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -432,25 +432,6 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
> {
> int ret;
>
> - /*
> - * Paper over NV2 brokenness by publishing the interrupt status
> - * bit. This still results in a poor quality of emulation (guest
> - * writes will have no effect until the next exit).
> - *
> - * But hey, it's fast, right?
> - */
> - if (is_hyp_ctxt(vcpu) &&
> - (timer_ctx == vcpu_vtimer(vcpu) || timer_ctx == vcpu_ptimer(vcpu))) {
> - u32 ctl = timer_get_ctl(timer_ctx);
> -
> - if (new_level)
> - ctl |= ARCH_TIMER_CTRL_IT_STAT;
> - else
> - ctl &= ~ARCH_TIMER_CTRL_IT_STAT;
> -
> - timer_set_ctl(timer_ctx, ctl);
> - }
> -
> timer_ctx->irq.level = new_level;
> trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_irq(timer_ctx),
> timer_ctx->irq.level);
> @@ -471,6 +452,19 @@ static void timer_emulate(struct arch_timer_context *ctx)
>
> trace_kvm_timer_emulate(ctx, should_fire);
>
> + /*
> + * Paper over NV2 brokenness by publishing the interrupt status
> + * bit. This still results in a poor quality of emulation (guest
> + * writes will have no effect until the next exit).
> + *
> + * But hey, it's fast, right?
> + */
> + if (is_hyp_ctxt(ctx->vcpu)) {
> + unsigned long val = timer_get_ctl(ctx);
> + __assign_bit(__ffs(ARCH_TIMER_CTRL_IT_STAT), &val, should_fire);
> + timer_set_ctl(ctx, val);
> + }
> +
> if (should_fire != ctx->irq.level) {
> kvm_timer_update_irq(ctx->vcpu, should_fire, ctx);
> return;
I tried this patch and it did not work, looks like there are some
exit/entry paths which updates timer interrupt without going though
timer_emulate (like kvm_hrtimer_expire). If I undo the deleted lines in
above diff in the function kvm_timer_update_irq, then it is working.
below is the diff which is working.
diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index dd038d62e99b..a54bdb6dc566 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -432,23 +432,11 @@ static void kvm_timer_update_irq(struct kvm_vcpu
*vcpu, bool new_level,
{
int ret;
- /*
- * Paper over NV2 brokenness by publishing the interrupt status
- * bit. This still results in a poor quality of emulation (guest
- * writes will have no effect until the next exit).
- *
- * But hey, it's fast, right?
- */
if (is_hyp_ctxt(vcpu) &&
(timer_ctx == vcpu_vtimer(vcpu) || timer_ctx ==
vcpu_ptimer(vcpu))) {
- u32 ctl = timer_get_ctl(timer_ctx);
-
- if (new_level)
- ctl |= ARCH_TIMER_CTRL_IT_STAT;
- else
- ctl &= ~ARCH_TIMER_CTRL_IT_STAT;
-
- timer_set_ctl(timer_ctx, ctl);
+ unsigned long val = timer_get_ctl(timer_ctx);
+ __assign_bit(__ffs(ARCH_TIMER_CTRL_IT_STAT), &val,
new_level);
+ timer_set_ctl(timer_ctx, val);
}
timer_ctx->irq.level = new_level;
@@ -471,6 +459,19 @@ static void timer_emulate(struct arch_timer_context
*ctx)
trace_kvm_timer_emulate(ctx, should_fire);
+ /*
+ * Paper over NV2 brokenness by publishing the interrupt status
+ * bit. This still results in a poor quality of emulation (guest
+ * writes will have no effect until the next exit).
+ *
+ * But hey, it's fast, right?
+ */
+ if (is_hyp_ctxt(ctx->vcpu)) {
+ unsigned long val = timer_get_ctl(ctx);
+ __assign_bit(__ffs(ARCH_TIMER_CTRL_IT_STAT), &val,
should_fire);
+ timer_set_ctl(ctx, val);
+ }
+
if (should_fire != ctx->irq.level) {
kvm_timer_update_irq(ctx->vcpu, should_fire, ctx);
return;
@@ -948,9 +949,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 2c35e1f8193e..52a263e7dcca 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1238,7 +1238,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
if (static_branch_unlikely(&userspace_irqchip_in_use))
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);
--
Thanks,
Ganapat/GK
next prev parent reply other threads:[~2024-12-10 12:48 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 5:32 Ganapatrao Kulkarni
2024-12-09 9:54 ` Marc Zyngier
2024-12-09 12:25 ` Ganapatrao Kulkarni
2024-12-09 13:20 ` Marc Zyngier
2024-12-09 15:23 ` Marc Zyngier
2024-12-09 15:39 ` Ganapatrao Kulkarni
2024-12-09 15:52 ` Marc Zyngier
2024-12-09 16:46 ` Eric Auger
2024-12-09 17:30 ` Marc Zyngier
2024-12-09 17:34 ` Eric Auger
2024-12-19 9:30 ` Ganapatrao Kulkarni
2024-12-19 12:23 ` Marc Zyngier
2025-01-14 13:12 ` Eric Auger
2025-01-14 14:38 ` Marc Zyngier
2025-01-14 14:57 ` Eric Auger
2025-01-14 15:52 ` Marc Zyngier
2025-01-16 17:52 ` Eric Auger
2025-01-16 18:25 ` Marc Zyngier
2025-02-07 17:45 ` Marc Zyngier
2025-02-07 18:09 ` Oliver Upton
2025-02-07 18:38 ` Marc Zyngier
2025-02-07 19:08 ` Oliver Upton
2025-02-10 18:26 ` Eric Auger
2025-02-11 19:20 ` Marc Zyngier
2025-02-15 17:50 ` Marc Zyngier
2025-02-18 7:33 ` Ganapatrao Kulkarni
2025-02-18 16:33 ` Marc Zyngier
2025-02-18 21:24 ` Marc Zyngier
2025-02-20 6:10 ` Ganapatrao Kulkarni
2025-02-10 13:18 ` Eric Auger
2024-12-10 12:48 ` Ganapatrao Kulkarni [this message]
2024-12-09 19:36 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20a6d0d5-2733-4959-a9a1-bc6c2e64111f@os.amperecomputing.com \
--to=gankulkarni@os.amperecomputing.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.com \
--cc=coltonlewis@google.com \
--cc=darren@os.amperecomputing.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=vishnu@os.amperecomputing.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®