qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	alex.williamson@redhat.com
Cc: pbonzini@redhat.com, bbhushan2@marvell.com,
	qemu-devel@nongnu.org, peterx@redhat.com, mst@redhat.com
Subject: Re: [PATCH v10 09/10] virtio-iommu: Set supported page size mask
Date: Fri, 16 Oct 2020 15:08:03 +0200	[thread overview]
Message-ID: <53892fd2-a69f-bd83-4167-b1d2569fb4c3@redhat.com> (raw)
In-Reply-To: <20201008171558.410886-10-jean-philippe@linaro.org>

Hi Jean,

On 10/8/20 7:15 PM, Jean-Philippe Brucker wrote:
> From: Bharat Bhushan <bbhushan2@marvell.com>
> 
> The virtio-iommu device can deal with arbitrary page sizes for virtual
> endpoints, but for endpoints assigned with VFIO it must follow the page
> granule used by the host IOMMU driver.
> 
> Implement the interface to set the vIOMMU page size mask, called by VFIO
> for each endpoint. We assume that all host IOMMU drivers use the same
> page granule (the host page granule). Override the page_size_mask field
> in the virtio config space.
> 
> Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

> ---
> v10: Use global page mask, allowing VFIO to override it until boot.
> ---
>  hw/virtio/virtio-iommu.c | 51 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 8823bfc804a..dd0b3093d1b 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -914,6 +914,56 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr,
>      return 0;
>  }
>  
> +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr,
> +                                           uint64_t page_size_mask,
> +                                           Error **errp)
> +{
> +    int new_granule, old_granule;
> +    IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr);
> +    VirtIOIOMMU *s = sdev->viommu;
> +
> +    if (!page_size_mask) {
set errp
> +        return -1;
> +    }
> +
> +    new_granule = ctz64(page_size_mask);
> +    old_granule = ctz64(s->config.page_size_mask);

I think this would be interesting to add a trace point
> +
> +    /*
> +     * Modifying the page size after machine initialization isn't supported.
> +     * Having a different mask is possible but the guest will use sub-optimal
> +     * block sizes, so warn about it.
> +     */
> +    if (qdev_hotplug) {
> +        if (new_granule != old_granule) {
> +            error_setg(errp,
> +                       "virtio-iommu page mask 0x%"PRIx64
> +                       " is incompatible with mask 0x%"PRIx64,
> +                       s->config.page_size_mask, page_size_mask);
> +            return -1;
> +        } else if (page_size_mask != s->config.page_size_mask) {
> +            warn_report("virtio-iommu page mask 0x%"PRIx64
> +                        " does not match 0x%"PRIx64,
> +                        s->config.page_size_mask, page_size_mask);
> +        }
> +        return 0;
> +    }
> +
> +    /*
> +     * Disallow shrinking the page size. For example if an endpoint only
> +     * supports 64kB pages, we can't globally enable 4kB pages. But that
> +     * shouldn't happen, the host is unlikely to setup differing page granules.
> +     * The other bits are only hints describing optimal block sizes.
> +     */
> +    if (new_granule < old_granule) {
> +        error_setg(errp, "memory region shrinks the virtio-iommu page granule");
> +        return -1;
> +    }
> +
> +    s->config.page_size_mask = page_size_mask;
> +    return 0;
> +}
> +
>  static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
>  {
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> @@ -1146,6 +1196,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,
>      imrc->translate = virtio_iommu_translate;
>      imrc->replay = virtio_iommu_replay;
>      imrc->notify_flag_changed = virtio_iommu_notify_flag_changed;
> +    imrc->iommu_set_page_size_mask = virtio_iommu_set_page_size_mask;
>  }
>  
>  static const TypeInfo virtio_iommu_info = {
> 
Thanks

Eric



  reply	other threads:[~2020-10-16 13:09 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 17:15 [PATCH v10 00/10] virtio-iommu: VFIO integration Jean-Philippe Brucker
2020-10-08 17:15 ` [PATCH v10 01/10] virtio-iommu: Fix virtio_iommu_mr() Jean-Philippe Brucker
2020-10-16  7:36   ` Auger Eric
2020-10-19 21:36   ` Peter Xu
2020-10-08 17:15 ` [PATCH v10 02/10] virtio-iommu: Store memory region in endpoint struct Jean-Philippe Brucker
2020-10-16  7:37   ` Auger Eric
2020-10-08 17:15 ` [PATCH v10 03/10] virtio-iommu: Add memory notifiers for map/unmap Jean-Philippe Brucker
2020-10-16  7:58   ` Auger Eric
2020-10-22 16:41     ` Jean-Philippe Brucker
2020-10-08 17:15 ` [PATCH v10 04/10] virtio-iommu: Call memory notifiers in attach/detach Jean-Philippe Brucker
2020-10-16  8:05   ` Auger Eric
2020-10-08 17:15 ` [PATCH v10 05/10] virtio-iommu: Add replay() memory region callback Jean-Philippe Brucker
2020-10-16  9:12   ` Auger Eric
2020-10-22 16:42     ` Jean-Philippe Brucker
2020-10-08 17:15 ` [PATCH v10 06/10] virtio-iommu: Add notify_flag_changed() " Jean-Philippe Brucker
2020-10-16  8:18   ` Auger Eric
2020-10-08 17:15 ` [PATCH v10 07/10] memory: Add interface to set iommu page size mask Jean-Philippe Brucker
2020-10-16  9:24   ` Auger Eric
2020-10-22 16:43     ` Jean-Philippe Brucker
2020-10-19 21:36   ` Peter Xu
2020-10-08 17:15 ` [PATCH v10 08/10] vfio: Set IOMMU page size as per host supported page size Jean-Philippe Brucker
2020-10-08 21:22   ` Alex Williamson
2020-10-30 10:26     ` Michael S. Tsirkin
2020-10-30 15:19       ` Jean-Philippe Brucker
2020-10-16  9:25   ` Auger Eric
2020-10-08 17:15 ` [PATCH v10 09/10] virtio-iommu: Set supported page size mask Jean-Philippe Brucker
2020-10-16 13:08   ` Auger Eric [this message]
2020-10-22 16:43     ` Jean-Philippe Brucker
2020-10-19 21:35   ` Peter Xu
2020-10-22 16:39     ` Jean-Philippe Brucker
2020-10-22 20:56       ` Peter Xu
2020-10-23  7:48         ` Jean-Philippe Brucker
2020-10-23 16:47           ` Peter Xu
2020-10-27 17:38             ` Jean-Philippe Brucker
2020-10-30 10:24               ` Michael S. Tsirkin
2020-10-08 17:15 ` [PATCH v10 10/10] vfio: Don't issue full 2^64 unmap Jean-Philippe Brucker
2020-10-08 21:22   ` Alex Williamson
2020-10-30 10:25     ` Michael S. Tsirkin
2020-10-30 17:26       ` Alex Williamson
2020-10-30 18:19         ` Paolo Bonzini
2020-11-02 17:37           ` Alex Williamson
2020-11-02 17:44             ` Paolo Bonzini
2020-11-02 18:00               ` Alex Williamson
2020-10-16  9:47   ` Auger Eric
2020-10-16 13:13 ` [PATCH v10 00/10] virtio-iommu: VFIO integration Auger Eric
2020-10-30 10:27 ` Michael S. Tsirkin
2020-10-30 10:48   ` Jean-Philippe Brucker

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=53892fd2-a69f-bd83-4167-b1d2569fb4c3@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=bbhushan2@marvell.com \
    --cc=jean-philippe@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.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 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).