From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90201C0044C for ; Thu, 1 Nov 2018 18:45:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BF6C2064C for ; Thu, 1 Nov 2018 18:45:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BF6C2064C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=libc.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-sgx-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727668AbeKBDuB (ORCPT ); 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-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Message-ID: <20181101183037.dA1IWZH5orSiiZx3BTrdrjKYKErBBjEtKo-v_G371Bg@z> 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