linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>,
	Jingoo Han <jingoohan1@gmail.com>,
	Joao Pinto <Joao.Pinto@synopsys.com>,
	Matt Sealey <neko@bakuhatsu.net>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Russell King <linux@armlinux.org.uk>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	linux-pci <linux-pci@vger.kernel.org>
Subject: Re: framebuffer corruption due to overlapping stp instructions on arm64
Date: Fri, 3 Aug 2018 19:33:22 +0200	[thread overview]
Message-ID: <CAKv+Gu-aNFh1fsr_05SEwDp99n3pLrguP7=tEcFQPNY53=K7Fw@mail.gmail.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1808031235410.31584@file01.intranet.prod.int.rdu2.redhat.com>

(- libc-alpha)

On 3 August 2018 at 19:09, Mikulas Patocka <mpatocka@redhat.com> wrote:
>
>
> On Fri, 3 Aug 2018, Will Deacon wrote:
>
>> On Fri, Aug 03, 2018 at 09:16:39AM +0200, Ard Biesheuvel wrote:
>> > On 3 August 2018 at 08:35, Mikulas Patocka <mpatocka@redhat.com> wrote:
>> > >
>> > >
>> > > On Thu, 2 Aug 2018, Matt Sealey wrote:
>> > >
>> > >> The easiest explanation for this would be that the memory isn?t mapped
>> > >> correctly. You can?t use PCIe memory spaces with anything other than
>> > >> Device-nGnRE or stricter mappings. That?s just differences between the
>> > >> AMBA and PCIe (posted/unposted) memory models.
>> >
>> > Whoa hold on there.
>> >
>> > Are you saying we cannot have PCIe BAR windows with memory semantics on ARM?
>> >
>> > Most accelerated graphics drivers rely heavily on the ability to map
>> > the VRAM normal-non-cacheable (ioremap_wc, basically), and treat it as
>> > ordinary memory.
>>
>> Yeah, I'd expect framebuffers to be mapped as normal NC. That should be
>> fine for prefetchable BARs, no?
>>
>> Will
>
> So - why does it corrupt data then? I've created this program that
> reproduces the data corruption quicky. If I run it on /dev/fb0, I get an
> instant failure. Sometimes a few bytes are not written, sometimes a few
> bytes are written with a value that should be 16 bytes apart.
>

Are we still talking about overlapping unaligned accesses here? Or do
you see other failures as well?

> I tried to run it on system RAM mapped with the NC attribute and I didn't
> get any corruption - that suggests the the bug may be in the PCIE
> subsystem.
>
> Jingoo Han and Joao Pinto are maintainers for the designware PCIE
> controllers. Could you suggest why does the controller corrupt data when
> writing to videoram? Are there any tricks that could be tried to work
> around the corruption?
>
> Mikulas
>
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <sys/mman.h>
>
> #define LEN             256
> #define PRINT_STRIDE    0x20
>
> static unsigned char data[LEN];
> static unsigned char val = 0;
>
> static unsigned char prev_data[LEN];
>
> static unsigned char map_copy[LEN];
>
> int main(int argc, char *argv[])
> {
>         unsigned long n = 0;
>         int h;
>         unsigned char *map;
>         unsigned start, end, i;
>
>         if (argc < 2) fprintf(stderr, "argc\n"), exit(1);
>         if (argc >= 4) srandom(atoll(argv[3]));
>         h = open(argv[1], O_RDWR | O_DSYNC);
>         if (h == -1) perror("open"), exit(1);
>         map = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, h, argc >= 3 ? strtoull(argv[2], NULL, 16) : 0);
>         if (map == MAP_FAILED) perror("mmap"), exit(1);
>
>         memset(data, 0, LEN);
>         memset(prev_data, 0, LEN);
>         memset(map, 0, LEN);
>
>         sleep(1);
>
>         while (1) {
>                 start = (unsigned)random() % (LEN + 1);
>                 end = (unsigned)random() % (LEN + 1);
>                 if (start > end)
>                         continue;
>                 for (i = start; i < end; i++)
>                         data[i] = val++;
>                 memcpy(map + start, data + start, end - start);
>                 if (memcmp(map, data, LEN)) {
>                         unsigned j;
>                         memcpy(map_copy, map, LEN);
>                         fprintf(stderr, "mismatch after %lu loops!\n", n);
>                         fprintf(stderr, "last copied range: 0x%x - 0x%x (0x%x)\n", start, end, (unsigned)(end - start));
>                         for (j = 0; j < LEN; j += PRINT_STRIDE) {
>                                 fprintf(stderr, "p[%03x]", j);
>                                 for (i = j; i < j + PRINT_STRIDE && i < LEN; i++)
>                                         fprintf(stderr, " %s%s%02x\e[0m", !(i % 4) ? " " : "", data[i] != map_copy[i] ? "\e[31m" : "", prev_data[i]);
>                                 fprintf(stderr, "\n");
>                                 fprintf(stderr, "d[%03x]", j);
>                                 for (i = j; i < j + PRINT_STRIDE && i < LEN; i++)
>                                         fprintf(stderr, " %s%s%02x\e[0m", !(i % 4) ? " " : "", data[i] != map_copy[i] ? "\e[31m" : "", data[i]);
>                                 fprintf(stderr, "\n");
>                                 fprintf(stderr, "m[%03x]", j);
>                                 for (i = j; i < j + PRINT_STRIDE && i < LEN; i++)
>                                         fprintf(stderr, " %s%s%02x\e[0m", !(i % 4) ? " " : "", data[i] != map_copy[i] ? "\e[31m" : "", map_copy[i]);
>                                 fprintf(stderr, "\n\n");
>                         }
>                         exit(1);
>                 }
>                 memcpy(prev_data, data, LEN);
>                 n++;
>         }
> }

  parent reply	other threads:[~2018-08-03 17:33 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 19:31 framebuffer corruption due to overlapping stp instructions on arm64 Mikulas Patocka
     [not found] ` <CAHCPf3tFGqkYEcWNN4LaWThw_rVqT316pzLv6T7RfxwO-eZ0EA@mail.gmail.com>
2018-08-03  6:35   ` Mikulas Patocka
2018-08-03  7:16     ` Ard Biesheuvel
2018-08-03  9:41       ` Will Deacon
2018-08-03 17:09         ` Mikulas Patocka
2018-08-03 17:32           ` Sinan Kaya
2018-08-03 17:33           ` Ard Biesheuvel [this message]
2018-08-03 18:25             ` Mikulas Patocka
2018-08-03 20:44               ` Matt Sealey
2018-08-03 21:20                 ` Ard Biesheuvel
2018-08-06 10:25                   ` Mikulas Patocka
2018-08-06 12:42                     ` Robin Murphy
2018-08-06 12:53                       ` Ard Biesheuvel
2018-08-06 13:41                       ` Marcin Wojtas
2018-08-06 13:48                         ` Ard Biesheuvel
2018-08-06 14:07                           ` Marcin Wojtas
2018-08-06 14:13                             ` Mikulas Patocka
2018-08-06 15:47                       ` Ard Biesheuvel
2018-08-06 17:09                         ` Mikulas Patocka
2018-08-06 17:21                           ` Ard Biesheuvel
2018-08-06 19:54                             ` Mikulas Patocka
2018-08-06 20:11                               ` Ard Biesheuvel
2018-08-06 20:31                                 ` Mikulas Patocka
2018-08-07 16:40                                 ` Marcin Wojtas
2018-08-07 17:39                                   ` Mikulas Patocka
2018-08-07 18:07                                     ` Ard Biesheuvel
2018-08-07 18:17                                       ` Mikulas Patocka
     [not found]                                     ` <CAPv3WKcKoEe=Qysp6Oac2C=G9bUhUQf1twSRCY+_qJ6XEC-iag@mail.gmail.com>
2018-08-08 14:10                                       ` Mikulas Patocka
2018-08-06 17:13                         ` Catalin Marinas
2018-08-06 17:19                           ` Mikulas Patocka
2018-08-08 18:31                       ` Mikulas Patocka
2018-08-04 13:29                 ` Mikulas Patocka
2018-08-08 12:16                 ` Catalin Marinas
2018-08-08 13:02                   ` David Laight
2018-08-08 13:46                     ` Mikulas Patocka
2018-08-08 14:26                       ` David Laight
2018-08-08 14:50                         ` Catalin Marinas
2018-08-08 16:21                           ` Mikulas Patocka
2018-08-08 16:31                             ` Arnd Bergmann
2018-08-08 16:43                               ` David Laight
2018-08-08 18:56                                 ` Mikulas Patocka
2018-08-08 18:37                         ` Mikulas Patocka
2018-08-08 11:39           ` Catalin Marinas
2018-08-08 14:12             ` Mikulas Patocka
2018-08-08 14:28               ` Catalin Marinas
2018-08-08 18:40                 ` Mikulas Patocka
2018-08-08 15:01               ` Richard Earnshaw (lists)
2018-08-08 15:14                 ` Catalin Marinas
2018-08-08 16:01                   ` Arnd Bergmann
2018-08-08 18:25                     ` Mikulas Patocka
2018-08-08 21:51                       ` Arnd Bergmann
2018-08-09 15:29                         ` Arnd Bergmann
2018-08-03  7:11 ` Andrew Pinski
2018-08-03  7:53   ` Florian Weimer
2018-08-03  9:12     ` Szabolcs Nagy
2018-08-03  9:15     ` Ramana Radhakrishnan
2018-08-03  9:29       ` Ard Biesheuvel
2018-08-03  9:37         ` Ramana Radhakrishnan
2018-08-03  9:42         ` Richard Earnshaw (lists)
2018-08-04  0:58           ` Mikulas Patocka
2018-08-04  1:13             ` Andrew Pinski
2018-08-04 11:04               ` Mikulas Patocka
2018-08-05 18:33                 ` Florian Weimer
2018-08-06  8:02                   ` Mikulas Patocka
2018-08-06  8:10                     ` Ard Biesheuvel
2018-08-06 10:31                       ` Mikulas Patocka
2018-08-06 10:37                         ` Ard Biesheuvel
2018-08-06 10:42                           ` Mikulas Patocka
2018-08-06 10:48                             ` Ard Biesheuvel
2018-08-06 12:09                               ` Mikulas Patocka
2018-08-06 12:19                                 ` Ard Biesheuvel
2018-08-06 12:22                                   ` Ard Biesheuvel
2018-08-07 14:14                                   ` Mikulas Patocka
2018-08-07 14:40                                     ` Ard Biesheuvel
2018-08-08 19:15                                   ` Mikulas Patocka
2018-08-06 11:19                         ` Siddhesh Poyarekar
2018-08-06 11:29                           ` Ard Biesheuvel
2018-08-06 14:26                   ` Tulio Magno Quites Machado Filho
2018-08-05 21:51                 ` Pavel Machek
2018-08-06 14:30                   ` Mikulas Patocka
2018-08-03 11:24         ` David Laight
2018-08-03 12:04           ` Mikulas Patocka
2018-08-03 13:04             ` David Laight
2018-08-05 14:36               ` Mikulas Patocka
2018-08-06 10:18                 ` David Laight
2018-08-07 14:07                   ` Mikulas Patocka
2018-08-07 14:33                     ` David Laight
2018-08-08 14:21                       ` Mikulas Patocka
2018-08-03 13:20     ` Mikulas Patocka
2018-08-03 13:31   ` Mikulas Patocka
2018-08-03 14:17     ` Richard Earnshaw (lists)
2018-08-05 21:36   ` Pavel Machek
2018-08-06  8:04     ` Ramana Radhakrishnan
2018-08-06  8:44       ` Pavel Machek
2018-08-06  9:11         ` Ard Biesheuvel

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='CAKv+Gu-aNFh1fsr_05SEwDp99n3pLrguP7=tEcFQPNY53=K7Fw@mail.gmail.com' \
    --to=ard.biesheuvel@linaro.org \
    --cc=Joao.Pinto@synopsys.com \
    --cc=catalin.marinas@arm.com \
    --cc=jingoohan1@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mpatocka@redhat.com \
    --cc=neko@bakuhatsu.net \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=will.deacon@arm.com \
    /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).