Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5145008pxj; Wed, 9 Jun 2021 10:08:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu3fWrl56R/ICD4A76ia7n94DuCgImZApjbZC5hEX33MIvzBPz68uaG36H3/y2kjoLYQtP X-Received: by 2002:a17:906:3644:: with SMTP id r4mr887162ejb.140.1623258483608; Wed, 09 Jun 2021 10:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623258483; cv=none; d=google.com; s=arc-20160816; b=EgrBhNgwWBkZWJ31rP11ZUx1ANOaMMTdJDc6zJQSHZ0gEYy+i8uOP6WC7k7WxVfMfJ mRqlKYVOs5t2yRyCjl/XB4/CKHH5aujZAtgQtfIumesuiJt8d1190NHtuL0J/+IHNRX5 eJCyMv2H/4O3KRlIvVweklPipTY/nQtKTsSyvZ6cXMkvcO2asDtEVWcLVeiqbTH00AF+ t5zxDMvjmqztPGk0Dj8Siwn0I6MCi/KWWFH6Js7oMVtAhjFrZPc1rFJKLXKsCqaRV2xc c2A2imUF0A6DweOLzTGlmLOTJFC1MdfnAnJLoBBXQHhvPq4MUYo5Ygygoi0hSaAIuvRx 1HKQ== 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=s49P6l+xu1vflFN4QLmJCfSZvBVyezq9InIWh0eoZY8=; b=D5cVZOaAeblzkjmfUhDUDbRhH92y/OLpk8IScursS37gLrz+y1P0b6w4T5ouLb/iEq dvu7isnnJXvo+1F7Zn5Y6aBSQEdYbfUWT2AYpiSyY/+ccCOpExwf0f0HZ2LIxXT5RtBY 1mC5Dggq3XiZXQexs9rJn2tKhKFi87d5NSku3ZDhZzagpS8MXkziTXsEm8CGktkmf+PA nF02LGh+vxADUjkBKNYDON95b0Hqg/deEHbmLm2CrmTFa5zUEPUWfUVUBlrXa2WAdvCh VQlkmyXOpb0xvyPDNBVo7c8aWsagVofdJUxBh+i5yY7KVvMW3n+2mXfpIo9ve1kWN0jb TnXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rblvkurE; 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 c14si235661edr.15.2021.06.09.10.07.39; Wed, 09 Jun 2021 10:08:03 -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=rblvkurE; 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 S233650AbhFIEcX (ORCPT + 99 others); Wed, 9 Jun 2021 00:32:23 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:37439 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbhFIEcW (ORCPT ); Wed, 9 Jun 2021 00:32:22 -0400 Received: by mail-lf1-f42.google.com with SMTP id p7so1733327lfg.4 for ; Tue, 08 Jun 2021 21:30:18 -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=s49P6l+xu1vflFN4QLmJCfSZvBVyezq9InIWh0eoZY8=; b=rblvkurEZ17edKlzUlvor2BKX1S4M5Ir5iIXrAatPAyVLSAunLl8VWTIpV5DJCZu48 4f3X/0WA+TpUlXW9X6yrguwaOAmXWPhjqMe0i9cQcFEvKwhVZeTh61elv+26TbxKGt6i rKDj9Ea/1cgs6kMr7FS9VRPl6T13GIUzdUMAYA3Nt13cLwFoi4akncoOJuMJjLo3VqrB kdRvKZL0NdxQm4OsqgcroTxcosrvqKNdJmbeQ+cE+aK1AqoXtdXv0dEuoU9k6dKQDDmI GOK4D1YBsDLWk5XaOUsMJVu4ytaz6QYHMBJ1y2atqTBdkyUiBKKAq3vwyzDW2ta+zwrv l9rw== 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=s49P6l+xu1vflFN4QLmJCfSZvBVyezq9InIWh0eoZY8=; b=lZjbgmgzK321w4OWyY9p12q4YH0fn2EKqmN8RBnhfR+XI8wKVsa2ylublbk0/Rpm/z b39SJYzZr3ktNTqcm+xPImzFAXdsuJ1C55Oho6r9jmnrAsTYxy/susELRkY3Gc24G0Jt zphDO2dAenHkrmZQzd9NdJG4xQtS2lYb8AP2THzvSoXCwXCo0lSxRAw71TXccTCTwBf6 X3JTTWfJlc6jQTmgamdr1oGZXzAxzQuF0LC0v83rz7vOG3H3wAuH5UWAN1a3eDYzgHg0 GMOk2BGhhaWYRCBb6C9JgUY+wWDz/LfTC+skFAT/xR4pye6OvSyvXHU7ftT5er8SbLPh OSdw== X-Gm-Message-State: AOAM5339fgCrGrrnZb/KK8Bcx068ebYXmJUb01sBH5Yj0IphIGjad3qO 1nWspBgd3FHpvWwLRTRwY/iYBgZPA/wx3u+W2AlFvQ== X-Received: by 2002:a19:484d:: with SMTP id v74mr17541890lfa.396.1623212957298; Tue, 08 Jun 2021 21:29:17 -0700 (PDT) MIME-Version: 1.0 References: <20210609002326.210024-1-tyhicks@linux.microsoft.com> <20210609002326.210024-6-tyhicks@linux.microsoft.com> In-Reply-To: <20210609002326.210024-6-tyhicks@linux.microsoft.com> From: Sumit Garg Date: Wed, 9 Jun 2021 09:59:04 +0530 Message-ID: Subject: Re: [PATCH v3 5/7] tee: Support shm registration without dma-buf backing To: Tyler Hicks Cc: Jens Wiklander , Allen Pais , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Vikas Gupta , Thirupathaiah Annapureddy , Pavel Tatashin , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , op-tee@lists.trustedfirmware.org, linux-integrity , bcm-kernel-feedback-list@broadcom.com, 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 Tyler, On Wed, 9 Jun 2021 at 05:55, Tyler Hicks wrote: > > Uncouple the registration of dynamic shared memory buffers from the > TEE_SHM_DMA_BUF flag. Drivers may wish to allocate dynamic shared memory > regions but do not need them to be backed by a dma-buf when the memory > region is private to the driver. In this case drivers should use tee_shm_register() instead where the memory allocated is actually private to the driver. However, you need to remove TEE_SHM_DMA_BUF as a mandatory flag for tee_shm_register(). Have a look at an example here [1]. So modifying tee_shm_alloc() for this purpose doesn't look appropriate to me. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/keys/trusted-keys/trusted_tee.c#n73 -Sumit > > Allow callers of tee_shm_alloc() to specify the TEE_SHM_REGISTER flag to > request registration. If the TEE implementation does not require dynamic > shared memory to be registered, clear the flag prior to calling the > corresponding pool alloc function. Update the OP-TEE driver to respect > TEE_SHM_REGISTER, rather than TEE_SHM_DMA_BUF, when deciding whether to > (un)register on alloc/free operations. The AMD-TEE driver continues to > ignore the TEE_SHM_REGISTER flag. > > Signed-off-by: Tyler Hicks > --- > drivers/tee/optee/shm_pool.c | 5 ++--- > drivers/tee/tee_shm.c | 11 ++++++++++- > 2 files changed, 12 insertions(+), 4 deletions(-) > > diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c > index da06ce9b9313..6054343a29fb 100644 > --- a/drivers/tee/optee/shm_pool.c > +++ b/drivers/tee/optee/shm_pool.c > @@ -27,7 +27,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, > shm->paddr = page_to_phys(page); > shm->size = PAGE_SIZE << order; > > - if (shm->flags & TEE_SHM_DMA_BUF) { > + if (shm->flags & TEE_SHM_REGISTER) { > unsigned int nr_pages = 1 << order, i; > struct page **pages; > > @@ -42,7 +42,6 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, > page++; > } > > - shm->flags |= TEE_SHM_REGISTER; > rc = optee_shm_register(shm->ctx, shm, pages, nr_pages, > (unsigned long)shm->kaddr); > kfree(pages); > @@ -60,7 +59,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, > static void pool_op_free(struct tee_shm_pool_mgr *poolm, > struct tee_shm *shm) > { > - if (shm->flags & TEE_SHM_DMA_BUF) > + if (shm->flags & TEE_SHM_REGISTER) > optee_shm_unregister(shm->ctx, shm); > > free_pages((unsigned long)shm->kaddr, get_order(shm->size)); > diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c > index 00472f5ce22e..1c0176550b9c 100644 > --- a/drivers/tee/tee_shm.c > +++ b/drivers/tee/tee_shm.c > @@ -117,7 +117,7 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) > return ERR_PTR(-EINVAL); > } > > - if ((flags & ~(TEE_SHM_MAPPED | TEE_SHM_DMA_BUF))) { > + if ((flags & ~(TEE_SHM_MAPPED | TEE_SHM_DMA_BUF | TEE_SHM_REGISTER))) { > dev_err(teedev->dev.parent, "invalid shm flags 0x%x", flags); > return ERR_PTR(-EINVAL); > } > @@ -137,6 +137,15 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) > goto err_dev_put; > } > > + if (!teedev->desc->ops->shm_register || > + !teedev->desc->ops->shm_unregister) { > + /* registration is not required by the TEE implementation */ > + flags &= ~TEE_SHM_REGISTER; > + } else if (flags & TEE_SHM_DMA_BUF) { > + /* all dma-buf backed shm allocations are registered */ > + flags |= TEE_SHM_REGISTER; > + } > + > shm->flags = flags | TEE_SHM_POOL; > shm->ctx = ctx; > if (flags & TEE_SHM_DMA_BUF) > -- > 2.25.1 >