mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vitaly Mayatskikh <v.mayatskih@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Vitaly Mayatskikh <v.mayatskih@gmail.com>,
	linux-kernel@vger.kernel.org, Andi Kleen <andi@firstfloor.org>,
	Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] x86: Optimize tail handling for copy_user
Date: Wed, 30 Jul 2008 14:07:58 +0200	[thread overview]
Message-ID: <m3hca760dd.fsf@gravicappa.englab.brq.redhat.com> (raw)
In-Reply-To: <alpine.LFD.1.10.0807280846320.3486@nehalem.linux-foundation.org> (Linus Torvalds's message of "Mon, 28 Jul 2008 08:48:41 -0700 (PDT)")

Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Mon, 28 Jul 2008, Vitaly Mayatskikh wrote:
>>
>> Reduce protection faults count in copy_user_handle_tail routine by
>> limiting clear length to the end of page as was suggested by Linus.
>
> No, you did it wrong.

Optimize tail handling with regarding to flags passed to handler
routine.

Signed-off-by: Vitaly Mayatskikh <v.mayatskih@gmail.com>

diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
index f4df6e7..d793900 100644
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -161,23 +161,32 @@ EXPORT_SYMBOL(copy_in_user);
 /*
  * Try to copy last bytes and clear the rest if needed.
  * Since protection fault in copy_from/to_user is not a normal situation,
- * it is not necessary to optimize tail handling.
+ * it is not necessary to do low level optimization of tail handling.
  */
 unsigned long
-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
+copy_user_handle_tail(char *dst, char *src, unsigned remainder, unsigned flags)
 {
 	char c;
-	unsigned zero_len;
+	unsigned max_copy = remainder;
 
-	for (; len; --len) {
-		if (__get_user_nocheck(c, from++, sizeof(char)))
+	/* Don't even bother trying to cross a page in user space! */
+	if (flags & DEST_IS_USERSPACE)
+		max_copy = min(max_copy, BYTES_LEFT_IN_PAGE(dst));
+	if (flags & SOURCE_IS_USERSPACE)
+		max_copy = min(max_copy, BYTES_LEFT_IN_PAGE(src));
+
+	while (max_copy--) {
+		if (__get_user(c, src))
 			break;
-		if (__put_user_nocheck(c, to++, sizeof(char)))
+		if (__put_user(c, dst))
 			break;
+		src++;
+		dst++;
+		remainder--;
 	}
 
-	for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
-		if (__put_user_nocheck(c, to++, sizeof(char)))
-			break;
-	return len;
+	if (flags & CLEAR_REMAINDER)
+		memset(dst, 0, remainder);
+
+	return remainder;
 }

-- 
wbr, Vitaly

  parent reply	other threads:[~2008-07-30 12:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-28 14:10 Vitaly Mayatskikh
2008-07-28 15:48 ` Linus Torvalds
2008-07-29 15:24   ` Vitaly Mayatskikh
2008-07-30 12:02   ` Vitaly Mayatskikh
2008-07-30 17:29     ` Linus Torvalds
2008-07-31 14:27       ` Vitaly Mayatskikh
2008-08-01 20:10         ` Linus Torvalds
2008-08-01 22:04           ` Vitaly Mayatskikh
2008-08-01 22:30             ` Linus Torvalds
2008-08-01 22:53               ` Vitaly Mayatskikh
2008-07-30 12:07   ` Vitaly Mayatskikh [this message]
2008-07-30 12:13   ` Vitaly Mayatskikh

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=m3hca760dd.fsf@gravicappa.englab.brq.redhat.com \
    --to=v.mayatskih@gmail.com \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome