Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp743313ima; Fri, 15 Mar 2019 13:08:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwn2OWCVZaX4jNW2sm5FxAT1yUqZrhjw4ACIDVIWGpbW2cn0pw5vlp4eTNQMMzzYRPFWG2p X-Received: by 2002:a65:6290:: with SMTP id f16mr5181263pgv.106.1552680483813; Fri, 15 Mar 2019 13:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552680483; cv=none; d=google.com; s=arc-20160816; b=Os+kQYniMgy61NHFSJpx9Kb9i4Lmfrxe6WBjMuffYW5HAM1wmrYX+W+giKzRqSGgtH EZIcbfWvP/hAkLKJO/FnsGAAKjd4UwDkX7yTh9rfp4FGEAg3TBjc8KbiS9Rk/4geY76K 1oCn/NFccT+J+hfmzsm80QTAZCASWMqxU04rol8Bla+jzaHWus8nfr7JyHR/URlE/KYp Ju7HiwZjlQApmiE7BPs5XmLU2gXWB6LkSo9h4eIPTYuw5YX1I6Qvsc/fcWE2PbsHfXaj YxBSIDUitgHGMNCJjFNwEcecGGRKxqcTa/MlGvAIHpoiqiE6L2E3lvi/6VNSLaSzFa2h hJJg== 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=ciKiQOCV0DQNDBatlCLmQALnCv+uApEuNkAgApY66yA=; b=CyiKZUAzdr2Ga77L+nFBYtu75CAGGzYjEJdB8hm78MxhmEIQbTdw5nlTH6fvHJD3kT iCz0bMZfDmM6rAp3OYauWOF6WnLT620gaG8wQIA880fDo7ChMJDDLukxvYqF0GxIpamf vS+qLcseMS6OCHoBs8WviYmgqiLu7heySYkGHQi/c3J9BdbhP5YCfD2z1sG2JP/8hcBd ak11SOIsPa9qwTBtIWriYCi1MtNp9OL53eDUfpbswdiRo0AgN52q44LZWmVc/dBkNsCW UBQCRApG8ghYoBRv3ny3ocN3Gos69/iRK5emBP6Q1Ug8vqUcnFAf8gwY5x0AM5ZgKF2C vrgw== 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 32si2609567ple.241.2019.03.15.13.07.48; Fri, 15 Mar 2019 13:08:03 -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 S1726780AbfCOUHH (ORCPT + 99 others); Fri, 15 Mar 2019 16:07:07 -0400 Received: from mga01.intel.com ([192.55.52.88]:22898 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbfCOUHE (ORCPT ); Fri, 15 Mar 2019 16:07:04 -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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,483,1544515200"; d="scan'208";a="307617716" Received: from chang-linux-3.sc.intel.com ([143.183.85.65]) by orsmga005.jf.intel.com with ESMTP; 15 Mar 2019 13:07:02 -0700 From: "Chang S. Bae" To: Thomas Gleixner , Ingo Molnar , Andy Lutomirski , "H . Peter Anvin" , Andi Kleen Cc: Ravi Shankar , "Chang S . Bae" , LKML , Dave Hansen Subject: [RESEND PATCH v6 07/12] x86/fsgsbase/64: Introduce the FIND_PERCPU_BASE macro Date: Fri, 15 Mar 2019 13:06:40 -0700 Message-Id: <1552680405-5265-8-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 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 | 41 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/inst.h | 15 ++++++++++++ 2 files changed, 56 insertions(+) diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h index aefd53767a5d..5e3dfbe8c1bf 100644 --- a/arch/x86/include/asm/fsgsbase.h +++ b/arch/x86/include/asm/fsgsbase.h @@ -78,6 +78,47 @@ extern void x86_gsbase_write_cpu_inactive(unsigned long gsbase); #endif /* CONFIG_X86_64 */ +#else /* __ASSEMBLY__ */ + +#ifdef CONFIG_X86_64 + +#include + +#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 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 + 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 + 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