Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp910312ima; Fri, 1 Feb 2019 12:59:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN74FpiacFZwomRGbktoVwoLMEx8JV76Q8imZpdPJCNbVuw8m+LwqDQBzPmT8BeiPkNlDbZq X-Received: by 2002:a62:1e87:: with SMTP id e129mr40556435pfe.221.1549054765345; Fri, 01 Feb 2019 12:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549054765; cv=none; d=google.com; s=arc-20160816; b=A2P8Y+TECSvls1fWdt0HVndf+N/NniKhXF1wUuo3RChONzIq+/Ho88KB4QnbcKgIjE 6Mx2e6+ARNf21FS41FNduoMeyqLe0p42yyAN3+4R868vx6OL7WETItsKnQ2+rEuPdywL 9/hehGVpagGN7Rl7eEJPlwE0YM5hwnCbHzej0gpIon7Mjq/uky9GiYgy4K6PNkIXOly3 x9doFutDPHLG2C+zv507THWgl/SuQcZslNhVZgbThepdl/FL1vfycXCljSEg8phDm9tK /leRRMKFoCPLETWNqRkM9aTT25krPNLw43XWmJhlLp8CSSn1ZseQn6hPc9dX2Aweu9IM hAjQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e13IrCX2/ixTWgEguO2Ha3598rgY02nkYlK7jkcXtOQ=; b=j5lKnSqQIqsThCdBr5/WurbJ7nrd+h8O7JQbYX+se99MJPgNtHaCfyc8KMe2IQRrW3 uinnH7bXX5VOS9m0E5FI0BxkpfXGtKwU3ibm3KQ3W2Gh8OQhK7eU2uQDuRhuouQfpSW1 uYuRoVM2tG54CuE6aQ1QgqIL6wC8gRkz6/mTTAMgawoMccGpMCbpvqHFSpvTXKniPqk/ 7VJVT9JGxVs8OFKvrEHR+gVEuA2KEZevsK+yZ35Cd90OV7SrDKbJhPkpbBOvhGTEclAH yR6fX91URLFouPAyzvZPhA9wsjoanePkhZl5ky9//xyF3Udrft1BAiSmb3Vr9KTJQGjn TB/w== 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 11si7827327pgs.126.2019.02.01.12.59.10; Fri, 01 Feb 2019 12:59:25 -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 S1729450AbfBAUyw (ORCPT + 99 others); Fri, 1 Feb 2019 15:54:52 -0500 Received: from mga18.intel.com ([134.134.136.126]:59549 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729009AbfBAUyp (ORCPT ); Fri, 1 Feb 2019 15:54:45 -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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2019 12:54:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,549,1539673200"; d="scan'208";a="140866337" Received: from chang-linux-2.sc.intel.com ([10.3.52.165]) by fmsmga004.fm.intel.com with ESMTP; 01 Feb 2019 12:54:45 -0800 From: "Chang S. Bae" To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andi Kleen Cc: Markus T Metzger , Ravi Shankar , "Chang S . Bae" , LKML Subject: [PATCH v5 04/13] x86/fsgsbase/64: Add intrinsics for FSGSBASE instructions Date: Fri, 1 Feb 2019 12:53:09 -0800 Message-Id: <20190201205319.15995-5-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190201205319.15995-1-chang.seok.bae@intel.com> References: <20190201205319.15995-1-chang.seok.bae@intel.com> 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 From: Andi Kleen Add C intrinsics and assembler macros for the new FSBASE and GSBASE instructions. Very straight forward. Used in followon patches. [ luto: Rename the variables from FS and GS to FSBASE and GSBASE and make safe to include on 32-bit kernels. ] v2: Use __always_inline [ chang: Revise the changelog. Place them in . Replace the macros with GAS-compatible ones. ] If GCC supports it, we can add -mfsgsbase to CFLAGS and use the builtins here for extra performance. [ chang: Use FSGSBASE instructions directly. Removed GAS-compatible macros as the minimum required binutils (v2.21) supports the FSGSBASE instructions. ] Signed-off-by: Andi Kleen Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andy Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar --- arch/x86/include/asm/fsgsbase.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h index bca4c743de77..fdd1177499b4 100644 --- a/arch/x86/include/asm/fsgsbase.h +++ b/arch/x86/include/asm/fsgsbase.h @@ -19,6 +19,36 @@ extern unsigned long x86_gsbase_read_task(struct task_struct *task); extern void x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase); extern void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase); +/* Must be protected by X86_FEATURE_FSGSBASE check. */ + +static __always_inline unsigned long rdfsbase(void) +{ + unsigned long fsbase; + + asm volatile("rdfsbase %0" : "=r" (fsbase) :: "memory"); + + return fsbase; +} + +static __always_inline unsigned long rdgsbase(void) +{ + unsigned long gsbase; + + asm volatile("rdgsbase %0" : "=r" (gsbase) :: "memory"); + + return gsbase; +} + +static __always_inline void wrfsbase(unsigned long fsbase) +{ + asm volatile("wrfsbase %0" :: "r" (fsbase) : "memory"); +} + +static __always_inline void wrgsbase(unsigned long gsbase) +{ + asm volatile("wrgsbase %0" :: "r" (gsbase) : "memory"); +} + /* Helper functions for reading/writing FS/GS base */ static inline unsigned long x86_fsbase_read_cpu(void) -- 2.19.1