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

Re: [PATCH 2/2] xen/arm: Move early mapping operations to new function


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 13 Feb 2025 10:20:29 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=V0q2INw4wGjzYyiRoYPajrAIWZa0EoCr2/dWb+WbSXU=; b=SL7Sr8lGoOW6kja+TA9DaOfqkr0ZV8alQ4HMiPNNrExGGeOPdyuy/u+9TNWhHsVU3awSPY7G+V1QbCzgQl5UBruyU8Msz0ySrcTKgkY6L+MqrBYSweHiQgDA2Yfzhu5a09cxBybax+6mbiDOMzInbEa/JfSifcc2+P7K5ptPcZbgTP43grgpAAmhKsTHXoONuySqginjNxrx2zCjNs5AUpC3F3WhoyQrHDUEHpdp0gpbJjAgBWFLvxZsAOvoqPsOqRYWTcx97XusBJf7RXlRPIbU4vBKYfQeMB98xHKBpXLqeqWlf938iFPjXSFYyVgD0d678xttrwyU2xQXJcwDGg==
  • 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=V0q2INw4wGjzYyiRoYPajrAIWZa0EoCr2/dWb+WbSXU=; b=ce5uzUM7k1Cjmxm7QhGcZlByj7K0/mTXeImsQPX8YQW2k7EH5LyurhVX/yZop4v+VcrSw9MxHLiY3AqJndcldwt9Sr+5fbfWQMD/KEtKm0+CC9QdPetFNP62lJqudewIXgX50i89qnR4Ah4Fo0zR6jLzkInFy6jEE/nqtIyEDM0nzk+4ZWCjhVTQNauFxOaRhoDbW5yMMoqsXaGXunojyhHnZI6k+SgyxgMrIYXe6g3DobdVDDotfDBziFhLAMNu1b92r2SLY++/nFBdLIH8ZiR3DQzgk41wdnlLzJdJzqb/dS7btb/scARm0/gE2oM95DTHZeLZ3IFNziC7C1Ozvw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=Z16F756pew0YVhrZeVj2WaEHZ2fsC7ERNWWjTW6PL2hRMe8QVMIx3rpKQNTsfTtxYvZ2BUhbqdv5PjLYkCQPsvuU4233OWJ4yGtgLPQ4ISEdyrtQ/OCywPoxmRkJYdkBoR7nk69wEny6cjVwxF+exHa0W+RPnWmAusfy5fKsdxJcvMAcA/O5dysn4pH6DtaRRR9oYaNunST3AmKKbCgF1stI3Bm1hC/Lk8Fi74k4sKjzFdENKneLiSfay5/U1B4OSAQepiThpcvInayxxsVj3bRBeEqkTB1QwJgmbCb7wcBH3HtMYQpbdaDeoPJnzUv5WCBmZ5fGvKHFMx83NfBDGA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wbR25KCUTZWznKkUfYckJ1X1yUWr/mytiapO42R14PENvXCJ7xjEvk1g3qlebj3K9MBfyLKiy9986MfMctfVyNH+k+nAYw+07BaDXNatzOpuNsrXzJu0Oot0/M6U3d/Ut0NpLlVKMW05AtAs009ZrOYmKbQpooL0jqk56EFM4c/kFSs6YleOGk/Ij5iGXTVR0X+2WaqWRtiDY1g4Q5VCBhcnXbXu+GyuKy22TXm8DjVngoMYN1s+EW15jhyw8zxNlf8Es3oue0rkeA+Ril9ZDzL3J+YQaWu6uqLXzR68oyvCwG3++aFcdkRpLCTikL7MobPK62sLV1zd6X4davodZg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 13 Feb 2025 10:20:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHbfS8+dm16q6nrp0GkauzwoWX70bNERcyAgADBgYA=
  • Thread-topic: [PATCH 2/2] xen/arm: Move early mapping operations to new function

Hi Julien,

thanks for your review.

>>  +void __init setup_early_mappings(paddr_t fdt_paddr)
>> +{
>> +    const char *cmdline;
>> +    struct bootmodule *xen_bootmodule;
>> +
>> +    device_tree_flattened = early_fdt_map(fdt_paddr);
>> +    if ( !device_tree_flattened )
>> +        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
>> +              "The DTB must be 8-byte aligned and must not exceed 2 MB in 
>> size.\n\n"
>> +              "Please check your bootloader.\n",
>> +              fdt_paddr);
>> +
>> +    /* Register Xen's load address as a boot module. */
>> +    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
>> +                             virt_to_maddr(_start),
>> +                             (paddr_t)(uintptr_t)(_end - _start), false);
>> +    BUG_ON(!xen_bootmodule);
> 
> Don't you need the code above for the MPU?
> 
>> +
>> +    cmdline = boot_fdt_cmdline(device_tree_flattened);
>> +    printk("Command line: %s\n", cmdline);
>> +    cmdline_parse(cmdline);
> 
> I find confusing this is part of early mappings. Shouldn't this be part of 
> common code?
> 
>> +
>> +    llc_coloring_init();
>> +
>> +    /*
>> +     * Page tables must be setup after LLC coloring initialization because
>> +     * coloring info are required in order to create colored mappings
>> +     */
>> +    setup_pagetables();
>> +    /* Device-tree was mapped in boot page tables, remap it in the new 
>> tables */
>> +    device_tree_flattened = early_fdt_map(fdt_paddr);
>> +}
>> +
>>  void *__init arch_vmap_virt_end(void)
>>  {
>>      return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE);
>> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
>> index c1f2d1b89d43..b2f34ba2a873 100644
>> --- a/xen/arch/arm/setup.c
>> +++ b/xen/arch/arm/setup.c
>> @@ -12,7 +12,6 @@
>>  #include <xen/device_tree.h>
>>  #include <xen/domain_page.h>
>>  #include <xen/grant_table.h>
>> -#include <xen/llc-coloring.h>
>>  #include <xen/types.h>
>>  #include <xen/string.h>
>>  #include <xen/serial.h>
>> @@ -300,8 +299,6 @@ size_t __read_mostly dcache_line_bytes;
>>  void asmlinkage __init start_xen(unsigned long fdt_paddr)
>>  {
>>      size_t fdt_size;
>> -    const char *cmdline;
>> -    struct bootmodule *xen_bootmodule;
>>      struct domain *d;
>>      int rc, i;
>>  @@ -315,35 +312,10 @@ void asmlinkage __init start_xen(unsigned long 
>> fdt_paddr)
>>        smp_clear_cpu_maps();
>>  -    device_tree_flattened = early_fdt_map(fdt_paddr);
>> -    if ( !device_tree_flattened )
>> -        panic("Invalid device tree blob at physical address %#lx.\n"
>> -              "The DTB must be 8-byte aligned and must not exceed 2 MB in 
>> size.\n\n"
>> -              "Please check your bootloader.\n",
>> -              fdt_paddr);
> 
> I understand why you don't need to call early_fdt_map() twice. But I am a bit 
> surprised why the two calls are moved to the MMU code. I think it would be 
> better if one of the call is kept here and early_fdt_map() is implemented for 
> the MPU.
> 
>> -
>> -    /* Register Xen's load address as a boot module. */
>> -    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
>> -                             virt_to_maddr(_start),
>> -                             (paddr_t)(uintptr_t)(_end - _start), false);
>> -    BUG_ON(!xen_bootmodule);
>> +    setup_early_mappings(fdt_paddr);
>>        fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);
> 
> This function will parse the memory banks. This is required by ...
> 
>>  -    cmdline = boot_fdt_cmdline(device_tree_flattened);
>> -    printk("Command line: %s\n", cmdline);
>> -    cmdline_parse(cmdline);
>> -
>> -    llc_coloring_init();
> 
> ... llc_coloring_init(). Yet you move it early. So I think it means the cache 
> coloring code would stop working.

woops, I didn’t see boot_fdt_info was parsing the memory banks, sorry I 
overlooked that,
I saw no dependencies on variables and given that I don’t have a working cache 
coloring setup
I didn’t notice. I’ll be more careful next time.

> 
> 
> > -> -    /*
>> -     * Page tables must be setup after LLC coloring initialization because
>> -     * coloring info are required in order to create colored mappings
>> -     */
>> -    setup_pagetables();
>> -    /* Device-tree was mapped in boot page tables, remap it in the new 
>> tables */
>> -    device_tree_flattened = early_fdt_map(fdt_paddr);
>> -
>>      setup_mm();
>>        vm_init();

So yes I would have used some duplication for the MPU part doing this:

void __init setup_early_mappings(paddr_t fdt_paddr)
{
    const char *cmdline;
    struct bootmodule *xen_bootmodule;

    <setup_mpu>

    device_tree_flattened = early_fdt_map(fdt_paddr);
    if ( !device_tree_flattened )
        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
              "The DTB must be 8-byte aligned and must not exceed 2 MB in 
size.\n\n"
              "Please check your bootloader.\n",
              fdt_paddr);

    /* Register Xen's load address as a boot module. */
    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
                             virt_to_maddr(_start),
                             (paddr_t)(uintptr_t)(_end - _start), false);
    BUG_ON(!xen_bootmodule);

    cmdline = boot_fdt_cmdline(device_tree_flattened);
    printk("Command line: %s\n", cmdline);
    cmdline_parse(cmdline);
}

I discussed with Michal before and he suggested to setup the MPU from the early 
ASM code,
it sounded a good idea to do that in the mpu enable_boot_cpu_mm, but then I 
realised my
MPU region table sits in .bss.

So I had some choices:
1) place the MPU region table in .data? I would still like it to be zeroed but 
I could do that in a “setup_mpu()” function.
    There is still the DT additional early_fdt_map call, but maybe I could move 
that into setup_pagetables() ?
    Or I could have a return value from llc_coloring_init() and make the second 
early_fdt_map call depending on if
    cache coloring is setup or not?
    I would then provide an empty stub for setup_pagetables() on MPU systems.

2) Provide a common function like what I’ve tried to do in this patch, so that 
different memory management subsystem
     could provide their implementation. Key differences as we saw are:
      a) MMU don’t call anything before early_fdt_map because it has already 
some data structure in place at this stage
      b) MMU needs to call llc_coloring_init, setup_pagetables and an 
additional early_fdt_map.
     Would something like pre_fdt_map(), post_fdt_map() work? pre_fdt_map() 
would be empty for MMU.

Please let me know your view on this, maybe you have some better design.

Cheers,
Luca




 


Rackspace

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