All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Apply transparent_union attribute to union semun
@ 2011-05-26 22:27 jonas
  2011-05-27  8:13 ` [ORLinux] " Jeremy Bennett
  2011-06-17 17:31 ` Jonas Bonn
  0 siblings, 2 replies; 3+ messages in thread
From: jonas @ 2011-05-26 22:27 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux, joern.rennecke, Jonas Bonn


From: Jonas Bonn <jonas@southpole.se>

The syscall handler for semctl is written under the assumption that the
toolchain will pass "small" unions as function parameters directly instead
of by reference.  The union semun is "small" and thus fits this description.

Since it is assumed that the union will be passed directly and not by
reference, it is safe to access the union members without going via
get_user.

The OpenRISC architecture, however, passes all unions by reference, thus
breaking the above assumption.

The technically correct fix here is to mark the union as being transparent
so that the ABI of the union's first element determines the parameter
passing method and thus make explicit what's already implied in the function
definition.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 include/linux/sem.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/sem.h b/include/linux/sem.h
index f2961af..6985c7d 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -48,7 +48,7 @@ union semun {
 	unsigned short __user *array;	/* array for GETALL & SETALL */
 	struct seminfo __user *__buf;	/* buffer for IPC_INFO */
 	void __user *__pad;
-};
+} __attribute__ ((transparent_union));
 
 struct  seminfo {
 	int semmap;
-- 
1.7.4.1


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

* Re: [ORLinux] [PATCH 1/1] Apply transparent_union attribute to union semun
  2011-05-26 22:27 [PATCH 1/1] Apply transparent_union attribute to union semun jonas
@ 2011-05-27  8:13 ` Jeremy Bennett
  2011-06-17 17:31 ` Jonas Bonn
  1 sibling, 0 replies; 3+ messages in thread
From: Jeremy Bennett @ 2011-05-27  8:13 UTC (permalink / raw)
  To: jonas; +Cc: linux-kernel, joern.rennecke, linux

On Fri, 2011-05-27 at 00:27 +0200, jonas@southpole.se wrote: 
> From: Jonas Bonn <jonas@southpole.se>
> 
> The syscall handler for semctl is written under the assumption that the
> toolchain will pass "small" unions as function parameters directly instead
> of by reference.  The union semun is "small" and thus fits this description.
> 
> Since it is assumed that the union will be passed directly and not by
> reference, it is safe to access the union members without going via
> get_user.
> 
> The OpenRISC architecture, however, passes all unions by reference, thus
> breaking the above assumption.

Hi Jonas

Joern and I were discussing this - there is a case for changing the ABI.
It would certainly fix a debugging issue.

> The technically correct fix here is to mark the union as being transparent
> so that the ABI of the union's first element determines the parameter
> passing method and thus make explicit what's already implied in the function
> definition.
> 
> Signed-off-by: Jonas Bonn <jonas@southpole.se>
> ---
>  include/linux/sem.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/sem.h b/include/linux/sem.h
> index f2961af..6985c7d 100644
> --- a/include/linux/sem.h
> +++ b/include/linux/sem.h
> @@ -48,7 +48,7 @@ union semun {
>  	unsigned short __user *array;	/* array for GETALL & SETALL */
>  	struct seminfo __user *__buf;	/* buffer for IPC_INFO */
>  	void __user *__pad;
> -};
> +} __attribute__ ((transparent_union));
>  
>  struct  seminfo {
>  	int semmap;

Excellent. Semaphore test now passes. I look forward to rerunning
regression - we may be down to a single failure now!

Best wishes,


Jeremy

-- 
Tel:      +44 (1590) 610184
Cell:     +44 (7970) 676050
SkypeID: jeremybennett
Email:   jeremy.bennett@embecosm.com
Web:     www.embecosm.com


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

* Re: [PATCH 1/1] Apply transparent_union attribute to union semun
  2011-05-26 22:27 [PATCH 1/1] Apply transparent_union attribute to union semun jonas
  2011-05-27  8:13 ` [ORLinux] " Jeremy Bennett
@ 2011-06-17 17:31 ` Jonas Bonn
  1 sibling, 0 replies; 3+ messages in thread
From: Jonas Bonn @ 2011-06-17 17:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux


Hi,
I never got any feedback on this patch... is this an acceptable solution
for upstream?  ...or is the usage of this GCC extension discouraged?
/Jonas

On Fri, 2011-05-27 at 00:27 +0200, jonas@southpole.se wrote:
> From: Jonas Bonn <jonas@southpole.se>
> 
> The syscall handler for semctl is written under the assumption that the
> toolchain will pass "small" unions as function parameters directly instead
> of by reference.  The union semun is "small" and thus fits this description.
> 
> Since it is assumed that the union will be passed directly and not by
> reference, it is safe to access the union members without going via
> get_user.
> 
> The OpenRISC architecture, however, passes all unions by reference, thus
> breaking the above assumption.
> 
> The technically correct fix here is to mark the union as being transparent
> so that the ABI of the union's first element determines the parameter
> passing method and thus make explicit what's already implied in the function
> definition.
> 
> Signed-off-by: Jonas Bonn <jonas@southpole.se>
> ---
>  include/linux/sem.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/sem.h b/include/linux/sem.h
> index f2961af..6985c7d 100644
> --- a/include/linux/sem.h
> +++ b/include/linux/sem.h
> @@ -48,7 +48,7 @@ union semun {
>  	unsigned short __user *array;	/* array for GETALL & SETALL */
>  	struct seminfo __user *__buf;	/* buffer for IPC_INFO */
>  	void __user *__pad;
> -};
> +} __attribute__ ((transparent_union));
>  
>  struct  seminfo {
>  	int semmap;



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

end of thread, other threads:[~2011-06-17 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26 22:27 [PATCH 1/1] Apply transparent_union attribute to union semun jonas
2011-05-27  8:13 ` [ORLinux] " Jeremy Bennett
2011-06-17 17:31 ` Jonas Bonn

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.