Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1575291ybk; Sun, 10 May 2020 21:56:09 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0dM5SmYxq2kO19waE+rJQZUg6beB/x1DbATk4Qz9ecAtrEdHMHifVgjOF6jv8b3Am9Jnw X-Received: by 2002:a17:906:46da:: with SMTP id k26mr12119444ejs.106.1589172969703; Sun, 10 May 2020 21:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589172969; cv=none; d=google.com; s=arc-20160816; b=H28vZ+51xnAqapcThbPmRxovTlwAxFlges8t3Mf/c7lVgpoCz6jyVQc0bJ0aU3872y tldhyCJPOIQbL4N7HCdt0mW5oztKnh6vS+ZQ+LyJ5f8dINReRkOos833yKmmnSSzJL6W pbLl5Sz7e1w+bZBGPJqI8pRFGoQv0pBirKY4ySx3nkZSMxmRmxcVNRTPIDr7ruJPIl1/ uBB/h4tXqTiscmP9vpP9KtXCC6OHL+vFIZ3FMl61lKuQ5iJvQMWLjrxZCAvcTrvzDPZ2 oxTZ4tTKi02mJcr9DlSbLAicovO1pLC2lPHHLm8rjfkr7GkyniSyZCIgL7FBamSabR48 zjhg== 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=7slurwkWKop/eRO35/8+Oxb0QPhPEJnq7MA2ReJ9TaI=; b=rVlp1Rhkym8kKx9bIz/6Zdwl8FCOc7zHWTn9HUuGWeAc1rp/rTlB3JjE30MCupQ5Vf d1Gpyyeri0TWhPLLlD1A3pCgKnu0QLQgpwMdP3aE5ViGM9Gw0lxyrv/wSTq9+q9EyliU dNMj2FRqjFLXWuBjXFrouPCy2IN6XvKY/Wm0k1LZ3pepF1gJKcCaBsFfDZBOSc5XXJpH yKFeVghWEp7QJw3Aj8awJ5DqfHt5nnCCWySxjzWR22asca85ZPumHdSOjqlR5eEOTGiC XlLLcextVD4K+KGM0Yg0U7wtOa6XtT60CJPd47n3/cPx7JIjY8U5H313FH8ZMS9nIMgi ZXBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bjqDFAom; 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 b13si4155329edz.29.2020.05.10.21.55.39; Sun, 10 May 2020 21:56:09 -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=bjqDFAom; 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 S1729096AbgEKExw (ORCPT + 99 others); Mon, 11 May 2020 00:53:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728989AbgEKExu (ORCPT ); Mon, 11 May 2020 00:53:50 -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 BE9442184D; Mon, 11 May 2020 04:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172829; bh=Uf/dQt3pOb42ZMkyeOF+KZniQCmaCDN+4LcrOHEj2qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjqDFAomX2xBIvyoY7/YfoUgsg8v2Towsjn+NYNS9GZ1Df8x8h8UdLLVfy6Rw2Ep7 ynGlmrSuaGJaa4py+Gtcgmhkb/vY0vzUGkYNW+iP6+dJkbh/Jn2DVtLSaNEZfDBXei qdKGWNHviFQB0cb3hOD7/S2l8xbck2ZJApfASBV8= 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 17/18] x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2 Date: Mon, 11 May 2020 00:53:10 -0400 Message-Id: <20200511045311.4785-18-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 The kernel needs to explicitly enable FSGSBASE. So, the application needs to know if it can safely use these instructions. Just looking at the CPUID bit is not enough because it may be running in a kernel that does not enable the instructions. One way for the application would be to just try and catch the SIGILL. But that is difficult to do in libraries which may not want to overwrite the signal handlers of the main application. Enumerate the enabled FSGSBASE capability in bit 1 of AT_HWCAP2 in the ELF aux vector. AT_HWCAP2 is already used by PPC for similar purposes. The application can access it open coded or by using the getauxval() function in newer versions of glibc. Signed-off-by: Andi Kleen Signed-off-by: Chang S. Bae Signed-off-by: Sasha Levin Reviewed-by: Tony Luck Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen --- arch/x86/include/uapi/asm/hwcap2.h | 3 +++ arch/x86/kernel/cpu/common.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/uapi/asm/hwcap2.h b/arch/x86/include/uapi/asm/hwcap2.h index 8b2effe6efb82..5fdfcb47000f9 100644 --- a/arch/x86/include/uapi/asm/hwcap2.h +++ b/arch/x86/include/uapi/asm/hwcap2.h @@ -5,4 +5,7 @@ /* MONITOR/MWAIT enabled in Ring 3 */ #define HWCAP2_RING3MWAIT (1 << 0) +/* Kernel allows FSGSBASE instructions available in Ring 3 */ +#define HWCAP2_FSGSBASE BIT(1) + #endif diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 0d480cbadc7dc..b5a086ea34258 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1495,8 +1495,10 @@ static void identify_cpu(struct cpuinfo_x86 *c) setup_umip(c); /* Enable FSGSBASE instructions if available. */ - if (cpu_has(c, X86_FEATURE_FSGSBASE)) + if (cpu_has(c, X86_FEATURE_FSGSBASE)) { cr4_set_bits(X86_CR4_FSGSBASE); + elf_hwcap2 |= HWCAP2_FSGSBASE; + } /* * The vendor-specific functions might have changed features. -- 2.20.1