From: Eric Auger <eric.auger@redhat.com>
To: "Duan, Zhenzhong" <zhenzhong.duan@intel.com>,
"eric.auger.pro@gmail.com" <eric.auger.pro@gmail.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"qemu-arm@nongnu.org" <qemu-arm@nongnu.org>,
"mst@redhat.com" <mst@redhat.com>,
"jean-philippe@linaro.org" <jean-philippe@linaro.org>,
"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
"clg@redhat.com" <clg@redhat.com>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"jasowang@redhat.com" <jasowang@redhat.com>
Cc: "yanghliu@redhat.com" <yanghliu@redhat.com>
Subject: Re: [PATCH 3/6] virtio-iommu: Free [host_]resv_ranges on unset_iommu_devices
Date: Wed, 17 Jul 2024 09:40:55 +0200 [thread overview]
Message-ID: <d31d814e-ba00-4a2c-b905-d01022883b95@redhat.com> (raw)
In-Reply-To: <SJ0PR11MB6744D54C9B81BD1AD2BE5E1A92A32@SJ0PR11MB6744.namprd11.prod.outlook.com>
Hi Zhenzhong,
On 7/17/24 05:06, Duan, Zhenzhong wrote:
>
>> -----Original Message-----
>> From: Eric Auger <eric.auger@redhat.com>
>> Subject: [PATCH 3/6] virtio-iommu: Free [host_]resv_ranges on
>> unset_iommu_devices
>>
>> We are currently missing the deallocation of the [host_]resv_regions
>> in case of hot unplug. Also to make things more simple let's rule
>> out the case where multiple HostIOMMUDevices would be aliased and
>> attached to the same IOMMUDevice. This allows to remove the handling
>> of conflicting Host reserved regions. Anyway this is not properly
>> supported at guest kernel level. On hotunplug the reserved regions
>> are reset to the ones set by virtio-iommu property.
>>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>> ---
>> hw/virtio/virtio-iommu.c | 62 ++++++++++++++++++----------------------
>> 1 file changed, 28 insertions(+), 34 deletions(-)
>>
>> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
>> index 2c54c0d976..2de41ab412 100644
>> --- a/hw/virtio/virtio-iommu.c
>> +++ b/hw/virtio/virtio-iommu.c
>> @@ -538,8 +538,6 @@ static int
>> virtio_iommu_set_host_iova_ranges(VirtIOIOMMU *s, PCIBus *bus,
>> {
>> IOMMUPciBus *sbus = g_hash_table_lookup(s->as_by_busptr, bus);
>> IOMMUDevice *sdev;
>> - GList *current_ranges;
>> - GList *l, *tmp, *new_ranges = NULL;
>> int ret = -EINVAL;
>>
>> if (!sbus) {
>> @@ -553,33 +551,10 @@ static int
>> virtio_iommu_set_host_iova_ranges(VirtIOIOMMU *s, PCIBus *bus,
>> return ret;
>> }
>>
>> - current_ranges = sdev->host_resv_ranges;
>> -
>> - /* check that each new resv region is included in an existing one */
>> if (sdev->host_resv_ranges) {
>> - range_inverse_array(iova_ranges,
>> - &new_ranges,
>> - 0, UINT64_MAX);
>> -
>> - for (tmp = new_ranges; tmp; tmp = tmp->next) {
>> - Range *newr = (Range *)tmp->data;
>> - bool included = false;
>> -
>> - for (l = current_ranges; l; l = l->next) {
>> - Range * r = (Range *)l->data;
>> -
>> - if (range_contains_range(r, newr)) {
>> - included = true;
>> - break;
>> - }
>> - }
>> - if (!included) {
>> - goto error;
>> - }
>> - }
>> - /* all new reserved ranges are included in existing ones */
>> - ret = 0;
>> - goto out;
>> + error_setg(errp, "%s virtio-iommu does not support aliased BDF",
>> + __func__);
>> + return ret;
>> }
>>
>> range_inverse_array(iova_ranges,
>> @@ -588,14 +563,31 @@ static int
>> virtio_iommu_set_host_iova_ranges(VirtIOIOMMU *s, PCIBus *bus,
>> rebuild_resv_regions(sdev);
>>
>> return 0;
>> -error:
>> - error_setg(errp, "%s Conflicting host reserved ranges set!",
>> - __func__);
>> -out:
>> - g_list_free_full(new_ranges, g_free);
>> - return ret;
>> }
>>
>> +static void virtio_iommu_unset_host_iova_ranges(VirtIOIOMMU *s,
>> PCIBus *bus,
>> + int devfn)
>> +{
>> + IOMMUPciBus *sbus = g_hash_table_lookup(s->as_by_busptr, bus);
>> + IOMMUDevice *sdev;
>> +
>> + if (!sbus) {
>> + return;
>> + }
>> +
>> + sdev = sbus->pbdev[devfn];
>> + if (!sdev) {
>> + return;
>> + }
>> +
>> + g_list_free_full(g_steal_pointer(&sdev->host_resv_ranges), g_free);
>> + g_list_free_full(sdev->resv_regions, g_free);
>> + sdev->host_resv_ranges = NULL;
>> + sdev->resv_regions = NULL;
>> + add_prop_resv_regions(sdev);
> Is this necessary? rebuild_resv_regions() will do that again.
My goal was to reset the state that existed before the
virtio_iommu_set_host_iova_ranges() was called. prop resv regions were originally added in virtio_iommu_find_add_as.
The next device to be hotplugged at this aliased bdf is not necessarily a VFIO device (may be a virtio one), in which case we would miss the prop resv regions.
>
> Other than that, for the whole series,
>
> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Thanks!
Eric
>
> Thanks
> Zhenzhong
>
>> +}
>> +
>> +
>> static bool check_page_size_mask(VirtIOIOMMU *viommu, uint64_t
>> new_mask,
>> Error **errp)
>> {
>> @@ -704,6 +696,8 @@ virtio_iommu_unset_iommu_device(PCIBus *bus,
>> void *opaque, int devfn)
>> if (!hiod) {
>> return;
>> }
>> + virtio_iommu_unset_host_iova_ranges(viommu, hiod->aliased_bus,
>> + hiod->aliased_devfn);
>>
>> g_hash_table_remove(viommu->host_iommu_devices, &key);
>> }
>> --
>> 2.41.0
next prev parent reply other threads:[~2024-07-17 7:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 9:45 [PATCH 0/6] VIRTIO-IOMMU/VFIO: Revert IOMMUDevice clear and fix hotunplug Eric Auger
2024-07-16 9:45 ` [PATCH 1/6] Revert "virtio-iommu: Clear IOMMUDevice when VFIO device is unplugged" Eric Auger
2024-07-16 13:05 ` Cédric Le Goater
2024-07-16 9:45 ` [PATCH 2/6] virtio-iommu: Remove probe_done Eric Auger
2024-07-16 13:06 ` Cédric Le Goater
2024-07-16 9:45 ` [PATCH 3/6] virtio-iommu: Free [host_]resv_ranges on unset_iommu_devices Eric Auger
2024-07-16 13:36 ` Cédric Le Goater
2024-07-17 3:06 ` Duan, Zhenzhong
2024-07-17 7:40 ` Eric Auger [this message]
2024-07-17 7:56 ` Duan, Zhenzhong
2024-07-16 9:45 ` [PATCH 4/6] virtio-iommu: Remove the end point on detach Eric Auger
2024-07-16 13:36 ` Cédric Le Goater
2024-07-16 9:45 ` [PATCH 5/6] hw/vfio/common: Add vfio_listener_region_del_iommu trace event Eric Auger
2024-07-16 13:36 ` Cédric Le Goater
2024-07-16 9:45 ` [PATCH 6/6] virtio-iommu: Add trace point on virtio_iommu_detach_endpoint_from_domain Eric Auger
2024-07-16 13:36 ` Cédric Le Goater
2024-07-16 14:02 ` [PATCH 0/6] VIRTIO-IOMMU/VFIO: Revert IOMMUDevice clear and fix hotunplug Cédric Le Goater
2024-07-16 14:59 ` 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=d31d814e-ba00-4a2c-b905-d01022883b95@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=jasowang@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=yanghliu@redhat.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).