dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jeffrey Kardatzke <jkardatzke@google.com>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"krzysztof.kozlowski+dt@linaro.org"
	<krzysztof.kozlowski+dt@linaro.org>,
	"Kuohong Wang (王國鴻)" <kuohong.wang@mediatek.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"sumit.semwal@linaro.org" <sumit.semwal@linaro.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"Jianjiao Zeng (曾健姣)" <Jianjiao.Zeng@mediatek.com>,
	"tjmercier@google.com" <tjmercier@google.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"jstultz@google.com" <jstultz@google.com>,
	"Joakim Bech" <joakim.bech@linaro.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"christian.koenig@amd.com" <christian.koenig@amd.com>,
	"Yong Wu (吴勇)" <Yong.Wu@mediatek.com>,
	"angelogioacchino.delregno@collabora.com"
	<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH 5/9] dma-buf: heaps: mtk_sec_heap: Initialise tee session
Date: Fri, 13 Oct 2023 12:10:56 -0700	[thread overview]
Message-ID: <CA+ddPcNMBhXPNie3XUzbnCME_KccOxsNsWREmO80nwhSskN7JQ@mail.gmail.com> (raw)
In-Reply-To: <32e515e1-b7a2-de3c-723b-ade3ec760b4d@collabora.com>

Sorry for the delayed reply, needed to get some more info. This really
wouldn't be possible due to the limitation on the number of
regions...for example only 32 regions can be defined on some SoCs, and
you'd run out of regions really fast trying to do this. That's why
this is creating heaps for those regions and then allocations are
performed within the defined region is the preferred strategy.


On Thu, Sep 28, 2023 at 11:54 PM Benjamin Gaignard
<benjamin.gaignard@collabora.com> wrote:
>
>
> Le 28/09/2023 à 19:48, Jeffrey Kardatzke a écrit :
> > On Thu, Sep 28, 2023 at 1:30 AM Benjamin Gaignard
> > <benjamin.gaignard@collabora.com> wrote:
> >>
> >> Le 27/09/2023 à 20:56, Jeffrey Kardatzke a écrit :
> >>> On Wed, Sep 27, 2023 at 8:18 AM Benjamin Gaignard
> >>> <benjamin.gaignard@collabora.com> wrote:
> >>>> Le 27/09/2023 à 15:46, Joakim Bech a écrit :
> >>>>> On Mon, Sep 25, 2023 at 12:49:50PM +0000, Yong Wu (吴勇) wrote:
> >>>>>> On Tue, 2023-09-12 at 11:32 +0200, AngeloGioacchino Del Regno wrote:
> >>>>>>> Il 12/09/23 08:17, Yong Wu (吴勇) ha scritto:
> >>>>>>>> On Mon, 2023-09-11 at 11:29 +0200, AngeloGioacchino Del Regno
> >>>>>>>> wrote:
> >>>>>>>>> Il 11/09/23 04:30, Yong Wu ha scritto:
> >>>>>>>>>> The TEE probe later than dma-buf heap, and PROBE_DEDER doesn't
> >>>>>>>>>> work
> >>>>>>>>>> here since this is not a platform driver, therefore initialise
> >>>>>>>>>> the
> >>>>>>>>>> TEE
> >>>>>>>>>> context/session while we allocate the first secure buffer.
> >>>>>>>>>>
> >>>>>>>>>> Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> >>>>>>>>>> ---
> >>>>>>>>>>       drivers/dma-buf/heaps/mtk_secure_heap.c | 61
> >>>>>>>>>> +++++++++++++++++++++++++
> >>>>>>>>>>       1 file changed, 61 insertions(+)
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/drivers/dma-buf/heaps/mtk_secure_heap.c
> >>>>>>>>>> b/drivers/dma-
> >>>>>>>>>> buf/heaps/mtk_secure_heap.c
> >>>>>>>>>> index bbf1c8dce23e..e3da33a3d083 100644
> >>>>>>>>>> --- a/drivers/dma-buf/heaps/mtk_secure_heap.c
> >>>>>>>>>> +++ b/drivers/dma-buf/heaps/mtk_secure_heap.c
> >>>>>>>>>> @@ -10,6 +10,12 @@
> >>>>>>>>>>       #include <linux/err.h>
> >>>>>>>>>>       #include <linux/module.h>
> >>>>>>>>>>       #include <linux/slab.h>
> >>>>>>>>>> +#include <linux/tee_drv.h>
> >>>>>>>>>> +#include <linux/uuid.h>
> >>>>>>>>>> +
> >>>>>>>>>> +#define TZ_TA_MEM_UUID          "4477588a-8476-11e2-ad15-
> >>>>>>>>>> e41f1390d676"
> >>>>>>>>>> +
> >>>>>>>>> Is this UUID the same for all SoCs and all TZ versions?
> >>>>>>>> Yes. It is the same for all SoCs and all TZ versions currently.
> >>>>>>>>
> >>>>>>> That's good news!
> >>>>>>>
> >>>>>>> Is this UUID used in any userspace component? (example: Android
> >>>>>>> HALs?)
> >>>>>> No. Userspace never use it. If userspace would like to allocate this
> >>>>>> secure buffer, it can achieve through the existing dmabuf IOCTL via
> >>>>>> /dev/dma_heap/mtk_svp node.
> >>>>>>
> >>>>> In general I think as mentioned elsewhere in comments, that there isn't
> >>>>> that much here that seems to be unique for MediaTek in this patch
> >>>>> series, so I think it worth to see whether this whole patch set can be
> >>>>> made more generic. Having said that, the UUID is always unique for a
> >>>>> certain Trusted Application. So, it's not entirely true saying that the
> >>>>> UUID is the same for all SoCs and all TrustZone versions. It might be
> >>>>> true for a family of MediaTek devices and the TEE in use, but not
> >>>>> generically.
> >>>>>
> >>>>> So, if we need to differentiate between different TA implementations,
> >>>>> then we need different UUIDs. If it would be possible to make this patch
> >>>>> set generic, then it sounds like a single UUID would be sufficient, but
> >>>>> that would imply that all TA's supporting such a generic UUID would be
> >>>>> implemented the same from an API point of view. Which also means that
> >>>>> for example Trusted Application function ID's needs to be the same etc.
> >>>>> Not impossible to achieve, but still not easy (different TEE follows
> >>>>> different specifications) and it's not typically something we've done in
> >>>>> the past.
> >>>>>
> >>>>> Unfortunately there is no standardized database of TA's describing what
> >>>>> they implement and support.
> >>>>>
> >>>>> As an alternative, we could implement a query call in the TEE answering,
> >>>>> "What UUID does your TA have that implements secure unmapped heap?".
> >>>>> I.e., something that reminds of a lookup table. Then we wouldn't have to
> >>>>> carry this in UAPI, DT or anywhere else.
> >>>> Joakim does a TA could offer a generic API and hide the hardware specific
> >>>> details (like kernel uAPI does for drivers) ?
> >>> It would have to go through another layer (like the tee driver) to be
> >>> a generic API. The main issue with TAs is that they have UUIDs you
> >>> need to connect to and specific codes for each function; so we should
> >>> abstract at a layer above where those exist in the dma-heap code.
> >>>> Aside that question I wonder what are the needs to perform a 'secure' playback.
> >>>> I have in mind 2 requirements:
> >>>> - secure memory regions, which means configure the hardware to ensure that only
> >>>> dedicated hardware blocks and read or write into it.
> >>>> - set hardware blocks in secure modes so they access to secure memory.
> >>>> Do you see something else ?
> >>> This is more or less what is required, but this is out of scope for
> >>> the Linux kernel since it can't be trusted to do these things...this
> >>> is all done in firmware or the TEE itself.
> >> Yes kernel can't be trusted to do these things but know what we need could help
> >> to define a API for a generic TA.
> >>
> >> Just to brainstorm on mailing list:
> >> What about a TA API like
> >> TA_secure_memory_region() and TA_unsecure_memory_region() with parameters like:
> >> - device identifier (an ID or compatible string maybe)
> >> - memory region (physical address, size, offset)
> >> - requested access rights (read, write)
> >>
> >> and on kernel side a IOMMU driver because it basically have all this information already
> >> (device attachment, kernel map/unmap).
> >>
> >> In my mind it sound like a solution to limit the impact (new controls, new memory type)
> >> inside v4l2. Probably we won't need new heap either.
> >> All hardware dedicated implementations could live inside the TA which can offer a generic
> >> API.
> > The main problem with that type of design is the limitations of
> > TrustZone memory protection. Usually there is a limit to the number of
> > regions you can define for memory protection (and there is on
> > Mediatek). So you can't pass an arbitrary memory region and mark it
> > protected/unprotected at a given time. You need to establish these
> > regions in the firmware instead and then configure those regions for
> > protection in the firmware or the TEE.
>
> The TEE iommu could be aware of these limitations and merge the regions when possible
> plus we can define a CMA region for each device to limit the secured memory fragmentation.
>
> >
> >>>> Regards,
> >>>> Benjamin
> >>>>

  parent reply	other threads:[~2023-10-13 19:11 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11  2:30 [PATCH 0/9] dma-buf: heaps: Add MediaTek secure heap Yong Wu
2023-09-11  2:30 ` [PATCH 1/9] dma-buf: heaps: Deduplicate docs and adopt common format Yong Wu
2023-09-11  9:36   ` Christian König
2023-09-11 23:51     ` T.J. Mercier
2023-09-11  2:30 ` [PATCH 2/9] dma-heap: Add proper kref handling on dma-buf heaps Yong Wu
2023-09-11  9:48   ` Christian König
2023-09-22 18:19     ` T.J. Mercier
2023-09-11  2:30 ` [PATCH 3/9] dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps Yong Wu
2023-09-11 10:13   ` Christian König
2023-09-11 18:29     ` John Stultz
2023-09-12  7:06       ` Christian König
2023-09-12  8:52         ` Yong Wu (吴勇)
2023-09-12 14:46           ` Christian König
2023-09-12 14:58             ` Nicolas Dufresne
2023-09-13  8:30               ` Christian König
2023-09-12 14:50     ` Nicolas Dufresne
2023-09-11 16:12   ` Nicolas Dufresne
2023-09-12  8:47     ` Yong Wu (吴勇)
2023-09-12 15:05       ` Nicolas Dufresne
2023-09-18 10:46         ` Yong Wu (吴勇)
2023-09-11  2:30 ` [PATCH 4/9] dma-buf: heaps: Initialise MediaTek secure heap Yong Wu
2023-09-11  8:05   ` kernel test robot
2023-09-27 14:42   ` Joakim Bech
2023-09-28  8:03     ` Yong Wu (吴勇)
2023-10-19  4:45   ` Vijayanand Jitta
2023-10-20  9:59     ` Yong Wu (吴勇)
2023-10-26  4:48       ` Vijayanand Jitta
2023-10-27  7:47         ` Yong Wu (吴勇)
2023-10-30  8:06           ` Vijayanand Jitta
2023-09-11  2:30 ` [PATCH 5/9] dma-buf: heaps: mtk_sec_heap: Initialise tee session Yong Wu
2023-09-11  9:29   ` AngeloGioacchino Del Regno
2023-09-11 10:15     ` Christian König
2023-09-12  6:17     ` Yong Wu (吴勇)
2023-09-12  9:32       ` AngeloGioacchino Del Regno
2023-09-25 12:49         ` Yong Wu (吴勇)
2023-09-27 13:46           ` Joakim Bech
2023-09-27 15:17             ` Benjamin Gaignard
2023-09-27 18:56               ` Jeffrey Kardatzke
2023-09-28  8:30                 ` Benjamin Gaignard
2023-09-28 17:48                   ` Jeffrey Kardatzke
2023-09-29  6:54                     ` Benjamin Gaignard
2023-10-13 19:09                       ` Jeffrey Kardatzke
2023-10-13 19:10                       ` Jeffrey Kardatzke [this message]
2023-09-27 18:54             ` Jeffrey Kardatzke
2023-09-13 13:35   ` kernel test robot
2023-09-11  2:30 ` [PATCH 6/9] dma-buf: heaps: mtk_sec_heap: Add tee service call for buffer allocating/freeing Yong Wu
2023-09-14 10:18   ` kernel test robot
2023-09-27 14:37   ` Joakim Bech
2023-09-28  5:24     ` Yong Wu (吴勇)
2023-10-19  4:45   ` Vijayanand Jitta
2023-10-20 10:01     ` Yong Wu (吴勇)
2023-09-11  2:30 ` [PATCH 7/9] dma-buf: heaps: mtk_sec_heap: Add dma_ops Yong Wu
2023-09-11  2:30 ` [PATCH 8/9] dt-bindings: reserved-memory: MediaTek: Add reserved memory for SVP Yong Wu
2023-09-11 15:44   ` Rob Herring
2023-09-12  6:16     ` Yong Wu (吴勇)
2023-09-12  8:28       ` Krzysztof Kozlowski
2023-09-12 10:13         ` Robin Murphy
2023-09-12 15:53           ` Rob Herring
2023-09-12 16:05             ` Robin Murphy
2023-09-18 10:47             ` Yong Wu (吴勇)
2023-09-19 22:15               ` Jeffrey Kardatzke
2023-10-12  6:54                 ` Yong Wu (吴勇)
2023-10-12  7:07                   ` Krzysztof Kozlowski
2023-10-12 11:15                     ` Yong Wu (吴勇)
2023-10-19  4:46   ` Vijayanand Jitta
2023-10-20  9:50     ` Yong Wu (吴勇)
2023-11-01  5:50       ` Jaskaran Singh
2023-11-06  5:56         ` Yong Wu (吴勇)
2023-11-20  8:20           ` Jaskaran Singh
2023-09-11  2:30 ` [PATCH 9/9] dma_buf: heaps: mtk_sec_heap: Add a new CMA heap Yong Wu
2023-09-11  9:33   ` AngeloGioacchino Del Regno
2023-10-19  4:44 ` [PATCH 0/9] dma-buf: heaps: Add MediaTek secure heap Vijayanand Jitta

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=CA+ddPcNMBhXPNie3XUzbnCME_KccOxsNsWREmO80nwhSskN7JQ@mail.gmail.com \
    --to=jkardatzke@google.com \
    --cc=Jianjiao.Zeng@mediatek.com \
    --cc=Yong.Wu@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=christian.koenig@amd.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=joakim.bech@linaro.org \
    --cc=jstultz@google.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuohong.wang@mediatek.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=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tjmercier@google.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).