]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
Revert "KVM: x86/xen: Fix SRCU/RCU usage in readers of evtchn_ports"
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 26 Dec 2022 11:24:40 +0000 (11:24 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 26 Dec 2022 11:35:15 +0000 (11:35 +0000)
This reverts commit 0ae356e28968715e0d7fb8608e3f6e1caf5e2dad.

arch/x86/kvm/xen.c

index 935f845d005cac2935e5556c73403f8c2044b264..d7af402402484bb008f253213a86c186224a34c1 100644 (file)
@@ -1825,23 +1825,20 @@ static int kvm_xen_eventfd_update(struct kvm *kvm,
 {
        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
@@ -1849,21 +1846,20 @@ static int kvm_xen_eventfd_update(struct kvm *kvm,
         */
        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;
 }
 
 /*
@@ -2009,23 +2005,19 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r)
        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);
@@ -2036,13 +2028,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r)
        }
 
        *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)