iommu/riscv: Support Svpbmt memory types in generic_pt
Subsystems (4)
v3 cover iommu/riscv: Support Svpbmt memory types in generic_pt
From: Fangyu Yu <[email protected]>
RISC-V Svpbmt adds page-based memory types (PBMT) to PTEs, allowing mappings to be tagged as e.g. normal memory, non-cacheable memory, or I/O.
This series wires the RISC-V IOMMU Svpbmt capability into generic_pt and uses PBMT to encode device memory attributes for IOMMU mappings.
---
Changes in v3:
- Include RISCVPT_NC and RISCVPT_IO in riscvpt_attr_from_entry() to keep iommupt KUnit tests in sync.
- Link to v2:
https://lore.kernel.org/linux-riscv/[email protected]
---
Changes in v2:
- Add a comment for PT_FEAT_RISCV_SVPBMT (per Kevin and Jason).
- Clarify PBMT encoding condition, sort PBMT-related bits by position, and drop the redundant PBMT clear(per Kevin).
- Link to v1:
https://lore.kernel.org/linux-iommu/[email protected]/
Fangyu Yu (2):
iommu/riscv: Advertise Svpbmt support to generic page table
iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bits
drivers/iommu/generic_pt/fmt/riscv.h | 11 ++++++++++- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-)
Signature · 1 line
2.50.1
PATCH v3 1/2 iommu/riscv: Advertise Svpbmt support to generic page table
From: Fangyu Yu <[email protected]>
The RISC-V IOMMU can optionally support Svpbmt page-based memory types in its page table format. When present,the generic page table code can use this capability to encode memory attributes (e.g. MMIO vs normal memory) in PTEs.
--- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 4 ++++ 2 files changed, 6 insertions(+)
drivers/iommu/riscv/iommu.c +2 -0
@@ -1268,6 +1268,8 @@ static struct iommu_domain *riscv_iommu_alloc_paging_domain(struct device *dev) cfg.common.features =BIT (PT_FEAT_SIGN_EXTEND ) |BIT (PT_FEAT_FLUSH_RANGE ) |BIT (PT_FEAT_RISCV_SVNAPOT_64K ); +if (iommu->caps &RISCV_IOMMU_CAPABILITIES_SVPBMT ) + cfg.common.features |=BIT (PT_FEAT_RISCV_SVPBMT ); domain->riscvpt.iommu.nid =dev_to_node (iommu->dev); domain->domain.ops = &riscv_iommu_paging_domain_ops;
include/linux/generic_pt/common.h +4 -0
@@ -188,6 +188,10 @@ enum {* Support the 64k contiguous page size following the Svnapot extension. */ PT_FEAT_RISCV_SVNAPOT_64K =PT_FEAT_FMT_START , +/* +* Support Svpbmt extension: encode page-based memory type (PBMT) in PTEs. +*/ + PT_FEAT_RISCV_SVPBMT, };
Signature · 1 line
2.50.1
PATCH v3 2/2 iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bits
In reply to [email protected]From: Fangyu Yu <[email protected]>
When the RISC-V IOMMU page table format support Svpbmt, PBMT provides a way to tag mappings with page-based memory types. Encode memory type via PBMT in RISC-V IOMMU PTEs:
- IOMMU_MMIO -> PBMT=IO
- !IOMMU_MMIO && !IOMMU_CACHE -> PBMT=NC
- otherwise -> PBMT=Normal (PBMT=0)
Only touch PBMT when PT_FEAT_RISCV_SVPBMT is advertised.
--- drivers/iommu/generic_pt/fmt/riscv.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/generic_pt/fmt/riscv.h +10 -1
@@ -64,6 +64,8 @@ enum {RISCVPT_PPN64 =GENMASK_ULL (53 ,10 ),RISCVPT_PPN64_64K =GENMASK_ULL (53 ,14 ),RISCVPT_PBMT =GENMASK_ULL (62 ,61 ), +RISCVPT_NC =BIT (61 ), +RISCVPT_IO =BIT (62 ), RISCVPT_N = BIT_ULL(63),/* Svnapot encodings for ppn[0] */
@@ -201,7 +203,8 @@ static inline void riscvpt_attr_from_entry(const struct pt_state *pts, { attrs->descriptor_bits = pts->entry & (RISCVPT_R |RISCVPT_W |RISCVPT_X |RISCVPT_U | -RISCVPT_G |RISCVPT_A |RISCVPT_D ); +RISCVPT_G |RISCVPT_A |RISCVPT_D |RISCVPT_NC | +RISCVPT_IO ); }#define pt_attr_from_entry riscvpt_attr_from_entry
@@ -237,6 +240,12 @@ static inline int riscvpt_iommu_set_prot(struct pt_common *common, pte |=RISCVPT_R ;if (!(iommu_prot &IOMMU_NOEXEC )) pte |=RISCVPT_X ; +if (common->features &BIT (PT_FEAT_RISCV_SVPBMT )) { +if (iommu_prot &IOMMU_MMIO ) + pte |=RISCVPT_IO ; +else if (!(iommu_prot &IOMMU_CACHE )) + pte |=RISCVPT_NC ; + }/* Caller must specify a supported combination of flags */ if (unlikely ((pte & (RISCVPT_X |RISCVPT_W |RISCVPT_R )) ==0 ))
Signature · 1 line
2.50.1
Jörg Rödel
maintainerQuoted 8 lines · On Fri, Apr 17, 2026 at 10:07:44PM +0800, [email protected] wrote:
Fangyu Yu (2):
iommu/riscv: Advertise Svpbmt support to generic page table
iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bitsdrivers/iommu/generic_pt/fmt/riscv.h | 11 ++++++++++- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-)
Applied this one instead of v2.
Quoted 10 lines
Quoted 8 lines
Fangyu Yu (2):
iommu/riscv: Advertise Svpbmt support to generic page table
iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bitsdrivers/iommu/generic_pt/fmt/riscv.h | 11 ++++++++++- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-)Applied this one instead of v2.
Thanks for the review and for applying this version. I’ve sent a v4 update to fix the 32-bit build warning, so please use the v4 series going forward.
v4: https://lore.kernel.org/linux-riscv/[email protected]
[1] https://lore.kernel.org/oe-kbuild-all/[email protected]/
Thanks,
Fangyu
Quoted 9 lines · On Tue, May 12, 2026 at 03:53:39PM +0800, [email protected] wrote:
Quoted 9 lines
Quoted 8 lines
Fangyu Yu (2):
iommu/riscv: Advertise Svpbmt support to generic page table
iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bitsdrivers/iommu/generic_pt/fmt/riscv.h | 11 ++++++++++- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 1 line
Applied this one instead of v2.
Thanks for the review and for applying this version. I’ve sent a v4 update to fix the 32-bit build warning, so please use the v4 series going forward.
Since Joerg already applied it the normal thing is to send a fixup patch to correct the bot warning
Jason