Commit 3ae83945 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull KVM fixes from Paolo Bonzini:
 "Mostly stable material, a lot of ARM fixes"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (22 commits)
  sched: access local runqueue directly in single_task_running
  arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'
  arm64: KVM: Remove all traces of the ThumbEE registers
  arm: KVM: Disable virtual timer even if the guest is not using it
  arm64: KVM: Disable virtual timer even if the guest is not using it
  arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources
  KVM: s390: Replace incorrect atomic_or with atomic_andnot
  arm: KVM: Fix incorrect device to IPA mapping
  arm64: KVM: Fix user access for debug registers
  KVM: vmx: fix VPID is 0000H in non-root operation
  KVM: add halt_attempted_poll to VCPU stats
  kvm: fix zero length mmio searching
  kvm: fix double free for fast mmio eventfd
  kvm: factor out core eventfd assign/deassign logic
  kvm: don't try to register to KVM_FAST_MMIO_BUS for non mmio eventfd
  KVM: make the declaration of functions within 80 characters
  KVM: arm64: add workaround for Cortex-A57 erratum #852523
  KVM: fix polling for guest halt continued even if disable it
  arm/arm64: KVM: Fix PSCI affinity info return value for non valid cores
  arm64: KVM: set {v,}TCR_EL2 RES1 bits
  ...
parents fadb97b0 00cc1633
...@@ -6064,6 +6064,8 @@ static __init int hardware_setup(void) ...@@ -6064,6 +6064,8 @@ static __init int hardware_setup(void)
memcpy(vmx_msr_bitmap_longmode_x2apic, memcpy(vmx_msr_bitmap_longmode_x2apic,
vmx_msr_bitmap_longmode, PAGE_SIZE); vmx_msr_bitmap_longmode, PAGE_SIZE);
set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
if (enable_apicv) { if (enable_apicv) {
for (msr = 0x800; msr <= 0x8ff; msr++) for (msr = 0x800; msr <= 0x8ff; msr++)
vmx_disable_intercept_msr_read_x2apic(msr); vmx_disable_intercept_msr_read_x2apic(msr);
......
...@@ -149,6 +149,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { ...@@ -149,6 +149,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
{ "nmi_window", VCPU_STAT(nmi_window_exits) }, { "nmi_window", VCPU_STAT(nmi_window_exits) },
{ "halt_exits", VCPU_STAT(halt_exits) }, { "halt_exits", VCPU_STAT(halt_exits) },
{ "halt_successful_poll", VCPU_STAT(halt_successful_poll) }, { "halt_successful_poll", VCPU_STAT(halt_successful_poll) },
{ "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) },
{ "halt_wakeup", VCPU_STAT(halt_wakeup) }, { "halt_wakeup", VCPU_STAT(halt_wakeup) },
{ "hypercalls", VCPU_STAT(hypercalls) }, { "hypercalls", VCPU_STAT(hypercalls) },
{ "request_irq", VCPU_STAT(request_irq_exits) }, { "request_irq", VCPU_STAT(request_irq_exits) },
......
...@@ -35,11 +35,7 @@ ...@@ -35,11 +35,7 @@
#define VGIC_V3_MAX_LRS 16 #define VGIC_V3_MAX_LRS 16
#define VGIC_MAX_IRQS 1024 #define VGIC_MAX_IRQS 1024
#define VGIC_V2_MAX_CPUS 8 #define VGIC_V2_MAX_CPUS 8
#define VGIC_V3_MAX_CPUS 255
/* Sanity checks... */
#if (KVM_MAX_VCPUS > 255)
#error Too many KVM VCPUs, the VGIC only supports up to 255 VCPUs for now
#endif
#if (VGIC_NR_IRQS_LEGACY & 31) #if (VGIC_NR_IRQS_LEGACY & 31)
#error "VGIC_NR_IRQS must be a multiple of 32" #error "VGIC_NR_IRQS must be a multiple of 32"
......
...@@ -2669,13 +2669,20 @@ unsigned long nr_running(void) ...@@ -2669,13 +2669,20 @@ unsigned long nr_running(void)
/* /*
* Check if only the current task is running on the cpu. * Check if only the current task is running on the cpu.
*
* Caution: this function does not check that the caller has disabled
* preemption, thus the result might have a time-of-check-to-time-of-use
* race. The caller is responsible to use it correctly, for example:
*
* - from a non-preemptable section (of course)
*
* - from a thread that is bound to a single CPU
*
* - in a loop with very short iterations (e.g. a polling loop)
*/ */
bool single_task_running(void) bool single_task_running(void)
{ {
if (cpu_rq(smp_processor_id())->nr_running == 1) return raw_rq()->nr_running == 1;
return true;
else
return false;
} }
EXPORT_SYMBOL(single_task_running); EXPORT_SYMBOL(single_task_running);
......
...@@ -199,6 +199,14 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, ...@@ -199,6 +199,14 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
*/ */
timer->irq = irq; timer->irq = irq;
/*
* The bits in CNTV_CTL are architecturally reset to UNKNOWN for ARMv8
* and to 0 for ARMv7. We provide an implementation that always
* resets the timer to be disabled and unmasked and is compliant with
* the ARMv7 architecture.
*/
timer->cntv_ctl = 0;
/* /*
* Tell the VGIC that the virtual interrupt is tied to a * Tell the VGIC that the virtual interrupt is tied to a
* physical interrupt. We do that once per VCPU. * physical interrupt. We do that once per VCPU.
......
...@@ -288,7 +288,7 @@ int vgic_v3_probe(struct device_node *vgic_node, ...@@ -288,7 +288,7 @@ int vgic_v3_probe(struct device_node *vgic_node,
vgic->vctrl_base = NULL; vgic->vctrl_base = NULL;
vgic->type = VGIC_V3; vgic->type = VGIC_V3;
vgic->max_gic_vcpus = KVM_MAX_VCPUS; vgic->max_gic_vcpus = VGIC_V3_MAX_CPUS;
kvm_info("%s@%llx IRQ%d\n", vgic_node->name, kvm_info("%s@%llx IRQ%d\n", vgic_node->name,
vcpu_res.start, vgic->maint_irq); vcpu_res.start, vgic->maint_irq);
......
...@@ -1144,26 +1144,11 @@ static void vgic_queue_irq_to_lr(struct kvm_vcpu *vcpu, int irq, ...@@ -1144,26 +1144,11 @@ static void vgic_queue_irq_to_lr(struct kvm_vcpu *vcpu, int irq,
struct irq_phys_map *map; struct irq_phys_map *map;
map = vgic_irq_map_search(vcpu, irq); map = vgic_irq_map_search(vcpu, irq);
/*
* If we have a mapping, and the virtual interrupt is
* being injected, then we must set the state to
* active in the physical world. Otherwise the
* physical interrupt will fire and the guest will
* exit before processing the virtual interrupt.
*/
if (map) { if (map) {
int ret;
BUG_ON(!map->active);
vlr.hwirq = map->phys_irq; vlr.hwirq = map->phys_irq;
vlr.state |= LR_HW; vlr.state |= LR_HW;
vlr.state &= ~LR_EOI_INT; vlr.state &= ~LR_EOI_INT;
ret = irq_set_irqchip_state(map->irq,
IRQCHIP_STATE_ACTIVE,
true);
WARN_ON(ret);
/* /*
* Make sure we're not going to sample this * Make sure we're not going to sample this
* again, as a HW-backed interrupt cannot be * again, as a HW-backed interrupt cannot be
...@@ -1255,7 +1240,7 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) ...@@ -1255,7 +1240,7 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
struct vgic_dist *dist = &vcpu->kvm->arch.vgic; struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
unsigned long *pa_percpu, *pa_shared; unsigned long *pa_percpu, *pa_shared;
int i, vcpu_id; int i, vcpu_id, lr, ret;
int overflow = 0; int overflow = 0;
int nr_shared = vgic_nr_shared_irqs(dist); int nr_shared = vgic_nr_shared_irqs(dist);
...@@ -1310,6 +1295,31 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) ...@@ -1310,6 +1295,31 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)
*/ */
clear_bit(vcpu_id, dist->irq_pending_on_cpu); clear_bit(vcpu_id, dist->irq_pending_on_cpu);
} }
for (lr = 0; lr < vgic->nr_lr; lr++) {
struct vgic_lr vlr;
if (!test_bit(lr, vgic_cpu->lr_used))
continue;
vlr = vgic_get_lr(vcpu, lr);
/*
* If we have a mapping, and the virtual interrupt is
* presented to the guest (as pending or active), then we must
* set the state to active in the physical world. See
* Documentation/virtual/kvm/arm/vgic-mapped-irqs.txt.
*/
if (vlr.state & LR_HW) {
struct irq_phys_map *map;
map = vgic_irq_map_search(vcpu, vlr.irq);
ret = irq_set_irqchip_state(map->irq,
IRQCHIP_STATE_ACTIVE,
true);
WARN_ON(ret);
}
}
} }
static bool vgic_process_maintenance(struct kvm_vcpu *vcpu) static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)
......
...@@ -24,9 +24,9 @@ struct kvm_coalesced_mmio_dev { ...@@ -24,9 +24,9 @@ struct kvm_coalesced_mmio_dev {
int kvm_coalesced_mmio_init(struct kvm *kvm); int kvm_coalesced_mmio_init(struct kvm *kvm);
void kvm_coalesced_mmio_free(struct kvm *kvm); void kvm_coalesced_mmio_free(struct kvm *kvm);
int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm, int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
struct kvm_coalesced_mmio_zone *zone); struct kvm_coalesced_mmio_zone *zone);
int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm, int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
struct kvm_coalesced_mmio_zone *zone); struct kvm_coalesced_mmio_zone *zone);
#else #else
......
...@@ -771,40 +771,14 @@ static enum kvm_bus ioeventfd_bus_from_flags(__u32 flags) ...@@ -771,40 +771,14 @@ static enum kvm_bus ioeventfd_bus_from_flags(__u32 flags)
return KVM_MMIO_BUS; return KVM_MMIO_BUS;
} }
static int static int kvm_assign_ioeventfd_idx(struct kvm *kvm,
kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) enum kvm_bus bus_idx,
struct kvm_ioeventfd *args)
{ {
enum kvm_bus bus_idx;
struct _ioeventfd *p;
struct eventfd_ctx *eventfd;
int ret;
bus_idx = ioeventfd_bus_from_flags(args->flags);
/* must be natural-word sized, or 0 to ignore length */
switch (args->len) {
case 0:
case 1:
case 2:
case 4:
case 8:
break;
default:
return -EINVAL;
}
/* check for range overflow */
if (args->addr + args->len < args->addr)
return -EINVAL;
/* check for extra flags that we don't understand */ struct eventfd_ctx *eventfd;
if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK) struct _ioeventfd *p;
return -EINVAL; int ret;
/* ioeventfd with no length can't be combined with DATAMATCH */
if (!args->len &&
args->flags & (KVM_IOEVENTFD_FLAG_PIO |
KVM_IOEVENTFD_FLAG_DATAMATCH))
return -EINVAL;
eventfd = eventfd_ctx_fdget(args->fd); eventfd = eventfd_ctx_fdget(args->fd);
if (IS_ERR(eventfd)) if (IS_ERR(eventfd))
...@@ -843,16 +817,6 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) ...@@ -843,16 +817,6 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
if (ret < 0) if (ret < 0)
goto unlock_fail; goto unlock_fail;
/* When length is ignored, MMIO is also put on a separate bus, for
* faster lookups.
*/
if (!args->len && !(args->flags & KVM_IOEVENTFD_FLAG_PIO)) {
ret = kvm_io_bus_register_dev(kvm, KVM_FAST_MMIO_BUS,
p->addr, 0, &p->dev);
if (ret < 0)
goto register_fail;
}
kvm->buses[bus_idx]->ioeventfd_count++; kvm->buses[bus_idx]->ioeventfd_count++;
list_add_tail(&p->list, &kvm->ioeventfds); list_add_tail(&p->list, &kvm->ioeventfds);
...@@ -860,8 +824,6 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) ...@@ -860,8 +824,6 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
return 0; return 0;
register_fail:
kvm_io_bus_unregister_dev(kvm, bus_idx, &p->dev);
unlock_fail: unlock_fail:
mutex_unlock(&kvm->slots_lock); mutex_unlock(&kvm->slots_lock);
...@@ -873,14 +835,13 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) ...@@ -873,14 +835,13 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
} }
static int static int
kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
struct kvm_ioeventfd *args)
{ {
enum kvm_bus bus_idx;
struct _ioeventfd *p, *tmp; struct _ioeventfd *p, *tmp;
struct eventfd_ctx *eventfd; struct eventfd_ctx *eventfd;
int ret = -ENOENT; int ret = -ENOENT;
bus_idx = ioeventfd_bus_from_flags(args->flags);
eventfd = eventfd_ctx_fdget(args->fd); eventfd = eventfd_ctx_fdget(args->fd);
if (IS_ERR(eventfd)) if (IS_ERR(eventfd))
return PTR_ERR(eventfd); return PTR_ERR(eventfd);
...@@ -901,10 +862,6 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) ...@@ -901,10 +862,6 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
continue; continue;
kvm_io_bus_unregister_dev(kvm, bus_idx, &p->dev); kvm_io_bus_unregister_dev(kvm, bus_idx, &p->dev);
if (!p->length) {
kvm_io_bus_unregister_dev(kvm, KVM_FAST_MMIO_BUS,
&p->dev);
}
kvm->buses[bus_idx]->ioeventfd_count--; kvm->buses[bus_idx]->ioeventfd_count--;
ioeventfd_release(p); ioeventfd_release(p);
ret = 0; ret = 0;
...@@ -918,6 +875,71 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) ...@@ -918,6 +875,71 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
return ret; return ret;
} }
static int kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
{
enum kvm_bus bus_idx = ioeventfd_bus_from_flags(args->flags);
int ret = kvm_deassign_ioeventfd_idx(kvm, bus_idx, args);
if (!args->len && bus_idx == KVM_MMIO_BUS)
kvm_deassign_ioeventfd_idx(kvm, KVM_FAST_MMIO_BUS, args);
return ret;
}
static int
kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
{
enum kvm_bus bus_idx;
int ret;
bus_idx = ioeventfd_bus_from_flags(args->flags);
/* must be natural-word sized, or 0 to ignore length */
switch (args->len) {
case 0:
case 1:
case 2:
case 4:
case 8:
break;
default:
return -EINVAL;
}
/* check for range overflow */
if (args->addr + args->len < args->addr)
return -EINVAL;
/* check for extra flags that we don't understand */
if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK)
return -EINVAL;
/* ioeventfd with no length can't be combined with DATAMATCH */
if (!args->len &&
args->flags & (KVM_IOEVENTFD_FLAG_PIO |
KVM_IOEVENTFD_FLAG_DATAMATCH))
return -EINVAL;
ret = kvm_assign_ioeventfd_idx(kvm, bus_idx, args);
if (ret)
goto fail;
/* When length is ignored, MMIO is also put on a separate bus, for
* faster lookups.
*/
if (!args->len && bus_idx == KVM_MMIO_BUS) {
ret = kvm_assign_ioeventfd_idx(kvm, KVM_FAST_MMIO_BUS, args);
if (ret < 0)
goto fast_fail;
}
return 0;
fast_fail:
kvm_deassign_ioeventfd_idx(kvm, bus_idx, args);
fail:
return ret;
}
int int
kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
{ {
......
...@@ -2004,6 +2004,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) ...@@ -2004,6 +2004,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
if (vcpu->halt_poll_ns) { if (vcpu->halt_poll_ns) {
ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns);
++vcpu->stat.halt_attempted_poll;
do { do {
/* /*
* This sets KVM_REQ_UNHALT if an interrupt * This sets KVM_REQ_UNHALT if an interrupt
...@@ -2043,7 +2044,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) ...@@ -2043,7 +2044,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
else if (vcpu->halt_poll_ns < halt_poll_ns && else if (vcpu->halt_poll_ns < halt_poll_ns &&
block_ns < halt_poll_ns) block_ns < halt_poll_ns)
grow_halt_poll_ns(vcpu); grow_halt_poll_ns(vcpu);
} } else
vcpu->halt_poll_ns = 0;
trace_kvm_vcpu_wakeup(block_ns, waited); trace_kvm_vcpu_wakeup(block_ns, waited);
} }
...@@ -3156,10 +3158,25 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus) ...@@ -3156,10 +3158,25 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
static inline int kvm_io_bus_cmp(const struct kvm_io_range *r1, static inline int kvm_io_bus_cmp(const struct kvm_io_range *r1,
const struct kvm_io_range *r2) const struct kvm_io_range *r2)
{ {
if (r1->addr < r2->addr) gpa_t addr1 = r1->addr;
gpa_t addr2 = r2->addr;
if (addr1 < addr2)
return -1; return -1;
if (r1->addr + r1->len > r2->addr + r2->len)
/* If r2->len == 0, match the exact address. If r2->len != 0,
* accept any overlapping write. Any order is acceptable for
* overlapping ranges, because kvm_io_bus_get_first_dev ensures
* we process all of them.
*/
if (r2->len) {
addr1 += r1->len;
addr2 += r2->len;
}
if (addr1 > addr2)
return 1; return 1;
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment