From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751161AbdA1E3u (ORCPT ); Fri, 27 Jan 2017 23:29:50 -0500 Received: from gate.crashing.org ([63.228.1.57]:60462 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750838AbdA1E3l (ORCPT ); Fri, 27 Jan 2017 23:29:41 -0500 Message-ID: <1485577703.2980.104.camel@kernel.crashing.org> Subject: Re: ibmvtpm byteswapping inconsistency From: Benjamin Herrenschmidt To: Tyrel Datwyler , Michal =?ISO-8859-1?Q?Such=E1nek?= , Ashley Lai , Paul Mackerras , Michael Ellerman , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , tpmdd-devel@lists.sourceforge.net, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Sat, 28 Jan 2017 15:28:23 +1100 In-Reply-To: <48dc15a0-eaba-29e4-f39e-500177f98638@linux.vnet.ibm.com> References: <20170126212248.3f3e9103@kitsune.suse.cz> <1485481819.2980.82.camel@kernel.crashing.org> <1485547137.2980.94.camel@kernel.crashing.org> <48dc15a0-eaba-29e4-f39e-500177f98638@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.4 (3.22.4-2.fc25) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2017-01-27 at 12:32 -0800, Tyrel Datwyler wrote: > Its possible being the end of the week I'm just a little dense, but > wouldn't be64_to_cpu() imply that we are byte-swapping something that is > already, or supposedly already, in BE format to cpu endianness? Which on > a BE cpu I would expect a no-op, and on a LE cpu the 64bit word to have > been swapped from BE --> LE? It's in BE format in memory. In LE mode, loading it into a register will get it the wrong way around, thus we have to swap it again. Once in a register it has no "endianness" per-se, what matters is that the act of loading from memory to a register would have loaded it the wrong way around in LE. > In my eyes the code does seem to support what I've argued. The same > thing is done in the scsi VIO drivers. The CRQ structure is laid out and > annotated BE. We use cpu_to_be() calls to load any non 8bit field. > Finally, each word is swapped to cpu endian when we hand it off for the > hcall. > > from ibmvfc_send_event(): > >         __be64 *crq_as_u64 = (__be64 *) &evt->crq; > >         <..snip..> > >         if ((rc = ibmvfc_send_crq(vhost, be64_to_cpu(crq_as_u64[0]), >                                   be64_to_cpu(crq_as_u64[1])))) { > > Again, maybe I'm missing something.