[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 37/39] xen/riscv: implement continue_new_vcpu()
- To: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Fri, 6 Nov 2026 12:31:32 +0100
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
- Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Zheng Zhang <zhangzheng@xxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- Delivery-date: Fri, 06 Nov 2026 11:31:36 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 11/4/26 3:00 PM, Baptiste Le Duc wrote:
continue_new_vcpu() is the arch hook invoked the first time a freshly
created vCPU is scheduled. Implement both cases it has to cover:
- for the idle vCPU, switch to its own stack and jump to idle_loop();
- for a guest vCPU, enter the guest through the new
return_to_new_vcpu() path in entry.S, which restores hstatus and
sepc, passes the hart id in a0 and, in a1, either the DTB address
(boot vCPU, as expected by the RISC-V boot protocol) or the opaque
value passed to SBI HSM hart_start() (secondary vCPUs), clears the
remaining GPRs, sets sstatus.SPP and sstatus.SPIE and executes sret.
Nit: the guest vCPU sentence is hard to follow in one go. Maybe split it:
- for a guest vCPU, enter the guest through the new
return_to_new_vcpu() path in entry.S. It restores hstatus and
sepc and passes the hart id in a0. a1 holds the DTB address for
the boot vCPU (as expected by the RISC-V boot protocol), or the
opaque value passed to SBI HSM hart_start() for secondary vCPUs.
It then clears the remaining GPRs, sets sstatus.SPP and
sstatus.SPIE, and executes sret.
Thanks for the suggestion. I'll use this wording.
[ ... 94 lines skipped ... ]
--- a/xen/arch/riscv/entry.S
+++ b/xen/arch/riscv/entry.S
@@ -147,3 +147,42 @@ FUNC(__context_switch)
ret
END(__context_switch)
+
+/*
+ * Enter a vCPU for the first time. Must be called with interrupts disabled,
+ * see continue_new_vcpu().
+ */
+FUNC(return_to_new_vcpu)
+ REG_L t0, CPU_USER_REGS_HSTATUS(sp)
+ csrw CSR_HSTATUS, t0
+
At this point regs->hstatus only has SPV | SPVP (arch_vcpu_create()), so
VSXL is written as 0, which is a reserved encoding. That only gets fixed
by "xen/riscv: set the guest's XLEN explicitly in hstatus.VSXL", which
comes later in the series. Wouldn't it be better to move that one ahead
of this patch?
Agreed. I'll move "xen/riscv: set the guest's XLEN explicitly in
hstatus.VSXL" before this patch.
Reviewed-by: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
Thanks!
~ Oleksii
|