LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: mingo@elte.hu
Cc: jdike@addtoit.com, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org,
	user-mode-linux-devel@lists.sourceforge.net
Subject: Re: uml and -regparm=3
Date: Thu, 10 Jan 2008 10:05:54 +0100	[thread overview]
Message-ID: <E1JCtMI-0007jw-5U@pomaz-ex.szeredi.hu> (raw)
In-Reply-To: <20080110073215.GA11506@elte.hu> (message from Ingo Molnar on Thu, 10 Jan 2008 08:32:16 +0100)

> * Miklos Szeredi <miklos@szeredi.hu> wrote:
> 
> > FASTCALL is defined empty in -mm, but UML is not compiled with 
> > -mregparm=3 and so this breaks things (I noticed problems with 
> > rwsem_down_write_failed).
> > 
> > Tried recompiling UML with -mregparm=3, but that resulted in a strange 
> > failure immediately after startup:
> > 
> > |^[%G�^[%@: Invalid argument
> > 
> > What's up?
> 
> Miklos, could you try the fix below?
> 
> In general most FASTCALL/fastcall uses are bogus, except for code where 
> a function that takes parameters is implemented in assembly with a 
> regparm calling convention. The fix is to introduce the "asmregparm" 
> attribute to mark such function prototypes with regparm(3). This is the 
> opposite of asmlinkage. [asmlinkage forced regparm(0)]

Thanks.  Patch works, but needed to add asmregparm to the definitions
as well, plus added default define into <linux/linkage.h> (updated
patch below).

Miklos
----

Subject: x86: fix UML calling convention
From: Ingo Molnar <mingo@elte.hu>

introduce the "asmregparm" calling convention: for functions
implemented in assembly with a fixed regparm input parameters
calling convention.

mark the semaphore and rwsem slowpath functions with that.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---

Index: linux/include/asm-x86/linkage.h
===================================================================
--- linux.orig/include/asm-x86/linkage.h	2008-01-09 21:16:29.000000000 +0100
+++ linux/include/asm-x86/linkage.h	2008-01-10 09:38:17.000000000 +0100
@@ -9,6 +9,11 @@
 #ifdef CONFIG_X86_32
 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
 #define prevent_tail_call(ret) __asm__ ("" : "=r" (ret) : "0" (ret))
+/*
+ * For 32-bit UML - mark functions implemented in assembly that use
+ * regparm input parameters:
+ */
+#define asmregparm __attribute__((regparm(3)))
 #endif
 
 #ifdef CONFIG_X86_ALIGNMENT_16
Index: linux/include/asm-x86/rwsem.h
===================================================================
--- linux.orig/include/asm-x86/rwsem.h	2008-01-09 21:16:29.000000000 +0100
+++ linux/include/asm-x86/rwsem.h	2008-01-10 09:55:07.000000000 +0100
@@ -44,10 +44,14 @@
 
 struct rwsem_waiter;
 
-extern struct rw_semaphore *FASTCALL(rwsem_down_read_failed(struct rw_semaphore *sem));
-extern struct rw_semaphore *FASTCALL(rwsem_down_write_failed(struct rw_semaphore *sem));
-extern struct rw_semaphore *FASTCALL(rwsem_wake(struct rw_semaphore *));
-extern struct rw_semaphore *FASTCALL(rwsem_downgrade_wake(struct rw_semaphore *sem));
+extern asmregparm struct rw_semaphore *
+ rwsem_down_read_failed(struct rw_semaphore *sem);
+extern asmregparm struct rw_semaphore *
+ rwsem_down_write_failed(struct rw_semaphore *sem);
+extern asmregparm struct rw_semaphore *
+ rwsem_wake(struct rw_semaphore *);
+extern asmregparm struct rw_semaphore *
+ rwsem_downgrade_wake(struct rw_semaphore *sem);
 
 /*
  * the semaphore definition
Index: linux/include/asm-x86/semaphore_32.h
===================================================================
--- linux.orig/include/asm-x86/semaphore_32.h	2008-01-09 21:16:29.000000000 +0100
+++ linux/include/asm-x86/semaphore_32.h	2008-01-10 09:38:17.000000000 +0100
@@ -83,10 +83,10 @@ static inline void init_MUTEX_LOCKED (st
 	sema_init(sem, 0);
 }
 
-void __down_failed(void /* special register calling convention */);
-int  __down_failed_interruptible(void  /* params in registers */);
-int  __down_failed_trylock(void  /* params in registers */);
-void __up_wakeup(void /* special register calling convention */);
+extern asmregparm void __down_failed(atomic_t *count_ptr);
+extern asmregparm int  __down_failed_interruptible(atomic_t *count_ptr);
+extern asmregparm int  __down_failed_trylock(atomic_t *count_ptr);
+extern asmregparm void __up_wakeup(atomic_t *count_ptr);
 
 /*
  * This is ugly, but we want the default case to fall through.
Index: linux/lib/rwsem.c
===================================================================
--- linux.orig/lib/rwsem.c	2008-01-09 21:16:30.000000000 +0100
+++ linux/lib/rwsem.c	2008-01-10 09:55:55.000000000 +0100
@@ -187,7 +187,7 @@ rwsem_down_failed_common(struct rw_semap
 /*
  * wait for the read lock to be granted
  */
-struct rw_semaphore __sched *
+asmregparm struct rw_semaphore __sched *
 rwsem_down_read_failed(struct rw_semaphore *sem)
 {
 	struct rwsem_waiter waiter;
@@ -201,7 +201,7 @@ rwsem_down_read_failed(struct rw_semapho
 /*
  * wait for the write lock to be granted
  */
-struct rw_semaphore __sched *
+asmregparm struct rw_semaphore __sched *
 rwsem_down_write_failed(struct rw_semaphore *sem)
 {
 	struct rwsem_waiter waiter;
@@ -216,7 +216,7 @@ rwsem_down_write_failed(struct rw_semaph
  * handle waking up a waiter on the semaphore
  * - up_read/up_write has decremented the active part of count if we come here
  */
-struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
+asmregparm struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
 {
 	unsigned long flags;
 
@@ -236,7 +236,7 @@ struct rw_semaphore *rwsem_wake(struct r
  * - caller incremented waiting part of count and discovered it still negative
  * - just wake up any readers at the front of the queue
  */
-struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
+asmregparm struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
 {
 	unsigned long flags;
 
Index: linux/include/linux/linkage.h
===================================================================
--- linux.orig/include/linux/linkage.h	2008-01-09 21:16:04.000000000 +0100
+++ linux/include/linux/linkage.h	2008-01-10 10:01:52.000000000 +0100
@@ -13,6 +13,10 @@
 #define asmlinkage CPP_ASMLINKAGE
 #endif
 
+#ifndef asmregparm
+#define asmregparm
+#endif
+
 #ifndef prevent_tail_call
 # define prevent_tail_call(ret) do { } while (0)
 #endif

  reply	other threads:[~2008-01-10  9:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-09 21:01 Miklos Szeredi
2008-01-09 21:12 ` Andi Kleen
2008-01-09 21:20   ` Miklos Szeredi
2008-01-09 21:32     ` Andi Kleen
2008-01-09 21:50       ` Miklos Szeredi
2008-01-10  2:14         ` Jeff Dike
2008-01-10  2:37           ` Andi Kleen
2008-01-10  2:45             ` H. Peter Anvin
2008-01-09 21:33     ` Adrian Bunk
2008-01-09 22:01 ` linux-os (Dick Johnson)
2008-01-10  7:32 ` Ingo Molnar
2008-01-10  9:05   ` Miklos Szeredi [this message]
2008-01-10  9:35     ` Ingo Molnar

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=E1JCtMI-0007jw-5U@pomaz-ex.szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=akpm@linux-foundation.org \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    --subject='Re: uml and -regparm=3' \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).