diff mbox series

[RFC,1/3] vfio: Introduce helpers to mark dirty pages of a RAM section

Message ID 20210219094230.231-2-jiangkunkun@huawei.com (mailing list archive)
State New, archived
Headers show
Series Add migration support for VFIO PCI devices in SMMUv3 nested stage mode | expand

Commit Message

Kunkun Jiang Feb. 19, 2021, 9:42 a.m. UTC
Extract part of the code from vfio_sync_dirty_bitmap to form a
new helper, which allows to mark dirty pages of a RAM section.
This helper will be called for nested stage.

Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
---
 hw/vfio/common.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

Comments

Eric Auger April 8, 2021, 1:46 p.m. UTC | #1
Hi Kunkun,

On 2/19/21 10:42 AM, Kunkun Jiang wrote:
> Extract part of the code from vfio_sync_dirty_bitmap to form a
> new helper, which allows to mark dirty pages of a RAM section.
> This helper will be called for nested stage.
> 
> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
> ---
>  hw/vfio/common.c | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 9225f10722..7c50905856 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1203,6 +1203,19 @@ err_out:
>      return ret;
>  }
>  
> +static int vfio_dma_sync_ram_section_dirty_bitmap(VFIOContainer *container,
> +                                                  MemoryRegionSection *section)
> +{
> +    ram_addr_t ram_addr;
> +
> +    ram_addr = memory_region_get_ram_addr(section->mr) +
> +               section->offset_within_region;
> +
> +    return vfio_get_dirty_bitmap(container,
> +                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
> +                       int128_get64(section->size), ram_addr);
> +}
> +
>  typedef struct {
>      IOMMUNotifier n;
>      VFIOGuestIOMMU *giommu;
> @@ -1244,8 +1257,6 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>  static int vfio_sync_dirty_bitmap(VFIOContainer *container,
>                                    MemoryRegionSection *section)
>  {
> -    ram_addr_t ram_addr;
> -
>      if (memory_region_is_iommu(section->mr)) {
>          VFIOGuestIOMMU *giommu;
>  
> @@ -1274,12 +1285,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainer *container,
>          return 0;
>      }
>  
> -    ram_addr = memory_region_get_ram_addr(section->mr) +
> -               section->offset_within_region;
> -
> -    return vfio_get_dirty_bitmap(container,
> -                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
this is now REAL_HOST_PAGE_ALIGN

Thanks

Eric
> -                       int128_get64(section->size), ram_addr);
> +    return vfio_dma_sync_ram_section_dirty_bitmap(container, section);
>  }
>  
>  static void vfio_listerner_log_sync(MemoryListener *listener,
>
Kunkun Jiang April 12, 2021, 1:45 p.m. UTC | #2
Hi Eric,

On 2021/4/8 21:46, Auger Eric wrote:
> Hi Kunkun,
>
> On 2/19/21 10:42 AM, Kunkun Jiang wrote:
>> Extract part of the code from vfio_sync_dirty_bitmap to form a
>> new helper, which allows to mark dirty pages of a RAM section.
>> This helper will be called for nested stage.
>>
>> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
>> ---
>>   hw/vfio/common.c | 22 ++++++++++++++--------
>>   1 file changed, 14 insertions(+), 8 deletions(-)
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index 9225f10722..7c50905856 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -1203,6 +1203,19 @@ err_out:
>>       return ret;
>>   }
>>   
>> +static int vfio_dma_sync_ram_section_dirty_bitmap(VFIOContainer *container,
>> +                                                  MemoryRegionSection *section)
>> +{
>> +    ram_addr_t ram_addr;
>> +
>> +    ram_addr = memory_region_get_ram_addr(section->mr) +
>> +               section->offset_within_region;
>> +
>> +    return vfio_get_dirty_bitmap(container,
>> +                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
>> +                       int128_get64(section->size), ram_addr);
>> +}
>> +
>>   typedef struct {
>>       IOMMUNotifier n;
>>       VFIOGuestIOMMU *giommu;
>> @@ -1244,8 +1257,6 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>>   static int vfio_sync_dirty_bitmap(VFIOContainer *container,
>>                                     MemoryRegionSection *section)
>>   {
>> -    ram_addr_t ram_addr;
>> -
>>       if (memory_region_is_iommu(section->mr)) {
>>           VFIOGuestIOMMU *giommu;
>>   
>> @@ -1274,12 +1285,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainer *container,
>>           return 0;
>>       }
>>   
>> -    ram_addr = memory_region_get_ram_addr(section->mr) +
>> -               section->offset_within_region;
>> -
>> -    return vfio_get_dirty_bitmap(container,
>> -                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
> this is now REAL_HOST_PAGE_ALIGN
>
> Thanks
>
> Eric
Sorry for late replay.

Yes, it is REAL_HOST_PAGE_ALIGN now which modified by a patch I sent 
earlier.

I posted v2 a few days ago and I have modified TARGET_PAGE_ALIGN to
REAL_HOST_PAGE_ALIGN.[1]

[1] 
https://lore.kernel.org/qemu-devel/20210331101259.2153-2-jiangkunkun@huawei.com/

Thanks,
Kunkun Jiang
>> -                       int128_get64(section->size), ram_addr);
>> +    return vfio_dma_sync_ram_section_dirty_bitmap(container, section);
>>   }
>>   
>>   static void vfio_listerner_log_sync(MemoryListener *listener,
>>
> .
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 9225f10722..7c50905856 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1203,6 +1203,19 @@  err_out:
     return ret;
 }
 
+static int vfio_dma_sync_ram_section_dirty_bitmap(VFIOContainer *container,
+                                                  MemoryRegionSection *section)
+{
+    ram_addr_t ram_addr;
+
+    ram_addr = memory_region_get_ram_addr(section->mr) +
+               section->offset_within_region;
+
+    return vfio_get_dirty_bitmap(container,
+                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
+                       int128_get64(section->size), ram_addr);
+}
+
 typedef struct {
     IOMMUNotifier n;
     VFIOGuestIOMMU *giommu;
@@ -1244,8 +1257,6 @@  static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
 static int vfio_sync_dirty_bitmap(VFIOContainer *container,
                                   MemoryRegionSection *section)
 {
-    ram_addr_t ram_addr;
-
     if (memory_region_is_iommu(section->mr)) {
         VFIOGuestIOMMU *giommu;
 
@@ -1274,12 +1285,7 @@  static int vfio_sync_dirty_bitmap(VFIOContainer *container,
         return 0;
     }
 
-    ram_addr = memory_region_get_ram_addr(section->mr) +
-               section->offset_within_region;
-
-    return vfio_get_dirty_bitmap(container,
-                       TARGET_PAGE_ALIGN(section->offset_within_address_space),
-                       int128_get64(section->size), ram_addr);
+    return vfio_dma_sync_ram_section_dirty_bitmap(container, section);
 }
 
 static void vfio_listerner_log_sync(MemoryListener *listener,