Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3701093pxk; Tue, 29 Sep 2020 04:12:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx+WFncoHuxLAWRsioF5layszhR21Kylzqt/ugSzXJy0PqQn5GfVh/KVBIYlJ1sCkXHWSp X-Received: by 2002:a17:907:aaa:: with SMTP id bz10mr608450ejc.353.1601377920096; Tue, 29 Sep 2020 04:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601377920; cv=none; d=google.com; s=arc-20160816; b=ahv0wLq6BSWBDNTc6Tb/vhXs26hdmW9UaxcGXgVWl9Dy6zWrbn7FxMrAJ992vDYYcc u4hgG2qmVRNDzsTcJr2AEgd93YJ+lCQ6dvTemQOSSgGf8MnCEMeXe10mwhNv5bdm70AV dnyUobsD5eUVjzbjWw3jZoN96DG7mxhkqyPhREqyqLTImZBr14HUZHQICCqho0iug04P AkqlNSE7CV8b9NHN3DkemSQA8+SJ9DpvcnqEjnl4indJolmOOXZi2UvhoVMXFbN90Uzq xeBnZxpZY5SGLZQ9+vNjhVsds8l7WgV9LDB98rORHiULHwpLz41HcsxZ/jdw/wxbSUBn 2t+Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8JGHQuj4utVRw5pK7Hkqwqgx5b4J/2HuIfnCCTtV2HE=; b=NYLX6OagzhpyozdqNJAXKD6ZMX4j+rN2VcFssyP2xPAfCXk4B7OXdv3j1vGLVk6BbW tcsDQe1RIekgodJz4dy475EMojYa8DNZZ5fXtwiOIdhQGAPrzacAdO6QDh/J0IXhY8mw hXRKY590UhG++RhIwHkajERCRUsgAmIvmIa5/n9sA8lyMfpEb6/afk+YfxdnJuT2/sv7 0O4iri7H5ZCIsm41W2bE2AO4NCTEH9g441/zdOnPMieQoJz4XDpq22q9TAa4x4wCKQZc vweaVakaAbPbSYaURxw+5w6L3Gs5ye+cwxMeApIA4Tvd++F7rmxoWVrptC15VvF5SITA PBmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fHsQUWvY; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u2si2566201edx.5.2020.09.29.04.11.37; Tue, 29 Sep 2020 04:12:00 -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=@kernel.org header.s=default header.b=fHsQUWvY; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728585AbgI2LJV (ORCPT + 99 others); Tue, 29 Sep 2020 07:09:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:49550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729077AbgI2LJT (ORCPT ); Tue, 29 Sep 2020 07:09:19 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6266221941; Tue, 29 Sep 2020 11:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377757; bh=muIuyhP/cJjVwo+TG7Ox+ClqqRg1N6YBSaL2OCN8hIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHsQUWvYMHcLvqVP8nnFCNjxnMgCwf4JiURTqMUR6tkiKPBku12W9N0GtdLiQH8mO fai2yMSQyOpS7ET8NyGK4fAsoydhAff1LMsYqY4IuVwrnU0aoJ1JUXEEDmj6aOwYiK grAyuLxvjYZvEQxQEvkaJrcwQ3lhUdzlGF6MU8qw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Berger , Nayna Jain , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 4.9 062/121] tpm: ibmvtpm: Wait for buffer to be set before proceeding Date: Tue, 29 Sep 2020 13:00:06 +0200 Message-Id: <20200929105933.245725275@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Berger [ Upstream commit d8d74ea3c00214aee1e1826ca18e77944812b9b4 ] 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 ("drivers/char/tpm: Add new device driver to support IBM vTPM") Signed-off-by: Stefan Berger Acked-by: Nayna Jain Tested-by: Nayna Jain Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Sasha Levin --- 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 84eca4f93b828..0fad6cf37bab4 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -550,6 +550,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(); } @@ -596,6 +597,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); @@ -648,6 +650,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 91dfe766d0800..4f6a124601db4 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.h +++ b/drivers/char/tpm/tpm_ibmvtpm.h @@ -31,6 +31,7 @@ struct ibmvtpm_crq_queue { struct ibmvtpm_crq *crq_addr; u32 index; u32 num_entry; + wait_queue_head_t wq; }; struct ibmvtpm_dev { -- 2.25.1