Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1337092imm; Wed, 20 Jun 2018 16:17:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIK1r4ZvKpHlwc1TWKhtVl6y11KteHnyAVWqNxnL0aKKRdWKayDDMoZEdjWmL4+qWJLE2hX X-Received: by 2002:a17:902:74cc:: with SMTP id f12-v6mr25997354plt.7.1529536643250; Wed, 20 Jun 2018 16:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529536643; cv=none; d=google.com; s=arc-20160816; b=UPGH+TqC2FmBJnQHJ0HNMwZOJZyR5InIE+ghxU/IAFRmA8LK2n8Zc5+14fAABy8Mti vcPjDFukZwbmtoQVRu0gjFB3aiHdBcijDtQ/aZZrHpGClG5euzo0UlcfrzB1tY3lNsby OoH6alzRokzWFMObsol0+0z5K5QgIm/kXJdcf5+mEq0cU1+vtZo2h9xkRmVsNZK4/mhc TlUC/rtOFtOSectmMV+uUxSDAtkmSQ96YGqdvQ4WcPr+XGpc5OjaAuNdNQzcFqAaKeT7 A9Lfku98d5+tCvV1HTK754TJOK3IHHxlyu0YNUHj+MKUI1+QX65kjjMATFx+ox9mPUer taCw== 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:arc-authentication-results; bh=mHpKCU2iIktkvlGRV54C97aNxlXdOr0VlLhHtT5saDk=; b=hcY9Pes8cpnbiLVWqHQJzzkNMjX6YiYCc5Cc0HS3ta5GrFaf0MeyZhalDnKeBw0G7R wS2GyLKy9cgje3FEP0ysjITp+wpueLWMtdn8oikMoA8ewIQ3i0Zw704lN/Tffa9hMvPQ v28RystsDHV1/GqHd1VoMy2tDCDS/fkFc3HMeZEg6XxBTN3j+mhpiRJQv8s3LDFByjp3 9bYfbJFUjzTKYXogqtdFLUqZ/z19bKFrE02XCKTi7W4JNBBNZHG++J3v/gqqfJCkQr2m 8bwBizVipd4gFF/mePR/KslCCR4+LQe4Dkpb2tFEmhjrrmF52eLb1fbDwIeS2QfMItJJ Hk/A== 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 w11-v6si2771872pgp.140.2018.06.20.16.17.09; Wed, 20 Jun 2018 16:17:23 -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 S932735AbeFTXQI (ORCPT + 99 others); Wed, 20 Jun 2018 19:16:08 -0400 Received: from mga12.intel.com ([192.55.52.136]:65395 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932241AbeFTXP2 (ORCPT ); Wed, 20 Jun 2018 19:15:28 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 16:15:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,249,1526367600"; d="scan'208";a="66325227" Received: from chang-linux-2.sc.intel.com ([10.3.52.139]) by orsmga001.jf.intel.com with ESMTP; 20 Jun 2018 16:15:27 -0700 From: "Chang S. Bae" To: Andy Lutomirski , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar Cc: Andi Kleen , Dave Hansen , Markus T Metzger , Ravi Shankar , "Chang S . Bae" , LKML Subject: [PATCH v4 6/7] x86/vdso: Introduce CPU number helper functions Date: Wed, 20 Jun 2018 16:15:05 -0700 Message-Id: <1529536506-26237-7-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529536506-26237-1-git-send-email-chang.seok.bae@intel.com> References: <1529536506-26237-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 CPU number initialization in vDSO is now a bit cleaned up by the new helper functions. The helper functions will take care of combing CPU and node number and reading each from the combined value. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: H. Peter Anvin Cc: Andi Kleen Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Acked-by: Andy Lutomirski --- arch/x86/entry/vdso/vgetcpu.c | 4 ++-- arch/x86/entry/vdso/vma.c | 16 ++++++++-------- arch/x86/include/asm/segment.h | 28 ++++++++++++++++++++++++++++ arch/x86/include/asm/vgtod.h | 2 -- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/arch/x86/entry/vdso/vgetcpu.c b/arch/x86/entry/vdso/vgetcpu.c index 8ec3d1f..3284069 100644 --- a/arch/x86/entry/vdso/vgetcpu.c +++ b/arch/x86/entry/vdso/vgetcpu.c @@ -18,9 +18,9 @@ __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused) p = __getcpu(); if (cpu) - *cpu = p & VGETCPU_CPU_MASK; + *cpu = lsl_tscp_to_cpu(p); if (node) - *node = p >> 12; + *node = lsl_tscp_to_node(p); return 0; } diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 833e229..1fc93da 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -340,19 +340,19 @@ static void vgetcpu_cpu_init(void *arg) int cpu = smp_processor_id(); struct desc_struct d = { }; unsigned long node = 0; + unsigned long cpu_number = 0; #ifdef CONFIG_NUMA node = cpu_to_node(cpu); #endif + cpu_number = make_lsl_tscp(cpu, node); + if (static_cpu_has(X86_FEATURE_RDTSCP)) - write_rdtscp_aux((node << 12) | cpu); + write_rdtscp_aux(cpu_number); + + /* Store cpu number in limit */ + d.limit0 = cpu_number; + d.limit1 = cpu_number >> 16; - /* - * Store cpu number in limit so that it can be loaded - * quickly in user space in vgetcpu. (12 bits for the CPU - * and 8 bits for the node) - */ - d.limit0 = cpu | ((node & 0xf) << 12); - d.limit1 = node >> 4; d.type = 5; /* RO data, expand down, accessed */ d.dpl = 3; /* Visible to user code */ d.s = 1; /* Not a system segment */ diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index e3e788ea..18fec9e 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -224,6 +224,34 @@ #define GDT_ENTRY_TLS_ENTRIES 3 #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8) +#ifdef CONFIG_X86_64 + +/* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */ +#define LSL_TSCP_CPU_SIZE 12 +#define LSL_TSCP_CPU_MASK 0xfff + +#ifndef __ASSEMBLY__ + +/* Helper functions to store/load CPU and node numbers */ + +static inline unsigned long make_lsl_tscp(int cpu, unsigned long node) +{ + return ((node << LSL_TSCP_CPU_SIZE) | cpu); +} + +static inline unsigned int lsl_tscp_to_cpu(unsigned long x) +{ + return (x & LSL_TSCP_CPU_MASK); +} + +static inline unsigned int lsl_tscp_to_node(unsigned long x) +{ + return (x >> LSL_TSCP_CPU_SIZE); +} + +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_X86_64 */ + #ifdef __KERNEL__ /* diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h index 9cd9036..24e69b3 100644 --- a/arch/x86/include/asm/vgtod.h +++ b/arch/x86/include/asm/vgtod.h @@ -79,8 +79,6 @@ static inline void gtod_write_end(struct vsyscall_gtod_data *s) #ifdef CONFIG_X86_64 -#define VGETCPU_CPU_MASK 0xfff - static inline unsigned int __getcpu(void) { unsigned int p; -- 2.7.4