diff mbox series

[v1,3/8] powerpc/fsl_booke: Take exec flag into account when setting TLBCAMs

Message ID 5467044e59f27f9fcf709b9661779e3ce5f784f6.1634292136.git.christophe.leroy@csgroup.eu (mailing list archive)
State Accepted
Headers show
Series [v1,1/8] powerpc/booke: Disable STRICT_KERNEL_RWX, DEBUG_PAGEALLOC and KFENCE | expand
Related show

Commit Message

Christophe Leroy Oct. 15, 2021, 10:02 a.m. UTC
Don't force MAS3_SX and MAS3_UX at all time. Take into account the
exec flag.

While at it, fix a couple of closeby style problems (indent with space
and unnecessary parenthesis), it keeps more readability.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/mm/nohash/fsl_book3e.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Christophe Leroy Oct. 25, 2021, 9:57 p.m. UTC | #1
On 22/10/2021 08:36, kernel test robot wrote:
> Hi Christophe,
> 
> I love your patch! Yet something to improve:
> 
> [auto build test ERROR on powerpc/next]
> [also build test ERROR on v5.15-rc6 next-20211021]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-booke-Disable-STRICT_KERNEL_RWX-DEBUG_PAGEALLOC-and-KFENCE/20211015-180535
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
> config: powerpc-tqm8541_defconfig (attached as .config)
> compiler: powerpc-linux-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>          chmod +x ~/bin/make.cross
>          # https://github.com/0day-ci/linux/commit/159ed9a0b39712475dfebed64d1bb9387a0b9ad5
>          git remote add linux-review https://github.com/0day-ci/linux
>          git fetch --no-tags linux-review Christophe-Leroy/powerpc-booke-Disable-STRICT_KERNEL_RWX-DEBUG_PAGEALLOC-and-KFENCE/20211015-180535
>          git checkout 159ed9a0b39712475dfebed64d1bb9387a0b9ad5
>          # save the attached .config to linux build tree
>          mkdir build_dir
>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/mm/nohash/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>     arch/powerpc/mm/nohash/fsl_book3e.c:63:15: error: no previous prototype for 'tlbcam_sz' [-Werror=missing-prototypes]
>        63 | unsigned long tlbcam_sz(int idx)
>           |               ^~~~~~~~~
>     arch/powerpc/mm/nohash/fsl_book3e.c: In function 'settlbcam':
>>> arch/powerpc/mm/nohash/fsl_book3e.c:126:40: error: '_PAGE_BAP_SX' undeclared (first use in this function)
>       126 |         TLBCAM[index].MAS3 |= (flags & _PAGE_BAP_SX) ? MAS3_SX : 0;
>           |                                        ^~~~~~~~~~~~
>     arch/powerpc/mm/nohash/fsl_book3e.c:126:40: note: each undeclared identifier is reported only once for each function it appears in
>     cc1: all warnings being treated as errors
> 

Thanks Robot for reporting that.

The problem is not trivial and is in fact deeper, we have a 
misdefinition of _PAGE_EXEC on book3e.

I sent a v2 which adds two patches at the begining of the series to 
clear that problem, then I fixed this patch 3 (which has become patch 5) 
to use _PAGE_EXEC instead of _PAGE_BAP_SX.

Christophe

> 
> vim +/_PAGE_BAP_SX +126 arch/powerpc/mm/nohash/fsl_book3e.c
> 
>     114	
>     115		TLBCAM[index].MAS0 = MAS0_TLBSEL(1) | MAS0_ESEL(index) | MAS0_NV(index+1);
>     116		TLBCAM[index].MAS1 = MAS1_VALID | MAS1_IPROT | MAS1_TSIZE(tsize) | MAS1_TID(pid);
>     117		TLBCAM[index].MAS2 = virt & PAGE_MASK;
>     118	
>     119		TLBCAM[index].MAS2 |= (flags & _PAGE_WRITETHRU) ? MAS2_W : 0;
>     120		TLBCAM[index].MAS2 |= (flags & _PAGE_NO_CACHE) ? MAS2_I : 0;
>     121		TLBCAM[index].MAS2 |= (flags & _PAGE_COHERENT) ? MAS2_M : 0;
>     122		TLBCAM[index].MAS2 |= (flags & _PAGE_GUARDED) ? MAS2_G : 0;
>     123		TLBCAM[index].MAS2 |= (flags & _PAGE_ENDIAN) ? MAS2_E : 0;
>     124	
>     125		TLBCAM[index].MAS3 = (phys & MAS3_RPN) | MAS3_SR;
>   > 126		TLBCAM[index].MAS3 |= (flags & _PAGE_BAP_SX) ? MAS3_SX : 0;
>     127		TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_SW : 0;
>     128		if (mmu_has_feature(MMU_FTR_BIG_PHYS))
>     129			TLBCAM[index].MAS7 = (u64)phys >> 32;
>     130	
>     131		/* Below is unlikely -- only for large user pages or similar */
>     132		if (pte_user(__pte(flags))) {
>     133			TLBCAM[index].MAS3 |= MAS3_UR;
>     134			TLBCAM[index].MAS3 |= (flags & _PAGE_EXEC) ? MAS3_UX : 0;
>     135			TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_UW : 0;
>     136		}
>     137	
>     138		tlbcam_addrs[index].start = virt;
>     139		tlbcam_addrs[index].limit = virt + size - 1;
>     140		tlbcam_addrs[index].phys = phys;
>     141	}
>     142	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
>
diff mbox series

Patch

diff --git a/arch/powerpc/mm/nohash/fsl_book3e.c b/arch/powerpc/mm/nohash/fsl_book3e.c
index 03dacbe940e5..fdf1029e62f0 100644
--- a/arch/powerpc/mm/nohash/fsl_book3e.c
+++ b/arch/powerpc/mm/nohash/fsl_book3e.c
@@ -122,15 +122,17 @@  static void settlbcam(int index, unsigned long virt, phys_addr_t phys,
 	TLBCAM[index].MAS2 |= (flags & _PAGE_GUARDED) ? MAS2_G : 0;
 	TLBCAM[index].MAS2 |= (flags & _PAGE_ENDIAN) ? MAS2_E : 0;
 
-	TLBCAM[index].MAS3 = (phys & MAS3_RPN) | MAS3_SX | MAS3_SR;
-	TLBCAM[index].MAS3 |= ((flags & _PAGE_RW) ? MAS3_SW : 0);
+	TLBCAM[index].MAS3 = (phys & MAS3_RPN) | MAS3_SR;
+	TLBCAM[index].MAS3 |= (flags & _PAGE_BAP_SX) ? MAS3_SX : 0;
+	TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_SW : 0;
 	if (mmu_has_feature(MMU_FTR_BIG_PHYS))
 		TLBCAM[index].MAS7 = (u64)phys >> 32;
 
 	/* Below is unlikely -- only for large user pages or similar */
 	if (pte_user(__pte(flags))) {
-	   TLBCAM[index].MAS3 |= MAS3_UX | MAS3_UR;
-	   TLBCAM[index].MAS3 |= ((flags & _PAGE_RW) ? MAS3_UW : 0);
+		TLBCAM[index].MAS3 |= MAS3_UR;
+		TLBCAM[index].MAS3 |= (flags & _PAGE_EXEC) ? MAS3_UX : 0;
+		TLBCAM[index].MAS3 |= (flags & _PAGE_RW) ? MAS3_UW : 0;
 	}
 
 	tlbcam_addrs[index].start = virt;