From: "Radim Krčmář" <rkrcmar@ventanamicro.com>
To: "Alistair Francis" <alistair23@gmail.com>, "Xie Bo" <xb@ultrarisc.com>
Cc: <qemu-devel@nongnu.org>, <ajones@ventanamicro.com>,
<qemu-riscv@nongnu.org>, <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: Mon, 29 Sep 2025 19:36:58 +0200 [thread overview]
Message-ID: <DD5GSZ9KWEIJ.2GLJ40HGEWWM1@ventanamicro.com> (raw)
In-Reply-To: <CAKmqyKMMo0XfaEsTYqpsV8UfXkhM5YHZsCdptFVR5pSYM1KRxQ@mail.gmail.com>
2025-09-29T11:48:08+10:00, Alistair Francis <alistair23@gmail.com>:
> On Mon, Sep 15, 2025 at 5:08 PM Xie Bo <xb@ultrarisc.com> wrote:
>>
>> 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.
>>
>> Signed-off-by: Xie Bo <xb@ultrarisc.com>
>> ---
>> target/riscv/cpu.c | 17 ++++++++++++++++-
>> target/riscv/cpu.h | 2 ++
>> 2 files changed, 18 insertions(+), 1 deletion(-)
>
> This fails to build with the following error, it seems an include is missing
>
> ../target/riscv/cpu.c: In function ‘riscv_cpu_reset_hold’:
> ../target/riscv/cpu.c:711:25: error: ‘KVM_MP_STATE_RUNNABLE’
> undeclared (first use in this function)
> 711 | env->mp_state = KVM_MP_STATE_RUNNABLE;
> | ^~~~~~~~~~~~~~~~~~~~~
> ../target/riscv/cpu.c:711:25: note: each undeclared identifier is
> reported only once for each function it appears in
> ../target/riscv/cpu.c:713:25: error: ‘KVM_MP_STATE_STOPPED’ undeclared
> (first use in this function); did you mean ‘S390_CPU_STATE_STOPPED’?
> 713 | env->mp_state = KVM_MP_STATE_STOPPED;
> | ^~~~~~~~~~~~~~~~~~~~
> | S390_CPU_STATE_STO
I think this is because the code belongs in kvm_riscv_reset_vcpu().
>> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
>> + static int boot_cpu_index;
>> + MachineState *ms = MACHINE(qdev_get_machine());
>> + if (cs->cpu_index == 0) {
>> + boot_cpu_index = g_random_int_range(0, ms->smp.cpus);
>> + }
If we're already touching the code, can we also express boot_cpu_index
in a VM state? Using a static variable is pretty scary.
Thanks.
next prev parent reply other threads:[~2025-09-29 17:38 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ář
2025-09-29 1:48 ` Alistair Francis
2025-09-29 17:36 ` Radim Krčmář [this message]
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=DD5GSZ9KWEIJ.2GLJ40HGEWWM1@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 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.