Skip to content

[PW_SID:1091007] iommu/riscv: Add hardware dirty tracking for second-stage domains#1880

Closed
linux-riscv-bot wants to merge 11 commits into
workflow__riscv__fixesfrom
pw1091007
Closed

[PW_SID:1091007] iommu/riscv: Add hardware dirty tracking for second-stage domains#1880
linux-riscv-bot wants to merge 11 commits into
workflow__riscv__fixesfrom
pw1091007

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1091007 applied to workflow__riscv__fixes

Name: iommu/riscv: Add hardware dirty tracking for second-stage domains
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1091007
Version: 2

Linux RISC-V bot and others added 11 commits May 2, 2026 08:13
Add support for Sv39x4/Sv48x4/Sv57x4 Second-stage page tables used by
the RISC-V IOMMU iohgatp register. The x4 root page table is 16 KiB
instead of the usual 4 KiB, covering 2 extra GPA bits (hw_max_vasz_lg2
= 41/50/59).

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Implement the three dirty-tracking hooks required by the generic page
table framework for the RISC-V format:

  pt_entry_is_write_dirty():
    Check the D bit (bit 7) in the PTE.

  pt_entry_make_write_clean():
    Clear the D bit across the full contiguous range.

  pt_entry_make_write_dirty():
    Atomically set D via try_cmpxchg64() on a single PTE.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Report RISC-V IOMMU capabilities required by VFIO subsystem
to enable PCIe device assignment.

Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com>
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The parameter will be increased when we need to set up more
bit fields in the device context. Use a data structure to
wrap them up.

Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
This patch adds a ID Allocator for GSCID and a wrap for setting up
GSCID in IOTLB invalidation command.

Set up iohgatp to enable second stage table and flush stage-2 table if
the GSCID is set.

The GSCID of domain should be freed when release domain. GSCID will be
allocated for parent domain in nested IOMMU process.

Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Enable KVM/VFIO support on RISC-V architecture.

Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com>
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Replace .domain_alloc_paging with .domain_alloc_paging_flags so callers
can pass allocation flags to select the appropriate page-table type.

When IOMMU_HWPT_ALLOC_NEST_PARENT or IOMMU_HWPT_ALLOC_DIRTY_TRACKING is
set in @flags, allocate a second-stage (iohgatp) domain.

When @flags is 0 the behaviour is identical to the previous
domain_alloc_paging: first-stage (iosatp) domain.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Pre-enable RISCV_IOMMU_DC_TC_GADE in the device context when
attaching a second-stage domain, if the IOMMU supports AMO_HWAD.

Software pre-populates second-stage page tables with D set, so
enabling GADE by default does not change normal behavior. When
dirty tracking is enabled, iommufd clears the pre-set D bits and
GADE becomes necessary for hardware to update the dirty bit on
write access.

This avoids toggling GADE dynamically and keeps device context
setup consistent with second-stage domain attachment.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add hardware dirty tracking support for second-stage (iohgatp) domains
used in KVM VFIO device pass-through.

The RISC-V IOMMU can automatically set the dirty bit in PTEs on write
access when DC.tc.GADE is set and the hardware has AMO_HWAD capability.
Wire this up to the iommufd dirty tracking interface:

  - riscv_iommu_set_dirty_tracking(): Always enabled dirty tracking for
    second-stage domain.

  - riscv_iommu_dirty_ops: Exposes set_dirty_tracking and the generic
    page-table read_and_clear_dirty via IOMMU_PT_DIRTY_OPS(riscv_64).

  - domain_alloc_paging_flags: Assigns dirty_ops to second-stage domains
    when AMO_HWAD is advertised in hardware capabilities.

  - riscv_iommu_capable: Reports IOMMU_CAP_DIRTY_TRACKING when
    AMO_HWAD is present.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Previously, only IOTINVAL.VMA was issued, which is insufficient for
second-stage address translation consistency.

Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 138.64 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1156.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1696.65 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.90 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.46 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 86.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
kdoc
Desc: Detects for kdoc errors
Duration: 0.88 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
module-param
Desc: Detect module_param changes
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v2,01/10] iommupt: Add RISC-V Second-stage (iohgatp) page table support"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.69 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1130.19 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1674.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.09 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.93 seconds
Result: WARNING
Output:

CHECK: Please use a blank line after function/struct/union/enum declarations
#50: FILE: drivers/iommu/generic_pt/fmt/riscv.h:243:
+}
+#define pt_entry_is_write_dirty riscvpt_entry_is_write_dirty

CHECK: Please use a blank line after function/struct/union/enum declarations
#63: FILE: drivers/iommu/generic_pt/fmt/riscv.h:256:
+}
+#define pt_entry_make_write_clean riscvpt_entry_make_write_clean

CHECK: Please use a blank line after function/struct/union/enum declarations
#73: FILE: drivers/iommu/generic_pt/fmt/riscv.h:266:
+}
+#define pt_entry_make_write_dirty riscvpt_entry_make_write_dirty

total: 0 errors, 0 warnings, 3 checks, 49 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit ae32f287c90d ("iommupt: Add RISC-V dirty tracking PTE ops") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 0 warnings, 3 checks, 49 lines checked
CHECK: Please use a blank line after function/struct/union/enum declarations


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v2,02/10] iommupt: Add RISC-V dirty tracking PTE ops"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 86.59 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[RFC,v2,08/10] iommu/riscv: Pre-enable GADE for second-stage domains"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[RFC,v2,08/10] iommu/riscv: Pre-enable GADE for second-stage domains"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1135.49 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1683.90 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.49 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.01 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 85.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
kdoc
Desc: Detects for kdoc errors
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v2,09/10] iommu/riscv: Add dirty tracking support for second-stage domains"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.66 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1137.72 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1683.66 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.56 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.11 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.76 seconds
Result: WARNING
Output:

CHECK: Alignment should match open parenthesis
#34: FILE: drivers/iommu/riscv/iommu.c:1076:
+		riscv_iommu_cmd_inval_set_gscid(&cmd,
+			FIELD_GET(RISCV_IOMMU_DC_IOHGATP_GSCID, iohgatp));

total: 0 errors, 0 warnings, 1 checks, 18 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit eca49486916b ("iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 0 warnings, 1 checks, 18 lines checked
CHECK: Alignment should match open parenthesis


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 85.13 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
kdoc
Desc: Detects for kdoc errors
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 10: "[RFC,v2,10/10] iommu/riscv: Add IOTINVAL.GVMA after updating DDT/PDT entries"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__fixes branch 2 times, most recently from 2d4fcdd to cd9d421 Compare May 14, 2026 08:49
@linux-riscv-bot linux-riscv-bot deleted the pw1091007 branch May 15, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants