public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
       [not found] <201008112336.o7BNaNEj020805@imap1.linux-foundation.org>
@ 2010-08-11 23:43 ` Randy Dunlap
  2010-08-12  0:33   ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Dunlap @ 2010-08-11 23:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, gcosta, hpa, lenb, mingo, tglx, ying.huang

On Wed, 11 Aug 2010 16:06:24 -0700 akpm@linux-foundation.org wrote:

> 
> The patch titled
>      drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> has been added to the -mm tree.  Its filename is
>      drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch
> 
> Before you just go and hit "reply", please:
>    a) Consider who else should be cc'ed
>    b) Prefer to cc a suitable mailing list as well
>    c) Ideally: find the original patch on the mailing list and do a
>       reply-to-all to that, adding suitable additional cc's
> 
> *** Remember to use Documentation/SubmitChecklist when testing your code ***
> 
> See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
> out what to do about this
> 
> The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/
> 
> ------------------------------------------------------
> Subject: drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> From: Andrew Morton <akpm@linux-foundation.org>
> 
> Might be an x86 bug?  A get_user() on a u64 on i386 expands to
> 
> #define __get_user_8(__ret_gu, __val_gu, ptr)				\
> 		__get_user_x(X, __ret_gu, __val_gu, ptr)
> 
> which emits a call to __get_user_X(), which doesn't exist.
> 
> Kludge around it with copy_from_user().
> 

Reported and fixed yesterday.

> 
> 
> While we're there, teach it how to print size_t's:

That was also patched, but yours is better.
I missed the cast in Huang's patch.


> drivers/acpi/apei/erst-dbg.c: In function 'erst_dbg_read':
> drivers/acpi/apei/erst-dbg.c:106: warning: format '%lx' expects type 'long unsigned int', but argument 3 has type 'ssize_t'
> 
> Cc: Glauber Costa <gcosta@redhat.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: Huang Ying <ying.huang@intel.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  drivers/acpi/apei/erst-dbg.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff -puN drivers/acpi/apei/erst-dbg.c~drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386 drivers/acpi/apei/erst-dbg.c
> --- a/drivers/acpi/apei/erst-dbg.c~drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386
> +++ a/drivers/acpi/apei/erst-dbg.c
> @@ -57,9 +57,10 @@ static long erst_dbg_ioctl(struct file *
>  
>  	switch (cmd) {
>  	case APEI_ERST_CLEAR_RECORD:
> -		rc = get_user(record_id, (u64 __user *)arg);
> +		rc = copy_from_user(&record_id, (const void __user *)arg,
> +					sizeof(record_id));
>  		if (rc)
> -			return rc;
> +			return -EFAULT;
>  		return erst_clear(record_id);
>  	case APEI_ERST_GET_RECORD_COUNT:
>  		rc = erst_get_record_count();
> @@ -104,7 +105,7 @@ retry:
>  		goto out;
>  	if (len > ERST_DBG_RECORD_LEN_MAX) {
>  		pr_warning(ERST_DBG_PFX
> -			   "Record (ID: 0x%llx) length is too long: 0x%lx\n",
> +			   "Record (ID: 0x%llx) length is too long: 0x%zx\n",
>  			   id, len);
>  		rc = -EIO;
>  		goto out;
> _


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-11 23:43 ` + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree Randy Dunlap
@ 2010-08-12  0:33   ` Andrew Morton
  2010-08-12  0:42     ` Huang Ying
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Andrew Morton @ 2010-08-12  0:33 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: linux-kernel, gcosta, hpa, lenb, mingo, tglx, ying.huang

On Wed, 11 Aug 2010 16:43:10 -0700 Randy Dunlap <randy.dunlap@oracle.com> wrote:

> On Wed, 11 Aug 2010 16:06:24 -0700 akpm@linux-foundation.org wrote:
> 
> > 
> > The patch titled
> >      drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> > has been added to the -mm tree.  Its filename is
> >      drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch
> > 
> > Before you just go and hit "reply", please:
> >    a) Consider who else should be cc'ed
> >    b) Prefer to cc a suitable mailing list as well
> >    c) Ideally: find the original patch on the mailing list and do a
> >       reply-to-all to that, adding suitable additional cc's
> > 
> > *** Remember to use Documentation/SubmitChecklist when testing your code ***
> > 
> > See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
> > out what to do about this
> > 
> > The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/
> > 
> > ------------------------------------------------------
> > Subject: drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> > From: Andrew Morton <akpm@linux-foundation.org>
> > 
> > Might be an x86 bug?  A get_user() on a u64 on i386 expands to
> > 
> > #define __get_user_8(__ret_gu, __val_gu, ptr)				\
> > 		__get_user_x(X, __ret_gu, __val_gu, ptr)
> > 
> > which emits a call to __get_user_X(), which doesn't exist.
> > 
> > Kludge around it with copy_from_user().
> > 
> 
> Reported and fixed yesterday.

Not very well.

+		rc = copy_from_user(&record_id, (void __user *)arg,
+				    sizeof(u64));

better to use sizeof(record_id).

Where's Len??


Anyway, this should be fixed in x86 core, I suspect.

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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  0:33   ` Andrew Morton
@ 2010-08-12  0:42     ` Huang Ying
  2010-08-12  1:35     ` H. Peter Anvin
  2010-08-12  4:22     ` H. Peter Anvin
  2 siblings, 0 replies; 10+ messages in thread
From: Huang Ying @ 2010-08-12  0:42 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel@vger.kernel.org, gcosta@redhat.com,
	hpa@zytor.com, lenb@kernel.org, mingo@elte.hu, tglx@linutronix.de

On Thu, 2010-08-12 at 08:33 +0800, Andrew Morton wrote:
> On Wed, 11 Aug 2010 16:43:10 -0700 Randy Dunlap <randy.dunlap@oracle.com> wrote:
> 
> > On Wed, 11 Aug 2010 16:06:24 -0700 akpm@linux-foundation.org wrote:
> > 
> > > 
> > > The patch titled
> > >      drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> > > has been added to the -mm tree.  Its filename is
> > >      drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch
> > > 
> > > Before you just go and hit "reply", please:
> > >    a) Consider who else should be cc'ed
> > >    b) Prefer to cc a suitable mailing list as well
> > >    c) Ideally: find the original patch on the mailing list and do a
> > >       reply-to-all to that, adding suitable additional cc's
> > > 
> > > *** Remember to use Documentation/SubmitChecklist when testing your code ***
> > > 
> > > See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
> > > out what to do about this
> > > 
> > > The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/
> > > 
> > > ------------------------------------------------------
> > > Subject: drivers/acpi/apei/erst-dbg.c: get_user(u64) doesn't work on i386
> > > From: Andrew Morton <akpm@linux-foundation.org>
> > > 
> > > Might be an x86 bug?  A get_user() on a u64 on i386 expands to
> > > 
> > > #define __get_user_8(__ret_gu, __val_gu, ptr)				\
> > > 		__get_user_x(X, __ret_gu, __val_gu, ptr)
> > > 
> > > which emits a call to __get_user_X(), which doesn't exist.
> > > 
> > > Kludge around it with copy_from_user().
> > > 
> > 
> > Reported and fixed yesterday.
> 
> Not very well.
> 
> +		rc = copy_from_user(&record_id, (void __user *)arg,
> +				    sizeof(u64));
> 
> better to use sizeof(record_id).

Will fix this with a new version. And the ssize printk format string.

> Where's Len??
>
> Anyway, this should be fixed in x86 core, I suspect.

Yes. I think so too.

Best Regards,
Huang Ying



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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  0:33   ` Andrew Morton
  2010-08-12  0:42     ` Huang Ying
@ 2010-08-12  1:35     ` H. Peter Anvin
  2010-08-12  4:22     ` H. Peter Anvin
  2 siblings, 0 replies; 10+ messages in thread
From: H. Peter Anvin @ 2010-08-12  1:35 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang

On 08/11/2010 05:33 PM, Andrew Morton wrote:
> 
> Not very well.
> 
> +		rc = copy_from_user(&record_id, (void __user *)arg,
> +				    sizeof(u64));
> 
> better to use sizeof(record_id).
> 
> Where's Len??
> 
> Anyway, this should be fixed in x86 core, I suspect.

Agreed.  Looking at it now.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  0:33   ` Andrew Morton
  2010-08-12  0:42     ` Huang Ying
  2010-08-12  1:35     ` H. Peter Anvin
@ 2010-08-12  4:22     ` H. Peter Anvin
  2010-08-12  4:30       ` Andrew Morton
  2 siblings, 1 reply; 10+ messages in thread
From: H. Peter Anvin @ 2010-08-12  4:22 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

[Adding Linux and linux-arch.  The context is that get_user/put_user
don't work on 64 bit values on i386.]

On 08/11/2010 05:33 PM, Andrew Morton wrote:
> 
> Anyway, this should be fixed in x86 core, I suspect.

After looking at it -- and suffering a bad case of déjà vu -- I'm
reluctant to change it, as get/put_user are specified to work only on
locally atomic data:

 * This macro copies a single simple variable from user space to kernel
 * space.  It supports simple types like char and int, but not larger
 * data types like structures or arrays.

Given that u64 is not a simple type on 32 bits, it would appear that the
behavior is intentional.

A user might very well find that supporting u64 and/or structure types
would be beneficial, but it would a) be a semantic change, and b) would
introduce the possibility of a partially completed transfer.  That is a
semantic change to the interface.  However, it may very well be nicer to
have a generally available get_user()/put_user() for the cases which
would just kick an EFAULT up the stack when they fail anyway.

If there is consensus for making get_user/put_user a general interface,
I'm more than willing to do the x86 changes, but I don't want to do them
a) unilaterally and b) for 2.6.36.  This seems like .37 material at this
point.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  4:22     ` H. Peter Anvin
@ 2010-08-12  4:30       ` Andrew Morton
  2010-08-12  4:42         ` H. Peter Anvin
  2010-08-12  5:06         ` H. Peter Anvin
  0 siblings, 2 replies; 10+ messages in thread
From: Andrew Morton @ 2010-08-12  4:30 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

On Wed, 11 Aug 2010 21:22:51 -0700 "H. Peter Anvin" <hpa@zytor.com> wrote:

> [Adding Linux and linux-arch.  The context is that get_user/put_user
> don't work on 64 bit values on i386.]
> 
> On 08/11/2010 05:33 PM, Andrew Morton wrote:
> > 
> > Anyway, this should be fixed in x86 core, I suspect.
> 
> After looking at it -- and suffering a bad case of d__j__ vu -- I'm
> reluctant to change it, as get/put_user are specified to work only on
> locally atomic data:
> 
>  * This macro copies a single simple variable from user space to kernel
>  * space.  It supports simple types like char and int, but not larger
>  * data types like structures or arrays.
> 
> Given that u64 is not a simple type on 32 bits, it would appear that the
> behavior is intentional.
> 
> A user might very well find that supporting u64 and/or structure types
> would be beneficial, but it would a) be a semantic change, and b) would
> introduce the possibility of a partially completed transfer.  That is a
> semantic change to the interface.  However, it may very well be nicer to
> have a generally available get_user()/put_user() for the cases which
> would just kick an EFAULT up the stack when they fail anyway.
> 
> If there is consensus for making get_user/put_user a general interface,
> I'm more than willing to do the x86 changes, but I don't want to do them
> a) unilaterally and b) for 2.6.36.  This seems like .37 material at this
> point.

It occurs so rarely that it's probably not worth bothering about, IMO.

However we should arrange for it to fail at compile time rather than
at link time, please.




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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  4:30       ` Andrew Morton
@ 2010-08-12  4:42         ` H. Peter Anvin
  2010-08-12  5:06         ` H. Peter Anvin
  1 sibling, 0 replies; 10+ messages in thread
From: H. Peter Anvin @ 2010-08-12  4:42 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

On 08/11/2010 09:30 PM, Andrew Morton wrote:
> 
> However we should arrange for it to fail at compile time rather than
> at link time, please.
> 

That is easy to do, of course.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  4:30       ` Andrew Morton
  2010-08-12  4:42         ` H. Peter Anvin
@ 2010-08-12  5:06         ` H. Peter Anvin
  2010-08-12  6:03           ` Andrew Morton
  1 sibling, 1 reply; 10+ messages in thread
From: H. Peter Anvin @ 2010-08-12  5:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

On 08/11/2010 09:30 PM, Andrew Morton wrote:
> 
> It occurs so rarely that it's probably not worth bothering about, IMO.
> 

I think the real question is if we want people to convert:

	if (copy_from_user(foo, bar, sizeof *foo))
		return -EFAULT;

... into ...

	if (get_user(*foo, bar))
		return -EFAULT;

... or ...

	rv = get_user(*foo, bar);
	if (rv)
		return rv;

... where *foo is a structure type.  It does have the advantage that a
single API does everything, simple or not, but has the disadvantage that
the partial-access semantics are now less explicit.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  5:06         ` H. Peter Anvin
@ 2010-08-12  6:03           ` Andrew Morton
  2010-08-12  6:10             ` H. Peter Anvin
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2010-08-12  6:03 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

On Wed, 11 Aug 2010 22:06:08 -0700 "H. Peter Anvin" <hpa@zytor.com> wrote:

> On 08/11/2010 09:30 PM, Andrew Morton wrote:
> > 
> > It occurs so rarely that it's probably not worth bothering about, IMO.
> > 
> 
> I think the real question is if we want people to convert:
> 
> 	if (copy_from_user(foo, bar, sizeof *foo))
> 		return -EFAULT;
> 
> ... into ...
> 
> 	if (get_user(*foo, bar))
> 		return -EFAULT;
> 
> ... or ...
> 
> 	rv = get_user(*foo, bar);
> 	if (rv)
> 		return rv;
> 
> ... where *foo is a structure type.  It does have the advantage that a
> single API does everything, simple or not, but has the disadvantage that
> the partial-access semantics are now less explicit.
> 

Well, anyone who does get_user() on a struct while expecting it to be
atomic gets to own both pieces.  I think the problem here is
specifically u64/s64.  These work on 64-bit but don't work on 32-bit.

Is the atomicity really a problem?  If userspace updates the 64-bit
number while the kernel is copying it, the kernel gets a garbage
number.  But so what?  Userspace can feed the kernel garbage numbers in
lots of ways, and the kernel must be able to cope with it
appropriately.


<I suspect you can do get_user() on a 4-byte or 8-byte struct right now
and it'll work>

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

* Re: + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree
  2010-08-12  6:03           ` Andrew Morton
@ 2010-08-12  6:10             ` H. Peter Anvin
  0 siblings, 0 replies; 10+ messages in thread
From: H. Peter Anvin @ 2010-08-12  6:10 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, linux-kernel, gcosta, lenb, mingo, tglx, ying.huang,
	Linux Arch Mailing List, Linus Torvalds

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

On 08/11/2010 11:03 PM, Andrew Morton wrote:
> <I suspect you can do get_user() on a 4-byte or 8-byte struct right now
> and it'll work>

Not so:

/home/hpa/kernel/linux-2.6-tip.urgent/arch/x86/lib/testuser.c:12: error: 
conversion to non-scalar type requested

	-hpa

[-- Attachment #2: testuser.c --]
[-- Type: text/x-csrc, Size: 194 bytes --]

#include <linux/types.h>
#include <linux/uaccess.h>

struct foo {
	u16 a, b;
};

int bluttan(struct foo *foo)
{
	struct foo bar;

	if (get_user(bar, foo))
		return -1;

	return bar.a + bar.b;
}

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

end of thread, other threads:[~2010-08-12  6:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <201008112336.o7BNaNEj020805@imap1.linux-foundation.org>
2010-08-11 23:43 ` + drivers-acpi-apei-erst-dbgc-get_useru64-doesnt-work-on-i386.patch added to -mm tree Randy Dunlap
2010-08-12  0:33   ` Andrew Morton
2010-08-12  0:42     ` Huang Ying
2010-08-12  1:35     ` H. Peter Anvin
2010-08-12  4:22     ` H. Peter Anvin
2010-08-12  4:30       ` Andrew Morton
2010-08-12  4:42         ` H. Peter Anvin
2010-08-12  5:06         ` H. Peter Anvin
2010-08-12  6:03           ` Andrew Morton
2010-08-12  6:10             ` H. Peter Anvin

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