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 17:06:08 +0000 Message-ID: References: <87bk3jh8bt.fsf@localhost> <86msn1fk0c.fsf@gnu.org> <86h6d9dlyg.fsf@gnu.org> <86h6d8c52h.fsf@gnu.org> <86sewrc057.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="27075"; 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 20:21:38 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 1sOi8I-0006rO-9b for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 20:21:38 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOi7U-0002eS-7q; Tue, 02 Jul 2024 14:20:48 -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 1sOgxO-0004DM-Bj for emacs-devel@gnu.org; Tue, 02 Jul 2024 13:06:18 -0400 Original-Received: from mail-4322.protonmail.ch ([185.70.43.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOgxM-0007Ft-3d for emacs-devel@gnu.org; Tue, 02 Jul 2024 13:06:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1719939973; x=1720199173; bh=kxxIpNu5YoVx9proPf8mmnWyvdd/LhfQ9xQx4aOP+kk=; 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=U/95NsDG9kYiUZjqOv6fd0wQFubqOfn+zdjJ2PeJpbYiXSRhkzdq02cd5oZV8r9g4 TzbWsODHTziNZadv1m0Rv5wBCFJnkol6pyNXvYNPssUaHTIAYQUet0Hq1HVvV5Kl1R pdLskMmxSaxq3AYtR6UWxMT2MVYvbiU1SEZhqEOjYiUcWn/Sm8YietUdMbsN+smXvl DQY9yqMpEQ6GMqqIQaZf36hCz0XoBAjXTU7OTOjkssTuq0ZDq4+R/3NxcJbu8RevYS jia6X7ZM1bOeRDzTWGJczCaazBVU+lhmXhFQDg69c9qrlMVeVaXS2cxBR9MGgMvEJg Ax4TJe5mk9VYA== In-Reply-To: <86sewrc057.fsf@gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: fc2e775e9e2297ca0907b30e95d874d5b521ba59 Received-SPF: pass client-ip=185.70.43.22; envelope-from=pipcet@protonmail.com; helo=mail-4322.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, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 02 Jul 2024 14:20:42 -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:321194 Archived-At: On Tuesday, July 2nd, 2024 at 14:57, Eli Zaretskii wrote: > > Date: Tue, 02 Jul 2024 14:24:33 +0000 > > From: Pip Cet pipcet@protonmail.com > > Cc: eller.helmut@gmail.com, gerd.moellmann@gmail.com, yantar92@posteo.n= et, emacs-devel@gnu.org > >=20 > > > > > That's not the problem, AFAIU. The problem is that a signal handl= er > > > > > which accesses Lisp data or the state of the Lisp machine could > > > > > trigger an MPS call, which will try taking the arena lock, and th= at > > > > > cannot be nested, by MPS design. And our handlers do access the L= isp > > > > > machine, albeit cautiously and as little as necessary. So when th= e > > > > > signal happens in the middle of an MPS call which already took th= e > > > > > 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 seems that whenever MPS puts up a protection barrier for existing alloca= ted memory, the arena lock has already been released. As signal handlers ca= nnot allocate memory directly, there's no deadlock, either. I finally figured out what I was doing wrong. I was allocating a few very l= arge objects, but I needed many very small ones. ./emacs --batch -Q --eval "(progn (setq list nil) (keymap-set special-event= -map \"\" (lambda () (interactive) (length list))) (while t (push = nil list)))" & while sleep .1; do kill -USR1 %%; done works. > > Those were all signals interrupting MPS's SIGSEGV handler. You were tal= king about signals interrupting MPS code that runs outside of a signal hand= ler, weren't you? >=20 >=20 > I don't think they all were interrupting MPS's SIGSEGV handler. I > think it's the other way around: we interrupted MPS code, and our > signal handler accessed memory which triggered MPS's SIGSEGV. You're correct. > But even if I'm wrong, why is that important? We need to solve both > kinds of situations, don't we? Now that we have a way to reproducibly make it happen, yes, I agree. > > > Also, there was a recipe with SIGCHLD not long ago (you'd need to und= o > > > Helmut's fixes for that, I believe, to be able to reproduce that). > >=20 > > Same thing. >=20 > Not AFAICT. Look: I did, now. You're right. > . we called Fcons (from a "normal" Emacs Lisp program, which called > set-face-attribute) > . that entered MPS by way of igc_make_cons > . MPS called our scanning code in dflt_scan > . while in fix_* functions called by dflt_scan, we got SIGCHLD > . the SIGCHLD handler accessed Lisp data of the process object(s), > which triggered MPS SIGSEGV handler > . the MPS handler tried to take the arena lock and aborted >=20 > IOW, SIGCHLD did NOT interrupt the MPS SIGSEGV handler, it interrupted > the "normal" MPS code when it called our scanning callbacks. You're right, again. > > > 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. > >=20 > > Because I wanted to be sure to hit the tiny window while a global lock = was taken. >=20 > I think the scenario above with SIGCHLD does precisely that, no? It does. Pip