Linux MIPS Architecture development
 help / color / mirror / Atom feed
* 64-bit sysinfo
@ 2003-06-12 10:59 Trevor Woerner
  2003-06-12 11:35 ` Ralf Baechle
  2003-06-12 21:36 ` Andrew Clausen
  0 siblings, 2 replies; 10+ messages in thread
From: Trevor Woerner @ 2003-06-12 10:59 UTC (permalink / raw)
  To: linux-mips

Hi everyone,

(good to see some familiar and friendly faces from the PPC list! :-)

I ran into a problem yesterday and I just don't know how I'm going to 
approach solving it.

I compiled a 64-bit MIPS kernel, then built a busybox-based ramdisk. At 
first I couldn't get busybox's 'init' to work but later solved it by 
disabling the 'check_memory()' call.

Further investigation into why the 'check_memory()' call was failing 
revealed a problem with the 'sysinfo()' system call. The kernel is 
64-bit, therefore when it fills in the 'struct sysinfo' (as it does 
when 'sys_meminfo()' is called) unsigned int's are 64 bits. But back in 
userspace, the 'struct sysinfo' that gets allocated thinks that 
unsigned int's are 32 bits.

This causes a crash if the 'struct sysinfo' is allocated on the stack 
back in userspace, and causes seg faults if it's allocated in the .data 
section (globally).

I'm crossing my fingers and hoping that my solution is to build all 
user-space apps with some switch that will set the sizes of data types 
to be the same between user space and kernel space. Does some such 
option exist?

	Trevor

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

* Re: 64-bit sysinfo
@ 2003-06-12 11:19 Tor Arntsen
  2003-06-12 12:04 ` Trevor Woerner
  0 siblings, 1 reply; 10+ messages in thread
From: Tor Arntsen @ 2003-06-12 11:19 UTC (permalink / raw)
  To: mips081, linux-mips

On Jun 12, 12:05, Trevor Woerner wrote:
[...]
>I compiled a 64-bit MIPS kernel, then built a busybox-based ramdisk. At 
>first I couldn't get busybox's 'init' to work but later solved it by 
>disabling the 'check_memory()' call.
>
>Further investigation into why the 'check_memory()' call was failing 
>revealed a problem with the 'sysinfo()' system call. The kernel is 
>64-bit, therefore when it fills in the 'struct sysinfo' (as it does 
>when 'sys_meminfo()' is called) unsigned int's are 64 bits. But back in 
>userspace, the 'struct sysinfo' that gets allocated thinks that 
>unsigned int's are 32 bits.
[...]

Hm, that sounds wrong to me. 'int' is supposed to be 32 bits also on
64-bit systems, only 'long' should be 64 bits.

-Tor

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

* Re: 64-bit sysinfo
  2003-06-12 10:59 Trevor Woerner
@ 2003-06-12 11:35 ` Ralf Baechle
  2003-06-12 12:07   ` Trevor Woerner
  2003-06-12 21:36 ` Andrew Clausen
  1 sibling, 1 reply; 10+ messages in thread
From: Ralf Baechle @ 2003-06-12 11:35 UTC (permalink / raw)
  To: Trevor Woerner; +Cc: linux-mips

On Thu, Jun 12, 2003 at 06:59:26AM -0400, Trevor Woerner wrote:

> (good to see some familiar and friendly faces from the PPC list! :-)
> 
> I ran into a problem yesterday and I just don't know how I'm going to 
> approach solving it.
> 
> I compiled a 64-bit MIPS kernel, then built a busybox-based ramdisk. At 
> first I couldn't get busybox's 'init' to work but later solved it by 
> disabling the 'check_memory()' call.
> 
> Further investigation into why the 'check_memory()' call was failing 
> revealed a problem with the 'sysinfo()' system call. The kernel is 
> 64-bit, therefore when it fills in the 'struct sysinfo' (as it does 
> when 'sys_meminfo()' is called) unsigned int's are 64 bits. But back in 
> userspace, the 'struct sysinfo' that gets allocated thinks that 
> unsigned int's are 32 bits.
> 
> This causes a crash if the 'struct sysinfo' is allocated on the stack 
> back in userspace, and causes seg faults if it's allocated in the .data 
> section (globally).
> 
> I'm crossing my fingers and hoping that my solution is to build all 
> user-space apps with some switch that will set the sizes of data types 
> to be the same between user space and kernel space. Does some such 
> option exist?

Userspace really shouldn't need to know what kind of kernel it's running
on ...

The kernel has a wrapper for 32-bit code (see sys32_sysinfo) and that one
seems to look correct to me.

Can you check that your program is actually using the right syscall,
that is syscall number 4116?  If it's using 5097 it's using the native
64-bit syscall which obviously would explain your observation.

Any piece of usercode that's directly using <asm/unistd.h> is likely
to do something like this.  In short, using <asm/unistd.h> from userspace
is a really bad idea ...

  Ralf

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

* Re: 64-bit sysinfo
  2003-06-12 21:36 ` Andrew Clausen
@ 2003-06-12 11:44   ` Ralf Baechle
  2003-06-12 12:02     ` Trevor Woerner
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Baechle @ 2003-06-12 11:44 UTC (permalink / raw)
  To: Andrew Clausen; +Cc: Trevor Woerner, linux-mips

On Thu, Jun 12, 2003 at 09:36:25PM +0000, Andrew Clausen wrote:

> On Thu, Jun 12, 2003 at 06:59:26AM -0400, Trevor Woerner wrote:
> > I'm crossing my fingers and hoping that my solution is to build all 
> > user-space apps with some switch that will set the sizes of data types 
> > to be the same between user space and kernel space. Does some such 
> > option exist?
> 
> No, the kernel should provide 32 bit values.  This is a bug.
> 
> I *thought* I sent a patch for this a while ago... I'm not sure now.

You sent it and I applied your patch on February 21.  Old mail appended
below again for Trevor's reference.  It doesn't explain why he sees
64-bit values though.  Trevor, what kernel exactly are you running?

  Ralf

Date:	Thu, 20 Feb 2003 11:26:55 +1100
From:	Andrew Clausen <clausen@melbourne.sgi.com>
To:	Linux-MIPS <linux-mips@linux-mips.org>
Cc:	ralf@linux-mips.org, linux-ia64@linuxia64.org
Subject: [patch] sys32_sysinfo broken on mips64 and ia64
Message-ID: <20030220002655.GE915@pureza.melbourne.sgi.com>

Hi all,

The sys32_sysinfo() calls are currently using an old version of
"struct sysinfo32", in both the mips64 and ia64 ports.

busybox's init can't cope with the bogus output on my Origin 200,
so this bug prevents the Debian installer from bootstrapping.

This is the mips64 version of the patch.  A very similar patch
could be constructed for ia64... it's very obvious what to do,
so I'll leave it to you ia64 people :)

Cheers,
Andrew


diff -u -r1.42.2.23 linux32.c
--- arch/mips64/kernel/linux32.c	23 Jan 2003 02:12:59 -0000	1.42.2.23
+++ arch/mips64/kernel/linux32.c	20 Feb 2003 00:05:41 -0000
@@ -672,8 +672,11 @@
         u32 bufferram;
         u32 totalswap;
         u32 freeswap;
-        unsigned short procs;
-        char _f[22];
+        u16 procs;
+	u32 totalhigh;
+	u32 freehigh;
+	u32 mem_unit;
+	char _f[8];
 };
 
 extern asmlinkage int sys_sysinfo(struct sysinfo *info);
@@ -698,6 +701,9 @@
 	err |= __put_user (s.totalswap, &info->totalswap);
 	err |= __put_user (s.freeswap, &info->freeswap);
 	err |= __put_user (s.procs, &info->procs);
+	err |= __put_user (s.totalhigh, &info->totalhigh);
+	err |= __put_user (s.freehigh, &info->freehigh);
+	err |= __put_user (s.mem_unit, &info->mem_unit);
 	if (err)
 		return -EFAULT;
 	return ret;

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

* Re: 64-bit sysinfo
  2003-06-12 11:44   ` Ralf Baechle
@ 2003-06-12 12:02     ` Trevor Woerner
  0 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2003-06-12 12:02 UTC (permalink / raw)
  To: Ralf Baechle, Andrew Clausen; +Cc: linux-mips

On June 12, 2003 07:44 am, Ralf Baechle wrote:
> Trevor, what kernel exactly are you
> running?

I'm running Broadcom's SWARM board (sb1, 1250), so I'm running the most 
recent Broadcom kernel that comes with it (2.4.20-rc6 with patches).

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

* Re: 64-bit sysinfo
  2003-06-12 11:19 64-bit sysinfo Tor Arntsen
@ 2003-06-12 12:04 ` Trevor Woerner
  2003-06-12 12:04   ` Trevor Woerner
  0 siblings, 1 reply; 10+ messages in thread
From: Trevor Woerner @ 2003-06-12 12:04 UTC (permalink / raw)
  To: Tor Arntsen, linux-mips

On June 12, 2003 07:19 am, Tor Arntsen wrote:
> Hm, that sounds wrong to me. 'int' is supposed to be 32 bits also on
> 64-bit systems, only 'long' should be 64 bits.

Right, sorry. That was suppsed to read long. In any case, I put 'printk' 
where the calls are being made as printed out the sizeof() of the 
values and discovered that in user space they're 32 bits and in the 
kernel they're 64 bits.

	Trevor

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

* Re: 64-bit sysinfo
  2003-06-12 12:04 ` Trevor Woerner
@ 2003-06-12 12:04   ` Trevor Woerner
  0 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2003-06-12 12:04 UTC (permalink / raw)
  To: Tor Arntsen, linux-mips

On June 12, 2003 07:19 am, Tor Arntsen wrote:
> Hm, that sounds wrong to me. 'int' is supposed to be 32 bits also on
> 64-bit systems, only 'long' should be 64 bits.

Right, sorry. That was suppsed to read long. In any case, I put 'printk' 
where the calls are being made as printed out the sizeof() of the 
values and discovered that in user space they're 32 bits and in the 
kernel they're 64 bits.

	Trevor

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

* Re: 64-bit sysinfo
  2003-06-12 11:35 ` Ralf Baechle
@ 2003-06-12 12:07   ` Trevor Woerner
  2003-06-12 12:27     ` Ralf Baechle
  0 siblings, 1 reply; 10+ messages in thread
From: Trevor Woerner @ 2003-06-12 12:07 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On June 12, 2003 07:35 am, Ralf Baechle wrote:
> The kernel has a wrapper for 32-bit code (see sys32_sysinfo) and that
> one seems to look correct to me.
>
> Can you check that your program is actually using the right syscall,
> that is syscall number 4116?  If it's using 5097 it's using the
> native 64-bit syscall which obviously would explain your observation.

Thanks for your (and everyone's suggestions) I'll have a look at this 
today. I put a printk in kernel/proc.c:sys_sysinfo() so that's the one 
being called. I also put another printk in 
arch/mips64/mm/init.c:si_meminfo() (??? i think...) and it was being 
called from 'sys_info()'. I don't remember seeing sys32_sysinfo() but 
I'll look again.

	Trevor

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

* Re: 64-bit sysinfo
  2003-06-12 12:07   ` Trevor Woerner
@ 2003-06-12 12:27     ` Ralf Baechle
  0 siblings, 0 replies; 10+ messages in thread
From: Ralf Baechle @ 2003-06-12 12:27 UTC (permalink / raw)
  To: Trevor Woerner; +Cc: linux-mips

On Thu, Jun 12, 2003 at 08:07:59AM -0400, Trevor Woerner wrote:

> Thanks for your (and everyone's suggestions) I'll have a look at this 
> today. I put a printk in kernel/proc.c:sys_sysinfo() so that's the one 
> being called. I also put another printk in 
> arch/mips64/mm/init.c:si_meminfo() (??? i think...) and it was being 
> called from 'sys_info()'. I don't remember seeing sys32_sysinfo() but 
> I'll look again.

sys32_sysinfo calls sys_sysinfo.  So if you see a direct call to
sys_sysinfo this might proof something is using the wrong syscall.
Strace is your friend ...  Oh, and verify that your kernel has Andrew's
patch from my previous mail applied.

  Ralf

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

* Re: 64-bit sysinfo
  2003-06-12 10:59 Trevor Woerner
  2003-06-12 11:35 ` Ralf Baechle
@ 2003-06-12 21:36 ` Andrew Clausen
  2003-06-12 11:44   ` Ralf Baechle
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Clausen @ 2003-06-12 21:36 UTC (permalink / raw)
  To: Trevor Woerner; +Cc: linux-mips, Ralf Baechle

On Thu, Jun 12, 2003 at 06:59:26AM -0400, Trevor Woerner wrote:
> I'm crossing my fingers and hoping that my solution is to build all 
> user-space apps with some switch that will set the sizes of data types 
> to be the same between user space and kernel space. Does some such 
> option exist?

No, the kernel should provide 32 bit values.  This is a bug.

I *thought* I sent a patch for this a while ago... I'm not sure now.

Cheers,
Andrew

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

end of thread, other threads:[~2003-06-12 12:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-12 11:19 64-bit sysinfo Tor Arntsen
2003-06-12 12:04 ` Trevor Woerner
2003-06-12 12:04   ` Trevor Woerner
  -- strict thread matches above, loose matches on Subject: below --
2003-06-12 10:59 Trevor Woerner
2003-06-12 11:35 ` Ralf Baechle
2003-06-12 12:07   ` Trevor Woerner
2003-06-12 12:27     ` Ralf Baechle
2003-06-12 21:36 ` Andrew Clausen
2003-06-12 11:44   ` Ralf Baechle
2003-06-12 12:02     ` Trevor Woerner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox