This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a7bb907c9c drivers/vhost: keep the driver structures per CPU in BMP 
mode
3a7bb907c9c is described below

commit 3a7bb907c9c95422ed8c73720dfbb5510f22a43f
Author: Bowen Wang <[email protected]>
AuthorDate: Wed Nov 25 23:53:05 2026 +0800

    drivers/vhost: keep the driver structures per CPU in BMP mode
    
    With the vhost bus per CPU in BMP mode, every CPU registers its own
    vhost drivers, and a vhost_driver is linked into its bus through its
    own node, so each driver structure must be per CPU too. Define them
    with DEFINE_PER_CPU_BMP(), which leaves them plain globals when BMP is
    off.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/vhost/vhost-blk.c    | 4 +++-
 drivers/vhost/vhost-crypto.c | 4 +++-
 drivers/vhost/vhost-gpio.c   | 4 +++-
 drivers/vhost/vhost-i2c.c    | 4 +++-
 drivers/vhost/vhost-net.c    | 4 +++-
 drivers/vhost/vhost-ping.c   | 4 +++-
 drivers/vhost/vhost-rng.c    | 4 +++-
 drivers/vhost/vhost-rpmb.c   | 4 +++-
 drivers/vhost/vhost-rpmsg.c  | 4 +++-
 drivers/vhost/vhost-serial.c | 8 ++++++--
 drivers/vhost/vhost-spi.c    | 4 +++-
 11 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/drivers/vhost/vhost-blk.c b/drivers/vhost/vhost-blk.c
index ccf9f4e092e..a55eff8c4b7 100644
--- a/drivers/vhost/vhost-blk.c
+++ b/drivers/vhost/vhost-blk.c
@@ -30,6 +30,7 @@
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/ioctl.h>
 #include <nuttx/kthread.h>
+#include <nuttx/percpu.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-blk.h>
@@ -73,12 +74,13 @@ static void vhost_blk_remove(FAR struct vhost_device *vdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_blk_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_blk_driver) =
 {
   VIRTIO_ID_BLOCK,                              /* device id */
   vhost_blk_probe,                              /* probe */
   vhost_blk_remove,                             /* remove */
 };
+#define g_vhost_blk_driver this_cpu_var_bmp(g_vhost_blk_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-crypto.c b/drivers/vhost/vhost-crypto.c
index e61a12e8669..0538d08e01f 100644
--- a/drivers/vhost/vhost-crypto.c
+++ b/drivers/vhost/vhost-crypto.c
@@ -32,6 +32,7 @@
 #include <crypto/cryptodev.h>
 #include <crypto/virtio_crypto.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-crypto.h>
@@ -120,12 +121,13 @@ static void vhost_crypto_remove(FAR struct vhost_device 
*hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_crypto_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_crypto_driver) =
 {
   VIRTIO_ID_CRYPTO,      /* device id */
   vhost_crypto_probe,    /* probe */
   vhost_crypto_remove,   /* remove */
 };
+#define g_vhost_crypto_driver this_cpu_var_bmp(g_vhost_crypto_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-gpio.c b/drivers/vhost/vhost-gpio.c
index 733db472140..198c09c1b77 100644
--- a/drivers/vhost/vhost-gpio.c
+++ b/drivers/vhost/vhost-gpio.c
@@ -33,6 +33,7 @@
 
 #include <nuttx/ioexpander/ioexpander.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/spinlock.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-gpio.h>
@@ -106,12 +107,13 @@ static void vhost_gpio_remove(FAR struct vhost_device 
*hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_gpio_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_gpio_driver) =
 {
   VIRTIO_ID_GPIO,    /* Device id */
   vhost_gpio_probe,  /* Probe */
   vhost_gpio_remove, /* Remove */
 };
+#define g_vhost_gpio_driver this_cpu_var_bmp(g_vhost_gpio_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-i2c.c b/drivers/vhost/vhost-i2c.c
index 10cace0bd87..904b310006a 100644
--- a/drivers/vhost/vhost-i2c.c
+++ b/drivers/vhost/vhost-i2c.c
@@ -34,6 +34,7 @@
 #include <nuttx/fs/fs.h>
 #include <nuttx/i2c/i2c_master.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-i2c.h>
 #include <nuttx/wqueue.h>
@@ -62,12 +63,13 @@ static void vhost_i2c_remove(FAR struct vhost_device *hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_i2c_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_i2c_driver) =
 {
   VIRTIO_ID_I2C_ADAPTER, /* Device id */
   vhost_i2c_probe,       /* Probe */
   vhost_i2c_remove,      /* Remove */
 };
+#define g_vhost_i2c_driver this_cpu_var_bmp(g_vhost_i2c_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-net.c b/drivers/vhost/vhost-net.c
index e06a54be560..2659d8fd3c6 100644
--- a/drivers/vhost/vhost-net.c
+++ b/drivers/vhost/vhost-net.c
@@ -67,6 +67,7 @@
 #include <nuttx/kmalloc.h>
 #include <nuttx/net/ethernet.h>
 #include <nuttx/net/netdev_lowerhalf.h>
+#include <nuttx/percpu.h>
 #include <nuttx/vhost/vhost.h>
 
 #include "vhost-net.h"
@@ -179,12 +180,13 @@ static const struct netdev_ops_s g_vhost_net_ops =
 #endif
 };
 
-static struct vhost_driver g_vhost_net_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_net_driver) =
 {
   VIRTIO_ID_NETWORK,                            /* device id */
   vhost_net_probe,                              /* probe */
   vhost_net_remove,                             /* remove */
 };
+#define g_vhost_net_driver this_cpu_var_bmp(g_vhost_net_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-ping.c b/drivers/vhost/vhost-ping.c
index 7228795223c..452782d803d 100644
--- a/drivers/vhost/vhost-ping.c
+++ b/drivers/vhost/vhost-ping.c
@@ -32,6 +32,7 @@
 #include <nuttx/clock.h>
 #include <nuttx/debug.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/signal.h>
 #include <nuttx/spinlock.h>
@@ -86,13 +87,14 @@ static void vhost_ping_txdone(FAR struct virtqueue *vq);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_ping_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_ping_driver) =
 {
   VIRTIO_ID_PING,    /* Device id */
   vhost_ping_probe,  /* Probe */
   vhost_ping_remove, /* Remove */
   vhost_ping_dump,   /* Dump */
 };
+#define g_vhost_ping_driver this_cpu_var_bmp(g_vhost_ping_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-rng.c b/drivers/vhost/vhost-rng.c
index 8bb9395ffd3..bddabf36916 100644
--- a/drivers/vhost/vhost-rng.c
+++ b/drivers/vhost/vhost-rng.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/spinlock.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/wqueue.h>
@@ -65,12 +66,13 @@ static void vhost_rng_handler(FAR struct virtqueue *vq);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_rng_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_rng_driver) =
 {
   VIRTIO_ID_ENTROPY,                           /* Device id */
   vhost_rng_probe,                             /* Probe */
   vhost_rng_remove,                            /* Remove */
 };
+#define g_vhost_rng_driver this_cpu_var_bmp(g_vhost_rng_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-rpmb.c b/drivers/vhost/vhost-rpmb.c
index 876e188bc8d..8b7a5dc9886 100644
--- a/drivers/vhost/vhost-rpmb.c
+++ b/drivers/vhost/vhost-rpmb.c
@@ -37,6 +37,7 @@
 #include <nuttx/kmalloc.h>
 #include <nuttx/kthread.h>
 #include <nuttx/mmcsd.h>
+#include <nuttx/percpu.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-rpmb.h>
@@ -101,12 +102,13 @@ static void vhost_rpmb_remove(FAR struct vhost_device 
*hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_rpmb_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_rpmb_driver) =
 {
   VIRTIO_ID_RPMB,                               /* device id */
   vhost_rpmb_probe,                             /* probe */
   vhost_rpmb_remove,                            /* remove */
 };
+#define g_vhost_rpmb_driver this_cpu_var_bmp(g_vhost_rpmb_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-rpmsg.c b/drivers/vhost/vhost-rpmsg.c
index 002d514763a..6c3840e9414 100644
--- a/drivers/vhost/vhost-rpmsg.c
+++ b/drivers/vhost/vhost-rpmsg.c
@@ -22,6 +22,7 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/percpu.h>
 #include <nuttx/rpmsg/rpmsg_virtio.h>
 #include <nuttx/vhost/vhost.h>
 
@@ -31,12 +32,13 @@
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_rpmsg_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_rpmsg_driver) =
 {
   VIRTIO_ID_RPMSG,                                /* Device id */
   rpmsg_virtio_probe,                             /* Probe */
   rpmsg_virtio_remove,                            /* Remove */
 };
+#define g_vhost_rpmsg_driver this_cpu_var_bmp(g_vhost_rpmsg_driver)
 
 /****************************************************************************
  * Public Functions
diff --git a/drivers/vhost/vhost-serial.c b/drivers/vhost/vhost-serial.c
index 7c598c5ff44..da36496cb94 100644
--- a/drivers/vhost/vhost-serial.c
+++ b/drivers/vhost/vhost-serial.c
@@ -33,6 +33,7 @@
 
 #include <nuttx/lib/lib.h>
 #include <nuttx/kthread.h>
+#include <nuttx/percpu.h>
 #include <nuttx/spinlock.h>
 #include <nuttx/vhost/vhost.h>
 #include <nuttx/virtio/virtio-config.h>
@@ -65,19 +66,22 @@ static void vhost_serial_remove(FAR struct vhost_device 
*hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_serial_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_serial_driver) =
 {
   VIRTIO_ID_CONSOLE,                                   /* device id */
   vhost_serial_probe,                                  /* probe */
   vhost_serial_remove,                                 /* remove */
 };
+#define g_vhost_serial_driver this_cpu_var_bmp(g_vhost_serial_driver)
 
-static struct vhost_driver g_vhost_rprocserial_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_rprocserial_driver) =
 {
   VIRTIO_ID_RPROC_SERIAL,                              /* device id */
   vhost_serial_probe,                                  /* probe */
   vhost_serial_remove,                                 /* remove */
 };
+#define g_vhost_rprocserial_driver \
+  this_cpu_var_bmp(g_vhost_rprocserial_driver)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/vhost/vhost-spi.c b/drivers/vhost/vhost-spi.c
index 7741c037e72..7b8a81e3611 100644
--- a/drivers/vhost/vhost-spi.c
+++ b/drivers/vhost/vhost-spi.c
@@ -33,6 +33,7 @@
 
 #include <nuttx/fs/fs.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/spi/spi.h>
 #include <nuttx/spi/spi_transfer.h>
 #include <nuttx/vhost/vhost.h>
@@ -63,12 +64,13 @@ static void vhost_spi_remove(FAR struct vhost_device *hdev);
  * Private Data
  ****************************************************************************/
 
-static struct vhost_driver g_vhost_spi_driver =
+static DEFINE_PER_CPU_BMP(struct vhost_driver, g_vhost_spi_driver) =
 {
   VIRTIO_ID_SPI,    /* Device id */
   vhost_spi_probe,  /* Probe */
   vhost_spi_remove, /* Remove */
 };
+#define g_vhost_spi_driver this_cpu_var_bmp(g_vhost_spi_driver)
 
 /****************************************************************************
  * Private Functions

Reply via email to