Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp784139imm; Fri, 3 Aug 2018 11:27:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgped/UfiCT8Jvoy584r7Ve3EJfBxgE7IOhXKUbqmVx97BMyPkYn8ZMs8deTTcNbGcZK4wi/7 X-Received: by 2002:a17:902:8541:: with SMTP id d1-v6mr4649270plo.81.1533320855044; Fri, 03 Aug 2018 11:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533320855; cv=none; d=google.com; s=arc-20160816; b=p0AWWMEty/OYiXEiyUTCu0t7cKdXj1vgfDDsh7x3m08MAiQuwXV2cquoqzINrP2eD5 xnkcC/WNwlRIMLBzlrOd0JLpDfMkO09v2dMO+dXahqfayz6BFfzAfySZty4XMRxRRr7n +Ace7AKC14Wyv9ImW+Fv7llSCbvvZHjfsel87PWQ4J2kunv9JBtqA+ayZjkTiNLEa4g1 cgBWqbzjBAYjTVzOONs0ZBEUP4zNfEBhBZsMsboD+KWTkzrvaaWTM7banvCSADxGAVzg QlQXiJTMTzqZi3QqXmGt/b1NwCU4VritPuWKwvKbfryjL6Al089GoJUpns0lIbK9UDCm 9piA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=PNPEA46SWHJSpl7aQ5J+Hgr/F4pcPe3eTvxcMjV+Cm8=; b=PcEZR+XFOdkLdQVNsZPaK/0TP22b+1vxNi9cp2eO+DFidq9riITR4aVGlQBsYb9vzE eYA0G27l1YrE087Hf913iQJbVLv2XbmKaa8wLYTQkBq+AytqBostl3ArLytdZXbyivp7 8ITZZjwNIhlrnWSeEx/r6mXasIT98oovhR2yBnbF3uuXOQCt0s6U7C59GYBNvEwUzeJq NuqVJhpEL87HDrWFzj77zxhUWo+D4sIhqePqsQ7jsHEtVuBy2KnTe5lE+1ccU0ULHlpe ExoMu6XhZT6ULWQRUk4Hdlpwn7Vr14u2aRD6arTZQYKQrT/q3NstgnfIEnY/ch6Iflqf DS4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si5321911pgb.107.2018.08.03.11.27.06; Fri, 03 Aug 2018 11:27:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729946AbeHCUXH (ORCPT + 99 others); Fri, 3 Aug 2018 16:23:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56830 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727479AbeHCUXG (ORCPT ); Fri, 3 Aug 2018 16:23:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0F0D7A7EF; Fri, 3 Aug 2018 18:25:39 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3DEF2026D65; Fri, 3 Aug 2018 18:25:39 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id w73IPduU019515; Fri, 3 Aug 2018 14:25:39 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w73IPcg4019511; Fri, 3 Aug 2018 14:25:38 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 3 Aug 2018 14:25:38 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Ard Biesheuvel cc: Will Deacon , Jingoo Han , Joao Pinto , Matt Sealey , Thomas Petazzoni , Catalin Marinas , Russell King , Linux Kernel Mailing List , linux-arm-kernel , linux-pci Subject: Re: framebuffer corruption due to overlapping stp instructions on arm64 In-Reply-To: Message-ID: References: <20180803094129.GB17798@arm.com> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 03 Aug 2018 18:25:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 03 Aug 2018 18:25:40 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mpatocka@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 3 Aug 2018, Ard Biesheuvel wrote: > (- libc-alpha) > > On 3 August 2018 at 19:09, Mikulas Patocka 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 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? Yes - it is caused by overlapping unaligned accesses inside memcpy. When I put "dmb sy" between the overlapping accesses in glibc/sysdeps/aarch64/memcpy.S, this program doesn't detect any memory corruption. > > 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 > > #include > > #include > > #include > > #include > > #include > > > > #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++; > > } > > } >