From patchwork Wed Sep 4 14:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13791073 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 B32D4CD4855 for ; Wed, 4 Sep 2024 14:57:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790437.1200189 (Exim 4.92) (envelope-from ) id 1slrRS-0001FL-23; Wed, 04 Sep 2024 14:57:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790437.1200189; Wed, 04 Sep 2024 14:57:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrRR-0001F4-U8; Wed, 04 Sep 2024 14:57:05 +0000 Received: by outflank-mailman (input) for mailman id 790437; Wed, 04 Sep 2024 14:57:04 +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 1slrRQ-0001Bm-AI for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 14:57:04 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f13457af-6acd-11ef-99a1-01e77a169b0f; Wed, 04 Sep 2024 16:57:02 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c24ebaa427so1329718a12.1 for ; Wed, 04 Sep 2024 07:57:02 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3cc56c501sm18862a12.52.2024.09.04.07.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 07:57:00 -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: f13457af-6acd-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725461821; x=1726066621; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wjVZTVNCRpvS5aCzrzAh7uYMP3IDPAnNfZT/d8l3gkk=; b=lY5ZGsGc/VNhsMccO1LGzZGtyfKCfS4oY5EXov30K9sYvV1yJqG+mjth3h6MCorYsO ASN1Kq1A5pjYeC9GouAH2mwfQzGmDCzUvXy5zjcTFMDyoBHef25mHw2lTp/NwbTvBaaQ NeGp7xKJztKGNRZCoUVKRT/X3Y9CBjBi90y0Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725461821; x=1726066621; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wjVZTVNCRpvS5aCzrzAh7uYMP3IDPAnNfZT/d8l3gkk=; b=WMhj+lch3Q5COqj0JoCkWifPRvoZojMUJ1Tq8iLgYkfvZH/XG+zIil2G0/9087I8sN 5CQjkrhBP6PhYkWr9td03b2XTBtN4fRVrk3PPcjrgbleHCwA5n5a4Ip/RVTn20QtjGuH 1HR74+BCmuPZHgKUfSD4x5icm4WDbl83DbFntC/5YeKNh1/Kq9CVsW76zrbHUFEHDAB+ ROGO2HYfKv+Ig7qaKhT75qswozwMbuUvpkbo7ZsIM43pypXTgZ+JlmfFvrZaJX90Pvbz Si84J28O+c1UyR6SkK4E7sPMsIzN3YYc/OrqY93Uahqwc1N5imxlgz3Qi+4nHAd0cm31 e0/A== X-Gm-Message-State: AOJu0YzVL8rbxoOW8+d+Ae3toYU3fb7Idjyn5/Z0/Sjbe9HFA6dMCfR2 RHfd5TTNIahtIfU5ePEni/uuFQ/ywQCTuT9uPaV4iAf5xCCCUEdoLYli5bRch6GpTWdm4p1ceNt I X-Google-Smtp-Source: AGHT+IEeTb5cESA7yQkfy1YDNrPTTlFIpRm/E8yy/aK4TqdHdZt8pJOIwy2NKa4aCg2Ou/23rKob8A== X-Received: by 2002:a05:6402:3509:b0:5c2:76a3:fba4 with SMTP id 4fb4d7f45d1cf-5c3b291f14emr2516519a12.0.1725461821024; Wed, 04 Sep 2024 07:57:01 -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 , "Daniel P. Smith" , =?utf-8?q?Marek_Marczykow?= =?utf-8?q?ski-G=C3=B3recki?= Subject: [RFC 0/5] Reuse 32 bit C code more safely Date: Wed, 4 Sep 2024 15:56:43 +0100 Message-ID: <20240904145648.33707-1-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 This RFC series attempt to: - use more C code, that is replace some assembly code with C; - avoid some code duplication between C and assembly; - prevent some issues having relocations in C code. The idea is extending the current C to binary code conversion done for 32 bit C code called from head.S making sure relocations are safe and allowing external symbols usage from C code. Note that, as an addition, scripts generating code check for no data to allow code and data separation. More details of the implementation are in commit message 2/5, which is the largest patch. Patch 1/5 is to prepare code and avoid data. Patch 3/5 is an example of code reuse between 32 and 64 bit. Patch 4/5 is also another example of code reuse but is more hacky and dirty due to not being possible include use some headers. Code boot successfully using: - BIOS boot; - EFI boot with Grub2 and ELF file; - direct EFI boot without Grub. Suggestions/opinions are welcome. Code is currently based on "staging" branch, currently commit 6471badeeec92db1cb8155066551f7509cd82efd. Frediano Ziglio (5): Avoid usage of global in reloc.c x86/boot: create a C bundle for 32 bit boot code and use it Reuse code to relocate trampoline Remove duplication preparing pages setup mapping for trampoline in setup_pagesXX .gitignore | 3 +- xen/arch/x86/boot/Makefile | 30 ++- .../x86/boot/{build32.lds => build32.lds.S} | 60 +++++- xen/arch/x86/boot/cmdline.c | 7 - xen/arch/x86/boot/head.S | 89 +-------- xen/arch/x86/boot/reloc-trampoline.c | 28 +++ xen/arch/x86/boot/reloc-trampoline64.c | 1 + xen/arch/x86/boot/reloc.c | 69 ++++--- xen/arch/x86/boot/setup-pages.c | 116 ++++++++++++ xen/arch/x86/boot/setup-pages64.c | 1 + xen/arch/x86/boot/x86_64.S | 2 +- xen/arch/x86/efi/efi-boot.h | 67 +------ xen/arch/x86/include/asm/page.h | 3 +- xen/tools/make_output | 177 ++++++++++++++++++ 14 files changed, 446 insertions(+), 207 deletions(-) rename xen/arch/x86/boot/{build32.lds => build32.lds.S} (52%) create mode 100644 xen/arch/x86/boot/reloc-trampoline.c create mode 120000 xen/arch/x86/boot/reloc-trampoline64.c create mode 100644 xen/arch/x86/boot/setup-pages.c create mode 120000 xen/arch/x86/boot/setup-pages64.c create mode 100755 xen/tools/make_output