Sorry, forgive me. I don't know how to reply the email like you.My linux kernel version is 3.11, and I do not touch the kvm makefile. Now let me show you in detail.
First I put the files of my module in " /arch/x86/logger ", "logger" is the directory I create. The Makefile in " /arch/x86/kvm/" I think is the Makefile of kvm. It is like this:
ccflags-y += -Ivirt/kvm -Iarch/x86/kvm
CFLAGS_x86.o := -I.
CFLAGS_svm.o := -I.
CFLAGS_vmx.o := -I.
KVM := ../../../virt/kvm
kvm-y += $(KVM)/kvm_main.o $(KVM)/ioapic.o \
$(KVM)/coalesced_mmio.o $(KVM)/irq_comm.o \
$(KVM)/eventfd.o $(KVM)/irqchip.o
kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += $(KVM)/assigned-dev.o $(KVM)/iommu.o
kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
i8254.o cpuid.o pmu.o
kvm-intel-y += vmx.o
kvm-amd-y += svm.o
obj-$(CONFIG_KVM) += kvm.o
obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
obj-$(CONFIG_KVM_AMD) += kvm-amd.o
And the Makefile of my module in "/arch/x86/logger" is like this:
ifneq ($(KERNELRELEASE),)
obj-m := logger.o
logger-objs := logger_main.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
rm -rf *.o *.ko *.mod.c
So I compile my module first by running "make", then insmod it. I don't install it because I don't know if it is necessary. Then I go to the root of my linux code, and run a shell containing "make modules". Then it will show that :
make -j 16 modules
make[1]: Nothing to be done for `all'.
CHK include/generated/uapi/linux/version.h
make[1]: Nothing to be done for `relocs'.
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CC [M] arch/x86/kvm/x86.o
LD [M] arch/x86/kvm/kvm.o
LD [M] arch/x86/kvm/kvm-intel.o
LD [M] arch/x86/kvm/kvm-amd.o
Building modules, stage 2.
MODPOST 2832 modules
ERROR: "print_record" [arch/x86/kvm/kvm.ko] undefined!
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2
rmmod kvm_intel
rmmod kvm
cp /home/tanle/study/replay/linux-log/linux-3.11-replay/arch/x86/kvm/kvm.ko /lib/modules/3.11.0+/kernel/arch/x86/kvm/kvm.ko
cp /home/tanle/study/replay/linux-log/linux-3.11-replay/arch/x86/kvm/kvm-intel.ko /lib/modules/3.11.0+/kernel/arch/x86/kvm/kvm-intel.ko
modprobe kvm
modprobe kvm_intel
Notice that I add two sentences to the /arch/x86/kvm/x86.c:
extern void print_record(char *format); //This functino is defined in my module, this sentence is global
print_record(NULL); //Call this function in the vcpu_enter_guest() function
So I don't know how to deal with this. I have poor knowledge about makefile and KBuild.
Thanks for helping me again!