Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3663390pxj; Tue, 15 Jun 2021 06:06:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+ic4f8b8/7jhc9djFehys5TzphNfcWvM7uEHeeaQyvACYipO2vI6YLY5vaK21KRgAYGPc X-Received: by 2002:a05:6e02:1e06:: with SMTP id g6mr17654362ila.192.1623762397317; Tue, 15 Jun 2021 06:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623762397; cv=none; d=google.com; s=arc-20160816; b=phciPFIMp6ef0e59FGT0rXDbU+0kfAITN1G1PPVVU31eqOsFCgfgpTdiPD8BlpqfdL GR0OiSxi4qIHzVoeV5NFfh4mRIydUs2GXCYB4OoVVsBSNDnOvQBo1s/iwH8goX7zR+C+ M+QYGneuhCAHplsIebNEyEQRMzQJKxKBsBpPoo1T516DSJYjE+SDe1LgZ++6JJhinbYt EErObCrk5Ghf6pi81Cmgq/eWdi9D1JxPk/kCIdBEk/WvtxWOIOiq9eOtLIDv8v9C/uXd rg+dQ3Hc9xNl9vfoYGcuUFLMgVo2yVVoUOQmxYCogoOC72QX5YzBkgqmiY7sZ2QJk3dH ZulA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xC2XKD8X5LINP8+IE+rV8bSrp3nx+QHj9i4lKBoy6yM=; b=gfhY4w7uznGv8d86+vhS2jIO8qof5STOepgFIO+kqbzB6rgSKHl4/1FjJFFvyddQGS AebgEPsUrC9GiUNDROr1St1F9vHytsFzt03Re+O3jJb1RfhX0ZrDi/3eRV5+njz3VzR9 gWmKDDNFAdGG9g6Uwv2cs12WJHvO6dC8j5HGKoSw7cwE1zGo7BxCLvU5TcUWsg8SLchD GPiViBuhhd1sYp9V9mZxOXbxwGqLDhceGfcRehMFFJOBP8evtZVqlspqHP+TkbPAODhr G0zoBBta0kdPB5dMgEM+Am+Bu79MXC4qBWOiUAUUBq+9nrErl0Ccdln2vFUZQonKbfRn UaAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jDvDqv8C; 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 i15si19852270ila.101.2021.06.15.06.06.23; Tue, 15 Jun 2021 06:06:37 -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=k20201202 header.b=jDvDqv8C; 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 S230261AbhFONGT (ORCPT + 99 others); Tue, 15 Jun 2021 09:06:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbhFONGS (ORCPT ); Tue, 15 Jun 2021 09:06:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6988261468; Tue, 15 Jun 2021 13:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623762253; bh=ry99x+VlQjPK7efumwMdnhXfJRG8zvDuRrxE6Ux6eR8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jDvDqv8CLOWhE9drMsXT3eTVyW3tyOo1D1tbIUn/raoSEEyC5NL+OsLfKSll9XhwF 9J1aBty8Nmxq1V00hXTgElu39a/vhaUyL6XeOuDBiRwFsbDyIw+9aRBJkigYJwu6qq oje+lVDELB/ILDfIf3qiYZG/5Q1W3nm+uVJCdGnjpV6oY0nBM6sLQuNQBfFVbXrKnG qZZrH/iqY9AJHCAmOvdJHP4489lXF23Id8tE7mQQVNjzfGINloc9SX6hf9GmyvdDgV x/7qD6GO4EH9zDLSLA1a+ey+USon9Hh/Rfp+Vosj6bEvmkmmAGsX2t1ZrR4cJybUYi mjd3FoMOOZyIg== Date: Tue, 15 Jun 2021 16:04:11 +0300 From: Jarkko Sakkinen To: Tyler Hicks Cc: Jens Wiklander , Allen Pais , Sumit Garg , Peter Huewe , Jason Gunthorpe , Vikas Gupta , Thirupathaiah Annapureddy , Pavel Tatashin , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , 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: Re: [PATCH v4 7/8] tpm_ftpm_tee: Free and unregister TEE shared memory during kexec Message-ID: <20210615130411.hvpnaxnhimjloiz3@kernel.org> References: <20210610210913.536081-1-tyhicks@linux.microsoft.com> <20210610210913.536081-8-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210610210913.536081-8-tyhicks@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 10, 2021 at 04:09:12PM -0500, Tyler Hicks wrote: > 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") > Signed-off-by: Tyler Hicks Acked-by: Jarkko Sakkinen > --- > 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 > > /Jarkko