Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp863945imu; Tue, 20 Nov 2018 08:06:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/WkQd6SeXJHFrx5Ln6xr7O01ZfUEUHjrs2vZywF1fBor/z43L8Ii9kudBqWyxJ+301pzcPl X-Received: by 2002:a17:902:87:: with SMTP id a7mr2394101pla.239.1542729964204; Tue, 20 Nov 2018 08:06:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542729964; cv=none; d=google.com; s=arc-20160816; b=k9LzZNChY/9LaL2BrtPePIX9Uv2ZLqmRFPX1p9FrH1m2jxVe6saL2yaoGMWFCcoKoj wGYLE7AlQACuGTvReOheMaeYXh67corgiz3O6PfEiBToaBmyFu47edF5JkVjyPeh/km6 ukNb4hLzrjmriLJu00h8ZbYrKr50zQzoS3liguhGigH2Y9axweWcH/4HrRgcUGxa2BFT SrPy72SawLw7VaXiSFoYyhfpcqLZ+zi1F5TbHFcn83f///gdPWo2Gf4D7a3GrPsws3oe 2HQbrDGkHpGQfbr+/e/2RElLjk/hEzNQuosUtBTv8Z0fKR9MdZeXs7Il1Q5q8pyEz0QU PQMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=564RpV4r1oe7zmcS1r55GB01YRElCw+wkTd9WMkrj7A=; b=FQYeU0TaUqaGg1tSkE8FNEWIUiTUpSgfs9Ulyz0UG8JlavcmmkBEA1mhmnR43itnvr y6sDxcMVOJZx2V8hC/Eg4JeH0AyAziNL0atgU01bZmvXGxYjsRoyJ5d1oynSZiPnoffR VOkNCPexO7nyAiTdpv2zDXf6lONnRiODJ4Bv0fTT8m7bYLXFMsUo1rjuBH7LaNic1VnY qqukdO8iYoKdByuwWvxg+hA36HjHuIpaaJUaXe8JM9F6tSP5xFD4bIeUQMDHBWHpWeLt 4vkeVcV4xCoIUVDvWup0nsw51+I1MFkVqWqIJ7MqzpaqEBq8Y7RUJCoHQNz5+hgypHiY 2gxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mOaP8rBC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 207si4221099pfz.249.2018.11.20.08.05.48; Tue, 20 Nov 2018 08:06:04 -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; dkim=pass header.i=@kernel.org header.s=default header.b=mOaP8rBC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728667AbeKUBtb (ORCPT + 99 others); Tue, 20 Nov 2018 20:49:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:33670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbeKUBtb (ORCPT ); Tue, 20 Nov 2018 20:49:31 -0500 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A29842148E for ; Tue, 20 Nov 2018 15:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542727191; bh=8roBoGZuCicv4hoTrM6ONEj0zHK6snI9tHj+r9Z1KPw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mOaP8rBCOKdFCE2VAeZLYzRC6vjuuZbN6R+okpXzyzjpKIsr4F/nnf5zbrilMplWD iJQr8xzFUs5i6cjVxo4EZUm4mVjEjD9n4KcSYZSnj3IwWWuNEJ4YZD/yPbnS/kOm3x aGfuKRH4NTc7HiK4APd6meD99iqhCt88pfb3boP0= Received: by mail-wr1-f52.google.com with SMTP id 96so2399469wrb.2 for ; Tue, 20 Nov 2018 07:19:51 -0800 (PST) X-Gm-Message-State: AA+aEWaxjtCyItpv1l4ujVNGbUYFEwMvvOVgz0ikwUTdTCNKnpywFH7D 0IM42UdJb7187YM++BTXu4RNMAxpCnIGdjURpkPs3g== X-Received: by 2002:a5d:5541:: with SMTP id g1mr2432718wrw.330.1542727189965; Tue, 20 Nov 2018 07:19:49 -0800 (PST) MIME-Version: 1.0 References: <20181118071548.GA4795@linux.intel.com> <20181119160204.GD13298@linux.intel.com> <20181120101133.GA7319@linux.intel.com> In-Reply-To: <20181120101133.GA7319@linux.intel.com> From: Andy Lutomirski Date: Tue, 20 Nov 2018 07:19:37 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: RFC: userspace exception fixups To: Jarkko Sakkinen Cc: Andrew Lutomirski , Dave Hansen , "Christopherson, Sean J" , Jethro Beekman , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 20, 2018 at 2:11 AM Jarkko Sakkinen wrote: > > On Mon, Nov 19, 2018 at 09:00:08AM -0800, Andy Lutomirski wrote: > > On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen > > wrote: > > > > > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > > > 1. The kernel needs some way to know *when* to apply this fixup. > > > > Decoding the instruction stream and doing it to all exceptions that > > > > hit an ENCLU instruction seems like a poor design. > > > > > > I'm not sure why you would ever need to do any type of fixup as the idea > > > is to just return to AEP i.e. from chosen exceptions (EPCM, #UD) the AEP > > > would work the same way as for exceptions that the kernel can deal with > > > except filling the exception information to registers. > > > > Sure, but how does the kernel know when to do that and when to send a > > signal? I don't really like decoding the instruction stream to figure > > it out. > > Hmm... why you have to decode instruction stream to find that out? Would > just depend on exception type (#GP with EPCM, #UD). What is "#GP with EPCM"? We certainly don't want to react to #UD in general by mucking with some regs and retrying -- that will infinite loop and confuse everyone. I'm not even 100% convinced that decoding the insn stream is useful -- AEP can point to something that isn't ENCLU. IOW the kernel needs to know *when* to apply this special behavior. Sadly there is no bit in the exception frame that says "came from SGX".