Re: [PATCH v8 7/7] iommu/riscv: Paging domain support

From: Robin Murphy
Date: Mon Aug 12 2024 - 09:13:05 EST


On 08/08/2024 5:40 pm, Easwar Hariharan wrote:
On 8/8/2024 6:14 AM, Jason Gunthorpe wrote:
On Tue, Aug 06, 2024 at 12:24:40PM -0700, Easwar Hariharan wrote:
On 6/14/2024 10:27 PM, Tomasz Jeznach wrote:

@@ -856,7 +1473,7 @@ static struct iommu_domain riscv_iommu_identity_domain = {
static int riscv_iommu_device_domain_type(struct device *dev)
{
- return IOMMU_DOMAIN_IDENTITY;
+ return 0;
}

<snip>
Sorry for the drive by comment, I just happen to be in the nearby code
context.

Nit: It may be better to use IOMMU_DOMAIN_BLOCKED here for readability
rather than the bare value.

It is weird and confusing, but 0 means "I have nothing to add" not
BLOCKED.

You can't return BLOCKED from this op right now..

Jason

Ok, that's weird and confusing as you say. I went back and looked at the
kerneldoc for iommu_ops and it IS called out, but it's confusing that a
function named get_default_domain_type() can return a value that's a
valid domain type but isn't treated as one.

This was useful to fill in my mental model, thanks!

Yeah, it's perhaps a bit subtle, but the context is that not all domain types are valid *default domain* types, those are strictly only DMA or identity, because the other types would be nonsensical. If a driver really wanted to completely block a device for some specific reason, it should do that by refusing to attach it to the default domain at all.

Thanks,
Robin.