public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <andrea@qumranet.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm-devel@lists.sourceforge.net, Chris Lalancette <clalance@redhat.com>
Subject: Re: Broken external module build on 2.6.23
Date: Mon, 11 Feb 2008 12:19:44 +0100	[thread overview]
Message-ID: <20080211111944.GG7051@v2.random> (raw)
In-Reply-To: <47B00400.3010306@qumranet.com>

On Mon, Feb 11, 2008 at 10:14:56AM +0200, Avi Kivity wrote:
> What happens if you compile kvm against a kernel that doesn't have 
> linux/cmpxchg.h?
>
>> diff --git a/kernel/include/linux/anon_inodes.h 
>> b/kernel/include/linux/anon_inodes.h
>> deleted file mode 100644
>> index b2e1ba3..0000000
>> --- a/kernel/include/linux/anon_inodes.h
>> +++ /dev/null
>> @@ -1,16 +0,0 @@
>> -/*
>> - *  include/linux/anon_inodes.h
>> - *
>> - *  Copyright (C) 2007  Davide Libenzi <davidel@xmailserver.org>
>> - *
>> - */
>>   
>
> Or linux/anon_inodes.h?  etc.

Yes, the patch wasn't complete, it was primarily to show the idea to
remove the fragile dependency on exact #include order in the
headers. If the only trouble is the lack of build for older kernels I
guess I can proceed to add that last bit. Those compat files for old
kernels should be added to a brand new include-compat directory
instead of being mixed with the kvm headers and -Iinclude-compat can
be added at the end of the LINUXINCLUDES definition.

$LINUX kvm headers should be included before the $KERNELDIR headers,
and include-compat should be included after the $KERNELDIR headers.

I created a more complete patch below, this will solve all my silent
time-wasting miscompilations (currnently when building kvm.git on a
newer mainline kernels, certain kvm*.h $KERNELDIR headers are included
instead of my modified ones in $LINUX, so the build can crash if
$LINUX and $KERNELDIR don't have the kvm*.h headers in sync) and this
below patch will retain compatibility with older kernels too. If patch
doesn't wipe kernel/include you can follow it with a rm -r
kernel/include. I verified libkvm already gives more priority to
whatever is in kernel/include and only if kernel/include are missing
it uses the kvm.h in /usr/include/linux/kvm.h (I filled all my
/usr/src and /usr/include headers with #error "x" to be sure... along
with running gcc -E and checking the cpp work).

Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>

diff -urN 1/kernel/include/asm-x86/cmpxchg.h 2/kernel/include/asm-x86/cmpxchg.h
--- 1/kernel/include/asm-x86/cmpxchg.h	2008-02-11 12:00:19.000000000 +0100
+++ 2/kernel/include/asm-x86/cmpxchg.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,5 +0,0 @@
-/*
- * Empty file to satisfy #include <linux/cmpxchg.h> for older kernels.
- */
-
-
diff -urN 1/kernel/include/linux/anon_inodes.h 2/kernel/include/linux/anon_inodes.h
--- 1/kernel/include/linux/anon_inodes.h	2008-02-11 12:00:19.000000000 +0100
+++ 2/kernel/include/linux/anon_inodes.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,16 +0,0 @@
-/*
- *  include/linux/anon_inodes.h
- *
- *  Copyright (C) 2007  Davide Libenzi <davidel@xmailserver.org>
- *
- */
-
-#ifndef _LINUX_ANON_INODES_H
-#define _LINUX_ANON_INODES_H
-
-int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
-		     const char *name, const struct file_operations *fops,
-		     void *priv);
-
-#endif /* _LINUX_ANON_INODES_H */
-
diff -urN 1/kernel/include/linux/magic.h 2/kernel/include/linux/magic.h
--- 1/kernel/include/linux/magic.h	2008-02-11 12:00:19.000000000 +0100
+++ 2/kernel/include/linux/magic.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,41 +0,0 @@
-#ifndef __LINUX_MAGIC_H__
-#define __LINUX_MAGIC_H__
-
-#define ADFS_SUPER_MAGIC	0xadf5
-#define AFFS_SUPER_MAGIC	0xadff
-#define AFS_SUPER_MAGIC                0x5346414F
-#define AUTOFS_SUPER_MAGIC	0x0187
-#define CODA_SUPER_MAGIC	0x73757245
-#define EFS_SUPER_MAGIC		0x414A53
-#define EXT2_SUPER_MAGIC	0xEF53
-#define EXT3_SUPER_MAGIC	0xEF53
-#define EXT4_SUPER_MAGIC	0xEF53
-#define HPFS_SUPER_MAGIC	0xf995e849
-#define ISOFS_SUPER_MAGIC	0x9660
-#define JFFS2_SUPER_MAGIC	0x72b6
-#define KVMFS_SUPER_MAGIC	0x19700426
-
-#define MINIX_SUPER_MAGIC	0x137F		/* original minix fs */
-#define MINIX_SUPER_MAGIC2	0x138F		/* minix fs, 30 char names */
-#define MINIX2_SUPER_MAGIC	0x2468		/* minix V2 fs */
-#define MINIX2_SUPER_MAGIC2	0x2478		/* minix V2 fs, 30 char names */
-#define MINIX3_SUPER_MAGIC	0x4d5a		/* minix V3 fs */
-
-#define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
-#define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
-#define NFS_SUPER_MAGIC		0x6969
-#define OPENPROM_SUPER_MAGIC	0x9fa1
-#define PROC_SUPER_MAGIC	0x9fa0
-#define QNX4_SUPER_MAGIC	0x002f		/* qnx4 fs detection */
-
-#define REISERFS_SUPER_MAGIC	0x52654973	/* used by gcc */
-					/* used by file system utilities that
-	                                   look at the superblock, etc.  */
-#define REISERFS_SUPER_MAGIC_STRING	"ReIsErFs"
-#define REISER2FS_SUPER_MAGIC_STRING	"ReIsEr2Fs"
-#define REISER2FS_JR_SUPER_MAGIC_STRING	"ReIsEr3Fs"
-
-#define SMB_SUPER_MAGIC		0x517B
-#define USBDEVICE_SUPER_MAGIC	0x9fa2
-
-#endif /* __LINUX_MAGIC_H__ */
diff -urN 1/kernel/include/linux/mutex.h 2/kernel/include/linux/mutex.h
--- 1/kernel/include/linux/mutex.h	2008-02-11 12:00:19.000000000 +0100
+++ 2/kernel/include/linux/mutex.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,5 +0,0 @@
-/*
- * Empty file to satisfy #include <linux/mutex.h> for older kernels.
- */
-
-
diff -urN 1/kernel/include-compat/asm-x86/cmpxchg.h 2/kernel/include-compat/asm-x86/cmpxchg.h
--- 1/kernel/include-compat/asm-x86/cmpxchg.h	1970-01-01 01:00:00.000000000 +0100
+++ 2/kernel/include-compat/asm-x86/cmpxchg.h	2008-02-11 12:00:19.000000000 +0100
@@ -0,0 +1,5 @@
+/*
+ * Empty file to satisfy #include <linux/cmpxchg.h> for older kernels.
+ */
+
+
diff -urN 1/kernel/include-compat/linux/anon_inodes.h 2/kernel/include-compat/linux/anon_inodes.h
--- 1/kernel/include-compat/linux/anon_inodes.h	1970-01-01 01:00:00.000000000 +0100
+++ 2/kernel/include-compat/linux/anon_inodes.h	2008-02-11 12:00:19.000000000 +0100
@@ -0,0 +1,16 @@
+/*
+ *  include/linux/anon_inodes.h
+ *
+ *  Copyright (C) 2007  Davide Libenzi <davidel@xmailserver.org>
+ *
+ */
+
+#ifndef _LINUX_ANON_INODES_H
+#define _LINUX_ANON_INODES_H
+
+int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
+		     const char *name, const struct file_operations *fops,
+		     void *priv);
+
+#endif /* _LINUX_ANON_INODES_H */
+
diff -urN 1/kernel/include-compat/linux/magic.h 2/kernel/include-compat/linux/magic.h
--- 1/kernel/include-compat/linux/magic.h	1970-01-01 01:00:00.000000000 +0100
+++ 2/kernel/include-compat/linux/magic.h	2008-02-11 12:00:19.000000000 +0100
@@ -0,0 +1,41 @@
+#ifndef __LINUX_MAGIC_H__
+#define __LINUX_MAGIC_H__
+
+#define ADFS_SUPER_MAGIC	0xadf5
+#define AFFS_SUPER_MAGIC	0xadff
+#define AFS_SUPER_MAGIC                0x5346414F
+#define AUTOFS_SUPER_MAGIC	0x0187
+#define CODA_SUPER_MAGIC	0x73757245
+#define EFS_SUPER_MAGIC		0x414A53
+#define EXT2_SUPER_MAGIC	0xEF53
+#define EXT3_SUPER_MAGIC	0xEF53
+#define EXT4_SUPER_MAGIC	0xEF53
+#define HPFS_SUPER_MAGIC	0xf995e849
+#define ISOFS_SUPER_MAGIC	0x9660
+#define JFFS2_SUPER_MAGIC	0x72b6
+#define KVMFS_SUPER_MAGIC	0x19700426
+
+#define MINIX_SUPER_MAGIC	0x137F		/* original minix fs */
+#define MINIX_SUPER_MAGIC2	0x138F		/* minix fs, 30 char names */
+#define MINIX2_SUPER_MAGIC	0x2468		/* minix V2 fs */
+#define MINIX2_SUPER_MAGIC2	0x2478		/* minix V2 fs, 30 char names */
+#define MINIX3_SUPER_MAGIC	0x4d5a		/* minix V3 fs */
+
+#define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
+#define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
+#define NFS_SUPER_MAGIC		0x6969
+#define OPENPROM_SUPER_MAGIC	0x9fa1
+#define PROC_SUPER_MAGIC	0x9fa0
+#define QNX4_SUPER_MAGIC	0x002f		/* qnx4 fs detection */
+
+#define REISERFS_SUPER_MAGIC	0x52654973	/* used by gcc */
+					/* used by file system utilities that
+	                                   look at the superblock, etc.  */
+#define REISERFS_SUPER_MAGIC_STRING	"ReIsErFs"
+#define REISER2FS_SUPER_MAGIC_STRING	"ReIsEr2Fs"
+#define REISER2FS_JR_SUPER_MAGIC_STRING	"ReIsEr3Fs"
+
+#define SMB_SUPER_MAGIC		0x517B
+#define USBDEVICE_SUPER_MAGIC	0x9fa2
+
+#endif /* __LINUX_MAGIC_H__ */
diff -urN 1/kernel/include-compat/linux/mutex.h 2/kernel/include-compat/linux/mutex.h
--- 1/kernel/include-compat/linux/mutex.h	1970-01-01 01:00:00.000000000 +0100
+++ 2/kernel/include-compat/linux/mutex.h	2008-02-11 12:00:19.000000000 +0100
@@ -0,0 +1,5 @@
+/*
+ * Empty file to satisfy #include <linux/mutex.h> for older kernels.
+ */
+
+
diff --git a/kernel/external-module-compat.h b/kernel/external-module-compat.h
index 052d561..ae69799 100644
--- a/kernel/external-module-compat.h
+++ b/kernel/external-module-compat.h
@@ -10,8 +10,8 @@
 #include <linux/compiler.h>
 #include <linux/version.h>
 #include <linux/string.h>
-#include "include/linux/kvm.h"
-#include "include/linux/kvm_para.h"
+#include <include/linux/kvm.h>
+#include <include/linux/kvm_para.h>
 #include <linux/cpu.h>
 #include <asm/processor.h>
 #include <linux/hrtimer.h>
diff --git a/kernel/Makefile b/kernel/Makefile
index 7a435b5..0ee55a0 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -25,17 +25,21 @@ hack = $(call _hack,tmp/$(strip $1))
 unifdef = $(call _unifdef,tmp/$(strip $1))
 
 all::
-	$(MAKE) -C $(KERNELDIR) M=`pwd` "$$@"
+	# include header priority 1) $LINUX 2) $KERNELDIR 3) include-compat
+	$(MAKE) -C $(KERNELDIR) M=`pwd` \
+		LINUXINCLUDE="-I`pwd`/include -Iinclude -Iinclude-compat \
+		-include include/linux/autoconf.h" \
+		"$$@"
 
 sync:
-	rm -rf tmp
+	rm -rf tmp include
 	rsync --exclude='*.mod.c' -R \
              "$(LINUX)"/arch/x86/kvm/./*.[ch] \
              "$(LINUX)"/virt/kvm/./*.[ch] \
 	     "$(LINUX)"/./include/linux/kvm*.h \
 	     "$(LINUX)"/./include/asm-x86/kvm*.h \
              tmp/
-	rm -rf include/asm
+	mkdir -p include/linux include/asm-x86
 	ln -s asm-x86 include/asm
 
 	$(call unifdef, include/linux/kvm.h)
@@ -78,6 +82,7 @@ rpm:	all
 
 clean:
 	$(MAKE) -C $(KERNELDIR) M=`pwd` $@
+	rm -rf include
 
 svnclean:
 	svn st | grep '^\?' | awk '{print $2}' | xargs rm -rf

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  reply	other threads:[~2008-02-11 11:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-04 21:01 Broken external module build on 2.6.23 Chris Lalancette
     [not found] ` <47A77D2B.90902-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-02-05 23:15   ` Andrea Arcangeli
2008-02-11  8:14     ` Avi Kivity
2008-02-11 11:19       ` Andrea Arcangeli [this message]
2008-02-11 11:26         ` Andrea Arcangeli
2008-02-11 12:24         ` Avi Kivity
2008-02-11 12:24           ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080211111944.GG7051@v2.random \
    --to=andrea@qumranet.com \
    --cc=avi@qumranet.com \
    --cc=clalance@redhat.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox