From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
"Will Deacon" <will@kernel.org>,
"Robin Murphy" <robin.murphy@arm.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
iommu@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
"Detlev Casanova" <detlev.casanova@collabora.com>
Subject: Re: [PATCH 0/6] rust: iommu: add a paging domain abstraction
Date: Wed, 18 Nov 2026 16:56:40 -0500 [thread overview]
Message-ID: <70ed0df5a04b11d8dcfe41d91e86fc28dedcb132.camel@collabora.com> (raw)
In-Reply-To: <20261118195130.GE3115493@ziepe.ca>
[-- Attachment #1: Type: text/plain, Size: 8113 bytes --]
Le mercredi 18 novembre 2026 à 15:51 -0400, Jason Gunthorpe a écrit :
> On Wed, Nov 18, 2026 at 02:31:28PM -0500, Nicolas Dufresne wrote:
> > > > This seem to digress. All we want to do is use the iommu subsystem as intended
> > > > for the case the iommu driver is not inside the DRM driver (which seems to have
> > > > never been the case so far in DRM).
> > >
> > > "As intended" means you use the DMA API and you do not touch
> > > the paging domain.
> > >
> > > "As intended" means you use iommufd if you want a domain full of user
> > > controlled mappings.
> >
> > As discussed at LPC, we believe its pointless for this type of device to give
> > any direct page choices to userspace. Can you explain why you believe
> > differently?
>
> This is what was asked for a few messages back?
>
> > I'm not sure how this applies to our work. But since they are all broken
> > according to you, let me give example of cores/iommu mapping we are using, and
> > perhaps you'll be able to explain us correctly? I've picked the Rockchip video
> > decoder, which is upstream but expose through V4L2 stateless API, but from a
> > hardware point of view is pretty much identical:
> >
> > The DT (which I read you must be broken and in violation of everything, yet all
> > reviewed by DT maintainers):
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3588-base.dtsi#n1400
>
> You linked to a clocks line, I have no idea what I'm supposed to look
> at in this file. Can you explain what parts of the DT apply to what
> you are intersted in?
No, I linked to the four nodes, 2 decoders, 2 iommus.
>
> > The multi-core support proposal, its not doing process isolation, its not
> > strictly needed in higher level abstraction (though could be better), but its
> > using domains so that each core can actually see the same memory:
> > https://lore.kernel.org/all/20260810-rkvdec-multicore-v2-0-986f89d22cdc@collabora.com/
>
> IIRC This is the driver that had the weird not-quite-an-iommu issue and
> there were many complaints about it doing things with the API that
> make no sense because it's HW is bad.
>
> /*
> * To rewrite mapping into the attached IOMMU core, attach a new empty domain that
> * will program an empty table, then detach it to restore the default domain and
> * all cached mappings.
> * This is safely done in this interrupt handler to make sure no memory get mapped
> * through the IOMMU while the empty domain is attached.
> */
We are aware of this, someone have to find the time to go back to it and spend
another year in discussion to try and fit the need to re-program the rkiommu
after a decoder fault.
Our best guess of the hardware problem is that its "self reset" mechanism on
fault spill over the mmio of the iommu. It pretty hard to create a rkiommu
function that does not look like a bigger hack. And until we had an agreement,
this made it work for the users.
>
> But that doesn't excuse this:
>
> As each core has its own IOMMU core, buffers must be mapped in each
> core's IOMMU so that any run() call can use any core without having to
> remap everything.
>
> To do that, we use rockchip iommu domain's iommu devices list.
> With that, one IOMMU domain can be mapped on multiple devices, meaning
> that each call to iommu_map() will flush the new mapping on all devices
> in the list.
>
> We have DT for this already, you use iommus=[] and list all your
> iommus and it sets everything up for you. Going around and changing
> domains behind the scenes when the core already attached DMA API
Mind linking examples and doc? No one mentioned this, maybe the DT maintainer
need to be educated, you guys don't participate when these bindings are made.
Can we group the iommus from driver instead of DT ? (these DT predates us trying
to use the HW unfortunatly, so backward compatibility is kind of needed). Note
that appart from the hack above the v4l2 mutli-core case has completely static
domain, just that there is N device with the same domain. It is less safe, since
it does not do process isolation.
>
> Then WTF is this:
>
> - ret = iommu_map(iommu_get_domain_for_dev(core->dev),
> - virt_addr, phys_addr,
>
> Seriously? You cannot directly map to a DMA API owned domain. It is
> fully illegal.
I guess I should fix that one, suggested change below (I'll make a patch later).
We should drop iommu_map() from any bindings. But that leaves us with no way to
use the rkiommu and do process isolation, which basically defeat the purpose of
an iommu no?
RFC:
---
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
index fdcf1f1773797..37d5677e4c8f9 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
@@ -9,7 +9,7 @@
#include "rkvdec.h"
#include "rkvdec-rcb.h"
-#include <linux/iommu.h>
+#include <linux/dma-mapping.h>
#include <linux/genalloc.h>
#include <linux/sizes.h>
#include <linux/types.h>
@@ -44,7 +44,6 @@ void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
{
struct rkvdec_dev *dev = ctx->dev;
struct rkvdec_rcb_config *cfg = ctx->rcb_config;
- unsigned long virt_addr;
int i;
if (!cfg)
@@ -58,11 +57,11 @@ void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
switch (cfg->rcb_bufs[i].type) {
case RKVDEC_ALLOC_SRAM:
- virt_addr = (unsigned long)cfg->rcb_bufs[i].cpu;
-
- if (dev->iommu_domain)
- iommu_unmap(dev->iommu_domain, virt_addr, rcb_size);
- gen_pool_free(dev->sram_pool, virt_addr, rcb_size);
+ dma_unmap_resource(dev->dev, cfg->rcb_bufs[i].dma,
+ rcb_size, DMA_BIDIRECTIONAL, 0);
+ gen_pool_free(dev->sram_pool,
+ (unsigned long)cfg->rcb_bufs[i].cpu,
+ rcb_size);
break;
case RKVDEC_ALLOC_DMA:
dma_free_coherent(dev->dev,
@@ -125,29 +124,19 @@ int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
SZ_4K);
}
- /* If an IOMMU is used, map the SRAM address through it */
- if (cpu && rkvdec->iommu_domain) {
- unsigned long virt_addr = (unsigned long)cpu;
+ if (cpu) {
phys_addr_t phys_addr = dma;
- ret = iommu_map(rkvdec->iommu_domain, virt_addr, phys_addr,
- rcb_size, IOMMU_READ | IOMMU_WRITE, 0);
- if (ret) {
+ dma = dma_map_resource(rkvdec->dev, phys_addr, rcb_size,
+ DMA_BIDIRECTIONAL, 0);
+ if (dma_mapping_error(rkvdec->dev, dma)) {
gen_pool_free(ctx->dev->sram_pool,
(unsigned long)cpu,
rcb_size);
cpu = NULL;
- goto ram_fallback;
}
-
- /*
- * The registers will be configured with the virtual
- * address so that it goes through the IOMMU
- */
- dma = virt_addr;
}
-ram_fallback:
/* Fallback to RAM */
if (!cpu) {
cpu = dma_alloc_coherent(ctx->dev->dev,
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-18 21:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 17:00 [PATCH 0/6] rust: iommu: add a paging domain abstraction Daniel Almeida
2026-11-12 17:00 ` [PATCH 1/6] rust: iommu: move the protection flags to the module root Daniel Almeida
2026-11-12 17:00 ` [PATCH 2/6] rust: scatterlist: make SGTable::as_raw() visible to the crate Daniel Almeida
2026-11-12 17:00 ` [PATCH 3/6] rust: iommu: add the paging domain abstraction Daniel Almeida
2026-11-12 17:00 ` [PATCH 4/6] rust: iommu: add Domain::attach() Daniel Almeida
2026-11-16 21:54 ` Detlev Casanova
2026-11-12 17:00 ` [PATCH 5/6] rust: iommu: add Domain::map() Daniel Almeida
2026-11-12 17:00 ` [PATCH 6/6] rust: iommu: add Domain::with_fault_handler() Daniel Almeida
2026-11-16 19:38 ` [PATCH 0/6] rust: iommu: add a paging domain abstraction Jason Gunthorpe
2026-11-17 20:09 ` Daniel Almeida
2026-11-17 20:20 ` Jason Gunthorpe
2026-11-18 15:25 ` Nicolas Dufresne
2026-11-18 15:55 ` Daniel Almeida
2026-11-18 15:59 ` Daniel Almeida
2026-11-18 16:09 ` Jason Gunthorpe
2026-11-18 19:31 ` Nicolas Dufresne
2026-11-18 19:51 ` Jason Gunthorpe
2026-11-18 21:56 ` Nicolas Dufresne [this message]
2026-11-18 19:11 ` Daniel Almeida
2026-11-18 19:35 ` Jason Gunthorpe
2026-11-18 19:41 ` Nicolas Dufresne
2026-11-18 21:06 ` Jason Gunthorpe
2026-11-16 21:54 ` Detlev Casanova
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=70ed0df5a04b11d8dcfe41d91e86fc28dedcb132.camel@collabora.com \
--to=nicolas.dufresne@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=detlev.casanova@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
--cc=work@onurozkan.dev \
/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