Skip to content

Commit a1cd3f0

Browse files
legoaterpaulusmack
authored andcommitted
KVM: Introduce a 'mmap' method for KVM devices
Some KVM devices will want to handle special mappings related to the underlying HW. For instance, the XIVE interrupt controller of the POWER9 processor has MMIO pages for thread interrupt management and for interrupt source control that need to be exposed to the guest when the OS has the required support. Cc: Paolo Bonzini <[email protected]> Signed-off-by: Cédric Le Goater <[email protected]> Reviewed-by: David Gibson <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent e4945b9 commit a1cd3f0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/linux/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ struct kvm_device_ops {
12451245
int (*has_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
12461246
long (*ioctl)(struct kvm_device *dev, unsigned int ioctl,
12471247
unsigned long arg);
1248+
int (*mmap)(struct kvm_device *dev, struct vm_area_struct *vma);
12481249
};
12491250

12501251
void kvm_device_get(struct kvm_device *dev);

virt/kvm/kvm_main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,16 @@ static long kvm_vcpu_compat_ioctl(struct file *filp,
28842884
}
28852885
#endif
28862886

2887+
static int kvm_device_mmap(struct file *filp, struct vm_area_struct *vma)
2888+
{
2889+
struct kvm_device *dev = filp->private_data;
2890+
2891+
if (dev->ops->mmap)
2892+
return dev->ops->mmap(dev, vma);
2893+
2894+
return -ENODEV;
2895+
}
2896+
28872897
static int kvm_device_ioctl_attr(struct kvm_device *dev,
28882898
int (*accessor)(struct kvm_device *dev,
28892899
struct kvm_device_attr *attr),
@@ -2936,6 +2946,7 @@ static const struct file_operations kvm_device_fops = {
29362946
.unlocked_ioctl = kvm_device_ioctl,
29372947
.release = kvm_device_release,
29382948
KVM_COMPAT(kvm_device_ioctl),
2949+
.mmap = kvm_device_mmap,
29392950
};
29402951

29412952
struct kvm_device *kvm_device_from_filp(struct file *filp)

0 commit comments

Comments
 (0)