Skip to content

Commit 07ce121

Browse files
jandryukjgross1
authored andcommitted
xen/events: Return -EEXIST for bound VIRQs
Change find_virq() to return -EEXIST when a VIRQ is bound to a different CPU than the one passed in. With that, remove the BUG_ON() from bind_virq_to_irq() to propogate the error upwards. Some VIRQs are per-cpu, but others are per-domain or global. Those must be bound to CPU0 and can then migrate elsewhere. The lookup for per-domain and global will probably fail when migrated off CPU 0, especially when the current CPU is tracked. This now returns -EEXIST instead of BUG_ON(). A second call to bind a per-domain or global VIRQ is not expected, but make it non-fatal to avoid trying to look up the irq, since we don't know which per_cpu(virq_to_irq) it will be in. Cc: stable@vger.kernel.org Signed-off-by: Jason Andryuk <jason.andryuk@amd.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20250828003604.8949-3-jason.andryuk@amd.com>
1 parent 08df2d7 commit 07ce121

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/xen/events/events_base.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,12 @@ int bind_interdomain_evtchn_to_irq_lateeoi(struct xenbus_device *dev,
13141314
}
13151315
EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irq_lateeoi);
13161316

1317-
static int find_virq(unsigned int virq, unsigned int cpu, evtchn_port_t *evtchn)
1317+
static int find_virq(unsigned int virq, unsigned int cpu, evtchn_port_t *evtchn,
1318+
bool percpu)
13181319
{
13191320
struct evtchn_status status;
13201321
evtchn_port_t port;
1322+
bool exists = false;
13211323

13221324
memset(&status, 0, sizeof(status));
13231325
for (port = 0; port < xen_evtchn_max_channels(); port++) {
@@ -1330,12 +1332,16 @@ static int find_virq(unsigned int virq, unsigned int cpu, evtchn_port_t *evtchn)
13301332
continue;
13311333
if (status.status != EVTCHNSTAT_virq)
13321334
continue;
1333-
if (status.u.virq == virq && status.vcpu == xen_vcpu_nr(cpu)) {
1335+
if (status.u.virq != virq)
1336+
continue;
1337+
if (status.vcpu == xen_vcpu_nr(cpu)) {
13341338
*evtchn = port;
13351339
return 0;
1340+
} else if (!percpu) {
1341+
exists = true;
13361342
}
13371343
}
1338-
return -ENOENT;
1344+
return exists ? -EEXIST : -ENOENT;
13391345
}
13401346

13411347
/**
@@ -1382,8 +1388,11 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu)
13821388
evtchn = bind_virq.port;
13831389
else {
13841390
if (ret == -EEXIST)
1385-
ret = find_virq(virq, cpu, &evtchn);
1386-
BUG_ON(ret < 0);
1391+
ret = find_virq(virq, cpu, &evtchn, percpu);
1392+
if (ret) {
1393+
__unbind_from_irq(info, info->irq);
1394+
goto out;
1395+
}
13871396
}
13881397

13891398
ret = xen_irq_info_virq_setup(info, cpu, evtchn, virq);

0 commit comments

Comments
 (0)