From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Atish Patra <atish.patra@wdc.com>
Cc: Palmer Dabbelt <palmer@sifive.com>,
"linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Albert Ou <albert@sifive.com>
Subject: Re: [PATCH 3/3] riscv: fix __user annotation for __copy_user()
Date: Mon, 4 Jun 2018 21:09:28 +0200 [thread overview]
Message-ID: <20180604190927.7jrdlulgowt5umce@ltop.local> (raw)
In-Reply-To: <235fec3e-be2e-874a-8313-e7390fcdca74@wdc.com>
On Mon, Jun 04, 2018 at 11:46:50AM -0700, Atish Patra wrote:
> On 6/1/18 8:22 AM, Luc Van Oostenryck wrote:
> > __copy_user() is a function, written in assembly, used to copy
> > memory between kernel & user space. As such its to & from args
> > may both take a user pointer or a kernel pointer.
> >
> > However the prototype for this function declare these two args
> > as 'void __user *', which is no more & no less correct than
> > declaring them as 'void *'. In fact theer is no possible correct
>
> /s/theer/there
>
> > annotation for such a function.
> >
> > The problem is worked around here by declaring these args as
> > unsigned long and casting them to the right type in each of
> > two callers raw_copy_{to,from}_user() as some kind of cast would
> > be needed anyway.
> >
> > Note: another solution, maybe cleaner but slightly more complex,
> > would be to declare two version of __copy_user,
> > either in the asm file or via an alias, each having already
> > the correct typing for raw_copy_{to,from}_user().
> >
>
> I feel that would be a better solution as it is implemented similarly
> in ARM as well.
>
> I am unable to understand how "unsigned long" is better than "void*".
> x86 implementation has both arguments as void*. Can you please clarify ?
"better" is quite relative and it must be understood that sparse
allow to cast pointers o fany kinds to and from unsigned long
without any warnings (while doing a cast between different address
space will emit a warning unless you use '__force').
As I tried to explain here above, the fact that this function is
declared as taking 2 __user pointers requires to use of casts
(ugly casts with __force) to get over the __user. By declaring
them as taking unsigned long, you still have to use casts but, IMO,
it's cleaner
Note: they're generic pointers/addresses anyway, they can't be
dereferenced anyway so unsigned is as good as a plain void*
or a void __user*
Note: using unsigned long here, fundamentally to bypass the __user,
is the same as casting a const pointer back to a plain pointer
via an intermediate cast to unsigned long. People can argue
that's kinda cheating, and they would be right of course, but
using __force or declaring twice the function with two different
names and prototype is also a form of cheating.
Note: if this would be my code, I would choose the solution with
two declarations.
Best regards,
-- Luc
next prev parent reply other threads:[~2018-06-04 19:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-01 15:21 [PATCH 0/3] riscv: fix sparse annotations Luc Van Oostenryck
2018-06-01 15:21 ` [PATCH 1/3] riscv: use NULL instead of a plain 0 Luc Van Oostenryck
2018-06-01 15:21 ` [PATCH 2/3] riscv: no __user for probe_kernel_address() Luc Van Oostenryck
2018-06-01 15:21 ` [PATCH 3/3] riscv: fix __user annotation for __copy_user() Luc Van Oostenryck
2018-06-04 18:46 ` Atish Patra
2018-06-04 19:09 ` Luc Van Oostenryck [this message]
2018-06-04 19:28 ` Atish Patra
2018-06-07 16:30 ` Palmer Dabbelt
2018-06-07 16:45 ` Atish Patra
2018-06-07 16:51 ` Luc Van Oostenryck
2018-06-08 22:33 ` Palmer Dabbelt
2018-06-09 0:13 ` Luc Van Oostenryck
2018-06-09 20:00 ` Palmer Dabbelt
2018-06-09 21:42 ` Luc Van Oostenryck
2018-06-11 19:01 ` Palmer Dabbelt
2018-06-12 3:00 ` Luc Van Oostenryck
2018-06-12 17:12 ` Palmer Dabbelt
2018-06-12 18:19 ` Luc Van Oostenryck
2018-06-12 19:38 ` Palmer Dabbelt
2018-06-09 0:33 ` [PATCH] riscv: split the declaration of __copy_user Luc Van Oostenryck
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=20180604190927.7jrdlulgowt5umce@ltop.local \
--to=luc.vanoostenryck@gmail.com \
--cc=albert@sifive.com \
--cc=atish.patra@wdc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@sifive.com \
/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®