Skip to contentSkip to conversation

KVM: fix 'release' method of KVM device

PATCH In review Cédric Le Goater 3 participants 4 messages May 7, 2019 – May 8, 2019 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: fix 'release' method of KVM device

There is no need to test for the device pointer validity when releasing a KVM device. The file descriptor should identify it safely.

---

Fixes http://patchwork.ozlabs.org/patch/1087506/
https://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/commit/?h=kvm-ppc-next&id+de9b3ec8bdf60788e9e2ce8c07a2f8d6003dbd

 virt/kvm/kvm_main.c | 6 ------
 1 file changed, 6 deletions(-)
virt/kvm/kvm_main.c +0 -6
index 161830ec0aa5..ac15b8fd8399 100644
@@ -2939,12 +2939,6 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
 	struct kvm_device *dev = filp->private_data;
 	struct kvm *kvm = dev->kvm;
 
-	if (!dev)
-		return -ENODEV;
-
-	if (dev->kvm != kvm)
-		return -EPERM;
-
 	if (dev->ops->release) {
 		mutex_lock(&kvm->lock);
 		list_del(&dev->vm_node);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 2 lines · Cédric Le Goater

There is no need to test for the device pointer validity when releasing a KVM device. The file descriptor should identify it safely.

"Fix" implies it is broken. Is it broken?

Quoted 28 lines

---

Fixes http://patchwork.ozlabs.org/patch/1087506/
https://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/commit/?h=kvm-ppc-next&id+de9b3ec8bdf60788e9e2ce8c07a2f8d6003dbd

 virt/kvm/kvm_main.c | 6 ------
 1 file changed, 6 deletions(-)
virt/kvm/kvm_main.c +0 -6
index 161830ec0aa5..ac15b8fd8399 100644
@@ -2939,12 +2939,6 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
 	struct kvm_device *dev = filp->private_data;
 	struct kvm *kvm = dev->kvm;
 
-	if (!dev)
-		return -ENODEV;
-
-	if (dev->kvm != kvm)
-		return -EPERM;
-
 	if (dev->ops->release) {
 		mutex_lock(&kvm->lock);
 		list_del(&dev->vm_node);
Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 5 lines · David Hildenbrand
Quoted 2 lines · Cédric Le Goater

There is no need to test for the device pointer validity when releasing a KVM device. The file descriptor should identify it safely.

"Fix" implies it is broken. Is it broken?

no, it's not broken indeed. The changes are removing useless checks leftover from a previous patch. A title such as :

remove useless checks in 'release' method of KVM device

would be more appropriate. I can send a v2 with Alexey's rb.

Thanks,

C.

Quoted 30 lines
Quoted 28 lines

---

Fixes http://patchwork.ozlabs.org/patch/1087506/
https://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/commit/?h=kvm-ppc-next&id+de9b3ec8bdf60788e9e2ce8c07a2f8d6003dbd

 virt/kvm/kvm_main.c | 6 ------
 1 file changed, 6 deletions(-)
virt/kvm/kvm_main.c +0 -6
index 161830ec0aa5..ac15b8fd8399 100644
@@ -2939,12 +2939,6 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
 	struct kvm_device *dev = filp->private_data;
 	struct kvm *kvm = dev->kvm;
 
-	if (!dev)
-		return -ENODEV;
-
-	if (dev->kvm != kvm)
-		return -EPERM;
-
 	if (dev->ops->release) {
 		mutex_lock(&kvm->lock);
 		list_del(&dev->vm_node);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Cédric Le Goater
Quoted 8 lines · Cédric Le Goater

There is no need to test for the device pointer validity when releasing a KVM device. The file descriptor should identify it safely.

---

Fixes http://patchwork.ozlabs.org/patch/1087506/
https://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/commit/?h=kvm-ppc-next&id+de9b3ec8bdf60788e9e2ce8c07a2f8d6003dbd

Usually suggested way is:

[fstn1-p1 kernel]$ git log -1 --format='Fixes: %h ("%s")' 2bde9b3ec8bd

Fixes 2bde9b3ec8bd ("KVM: Introduce a 'release' method for KVM devices")

Anyway,

Quoted 22 lines
 virt/kvm/kvm_main.c | 6 ------
 1 file changed, 6 deletions(-)
virt/kvm/kvm_main.c +0 -6
index 161830ec0aa5..ac15b8fd8399 100644
@@ -2939,12 +2939,6 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
 	struct kvm_device *dev = filp->private_data;
 	struct kvm *kvm = dev->kvm;
 
-	if (!dev)
-		return -ENODEV;
-
-	if (dev->kvm != kvm)
-		return -EPERM;
-
 	if (dev->ops->release) {
 		mutex_lock(&kvm->lock);
 		list_del(&dev->vm_node);
Signature · 1 line
Alexey