Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp878350pxk; Thu, 17 Sep 2020 20:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCfkDC7E9ut5f4Hi4t8iYdDl4H6cSlR0UFKXQU9ZnCDwlpYrozJLelixoabAqiVdXSslRZ X-Received: by 2002:aa7:de91:: with SMTP id j17mr36697132edv.85.1600398429726; Thu, 17 Sep 2020 20:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398429; cv=none; d=google.com; s=arc-20160816; b=E/e18UozddYM/kokJdYglH1xsEiuomeYa/WA8vMZcR9chjYWPS0VoDuXD7JMHkFQPI 7CHwqjKMKrzY06oeOd3bBQEROLZ+ql8PScW0Uc3av1NfjcJhKXfAYH7hGGlRWTHu3QNJ oOjVj0554ddXqAQpCKFHcOVOdpF0FFRPkJWLz3DyCCPLj5QNqMFcSdoeDa5RQcWUBZXt q98oh/1ENvdxZq+6OxBzeLnXWb37eGG/ra0HxXxRrzCjLg+8L4fm50sw3cjaEJ8iYRL6 r6J6uU+keKcPt8g5VBo6iKoDqcoV/dfwROZueUXtS2zkXpsyIfSlgLKoXrWKVBgQvEeB deKg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XKOzQEBgAAAuhiTaXyRAiXz9YoV33r6iXvtYVrPFb6Y=; b=Np6dAm9NokrrZhEXsUV/e1laLOL2p0fPojkYCz+x6cqIb/5okU+znecy5ztpbB8cNf FjvczwbpvHjmPsHxiwjSaGImVTp8qP9pKXEvxPZaXisRuacrRNLO0pOX8W2Fj8MBHxgX xa27LXSTxOcO2uk4ImRZCBP4Vo9P6is096dFAy8Wo0kjohruBF+N1/9g1ymZlkWZZEe3 jgfAYx3+BG+heZDJUqq6NdCvxRFEDAPqvGa6Jwo9ajwZlUqzE0pU8acIfhMY6crAnz70 dUbPMqtmrir+VyFqTFnnVugALqBDvwtXLdE3eQjUzYSE0tEN+5ukIOav2n0bfcpDFlaM aHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I39hFfGW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si1221676ejj.497.2020.09.17.20.06.46; Thu, 17 Sep 2020 20:07:09 -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=I39hFfGW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730574AbgIRDE2 (ORCPT + 99 others); Thu, 17 Sep 2020 23:04:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:52464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbgIRCEq (ORCPT ); Thu, 17 Sep 2020 22:04:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6FE4F23899; Fri, 18 Sep 2020 02:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394685; bh=CPYBrKhhR0qMmXjqeLWqB2hUBu0Z7xqNICuBAzDBHV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I39hFfGWY1ZTUbppvdI+9z/mEkoThOF4XbJCgi8ckoDVxQjMAS8UtI47IQlpJJiup DxTplhAWYc6KdSO3Theapalrb0zseKYyMVJbOOaRb/0kcMIilG/CUoWyrofIecGLF6 t9iBcNIIK5YSqZ1UxwXiVKbja2i2hJEVPhCYQvU0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stefan Berger , Nayna Jain , Jarkko Sakkinen , Sasha Levin , tpmdd-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.4 174/330] tpm: ibmvtpm: Wait for buffer to be set before proceeding Date: Thu, 17 Sep 2020 21:58:34 -0400 Message-Id: <20200918020110.2063155-174-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 e82013d587b46..64428dbed9928 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -581,6 +581,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(); } @@ -628,6 +629,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); @@ -680,6 +682,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 7983f1a33267e..b92aa7d3e93e7 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.25.1