Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1671372rdb; Wed, 31 Jan 2024 05:59:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSsZptaKgBHVwgwzVvDyKkhAvOYBReXwyvPm3JS/XYoF9t/Vsy29IuxR71A0aySlpqaIrz X-Received: by 2002:a05:6808:2202:b0:3be:41c1:26d9 with SMTP id bd2-20020a056808220200b003be41c126d9mr1945608oib.31.1706709545860; Wed, 31 Jan 2024 05:59:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706709545; cv=pass; d=google.com; s=arc-20160816; b=f7UprgqJyVdO2O3mmhQbDQ0v5sKLqnz3qqyV8PC7BNeBGQxB99FrN2151j8BrgSb3O JutS/0ZK5vnwvHYJ/58k0reF8Sf+ZXMIRXbbnAOrzG875VfLZmrHIgyp70ffCVGBZqco rN8J5jHRapBAkrj3/66mpN4ClXyWvb+GCvr4qtVdc44BDQnohfvRHiEYtfNsLHyWuPn7 4G+Axasot1dSOchFHpLK+gakbvB7aoBxThBRz3kZIRYm+V1g97CdsTeXlA2SZBWvnAPs dSzPIboZ2KXYx8S3Z5e/wGT6JDrP3P2qVUPZ07kwQrL5qzJeMrQHRMKSJu3MRhp7U9ed lM2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=OVL7vpRVhiQT8rKruMK2mDLtCwDrKkGBYpIwPatG2NE=; fh=WKgi5x6akgPPW8iivH3p7E8U9S3GVAgQlOW+LJtO4t4=; b=DS8/BS6s1mPUqcME6ZkGvh6O6JXTje7XhwckghfeDC/s8dPTLT3+Ri4skAcGAvykk1 ErkGG0EGa0ClG+426SVmLhCUYn7Ru/dj+pgFDqsxMuS0SuHbIStEMikrMP3PlVzYB6BT UvT+Qhn5XHLrjwX6dS/QPHxeZ3/WYnkDpee+OJvw9x+1XmIPrTgbm+g4aq2cJC/tzuX5 9mok/v82HOgT4sIGYrQMcjWuRQX1JhGkzrhj/jcxcwY/Zht4Y7HWaY8XSGWKJ5IeIigP Hkh3qyYxWWcnMKzEco9ofnCnUhVv92kbeDwE4jaFdC9LmxFYzdf68YH0ydB60MUDIYeN Zwtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JMJM9ktc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVBeTB2U/HNHNq2rFw/lybcD/Ph1PvbR38TFfms0pJ4kW43iyxr0KPra46Sid7XM9G0ucqbbFLoZ9cWj6ClJ6TAz/VtFOxBDVeZBhDhGw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i185-20020a636dc2000000b005ce087e004dsi9518415pgc.799.2024.01.31.05.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 05:59:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JMJM9ktc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C4C2928756C for ; Wed, 31 Jan 2024 13:57:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 578C080C09; Wed, 31 Jan 2024 13:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JMJM9ktc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7349B7866F; Wed, 31 Jan 2024 13:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706709451; cv=none; b=AmsAIh3a1JX/HTHPzpuphY/YzYacyl0VHxLH/9sD18YAo0VAD4BcqSKfmatzYfPbvYvL0Jq02N9zyRQ5p0MY67h9aV7CczKhThkV6znDdeIQTciAL4b1brXEFsSgm9N+bVFvcZALqPO19k9BzHFmi6XH/a9i/e/MPpb23G4CJ+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706709451; c=relaxed/simple; bh=nLvzwb6WYwRoyrFoBK7xr3Ig0dOYx8JY28+OYqJ4wAE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=aJv8ZnVc4xjA1ydXvNJtIygLXyT6pgHC7IobtQ35weA7bl8tUSSXjZrMJisvYGTmNFygTObgF11zOc6F/heZs0tRx8Z9NWA6xc86pSo4zzlGeP16orqJi0YXRppQNs+ReVDD7s+PXPwBO80AeyGxw6QrHl58fvwTCsgmT8Pr/f8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JMJM9ktc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 482A5C433C7; Wed, 31 Jan 2024 13:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706709451; bh=nLvzwb6WYwRoyrFoBK7xr3Ig0dOYx8JY28+OYqJ4wAE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=JMJM9ktcnrmUtDHOzMgMydX0TzI+TQgzOdnVQZlAwuF7himMX6COXvBqgs785UpQ6 O0jSx/fOukXyp+nn4TIEkZAhXE/96/L3bRebV/UC+givnL9IvqbHa9H5Ma/9ZzpqcK /15dYAELntgCU2xsAEY2xaTFs1jedkULLNmdi7f40VdAP+iS/WXdRoalRK4z3VID3t UCYeJtmrER5z/4xL1bz/BTphqkQLQvbFlQsx08bkI7oMBSnnRCTvD52ujkJIByE35N OMGqTxI01L+tvZoc41J3ghLjPobM61vnrgrXXrXw2S7fVMMNVv0t6IwFgk/ghbk8vk UpZyn7atMR6RQ== Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2cf588c4dbcso50606941fa.1; Wed, 31 Jan 2024 05:57:31 -0800 (PST) X-Gm-Message-State: AOJu0Ywiu5QCo/4CW8TcDLKr0GwNTdAZMW08w/ZN8RAtjtGCcObzXcyE +uTzk6okXyFNrvAVMDWCYBuBz2kKGrSwcyUaIerRmRWqxuC3/ugr0mP18Rqn3a91mIylHLtLqyE Db0MHpxUi0KrPNBSrL0VF8eFMD4A= X-Received: by 2002:a05:651c:19a8:b0:2ce:fa00:9b0a with SMTP id bx40-20020a05651c19a800b002cefa009b0amr1505548ljb.16.1706709449515; Wed, 31 Jan 2024 05:57:29 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240129180502.4069817-21-ardb+git@google.com> <20240129180502.4069817-24-ardb+git@google.com> <20240131134431.GJZbpOvz3Ibhg4VhCl@fat_crate.local> In-Reply-To: <20240131134431.GJZbpOvz3Ibhg4VhCl@fat_crate.local> From: Ard Biesheuvel Date: Wed, 31 Jan 2024 14:57:18 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 03/19] x86/startup_64: Drop long return to initial_code pointer To: Borislav Petkov Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Kees Cook , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" On Wed, 31 Jan 2024 at 14:45, Borislav Petkov wrote: > > On Mon, Jan 29, 2024 at 07:05:06PM +0100, Ard Biesheuvel wrote: > > From: Ard Biesheuvel > > > > Since commit 866b556efa12 ("x86/head/64: Install startup GDT"), the > > primary startup sequence sets the code segment register (CS) to __KERNEL_CS > > before calling into the startup code shared between primary and > > secondary boot. > > > > This means a simple indirect call is sufficient here. > > > > Signed-off-by: Ard Biesheuvel > > --- > > arch/x86/kernel/head_64.S | 35 ++------------------ > > 1 file changed, 3 insertions(+), 32 deletions(-) > > > > diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S > > index d4918d03efb4..4017a49d7b76 100644 > > --- a/arch/x86/kernel/head_64.S > > +++ b/arch/x86/kernel/head_64.S > > @@ -428,39 +428,10 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) > > movq %r15, %rdi > > > > .Ljump_to_C_code: > > - /* > > - * Jump to run C code and to be on a real kernel address. > > - * Since we are running on identity-mapped space we have to jump > > - * to the full 64bit address, this is only possible as indirect > > - * jump. In addition we need to ensure %cs is set so we make this > > - * a far return. > > - * > > - * Note: do not change to far jump indirect with 64bit offset. > > - * > > - * AMD does not support far jump indirect with 64bit offset. > > - * AMD64 Architecture Programmer's Manual, Volume 3: states only > > - * JMP FAR mem16:16 FF /5 Far jump indirect, > > - * with the target specified by a far pointer in memory. > > - * JMP FAR mem16:32 FF /5 Far jump indirect, > > - * with the target specified by a far pointer in memory. > > - * > > - * Intel64 does support 64bit offset. > > - * Software Developer Manual Vol 2: states: > > - * FF /5 JMP m16:16 Jump far, absolute indirect, > > - * address given in m16:16 > > - * FF /5 JMP m16:32 Jump far, absolute indirect, > > - * address given in m16:32. > > - * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect, > > - * address given in m16:64. > > - */ > > - pushq $.Lafter_lret # put return address on stack for unwinder > > xorl %ebp, %ebp # clear frame pointer > > - movq initial_code(%rip), %rax > > - pushq $__KERNEL_CS # set correct cs > > - pushq %rax # target address in negative space > > - lretq > > -.Lafter_lret: > > - ANNOTATE_NOENDBR > > + ANNOTATE_RETPOLINE_SAFE > > + callq *initial_code(%rip) > > + int3 > > SYM_CODE_END(secondary_startup_64) > > > > #include "verify_cpu.S" > > objtool doesn't like it yet: > > vmlinux.o: warning: objtool: verify_cpu+0x0: stack state mismatch: cfa1=4+8 cfa2=-1+0 > > Once we've solved this, I'll take this one even now - very nice cleanup! > s/int3/RET seems to do the trick. As long as there is an instruction that follows the callq, the unwinder will see secondary_startup_64 at the base of the call stack. We never return here anyway.