From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: MPS: a random backtrace while toying with gdb Date: Sun, 30 Jun 2024 11:52:52 +0300 Message-ID: <86r0cehkwr.fsf@gnu.org> References: <87bk3jh8bt.fsf@localhost> <867ce7hvvz.fsf@gnu.org> <86tthbgdlr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10761"; mail-complaints-to="usenet@ciao.gmane.io" Cc: pipcet@protonmail.com, yantar92@posteo.net, emacs-devel@gnu.org, eller.helmut@gmail.com To: Gerd =?iso-8859-1?Q?M=F6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 30 10:53:42 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sNqJZ-0002YV-QF for ged-emacs-devel@m.gmane-mx.org; Sun, 30 Jun 2024 10:53:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNqIu-0002EM-Mn; Sun, 30 Jun 2024 04:53:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sNqIt-0002EC-0Y for emacs-devel@gnu.org; Sun, 30 Jun 2024 04:52:59 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sNqIs-0004ry-Nu; Sun, 30 Jun 2024 04:52:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=ilhGb67cPOT76p+TFhFJlmHkrRGA1hW+eoq8uGjKmD8=; b=eGacAp5o+TNXLT+hELgn 1PSPGsZn3HPJb9GP3sFHsbok1VyjfKM2NfJ/yrlDpMT3LXtFqCZ48DJaifvUViZkVjvSyGuU8IHN2 eThQ0vbT36skUw9EM3M8del6HB03CsjDXahXbs9K5mqmM6SBvjzS72+97zOyrqom8y+8phP4LWrPd sMJck/+PNmAfvX7aGsnynVRj1Q8pMi1zTAA8tu54X/tOFYJMvYw7vPcFNve4bZA/FytAfnF6DxxpL 7/uRHLK3MxjA1TIyw/xMf2v4GAZLpocAgcT9pg2WlCxiCu/Gwpi6e5qlml5OkH/+pIcVVv1ZkKRny 7X5VpDN5gE6NmA==; In-Reply-To: (message from Gerd =?iso-8859-1?Q?M=F6llmann?= on Sun, 30 Jun 2024 08:43:02 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:320924 Archived-At: > From: Gerd Möllmann > Cc: pipcet@protonmail.com, yantar92@posteo.net, emacs-devel@gnu.org, > eller.helmut@gmail.com > Date: Sun, 30 Jun 2024 08:43:02 +0200 > > Eli Zaretskii writes: > > > Why "yuck"? That's a valid solution, IMO, especially if there are no > > better ones. I'm talking about blocking only a small number of > > signals: SIGCHLD, SIGPROF, SIGALRM, and maybe also SIGIO and SIGINT. > > (We should also consider SIGUSR1 and SIGUSR2.) > > I find that really ugly. Of course, should there be no other solution on > some platforms, we can try that. It's not needed for macOS, for example. We should only block signals where that is necessary, of course. > >> > Are there any guidance in the MPS docs for handling such signals in > >> > these situations? If not, can we ask them for guidance? It is > >> > unrealistic to expect any real-life program to do nothing in signal > >> > handlers except setting flags. And even flags could be subject to MPS > >> > moving GC, at least in some cases. So there must be some way of > >> > dealing with that in a safe way. > >> > >> It's Emacs' fault. MPS cannot reasonably be expected to assume that a > >> client program uses MPS managed memory in a signal handler. My 2 cents. > > > > That's unreasonable, IMNSHO. Programs manage memory for various > > purposes, and nothing in principle should prevent a program from > > accessing MPS-managed memory from a signal handler. > > I disagree. > > > Are you saying that a program that manages _all_ of its heap-allocated > > memory via MPS cannot also handle signals in a safe way? > > The program can do both, but only if the signal handler behaves. There > is not much a signal handler is allowed to do. Portably it can do almost > nothing. But even non-portably, it's never safe to call non-reentrant > code. On Linux, there is a list of async-signal-safe functions one can > call in a signal handler, others cannot be used. Which unsafe function did we call in this case, though? AFAICT, we simply accessed memory that happens to be behind the barrier: #9 0x00007ffff3048050 in () at /lib64/libc.so.6 #10 0x0000555555827385 in PSEUDOVECTORP (a=XIL(0x7fffeb90875d), code=9) at /home/yantar92/Git/emacs/src/lisp.h:1105 #11 PROCESSP (a=XIL(0x7fffeb90875d)) at /home/yantar92/Git/emacs/src/process.h:212 #12 XPROCESS (a=XIL(0x7fffeb90875d)) at /home/yantar92/Git/emacs/src/process.h:224 #13 handle_child_signal (sig=sig@entry=17) at process.c:7660 Line 7660 of process.c is this: struct Lisp_Process *p = XPROCESS (proc); What "crime" did we commit here? > I don't expect MPS to be async-signal-safe. I find that unreasonble. > Why would it be? Emacs's isn't either. Almost nothing is. See above: I'm not sure this is about async-signal-safety. > >> Just remembered that I won't be able to reproduce this anyway an macOS, > >> where barriers don't use signals. > > > > AFAIU, this scenario is not necessarily related to barrier-related > > signals. SIGCHLD caused us to access MPS-managed memory, which > > violated some assertion in MPS, because the arena lock was already > > taken. > > I would have to see an example where no barrier is involved. It is in > this case. MPS is doing work, therefore holds the lock, receives SIGxy > which it let's the client handle. The client hits a barrier, which > invokes MPS's signal handler, which tries to acquire the lock which is > already taken. Wouldn't the equivalent mechanism used on macOS also want to acquire the arena lock in this case? If not, what will it do?