From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.64 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795991840; b=kcGx4bzN1krfxivFpfpJaQo9Z5u53nTf8UrImTIuORg3/DrFavLNFSsGKw+MiaRvQden FI1rzBO7ThWcV6HRO6o0ikUJri7Z36L7hzFQGuDuZZqGAJ/BVJkhDKIHxnMON4r7VuesT 9qdIF60GsBLv4Bams1QbIQRMiIQFLMJz8J/7w9Xq/IlgbF5DLFJJRcKbtN76ID2hSIQFm EWlxLkUGAprbNvcLoHgDmfmaYFrXGgSyJGnP5cD1pNPSxvNZ08jspWDzwBdVEv5s0Fd3Y IELCfmWg2eCSQOJJD8TrcaE2OpN0LcGEno5E1+LZ4fP6jlJn2Ksiwt91zVshDWt6tPQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991840; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=cg/s3GGmQMOxJOhQrfQ5p6oIpYRC0uOFYW6IKPcdp9g=; b=uYPygnshAZLdk/O8zuWHeMCa19OJFT+kD9nCbbcrunNGJm81cZYnslA0fOiGkZb4P0DA pUZzekk9dCzaxe/5v6jo0M2JRLbWSo5Mk8ZBT6A0N5LH5n3STo4kCd79OSBarh+uh/w8L nNguMqzedF4TSSLz7qoGkds2vFFI6lSuhM5+G/PiOATLdTyE/tqYJirrDYLc59Slbt0Xu 41g4td5RIXUgKeD6ha567dJCITrbfhVWdS4gU7jlARsYVYZEtBc6Ri3I7oUbl9/6Z3y5S 6Z/b67Py7aO4GsAl7ALwt+WOkiZcSYygjBOkzMYJ65AwuI1Q+VL6ZaKM43jrc2u8oTQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=0tRzfVqg; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.64 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013064.outbound.protection.outlook.com [40.107.201.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C043606A325 for ; Sun, 29 Nov 2026 22:37:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C043606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=0tRzfVqg ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NPTg0QsNgq9fGETI/KzxlWBeiyssB37qc86H6NGQt1Qa7vWNGZHRQzhZeE59ty9GkXm2te/iB3cAFWDZRXQvYbPVIjrLCDyzfnSQex/IocE4rdgwFMiivRej2OPCd5i5yvxM6NHTQ3BX0/Y+A4Ek3bszBjcNDygqkO5a9dm3diCzV8AIU/5aCLY0GyaePhJKzjUOv3b4OHARmmcYStREcgD02mplUcYNDpcnmdF0ifo9y4KsWjUB2lhz0w/W6s0Sg4NYo2K9J4Wp9SrZAY19hAavkjNXe3/cP2mf9TGxnCHoomXP0TVt+ixG14cf0uYmCGegO+nhPTKVAJkgzwkmqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cg/s3GGmQMOxJOhQrfQ5p6oIpYRC0uOFYW6IKPcdp9g=; b=KakQa021ELqcfKHHNX1cJ0igTRitzvw7NygPkGHqZilygG9L5QqNfU4QvXyRPnOV8IE2P/eAtsJ1fgyB+DnKiwonu2NInYyfQjUiJZz/vmgvefyqR7y5wd/W7kTJygmVehK0d2lN9hsq5brIk8L+dxNI5Ji+0RF9qmums1izrdO14+0qET2lMmyq8nsI3n5yPtAGih88M3kvkwWQuoaXxiNms5x+6NYTxl7TnFoqhSNhsxXqSV+M/pVgGEYs22A3l5lthl5VKsHTChmCl3nHi06QBiJ4ndYDSnmDCQS4N/1ngk/2cP3ppT7AgP59qP9+SH8WNM+84KgpxI8GLa4AAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cg/s3GGmQMOxJOhQrfQ5p6oIpYRC0uOFYW6IKPcdp9g=; b=0tRzfVqgyry8qDucxmaPxi3IEL5zcBOPsoXyra6YyFJ0M937fbk/iXtC1yas4MSDdFgP2FnCPSeFVwSRHpIGckEsh828ubSHfQBhTYfCYCdcJAbssNT47HO4wImEbU1q8lw++JNbSZSNhifPiT9hKqI+NUAo/GdswpetnHqRFug= Received: from DM6PR07CA0084.namprd07.prod.outlook.com (2603:10b6:5:337::17) by IA1PR12MB6138.namprd12.prod.outlook.com (2603:10b6:208:3ea::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Sun, 29 Nov 2026 22:37:15 +0000 Received: from CY7PEPF000000F4.namprd05.prod.outlook.com (2603:10b6:5:337:cafe::8) by DM6PR07CA0084.outlook.office365.com (2603:10b6:5:337::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.12 via Frontend Transport; Sun, 29 Nov 2026 22:37:15 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CY7PEPF000000F4.mail.protection.outlook.com (10.167.247.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Sun, 29 Nov 2026 22:37:14 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Sun, 29 Nov 2026 16:37:09 -0600 From: K Prateek Nayak To: Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , the arch/x86 maintainers , CC: Andy Lutomirski , Peter Zijlstra , Rick Edgecombe , Andrew Cooper , Kees Cook , Pawan Gupta , K Prateek Nayak Subject: [RFC PATCH 24/27] x86/process: Initialize shadow stack for IDT systems Date: Sun, 29 Nov 2026 22:29:49 +0000 Message-ID: <20261129222953.9124-25-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261129222953.9124-1-kprateek.nayak@amd.com> References: <20261129222953.9124-1-kprateek.nayak@amd.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY7PEPF000000F4:EE_|IA1PR12MB6138:EE_ X-MS-Office365-Filtering-Correlation-Id: fa89c4f6-bc4e-4e31-c4df-08df4e6950c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|82310400026|376014|7416014|10067099003|56012099006|261028144727099003|261026121527099003|261026140227099003|261021123027099003|261021121427099003|261022113327099003|261022105027099003|261022075727099003|261102123227099003|261009223027099003|18002099003|22082099003|11063799006; X-Microsoft-Antispam-Message-Info: Rzm6iseG/90lN5Gmhk9Yzki7+Ma0D66jrwa2K7gVwO2Wg05aroP/FYsw/1V/qU2atzXvLw4eNTClFmh9MnvrqyU6MttRmVDzTkir47tGbmoKP+i0HzXF2EdHW9lgbzYb1KFjLK0O0Zc4VQfdqX3pG/DnCwl43zQMCd+l5GdTkE34eaCF3icVkoZLfM4tOCE1dEgfu6wahSu25/VE+tbjI2RsRA8UOuZ/jIjOhzod2sq6RpdbPqP0HIFPxUg9WmW+JaecYo+Wg57b2W5NCHz3NysuuILZZ8zxb4J/N41GOGPwV7NsMOPZ3ySKsPsRuSlJwqNEviVMSvhzk8aMQKooHSe6eAh/y+fcv7LwG0KuaJ4gOpFsYP++s49BbqoI8Y56XGCCX5j8xSkEeJ3lauWTrnJhk2z9WmVNmICl1/KGf6GIfZFQn1xhMcHp1zqOEMASOXeMD5QvMo0qJZGPwzpOtuuTmOr0gOjopur20eI/Av62G7v/TS60A7KUZ5PdJQ+yqX1wqz3UGIYI7WEV7NRSboOXpr/fzdheVI/dxf/rhuDKQlQtXSF184XMV2SJ5ZPRv2u2eoApCVFjUGXGplOSBowr1g/oEqtZvmXOcQL8pIDlyX0X5W5jQliRYvc7eKM/cS/gNHMA3WrN3DR81VlqzHW0jMoUzP9ycF4yKOs5Bm4mcHzqBbQVfj5o8axc0wPSjTwD/ZrHDTO2asVYBa4rnA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(1800799024)(82310400026)(376014)(7416014)(10067099003)(56012099006)(261028144727099003)(261026121527099003)(261026140227099003)(261021123027099003)(261021121427099003)(261022113327099003)(261022105027099003)(261022075727099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fgb//WSXtkIz1EwFmYMDjJ4i313y8V3p4+DMoRYTwd/0bFWtB+2gbD7bKQd/TOHxyhJFgVS1/YLyVFlgb3NzZMmgcW2BWrs6tye7OMRvFxhNKp4ggjcyPVw3DqXLNlKHG45/3pe4Frx7Pgj8KPRYhUmy2zby4tR80jorisjRX/JUvSkq6ueQcHj0vYUlD9HCSKmEWS9voYx3Ewl60VQYIEeskV+8gidBbxFcpngicowWbRTBmg43LbhZcCKQBIvN//zUCLSxYG38N1S0vT+Y9HA/IhdDnY74eo1C3rkEztcUwzEYxjTrNRxwNcYVrc8iu2IrlK4u3gKW4L4SN8OXl3sWUZhVkglXBcJHWWUtS6dq30SLlDQChCDfvVEhsgqeUf6Z916Iarqjpf2ghBRw5kmy6VjjQH0kCIdBQEjJetu/kHVQvBbeBjm4nnYSeNM6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2026 22:37:14.2362 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa89c4f6-bc4e-4e31-c4df-08df4e6950c0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY7PEPF000000F4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6138 On IDT systems, the bottom of the stack should always have a supervisor token that can be marked busy by the hardware. Populate the supervisor token in the fist slot and, like FRED path, populate the first return address and the restore token below. Since SSP0 should point to the supervisor slot, set SSP0 to one slot below task_shstk_top() that contains the supervisor token. The SSP0 reset is no longer limited to FRED enabled systems. Use MSR_IA32_PL0_SSP to reference the MSR instead of the FRED alias. Signed-off-by: K Prateek Nayak --- arch/x86/include/asm/cpu.h | 4 +++- arch/x86/include/asm/entry-common.h | 19 ++++++++++++++++++- arch/x86/include/asm/fred.h | 7 ------- arch/x86/kernel/process.c | 17 +++++++++++++++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index e8227cc1336b..8c91a3ee59d8 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -138,8 +138,10 @@ static __always_inline unsigned long disable_kernel_shstk(void) static __always_inline void cpu_setup_kernel_shstk(bool boot_cpu) { struct task_struct *tsk = current; + u64 ssp0 = (u64)task_shstk_top(tsk) - sizeof(unsigned long); unsigned long shstk_top; + if (!cpu_feature_enabled(X86_FEATURE_KERN_SHSTK)) return; @@ -152,7 +154,7 @@ static __always_inline void cpu_setup_kernel_shstk(bool boot_cpu) shstk_top = (unsigned long)tsk->thread.kshstk_ssp; load_ssp_table(); - wrmsrq(MSR_IA32_FRED_SSP0, shstk_top); + wrmsrq(MSR_IA32_PL0_SSP, ssp0); enable_kernel_shstk(shstk_top); } diff --git a/arch/x86/include/asm/entry-common.h b/arch/x86/include/asm/entry-common.h index 470ac946afba..10960d8237c9 100644 --- a/arch/x86/include/asm/entry-common.h +++ b/arch/x86/include/asm/entry-common.h @@ -56,6 +56,23 @@ static inline void arch_exit_work(unsigned long ti_work) switch_fpu_return(); } +#ifdef CONFIG_X86_KERN_SHADOW_STACK +static inline void update_ssp0(void) +{ + if (current->thread.kshstk_ssp) { + u64 top = (u64)task_shstk_top(current); + + /* On IDT systems, restore past the token. */ + if (!cpu_feature_enabled(X86_FEATURE_FRED)) + top -= sizeof(unsigned long); + + wrmsrns(MSR_IA32_PL0_SSP, top); + } +} +#else /* !CONFIG_X86_KERN_SHADOW_STACK */ +static inline void update_ssp0(void) { } +#endif /* CONFIG_X86_KERN_SHADOW_STACK */ + static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, unsigned long ti_work) { @@ -65,7 +82,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, arch_exit_work(ti_work); fred_update_rsp0(); - fred_update_ssp0(); + update_ssp0(); #ifdef CONFIG_COMPAT /* * Compat syscalls set TS_COMPAT. Make sure we clear it before diff --git a/arch/x86/include/asm/fred.h b/arch/x86/include/asm/fred.h index 57c7e78c787a..477b0b2605a7 100644 --- a/arch/x86/include/asm/fred.h +++ b/arch/x86/include/asm/fred.h @@ -105,13 +105,6 @@ static __always_inline void fred_update_rsp0(void) __this_cpu_write(fred_rsp0, rsp0); } } -static __always_inline void fred_update_ssp0(void) -{ -#ifdef CONFIG_X86_KERN_SHADOW_STACK - if (current->thread.kshstk_ssp) - wrmsrns(MSR_IA32_FRED_SSP0, (u64)task_shstk_top(current)); -#endif -} #else /* CONFIG_X86_FRED */ static __always_inline unsigned long fred_event_data(struct pt_regs *regs) { return 0; } static inline void cpu_init_fred_exceptions(void) { } diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 357c815d4522..661932d894cb 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -206,8 +206,21 @@ void prep_kernel_shadow_stack(struct task_struct *tsk, * Write the return address for the first RET: and point the task's * kshstk_ssp to the top slot. */ - *ss_top_slot = (unsigned long)ret_addr; - tsk->thread.kshstk_ssp = task_shstk_top(tsk) - sizeof(unsigned long); + if (cpu_feature_enabled(X86_FEATURE_FRED)) { + *ss_top_slot = (unsigned long)ret_addr; + tsk->thread.kshstk_ssp = task_shstk_top(tsk) - sizeof(unsigned long); + + } else { + unsigned long *shstk_top = task_shstk_top(tsk); + + /* Supervisor token for PL0_SSP */ + *ss_top_slot = (unsigned long)(shstk_top - 1); + + ss_top_slot -= 1; + /* Token for first return. */ + *ss_top_slot = (unsigned long)ret_addr; + tsk->thread.kshstk_ssp = shstk_top - 2; + } /* * Back up one more frame and write the token for rstorssp when this -- 2.43.0