[RFC PATCH v2 07/10] iommu/riscv: Add domain_alloc_paging_flags for second-stage domain
fangyu.yu at linux.alibaba.com
fangyu.yu at linux.alibaba.com
Tue Aug 18 07:03:40 PDT 2026
>On Thu, May 07, 2026 at 07:37:03PM +0800, fangyu.yu at linux.alibaba.com wrote:
>...
>> + case IOMMU_HWPT_ALLOC_NEST_PARENT:
>> + case IOMMU_HWPT_ALLOC_DIRTY_TRACKING:
>> + case IOMMU_HWPT_ALLOC_DIRTY_TRACKING | IOMMU_HWPT_ALLOC_NEST_PARENT:
>> + /*
>> + * Second-stage (iohgatp) page table for KVM VFIO device
>> + * pass-through and dirty tracking. The GPA space is 2 bits
>> + * wider than the corresponding first-stage VA space (x4 root
>> + * page table), so hw_max_vasz_lg2 values are 41/50/59.
>> + */
>> + if (iommu->caps & RISCV_IOMMU_CAPABILITIES_SV57X4) {
>> + cfg.common.hw_max_vasz_lg2 = 59;
>> + } else if (iommu->caps & RISCV_IOMMU_CAPABILITIES_SV48X4) {
>> + cfg.common.hw_max_vasz_lg2 = 50;
>> + } else if (iommu->caps & RISCV_IOMMU_CAPABILITIES_SV39X4) {
>> + cfg.common.hw_max_vasz_lg2 = 41;
>> + } else {
>> + ret = -ENODEV;
>> + goto err_free;
>> + }
>> + domain->gscid = ida_alloc_range(&riscv_iommu_gscids, 1,
>> + RISCV_IOMMU_MAX_GSCID, GFP_KERNEL);
>> + if (domain->gscid < 0) {
>> + ret = -ENOMEM;
>> + goto err_free;
>> + }
>> + cfg.common.features |= BIT(PT_FEAT_RISCV_S2);
>
>cfg.common.features currently has PT_FEAT_SIGN_EXTEND which isn't correct
>for the second stage. So it needs to removed and then added back in for
>the first stage. riscv_64_kunit_fmt_cfgs[] in the kunit test will then
>need to also be updated.
Thanks, agreed. PT_FEAT_SIGN_EXTEND is only valid for first-stage
VA translation and should not be inherited by iohgatp domains. I'll move
PT_FEAT_SIGN_EXTEND into the first-stage allocation path, leave second-stage
domains with PT_FEAT_RISCV_S2 only, and update the RISC-V KUnit configs
accordingly in next version.
>
>Thanks,
>drew
More information about the linux-riscv
mailing list