Skip to content

multikernel: take the pending message lock as a raw spinlock - #55

Merged
congwang-mk merged 1 commit into
multikernel:masterfrom
pro-utkarshM:fix/mk-pending-msgs-raw-lock
Nov 24, 2026
Merged

congwang-mk merged 1 commit into
multikernel:masterfrom
pro-utkarshM:fix/mk-pending-msgs-raw-lock

Conversation

@pro-utkarshM

@pro-utkarshM pro-utkarshM commented Nov 24, 2026 •

Copy link
Copy Markdown

mk_msg_pending_complete() runs from the multikernel IPI handler in hard interrupt context, under the raw mk_drain_lock, and takes mk_pending_msgs_lock, a spinlock_t (a sleeping lock on PREEMPT_RT). With PROVE_RAW_LOCK_NESTING the host reports it on the first halt ACK of a spawn (RISC-V, #49 head b4be1bf):

[ BUG: Invalid wait context ]
swapper/0/0 is trying to lock:
(mk_pending_msgs_lock){....}-{3:3}, at: mk_msg_pending_complete+0x34/0x8c
context-{2:2}
1 lock held by swapper/0/0:
 #0: (mk_drain_lock){-...}-{2:2}, at: multikernel_interrupt_handler+0x36/0xf0

The lock only guards a list add, a walk that calls complete(), and a list delete; the allocation and kfree() are already outside it, and complete() is safe under a raw lock. Make it a raw spinlock.

Tested: RISC-V QEMU virt (aia=aplic-imsic, OpenSBI v1.8.1), #49 head b4be1bf with #55–#59 applied: spawn, graceful and forced halt, re-spawn, 20 start/halt rounds, hart and memory hotplug, poweroff/reboot inside the spawn, 28 spawns, no lockdep report on the host. Builds on current master (fca2f47): x86_64 clang W=1 with no new warnings, also with PCI=n and with MULTIKERNEL=n; checkpatch --strict clean.

mk_msg_pending_complete() runs from the multikernel IPI handler, in hard
interrupt context and under the raw mk_drain_lock. It takes
mk_pending_msgs_lock, a spinlock_t, which becomes a sleeping lock on
PREEMPT_RT. With PROVE_RAW_LOCK_NESTING, the host reports this on the
first halt ACK of every spawn:

  [ BUG: Invalid wait context ]
  swapper/0/0 is trying to lock:
  (mk_pending_msgs_lock){....}-{3:3}, at: mk_msg_pending_complete+0x34/0x8c
  context-{2:2}
  1 lock held by swapper/0/0:
   #0: (mk_drain_lock){-...}-{2:2}, at: multikernel_interrupt_handler
  Call Trace:
   mk_msg_pending_complete+0x34/0x8c
   mk_system_msg_handler+0xcc/0x170
   mk_message_type_ipi_callback+0x50/0xa0
   mk_ipi_drain_ring+0xca/0x124
   multikernel_interrupt_handler+0xb0/0xf0

The lock only guards a list add, a list walk that calls complete(), and
a list delete. The allocation and the kfree() are already outside it,
and complete() is safe under a raw lock, so make it a raw spinlock.

Fixes: 4f676d2 ("multikernel: Add messaging layer for inter-kernel communication")
Signed-off-by: Utkarsh Maurya <projects.utkarshMaurya@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants