KVM updates for Linux 3.1.8
Subsystems (6)
cover KVM updates for Linux 3.1.8
The following patches want to be applied to the 3.1 branch. "All users must update".
Alex Williamson (2):
KVM: Remove ability to assign a device without iommu support
KVM: Device assignment permission checks
Avi Kivity (1):
KVM guest: prevent tracing recursion with kvmclock
Jan Kiszka (1):
KVM: x86: Prevent starting PIT timers in the absence of irqchip
support
Documentation/virtual/kvm/api.txt | 7 +++ arch/x86/kernel/kvmclock.c | 5 +- arch/x86/kvm/i8254.c | 10 +++- virt/kvm/assigned-dev.c | 93 +++++++++++++++++++++++++++++++++---- 4 files changed, 101 insertions(+), 14 deletions(-)
Signature · 1 line
1.7.7.1
PATCH 1/4 KVM guest: prevent tracing recursion with kvmclock
Prevent tracing of preempt_disable() in get_cpu_var() in kvm_clock_read(). When CONFIG_DEBUG_PREEMPT is enabled, preempt_disable/enable() are traced and this causes the function_graph tracer to go into an infinite recursion. By open coding the preempt_disable() around the get_cpu_var(), we can use the notrace version which prevents preempt_disable/enable() from being traced and prevents the recursion.
Based on a similar patch for Xen from Jeremy Fitzhardinge.
--- arch/x86/kernel/kvmclock.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/kvmclock.c +3 -2
@@ -74,9 +74,10 @@ static cycle_t kvm_clock_read(void)struct pvclock_vcpu_time_info *src;cycle_t ret; - src = &get_cpu_var (hv_clock); +preempt_disable_notrace (); + src = &__get_cpu_var (hv_clock); ret =pvclock_clocksource_read (src); -put_cpu_var (hv_clock); +preempt_enable_notrace ();return ret; }
Signature · 1 line
1.7.7.1
PATCH 2/4 KVM: x86: Prevent starting PIT timers in the absence of irqchip support
In reply to Avi KivityFrom: Jan Kiszka <[email protected]>
User space may create the PIT and forgets about setting up the irqchips. In that case, firing PIT IRQs will crash the host:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000128 IP: [<ffffffffa10f6280>] kvm_set_irq+0x30/0x170 [kvm] ... Call Trace: [<ffffffffa11228c1>] pit_do_work+0x51/0xd0 [kvm] [<ffffffff81071431>] process_one_work+0x111/0x4d0 [<ffffffff81071bb2>] worker_thread+0x152/0x340 [<ffffffff81075c8e>] kthread+0x7e/0x90 [<ffffffff815a4474>] kernel_thread_helper+0x4/0x10
Prevent this by checking the irqchip mode before starting a timer. We can't deny creating the PIT if the irqchips aren't set up yet as current user land expects this order to work.
--- arch/x86/kvm/i8254.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/kvm/i8254.c +7 -3
@@ -338,11 +338,15 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)return HRTIMER_NORESTART ; } -static void create_pit_timer (struct kvm_kpit_state *ps,u32 val,int is_period) +static void create_pit_timer (struct kvm *kvm,u32 val,int is_period) { +struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;struct kvm_timer *pt = &ps->pit_timer;s64 interval; +if (!irqchip_in_kernel (kvm)) +return ; + interval =muldiv64 (val,NSEC_PER_SEC ,KVM_PIT_FREQ );pr_debug ("create pit timer, interval is %llu nsec\n" , interval);
@@ -394,13 +398,13 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)/* FIXME: enhance mode 4 precision */ case 4 :if (!(ps->flags &KVM_PIT_FLAGS_HPET_LEGACY )) { -create_pit_timer (ps, val,0 ); +create_pit_timer (kvm, val,0 ); }break ;case 2 :case 3 :if (!(ps->flags &KVM_PIT_FLAGS_HPET_LEGACY )){ -create_pit_timer (ps, val,1 ); +create_pit_timer (kvm, val,1 ); }break ;default :
Signature · 1 line
1.7.7.1
PATCH 3/4 KVM: Remove ability to assign a device without iommu support
In reply to Avi KivityFrom: Alex Williamson <[email protected]>
This option has no users and it exposes a security hole that we can allow devices to be assigned without iommu protection. Make KVM_DEV_ASSIGN_ENABLE_IOMMU a mandatory option.
--- Documentation/virtual/kvm/api.txt | 3 +++ virt/kvm/assigned-dev.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-)
Documentation/virtual/kvm/api.txt +3 -0
@@ -1131,6 +1131,9 @@ following flags are specified: /* Depends on KVM_CAP_IOMMU */ #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) +The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure +isolation of the device. Usages not specifying this flag are deprecated. + 4.49 KVM_DEASSIGN_PCI_DEVICE Capability: KVM_CAP_DEVICE_DEASSIGNMENT
virt/kvm/assigned-dev.c +9 -9
@@ -481,6 +481,9 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,struct kvm_assigned_dev_kernel *match;struct pci_dev *dev; +if (!(assigned_dev->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU )) +return -EINVAL ; +mutex_lock (&kvm->lock); idx =srcu_read_lock (&kvm->srcu);
@@ -538,16 +541,14 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,list_add (&match->list, &kvm->arch.assigned_dev_head); -if (assigned_dev->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU ) { -if (!kvm->arch.iommu_domain) { - r =kvm_iommu_map_guest (kvm); -if (r) - goto out_list_del; - } - r =kvm_assign_device (kvm, match); +if (!kvm->arch.iommu_domain) { + r =kvm_iommu_map_guest (kvm);if (r) goto out_list_del; } + r =kvm_assign_device (kvm, match); +if (r) + goto out_list_del; out:srcu_read_unlock (&kvm->srcu, idx);
@@ -587,8 +588,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm, goto out; } -if (match->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU ) -kvm_deassign_device (kvm, match); +kvm_deassign_device (kvm, match);kvm_free_assigned_device (kvm, match);
Signature · 1 line
1.7.7.1
PATCH 4/4 KVM: Device assignment permission checks
In reply to Avi KivityFrom: Alex Williamson <[email protected]>
Only allow KVM device assignment to attach to devices which:
- Are not bridges
- Have BAR resources (assume others are special devices)
- The user has permissions to use
Assigning a bridge is a configuration error, it's not supported, and typically doesn't result in the behavior the user is expecting anyway. Devices without BAR resources are typically chipset components that also don't have host drivers. We don't want users to hold such devices captive or cause system problems by fencing them off into an iommu domain. We determine "permission to use" by testing whether the user has access to the PCI sysfs resource files. By default a normal user will not have access to these files, so it provides a good indication that an administration agent has granted the user access to the device.
[Yang Bai: add missing #include]
[avi: fix comment style]
--- Documentation/virtual/kvm/api.txt | 4 ++ virt/kvm/assigned-dev.c | 75 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 0 deletions(-)
Documentation/virtual/kvm/api.txt +4 -0
@@ -1134,6 +1134,10 @@ following flags are specified: The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure isolation of the device. Usages not specifying this flag are deprecated. +Only PCI header type 0 devices with PCI BAR resources are supported by +device assignment. The user requesting this ioctl must have read/write +access to the PCI sysfs resource files associated with the device. + 4.49 KVM_DEASSIGN_PCI_DEVICE Capability: KVM_CAP_DEVICE_DEASSIGNMENT
virt/kvm/assigned-dev.c +75 -0
99 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Quoted 2 lines · Avi Kivity
The following patches want to be applied to the 3.1 branch. "All users must update".
Do any of these also need to go to the 3.0 branch?
thanks,
greg k-h
Quoted 5 lines · Greg KH
Quoted 2 lines · Avi Kivity
The following patches want to be applied to the 3.1 branch. "All users must update".
Do any of these also need to go to the 3.0 branch?
Yes. But for kvm we regression test stable patches, and I haven't done this yet. I find the normal stable process, while very convenient, frightening.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Avi Kivity
Quoted 5 lines · Greg KH
Quoted 2 lines · Avi Kivity
The following patches want to be applied to the 3.1 branch. "All users must update".
Do any of these also need to go to the 3.0 branch?
Yes. But for kvm we regression test stable patches, and I haven't done this yet. I find the normal stable process, while very convenient, frightening.
What do you mean by this?
And thanks for the patches, they are all now queued up.
greg k-h