Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3577281pxv; Mon, 19 Jul 2021 03:50:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhjLOxGN+gIaWyqAnoLWHlChjQj8oJjYGBFY2BdndUCHiRX0BJI0qsV6afYT4fVOh0MiGN X-Received: by 2002:a92:b506:: with SMTP id f6mr11571326ile.151.1626691859575; Mon, 19 Jul 2021 03:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626691859; cv=none; d=google.com; s=arc-20160816; b=ZQa2D2iLjgGULr5Te/vlhseQb20PBHdIhqgI7mptHofzWZzsiclPW/4p+UbachwNJO NMLyBxKEMIjDaU6vfVaBOldRtAseWHabmy6ro5FL3cRKoKz97yt+fCe32VT2PGlMjQA1 OHVDMcEFVbTxQ9jF7OsI+KxxQ7a856tvNXWs3MdMNjHf1tXq0Z/UdhJSnNW9Y5I7il+g bKVQbV30e8sobsNRiFfgycNQOXxoYl8pdinJshumAaRMY5QCMijYJForXR36yQsddlQH dLUYDFr+WTJHvzPdcfmvwdV+9h5Gw+aGQAqHNx2yp3IYVPPhPY7hmbZAN42q0AvzQie9 3GyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=izuO6gvI65i5N9voqwWRAxIjJnPgY0dtLzVTkR8nBPo=; b=W1/6WOAUAoE4c12Lz4q+Eior0dXUPQubjpb38m/Qnss5y4rMXzVJQdf1fJsORcBXEw t9+S8DgAAXy+wr8e9lyrw+feGmGQVYIYp0sM4lMYgYEXgBYiK05j3PZgxhi6E5OWD3DI hAW2962cfm4XHXBia+0ppNHsqNjL7ZXO3qeaWC6e2E3SmYp1mwU0wEhKuMIUcTuG9HfN L8DCs1THAfXfhr3fFscoT2MVJ98qa4eaM6fEUlLjMpFH1rtBN5RoyCjiLAgVHvqekCHU A7gdVbWJbv9zS6TwjRBuCDni3UAJTs1KXEsF2NrS4i88r+mUN8/xtDfBbzXanDB1Fpe7 YtWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k6FvzoDA; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si16294300ilo.119.2021.07.19.03.50.47; Mon, 19 Jul 2021 03:50:59 -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=@linaro.org header.s=google header.b=k6FvzoDA; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236516AbhGSKJ1 (ORCPT + 99 others); Mon, 19 Jul 2021 06:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236330AbhGSKJ0 (ORCPT ); Mon, 19 Jul 2021 06:09:26 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8A07C061766 for ; Mon, 19 Jul 2021 02:58:08 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id k4so21430465wrc.8 for ; Mon, 19 Jul 2021 03:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=izuO6gvI65i5N9voqwWRAxIjJnPgY0dtLzVTkR8nBPo=; b=k6FvzoDAJSW94zB39kfmFHDISI3yFTMUzn1gC61Vx6eoZyCD6lYdg1wA9VAdTUifZT CaTyfzOWFktyxbYqVOfyWBbqdlSR+JtngddRYbSNz2/nMqfNEY0my6w93kOIwwTrt3UY /trq4vQrsfCpKxbM9uTjxbp5UpdgKPdg2pBENE1o2WfluC0kfHVKlrdMZKHtxpC46B8+ C8IQKJL5iQIL8V/jdUf+bRjXSZs0n+C1W2iBe/byxnB/MzDJwTlU/rWJR+jqOZ0AU7yv nyaUrtXPCPcr3JYHaxkSZKrLUBwWVqRrnNhxJAuOBgehnCcKVu4jfuZAoJ6NZHmP7aO0 2P+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=izuO6gvI65i5N9voqwWRAxIjJnPgY0dtLzVTkR8nBPo=; b=ZlAHh5I8cCc0xPJP7j3X7u0pu6XNY7F2LRIEcA9fE/v87LBjDFOz/A4+zBhNFA9BzZ qsBOKTt0YbJhsF0iZSQSvYroM/zNt0KI15C75bzBNZzNliZh416bPf/UGUZWud57FYCT nzHnMp+9k4zpbonQbCKo6GifRAinpQR54qibSd/BY00EBjZdaEwZmZIv6qfsMXPXp0mZ DakzBvQ8JsLMvf9aVXWGgZn1i4Nq/VC9NI8tTawEtvl02z+CzVgPDQ9Ze5Uy0SFFoCdM YBOPH1LxKhziRy9Sxx/PJ8a5/pJ6O8/rKjXjSZDiWDBTupYaR3y61mRsCer7cYEEhOBp oR1A== X-Gm-Message-State: AOAM532jyZcH0mKrw8YMVsLCJxsQhiLWkVUvNioCprErNhHq3gW5QUvK XbyjQ1EjIL6PKlk+iVOHkr/OW5rYCSv0nImsLVASwg== X-Received: by 2002:a5d:6da9:: with SMTP id u9mr28517634wrs.7.1626691801564; Mon, 19 Jul 2021 03:50:01 -0700 (PDT) MIME-Version: 1.0 References: <20210716022332.GC3232@sequoia> In-Reply-To: From: Jens Wiklander Date: Mon, 19 Jul 2021 12:49:51 +0200 Message-ID: Subject: Re: [PATCH v5 8/8] firmware: tee_bnxt: Release TEE shm, session, and context during kexec To: Vikas Gupta , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Cc: Tyler Hicks , Allen Pais , Sumit Garg , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Thirupathaiah Annapureddy , Pavel Tatashin , OP-TEE TrustedFirmware , linux-integrity , BCM Kernel Feedback , linux-mips@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Jul 16, 2021 at 4:48 AM Vikas Gupta wrote: > > Hi Allen/Tyler, > The patch looks good to me. Thanks. Rafal, is it OK if I include this patch together with the rest of the patches in this patch set in a pull request to arm-soc? Thanks, Jens > > Thanks, > Vikas > >> >> > From: Allen Pais >> > >> > Implement a .shutdown hook that will be called during a kexec operation >> > so that the TEE shared memory, session, and context that were set up >> > during .probe can be properly freed/closed. >> > >> > Additionally, don't use dma-buf backed shared memory for the >> > fw_shm_pool. 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: 246880958ac9 ("firmware: broadcom: add OP-TEE based BNXT f/w manager") >> > Cc: stable@vger.kernel.org >> > Signed-off-by: Allen Pais >> > Co-developed-by: Tyler Hicks >> > Signed-off-by: Tyler Hicks >> > --- >> > drivers/firmware/broadcom/tee_bnxt_fw.c | 14 +++++++++++--- >> > 1 file changed, 11 insertions(+), 3 deletions(-) >> > >> > diff --git a/drivers/firmware/broadcom/tee_bnxt_fw.c b/drivers/firmware/broadcom/tee_bnxt_fw.c >> > index ed10da5313e8..a5bf4c3f6dc7 100644 >> > --- a/drivers/firmware/broadcom/tee_bnxt_fw.c >> > +++ b/drivers/firmware/broadcom/tee_bnxt_fw.c >> > @@ -212,10 +212,9 @@ static int tee_bnxt_fw_probe(struct device *dev) >> > >> > pvt_data.dev = dev; >> > >> > - fw_shm_pool = tee_shm_alloc(pvt_data.ctx, MAX_SHM_MEM_SZ, >> > - TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); >> > + fw_shm_pool = tee_shm_alloc_kernel_buf(pvt_data.ctx, MAX_SHM_MEM_SZ); >> > if (IS_ERR(fw_shm_pool)) { >> > - dev_err(pvt_data.dev, "tee_shm_alloc failed\n"); >> > + dev_err(pvt_data.dev, "tee_shm_alloc_kernel_buf failed\n"); >> > err = PTR_ERR(fw_shm_pool); >> > goto out_sess; >> > } >> > @@ -242,6 +241,14 @@ static int tee_bnxt_fw_remove(struct device *dev) >> > return 0; >> > } >> > >> > +static void tee_bnxt_fw_shutdown(struct device *dev) >> > +{ >> > + tee_shm_free(pvt_data.fw_shm_pool); >> > + tee_client_close_session(pvt_data.ctx, pvt_data.session_id); >> > + tee_client_close_context(pvt_data.ctx); >> > + pvt_data.ctx = NULL; >> > +} >> > + >> > static const struct tee_client_device_id tee_bnxt_fw_id_table[] = { >> > {UUID_INIT(0x6272636D, 0x2019, 0x0716, >> > 0x42, 0x43, 0x4D, 0x5F, 0x53, 0x43, 0x48, 0x49)}, >> > @@ -257,6 +264,7 @@ static struct tee_client_driver tee_bnxt_fw_driver = { >> > .bus = &tee_bus_type, >> > .probe = tee_bnxt_fw_probe, >> > .remove = tee_bnxt_fw_remove, >> > + .shutdown = tee_bnxt_fw_shutdown, >> > }, >> > }; >> > >> > -- >> > 2.25.1 >> > >> >> ----- End forwarded message -----