Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752621AbbHDSLp (ORCPT ); Tue, 4 Aug 2015 14:11:45 -0400 Received: from mail-by2on0131.outbound.protection.outlook.com ([207.46.100.131]:40033 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751710AbbHDSLn (ORCPT ); Tue, 4 Aug 2015 14:11:43 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; arm.linux.org.uk; dkim=none (message not signed) header.d=none; Subject: Re: [BUG?] crypto: caam: little/big endianness on ARM vs PPC To: Russell King - ARM Linux , Jon Nettleton References: <20150615155907.GC7947@pengutronix.de> <20150615171848.GP7557@n2100.arm.linux.org.uk> CC: Steffen Trumtrar , Herbert Xu , , Ruchika Gupta , , Sascha Hauer , , Scott Wood From: =?UTF-8?Q?Horia_Geant=c4=83?= Message-ID: <55C0FCA6.6070806@freescale.com> Date: Tue, 4 Aug 2015 20:55:50 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <20150615171848.GP7557@n2100.arm.linux.org.uk> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD004;1:qMx0jEsu1ylzrfbUJ4RDSY9f0BkjWQ/fUtGAqWthHcm5sQIBYJ/37p+gbAhaIap/lHGv3v5aEhIy/Sbx3vZR3pwkSKs4KI05vDFBoLuv9KM0+ku0aUBFdZXB5xIbXxvAnBH+oXhM7ewaEmcaUscwF526lzPv/T1UYP27esUTJXs2Di3J4ZtID7FtNM/8wd3IscUAFIg+JwNKxJfDiShymtsLlu6AuV14dpDkFMPtStQBn8fm2YeALqyyS5MvWDcnAjADs5b95THqZlsq6Ktt7cGY/gglTdyw38LWpk2TJ9Q= X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(479174004)(377454003)(24454002)(199003)(189002)(164054003)(36756003)(107886002)(59896002)(65806001)(5001860100001)(80316001)(65956001)(64706001)(4001350100001)(6806004)(47776003)(64126003)(46102003)(62966003)(120886001)(5005550100001)(77156002)(104016003)(92566002)(86362001)(81156007)(2950100001)(69596002)(65816999)(33656002)(68736005)(4001540100001)(77096005)(105606002)(87936001)(189998001)(106466001)(50986999)(54356999)(83506001)(87266999)(85426001)(5001770100001)(50466002)(5001830100001)(76176999)(5001960100002)(97736004)(23676002)(4001430100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB572;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB572;2:dtJ1tovWu8xrLGar0em0QM/s0HnMQ1Uqcgs3YkJz12ZPCFYk6oRnuH/dMalgZDiKNKrET83a8/dIeuaTuaPssnmN0eXqbcGSerxCqOb3SeeVHiuyp4lSUtop43nKQxaxUOmnoVEBSLezimU9MLYuetcYmptKfwdP5duxZbdCj4U=;3:5J6b0obDFvjWp+w3KMozziRsmBldsXARwyvG8LiSE+PZdwNpN3SkoT47LOLsY1xdX37fupzJnTlyDvxZs29zR1q1cLtyMpeY0tcyXjwCDEvrt0vWImdxzU25oeYOkmyz0NNe6XYdpk/6cJMUrLfo8U/PHCV7e4b9oEPaxuHyH3UOqn+9MSQ1Zz1WaG3WT/ffrH/AJPAdJRfFjXHNoMUleEtfSWBR+rwTTjGR7MaKQvU=;25:/Fxo0mmy2/d47SwRs85WkaazFaK/VfK88Uj6rzs3AUh106FGNy5Ij026SOMdxrnOxDbIuPhX7ebo+ezZ/OsvVOPc43+ZyDa4C0TUK/q6q6soZ9UVgSqXASaNkgn2ajsk96HuZDXec2WQMi+MCuZLcRhCoE4r5PyaehjZSwVaomGdkZzdVGkfvwq1T4W8+B1E1M0Z0FFThL9/FefO5D3bDxRZTPT2jPxCu2Hqebl9+54dhtW2P31dsmhsPPzrsj07oPOGnV6mPl/bOB4qGbSqww== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB572; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB572;20:haXHZEOWpbS3A7uWUfaCa0jZ4QeedoVhAyRttCSfFD2hFcbhhOcVwv6zqNBCJNE49zYn13Osxa3cPmPBEASwvsXLzG6+DgriQzVkju6IHf18cn56ZS/4eLBCp33+Kx7FcBkYthrgqFjW9aG2IM384fIFHIPDZjFCD7qQZBk7+zSxw1dsyD8xhSPgxzmf5dhbYGNCmThe7xbFCkTpZ8tdwKTpd1ByHhHbVzePoBSCnyTnF9phcl9YEtZcycBySYobLDN+EeEQL7WgxSPmLbVwh8Hv3Nn80dD7hAwm5Afbd0D9q3k8q939TyKa8BUN2/mlLrtwjE5U4puKTevgB43To2bisd4KS1vxtr+fjzCeR1w=;4:Ij8FOv5la8HRj9QMF7z4Lp7nICkmjmDyfUlco2QAIjgOacdY2M6BPi12W4MQKoXOCttEsDoQY5UZLxbih41hFQlsWcsQ3/gy1SsDnGzY/o6mRACNZUdRNjs5u6Jq02nRLmkt/Yz5YR/teR5QW+QCsCo8gkwN8XQa28lMR7H9qGPUm2qddRA88l6JlCD6L49KFc75YU9S+9d/t6ep+YrI4H1g1xBSAHNoh0LQ94vxWEYopHMaWxFWaulA0ZcRU269W/PcbHtrZHDz/QNJdXkzHBgxiZHQ5jk401x586RKDI0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BY2PR03MB572;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB572; X-Forefront-PRVS: 0658BAF71F X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCW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FBbFZkakJsbzV1akw4cloyVHV5?= =?utf-8?B?WHBIU0swaUozaXZFdFl4VElXWTNhR0QrNXNCdFQvNm0xUnQ1c2p1TmNkMFFI?= =?utf-8?Q?Lq0TXG/HJcisEXkL+F0H24qBxVjbElo?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB572;5:3hQbIFE5jndszp/e7FLttR5RQ0JnpfuqcewoN3zxEFE5P7N+FU4/VRZpZHJ7FUyrfeL1lu6JCt4WFfeChcyo3p1COJ81BC/FC0TpsHB0UqnDWh/3gqiBNnYiFvuzgA3O0xUARnPpKwU2kHa3NwtH0w==;24:+l9HGyt4nvcnEWPS6gmw141PPNeyAQC0ouPd9L3zZjZRVYFqftgHTuDSPsYL0qlBb4PA/iKODjyVSclmzMPqgDe6dnfoY+YKVFi+mA/TlFA=;20:7AfJAJnb7Qd6hKo1dRabofm1zF+3K43FEYnJq1a30VqcLBeV1R1EBIhfTIjRPHFc3nhqzDRgi5wotY7fm12hUg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2015 17:55:58.4368 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB572 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3733 Lines: 88 On 6/15/2015 8:18 PM, Russell King - ARM Linux wrote: > On Mon, Jun 15, 2015 at 06:33:17PM +0200, Jon Nettleton wrote: >> Funny enough I tackled this problem over the weekend as well. My >> approach was to switch the driver over to use the *_relaxed() io >> functions and then special case the bits missing from the various >> ARCHs. Basically adding setbits32 and clrbits32 for !PPC >> architectures and letting PPC and ARM share a writeq/readq set of >> functions. I left the existing LITTLE_ENDIAN special case until I >> could verify if it was needed, or had been tested. > > I'll follow up here with what I've mentioned elsewhere, and some further > thoughts. > > I think this shows the dangers of using struct { } to define register > offsets. Let's start here: > > /* > * caam_job_ring - direct job ring setup > * 1-4 possible per instantiation, base + 1000/2000/3000/4000 > * Padded out to 0x1000 > */ > struct caam_job_ring { > /* Input ring */ > u64 inpring_base; /* IRBAx - Input desc ring baseaddr */ > u32 rsvd1; > > Apparently, this is a CPU-endian 64-bit value (it's not defined using > le64 or be64 which would "fix" it's endian.) The IP in question (CAAM) has different endianness, depending on the integration on the SoC. Would it be ok to #define a sec64 type which would translate either to be64 or le64? > > The second question, which comes up in light of the breakage that's > being reported is: is this really a 64-bit register, or is it a pair > of 32-bit registers side-by-side? > > The documentation I'm looking at doesn't document the register at > base + 0x1000, but documents the one at base + 0x1004, and the one > at 0x1004 is given the name "IRBAR0_LS", which presumably stands > for "input ring base address register 0, least significant". > > As the code originally stood for PPC, IRBAR0_LS is also at 0x1004, > but appears to be big endian. > > On ARM, IRBAR0_LS appears at the same address, but is little endian. In some cases, CAAM endianness does not match CPU endianness (for e.g. i.MX). We're talking about default endianness here, both for CAAM and for CPU - no CONFIG_CPU_{BIG,LITTLE}_ENDIAN. ARCH CPU CAAM SoC PPC BIG BIG P4080, T4240 etc. ARM LITTLE LITTLE LS1021A, LS2085A etc. ARM LITTLE BIG i.MX6, i.MX7, LS1043A > This is *not* a 64-bit register at all, but is a pair of 32-bit > registers side by side. Moreover, readq() should not be used - no > amount of arch mangling could ever produce a sane readq() which > coped with this. > > So, the CAAM code is buggy in this regard: using readq() here when > endian-portability is required is wrong. It's got to be two 32-bit > reads or two 32-bit writes in the appropriate endian. > > Also, note that there's a big difference between __raw_readl() and > readl_relaxed(). readl_relaxed() is always little-endian. __raw_readl() > is god-knows-what-the-archtecture-decides endian. Switching PPC > drivers from __raw_readl() to readl_relaxed() is really not a good > idea unless someone from the PPC camp reviews and tests the code. > > So, what I'd suggest is just fixing rd_reg64() and wr_reg64() to do > the right thing: keeping the two 32-bit words in the same order > irrespective of the endian-ness, and staying with the __raw_* > accessors until PPC people can look at this. Agree that the I/O accessors need to be revisited. Unfortunately, the proposed change does not work for LE CAAM (LS1021A). I'll send a fix. Thanks, Horia -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/