Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1575952ybk; Sun, 10 May 2020 21:57:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIdSyzFrbOjL3RwaiWBtd8hleVugaNBlWQc9bMxYHx5/U/J1mHiE+9Eg0S1z3Cw8BfNjruy X-Received: by 2002:aa7:ca48:: with SMTP id j8mr11257630edt.328.1589173068202; Sun, 10 May 2020 21:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173068; cv=none; d=google.com; s=arc-20160816; b=nev5P1IC0LEtCvLlIE2bbRqLNrFfAL7TbIKPoaAiQ4i0fVtZWdyVd6ScUPq4N+Bdfn LC3W8pd9Ji/TmsH4jXKkgMHHV2kp6rBsP5aIti768Z3QfM+z3phnFx6YG1j7adddDi1n 8Cb9dkqzeA1Jg/OkgmUyTIQD0Wezgj3i5LdnRLJB6gdHdcVlWccnpjxRWza019/x6KtT AK0txw8iuDF6CRHVyzx641hteRpdZXzX2S/KddK1z4vtdd+fIFWBbtYHxOf2OoGQrIrM 5RaO0lfcv9uTEPYWILjQa+1DTJYSEvA+3/lz8zjUoD1SgHuD35ZNrcE7oLshO83hyoTG da8Q== 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=X4VD8G0zFCh4OxrInRAzQcy+366zv+h5fvFs9xYQUR4=; b=hkJ8kcBvJOUwloph899+5HLbibC4/hDx4loDrbimVrH3vwpwO5odfrOGNSyat86EiP mI3qwuycmLzuVub+L5hN+zygtszRy3dKgQDrFhHI02Nirnkd70cymotnRpyED8FUAfXq H+kpdw3dS3W3F+4sx4XWRPkSQImg+G2qrgT4A0dmWOxoakHe3tmranKw33MhP7LBD6Xk 1l/AM6fDd4cE5bn6klwGPSF8PhLHyiLbJf8u6h2xQsKRMNt96J5Tn8UrYEyYBpBuRV51 yg2U2F8gZuepbt1iCU9auhOSPCZyTElcVdZLQHOaXhCgdQJYP/kIcMXsoV5SFoHYBy0T iRJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N1Uy9h5N; 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 f4si5104169ejd.83.2020.05.10.21.57.20; Sun, 10 May 2020 21:57: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=N1Uy9h5N; 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 S1729305AbgEKEyS (ORCPT + 99 others); Mon, 11 May 2020 00:54:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:37410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbgEKExg (ORCPT ); Mon, 11 May 2020 00:53:36 -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 03C932137B; Mon, 11 May 2020 04:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172815; bh=rebr4oJHqsxfoTg+DmxLtFUh8gQKAx9aHBZRwmZGkKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N1Uy9h5NaBaUzQXXknoEdOT8zV1nTTApivFjb7l1RIyLQsW1kCfzhqVhkS5XWCOo6 CiFkUQFTwdnQBGhxtdTwWZrhM4HZHNp44oW7eucV6OZos6zb3XIDu9rFivSKIZly3U a1tPqOEaTCWdy5U/G15Zbq3/ojK9gprJ6t51+4qY= 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 v12 06/18] x86/entry/64: Introduce the FIND_PERCPU_BASE macro Date: Mon, 11 May 2020 00:52:59 -0400 Message-Id: <20200511045311.4785-7-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: "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 1c7f13bb67286..29982fe140541 100644 --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -6,6 +6,7 @@ #include #include #include +#include /* @@ -349,6 +350,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