Thread (23 messages) 23 messages, 9 authors, 2017-02-02

Re: ibmvtpm byteswapping inconsistency

flat view

From: Michal Suchánek <hidden>
Date: 2017-02-02 11:40:07
Also in: lkml

On Wed, 1 Feb 2017 23:40:33 -0500
Vicky [off-list ref] wrote:
quoted
On Jan 26, 2017, at 5:58 PM, Ashley Lai [off-list ref]
wrote:
=20
Adding Vicky from IBM.
=20
=20
On 01/26/2017 04:05 PM, Jason Gunthorpe wrote: =20
quoted
On Thu, Jan 26, 2017 at 09:22:48PM +0100, Michal Such??nek wrote:
 =20
quoted
This is repeated a few times in the driver so I added memset to
quiet gcc and make behavior deterministic in case the unused
fields get some meaning in the future. =20
Yep, reserved certainly needs to be zeroed.. Can you send a patch?
memset is overkill...
 =20
quoted
However, in tpm_ibmvtpm_send the structure is initialized as
=20
	struct ibmvtpm_crq crq;
        __be64 *word =3D (__be64 *)&crq;
...
        crq.valid =3D (u8)IBMVTPM_VALID_CMD;
        crq.msg =3D (u8)VTPM_TPM_COMMAND;
        crq.len =3D cpu_to_be16(count);
        crq.data =3D cpu_to_be32(ibmvtpm->rtce_dma_handle);
=20
and submitted with
=20
	rc =3D ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
                              be64_to_cpu(word[1]));
meaning it is swapped twice. =20
No idea, Nayna may know.
=20
My guess is that '__be64 *word' should be 'u64 *word'...
=20
Jason =20
 =20
=20
I don=E2=80=99t think we want =E2=80=98word' to be changed back to be of =
type
=E2=80=98u64=E2=80=99.   Please see commit 62dfd912ab3b5405b6fe72d0135c37=
e9648071f1

The word is marked correctly as __be64 in that patch because count and
handle are swapped to BE when saved to it and the whole word is then
swapped again when loaded. If you just load ((u64)IBMVTPM_VALID_CMD <<
56 | ((u64)VTPM_TPM_COMMAND << 48) | ((u64)count << 32) |
ibmvtpm->rtce_dma_handle in a register it works equally well
without any __be and swaps involved.

Note however that __be64 and u64 are all the same to the compiler. It's
just a note for the reader and analysis tools.

Thanks

Michal
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help