linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: remove [_text, _stext) from kernel code resource
@ 2021-12-03 14:14 Mark-PK Tsai
  2021-12-07 15:57 ` Mike Rapoport
  0 siblings, 1 reply; 6+ messages in thread
From: Mark-PK Tsai @ 2021-12-03 14:14 UTC (permalink / raw)
  To: linux, matthias.bgg, rmk+kernel
  Cc: arnd, akpm, linux, rppt, wangkefeng.wang, linux-arm-kernel,
	linux-kernel, linux-mediatek, yj.chiang, mark-pk.tsai

Remove the [_text, _stext) from Kernel Code.
Although there are some startup code in head.text, they
are freed to the buddy system after kernel boot.

And we have memory protection mechanism use this
which have false alarm when some other IPs doing dma
if the dma page frame is in the [_text, _stext).

Below are my iomem resource and reserved memory information:
console:/ # grep Kernel /proc/iomem
  20208000-219fffff : Kernel code
  21b00000-21c2e76f : Kernel data

console:/ # cat /sys/kernel/debug/memblock/reserved
0: 0x20201000..0x20207fff
1: 0x20300000..0x21c2e76f

Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
---
 arch/arm/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 284a80c0b6e1..85ffc9501e38 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -851,7 +851,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
 	struct resource *res;
 	u64 i;
 
-	kernel_code.start   = virt_to_phys(_text);
+	kernel_code.start   = virt_to_phys(_stext);
 	kernel_code.end     = virt_to_phys(__init_begin - 1);
 	kernel_data.start   = virt_to_phys(_sdata);
 	kernel_data.end     = virt_to_phys(_end - 1);
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] arm: remove [_text, _stext) from kernel code resource
  2021-12-03 14:14 [PATCH] arm: remove [_text, _stext) from kernel code resource Mark-PK Tsai
@ 2021-12-07 15:57 ` Mike Rapoport
  2021-12-08  2:26   ` Mark-PK Tsai
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2021-12-07 15:57 UTC (permalink / raw)
  To: Mark-PK Tsai
  Cc: linux, matthias.bgg, rmk+kernel, arnd, akpm, linux,
	wangkefeng.wang, linux-arm-kernel, linux-kernel, linux-mediatek,
	yj.chiang

On Fri, Dec 03, 2021 at 10:14:16PM +0800, Mark-PK Tsai wrote:
> Remove the [_text, _stext) from Kernel Code.
> Although there are some startup code in head.text, they
> are freed to the buddy system after kernel boot.

Hmm, I don't see it is being freed anywhere. Can you elaborate when and how
the range [_text, _stext) is freed?

> And we have memory protection mechanism use this
> which have false alarm when some other IPs doing dma
> if the dma page frame is in the [_text, _stext).
> 
> Below are my iomem resource and reserved memory information:
> console:/ # grep Kernel /proc/iomem
>   20208000-219fffff : Kernel code
>   21b00000-21c2e76f : Kernel data
> 
> console:/ # cat /sys/kernel/debug/memblock/reserved
> 0: 0x20201000..0x20207fff
> 1: 0x20300000..0x21c2e76f
 
What are the addresses of _text and _stext in your configuration? 
What these dumps are supposed to show here?

> Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
> ---
>  arch/arm/kernel/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index 284a80c0b6e1..85ffc9501e38 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -851,7 +851,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
>  	struct resource *res;
>  	u64 i;
>  
> -	kernel_code.start   = virt_to_phys(_text);
> +	kernel_code.start   = virt_to_phys(_stext);
>  	kernel_code.end     = virt_to_phys(__init_begin - 1);
>  	kernel_data.start   = virt_to_phys(_sdata);
>  	kernel_data.end     = virt_to_phys(_end - 1);
> -- 
> 2.18.0
> 

-- 
Sincerely yours,
Mike.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] arm: remove [_text, _stext) from kernel code resource
  2021-12-07 15:57 ` Mike Rapoport
@ 2021-12-08  2:26   ` Mark-PK Tsai
  2021-12-08  9:43     ` Mike Rapoport
  0 siblings, 1 reply; 6+ messages in thread
From: Mark-PK Tsai @ 2021-12-08  2:26 UTC (permalink / raw)
  To: rppt
  Cc: akpm, arnd, linux-arm-kernel, linux-kernel, linux-mediatek,
	linux, linux, mark-pk.tsai, matthias.bgg, rmk+kernel,
	wangkefeng.wang, yj.chiang

> On Fri, Dec 03, 2021 at 10:14:16PM +0800, Mark-PK Tsai wrote:
> > Remove the [_text, _stext) from Kernel Code.
> > Although there are some startup code in head.text, they
> > are freed to the buddy system after kernel boot.
>
> Hmm, I don't see it is being freed anywhere. Can you elaborate when and how
> the range [_text, _stext) is freed?

arm_memblock_init() reserve [KERNEL_START, KERNEL_END) which are defined as following.

#define KERNEL_START            _stext
#define KERNEL_END              _end

free_low_memory_core_early() free all the non-reserved range in lowmem,
so the range [_text, _stext) is also freed here.

>
> > And we have memory protection mechanism use this
> > which have false alarm when some other IPs doing dma
> > if the dma page frame is in the [_text, _stext).
> >
> > Below are my iomem resource and reserved memory information:
> > console:/ # grep Kernel /proc/iomem
> >   20208000-219fffff : Kernel code
> >   21b00000-21c2e76f : Kernel data
> >
> > console:/ # cat /sys/kernel/debug/memblock/reserved
> > 0: 0x20201000..0x20207fff
> > 1: 0x20300000..0x21c2e76f
>
> What are the addresses of _text and _stext in your configuration?

va	 pa
c0008000 20208000 _text
c0100000 20300000 _stext

>
> What these dumps are supposed to show here?
>

Below is the dump info after applied this patch.

console:/ # grep Kernel /proc/iomem
  20300000-219fffff : Kernel code
  21b00000-21c2e76f : Kernel data

console:/ # cat /sys/kernel/debug/memblock/reserved
0: 0x20201000..0x20207fff
1: 0x20300000..0x21c2e76f

The difference is that Kernel Code resource match the reserved memblock 1
which is reserved in arm_memblock_init().

>
> > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
> > ---
> >  arch/arm/kernel/setup.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> > index 284a80c0b6e1..85ffc9501e38 100644
> > --- a/arch/arm/kernel/setup.c
> > +++ b/arch/arm/kernel/setup.c
> > @@ -851,7 +851,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
> >  	struct resource *res;
> >  	u64 i;
> >
> > -	kernel_code.start   = virt_to_phys(_text);
> > +	kernel_code.start   = virt_to_phys(_stext);
> >  	kernel_code.end     = virt_to_phys(__init_begin - 1);
> >  	kernel_data.start   = virt_to_phys(_sdata);
> >  	kernel_data.end     = virt_to_phys(_end - 1);
> > --
> > 2.18.0
> >
>
> --
> Sincerely yours,
> Mike.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] arm: remove [_text, _stext) from kernel code resource
  2021-12-08  2:26   ` Mark-PK Tsai
@ 2021-12-08  9:43     ` Mike Rapoport
  2021-12-08 10:22       ` Mark-PK Tsai
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2021-12-08  9:43 UTC (permalink / raw)
  To: Mark-PK Tsai
  Cc: akpm, arnd, linux-arm-kernel, linux-kernel, linux-mediatek,
	linux, linux, matthias.bgg, rmk+kernel, wangkefeng.wang,
	yj.chiang

On Wed, Dec 08, 2021 at 10:26:23AM +0800, Mark-PK Tsai wrote:
> > On Fri, Dec 03, 2021 at 10:14:16PM +0800, Mark-PK Tsai wrote:
> > > Remove the [_text, _stext) from Kernel Code.
> > > Although there are some startup code in head.text, they
> > > are freed to the buddy system after kernel boot.
> >
> > Hmm, I don't see it is being freed anywhere. Can you elaborate when and how
> > the range [_text, _stext) is freed?
> 
> arm_memblock_init() reserve [KERNEL_START, KERNEL_END) which are defined as following.
> 
> #define KERNEL_START            _stext
> #define KERNEL_END              _end
> 
> free_low_memory_core_early() free all the non-reserved range in lowmem,
> so the range [_text, _stext) is also freed here.

Right, I've misread KERNEL_START as if it was _text...
 
> >
> > > And we have memory protection mechanism use this
> > > which have false alarm when some other IPs doing dma
> > > if the dma page frame is in the [_text, _stext).
> > >
> > > Below are my iomem resource and reserved memory information:
> > > console:/ # grep Kernel /proc/iomem
> > >   20208000-219fffff : Kernel code
> > >   21b00000-21c2e76f : Kernel data
> > >
> > > console:/ # cat /sys/kernel/debug/memblock/reserved
> > > 0: 0x20201000..0x20207fff
> > > 1: 0x20300000..0x21c2e76f
> >
> > What are the addresses of _text and _stext in your configuration?
> 
> va	 pa
> c0008000 20208000 _text
> c0100000 20300000 _stext
> 
> >
> > What these dumps are supposed to show here?
> >
> 
> Below is the dump info after applied this patch.
> 
> console:/ # grep Kernel /proc/iomem
>   20300000-219fffff : Kernel code
>   21b00000-21c2e76f : Kernel data
> 
> console:/ # cat /sys/kernel/debug/memblock/reserved
> 0: 0x20201000..0x20207fff
> 1: 0x20300000..0x21c2e76f
> 
> The difference is that Kernel Code resource match the reserved memblock 1
> which is reserved in arm_memblock_init().

For that I'd extend the reservation in arm_memblock_init() to include
[_text, _stext). 

Even if the code there is not needed after init, at least we'll keep this
consistent with other architectures.
 

-- 
Sincerely yours,
Mike.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] arm: remove [_text, _stext) from kernel code resource
  2021-12-08  9:43     ` Mike Rapoport
@ 2021-12-08 10:22       ` Mark-PK Tsai
  2021-12-16 15:14         ` Mark-PK Tsai
  0 siblings, 1 reply; 6+ messages in thread
From: Mark-PK Tsai @ 2021-12-08 10:22 UTC (permalink / raw)
  To: rppt
  Cc: akpm, arnd, linux-arm-kernel, linux-kernel, linux-mediatek,
	linux, linux, mark-pk.tsai, matthias.bgg, rmk+kernel,
	wangkefeng.wang, yj.chiang

> On Wed, Dec 08, 2021 at 10:26:23AM +0800, Mark-PK Tsai wrote:
> > > On Fri, Dec 03, 2021 at 10:14:16PM +0800, Mark-PK Tsai wrote:
> > > > Remove the [_text, _stext) from Kernel Code.
> > > > Although there are some startup code in head.text, they
> > > > are freed to the buddy system after kernel boot.
> > >
> > > Hmm, I don't see it is being freed anywhere. Can you elaborate when and how
> > > the range [_text, _stext) is freed?
> > 
> > arm_memblock_init() reserve [KERNEL_START, KERNEL_END) which are defined as following.
> > 
> > #define KERNEL_START            _stext
> > #define KERNEL_END              _end
> > 
> > free_low_memory_core_early() free all the non-reserved range in lowmem,
> > so the range [_text, _stext) is also freed here.
> 
> Right, I've misread KERNEL_START as if it was _text...
>  
> > >
> > > > And we have memory protection mechanism use this
> > > > which have false alarm when some other IPs doing dma
> > > > if the dma page frame is in the [_text, _stext).
> > > >
> > > > Below are my iomem resource and reserved memory information:
> > > > console:/ # grep Kernel /proc/iomem
> > > >   20208000-219fffff : Kernel code
> > > >   21b00000-21c2e76f : Kernel data
> > > >
> > > > console:/ # cat /sys/kernel/debug/memblock/reserved
> > > > 0: 0x20201000..0x20207fff
> > > > 1: 0x20300000..0x21c2e76f
> > >
> > > What are the addresses of _text and _stext in your configuration?
> > 
> > va	 pa
> > c0008000 20208000 _text
> > c0100000 20300000 _stext
> > 
> > >
> > > What these dumps are supposed to show here?
> > >
> > 
> > Below is the dump info after applied this patch.
> > 
> > console:/ # grep Kernel /proc/iomem
> >   20300000-219fffff : Kernel code
> >   21b00000-21c2e76f : Kernel data
> > 
> > console:/ # cat /sys/kernel/debug/memblock/reserved
> > 0: 0x20201000..0x20207fff
> > 1: 0x20300000..0x21c2e76f
> > 
> > The difference is that Kernel Code resource match the reserved memblock 1
> > which is reserved in arm_memblock_init().
> 
> For that I'd extend the reservation in arm_memblock_init() to include
> [_text, _stext). 
> 
> Even if the code there is not needed after init, at least we'll keep this
> consistent with other architectures.
>  

Extending the reservation in arm_memblock_init() will consume up to SECTION_SIZE
memory for SECTION_SIZE alignment when CONFIG_STRICT_KERNEL_RWX=y.
So we really don't want to extend the reservation because it affect
the low RAM devices.

And arm64_memblock_init() also reserve [_stext, _end) in the recent kernel.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] arm: remove [_text, _stext) from kernel code resource
  2021-12-08 10:22       ` Mark-PK Tsai
@ 2021-12-16 15:14         ` Mark-PK Tsai
  0 siblings, 0 replies; 6+ messages in thread
From: Mark-PK Tsai @ 2021-12-16 15:14 UTC (permalink / raw)
  To: mark-pk.tsai
  Cc: akpm, arnd, linux-arm-kernel, linux-kernel, linux-mediatek,
	linux, linux, matthias.bgg, rmk+kernel, rppt, wangkefeng.wang,
	yj.chiang

> > On Wed, Dec 08, 2021 at 10:26:23AM +0800, Mark-PK Tsai wrote:
> > > > On Fri, Dec 03, 2021 at 10:14:16PM +0800, Mark-PK Tsai wrote:
> > > > > Remove the [_text, _stext) from Kernel Code.
> > > > > Although there are some startup code in head.text, they
> > > > > are freed to the buddy system after kernel boot.
> > > >
> > > > Hmm, I don't see it is being freed anywhere. Can you elaborate when and how
> > > > the range [_text, _stext) is freed?
> > > 
> > > arm_memblock_init() reserve [KERNEL_START, KERNEL_END) which are defined as following.
> > > 
> > > #define KERNEL_START            _stext
> > > #define KERNEL_END              _end
> > > 
> > > free_low_memory_core_early() free all the non-reserved range in lowmem,
> > > so the range [_text, _stext) is also freed here.
> > 
> > Right, I've misread KERNEL_START as if it was _text...
> >  
> > > >
> > > > > And we have memory protection mechanism use this
> > > > > which have false alarm when some other IPs doing dma
> > > > > if the dma page frame is in the [_text, _stext).
> > > > >
> > > > > Below are my iomem resource and reserved memory information:
> > > > > console:/ # grep Kernel /proc/iomem
> > > > >   20208000-219fffff : Kernel code
> > > > >   21b00000-21c2e76f : Kernel data
> > > > >
> > > > > console:/ # cat /sys/kernel/debug/memblock/reserved
> > > > > 0: 0x20201000..0x20207fff
> > > > > 1: 0x20300000..0x21c2e76f
> > > >
> > > > What are the addresses of _text and _stext in your configuration?
> > > 
> > > va	 pa
> > > c0008000 20208000 _text
> > > c0100000 20300000 _stext
> > > 
> > > >
> > > > What these dumps are supposed to show here?
> > > >
> > > 
> > > Below is the dump info after applied this patch.
> > > 
> > > console:/ # grep Kernel /proc/iomem
> > >   20300000-219fffff : Kernel code
> > >   21b00000-21c2e76f : Kernel data
> > > 
> > > console:/ # cat /sys/kernel/debug/memblock/reserved
> > > 0: 0x20201000..0x20207fff
> > > 1: 0x20300000..0x21c2e76f
> > > 
> > > The difference is that Kernel Code resource match the reserved memblock 1
> > > which is reserved in arm_memblock_init().
> > 
> > For that I'd extend the reservation in arm_memblock_init() to include
> > [_text, _stext). 
> > 
> > Even if the code there is not needed after init, at least we'll keep this
> > consistent with other architectures.
> >  
> 
> Extending the reservation in arm_memblock_init() will consume up to SECTION_SIZE
> memory for SECTION_SIZE alignment when CONFIG_STRICT_KERNEL_RWX=y.
> So we really don't want to extend the reservation because it affect
> the low RAM devices.
> 
> And arm64_memblock_init() also reserve [_stext, _end) in the recent kernel.

Hi,

Is there anything wrong with this patch?
Either extend the reserved range or remove the head.text from iomem resource
can fix the issue.
So if you have any concern about it please let me know.

Thanks!


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-16 15:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 14:14 [PATCH] arm: remove [_text, _stext) from kernel code resource Mark-PK Tsai
2021-12-07 15:57 ` Mike Rapoport
2021-12-08  2:26   ` Mark-PK Tsai
2021-12-08  9:43     ` Mike Rapoport
2021-12-08 10:22       ` Mark-PK Tsai
2021-12-16 15:14         ` Mark-PK Tsai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).