linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Making __copy_tofrom_user more readable for powerpc (arch/powerpc/lib/copy_32.S)
@ 2008-07-10 18:06 prodyut hazarika
  0 siblings, 0 replies; 4+ messages in thread
From: prodyut hazarika @ 2008-07-10 18:06 UTC (permalink / raw)
  To: linuxppc-dev

Hi all,
I am trying to optimize the __copy_tofrom_user function for PPC4xx,
and I would want to know why the exception handling code has been made
so complicated. All the fixup code should do is to store the number of
bytes that failed in copy in r3 and return back.

The current code tries to copy one byte at a time after read fault. I
don't understand why that is necessary. It then clears out the
destination. All these logic has made the code very unfriendly to
read.

I have a version which just keeps a count of bytes copied till any
fault happened. Then for any exception, I just substract this value
from the total number of bytes to be copied, and store in r3 and
return back. This is the common fixup code for all paths. It makes the
code much more readable like other architectures (eg. x86).

My questions are:
1) Why do we need to distinguish between load and store failure? If
either load or store fails, the copy did not go thru. But the code
sets r9 to 0 for load failure, and r9 to 1 for write failure. Why do
we need to care for that?

2) For read failure, why do we clear out the destination? Other
architecture don't do that.

I would appreciate any comments. I will submit my patch later.

Thanks,
Prodyut

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

* Making __copy_tofrom_user more readable for powerpc (arch/powerpc/lib/copy_32.S)
@ 2008-07-10 23:44 prodyut hazarika
  2008-07-11  6:50 ` Michael Neuling
  2008-07-11  7:02 ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: prodyut hazarika @ 2008-07-10 23:44 UTC (permalink / raw)
  To: linuxppc-dev

Hi all,
I am trying to optimize the __copy_tofrom_user function for PPC4xx,
and I would want to know why the exception handling code has been made
so complicated. All the fixup code should do is to store the number of
bytes that failed in copy in r3 and return back.

The current code tries to copy one byte at a time after read fault. I
don't understand why that is necessary. It then clears out the
destination. All these logic has made the code very unfriendly to
read.

I have a version which just keeps a count of bytes copied till any
fault happened. Then for any exception, I just substract this value
from the total number of bytes to be copied, and store in r3 and
return back. This is the common fixup code for all paths. It makes the
fixup code much more readable like other architectures (eg. x86).

My questions are:
1) Why do we need to distinguish between load and store failure? If
either load or store fails, the copy did not go thru. But the code
sets r9 to 0 for load failure, and r9 to 1 for write failure. Why do
we need to care for that?

2) For read failure, why do we clear out the destination (lines 509 to
529 in arch/powerpc/lib/copy_32.S)? Other architecture don't do that.

I would appreciate any comments.

Thanks,
Prodyut

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

* Re: Making __copy_tofrom_user more readable for powerpc (arch/powerpc/lib/copy_32.S)
  2008-07-10 23:44 prodyut hazarika
@ 2008-07-11  6:50 ` Michael Neuling
  2008-07-11  7:02 ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Neuling @ 2008-07-11  6:50 UTC (permalink / raw)
  To: prodyut hazarika; +Cc: linuxppc-dev

In message <49c0ff980807101644x6ffb9a66x3f73c72f1be86e3@mail.gmail.com> you wro
te:
> Hi all,
> I am trying to optimize the __copy_tofrom_user function for PPC4xx,
> and I would want to know why the exception handling code has been made
> so complicated. All the fixup code should do is to store the number of
> bytes that failed in copy in r3 and return back.
> 
> The current code tries to copy one byte at a time after read fault. I
> don't understand why that is necessary. It then clears out the
> destination. All these logic has made the code very unfriendly to
> read.

Would a multibyte read be guaranteed to be aligned?

> I have a version which just keeps a count of bytes copied till any
> fault happened. Then for any exception, I just substract this value
> from the total number of bytes to be copied, and store in r3 and
> return back. This is the common fixup code for all paths. It makes the
> fixup code much more readable like other architectures (eg. x86).
> 
> My questions are:
> 1) Why do we need to distinguish between load and store failure? If
> either load or store fails, the copy did not go thru. But the code
> sets r9 to 0 for load failure, and r9 to 1 for write failure. Why do
> we need to care for that?
> 
> 2) For read failure, why do we clear out the destination (lines 509 to
> 529 in arch/powerpc/lib/copy_32.S)? Other architecture don't do that.

Which version of the code are you referring to here?  Can you give us a
git SHA1?

Clean up patches are welcome.  Maybe it would be best to post what you
have as an RFC patch.  Then people can take a closer/easier look at your
cleanups and/or try them out.

Mikey

> 
> I would appreciate any comments.
> 
> Thanks,
> Prodyut
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
> 

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

* Re: Making __copy_tofrom_user more readable for powerpc (arch/powerpc/lib/copy_32.S)
  2008-07-10 23:44 prodyut hazarika
  2008-07-11  6:50 ` Michael Neuling
@ 2008-07-11  7:02 ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2008-07-11  7:02 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: prodyut hazarika

On Friday 11 July 2008, prodyut hazarika wrote:
> I have a version which just keeps a count of bytes copied till any
> fault happened. Then for any exception, I just substract this value
> from the total number of bytes to be copied, and store in r3 and
> return back. This is the common fixup code for all paths. It makes the
> fixup code much more readable like other architectures (eg. x86).

In some cases, you need to make sure that the return value is exactly
the maximum you could copy, not a little less.
 
> The current code tries to copy one byte at a time after read fault. I
> don't understand why that is necessary. It then clears out the
> destination. All these logic has made the code very unfriendly to
> read.

I'm not sure if the code is also avoiding unaligned accesses here,
which is not a problem on x86. If you access uncached memory with
unaligned pointers, you get an exception and the fixup code will
copy it just fine with byte accesses.

> 2) For read failure, why do we clear out the destination (lines 509 to
> 529 in arch/powerpc/lib/copy_32.S)? Other architecture don't do that.

All architectures should do that for copy_from_user, to avoid potential
data leaks from the kernel when the data is copied back.

	Arnd <><

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

end of thread, other threads:[~2008-07-11  7:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-10 18:06 Making __copy_tofrom_user more readable for powerpc (arch/powerpc/lib/copy_32.S) prodyut hazarika
  -- strict thread matches above, loose matches on Subject: below --
2008-07-10 23:44 prodyut hazarika
2008-07-11  6:50 ` Michael Neuling
2008-07-11  7:02 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).