From nobody Tue Oct 7 18:58:54 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 28541203704 for ; Wed, 27 Nov 2024 19:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732734251; cv=none; b=mz7WTdBCUyP7O8sSrqTbrv5fwAwVGAEjOGe0xIr3xOqbKJF9TLIgQkfiP+cqotOsoKHDR2L8j0Kpy+d4biVKRje8b0oC4jF7bCAtps8pugXMSbZaJ1Bh0msFBBL+BvJndRFBID+PpN6FrsooxRFVg7mrmZTTl43OvSjO6TQZv+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732734251; c=relaxed/simple; bh=MjVsLckdiCBNZq9iVaa/SPkl4U5dQcUJNFlUyW9YUYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FsyM8fvcB5fdqvLRTFHrv4OssNpBzzrqOLnj0UcM/C2UBjl7nOKxmCKVKyw4SYbhmuYtwKy6JbjlkOtcmQBIvnnD79k6vBP6VnlHvP+M1RSrweZHW8FHnxmP7+53UqJrxByH8a6fllHoBvUvREhYv+C6TVrfx0ZJUg2BFK2c0EE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=KWl4g9w6; arc=none smtp.client-ip=90.155.50.34 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=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KWl4g9w6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=B+cdGMrXlLMQ5gF/V+Me3rwZRfmBgngjB82bVhN99Q4=; b=KWl4g9w6uuVvVNBdyAo0iQzqrh A5Tg6tGQ1WazTsXKLaVaCAZK5fn790dTl88FZD53ZBp6NYqXaa1CNwSWi6D4hMCk5chl71FsgVbBz NhIvqpsVhLM0PPIqIqE68HbwzYi1h+X7wlvm3U5JFZi2ZQW4cgWGn110ssZvflrb8fX25GA91DDz8 bJTGaPpzlA/L3ataInSZl+Ik8/R5VSnCMfQzIw21tKcbwazADTRPYbbBTtnaSj1gNqTQIbmRnbkdE AlOCtVecMo/NL9BG05CGVWNMeEW9JNHObE19bnch2kX0u3RfN6wbOtCPcQyRCezmcEfJVrlawkz7G etN4e9kw==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGNKD-00000001cWE-1s5a; Wed, 27 Nov 2024 19:03:46 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGNKE-00000000Biy-205D; Wed, 27 Nov 2024 19:03:46 +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 13/20] x86/kexec: Clean up register usage in relocate_kernel() Date: Wed, 27 Nov 2024 19:00:27 +0000 Message-ID: <20241127190343.44916-14-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 casper.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse The memory encryption flag is passed in %r8 because that's where the calling convention puts it. Instead of moving it to %r12 and then using %r8 for other things, just leave it in %r8 and use other registers instead. Signed-off-by: David Woodhouse --- arch/x86/kernel/relocate_kernel_64.S | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 288dfc08c63d..b24198eb1fe9 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -79,24 +79,18 @@ SYM_CODE_START_NOALIGN(relocate_kernel) movq %cr4, %r13 movq %r13, saved_cr4(%rip) =20 - /* Save SME active flag */ - movq %r8, %r12 - /* save indirection list for jumping back */ movq %rdi, pa_backup_pages_map(%rip) =20 /* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */ movq %rcx, %r11 =20 - /* Physical address of control page */ - movq %rsi, %r8 - /* setup a new stack at the end of the physical control page */ - lea PAGE_SIZE(%r8), %rsp + lea PAGE_SIZE(%rsi), %rsp =20 /* jump to identity mapped page */ - addq $(identity_mapped - relocate_kernel), %r8 - pushq %r8 + addq $(identity_mapped - relocate_kernel), %rsi + pushq %rsi ANNOTATE_UNRET_SAFE ret int3 @@ -107,8 +101,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) /* * %rdi indirection page * %rdx start address + * %r8 host_mem_enc_active + * %r9 page table page * %r11 preserve_context - * %r12 host_mem_enc_active * %r13 original CR4 when relocate_kernel() was invoked */ =20 @@ -161,7 +156,7 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) * entries that will conflict with the now unencrypted memory * used by kexec. Flush the caches before copying the kernel. */ - testq %r12, %r12 + testq %r8, %r8 jz .Lsme_off wbinvd .Lsme_off: --=20 2.47.0