History

KVM: Introduce a 'release' method for KVM devices

When a P9 sPAPR VM boots, the CAS negotiation process determines which interrupt mode to use (XICS legacy or XIVE native) and invokes a machine reset to activate the chosen mode. To be able to switch from one interrupt mode to another, we introduce the capability to release a KVM device without destroying the VM. The KVM device interface is extended with a new 'release' method which is called when the file descriptor of the device is closed. Once 'release' is called, the 'destroy' method will not be called anymore as the device is removed from the device list of the VM.

Cédric Le Goater committed 7 years ago

Commit 2bde9b31 parent 3fab2d12 files · +22 −0Browse files

Unified · Split

2 files
  1. include/linux/kvm_host.h +9 −0
  2. virt/kvm/kvm_main.c +13 −0
include/linux/kvm_host.h+9−0
@@ -1240,6 +1240,15 @@ struct kvm_device_ops { · 1239 unmodified lines
12401240 */
12411241 void (*destroy)(struct kvm_device *dev);
12421242
1243+ /*
1244+ * Release is an alternative method to free the device. It is
1245+ * called when the device file descriptor is closed. Once
1246+ * release is called, the destroy method will not be called
1247+ * anymore as the device is removed from the device list of
1248+ * the VM. kvm->lock is held.
1249+ */
1250+ void (*release)(struct kvm_device *dev);
1251+
12431252 int (*set_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
12441253 int (*get_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
12451254 int (*has_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
virt/kvm/kvm_main.c+13−0
@@ -2938,6 +2938,19 @@ static int kvm_device_release(struct inode *inode, struct file *filp) · 2937 unmodified lines
29382938 struct kvm_device *dev = filp->private_data;
29392939 struct kvm *kvm = dev->kvm;
29402940
2941+ if (!dev)
2942+ return -ENODEV;
2943+
2944+ if (dev->kvm != kvm)
2945+ return -EPERM;
2946+
2947+ if (dev->ops->release) {
2948+ mutex_lock(&kvm->lock);
2949+ list_del(&dev->vm_node);
2950+ dev->ops->release(dev);
2951+ mutex_unlock(&kvm->lock);
2952+ }
2953+
29412954 kvm_put_kvm(kvm);
29422955 return 0;
29432956 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t