From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751235AbdA0UoL (ORCPT ); Fri, 27 Jan 2017 15:44:11 -0500 Received: from gate.crashing.org ([63.228.1.57]:55973 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751144AbdA0UnB (ORCPT ); Fri, 27 Jan 2017 15:43:01 -0500 Message-ID: <1485547137.2980.94.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 06:58:57 +1100 In-Reply-To: References: <20170126212248.3f3e9103@kitsune.suse.cz> <1485481819.2980.82.camel@kernel.crashing.org> 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: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2017-01-27 at 10:02 -0800, Tyrel Datwyler wrote: > > The problem is that we are packing an in-memory structure into 2 > > registers and it's expected that this structure is laid out in the > > registers as if it had been loaded by a BE CPU. > > This is only the case if the cpu is BE. If the cpu is LE, regardless of > the fact that our in memory structure is laid out BE, when we break it > into 2 words each of those words needs to be loaded LE. That doesn't make sense and doesn't match the code... The structure needs to always have the same in-register layout regardless of the endianness of the CPU, especially since the underlying hypervisor will most likely be BE :-) Thta's why the code does a be64_to_cpu() when loading it, this in effect performs a "BE" load, which on a BE CPU is just a normal load and on LE is a swap to compensate for the CPU loading it the "wrong way around". Cheers, Ben.