[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/boot: Simplify the expression for extra allocation space


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 19 Mar 2025 17:41:25 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cUHmAtpELtLd8qSdLVwGxkUYu+FMJDUKVdU+jA1yMqE=; b=g4dRV0hlS8DW3bO/FPH3KloViR/sjjFmQo2pP/d/NeTo9U6BlVJXwPhZfQEdHTwCt4twcGw6VO3vtwpTZHKGmzBFL2FaNRxbzo5jioaw7020AfuiopVh95NCe2nTvsWx5KrmAxj4EQ5jW/q2HEbIFMqmGyOAfmUfoWcrC6bq3YQp34owW64+18zq2zMGyhn2KzkB6Uf7XLel9/vbpkaQCZ4qca1/WO9ReH/metw4nTAE4emJDh43y3DHhYLcpjLE2O0iOi3bQCYC/O/I8umaC0JQjI2LdYQx6K2xIfIh49CULnfPRqIwvKy/FrDzSRQR6c2mKdGFoZJH/OPO2f/UjQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jcMVDAWgsLmTjs/8OqKX4lqXdQmhLUl785SgQqNYjHImeWNeuvrCEXMA3H+gbeZar0mJoAQaWdKU2ZvvgJ5sN6k8kcUBrT4df1HlI7Bbj6JiFWxY4zJK6+mJwnKlzKI3tAp3s4ucxSdeW/fLbeWiP0q6jlVxO6DdqSb+P89dZXtO/1GnxAq47zhZqsOl8S+fQbtJIBG53NL6IWgtk/61PBuejeVZfaeWeCVU1PRgbsjlZRDQ6lYksQAVZXWI8MwuO9qs7GOqnk/MjQudS4QfzyRD1UGexy5dq2eLSauF7fM15HvqmOo22R2rl5IxD9ARTAmPq307Uw3uiLBUHPuNpA==
  • Cc: Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 19 Mar 2025 21:41:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-03-19 13:13, Andrew Cooper wrote:
The expression for one parameter of find_memory() is already complicated and
about to become moreso.  Break it out into a new variable, and express it in
an easier-to-follow way.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>

One thought...

---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
  xen/arch/x86/hvm/dom0_build.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c
index 6a4453103a9a..6591949984b8 100644
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -654,6 +654,7 @@ static int __init pvh_load_kernel(
      const char *cmdline = image->cmdline_pa ? __va(image->cmdline_pa) : NULL;
      struct elf_binary elf;
      struct elf_dom_parms parms;
+    size_t extra_space;
      paddr_t last_addr;
      struct hvm_start_info start_info = { 0 };
      struct hvm_modlist_entry mod = { 0 };
@@ -711,13 +712,16 @@ static int __init pvh_load_kernel(
       * split into smaller allocations, done as a single region in order to
       * simplify it.
       */
-    last_addr = find_memory(d, &elf, sizeof(start_info) +
-                            (initrd ? ROUNDUP(initrd_len, PAGE_SIZE) +
-                                      sizeof(mod)
-                                    : 0) +
-                            (cmdline ? ROUNDUP(strlen(cmdline) + 1,
-                                               elf_64bit(&elf) ? 8 : 4)
-                                     : 0));
+    extra_space = sizeof(start_info);
+
+    if ( initrd )
+        extra_space += sizeof(mod) + ROUNDUP(initrd_len, PAGE_SIZE);
+
+    if ( cmdline )
+        extra_space += ROUNDUP(strlen(cmdline) + 1,
+                               elf_64bit(&elf) ? 8 : 4);

These component values are re-calculated below. With additional variables, they could be calculated once and used for find_memory() and later last_addr adjustments.

Regards,
Jason

+
+    last_addr = find_memory(d, &elf, extra_space);
      if ( last_addr == INVALID_PADDR )
      {
          printk("Unable to find a memory region to load initrd and 
metadata\n");

base-commit: aa78a7d10c6c2ef877b34d119a6db934c201ddfd




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.