Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4507229ybf; Wed, 4 Mar 2020 05:23:39 -0800 (PST) X-Google-Smtp-Source: ADFU+vsaWcJUSQNUGUmjQjQc/6ccy6hebHDHSo9hYNHKAf1pat2hMd3cSzCcybrK3h2uC2fglyz8 X-Received: by 2002:aca:130c:: with SMTP id e12mr1633438oii.122.1583328219154; Wed, 04 Mar 2020 05:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583328219; cv=none; d=google.com; s=arc-20160816; b=SzO3BQh4fjNSKS1Rz5BWAYMuVwtPEPwJnXLhV5B5lkNGZE4+IdDbqGZT3id5sGnjJ3 W/yartitf0j2xqEkuOxFl+33Y+C25nTTNJeHxv8CQSCxL1AMMuyqip+zIHt+ksI51lG2 lVahPA6732PEjuydzOfg1t0MA1BE3Gn/xK0f1sfuw9MfP3jaI6m+K6759TbIqn8HFbq1 YCATugiJqZ3eevJjpMXCy5x7NekEm3hTDyN82mHneCWgq3YjLOiFpHxs/QUFu7Ie32bF Dpx9Lgmnc4sOrPtUhVFxOrSDjCVlmVO0rR3umeKg9Lp0ZpT1Ktj+tGxcPwx0iW9XU6Cm iykg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vvZaRrX5XwAUZ+Y3IQQctc0AsXOkUb55W2mrsWPRSXA=; b=x/46nRuwfUJ52j3Gm1UQYF956HvuwKy2muCpaNr4/xhvgSHh9sBXsOmLVOxzmES3ye GnWnvw1PrCz7k2Zm1++ha5UuK5KSh+qpAmhM1C7NNq6pJdsyItCAvzENFxGdM1TeXX0o ZT5KiXjnif/ERQxq3xSE6TyvPqklswMvUgAy+hg+vt7npdhVwjnCZ3qhzucizdCb9LgQ VcOfAiyNXzyo0EK8jfS9kiCj+InGkm+nkrd+0W6PPRcfAIPRtyclb/zPm0a369aXUt4s UWESDBwCkmn7fKb29l1cVPnNfgm/xifzoCy5ZrcWdMNYsp0r73a4dlSG1KpbI9GENiQM XgRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e19si1151934oti.20.2020.03.04.05.23.27; Wed, 04 Mar 2020 05:23:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388107AbgCDNXD (ORCPT + 99 others); Wed, 4 Mar 2020 08:23:03 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51432 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387776AbgCDNXD (ORCPT ); Wed, 4 Mar 2020 08:23:03 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 024DKh7m082210; Wed, 4 Mar 2020 08:22:53 -0500 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yj4q12ut9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Mar 2020 08:22:53 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 024DLATo016344; Wed, 4 Mar 2020 13:22:52 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 2yffk6b1mr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Mar 2020 13:22:52 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 024DMoPa57082320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Mar 2020 13:22:50 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B5A79C605A; Wed, 4 Mar 2020 13:22:50 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1FF8C6055; Wed, 4 Mar 2020 13:22:49 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 4 Mar 2020 13:22:49 +0000 (GMT) From: Stefan Berger To: jarkko.sakkinen@linux.intel.com, linux-integrity@vger.kernel.org Cc: aik@ozlabs.ru, david@gibson.dropbear.id.au, linux-kernel@vger.kernel.org, nayna@linux.vnet.ibm.com, gcwilson@linux.ibm.com, jgg@ziepe.ca, Stefan Berger Subject: [PATCH v6 2/3] tpm: ibmvtpm: Wait for buffer to be set before proceeding Date: Wed, 4 Mar 2020 08:22:42 -0500 Message-Id: <20200304132243.179402-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200304132243.179402-1-stefanb@linux.vnet.ibm.com> References: <20200304132243.179402-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-04_05:2020-03-04,2020-03-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003040102 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Berger Synchronize with the results from the CRQs before continuing with the initialization. This avoids trying to send TPM commands while the rtce buffer has not been allocated, yet. This patch fixes an existing race condition that may occurr if the hypervisor does not quickly respond to the VTPM_GET_RTCE_BUFFER_SIZE request sent during initialization and therefore the ibmvtpm->rtce_buf has not been allocated at the time the first TPM command is sent. Fixes: 132f76294744 ("Add new device driver to support IBM vTPM") Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm_ibmvtpm.c | 9 +++++++++ drivers/char/tpm/tpm_ibmvtpm.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index 78cc52690177..cfe40e7b1ba4 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -571,6 +571,7 @@ static irqreturn_t ibmvtpm_interrupt(int irq, void *vtpm_instance) */ while ((crq = ibmvtpm_crq_get_next(ibmvtpm)) != NULL) { ibmvtpm_crq_process(crq, ibmvtpm); + wake_up_interruptible(&ibmvtpm->crq_queue.wq); crq->valid = 0; smp_wmb(); } @@ -618,6 +619,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, } crq_q->num_entry = CRQ_RES_BUF_SIZE / sizeof(*crq_q->crq_addr); + init_waitqueue_head(&crq_q->wq); ibmvtpm->crq_dma_handle = dma_map_single(dev, crq_q->crq_addr, CRQ_RES_BUF_SIZE, DMA_BIDIRECTIONAL); @@ -670,6 +672,13 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, if (rc) goto init_irq_cleanup; + if (!wait_event_timeout(ibmvtpm->crq_queue.wq, + ibmvtpm->rtce_buf != NULL, + HZ)) { + dev_err(dev, "CRQ response timed out\n"); + goto init_irq_cleanup; + } + return tpm_chip_register(chip); init_irq_cleanup: do { diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtpm.h index 7983f1a33267..b92aa7d3e93e 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.h +++ b/drivers/char/tpm/tpm_ibmvtpm.h @@ -26,6 +26,7 @@ struct ibmvtpm_crq_queue { struct ibmvtpm_crq *crq_addr; u32 index; u32 num_entry; + wait_queue_head_t wq; }; struct ibmvtpm_dev { -- 2.23.0