Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1777574rdb; Mon, 2 Oct 2023 23:58:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGc+li6YDFwZqPMnjgzAtjDeyV6zSLF3sAhnaOSPiVjXfhQzssU+2g62bDG/04ec8XZvJd1 X-Received: by 2002:a05:6808:10d5:b0:3a9:9bcb:8760 with SMTP id s21-20020a05680810d500b003a99bcb8760mr18184266ois.39.1696316339055; Mon, 02 Oct 2023 23:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696316339; cv=none; d=google.com; s=arc-20160816; b=GCNuflSrw4Wz1Ensq+ElzqnRK9RhlOnfL99RIxj8FJVJAcCc0lJqKbyBjFlArNbEna /VbOIDvjOFE1olSM2iRh6E41yjXL0rGKu4DkzCo9hWtLQFcj2vM+yPbPBk2VcJJUL+WN GdcHvaN54OL/eaTUIjrj2lDhBEBTT5afGAyQaJiy8zDzO+8vmR49217q3VgjCL7HkdpX FI+Fcb4/roTH2jjPp32KmlvmcOUAa5J0PlFUQ+H3wXy+AH1Tbz5WG2AQrsjfMZ83Qsd7 4mKTdARkbSlgzQ3Z/T2nrV3om5WsNsEqy06J3tLy0+O2T8HfI0BEcH5Wn9utnQKbDGni xMhw== 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=gmnJ/zKQF5y18k2o+mm/bitnRTYVj68tIOG2UhbARBM=; fh=Tb1p8S3iOxe/kX/WSNC3xEJzSVgGJ5DaxSrKb+pzH+4=; b=wjQcyo/NQxkmOVIb6rXAPEgaLlJIAgrfY2u1YPR3LgnYdq6LQmqLD8zDL2nKhawR7y 2L6kpdZ2trN5VCX2LYEIL1AFHyrJJKNoVkTlzhx+1OrRop5MkhOk9g3v14L0heTbBVnt 9m+NPd4rZyyGJ1VVSCio6reLa634IYI3rrvispmMftxJAB+sLpr987wNBeT5fx/FBo2u 4H+Mr8WKMvhM9N0YYM3vdvIkJqiqo6TGsaXUciv6clLnrAItqqodkkx7krJmOTardEFD ilaWxa2CYvPxdYgQP3cTsiQ22rI+KXSTEM1xWwlhIu0Q8RV7FBpviW+YjjvRYSqq8onf AzMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LCqK0SUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id be3-20020a656e43000000b00578a2da0e4bsi821855pgb.302.2023.10.02.23.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LCqK0SUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 1F11D81352AC; Mon, 2 Oct 2023 23:58:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239446AbjJCG6u (ORCPT + 99 others); Tue, 3 Oct 2023 02:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239417AbjJCG6j (ORCPT ); Tue, 3 Oct 2023 02:58:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8591B2D6B; Mon, 2 Oct 2023 23:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696316153; x=1727852153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eEbBoWC5xFSRvZAlegSoACai1Gg5zcI498qdyjosTZg=; b=LCqK0SUNoVZuSlE87IrtuLL7LZs0+0Ox9Yhwsw7/VfVwP5gpiu4dgRI7 MKCqMvZ2UVJshQSQ9RVMH5Wl6Y0gAzJtD57YXbZ5coSKdQDnmyqXtmDr2 OYifj7m/SCRxt29TiduKgCbiw76TjCM4/sjG8Jjwb22ZzOXmlCrgaH3t0 5W2fMf+WBw1drmhtiilXDM7+M56dBG+gkpYunKTXL/PKucgUo1pZqgU9m PEsWB8y+wyMt7/ZFBeM+19oSOS/3+V0rnmKe9taBwlEwO/gBO0WEKcLnZ QCTHumOgDGnsbWX3RMY5jKT0V232HgOwZQmpkfsZxiWZHHABUAftFp0ru w==; X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="367858374" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="367858374" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 23:54:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="1081901031" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="1081901031" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga005.fm.intel.com with ESMTP; 02 Oct 2023 23:54:53 -0700 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 Subject: [PATCH v12 37/37] x86/fred: Invoke FRED initialization code to enable FRED Date: Mon, 2 Oct 2023 23:24:58 -0700 Message-Id: <20231003062458.23552-38-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003062458.23552-1-xin3.li@intel.com> References: <20231003062458.23552-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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]); Mon, 02 Oct 2023 23:58:58 -0700 (PDT) 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) Co-developed-by: Xin Li Tested-by: Shan Kang 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 69f9bdab19a9..b103cfad0520 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 @@ -2119,7 +2120,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 */ @@ -2235,8 +2244,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); @@ -2245,8 +2255,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.34.1