[PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory

Luca Fancellu posted 5 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory
Posted by Luca Fancellu 2 months, 2 weeks ago
From: Penny Zheng <Penny.Zheng@arm.com>

In free_init_memory, we do not need to map the whole init section RW,
as only init text section is mapped RO in boot time.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
This is this one: https://patchwork.kernel.org/project/xen-devel/patch/20230626033443.2943270-19-Penny.Zheng@arm.com/
---
 xen/arch/arm/mmu/setup.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c
index 9664e85ee6c0..1b1d302c8788 100644
--- a/xen/arch/arm/mmu/setup.c
+++ b/xen/arch/arm/mmu/setup.c
@@ -7,6 +7,7 @@
 
 #include <xen/init.h>
 #include <xen/libfdt/libfdt.h>
+#include <xen/pfn.h>
 #include <xen/sections.h>
 #include <xen/sizes.h>
 #include <xen/vmap.h>
@@ -309,16 +310,17 @@ void *__init arch_vmap_virt_end(void)
 void free_init_memory(void)
 {
     paddr_t pa = virt_to_maddr(__init_begin);
+    unsigned long inittext_end = round_pgup((unsigned long)_einittext);
     unsigned long len = __init_end - __init_begin;
     uint32_t insn;
     unsigned int i, nr = len / sizeof(insn);
     uint32_t *p;
     int rc;
 
-    rc = modify_xen_mappings((unsigned long)__init_begin,
-                             (unsigned long)__init_end, PAGE_HYPERVISOR_RW);
+    rc = modify_xen_mappings((unsigned long)__init_begin, inittext_end,
+                             PAGE_HYPERVISOR_RW);
     if ( rc )
-        panic("Unable to map RW the init section (rc = %d)\n", rc);
+        panic("Unable to map RW the init text section (rc = %d)\n", rc);
 
     /*
      * From now on, init will not be used for execution anymore,
-- 
2.34.1
Re: [PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory
Posted by Julien Grall 2 months, 1 week ago
Hi Luca,

On 15/11/2024 10:50, Luca Fancellu wrote:
> From: Penny Zheng <Penny.Zheng@arm.com>
> 
> In free_init_memory, we do not need to map the whole init section RW,
> as only init text section is mapped RO in boot time.

So originally, this was done because the function was generic. But now 
this is MMU specific, we don't really gain that much during boot but 
will impair any work that would restrict some init further (for instance 
.init.rodata could be RO). So is it actually worth it?

> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>

Given the link below, why are Penny and Wei's signed-off-by are missing?

> ---
> This is this one: https://patchwork.kernel.org/project/xen-devel/patch/20230626033443.2943270-19-Penny.Zheng@arm.com/
> ---
>   xen/arch/arm/mmu/setup.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c
> index 9664e85ee6c0..1b1d302c8788 100644
> --- a/xen/arch/arm/mmu/setup.c
> +++ b/xen/arch/arm/mmu/setup.c
> @@ -7,6 +7,7 @@
>   
>   #include <xen/init.h>
>   #include <xen/libfdt/libfdt.h>
> +#include <xen/pfn.h>
>   #include <xen/sections.h>
>   #include <xen/sizes.h>
>   #include <xen/vmap.h>
> @@ -309,16 +310,17 @@ void *__init arch_vmap_virt_end(void)
>   void free_init_memory(void)
>   {
>       paddr_t pa = virt_to_maddr(__init_begin);
> +    unsigned long inittext_end = round_pgup((unsigned long)_einittext);
>       unsigned long len = __init_end - __init_begin;
>       uint32_t insn;
>       unsigned int i, nr = len / sizeof(insn);
>       uint32_t *p;
>       int rc;
>   
> -    rc = modify_xen_mappings((unsigned long)__init_begin,
> -                             (unsigned long)__init_end, PAGE_HYPERVISOR_RW);
> +    rc = modify_xen_mappings((unsigned long)__init_begin, inittext_end,
> +                             PAGE_HYPERVISOR_RW);
>       if ( rc )
> -        panic("Unable to map RW the init section (rc = %d)\n", rc);
> +        panic("Unable to map RW the init text section (rc = %d)\n", rc);
>   
>       /*
>        * From now on, init will not be used for execution anymore,

Cheers,

-- 
Julien Grall
Re: [PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory
Posted by Luca Fancellu 2 months, 1 week ago
Hi Julien,

> On 17 Nov 2024, at 17:58, Julien Grall <julien@xen.org> wrote:
> 
> Hi Luca,
> 
> On 15/11/2024 10:50, Luca Fancellu wrote:
>> From: Penny Zheng <Penny.Zheng@arm.com>
>> In free_init_memory, we do not need to map the whole init section RW,
>> as only init text section is mapped RO in boot time.
> 
> So originally, this was done because the function was generic. But now this is MMU specific, we don't really gain that much during boot but will impair any work that would restrict some init further (for instance .init.rodata could be RO). So is it actually worth it?

Probably not, I’ll drop this one.

> 
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> 
> Given the link below, why are Penny and Wei's signed-off-by are missing?

Internal policy, authorship is preserved though.

Cheers,
Luca