From patchwork Tue Dec 5 10:49:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 173973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3358657vqy; Tue, 5 Dec 2023 03:21:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFv3P3+PB3bbEuAQPfOoXEWfNumdvoawqXKcc9ZgPJO5Yg6p+gs9CF77n5taAZAudERMHT0 X-Received: by 2002:a05:6a00:22d1:b0:6ce:2731:5f6e with SMTP id f17-20020a056a0022d100b006ce27315f6emr823855pfj.45.1701775302718; Tue, 05 Dec 2023 03:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775302; cv=none; d=google.com; s=arc-20160816; b=BiNfvC1zUyq0X9TszEbkJacLSO8bytb3Rtu74+HpURZPhra/qXfvlYbY8+ogNbgFnd T/hCclNox9tTvJduYZ1AWuh+M20AbVHyuDD6WFaRWuJej7e0uNNtC4dceTtMUejQUf+u NMUCPtbfL61sPUXM90W/Jdt6nXuEy2/h1Xt1yQVUhv2o7d801VSK1Iuwi60GaNUv5HE2 Rm4jxNSU4ycKz0pC9D+JadxFGmEPJ275j2aTgyLBwc+FmUW7rAFyBLD8qko2PIA096EY xsHnSjZ2YTR4FPYLJy2JCyA3yz8ozYVfN2EZ3O2/SKG7H5ud42oj7vCIJ7RAEzGbvjH6 mNvQ== 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=d0OWnrxGYwqR7OuPMyUGlgrfhydWSb67AGNRqCjT3Ww=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=bhl9G3wCcWoDdELM3pzaN/A+vU7rDDssNR4UJYbc7wSzQsRA9XSD2gznP1c4CbzFzT Bmfz3cSNARGo9Jp/Brmj6szX1jo8/fwLh4+Q69jXMYXYVdL/2MaFQ03sNuSdx1YTxFAI IzbgIPBlJp084PoaH8m73mrCOnjE2ZaViwfZJfx5UfJAANTezH8SoTKe45JMPwKMhm8v cNxaAgHkzyBNlYZV3p1MU1NTP2j3mAwLyXEnG5cAD867cSReCMnCu34oQ/YW7BvtAW23 zmEi6HAaJUOexmnVWwtwxWfArDPHnrmsGm7oJ0eg0kSJognZFBci41ptqWjQEXhbXKZh odZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a2SsaUgB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b12-20020a056a0002cc00b006ce48180e88si1110706pft.378.2023.12.05.03.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:21:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a2SsaUgB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 73B8480C0354; Tue, 5 Dec 2023 03:21:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442057AbjLELV0 (ORCPT + 99 others); Tue, 5 Dec 2023 06:21:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442042AbjLELVP (ORCPT ); Tue, 5 Dec 2023 06:21:15 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB66211F; Tue, 5 Dec 2023 03:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701775282; x=1733311282; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rcIX7hZP19m5L490VTf3i3xI4HPGPBfZoYyDd0t+hRM=; b=a2SsaUgBWaE7P1DwwLYAYOeuhRtj6zoKmERqW1HLVGZ+NHpgxZ9RJ5NI bNfumROuD54ESirVyEsS6Ith5sF547dz0QPbTN/yojYHDnmNYc+Sgsrxt OMBpuyc7QmHfUEO4jiMTF3ZwgmyNErNhy9nbynjowqkdNs0CHwUztevWE AcuwfA8pvoKRYU6bcd791keJHQ1uoV9fKUx3wtit3QqqANsMkA59/RF8k wBPxwEo/nwX4wyg/tuOI0+vwMEK9YDgZiTFZz0Pntat5pJ0aQmXcupBy2 NS5qW1NZJg2UlGLvNN5jtB5UMq0xvnvoPW/eYdaYcVHxCl/zWIzZQXg+b Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942377" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942377" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 03:21:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018192908" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018192908" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:16 -0800 From: Xin Li To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, pbonzini@redhat.com, seanjc@google.com, peterz@infradead.org, jgross@suse.com, ravi.v.shankar@intel.com, mhiramat@kernel.org, andrew.cooper3@citrix.com, jiangshanlai@gmail.com, nik.borisov@suse.com, shan.kang@intel.com Subject: [PATCH v13 04/35] Documentation/x86/64: Add a documentation for FRED Date: Tue, 5 Dec 2023 02:49:53 -0800 Message-ID: <20231205105030.8698-5-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205105030.8698-1-xin3.li@intel.com> References: <20231205105030.8698-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:21:41 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440739773482639 X-GMAIL-MSGID: 1784440739773482639 Briefly introduce FRED, and its advantages compared to IDT. Reviewed-by: Bagas Sanjaya Signed-off-by: Xin Li --- Changes since v10: * Reword a sentence to improve readability (Nikolay Borisov). --- Documentation/arch/x86/x86_64/fred.rst | 96 +++++++++++++++++++++++++ Documentation/arch/x86/x86_64/index.rst | 1 + 2 files changed, 97 insertions(+) create mode 100644 Documentation/arch/x86/x86_64/fred.rst diff --git a/Documentation/arch/x86/x86_64/fred.rst b/Documentation/arch/x86/x86_64/fred.rst new file mode 100644 index 000000000000..9f57e7b91f7e --- /dev/null +++ b/Documentation/arch/x86/x86_64/fred.rst @@ -0,0 +1,96 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================================= +Flexible Return and Event Delivery (FRED) +========================================= + +Overview +======== + +The FRED architecture defines simple new transitions that change +privilege level (ring transitions). The FRED architecture was +designed with the following goals: + +1) Improve overall performance and response time by replacing event + delivery through the interrupt descriptor table (IDT event + delivery) and event return by the IRET instruction with lower + latency transitions. + +2) Improve software robustness by ensuring that event delivery + establishes the full supervisor context and that event return + establishes the full user context. + +The new transitions defined by the FRED architecture are FRED event +delivery and, for returning from events, two FRED return instructions. +FRED event delivery can effect a transition from ring 3 to ring 0, but +it is used also to deliver events incident to ring 0. One FRED +instruction (ERETU) effects a return from ring 0 to ring 3, while the +other (ERETS) returns while remaining in ring 0. Collectively, FRED +event delivery and the FRED return instructions are FRED transitions. + +In addition to these transitions, the FRED architecture defines a new +instruction (LKGS) for managing the state of the GS segment register. +The LKGS instruction can be used by 64-bit operating systems that do +not use the new FRED transitions. + +Furthermore, the FRED architecture is easy to extend for future CPU +architectures. + +Software based event dispatching +================================ + +FRED operates differently from IDT in terms of event handling. Instead +of directly dispatching an event to its handler based on the event +vector, FRED requires the software to dispatch an event to its handler +based on both the event's type and vector. Therefore, an event dispatch +framework must be implemented to facilitate the event-to-handler +dispatch process. The FRED event dispatch framework takes control +once an event is delivered, and employs a two-level dispatch. + +The first level dispatching is event type based, and the second level +dispatching is event vector based. + +Full supervisor/user context +============================ + +FRED event delivery atomically save and restore full supervisor/user +context upon event delivery and return. Thus it avoids the problem of +transient states due to %cr2 and/or %dr6, and it is no longer needed +to handle all the ugly corner cases caused by half baked entry states. + +FRED allows explicit unblock of NMI with new event return instructions +ERETS/ERETU, avoiding the mess caused by IRET which unconditionally +unblocks NMI, e.g., when an exception happens during NMI handling. + +FRED always restores the full value of %rsp, thus ESPFIX is no longer +needed when FRED is enabled. + +LKGS +==== + +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. With LKGS, it ends up with avoiding +mucking with kernel GS, i.e., an operating system can always operate +with its own GS base address. + +Because FRED event delivery from ring 3 and ERETU both swap the value +of the GS base address and that of the IA32_KERNEL_GS_BASE MSR, plus +the introduction of LKGS instruction, the SWAPGS instruction is no +longer needed when FRED is enabled, thus is disallowed (#UD). + +Stack levels +============ + +4 stack levels 0~3 are introduced to replace the nonreentrant IST for +event handling, and each stack level should be configured to use a +dedicated stack. + +The current stack level could be unchanged or go higher upon FRED +event delivery. If unchanged, the CPU keeps using the current event +stack. If higher, the CPU switches to a new event stack specified by +the MSR of the new stack level, i.e., MSR_IA32_FRED_RSP[123]. + +Only execution of a FRED return instruction ERET[US], could lower the +current stack level, causing the CPU to switch back to the stack it was +on before a previous event delivery that promoted the stack level. diff --git a/Documentation/arch/x86/x86_64/index.rst b/Documentation/arch/x86/x86_64/index.rst index a56070fc8e77..ad15e9bd623f 100644 --- a/Documentation/arch/x86/x86_64/index.rst +++ b/Documentation/arch/x86/x86_64/index.rst @@ -15,3 +15,4 @@ x86_64 Support cpu-hotplug-spec machinecheck fsgs + fred