From: Christophe RICARD <christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Jason Gunthorpe
<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Cc: peterhuewe-Mmb7MZpHnFY@public.gmane.org,
ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org,
tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org,
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
christophe-h.ricard-qxv4g6HH51o@public.gmane.org,
jean-luc.blanc-qxv4g6HH51o@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v3 11/15] tpm/tpm_i2c_stm_st33: Replace wait_for_serirq_timeout by wait_for_tpm_stat
Date: Tue, 14 Oct 2014 22:44:25 +0200 [thread overview]
Message-ID: <20141014224425.45b5de03@toffy-MacBookPro> (raw)
In-Reply-To: <20141014180914.GE27232-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
On Tue, 14 Oct 2014 12:09:14 -0600
Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote:
> On Mon, Oct 13, 2014 at 10:23:33PM +0200, Christophe Ricard wrote:
> > The tpm layer already provides a function to wait for a TIS event
> > wait_for_tpm_stat. Exactly like wait_for_serirq_timeout, it can
> > work in polling or interrupt mode.
> > Instead of using a completion struct, we rely on the waitqueue
> > read_queue and int_queue from chip->vendor field.
>
>
> > static int request_locality(struct tpm_chip *chip)
> > {
> [..]
>
> > if (chip->vendor.irq) {
> > - r = wait_for_serirq_timeout(chip, (check_locality
> > - (chip) >=
> > 0),
> > -
> > chip->vendor.timeout_a); +again:
> > + timeout = stop - jiffies;
> > + if ((long) timeout <= 0)
> > + return -1;
>
> I don't see an enable_irq before this sleep:
I missed that one i guess.
>
> > + r =
> > wait_event_interruptible_timeout(chip->vendor.read_queue,
> > + check_locality(chip) >= 0,
> > + timeout);
>
> Can it use wait_for_stat?
It actually cannot use wait_for_stat because wait_for_stat is waiting
for a mask condition on the status register. Here we are addressing the
TPM_ACCESS register.
>
> > static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned
> > long timeout,
> > - wait_queue_head_t *queue)
> > + wait_queue_head_t *queue, bool
> > check_cancel) {
>
> So, I didn't audit the driver 100%, but this new version has the flow
>
> - enable_irq
> - wait for irq
> - clear irq
>
> Which is conceptually fine (and efficient), but it requires the rest
> of the driver to guarentee that the interrupt is consistent after
> every interation with the TPM. Which for this driver I think means one
> of two states:
> - No interrupt asserted
> - Interrupt asserted, and the TPM is ready to accept a command
> Other states will cause longer command execution times, but not
> malfunction.
>
> For instance, it looks to me like request_locality might not maintain
> that invariant.
>
> Clearing old pending bits before starting an interaction is certainly
> safer, but costs that extra I2C sequence.
>
> > + tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
> > +
> > + if (chip->vendor.irq)
> > + enable_irq(chip->vendor.irq);
> > +
> > + r = wait_for_tpm_stat(chip, mask, timeout, queue,
> > check_cancel);
>
> This seqence is racy, the reason the nuvoton driver has the counter is
> because wake_up_interruptible only wakes sleeping threads, so the
> driver has to use the counter to close the race between the enable_irq
> and the actual sleep:
>
> unsigned int cur_intrs = priv->intrs;
> enable_irq(chip->vendor.irq);
> rc = wait_event_interruptible_timeout(*queue,
> cur_intrs !=
> priv->intrs, timeout);
If my understanding is correct the counter prevent the case where the
irq is raised before entering into the wait_event_interruptible_timeout.
wait_for_tpm_stat will check before going into sleep the status
register in order to make sure the condition is not already satisfied
and should fulfill this requirement.
As i could get different kind of interruption i think i cannot avoid an
i2c check here. The other solution would be to activate only the right
interruption in the INT_ENABLE tis register but still with an i2c
transaction.
>
> Jason
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-10-14 20:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 20:23 [PATCH v3 00/15] ST33 I2C TPM driver cleanup Christophe Ricard
[not found] ` <1413231817-5174-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-13 20:23 ` [PATCH v3 01/15] tpm/tpm_i2c_stm_st33: Update Kconfig in order to be inline to other similar product Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 02/15] tpm/tpm_i2c_stm_st33: Fix few coding style error reported by scripts/checkpatch.pl Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 03/15] tpm/tpm_i2c_stm_st33: Move tpm registers to tpm_i2c_stm_st33.c Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 04/15] tpm/tpm_i2c_stm_st33: Add new tpm_stm_dev structure and remove tpm_i2c_buffer[0], [1] buffer Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 05/15] tpm/tpm_i2c_stm_st33: Remove reference to io_serirq Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 06/15] tpm/tpm_i2c_stm_st33: Replace err/rc/ret by r for a function return code Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 07/15] tpm/tpm_i2c_stm_st33: Replace tpm_st33_* function with tpm_stm_* Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 08/15] tpm/tpm_i2c_stm_st33: Add devicetree structure Christophe Ricard
[not found] ` <1413231817-5174-9-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14 17:32 ` Jason Gunthorpe
[not found] ` <20141014173209.GD27232-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-14 19:59 ` Christophe RICARD
2014-10-13 20:23 ` [PATCH v3 09/15] tpm/tpm_i2c_stm_st33/dts/st33zp24_i2c: Add DTS Documentation Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 10/15] tpm/tpm_i2c_stm_st33: Few code cleanup Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 11/15] tpm/tpm_i2c_stm_st33: Replace wait_for_serirq_timeout by wait_for_tpm_stat Christophe Ricard
[not found] ` <1413231817-5174-12-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14 18:09 ` Jason Gunthorpe
[not found] ` <20141014180914.GE27232-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-14 20:44 ` Christophe RICARD [this message]
2014-10-14 21:15 ` Jason Gunthorpe
2014-10-13 20:23 ` [PATCH v3 12/15] tpm/tpm_i2c_stm_st33: Remove useless i2c read on interrupt registers Christophe Ricard
[not found] ` <1413231817-5174-13-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14 8:17 ` [tpmdd-devel] " Marcin Obara
[not found] ` <CAPxFvEPT8wEt4BfZ7112aFpsowXV2WUHvsN5W9=iKUvmRpcBFw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-14 8:34 ` Christophe Henri RICARD
2014-10-13 20:23 ` [PATCH v3 13/15] tpm/tpm_i2c_stm_st33: Fix potential bug in tpm_stm_i2c_send Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 14/15] tpm/tpm_i2c_stm_st33: Change License header to have up to date address information Christophe Ricard
2014-10-13 20:23 ` [PATCH v3 15/15] tpm/tpm_i2c_stm_st33: Increment driver version to 1.2.1 Christophe Ricard
2014-10-14 18:51 ` [PATCH v3 00/15] ST33 I2C TPM driver cleanup 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=20141014224425.45b5de03@toffy-MacBookPro \
--to=christophe.ricard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org \
--cc=christophe-h.ricard-qxv4g6HH51o@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=jean-luc.blanc-qxv4g6HH51o@public.gmane.org \
--cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@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).