Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp734382imm; Fri, 3 Aug 2018 10:34:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfz4P1wDvcZFIsl4GZTED1lvsevYSjsXC/B7JaDppmMt1KWKzFabBPXshq01ylCpjC+ToQA X-Received: by 2002:a17:902:8c84:: with SMTP id t4-v6mr4589899plo.100.1533317670426; Fri, 03 Aug 2018 10:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533317670; cv=none; d=google.com; s=arc-20160816; b=Kfajj9uu9ssZcB0Gedpnxxr+oOnO/wHUqfwVXjxCx2M558BZTrgPosmFTEDX2GbiIn eHzvWVY2UfO/oNQshUzetvW9jfNKikkXYsf4gnfOGYh+U7GJ9DtCXSHhQu5pDA2yy775 TKZu03JL2IHOn2HlluEDuEIe9NXHZrxE43SZQ/8cF6m3Z0mefI/+uowJXZOMTMYGGXAA afyG7IJz0IbaEU5/vHq3QEX4eN8DNx+MadMFtANzR0rACqo0d0Xi/Y14H/O2V0fMw/NQ oyGI2moaVqVTqE5orcOuXFRpXkMh4hWfzOBw/Q4xs5/opRS1mbEOc1Ed/JYEdypMrPRX nPHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=i6Qm6rE9hqJzvzsuLLcWwi/AdFMgBkHEy1Cs+Ul15TY=; b=mfGCQwIK4rGIUPCV2qKqWDlFKQYl2uzHf52vpNh0doQJJ+YYQtE73Gm9LqeQG+Ae0r /nmBUxxCbseaYn+ifdWJh7L/O4jRSMPaTlGJJImhqWBZSqmjChhUtyPfhsjfFYkmPyT6 DwSM2GeQrJJwsrYh3fksrRElH8nTZ1eMcIqviaGbY26acdhRs2yduB+qu848MbwNi6vi hIXR+jrqmFMfVM2bvKnRL3AsJhd6zEaNFjNwxfOZrvkPlGI45ogigtZMQeFIcYdz4jeQ o3lvbWPbrjubUr4CV2ZN+CgXE6bo5nPWVtuZIKbmRZxh5FMYbHqqpWHw/qbW/QtlDXgJ O/lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T3l7ZV1z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2-v6si6290872pfs.2.2018.08.03.10.34.15; Fri, 03 Aug 2018 10:34:30 -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; dkim=pass header.i=@linaro.org header.s=google header.b=T3l7ZV1z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730272AbeHCTaj (ORCPT + 99 others); Fri, 3 Aug 2018 15:30:39 -0400 Received: from mail-it0-f45.google.com ([209.85.214.45]:37059 "EHLO mail-it0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728116AbeHCTaj (ORCPT ); Fri, 3 Aug 2018 15:30:39 -0400 Received: by mail-it0-f45.google.com with SMTP id h20-v6so9450535itf.2 for ; Fri, 03 Aug 2018 10:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=i6Qm6rE9hqJzvzsuLLcWwi/AdFMgBkHEy1Cs+Ul15TY=; b=T3l7ZV1zLn1EpdyHn0VokSIB9RT9dNeGP8RWuCqyhe4VSRb6McWUPAFv//G5QY/93u E7U0NAKky+QGNNauqRFFs/IRqwUd3TEgiVHokzL4nih0MNe0cx6Y8pQ5J0NcwO4vr3DJ 2aussLc9F1Eg8V/U4I1bix7tGsSkMk9rfnTjM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=i6Qm6rE9hqJzvzsuLLcWwi/AdFMgBkHEy1Cs+Ul15TY=; b=V/i2SBUKmCnN5CTaGx+elu1H3obONNQ5yB5+6JcvwUkB5AZPJpkjccq1V1V/p1/Sar i6KTQ0On+D6QjCeeG3LLHj7Jq39VSro2pqX0Nl4zuxxjpCDarA7LnC6khZrLNCLMuf6V PPnDMy+z0nsRMRt91yZ/4zdmVPwoJ79CZmGDbLZhz7AOGRYHbKVqaWp1ENOoaQbcxUWt CfRF1HnCAs2elFhGNUa/YsuLfuo0M2TTzS+PenTf2Xr85MDyxP6y/SGQpzDXRfsPsxNk 7iHeZvK5GDCQXEXxyiySgsUgv7L72bUR6r9GoMYKvjnfJAPLrnNrL1rVIW2hAywt7raN FTaw== X-Gm-Message-State: AOUpUlFx4Sj+w42q1M4kDVzKS8sEbFriOWgmx51akaYRJw1QG/pAAW7T 4X9EGRgVfjCKKHVZbmBNxLwWDzqdS/A0W1UsARtZgx7N X-Received: by 2002:a24:610d:: with SMTP id s13-v6mr7299193itc.68.1533317603373; Fri, 03 Aug 2018 10:33:23 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:ac05:0:0:0:0:0 with HTTP; Fri, 3 Aug 2018 10:33:22 -0700 (PDT) In-Reply-To: References: <20180803094129.GB17798@arm.com> From: Ard Biesheuvel Date: Fri, 3 Aug 2018 19:33:22 +0200 Message-ID: Subject: Re: framebuffer corruption due to overlapping stp instructions on arm64 To: Mikulas Patocka Cc: Will Deacon , Jingoo Han , Joao Pinto , Matt Sealey , Thomas Petazzoni , Catalin Marinas , Russell King , Linux Kernel Mailing List , linux-arm-kernel , linux-pci Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (- 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? > 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++; > } > }