All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Cc: scott@os.amperecomputing.com, kvm@vger.kernel.org,
	catalin.marinas@arm.com, keyur@os.amperecomputing.com,
	will@kernel.org, kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/3] KVM: arm64: nv: only emulate timers that have not yet fired
Date: Thu, 29 Dec 2022 13:00:55 +0000	[thread overview]
Message-ID: <87zgb6e54o.wl-maz@kernel.org> (raw)
In-Reply-To: <20220824060304.21128-2-gankulkarni@os.amperecomputing.com>

On Wed, 24 Aug 2022 07:03:02 +0100,
Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> wrote:
> 
> From: D Scott Phillips <scott@os.amperecomputing.com>
> 
> The timer emulation logic goes into an infinite loop when the NestedVM(L2)
> timer is being emulated.
> 
> While the CPU is executing in L1 context, the L2 timers are emulated using
> host hrtimer. When the delta of cval and current time reaches zero, the
> vtimer interrupt is fired/forwarded to L2, however the emulation function
> in Host-Hypervisor(L0) is still restarting the hrtimer with an expiry time
> set to now, triggering hrtimer to fire immediately and resulting in a
> continuous trigger of hrtimer and endless looping in the timer emulation.
> 
> Adding a fix to avoid restarting of the hrtimer if the interrupt is
> already fired.
> 
> Signed-off-by: D Scott Phillips <scott@os.amperecomputing.com>
> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
> ---
>  arch/arm64/kvm/arch_timer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index 2371796b1ab5..27a6ec46803a 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -472,7 +472,8 @@ static void timer_emulate(struct arch_timer_context *ctx)
>  		return;
>  	}
>  
> -	soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
> +	if (!ctx->irq.level)
> +		soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
>  }
>  
>  static void timer_save_state(struct arch_timer_context *ctx)

I think this is a regression introduced by bee038a67487 ("KVM:
arm/arm64: Rework the timer code to use a timer_map"), and you can see
it because the comment in this function doesn't make much sense
anymore.

Does the following work for you, mostly restoring the original code?

Thanks,

	M.

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index ad2a5df88810..4945c5b96f05 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -480,7 +480,7 @@ static void timer_emulate(struct arch_timer_context *ctx)
 	 * scheduled for the future.  If the timer cannot fire at all,
 	 * then we also don't need a soft timer.
 	 */
-	if (!kvm_timer_irq_can_fire(ctx)) {
+	if (should_fire || !kvm_timer_irq_can_fire(ctx)) {
 		soft_timer_cancel(&ctx->hrtimer);
 		return;
 	}

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Cc: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	scott@os.amperecomputing.com, keyur@os.amperecomputing.com
Subject: Re: [PATCH 1/3] KVM: arm64: nv: only emulate timers that have not yet fired
Date: Thu, 29 Dec 2022 13:00:55 +0000	[thread overview]
Message-ID: <87zgb6e54o.wl-maz@kernel.org> (raw)
In-Reply-To: <20220824060304.21128-2-gankulkarni@os.amperecomputing.com>

On Wed, 24 Aug 2022 07:03:02 +0100,
Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> wrote:
> 
> From: D Scott Phillips <scott@os.amperecomputing.com>
> 
> The timer emulation logic goes into an infinite loop when the NestedVM(L2)
> timer is being emulated.
> 
> While the CPU is executing in L1 context, the L2 timers are emulated using
> host hrtimer. When the delta of cval and current time reaches zero, the
> vtimer interrupt is fired/forwarded to L2, however the emulation function
> in Host-Hypervisor(L0) is still restarting the hrtimer with an expiry time
> set to now, triggering hrtimer to fire immediately and resulting in a
> continuous trigger of hrtimer and endless looping in the timer emulation.
> 
> Adding a fix to avoid restarting of the hrtimer if the interrupt is
> already fired.
> 
> Signed-off-by: D Scott Phillips <scott@os.amperecomputing.com>
> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
> ---
>  arch/arm64/kvm/arch_timer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index 2371796b1ab5..27a6ec46803a 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -472,7 +472,8 @@ static void timer_emulate(struct arch_timer_context *ctx)
>  		return;
>  	}
>  
> -	soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
> +	if (!ctx->irq.level)
> +		soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
>  }
>  
>  static void timer_save_state(struct arch_timer_context *ctx)

I think this is a regression introduced by bee038a67487 ("KVM:
arm/arm64: Rework the timer code to use a timer_map"), and you can see
it because the comment in this function doesn't make much sense
anymore.

Does the following work for you, mostly restoring the original code?

Thanks,

	M.

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index ad2a5df88810..4945c5b96f05 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -480,7 +480,7 @@ static void timer_emulate(struct arch_timer_context *ctx)
 	 * scheduled for the future.  If the timer cannot fire at all,
 	 * then we also don't need a soft timer.
 	 */
-	if (!kvm_timer_irq_can_fire(ctx)) {
+	if (should_fire || !kvm_timer_irq_can_fire(ctx)) {
 		soft_timer_cancel(&ctx->hrtimer);
 		return;
 	}

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Cc: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	scott@os.amperecomputing.com, keyur@os.amperecomputing.com
Subject: Re: [PATCH 1/3] KVM: arm64: nv: only emulate timers that have not yet fired
Date: Thu, 29 Dec 2022 13:00:55 +0000	[thread overview]
Message-ID: <87zgb6e54o.wl-maz@kernel.org> (raw)
In-Reply-To: <20220824060304.21128-2-gankulkarni@os.amperecomputing.com>

On Wed, 24 Aug 2022 07:03:02 +0100,
Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> wrote:
> 
> From: D Scott Phillips <scott@os.amperecomputing.com>
> 
> The timer emulation logic goes into an infinite loop when the NestedVM(L2)
> timer is being emulated.
> 
> While the CPU is executing in L1 context, the L2 timers are emulated using
> host hrtimer. When the delta of cval and current time reaches zero, the
> vtimer interrupt is fired/forwarded to L2, however the emulation function
> in Host-Hypervisor(L0) is still restarting the hrtimer with an expiry time
> set to now, triggering hrtimer to fire immediately and resulting in a
> continuous trigger of hrtimer and endless looping in the timer emulation.
> 
> Adding a fix to avoid restarting of the hrtimer if the interrupt is
> already fired.
> 
> Signed-off-by: D Scott Phillips <scott@os.amperecomputing.com>
> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
> ---
>  arch/arm64/kvm/arch_timer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index 2371796b1ab5..27a6ec46803a 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -472,7 +472,8 @@ static void timer_emulate(struct arch_timer_context *ctx)
>  		return;
>  	}
>  
> -	soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
> +	if (!ctx->irq.level)
> +		soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
>  }
>  
>  static void timer_save_state(struct arch_timer_context *ctx)

I think this is a regression introduced by bee038a67487 ("KVM:
arm/arm64: Rework the timer code to use a timer_map"), and you can see
it because the comment in this function doesn't make much sense
anymore.

Does the following work for you, mostly restoring the original code?

Thanks,

	M.

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index ad2a5df88810..4945c5b96f05 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -480,7 +480,7 @@ static void timer_emulate(struct arch_timer_context *ctx)
 	 * scheduled for the future.  If the timer cannot fire at all,
 	 * then we also don't need a soft timer.
 	 */
-	if (!kvm_timer_irq_can_fire(ctx)) {
+	if (should_fire || !kvm_timer_irq_can_fire(ctx)) {
 		soft_timer_cancel(&ctx->hrtimer);
 		return;
 	}

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2022-12-29 13:02 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  6:03 [PATCH 0/3] KVM: arm64: nv: Fixes for Nested Virtualization issues Ganapatrao Kulkarni
2022-08-24  6:03 ` Ganapatrao Kulkarni
2022-08-24  6:03 ` Ganapatrao Kulkarni
2022-08-24  6:03 ` [PATCH 1/3] KVM: arm64: nv: only emulate timers that have not yet fired Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-12-29 13:00   ` Marc Zyngier [this message]
2022-12-29 13:00     ` Marc Zyngier
2022-12-29 13:00     ` Marc Zyngier
2023-01-09 12:25     ` Ganapatrao Kulkarni
2023-01-09 12:25       ` Ganapatrao Kulkarni
2023-01-09 13:44       ` Marc Zyngier
2023-01-09 13:44         ` Marc Zyngier
2023-01-09 14:03         ` Ganapatrao Kulkarni
2023-01-09 14:03           ` Ganapatrao Kulkarni
2022-08-24  6:03 ` [PATCH 2/3] KVM: arm64: nv: Emulate ISTATUS when emulated timers are fired Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-12-29 13:53   ` Marc Zyngier
2022-12-29 13:53     ` Marc Zyngier
2022-12-29 13:53     ` Marc Zyngier
2023-01-02 11:46     ` Marc Zyngier
2023-01-02 11:46       ` Marc Zyngier
2023-01-02 11:46       ` Marc Zyngier
2023-01-03  4:21       ` Ganapatrao Kulkarni
2023-01-03  4:21         ` Ganapatrao Kulkarni
2023-01-03  4:21         ` Ganapatrao Kulkarni
2023-01-10  8:41       ` Ganapatrao Kulkarni
2023-01-10  8:41         ` Ganapatrao Kulkarni
2023-01-10 10:46         ` Marc Zyngier
2023-01-10 10:46           ` Marc Zyngier
2022-08-24  6:03 ` [PATCH 3/3] KVM: arm64: nv: Avoid block mapping if max_map_size is smaller than block size Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-08-24  6:03   ` Ganapatrao Kulkarni
2022-12-29 17:42   ` Marc Zyngier
2022-12-29 17:42     ` Marc Zyngier
2022-12-29 17:42     ` Marc Zyngier
2023-01-03  4:26     ` Ganapatrao Kulkarni
2023-01-03  4:26       ` Ganapatrao Kulkarni
2023-01-03  4:26       ` Ganapatrao Kulkarni
2023-01-09 13:58       ` Ganapatrao Kulkarni
2023-01-09 13:58         ` Ganapatrao Kulkarni
2022-10-10  5:56 ` [PATCH 0/3] KVM: arm64: nv: Fixes for Nested Virtualization issues Ganapatrao Kulkarni
2022-10-10  5:56   ` Ganapatrao Kulkarni
2022-10-10  5:56   ` Ganapatrao Kulkarni
2022-10-19  7:59   ` Marc Zyngier
2022-10-19  7:59     ` Marc Zyngier
2022-10-19  7:59     ` Marc Zyngier
2023-01-10 12:17 ` Ganapatrao Kulkarni
2023-01-10 12:17   ` Ganapatrao Kulkarni
2023-01-10 14:05   ` Marc Zyngier
2023-01-10 14:05     ` Marc Zyngier
2023-01-10 21:54   ` Marc Zyngier
2023-01-10 21:54     ` Marc Zyngier
2023-01-11  7:54     ` Marc Zyngier
2023-01-11  7:54       ` Marc Zyngier
2023-01-11  8:46     ` Ganapatrao Kulkarni
2023-01-11  8:46       ` Ganapatrao Kulkarni
2023-01-11  8:48       ` Ganapatrao Kulkarni
2023-01-11  8:48         ` Ganapatrao Kulkarni
2023-01-11 11:39       ` Marc Zyngier
2023-01-11 11:39         ` Marc Zyngier
2023-01-11 12:46         ` Ganapatrao Kulkarni
2023-01-11 12:46           ` Ganapatrao Kulkarni
2023-01-11 13:36           ` Marc Zyngier
2023-01-11 13:36             ` Marc Zyngier

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=87zgb6e54o.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=gankulkarni@os.amperecomputing.com \
    --cc=keyur@os.amperecomputing.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=scott@os.amperecomputing.com \
    --cc=will@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.