linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/64s: Fix crashes on Power9 DD1 with radix MMU and STRICT_RWX
@ 2017-10-16  5:21 Balbir Singh
  2017-11-14 11:12 ` [v2] " Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Balbir Singh @ 2017-10-16  5:21 UTC (permalink / raw)
  To: mpe; +Cc: linuxppc-dev

When using the radix MMU on Power9 DD1, to work around a hardware
problem, radix__pte_update() is required to do a two stage update of
the PTE. First we write a zero value into the PTE, then we flush the
TLB, and then we write the new PTE value.

In the normal case that works OK, but it does not work if we're
updating the PTE that maps the code we're executing, because the
mapping is removed by the TLB flush and we can no longer execute from
it. Unfortunately the STRICT_RWX code needs to do exactly that.

The exact symptoms when we hit this case vary, sometimes we print an
oops and then get stuck after that, but I've also seen a machine just
get stuck continually page faulting with no oops printed. The variance
is presumably due to the exact layout of the text and the page size
used for the mappings. In all cases we are unable to boot to a shell.

There are possible solutions such as creating a second mapping of the
TLB flush code, executing from that, and then jumping back to the
original. However we don't want to add that level of complexity for a
DD1 work around.

So just detect that we're running on Power9 DD1 and refrain from
changing the permissions, effectively disabling STRICT_RWX on Power9
DD1.

Fixes: 7614ff3 ("powerpc/mm/radix: Implement STRICT_RWX/mark_rodata_ro() for Radix")

Cc: stable@vger.kernel.org

Reported-by: Andrew Jeffery <andrew@aj.id.au>
[Changelog as suggested by Michael Ellerman <mpe@ellerman.id.au>]
Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---

 Changelog v2
 - Rephrase the comments and changelog as suggested by mpe

 arch/powerpc/mm/pgtable-radix.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 39c252b54d16..cfbbee941a76 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -169,6 +169,16 @@ void radix__mark_rodata_ro(void)
 {
 	unsigned long start, end;
 
+	/*
+	 * mark_rodata_ro() will mark itself as !writable at some point.
+	 * Due to DD1 workaround in radix__pte_update(), we'll end up with
+	 * an invalid pte and the system will crash quite severly.
+	 */
+	if (cpu_has_feature(CPU_FTR_POWER9_DD1)) {
+		pr_warn("Warning: Unable to mark rodata read only on P9 DD1\n");
+		return;
+	}
+
 	start = (unsigned long)_stext;
 	end = (unsigned long)__init_begin;
 
-- 
2.13.6

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

* Re: [v2] powerpc/64s: Fix crashes on Power9 DD1 with radix MMU and STRICT_RWX
  2017-10-16  5:21 [PATCH v2] powerpc/64s: Fix crashes on Power9 DD1 with radix MMU and STRICT_RWX Balbir Singh
@ 2017-11-14 11:12 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2017-11-14 11:12 UTC (permalink / raw)
  To: Balbir Singh; +Cc: linuxppc-dev

On Mon, 2017-10-16 at 05:21:35 UTC, Balbir Singh wrote:
> When using the radix MMU on Power9 DD1, to work around a hardware
> problem, radix__pte_update() is required to do a two stage update of
> the PTE. First we write a zero value into the PTE, then we flush the
> TLB, and then we write the new PTE value.
> 
> In the normal case that works OK, but it does not work if we're
> updating the PTE that maps the code we're executing, because the
> mapping is removed by the TLB flush and we can no longer execute from
> it. Unfortunately the STRICT_RWX code needs to do exactly that.
> 
> The exact symptoms when we hit this case vary, sometimes we print an
> oops and then get stuck after that, but I've also seen a machine just
> get stuck continually page faulting with no oops printed. The variance
> is presumably due to the exact layout of the text and the page size
> used for the mappings. In all cases we are unable to boot to a shell.
> 
> There are possible solutions such as creating a second mapping of the
> TLB flush code, executing from that, and then jumping back to the
> original. However we don't want to add that level of complexity for a
> DD1 work around.
> 
> So just detect that we're running on Power9 DD1 and refrain from
> changing the permissions, effectively disabling STRICT_RWX on Power9
> DD1.
> 
> Fixes: 7614ff3 ("powerpc/mm/radix: Implement STRICT_RWX/mark_rodata_ro() for Radix")
> 
> Cc: stable@vger.kernel.org
> 
> Reported-by: Andrew Jeffery <andrew@aj.id.au>
> [Changelog as suggested by Michael Ellerman <mpe@ellerman.id.au>]
> Signed-off-by: Balbir Singh <bsingharora@gmail.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f79ad50ea3c73fb1ea5b09e95c864e

cheers

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

end of thread, other threads:[~2017-11-14 11:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16  5:21 [PATCH v2] powerpc/64s: Fix crashes on Power9 DD1 with radix MMU and STRICT_RWX Balbir Singh
2017-11-14 11:12 ` [v2] " Michael Ellerman

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