Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2783367imu; Mon, 19 Nov 2018 06:07:11 -0800 (PST) X-Google-Smtp-Source: AJdET5dfgBCWhZMraJz53hTgdoB4OIAnDAZa6m+4Hirh9WcpbuJ3JbDokK5ypr1Wc40fsG2pLYQ+ X-Received: by 2002:a65:4142:: with SMTP id x2mr18502541pgp.356.1542636431257; Mon, 19 Nov 2018 06:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542636431; cv=none; d=google.com; s=arc-20160816; b=ll4FoFUHLmpww2R5JAWsQ3ActwQT8WQ3pHGfF0orNkCocl2Dm2ntiUE8VGriZXoeRZ 0zffkiZtmMsPl7idOQBW12wYnehXkOIG43Sini272ewy14LV3QD0qC1uA3iqi+MOpbge QdKVvDgU+1CThTpmXe4KW+TddL09ufkz3DvhK2lgItvCp2F01QuAP4RGpKridauN+Uve OEoXWsmNqX2Rf2wOFPodkdAO0pfRoMJxD7R22ILA+N5vjzQezdxV+KDv6fa8AiiK98PJ zVsspaMdZdGqEK2C2egG9Jdqho66Mk6zR9q3pILdLzYjup2HLegrMR6lky7ulzd/U3MB BXZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=zjgTsQIjxgEAT5iMRwdntx4FoPYmew/fFnmkBm5tN5U=; b=Ka6/UnfG4QHeJwvCgXL7GvnB7xy3PGelAmllsW+78RyGhNqqjbhvZyKmah1Pu/JuEg sUpElNWm6oekwwUw9vYOg5Px8IIX6+h7rINtMAdTxwLlzAgex5d4EATOAaaMoLCJfrmt rJT2nAtYZCOxeKfO+Y1PvJk0PHcL7WvxfptNqbrT2UziI/+tAocpWiHSmI0mgN1VdLt9 6GySU13pzlhxyXWwZg2zgLwVcj44a8W8y9HpEv6z1628lF6ptixpa5vp5f5NlwcZLRtE bSvPqvBqOPCzQRpMHMH014alH67EydvOTRDf3voSUA6E5TdgDD7ODkZWmAIizPUzD9Rb 3Vfg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si22739679pli.175.2018.11.19.06.06.29; Mon, 19 Nov 2018 06:07:11 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729401AbeKTA3e (ORCPT + 99 others); Mon, 19 Nov 2018 19:29:34 -0500 Received: from mga17.intel.com ([192.55.52.151]:15864 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729331AbeKTA3e (ORCPT ); Mon, 19 Nov 2018 19:29:34 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2018 06:05:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,252,1539673200"; d="scan'208";a="101452753" Received: from tmuluk-mobl4.ger.corp.intel.com (HELO localhost) ([10.249.254.135]) by orsmga003.jf.intel.com with ESMTP; 19 Nov 2018 06:05:44 -0800 Date: Mon, 19 Nov 2018 16:05:43 +0200 From: Jarkko Sakkinen To: Jethro Beekman Cc: Andy Lutomirski , Dave Hansen , "Christopherson, Sean J" , Florian Weimer , Linux API , Jann Horn , Linus Torvalds , X86 ML , linux-arch , LKML , Peter Zijlstra , Rich Felker , "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 Subject: Re: RFC: userspace exception fixups Message-ID: <20181119140543.GF8755@linux.intel.com> References: <20181118071548.GA4795@linux.intel.com> <20181118130203.GA18934@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 05:17:26AM +0000, Jethro Beekman wrote: > On 2018-11-18 18:32, Jarkko Sakkinen wrote: > > On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: > > > On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > > > > Hi all- > > > > > > > > The people working on SGX enablement are grappling with a somewhat > > > > annoying issue: the x86 EENTER instruction is used from user code and > > > > can, as part of its normal-ish operation, raise an exception. It is > > > > also highly likely to be used from a library, and signal handling in > > > > libraries is unpleasant at best. > > > > > > > > There's been some discussion of adding a vDSO entry point to wrap > > > > EENTER and do something sensible with the exceptions, but I'm > > > > wondering if a more general mechanism would be helpful. > > > > > > I haven't really followed all of this discussion because I've been busy > > > working on the patch set but for me all of these approaches look awfully > > > complicated. > > > > > > I'll throw my own suggestion and apologize if this has been already > > > suggested and discarded: return-to-AEP. > > > > > > My idea is to do just a small extension to SGX AEX handling. At the > > > moment hardware will RAX, RBX and RCX with ERESUME parameters. We can > > > fill extend this by filling other three spare registers with exception > > > information. > > > > > > AEP handler can then do whatever it wants to do with this information > > > or just do ERESUME. > > > > A correction here. In practice this will add a requirement to have a bit > > more complicated AEP code (check the regs for exceptions) than before > > and not just bytes for ENCLU. > > > > e.g. AEP handler should be along the lines > > > > 1. #PF (or #UD or) happens. Kernel fills the registers when it cannot > > handle the exception and returns back to user space i.e. to the > > AEP handler. > > 2. Check the registers containing exception information. If they have > > been filled, take whatever actions user space wants to take. > > 3. Otherwise, just ERESUME. > > > > From my point of view this is making the AEP parameter useful. Its > > standard use is just weird (always point to a place just containing > > ENCLU bytes, why the heck it even exists). > > I like this solution. Keeps things simple. One question: when an exception > occurs, how does the kernel know whether to set special registers or send a > signal? Yes, and AFAIK people do in many cases people want to do something else than just direct ERESUME in AEP handler so would neither be a major bummer for user space. If I remember correctly you have such? You can check the cases that we have for SIGSEGV (namely EPCM conflict) from Sean's patch 08/23. I'm open for expanding the scope. It is the easy part after there is consensus for the handling mechanism :-) /Jarkko