Skip to contentSkip to conversation

powerpc: mm: fixup preempt undefflow with huge pages

PATCH Superseded Sebastian Andrzej Siewior 5 participants 10 messages Mar 7, 2016 – Mar 30, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: mm: fixup preempt undefflow with huge pages

hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Tiejun Chen <[email protected]>
---
 arch/powerpc/mm/hugetlbpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/hugetlbpage.c +1 -1
index 744e24bcb85c..9e8919b39640 100644
@@ -414,7 +414,7 @@ static void hugepd_free(struct mmu_gather *tlb, void *hugepte)
 {
 	struct hugepd_freelist **batchp;
 
-	batchp = this_cpu_ptr(&hugepd_freelist_cur);
+	batchp = get_cpu_ptr(&hugepd_freelist_cur);
 
 	if (atomic_read(&tlb->mm->mm_users) < 2 ||
 	    cpumask_equal(mm_cpumask(tlb->mm),
Signature · 1 line
2.7.0
#1 lore raw
Quoted 30 lines · Sebastian Andrzej Siewior

[ text/plain ]
hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Tiejun Chen <[email protected]>
---
 arch/powerpc/mm/hugetlbpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/hugetlbpage.c +0 -0
index 744e24bcb85c..9e8919b39640 100644

arch/powerpc/mm/hugetlbpage.c static void hugepd_free(struct mmu_gather *tlb, void *hugepte) · line 420

Quoted 8 lines
arch/powerpc/mm/hugetlbpage.c +1 -1
@@ -414,7 +414,7 @@ static void hugepd_free(struct mmu_gather *tlb, void *hugepte)
 {
 	struct hugepd_freelist **batchp;
 
-	batchp = this_cpu_ptr(&hugepd_freelist_cur);
+	batchp = get_cpu_ptr(&hugepd_freelist_cur);
 
 	if (atomic_read(&tlb->mm->mm_users) < 2 ||
 	    cpumask_equal(mm_cpumask(tlb->mm),

IMHO it would better if we do

batchp = get_cpu_var(hugepd_freelist_cpu);

so that it match the existing

put_cpu_var(hugepd_freelist_cur);

While you are there, can you also fix the wrong indentation on line 423 ?

-aneesh

#2 lore raw
Quoted 5 lines · Aneesh Kumar K.V

Sebastian Andrzej Siewior <[email protected]> writes:

While you are there, can you also fix the wrong indentation on line 423
?

 .../...

Also this looks like stable material no ?

Cheers,
Ben.

#3 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 5 lines · Aneesh Kumar K.V

Sebastian Andrzej Siewior <[email protected]> writes:

While you are there, can you also fix the wrong indentation on line 423
?

.../...

Also this looks like stable material no ?

Yes, I had a stable tag attached. I am going to resend it with the additional changes Aneesh asked for.

Quoted 3 lines

Cheers,
Ben.

Sebastian

#4 lore raw

PATCH v2 1/1 powerpc: mm: fixup preempt undefflow with huge pages

In reply to Benjamin Herrenschmidt

hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>

---
v1=E2=80=A6v2: - use get_cpu_var() instead of get_cpu_ptr()
- correct indentation of put_cpu_var()

 arch/powerpc/mm/hugetlbpage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/hugetlbpage.c +0 -0
index 744e24bcb85c..4a811ca7ac9d 100644
@@ -414,13 +414,13 @@ static void hugepd_free(struct mmu_gather *tlb, void =

*hugepte)
{
struct hugepd_freelist **batchp;
=20
- batchp =3D this_cpu_ptr(&hugepd_freelist_cur);
+ batchp =3D &get_cpu_var(hugepd_freelist_cur);
=20
if (atomic_read(&tlb->mm->mm_users) < 2 ||
cpumask_equal(mm_cpumask(tlb->mm),
cpumask_of(smp_processor_id()))) {
kmem_cache_free(hugepte_cache, hugepte);
- put_cpu_var(hugepd_freelist_cur);
+ put_cpu_var(hugepd_freelist_cur);
return;
}
=20
--=20
2.7.0

Reviewed-by on v2 1/1
#5 lore raw
Quoted 6 lines · Sebastian Andrzej Siewior

[ text/plain ]
hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Quoted 9 lines

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

arch/powerpc/mm/hugetlbpage.c static void hugepd_free(struct mmu_gather *tlb, voi=

Quoted 17 lines
Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>

---
v1=E2=80=A6v2: - use get_cpu_var() instead of get_cpu_ptr()
- correct indentation of put_cpu_var()

 arch/powerpc/mm/hugetlbpage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/hugetlbpage.c +0 -0
index 744e24bcb85c..4a811ca7ac9d 100644
@@ -414,13 +414,13 @@ static void hugepd_free(struct mmu_gather *tlb, voi=

d *hugepte)

Quoted 17 lines
arch/powerpc/mm/hugetlbpage.c +0 -0
 {
 	struct hugepd_freelist **batchp;

=20=20

arch/powerpc/mm/hugetlbpage.c +1 -1
-	batchp =3D this_cpu_ptr(&hugepd_freelist_cur);
+	batchp =3D &get_cpu_var(hugepd_freelist_cur);

=20=20

arch/powerpc/mm/hugetlbpage.c +1 -1
 	if (atomic_read(&tlb->mm->mm_users) < 2 ||
 	    cpumask_equal(mm_cpumask(tlb->mm),
 			  cpumask_of(smp_processor_id()))) {
 		kmem_cache_free(hugepte_cache, hugepte);
-        put_cpu_var(hugepd_freelist_cur);
+		put_cpu_var(hugepd_freelist_cur);
 		return;
 	}

=20=20
--=20
2.7.0

#6 lore raw
Quoted 1 line · Aneesh Kumar K.V

Sebastian Andrzej Siewior <[email protected]> writes:

*ping*
http://patchwork.ozlabs.org/patch/593943/

Quoted 27 lines
Quoted 6 lines

[ text/plain ]
hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Quoted 9 lines

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

=20

=20

Quoted 9 lines
Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>

---
v1=E2=80=A6v2: - use get_cpu_var() instead of get_cpu_ptr()
- correct indentation of put_cpu_var()

Quoted 4 lines

arch/powerpc/mm/hugetlbpag=

Quoted 4 lines
 arch/powerpc/mm/hugetlbpage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/hugetlbpag= renamed from arch/powerpc/mm/hugetlbpage.c +0 -0

e.c

Quoted 4 lines

arch/powerpc/mm/hugetlbpage.c static void hugepd_free(struct mmu_gather *tlb, v=

Quoted 4 lines

index 744e24bcb85c..4a811ca7ac9d 100644

arch/powerpc/mm/hugetlbpage.c +0 -0
@@ -414,13 +414,13 @@ static void hugepd_free(struct mmu_gather *tlb, v=

oid *hugepte)

Quoted 7 lines
Quoted 7 lines
arch/powerpc/mm/hugetlbpage.c +0 -0
 {
 	struct hugepd_freelist **batchp;

=20

arch/powerpc/mm/hugetlbpage.c +1 -1
-	batchp =3D this_cpu_ptr(&hugepd_freelist_cur);
+	batchp =3D &get_cpu_var(hugepd_freelist_cur);

=20
if (atomic_read(&tlb->mm->mm_users) < 2 ||

Quoted 8 lines
Quoted 8 lines
arch/powerpc/mm/hugetlbpage.c +1 -1
 	    cpumask_equal(mm_cpumask(tlb->mm),
 			  cpumask_of(smp_processor_id()))) {
 		kmem_cache_free(hugepte_cache, hugepte);
-        put_cpu_var(hugepd_freelist_cur);
+		put_cpu_var(hugepd_freelist_cur);
 		return;
 	}

=20

Sebastian

#8 lore raw
Quoted 4 lines · Michael Ellerman

The merge window just closed, I'm still recovering.

I've got it in my fixes branch locally, I'll probably push that today to linux-next.

Thank you.

Quoted 3 lines

cheers

Sebastian

reviewer Applied
#9 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 14 lines · Sebastian Siewior

hugepd_free() used __get_cpu_var() once. Nothing ensured that the code accessing the variable did not migrate from one CPU to another and soon this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
Replace __get_cpu_var with get_cpu_var"). So we had it fixed.

Christoph Lameter was doing his __get_cpu_var() replaces and forgot PowerPC. Then he noticed this and sent his fixed up batch again which got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").

The careful reader will noticed one little detail: get_cpu_var() got replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does a preempt_enable() and nothing that does preempt_disable() so we underflow the preempt counter.

Quoted 6 lines
Cc Benjamin Herrenschmidt <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/08a5bb2921e490939f78f38fd0

cheers