Received: by 10.213.65.68 with SMTP id h4csp1811051imn; Mon, 19 Mar 2018 13:58:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELuyHW0RZ4BOjY2QprM4eHleYEZ9UlTPoxcsN2dV5GQ6psDLN5zG7SsTmmLek5h5QoAwEubX X-Received: by 10.101.97.26 with SMTP id z26mr10200613pgu.44.1521493108764; Mon, 19 Mar 2018 13:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521493108; cv=none; d=google.com; s=arc-20160816; b=RIgecdzYLHPIkShTFVN497lxRPIsHujW4tnvSNcIugzA4wsH2oTeD3Q9Tpq6Ak1DhT GxPIf35Gt10nG8oO89/8ub1VeoVg171GvVr5llrBIYwPQOwdaBQNZRc5zusrW4UyoZLb oFfs3szBa5Qb6NAmFgKvVccGqx30ZdFQmGmDro1atGtYQR/0Q7Q73DBbtXPRVvbBeJbp DaGxdeW6PFKZ9C2ZSDuQTiq5TDD/FZMsrLygT62pOF6ivIKSYTUtRqIq5WU4mihLpa29 cve/7NHBGqejbjdUn6D/GhOxZiLvQVRqbk0WevVY7TX8fpqGmBSdb+MxMxLJnRqioqmI Icfg== 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:arc-authentication-results; bh=umkPUeZiwRjpE6dX85EGfGSQ31xIqG83EmbnZT+aAQE=; b=rHcB0swB16+MKEFTYK7Us1G0yv1WFqfjQgx9BBAlNXFBVRtGNfy7SM/PCsiJkrDI6S oR84R0GcaKxiIKqADY2Y3/kEH+KBsr34euzObm9E8QOlM1Gf8LASpALInHowdDMcLA1w OKAlu32CUnmFLJ+jl1W37ToxcAeR4iZY7HBDuz1ja+1U8O5DPxwUhtAGm1y0m3UrZs7E 8ySzTTBjP5KiHSdPGjHYzLxOuaJ9Ac/Jaw6DdTlpYxW+zsyVQ7NbKKjL3RnqDBM8A10K kbtJBR3hglgZ4OAwWNGC+sSgBv1w0bvlptHEFeOuNCiWg3g2pPONws3GrK+RliW2j9VM rBPg== 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 o18si38445pfa.401.2018.03.19.13.58.14; Mon, 19 Mar 2018 13:58:28 -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 S968478AbeCSSIw (ORCPT + 99 others); Mon, 19 Mar 2018 14:08:52 -0400 Received: from mga14.intel.com ([192.55.52.115]:62509 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965309AbeCSSIr (ORCPT ); Mon, 19 Mar 2018 14:08:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2018 11:08:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,331,1517904000"; d="scan'208";a="39330555" Received: from chang-linux.sc.intel.com ([143.183.85.144]) by fmsmga001.fm.intel.com with ESMTP; 19 Mar 2018 11:08:47 -0700 From: "Chang S. Bae" To: x86@kernel.org Cc: luto@kernel.org, ak@linux.intel.com, hpa@zytor.com, markus.t.metzger@intel.com, tony.luck@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com Subject: [PATCH 00/15] x86: Enable FSGSBASE instructions Date: Mon, 19 Mar 2018 10:49:12 -0700 Message-Id: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org FSGSBASE is 64-bit instruction set to allow read/write FS/GS base from any privilege. As introduced from Ivybridge, enabling effort has been revolving quite long [2,3,4] for various reasons. After extended discussions [1], this patchset is proposed to introduce new ABIs of customizing FS/GS base (separate from its selector). FSGSBASE-enabled VM can be located on hosts with either HW virtualization or SW emulation. KVM advertises FSGSBASE when physical CPU has and emulation is supported in QEMU/TCG [5]. In a pool of mixed systems, VMM may disable FSGSBASE for seamless VM migrations [6]. A couple of major benefits are expected. Kernel will have performance improvement in context switch by skipping MSR write for GS base. User-level programs (such as JAVA-based) benefit from avoiding system calls to edit FS/GS base. Changes when FSGSBASE enabled: * In context switch, a thread's FS/GS base is secured regardless of its selector [1]. * (Subsequently) when ptracer updates FS/GS base, it is (always) carried onto the tracee. This is an outcome of discussions with our GDB contact. Also, checked with other toolchains [7, 8]. * On paranoid entry, GS base is compared with the kernel’s to decide the necessity of SWAPGS. [1] Recent discussion on LKML: https://marc.info/?t=150147053700001&r=1&w=2 [2] Andy Lutomirski’s rebase work : https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/log/?h=x86/fsgsbase [3] Patch set shown in year 2016: https://marc.info/?t=145857711900001&r=1&w=2 [4] First patch set: https://lkml.org/lkml/2015/4/10/573 [5] QEMU with FSGSBASE emulation: https://github.com/qemu/qemu/blob/026aaf47c02b79036feb830206cfebb2a726510d/target/i386/translate.c#L8186 [6] 5-level EPT: http://lkml.kernel.org/r/9ddf602b-6c8b-8c1e-ab46-07ed12366593@redhat.com [7] RR/FSGSBASE: https://mail.mozilla.org/pipermail/rr-dev/2018-March/000616.html [8] CRIU/FSGSBASE: https://lists.openvz.org/pipermail/criu/2018-March/040654.html Andi Kleen (1): x86/fsgsbase/64: Add intrinsics/macros for FSGSBASE instructions Andy Lutomirski (4): x86/fsgsbase/64: Make ptrace read FS/GS base accurately x86/fsgsbase/64: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE x86/fsgsbase/64: Preserve FS/GS state in __switch_to if FSGSBASE is on x86/fsgsbase/64: Enable FSGSBASE by default and add a chicken bit Chang S. Bae (10): x86/fsgsbase/64: Introduce FS/GS base helper functions x86/fsgsbase/64: Use FS/GS base helpers in core dump x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to x86/ptrace: A new macro to get an offset of user_regs_struct x86/fsgsbase/64: Add putregs() to handle multiple elements' setting x86/fsgsbase/64: putregs() in a reverse order x86/fsgsbase/64: Enable FSGSBASE instructions in helper functions x86/fsgsbase/64: When copying a thread, use FSGSBASE if enabled x86/fsgsbase/64: With FSGSBASE, compare GS bases on paranoid_entry x86/fsgsbase/64: Support legacy behavior when FS/GS updated by ptracer Documentation/admin-guide/kernel-parameters.txt | 2 + arch/x86/entry/entry_64.S | 54 ++++- arch/x86/include/asm/elf.h | 6 +- arch/x86/include/asm/fsgsbase.h | 200 +++++++++++++++++ arch/x86/include/asm/inst.h | 15 ++ arch/x86/kernel/cpu/common.c | 20 ++ arch/x86/kernel/process_64.c | 274 ++++++++++++++++++++---- arch/x86/kernel/ptrace.c | 253 ++++++++++++++++------ 8 files changed, 696 insertions(+), 128 deletions(-) create mode 100644 arch/x86/include/asm/fsgsbase.h -- 2.7.4