{
u32 port = data->u.evtchn.send_port;
struct evtchnfd *evtchnfd;
- int ret;
if (!port || port >= max_evtchn_port(kvm))
return -EINVAL;
- /* Protect writes to evtchnfd as well as the idr lookup. */
mutex_lock(&kvm->lock);
evtchnfd = idr_find(&kvm->arch.xen.evtchn_ports, port);
+ mutex_unlock(&kvm->lock);
- ret = -ENOENT;
if (!evtchnfd)
- goto out_unlock;
+ return -ENOENT;
/* For an UPDATE, nothing may change except the priority/vcpu */
- ret = -EINVAL;
if (evtchnfd->type != data->u.evtchn.type)
- goto out_unlock;
+ return -EINVAL;
/*
* Port cannot change, and if it's zero that was an eventfd
*/
if (!evtchnfd->deliver.port.port ||
evtchnfd->deliver.port.port != data->u.evtchn.deliver.port.port)
- goto out_unlock;
+ return -EINVAL;
/* We only support 2 level event channels for now */
if (data->u.evtchn.deliver.port.priority != KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL)
- goto out_unlock;
+ return -EINVAL;
+ mutex_lock(&kvm->lock);
evtchnfd->deliver.port.priority = data->u.evtchn.deliver.port.priority;
if (evtchnfd->deliver.port.vcpu_id != data->u.evtchn.deliver.port.vcpu) {
evtchnfd->deliver.port.vcpu_id = data->u.evtchn.deliver.port.vcpu;
evtchnfd->deliver.port.vcpu_idx = -1;
}
- ret = 0;
-out_unlock:
mutex_unlock(&kvm->lock);
- return ret;
+ return 0;
}
/*
gpa_t gpa;
int idx;
- /*
- * evtchnfd is protected by kvm->srcu; the idr lookup instead
- * is protected by RCU.
- */
idx = srcu_read_lock(&vcpu->kvm->srcu);
gpa = kvm_mmu_gva_to_gpa_system(vcpu, param, NULL);
+ srcu_read_unlock(&vcpu->kvm->srcu, idx);
if (!gpa || kvm_vcpu_read_guest(vcpu, gpa, &send, sizeof(send))) {
*r = -EFAULT;
- goto out_handled;
+ return true;
}
- rcu_read_lock();
+ /* The evtchn_ports idr is protected by vcpu->kvm->srcu */
evtchnfd = idr_find(&vcpu->kvm->arch.xen.evtchn_ports, send.port);
- rcu_read_unlock();
if (!evtchnfd)
- goto out_not_handled;
+ return false;
if (evtchnfd->deliver.port.port) {
int ret = kvm_xen_set_evtchn(&evtchnfd->deliver.port, vcpu->kvm);
}
*r = 0;
-out_handled:
- srcu_read_unlock(&vcpu->kvm->srcu, idx);
return true;
-
-out_not_handled:
- srcu_read_unlock(&vcpu->kvm->srcu, idx);
- return false;
}
void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu)