Skip to content

Commit bc04d2d

Browse files
dwmw2opsiff
authored andcommitted
KVM: x86/xen: Allow 'out of range' event channel ports in IRQ routing table.
commit a7f4dff21fd744d08fa956c243d2b1795f23cbf7 upstream. To avoid imposing an ordering constraint on userspace, allow 'invalid' event channel targets to be configured in the IRQ routing table. This is the same as accepting interrupts targeted at vCPUs which don't exist yet, which is already the case for both Xen event channels *and* for MSIs (which don't do any filtering of permitted APIC ID targets at all). If userspace actually *triggers* an IRQ with an invalid target, that will fail cleanly, as kvm_xen_set_evtchn_fast() also does the same range check. If KVM enforced that the IRQ target must be valid at the time it is *configured*, that would force userspace to create all vCPUs and do various other parts of setup (in this case, setting the Xen long_mode) before restoring the IRQ table. Cc: [email protected] Signed-off-by: David Woodhouse <[email protected]> Reviewed-by: Paul Durrant <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: massage comment] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 20d1d9e7ce694cf1587fb54b0faf9df02392f89e)
1 parent 71c9e68 commit bc04d2d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

arch/x86/kvm/xen.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,8 +1737,19 @@ int kvm_xen_setup_evtchn(struct kvm *kvm,
17371737
{
17381738
struct kvm_vcpu *vcpu;
17391739

1740-
if (ue->u.xen_evtchn.port >= max_evtchn_port(kvm))
1741-
return -EINVAL;
1740+
/*
1741+
* Don't check for the port being within range of max_evtchn_port().
1742+
* Userspace can configure what ever targets it likes; events just won't
1743+
* be delivered if/while the target is invalid, just like userspace can
1744+
* configure MSIs which target non-existent APICs.
1745+
*
1746+
* This allow on Live Migration and Live Update, the IRQ routing table
1747+
* can be restored *independently* of other things like creating vCPUs,
1748+
* without imposing an ordering dependency on userspace. In this
1749+
* particular case, the problematic ordering would be with setting the
1750+
* Xen 'long mode' flag, which changes max_evtchn_port() to allow 4096
1751+
* instead of 1024 event channels.
1752+
*/
17421753

17431754
/* We only support 2 level event channels for now */
17441755
if (ue->u.xen_evtchn.priority != KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL)

0 commit comments

Comments
 (0)