From: David Laight <David.Laight@ACULAB.COM>
To: 'Linus Torvalds' <torvalds@linux-foundation.org>
Cc: Andrew Lutomirski <luto@kernel.org>,
"dvlasenk@redhat.com" <dvlasenk@redhat.com>,
Jens Axboe <axboe@kernel.dk>, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "bp@alien8.de" <bp@alien8.de>,
Peter Anvin <hpa@zytor.com>,
the arch/x86 maintainers <x86@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
"brgerst@gmail.com" <brgerst@gmail.com>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>
Subject: RE: [PATCH] x86: only use ERMS for user copies for larger sizes
Date: Mon, 26 Nov 2018 10:01:32 +0000 [thread overview]
Message-ID: <c4a6e3cc861e4cf2bf463286a62ae5fa@AcuMS.aculab.com> (raw)
In-Reply-To: <CAHk-=wj9DA-mH8jahuEPUWxO4EgbCcPRgdOJAQD58DBtCCrHcQ@mail.gmail.com>
From: Linus Torvalds
> Sent: 23 November 2018 16:36
>
> On Fri, Nov 23, 2018 at 2:12 AM David Laight <David.Laight@aculab.com> wrote:
> >
> > I've just patched my driver and redone the test on a 4.13 (ubuntu) kernel.
> > Calling memcpy_fromio(kernel_buffer, PCIe_address, length)
> > generates a lot of single byte TLP.
>
> I just tested it too - it turns out that the __inline_memcpy() code
> never triggers, and "memcpy_toio()" just generates a memcpy.
>
> So that code seems entirely dead.
>
> And, in fact, the codebase I looked at was the historical one, because
> I had been going back and looking at the history. The modern tree
> *does* have the "__inline_memcpy()" function I pointed at, but it's
> not actually hooked up to anything!
>
> This actually has been broken for _ages_. The breakage goes back to
> 2010, and commit 6175ddf06b61 ("x86: Clean up mem*io functions"), and
> it seems nobody really ever noticed - or thought that it was ok.
It probably was ok in 2010 - that predates ERMS copy.
> That commit claims that iomem has no special significance on x86, but
> that really really isn't true, exactly because the access size does
> matter.
I suspect that memcpy_to/fromio() should only be used for IO space
that has 'memory-like' semantics.
So it shouldn't really matter what size accesses are done.
OTOH the 'io' side is likely to be slow so you want to limit the
number of io cycles (reads in particular).
With memory-like semantics it is ok to read full words at both ends
of the buffer to avoid extra transfers.
Indeed, on PCIe, the misaligned transfer for the last 8 bytes is
probably optimal.
> And as mentioned, the generic memory copy routines are not at all
> appropriate, and that has nothing to do with ERMS. Our "do it by hand"
> memory copy routine does things like this:
>
> .Lless_16bytes:
> cmpl $8, %edx
> jb .Lless_8bytes
> /*
> * Move data from 8 bytes to 15 bytes.
> */
> movq 0*8(%rsi), %r8
> movq -1*8(%rsi, %rdx), %r9
> movq %r8, 0*8(%rdi)
> movq %r9, -1*8(%rdi, %rdx)
> retq
>
> and note how for a 8-byte copy, it will do *two* reads of the same 8
> bytes, and *two* writes of the same 8 byte destination. That's
> perfectly ok for regular memory, and it means that the code can handle
> an arbitrary 8-15 byte copy without any conditionals or loop counts,
> but it is *not* ok for iomem.
I'd say it is ok for memcpy_to/fromio() since that should only really
be used for targets with memory-like semantics - and could be documented
as such.
But doing the same transfers twice is definitely sub-optimal.
> Of course, in practice it all just happens to work in almost all
> situations (because a lot of iomem devices simply won't care), and
> manual access to iomem is basically extremely rare these days anyway,
> but it's definitely entirely and utterly broken.
>
> End result: we *used* to do this right. For the last eight years our
> "memcpy_{to,from}io()" has been entirely broken, and apparently even
> the people who noticed oddities like David, never reported it as
> breakage but instead just worked around it in drivers.
>
> Ho humm.
>
> Let me write a generic routine in lib/iomap_copy.c (which already does
> the "user specifies chunk size" cases), and hook it up for x86.
>
> David, are you using a bus analyzer or something to do your testing?
> I'll have a trial patch for you asap.
We've a TLP monitor built into our fpga image so can look at the last
few TLPs (IIRC a 32kB buffer).
Testing patches is a bit harder.
The test system isn't one I build kernels on.
Is there a 'sensible' amd64 kernel config that contains most of the drivers
a modern system might need?
It is a PITA trying to build kernels that will load on all my test systems
(since I tend to move the disks between systems).
Rebuilding the ubuntu config just takes too long and generates a ramdisk
that doesn't fit in /boot.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2018-11-26 10:01 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <02bfc577-32a5-66be-64bf-d476b7d447d2@kernel.dk>
2018-11-20 20:24 ` Jens Axboe
2018-11-21 6:36 ` Ingo Molnar
2018-11-21 13:32 ` Jens Axboe
2018-11-21 13:44 ` Denys Vlasenko
2018-11-22 17:36 ` David Laight
2018-11-22 17:52 ` Linus Torvalds
2018-11-22 18:06 ` Andy Lutomirski
2018-11-22 18:58 ` Linus Torvalds
2018-11-23 9:34 ` David Laight
2018-11-23 10:12 ` David Laight
2018-11-23 16:36 ` Linus Torvalds
2018-11-23 17:42 ` Linus Torvalds
2018-11-23 18:39 ` Andy Lutomirski
2018-11-23 18:44 ` Linus Torvalds
2018-11-23 19:11 ` Andy Lutomirski
2018-11-26 10:12 ` David Laight
2018-11-26 10:01 ` David Laight [this message]
2018-11-26 10:26 ` David Laight
2019-01-05 2:38 ` Linus Torvalds
2019-01-07 9:55 ` David Laight
2019-01-07 17:43 ` Linus Torvalds
2019-01-08 9:10 ` David Laight
2019-01-08 18:01 ` Linus Torvalds
2018-11-21 13:45 ` Paolo Abeni
2018-11-21 17:27 ` Linus Torvalds
2018-11-21 18:04 ` Jens Axboe
2018-11-21 18:26 ` Andy Lutomirski
2018-11-21 18:43 ` Linus Torvalds
2018-11-21 22:38 ` Andy Lutomirski
2018-11-21 18:16 ` Linus Torvalds
2018-11-21 19:01 ` Linus Torvalds
2018-11-22 10:32 ` Ingo Molnar
2018-11-22 11:13 ` Ingo Molnar
2018-11-22 11:21 ` Ingo Molnar
2018-11-23 16:40 ` Josh Poimboeuf
2018-11-22 16:55 ` Linus Torvalds
2018-11-22 17:26 ` Andy Lutomirski
2018-11-22 17:35 ` Linus Torvalds
2018-11-24 6:09 ` Jens Axboe
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=c4a6e3cc861e4cf2bf463286a62ae5fa@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dvlasenk@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=pabeni@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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