linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Set correct size for VDSO code mapping
@ 2024-09-29  7:49 Huacai Chen
  2024-09-29  8:19 ` Xi Ruoyao
  0 siblings, 1 reply; 2+ messages in thread
From: Huacai Chen @ 2024-09-29  7:49 UTC (permalink / raw)
  To: Arnd Bergmann, Huacai Chen
  Cc: loongarch, linux-arch, Xuefeng Li, Guo Ren, Xuerui Wang,
	Jiaxun Yang, linux-kernel, loongson-kernel, Huacai Chen

The current size of VDSO code mapping is hardcoded to PAGE_SIZE. This
cannot work for 4KB page size after commit 18efd0b10e0fd77 ("LoongArch:
vDSO: Wire up getrandom() vDSO implementation") because the code size
increases to 8KB. Thus set the code mapping size to its real size, i.e.
PAGE_ALIGN(vdso_end - vdso_start).

Fixes: 18efd0b10e0fd77 ("LoongArch: vDSO: Wire up getrandom() vDSO implementation")
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/kernel/vdso.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
index f6fcc52aefae..7e0cc7f5e1ed 100644
--- a/arch/loongarch/kernel/vdso.c
+++ b/arch/loongarch/kernel/vdso.c
@@ -85,7 +85,6 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
 
 struct loongarch_vdso_info vdso_info = {
 	.vdso = vdso_start,
-	.size = PAGE_SIZE,
 	.code_mapping = {
 		.name = "[vdso]",
 		.pages = vdso_pages,
@@ -103,7 +102,7 @@ static int __init init_vdso(void)
 	unsigned long i, cpu, pfn;
 
 	BUG_ON(!PAGE_ALIGNED(vdso_info.vdso));
-	BUG_ON(!PAGE_ALIGNED(vdso_info.size));
+	vdso_info.size = PAGE_ALIGN(vdso_end - vdso_start);
 
 	for_each_possible_cpu(cpu)
 		vdso_pdata[cpu].node = cpu_to_node(cpu);
-- 
2.43.5


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

* Re: [PATCH] LoongArch: Set correct size for VDSO code mapping
  2024-09-29  7:49 [PATCH] LoongArch: Set correct size for VDSO code mapping Huacai Chen
@ 2024-09-29  8:19 ` Xi Ruoyao
  0 siblings, 0 replies; 2+ messages in thread
From: Xi Ruoyao @ 2024-09-29  8:19 UTC (permalink / raw)
  To: Huacai Chen, Arnd Bergmann, Huacai Chen
  Cc: loongarch, linux-arch, Xuefeng Li, Guo Ren, Xuerui Wang,
	Jiaxun Yang, linux-kernel, loongson-kernel

On Sun, 2024-09-29 at 15:49 +0800, Huacai Chen wrote:
> The current size of VDSO code mapping is hardcoded to PAGE_SIZE. This
> cannot work for 4KB page size after commit 18efd0b10e0fd77 ("LoongArch:
> vDSO: Wire up getrandom() vDSO implementation") because the code size
> increases to 8KB. Thus set the code mapping size to its real size, i.e.
> PAGE_ALIGN(vdso_end - vdso_start).

I get:

$ size vdso.so
   text	   data	    bss	    dec	   
hex	filename
   3716	    328	      0	   4044	   
fcc	vdso.so

So it "just" fits in 4 KiB, and of course it may exceed 4 KiB with a
different compiler or some kernel configuration affecting code
generation like CONFIG_INIT_STACK_ALL_ZERO or
CONFIG_ZERO_CALL_USED_REGS).

I remember I've checked `size vdso.so` before but I cannot remember why
I didn't realize a problem here.  Sorry for the stupidity.

Reviewed-by: Xi Ruoyao <xry111@xry111.site>

> 
> Fixes: 18efd0b10e0fd77 ("LoongArch: vDSO: Wire up getrandom() vDSO implementation")
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  arch/loongarch/kernel/vdso.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
> index f6fcc52aefae..7e0cc7f5e1ed 100644
> --- a/arch/loongarch/kernel/vdso.c
> +++ b/arch/loongarch/kernel/vdso.c
> @@ -85,7 +85,6 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
>  
>  struct loongarch_vdso_info vdso_info = {
>  	.vdso = vdso_start,
> -	.size = PAGE_SIZE,
>  	.code_mapping = {
>  		.name = "[vdso]",
>  		.pages = vdso_pages,
> @@ -103,7 +102,7 @@ static int __init init_vdso(void)
>  	unsigned long i, cpu, pfn;
>  
>  	BUG_ON(!PAGE_ALIGNED(vdso_info.vdso));
> -	BUG_ON(!PAGE_ALIGNED(vdso_info.size));
> +	vdso_info.size = PAGE_ALIGN(vdso_end - vdso_start);
>  
>  	for_each_possible_cpu(cpu)
>  		vdso_pdata[cpu].node = cpu_to_node(cpu);

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

end of thread, other threads:[~2024-09-29  8:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-29  7:49 [PATCH] LoongArch: Set correct size for VDSO code mapping Huacai Chen
2024-09-29  8:19 ` Xi Ruoyao

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).