[PATCH v2 08/10] hw/virtio/vhost-user: make compilation unit common

Philippe Mathieu-Daudé posted 10 patches 1 week ago
There is a newer version of this series
[PATCH v2 08/10] hw/virtio/vhost-user: make compilation unit common
Posted by Philippe Mathieu-Daudé 1 week ago
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>

PPC architectures use a custom value for VHOST_USER_MAX_RAM_SLOTS (32
instead of 512).

vhost_user struct and several functions use VHOST_USER_MAX_RAM_SLOTS to
define stack allocated buffers. To avoid changing all functions to use
heap allocated buffers, we keep this max, and simply add a
target_base_ppc() conditional for the single place where size really
matters.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/virtio/vhost-user.c | 11 ++++-------
 hw/virtio/meson.build  |  3 +--
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 63fa9a1b4b1..c8a004c6d2d 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -44,13 +44,8 @@
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 #define VHOST_USER_BACKEND_MAX_FDS     8
 
-#if defined(TARGET_PPC) || defined(TARGET_PPC64)
-#include "hw/ppc/spapr.h"
-#define VHOST_USER_MAX_RAM_SLOTS SPAPR_MAX_RAM_SLOTS
-
-#else
+#include "hw/ppc/spapr_common.h"
 #define VHOST_USER_MAX_RAM_SLOTS 512
-#endif
 
 /*
  * Maximum size of virtio device config space
@@ -2280,7 +2275,9 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
                 return -EINVAL;
             }
 
-            u->user->memory_slots = MIN(ram_slots, VHOST_USER_MAX_RAM_SLOTS);
+            const uint64_t vhost_user_max_ram_slots = target_base_ppc() ?
+                SPAPR_MAX_RAM_SLOTS : VHOST_USER_MAX_RAM_SLOTS;
+            u->user->memory_slots = MIN(ram_slots, vhost_user_max_ram_slots);
         }
     }
 
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index affd66887db..ee397aaf196 100644
--- a/hw/virtio/meson.build
+++ b/hw/virtio/meson.build
@@ -17,8 +17,7 @@ if have_vhost
   system_virtio_ss.add(files('vhost.c'))
   system_virtio_ss.add(files('vhost-backend.c', 'vhost-iova-tree.c'))
   if have_vhost_user
-    # fixme - this really should be generic
-    specific_virtio_ss.add(files('vhost-user.c'))
+    system_virtio_ss.add(files('vhost-user.c'))
     system_virtio_ss.add(files('vhost-user-base.c'))
 
     # MMIO Stubs
-- 
2.52.0


Re: [PATCH v2 08/10] hw/virtio/vhost-user: make compilation unit common
Posted by Philippe Mathieu-Daudé 1 week ago
On 2/2/26 00:19, Philippe Mathieu-Daudé wrote:
> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> 
> PPC architectures use a custom value for VHOST_USER_MAX_RAM_SLOTS (32
> instead of 512).
> 
> vhost_user struct and several functions use VHOST_USER_MAX_RAM_SLOTS to
> define stack allocated buffers. To avoid changing all functions to use
> heap allocated buffers, we keep this max, and simply add a
> target_base_ppc() conditional for the single place where size really
> matters.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/virtio/vhost-user.c | 11 ++++-------
>   hw/virtio/meson.build  |  3 +--
>   2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 63fa9a1b4b1..c8a004c6d2d 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -44,13 +44,8 @@
>   #define VHOST_USER_F_PROTOCOL_FEATURES 30
>   #define VHOST_USER_BACKEND_MAX_FDS     8
>   
> -#if defined(TARGET_PPC) || defined(TARGET_PPC64)
> -#include "hw/ppc/spapr.h"
> -#define VHOST_USER_MAX_RAM_SLOTS SPAPR_MAX_RAM_SLOTS
> -
> -#else
> +#include "hw/ppc/spapr_common.h"
>   #define VHOST_USER_MAX_RAM_SLOTS 512
> -#endif

Since I didn't picked the correct branch base when posting with
git-publish, I neglected to include this patch:
https://lore.kernel.org/qemu-devel/20260131020100.1115203-4-pierrick.bouvier@linaro.org/