linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals
@ 2013-03-06 20:47 David Howells
  2013-03-06 20:47 ` David Howells
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds; +Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, linux-kernel, akpm


Here are four patches to fix some of the problems with endianness-related
preprocessor conditionals I have found in the UAPI header files.

The problem is that the way that preprocessor conditionals are used to
determine endianness when building for Linux userspace (as defined by the
predominant use of glibc) is not compatible with the way that the kernel build
does things.  The problem revolves around how __BIG_ENDIAN and __LITTLE_ENDIAN
are defined in each environment.

When building for Linux userspace, __BIG_ENDIAN and __LITTLE_ENDIAN are always
defined - so the kernel's preferred:

	if defined(__xxx_ENDIAN)

is always true in userspace builds, no matter which endianness your check
employs - whereas only one is defined in the kernel builds - meaning

	#if __BYTE_ORDER == __xxx_ENDIAN

gives a warning with -Wundef if you select the undefined endianness for your
check.


Unfortunately, the UAPI header files _must_ employ the userspace variant of
these conditionals outside of __KERNEL__-conditionalised regions as these
conditionals get exposed to userspace and userspace _cannot_ be changed.

These can be fixed in the UAPI headers by changing:

	#if defined(__BIG_ENDIAN)
	#define foo 1234
	#elif defined(__LITTLE_ENDIAN)
	#define foo 4321
	#else
	#error endianness unspecified
	#endif

to:

	#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
	#define foo 1234
	#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
	#define foo 4321
	#else
	#error endianness unspecified
	#endif

as it appears gcc's cpp doesn't complain about macros that aren't evaluated.

[!!!] NOTE [!!!]  These patches may adversely change the userspace API.  Since
the userspace API appears to be wrong under some circumstances due to incorrect
conditionals, it may be necessary to make an alternate fix whereby the we
select the first variant unconditionally in all cases as we would otherwise be
changing the actual userspace API.

David
---
David Howells (4):
      UAPI: Fix endianness conditionals in linux/aio_abi.h
      UAPI: Fix endianness conditionals in linux/acct.h
      UAPI: Fix endianness conditionals in linux/raid/md_p.h
      UAPI: Fix endianness conditionals in M32R's asm/stat.h


 arch/m32r/include/uapi/asm/stat.h |    4 ++--
 include/uapi/linux/acct.h         |    6 ++++--
 include/uapi/linux/aio_abi.h      |    4 ++--
 include/uapi/linux/raid/md_p.h    |    6 ++++--
 4 files changed, 12 insertions(+), 8 deletions(-)

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

* [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals
  2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
@ 2013-03-06 20:47 ` David Howells
  2013-03-06 20:47 ` [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h David Howells
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds; +Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, linux-kernel, akpm


Here are four patches to fix some of the problems with endianness-related
preprocessor conditionals I have found in the UAPI header files.

The problem is that the way that preprocessor conditionals are used to
determine endianness when building for Linux userspace (as defined by the
predominant use of glibc) is not compatible with the way that the kernel build
does things.  The problem revolves around how __BIG_ENDIAN and __LITTLE_ENDIAN
are defined in each environment.

When building for Linux userspace, __BIG_ENDIAN and __LITTLE_ENDIAN are always
defined - so the kernel's preferred:

	if defined(__xxx_ENDIAN)

is always true in userspace builds, no matter which endianness your check
employs - whereas only one is defined in the kernel builds - meaning

	#if __BYTE_ORDER == __xxx_ENDIAN

gives a warning with -Wundef if you select the undefined endianness for your
check.


Unfortunately, the UAPI header files _must_ employ the userspace variant of
these conditionals outside of __KERNEL__-conditionalised regions as these
conditionals get exposed to userspace and userspace _cannot_ be changed.

These can be fixed in the UAPI headers by changing:

	#if defined(__BIG_ENDIAN)
	#define foo 1234
	#elif defined(__LITTLE_ENDIAN)
	#define foo 4321
	#else
	#error endianness unspecified
	#endif

to:

	#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
	#define foo 1234
	#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
	#define foo 4321
	#else
	#error endianness unspecified
	#endif

as it appears gcc's cpp doesn't complain about macros that aren't evaluated.

[!!!] NOTE [!!!]  These patches may adversely change the userspace API.  Since
the userspace API appears to be wrong under some circumstances due to incorrect
conditionals, it may be necessary to make an alternate fix whereby the we
select the first variant unconditionally in all cases as we would otherwise be
changing the actual userspace API.

David
---
David Howells (4):
      UAPI: Fix endianness conditionals in linux/aio_abi.h
      UAPI: Fix endianness conditionals in linux/acct.h
      UAPI: Fix endianness conditionals in linux/raid/md_p.h
      UAPI: Fix endianness conditionals in M32R's asm/stat.h


 arch/m32r/include/uapi/asm/stat.h |    4 ++--
 include/uapi/linux/acct.h         |    6 ++++--
 include/uapi/linux/aio_abi.h      |    4 ++--
 include/uapi/linux/raid/md_p.h    |    6 ++++--
 4 files changed, 12 insertions(+), 8 deletions(-)


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

* [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
  2013-03-06 20:47 ` David Howells
@ 2013-03-06 20:47 ` David Howells
  2013-03-06 20:47   ` David Howells
  2013-03-12 16:32   ` Benjamin LaHaise
  2013-03-06 20:47 ` [PATCH 2/4] UAPI: Fix endianness conditionals in linux/acct.h David Howells
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds
  Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, linux-aio, linux-kernel,
	Benjamin LaHaise, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
userspace will likely interpret this and thus the order of fields in struct
iocb incorrectly as the little-endian variant on big-endian machines -
depending on header inclusion order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Benjamin LaHaise <bcrl@kvack.org>
cc: linux-aio@kvack.org
---

 include/uapi/linux/aio_abi.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h
index 86fa7a7..bb2554f 100644
--- a/include/uapi/linux/aio_abi.h
+++ b/include/uapi/linux/aio_abi.h
@@ -62,9 +62,9 @@ struct io_event {
 	__s64		res2;		/* secondary result */
 };
 
-#if defined(__LITTLE_ENDIAN)
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 #define PADDED(x,y)	x, y
-#elif defined(__BIG_ENDIAN)
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 #define PADDED(x,y)	y, x
 #else
 #error edit for your odd byteorder.

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

* [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-06 20:47 ` [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h David Howells
@ 2013-03-06 20:47   ` David Howells
  2013-03-12 16:32   ` Benjamin LaHaise
  1 sibling, 0 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds
  Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, linux-aio, linux-kernel,
	Benjamin LaHaise, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
userspace will likely interpret this and thus the order of fields in struct
iocb incorrectly as the little-endian variant on big-endian machines -
depending on header inclusion order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Benjamin LaHaise <bcrl@kvack.org>
cc: linux-aio@kvack.org
---

 include/uapi/linux/aio_abi.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h
index 86fa7a7..bb2554f 100644
--- a/include/uapi/linux/aio_abi.h
+++ b/include/uapi/linux/aio_abi.h
@@ -62,9 +62,9 @@ struct io_event {
 	__s64		res2;		/* secondary result */
 };
 
-#if defined(__LITTLE_ENDIAN)
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 #define PADDED(x,y)	x, y
-#elif defined(__BIG_ENDIAN)
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 #define PADDED(x,y)	y, x
 #else
 #error edit for your odd byteorder.


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

* [PATCH 2/4] UAPI: Fix endianness conditionals in linux/acct.h
  2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
  2013-03-06 20:47 ` David Howells
  2013-03-06 20:47 ` [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h David Howells
@ 2013-03-06 20:47 ` David Howells
  2013-03-06 20:47 ` [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h David Howells
  2013-03-06 20:48 ` [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h David Howells
  4 siblings, 0 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds; +Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, linux-kernel, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of ACCT_BYTEORDER in linux/acct.h is wrong in this way.  Note
that userspace will likely interpret this incorrectly as the big-endian variant
on little-endian machines - depending on header inclusion order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the value of ACCT_BYTEORDER.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 include/uapi/linux/acct.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/acct.h b/include/uapi/linux/acct.h
index 11b6ca3..df2f9a0 100644
--- a/include/uapi/linux/acct.h
+++ b/include/uapi/linux/acct.h
@@ -107,10 +107,12 @@ struct acct_v3
 #define ACORE		0x08	/* ... dumped core */
 #define AXSIG		0x10	/* ... was killed by a signal */
 
-#ifdef __BIG_ENDIAN
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 #define ACCT_BYTEORDER	0x80	/* accounting file is big endian */
-#else
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 #define ACCT_BYTEORDER	0x00	/* accounting file is little endian */
+#else
+#error unspecified endianness
 #endif
 
 #ifndef __KERNEL__

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

* [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h
  2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
                   ` (2 preceding siblings ...)
  2013-03-06 20:47 ` [PATCH 2/4] UAPI: Fix endianness conditionals in linux/acct.h David Howells
@ 2013-03-06 20:47 ` David Howells
  2013-03-12  1:43   ` NeilBrown
  2013-03-06 20:48 ` [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h David Howells
  4 siblings, 1 reply; 13+ messages in thread
From: David Howells @ 2013-03-06 20:47 UTC (permalink / raw)
  To: torvalds
  Cc: linux-arch, sfr, Joakim.Tjernlund, arnd, Neil Brown, linux-kernel,
	linux-raid, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of struct mdp_superblock_s in linux/raid/md_p.h is wrong in this
way.  Note that userspace will likely interpret the ordering of the fields
incorrectly as the big-endian variant on a little-endian machines - depending
on header inclusion order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the ordering of events_hi, events_lo, cp_events_hi and
cp_events_lo in struct mdp_superblock_s / typedef mdp_super_t.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Neil Brown <neilb@suse.de>
cc: linux-raid@vger.kernel.org
---

 include/uapi/linux/raid/md_p.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/raid/md_p.h b/include/uapi/linux/raid/md_p.h
index ee75353..fe1a540 100644
--- a/include/uapi/linux/raid/md_p.h
+++ b/include/uapi/linux/raid/md_p.h
@@ -145,16 +145,18 @@ typedef struct mdp_superblock_s {
 	__u32 failed_disks;	/*  4 Number of failed disks		      */
 	__u32 spare_disks;	/*  5 Number of spare disks		      */
 	__u32 sb_csum;		/*  6 checksum of the whole superblock        */
-#ifdef __BIG_ENDIAN
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 	__u32 events_hi;	/*  7 high-order of superblock update count   */
 	__u32 events_lo;	/*  8 low-order of superblock update count    */
 	__u32 cp_events_hi;	/*  9 high-order of checkpoint update count   */
 	__u32 cp_events_lo;	/* 10 low-order of checkpoint update count    */
-#else
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 	__u32 events_lo;	/*  7 low-order of superblock update count    */
 	__u32 events_hi;	/*  8 high-order of superblock update count   */
 	__u32 cp_events_lo;	/*  9 low-order of checkpoint update count    */
 	__u32 cp_events_hi;	/* 10 high-order of checkpoint update count   */
+#else
+#error unspecified endianness
 #endif
 	__u32 recovery_cp;	/* 11 recovery checkpoint sector count	      */
 	/* There are only valid for minor_version > 90 */

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

* [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h
  2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
                   ` (3 preceding siblings ...)
  2013-03-06 20:47 ` [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h David Howells
@ 2013-03-06 20:48 ` David Howells
  2013-03-06 20:48   ` David Howells
  4 siblings, 1 reply; 13+ messages in thread
From: David Howells @ 2013-03-06 20:48 UTC (permalink / raw)
  To: torvalds
  Cc: linux-arch, sfr, linux-m32r, Joakim.Tjernlund, arnd,
	Hirokazu Takata, linux-kernel, linux-m32r-ja, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of struct stat64 in M32R's asm/stat.h is wrong in this way.
Note that userspace will likely interpret the field order incorrectly as the
big-endian variant on little-endian machines - depending on header inclusion
order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the ordering of st_blocks and __pad4 in struct stat64.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Hirokazu Takata <takata@linux-m32r.org>
cc: linux-m32r@ml.linux-m32r.org
cc: linux-m32r-ja@ml.linux-m32r.org
---

 arch/m32r/include/uapi/asm/stat.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/m32r/include/uapi/asm/stat.h b/arch/m32r/include/uapi/asm/stat.h
index da4518f..98470fe 100644
--- a/arch/m32r/include/uapi/asm/stat.h
+++ b/arch/m32r/include/uapi/asm/stat.h
@@ -63,10 +63,10 @@ struct stat64 {
 	long long	st_size;
 	unsigned long	st_blksize;
 
-#if defined(__BIG_ENDIAN)
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 	unsigned long	__pad4;		/* future possible st_blocks high bits */
 	unsigned long	st_blocks;	/* Number 512-byte blocks allocated. */
-#elif defined(__LITTLE_ENDIAN)
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 	unsigned long	st_blocks;	/* Number 512-byte blocks allocated. */
 	unsigned long	__pad4;		/* future possible st_blocks high bits */
 #else

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

* [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h
  2013-03-06 20:48 ` [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h David Howells
@ 2013-03-06 20:48   ` David Howells
  0 siblings, 0 replies; 13+ messages in thread
From: David Howells @ 2013-03-06 20:48 UTC (permalink / raw)
  To: torvalds
  Cc: linux-arch, sfr, linux-m32r, Joakim.Tjernlund, arnd,
	Hirokazu Takata, linux-kernel, linux-m32r-ja, akpm

In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
against __BYTE_ORDER in preprocessor conditionals where these are exposed to
userspace (that is they're not inside __KERNEL__ conditionals).

However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
rather than comparing against __BYTE_ORDER and this has incorrectly leaked
into the userspace headers.

The definition of struct stat64 in M32R's asm/stat.h is wrong in this way.
Note that userspace will likely interpret the field order incorrectly as the
big-endian variant on little-endian machines - depending on header inclusion
order.

[!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
be better to fix the ordering of st_blocks and __pad4 in struct stat64.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Hirokazu Takata <takata@linux-m32r.org>
cc: linux-m32r@ml.linux-m32r.org
cc: linux-m32r-ja@ml.linux-m32r.org
---

 arch/m32r/include/uapi/asm/stat.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/m32r/include/uapi/asm/stat.h b/arch/m32r/include/uapi/asm/stat.h
index da4518f..98470fe 100644
--- a/arch/m32r/include/uapi/asm/stat.h
+++ b/arch/m32r/include/uapi/asm/stat.h
@@ -63,10 +63,10 @@ struct stat64 {
 	long long	st_size;
 	unsigned long	st_blksize;
 
-#if defined(__BIG_ENDIAN)
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
 	unsigned long	__pad4;		/* future possible st_blocks high bits */
 	unsigned long	st_blocks;	/* Number 512-byte blocks allocated. */
-#elif defined(__LITTLE_ENDIAN)
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
 	unsigned long	st_blocks;	/* Number 512-byte blocks allocated. */
 	unsigned long	__pad4;		/* future possible st_blocks high bits */
 #else


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

* Re: [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h
  2013-03-06 20:47 ` [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h David Howells
@ 2013-03-12  1:43   ` NeilBrown
  0 siblings, 0 replies; 13+ messages in thread
From: NeilBrown @ 2013-03-12  1:43 UTC (permalink / raw)
  To: David Howells
  Cc: torvalds, linux-arch, sfr, Joakim.Tjernlund, arnd, linux-kernel,
	linux-raid, akpm

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

On Wed, 06 Mar 2013 20:47:51 +0000 David Howells <dhowells@redhat.com> wrote:

> In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
> against __BYTE_ORDER in preprocessor conditionals where these are exposed to
> userspace (that is they're not inside __KERNEL__ conditionals).
> 
> However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
> rather than comparing against __BYTE_ORDER and this has incorrectly leaked
> into the userspace headers.
> 
> The definition of struct mdp_superblock_s in linux/raid/md_p.h is wrong in this
> way.  Note that userspace will likely interpret the ordering of the fields
> incorrectly as the big-endian variant on a little-endian machines - depending
> on header inclusion order.
> 
> [!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
> be better to fix the ordering of events_hi, events_lo, cp_events_hi and
> cp_events_lo in struct mdp_superblock_s / typedef mdp_super_t.

Thanks David - looks good to me.
Changing the ordering of fields isn't really an option at this stage - over
10 years too late :-(.
I think any user-space tools that use this data structure have their own copy
of the include file.

Acked-by: NeilBrown <neilb@suse.de>

Thanks,
NeilBrown


> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Neil Brown <neilb@suse.de>
> cc: linux-raid@vger.kernel.org
> ---
> 
>  include/uapi/linux/raid/md_p.h |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/raid/md_p.h b/include/uapi/linux/raid/md_p.h
> index ee75353..fe1a540 100644
> --- a/include/uapi/linux/raid/md_p.h
> +++ b/include/uapi/linux/raid/md_p.h
> @@ -145,16 +145,18 @@ typedef struct mdp_superblock_s {
>  	__u32 failed_disks;	/*  4 Number of failed disks		      */
>  	__u32 spare_disks;	/*  5 Number of spare disks		      */
>  	__u32 sb_csum;		/*  6 checksum of the whole superblock        */
> -#ifdef __BIG_ENDIAN
> +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
>  	__u32 events_hi;	/*  7 high-order of superblock update count   */
>  	__u32 events_lo;	/*  8 low-order of superblock update count    */
>  	__u32 cp_events_hi;	/*  9 high-order of checkpoint update count   */
>  	__u32 cp_events_lo;	/* 10 low-order of checkpoint update count    */
> -#else
> +#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
>  	__u32 events_lo;	/*  7 low-order of superblock update count    */
>  	__u32 events_hi;	/*  8 high-order of superblock update count   */
>  	__u32 cp_events_lo;	/*  9 low-order of checkpoint update count    */
>  	__u32 cp_events_hi;	/* 10 high-order of checkpoint update count   */
> +#else
> +#error unspecified endianness
>  #endif
>  	__u32 recovery_cp;	/* 11 recovery checkpoint sector count	      */
>  	/* There are only valid for minor_version > 90 */


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

* Re: [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-06 20:47 ` [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h David Howells
  2013-03-06 20:47   ` David Howells
@ 2013-03-12 16:32   ` Benjamin LaHaise
  2013-03-12 16:32     ` Benjamin LaHaise
  2013-03-12 18:22     ` Jeff Moyer
  1 sibling, 2 replies; 13+ messages in thread
From: Benjamin LaHaise @ 2013-03-12 16:32 UTC (permalink / raw)
  To: David Howells
  Cc: torvalds, linux-arch, sfr, Joakim.Tjernlund, arnd, linux-aio,
	linux-kernel, akpm

On Wed, Mar 06, 2013 at 08:47:33PM +0000, David Howells wrote:
> In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
> against __BYTE_ORDER in preprocessor conditionals where these are exposed to
> userspace (that is they're not inside __KERNEL__ conditionals).
> 
> However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
> rather than comparing against __BYTE_ORDER and this has incorrectly leaked
> into the userspace headers.
> 
> The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
> userspace will likely interpret this and thus the order of fields in struct
> iocb incorrectly as the little-endian variant on big-endian machines -
> depending on header inclusion order.
> 
> [!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
> be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.

It is unlikely that anyone has used the existing kernel headers and hit this 
issue given that most existing users use the libaio.h include (which does not 
get the endianness tests wrong).  Given that the kernel has always used the 
correct endian mappings, this change is correct.

Acked-by: Benjamin LaHaise <bcrl@kvack.org>

		-ben

> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Benjamin LaHaise <bcrl@kvack.org>
> cc: linux-aio@kvack.org
> ---
> 
>  include/uapi/linux/aio_abi.h |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h
> index 86fa7a7..bb2554f 100644
> --- a/include/uapi/linux/aio_abi.h
> +++ b/include/uapi/linux/aio_abi.h
> @@ -62,9 +62,9 @@ struct io_event {
>  	__s64		res2;		/* secondary result */
>  };
>  
> -#if defined(__LITTLE_ENDIAN)
> +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
>  #define PADDED(x,y)	x, y
> -#elif defined(__BIG_ENDIAN)
> +#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
>  #define PADDED(x,y)	y, x
>  #else
>  #error edit for your odd byteorder.
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-aio' in
> the body to majordomo@kvack.org.  For more info on Linux AIO,
> see: http://www.kvack.org/aio/
> Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

-- 
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org.  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

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

* Re: [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-12 16:32   ` Benjamin LaHaise
@ 2013-03-12 16:32     ` Benjamin LaHaise
  2013-03-12 18:22     ` Jeff Moyer
  1 sibling, 0 replies; 13+ messages in thread
From: Benjamin LaHaise @ 2013-03-12 16:32 UTC (permalink / raw)
  To: David Howells
  Cc: torvalds, linux-arch, sfr, Joakim.Tjernlund, arnd, linux-aio,
	linux-kernel, akpm

On Wed, Mar 06, 2013 at 08:47:33PM +0000, David Howells wrote:
> In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
> against __BYTE_ORDER in preprocessor conditionals where these are exposed to
> userspace (that is they're not inside __KERNEL__ conditionals).
> 
> However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
> rather than comparing against __BYTE_ORDER and this has incorrectly leaked
> into the userspace headers.
> 
> The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
> userspace will likely interpret this and thus the order of fields in struct
> iocb incorrectly as the little-endian variant on big-endian machines -
> depending on header inclusion order.
> 
> [!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
> be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.

It is unlikely that anyone has used the existing kernel headers and hit this 
issue given that most existing users use the libaio.h include (which does not 
get the endianness tests wrong).  Given that the kernel has always used the 
correct endian mappings, this change is correct.

Acked-by: Benjamin LaHaise <bcrl@kvack.org>

		-ben

> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Benjamin LaHaise <bcrl@kvack.org>
> cc: linux-aio@kvack.org
> ---
> 
>  include/uapi/linux/aio_abi.h |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h
> index 86fa7a7..bb2554f 100644
> --- a/include/uapi/linux/aio_abi.h
> +++ b/include/uapi/linux/aio_abi.h
> @@ -62,9 +62,9 @@ struct io_event {
>  	__s64		res2;		/* secondary result */
>  };
>  
> -#if defined(__LITTLE_ENDIAN)
> +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
>  #define PADDED(x,y)	x, y
> -#elif defined(__BIG_ENDIAN)
> +#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
>  #define PADDED(x,y)	y, x
>  #else
>  #error edit for your odd byteorder.
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-aio' in
> the body to majordomo@kvack.org.  For more info on Linux AIO,
> see: http://www.kvack.org/aio/
> Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

-- 
"Thought is the essence of where you are now."

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

* Re: [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-12 16:32   ` Benjamin LaHaise
  2013-03-12 16:32     ` Benjamin LaHaise
@ 2013-03-12 18:22     ` Jeff Moyer
  2013-03-12 18:22       ` Jeff Moyer
  1 sibling, 1 reply; 13+ messages in thread
From: Jeff Moyer @ 2013-03-12 18:22 UTC (permalink / raw)
  To: Benjamin LaHaise
  Cc: David Howells, torvalds, linux-arch, sfr, Joakim.Tjernlund, arnd,
	linux-aio, linux-kernel, akpm

Benjamin LaHaise <bcrl@kvack.org> writes:

> On Wed, Mar 06, 2013 at 08:47:33PM +0000, David Howells wrote:
>> In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
>> against __BYTE_ORDER in preprocessor conditionals where these are exposed to
>> userspace (that is they're not inside __KERNEL__ conditionals).
>> 
>> However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
>> rather than comparing against __BYTE_ORDER and this has incorrectly leaked
>> into the userspace headers.
>> 
>> The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
>> userspace will likely interpret this and thus the order of fields in struct
>> iocb incorrectly as the little-endian variant on big-endian machines -
>> depending on header inclusion order.
>> 
>> [!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
>> be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.
>
> It is unlikely that anyone has used the existing kernel headers and hit this 
> issue given that most existing users use the libaio.h include (which does not 
> get the endianness tests wrong).  Given that the kernel has always used the 
> correct endian mappings, this change is correct.

Agreed.

Acked-by: Jeff Moyer <jmoyer@redhat.com>

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org.  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

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

* Re: [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h
  2013-03-12 18:22     ` Jeff Moyer
@ 2013-03-12 18:22       ` Jeff Moyer
  0 siblings, 0 replies; 13+ messages in thread
From: Jeff Moyer @ 2013-03-12 18:22 UTC (permalink / raw)
  To: Benjamin LaHaise
  Cc: David Howells, torvalds, linux-arch, sfr, Joakim.Tjernlund, arnd,
	linux-aio, linux-kernel, akpm

Benjamin LaHaise <bcrl@kvack.org> writes:

> On Wed, Mar 06, 2013 at 08:47:33PM +0000, David Howells wrote:
>> In the UAPI header files, __BIG_ENDIAN and __LITTLE_ENDIAN must be compared
>> against __BYTE_ORDER in preprocessor conditionals where these are exposed to
>> userspace (that is they're not inside __KERNEL__ conditionals).
>> 
>> However, in the main kernel the norm is to check for "defined(__XXX_ENDIAN)"
>> rather than comparing against __BYTE_ORDER and this has incorrectly leaked
>> into the userspace headers.
>> 
>> The definition of PADDED() in linux/aio_abi.h is wrong in this way.  Note that
>> userspace will likely interpret this and thus the order of fields in struct
>> iocb incorrectly as the little-endian variant on big-endian machines -
>> depending on header inclusion order.
>> 
>> [!!!] NOTE [!!!]  This patch may adversely change the userspace API.  It might
>> be better to fix the ordering of aio_key and aio_reserved1 in struct iocb.
>
> It is unlikely that anyone has used the existing kernel headers and hit this 
> issue given that most existing users use the libaio.h include (which does not 
> get the endianness tests wrong).  Given that the kernel has always used the 
> correct endian mappings, this change is correct.

Agreed.

Acked-by: Jeff Moyer <jmoyer@redhat.com>

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

end of thread, other threads:[~2013-03-12 18:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-06 20:47 [RFC][PATCH 0/4] UAPI: Fix up endianness conditionals David Howells
2013-03-06 20:47 ` David Howells
2013-03-06 20:47 ` [PATCH 1/4] UAPI: Fix endianness conditionals in linux/aio_abi.h David Howells
2013-03-06 20:47   ` David Howells
2013-03-12 16:32   ` Benjamin LaHaise
2013-03-12 16:32     ` Benjamin LaHaise
2013-03-12 18:22     ` Jeff Moyer
2013-03-12 18:22       ` Jeff Moyer
2013-03-06 20:47 ` [PATCH 2/4] UAPI: Fix endianness conditionals in linux/acct.h David Howells
2013-03-06 20:47 ` [PATCH 3/4] UAPI: Fix endianness conditionals in linux/raid/md_p.h David Howells
2013-03-12  1:43   ` NeilBrown
2013-03-06 20:48 ` [PATCH 4/4] UAPI: Fix endianness conditionals in M32R's asm/stat.h David Howells
2013-03-06 20:48   ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).