Skip to content

xen: Fix dispatching of event handlers on multi-CPU platforms#2172

Open
francescolavra wants to merge 5 commits into
masterfrom
fix/xen-interrupt
Open

xen: Fix dispatching of event handlers on multi-CPU platforms#2172
francescolavra wants to merge 5 commits into
masterfrom
fix/xen-interrupt

Conversation

@francescolavra

Copy link
Copy Markdown
Member

The Xen interrupt handler is invoking the handlers of all pending events whose port numbers belong to the same evtchn_pending array element as the element for which there is a pending event for the current vCPU. This means that the handler for an event bound to a given vCPU can potentially be executed on a different vCPU. This creates issues in event handlers (such as xennet_event_handler() that assume they are always run sequentially and cannot run in parallel on different vCPUs.
This change set fixes the Xen interrupt handler so that it only invokes handlers for events bound to the current vCPU.
In addition, Xen device drivers can now request that their event handler is bound to a specific vCPU (via the newly defined xen_bind_evtchn() function) instead of the default vCPU 0; this allows spreading the interrupt load for different devices among different vCPUs.

Francesco Lavra added 5 commits July 6, 2026 11:59
This avoids a separate memory allocation for the vector struct.
As part of this change, add the vector_init() and vector_deinit() generic
functions to the runtime library.
Remove fields that are only used during initialization.
This will allow avoiding early allocation of the struct xen_platform_info
when the static structure is replaced with a dynamically allocated one in
a future commit.
…ed one

This change, which decreases memory requirements on non-Xen platforms, is
being made in preparation for a commit that will add a new (somewhat large)
field (`vcpu_evtchn_enable`) to this struct.
The Xen interrupt handler is invoking the handlers of all pending events
whose port numbers belong to the same `evtchn_pending` array element as the
element for which there is a pending event for the current vCPU. This means
that the handler for an event bound to a given vCPU can potentially be
executed on a different vCPU. This creates issues in event handlers (such
as `xennet_event_handler()` that assume they are always run sequentially
and cannot run in parallel on different vCPUs.
Fix the Xen interrupt handler so that it only invokes handlers for events
bound to the current vCPU. The issue with seemingly spurious interrupts
mentioned in a comment in the interrupt handler function cannot be
reproduced (tested on t2.nano, t2.medium and t2.2xlarge AWS instances),
thus the `evtchn_mask` array is no longer used.
In addition, allow device drivers to request that their event handler is
bound to a specific vCPU (via the newly defined xen_bind_evtchn()
function); this allows spreading the interrupt load among different vCPUs.
Initialize the `retval` variable to fix "error: variable 'retval' is
uninitialized when passed as a const pointer argument here
[-Werror,-Wuninitialized-const-pointer]" when compiling with clang on a Mac
host.
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.

1 participant