From patchwork Tue Oct 3 06:24:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 147678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1899990vqb; Mon, 2 Oct 2023 23:59:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrTOlojmtD7MuBXVc41Zh7JoMNH0GHL0HwcC6TvnrMIr+u8HQx7XQgH3O83za8TNUS47qb X-Received: by 2002:aca:2b17:0:b0:3a1:e85f:33ee with SMTP id i23-20020aca2b17000000b003a1e85f33eemr13774031oik.56.1696316348475; Mon, 02 Oct 2023 23:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696316348; cv=none; d=google.com; s=arc-20160816; b=gBNqEJvlRYkg+TfkPKNZQ+DyZBOm9f4/Lbe+jlJTqn075tnnneCJMiKSYxyK/KhXAA jXQ7BAtTg+Ucdj7Gwxbb5D3K8iFLRpdQ+yy0ej7S3KovdqFrGrN7yGgmemFQCeLlwXeJ pjARF6sDYNh7Sm7ffhOf3v1I39kH1i0Dc7vUF7jifVZA68Dmxpo6GJXEXoL3qr759sOj Cr+d85CI7bb00h5iCZ+2v5fDQzConmFuWIN2/ODnLqUqORu9ZeBtzXi+SbXIM9yMrQXN NLQYUcnLHefqWDeCtkBJ1OecZaLcLK2j5DBJXNWmJEK800cBfZa4jgvtmNBsxgMPFVjn 1cOQ== 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 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ob6-20020a17090b390600b0027920d6f859si10708351pjb.107.2023.10.02.23.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:59:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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 23.128.96.34 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 98F32806FB73; Mon, 2 Oct 2023 23:59:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239475AbjJCG6u (ORCPT + 18 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 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 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 23:59:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778716611683248522 X-GMAIL-MSGID: 1778716611683248522 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(); }