[PATCH] The critical section lock _can_ be held in these place.
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 30 Sep 2023 08:31:05 +0000 (09:31 +0100)
committerAurelien Jarno <aurel32@debian.org>
Sat, 30 Sep 2023 08:31:05 +0000 (09:31 +0100)
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 0545935d801743197196367681f63ece2fca2401..a2314bf3b2a89471f6d2f5e2bb93635c75a5e7e2 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 58259d0ab947b11e52531ba688943a78536762de..05b4052911a0f5dc204f23ab93cc32f3546f3914 100644 (file)
@@ -51,7 +51,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);
@@ -91,7 +90,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 f8938bc6f4465ef1242d66951c317b5bba03a5d9..ef124b072c86fd1f3206a402f4b4bdcad1e597da 100644 (file)
@@ -49,9 +49,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 ffc62e660e30cefb53339dd14a92bba266b25aff..d911d0909d2cdefba7a4990a7ff3025c413a4f88 100644 (file)
@@ -334,7 +334,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);