Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp743214ima; Fri, 15 Mar 2019 13:07:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0cBjiQliIAASOj/CYB5de+ALyauUzmV0D3p6n6gUysUTIXi4U9qKWjvARHwhZ40avhidQ X-Received: by 2002:a17:902:20eb:: with SMTP id v40mr6232662plg.20.1552680476944; Fri, 15 Mar 2019 13:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552680476; cv=none; d=google.com; s=arc-20160816; b=FUIej90EQ+f4BUko3cJU3rhj5mlfPu7Lz2SWPjcdOuXJkH39m/B7hTkoMiv4Yv5Gsf lCEzCUMX5RBcG7GJ++k79B4VQQ2xLzK4OtizKIvZq84O4bX2zaoqBNbaNoIOJc3TQojO ftNDHQrHkYYYTzfPxh3dE0S5ahKK78wTh+6fTAkIl+tqFvNwf2OJJvLuZI5igo5ipdnf VZ9ZiEu86EC2wbTpzVA9IJ/P4pgpGXOcTY0A9UzVVPY2s6bqa3sG3/Wuk82CpFbXKMwM rVmFJufpKDfWjVwKEPTgBqsSdDu2zQTneSrMMoj6MKmxwKQTj1+Tbu/kRw0zfScdh0UP xM4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ZUcOWZkgZV1XRw/bzOKmDnG7HX2PEUZzOJQsdZJ5Zps=; b=o3LN2mlcRYtGrjDG0BH1lCyEaaoLtGilOQOYgV13WpCJwimhxm53W3ygqEt8ZVI9cB l2FE6nsPfP2W0Imv8bfvglkGI01e57BDUsNkmRh9roMRNRgPywqivF25lHDHzQUIM8DK rp1g95Lg5X2ioZQbltltmJ0l6kBxcvSewGfJbtZPF3nPhP7KbjBYUSSRuwfEF+ZmRMgq ShPKEnQxtrIdUZAx371GedvI7ytfQRtKTwKCxcezT0eomQ6jq4XzDc3NHzco8axiF9uM 3JDi4XEMNNS/wG7KokJaK1ugJu53NT4utbH8H8+CA1GXY1xckc0YGmYgM/n0G1VkPUoN m+rQ== 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 r39si2670157pld.70.2019.03.15.13.07.41; Fri, 15 Mar 2019 13:07:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbfCOUHD (ORCPT + 99 others); Fri, 15 Mar 2019 16:07:03 -0400 Received: from mga01.intel.com ([192.55.52.88]:22894 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726465AbfCOUHB (ORCPT ); Fri, 15 Mar 2019 16:07:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2019 13:07:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,483,1544515200"; d="scan'208";a="307617691" Received: from chang-linux-3.sc.intel.com ([143.183.85.65]) by orsmga005.jf.intel.com with ESMTP; 15 Mar 2019 13:07:00 -0700 From: "Chang S. Bae" To: Thomas Gleixner , Ingo Molnar , Andy Lutomirski , "H . Peter Anvin" , Andi Kleen Cc: Ravi Shankar , "Chang S . Bae" , LKML Subject: [RESEND PATCH v6 03/12] x86/fsgsbase/64: Add intrinsics for FSGSBASE instructions Date: Fri, 15 Mar 2019 13:06:36 -0700 Message-Id: <1552680405-5265-4-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552680405-5265-1-git-send-email-chang.seok.bae@intel.com> References: <1552680405-5265-1-git-send-email-chang.seok.bae@intel.com> 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. ] Signed-off-by: Andi Kleen Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Andy Lutomirski Reviewed-by: Andi Kleen 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