From: Ruslan Ruslichenko <ruslichenko.r@gmail.com>
To: "Clément MATHIEU--DRIF" <clement.mathieu--drif@bull.com>,
"Ruslan Ruslichenko" <ruslichenko.r@gmail.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "qemu-arm@nongnu.org" <qemu-arm@nongnu.org>,
"artem_mygaiev@epam.com" <artem_mygaiev@epam.com>,
"volodymyr_babchuk@epam.com" <volodymyr_babchuk@epam.com>,
"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
"francisco.iglesias@amd.com" <francisco.iglesias@amd.com>,
"edgar.iglesias@gmail.com" <edgar.iglesias@gmail.com>,
"berrange@redhat.com" <berrange@redhat.com>,
"eugene@nuvacore.ai" <eugene@nuvacore.ai>,
"Ruslan_Ruslichenko@epam.com" <Ruslan_Ruslichenko@epam.com>,
"takahiro.nakata.wr@renesas.com" <takahiro.nakata.wr@renesas.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Edgar E . Iglesias" <edgar.iglesias@amd.com>
Subject: Re: [PATCH v2 12/20] system/physmem: Add ats_do_translate helper
Date: Fri, 16 Oct 2026 21:28:52 +0200 [thread overview]
Message-ID: <068f6239-9a04-4182-9e45-19fe38106184@gmail.com> (raw)
In-Reply-To: <d29965e800482e96e8f42c8307900f665eb61a69.camel@bull.com>
On 10/15/26 11:40, Clément MATHIEU--DRIF wrote:
>
> On Wed, 2026-10-14 at 10:21 +0200, Ruslan Ruslichenko wrote:
>> Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
>>
>>
>> On 10/13/26 16:27, Clément MATHIEU--DRIF wrote:
>>
>>> Do you need to operate at physmem level?
>>> We have an API for PCI device for ATS and PRI (see pci_ats_request_translation and pci_pri_unregister_notifier)
>>>
>>
>>
>> This helper is used by Remote-Port-ATS device, which is used for resolving ATS requests from remote masters via RemotePort link and it is TYPE_DEVICE itself.
>> As it is not a PCI device itself, we cannot use PCI API unfortunately.
>>
>
> Ok, I see,
>
> The issue I see here is that we are basically re-implemeting what IOMMUs already do through the PCI API.
> It looks like there is a risk here as some IOMMUs might want to update their state when being called on ATS/PRI, which won't be done here.
>
> I'm not super familiar with RemotePort but I have a high level overview of what some companies do to bridge rtl simulators with a PCI bus in Qemu.
> IIUC, the bus type of the simulator is known, and their bridge allocates an emulated device of the matching type in Qemu so they can call the official APIs as if there was a "real" emulated device.
>
> In your use case, what kind of devices are you running in the external simulator? PCI I guess?
>
The most common usage of ATS and remote-port-ats is indeed bound to PCI subsystem.
For reference, in Remote Port subsystem it is used by remote-port-pci-device and remote-port-pcie-root-port in Xilinx tree:
https://github.com/Xilinx/qemu/blob/master/hw/core/remote-port-pci-device.c
https://github.com/Xilinx/qemu/blob/master/hw/core/remote-port-pcie-root-port.c
And since there is already existing 'pci_ats_request_translation' API, I agree it is a cleaner and more correct approach.
I think, ATS device can use PCIDevice created by those models and call pci_ats_request_translation(), which removes the need for physmem-level helper.
Although, the 'ats_request_translation' is currently implemented only by the Intel IOMMU, ARM SMMU don't implement it, so this needs to be done too.
In our case we have a use case where a device on the platform bus, behind SMMU also wants to use ATS requests.
But those likely require separate approach and it belongs to SMMU for platform bus series, such as:
https://lists.nongnu.org/archive/html/qemu-devel/2025-12/msg02637.html
So will drop 'ats_do_translate' for the next revision.
Thanks for the feedback!
--
Best Regards,
Ruslan
>>
>>> On Tue, 2026-09-15 at 18:00 +0200, Ruslan Ruslichenko wrote:
>>>
>>>> From: Ruslan Ruslichenko <[[Ruslan_Ruslichenko@epam.com](mailto:Ruslan_Ruslichenko@epam.com)](mailto:[Ruslan_Ruslichenko@epam.com](mailto:Ruslan_Ruslichenko@epam.com))>
>>>>
>>>> Add 'ats_do_translate' method to enable manual IOMMU address
>>>> translation.
>>>>
>>>> This allows the Remote Port subsystem to resolve guest virtual
>>>> addresses to physical addresses by querying the QEMU IOMMU
>>>> translation pipeline. This is required for the Remote Port
>>>> subsystem to support translation requests from external masters
>>>> in a co-simulation environment.
>>>>
>>>> Signed-off-by: Edgar E. Iglesias <[[edgar.iglesias@amd.com](mailto:edgar.iglesias@amd.com)](mailto:[edgar.iglesias@amd.com](mailto:edgar.iglesias@amd.com))>
>>>> Signed-off-by: Takahiro Nakata <[[takahiro.nakata.wr@renesas.com](mailto:takahiro.nakata.wr@renesas.com)](mailto:[takahiro.nakata.wr@renesas.com](mailto:takahiro.nakata.wr@renesas.com))>
>>>> Signed-off-by: Ruslan Ruslichenko <[[Ruslan_Ruslichenko@epam.com](mailto:Ruslan_Ruslichenko@epam.com)](mailto:[Ruslan_Ruslichenko@epam.com](mailto:Ruslan_Ruslichenko@epam.com))>
>>>> ---
>>>> include/system/memory.h | 8 +++++++
>>>> system/physmem.c | 53 +++++++++++++++++++++++++++++++++++++++++
>>>> 2 files changed, 61 insertions(+)
>>>>
>>>> diff --git a/include/system/memory.h b/include/system/memory.h
>>>> index a7e03fc3e7..2032d3028d 100644
>>>> --- a/include/system/memory.h
>>>> +++ b/include/system/memory.h
>>>> @@ -2583,6 +2583,14 @@ static inline MemoryRegion *address_space_translate(AddressSpace *as,
>>>> addr, xlat, len, is_write, attrs);
>>>> }
>>>>
>>>> +MemoryRegion *ats_do_translate(AddressSpace *as,
>>>> + hwaddr addr,
>>>> + hwaddr *xlat,
>>>> + hwaddr *plen_out,
>>>> + AddressSpace **target_as,
>>>> + int *prot,
>>>> + MemTxAttrs attrs);
>>>> +
>>>> /* address_space_access_valid: check for validity of accessing an address
>>>> * space range
>>>> *
>>>> diff --git a/system/physmem.c b/system/physmem.c
>>>> index a4a6a4710c..1acda22ede 100644
>>>> --- a/system/physmem.c
>>>> +++ b/system/physmem.c
>>>> @@ -525,6 +525,59 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv,
>>>> return *section;
>>>> }
>>>>
>>>> +/* This function is called from RCU critical section */
>>>> +MemoryRegion *ats_do_translate(AddressSpace *as,
>>>> + hwaddr addr,
>>>> + hwaddr *xlat,
>>>> + hwaddr *plen_out,
>>>> + AddressSpace **target_as,
>>>> + int *prot,
>>>> + MemTxAttrs attrs)
>>>> +{
>>>> + MemoryRegionSection *section;
>>>> + IOMMUMemoryRegion *iommu_mr;
>>>> + hwaddr plen = (hwaddr)(-1);
>>>> + FlatView *fv = address_space_to_flatview(as);
>>>> + IOMMUMemoryRegionClass *imrc;
>>>> + IOMMUTLBEntry iotlb;
>>>> + int iommu_idx = 0;
>>>> +
>>>> + if (!plen_out) {
>>>> + plen_out = &plen;
>>>> + }
>>>> +
>>>> + /* This can be MMIO, so setup MMIO bit. */
>>>> + section = address_space_translate_internal(
>>>> + flatview_to_dispatch(fv), addr, xlat,
>>>> + plen_out, true);
>>>> +
>>>> + /* Illegal translation */
>>>> + if (section->mr == &io_mem_unassigned) {
>>>> + return NULL;
>>>> + }
>>>> +
>>>> + iommu_mr = memory_region_get_iommu(section->mr);
>>>> + if (!iommu_mr) {
>>>> + return NULL;
>>>> + }
>>>> +
>>>> + imrc = memory_region_get_iommu_class_nocheck(iommu_mr);
>>>> +
>>>> + if (imrc->attrs_to_index) {
>>>> + iommu_idx = imrc->attrs_to_index(iommu_mr, attrs);
>>>> + }
>>>> +
>>>> + iotlb = imrc->translate(iommu_mr, addr, IOMMU_RO, iommu_idx);
>>>> +
>>>> + *xlat = ((iotlb.translated_addr & ~iotlb.addr_mask)
>>>> + | (addr & iotlb.addr_mask));
>>>> + *plen_out = MIN(*plen_out, (addr | iotlb.addr_mask) - addr + 1);
>>>> + *prot = iotlb.perm;
>>>> + *target_as = iotlb.target_as;
>>>> +
>>>> + return section->mr;
>>>> +}
>>>> +
>>>> /* Called from RCU critical section */
>>>> IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
>>>> bool is_write, MemTxAttrs attrs)
>>>
>>
next prev parent reply other threads:[~2026-10-16 19:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 16:00 [PATCH v2 00/20] hw/core: Introduce Remote Port Co-simulation Protocol Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 01/20] hw/core: Add Remote Port protocol packet definition Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 02/20] hw/core: Add Remote Port header helpers Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 03/20] hw/core: Add Remote Port session state and hello protocol Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 04/20] hw/core: Implement Remote Port bus access helpers Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 05/20] hw/core: Implement Remote Port irq, sync and ATS helpers Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 06/20] hw/core: Add Remote Port object skeleton Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 07/20] hw/core: Add Remote Port protocol thread and handshake Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 08/20] hw/core: Implement Remote Port response handling Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 09/20] hw/core: Implement Remote Port time synchronization Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 10/20] hw/core: Add Remote Port Memory Master object skeleton Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 11/20] hw/core: Implement Remote Port Memory Master bus transactions Ruslan Ruslichenko
2026-10-13 16:09 ` Philippe Mathieu-Daudé
2026-10-13 16:10 ` Philippe Mathieu-Daudé
2026-10-14 8:24 ` Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 12/20] system/physmem: Add ats_do_translate helper Ruslan Ruslichenko
2026-10-13 14:27 ` Clément MATHIEU--DRIF
2026-10-14 8:21 ` Ruslan Ruslichenko
2026-10-15 9:40 ` Clément MATHIEU--DRIF
2026-10-16 19:28 ` Ruslan Ruslichenko [this message]
2026-10-18 5:14 ` Clément MATHIEU--DRIF
2026-09-15 16:00 ` [PATCH v2 13/20] hw/core: Add Remote Port ATS device skeleton Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 14/20] hw/core: Implement Remote Port ATS logic and cache management Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 15/20] hw/core: Add Remote Port memory slave device Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 16/20] hw/core: Add Remote Port GPIO/Interrupt bridge Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 17/20] hw/core: Add Remote Port Stream device Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 18/20] hw/core: Add Remote Port files to build Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 19/20] hw/core: Add FDT support to Remote Port GPIO Ruslan Ruslichenko
2026-09-15 16:00 ` [PATCH v2 20/20] hw/core: Add FDT support to Remote Port memory master Ruslan Ruslichenko
2026-09-28 7:30 ` [PATCH v2 00/20] hw/core: Introduce Remote Port Co-simulation Protocol Ruslan Ruslichenko
2026-10-13 16:17 ` Philippe Mathieu-Daudé
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=068f6239-9a04-4182-9e45-19fe38106184@gmail.com \
--to=ruslichenko.r@gmail.com \
--cc=Ruslan_Ruslichenko@epam.com \
--cc=artem_mygaiev@epam.com \
--cc=berrange@redhat.com \
--cc=clement.mathieu--drif@bull.com \
--cc=edgar.iglesias@amd.com \
--cc=edgar.iglesias@gmail.com \
--cc=eugene@nuvacore.ai \
--cc=francisco.iglesias@amd.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=takahiro.nakata.wr@renesas.com \
--cc=volodymyr_babchuk@epam.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.