Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp550993ybk; Sat, 9 May 2020 10:42:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLqzVLAe0NJfs7dpaZhIumR/47z5rjUVAPOZzOD3g/IuePlxtniSLExhPBUynlUVfolASeG X-Received: by 2002:aa7:c34e:: with SMTP id j14mr7052233edr.195.1589046168648; Sat, 09 May 2020 10:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589046168; cv=none; d=google.com; s=arc-20160816; b=vLyklCHSOHTZoP8nLXmJjP7kGpAHdFNgys7gcV/Ra5oFTO5eYhfFxyZMe40ZsIiUi5 x1iByIHnUGjRmVn1py/CgMDkTjvq8zMXzSEWJSXwq1Zw6r1CU1kZOY3q7ondU8z5PKuN NXgPy8xLfE/h/QvYR3oJNztbuxRzaPp176ZoMNU5WLc8ghQVjUsX+42jfIpR+P3l2xbk r7PdmGgtf5UXXZJyohr2+Uw1MVFWUfiyjvspkSBfPa2iJGf6E1nTpd+NWP22PMPTVPxe NvyiOK5RYiKQgWDWf+EoRbVQMJVWwc0AkQSnS9Wv3/Wbd4wWCLWDLFQmu4578nsYVQz5 fHRA== 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=0CtV9tFQMjkO+GFK8fxhkF7ALb7lvc6qmlVla0D94cI=; b=exMs5Xp9MsrXVSUpxchEZ5fiBn3jL4FNTRpEGAE7m65sbscyv2r2JnInejq+ZpdjoE j7VEVbtIc1IcpfG+zehEm/aVn+4a52vTZ3qUs1pzD2FGNId4yDBoV/Lbg+CETk53W/D1 CAEbdP3qUkxOTDke8ZTbTKS/UbVqBCiWuhkEf6pkUrf91ERAMVjFwwVPsDMqAFtPCgXs m6eIdFpMfyMD6rOeq85A2GP3YTMsM27z0PI2woE5oTSZD5gZOXcag9Okw80N/BMnAlmz ZPJeWLZGJ+dEw/DgJ27lzUwZpULdyGb0GropAU+Dyly75DnLASMYN3IkXKGUFwZZKDVV rTbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PemMlYkG; 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 i17si3084663ejr.440.2020.05.09.10.42.26; Sat, 09 May 2020 10:42: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=PemMlYkG; 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 S1728486AbgEIRhK (ORCPT + 99 others); Sat, 9 May 2020 13:37:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:54398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728467AbgEIRhI (ORCPT ); Sat, 9 May 2020 13:37:08 -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 1F7DB24962; Sat, 9 May 2020 17:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589045828; bh=tB7BVcfBITUUlx6zi+o4KhoQeXxzJTkUX4vgjvc8OYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PemMlYkGJTjTOZHnbzl5YG1M6gqzhM68/G7ZJ4M7zGUU9Xoj3l/sEp0RZWCa1upsA CXQHYWd8mSnA/+POmm2UsDyRo/+o0ntk+ujRbP2Cf7h7SjgdYdgmdoyR0YJ0/pDaB8 JXEQSQdi5cocTR20Aoah4T7KbohjH/LRZsBwSZz4= 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 , Vegard Nossum Subject: [PATCH v11 06/18] x86/entry/64: Introduce the FIND_PERCPU_BASE macro Date: Sat, 9 May 2020 13:36:43 -0400 Message-Id: <20200509173655.13977-7-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: "Chang S. Bae" GS base is used to find per-CPU data in the kernel. But when GS base is unknown, the per-CPU base can be found from the per_cpu_offset table with a CPU NR. The CPU NR is extracted from the limit field of the CPUNODE entry in GDT, or by the RDPID instruction. This is a prerequisite for using FSGSBASE in the low level entry code. Also, add the GAS-compatible RDPID macro as binutils 2.21 does not support it. Support is added in version 2.27. Suggested-by: H. Peter Anvin 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 Cc: Vegard Nossum --- arch/x86/entry/calling.h | 34 ++++++++++++++++++++++++++++++++++ arch/x86/include/asm/inst.h | 15 +++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h index 0789e13ece905..0eb134e18b7a9 100644 --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -6,6 +6,7 @@ #include #include #include +#include /* @@ -347,6 +348,39 @@ For 32-bit we have the following conventions - kernel is built with #endif .endm +#ifdef CONFIG_SMP + +/* + * CPU/node NR is loaded from the limit (size) field of a special segment + * descriptor entry in GDT. + */ +.macro LOAD_CPU_AND_NODE_SEG_LIMIT reg:req + movq $__CPUNODE_SEG, \reg + lsl \reg, \reg +.endm + +/* + * Fetch the per-CPU GS base value for this processor and put it in @reg. + * We normally use %gs for accessing per-CPU data, but we are setting up + * %gs here and obviously can not use %gs itself to access per-CPU data. + */ +.macro GET_PERCPU_BASE reg:req + ALTERNATIVE \ + "LOAD_CPU_AND_NODE_SEG_LIMIT \reg", \ + "RDPID \reg", \ + X86_FEATURE_RDPID + andq $VDSO_CPUNODE_MASK, \reg + movq __per_cpu_offset(, \reg, 8), \reg +.endm + +#else + +.macro GET_PERCPU_BASE reg:req + movq pcpu_unit_offsets(%rip), \reg +.endm + +#endif /* CONFIG_SMP */ + /* * This does 'call enter_from_user_mode' unless we can avoid it based on * kernel config or using the static jump infrastructure. diff --git a/arch/x86/include/asm/inst.h b/arch/x86/include/asm/inst.h index f5a796da07f88..d063841a17e39 100644 --- a/arch/x86/include/asm/inst.h +++ b/arch/x86/include/asm/inst.h @@ -306,6 +306,21 @@ .endif MODRM 0xc0 movq_r64_xmm_opd1 movq_r64_xmm_opd2 .endm + +.macro RDPID opd + REG_TYPE rdpid_opd_type \opd + .if rdpid_opd_type == REG_TYPE_R64 + R64_NUM rdpid_opd \opd + .else + R32_NUM rdpid_opd \opd + .endif + .byte 0xf3 + .if rdpid_opd > 7 + PFX_REX rdpid_opd 0 + .endif + .byte 0x0f, 0xc7 + MODRM 0xc0 rdpid_opd 0x7 +.endm #endif #endif -- 2.20.1