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

Re: [PATCH] xen/riscv: init bss section


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 24 Feb 2023 16:55:06 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=+8AsOnkZ93FKjt7dyr38w2/7YTVfOQDe1xEzpKG63yk=; b=AvAcCaDnhTcPGd+/NpgxaJmnnZoyLOzTNYzyBfmcHUk7sht4doStRs9kKkEbmbYtiFpLei6uLfmBt6XJqag/KnrPoagYoA+tSBIK3rP/C5y/OS7PMNiGMbDBlfMYO9X+X9F8QgnyzkKS4TaWX+fVEwbsYhERUjW67qnPKhSq+Nntz6HvzIYJ8a9TdV2jmbCgjADFe7KIGfMfmTomHE08WpSrk5jLkf+Mvvpc8EYtsC20TNIsOENlKVe0wLjtqhp0epv20fa2EQYCJ9kmLh8DZzgccNE5Pl9bzgGQ7b7eW62oTzQ8elHAtgrdd5i0Eh95G51iHxw7YFGmUdudQkl7lA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DpCoffjM6zkDa/6CZrmX2JhVhAWG03XFdEfO7whCPmKD2pbqVbfc2t+e7xGbtuUtR/c1L99ApsUP9vRMSbdU6UJO3t1C6CKyKOwaSAGQmJym0g8sPz4q6cGpIytE6uVemKWJt6txxn3mMQQ+7qIZdLVQPfHE1P8sZG2tc03tPA4lECQJMMZJZ674o19cdws0PZPmG0QK4VrsBmNJkYZLgGN5qDZQsv07ysvhHb7BQcARFW1QZ7Oyqg/iPY1h4AiH3NritHTGeHYr3G4V08XiakwacVATwutuYCHIRAorYwvvzGzHqdZedFn/qOCPEkrh3T2xJxIZi18DloKzREU1Mg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>
  • Delivery-date: Fri, 24 Feb 2023 16:55:35 +0000
  • Ironport-data: A9a23:tycfZqs0FxVW5U+HRyu4VXlzTOfnVM9fMUV32f8akzHdYApBsoF/q tZmKTrXbP6OajT2e9ojO4vgpEMF7ZWAnYdmTQA9pCxjRi9G+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg3HVQ+IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4bKj51v0gnRkPaoQ5AWEyyFOZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwA2AUVxuJ1/yMxeigZfkytNoMB+TII9ZK0p1g5Wmx4fcOZ7nmGv+PwOACmTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0ovjv6xbLI5efTTLSlRtm+eq njL4CLSBRYCOcbE4TGE7mitlqnEmiaTtIc6ReLorKMz2AP7Kmo7LAI1TlKe/fSF0BCQdvlDF 0gSynsAov1nnKCsZpynN/Gim1aDuhMfQNtRVe4n8gaGyqnTywmcD2kACDVGbbQOpMIwADAny FKNt9foHiB09q2YT2qH8bWZpi/0PjIaRUcZfjMNRwYB59jloakwgwjJQ9IlF7S65vX6GDj2x y2BpQAkhqsUls8N3OOw+lWvqzirrJLYQxU14gjSV2SN4QZwZYrjbIutgXDS6fdbMI+YVB+Pp nECkMmFxP8CBteGkynlaO4KGreu5fqMLjzHqVFqFpglsT+q/haekZt45Th/IAJsLZwCcDqwO kvL41sNuNlUIWegarJxb8SpEcM2wKP8FNPjEPfJct5JZZs3fwiClM1zWXOtM6nWuBBEuckC1 V2zLK5A0V5y5Xxb8QeL
  • Ironport-hdrordr: A9a23:7TsmI66IPfuzx6aczwPXwKvXdLJyesId70hD6qkRc3xom6mj/P xG88536faZslwssRIb+OxoRpPufZq0z/cc3WB7B9uftWfd1leVEA==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 24/02/2023 2:48 pm, Oleksii Kurochko wrote:
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
> ---
>  xen/arch/riscv/setup.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c
> index 154bf3a0bc..593bb471a4 100644
> --- a/xen/arch/riscv/setup.c
> +++ b/xen/arch/riscv/setup.c
> @@ -24,6 +24,18 @@ static void test_macros_from_bug_h(void)
>      early_printk("WARN is most likely working\n");
>  }
>  
> +static void __init init_bss(void)
> +{
> +    extern char __bss_start;
> +    extern char __bss_end;
> +    char *bss = &__bss_start;
> +
> +    while ( bss < &__bss_end ) {
> +        *bss = 0;
> +        bss++;
> +    }
> +}
> +
>  void __init noreturn start_xen(void)
>  {
>      /*
> @@ -38,6 +50,8 @@ void __init noreturn start_xen(void)
>  
>      asm volatile( "mv %0, a1" : "=r" (dtb_base) );
>  
> +    init_bss();
> +
>      early_printk("Hello from C env\n");
>  
>      trap_init();

Zeroing the BSS needs to one of the earliest thing you do.  It really
does need to be before entering C, and needs to be as close to the start
of head.S as you can reasonably make it.

I'd put it even before loading sp in start.

Even like this, there are various things the compiler might do behind
your back which expect a) the BSS to already be zeroed, and b) not
change value unexpectedly.


Also, note:

arch/riscv/xen.lds.S-143-        . = ALIGN(POINTER_ALIGN);
arch/riscv/xen.lds.S:144:        __bss_end = .;

The POINTER_ALIGN there is specifically so you can depend on
__bss_{start,end} being suitably aligned to use a register-width store,
rather than using byte stores, which in 64bit means you've got 8x fewer
iterations.

~Andrew



 


Rackspace

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