Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757548AbbFCQLr (ORCPT ); Wed, 3 Jun 2015 12:11:47 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:37835 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754854AbbFCQLk (ORCPT ); Wed, 3 Jun 2015 12:11:40 -0400 Date: Wed, 3 Jun 2015 10:11:28 -0600 From: Jason Gunthorpe To: Jarkko Sakkinen Cc: peterhuewe@gmx.de, safford@us.ibm.com, Marcel Selhorst , "moderated list:TPM DEVICE DRIVER" , open list , richard.l.maliszewski@intel.com Subject: Re: [PATCH] tpm: introduce struct tpm_buf Message-ID: <20150603161128.GB12073@obsidianresearch.com> References: <1433250262-17200-1-git-send-email-jarkko.sakkinen@linux.intel.com> <20150602181315.GE17776@obsidianresearch.com> <20150603122331.GA3542@jsakkine-mobl1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150603122331.GA3542@jsakkine-mobl1> User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.192 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1746 Lines: 45 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.. Jason -- 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/