From: Eric Auger <eric.auger@redhat.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: eric.auger.pro@gmail.com, qemu-devel@nongnu.org,
qemu-arm@nongnu.org, alex.williamson@redhat.com, clg@redhat.com,
mst@redhat.com, pbonzini@redhat.com, peter.maydell@linaro.org,
peterx@redhat.com, david@redhat.com, philmd@linaro.org
Subject: Re: [PATCH v2 07/12] virtio-iommu: Implement set_iova_ranges() callback
Date: Tue, 10 Oct 2023 16:36:37 +0200 [thread overview]
Message-ID: <9bc182c6-dd2d-2f00-c7eb-3065f17a05cb@redhat.com> (raw)
In-Reply-To: <20230929161547.GB2957297@myrica>
Hi Jean,
On 9/29/23 18:15, Jean-Philippe Brucker wrote:
> On Wed, Sep 13, 2023 at 10:01:42AM +0200, Eric Auger wrote:
>> The implementation populates the array of per IOMMUDevice
>> host reserved regions.
>>
>> It is forbidden to have conflicting sets of host IOVA ranges
>> to be applied onto the same IOMMU MR (implied by different
>> host devices).
>>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>>
>> ---
>>
>> v1 -> v2:
>> - Forbid conflicting sets of host resv regions
>> ---
>> include/hw/virtio/virtio-iommu.h | 2 ++
>> hw/virtio/virtio-iommu.c | 48 ++++++++++++++++++++++++++++++++
>> 2 files changed, 50 insertions(+)
>>
>> diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h
>> index 70b8ace34d..31b69c8261 100644
>> --- a/include/hw/virtio/virtio-iommu.h
>> +++ b/include/hw/virtio/virtio-iommu.h
>> @@ -40,6 +40,8 @@ typedef struct IOMMUDevice {
>> MemoryRegion root; /* The root container of the device */
>> MemoryRegion bypass_mr; /* The alias of shared memory MR */
>> GList *resv_regions;
>> + Range *host_resv_regions;
>> + uint32_t nr_host_resv_regions;
>> } IOMMUDevice;
>>
>> typedef struct IOMMUPciBus {
>> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
>> index ea359b586a..ed2df5116f 100644
>> --- a/hw/virtio/virtio-iommu.c
>> +++ b/hw/virtio/virtio-iommu.c
>> @@ -20,6 +20,7 @@
>> #include "qemu/osdep.h"
>> #include "qemu/log.h"
>> #include "qemu/iov.h"
>> +#include "qemu/range.h"
>> #include "exec/target_page.h"
>> #include "hw/qdev-properties.h"
>> #include "hw/virtio/virtio.h"
>> @@ -1158,6 +1159,52 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr,
>> return 0;
>> }
>>
>> +static int virtio_iommu_set_iova_ranges(IOMMUMemoryRegion *mr,
>> + uint32_t nr_ranges,
>> + struct Range *iova_ranges,
>> + Error **errp)
>> +{
>> + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr);
>> + uint32_t nr_host_resv_regions;
>> + Range *host_resv_regions;
>> + int ret = -EINVAL;
>> +
>> + if (!nr_ranges) {
>> + return 0;
>> + }
>> +
>> + if (sdev->host_resv_regions) {
>> + range_inverse_array(nr_ranges, iova_ranges,
>> + &nr_host_resv_regions, &host_resv_regions,
>> + 0, UINT64_MAX);
>> + if (nr_host_resv_regions != sdev->nr_host_resv_regions) {
>> + goto error;
>> + }
>> + for (int i = 0; i < nr_host_resv_regions; i++) {
>> + Range *new = &host_resv_regions[i];
>> + Range *existing = &sdev->host_resv_regions[i];
>> +
>> + if (!range_contains_range(existing, new)) {
>> + goto error;
>> + }
>> + }
>> + ret = 0;
>> + goto out;
>> + }
>> +
>> + range_inverse_array(nr_ranges, iova_ranges,
>> + &sdev->nr_host_resv_regions, &sdev->host_resv_regions,
>> + 0, UINT64_MAX);
> Can set_iova_ranges() only be called for the first time before the guest
> has had a chance to issue a probe request? Maybe we could add a
> sanity-check that the guest hasn't issued a probe request yet, since we
> can't notify about updated reserved regions.
I added a warning if the set_iova is called after the probe
Eric
>
> I'm probably misremembering because I thought Linux set up IOMMU contexts
> (including probe requests) before enabling DMA master in PCI which cause
> QEMU VFIO to issue these calls. I'll double check.
>
> Thanks,
> Jean
>
>> +
>> + return 0;
>> +error:
>> + error_setg(errp, "IOMMU mr=%s Conflicting host reserved regions set!",
>> + mr->parent_obj.name);
>> +out:
>> + g_free(host_resv_regions);
>> + return ret;
>> +}
>> +
>> static void virtio_iommu_system_reset(void *opaque)
>> {
>> VirtIOIOMMU *s = opaque;
>> @@ -1453,6 +1500,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,
>> 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;
>> + imrc->iommu_set_iova_ranges = virtio_iommu_set_iova_ranges;
>> }
>>
>> static const TypeInfo virtio_iommu_info = {
>> --
>> 2.41.0
>>
next prev parent reply other threads:[~2023-10-10 14:37 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 8:01 [PATCH v2 00/12] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space Eric Auger
2023-09-13 8:01 ` [PATCH v2 01/12] memory: Let ReservedRegion use Range Eric Auger
2023-09-13 12:43 ` Cédric Le Goater
2023-09-13 8:01 ` [PATCH v2 02/12] memory: Introduce memory_region_iommu_set_iova_ranges Eric Auger
2023-09-13 12:43 ` Cédric Le Goater
2023-09-20 7:40 ` Eric Auger
2023-09-13 8:01 ` [PATCH v2 03/12] vfio: Collect container iova range info Eric Auger
2023-09-13 12:55 ` Cédric Le Goater
2023-09-20 7:38 ` Eric Auger
2023-09-19 15:44 ` Alex Williamson
2023-09-20 7:15 ` Eric Auger
2023-09-20 7:39 ` Eric Auger
2023-09-13 8:01 ` [PATCH v2 04/12] virtio-iommu: Rename reserved_regions into prop_resv_regions Eric Auger
2023-09-13 13:01 ` Cédric Le Goater
2023-09-13 8:01 ` [PATCH v2 05/12] virtio-iommu: Introduce per IOMMUDevice reserved regions Eric Auger
2023-09-29 15:52 ` Jean-Philippe Brucker
2023-10-03 15:48 ` Eric Auger
2023-09-13 8:01 ` [PATCH v2 06/12] range: Introduce range_inverse_array() Eric Auger
2023-09-19 16:29 ` Alex Williamson
2023-09-20 7:24 ` Eric Auger
2023-09-13 8:01 ` [PATCH v2 07/12] virtio-iommu: Implement set_iova_ranges() callback Eric Auger
2023-09-29 16:15 ` Jean-Philippe Brucker
2023-10-10 14:36 ` Eric Auger [this message]
2023-09-13 8:01 ` [PATCH v2 08/12] range: Make range_compare() public Eric Auger
2023-09-13 8:01 ` [PATCH v2 09/12] util/reserved-region: Add new ReservedRegion helpers Eric Auger
2023-09-29 16:16 ` Jean-Philippe Brucker
2023-10-10 13:51 ` Eric Auger
2023-09-13 8:01 ` [PATCH v2 10/12] virtio-iommu: Consolidate host reserved regions and property set ones Eric Auger
2023-09-13 8:01 ` [PATCH v2 11/12] test: Add some tests for range and resv-mem helpers Eric Auger
2023-09-13 8:01 ` [PATCH v2 12/12] vfio: Remove 64-bit IOVA address space assumption Eric Auger
2023-09-19 17:22 ` Alex Williamson
2023-09-20 7:28 ` Eric Auger
2023-09-26 20:00 ` Eric Auger
2023-10-10 17:16 ` Eric Auger
2023-09-20 20:02 ` Alex Williamson
2023-10-11 17:32 ` Eric Auger
2023-09-26 8:06 ` [PATCH v2 00/12] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space YangHang Liu
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=9bc182c6-dd2d-2f00-c7eb-3065f17a05cb@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=david@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=jean-philippe@linaro.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--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).