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 07:55:26 +0000 Message-ID: References: <87bk3jh8bt.fsf@localhost> <86cynyhfsn.fsf@gnu.org> <87v81qp91g.fsf@gmail.com> <86r0cefb0i.fsf@gnu.org> <86msn1fk0c.fsf@gnu.org> <86h6d9dlyg.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="23647"; 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 13:07:55 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 1sObMZ-0005vn-BL for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 13:07:55 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sObLT-0004rx-7H; Tue, 02 Jul 2024 07:06:47 -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 1sOYMR-0004Q9-RR for emacs-devel@gnu.org; Tue, 02 Jul 2024 03:55:35 -0400 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOYMO-00024K-EK for emacs-devel@gnu.org; Tue, 02 Jul 2024 03:55:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1719906929; x=1720166129; bh=NhpKvMAg8vQs1d8OXjsEiG7h3icMCb6UgtDiZj4Uvn8=; 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=q5wm9E3he7/fsEHTsBq3A/D/tkt1K7pW4Rhh94rJkwRICtAIARE3EO6P6EY0Iuabf js5KLIPVSPQHtiMMjhHyhPGwlMcc6nUlMJ73MQq0gwLkFsuQP4IrpI9Eq4/XUbaHIS ldTzl/qJv7UfrWxMwTyMMGH/EJyjytlu6ynr68GdEna0xR0i8dVZc9jaxvswrrFnbr CdnqpL11u3duq3Dr1JTIJpuAebh0SqbxmQyDk9gVhITxXqyMYdKNS1qmTXIDoB6dwM z0Qcjy33kI7mfmv2KoruqfLR2yxTA9iHaCgMKFjIqRynxJ2keu01TNni0uInhvTSm5 gol+tRyoNL7yQ== In-Reply-To: <86h6d9dlyg.fsf@gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 8e855848b8e6fd5d3d3125fe322238b0547751fb Received-SPF: pass client-ip=185.70.43.16; envelope-from=pipcet@protonmail.com; helo=mail-4316.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 07:06:43 -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:321121 Archived-At: On Monday, July 1st, 2024 at 18:08, Eli Zaretskii wrote: > > Date: Mon, 01 Jul 2024 17:27:49 +0000 > > > From: Pip Cet pipcet@protonmail.com > > Cc: eller.helmut@gmail.com, gerd.moellmann@gmail.com, yantar92@posteo.n= et, emacs-devel@gnu.org > > First, that queue was intended for more than just SIGCHLD. > > And second, depending on the OS, nested signals can or cannot be > possible, so we need to take that into consideration. I understand now, I think. Thank you. > > One last suggestion: how about blocking those signals for most of Emacs= ' lifetime, only unblocking them in maybe_quit or at similar points? That w= ould allow us to keep the existing signal handlers and make them safe... > > IMO, this would be the opposite of what we should do. We should have > these signals blocked for as little time as possible, because > otherwise the features built on them will be much less useful. For > example, SIGUSR1/2 are a means of forcing Emacs out of some infinite > loop which is otherwise uninterruptible -- if we let these signals be > unblocked only in maybe_quit, we will have lost this useful feature. Thanks for making that clear. That is a very useful feature and I would lik= e to keep it. I'm also quite fond of the hourglass cursor :-) > 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. And it adds two syscalls to what should be a very fast operation. I'm not c= onvinced it's necessary. > But if people who have time to work on that disagree, I have no means > of making them do what they don't agree with. > > > I still think this is a simple oversight on the part of MPS, FWIW. You = shouldn't allow other signals when handling SIGSEGV, or at least give the c= lient program an option to specify a signal mask. > > 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. 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 allocated memo= ry, the arena lock has already been released. As signal handlers cannot all= ocate memory directly, there's no deadlock, either. I don't understand MPS as well as you apparently do, so could you help me a= nd tell where to put a kill(getpid(), SIGWHATEVER) with an appropriate sign= al handler which will cause a crash (without, in the signal handler, alloca= ting memory)? 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 SIGSEGV is= enough, but, again, I don't fully understand MPS and its complicated locki= ng scheme. To expand a little on what I'm doing: * install a handler for SIGUSR2 which dereferences a pointer stored in a gl= obal variable (and remove the old SIGUSR2 handler) * modify MPS's locking functions to kill(getpid(), SIGUSR2) right after acq= uiring the lock * in gdb, wait for a SIGSEGV to find a protected address/segment. Store tha= t in the pointer variable. * there should now be a crash when the SIGUSR2 handler runs and memory prot= ection for the pointer is in effect * no crashes observed so far. Pip