Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1349240imu; Thu, 13 Dec 2018 13:34:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/VyhY0ZGIPxAnYgoP9Gb2BKYga6o2oYge0gmluqb4k086kThiD8AOu7r3ai/nH5Iydh/Zcs X-Received: by 2002:a17:902:6bc9:: with SMTP id m9mr398325plt.173.1544736892187; Thu, 13 Dec 2018 13:34:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544736892; cv=none; d=google.com; s=arc-20160816; b=hlslBH6EwSyk3H2TTvM8b04GrfFxRCKHIJWclTHSA6wKYTvdDDzuGl+phHJ4e6aWKW Hwq23OlfW6LHSFKpYDSA4WORKyG6VOxM+a7Az8Zdko+g9g5Y5UDpxtqHH6tqG95vVbJA SG0oG3TdjEPXEOsrbzujcKulS54V2yX3poh06I5b8HyzHmyZkfdgNq9QtR99k8zcXQIq BDgRo0UFt48rXjCwn7kVVWE4ymWtWD4O2HPTRiib1iA6uUVFvwiWTWdAxBBxdayO5rkf SaSNHGX5PUBZLU7+W5P8MQBWHKseGUhdBgj1upYThv7Vxlg1EUFZVIVe/gGRbRQg3b2F n1sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CujukCtRegZxJG29Mi4khBZL7+kda6Km4pEdp5D0aao=; b=D6z8DTwpVWNULGWevpqWCgCnTm3RSyaeVg8yI+ljoZCtOJdpbkZdslT8sY7LGk7Iqs ibAGjAvJ6fWL9jUOCh7o77ORLWF6lv3dBXyDggZ5/IOm2l8cMm8VSJJTXKcqQI3Xb9I0 AtuJBhiSfVEVb3FpVNVTlXgZYLxfQxAngBTri9P649WZ899pIHUZDZL9AEk96Xr+j9kJ upSD/AR74gYpiBnW3wSAiarqfN9dRC8t2o6hlTp4L/yCIm26htGMVNGPDRt5qUMvJRuZ H+vpgoeW7J5l033vfZJ+fmaBZITgZHQnLd2AUJ2sxlPv4DyWo8kmhz9O4wRItGRrFL3H X/Pw== 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 w75si2502778pfd.55.2018.12.13.13.34.34; Thu, 13 Dec 2018 13:34:52 -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 S1727254AbeLMVbl (ORCPT + 99 others); Thu, 13 Dec 2018 16:31:41 -0500 Received: from mga03.intel.com ([134.134.136.65]:43547 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbeLMVbl (ORCPT ); Thu, 13 Dec 2018 16:31:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Dec 2018 13:31:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,349,1539673200"; d="scan'208";a="127709232" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.154]) by fmsmga004.fm.intel.com with ESMTP; 13 Dec 2018 13:31:39 -0800 From: Sean Christopherson To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Dave Hansen , Peter Zijlstra , Jarkko Sakkinen Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, Andy Lutomirski , Josh Triplett , Haitao Huang , Jethro Beekman , "Dr . Greg Wettstein" Subject: [RFC PATCH v4 0/5] x86: Add vDSO exception fixup for SGX Date: Thu, 13 Dec 2018 13:31:30 -0800 Message-Id: <20181213213135.12913-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Episode IV: The vDSO Strikes Back After a brief detour into ioctl-based fixup, the vDSO implementation is back. Relative to v2 (the previous vDSO RFC), patch 4/4 once again contains the vast majority of changes. __vdso_sgx_enter_enclave() is now written entirely in straight assembly. Implementing the expanded enclave ABI in inline assembly was an absolute train wreck as GCC's contraints don't play nice with the full spectrum of registers. And I suspect the previous vDSO RFCs were likely broken due to incorrect register clobbering (I never tested them end-to-end). The exit_handler() concept proposed in v2 is gone. I expect most SGX libraries will directly call __vdso_sgx_enter_enclave(), at which point the overhead of returning effectively boils down to restoring the non-volatile registers, which is likely outweighed by the cost of the retpoline call (to the handler) alone. In other words, I doubt anyone will actually use the exit_handler()... ...except for libraries that want to manipulate the untrusted stack, i.e. force __vdso_sgx_enter_enclave() to treat RSP as volatile. At that point we're effectively maintaining two separate ABIs since the normal ABI would be e.g. "RBP, RSP and the red zone must be preserved" vs. the exit_handler() ABI's "RBP must be preserved". And *if* we want to deal with maintaining two ABIs, supporting the kernel's existing signal ABI is a lot cleaner (from a kernel perspective) than polluting the vDSO. v1: https://lkml.kernel.org/r/20181205232012.28920-1-sean.j.christopherson@intel.com v2: https://lkml.kernel.org/r/20181206221922.31012-1-sean.j.christopherson@intel.com v3: https://lkml.kernel.org/r/20181210232141.5425-1-sean.j.christopherson@intel.com v4: - Back to vDSO - Implement __vdso_sgx_enter_enclave() directly in assembly - Modify effective enclave register ABI to follow x86-64 kernel ABI - Split __vdso_sgx_enter_enclave input into separate non-union params - Drop the exit_handler() concept Sean Christopherson (5): x86/vdso: Add support for exception fixup in vDSO functions x86/fault: Add helper function to sanitize error code x86/fault: Attempt to fixup unhandled #PF on ENCLU before signaling x86/traps: Attempt to fixup exceptions in vDSO before signaling x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions arch/x86/entry/vdso/Makefile | 6 +- arch/x86/entry/vdso/extable.c | 37 ++++++ arch/x86/entry/vdso/extable.h | 29 +++++ arch/x86/entry/vdso/vdso-layout.lds.S | 9 +- arch/x86/entry/vdso/vdso.lds.S | 1 + arch/x86/entry/vdso/vdso2c.h | 58 ++++++++-- arch/x86/entry/vdso/vsgx_enter_enclave.S | 136 +++++++++++++++++++++++ arch/x86/include/asm/vdso.h | 5 + arch/x86/include/uapi/asm/sgx.h | 44 ++++++++ arch/x86/kernel/traps.c | 14 +++ arch/x86/mm/fault.c | 33 ++++-- 11 files changed, 349 insertions(+), 23 deletions(-) create mode 100644 arch/x86/entry/vdso/extable.c create mode 100644 arch/x86/entry/vdso/extable.h create mode 100644 arch/x86/entry/vdso/vsgx_enter_enclave.S -- 2.19.2