Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4089462pxb; Wed, 13 Oct 2021 20:43:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd8GvWUmL+wFXI00V9sftkFkn4ie5HuROJ9Rm8wBEQOcD041ElxWOSkwO5RFGAQV8hHnET X-Received: by 2002:a17:90a:be02:: with SMTP id a2mr3696168pjs.59.1634183029519; Wed, 13 Oct 2021 20:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634183029; cv=none; d=google.com; s=arc-20160816; b=fSzpe2YDiqOyESNruJNKjb5eFXvKiqRYG09+Foh7Zd7hxb0/u+tsMyqOqN236mg64z F8bm4Ww0NompIMfjp0vsm7jePYl969I3paCpNLf/fgdLPZMHD6F8uk4nDDCaPtL2dNXE +kNHA6+jgKb2d19xp4xJxaiuMOPHqss0mlD+EQ/sc6I6045C57saNGAmKlVFLqDhBufC LOwn1ncy8ew3LNaoIcCiOnuI2p4NNEXaN9VR8uy4doPgQ2daujX3QmIJ/Hfs8vRHvhRq X8LwZ+1hBc9BynZnb8rjSVd0NEsUTDY34UBQYMSV/d+5Tq9NCYsg8PbrbTc9KnnwXe9M dPXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PaS3e6HPf4uIDioaRz2iYDZJ5aCgKi5pCRpWThtL0F4=; b=XFslcqKEIOz+q+hbP62RfvaaxPXqhoQS36GIHsahxHSOy6v9nQH2tcag23MdMMuUnt +f9mqUm5CneUlmk0e1eXFdgvwhZrjzNR1+Ut2yUGl9yFy1qXtDQuENdY2ypEcK4sM0ET EZt4iZSktTLZGMHNfMBYppbcKBrwnLT6FmzDkNmRJaDK2P52BEOrEMY+JbOSn338WwDV 825hFgoja2hqqmd1nCd5juMIL3FVqDdjBW9MgCiqVgnb4X3bLP9qymaG8umnth8UjSx6 8g//xr2vg4Dxxzs82axMZFQ3OLJwqkvpBFPWOtu4czLLWB7aoFC6VaWai50D9n4cnv2O bhVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eU1ZK7jM; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z130si2101790pgz.341.2021.10.13.20.43.36; Wed, 13 Oct 2021 20:43:49 -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=@gmail.com header.s=20210112 header.b=eU1ZK7jM; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbhJNDok (ORCPT + 99 others); Wed, 13 Oct 2021 23:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbhJNDnz (ORCPT ); Wed, 13 Oct 2021 23:43:55 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77692C061746 for ; Wed, 13 Oct 2021 20:41:28 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id 187so4265053pfc.10 for ; Wed, 13 Oct 2021 20:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PaS3e6HPf4uIDioaRz2iYDZJ5aCgKi5pCRpWThtL0F4=; b=eU1ZK7jMIezGEditoBhQYEsh65Q0C4BWQDSRE8cuTD7TZ1mciisyK1FTk1WMEcEUgJ Bqj9PVG9niuwr+VZhqeGf1sdbk3fIVkxabamMXDRsLnlTRtWPGvu8O7Zf+bjjOqMs0/E i5oCig8c29oQFmPchRq/HnHCN7pIXD8aIf8+xucjwpRFg6BIVERbLJMGveDidXmuMLXl FhgAt6gj3nHyBmSqUm+AIwU1AB0UYyfnDjb6u6rULTZxf/Nqu784XxOQv2/tSgrpFmX0 DRpt2FV9VXM+/upoE11b0Z4tyrhkjWcgbHFBUDuiFjjQYPdfD1+bqhznaTEtj/Ms09IG cQ4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PaS3e6HPf4uIDioaRz2iYDZJ5aCgKi5pCRpWThtL0F4=; b=4Krh7sPTp5r6BEq90q/GLHUU9TvcphplV+PQk6U1wSyGOdu5oMqxn16FcdyDIHfGYw UOmNZiCU2vXPOJFZpuEevVU2jUhcx28M4o5omAL24/gzoGCQXD+rWG+2qD/QZzuzH5gO nsgmkR7OmEXM9FOGCdlvrWYpuyF/HYSU/5AoFHiLAWNK/K+Q8rDP2pYYSrKS2VdasOpt 4H8xfO6GKtYSKISI4asK8YN3vNd4G+fomY9bRG6OYv9YH96fu+QrHDyHS8EfEwq9k82a 3E9PzlGLf6/ggQ2AttPuFW1CSVavf+URcJr+K/XpUZPdlXvF9PZRKPSsHaJcPfqDmQP/ 6mwA== X-Gm-Message-State: AOAM533gG5pvAQpuBvd2EXV69nd3dXL9RNWHJpW9XAqBmV735bcLnMxf 5lWQcS7Oslgqvi+7t/GbT4ZStuYoUCc= X-Received: by 2002:a62:e90d:0:b0:44d:35a1:e5a0 with SMTP id j13-20020a62e90d000000b0044d35a1e5a0mr3210645pfh.54.1634182887896; Wed, 13 Oct 2021 20:41:27 -0700 (PDT) Received: from localhost ([198.11.178.15]) by smtp.gmail.com with ESMTPSA id i124sm867959pfc.153.2021.10.13.20.41.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Oct 2021 20:41:27 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH V3 33/49] x86/entry: Add the C version get_percpu_base() Date: Thu, 14 Oct 2021 11:41:05 +0800 Message-Id: <20211014034121.17025-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211014031413.14471-1-jiangshanlai@gmail.com> References: <20211014031413.14471-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan It implements the C version of asm macro GET_PERCPU_BASE(). Not functional difference intended. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry64.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/x86/entry/entry64.c b/arch/x86/entry/entry64.c index 5edbb4bb4786..48fd3199f00b 100644 --- a/arch/x86/entry/entry64.c +++ b/arch/x86/entry/entry64.c @@ -201,3 +201,39 @@ struct pt_regs *error_entry(struct pt_regs *eregs) /* Enter from kernel, don't move pt_regs */ return eregs; } + +#ifdef CONFIG_SMP +/* + * CPU/node NR is loaded from the limit (size) field of a special segment + * descriptor entry in GDT. + * + * Do not use RDPID, because KVM loads guest's TSC_AUX on vm-entry and + * may not restore the host's value until the CPU returns to userspace. + * Thus the kernel would consume a guest's TSC_AUX if an NMI arrives + * while running KVM's run loop. + */ +static __always_inline unsigned int gdt_get_cpu(void) +{ + unsigned int p; + + asm ("lsl %[seg],%[p]" : [p] "=a" (p) : [seg] "r" (__CPUNODE_SEG)); + + return p & VDSO_CPUNODE_MASK; +} + +/* + * Fetch the per-CPU GSBASE value for this processor. + * + * 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. + */ +static __always_inline unsigned long get_percpu_base(void) +{ + return __per_cpu_offset[gdt_get_cpu()]; +} +#else +static __always_inline unsigned long get_percpu_base(void) +{ + return pcpu_unit_offsets; +} +#endif -- 2.19.1.6.gb485710b