Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp743653ima; Fri, 15 Mar 2019 13:08:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXBi628uvPtYqJ6BWaa1ixh2FhzTzBgUI3nQN9Z+QIZggHEtnEgHesJgvEDO/xTlbu3lTX X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr6231147plk.282.1552680511241; Fri, 15 Mar 2019 13:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552680511; cv=none; d=google.com; s=arc-20160816; b=UDK4VhTIMzMG7I9207iA8USCR2XRdIzdKhvumO6VU4JcehiGRUkQafRRLLhz345PTX +V1BHMULBCdbN6epVy70bWWZkr1RnTRx4hrqIzKCYWFc5ZczFSumabclrbA6NTY1VBTA G6BAOL61crrel2hfzh0X7xURJ/ttfewGVy0Lf+T31/GqihIMWJ6lEAcUSHzlNAmJh24n az1GWmCFoplvvSrBn104qQDv0D1Bbq51xYBqdHnRpJZCXETJnKmSc72DIK/5/pvqTkgM 9qtzsCC1a3C8HpjCYNVlRbOBwYGgOru4gMoVVUCO3wp4x4uKMymZkfuV1/aluxESOLY/ h9zQ== 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=4wPqEHJ/pGomHyGdIOtMbdvMHYUKC2vR4Vb+WDNVFlQ=; b=GZMCy1eZMh9dURcok2aIVGsP14qCiM/qI4ClCCkto4NWCYJX211+PWEdCfNV5eXGbg 8bW+owqO5wCTvnWvsCYPjuqJ5bb+9eNI18id72pHGKzzguat/oPrTQgesaQaD1LRcHyK ijxKPAOZBDtd528hteSydbJ2GfnxIIjGHjIJzBx+SR+h9hfipIXNIcei4gma87odkI9R /f3k8kh0Ai5JqMDVqJ+l5YhnNQpbSojCikMEaAxTuRNZEdD6Gkt1EsSnnjidi9f88sjf 6qQUB5w2MwIsNBAd7cJP142b6C32v/KMrlOpyQ2IEP7mpfjYN1yVjtjG9+/c/UHm8WtK k1WQ== 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 f59si2670618plf.158.2019.03.15.13.08.16; Fri, 15 Mar 2019 13:08:31 -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 S1726875AbfCOUHZ (ORCPT + 99 others); Fri, 15 Mar 2019 16:07:25 -0400 Received: from mga01.intel.com ([192.55.52.88]:22903 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfCOUHG (ORCPT ); Fri, 15 Mar 2019 16:07:06 -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:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,483,1544515200"; d="scan'208";a="307617736" Received: from chang-linux-3.sc.intel.com ([143.183.85.65]) by orsmga005.jf.intel.com with ESMTP; 15 Mar 2019 13:07:05 -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 11/12] x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2 Date: Fri, 15 Mar 2019 13:06:44 -0700 Message-Id: <1552680405-5265-12-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 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. So we need to provide a way for the application to discover the kernel capability. I used AT_HWCAP2 in the ELF aux vector which is already used by PPC for similar things. We define a new Linux defined bitmap returned in AT_HWCAP. Next to MONITOR/MWAIT, bit 1 is reserved for FSGSBASE capability checks. The application can then access it manually or using the getauxval() function in newer glibc. Signed-off-by: Andi Kleen Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar --- 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 6ebaae90e207..c5ce54e749f6 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 3d7d4ca1a29e..3bdac91316c9 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1369,8 +1369,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.19.1