From mboxrd@z Thu Jan 1 00:00:00 1970 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 8C0A9218EB5 for ; Thu, 9 Jan 2025 14:08:32 +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=1736431714; cv=none; b=d4iF0GLhz8++qo+JNepzNwTtJPRN2olFh+lkO8uJPa+8eSJwD4rC4WyHL6BEE3TWG+XxIjv/nAykUWOHvrunxW8mEyWFM2sEbDs/Ecs8tDa0MK8FQuv9wBWYd7DRbhKdoRxNHam0+0YdiezSECt123ovAZO8Jex3/EAhqQ7Yl34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736431714; c=relaxed/simple; bh=ToWCWMVySNp3GEwJvtjStY+oRJ0oUAHzme2Otwr4ZzQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nUMuyZTRaDJ8pJky7F66yxR7TVKXHWsyC4djvwDVW29BYmzOlxwq/TdbKBkRDTrAcdZgn74KnDtB/NjRYF97U38abB+K9BRnIKJxr3RIfj460atJ50cTJcLlQrwamK4KJGANyoJF5EqJqSKdFX3Zp63MMn4aLQ2qLVCjzZ9Fv80= 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=pzgG0B5e; 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="pzgG0B5e" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:In-Reply-To:References; bh=h57faAuSzAxCss48S50xg8gyErd3bJ9VneT8C0mRQ4E=; b=pzgG0B5egMmevfyW9B7KzovKlY nDiT/uE4u35xPzfDnqp3dF+4gd8pryKZxPd/BgDCP18nxRlJSNRMp0SAaO+buL2yWH5YakeG3nIdi 0b/mB/7nLzSx27mvTezJ66rkrUzsqi7alw4rCF/qkLPJf84O+Q2AyetJEZKwsFu2gRYLvpka/QP2u UQxvQM81TOroDTE6pPVXhdn+T0jd+AH+IOhlWdGBZLNz4ZiGpUeI9opUk0Teco9Bk3ZXvDwPdADfB 3gLC8rbpHnoccsvLu/mxvoQ05la17BCQycP5orUIFyccLo5mFkgNZ0VpQq171P28vtHHzwiUXnms7 NnFJmP5Q==; 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-00000009Zhe-3Db8; Thu, 09 Jan 2025 14:08:01 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tVtCY-0000000Bx5j-1vs9; 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 0/9] x86/kexec: Fixes for tip/x86/boot Date: Thu, 9 Jan 2025 14:04:12 +0000 Message-ID: <20250109140757.2841269-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html Fix a few bugs introduced by the recent rework of the relocate_kernel() code, and one which has been there in the kjump code from the beginning. • Global read-only TLB entries made relocate_kernel() crash when writing to its own page after the %cr3 switch should have made it writeable. • The preserve_context flag was lost when invoking swap_pages on the way back, causing pages not to be swapped. • The wrong page was being used as the swap page. • The ABI for the kjump call asks the callee to put its entry address for next time at %rsp+8 before returning, but we set %rsp to the top of the available page, such that the entry address is at the start of some other page. • The relocate_kernel() function lacked Clang CFI information, but is now called via a function pointer, leading to a crash¹. • The relocate_kernel() code and data could end up being linked into the wrong place for a LTO / -ffunction-sections build. Thanks to Nathan for reporting many of the above. Also a few minor cleanups, including a comments-only patch from Rafael on the suspend-like part of kjump as a prelude to actually cleaning that up. ¹ Fixed by just adding __nocfi. Actually providing the CFI information for relocate_kernel() will need a bit more work, so let's just do the simple fix for now. v2: • Rebase • Save a whole byte on a 'movq $1, %r11' instruction. • Fix duplicated word in comment. • Avoid absolute relocations against __relocate_kernel_start David Woodhouse (7): x86/kexec: Disable global pages before writing to control page x86/kexec: Ensure preserve_context flag is set on return to kernel x86/kexec: Use correct swap page in swap_pages function x86/kexec: Fix stack and handling of re-entry point for ::preserve_context x86/kexec: Mark machine_kexec() with __nocfi x86/kexec: Cope with relocate_kernel() not being at the start of the page x86/kexec: Use typedef for relocate_kernel_fn function prototype Nathan Chancellor (1): x86/kexec: Fix location of relocate_kernel with -ffunction-sections Rafael J. Wysocki (1): kexec_core: Add and update comments regarding the KEXEC_JUMP flow arch/x86/include/asm/kexec.h | 26 ++++++++-------- arch/x86/kernel/machine_kexec_32.c | 7 +---- arch/x86/kernel/machine_kexec_64.c | 8 ++--- arch/x86/kernel/relocate_kernel_64.S | 57 ++++++++++++++++++++++++------------ arch/x86/kernel/vmlinux.lds.S | 4 +-- kernel/kexec_core.c | 23 +++++++++++---- 6 files changed, 74 insertions(+), 51 deletions(-)