Allow enabling kvm_trace on external module
cover Allow enabling kvm_trace on external module
This series adds compat code to allow enabling kvm_trace when building KVM as an external module on older kernels.
The most hackish part is the last patch, that adds --with-kvm-trace to configure and adds an include to a generated file on kernel/x86/Kbuild. It doesn't look pretty, so suggestions on how to make this better are welcome.
PATCH 1/4 Add kvm_trace.c to hack-files-x86
We will add some hacks for kvm_trace.c on hack-module.awk
--- kernel/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/Makefile +1 -1
@@ -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))
Signature · 1 line
1.5.5.GIT
PATCH 2/4 Hack DEFINE_SIMPLE_ATTRIBUTE for lost_records_get() also
In reply to Eduardo HabkostChange the DEFINE_SIMPLE_ATTRIBUTE pattern to match the lost_records_get() definition also, so kvm_trace can compile on older kernels.
--- kernel/x86/hack-module.awk | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/x86/hack-module.awk +2 -2
@@ -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 ")" }
Signature · 1 line
1.5.5.GIT
PATCH 3/4 relay_open() compat
In reply to Eduardo HabkostOn 2.6.21 a new parameter was added to relay_open(). Handle this parameter on kvm_relay_open() if needed.
--- kernel/external-module-compat-comm.h | 19 +++++++++++++++++++ kernel/external-module-compat.c | 22 ++++++++++++++++++++++ kernel/x86/hack-module.awk | 2 ++ 3 files changed, 43 insertions(+), 0 deletions(-)
kernel/external-module-compat-comm.h +19 -0
@@ -533,3 +533,22 @@ struct pci_dev;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
kernel/external-module-compat.c +22 -0
@@ -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
kernel/x86/hack-module.awk +2 -0
@@ -73,6 +73,8 @@ BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \ } } +{ sub(/relay_open/, "kvm_relay_open") } + { print } /kvm_x86_ops->run/ {
Signature · 1 line
1.5.5.GIT
PATCH 4/4 Add --with-kvm-trace arg to configure
In reply to Eduardo Habkost./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.
--- .gitignore | 1 + configure | 11 +++++++++++ kernel/Makefile | 7 ++++++- kernel/x86/Kbuild | 4 ++++ 4 files changed, 22 insertions(+), 1 deletions(-)
.gitignore +1 -0
@@ -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
configure +11 -0
@@ -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=PREFIX where to install things ($prefix) --with-patched-kernel don't use external module + --with-kvm-trace Enable kvm_trace --kerneldir=DIR kernel 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
kernel/Makefile +6 -1
@@ -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
kernel/x86/Kbuild +4 -0
@@ -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 \
Signature · 1 line
1.5.5.GIT
Quoted 8 lines · Eduardo Habkost
This series adds compat code to allow enabling
kvm_tracewhen building KVM as an external module on older kernels.The most hackish part is the last patch, that adds --with-kvm-trace to configure and adds an include to a generated file on
kernel/x86/Kbuild. It doesn't look pretty, so suggestions on how to make this better are welcome.
Applied all, thanks. We could improve Kbuild by having kernel/Makefile include config.mak and pass some variable to Kbuild somehow, but diving into Kbuild isn't my idea of a week well spent.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 3/4] relay_open() compat
In reply to Eduardo Habkostkernel/x86/hack-module.awk BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \ · line 78
Quoted 7 lines · Eduardo Habkost
kernel/x86/hack-module.awk +2
-0@@ -73,6 +73,8 @@ BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \ } } +{ sub(/relay_open/, "kvm_relay_open") } +
I moved this bit into the compat_apis variable. Hope it still works.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Eduardo Habkost
This series adds compat code to allow enabling
kvm_tracewhen building KVM as an external module on older kernels.The most hackish part is the last patch, that adds --with-kvm-trace to configure and adds an include to a generated file on
kernel/x86/Kbuild. It doesn't look pretty, so suggestions on how to make this better are welcome.
Quoted 3 lines
Applied all, thanks. We could improve
Kbuildby having kernel/Makefile include config.mak and pass some variable toKbuildsomehow, but diving intoKbuildisn't my idea of a week well spent.
Oops. I've just noticed I broke './configure --with-patched-kernel'. Fix below.
---
From: Eduardo Habkost <[email protected]>
Date: Wed, 24 Sep 2008 14:11:42 -0300
Subject: Always generate config.kbuild
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.
--- configure | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
configure +0 -2
@@ -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
Signature · 5 lines
1.5.5.GIT -- Eduardo
Avi Kivity
AppliedQuoted 4 lines · Eduardo Habkost
From: Eduardo Habkost <[email protected]>
Date: Wed, 24 Sep 2008 14:11:42 -0300
Subject: Always generate config.kbuild
Quoted 8 lines
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.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function