Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2347234ybx; Fri, 8 Nov 2019 03:07:30 -0800 (PST) X-Google-Smtp-Source: APXvYqy6VhwdILgiPZz5GygvZm1Jvcav1ECUgKophmN9+pWJ8GnVrirNqEU6kZCKkUPDB/VsJST5 X-Received: by 2002:a05:6402:158d:: with SMTP id c13mr9377498edv.62.1573211250227; Fri, 08 Nov 2019 03:07:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573211250; cv=none; d=google.com; s=arc-20160816; b=judkcmqSHpsWHB96AvRZBeQR5m8bHjdPSbzsoWqeTM83NCi8CLwediIhisilYHnoBp KrcuTWIu+HhWn1ulDM8/gyHLuUS4E7hveAgclAxbGrxLCHVTXtPIHRvezIJ+xKpXrL5z +3xgOZerHQDy6Suk+v9CM5s5XhMWmCqpVnbxSAqnu8VqY/nlGb1dRV96MGoKfx1VDhty 1Xybpn2fHxOj+cXVzO1y9erZshkJ7D5a/IBYTc1+GP1ZafHaFht++EeVZr9eBY6rBbRx yKpl5VEH6mEwvSVHUq1l2anVlJg9o2tqvk6zrRox46u3uZ3TSgimDd9IgvBg6vMEulsT JfGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Sy2LP6u2jmHt5m9xRWZK7C9zG0JoW6tUkzFgmde33yU=; b=RKTgMZ4zT4BzyWMSIPXlKfS1UgELBYuHFaSZ65M2+I8IZZXDdnO4XZUSgzdgK1zmDj qPK6LFlAtEnnZJpAKUfcMuOGMiNB3KOLerVCqRqEcgcfIvE4fihPSVQEXqySC5kycM7q fmNQDK0EwJ4KCW4uMBxiEDgD4d/8FsI88UkziROwotW/xUcDTITNYhA2EM5rEc059ZTb QayXrxunshY2yPJRLBVV6Z4DLtoNeuhR0miDUPOMz5EITDPBkG6FhfeFhpjAT+udzlz3 6FibzDW6YRDxmiSm4h8nK5lIyArOqn1Ze1N0H05eDAJNZw4tYIC8K/WTnHlcm5rd8D3K kdbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uoo+Q71g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id n12si3679584edr.448.2019.11.08.03.07.06; Fri, 08 Nov 2019 03:07:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uoo+Q71g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1731465AbfKHLGK (ORCPT + 99 others); Fri, 8 Nov 2019 06:06:10 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:38697 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729896AbfKHLGK (ORCPT ); Fri, 8 Nov 2019 06:06:10 -0500 Received: by mail-lf1-f67.google.com with SMTP id q28so4146694lfa.5 for ; Fri, 08 Nov 2019 03:06:09 -0800 (PST) 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=Sy2LP6u2jmHt5m9xRWZK7C9zG0JoW6tUkzFgmde33yU=; b=Uoo+Q71g0cxgu2QJpg7+In6A15rgLEBTHByOzyJL97eOk18NJI51sZj2MVQ/S83qnd PKMsn/7nn9yx2/zuOFefoYhUO82xdF0PH//iratH+QNhSQP3K5MReZu0S9JM4L8+xR6o u1xg4nzdI3kA7WJV5bv/8B/xxMp3YC3o39Bqs/RLx3v7xXV3ub5OpxzmswbJg0IG+1De 3a6bBNt510nQw5N2VmgnMKCTPwTSXrZjpkAfEThVXifBOky4VtKm7asTs0JtFnQzrYHc svgkw0HFx6FwYaLAoQJ0CNKC0WWwYovxtgdbqYVM7ZSjRHFH/v++3N8fhWa8xO+K6fo0 LolA== 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=Sy2LP6u2jmHt5m9xRWZK7C9zG0JoW6tUkzFgmde33yU=; b=HwS9crx4ongFnUQBtTTsq1qn1gglf2ok3KDRqXfo6xb56j1vgZNPBHaZ7vwTVwvXB4 KiVFccpx2ZsNpB3pXpyVG3PrpOuABkbWOMJbowqkdvgVm2CBW6RDSryngPrGTuQ63/wS Bb4Bng32OUynLb4OqTS/9AWWMx3jXpUDMAu0oPR5lg6LniulK1UfoiaZMcDQTC8KRWas DGc49fvVzlqZuotQquvIlE2qCZFAsSa2ll+WcbwZFkTvsTWjowh9L0wa8fRdfJeOXAQK pwBnSJ91x+1Z1JeuSvXLFzBQDuGIT+deH92FkvW62RURC5d3mp1Jr+R+Htwghc/PqnJ7 PbgQ== X-Gm-Message-State: APjAAAX9pOkV8AO6XDTYlzkYXlwZHZBCUhG2/sYg3Sdt2R3Da4VX9E7c 2HDbGcw8FWlsq+8RfF6lT6eZw8NbJj+iCEPApNjfFw== X-Received: by 2002:ac2:5bca:: with SMTP id u10mr6376774lfn.134.1573211168327; Fri, 08 Nov 2019 03:06:08 -0800 (PST) MIME-Version: 1.0 References: <1572527274-21925-1-git-send-email-sumit.garg@linaro.org> <20191107110603.GA8790@jax> In-Reply-To: From: Sumit Garg Date: Fri, 8 Nov 2019 16:35:56 +0530 Message-ID: Subject: Re: [PATCH] tee: optee: Fix dynamic shm pool allocations To: Jens Wiklander Cc: Volodymyr Babchuk , "tee-dev @ lists . linaro . org" , Linux Kernel Mailing List , Carriere Etienne Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jens, On Fri, 8 Nov 2019 at 16:09, Jens Wiklander wrote: > > Hi Sumit, > > On Thu, Nov 7, 2019 at 1:41 PM Sumit Garg wrote: > > > > Hi Jens, > > > > On Thu, 7 Nov 2019 at 16:36, Jens Wiklander wrote: > > > > > > Hi Sumit, > > > > > > On Thu, Oct 31, 2019 at 06:37:54PM +0530, Sumit Garg wrote: > > > > In case of dynamic shared memory pool, kernel memory allocated using > > > > dmabuf_mgr pool needs to be registered with OP-TEE prior to its usage > > > > during optee_open_session() or optee_invoke_func(). > > > > > > > > So fix dmabuf_mgr pool allocations via an additional call to > > > > optee_shm_register(). > > > > > > > > Fixes: 9733b072a12a ("optee: allow to work without static shared memory") > > > > Signed-off-by: Sumit Garg > > > > > > Looks good, I'm picking this up. Etienne told me has tested this on some > > > of his hardware so I'll add: > > > Tested-by: Etienne Carriere > > > > > > > Thanks for picking this up. > > > > > > > > > --- > > > > > > > > Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support > > > > to allow registration of kernel buffers with OP-TEE. > > > > You also need to pick up the dependency patch too. The latest v3 of > > this patch is here [1] although its unchanged from v2. Also, If you > > pick that up I will drop it from future revisions of Trusted Keys > > patchset [2]. > > > > [1] https://lkml.org/lkml/2019/10/31/431 > > [2] https://lkml.org/lkml/2019/10/31/430 > > So I missed taking [1] into account. I think that it would make more > sense to merge this patch ("tee: optee: Fix dynamic shm pool > allocations") with [1] ("tee: optee: allow kernel pages to register as > shm") into a new patch. Sure, will send v2 as merged patch instead. -Sumit > Cheers, > Jens > > > > > -Sumit > > > > > > > > > > drivers/tee/optee/shm_pool.c | 12 +++++++++++- > > > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c > > > > index de1d9b8..0332a53 100644 > > > > --- a/drivers/tee/optee/shm_pool.c > > > > +++ b/drivers/tee/optee/shm_pool.c > > > > @@ -17,6 +17,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, > > > > { > > > > unsigned int order = get_order(size); > > > > struct page *page; > > > > + int rc = 0; > > > > > > > > page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); > > > > if (!page) > > > > @@ -26,12 +27,21 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, > > > > shm->paddr = page_to_phys(page); > > > > shm->size = PAGE_SIZE << order; > > > > > > > > - return 0; > > > > + if (shm->flags & TEE_SHM_DMA_BUF) { > > > > + shm->flags |= TEE_SHM_REGISTER; > > > > + rc = optee_shm_register(shm->ctx, shm, &page, 1 << order, > > > > + (unsigned long)shm->kaddr); > > > > + } > > > > + > > > > + return rc; > > > > } > > > > > > > > static void pool_op_free(struct tee_shm_pool_mgr *poolm, > > > > struct tee_shm *shm) > > > > { > > > > + if (shm->flags & TEE_SHM_DMA_BUF) > > > > + optee_shm_unregister(shm->ctx, shm); > > > > + > > > > free_pages((unsigned long)shm->kaddr, get_order(shm->size)); > > > > shm->kaddr = NULL; > > > > } > > > > -- > > > > 2.7.4 > > > >