From nobody Sat May 18 04:13:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1645092168; cv=none; d=zohomail.com; s=zohoarc; b=P5ouuufUniHSqEkUU2yf2GiHyy8fC0pDWrJEb4jA9P1BAl2WzrwB6rXVegJu1q01vqgrYdJ9XaidlcJDP1lAT9i2qc94azt+IoPnfMFiD3S98M7nNtOM+s9s63JIGCl2A9ZzhtnHohtU2G7RUo8/c+/CR4D2UhytprS1gJt1Cao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645092168; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NIi6RLjef3+09dE3GpyhEpwxG5eBx5zsOvhvFXwoU7c=; b=jpdwRSbUEtxgHar0lt1ykxYD+SBpn6TksvkjVeT3n5YoIdEeXikcHzo5QRAq8P2nheqSfZjbVwff/sMjQTOwoLu+qu2KgR1pklrnRIqAyBNELuSCFPZlKysl8PZpSncoLdaoOELTkwTbxo80td9wdbcBhUomxyyciM+iSw7r3hk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1645092168053573.3105319680236; Thu, 17 Feb 2022 02:02:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.274580.470092 (Exim 4.92) (envelope-from ) id 1nKdc8-0003Tw-Eq; Thu, 17 Feb 2022 10:02:16 +0000 Received: by outflank-mailman (output) from mailman id 274580.470092; Thu, 17 Feb 2022 10:02:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nKdc8-0003Tp-AA; Thu, 17 Feb 2022 10:02:16 +0000 Received: by outflank-mailman (input) for mailman id 274580; Thu, 17 Feb 2022 10:02:14 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nKdc6-0003Tj-Cx for xen-devel@lists.xenproject.org; Thu, 17 Feb 2022 10:02:14 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ab32a6cb-8fd8-11ec-b215-9bbe72dcb22c; Thu, 17 Feb 2022 11:02:10 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ab32a6cb-8fd8-11ec-b215-9bbe72dcb22c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1645092132; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GMU8LsN/3Pxq78qL9996Dptilzd5w89xVJXi9VTdYfI=; b=YxpzR8+mSemDdtYBt7arL6HzL/pNR3TCnRr1hDIJGv7E7yu7H9HwS0Gv 5YC6mvHj17LaCiZACvy/8Dk0cYadTISUUwr47nVjKRyUlaGRkQkFDxNnx H7mZrAelOLUc5ZGq+il1jAoaDiqRFtR02NUwc2NW12ZjgVgOJqWbJT0sz s=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: e3tKdMLDgMD4cmrSo3bQqbb3IOiAmvd8tP/z/S7DAulTflI0ai1izY773zlo3el5TudJqz6d/H CJx3ZdBBA0BDOKNlJlQQcYEcTiAl1Rnd4oDbRVP7espBbt10ggmQSyfffwUQO3lHwER+Q16Gl6 nns0lVWbMFDFfvAviL5kGs8AzpOs7M109sCU6IwtpMur+h1eHj6+4IjtPgJxiMOoxthZ+hnTT8 9Cyo4wOgs8bEYnZns0tcxVsZi0YkBZ4Cvt3maYHe1bOslCyzsTWi/oaFKdP1q4yZYWksNaLkvM M3LKDwacXvRdzCyz3rN2FPkF X-SBRS: 5.1 X-MesageID: 64418586 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:/POyTannM4d2Ue3RgAX1ySvo5gxDIURdPkR7XQ2eYbSJt1+Wr1Gzt xJJDTqGP6rba2KhetFwaNi29EhT75TQy95lQVZuqHo0QyMWpZLJC+rCIxarNUt+DCFioGGLT Sk6QoOdRCzhZiaE/n9BClVlxJVF/fngqoDUUYYoAQgsA180IMsdoUg7wbRh2Nc32YHR7z6l4 rseneWOYDdJ5BYsWo4kw/rrRMRH5amaVJsw5zTSVNgT1LPsvyB94KE3fMldG0DQUIhMdtNWc s6YpF2PEsE1yD92Yj+tuu6TnkTn2dc+NyDW4pZdc/DKbhSvOkXee0v0XRYRQR4/ttmHozx+4 NtLi5eUbQYjB5+PiP05bjhxOTNuMrITrdcrIVDn2SCS50jPcn+qyPRyFkAme4Yf/46bA0kXq 6ZecmpUKEne2aTmm9pXScE17ignBODtMJkSpTdLyjbBAOx9aZvCX7/L9ZlT2zJYasVmQ6qCP ppEOWQHgBLoM0ISNF48V5UFvKSDoUOubm17qwuPjP9ii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sH8XT7LvMsb09wNSdvIvpDfIU3DAbv31ZSRFFG/Fxl6 iV8sjzsiWE8Qr5OUtQ/+xoV5PhfZqxz/JICMwqTNKftWrdyQyVxeNZnOjfKlTbckWUnINgPO VbAsxD4bXLfCBHZK3BgTVQfexO/DD+ytHLudvj X-IronPort-AV: E=Sophos;i="5.88,375,1635220800"; d="scan'208";a="64418586" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2.1 6.5/70] x86/kexec: Annotate embedded data with ELF metadata Date: Thu, 17 Feb 2022 10:01:58 +0000 Message-ID: <20220217100158.22402-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220214125127.17985-1-andrew.cooper3@citrix.com> References: <20220214125127.17985-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1645092171063100001 Scanning for embedded endbranch instructions involves parsing the .text disassembly. Data in the kexec trampoline has no ELF metadata, so objdump treats it as instructions and tries to disassemble. Convert: ffff82d040396108 : ffff82d040396108: 00 00 add %al,(%rax) ffff82d04039610a: 00 00 add %al,(%rax) ffff82d04039610c: 10 00 adc %al,(%rax) ffff82d04039610e : ffff82d04039610e: 17 (bad) ... ffff82d040396118 : ... ffff82d040396120: ff (bad) ffff82d040396121: ff 00 incl (%rax) ffff82d040396123: 00 00 add %al,(%rax) ffff82d040396125: 93 xchg %eax,%ebx ffff82d040396126: cf iret ffff82d040396127: 00 ff add %bh,%bh ffff82d040396129: ff 00 incl (%rax) ffff82d04039612b: 00 00 add %al,(%rax) ffff82d04039612d: 9b fwait ffff82d04039612e: cf iret ... ffff82d040396130 : ... ffff82d0403961b6 : ffff82d0403961b6: b6 01 mov $0x1,%dh ... to: ffff82d040396108 : ffff82d040396108: 00 00 00 00 10 00 .= ..... ffff82d04039610e : ffff82d04039610e: 17 00 00 00 00 00 00 00 00 00 .= ......... ffff82d040396118 : ... ffff82d040396120: ff ff 00 00 00 93 cf 00 ff ff 00 00 00 9b cf 00 .= ............... ffff82d040396130 : ffff82d040396130: 00 00 00 00 00 00 .= ..... ffff82d040396136 : ... Most data just gains type and size metadata. The reloc_stack label is the wrong end of the data block to have a size, so move it to the lowest address and introduce .Lreloc_stack_base as a replacement. While kexec_reloc_size could gain metadata, it's use in the linker assertion (while correct) is deeply confusing to follow. Drop it entirely, using a linker symbol instead to denote the end of the trampoline. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu The remainder of the 32bit code has mode-invariant lengths, so disassembles safely as 64bit. The only differences come from 32/64bit implicit register sizes. v2.1: * New --- xen/arch/x86/include/asm/machine_kexec.h | 2 +- xen/arch/x86/machine_kexec.c | 2 +- xen/arch/x86/x86_64/kexec_reloc.S | 22 +++++++++++++++++----- xen/arch/x86/xen.lds.S | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/include/asm/machine_kexec.h b/xen/arch/x86/includ= e/asm/machine_kexec.h index ba0d469d077b..d4880818c1d9 100644 --- a/xen/arch/x86/include/asm/machine_kexec.h +++ b/xen/arch/x86/include/asm/machine_kexec.h @@ -9,7 +9,7 @@ extern void kexec_reloc(unsigned long reloc_code, unsigned = long reloc_pt, unsigned long ind_maddr, unsigned long entry_maddr, unsigned long flags); =20 -extern unsigned int kexec_reloc_size; +extern const char kexec_reloc_end[]; =20 #endif =20 diff --git a/xen/arch/x86/machine_kexec.c b/xen/arch/x86/machine_kexec.c index 08ec9fd43b1d..751a9efcaf6a 100644 --- a/xen/arch/x86/machine_kexec.c +++ b/xen/arch/x86/machine_kexec.c @@ -117,7 +117,7 @@ int machine_kexec_load(struct kexec_image *image) } =20 code_page =3D __map_domain_page(image->control_code_page); - memcpy(code_page, kexec_reloc, kexec_reloc_size); + memcpy(code_page, kexec_reloc, kexec_reloc_end - (char *)kexec_reloc); unmap_domain_page(code_page); =20 /* diff --git a/xen/arch/x86/x86_64/kexec_reloc.S b/xen/arch/x86/x86_64/kexec_= reloc.S index d488d127cfb9..05bf8810cee6 100644 --- a/xen/arch/x86/x86_64/kexec_reloc.S +++ b/xen/arch/x86/x86_64/kexec_reloc.S @@ -34,7 +34,7 @@ ENTRY(kexec_reloc) movq %rcx, %rbp =20 /* Setup stack. */ - leaq (reloc_stack - kexec_reloc)(%rdi), %rsp + leaq (.Lreloc_stack_base - kexec_reloc)(%rdi), %rsp =20 /* Load reloc page table. */ movq %rsi, %cr3 @@ -175,10 +175,16 @@ compatibility_mode_far: .long 0x00000000 /* set in call_32_bit above */ .word 0x0010 =20 + .type compatibility_mode_far, @object + .size compatibility_mode_far, . - compatibility_mode_far + compat_mode_gdt_desc: .word .Lcompat_mode_gdt_end - compat_mode_gdt -1 .quad 0x0000000000000000 /* set in call_32_bit above */ =20 + .type compat_mode_gdt_desc, @object + .size compat_mode_gdt_desc, . - compat_mode_gdt_desc + .align 8 compat_mode_gdt: .quad 0x0000000000000000 /* null = */ @@ -186,16 +192,22 @@ compat_mode_gdt: .quad 0x00cf9b000000ffff /* 0x0010 ring 0 code, compatibility = */ .Lcompat_mode_gdt_end: =20 + .type compat_mode_gdt, @object + .size compat_mode_gdt, . - compat_mode_gdt + compat_mode_idt: .word 0 /* limit */ .long 0 /* base */ =20 + .type compat_mode_idt, @object + .size compat_mode_idt, . - compat_mode_idt + /* * 16 words of stack are more than enough. */ - .fill 16,8,0 reloc_stack: + .fill 16,8,0 +.Lreloc_stack_base: =20 - .globl kexec_reloc_size -kexec_reloc_size: - .long . - kexec_reloc + .type reloc_stack, @object + .size reloc_stack, . - reloc_stack diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index c399178ac123..13fc7ee008c1 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -87,6 +87,7 @@ SECTIONS *(.text.unlikely) *(.fixup) *(.text.kexec) + kexec_reloc_end =3D .; *(.gnu.warning) _etext =3D .; /* End of text section */ } PHDR(text) =3D 0x9090 @@ -433,7 +434,7 @@ ASSERT(__2M_rwdata_end <=3D XEN_VIRT_END - XEN_VIRT_STA= RT + __XEN_VIRT_START - "Xen image overlaps stubs area") =20 #ifdef CONFIG_KEXEC -ASSERT(kexec_reloc_size - kexec_reloc <=3D PAGE_SIZE, "kexec_reloc is too = large") +ASSERT(kexec_reloc_end - kexec_reloc <=3D PAGE_SIZE, "kexec_reloc is too l= arge") #endif =20 /* The Multiboot setup paths relies on this to simplify superpage PTE crea= tion. */ --=20 2.11.0