From nobody Mon Feb 9 17:23:03 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B8449200B95 for ; Wed, 27 Nov 2024 19:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732734247; cv=none; b=VknseQFJWE9yxmTKxOtcq+J5g4g5lFU+DxlmQz3hJkLLXw1Enlouy2vgNZY6lEV5RdGSkc8iqNaN1TZD+epAi1SD4dr/Skh7Rn5g9/j0i0wAK021OGUUicpcMEAewV3sifWu20VJxxHQ4krEPI4iLhlv6sEP6gkkmYNjr0v3/fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732734247; c=relaxed/simple; bh=YEYgduFbx3hxPviKlbaHo3vgA2xGogrBHXSzn5W5fyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W1vU183fRc/WeJ4s51P+5nNvzP4Ou6faBqv+Bug+kB+Xl3U9TwDws7iJ6J61fn0goYk1MqmkDDdpWlq+9x0B8gha0G6MM1XgesEJUecpMWXcfKS3w5eDI+OxlpInoN2JOlMsIk7ltHMyZQVcTF+6mPbo1Kypcf+CtwHmbTlJ4xs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=oozLZbru; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="oozLZbru" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=G8KdxSUjA1BoxOPlX8D0AVdJHTOMU4u9sPbtmHj+Y10=; b=oozLZbrufgQLvjMvST9Tk0OoKX F2Y6DFOreM8CdHo3b6KM9q3DvDFNCM6NHxvnGFFWrqxJkP6gmQdl9RVPP4JY4rtmegp8a6X7Dmwde Wse0mPybjCz99WPJYJsHyT928/VaWmqTtEO4IDpkBvwhlxTm3i9VI3cfl3nxODEMyq3vv9DhAt0hx ncH0P1AWEumIdUc1qCf9y65HRZmR4q+K4TW4aoILXPp/JTL/6pnJ9XJx4NLmayRv+Y5+cn8/8SFMP pqkxc+peG8tIhv3iGcx92fctxfId6z6jX1pvuYdVqRkuOMiuY4VK7IdLGG7V5sf7kBGXX4OeVfoXZ zG73p7qg==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGNKF-00000001Suc-17d4; Wed, 27 Nov 2024 19:03:47 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGNKD-00000000BiE-3dWr; Wed, 27 Nov 2024 19:03:45 +0000 From: David Woodhouse To: kexec@lists.infradead.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , "Kirill A. Shutemov" , Kai Huang , Nikolay Borisov , linux-kernel@vger.kernel.org, Simon Horman , Dave Young , Peter Zijlstra , jpoimboe@kernel.org, bsz@amazon.de Subject: [RFC PATCH v4 02/20] x86/kexec: Clean up and document register use in relocate_kernel_64.S Date: Wed, 27 Nov 2024 19:00:16 +0000 Message-ID: <20241127190343.44916-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127190343.44916-1-dwmw2@infradead.org> References: <20241127190343.44916-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse Add more comments explaining what each register contains, and save the preserve_context flag to a non-clobbered register sooner, to keep things simpler. Signed-off-by: David Woodhouse Acked-by: Kai Huang --- 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 1236f25fc8d1..92478e2e254f 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 --=20 2.47.0