From: Eric Biggers <ebiggers3@gmail.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
David Howells <dhowells@redhat.com>,
linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH v2] statx: optimize copy of struct statx to userspace
Date: Sat, 11 Mar 2017 22:01:48 -0800 [thread overview]
Message-ID: <20170312060148.GA1595@zzz> (raw)
In-Reply-To: <20170312040206.GA3684@zzz>
On Sat, Mar 11, 2017 at 08:02:06PM -0800, Eric Biggers wrote:
> On Sun, Mar 12, 2017 at 02:29:27AM +0000, Al Viro wrote:
> >
> > Oh, I agree that multiple __put_user() are wrong; I also agree that bulk copy is
> > the right approach (when we get the unsafe stuff right, we can revisit that, but
> > I suspect that on quite a few architectures a bulk copy will still give better
> > time, no matter what).
> >
> > > If padding is a concern at all (AFAICS it's not actually an issue now with
> > > struct statx, but people tend to have different opinions on how careful they
> > > want to be with padding), then I think we'll just have to start by memsetting
> > > the whole struct to 0.
> >
> > My point is simply that it's worth a comment in that code.
>
> Okay, thanks. I'll add a comment about the padding assumption, and I think I'll
> take the suggestion to use a designated initializer. Then at least all *fields*
> get initialized by default. And if in the future someone wants to conditionally
> initialize fields, then they can use ?: or they can do it after the initializer.
> Either way, at least they won't be able to forget to zero some field.
>
> - Eric
Okay, well, I may have changed my mind again... I tried the designated
initializer on x86_64 with gcc 4.8 and 6.3, and also on arm64 with gcc 4.8. In
each case, it was compiled into first zeroing all 256 bytes of the struct, just
like memset(&tmp, 0, sizeof(tmp)). Yes, this was with
CC_OPTIMIZE_FOR_PERFORMANCE=y. So I think we might as well just write the full
memset(), making it completely clear that everything is initialized. (This is
especially useful for people who are auditing code paths like this for
information leaks.) Also, a smart compiler could potentially optimize away
parts of the memset() anyway...
Eric
next prev parent reply other threads:[~2017-03-12 6:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-11 21:45 [PATCH v2] statx: optimize copy of struct statx to userspace Eric Biggers
2017-03-12 1:24 ` Al Viro
2017-03-12 2:16 ` Eric Biggers
2017-03-12 2:29 ` Al Viro
2017-03-12 4:02 ` Eric Biggers
2017-03-12 6:01 ` Eric Biggers [this message]
2017-03-13 4:34 ` Andreas Dilger
2017-03-13 10:27 ` Florian Weimer
2017-03-13 18:11 ` Eric Biggers
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=20170312060148.GA1595@zzz \
--to=ebiggers3@gmail.com \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).