Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp297658pxb; Wed, 13 Jan 2021 04:03:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTrbnb6Hc+CWleBWap8daqNkydHRbvhTTbz5pEIWRN7agvfYjAsA7uYqp2ElLZOZcdbPbI X-Received: by 2002:aa7:c707:: with SMTP id i7mr1487659edq.183.1610539419755; Wed, 13 Jan 2021 04:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610539419; cv=none; d=google.com; s=arc-20160816; b=jMuL87WiVTIdziMx0GsLLwsczHCBHyFCPh5KfmArTVmvxEhfVMEzMwT9il7ayhzLdO qg0VR3s79jPE38TyKdbn6mWj8wf71hQkD2kp0H0rNbUiqtHMyjHDEYUg08D4W58S5TUZ XgVtnomgJPU5MIQ+g7XWKVoayKDIju7bXhzC6mhob3tBZpA0TA2iJ+iPuBXBY6D0fcIP FqYJDwaWG5yht5gv9iENHM3CfZV/4S38eQ5y1C5MgaTzJMJuOvq9JX9UwBSiO2DygNIN jvgDDzwFb3rivMueyyCDJBAcGlORPN137rM+YoEu1Fu1KkjGLJ7o7jU8+LMOdD2pRBs+ k30g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gVeoKKU7tCNOPPT8b4PYQXHodcuNvGc4a6zg+ywWbXY=; b=vbGTLiXB1ZNOxYyExZqkI3OWdRZVelXlfGXpbNpSPTEVXKa3FNCluxdtQHXEOZLiPX cOkZ4/oxY+9CPthxyyMGnEMQbh3Ig3VZOIIZeD46sJVkVpvyAWWdXvLpWV5ov4KsNevm u6YqhrGeOLZDQ8CfnqHX0xrWXdLFHFnZdDjnP/hBVHr+BX2tDolMhNw0j2O15Ic3GNfL zoF94RdFlHtYoqC5RvGtlSTsN/xLu0Zp3zTo0WozHOquKVLvqYtyjR3N1gXVHaFc0XvA 9qrpNAaAKXRemolQRXGC4+lX9sQTNETF3i3v6wskNbzF2K1HxwvnmTxgVCm5Qh9Om0Vq gEZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si922747ejc.31.2021.01.13.04.03.06; Wed, 13 Jan 2021 04:03:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbhAMMBO (ORCPT + 99 others); Wed, 13 Jan 2021 07:01:14 -0500 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:38158 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbhAMMBN (ORCPT ); Wed, 13 Jan 2021 07:01:13 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R441e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0ULcwkx0_1610539221; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0ULcwkx0_1610539221) by smtp.aliyun-inc.com(127.0.0.1); Wed, 13 Jan 2021 20:00:21 +0800 From: Tianjia Zhang To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhang Cc: Tianjia Zhang Subject: [PATCH] tpm/tpm_tis: Fix variable reset during IRQ probing Date: Wed, 13 Jan 2021 20:00:21 +0800 Message-Id: <20210113120021.59045-1-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.3.ge56e4f7 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tpm_tis_core_init(), tpm2_probe() will be called first, this function will eventually call tpm_tis_send(), and then tpm_tis_probe_irq_single() will detect whether the interrupt is normal, mainly the installation interrupted, set `priv->irq_tested` to false. The logic will eventually be executed to tpm_tis_send() to trigger an interrupt. There is currently such a scenario, which will cause the IRQ probe code to never be executed, so that the TPM device is in polling mode: after setting irq_tested to false, an interrupt occurs between entering the ttpm_tis_send() function, and the interrupt will be first set irq_tested to true will cause the IRQ probe code to never be executed. It seems that this interrupt comes from tpm2_probe(). Although the interrupt has not been installed when tpm2_probe() is called, the interrupt of tpm2_probe() is only received after IRQ detection. This patch solves this issue by introducing a new variable, which is only used in interrupts, and irq_tested only marks whether the interrupt test has been completed. Signed-off-by: Tianjia Zhang --- drivers/char/tpm/tpm_tis_core.c | 8 ++++---- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 92c51c6cfd1b..d7589b0b3e56 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -502,7 +502,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (priv->irq_tested) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -512,9 +512,9 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!priv->int_count) tpm_msleep(1); - if (!priv->irq_tested) + if (!priv->int_count) disable_interrupts(chip); priv->irq_tested = true; return rc; @@ -725,7 +725,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + priv->int_count += 1; if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 9b2d32a59f67..c6845672f6f7 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -90,6 +90,7 @@ struct tpm_tis_data { int locality; int irq; bool irq_tested; + unsigned int int_count; unsigned int flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; -- 2.19.1.3.ge56e4f7