Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1866709iog; Sat, 25 Jun 2022 23:46:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vCcL/yZYbqkaR41ezOSLFe/FktQR2pAyHD+wJ+Wc8WA6z+7bWGVIy/e3NcXq9uBLg54JUg X-Received: by 2002:a17:902:e746:b0:16a:3b5c:2134 with SMTP id p6-20020a170902e74600b0016a3b5c2134mr8226650plf.36.1656225990841; Sat, 25 Jun 2022 23:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656225990; cv=none; d=google.com; s=arc-20160816; b=EPPNsLXnvM3OEVhSQO4p1V2EXtr15bobbQaLaSQqEh8Yd0ox30lon3Bp86if+PHcv4 mJl2HxOB84mmdYbjl6HTbiN1mrzVTP1sh9lfQjvyrZIZ8nLwaQn2Gx0zrQR5E89jU7NP hKznr8LF+jIpTA79wXw2yy1pjSvg1fpFk7jKvdlSmuRmRcxkZLz9mptisZiH8ObD8Tja 6reQct3XKvoL9n0XY52WPc4nH0mUFOxh4yrikqktmygocKi5NeApuMrCS9bjJM+XH3yU yHHCA8IBBQY9yN/NECjrB6YFje0xq4flx+8pxnUeGVpyEsB7phWiPVBke/q7qetpWErg Mbvg== 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=QwRd6yGYjRtNs5QHfAG4z5lhYQII4kB5xESmUeOJCD8=; b=0e7G2nTaXdcvkNGWmFIQ9UjChG1jtF3jDc+I1cPeG9mjk8x4ohHez96j9EMfSY2soF ahAh+6w5xG08k2eeIEbPUt4z3HKwKfOpBXBtRKddR1T+eFpe10th3BQY22okfm4rRrVl WA8nzPdmcBegVbaprm46vV+L3fD1Dmc2JNsLYS0L5P2uOE/aNnZCUFACst0Jsww0m+a+ mjzHGyFpHP4hBqyh8972++kI/bmz7v7U76qRf3ZO1ZI4iD+a66/cIgIlIiyJV9GyNIbA y+mlu53pJ6AQ57a/6KeZQnzyrXCLv/N7TxdnNQYqKdMrDA8W3IREV2uF0RGSqA/RwEzw tNNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aZiN3O1j; 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 x14-20020a170902ec8e00b00163e1591f90si12277591plg.24.2022.06.25.23.46.01; Sat, 25 Jun 2022 23:46:30 -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=aZiN3O1j; 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 S233964AbiFZGoI (ORCPT + 99 others); Sun, 26 Jun 2022 02:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232935AbiFZGoH (ORCPT ); Sun, 26 Jun 2022 02:44:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C15BF5E; Sat, 25 Jun 2022 23:44:06 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6F8176112C; Sun, 26 Jun 2022 06:44:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7952EC34114; Sun, 26 Jun 2022 06:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656225845; bh=9ZJU86lQ5UWr7OdwF+1fcUD9JncNiwNET9qCr7/rCP4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aZiN3O1jc4XfSZ74OjHhMQldK57BUIPxLvJA71N/4gP3uPnfTG2la9niGt/78l5tM wmUaPSpvD/cAoKi9v2+kqBExMyu7HQmoDuy/EOGB5zIPBPmFg17vUT+I3P9L2eLOkl b9tmszguhYIzCZ+gjzdHOE12gtmAuSIYx9HQQ36IYCVCKcxbIaJCXiQdkThucbFQsG 8koiiOUpX/hU9KE37GjwK1YOzjHmv6evWLGj5A9LnIhey1EEN9STm/6sBeOt1XuPVo 4EpQ0ssCq93iBH4EXZLiFm32fzrJqvOridFuZkniUcLm2pidAj+QxXE7QNAr/go8YK sz8i+YKoXMs6g== Date: Sun, 26 Jun 2022 09:44:02 +0300 From: Jarkko Sakkinen To: Lino Sanfilippo 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 v6 5/9] tpm, tpm_tis: Only handle supported interrupts Message-ID: References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> <20220621132447.16281-6-LinoSanfilippo@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.7 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 Sun, Jun 26, 2022 at 09:40:43AM +0300, Jarkko Sakkinen wrote: > On Tue, Jun 21, 2022 at 03:24:43PM +0200, Lino Sanfilippo wrote: > > From: Lino Sanfilippo > > > > According to the TPM Interface Specification (TIS) support for "stsValid" > > and "commandReady" interrupts is only optional. > > This has to be taken into account when handling the interrupts in functions > > like wait_for_tpm_stat(). To determine the supported interrupts use the > > capability query. > > > > Also adjust wait_for_tpm_stat() to only wait for interrupt reported status > > changes. 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 | 119 +++++++++++++++++++------------- > > drivers/char/tpm/tpm_tis_core.h | 1 + > > 2 files changed, 72 insertions(+), 48 deletions(-) > > > > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c > > index 09d8f04cbc81..cb469591373a 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 sts_mask = 0; > > + 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->int_mask & TPM_INTF_STS_VALID_INT) > > + sts_mask |= TPM_STS_VALID; > > > > - if (chip->flags & TPM_CHIP_FLAG_IRQ) { > > + if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) > > + sts_mask |= TPM_STS_DATA_AVAIL; > > + > > + if (priv->int_mask & TPM_INTF_CMD_READY_INT) > > + sts_mask |= TPM_STS_COMMAND_READY; > > + > > + sts_mask &= mask; > > I would instead mask out bits and write a helper function > taking care of this: > > static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask) > { > struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); Ignore this line (wrote this out of top of my head). > if (!(int_mask & TPM_INTF_STS_VALID_INT)) > sts_mask &= ~TPM_STS_VALID; > > if (!(int_mask & TPM_INTF_DATA_AVAIL_INT)) > sts_mask &= ~TPM_STS_DATA_AVAIL; > > if (!(int_mask & TPM_INTF_CMD_READY_INT)) > sts_mask &= ~TPM_STS_COMMAND_READY; > > return sts_mask; > } > > Less operations and imho somewhat cleaner structure. > > Add suggested-by if you want. > > BR, Jarkko