All of lore.kernel.org
 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>,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [tpmdd-devel] [PATCH v2 2/7] tpm: two-phase chip management functions
Date: Wed, 8 Oct 2014 01:28:14 +0300	[thread overview]
Message-ID: <20141007222814.GA7262@intel.com> (raw)
In-Reply-To: <20141007175017.GA10432-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>

On Tue, Oct 07, 2014 at 11:50:17AM -0600, Jason Gunthorpe wrote:
> On Tue, Oct 07, 2014 at 08:01:12PM +0300, Jarkko Sakkinen wrote:
> > Added tpm_chip_alloc() and tpm_chip_register() where tpm_chip_alloc()
> > reserves memory resources and tpm_chip_register() initializes the
> > device driver. This way it is possible to alter struct tpm_chip
> > attributes before passing it to tpm_chip_register().
> 
> This looks broadly reasonable to me
> 
> Please add a note to the commit that this is known to still have
> problems with resource reference counting, but they are less severe
> than what existed before, and this is only an interm step.
> 
> > +/**
> > + * tpm_chip_alloc() - allocate a new struct tpm_chip instance
> 
> This is using devm so it should be called 'tpmm_chip_alloc()' for
> clarity
> 
> 
> I know that was there before, but it sure is racy:
> 
> > +	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
> [..]
> > +	set_bit(chip->dev_num, dev_mask);
> 
> Someday it should use IDR.
> 
> 
> > @@ -896,18 +872,7 @@ void tpm_remove_hardware(struct device *dev)
> >  		return;
> >  	}
> >  
> > -	spin_lock(&driver_lock);
> > -	list_del_rcu(&chip->list);
> > -	spin_unlock(&driver_lock);
> > -	synchronize_rcu();
> > -
> > -	tpm_dev_del_device(chip);
> > -	tpm_sysfs_del_device(chip);
> > -	tpm_remove_ppi(&dev->kobj);
> > -	tpm_bios_log_teardown(chip->bios_dir);
> > -
> > -	/* write it this way to be explicit (chip->dev == dev) */
> > -	put_device(chip->dev);
> > +	tpm_chip_unregister(chip);
> >  }
> >  EXPORT_SYMBOL_GPL(tpm_remove_hardware);
> 
> This can move to tpm-chip too, same with tpm_register_hardware
> 
> > @@ -714,15 +709,10 @@ static int tpm_tis_i2c_remove(struct i2c_client *client)
> >  	struct tpm_chip *chip = tpm_dev.chip;
> >  	release_locality(chip, chip->vendor.locality, 1);
> >  
> > -	/* close file handles */
> > -	tpm_dev_vendor_release(chip);
> > -
> >  	/* remove hardware */
> >  	tpm_remove_hardware(chip->dev);
> 
> Wrong ordering here, tpm_remove_hardware should always be first -
> drivers should not tear down internal state before calling it, so
> release_locality should be second.
> 
> Noting that since we use devm the kfree will not happen until
> remove returns, so the chip pointer is still valid.

Should I fix this ordering? I was thinking to focus putting proper
patterns in place only in tpm_tis and tpm_crb because they are the
that I'm able to test easily and then they can work as guideline for
other drivers.

> >  	/* reset these pointers, otherwise we oops */
> > -	chip->dev->release = NULL;
> > -	chip->release = NULL;
> >  	tpm_dev.client = NULL;
> 
> The comment can go too
> 
> Note: tpm_dev should be driver private data, but that is not your
> problem..
> 
> Did you test compile all the drivers? One of my git commits on github
> has some hackery to make that possible on x86.
> 
> Jason

/Jarkko

WARNING: multiple messages have this Message-ID (diff)
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Peter Huewe <peterhuewe@gmx.de>,
	Ashley Lai <ashley@ashleylai.com>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	linux-api@vger.kernel.org, tpmdd-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [tpmdd-devel] [PATCH v2 2/7] tpm: two-phase chip management functions
Date: Wed, 8 Oct 2014 01:28:14 +0300	[thread overview]
Message-ID: <20141007222814.GA7262@intel.com> (raw)
In-Reply-To: <20141007175017.GA10432@obsidianresearch.com>

On Tue, Oct 07, 2014 at 11:50:17AM -0600, Jason Gunthorpe wrote:
> On Tue, Oct 07, 2014 at 08:01:12PM +0300, Jarkko Sakkinen wrote:
> > Added tpm_chip_alloc() and tpm_chip_register() where tpm_chip_alloc()
> > reserves memory resources and tpm_chip_register() initializes the
> > device driver. This way it is possible to alter struct tpm_chip
> > attributes before passing it to tpm_chip_register().
> 
> This looks broadly reasonable to me
> 
> Please add a note to the commit that this is known to still have
> problems with resource reference counting, but they are less severe
> than what existed before, and this is only an interm step.
> 
> > +/**
> > + * tpm_chip_alloc() - allocate a new struct tpm_chip instance
> 
> This is using devm so it should be called 'tpmm_chip_alloc()' for
> clarity
> 
> 
> I know that was there before, but it sure is racy:
> 
> > +	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
> [..]
> > +	set_bit(chip->dev_num, dev_mask);
> 
> Someday it should use IDR.
> 
> 
> > @@ -896,18 +872,7 @@ void tpm_remove_hardware(struct device *dev)
> >  		return;
> >  	}
> >  
> > -	spin_lock(&driver_lock);
> > -	list_del_rcu(&chip->list);
> > -	spin_unlock(&driver_lock);
> > -	synchronize_rcu();
> > -
> > -	tpm_dev_del_device(chip);
> > -	tpm_sysfs_del_device(chip);
> > -	tpm_remove_ppi(&dev->kobj);
> > -	tpm_bios_log_teardown(chip->bios_dir);
> > -
> > -	/* write it this way to be explicit (chip->dev == dev) */
> > -	put_device(chip->dev);
> > +	tpm_chip_unregister(chip);
> >  }
> >  EXPORT_SYMBOL_GPL(tpm_remove_hardware);
> 
> This can move to tpm-chip too, same with tpm_register_hardware
> 
> > @@ -714,15 +709,10 @@ static int tpm_tis_i2c_remove(struct i2c_client *client)
> >  	struct tpm_chip *chip = tpm_dev.chip;
> >  	release_locality(chip, chip->vendor.locality, 1);
> >  
> > -	/* close file handles */
> > -	tpm_dev_vendor_release(chip);
> > -
> >  	/* remove hardware */
> >  	tpm_remove_hardware(chip->dev);
> 
> Wrong ordering here, tpm_remove_hardware should always be first -
> drivers should not tear down internal state before calling it, so
> release_locality should be second.
> 
> Noting that since we use devm the kfree will not happen until
> remove returns, so the chip pointer is still valid.

Should I fix this ordering? I was thinking to focus putting proper
patterns in place only in tpm_tis and tpm_crb because they are the
that I'm able to test easily and then they can work as guideline for
other drivers.

> >  	/* reset these pointers, otherwise we oops */
> > -	chip->dev->release = NULL;
> > -	chip->release = NULL;
> >  	tpm_dev.client = NULL;
> 
> The comment can go too
> 
> Note: tpm_dev should be driver private data, but that is not your
> problem..
> 
> Did you test compile all the drivers? One of my git commits on github
> has some hackery to make that possible on x86.
> 
> Jason

/Jarkko

  parent reply	other threads:[~2014-10-07 22:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 17:01 [PATCH v2 0/7] TPM 2.0 support Jarkko Sakkinen
2014-10-07 17:01 ` Jarkko Sakkinen
2014-10-07 17:01 ` [PATCH v2 1/7] tpm: merge duplicate transmit_cmd() functions Jarkko Sakkinen
2014-10-07 17:01 ` [PATCH v2 3/7] tpm: clean up tpm_tis driver life-cycle Jarkko Sakkinen
     [not found]   ` <1412701277-27794-4-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-07 17:53     ` [tpmdd-devel] " Jason Gunthorpe
2014-10-07 17:53       ` Jason Gunthorpe
2014-10-07 17:01 ` [PATCH v2 4/7] tpm: TPM 2.0 commands Jarkko Sakkinen
2014-10-07 17:01 ` [PATCH v2 5/7] tpm: TPM 2.0 sysfs attributes Jarkko Sakkinen
2014-10-07 17:01 ` [PATCH v2 6/7] tpm: TPM 2.0 CRB Interface Jarkko Sakkinen
     [not found]   ` <1412701277-27794-7-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-07 17:54     ` [tpmdd-devel] " Jason Gunthorpe
2014-10-07 17:54       ` Jason Gunthorpe
     [not found] ` <1412701277-27794-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-10-07 17:01   ` [PATCH v2 2/7] tpm: two-phase chip management functions Jarkko Sakkinen
2014-10-07 17:01     ` Jarkko Sakkinen
2014-10-07 17:50     ` [tpmdd-devel] " Jason Gunthorpe
     [not found]       ` <20141007175017.GA10432-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-07 18:04         ` Jarkko Sakkinen
2014-10-07 18:04           ` Jarkko Sakkinen
     [not found]           ` <20141007180417.GA29459-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-07 18:27             ` Jason Gunthorpe
2014-10-07 18:27               ` Jason Gunthorpe
     [not found]               ` <20141007182756.GA10774-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-07 19:15                 ` Jarkko Sakkinen
2014-10-07 19:15                   ` Jarkko Sakkinen
2014-10-07 22:28         ` Jarkko Sakkinen [this message]
2014-10-07 22:28           ` Jarkko Sakkinen
     [not found]           ` <20141007222814.GA7262-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-07 22:34             ` Jason Gunthorpe
2014-10-07 22:34               ` Jason Gunthorpe
     [not found]               ` <20141007223442.GA3014-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-09  9:07                 ` Jarkko Sakkinen
2014-10-09  9:07                   ` Jarkko Sakkinen
2014-10-07 17:01   ` [PATCH v2 7/7] tpm: TPM 2.0 FIFO Interface Jarkko Sakkinen
2014-10-07 17:01     ` Jarkko Sakkinen

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=20141007222814.GA7262@intel.com \
    --to=jarkko.sakkinen-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.