Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp909528ima; Fri, 1 Feb 2019 12:58:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN4C7ofFD/tnEEtnEKTAFjjojqItlGY9zcxC+rmYPruwjdwjg1caMBeWlrsZ7zXoXfKhmPhB X-Received: by 2002:a17:902:8a8a:: with SMTP id p10mr41722771plo.50.1549054700422; Fri, 01 Feb 2019 12:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549054700; cv=none; d=google.com; s=arc-20160816; b=qAWKoGtxO64REi/uM75OJ2nexlaMH/PU6hmE2XcA17hrdho5dkQiP1ygBYabMv4/RQ I59qJqeDERFoGJOJqH8U94yFS2exTut45P/xiXMJnh4SibLDXLDtJ+gQUvvnn72AFp6O zX0fyuMQbomEQoQVwjBy2w8TcEz8UgiRflnvODLWV3d9yd40MUZN5Swe1Gr/ynh3hXIk PSIYWmt++qrELNrPeFvbSba2U80hs3OGEGwD71FUVYLovvqdhDc7tx6VIm2fRGhXMw/i 4dZ2M3B2pMD4/pHnVghx02/5b59WMexypIdoZzolae2Tbk7YC5EZPg7OjtAPUEeu65jS SI6Q== 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; bh=l3l402pT0xtEx8eUGjjrButHXiHNcEfLZkFdEP0oZTg=; b=Z+qa0Kwy8C6TqkBDR+CFr3pbZeeaS+JjdSGdNvavQ2khgOhJ+IAfbldAsnpKloTnTX GXdyJQ+BaQnYvV+jctj3NWWx2O1OwmHif+FeD8WTL4P23ybtoTOAq2NAVY2uvj6CyuMB 325OwuweNLHEGoeT5CBmRKgXAJsSFnHTaPwOI2kpcFcT0w2fxWi9jOj5qAbZnUCFcRzK YLNJZ8rtHrL92szL3QXMnBxBBlzoOELyhZkVjFO5M2v3uuG4TxYXu9UAcZkr5L8D/6db 43Q/SUO6YKCrQoV/9O/IP4NyoLBDILmj6WVU0OCTxwS5wFZET+QEuIvrQnqSmP03fkXy 0gzQ== 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 n184si3914371pgn.95.2019.02.01.12.58.04; Fri, 01 Feb 2019 12:58:20 -0800 (PST) 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 S1730505AbfBAUzC (ORCPT + 99 others); Fri, 1 Feb 2019 15:55:02 -0500 Received: from mga07.intel.com ([134.134.136.100]:49748 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730023AbfBAUzA (ORCPT ); Fri, 1 Feb 2019 15:55:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2019 12:54:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,549,1539673200"; d="scan'208";a="140866371" Received: from chang-linux-2.sc.intel.com ([10.3.52.165]) by fmsmga004.fm.intel.com with ESMTP; 01 Feb 2019 12:54:59 -0800 From: "Chang S. Bae" To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andi Kleen Cc: Markus T Metzger , Ravi Shankar , "Chang S . Bae" , LKML , Dave Hansen Subject: [PATCH v5 08/13] x86/fsgsbase/64: Introduce the FIND_PERCPU_BASE macro Date: Fri, 1 Feb 2019 12:53:14 -0800 Message-Id: <20190201205319.15995-10-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190201205319.15995-1-chang.seok.bae@intel.com> References: <20190201205319.15995-1-chang.seok.bae@intel.com> 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 GSBASE is used to find per-CPU data in the kernel. But when it 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. Also, add the GAS-compatible RDPID macro. The new macro will be used on a following patch. Suggested-by: H. Peter Anvin Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Dave Hansen Cc: Andi Kleen --- arch/x86/include/asm/fsgsbase.h | 46 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/inst.h | 15 +++++++++++ 2 files changed, 61 insertions(+) diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h index aefd53767a5d..eecca2250748 100644 --- a/arch/x86/include/asm/fsgsbase.h +++ b/arch/x86/include/asm/fsgsbase.h @@ -78,6 +78,52 @@ extern void x86_gsbase_write_cpu_inactive(unsigned long gsbase); #endif /* CONFIG_X86_64 */ +#else /* __ASSEMBLY__ */ + +#ifdef CONFIG_X86_64 + +#include + +#if 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 GSBASE 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 FIND_PERCPU_BASE reg:req + /* + * The CPU/node NR is initialized earlier, directly in cpu_init(). + * The CPU NR is extracted from it. + */ + 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 FIND_PERCPU_BASE reg:req + /* Tracking the base offset value */ + movq pcpu_unit_offsets(%rip), \reg +.endm + +#endif /* CONFIG_SMP */ + +#endif /* CONFIG_X86_64 */ + #endif /* __ASSEMBLY__ */ #endif /* _ASM_FSGSBASE_H */ diff --git a/arch/x86/include/asm/inst.h b/arch/x86/include/asm/inst.h index f5a796da07f8..d063841a17e3 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.19.1