[PATCH] The critical section lock _can_ be held in these place.
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Fri, 10 Jan 2020 22:21:25 +0000 (22:21 +0000)
committerAurelien Jarno <aurel32@debian.org>
Fri, 10 Jan 2020 22:21:25 +0000 (22:21 +0000)
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 88ebcccd82e8588b4359c5b28eba08205801153f..1bcba456f90bc15b42e0c3cdb7f651f86560c7c7 100644 (file)
@@ -123,7 +123,6 @@ _hurd_exec_paths (task_t task, file_t file,
 
   ss = _hurd_self_sigstate ();
 
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
 
   __spin_lock (&ss->lock);
index ade938c93e038ec9db381f881538d837c71ec6dc..5234bef68a351964daeed389cf8ce66141da8678 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 0e4705dd4831c9af2079371bc32ddbba0bac20cb..e7e64dffc37f529ac929c76ca3994bf78d64695d 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 4e818ec3e66730c2828a963e2273b27ffd8a620a..25dfc82d0e3744c360e5664631db4304f9b0e811 100644 (file)
@@ -333,7 +333,6 @@ __spawni (pid_t *pid, const char *file,
 
   ss = _hurd_self_sigstate ();
 
-  assert (! __spin_lock_locked (&ss->critical_section_lock));
   __spin_lock (&ss->critical_section_lock);
 
   __spin_lock (&ss->lock);