All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'Russell King'" <linux@armlinux.org.uk>,
	"Krzysztof Hałasa" <khalasa@piap.pl>
Cc: linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: RE: Data corruption on i.MX6 IPU in arm_copy_from_user()
Date: Thu, 27 May 2021 14:06:10 +0000	[thread overview]
Message-ID: <eb842382ac2d472d858d6daa3dc345bd@AcuMS.aculab.com> (raw)
In-Reply-To: <20210526131853.GE30436@shell.armlinux.org.uk>

From: Russell King <linux@armlinux.org.uk>
> Sent: 26 May 2021 14:19
> 
> On Wed, May 26, 2021 at 02:29:07PM +0200, Krzysztof Hałasa wrote:
> > "Russell King (Oracle)" <linux@armlinux.org.uk> writes:
> >
> > > Surely someone is not using copy_*_user() to copy data from userspace
> > > direct to MMIO space... that would be crazy.
> >
> > No, it's the other way around: reading MMIO mapped to userspace (mmap
> > on /dev/mem) and copying it to simple kernel buffer (e.g. pipe buffer).
> > I.e., the MMIO is the userspace here (thus copy_from_user()).
> 
> Ah. I think we assume copy_from_user() will be used on memory only and
> not device mappings.
> 
> In any case, looking at the architecture reference manual, LDM is
> permitted on device and strongly ordered mappings, and the memory
> subsystem is required to decompose it into a series of 32-bit accesses.
> So, it sounds to me like there could be a hardware bug in the buses/IPU
> causing this.
> 
> Can you try using LDM directly inside the kernel and seeing what effect
> it has when reading the IPU? A simple test module should be sufficient.
> I suspect it'll show the same thing - basically, that using LDM to the
> IPU is broken.

I was wondering if there is some kind of page fault on the first access?

What happens if you repeat the write() ?

FWIW you don't want to try this on x86.
The MMIO addresses are likely to be uncached but the copy
function is likely to decide to use the ERMS 'rep movsb' so
suddenly you get single byte PCIe reads!
What you really want is the largest AVX register available.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

WARNING: multiple messages have this Message-ID (diff)
From: David Laight <David.Laight@ACULAB.COM>
To: "'Russell King'" <linux@armlinux.org.uk>,
	"Krzysztof Hałasa" <khalasa@piap.pl>
Cc: linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: RE: Data corruption on i.MX6 IPU in arm_copy_from_user()
Date: Thu, 27 May 2021 14:06:10 +0000	[thread overview]
Message-ID: <eb842382ac2d472d858d6daa3dc345bd@AcuMS.aculab.com> (raw)
In-Reply-To: <20210526131853.GE30436@shell.armlinux.org.uk>

From: Russell King <linux@armlinux.org.uk>
> Sent: 26 May 2021 14:19
> 
> On Wed, May 26, 2021 at 02:29:07PM +0200, Krzysztof Hałasa wrote:
> > "Russell King (Oracle)" <linux@armlinux.org.uk> writes:
> >
> > > Surely someone is not using copy_*_user() to copy data from userspace
> > > direct to MMIO space... that would be crazy.
> >
> > No, it's the other way around: reading MMIO mapped to userspace (mmap
> > on /dev/mem) and copying it to simple kernel buffer (e.g. pipe buffer).
> > I.e., the MMIO is the userspace here (thus copy_from_user()).
> 
> Ah. I think we assume copy_from_user() will be used on memory only and
> not device mappings.
> 
> In any case, looking at the architecture reference manual, LDM is
> permitted on device and strongly ordered mappings, and the memory
> subsystem is required to decompose it into a series of 32-bit accesses.
> So, it sounds to me like there could be a hardware bug in the buses/IPU
> causing this.
> 
> Can you try using LDM directly inside the kernel and seeing what effect
> it has when reading the IPU? A simple test module should be sufficient.
> I suspect it'll show the same thing - basically, that using LDM to the
> IPU is broken.

I was wondering if there is some kind of page fault on the first access?

What happens if you repeat the write() ?

FWIW you don't want to try this on x86.
The MMIO addresses are likely to be uncached but the copy
function is likely to decide to use the ERMS 'rep movsb' so
suddenly you get single byte PCIe reads!
What you really want is the largest AVX register available.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-05-27 14:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26  8:26 Data corruption on i.MX6 IPU in arm_copy_from_user() Krzysztof Hałasa
2021-05-26  8:26 ` Krzysztof Hałasa
2021-05-26 10:08 ` Russell King (Oracle)
2021-05-26 10:08   ` Russell King (Oracle)
2021-05-26 12:29   ` Krzysztof Hałasa
2021-05-26 12:29     ` Krzysztof Hałasa
2021-05-26 13:18     ` Russell King (Oracle)
2021-05-26 13:18       ` Russell King (Oracle)
2021-05-27 14:06       ` David Laight [this message]
2021-05-27 14:06         ` David Laight
2021-05-28 10:02       ` Krzysztof Hałasa
2021-05-28 10:02         ` Krzysztof Hałasa
2021-05-28 14:35         ` Russell King (Oracle)
2021-05-28 14:35           ` Russell King (Oracle)
2021-05-31  4:30           ` Krzysztof Hałasa
2021-05-31  4:30             ` Krzysztof Hałasa
2021-05-31  6:20           ` Krzysztof Hałasa
2021-05-31  6:20             ` Krzysztof Hałasa

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=eb842382ac2d472d858d6daa3dc345bd@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=khalasa@piap.pl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.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 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.