Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1528775

Re: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access.

From Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Newsgroups linux.kernel
Subject Re: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access.
Date 2016-11-23 22:10 +0100
Message-ID <sGMXL-1Cc-1@gated-at.bofh.it> (permalink)
References <sGCOK-3Ax-21@gated-at.bofh.it> <sGJ3Q-7mu-27@gated-at.bofh.it> <sGMO5-1jI-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Nov 23, 2016 at 08:56:25PM +0000, Winkler, Tomas wrote:
> > On Wed, Nov 23, 2016 at 01:04:54PM +0200, Tomas Winkler wrote:
> > > Use get_unaligned_be32 as b32_to_cpu doesn't work correctly on all
> > > platforms for unaligned access.
> > >
> > > The fix doesn't cover all the cases as also some cast structures have
> > > members on unaligned addresses.
> > 
> > I think this is a good idea..
> > 
> > > @@ -353,8 +353,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8
> > *buf, size_t bufsiz,
> > >  	if (bufsiz > TPM_BUFSIZE)
> > >  		bufsiz = TPM_BUFSIZE;
> > >
> > > -	count = be32_to_cpu(*((__be32 *) (buf + 2)));
> > > -	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
> > > +	count = get_unaligned_be32(buf + 2);
> > > +	ordinal = get_unaligned_be32(buf + 6);
> >
> > But lets fix this better and get rid of the constants too...
> 
> >  const tpm_input_header *hdr = buf;
> >  count = be32_to_cpu(hdr->length);
> >  ordinal = be32_to_cpu(hdr->ordinal);
> > 
> > Compiler will take care of unaligned for __packed.
> 
> Yes, compiler takes care at performance penalty but probably we
> don't care about that much,

Hmm? get_unaligned_be32 boils down to the same __packed construct.

As is today we must be hitting the in-kernel unaligned access trap (eg
on ARM) which is *very* expensive so this is a very worthwhile fix ...

Jason

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] tpm: use get_unaligned_be32 unaligned buffer access. Tomas Winkler <tomas.winkler@intel.com> - 2016-11-23 11:20 +0100
  Re: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access. Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-11-23 18:00 +0100
    RE: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access. "Winkler, Tomas" <tomas.winkler@intel.com> - 2016-11-23 22:00 +0100
      Re: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access. Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-11-23 22:10 +0100
  Re: [PATCH] tpm: use get_unaligned_be32 unaligned buffer access. Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-11-24 14:40 +0100

csiph-web