linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jens Wiklander <jens.wiklander@linaro.org>
To: Robin Murphy <robin.murphy@arm.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	op-tee@lists.trustedfirmware.org,
	linux-arm-kernel@lists.infradead.org,
	"Olivier Masse" <olivier.masse@nxp.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Yong Wu" <yong.wu@mediatek.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
	"Brian Starkey" <Brian.Starkey@arm.com>,
	"John Stultz" <jstultz@google.com>,
	"T . J . Mercier" <tjmercier@google.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Sumit Garg" <sumit.garg@kernel.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	azarrabi@qti.qualcomm.com,
	"Simona Vetter" <simona.vetter@ffwll.ch>,
	"Daniel Stone" <daniel@fooishbar.org>,
	"Rouven Czerwinski" <rouven.czerwinski@linaro.org>
Subject: Re: [PATCH v8 06/14] tee: implement protected DMA-heap
Date: Tue, 6 May 2025 08:50:20 +0200	[thread overview]
Message-ID: <CAHUa44EQV5O+KZbE19-d-Z6Wu=HAQuGQmZe+mXZRpmdvRDbmSA@mail.gmail.com> (raw)
In-Reply-To: <6a33e85f-6b60-4260-993d-974dd29cf8e6@arm.com>

Hi,

On Fri, May 2, 2025 at 3:59 PM Robin Murphy <robin.murphy@arm.com> wrote:
>
> On 02/05/2025 10:59 am, Jens Wiklander wrote:
> > Implement DMA heap for protected DMA-buf allocation in the TEE
> > subsystem.
> >
> > Restricted memory refers to memory buffers behind a hardware enforced
> > firewall. It is not accessible to the kernel during normal circumstances
> > but rather only accessible to certain hardware IPs or CPUs executing in
> > higher or differently privileged mode than the kernel itself. This
> > interface allows to allocate and manage such protected memory buffers
> > via interaction with a TEE implementation.
> >
> > The protected memory is allocated for a specific use-case, like Secure
> > Video Playback, Trusted UI, or Secure Video Recording where certain
> > hardware devices can access the memory.
> >
> > The DMA-heaps are enabled explicitly by the TEE backend driver. The TEE
> > backend drivers needs to implement protected memory pool to manage the
> > protected memory.
>
> [...]> +static struct sg_table *
> > +tee_heap_map_dma_buf(struct dma_buf_attachment *attachment,
> > +                  enum dma_data_direction direction)
> > +{
> > +     struct tee_heap_attachment *a = attachment->priv;
> > +     int ret;
> > +
> > +     ret = dma_map_sgtable(attachment->dev, &a->table, direction,
> > +                           DMA_ATTR_SKIP_CPU_SYNC);
>
> If the memory is inaccessible to the kernel, what does this DMA mapping
> even mean? What happens when it tries to perform cache maintenance or
> bounce-buffering on inaccessible memory (which presumably doesn't even
> have a VA if it's not usable as normal kernel memory)?

Doesn't DMA_ATTR_SKIP_CPU_SYNC say that the kernel shouldn't perform
cache maintenance on the buffer since it's already in the device
domain? The device is expected to be permitted to access the memory.

>
> If we're simply housekeeping the TEE's resources on its behalf, and
> giving it back some token to tell it which resource to go do its thing
> with, then that's really not "DMA" as far as the kernel is concerned.

These buffers are supposed to be passed to devices that might be under
only partial control of the kernel.

>
> [...]
> > +static int protmem_pool_op_static_alloc(struct tee_protmem_pool *pool,
> > +                                     struct sg_table *sgt, size_t size,
> > +                                     size_t *offs)
> > +{
> > +     struct tee_protmem_static_pool *stp = to_protmem_static_pool(pool);
> > +     phys_addr_t pa;
> > +     int ret;
> > +
> > +     pa = gen_pool_alloc(stp->gen_pool, size);
> > +     if (!pa)
> > +             return -ENOMEM;
> > +
> > +     ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
> > +     if (ret) {
> > +             gen_pool_free(stp->gen_pool, pa, size);
> > +             return ret;
> > +     }
> > +
> > +     sg_set_page(sgt->sgl, phys_to_page(pa), size, 0);
>
> Where does "pa" come from here (i.e. what's the provenance of the
> initial "paddr" passed to tee_protmem_static_pool_alloc())? In general
> we can't call {phys,pfn}_to_page() an arbitrary addresses without
> checking pfn_valid() first. A bogus address might even crash
> __pfn_to_page() itself under CONFIG_SPARSEMEM.

That's a good point. Would it be enough to check the address with
pfn_valid() in tee_protmem_static_pool_alloc()?

I expect that the memory is normally carved out of DDR and made secure
or protected in a platform-specific way, either at boot with a static
carveout or dynamically after boot.

Thanks,
Jens


>
> Thanks,
> Robin.
>
> > +     *offs = pa - stp->pa_base;
> > +
> > +     return 0;
> > +}


  reply	other threads:[~2025-05-06  6:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02  9:59 [PATCH v8 00/14] TEE subsystem for protected dma-buf allocations Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 01/14] tee: tee_device_alloc(): copy dma_mask from parent device Jens Wiklander
2025-05-02 13:36   ` Robin Murphy
2025-05-05 12:10     ` Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 02/14] optee: pass parent device to tee_device_alloc() Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 03/14] optee: account for direction while converting parameters Jens Wiklander
2025-05-07 12:42   ` Sumit Garg
2025-05-07 13:07     ` Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 04/14] optee: sync secure world ABI headers Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 05/14] dma-buf: dma-heap: export declared functions Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 06/14] tee: implement protected DMA-heap Jens Wiklander
2025-05-02 13:59   ` Robin Murphy
2025-05-06  6:50     ` Jens Wiklander [this message]
2025-05-02  9:59 ` [PATCH v8 07/14] tee: refactor params_from_user() Jens Wiklander
2025-05-07 12:53   ` Sumit Garg
2025-05-02  9:59 ` [PATCH v8 08/14] tee: new ioctl to a register tee_shm from a dmabuf file descriptor Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 09/14] cma: export cma_alloc() and cma_release() Jens Wiklander
2025-05-02 15:49   ` Matthew Wilcox
2025-05-05 11:38     ` Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 10/14] dma-contiguous: export dma_contiguous_default_area Jens Wiklander
2025-05-02 13:11   ` Robin Murphy
2025-05-05 10:00     ` Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 11/14] tee: add tee_shm_alloc_cma_phys_mem() Jens Wiklander
2025-05-02 15:11   ` Robin Murphy
2025-05-07 16:32     ` Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 12/14] optee: support protected memory allocation Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 13/14] optee: FF-A: dynamic " Jens Wiklander
2025-05-02  9:59 ` [PATCH v8 14/14] optee: smc abi: " Jens Wiklander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHUa44EQV5O+KZbE19-d-Z6Wu=HAQuGQmZe+mXZRpmdvRDbmSA@mail.gmail.com' \
    --to=jens.wiklander@linaro.org \
    --cc=Brian.Starkey@arm.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=azarrabi@qti.qualcomm.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@fooishbar.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jstultz@google.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=olivier.masse@nxp.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=robin.murphy@arm.com \
    --cc=rouven.czerwinski@linaro.org \
    --cc=simona.vetter@ffwll.ch \
    --cc=sumit.garg@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=thierry.reding@gmail.com \
    --cc=tjmercier@google.com \
    --cc=yong.wu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).