mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: fangyu.yu@linux.alibaba.com
To: jgg@nvidia.com
Cc: alex@ghiti.fr, andrew.jones@linux.dev, aou@eecs.berkeley.edu,
	fangyu.yu@linux.alibaba.com, gong.shuai@sanechips.com.cn,
	gsh517025@gmail.com, guoren@kernel.org, iommu@lists.linux.dev,
	joro@8bytes.org, jroedel@suse.de, kvm-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	palmer@dabbelt.com, pjw@kernel.org, robin.murphy@arm.com,
	tomasz.jeznach@linux.dev, will@kernel.org, zong.li@sifive.com
Subject: Re: [RFC PATCH v2 3/4] iommu/riscv: Add guest IMSIC GPA mapping helpers
Date: Thu, 29 Oct 2026 21:34:42 +0800	[thread overview]
Message-ID: <20261029133442.82962-1-fangyu.yu@linux.alibaba.com> (raw)
In-Reply-To: <20261027141300.GB2338330@nvidia.com>

>> >His concern seems to be about who owns and maintains these mappings.
>> >When the RISC-V IOMMU driver calls iommu_map directly on a paging
>> >domain managed by iommufd, the mappings are not visible to the domain
>> >owner. This makes it difficult to handle mapping lifetime and
>> >hardware page table replacement correctly.
>> >
>>
>> Hi Shuai,
>>
>> Thanks for the review.
>>
>> Before going further, I want to make sure I answer the actual
>> question. If the concern is about who owns and maintains these
>> mappings, I address that below.
>>
>> The iommu_map() and replace_leaf() calls are not a separate
>> mapping facility added next to the forwarding code. They are
>> two steps in the existing interrupt-forwarding state machine
>> driven from iommu-ir.c:
>>
>>   - first FORWARD:      flat -> MSIPTE written /
>>                         noflat -> S2 PTE installed
>>   - UPDATE_TARGET:      flat -> MSIPTE updated /
>>                         noflat -> replace_leaf()
>>                          (only if the VS-file page moved)
>>   - last unforward:     flat -> MSI table deactivated /
>>                         noflat -> S2 PTE removed
>>
>> So the lifetime of the S2 mapping matches the lifetime of the
>> forwarding session, which is the same rule the MSI page table
>> already follows. The driver is the only layer that sees both
>> the forwarding session (device <-> vCPU) and the paging domain
>> used to translate guest MSI writes, so it is also the only
>> layer that can maintain this mapping.
>>
>> Note that the noflat column of the last row is not in v2: v2
>> only frees the bookkeeping when the domain is torn down. In
>> v3, I revoke the S2 entries both when the last forwarded IRQ
>> in the domain is released and at domain free, so the entry
>> lifetime becomes identical to the MSIPTE lifetime.
>
>The big point is interrupt code has to live in an irq_domain, not in
>the iommu driver, and the IOVA allocator is not part of either irq or
>iommu drivers.
>

Hi Jason,

Thanks, I agree that interrupt routing belongs in irq_domain, and IOVA
allocation belongs in dma-iommu/iommufd, not in the irq or iommu
drivers.

This series does not invent the interrupt-remapping structure; it
builds on Andrew's RISC-V IOMMU irqbypass v3 series:

  https://lore.kernel.org/linux-iommu/20260928143113.49838-1-
  andrew.jones@oss.qualcomm.com/

That series creates a DOMAIN_BUS_MSI_REMAP irq_domain under the MSI
parent, with an irq_chip whose .irq_set_vcpu_affinity is the
forwarding entry point. Our noflat support hooks into the same
callback and does not touch the DMA path in iommu.c.

There is no IOVA allocator involved in the noflat path. The mapped
address is the guest IMSIC GPA, a reserved guest MMIO window, and
what we install is a stage-2 translation from that GPA to the host
VS-file HPA. The IOMMU driver already owns the stage-2 tables for
this domain, so the update happens through the same irq_chip callback
used by the flat MSI case.

If you have a cleaner layering in mind, I'd be happy to discuss it.
For example, should irq_domain own a reserved S2 window and ask the
IOMMU driver for a primitive like "map GPA X to HPA Y in this
domain's S2"?

Thanks,
Fangyu

>So you have to layer this properly if you are going to even attempt
>it. It sounds complicated.
>
>Jason
>

  reply	other threads:[~2026-10-29 13:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 14:11 [RFC PATCH v2 0/4] iommu/riscv: Add irqbypass support without MSI page table fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 1/4] iommupt: Add replace_leaf to atomically swap a leaf OA fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 2/4] iommu/riscv: Extract IRQ forwarding payload validation fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 3/4] iommu/riscv: Add guest IMSIC GPA mapping helpers fangyu.yu
2026-10-15 23:47   ` Jason Gunthorpe
2026-10-16  3:01     ` fangyu.yu
2026-10-26  8:06       ` Gong Shuai
2026-10-27 14:08         ` fangyu.yu
2026-10-27 14:13           ` Jason Gunthorpe
2026-10-29 13:34             ` fangyu.yu [this message]
2026-10-14 14:11 ` [RFC PATCH v2 4/4] iommu/riscv: Support IRQ forwarding without MSI page tables fangyu.yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029133442.82962-1-fangyu.yu@linux.alibaba.com \
    --to=fangyu.yu@linux.alibaba.com \
    --cc=alex@ghiti.fr \
    --cc=andrew.jones@linux.dev \
    --cc=aou@eecs.berkeley.edu \
    --cc=gong.shuai@sanechips.com.cn \
    --cc=gsh517025@gmail.com \
    --cc=guoren@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=tomasz.jeznach@linux.dev \
    --cc=will@kernel.org \
    --cc=zong.li@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®