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.93.195.10 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795991807; b=HbKQabpyKOoLfLMzJ1YZOQ7RjY+aiFCKV/GXgbUCENY8TkkMExXzuH9OL+de1MU3ne2+ 5hpsFlYA+70cmkui4S5c7bwQwvhn/USe7KOPmhV18IP1RbwUJ/84gRThRq4/CxiK5Y5oI Wcw1VsUz21Iaduc4htHMOoEkq6NvQQN00uYM6MgUZSS5GTNEy4UnUL8OXZ4OCKPTqoapl uY8kViMhnhPRi7YH3dXdfaJJuCRcocfv89MbOF5Q1hnxIkENioNWVSgE3CwOJlaOGKxHK GoXkwsmsD2f37PNjP6PQSaMxbB+CKYpth/OEahYdJ0xvD1d8qvOSK0E6BUNl8vn/fSw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991807; 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=nR68V9VdzqIyny3Lc0HOwE2ibbt6Mgvg6P8KR56G7vI=; b=txSpKxAL8Y/3JqMvMSm/sExvY0HEsChuJd1zeQspQB41EEeQJdVvTu8znChIFVu8YrsP dBmnXh5RilajTOAdNOwWmD/lvq/zjdi+iBSomrHPuCX3MhNiazZ9XWnnsA3L1bzjY3jAr 92kH9VTGT+Q8vs2xlFv4XRvPJP2Ri50OnGuz9QJBB+NVoMdZMN4PBiTy29nr2dGBtp7gI Q3bfQrbn3Ub78bRgkPiryRmw2SuG5kF8kvcEPyYa27P5OYH8UzaBrkou8UI2SK8TSXofF sx/3zMHb01MKsgIvgaAIj1QVBOdMWBync4krBoPEAxMek13hXSrkfKp4S9rOhadAu5g== 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="2ktOk/sq"; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.10 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012010.outbound.protection.outlook.com [40.93.195.10]) (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 24C2E606A327 for ; Sun, 29 Nov 2026 22:36:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 24C2E606A327 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=2ktOk/sq ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SS0bHFkcgowlisr177PeDctnAjwkG77nFMLmRDXFIi+UWet09xT9e5hxtp0WsQITbTvi3KWtt5YHaOy7mR+ZT9IWByepao6JuFMQLuetxYaZkP84uhPUuSu29cYKw5axMtLL09VRSFcCH7W2K3bZrEj8nm6GNiw7GZx1XmnIuloDUR1AokfkTb637aqMLjVYyiWgil/OqZReFjk4LBWpzfOP62F7QjIKvPnek4O4TWrGV6TWlqdXQqz4VWWw9sWTj4Hyfr51R9RHhcduJVSMSqpy02scoSCzAXfsNuLvhn+ohvA3l8+HZ4BfN2olfADVePxfwZTMkfh5DXxG2uXETw== 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=nR68V9VdzqIyny3Lc0HOwE2ibbt6Mgvg6P8KR56G7vI=; b=KjlNyhN47NmwoQd2OR3faIMg65l4F8sFpWbzWhOSU1rO5ldkpQNC7T04nwtwe6kMrfkNsI1VundHMjN0RQ7xWBflh9bWDh/H4ElFpEZkSMxPWc3jlo69sLEfEhY/8uqDjIocJx06wbWJhjEzXsDoZVsv4LdSa14K+GvVUxFuUIyR8/ZkXRed3J6vNZfGbVPy0ZS4EemJxevIO6F7XSUlxFZWEgAiNIpOWTypACcBjekXLLFkHRzhkBq3Y1awIHYMiQIcqNsCByMJCll2RnbK2/uwDzYsw3F9WK5AZ8gsAUyaHEVWSVm5vIwpAgpomNwC99OaNFdHrqycOcuw4GfQ2Q== 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=nR68V9VdzqIyny3Lc0HOwE2ibbt6Mgvg6P8KR56G7vI=; b=2ktOk/sq9XF/tVbLyOv6Cgbrcb9kbFP+JHcuack/nXGJVUhosdAtDiQmyLuyAlA+Pxg5UwADcDwCSt27O0SW4G/PtIdOVw/R2F4DzbSMF395mocd3flySfFXbmHjELnbdiS15xJ8Y56r04Ln+EdBJZz4lluQ41fuKKj9rFyjoe4= Received: from DS1PR06CA0028.namprd06.prod.outlook.com (2603:10b6:8:23e::8) by PH7PR12MB6420.namprd12.prod.outlook.com (2603:10b6:510:1fc::18) 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:36:39 +0000 Received: from CY7PEPF000000F2.namprd05.prod.outlook.com (2603:10b6:8:23e:cafe::1a) by DS1PR06CA0028.outlook.office365.com (2603:10b6:8:23e::8) 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:36:39 +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 CY7PEPF000000F2.mail.protection.outlook.com (10.167.247.150) 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:36:39 +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:36:34 -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 22/27] x86/shstk: Save and restore shadow stack pointer during kexec Date: Sun, 29 Nov 2026 22:29:47 +0000 Message-ID: <20261129222953.9124-23-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: CY7PEPF000000F2:EE_|PH7PR12MB6420:EE_ X-MS-Office365-Filtering-Correlation-Id: ab2ab2d2-1fa2-4b76-053c-08df4e693bde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700016|1800799024|23010399003|5023799004|11063799006|261009223027099003|22082099003|18002099003|10067099003|56012099006|261102123227099003|261028144727099003|261026121527099003|261026140227099003|261021123027099003|261021121427099003|261022115727099003|261022113327099003|261022105027099003|261022075727099003; X-Microsoft-Antispam-Message-Info: eKjpj7QLNpBNR2+sBl5/ieytKggfbizUadotJAxzsSPoE1WMqo15+OLOXeVfJi2BbQlpzKSyp9L2ayBHS8IhVEmRURp44bZlatunZ9sqy0xXODwiXMw3mX+yAD5mBaNS2aQRLJRZAzCjWmbGBc6FIoNN7XprrhhA0YvplBofOiIvTXkpECHJM3aapwWeXunN1yjwADS6Gya38vjcxw0TSD3uYuAJaSmw4R/+alTrA58kQN4HotEtU1LYXtZTv0IkWQA4OuQhTVnkz3otNQ4CIGB71WcZIPX+ZeJPqNTKzKvHpR1KrvIuGIi+hTFJ779cQXxQbh7dAJ9lqw7vUrwxOG8tlasMEfXYZ5sRr3PlaQvLqQD3xG/aX9yoOXTq9nl3YZhPwqmSvC06e/M9Xg7rD7wIK5joioaNLJEmEtR+S1oZKP4GFhsAKTmO2yxL0yqgf7c9U99xjK0l+5Xm/tUe4Gc7W+rK7U/jYMjehqHrYPzO0Zi6q+Z0iYZLS04k7e2dypJ1EkV4mxsPYoTZCuxGqrinGVyUVoOzTGh8yX/vCvPA+4XAKt2r8oCb6P/AmS7goQFKBiylS1YakeZI4LDt5Gmsmh1Ai9JrsoSbrih7YB7zxOcMlQU377wBsseOEWUNYg+Oixg07tpAzKrQbjlX2/q8iF6jtQKDHsFQ059ujz8wJJiZjD/5nYpkGqS7TWNzOI2KB/tb6wLr+JTBBehtgQ== 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)(376014)(7416014)(82310400026)(36860700016)(1800799024)(23010399003)(5023799004)(11063799006)(261009223027099003)(22082099003)(18002099003)(10067099003)(56012099006)(261102123227099003)(261028144727099003)(261026121527099003)(261026140227099003)(261021123027099003)(261021121427099003)(261022115727099003)(261022113327099003)(261022105027099003)(261022075727099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6aH34Jy8ZYCDCpkNHZMGTqs+p3rxfAP18whSKIJl9YTj7i1/pc8byfQfPGdyj6kFJs40gfz8Wv+RuGOD7qxzPAU2jC6NV8sE0K/TYom+4skhABDbyOO8CoeujenDUSC9JypEdTXxZXqd9hX/Uc6gBtmHCiR8T/D1ZSuNRnAhrz/GdOltGFZy80wHa9TP+Q/WPSaZw3E91VmLf6S/pCZ1O8HF2yHAqRT9q8kQNeYnBiabCqIEfPlgyDrW4WiwAoLn1AXjFjVCIxqyj6G/99z0ZbiXg0F/2ewbOg27cCflgVtskKZTQqf5U07oLN1QVxS9kypLToYFtAY2EGqQvNeFErmlhflOl8BTUoDuLHwyAJ5b4ppMu216bVFI5l80P6A/SiGB0gz5yEabaK7suvJBgbAtVJUtv9VrN1VGvABoeFluGScDnmFPBWA/bvXUiAnU X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2026 22:36:39.1960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab2ab2d2-1fa2-4b76-053c-08df4e693bde 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: CY7PEPF000000F2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6420 To support KEXEC and KEXEC_JUMP, save and restore shadow stack token on either side of relocate_kernel_ptr(). On regual kexec path, disable_kernel_shstk() from stop_this_cpu() will disable shadow stack on APs after the APIC is turned off. KEXEC_JUMP would disable the shadow stack from the offline callback. restore_processor_state() populates the CR4 and FRED exceptions, RSPs and SSPs on the way back - restore the shadow stack token on the way back in machine_kexec() after the necessary FRED bits have been initialized. APs re-enable shadow stack when coming online in start_secondary. Signed-off-by: K Prateek Nayak --- arch/x86/Kconfig | 4 ---- arch/x86/kernel/machine_kexec_64.c | 4 ++++ arch/x86/kernel/process.c | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 4f5097fdd365..c101f7b23644 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1907,10 +1907,6 @@ config X86_KERN_SHADOW_STACK depends on VMAP_STACK depends on AS_WRUSS select X86_CET - # relocate_kernel() switches CR3 and CR4 with a shadow stack live - # and uses "pushq $0 ... ret" as the handoff into purgatory. It - # needs S_CET.SH_STK_EN cleared first, which nothing does yet. - depends on !KEXEC_CORE # __efi64_thunk() drops into 32-bit firmware with LRETQ and comes # back with LRET. Far returns are shadow stack checked and expect # a far CALL frame that was never pushed. diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index c3f4a389992d..e18f7d292d62 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -386,6 +386,7 @@ void __nocfi machine_kexec(struct kimage *image) unsigned long reloc_start = (unsigned long)__relocate_kernel_start; relocate_kernel_fn *relocate_kernel_ptr; unsigned int relocate_kernel_flags; + unsigned long shstk_token; int save_ftrace_enabled; void *control_page; @@ -399,6 +400,8 @@ void __nocfi machine_kexec(struct kimage *image) /* Interrupts aren't acceptable while we reboot */ local_irq_disable(); hw_breakpoint_disable(); + + shstk_token = disable_kernel_shstk(); cet_disable(); if (image->preserve_context) { @@ -461,6 +464,7 @@ void __nocfi machine_kexec(struct kimage *image) restore_processor_state(); #endif + enable_kernel_shstk(shstk_token); __ftrace_enabled_restore(save_ftrace_enabled); } /* diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 7b3a9f112451..357c815d4522 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -902,6 +902,7 @@ void __noreturn stop_this_cpu(void *dummy) set_cpu_online(cpu, false); disable_local_APIC(); mcheck_cpu_clear(c); + disable_kernel_shstk(); if (this_cpu_read(cache_state_incoherent)) wbinvd(); -- 2.43.0