From nobody Wed Dec 17 21:27:30 2025 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 14C87202C25; Fri, 6 Dec 2024 10:16:53 +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=1733480216; cv=none; b=LLHkqqlrKMaIeMgg9F4RTQltTEGC9z3yjl6ImboovVzCvrvqKzi9YOXJBJ+q4uiWGf1udC7W2UeYyVPa9tv4B5uYBWVAuE7aTns/TCa+TFfC8+V/P/ywHrRkg/rzLZwmOihcZK0VXrWt+GK2+6YzBxO9w5runyJcOHhb8UIqulI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733480216; c=relaxed/simple; bh=dKEywtT19W6eu7kEzGBl+y0v3QF37FzmZWODXdY34ms=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=GnJp2Kl0bCiuVHV/AKJtcDYLBapkJTmVaGRApKJhMnTjdNb2uANDpId9/fC9rLRGMNj8KZGvuXH77qdPzQ4s2J65iaJYw0MIUpruV4ISObrkU9TTktd7AAvsXuwxJbqR2VdZdI6lBrFO6Yxwe1MSr7UIoxizDxi87i8uAsYj8xA= 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=zoGJEjIf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Dy3NFOEF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zoGJEjIf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Dy3NFOEF" Date: Fri, 06 Dec 2024 10:16:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1733480212; 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=ImIeqHVbMbg07wQRIPOIM8PFfxXUIpFUBAQpZ6FMv6w=; b=zoGJEjIftJdTgrklUJws2QtfkbqkuGrD6gnxkOhxsd3Y+J0wHBXeVgOq8ztVP5X8qTWXp7 oUYuKzfGS7w2exMUw0oZL7K41pZAVmxxHmqKAq5AIvFS+oSBtio2ycdFitJyw0rpBPJbOe bqefkaMJWVJji3rVfvtleC2kh8ecIjsck13nBCA5L2Lo+A2a6VpoJkeLUlUnG7OSOxmOsP cWB/Uk42z7/Uhrx1AnOVWsKTThpbqcDaNjRMvf2iLTnms5+hvLLDNX2W8CH9AMlWuI8dz7 G8F0bJdx2lMuR9IciX+6QBxld3wXP2MI3fcS086Wrzhdz4/Dn2832QlQytdX1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1733480212; 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=ImIeqHVbMbg07wQRIPOIM8PFfxXUIpFUBAQpZ6FMv6w=; b=Dy3NFOEFJsyJ56YrCfVH4D2+ThSK2fTDSdJgkIyvv4xhqCrvjYDaWGvoFWatoxa7N7/ZBD qlX8cvZYt90I2lCQ== From: "tip-bot2 for David Woodhouse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/kexec: Clean up and document register use in relocate_kernel_64.S Cc: David Woodhouse , Ingo Molnar , Kai Huang , Baoquan He , Vivek Goyal , Dave Young , Eric Biederman , Ard Biesheuvel , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20241205153343.3275139-3-dwmw2@infradead.org> References: <20241205153343.3275139-3-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173348021148.412.18219123016253087754.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: quoted-printable The following commit has been merged into the x86/boot branch of tip: Commit-ID: 207bdf7f72ae8b1764de294ae59bdf5b015082bd Gitweb: https://git.kernel.org/tip/207bdf7f72ae8b1764de294ae59bdf5b0= 15082bd Author: David Woodhouse AuthorDate: Thu, 05 Dec 2024 15:05:08=20 Committer: Ingo Molnar CommitterDate: Fri, 06 Dec 2024 10:41:58 +01:00 x86/kexec: Clean up and document register use in relocate_kernel_64.S Add more comments explaining what each register contains, and save the preserve_context flag to a non-clobbered register sooner, to keep things simpler. No change in behavior intended. Signed-off-by: David Woodhouse Signed-off-by: Ingo Molnar Acked-by: Kai Huang Cc: Baoquan He Cc: Vivek Goyal Cc: Dave Young Cc: Eric Biederman Cc: Ard Biesheuvel Cc: "H. Peter Anvin" Link: https://lore.kernel.org/r/20241205153343.3275139-3-dwmw2@infradead.org --- arch/x86/kernel/relocate_kernel_64.S | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 1236f25..92478e2 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -100,6 +100,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel) movq %r10, CP_PA_SWAP_PAGE(%r11) movq %rdi, CP_PA_BACKUP_PAGES_MAP(%r11) =20 + /* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */ + movq %rcx, %r11 + /* Switch to the identity mapped page tables */ movq %r9, %cr3 =20 @@ -116,6 +119,14 @@ SYM_CODE_END(relocate_kernel) =20 SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) UNWIND_HINT_END_OF_STACK + /* + * %rdi indirection page + * %rdx start address + * %r11 preserve_context + * %r12 host_mem_enc_active + * %r13 original CR4 when relocate_kernel() was invoked + */ + /* set return address to 0 if not preserving context */ pushq $0 /* store the start address on the stack */ @@ -170,8 +181,6 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) wbinvd .Lsme_off: =20 - /* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */ - movq %rcx, %r11 call swap_pages =20 /* @@ -183,13 +192,14 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) movq %cr3, %rax movq %rax, %cr3 =20 + testq %r11, %r11 /* preserve_context */ + jnz .Lrelocate + /* * set all of the registers to known values * leave %rsp alone */ =20 - testq %r11, %r11 - jnz .Lrelocate xorl %eax, %eax xorl %ebx, %ebx xorl %ecx, %ecx