qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@ventanamicro.com>
To: "Xie Bo" <xb@ultrarisc.com>, <qemu-devel@nongnu.org>
Cc: <ajones@ventanamicro.com>, <qemu-riscv@nongnu.org>,
	<alistair23@gmail.com>, <pbonzini@redhat.com>,
	<anup@brainfault.org>, <alistair.francis@wdc.com>,
	<palmer@dabbelt.com>, <xiamy@ultrarisc.com>,
	<qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org>
Subject: Re: [PATCH v9 1/2] Set KVM initial privilege mode and mp_state
Date: Tue, 16 Sep 2025 10:00:48 +0200	[thread overview]
Message-ID: <DCU2ER2UIJDS.3CTYAJAJP8NSX@ventanamicro.com> (raw)
In-Reply-To: <20250915070811.3422578-2-xb@ultrarisc.com>

2025-09-15T15:08:07+08:00, Xie Bo <xb@ultrarisc.com>:
> For KVM mode, the privilege mode should not include M-mode, and the
> initial value should be set to S-mode. Additionally, a following patch
> adds the implementation of putting the vCPU privilege mode to KVM.
> When the vCPU runs for the first time, QEMU will first put the privilege
> state to KVM. If the initial value is set to M-mode, KVM will encounter
> an error.
>
> In addition, this patch introduces the 'mp_state' field to RISC-V
> vCPUs, following the convention used by KVM on x86. The 'mp_state'
> reflects the multiprocessor state of a vCPU, and is used to control
> whether the vCPU is runnable by KVM. Randomly select one CPU as the
> boot CPU. Since each CPU executes the riscv_cpu_reset_hold() function
> and CPU0 executes first, only CPU0 randomly selects the boot CPU.

This could really be two patches, as changing the boot 

> Signed-off-by: Xie Bo <xb@ultrarisc.com>
> ---
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> @@ -685,18 +686,32 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
> +    static int boot_cpu_index;
       ^^^^^^
!

> +    if (kvm_enabled()) {
> +        env->priv = PRV_S;
> +    } else {
> +        env->priv = PRV_M;
> +    }

(I think changing the priv belongs to a separate patch.)

> +    if (cs->cpu_index == 0) {
> +        boot_cpu_index = g_random_int_range(0, ms->smp.cpus);
> +    }

This adds an assumption that vcpu_index == 0 is executed first.
Is that always going to be true?

If we reset the VCPUs in a different order (or in parallel), we might
also online zero or two VCPUs.

Performing the selection just once, in the reset initiator, would allow
us to avoid the dreaded static variable by putting it in machine arch
state.

> +    if (cs->cpu_index == boot_cpu_index) {
> +        env->mp_state = KVM_MP_STATE_RUNNABLE;
> +    } else {
> +        env->mp_state = KVM_MP_STATE_STOPPED;
> +    }

Thanks.


  reply	other threads:[~2025-09-16  8:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15  7:08 [PATCH v9 0/2] target/riscv:Fix riscv64 kvm migration Xie Bo
2025-09-15  7:08 ` [PATCH v9 1/2] Set KVM initial privilege mode and mp_state Xie Bo
2025-09-16  8:00   ` Radim Krčmář [this message]
2025-09-29  1:48   ` Alistair Francis
2025-09-29 17:36     ` Radim Krčmář
2025-10-22 11:47   ` Daniel Henrique Barboza
2025-09-15  7:08 ` [PATCH v9 2/2] Fix VM resume after QEMU+KVM migration Xie Bo
2025-09-16  8:03   ` Radim Krčmář
2025-09-15 15:31 ` [PATCH v9 0/2] target/riscv:Fix riscv64 kvm migration Andrew Jones
2025-09-29  1:43 ` Alistair Francis

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=DCU2ER2UIJDS.3CTYAJAJP8NSX@ventanamicro.com \
    --to=rkrcmar@ventanamicro.com \
    --cc=ajones@ventanamicro.com \
    --cc=alistair.francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=anup@brainfault.org \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=xb@ultrarisc.com \
    --cc=xiamy@ultrarisc.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;
as well as URLs for NNTP newsgroup(s).