Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3207760pxb; Sun, 26 Sep 2021 08:15:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzbRoXaE89iMknQjdIFSgj345uZRKo9cx3RNzYIwyZGUIk7WAXE20z0I1usabPp4srumI2 X-Received: by 2002:a17:906:72d0:: with SMTP id m16mr22777264ejl.282.1632669347846; Sun, 26 Sep 2021 08:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632669347; cv=none; d=google.com; s=arc-20160816; b=R2Z+PJTjRzqHd0bPcwBkFu8CQkbXbs7ysLYXULSw7PeSa24hXbgQivryNP6ameLheL bBMNNq0Mi29rwFALRollKEL4TbTABBkEiHL5Clmo01+YLyXbF6INJuYzqOl108AqkLVQ QDcfsDJ+gzTyzdGLrK4mbcJBb5uF18nSV/50W3PAn/k2F7AFCzyURp1snIxIaChVthw7 Ao8BEwJwLprNFFnK9eUpYDki9szI7SelBVo67BQ0AmZ6liY9qey1iW5AlrlGEo09K7WJ 6d+gW7ng0GjMQJwk37XSAdSx4hDotyE57mVmZMWCgbyW6IQWB6gSNJbDzYP9qe9Hf9mt VLCw== 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=YCyxXp6YhEkTYhQl4V4f1d1n0+TejnqWneDkxQhc6BY=; b=dHrgk/z0bcetd8oNLbvUwszBEggwHPERlPZaD4fJ+I51XpD8XAGRQ6CKxHc4IcIp6G 7/oA1cTkgkI5tRLhqmaLdffPBT1VTxFK+MHVTP6P/ymzXiegpQ8g96hRCD/jML2ad5R7 LuECYBy/h/4iDPhbg9nKMqKnXoIfQN8jsbk9y0ljkmQwlxPfFx9fj7UYYPmR+fgo0QYk 5mbNbACfb4Cunx9yQddmbUT7kESDCLB7IPH43/FjiPkTkZkf7GkmBK9yO71zGQKKbZk0 /BPm1BBmQfgleOO70INTnA+HGcBeGdb9EN3LH9EQaE8RSlXI4gOmH6AKMXFrxGjBs8rK wcKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DY1HfLro; 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 i21si16533199ejo.253.2021.09.26.08.15.23; Sun, 26 Sep 2021 08:15:47 -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=DY1HfLro; 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 S232210AbhIZPNH (ORCPT + 99 others); Sun, 26 Sep 2021 11:13:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbhIZPMl (ORCPT ); Sun, 26 Sep 2021 11:12:41 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B778BC061714 for ; Sun, 26 Sep 2021 08:11:04 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id w8so15302630pgf.5 for ; Sun, 26 Sep 2021 08:11:04 -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=YCyxXp6YhEkTYhQl4V4f1d1n0+TejnqWneDkxQhc6BY=; b=DY1HfLro95ZdGJZAGx80gMhkpt4zBcVnWSBKF/r9oEWeCSUsam4V+Cp8ZZATkwxwgB MBJm32uQXy9+2SMtKNk/QvGbStsPg8ByoQhi0PlJne+Qihn/tTakoNHD3nyVi+TyRxk5 Kdx7qDPzZLayVOjR1cB3MTL8jvQrT3TcqVIdalcuOgvrtpoa7INv2q6gSiFt/yRx7j58 h+R2QkFCHzM6W4j+l1anYKPpob5GqdbcFwgydrEnYk0fZHNcmQUQXMHvqUXXpV81Ylg8 661tSifYkhWiGcAHcc/BF858J8bnCblf/W9Ikw4Gh3WsRSpWl26YKo5VU71NkeyK+plm eXnw== 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=YCyxXp6YhEkTYhQl4V4f1d1n0+TejnqWneDkxQhc6BY=; b=CLWQVVFD5cStjerfCZTMVh/mxMD2c7DKxpKizra363F4ZP514xRNpv14omfng1I5Hg XosyXeVgQL93+VaegRsueAO/11+y9vEoOSQg5KAX1CpKZqLXrorXsB0y599hRgg5DnqD 0xp71kpqTZDRofNnoUjEkz5OtcGvny7cTJ8okrnb/bypIEopSPFjT165anftRV5W+Ifz WTr+UIGzZNrzNeonhOEUOTVyuUiTuRUpXFTVFakcgzqi5D8G31g1WnWGPh6fr1ce/cLG HxbLiIkoH8/BbzywbdOWAqWcFE8mk0P7vagkURHthpv/CgWBdrV4u7JoTQR4V8Tw/mSj s/yg== X-Gm-Message-State: AOAM53122Uip6BH2hkVUjC8vrVX0tfCg+sIY8QDFjcUR/sf6q7YEz6QB 44A4Yaa+erWLdHP1amqRiHFI/PA1bz4LMQ== X-Received: by 2002:aa7:8609:0:b0:44b:346a:7404 with SMTP id p9-20020aa78609000000b0044b346a7404mr19135700pfn.86.1632669064086; Sun, 26 Sep 2021 08:11:04 -0700 (PDT) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id m186sm12588914pfb.165.2021.09.26.08.11.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Sep 2021 08:11:03 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH V2 22/41] x86/entry: Add the C version get_percpu_base() Date: Sun, 26 Sep 2021 23:08:19 +0800 Message-Id: <20210926150838.197719-23-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20210926150838.197719-1-jiangshanlai@gmail.com> References: <20210926150838.197719-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 2db9ae3508f1..b939b56d985d 100644 --- a/arch/x86/entry/entry64.c +++ b/arch/x86/entry/entry64.c @@ -193,3 +193,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