From: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
To: Santosh Shukla <santosh.shukla@amd.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, joao.m.martins@oracle.com,
Suravee.Suthikulpanit@amd.com, vasant.hegde@amd.com,
mtosatti@redhat.com, mst@redhat.com, marcel.apfelbaum@gmail.com
Subject: Re: [PATCH v2 2/5] amd_iommu: Add support for pass though mode
Date: Fri, 20 Sep 2024 16:26:01 -0400 [thread overview]
Message-ID: <d70a7757-4c39-4801-857c-607420cad4b5@oracle.com> (raw)
In-Reply-To: <20240916143116.169693-3-santosh.shukla@amd.com>
Hi Santosh,
On 9/16/24 10:31, Santosh Shukla wrote:
> From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
>
> Introduce 'nodma' shared memory region to support PT mode
> so that for each device, we only create an alias to shared memory
> region when DMA-remapping is disabled.
>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Signed-off-by: Santosh Shukla <santosh.shukla@amd.com>
> ---
> hw/i386/amd_iommu.c | 49 ++++++++++++++++++++++++++++++++++++---------
> hw/i386/amd_iommu.h | 2 ++
> 2 files changed, 42 insertions(+), 9 deletions(-)
>
> diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
> index abb64ea507be..c5f5103f4911 100644
> --- a/hw/i386/amd_iommu.c
> +++ b/hw/i386/amd_iommu.c
> @@ -60,8 +60,9 @@ struct AMDVIAddressSpace {
> uint8_t bus_num; /* bus number */
> uint8_t devfn; /* device function */
> AMDVIState *iommu_state; /* AMDVI - one per machine */
> - MemoryRegion root; /* AMDVI Root memory map region */
> + MemoryRegion root; /* AMDVI Root memory map region */
> IOMMUMemoryRegion iommu; /* Device's address translation region */
> + MemoryRegion iommu_nodma; /* Alias of shared nodma memory region */
> MemoryRegion iommu_ir; /* Device's interrupt remapping region */
> AddressSpace as; /* device's corresponding address space */
> };
> @@ -1412,6 +1413,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)
> AMDVIState *s = opaque;
> AMDVIAddressSpace **iommu_as, *amdvi_dev_as;
> int bus_num = pci_bus_num(bus);
> + X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
>
> iommu_as = s->address_spaces[bus_num];
>
> @@ -1436,13 +1438,13 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)
> * Memory region relationships looks like (Address range shows
> * only lower 32 bits to make it short in length...):
> *
> - * |-----------------+-------------------+----------|
> - * | Name | Address range | Priority |
> - * |-----------------+-------------------+----------+
> - * | amdvi_root | 00000000-ffffffff | 0 |
> - * | amdvi_iommu | 00000000-ffffffff | 1 |
> - * | amdvi_iommu_ir | fee00000-feefffff | 64 |
> - * |-----------------+-------------------+----------|
> + * |--------------------+-------------------+----------|
> + * | Name | Address range | Priority |
> + * |--------------------+-------------------+----------+
> + * | amdvi-root | 00000000-ffffffff | 0 |
> + * | amdvi-iommu_nodma | 00000000-ffffffff | 0 |
> + * | amdvi-iommu_ir | fee00000-feefffff | 64 |
> + * |--------------------+-------------------+----------|
Minor nit: I would keep the original indentation here to help reinforce the concept that iommu_nodma and iommu_ir are meant to be sub-regions under the root container. It would also be great if the table could show that they are mutually exclusive based on whether passthrough is in use, but that is probably too much to include in this format.
Alejandro
> +
> + if (!x86_iommu->pt_supported) {
> + memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, false);
> + memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu),
> + true);
> + } else {
> + memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu),
> + false);
> + memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, true);
> + }
> }
> return &iommu_as[devfn]->as;
> }
> @@ -1602,6 +1622,17 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
> "amdvi-mmio", AMDVI_MMIO_SIZE);
> memory_region_add_subregion(get_system_memory(), AMDVI_BASE_ADDR,
> &s->mr_mmio);
> +
> + /* Create the share memory regions by all devices */
> + memory_region_init(&s->mr_sys, OBJECT(s), "amdvi-sys", UINT64_MAX);
> +
> + /* set up the DMA disabled memory region */
> + memory_region_init_alias(&s->mr_nodma, OBJECT(s),
> + "amdvi-nodma", get_system_memory(), 0,
> + memory_region_size(get_system_memory()));
> + memory_region_add_subregion_overlap(&s->mr_sys, 0,
> + &s->mr_nodma, 0);
> +
> pci_setup_iommu(bus, &amdvi_iommu_ops, s);
> amdvi_init(s);
> }
> diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h
> index e5c2ae94f243..be417e51c4dc 100644
> --- a/hw/i386/amd_iommu.h
> +++ b/hw/i386/amd_iommu.h
> @@ -354,6 +354,8 @@ struct AMDVIState {
> uint32_t pprlog_tail; /* ppr log tail */
>
> MemoryRegion mr_mmio; /* MMIO region */
> + MemoryRegion mr_sys;
> + MemoryRegion mr_nodma;
> uint8_t mmior[AMDVI_MMIO_SIZE]; /* read/write MMIO */
> uint8_t w1cmask[AMDVI_MMIO_SIZE]; /* read/write 1 clear mask */
> uint8_t romask[AMDVI_MMIO_SIZE]; /* MMIO read/only mask */
next prev parent reply other threads:[~2024-09-20 20:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 14:31 [PATCH v2 0/5] Interrupt Remap support for emulated amd viommu Santosh Shukla
2024-09-16 14:31 ` [PATCH v2 1/5] amd_iommu: Rename variable mmio to mr_mmio Santosh Shukla
2024-09-16 14:31 ` [PATCH v2 2/5] amd_iommu: Add support for pass though mode Santosh Shukla
2024-09-20 20:26 ` Alejandro Jimenez [this message]
2024-09-27 14:06 ` Shukla, Santosh
2024-09-16 14:31 ` [PATCH v2 3/5] amd_iommu: Use shared memory region for Interrupt Remapping Santosh Shukla
2024-09-16 14:31 ` [PATCH v2 4/5] amd_iommu: Send notification when invaldate interrupt entry cache Santosh Shukla
2024-09-20 20:26 ` Alejandro Jimenez
2024-09-23 12:03 ` Shukla, Santosh
2024-09-16 14:31 ` [PATCH v2 5/5] amd_iommu: Check APIC ID > 255 for XTSup Santosh Shukla
2024-09-20 20:26 ` Alejandro Jimenez
2024-09-23 12:04 ` Shukla, Santosh
2024-09-20 20:39 ` [PATCH v2 0/5] Interrupt Remap support for emulated amd viommu Alejandro Jimenez
2024-09-23 12:05 ` Shukla, Santosh
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=d70a7757-4c39-4801-857c-607420cad4b5@oracle.com \
--to=alejandro.j.jimenez@oracle.com \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=joao.m.martins@oracle.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=santosh.shukla@amd.com \
--cc=vasant.hegde@amd.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;
as well as URLs for NNTP newsgroup(s).