From: Avihai Horon <avihaih@nvidia.com>
To: Joao Martins <joao.m.martins@oracle.com>, qemu-devel@nongnu.org
Cc: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>,
Zhenzhong Duan <zhenzhong.duan@intel.com>,
Alex Williamson <alex.williamson@redhat.com>,
Cedric Le Goater <clg@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>,
Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [PATCH RFCv2 6/8] backends/iommufd: Add ability to disable hugepages
Date: Mon, 19 Feb 2024 12:05:14 +0200 [thread overview]
Message-ID: <a44e354e-f157-49db-9e60-5014afc605a5@nvidia.com> (raw)
In-Reply-To: <20240212135643.5858-7-joao.m.martins@oracle.com>
Hi Joao,
On 12/02/2024 15:56, Joao Martins wrote:
> External email: Use caution opening links or attachments
>
>
> Allow disabling hugepages to be dirty track at base page
> granularity in similar vein to vfio_type1_iommu.disable_hugepages
> but per IOAS.
>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
> backends/iommufd.c | 36 ++++++++++++++++++++++++++++++++++++
> backends/trace-events | 1 +
> hw/vfio/iommufd.c | 4 ++++
> include/sysemu/iommufd.h | 4 ++++
> qapi/qom.json | 2 +-
> 5 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index dd676d493c37..72fd98a9a50c 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -29,6 +29,7 @@ static void iommufd_backend_init(Object *obj)
> be->fd = -1;
> be->users = 0;
> be->owned = true;
> + be->hugepages = 1;
> }
>
> static void iommufd_backend_finalize(Object *obj)
> @@ -63,6 +64,14 @@ static bool iommufd_backend_can_be_deleted(UserCreatable *uc)
> return !be->users;
> }
>
> +static void iommufd_backend_set_hugepages(Object *obj, bool enabled,
> + Error **errp)
> +{
> + IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
> +
> + be->hugepages = enabled;
> +}
> +
> static void iommufd_backend_class_init(ObjectClass *oc, void *data)
> {
> UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
> @@ -70,6 +79,11 @@ static void iommufd_backend_class_init(ObjectClass *oc, void *data)
> ucc->can_be_deleted = iommufd_backend_can_be_deleted;
>
> object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd);
> +
> + object_class_property_add_bool(oc, "hugepages", NULL,
> + iommufd_backend_set_hugepages);
> + object_class_property_set_description(oc, "hugepages",
> + "Set to 'off' to disable hugepages");
> }
>
> int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp)
> @@ -106,6 +120,28 @@ out:
> trace_iommufd_backend_disconnect(be->fd, be->users);
> }
>
> +int iommufd_backend_set_option(int fd, uint32_t object_id,
> + uint32_t option_id, uint64_t val64)
> +{
> + int ret;
> + struct iommu_option option = {
> + .size = sizeof(option),
> + .option_id = option_id,
> + .op = IOMMU_OPTION_OP_SET,
> + .val64 = val64,
> + .object_id = object_id,
> + };
> +
> + ret = ioctl(fd, IOMMU_OPTION, &option);
> + if (ret) {
> + error_report("Failed to set option %x to value %"PRIx64" %m", option_id,
> + val64);
> + }
> + trace_iommufd_backend_set_option(fd, object_id, option_id, val64, ret);
> +
> + return ret;
> +}
> +
> int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
> Error **errp)
> {
> diff --git a/backends/trace-events b/backends/trace-events
> index 11a27cb114b6..076166552881 100644
> --- a/backends/trace-events
> +++ b/backends/trace-events
> @@ -15,6 +15,7 @@ iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t iova, u
> iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)"
> iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_t out_hwpt_id, int ret) " iommufd=%d dev_id=%u pt_id=%u flags=0x%x hwpt_type=%u len=%u data_ptr=0x%"PRIx64" out_hwpt=%u (%d)"
> iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd=%d ioas=%d (%d)"
> +iommufd_backend_set_option(int iommufd, uint32_t object_id, uint32_t option_id, uint64_t val, int ret) " iommufd=%d object_id=%u option_id=%u val64=0x%"PRIx64" (%d)"
> iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%d)"
> iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%d enable=%d (%d)"
> iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%d iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)"
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 79b13bd262cc..697d40841d7f 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -521,6 +521,10 @@ static int iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
> goto err_alloc_ioas;
> }
>
> + if (!vbasedev->iommufd_dev.iommufd->hugepages) {
> + iommufd_backend_set_option(vbasedev->iommufd_dev.iommufd->fd, ioas_id,
> + IOMMU_OPTION_HUGE_PAGES, 0);
Shouldn't we fail device attach if iommufd_backend_set_option() fails?
Thanks.
> + }
> trace_iommufd_cdev_alloc_ioas(vbasedev->iommufd_dev.iommufd->fd, ioas_id);
>
> container = g_malloc0(sizeof(*container));
> diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
> index ba19b7ea4c19..bc6607e3d444 100644
> --- a/include/sysemu/iommufd.h
> +++ b/include/sysemu/iommufd.h
> @@ -19,6 +19,7 @@ struct IOMMUFDBackend {
> /*< protected >*/
> int fd; /* /dev/iommu file descriptor */
> bool owned; /* is the /dev/iommu opened internally */
> + bool hugepages; /* are hugepages enabled on the IOAS */
> uint32_t users;
>
> /*< public >*/
> @@ -30,6 +31,9 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be);
> int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
> Error **errp);
> void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id);
> +int iommufd_backend_set_option(int fd, uint32_t object_id,
> + uint32_t option_id,
> + uint64_t val64);
> int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova,
> ram_addr_t size, void *vaddr, bool readonly);
> int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 84af23fe245d..9ad27e2b939b 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -809,7 +809,7 @@
> # Since: 9.0
> ##
> { 'struct': 'IOMMUFDProperties',
> - 'data': { '*fd': 'str' } }
> + 'data': { '*fd': 'str', '*hugepages': 'bool' } }
>
> ##
> # @RngProperties:
> --
> 2.39.3
>
next prev parent reply other threads:[~2024-02-19 10:05 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 13:56 [PATCH RFCv2 0/8] vfio/iommufd: IOMMUFD Dirty Tracking Joao Martins
2024-02-12 13:56 ` [PATCH RFCv2 1/8] backends/iommufd: Introduce helper function iommufd_device_get_hw_capabilities() Joao Martins
2024-02-26 7:29 ` Duan, Zhenzhong
2024-02-26 10:10 ` Joao Martins
2024-02-27 4:04 ` Duan, Zhenzhong
2024-02-12 13:56 ` [PATCH RFCv2 2/8] vfio/iommufd: Introduce auto domain creation Joao Martins
2024-02-12 16:27 ` Jason Gunthorpe
2024-02-12 18:09 ` Joao Martins
2024-02-26 9:14 ` Duan, Zhenzhong
2024-02-13 12:01 ` Joao Martins
2024-02-19 8:58 ` Avihai Horon
2024-02-20 10:42 ` Joao Martins
2024-02-12 13:56 ` [PATCH RFCv2 3/8] vfio/iommufd: Probe and request hwpt dirty tracking capability Joao Martins
2024-02-19 9:03 ` Avihai Horon
2024-02-20 10:51 ` Joao Martins
2024-02-20 12:46 ` Avihai Horon
2024-02-12 13:56 ` [PATCH RFCv2 4/8] vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support Joao Martins
2024-02-19 9:17 ` Avihai Horon
2024-02-12 13:56 ` [PATCH RFCv2 5/8] vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support Joao Martins
2024-02-19 9:30 ` Avihai Horon
2024-02-20 10:59 ` Joao Martins
2024-02-20 12:52 ` Avihai Horon
2024-02-20 13:17 ` Joao Martins
2024-02-12 13:56 ` [PATCH RFCv2 6/8] backends/iommufd: Add ability to disable hugepages Joao Martins
2024-02-12 16:59 ` Jason Gunthorpe
2024-02-12 17:17 ` Markus Armbruster
2024-02-12 19:16 ` Joao Martins
2024-02-19 10:05 ` Avihai Horon [this message]
2024-02-20 11:01 ` Joao Martins
2024-02-12 13:56 ` [PATCH RFCv2 7/8] vfio/migration: Don't block migration device dirty tracking is unsupported Joao Martins
2024-02-19 10:12 ` Avihai Horon
2024-02-20 11:05 ` Joao Martins
2024-02-12 13:56 ` [PATCH RFCv2 8/8] vfio/common: Allow disabling device dirty page tracking Joao Martins
2024-02-13 11:59 ` [PATCH RFCv2 0/8] vfio/iommufd: IOMMUFD Dirty Tracking Joao Martins
2024-02-14 15:40 ` Cédric Le Goater
2024-02-14 16:25 ` Joao Martins
2024-02-15 14:20 ` Eric Auger
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=a44e354e-f157-49db-9e60-5014afc605a5@nvidia.com \
--to=avihaih@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=eric.auger@redhat.com \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yi.l.liu@intel.com \
--cc=zhenzhong.duan@intel.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).