From patchwork Thu Oct 17 13:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13840036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1EEBCD37492 for ; Thu, 17 Oct 2024 13:32:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.820590.1234111 (Exim 4.92) (envelope-from ) id 1t1QbJ-0007F6-Em; Thu, 17 Oct 2024 13:31:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 820590.1234111; Thu, 17 Oct 2024 13:31:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t1QbJ-0007Cl-B6; Thu, 17 Oct 2024 13:31:37 +0000 Received: by outflank-mailman (input) for mailman id 820590; Thu, 17 Oct 2024 13:31:36 +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 1t1QbI-00079Y-O6 for xen-devel@lists.xenproject.org; Thu, 17 Oct 2024 13:31:36 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 21641546-8c8c-11ef-a0be-8be0dac302b0; Thu, 17 Oct 2024 15:31:35 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-431286f50e1so13610905e9.0 for ; Thu, 17 Oct 2024 06:31:35 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29817036sm299115166b.124.2024.10.17.06.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 06:31:34 -0700 (PDT) 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: 21641546-8c8c-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1729171895; x=1729776695; 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=aTukZVgKzhy9d/EZhN5tjFy+YSVWDkf6PLq9hRFbkpM=; b=fKGkYArtg+mto6xbLI0bNYZrMX8LygRS5InFCKuWhKQVHY8V/zCzotIQyIXznMMmsf ieJ2hkWvFinR6QM2Wx+SN2YCWavxfmt9y6lVEdJJjy6pzqGIglthPfMwE+7IHa6coWAc R5ftoLmT1iMPA93NlC+Eq4a7O7In3svgXrRBE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729171895; x=1729776695; 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=aTukZVgKzhy9d/EZhN5tjFy+YSVWDkf6PLq9hRFbkpM=; b=FUAhTLcD6uOWrz7DRLb0LZo8iVtNjBITcglbVnv7nrdo1u8wvaLro17jVXYVUCCoYC 9qQzZUv7xpO3ohMoxD0GKa0WGUJVb5c0i+CrYQBu7vv8ZOQME+ByOeWsntZioIre+bym xurLDl6x/5UMlptKT4tGyWCi163C9JTrD6c7LMoz/PiRdhZptW/MOYkdk22JWeIhMphO IA6EEDvH7ZrlJFRR0xPloi3VMnh3r+cKpnBCGLG4DAr+QDy6l4fSj2TZkawP2uFYaaku hqTEGIClsJXzzKimnu9PpDIoWIPaF8yxE1NOq1fVb6vzPcCKKELmo9wwuxgyMAInTT3N IdKw== X-Gm-Message-State: AOJu0YxcXZa/GgVRsqtZ+j5w+0wBHBcpgpJmsHFVWAo7Xr96T7pqJABB NPFZLMyNqPcDbino40nBqfWJklVY6hxHF7ncJOvyZi6d9Johoehe/3FVFPdQ8AaXL2OERkUxQN7 T X-Google-Smtp-Source: AGHT+IHkTEuRhWe96GPNZ6Y+ZAg0GdHr85Kbc09J+RXHqj4JULeE4Wwt0YbTGMFzV3DGDWn1sUrvMA== X-Received: by 2002:a5d:4b92:0:b0:37c:fbf8:fc4 with SMTP id ffacd0b85a97d-37d601fc350mr16482223f8f.59.1729171894559; Thu, 17 Oct 2024 06:31:34 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Julien Grall , Stefano Stabellini Subject: [PATCH v6 1/5] x86/boot: create a C bundle for 32 bit boot code and use it Date: Thu, 17 Oct 2024 14:31:19 +0100 Message-Id: <20241017133123.1946204-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017133123.1946204-1-frediano.ziglio@cloud.com> References: <20241017133123.1946204-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 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=error 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 Reviewed-by: Anthony PERARD --- 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. Changes since v4: - add build32.final.lds build32.other.lds to targets macro; - place some comments over a rule, not inside; - simplified linking and producing binary rule; - renamed built_in_32 to built-in-32, coding style; - fix minor indentation; - put magic numbers in Makefile and propagate them; - minor variable cleanups in Python script; - add dependency to Python script. Changes since v5: - renamed "other" and "final" phases to "base" and "offset"; - use if_changed macro to generate built-in-32.S. --- xen/arch/x86/boot/.gitignore | 5 +- xen/arch/x86/boot/Makefile | 47 +++- .../x86/boot/{build32.lds => 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 | 220 ++++++++++++++++++ 7 files changed, 292 insertions(+), 53 deletions(-) rename xen/arch/x86/boot/{build32.lds => 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..7e85549751 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..5da19501be 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,4 +1,5 @@ obj-bin-y += head.o +obj-bin-y += built-in-32.o obj32 := cmdline.32.o obj32 += reloc.32.o @@ -9,9 +10,6 @@ targets += $(obj32) obj32 := $(addprefix $(obj)/,$(obj32)) -$(obj)/head.o: AFLAGS-y += -Wa$(comma)-I$(obj) -$(obj)/head.o: $(obj32:.32.o=.bin) - CFLAGS_x86_32 := $(subst -m64,-m32 -march=i686,$(XEN_TREEWIDE_CFLAGS)) $(call cc-options-add,CFLAGS_x86_32,CC,$(EMBEDDED_EXTRA_CFLAGS)) CFLAGS_x86_32 += -Werror -fno-builtin -g0 -msoft-float -mregparm=3 @@ -25,14 +23,47 @@ $(obj32): XEN_CFLAGS := $(CFLAGS_x86_32) -fpic $(obj)/%.32.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) +orphan-handling-$(call ld-option,--orphan-handling=error) := --orphan-handling=error LDFLAGS_DIRECT-$(call ld-option,--warn-rwx-segments) := --no-warn-rwx-segments LDFLAGS_DIRECT += $(LDFLAGS_DIRECT-y) LD32 := $(LD) $(subst x86_64,i386,$(LDFLAGS_DIRECT)) -%.bin: %.lnk - $(OBJCOPY) -j .text -O binary $< $@ +text_gap := 0x010200 +text_diff := 0x408020 + +$(obj)/build32.base.lds: AFLAGS-y += -DGAP=$(text_gap) -DTEXT_DIFF=$(text_diff) +$(obj)/build32.offset.lds: AFLAGS-y += -DGAP=$(text_gap) -DTEXT_DIFF=$(text_diff) -DFINAL +$(obj)/build32.base.lds $(obj)/build32.offset.lds: $(src)/build32.lds.S FORCE + $(call if_changed_dep,cpp_lds_S) + +targets += build32.offset.lds build32.base.lds + +# link all 32bit objects together +$(obj)/built-in-32.tmp.o: $(obj32) + $(LD32) -r -o $@ $^ + +# link bundle with a given layout and extract a binary from it +$(obj)/built-in-32.%.bin: $(obj)/build32.%.lds $(obj)/built-in-32.tmp.o + $(LD32) $(orphan-handling-y) -N -T $< -Map $(@:bin=map) -o $(@:bin=o) $(filter %.o,$^) + $(OBJCOPY) -j .text -O binary $(@:bin=o) $@ + rm -f $(@:bin=o) + +quiet_cmd_combine = GEN $@ +cmd_combine = \ + $(PYTHON) $(srctree)/tools/combine_two_binaries.py \ + --gap=$(text_gap) --text-diff=$(text_diff) \ + --script $(obj)/build32.offset.lds \ + --bin1 $(obj)/built-in-32.base.bin \ + --bin2 $(obj)/built-in-32.offset.bin \ + --map $(obj)/built-in-32.offset.map \ + --exports cmdline_parse_early,reloc \ + --output $@ + +targets += built-in-32.S -%.lnk: %.32.o $(src)/build32.lds - $(LD32) -N -T $(filter %.lds,$^) -o $@ $< +# generate final object file combining and checking above binaries +$(obj)/built-in-32.S: $(obj)/built-in-32.base.bin $(obj)/built-in-32.offset.bin \ + $(srctree)/tools/combine_two_binaries.py FORCE + $(call if_changed,combine) -clean-files := *.lnk *.bin +clean-files := 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..e3f5e55261 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 . */ -ENTRY(_start) +#ifdef FINAL +# undef GAP +# define GAP 0 +# define MULT 0 +# define TEXT_START +#else +# define MULT 1 +# define TEXT_START TEXT_DIFF +#endif +#define DECLARE_IMPORT(name) name = . + (__LINE__ * MULT) + +ENTRY(dummy_start) SECTIONS { /* Merge code and data into one section. */ - .text : { + .text TEXT_START : { + /* Silence linker warning, we are not going to use it */ + dummy_start = .; + + /* 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); + . = . + 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 empty. */ .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). */ -/* - * This entry point is entered from xen/arch/x86/boot/head.S with: - * - %eax = &cmdline, - * - %edx = &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 - /* - * 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 */ -/* - * This entry point is entered from xen/arch/x86/boot/head.S with: - * - %eax = MAGIC, - * - %edx = INFORMATION_ADDRESS, - * - %ecx = TOPMOST_LOW_MEMORY_STACK_ADDRESS. - * - 0x04(%esp) = 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_binaries.py new file mode 100755 index 0000000000..264be77274 --- /dev/null +++ b/xen/tools/combine_two_binaries.py @@ -0,0 +1,220 @@ +#!/usr/bin/env python3 + +from __future__ import print_function +import argparse +import functools +import re +import struct +import sys + +parser = argparse.ArgumentParser(description='Generate assembly file to merge into other code.') +auto_int = functools.update_wrapper(lambda x: int(x, 0), int) # allows hex +parser.add_argument('--script', dest='script', + required=True, + help='Linker script for extracting symbols') +parser.add_argument('--bin1', dest='bin1', + required=True, + help='First binary') +parser.add_argument('--bin2', dest='bin2', + required=True, + help='Second binary') +parser.add_argument('--gap', dest='gap', + required=True, + type=auto_int, + help='Gap inserted at the start of code section') +parser.add_argument('--text-diff', dest='text_diff', + required=True, + type=auto_int, + help='Difference between code section start') +parser.add_argument('--output', dest='output', + help='Output file') +parser.add_argument('--map', dest='mapfile', + help='Map file to read for symbols to export') +parser.add_argument('--exports', dest='exports', + help='Symbols to export') +parser.add_argument('--section-header', dest='section_header', + default='.section .init.text, "ax", @progbits', + help='Section header declaration') +parser.add_argument('-v', '--verbose', + action='store_true') +args = parser.parse_args() + +gap = args.gap +text_diff = args.text_diff + +# Parse linker script for external symbols to use. +# Next regex matches expanded DECLARE_IMPORT lines in linker script. +symbol_re = re.compile(r'\s+(\S+)\s*=\s*\.\s*\+\s*\((\d+)\s*\*\s*0\s*\)\s*;') +symbols = {} +lines = {} +for line in open(args.script): + m = symbol_re.match(line) + if not m: + continue + (name, line_num) = (m.group(1), int(m.group(2))) + if line_num == 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" + line) + if name in lines: + raise Exception("Symbol with this name already present:\n\t" + name) + symbols[line_num] = name + lines[name] = line_num + +exports = [] +if args.exports is not None: + exports = 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 = re.compile(r'\s{15,}0x([0-9a-f]+)\s+(\S+)\n') + for line in open(args.mapfile): + m = symbol_re.match(line) + if not m or m.group(2) not in exports: + continue + addr = int(m.group(1), 16) + exports[m.group(2)] = addr +for (name, addr) in exports.items(): + if addr is None: + raise Exception("Required export symbols %s not found" % name) + +file1 = open(args.bin1, 'rb') +file2 = open(args.bin2, 'rb') +file1.seek(0, 2) +size1 = file1.tell() +file2.seek(0, 2) +size2 = file2.tell() +if size1 > size2: + file1, file2 = file2, file1 + size1, size2 = size2, size1 +if size2 != size1 + gap: + raise Exception('File sizes do not match') +del size2 + +file1.seek(0, 0) +data1 = file1.read(size1) +del file1 +file2.seek(gap, 0) +data2 = file2.read(size1) +del file2 + +max_line = max(symbols.keys()) + +def to_int32(n): + '''Convert a number to signed 32 bit integer truncating if needed''' + mask = (1 << 32) - 1 + h = 1 << 31 + return (n & mask) ^ h - h + +i = 0 +references = {} +internals = 0 +while i <= size1 - 4: + n1 = struct.unpack('= 10: + break + continue + # This is a relative relocation to a symbol, accepted, code/data is + # relocatable. + if diff < gap and diff >= gap - max_line: + n = gap - diff + symbol = symbols.get(n) + # check we have a symbol + if symbol is None: + raise Exception("Cannot find symbol for line %d" % n) + pos = i - 1 + if args.verbose: + print('Position %#x %d %s' % (pos, n, symbol), file=sys.stderr) + i += 3 + references[pos] = symbol + continue + # First byte is the same, move to next byte + if diff & 0xff == 0 and i <= size1 - 4: + continue + # Probably a type of relocation we don't want or support + pos = i - 1 + suggestion = '' + symbol = symbols.get(-diff - text_diff) + if symbol is not None: + suggestion = " Maybe %s is not defined as hidden?" % symbol + raise Exception("Unexpected difference found at %#x " + "n1=%#x n2=%#x diff=%#x gap=%#x.%s" % \ + (pos, n1, n2, diff, gap, suggestion)) +if internals != 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) == str: + print("\t.byte " + ','.join([str(ord(c)) for c in buf]), file=out) + else: + print("\t.byte " + ','.join([str(n) for n in buf]), file=out) + +def part(start, end, out): + '''Output bytes of "data" from "start" to "end"''' + while start < end: + e = min(start + 16, end) + line_bytes(data1[start:e], out) + start = e + +def reference(pos, out): + name = references[pos] + n = struct.unpack('= (1 << 31): + n -= (1 << 32) + n += pos + if n < 0: + n = -n + sign = '-' + print("\t.hidden %s\n" + "\t.long %s %s %#x - ." % (name, name, sign, n), + file=out) + +def output(out): + prev = 0 + exports_by_addr = {} + for (sym, addr) in exports.items(): + exports_by_addr.setdefault(addr, []).append(sym) + positions = list(references.keys()) + positions += list(exports_by_addr.keys()) + for pos in sorted(positions): + part(prev, pos, out) + prev = pos + if pos in references: + reference(pos, out) + prev = 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=out) + part(prev, size1, out) + +out = sys.stdout +if args.output is not None: + out = open(args.output, 'w') +print('''/* + * File autogenerated by combine_two_binaries.py DO NOT EDIT + */''', file=out) +print('\t' + args.section_header, file=out) +print('obj32_start:', file=out) +output(out) +print('\n\t.section\t.note.GNU-stack,"",@progbits', file=out) +out.flush() From patchwork Thu Oct 17 13:31:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13840033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4B48D37489 for ; Thu, 17 Oct 2024 13:32:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.820591.1234126 (Exim 4.92) (envelope-from ) id 1t1QbL-0007dB-MA; Thu, 17 Oct 2024 13:31:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 820591.1234126; Thu, 17 Oct 2024 13:31:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t1QbL-0007cy-JG; Thu, 17 Oct 2024 13:31:39 +0000 Received: by outflank-mailman (input) for mailman id 820591; Thu, 17 Oct 2024 13:31:38 +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 1t1QbK-0007Yl-K9 for xen-devel@lists.xenproject.org; Thu, 17 Oct 2024 13:31:38 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 21e28026-8c8c-11ef-99a3-01e77a169b0f; Thu, 17 Oct 2024 15:31:36 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5366fd6fdf1so1536290e87.0 for ; Thu, 17 Oct 2024 06:31:36 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29817036sm299115166b.124.2024.10.17.06.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 06:31:35 -0700 (PDT) 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: 21e28026-8c8c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1729171895; x=1729776695; 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=fZ9CyilDRJ9hcc5UhF8AJZBpprsEzy6yq5x+V3+UrsI=; b=VsqWJvTFpUpAfXUeLi2nmZXtXAGgj8Gj7J7kfvj3iVP5V2T5qf2XJzc87lISwuvGvw 7Vy7c9NN277GE4HhjovzrekxUmZtxABHKG1H43Ld7u6jSZsfyjH+WkQ+F/Df05JkK7Fm j0t0McbpFVxqWrJVwHYoLokvZVI6oH9N5hlao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729171895; x=1729776695; 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=fZ9CyilDRJ9hcc5UhF8AJZBpprsEzy6yq5x+V3+UrsI=; b=T7pIfrPvUVL67Inwp7kb9BktCZS8KOAY/4b4pyPMn/D/S/w6ZfeHMBzsP1SY343U50 FGPC4VvosYoXIJ2WgHG51kBhRYdQ8TuLhkzAQ0lugI3Bk2ln4T7E9T1AUKkwoAzLCydT pyoBzHsHfYSgNeNX34ZogPCx0HReadZUKfR6I/Oj2GKK+Un8qtiWVngV4Df/nQ6X0TVa 1B2MTTLXjP35IMcaelXNNTQYBuxkDppT7KN2Dtd8ryCw2JKYh6mg4h3WXj9xdlCE7x/4 AZjlIMpcXbT1G6VTsAGfhXzuauzoIMiIOr37K/i5Coi54qKcNZFJ3k9JY4FdRC1IrR0D Ni7Q== X-Gm-Message-State: AOJu0YwWcC+/o8VEIAUdhnNucZgr2ECfav56bVBWzGQcckSBAm+s9Yad TyL3ungXmsG1M9sM3KEUOtM8qXRgL7SmmYgEsslQ2dUot/piDoMlOZm7sTaVb2h7L7+pXYjKPUf b X-Google-Smtp-Source: AGHT+IErctvAnrUFXio0tyEeDTz1agZ8lWqX/qFwPX6eTI7Ki7+QcjFIYjiah0Jl/0rakksP8ZAvxQ== X-Received: by 2002:a05:6512:2384:b0:539:ea66:597e with SMTP id 2adb3069b0e04-53a03f07225mr5393227e87.2.1729171895361; Thu, 17 Oct 2024 06:31:35 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , "Daniel P. Smith" , =?utf-8?q?Marek_Marczykow?= =?utf-8?q?ski-G=C3=B3recki?= Subject: [PATCH v6 2/5] x86/boot: Reuse code to relocate trampoline Date: Thu, 17 Oct 2024 14:31:20 +0100 Message-Id: <20241017133123.1946204-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017133123.1946204-1-frediano.ziglio@cloud.com> References: <20241017133123.1946204-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 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 Acked-by: Marek Marczykowski-Górecki --- Changes since v3: - fixed a typo in comment; - added Reviewed-by. Changes since v5: - do not add obj64 to targets, already done adding it to obj-bin-y. --- xen/arch/x86/boot/Makefile | 10 +++++--- 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, 51 insertions(+), 38 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 5da19501be..98ceb1983d 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,11 +1,15 @@ obj-bin-y += head.o obj-bin-y += built-in-32.o +obj-bin-y += $(obj64) obj32 := cmdline.32.o obj32 += reloc.32.o +obj32 += reloc-trampoline.32.o -nocov-y += $(obj32) -noubsan-y += $(obj32) +obj64 := reloc-trampoline.o + +nocov-y += $(obj32) $(obj64) +noubsan-y += $(obj32) $(obj64) targets += $(obj32) obj32 := $(addprefix $(obj)/,$(obj32)) @@ -56,7 +60,7 @@ cmd_combine = \ --bin1 $(obj)/built-in-32.base.bin \ --bin2 $(obj)/built-in-32.offset.bin \ --map $(obj)/built-in-32.offset.map \ - --exports cmdline_parse_early,reloc \ + --exports cmdline_parse_early,reloc,reloc_trampoline32 \ --output $@ targets += built-in-32.S diff --git a/xen/arch/x86/boot/build32.lds.S b/xen/arch/x86/boot/build32.lds.S index e3f5e55261..fa282370f4 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); . = . + 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) /* 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 /* 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 = 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 = __trampoline_rel_start; + trampoline_ptr < __trampoline_rel_stop; + ++trampoline_ptr ) + *(uint32_t *)(*trampoline_ptr + (long)trampoline_ptr) += phys; + + for ( trampoline_ptr = __trampoline_seg_start; + trampoline_ptr < __trampoline_seg_stop; + ++trampoline_ptr ) + *(uint16_t *)(*trampoline_ptr + (long)trampoline_ptr) = 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 long delta) } } -extern const int32_t __trampoline_rel_start[], __trampoline_rel_stop[]; -extern const int32_t __trampoline_seg_start[], __trampoline_seg_stop[]; +void reloc_trampoline64(void); static void __init relocate_trampoline(unsigned long phys) { - const int32_t *trampoline_ptr; - trampoline_phys = phys; if ( !efi_enabled(EFI_LOADER) ) return; - /* Apply relocations to trampoline. */ - for ( trampoline_ptr = __trampoline_rel_start; - trampoline_ptr < __trampoline_rel_stop; - ++trampoline_ptr ) - *(u32 *)(*trampoline_ptr + (long)trampoline_ptr) += phys; - for ( trampoline_ptr = __trampoline_seg_start; - trampoline_ptr < __trampoline_seg_stop; - ++trampoline_ptr ) - *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4; + reloc_trampoline64(); } static void __init place_string(u32 *addr, const char *s) From patchwork Thu Oct 17 13:31:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13840037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C0A3D3748A for ; Thu, 17 Oct 2024 13:32:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.820593.1234140 (Exim 4.92) (envelope-from ) id 1t1QbN-0007vr-Dt; Thu, 17 Oct 2024 13:31:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 820593.1234140; Thu, 17 Oct 2024 13:31:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t1QbN-0007v8-8P; Thu, 17 Oct 2024 13:31:41 +0000 Received: by outflank-mailman (input) for mailman id 820593; Thu, 17 Oct 2024 13:31:39 +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 1t1QbL-0007Yl-98 for xen-devel@lists.xenproject.org; Thu, 17 Oct 2024 13:31:39 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 223c76a0-8c8c-11ef-99a3-01e77a169b0f; Thu, 17 Oct 2024 15:31:37 +0200 (CEST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c99be0a4bbso1367226a12.2 for ; Thu, 17 Oct 2024 06:31:37 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29817036sm299115166b.124.2024.10.17.06.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 06:31:35 -0700 (PDT) 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: 223c76a0-8c8c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1729171896; x=1729776696; 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=XzEVlEnNeKtsG4oZ8vIN3HV3hoDau6dk7zOGpeVNZ9s=; b=fi+RtnsGWTd6Jcj4TsDLuflGNx5hUaGq1/kX2kcJwcQydiTEtlZ/+n1CV5ejVNFxyO Tw2EL55WZcUz56mpg2JPbTdgqgLuOLIfz+BssnovXM7L5CE/cx9GLb7Fe4++7SYkbp5v W3mlGfWca0Da/AeUPDWhs8JdLGqfI/VUoT6EE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729171896; x=1729776696; 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=XzEVlEnNeKtsG4oZ8vIN3HV3hoDau6dk7zOGpeVNZ9s=; b=dnu5gP4ivCdqyGwG0CbNHDrprDly0RxdKZxojUj/Vnlqg2HVjneK09CPVIHOdsL90j 22+iQpOW086TcOka2bQWrN659Y7UJ0g/JOaakCrxJfZbpaHNI5v27/FDqZc7PwdXIa5J +B2ytRQZ/zhd+mWQy3G86pnluxvoZb7P3vcK3/FiE71qsA/BNfbuoyEuG310GS1M2OvZ e91hGIVgtq+0vNRNiW7EJzI4X2d0VtpCZZ4aaqfx2kKrAZ9RZGwQUivvbtscgwBhDVHO 9kJK94Ea/jMSHtjl5B0bphQBp3HXqDeIpWaAA0xCEXj0MBTmx7CaOzM55iuMAdsyhTyh iJkA== X-Gm-Message-State: AOJu0YzPQsQHEaeTrDul+UoV/tjIXNnSdBd3doH79wuut7CwITiU1PKf 0+C832pWF3TuFE4hk7ZwZLf+bPIqfUnBS4ceie2OIM2OyHIDOGea45F2ZGj0O3M+QfQRGti93sn m X-Google-Smtp-Source: AGHT+IGWyhuxM7dJJSlPTmg2r0XRuRDKeUhaUqGi1S7DhQ/mgftCJznObm2bf8PG4/w9z+TZwuU/jw== X-Received: by 2002:a17:907:940c:b0:a9a:f53:a5c6 with SMTP id a640c23a62f3a-a9a0f53a8d2mr1364462866b.65.1729171896126; Thu, 17 Oct 2024 06:31:36 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v6 3/5] x86/boot: Use boot_vid_info variable directly from C code Date: Thu, 17 Oct 2024 14:31:21 +0100 Message-Id: <20241017133123.1946204-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017133123.1946204-1-frediano.ziglio@cloud.com> References: <20241017133123.1946204-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 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.lds.S index fa282370f4..88b1964845 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); . = . + 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 -#ifdef CONFIG_VIDEO - lea sym_esi(boot_vid_info), %edx -#else - xor %edx, %edx -#endif - /* Save Multiboot / PVH info struct (after relocation) for later use. */ - push %edx /* Boot video info to be filled from MB2. */ mov %ebx, %edx /* Multiboot / PVH information address. */ - /* reloc(magic/eax, info/edx, trampoline/ecx, video/stk) using fastcall. */ + /* reloc(magic/eax, info/edx, trampoline/ecx) using fastcall. */ call reloc - add $4, %esp #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, memctx *ctx) return mbi_out; } -static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, memctx *ctx) +static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, memctx *ctx) { const multiboot2_fixed_t *mbi_fix = _p(mbi_in); const multiboot2_memory_map_t *mmap_src; @@ -185,7 +185,7 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, memctx memory_map_t *mmap_dst; multiboot_info_t *mbi_out; #ifdef CONFIG_VIDEO - struct boot_video_info *video = NULL; + struct boot_video_info *video = &boot_vid_info; #endif uint32_t ptr; unsigned int i, mod_idx = 0; @@ -290,12 +290,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, memctx #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; - video = _p(video_out); ci = (const void *)get_mb2_data(tag, vbe, vbe_control_info); mi = (const void *)get_mb2_data(tag, vbe, vbe_mode_info); @@ -321,7 +320,6 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, memctx if ( (get_mb2_data(tag, framebuffer, framebuffer_type) != MULTIBOOT2_FRAMEBUFFER_TYPE_RGB) ) { - video_out = 0; video = NULL; } break; @@ -346,8 +344,7 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out, memctx } /* 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 = { trampoline }; @@ -357,7 +354,7 @@ void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline, return mbi_reloc(in, &ctx); case MULTIBOOT2_BOOTLOADER_MAGIC: - return mbi2_reloc(in, video_info, &ctx); + return mbi2_reloc(in, &ctx); case XEN_HVM_START_MAGIC_VALUE: if ( IS_ENABLED(CONFIG_PVH_GUEST) ) From patchwork Thu Oct 17 13:31:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13840034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7515D3748C for ; Thu, 17 Oct 2024 13:32:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.820594.1234147 (Exim 4.92) (envelope-from ) id 1t1QbN-00081S-SE; Thu, 17 Oct 2024 13:31:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 820594.1234147; Thu, 17 Oct 2024 13:31:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t1QbN-00080G-Is; Thu, 17 Oct 2024 13:31:41 +0000 Received: by outflank-mailman (input) for mailman id 820594; Thu, 17 Oct 2024 13:31:40 +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 1t1QbM-0007Yl-9d for xen-devel@lists.xenproject.org; Thu, 17 Oct 2024 13:31:40 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 22c4da06-8c8c-11ef-99a3-01e77a169b0f; Thu, 17 Oct 2024 15:31:38 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a86e9db75b9so125863266b.1 for ; Thu, 17 Oct 2024 06:31:38 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29817036sm299115166b.124.2024.10.17.06.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 06:31:36 -0700 (PDT) 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: 22c4da06-8c8c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1729171897; x=1729776697; 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=hfvgJ7F4jiCfxikslPkJ6i1P5OKOMRuqlMUEX4FX+0Ov9iSWe8x1Qzzy0Qw2W/6/1i 5aK9JJfMm81DG9KzAWWB8Ho4/YAuuFgLzG5hG1xxbhj2jPvDAZr55HlSlLl4JoMacuc+ +Y6A2mNiJuNAtldy3g4k8xC1d1r8cJLLuE4w0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729171897; x=1729776697; 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=Q3g1m7wEbR09fKNOvAI3qk9VL5bcO5BgeOrXcxeQokydv22z6MIVx3w9OHkdIwPESR cDQ4NP4RihatTWQdnTDE53HXdRDaRpsQagid+cF9YFLnQLJP4IXHtbxOhv82EtMlIR5w PqymYiCTBAnWfh1u8fR8gTocNfNPmUl6WXcn7Ty4F7KkL4cJADk/VpkO0hafupcwNd2R touddLFHnCbCRw8UiB2NHKWldr9gelo/a7/2vaw+AJP7WwfB2WbUUVZLCb07IP4Ueyi1 uYoVZc596uArrTzmCmXFEZ3/rvo+KNtt1INpc/EBBb4fJPas+T5OsLlPjAnQDUqiAHZ3 REag== X-Gm-Message-State: AOJu0YxPFToJvw5H5wEiw5qRQWpCKYM9OcrxLFPhAgjjaiN6jbgMfEFk a7B5BBsfNpzh24g6FGcxmfD3I+5WS+cB0i55JcmsMayjOm7I4VeeZYkbZ+aBHiihI6Q7M0Cy7wl H X-Google-Smtp-Source: AGHT+IG1sYUmoX/vjQ7f1uakOXeaM56klxTlFbUCF5mFMb9u+u+inCKeGcvEet19Mzb6gBceym8AIQ== X-Received: by 2002:a17:907:96a1:b0:a99:e82a:87ee with SMTP id a640c23a62f3a-a99e82a8932mr1790616066b.57.1729171897068; Thu, 17 Oct 2024 06:31:37 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v6 4/5] x86/boot: Use trampoline_phys variable directly from C code Date: Thu, 17 Oct 2024 14:31:22 +0100 Message-Id: <20241017133123.1946204-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017133123.1946204-1-frediano.ziglio@cloud.com> References: <20241017133123.1946204-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 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) - /* 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 use. */ 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 #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 #include @@ -344,9 +347,10 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, memctx *ctx) } /* SAF-1-safe */ -void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline) +void *reloc(uint32_t magic, uint32_t in) { - memctx ctx = { trampoline }; + /* Get bottom-most low-memory stack address. */ + memctx ctx = { trampoline_phys + TRAMPOLINE_SPACE }; switch ( magic ) { From patchwork Thu Oct 17 13:31:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13840032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46C00D37489 for ; Thu, 17 Oct 2024 13:31:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.820592.1234136 (Exim 4.92) (envelope-from ) id 1t1QbN-0007ss-36; Thu, 17 Oct 2024 13:31:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 820592.1234136; Thu, 17 Oct 2024 13:31:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t1QbM-0007sd-W3; Thu, 17 Oct 2024 13:31:40 +0000 Received: by outflank-mailman (input) for mailman id 820592; Thu, 17 Oct 2024 13:31:39 +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 1t1QbL-00079Y-8E for xen-devel@lists.xenproject.org; Thu, 17 Oct 2024 13:31:39 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 23512cb5-8c8c-11ef-a0be-8be0dac302b0; Thu, 17 Oct 2024 15:31:38 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-539f1292a9bso1256718e87.2 for ; Thu, 17 Oct 2024 06:31:38 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29817036sm299115166b.124.2024.10.17.06.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 06:31:37 -0700 (PDT) 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: 23512cb5-8c8c-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1729171898; x=1729776698; 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=QgEVa7OmJ+TwPHVt5a1XLA0+1paZfixgP5b/ei2Anfu5yvP/PIUUth6gL9I4VaLFwZ 52bUQicR/FaZ2jK0SQV27cQ00Ej5ZSr+DaCHuD3ZsMiMs+t1rWV0fMfsyyVqeF0UF9L3 0REXYC1QqLdlzCw5oRa/1/lYEb/bBWx4oiN5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729171898; x=1729776698; 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=SZjzvII2KQn+AK+QMVcF32O3Tk/Y97cyWyWcVIVqv8gRAgCZS9wz2qGI7gNHJsXeaH cUk1kpVhIfihNJ3ck0R16PY4Aai8pqi6WwA3r5d+ZQRBK/dTNFA90nD0IEg256WXY0az IDTtYEHK4bDjgn2AH/WFDOZ35EaJFp9GGilFeX+p57Uasp5YtHC1WWgMsFLNk7zUIzKF SUL2Sz1AJhwVjMWID/HfWabKSYq/yCypBYMfhSXcCsTEXYoYOWzo0XRtewValhmKqFEo g2jXtsrxxH2rSZ4CqZ+hUM9m3Coymld004TrwBjqhBXTU0g+/cgESu6OCoXCkFf0uV9b cSlQ== X-Gm-Message-State: AOJu0Yxbwwf1GYdF/zj4R4I99lYvhuiWMfDz36w/bzD0lFuKWFjefoNx BYM6lxL6Zbk5otX0hU1IxgbTsIuVsxFrN9gzmSwN5reyC+Po8LY7Y/Lup3OKYZncVLAw3TWBP4b C X-Google-Smtp-Source: AGHT+IFQ8m7GP7IvMkAOFAVyuP9c1bo224/GXyA7Alb7lgZRKE1PAPj0LVHeXKyTyxPZGR/uiwNpDw== X-Received: by 2002:a05:6512:2384:b0:539:ea66:597e with SMTP id 2adb3069b0e04-53a03f07225mr5393333e87.2.1729171898000; Thu, 17 Oct 2024 06:31:38 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v6 5/5] x86/boot: Clarify comment Date: Thu, 17 Oct 2024 14:31:23 +0100 Message-Id: <20241017133123.1946204-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017133123.1946204-1-frediano.ziglio@cloud.com> References: <20241017133123.1946204-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 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;