From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EED8FC4363A for ; Fri, 30 Oct 2020 12:18:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88EFD2076E for ; Fri, 30 Oct 2020 12:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604060283; bh=GZiEe7WlY9Chvgttiuy4woHf87RW8MIHVcQlETW/p4o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=ulPj0HfjtcV4jvt16BydGb93pAOhb2Yu5MFuehNvDyeKxgX0p500UUvhhkUPXL70N RxBn0E2cVoJnBKkM/PXS0wbsdqbMlY2GqekjzbC5u+iV8Qp0dt2p/BkxNJKXCuYbPm 7mq4hMfhNyQ028zKwwQtabqyIrqXMQEwB9naSzhw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726318AbgJ3MSD (ORCPT ); Fri, 30 Oct 2020 08:18:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:47704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbgJ3MSD (ORCPT ); Fri, 30 Oct 2020 08:18:03 -0400 Received: from kernel.org (83-245-197-237.elisa-laajakaista.fi [83.245.197.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70C4E20724; Fri, 30 Oct 2020 12:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604060281; bh=GZiEe7WlY9Chvgttiuy4woHf87RW8MIHVcQlETW/p4o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DkHvJ7/egroVVHfaYN24LdIPl8BZwf3IkgT0rSGhevlaa3u6NmxSuJ6W/DpDYssVN UlnHhOVtl4JrWAz3aLqi8hz9DU45v2StqMAFC4d0p823ROwCZN4e+GL9Jwf/o2gN36 PwtoBOmCBBNAXQMOyEmQLFgyRYvP5JSFPYONNmP0= Date: Fri, 30 Oct 2020 14:17:56 +0200 From: Jarkko Sakkinen To: Jerry Snitselaar Cc: James Bottomley , linux-integrity@vger.kernel.org, Jason Gunthorpe , Jarkko Sakkinen , Peter Huewe Subject: Re: [PATCH v2 2/5] tpm_tis: Clean up locality release Message-ID: <20201030121756.GB522355@kernel.org> References: <20201001180925.13808-1-James.Bottomley@HansenPartnership.com> <20201001180925.13808-3-James.Bottomley@HansenPartnership.com> <875z75hkk8.fsf@redhat.com> <20201024121007.GA32960@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201024121007.GA32960@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org On Sat, Oct 24, 2020 at 03:10:07PM +0300, Jarkko Sakkinen wrote: > On Mon, Oct 19, 2020 at 04:17:59PM -0700, Jerry Snitselaar wrote: > > > > James Bottomley @ 2020-10-01 11:09 MST: > > > > > The current release locality code seems to be based on the > > > misunderstanding that the TPM interrupts when a locality is released: > > > it doesn't, only when the locality is acquired. > > > > > > Furthermore, there seems to be no point in waiting for the locality to > > > be released. All it does is penalize the last TPM user. However, if > > > there's no next TPM user, this is a pointless wait and if there is a > > > next TPM user, they'll pay the penalty waiting for the new locality > > > (or possibly not if it's the same as the old locality). > > > > > > Fix the code by making release_locality as simple write to release > > > with no waiting for completion. > > > > > > Fixes: 33bafe90824b ("tpm_tis: verify locality released before returning from release_locality") > > > Signed-off-by: James Bottomley > > > > > > --- > > > > > > v2: added fixes > > > --- > > > drivers/char/tpm/tpm_tis_core.c | 47 +-------------------------------- > > > 1 file changed, 1 insertion(+), 46 deletions(-) > > > > > > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c > > > index f3ecde8df47d..431919d5f48a 100644 > > > --- a/drivers/char/tpm/tpm_tis_core.c > > > +++ b/drivers/char/tpm/tpm_tis_core.c > > > @@ -135,58 +135,13 @@ static bool check_locality(struct tpm_chip *chip, int l) > > > return false; > > > } > > > > > > -static bool locality_inactive(struct tpm_chip *chip, int l) > > > -{ > > > - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); > > > - int rc; > > > - u8 access; > > > - > > > - rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); > > > - if (rc < 0) > > > - return false; > > > - > > > - if ((access & (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) > > > - == TPM_ACCESS_VALID) > > > - return true; > > > - > > > - return false; > > > -} > > > - > > > static int release_locality(struct tpm_chip *chip, int l) > > > { > > > struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); > > > - unsigned long stop, timeout; > > > - long rc; > > > > > > tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); > > > > > > - stop = jiffies + chip->timeout_a; > > > - > > > - if (chip->flags & TPM_CHIP_FLAG_IRQ) { > > > -again: > > > - timeout = stop - jiffies; > > > - if ((long)timeout <= 0) > > > - return -1; > > > - > > > - rc = wait_event_interruptible_timeout(priv->int_queue, > > > - (locality_inactive(chip, l)), > > > - timeout); > > > - > > > - if (rc > 0) > > > - return 0; > > > - > > > - if (rc == -ERESTARTSYS && freezing(current)) { > > > - clear_thread_flag(TIF_SIGPENDING); > > > - goto again; > > > - } > > > - } else { > > > - do { > > > - if (locality_inactive(chip, l)) > > > - return 0; > > > - tpm_msleep(TPM_TIMEOUT); > > > - } while (time_before(jiffies, stop)); > > > - } > > > - return -1; > > > + return 0; > > > } > > > > > > static int request_locality(struct tpm_chip *chip, int l) > > > > Reviewed-by: Jerry Snitselaar > > Reviewed-by: Jarkko Sakkinen Just noticed that the short summary is wrong: a fix is not a clean up. Maybe "tpm_tis: Invoke locality release without wait" ? I'm also open for other suggestions but the current is short summary does not describe the patch. /Jarkko