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 2026/10/17 22:30:17 UTC

(nuttx) branch master updated (aaa7f2bfc6f -> 15a3ee13cd7)

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

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


    from aaa7f2bfc6f libs/libc/unistd: Add copy_file_range().
     new 892c24d9b26 sched/semaphore: Do not fail a mutex wait for a pending signal.
     new 1c03b44a37b mm/mm_heap: Do not run without the heap lock when a signal arrives.
     new 15a3ee13cd7 mm/mm_gran: Do not fail an allocation when a signal arrives.

The 3 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:
 mm/mm_gran/mm_grancritical.c | 12 +++++++++++-
 mm/mm_heap/mm_lock.c         | 13 +++++++++++--
 sched/semaphore/sem_wait.c   | 18 +++++++++++++-----
 3 files changed, 35 insertions(+), 8 deletions(-)


(nuttx) 01/03: sched/semaphore: Do not fail a mutex wait for a pending signal.

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

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

commit 892c24d9b268f235d4775600e7fd69a872bc5e83
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 13 10:29:26 2026 +0200

    sched/semaphore: Do not fail a mutex wait for a pending signal.
    
    nxsem_wait_slow() returns -EINTR at once when an unmasked signal is
    pending, so that a signal that arrives just before the task blocks
    still interrupts the wait.  During a system call, an unmasked signal
    stays pending until the call returns.  Kernel code retries a mutex wait
    until it gets the mutex, as mm_lock() does, so each retry failed at once
    and the task looped.  If it looped in a critical section, the task that
    held the mutex could not run.
    
    On a 4-CPU arm64 SMP target, a task in pselect() with SIGCHLD pending
    freed a pending signal with kmm_free(), and mm_lock() looped in
    pselect()'s critical section while the other CPUs waited for it.
    
    Do not make this check for a mutex.  A mutex wait is not interrupted by
    a signal, and a signal that arrives while the task waits still wakes it
    through nxsem_wait_irq().
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 sched/semaphore/sem_wait.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c
index 7481b2fa7c9..3493048af98 100644
--- a/sched/semaphore/sem_wait.c
+++ b/sched/semaphore/sem_wait.c
@@ -96,14 +96,22 @@ int nxsem_wait_slow(FAR sem_t *sem)
    * TSTATE_WAIT_SEM. In that window, the wait cannot yet be aborted by
    * sem_wait_irq(). If sem_wait then blocks without re-checking unmasked
    * pending signals, it can sleep indefinitely and miss the interrupt.
+   *
+   * Not for a mutex: a mutex wait is not interrupted by a signal, and the
+   * kernel retries it until it gets the mutex (mm_lock(), for example).
+   * During a system call an unmasked signal stays pending until the call
+   * returns, so the check would make every retry fail at once.
    */
 
-  pendingset = nxsig_pendingset(rtcb);
-  nxsig_nandset(&pendingset, &pendingset, &rtcb->sigprocmask);
-  if (!sigisemptyset(&pendingset))
+  if (!mutex)
     {
-      leave_critical_section(flags);
-      return -EINTR;
+      pendingset = nxsig_pendingset(rtcb);
+      nxsig_nandset(&pendingset, &pendingset, &rtcb->sigprocmask);
+      if (!sigisemptyset(&pendingset))
+        {
+          leave_critical_section(flags);
+          return -EINTR;
+        }
     }
 #endif
 


(nuttx) 02/03: mm/mm_heap: Do not run without the heap lock when a signal arrives.

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

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

commit 1c03b44a37b5f7724980a1bf23baf682a858382d
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Mon Oct 12 14:45:33 2026 +0200

    mm/mm_heap: Do not run without the heap lock when a signal arrives.
    
    mm_lock() returned 0 even when nxmutex_lock() failed.  nxmutex_lock()
    returns -EINTR when a signal interrupts the wait, so a task that got a
    signal while another task held the heap lock went on to change the heap
    without the lock, and two tasks changed the free lists at the same
    time.  With SMP this happened within seconds when processes were
    created and reaped in parallel: SIGCHLD reached the parents while the
    heap was busy, and the heap was corrupted.
    
    Retry the lock when a signal interrupts it, and return the result.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 mm/mm_heap/mm_lock.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mm/mm_heap/mm_lock.c b/mm/mm_heap/mm_lock.c
index a5a2c649f0b..2776ee3e121 100644
--- a/mm/mm_heap/mm_lock.c
+++ b/mm/mm_heap/mm_lock.c
@@ -104,13 +104,22 @@ int mm_lock(FAR struct mm_heap_s *heap)
     }
   else
     {
-      int ret = nxmutex_lock(&heap->mm_lock);
+      int ret;
+
+      /* A signal must not make the caller run without the lock */
+
+      do
+        {
+          ret = nxmutex_lock(&heap->mm_lock);
+        }
+      while (ret == -EINTR);
+
       if (ret >= 0)
         {
           kasan_bypass(true);
         }
 
-      return 0;
+      return ret;
     }
 }
 


(nuttx) 03/03: mm/mm_gran: Do not fail an allocation when a signal arrives.

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

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

commit 15a3ee13cd7eec09084b7e64dce8a1e4fee8dbf2
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Mon Oct 12 14:45:34 2026 +0200

    mm/mm_gran: Do not fail an allocation when a signal arrives.
    
    gran_enter_critical() returned the result of nxmutex_lock(), which is
    -EINTR when a signal interrupts the wait, and gran_alloc() then returned
    NULL as if the pool were full.  The page allocator uses a granule
    allocator, so fork(), sbrk() and the stack of a new task failed with
    ENOMEM while most of the page pool was free.
    
    Retry the lock when a signal interrupts it.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 mm/mm_gran/mm_grancritical.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mm/mm_gran/mm_grancritical.c b/mm/mm_gran/mm_grancritical.c
index 06481e1de06..5a01094dbfd 100644
--- a/mm/mm_gran/mm_grancritical.c
+++ b/mm/mm_gran/mm_grancritical.c
@@ -62,7 +62,17 @@ int gran_enter_critical(FAR struct gran_s *priv)
   priv->irqstate = spin_lock_irqsave(&priv->lock);
   return OK;
 #else
-  return nxmutex_lock(&priv->lock);
+  int ret;
+
+  /* A signal must not make the allocation fail */
+
+  do
+    {
+      ret = nxmutex_lock(&priv->lock);
+    }
+  while (ret == -EINTR);
+
+  return ret;
 #endif
 }