@@ -3888,7 +3888,10 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
38883888static int vcpu_get_pid (void * data , u64 * val )
38893889{
38903890 struct kvm_vcpu * vcpu = data ;
3891- * val = pid_nr (rcu_access_pointer (vcpu -> pid ));
3891+
3892+ rcu_read_lock ();
3893+ * val = pid_nr (rcu_dereference (vcpu -> pid ));
3894+ rcu_read_unlock ();
38923895 return 0 ;
38933896}
38943897
@@ -3990,7 +3993,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
39903993 if (r < 0 )
39913994 goto kvm_put_xa_release ;
39923995
3993- if (KVM_BUG_ON (!! xa_store (& kvm -> vcpu_array , vcpu -> vcpu_idx , vcpu , 0 ), kvm )) {
3996+ if (KVM_BUG_ON (xa_store (& kvm -> vcpu_array , vcpu -> vcpu_idx , vcpu , 0 ), kvm )) {
39943997 r = - EINVAL ;
39953998 goto kvm_put_xa_release ;
39963999 }
@@ -5313,6 +5316,12 @@ static void hardware_disable_all(void)
53135316}
53145317#endif /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
53155318
5319+ static void kvm_iodevice_destructor (struct kvm_io_device * dev )
5320+ {
5321+ if (dev -> ops -> destructor )
5322+ dev -> ops -> destructor (dev );
5323+ }
5324+
53165325static void kvm_io_bus_destroy (struct kvm_io_bus * bus )
53175326{
53185327 int i ;
@@ -5536,7 +5545,7 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
55365545int kvm_io_bus_unregister_dev (struct kvm * kvm , enum kvm_bus bus_idx ,
55375546 struct kvm_io_device * dev )
55385547{
5539- int i , j ;
5548+ int i ;
55405549 struct kvm_io_bus * new_bus , * bus ;
55415550
55425551 lockdep_assert_held (& kvm -> slots_lock );
@@ -5566,18 +5575,19 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
55665575 rcu_assign_pointer (kvm -> buses [bus_idx ], new_bus );
55675576 synchronize_srcu_expedited (& kvm -> srcu );
55685577
5569- /* Destroy the old bus _after_ installing the (null) bus. */
5578+ /*
5579+ * If NULL bus is installed, destroy the old bus, including all the
5580+ * attached devices. Otherwise, destroy the caller's device only.
5581+ */
55705582 if (!new_bus ) {
55715583 pr_err ("kvm: failed to shrink bus, removing it completely\n" );
5572- for (j = 0 ; j < bus -> dev_count ; j ++ ) {
5573- if (j == i )
5574- continue ;
5575- kvm_iodevice_destructor (bus -> range [j ].dev );
5576- }
5584+ kvm_io_bus_destroy (bus );
5585+ return - ENOMEM ;
55775586 }
55785587
5588+ kvm_iodevice_destructor (dev );
55795589 kfree (bus );
5580- return new_bus ? 0 : - ENOMEM ;
5590+ return 0 ;
55815591}
55825592
55835593struct kvm_io_device * kvm_io_bus_get_dev (struct kvm * kvm , enum kvm_bus bus_idx ,
0 commit comments