linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/vdso: Fix VDSO unmap check
@ 2020-11-03 17:13 Laurent Dufour
  2022-03-09 15:51 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Dufour @ 2020-11-03 17:13 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Thomas Gleixner, Christophe Leroy,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras

The check introduced by the commit 83d3f0e90c6c ("powerpc/mm: tracking vDSO
remap") is wrong and is missing some partial unmaps of the VDSO.

To be complete the check needs the base and end address of the
VDSO. Currently only the base is available in the mm_context of a task, but
the end address can easily be computed because the size of VDSO is
constant. However, there are 2 sizes for 32 or 64 bits task and they are
stored in static variables in arch/powerpc/kernel/vdso.c.

Exporting a new function called vdso_pages() to get the number of pages of
the VDSO based on the static variables from arch/powerpc/kernel/vdso.c.

Fixes: 83d3f0e90c6c ("powerpc/mm: tracking vDSO remap")

Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/include/asm/mmu_context.h | 18 ++++++++++++++++--
 arch/powerpc/kernel/vdso.c             | 14 ++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h
index e02aa793420b..ced80897b7a1 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -259,11 +259,25 @@ static inline void enter_lazy_tlb(struct mm_struct *mm,
 
 extern void arch_exit_mmap(struct mm_struct *mm);
 
+extern int vdso_pages(void);
 static inline void arch_unmap(struct mm_struct *mm,
 			      unsigned long start, unsigned long end)
 {
-	if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
-		mm->context.vdso_base = 0;
+	unsigned long vdso_end;
+
+	if (mm->context.vdso_base) {
+		/*
+		 * case 1   >  |     VDSO    |  <
+		 * case 2   >  |           < |
+		 * case 3      |  >        < |
+		 * case 4      |  >          |  <
+		 */
+		vdso_end = mm->context.vdso_base;
+		vdso_end += vdso_pages() << PAGE_SHIFT;
+
+		if (start < vdso_end && mm->context.vdso_base < end)
+			mm->context.vdso_base = 0;
+	}
 }
 
 #ifdef CONFIG_PPC_MEM_KEYS
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index 8dad44262e75..9defa35a1eba 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -117,6 +117,20 @@ struct lib64_elfinfo
 	unsigned long	text;
 };
 
+/*
+ * Return the number of pages of the VDSO for the current task.
+ */
+int vdso_pages(void)
+{
+	int vdso_pages = vdso32_pages;
+
+#ifdef CONFIG_PPC64
+	if (!is_32bit_task())
+		vdso_pages = vdso64_pages;
+#endif
+
+	return vdso_pages + 1; /* Add the data page */
+}
 
 /*
  * This is called from binfmt_elf, we create the special vma for the
-- 
2.29.2


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

* Re: [PATCH] powerpc/vdso: Fix VDSO unmap check
  2020-11-03 17:13 [PATCH] powerpc/vdso: Fix VDSO unmap check Laurent Dufour
@ 2022-03-09 15:51 ` Christophe Leroy
  2022-03-10 16:18   ` Laurent Dufour
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2022-03-09 15:51 UTC (permalink / raw)
  To: Laurent Dufour, linuxppc-dev
  Cc: linux-kernel, Thomas Gleixner, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras



Le 03/11/2020 à 18:13, Laurent Dufour a écrit :
> The check introduced by the commit 83d3f0e90c6c ("powerpc/mm: tracking vDSO
> remap") is wrong and is missing some partial unmaps of the VDSO.
> 
> To be complete the check needs the base and end address of the
> VDSO. Currently only the base is available in the mm_context of a task, but
> the end address can easily be computed because the size of VDSO is
> constant. However, there are 2 sizes for 32 or 64 bits task and they are
> stored in static variables in arch/powerpc/kernel/vdso.c.
> 
> Exporting a new function called vdso_pages() to get the number of pages of
> the VDSO based on the static variables from arch/powerpc/kernel/vdso.c.
> 
> Fixes: 83d3f0e90c6c ("powerpc/mm: tracking vDSO remap")
> 
> Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> ---
>   arch/powerpc/include/asm/mmu_context.h | 18 ++++++++++++++++--
>   arch/powerpc/kernel/vdso.c             | 14 ++++++++++++++
>   2 files changed, 30 insertions(+), 2 deletions(-)

This patch doesn't apply anymore.

In the meantime there's a pending series from Dmitry, so I'm wondering 
if it is worth rebasing this series or not.

Christophe

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

* Re: [PATCH] powerpc/vdso: Fix VDSO unmap check
  2022-03-09 15:51 ` Christophe Leroy
@ 2022-03-10 16:18   ` Laurent Dufour
  0 siblings, 0 replies; 3+ messages in thread
From: Laurent Dufour @ 2022-03-10 16:18 UTC (permalink / raw)
  To: Christophe Leroy, linuxppc-dev
  Cc: linux-kernel, Thomas Gleixner, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras

On 09/03/2022, 16:51:04, Christophe Leroy wrote:
> 
> 
> Le 03/11/2020 à 18:13, Laurent Dufour a écrit :
>> The check introduced by the commit 83d3f0e90c6c ("powerpc/mm: tracking vDSO
>> remap") is wrong and is missing some partial unmaps of the VDSO.
>>
>> To be complete the check needs the base and end address of the
>> VDSO. Currently only the base is available in the mm_context of a task, but
>> the end address can easily be computed because the size of VDSO is
>> constant. However, there are 2 sizes for 32 or 64 bits task and they are
>> stored in static variables in arch/powerpc/kernel/vdso.c.
>>
>> Exporting a new function called vdso_pages() to get the number of pages of
>> the VDSO based on the static variables from arch/powerpc/kernel/vdso.c.
>>
>> Fixes: 83d3f0e90c6c ("powerpc/mm: tracking vDSO remap")
>>
>> Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
>> Reported-by: Thomas Gleixner <tglx@linutronix.de>
>> Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> Cc: Paul Mackerras <paulus@samba.org>
>> ---
>>   arch/powerpc/include/asm/mmu_context.h | 18 ++++++++++++++++--
>>   arch/powerpc/kernel/vdso.c             | 14 ++++++++++++++
>>   2 files changed, 30 insertions(+), 2 deletions(-)
> 
> This patch doesn't apply anymore.
> 
> In the meantime there's a pending series from Dmitry, so I'm wondering if
> it is worth rebasing this series or not.

I agee, the Dimitry's series looks better, addressing the issue in the
common code for all the architectures.

Laurent.

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

end of thread, other threads:[~2022-03-10 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03 17:13 [PATCH] powerpc/vdso: Fix VDSO unmap check Laurent Dufour
2022-03-09 15:51 ` Christophe Leroy
2022-03-10 16:18   ` Laurent Dufour

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