Skip to contentSkip to conversation

Support RISC-V IOPMP

PATCH Superseded Ethan Chen via 3 participants 20 messages Oct 25, 2023 – Oct 31, 2023

Subsystems (2)

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

cover Support RISC-V IOPMP

This series implements IOPMP specification v1.0.0-draft4 rapid-k model:
https://github.com/riscv-non-isa/iopmp-spec/blob/main/riscv_iopmp_specification.pdf

When IOPMP is enabled, a DMA device ATCDMAC300 is added to RISC-V virt platform. This DMA devce is connected to the IOPMP and has the functionalities required by IOPMP, including:
- Support specify source-id (SID)
- Support asynchronous I/O to handle stall transcations

Ethan Chen (6):
exec/memory: Introduce the translate_size function within the IOMMU
class
system/physmem: IOMMU: Invoke the translate_size function if it is
implemented
exec/memattrs: Add iopmp source id to MemTxAttrs
Add RISC-V IOPMP support
hw/dma: Add Andes ATCDMAC300 support
hw/riscv/virt: Add IOPMP support

 hw/dma/Kconfig                |   3 +
 hw/dma/atcdmac300.c           | 435 +++++++++++++++++
 hw/dma/meson.build            |   1 +
 hw/misc/Kconfig               |   3 +
 hw/misc/meson.build           |   1 +
 hw/misc/riscv_iopmp.c         | 881 ++++++++++++++++++++++++++++++++++
 hw/riscv/Kconfig              |   2 +
 hw/riscv/virt.c               |  72 ++-
 include/exec/memattrs.h       |   3 +
 include/exec/memory.h         |  19 +
 include/hw/dma/atcdmac300.h   | 171 +++++++
 include/hw/misc/riscv_iopmp.h | 322 +++++++++++++
 include/hw/riscv/virt.h       |  10 +-
 system/physmem.c              |   9 +-
 14 files changed, 1927 insertions(+), 5 deletions(-)
 create mode 100644 hw/dma/atcdmac300.c
 create mode 100644 hw/misc/riscv_iopmp.c
 create mode 100644 include/hw/dma/atcdmac300.h
 create mode 100644 include/hw/misc/riscv_iopmp.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/6 exec/memory: Introduce the translate_size function within the IOMMU class

IOMMU have size information during translation.

---
 include/exec/memory.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/exec/memory.h +19 -0
index 9087d02769..5520b7c8c0 100644
@@ -396,6 +396,25 @@ struct IOMMUMemoryRegionClass {
      */
     IOMMUTLBEntry (*translate)(IOMMUMemoryRegion *iommu, hwaddr addr,
                                IOMMUAccessFlags flag, int iommu_idx);
+    /**
+     * @translate_size:
+     *
+     * Return a TLB entry that contains a given address and size.
+     *
+     * @iommu: the IOMMUMemoryRegion
+     *
+     * @hwaddr: address to be translated within the memory region
+     *
+     * @size: size to indicate the scope of the entire transaction
+     *
+     * @flag: requested access permission
+     *
+     * @iommu_idx: IOMMU index for the translation
+     */
+    IOMMUTLBEntry (*translate_size)(IOMMUMemoryRegion *iommu, hwaddr addr,
+                                    hwaddr size, IOMMUAccessFlags flag,
+                                    int iommu_idx);
+
     /**
      * @get_min_page_size:
      *
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/6] exec/memory: Introduce the translate_size function within the IOMMU class

Quoted 2 lines · Ethan Chen

IOMMU have size information during translation.

Can you add some more information why we would want this and how the backend can do "better" things with the size at hand?

Note that I was not CCed on the cover letter.

Quoted 35 lines
---
  include/exec/memory.h | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
include/exec/memory.h +19 -0
index 9087d02769..5520b7c8c0 100644
@@ -396,6 +396,25 @@ struct IOMMUMemoryRegionClass {
       */
      IOMMUTLBEntry (*translate)(IOMMUMemoryRegion *iommu, hwaddr addr,
                                 IOMMUAccessFlags flag, int iommu_idx);
+    /**
+     * @translate_size:
+     *
+     * Return a TLB entry that contains a given address and size.
+     *
+     * @iommu: the IOMMUMemoryRegion
+     *
+     * @hwaddr: address to be translated within the memory region
+     *
+     * @size: size to indicate the scope of the entire transaction
+     *
+     * @flag: requested access permission
+     *
+     * @iommu_idx: IOMMU index for the translation
+     */
+    IOMMUTLBEntry (*translate_size)(IOMMUMemoryRegion *iommu, hwaddr addr,
+                                    hwaddr size, IOMMUAccessFlags flag,
+                                    int iommu_idx);
+
      /**
       * @get_min_page_size:
       *
Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw

Re: [PATCH 1/6] exec/memory: Introduce the translate_size function within the IOMMU class

Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Ethan Chen

IOMMU have size information during translation.

Can you add some more information why we would want this and how the backend can do "better" things with the size at hand?

With size information, IOMMU can reject a memory access which is patially in valid region.

Currently translation function limit memory access size with a mask, so the valid part of access will success. My target is to detect partially hit and reject whole access. Translation function cannot detect partially hit because it lacks size information.

Quoted 29 lines

Note that I was not CCed on the cover letter.

Quoted 27 lines
---
  include/exec/memory.h | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
include/exec/memory.h +14 -0
index 9087d02769..5520b7c8c0 100644
@@ -396,6 +396,25 @@ struct IOMMUMemoryRegionClass {
       */
      IOMMUTLBEntry (*translate)(IOMMUMemoryRegion *iommu, hwaddr addr,
                                 IOMMUAccessFlags flag, int iommu_idx);
+    /**
+     * @translate_size:
+     *
+     * Return a TLB entry that contains a given address and size.
+     *
+     * @iommu: the IOMMUMemoryRegion
+     *
+     * @hwaddr: address to be translated within the memory region
+     *
+     * @size: size to indicate the scope of the entire transaction
+     *
+     * @flag: requested access permission
+     *
+     * @iommu_idx: IOMMU index for the translation
Quoted 14 lines
Quoted 8 lines
include/exec/memory.h +5 -0
+     */
+    IOMMUTLBEntry (*translate_size)(IOMMUMemoryRegion *iommu, hwaddr addr,
+                                    hwaddr size, IOMMUAccessFlags flag,
+                                    int iommu_idx);
+
      /**
       * @get_min_page_size:
       *
Signature · 3 lines
Cheers,

David / dhildenb

Thanks,
Ethan Chen

#4 lore raw

Re: [PATCH 1/6] exec/memory: Introduce the translate_size function within the IOMMU class

Quoted 8 lines · Ethan Chen
Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Ethan Chen

IOMMU have size information during translation.

Can you add some more information why we would want this and how the backend can do "better" things with the size at hand?

Quoted 7 lines

With size information, IOMMU can reject a memory access which is patially in valid region.

Currently translation function limit memory access size with a mask, so the valid part of access will success. My target is to detect partially hit and reject whole access. Translation function cannot detect partially hit because it lacks size information.

Thanks; please add some of that to the patch description.

Signature · 3 lines
Cheers,

David / dhildenb
#5 lore raw

PATCH 2/6 system/physmem: IOMMU: Invoke the translate_size function if it is implemented

In reply to Ethan Chen via
---
 system/physmem.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
system/physmem.c +7 -2
index fc2b0fee01..53b6ab735c 100644
@@ -432,8 +432,13 @@ static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion *iomm
             iommu_idx = imrc->attrs_to_index(iommu_mr, attrs);
         }
 
-        iotlb = imrc->translate(iommu_mr, addr, is_write ?
-                                IOMMU_WO : IOMMU_RO, iommu_idx);
+        if (imrc->translate_size) {
+            iotlb = imrc->translate_size(iommu_mr, addr, *plen_out, is_write ?
+                                         IOMMU_WO : IOMMU_RO, iommu_idx);
+        } else {
+            iotlb = imrc->translate(iommu_mr, addr, is_write ?
+                                    IOMMU_WO : IOMMU_RO, iommu_idx);
+        }
 
         if (!(iotlb.perm & (1 << is_write))) {
             goto unassigned;
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 12 lines · Ethan Chen
---
 system/physmem.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
system/physmem.c +0 -0
index fc2b0fee01..53b6ab735c 100644
@@ -432,8 +432,13 @@ static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion *iomm
             iommu_idx = imrc->attrs_to_index(iommu_mr, attrs);
         }

system/physmem.c static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion *iomm · line 441

Quoted 10 lines
system/physmem.c +7 -2
 
-        iotlb = imrc->translate(iommu_mr, addr, is_write ?
-                                IOMMU_WO : IOMMU_RO, iommu_idx);
+        if (imrc->translate_size) {
+            iotlb = imrc->translate_size(iommu_mr, addr, *plen_out, is_write ?
+                                         IOMMU_WO : IOMMU_RO, iommu_idx);
+        } else {
+            iotlb = imrc->translate(iommu_mr, addr, is_write ?
+                                    IOMMU_WO : IOMMU_RO, iommu_idx);
+        }

Currently the translation size is encoded in iotlb.addr_mask. Can riscv do the same?

For example, lookup addr in match_entry_md() ranges, report size back into iotlb.addr_mask, rather than enforcing *plen_out range always resides in one translation only.

IMHO it's actually legal if *plen_out covers more than one IOMMU translations. QEMU memory core should have taken care of that by separately translate the ranges and apply RW on top. With current proposal of translate_size() I think it'll fail instead, which is not wanted.

Thanks,

Signature · 1 line
Peter Xu
#7 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 14 lines · Peter Xu
Quoted 13 lines · Ethan Chen
---
 system/physmem.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
system/physmem.c +0 -0
index fc2b0fee01..53b6ab735c 100644
@@ -432,8 +432,13 @@ static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion *iomm
             iommu_idx = imrc->attrs_to_index(iommu_mr, attrs);
         }
 
Quoted 12 lines

system/physmem.c static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion *iomm · line 441

Quoted 9 lines
system/physmem.c +7 -2
-        iotlb = imrc->translate(iommu_mr, addr, is_write ?
-                                IOMMU_WO : IOMMU_RO, iommu_idx);
+        if (imrc->translate_size) {
+            iotlb = imrc->translate_size(iommu_mr, addr, *plen_out, is_write ?
+                                         IOMMU_WO : IOMMU_RO, iommu_idx);
+        } else {
+            iotlb = imrc->translate(iommu_mr, addr, is_write ?
+                                    IOMMU_WO : IOMMU_RO, iommu_idx);
+        }

Currently the translation size is encoded in iotlb.addr_mask. Can riscv do the same?

Riscv do the same, so translation size may be reduced by iotlb.addr_mask.

Quoted 10 lines

For example, lookup addr in match_entry_md() ranges, report size back into iotlb.addr_mask, rather than enforcing *plen_out range always resides in one translation only.

IMHO it's actually legal if *plen_out covers more than one IOMMU translations. QEMU memory core should have taken care of that by separately translate the ranges and apply RW on top. With current proposal of translate_size() I think it'll fail instead, which is not wanted.

My target is to support IOPMP partially hit error. IOPMP checks whole memory access region is in the same entry. If not, reject the access instead of modify the access size.

Because most of IOPMP permisson checking features can be implemented by current IOMMU class, so I add this function in IOMMU class. There may be other more suitable ways to support partially hit error.

Quoted 5 lines

Thanks,

Signature · 1 line
Peter Xu

Thanks,
Ethan Chen

#8 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 3 lines · Ethan Chen

My target is to support IOPMP partially hit error. IOPMP checks whole memory access region is in the same entry. If not, reject the access instead of modify the access size.

Could you elaborate why is that important? In what use case?

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Thanks,

Signature · 1 line
Peter Xu
#9 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

In reply to Peter Xu
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

Thanks,
Ethan Chen

#10 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 17 lines · Ethan Chen
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Quoted 7 lines

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

I was expecting a DMA request can be fulfilled successfully as long as the DMA translations are valid for the whole range of the request, even if the requested range may include two separate translated targets or more, each point to different places (either RAM, or other devicie's MMIO regions).

AFAIK currently QEMU memory model will automatically split that large request into two or more smaller requests, and fulfill them separately by two/more IOMMU translations, with its memory access dispatched to the specific memory regions.

The example you provided doesn't seem to be RISCV specific. Do you mean it is a generic requirement from PCI/PCIe POV, or is it only a restriction of IOPMP? If it's a valid PCI restriction, does it mean that all the rest IOMMU implementations in QEMU currently are broken?

[copy Michael and Igor]

Thanks,

Signature · 1 line
Peter Xu
#11 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Add cc list.

Quoted 47 lines · Peter Xu
Quoted 17 lines · Ethan Chen
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Quoted 7 lines

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

I was expecting a DMA request can be fulfilled successfully as long as the DMA translations are valid for the whole range of the request, even if the requested range may include two separate translated targets or more, each point to different places (either RAM, or other devicie's MMIO regions).

AFAIK currently QEMU memory model will automatically split that large request into two or more smaller requests, and fulfill them separately by two/more IOMMU translations, with its memory access dispatched to the specific memory regions.

The example you provided doesn't seem to be RISCV specific. Do you mean it is a generic requirement from PCI/PCIe POV, or is it only a restriction of IOPMP? If it's a valid PCI restriction, does it mean that all the rest IOMMU implementations in QEMU currently are broken?

[copy Michael and Igor]

Thanks,

Signature · 1 line
Peter Xu
Signature · 1 line
Peter Xu
#12 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

In reply to Peter Xu
Quoted 33 lines · Peter Xu

Add cc list.

Quoted 30 lines · Peter Xu
Quoted 17 lines · Ethan Chen
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Quoted 7 lines

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

I was expecting a DMA request can be fulfilled successfully as long as the DMA translations are valid for the whole range of the request, even if the requested range may include two separate translated targets or more, each point to different places (either RAM, or other devicie's MMIO regions).

IOPMP is used to check DMA translation is vaild or not. In IOPMP specification , a translation access more than one entry is not invalid.
Though it is not recommand, user can create an IOPMP entry contains mutiple places to make this kind translations valid.

Quoted 5 lines
Quoted 5 lines

AFAIK currently QEMU memory model will automatically split that large request into two or more smaller requests, and fulfill them separately by two/more IOMMU translations, with its memory access dispatched to the specific memory regions.

Because of requests may be split, I need a method to take the original request information to IOPMP.

Quoted 6 lines
Quoted 6 lines

The example you provided doesn't seem to be RISCV specific. Do you mean it is a generic requirement from PCI/PCIe POV, or is it only a restriction of IOPMP? If it's a valid PCI restriction, does it mean that all the rest IOMMU implementations in QEMU currently are broken?

It only a restriction of IOPMP.

Thanks,
Ethan Chen

#13 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 41 lines · Ethan Chen
Quoted 33 lines · Peter Xu

Add cc list.

Quoted 30 lines · Peter Xu
Quoted 17 lines · Ethan Chen
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Quoted 7 lines

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

I was expecting a DMA request can be fulfilled successfully as long as the DMA translations are valid for the whole range of the request, even if the requested range may include two separate translated targets or more, each point to different places (either RAM, or other devicie's MMIO regions).

IOPMP is used to check DMA translation is vaild or not. In IOPMP specification , a translation access more than one entry is not invalid.
Though it is not recommand, user can create an IOPMP entry contains mutiple places to make this kind translations valid.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

AFAIK currently QEMU memory model will automatically split that large request into two or more smaller requests, and fulfill them separately by two/more IOMMU translations, with its memory access dispatched to the specific memory regions.

Because of requests may be split, I need a method to take the original request information to IOPMP.

I'm not sure whether translate() is the "original request" either. The problem is QEMU can split the request for various reasons already, afaict.

For example, address_space_translate_internal() has this:

    if (memory_region_is_ram(mr)) {
        diff = int128_sub(section->size, int128_make64(addr));
        *plen = int128_get64(int128_min(diff, int128_make64(*plen)));
    }

Which can already shrink the request size from the caller before reaching translate(). So the length passed into translate() can already be modified.

Another thing is, we have two other common call sites for translate():

memory_region_iommu_replay
address_space_translate_for_iotlb

I'm not sure whether you've looked into them and think they don't need to be trapped: at least memory_region_iommu_replay() looks all fine in this regard because it always translate in min page size granule. But I think the restriction should apply to all translate()s.

translate_size() is weird on its own. If the only purpose is to pass the length into translate(), another option is to add that parameter into current translate(), allowing the implementation to ignore it. I think that'll be better, but even if so, I'm not 100% sure it'll always do what you wanted as discussed above.

Thanks,

Signature · 1 line
Peter Xu
#14 lore raw

Re: [PATCH 2/6] system/physmem: IOMMU: Invoke the translate_size function if it is implemented

Quoted 74 lines · Peter Xu
Quoted 41 lines · Ethan Chen
Quoted 33 lines · Peter Xu

Add cc list.

Quoted 30 lines · Peter Xu
Quoted 17 lines · Ethan Chen
Quoted 1 line · Peter Xu

Could you elaborate why is that important? In what use case?

I was not involved in the formulation of the IOPMP specification, but I'll try to explain my perspective. IOPMP use the same the idea as PMP. "The matching PMP entry must match all bytes of an access, or the access fails."

Quoted 10 lines

Consider IOVA mapped for address range iova=[0, 4K] only, here we have a DMA request with range=[0, 8K]. Now my understanding is what you want to achieve is don't trigger the DMA to [0, 4K] and fail the whole [0, 8K] request.

Can we just fail at the latter DMA [4K, 8K] when it happens? After all, IIUC a device can split the 0-8K DMA into two smaller DMAs, then the 1st chunk can succeed then if it falls in 0-4K. Some further explanation of the failure use case could be helpful.

Quoted 7 lines

IOPMP can only detect partially hit in an access. DMA device will split a large DMA transfer to small DMA transfers base on target and DMA transfer width, so partially hit error only happens when an access cross the boundary. But to ensure that an access is only within one entry is still important. For example, an entry may mean permission of a device memory region. We do not want to see one DMA transfer can access mutilple devices, although DMA have permissions from multiple entries.

I was expecting a DMA request can be fulfilled successfully as long as the DMA translations are valid for the whole range of the request, even if the requested range may include two separate translated targets or more, each point to different places (either RAM, or other devicie's MMIO regions).

IOPMP is used to check DMA translation is vaild or not. In IOPMP specification , a translation access more than one entry is not invalid.
Though it is not recommand, user can create an IOPMP entry contains mutiple places to make this kind translations valid.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

AFAIK currently QEMU memory model will automatically split that large request into two or more smaller requests, and fulfill them separately by two/more IOMMU translations, with its memory access dispatched to the specific memory regions.

Because of requests may be split, I need a method to take the original request information to IOPMP.

I'm not sure whether translate() is the "original request" either. The problem is QEMU can split the request for various reasons already, afaict.

For example, address_space_translate_internal() has this:

    if (memory_region_is_ram(mr)) {
        diff = int128_sub(section->size, int128_make64(addr));
        *plen = int128_get64(int128_min(diff, int128_make64(*plen)));
    }

Which can already shrink the request size from the caller before reaching translate(). So the length passed into translate() can already be modified.

Another thing is, we have two other common call sites for translate():

memory_region_iommu_replay
address_space_translate_for_iotlb

I'm not sure whether you've looked into them and think they don't need to be trapped: at least memory_region_iommu_replay() looks all fine in this regard because it always translate in min page size granule. But I think the restriction should apply to all translate()s.

Quoted 5 lines

translate_size() is weird on its own. If the only purpose is to pass the length into translate(), another option is to add that parameter into current translate(), allowing the implementation to ignore it. I think that'll be better, but even if so, I'm not 100% sure it'll always do what you wanted as discussed above.

It seems that there are too many things that have not been considered in my current method. I am doing the revision that no new translation function but adding start address and end address to MemTxAttrs.

Since attrs_to_index() only return one interger, IOPMP attrs_to_index() will copy the address range to its device state and then handle the translate().

Thanks,
Ethan Chen

#15 lore raw

PATCH 3/6 exec/memattrs: Add iopmp source id to MemTxAttrs

In reply to Ethan Chen via
---
 include/exec/memattrs.h | 3 +++
 1 file changed, 3 insertions(+)
include/exec/memattrs.h +3 -0
index d04170aa27..e27b4fab00 100644
@@ -64,6 +64,9 @@ typedef struct MemTxAttrs {
     unsigned int target_tlb_bit0 : 1;
     unsigned int target_tlb_bit1 : 1;
     unsigned int target_tlb_bit2 : 1;
+
+    /* IOPMP support up to 65535 sources */
+    unsigned int iopmp_sid:16;
 } MemTxAttrs;
 
 /* Bus masters which don't specify any attributes will get this,
Signature · 1 line
2.34.1
#16 lore raw

PATCH 4/6 Add RISC-V IOPMP support

In reply to Ethan Chen via

Support specification Version 1.0.0-draft4 rapid-k model.

---
 hw/misc/Kconfig               |   3 +
 hw/misc/meson.build           |   1 +
 hw/misc/riscv_iopmp.c         | 881 ++++++++++++++++++++++++++++++++++
 include/hw/misc/riscv_iopmp.h | 322 +++++++++++++
 4 files changed, 1207 insertions(+)
 create mode 100644 hw/misc/riscv_iopmp.c
 create mode 100644 include/hw/misc/riscv_iopmp.h
hw/misc/Kconfig +3 -0
index dba41afe67..8c63eb4cef 100644
@@ -197,4 +197,7 @@ config DJMEMC
 config IOSB
     bool
 
+config RISCV_IOPMP
+    bool
+
 source macio/Kconfig
hw/misc/meson.build +1 -0
index f60de33f9a..7826ed9b7b 100644
@@ -35,6 +35,7 @@ system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c'))
+specific_ss.add(when: 'CONFIG_RISCV_IOPMP', if_true: files('riscv_iopmp.c'))
 
 subdir('macio')
 
hw/misc/riscv_iopmp.c new file +881 -0

881 lines not on this page · raw message

include/hw/misc/riscv_iopmp.h new file +322 -0

322 lines not on this page · raw message

Signature · 1 line
2.34.1
#17 lore raw

PATCH 5/6 hw/dma: Add Andes ATCDMAC300 support

In reply to Ethan Chen via
---
 hw/dma/Kconfig              |   3 +
 hw/dma/atcdmac300.c         | 435 ++++++++++++++++++++++++++++++++++++
 hw/dma/meson.build          |   1 +
 include/hw/dma/atcdmac300.h | 171 ++++++++++++++
 4 files changed, 610 insertions(+)
 create mode 100644 hw/dma/atcdmac300.c
 create mode 100644 include/hw/dma/atcdmac300.h
hw/dma/Kconfig +3 -0
index 98fbb1bb04..b3f4edc873 100644
@@ -30,3 +30,6 @@ config SIFIVE_PDMA
 config XLNX_CSU_DMA
     bool
     select REGISTER
+
+config ATCDMAC300
+    bool
hw/dma/atcdmac300.c new file +435 -0

435 lines not on this page · raw message

hw/dma/meson.build +1 -0
index a96c1be2c8..dfe37de32d 100644
@@ -14,3 +14,4 @@ system_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_dma.c'))
 system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_dma.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_PDMA', if_true: files('sifive_pdma.c'))
 system_ss.add(when: 'CONFIG_XLNX_CSU_DMA', if_true: files('xlnx_csu_dma.c'))
+system_ss.add(when: 'CONFIG_ATCDMAC300', if_true: files('atcdmac300.c'))
\ No newline at end of file
include/hw/dma/atcdmac300.h new file +171 -0

171 lines not on this page · raw message

Signature · 1 line
2.34.1
#18 lore raw

PATCH 6/6 hw/riscv/virt: Add IOPMP support

In reply to Ethan Chen via

- Add 'iopmp=on' option to enable iopmp
- Add 'iopmp_cascade=on' option to enable iopmp cascading.

---
 hw/riscv/Kconfig        |  2 ++
 hw/riscv/virt.c         | 72 +++++++++++++++++++++++++++++++++++++++--
 include/hw/riscv/virt.h | 10 +++++-
 3 files changed, 81 insertions(+), 3 deletions(-)
hw/riscv/Kconfig +2 -0
index b6a5eb4452..c30a104aa4 100644
@@ -45,6 +45,8 @@ config RISCV_VIRT
     select FW_CFG_DMA
     select PLATFORM_BUS
     select ACPI
+    select ATCDMAC300
+    select RISCV_IOPMP
 
 config SHAKTI_C
     bool
hw/riscv/virt.c +70 -2

107 lines not on this page · raw message

include/hw/riscv/virt.h +9 -1
index e5c474b26e..5fa2944d29 100644
@@ -54,6 +54,8 @@ struct RISCVVirtState {
 
     int fdt_size;
     bool have_aclint;
+    bool have_iopmp;
+    bool have_iopmp_cascade;
     RISCVVirtAIAType aia_type;
     int aia_guests;
     char *oem_id;
@@ -82,12 +84,18 @@ enum {
     VIRT_PCIE_MMIO,
     VIRT_PCIE_PIO,
     VIRT_PLATFORM_BUS,
-    VIRT_PCIE_ECAM
+    VIRT_PCIE_ECAM,
+    VIRT_IOPMP,
+    VIRT_IOPMP2,
+    VIRT_DMAC,
 };
 
 enum {
     UART0_IRQ = 10,
     RTC_IRQ = 11,
+    DMAC_IRQ = 12,
+    IOPMP_IRQ = 13,
+    IOPMP2_IRQ = 14,
     VIRTIO_IRQ = 1, /* 1 to 8 */
     VIRTIO_COUNT = 8,
     PCIE_IRQ = 0x20, /* 32 to 35 */
Signature · 1 line
2.34.1
#19 lore raw
In reply to Ethan Chen via

I found that after add size information it is still not enough for IOPMP to reject partially hit error. Access is separated in flatview_read_continue and lost the start address information. I will fix it in next version.

Address start, address end will be added to MemTxAttr, translate_size will beremoved and translate_attr which is have full MemTxAttr information will be added in next version patch.