Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751898AbdGRLIV (ORCPT ); Tue, 18 Jul 2017 07:08:21 -0400 Received: from mail-db5eur01on0052.outbound.protection.outlook.com ([104.47.2.52]:11904 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751503AbdGRLIQ (ORCPT ); Tue, 18 Jul 2017 07:08:16 -0400 From: Laurentiu Tudor To: Arnd Bergmann CC: gregkh , Stuart Yoder , "devel@driverdev.osuosl.org" , "Linux Kernel Mailing List" , Marc Zyngier , Alexander Graf , Ioana Ciornei , Ruxandra Ioana Radulescu , Bharat Bhushan , Catalin Horghidan , Leo Li , Roy Pledge , Linux ARM Subject: Re: [PATCH 6/7] staging: fsl-mc: rewrite mc command send/receive to work on 32-bits Thread-Topic: [PATCH 6/7] staging: fsl-mc: rewrite mc command send/receive to work on 32-bits Thread-Index: AQHS/wBzPleRJFQYukKH8pTIIt4qC6JYB++AgAALaACAAAl3gIABUXeA Date: Tue, 18 Jul 2017 11:08:10 +0000 Message-ID: <596DEC19.6060301@nxp.com> References: <20170717132646.3020-1-laurentiu.tudor@nxp.com> <20170717132646.3020-7-laurentiu.tudor@nxp.com> <596CC912.3020709@nxp.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0401MB2560;7:qurSnWj9Zv2isdmMk1kTSvpkLbcNR1x8PiM2jqaLN4SV22GkLQviE3PAGJFfpLoswBIDJJd5ZX5HTkEIDoXG6t+m5CyjxSv8OrLps9A6NLB5krijll2RCDvTX2uHyzfKGn3YtzV4yq3RtvmBb4Rek2kXK4lf3N82WVtFMtiGqR20P8kjXvTnP0p5GCFKJdZ2czyxmn8kVanuGvBV8e2l13pqtoP2S8ebUZN3jzn9UwrvJPSgY0bXDHu2xuESU6I29BZLmQiRJeNpP5V1nB3ownZTDcJ58yj4aGCSNSkhf/cqdFJS6ly51mrw1QMk8opAJ+KpPP9PTpW6i+PdwlNQnPokNVtYNoulut3+JCqUPxeF3iKfUS/7uHtTj460lxQbqiCbxihpF1G2B0aJ/QBDn/jho1MToA+EtzknGJegwAxDORDyhCe/HkKRjxELvKBENdA7e/cWEblq5jtfIb5ZNSLdnqCqZRC7LRdxOJGw3SmkPLBCagLPV9eew8ZfV1wUaj46Mt/V7cP1lLu1ZrNm3lVz8PEsjeNWSKBjCPZ/E3xjQ5097xvM3x1WdqUrdwx/C2DMRHydz07361irpNf87B6a9Q6qLG1jTXC+0sUNNv8b35S5SN98tmyi9TToOceO9hThfRhWeygWYHzKZeU/Pl8yaafcHsJtdd21cZK5YQXjUJUdyKJTJ+GzemVWcCLi/6cVqQRS4H2rPkR4wGg2WVLdLY4ZnDqlnWFn0MQT3ZNiRke8DjJJhXimNPtX7oHLWCRbdGnA7AoV7otFa3ZkHOBaJqLysawbDobcUr/f6J8= x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(39840400002)(39450400003)(39410400002)(39850400002)(39400400002)(24454002)(51914003)(377454003)(86362001)(6246003)(99286003)(6486002)(4326008)(229853002)(3660700001)(66066001)(39060400002)(305945005)(53936002)(189998001)(7736002)(3280700002)(5660300001)(33656002)(59896002)(76176999)(54356999)(87266999)(2900100001)(65816999)(50986999)(93886004)(110136004)(38730400002)(14454004)(6916009)(2950100002)(36756003)(6506006)(81166006)(102836003)(6116002)(8676002)(53546010)(8936002)(3846002)(80316001)(6512007)(5250100002)(25786009)(6436002)(54906002)(478600001)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2560;H:VI1PR0401MB1856.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:ovrnspm;PTR:InfoNoRecords;LANG:en; x-ms-office365-filtering-correlation-id: a4066c8a-11f3-4476-a1f0-08d4cdcd46f7 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR0401MB2560; x-ms-traffictypediagnostic: VI1PR0401MB2560: x-exchange-antispam-report-test: UriScan:(236129657087228)(185117386973197)(48057245064654)(275809806118684)(247924648384137); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(2017060910075)(10201501046)(100000703101)(100105400095)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0401MB2560;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0401MB2560; x-forefront-prvs: 037291602B spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <23EC69F9CB698548B9E6C1CB685DC776@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jul 2017 11:08:10.6987 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2560 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id v6IB8WhJ027826 Content-Length: 4278 Lines: 108 On 07/17/2017 06:00 PM, Arnd Bergmann wrote: > On Mon, Jul 17, 2017 at 4:27 PM, Laurentiu Tudor > wrote: >> Hi Arnd, >> >> On 07/17/2017 04:45 PM, Arnd Bergmann wrote: >>> On Mon, Jul 17, 2017 at 3:26 PM, wrote: >>>> From: Laurentiu Tudor >>>> >>>> Split the 64-bit accesses in 32-bit accesses because there's no real >>>> constrain in MC to do only atomic 64-bit. There's only one place >>>> where ordering is important: when writing the MC command header the >>>> first 32-bit part of the header must be written last. >>>> We do this switch in order to allow compiling the driver on 32-bit. >>>> >>>> Signed-off-by: Laurentiu Tudor >>>> --- >>>> drivers/staging/fsl-mc/bus/mc-sys.c | 31 ++++++++++++------------------- >>>> 1 file changed, 12 insertions(+), 19 deletions(-) >>>> >>>> diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c >>>> index 195d9f3..dd2828e 100644 >>>> --- a/drivers/staging/fsl-mc/bus/mc-sys.c >>>> +++ b/drivers/staging/fsl-mc/bus/mc-sys.c >>>> @@ -124,14 +124,15 @@ static inline void mc_write_command(struct mc_command __iomem *portal, >>>> { >>>> int i; >>>> >>>> - /* copy command parameters into the portal */ >>>> - for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) >>>> - __raw_writeq(cmd->params[i], &portal->params[i]); >>>> - /* ensure command params are committed before submitting it */ >>>> - wmb(); >>>> - >>>> - /* submit the command by writing the header */ >>>> - __raw_writeq(cmd->header, &portal->header); >>>> + /* >>>> + * copy command parameters into the portal. Final write >>>> + * triggers the submission of the command. >>>> + */ >>>> + for (i = sizeof(struct mc_command) / sizeof(u32) - 1; i >= 0; i--) { >>>> + __raw_writel(((u32 *)cmd)[i], &((u32 *)portal)[i]); >>>> + /* ensure command params are committed before submitting it */ >>>> + wmb(); >>>> + } >>>> } >>> >>> What is the byte order requirement on this buffer? >> >> Endianness is handled by the callers so this function must leave >> the binary blob intact. > > Got it, the endianess looks correct indeed. > >>> If this is a byte string >>> rather than individual registers, you should probably just use >>> memcpy_toio() >> >> It's a header followed by an opaque command. The protocol for queueing a >> command says that the first 32-bit half of the header must be written >> last, this triggering the command handling in the MC. > > Strictly speaking the __raw_writel() won't guarantee that the > data is written as a single word, the compiler might decide to > split it up into byte-sized writes if it believes the destination pointer > is unaligned and the CPU has no efficient writes. > > I think this cannot happen on arm or powerpc, as we go through > inline assembly for the store, but it's not completely portable. Should i worry about portability? Slim changes that this driver will ever run on anything else other than ARM & ARM64. My current goal was just to make it compile on other arches. > Before your patch, both the compiler and the CPU could also > reorder the stores in theory (but normally won't), but the wmb() > will prevent that now. Ok, thanks for the info. >>> but if these are separate registers, then using the >>> __raw_* accessors is still wrong, at least on kernels that have a >>> different byteorder from the hardware. >> >> As mentioned above, endianness is handled by the caller. This function >> takes raw data and must leave it unchanged. >> >>> Also, are you sure that adding those six extra barriers has no >>> performance impact? >> >> This is a slow interface used in slow paths, so i don't think those >> extra barriers will have any performance impact. > > Ok. > > One other problem remains: most developers looking at this > code like Robin and me will immediately think there might be > an endianess bug here. As this is a slow path, how about > using an explicit conversion using > > writeq(le64_to_cpup(buffer), pointer); Sure, sounds perfect. I'll do that in the next respin. --- Thanks & Best Regards, Laurentiu