tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Jerry Snitselaar <jsnitsel@redhat.com>
Cc: tpmdd-devel@lists.sourceforge.net,
	linux-security-module@vger.kernel.org, gang.wei@intel.com,
	Peter Huewe <peterhuewe@gmx.de>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] tpm_crb: request and relinquish locality 0
Date: Mon, 13 Mar 2017 13:58:24 +0200	[thread overview]
Message-ID: <20170313115824.el7aoo46hwszrfac@intel.com> (raw)
In-Reply-To: <87tw6ys2dt.fsf@redhat.com>

On Sun, Mar 12, 2017 at 12:47:58PM -0700, Jerry Snitselaar wrote:
> 
> Jarkko Sakkinen @ 2017-03-11 13:02 GMT:
> 
> > Added two new callbacks to struct tpm_class_ops:
> >
> > - request_locality
> > - relinquish_locality
> >
> > These are called before sending and receiving data from the TPM.  We
> > update also tpm_tis_core to use these callbacks. Small modification to
> > request_locality() is done so that it returns -EBUSY instead of locality
> > number when check_locality() fails.
> >
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >  drivers/char/tpm/tpm-interface.c |  9 +++++++++
> >  drivers/char/tpm/tpm_crb.c       | 41 +++++++++++++++++++++++++++++++++++++++-
> >  drivers/char/tpm/tpm_tis_core.c  | 12 ++++--------
> >  include/linux/tpm.h              |  3 ++-
> >  4 files changed, 55 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > index e38c792..9c56581 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -407,6 +407,12 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
> >  	if (chip->dev.parent)
> >  		pm_runtime_get_sync(chip->dev.parent);
> >  
> > +	if (chip->ops->request_locality)  {
> > +		rc = chip->ops->request_locality(chip, 0);
> > +		if (rc)
> > +			goto out;
> > +	}
> > +
> >  	rc = tpm2_prepare_space(chip, space, ordinal, buf);
> >  	if (rc)
> >  		goto out;
> > @@ -466,6 +472,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
> >  	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
> >  
> >  out:
> > +	if (chip->ops->relinquish_locality)
> > +		chip->ops->relinquish_locality(chip, 0, false);
> > +
> >  	if (chip->dev.parent)
> >  		pm_runtime_put_sync(chip->dev.parent);
> >  
> > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> > index 3245618..15b22a0 100644
> > --- a/drivers/char/tpm/tpm_crb.c
> > +++ b/drivers/char/tpm/tpm_crb.c
> > @@ -34,6 +34,15 @@ enum crb_defaults {
> >  	CRB_ACPI_START_INDEX = 1,
> >  };
> >  
> > +enum crb_loc_ctrl {
> > +	CRB_LOC_CTRL_REQUEST_ACCESS	= BIT(0),
> > +	CRB_LOC_CTRL_RELINQUISH		= BIT(1),
> > +};
> > +
> > +enum crb_loc_state {
> > +	CRB_LOC_STATE_LOC_ASSIGNED	= BIT(1),
> > +};
> > +
> >  enum crb_ctrl_req {
> >  	CRB_CTRL_REQ_CMD_READY	= BIT(0),
> >  	CRB_CTRL_REQ_GO_IDLE	= BIT(1),
> > @@ -172,6 +181,35 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
> >  	return 0;
> >  }
> >  
> > +static int crb_request_locality(struct tpm_chip *chip, int loc)
> > +{
> > +	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
> > +
> > +	if (!priv->regs_h)
> > +		return 0;
> > +
> > +	iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
> > +	if (!crb_wait_for_reg_32(&priv->regs_h->loc_state,
> > +				 CRB_LOC_STATE_LOC_ASSIGNED, /* mask */
> > +				 CRB_LOC_STATE_LOC_ASSIGNED, /* value */
> 
> Should this mask and check bit 7 as well (tpmRegValidSts)? The
> table with the definition in the PTP spec says it indicates whether
> all other bits contain valid values, but the text above it doesn't
> discuss the locAssigned and activeLocality bits with respect to
> tpmRegValidSts, so not completely clear.

You are probably right. There's also regression with the resource
manager (in this patch not in RM) that I'll fix. Thaks for reporting
this.

/Jarkko

  reply	other threads:[~2017-03-13 11:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11 13:02 [PATCH v2] tpm_crb: request and relinquish locality 0 Jarkko Sakkinen
     [not found] ` <20170311130216.21419-1-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-03-12 19:47   ` Jerry Snitselaar
2017-03-13 11:58     ` Jarkko Sakkinen [this message]
2017-03-13 16:34   ` Jason Gunthorpe
     [not found]     ` <20170313163452.GD22997-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-03-13 20:12       ` Jarkko Sakkinen
     [not found]         ` <20170313201235.tvcyugdh7awqfrfq-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-03-13 20:43           ` Jason Gunthorpe

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=20170313115824.el7aoo46hwszrfac@intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=gang.wei@intel.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=jsnitsel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    /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).