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

Re: [PATCH v4 11/13] x86/hyperlaunch: add memory parsing to domain config


  • To: <dmkhn@xxxxxxxxx>
  • From: Alejandro Vallejo <agarciav@xxxxxxx>
  • Date: Wed, 23 Apr 2025 14:05:20 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=proton.me 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=x0BnSVIvKuggEUL7lwrJ3sy4hxNZiE2bq6jdHVZuyEQ=; b=ovBezUlOKxIa2RVm58L5AxBpRLzXVvSR8vpvjhL1GtdwEqGaWvZKNdREPD5OHvNhIvXdGMXDfIYBvE8uubzsmu/Ojl8j/a6hwuPSa+5szRaQ4fYP+3h5/XodP6Ydaa0lp+e2wQ2s3+ZQzJAXTJamJ3oh5OooyqNqLLN+lvm/5hD/esDQJVF2sadWbNgYvnfdZAmY0aApv6AWZ9Gt9UT5ocmIwf9n18flGRAIwb5Cpih+HYZjuL8zd7On/TvBT8zwvGSN/GKjfDjHyOK3O4R8knYORBmZeP7Npfn7XGzntjkdzIxhTGMSa9n55uEQdNvd7olHAoKEAp1f1A2rDwcZxA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f9YeIZ9TAf/chWimnB0GaPAJ3tKKLkrBnxEkiqyLA2OWHKjB9C3ZC8njGQpQq1o0JJvwfScyIwfPkuWDDrOV2+NcF9WaTKgHzfrGlSvUpvPOVM0OATTrxdwvuwGLzLaWeObkjHUdM47qmiTDCh6vhzIJwDKJ+nUCxHzxSXfJaaHMYFARvG+Q9CUAgvmfFSqx6XZ61277v3iDLDtwpYCTrnVu+LWDGSlvkdxsku7EdyMro/h3Mk/yEJhUs1fOOrD4fhrO9GO2aFwPiYuj6RCkiGFk7WKF8h+k/Uzjz4cs1/q72/Q+Lp9spQUhCDTYw1LM6YuFgRGTWAIySO00S4rWIQ==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, "Michal Orzel" <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Wed, 23 Apr 2025 13:05:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Sat Apr 19, 2025 at 12:21 AM BST, dmkhn wrote:
> On Thu, Apr 17, 2025 at 01:48:33PM +0100, Alejandro Vallejo wrote:
>> From: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
>> 
>> Add three properties, memory, mem-min, and mem-max, to the domain node device
>> tree parsing to define the memory allocation for a domain. All three fields 
>> are
>> expressed in kb and written as a u64 in the device tree entries.
>> 
>> Signed-off-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
>> Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
>> Signed-off-by: Alejandro Vallejo <agarciav@xxxxxxx>
>> ---
>> Can't use KB() rather tha SZ_1K, as that's strictly for literals.
>
> Oh, that's right! Thanks!
>
>> 
>> v4:
>>   * Don't override fdt_prop_as_u64() rc on error.
>>   * Add separate printk statements for each memory prop error.
>>   * Fix bug setting up dom0_size, dom0_min_size and dom0_max_size
>>     * Was overriding dom0_size on all 3 paths.
>>   * Pre-initialise max_pages of all boot_domains to be LONG_MAX, just as
>>     dom0_max_size.
>>     * Eventually dom0_max_size drops out in the bigger series, so we
>>       need that logic to be correct.
>> ---
>>  xen/arch/x86/dom0_build.c              |  8 ++++++
>>  xen/arch/x86/include/asm/boot-domain.h |  4 +++
>>  xen/arch/x86/setup.c                   |  5 +++-
>>  xen/common/domain-builder/fdt.c        | 36 ++++++++++++++++++++++++++
>>  xen/include/xen/libfdt/libfdt-xen.h    | 10 +++++++
>>  5 files changed, 62 insertions(+), 1 deletion(-)
>> 
>> diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c
>> index 0b467fd4a4..8db24dbc0a 100644
>> --- a/xen/arch/x86/dom0_build.c
>> +++ b/xen/arch/x86/dom0_build.c
>> @@ -627,6 +627,14 @@ int __init construct_dom0(const struct boot_domain *bd)
>> 
>>      process_pending_softirqs();
>> 
>> +    /* If param dom0_size was not set and HL config provided memory size */
>> +    if ( !get_memsize(&dom0_size, ULONG_MAX) && bd->mem_pages )
>> +        dom0_size.nr_pages = bd->mem_pages;
>> +    if ( !get_memsize(&dom0_min_size, ULONG_MAX) && bd->min_pages )
>> +        dom0_min_size.nr_pages = bd->min_pages;
>> +    if ( !get_memsize(&dom0_max_size, ULONG_MAX) && bd->max_pages )
>> +        dom0_max_size.nr_pages = bd->max_pages;
>> +
>>      if ( is_hvm_domain(d) )
>>          rc = dom0_construct_pvh(bd);
>>      else if ( is_pv_domain(d) )
>> diff --git a/xen/arch/x86/include/asm/boot-domain.h 
>> b/xen/arch/x86/include/asm/boot-domain.h
>> index e316d4bcde..fa8ea1cc66 100644
>> --- a/xen/arch/x86/include/asm/boot-domain.h
>> +++ b/xen/arch/x86/include/asm/boot-domain.h
>> @@ -18,6 +18,10 @@ struct boot_domain {
>>  #define BUILD_MODE_ENABLE_DM     (1 << 1) /* HVM    | PVH     */
>>      uint32_t mode;
>> 
>> +    unsigned long mem_pages;
>> +    unsigned long min_pages;
>> +    unsigned long max_pages;
>> +
>>      struct boot_module *kernel;
>>      struct boot_module *module;
>>      const char *cmdline;
>> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
>> index 05e3d2cf2a..455dad454c 100644
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -296,7 +296,10 @@ static const char *cmdline_cook(const char *p, const 
>> char *loader_name);
>>  struct boot_info __initdata xen_boot_info = {
>>      .loader = "unknown",
>>      .cmdline = "",
>> -    .domains = { [0 ... MAX_NR_BOOTDOMS - 1] = { .domid = DOMID_INVALID } },
>> +    .domains = { [0 ... MAX_NR_BOOTDOMS - 1] = {
>> +        .domid = DOMID_INVALID,
>> +        .max_pages = ULONG_MAX,
>> +    }},
>>  };
>> 
>>  static struct boot_info *__init multiboot_fill_boot_info(
>> diff --git a/xen/common/domain-builder/fdt.c 
>> b/xen/common/domain-builder/fdt.c
>> index 6809c7f917..90218d120a 100644
>> --- a/xen/common/domain-builder/fdt.c
>> +++ b/xen/common/domain-builder/fdt.c
>> @@ -7,6 +7,7 @@
>>  #include <xen/init.h>
>>  #include <xen/lib.h>
>>  #include <xen/libfdt/libfdt.h>
>> +#include <xen/sizes.h>
>> 
>>  #include <asm/bootinfo.h>
>>  #include <asm/page.h>
>> @@ -246,6 +247,41 @@ static int __init process_domain_node(
>>                     (bd->mode & BUILD_MODE_ENABLE_DM) ? "hvm" :
>>                                                         "pvh");
>>          }
>> +        else if ( strncmp(prop_name, "memory", name_len) == 0 )
>
> Use !strncmp(...) like in the below code?

Sure

>
>> +        {
>> +            uint64_t kb;
>> +            if ( (rc = fdt_prop_as_u64(prop, &kb)) )
>> +            {
>> +                printk(XENLOG_ERR "  bad \"memory\" prop on domain %s\n", 
>> name);
>> +                return rc;
>> +            }
>> +            bd->mem_pages = PFN_DOWN(kb * SZ_1K);
>> +            printk(XENLOG_ERR "  memory: %lu KiB\n", kb);
>> +        }
>> +        else if ( !strncmp(prop_name, "mem-min", name_len) )
>> +        {
>> +            uint64_t kb;
>> +            if ( (rc = fdt_prop_as_u64(prop, &kb)) )
>> +            {
>> +                printk(XENLOG_ERR
>> +                       "  bad \"mem-min\" prop on domain %s\n", name);
>> +                return rc;
>> +            }
>> +            bd->min_pages = PFN_DOWN(kb * SZ_1K);
>> +            printk(XENLOG_INFO "  min memory: %lu kb\n", kb);
>> +        }
>> +        else if ( !strncmp(prop_name, "mem-max", name_len) )
>> +        {
>> +            uint64_t kb;
>> +            if ( (rc = fdt_prop_as_u64(prop, &kb)) )
>> +            {
>> +                printk(XENLOG_ERR
>> +                       "  bad \"mem-max\" prop on domain %s\n", name);
>> +                return rc;
>> +            }
>> +            bd->max_pages = PFN_DOWN(kb * SZ_1K);
>> +            printk(XENLOG_INFO "  max memory: %lu KiB\n", kb);
>> +        }
>>      }
>> 
>>      fdt_for_each_subnode(node, fdt, dom_node)
>> diff --git a/xen/include/xen/libfdt/libfdt-xen.h 
>> b/xen/include/xen/libfdt/libfdt-xen.h
>> index afc76e7750..3054b48a83 100644
>> --- a/xen/include/xen/libfdt/libfdt-xen.h
>> +++ b/xen/include/xen/libfdt/libfdt-xen.h
>> @@ -24,6 +24,16 @@ static inline int __init fdt_prop_as_u32(
>>      return 0;
>>  }
>> 
>> +static inline int __init fdt_prop_as_u64(
>> +    const struct fdt_property *prop, uint64_t *val)
>> +{
>> +    if ( !prop || fdt32_to_cpu(prop->len) < sizeof(uint64_t) )
>> +        return -EINVAL;
>> +
>> +    *val = fdt64_to_cpu(*(const fdt64_t *)prop->data);
>> +    return 0;
>> +}
>
> Perhaps move the call to common/domain-builder/fdt.c?

Yes, all new additions to that header ought to have gone to fdt.c
instead. That was my original intent, but then didn't go through with
everything.

Cheers,
Alejandro



 


Rackspace

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