Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1919518rdb; Wed, 31 Jan 2024 13:15:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8EQKqXUGhbWxzbvViQEt0I2nH5NfHBZ0IKoxdVR6yRp1bOuN2jQsiJ2a9hBNuQpR+7cTm X-Received: by 2002:a50:d597:0:b0:55e:eedc:f9a3 with SMTP id v23-20020a50d597000000b0055eeedcf9a3mr1945931edi.2.1706735710264; Wed, 31 Jan 2024 13:15:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706735710; cv=pass; d=google.com; s=arc-20160816; b=RIry3tqFQEmsJtryS8Aw7Wb6DWWQwajHFuB0H91yYinVxKMYtCKjrB1OYAAe6axxlP kEivBks5gpjW8ntHYkaOyrXKaGY05432GDti8rKg1MX1XkU9/cn1Xg6zXQI74O6Gu5XR esUsydktTWxlv8CD02zR87RuiJvcL06ParwOQQn+TF9KOlqiKMRhbWK4DiusszzGvYug FahME/vto/UY4C/GPKJilOTr85u31JiGSOIH1mn+PbiBQZAc8hmCH/u14+zx/l455E6I NqehcyoiX2gprqcZ+OM0IIdzD1IZbJdrTH8308NXzy8fQR3G03PrAMEUsic2aksvVBiN XYjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=roTZ7/tHvZOfb2gFOmTpe5nbycM6sv+b7LY7uSI+xwY=; fh=LYKeWrmSeHWdrk+ZFAmB12S6MrmuwLAp1Set8TAs3WA=; b=Oiz8iofanbl1GcuAOH/Qx886GCTLFcnrzSboey6HWPCBXem4KCrvB3ZUFI8ImvlUAr Jj4WZUvlojcy0/Fi60BgPxkjyABS2qRUQYl7uQuTcKaBqDHbX9G4MdNzSmN8ngVpqPx7 feSxOEBuAnH/6HWmYeR23Wf0xZcL4sbHFsDLgVF4BCQCHFb/Udgu4t9EOY6OAjQc+AUN hO140V04T9DWMXvX5M+dgQmQSExFZQdxeyz6qCfZOjJLo9Y9oJA/fjVKPWVghtVHfQyb xvQ252AG+H67BtlrQgxOGNRplCXmBwXiPl1HX06W4dGPNMjj50Zcfgf/r7qkmvK2RGDC raAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yKXqYSVM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mpylkgwj; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47117-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47117-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCV7LPFKG75N8Ki1MVD0LBIB0zMWjpjY36PAmHfsRJLzB6MJrY76vAviI6x/vWE/LISif0FQE4FymXc0DaLFKO/gV3VOXqJqPrTd+kMQSw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r5-20020a056402234500b0055f313139c7si2429434eda.373.2024.01.31.13.15.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:15:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47117-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yKXqYSVM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mpylkgwj; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47117-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47117-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CA8E01F2A114 for ; Wed, 31 Jan 2024 21:15:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D65E039ADD; Wed, 31 Jan 2024 21:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yKXqYSVM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mpylkgwj" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB4A539AC7; Wed, 31 Jan 2024 21:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735683; cv=none; b=oc06lSFpecZac9OffU4rSrrfQVTnIWndA71mUtYaN6nwsS5hZrPTc81uWSEJH/gMi5d1PixxgXZwwRtbEAl4GvEr8blX3yzzdCkos9mf2L6g5pqkeEc17sGGOKwIcrDS4v3aJJ/yKOeK7nzoM3PirLIPgbUUelS6BGNW+FIe0EU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735683; c=relaxed/simple; bh=3O0qDRDhPH9KqD642IEiWJ4kj+fu1gV+eTfhzgS4RJg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sXCJd/9oeUvhW7/FFrhDtG5ZoiANuJ3dNmguLlFcI3cpI55Vdw/VyxEBSFAMWkpS/jvtkWiU+yya7TTFKGWFwZXueSP1HEg+ySZmgPCiab5TGDOA0JaLTdkD6Vb6uNCWLQi9hMEeHUqDt+i75mnJqUPgA1/R+SRxXEsX3tzmFcI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yKXqYSVM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mpylkgwj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 31 Jan 2024 21:14:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706735679; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=roTZ7/tHvZOfb2gFOmTpe5nbycM6sv+b7LY7uSI+xwY=; b=yKXqYSVM2rZfjf1O09AF9V9xzB5cH3WTQgmBoOonWyJmtv8tRjJV63pV1qwEEldvK4jXtX us+X11DpQBCKpd3WNMR01+LsFo3dtTqPOSPnJ3t8IcnBfx6PVZ70t8SV6ehhZig2WnRHqQ KDISe6p81Vc+ivCyUigSH9S3dVQK2L368DCZ90aWJFuaEoNfydzPb+L3/2nqhCuaYxBS4R OXVYKBlHJMgXt5I7xUoHKHNKZv8tssjcr6g5crcgNoBKTbLWnEKUZm7i8WX/Q9bg0tdr5z v2NzKdPkXeGP1y5yz8DKn8By/GDs3FUEAqhYxHuE20BuwvZltqcyrT3veLBJ6A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706735679; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=roTZ7/tHvZOfb2gFOmTpe5nbycM6sv+b7LY7uSI+xwY=; b=mpylkgwj0Q3jsCCSESoVfEppE1iNZoF9B2HjF7vZjJCDfVgFljadBGtcb+yOAsVtdB9dzu taDXCBWh//DWyVDg== From: "tip-bot2 for H. Peter Anvin (Intel)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/fred: Invoke FRED initialization code to enable FRED Cc: "H. Peter Anvin (Intel)" , Xin Li , Thomas Gleixner , "Borislav Petkov (AMD)" , Shan Kang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231205105030.8698-36-xin3.li@intel.com> References: <20231205105030.8698-36-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170673567895.398.11546031751766547696.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/fred branch of tip: Commit-ID: 208d8c79fd0f155bce1b23d8d78926653f7603b7 Gitweb: https://git.kernel.org/tip/208d8c79fd0f155bce1b23d8d78926653f7603b7 Author: H. Peter Anvin (Intel) AuthorDate: Tue, 05 Dec 2023 02:50:24 -08:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 31 Jan 2024 22:03:36 +01:00 x86/fred: Invoke FRED initialization code to enable FRED 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. Co-developed-by: Xin Li Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Tested-by: Shan Kang Link: https://lore.kernel.org/r/20231205105030.8698-36-xin3.li@intel.com --- 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 4f5e4aa..cf82e31 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 @@ -2107,7 +2108,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 */ @@ -2213,8 +2222,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); @@ -2223,8 +2233,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 c683666..f79c5ed 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 1b19a17..6cb31df 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -1438,7 +1438,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(); }