Re: ibmvtpm byteswapping inconsistency
flat view
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: 2017-01-28 04:29:50
Also in:
lkml
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.