From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Nicholas Mc Guire <der.herr@hofr.at>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Question regarding anotation
Date: Mon, 22 Aug 2016 23:02:23 +0200 [thread overview]
Message-ID: <20160822210221.GA34545@macbook.home> (raw)
In-Reply-To: <20160822172550.GA28401@osadl.at>
On Mon, Aug 22, 2016 at 05:25:50PM +0000, Nicholas Mc Guire wrote:
>
> Hi !
>
> A probably very basic sparse question - but I could not figure out a
> satisfying answer. while compile testing a patch for ntb_transfer.c I got
>
> CHECK drivers/ntb/ntb_transport.c
> drivers/ntb/ntb_transport.c:1583:43: warning: incorrect type in argument 1 (different address spaces)
> drivers/ntb/ntb_transport.c:1583:43: expected void *dst
> drivers/ntb/ntb_transport.c:1583:43: got void [noderef] <asn:2>*offset
> drivers/ntb/ntb_transport.c:1583:56: warning: incorrect type in argument 2 (different address spaces)
> drivers/ntb/ntb_transport.c:1583:56: expected void const [noderef] <asn:1>*src
> drivers/ntb/ntb_transport.c:1583:56: got void *buf
>
> looking at the offending line;
>
> static void ntb_memcpy_tx(struct ntb_queue_entry *entry, void __iomem *offset)
> {
> #ifdef ARCH_HAS_NOCACHE_UACCESS
> /*
> * Using non-temporal mov to improve performance on non-cached
> * writes, even though we aren't actually copying from user space.
> */
> __copy_from_user_inatomic_nocache(offset, entry->buf, entry->len);
>
> the absence of a __user in the buf argument seems intentional and the
> dst is not a kernel but __iomem address which triggers the second warning
> So the first warning seems to be a false positive here, the second one
> Im not clear about, but I guess its also a false positive. The question
> is if there is a clean way to anotate this to make sparse happy without
> any unwanted sideffects ?
>
> For the first warning using (void __user *) entry->buf should do
> and be side-effect free, but how could the second warning be fixed ?
So the original code, now in the #else part was:
memcpy_toio(offset, entry->buf, entry->len);
which is correct regarding the annotation/extended typing:
- offset points to IO memory (annotated as void __iomem *)
- entry->buff is normal kernel memory (no annotation needed)
I have no idea if replacing this by __copy_from_user_inatomic_nocache()
does indeed improve performance or not, but it's a complete abuse of this
function's typing and intent and sparse rightfully complains about both case.
So, I really think that these warnings don't need any fixing and that hiding
them behind a cast is not a good idea at all.
Independently of the validity of using __copy_from_user_inatomic_nocache()
here it would be much better to have something like memcpy_toio_nocache().
Doesn't something like this already exist?
Why not make something using the primitives already used by
__copy_from_user_inatomic_nocache() (where, if really needed, using a cast
to "adjust" the types is much more justified)?
Regards,
Luc Van Oostenryck
next prev parent reply other threads:[~2016-08-22 21:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-22 17:25 Question regarding anotation Nicholas Mc Guire
2016-08-22 20:00 ` Van Oostenryck Luc
2016-08-22 21:02 ` Luc Van Oostenryck [this message]
2016-08-23 8:58 ` Nicholas Mc Guire
2016-08-22 22:01 ` Linus Torvalds
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=20160822210221.GA34545@macbook.home \
--to=luc.vanoostenryck@gmail.com \
--cc=der.herr@hofr.at \
--cc=linux-sparse@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.