This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
from b33a925787 armv7-r: fix arm_gic_nlines redefines
new f599527e1e rptun: fix rptun sem post too much
new 8aa5145273 rptun: fix race-condition on g_rptun_cb & g_rptun_priv
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
drivers/rptun/rptun.c | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 8aa51452739ef1b2364841ce6b68e83614b23170
Author: ligd <li...@xiaomi.com>
AuthorDate: Mon Oct 31 23:40:16 2022 +0800
rptun: fix race-condition on g_rptun_cb & g_rptun_priv
both rptun_dev_start() & rpmsg_register_callback() will use
these two lists
Signed-off-by: ligd <li...@xiaomi.com>
---
drivers/rptun/rptun.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 8cdbc92109..e7b49740ca 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -196,8 +196,7 @@ static const struct image_store_ops g_rptun_storeops =
static METAL_DECLARE_LIST(g_rptun_cb);
static METAL_DECLARE_LIST(g_rptun_priv);
-static rmutex_t g_rptun_lockcb = NXRMUTEX_INITIALIZER;
-static rmutex_t g_rptun_lockpriv = NXRMUTEX_INITIALIZER;
+static rmutex_t g_rptun_lockcb = NXRMUTEX_INITIALIZER;
/****************************************************************************
* Private Functions
@@ -746,13 +745,10 @@ static int rptun_dev_start(FAR struct remoteproc *rproc)
}
}
- nxrmutex_unlock(&g_rptun_lockcb);
-
/* Add priv to list */
- nxrmutex_lock(&g_rptun_lockpriv);
metal_list_add_tail(&g_rptun_priv, &priv->node);
- nxrmutex_unlock(&g_rptun_lockpriv);
+ nxrmutex_unlock(&g_rptun_lockcb);
virtqueue_enable_cb(priv->rvdev.svq);
@@ -778,14 +774,11 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc)
/* Remove priv from list */
- nxrmutex_lock(&g_rptun_lockpriv);
+ nxrmutex_lock(&g_rptun_lockcb);
metal_list_del(&priv->node);
- nxrmutex_unlock(&g_rptun_lockpriv);
/* Broadcast device_destroy to all registers */
- nxrmutex_lock(&g_rptun_lockcb);
-
metal_list_for_each(&g_rptun_cb, node)
{
cb = metal_container_of(node, struct rptun_cb_s, node);
@@ -1075,7 +1068,7 @@ int rpmsg_register_callback(FAR void *priv_,
cb->ns_match = ns_match;
cb->ns_bind = ns_bind;
- nxrmutex_lock(&g_rptun_lockpriv);
+ nxrmutex_lock(&g_rptun_lockcb);
metal_list_for_each(&g_rptun_priv, node)
{
@@ -1115,9 +1108,6 @@ again:
nxrmutex_unlock(&priv->lock);
}
- nxrmutex_unlock(&g_rptun_lockpriv);
-
- nxrmutex_lock(&g_rptun_lockcb);
metal_list_add_tail(&g_rptun_cb, &cb->node);
nxrmutex_unlock(&g_rptun_lockcb);
@@ -1153,12 +1143,8 @@ void rpmsg_unregister_callback(FAR void *priv_,
}
}
- nxrmutex_unlock(&g_rptun_lockcb);
-
if (device_destroy)
{
- nxrmutex_lock(&g_rptun_lockpriv);
-
metal_list_for_each(&g_rptun_priv, pnode)
{
struct rptun_priv_s *priv;
@@ -1167,9 +1153,9 @@ void rpmsg_unregister_callback(FAR void *priv_,
struct rptun_priv_s, node);
device_destroy(&priv->rvdev.rdev, priv_);
}
-
- nxrmutex_unlock(&g_rptun_lockpriv);
}
+
+ nxrmutex_unlock(&g_rptun_lockcb);
}
int rptun_initialize(FAR struct rptun_dev_s *dev)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit f599527e1e6de92e24313c554fc33a912440fb47
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Nov 4 11:44:25 2022 +0800
rptun: fix rptun sem post too much
_assert
/media/liangchaozhong/ssd/86v1ap/nuttx/libs/libc/assert/lib_assert.c:36
nxsem_post
/media/liangchaozhong/ssd/86v1ap/nuttx/sched/semaphore/sem_post.c:91 (discriminator 1)
rptun_wakeup_rx
/media/liangchaozhong/ssd/86v1ap/nuttx/drivers/rptun/rptun.c:374
rpmsg_virtio_rx_callback
/media/liangchaozhong/ssd/86v1ap/nuttx/openamp/open-amp/lib/rpmsg/rpmsg_virtio.c:377
rproc_virtio_notified
/media/liangchaozhong/ssd/86v1ap/nuttx/openamp/open-amp/lib/remoteproc/remoteproc_virtio.c:342
remoteproc_get_notification
/media/liangchaozhong/ssd/86v1ap/nuttx/openamp/open-amp/lib/remoteproc/remoteproc.c:998
nxtask_start
/media/liangchaozhong/ssd/86v1ap/nuttx/sched/task/task_start.c:129
Signed-off-by: ligd <li...@xiaomi.com>
---
drivers/rptun/rptun.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 5c5208c6e2..8cdbc92109 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -292,7 +292,13 @@ static int rptun_thread(int argc, FAR char *argv[])
static void rptun_wakeup_rx(FAR struct rptun_priv_s *priv)
{
- nxsem_post(&priv->semrx);
+ int semcount;
+
+ nxsem_get_value(&priv->semrx, &semcount);
+ if (semcount < 1)
+ {
+ nxsem_post(&priv->semrx);
+ }
}
static bool rptun_is_recursive(FAR struct rptun_priv_s *priv)