From nobody Thu Dec 18 00:06:28 2025 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 74FE4219A74 for ; Thu, 9 Jan 2025 14:08:33 +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=1736431715; cv=none; b=jUDPs789A3VbLORWIf9dkNpN2FRXBlVbysRfAOaTkgkNgzUe5QyE1EYa5IaZ4llGF5sj3+QFnKsT+n5eZoHAFRzj9ulCgRkQsyybo5fmkkcVRl48H4KLDh33m9Ps6/P2DO5xo3lknCrpjzRjKYH/Yu2FbtEHD3u+JCIyFA6MPEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736431715; c=relaxed/simple; bh=lFfg/xVgGCpkMthS9+K7x/uEqbtknHfNHHBj6VuQVSw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cjd0WpwKLGTRv2Jz2GfdSIT8RX/2h3XiO68OGx5QuefSEP1tT05Bv8y7x/xd5CcRcB/3yXhQ20E58U1RX5lqeIP2mTDJF7wdEBBmijncPUFdYIG6r2uOrfU3p47X8hF+Ve3qLQr46cT9O30ssjtBBHaOqsFQdqy23U/oF0PzZIQ= 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=hlBqLaT9; 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="hlBqLaT9" 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:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description; bh=Fe3DN3ndw9ctJtc0ND815AU97XruK260fddKsjsDX6w=; b=hlBqLaT9Cgu8uFFmIH0eBCfh1P IFq6xNRdw+UbHAw6WBfhV95Rzu4M9q1ZJvwUpy4jPXYdl3IomhJvcTSvksbAStshQrDi+16j3828+ 70WWTQ4JuWeT5wRSgphebXocZ8ee+ke+KxjXYT2BEzudFGHs1V/8WzL9TZCDDenwdMfztmw0REJYU 9j4xD/Sl6eHWeaa0yfzulf8XH+xzh+4lWW/3VueWoXCyvxebchOFIcEuZOW1YubiBOBWac8x7gRP3 jHk+YCxHaVV4imH+ZMW6taepLJ1z26wnvYqAGKjRSSTaXf8SzGF6PZBRMoqy1nPY4eWCXg9yh1JHP sGefLqmw==; 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 1tVtCa-00000009Zhf-3Dct; Thu, 09 Jan 2025 14:08:02 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tVtCY-0000000Bx65-2p5c; Thu, 09 Jan 2025 14:07:58 +0000 From: David Woodhouse To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Eric Biederman , David Woodhouse , Sourabh Jain , Hari Bathini , Michael Ellerman , Thomas Zimmermann , Andrew Morton , Baoquan He , Yuntao Wang , David Kaplan , Tao Liu , "Kirill A . Shutemov" , Kai Huang , Ard Biesheuvel , Josh Poimboeuf , Breno Leitao , Wei Yang , Rong Xu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, Simon Horman , Dave Young , Peter Zijlstra , bsz@amazon.de, nathan@kernel.org Subject: [PATCH v2 3/9] x86/kexec: Use correct swap page in swap_pages function Date: Thu, 9 Jan 2025 14:04:15 +0000 Message-ID: <20250109140757.2841269-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250109140757.2841269-1-dwmw2@infradead.org> References: <20250109140757.2841269-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 The swap_pages function expects the swap page to be in %r10, but there was no documentation to that effect. Once upon a time the setup code used to load its value from a kernel virtual address and save it to an address which is accessible in the identity-mapped page tables, and *happened* to use %r10 to do so, with no comment that it was left there on *purpose* instead of just being a scratch register. Once that was no longer necessary, %r10 just holds whatever the kernel happened to leave in it. Now that the original value passed by the kernel is accessible via %rip-relative addressing, load directly from there instead of using %r10 for it. But document the other parameters that the swap_pages function *does* expect in registers. Fixes: b3adabae8a96 ("x86/kexec: Drop page_list argument from relocate_kern= el()") Signed-off-by: David Woodhouse --- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 6fce4b459652..3ca3bf6b3f49 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -264,6 +264,10 @@ SYM_CODE_END(virtual_mapped) /* Do the copies */ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) UNWIND_HINT_END_OF_STACK + /* + * %rdi indirection page + * %r11 preserve_context + */ movq %rdi, %rcx /* Put the indirection_page in %rcx */ xorl %edi, %edi xorl %esi, %esi @@ -302,7 +306,7 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) jz .Lnoswap =20 /* copy source page to swap page */ - movq %r10, %rdi + movq kexec_pa_swap_page(%rip), %rdi movl $512, %ecx rep ; movsq =20 @@ -314,7 +318,7 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) =20 /* copy swap page to destination page */ movq %rdx, %rdi - movq %r10, %rsi + movq kexec_pa_swap_page(%rip), %rsi .Lnoswap: movl $512, %ecx rep ; movsq --=20 2.47.0