[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 07/20] vfio/common: Add VFIOBitmap and (de)alloc functions
From: |
Alex Williamson |
Subject: |
Re: [PATCH v2 07/20] vfio/common: Add VFIOBitmap and (de)alloc functions |
Date: |
Wed, 22 Feb 2023 14:40:09 -0700 |
On Wed, 22 Feb 2023 19:49:02 +0200
Avihai Horon <avihaih@nvidia.com> wrote:
> There are already two places where dirty page bitmap allocation and
> calculations are done in open code. With device dirty page tracking
> being added in next patches, there are going to be even more places.
>
> To avoid code duplication, introduce VFIOBitmap struct and corresponding
> alloc and dealloc functions and use them where applicable.
>
> Signed-off-by: Avihai Horon <avihaih@nvidia.com>
> ---
> hw/vfio/common.c | 89 ++++++++++++++++++++++++++++++++----------------
> 1 file changed, 60 insertions(+), 29 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index ac93b85632..84f08bdbbb 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -320,6 +320,41 @@ const MemoryRegionOps vfio_region_ops = {
> * Device state interfaces
> */
>
> +typedef struct {
> + unsigned long *bitmap;
> + hwaddr size;
> + hwaddr pages;
> +} VFIOBitmap;
> +
> +static VFIOBitmap *vfio_bitmap_alloc(hwaddr size)
> +{
> + VFIOBitmap *vbmap = g_try_new0(VFIOBitmap, 1);
> + if (!vbmap) {
> + errno = ENOMEM;
> +
> + return NULL;
> + }
> +
> + vbmap->pages = REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size();
> + vbmap->size = ROUND_UP(vbmap->pages, sizeof(__u64) * BITS_PER_BYTE) /
> + BITS_PER_BYTE;
> + vbmap->bitmap = g_try_malloc0(vbmap->size);
> + if (!vbmap->bitmap) {
> + g_free(vbmap);
> + errno = ENOMEM;
> +
> + return NULL;
> + }
> +
> + return vbmap;
> +}
> +
> +static void vfio_bitmap_dealloc(VFIOBitmap *vbmap)
> +{
> + g_free(vbmap->bitmap);
> + g_free(vbmap);
> +}
Nit, '_alloc' and '_free' seems like a more standard convention.
Thanks,
Alex
- [PATCH v2 00/20] vfio: Add migration pre-copy support and device dirty tracking, Avihai Horon, 2023/02/22
- [PATCH v2 01/20] migration: Pass threshold_size to .state_pending_{estimate, exact}(), Avihai Horon, 2023/02/22
- [PATCH v2 02/20] vfio/migration: Refactor vfio_save_block() to return saved data size, Avihai Horon, 2023/02/22
- [PATCH v2 04/20] vfio/common: Fix error reporting in vfio_get_dirty_bitmap(), Avihai Horon, 2023/02/22
- [PATCH v2 07/20] vfio/common: Add VFIOBitmap and (de)alloc functions, Avihai Horon, 2023/02/22
- [PATCH v2 09/20] util: Extend iova_tree_foreach() to take data argument, Avihai Horon, 2023/02/22
- [PATCH v2 05/20] vfio/common: Fix wrong %m usages, Avihai Horon, 2023/02/22
- [PATCH v2 06/20] vfio/common: Abort migration if dirty log start/stop/sync fails, Avihai Horon, 2023/02/22
- [PATCH v2 03/20] vfio/migration: Add VFIO migration pre-copy support, Avihai Horon, 2023/02/22