All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>, qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
	eric.auger@redhat.com, Paolo Bonzini <pbonzini@redhat.com>,
	philmd@linaro.org, qemu-ppc@nongnu.org
Subject: Re: [PATCH v5 7/8] hw/vfio/spapr.c: extract vfio_spapr_kvm_attach_tce to hw/vfio/kvm-spapr.c
Date: Thu, 19 Mar 2026 09:32:46 +0100	[thread overview]
Message-ID: <f977b52c-5e11-4d0d-ba3a-2fbe165fbbcf@redhat.com> (raw)
In-Reply-To: <20260318174733.1717643-8-pierrick.bouvier@linaro.org>

On 3/18/26 18:47, Pierrick Bouvier wrote:
> Since this function needs kvm specific types, we need to extract in
> another file and link it only for KVM builds.
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   hw/vfio/kvm-spapr.h | 12 ++++++++++++
>   hw/vfio/kvm-spapr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
>   hw/vfio/kvm-stubs.c |  8 ++++++++
>   hw/vfio/spapr.c     | 30 ++++-------------------------
>   hw/vfio/meson.build |  1 +
>   5 files changed, 72 insertions(+), 26 deletions(-)
>   create mode 100644 hw/vfio/kvm-spapr.h
>   create mode 100644 hw/vfio/kvm-spapr.c
> 
> diff --git a/hw/vfio/kvm-spapr.h b/hw/vfio/kvm-spapr.h
> new file mode 100644
> index 00000000000..b1f68c686a7
> --- /dev/null
> +++ b/hw/vfio/kvm-spapr.h
> @@ -0,0 +1,12 @@
> +/*
> + * VFIO sPAPR KVM specific functions
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "hw/vfio/vfio-container.h"
> +#include "qapi/error.h"
> +
> +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer,
> +                               MemoryRegionSection *section,
> +                               Error **errp);
> diff --git a/hw/vfio/kvm-spapr.c b/hw/vfio/kvm-spapr.c
> new file mode 100644
> index 00000000000..ad71c5a85e2
> --- /dev/null
> +++ b/hw/vfio/kvm-spapr.c
> @@ -0,0 +1,47 @@
> +/*
> + * VFIO sPAPR KVM specific functions
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include <sys/ioctl.h>
> +#include <linux/vfio.h>
> +#include <linux/kvm.h>
> +
> +#include "hw/vfio/vfio-container-legacy.h"
> +#include "hw/vfio/kvm-spapr.h"
> +#include "qapi/error.h"
> +#include "trace.h"
> +#include "vfio-helpers.h"
> +
> +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer,
> +                               MemoryRegionSection *section,
> +                               Error **errp)
> +{
> +    VFIOLegacyContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
> +    VFIOGroup *group;
> +    IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
> +    struct kvm_vfio_spapr_tce param;
> +    struct kvm_device_attr attr = {
> +        .group = KVM_DEV_VFIO_GROUP,
> +        .attr = KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE,
> +        .addr = (uint64_t)(unsigned long)&param,
> +    };
> +
> +    if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_FD,
> +                &param.tablefd)) {
> +        QLIST_FOREACH(group, &container->group_list, container_next) {
> +            param.groupfd = group->fd;
> +            if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
> +                error_setg_errno(errp, errno,
> +                        "vfio: failed GROUP_SET_SPAPR_TCE for "
> +                        "KVM VFIO device %d and group fd %d",
> +                        param.tablefd, param.groupfd);
> +                return false;
> +            }
> +            trace_vfio_spapr_group_attach(param.groupfd, param.tablefd);
> +        }
> +    }
> +    return true;
> +}
> diff --git a/hw/vfio/kvm-stubs.c b/hw/vfio/kvm-stubs.c
> index 5a489d1b711..78c51b99155 100644
> --- a/hw/vfio/kvm-stubs.c
> +++ b/hw/vfio/kvm-stubs.c
> @@ -6,6 +6,7 @@
>   
>   #include "qemu/osdep.h"
>   
> +#include "hw/vfio/kvm-spapr.h"
>   #include "hw/vfio/vfio-device.h"
>   #include "qapi/error.h"
>   #include "vfio-helpers.h"
> @@ -24,3 +25,10 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
>   {
>       return 0;
>   }
> +
> +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer,
> +                               MemoryRegionSection *section,
> +                               Error **errp)
> +{
> +    g_assert_not_reached();
> +}
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index a9f093c3570..42690e4323d 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -16,6 +16,7 @@
>   #include "system/address-spaces.h"
>   
>   #include "hw/vfio/vfio-container-legacy.h"
> +#include "hw/vfio/kvm-spapr.h"
>   #include "hw/core/hw-error.h"
>   #include "qemu/error-report.h"
>   #include "qapi/error.h"
> @@ -406,33 +407,10 @@ vfio_spapr_container_add_section_window(VFIOContainer *bcontainer,
>       vfio_host_win_add(scontainer, section->offset_within_address_space,
>                         section->offset_within_address_space +
>                         int128_get64(section->size) - 1, pgsize);
> -#ifdef CONFIG_KVM
> -    if (kvm_enabled()) {
> -        VFIOGroup *group;
> -        IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
> -        struct kvm_vfio_spapr_tce param;
> -        struct kvm_device_attr attr = {
> -            .group = KVM_DEV_VFIO_GROUP,
> -            .attr = KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE,
> -            .addr = (uint64_t)(unsigned long)&param,
> -        };
> -
> -        if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_FD,
> -                                          &param.tablefd)) {
> -            QLIST_FOREACH(group, &container->group_list, container_next) {
> -                param.groupfd = group->fd;
> -                if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
> -                    error_setg_errno(errp, errno,
> -                                     "vfio: failed GROUP_SET_SPAPR_TCE for "
> -                                     "KVM VFIO device %d and group fd %d",
> -                                     param.tablefd, param.groupfd);
> -                    return false;
> -                }
> -                trace_vfio_spapr_group_attach(param.groupfd, param.tablefd);
> -            }
> -        }
> +    if (kvm_enabled() && !vfio_spapr_kvm_attach_tce(bcontainer, section, errp)) {
> +        return false;
>       }
> -#endif
> +
>       return true;
>   }
>   
> diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
> index 6c00a7f51bb..bab5f2b7f15 100644
> --- a/hw/vfio/meson.build
> +++ b/hw/vfio/meson.build
> @@ -10,6 +10,7 @@ vfio_ss.add(files(
>   vfio_ss.add(when: 'CONFIG_KVM', if_true: files('kvm-helpers.c'))
>   stub_ss.add(files('kvm-stubs.c'))
>   vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
> +vfio_ss.add(when: ['CONFIG_KVM', 'CONFIG_PSERIES'], if_true: files('kvm-spapr.c'))
>   vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
>     'pci-quirks.c',
>     'pci.c',



Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.



  reply	other threads:[~2026-03-19  8:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 17:47 [PATCH v5 0/8] hw/vfio: single-binary Pierrick Bouvier
2026-03-18 17:47 ` [PATCH v5 1/8] hw/vfio/listener.c: remove CONFIG_KVM Pierrick Bouvier
2026-03-18 17:47 ` [PATCH v5 2/8] hw/vfio/helpers.c: extract kvm helpers in kvm-helpers.c Pierrick Bouvier
2026-03-18 17:47 ` [PATCH v5 3/8] hw/vfio/pci-quirks.c: remove CONFIG_VFIO_IGD Pierrick Bouvier
2026-03-18 17:47 ` [PATCH v5 4/8] hw/vfio: eradicate CONFIG_IOMMU from sources Pierrick Bouvier
2026-03-19  8:32   ` Cédric Le Goater
2026-03-18 17:47 ` [PATCH v5 5/8] hw/vfio/pci.c: eradicate CONFIG_KVM Pierrick Bouvier
2026-03-19  8:33   ` Cédric Le Goater
2026-03-18 17:47 ` [PATCH v5 6/8] hw/vfio/ap.c: use full path for target specific header Pierrick Bouvier
2026-03-18 17:47 ` [PATCH v5 7/8] hw/vfio/spapr.c: extract vfio_spapr_kvm_attach_tce to hw/vfio/kvm-spapr.c Pierrick Bouvier
2026-03-19  8:32   ` Cédric Le Goater [this message]
2026-03-18 17:47 ` [PATCH v5 8/8] hw/vfio: all vfio files can now be common files Pierrick Bouvier
2026-03-19  7:45 ` [PATCH v5 0/8] hw/vfio: single-binary Philippe Mathieu-Daudé
2026-03-19  8:33 ` 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=f977b52c-5e11-4d0d-ba3a-2fbe165fbbcf@redhat.com \
    --to=clg@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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.