All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH 0/6] Add endian functions to tools/include
@ 2012-02-28 13:37 Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton; +Cc: linux-kernel, Matt Fleming

From: Matt Fleming <matt.fleming@intel.com>

There's a few host tools in the kernel that are rolling their own
versions of the {get,put}_unaligned_le*() functions. This series
copies the include/linux/unaligned/*_byteshift.h headers to
tools/include for their use.

I don't think it really makes sense for these to be exported to
userspace (i.e. installed by make headers_install) because they're
only used by hostprogs within the kernel, but this series is RFC for a
reason - because I'm not sure where they belong.

Matt Fleming (6):
  tools/include: Add byteshift headers for endian access
  x86, relocs: Don't open code put_unaligned_le32()
  x86, mkpiggy: Don't open code put_unaligned_le32()
  x86, boot: Restrict CFLAGS for hostprogs
  x86, efi: Fix endian issues and unaligned accesses
  USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions

 arch/x86/boot/Makefile             |    5 ++-
 arch/x86/boot/compressed/Makefile  |    1 +
 arch/x86/boot/compressed/mkpiggy.c |   11 +-----
 arch/x86/boot/compressed/relocs.c  |    6 +--
 arch/x86/boot/tools/build.c        |   31 ++++++++--------
 tools/include/tools/be_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 tools/include/tools/le_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 tools/usb/Makefile                 |    2 +-
 tools/usb/ffs-test.c               |   29 +--------------
 9 files changed, 165 insertions(+), 60 deletions(-)
 create mode 100644 tools/include/tools/be_byteshift.h
 create mode 100644 tools/include/tools/le_byteshift.h

-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 19:23   ` [tip:x86/build] " tip-bot for Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32() Matt Fleming
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton; +Cc: linux-kernel, Matt Fleming

From: Matt Fleming <matt.fleming@intel.com>

There are various hostprogs in the kernel that are rolling their own
implementations of {get,put}_unaligned_le*(). Copy the byteshift
headers from include/linux/unaligned so that they can all use a single
implementation.

This requires changing some of the data types to the userspace
exported ones (u32 -> __u32, etc).

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 tools/include/tools/be_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 tools/include/tools/le_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 tools/include/tools/be_byteshift.h
 create mode 100644 tools/include/tools/le_byteshift.h

diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
new file mode 100644
index 0000000..f4912e2
--- /dev/null
+++ b/tools/include/tools/be_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_BE_BYTESHIFT_H
+#define _TOOLS_BE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_be16(const __u8 *p)
+{
+	return p[0] << 8 | p[1];
+}
+
+static inline __u32 __get_unaligned_be32(const __u8 *p)
+{
+	return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline __u64 __get_unaligned_be64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_be32(p) << 32 |
+	       __get_unaligned_be32(p + 4);
+}
+
+static inline void __put_unaligned_be16(__u16 val, __u8 *p)
+{
+	*p++ = val >> 8;
+	*p++ = val;
+}
+
+static inline void __put_unaligned_be32(__u32 val, __u8 *p)
+{
+	__put_unaligned_be16(val >> 16, p);
+	__put_unaligned_be16(val, p + 2);
+}
+
+static inline void __put_unaligned_be64(__u64 val, __u8 *p)
+{
+	__put_unaligned_be32(val >> 32, p);
+	__put_unaligned_be32(val, p + 4);
+}
+
+static inline __u16 get_unaligned_be16(const void *p)
+{
+	return __get_unaligned_be16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_be32(const void *p)
+{
+	return __get_unaligned_be32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_be64(const void *p)
+{
+	return __get_unaligned_be64((const __u8 *)p);
+}
+
+static inline void put_unaligned_be16(__u16 val, void *p)
+{
+	__put_unaligned_be16(val, p);
+}
+
+static inline void put_unaligned_be32(__u32 val, void *p)
+{
+	__put_unaligned_be32(val, p);
+}
+
+static inline void put_unaligned_be64(__u64 val, void *p)
+{
+	__put_unaligned_be64(val, p);
+}
+
+#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
new file mode 100644
index 0000000..c99d45a
--- /dev/null
+++ b/tools/include/tools/le_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_LE_BYTESHIFT_H
+#define _TOOLS_LE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_le16(const __u8 *p)
+{
+	return p[0] | p[1] << 8;
+}
+
+static inline __u32 __get_unaligned_le32(const __u8 *p)
+{
+	return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline __u64 __get_unaligned_le64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_le32(p + 4) << 32 |
+	       __get_unaligned_le32(p);
+}
+
+static inline void __put_unaligned_le16(__u16 val, __u8 *p)
+{
+	*p++ = val;
+	*p++ = val >> 8;
+}
+
+static inline void __put_unaligned_le32(__u32 val, __u8 *p)
+{
+	__put_unaligned_le16(val >> 16, p + 2);
+	__put_unaligned_le16(val, p);
+}
+
+static inline void __put_unaligned_le64(__u64 val, __u8 *p)
+{
+	__put_unaligned_le32(val >> 32, p + 4);
+	__put_unaligned_le32(val, p);
+}
+
+static inline __u16 get_unaligned_le16(const void *p)
+{
+	return __get_unaligned_le16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_le32(const void *p)
+{
+	return __get_unaligned_le32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_le64(const void *p)
+{
+	return __get_unaligned_le64((const __u8 *)p);
+}
+
+static inline void put_unaligned_le16(__u16 val, void *p)
+{
+	__put_unaligned_le16(val, p);
+}
+
+static inline void put_unaligned_le32(__u32 val, void *p)
+{
+	__put_unaligned_le32(val, p);
+}
+
+static inline void put_unaligned_le64(__u64 val, void *p)
+{
+	__put_unaligned_le64(val, p);
+}
+
+#endif /* _TOOLS_LE_BYTESHIFT_H */
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32()
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 19:23   ` [tip:x86/build] " tip-bot for Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 3/6] x86, mkpiggy: " Matt Fleming
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton; +Cc: linux-kernel, Matt Fleming

From: Matt Fleming <matt.fleming@intel.com>

Use the new headers in tools/include instead of rolling our own
put_unaligned_le32() implementation.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 arch/x86/boot/compressed/relocs.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index 89bbf4e..d3c0b02 100644
--- a/arch/x86/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
@@ -10,6 +10,7 @@
 #define USE_BSD
 #include <endian.h>
 #include <regex.h>
+#include <tools/le_byteshift.h>
 
 static void die(char *fmt, ...);
 
@@ -605,10 +606,7 @@ static void emit_relocs(int as_text)
 		fwrite("\0\0\0\0", 4, 1, stdout);
 		/* Now print each relocation */
 		for (i = 0; i < reloc_count; i++) {
-			buf[0] = (relocs[i] >>  0) & 0xff;
-			buf[1] = (relocs[i] >>  8) & 0xff;
-			buf[2] = (relocs[i] >> 16) & 0xff;
-			buf[3] = (relocs[i] >> 24) & 0xff;
+			put_unaligned_le32(relocs[i], buf);
 			fwrite(buf, 4, 1, stdout);
 		}
 	}
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC][PATCH 3/6] x86, mkpiggy: Don't open code put_unaligned_le32()
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32() Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 19:24   ` [tip:x86/build] " tip-bot for Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton; +Cc: linux-kernel, Matt Fleming

From: Matt Fleming <matt.fleming@intel.com>

Use the new headers in tools/include instead of rolling our own
put_unaligned_le32() implementation.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 arch/x86/boot/compressed/Makefile  |    1 +
 arch/x86/boot/compressed/mkpiggy.c |   11 ++---------
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index b123b9a..fd55a2f 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
 LDFLAGS_vmlinux := -T
 
 hostprogs-y	:= mkpiggy
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
 VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
 	$(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 46a8238..958a641 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -29,14 +29,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
-
-static uint32_t getle32(const void *p)
-{
-	const uint8_t *cp = p;
-
-	return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) +
-		((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
-}
+#include <tools/le_byteshift.h>
 
 int main(int argc, char *argv[])
 {
@@ -69,7 +62,7 @@ int main(int argc, char *argv[])
 	}
 
 	ilen = ftell(f);
-	olen = getle32(&olen);
+	olen = get_unaligned_le32(&olen);
 	fclose(f);
 
 	/*
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
                   ` (2 preceding siblings ...)
  2012-02-28 13:37 ` [RFC][PATCH 3/6] x86, mkpiggy: " Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 19:25   ` [tip:x86/build] " tip-bot for Matt Fleming
  2012-03-22 21:26   ` [tip:x86/urgent] x86, boot: Correct " tip-bot for H. Peter Anvin
  2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
  2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
  5 siblings, 2 replies; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton; +Cc: linux-kernel, Matt Fleming

From: Matt Fleming <matt.fleming@intel.com>

Currently tools/build has access to all the kernel headers in
$(srctree). This is unnecessary and could potentially allow
tools/build to erroneously include kernel headers when it should only
be including userspace-exported headers.

Unfortunately, mkcpustr still needs access to some of the asm kernel
headers, so explicitly special case that hostprog.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 arch/x86/boot/Makefile |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 95365a8..3e02148 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -37,8 +37,9 @@ setup-y		+= video-bios.o
 targets		+= $(setup-y)
 hostprogs-y	:= mkcpustr tools/build
 
-HOST_EXTRACFLAGS += $(LINUXINCLUDE)
-
+HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include
+HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \
+                   -include $(srctree)/include/linux/kconfig.h
 $(obj)/cpu.o: $(obj)/cpustr.h
 
 quiet_cmd_cpustr = CPUSTR  $@
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
                   ` (3 preceding siblings ...)
  2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 19:26   ` [tip:x86/build] " tip-bot for Matt Fleming
  2012-02-28 23:52   ` [RFC][PATCH 5/6] " Stephen Rothwell
  2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
  5 siblings, 2 replies; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton
  Cc: linux-kernel, Matt Fleming, Stephen Rothwell, Nick Bowler

From: Matt Fleming <matt.fleming@intel.com>

We may need to convert the endianness of the data we read from/write
to 'buf', so let's use {get,put}_unaligned_le32() to do that. Failure
to do so can result in accessing invalid memory, leading to a
segfault.  Stephen Rothwell noticed this bug while cross-building an
x86_64 allmodconfig kernel on PowerPC.

We need to read from and write to 'buf' a byte at a time otherwise
it's possible we'll perform an unaligned access, which can lead to bus
errors when cross-building an x86 kernel on risc architectures.

Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Nick Bowler <nbowler@elliptictech.com>
Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 arch/x86/boot/tools/build.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 4e9bd6b..f2ac95e 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <asm/boot.h>
+#include <tools/le_byteshift.h>
 
 typedef unsigned char  u8;
 typedef unsigned short u16;
@@ -41,6 +42,7 @@ typedef unsigned long  u32;
 
 #define DEFAULT_MAJOR_ROOT 0
 #define DEFAULT_MINOR_ROOT 0
+#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
 
 /* Minimal number of setup sectors */
 #define SETUP_SECT_MIN 5
@@ -159,7 +161,7 @@ int main(int argc, char ** argv)
 		die("read-error on `setup'");
 	if (c < 1024)
 		die("The setup must be at least 1024 bytes");
-	if (buf[510] != 0x55 || buf[511] != 0xaa)
+	if (get_unaligned_le16(&buf[510]) != 0xAA55)
 		die("Boot block hasn't got boot flag (0xAA55)");
 	fclose(file);
 
@@ -171,8 +173,7 @@ int main(int argc, char ** argv)
 	memset(buf+c, 0, i-c);
 
 	/* Set the default root device */
-	buf[508] = DEFAULT_MINOR_ROOT;
-	buf[509] = DEFAULT_MAJOR_ROOT;
+	put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
 
 	fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i);
 
@@ -192,44 +193,42 @@ int main(int argc, char ** argv)
 
 	/* Patch the setup code with the appropriate size parameters */
 	buf[0x1f1] = setup_sectors-1;
-	buf[0x1f4] = sys_size;
-	buf[0x1f5] = sys_size >> 8;
-	buf[0x1f6] = sys_size >> 16;
-	buf[0x1f7] = sys_size >> 24;
+	put_unaligned_le32(sys_size, &buf[0x1f4]);
 
 #ifdef CONFIG_EFI_STUB
 	file_sz = sz + i + ((sys_size * 16) - sz);
 
-	pe_header = *(unsigned int *)&buf[0x3c];
+	pe_header = get_unaligned_le32(&buf[0x3c]);
 
 	/* Size of code */
-	*(unsigned int *)&buf[pe_header + 0x1c] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
 
 	/* Size of image */
-	*(unsigned int *)&buf[pe_header + 0x50] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
 
 #ifdef CONFIG_X86_32
 	/* Address of entry point */
-	*(unsigned int *)&buf[pe_header + 0x28] = i;
+	put_unaligned_le32(i, &buf[pe_header + 0x28]);
 
 	/* .text size */
-	*(unsigned int *)&buf[pe_header + 0xb0] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
 
 	/* .text size of initialised data */
-	*(unsigned int *)&buf[pe_header + 0xb8] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
 #else
 	/*
 	 * Address of entry point. startup_32 is at the beginning and
 	 * the 64-bit entry point (startup_64) is always 512 bytes
 	 * after.
 	 */
-	*(unsigned int *)&buf[pe_header + 0x28] = i + 512;
+	put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
 
 	/* .text size */
-	*(unsigned int *)&buf[pe_header + 0xc0] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
 
 	/* .text size of initialised data */
-	*(unsigned int *)&buf[pe_header + 0xc8] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
+
 #endif /* CONFIG_X86_32 */
 #endif /* CONFIG_EFI_STUB */
 
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions
  2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
                   ` (4 preceding siblings ...)
  2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
@ 2012-02-28 13:37 ` Matt Fleming
  2012-02-28 17:50   ` H. Peter Anvin
  2012-02-28 19:27   ` [tip:x86/build] USB: ffs-test: Don't duplicate {get, put}_unaligned*() functions tip-bot for Matt Fleming
  5 siblings, 2 replies; 23+ messages in thread
From: Matt Fleming @ 2012-02-28 13:37 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Morton
  Cc: linux-kernel, Matt Fleming, Davidlohr Bueso, Greg Kroah-Hartman

From: Matt Fleming <matt.fleming@intel.com>

Use the header file in tools/include instead of duplicating the endian
functions.

Cc: Davidlohr Bueso <dave@gnu.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 tools/usb/Makefile   |    2 +-
 tools/usb/ffs-test.c |   29 +----------------------------
 2 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/tools/usb/Makefile b/tools/usb/Makefile
index 8b704af..396d6c4 100644
--- a/tools/usb/Makefile
+++ b/tools/usb/Makefile
@@ -3,7 +3,7 @@
 CC = $(CROSS_COMPILE)gcc
 PTHREAD_LIBS = -lpthread
 WARNINGS = -Wall -Wextra
-CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS)
+CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include
 
 all: testusb ffs-test
 %: %.c
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index b9c7986..384f47a 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <tools/le_byteshift.h>
 
 #include "../../include/linux/usb/functionfs.h"
 
@@ -47,34 +48,6 @@
 #define le32_to_cpu(x)  le32toh(x)
 #define le16_to_cpu(x)  le16toh(x)
 
-static inline __u16 get_unaligned_le16(const void *_ptr)
-{
-	const __u8 *ptr = _ptr;
-	return ptr[0] | (ptr[1] << 8);
-}
-
-static inline __u32 get_unaligned_le32(const void *_ptr)
-{
-	const __u8 *ptr = _ptr;
-	return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
-}
-
-static inline void put_unaligned_le16(__u16 val, void *_ptr)
-{
-	__u8 *ptr = _ptr;
-	*ptr++ = val;
-	*ptr++ = val >> 8;
-}
-
-static inline void put_unaligned_le32(__u32 val, void *_ptr)
-{
-	__u8 *ptr = _ptr;
-	*ptr++ = val;
-	*ptr++ = val >>  8;
-	*ptr++ = val >> 16;
-	*ptr++ = val >> 24;
-}
-
 
 /******************** Messages and Errors ***********************************/
 
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions
  2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
@ 2012-02-28 17:50   ` H. Peter Anvin
  2012-02-28 17:58     ` Greg Kroah-Hartman
  2012-02-28 19:25     ` Davidlohr Bueso
  2012-02-28 19:27   ` [tip:x86/build] USB: ffs-test: Don't duplicate {get, put}_unaligned*() functions tip-bot for Matt Fleming
  1 sibling, 2 replies; 23+ messages in thread
From: H. Peter Anvin @ 2012-02-28 17:50 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Andrew Morton, linux-kernel, Matt Fleming, Davidlohr Bueso,
	Greg Kroah-Hartman

On 02/28/2012 05:37 AM, Matt Fleming wrote:
> From: Matt Fleming <matt.fleming@intel.com>
> 
> Use the header file in tools/include instead of duplicating the endian
> functions.
> 
> Cc: Davidlohr Bueso <dave@gnu.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Signed-off-by: Matt Fleming <matt.fleming@intel.com>

Greg and Dave, since the rest of this series is all in the x86
directory, mind if I pick it up and put it in the -tip tree including
this patch?

	-hpa


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions
  2012-02-28 17:50   ` H. Peter Anvin
@ 2012-02-28 17:58     ` Greg Kroah-Hartman
  2012-02-28 19:25     ` Davidlohr Bueso
  1 sibling, 0 replies; 23+ messages in thread
From: Greg Kroah-Hartman @ 2012-02-28 17:58 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Matt Fleming, Andrew Morton, linux-kernel, Matt Fleming, Davidlohr Bueso

On Tue, Feb 28, 2012 at 09:50:19AM -0800, H. Peter Anvin wrote:
> On 02/28/2012 05:37 AM, Matt Fleming wrote:
> > From: Matt Fleming <matt.fleming@intel.com>
> > 
> > Use the header file in tools/include instead of duplicating the endian
> > functions.
> > 
> > Cc: Davidlohr Bueso <dave@gnu.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: H. Peter Anvin <hpa@zytor.com>
> > Signed-off-by: Matt Fleming <matt.fleming@intel.com>
> 
> Greg and Dave, since the rest of this series is all in the x86
> directory, mind if I pick it up and put it in the -tip tree including
> this patch?

No objection from me at all:
	Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [tip:x86/build] tools/include: Add byteshift headers for endian access
  2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
@ 2012-02-28 19:23   ` tip-bot for Matt Fleming
  0 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:23 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, matt.fleming

Commit-ID:  a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c
Gitweb:     http://git.kernel.org/tip/a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:20 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:22:51 -0800

tools/include: Add byteshift headers for endian access

There are various hostprogs in the kernel that are rolling their own
implementations of {get,put}_unaligned_le*(). Copy the byteshift
headers from include/linux/unaligned so that they can all use a single
implementation.

This requires changing some of the data types to the userspace
exported ones (u32 -> __u32, etc).

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-2-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 tools/include/tools/be_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 tools/include/tools/le_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
new file mode 100644
index 0000000..f4912e2
--- /dev/null
+++ b/tools/include/tools/be_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_BE_BYTESHIFT_H
+#define _TOOLS_BE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_be16(const __u8 *p)
+{
+	return p[0] << 8 | p[1];
+}
+
+static inline __u32 __get_unaligned_be32(const __u8 *p)
+{
+	return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline __u64 __get_unaligned_be64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_be32(p) << 32 |
+	       __get_unaligned_be32(p + 4);
+}
+
+static inline void __put_unaligned_be16(__u16 val, __u8 *p)
+{
+	*p++ = val >> 8;
+	*p++ = val;
+}
+
+static inline void __put_unaligned_be32(__u32 val, __u8 *p)
+{
+	__put_unaligned_be16(val >> 16, p);
+	__put_unaligned_be16(val, p + 2);
+}
+
+static inline void __put_unaligned_be64(__u64 val, __u8 *p)
+{
+	__put_unaligned_be32(val >> 32, p);
+	__put_unaligned_be32(val, p + 4);
+}
+
+static inline __u16 get_unaligned_be16(const void *p)
+{
+	return __get_unaligned_be16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_be32(const void *p)
+{
+	return __get_unaligned_be32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_be64(const void *p)
+{
+	return __get_unaligned_be64((const __u8 *)p);
+}
+
+static inline void put_unaligned_be16(__u16 val, void *p)
+{
+	__put_unaligned_be16(val, p);
+}
+
+static inline void put_unaligned_be32(__u32 val, void *p)
+{
+	__put_unaligned_be32(val, p);
+}
+
+static inline void put_unaligned_be64(__u64 val, void *p)
+{
+	__put_unaligned_be64(val, p);
+}
+
+#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
new file mode 100644
index 0000000..c99d45a
--- /dev/null
+++ b/tools/include/tools/le_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_LE_BYTESHIFT_H
+#define _TOOLS_LE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_le16(const __u8 *p)
+{
+	return p[0] | p[1] << 8;
+}
+
+static inline __u32 __get_unaligned_le32(const __u8 *p)
+{
+	return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline __u64 __get_unaligned_le64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_le32(p + 4) << 32 |
+	       __get_unaligned_le32(p);
+}
+
+static inline void __put_unaligned_le16(__u16 val, __u8 *p)
+{
+	*p++ = val;
+	*p++ = val >> 8;
+}
+
+static inline void __put_unaligned_le32(__u32 val, __u8 *p)
+{
+	__put_unaligned_le16(val >> 16, p + 2);
+	__put_unaligned_le16(val, p);
+}
+
+static inline void __put_unaligned_le64(__u64 val, __u8 *p)
+{
+	__put_unaligned_le32(val >> 32, p + 4);
+	__put_unaligned_le32(val, p);
+}
+
+static inline __u16 get_unaligned_le16(const void *p)
+{
+	return __get_unaligned_le16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_le32(const void *p)
+{
+	return __get_unaligned_le32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_le64(const void *p)
+{
+	return __get_unaligned_le64((const __u8 *)p);
+}
+
+static inline void put_unaligned_le16(__u16 val, void *p)
+{
+	__put_unaligned_le16(val, p);
+}
+
+static inline void put_unaligned_le32(__u32 val, void *p)
+{
+	__put_unaligned_le32(val, p);
+}
+
+static inline void put_unaligned_le64(__u64 val, void *p)
+{
+	__put_unaligned_le64(val, p);
+}
+
+#endif /* _TOOLS_LE_BYTESHIFT_H */

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, relocs: Don't open code put_unaligned_le32()
  2012-02-28 13:37 ` [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32() Matt Fleming
@ 2012-02-28 19:23   ` tip-bot for Matt Fleming
  0 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:23 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, matt.fleming

Commit-ID:  55f9709cd07c9d33e30b575ee1b3bfd0aeaa3760
Gitweb:     http://git.kernel.org/tip/55f9709cd07c9d33e30b575ee1b3bfd0aeaa3760
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:21 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:22:55 -0800

x86, relocs: Don't open code put_unaligned_le32()

Use the new headers in tools/include instead of rolling our own
put_unaligned_le32() implementation.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-3-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/compressed/relocs.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index 89bbf4e..d3c0b02 100644
--- a/arch/x86/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
@@ -10,6 +10,7 @@
 #define USE_BSD
 #include <endian.h>
 #include <regex.h>
+#include <tools/le_byteshift.h>
 
 static void die(char *fmt, ...);
 
@@ -605,10 +606,7 @@ static void emit_relocs(int as_text)
 		fwrite("\0\0\0\0", 4, 1, stdout);
 		/* Now print each relocation */
 		for (i = 0; i < reloc_count; i++) {
-			buf[0] = (relocs[i] >>  0) & 0xff;
-			buf[1] = (relocs[i] >>  8) & 0xff;
-			buf[2] = (relocs[i] >> 16) & 0xff;
-			buf[3] = (relocs[i] >> 24) & 0xff;
+			put_unaligned_le32(relocs[i], buf);
 			fwrite(buf, 4, 1, stdout);
 		}
 	}

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, mkpiggy: Don't open code put_unaligned_le32()
  2012-02-28 13:37 ` [RFC][PATCH 3/6] x86, mkpiggy: " Matt Fleming
@ 2012-02-28 19:24   ` tip-bot for Matt Fleming
  0 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:24 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, matt.fleming

Commit-ID:  12871c568305a0b20f116315479a18cd46882e9b
Gitweb:     http://git.kernel.org/tip/12871c568305a0b20f116315479a18cd46882e9b
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:22 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:22:57 -0800

x86, mkpiggy: Don't open code put_unaligned_le32()

Use the new headers in tools/include instead of rolling our own
put_unaligned_le32() implementation.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-4-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/compressed/Makefile  |    1 +
 arch/x86/boot/compressed/mkpiggy.c |   11 ++---------
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index b123b9a..fd55a2f 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
 LDFLAGS_vmlinux := -T
 
 hostprogs-y	:= mkpiggy
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
 VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
 	$(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 46a8238..958a641 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -29,14 +29,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
-
-static uint32_t getle32(const void *p)
-{
-	const uint8_t *cp = p;
-
-	return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) +
-		((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
-}
+#include <tools/le_byteshift.h>
 
 int main(int argc, char *argv[])
 {
@@ -69,7 +62,7 @@ int main(int argc, char *argv[])
 	}
 
 	ilen = ftell(f);
-	olen = getle32(&olen);
+	olen = get_unaligned_le32(&olen);
 	fclose(f);
 
 	/*

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, boot: Restrict CFLAGS for hostprogs
  2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
@ 2012-02-28 19:25   ` tip-bot for Matt Fleming
  2012-03-22 21:26   ` [tip:x86/urgent] x86, boot: Correct " tip-bot for H. Peter Anvin
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, matt.fleming

Commit-ID:  d40f833630a1299fd377408dc8d8fac370d621b0
Gitweb:     http://git.kernel.org/tip/d40f833630a1299fd377408dc8d8fac370d621b0
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:23 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:22:59 -0800

x86, boot: Restrict CFLAGS for hostprogs

Currently tools/build has access to all the kernel headers in
$(srctree). This is unnecessary and could potentially allow
tools/build to erroneously include kernel headers when it should only
be including userspace-exported headers.

Unfortunately, mkcpustr still needs access to some of the asm kernel
headers, so explicitly special case that hostprog.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-5-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/Makefile |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 95365a8..3e02148 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -37,8 +37,9 @@ setup-y		+= video-bios.o
 targets		+= $(setup-y)
 hostprogs-y	:= mkcpustr tools/build
 
-HOST_EXTRACFLAGS += $(LINUXINCLUDE)
-
+HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include
+HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \
+                   -include $(srctree)/include/linux/kconfig.h
 $(obj)/cpu.o: $(obj)/cpustr.h
 
 quiet_cmd_cpustr = CPUSTR  $@

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions
  2012-02-28 17:50   ` H. Peter Anvin
  2012-02-28 17:58     ` Greg Kroah-Hartman
@ 2012-02-28 19:25     ` Davidlohr Bueso
  1 sibling, 0 replies; 23+ messages in thread
From: Davidlohr Bueso @ 2012-02-28 19:25 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Matt Fleming, Andrew Morton, linux-kernel, Matt Fleming,
	Greg Kroah-Hartman

On Tue, 2012-02-28 at 09:50 -0800, H. Peter Anvin wrote:
> On 02/28/2012 05:37 AM, Matt Fleming wrote:
> > From: Matt Fleming <matt.fleming@intel.com>
> > 
> > Use the header file in tools/include instead of duplicating the endian
> > functions.
> > 
> > Cc: Davidlohr Bueso <dave@gnu.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: H. Peter Anvin <hpa@zytor.com>
> > Signed-off-by: Matt Fleming <matt.fleming@intel.com>
> 
Acked-by: Davidlohr Bueso <dave@gnu.org>

> Greg and Dave, since the rest of this series is all in the x86
> directory, mind if I pick it up and put it in the -tip tree including
> this patch?

Fine by me.


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, efi: Fix endian issues and unaligned accesses
  2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
@ 2012-02-28 19:26   ` tip-bot for Matt Fleming
  2012-02-28 23:52   ` [RFC][PATCH 5/6] " Stephen Rothwell
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, nbowler, hpa, mingo, sfr, tglx, matt.fleming

Commit-ID:  92f42c50f227ad228f815a8f4eec872524dae3a5
Gitweb:     http://git.kernel.org/tip/92f42c50f227ad228f815a8f4eec872524dae3a5
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:24 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:23:02 -0800

x86, efi: Fix endian issues and unaligned accesses

We may need to convert the endianness of the data we read from/write
to 'buf', so let's use {get,put}_unaligned_le32() to do that. Failure
to do so can result in accessing invalid memory, leading to a
segfault.  Stephen Rothwell noticed this bug while cross-building an
x86_64 allmodconfig kernel on PowerPC.

We need to read from and write to 'buf' a byte at a time otherwise
it's possible we'll perform an unaligned access, which can lead to bus
errors when cross-building an x86 kernel on risc architectures.

Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Nick Bowler <nbowler@elliptictech.com>
Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-6-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/tools/build.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 4e9bd6b..f2ac95e 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <asm/boot.h>
+#include <tools/le_byteshift.h>
 
 typedef unsigned char  u8;
 typedef unsigned short u16;
@@ -41,6 +42,7 @@ typedef unsigned long  u32;
 
 #define DEFAULT_MAJOR_ROOT 0
 #define DEFAULT_MINOR_ROOT 0
+#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
 
 /* Minimal number of setup sectors */
 #define SETUP_SECT_MIN 5
@@ -159,7 +161,7 @@ int main(int argc, char ** argv)
 		die("read-error on `setup'");
 	if (c < 1024)
 		die("The setup must be at least 1024 bytes");
-	if (buf[510] != 0x55 || buf[511] != 0xaa)
+	if (get_unaligned_le16(&buf[510]) != 0xAA55)
 		die("Boot block hasn't got boot flag (0xAA55)");
 	fclose(file);
 
@@ -171,8 +173,7 @@ int main(int argc, char ** argv)
 	memset(buf+c, 0, i-c);
 
 	/* Set the default root device */
-	buf[508] = DEFAULT_MINOR_ROOT;
-	buf[509] = DEFAULT_MAJOR_ROOT;
+	put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
 
 	fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i);
 
@@ -192,44 +193,42 @@ int main(int argc, char ** argv)
 
 	/* Patch the setup code with the appropriate size parameters */
 	buf[0x1f1] = setup_sectors-1;
-	buf[0x1f4] = sys_size;
-	buf[0x1f5] = sys_size >> 8;
-	buf[0x1f6] = sys_size >> 16;
-	buf[0x1f7] = sys_size >> 24;
+	put_unaligned_le32(sys_size, &buf[0x1f4]);
 
 #ifdef CONFIG_EFI_STUB
 	file_sz = sz + i + ((sys_size * 16) - sz);
 
-	pe_header = *(unsigned int *)&buf[0x3c];
+	pe_header = get_unaligned_le32(&buf[0x3c]);
 
 	/* Size of code */
-	*(unsigned int *)&buf[pe_header + 0x1c] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
 
 	/* Size of image */
-	*(unsigned int *)&buf[pe_header + 0x50] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
 
 #ifdef CONFIG_X86_32
 	/* Address of entry point */
-	*(unsigned int *)&buf[pe_header + 0x28] = i;
+	put_unaligned_le32(i, &buf[pe_header + 0x28]);
 
 	/* .text size */
-	*(unsigned int *)&buf[pe_header + 0xb0] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
 
 	/* .text size of initialised data */
-	*(unsigned int *)&buf[pe_header + 0xb8] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
 #else
 	/*
 	 * Address of entry point. startup_32 is at the beginning and
 	 * the 64-bit entry point (startup_64) is always 512 bytes
 	 * after.
 	 */
-	*(unsigned int *)&buf[pe_header + 0x28] = i + 512;
+	put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
 
 	/* .text size */
-	*(unsigned int *)&buf[pe_header + 0xc0] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
 
 	/* .text size of initialised data */
-	*(unsigned int *)&buf[pe_header + 0xc8] = file_sz;
+	put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
+
 #endif /* CONFIG_X86_32 */
 #endif /* CONFIG_EFI_STUB */
 

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:x86/build] USB: ffs-test: Don't duplicate {get, put}_unaligned*() functions
  2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
  2012-02-28 17:50   ` H. Peter Anvin
@ 2012-02-28 19:27   ` tip-bot for Matt Fleming
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Matt Fleming @ 2012-02-28 19:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, gregkh, hpa, mingo, dave, tglx, matt.fleming

Commit-ID:  24fa9a9d6d70ef7ef7087dce472a8f43a9078da5
Gitweb:     http://git.kernel.org/tip/24fa9a9d6d70ef7ef7087dce472a8f43a9078da5
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:25 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:23:18 -0800

USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions

Use the header file in tools/include instead of duplicating the endian
functions.

Cc: Davidlohr Bueso <dave@gnu.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-7-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 tools/usb/Makefile   |    2 +-
 tools/usb/ffs-test.c |   29 +----------------------------
 2 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/tools/usb/Makefile b/tools/usb/Makefile
index 8b704af..396d6c4 100644
--- a/tools/usb/Makefile
+++ b/tools/usb/Makefile
@@ -3,7 +3,7 @@
 CC = $(CROSS_COMPILE)gcc
 PTHREAD_LIBS = -lpthread
 WARNINGS = -Wall -Wextra
-CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS)
+CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include
 
 all: testusb ffs-test
 %: %.c
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index b9c7986..384f47a 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <tools/le_byteshift.h>
 
 #include "../../include/linux/usb/functionfs.h"
 
@@ -47,34 +48,6 @@
 #define le32_to_cpu(x)  le32toh(x)
 #define le16_to_cpu(x)  le16toh(x)
 
-static inline __u16 get_unaligned_le16(const void *_ptr)
-{
-	const __u8 *ptr = _ptr;
-	return ptr[0] | (ptr[1] << 8);
-}
-
-static inline __u32 get_unaligned_le32(const void *_ptr)
-{
-	const __u8 *ptr = _ptr;
-	return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
-}
-
-static inline void put_unaligned_le16(__u16 val, void *_ptr)
-{
-	__u8 *ptr = _ptr;
-	*ptr++ = val;
-	*ptr++ = val >> 8;
-}
-
-static inline void put_unaligned_le32(__u32 val, void *_ptr)
-{
-	__u8 *ptr = _ptr;
-	*ptr++ = val;
-	*ptr++ = val >>  8;
-	*ptr++ = val >> 16;
-	*ptr++ = val >> 24;
-}
-
 
 /******************** Messages and Errors ***********************************/
 

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses
  2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
  2012-02-28 19:26   ` [tip:x86/build] " tip-bot for Matt Fleming
@ 2012-02-28 23:52   ` Stephen Rothwell
  2012-02-29  0:13     ` Stephen Rothwell
  1 sibling, 1 reply; 23+ messages in thread
From: Stephen Rothwell @ 2012-02-28 23:52 UTC (permalink / raw)
  To: Matt Fleming
  Cc: H. Peter Anvin, Andrew Morton, linux-kernel, Matt Fleming, Nick Bowler

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

Hi all,

On Tue, 28 Feb 2012 13:37:24 +0000 Matt Fleming <matt@console-pimps.org> wrote:
>
> From: Matt Fleming <matt.fleming@intel.com>
> 
> We may need to convert the endianness of the data we read from/write
> to 'buf', so let's use {get,put}_unaligned_le32() to do that. Failure
> to do so can result in accessing invalid memory, leading to a
> segfault.  Stephen Rothwell noticed this bug while cross-building an
> x86_64 allmodconfig kernel on PowerPC.
> 
> We need to read from and write to 'buf' a byte at a time otherwise
> it's possible we'll perform an unaligned access, which can lead to bus
> errors when cross-building an x86 kernel on risc architectures.
> 
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Nick Bowler <nbowler@elliptictech.com>
> Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Matt Fleming <matt.fleming@intel.com>

Just to be absolutely clear, I have not yet tested this version of the
patch and also this fixes a problem with cross building Linus' tree (i.e.
this is a regression with cross building introduced in v3.3-rc1).

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses
  2012-02-28 23:52   ` [RFC][PATCH 5/6] " Stephen Rothwell
@ 2012-02-29  0:13     ` Stephen Rothwell
  2012-02-29  0:28       ` Stephen Rothwell
                         ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Stephen Rothwell @ 2012-02-29  0:13 UTC (permalink / raw)
  To: Matt Fleming
  Cc: H. Peter Anvin, Andrew Morton, linux-kernel, Matt Fleming, Nick Bowler

[-- Attachment #1: Type: text/plain, Size: 1764 bytes --]

Hi all,

On Wed, 29 Feb 2012 10:52:10 +1100 Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> On Tue, 28 Feb 2012 13:37:24 +0000 Matt Fleming <matt@console-pimps.org> wrote:
> >
> > From: Matt Fleming <matt.fleming@intel.com>
> > 
> > We may need to convert the endianness of the data we read from/write
> > to 'buf', so let's use {get,put}_unaligned_le32() to do that. Failure
> > to do so can result in accessing invalid memory, leading to a
> > segfault.  Stephen Rothwell noticed this bug while cross-building an
> > x86_64 allmodconfig kernel on PowerPC.
> > 
> > We need to read from and write to 'buf' a byte at a time otherwise
> > it's possible we'll perform an unaligned access, which can lead to bus
> > errors when cross-building an x86 kernel on risc architectures.
> > 
> > Cc: H. Peter Anvin <hpa@zytor.com>
> > Cc: Nick Bowler <nbowler@elliptictech.com>
> > Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Signed-off-by: Matt Fleming <matt.fleming@intel.com>
> 
> Just to be absolutely clear, I have not yet tested this version of the
> patch and also this fixes a problem with cross building Linus' tree (i.e.
> this is a regression with cross building introduced in v3.3-rc1).

OK, I tried just that patch on top of Linus' tree and obviously that
didn't work :-) so I pulled the x86/build branch from the tip tree into
my tree (which contained just Linus' tree of today
(v3.3-rc5-97-g891003a)). and the build failed like this:

arch/x86/boot/tools/build.c:36:22: error: asm/boot.h: No such file or directory

The build is an ARCH=x86_64 defconfig with CONFIG_EFI_STUB=y.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses
  2012-02-29  0:13     ` Stephen Rothwell
@ 2012-02-29  0:28       ` Stephen Rothwell
  2012-02-29  8:04         ` Stephen Rothwell
  2012-02-29  7:49       ` [tip:x86/build] x86, tools: Remove unneeded header files from tools/build.c tip-bot for H. Peter Anvin
  2012-02-29  7:50       ` [tip:x86/build] x86, build: Fix portability issues when cross-building tip-bot for H. Peter Anvin
  2 siblings, 1 reply; 23+ messages in thread
From: Stephen Rothwell @ 2012-02-29  0:28 UTC (permalink / raw)
  To: Matt Fleming
  Cc: H. Peter Anvin, Andrew Morton, linux-kernel, Matt Fleming, Nick Bowler

[-- Attachment #1: Type: text/plain, Size: 1117 bytes --]

Hi again,

On Wed, 29 Feb 2012 11:13:22 +1100 Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> OK, I tried just that patch on top of Linus' tree and obviously that
> didn't work :-) so I pulled the x86/build branch from the tip tree into
> my tree (which contained just Linus' tree of today
> (v3.3-rc5-97-g891003a)). and the build failed like this:
> 
> arch/x86/boot/tools/build.c:36:22: error: asm/boot.h: No such file or directory
> 
> The build is an ARCH=x86_64 defconfig with CONFIG_EFI_STUB=y.

I added V=1 and the command line for the build of build.c is

gcc -Wp,-MD,arch/x86/boot/tools/.build.d -Iarch/x86/boot -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/scratch/sfr/x86_seg.obj/include   -I/scratch/sfr/x86_seg/tools/include -include /scratch/sfr/x86_seg/include/linux/kconfig.h -o arch/x86/boot/tools/build /scratch/sfr/x86_seg/arch/x86/boot/tools/build.c  

I am using a separate object tree as well (source tree
is /scratch/sfr/x86_seg, object is /scratch/sfr/x86_seg.obj).

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, tools: Remove unneeded header files from tools/build.c
  2012-02-29  0:13     ` Stephen Rothwell
  2012-02-29  0:28       ` Stephen Rothwell
@ 2012-02-29  7:49       ` tip-bot for H. Peter Anvin
  2012-02-29  7:50       ` [tip:x86/build] x86, build: Fix portability issues when cross-building tip-bot for H. Peter Anvin
  2 siblings, 0 replies; 23+ messages in thread
From: tip-bot for H. Peter Anvin @ 2012-02-29  7:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, nbowler, hpa, mingo, akpm, matt, tglx, sfr, mingo

Commit-ID:  b8d43cb504a94f1070159a37c8cb23008276eff3
Gitweb:     http://git.kernel.org/tip/b8d43cb504a94f1070159a37c8cb23008276eff3
Author:     H. Peter Anvin <hpa@zytor.com>
AuthorDate: Tue, 28 Feb 2012 23:30:58 -0800
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 23:40:15 -0800

x86, tools: Remove unneeded header files from tools/build.c

We include <sys/sysmacros.h> and <asm/boot.h>, but none of those
header files actually provide anything this file needs.  Furthermore,
it breaks cross-compilation, so just remove them.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Matt Fleming <matt@console-pimps.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Bowler <nbowler@elliptictech.com>
Link: http://lkml.kernel.org/r/20120229111322.9eb4b23ff1672e8853ad3b3b@canb.auug.org.au
---
 arch/x86/boot/tools/build.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index f2ac95e..f3bd2e6 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -29,11 +29,9 @@
 #include <stdarg.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/sysmacros.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/mman.h>
-#include <asm/boot.h>
 #include <tools/le_byteshift.h>
 
 typedef unsigned char  u8;

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:x86/build] x86, build: Fix portability issues when cross-building
  2012-02-29  0:13     ` Stephen Rothwell
  2012-02-29  0:28       ` Stephen Rothwell
  2012-02-29  7:49       ` [tip:x86/build] x86, tools: Remove unneeded header files from tools/build.c tip-bot for H. Peter Anvin
@ 2012-02-29  7:50       ` tip-bot for H. Peter Anvin
  2 siblings, 0 replies; 23+ messages in thread
From: tip-bot for H. Peter Anvin @ 2012-02-29  7:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, nbowler, hpa, mingo, akpm, matt, tglx, sfr

Commit-ID:  a51f4047758d2bcd099ea113b833ed380f4024ba
Gitweb:     http://git.kernel.org/tip/a51f4047758d2bcd099ea113b833ed380f4024ba
Author:     H. Peter Anvin <hpa@zytor.com>
AuthorDate: Tue, 28 Feb 2012 23:36:21 -0800
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 23:40:56 -0800

x86, build: Fix portability issues when cross-building

It would appear that we never actually generated a correct CRC when
building on a bigendian machine.  Depending on the word size, we would
either generate an all-zero CRC (64-bit machine) or a byte-swapped
CRC (32-bit machine.)  Fix the types used so we don't arbitrarily use
a 64-bit word to hold 32-bit numbers, and pass the CRC through
put_unaligned_le32() like all the other numbers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Matt Fleming <matt@console-pimps.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Bowler <nbowler@elliptictech.com>
Link: http://lkml.kernel.org/r/20120229111322.9eb4b23ff1672e8853ad3b3b@canb.auug.org.au
---
 arch/x86/boot/tools/build.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index f3bd2e6..ed54976 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -36,7 +36,7 @@
 
 typedef unsigned char  u8;
 typedef unsigned short u16;
-typedef unsigned long  u32;
+typedef unsigned int   u32;
 
 #define DEFAULT_MAJOR_ROOT 0
 #define DEFAULT_MINOR_ROOT 0
@@ -247,8 +247,9 @@ int main(int argc, char ** argv)
 	}
 
 	/* Write the CRC */
-	fprintf(stderr, "CRC %lx\n", crc);
-	if (fwrite(&crc, 1, 4, stdout) != 4)
+	fprintf(stderr, "CRC %x\n", crc);
+	put_unaligned_le32(crc, buf);
+	if (fwrite(buf, 1, 4, stdout) != 4)
 		die("Writing CRC failed");
 
 	close(fd);

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses
  2012-02-29  0:28       ` Stephen Rothwell
@ 2012-02-29  8:04         ` Stephen Rothwell
  0 siblings, 0 replies; 23+ messages in thread
From: Stephen Rothwell @ 2012-02-29  8:04 UTC (permalink / raw)
  To: Matt Fleming, H. Peter Anvin
  Cc: Andrew Morton, linux-kernel, Matt Fleming, Nick Bowler

[-- Attachment #1: Type: text/plain, Size: 1489 bytes --]

On Wed, 29 Feb 2012 11:28:52 +1100 Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> Hi again,
> 
> On Wed, 29 Feb 2012 11:13:22 +1100 Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> >
> > OK, I tried just that patch on top of Linus' tree and obviously that
> > didn't work :-) so I pulled the x86/build branch from the tip tree into
> > my tree (which contained just Linus' tree of today
> > (v3.3-rc5-97-g891003a)). and the build failed like this:
> > 
> > arch/x86/boot/tools/build.c:36:22: error: asm/boot.h: No such file or directory
> > 
> > The build is an ARCH=x86_64 defconfig with CONFIG_EFI_STUB=y.
> 
> I added V=1 and the command line for the build of build.c is
> 
> gcc -Wp,-MD,arch/x86/boot/tools/.build.d -Iarch/x86/boot -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/scratch/sfr/x86_seg.obj/include   -I/scratch/sfr/x86_seg/tools/include -include /scratch/sfr/x86_seg/include/linux/kconfig.h -o arch/x86/boot/tools/build /scratch/sfr/x86_seg/arch/x86/boot/tools/build.c  
> 
> I am using a separate object tree as well (source tree
> is /scratch/sfr/x86_seg, object is /scratch/sfr/x86_seg.obj).

I have refetched x86/build after these two patches:
	x86, tools: Remove unneeded header files from tools/build.c
	x86, build: Fix portability issues when cross-building

And the kernel build now completes.

Thank you all for all the work.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [tip:x86/urgent] x86, boot: Correct CFLAGS for hostprogs
  2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
  2012-02-28 19:25   ` [tip:x86/build] " tip-bot for Matt Fleming
@ 2012-03-22 21:26   ` tip-bot for H. Peter Anvin
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for H. Peter Anvin @ 2012-03-22 21:26 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, torvalds, tglx, matt.fleming

Commit-ID:  446e1c86d51d0823e003a43a2b85c430efce2733
Gitweb:     http://git.kernel.org/tip/446e1c86d51d0823e003a43a2b85c430efce2733
Author:     H. Peter Anvin <hpa@zytor.com>
AuthorDate: Thu, 22 Mar 2012 11:08:18 -0700
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Thu, 22 Mar 2012 12:42:51 -0700

x86, boot: Correct CFLAGS for hostprogs

This is a partial revert of commit:
    d40f833 "Restrict CFLAGS for hostprogs"

The endian-manipulation macros in tools/include need <linux/types.h>,
but the hostprogs in arch/x86/boot need several headers from the
kernel build tree, which means we have to add the kernel headers to
the include path.  This picks up <linux/types.h> from the kernel tree,
which gives a warning.

Since this use of <linux/types.h> is intentional, add
-D__EXPORTED_HEADERS__ to the command line to silence the warning.

A better way to fix this would be to always install the exported
kernel headers into $(objtree)/usr/include as a standard part of the
kernel build, but that is a lot more involved.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-5-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/Makefile |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 3e02148..5a747dd 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -37,9 +37,9 @@ setup-y		+= video-bios.o
 targets		+= $(setup-y)
 hostprogs-y	:= mkcpustr tools/build
 
-HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include
-HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \
-                   -include $(srctree)/include/linux/kconfig.h
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include $(LINUXINCLUDE) \
+	            -D__EXPORTED_HEADERS__
+
 $(obj)/cpu.o: $(obj)/cpustr.h
 
 quiet_cmd_cpustr = CPUSTR  $@

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2012-03-22 21:26 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
2012-02-28 19:23   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32() Matt Fleming
2012-02-28 19:23   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 3/6] x86, mkpiggy: " Matt Fleming
2012-02-28 19:24   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
2012-02-28 19:25   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-03-22 21:26   ` [tip:x86/urgent] x86, boot: Correct " tip-bot for H. Peter Anvin
2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
2012-02-28 19:26   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 23:52   ` [RFC][PATCH 5/6] " Stephen Rothwell
2012-02-29  0:13     ` Stephen Rothwell
2012-02-29  0:28       ` Stephen Rothwell
2012-02-29  8:04         ` Stephen Rothwell
2012-02-29  7:49       ` [tip:x86/build] x86, tools: Remove unneeded header files from tools/build.c tip-bot for H. Peter Anvin
2012-02-29  7:50       ` [tip:x86/build] x86, build: Fix portability issues when cross-building tip-bot for H. Peter Anvin
2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
2012-02-28 17:50   ` H. Peter Anvin
2012-02-28 17:58     ` Greg Kroah-Hartman
2012-02-28 19:25     ` Davidlohr Bueso
2012-02-28 19:27   ` [tip:x86/build] USB: ffs-test: Don't duplicate {get, put}_unaligned*() functions tip-bot for Matt Fleming

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.