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;

View File

@ -22,6 +22,7 @@ struct evtchn_bind_virq;
struct evtchn_bind_ipi;
struct evtchn_send;
struct evtchn_alloc_unbound;
struct evtchn_bind_interdomain;
int xen_evtchn_status_op(struct evtchn_status *status);
int xen_evtchn_close_op(struct evtchn_close *close);
int xen_evtchn_unmask_op(struct evtchn_unmask *unmask);
@ -29,5 +30,6 @@ int xen_evtchn_bind_virq_op(struct evtchn_bind_virq *virq);
int xen_evtchn_bind_ipi_op(struct evtchn_bind_ipi *ipi);
int xen_evtchn_send_op(struct evtchn_send *send);
int xen_evtchn_alloc_unbound_op(struct evtchn_alloc_unbound *alloc);
int xen_evtchn_bind_interdomain_op(struct evtchn_bind_interdomain *interdomain);
#endif /* QEMU_XEN_EVTCHN_H */

View File

@ -936,6 +936,22 @@ static bool kvm_xen_hcall_evtchn_op(struct kvm_xen_exit *exit, X86CPU *cpu,
}
break;
}
case EVTCHNOP_bind_interdomain: {
struct evtchn_bind_interdomain interdomain;
qemu_build_assert(sizeof(interdomain) == 12);
if (kvm_copy_from_gva(cs, arg, &interdomain, sizeof(interdomain))) {
err = -EFAULT;
break;
}
err = xen_evtchn_bind_interdomain_op(&interdomain);
if (!err &&
kvm_copy_to_gva(cs, arg, &interdomain, sizeof(interdomain))) {
err = -EFAULT;
}
break;
}
default:
return false;
}