linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Jason Gunthorpe
	<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Cc: Peter Huewe <peterhuewe-Mmb7MZpHnFY@public.gmane.org>,
	Ashley Lai <ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org>,
	Marcel Selhorst <tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org>,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	josh.triplett-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	jason.gunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org
Subject: Re: [PATCH v1 3/3] tpm: fix multiple race conditions in tpm_ppi.c
Date: Thu, 23 Oct 2014 10:30:19 +0300	[thread overview]
Message-ID: <20141023073019.GB5188@intel.com> (raw)
In-Reply-To: <20141022172646.GD12775-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>

Thanks for the excellent review comments. I'll do another spin an try to
incorporate most them.

/Jarkko

On Wed, Oct 22, 2014 at 11:26:46AM -0600, Jason Gunthorpe wrote:
> On Wed, Oct 22, 2014 at 07:23:56PM +0300, Jarkko Sakkinen wrote:
> > Traversal of the ACPI device tree was not done right. It should lookup
> > PPI only under the ACPI device that it is associated. Otherwise, it could
> > match to a wrong PPI interface if there are two TPM devices in the device
> > tree.
> > 
> > Removed global ACPI handle and version string from tpm_ppi.c as this
> > is racy. Instead they should be associated with the chip.
> > 
> > Moved code just a tiny bit towards two-phase allocation to implement
> > fix for the PPI race conditions.
> 
> Not this version..
> 
> > Added missing copyright platter to tpm_ppi.c.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> 
> Reviewed-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
> 
> I like this one the most of the three I've seen :)
> 
> Did you also look in tpm_acpi.c to see if it needs to use
> acpi_dev_handle somehow too?
> 
> > +	union acpi_object *obj;
> > +	struct kobject *parent = &chip->dev->kobj;
> 
> Nit, this variable is only used once, it would be clearer to inline
> 
> > +	/* Cache PPI version string. */
> > +	obj = acpi_evaluate_dsm_typed(chip->acpi_dev_handle, tpm_ppi_uuid,
> > +				      TPM_PPI_REVISION_ID, TPM_PPI_FN_VERSION,
> > +				      NULL, ACPI_TYPE_STRING);
> > +       if (obj) {
> > +               strlcpy(chip->ppi_version, obj->string.pointer,
> > +                       PPI_VERSION_LEN + 1);
> > +               ACPI_FREE(obj);
> > +       } else
> > +               return -ENOMEM;
> > +
> > +       return chip->acpi_dev_handle ?
> > +               sysfs_create_group(parent, &ppi_attr_grp) : 0;
> 
> The above sequence can just be:
> 
> if (!obj)
>    return -ENOMEM;
> 
> strlcpy(chip->ppi_version, obj->string.pointer, sizeof(chip->ppi_version));
> ACPI_FREE(obj);
> 
> return sysfs_create_group(&chip->dev->kobj, &ppi_attr_grp);
> 
> Which is more idiomatic. Also remove TPM_PPI_VERSION_LEN, sizeof is better.
> 
> I know nothing about acpi, but is ENOMEM the right code? I would think
> acpi_evalute_dsm_typed would also fail if tpm_ppi_uuid is not found??
> 
> > +	return chip->acpi_dev_handle ?
> > +		sysfs_create_group(parent, &ppi_attr_grp) : 0;
> 
> dev_handle is already checked to be non 0
> 
> > +void tpm_remove_ppi(struct tpm_chip *chip)
> > +	struct kobject *parent = &chip->dev->kobj;
> 
> Also used only once
> 
> Jason

      parent reply	other threads:[~2014-10-23  7:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 16:23 [PATCH v1 0/3] tpm: prepare for TPM2 Jarkko Sakkinen
     [not found] ` <1413995036-22497-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-22 16:23   ` [PATCH v1 1/3] tpm: merge duplicate transmit_cmd() functions Jarkko Sakkinen
     [not found]     ` <1413995036-22497-2-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-22 16:37       ` Jason Gunthorpe
2014-10-22 16:34   ` Aw: [PATCH v1 0/3] tpm: prepare for TPM2 Peter Huewe
2014-10-22 16:23 ` [PATCH v1 2/3] tpm: two-phase chip management functions Jarkko Sakkinen
     [not found]   ` <1413995036-22497-3-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-22 17:16     ` Jason Gunthorpe
     [not found]       ` <20141022171603.GC12775-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-23  7:22         ` Jarkko Sakkinen
2014-10-22 16:23 ` [PATCH v1 3/3] tpm: fix multiple race conditions in tpm_ppi.c Jarkko Sakkinen
     [not found]   ` <1413995036-22497-4-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-22 17:26     ` Jason Gunthorpe
     [not found]       ` <20141022172646.GD12775-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-23  7:30         ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141023073019.GB5188@intel.com \
    --to=jarkko.sakkinen-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org \
    --cc=christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jason.gunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=josh.triplett-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=peterhuewe-Mmb7MZpHnFY@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).