From: David Laight <David.Laight@ACULAB.COM>
To: 'Al Viro' <viro@zeniv.linux.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Christophe Leroy <christophe.leroy@c-s.fr>,
Josh Poimboeuf <jpoimboe@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
the arch/x86 maintainers <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: RE: objtool clac/stac handling change..
Date: Tue, 7 Jul 2020 12:35:16 +0000 [thread overview]
Message-ID: <b95ffa72db83431b95597a35f63d8e33@AcuMS.aculab.com> (raw)
In-Reply-To: <20200704021157.GZ2786714@ZenIV.linux.org.uk>
From: Al Viro
> Sent: 04 July 2020 03:12
...
> BTW, looking at csum_and_copy_{to,from}_user() callers (all 3 of them,
> all in lib/iov_iter.c) we have this:
> 1) len is never 0
> 2) sum (initial value of csum) is always 0
> 3) failure (reported via *err_ptr) is always treateds as "discard
> the entire iovec segment (and possibly the entire iovec)". Exact value
> put into *err_ptr doesn't matter (it's only compared to 0) and in case of
> error the return value is ignored.
>
> Now, using ~0U instead of 0 for initial sum would yield an equivalent csum
> (comparable modulo 2^16-1) *AND* never yield 0 (recall how csum addition works).
>
> IOW, we could simply return 0 to indicate an error. Which gives much saner
> calling conventions:
> __wsum csum_and_copy_from_user(const void __user *src, void *dst, int len)
> copying the damn thing and returning 0 on error or a non-zero value comparable
> to csum of the data modulo 2^16-1 on success. Same for csum_and_copy_to_user()
> (modulo const and __user being on the other argument).
>
> For x86 it simplifies the instances (both the inline wrappers and asm parts);
> I hadn't checked the other architectures yet, but it looks like that should
> be doable for all architectures. And it does simplify the callers...
All the csum functions should let the caller pass in a small value
to be added in (could be over 2^32 on 64 bit systems) since that is
normally 'free' in the algorithm - certainly better than adding it
it at the end - which is what the current x86 code does.
(For 64bit systems the 'small' value can exceed 2^32.)
I also wonder if the csum_and_copy() functions are actually worthwhile on x86.
The csum code can run at 8 bytes/clock on all Intel cpu since ivy bridge.
(It doesn't, it only does 4 bytes/clock until (IIRC) Haswell [1].)
On cpu that support ADCX/ADOX you may do better - probably 12 bytes/clock,
I think 16 bytes/clock is wishful thinking.
But there is no leeway for any extra uops in either case.
However trying to get a memory read, memory write, adc and bits of loop
control scheduled in one clock is probably impossible - even though
it might not exceed the number of uops the execution pipelines can process.
ISTR that just separating the memory read from the adc slows
thing down too much - probably issues with retiring instructions.
So I don't think it can get near 8 bytes/clock.
OTOH a copy operation trivially does 8 bytes/clock.
I even think 'rep movsq' is faster - never mind the fast 'rep movsb'.
So separate copy and checksum passes should easily exceed 4 bytes/clock,
but I suspect that doing them together never does.
(Unless the buffer is too big for the L1 cache.)
[1] The underlying problem is that a uop can only have 2 inputs.
ADC needs three (two values and the carry flag).
So the ADC instruction takes two clocks.
From ivy bridge (sandy?) the carry flag is available early,
so adding to alternate registers lets you do 1 per clock.
So the existing csum function is rather slower than adding
32bit values to a 64bit register on most older cpus.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2020-07-07 12:35 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-01 18:22 Linus Torvalds
2020-07-01 18:29 ` Andy Lutomirski
2020-07-01 19:35 ` Linus Torvalds
2020-07-01 20:36 ` Andy Lutomirski
2020-07-01 20:51 ` Josh Poimboeuf
2020-07-01 21:02 ` Linus Torvalds
2020-07-02 0:00 ` Josh Poimboeuf
2020-07-02 8:05 ` Peter Zijlstra
2020-07-01 20:51 ` Linus Torvalds
2020-07-02 0:47 ` Andy Lutomirski
2020-07-02 2:30 ` Linus Torvalds
2020-07-02 2:35 ` Linus Torvalds
2020-07-02 3:08 ` Andy Lutomirski
2020-07-01 18:41 ` Al Viro
2020-07-01 19:04 ` Linus Torvalds
2020-07-01 19:59 ` Al Viro
2020-07-01 20:25 ` Linus Torvalds
2020-07-02 13:34 ` Michael Ellerman
2020-07-02 14:01 ` Al Viro
2020-07-02 14:04 ` Al Viro
2020-07-02 15:13 ` Christophe Leroy
2020-07-02 20:13 ` Linus Torvalds
2020-07-03 3:59 ` Michael Ellerman
2020-07-03 3:17 ` Michael Ellerman
2020-07-03 5:27 ` Christophe Leroy
2020-07-02 19:52 ` Linus Torvalds
2020-07-02 20:17 ` Al Viro
2020-07-02 20:32 ` Linus Torvalds
2020-07-02 20:59 ` Al Viro
2020-07-02 21:55 ` Linus Torvalds
2020-07-03 1:33 ` Al Viro
2020-07-03 3:32 ` Linus Torvalds
2020-07-03 21:02 ` Al Viro
2020-07-03 21:10 ` Linus Torvalds
2020-07-03 21:41 ` Andy Lutomirski
2020-07-03 22:25 ` Al Viro
2020-07-03 21:59 ` Al Viro
2020-07-03 22:04 ` Al Viro
2020-07-03 22:12 ` Al Viro
2020-07-04 0:49 ` Al Viro
2020-07-04 1:54 ` Linus Torvalds
2020-07-04 2:30 ` Al Viro
2020-07-04 3:06 ` Linus Torvalds
2020-07-04 2:11 ` Al Viro
2020-07-07 12:35 ` David Laight [this message]
2020-07-10 22:37 ` Linus Torvalds
2020-07-13 9:32 ` David Laight
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=b95ffa72db83431b95597a35f63d8e33@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=christophe.leroy@c-s.fr \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpe@ellerman.id.au \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@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
Powered by JetHome