Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp923618ybx; Thu, 7 Nov 2019 04:45:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzkPxrfzcp9uJPNMlBA7XcQu/DeulUQLijORYJSsRmMLdWeG3PSDUxclq080HjXGkj8pGYW X-Received: by 2002:a17:906:a28d:: with SMTP id i13mr2722838ejz.288.1573130759697; Thu, 07 Nov 2019 04:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573130759; cv=none; d=google.com; s=arc-20160816; b=yZmYwb2VJF2C7jtE6OVeKGkMQ8zcffpoWlDKXnnNAhD4hf1+ZcyN5fTlWAf5YIIqF/ BG/um68Dr2XIwTBfAVM9SNP7svr3EgSq1SzZhueN3U3UZJbTOckNKngcCu/ZtK7w3Gc1 qvg4ytPYkSPSWE14cXWAyEyHUcRfl0Iicg2GURTmHp5nXnezAvHOnIykxuxtfa0yEElN VwX8lxP/HEo5Mi10NWw393FIRUg5wAUUQANf1ncEF6VGv37Rr36Hj8JrCtWl2wRYffiJ us7bOH6j5H1f/de5M/fxHPQep85OX223+y6HUdSeXC3DN14WZCRVU1a5uRqbFH3AGC2p 2u3Q== 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=e2XfEnWtfgJ6guYxPo+ALFnkJVTOUcEM3sbl6pL7pOE=; b=EbdZ/xKGhF4+GMAIj+W9OBFVvimgJvzD0s4bB49CuaOmSR7ZhBDwNs4fa+GX4R0ilg 9fRpU5aqeGMTcuJP53uZYU3NweECRMFyr37ysFUgolDB1xiK5JjU7f8f+HMWeSm0erdJ HCBfOFBdsfvsG/R93ujy6W3khD+r7maDTfo8/TP1SXdvN2UsHMpZ0f6+BE5cadEnxmNR t3GQ2nEwRbp1qPRz5PoT4W8+JNJgfCn1SXl2pEU2uvD9994SyNmCBLYR6cwhbQfsx/Ce KoOnLovSW9/cfBxX0O+XeaeIBwHi72jFqA4TN06qm0CWHkX9H3ZcpJpCG3CRh7Q04L6p mejQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q7mof4I7; 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 l16si1047306ejg.240.2019.11.07.04.45.36; Thu, 07 Nov 2019 04:45:59 -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=Q7mof4I7; 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 S2388634AbfKGMlp (ORCPT + 99 others); Thu, 7 Nov 2019 07:41:45 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33107 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbfKGMlp (ORCPT ); Thu, 7 Nov 2019 07:41:45 -0500 Received: by mail-lj1-f195.google.com with SMTP id t5so2127370ljk.0 for ; Thu, 07 Nov 2019 04:41:44 -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=e2XfEnWtfgJ6guYxPo+ALFnkJVTOUcEM3sbl6pL7pOE=; b=Q7mof4I7FOaxy3d+UFM0BB9pfgpIP3AyAFwHi9KEOqPChO4Kqi8JBZZTu2iAj3OvDj HFBY+cKHBFOasbUFe4BIkNtfwOu3bzZDaslcwoZBTVpYTREHHpK1OM8rvRBg/TWlAkke GV5I1pIEljfinoxgo9SFFi+9rG9squV334ktjUTClh6ieeu/gOicpnrlP6lqgY0PDegS B9b3YfFvIiMA7Sszif6u/upfutt7Ldu+vLiV9D5urpTQbX+6jO8ZTNzENlt87SNIDKsj edhWy1BXJS5xMt9GZ4iYjxfWd8wi7YTin0/oyHqxOdlMfnfkDZkwxX1IaoF96oD/69Gg VWEA== 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=e2XfEnWtfgJ6guYxPo+ALFnkJVTOUcEM3sbl6pL7pOE=; b=sEerY5qa5cknQ4eXTMdNIuVjbaS3Ka96Hc9s0ksmn4CdjXA3ALKEd/RX2EBhPkiCbO tlDS6GPYLjNBGZ5mD+jW7+jJJtPYmQCsJ3MECdj67Ld7KZapoL24zvZ37JpttWbLo4OR cT/S1gkMe2FTUe7VP2noKXoSpI69MSSR64+suL8c3hY6dVunlLjKBuJvh6A+cDpOzmC9 6NJ8UI/abkbRRRgTztUEc29dCdiBBewVjd5CSEL35jRDmUaGIYVpWwXhlhTC9/LO2Etd ZeK2kR2CkoCCs2fw9SNJGq28KXpnhp0pyK0CFxRhjlb0apGaNZsr7aksHe5rKFy8SJT7 YJfw== X-Gm-Message-State: APjAAAW3a96AKbodAHKbpuSst+B9BRuQZU++FkoGR9mmWrvVCZX/Eoe4 wn3oBXRV4/UFdMhLjr/8K0wmNY/elgAYrAzdJE3f8g== X-Received: by 2002:a2e:898a:: with SMTP id c10mr2253609lji.177.1573130503712; Thu, 07 Nov 2019 04:41:43 -0800 (PST) MIME-Version: 1.0 References: <1572527274-21925-1-git-send-email-sumit.garg@linaro.org> <20191107110603.GA8790@jax> In-Reply-To: <20191107110603.GA8790@jax> From: Sumit Garg Date: Thu, 7 Nov 2019 18:11:32 +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 , etienne.carriere@linaro.org 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 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 -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 > >