Re: [uml-devel] [PATCH 4/5] UML - Simplify helper stack handling

2007-06-26 Thread Jeff Dike
On Tue, Jun 26, 2007 at 01:35:50PM -0700, Andrew Morton wrote:
> > sprintf(title, data->title, data->device);
> > -   pid = run_helper(NULL, NULL, argv, NULL);
> > +   pid = run_helper(NULL, NULL, argv);
> > if (pid < 0) {
> > err = pid;
> > printk(UM_KERN_ERR "xterm_open : run_helper failed, "
> 
> Something's gone wrong here.  My copy of this file has
> 
> pid = run_helper(NULL, NULL, argv, &stack);

Looks like you're applying patches out of order.  This is from the
14th, while a patch from the 13th ("UML - xterm driver tidying") has
-   pid = run_helper(NULL, NULL, argv, &stack);
...
+   pid = run_helper(NULL, NULL, argv, NULL);

If you don't want to fiddle with this, just drop it and I'll rediff
against the next -mm and resend.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] UML - Add stack usage monitoring

2007-06-20 Thread Jeff Dike
On Tue, Jun 19, 2007 at 01:14:41PM -0700, Andrew Morton wrote:
> Oh well.  Your new code should really be generic, utilising the
> stack-page-zeroing which CONFIG_DEBUG_STACK_USAGE enables.  There's nothing
> UML-specific about it.
> 
> low_water_lock and lowest_to_date should be static to check_stack_usage(),
> btw..

OK, here's a fixed version.  Dunno if the prink wants to be more elaborate.

If this is OK, then drop the UML version.

Jeff

-- 
Work email - jdike at linux dot intel dot com



Add generic exit-time stack-depth checking to CONFIG_DEBUG_STACK_USAGE.

This also adds UML support.

Tested on UML and i386.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig.debug|9 +
 arch/um/defconfig|1 +
 include/asm-um/thread_info.h |9 +
 kernel/exit.c|   24 
 4 files changed, 43 insertions(+)

Index: linux-2.6.21-mm/kernel/exit.c
===
--- linux-2.6.21-mm.orig/kernel/exit.c  2007-06-20 11:57:07.0 -0400
+++ linux-2.6.21-mm/kernel/exit.c   2007-06-20 13:53:20.0 -0400
@@ -867,6 +867,27 @@ static void exit_notify(struct task_stru
release_task(tsk);
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+static void check_stack_usage(void)
+{
+   static DEFINE_SPINLOCK(low_water_lock);
+   static int lowest_to_date = THREAD_SIZE;
+   unsigned long *n = end_of_stack(current), free;
+
+   while (*n == 0)
+   n++;
+   free = (unsigned long)n - (unsigned long)end_of_stack(current);
+
+   spin_lock(&low_water_lock);
+   if (free < lowest_to_date) {
+   printk(KERN_WARNING "Greatest stack depth - %ld bytes left\n",
+  free);
+   lowest_to_date = free;
+   }
+   spin_unlock(&low_water_lock);
+}
+#endif
+
 fastcall NORET_TYPE void do_exit(long code)
 {
struct task_struct *tsk = current;
@@ -942,6 +963,9 @@ fastcall NORET_TYPE void do_exit(long co
exit_sem(tsk);
__exit_files(tsk);
__exit_fs(tsk);
+#ifdef CONFIG_DEBUG_STACK_USAGE
+   check_stack_usage();
+#endif
exit_thread();
container_exit(tsk, 1);
exit_keys(tsk);
Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug  2007-06-20 11:57:13.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug   2007-06-20 11:59:43.0 
-0400
@@ -47,4 +47,13 @@ config GCOV
 If you're involved in UML kernel development and want to use gcov,
 say Y.  If you're unsure, say N.
 
+config DEBUG_STACK_USAGE
+   bool "Stack utilization instrumentation"
+   default N
+   help
+ Track the maximum kernel stack usage - this will look at each
+ kernel stack at process exit and log it if it's the deepest
+ stack seen so far.
+
+ This option will slow down process creation and destruction somewhat.
 endmenu
Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-06-20 11:57:13.0 
-0400
+++ linux-2.6.21-mm/arch/um/defconfig   2007-06-20 11:58:29.0 -0400
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y
 # CONFIG_RCU_TORTURE_TEST is not set
 # CONFIG_GPROF is not set
 # CONFIG_GCOV is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h   2007-06-20 
11:57:13.0 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h2007-06-20 
14:17:22.0 -0400
@@ -52,10 +52,19 @@ static inline struct thread_info *curren
return ti;
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+#define alloc_thread_info(tsk) \
+   ((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+CONFIG_KERNEL_STACK_ORDER))
+#else
+
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
 CONFIG_KERNEL_STACK_ORDER))
+#endif
+
 #define free_thread_info(ti) \
free_pages((unsigned long)(ti),CONFIG_KERNEL_STACK_ORDER)
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] UML - Add stack usage monitoring

2007-06-20 Thread Jeff Dike
On Tue, Jun 19, 2007 at 12:57:07PM -0700, Randy Dunlap wrote:
> Kconfig help text is indented 2 more spaces (by convention or
> CodingStyle).

OK, will fix.

> > +   if(*p != 0)
> 
>   if (*p != NULL)

p is int *, so that's a int version pointer comparision.

> or
>   if (*p)

Conceptually, p is an int, not a boolean, so I prefer to type the
extra characters to do the int-to-boolean conversion in places that
want booleans.

> > +   if (left < lowest_to_date) {
> > +   printk("Greatest stack depth - %d bytes left\n", left);
> 
> Does UML need/use KERN_* facility levels in printk() calls?

Yes, will fix.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

2007-06-20 Thread Jeff Dike
On Wed, Jun 20, 2007 at 04:18:56PM +0200, Blaisorblade wrote:
> In Italy we say "habits are hard to die"...

"Old habits are hard to kill"

I'm working on it.

> In the end: are you interested in this stuff? I'm busy right now but
> can work to apply these changes after this thursday
> (i.e. tomorrow). I'd need to get Jeff's patchset to fix it.

I actually prefer to do them by hand (although that does have
disadvantages, as we've just seen).  The reason is that it makes me
look at the code line-by-line, and I often see other things which need
fixing.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

2007-06-20 Thread Jeff Dike
On Wed, Jun 20, 2007 at 04:06:58PM +0200, Blaisorblade wrote:
> Oh, it's exactly what CONFIG_DEBUG_STACK_USAGE does for i386... (not sure if 
> you were still wondering...).

Where?  The only usage in i386 that I see is thread_info.h zeroing stacks
as they are allocated.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] UML - Add stack usage monitoring

2007-06-19 Thread Jeff Dike
On Tue, Jun 19, 2007 at 11:54:22AM -0700, Andrew Morton wrote:
> On Tue, 19 Jun 2007 14:42:45 -0400
> Jeff Dike <[EMAIL PROTECTED]> wrote:
> 
> > Add a machanism to see how much of a kernel stack is used.  This
> > allocates zeroed stacks and sees where the lowest non-zero byte is on
> > process exit.  It keeps track of the lowest value and logs values as
> > they get lower.
> > 
> 
> remind us again why the generic code is unsuitable?

It does something different - it will tell you the greatest stack
usage of any currently running process.  What I want to be able to do
is run a workload and come back a few days later and see how close
anything came to running out of stack.
> 
> > +   for(p = stack; p < end; p++){
> > +   if(*p != 0)
> > +   if(left < lowest_to_date){
> 
> Are there any plans to fix UML coding style?

You know I have been fixing it.  I forgot to eyeball this patch for
style - fixed patch below.

Jeff

-- 
Work email - jdike at linux dot intel dot com


Add a machanism to see how much of a kernel stack is used.  This
allocates zeroed stacks and sees where the lowest non-zero byte is on
process exit.  It keeps track of the lowest value and logs values as
they get lower.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig.debug|9 +
 arch/um/defconfig|1 +
 arch/um/kernel/process.c |   29 +
 include/asm-um/thread_info.h |   16 
 4 files changed, 55 insertions(+)

Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug  2007-06-19 14:06:36.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug   2007-06-19 14:06:44.0 
-0400
@@ -47,4 +47,13 @@ config GCOV
 If you're involved in UML kernel development and want to use gcov,
 say Y.  If you're unsure, say N.
 
+config DEBUG_STACK_USAGE
+   bool "Stack utilization instrumentation"
+   default N
+   help
+   Track the maximum kernel stack usage - this will look at each
+   kernel stack at process exit and log it if it's the deepest
+   stack seen so far.
+
+   This option will slow down process creation and destruction somewhat.
 endmenu
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/process.c   2007-06-19 
14:06:36.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c2007-06-19 15:48:20.0 
-0400
@@ -411,3 +411,32 @@ unsigned long arch_align_stack(unsigned 
return sp & ~0xf;
 }
 #endif
+
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+static DEFINE_SPINLOCK(low_water_lock);
+static int lowest_to_date = THREAD_SIZE;
+
+void check_stack_usage(struct thread_info *s)
+{
+   unsigned int *stack, *p, *end;
+   int left;
+
+   stack = (unsigned int *) (s + 1);
+   end = (unsigned int *) ((unsigned long) s + THREAD_SIZE);
+   for (p = stack; p < end; p++) {
+   if(*p != 0)
+   break;
+   }
+
+   left = (p - stack) * sizeof(*p);
+
+   spin_lock(&low_water_lock);
+   if (left < lowest_to_date) {
+   printk("Greatest stack depth - %d bytes left\n", left);
+   lowest_to_date = left;
+   }
+   spin_unlock(&low_water_lock);
+}
+
+#endif
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h   2007-06-19 
14:06:36.0 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h2007-06-19 
14:06:44.0 -0400
@@ -52,6 +52,20 @@ static inline struct thread_info *curren
return ti;
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+extern void check_stack_usage(struct thread_info *stack);
+
+#define alloc_thread_info(tsk) \
+   ((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+CONFIG_KERNEL_STACK_ORDER))
+
+#define free_thread_info(ti) ({ check_stack_usage(ti) ; \
+   free_pages((unsigned long)(ti), \
+  CONFIG_KERNEL_STACK_ORDER); })
+
+#else
+
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
@@ -61,6 +75,8 @@ static inline struct thread_info *curren
 
 #endif
 
+#endif
+
 #define PREEMPT_ACTIVE 0x1000
 
 #define TIF_SYSCALL_TRACE  0   /* syscall trace active */
Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-06-19 14:

[PATCH 2/2] UML - Add stack usage monitoring

2007-06-19 Thread Jeff Dike
Add a machanism to see how much of a kernel stack is used.  This
allocates zeroed stacks and sees where the lowest non-zero byte is on
process exit.  It keeps track of the lowest value and logs values as
they get lower.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig.debug|9 +
 arch/um/defconfig|1 +
 arch/um/kernel/process.c |   29 +
 include/asm-um/thread_info.h |   16 
 4 files changed, 55 insertions(+)

Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug  2007-06-19 13:37:16.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug   2007-06-19 14:05:59.0 
-0400
@@ -47,4 +47,13 @@ config GCOV
 If you're involved in UML kernel development and want to use gcov,
 say Y.  If you're unsure, say N.
 
+config DEBUG_STACK_USAGE
+   bool "Stack utilization instrumentation"
+   default N
+   help
+   Track the maximum kernel stack usage - this will look at each
+   kernel stack at process exit and log it if it's the deepest
+   stack seen so far.
+
+   This option will slow down process creation and destruction somewhat.
 endmenu
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/process.c   2007-06-19 
13:37:16.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c2007-06-19 14:01:55.0 
-0400
@@ -411,3 +411,32 @@ unsigned long arch_align_stack(unsigned 
return sp & ~0xf;
 }
 #endif
+
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+static DEFINE_SPINLOCK(low_water_lock);
+static int lowest_to_date = THREAD_SIZE;
+
+void check_stack_usage(struct thread_info *s)
+{
+   unsigned int *stack, *p, *end;
+   int left;
+
+   stack = (unsigned int *) (s + 1);
+   end = (unsigned int *) ((unsigned long) s + THREAD_SIZE);
+   for(p = stack; p < end; p++){
+   if(*p != 0)
+   break;
+   }
+
+   left = (p - stack) * sizeof(*p);
+
+   spin_lock(&low_water_lock);
+   if(left < lowest_to_date){
+   printk("Greatest stack depth - %d bytes left\n", left);
+   lowest_to_date = left;
+   }
+   spin_unlock(&low_water_lock);
+}
+
+#endif
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h   2007-06-19 
13:37:16.0 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h2007-06-19 
13:57:07.0 -0400
@@ -52,6 +52,20 @@ static inline struct thread_info *curren
return ti;
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+extern void check_stack_usage(struct thread_info *stack);
+
+#define alloc_thread_info(tsk) \
+   ((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+CONFIG_KERNEL_STACK_ORDER))
+
+#define free_thread_info(ti) ({ check_stack_usage(ti) ; \
+   free_pages((unsigned long)(ti), \
+  CONFIG_KERNEL_STACK_ORDER); })
+
+#else
+
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
@@ -61,6 +75,8 @@ static inline struct thread_info *curren
 
 #endif
 
+#endif
+
 #define PREEMPT_ACTIVE 0x1000
 
 #define TIF_SYSCALL_TRACE  0   /* syscall trace active */
Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-06-19 13:37:16.0 
-0400
+++ linux-2.6.21-mm/arch/um/defconfig   2007-06-19 13:51:44.0 -0400
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y
 # CONFIG_RCU_TORTURE_TEST is not set
 # CONFIG_GPROF is not set
 # CONFIG_GCOV is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] UML - Use get_free_pages to allocate kernel stacks

2007-06-19 Thread Jeff Dike
For some reason, I was using kmalloc instead of get_free_pages for
kernel stacks.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/thread_info.h |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h   2007-06-19 
12:23:16.0 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h2007-06-19 
14:06:36.0 -0400
@@ -54,8 +54,10 @@ static inline struct thread_info *curren
 
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
-   ((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
-#define free_thread_info(ti) kfree(ti)
+   ((struct thread_info *) __get_free_pages(GFP_KERNEL, \
+CONFIG_KERNEL_STACK_ORDER))
+#define free_thread_info(ti) \
+   free_pages((unsigned long)(ti),CONFIG_KERNEL_STACK_ORDER)
 
 #endif
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] UML stack tweaks

2007-06-19 Thread Jeff Dike
These can wait till 2.6.23.

They use get_free_page instead of kmalloc to allocate kernel stacks
and add some stack usage monitoring under CONFIG_DEBUG_STACK_USAGE.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Allow group ownership of TUN/TAP devices

2007-06-18 Thread Jeff Dike
I recieved from Guido Guenther the patch below to the TUN/TAP driver
which allows group ownerships to be effective.

It seems reasonable to me.

> the attached patches allow tun ownership by group. We found this useful
> since we can then spawn tapX devices on system boot (via
> /etc/network/interfaces) which logged on users can then use for their
> virtual machines.
>   
> The first patch is for the kernel, the second one for the tunctl. They
> shouldn't change existing behaviour and we introduced a new syscall for
> the group setting. The user now is allowed to send packages if either
> his euid or his egid matches the one specified via tunctl (via -u or -g
> respecitvely). If both gid and uid are set via tunctl, both have to
> match. In case you find these useful, please apply.

-- 
Work email - jdike at linux dot intel dot com

From: Guido Guenther <[EMAIL PROTECTED]>
Date: Fri, 25 May 2007 11:10:27 +0200
Subject: [PATCH] allow tun ownership by group

---
 drivers/net/tun.c  |   15 +--
 include/linux/if_tun.h |2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a2c6caa..62b2b30 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -432,6 +432,7 @@ static void tun_setup(struct net_device *dev)
init_waitqueue_head(&tun->read_wait);
 
tun->owner = -1;
+   tun->group = -1;
 
SET_MODULE_OWNER(dev);
dev->open = tun_net_open;
@@ -467,8 +468,11 @@ static int tun_set_iff(struct file *file, struct ifreq 
*ifr)
return -EBUSY;
 
/* Check permissions */
-   if (tun->owner != -1 &&
-   current->euid != tun->owner && !capable(CAP_NET_ADMIN))
+   if (((tun->owner != -1 &&
+ current->euid != tun->owner) ||
+(tun->group != -1 &&
+ current->egid != tun->group)) &&
+!capable(CAP_NET_ADMIN))
return -EPERM;
}
else if (__dev_get_by_name(ifr->ifr_name))
@@ -610,6 +614,13 @@ static int tun_chr_ioctl(struct inode *inode, struct file 
*file,
DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, 
tun->owner);
break;
 
+   case TUNSETGROUP:
+   /* Set group of the device */
+   tun->group= (gid_t) arg;
+
+   DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, 
tun->group);
+   break;
+
case TUNSETLINK:
/* Only allow setting the type when the interface is down */
if (tun->dev->flags & IFF_UP) {
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index 88aef7b..42eb694 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -36,6 +36,7 @@ struct tun_struct {
unsigned long   flags;
int attached;
uid_t   owner;
+   gid_t   group;
 
wait_queue_head_t   read_wait;
struct sk_buff_head readq;
@@ -78,6 +79,7 @@ struct tun_struct {
 #define TUNSETPERSIST _IOW('T', 203, int) 
 #define TUNSETOWNER   _IOW('T', 204, int)
 #define TUNSETLINK_IOW('T', 205, int)
+#define TUNSETGROUP   _IOW('T', 206, int)
 
 /* TUNSETIFF ifr flags */
 #define IFF_TUN0x0001
-- 
1.5.1.4

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] UML - Use generic BUG

2007-06-15 Thread Jeff Dike
From: Nick Piggin <[EMAIL PROTECTED]>

Get UML to use the generic bug support rather than arch specific one.

If I insert an artificial bug right before loading init, I get this:

 Kernel panic - not syncing: Kernel mode signal 4

 EIP: 0023:[<0819d501>] CPU: 0 Not tainted ESP: 002b:f7fd4fbc EFLAGS: 0246
Not tainted
EAX:  EBX: 7870 ECX: 0013 EDX: 7870
ESI: 786d EDI: 0011 EBP: f7fd4fd8 DS: 002b ES: 002b
08273bec:  [<0806e814>] show_regs+0x104/0x106
08273c08:  [<08058927>] panic_exit+0x2c/0x4b
08273c18:  [<08080ee7>] notifier_call_chain+0x32/0x5b
08273c38:  [<08080fbd>] __atomic_notifier_call_chain+0x30/0x32
08273c54:  [<08080fee>] atomic_notifier_call_chain+0x2f/0x31
08273c70:  [<08073b88>] panic+0x75/0x131
08273c94:  [<080586c7>] relay_signal+0x87/0x95
08273cb0:  [<0806b9ee>] sig_handler_common_skas+0x9e/0x120
08273cd8:  [<08067738>] sig_handler+0x28/0x4f
08273cec:  [<0806792e>] handle_signal+0x53/0x89
08273d0c:  [<08069f60>] hard_handler+0x18/0x28
08273d1c:  [] transitions+0xf7d598b8/0xfff0


With this patch in place, this is how it looks:

 BUG: failure at init/main.c:779/init_post()!
 Kernel panic - not syncing: BUG!

 EIP: 0023:[<081a65d1>] CPU: 0 Not tainted ESP: 002b:f7f0dfbc EFLAGS: 0246
Not tainted
EAX:  EBX: 69db ECX: 0013 EDX: 69db
ESI: 69d8 EDI: 0011 EBP: f7f0dfd8 DS: 002b ES: 002b
098efedc:  [<0806e9a4>] show_regs+0x104/0x106
098efef8:  [<080589c7>] panic_exit+0x2c/0x4b
098eff08:  [<080818d7>] notifier_call_chain+0x32/0x5b
098eff28:  [<080819ad>] __atomic_notifier_call_chain+0x30/0x32
098eff44:  [<080819de>] atomic_notifier_call_chain+0x2f/0x31
098eff60:  [<08073f28>] panic+0x75/0x131
098eff84:  [<080541d5>] init_post+0xcd/0xe8
098eff9c:  [<08048ad4>] kernel_init+0x8e/0x9a
098effb4:  [<08066dee>] run_kernel_thread+0x41/0x53
098effe0:  [<08058e75>] new_thread_handler+0x62/0x8b
    098efffc:  [] 0xa55a5a5a

[ jdike - added BUG_TABLE to linker script ]

Signed-off-by: Nick Piggin <[EMAIL PROTECTED]>
Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/bug.h|2 +-
 include/asm-um/common.lds.S |2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

Index: linux-2.6.21-mm/include/asm-um/bug.h
===
--- linux-2.6.21-mm.orig/include/asm-um/bug.h   2007-06-14 15:28:21.0 
-0400
+++ linux-2.6.21-mm/include/asm-um/bug.h2007-06-14 16:10:07.0 
-0400
@@ -1,6 +1,6 @@
 #ifndef __UM_BUG_H
 #define __UM_BUG_H
 
-#include 
+#include 
 
 #endif
Index: linux-2.6.21-mm/include/asm-um/common.lds.S
===
--- linux-2.6.21-mm.orig/include/asm-um/common.lds.S2007-05-07 
10:24:48.0 -0400
+++ linux-2.6.21-mm/include/asm-um/common.lds.S 2007-06-15 11:00:48.0 
-0400
@@ -20,6 +20,8 @@
   __ex_table : { *(__ex_table) }
   __stop___ex_table = .;
 
+  BUG_TABLE
+
   __uml_setup_start = .;
   .uml.setup.init : { *(.uml.setup.init) }
   __uml_setup_end = .;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] UML - add asm/paravirt.h

2007-06-15 Thread Jeff Dike
Add asm-um/paravirt.h so that i386 headers that get pulled into UML
don't cause build failures when they want asm/paravirt.h.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/paravirt.h |6 ++
 1 file changed, 6 insertions(+)

Index: linux-2.6.21-mm/include/asm-um/paravirt.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.21-mm/include/asm-um/paravirt.h   2007-06-14 12:02:04.0 
-0400
@@ -0,0 +1,6 @@
+#ifndef __UM_PARAVIRT_H
+#define __UM_PARAVIRT_H
+
+#include "asm/arch/paravirt.h"
+
+#endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] UML - Two for 2.6.22

2007-06-15 Thread Jeff Dike
These two are for 2.6.22.

The first switches to the generic BUG support and adds a related build
fix.  The second is a build fix for configurations which pull in i386
headers which want paravirt.h.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: UML - Compilation problem on 2.6.22-rc4

2007-06-15 Thread Jeff Dike
On Fri, Jun 15, 2007 at 11:53:55AM +0530, Arun Raghavan wrote:
> Hello,
> I ran into some compilations problems with UML on the 2.6.22-rc4 kernel.
> The problem turns up because "paravirt.h" is included in a couple of
> headers in asm-i386 without being protected by a "#ifdef CONFIG_PARAVIRT".
> 
> I've attached a patch to fix this (i.e. UML compiles and runs fine for
> me with these changes). I don't know if this is sufficient for all cases
> though (most other uses of the #ifdef include a lengthy #else).

Thanks, I have this fixed by making an asm-um/paravirt.h instead.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/5] UML - handle errors on opening host side of consoles

2007-06-14 Thread Jeff Dike
If the host side of a console can't be opened, this will now produce
visible error messages.

enable_chan now returns a status and this is passed up to con_open and
ssl_open, which will complain if anything went wrong.

The default host device for the serial line driver is now a pts device
rather than a pty device since lots of hosts have LEGACY_PTYS
disabled.  This had always been failing on such hosts, but silently.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/defconfig   |2 +-
 arch/um/drivers/chan_kern.c |   23 +++
 arch/um/drivers/line.c  |5 -
 arch/um/drivers/ssl.c   |8 +++-
 arch/um/drivers/stdio_console.c |7 ++-
 arch/um/include/chan_kern.h |2 +-
 6 files changed, 38 insertions(+), 9 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/chan_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/chan_kern.c2007-06-14 
15:40:01.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/chan_kern.c 2007-06-14 16:00:23.0 
-0400
@@ -203,22 +203,37 @@ void chan_enable_winch(struct list_head 
}
 }
 
-void enable_chan(struct line *line)
+int enable_chan(struct line *line)
 {
struct list_head *ele;
struct chan *chan;
+   int err;
 
list_for_each(ele, &line->chan_list){
chan = list_entry(ele, struct chan, list);
-   if(open_one_chan(chan))
+   err = open_one_chan(chan);
+   if (err) {
+   if (chan->primary)
+   goto out_close;
+
continue;
+   }
 
if(chan->enabled)
continue;
-   line_setup_irq(chan->fd, chan->input, chan->output, line,
-  chan);
+   err = line_setup_irq(chan->fd, chan->input, chan->output, line,
+chan);
+   if (err)
+   goto out_close;
+
chan->enabled = 1;
}
+
+   return 0;
+
+ out_close:
+   close_chan(&line->chan_list, 0);
+   return err;
 }
 
 /* Items are added in IRQ context, when free_irq can't be called, and
Index: linux-2.6.21-mm/arch/um/drivers/line.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/line.c 2007-06-14 15:40:01.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/line.c  2007-06-14 16:00:23.0 
-0400
@@ -454,7 +454,10 @@ int line_open(struct line *lines, struct
tty->driver_data = line;
line->tty = tty;
 
-   enable_chan(line);
+   err = enable_chan(line);
+   if (err)
+   return err;
+
INIT_DELAYED_WORK(&line->task, line_timer_cb);
 
if(!line->sigio){
Index: linux-2.6.21-mm/arch/um/drivers/ssl.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ssl.c  2007-06-14 15:40:01.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/ssl.c   2007-06-14 16:00:23.0 
-0400
@@ -97,7 +97,13 @@ static int ssl_remove(int n, char **erro
 
 static int ssl_open(struct tty_struct *tty, struct file *filp)
 {
-   return line_open(serial_lines, tty);
+   int err = line_open(serial_lines, tty);
+
+   if (err)
+   printk(KERN_ERR "Failed to open serial line %d, err = %d\n",
+  tty->index, err);
+
+   return err;
 }
 
 #if 0
Index: linux-2.6.21-mm/arch/um/drivers/stdio_console.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/stdio_console.c2007-06-14 
15:40:01.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/stdio_console.c 2007-06-14 
16:00:23.0 -0400
@@ -99,7 +99,12 @@ static int con_remove(int n, char **erro
 
 static int con_open(struct tty_struct *tty, struct file *filp)
 {
-   return line_open(vts, tty);
+   int err = line_open(vts, tty);
+   if (err)
+   printk(KERN_ERR "Failed to open console %d, err = %d\n",
+  tty->index, err);
+
+   return err;
 }
 
 /* Set in an initcall, checked in an exitcall */
Index: linux-2.6.21-mm/arch/um/include/chan_kern.h
===
--- linux-2.6.21-mm.orig/arch/um/include/chan_kern.h2007-06-14 
15:40:01.0 -0400
+++ linux-2.6.21-mm/arch/um/include/chan_kern.h 2007-06-14 16:00:23.0 
-0400
@@ -40,7 +40,7 @@ extern int console_open_chan(struct line
 extern void deactivate_chan(struct list_head *chans, int irq);
 extern void reactivate_chan(struct list_head *chans, int irq);
 extern void chan_enable_winch(struct list_head *chans, struct tty_struct *tty);
-extern void enable_chan(struct line 

[PATCH 1/5] UML - pty channel tidying

2007-06-14 Thread Jeff Dike
Cleanup, mostly style violations.

Tidied the includes.

getmaster returns a real errno, which pty_open returns if there's a
problem.

The printks now have severity.

Changed os_* calls to call libc directly.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/pty.c |   76 ++
 1 file changed, 40 insertions(+), 36 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/pty.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/pty.c  2007-06-06 09:28:13.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/pty.c   2007-06-14 15:35:13.0 
-0400
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2001, 2002 Jeff Dike ([EMAIL PROTECTED])
+ * Copyright (C) 2001 - 2007 Jeff Dike ([EMAIL PROTECTED],linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -7,12 +7,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include "chan_user.h"
-#include "user.h"
-#include "kern_util.h"
 #include "os.h"
+#include "user.h"
+#include "kern_constants.h"
 #include "um_malloc.h"
 
 struct pty_chan {
@@ -28,11 +30,13 @@ static void *pty_chan_init(char *str, in
struct pty_chan *data;
 
data = um_kmalloc(sizeof(*data));
-   if(data == NULL) return(NULL);
+   if (data == NULL)
+   return NULL;
+
*data = ((struct pty_chan) { .announce  = opts->announce, 
 .dev   = device,
 .raw   = opts->raw });
-   return(data);
+   return data;
 }
 
 static int pts_open(int input, int output, int primary, void *d,
@@ -43,31 +47,35 @@ static int pts_open(int input, int outpu
int fd, err;
 
fd = get_pty();
-   if(fd < 0){
+   if (fd < 0) {
err = -errno;
-   printk("open_pts : Failed to open pts\n");
+   printk(UM_KERN_ERR "open_pts : Failed to open pts\n");
return err;
}
-   if(data->raw){
+
+   if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
-   if(err)
-   return(err);
+   if (err)
+   return err;
 
err = raw(fd);
-   if(err)
-   return(err);
+   if (err)
+   return err;
}
 
dev = ptsname(fd);
sprintf(data->dev_name, "%s", dev);
*dev_out = data->dev_name;
+
if (data->announce)
(*data->announce)(dev, data->dev);
-   return(fd);
+
+   return fd;
 }
 
 static int getmaster(char *line)
 {
+   struct stat buf;
char *pty, *bank, *cp;
int master, err;
 
@@ -75,24 +83,29 @@ static int getmaster(char *line)
for (bank = "pqrs"; *bank; bank++) {
line[strlen("/dev/pty")] = *bank;
*pty = '0';
-   if (os_stat_file(line, NULL) < 0)
+   /* Did we hit the end ? */
+   if ((stat(line, &buf) < 0) && (errno == ENOENT))
break;
+
for (cp = "0123456789abcdef"; *cp; cp++) {
*pty = *cp;
-   master = os_open_file(line, of_rdwr(OPENFLAGS()), 0);
+   master = open(line, O_RDWR);
if (master >= 0) {
char *tp = &line[strlen("/dev/")];
 
/* verify slave side is usable */
*tp = 't';
-   err = os_access(line, OS_ACC_RW_OK);
+   err = access(line, R_OK | W_OK);
*tp = 'p';
-   if(err == 0) return(master);
-   (void) os_close_file(master);
+   if(!err)
+   return master;
+   close(master);
}
}
}
-   return(-1);
+
+   printk(UM_KERN_ERR "getmaster - no usable host pty devices\n");
+   return -ENOENT;
 }
 
 static int pty_open(int input, int output, int primary, void *d,
@@ -103,20 +116,22 @@ static int pty_open(int input, int outpu
char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
 
fd = getmaster(dev);
-   if(fd < 0)
-   return(-errno);
+   if (fd < 0)
+   return fd;
 
if(data->raw){
err = raw(fd);
-   if(err)
-   return(err);
+   if (err)
+

[PATCH 5/5] UML - Eliminate kernel allocator wrappers

2007-06-14 Thread Jeff Dike
UML had two wrapper procedures for kmalloc, um_kmalloc and
um_kmalloc_atomic because the flag constants weren't available in
userspace code.  kern_constants.h had made kernel constants available
for a long time, so there is no need for these wrappers any more.
Rather, userspace code calls kmalloc directly with the userspace
versions of the gfp flags.

kmalloc isn't a real procedure, so I had to essentially copy the
inline wrapper around __kmalloc.

vmalloc also had its own wrapper for no good reason.  This is now gone.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/cow_sys.h|2 +-
 arch/um/drivers/daemon_user.c|4 ++--
 arch/um/drivers/fd.c |2 +-
 arch/um/drivers/mcast_user.c |2 +-
 arch/um/drivers/net_user.c   |2 +-
 arch/um/drivers/port_user.c  |2 +-
 arch/um/drivers/pty.c|2 +-
 arch/um/drivers/slip_user.c  |2 +-
 arch/um/drivers/tty.c|2 +-
 arch/um/include/common-offsets.h |3 +++
 arch/um/include/um_malloc.h  |   12 +---
 arch/um/kernel/irq.c |1 -
 arch/um/kernel/process.c |   16 
 arch/um/os-Linux/drivers/ethertap_user.c |4 ++--
 arch/um/os-Linux/helper.c|4 ++--
 arch/um/os-Linux/main.c  |4 ++--
 arch/um/os-Linux/sigio.c |4 ++--
 17 files changed, 30 insertions(+), 38 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/cow_sys.h
===
--- linux-2.6.21-mm.orig/arch/um/drivers/cow_sys.h  2007-06-14 
15:33:34.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/cow_sys.h   2007-06-14 16:08:07.0 
-0400
@@ -8,7 +8,7 @@
 
 static inline void *cow_malloc(int size)
 {
-   return um_kmalloc(size);
+   return kmalloc(size, UM_GFP_KERNEL);
 }
 
 static inline void cow_free(void *ptr)
Index: linux-2.6.21-mm/arch/um/drivers/daemon_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/daemon_user.c  2007-06-14 
15:33:34.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/daemon_user.c   2007-06-14 
16:08:07.0 -0400
@@ -35,7 +35,7 @@ static struct sockaddr_un *new_addr(void
 {
struct sockaddr_un *sun;
 
-   sun = um_kmalloc(sizeof(struct sockaddr_un));
+   sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
return NULL;
@@ -83,7 +83,7 @@ static int connect_to_switch(struct daem
goto out_close;
}
 
-   sun = um_kmalloc(sizeof(struct sockaddr_un));
+   sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
err = -ENOMEM;
Index: linux-2.6.21-mm/arch/um/drivers/fd.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/fd.c   2007-06-14 15:33:34.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/fd.c2007-06-14 16:08:07.0 
-0400
@@ -37,7 +37,7 @@ static void *fd_init(char *str, int devi
printk("fd_init : couldn't parse file descriptor '%s'\n", str);
return(NULL);
}
-   data = um_kmalloc(sizeof(*data));
+   data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if(data == NULL) return(NULL);
*data = ((struct fd_chan) { .fd = n,
.raw= opts->raw });
Index: linux-2.6.21-mm/arch/um/drivers/mcast_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/mcast_user.c   2007-06-14 
15:33:34.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/mcast_user.c2007-06-14 
16:08:07.0 -0400
@@ -30,7 +30,7 @@ static struct sockaddr_in *new_addr(char
 {
struct sockaddr_in *sin;
 
-   sin = um_kmalloc(sizeof(struct sockaddr_in));
+   sin = kmalloc(sizeof(struct sockaddr_in), UM_GFP_KERNEL);
if(sin == NULL){
printk("new_addr: allocation of sockaddr_in failed\n");
return NULL;
Index: linux-2.6.21-mm/arch/um/drivers/net_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/net_user.c 2007-06-14 
16:07:30.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/net_user.c  2007-06-14 16:08:07.0 
-0400
@@ -217,7 +217,7 @@ static void change(char *dev, char *what
netmask[2], netmask[3]);
 
output_len = UM_KERN_PAGE_SIZE;
-   output = um_kmalloc(output_len);
+   output = kmalloc(output_len, UM_GFP_KERN

[PATCH 4/5] UML - Simplify helper stack handling

2007-06-14 Thread Jeff Dike
run_helper and run_helper_thread had arguments which were the same in
all callers.  run_helper's stack_out was always NULL and
run_helper_thread's stack_order was always 0.  These are now gone, and
the constants folded into the code.

Also fixed leaks of the helper stack in the AIO and SIGIO code.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/chan_user.c  |2 +-
 arch/um/drivers/harddog_user.c   |2 +-
 arch/um/drivers/net_user.c   |2 +-
 arch/um/drivers/port_user.c  |2 +-
 arch/um/drivers/slip_user.c  |2 +-
 arch/um/drivers/slirp_user.c |2 +-
 arch/um/drivers/xterm.c  |2 +-
 arch/um/include/os.h |6 ++
 arch/um/os-Linux/aio.c   |   11 ++-
 arch/um/os-Linux/drivers/ethertap_user.c |2 +-
 arch/um/os-Linux/drivers/tuntap_user.c   |2 +-
 arch/um/os-Linux/helper.c|   19 +++
 arch/um/os-Linux/sigio.c |   19 ---
 13 files changed, 36 insertions(+), 37 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/harddog_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/harddog_user.c 2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/harddog_user.c  2007-06-13 
18:44:41.0 -0400
@@ -68,7 +68,7 @@ int start_watchdog(int *in_fd_ret, int *
args = pid_args;
}
 
-   pid = run_helper(pre_exec, &data, args, NULL);
+   pid = run_helper(pre_exec, &data, args);
 
os_close_file(out_fds[0]);
os_close_file(in_fds[1]);
Index: linux-2.6.21-mm/arch/um/drivers/net_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/net_user.c 2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/net_user.c  2007-06-14 11:20:36.0 
-0400
@@ -187,7 +187,7 @@ static int change_tramp(char **argv, cha
}
pe_data.close_me = fds[0];
pe_data.stdout = fds[1];
-   pid = run_helper(change_pre_exec, &pe_data, argv, NULL);
+   pid = run_helper(change_pre_exec, &pe_data, argv);
 
if (pid > 0)/* Avoid hang as we won't get data in failure case. */
read_output(fds[0], output, output_len);
Index: linux-2.6.21-mm/arch/um/drivers/port_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/port_user.c2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/port_user.c 2007-06-14 11:20:36.0 
-0400
@@ -188,7 +188,7 @@ int port_connection(int fd, int *socket,
{ .sock_fd  = new,
  .pipe_fd  = socket[1] });
 
-   err = run_helper(port_pre_exec, &data, argv, NULL);
+   err = run_helper(port_pre_exec, &data, argv);
if(err < 0)
goto out_shutdown;
 
Index: linux-2.6.21-mm/arch/um/drivers/slip_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/slip_user.c2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/slip_user.c 2007-06-14 11:20:36.0 
-0400
@@ -85,7 +85,7 @@ static int slip_tramp(char **argv, int f
pe_data.stdin = fd;
pe_data.stdout = fds[1];
pe_data.close_me = fds[0];
-   err = run_helper(slip_pre_exec, &pe_data, argv, NULL);
+   err = run_helper(slip_pre_exec, &pe_data, argv);
if(err < 0)
goto out_close;
pid = err;
Index: linux-2.6.21-mm/arch/um/drivers/slirp_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/slirp_user.c   2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/slirp_user.c2007-06-13 
18:44:41.0 -0400
@@ -42,7 +42,7 @@ static int slirp_tramp(char **argv, int 
 
pe_data.stdin = fd;
pe_data.stdout = fd;
-   pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL);
+   pid = run_helper(slirp_pre_exec, &pe_data, argv);
 
return(pid);
 }
Index: linux-2.6.21-mm/arch/um/drivers/xterm.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/xterm.c2007-06-13 
17:13:42.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/xterm.c 2007-06-13 18:44:41.0 
-0400
@@ -132,7 +132,7 @@ static int xterm_open(int input, int out
}
 
sprintf(title, data->title, data->device);
-   pid = run_helper(NULL, NULL, argv, NULL);
+   pid = run_helper(NULL, NULL, argv);
if (pid < 0) {
err = pid;
printk(UM_KERN_ERR

[PATCH 0/5] UML cleanups for post-2.6.22

2007-06-14 Thread Jeff Dike
This patch set is code cleanup, mostly.  It can wait until after 2.6.22.

Jeff
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/5] UML - SIGIO support cleanup

2007-06-14 Thread Jeff Dike
Cleanup of the SIGWINCH support.

Some code and comment reformatting.

The stack used for SIGWINCH threads was leaked.  This is now fixed by
storing it with the pid and other information, and freeing it when the
thread is killed.

If something goes wrong with a WIGWINCH thread, and this is discovered
in the interrupt handler, the winch record would leak.  It is now
freed, except that the IRQ isn't freed.  This is hard to do from
interrupt context.  This has the side-effect that the IRQ system
maintains a reference to the freed structure, but that shouldn't cause
a problem since the descriptor is disabled.

register_winch_irq is now much better about cleaning up after an
initialization failure.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/chan_user.c |   70 +---
 arch/um/drivers/line.c  |   60 ++
 arch/um/include/chan_user.h |3 +
 arch/um/os-Linux/skas/process.c |2 -
 4 files changed, 80 insertions(+), 55 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/chan_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/chan_user.c2007-06-14 
15:33:37.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/chan_user.c 2007-06-14 16:04:12.0 
-0400
@@ -51,19 +51,21 @@ error:
 /*
  * UML SIGWINCH handling
  *
- * The point of this is to handle SIGWINCH on consoles which have host ttys and
- * relay them inside UML to whatever might be running on the console and cares
- * about the window size (since SIGWINCH notifies about terminal size changes).
+ * The point of this is to handle SIGWINCH on consoles which have host
+ * ttys and relay them inside UML to whatever might be running on the
+ * console and cares about the window size (since SIGWINCH notifies
+ * about terminal size changes).
  *
- * So, we have a separate thread for each host tty attached to a UML device
- * (side-issue - I'm annoyed that one thread can't have multiple controlling
- * ttys for purposed of handling SIGWINCH, but I imagine there are other 
reasons
- * that doesn't make any sense).
+ * So, we have a separate thread for each host tty attached to a UML
+ * device (side-issue - I'm annoyed that one thread can't have
+ * multiple controlling ttys for the purpose of handling SIGWINCH, but
+ * I imagine there are other reasons that doesn't make any sense).
  *
- * SIGWINCH can't be received synchronously, so you have to set up to receive 
it
- * as a signal.  That being the case, if you are going to wait for it, it is
- * convenient to sit in sigsuspend() and wait for the signal to bounce you out 
of
- * it (see below for how we make sure to exit only on SIGWINCH).
+ * SIGWINCH can't be received synchronously, so you have to set up to
+ * receive it as a signal.  That being the case, if you are going to
+ * wait for it, it is convenient to sit in sigsuspend() and wait for
+ * the signal to bounce you out of it (see below for how we make sure
+ * to exit only on SIGWINCH).
  */
 
 static void winch_handler(int sig)
@@ -112,7 +114,8 @@ static int winch_thread(void *arg)
 
err = os_new_tty_pgrp(pty_fd, os_getpid());
if(err < 0){
-   printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err);
+   printk("winch_thread : new_tty_pgrp failed on fd %d, "
+  "err = %d\n", pty_fd, -err);
exit(1);
}
 
@@ -126,8 +129,9 @@ static int winch_thread(void *arg)
   "err = %d\n", -count);
 
while(1){
-   /* This will be interrupted by SIGWINCH only, since other 
signals
-* are blocked.*/
+   /* This will be interrupted by SIGWINCH only, since
+* other signals are blocked.
+*/
sigsuspend(&sigs);
 
count = os_write_file(pipe_fd, &c, sizeof(c));
@@ -137,10 +141,10 @@ static int winch_thread(void *arg)
}
 }
 
-static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out)
+static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
+  unsigned long *stack_out)
 {
struct winch_data data;
-   unsigned long stack;
int fds[2], n, err;
char c;
 
@@ -153,9 +157,11 @@ static int winch_tramp(int fd, struct tt
data = ((struct winch_data) { .pty_fd   = fd,
  .pipe_fd  = fds[1] } );
/* CLONE_FILES so this thread doesn't hold open files which are open
-* now, but later closed.  This is a problem with /dev/net/tun.
+* now, but later closed in a different thread.  This is a
+* problem with /dev/net/tun, which if held open by this
+* thread, prevents the TUN/TAP device from being reused.
 */
-   er

Re: [patch] uml: better bugs

2007-06-14 Thread Jeff Dike
On Thu, Jun 14, 2007 at 07:38:33AM +0200, Nick Piggin wrote:
> Get UML to use the generic bug support rather than arch specific one.

Added to my tree, thanks.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] UML - xterm driver tidying

2007-06-13 Thread Jeff Dike
Major tidying of the xterm console driver:
got rid of the tt-mode gdb support
tidied up the includes
fixed lots of style violations
replaced os_* calls with glibc calls in xterm.c
all printk calls now have a severity indicator
the error paths of xterm_open are closer to being right

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/ssl.c   |2 
 arch/um/drivers/stdio_console.c |2 
 arch/um/drivers/xterm.c |  173 
 arch/um/drivers/xterm_kern.c|   49 +++
 arch/um/include/chan_user.h |2 
 5 files changed, 105 insertions(+), 123 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/ssl.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ssl.c  2007-06-11 21:14:50.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/ssl.c   2007-06-11 21:15:08.0 
-0400
@@ -42,8 +42,6 @@ static struct chan_opts opts = {
.announce   = ssl_announce,
.xterm_title= "Serial Line #%d",
.raw= 1,
-   .tramp_stack= 0,
-   .in_kernel  = 1,
 };
 
 static int ssl_config(char *str, char **error_out);
Index: linux-2.6.21-mm/arch/um/drivers/stdio_console.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/stdio_console.c2007-06-11 
21:14:50.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/stdio_console.c 2007-06-11 
21:15:08.0 -0400
@@ -46,8 +46,6 @@ static struct chan_opts opts = {
.announce   = stdio_announce,
.xterm_title= "Virtual Console #%d",
.raw= 1,
-   .tramp_stack= 0,
-   .in_kernel  = 1,
 };
 
 static int con_config(char *str, char **error_out);
Index: linux-2.6.21-mm/arch/um/drivers/xterm.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/xterm.c2007-06-11 
21:14:51.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/xterm.c 2007-06-11 21:15:16.0 
-0400
@@ -1,22 +1,20 @@
 /* 
- * Copyright (C) 2001, 2002 Jeff Dike ([EMAIL PROTECTED])
+ * Copyright (C) 2001 - 2007 Jeff Dike ([EMAIL PROTECTED],linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include "kern_util.h"
 #include "chan_user.h"
-#include "user.h"
 #include "os.h"
+#include "init.h"
+#include "user.h"
 #include "xterm.h"
+#include "kern_constants.h"
 
 struct xterm_chan {
int pid;
@@ -25,25 +23,21 @@ struct xterm_chan {
int device;
int raw;
struct termios tt;
-   unsigned long stack;
-   int direct_rcv;
 };
 
-/* Not static because it's called directly by the tt mode gdb code */
-void *xterm_init(char *str, int device, const struct chan_opts *opts)
+static void *xterm_init(char *str, int device, const struct chan_opts *opts)
 {
struct xterm_chan *data;
 
data = malloc(sizeof(*data));
-   if(data == NULL) return(NULL);
-   *data = ((struct xterm_chan) { .pid = -1, 
+   if (data == NULL)
+   return NULL;
+   *data = ((struct xterm_chan) { .pid = -1,
   .helper_pid  = -1,
-  .device  = device, 
+  .device  = device,
   .title   = opts->xterm_title,
-  .raw = opts->raw,
-  .stack   = opts->tramp_stack,
-  .direct_rcv  = !opts->in_kernel } );
-   return(data);
+  .raw = opts->raw } );
+   return data;
 }
 
 /* Only changed by xterm_setup, which is a setup */
@@ -57,16 +51,22 @@ static int __init xterm_setup(char *line
terminal_emulator = line;
 
line = strchr(line, ',');
-   if(line == NULL) return(0);
+   if (line == NULL)
+   return 0;
+
*line++ = '\0';
-   if(*line) title_switch = line;
+   if (*line)
+   title_switch = line;
 
line = strchr(line, ',');
-   if(line == NULL) return(0);
+   if (line == NULL)
+   return 0;
+
*line++ = '\0';
-   if(*line) exec_switch = line;
+   if (*line)
+   exec_switch = line;
 
-   return(0);
+   return 0;
 }
 
 __uml_setup("xterm=", xterm_setup,
@@ -82,114 +82,128 @@ __uml_setup("xterm=", xterm_setup,
 "are 'xterm=gnome-terminal,-t,-x'.\n\n"
 );
 

[PATCH 1/2] UML - DEBUG_SHIRQ fixes

2007-06-13 Thread Jeff Dike
From: Eduard-Gabriel Munteanu <[EMAIL PROTECTED]>

DEBUG_SHIRQ generates spurious interrupts, triggering handlers such as
mconsole_interrupt() or line_interrupt(). They expect data to be
available to be read from their sockets/pipes, but in the case of
spurious interrupts, the host didn't actually send anything, so UML  
hangs in read() and friends. Setting those fd's as O_NONBLOCK makes 
DEBUG_SHIRQ-enabled UML kernels boot and run correctly.

The patch was written and tested on Linux 2.6.22-rc2-mm1.

I have also included a couple of short/minor fixes for potential
problems.

Signed-off-by: Eduard-Gabriel Munteanu <[EMAIL PROTECTED]>
Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/chan_user.c |8 +++-
 arch/um/drivers/mconsole_user.c |5 +++--
 arch/um/drivers/ubd_user.c  |6 ++
 arch/um/drivers/xterm.c |7 +++
 4 files changed, 23 insertions(+), 3 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/chan_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/chan_user.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/chan_user.c 2007-06-11 13:51:29.0 
-0400
@@ -170,7 +170,13 @@ static int winch_tramp(int fd, struct tt
 err = -EINVAL;
goto out_close;
}
-   return err ;
+
+   if (os_set_fd_block(*fd_out, 0)) {
+   printk("winch_tramp: failed to set thread_fd non-blocking.\n");
+   goto out_close;
+   }
+
+   return err;
 
  out_close:
os_close_file(fds[1]);
Index: linux-2.6.21-mm/arch/um/drivers/mconsole_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/mconsole_user.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/mconsole_user.c 2007-06-11 
13:38:19.0 -0400
@@ -86,8 +86,9 @@ int mconsole_get_request(int fd, struct 
int len;
 
req->originlen = sizeof(req->origin);
-   req->len = recvfrom(fd, &req->request, sizeof(req->request), 0,
-   (struct sockaddr *) req->origin, &req->originlen);
+   req->len = recvfrom(fd, &req->request, sizeof(req->request),
+   MSG_DONTWAIT, (struct sockaddr *) req->origin,
+   &req->originlen);
if (req->len < 0)
return 0;
 
Index: linux-2.6.21-mm/arch/um/drivers/ubd_user.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ubd_user.c 2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/ubd_user.c  2007-06-11 13:44:56.0 
-0400
@@ -43,6 +43,12 @@ int start_io_thread(unsigned long sp, in
kernel_fd = fds[0];
*fd_out = fds[1];
 
+   err = os_set_fd_block(*fd_out, 0);
+   if (err) {
+   printk("start_io_thread - failed to set nonblocking I/O.\n");
+   goto out_close;
+   }
+
pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM | SIGCHLD,
NULL);
if(pid < 0){
Index: linux-2.6.21-mm/arch/um/drivers/xterm.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/xterm.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/xterm.c 2007-06-12 12:25:44.0 
-0400
@@ -151,6 +151,13 @@ int xterm_open(int input, int output, in
goto out;
}
 
+   err = os_set_fd_block(new, 0);
+   if (err) {
+   printk("xterm_open : failed to set xterm descriptor "
+  "non-blocking, err = %d\n", -err);
+   goto out;
+   }
+
CATCH_EINTR(err = tcgetattr(new, &data->tt));
if(err){
new = err;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] UML bug fixes and cleanups

2007-06-13 Thread Jeff Dike
These two are for 2.6.22.  We have a patch which makes UML boot with
DEBUG_SHIRQ enabled and one which cleans up the xterm driver.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] UML - Remove PAGE_SIZE from libc code

2007-06-12 Thread Jeff Dike
Distros seem to be removing PAGE_SIZE from asm/page.h.  So, the libc
side of UML should stop using it.

I replace it with UM_KERN_PAGE_SIZE, which is defined to be the same
as PAGE_SIZE on the kernel side of the house.  I could also use
getpagesize(), but it's more important that UML have the same value of
PAGE_SIZE everywhere.  It's conceivable that it could be built with a
larger PAGE_SIZE, and use of getpagesize() would break that badly.

PAGE_MASK got the same treatment, as it is closely tied to PAGE_SIZE.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/include/common-offsets.h |1 +
 arch/um/os-Linux/main.c  |4 +++-
 arch/um/os-Linux/skas/mem.c  |   13 +++--
 arch/um/os-Linux/skas/process.c  |   13 +++--
 arch/um/os-Linux/start_up.c  |7 ---
 5 files changed, 22 insertions(+), 16 deletions(-)

Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-06-12 11:33:37.0 
-0400
@@ -24,6 +24,7 @@
 #include "uml-config.h"
 #include "os.h"
 #include "um_malloc.h"
+#include "kern_constants.h"
 
 /* Set in main, unchanged thereafter */
 char *linux_prog;
@@ -232,7 +233,8 @@ void *__wrap_malloc(int size)
 
if(!CAN_KMALLOC())
return __real_malloc(size);
-   else if(size <= PAGE_SIZE) /* finding contiguos pages can be hard*/
+   else if(size <= UM_KERN_PAGE_SIZE)
+   /* finding contiguous pages can be hard*/
ret = um_kmalloc(size);
else ret = um_vmalloc(size);
 
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/mem.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/mem.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/mem.c 2007-06-12 11:34:37.0 
-0400
@@ -25,6 +25,7 @@
 #include "sysdep/ptrace.h"
 #include "sysdep/stub.h"
 #include "init.h"
+#include "kern_constants.h"
 
 extern unsigned long batch_syscall_stub, __syscall_stub_start;
 
@@ -149,8 +150,8 @@ long run_syscall_stub(struct mm_id * mm_
*stack = 0;
multi_op_count++;
 
-   if(!done && unsigned long) stack) & ~PAGE_MASK) <
-PAGE_SIZE - 10 * sizeof(long))){
+   if(!done && unsigned long) stack) & ~UM_KERN_PAGE_MASK) <
+UM_KERN_PAGE_SIZE - 10 * sizeof(long))){
*addr = stack;
return 0;
}
@@ -168,8 +169,8 @@ long syscall_stub_data(struct mm_id * mm
/* If *addr still is uninitialized, it *must* contain NULL.
 * Thus in this case do_syscall_stub correctly won't be called.
 */
-   ifunsigned long) *addr) & ~PAGE_MASK) >=
-  PAGE_SIZE - (10 + data_count) * sizeof(long)) {
+   ifunsigned long) *addr) & ~UM_KERN_PAGE_MASK) >=
+  UM_KERN_PAGE_SIZE - (10 + data_count) * sizeof(long)) {
ret = do_syscall_stub(mm_idp, addr);
/* in case of error, don't overwrite data on stack */
if(ret)
@@ -183,8 +184,8 @@ long syscall_stub_data(struct mm_id * mm
 
memcpy(stack + 1, data, data_count * sizeof(long));
 
-   *stub_addr = (void *)(((unsigned long)(stack + 1) & ~PAGE_MASK) +
- UML_CONFIG_STUB_DATA);
+   *stub_addr = (void *)(((unsigned long)(stack + 1) &
+  ~UM_KERN_PAGE_MASK) + UML_CONFIG_STUB_DATA);
 
return 0;
 }
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/process.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/process.c2007-06-06 
09:28:13.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/process.c 2007-06-12 
11:31:14.0 -0400
@@ -252,11 +252,12 @@ int start_userspace(unsigned long stub_s
unsigned long sp;
int pid, status, n, flags;
 
-   stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
+   stack = mmap(NULL, UM_KERN_PAGE_SIZE,
+PROT_READ | PROT_WRITE | PROT_EXEC,
 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(stack == MAP_FAILED)
panic("start_userspace : mmap failed, errno = %d", errno);
-   sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
+   sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
 
flags = CLONE_FILES | SIGCHLD;
if(proc_mm) flags |= CLONE_VM;
@@ -279,7 +280,7 @@ int start_userspace(unsigned long stub_s
panic("start_userspace : PTRACE_OLDSETOPTIONS failed, 
errno=%d\n",
  errno);
 
-

[PATCH 2/2] UML - kill x86_64 STACK_TOP_MAX

2007-06-12 Thread Jeff Dike
The x86_64 a.out.h got a definition of STACK_TOP_MAX, which interferes
with the UML version.  So, just undef it like STACK_TOP.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/a.out.h |1 +
 1 file changed, 1 insertion(+)

Index: linux-2.6.21-mm/include/asm-um/a.out.h
===
--- linux-2.6.21-mm.orig/include/asm-um/a.out.h 2007-06-06 09:28:48.0 
-0400
+++ linux-2.6.21-mm/include/asm-um/a.out.h  2007-06-06 15:51:02.0 
-0400
@@ -5,6 +5,7 @@
 #include "choose-mode.h"
 
 #undef STACK_TOP
+#undef STACK_TOP_MAX
 
 extern unsigned long stacksizelim;
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] UML compile fixes

2007-06-12 Thread Jeff Dike
These are a couple of UML build fixes for 2.6.22.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] UML: fix missing non-blocking I/O, now DEBUG_SHIRQ works

2007-06-12 Thread Jeff Dike
On Tue, Jun 12, 2007 at 08:44:37AM +0300, Eduard-Gabriel Munteanu wrote:
> Okay, I don't have an x86_64, sparc64 or something similar, as my 
> computer is an x86, so I can't contradict this. If everything is fine on 
> such arches, no fix is needed when nothing's broken... though I still 
> think it's kind of ugly (though it's somehow ingenious as a hack) :)

Yeah, I would agree with that.

> Do you want me to resubmit the patch without these changes? I'll be back 
> in a few hours (got to go now) and trim this out from the patch if 
> that's necessary.

I have it in my tree now, without that set of changes.  If you want to
make the change yourself, send me a new patch, and I'll use it.
Otherwise, I'll stick with what I have now.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] UML: fix missing non-blocking I/O, now DEBUG_SHIRQ works

2007-06-11 Thread Jeff Dike
On Tue, Jun 12, 2007 at 01:39:25AM +0300, Eduard-Gabriel Munteanu wrote:
> The cast isn't done right. Doing "fd = (long) dev_id;" doesn't help, 
> since you pass fd to mconsole_get_request() as is. And 
> mconsole_get_request() expects an integer:
> int mconsole_get_request(int fd, struct mc_request *req)

gcc will trim a long to an integer correctly.  You can pass a long to
an integer without casting.

> This will generate at least a warning on arches where sizeof(int) != 
> sizeof(long). 

No it won't.  UML builds without warnings here on x86_64.

> And by the way, AFAIK, GCC has the habit of breaking compatibility with 
> some userspace apps when a new GCC major version is released. And, 
> AFAIK, they're moving towards standards, so relying on GCC's 
> "guarantees" may backfire.

The GCC guarantee I'm talking about it LP64 - I'm highly confident
that's not changing any time soon.

> >>You're calling glibc functions
> >>with that fd as a parameter. On some arches, compiling will issue
> >>warnings or simply fail. 
> >
> >Which ones?
> >
> 
> An example is sparc64:
> quote from
> >>http://lxr.linux.no/source/include/asm-sparc64/types.h#L49

What warnings does this produce?  These are the same sizes as x86_64
(and every other 64-bit arch that Linux runs on, I bet), where this
code compiles without warning.

> Really, a kmalloc() isn't such a big deal, it only happens once and 
> we're not in interrupt context.

It's not the runtime cost - it's the extra code.

> One the other hand, ensuring safety and 
> portability on other arches is something that needs to be taken care
> of.

You haven't demonstrated any safety or portability problems yet.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] UML: fix missing non-blocking I/O, now DEBUG_SHIRQ works

2007-06-11 Thread Jeff Dike
On Mon, Jun 11, 2007 at 10:39:56PM +0300, Eduard-Gabriel Munteanu wrote:
> No offense, but this is an ugly hack. 

I'm not going to defend it too much, but the alternatives don't seem any
better to me.

> What if sizeof(int) !=  sizeof(long)?

Doesn't matter - the casting will preserve the value.  Of greater
concern is the relationship between sizeof(void *) and sizeof(long).
That's not guaranteed by the standard, but is by gcc.

> You're calling glibc functions
> with that fd as a parameter. On some arches, compiling will issue
> warnings or simply fail. 

Which ones?

> An alternative would be to use kmalloc instead of a global static 
> variable. Do you like this one more?

No, that trades the global variable for a new point of failure.

The main reason I like the current casting better than your global
(not by a lot) is that globals have to be audited for SMP safety.  So,
I don't want any globals which don't need to be.  This implies a
local, and to minimize the machinery associated with that (kmalloc, or
passing a pointer and synchronizing to avoid returning too soon), just
passing the descriptor in the pointer and accepting the casting needed
to get it through the compiler.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] UML: fix missing non-blocking I/O, now DEBUG_SHIRQ works

2007-06-11 Thread Jeff Dike
On Mon, Jun 11, 2007 at 01:01:57AM +0300, Eduard-Gabriel Munteanu wrote:
> DEBUG_SHIRQ generates spurious interrupts, triggering handlers such as 
> mconsole_interrupt() or line_interrupt(). They expect data to be 
> available to be read from their sockets/pipes, but in the case of 
> spurious interrupts, the host didn't actually send anything, so UML 
> hangs in read() and friends. Setting those fd's as O_NONBLOCK makes 
> DEBUG_SHIRQ-enabled UML kernels boot and run correctly. 

Nice.

I don't really like this section though.  The casting I have now isn't
pleasant, but I don't like adding a new global to get rid of it.

> diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
> index 542c9ef..02d132e 100644
> --- a/arch/um/drivers/mconsole_kern.c
> +++ b/arch/um/drivers/mconsole_kern.c
> @@ -74,12 +74,11 @@ static DECLARE_WORK(mconsole_work, mc_work_proc);
>  
>  static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
>  {
> - /* long to avoid size mismatch warnings from gcc */
> - long fd;
> + int fd;
>   struct mconsole_entry *new;
>   static struct mc_request req;   /* that's OK */
>  
> - fd = (long) dev_id;
> + fd = *((int *) dev_id);
>   while (mconsole_get_request(fd, &req)){
>   if(req.cmd->context == MCONSOLE_INTR)
>   (*req.cmd->handler)(&req);
> @@ -798,10 +797,10 @@ void mconsole_stack(struct mc_request *req)
>   */
>  static char *notify_socket = NULL;
>  
> +static int sock;
> +
>  static int mconsole_init(void)
>  {
> - /* long to avoid size mismatch warnings from gcc */
> - long sock;
>   int err;
>   char file[256];
>  
> @@ -818,7 +817,7 @@ static int mconsole_init(void)
>  
>   err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt,
>IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
> -  "mconsole", (void *)sock);
> +  "mconsole", &sock);
>   if (err){
>   printk("Failed to get IRQ for management console\n");
>   return(1);

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

2007-06-08 Thread Jeff Dike
On Thu, Jun 07, 2007 at 08:09:48AM +0300, Avi Kivity wrote:
> Some extra logic is needed on i386 with >= 4GB.  Current code will
> wraparound since gfn_t is 32-bits long, but casting it to 64-bits is not
> the answer since the processor will truncate it back to 32 bits (the
> return value is eventually used as a long in enter_rmode()).

Is it necessary to initialize TR in enter_rmode?  I can't see anything
that says it has any meaning in real mode.

And if not, would not the guest be responsible for finding room for the
TSS?

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Syslets - Fix cachemiss_thread return value

2007-06-08 Thread Jeff Dike
On Fri, Jun 08, 2007 at 09:26:01AM -0700, Zach Brown wrote:
> >I don't like it :-)
> 
> For a fundamental reason or because it happens to not work yet? :)

The latter - it fails the test that I posted.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Syslets - Fix cachemiss_thread return value

2007-06-08 Thread Jeff Dike
On Thu, Jun 07, 2007 at 04:27:33PM -0700, Zach Brown wrote:
> On Thu, May 31, 2007 at 02:19:23PM -0400, Jeff Dike wrote:
> > cachemiss_thread should explicitly return 0 or error instead of
> > task_ret_reg(current) (which is -ENOSYS anyway) because
> > async_thread_helper is careful to put the return value in eax anyway.
> 
> Here's the fix I came up with for this.  Untested (my test boxes are
> busy doing some aio+syslet perf runs :)).  What do you guys think?

I don't like it :-)

It's better though.  With the test below (a hacked up version of
aio-read.c), I still get -ENOSYS leaking out of sys_async_exec when it
tries an async setuid.

I haven't started looking into this yet.

Jeff

-- 
Work email - jdike at linux dot intel dot com


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "sys.h"

/*
 * Set up a syslet atom:
 */
static void
init_atom(struct syslet_uatom *atom, int nr,
  void *arg_ptr0, void *arg_ptr1, void *arg_ptr2,
  void *arg_ptr3, void *arg_ptr4, void *arg_ptr5,
  void *ret_ptr, unsigned long flags, struct syslet_uatom *next)
{
atom->nr = nr;
atom->arg_ptr[0] = (u64)(unsigned long)arg_ptr0;
atom->arg_ptr[1] = (u64)(unsigned long)arg_ptr1;
atom->arg_ptr[2] = (u64)(unsigned long)arg_ptr2;
atom->arg_ptr[3] = (u64)(unsigned long)arg_ptr3;
atom->arg_ptr[4] = (u64)(unsigned long)arg_ptr4;
atom->arg_ptr[5] = (u64)(unsigned long)arg_ptr5;
atom->ret_ptr = (u64)(unsigned long)ret_ptr;
atom->flags = flags;
atom->next = (u64)(unsigned long)next;
}

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

static int collect_status(void)
{
int n = 0;

sys_async_wait(1, async_head.user_ring_idx, &async_head);
while(completion_ring[async_head.user_ring_idx] != 0){
completion_ring[async_head.user_ring_idx++] = 0;
async_head.user_ring_idx %= ARRAY_SIZE(completion_ring);
n++;
}

return n;
}

int oneshot(struct syslet_uatom *atom, int syscall)
{
struct syslet_uatom *done;
int err = -1;

init_atom(atom, __NR_getuid, NULL, NULL, NULL, NULL, NULL, NULL,
  &err, SYSLET_ASYNC, NULL);
if(async_head.new_thread_stack == 0)
async_head.new_thread_stack = thread_stack_alloc();
done = sys_async_exec(atom, &async_head);
if(done == atom)
printf("setuid was synchronous\n");
else if(done == NULL){
collect_status();
}
else {
perror("async setuid");
exit(1);
}

return err;
}

int main(int argc, char *argv[])
{
struct syslet_uatom *atoms, *done;
struct stat stbuf;
char *file, *buf;
int fd, err, npages, i, len, async, sync;

if(argc < 2){
fprintf(stderr, "Usage : aio-read file\n");
exit(1);
}

file = argv[1];
fd = open(file, O_RDONLY);
if(fd < 0){
perror("open");
exit(1);
}

err = fstat(fd, &stbuf);
if(err < 0){
perror("stat");
exit(1);
}

buf = malloc(stbuf.st_size);
if(buf == NULL){
perror("malloc");
exit(1);
}

len = getpagesize();
npages = (stbuf.st_size + len - 1) / len;
atoms = malloc(npages * sizeof(struct syslet_uatom));
if(atoms == NULL){
perror("malloc atoms");
exit(1);
}

async_head_init();
async = 0;
sync = 0;
printf("head pid = %d, uid = %d\n", getpid(), getuid());
for(i = 0; i < npages; i++){
char *ptr = &buf[i * len];
init_atom(&atoms[i], __NR_sys_read, &fd, &ptr, &len,
  NULL, NULL, NULL, NULL, 0, NULL);
if(async_head.new_thread_stack == 0)
async_head.new_thread_stack = thread_stack_alloc();
done = sys_async_exec(&atoms[i], &async_head);
if(done == &atoms[i]){
sync++;
continue;
}
else if(done < 0)
perror("sys_async_exec");

async++;
printf("async = %d, pid = %ld\n", async, syscall(__NR_gettid));
if(async < ARRAY_SIZE(completion_ring))
continue;

async -= collect_status();
}

while(async)
async -= collect_status();

 

Re: [patch 7/8] fdmap v2 - implement sys_socket2

2007-06-08 Thread Jeff Dike
On Thu, Jun 07, 2007 at 01:10:23PM -0700, Linus Torvalds wrote:
> HOWEVER.
> 
> I think we could introduce a *single* new system call, which does 
> basically a "run the specified system call with the following flags".

As long as we are considering indirecting system calls, how about
reviving your proposal to run a system call in a different address
space:
http://www.ussg.iu.edu/hypermail/linux/kernel/0212.3/0502.html

UML could make good use of the ability to remotely manipulate address
spaces.  I never liked any of the proposed interfaces very much,
including mm_indirect.  However, if my tastebuds are defective, and
indirecting system calls is the way to solve a family of problems,
then we should look at fitting in mm_indirect.

> It has the disadvantage that it would need some per-architecture setup to 
> load the actual real arguments from memory: the system call would probably 
> look something like
> 
>   syscall_indirect(unsigned long flags, sigset_t *, 
>int syscall, unsigned long args[6]);

mm_indirect would need a file descriptor to the other address space,
which we would presumably get from a new get_mm() system call.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: signalfd API issues (was Re: [PATCH/RFC] signal races/bugs, losing TIF_SIGPENDING and other woes)

2007-06-07 Thread Jeff Dike
On Thu, Jun 07, 2007 at 01:29:23PM +1000, Benjamin Herrenschmidt wrote:
> But you use ptrace and don't steal signals with dequeue_signal() on a
> live other task, which is ok.

True.  However, with an SMP UML running a threaded app (which is also
threads on the host), if the thread on one CPU gets a signal which
will be nullified (SIGTRAP, SIG*ALRM, later SIGSEGV) and the other
thread continues running, does that count as stealing a signal from
another live task?

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

2007-06-06 Thread Jeff Dike
On Thu, Jun 07, 2007 at 10:13:42AM +0800, Li, Xin B wrote:
> >-static int rmode_tss_base(struct kvm* kvm)
> >+static unsigned long rmode_tss_base(struct kvm* kvm)
> 
> Should use gpa_t instead.

Right you are, I didn't notice that type.

Will fix.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: signalfd API issues (was Re: [PATCH/RFC] signal races/bugs, losing TIF_SIGPENDING and other woes)

2007-06-06 Thread Jeff Dike
On Thu, Jun 07, 2007 at 08:43:42AM +1000, Paul Mackerras wrote:
> What Ben was talking about was stealing a synchronous SEGV from a task
> without stopping it, and as Ben says that makes no sense.
> Intercepting a signal and stopping the task is reasonable, and that is
> what ptrace does, and I assume also UML.

It is, but I can also see UML stealing the SEGV from the child.  The
UML skas does this - a ptrace extension, PTRACE_FAULTINFO, is used to
extract page fault information from the child, and other pieces of the
patch are used to fix the fault without the child continuing until
it's fixed.  So, in this case, the child never sees the SEGV.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] KVM - Fix rmode_tss_base declaration

2007-06-06 Thread Jeff Dike
The long return value of rmode_tss_base is truncated by its declared
return type of int.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 drivers/kvm/vmx.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: kvm/drivers/kvm/vmx.c
===
--- kvm.orig/drivers/kvm/vmx.c
+++ kvm/drivers/kvm/vmx.c
@@ -884,7 +884,7 @@ static void enter_pmode(struct kvm_vcpu 
vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
 }
 
-static int rmode_tss_base(struct kvm* kvm)
+static unsigned long rmode_tss_base(struct kvm* kvm)
 {
gfn_t base_gfn = kvm->memslots[0].base_gfn + kvm->memslots[0].npages - 
3;
return base_gfn << PAGE_SHIFT;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] UML - Get declaration of simple_strtoul

2007-06-06 Thread Jeff Dike
Include linux/kernel.h wherever simple_strtoul is used.  This kills a
compile warning in stderr_console.c and potential ones in the other
files.

This also fixes a bunch of style violations in exitcode.c.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/line.c   |1 +
 arch/um/drivers/stderr_console.c |1 +
 arch/um/drivers/ubd_kern.c   |1 +
 arch/um/kernel/exitcode.c|   39 +--
 4 files changed, 20 insertions(+), 22 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/stderr_console.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/stderr_console.c   2007-05-28 
11:06:27.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/stderr_console.c2007-06-06 
09:31:06.0 -0400
@@ -1,3 +1,4 @@
+#include 
 #include 
 #include 
 
Index: linux-2.6.21-mm/arch/um/drivers/line.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/line.c 2007-06-06 09:28:13.0 
-0400
+++ linux-2.6.21-mm/arch/um/drivers/line.c  2007-06-06 11:13:03.0 
-0400
@@ -3,6 +3,7 @@
  * Licensed under the GPL
  */
 
+#include "linux/kernel.h"
 #include "linux/sched.h"
 #include "linux/slab.h"
 #include "linux/list.h"
Index: linux-2.6.21-mm/arch/um/drivers/ubd_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ubd_kern.c 2007-06-06 
09:28:47.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/ubd_kern.c  2007-06-06 11:13:42.0 
-0400
@@ -20,6 +20,7 @@
 #define MAJOR_NR UBD_MAJOR
 #define UBD_SHIFT 4
 
+#include "linux/kernel.h"
 #include "linux/module.h"
 #include "linux/blkdev.h"
 #include "linux/hdreg.h"
Index: linux-2.6.21-mm/arch/um/kernel/exitcode.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/exitcode.c  2007-05-28 
11:06:28.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/exitcode.c   2007-06-06 11:23:09.0 
-0400
@@ -1,8 +1,9 @@
-/* 
+/*
  * Copyright (C) 2002 Jeff Dike ([EMAIL PROTECTED])
  * Licensed under the GPL
  */
 
+#include "linux/kernel.h"
 #include "linux/init.h"
 #include "linux/ctype.h"
 #include "linux/proc_fs.h"
@@ -24,11 +25,14 @@ static int read_proc_exitcode(char *page
val = uml_exitcode;
len = sprintf(page, "%d\n", val);
len -= off;
-   if(len <= off+count) *eof = 1;
+   if(len <= off+count)
+   *eof = 1;
*start = page + off;
-   if(len > count) len = count;
-   if(len < 0) len = 0;
-   return(len);
+   if(len > count)
+   len = count;
+   if(len < 0)
+   len = 0;
+   return len;
 }
 
 static int write_proc_exitcode(struct file *file, const char __user *buffer,
@@ -38,12 +42,14 @@ static int write_proc_exitcode(struct fi
int tmp;
 
if(copy_from_user(buf, buffer, count))
-   return(-EFAULT);
+   return -EFAULT;
+
tmp = simple_strtol(buf, &end, 0);
if((*end != '\0') && !isspace(*end))
-   return(-EINVAL);
+   return -EINVAL;
+
uml_exitcode = tmp;
-   return(count);
+   return count;
 }
 
 static int make_proc_exitcode(void)
@@ -54,24 +60,13 @@ static int make_proc_exitcode(void)
if(ent == NULL){
printk(KERN_WARNING "make_proc_exitcode : Failed to register "
   "/proc/exitcode\n");
-   return(0);
+   return 0;
}
 
ent->read_proc = read_proc_exitcode;
ent->write_proc = write_proc_exitcode;
-   
-   return(0);
+
+   return 0;
 }
 
 __initcall(make_proc_exitcode);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] UML - Fix kernel stack size on x86_64

2007-06-06 Thread Jeff Dike
On Tue, Jun 05, 2007 at 06:20:24PM -0700, Andrew Morton wrote:
> If you do
> 
> - int "Kernel stack size order"
> + int
> 
> then this rule will no longer be offered to the user and `make oldconfig'
> (actually anythingconfig) will override whatever happens to be in .config
> for KERNEL_STACK_ORDER.

You're saying that making an option user-visible changes whether
*config overrides .config?  That's non-intuitive.

> I'm not sure if that's actually what you want, but if the current situation
> is that a random CONFIG_KERNEL_STACK_ORDER=0 left over in .config will
> break the kernel at runtime then I think something sterner than editing
> defconfig is needed?

That's a good point, but I think I do want it user-visible.  If
someone sees someething I suspect to be a stack overflow, I'd like to
be able to tell them to bump KERNEL_STACK_ORDER and see if the problem
goes away.

As for something sterner, it turns out that Kbuild provides some
support for this.  So, drop the previous patch in favor of this one:

Force KERNEL_STACK_ORDER to be at least 1 on UML/x86_64.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig |1 +
 1 file changed, 1 insertion(+)

Index: linux-2.6.21-mm/arch/um/Kconfig
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig2007-06-06 09:28:13.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig 2007-06-06 11:08:49.0 -0400
@@ -278,6 +278,7 @@ config HIGHMEM
 config KERNEL_STACK_ORDER
int "Kernel stack size order"
default 1 if 64BIT
+   range 1 10 if 64BIT
default 0 if !64BIT
help
This option determines the size of UML kernel stacks.  They will
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: signalfd API issues (was Re: [PATCH/RFC] signal races/bugs, losing TIF_SIGPENDING and other woes)

2007-06-06 Thread Jeff Dike
On Wed, Jun 06, 2007 at 12:50:04PM +1000, Benjamin Herrenschmidt wrote:
> Yeah, synchronous signals should probably never be delivered to another
> process, even via signalfd. There's no point delivering a SEGV to
> somebody else :-)

Sure there is.  UML does exactly that - intercepting child signals
(including SEGV) with wait.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] UML - Fix kernel stack size on x86_64

2007-06-05 Thread Jeff Dike
On Tue, Jun 05, 2007 at 05:00:01PM -0700, Andrew Morton wrote:
> On Tue, 5 Jun 2007 16:50:55 -0400
> Jeff Dike <[EMAIL PROTECTED]> wrote:
> 
> > [ This is 2.6.22 material ]
> > 
> > Having KERNEL_STACK_ORDER in defconfig overrides the value provided by
> > Kconfig, breaking UML/x86_64, which wants 2 page stacks.

> That means the Kconfig rules are wrong, surely?

I'm far from a Kconfig expert, but what I have is

config KERNEL_STACK_ORDER
int "Kernel stack size order"
default 1 if 64BIT
default 0 if !64BIT

which seems reasonably clear and simple...

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] UML - Improve host PTRACE_SYSEMU check

2007-06-05 Thread Jeff Dike
Make the PTRACE_SYSEMU checking more robust.  It will make sure that
system call numbers are reported correctly.  If there is a problem, it
will disable PTRACE_SYSEMU use and use PTRACE_SYSCALL instead.

This fixes a hang on boot on FC6 hosts with a broken PTRACE_SYSEMU.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/os-Linux/start_up.c |   24 
 1 file changed, 16 insertions(+), 8 deletions(-)

Index: linux-2.6.17/arch/um/os-Linux/start_up.c
===
--- linux-2.6.17.orig/arch/um/os-Linux/start_up.c   2007-06-05 
16:53:41.0 -0400
+++ linux-2.6.17/arch/um/os-Linux/start_up.c2007-06-05 16:54:21.0 
-0400
@@ -144,9 +144,7 @@ static int stop_ptraced_child(int pid, v
int exit_with = WEXITSTATUS(status);
if (exit_with == 2)
non_fatal("check_ptrace : child exited with status 2. "
- "Serious trouble happening! Try updating "
- "your host skas patch!\nDisabling SYSEMU "
- "support.");
+ "\nDisabling SYSEMU support.\n");
non_fatal("check_ptrace : child exited with exitcode %d, while "
  "expecting %d; status 0x%x\n", exit_with,
  exitcode, status);
@@ -209,6 +207,7 @@ __uml_setup("nosysemu", nosysemu_cmd_par
 static void __init check_sysemu(void)
 {
void *stack;
+   unsigned long regs[MAX_REG_NR];
int pid, n, status, count=0;
 
non_fatal("Checking syscall emulation patch for ptrace...");
@@ -225,11 +224,20 @@ static void __init check_sysemu(void)
fatal("check_sysemu : expected SIGTRAP, got status = %d",
  status);
 
-   n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET,
-  os_getpid());
-   if(n < 0)
-   fatal_perror("check_sysemu : failed to modify system call "
-"return");
+   if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
+   fatal_perror("check_sysemu : PTRACE_GETREGS failed");
+   if(PT_SYSCALL_NR(regs) != __NR_getpid){
+   non_fatal("check_sysemu got system call number %d, "
+ "expected %d...", PT_SYSCALL_NR(regs), __NR_getpid);
+   goto fail;
+   }
+
+   n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, os_getpid());
+   if(n < 0){
+   non_fatal("check_sysemu : failed to modify system call "
+ "return");
+   goto fail;
+   }
 
if (stop_ptraced_child(pid, stack, 0, 0) < 0)
goto fail_stopped;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] UML - Fix request->sector update

2007-06-05 Thread Jeff Dike
[ This is post-2.6.22 material - it fixes a bug, but not one that I
think has been seen in the wild, plus an earlier version of this fix
caused file corruption ]

It is theoretically possible for a request to finish and be freed
between writing it to the I/O thread and updating the sector count.
In this case, the update will dereference a freed pointer.

To avoid this, I delay the update until processing the next sg
segment, when the request pointer is known to be good.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/ubd_kern.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/ubd_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ubd_kern.c 2007-06-02 
12:13:50.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/ubd_kern.c  2007-06-02 22:23:41.0 
-0400
@@ -1082,7 +1082,7 @@ static void do_ubd_request(request_queue
 {
struct io_thread_req *io_req;
struct request *req;
-   int n;
+   int n, last_sectors;
 
while(1){
struct ubd *dev = q->queuedata;
@@ -1098,9 +1098,11 @@ static void do_ubd_request(request_queue
}
 
req = dev->request;
+   last_sectors = 0;
while(dev->start_sg < dev->end_sg){
struct scatterlist *sg = &dev->sg[dev->start_sg];
 
+   req->sector += last_sectors;
io_req = kmalloc(sizeof(struct io_thread_req),
 GFP_ATOMIC);
if(io_req == NULL){
@@ -1112,6 +1114,7 @@ static void do_ubd_request(request_queue
(unsigned long long) req->sector << 9,
sg->offset, sg->length, sg->page);
 
+   last_sectors = sg->length >> 9;
n = os_write_file(thread_fd, &io_req,
  sizeof(struct io_thread_req *));
if(n != sizeof(struct io_thread_req *)){
@@ -1123,7 +1126,6 @@ static void do_ubd_request(request_queue
return;
}
 
-   req->sector += sg->length >> 9;
dev->start_sg++;
}
dev->end_sg = 0;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] UML - Fix kernel stack size on x86_64

2007-06-05 Thread Jeff Dike
[ This is 2.6.22 material ]

Having KERNEL_STACK_ORDER in defconfig overrides the value provided by
Kconfig, breaking UML/x86_64, which wants 2 page stacks.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/defconfig |1 -
 1 file changed, 1 deletion(-)

Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-06-05 12:18:35.0 
-0400
+++ linux-2.6.21-mm/arch/um/defconfig   2007-06-05 12:19:12.0 -0400
@@ -86,7 +86,6 @@ CONFIG_MCONSOLE=y
 # CONFIG_MAGIC_SYSRQ is not set
 CONFIG_NEST_LEVEL=0
 # CONFIG_HIGHMEM is not set
-CONFIG_KERNEL_STACK_ORDER=0
 CONFIG_UML_REAL_TIME_CLOCK=y
 
 #
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Syslets, signals, and security

2007-06-04 Thread Jeff Dike
On Mon, Jun 04, 2007 at 10:45:42AM -0700, Zach Brown wrote:
> > Second, security.  What happens if a well-written server starts life
> > as root, does some (async) I/O, and setuids to a non-root uid?  There
> > will be a bunch of async threads still running as root, with the
> > result that async operations (and the main thread) will more than
> > occassionally regain root privs.

> One can imagine all sorts of crazy schemes which let us only shoot down
> waiting async threads which were cloned before state in the submitting
> task_struct was changed.  Maybe we could swallow increasing a counter in
> task_struct each time we change one of these sensitive fields (fsuid,
> etc), but I bet the maintenance burden of anything more fine grained
> than that would get pretty excessive.

How about splitting the credentials out of the task_struct and making
them sharable ala ->mm et al?  You change uid there and it changes for
everyone.  It will make fork slightly more expensive though.

> Yeah, and I'm blissfully ignorant of ptrace.  Imagine me skipping
> through a field of daisies with some ptrace wolves hiding in the bushes
> at the edge of the meadow.  La la la.

Heh, I'm somewhat less ignorant of ptrace, so I'll see if I can help
out there.

> Each execution context having its own task struct is intentional, very
> much so.  Remember, this started with the fibrils patch series which
> indeed shared a single task struct amongst a set of running stacks and
> thread infos, etc.  This approach is invasive because it changes the
> sleeping entity in the scheduler from a task struct to some new
> construct which has a many to one mapping to the task struct.  It
> touches vast amounts of code.  This approach is also risky because it
> introduces concurrent access to the task struct.  That's a pretty big
> auditing burden.

Yeah, I realize that, but have no idea how much code that requires
looking at.

> Have you looked at how the fibrils stuff did it?  It's a lot more work
> than it seems like it should be, on first glance.  You start to modify
> things and every few days you trip across another fundamental kernel
> construct which needs to be modified :/.
> 
>   http://lwn.net/Articles/219954/

Ah, I somehow missed this.  Since you seem to have explored that area
of the solution space already and found it wanting, I agree that it
makes sense to see if syslets can be made to work.

Jeff
-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Syslets, signals, and security

2007-06-04 Thread Jeff Dike
Syslets seem like a fundamentally good idea to me, but the current
implementation, using CLONE_THREAD threads, seems like a basic
problem.

First, there are signals.  If the app has an interval timer enabled,
every thread will inherit it and you will have 32 threads getting
alarms, which seems surprising and wasteful.  I can imagine other
signals (like SIGWINCH and  SIGHUP) which might be surprising to
receive multiple times in an obstensibly single-threaded process.

Second, security.  What happens if a well-written server starts life
as root, does some (async) I/O, and setuids to a non-root uid?  There
will be a bunch of async threads still running as root, with the
result that async operations (and the main thread) will more than
occassionally regain root privs.

You can fix this by going around to all the threads in the thread
group and changing their ->uid, but that seems somewhat kludgy.  You
could also fix this by killing off the async threads on a setuid, and
make the app recreate the async threads under its new uid.  However,
the current interface has no way to give the userspace stacks back to
the process, so this would force a memory leak on the process.

There's also ptrace, which (as I think Zach already mentioned) gets
along badly with syslets.

Offhand, it seems to me that the underlying problem is that the
threads all have their own task_structs and userspaces.

If only the main thread can receive signals and exit to userspace, the
signal surprises go away.

Similarly, if they all share a task structure, the setuid problem goes
away.

There are also warts in the current interface due to all of the
threads possibly being able to return to userspace:
they all need to be provided with userspace stacks
they need to be given an user IP to execute
there is a new system call for them to call when they land in
userspace.

Since the basic schedulable unit is currently a task_struct, and
syslets would prefer to have multiple schedulable units per
task_struct, this would imply some surgery on the task_struct and the
scheduler.  What I think we'd want is for the basic schedulable unit
to be not much more than a kernel stack and a register set.  A
(non-kernel-thread) task_struct would still be associated 1-1 with a
userspace, but could have multiple schedulable units, one of which is
allowed to exit to userspace.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] syslets demo - fix malloc failure check

2007-06-03 Thread Jeff Dike
Fix the stack malloc failure check.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 syslets/async-test-v5/sys.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux-2.6/syslets/async-test-v5/sys.h
===
--- linux-2.6.orig/syslets/async-test-v5/sys.h  2007-05-31 13:29:57.0 
-0400
+++ linux-2.6/syslets/async-test-v5/sys.h   2007-06-03 13:12:43.0 
-0400
@@ -108,9 +108,10 @@ static u64 completion_ring[MAX_PENDING];
 
 static unsigned long thread_stack_alloc()
 {
-   void *stack = malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE;
+   void *stack = malloc(THREAD_STACK_SIZE);
assert(stack != NULL);
 
+   stack += THREAD_STACK_SIZE;
pr("allocated stack: %p\n", stack);
 
return (unsigned long)stack;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Syslets - Fix cachemiss_thread return value

2007-05-31 Thread Jeff Dike
On Thu, May 31, 2007 at 03:07:16PM -0700, Zach Brown wrote:
> Can you explain what motivated you to send out this patch?
> 
> It used to return 0.  It was changed because, unlike the syslet
> syscalls, sys_io_submit() doesn't have a simple 0 value to indicate
> success.  The current implementation wants to return the number of iocbs
> that were processed, including the one which blocked, from the cachemiss
> thread.  So before calling into an operation it sets task_ret_ret() so
> that the cachemiss thread can return it if it takes over.
> task_ret_reg() is holding a return value that is being returned by the
> cachemiss thread on behalf of a sys_io_submit() which blocked.
> 
> When I made the change I didn't really audit its effect on the other
> paths.  I suppose it's time to do that, and you could help by telling me
> if you saw something bad happen :).

The bad thing was sys_async_exec returning -NOSYS every time a new
cachemiss thread was created.

Without this patch, you'll see sys_async_exec failures with either of
the demos I sent out.  Dunno about the existing ones, but I bet they do
the same.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Syslets - Fix cachemiss_thread return value

2007-05-31 Thread Jeff Dike
cachemiss_thread should explicitly return 0 or error instead of
task_ret_reg(current) (which is -ENOSYS anyway) because
async_thread_helper is careful to put the return value in eax anyway.

On x86_64, it looks like async_child_rip is similarly careful.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 kernel/async.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6/kernel/async.c
===
--- linux-2.6.orig/kernel/async.c   2007-05-29 20:11:11.0 -0400
+++ linux-2.6/kernel/async.c2007-05-31 14:12:49.0 -0400
@@ -575,7 +575,7 @@ static long cachemiss_thread(void *data)
struct task_struct *t = current;
struct async_head *ah = args->ah;
struct async_thread *at;
-   int ret;
+   int ret = 0;
 
at = &t->__at;
async_thread_init(t, at, ah);
@@ -607,7 +607,7 @@ static long cachemiss_thread(void *data)
complete(&ah->start_done);
 
async_cachemiss_loop(at, ah, t);
-   return task_ret_reg(t);
+   return ret;
 }
 
 /**
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] syslet demos - collecting timer expirations and child status

2007-05-31 Thread Jeff Dike
wait-sleep uses the async_exec mechanism to collect timer expirations
and child process wait status.  It randomly fires off a number of
sleeps and forks, waiting for them to finish, and firing off something
new to replace anything that finishes.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 Makefile |4 +
 wait-sleep.c |  123 +++
 2 files changed, 127 insertions(+)

Index: async-test-v5/Makefile
===
--- async-test-v5.orig/Makefile 2007-05-31 13:30:17.0 -0400
+++ async-test-v5/Makefile  2007-05-31 13:45:35.0 -0400
@@ -17,3 +17,7 @@ evserver_epoll_threadlet: evserver_epoll
 
 aio-read: aio-read.c syslet.h sys.h Makefile
gcc -O2 -g -Wall -o aio-read aio-read.c -fomit-frame-pointer
+
+wait-sleep: wait-sleep.c syslet.h sys.h Makefile
+   gcc -O2 -g -Wall -o wait-sleep wait-sleep.c -fomit-frame-pointer
+
Index: async-test-v5/wait-sleep.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ async-test-v5/wait-sleep.c  2007-05-31 13:32:39.0 -0400
@@ -0,0 +1,123 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "sys.h"
+
+/*
+ * Set up a syslet atom:
+ */
+static void
+init_atom(struct syslet_uatom *atom, int nr,
+ void *arg_ptr0, void *arg_ptr1, void *arg_ptr2,
+ void *arg_ptr3, void *arg_ptr4, void *arg_ptr5,
+ void *ret_ptr, unsigned long flags, struct syslet_uatom *next,
+ void *private)
+{
+   atom->nr = nr;
+   atom->arg_ptr[0] = (u64)(unsigned long)arg_ptr0;
+   atom->arg_ptr[1] = (u64)(unsigned long)arg_ptr1;
+   atom->arg_ptr[2] = (u64)(unsigned long)arg_ptr2;
+   atom->arg_ptr[3] = (u64)(unsigned long)arg_ptr3;
+   atom->arg_ptr[4] = (u64)(unsigned long)arg_ptr4;
+   atom->arg_ptr[5] = (u64)(unsigned long)arg_ptr5;
+   atom->ret_ptr = (u64)(unsigned long)ret_ptr;
+   atom->flags = flags;
+   atom->next = (u64)(unsigned long)next;
+   atom->private = (u64) (u32) private;
+}
+
+struct something {
+   enum { SLEEPER, RUNNER } type;
+   int time;
+   int status;
+};
+
+void start_something(struct syslet_uatom *atom, struct something *s)
+{
+   struct syslet_uatom *done;
+
+   s->time = rand() % 10 + 1;
+   if((rand() % 2) == 0){
+   struct timespec ts = { s->time, 0 }, *timeptr = &ts;
+   struct timespec *rem = NULL;
+
+   s->type = SLEEPER;
+   printf("0x%p : Sleeping for %d seconds\n", atom, s->time);
+   init_atom(atom, __NR_sys_nanosleep, &timeptr, &rem,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL, s);
+   }
+   else {
+   int pid = fork();
+   if(pid < 0){
+   perror("fork");
+   exit(1);
+   }
+   else if(pid > 0){
+   int *stat = &s->status, flags = 0;
+   s->type = RUNNER;
+   init_atom(atom, __NR_sys_waitpid, &pid, &stat,
+ &flags, NULL, NULL, NULL, NULL, 0, NULL, s);
+   }
+   else {
+   int status = rand() % 128;
+   sleep(s->time);
+   printf("0x%p : child %d exiting with status %d\n", atom,
+  getpid(), status);
+   exit(status);
+   }
+   }
+   if(async_head.new_thread_stack == 0)
+   async_head.new_thread_stack = thread_stack_alloc();
+   done = sys_async_exec(atom, &async_head);
+   if(done == atom){
+   printf("something finished too fast\n");
+   exit(1);
+   }
+}
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+int main(int argc, char *argv[])
+{
+   struct something something[ARRAY_SIZE(completion_ring)], *s;
+   struct syslet_uatom atoms[ARRAY_SIZE(completion_ring)], *done;
+   int err, i;
+
+   async_head_init();
+   for(i = 0; i < ARRAY_SIZE(atoms); i++){
+   start_something(&atoms[i], &something[i]);
+   }
+
+   while(1){
+   err = sys_async_wait(1, async_head.user_ring_idx, &async_head);
+   if(err){
+   perror("sys_async_wait");
+   exit(1);
+   }
+   while(completion_ring[async_head.user_ring_idx] != 0){
+   done = (struct syslet_uatom *) (u32)
+   completion_ring[async_head.user_ring_idx];
+   completion_ring[async_head.user_ring_idx++] = 0;
+   async_head.user_ring_idx %= ARR

[PATCH 2/3] syslet demos - AIO file reading

2007-05-31 Thread Jeff Dike
aio-read uses the async_exec mechanism to queue reads of pages of a
file.  As completions come in, new reads are queued until all pages in
the file have requests queued or finished.  When that has happened, it
just waits for the remaining completions to come in.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 Makefile   |6 ++-
 aio-read.c |  114 +
 2 files changed, 118 insertions(+), 2 deletions(-)

Index: async-test-v5/Makefile
===
--- async-test-v5.orig/Makefile 2007-05-31 13:28:42.0 -0400
+++ async-test-v5/Makefile  2007-05-31 13:46:14.0 -0400
@@ -1,5 +1,4 @@
-
-all: hello syslet-test threadlet-test evserver_threadlet evserver_epoll 
evserver_epoll_threadlet
+all: hello syslet-test threadlet-test evserver_threadlet evserver_epoll 
evserver_epoll_threadlet aio-read
@echo version: async
 
 clean:
@@ -15,3 +14,6 @@ evserver_threadlet: evserver_threadlet.c
gcc -O2 -g -Wall -o evserver_threadlet evserver_threadlet.c 
-fomit-frame-pointer
 evserver_epoll_threadlet: evserver_epoll_threadlet.c syslet.h sys.h 
threadlet.h Makefile
gcc -O2 -g -Wall -o evserver_epoll_threadlet evserver_epoll_threadlet.c 
-fomit-frame-pointer
+
+aio-read: aio-read.c syslet.h sys.h Makefile
+   gcc -O2 -g -Wall -o aio-read aio-read.c -fomit-frame-pointer
Index: async-test-v5/aio-read.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ async-test-v5/aio-read.c2007-05-31 13:31:00.0 -0400
@@ -0,0 +1,114 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "sys.h"
+
+/*
+ * Set up a syslet atom:
+ */
+static void
+init_atom(struct syslet_uatom *atom, int nr,
+ void *arg_ptr0, void *arg_ptr1, void *arg_ptr2,
+ void *arg_ptr3, void *arg_ptr4, void *arg_ptr5,
+ void *ret_ptr, unsigned long flags, struct syslet_uatom *next)
+{
+   atom->nr = nr;
+   atom->arg_ptr[0] = (u64)(unsigned long)arg_ptr0;
+   atom->arg_ptr[1] = (u64)(unsigned long)arg_ptr1;
+   atom->arg_ptr[2] = (u64)(unsigned long)arg_ptr2;
+   atom->arg_ptr[3] = (u64)(unsigned long)arg_ptr3;
+   atom->arg_ptr[4] = (u64)(unsigned long)arg_ptr4;
+   atom->arg_ptr[5] = (u64)(unsigned long)arg_ptr5;
+   atom->ret_ptr = (u64)(unsigned long)ret_ptr;
+   atom->flags = flags;
+   atom->next = (u64)(unsigned long)next;
+}
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+static int collect_status()
+{
+   int n = 0;
+
+   sys_async_wait(1, async_head.user_ring_idx, &async_head);
+   while(completion_ring[async_head.user_ring_idx] != 0){
+   completion_ring[async_head.user_ring_idx++] = 0;
+   async_head.user_ring_idx %= ARRAY_SIZE(completion_ring);
+   n++;
+   }
+
+   return n;
+}
+
+int main(int argc, char *argv[])
+{
+   struct syslet_uatom *atoms, *done;
+   struct stat stbuf;
+   char *file, *buf;
+   int fd, err, npages, i, len, async, sync;
+
+   if(argc < 2){
+   fprintf(stderr, "Usage : aio-read file\n");
+   exit(1);
+   }
+
+   file = argv[1];
+   fd = open(file, O_RDONLY);
+   if(fd < 0){
+   perror("open");
+   exit(1);
+   }
+
+   err = fstat(fd, &stbuf);
+   if(err < 0){
+   perror("stat");
+   exit(1);
+   }
+
+   buf = malloc(stbuf.st_size);
+   if(buf == NULL){
+   perror("malloc");
+   exit(1);
+   }
+
+   len = getpagesize();
+   npages = (stbuf.st_size + len - 1) / len;
+   atoms = malloc(npages * sizeof(struct syslet_uatom));
+   if(atoms == NULL){
+   perror("malloc atoms");
+   exit(1);
+   }
+
+   async_head_init();
+   async = 0;
+   sync = 0;
+   for(i = 0; i < npages; i++){
+   char *ptr = &buf[i * len];
+   init_atom(&atoms[i], __NR_sys_read, &fd, &ptr, &len,
+ NULL, NULL, NULL, NULL, 0, NULL);
+   if(async_head.new_thread_stack == 0)
+   async_head.new_thread_stack = thread_stack_alloc();
+   done = sys_async_exec(&atoms[i], &async_head);
+   if(done == &atoms[i]){
+   sync++;
+   continue;
+   }
+   else if(done < 0)
+   perror("sys_async_exec");
+
+   async++;
+   if(async < ARRAY_SIZE(completion_ring))
+   continue;
+
+   async -= collect_status();
+   }
+
+   while(async)
+   async -= collect_sta

[PATCH 1/3] syslet demos - add more includes

2007-05-31 Thread Jeff Dike
Add a bunch of includes to sys.h and syslet.h to kill off compilation warnings.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 sys.h|7 +++
 syslet.h |2 ++
 2 files changed, 9 insertions(+)

Index: async-test-v5/sys.h
===
--- async-test-v5.orig/sys.h2007-02-28 14:32:16.0 -0500
+++ async-test-v5/sys.h 2007-05-31 13:29:57.0 -0400
@@ -1,5 +1,12 @@
 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "syslet.h"
 
 #if DEBUG
 # define pr(x...) do { printf("%d: ", sys_gettid()); printf(x); 
fflush(stdout); } while (0)
Index: async-test-v5/syslet.h
===
--- async-test-v5.orig/syslet.h 2007-02-28 14:32:16.0 -0500
+++ async-test-v5/syslet.h  2007-05-30 12:32:44.0 -0400
@@ -10,6 +10,8 @@
  * User-space API/ABI definitions:
  */
 
+#include "common.h"
+
 #ifndef __user
 # define __user
 #endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Current utrace breaks UML

2007-05-25 Thread Jeff Dike
On Fri, May 25, 2007 at 06:35:13PM -0700, Roland McGrath wrote:
> Oops!  I overlooked the need to preserve the orig_eax value, though its
> necessity is obvious.  This makes me wonder about those previous
> reports that UML was working OK.

The one from me was on x86_64, where PTRACE_SYSEMU isn't an issue yet.

> I've fixed this in the latest utrace patch set.  I also wired up
> sysemu on x86_64.  This means 32-bit processes calling ptrace now
> support it for full compatibility with native i386, which the vanilla
> kernel does not.  It also means it works for 64-bit ptrace calls,
> whether operating on a 64-bit or a 32-bit target process.

Beautiful!

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] UML - Fix ubd_add error reporting

2007-05-23 Thread Jeff Dike
ubd_add returns 0 when there could actually be an error to report.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/ubd_kern.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.21-mm/arch/um/drivers/ubd_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/ubd_kern.c 2007-05-22 
11:55:48.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/ubd_kern.c  2007-05-22 12:03:48.0 
-0400
@@ -766,7 +766,7 @@ static int ubd_add(int n, char **error_o
make_ide_entries(ubd_gendisk[n]->disk_name);
 
 out:
-   return 0;
+   return err;
 
 out_cleanup:
blk_cleanup_queue(ubd_dev->queue);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] UML - Improve PTRACE_SYSEMU checking

2007-05-23 Thread Jeff Dike
Make the PTRACE_SYSEMU checking more robust.  It will make sure that
system call numbers are reported correctly.  If there is a problem, it
will disable PTRACE_SYSEMU use and use PTRACE_SYSCALL instead.

Thanks to Balaji G for helping reproduce this problem.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/os-Linux/start_up.c |   24 
 1 file changed, 16 insertions(+), 8 deletions(-)

Index: linux-2.6.21-mm/arch/um/os-Linux/start_up.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/start_up.c2007-05-16 
18:23:49.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/start_up.c 2007-05-22 17:47:57.0 
-0400
@@ -144,9 +144,7 @@ static int stop_ptraced_child(int pid, v
int exit_with = WEXITSTATUS(status);
if (exit_with == 2)
non_fatal("check_ptrace : child exited with status 2. "
- "Serious trouble happening! Try updating "
- "your host skas patch!\nDisabling SYSEMU "
- "support.");
+ "\nDisabling SYSEMU support.\n");
non_fatal("check_ptrace : child exited with exitcode %d, while "
  "expecting %d; status 0x%x\n", exit_with,
  exitcode, status);
@@ -209,6 +207,7 @@ __uml_setup("nosysemu", nosysemu_cmd_par
 static void __init check_sysemu(void)
 {
void *stack;
+   unsigned long regs[MAX_REG_NR];
int pid, n, status, count=0;
 
non_fatal("Checking syscall emulation patch for ptrace...");
@@ -225,11 +224,20 @@ static void __init check_sysemu(void)
fatal("check_sysemu : expected SIGTRAP, got status = %d",
  status);
 
-   n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET,
-  os_getpid());
-   if(n < 0)
-   fatal_perror("check_sysemu : failed to modify system call "
-"return");
+   if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
+   fatal_perror("check_sysemu : PTRACE_GETREGS failed");
+   if(PT_SYSCALL_NR(regs) != __NR_getpid){
+   non_fatal("check_sysemu got system call number %d, "
+ "expected %d...", PT_SYSCALL_NR(regs), __NR_getpid);
+   goto fail;
+   }
+
+   n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, os_getpid());
+   if(n < 0){
+   non_fatal("check_sysemu : failed to modify system call "
+ "return");
+   goto fail;
+   }
 
if (stop_ptraced_child(pid, stack, 0, 0) < 0)
goto fail_stopped;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] UML - Two bug fixes for 2.6.22

2007-05-23 Thread Jeff Dike
One of them is really more a workaround for a host bug than a UML bug
fix, but it does robustify the early boot checks a bit, and makes UML
boot on current FC6, so it's worth going in 2.6.22.

The other is a trivial error return fix in the ubd driver.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Deal with IRQs having different IRQF_DISABLED

2007-05-23 Thread Jeff Dike
handle_IRQ_event either enables IRQs or leaves them disabled for the
entire chain.  However, there is nothing in request_irq or setup_irq
which ensures that all IRQs in a chain will have the same
IRQF_DISABLED.

This seems like a bug to me.  Below are two possible fixes -
enable/disable IRQs for each action or refuse to register an IRQ if
there is a mismatched IRQF_DISABLED.

-- 
Work email - jdike at linux dot intel dot com

Refuse to register an IRQ if it has a mismatched IRQF_DISABLED with
what's already in the IRQ chain.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 kernel/irq/manage.c |8 
 1 file changed, 8 insertions(+)

Index: linux-2.6.21-mm/kernel/irq/manage.c
===
--- linux-2.6.21-mm.orig/kernel/irq/manage.c2007-05-23 09:01:16.0 
-0400
+++ linux-2.6.21-mm/kernel/irq/manage.c 2007-05-23 09:02:28.0 -0400
@@ -301,6 +301,14 @@ int setup_irq(unsigned int irq, struct i
goto mismatch;
}
 
+   /*
+* Handlers must agree on disabling IRQs since
+* handle_IRQ_event leaves IRQs either on or off for
+* the entire chain.
+*/
+   if ((old->flags ^ new->flags) & IRQF_DISABLED)
+   goto mismatch;
+
 #if defined(CONFIG_IRQ_PER_CPU)
/* All handlers must agree on per-cpuness */
if ((old->flags & IRQF_PERCPU) !=


Move the enabling/disabling of IRQs into the loop so that actions with
differing IRQF_DISABLED get the IRQ enabling that they asked for.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 kernel/irq/handle.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

Index: linux-2.6.21-mm/kernel/irq/handle.c
===
--- linux-2.6.21-mm.orig/kernel/irq/handle.c2007-05-16 18:21:18.0 
-0400
+++ linux-2.6.21-mm/kernel/irq/handle.c 2007-05-23 09:02:57.0 -0400
@@ -133,20 +133,21 @@ irqreturn_t handle_IRQ_event(unsigned in
 
handle_dynamic_tick(action);
 
-   if (!(action->flags & IRQF_DISABLED))
-   local_irq_enable_in_hardirq();
-
do {
+   if (!(action->flags & IRQF_DISABLED))
+   local_irq_enable_in_hardirq();
+
ret = action->handler(irq, action->dev_id);
if (ret == IRQ_HANDLED)
status |= action->flags;
retval |= ret;
action = action->next;
+
+   local_irq_disable();
} while (action);
 
if (status & IRQF_SAMPLE_RANDOM)
add_interrupt_randomness(irq);
-   local_irq_disable();
 
return retval;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Current utrace breaks UML

2007-05-23 Thread Jeff Dike
On Tue, May 22, 2007 at 11:46:11PM -0700, Roland McGrath wrote:
> (It also works for free on other arch's if you want to #define the
> constants there.)

(Forgot to mention...) sweet

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Current utrace breaks UML

2007-05-23 Thread Jeff Dike
On Tue, May 22, 2007 at 11:46:11PM -0700, Roland McGrath wrote:
> Do you have a test case for PTRACE_SYSEMU that does not work right?

UML, obviously.  Below is a smaller test.  orig_eax is wrong, so you
can't read the system call number from the process.

With kernel-2.6.20-1.2948, it prints out a bunch of -1's.  On FC5
kernels, you get more reasonable numbers.

Jeff

-- 
Work email - jdike at linux dot intel dot com


#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define PTRACE_SYSEMU 31
#define PAGE_SIZE 4096

static inline long stub_syscall0(long syscall)
{
long ret;

__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));

return ret;
}

static void child(void)
{
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
perror("traceme");
exit(1);
}

kill(getpid(), SIGUSR1);
stub_syscall0(__NR_getpid);
}

int main(void)
{
void *stack;
unsigned long sp, regs[FRAME_SIZE];
int pid, n, status;

stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(stack == MAP_FAILED){
perror("mmap");
exit(1);
}

sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
pid = fork();
if(pid < 0)
perror("fork");
else if(pid == 0){
child();
}
else {
while(1){
n = waitpid(pid, &status, WUNTRACED);
if(n < 0){
perror("waitpid");
exit(1);
}

n = ptrace(PTRACE_GETREGS, pid, 0, regs);
if(n < 0){
perror("PTRACE_GETREGS");
exit(1);
}

printf("Status 0x%x orig_eax 0x%x\n", status,
   regs[ORIG_EAX]);

if(ptrace(PTRACE_SYSEMU, pid, 0, 0)){
perror("PTRACE_SYSEMU");
exit(1);
}
}
}

return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Current utrace breaks UML

2007-05-22 Thread Jeff Dike
This chunk from linux-2.6-utrace.patch breaks PTRACE_SYSEMU, which UML
rather relies on.

@@ -514,9 +514,6 @@ syscall_trace_entry:
movl %esp, %eax
xorl %edx,%edx
call do_syscall_trace
-   cmpl $0, %eax
-   jne resume_userspace# ret != 0 -> running under 
PTRACE_SYSEMU,
-   # so must skip actual syscall
movl PT_ORIG_EAX(%esp), %eax
cmpl $(nr_syscalls), %eax
jnae syscall_call

If the point of this patch was to completely remove ptrace support,
with later patches adding it back, then that chunk should be added
back in utrace-ptrace-compat.patch.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: UML doesn't compile in 2.6.21

2007-05-21 Thread Jeff Dike
On Thu, May 17, 2007 at 12:49:38AM +0200, Robert Schwebel wrote:
> Jeff,
> 
> Any idea how this could happen? I'm trying to build 2.6.21 for
> ARCH=um, and the linker stage explodes here:
> 
>   CHK include/linux/compile.h
>   UPD include/linux/compile.h
>   CC  init/version.o
>   LD  init/built-in.o
>   LD  .tmp_vmlinux1
> lib/lib.a(bug.o): In function `find_bug':
> bug.c:(.text+0x171): undefined reference to `__start___bug_table'
> bug.c:(.text+0x177): undefined reference to `__stop___bug_table'
> bug.c:(.text+0x180): undefined reference to `__start___bug_table'
> bug.c:(.text+0x193): undefined reference to `__stop___bug_table'

No, I don't.  The bug_table symbols are rather unconditionally defined
in asm-generic/vmlinux.lds.h.  This can't be affected by any config
settings that I can see, let alone module support.  Further, the
config I always build has modules enabled, and I've never seen this.

Can you try starting over with an mrproper and see if you can
reproduce it?

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: signals logged / [RFC] log out-of-virtual-memory events

2007-05-20 Thread Jeff Dike
On Mon, May 21, 2007 at 12:24:22AM +0200, Andi Kleen wrote:
> > > But I think your list is far too long anyways.
> > 
> > So, which ones would you like to have removed then?
> 
> SIGFPE at least and the accounting signals are dubious too. SIGQUIT can
> be also relatively common.

And SIGSEGV and SIGBUS - UML catches these internally and handles them.

Jeff
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] fix uml-x86_64

2007-05-15 Thread Jeff Dike
On Tue, May 15, 2007 at 08:36:00PM +0100, Al Viro wrote:
> 
> __NR_syscall_max is done in x86_64 asm-offsets; do an equivalent in
> uml kern_constants.h
> 
> Signed-off-by: Al Viro <[EMAIL PROTECTED]>

ACK

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] spelling fixes: arch/um/

2007-05-12 Thread Jeff Dike
On Fri, May 11, 2007 at 08:43:47PM +0100, Simon Arlott wrote:
> Spelling fixes in arch/um/.

ACK

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/6] UML - Monitor stack usage

2007-05-10 Thread Jeff Dike
On Wed, May 09, 2007 at 09:07:38PM -0700, Andrew Morton wrote:
> but, but.  We already have CONFIG_DEBUG_STACK_USAGE?

Whoops, that's not exactly what I want, but it's close enough to let
me throw out some code.

Drop that and I'll send a fixed version.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/6] UML - IRQ stacks

2007-05-09 Thread Jeff Dike
[ Paolo - can you take a look at the race avoidance here?  I think
it's OK, and it holds up under stress, but I'd like a second set of
eyes on this. ]

Add a separate IRQ stack.  This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal
kernel stack and switching over once some preparation has been done.
The underlying mechanism, is of course, sigaltstack.

Another difference is that interrupts that happen in userspace are
handled on the normal kernel stack.  These cause a wait wakeup instead
of a signal delivery so there is no point in trying to switch stacks
for these.  There's no other stuff on the stack, so there is no extra
stack consumption.

This quirk makes it possible to have the entire interrupt run on a
separate stack - process preemption (and calls to schedule()) happens
on a normal kernel stack.  If we enable CONFIG_PREEMPT, this will need
to be rethought.

The IRQ stack for CPU 0 is declared in the same way as the initial
kernel stack.  IRQ stacks for other CPUs will be allocated
dynamically.

An extra field was added to the thread_info structure.  When the
active thread_info is copied to the IRQ stack, the real_thread field
points back to the original stack.  This makes it easy to tell where
to copy the thread_info struct back to when the interrupt is
finished.  It also serves as a marker of a nested interrupt.  It is
NULL for the first interrupt on the stack, and non-NULL for any nested
interrupts.

Care is taken to behave correctly if a second interrupt comes in when
the thread_info structure is being set up or taken down.  I could just
disable interrupts here, but I don't feel like giving up any of the
performance gained by not flipping signals on and off.

If an interrupt comes in during these critical periods, the
handler can't run because it has no idea what shape the stack is in.
So, it sets a bit for its signal in a global mask and returns.  The
outer handler will deal with this signal itself.

Atomicity is had with xchg.  A nested interrupt that needs to bail out
will xchg its signal mask into pending_mask and repeat in case yet
another interrupt hit at the same time, until the mask stabilizes.

The outermost interrupt will set up the thread_info and xchg a zero
into pending_mask when it is done.  At this point, nested interrupts
will look at ->real_thread and see that no setup needs to be done.
They can just continue normally.

Similar care needs to be taken when exiting the outer handler.  If
another interrupt comes in while it is copying the thread_info, it
will drop a bit into pending_mask.  The outer handler will check this
and if it is non-zero, will loop, set up the stack again, and handle
the interrupt.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/include/kern_util.h  |3 
 arch/um/kernel/dyn.lds.S |2 
 arch/um/kernel/init_task.c   |   16 +++--
 arch/um/kernel/irq.c |  111 +++
 arch/um/kernel/skas/process.c|4 +
 arch/um/kernel/uml.lds.S |2 
 arch/um/os-Linux/signal.c|   40 
 arch/um/os-Linux/sys-i386/signal.c   |8 --
 arch/um/os-Linux/sys-x86_64/signal.c |6 -
 include/asm-um/thread_info.h |2 
 10 files changed, 180 insertions(+), 14 deletions(-)

Index: linux-2.6.21-mm/arch/um/kernel/dyn.lds.S
===
--- linux-2.6.21-mm.orig/arch/um/kernel/dyn.lds.S   2007-05-09 
12:52:22.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/dyn.lds.S2007-05-09 12:52:59.0 
-0400
@@ -97,6 +97,8 @@ SECTIONS
   .data   : {
 . = ALIGN(KERNEL_STACK_SIZE);  /* init_task */
 *(.data.init_task)
+. = ALIGN(KERNEL_STACK_SIZE);
+*(.data.init_irqstack)
 *(.data .data.* .gnu.linkonce.d.*)
 EXTRA_RWDATA
 SORT(CONSTRUCTORS)
Index: linux-2.6.21-mm/arch/um/kernel/init_task.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/init_task.c 2007-05-09 
12:52:22.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/init_task.c  2007-05-09 12:52:59.0 
-0400
@@ -1,5 +1,5 @@
-/* 
- * Copyright (C) 2000 Jeff Dike ([EMAIL PROTECTED])
+/*
+ * Copyright (C) 2000 - 2007 Jeff Dike ([EMAIL PROTECTED],intel.linux}.com)
  * Licensed under the GPL
  */
 
@@ -33,14 +33,18 @@ EXPORT_SYMBOL(init_task);
 /*
  * Initial thread structure.
  *
- * We need to make sure that this is 16384-byte aligned due to the
+ * We need to make sure that this is aligned due to the
  * way process stacks are handled. This is done by having a special
  * "init_task" linker map entry..
  */
 
-union thread_union init_thread_union 
-__attribute__((__section__(".data.init_task"))) = 
-{ INIT_THREAD_INFO(init_task) };
+union thread_union init_thread_union
+   __attribute__((__section__(&qu

[PATCH 6/6] UML - Shrink kernel stacks

2007-05-09 Thread Jeff Dike
Make kernel stacks be 1 page on i386 and 2 pages on x86_64.  These
matche the host values.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig   |2 +-
 arch/um/defconfig |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6.21-mm/arch/um/Kconfig
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig2007-05-09 15:45:56.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig 2007-05-09 16:06:03.0 -0400
@@ -277,7 +277,8 @@ config HIGHMEM
 
 config KERNEL_STACK_ORDER
int "Kernel stack size order"
-   default 2
+   default 1 if 64BIT
+   default 0 if !64BIT
help
This option determines the size of UML kernel stacks.  They will
be 1 << order pages.  The default is OK unless you're running Valgrind
Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-05-09 15:45:56.0 
-0400
+++ linux-2.6.21-mm/arch/um/defconfig   2007-05-09 15:57:20.0 -0400
@@ -86,7 +86,7 @@ CONFIG_MCONSOLE=y
 # CONFIG_MAGIC_SYSRQ is not set
 CONFIG_NEST_LEVEL=0
 # CONFIG_HIGHMEM is not set
-CONFIG_KERNEL_STACK_ORDER=2
+CONFIG_KERNEL_STACK_ORDER=0
 CONFIG_UML_REAL_TIME_CLOCK=y
 
 #
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/6] UML - IRQ stacks and smaller kernel stacks

2007-05-09 Thread Jeff Dike
This is 2.6.22 material.

This set adds a separate IRQ stack and reduces kernel stack size.
There is also some preparatory cleanup and a new mechanism to keep
track of how close kernel stacks are to exhaustion.

Jeff
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/6] UML - Use UM_THREAD_SIZE in userspace code

2007-05-09 Thread Jeff Dike
Now that we have UM_THREAD_SIZE, we can replace the calculations in
user-space code (an earlier patch took care of the kernel side of the
house).

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/kernel/init_task.c  |3 +--
 arch/um/os-Linux/skas/process.c |7 +++
 2 files changed, 4 insertions(+), 6 deletions(-)

Index: linux-2.6.21-mm/arch/um/kernel/init_task.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/init_task.c 2007-05-07 
15:01:10.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/init_task.c  2007-05-08 10:06:07.0 
-0400
@@ -44,8 +44,7 @@ __attribute__((__section__(".data.init_t
 
 void unprotect_stack(unsigned long stack)
 {
-   os_protect_memory((void *) stack, (1 << CONFIG_KERNEL_STACK_ORDER) * 
PAGE_SIZE,
-  1, 1, 0);
+   os_protect_memory((void *) stack, THREAD_SIZE, 1, 1, 0);
 }
 
 /*
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/process.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/process.c2007-05-07 
15:35:31.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/process.c 2007-05-08 
10:06:07.0 -0400
@@ -490,8 +490,8 @@ void map_stub_pages(int fd, unsigned lon
 void new_thread(void *stack, jmp_buf *buf, void (*handler)(void))
 {
(*buf)[0].JB_IP = (unsigned long) handler;
-   (*buf)[0].JB_SP = (unsigned long) stack +
-   (PAGE_SIZE << UML_CONFIG_KERNEL_STACK_ORDER) - sizeof(void *);
+   (*buf)[0].JB_SP = (unsigned long) stack + UM_THREAD_SIZE -
+   sizeof(void *);
 }
 
 #define INIT_JMP_NEW_THREAD 0
@@ -533,8 +533,7 @@ int start_idle_thread(void *stack, jmp_b
case INIT_JMP_NEW_THREAD:
(*switch_buf)[0].JB_IP = (unsigned long) new_thread_handler;
(*switch_buf)[0].JB_SP = (unsigned long) stack +
-   (PAGE_SIZE << UML_CONFIG_KERNEL_STACK_ORDER) -
-   sizeof(void *);
+   UM_THREAD_SIZE - sizeof(void *);
break;
case INIT_JMP_CALLBACK:
(*cb_proc)(cb_arg);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/6] UML - Remove task_protections

2007-05-09 Thread Jeff Dike
Replaced task_protections with stack_protections since they do the same
thing, and task_protections was misnamed anyway.

This needs THREAD_SIZE, so that's imported via common-offsets.h

Also tidied up the code in the vicinity.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/include/common-offsets.h |2 ++
 arch/um/include/os.h |1 -
 arch/um/kernel/tt/exec_kern.c|2 +-
 arch/um/kernel/tt/process_kern.c |2 +-
 arch/um/kernel/um_arch.c |2 +-
 arch/um/os-Linux/util.c  |   23 +++
 6 files changed, 8 insertions(+), 24 deletions(-)

Index: linux-2.6.21-mm/arch/um/include/os.h
===
--- linux-2.6.21-mm.orig/arch/um/include/os.h   2007-05-07 15:01:10.0 
-0400
+++ linux-2.6.21-mm/arch/um/include/os.h2007-05-07 15:37:28.0 
-0400
@@ -272,7 +272,6 @@ extern void do_longjmp(void *p, int val)
 
 /* util.c */
 extern void stack_protections(unsigned long address);
-extern void task_protections(unsigned long address);
 extern int raw(int fd);
 extern void setup_machinename(char *machine_out);
 extern void setup_hostinfo(char *buf, int len);
Index: linux-2.6.21-mm/arch/um/kernel/tt/exec_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/tt/exec_kern.c  2007-05-07 
15:01:10.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/tt/exec_kern.c   2007-05-07 
15:37:29.0 -0400
@@ -57,7 +57,7 @@ void flush_thread_tt(void)
enable_timer();
free_page(stack);
protect_memory(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
-   task_protections((unsigned long) current_thread);
+   stack_protections((unsigned long) current_thread);
force_flush_all();
unblock_signals();
 }
Index: linux-2.6.21-mm/arch/um/kernel/tt/process_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/tt/process_kern.c   2007-05-07 
15:01:10.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/tt/process_kern.c2007-05-07 
15:37:29.0 -0400
@@ -209,7 +209,7 @@ void finish_fork_handler(int sig)
if(current->mm != current->parent->mm)
protect_memory(uml_reserved, high_physmem - uml_reserved, 1, 
   1, 0, 1);
-   task_protections((unsigned long) current_thread);
+   stack_protections((unsigned long) current_thread);
 
free_page(current->thread.temp_stack);
local_irq_disable();
Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c   2007-05-07 
15:02:04.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/um_arch.c2007-05-07 15:37:29.0 
-0400
@@ -459,7 +459,7 @@ int __init linux_main(int argc, char **a
 
uml_postsetup();
 
-   task_protections((unsigned long) &init_thread_info);
+   stack_protections((unsigned long) &init_thread_info);
os_flush_stdout();
 
return CHOOSE_MODE(start_uml_tt(), start_uml_skas());
Index: linux-2.6.21-mm/arch/um/os-Linux/util.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/util.c2007-05-07 
15:01:10.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/util.c 2007-05-07 15:37:29.0 
-0400
@@ -33,25 +33,8 @@
 
 void stack_protections(unsigned long address)
 {
-   int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
-
-   if(mprotect((void *) address, UM_KERN_PAGE_SIZE, prot) < 0)
-   panic("protecting stack failed, errno = %d", errno);
-}
-
-void task_protections(unsigned long address)
-{
-   unsigned long guard = address + UM_KERN_PAGE_SIZE;
-   unsigned long stack = guard + UM_KERN_PAGE_SIZE;
-   int prot = 0, pages;
-
-#ifdef notdef
-   if(mprotect((void *) stack, UM_KERN_PAGE_SIZE, prot) < 0)
-   panic("protecting guard page failed, errno = %d", errno);
-#endif
-   pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
-   prot = PROT_READ | PROT_WRITE | PROT_EXEC;
-   if(mprotect((void *) stack, pages * UM_KERN_PAGE_SIZE, prot) < 0)
+   if(mprotect((void *) address, UM_THREAD_SIZE,
+   PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
panic("protecting stack failed, errno = %d", errno);
 }
 
@@ -72,7 +55,7 @@ int raw(int fd)
 
/* XXX tcsetattr could have applied only some changes
 * (and cfmakeraw() is a set of changes) */
-   return(0);
+   return 0;
 }
 
 void setup_machinename(char *machine_out)
Index: linux-2.6.21-mm/arch/um/include/common-offsets.h
===
--- linux-2.6.21-mm.orig/arch/um/include/common-offsets.h   2007-05-07

[PATCH 3/6] UML - Tidy IRQ code

2007-05-09 Thread Jeff Dike
Some tidying of the irq code before introducing irq stacks.  Mostly
style fixes, but the timer handler calls the timer code directly
rather than going through the generic sig_handler_common_skas.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/kernel/init_task.c  |   11 ---
 arch/um/kernel/irq.c|4 ++--
 arch/um/os-Linux/signal.c   |   10 +++---
 arch/um/os-Linux/skas/process.c |6 --
 4 files changed, 13 insertions(+), 18 deletions(-)

Index: linux-2.6.21-mm/arch/um/kernel/init_task.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/init_task.c 2007-05-07 
14:52:28.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/init_task.c  2007-05-07 14:56:24.0 
-0400
@@ -46,14 +46,3 @@ void unprotect_stack(unsigned long stack
 {
os_protect_memory((void *) stack, THREAD_SIZE, 1, 1, 0);
 }
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
Index: linux-2.6.21-mm/arch/um/kernel/irq.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/irq.c   2007-05-07 14:52:28.0 
-0400
+++ linux-2.6.21-mm/arch/um/kernel/irq.c2007-05-07 14:56:24.0 
-0400
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000 Jeff Dike ([EMAIL PROTECTED])
  * Licensed under the GPL
  * Derived (i.e. mostly copied) from arch/i386/kernel/irq.c:
@@ -53,7 +53,7 @@ int show_interrupts(struct seq_file *p, 
if (i < NR_IRQS) {
spin_lock_irqsave(&irq_desc[i].lock, flags);
action = irq_desc[i].action;
-   if (!action) 
+   if (!action)
goto skip;
seq_printf(p, "%3d: ",i);
 #ifndef CONFIG_SMP
Index: linux-2.6.21-mm/arch/um/os-Linux/signal.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/signal.c  2007-05-07 
14:52:28.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/signal.c   2007-05-07 14:56:24.0 
-0400
@@ -61,15 +61,19 @@ void sig_handler(int sig, struct sigcont
 
 static void real_alarm_handler(int sig, struct sigcontext *sc)
 {
+   union uml_pt_regs regs;
+
if(sig == SIGALRM)
switch_timers(0);
 
-   CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
-sig, sc);
+   if(sc != NULL)
+   copy_sc(®s, sc);
+   regs.skas.is_user = 0;
+   unblock_signals();
+   timer_handler(sig, ®s);
 
if(sig == SIGALRM)
switch_timers(1);
-
 }
 
 void alarm_handler(int sig, struct sigcontext *sc)
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/process.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/process.c2007-05-07 
14:52:28.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/process.c 2007-05-07 
14:56:24.0 -0400
@@ -288,7 +288,8 @@ int start_userspace(unsigned long stub_s
 void userspace(union uml_pt_regs *regs)
 {
int err, status, op, pid = userspace_pid[0];
-   int local_using_sysemu; /*To prevent races if using_sysemu changes 
under us.*/
+   /* To prevent races if using_sysemu changes under us.*/
+   int local_using_sysemu;
 
while(1){
restore_registers(pid, regs);
@@ -296,7 +297,8 @@ void userspace(union uml_pt_regs *regs)
/* Now we set local_using_sysemu to be used for one loop */
local_using_sysemu = get_using_sysemu();
 
-   op = SELECT_PTRACE_OPERATION(local_using_sysemu, 
singlestepping(NULL));
+   op = SELECT_PTRACE_OPERATION(local_using_sysemu,
+singlestepping(NULL));
 
err = ptrace(op, pid, 0, 0);
if(err)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/6] UML - Monitor stack usage

2007-05-09 Thread Jeff Dike
In preparation for reducing stack size, add a machanism to see how
much of a kernel stack is used.  This fills a new stack with 0x6b on
allocation and sees where the lowest non-0x6b byte is on process
exit.  It keeps track of the lowest value and logs values as they get
lower.

The lowest values I've seen so far are ~1250 bytes remaining on i386
(with order 0 stacks) and ~2650 on x86_64 (order 1).

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig.debug|8 
 arch/um/defconfig|1 +
 arch/um/kernel/process.c |   35 +++
 include/asm-um/thread_info.h |   16 
 4 files changed, 60 insertions(+)

Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug  2007-05-09 14:34:39.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug   2007-05-09 14:36:10.0 
-0400
@@ -47,4 +47,12 @@ config GCOV
 If you're involved in UML kernel development and want to use gcov,
 say Y.  If you're unsure, say N.
 
+config STACK_USAGE
+   bool "Track kernel stack usage"
+   default N
+   help
+   Track the maximum kernel stack usage - this will look at each
+   kernel stack at process exit and log it if it's the deepest
+   stack seen so far.
+
 endmenu
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/process.c   2007-05-09 
14:34:39.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c2007-05-09 14:36:10.0 
-0400
@@ -427,3 +427,38 @@ unsigned long arch_align_stack(unsigned 
return sp & ~0xf;
 }
 #endif
+
+#ifdef CONFIG_STACK_USAGE
+
+static int lowest_to_date = THREAD_SIZE;
+
+void mark_stack(struct thread_info *stack)
+{
+   if(stack == NULL)
+   return;
+
+   memset(stack, 0x6b, THREAD_SIZE);
+}
+
+void check_stack_usage(struct thread_info *s)
+{
+   unsigned int *stack;
+   unsigned int *p, *end;
+   int left;
+
+   stack = (unsigned int *) (s + 1);
+   end = (unsigned int *) ((unsigned long) stack + THREAD_SIZE);
+   for(p = stack; p < end; p++){
+   if(*p != 0x6b6b6b6b){
+   left = (p - stack);
+   if(left < lowest_to_date){
+   printk("Greatest stack depth - %d bytes left\n",
+  left * sizeof(*p));
+   lowest_to_date = left;
+   }
+   return;
+   }
+   }
+}
+
+#endif
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h   2007-05-09 
14:34:39.0 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h2007-05-09 
14:36:10.0 -0400
@@ -52,6 +52,20 @@ static inline struct thread_info *curren
return ti;
 }
 
+#ifdef CONFIG_STACK_USAGE
+
+extern void mark_stack(struct thread_info *stack);
+extern void check_stack_usage(struct thread_info *stack);
+
+#define alloc_thread_info(tsk) \
+   ({ struct thread_info *stack = kmalloc(THREAD_SIZE, GFP_KERNEL); \
+  mark_stack(stack); \
+  stack; \
+})
+#define free_thread_info(ti) ({ check_stack_usage(ti) ; kfree(ti); })
+
+#else
+
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
@@ -59,6 +73,8 @@ static inline struct thread_info *curren
 
 #endif
 
+#endif
+
 #define PREEMPT_ACTIVE 0x1000
 
 #define TIF_SYSCALL_TRACE  0   /* syscall trace active */
Index: linux-2.6.21-mm/arch/um/defconfig
===
--- linux-2.6.21-mm.orig/arch/um/defconfig  2007-05-09 14:42:04.0 
-0400
+++ linux-2.6.21-mm/arch/um/defconfig   2007-05-09 14:42:59.0 -0400
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y
 # CONFIG_RCU_TORTURE_TEST is not set
 # CONFIG_GPROF is not set
 # CONFIG_GCOV is not set
+# CONFIG_STACK_USAGE is not set
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/5] Fix Linuxdoc comment

2007-05-07 Thread Jeff Dike
A linuxdoc comment had fallen out of date - it refers to an argument
which no longer exists.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 kernel/irq/handle.c |1 -
 1 file changed, 1 deletion(-)

Index: linux-2.6.21-mm/kernel/irq/handle.c
===
--- linux-2.6.21-mm.orig/kernel/irq/handle.c2007-05-02 11:21:45.0 
-0400
+++ linux-2.6.21-mm/kernel/irq/handle.c 2007-05-04 14:53:58.0 -0400
@@ -22,7 +22,6 @@
  * handle_bad_irq - handle spurious and unhandled irqs
  * @irq:   the interrupt number
  * @desc:  description of the interrupt
- * @regs:  pointer to a register structure
  *
  * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
  */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/5] UML - Mark a tt-only function

2007-05-07 Thread Jeff Dike
Mark another function as tt-mode only.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/os-Linux/process.c |2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6.21-mm/arch/um/os-Linux/process.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/process.c 2007-05-02 
11:33:18.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/process.c  2007-05-04 14:53:04.0 
-0400
@@ -239,6 +239,7 @@ out:
return ok;
 }
 
+#ifdef UML_CONFIG_MODE_TT
 void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
 {
int flags = 0, pages;
@@ -260,6 +261,7 @@ void init_new_thread_stack(void *sig_sta
  "errno = %d\n", errno);
}
 }
+#endif
 
 void init_new_thread_signals(void)
 {
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] UML - Turn build warnings into comments

2007-05-07 Thread Jeff Dike
From: Miklos Szeredi <[EMAIL PROTECTED]>

These haven't been fixed for ages.  Just make comments out of them.

arch/um/kernel/skas/process.c:181:2: warning: #warning Need to look up
+userspace_pid by cpu
arch/um/kernel/skas/process.c:187:2: warning: #warning Need to look up
+userspace_pid by cpu
arch/um/kernel/skas/process.c:194:2: warning: #warning need to loop over
+userspace_pids in kill_off_processes_skas

Signed-off-by: Miklos Szeredi <[EMAIL PROTECTED]>
Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/kernel/skas/process.c   |9 ++---
 arch/um/os-Linux/skas/mem.c |2 +-
 arch/um/os-Linux/skas/process.c |2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

Index: linux-2.6.21-mm/arch/um/kernel/skas/process.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/skas/process.c  2007-05-07 
14:58:53.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/skas/process.c   2007-05-07 
14:59:26.0 -0400
@@ -178,20 +178,23 @@ int start_uml_skas(void)
 
 int external_pid_skas(struct task_struct *task)
 {
-#warning Need to look up userspace_pid by cpu
+   /* FIXME: Need to look up userspace_pid by cpu */
return(userspace_pid[0]);
 }
 
 int thread_pid_skas(struct task_struct *task)
 {
-#warning Need to look up userspace_pid by cpu
+   /* FIXME: Need to look up userspace_pid by cpu */
return(userspace_pid[0]);
 }
 
 void kill_off_processes_skas(void)
 {
if(proc_mm)
-#warning need to loop over userspace_pids in kill_off_processes_skas
+   /*
+* FIXME: need to loop over userspace_pids in
+* kill_off_processes_skas
+*/
os_kill_ptraced_process(userspace_pid[0], 1);
else {
struct task_struct *p;
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/mem.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/mem.c2007-05-07 
10:36:17.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/mem.c 2007-05-07 14:59:26.0 
-0400
@@ -68,7 +68,7 @@ static inline long do_syscall_stub(struc
int err, pid = mm_idp->u.pid;
 
if(proc_mm)
-#warning Need to look up userspace_pid by cpu
+   /* FIXME: Need to look up userspace_pid by cpu */
pid = userspace_pid[0];
 
multi_count++;
Index: linux-2.6.21-mm/arch/um/os-Linux/skas/process.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/skas/process.c2007-05-07 
14:59:00.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/skas/process.c 2007-05-07 
14:59:26.0 -0400
@@ -586,7 +586,7 @@ void switch_mm_skas(struct mm_id *mm_idp
 {
int err;
 
-#warning need cpu pid in switch_mm_skas
+   /* FIXME: need cpu pid in switch_mm_skas */
if(proc_mm){
err = ptrace(PTRACE_SWITCH_MM, userspace_pid[0], 0,
 mm_idp->u.mm_fd);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/5] UML - Turn on SCSI support

2007-05-07 Thread Jeff Dike
From: Peter Zijlstra <[EMAIL PROTECTED]>

Enable (i)SCSI on UML, dunno why SCSI was deemed broken, it works like a
charm. 

Signed-off-by: Peter Zijlstra <[EMAIL PROTECTED]>
Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/Kconfig  |   16 --
 arch/um/Kconfig.scsi |   58 ---
 2 files changed, 1 insertion(+), 73 deletions(-)

Index: linux-2.6.21-mm/arch/um/Kconfig
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig2007-05-02 11:33:20.0 
-0400
+++ linux-2.6.21-mm/arch/um/Kconfig 2007-05-04 13:42:07.0 -0400
@@ -320,21 +320,7 @@ source "crypto/Kconfig"
 
 source "lib/Kconfig"
 
-menu "SCSI support"
-depends on BROKEN
-
-config SCSI
-   tristate "SCSI support"
-
-# This gives us free_dma, which scsi.c wants.
-config GENERIC_ISA_DMA
-   bool
-   depends on SCSI
-   default y
-
-source "arch/um/Kconfig.scsi"
-
-endmenu
+source "drivers/scsi/Kconfig"
 
 source "drivers/md/Kconfig"
 
Index: linux-2.6.21-mm/arch/um/Kconfig.scsi
===
--- linux-2.6.21-mm.orig/arch/um/Kconfig.scsi   2007-02-04 13:44:54.0 
-0500
+++ /dev/null   1970-01-01 00:00:00.0 +
@@ -1,58 +0,0 @@
-comment "SCSI support type (disk, tape, CD-ROM)"
-   depends on SCSI
-
-config BLK_DEV_SD
-   tristate "SCSI disk support"
-   depends on SCSI
-
-config SD_EXTRA_DEVS
-   int "Maximum number of SCSI disks that can be loaded as modules"
-   depends on BLK_DEV_SD
-   default "40"
-
-config CHR_DEV_ST
-   tristate "SCSI tape support"
-   depends on SCSI
-
-config BLK_DEV_SR
-   tristate "SCSI CD-ROM support"
-   depends on SCSI
-
-config BLK_DEV_SR_VENDOR
-   bool "Enable vendor-specific extensions (for SCSI CDROM)"
-   depends on BLK_DEV_SR
-
-config SR_EXTRA_DEVS
-   int "Maximum number of CDROM devices that can be loaded as modules"
-   depends on BLK_DEV_SR
-   default "2"
-
-config CHR_DEV_SG
-   tristate "SCSI generic support"
-   depends on SCSI
-
-comment "Some SCSI devices (e.g. CD jukebox) support multiple LUNs"
-   depends on SCSI
-
-#if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
-config SCSI_DEBUG_QUEUES
-   bool "Enable extra checks in new queueing code"
-   depends on SCSI
-
-#fi
-config SCSI_MULTI_LUN
-   bool "Probe all LUNs on each SCSI device"
-   depends on SCSI
-
-config SCSI_CONSTANTS
-   bool "Verbose SCSI error reporting (kernel size +=12K)"
-   depends on SCSI
-
-config SCSI_LOGGING
-   bool "SCSI logging facility"
-   depends on SCSI
-
-config SCSI_DEBUG
-   tristate "SCSI debugging host simulator (EXPERIMENTAL)"
-   depends on SCSI
-
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/5] UML - Fix build breakage

2007-05-07 Thread Jeff Dike
UML now needs required-features.h to build - an empty one suffices.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/required-features.h |9 +
 1 file changed, 9 insertions(+)

Index: linux-2.6.21-mm/include/asm-um/required-features.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.21-mm/include/asm-um/required-features.h  2007-05-07 
15:01:39.0 -0400
@@ -0,0 +1,9 @@
+#ifndef __UM_REQUIRED_FEATURES_H
+#define __UM_REQUIRED_FEATURES_H
+
+/*
+ * Nothing to see, just need something for the i386 and x86_64 asm
+ * headers to include.
+ */
+
+#endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/5] UML fixes plus a linuxdoc tweak

2007-05-07 Thread Jeff Dike
These five are 2.6.22 material.

In this batch, we have
a UML build fix
enabling SCSI on UML
ifdefing a function for later removal
build warnings turned into comments

In addition, a comment in kernel/irq/handle.c hadn't been updated to
reflect the alimination of the regs arguments in much of the IRQ path.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] UML - Make hostfs_setattr() support operations on unlinked open files.

2007-05-04 Thread Jeff Dike
From: Alberto Bertogli <[EMAIL PROTECTED]>

This patch allows hostfs_setattr() to work on unlinked open files by
calling set_attr() (the userspace part) with the inode's fd.

Without this, applications that depend on doing attribute changes to
unlinked open files will fail.

It works by using the fd versions instead of the path ones (for example
fchmod() instead of chmod(), fchown() instead of chown()) when an fd is
available.

Signed-off-by: Alberto Bertogli <[EMAIL PROTECTED]>
Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 fs/hostfs/hostfs.h  |4 -
 fs/hostfs/hostfs_kern.c |6 +-
 fs/hostfs/hostfs_user.c |  106 ++--
 3 files changed, 73 insertions(+), 43 deletions(-)

Index: linux-2.6.21-mm/fs/hostfs/hostfs.h
===
--- linux-2.6.21-mm.orig/fs/hostfs/hostfs.h 2007-02-04 13:44:54.0 
-0500
+++ linux-2.6.21-mm/fs/hostfs/hostfs.h  2007-05-01 15:10:39.0 -0400
@@ -55,7 +55,7 @@ extern int stat_file(const char *path, u
 int *mode_out, int *nlink_out, int *uid_out, int *gid_out,
 unsigned long long *size_out, struct timespec *atime_out,
 struct timespec *mtime_out, struct timespec *ctime_out,
-int *blksize_out, unsigned long long *blocks_out);
+int *blksize_out, unsigned long long *blocks_out, int fd);
 extern int access_file(char *path, int r, int w, int x);
 extern int open_file(char *path, int r, int w, int append);
 extern int file_type(const char *path, int *maj, int *min);
@@ -71,7 +71,7 @@ extern int lseek_file(int fd, long long 
 extern int fsync_file(int fd, int datasync);
 extern int file_create(char *name, int ur, int uw, int ux, int gr,
   int gw, int gx, int or, int ow, int ox);
-extern int set_attr(const char *file, struct hostfs_iattr *attrs);
+extern int set_attr(const char *file, struct hostfs_iattr *attrs, int fd);
 extern int make_symlink(const char *from, const char *to);
 extern int unlink_file(const char *file);
 extern int do_mkdir(const char *file, int mode);
Index: linux-2.6.21-mm/fs/hostfs/hostfs_kern.c
===
--- linux-2.6.21-mm.orig/fs/hostfs/hostfs_kern.c2007-04-27 
11:27:15.0 -0400
+++ linux-2.6.21-mm/fs/hostfs/hostfs_kern.c 2007-05-01 15:10:39.0 
-0400
@@ -147,7 +147,7 @@ static int read_name(struct inode *ino, 
 
err = stat_file(name, &i_ino, &i_mode, &i_nlink, &ino->i_uid,
&ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime,
-   &ino->i_ctime, &i_blksize, &i_blocks);
+   &ino->i_ctime, &i_blksize, &i_blocks, -1);
if(err)
return(err);
 
@@ -820,6 +820,8 @@ int hostfs_setattr(struct dentry *dentry
char *name;
int err;
 
+   int fd = HOSTFS_I(dentry->d_inode)->fd;
+
err = inode_change_ok(dentry->d_inode, attr);
if (err)
return err;
@@ -864,7 +866,7 @@ int hostfs_setattr(struct dentry *dentry
}
name = dentry_name(dentry, 0);
if(name == NULL) return(-ENOMEM);
-   err = set_attr(name, &attrs);
+   err = set_attr(name, &attrs, fd);
kfree(name);
if(err)
return(err);
Index: linux-2.6.21-mm/fs/hostfs/hostfs_user.c
===
--- linux-2.6.21-mm.orig/fs/hostfs/hostfs_user.c2007-04-26 
17:41:19.0 -0400
+++ linux-2.6.21-mm/fs/hostfs/hostfs_user.c 2007-05-01 15:10:39.0 
-0400
@@ -21,12 +21,16 @@ int stat_file(const char *path, unsigned
  int *nlink_out, int *uid_out, int *gid_out,
  unsigned long long *size_out, struct timespec *atime_out,
  struct timespec *mtime_out, struct timespec *ctime_out,
- int *blksize_out, unsigned long long *blocks_out)
+ int *blksize_out, unsigned long long *blocks_out, int fd)
 {
struct stat64 buf;
 
-   if(lstat64(path, &buf) < 0)
+   if(fd >= 0) {
+   if (fstat64(fd, &buf) < 0)
+   return(-errno);
+   } else if(lstat64(path, &buf) < 0) {
return(-errno);
+   }
 
if(inode_out != NULL) *inode_out = buf.st_ino;
if(mode_out != NULL) *mode_out = buf.st_mode;
@@ -202,58 +206,82 @@ int file_create(char *name, int ur, int 
return(fd);
 }
 
-int set_attr(const char *file, struct hostfs_iattr *attrs)
+int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
 {
-   struct utimbuf buf;
+   struct timeval times[2];
+   struct timespec atime_ts, mtime_ts;
int err, ma;
 
-   if(attrs->ia_valid & HOSTFS_ATTR_MODE){

[PATCH 2/3] UML - hostfs style fixes

2007-05-04 Thread Jeff Dike
hostfs needed some style goodness.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 fs/hostfs/hostfs.h  |   11 --
 fs/hostfs/hostfs_kern.c |  186 
 fs/hostfs/hostfs_user.c |  141 ++--
 3 files changed, 167 insertions(+), 171 deletions(-)

Index: linux-2.6.21-mm/fs/hostfs/hostfs.h
===
--- linux-2.6.21-mm.orig/fs/hostfs/hostfs.h 2007-05-01 15:10:39.0 
-0400
+++ linux-2.6.21-mm/fs/hostfs/hostfs.h  2007-05-01 15:22:05.0 -0400
@@ -87,14 +87,3 @@ extern int do_statfs(char *root, long *b
 long *spare_out);
 
 #endif
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
Index: linux-2.6.21-mm/fs/hostfs/hostfs_kern.c
===
--- linux-2.6.21-mm.orig/fs/hostfs/hostfs_kern.c2007-05-01 
15:20:49.0 -0400
+++ linux-2.6.21-mm/fs/hostfs/hostfs_kern.c 2007-05-01 15:26:02.0 
-0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000, 2001, 2002 Jeff Dike ([EMAIL PROTECTED])
+ * Copyright (C) 2000 - 2007 Jeff Dike ([EMAIL PROTECTED],linux.intel}.com)
  * Licensed under the GPL
  *
  * Ported the filesystem routines to 2.5.
@@ -31,14 +31,14 @@ struct hostfs_inode_info {
 
 static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
 {
-   return(list_entry(inode, struct hostfs_inode_info, vfs_inode));
+   return list_entry(inode, struct hostfs_inode_info, vfs_inode);
 }
 
 #define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode)
 
 int hostfs_d_delete(struct dentry *dentry)
 {
-   return(1);
+   return 1;
 }
 
 struct dentry_operations hostfs_dentry_ops = {
@@ -79,7 +79,7 @@ static int __init hostfs_args(char *opti
}
options = ptr;
}
-   return(0);
+   return 0;
 }
 
 __uml_setup("hostfs=", hostfs_args,
@@ -110,7 +110,8 @@ static char *dentry_name(struct dentry *
root = HOSTFS_I(parent->d_inode)->host_filename;
len += strlen(root);
name = kmalloc(len + extra + 1, GFP_KERNEL);
-   if(name == NULL) return(NULL);
+   if(name == NULL)
+   return NULL;
 
name[len] = '\0';
parent = dentry;
@@ -122,7 +123,7 @@ static char *dentry_name(struct dentry *
parent = parent->d_parent;
}
strncpy(name, root, strlen(root));
-   return(name);
+   return name;
 }
 
 static char *inode_name(struct inode *ino, int extra)
@@ -130,7 +131,7 @@ static char *inode_name(struct inode *in
struct dentry *dentry;
 
dentry = list_entry(ino->i_dentry.next, struct dentry, d_alias);
-   return(dentry_name(dentry, extra));
+   return dentry_name(dentry, extra);
 }
 
 static int read_name(struct inode *ino, char *name)
@@ -149,14 +150,14 @@ static int read_name(struct inode *ino, 
&ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime,
&ino->i_ctime, &i_blksize, &i_blocks, -1);
if(err)
-   return(err);
+   return err;
 
ino->i_ino = i_ino;
ino->i_mode = i_mode;
ino->i_nlink = i_nlink;
ino->i_size = i_size;
ino->i_blocks = i_blocks;
-   return(0);
+   return 0;
 }
 
 static char *follow_link(char *link)
@@ -181,11 +182,11 @@ static char *follow_link(char *link)
goto out_free;
 
if(*name == '/')
-   return(name);
+   return name;
 
end = strrchr(link, '/');
if(end == NULL)
-   return(name);
+   return name;
 
*(end + 1) = '\0';
len = strlen(link) + strlen(name) + 1;
@@ -199,12 +200,12 @@ static char *follow_link(char *link)
sprintf(resolved, "%s%s", link, name);
kfree(name);
kfree(link);
-   return(resolved);
+   return resolved;
 
  out_free:
kfree(name);
  out:
-   return(ERR_PTR(n));
+   return ERR_PTR(n);
 }
 
 static int read_inode(struct inode *ino)
@@ -234,7 +235,7 @@ static int read_inode(struct inode *ino)
err = read_name(ino, name);
kfree(name);
  out:
-   return(err);
+   return err;
 }
 
 int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
@@ -254,14 +255,15 @@ int hostfs_statfs(struct dentry *dentry,
&sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &

[PATCH 0/3] Small UML fixes

2007-05-04 Thread Jeff Dike
These are for 2.6.22.

We have a hostfs fix and hostfs style fixes in the first two.

The third fixes the load average on an idle system.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] UML - An idle system should have zero load average

2007-05-04 Thread Jeff Dike
The ever-vigilant users of linode.com noticed that an idle 2.6 UML has
a persistent load average of ~.4.

It turns out that because the UML timer handler processed softirqs
before actually delivering the tick, the tick was counted in the
context of the idle thread about half the time.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/kernel/time.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6.21-mm/arch/um/kernel/time.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/time.c  2007-05-04 12:40:52.0 
-0400
+++ linux-2.6.21-mm/arch/um/kernel/time.c   2007-05-04 13:13:39.0 
-0400
@@ -177,6 +177,8 @@ int do_settimeofday(struct timespec *tv)
 
 void timer_handler(int sig, union uml_pt_regs *regs)
 {
+   if(current_thread->cpu == 0)
+   timer_irq(regs);
local_irq_disable();
irq_enter();
update_process_times(CHOOSE_MODE(
@@ -184,6 +186,4 @@ void timer_handler(int sig, union uml_pt
 (regs)->skas.is_user));
irq_exit();
local_irq_enable();
-   if(current_thread->cpu == 0)
-   timer_irq(regs);
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Remove tas and split out cmpxchg

2007-05-04 Thread Jeff Dike
These are regenerated against your ff tree so as to not lose the
cmpxchg changes that you're carrying.

The first one removes tas() from all of the architectures - this comes
from the cmpxchg material, so it needs to come first.

The next two split out cmpxchg for i386 and x86_64.  The i386 change
fixes a missing include in atomic.h and the consequent UML build
warnings.  The x86_64 is done as tidying in the event that you think
it deserves to be split out.

Jeff
-- 
Work email - jdike at linux dot intel dot com
tas() has no users, so get rid of it.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-alpha/system.h |3 ---
 include/asm-arm/system.h   |2 --
 include/asm-arm26/system.h |2 --
 include/asm-h8300/system.h |1 -
 include/asm-i386/system.h  |2 --
 include/asm-m32r/system.h  |2 --
 include/asm-m68k/system.h  |1 -
 include/asm-m68knommu/system.h |1 -
 include/asm-mips/system.h  |1 -
 include/asm-powerpc/system.h   |2 --
 include/asm-ppc/system.h   |1 -
 include/asm-sh/system.h|   10 --
 include/asm-sh64/system.h  |2 --
 include/asm-sparc/system.h |1 -
 include/asm-sparc64/system.h   |1 -
 include/asm-v850/system.h  |1 -
 include/asm-x86_64/system.h|2 --
 include/asm-xtensa/system.h|2 --
 18 files changed, 37 deletions(-)

Index: linux-2.6/include/asm-alpha/system.h
===
--- linux-2.6.orig/include/asm-alpha/system.h   2007-03-27 17:07:34.0 
-0400
+++ linux-2.6/include/asm-alpha/system.h2007-05-03 17:17:16.0 
-0400
@@ -443,9 +443,6 @@ extern void __xchg_called_with_bad_point
  (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
   })
 
-#define tas(ptr) (xchg((ptr),1))
-
-
 /* 
  * Atomic compare and exchange.  Compare OLD with MEM, if identical,
  * store NEW in MEM.  Return the initial value in MEM.  Success is
Index: linux-2.6/include/asm-arm/system.h
===
--- linux-2.6.orig/include/asm-arm/system.h 2007-04-30 13:01:46.0 
-0400
+++ linux-2.6/include/asm-arm/system.h  2007-05-03 17:17:16.0 -0400
@@ -101,8 +101,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
 
Index: linux-2.6/include/asm-arm26/system.h
===
--- linux-2.6.orig/include/asm-arm26/system.h   2007-03-27 17:07:35.0 
-0400
+++ linux-2.6/include/asm-arm26/system.h2007-05-03 17:17:16.0 
-0400
@@ -52,8 +52,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 
 #define set_cr(x)  \
Index: linux-2.6/include/asm-h8300/system.h
===
--- linux-2.6.orig/include/asm-h8300/system.h   2007-03-27 17:07:35.0 
-0400
+++ linux-2.6/include/asm-h8300/system.h2007-05-03 17:17:16.0 
-0400
@@ -98,7 +98,6 @@ asmlinkage void resume(void);
 #endif
 
 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(x),(ptr),sizeof(*(ptr
-#define tas(ptr) (xchg((ptr),1))
 
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
Index: linux-2.6/include/asm-i386/system.h
===
--- linux-2.6.orig/include/asm-i386/system.h2007-05-03 17:14:47.0 
-0400
+++ linux-2.6/include/asm-i386/system.h 2007-05-03 17:17:16.0 -0400
@@ -197,8 +197,6 @@ static inline unsigned long get_limit(un
 
 #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(v),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((struct __xchg_dummy *)(x))
 
Index: linux-2.6/include/asm-m32r/system.h
===
--- linux-2.6.orig/include/asm-m32r/system.h2007-03-27 18:35:19.0 
-0400
+++ linux-2.6/include/asm-m32r/system.h 2007-05-03 17:17:16.0 -0400
@@ -122,8 +122,6 @@ static inline void local_irq_disable(voi
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr)   (xchg((ptr),1))
-
 #ifdef CONFIG_SMP
 extern void  __xchg_called_with_bad_pointer(void);
 #endif
Index: linux-2.6/include/asm-m6

Re: [PATCH 2/6] Create asm-i386/cmpxchg.h

2007-05-03 Thread Jeff Dike
On Wed, May 02, 2007 at 05:55:22PM +0200, Eric Dumazet wrote:
> My guess is ff means firstfloor :) 
> 
> https://www.x86-64.org/pipermail/discuss/2006-January/007467.html

Thanks!  That makes much more sense than my funky German keyboard theory...

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/6] UML - Network and pcap cleanup

2007-05-03 Thread Jeff Dike
On Thu, May 03, 2007 at 03:32:43PM +0200, Blaisorblade wrote:
> This is due to patch:
> "uml: drivers get release methods"
> this could be useful to check whether other such changes are needed, by 
> grepping for platform_device_unregister in exit paths, also for ubd driver.
> 
> That patch only fixed net_remove() and ubd_remove().

Yeah, good point - I'll have a look.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] UML - forgot asm-um/cmpxchg.h

2007-05-03 Thread Jeff Dike
On Wed, May 02, 2007 at 11:09:19PM -0700, Andrew Morton wrote:
> OK, I clumped all three patches into one as I think that's required for
> git-bisect friendliness.

OK - I separated the i386 and x86_64 bits to make it easy to drop the
x86_64 part.

Plus, I think it doesn't make any difference - the headers behave the
same as seen from the outside, except that UML needs the uml-cmpxchg
patch in order to build.  So, putting that first, then the other two
separately results in a patchset that builds at all stages, I believe.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/6] UML - free() wrapper should call libc free

2007-05-02 Thread Jeff Dike
On Wed, May 02, 2007 at 12:49:01PM +1000, Nick Piggin wrote:
> I want to get rid of PG_reserved eventually. Is it possible to use PG_arch_1
> for this?

Yup.

Andrew - Feel free to drop this or just sit on it until I send a
replacement.  Whichever is easier.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/6] Create asm-i386/cmpxchg.h

2007-05-02 Thread Jeff Dike
On Wed, May 02, 2007 at 11:37:48AM +0200, Andi Kleen wrote:
> Doesn't apply against the latest ff tree. Can you please regenerate,
> not losing whatever change caused it to reject?

What's the ff tree?  Is 'f' next to 'm' on your keyboard?

It depends on the tas() elimination patch, which I sent to LKML and
linux-arch yesterday, and which is attached.

Also attached is a standalone version of cmpxchg-i386 against
rc7-mm2.  no-tas applies on top of it.  Take your pick.

Jeff

-- 
Work email - jdike at linux dot intel dot com
tas() has no users, so get rid of it.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-alpha/system.h |3 ---
 include/asm-arm/system.h   |2 --
 include/asm-arm26/system.h |2 --
 include/asm-blackfin/system.h  |1 -
 include/asm-h8300/system.h |1 -
 include/asm-i386/system.h  |2 --
 include/asm-m32r/system.h  |2 --
 include/asm-m68k/system.h  |1 -
 include/asm-m68knommu/system.h |1 -
 include/asm-mips/system.h  |1 -
 include/asm-powerpc/system.h   |2 --
 include/asm-ppc/system.h   |1 -
 include/asm-sh/system.h|   10 --
 include/asm-sh64/system.h  |2 --
 include/asm-sparc/system.h |1 -
 include/asm-sparc64/system.h   |1 -
 include/asm-v850/system.h  |1 -
 include/asm-x86_64/system.h|2 --
 include/asm-xtensa/system.h|2 --
 19 files changed, 38 deletions(-)

Index: linux-2.6.21-mm/include/asm-alpha/system.h
===
--- linux-2.6.21-mm.orig/include/asm-alpha/system.h 2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-alpha/system.h  2007-04-30 17:54:32.0 
-0400
@@ -548,9 +548,6 @@ __xchg_u64_local(volatile long *m, unsig
sizeof(*(ptr))); \
   })
 
-#define tas(ptr) (xchg((ptr),1))
-
-
 /* 
  * Atomic compare and exchange.  Compare OLD with MEM, if identical,
  * store NEW in MEM.  Return the initial value in MEM.  Success is
Index: linux-2.6.21-mm/include/asm-arm/system.h
===
--- linux-2.6.21-mm.orig/include/asm-arm/system.h   2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-arm/system.h2007-04-30 17:54:33.0 
-0400
@@ -103,8 +103,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
 
Index: linux-2.6.21-mm/include/asm-arm26/system.h
===
--- linux-2.6.21-mm.orig/include/asm-arm26/system.h 2007-02-04 
13:44:54.0 -0500
+++ linux-2.6.21-mm/include/asm-arm26/system.h  2007-04-30 17:54:33.0 
-0400
@@ -52,8 +52,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 
 #define set_cr(x)  \
Index: linux-2.6.21-mm/include/asm-blackfin/system.h
===
--- linux-2.6.21-mm.orig/include/asm-blackfin/system.h  2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-blackfin/system.h   2007-04-30 
17:54:33.0 -0400
@@ -138,7 +138,6 @@ extern unsigned long irq_flags;
 #endif
 
 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(x),(ptr),sizeof(*(ptr
-#define tas(ptr) ((void)xchg((ptr),1))
 
 struct __xchg_dummy {
unsigned long a[100];
Index: linux-2.6.21-mm/include/asm-h8300/system.h
===
--- linux-2.6.21-mm.orig/include/asm-h8300/system.h 2007-02-04 
13:44:54.0 -0500
+++ linux-2.6.21-mm/include/asm-h8300/system.h  2007-04-30 17:54:34.0 
-0400
@@ -98,7 +98,6 @@ asmlinkage void resume(void);
 #endif
 
 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(x),(ptr),sizeof(*(ptr
-#define tas(ptr) (xchg((ptr),1))
 
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
Index: linux-2.6.21-mm/include/asm-i386/system.h
===
--- linux-2.6.21-mm.orig/include/asm-i386/system.h  2007-04-30 
12:38:17.0 -0400
+++ linux-2.6.21-mm/include/asm-i386/system.h   2007-04-30 18:04:43.0 
-0400
@@ -197,8 +197,6 @@ static inline unsigned long get_limit(un
 
 #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(v),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 struct __xchg_dummy { unsigned long a[100]; };
 #define __

[PATCH] UML - forgot asm-um/cmpxchg.h

2007-05-01 Thread Jeff Dike
The i386 and x86_64 cmpxchg patches require an asm-um/cmpxchg.h for
the UML build.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-um/cmpxchg.h |6 ++
 1 file changed, 6 insertions(+)

Index: linux-2.6.21-mm/include/asm-um/cmpxchg.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.21-mm/include/asm-um/cmpxchg.h2007-05-01 15:31:09.0 
-0400
@@ -0,0 +1,6 @@
+#ifndef __UM_CMPXCHG_H
+#define __UM_CMPXCHG_H
+
+#include "asm/arch/cmpxchg.h"
+
+#endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/6] Create asm-i386/cmpxchg.h

2007-05-01 Thread Jeff Dike
Rearrange the i386 cmpxchg code to allow atomic.h to get it without
needing to include system.h.  This kills warnings in the UML build
from atomic.h about implicit declarations of cmpxchg symbols.  The
i386 build presumably isn't seeing this because a separate inclusion
of system.h is covering it over.

The cmpxchg stuff is moved to asm-i386/cmpxchg.h, with an include left
in system.h for the benefit of generic code which expects cmpxchg
there.

Meanwhile, atomic.h includes cmpxchg.h.

This causes no noticable damage to the i386 build.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-i386/atomic.h  |1 
 include/asm-i386/cmpxchg.h |  293 +
 include/asm-i386/system.h  |  289 
 3 files changed, 295 insertions(+), 288 deletions(-)

Index: linux-2.6.21-mm/include/asm-i386/atomic.h
===
--- linux-2.6.21-mm.orig/include/asm-i386/atomic.h  2007-04-30 
18:04:43.0 -0400
+++ linux-2.6.21-mm/include/asm-i386/atomic.h   2007-05-01 12:41:52.0 
-0400
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 
 /*
  * Atomic operations that C can't guarantee us.  Useful for
Index: linux-2.6.21-mm/include/asm-i386/cmpxchg.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.21-mm/include/asm-i386/cmpxchg.h  2007-05-01 12:42:08.0 
-0400
@@ -0,0 +1,293 @@
+#ifndef __ASM_CMPXCHG_H
+#define __ASM_CMPXCHG_H
+
+#include  /* for LOCK_PREFIX */
+
+#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(v),(ptr),sizeof(*(ptr
+
+struct __xchg_dummy { unsigned long a[100]; };
+#define __xg(x) ((struct __xchg_dummy *)(x))
+
+
+#ifdef CONFIG_X86_CMPXCHG64
+
+/*
+ * The semantics of XCHGCMP8B are a bit strange, this is why
+ * there is a loop and the loading of %%eax and %%edx has to
+ * be inside. This inlines well in most cases, the cached
+ * cost is around ~38 cycles. (in the future we might want
+ * to do an SIMD/3DNOW!/MMX/FPU 64-bit store here, but that
+ * might have an implicit FPU-save as a cost, so it's not
+ * clear which path to go.)
+ *
+ * cmpxchg8b must be used with the lock prefix here to allow
+ * the instruction to be executed atomically, see page 3-102
+ * of the instruction set reference 24319102.pdf. We need
+ * the reader side to see the coherent 64bit value.
+ */
+static inline void __set_64bit (unsigned long long * ptr,
+   unsigned int low, unsigned int high)
+{
+   __asm__ __volatile__ (
+   "\n1:\t"
+   "movl (%0), %%eax\n\t"
+   "movl 4(%0), %%edx\n\t"
+   "lock cmpxchg8b (%0)\n\t"
+   "jnz 1b"
+   : /* no outputs */
+   :   "D"(ptr),
+   "b"(low),
+   "c"(high)
+   :   "ax","dx","memory");
+}
+
+static inline void __set_64bit_constant (unsigned long long *ptr,
+unsigned long long value)
+{
+   __set_64bit(ptr,(unsigned int)(value), (unsigned int)((value)>>32ULL));
+}
+#define ll_low(x)  *(((unsigned int*)&(x))+0)
+#define ll_high(x) *(((unsigned int*)&(x))+1)
+
+static inline void __set_64bit_var (unsigned long long *ptr,
+unsigned long long value)
+{
+   __set_64bit(ptr,ll_low(value), ll_high(value));
+}
+
+#define set_64bit(ptr,value) \
+(__builtin_constant_p(value) ? \
+ __set_64bit_constant(ptr, value) : \
+ __set_64bit_var(ptr, value) )
+
+#define _set_64bit(ptr,value) \
+(__builtin_constant_p(value) ? \
+ __set_64bit(ptr, (unsigned int)(value), (unsigned int)((value)>>32ULL) ) : \
+ __set_64bit(ptr, ll_low(value), ll_high(value)) )
+
+#endif
+
+/*
+ * Note: no "lock" prefix even on SMP: xchg always implies lock anyway
+ * Note 2: xchg has side effect, so that attribute volatile is necessary,
+ *   but generally the primitive is invalid, *ptr is output argument. --ANK
+ */
+static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int 
size)
+{
+   switch (size) {
+   case 1:
+   __asm__ __volatile__("xchgb %b0,%1"
+   :"=q" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   case 2:
+   __asm__ __volatile__("xchgw %w0,%1"
+   :"=r" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   case 4:

[PATCH /6] UML - pcap devices should get MACs from command line

2007-05-01 Thread Jeff Dike
Allow a pcap device to be assigned a MAC on the command line.  They
don't really need one, but it is handy to be able to do when your
distro assigns a new ethernet device whenever it sees a new MAC.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/pcap_kern.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.21-mm/arch/um/drivers/pcap_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/pcap_kern.c2007-04-27 
16:15:41.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/pcap_kern.c 2007-04-27 16:15:57.0 
-0400
@@ -70,7 +70,7 @@ int pcap_setup(char *str, char **mac_out
  .filter   = NULL });
 
remain = split_if_spec(str, &host_if, &init->filter,
-  &options[0], &options[1], NULL);
+  &options[0], &options[1], mac_out, NULL);
if(remain != NULL){
printk(KERN_ERR "pcap_setup - Extra garbage on "
   "specification : '%s'\n", remain);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/6] Create asm-x86_64/cmpxchg.h

2007-05-01 Thread Jeff Dike
This is the x86_64 movement of cmpxchg into its own header.  atomic.h
already included system.h, so this is changed to include cmpxchg.h.

This is purely cleanup - it's not fixing any warnings - so if the
x86_64 system.h isn't considered as cleanup-worthy as i386, then this
can be dropped.

It causes no noticable damage to the x86_64 build.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-x86_64/atomic.h  |2 
 include/asm-x86_64/cmpxchg.h |  134 +++
 include/asm-x86_64/system.h  |  130 -
 3 files changed, 136 insertions(+), 130 deletions(-)

Index: linux-2.6.21-mm/include/asm-x86_64/atomic.h
===
--- linux-2.6.21-mm.orig/include/asm-x86_64/atomic.h2007-04-30 
18:04:43.0 -0400
+++ linux-2.6.21-mm/include/asm-x86_64/atomic.h 2007-05-01 12:42:34.0 
-0400
@@ -2,7 +2,7 @@
 #define __ARCH_X86_64_ATOMIC__
 
 #include 
-#include 
+#include 
 
 /* atomic_t should be 32 bit signed type */
 
Index: linux-2.6.21-mm/include/asm-x86_64/cmpxchg.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.21-mm/include/asm-x86_64/cmpxchg.h2007-05-01 
12:43:48.0 -0400
@@ -0,0 +1,134 @@
+#ifndef __ASM_CMPXCHG_H
+#define __ASM_CMPXCHG_H
+
+#include  /* Provides LOCK_PREFIX */
+
+#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(v),(ptr),sizeof(*(ptr
+
+#define __xg(x) ((volatile long *)(x))
+
+static inline void set_64bit(volatile unsigned long *ptr, unsigned long val)
+{
+   *ptr = val;
+}
+
+#define _set_64bit set_64bit
+
+/*
+ * Note: no "lock" prefix even on SMP: xchg always implies lock anyway
+ * Note 2: xchg has side effect, so that attribute volatile is necessary,
+ *   but generally the primitive is invalid, *ptr is output argument. --ANK
+ */
+static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int 
size)
+{
+   switch (size) {
+   case 1:
+   __asm__ __volatile__("xchgb %b0,%1"
+   :"=q" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   case 2:
+   __asm__ __volatile__("xchgw %w0,%1"
+   :"=r" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   case 4:
+   __asm__ __volatile__("xchgl %k0,%1"
+   :"=r" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   case 8:
+   __asm__ __volatile__("xchgq %0,%1"
+   :"=r" (x)
+   :"m" (*__xg(ptr)), "0" (x)
+   :"memory");
+   break;
+   }
+   return x;
+}
+
+/*
+ * Atomic compare and exchange.  Compare OLD with MEM, if identical,
+ * store NEW in MEM.  Return the initial value in MEM.  Success is
+ * indicated by comparing RETURN with OLD.
+ */
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
+ unsigned long new, int size)
+{
+   unsigned long prev;
+   switch (size) {
+   case 1:
+   __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
+: "=a"(prev)
+: "q"(new), "m"(*__xg(ptr)), "0"(old)
+: "memory");
+   return prev;
+   case 2:
+   __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
+: "=a"(prev)
+: "r"(new), "m"(*__xg(ptr)), "0"(old)
+: "memory");
+   return prev;
+   case 4:
+   __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2"
+: "=a"(prev)
+: "r"(new), "m"(*__xg(ptr)), "0"(old)
+: "memory");
+   return prev;
+   case 8:
+   __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2"
+: "=a"(prev)
+  

[PATCH 4/6] UML - free() wrapper should call libc free

2007-05-01 Thread Jeff Dike
The libc free wrapper wasn't correctly detecting buffers obtained with
malloc().  This is now done by seeing if the page was reserved.  This is
the case for memory which is left aside for libc and isn't given to
the page allocator.  If we free a pointer in a reserved page, it is
given to free() rather than kfree().

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/include/user.h   |1 +
 arch/um/kernel/um_arch.c |7 +++
 arch/um/os-Linux/main.c  |6 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

Index: linux-2.6.21-mm/arch/um/include/user.h
===
--- linux-2.6.21-mm.orig/arch/um/include/user.h 2007-04-26 17:33:01.0 
-0400
+++ linux-2.6.21-mm/arch/um/include/user.h  2007-04-27 14:21:35.0 
-0400
@@ -27,5 +27,6 @@ extern int in_aton(char *str);
 extern int open_gdb_chan(void);
 extern size_t strlcpy(char *, const char *, size_t);
 extern size_t strlcat(char *, const char *, size_t);
+extern int reserved_address(void *addr);
 
 #endif
Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
===
--- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c   2007-04-26 
17:41:21.0 -0400
+++ linux-2.6.21-mm/arch/um/kernel/um_arch.c2007-04-27 14:30:36.0 
-0400
@@ -500,6 +500,13 @@ void __init check_bugs(void)
os_check_bugs();
 }
 
+int reserved_address(void *addr)
+{
+   struct page *page = virt_to_page(addr);
+
+   return(PageReserved(page));
+}
+
 void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
 {
 }
Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
===
--- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c2007-04-26 
17:41:10.0 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-04-27 14:30:31.0 
-0400
@@ -266,6 +266,8 @@ void __wrap_free(void *ptr)
/* We need to know how the allocation happened, so it can be correctly
 * freed.  This is done by seeing what region of memory the pointer is
 * in -
+*  in a reserved page - free, assume the pointer was
+*  acquired with malloc, since it couldn't have been kmalloced.
 *  physical memory - kmalloc/kfree
 *  kernel virtual memory - vmalloc/vfree
 *  anywhere else - malloc/free
@@ -281,7 +283,9 @@ void __wrap_free(void *ptr)
 * there is a possibility for memory leaks.
 */
 
-   if((addr >= uml_physmem) && (addr < high_physmem)){
+   if(kmalloc_ok && reserved_address(ptr))
+   __real_free(ptr);
+   else if((addr >= uml_physmem) && (addr < high_physmem)){
if(CAN_KMALLOC())
kfree(ptr);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/6] UML - Network and pcap cleanup

2007-05-01 Thread Jeff Dike
[ Paolo - could you eyeball the globally valid MAC piece of this and
see if you think it's OK? ]

Some network device cleanup.

When setup_etheraddr found a globally valid MAC being assigned to an
interface, it went ahead and used it rather than assigning a random
MAC like the other cases do.  This isn't really an error like the
others, but it seems consistent to make it behave the same.

We were getting some duplicate kfree() in the error case in
eth_configure because platform_device_unregister frees buffers that
the error cases following tried to free again.

The pcap initialization routine wasn't doing the proper printk of its
information, causing a printk of the first part of that line to be
unterminated by a newline.

The pcap code had a bunch of style violations, which are now fixed.

pcap_setup wasn't returning false when it detected an unrecognized
option.

The printks in pcap_user all got UM_KERN_BLAH prepended to their
format strings.

pcap_remove now checks for a non-NULL pcap structure before it calls
pcap_close.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 arch/um/drivers/net_kern.c  |   15 +--
 arch/um/drivers/pcap_kern.c |   25 -
 arch/um/drivers/pcap_user.c |   23 +--
 3 files changed, 38 insertions(+), 25 deletions(-)

Index: linux-2.6.21-mm/arch/um/drivers/net_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/net_kern.c 2007-04-27 
16:23:31.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/net_kern.c  2007-04-27 16:24:12.0 
-0400
@@ -316,12 +316,14 @@ static void setup_etheraddr(char *str, u
}
if (!is_local_ether_addr(addr)) {
printk(KERN_WARNING
-  "Warning: attempt to assign a globally valid ethernet 
address to a "
-  "device\n");
-   printk(KERN_WARNING "You should better enable the 2nd rightmost 
bit "
- "in the first byte of the MAC, i.e. "
- "%02x:%02x:%02x:%02x:%02x:%02x\n",
- addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4], 
addr[5]);
+  "Warning: attempt to assign a globally valid ethernet "
+  "address to a device\n");
+   printk(KERN_WARNING "You should better enable the 2nd "
+  "rightmost bit in the first byte of the MAC,\n");
+   printk(KERN_WARNING "i.e. %02x:%02x:%02x:%02x:%02x:%02x\n",
+  addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4],
+  addr[5]);
+   goto random;
}
return;
 
@@ -478,6 +480,7 @@ out_undo_user_init:
(*transport->user->remove)(&lp->user);
 out_unregister:
platform_device_unregister(&device->pdev);
+   return; /* platform_device_unregister frees dev and device */
 out_free_netdev:
free_netdev(dev);
 out_free_device:
Index: linux-2.6.21-mm/arch/um/drivers/pcap_kern.c
===
--- linux-2.6.21-mm.orig/arch/um/drivers/pcap_kern.c2007-04-27 
16:24:05.0 -0400
+++ linux-2.6.21-mm/arch/um/drivers/pcap_kern.c 2007-04-27 16:24:22.0 
-0400
@@ -29,21 +29,25 @@ void pcap_init(struct net_device *dev, v
ppri->promisc = init->promisc;
ppri->optimize = init->optimize;
ppri->filter = init->filter;
+
+   printk("pcap backend, host interface %s\n", ppri->host_if);
 }
 
-static int pcap_read(int fd, struct sk_buff **skb, 
+static int pcap_read(int fd, struct sk_buff **skb,
   struct uml_net_private *lp)
 {
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
-   if(*skb == NULL) return(-ENOMEM);
-   return(pcap_user_read(fd, skb_mac_header(*skb),
+   if(*skb == NULL)
+   return -ENOMEM;
+
+   return pcap_user_read(fd, skb_mac_header(*skb),
  (*skb)->dev->mtu + ETH_HEADER_OTHER,
- (struct pcap_data *) &lp->user));
+ (struct pcap_data *) &lp->user);
 }
 
 static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
 {
-   return(-EPERM);
+   return -EPERM;
 }
 
 static const struct net_kern_info pcap_kern_info = {
@@ -65,12 +69,12 @@ int pcap_setup(char *str, char **mac_out
  .optimize = 0,
  .filter   = NULL });
 
-   remain = split_if_spec(str, &host_if, &init->filter, 
+   remain = split_if_spec(str, &host_if, &init->filter,
   &options[0], &options[1], NULL);
if(remain != NULL){
printk(KERN_ERR "pcap_setup 

[PATCH 0/6] cmpxchg cleanups and UML fixes

2007-05-01 Thread Jeff Dike
This set is a combination of cmpxchg cleanups and UML fixes.

Patches 1 - 3 are the cmpxchg stuff -
Remove tas() from all arches - I can't find any users.
Move the i386 cmpxchg to asm-i386/cmpxchg.h
Move the x86_64 cmpxchg to asm-x86_64/cmpxchg.h

Patches 4 - 6 fix things discovered while playing with pcap interfaces -
Have the free wrapper detect malloced buffers and call libc free
Fix the device initialization failure path and other small cleanups
Allow pcap devices to be assigned MACs on the command line

This is all 2.6.22 material.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/6] Remove tas()

2007-05-01 Thread Jeff Dike
tas() has no users, so get rid of it.

The blackfin piece of this clashes with mainline, so this should maybe
be merged with the blackfin port.

Signed-off-by: Jeff Dike <[EMAIL PROTECTED]>
--
 include/asm-alpha/system.h |3 ---
 include/asm-arm/system.h   |2 --
 include/asm-arm26/system.h |2 --
 include/asm-blackfin/system.h  |1 -
 include/asm-h8300/system.h |1 -
 include/asm-i386/system.h  |2 --
 include/asm-m32r/system.h  |2 --
 include/asm-m68k/system.h  |1 -
 include/asm-m68knommu/system.h |1 -
 include/asm-mips/system.h  |1 -
 include/asm-powerpc/system.h   |2 --
 include/asm-ppc/system.h   |1 -
 include/asm-sh/system.h|   10 --
 include/asm-sh64/system.h  |2 --
 include/asm-sparc/system.h |1 -
 include/asm-sparc64/system.h   |1 -
 include/asm-v850/system.h  |1 -
 include/asm-x86_64/system.h|2 --
 include/asm-xtensa/system.h|2 --
 19 files changed, 38 deletions(-)

Index: linux-2.6.21-mm/include/asm-alpha/system.h
===
--- linux-2.6.21-mm.orig/include/asm-alpha/system.h 2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-alpha/system.h  2007-04-30 17:54:32.0 
-0400
@@ -548,9 +548,6 @@ __xchg_u64_local(volatile long *m, unsig
sizeof(*(ptr))); \
   })
 
-#define tas(ptr) (xchg((ptr),1))
-
-
 /* 
  * Atomic compare and exchange.  Compare OLD with MEM, if identical,
  * store NEW in MEM.  Return the initial value in MEM.  Success is
Index: linux-2.6.21-mm/include/asm-arm/system.h
===
--- linux-2.6.21-mm.orig/include/asm-arm/system.h   2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-arm/system.h2007-04-30 17:54:33.0 
-0400
@@ -103,8 +103,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
 
Index: linux-2.6.21-mm/include/asm-arm26/system.h
===
--- linux-2.6.21-mm.orig/include/asm-arm26/system.h 2007-02-04 
13:44:54.0 -0500
+++ linux-2.6.21-mm/include/asm-arm26/system.h  2007-04-30 17:54:33.0 
-0400
@@ -52,8 +52,6 @@ void hook_fault_code(int nr, int (*fn)(u
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 extern asmlinkage void __backtrace(void);
 
 #define set_cr(x)  \
Index: linux-2.6.21-mm/include/asm-blackfin/system.h
===
--- linux-2.6.21-mm.orig/include/asm-blackfin/system.h  2007-04-26 
17:33:06.0 -0400
+++ linux-2.6.21-mm/include/asm-blackfin/system.h   2007-04-30 
17:54:33.0 -0400
@@ -138,7 +138,6 @@ extern unsigned long irq_flags;
 #endif
 
 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(x),(ptr),sizeof(*(ptr
-#define tas(ptr) ((void)xchg((ptr),1))
 
 struct __xchg_dummy {
unsigned long a[100];
Index: linux-2.6.21-mm/include/asm-h8300/system.h
===
--- linux-2.6.21-mm.orig/include/asm-h8300/system.h 2007-02-04 
13:44:54.0 -0500
+++ linux-2.6.21-mm/include/asm-h8300/system.h  2007-04-30 17:54:34.0 
-0400
@@ -98,7 +98,6 @@ asmlinkage void resume(void);
 #endif
 
 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(x),(ptr),sizeof(*(ptr
-#define tas(ptr) (xchg((ptr),1))
 
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
Index: linux-2.6.21-mm/include/asm-i386/system.h
===
--- linux-2.6.21-mm.orig/include/asm-i386/system.h  2007-04-30 
12:38:17.0 -0400
+++ linux-2.6.21-mm/include/asm-i386/system.h   2007-04-30 18:04:43.0 
-0400
@@ -197,8 +197,6 @@ static inline unsigned long get_limit(un
 
 #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned 
long)(v),(ptr),sizeof(*(ptr
 
-#define tas(ptr) (xchg((ptr),1))
-
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((struct __xchg_dummy *)(x))
 
Index: linux-2.6.21-mm/include/asm-m32r/system.h
===
--- linux-2.6.21-mm.orig/include/asm-m32r/system.h  2007-04-26 
17:31:51.0 -0400
+++ linux-2.6.21-mm/include/asm-m32r/system.h   2007-04-30 17:54:34.0 
-0400
@@ -122,8 +122,6 @@ static inline void local_irq_disable(voi
 #define xchg(ptr,x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof

Re: [patch] uml: fix cmpxchg warnings in -mm

2007-04-27 Thread Jeff Dike
On Fri, Apr 27, 2007 at 07:27:48PM +0200, Sam Ravnborg wrote:
> Then atomic.h should include system.h and not rely on someone else doing it.
> Yes - then system.h may be included twice but that's ok.

I tried that - Andi didn't like it.  My current thinking is to pull the
cmpxchg stuff out of system.h into its own header since I don't see
any existing natural place to put it.

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH] ChunkFS: fs fission for faster fsck

2007-04-27 Thread Jeff Dike
On Thu, Apr 26, 2007 at 09:58:25PM -0700, Valerie Henson wrote:
> Here's an example, spelled out:
> 
> Allocate file 1 in chunk A.
> Grow file 1.
> Chunk A fills up.
> Allocate continuation inode for file 1 in chunk B.
> Chunk A gets some free space.
> Chunk B fills up.
> Pick chunk A for allocating next block of file 1.
> Try to look up a continuation inode for file 1 in chunk A.
> Continuation inode for file 1 found in chunk A!
> Attach newly allocated block to existing inode for file 1 in chunk A.

So far, so good (and the slides are helpful, tx!).  What happens when
file 1 keeps growing and chunk A fills up (and chunk B is still full)?
Can the same continuation inode also point at chunk C, where the file
is going to grow to?

Jeff

-- 
Work email - jdike at linux dot intel dot com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


<    1   2   3   4   5   6   7   8   9   >