Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1890992ybg; Thu, 4 Jun 2020 23:44:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr8F91pCLjlf282rp2EB6A5JOWVuTKKsQCmEXwfpptMrCFnanAemkXffh6Ys4H8QSeUp/+ X-Received: by 2002:a17:906:8294:: with SMTP id h20mr7058600ejx.17.1591339471986; Thu, 04 Jun 2020 23:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591339471; cv=none; d=google.com; s=arc-20160816; b=fjIEsHKjD7mBWhEF9FWQmg3S5WMogFuXTT/nBXTuxccYJmYJ0uSPLBTsN+nItViyjw F2mpbxX+fJ5CurmsAiixDO4319lLItEtKMFPap8QO2BG0iJy4pif3El+oeB+g3KQsRXh GFTtqH+QfE4Pc7UIiVffU/GNJ53IsL8akxyu4wm5l128dqXLdb1TKRpMHDCB11JXx0yE 4lyNQOVNIX5nV2gvTCf8R2jlYImmzHQszpIEpYAchEIbuepQqFLTDdzTC2rlCpSyG+EC YhkPEAOssHqhL4HHCjud8UjHgCLRgGz9WTD30bX2x83wMtv3/PMFE5pljaM2zAnB1+e/ v2AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qwzDEQkwHdEnq+mhcDB3Jm+NND58dUzEWDRIOfKzzEM=; b=JBV513N9YnR97WNcz49wxWPKxpId0cPUpxVMcIpfdjvckQ6px8mGSozwCLOzYJ58Ke 2zMPfDcmJMKNqTQA+qTM+lPSn8IkMWz9eVASqrxfm3QMfHp4zEjx+JZYOZ1uJWQH37Sg jFPZs75Ep2BK1xC/ybg6r1EoK135x50r02esWt38Ge1ePLX8jbL0pSkU7C0dfCzxRFmk yj7I0ZBa+bTbyTLjDBvW0ol0w7gHE3x/f/ZJz7AodL1aZdOalV5AUPfzzAcuSL6EUAow vkvKP/rYwX09WFY+RVoOJid/ixzL5iiM4JhPAjeMWAg9VdCN36+/ysJK4/pKhRVMRz/r s+hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=IrxIHTOt; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si2925416edr.130.2020.06.04.23.44.08; Thu, 04 Jun 2020 23:44:31 -0700 (PDT) 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; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=IrxIHTOt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726099AbgFEGlz (ORCPT + 99 others); Fri, 5 Jun 2020 02:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbgFEGly (ORCPT ); Fri, 5 Jun 2020 02:41:54 -0400 Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D249C08C5C2; Thu, 4 Jun 2020 23:41:54 -0700 (PDT) Received: by ozlabs.org (Postfix, from userid 1007) id 49dY336tn3z9sT8; Fri, 5 Jun 2020 16:41:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591339311; bh=4xfwcfWg3fYDkvoSshyHr3xzme+hp4xxgCEBnrJPiQA=; h=From:To:Cc:Subject:Date:From; b=IrxIHTOtq36n7hL5oemlz8t7GEAZpF+h8mTGZWroOBqSOJhlOm51dSAX5GS8JjdQw WHPJOGd2sMRNJx6TszW1g1u49Df8BhbVSg50aDEDD0Kr11VDFLFtDyVVb6LQh/IizZ 9MyDft/8Rp9JAU6KU9KeE06jCzBBToAxZF9pO1V4= From: David Gibson To: Michael Ellerman , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Stefan Berger , Nayna Jain Cc: Paul Mackerras , linuxppc-dev@lists.ozlabs.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, David Gibson Subject: [PATCH] tpm: ibmvtpm: Wait for ready buffer before probing for TPM2 attributes Date: Fri, 5 Jun 2020 16:37:19 +1000 Message-Id: <20200605063719.456277-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tpm2_get_cc_attrs_tbl() call will result in TPM commands being issued, which will need the use of the internal command/response buffer. But, we're issuing this *before* we've waited to make sure that buffer is allocated. This can result in intermittent failures to probe if the hypervisor / TPM implementation doesn't respond quickly enough. I find it fails almost every time with an 8 vcpu guest under KVM with software emulated TPM. Fixes: 18b3670d79ae9 "tpm: ibmvtpm: Add support for TPM2" Signed-off-by: David Gibson --- drivers/char/tpm/tpm_ibmvtpm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index 09fe45246b8c..994385bf37c0 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -683,13 +683,6 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, if (rc) goto init_irq_cleanup; - if (!strcmp(id->compat, "IBM,vtpm20")) { - chip->flags |= TPM_CHIP_FLAG_TPM2; - rc = tpm2_get_cc_attrs_tbl(chip); - if (rc) - goto init_irq_cleanup; - } - if (!wait_event_timeout(ibmvtpm->crq_queue.wq, ibmvtpm->rtce_buf != NULL, HZ)) { @@ -697,6 +690,13 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, goto init_irq_cleanup; } + if (!strcmp(id->compat, "IBM,vtpm20")) { + chip->flags |= TPM_CHIP_FLAG_TPM2; + rc = tpm2_get_cc_attrs_tbl(chip); + if (rc) + goto init_irq_cleanup; + } + return tpm_chip_register(chip); init_irq_cleanup: do { -- 2.26.2