From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.devel Subject: Re: MPS: a random backtrace while toying with gdb Date: Tue, 02 Jul 2024 14:24:33 +0000 Message-ID: References: <87bk3jh8bt.fsf@localhost> <86r0cefb0i.fsf@gnu.org> <86msn1fk0c.fsf@gnu.org> <86h6d9dlyg.fsf@gnu.org> <86h6d8c52h.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13445"; mail-complaints-to="usenet@ciao.gmane.io" Cc: eller.helmut@gmail.com, gerd.moellmann@gmail.com, yantar92@posteo.net, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jul 02 16:43:21 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 1sOej3-0003J2-OI for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 16:43:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOeht-0004Ft-FM; Tue, 02 Jul 2024 10:42:09 -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 1sOeR6-0007RX-BG for emacs-devel@gnu.org; Tue, 02 Jul 2024 10:24:48 -0400 Original-Received: from mail-40134.protonmail.ch ([185.70.40.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOeQy-0002M7-Rf; Tue, 02 Jul 2024 10:24:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1719930276; x=1720189476; bh=oEfaFuMr8XmdWaxeebGSuXPU/oj7AqDmcM5riAldyMM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=qeOiX4BYkHndT341iPDxS9s2wGQPR3l+92F7itQBaovHF0ZkO+j7k3xyjCKlz6mJm 9ER2D9leMomemAQJo3i/SKMPqJxEDFRBbxe8X0nwEya79AlfbsCE07gY8hBm5oiBYo 52URMM0dG3Q0vTGoVFc02g8denkrdSVYPA3OxYkheCQK+cvWHcZKXNnDw9ZRU4OA3J 4xPnmh/r2pNlGYuVBPZK738qYyRIVwyqORfPlbg9PcLiWqmWchgDiA/2XSAvEOMNQl BfrbM7ONpOfUf178X3l8rtD9QX3PgrHKTLZLl207/054R/i7ymc16cPMqGO/FHGZnJ thhRWtQOB5vkw== In-Reply-To: <86h6d8c52h.fsf@gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 37f4c19dcf6ef13f19c0cac12b103bee44575818 Received-SPF: pass client-ip=185.70.40.134; envelope-from=pipcet@protonmail.com; helo=mail-40134.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 02 Jul 2024 10:42:06 -0400 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:321167 Archived-At: On Tuesday, July 2nd, 2024 at 13:10, Eli Zaretskii wrote: > > Date: Tue, 02 Jul 2024 07:55:26 +0000 >=20 > > From: Pip Cet pipcet@protonmail.com > > Cc: eller.helmut@gmail.com, gerd.moellmann@gmail.com, yantar92@posteo.n= et, emacs-devel@gnu.org > >=20 > > > Which is why I suggested to block the signals before calling MPS and > > > unblock them immediately when we return from an MPS call. All of > > > these calls are in igc.c, so the job of adding these blocks, while > > > mundane and boring, is not impossible. > >=20 > > And it adds two syscalls to what should be a very fast operation. I'm n= ot convinced it's necessary. >=20 > We should time these syscalls if we are afraid they could slow us > down. Agreed. > > > That's not the problem, AFAIU. The problem is that a signal handler > > > which accesses Lisp data or the state of the Lisp machine could > > > trigger an MPS call, which will try taking the arena lock, and that > > > cannot be nested, by MPS design. And our handlers do access the Lisp > > > machine, albeit cautiously and as little as necessary. So when the > > > signal happens in the middle of an MPS call which already took the > > > arena lock, we cannot safely access our data. > >=20 > > I've tried quite hard to make this happen, but I didn't manage it. It s= eems that whenever MPS puts up a protection barrier for existing allocated = memory, the arena lock has already been released. As signal handlers cannot= allocate memory directly, there's no deadlock, either. > >=20 > > I don't understand MPS as well as you apparently do, so could you help = me and tell where to put a kill(getpid(), SIGWHATEVER) with an appropriate = signal handler which will cause a crash (without, in the signal handler, al= locating memory)? >=20 > I thought using the profiler would trigger these easily enough? I > think someone (Helmut?) posted a simple recipe for reproducing that > some time ago? Those were all signals interrupting MPS's SIGSEGV handler. You were talking= about signals interrupting MPS code that runs outside of a signal handler,= weren't you? > Also, there was a recipe with SIGCHLD not long ago (you'd need to undo > Helmut's fixes for that, I believe, to be able to reproduce that). Same thing. > > I'm seriously tempted to suggest that until we can produce such a crash= , we can work on the assumption that blocking signals while handling SIGSEG= V is enough, but, again, I don't fully understand MPS and its complicated l= ocking scheme. >=20 > I agree that having a reproduction recipe is a necessary condition for > trying to fix this. Excellent. > > To expand a little on what I'm doing: > >=20 > > * install a handler for SIGUSR2 which dereferences a pointer stored in = a global variable (and remove the old SIGUSR2 handler) > > * modify MPS's locking functions to kill(getpid(), SIGUSR2) right after= acquiring the lock > > * in gdb, wait for a SIGSEGV to find a protected address/segment. Store= that in the pointer variable. > > * there should now be a crash when the SIGUSR2 handler runs and memory = protection for the pointer is in effect > > * no crashes observed so far. >=20 > Why not simply bind the sigusr2 event to some function (see the node > "Misc Events" in the ELisp manual for how), and then use "kill -USR2" > outside of Emacs? IOW, I guess I don't understand why you'd need all > that complexity just to reproduce the crashes. Because I wanted to be sure to hit the tiny window while a global lock was = taken. Pip