[RFC PATCH 3/4] KVM: x86: Add EOI exit bitmap inference

2015-05-12 Thread Steve Rutherford
In order to support a userspace IOAPIC interacting with an in kernel
APIC, the EOI exit bitmaps need to be configurable.

If the IOAPIC is in userspace (i.e. the irqchip has been split), the
EOI exit bitmaps will be set whenever the GSI Routes are configured.
In particular, for the low 24 MSI routes, the EOI Exit bit
corresponding to the destination vector will be set for the
destination VCPU.

The intention is for the userspace IOAPIC to use MSI routes [0,23] to
inject interrupts into the guest.

This is a slight abuse of the notion of an MSI Route, given that MSIs
classically bypass the IOAPIC. It might be worthwhile to add an
additional route type to improve clarity.

Compile tested for Intel x86.

Signed-off-by: Steve Rutherford srutherf...@google.com
---
 arch/x86/kvm/ioapic.c| 11 +++
 arch/x86/kvm/ioapic.h|  1 +
 arch/x86/kvm/lapic.c |  2 ++
 arch/x86/kvm/x86.c   | 13 +++--
 include/linux/kvm_host.h |  4 
 virt/kvm/irqchip.c   | 32 
 6 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 856f791..3323c86 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -672,3 +672,14 @@ int kvm_set_ioapic(struct kvm *kvm, struct 
kvm_ioapic_state *state)
spin_unlock(ioapic-lock);
return 0;
 }
+
+void kvm_vcpu_request_scan_userspace_ioapic(struct kvm *kvm)
+{
+   struct kvm_ioapic *ioapic = kvm-arch.vioapic;
+
+   if (ioapic)
+   return;
+   if (!lapic_in_kernel(kvm))
+   return;
+   kvm_make_scan_ioapic_request(kvm);
+}
diff --git a/arch/x86/kvm/ioapic.h b/arch/x86/kvm/ioapic.h
index ca0b0b4..b7af71b 100644
--- a/arch/x86/kvm/ioapic.h
+++ b/arch/x86/kvm/ioapic.h
@@ -123,4 +123,5 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state 
*state);
 void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
u32 *tmr);
 
+void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
 #endif
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 42fada6f..7533b87 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -211,6 +211,8 @@ out:
 
if (!irqchip_split(kvm))
kvm_vcpu_request_scan_ioapic(kvm);
+   else
+   kvm_vcpu_request_scan_userspace_ioapic(kvm);
 }
 
 static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cc27c35..6127fe7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6335,8 +6335,17 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
goto out;
}
}
-   if (kvm_check_request(KVM_REQ_SCAN_IOAPIC, vcpu))
-   vcpu_scan_ioapic(vcpu);
+   if (kvm_check_request(KVM_REQ_SCAN_IOAPIC, vcpu)) {
+   if (irqchip_split(vcpu-kvm)) {
+   memset(vcpu-arch.eoi_exit_bitmaps, 0, 32);
+   kvm_scan_ioapic_routes(
+   vcpu, vcpu-arch.eoi_exit_bitmaps);
+   kvm_x86_ops-load_eoi_exitmap(
+   vcpu, vcpu-arch.eoi_exit_bitmaps);
+
+   } else
+   vcpu_scan_ioapic(vcpu);
+   }
if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))
kvm_vcpu_reload_apic_access_page(vcpu);
}
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index cef20ad..678215a 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -438,10 +438,14 @@ void vcpu_put(struct kvm_vcpu *vcpu);
 
 #ifdef __KVM_HAVE_IOAPIC
 void kvm_vcpu_request_scan_ioapic(struct kvm *kvm);
+void kvm_vcpu_request_scan_userspace_ioapic(struct kvm *kvm);
 #else
 static inline void kvm_vcpu_request_scan_ioapic(struct kvm *kvm)
 {
 }
+static inline void kvm_vcpu_request_scan_userspace_ioapic(struct kvm *kvm)
+{
+}
 #endif
 
 #ifdef CONFIG_HAVE_KVM_IRQFD
diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c
index 8aaceed..8a253aa 100644
--- a/virt/kvm/irqchip.c
+++ b/virt/kvm/irqchip.c
@@ -205,6 +205,8 @@ int kvm_set_irq_routing(struct kvm *kvm,
 
synchronize_srcu_expedited(kvm-irq_srcu);
 
+   kvm_vcpu_request_scan_userspace_ioapic(kvm);
+
new = old;
r = 0;
 
@@ -212,3 +214,33 @@ out:
kfree(new);
return r;
 }
+
+void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
+{
+   struct kvm *kvm = vcpu-kvm;
+   struct kvm_kernel_irq_routing_entry *entry;
+   struct kvm_irq_routing_table *table;
+   u32 i, nr_rt_entries;
+
+   mutex_lock(kvm-irq_lock);
+   table = kvm-irq_routing;
+   nr_rt_entries = min_t(u32, table-nr_rt_entries, IOAPIC_NUM_PINS);
+   for (i = 0; i  nr_rt_entries; ++i) {
+   

[PATCH v2] KVM: x86: add module parameter to disable periodic kvmclock sync

2015-05-12 Thread Marcelo Tosatti

The periodic kvmclock sync can be an undesired source of latencies.

When running cyclictest on a guest, a latency spike is visible.
With kvmclock periodic sync disabled, the spike is gone.

Guests should use ntp which means the propagations of ntp corrections
from the host clock are unnecessary.

v2:
- Make parameter read-only (Radim)
- Return early on kvmclock_sync_fn (Andrew)

Reported-and-tested-by: Luiz Capitulino lcapitul...@redhat.com
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 986b3f5..4c0c954 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -99,6 +99,9 @@ module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
 unsigned int min_timer_period_us = 500;
 module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
 
+static bool __read_mostly kvmclock_periodic_sync = true;
+module_param(kvmclock_periodic_sync, bool, S_IRUGO);
+
 bool kvm_has_tsc_control;
 EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
 u32  kvm_max_guest_tsc_khz;
@@ -1768,6 +1771,9 @@ static void kvmclock_sync_fn(struct work_struct *work)
   kvmclock_sync_work);
struct kvm *kvm = container_of(ka, struct kvm, arch);
 
+   if (!kvmclock_periodic_sync)
+   return;
+
schedule_delayed_work(kvm-arch.kvmclock_update_work, 0);
schedule_delayed_work(kvm-arch.kvmclock_sync_work,
KVMCLOCK_SYNC_PERIOD);
@@ -7109,6 +7115,9 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
kvm_write_tsc(vcpu, msr);
vcpu_put(vcpu);
 
+   if (!kvmclock_periodic_sync)
+   return;
+
schedule_delayed_work(kvm-arch.kvmclock_sync_work,
KVMCLOCK_SYNC_PERIOD);
 }
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/9] KVM: MMU: introduce for_each_rmap_spte()

2015-05-12 Thread Xiao Guangrong



On 05/12/2015 04:08 PM, Paolo Bonzini wrote:



On 12/05/2015 04:32, Xiao Guangrong wrote:

-   while ((sptep = rmap_get_first(*rmapp, iter))) {
-   BUG_ON(!(*sptep  PT_PRESENT_MASK));
+restart:
+   for_each_rmap_spte(rmapp, iter, sptep) {
rmap_printk(kvm_rmap_unmap_hva: spte %p %llx gfn %llx (%d)\n,
 sptep, *sptep, gfn, level);

drop_spte(kvm, sptep);
need_tlb_flush = 1;
+   goto restart;
}



For this one, I would keep using rmap_get_first.  Otherwise looks good.

Paolo



Okay, will do.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 0/8] vhost: support for cross endian guests

2015-05-12 Thread Michael S. Tsirkin
On Tue, May 12, 2015 at 12:44:26PM +0200, Greg Kurz wrote:
 On Fri, 24 Apr 2015 15:31:54 +0200
 Michael S. Tsirkin m...@redhat.com wrote:
 
  On Fri, Apr 24, 2015 at 02:24:15PM +0200, Greg Kurz wrote:
   Only cosmetic and documentation changes since v5.
   
   ---
  
  Looks sane to me. I plan to review and apply next week.
  
 
 Hi Michael,
 
 I realize you just got back and have tons of things to do... Do
 you still plan to apply shortly ? Would you also have time to
 comment the QEMU part ?
 
 Thanks.
 
 --
 Greg

Yes, sorry about the delay - I also got virtio upstream landed on my lap.
I'll do my best to prioritize.

   Greg Kurz (8):
 virtio: introduce virtio_is_little_endian() helper
 tun: add tun_is_little_endian() helper
 macvtap: introduce macvtap_is_little_endian() helper
 vringh: introduce vringh_is_little_endian() helper
 vhost: introduce vhost_is_little_endian() helper
 virtio: add explicit big-endian support to memory accessors
 vhost: cross-endian support for legacy devices
 macvtap/tun: cross-endian support for little-endian hosts
   
   
drivers/net/Kconfig  |   14 ++
drivers/net/macvtap.c|   66 +-
drivers/net/tun.c|   68 ++
drivers/vhost/Kconfig|   15 +++
drivers/vhost/vhost.c|   85 
   ++
drivers/vhost/vhost.h|   25 ---
include/linux/virtio_byteorder.h |   24 ++-
include/linux/virtio_config.h|   18 +---
include/linux/vringh.h   |   18 +---
include/uapi/linux/if_tun.h  |6 +++
include/uapi/linux/vhost.h   |   14 ++
11 files changed, 320 insertions(+), 33 deletions(-)
   
   --
   Greg
  
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html