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

commit 48812e0e5e9fcaaaf9e355e4e0dadca2643b55d8
Author: Yongrong Wang <[email protected]>
AuthorDate: Tue Mar 10 17:05:33 2026 +0800

    drivers/rpmsg: keep the rx worker priority in range
    
    rpmsg_queue_work() took the endpoint priority as uint8_t and stored
    the mapped thread priority back into it, so a priority above 255 or
    below 0 wrapped around. This happens for name service messages of an
    RT endpoint: rpmsg_virtio gives the message the priority of the
    endpoint it announces, 255, which maps to 255 - 127 + 224 = 352 and
    wraps to 96, so the message runs on a worker far below the default.
    
    Do not let the name service message inherit RPMSG_PRIO_RT, take the
    priority as int and clamp the result to the scheduler range. Also check
    that the global work queues are created.
    
    Signed-off-by: Yongrong Wang <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg.c        | 7 +++++--
 drivers/rpmsg/rpmsg.h        | 2 +-
 drivers/rpmsg/rpmsg_virtio.c | 8 +++++++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/rpmsg.c b/drivers/rpmsg/rpmsg.c
index 0487dc020f6..23f556678ca 100644
--- a/drivers/rpmsg/rpmsg.c
+++ b/drivers/rpmsg/rpmsg.c
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <syslog.h>
+#include <sys/param.h>
 #include <time.h>
 
 #include <metal/sys.h>
@@ -353,7 +354,8 @@ void rpmsg_initialize(void)
 {
   rpmsg_procfs_initialize();
 #ifdef CONFIG_RPMSG_WQUEUE_GLOBAL
-  rpmsg_create_wqueues(g_rpmsg_wqueues, "glb", CONFIG_RPMSG_WQUEUE_PRIORITY);
+  DEBUGVERIFY(rpmsg_create_wqueues(g_rpmsg_wqueues, "glb",
+              CONFIG_RPMSG_WQUEUE_PRIORITY) == 0);
 #endif
 }
 
@@ -1040,7 +1042,7 @@ void rpmsg_deinit_wqueues(FAR struct rpmsg_s *rpmsg)
 #endif
 }
 
-int rpmsg_queue_work(FAR struct rpmsg_s *rpmsg, uint8_t priority,
+int rpmsg_queue_work(FAR struct rpmsg_s *rpmsg, int priority,
                      FAR struct work_s *work, worker_t worker, FAR void *arg)
 {
   FAR struct rpmsg_wqueue_s *wqueues = rpmsg_get_wqueues(rpmsg);
@@ -1051,6 +1053,7 @@ int rpmsg_queue_work(FAR struct rpmsg_s *rpmsg, uint8_t 
priority,
   int i;
 
   priority = priority - RPMSG_PRIO_DEFAULT + rpmsg->priority;
+  priority = CLAMP(priority, SCHED_PRIORITY_MIN, SCHED_PRIORITY_MAX);
 
 #ifdef CONFIG_RPMSG_WQUEUE_GLOBAL
   flags = spin_lock_irqsave(&g_rpmsg_wqueue_lock);
diff --git a/drivers/rpmsg/rpmsg.h b/drivers/rpmsg/rpmsg.h
index 19749c7497c..e317cb3d1b3 100644
--- a/drivers/rpmsg/rpmsg.h
+++ b/drivers/rpmsg/rpmsg.h
@@ -149,7 +149,7 @@ void rpmsg_unregister(FAR const char *path, FAR struct 
rpmsg_s *rpmsg);
 int rpmsg_init_wqueues(FAR struct rpmsg_s *rpmsg, uint8_t priority);
 void rpmsg_deinit_wqueues(FAR struct rpmsg_s *rpmsg);
 
-int rpmsg_queue_work(FAR struct rpmsg_s *rpmsg, uint8_t priority,
+int rpmsg_queue_work(FAR struct rpmsg_s *rpmsg, int priority,
                      FAR struct work_s *work, worker_t worker,
                      FAR void *arg);
 void rpmsg_queue_rx_work(FAR struct rpmsg_s *rpmsg, uint8_t priority,
diff --git a/drivers/rpmsg/rpmsg_virtio.c b/drivers/rpmsg/rpmsg_virtio.c
index fff69da6166..58b87e7838a 100644
--- a/drivers/rpmsg/rpmsg_virtio.c
+++ b/drivers/rpmsg/rpmsg_virtio.c
@@ -583,7 +583,13 @@ static void rpmsg_virtio_rx_dispatch(FAR struct 
rpmsg_virtio_priv_s *priv)
               ns_msg = (FAR struct rpmsg_ns_msg *)RPMSG_LOCATE_DATA(hdr);
               ept_ = rpmsg_get_endpoint(rdev, ns_msg->name, RPMSG_ADDR_ANY,
                                         hdr->dst);
-              if (ept_)
+
+              /* Only inherit non-RT priority from the matched endpoint,
+               * ns_ept should not use RT priority to avoid overflow in
+               * priority calculation.
+               */
+
+              if (ept_ && ept_->priority != RPMSG_PRIO_RT)
                 {
                   priority = ept_->priority;
                 }

Reply via email to