Skip to contentSkip to conversation

Revert broken C0_Pagegrain[PG_IEC] support.

PATCH In review David Daney 4 participants 9 messages Dec 20, 2014 MIPS

lore
Share & tools
lore
#0 lore raw

cover Revert broken C0_Pagegrain[PG_IEC] support.

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

 arch/mips/include/asm/mipsregs.h | 1 -
 arch/mips/kernel/cpu-probe.c     | 9 ---------
 arch/mips/kernel/traps.c         | 7 -------
 arch/mips/mm/tlbex.c             | 4 ++--
 4 files changed, 2 insertions(+), 19 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI exceptions"

From: David Daney <[email protected]>

This reverts commit 5890f70f15c52d0204a578422f8da828a0ba1096.

The patch was not tested, It sets PG_IEC in cpu-probe. But this value is clobbered in tlb_init() so the system is never configured to take the RIXI specific exceptions, and we end up in an endless loop in handle_tlbl because that code is not expecting the XI condition.

---
 arch/mips/kernel/traps.c | 7 -------
 arch/mips/mm/tlbex.c     | 4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/mips/kernel/traps.c +0 -7
index ad3d203..722ed75 100644
@@ -90,7 +90,6 @@ extern asmlinkage void handle_mt(void);
 extern asmlinkage void handle_dsp(void);
 extern asmlinkage void handle_mcheck(void);
 extern asmlinkage void handle_reserved(void);
-extern void tlb_do_page_fault_0(void);
 
 void (*board_be_init)(void);
 int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
@@ -2205,12 +2204,6 @@ void __init trap_init(void)
 		set_except_vector(15, handle_fpe);
 
 	set_except_vector(16, handle_ftlb);
-
-	if (cpu_has_rixiex) {
-		set_except_vector(19, tlb_do_page_fault_0);
-		set_except_vector(20, tlb_do_page_fault_0);
-	}
-
 	set_except_vector(21, handle_msa);
 	set_except_vector(22, handle_mdmx);
 
arch/mips/mm/tlbex.c +2 -2
index 3978a3d..c9e0150 100644
@@ -1934,7 +1934,7 @@ static void build_r4000_tlb_load_handler(void)
 	if (m4kc_tlbp_war())
 		build_tlb_probe_entry(&p);
 
-	if (cpu_has_rixi && !cpu_has_rixiex) {
+	if (cpu_has_rixi) {
 		/*
 		 * If the page is not _PAGE_VALID, RI or XI could not
 		 * have triggered it.  Skip the expensive test..
@@ -2001,7 +2001,7 @@ static void build_r4000_tlb_load_handler(void)
 	build_pte_present(&p, &r, wr.r1, wr.r2, wr.r3, label_nopage_tlbl);
 	build_tlb_probe_entry(&p);
 
-	if (cpu_has_rixi && !cpu_has_rixiex) {
+	if (cpu_has_rixi) {
 		/*
 		 * If the page is not _PAGE_VALID, RI or XI could not
 		 * have triggered it.  Skip the expensive test..
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH 2/2 Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

In reply to David Daney

From: David Daney <[email protected]>

This reverts commit 6575b1d4173eaeff6742a2c6dcbd835bb052952b.

It sets PG_IEC in cpu-probe. But this value is clobbered in tlb_init() so the system is never configured to take the RIXI specific exceptions. Caos ensues.

---
 arch/mips/include/asm/mipsregs.h | 1 -
 arch/mips/kernel/cpu-probe.c     | 9 ---------
 2 files changed, 10 deletions(-)
arch/mips/include/asm/mipsregs.h +0 -1
index 5e4aef3..dfdca76 100644
@@ -265,7 +265,6 @@
 #define PG_XIE		(_ULCAST_(1) <<	 30)
 #define PG_ELPA		(_ULCAST_(1) <<	 29)
 #define PG_ESP		(_ULCAST_(1) <<	 28)
-#define PG_IEC		(_ULCAST_(1) <<  27)
 
 /*
  * R4x00 interrupt enable / cause bits
arch/mips/kernel/cpu-probe.c +0 -9
index 5342674..63ace78 100644
@@ -531,15 +531,6 @@ static void decode_configs(struct cpuinfo_mips *c)
 
 	mips_probe_watch_registers(c);
 
-	if (cpu_has_rixi) {
-		/* Enable the RIXI exceptions */
-		write_c0_pagegrain(read_c0_pagegrain() | PG_IEC);
-		back_to_back_c0_hazard();
-		/* Verify the IEC bit is set */
-		if (read_c0_pagegrain() & PG_IEC)
-			c->options |= MIPS_CPU_RIXIEX;
-	}
-
 #ifndef CONFIG_MIPS_CPS
 	if (cpu_has_mips_r2) {
 		c->core = get_ebase_cpunum();
Signature · 1 line
1.7.11.7
#3 lore raw
In reply to David Daney
Quoted 16 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 6 lines
  arch/mips/include/asm/mipsregs.h | 1 -
  arch/mips/kernel/cpu-probe.c     | 9 ---------
  arch/mips/kernel/traps.c         | 7 -------
  arch/mips/mm/tlbex.c             | 4 ++--
  4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

#4 lore raw
Quoted 17 lines · Leonid Yegoshin
Quoted 16 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 7 lines
Quoted 6 lines
  arch/mips/include/asm/mipsregs.h | 1 -
  arch/mips/kernel/cpu-probe.c     | 9 ---------
  arch/mips/kernel/traps.c         | 7 -------
  arch/mips/mm/tlbex.c             | 4 ++--
  4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

arch/mips/mm/tlb-r4k.c +1 -1
index aa6e4b3b2fe2..ed18efd9374b 100644
@@ -602,7 +602,7 @@ void __cpuinit tlb_init(void)
 #ifdef CONFIG_64BIT
                pg |= PG_ELPA;
 #endif
-               write_c0_pagegrain(pg);
+               write_c0_pagegrain(pg | read_c0_pagegrain());
        }
        mtc0_tlbw_hazard();
#5 lore raw
Quoted 38 lines · Leonid Yegoshin

Date: Fri, 19 Dec 2014 16:49:28 -0800
From: Leonid Yegoshin <[email protected]>
To: David Daney <[email protected]>, [email protected],
[email protected]
Subject: Re: [PATCH 0/2] Revert broken C0_Pagegrain[PG_IEC] support.
Content-Type: text/plain; charset="windows-1252"; format=flowed

Quoted 24 lines · Leonid Yegoshin
Quoted 16 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 6 lines
 arch/mips/include/asm/mipsregs.h | 1 -
 arch/mips/kernel/cpu-probe.c     | 9 ---------
 arch/mips/kernel/traps.c         | 7 -------
 arch/mips/mm/tlbex.c             | 4 ++--
 4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

arch/mips/mm/tlb-r4k.c +0 -0
index aa6e4b3b2fe2..ed18efd9374b 100644

arch/mips/mm/tlb-r4k.c void __cpuinit tlb_init(void) · line 605

Quoted 5 lines
arch/mips/mm/tlb-r4k.c +1 -1
@@ -602,7 +602,7 @@ void __cpuinit tlb_init(void)
 #ifdef CONFIG_64BIT
                pg |= PG_ELPA;
 #endif
-               write_c0_pagegrain(pg);
+               write_c0_pagegrain(pg | read_c0_pagegrain());

Simpler:
set_c0_pagegrain(pg);

Ralf

#6 lore raw
Quoted 34 lines · Ralf Baechle
Quoted 33 lines · Leonid Yegoshin

Date: Fri, 19 Dec 2014 16:49:28 -0800
From: Leonid Yegoshin <[email protected]>
To: David Daney <[email protected]>, [email protected],
[email protected]
Subject: Re: [PATCH 0/2] Revert broken C0_Pagegrain[PG_IEC] support.
Content-Type: text/plain; charset="windows-1252"; format=flowed

Quoted 24 lines · Leonid Yegoshin
Quoted 16 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 6 lines
  arch/mips/include/asm/mipsregs.h | 1 -
  arch/mips/kernel/cpu-probe.c     | 9 ---------
  arch/mips/kernel/traps.c         | 7 -------
  arch/mips/mm/tlbex.c             | 4 ++--
  4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

Quoted 13 lines

arch/mips/mm/tlb-r4k.c void __cpuinit tlb_init(void) · line 605

Quoted 10 lines
arch/mips/mm/tlb-r4k.c +1 -1
index aa6e4b3b2fe2..ed18efd9374b 100644
@@ -602,7 +602,7 @@ void __cpuinit tlb_init(void)
  #ifdef CONFIG_64BIT
                 pg |= PG_ELPA;
  #endif
-               write_c0_pagegrain(pg);
+               write_c0_pagegrain(pg | read_c0_pagegrain());

Simpler:
set_c0_pagegrain(pg);

No. That is exactly how it was broken before.

It is possible that you would want:

	if (cpu_has_rixiex)
		pg |= PG_IEC;
	set_c0_pagegrain(pg);

But that wasn't really tested. It seems to work though.

I will send another patch.

David Daney

Quoted 4 lines

Ralf

#7 lore raw
Quoted 58 lines · David Daney
Quoted 47 lines · Ralf Baechle
Quoted 39 lines · Leonid Yegoshin

Date: Fri, 19 Dec 2014 16:49:28 -0800
From: Leonid Yegoshin <[email protected]>
To: David Daney <[email protected]>, [email protected],
[email protected]
Subject: Re: [PATCH 0/2] Revert broken C0_Pagegrain[PG_IEC] support.
Content-Type: text/plain; charset="windows-1252"; format=flowed

Quoted 25 lines · Leonid Yegoshin
Quoted 17 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports
RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 6 lines
  arch/mips/include/asm/mipsregs.h | 1 -
  arch/mips/kernel/cpu-probe.c     | 9 ---------
  arch/mips/kernel/traps.c         | 7 -------
  arch/mips/mm/tlbex.c             | 4 ++--
  4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

arch/mips/mm/tlb-r4k.c +0 -0
index aa6e4b3b2fe2..ed18efd9374b 100644

arch/mips/mm/tlb-r4k.c void __cpuinit tlb_init(void) · line 605

Quoted 5 lines
arch/mips/mm/tlb-r4k.c +1 -1
@@ -602,7 +602,7 @@ void __cpuinit tlb_init(void)
  #ifdef CONFIG_64BIT
                 pg |= PG_ELPA;
  #endif
-               write_c0_pagegrain(pg);
+               write_c0_pagegrain(pg | read_c0_pagegrain());

Simpler:

Quoted 1 line
          set_c0_pagegrain(pg);

No. That is exactly how it was broken before.

It is possible that you would want:

    if (cpu_has_rixiex)
        pg |= PG_IEC;
    set_c0_pagegrain(pg);
Quoted 5 lines

But that wasn't really tested. It seems to work though.

I will send another patch.

David Daney

Well, to honest, it is extensively tested on MIPS R6 because it have PG_IEC read-only == 1 (non-switchable OFF) And on other cores which has no PG_IEC at all, of course.

As for your concern about set_c0_pagegrain(pg) - it sets 2 or 3 bits in pagegrain but doesn't clear the rest which was before with a single write_c0_pagegrain(pg) and any switchable bit comes down.

#8 lore raw
In reply to Leonid Yegoshin
Quoted 17 lines · Leonid Yegoshin
Quoted 16 lines · David Daney

From: David Daney <[email protected]>

The two patches reverted here break eXecute-Inhibit (XI) memory protection support. Before the patches we get SIGSEGV when attempting to execute in non-executable memory, after the patches we loop forever in handle_tlbl.

It is probably possible to make C0_Pagegrain[PG_IEC] work, but I think the most prudent thing is to revert these patches, and then only reapply something that works after it has been well tested.

David Daney (2):
Revert "MIPS: Use dedicated exception handler if CPU supports RI/XI
exceptions"
Revert "MIPS: kernel: cpu-probe: Detect unique RI/XI exceptions"

Quoted 7 lines
Quoted 6 lines
  arch/mips/include/asm/mipsregs.h | 1 -
  arch/mips/kernel/cpu-probe.c     | 9 ---------
  arch/mips/kernel/traps.c         | 7 -------
  arch/mips/mm/tlbex.c             | 4 ++--
  4 files changed, 2 insertions(+), 19 deletions(-)

Well, it may be have sense just to fix tlb_init() instead.

I have more confidence in going back to a working configuration. My simple tests on OCTEON tell me that it is working again.

Somebody adding working support for C0_Pagegrain[PG_IEC] would want to do much more testing across many different CPUs to be able to assert that it was tested and working.

I would be happy to test any patches adding this support on a variety of different OCTEON CPU cores, but I don't have access to anything MIPS/img may have that supports this feature.

David Daney.