Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1575201ybk; Sun, 10 May 2020 21:55:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl5tnJ2ESYaTdV/BTmySGsXwwTUzwluCA6S50rIMbKGDaP2+1zMP4d8szgGsAiVkWFD2dO X-Received: by 2002:a17:906:3495:: with SMTP id g21mr301425ejb.154.1589172958010; Sun, 10 May 2020 21:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589172958; cv=none; d=google.com; s=arc-20160816; b=eToc1EAdaoRtQss1setbfGTkH+AHsn9Dt0fJBs9cZNg6R0DgUBPOXyKiFoW+TP2M/6 LUgfVPvHhsn+JAia1lO9zE3SX9exHOm8iMGMBAueuthpMqi1jBWYUYiqZti9HIelRbCz 9v8vxNJYiyvm/xW5hBAyzQ/i4CSgWpmPTZGUf0svMsl1jrLqLpZtnhrr+aKPabnHaDYI iOiETBwFbYoMGPDsm+H+JFZkC8FPg1tRo9HwCGBiltVQpU50PjJPG4yOCsKPbL+a0woz dKM+7vcQHHiy6+OJnlJjYd2264b8rfvfnJvwJc7NQ6JrOnFH0ZX4qbrySi80NauYHJWE b09A== 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=MdYHvenNeHR8Co8nOhgQfagJpMNb6RQiYuR1H/DayKNlP8WgzLBEvPRlJvCML0Upwf UsgNqpm5WbUKTUu/DfUWZnBMax40LRYg7pRZ7dy6Y3Vw7dLa+iuHifVWnad+2T8VcOl7 x9FMF/mKK6yWpup0x7yMJxHEuwL+xRUqjxk8vUuXuJas1evjWUk91VSt8DfVly8+namt P7Ur5Ca/ePb7PU2WkuKONGkNIZOr85HO7UyswSrH7chHmL6U4Eb7Oyj2CkrLMy2zM+qT LgYva4fF+QeNnqSqljDe2u02gjNygLxHOgQCnobMtHk1iVCWx9UHXspAH5JfMJt/S9G5 Un9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nV6qc3lV; 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 x25si5286985eds.136.2020.05.10.21.55.30; Sun, 10 May 2020 21:55:57 -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=nV6qc3lV; 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 S1728704AbgEKExp (ORCPT + 99 others); Mon, 11 May 2020 00:53:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:37590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728528AbgEKExj (ORCPT ); Mon, 11 May 2020 00:53:39 -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 30FD52082E; Mon, 11 May 2020 04:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172819; bh=+jhPw0rKcLdSwEpXP+vf94JohnnlOBJwaZ5En19kTlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nV6qc3lVOfq5pcVCLPmhg28LTpNiTLBEtGTVdW2qWeZZWaDO0mkxCK+zvaeYFVo/H YWtKnk6wdf+I2XzxzkIkC9SJ+O7m7ngY9pNtVCb4m6D76buDjQ9dh3TAePPJHrD00Z WNZ0HVlSqV5pdKrf8WddNt/HHRpMGay4TDAKdWU0= 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 v12 09/18] x86/fsgsbase/64: Add intrinsics for FSGSBASE instructions Date: Mon, 11 May 2020 00:53:02 -0400 Message-Id: <20200511045311.4785-10-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511045311.4785-1-sashal@kernel.org> References: <20200511045311.4785-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