Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp151515ima; Thu, 25 Oct 2018 17:26:13 -0700 (PDT) X-Google-Smtp-Source: AJdET5eXn9uFfeIZQ6xzSaspP8fRC2vSYD6n1SKTLtPylmePyAc2sjbjZDKccTuNI90k3pr+ZbHv X-Received: by 2002:a62:4681:: with SMTP id o1-v6mr1385689pfi.108.1540513573166; Thu, 25 Oct 2018 17:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540513573; cv=none; d=google.com; s=arc-20160816; b=qAkICnYJQWN+Qr1imBFMbsQsTlg4weeWJkfBT3VTxuMHvxt8N+YRbZyrM8/s28ZgZb sumWIaxE2rKDzFpHCYAOUpgpswwwo6rt+gwVFbsWhCw1ZXKVTNkO0Nk8ILd2mxMHXLyO vR5AeF53jmLXHJBBlr9oMJ1MmLS5RscCCSQoVIY817/LbS1K6bI+Jz0xMhpzOOq0BJKs VgJO6xFshwYUZNa4f9d+xPCkuZC3KdRjlhJ1BklzgibEzJ/c5NAA1ntseEbWrod9DkMm dFRhlK7UlQg9cGCxWj2D1scKjtd33YkQndpLTU4MJOxfcY6xf8iOhAZmwjOmTgwxk6BZ 84FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=E9RG4yVLkXlxjeSursAWmKQ0o5hzl4vy/XE1sxikRis=; b=EILcFcN5rwChn1MDtqRMVizZuIDllNpWaEwdPxrZuSJHt3bGC0hxRYEHWJn4ilN1Nq WpoqjG/umP6vMPbb5Guu7CtI2Fso6knnYA4gsGka8DZIjh2RL5Fh5VIku03gwQQJ4tOI VHBcqSuw/OA+8dF7zHx25YZcMibS8Wonl3bvQUMp5wjtjz8ryZvpmrnZ1cSUkHCU9a9v 8CtcHYrUDWCqteFhhvGwFPBG3rAyq6oGAEs3cfb0mv6srLSfhzBIQNpmys5m6Q4c5iOd kY7lmKfV6hrG1agW9R4m+qZOOTMNQrZwQIhSCh7xLfRTAFNmpqA4ZsQbzWmem9B+jIpS clIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QCOH9RGT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5-v6si9818365pgg.105.2018.10.25.17.25.55; Thu, 25 Oct 2018 17:26:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=QCOH9RGT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726028AbeJZJAT (ORCPT + 99 others); Fri, 26 Oct 2018 05:00:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:37364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725849AbeJZJAT (ORCPT ); Fri, 26 Oct 2018 05:00:19 -0400 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 5F71520856 for ; Fri, 26 Oct 2018 00:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540513531; bh=cRoT0wIbJUFXnXOn5R/x9mJBTNcYLM/+Yo+8yKhGZSg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QCOH9RGThf+yA4SIDis2hW2zMw66ObxsNg30dTjRjuJfDzVjL6E805H1MuPISDUxm Bet6Z+JmEjaE062TI39ZvlnPwZXE3gcnSGyC/L2zDrL7Zi6eNBN7wKWnEnbS0oF3j6 hL0NfmfY4laiWt8WHagvYMlKvJXnHiAYg/GVzNCE= Received: by mail-wr1-f44.google.com with SMTP id w5-v6so11076633wrt.2 for ; Thu, 25 Oct 2018 17:25:31 -0700 (PDT) X-Gm-Message-State: AGRZ1gL2XaPalr1au0YxopL5VpTNYe36Axab92r4QVXr+FF2ZYNio4Hy KYlx78k0owSHFKDCglfN+GTUkeiNW5+jmfRluJ4pWg== X-Received: by 2002:adf:97d3:: with SMTP id t19-v6mr3921127wrb.283.1540513529521; Thu, 25 Oct 2018 17:25:29 -0700 (PDT) MIME-Version: 1.0 References: <20181023184234.14025-1-chang.seok.bae@intel.com> <20181023184234.14025-8-chang.seok.bae@intel.com> In-Reply-To: <20181023184234.14025-8-chang.seok.bae@intel.com> From: Andy Lutomirski Date: Thu, 25 Oct 2018 17:25:17 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [v3 07/12] x86/fsgsbase/64: Introduce the new FIND_PERCPU_BASE macro To: "Bae, Chang Seok" , Nadav Amit Cc: Ingo Molnar , Thomas Gleixner , Andrew Lutomirski , "H. Peter Anvin" , Andi Kleen , Dave Hansen , "Metzger, Markus T" , "Ravi V. Shankar" , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 23, 2018 at 11:43 AM Chang S. Bae wrote: > > 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: Andi Kleen > Cc: Andy Lutomirski > Cc: Dave Hansen > Cc: Thomas Gleixner > Cc: Ingo Molnar > --- > arch/x86/include/asm/fsgsbase.h | 52 +++++++++++++++++++++++++++++++++ > arch/x86/include/asm/inst.h | 15 ++++++++++ > 2 files changed, 67 insertions(+) > > diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h > index e500d771155f..0c2d7d8a8c01 100644 > --- a/arch/x86/include/asm/fsgsbase.h > +++ b/arch/x86/include/asm/fsgsbase.h > @@ -111,6 +111,58 @@ extern void x86_gsbase_write_cpu_inactive(unsigned long gsbase); > MODRM 0xd0 wrgsbase_opd 1 > .endm > > +#if CONFIG_SMP > + > +/* > + * 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_RDPID reg:req > + /* > + * The CPU/node NR is initialized earlier, directly in cpu_init(). P > + */ > + RDPID \reg I would suggest that you instead add a macro LOAD_CPU_AND_NODE \reg and have that macro contain the alternative. It can switch between RDPID and LSL. This way you avoid duplicating the rest of it. This should end up in the same header as __getcpu() -- it probably makes sense to just move __getcpu() for this purpose. Also, hpa and Nadav, shouldn't asm/inst.h end up in macros.S? --Andy