hw/xen: Implement EVTCHNOP_bind_interdomain

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
This commit is contained in:
David Woodhouse 2022-12-14 17:26:32 +00:00
parent e1db61b87b
commit 8432788104
3 changed files with 96 additions and 0 deletions

View file

@ -722,6 +722,23 @@ static int close_port(XenEvtchnState *s, evtchn_port_t port)
}
break;
case EVTCHNSTAT_interdomain:
if (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) {
/* Not yet implemented. This can't happen! */
} else {
/* Loopback interdomain */
XenEvtchnPort *rp = &s->port_table[p->type_val];
if (!valid_port(p->type_val) || rp->type_val != port ||
rp->type != EVTCHNSTAT_interdomain) {
error_report("Inconsistent state for interdomain unbind");
} else {
/* Set the other end back to unbound */
rp->type = EVTCHNSTAT_unbound;
rp->type_val = 0;
}
}
break;
default:
break;
}
@ -837,6 +854,67 @@ int xen_evtchn_bind_ipi_op(struct evtchn_bind_ipi *ipi)
return ret;
}
int xen_evtchn_bind_interdomain_op(struct evtchn_bind_interdomain *interdomain)
{
XenEvtchnState *s = xen_evtchn_singleton;
uint16_t type_val;
int ret;
if (!s) {
return -ENOTSUP;
}
if (interdomain->remote_dom == DOMID_QEMU) {
type_val = PORT_INFO_TYPEVAL_REMOTE_QEMU;
} else if (interdomain->remote_dom == DOMID_SELF ||
interdomain->remote_dom == xen_domid) {
type_val = 0;
} else {
return -ESRCH;
}
if (!valid_port(interdomain->remote_port)) {
return -EINVAL;
}
qemu_mutex_lock(&s->port_lock);
/* The newly allocated port starts out as unbound */
ret = allocate_port(s, 0, EVTCHNSTAT_unbound, type_val,
&interdomain->local_port);
if (ret) {
goto out;
}
if (interdomain->remote_dom == DOMID_QEMU) {
/* We haven't hooked up QEMU's PV drivers to this yet */
ret = -ENOSYS;
} else {
/* Loopback */
XenEvtchnPort *rp = &s->port_table[interdomain->remote_port];
XenEvtchnPort *lp = &s->port_table[interdomain->local_port];
if (rp->type == EVTCHNSTAT_unbound && rp->type_val == 0) {
/* It's a match! */
rp->type = EVTCHNSTAT_interdomain;
rp->type_val = interdomain->local_port;
lp->type = EVTCHNSTAT_interdomain;
lp->type_val = interdomain->remote_port;
} else {
ret = -EINVAL;
}
}
if (ret) {
free_port(s, interdomain->local_port);
}
out:
qemu_mutex_unlock(&s->port_lock);
return ret;
}
int xen_evtchn_alloc_unbound_op(struct evtchn_alloc_unbound *alloc)
{
XenEvtchnState *s = xen_evtchn_singleton;