Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3138575pxj; Mon, 14 Jun 2021 15:37:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE2FSQUXTQgvrRDWNgl8sziwCyh/BORZNSTJ17js7h6U28AC39gv6sI+WHXd1X0s6/qw9z X-Received: by 2002:a17:906:53c9:: with SMTP id p9mr17626167ejo.419.1623710224982; Mon, 14 Jun 2021 15:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623710224; cv=none; d=google.com; s=arc-20160816; b=dZHgICrEmBGgY5CqJ3MNa/vlkyQ/pspdgZbX0tYEl8RT7M8nQVW8mabAQpvZ8SB7TH bnwzq0eaSrs8FNnfx1VWSWfoCIaZUs1GxUoZQ/BrZzGYuJ2coepxiNgXT/Sba3sy/hM6 0y46/2vDKLbjiNEaCviXzZJpNvVeNMWgmHIrVvsmcvzrflx9wdfdfRIMRnMbnNF7uNph mmh0TKBNMORwrpHr1N3vvHQRSWR+HTbHcwpAzGyJ6yqKQ4pW9EA/uA933j1CpE2H+QZm anbb8RLrlJhSkCFwSLGsBG0jjGlzZXskFJo6FzwXnUKYbcSXr4m2vxGDbHsHYYSxDIC4 r4BA== 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:dkim-filter; bh=Tl/p2tGxM6IrZJQb02DL6qvvXW35MjdSvBm9pBSwJbQ=; b=MvRN17fwR5P3XhLTl3Hv2EWgFWfn+zpkT+4pcGE+VZeGUPBKLJwla6rjMdKDUA13n9 3SSt4/cNfAx4/biVdoCGgk1tfM5JZXfvNcIjTr7c6G1seNM+W7WUCNL7RcUugjwd3aI2 bLvsa7iBjXcVNaj8h/hkl51nptOQ3WhKfkqEuZI6KUFagsSOEzGRnqyXRARiY0Iwt3j9 j43fXShcPlkCOB4rKa2lnWTYEUeBn8wcRlDt4Cjdga3YBtr7le032V9maXTLmNfh6NF+ bRsb937SsUVl25tGudYDVeMY77KCghdYW7TzE+M+kmzvfOU/ynKhE30NXYKkDAUkUPq6 61SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=GwK26bNS; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si5595055edu.539.2021.06.14.15.36.42; Mon, 14 Jun 2021 15:37:04 -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=@linux.microsoft.com header.s=default header.b=GwK26bNS; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbhFNWfx (ORCPT + 99 others); Mon, 14 Jun 2021 18:35:53 -0400 Received: from linux.microsoft.com ([13.77.154.182]:56188 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231707AbhFNWfq (ORCPT ); Mon, 14 Jun 2021 18:35:46 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id EFEEF20B83C5; Mon, 14 Jun 2021 15:33:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EFEEF20B83C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1623710022; bh=Tl/p2tGxM6IrZJQb02DL6qvvXW35MjdSvBm9pBSwJbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GwK26bNSv07YR68gmqo7+Na9IYLTsD9xsUTsvPaPBysEcafwLw60LQTTer77lItY5 X7hyczaPH3k/H/rtjY+gI3o218d2AbjrLufDWbg0p0s6U+xzKbSnwJBoELO6Idknrd TmlqQDmoBEmer4YHmE/q3X8vi2y4BHSLUTYBU6Tc= From: Tyler Hicks To: Jens Wiklander , Allen Pais , Sumit Garg , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Vikas Gupta Cc: Thirupathaiah Annapureddy , Pavel Tatashin , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , op-tee@lists.trustedfirmware.org, linux-integrity@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 7/8] tpm_ftpm_tee: Free and unregister TEE shared memory during kexec Date: Mon, 14 Jun 2021 17:33:16 -0500 Message-Id: <20210614223317.999867-8-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614223317.999867-1-tyhicks@linux.microsoft.com> References: <20210614223317.999867-1-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma-buf backed shared memory cannot be reliably freed and unregistered during a kexec operation even when tee_shm_free() is called on the shm from a .shutdown hook. The problem occurs because dma_buf_put() calls fput() which then uses task_work_add(), with the TWA_RESUME parameter, to queue tee_shm_release() to be called before the current task returns to user mode. However, the current task never returns to user mode before the kexec completes so the memory is never freed nor unregistered. Use tee_shm_alloc_kernel_buf() to avoid dma-buf backed shared memory allocation so that tee_shm_free() can directly call tee_shm_release(). This will ensure that the shm can be freed and unregistered during a kexec operation. Fixes: 09e574831b27 ("tpm/tpm_ftpm_tee: A driver for firmware TPM running inside TEE") Fixes: 1760eb689ed6 ("tpm/tpm_ftpm_tee: add shutdown call back") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks --- drivers/char/tpm/tpm_ftpm_tee.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c index 2ccdf8ac6994..6e3235565a4d 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -254,11 +254,11 @@ static int ftpm_tee_probe(struct device *dev) pvt_data->session = sess_arg.session; /* Allocate dynamic shared memory with fTPM TA */ - pvt_data->shm = tee_shm_alloc(pvt_data->ctx, - MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE, - TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); + pvt_data->shm = tee_shm_alloc_kernel_buf(pvt_data->ctx, + MAX_COMMAND_SIZE + + MAX_RESPONSE_SIZE); if (IS_ERR(pvt_data->shm)) { - dev_err(dev, "%s: tee_shm_alloc failed\n", __func__); + dev_err(dev, "%s: tee_shm_alloc_kernel_buf failed\n", __func__); rc = -ENOMEM; goto out_shm_alloc; } -- 2.25.1