mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Guan Xuetao" <gxt@mprc.pku.edu.cn>
To: "'Arnd Bergmann'" <arnd@arndb.de>
Cc: <linux-kernel@vger.kernel.org>, <linux-arch@vger.kernel.org>,
	"'Greg KH'" <greg@kroah.com>
Subject: RE: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccess
Date: Sun, 27 Feb 2011 11:21:12 +0800	[thread overview]
Message-ID: <017b01cbd62d$633fd070$29bf7150$@mprc.pku.edu.cn> (raw)
In-Reply-To: <201102171845.01177.arnd@arndb.de>



> -----Original Message-----
> From: Arnd Bergmann [mailto:arnd@arndb.de]
> Sent: Friday, February 18, 2011 1:45 AM
> To: Guan Xuetao
> Cc: linux-kernel@vger.kernel.org; linux-arch@vger.kernel.org; 'Greg KH'
> Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccess
> 
> On Wednesday 16 February 2011, Guan Xuetao wrote:
> > +
> > +#define __kernel_ok		(segment_eq(get_fs(), KERNEL_DS))
> > +#define __user_ok(addr, size)	(((size) <= TASK_SIZE)			\
> > +				&& ((addr) <= TASK_SIZE - (size)))
> > +#define __access_ok(addr, size)	(__kernel_ok || __user_ok((addr), (size)))
> 
> A nice trick to simplify this is to introduce a per-process variable for comparing
> the pointer, set_fs() then sets this variable to either TASK_SIZE or
> UINT_MAX.

Perhaps like this:
1. add a member named kaddr in thread_info
2. add following assignment codes in set_fs:
        current_thread_info()->kaddr =  segment_eq(fs, KERNEL_DS) ? UINT_MAX : TASK_SIZE;
3. then __access_ok will be:
        #define addr 
        #define __access_ok(addr, size)   (((size) <= TASK_SIZE)			\
				&& ((addr) <= current_thread_info()->kaddr)  - (size)))

> 
> This saves one conditional branch for each call to __access_ok.
> 
> 	Arnd


  reply	other threads:[~2011-02-27  3:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16  7:48 Guan Xuetao
2011-02-17 17:45 ` Arnd Bergmann
2011-02-27  3:21   ` Guan Xuetao [this message]
2011-02-27 17:21     ` Arnd Bergmann
2011-02-28  1:04       ` Guan Xuetao

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='017b01cbd62d$633fd070$29bf7150$@mprc.pku.edu.cn' \
    --to=gxt@mprc.pku.edu.cn \
    --cc=arnd@arndb.de \
    --cc=greg@kroah.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®