Message ID | 20230112072032.35626-1-xin3.li@intel.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3749317wrt; Wed, 11 Jan 2023 23:49:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXu88/WpSTCMr0f9q+Y+JX8b3c6ALZn/Pd/VXe9xJj5shFn9H84vb5bj0ZMcBd3ZkF/tCEtA X-Received: by 2002:a05:6402:5293:b0:497:c96b:4dea with SMTP id en19-20020a056402529300b00497c96b4deamr17742069edb.5.1673509790093; Wed, 11 Jan 2023 23:49:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673509790; cv=none; d=google.com; s=arc-20160816; b=v2zFdoXMwoMjiRIyQzCDnQCSs03d6NUTaue1bpidNNRPN+doBJhVy51iwNH0tnKvIg 5WWE2+Ih0d51qkaKbnGzbukGCQD9jd8ThwxELv7CjyQjMtVace7hGPFM7sUSXBcPWOIh Em4phChJzEmP13+RgHUxSaquMn93sr3reGM3ttKSYuxqkBzRC3cBlcdOm/O4wW7e8eZ9 uyfd0FGWcIp99vChuuslHowheqTBsiE0GXzvp2Ngrbip2xJ/PCzlp99xIQGSc6q4aiLl N7JOpA5aYdaUFuZW7E4naa/2scGs2WOJOW5o2MzwOQU5gvhcpuhV890SpN8i6s8wXXhp 52Hw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=qVG8UD+wdXwJjhrS8iGNz5T5zRXl+wE3luZ+ef81wQI=; b=mPIpHwuzdnmeoqHao0UJSL+72I7fBmv3/+nNR/PnrU/dgXK98/D6AO7ca2BDj/11ON Eb519MZHj5XKlTkdzoWD6sJAg+qIS2nMCb0wlIrhEJWCQpbh6uKiEIvAmtIhb4A7AWQG uu89M+BiyYKT1C7NrTiJgQhKhpK/xWI2etOXDSiTzzutQ4i4YvMSz/RtM4wMRTuBafP6 4o1ajFHDV2wPjqFg1NPVvjGSZOeN6PzYW0IDC9oB9tumOMx6EeLmVqlI0v0qvBYjHO4K Yg7m7A0u2Ece2JSR29gZQg3EYDq4ugf+OlZFy9zHkdLJUwXPyaYA6O+vO5fo8UCwvc8Y 2B+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9S05tsi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa7d845000000b004922b9ba177si14967568eds.112.2023.01.11.23.49.25; Wed, 11 Jan 2023 23:49:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9S05tsi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238774AbjALHoY (ORCPT <rfc822;zhuangel570@gmail.com> + 99 others); Thu, 12 Jan 2023 02:44:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231469AbjALHoW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 12 Jan 2023 02:44:22 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6723E3F45B for <linux-kernel@vger.kernel.org>; Wed, 11 Jan 2023 23:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673509461; x=1705045461; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5bdLaL9GU2RwLB3Lz5X0TADw/y+Uxo5/E0WnDJifRaI=; b=S9S05tsiMu9tHCITP0SKQSN9m3gGqNCbzNMGjLglO7CLIOSlZSluebFE i7AJUjJseQ9GJWWvsiN/hLDoIrMlLDx4gHiHnOxGQ2JpMvJazbEzoH+Zn ZsqGZygyVl/jjCr+Gqf+28bU6U59FeQOB/PUIAfHIdCYhkWRJCyF+GcNN fR68FbFZEDl375ZlwOOmvH2KvcyRRCd9mO/9uXIgun8+rG+h3TtUCDFAN HO84AZ4zHwEv3H53C044eI+GAEj6v93mix9jymqayPiYQbalkSsn0wphW NcDU8NNV9MZGCNW8ApNNDj8EJsmNHh0AkkcmI8H+naid681YdS/wsa5M5 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="321328667" X-IronPort-AV: E=Sophos;i="5.96,319,1665471600"; d="scan'208";a="321328667" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 23:44:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="635283900" X-IronPort-AV: E=Sophos;i="5.96,319,1665471600"; d="scan'208";a="635283900" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga006.jf.intel.com with ESMTP; 11 Jan 2023 23:44:20 -0800 From: Xin Li <xin3.li@intel.com> To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, brgerst@gmail.com, chang.seok.bae@intel.com, jgross@suse.com Subject: [PATCH v6 0/5] x86: Enable LKGS instruction Date: Wed, 11 Jan 2023 23:20:27 -0800 Message-Id: <20230112072032.35626-1-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754802201436621457?= X-GMAIL-MSGID: =?utf-8?q?1754802201436621457?= |
Series |
x86: Enable LKGS instruction
|
|
Message
Li, Xin3
Jan. 12, 2023, 7:20 a.m. UTC
LKGS instruction is introduced with Intel FRED (flexible return and event delivery) specification. As LKGS is independent of FRED, we enable it as a standalone CPU feature. LKGS behaves like the MOV to GS instruction except that it loads the base address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment’s descriptor cache, which is exactly what Linux kernel does to load user level GS base. Thus, with LKGS, there is no need to SWAPGS away from the kernel GS base. Changes since v5: * Recommend to search for the latest FRED spec instead of providing a FRED spec URL, which is likely to be unstable (Borislav Petkov). * Remove reviewers' SOBs (Borislav Petkov). Changes since v4: * Clear the LKGS feature from Xen PV guests (Juergen Gross). Changes since v3: * We want less ASM not more, thus keep local_irq_{save,restore}() inside native_load_gs_index() (Thomas Gleixner). * For paravirt enabled kernels, initialize pv_ops.cpu.load_gs_index to native_lkgs (Thomas Gleixner). Changes since v2: * Add "" not to show "lkgs" in /proc/cpuinfo (Chang S. Bae). * Mark DI as input and output (+D) as in v1, since the exception handler modifies it (Brian Gerst). Changes since v1: * Use EX_TYPE_ZERO_REG instead of fixup code in the obsolete .fixup code section (Peter Zijlstra). * Add a comment that states the LKGS_DI macro will be replaced with "lkgs %di" once the binutils support the LKGS instruction (Peter Zijlstra). H. Peter Anvin (Intel) (5): x86/cpufeature: add the cpu feature bit for LKGS x86/opcode: add the LKGS instruction to x86-opcode-map x86/gsseg: make asm_load_gs_index() take an u16 x86/gsseg: move load_gs_index() to its own new header file x86/gsseg: use the LKGS instruction if available for load_gs_index() arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/gsseg.h | 66 ++++++++++++++++++++++++ arch/x86/include/asm/mmu_context.h | 1 + arch/x86/include/asm/special_insns.h | 21 -------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/paravirt.c | 1 + arch/x86/kernel/signal_32.c | 1 + arch/x86/kernel/tls.c | 1 + arch/x86/lib/x86-opcode-map.txt | 1 + arch/x86/xen/enlighten_pv.c | 1 + tools/arch/x86/include/asm/cpufeatures.h | 1 + tools/arch/x86/lib/x86-opcode-map.txt | 1 + 13 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 arch/x86/include/asm/gsseg.h
Comments
* Xin Li <xin3.li@intel.com> wrote: > LKGS instruction is introduced with Intel FRED (flexible return and event > delivery) specification. As LKGS is independent of FRED, we enable it as > a standalone CPU feature. > > LKGS behaves like the MOV to GS instruction except that it loads the base > address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment’s > descriptor cache, which is exactly what Linux kernel does to load user > level GS base. Thus, with LKGS, there is no need to SWAPGS away from the > kernel GS base. Ok, this looks good to me. I've applied the first 4 patches to tip:x86/cpu, as the instruction exists in a public document and these patches are fine stand-alone as well, such as the factoring out of load_gs_index() methods from a high-use low level header into a new header file. Planning to apply the final, LKGS enabler patch as well, unless there's any objections from others? Thanks, Ingo
On Thu, Jan 12, 2023 at 01:13:20PM +0100, Ingo Molnar wrote: > > * Xin Li <xin3.li@intel.com> wrote: > > > LKGS instruction is introduced with Intel FRED (flexible return and event > > delivery) specification. As LKGS is independent of FRED, we enable it as > > a standalone CPU feature. > > > > LKGS behaves like the MOV to GS instruction except that it loads the base > > address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment’s > > descriptor cache, which is exactly what Linux kernel does to load user > > level GS base. Thus, with LKGS, there is no need to SWAPGS away from the > > kernel GS base. > > Ok, this looks good to me. > > I've applied the first 4 patches to tip:x86/cpu, as the instruction exists > in a public document and these patches are fine stand-alone as well, such > as the factoring out of load_gs_index() methods from a high-use low level > header into a new header file. > > Planning to apply the final, LKGS enabler patch as well, unless there's any > objections from others? Nah, I think that thing's bike-shedded to near death. Let's just do it.
* Peter Zijlstra <peterz@infradead.org> wrote: > On Thu, Jan 12, 2023 at 01:13:20PM +0100, Ingo Molnar wrote: > > > > * Xin Li <xin3.li@intel.com> wrote: > > > > > LKGS instruction is introduced with Intel FRED (flexible return and > > > event delivery) specification. As LKGS is independent of FRED, we > > > enable it as a standalone CPU feature. > > > > > > LKGS behaves like the MOV to GS instruction except that it loads the > > > base address into the IA32_KERNEL_GS_BASE MSR instead of the GS > > > segment’s descriptor cache, which is exactly what Linux kernel does > > > to load user level GS base. Thus, with LKGS, there is no need to > > > SWAPGS away from the kernel GS base. > > > > Ok, this looks good to me. > > > > I've applied the first 4 patches to tip:x86/cpu, as the instruction > > exists in a public document and these patches are fine stand-alone as > > well, such as the factoring out of load_gs_index() methods from a > > high-use low level header into a new header file. > > > > Planning to apply the final, LKGS enabler patch as well, unless there's > > any objections from others? > > Nah, I think that thing's bike-shedded to near death. Let's just do it. Ok - applied the #5 patch to tip:x86/cpu, for a v6.3 merge. Thanks, Ingo
> > > > LKGS instruction is introduced with Intel FRED (flexible return > > > > and event delivery) specification. As LKGS is independent of FRED, > > > > we enable it as a standalone CPU feature. > > > > > > > > LKGS behaves like the MOV to GS instruction except that it loads > > > > the base address into the IA32_KERNEL_GS_BASE MSR instead of the > > > > GS segment’s descriptor cache, which is exactly what Linux kernel > > > > does to load user level GS base. Thus, with LKGS, there is no > > > > need to SWAPGS away from the kernel GS base. > > > > > > Ok, this looks good to me. > > > > > > I've applied the first 4 patches to tip:x86/cpu, as the instruction > > > exists in a public document and these patches are fine stand-alone > > > as well, such as the factoring out of load_gs_index() methods from a > > > high-use low level header into a new header file. > > > > > > Planning to apply the final, LKGS enabler patch as well, unless > > > there's any objections from others? > > > > Nah, I think that thing's bike-shedded to near death. Let's just do it. > > Ok - applied the #5 patch to tip:x86/cpu, for a v6.3 merge. > > Thanks, > > Ingo Thanks a lot! Xin