Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp338895imu; Wed, 21 Nov 2018 21:16:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ud+8yjnytf2G/swPiFo3s5kCH+bjQexBFe8hU0krgbVmNXL5+3RDD/R1ZI0+OUEdc9a1nS X-Received: by 2002:a63:d70e:: with SMTP id d14mr8804029pgg.159.1542863807716; Wed, 21 Nov 2018 21:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542863807; cv=none; d=google.com; s=arc-20160816; b=KXTLtUo3VOS3RHjIZuR4a/6ltGQ9VxO+MWc5K4bORHIbVd5WtUk9xd78fsnWD+yQz9 CpA+GHZZ9vVSxj6rrXuarnl3ogHuOVkzMnb9Q8NmQlQXH7wmLdm62QNJjTuHKY9ohPDV uPQU2PCTTdbWeXy21wlyd1mdMXduBvK/c0aOHCMEc24RXVRc1WMwt3WqqjTHbZP0YFDj OAafsIJI0M9CFihPrsPpBANDn52zYZzQpNeLwpo0EyML1ASwzgUZK46wrS48ZVvGKGu/ RQ1Lu428t9SCxuXGgEVIjVDce8BW4CtjdJQcdRfq0nCwPgZiHbfTO5su01tCpr4cAfGZ UiKA== 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 :in-reply-to:references:mime-version; bh=NRjxJoHyWVS4XjqdcRM0pfqjiGJnAqqkKVmP/gwOPrA=; b=1DSGv3XXTQgu0z/KH0eJmHZ8JWSOl7P+F2jPl+/CSxhytdw8AVnV2tjkIvcwm7f0a6 dNHShnwLC9YIx3vlVUj3hyCO7gl98W4ZtA3o7ehLigAnMUk4+WzZROqwW3cBQOXbEMmi 5uY6BxRnIOJOMBdtxmK+mrFJfcUBOuh9wa6LAP5AjH4qqkI9pnPaEgT3wNuleEZncdVv Lbi6u3jqgkqOldVUl1YPSZVjK8X1E1ER/b1OmVmeCMX1+B+y2F+FVWSG3ViEh5lAq9OI r9mZz8CslE3Tw7Cs2v7cU8b0UB9MJpmabpFnYLK7Yrpzwjbzu1ugtXlZjxWDYEvAMhvI +7bw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si32729878pls.30.2018.11.21.21.16.13; Wed, 21 Nov 2018 21:16:47 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389495AbeKVGzG (ORCPT + 99 others); Thu, 22 Nov 2018 01:55:06 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:43684 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389352AbeKVGyI (ORCPT ); Thu, 22 Nov 2018 01:54:08 -0500 Received: by mail-qt1-f194.google.com with SMTP id i7so5262316qtj.10 for ; Wed, 21 Nov 2018 12:18:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NRjxJoHyWVS4XjqdcRM0pfqjiGJnAqqkKVmP/gwOPrA=; b=MbunCfzdQqf3qO5nHold71aeFCs5zhhRFkglpbaDbeHMjS9pyddwy68kFK+ubm/8jW Omih7YvZyAnbnN5BNkqCW5qcGFcky+ZEPfVswRYzs3nU+dYZ43O/e8Oad5/OWXhtJn3E dD1bG8Hsqn2N1Mk7u/ZF23IofB6FUuNKfILM+mDZI53jcX0l9GoIolfrALKdnUMQIzmT AzPTLcujF/zzNCzYP9YelsO7iJZK8keOH0ehEWweSOMr0DUAo78CWluzyvx0Ni6XVI9R rmT7ZdEnj/vgbEhcvDjOn7wiDfoQjnFPcKc4iIdUmID5TTsF+k1bQ9CZx3VZvjZzwQjY KXyg== X-Gm-Message-State: AA+aEWZetNNnoTMle9OAlcFVuUUjWLscpXwT29Z627//kgovKzmXcNg6 jpbRAvGtGGF7sq0erE2hBp5QH/VSr6Nfcmodxu0= X-Received: by 2002:a0c:f50c:: with SMTP id j12mr7362572qvm.149.1542831499850; Wed, 21 Nov 2018 12:18:19 -0800 (PST) MIME-Version: 1.0 References: <13D59CF9CEBAF94592A12E8AE55501350113CD10@DE02WEMBXB.internal.synopsys.com> <9ffd1270-ad92-88b7-eb53-85c65fe971dd@synopsys.com> <4881796E12491D4BB15146FE0209CE6468198AC6@DE02WEMBXB.internal.synopsys.com> <661a4323-5768-4977-5434-ab644c5418aa@synopsys.com> In-Reply-To: From: Arnd Bergmann Date: Wed, 21 Nov 2018 21:18:03 +0100 Message-ID: Subject: Re: Misaligned Access To: Vineet Gupta Cc: Vitor Soares , alexey.brodkin@synopsys.com, Joao Pinto , jose.abreu@synopsys.com, "open list:SYNOPSYS ARC ARCHITECTURE" , Linux Kernel Mailing List 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 On Wed, Nov 21, 2018 at 9:15 PM Vineet Gupta wrote: > > On 11/21/18 12:12 PM, Arnd Bergmann wrote: > > On Wed, Nov 21, 2018 at 8:42 PM Vineet Gupta wrote: > >> +CC lkml, Arnd : subject matter expert > >> > >> On 11/21/18 10:06 AM, Vitor Soares wrote: > >>> I use the follow function to get data from a RX Fifo. > >>> > >>> > >>> static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master, > >>> u8 *bytes, int nbytes) > >>> { > >>> readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4); > >> So the semantics are reading the same fifo register N times, to get the N words, > >> hence read*s*l is appropriate. That however expects the buffer to be 4 bytes > >> aligned, hence your issue. You can't possibly use the reads*b* as we want the > >> > >> The obvious but crude hack is to use a temp array for readsl and then copy over > >> using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is issue is > >> a driver triggering unaligned access due to the misinteraction of API (driver get > >> an unaligned u8 *) which goes against expectations of io accessor readl (needed > >> since the register contents are 4 bytes) > > Is this again on ARC or some other architecture that cannot do unaligned > > access to normal RAM? On ARMv7 or x86, you should never see a problem > > because the CPU handles misaligned writes. On ARMv4/v5, the readsl() > > implementation internally aligns the access to the output buffer so it > > will work correctly. > > This is indeed on ARC: on ARC700 unaligned access to RAM was never supported and > on HS38x cores, it is configurable, so the API probably needs to support both cases. Ok, then I think you need to overwrite readsl() with a variant that uses put_unaligned() instead the plain pointer dereference for the output. Arnd