Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1200767imd; Thu, 1 Nov 2018 11:46:27 -0700 (PDT) X-Google-Smtp-Source: AJdET5cDNVU4XvsyGO6t51/rg6Afs6zUJQrmq93dLGpFEqZWilFfKRY8/B9//U/NIlrs7A8/v26U X-Received: by 2002:a62:c184:: with SMTP id i126-v6mr8857478pfg.53.1541097987658; Thu, 01 Nov 2018 11:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541097987; cv=none; d=google.com; s=arc-20160816; b=WwRvVkdA6DpPqA/8SNQGt8PMPV/edVdRDSd7VBDX5jIgWBeJqZa2/8HZmZ/zdNhFqk w3UHNDXFVIC2BCDJEN//BveV+P1ptXRQI9EK8J8JB+C08vDnyvbK434pMT+k9vrHUz1a JDOLnCZrplim97nnhSzqFjctqBfQjstJMj+Ec/QTKRb5o9Wfp2Mz4lmg5y/n5prS726o oPgsL7f8PAdL2my7VK6xyJtJFzM/QziAgQmge0YstyDn8J35jckEG+KS+z29VnAqZB1S Azx99up9U1Q659H+TeC+V2OX1gWfX0cf7rcPdKlUw9T0sz69+8b4XfFLgCoZ9ap1gTvE hpig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=S4leEkXBDHqYWlvPvEc9ZK40qHehCFJHN7JkA68vsmo=; b=TSqTkUm7yE3hZgdTFBwEcoJ5MdJ7GhwEb3GmUJFFN+tDe/EChfIMLa7HCtcQM8Uj3p +nf7JBV3+CGxTtMhO7Wd57ZhUV8YCVHySB8Nkr7nnkel9b3B2yhQS5W6k1eKy84HPA33 Gv5bu+dtFxzsxEp/k535fUqrX8fkes3u4n8mVSPSWTdH0Nu+lf0CgXafUYWn7jd/Vfrm jWYp8Fo0p/XmrQgDSDsELM+FjFaFFIekkLNqQ6IxVyV1D4nhNGiVwTzurdgLFFVBFqoq nRwTX3dh8LfjfWKIbWDOTE/3h1H60sHeUAL34jzl2Ga6hEq+83FKjG9g6P4NT2fB1U9b /fFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si30867828plz.250.2018.11.01.11.46.13; Thu, 01 Nov 2018 11:46:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbeKBDuB (ORCPT + 99 others); Thu, 1 Nov 2018 23:50:01 -0400 Received: from 216-12-86-13.cv.mvl.ntelos.net ([216.12.86.13]:57902 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbeKBDuA (ORCPT ); Thu, 1 Nov 2018 23:50:00 -0400 Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1gIHjp-0001W4-00; Thu, 01 Nov 2018 18:30:37 +0000 Date: Thu, 1 Nov 2018 14:30:37 -0400 From: Rich Felker To: Florian Weimer Cc: Andy Lutomirski , Dave Hansen , "Christopherson, Sean J" , Jethro Beekman , Jarkko Sakkinen , Linux API , Jann Horn , Linus Torvalds , X86 ML , linux-arch , LKML , Peter Zijlstra , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Adhemerval Zanella , carlos@redhat.com Subject: Re: RFC: userspace exception fixups Message-ID: <20181101183037.GB5150@brightrain.aerifal.cx> References: <877ehwisaa.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877ehwisaa.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 01, 2018 at 07:09:17PM +0100, Florian Weimer wrote: > * Andy Lutomirski: > > > The basic idea would be to allow libc, or maybe even any library, to > > register a handler that gets a chance to act on an exception caused by > > a user instruction before a signal is delivered. As a straw-man > > example for how this could work, there could be a new syscall: > > > > long register_exception_handler(void (*handler)(int, siginfo_t *, void *)); > > > > If a handler is registered, then, if a synchronous exception happens > > (page fault, etc), the kernel would set up an exception frame as usual > > but, rather than checking for signal handlers, it would just call the > > registered handler. That handler is expected to either handle the > > exception entirely on its own or to call one of two new syscalls to > > ask for normal signal delivery or to ask to retry the faulting > > instruction. > > Would the exception handler be a per-thread resource? > > If it is: Would the setup and teardown overhead be prohibitive for many > use cases (at least those do not expect a fault)? > > Something peripherally related to this interface: Wrappers for signal > handlers (and not just CPU exceptions). Ideally, we want to maintain a > flag that indicates whether we are in a signal handler, and save and > restore errno around the installed handler. I think the right way to make it per-thread AND low-cost would be to register not the handler, but the (per-thread) address of a function-pointer object pointing to the handler. Then switching the handler just requires a single volatile store to thread-local memory, no syscall. Rich