From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896063; cv=none; d=zohomail.com; s=zohoarc; b=JqZAbPebKvDwPoLmvYvQMYfJlmVt3utFf6CwKBNy7EECgGRrJMJZkSKoGcoU4GEkvfYy3rW1wj/pNlA54DNFIFtwfk3o6nhI7q5XaIK44QdFTGl5uzjPINfeZ7VJQYtWRzl4BQhwjjKrBZvv7H14Qd0PgxBq/m5ZWoJYWNIUBeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896063; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ktEbN5Mta6+B/qu1SQOa+3juoPGypkurj1Nhhhu5ghA=; b=dbkzZmQwlKgfSBrPGnri+XI+kvFRsJgEJrKqC3vhb6JDgYE8cN+nJ/B5qGureEhErJLHJkhwGKrzyKhmgwjVJJt2ui1YWB/iFlGRnrOA2089oELAewfLwfKH4oIGS851AWqAoYUdVkEORtHSh0HYF/h+TVEkSVc1uw9Z72x/w1M= 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 172889606391548.19722235184838; Mon, 14 Oct 2024 01:54:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818520.1231835 (Exim 4.92) (envelope-from ) id 1t0Gpo-00007G-Rj; Mon, 14 Oct 2024 08:53:48 +0000 Received: by outflank-mailman (output) from mailman id 818520.1231835; Mon, 14 Oct 2024 08:53:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpo-000076-NC; Mon, 14 Oct 2024 08:53:48 +0000 Received: by outflank-mailman (input) for mailman id 818520; Mon, 14 Oct 2024 08:53:47 +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 1t0Gpn-00086D-Ev for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:47 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d1c56b41-8a09-11ef-99a2-01e77a169b0f; Mon, 14 Oct 2024 10:53:45 +0200 (CEST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9a156513a1so63005766b.0 for ; Mon, 14 Oct 2024 01:53:45 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:43 -0700 (PDT) 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: d1c56b41-8a09-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896024; x=1729500824; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ktEbN5Mta6+B/qu1SQOa+3juoPGypkurj1Nhhhu5ghA=; b=Jv2+rt37jOMGVvGxyvVG0X665Z6fNROEoeVuG1xQh7sBi02Lze6CFH16U4XR1spFFw HUD7bVVs7CegHmDQsjxpK96by0dHxzFi9J7T6LB2DefIN/noHlRXZ++d0yhphfNW+m/2 dU3E01KRsciNMZ1ARwTkRCgww2eTPtitmovC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896024; x=1729500824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ktEbN5Mta6+B/qu1SQOa+3juoPGypkurj1Nhhhu5ghA=; b=mlcnRrSNpkU31jXXIp2rbkxqD/jQKsi51N7qT4wYSPqTlanrEawQROGCoxzyiyPtw6 h2RaWILp6lBt68VX5fWK1S6Ng9K7rUmtE5iZ3bb1Vj/QHLigzsSKqkXo/zkDaS3BY1T8 aCyQ42fUtOzolNT8iV5xWarHTjhT7Batc7L4bHuR1KP+ZJ2J44CnKmmEMDKHsqP4sSbS pSYpbXOTaAcy4WDpEG+xojCQiU62hyvmwzGE1A/rrBSWHXHn572KbYVAExAdegro+sJC qifNO3Y8OxA9PyBC3hSVQFLGd6W10/HeHvww1j/ZDPdDMizPAvxPX24weCIvuzRnnDBq BjaQ== X-Gm-Message-State: AOJu0YzF2YTHXoGPyArEtwlBPO4lgdspaCNDcrePUOUlf5nZqBZNAj/R hvgG/Lr1Ggo42glmpHaInO2zWpg4qHwfwznHQUHZeEZTof8Fr80uYQCdJFeZF7WmU9EAM0OT95n X X-Google-Smtp-Source: AGHT+IFEapbh2BjXX94GQenUWVcxXEC7ASsbiIPQtMGGSW4YUH3/bf6ShK4H3b+R4msB2bQ2SawLyQ== X-Received: by 2002:a17:907:3fa5:b0:a99:45c5:339 with SMTP id a640c23a62f3a-a99b93c8d07mr856330466b.32.1728896024368; Mon, 14 Oct 2024 01:53:44 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 1/6] x86/boot: Prep work for 32bit object changes Date: Mon, 14 Oct 2024 09:53:27 +0100 Message-Id: <20241014085332.3254546-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896065460116600 Content-Type: text/plain; charset="utf-8" Broken out of the subsequent patch for clarity. * Rename head-bin-objs to obj32 * Use a .32.o suffix to distinguish these objects * Factor out $(LD32) No functional change. Signed-off-by: Frediano Ziglio Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- xen/arch/x86/boot/Makefile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile index ff0f965876..1199291d2b 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,15 +1,16 @@ obj-bin-y +=3D head.o =20 -head-bin-objs :=3D cmdline.o reloc.o +obj32 :=3D cmdline.32.o +obj32 +=3D reloc.32.o =20 -nocov-y +=3D $(head-bin-objs) -noubsan-y +=3D $(head-bin-objs) -targets +=3D $(head-bin-objs) +nocov-y +=3D $(obj32) +noubsan-y +=3D $(obj32) +targets +=3D $(obj32) =20 -head-bin-objs :=3D $(addprefix $(obj)/,$(head-bin-objs)) +obj32 :=3D $(addprefix $(obj)/,$(obj32)) =20 $(obj)/head.o: AFLAGS-y +=3D -Wa$(comma)-I$(obj) -$(obj)/head.o: $(head-bin-objs:.o=3D.bin) +$(obj)/head.o: $(obj32:.32.o=3D.bin) =20 CFLAGS_x86_32 :=3D $(subst -m64,-m32 -march=3Di686,$(XEN_TREEWIDE_CFLAGS)) $(call cc-options-add,CFLAGS_x86_32,CC,$(EMBEDDED_EXTRA_CFLAGS)) @@ -18,16 +19,20 @@ CFLAGS_x86_32 +=3D -nostdinc -include $(filter %/includ= e/xen/config.h,$(XEN_CFLAGS CFLAGS_x86_32 +=3D $(filter -I% -O%,$(XEN_CFLAGS)) -D__XEN__ =20 # override for 32bit binaries -$(head-bin-objs): CFLAGS_stack_boundary :=3D -$(head-bin-objs): XEN_CFLAGS :=3D $(CFLAGS_x86_32) -fpic +$(obj32): CFLAGS_stack_boundary :=3D +$(obj32): XEN_CFLAGS :=3D $(CFLAGS_x86_32) -fpic + +$(obj)/%.32.o: $(src)/%.c FORCE + $(call if_changed_rule,cc_o_c) =20 LDFLAGS_DIRECT-$(call ld-option,--warn-rwx-segments) :=3D --no-warn-rwx-se= gments LDFLAGS_DIRECT +=3D $(LDFLAGS_DIRECT-y) +LD32 :=3D $(LD) $(subst x86_64,i386,$(LDFLAGS_DIRECT)) =20 %.bin: %.lnk $(OBJCOPY) -j .text -O binary $< $@ =20 -%.lnk: %.o $(src)/build32.lds - $(LD) $(subst x86_64,i386,$(LDFLAGS_DIRECT)) -N -T $(filter %.lds,$^) -o = $@ $< +%.lnk: %.32.o $(src)/build32.lds + $(LD32) -N -T $(filter %.lds,$^) -o $@ $< =20 clean-files :=3D *.lnk *.bin --=20 2.34.1 From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896070; cv=none; d=zohomail.com; s=zohoarc; b=VVAGEnEzhH8zCUxxqgFHrWTeoZBMsHa/+dSmK3eRYnejI5CpRqaXKl1TRLOcpbuD2ieDc2TWQL4d5/aqSgcDEByeaumEOc/AohPScCfVqs1UVFELQqVLjG5lZgSk2tG/hE8u5oe7LUnGZHA5Oz9pkE6pxf9FM8uLPWqXfmtMhO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896070; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uF49wRium9i4EoXLYTW2SLTmEeikurwbqD9tKvn/ty4=; b=defmFrOUBR8zYxweBCoY4Xy1SA18oVExw0O1KJVNQuUtgayl8Nl8x3q0y8Jyi6juWyKqQ7wjo1eegJzMUWC58lV/HYKrlGJgQhOhAPhuKI2NY1OB/cmqSus7Ll/mVkEbfFzRGS7mniz9tfYILhsy1vLiz+bFwWYgtMBeOgHxnms= 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 1728896070190595.6777331989538; Mon, 14 Oct 2024 01:54:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818519.1231819 (Exim 4.92) (envelope-from ) id 1t0Gpn-00089d-LS; Mon, 14 Oct 2024 08:53:47 +0000 Received: by outflank-mailman (output) from mailman id 818519.1231819; Mon, 14 Oct 2024 08:53:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpn-000896-FM; Mon, 14 Oct 2024 08:53:47 +0000 Received: by outflank-mailman (input) for mailman id 818519; Mon, 14 Oct 2024 08:53:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpm-000862-Vr for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:47 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d27c7779-8a09-11ef-a0be-8be0dac302b0; Mon, 14 Oct 2024 10:53:46 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a99eb8b607aso227188766b.2 for ; Mon, 14 Oct 2024 01:53:46 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:44 -0700 (PDT) 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: d27c7779-8a09-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896025; x=1729500825; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uF49wRium9i4EoXLYTW2SLTmEeikurwbqD9tKvn/ty4=; b=COvIKQ+KWp3XB3Fq0Qf/jwzqqX/tNqqrruZT/EMz/FU4Xnrb5R1/rsUah57TnTx87U mfgvrLr+5KuHNvuGuA1MOvV+GkI+D2h/IRLM/WlyWj1vmXQ/ACqHHqCJZX5FBirCAuEy xRGDpuPmJ4QFnWX6GhEXAen8W3HvVhCnlkNT8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896025; x=1729500825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uF49wRium9i4EoXLYTW2SLTmEeikurwbqD9tKvn/ty4=; b=nmEDRPH8dc3TW9z4fcM0p8Q1oAhAIVGoYkmGQA+rJtKibt8vosv+YtbIwwA/CGAyL6 EnmuA/okBdt4LeELXTeMdHqf3a/wHHqHshG/KiF9b2n0VFPZIJYrB9cIf0kCogiWIoH7 b9NCfkb6Hp5BGRBBABiaIZSiNaSBxcHy/K2VjhPbv2sH9dDkO+qg9BOCZ9lxArFCdlqj 3V4Iu2DsPwn7T6v5Uxs3VKrswtSnFVtP0X+VhkX/x0jcMKmG6rn1h0PreCq0Lqm3fpH8 Y8EmKdyEV25+nenqBlEPT0bpggSncPrMxtXPuHDcJ23CCfd1nAeh7+VBk870PMBHzPk4 4P2w== X-Gm-Message-State: AOJu0Ywv4FCuwXjXF30zQwS7+1nVXg04mGN8rIBJ4/Km6TY+5EUJRC2E M+Ek9SIGH861C+RZBws2JjLQXxpNNWAWpO9yrtH2Gmwmp4Nu2PHKsGk9M3xJdBqSilHsFskc1pv h X-Google-Smtp-Source: AGHT+IH5ZbWN//oAAR1E4EBGs18FbAmIUsa7vCFIn2id5C5jlMOVBB9J9wqwvM57wwc+bXFYmWcktg== X-Received: by 2002:a17:907:84d:b0:a99:e939:d69e with SMTP id a640c23a62f3a-a99e939d95bmr684155466b.51.1728896025231; Mon, 14 Oct 2024 01:53:45 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall , Stefano Stabellini Subject: [PATCH v4 2/6] x86/boot: create a C bundle for 32 bit boot code and use it Date: Mon, 14 Oct 2024 09:53:28 +0100 Message-Id: <20241014085332.3254546-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896071569116600 Content-Type: text/plain; charset="utf-8" The current method to include 32 bit C boot code is: - compile each function we want to use into a separate object file; - each function is compiled with -fpic option; - convert these object files to binary files. This operation removes GOP which we don't want in the executable; - a small assembly part in each file add the entry point; - code can't have external references, all possible variables are passed by value or pointer; - include these binary files in head.S. There are currently some limitations: - code is compiled separately, it's not possible to share a function (like memcpy) between different functions to use; - although code is compiled with -fpic there's no certainty there are no relocations, specifically data ones. This can lead into hard to find bugs; - it's hard to add a simple function; - having to pass external variables makes hard to do multiple things otherwise functions would require a lot of parameters so code would have to be split into multiple functions which is not easy. Current change extends the current process: - all object files are linked together before getting converted making possible to share code between the function we want to call; - a single object file is generated with all functions to use and exported symbols to easily call; - variables to use are declared in linker script and easily used inside C code. Declaring them manually could be annoying but makes also easier to check them. Using external pointers can be still an issue if they are not fixed. If an external symbol is not declared this gives a link error. Some details of the implementation: - C code is compiled with -fpic flags (as before); - object files from C code are linked together; - the single bundled object file is linked with 2 slightly different script files to generate 2 bundled object files; - the 2 bundled object files are converted to binary removing the need for global offset tables; - a Python script is used to generate assembly source from the 2 binaries; - the single assembly file is compiled to generate final bundled object file; - to detect possible unwanted relocation in data/code code is generated with different addresses. This is enforced starting .text section at different positions and adding a fixed "gap" at the beginning. This makes sure code and data is position independent; - to detect used symbols in data/code symbols are placed in .text section at different offsets (based on the line in the linker script). This is needed as potentially a reference to a symbol is converted to a reference to the containing section so multiple symbols could be converted to reference to same symbol (section name) and we need to distinguish them; - --orphan-handling=3Derror option to linker is used to make sure we account for all possible sections from C code; Current limitations: - the main one is the lack of support for 64 bit code. It would make sure that even the code used for 64 bit (at the moment EFI code) is code and data position independent. We cannot assume that code that came from code compiled for 32 bit and compiled for 64 bit is code and data position independent, different compiler options lead to different code/data. Signed-off-by: Frediano Ziglio --- Changes since v2: - removed W^X limitation, allowing data; - added some comments to python script; - added extension to python script; - added header to generated assembly code from python script; - added starting symbol to generated assembly code from python script to make disassembly more clear; - other minor style changes to python script. --- xen/arch/x86/boot/.gitignore | 5 +- xen/arch/x86/boot/Makefile | 38 +++- .../x86/boot/{build32.lds =3D> build32.lds.S} | 35 ++- xen/arch/x86/boot/cmdline.c | 12 - xen/arch/x86/boot/head.S | 12 - xen/arch/x86/boot/reloc.c | 14 -- xen/tools/combine_two_binaries.py | 207 ++++++++++++++++++ 7 files changed, 268 insertions(+), 55 deletions(-) rename xen/arch/x86/boot/{build32.lds =3D> build32.lds.S} (70%) create mode 100755 xen/tools/combine_two_binaries.py diff --git a/xen/arch/x86/boot/.gitignore b/xen/arch/x86/boot/.gitignore index a379db7988..ebad650e5c 100644 --- a/xen/arch/x86/boot/.gitignore +++ b/xen/arch/x86/boot/.gitignore @@ -1,3 +1,4 @@ /mkelf32 -/*.bin -/*.lnk +/build32.*.lds +/built_in_32.*.bin +/built_in_32.*.map diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile index 1199291d2b..23ad274c89 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,4 +1,5 @@ obj-bin-y +=3D head.o +obj-bin-y +=3D built_in_32.o =20 obj32 :=3D cmdline.32.o obj32 +=3D reloc.32.o @@ -9,9 +10,6 @@ targets +=3D $(obj32) =20 obj32 :=3D $(addprefix $(obj)/,$(obj32)) =20 -$(obj)/head.o: AFLAGS-y +=3D -Wa$(comma)-I$(obj) -$(obj)/head.o: $(obj32:.32.o=3D.bin) - CFLAGS_x86_32 :=3D $(subst -m64,-m32 -march=3Di686,$(XEN_TREEWIDE_CFLAGS)) $(call cc-options-add,CFLAGS_x86_32,CC,$(EMBEDDED_EXTRA_CFLAGS)) CFLAGS_x86_32 +=3D -Werror -fno-builtin -g0 -msoft-float -mregparm=3D3 @@ -25,14 +23,34 @@ $(obj32): XEN_CFLAGS :=3D $(CFLAGS_x86_32) -fpic $(obj)/%.32.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) =20 +orphan-handling-$(call ld-option,--orphan-handling=3Derror) :=3D --orphan-= handling=3Derror LDFLAGS_DIRECT-$(call ld-option,--warn-rwx-segments) :=3D --no-warn-rwx-se= gments LDFLAGS_DIRECT +=3D $(LDFLAGS_DIRECT-y) LD32 :=3D $(LD) $(subst x86_64,i386,$(LDFLAGS_DIRECT)) =20 -%.bin: %.lnk - $(OBJCOPY) -j .text -O binary $< $@ - -%.lnk: %.32.o $(src)/build32.lds - $(LD32) -N -T $(filter %.lds,$^) -o $@ $< - -clean-files :=3D *.lnk *.bin +$(obj)/build32.final.lds: AFLAGS-y +=3D -DFINAL +$(obj)/build32.other.lds $(obj)/build32.final.lds: $(src)/build32.lds.S FO= RCE + $(call if_changed_dep,cpp_lds_S) + +# link all 32bit objects together +$(obj)/built_in_32.tmp.o: $(obj32) + $(LD32) -r -o $@ $^ + +$(obj)/built_in_32.%.bin: $(obj)/build32.%.lds $(obj)/built_in_32.tmp.o +## link bundle with a given layout + $(LD32) $(orphan-handling-y) -N -T $< -Map $(obj)/built_in_32.$(*F).map -= o $(obj)/built_in_32.$(*F).o $(obj)/built_in_32.tmp.o +## extract binaries from object + $(OBJCOPY) -j .text -O binary $(obj)/built_in_32.$(*F).o $@ + rm -f $(obj)/built_in_32.$(*F).o + +# generate final object file combining and checking above binaries +$(obj)/built_in_32.S: $(obj)/built_in_32.other.bin $(obj)/built_in_32.fina= l.bin + $(PYTHON) $(srctree)/tools/combine_two_binaries.py \ + --script $(obj)/build32.final.lds \ + --bin1 $(obj)/built_in_32.other.bin \ + --bin2 $(obj)/built_in_32.final.bin \ + --map $(obj)/built_in_32.final.map \ + --exports cmdline_parse_early,reloc \ + --output $@ + +clean-files :=3D built_in_32.*.bin built_in_32.*.map build32.*.lds diff --git a/xen/arch/x86/boot/build32.lds b/xen/arch/x86/boot/build32.lds.S similarity index 70% rename from xen/arch/x86/boot/build32.lds rename to xen/arch/x86/boot/build32.lds.S index 56edaa727b..50c167aef0 100644 --- a/xen/arch/x86/boot/build32.lds +++ b/xen/arch/x86/boot/build32.lds.S @@ -15,22 +15,47 @@ * with this program. If not, see . */ =20 -ENTRY(_start) +#ifdef FINAL +# define GAP 0 +# define MULT 0 +# define TEXT_START +#else +# define GAP 0x010200 +# define MULT 1 +# define TEXT_START 0x408020 +#endif +# define DECLARE_IMPORT(name) name =3D . + (__LINE__ * MULT) + +ENTRY(dummy_start) =20 SECTIONS { /* Merge code and data into one section. */ - .text : { + .text TEXT_START : { + /* Silence linker warning, we are not going to use it */ + dummy_start =3D .; + + /* Declare below any symbol name needed. + * Each symbol should be on its own line. + * It looks like a tedious work but we make sure the things we use. + * Potentially they should be all variables. */ + DECLARE_IMPORT(__base_relocs_start); + DECLARE_IMPORT(__base_relocs_end); + . =3D . + GAP; *(.text) *(.text.*) - *(.data) - *(.data.*) *(.rodata) *(.rodata.*) + *(.data) + *(.data.*) *(.bss) *(.bss.*) } - + /DISCARD/ : { + *(.comment) + *(.comment.*) + *(.note.*) + } /* Dynamic linkage sections. Collected simply so we can check they're e= mpty. */ .got : { *(.got) diff --git a/xen/arch/x86/boot/cmdline.c b/xen/arch/x86/boot/cmdline.c index fc9241ede9..196c580e91 100644 --- a/xen/arch/x86/boot/cmdline.c +++ b/xen/arch/x86/boot/cmdline.c @@ -18,18 +18,6 @@ * Linux kernel source (linux/lib/string.c). */ =20 -/* - * This entry point is entered from xen/arch/x86/boot/head.S with: - * - %eax =3D &cmdline, - * - %edx =3D &early_boot_opts. - */ -asm ( - " .text \n" - " .globl _start \n" - "_start: \n" - " jmp cmdline_parse_early \n" - ); - #include #include #include diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index c4de1dfab5..e0776e3896 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -759,18 +759,6 @@ trampoline_setup: /* Jump into the relocated trampoline. */ lret =20 - /* - * cmdline and reloc are written in C, and linked to be 32bit PIC = with - * entrypoints at 0 and using the fastcall convention. - */ -FUNC_LOCAL(cmdline_parse_early) - .incbin "cmdline.bin" -END(cmdline_parse_early) - -FUNC_LOCAL(reloc) - .incbin "reloc.bin" -END(reloc) - ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 8c58affcd9..94b078d7b1 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -12,20 +12,6 @@ * Daniel Kiper */ =20 -/* - * This entry point is entered from xen/arch/x86/boot/head.S with: - * - %eax =3D MAGIC, - * - %edx =3D INFORMATION_ADDRESS, - * - %ecx =3D TOPMOST_LOW_MEMORY_STACK_ADDRESS. - * - 0x04(%esp) =3D BOOT_VIDEO_INFO_ADDRESS. - */ -asm ( - " .text \n" - " .globl _start \n" - "_start: \n" - " jmp reloc \n" - ); - #include #include #include diff --git a/xen/tools/combine_two_binaries.py b/xen/tools/combine_two_bina= ries.py new file mode 100755 index 0000000000..138c59287e --- /dev/null +++ b/xen/tools/combine_two_binaries.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python3 + +from __future__ import print_function +import argparse +import re +import struct +import sys + +parser =3D argparse.ArgumentParser(description=3D'Generate assembly file t= o merge into other code.') +parser.add_argument('--script', dest=3D'script', + required=3DTrue, + help=3D'Linker script for extracting symbols') +parser.add_argument('--bin1', dest=3D'bin1', + required=3DTrue, + help=3D'First binary') +parser.add_argument('--bin2', dest=3D'bin2', + required=3DTrue, + help=3D'Second binary') +parser.add_argument('--output', dest=3D'output', + help=3D'Output file') +parser.add_argument('--map', dest=3D'mapfile', + help=3D'Map file to read for symbols to export') +parser.add_argument('--exports', dest=3D'exports', + help=3D'Symbols to export') +parser.add_argument('--section-header', dest=3D'section_header', + default=3D'.section .init.text, "ax", @progbits', + help=3D'Section header declaration') +parser.add_argument('-v', '--verbose', + action=3D'store_true') +args =3D parser.parse_args() + +gap =3D 0x010200 +text_diff =3D 0x408020 + +# Parse linker script for external symbols to use. +# Next regex matches expanded DECLARE_IMPORT lines in linker script. +symbol_re =3D re.compile(r'\s+(\S+)\s*=3D\s*\.\s*\+\s*\((\d+)\s*\*\s*0\s*\= )\s*;') +symbols =3D {} +lines =3D {} +for line in open(args.script): + m =3D symbol_re.match(line) + if not m: + continue + (name, line_num) =3D (m.group(1), int(m.group(2))) + if line_num =3D=3D 0: + raise Exception("Invalid line number found:\n\t" + line) + if line_num in symbols: + raise Exception("Symbol with this line already present:\n\t" + lin= e) + if name in lines: + raise Exception("Symbol with this name already present:\n\t" + nam= e) + symbols[line_num] =3D name + lines[name] =3D line_num + +exports =3D [] +if args.exports is not None: + exports =3D dict([(name, None) for name in args.exports.split(',')]) + +# Parse mapfile, look for ther symbols we want to export. +if args.mapfile is not None: + symbol_re =3D re.compile(r'\s{15,}0x([0-9a-f]+)\s+(\S+)\n') + for line in open(args.mapfile): + m =3D symbol_re.match(line) + if not m or m.group(2) not in exports: + continue + addr =3D int(m.group(1), 16) + exports[m.group(2)] =3D addr +for (name, addr) in exports.items(): + if addr is None: + raise Exception("Required export symbols %s not found" % name) + +file1 =3D open(args.bin1, 'rb') +file2 =3D open(args.bin2, 'rb') +file1.seek(0, 2) +size1 =3D file1.tell() +file2.seek(0, 2) +size2 =3D file2.tell() +if size1 > size2: + file1, file2 =3D file2, file1 + size1, size2 =3D size2, size1 +if size2 !=3D size1 + gap: + raise Exception('File sizes do not match') + +file1.seek(0, 0) +data1 =3D file1.read(size1) +file2.seek(gap, 0) +data2 =3D file2.read(size1) + +max_line =3D max(symbols.keys()) + +def to_int32(n): + '''Convert a number to signed 32 bit integer truncating if needed''' + mask =3D (1 << 32) - 1 + h =3D 1 << 31 + return (n & mask) ^ h - h + +i =3D 0 +references =3D {} +internals =3D 0 +while i <=3D size1 - 4: + n1 =3D struct.unpack('=3D 10: + break + continue + # This is a relative relocation to a symbol, accepted, code/data is + # relocatable. + if diff < gap and diff >=3D gap - max_line: + n =3D gap - diff + symbol =3D symbols.get(n) + # check we have a symbol + if symbol is None: + raise Exception("Cannot find symbol for line %d" % n) + pos =3D i - 1 + if args.verbose: + print('Position %#x %d %s' % (pos, n, symbol), file=3Dsys.stde= rr) + i +=3D 3 + references[pos] =3D symbol + continue + # First byte is the same, move to next byte + if diff & 0xff =3D=3D 0 and i <=3D size1 - 4: + continue + # Probably a type of relocation we don't want or support + pos =3D i - 1 + suggestion =3D '' + symbol =3D symbols.get(-diff - text_diff) + if symbol is not None: + suggestion =3D " Maybe %s is not defined as hidden?" % symbol + raise Exception("Unexpected difference found at %#x " + "n1=3D%#x n2=3D%#x diff=3D%#x gap=3D%#x.%s" % \ + (pos, n1, n2, diff, gap, suggestion)) +if internals !=3D 0: + raise Exception("Previous relocations found") + +def line_bytes(buf, out): + '''Output an assembly line with all bytes in "buf"''' + # Python 2 compatibility + if type(buf) =3D=3D str: + print("\t.byte " + ','.join([str(ord(c)) for c in buf]), file=3Dou= t) + else: + print("\t.byte " + ','.join([str(n) for n in buf]), file=3Dout) + +def part(start, end, out): + '''Output bytes of "data" from "start" to "end"''' + while start < end: + e =3D min(start + 16, end) + line_bytes(data1[start:e], out) + start =3D e + +def reference(pos, out): + name =3D references[pos] + n =3D struct.unpack('=3D (1 << 31): + n -=3D (1 << 32) + n +=3D pos + if n < 0: + n =3D -n + sign =3D '-' + print("\t.hidden %s\n" + "\t.long %s %s %#x - ." % (name, name, sign, n), + file=3Dout) + +def output(out): + prev =3D 0 + exports_by_addr =3D {} + for (sym, addr) in exports.items(): + exports_by_addr.setdefault(addr, []).append(sym) + positions =3D list(references.keys()) + positions +=3D list(exports_by_addr.keys()) + for pos in sorted(positions): + part(prev, pos, out) + prev =3D pos + if pos in references: + reference(pos, out) + prev =3D pos + 4 + if pos in exports_by_addr: + for sym in exports_by_addr[pos]: + print("\t.global %s\n" + "\t.hidden %s\n" + "%s:" % (sym, sym, sym), + file=3Dout) + part(prev, size1, out) + +out =3D sys.stdout +if args.output is not None: + out =3D open(args.output, 'w') +print('''/* + * File autogenerated by combine_two_binaries.py DO NOT EDIT + */''', file=3Dout) +print('\t' + args.section_header, file=3Dout) +print('obj_start:', file=3Dout) +output(out) +print('\n\t.section\t.note.GNU-stack,"",@progbits', file=3Dout) +out.flush() --=20 2.34.1 From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896065; cv=none; d=zohomail.com; s=zohoarc; b=KJMwR8MR4t5YqLzCicz4kohz6Pz2fY7mCcaOFakZzSs6FoJWJt2+Bd/nvak2t3MYqQXs9z4MnHoh8cgSukC5fj+4nk8JPNoxgci3rgwDc6Q35Px+S8A7edhZATrCkRtt+b/+SoWIO47pLem9jrm5z5Kr9BxPryrou2M45LYDKZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896065; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oySDyT4GmL2tsmRjXkrGrh0QdsSZG+8keHHypj0A/K8=; b=m8Sece6mLQEMIOn53IoiY1oBTwvLfnHb/mYs8lpuiGYHxWDRZ97gSwyvogaioO5zueckeDJODGyJ2WPYO/k/hBHGHIH8mp9KG7J7GblchOUP7Ktdkir75j9ILs4B8Hk3J5WUh9fXFWHAIUby6tne6g0XFFCFXxzI5v5GI76/PiI= 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 1728896065103466.89994784972043; Mon, 14 Oct 2024 01:54:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818522.1231848 (Exim 4.92) (envelope-from ) id 1t0Gpq-0000Pm-Fv; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (output) from mailman id 818522.1231848; Mon, 14 Oct 2024 08:53:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpq-0000P6-BT; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (input) for mailman id 818522; Mon, 14 Oct 2024 08:53:48 +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 1t0Gpo-00086D-IE for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:48 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d2e7e01e-8a09-11ef-99a2-01e77a169b0f; Mon, 14 Oct 2024 10:53:47 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2fb4af0b6beso8593321fa.3 for ; Mon, 14 Oct 2024 01:53:47 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:45 -0700 (PDT) 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: d2e7e01e-8a09-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896026; x=1729500826; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oySDyT4GmL2tsmRjXkrGrh0QdsSZG+8keHHypj0A/K8=; b=Gs4f4U4Ug7Ie82u9os/ec70JMWhcVnX5QSa+LqCNITRycmjzf2NwsxuxPHUkDw4dfA b9k3mCMvrPH+HhjFPNq3iuClSewe/I02zfYbYbd1t4xL0x3cgteyWWcA0RSsF0CMNWHn D/6r8GbJB8JLPzxhdKdDXHubt+ST/yYCK6JgI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896026; x=1729500826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oySDyT4GmL2tsmRjXkrGrh0QdsSZG+8keHHypj0A/K8=; b=VEEkZI0VQ4YFEXyyW+eWCJkBAgvG/QVznNxTHDwZpxkU1DcqhaSCk/jm9fuwIUYZwl GkwrFRIblC38X6UmJKSGKqSOKk0tOFDzgbWzzT/dw1sleVV0jGvrau/ucbI+y9GS/3pJ Z47Eewi2nc2Snvreh29CztNMmXqTJOPx8l59ETImfR2eU+LFLNYT2p5PGDXOKtsr1Jjr 3uEd6kYb4oGXqOEcgyzzkDJP8A3zqLKUW4PM69uqh6oNmFVtGV8KojfcqJROTeJanb/O wU4UXmNqUmKHJyzazgSevZsDxAiLkF/CHw32a4XoWjEJcFPW6fCMvHZe49VAwZdpMl3s roBQ== X-Gm-Message-State: AOJu0YytfXtAc2k78J8XmCeq1e/62OaQak0YEIwyk2kfNqS2pCvNuvWE EzspUgI5ON2vmH2llFBtbsZANb9aZBUXr9Lohrc7LECxYpexBbmkdBwkHpoh7phGXJBxVvftmg7 Q X-Google-Smtp-Source: AGHT+IH9NQoAnD2hbWSP0lmRunEYSkPbvCyiHCPSppmlkL1GMwO06hGOyc9V+oWZYD1MXxkljcKICw== X-Received: by 2002:a05:651c:2220:b0:2fb:3881:35d5 with SMTP id 38308e7fff4ca-2fb3f2c725emr29536201fa.35.1728896026013; Mon, 14 Oct 2024 01:53:46 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v4 3/6] x86/boot: Reuse code to relocate trampoline Date: Mon, 14 Oct 2024 09:53:29 +0100 Message-Id: <20241014085332.3254546-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896065548116600 Content-Type: text/plain; charset="utf-8" Move code from efi-boot.h to a separate, new, reloc-trampoline.c file. Reuse this new code, compiling it for 32bit as well, to replace assembly code in head.S doing the same thing. Signed-off-by: Frediano Ziglio Reviewed-by: Andrew Cooper --- Changes since v3: - fixed a typo in comment; - added Reviewed-by. --- xen/arch/x86/boot/Makefile | 12 ++++++---- xen/arch/x86/boot/build32.lds.S | 5 ++++ xen/arch/x86/boot/head.S | 23 +----------------- xen/arch/x86/boot/reloc-trampoline.c | 36 ++++++++++++++++++++++++++++ xen/arch/x86/efi/efi-boot.h | 15 ++---------- 5 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 xen/arch/x86/boot/reloc-trampoline.c diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile index 23ad274c89..ca258a9729 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,12 +1,16 @@ obj-bin-y +=3D head.o obj-bin-y +=3D built_in_32.o +obj-bin-y +=3D $(obj64) =20 obj32 :=3D cmdline.32.o obj32 +=3D reloc.32.o +obj32 +=3D reloc-trampoline.32.o =20 -nocov-y +=3D $(obj32) -noubsan-y +=3D $(obj32) -targets +=3D $(obj32) +obj64 :=3D reloc-trampoline.o + +nocov-y +=3D $(obj32) $(obj64) +noubsan-y +=3D $(obj32) $(obj64) +targets +=3D $(obj32) $(obj64) =20 obj32 :=3D $(addprefix $(obj)/,$(obj32)) =20 @@ -50,7 +54,7 @@ $(obj)/built_in_32.S: $(obj)/built_in_32.other.bin $(obj)= /built_in_32.final.bin --bin1 $(obj)/built_in_32.other.bin \ --bin2 $(obj)/built_in_32.final.bin \ --map $(obj)/built_in_32.final.map \ - --exports cmdline_parse_early,reloc \ + --exports cmdline_parse_early,reloc,reloc_trampoline32 \ --output $@ =20 clean-files :=3D built_in_32.*.bin built_in_32.*.map build32.*.lds diff --git a/xen/arch/x86/boot/build32.lds.S b/xen/arch/x86/boot/build32.ld= s.S index 50c167aef0..1110880ad4 100644 --- a/xen/arch/x86/boot/build32.lds.S +++ b/xen/arch/x86/boot/build32.lds.S @@ -41,6 +41,11 @@ SECTIONS * Potentially they should be all variables. */ DECLARE_IMPORT(__base_relocs_start); DECLARE_IMPORT(__base_relocs_end); + DECLARE_IMPORT(__trampoline_rel_start); + DECLARE_IMPORT(__trampoline_rel_stop); + DECLARE_IMPORT(__trampoline_seg_start); + DECLARE_IMPORT(__trampoline_seg_stop); + DECLARE_IMPORT(trampoline_phys); . =3D . + GAP; *(.text) *(.text.*) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index e0776e3896..ade2c5c43d 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -706,28 +706,7 @@ trampoline_setup: mov %edx, sym_offs(l1_bootmap)(%esi, %ecx, 8) =20 /* Apply relocations to bootstrap trampoline. */ - mov sym_esi(trampoline_phys), %edx - lea sym_esi(__trampoline_rel_start), %edi - lea sym_esi(__trampoline_rel_stop), %ecx -1: - mov (%edi), %eax - add %edx, (%edi, %eax) - add $4,%edi - - cmp %ecx, %edi - jb 1b - - /* Patch in the trampoline segment. */ - shr $4,%edx - lea sym_esi(__trampoline_seg_start), %edi - lea sym_esi(__trampoline_seg_stop), %ecx -1: - mov (%edi), %eax - mov %dx, (%edi, %eax) - add $4,%edi - - cmp %ecx, %edi - jb 1b + call reloc_trampoline32 =20 /* Do not parse command line on EFI platform here. */ cmpb $0, sym_esi(efi_platform) diff --git a/xen/arch/x86/boot/reloc-trampoline.c b/xen/arch/x86/boot/reloc= -trampoline.c new file mode 100644 index 0000000000..0a74c1e75a --- /dev/null +++ b/xen/arch/x86/boot/reloc-trampoline.c @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +extern const int32_t __trampoline_rel_start[], __trampoline_rel_stop[]; +extern const int32_t __trampoline_seg_start[], __trampoline_seg_stop[]; + +#if defined(__i386__) +void reloc_trampoline32(void) +#elif defined (__x86_64__) +void reloc_trampoline64(void) +#else +#error Unknown architecture +#endif +{ + unsigned long phys =3D trampoline_phys; + const int32_t *trampoline_ptr; + + /* + * Apply relocations to trampoline. + * + * This modifies the trampoline in place within Xen, so that it will + * operate correctly when copied into place. + */ + for ( trampoline_ptr =3D __trampoline_rel_start; + trampoline_ptr < __trampoline_rel_stop; + ++trampoline_ptr ) + *(uint32_t *)(*trampoline_ptr + (long)trampoline_ptr) +=3D phys; + + for ( trampoline_ptr =3D __trampoline_seg_start; + trampoline_ptr < __trampoline_seg_stop; + ++trampoline_ptr ) + *(uint16_t *)(*trampoline_ptr + (long)trampoline_ptr) =3D phys >> = 4; +} diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 94f3443364..1acceec471 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -103,27 +103,16 @@ static void __init efi_arch_relocate_image(unsigned l= ong delta) } } =20 -extern const int32_t __trampoline_rel_start[], __trampoline_rel_stop[]; -extern const int32_t __trampoline_seg_start[], __trampoline_seg_stop[]; +void reloc_trampoline64(void); =20 static void __init relocate_trampoline(unsigned long phys) { - const int32_t *trampoline_ptr; - trampoline_phys =3D phys; =20 if ( !efi_enabled(EFI_LOADER) ) return; =20 - /* Apply relocations to trampoline. */ - for ( trampoline_ptr =3D __trampoline_rel_start; - trampoline_ptr < __trampoline_rel_stop; - ++trampoline_ptr ) - *(u32 *)(*trampoline_ptr + (long)trampoline_ptr) +=3D phys; - for ( trampoline_ptr =3D __trampoline_seg_start; - trampoline_ptr < __trampoline_seg_stop; - ++trampoline_ptr ) - *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) =3D phys >> 4; + reloc_trampoline64(); } =20 static void __init place_string(u32 *addr, const char *s) --=20 2.34.1 From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896063; cv=none; d=zohomail.com; s=zohoarc; b=cKObv776Ixw4WITYe4WClj2bNayRnPdVOKuLzSFHZh7gvn1PmZCCiJwal5Q0WONpydc+hThtbfhkhyewzPHwyObC5Ux4dyFO7r17zP0VachvO868t74mYCxAKblXh19IKa/JtfFKZcKLJ/qgYejzpFYVN8emWSIsD5CXjmmaX4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896063; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TK+nbrmtQrubI4mXkXmmhgJ7U2/YQr+t6QKP18Zmwks=; b=JUs0Hnu9ysjzICUJxbZX1ZIQ9IA3Wa+MRqA9Qx/gaOBM05+PiszECMuSyOxvdKFc4MZbk9KjBf1kAGLMtRK7JLRB+IuN5olFV5qOdTT3+M0vO95a72sSfgLjsQJaChgxQZoCXotl1goGCrUV0FSrNUDRJYSf7+wNd5kp7I4sBWw= 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 1728896063657533.0228589801955; Mon, 14 Oct 2024 01:54:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818521.1231844 (Exim 4.92) (envelope-from ) id 1t0Gpq-0000NI-6O; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (output) from mailman id 818521.1231844; Mon, 14 Oct 2024 08:53:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpq-0000NB-2v; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (input) for mailman id 818521; Mon, 14 Oct 2024 08:53:48 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpo-000862-8Y for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:48 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d3681249-8a09-11ef-a0be-8be0dac302b0; Mon, 14 Oct 2024 10:53:47 +0200 (CEST) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso667109566b.3 for ; Mon, 14 Oct 2024 01:53:47 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:46 -0700 (PDT) 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: d3681249-8a09-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896027; x=1729500827; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TK+nbrmtQrubI4mXkXmmhgJ7U2/YQr+t6QKP18Zmwks=; b=J0Hei3kejJWEVBWlJIWPkgFx+Gq8LKyW2/4CP9vdti9OphBnK8QSpuj/QWpvq09Ohg ge9MJ30ofEeQfhiaild/45K67LQYJtrlJ2Vx41rRGZGlUiZyBPRGD/yo+HBsAzHnbYa+ HBLEk45PttaN0WAqruiQmO96xpw/sjugCqIU4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896027; x=1729500827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TK+nbrmtQrubI4mXkXmmhgJ7U2/YQr+t6QKP18Zmwks=; b=iapJpn9hB8YCq3YyceiMvo6NUg0iSFd2dJEcbtJ6GUdY0CLxMBAMobCUM5PYiB5Zcs gOkMa2RmQUsgOWEdvAf1eTLgZVXHoG99+xIpn14z2kpFm5gkNLfXQhLGVqCcadsCkWu0 XqoQrohHM8+v1F6YmAEspy/x/rJnzThV8vVjVOdOqKljp/K5m4z1n9dX3rJJT15Km2yN mKdjK6erhv5IuFqgRK3wxWaQ1suvOwu+ljXxuxzwPvfVeSdGbTm9Bp+zsRR+Z9TUj2jy KD1oJGMtTHh3xROGIS2gBKvoJ1y/9e+WvJbiQE/5t+mtnDlsUeYPCAa0bj74CBE3FG3e OnLw== X-Gm-Message-State: AOJu0Yw3tWwL10YGYCiyCLbw/wmjy4QHcjip4eFQdHazIyXTGmS4OZas 9VdzW+lB1UVCJZqNd3hm40YxE6Gpqrulj1tn8quOD4hcF3eq9AjH5fJZj3PZxFvDMMHJJNagem3 i X-Google-Smtp-Source: AGHT+IHYrbYIK/sUdXu0LMUkQtOaIozUCZSYqAN0jSzxJmBLPE2Czj5lW1Gq0OlEDuIF+bN1I7FXvw== X-Received: by 2002:a17:907:701:b0:a99:3c32:b538 with SMTP id a640c23a62f3a-a99e3e51b56mr687084666b.42.1728896027043; Mon, 14 Oct 2024 01:53:47 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 4/6] x86/boot: Use boot_vid_info variable directly from C code Date: Mon, 14 Oct 2024 09:53:30 +0100 Message-Id: <20241014085332.3254546-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896065481116600 Content-Type: text/plain; charset="utf-8" No more need to pass from assembly code. Signed-off-by: Frediano Ziglio Reviewed-by: Andrew Cooper --- Changes since v1: - split the 2 variable changes into 2 commits. Changes since v2: - revert commit order. --- xen/arch/x86/boot/build32.lds.S | 1 + xen/arch/x86/boot/head.S | 10 +--------- xen/arch/x86/boot/reloc.c | 13 +++++-------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/boot/build32.lds.S b/xen/arch/x86/boot/build32.ld= s.S index 1110880ad4..8c40758834 100644 --- a/xen/arch/x86/boot/build32.lds.S +++ b/xen/arch/x86/boot/build32.lds.S @@ -46,6 +46,7 @@ SECTIONS DECLARE_IMPORT(__trampoline_seg_start); DECLARE_IMPORT(__trampoline_seg_stop); DECLARE_IMPORT(trampoline_phys); + DECLARE_IMPORT(boot_vid_info); . =3D . + GAP; *(.text) *(.text.*) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index ade2c5c43d..5da7ac138f 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -514,18 +514,10 @@ trampoline_setup: mov sym_esi(trampoline_phys), %ecx add $TRAMPOLINE_SPACE,%ecx =20 -#ifdef CONFIG_VIDEO - lea sym_esi(boot_vid_info), %edx -#else - xor %edx, %edx -#endif - /* Save Multiboot / PVH info struct (after relocation) for later u= se. */ - push %edx /* Boot video info to be filled from M= B2. */ mov %ebx, %edx /* Multiboot / PVH information address= . */ - /* reloc(magic/eax, info/edx, trampoline/ecx, video/stk) usin= g fastcall. */ + /* reloc(magic/eax, info/edx, trampoline/ecx) using fastcall.= */ call reloc - add $4, %esp =20 #ifdef CONFIG_PVH_GUEST cmpb $0, sym_esi(pvh_boot) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 94b078d7b1..707d9c5f15 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -176,7 +176,7 @@ static multiboot_info_t *mbi_reloc(uint32_t mbi_in, mem= ctx *ctx) return mbi_out; } =20 -static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, m= emctx *ctx) +static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, memctx *ctx) { const multiboot2_fixed_t *mbi_fix =3D _p(mbi_in); const multiboot2_memory_map_t *mmap_src; @@ -185,7 +185,7 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, ui= nt32_t video_out, memctx memory_map_t *mmap_dst; multiboot_info_t *mbi_out; #ifdef CONFIG_VIDEO - struct boot_video_info *video =3D NULL; + struct boot_video_info *video =3D &boot_vid_info; #endif uint32_t ptr; unsigned int i, mod_idx =3D 0; @@ -290,12 +290,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out, memctx =20 #ifdef CONFIG_VIDEO case MULTIBOOT2_TAG_TYPE_VBE: - if ( video_out ) + if ( video ) { const struct vesa_ctrl_info *ci; const struct vesa_mode_info *mi; =20 - video =3D _p(video_out); ci =3D (const void *)get_mb2_data(tag, vbe, vbe_control_in= fo); mi =3D (const void *)get_mb2_data(tag, vbe, vbe_mode_info); =20 @@ -321,7 +320,6 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, ui= nt32_t video_out, memctx if ( (get_mb2_data(tag, framebuffer, framebuffer_type) !=3D MULTIBOOT2_FRAMEBUFFER_TYPE_RGB) ) { - video_out =3D 0; video =3D NULL; } break; @@ -346,8 +344,7 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, ui= nt32_t video_out, memctx } =20 /* SAF-1-safe */ -void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline, - uint32_t video_info) +void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline) { memctx ctx =3D { trampoline }; =20 @@ -357,7 +354,7 @@ void *reloc(uint32_t magic, uint32_t in, uint32_t tramp= oline, return mbi_reloc(in, &ctx); =20 case MULTIBOOT2_BOOTLOADER_MAGIC: - return mbi2_reloc(in, video_info, &ctx); + return mbi2_reloc(in, &ctx); =20 case XEN_HVM_START_MAGIC_VALUE: if ( IS_ENABLED(CONFIG_PVH_GUEST) ) --=20 2.34.1 From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896063; cv=none; d=zohomail.com; s=zohoarc; b=RseQwPrE9JaEa4vF0XjZjt4iOp2610XpDh2hB/9nl4uyBWeatH2uBRx0iZLnGztn1DNGhA83Y0U12ik05nynkmt5Xp1KegUVz8lPQohHtn8v2XaFqdRQA4ETRwjDgpnD2jaReJUX2wE6eL4JxrllQtQn1f6eN75pkGWHXt68fhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896063; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tUEXdxMnhhDzo/2gzjHB2TfqPR4THpXflyTPiqcQYhg=; b=YuGzSgDF2OJbRJUuvCWhhLoFkhLNYQAEDCgnRe8B2k68MQT0BEv6wdwHQEkktpGML8TzsGNxETq9os43tCA6U45Tu1OebsLEulQHB6COox8qG+ALOtdqo38mUANEwYw7yFiCJ5ykC16PljB+Ri48kWu6ml0kK9mN/IkhOE6DCHs= 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 172889606333443.71119014566489; Mon, 14 Oct 2024 01:54:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818523.1231855 (Exim 4.92) (envelope-from ) id 1t0Gpq-0000Vd-Sj; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (output) from mailman id 818523.1231855; Mon, 14 Oct 2024 08:53:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpq-0000Uw-Mm; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (input) for mailman id 818523; Mon, 14 Oct 2024 08:53:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpo-000862-WA for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:48 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d3e625df-8a09-11ef-a0be-8be0dac302b0; Mon, 14 Oct 2024 10:53:48 +0200 (CEST) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a99ebb390a5so291037566b.1 for ; Mon, 14 Oct 2024 01:53:48 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:47 -0700 (PDT) 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: d3e625df-8a09-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896028; x=1729500828; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tUEXdxMnhhDzo/2gzjHB2TfqPR4THpXflyTPiqcQYhg=; b=VZASOegr+0HPihLAeEU+kxpkZVIQ+yKWy96TH932Z58r+OKxuVRKJ5UjPsvQqmX/bt t62mn39jCTNwZQE2mS+mFFwVPuaLLbVU9UB5F56BRn5/V5yvj2SpNLeI646YQqwEQl/F UrbtxIIqypQitUjktuMjA4WT5D2Zq0AQv5o2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896028; x=1729500828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tUEXdxMnhhDzo/2gzjHB2TfqPR4THpXflyTPiqcQYhg=; b=H3vK+N/FxhfXo2+OL1Z0HDZ4izsbbHbhS0fjgRMMYYnQy7NhVyOJNTphZKDUBo2yau Ou0ODyw7MhaJpyLx16HRTCO5rEtCMayN8tSdrIt2/5UUMLm/dtYsAyYDpHHYgWmjNCHr PzrXg0D88yqYixyOKRv+EZnQhDYmZb55YaQXug92SPhmxoTbG15ux2mmlRny7dP2VLvE xdeD7IcW0e2+csJKzkQlw+bJMcOTy7/x8APHlTGm77p0rHvkbk85gewH4yUyq1HcCJim vCkWhjB8CyGFgiKtsCiw5O4/6w39epMsNs4VPS7qDUoFZa+QM3fRp4Xvt7qlmQ7uVxZ0 pH7Q== X-Gm-Message-State: AOJu0Yw7kxRTkAHmpbs22+yp7UGDOTryR0BslO+r4KR56zdfEnb2m1jH YhIgP2K7GrpJFrJqJ9hcM1/DvNS5DKcfqy/Qm3koI2y7di3vlllSrIkxPa/z1DdeJdbE230FF43 u X-Google-Smtp-Source: AGHT+IFj+V1uiM2hGVgK8TpUoL7Vy0uU8dQnXhBfw/jVVNHHTVFzCF12fB6dz2k1PZfFxGX1yqzZdw== X-Received: by 2002:a17:906:6a01:b0:a99:ee26:f416 with SMTP id a640c23a62f3a-a99ee270d76mr517229666b.14.1728896027803; Mon, 14 Oct 2024 01:53:47 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 5/6] x86/boot: Use trampoline_phys variable directly from C code Date: Mon, 14 Oct 2024 09:53:31 +0100 Message-Id: <20241014085332.3254546-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896065433116600 Content-Type: text/plain; charset="utf-8" No more need to pass from assembly code. Signed-off-by: Frediano Ziglio Reviewed-by: Andrew Cooper --- Changes since v1: - split the 2 variable changes into 2 commits. Changes since v2: - revert commit order; - avoid useless casts. --- xen/arch/x86/boot/head.S | 6 +----- xen/arch/x86/boot/reloc.c | 8 ++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 5da7ac138f..dcda91cfda 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -510,13 +510,9 @@ trampoline_setup: mov %esi, sym_esi(xen_phys_start) mov %esi, sym_esi(trampoline_xen_phys_start) =20 - /* Get bottom-most low-memory stack address. */ - mov sym_esi(trampoline_phys), %ecx - add $TRAMPOLINE_SPACE,%ecx - /* Save Multiboot / PVH info struct (after relocation) for later u= se. */ mov %ebx, %edx /* Multiboot / PVH information address= . */ - /* reloc(magic/eax, info/edx, trampoline/ecx) using fastcall.= */ + /* reloc(magic/eax, info/edx) using fastcall. */ call reloc =20 #ifdef CONFIG_PVH_GUEST diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 707d9c5f15..e50e161b27 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -19,6 +19,9 @@ #include #include #include +#include + +#include =20 #include =20 @@ -344,9 +347,10 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, m= emctx *ctx) } =20 /* SAF-1-safe */ -void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline) +void *reloc(uint32_t magic, uint32_t in) { - memctx ctx =3D { trampoline }; + /* Get bottom-most low-memory stack address. */ + memctx ctx =3D { trampoline_phys + TRAMPOLINE_SPACE }; =20 switch ( magic ) { --=20 2.34.1 From nobody Sun Nov 24 04:47:59 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728896065; cv=none; d=zohomail.com; s=zohoarc; b=i1j6MulyhtNWm/HgCxEEHbkvbneDl6Mb4rr6EGtuYVdR+WFQZIQ4dS8NXCMuiLxLhDJc7ygB9Grtp+uvoPf5rsUTcRTN0iTBWutvqkop0E0hqtLS9iMRN5IQGMTyP1xcPFLBRLr2+ErPe6ZyTdOw46fuj2+Oi8G0M9StLpqqZO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728896065; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/R9IwC5Rg/1YFlZU2XC6OhmnY2lp5++tA2yhEvcFGMk=; b=aKhjktY+qz6scN0xH1UInMVKMSuZw6IWbgpQj9Z9OTgVQ7UXsxkRiicRKayejrcLn/pJXx9ECWE/BeyPS5Lg51uW/n1b4caMhe5S1eus7zy6K0NqzAq/8WWVnIj72dOLvrb3YBfg+QyzHzbsWh/e6f3tXCwCh7llMvYMweajIYs= 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 1728896065433186.81605284685304; Mon, 14 Oct 2024 01:54:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.818524.1231861 (Exim 4.92) (envelope-from ) id 1t0Gpr-0000bb-6r; Mon, 14 Oct 2024 08:53:51 +0000 Received: by outflank-mailman (output) from mailman id 818524.1231861; Mon, 14 Oct 2024 08:53:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpq-0000ZN-Uu; Mon, 14 Oct 2024 08:53:50 +0000 Received: by outflank-mailman (input) for mailman id 818524; Mon, 14 Oct 2024 08:53:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0Gpp-000862-Qh for xen-devel@lists.xenproject.org; Mon, 14 Oct 2024 08:53:49 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d45a0fb5-8a09-11ef-a0be-8be0dac302b0; Mon, 14 Oct 2024 10:53:49 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a99ebb390a5so291041266b.1 for ; Mon, 14 Oct 2024 01:53:49 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80f2446sm551817766b.206.2024.10.14.01.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:53:48 -0700 (PDT) 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: d45a0fb5-8a09-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728896029; x=1729500829; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/R9IwC5Rg/1YFlZU2XC6OhmnY2lp5++tA2yhEvcFGMk=; b=S3NzKKMpV40iW4BWaXxT5dxu1M8okJE1cEEPRDmTxjr1s+dzivegcZTtJ6WqTsalF9 hDy5j9kNEgYTyCTmasb6nkhoBWdJn19WQ+y7X35vaOtXtTkd6DbfF3gUkbSDrCMcMLfX VpV+JerDzWQw3TVBxrCVOYlUkDzeW18I7/G48= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896029; x=1729500829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/R9IwC5Rg/1YFlZU2XC6OhmnY2lp5++tA2yhEvcFGMk=; b=FrHgYpbOJxeb4Lx+bimIvb+yhU3aznLQBKFvVOmPWSbvQaqfU7Xa9N9pgtFHF+6+A5 5fM8+bI761UOQW/T64Ti/kU2zlvRVkM06A94FAwB0cqZhsUXv852gFdads2ehPKsMKKm q16XaXDv82b4eTxpmAAi1D+HlDkp+pj4mxUAqCDtWGsKpGaUlEES1mtyVUyRUt2A577U 9acZmR1a13IFdqgeVixFIP5ppzyrcKvOzVtWoF+kNJOnclZCkmNm7DfLxBhGZXba4pA4 rG32LCui0LW+KC508GwDl0H5C3yiTo29u+k0mqx2wmLNBp3d+pYQO9yigARwX3cCznBo 2Mxw== X-Gm-Message-State: AOJu0YxW6PBxO5aY5NU6y9qxWgY5E0Iu8hJbSRf+rPwQcdMjlVe0fgH+ KrgOwAMrNCceQhfOpxuGAST49F/niuwO33hLVit2i3/V17DI8x/1FVznrUQgUSGMWn+nJjYPCHI 2 X-Google-Smtp-Source: AGHT+IGc3uopgrUcXO4DHv75cFKwBrzFVJ3Kwh7nYK4pEV18S6bEUtErDpN+I2e6t4ivAXmmg7nm9A== X-Received: by 2002:a17:906:6a07:b0:a99:f9fa:5c01 with SMTP id a640c23a62f3a-a99f9fa6707mr463195766b.32.1728896028631; Mon, 14 Oct 2024 01:53:48 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 6/6] x86/boot: Clarify comment Date: Mon, 14 Oct 2024 09:53:32 +0100 Message-Id: <20241014085332.3254546-7-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014085332.3254546-1-frediano.ziglio@cloud.com> References: <20241014085332.3254546-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728896067672116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/reloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index e50e161b27..e725cfb6eb 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -65,7 +65,7 @@ typedef struct memctx { /* * Simple bump allocator. * - * It starts from the base of the trampoline and allocates downwards. + * It starts on top of space reserved for the trampoline and allocates= downwards. */ uint32_t ptr; } memctx; --=20 2.34.1