Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp239032imu; Wed, 21 Nov 2018 18:59:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJ2n7auZtLteI1J+F1CqMSz5FADZvVcnm77uHsca6N8tuGgtbAmS4l+6wSDAcF0bAZ66rH X-Received: by 2002:a63:1904:: with SMTP id z4mr8103959pgl.135.1542855547087; Wed, 21 Nov 2018 18:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542855547; cv=none; d=google.com; s=arc-20160816; b=SKHTU8JiQuLSGk8LbeBLbEjd7Q4Az/DLdp8Cqd+nLAEQMVfF+U4bzAhUQx0SGAd43+ NneSv4yz648c6wyPB6ORlJmjcNPj8tfEBqWy4vRkmt9lMpqNyHvMd2GnBNTqvSziozAQ bJCg7am0o/XWy5SyWmLtHZtvHfK6OUpUop49RArs+QrBkWsFODkUOfeaFjx9ZRAJQpYs yDYL393eRZ/XKxZWduDDi6k/5edlJHrXgWkA+viwncEZ2HdDwXgZM4XRFEnUmCRrP9Bx /9m7zG+v2q3Xc21w3zJhZZ1Nut4NMHEQwB9tVjvu+ChY7yYyvv8DNbvQGwFBOOn0NxVR D5Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:references:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=0mq9TizmOiKZluz8u0CFQVVQzmLlnfMfr5dc7tvugS8=; b=VwOwCp7/rbqg4K6qooVppUyLNMG9RdnIF2bJAkRnmY8FGeq32pWjGATsLtmNqVQSZj Ds1xZy661+KR5Sp440PsHQa6kkfdfGTINigGuF7nUEZiJKmS4iBx+9IK5etugzXYH/TQ 2ftgAoaPAztv8eJFww54HPvL1hV8/rO6nveJUfWCk8qcKeib8FcSU+VmjLlCNQMuyCcd Qu0S6uih5OmAW+rjaI1RhlRD+ptSBd4FYQY7HOEtzRaRbB1fYjDyVvt5WxATK7TyYxOE wN+eYY83zyz42xM+Ch2cDoB0daduMFg9gbthEV+u/Ha51MfApbCBubZGhMqmqWL/CumE ho7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b="A/BX2PJR"; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si8962043plg.123.2018.11.21.18.58.52; Wed, 21 Nov 2018 18:59:07 -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; dkim=pass header.i=@synopsys.com header.s=mail header.b="A/BX2PJR"; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732835AbeKVGRg (ORCPT + 99 others); Thu, 22 Nov 2018 01:17:36 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:33962 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbeKVGRg (ORCPT ); Thu, 22 Nov 2018 01:17:36 -0500 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id A768124E12C5; Wed, 21 Nov 2018 11:41:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1542829317; bh=SMSSTlNFhJOx8xe5MPofETBAI9S74btb7y31gJPLUNU=; h=From:To:CC:Subject:Date:References:From; b=A/BX2PJRw5MhB6GdxV6EHkePCBkv0OQh2vBbD3Oj9eNB8y6KSMbtXGZtBR1osYQ1u tkPb59G/UbtOxvSNS9TpfiUZvMdgV8gJl1HebB1WiLPCxdNbIbUZjuxRrksM9Egu5j rfpz72yEe5ohp/y+07VCAmQy5n/1D5PyORZoTL4kdpuI/ueDA8y6nxQhko5cB9luqK OhAwDcBOPJe/WV0cMTWbjy9HHJz6S4Nmek4dpjh8OKzSj3eKIh/VSKdxYxm44n5B7g jrgrz1nFGxaN68VzgYwXVOyE1FcJpyB0416vSSjU/BjH5LYhfmKCXA7Y37HJ35NSpy Tk5vDR7ykDpCQ== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id 2B04B387E; Wed, 21 Nov 2018 11:41:57 -0800 (PST) Received: from US01WEMBX2.internal.synopsys.com ([fe80::e4b6:5520:9c0d:250b]) by US01WEHTC3.internal.synopsys.com ([::1]) with mapi id 14.03.0415.000; Wed, 21 Nov 2018 11:41:57 -0800 From: Vineet Gupta To: Vitor Soares , Alexey Brodkin , Joao Pinto , Jose Abreu CC: arcml , lkml , Arnd Bergmann Subject: Re: Misaligned Access Thread-Topic: Misaligned Access Thread-Index: AQHUa8BEl692JJiolkiUiQERHFjjDw== Date: Wed, 21 Nov 2018 19:41:56 +0000 Message-ID: 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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.144.199.106] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +CC lkml, Arnd : subject matter expert=0A= =0A= On 11/21/18 10:06 AM, Vitor Soares wrote:=0A= > I use the follow function to get data from a RX Fifo.=0A= >=0A= >=0A= > static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,=0A= > u8 *bytes, int nbytes)=0A= > {=0A= > readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);=0A= =0A= So the semantics are reading the same fifo register N times, to get the N w= ords,=0A= hence read*s*l is appropriate. That however expects the buffer to be 4 byte= s=0A= aligned, hence your issue. You can't possibly use the reads*b* as we want t= he=0A= =0A= The obvious but crude hack is to use a temp array for readsl and then copy = over=0A= using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is i= ssue is=0A= a driver triggering unaligned access due to the misinteraction of API (driv= er get=0A= an unaligned u8 *) which goes against expectations of io accessor readl (n= eeded=0A= since the register contents are 4 bytes)=0A= =0A= =0A= > if (nbytes & 3) {=0A= > u32 tmp;=0A= >=0A= > readsl(master->regs + RX_TX_DATA_PORT, &tmp, 1);=0A= > memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);=0A= > }=0A= > }=0A= >=0A= >=0A= > and the pointer u8 *bytes is what is unaligned and breaks when inside of = =0A= > realdsl() it does:=0A= >=0A= > *buf++ =3D x;=0A= >=0A= >=0A= > Note that the u8 *bytes pointer is the __u8 *buf of the i2c_msg struct.= =0A= =0A=