From: David Hildenbrand <david@redhat.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>, qemu-s390x@nongnu.org
Cc: farman@linux.ibm.com, schnelle@linux.ibm.com, thuth@redhat.com,
pasic@linux.ibm.com, borntraeger@linux.ibm.com,
richard.henderson@linaro.org, iii@linux.ibm.com,
clegoate@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v4 1/2] s390x/pci: add support for guests that request direct mapping
Date: Mon, 10 Feb 2025 15:52:36 +0100 [thread overview]
Message-ID: <5201950c-b0dd-4efa-a991-4e682c705682@redhat.com> (raw)
In-Reply-To: <20250207205613.474092-2-mjrosato@linux.ibm.com>
On 07.02.25 21:56, Matthew Rosato wrote:
> When receiving a guest mpcifc(4) or mpcifc(6) instruction without the T
> bit set, treat this as a request to perform direct mapping instead of
> address translation. In order to facilitate this, pin the entirety of
> guest memory into the host iommu.
>
> Pinning for the direct mapping case is handled via vfio and its memory
> listener. Additionally, ram discard settings are inherited from vfio:
> coordinated discards (e.g. virtio-mem) are allowed while uncoordinated
> discards (e.g. virtio-balloon) are disabled.
>
> Subsequent guest DMA operations are all expected to be of the format
> guest_phys+sdma, allowing them to be used as lookup into the host
> iommu table.
>
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
> hw/s390x/s390-pci-bus.c | 38 +++++++++++++++++++++++++++++++--
> hw/s390x/s390-pci-inst.c | 13 +++++++++--
> hw/s390x/s390-pci-vfio.c | 23 ++++++++++++++++----
> hw/s390x/s390-virtio-ccw.c | 5 +++++
> include/hw/s390x/s390-pci-bus.h | 4 ++++
> 5 files changed, 75 insertions(+), 8 deletions(-)
>
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index eead269cc2..81e5843c81 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -18,6 +18,8 @@
> #include "hw/s390x/s390-pci-inst.h"
> #include "hw/s390x/s390-pci-kvm.h"
> #include "hw/s390x/s390-pci-vfio.h"
> +#include "hw/s390x/s390-virtio-ccw.h"
> +#include "hw/boards.h"
> #include "hw/pci/pci_bus.h"
> #include "hw/qdev-properties.h"
> #include "hw/pci/pci_bridge.h"
> @@ -720,16 +722,45 @@ void s390_pci_iommu_enable(S390PCIIOMMU *iommu)
> TYPE_S390_IOMMU_MEMORY_REGION, OBJECT(&iommu->mr),
> name, iommu->pal + 1);
> iommu->enabled = true;
> + iommu->direct_map = false;
> memory_region_add_subregion(&iommu->mr, 0, MEMORY_REGION(&iommu->iommu_mr));
> g_free(name);
> }
>
> +void s390_pci_iommu_direct_map_enable(S390PCIIOMMU *iommu)
> +{
> + MachineState *ms = MACHINE(qdev_get_machine());
> + S390CcwMachineState *s390ms = S390_CCW_MACHINE(ms);
> +
> + /*
> + * For direct-mapping we must map the entire guest address space. Rather
> + * than using an iommu, create a memory region alias that maps GPA X to
> + * IOVA X + SDMA. VFIO will handle pinning via its memory listener.
> + */
> + g_autofree char *name = g_strdup_printf("iommu-dm-s390-%04x",
> + iommu->pbdev->uid);
Empty line.
> + memory_region_init_alias(&iommu->dm_mr, OBJECT(&iommu->mr), name,
> + get_system_memory(), 0,
> + s390_get_memory_limit(s390ms));
> + iommu->enabled = true;
> + iommu->direct_map = true;
You could dynamically allocate the dm_mr instead, and use that as
indication if the direct mapping is active. Whatever you prefer.
Nothing else jumped at me, thanks!
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-02-10 14:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 20:56 [PATCH v4 0/2] s390x/pci: relax I/O address translation requirement Matthew Rosato
2025-02-07 20:56 ` [PATCH v4 1/2] s390x/pci: add support for guests that request direct mapping Matthew Rosato
2025-02-10 13:12 ` Niklas Schnelle
2025-02-10 13:26 ` Cédric Le Goater
2025-02-10 14:52 ` David Hildenbrand [this message]
2025-02-07 20:56 ` [PATCH v4 2/2] s390x/pci: indicate QEMU supports relaxed translation for passthrough Matthew Rosato
2025-02-10 13:29 ` Niklas Schnelle
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=5201950c-b0dd-4efa-a991-4e682c705682@redhat.com \
--to=david@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=clegoate@redhat.com \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=schnelle@linux.ibm.com \
--cc=thuth@redhat.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.