Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2505196ybf; Mon, 2 Mar 2020 09:59:09 -0800 (PST) X-Google-Smtp-Source: ADFU+vvPVFIoXZYGdMfEvJjL0LiW3uj+m8NZXWDxxJznsdB1h3qZHpm4Byt2fp9ELIuJhQ5SlxI6 X-Received: by 2002:a9d:22e2:: with SMTP id y89mr314569ota.132.1583171949040; Mon, 02 Mar 2020 09:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583171949; cv=none; d=google.com; s=arc-20160816; b=vUnI4VwnCIAQvodYaxUV+ZFYCi6qvJdf4o74hxMrnA51bQXPMKzdkGpyBUyi1meVA/ R2oSVJjgKa+Y5oNzLQws/jEoziNg4S2i6NHNe3m9A2MeBs1ewCPWrtINTYlNvAHafV1v To3p2u//T3licqBeEi78zFK0wXPefJnED/MDMFFrQvoTGHVt0vVSo+5ONQVTAfF7S72M cyoaTeIuJnsYTlxBhqq4c/+pDJVrAU2EOz7n4ZTCmuwpufr05+c4VVkBrawcRWeKh2fN 4s4Q0YDQsBWD0bKpAj77RG7B2Nka5eokrxuuCOdM2rT6x67XO7bRABm6h+NTWp5ImBtw Kz6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=qHgsuovVyhCP5Ahg+X2h6zZj+8MkeOZD/xAWhz1Ud+U=; b=Rs5tFgatQYKUeCqPc7BoZvAFVPvxwdfUdNJfLiousPNy9o1TSbkrihjrbC5ovpSP6D ja164GUWMR4Q6nLRm5HWcFu5ao2KT89gXpvrTNWc9Gkt1og5NvgNqv0eKEmXQXoZghUF gWMGa0qrVKDHN8NrkURYARCVLp5dGkm47uFQE5VFUluQnE7Cv8AOQ5Z0zbJSpGNwa/8u WmsdOu9hB1ZLXCkdxMXIYEhLBXjKwN8axlXhcszWXSGkmJYuNPVub9NKhL3cMWB8zKhb yVvZ6tfoP/mDcAWHIFCbXdAlgYawQpa1Lx8efYSvBeZlHPscPJ+VQKXNfp40hpIZqBDP H56Q== 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 c17si4214380oto.198.2020.03.02.09.58.56; Mon, 02 Mar 2020 09:59:09 -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 S1727268AbgCBR5m (ORCPT + 99 others); Mon, 2 Mar 2020 12:57:42 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41900 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbgCBR5m (ORCPT ); Mon, 2 Mar 2020 12:57:42 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 022HpmGk021165; Mon, 2 Mar 2020 12:57:35 -0500 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yfnbf2emc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Mar 2020 12:57:34 -0500 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 022Hu7G8020505; Mon, 2 Mar 2020 17:57:33 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma04wdc.us.ibm.com with ESMTP id 2yffk645n0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Mar 2020 17:57:33 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 022HvWpg55378334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Mar 2020 17:57:32 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27F9AC6062; Mon, 2 Mar 2020 17:57:32 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F9F9C6057; Mon, 2 Mar 2020 17:57:31 +0000 (GMT) Received: from swastik.ibm.com (unknown [9.160.68.102]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 2 Mar 2020 17:57:30 +0000 (GMT) Subject: Re: [PATCH v5 2/3] tpm: ibmvtpm: Wait for buffer to be set before proceeding To: Stefan Berger , jarkko.sakkinen@linux.intel.com, linux-integrity@vger.kernel.org Cc: aik@ozlabs.ru, david@gibson.dropbear.id.au, linux-kernel@vger.kernel.org, gcwilson@linux.ibm.com, jgg@ziepe.ca, Stefan Berger References: <20200228030330.18081-1-stefanb@linux.vnet.ibm.com> <20200228030330.18081-3-stefanb@linux.vnet.ibm.com> From: Nayna Message-ID: Date: Mon, 2 Mar 2020 12:57:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200228030330.18081-3-stefanb@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-02_06:2020-03-02,2020-03-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 clxscore=1011 priorityscore=1501 mlxscore=0 impostorscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003020118 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/27/20 10:03 PM, Stefan Berger wrote: > 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..eee566eddb35 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, "Initialization failed\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 { Acked-by: Nayna Jain Thanks & Regards,      - Nayna