Skip to contentSkip to conversation

powerpc/mm: Invalidate partition table cache on host proc tbl base update

PATCH Applied Suraj Jitindar Singh 5 participants 11 messages Aug 3, 2017 – Aug 14, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/mm: Invalidate partition table cache on host proc tbl base update

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

---
 arch/powerpc/mm/pgtable-radix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/mm/pgtable-radix.c +2 -1
index 671a45d..1d5178f 100644
@@ -33,7 +33,8 @@ static int native_register_process_table(unsigned long base, unsigned long pg_sz
 {
 	unsigned long patb1 = base | table_size | PATB_GR;
 
-	partition_tb->patb1 = cpu_to_be64(patb1);
+	mmu_partition_table_set_entry(0, be64_to_cpu(partition_tb->patb0),
+				      patb1);
 	return 0;
 }
 
Signature · 1 line
2.9.4
#1 lore raw
Quoted 7 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

Quoted 5 lines

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

Without this patch the kernel will:
[ ] work normally
[ ] randomly crash
[ ] catch fire

?

cheers

#2 lore raw
Quoted 15 lines · Michael Ellerman
Quoted 7 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

Quoted 5 lines

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

Quoted 4 lines

Without this patch the kernel will:
[ ] work normally
[ ] randomly crash
[ ] catch fire

I think we get lucky because OPAL added a "flush the whole world" to opal_reinit_cpus() but this patch seems to improve general code "correctness".

Cheers,
Ben.

#3 lore raw
Quoted 27 lines · Benjamin Herrenschmidt
Quoted 21 lines · Michael Ellerman
Quoted 12 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling
the function native_register_process_table(). Currently this just sets
the entry in memory and is missing a proceeding cache invalidation
instruction. Any update to the partition table should be followed by a
cache invalidation instruction specifying invalidation of the caching of
any partition table entries (RIC = 2, PRS = 0).

Quoted 6 lines

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry().
Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

Quoted 4 lines

Without this patch the kernel will:
 [ ] work normally
 [ ] randomly crash
 [ ] catch fire

Quoted 7 lines

I think we get lucky because OPAL added a "flush the whole world" to opal_reinit_cpus() but this patch seems to improve general code "correctness".

Cheers,
Ben.

I guess there's the possibility of:
[x] randomly crash

This is required to run a powernv kernel as a guest because we need to know when it's updated its process table location.

#4 lore raw
Quoted 6 lines · Suraj Jitindar Singh

I guess there's the possibility of:
[x] randomly crash

This is required to run a powernv kernel as a guest because we need to know when it's updated its process table location.

You mean in qemu full emu ? powernv kernels don't run as guest do they ?

Cheers,
Ben.

#5 lore raw
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 4 lines · Suraj Jitindar Singh

I guess there's the possibility of:
[x] randomly crash

Quoted 7 lines
Quoted 3 lines

This is required to run a powernv kernel as a guest because we need to
know when it's updated its process table location.

You mean in qemu full emu ? powernv kernels don't run as guest do they
?

For now they don't... :p

Quoted 4 lines

Cheers,
Ben.

#6 lore raw
In reply to Suraj Jitindar Singh
Quoted 27 lines · Suraj Jitindar Singh
Quoted 26 lines · Benjamin Herrenschmidt
Quoted 25 lines · Michael Ellerman

Suraj Jitindar Singh <[email protected]> writes:
=20

Quoted 10 lines

The host process table base is stored in the partition table by calling
the function native_register_process_table(). Currently this just sets
the entry in memory and is missing a proceeding cache invalidation
instruction. Any update to the partition table should be followed by a
cache invalidation instruction specifying invalidation of the caching of

Quoted 8 lines

any partition table entries (RIC =3D 2, PRS =3D 0).
=20
We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry().
Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

=20
Without this patch the kernel will:
=C2=A0[ ] work normally
=C2=A0[ ] randomly crash
=C2=A0[ ] catch fire

Quoted 7 lines
Quoted 4 lines

=20
I think we get lucky because OPAL added a "flush the whole world" to opal_reinit_cpus() but this patch seems to improve general code "correctness".

I guess there's the possibility of:
[x] randomly crash

But you haven't actually see any right?

Quoted 2 lines

This is required to run a powernv kernel as a guest because we need to know when it's updated its process table location.

Which doesn't currently work for other reasons :)

cheers

Reviewed-by on v1 1/1
#7 lore raw
In reply to Suraj Jitindar Singh
Quoted 7 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

Quoted 6 lines

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

Quoted 21 lines
---
 arch/powerpc/mm/pgtable-radix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/mm/pgtable-radix.c +2 -1
index 671a45d..1d5178f 100644
@@ -33,7 +33,8 @@ static int native_register_process_table(unsigned long base, unsigned long pg_sz
 {
 	unsigned long patb1 = base | table_size | PATB_GR;
 
-	partition_tb->patb1 = cpu_to_be64(patb1);
+	mmu_partition_table_set_entry(0, be64_to_cpu(partition_tb->patb0),
+				      patb1);
 	return 0;
 }
 
Signature · 1 line
2.9.4
#8 lore raw
In reply to Suraj Jitindar Singh
Quoted 23 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

---
 arch/powerpc/mm/pgtable-radix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/mm/pgtable-radix.c +0 -0
index 671a45d..1d5178f 100644

arch/powerpc/mm/pgtable-radix.c static int native_register_process_table(unsigned long base, unsigned long pg_sz · line 37

Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +2 -1
@@ -33,7 +33,8 @@ static int native_register_process_table(unsigned long base, unsigned long pg_sz
 {
 	unsigned long patb1 = base | table_size | PATB_GR;
 
-	partition_tb->patb1 = cpu_to_be64(patb1);
+	mmu_partition_table_set_entry(0, be64_to_cpu(partition_tb->patb0),
+				      patb1);

This is really a bit gross.

Can we agree on whether partition_tb is an array or not?

How about ...

cheers

arch/powerpc/mm/pgtable-radix.c +6 -2
index c1185c8ecb22..5d8be076f8e5 100644
@@ -28,9 +28,13 @@
 static int native_register_process_table(unsigned long base, unsigned long pg_sz,
                                         unsigned long table_size)
 {
-       unsigned long patb1 = base | table_size | PATB_GR;
+       unsigned long patb0, patb1;
+
+       patb0 = be64_to_cpu(partition_tb[0].patb0);
+       patb1 = base | table_size | PATB_GR;
+
+       mmu_partition_table_set_entry(0, patb0, patb1);
 
-       partition_tb->patb1 = cpu_to_be64(patb1);
        return 0;
 }
#9 lore raw
Quoted 37 lines · Michael Ellerman
Quoted 35 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling
the function native_register_process_table(). Currently this just sets
the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a
cache invalidation instruction specifying invalidation of the caching of
any partition table entries (RIC = 2, PRS = 0).

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry().
Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

---
 arch/powerpc/mm/pgtable-radix.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/mm/pgtable-radix.c +0 -0
index 671a45d..1d5178f 100644
@@ -33,7 +33,8 @@ static int native_register_process_table(unsigned

long base, unsigned long pg_sz
 {
  unsigned long patb1 = base | table_size | PATB_GR;

arch/powerpc/mm/pgtable-radix.c +1 -1
-	partition_tb->patb1 = cpu_to_be64(patb1);
+	mmu_partition_table_set_entry(0, be64_to_cpu(partition_tb-
Quoted 6 lines

arch/powerpc/mm/pgtable-radix.c

Quoted 2 lines
Quoted 1 line

patb0),

arch/powerpc/mm/pgtable-radix.c +1 -0
+				      patb1);

This is really a bit gross.

Can we agree on whether partition_tb is an array or not?

Well it is an array, it's just we only ever want the first element in this function. That being said we might as well access it as an array to make that clear.

Quoted 22 lines

How about ...

cheers

arch/powerpc/mm/pgtable-radix.c +6 -1
index c1185c8ecb22..5d8be076f8e5 100644
@@ -28,9 +28,13 @@
  static int native_register_process_table(unsigned long base,
 unsigned long pg_sz,
                                          unsigned long table_size)
  {
-       unsigned long patb1 = base | table_size | PATB_GR;
+       unsigned long patb0, patb1;
+
+       patb0 = be64_to_cpu(partition_tb[0].patb0);
+       patb1 = base | table_size | PATB_GR;
+
+       mmu_partition_table_set_entry(0, patb0, patb1);
Quoted 4 lines


-       partition_tb->patb1 = cpu_to_be64(patb1);
        return 0;
 }

Looks good :)

#10 lore raw
In reply to Suraj Jitindar Singh
Quoted 7 lines · Suraj Jitindar Singh

The host process table base is stored in the partition table by calling the function native_register_process_table(). Currently this just sets the entry in memory and is missing a proceeding cache invalidation instruction. Any update to the partition table should be followed by a cache invalidation instruction specifying invalidation of the caching of any partition table entries (RIC = 2, PRS = 0).

Quoted 8 lines

We already have a function to update the partition table with the required cache invalidation instructions - mmu_partition_table_set_entry(). Update the native_register_process_table() function to call mmu_partition_table_set_entry(), this ensures all appropriate invalidation will be performed.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/7cd2a8695ef9c31e8f51773f0de9e6

cheers