Skip to content

riscv: Port multikernel to RISC-V - #49

Merged
congwang-mk merged 26 commits into
masterfrom
multikernel-riscv-port
Nov 24, 2026
Merged

congwang-mk merged 26 commits into
masterfrom
multikernel-riscv-port

Conversation

@congwang-mk

@congwang-mk congwang-mk commented Nov 13, 2026 •

Copy link
Copy Markdown

This series ports multikernel to RISC-V, following the plan in the tracking issue #36.

SBI HSM does the hart lifecycle on RISC-V. A pool hart is simply STOPPED in firmware, a spawn starts with one HART_START (which already enters with a0 = hart ID and a1 = device tree), and a spawn halts by stopping every hart. As on arm64, there is no counterpart of the x86 trampolines or park loop. MSIs need no proxy either. An IMSIC has one interrupt file per hart, so a spawn programs only the files of its own harts and composes its MSI messages itself.

What is in it

Foundation and hart lifecycle

Boot data and messaging

Interrupts and devices

Memory

  • the linear map is split at the edges of a partial hot-remove, and a partial section's memmap gets base pages, so carving the pool out of boot RAM and growing or shrinking an instance leave neighbouring memory mapped
  • an instance's initrd is no longer placed inside the kernel's PMD-rounded reservation

Generic fixes found on the way

  • pcifront unmaps a bus's ECAM when its probe fails, and no longer hands its domain number to the PCI core's emulation IDA when a bridge is released
  • backport of mainline cefafbd ("irqchip/riscv-imsic: Clear interrupt move state during CPU offlining"); without it, offlining harts into the pool leaves IMSIC vectors unmovable, and the host hangs unbinding a device it lends

Robustness and documentation

Testing

QEMU 10.2.4 virt,aia=aplic-imsic with its OpenSBI 1.7. All the mk-smoke scenarios pass, with no warnings:

  • lifecycle: graceful halt, forced halt, re-spawn
  • 50 start/halt rounds on the same harts and memory
  • poweroff and reboot inside a spawn, which leave the host running
  • hart hotplug
  • memory grow and shrink while running, and resize while stopped
  • a virtio NIC with MSI-X, on the root bus and behind a PCIe root port
  • an NVMe disk
  • a spawn hart taken offline under its NIC's MSIs

QEMU aia=none (PLIC) passes lifecycle, respawn, down, hotplug and memory. PCI devices get no interrupts there, as intended.

QEMU 8.2.2 cannot boot an AIA host at all (an IMSIC emulation bug fixed in later QEMU).

The SpacemiT K3 Pico-ITX matches this design: an S-mode IMSIC and APLIC, and PCIe whose msi-parent is the IMSIC. Its OpenSBI 1.6 implements HSM, DBCN and SSE. Nothing has run on it yet.

Left open

Closes #22
Closes #23
Closes #24
Closes #25
Closes #26
Closes #27
Closes #28
Closes #30
Closes #31
Closes #33
Closes #35

🤖 Generated with Claude Code

@congwang-mk
congwang-mk force-pushed the multikernel-riscv-port branch 2 times, most recently from b3f7bf4 to b4be1bf Compare November 18, 2026 22:50
@pro-utkarshM

Copy link
Copy Markdown

Tested b4be1bf70fb2 (not rebased) on QEMU 11.1.2 virt,aia=aplic-imsic with OpenSBI 1.8.1, clang 23, i.e. newer QEMU/OpenSBI than in the PR description. Everything passes: graceful and forced halt, re-spawn, 20 start/halt rounds, poweroff/reboot inside the spawn, hart hotplug, memory grow/shrink, a virtio-net with MSI-X lent to the spawn (ping works, MSI-X interrupts land on the spawn's harts, device goes back to the host after halt), and teardown.

One doc nit in riscv.rst: earlycon=uart8250,mmio,0x10000000 in a spawn stopped the host's serial output, since early 8250 setup clears the shared UART's IER. earlycon=sbi works.

nickolaev and others added 26 commits November 24, 2026 11:59
Wire CONFIG_MULTIKERNEL into the 64-bit RISC-V build and add sparse
hart ID translations. Reject the invalid hart sentinel before lookup so
it cannot alias an unused logical CPU slot.

Reserve the architecture control block for the spawn context, DTB and
entry stub. Provide safe stubs for the full architecture interface so the
functional SBI HSM, Image loader and doorbell work can land incrementally.

[Picked from #37 with the
 Kconfig dependencies split out and the ARCH_HAS_MK_POOL_STATE gate on
 CPU removal dropped: an arch that cannot park a departing CPU should
 refuse in its own takedown path. Added the empty struct mk_pool_arch
 the core now embeds, and dropped a force-stop registration stub that
 nothing declares.
 Rebased onto the instance-aware mk_force_stop_cpu(), and stubbed the
 mk_arch_register_ram() and mk_arch_pool_{map,unmap}() hooks the core
 gained since.]

Signed-off-by: Nikolay Nikolaev <nicknickolaev@gmail.com>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Memory hot-removed from the kernel leaves the linear map, and a user
that takes it out for good, so that no stray pointer reaches it, may
still need a few of its pages at their usual address.

Add map_linear_range() and unmap_linear_range() for that. The range is
mapped with pages only: remove_pmd_mapping() clears any leaf the removed
range touches, whole, so a block mapping wider than the range would take
its neighbours away with it on unmap.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Firmware owns the hart lifecycle on RISC-V, and Linux already drives
CPU hotplug through SBI HSM. A pool hart is a hart in the HSM STOPPED
state: it executes nothing, so the pool needs no park loop, no mailbox
and no page tables, and nothing of a previous kernel survives on it.

HART_START(hartid, addr, opaque) enters S-mode at addr with the MMU off,
interrupts masked, a0 = hartid and a1 = opaque. That is the Linux boot
protocol with the device tree in a1, so starting an instance is one
ecall with the Image entry and its device tree. cpu_ops_sbi.c keeps its
HSM wrappers static and logical-CPU based, while every hart here belongs
to another kernel, so the calls are made directly by hart ID.

 - Spawn: HART_START of the boot hart. From then on the instance's
   kernel may start any hart it was given, so all of them count as
   started until seen STOPPED, as on arm64.
 - Confirm parked and repark: wait for HART_STATUS to report STOPPED.
   A stopped hart belongs to whoever starts it next; there is nothing
   to move.
 - Pool state: HART_STOP from the calling hart. Host pool harts leave
   through the stock arch_cpu_idle_dead() -> sbi_cpu_stop().

The instance's control block lives in pool memory, which this kernel
reaches through its linear map address, so map it back with pages.

Ownership is not enforced by firmware: any S-mode kernel in the domain
may start a stopped hart, the same trust model as INIT/SIPI and PSCI
CPU_ON.

Signed-off-by: Cong Wang <cwang@multikernel.io>
RISC-V has no remote instruction cache invalidation. A hart stopped
through SBI HSM cannot be reached by SBI_RFENCE_REMOTE_FENCE_I, OpenSBI
does not invalidate anything on HART_START, and _start_kernel executes
fence.i only under CONFIG_RISCV_M_MODE. A hart that ran one instance's
image, stopped, and is later started on another image loaded at the
same physical addresses can fetch lines of the old one. A fence.i on
the way out does not close that: the stop path that runs after it is
itself image text and leaves lines behind.

So every hart a multikernel kernel starts enters through mk_hart_entry,
which executes fence.i and only then jumps to the image. Where the stub
itself lives matters as much: lines of an address that once held other
code are just as stale. Instance memory does not qualify, since any of
it may have held an earlier instance's text. The host's own kernel text
does: its addresses hold nothing else for as long as the host runs. The
stub is four instructions of host text, and everything that differs per
start comes through a1 as data, which data reads see coherently: a
struct mk_boot_record with the a1 to enter with and the entry point.

 - The boot hart is started at mk_hart_entry with a1 pointing at a
   record in the host's instance struct: the device tree and the Image
   entry. Nothing of RISC-V's needs the control block any more.
 - A spawn kernel's secondaries are harts an earlier kernel stopped too,
   so it starts them the same way, around the stock secondary_start_sbi
   entry and its boot data. It learns where mk_hart_entry is from the
   multikernel,hart-entry property of its /chosen and hands the same
   address down to the kernels it spawns itself.

The host's own secondaries keep entering directly: its image is never
replaced while it runs.

Drop struct mk_pool_arch, which the core no longer embeds.

Signed-off-by: Cong Wang <cwang@multikernel.io>
machine_halt(), machine_power_off() and machine_restart() end in the
SBI SRST extension, or the legacy shutdown call, through the power-off
handler and the restart notifier sbi_init() registers. Both act on the
whole machine: a spawn kernel taking the stock path powers off or
resets the host along with itself.

In a spawn all three now leave through mk_halt_to_pool(): the host is
told, and every hart calls HART_STOP, the last one too. They never get
as far as SRST. A host keeps the stock behaviour.

The other ways down:

 - smp_send_stop() leaves harts in a WFI loop inside the image, which is
   about to be overwritten. In a multikernel kernel the stop IPI stops
   the hart through SBI HSM instead, as a backup that fences a host can
   only take over stopped harts.
 - A panicking spawn spins in the panic loop and holds its harts. Its
   reboot on panic is the halt above, so make that the default.

The crash stop path already stops harts through cpu_ops->cpu_stop().

Signed-off-by: Cong Wang <cwang@multikernel.io>
kexec_file on RISC-V already loads an Image at any suitably aligned
physical address: the kernel's virtual addresses are fixed and its
physical base is found at boot. For a KEXEC_TYPE_MULTIKERNEL image the
generic code picks each segment's destination inside the instance's
memory grant. image->start is the Image's first byte, which is its
entry, and the device tree segment is what goes to a1. Those are the
two things a boot hart is started with.

What has to go is the preparation for replacing the running kernel,
which an instance never does:

 - No purgatory. It verifies the segments and jumps to the next kernel
   from the hart that runs kexec; an instance's boot hart is started
   at the Image entry directly.
 - No relocation code in the control page: the segments are copied in
   place, and again on every spawn, by the generic code.

The device tree the loader builds is a copy of this kernel's own with a
new /chosen. It names every hart, all of memory and every device, so an
instance must not boot from it, and what an instance owns can change
between load and exec anyway. Its boot tree is rebuilt in place on every
spawn instead, so size the segment for that, and record where it is.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The tree in a1 is a RISC-V kernel's only boot channel. Build it on every
spawn, into the device tree segment the loader sized for it, as on
arm64: the instance tree the generic code wrote, its /resources and
/chosen included, is the base, opened into the segment, and what the
RISC-V boot path itself reads goes on top:

 - /memory: the instance's current memory grant, regenerated on every
   exec, since the grant can change between load and exec.
 - /cpus: the host's /cpus properties (timebase-frequency, cell sizes)
   and a copy of each hart's node with its riscv,cpu-intc child and
   phandles, taken verbatim. The ISA strings, the MMU type and the
   cache block sizes describe a hart as firmware set it up, and a spawn
   probing an extension firmware left off on its hart would trap. The
   instance's harts lead, its boot hart first, so they get the low
   logical numbers; every other hart follows, since a kernel can only
   ever online a hart it enumerated at boot, and the generic code
   prunes the ones the instance does not own from the present mask.
 - /chosen: what only the loader's tree knows, the command line, the
   initrd and the seeds, plus linux,pci-probe-only: BARs and bridge
   windows are the host's to assign.

No interrupt controller beyond the harts' own goes in yet. A device-less
instance needs none: IPIs and the timer are local interrupts, and its
console is the message ring, or earlycon.

On the spawn side, setup_arch() accepts the tree as the manifest when
its root is multikernel compatible, before paging_init(), so that a
kernel told about RAM it will be handed later can start its linear map
low enough for it. The instance segment itself is not in the host's
linear map, so the builder maps it for the write.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The message ring needs a doorbell another kernel can ring on one of this
kernel's harts. Linux multiplexes its own IPI types over one hardware
interrupt through ipi_mux, whose per-CPU pending bits live in the
receiver's memory, out of every other kernel's reach. What any kernel
can do is make firmware raise a supervisor software interrupt on a hart
by hart ID: an SBI IPI. That is the doorbell, on every platform.

 - Sending: SBI_EXT_IPI_SEND_IPI to the hart, directly, as
   sbi_send_ipi() takes a logical CPU of this kernel.
 - Receiving where SBI IPIs carry this kernel's own IPIs as well (PLIC,
   CLINT): one software interrupt can stand for a local IPI and a
   doorbell at once, so the rings are drained on every one of them,
   after the muxed IPIs. Telling the two apart by "no muxed IPI was
   pending" would lose a doorbell that arrived together with one.
 - Receiving where something else provides the IPIs (IMSIC): software
   interrupts are not used otherwise, so sbi_ipi_init() still takes
   them, for the doorbell alone. A controller that already owns them,
   such as ACLINT SSWI, leaves the kernel without a doorbell, which is
   reported.

The other way would be an interrupt identity reserved in every hart's
IMSIC file and written by the sender, which needs the receiver's IMSIC
geometry, an identity no kernel allocates, and a second mechanism for
platforms without IMSIC. A doorbell is not a hot path, and the SBI IPI
works the same everywhere.

There is no foreign doorbell to filter: draining only looks at this
kernel's own rings, which no other sender can fill. The console can be
what is sending, so a failure is reported deferred, and once.

Signed-off-by: Cong Wang <cwang@multikernel.io>
S-mode has no NMI: a supervisor software interrupt is masked by
sstatus.SIE like any other, and SBI has no call that stops another hart.
So the only way to stop a kernel that no longer answers is to have it
stop its harts itself.

The generic force halt arms a marker in the instance's ring area before
it signals each hart. Signal with the doorbell, and have the doorbell
handler look at the marker before anything else: obeying it means
HART_STOP, for good. It has to come before the drain, which waits for a
lock the hart being stopped may hold. Only a kernel with a link to this
one can write the marker, which filters out a stop from anyone else.

That reaches a hart that takes interrupts, not one spinning with them
masked. Such a hart never reports STOPPED, and the host keeps the
instance's memory rather than overwrite code it may still run, so a
failed force halt costs memory, never the machine. SBI SSE events,
delivered whatever a hart has masked, are what closes this; the kernel
does not have them yet.

Signed-off-by: Cong Wang <cwang@multikernel.io>
pcifront maps the ECAM window of a bus node before it sets the bridge
up, and a probe that fails after that left the mapping behind. With an
architecture that defers the probe until its MSI domain exists, every
retry leaked another megabyte of vmalloc space.

Signed-off-by: Cong Wang <cwang@multikernel.io>
An IMSIC has one interrupt file per hart, and an MSI is a write of an
identity into the file of the hart it targets. A spawn kernel's IMSIC
driver only ever programs the files of the harts it brings online, so
the spawn can own the MSIs of its PCI devices outright: it composes the
messages itself and nothing needs the host to proxy them, which is the
part arm64 needs an ITS proxy for.

Copy the host's supervisor level IMSIC node into the boot tree, with
its reg translated to CPU addresses as the node can sit on a bus the
instance tree does not have. Its interrupts-extended names the local
controller of every hart, and every hart has a node in the spawn's
/cpus, so the driver resolves all of them.

Make the IMSIC the MSI domain of every pcifront bridge, the buses added
after boot as well as the ones in the boot tree. At boot pcifront binds
before the IMSIC platform driver has made its domain, so the bridge
probe defers until it has.

The doorbell stays an SBI IPI, so no IMSIC identity is held back for
it. A host without an IMSIC gives its spawns PCI devices without
interrupts: INTx is not offered to an instance.

Signed-off-by: Cong Wang <cwang@multikernel.io>
OpenSBI can partition a machine into domains, each with its own harts
and memory, and fails HART_START and HART_STATUS on a hart of another
domain with INVALID_PARAM, or DENIED for a start. Both reach the
caller as a bare -EINVAL or -EPERM, which reads like a kernel bug.

Name the cause instead. Such a hart can never join a pool: on a
statically partitioned machine each domain boots its own kernel, and
a multikernel spawn works only inside the domain of its host.

Signed-off-by: Cong Wang <cwang@multikernel.io>
A platform device interrupts through a wired source, and every wired
source goes through the machine's one PLIC or APLIC. Their priority,
enable and target registers for a source sit next to those of sources
the host keeps, the PLIC's driver probe masks every source in every
context it finds a hart for, and the APLIC's domain configuration is
global. Sharing them takes a tenant mode in both drivers and a source
grant in the manifest, for devices that also need their clocks, resets
and pin controllers from the host.

Do as arm64 does and give an instance PCI devices only, which interrupt
with MSIs into its own harts' IMSIC files. The boot tree describes no
wired interrupt controller, and an instance that has platform devices
fails to start.

Signed-off-by: Cong Wang <cwang@multikernel.io>
What a RISC-V platform has to provide, how harts move between the pool
and the kernels through SBI HSM, why every started hart enters through
a fence.i stub, why a spawn never goes down through SBI SRST, and the
limits of a forced halt without an S-mode NMI. Also what the host adds
to the boot tree, the SBI IPI doorbell, MSIs through the IMSIC, why an
instance gets no wired interrupts, and why the harts have to share one
OpenSBI domain.

Signed-off-by: Cong Wang <cwang@multikernel.io>
offline_and_remove_subsections() takes a range out of memory blocks
that stay online, and the unmap clears every leaf it meets whole. Boot
memory is mapped with 1G and 2M leaves, so a range ending inside one
takes memory still in use out of the linear map with it: carving a
multikernel pool out of boot RAM unmapped the kernel stacks next to it,
and every hart faulted on its stack.

Split the leaves at both ends of the range first, as set_memory_*()
already does on the live linear map. The vmemmap of a section added
back is mapped with one 2M block per section and is never split, so a
range whose memmap edges fall inside such a block is refused.

Signed-off-by: Cong Wang <cwang@multikernel.io>
A 64-bit kernel with STRICT_KERNEL_RWX reserves itself up to the next
PMD boundary past _end, as it maps itself read-only in the linear map
with PMD granularity. The loader only keeps the other segments past
image_size, and relies on placing them top-down to keep them far from
the kernel.

A multikernel instance is placed bottom-up in its memory grant, so its
initrd started right at _end, inside that reservation. The spawn found
it overlapping in-use memory, dropped it and panicked for want of a
root file system. Start the other segments at the next PMD boundary.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The vmemmap is mapped with 2M blocks, each holding the memmap of one
whole section. A range hot-added into part of a section shares that
block with the rest of the section, so removing it again would free the
memmap of all of it, and a partial hot-remove is refused for that.

A multikernel instance grows and shrinks in ranges smaller than a
section, and could never give back memory it was given. Map the memmap
of anything less than a section with base pages, as arm64 does, so that
it goes with its range.

Signed-off-by: Cong Wang <cwang@multikernel.io>
pcifront gives each bridge the domain number the host uses for the bus.
The PCI core takes any domain number set in a bridge for one it handed
out to an emulated bridge, and returns it to that IDA when the bridge
is released, so releasing one of pcifront's warned "ida_free called
for id=0 which is not allocated". A probe that defers until its MSI
domain exists releases its bridge on every retry, and so would every
teardown of a bus.

Clear the number in the bridge's release function. It cannot come from
that IDA instead: several of the host's buses can share one domain.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Affinity changes of IMSIC interrupts have to be careful to not lose an
interrupt in the process. Each vector keeps track of an affinity change in
progress with two pointers in struct imsic_vector.

imsic_vector::move_prev points to the previous CPU target data and
imsic_vector::move_next to the designated new CPU target data.

imsic_vector::move_prev on the new CPU can only be cleared after the
previous CPU has cleared imsic_vector::move_next, which ususally happens in
__imsic_remote_sync().

In case of CPU hot-unplug __imsic_remote_sync() is not invoked because the
CPU is already marked offline. That means imsic_vector::move_prev becomes
stale until the CPU is onlined again.

The stale pointer prevents further affinity changes for the affected
interrupts.

Solve this by clearing the imsic_vector::move_prev pointers in the CPU
hotplug offline path.

[ tglx: Replace word salad in change log ]

Fixes: 0f67911 ("irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector")
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260508-imsic-v2-1-e9f08dd46cf5@sifive.com
(cherry picked from commit cefafbd)
Splitting a linear map leaf takes a bare page for the new table, but
the hot-remove path frees an emptied table with pagetable_dtor(), which
expects a constructed one: with CONFIG_DEBUG_VM it trips the page type
check, and otherwise it takes NR_PAGETABLE below zero. A partial
hot-remove now splits the leaves at its edges, and removing the
neighbour of such an edge empties and frees the split table.

Allocate the split tables with pagetable_alloc() and construct them,
as alloc_pte_late() and alloc_pmd_late() do.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Hot-remove runs pagetable_dtor() on every PTE table it frees, but
tables from memblock at boot and the vmemmap tables the generic code
populates never had a constructor run. Freeing the PTE table of a
subsection's base page memmap, or a boot table at the unaligned edge
of a RAM region, trips the page type check with CONFIG_DEBUG_VM.

Skip the destructor for reserved pages and vmemmap tables, as the PMD
level already did for the vmemmap.

Signed-off-by: Cong Wang <cwang@multikernel.io>
… calls

mk_hsm_start() and mk_hsm_status() repeat sbi_hsm_hart_start() and
sbi_hsm_hart_get_status(), which the SBI CPU operations keep to
themselves. Let those two out and use them. What is left of
mk_hsm_start() is the message for a hart of another OpenSBI domain,
which firmware refuses with either of two errors.

Signed-off-by: Cong Wang <cwang@multikernel.io>
A machine can have CPUs of more than one kind, such as the X100 and
A100 cores of a SpacemiT K3. A kernel runs on one kind only, so the
others never become CPUs of the host, and its device tree need not
even mention them. The pool, which takes a CPU by offlining it, could
not hold them. They are the CPUs a second kernel is most wanted for.

Define the pool over the machine instead of over the host. A CPU is
unclaimed when firmware lets this kernel start it, but this kernel has
no logical CPU for it. The architecture finds such CPUs when the first
baseline is applied, and they join the pool without being asked for:
there is nothing to offline, only to see them parked. They never leave
it, as this kernel cannot run on them, so a baseline may now name no
CPU at all, and one that only holds unclaimed CPUs does not count as
applied. Nothing has a logical number to look up for them, so the
paths that only did that to check a CPU exists skip it, and an
instance whose boot CPU is unclaimed is started without one.

A kernel still runs on one kind only. The architecture numbers the
kinds, 0 being the kind of the CPUs this kernel runs on, and every CPU
of an instance must have the kind of its first: when the instance is
created, and when a CPU is added to a running one, whose kernel would
otherwise refuse a CPU it has disabled without the host learning why.

User space learns both from the root device tree, which is the view of
the pool it already reads: cpus-unclaimed in /resources, and one node
per kind under /cpu-kinds. The latter is left out where every CPU is
alike.

No architecture has an unclaimed CPU or a second kind yet.

Signed-off-by: Cong Wang <cwang@multikernel.io>
RISC-V has no CPUID. A kernel is told its harts and their features by
the device tree, and nothing tells it about a hart the tree leaves
out, as the upstream tree of the SpacemiT K3 leaves out the A100
cores. Firmware still holds those harts stopped, which is the state of
a pool hart.

So let each one describe itself. When the pool is first set up, ask
firmware for the state of every hart ID, and start each hart that is
stopped and not a CPU of this kernel once into a stub. With the MMU
off and a trap handler that counts a trap as "not there", it reads its
ID registers through SBI, tries one instruction or CSR of each
extension, and stops itself again.

What it reports goes where a device tree would have had it: the hart
gets a CPU node in this kernel's live tree, disabled, as this kernel
does not run on it. A hart with a node is not probed, so none is
started twice. A spawned kernel does none of this: its parent tells it
its harts, and what else it finds stopped is the parent's pool.

The harts this kernel runs on are kind 0, and so is a hart whose
vendor, architecture and implementation IDs match one of theirs. Any
other set of IDs is a kind of its own.

A hart's extensions are those this kernel knows and has, minus every
one whose probe trapped or that the stub cannot probe. An instance may
thus leave a feature of the hart unused, and never uses one that is
missing.

An IMSIC finds a hart's interrupt file by the hart's position in
interrupts-extended, and the host's node does not list these harts.
The stub therefore also writes an interrupt identity to each file no
known hart has, and the file whose write shows up in its own pending
bits is its own. Where the files are and which the host's harts have
is what the IMSIC driver already knows.

The tree an instance boots from copies the CPU nodes as before, the
new ones having no model name, MMU type or caches, and gets an IMSIC
node whose reg and interrupts-extended cover the files that were
found. The host's own IMSIC node is left as it is, as its driver has
long read it. Harts of the kind of the instance's boot hart are
enabled and all others are disabled. They are not left out, as the
interrupt files are found by position. The boot hart is the first the
instance owns, not a logical CPU of the host, which an unclaimed hart
does not have.

Tested under QEMU with half of the harts removed from the host's tree,
with a PLIC and with AIA. All QEMU harts are of one kind, so the
refusal to mix kinds in an instance is not covered.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The SBI Supervisor Software Events extension has firmware call a handler
a kernel registered, whatever that hart has masked in S-mode. Add its
extension ID, its function IDs and the local software-injected event,
the one an S-mode caller can raise on another hart.

This is what forcing a multikernel instance down needs. Attributes,
states and the other events are left to the SSE support proper, whose
names these follow.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Force halt rings the doorbell of each hart of the instance, and a hart
that spins with interrupts masked never takes it. Such a hart never
reports STOPPED, the host keeps the instance's memory, and on bare metal
nothing short of a reboot gets either back.

The SBI Supervisor Software Events extension closes this. Firmware
raises an event with an M-mode interrupt, which nothing in S-mode can
mask, and enters the handler the hart's kernel registered. So every
kernel registers the software-injected event on each of its harts, and
a force halt injects it before it rings the doorbell.

The handler is all there is of SSE here, and it is a stub. A hart being
forced down can be in user mode, halfway through the exception entry
with a user tp, or on a stack it has overflowed, and the handler either
stops the hart for good or returns as if nothing had happened, so it
has no use for the interrupted context. Firmware saves a6 and a7 and
restores them when the event completes, and both ways out are an SBI
call with its arguments in those two: the stub uses no other register,
no stack and no per-CPU data. It stops the hart if the force-halt
marker is armed and completes the event otherwise, which is the same
filter the doorbell applies.

Three things in OpenSBI shape the rest. It drops an event the target
has not registered and reports success, so the doorbell is still rung,
which also reaches a kernel too young to have registered. It keeps a
registration over a kexec, so the event is unregistered at shutdown,
and before each registration for a crash kernel. And an event sent to
a stopped hart leaves it spinning in firmware, so a stopped hart is
left alone.

Without SSE in firmware nothing changes.

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk
congwang-mk force-pushed the multikernel-riscv-port branch from b4be1bf to c565ae1 Compare November 24, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment