From: "Cédric Le Goater" <clg@redhat.com>
To: Amit Machhiwal <amachhiw@linux.ibm.com>,
qemu-ppc@nongnu.org, Nicholas Piggin <npiggin@gmail.com>,
Harsh Prateek Bora <harshpb@linux.ibm.com>
Cc: qemu-devel@nongnu.org, Vaibhav Jain <vaibhav@linux.ibm.com>,
Shivaprasad G Bhat <sbhat@linux.ibm.com>,
Daniel Henrique Barboza <danielhb413@gmail.com>,
Alex Williamson <alex.williamson@redhat.com>
Subject: Re: [PATCH v3 2/2] vfio/spapr: Fix L2 crash with PCI device passthrough and memory > 128G
Date: Tue, 8 Apr 2025 14:50:58 +0200 [thread overview]
Message-ID: <c1c55f9b-8628-421e-99af-970e30867dcb@redhat.com> (raw)
In-Reply-To: <20250408124042.2695955-3-amachhiw@linux.ibm.com>
On 4/8/25 14:40, Amit Machhiwal wrote:
> An L2 KVM guest fails to boot inside a pSeries LPAR when booted with a
> memory more than 128 GB and PCI device passthrough. The L2 guest also
> crashes when it is booted with a memory greater than 128 GB and a PCI
> device is hotplugged later.
>
> The issue arises from a conditional check for `levels > 1` in
> `spapr_tce_create_table()` within L1 KVM. This check is meant to prevent
> multi-level TCEs, which are not supported by the PowerVM hypervisor. As
> a result, when QEMU makes a `VFIO_IOMMU_SPAPR_TCE_CREATE` ioctl call
> with `levels > 1`, it triggers the conditional check and returns
> `EINVAL`, causing the guest to crash with the following errors:
>
> 2025-03-04T06:36:36.133117Z qemu-system-ppc64: Failed to create a window, ret = -1 (Invalid argument)
> 2025-03-04T06:36:36.133176Z qemu-system-ppc64: Failed to create SPAPR window: Invalid argument
> qemu: hardware error: vfio: DMA mapping failed, unable to continue
>
> Fix this by checking the supported DDW "levels" returned by the
> VFIO_IOMMU_SPAPR_TCE_GET_INFO ioctl before attempting the TCE create
> ioctl in KVM.
>
> The patch has been tested on KVM guests with memory configurations of up
> to 390GB, and 450GB on PowerVM and bare-metal environments respectively.
>
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/vfio/spapr.c | 36 +++++++++++++++++++++++++++---------
> 1 file changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index dd9207679dbe..32611096fa29 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -26,6 +26,7 @@ typedef struct VFIOSpaprContainer {
> VFIOContainer container;
> MemoryListener prereg_listener;
> QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
> + unsigned int levels;
> } VFIOSpaprContainer;
>
> OBJECT_DECLARE_SIMPLE_TYPE(VFIOSpaprContainer, VFIO_IOMMU_SPAPR);
> @@ -236,9 +237,11 @@ static bool vfio_spapr_create_window(VFIOContainer *container,
> {
> int ret = 0;
> VFIOContainerBase *bcontainer = &container->bcontainer;
> + VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
> + container);
> IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
> uint64_t pagesize = memory_region_iommu_get_min_page_size(iommu_mr), pgmask;
> - unsigned entries, bits_total, bits_per_level, max_levels;
> + unsigned entries, bits_total, bits_per_level, max_levels, ddw_levels;
> struct vfio_iommu_spapr_tce_create create = { .argsz = sizeof(create) };
> long rampagesize = qemu_minrampagesize();
>
> @@ -291,16 +294,29 @@ static bool vfio_spapr_create_window(VFIOContainer *container,
> */
> bits_per_level = ctz64(qemu_real_host_page_size()) + 8;
> create.levels = bits_total / bits_per_level;
> - if (bits_total % bits_per_level) {
> - ++create.levels;
> - }
> - max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size());
> - for ( ; create.levels <= max_levels; ++create.levels) {
> - ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
> - if (!ret) {
> - break;
> +
> + ddw_levels = scontainer->levels;
> + if (ddw_levels > 1) {
> + if (bits_total % bits_per_level) {
> + ++create.levels;
> }
> + max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size());
> + for ( ; create.levels <= max_levels; ++create.levels) {
> + ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
> + if (!ret) {
> + break;
> + }
> + }
> + } else { /* ddw_levels == 1 */
> + if (create.levels > ddw_levels) {
> + error_setg_errno(errp, EINVAL, "Host doesn't support multi-level TCE tables"
> + ". Use larger IO page size. Supported mask is 0x%lx",
> + bcontainer->pgsizes);
> + return false;
> + }
> + ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
> }
> +
> if (ret) {
> error_setg_errno(errp, errno, "Failed to create a window, ret = %d", ret);
> return false;
> @@ -501,6 +517,8 @@ static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer,
> goto listener_unregister_exit;
> }
>
> + scontainer->levels = info.ddw.levels;
> +
> if (v2) {
> bcontainer->pgsizes = info.ddw.pgsizes;
> /*
next prev parent reply other threads:[~2025-04-08 12:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 12:40 [PATCH v3 0/2] vfio/spapr: Fix L2 crash with PCI device passthrough Amit Machhiwal
2025-04-08 12:40 ` [PATCH v3 1/2] vfio/spapr: Enhance error handling in vfio_spapr_create_window() Amit Machhiwal
2025-04-08 12:50 ` Cédric Le Goater
2025-04-08 12:40 ` [PATCH v3 2/2] vfio/spapr: Fix L2 crash with PCI device passthrough and memory > 128G Amit Machhiwal
2025-04-08 12:50 ` Cédric Le Goater [this message]
2025-04-09 10:00 ` [PATCH v3 0/2] vfio/spapr: Fix L2 crash with PCI device passthrough Cédric Le Goater
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=c1c55f9b-8628-421e-99af-970e30867dcb@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=amachhiw@linux.ibm.com \
--cc=danielhb413@gmail.com \
--cc=harshpb@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sbhat@linux.ibm.com \
--cc=vaibhav@linux.ibm.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).