Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp550164ybk; Sat, 9 May 2020 10:40:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLBTuJtDR1KaR7Fp3uJIw5TVN2L4yPOSjQtHNTol3ep10G2v4zgDscOTc7eXnZnIoiot2TJ X-Received: by 2002:a17:906:6845:: with SMTP id a5mr6566213ejs.143.1589046048793; Sat, 09 May 2020 10:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589046048; cv=none; d=google.com; s=arc-20160816; b=hHFFlh0DkRMQJijivyfyyS1BqDxW8EdUb85lOVx47Y7nvddWCFKhg2t6f2ff0QYQ4a Lb7lKzskz5NoSOFjohxageVS0Fuw5LdOiNpcGD28orLGzYOjJpdVr8wlpgGT9Rg89O7j VF3h8MnBWLxBsjUJ4/mbGMCtnrSsFZQ8NgJjOjClIBFf904jAgvY+XbpRPvmzdhd3rFX rhEbv7amtymmbFC/NlGlQE8bgLsfBWyCLqc9FekYiDoXF+C42vfhp3+PAqdxXj5jh3IM PKetWLHYtRl07gs+f4cRHqE4n3gmg5KHw3hPTb1Gl/w/2/8JWkd93uhlrozreEKAGpic G6mw== 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 :dkim-signature; bh=xh59qdvZKT/2smZpy1buKM9WShKhZKzzO6IzI/GxFHQ=; b=T+Lduyku6p5qEX5xC9uKaaRanX79e/v99IxEC4Gsyfa134o9yo6uNq+hC1UhQKRWlr dUN1Pfr2ddK8uD332Mox+823/NhYER88dhBqPupj6F8icMRjmo8gZSYIGKWa1GqaQl0A FqmAr6h7Iyc9P5YRLrPcyqw/yr7AGUkemrEd6FtAypUfNy48le5NxUorehhCLfRM5oH7 Isexuk659ZCX/SGcEDx+je1dikaZC6WsJbmzsW4pa1yTwMtzTmNfVOk09kyvStRCWhrw 4TVfqznULLyZH7lctturW1Fglc3BeRSvk95iAPGx+aFbV3FNe9eCf1Fll8zv/b/sNCk5 OwAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mod8d75B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id y12si2918436edv.154.2020.05.09.10.40.25; Sat, 09 May 2020 10:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mod8d75B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728759AbgEIRhu (ORCPT + 99 others); Sat, 9 May 2020 13:37:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:54520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728535AbgEIRhN (ORCPT ); Sat, 9 May 2020 13:37:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 7719C2192A; Sat, 9 May 2020 17:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589045832; bh=+jhPw0rKcLdSwEpXP+vf94JohnnlOBJwaZ5En19kTlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mod8d75B92+rWLttUL4g2Tu+0EghX7N/Er7lNFB77Seg70dYLku1egPJ/XQX8QHWm aTy9DvIdaF4v6z0yfhER+D/UTTAVE6w8OSdBvl32XL0PWzcXgDN3MBdouQsA2B4AfN 02Dbd3zQSHF83PDOHpt8Cx89z2Q8ITf8V+PW2AAM= From: Sasha Levin To: linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org Cc: hpa@zytor.com, dave.hansen@intel.com, tony.luck@intel.com, ak@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com, Sasha Levin Subject: [PATCH v11 09/18] x86/fsgsbase/64: Add intrinsics for FSGSBASE instructions Date: Sat, 9 May 2020 13:36:46 -0400 Message-Id: <20200509173655.13977-10-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200509173655.13977-1-sashal@kernel.org> References: <20200509173655.13977-1-sashal@kernel.org> 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 [ 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 Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin Reviewed-by: Andy Lutomirski Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Dave Hansen Cc: Tony Luck Cc: H. Peter Anvin Cc: Andi Kleen --- 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 bca4c743de77c..fdd1177499b40 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.20.1