Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp210930rdb; Tue, 5 Dec 2023 03:25:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHv/dPzWUPp8DyU7ZHnhlMxSo1wPpKHT0PvlVIZ9PGBEENq+YW7VFFyBzrnVK3J+/CWoyfA X-Received: by 2002:a05:6358:913:b0:16d:b449:fe9d with SMTP id r19-20020a056358091300b0016db449fe9dmr3735315rwi.3.1701775507470; Tue, 05 Dec 2023 03:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775507; cv=none; d=google.com; s=arc-20160816; b=i1D3vbicrt8N5viDKUbw5R93fwMIMEJJhjktudi3guTBSmzcp2Go7RZ4mZWwtklebi KkucK4GwHOlDShyxNO7QlKWpte/j70XJi1vaJGdA1dUoIsejl6w02qi0jBUgAH0k2sGn BSkydt+SVZ6daUzTEQkolqTgxlwpqHswK34z0T4sw/KMI4kGOaBEQsQEWjMox2mcamUL 8Jqie/XjLgk3k1Eidt2HhiPx5izaudXhjtSbBNIkgBkSlK3Gurm1G4AuFq0aMRMF7FGO NS+VcUbB2iX5moh7sNeVLseheQErjPI5NOr3TxdqHePVoyUln5UwjH3qT2rR6j8/FfpZ UKdg== 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=GdjLaqvwZLizFYipLADF2TYxM6WbFxcIx5O0SRZtCpQ=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=tYqNzyt3daoJZHUYDz/6MjVAv+TUkvDSlMHCt4KRGq74XqB3K+ofU0zgD3+KJpiMQ3 MjUE17mmhT9vqfRRKJCyrxS0mCp0ekoswO8AjPk5xHn6OZsVm6eRxO1q/PWX3Ya8a8Xl socX4+zSvLK/TUYJn0LA+8CdCQCKR2n0tQLCuzSFi2kO3eJQYH1lpnj70ojxoPcFDw+8 rUeWfzWVewnbd/0B6wQjXK0pjDt9Z+560J+wCt/tiO0xS0+ylgClFrFp8V3jO8GipP11 MopwefFxOfG/wuTJACJAN9bU9qMPbrDJOfWZImgKWFt/b1LHTY/Mw5vOXLv55LnCeAmV ucbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BvEB5F1O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id p24-20020a056a0026d800b006ce55d8f595si2742709pfw.292.2023.12.05.03.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:25:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BvEB5F1O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id B069C8227788; Tue, 5 Dec 2023 03:25:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442118AbjLELXY (ORCPT + 99 others); Tue, 5 Dec 2023 06:23:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442212AbjLELVz (ORCPT ); Tue, 5 Dec 2023 06:21:55 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10968D6C; Tue, 5 Dec 2023 03:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701775299; x=1733311299; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GKdJrpjNAAfGimUxYAq3wTN/xrTwaQ33LU4i4+qObUE=; b=BvEB5F1O9zz/PB3qkbHuh3wEJHsdc2UpviBLDpT323YSPOXR1EYDna2T jZsH02cy7fhUmhCL9mj0Q0q340w0HSUIBW/MXeqWhxg7E1dAUxNAcGA04 IR8uZPWh1QeKEi1sNE73whKwZ5crYmCEu7aVvvjrQNGQCHGoRcQwtJZXC SLcVgOMtXq5LYkqSphDXPwvNbiDDLrkXkF++Jlml5OPmO1Jc2lw6Hj/XK y5iIkmmUs7B+JSUnbuCcBwEg2J7jpdECIbKYRsEpA2lp4o0Ufm9tPzJMs DDoxUl0aDJVm+RuEldgtpXiNsfL0gOnEEbQNA45EPi7yG5Q/zQDb58WNX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942743" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942743" 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:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018193022" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018193022" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:26 -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 35/35] x86/fred: Invoke FRED initialization code to enable FRED Date: Tue, 5 Dec 2023 02:50:24 -0800 Message-ID: <20231205105030.8698-36-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:25:03 -0800 (PST) From: "H. Peter Anvin (Intel)" Let cpu_init_exception_handling() call cpu_init_fred_exceptions() to initialize FRED. However if FRED is unavailable or disabled, it falls back to set up TSS IST and initialize IDT. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Co-developed-by: Xin Li Signed-off-by: Xin Li --- Changes since v10: * No need to invalidate SYSCALL and SYSENTER MSRs (Thomas Gleixner). Changes since v8: * Move this patch after all required changes are in place (Thomas Gleixner). --- arch/x86/kernel/cpu/common.c | 22 +++++++++++++++++----- arch/x86/kernel/irqinit.c | 7 ++++++- arch/x86/kernel/traps.c | 5 ++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 9a075792e275..91d2f6018c48 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -2117,7 +2118,15 @@ void syscall_init(void) /* The default user and kernel segments */ wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS); - idt_syscall_init(); + /* + * Except the IA32_STAR MSR, there is NO need to setup SYSCALL and + * SYSENTER MSRs for FRED, because FRED uses the ring 3 FRED + * entrypoint for SYSCALL and SYSENTER, and ERETU is the only legit + * instruction to return to ring 3 (both sysexit and sysret cause + * #UD when FRED is enabled). + */ + if (!cpu_feature_enabled(X86_FEATURE_FRED)) + idt_syscall_init(); } #else /* CONFIG_X86_64 */ @@ -2223,8 +2232,9 @@ void cpu_init_exception_handling(void) /* paranoid_entry() gets the CPU number from the GDT */ setup_getcpu(cpu); - /* IST vectors need TSS to be set up. */ - tss_setup_ist(tss); + /* For IDT mode, IST vectors need to be set in TSS. */ + if (!cpu_feature_enabled(X86_FEATURE_FRED)) + tss_setup_ist(tss); tss_setup_io_bitmap(tss); set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss); @@ -2233,8 +2243,10 @@ void cpu_init_exception_handling(void) /* GHCB needs to be setup to handle #VC. */ setup_ghcb(); - /* Finally load the IDT */ - load_current_idt(); + if (cpu_feature_enabled(X86_FEATURE_FRED)) + cpu_init_fred_exceptions(); + else + load_current_idt(); } /* diff --git a/arch/x86/kernel/irqinit.c b/arch/x86/kernel/irqinit.c index c683666876f1..f79c5edc0b89 100644 --- a/arch/x86/kernel/irqinit.c +++ b/arch/x86/kernel/irqinit.c @@ -28,6 +28,7 @@ #include #include #include +#include #include /* @@ -96,7 +97,11 @@ void __init native_init_IRQ(void) /* Execute any quirks before the call gates are initialised: */ x86_init.irqs.pre_vector_init(); - idt_setup_apic_and_irq_gates(); + if (cpu_feature_enabled(X86_FEATURE_FRED)) + fred_complete_exception_setup(); + else + idt_setup_apic_and_irq_gates(); + lapic_assign_system_vectors(); if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs()) { diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 848c85208a57..0ee78a30e14a 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -1411,7 +1411,10 @@ void __init trap_init(void) /* Initialize TSS before setting up traps so ISTs work */ cpu_init_exception_handling(); + /* Setup traps as cpu_init() might #GP */ - idt_setup_traps(); + if (!cpu_feature_enabled(X86_FEATURE_FRED)) + idt_setup_traps(); + cpu_init(); } -- 2.43.0