From nobody Tue Feb 10 14:49:45 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 AE4581DFD9D for ; Fri, 22 Nov 2024 22:47:50 +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=1732315672; cv=none; b=ukVMwrkQae3CvdrsdNO/SUGd5NqWRaUx9yVlaJ8Dzq46wN7qtHcYOVfcxVbbLy43uSTpDPB7pXHoasop8b9hj6AJnMFXLCEpdvrk5fxIjK1eu1FI3PVA28NbLYRawxmVDmxN4EJUA0AVyIdt5ldA2tAAIk6IrrIh2nFG4DuFX7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732315672; c=relaxed/simple; bh=oHixD4Rd4yh/kdDo4sDeeS4XxEV56OlFc1W88/QTwrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSTxbCPXWJPYgVluiwAn4+g4RTf//Cx5B5z+OzZjWQWJ7Df7GwptL0Drc4kSclNRTu9d6igipagxpJK4M23R58htc6LI89eFine0ZYYh9wSFItKv9BTd4KZUObkV7QeSxL2h6lJNqjIeHcXth5KmJggOHEUmBRwpRpgxvxS+IXU= 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=VtJlafzs; 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="VtJlafzs" 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=qYFRgzDbimC0blaDJOJhby5s1NuEeujIYbn61y3E6GM=; b=VtJlafzsjOxL1ciibmV+zNF2mD jJmOJnM3bMCLXyECAn33h6KmC7anHGDQhnxf54de4TgaQdixwGqRfU5m08YsRuxiONe/8qUh7NQG3 UUf+PVyb72aQW/l0c2+SfQreYi3jdmOrvLfINByqdzBzoqDXCrb9ezQQ6XlXPOlUivXD+13GDPDno DAUDeMuOYkyLG9GbdoQMlSMT5ejfxUOnmqIMMFTd+qcfGhZPgqIXu4hGWsFShlV3KVLkc9IWs2F3j GCEY9Rk7VTcQu1Uvv5Nnw8Eia1VP1DQipm1DJrKCkn+W7Djc6qw15WQgeMtielY3kqspM4AAwu+IW kq/Dek2g==; 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 1tEcQs-00000000ma4-00Xq; Fri, 22 Nov 2024 22:47:22 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tEcQp-00000000iiO-0jy2; Fri, 22 Nov 2024 22:47:19 +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 Subject: [RFC PATCH v2 08/16] x86/kexec: Copy control page into place in machine_kexec_prepare() Date: Fri, 22 Nov 2024 22:38:17 +0000 Message-ID: <20241122224715.171751-9-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241122224715.171751-1-dwmw2@infradead.org> References: <20241122224715.171751-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 There's no need for this to wait until the actual machine_kexec() invocatio= n; a subsequent change will mark the control page ROX so all writes should be completed earlier. Signed-off-by: David Woodhouse --- arch/x86/kernel/machine_kexec_64.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index 123e9544506b..60632a5a2a13 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -297,6 +297,8 @@ static void load_segments(void) int machine_kexec_prepare(struct kimage *image) { void *control_page =3D page_address(image->control_code_page) + PAGE_SIZE; + unsigned long reloc_start =3D (unsigned long)__relocate_kernel_start; + unsigned long reloc_end =3D (unsigned long)__relocate_kernel_end; unsigned long start_pgtable; int result; =20 @@ -308,6 +310,8 @@ int machine_kexec_prepare(struct kimage *image) if (result) return result; =20 + __memcpy(control_page, __relocate_kernel_start, reloc_end - reloc_start); + set_memory_x((unsigned long)control_page, 1); =20 return 0; @@ -334,7 +338,6 @@ void machine_kexec(struct kimage *image) unsigned int preserve_context, unsigned int host_mem_enc_active); unsigned long reloc_start =3D (unsigned long)__relocate_kernel_start; - unsigned long reloc_end =3D (unsigned long)__relocate_kernel_end; unsigned long page_list[PAGES_NR]; unsigned int host_mem_enc_active; int save_ftrace_enabled; @@ -372,7 +375,6 @@ void machine_kexec(struct kimage *image) } =20 control_page =3D page_address(image->control_code_page) + PAGE_SIZE; - __memcpy(control_page, __relocate_kernel_start, reloc_end - reloc_start); =20 page_list[PA_CONTROL_PAGE] =3D virt_to_phys(control_page); page_list[VA_CONTROL_PAGE] =3D (unsigned long)control_page; --=20 2.47.0