[PATCH] kvm: external module: relay_open() compat
From: Eduardo Habkost [EMAIL PROTECTED] On 2.6.21 a new parameter was added to relay_open(). Handle this parameter on kvm_relay_open() if needed. Signed-off-by: Eduardo Habkost [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/kernel/external-module-compat-comm.h b/kernel/external-module-compat-comm.h index 2499277..30d17fa 100644 --- a/kernel/external-module-compat-comm.h +++ b/kernel/external-module-compat-comm.h @@ -532,6 +532,25 @@ struct pci_dev *pci_get_bus_and_slot(unsigned int bus, unsigned int devfn); #endif +#if LINUX_VERSION_CODE KERNEL_VERSION(2,6,21) + +#include linux/relay.h + +/* relay_open() interface has changed on 2.6.21 */ + +struct rchan *kvm_relay_open(const char *base_filename, +struct dentry *parent, +size_t subbuf_size, +size_t n_subbufs, +struct rchan_callbacks *cb, +void *private_data); + +#else + +#define kvm_relay_open relay_open + +#endif + #if LINUX_VERSION_CODE KERNEL_VERSION(2,6,27) static inline int get_user_pages_fast(unsigned long start, int nr_pages, diff --git a/kernel/external-module-compat.c b/kernel/external-module-compat.c index 4b9a9f2..c0a0355 100644 --- a/kernel/external-module-compat.c +++ b/kernel/external-module-compat.c @@ -276,3 +276,25 @@ int intel_iommu_found() } #endif + + +#if LINUX_VERSION_CODE KERNEL_VERSION(2,6,21) + +/* relay_open() interface has changed on 2.6.21 */ + +struct rchan *kvm_relay_open(const char *base_filename, +struct dentry *parent, +size_t subbuf_size, +size_t n_subbufs, +struct rchan_callbacks *cb, +void *private_data) +{ + struct rchan *chan = relay_open(base_filename, parent, + subbuf_size, n_subbufs, + cb); + if (chan) + chan-private_data = private_data; + return chan; +} + +#endif diff --git a/kernel/x86/hack-module.awk b/kernel/x86/hack-module.awk index 7f59483..c3fa51e 100644 --- a/kernel/x86/hack-module.awk +++ b/kernel/x86/hack-module.awk @@ -1,5 +1,5 @@ BEGIN { split(INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr \ - on_each_cpu , compat_apis); } + on_each_cpu relay_open , compat_apis); } /^int kvm_init\(/ { anon_inodes = 1 } -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: external module: spin_needbreak() compat
From: Avi Kivity [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/kernel/external-module-compat-comm.h b/kernel/external-module-compat-comm.h index 30d17fa..76ddca3 100644 --- a/kernel/external-module-compat-comm.h +++ b/kernel/external-module-compat-comm.h @@ -567,3 +567,11 @@ static inline int get_user_pages_fast(unsigned long start, int nr_pages, } #endif + +/* spin_needbreak() was called something else in 2.6.24 */ +#if LINUX_VERSION_CODE = KERNEL_VERSION(2,6,24) + +#define spin_needbreak need_lockbreak + +#endif + -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: external module: Hack DEFINE_SIMPLE_ATTRIBUTE for lost_records_get() also
From: Eduardo Habkost [EMAIL PROTECTED] Change the DEFINE_SIMPLE_ATTRIBUTE pattern to match the lost_records_get() definition also, so kvm_trace can compile on older kernels. Signed-off-by: Eduardo Habkost [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/kernel/x86/hack-module.awk b/kernel/x86/hack-module.awk index 3f364f8..7f59483 100644 --- a/kernel/x86/hack-module.awk +++ b/kernel/x86/hack-module.awk @@ -42,11 +42,11 @@ BEGIN { split(INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr \ $0 = \t.VMA_OPS_FAULT(fault) = VMA_OPS_FAULT_FUNC( fcn ), } -/^static int .*_stat_get/ { +/^static int (.*_stat_get|lost_records_get)/ { $3 = __ $3 } -/DEFINE_SIMPLE_ATTRIBUTE.*_stat_get/ { +/DEFINE_SIMPLE_ATTRIBUTE.*(_stat_get|lost_records_get)/ { name = gensub(/,/, , g, $2); print MAKE_SIMPLE_ATTRIBUTE_GETTER( name ) } -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: external module: add --with-kvm-trace arg to configure
From: Eduardo Habkost [EMAIL PROTECTED] /configure --with-kvm-trace will set a CONFIG_KVM_TRACE option on a kernel/config.kbuild file. This file can be included from the Kbuild files to get kvm-specific CONFIG_* definitions. Signed-off-by: Eduardo Habkost [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/.gitignore b/.gitignore index bb35cca..0cabc17 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ vgabios/*.txt extboot/extboot.bin extboot/extboot.img extboot/signrom +kernel/config.kbuild kernel/modules.order kernel/Module.symvers kernel/Modules.symvers diff --git a/configure b/configure index 3bb10ce..78c2f9c 100755 --- a/configure +++ b/configure @@ -8,6 +8,7 @@ objcopy=objcopy want_module=1 qemu_cflags= qemu_ldflags= +kvm_trace= qemu_opts=() cross_prefix= arch=`uname -m` @@ -22,6 +23,7 @@ usage() { --cross-prefix=PREFIX prefix for cross compile --prefix=PREFIXwhere to install things ($prefix) --with-patched-kernel don't use external module + --with-kvm-trace Enable kvm_trace --kerneldir=DIRkernel build directory ($kerneldir) --qemu-cflags=CFLAGS CFLAGS to add to qemu configuration --qemu-ldflags=LDFLAGS LDFLAGS to add to qemu configuration @@ -56,6 +58,9 @@ while [[ $1 = -* ]]; do --with-patched-kernel) want_module= ;; + --with-kvm-trace) + kvm_trace=y + ;; --qemu-cflags) qemu_cflags=$arg ;; @@ -131,3 +136,9 @@ CC=$cross_prefix$cc LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy EOF + +if [ -n $want_module ];then +cat EOF kernel/config.kbuild +CONFIG_KVM_TRACE=$kvm_trace +EOF +fi diff --git a/kernel/Makefile b/kernel/Makefile index 151183a..9842dab 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,4 +1,5 @@ include ../config.mak +include config.kbuild ARCH_DIR = $(if $(filter $(ARCH),x86_64 i386),x86,$(ARCH)) ARCH_CONFIG := $(shell echo $(ARCH_DIR) | tr '[:lower:]' '[:upper:]') @@ -33,12 +34,16 @@ hack-files-ia64 = kvm_main.c kvm_fw.c hack-files = $(hack-files-$(ARCH_DIR)) +ifeq ($(CONFIG_KVM_TRACE),y) +module_defines += -DCONFIG_KVM_TRACE=y +endif + all:: header-link prerequisite # include header priority 1) $LINUX 2) $KERNELDIR 3) include-compat $(MAKE) -C $(KERNELDIR) M=`pwd` \ LINUXINCLUDE=-I`pwd`/include -Iinclude -Iarch/${ARCH_DIR}/include -I`pwd`/include-compat \ -include include/linux/autoconf.h \ - -include `pwd`/$(ARCH_DIR)/external-module-compat.h + -include `pwd`/$(ARCH_DIR)/external-module-compat.h $(module_defines) $$@ sync: header-sync source-sync header-link diff --git a/kernel/x86/Kbuild b/kernel/x86/Kbuild index 8dc0483..bc584f9 100644 --- a/kernel/x86/Kbuild +++ b/kernel/x86/Kbuild @@ -1,3 +1,7 @@ +# trick to get the kvm-specific CONFIG_KVM_* definitions, +# because the kernel source tree won't have them +include $(obj)/../config.kbuild + obj-m := kvm.o kvm-intel.o kvm-amd.o kvm-objs := kvm_main.o x86.o mmu.o x86_emulate.o ../anon_inodes.o irq.o i8259.o \ lapic.o ioapic.o preempt.o i8254.o coalesced_mmio.o \ -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: external module: add kvm_trace.c to hack-files-x86
From: Eduardo Habkost [EMAIL PROTECTED] We will add some hacks for kvm_trace.c on hack-module.awk Signed-off-by: Eduardo Habkost [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/kernel/Makefile b/kernel/Makefile index 3f5f6da..151183a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -28,7 +28,7 @@ unifdef = mv $1 $1.orig \ hack = $(call _hack,$T/$(strip $1)) -hack-files-x86 = kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c i8254.c +hack-files-x86 = kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c i8254.c kvm_trace.c hack-files-ia64 = kvm_main.c kvm_fw.c hack-files = $(hack-files-$(ARCH_DIR)) -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: external module: always generate config.kbuild
From: Eduardo Habkost [EMAIL PROTECTED] When implementing --with-kvm-trace, I supposed make would never enter the 'kernel' directory when compiling with --with-patched-kernel. I was wrong and broke --with-patched-kernel. Change configure to always generate config.kbuild on the kernel directory. Otherwise make will explode on 'make header-sync', that runs even when --with-patched-kernel was used. Signed-off-by: Eduardo Habkost [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/configure b/configure index 78c2f9c..3b27364 100755 --- a/configure +++ b/configure @@ -137,8 +137,6 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy EOF -if [ -n $want_module ];then cat EOF kernel/config.kbuild CONFIG_KVM_TRACE=$kvm_trace EOF -fi -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm: qemu: avoid allocating codegen buffer if kvm is enabled
From: Avi Kivity [EMAIL PROTECTED] Suggested by Anthony Liguori. Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/qemu/exec.c b/qemu/exec.c index cf9c99c..5a2554d 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -407,9 +407,8 @@ static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE]; static void code_gen_alloc(unsigned long tb_size) { -#ifdef TARGET_IA64 -return; -#endif +if (kvm_enabled()) +return; #ifdef USE_STATIC_CODE_GEN_BUFFER code_gen_buffer = static_code_gen_buffer; -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] KVM: MMU: do not write-protect large mappings
From: Marcelo Tosatti [EMAIL PROTECTED] There is not much point in write protecting large mappings. This can only happen when a page is shadowed during the window between is_largepage_backed and mmu_lock acquision. Zap the entry instead, so the next pagefault will find a shadowed page via is_largepage_backed and fallback to 4k translations. Simplifies out of sync shadow. Signed-off-by: Marcelo Tosatti [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 23752ef..731e6fe 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1180,11 +1180,16 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte, || (write_fault !is_write_protection(vcpu) !user_fault)) { struct kvm_mmu_page *shadow; + if (largepage has_wrprotected_page(vcpu-kvm, gfn)) { + ret = 1; + spte = shadow_trap_nonpresent_pte; + goto set_pte; + } + spte |= PT_WRITABLE_MASK; shadow = kvm_mmu_lookup_page(vcpu-kvm, gfn); - if (shadow || - (largepage has_wrprotected_page(vcpu-kvm, gfn))) { + if (shadow) { pgprintk(%s: found shadow page for %lx, marking ro\n, __func__, gfn); ret = 1; @@ -1197,6 +1202,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte, if (pte_access ACC_WRITE_MASK) mark_page_dirty(vcpu-kvm, gfn); +set_pte: set_shadow_pte(shadow_pte, spte); return ret; } -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] KVM: PIC: enhance IPI avoidance
From: Marcelo Tosatti [EMAIL PROTECTED] The PIC code makes little effort to avoid kvm_vcpu_kick(), resulting in unnecessary guest exits in some conditions. For example, if the timer interrupt is routed through the IOAPIC, IRR for IRQ 0 will get set but not cleared, since the APIC is handling the acks. This means that everytime an interrupt 16 is triggered, the priority logic will find IRQ0 pending and send an IPI to vcpu0 (in case IRQ0 is not masked, which is Linux's case). Introduce a new variable isr_ack to represent the IRQ's for which the guest has been signalled / cleared the ISR. Use it to avoid more than one IPI per trigger-ack cycle, in addition to the avoidance when ISR is set in get_priority(). Signed-off-by: Marcelo Tosatti [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index 71e3eee..17e41e1 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -33,6 +33,14 @@ static void pic_clear_isr(struct kvm_kpic_state *s, int irq) { s-isr = ~(1 irq); + s-isr_ack |= (1 irq); +} + +void kvm_pic_clear_isr_ack(struct kvm *kvm) +{ + struct kvm_pic *s = pic_irqchip(kvm); + s-pics[0].isr_ack = 0xff; + s-pics[1].isr_ack = 0xff; } /* @@ -213,6 +221,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s) s-irr = 0; s-imr = 0; s-isr = 0; + s-isr_ack = 0xff; s-priority_add = 0; s-irq_base = 0; s-read_reg_select = 0; @@ -444,10 +453,14 @@ static void pic_irq_request(void *opaque, int level) { struct kvm *kvm = opaque; struct kvm_vcpu *vcpu = kvm-vcpus[0]; + struct kvm_pic *s = pic_irqchip(kvm); + int irq = pic_get_irq(s-pics[0]); - pic_irqchip(kvm)-output = level; - if (vcpu) + s-output = level; + if (vcpu level (s-pics[0].isr_ack (1 irq))) { + s-pics[0].isr_ack = ~(1 irq); kvm_vcpu_kick(vcpu); + } } struct kvm_pic *kvm_create_pic(struct kvm *kvm) diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h index 479a3d2..4748532 100644 --- a/arch/x86/kvm/irq.h +++ b/arch/x86/kvm/irq.h @@ -42,6 +42,7 @@ struct kvm_kpic_state { u8 irr; /* interrupt request register */ u8 imr; /* interrupt mask register */ u8 isr; /* interrupt service register */ + u8 isr_ack; /* interrupt ack detection */ u8 priority_add;/* highest irq priority */ u8 irq_base; u8 read_reg_select; @@ -70,6 +71,7 @@ struct kvm_pic *kvm_create_pic(struct kvm *kvm); void kvm_pic_set_irq(void *opaque, int irq, int level); int kvm_pic_read_irq(struct kvm *kvm); void kvm_pic_update_irq(struct kvm_pic *s); +void kvm_pic_clear_isr_ack(struct kvm *kvm); static inline struct kvm_pic *pic_irqchip(struct kvm *kvm) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1c5864a..4cfdd1b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3963,6 +3963,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, pr_debug(Set back pending irq %d\n, pending_vec); } + kvm_pic_clear_isr_ack(vcpu-kvm); } kvm_set_segment(vcpu, sregs-cs, VCPU_SREG_CS); -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] KVM: MMU: add oos_shadow parameter to disable oos
From: Marcelo Tosatti [EMAIL PROTECTED] Subject says it all. Signed-off-by: Marcelo Tosatti [EMAIL PROTECTED] Signed-off-by: Avi Kivity [EMAIL PROTECTED] diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 6ddb16c..9ff8d90 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -70,6 +70,9 @@ static int dbg = 0; module_param(dbg, bool, 0644); #endif +static int oos_shadow = 1; +module_param(oos_shadow, bool, 0644); + #ifndef MMU_DEBUG #define ASSERT(x) do { } while (0) #else @@ -1424,7 +1427,7 @@ static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn, return 1; if (shadow-unsync) return 0; - if (can_unsync) + if (can_unsync oos_shadow) return kvm_unsync_page(vcpu, shadow); return 1; } -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html