From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB8B5C28CF6 for ; Fri, 3 Aug 2018 13:20:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73A092175D for ; Fri, 3 Aug 2018 13:20:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73A092175D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732140AbeHCPRB (ORCPT ); Fri, 3 Aug 2018 11:17:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53342 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728300AbeHCPRB (ORCPT ); Fri, 3 Aug 2018 11:17:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E91B97788E; Fri, 3 Aug 2018 13:20:41 +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 9E4F610CD6B3; Fri, 3 Aug 2018 13:20:41 +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 w73DKfMQ027965; Fri, 3 Aug 2018 09:20:41 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w73DKeKL027961; Fri, 3 Aug 2018 09:20:40 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 3 Aug 2018 09:20:40 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Florian Weimer cc: Andrew Pinski , Catalin Marinas , Will Deacon , linux@armlinux.org.uk, thomas.petazzoni@free-electrons.com, linux-arm-kernel@lists.infradead.org, LKML , GNU C Library Subject: Re: framebuffer corruption due to overlapping stp instructions on arm64 In-Reply-To: <9acdacdb-3bd5-b71a-3003-e48132ee1371@redhat.com> Message-ID: References: <9acdacdb-3bd5-b71a-3003-e48132ee1371@redhat.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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 03 Aug 2018 13:20:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 03 Aug 2018 13:20:42 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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, Florian Weimer wrote: > On 08/03/2018 09:11 AM, Andrew Pinski wrote: > > Yes fix Links not to use memcpy on the framebuffer. > > It is undefined behavior to use device memory with memcpy. > > Some (de facto) ABIs require that it is supported, though. For example, > the POWER string functions avoid unaligned loads and stores for this > reason because the platform has the same issue with device memory. And > yes, GCC will expand memcpy on POWER to something that is incompatible > with device memory. 8-( > > If we don't want people to use memcpy, we probably need to provide a > credible alternative. > > Thanks, > Florian And what does POWER do with code like this? void write_merge(int *x) { x[0] = x[1] = 0; } With -O2, gcc-8 translates it into: li 9,0 std 9,0(3) blr And that std instruction may end up being unaligned (the C ABI mandates that x is aligned to 4 bytes, not 8). If this piece of code is inside some graphics driver and writes to framebuffer memory, what do you do with it? Mikulas From mboxrd@z Thu Jan 1 00:00:00 1970 From: mpatocka@redhat.com (Mikulas Patocka) Date: Fri, 3 Aug 2018 09:20:40 -0400 (EDT) Subject: framebuffer corruption due to overlapping stp instructions on arm64 In-Reply-To: <9acdacdb-3bd5-b71a-3003-e48132ee1371@redhat.com> References: <9acdacdb-3bd5-b71a-3003-e48132ee1371@redhat.com> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, 3 Aug 2018, Florian Weimer wrote: > On 08/03/2018 09:11 AM, Andrew Pinski wrote: > > Yes fix Links not to use memcpy on the framebuffer. > > It is undefined behavior to use device memory with memcpy. > > Some (de facto) ABIs require that it is supported, though. For example, > the POWER string functions avoid unaligned loads and stores for this > reason because the platform has the same issue with device memory. And > yes, GCC will expand memcpy on POWER to something that is incompatible > with device memory. 8-( > > If we don't want people to use memcpy, we probably need to provide a > credible alternative. > > Thanks, > Florian And what does POWER do with code like this? void write_merge(int *x) { x[0] = x[1] = 0; } With -O2, gcc-8 translates it into: li 9,0 std 9,0(3) blr And that std instruction may end up being unaligned (the C ABI mandates that x is aligned to 4 bytes, not 8). If this piece of code is inside some graphics driver and writes to framebuffer memory, what do you do with it? Mikulas