Skip to content

Commit d74669e

Browse files
committed
Merge tag 'kvm-x86-generic-6.5' of https://github.com/kvm-x86/linux into HEAD
Common KVM changes for 6.5: - Fix unprotected vcpu->pid dereference via debugfs - Fix KVM_BUG() and KVM_BUG_ON() macros with 64-bit conditionals - Refactor failure path in kvm_io_bus_unregister_dev() to simplify the code - Misc cleanups
2 parents cc74404 + cc77b95 commit d74669e

6 files changed

Lines changed: 28 additions & 31 deletions

File tree

include/kvm/iodev.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,4 @@ static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
5555
: -EOPNOTSUPP;
5656
}
5757

58-
static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
59-
{
60-
if (dev->ops->destructor)
61-
dev->ops->destructor(dev);
62-
}
63-
6458
#endif /* __KVM_IODEV_H__ */

include/linux/kvm_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static inline void kvm_vm_bugged(struct kvm *kvm)
849849

850850
#define KVM_BUG(cond, kvm, fmt...) \
851851
({ \
852-
int __ret = (cond); \
852+
bool __ret = !!(cond); \
853853
\
854854
if (WARN_ONCE(__ret && !(kvm)->vm_bugged, fmt)) \
855855
kvm_vm_bugged(kvm); \
@@ -858,7 +858,7 @@ static inline void kvm_vm_bugged(struct kvm *kvm)
858858

859859
#define KVM_BUG_ON(cond, kvm) \
860860
({ \
861-
int __ret = (cond); \
861+
bool __ret = !!(cond); \
862862
\
863863
if (WARN_ON_ONCE(__ret && !(kvm)->vm_bugged)) \
864864
kvm_vm_bugged(kvm); \

include/uapi/linux/kvm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ struct kvm_s390_ucas_mapping {
16171617
#define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)
16181618
#define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs)
16191619
/*
1620-
* vcpu version available with KVM_ENABLE_CAP
1620+
* vcpu version available with KVM_CAP_ENABLE_CAP
16211621
* vm version available with KVM_CAP_ENABLE_CAP_VM
16221622
*/
16231623
#define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)

virt/kvm/coalesced_mmio.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,10 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
186186
coalesced_mmio_in_range(dev, zone->addr, zone->size)) {
187187
r = kvm_io_bus_unregister_dev(kvm,
188188
zone->pio ? KVM_PIO_BUS : KVM_MMIO_BUS, &dev->dev);
189-
190-
kvm_iodevice_destructor(&dev->dev);
191-
192189
/*
193190
* On failure, unregister destroys all devices on the
194-
* bus _except_ the target device, i.e. coalesced_zones
195-
* has been modified. Bail after destroying the target
196-
* device, there's no need to restart the walk as there
197-
* aren't any zones left.
191+
* bus, including the target device. There's no need
192+
* to restart the walk as there aren't any zones left.
198193
*/
199194
if (r)
200195
break;

virt/kvm/eventfd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,9 @@ static int kvm_assign_ioeventfd_idx(struct kvm *kvm,
889889

890890
unlock_fail:
891891
mutex_unlock(&kvm->slots_lock);
892+
kfree(p);
892893

893894
fail:
894-
kfree(p);
895895
eventfd_ctx_put(eventfd);
896896

897897
return ret;
@@ -901,7 +901,7 @@ static int
901901
kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
902902
struct kvm_ioeventfd *args)
903903
{
904-
struct _ioeventfd *p, *tmp;
904+
struct _ioeventfd *p;
905905
struct eventfd_ctx *eventfd;
906906
struct kvm_io_bus *bus;
907907
int ret = -ENOENT;
@@ -915,8 +915,7 @@ kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
915915

916916
mutex_lock(&kvm->slots_lock);
917917

918-
list_for_each_entry_safe(p, tmp, &kvm->ioeventfds, list) {
919-
918+
list_for_each_entry(p, &kvm->ioeventfds, list) {
920919
if (p->bus_idx != bus_idx ||
921920
p->eventfd != eventfd ||
922921
p->addr != args->addr ||
@@ -931,7 +930,6 @@ kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
931930
bus = kvm_get_bus(kvm, bus_idx);
932931
if (bus)
933932
bus->ioeventfd_count--;
934-
ioeventfd_release(p);
935933
ret = 0;
936934
break;
937935
}

virt/kvm/kvm_main.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,7 +3888,10 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
38883888
static 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+
53165325
static 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,
55365545
int 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

55835593
struct kvm_io_device *kvm_io_bus_get_dev(struct kvm *kvm, enum kvm_bus bus_idx,

0 commit comments

Comments
 (0)