Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1157838
| From | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] tpm: introduce struct tpm_buf |
| Date | 2015-06-03 18:50 +0200 |
| Message-ID | <pxk1B-6Pj-17@gated-at.bofh.it> (permalink) |
| References | <pwU78-23B-11@gated-at.bofh.it> <pwYX7-KM-19@gated-at.bofh.it> <pxg7E-14D-19@gated-at.bofh.it> <pxjyz-6gc-17@gated-at.bofh.it> |
| Organization | Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo |
On Wed, Jun 03, 2015 at 10:11:28AM -0600, Jason Gunthorpe wrote:
> On Wed, Jun 03, 2015 at 03:23:31PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Jun 02, 2015 at 12:13:15PM -0600, Jason Gunthorpe wrote:
> > > On Tue, Jun 02, 2015 at 04:04:22PM +0300, Jarkko Sakkinen wrote:
> > > > +/* A string buffer type for constructing TPM commands. This is based on the
> > > > + * code in security/keys/trusted.h.
> > > > + */
> > > > +
> > > > +#define TPM_BUF_SIZE 512
> > > > +
> > > > +struct tpm_buf {
> > > > + u8 data[TPM_BUF_SIZE];
> > > This should be u32 or u64 to guarentee correct alignment for the
> > > casting.
> >
> > Good catch. The functions where this might cause trouble are *_length()
> > and *_tag().
> >
> > In other places misalignment should not cause any regressions since data
> > is not directly assigned to the buffer with pointer casting.
> >
> > I would prefer to fix by changing *_length() and *_tag() to copy the
> > value to a local variable and return that. It's a fail safe way and here
> > the performance is not an issue.
>
> I would change the type, that is very simple and will improve
> performance of the memcpy as well.
>
> It actually isn't a problem for the casts to tpm_input_header - any
> structure marked __packed will cause the compiler to assume that the
> entire structure is unaligned and code gen accordingly, so the cast
> will always work, but on x86 it will be more efficient if the array
> is aligned.
>
> Ideally we could change to something like:
> __attribute__((packed,aligned(4)))
>
> Instead of __packed which will help the compiler minimize unaligned
> load instructions..
I realized basically the same what you said here when I refined the
patch (read this email after sending v2) :) I decided that align to 8
bytes.
I don't think the packed attribute is needed here because now I cast
the beginning to tpm_input_header, which is a packed struct.
> Jason
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: [PATCH] tpm: introduce struct tpm_buf Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2015-06-03 14:40 +0200
Re: [PATCH] tpm: introduce struct tpm_buf Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2015-06-03 18:20 +0200
Re: [PATCH] tpm: introduce struct tpm_buf Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2015-06-03 18:50 +0200
Re: [PATCH] tpm: introduce struct tpm_buf Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2015-06-03 19:10 +0200
Re: [PATCH] tpm: introduce struct tpm_buf Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2015-06-03 18:50 +0200
csiph-web