Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp760081iog; Wed, 15 Jun 2022 11:39:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBn2woyhjWyodYqO9ckUqGUHjkNV1NXqsQdGIuV619G0v0A/Nf+VH83qBZK/Ac4eEMg/SG X-Received: by 2002:a05:6402:1f0e:b0:42d:e38a:51f7 with SMTP id b14-20020a0564021f0e00b0042de38a51f7mr1513659edb.68.1655318391792; Wed, 15 Jun 2022 11:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655318391; cv=none; d=google.com; s=arc-20160816; b=XzQH53kKP7BH0HDx5IKi6Z39LeE0jvb3CXTJD2k1UVGDx/VZ0WLLVRp3yhaOQ9mfAi B1KdjrHhVc8X4az88uD3NAwvek6PZXzsDsdru8k00T+NPEL8N/oTS0UJ4Fu0fwgeNVNC gHKPCXH9Ic8sRuHA/EX6kSfR7zbuePzUZza3JWZppt0hMAYZOXZOeWnQj3fby0rxBCy7 EwSYBGMXQ52gBInFyfbc2XNkvP++JqxOBdHn+6WbgYbLEGndqvneI5++lQCXKn1huo3B 4aO0z+w3AUxlQ8zb4301taMpN1vKPIEcANSYB/f8aHNsewZpe3f94JyVQZJa9t668qCh nwIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7G3v0q5pv4hWS6QFRQL3rYWnWjQ/eRVVu8W/1+8uBTA=; b=fS4J3O7k+QAQ8bm8RZYCtWnCAHbJJV3+7IFkBKYZIAzuOta5GRHwwy2/dfUDyZIgiI oGuFoXihPZSSncdbf4QnRWwN2qm4Qcfmql01fbu8ulCfGl5+5IJg6LeLiDH5wiOWHH3r /B2xD0khamEVeaz+jJjBeAZiBg6hG6AautQ/2QQe7KVtg0zRDsYC647cjYihQjsBeRC2 5NnW8OuLqTns6mwMK9g8wcFwYPK+rlCRo1N5bVjtVA3iP98rbsIPQo0xalC9byHlqjnC bWe3W2vSU9dru8sscXuXoSj7ss+3e3mGAs6QctbUHplPOobEJyCjJP2EVbg7C2H4259z XC0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QsaiN+I9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd22-20020a1709069b9600b00718dba48d9asi6715864ejc.72.2022.06.15.11.39.24; Wed, 15 Jun 2022 11:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QsaiN+I9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355496AbiFOSXw (ORCPT + 99 others); Wed, 15 Jun 2022 14:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346397AbiFOSXs (ORCPT ); Wed, 15 Jun 2022 14:23:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9E425294; Wed, 15 Jun 2022 11:23:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A2D41B82130; Wed, 15 Jun 2022 18:23:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E5D4C36AF2; Wed, 15 Jun 2022 18:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655317424; bh=zObHqLUh2Rncs2EFcgmp5EbS5j6sE7FLEKEpqYw7Hfc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QsaiN+I9lB+w/4rklbNVmHf5zAK8JOiTSNF8/RnIJtGn9TQ1HS1k56Yx/XpAbHiKN tFf2HYsMP4lTjsDkZhVhPD2p04kEo7swymPhPnHMgLX6kDSR7GzIo2xdEM/DKN/vAP 0Q4Z1dogGiwlnM1I2d9S+9wHhVAnDiIBdAehKM+YN6kM+8BAM24aIVoUk9zg3E9Tei MvYyNiymrmLpmZkg6pRA3ooUK1OJ7EoACOvc6lC+Ov0XefhLdXhzI/MJsVrddfjv5G 4Ke6J1h6uUNEDirIwdpuIGCed7W7+uLWDnr2RUlj8rWDjP42AdJcFc+N4jjrYT6xen /1gJfXcEWV5Uw== Date: Wed, 15 Jun 2022 21:21:34 +0300 From: Jarkko Sakkinen To: LinoSanfilippo@gmx.de Cc: peterhuewe@gmx.de, jgg@ziepe.ca, stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, lukas@wunner.de, p.rosenberger@kunbus.com Subject: Re: [PATCH v5 06/10] tpm, tpm_tis: Only handle supported interrupts in wait_for_tpm_stat() Message-ID: References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> <20220610110846.8307-7-LinoSanfilippo@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220610110846.8307-7-LinoSanfilippo@gmx.de> X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 10, 2022 at 01:08:42PM +0200, LinoSanfilippo@gmx.de wrote: > From: Lino Sanfilippo > > According to the TPM Interface Specification (TIS) interrupts for > "stsValid" and "commandReady" might not be supported. > > Take this into account and only wait for interrupts which are actually in > use in wait_for_tpm_stat(). After that process all the remaining status > changes by polling the status register. > > Signed-off-by: Lino Sanfilippo > --- > drivers/char/tpm/tpm_tis_core.c | 46 ++++++++++++++++++++++++--------- > 1 file changed, 34 insertions(+), 12 deletions(-) > > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c > index 2f03fefa1706..028bec44362d 100644 > --- a/drivers/char/tpm/tpm_tis_core.c > +++ b/drivers/char/tpm/tpm_tis_core.c > @@ -53,41 +53,63 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, > long rc; > u8 status; > bool canceled = false; > + u8 active_irqs = 0; Something like sts_mask would be a better name. Calling it 'active_irqs' is a bit confusing. > + int ret = 0; > > /* check current status */ > status = chip->ops->status(chip); > if ((status & mask) == mask) > return 0; > > - stop = jiffies + timeout; > + /* check what status changes can be handled by irqs */ > + if (priv->irqs_in_use & TPM_INTF_STS_VALID_INT) > + active_irqs |= TPM_STS_VALID; > > - if (chip->flags & TPM_CHIP_FLAG_IRQ) { > + if (priv->irqs_in_use & TPM_INTF_DATA_AVAIL_INT) > + active_irqs |= TPM_STS_DATA_AVAIL; > + > + if (priv->irqs_in_use & TPM_INTF_CMD_READY_INT) > + active_irqs |= TPM_STS_COMMAND_READY; > + > + active_irqs &= mask; > + > + stop = jiffies + timeout; > + /* process status changes with irq support */ > + if (active_irqs) { > + ret = -ETIME; > again: > timeout = stop - jiffies; > if ((long)timeout <= 0) > return -ETIME; > rc = wait_event_interruptible_timeout(*queue, > - wait_for_tpm_stat_cond(chip, mask, check_cancel, > + wait_for_tpm_stat_cond(chip, active_irqs, check_cancel, > &canceled), > timeout); > if (rc > 0) { > if (canceled) > return -ECANCELED; > - return 0; > + ret = 0; > } > if (rc == -ERESTARTSYS && freezing(current)) { > clear_thread_flag(TIF_SIGPENDING); > goto again; > } > - } else { > - do { > - usleep_range(priv->timeout_min, > - priv->timeout_max); > - status = chip->ops->status(chip); > - if ((status & mask) == mask) > - return 0; > - } while (time_before(jiffies, stop)); > } > + > + if (ret) > + return ret; > + > + mask &= ~active_irqs; > + if (!mask) /* all done */ > + return 0; > + /* process status changes without irq support */ > + do { > + status = chip->ops->status(chip); > + if ((status & mask) == mask) > + return 0; > + usleep_range(priv->timeout_min, > + priv->timeout_max); > + } while (time_before(jiffies, stop)); > return -ETIME; > } > > -- > 2.36.1 > BR, Jarkko