linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RISC-V: KVM: Exit run-loop immediately if xfer_to_guest fails
@ 2022-11-08 11:55 Anup Patel
  2022-11-08 12:18 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Anup Patel @ 2022-11-08 11:55 UTC (permalink / raw)
  To: Paolo Bonzini, Atish Patra
  Cc: Palmer Dabbelt, Paul Walmsley, Andrew Jones, Anup Patel, kvm,
	kvm-riscv, linux-riscv, linux-kernel, Anup Patel

If xfer_to_guest_mode_handle_work() fails in the run-loop then exit
the run-loop immediately instead of doing it after some more work.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
 arch/riscv/kvm/vcpu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index 71ebbc4821f0..17d5b3f8c2ee 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -984,8 +984,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	while (ret > 0) {
 		/* Check conditions before entering the guest */
 		ret = xfer_to_guest_mode_handle_work(vcpu);
-		if (!ret)
-			ret = 1;
+		if (ret)
+			continue;
+		ret = 1;
 
 		kvm_riscv_gstage_vmid_update(vcpu);
 
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: Exit run-loop immediately if xfer_to_guest fails
  2022-11-08 11:55 [PATCH] RISC-V: KVM: Exit run-loop immediately if xfer_to_guest fails Anup Patel
@ 2022-11-08 12:18 ` Andreas Schwab
  2022-11-27 12:19   ` Anup Patel
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2022-11-08 12:18 UTC (permalink / raw)
  To: Anup Patel
  Cc: Paolo Bonzini, Atish Patra, Palmer Dabbelt, Paul Walmsley,
	Andrew Jones, Anup Patel, kvm, kvm-riscv, linux-riscv,
	linux-kernel

On Nov 08 2022, Anup Patel wrote:

> If xfer_to_guest_mode_handle_work() fails in the run-loop then exit
> the run-loop immediately instead of doing it after some more work.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> ---
>  arch/riscv/kvm/vcpu.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index 71ebbc4821f0..17d5b3f8c2ee 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -984,8 +984,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
>  	while (ret > 0) {
>  		/* Check conditions before entering the guest */
>  		ret = xfer_to_guest_mode_handle_work(vcpu);
> -		if (!ret)
> -			ret = 1;
> +		if (ret)
> +			continue;

If that is supposed to exit the loop, it would be clearer to just use
break.

> +		ret = 1;

There is a condition on ret <= 0 later in the loop that no longer can be
true.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: Exit run-loop immediately if xfer_to_guest fails
  2022-11-08 12:18 ` Andreas Schwab
@ 2022-11-27 12:19   ` Anup Patel
  0 siblings, 0 replies; 3+ messages in thread
From: Anup Patel @ 2022-11-27 12:19 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Anup Patel, Paolo Bonzini, Atish Patra, Palmer Dabbelt,
	Paul Walmsley, Andrew Jones, kvm, kvm-riscv, linux-riscv,
	linux-kernel

On Tue, Nov 8, 2022 at 5:48 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Nov 08 2022, Anup Patel wrote:
>
> > If xfer_to_guest_mode_handle_work() fails in the run-loop then exit
> > the run-loop immediately instead of doing it after some more work.
> >
> > Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> > ---
> >  arch/riscv/kvm/vcpu.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> > index 71ebbc4821f0..17d5b3f8c2ee 100644
> > --- a/arch/riscv/kvm/vcpu.c
> > +++ b/arch/riscv/kvm/vcpu.c
> > @@ -984,8 +984,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
> >       while (ret > 0) {
> >               /* Check conditions before entering the guest */
> >               ret = xfer_to_guest_mode_handle_work(vcpu);
> > -             if (!ret)
> > -                     ret = 1;
> > +             if (ret)
> > +                     continue;
>
> If that is supposed to exit the loop, it would be clearer to just use
> break.

This is a convention within the run-loop that we continue whenever
whenever "ret" is no longer suitable to continue. I don't see any
particular advantage in breaking this convention over here.

>
> > +             ret = 1;
>
> There is a condition on ret <= 0 later in the loop that no longer can be
> true.

Yes, for now the "ret <= 0" check is useless and the compiler will
optimize this comparison. We will be soon having more stuff added
to run-loop (such as AIA update) which will make "ret <= 0" check
useful again.

>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

Queued this patch for Linux-6.2

Thanks,
Anup

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-27 12:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 11:55 [PATCH] RISC-V: KVM: Exit run-loop immediately if xfer_to_guest fails Anup Patel
2022-11-08 12:18 ` Andreas Schwab
2022-11-27 12:19   ` Anup Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).