You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/01/16 16:53:34 UTC

[incubator-nuttx] branch pr113 updated (e23d58e -> 7c7750b)

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

acassis pushed a change to branch pr113
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from e23d58e  drivers/sensors/lsm303agr: fix compilation warnings and run through nxstyle; drivers/sensors/lsm6dsl: run through nxstyle
     new e1feb54  net/close: force wait tx drain to complete
     new 7c7750b  net/udp: break the network lock to avoid deadlock

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:
 net/inet/inet_close.c               | 24 +++++++++++++-----------
 net/udp/udp_psock_sendto_buffered.c | 14 ++++++++++++++
 2 files changed, 27 insertions(+), 11 deletions(-)


[incubator-nuttx] 02/02: net/udp: break the network lock to avoid deadlock

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch pr113
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 7c7750b39cc2ba13a8547fbf2d80392fa669ebef
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Jan 15 16:33:46 2020 +0800

    net/udp: break the network lock to avoid deadlock
    
    network deadlock when udp sendto() storm is coming
    
    refer:
    
    commit d3cedfb8233700210a391ecdd15f8e1d3a8f99c9
    Author: Valmantas Paliksa <wa...@gmail.com>
    Date:   Wed May 29 07:26:26 2019 -0600
    
        net/tcp/tcp_send_buffered.c: Fix deadlock in iob_copyin when iob buffers are exhausted and network lock is taken.
    
    Change-Id: I6613579b02afe8a09400dc6220d13f16f6ffdfb2
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/udp/udp_psock_sendto_buffered.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/net/udp/udp_psock_sendto_buffered.c b/net/udp/udp_psock_sendto_buffered.c
index 0dcf892..fbc44de 100644
--- a/net/udp/udp_psock_sendto_buffered.c
+++ b/net/udp/udp_psock_sendto_buffered.c
@@ -75,6 +75,7 @@
 #include "neighbor/neighbor.h"
 #include "udp/udp.h"
 #include "devif/devif.h"
+#include "utils/utils.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -713,8 +714,21 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
         }
       else
         {
+          unsigned int count;
+          int blresult;
+
+          /* iob_copyin might wait for buffers to be freed, but if
+           * network is locked this might never happen, since network
+           * driver is also locked, therefore we need to break the lock
+           */
+
+          blresult = net_breaklock(&count);
           ret = iob_copyin(wrb->wb_iob, (FAR uint8_t *)buf, len, 0, false,
                            IOBUSER_NET_SOCK_UDP);
+          if (blresult >= 0)
+            {
+              net_restorelock(count);
+            }
         }
 
       if (ret < 0)


[incubator-nuttx] 01/02: net/close: force wait tx drain to complete

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch pr113
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit e1feb54e8c82b8d5fb45b2e7d1d6b066936548a9
Author: chao.an <an...@xiaomi.com>
AuthorDate: Tue Jan 14 18:36:36 2020 +0800

    net/close: force wait tx drain to complete
    
    atomic send() and close() will causes data to be discarded directly
    
    Change-Id: I3d382bec5b97fa7ea4e191aa857c7a6c81897dd3
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/inet/inet_close.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/net/inet/inet_close.c b/net/inet/inet_close.c
index 2b26a63..dd5dd83 100644
--- a/net/inet/inet_close.c
+++ b/net/inet/inet_close.c
@@ -412,6 +412,8 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
 static inline int udp_close(FAR struct socket *psock)
 {
   FAR struct udp_conn_s *conn;
+  unsigned int timeout = UINT_MAX;
+  int ret;
 
   /* Interrupts are disabled here to avoid race conditions */
 
@@ -435,21 +437,21 @@ static inline int udp_close(FAR struct socket *psock)
 
   if (_SO_GETOPT(psock->s_options, SO_LINGER))
     {
-      int ret;
+      timeout = _SO_TIMEOUT(psock->s_linger);
+    }
+#endif
 
-      /* Wait until for the buffered TX data to be sent. */
+  /* Wait until for the buffered TX data to be sent. */
 
-      ret = udp_txdrain(psock, _SO_TIMEOUT(psock->s_linger));
-      if (ret < 0)
-        {
-          /* udp_txdrain may fail, but that won't stop us from closing
-           * the socket.
-           */
+  ret = udp_txdrain(psock, timeout);
+  if (ret < 0)
+    {
+      /* udp_txdrain may fail, but that won't stop us from closing
+       * the socket.
+       */
 
-          nerr("ERROR: udp_txdrain() failed: %d\n", ret);
-        }
+      nerr("ERROR: udp_txdrain() failed: %d\n", ret);
     }
-#endif
 
 #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
   /* Free any semi-permanent write buffer callback in place. */