[PATCH] The critical section lock _can_ be held in these place.
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 17 May 2025 15:15:43 +0000 (17:15 +0200)
committerAurelien Jarno <aurel32@debian.org>
Sat, 17 May 2025 15:15:43 +0000 (17:15 +0200)
At least since hurd_thread_cancel can be called by another thread and lock our
critical lock.

http://bugs.debian.org/46859


Thomas suggested that there is no need to take the critical section
lock.  I believe that taking the critical section lock is necessary to
prevent the target thread from entering a signal handler.  Roland will
look into the problem.


Taking the critical section lock makes these assertions bogus.

It happens that hurd_thread_cancel is only called from libports and inside
/hurd/term so this is rare in practice.

A reproducer can be found here:

http://lists.gnu.org/archive/html/bug-hurd/2014-05/msg00025.html

2006-08-05  Samuel Thibault  <samuel.thibault@ens-lyon.org>

       * hurd/thread-cancel.c (hurd_thread_cancel): Do not assert that
       `&ss->critical_section_lock' is unlocked.
       * sysdeps/mach/hurd/jmp-unwind.c (_longjmp_unwind): Likewise, and take
       critical section lock before taking the sigstate lock.
       * sysdeps/mach/hurd/spawni.c (__spawni): Likewise.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name tg-thread-cancel.diff

hurd/hurdexec.c
hurd/thread-cancel.c
sysdeps/mach/hurd/jmp-unwind.c
sysdeps/mach/hurd/spawni.c

index 32878382edc8319dbe89856ad1bdf8b6e690d750..24aef607901413a5b36ff6c123cbf8298cb1197f 100644 (file)
@@ -128,7 +128,6 @@ _hurd_exec_paths (task_t task, file_t file,
   ss = _hurd_self_sigstate ();
 
 retry:
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
 
   _hurd_sigstate_lock (ss);
index bb60f35d4e5cfeebd32b873cd7c365864a1f8e77..4c78062f59eb6408267b3033d19e838d925d70da 100644 (file)
@@ -42,7 +42,6 @@ hurd_thread_cancel (thread_t thread)
       return 0;
     }
 
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
   __spin_lock (&ss->lock);
   err = __thread_suspend (thread);
@@ -82,7 +81,6 @@ hurd_check_cancel (void)
   int cancel;
 
   __spin_lock (&ss->lock);
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   cancel = ss->cancel;
   ss->cancel = 0;
   __spin_unlock (&ss->lock);
index 681225496cb60eab8fbc2fb938600863c902841f..ede03124612c1602fe3b8caea9aa9116668ee4ee 100644 (file)
@@ -47,9 +47,8 @@ _longjmp_unwind (jmp_buf env, int val)
 
   /* All access to SS->active_resources must take place inside a critical
      section where signal handlers cannot run.  */
-  __spin_lock (&ss->lock);
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
+  __spin_lock (&ss->lock);
 
   /* Remove local signal preemptors being unwound past.  */
   while (ss->preemptors
index 7eaf0ad1861319759a0f218f3a6fb7abd40b942a..d2a7004297246811616631c2999da145e44f23e5 100644 (file)
@@ -333,7 +333,6 @@ __spawni (pid_t *pid, const char *file,
   ss = _hurd_self_sigstate ();
 
 retry:
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
 
   _hurd_sigstate_lock (ss);