[PATCH] powerpc/code-patching: Relax verification of patchability

2021-11-25 Thread Christophe Leroy
Commit 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of
patchability") introduced a stricter verification of the patched
area by checking it is proper kernel text.

But as least two usages of patch_instruction() fall outside:
- Code patching selftests, which use stack and vmalloc space.
- Ftrace

So for the time being, partially revert commit 8b8a8f0ab3f5 and add
a onetime warning:

  Running code patching self-tests ...
  patch_instruction() called on invalid text address 0xe1011e58 from 
test_code_patching+0x34/0xd6c

Reported-by: Sachin Sant 
Reported-by: Stephen Rothwell 
Cc: Nicholas Piggin 
Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of 
patchability")
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/lib/code-patching.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 1dd636a85cc1..c87eea773930 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -190,9 +190,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst 
instr)
 int patch_instruction(u32 *addr, struct ppc_inst instr)
 {
/* Make sure we aren't patching a freed init section */
-   if (!kernel_text_address((unsigned long)addr))
+   if (system_state >= SYSTEM_FREEING_INITMEM && 
init_section_contains(addr, 4))
return 0;
 
+   if (!kernel_text_address((unsigned long)addr))
+   pr_warn_once("%s() called on invalid text address 0x%p from 
%pS\n",
+__func__, addr, __builtin_return_address(0));
+
return do_patch_instruction(addr, instr);
 }
 NOKPROBE_SYMBOL(patch_instruction);
-- 
2.33.1



Re: [PATCH v4 00/17] powerpc: Make hash MMU code build configurable

2021-11-25 Thread Christophe Leroy




Le 26/11/2021 à 01:55, Nicholas Piggin a écrit :

Excerpts from Christophe Leroy's message of November 26, 2021 3:35 am:



Le 25/11/2021 à 17:35, Christophe Leroy a écrit :



Le 25/11/2021 à 13:50, Nicholas Piggin a écrit :

Now that there's a platform that can make good use of it, here's
a series that can prevent the hash MMU code being built for 64s
platforms that don't need it.


# CONFIG_PPC_64S_HASH_MMU is not set


:1559:2: warning: #warning syscall futex_waitv not implemented
[-Wcpp]
arch/powerpc/platforms/cell/spu_base.c: In function '__spu_kernel_slb':
arch/powerpc/platforms/cell/spu_base.c:215:38: error: 'mmu_linear_psize'
undeclared (first use in this function); did you mean 'mmu_virtual_psize'?
    215 | llp = mmu_psize_defs[mmu_linear_psize].sllp;
    |  ^~~~
    |  mmu_virtual_psize
arch/powerpc/platforms/cell/spu_base.c:215:38: note: each undeclared
identifier is reported only once for each function it appears in
make[3]: *** [scripts/Makefile.build:287:
arch/powerpc/platforms/cell/spu_base.o] Error 1
make[2]: *** [scripts/Makefile.build:549: arch/powerpc/platforms/cell]
Error 2
make[1]: *** [scripts/Makefile.build:549: arch/powerpc/platforms] Error 2
make: *** [Makefile:1846: arch/powerpc] Error 2





With CONFIG_SPU_BASE removed, the above voids and I get to the final
link with the following errors:


This is building cell platform with POWER9 CPU and !HASH?


I took ppc64_defconfig, changed CPU to POWER9 and removed VIRTUALIZATION 
and removed CONFIG_PPC_64S_HASH_MMU.




We don't have to make that build, just prevent the config. I had that in
a previous version which also had platforms select hash, but we went to
just CPU. But now there's no constraint that prevents cell+POWER9 even
though it doesn't make sense.

Not sure the best way to fix it. I'll think about it.



Force selection of CONFIG_PPC_64S_HASH_MMU by the CELL platform ?


Re: [PATCH] powerpc/pseries/vas: Don't print an error when VAS is unavailable

2021-11-25 Thread Cédric Le Goater

On 11/26/21 06:21, Nicholas Piggin wrote:

KVM does not support VAS so guests always print a useless error on boot

 vas: HCALL(398) error -2, query_type 0, result buffer 0x57f2000

Change this to only print the message if the error is not H_FUNCTION.



Just being curious, why is it even called since "ibm,compression" should
not be exposed in the DT ?

C.



Signed-off-by: Nicholas Piggin 
---
  arch/powerpc/platforms/pseries/vas.c | 11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/vas.c 
b/arch/powerpc/platforms/pseries/vas.c
index b043e3936d21..734523e2272f 100644
--- a/arch/powerpc/platforms/pseries/vas.c
+++ b/arch/powerpc/platforms/pseries/vas.c
@@ -151,8 +151,15 @@ int h_query_vas_capabilities(const u64 hcall, u8 
query_type, u64 result)
if (rc == H_SUCCESS)
return 0;
  
-	pr_err("HCALL(%llx) error %ld, query_type %u, result buffer 0x%llx\n",

-   hcall, rc, query_type, result);
+   /* H_FUNCTION means HV does not support VAS so don't print an error */
+   if (rc != H_FUNCTION) {
+   pr_err("%s error %ld, query_type %u, result buffer 0x%llx\n",
+   (hcall == H_QUERY_VAS_CAPABILITIES) ?
+   "H_QUERY_VAS_CAPABILITIES" :
+   "H_QUERY_NX_CAPABILITIES",
+   rc, query_type, result);
+   }
+
return -EIO;
  }
  EXPORT_SYMBOL_GPL(h_query_vas_capabilities);





[powerpc/merge] ftrace warning while running stress_code_patching

2021-11-25 Thread Sachin Sant
While running stress_code_patching.sh (powerpc/mm selftest) against
latest powerpc/merge branch (5.16.0-rc2-g2dbc3a3e8fc1) following
warning is seen:

Reverting following patch allows the test to run successfully.
commit 8b8a8f0ab3f5 :
powerpc/code-patching: Improve verification of patchability

I did try the 3 patch series [1] (powerpc/code-patching) posted by Nick, but 
that does not
seem to fix the problem.

ftrace-powerpc: Unexpected call sequence at 1d3f5e8d: 4801c5ad 2c23
[ ftrace bug ]
ftrace failed to modify 
[] fuse_len_args+0x4/0x80 [fuse]
 actual:   ad:c5:01:48
Setting ftrace call site to call ftrace function
ftrace record flags: 8001
(1)  
expected tramp: c0082494
[ cut here ]
WARNING: CPU: 18 PID: 1991307 at kernel/trace/ftrace.c:2068 
ftrace_bug+0x274/0x2e8
Modules linked in: dm_mod bonding nft_ct nf_conntrack nf_defrag_ipv6 
nf_defrag_ipv4 ip_set nf_tables rfkill libcrc32c nfnetlink sunrpc pseries_rng 
xts vmx_crypto sch_fq_codel ip_tables ext4 mbcache jbd2 sd_mod t10_pi sg 
ibmvscsi ibmveth scsi_transport_srp fuse
CPU: 18 PID: 1991307 Comm: stress_code_pat Not tainted 5.16.0-rc2-g2dbc3a3e8fc1 
#1
NIP:  c02d710c LR: c02d7108 CTR: c01f5e40
REGS: c00039d9b760 TRAP: 0700   Not tainted  (5.16.0-rc2-g2dbc3a3e8fc1)
MSR:  8282b033   CR: 48228224  XER: 
20040009
CFAR: c01f99e0 IRQMASK: 0 
GPR00: c02d7108 c00039d9ba00 c2a00500 0022 
GPR04: 7fff c00039d9b720 0027 c00efd747e18 
GPR08: 0023 0001 0027 0001 
GPR12: 8000 c00effbf8280 4000 00012d9f9798 
GPR16: 00012d9f9724 00012d996be8 00012d92f4f0 00012d9fd568 
GPR20: 00015bed3ed0 0001 00012d9a99d8 7fffc36f7f54 
GPR24: 0001  c00039d9bc70 c0faf228 
GPR28: c0ff3730 c0fac298 c00807110004 c0001669 
NIP [c02d710c] ftrace_bug+0x274/0x2e8
LR [c02d7108] ftrace_bug+0x270/0x2e8
Call Trace:
[c00039d9ba00] [c02d7108] ftrace_bug+0x270/0x2e8 (unreliable)
[c00039d9ba90] [c02d05c8] ftrace_modify_all_code+0x108/0x1c0
[c00039d9bac0] [c00822b8] arch_ftrace_update_code+0x18/0x30
[c00039d9bae0] [c02d07b8] ftrace_run_update_code+0x58/0xe0
[c00039d9bb10] [c02d5a78] ftrace_startup+0xf8/0x1a0
[c00039d9bb50] [c02d5b6c] register_ftrace_function+0x4c/0xc0
[c00039d9bb80] [c02f9b38] function_trace_init+0x88/0x100
[c00039d9bbb0] [c02efaf8] tracing_set_tracer+0x368/0x550
[c00039d9bc50] [c02efdf8] tracing_set_trace_write+0x118/0x180
[c00039d9bd10] [c0491e50] vfs_write+0xf0/0x340
[c00039d9bd60] [c049227c] ksys_write+0x7c/0x140
[c00039d9bdb0] [c0033284] system_call_exception+0x174/0x370
[c00039d9be10] [c000c74c] system_call_common+0xec/0x250
--- interrupt: c00 at 0x7fffb4f0bd74
NIP:  7fffb4f0bd74 LR: 7fffb4e834c4 CTR: 
REGS: c00039d9be80 TRAP: 0c00   Not tainted  (5.16.0-rc2-g2dbc3a3e8fc1)
MSR:  8280f033   CR: 2822  XER: 

IRQMASK: 0 
GPR00: 0004 7fffc36f7d30 7fffb5007100 0001 
GPR04: 00015bed1750 0009 0010 6e6f6974 
GPR08:     
GPR12:  7fffb513aeb0 4000 00012d9f9798 
GPR16: 00012d9f9724 00012d996be8 00012d92f4f0 00012d9fd568 
GPR20: 00015bed3ed0 0001 00012d9a99d8 7fffc36f7f54 
GPR24: 7fffc36f7f50 00012d9faf94 0009 00015bed1750 
GPR28: 0009 7fffb5001848 00015bed1750 0009 
NIP [7fffb4f0bd74] 0x7fffb4f0bd74
LR [7fffb4e834c4] 0x7fffb4e834c4
--- interrupt: c00
Instruction dump:
4814 3c62fe5f 386333e0 4bf228b1 6000 7fe3fb78 4bff88c5 7c641b78 
3c62fe5f 386333f8 4bf22895 6000 <0fe0> 38210090 3901 3d22fd68 
---[ end trace c4abf5aea4841297 ]---

Thanks
-Sachin

[1] 
https://lore.kernel.org/linuxppc-dev/f9e53405-b5b9-15d1-eaf9-0616a5b87...@csgroup.eu/T/



Re: [PATCH 1/3] powerpc/code-patching: work around code patching verification in patching tests

2021-11-25 Thread Christophe Leroy




Le 26/11/2021 à 04:22, Nicholas Piggin a écrit :

Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.

The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.


This really looks hacky.

To skip the test, you can call do_patch_instruction() instead of calling 
patch_instruction().




Fixes: 8b8a8f0ab3f55 ("powerpc/code-patching: Improve verification of 
patchability")
Signed-off-by: Nicholas Piggin 
---
  arch/powerpc/lib/code-patching.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 5e2fe133639e..57e160963ab7 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -187,10 +187,12 @@ static int do_patch_instruction(u32 *addr, struct 
ppc_inst instr)
  
  #endif /* CONFIG_STRICT_KERNEL_RWX */
  
+static bool skip_addr_verif = false;

+
  int patch_instruction(u32 *addr, struct ppc_inst instr)
  {
/* Make sure we aren't patching a freed init section */
-   if (!kernel_text_address((unsigned long)addr))
+   if (!skip_addr_verif && !kernel_text_address((unsigned long)addr))
return 0;
  
  	return do_patch_instruction(addr, instr);

@@ -738,11 +740,13 @@ static int __init test_code_patching(void)
  {
printk(KERN_DEBUG "Running code patching self-tests ...\n");
  
+	skip_addr_verif = true;

test_branch_iform();
test_branch_bform();
test_create_function_call();
test_translate_branch();
test_prefixed_patching();
+   skip_addr_verif = false;
  
  	return 0;

  }



Re: [PATCH] powerpc/64s/radix: Fix unmapping huge vmaps when CONFIG_HUGETLB_PAGE=n

2021-11-25 Thread Daniel Axtens
Hi,

> pmd_huge is defined out to false when HUGETLB_PAGE is not configured,
> but the vmap code still installs huge PMDs. This leads to errors
> encountering bad PMDs when vunmapping because it is not seen as a
> huge PTE, and the bad PMD check catches it. The end result may not
> be much more serious than some bad pmd warning messages, because the
> pmd_none_or_clear_bad() does what we wanted and clears the huge PTE
> anyway.

Huh. So vmap seems to key off arch_vmap_p?d_supported which checks for
radix and HAVE_ARCH_HUGE_VMAP.

> Fix this by checking pmd_is_leaf(), which checks for a PTE regardless
> of config options. The whole huge/large/leaf stuff is a tangled mess
> but that's kernel-wide and not something we can improve much in
> arch/powerpc code.

I guess I'm a bit late to the party here because p?d_is_leaf was added
in 2019 in commit d6eacedd1f0e ("powerpc/book3s: Use config independent
helpers for page table walk") but why wouldn't we just make pmd_huge()
not config dependent?

Also, looking at that commit, there are a few places that might still
throw warnings, e.g. find_linux_pte, find_current_mm_pte, pud_page which
seem like they might still throw warnings if they were to encounter a
huge vmap page:

struct page *pud_page(pud_t pud)
{
if (pud_is_leaf(pud)) {
VM_WARN_ON(!pud_huge(pud));

Do these functions need special treatment for huge vmappings()?

Apart from those questions, the patch itself makes sense to me and I can
follow how it would fix a problem.

Reviewed-by: Daniel Axtens 

Kind regards,
Daniel


Re: linux-next: runtime warnings from qemu run

2021-11-25 Thread Christophe Leroy




Le 26/11/2021 à 06:17, Stephen Rothwell a écrit :

Hi all,

My qemu boot test (pseries_le_defconfig) produces these new messages:

code-patching: test failed at line 444
code-patching: test failed at line 447
code-patching: test failed at line 450
code-patching: test failed at line 453
code-patching: test failed at line 456
code-patching: test failed at line 461
code-patching: test failed at line 466
code-patching: test failed at line 471
code-patching: test failed at line 476
code-patching: test failed at line 493
code-patching: test failed at line 533
code-patching: test failed at line 536
code-patching: test failed at line 539
code-patching: test failed at line 542
code-patching: test failed at line 545
code-patching: test failed at line 553
code-patching: test failed at line 558
code-patching: test failed at line 563
code-patching: test failed at line 568
code-patching: test failed at line 585
code-patching: test failed at line 605
code-patching: test failed at line 609
code-patching: test failed at line 618
code-patching: test failed at line 619
code-patching: test failed at line 620
code-patching: test failed at line 629
code-patching: test failed at line 630
code-patching: test failed at line 631
code-patching: test failed at line 640
code-patching: test failed at line 641
code-patching: test failed at line 650
code-patching: test failed at line 651
code-patching: test failed at line 661
code-patching: test failed at line 665
code-patching: test failed at line 675
code-patching: test failed at line 676
code-patching: test failed at line 677
code-patching: test failed at line 687
code-patching: test failed at line 688
code-patching: test failed at line 689
code-patching: test failed at line 699
code-patching: test failed at line 700
code-patching: test failed at line 710
code-patching: test failed at line 711

Maybe caused by commit

   8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")


Yes, Nic proposed a series to fix that: 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20211126032249.1652080-1-npig...@gmail.com/





As an presumably unrelated aside, we seem to be using a bit more stack
space as well

- mount (54) used greatest stack depth: 12512 bytes left
- mount (55) used greatest stack depth: 12032 bytes left
+ mount (54) used greatest stack depth: 10608 bytes left



[PATCH] powerpc/pseries/vas: Don't print an error when VAS is unavailable

2021-11-25 Thread Nicholas Piggin
KVM does not support VAS so guests always print a useless error on boot

vas: HCALL(398) error -2, query_type 0, result buffer 0x57f2000

Change this to only print the message if the error is not H_FUNCTION.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/platforms/pseries/vas.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/vas.c 
b/arch/powerpc/platforms/pseries/vas.c
index b043e3936d21..734523e2272f 100644
--- a/arch/powerpc/platforms/pseries/vas.c
+++ b/arch/powerpc/platforms/pseries/vas.c
@@ -151,8 +151,15 @@ int h_query_vas_capabilities(const u64 hcall, u8 
query_type, u64 result)
if (rc == H_SUCCESS)
return 0;
 
-   pr_err("HCALL(%llx) error %ld, query_type %u, result buffer 0x%llx\n",
-   hcall, rc, query_type, result);
+   /* H_FUNCTION means HV does not support VAS so don't print an error */
+   if (rc != H_FUNCTION) {
+   pr_err("%s error %ld, query_type %u, result buffer 0x%llx\n",
+   (hcall == H_QUERY_VAS_CAPABILITIES) ?
+   "H_QUERY_VAS_CAPABILITIES" :
+   "H_QUERY_NX_CAPABILITIES",
+   rc, query_type, result);
+   }
+
return -EIO;
 }
 EXPORT_SYMBOL_GPL(h_query_vas_capabilities);
-- 
2.23.0



linux-next: runtime warnings from qemu run

2021-11-25 Thread Stephen Rothwell
Hi all,

My qemu boot test (pseries_le_defconfig) produces these new messages:

code-patching: test failed at line 444
code-patching: test failed at line 447
code-patching: test failed at line 450
code-patching: test failed at line 453
code-patching: test failed at line 456
code-patching: test failed at line 461
code-patching: test failed at line 466
code-patching: test failed at line 471
code-patching: test failed at line 476
code-patching: test failed at line 493
code-patching: test failed at line 533
code-patching: test failed at line 536
code-patching: test failed at line 539
code-patching: test failed at line 542
code-patching: test failed at line 545
code-patching: test failed at line 553
code-patching: test failed at line 558
code-patching: test failed at line 563
code-patching: test failed at line 568
code-patching: test failed at line 585
code-patching: test failed at line 605
code-patching: test failed at line 609
code-patching: test failed at line 618
code-patching: test failed at line 619
code-patching: test failed at line 620
code-patching: test failed at line 629
code-patching: test failed at line 630
code-patching: test failed at line 631
code-patching: test failed at line 640
code-patching: test failed at line 641
code-patching: test failed at line 650
code-patching: test failed at line 651
code-patching: test failed at line 661
code-patching: test failed at line 665
code-patching: test failed at line 675
code-patching: test failed at line 676
code-patching: test failed at line 677
code-patching: test failed at line 687
code-patching: test failed at line 688
code-patching: test failed at line 689
code-patching: test failed at line 699
code-patching: test failed at line 700
code-patching: test failed at line 710
code-patching: test failed at line 711

Maybe caused by commit

  8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")

As an presumably unrelated aside, we seem to be using a bit more stack
space as well

- mount (54) used greatest stack depth: 12512 bytes left
- mount (55) used greatest stack depth: 12032 bytes left
+ mount (54) used greatest stack depth: 10608 bytes left

-- 
Cheers,
Stephen Rothwell


pgpEJzTk85LnZ.pgp
Description: OpenPGP digital signature


Re: [kbuild-all] Re: [PATCH 1/8] powerpc/mm: Make slice specific to book3s/64

2021-11-25 Thread Chen, Rong A




On 11/24/2021 9:49 PM, Christophe Leroy wrote:



Le 24/11/2021 à 13:10, Christophe Leroy a écrit :



Le 22/11/2021 à 15:48, kernel test robot a écrit :

Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on hnaz-mm/master linus/master v5.16-rc2 
next-2028]

[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/Convert-powerpc-to-default-topdown-mmap-layout/20211122-165115 

base: 
https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next

config: powerpc64-randconfig-s031-20211122 (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 11.2.0
reproduce:
 wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross 
-O ~/bin/make.cross

 chmod +x ~/bin/make.cross
 # apt-get install sparse
 # sparse version: v0.6.4-dirty
 # 
https://github.com/0day-ci/linux/commit/1d0b7cc86d08f25f595b52d8c39ba9ca1d29a30a 


 git remote add linux-review https://github.com/0day-ci/linux
 git fetch --no-tags linux-review 
Christophe-Leroy/Convert-powerpc-to-default-topdown-mmap-layout/20211122-165115 


 git checkout 1d0b7cc86d08f25f595b52d8c39ba9ca1d29a30a
 # save the attached .config to linux build tree
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 
make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' 
ARCH=powerpc64


If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

    arch/powerpc/mm/book3s64/slice.c: In function 
'slice_get_unmapped_area':
arch/powerpc/mm/book3s64/slice.c:639:1: warning: the frame size of 
1040 bytes is larger than 1024 bytes [-Wframe-larger-than=]

  639 | }
  | ^



The problem was already existing when slice.c was in arch/powerpc/mm/

This patch doesn't introduce the problem.



In fact the problem is really added by yourself mister 'kernel test robot'.

CONFIG_FRAME_WARN is supposed to be 2048 on 64 bit architectures.

It the robot starts to reduce that value, it is on its own 


Hi Christophe,

Thanks for the information, we'll set the default value for FRAME_WARN 
in randconfig tests.


Best Regards,
Rong Chen




config FRAME_WARN
 int "Warn for stack frames larger than"
 range 0 8192
 default 2048 if GCC_PLUGIN_LATENT_ENTROPY
 default 1536 if (!64BIT && (PARISC || XTENSA))
 default 1024 if (!64BIT && !PARISC)
 default 2048 if 64BIT
 help
   Tell gcc to warn at build time for stack frames larger than this.
   Setting this too low will cause a lot of warnings.
   Setting it to 0 disables the warning.
___
kbuild-all mailing list -- kbuild-...@lists.01.org
To unsubscribe send an email to kbuild-all-le...@lists.01.org


[PATCH 3/3] powerpc/code-patching: don't use the stack for code patching tests

2021-11-25 Thread Nicholas Piggin
Use the existing test function for code patching tests instead of
writing to the stack. This means the address verification does not have
to be bypassed for these tests.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/lib/code-patching.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 70247fc58b6e..babf6b22adef 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -422,9 +422,11 @@ static void __init test_branch_iform(void)
 {
int err;
struct ppc_inst instr;
-   u32 tmp[2];
-   u32 *iptr = tmp;
-   unsigned long addr = (unsigned long)tmp;
+   u32 *iptr;
+   unsigned long addr;
+
+   iptr = (u32 *)ppc_function_entry(test_trampoline);
+   addr = (unsigned long)iptr;
 
/* The simplest case, branch to self, no flags */
check(instr_is_branch_iform(ppc_inst(0x4800)));
@@ -516,12 +518,12 @@ static void __init test_create_function_call(void)
 static void __init test_branch_bform(void)
 {
int err;
-   unsigned long addr;
struct ppc_inst instr;
-   u32 tmp[2];
-   u32 *iptr = tmp;
+   u32 *iptr;
+   unsigned long addr;
unsigned int flags;
 
+   iptr = (u32 *)ppc_function_entry(test_trampoline);
addr = (unsigned long)iptr;
 
/* The simplest case, branch to self, no flags */
@@ -603,6 +605,12 @@ static void __init test_translate_branch(void)
if (!buf)
return;
 
+   /*
+* Have to disable the address bounds check for patch_instruction
+* because we are patching vmalloc space here.
+*/
+   skip_addr_verif = true;
+
/* Simple case, branch to self moved a little */
p = buf;
addr = (unsigned long)p;
@@ -715,6 +723,8 @@ static void __init test_translate_branch(void)
check(instr_is_branch_to_addr(p, addr));
check(instr_is_branch_to_addr(q, addr));
 
+   skip_addr_verif = false;
+
/* Free the buffer we were using */
vfree(buf);
 }
@@ -743,13 +753,11 @@ static int __init test_code_patching(void)
 {
printk(KERN_DEBUG "Running code patching self-tests ...\n");
 
-   skip_addr_verif = true;
test_branch_iform();
test_branch_bform();
test_create_function_call();
test_translate_branch();
test_prefixed_patching();
-   skip_addr_verif = false;
 
return 0;
 }
-- 
2.23.0



[PATCH 2/3] powerpc/code-patching: warn on code patching failure

2021-11-25 Thread Nicholas Piggin
Callers are supposed to handle this, but it is possible that they
don't or they do but don't make much noise about it. A failure is
probably an indication of a bigger problem somewhere so it is good
to warn once about it.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/lib/code-patching.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 57e160963ab7..70247fc58b6e 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -161,6 +161,7 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst 
instr)
 
text_poke_addr = (unsigned long)__this_cpu_read(text_poke_area)->addr;
if (map_patch_area(addr, text_poke_addr)) {
+   WARN_ON_ONCE(1);
err = -1;
goto out;
}
@@ -192,8 +193,10 @@ static bool skip_addr_verif = false;
 int patch_instruction(u32 *addr, struct ppc_inst instr)
 {
/* Make sure we aren't patching a freed init section */
-   if (!skip_addr_verif && !kernel_text_address((unsigned long)addr))
+   if (!skip_addr_verif && !kernel_text_address((unsigned long)addr)) {
+   WARN_ON_ONCE(1);
return 0;
+   }
 
return do_patch_instruction(addr, instr);
 }
-- 
2.23.0



[PATCH 1/3] powerpc/code-patching: work around code patching verification in patching tests

2021-11-25 Thread Nicholas Piggin
Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.

The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.

Fixes: 8b8a8f0ab3f55 ("powerpc/code-patching: Improve verification of 
patchability")
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/lib/code-patching.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 5e2fe133639e..57e160963ab7 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -187,10 +187,12 @@ static int do_patch_instruction(u32 *addr, struct 
ppc_inst instr)
 
 #endif /* CONFIG_STRICT_KERNEL_RWX */
 
+static bool skip_addr_verif = false;
+
 int patch_instruction(u32 *addr, struct ppc_inst instr)
 {
/* Make sure we aren't patching a freed init section */
-   if (!kernel_text_address((unsigned long)addr))
+   if (!skip_addr_verif && !kernel_text_address((unsigned long)addr))
return 0;
 
return do_patch_instruction(addr, instr);
@@ -738,11 +740,13 @@ static int __init test_code_patching(void)
 {
printk(KERN_DEBUG "Running code patching self-tests ...\n");
 
+   skip_addr_verif = true;
test_branch_iform();
test_branch_bform();
test_create_function_call();
test_translate_branch();
test_prefixed_patching();
+   skip_addr_verif = false;
 
return 0;
 }
-- 
2.23.0



[PATCH AUTOSEL 5.10 03/28] powerpc/pseries/ddw: Revert "Extend upper limit for huge DMA window for persistent memory"

2021-11-25 Thread Sasha Levin
From: Alexey Kardashevskiy 

[ Upstream commit 2d33f5504490a9d90924476dbccd4a5349ee1ad0 ]

This reverts commit 54fc3c681ded9437e4548e2501dc1136b23cfa9a
which does not allow 1:1 mapping even for the system RAM which
is usually possible.

Signed-off-by: Alexey Kardashevskiy 
Signed-off-by: Michael Ellerman 
Link: https://lore.kernel.org/r/20211108040320.3857636-2-...@ozlabs.ru
Signed-off-by: Sasha Levin 
---
 arch/powerpc/platforms/pseries/iommu.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index e4198700ed1a3..245f1f8df6563 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1034,15 +1034,6 @@ static phys_addr_t ddw_memory_hotplug_max(void)
phys_addr_t max_addr = memory_hotplug_max();
struct device_node *memory;
 
-   /*
-* The "ibm,pmemory" can appear anywhere in the address space.
-* Assuming it is still backed by page structs, set the upper limit
-* for the huge DMA window as MAX_PHYSMEM_BITS.
-*/
-   if (of_find_node_by_type(NULL, "ibm,pmemory"))
-   return (sizeof(phys_addr_t) * 8 <= MAX_PHYSMEM_BITS) ?
-   (phys_addr_t) -1 : (1ULL << MAX_PHYSMEM_BITS);
-
for_each_node_by_type(memory, "memory") {
unsigned long start, size;
int n_mem_addr_cells, n_mem_size_cells, len;
-- 
2.33.0



[PATCH AUTOSEL 5.15 04/39] powerpc/pseries/ddw: Do not try direct mapping with persistent memory and one window

2021-11-25 Thread Sasha Levin
From: Alexey Kardashevskiy 

[ Upstream commit ad3976025b311cdeb822ad3e7a7554018cb0f83f ]

There is a possibility of having just one DMA window available with
a limited capacity which the existing code does not handle that well.
If the window is big enough for the system RAM but less than
MAX_PHYSMEM_BITS (which we want when persistent memory is present),
we create 1:1 window and leave persistent memory without DMA.

This disables 1:1 mapping entirely if there is persistent memory and
either:
- the huge DMA window does not cover the entire address space;
- the default DMA window is removed.

This relies on reverted 54fc3c681ded
("powerpc/pseries/ddw: Extend upper limit for huge DMA window for persistent 
memory")
to return the actual amount RAM in ddw_memory_hotplug_max() (posted
separately).

Signed-off-by: Alexey Kardashevskiy 
Signed-off-by: Michael Ellerman 
Link: https://lore.kernel.org/r/20211108040320.3857636-4-...@ozlabs.ru
Signed-off-by: Sasha Levin 
---
 arch/powerpc/platforms/pseries/iommu.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index ad96d6e13d1f6..8322ca86d5acf 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1356,8 +1356,10 @@ static bool enable_ddw(struct pci_dev *dev, struct 
device_node *pdn)
len = order_base_2(query.largest_available_block << page_shift);
win_name = DMA64_PROPNAME;
} else {
-   direct_mapping = true;
-   win_name = DIRECT64_PROPNAME;
+   direct_mapping = !default_win_removed ||
+   (len == MAX_PHYSMEM_BITS) ||
+   (!pmem_present && (len == max_ram_len));
+   win_name = direct_mapping ? DIRECT64_PROPNAME : DMA64_PROPNAME;
}
 
ret = create_ddw(dev, ddw_avail, , page_shift, len);
-- 
2.33.0



[PATCH AUTOSEL 5.15 03/39] powerpc/pseries/ddw: Revert "Extend upper limit for huge DMA window for persistent memory"

2021-11-25 Thread Sasha Levin
From: Alexey Kardashevskiy 

[ Upstream commit 2d33f5504490a9d90924476dbccd4a5349ee1ad0 ]

This reverts commit 54fc3c681ded9437e4548e2501dc1136b23cfa9a
which does not allow 1:1 mapping even for the system RAM which
is usually possible.

Signed-off-by: Alexey Kardashevskiy 
Signed-off-by: Michael Ellerman 
Link: https://lore.kernel.org/r/20211108040320.3857636-2-...@ozlabs.ru
Signed-off-by: Sasha Levin 
---
 arch/powerpc/platforms/pseries/iommu.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index a52af8fbf5711..ad96d6e13d1f6 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1092,15 +1092,6 @@ static phys_addr_t ddw_memory_hotplug_max(void)
phys_addr_t max_addr = memory_hotplug_max();
struct device_node *memory;
 
-   /*
-* The "ibm,pmemory" can appear anywhere in the address space.
-* Assuming it is still backed by page structs, set the upper limit
-* for the huge DMA window as MAX_PHYSMEM_BITS.
-*/
-   if (of_find_node_by_type(NULL, "ibm,pmemory"))
-   return (sizeof(phys_addr_t) * 8 <= MAX_PHYSMEM_BITS) ?
-   (phys_addr_t) -1 : (1ULL << MAX_PHYSMEM_BITS);
-
for_each_node_by_type(memory, "memory") {
unsigned long start, size;
int n_mem_addr_cells, n_mem_size_cells, len;
-- 
2.33.0



[PATCH] powerpc/64s/radix: Fix unmapping huge vmaps when CONFIG_HUGETLB_PAGE=n

2021-11-25 Thread Nicholas Piggin
pmd_huge is defined out to false when HUGETLB_PAGE is not configured,
but the vmap code still installs huge PMDs. This leads to errors
encountering bad PMDs when vunmapping because it is not seen as a
huge PTE, and the bad PMD check catches it. The end result may not
be much more serious than some bad pmd warning messages, because the
pmd_none_or_clear_bad() does what we wanted and clears the huge PTE
anyway.

Fix this by checking pmd_is_leaf(), which checks for a PTE regardless
of config options. The whole huge/large/leaf stuff is a tangled mess
but that's kernel-wide and not something we can improve much in
arch/powerpc code.

Fixes: d909f9109c30 ("powerpc/64s/radix: Enable HAVE_ARCH_HUGE_VMAP")
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c 
b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 99dbee114539..7559638068ef 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -1089,7 +1089,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t 
prot)
 
 int pud_clear_huge(pud_t *pud)
 {
-   if (pud_huge(*pud)) {
+   if (pud_is_leaf(*pud)) {
pud_clear(pud);
return 1;
}
@@ -1136,7 +1136,7 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t 
prot)
 
 int pmd_clear_huge(pmd_t *pmd)
 {
-   if (pmd_huge(*pmd)) {
+   if (pmd_is_leaf(*pmd)) {
pmd_clear(pmd);
return 1;
}
-- 
2.23.0



[Bug 205099] KASAN hit at raid6_pq: BUG: Unable to handle kernel data access at 0x00f0fd0d

2021-11-25 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=205099

Erhard F. (erhar...@mailbox.org) changed:

   What|Removed |Added

 Attachment #292347|0   |1
is obsolete||

--- Comment #36 from Erhard F. (erhar...@mailbox.org) ---
Created attachment 299715
  --> https://bugzilla.kernel.org/attachment.cgi?id=299715=edit
kernel .config (5.15.5, PowerMac G4 DP)

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 205099] KASAN hit at raid6_pq: BUG: Unable to handle kernel data access at 0x00f0fd0d

2021-11-25 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=205099

--- Comment #35 from Erhard F. (erhar...@mailbox.org) ---
Created attachment 299713
  --> https://bugzilla.kernel.org/attachment.cgi?id=299713=edit
dmesg (5.15.5, INLINE KASAN, PowerMac G4 DP)

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 205099] KASAN hit at raid6_pq: BUG: Unable to handle kernel data access at 0x00f0fd0d

2021-11-25 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=205099

--- Comment #34 from Erhard F. (erhar...@mailbox.org) ---
Created attachment 299711
  --> https://bugzilla.kernel.org/attachment.cgi?id=299711=edit
dmesg (5.15.5, OUTLINE KASAN, PowerMac G4 DP)

Finally my G4 DP got its' fixed & overhauled PSU so I am able to continue here.

Tested kernel 5.15.5 and the original KASAN hit at raid6_pq did not show up.
Instead I am getting this now:

[...]
Running code patching self-tests ...
vmap allocation for size 33562624 failed: use vmalloc= to increase size
swapper/0: vmalloc error: size 33558528, vm_struct allocation failed,
mode:0xcc0(GFP_KERNEL), nodemask=(null)
CPU: 0 PID: 1 Comm: swapper/0 Tainted: GW
5.15.5-gentoo-PowerMacG4 #5
Call Trace:
[f1033bb0] [c0d933c0] dump_stack_lvl+0x80/0xb0 (unreliable)
[f1033bd0] [c0516128] warn_alloc+0x11c/0x2b4
[f1033cb0] [c0508c40] __vmalloc_node_range+0xd8/0x64c
[f1033d70] [c0508a58] __vmalloc_node+0xec/0xf4
[f1033db0] [c1c0ecb0] test_code_patching+0x72c/0xd50
[f1033df0] [c0008908] do_one_initcall+0x284/0x574
[f1033ec0] [c1c03f78] kernel_init_freeable+0x510/0x51c
[f1033f10] [c000934c] kernel_init+0x24/0x140
[f1033f30] [c0033148] ret_from_kernel_thread+0x14/0x1c
Mem-Info:
active_anon:0 inactive_anon:0 isolated_anon:0
 active_file:0 inactive_file:0 isolated_file:0
 unevictable:0 dirty:0 writeback:0
 slab_reclaimable:1306 slab_unreclaimable:4214
 mapped:0 shmem:0 pagetables:0 bounce:0
 kernel_misc_reclaimable:0
 free:474459 free_pcp:592 free_cma:0
Node 0 active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB
unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:0kB dirty:0kB
writeback:0kB shmem:0kB writeback_tmp:0kB kernel_stack:840kB pagetables:0kB
all_unreclaimable? no
DMA free:588612kB min:3144kB low:3928kB high:4712kB reserved_highatomic:0KB
active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB
unevictable:0kB writepending:0kB present:786432kB managed:618264kB mlocked:0kB
bounce:0kB free_pcp:1964kB local_pcp:1568kB free_cma:0kB
lowmem_reserve[]: 0 0 1280 1280
HighMem free:1309224kB min:512kB low:2176kB high:3840kB reserved_highatomic:0KB
active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB
unevictable:0kB writepending:0kB present:1310720kB managed:1310720kB
mlocked:0kB bounce:0kB free_pcp:404kB local_pcp:116kB free_cma:0kB
lowmem_reserve[]: 0 0 0 0
DMA: 5*4kB (ME) 2*8kB (UM) 4*16kB (M) 5*32kB (ME) 1*64kB (M) 4*128kB (UME)
4*256kB (ME) 4*512kB (UM) 3*1024kB (M) 4*2048kB (ME) 140*4096kB (M) = 588612kB
HighMem: 0*4kB 1*8kB (U) 0*16kB 1*32kB (U) 0*64kB 2*128kB (U) 1*256kB (U)
0*512kB 0*1024kB 1*2048kB (U) 319*4096kB (M) = 1309224kB
0 total pagecache pages
0 pages in swap cache
Swap cache stats: add 0, delete 0, find 0/0
Free swap  = 0kB
Total swap = 0kB
524288 pages RAM
327680 pages HighMem/MovableOnly
42042 pages reserved
code-patching: test failed at line 598
[...]

This makes me wonder whether KASAN is working correctly when not enough vmap
size is available. I did set it to vmalloc=64M via Kernel command line but this
does not seem to be reckognized. Same situation with INLINE KASAN. In both
cases with VMAP_STACK and CONFIG_THREAD_SHIFT=14.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH v4 00/17] powerpc: Make hash MMU code build configurable

2021-11-25 Thread Nicholas Piggin
Excerpts from Christophe Leroy's message of November 26, 2021 3:35 am:
> 
> 
> Le 25/11/2021 à 17:35, Christophe Leroy a écrit :
>> 
>> 
>> Le 25/11/2021 à 13:50, Nicholas Piggin a écrit :
>>> Now that there's a platform that can make good use of it, here's
>>> a series that can prevent the hash MMU code being built for 64s
>>> platforms that don't need it.
>> 
>> # CONFIG_PPC_64S_HASH_MMU is not set
>> 
>> 
>> :1559:2: warning: #warning syscall futex_waitv not implemented 
>> [-Wcpp]
>> arch/powerpc/platforms/cell/spu_base.c: In function '__spu_kernel_slb':
>> arch/powerpc/platforms/cell/spu_base.c:215:38: error: 'mmu_linear_psize' 
>> undeclared (first use in this function); did you mean 'mmu_virtual_psize'?
>>    215 | llp = mmu_psize_defs[mmu_linear_psize].sllp;
>>    |  ^~~~
>>    |  mmu_virtual_psize
>> arch/powerpc/platforms/cell/spu_base.c:215:38: note: each undeclared 
>> identifier is reported only once for each function it appears in
>> make[3]: *** [scripts/Makefile.build:287: 
>> arch/powerpc/platforms/cell/spu_base.o] Error 1
>> make[2]: *** [scripts/Makefile.build:549: arch/powerpc/platforms/cell] 
>> Error 2
>> make[1]: *** [scripts/Makefile.build:549: arch/powerpc/platforms] Error 2
>> make: *** [Makefile:1846: arch/powerpc] Error 2
>> 
>> 
> 
> 
> With CONFIG_SPU_BASE removed, the above voids and I get to the final 
> link with the following errors:

This is building cell platform with POWER9 CPU and !HASH?

We don't have to make that build, just prevent the config. I had that in 
a previous version which also had platforms select hash, but we went to 
just CPU. But now there's no constraint that prevents cell+POWER9 even 
though it doesn't make sense.

Not sure the best way to fix it. I'll think about it.

Thanks,
Nick


Re: [PATCH] powerpc/watchdog: Fix wd_smp_last_reset_tb reporting

2021-11-25 Thread Nicholas Piggin
Excerpts from Laurent Dufour's message of November 26, 2021 3:21 am:
> On 25/11/2021, 11:33:46, Nicholas Piggin wrote:
>> wd_smp_last_reset_tb now gets reset by watchdog_smp_panic() as part of
>> marking CPUs stuck and removing them from the pending mask before it
>> begins any printing. This causes last reset times reported to be off.
>> 
>> Fix this by reading it into a local variable before it gets reset.
>> 
>> Fixes: 76521c4b0291 ("powerpc/watchdog: Avoid holding wd_smp_lock over 
>> printk and smp_send_nmi_ipi")
>> Signed-off-by: Nicholas Piggin 
>> ---
>> 
>> This is the delta for patches 1-4 between v3 and v4 of the series which
>> is the result of fixing the bug in patch 3. Sending because v3 got
>> merged into powerpc next
> 
> What about the 5th patch in the v4 series titled "[PATCH v4 5/5]
> powerpc/watchdog: help remote CPUs to flush NMI printk output"?

Yes it would be good to get that one in too.

Thanks,
Nick


Re: [PATCH v2 9/9] powerpc: Simplify and move arch_randomize_brk()

2021-11-25 Thread kernel test robot
Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on hnaz-mm/master linus/master v5.16-rc2 next-20211125]
[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/Convert-powerpc-to-default-topdown-mmap-layout/20211125-162916
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: riscv-allyesconfig 
(https://download.01.org/0day-ci/archive/20211126/202111260844.kcgkx5uk-...@intel.com/config)
compiler: riscv64-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/554c475dfb73dc352708dff3589b55845b3dd751
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Christophe-Leroy/Convert-powerpc-to-default-topdown-mmap-layout/20211125-162916
git checkout 554c475dfb73dc352708dff3589b55845b3dd751
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross 
O=build_dir ARCH=riscv SHELL=/bin/bash 
drivers/net/wireless/mediatek/mt76/mt7915/ drivers/pci/controller/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/pci/controller/pci-xgene.c:52: warning: "SZ_1T" redefined
  52 | #define SZ_1T   (SZ_1G*1024ULL)
 | 
   In file included from arch/riscv/include/asm/pgtable.h:10,
from include/linux/pgtable.h:6,
from arch/riscv/include/asm/io.h:15,
from include/linux/io.h:13,
from drivers/pci/controller/pci-xgene.c:11:
   include/linux/sizes.h:51: note: this is the location of the previous 
definition
  51 | #define SZ_1T   _AC(0x100, ULL)
 | 


vim +/SZ_1T +52 drivers/pci/controller/pci-xgene.c

5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  45  
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  46  
#define LINK_UP_MASK0x0100
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  47  
#define AXI_EP_CFG_ACCESS   0x1
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  48  
#define EN_COHERENCY0xF000
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  49  
#define EN_REG  0x0001
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  50  
#define OB_LO_IO0x0002
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  51  
#define XGENE_PCIE_DEVICEID 0xE004
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01 @52  
#define SZ_1T   (SZ_1G*1024ULL)
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  53  
#define PIPE_PHY_RATE_RD(src)   ((0xc000 & (u32)(src)) >> 0xe)
5f6b6ccdbe1cdfa drivers/pci/host/pci-xgene.c Tanmay Inamdar 2014-10-01  54  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


[powerpc:next-test] BUILD SUCCESS dbf69a1d7c9daa284ec98147f627321bdfd64288

2021-11-25 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
next-test
branch HEAD: dbf69a1d7c9daa284ec98147f627321bdfd64288  powerpc/ftrace: Activate 
HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32

elapsed time: 728m

configs tested: 54
configs skipped: 3

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
i386 randconfig-c001-20211125
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
i386  debian-10.3
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
riscvallmodconfig
um   x86_64_defconfig
um i386_defconfig
x86_64   allyesconfig
x86_64rhel-8.3-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-func
x86_64  kexec

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


[powerpc:next] BUILD SUCCESS 3d030e301856da366380b3865fce6c03037b08a6

2021-11-25 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
next
branch HEAD: 3d030e301856da366380b3865fce6c03037b08a6  powerpc/watchdog: Fix 
wd_smp_last_reset_tb reporting

elapsed time: 729m

configs tested: 54
configs skipped: 3

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
i386 randconfig-c001-20211125
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
i386  debian-10.3
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
riscvallmodconfig
um   x86_64_defconfig
um i386_defconfig
x86_64   allyesconfig
x86_64rhel-8.3-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-func
x86_64  kexec

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


[powerpc:topic/ppc-kvm] BUILD SUCCESS 9c5a432a558105d6145b058fad78eb6fcf3d4c38

2021-11-25 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
topic/ppc-kvm
branch HEAD: 9c5a432a558105d6145b058fad78eb6fcf3d4c38  KVM: PPC: Book3S HV P9: 
Remove subcore HMI handling

elapsed time: 726m

configs tested: 54
configs skipped: 3

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
i386 randconfig-c001-20211125
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
i386  debian-10.3
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
riscvallmodconfig
um   x86_64_defconfig
um i386_defconfig
x86_64   allyesconfig
x86_64rhel-8.3-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-func
x86_64  kexec

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


Re: [PATCH 0/5] xen: cleanup detection of non-essential pv devices

2021-11-25 Thread Boris Ostrovsky



On 11/22/21 3:20 AM, Juergen Gross wrote:

On 22.10.21 08:47, Juergen Gross wrote:

Today the non-essential pv devices are hard coded in the xenbus driver
and this list is lacking multiple entries.

This series reworks the detection logic of non-essential devices by
adding a flag for that purpose to struct xenbus_driver.

Juergen Gross (5):
   xen: add "not_essential" flag to struct xenbus_driver
   xen: flag xen_drm_front to be not essential for system boot
   xen: flag hvc_xen to be not essential for system boot
   xen: flag pvcalls-front to be not essential for system boot
   xen: flag xen_snd_front to be not essential for system boot

  drivers/gpu/drm/xen/xen_drm_front.c    |  1 +
  drivers/input/misc/xen-kbdfront.c  |  1 +
  drivers/tty/hvc/hvc_xen.c  |  1 +
  drivers/video/fbdev/xen-fbfront.c  |  1 +
  drivers/xen/pvcalls-front.c    |  1 +
  drivers/xen/xenbus/xenbus_probe_frontend.c | 14 +++---
  include/xen/xenbus.h   |  1 +
  sound/xen/xen_snd_front.c  |  1 +
  8 files changed, 10 insertions(+), 11 deletions(-)







Applied to for-linus-5.16c


-boris



Re: [PATCH v4 16/17] powerpc/64s: Move hash MMU support code under CONFIG_PPC_64S_HASH_MMU

2021-11-25 Thread kernel test robot
Hi Nicholas,

I love your patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on char-misc/char-misc-testing v5.16-rc2 next-20211125]
[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/Nicholas-Piggin/powerpc-Make-hash-MMU-code-build-configurable/20211125-210259
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-allnoconfig 
(https://download.01.org/0day-ci/archive/20211126/202111260315.gs4d14lt-...@intel.com/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/34f5477219850333c3c610b708932d555b7e9c96
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Nicholas-Piggin/powerpc-Make-hash-MMU-code-build-configurable/20211125-210259
git checkout 34f5477219850333c3c610b708932d555b7e9c96
# save the config file 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/book3s32/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

>> arch/powerpc/mm/book3s32/mmu.c:321:6: error: redefinition of 
>> 'update_mmu_cache'
 321 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long 
address,
 |  ^~~~
   In file included from arch/powerpc/include/asm/pgtable.h:18,
from include/linux/pgtable.h:6,
from include/linux/mm.h:33,
from arch/powerpc/mm/book3s32/mmu.c:21:
   arch/powerpc/include/asm/book3s/pgtable.h:40:20: note: previous definition 
of 'update_mmu_cache' with type 'void(struct vm_area_struct *, long unsigned 
int,  pte_t *)' {aka 'void(struct vm_area_struct *, long unsigned int,  long 
unsigned int *)'}
  40 | static inline void update_mmu_cache(struct vm_area_struct *vma, 
unsigned long address, pte_t *ptep) {}
 |^~~~


vim +/update_mmu_cache +321 arch/powerpc/mm/book3s32/mmu.c

3c726f8dee6f55e arch/powerpc/mm/ppc_mmu_32.c   Benjamin Herrenschmidt 
2005-11-07  312  
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  313  /*
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  314   * This is called at the end of handling a user page fault, 
when the
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  315   * fault has been handled by updating a PTE in the linux page 
tables.
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  316   * We use it to preload an HPTE into the hash table 
corresponding to
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  317   * the updated linux PTE.
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  318   *
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  319   * This must always be called with the pte lock held.
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  320   */
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16 @321  void update_mmu_cache(struct vm_area_struct *vma, unsigned 
long address,
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  322 pte_t *ptep)
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  323  {
f204338f8e29777 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  324   if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
f204338f8e29777 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  325   return;
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  326   /*
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  327* We don't need to worry about _PAGE_PRESENT here because we 
are
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  328* called with either mm->page_table_lock held or ptl lock 
held
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  329*/
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  330  
e5a1edb9fe4cfa0 arch/powerpc/mm/book3s32/mmu.c Christophe Leroy   
2019-08-16  331   /* We only want HPTEs for linux PTEs that have _PAGE_ACCESSED 
set */
e5a1edb9fe4cfa0 arch/powe

[PATCH v2 2/2] ppc64/fadump: fix inaccurate CPU state info in vmcore generated with panic

2021-11-25 Thread Hari Bathini
In panic path, fadump is triggered via a panic notifier function.
Before calling panic notifier functions, smp_send_stop() gets called,
which stops all CPUs except the panic'ing CPU. Commit 8389b37dffdc
("powerpc: stop_this_cpu: remove the cpu from the online map.") and
again commit bab26238bbd4 ("powerpc: Offline CPU in stop_this_cpu()")
started marking CPUs as offline while stopping them. So, if a kernel
has either of the above commits, vmcore captured with fadump via panic
path would not process register data for all CPUs except the panic'ing
CPU. Sample output of crash-utility with such vmcore:

  # crash vmlinux vmcore
  ...
KERNEL: vmlinux
  DUMPFILE: vmcore  [PARTIAL DUMP]
  CPUS: 1
  DATE: Wed Nov 10 09:56:34 EST 2021
UPTIME: 00:00:42
  LOAD AVERAGE: 2.27, 0.69, 0.24
 TASKS: 183
  NODENAME: X
   RELEASE: 5.15.0+
   VERSION: #974 SMP Wed Nov 10 04:18:19 CST 2021
   MACHINE: ppc64le  (2500 Mhz)
MEMORY: 8 GB
 PANIC: "Kernel panic - not syncing: sysrq triggered crash"
   PID: 3394
   COMMAND: "bash"
  TASK: c000150a5f80  [THREAD_INFO: c000150a5f80]
   CPU: 1
 STATE: TASK_RUNNING (PANIC)

  crash> p -x __cpu_online_mask
  __cpu_online_mask = $1 = {
bits = {0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
  }
  crash>
  crash>
  crash> p -x __cpu_active_mask
  __cpu_active_mask = $2 = {
bits = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
  }
  crash>

While this has been the case since fadump was introduced, the issue
was not identified for two probable reasons:

  - In general, the bulk of the vmcores analyzed were from crash
due to exception.

  - The above did change since commit 8341f2f222d7 ("sysrq: Use
panic() to force a crash") started using panic() instead of
deferencing NULL pointer to force a kernel crash. But then
commit de6e5d38417e ("powerpc: smp_send_stop do not offline
stopped CPUs") stopped marking CPUs as offline till kernel
commit bab26238bbd4 ("powerpc: Offline CPU in stop_this_cpu()")
reverted that change.

To ensure post processing register data of all other CPUs happens
as intended, let panic() function take the crash friendly path (read
crash_smp_send_stop()) with the help of crash_kexec_post_notifiers
option. Also, as register data for all CPUs is captured by f/w, skip
IPI callbacks here for fadump, to avoid any complications in finding
the right backtraces.

Signed-off-by: Hari Bathini 
---

Changes in v2:
* Let panic(0 take crash friendly path when fadump is enabled
  using crash_kexec_post_notifiers option.


 arch/powerpc/kernel/fadump.c |  8 
 arch/powerpc/kernel/smp.c| 10 ++
 2 files changed, 18 insertions(+)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index b7ceb041743c..60f5fc14aa23 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1641,6 +1641,14 @@ int __init setup_fadump(void)
else if (fw_dump.reserve_dump_area_size)
fw_dump.ops->fadump_init_mem_struct(_dump);
 
+   /*
+* In case of panic, fadump is triggered via ppc_panic_event()
+* panic notifier. Setting crash_kexec_post_notifiers to 'true'
+* lets panic() function take crash friendly path before panic
+* notifiers are invoked.
+*/
+   crash_kexec_post_notifiers = true;
+
return 1;
 }
 subsys_initcall(setup_fadump);
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index d34e6b67684c..00a52b6e3888 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -61,6 +61,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef DEBUG
 #include 
@@ -634,6 +635,15 @@ void crash_smp_send_stop(void)
 {
static bool stopped = false;
 
+   /*
+* In case of fadump, register data for all CPUs is captured by f/w
+* on ibm,os-term rtas call. Skip IPI callbacks to other CPUs before
+* this rtas call to avoid tricky post processing of those CPUs'
+* backtraces.
+*/
+   if (should_fadump_crash())
+   return;
+
if (stopped)
return;
 
-- 
2.33.1



[PATCH v2 1/2] powerpc: handle kdump appropriately with crash_kexec_post_notifiers option

2021-11-25 Thread Hari Bathini
Kdump can be triggered after panic_notifers since commit f06e5153f4ae2
("kernel/panic.c: add "crash_kexec_post_notifiers" option for kdump
after panic_notifers") introduced crash_kexec_post_notifiers option.
But using this option would mean smp_send_stop(), that marks all other
CPUs as offline, gets called before kdump is triggered. As a result,
kdump routines fail to save other CPUs' registers. To fix this, kdump
friendly crash_smp_send_stop() function was introduced with kernel
commit 0ee59413c967 ("x86/panic: replace smp_send_stop() with kdump
friendly version in panic path"). Override this kdump friendly weak
function to handle crash_kexec_post_notifiers option appropriately
on powerpc.

Signed-off-by: Hari Bathini 
---

* New patch to handle the case where kdump is triggered after
  panic notifiers.


 arch/powerpc/kernel/smp.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index c23ee842c4c3..d34e6b67684c 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -620,6 +620,32 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct 
pt_regs *))
 }
 #endif
 
+static void crash_stop_this_cpu(struct pt_regs *regs)
+{
+   /*
+* Just busy wait here and avoid marking CPU as offline to ensure
+* register data of all these CPUs is captured appropriately.
+*/
+   while (1)
+   cpu_relax();
+}
+
+void crash_smp_send_stop(void)
+{
+   static bool stopped = false;
+
+   if (stopped)
+   return;
+
+   stopped = true;
+
+#ifdef CONFIG_NMI_IPI
+   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_stop_this_cpu, 100);
+#else
+   smp_call_function(crash_stop_this_cpu, NULL, 0);
+#endif /* CONFIG_NMI_IPI */
+}
+
 #ifdef CONFIG_NMI_IPI
 static void nmi_stop_this_cpu(struct pt_regs *regs)
 {
-- 
2.33.1



[PATCH v2 6/6] module: Move duplicate mod_check_sig users code to mod_parse_sig

2021-11-25 Thread Michal Suchanek
Multiple users of mod_check_sig check for the marker, then call
mod_check_sig, extract signature length, and remove the signature.

Put this code in one place together with mod_check_sig.

Signed-off-by: Michal Suchanek 
---
 include/linux/module_signature.h|  1 +
 kernel/module_signature.c   | 56 -
 kernel/module_signing.c | 26 +++---
 security/integrity/ima/ima_modsig.c | 22 ++--
 4 files changed, 63 insertions(+), 42 deletions(-)

diff --git a/include/linux/module_signature.h b/include/linux/module_signature.h
index 7eb4b00381ac..1343879b72b3 100644
--- a/include/linux/module_signature.h
+++ b/include/linux/module_signature.h
@@ -42,5 +42,6 @@ struct module_signature {
 
 int mod_check_sig(const struct module_signature *ms, size_t file_len,
  const char *name);
+int mod_parse_sig(const void *data, size_t *len, size_t *sig_len, const char 
*name);
 
 #endif /* _LINUX_MODULE_SIGNATURE_H */
diff --git a/kernel/module_signature.c b/kernel/module_signature.c
index 00132d12487c..784b40575ee4 100644
--- a/kernel/module_signature.c
+++ b/kernel/module_signature.c
@@ -8,14 +8,36 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
+/**
+ * mod_check_sig_marker - check that the given data has signature marker at 
the end
+ *
+ * @data:  Data with appended signature
+ * @len:   Length of data. Signature marker length is subtracted on 
success.
+ */
+static inline int mod_check_sig_marker(const void *data, size_t *len)
+{
+   const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
+
+   if (markerlen > *len)
+   return -ENODATA;
+
+   if (memcmp(data + *len - markerlen, MODULE_SIG_STRING,
+  markerlen))
+   return -ENODATA;
+
+   *len -= markerlen;
+   return 0;
+}
+
 /**
  * mod_check_sig - check that the given signature is sane
  *
  * @ms:Signature to check.
- * @file_len:  Size of the file to which @ms is appended.
+ * @file_len:  Size of the file to which @ms is appended (without the marker).
  * @name:  What is being checked. Used for error messages.
  */
 int mod_check_sig(const struct module_signature *ms, size_t file_len,
@@ -44,3 +66,35 @@ int mod_check_sig(const struct module_signature *ms, size_t 
file_len,
 
return 0;
 }
+
+/**
+ * mod_parse_sig - check that the given signature is sane and determine 
signature length
+ *
+ * @data:  Data with appended signature.
+ * @len:   Length of data. Signature and marker length is subtracted on 
success.
+ * @sig_len:   Length of signature. Filled on success.
+ * @name:  What is being checked. Used for error messages.
+ */
+int mod_parse_sig(const void *data, size_t *len, size_t *sig_len, const char 
*name)
+{
+   const struct module_signature *sig;
+   int rc;
+
+   rc = mod_check_sig_marker(data, len);
+   if (rc)
+   return rc;
+
+   if (*len < sizeof(*sig))
+   return -ENODATA;
+
+   sig = (const struct module_signature *)(data + (*len - sizeof(*sig)));
+
+   rc = mod_check_sig(sig, *len, name);
+   if (rc)
+   return rc;
+
+   *sig_len = be32_to_cpu(sig->sig_len);
+   *len -= *sig_len + sizeof(*sig);
+
+   return 0;
+}
diff --git a/kernel/module_signing.c b/kernel/module_signing.c
index cef72a6f6b5d..02bbca90f467 100644
--- a/kernel/module_signing.c
+++ b/kernel/module_signing.c
@@ -25,35 +25,17 @@ int verify_appended_signature(const void *data, size_t *len,
  struct key *trusted_keys,
  enum key_being_used_for purpose)
 {
-   const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
struct module_signature ms;
-   size_t sig_len, modlen = *len;
+   size_t sig_len;
int ret;
 
-   pr_devel("==>%s %s(,%zu)\n", __func__, key_being_used_for[purpose], 
modlen);
+   pr_devel("==>%s %s(,%zu)\n", __func__, key_being_used_for[purpose], 
*len);
 
-   if (markerlen > modlen)
-   return -ENODATA;
-
-   if (memcmp(data + modlen - markerlen, MODULE_SIG_STRING,
-  markerlen))
-   return -ENODATA;
-   modlen -= markerlen;
-
-   if (modlen <= sizeof(ms))
-   return -EBADMSG;
-
-   memcpy(, data + (modlen - sizeof(ms)), sizeof(ms));
-
-   ret = mod_check_sig(, modlen, key_being_used_for[purpose]);
+   ret = mod_parse_sig(data, len, _len, key_being_used_for[purpose]);
if (ret)
return ret;
 
-   sig_len = be32_to_cpu(ms.sig_len);
-   modlen -= sig_len + sizeof(ms);
-   *len = modlen;
-
-   return verify_pkcs7_signature(data, modlen, data + modlen, sig_len,
+   return verify_pkcs7_signature(data, *len, data + *len, sig_len,
  trusted_keys,
  purpose,
  NULL, NULL);
diff 

[PATCH v2 2/6] powerpc/kexec_file: Add KEXEC_SIG support.

2021-11-25 Thread Michal Suchanek
Copy the code from s390x

Signed-off-by: Michal Suchanek 
---
 arch/powerpc/Kconfig| 11 +++
 arch/powerpc/kexec/elf_64.c | 36 
 2 files changed, 47 insertions(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index ac0c515552fd..ecc1227a77f1 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -561,6 +561,17 @@ config KEXEC_FILE
 config ARCH_HAS_KEXEC_PURGATORY
def_bool KEXEC_FILE
 
+config KEXEC_SIG
+   bool "Verify kernel signature during kexec_file_load() syscall"
+   depends on KEXEC_FILE && MODULE_SIG_FORMAT
+   help
+ This option makes kernel signature verification mandatory for
+ the kexec_file_load() syscall.
+
+ In addition to that option, you need to enable signature
+ verification for the corresponding kernel image type being
+ loaded in order for this to work.
+
 config PPC64_BUILD_ELF_V2_ABI
bool
 
diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index eeb258002d1e..25dc1071feec 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void *elf64_load(struct kimage *image, char *kernel_buf,
unsigned long kernel_len, char *initrd,
@@ -151,7 +152,42 @@ static void *elf64_load(struct kimage *image, char 
*kernel_buf,
return ret ? ERR_PTR(ret) : NULL;
 }
 
+#ifdef CONFIG_KEXEC_SIG
+int elf64_verify_sig(const char *kernel, unsigned long kernel_len)
+{
+   const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
+   struct module_signature *ms;
+   unsigned long sig_len;
+   int ret;
+
+   if (marker_len > kernel_len)
+   return -EKEYREJECTED;
+
+   if (memcmp(kernel + kernel_len - marker_len, MODULE_SIG_STRING,
+  marker_len))
+   return -EKEYREJECTED;
+   kernel_len -= marker_len;
+
+   ms = (void *)kernel + kernel_len - sizeof(*ms);
+   ret = mod_check_sig(ms, kernel_len, "kexec");
+   if (ret)
+   return ret;
+
+   sig_len = be32_to_cpu(ms->sig_len);
+   kernel_len -= sizeof(*ms) + sig_len;
+
+   return verify_pkcs7_signature(kernel, kernel_len,
+ kernel + kernel_len, sig_len,
+ VERIFY_USE_PLATFORM_KEYRING,
+ VERIFYING_MODULE_SIGNATURE,
+ NULL, NULL);
+}
+#endif /* CONFIG_KEXEC_SIG */
+
 const struct kexec_file_ops kexec_elf64_ops = {
.probe = kexec_elf_probe,
.load = elf64_load,
+#ifdef CONFIG_KEXEC_SIG
+   .verify_sig = elf64_verify_sig,
+#endif
 };
-- 
2.31.1



[PATCH v2 4/6] module: strip the signature marker in the verification function.

2021-11-25 Thread Michal Suchanek
It is stripped by each caller separately.

Signed-off-by: Michal Suchanek 
---
 arch/powerpc/kexec/elf_64.c   |  9 -
 arch/s390/kernel/machine_kexec_file.c |  9 -
 kernel/module.c   |  7 +--
 kernel/module_signing.c   | 12 ++--
 4 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index 266cb26d3ca0..63634c95265d 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -156,15 +156,6 @@ static void *elf64_load(struct kimage *image, char 
*kernel_buf,
 int elf64_verify_sig(const char *kernel, unsigned long length)
 {
size_t kernel_len = length;
-   const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
-
-   if (marker_len > kernel_len)
-   return -EKEYREJECTED;
-
-   if (memcmp(kernel + kernel_len - marker_len, MODULE_SIG_STRING,
-  marker_len))
-   return -EKEYREJECTED;
-   kernel_len -= marker_len;
 
return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
"kexec_file");
diff --git a/arch/s390/kernel/machine_kexec_file.c 
b/arch/s390/kernel/machine_kexec_file.c
index 432797249db3..c4632c1a1b59 100644
--- a/arch/s390/kernel/machine_kexec_file.c
+++ b/arch/s390/kernel/machine_kexec_file.c
@@ -27,20 +27,11 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {
 int s390_verify_sig(const char *kernel, unsigned long length)
 {
size_t kernel_len = length;
-   const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
 
/* Skip signature verification when not secure IPLed. */
if (!ipl_secure_flag)
return 0;
 
-   if (marker_len > kernel_len)
-   return -EKEYREJECTED;
-
-   if (memcmp(kernel + kernel_len - marker_len, MODULE_SIG_STRING,
-  marker_len))
-   return -EKEYREJECTED;
-   kernel_len -= marker_len;
-
return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
"kexec_file");
 }
diff --git a/kernel/module.c b/kernel/module.c
index 8481933dfa92..d91ca0f93a40 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2882,7 +2882,6 @@ static inline void kmemleak_load_module(const struct 
module *mod,
 static int module_sig_check(struct load_info *info, int flags)
 {
int err = -ENODATA;
-   const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
const char *reason;
const void *mod = info->hdr;
 
@@ -2890,11 +2889,7 @@ static int module_sig_check(struct load_info *info, int 
flags)
 * Require flags == 0, as a module with version information
 * removed is no longer the module that was signed
 */
-   if (flags == 0 &&
-   info->len > markerlen &&
-   memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) 
== 0) {
-   /* We truncate the module to discard the signature */
-   info->len -= markerlen;
+   if (flags == 0) {
err = verify_appended_signature(mod, >len,
VERIFY_USE_SECONDARY_KEYRING, 
"module");
if (!err) {
diff --git a/kernel/module_signing.c b/kernel/module_signing.c
index f492e410564d..4c28cb55275f 100644
--- a/kernel/module_signing.c
+++ b/kernel/module_signing.c
@@ -15,8 +15,7 @@
 #include "module-internal.h"
 
 /**
- * verify_appended_signature - Verify the signature on a module with the
- * signature marker stripped.
+ * verify_appended_signature - Verify the signature on a module
  * @data: The data to be verified
  * @len: Size of @data.
  * @trusted_keys: Keyring to use for verification
@@ -25,12 +24,21 @@
 int verify_appended_signature(const void *data, size_t *len,
  struct key *trusted_keys, const char *what)
 {
+   const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
struct module_signature ms;
size_t sig_len, modlen = *len;
int ret;
 
pr_devel("==>%s(,%zu)\n", __func__, modlen);
 
+   if (markerlen > modlen)
+   return -ENODATA;
+
+   if (memcmp(data + modlen - markerlen, MODULE_SIG_STRING,
+  markerlen))
+   return -ENODATA;
+   modlen -= markerlen;
+
if (modlen <= sizeof(ms))
return -EBADMSG;
 
-- 
2.31.1



[PATCH v2 5/6] module: Use key_being_used_for for log messages in verify_appended_signature

2021-11-25 Thread Michal Suchanek
Add value for kexec appended signature and pass in key_being_used_for
enum rather than a string to verify_appended_signature to produce log
messages about the signature.

Signed-off-by: Michal Suchanek 
---
 arch/powerpc/kexec/elf_64.c  |  2 +-
 arch/s390/kernel/machine_kexec_file.c|  2 +-
 crypto/asymmetric_keys/asymmetric_type.c |  1 +
 include/linux/verification.h |  3 ++-
 kernel/module.c  |  3 ++-
 kernel/module_signing.c  | 11 ++-
 6 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index 63634c95265d..3aa5269f6e0f 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -158,7 +158,7 @@ int elf64_verify_sig(const char *kernel, unsigned long 
length)
size_t kernel_len = length;
 
return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
-   "kexec_file");
+VERIFYING_KEXEC_APPENDED_SIGNATURE);
 }
 #endif /* CONFIG_KEXEC_SIG */
 
diff --git a/arch/s390/kernel/machine_kexec_file.c 
b/arch/s390/kernel/machine_kexec_file.c
index c4632c1a1b59..316d082c9d99 100644
--- a/arch/s390/kernel/machine_kexec_file.c
+++ b/arch/s390/kernel/machine_kexec_file.c
@@ -33,7 +33,7 @@ int s390_verify_sig(const char *kernel, unsigned long length)
return 0;
 
return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
-   "kexec_file");
+   VERIFYING_KEXEC_APPENDED_SIGNATURE);
 }
 #endif /* CONFIG_KEXEC_SIG */
 
diff --git a/crypto/asymmetric_keys/asymmetric_type.c 
b/crypto/asymmetric_keys/asymmetric_type.c
index ad8af3d70ac0..6fd20eec3882 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -25,6 +25,7 @@ const char *const key_being_used_for[NR__KEY_BEING_USED_FOR] 
= {
[VERIFYING_KEXEC_PE_SIGNATURE]  = "kexec PE sig",
[VERIFYING_KEY_SIGNATURE]   = "key sig",
[VERIFYING_KEY_SELF_SIGNATURE]  = "key self sig",
+   [VERIFYING_KEXEC_APPENDED_SIGNATURE]= "kexec appended sig",
[VERIFYING_UNSPECIFIED_SIGNATURE]   = "unspec sig",
 };
 EXPORT_SYMBOL_GPL(key_being_used_for);
diff --git a/include/linux/verification.h b/include/linux/verification.h
index c1cf0582012a..23748feb9e03 100644
--- a/include/linux/verification.h
+++ b/include/linux/verification.h
@@ -26,6 +26,7 @@ enum key_being_used_for {
VERIFYING_KEXEC_PE_SIGNATURE,
VERIFYING_KEY_SIGNATURE,
VERIFYING_KEY_SELF_SIGNATURE,
+   VERIFYING_KEXEC_APPENDED_SIGNATURE,
VERIFYING_UNSPECIFIED_SIGNATURE,
NR__KEY_BEING_USED_FOR
 };
@@ -61,7 +62,7 @@ extern int verify_pefile_signature(const void *pebuf, 
unsigned pelen,
 #endif
 
 int verify_appended_signature(const void *data, size_t *len, struct key 
*trusted_keys,
- const char *what);
+ enum key_being_used_for purpose);
 
 #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
 #endif /* _LINUX_VERIFY_PEFILE_H */
diff --git a/kernel/module.c b/kernel/module.c
index d91ca0f93a40..0a359dc6b690 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2891,7 +2891,8 @@ static int module_sig_check(struct load_info *info, int 
flags)
 */
if (flags == 0) {
err = verify_appended_signature(mod, >len,
-   VERIFY_USE_SECONDARY_KEYRING, 
"module");
+   VERIFY_USE_SECONDARY_KEYRING,
+   VERIFYING_MODULE_SIGNATURE);
if (!err) {
info->sig_ok = true;
return 0;
diff --git a/kernel/module_signing.c b/kernel/module_signing.c
index 4c28cb55275f..cef72a6f6b5d 100644
--- a/kernel/module_signing.c
+++ b/kernel/module_signing.c
@@ -19,17 +19,18 @@
  * @data: The data to be verified
  * @len: Size of @data.
  * @trusted_keys: Keyring to use for verification
- * @what: Informational string for log messages
+ * @purpose: The use to which the key is being put
  */
 int verify_appended_signature(const void *data, size_t *len,
- struct key *trusted_keys, const char *what)
+ struct key *trusted_keys,
+ enum key_being_used_for purpose)
 {
const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
struct module_signature ms;
size_t sig_len, modlen = *len;
int ret;
 
-   pr_devel("==>%s(,%zu)\n", __func__, modlen);
+   pr_devel("==>%s %s(,%zu)\n", __func__, key_being_used_for[purpose], 
modlen);
 
if (markerlen > modlen)
return -ENODATA;
@@ -44,7 +45,7 @@ int verify_appended_signature(const void *data, 

[PATCH v2 3/6] kexec_file: Don't opencode appended signature verification.

2021-11-25 Thread Michal Suchanek
Module verification already implements appeded signature verification.

Reuse it for kexec_file.

Signed-off-by: Michal Suchanek 
---
 arch/powerpc/kexec/elf_64.c   | 21 -
 arch/s390/kernel/machine_kexec_file.c | 21 -
 include/linux/verification.h  |  3 +++
 kernel/module-internal.h  |  2 --
 kernel/module.c   |  4 +++-
 kernel/module_signing.c   | 24 +++-
 6 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index 25dc1071feec..266cb26d3ca0 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -153,12 +153,10 @@ static void *elf64_load(struct kimage *image, char 
*kernel_buf,
 }
 
 #ifdef CONFIG_KEXEC_SIG
-int elf64_verify_sig(const char *kernel, unsigned long kernel_len)
+int elf64_verify_sig(const char *kernel, unsigned long length)
 {
+   size_t kernel_len = length;
const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
-   struct module_signature *ms;
-   unsigned long sig_len;
-   int ret;
 
if (marker_len > kernel_len)
return -EKEYREJECTED;
@@ -168,19 +166,8 @@ int elf64_verify_sig(const char *kernel, unsigned long 
kernel_len)
return -EKEYREJECTED;
kernel_len -= marker_len;
 
-   ms = (void *)kernel + kernel_len - sizeof(*ms);
-   ret = mod_check_sig(ms, kernel_len, "kexec");
-   if (ret)
-   return ret;
-
-   sig_len = be32_to_cpu(ms->sig_len);
-   kernel_len -= sizeof(*ms) + sig_len;
-
-   return verify_pkcs7_signature(kernel, kernel_len,
- kernel + kernel_len, sig_len,
- VERIFY_USE_PLATFORM_KEYRING,
- VERIFYING_MODULE_SIGNATURE,
- NULL, NULL);
+   return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
+   "kexec_file");
 }
 #endif /* CONFIG_KEXEC_SIG */
 
diff --git a/arch/s390/kernel/machine_kexec_file.c 
b/arch/s390/kernel/machine_kexec_file.c
index 43a9abe48abd..432797249db3 100644
--- a/arch/s390/kernel/machine_kexec_file.c
+++ b/arch/s390/kernel/machine_kexec_file.c
@@ -24,12 +24,10 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {
 };
 
 #ifdef CONFIG_KEXEC_SIG
-int s390_verify_sig(const char *kernel, unsigned long kernel_len)
+int s390_verify_sig(const char *kernel, unsigned long length)
 {
+   size_t kernel_len = length;
const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
-   struct module_signature *ms;
-   unsigned long sig_len;
-   int ret;
 
/* Skip signature verification when not secure IPLed. */
if (!ipl_secure_flag)
@@ -43,19 +41,8 @@ int s390_verify_sig(const char *kernel, unsigned long 
kernel_len)
return -EKEYREJECTED;
kernel_len -= marker_len;
 
-   ms = (void *)kernel + kernel_len - sizeof(*ms);
-   ret = mod_check_sig(ms, kernel_len, "kexec");
-   if (ret)
-   return ret;
-
-   sig_len = be32_to_cpu(ms->sig_len);
-   kernel_len -= sizeof(*ms) + sig_len;
-
-   return verify_pkcs7_signature(kernel, kernel_len,
- kernel + kernel_len, sig_len,
- VERIFY_USE_PLATFORM_KEYRING,
- VERIFYING_MODULE_SIGNATURE,
- NULL, NULL);
+   return verify_appended_signature(kernel, _len, 
VERIFY_USE_PLATFORM_KEYRING,
+   "kexec_file");
 }
 #endif /* CONFIG_KEXEC_SIG */
 
diff --git a/include/linux/verification.h b/include/linux/verification.h
index a655923335ae..c1cf0582012a 100644
--- a/include/linux/verification.h
+++ b/include/linux/verification.h
@@ -60,5 +60,8 @@ extern int verify_pefile_signature(const void *pebuf, 
unsigned pelen,
   enum key_being_used_for usage);
 #endif
 
+int verify_appended_signature(const void *data, size_t *len, struct key 
*trusted_keys,
+ const char *what);
+
 #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
 #endif /* _LINUX_VERIFY_PEFILE_H */
diff --git a/kernel/module-internal.h b/kernel/module-internal.h
index 33783abc377b..80461e14bf29 100644
--- a/kernel/module-internal.h
+++ b/kernel/module-internal.h
@@ -27,5 +27,3 @@ struct load_info {
unsigned int sym, str, mod, vers, info, pcpu;
} index;
 };
-
-extern int mod_verify_sig(const void *mod, struct load_info *info);
diff --git a/kernel/module.c b/kernel/module.c
index 84a9141a5e15..8481933dfa92 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "module-internal.h"
 
@@ -2894,7 +2895,8 @@ static int 

[PATCH v2 1/6] s390/kexec_file: Don't opencode appended signature check.

2021-11-25 Thread Michal Suchanek
Module verification already implements appeded signature check.

Reuse it for kexec_file.

Signed-off-by: Michal Suchanek 
---
 arch/s390/kernel/machine_kexec_file.c | 22 +-
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/arch/s390/kernel/machine_kexec_file.c 
b/arch/s390/kernel/machine_kexec_file.c
index 9975ad200d74..43a9abe48abd 100644
--- a/arch/s390/kernel/machine_kexec_file.c
+++ b/arch/s390/kernel/machine_kexec_file.c
@@ -29,6 +29,7 @@ int s390_verify_sig(const char *kernel, unsigned long 
kernel_len)
const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
struct module_signature *ms;
unsigned long sig_len;
+   int ret;
 
/* Skip signature verification when not secure IPLed. */
if (!ipl_secure_flag)
@@ -43,25 +44,12 @@ int s390_verify_sig(const char *kernel, unsigned long 
kernel_len)
kernel_len -= marker_len;
 
ms = (void *)kernel + kernel_len - sizeof(*ms);
-   kernel_len -= sizeof(*ms);
+   ret = mod_check_sig(ms, kernel_len, "kexec");
+   if (ret)
+   return ret;
 
sig_len = be32_to_cpu(ms->sig_len);
-   if (sig_len >= kernel_len)
-   return -EKEYREJECTED;
-   kernel_len -= sig_len;
-
-   if (ms->id_type != PKEY_ID_PKCS7)
-   return -EKEYREJECTED;
-
-   if (ms->algo != 0 ||
-   ms->hash != 0 ||
-   ms->signer_len != 0 ||
-   ms->key_id_len != 0 ||
-   ms->__pad[0] != 0 ||
-   ms->__pad[1] != 0 ||
-   ms->__pad[2] != 0) {
-   return -EBADMSG;
-   }
+   kernel_len -= sizeof(*ms) + sig_len;
 
return verify_pkcs7_signature(kernel, kernel_len,
  kernel + kernel_len, sig_len,
-- 
2.31.1



[PATCH v2 0/6] KEXEC_SIG with appended signature

2021-11-25 Thread Michal Suchanek
Hello,

This is resend of the KEXEC_SIG patchset.

The first patch is new because it'a a cleanup that does not require any
change to the module verification code.

The second patch is the only one that is intended to change any
functionality.

The rest only deduplicates code but I did not receive any review on that
part so I don't know if it's desirable as implemented.

The first two patches can be applied separately without the rest.

Thanks

Michal

Michal Suchanek (6):
  s390/kexec_file: Don't opencode appended signature check.
  powerpc/kexec_file: Add KEXEC_SIG support.
  kexec_file: Don't opencode appended signature verification.
  module: strip the signature marker in the verification function.
  module: Use key_being_used_for for log messages in
verify_appended_signature
  module: Move duplicate mod_check_sig users code to mod_parse_sig

 arch/powerpc/Kconfig | 11 +
 arch/powerpc/kexec/elf_64.c  | 14 ++
 arch/s390/kernel/machine_kexec_file.c| 42 ++
 crypto/asymmetric_keys/asymmetric_type.c |  1 +
 include/linux/module_signature.h |  1 +
 include/linux/verification.h |  4 ++
 kernel/module-internal.h |  2 -
 kernel/module.c  | 12 +++--
 kernel/module_signature.c| 56 +++-
 kernel/module_signing.c  | 33 +++---
 security/integrity/ima/ima_modsig.c  | 22 ++
 11 files changed, 113 insertions(+), 85 deletions(-)

-- 
2.31.1



[PATCH v2 rebased 3/9] powerpc/mm: Remove CONFIG_PPC_MM_SLICES

2021-11-25 Thread Christophe Leroy
CONFIG_PPC_MM_SLICES is always selected by hash book3s/64.
CONFIG_PPC_MM_SLICES is never selected by other platforms.

Remove it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/64/hash.h |  4 ++--
 arch/powerpc/include/asm/hugetlb.h|  2 +-
 arch/powerpc/include/asm/paca.h   |  7 ---
 arch/powerpc/include/asm/slice.h  | 13 ++---
 arch/powerpc/kernel/paca.c|  5 -
 arch/powerpc/mm/book3s64/Makefile |  3 +--
 arch/powerpc/mm/book3s64/hash_utils.c | 14 --
 arch/powerpc/platforms/Kconfig.cputype|  4 
 8 files changed, 6 insertions(+), 46 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/hash.h 
b/arch/powerpc/include/asm/book3s/64/hash.h
index 674fe0e890dc..97f2fc217a49 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -99,10 +99,10 @@
  * Defines the address of the vmemap area, in its own region on
  * hash table CPUs.
  */
-#ifdef CONFIG_PPC_MM_SLICES
+#ifdef CONFIG_PPC_64S_HASH_MMU
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
-#endif /* CONFIG_PPC_MM_SLICES */
+#endif
 
 /* PTEIDX nibble */
 #define _PTEIDX_SECONDARY  0x8
diff --git a/arch/powerpc/include/asm/hugetlb.h 
b/arch/powerpc/include/asm/hugetlb.h
index f18c543bc01d..86a60ba6bd2a 100644
--- a/arch/powerpc/include/asm/hugetlb.h
+++ b/arch/powerpc/include/asm/hugetlb.h
@@ -24,7 +24,7 @@ static inline int is_hugepage_only_range(struct mm_struct *mm,
 unsigned long addr,
 unsigned long len)
 {
-   if (IS_ENABLED(CONFIG_PPC_MM_SLICES) && !radix_enabled())
+   if (IS_ENABLED(CONFIG_PPC_64S_HASH_MMU) && !radix_enabled())
return slice_is_hugepage_only_range(mm, addr, len);
return 0;
 }
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 295573a82c66..bd4dd02e61c8 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -152,16 +152,9 @@ struct paca_struct {
struct tlb_core_data tcd;
 #endif /* CONFIG_PPC_BOOK3E */
 
-#ifdef CONFIG_PPC_BOOK3S
 #ifdef CONFIG_PPC_64S_HASH_MMU
-#ifdef CONFIG_PPC_MM_SLICES
unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE];
unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE];
-#else
-   u16 mm_ctx_user_psize;
-   u16 mm_ctx_sllp;
-#endif
-#endif
 #endif
 
/*
diff --git a/arch/powerpc/include/asm/slice.h b/arch/powerpc/include/asm/slice.h
index 0bdd9c62eca0..b15141f2bd76 100644
--- a/arch/powerpc/include/asm/slice.h
+++ b/arch/powerpc/include/asm/slice.h
@@ -10,7 +10,7 @@
 
 struct mm_struct;
 
-#ifdef CONFIG_PPC_MM_SLICES
+#ifdef CONFIG_PPC_64S_HASH_MMU
 
 #ifdef CONFIG_HUGETLB_PAGE
 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
@@ -30,16 +30,7 @@ void slice_set_range_psize(struct mm_struct *mm, unsigned 
long start,
 void slice_init_new_context_exec(struct mm_struct *mm);
 void slice_setup_new_exec(void);
 
-#else /* CONFIG_PPC_MM_SLICES */
-
-static inline void slice_init_new_context_exec(struct mm_struct *mm) {}
-
-static inline unsigned int get_slice_psize(struct mm_struct *mm, unsigned long 
addr)
-{
-   return 0;
-}
-
-#endif /* CONFIG_PPC_MM_SLICES */
+#endif /* CONFIG_PPC_64S_HASH_MMU */
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c
index 39da688a9455..ba593fd60124 100644
--- a/arch/powerpc/kernel/paca.c
+++ b/arch/powerpc/kernel/paca.c
@@ -344,15 +344,10 @@ void copy_mm_to_paca(struct mm_struct *mm)
 {
mm_context_t *context = >context;
 
-#ifdef CONFIG_PPC_MM_SLICES
VM_BUG_ON(!mm_ctx_slb_addr_limit(context));
memcpy(_paca()->mm_ctx_low_slices_psize, mm_ctx_low_slices(context),
   LOW_SLICE_ARRAY_SZ);
memcpy(_paca()->mm_ctx_high_slices_psize, 
mm_ctx_high_slices(context),
   TASK_SLICE_ARRAY_SZ(context));
-#else /* CONFIG_PPC_MM_SLICES */
-   get_paca()->mm_ctx_user_psize = context->user_psize;
-   get_paca()->mm_ctx_sllp = context->sllp;
-#endif
 }
 #endif /* CONFIG_PPC_64S_HASH_MMU */
diff --git a/arch/powerpc/mm/book3s64/Makefile 
b/arch/powerpc/mm/book3s64/Makefile
index af2f3e75d458..d527dc8e30a8 100644
--- a/arch/powerpc/mm/book3s64/Makefile
+++ b/arch/powerpc/mm/book3s64/Makefile
@@ -5,7 +5,7 @@ ccflags-y   := $(NO_MINIMAL_TOC)
 obj-y  += mmu_context.o pgtable.o trace.o
 ifdef CONFIG_PPC_64S_HASH_MMU
 CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
-obj-y  += hash_pgtable.o hash_utils.o hash_tlb.o slb.o
+obj-y  += hash_pgtable.o hash_utils.o hash_tlb.o slb.o 
slice.o
 obj-$(CONFIG_PPC_HASH_MMU_NATIVE)  += hash_native.o
 obj-$(CONFIG_PPC_4K_PAGES) += hash_4k.o
 obj-$(CONFIG_PPC_64K_PAGES)+= hash_64k.o
@@ -21,7 +21,6 @@ obj-$(CONFIG_PPC_RADIX_MMU)   += radix_hugetlbpage.o
 endif
 

[PATCH v2 rebased 4/9] powerpc/mm: Remove asm/slice.h

2021-11-25 Thread Christophe Leroy
Move necessary stuff in asm/book3s/64/slice.h and
remove asm/slice.h

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/64/hash.h |  3 ++
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |  1 +
 arch/powerpc/include/asm/book3s/64/slice.h| 18 +
 arch/powerpc/include/asm/page.h   |  1 -
 arch/powerpc/include/asm/slice.h  | 37 ---
 5 files changed, 22 insertions(+), 38 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/slice.h

diff --git a/arch/powerpc/include/asm/book3s/64/hash.h 
b/arch/powerpc/include/asm/book3s/64/hash.h
index 97f2fc217a49..fab032f552f3 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -100,6 +100,9 @@
  * hash table CPUs.
  */
 #ifdef CONFIG_PPC_64S_HASH_MMU
+#ifdef CONFIG_HUGETLB_PAGE
+#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
+#endif
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
 #endif
diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 3004f3323144..b4b2ca111f75 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -18,6 +18,7 @@
  * complete pgtable.h but only a portion of it.
  */
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/powerpc/include/asm/book3s/64/slice.h 
b/arch/powerpc/include/asm/book3s/64/slice.h
index f0d3194ba41b..5b0f7105bc8b 100644
--- a/arch/powerpc/include/asm/book3s/64/slice.h
+++ b/arch/powerpc/include/asm/book3s/64/slice.h
@@ -2,6 +2,8 @@
 #ifndef _ASM_POWERPC_BOOK3S_64_SLICE_H
 #define _ASM_POWERPC_BOOK3S_64_SLICE_H
 
+#ifndef __ASSEMBLY__
+
 #define SLICE_LOW_SHIFT28
 #define SLICE_LOW_TOP  (0x1ul)
 #define SLICE_NUM_LOW  (SLICE_LOW_TOP >> SLICE_LOW_SHIFT)
@@ -13,4 +15,20 @@
 
 #define SLB_ADDR_LIMIT_DEFAULT DEFAULT_MAP_WINDOW_USER64
 
+struct mm_struct;
+
+unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
+ unsigned long flags, unsigned int psize,
+ int topdown);
+
+unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr);
+
+void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
+  unsigned long len, unsigned int psize);
+
+void slice_init_new_context_exec(struct mm_struct *mm);
+void slice_setup_new_exec(void);
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* _ASM_POWERPC_BOOK3S_64_SLICE_H */
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index 254687258f42..62e0c6f12869 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -329,6 +329,5 @@ static inline unsigned long kaslr_offset(void)
 
 #include 
 #endif /* __ASSEMBLY__ */
-#include 
 
 #endif /* _ASM_POWERPC_PAGE_H */
diff --git a/arch/powerpc/include/asm/slice.h b/arch/powerpc/include/asm/slice.h
deleted file mode 100644
index b15141f2bd76..
--- a/arch/powerpc/include/asm/slice.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_POWERPC_SLICE_H
-#define _ASM_POWERPC_SLICE_H
-
-#ifdef CONFIG_PPC_BOOK3S_64
-#include 
-#endif
-
-#ifndef __ASSEMBLY__
-
-struct mm_struct;
-
-#ifdef CONFIG_PPC_64S_HASH_MMU
-
-#ifdef CONFIG_HUGETLB_PAGE
-#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
-#endif
-#define HAVE_ARCH_UNMAPPED_AREA
-#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
-
-unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
- unsigned long flags, unsigned int psize,
- int topdown);
-
-unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr);
-
-void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
-  unsigned long len, unsigned int psize);
-
-void slice_init_new_context_exec(struct mm_struct *mm);
-void slice_setup_new_exec(void);
-
-#endif /* CONFIG_PPC_64S_HASH_MMU */
-
-#endif /* __ASSEMBLY__ */
-
-#endif /* _ASM_POWERPC_SLICE_H */
-- 
2.33.1



[PATCH v2 rebased 5/9] powerpc/mm: Call radix__arch_get_unmapped_area() from arch_get_unmapped_area()

2021-11-25 Thread Christophe Leroy
Instead of setting mm->get_unmapped_area() to either
arch_get_unmapped_area() or radix__arch_get_unmapped_area(),
always set it to arch_get_unmapped_area() and call
radix__arch_get_unmapped_area() from there when radix is enabled.

To keep radix__arch_get_unmapped_area() static, move it to slice.c

Do the same with radix__arch_get_unmapped_area_topdown()

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/book3s64/slice.c | 104 ++
 arch/powerpc/mm/mmap.c   | 123 ---
 2 files changed, 104 insertions(+), 123 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c
index 4c3e9601fdf6..99742dde811c 100644
--- a/arch/powerpc/mm/book3s64/slice.c
+++ b/arch/powerpc/mm/book3s64/slice.c
@@ -639,12 +639,113 @@ unsigned long slice_get_unmapped_area(unsigned long 
addr, unsigned long len,
 }
 EXPORT_SYMBOL_GPL(slice_get_unmapped_area);
 
+/*
+ * Same function as generic code used only for radix, because we don't need to 
overload
+ * the generic one. But we will have to duplicate, because hash select
+ * HAVE_ARCH_UNMAPPED_AREA
+ */
+static unsigned long
+radix__arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned 
long len,
+ unsigned long pgoff, unsigned long flags)
+{
+   struct mm_struct *mm = current->mm;
+   struct vm_area_struct *vma;
+   int fixed = (flags & MAP_FIXED);
+   unsigned long high_limit;
+   struct vm_unmapped_area_info info;
+
+   high_limit = DEFAULT_MAP_WINDOW;
+   if (addr >= high_limit || (fixed && (addr + len > high_limit)))
+   high_limit = TASK_SIZE;
+
+   if (len > high_limit)
+   return -ENOMEM;
+
+   if (fixed) {
+   if (addr > high_limit - len)
+   return -ENOMEM;
+   return addr;
+   }
+
+   if (addr) {
+   addr = PAGE_ALIGN(addr);
+   vma = find_vma(mm, addr);
+   if (high_limit - len >= addr && addr >= mmap_min_addr &&
+   (!vma || addr + len <= vm_start_gap(vma)))
+   return addr;
+   }
+
+   info.flags = 0;
+   info.length = len;
+   info.low_limit = mm->mmap_base;
+   info.high_limit = high_limit;
+   info.align_mask = 0;
+
+   return vm_unmapped_area();
+}
+
+static unsigned long
+radix__arch_get_unmapped_area_topdown(struct file *filp, const unsigned long 
addr0,
+ const unsigned long len, const unsigned 
long pgoff,
+ const unsigned long flags)
+{
+   struct vm_area_struct *vma;
+   struct mm_struct *mm = current->mm;
+   unsigned long addr = addr0;
+   int fixed = (flags & MAP_FIXED);
+   unsigned long high_limit;
+   struct vm_unmapped_area_info info;
+
+   high_limit = DEFAULT_MAP_WINDOW;
+   if (addr >= high_limit || (fixed && (addr + len > high_limit)))
+   high_limit = TASK_SIZE;
+
+   if (len > high_limit)
+   return -ENOMEM;
+
+   if (fixed) {
+   if (addr > high_limit - len)
+   return -ENOMEM;
+   return addr;
+   }
+
+   if (addr) {
+   addr = PAGE_ALIGN(addr);
+   vma = find_vma(mm, addr);
+   if (high_limit - len >= addr && addr >= mmap_min_addr &&
+   (!vma || addr + len <= vm_start_gap(vma)))
+   return addr;
+   }
+
+   info.flags = VM_UNMAPPED_AREA_TOPDOWN;
+   info.length = len;
+   info.low_limit = max(PAGE_SIZE, mmap_min_addr);
+   info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW);
+   info.align_mask = 0;
+
+   addr = vm_unmapped_area();
+   if (!(addr & ~PAGE_MASK))
+   return addr;
+   VM_BUG_ON(addr != -ENOMEM);
+
+   /*
+* A failed mmap() very likely causes application failure,
+* so fall back to the bottom-up function here. This scenario
+* can happen with large stack limits and large mmap()
+* allocations.
+*/
+   return radix__arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
+}
+
 unsigned long arch_get_unmapped_area(struct file *filp,
 unsigned long addr,
 unsigned long len,
 unsigned long pgoff,
 unsigned long flags)
 {
+   if (radix_enabled())
+   return radix__arch_get_unmapped_area(filp, addr, len, pgoff, 
flags);
+
return slice_get_unmapped_area(addr, len, flags,
   
mm_ctx_user_psize(>mm->context), 0);
 }
@@ -655,6 +756,9 @@ unsigned long arch_get_unmapped_area_topdown(struct file 
*filp,
 const unsigned long pgoff,
 const 

[PATCH v2 rebased 7/9] powerpc/mm: Convert to default topdown mmap layout

2021-11-25 Thread Christophe Leroy
Select CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT and
remove arch/powerpc/mm/mmap.c

This change provides standard randomisation of mmaps.

See commit 8b8addf891de ("x86/mm/32: Enable full randomization on i386
and X86_32") for all the benefits of mmap randomisation.

Signed-off-by: Christophe Leroy 
---
v2: Also remove selection of ARCH_HAS_ELF_RANDOMIZE as it is already selected 
by CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
---
 arch/powerpc/Kconfig |   2 +-
 arch/powerpc/include/asm/processor.h |   2 -
 arch/powerpc/mm/Makefile |   2 +-
 arch/powerpc/mm/mmap.c   | 105 ---
 4 files changed, 2 insertions(+), 109 deletions(-)
 delete mode 100644 arch/powerpc/mm/mmap.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index fb48823ccd62..20504a9901f2 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -122,7 +122,6 @@ config PPC
select ARCH_HAS_DEBUG_WXif STRICT_KERNEL_RWX
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_DMA_MAP_DIRECT  if PPC_PSERIES
-   select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
select ARCH_HAS_HUGEPD  if HUGETLB_PAGE
@@ -158,6 +157,7 @@ config PPC
select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS  if PPC_QUEUED_SPINLOCKS
select ARCH_USE_QUEUED_SPINLOCKSif PPC_QUEUED_SPINLOCKS
+   select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
select ARCH_WANT_IPC_PARSE_VERSION
select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
select ARCH_WANT_LD_ORPHAN_WARN
diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index e39bd0ff69f3..d906b14dd599 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -378,8 +378,6 @@ static inline void prefetchw(const void *x)
 
 #define spin_lock_prefetch(x)  prefetchw(x)
 
-#define HAVE_ARCH_PICK_MMAP_LAYOUT
-
 /* asm stubs */
 extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
 extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index d4c20484dad9..503a6e249940 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -5,7 +5,7 @@
 
 ccflags-$(CONFIG_PPC64):= $(NO_MINIMAL_TOC)
 
-obj-y  := fault.o mem.o pgtable.o mmap.o maccess.o 
pageattr.o \
+obj-y  := fault.o mem.o pgtable.o maccess.o pageattr.o 
\
   init_$(BITS).o pgtable_$(BITS).o \
   pgtable-frag.o ioremap.o ioremap_$(BITS).o \
   init-common.o mmu_context.o drmem.o \
diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
deleted file mode 100644
index 5972d619d274..
--- a/arch/powerpc/mm/mmap.c
+++ /dev/null
@@ -1,105 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- *  flexible mmap layout support
- *
- * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
- * All Rights Reserved.
- *
- * Started by Ingo Molnar 
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-/*
- * Top of mmap area (just below the process stack).
- *
- * Leave at least a ~128 MB hole.
- */
-#define MIN_GAP (128*1024*1024)
-#define MAX_GAP (TASK_SIZE/6*5)
-
-static inline int mmap_is_legacy(struct rlimit *rlim_stack)
-{
-   if (current->personality & ADDR_COMPAT_LAYOUT)
-   return 1;
-
-   if (rlim_stack->rlim_cur == RLIM_INFINITY)
-   return 1;
-
-   return sysctl_legacy_va_layout;
-}
-
-unsigned long arch_mmap_rnd(void)
-{
-   unsigned long shift, rnd;
-
-   shift = mmap_rnd_bits;
-#ifdef CONFIG_COMPAT
-   if (is_32bit_task())
-   shift = mmap_rnd_compat_bits;
-#endif
-   rnd = get_random_long() % (1ul << shift);
-
-   return rnd << PAGE_SHIFT;
-}
-
-static inline unsigned long stack_maxrandom_size(void)
-{
-   if (!(current->flags & PF_RANDOMIZE))
-   return 0;
-
-   /* 8MB for 32bit, 1GB for 64bit */
-   if (is_32bit_task())
-   return (1<<23);
-   else
-   return (1<<30);
-}
-
-static inline unsigned long mmap_base(unsigned long rnd,
- struct rlimit *rlim_stack)
-{
-   unsigned long gap = rlim_stack->rlim_cur;
-   unsigned long pad = stack_maxrandom_size() + stack_guard_gap;
-
-   /* Values close to RLIM_INFINITY can overflow. */
-   if (gap + pad > gap)
-   gap += pad;
-
-   if (gap < MIN_GAP)
-   gap = MIN_GAP;
-   else if (gap > MAX_GAP)
-   gap = MAX_GAP;
-
-   return PAGE_ALIGN(DEFAULT_MAP_WINDOW - gap - rnd);
-}
-
-/*
- * This function, called very early during the creation of a new
- * process VM image, 

[PATCH v2 rebased 8/9] powerpc/mm: Properly randomise mmap with slices

2021-11-25 Thread Christophe Leroy
Now that powerpc switched to default topdown mmap layout,
mm->mmap_base is properly randomised.  However
slice_find_area_bottomup() doesn't use mm->mmap_base but
uses the fixed TASK_UNMAPPED_BASE instead.

slice_find_area_bottomup() being used as a fallback to
slice_find_area_topdown(), it can't use mm->mmap_base
directly.

Instead of always using TASK_UNMAPPED_BASE as base address, leave
it to the caller. When called from slice_find_area_topdown()
TASK_UNMAPPED_BASE is used. Otherwise mm->mmap_base is used.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/book3s64/slice.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c
index 99742dde811c..997f40184e97 100644
--- a/arch/powerpc/mm/book3s64/slice.c
+++ b/arch/powerpc/mm/book3s64/slice.c
@@ -276,20 +276,18 @@ static bool slice_scan_available(unsigned long addr,
 }
 
 static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
- unsigned long len,
+ unsigned long addr, unsigned long 
len,
  const struct slice_mask 
*available,
  int psize, unsigned long 
high_limit)
 {
int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
-   unsigned long addr, found, next_end;
+   unsigned long found, next_end;
struct vm_unmapped_area_info info;
 
info.flags = 0;
info.length = len;
info.align_mask = PAGE_MASK & ((1ul << pshift) - 1);
info.align_offset = 0;
-
-   addr = TASK_UNMAPPED_BASE;
/*
 * Check till the allow max value for this mmap request
 */
@@ -322,12 +320,12 @@ static unsigned long slice_find_area_bottomup(struct 
mm_struct *mm,
 }
 
 static unsigned long slice_find_area_topdown(struct mm_struct *mm,
-unsigned long len,
+unsigned long addr, unsigned long 
len,
 const struct slice_mask *available,
 int psize, unsigned long 
high_limit)
 {
int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
-   unsigned long addr, found, prev;
+   unsigned long found, prev;
struct vm_unmapped_area_info info;
unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr);
 
@@ -335,8 +333,6 @@ static unsigned long slice_find_area_topdown(struct 
mm_struct *mm,
info.length = len;
info.align_mask = PAGE_MASK & ((1ul << pshift) - 1);
info.align_offset = 0;
-
-   addr = mm->mmap_base;
/*
 * If we are trying to allocate above DEFAULT_MAP_WINDOW
 * Add the different to the mmap_base.
@@ -377,7 +373,7 @@ static unsigned long slice_find_area_topdown(struct 
mm_struct *mm,
 * can happen with large stack limits and large mmap()
 * allocations.
 */
-   return slice_find_area_bottomup(mm, len, available, psize, high_limit);
+   return slice_find_area_bottomup(mm, TASK_UNMAPPED_BASE, len, available, 
psize, high_limit);
 }
 
 
@@ -386,9 +382,9 @@ static unsigned long slice_find_area(struct mm_struct *mm, 
unsigned long len,
 int topdown, unsigned long high_limit)
 {
if (topdown)
-   return slice_find_area_topdown(mm, len, mask, psize, 
high_limit);
+   return slice_find_area_topdown(mm, mm->mmap_base, len, mask, 
psize, high_limit);
else
-   return slice_find_area_bottomup(mm, len, mask, psize, 
high_limit);
+   return slice_find_area_bottomup(mm, mm->mmap_base, len, mask, 
psize, high_limit);
 }
 
 static inline void slice_copy_mask(struct slice_mask *dst,
-- 
2.33.1



[PATCH v2 rebased 9/9] powerpc: Simplify and move arch_randomize_brk()

2021-11-25 Thread Christophe Leroy
arch_randomize_brk() is only needed for hash on book3s/64, for other
platforms the one provided by the default mmap layout is good enough.

Move it to hash_utils.c and use randomize_page() like the generic one.

And properly opt out the radix case instead of making an assumption
on mmu_highuser_ssize.

Also change to a 32M range like most other architectures instead of 8M.

Signed-off-by: Christophe Leroy 
---
v3: Add missing include 

v2: New
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/process.c | 41 ---
 arch/powerpc/mm/book3s64/hash_utils.c | 19 +
 include/linux/sizes.h |  2 ++
 3 files changed, 21 insertions(+), 41 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index a64cfbb85ca2..44c4bce5211d 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -34,10 +34,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -2310,42 +2308,3 @@ unsigned long arch_align_stack(unsigned long sp)
sp -= get_random_int() & ~PAGE_MASK;
return sp & ~0xf;
 }
-
-static inline unsigned long brk_rnd(void)
-{
-unsigned long rnd = 0;
-
-   /* 8MB for 32bit, 1GB for 64bit */
-   if (is_32bit_task())
-   rnd = (get_random_long() % (1UL<<(23-PAGE_SHIFT)));
-   else
-   rnd = (get_random_long() % (1UL<<(30-PAGE_SHIFT)));
-
-   return rnd << PAGE_SHIFT;
-}
-
-unsigned long arch_randomize_brk(struct mm_struct *mm)
-{
-   unsigned long base = mm->brk;
-   unsigned long ret;
-
-#ifdef CONFIG_PPC_BOOK3S_64
-   /*
-* If we are using 1TB segments and we are allowed to randomise
-* the heap, we can put it above 1TB so it is backed by a 1TB
-* segment. Otherwise the heap will be in the bottom 1TB
-* which always uses 256MB segments and this may result in a
-* performance penalty.
-*/
-   if (!radix_enabled() && !is_32bit_task() && (mmu_highuser_ssize == 
MMU_SEGSIZE_1T))
-   base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
-#endif
-
-   ret = PAGE_ALIGN(base + brk_rnd());
-
-   if (ret < mm->brk)
-   return mm->brk;
-
-   return ret;
-}
-
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index 7ecadf5e6bf9..68a5468b0f19 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -37,6 +37,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -2171,3 +2173,20 @@ void __init print_system_hash_info(void)
if (htab_hash_mask)
pr_info("htab_hash_mask= 0x%lx\n", htab_hash_mask);
 }
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+   /*
+* If we are using 1TB segments and we are allowed to randomise
+* the heap, we can put it above 1TB so it is backed by a 1TB
+* segment. Otherwise the heap will be in the bottom 1TB
+* which always uses 256MB segments and this may result in a
+* performance penalty.
+*/
+   if (is_32bit_task())
+   return randomize_page(mm->brk, SZ_32M);
+   else if (!radix_enabled() && mmu_highuser_ssize == MMU_SEGSIZE_1T)
+   return randomize_page(max_t(unsigned long, mm->brk, SZ_1T), 
SZ_1G);
+   else
+   return randomize_page(mm->brk, SZ_1G);
+}
diff --git a/include/linux/sizes.h b/include/linux/sizes.h
index 1ac79bcee2bb..84aa448d8bb3 100644
--- a/include/linux/sizes.h
+++ b/include/linux/sizes.h
@@ -47,6 +47,8 @@
 #define SZ_8G  _AC(0x2, ULL)
 #define SZ_16G _AC(0x4, ULL)
 #define SZ_32G _AC(0x8, ULL)
+
+#define SZ_1T  _AC(0x100, ULL)
 #define SZ_64T _AC(0x4000, ULL)
 
 #endif /* __LINUX_SIZES_H__ */
-- 
2.33.1



[PATCH v2 rebased 0/9] Convert powerpc to default topdown mmap layout

2021-11-25 Thread Christophe Leroy
Same as v2 but rebased on top of Nic's v4 series "powerpc: Make hash MMU code 
build configurable"

This series converts powerpc to default topdown mmap layout.

powerpc provides its own arch_get_unmapped_area() only when
slices are needed, which is only for book3s/64. First part of
the series moves slices into book3s/64 specific directories
and cleans up other subarchitectures.

Then a small modification is done to core mm to allow
powerpc to still provide its own arch_randomize_brk()

Last part converts to default topdown mmap layout.

Changes in v2:
- Moved patch 4 before patch 2
- Make generic arch_randomize_brk() __weak
- Added patch 9

Christophe Leroy (9):
  powerpc/mm: Make slice specific to book3s/64
  powerpc/mm: Move vma_mmu_pagesize() and hugetlb_get_unmapped_area() to
slice.c
  powerpc/mm: Remove CONFIG_PPC_MM_SLICES
  powerpc/mm: Remove asm/slice.h
  powerpc/mm: Call radix__arch_get_unmapped_area() from
arch_get_unmapped_area()
  mm: Allow arch specific arch_randomize_brk() with
CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
  powerpc/mm: Convert to default topdown mmap layout
  powerpc/mm: Properly randomise mmap with slices
  powerpc: Simplify and move arch_randomize_brk()

 arch/powerpc/Kconfig  |   2 +-
 arch/powerpc/include/asm/book3s/64/hash.h |   7 +-
 arch/powerpc/include/asm/book3s/64/hugetlb.h  |   4 -
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |   1 +
 arch/powerpc/include/asm/book3s/64/slice.h|  18 ++
 arch/powerpc/include/asm/hugetlb.h|   2 +-
 arch/powerpc/include/asm/paca.h   |   7 -
 arch/powerpc/include/asm/page.h   |   1 -
 arch/powerpc/include/asm/processor.h  |   2 -
 arch/powerpc/include/asm/slice.h  |  46 
 arch/powerpc/kernel/paca.c|   5 -
 arch/powerpc/kernel/process.c |  41 
 arch/powerpc/mm/Makefile  |   3 +-
 arch/powerpc/mm/book3s64/Makefile |   2 +-
 arch/powerpc/mm/book3s64/hash_utils.c |  33 +--
 arch/powerpc/mm/book3s64/radix_hugetlbpage.c  |  55 -
 arch/powerpc/mm/{ => book3s64}/slice.c| 200 ++-
 arch/powerpc/mm/hugetlbpage.c |  28 ---
 arch/powerpc/mm/mmap.c| 228 --
 arch/powerpc/mm/nohash/mmu_context.c  |   9 -
 arch/powerpc/mm/nohash/tlb.c  |   4 -
 arch/powerpc/platforms/Kconfig.cputype|   4 -
 include/linux/sizes.h |   2 +
 mm/util.c |   2 +-
 24 files changed, 237 insertions(+), 469 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/slice.h
 rename arch/powerpc/mm/{ => book3s64}/slice.c (80%)
 delete mode 100644 arch/powerpc/mm/mmap.c

-- 
2.33.1



[PATCH v2 rebased 1/9] powerpc/mm: Make slice specific to book3s/64

2021-11-25 Thread Christophe Leroy
Since commit 555904d07eef ("powerpc/8xx: MM_SLICE is not needed
anymore") only book3s/64 selects CONFIG_PPC_MM_SLICES.

Move slice.c into mm/book3s64/

Signed-off-by: Christophe Leroy 
---
v2: Remove now unnecessary #ifdef CONFIG_PPC_BOOK3S_64 in slice.c
---
 arch/powerpc/mm/Makefile   | 1 -
 arch/powerpc/mm/book3s64/Makefile  | 1 +
 arch/powerpc/mm/{ => book3s64}/slice.c | 2 --
 arch/powerpc/mm/nohash/mmu_context.c   | 9 -
 arch/powerpc/mm/nohash/tlb.c   | 4 
 5 files changed, 1 insertion(+), 16 deletions(-)
 rename arch/powerpc/mm/{ => book3s64}/slice.c (99%)

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index df8172da2301..d4c20484dad9 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -14,7 +14,6 @@ obj-$(CONFIG_PPC_MMU_NOHASH)  += nohash/
 obj-$(CONFIG_PPC_BOOK3S_32)+= book3s32/
 obj-$(CONFIG_PPC_BOOK3S_64)+= book3s64/
 obj-$(CONFIG_NUMA) += numa.o
-obj-$(CONFIG_PPC_MM_SLICES)+= slice.o
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
diff --git a/arch/powerpc/mm/book3s64/Makefile 
b/arch/powerpc/mm/book3s64/Makefile
index 2d50cac499c5..af2f3e75d458 100644
--- a/arch/powerpc/mm/book3s64/Makefile
+++ b/arch/powerpc/mm/book3s64/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_PPC_RADIX_MMU)   += radix_hugetlbpage.o
 endif
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += iommu_api.o
 obj-$(CONFIG_PPC_PKEY) += pkeys.o
+obj-$(CONFIG_PPC_MM_SLICES)+= slice.o
 
 # Instrumenting the SLB fault path can lead to duplicate SLB entries
 KCOV_INSTRUMENT_slb.o := n
diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/book3s64/slice.c
similarity index 99%
rename from arch/powerpc/mm/slice.c
rename to arch/powerpc/mm/book3s64/slice.c
index 82b45b1cb973..c83be371c6e7 100644
--- a/arch/powerpc/mm/slice.c
+++ b/arch/powerpc/mm/book3s64/slice.c
@@ -712,7 +712,6 @@ void slice_init_new_context_exec(struct mm_struct *mm)
bitmap_fill(mask->high_slices, SLICE_NUM_HIGH);
 }
 
-#ifdef CONFIG_PPC_BOOK3S_64
 void slice_setup_new_exec(void)
 {
struct mm_struct *mm = current->mm;
@@ -724,7 +723,6 @@ void slice_setup_new_exec(void)
 
mm_ctx_set_slb_addr_limit(>context, DEFAULT_MAP_WINDOW);
 }
-#endif
 
 void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
   unsigned long len, unsigned int psize)
diff --git a/arch/powerpc/mm/nohash/mmu_context.c 
b/arch/powerpc/mm/nohash/mmu_context.c
index 44b2b5e7cabe..dc3528e815b9 100644
--- a/arch/powerpc/mm/nohash/mmu_context.c
+++ b/arch/powerpc/mm/nohash/mmu_context.c
@@ -313,15 +313,6 @@ void switch_mmu_context(struct mm_struct *prev, struct 
mm_struct *next,
  */
 int init_new_context(struct task_struct *t, struct mm_struct *mm)
 {
-   /*
-* We have MMU_NO_CONTEXT set to be ~0. Hence check
-* explicitly against context.id == 0. This ensures that we properly
-* initialize context slice details for newly allocated mm's (which will
-* have id == 0) and don't alter context slice inherited via fork (which
-* will have id != 0).
-*/
-   if (mm->context.id == 0)
-   slice_init_new_context_exec(mm);
mm->context.id = MMU_NO_CONTEXT;
mm->context.active = 0;
pte_frag_set(>context, NULL);
diff --git a/arch/powerpc/mm/nohash/tlb.c b/arch/powerpc/mm/nohash/tlb.c
index 311281063d48..3359cf7c2a61 100644
--- a/arch/powerpc/mm/nohash/tlb.c
+++ b/arch/powerpc/mm/nohash/tlb.c
@@ -773,9 +773,5 @@ void __init early_init_mmu(void)
 #ifdef CONFIG_PPC_47x
early_init_mmu_47x();
 #endif
-
-#ifdef CONFIG_PPC_MM_SLICES
-   mm_ctx_set_slb_addr_limit(_mm.context, SLB_ADDR_LIMIT_DEFAULT);
-#endif
 }
 #endif /* CONFIG_PPC64 */
-- 
2.33.1



[PATCH v2 rebased 6/9] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT

2021-11-25 Thread Christophe Leroy
Commit e7142bf5d231 ("arm64, mm: make randomization selected by
generic topdown mmap layout") introduced a default version of
arch_randomize_brk() provided when
CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT is selected.

powerpc could select CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
but needs to provide its own arch_randomize_brk().

In order to allow that, define generic version of arch_randomize_brk()
as a __weak symbol.

Cc: Alexandre Ghiti 
Signed-off-by: Christophe Leroy 
---
v2: Make the generic version of it a __weak symbol instead of a messy play with 
CONFIG_ items.
---
 mm/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index e58151a61255..7eb69f697b38 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -344,7 +344,7 @@ unsigned long randomize_stack_top(unsigned long stack_top)
 }
 
 #ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
-unsigned long arch_randomize_brk(struct mm_struct *mm)
+unsigned long __weak arch_randomize_brk(struct mm_struct *mm)
 {
/* Is the current task 32bit ? */
if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task())
-- 
2.33.1



[PATCH v2 rebased 2/9] powerpc/mm: Move vma_mmu_pagesize() and hugetlb_get_unmapped_area() to slice.c

2021-11-25 Thread Christophe Leroy
vma_mmu_pagesize() is only required for slices,
otherwise there is a generic weak version.

hugetlb_get_unmapped_area() is dedicated to slices.
radix__hugetlb_get_unmapped_area() as well.

Move them to slice.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/64/hugetlb.h |  4 --
 arch/powerpc/mm/book3s64/radix_hugetlbpage.c | 55 --
 arch/powerpc/mm/book3s64/slice.c | 76 
 arch/powerpc/mm/hugetlbpage.c| 28 
 4 files changed, 76 insertions(+), 87 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h 
b/arch/powerpc/include/asm/book3s/64/hugetlb.h
index 12e150e615b7..b37a28f62cf6 100644
--- a/arch/powerpc/include/asm/book3s/64/hugetlb.h
+++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h
@@ -8,10 +8,6 @@
  */
 void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long 
vmaddr);
 void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long 
vmaddr);
-extern unsigned long
-radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
-   unsigned long len, unsigned long pgoff,
-   unsigned long flags);
 
 extern void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep,
diff --git a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c 
b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c
index 23d3e08911d3..d2fb776febb4 100644
--- a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c
+++ b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c
@@ -41,61 +41,6 @@ void radix__flush_hugetlb_tlb_range(struct vm_area_struct 
*vma, unsigned long st
radix__flush_tlb_range_psize(vma->vm_mm, start, end, psize);
 }
 
-/*
- * A vairant of hugetlb_get_unmapped_area doing topdown search
- * FIXME!! should we do as x86 does or non hugetlb area does ?
- * ie, use topdown or not based on mmap_is_legacy check ?
- */
-unsigned long
-radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
-   unsigned long len, unsigned long pgoff,
-   unsigned long flags)
-{
-   struct mm_struct *mm = current->mm;
-   struct vm_area_struct *vma;
-   struct hstate *h = hstate_file(file);
-   int fixed = (flags & MAP_FIXED);
-   unsigned long high_limit;
-   struct vm_unmapped_area_info info;
-
-   high_limit = DEFAULT_MAP_WINDOW;
-   if (addr >= high_limit || (fixed && (addr + len > high_limit)))
-   high_limit = TASK_SIZE;
-
-   if (len & ~huge_page_mask(h))
-   return -EINVAL;
-   if (len > high_limit)
-   return -ENOMEM;
-
-   if (fixed) {
-   if (addr > high_limit - len)
-   return -ENOMEM;
-   if (prepare_hugepage_range(file, addr, len))
-   return -EINVAL;
-   return addr;
-   }
-
-   if (addr) {
-   addr = ALIGN(addr, huge_page_size(h));
-   vma = find_vma(mm, addr);
-   if (high_limit - len >= addr && addr >= mmap_min_addr &&
-   (!vma || addr + len <= vm_start_gap(vma)))
-   return addr;
-   }
-   /*
-* We are always doing an topdown search here. Slice code
-* does that too.
-*/
-   info.flags = VM_UNMAPPED_AREA_TOPDOWN;
-   info.length = len;
-   info.low_limit = max(PAGE_SIZE, mmap_min_addr);
-   info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW);
-   info.align_mask = PAGE_MASK & ~huge_page_mask(h);
-   info.align_offset = 0;
-
-   return vm_unmapped_area();
-}
-
 void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
 unsigned long addr, pte_t *ptep,
 pte_t old_pte, pte_t pte)
diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c
index c83be371c6e7..4c3e9601fdf6 100644
--- a/arch/powerpc/mm/book3s64/slice.c
+++ b/arch/powerpc/mm/book3s64/slice.c
@@ -777,4 +777,80 @@ int slice_is_hugepage_only_range(struct mm_struct *mm, 
unsigned long addr,
 
return !slice_check_range_fits(mm, maskp, addr, len);
 }
+
+unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
+{
+   /* With radix we don't use slice, so derive it from vma*/
+   if (radix_enabled())
+   return vma_kernel_pagesize(vma);
+
+   return 1UL << mmu_psize_to_shift(get_slice_psize(vma->vm_mm, 
vma->vm_start));
+}
+
+/*
+ * A variant of hugetlb_get_unmapped_area() doing topdown search
+ * FIXME!! should we do as x86 does or non hugetlb area does ?
+ * ie, use topdown or not based on mmap_is_legacy check ?
+ */
+static unsigned long
+radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, 
unsigned long len,
+unsigned long 

Re: [PATCH v4 00/17] powerpc: Make hash MMU code build configurable

2021-11-25 Thread Christophe Leroy




Le 25/11/2021 à 17:35, Christophe Leroy a écrit :



Le 25/11/2021 à 13:50, Nicholas Piggin a écrit :

Now that there's a platform that can make good use of it, here's
a series that can prevent the hash MMU code being built for 64s
platforms that don't need it.


# CONFIG_PPC_64S_HASH_MMU is not set


:1559:2: warning: #warning syscall futex_waitv not implemented 
[-Wcpp]

arch/powerpc/platforms/cell/spu_base.c: In function '__spu_kernel_slb':
arch/powerpc/platforms/cell/spu_base.c:215:38: error: 'mmu_linear_psize' 
undeclared (first use in this function); did you mean 'mmu_virtual_psize'?

   215 | llp = mmu_psize_defs[mmu_linear_psize].sllp;
   |  ^~~~
   |  mmu_virtual_psize
arch/powerpc/platforms/cell/spu_base.c:215:38: note: each undeclared 
identifier is reported only once for each function it appears in
make[3]: *** [scripts/Makefile.build:287: 
arch/powerpc/platforms/cell/spu_base.o] Error 1
make[2]: *** [scripts/Makefile.build:549: arch/powerpc/platforms/cell] 
Error 2

make[1]: *** [scripts/Makefile.build:549: arch/powerpc/platforms] Error 2
make: *** [Makefile:1846: arch/powerpc] Error 2





With CONFIG_SPU_BASE removed, the above voids and I get to the final 
link with the following errors:


powerpc64-linux-gnu-ld: warning: discarding dynamic section .glink
powerpc64-linux-gnu-ld: warning: discarding dynamic section .plt
powerpc64-linux-gnu-ld: linkage table error against `update_mmu_cache'
powerpc64-linux-gnu-ld: stubs don't match calculated size
powerpc64-linux-gnu-ld: can not build stubs: bad value
powerpc64-linux-gnu-ld: 
arch/powerpc/platforms/pasemi/setup.o:(.toc+0x0): undefined reference to 
`mmu_slb_size'
powerpc64-linux-gnu-ld: arch/powerpc/platforms/cell/iommu.o:(.toc+0x0): 
undefined reference to `htab_address'
powerpc64-linux-gnu-ld: arch/powerpc/platforms/cell/iommu.o:(.toc+0x8): 
undefined reference to `htab_size_bytes'
powerpc64-linux-gnu-ld: arch/powerpc/platforms/ps3/htab.o:(.toc+0x0): 
undefined reference to `mmu_hash_ops'

powerpc64-linux-gnu-ld: mm/filemap.o: in function `.filemap_map_pages':
(.text+0x6f08): undefined reference to `.update_mmu_cache'
powerpc64-linux-gnu-ld: mm/gup.o: in function `.follow_page_pte':
gup.c:(.text+0x1b38): undefined reference to `.update_mmu_cache'
powerpc64-linux-gnu-ld: mm/memory.o: in function `.wp_page_copy':
memory.c:(.text+0xd84): undefined reference to `.update_mmu_cache'
powerpc64-linux-gnu-ld: memory.c:(.text+0x1528): undefined reference to 
`.update_mmu_cache'

powerpc64-linux-gnu-ld: mm/memory.o: in function `.finish_mkwrite_fault':
(.text+0x3d6c): undefined reference to `.update_mmu_cache'
powerpc64-linux-gnu-ld: mm/memory.o:memory.c:(.text+0x4254): more 
undefined references to `.update_mmu_cache' follow

make: *** [Makefile:1161: vmlinux] Error 1


Re: [PATCH] powerpc/watchdog: Fix wd_smp_last_reset_tb reporting

2021-11-25 Thread Laurent Dufour
On 25/11/2021, 11:33:46, Nicholas Piggin wrote:
> wd_smp_last_reset_tb now gets reset by watchdog_smp_panic() as part of
> marking CPUs stuck and removing them from the pending mask before it
> begins any printing. This causes last reset times reported to be off.
> 
> Fix this by reading it into a local variable before it gets reset.
> 
> Fixes: 76521c4b0291 ("powerpc/watchdog: Avoid holding wd_smp_lock over printk 
> and smp_send_nmi_ipi")
> Signed-off-by: Nicholas Piggin 
> ---
> 
> This is the delta for patches 1-4 between v3 and v4 of the series which
> is the result of fixing the bug in patch 3. Sending because v3 got
> merged into powerpc next

What about the 5th patch in the v4 series titled "[PATCH v4 5/5]
powerpc/watchdog: help remote CPUs to flush NMI printk output"?


> Thanks,
> Nick
> 
>  arch/powerpc/kernel/watchdog.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
> index b6533539386b..23745af38d62 100644
> --- a/arch/powerpc/kernel/watchdog.c
> +++ b/arch/powerpc/kernel/watchdog.c
> @@ -179,13 +179,14 @@ static void watchdog_smp_panic(int cpu)
>  {
>   static cpumask_t wd_smp_cpus_ipi; // protected by reporting
>   unsigned long flags;
> - u64 tb;
> + u64 tb, last_reset;
>   int c;
>  
>   wd_smp_lock();
>   /* Double check some things under lock */
>   tb = get_tb();
> - if ((s64)(tb - wd_smp_last_reset_tb) < (s64)wd_smp_panic_timeout_tb)
> + last_reset = wd_smp_last_reset_tb;
> + if ((s64)(tb - last_reset) < (s64)wd_smp_panic_timeout_tb)
>   goto out;
>   if (cpumask_test_cpu(cpu, _smp_cpus_pending))
>   goto out;
> @@ -210,8 +211,7 @@ static void watchdog_smp_panic(int cpu)
>   pr_emerg("CPU %d detected hard LOCKUP on other CPUs %*pbl\n",
>cpu, cpumask_pr_args(_smp_cpus_ipi));
>   pr_emerg("CPU %d TB:%lld, last SMP heartbeat TB:%lld (%lldms ago)\n",
> -  cpu, tb, wd_smp_last_reset_tb,
> -  tb_to_ns(tb - wd_smp_last_reset_tb) / 100);
> +  cpu, tb, last_reset, tb_to_ns(tb - last_reset) / 100);
>  
>   if (!sysctl_hardlockup_all_cpu_backtrace) {
>   /*
> 



Re: [PATCH v3 0/4] powerpc: watchdog fixes

2021-11-25 Thread Laurent Dufour
On 25/11/2021, 16:26:33, Michal Suchánek wrote:
> Hello,
> 
> On Thu, Nov 25, 2021 at 04:11:03PM +0100, Laurent Dufour wrote:
>> On 25/11/2021, 10:36:43, Michael Ellerman wrote:
>>> On Wed, 10 Nov 2021 12:50:52 +1000, Nicholas Piggin wrote:
 These are some watchdog fixes and improvements, in particular a
 deadlock between the wd_smp_lock and console lock when the watchdog
 fires, found by Laurent.

 Thanks,
 Nick

 [...]
>>>
>>> Applied to powerpc/next.
>>>
>>> [1/4] powerpc/watchdog: Fix missed watchdog reset due to memory ordering 
>>> race
>>>   
>>> https://git.kernel.org/powerpc/c/5dad4ba68a2483fc80d70b9dc90bbe16e1f27263
>>> [2/4] powerpc/watchdog: tighten non-atomic read-modify-write access
>>>   
>>> https://git.kernel.org/powerpc/c/858c93c31504ac1507084493d7eafbe7e2302dc2
>>> [3/4] powerpc/watchdog: Avoid holding wd_smp_lock over printk and 
>>> smp_send_nmi_ipi
>>>   
>>> https://git.kernel.org/powerpc/c/76521c4b0291ad25723638ade5a0ff4d5f659771
>>> [4/4] powerpc/watchdog: read TB close to where it is used
>>>   
>>> https://git.kernel.org/powerpc/c/1f01bf90765fa5f88fbae452c131c1edf5cda7ba
>>>
>>> cheers
>>>
>>
>> Hi Michael,
>>
>> This series has been superseded by this series (v4)
>> http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=272865
>>
>> Do you plan to apply that v4?
> 
> It has been fixed up in
> 
> https://lore.kernel.org/linuxppc-dev/20211125103346.1188958-1-npig...@gmail.com/

Thanks Michal, I forgot that one.





Re: [PATCH v4 00/17] powerpc: Make hash MMU code build configurable

2021-11-25 Thread Christophe Leroy




Le 25/11/2021 à 13:50, Nicholas Piggin a écrit :

Now that there's a platform that can make good use of it, here's
a series that can prevent the hash MMU code being built for 64s
platforms that don't need it.


# CONFIG_PPC_64S_HASH_MMU is not set


:1559:2: warning: #warning syscall futex_waitv not implemented 
[-Wcpp]

arch/powerpc/platforms/cell/spu_base.c: In function '__spu_kernel_slb':
arch/powerpc/platforms/cell/spu_base.c:215:38: error: 'mmu_linear_psize' 
undeclared (first use in this function); did you mean 'mmu_virtual_psize'?

  215 | llp = mmu_psize_defs[mmu_linear_psize].sllp;
  |  ^~~~
  |  mmu_virtual_psize
arch/powerpc/platforms/cell/spu_base.c:215:38: note: each undeclared 
identifier is reported only once for each function it appears in
make[3]: *** [scripts/Makefile.build:287: 
arch/powerpc/platforms/cell/spu_base.o] Error 1
make[2]: *** [scripts/Makefile.build:549: arch/powerpc/platforms/cell] 
Error 2

make[1]: *** [scripts/Makefile.build:549: arch/powerpc/platforms] Error 2
make: *** [Makefile:1846: arch/powerpc] Error 2







Since v3:
- Merged microwatt patches into 1.
- Fix some changelogs, titles, comments.
- Keep MMU_FTR_HPTE_TABLE in the features when booting radix if hash
   support is is configured because it will be needed for KVM radix host
   hash guest (when we extend this option to KVM).
- Accounted for hopefully all review comments (thanks Christophe)

Since v2:
- Split MMU_FTR_HPTE_TABLE clearing for radix boot into its own patch.
- Remove memremap_compat_align from other sub archs entirely.
- Flip patch order of the 2 main patches to put Kconfig change first.
- Fixed Book3S/32 xmon segment dumping bug.
- Removed a few more ifdefs, changed numbers to use SZ_ definitions,
   etc.
- Fixed microwatt defconfig so it should actually disable hash MMU now.

Since v1:
- Split out most of the Kconfig change from the conditional compilation
   changes.
- Split out several more changes into preparatory patches.
- Reduced some ifdefs.
- Caught a few missing hash bits: pgtable dump, lkdtm,
   memremap_compat_align.

Since RFC:
- Split out large code movement from other changes.
- Used mmu ftr test constant folding rather than adding new constant
   true/false for radix_enabled().
- Restore tlbie trace point that had to be commented out in the
   previous.
- Avoid minor (probably unreachable) behaviour change in machine check
   handler when hash was not compiled.
- Fix microwatt updates so !HASH is not enforced.
- Rebase, build fixes.

Thanks,
Nick

Nicholas Piggin (17):
   powerpc: Remove unused FW_FEATURE_NATIVE references
   powerpc: Rename PPC_NATIVE to PPC_HASH_MMU_NATIVE
   powerpc/pseries: Stop selecting PPC_HASH_MMU_NATIVE
   powerpc/64s: Move and rename do_bad_slb_fault as it is not hash
 specific
   powerpc/pseries: move process table registration away from
 hash-specific code
   powerpc/pseries: lparcfg don't include slb_size line in radix mode
   powerpc/64s: move THP trace point creation out of hash specific file
   powerpc/64s: Make flush_and_reload_slb a no-op when radix is enabled
   powerpc/64s: move page size definitions from hash specific file
   powerpc/64s: Rename hash_hugetlbpage.c to hugetlbpage.c
   powerpc/64: pcpu setup avoid reading mmu_linear_psize on 64e or radix
   powerpc: make memremap_compat_align 64s-only
   powerpc/64e: remove mmu_linear_psize
   powerpc/64s: Fix radix MMU when MMU_FTR_HPTE_TABLE is clear
   powerpc/64s: Make hash MMU support configurable
   powerpc/64s: Move hash MMU support code under CONFIG_PPC_64S_HASH_MMU
   powerpc/microwatt: add POWER9_CPU, clear PPC_64S_HASH_MMU

  arch/powerpc/Kconfig  |   5 +-
  arch/powerpc/configs/microwatt_defconfig  |   3 +-
  arch/powerpc/include/asm/book3s/64/mmu.h  |  21 +++-
  .../include/asm/book3s/64/tlbflush-hash.h |   6 +
  arch/powerpc/include/asm/book3s/64/tlbflush.h |   4 -
  arch/powerpc/include/asm/book3s/pgtable.h |   4 +
  arch/powerpc/include/asm/firmware.h   |   8 --
  arch/powerpc/include/asm/interrupt.h  |   2 +-
  arch/powerpc/include/asm/mmu.h|  16 ++-
  arch/powerpc/include/asm/mmu_context.h|   2 +
  arch/powerpc/include/asm/nohash/mmu-book3e.h  |   1 -
  arch/powerpc/include/asm/paca.h   |   8 ++
  arch/powerpc/kernel/asm-offsets.c |   2 +
  arch/powerpc/kernel/dt_cpu_ftrs.c |  14 ++-
  arch/powerpc/kernel/entry_64.S|   4 +-
  arch/powerpc/kernel/exceptions-64s.S  |  20 +++-
  arch/powerpc/kernel/mce.c |   2 +-
  arch/powerpc/kernel/mce_power.c   |  16 ++-
  arch/powerpc/kernel/paca.c|  18 ++-
  arch/powerpc/kernel/process.c |  13 +-
  arch/powerpc/kernel/prom.c|   2 +
  arch/powerpc/kernel/setup_64.c|  26 +++-
  

[PATCH] powerpc: mm: radix_tlb: rearrange the if-else block

2021-11-25 Thread Anders Roxell
Clang warns:

arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
'hstart' to silence this warning
unsigned long hstart, hend;
^
 = 0
arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~~~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
'hend' to silence this warning
unsigned long hstart, hend;
  ^
   = 0
2 errors generated.

Rework the if-else to pull the 'IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE)'
check one level up, this will silent the warnings. That will also
simplify the 'else' path. Clang is getting confused with these warnings,
but the warnings is a false-positive.

Suggested-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/mm/book3s64/radix_tlb.c | 31 +---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
b/arch/powerpc/mm/book3s64/radix_tlb.c
index 7724af19ed7e..e494a45ce1b4 100644
--- a/arch/powerpc/mm/book3s64/radix_tlb.c
+++ b/arch/powerpc/mm/book3s64/radix_tlb.c
@@ -1170,16 +1170,14 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
_tlbiel_pid_multicast(mm, pid, RIC_FLUSH_ALL);
}
}
-   } else {
+   } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
bool hflush = false;
unsigned long hstart, hend;
 
-   if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
-   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
-   hend = end & PMD_MASK;
-   if (hstart < hend)
-   hflush = true;
-   }
+   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
+   hend = end & PMD_MASK;
+   if (hstart < hend)
+   hflush = true;
 
if (type == FLUSH_TYPE_LOCAL) {
asm volatile("ptesync": : :"memory");
@@ -1207,6 +1205,25 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
_tlbiel_va_range_multicast(mm,
hstart, hend, pid, PMD_SIZE, 
MMU_PAGE_2M, flush_pwc);
}
+   } else {
+
+   if (type == FLUSH_TYPE_LOCAL) {
+   asm volatile("ptesync" : : : "memory");
+   if (flush_pwc)
+   /* For PWC, only one flush is needed */
+   __tlbiel_pid(pid, 0, RIC_FLUSH_PWC);
+   __tlbiel_va_range(start, end, pid, page_size, 
mmu_virtual_psize);
+   ppc_after_tlbiel_barrier();
+   } else if (cputlb_use_tlbie()) {
+   asm volatile("ptesync" : : : "memory");
+   if (flush_pwc)
+   __tlbie_pid(pid, RIC_FLUSH_PWC);
+   __tlbie_va_range(start, end, pid, page_size, 
mmu_virtual_psize);
+   asm volatile("eieio; tlbsync; ptesync" : : : "memory");
+   } else {
+   _tlbiel_va_range_multicast(mm,
+   start, end, pid, page_size, 
mmu_virtual_psize, flush_pwc);
+   }
}
 out:
preempt_enable();
-- 
2.33.0



Re: [PATCH v3 0/4] powerpc: watchdog fixes

2021-11-25 Thread Michal Suchánek
Hello,

On Thu, Nov 25, 2021 at 04:11:03PM +0100, Laurent Dufour wrote:
> On 25/11/2021, 10:36:43, Michael Ellerman wrote:
> > On Wed, 10 Nov 2021 12:50:52 +1000, Nicholas Piggin wrote:
> >> These are some watchdog fixes and improvements, in particular a
> >> deadlock between the wd_smp_lock and console lock when the watchdog
> >> fires, found by Laurent.
> >>
> >> Thanks,
> >> Nick
> >>
> >> [...]
> > 
> > Applied to powerpc/next.
> > 
> > [1/4] powerpc/watchdog: Fix missed watchdog reset due to memory ordering 
> > race
> >   
> > https://git.kernel.org/powerpc/c/5dad4ba68a2483fc80d70b9dc90bbe16e1f27263
> > [2/4] powerpc/watchdog: tighten non-atomic read-modify-write access
> >   
> > https://git.kernel.org/powerpc/c/858c93c31504ac1507084493d7eafbe7e2302dc2
> > [3/4] powerpc/watchdog: Avoid holding wd_smp_lock over printk and 
> > smp_send_nmi_ipi
> >   
> > https://git.kernel.org/powerpc/c/76521c4b0291ad25723638ade5a0ff4d5f659771
> > [4/4] powerpc/watchdog: read TB close to where it is used
> >   
> > https://git.kernel.org/powerpc/c/1f01bf90765fa5f88fbae452c131c1edf5cda7ba
> > 
> > cheers
> > 
> 
> Hi Michael,
> 
> This series has been superseded by this series (v4)
> http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=272865
> 
> Do you plan to apply that v4?

It has been fixed up in

https://lore.kernel.org/linuxppc-dev/20211125103346.1188958-1-npig...@gmail.com/

Thanks

Michal


Re: [5.16.0-rc2] Kernel warning while running sigfuz w/PPC_IRQ_SOFT_MASK_DEBUG

2021-11-25 Thread Sachin Sant


>> [ 1032.913679] GPR00: c000c6d8 cc7e7e10 2fcdac67 
>> 0800 
>> [ 1032.913679] GPR04: 60d67006 8280f032 45faa436 
>> c001eb3d4c00 
>> [ 1032.913679] GPR08: 8280f032 0001 0001 
>> 60d67004 
>> [ 1032.913679] GPR12: 60d67006 c0077fdf2300  
>> 7fff9da0 
> 
> SRR0 == r11, regs->nip == r12
> 
> I wonder if this is just that SRR0 does not implement the bottom 2 bits 
> so the check fails when the signal context sets them. Hopefully the 
> panic is just due to this warning 0x700 program check hitting at a bad
> time.
> 
> We could always adjust the debug check but maybe something like this 
> would keep those bits clear which might be cleaner.
> 

Thanks for the patch Nick.
The test runs to completion without any kernel warning/crash.

Thanks
-Sachin

Re: [PATCH v3 0/4] powerpc: watchdog fixes

2021-11-25 Thread Laurent Dufour
On 25/11/2021, 10:36:43, Michael Ellerman wrote:
> On Wed, 10 Nov 2021 12:50:52 +1000, Nicholas Piggin wrote:
>> These are some watchdog fixes and improvements, in particular a
>> deadlock between the wd_smp_lock and console lock when the watchdog
>> fires, found by Laurent.
>>
>> Thanks,
>> Nick
>>
>> [...]
> 
> Applied to powerpc/next.
> 
> [1/4] powerpc/watchdog: Fix missed watchdog reset due to memory ordering race
>   
> https://git.kernel.org/powerpc/c/5dad4ba68a2483fc80d70b9dc90bbe16e1f27263
> [2/4] powerpc/watchdog: tighten non-atomic read-modify-write access
>   
> https://git.kernel.org/powerpc/c/858c93c31504ac1507084493d7eafbe7e2302dc2
> [3/4] powerpc/watchdog: Avoid holding wd_smp_lock over printk and 
> smp_send_nmi_ipi
>   
> https://git.kernel.org/powerpc/c/76521c4b0291ad25723638ade5a0ff4d5f659771
> [4/4] powerpc/watchdog: read TB close to where it is used
>   
> https://git.kernel.org/powerpc/c/1f01bf90765fa5f88fbae452c131c1edf5cda7ba
> 
> cheers
> 

Hi Michael,

This series has been superseded by this series (v4)
http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=272865

Do you plan to apply that v4?

Thanks,
Laurent.


Re: [PATCH v2 2/2] powerpc:85xx: fix timebase sync issue when CONFIG_HOTPLUG_CPU=n

2021-11-25 Thread Martin Kennedy
Hi there,

Yes, I can test this patch.

I have added it to my tree and removed the reversion, and can confirm
that the second CPU comes up correctly now.

Martin

On Thu, Nov 25, 2021 at 2:23 AM Xiaoming Ni  wrote:
>
> On 2021/11/25 12:20, Martin Kennedy wrote:
> > Hi there,
> >
> > I have bisected OpenWrt master, and then the Linux kernel down to this
> > change, to confirm that this change causes a kernel panic on my
> > P1020RDB-based, dual-core Aerohive HiveAP 370, at initialization of
> > the second CPU:
> >
> > :
> > [0.00] Linux version 5.10.80 (labby@lobon)
> > (powerpc-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0
> > r18111+1-ebb6f9287e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Thu
> > Nov 25 02:49:35 2021
> > [0.00] Using P1020 RDB machine description
> > :
> > [0.627233] smp: Bringing up secondary CPUs ...
> > [0.681659] kernel tried to execute user page (0) - exploit attempt? 
> > (uid: 0)
> > [0.766618] BUG: Unable to handle kernel instruction fetch (NULL 
> > pointer?)
> > [0.848899] Faulting instruction address: 0x
> > [0.908273] Oops: Kernel access of bad area, sig: 11 [#1]
> > [0.972851] BE PAGE_SIZE=4K SMP NR_CPUS=2 P1020 RDB
> > [1.031179] Modules linked in:
> > [1.067640] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.80 #0
> > [1.139507] NIP:   LR: c0021d2c CTR: 
> > [1.199921] REGS: c1051cf0 TRAP: 0400   Not tainted  (5.10.80)
> > [1.269705] MSR:  00021000   CR: 84020202  XER: 
> > [1.340534]
> > [1.340534] GPR00: c0021cb8 c1051da8 c1048000 0001 00029000
> >  0001 
> > [1.340534] GPR08: 0001  c08b 0040 22000208
> >  c00032c4 
> > [1.340534] GPR16:     
> >  00029000 0001
> > [1.340534] GPR24: 1240 2000 d240 c080a1f4 0001
> > c08ae0a8 0001 d240
> > [1.758220] NIP [] 0x0
> > [1.794688] LR [c0021d2c] smp_85xx_kick_cpu+0xe8/0x568
> > [1.856126] Call Trace:
> > [1.885295] [c1051da8] [c0021cb8] smp_85xx_kick_cpu+0x74/0x568 
> > (unreliable)
> > [1.968633] [c1051de8] [c0011460] __cpu_up+0xc0/0x228
> > [2.029038] [c1051e18] [c0031bbc] bringup_cpu+0x30/0x224
> > [2.092572] [c1051e48] [c0031f3c] cpu_up.constprop.0+0x180/0x33c
> > [2.164443] [c1051e88] [c00322e8] bringup_nonboot_cpus+0x88/0xc8
> > [2.236326] [c1051eb8] [c07e67bc] smp_init+0x30/0x78
> > [2.295698] [c1051ed8] [c07d9e28] kernel_init_freeable+0x118/0x2a8
> > [2.369641] [c1051f18] [c00032d8] kernel_init+0x14/0x124
> > [2.433176] [c1051f38] [c0010278] ret_from_kernel_thread+0x14/0x1c
> > [2.507125] Instruction dump:
> > [2.542541]      
> >  
> > [2.635242]      
> >  
> > [2.727952] ---[ end trace 9b796a4bafb6bc14 ]---
> > [2.783149]
> > [3.800879] Kernel panic - not syncing: Fatal exception
> > [3.862353] Rebooting in 1 seconds..
> > [5.905097] System Halted, OK to turn off power
> >
> > Without this patch, the kernel no longer panics:
> >
> > [0.627232] smp: Bringing up secondary CPUs ...
> > [0.681857] smp: Brought up 1 node, 2 CPUs
> >
> > Here is the kernel configuration for this built kernel:
> > https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob_plain;f=target/linux/mpc85xx/config-5.10;hb=HEAD
> >
> > In case a force-push is needed for the source repository
> > (https://github.com/Hurricos/openwrt/commit/ad19bdfc77d60ee1c52b41bb4345fdd02284c4cf),
> > here is the device tree for this board:
> > https://paste.c-net.org/TrousersSliced
> >
> > Martin
> > .
> >
> When CONFIG_FSL_PMC is set to n, cpu_up_prepare is not assigned to
> mpc85xx_pm_ops. I suspect that this is the cause of the current null
> pointer access.
> I do not have the corresponding board test environment. Can you help me
> to test whether the following patch solves the problem?
>
> diff --git a/arch/powerpc/platforms/85xx/smp.c
> b/arch/powerpc/platforms/85xx/smp.c
> index 83f4a6389a28..d7081e9af65c 100644
> --- a/arch/powerpc/platforms/85xx/smp.c
> +++ b/arch/powerpc/platforms/85xx/smp.c
> @@ -220,7 +220,7 @@ static int smp_85xx_start_cpu(int cpu)
>  local_irq_save(flags);
>  hard_irq_disable();
>
> -   if (qoriq_pm_ops)
> + if (qoriq_pm_ops && qoriq_pm_ops->cpu_up_prepare)
>  qoriq_pm_ops->cpu_up_prepare(cpu);
>
>  /* if cpu is not spinning, reset it */
> @@ -292,7 +292,7 @@ static int smp_85xx_kick_cpu(int nr)
>  booting_thread_hwid = cpu_thread_in_core(nr);
>  primary = cpu_first_thread_sibling(nr);
>
> -   if (qoriq_pm_ops)
> + if (qoriq_pm_ops && qoriq_pm_ops->cpu_up_prepare)
>  qoriq_pm_ops->cpu_up_prepare(nr);
>
>  /*
>
>


Re: bug: usb: gadget: FSL_UDC_CORE Corrupted request list leads to unrecoverable loop.

2021-11-25 Thread Thorsten Leemhuis
Hi, this is your Linux kernel regression tracker speaking.

Top-posting for once, to make this easy to process for everyone:

Li Yang and Felipe Balbi: how to move on with this? It's quite an old
regression, but nevertheless it is one and thus should be fixed. Part of
my position is to make that happen and thus remind developers and
maintainers about this until the regression is resolved.

Ciao, Thorsten

On 16.11.21 20:11, Eugene Bordenkircher wrote:
> On 02.11.21 22:15, Joakim Tjernlund wrote:
>> On Sat, 2021-10-30 at 14:20 +, Joakim Tjernlund wrote:
>>> On Fri, 2021-10-29 at 17:14 +, Eugene Bordenkircher wrote:
>>
 We've discovered a situation where the FSL udc driver 
 (drivers/usb/gadget/udc/fsl_udc_core.c) will enter a loop iterating over 
 the request queue, but the queue has been corrupted at some point so it 
 loops infinitely.  I believe we have narrowed into the offending code, but 
 we are in need of assistance trying to find an appropriate fix for the 
 problem.  The identified code appears to be in all versions of the Linux 
 kernel the driver exists in.

 The problem appears to be when handling a USB_REQ_GET_STATUS request.  The 
 driver gets this request and then calls the ch9getstatus() function.  In 
 this function, it starts a request by "borrowing" the per device 
 status_req, filling it in, and then queuing it with a call to 
 list_add_tail() to add the request to the endpoint queue.  Right before it 
 exits the function however, it's calling ep0_prime_status(), which is 
 filling out that same status_req structure and then queuing it with 
 another call to list_add_tail() to add the request to the endpoint queue.  
 This adds two instances of the exact same LIST_HEAD to the endpoint queue, 
 which breaks the list since the prev and next pointers end up pointing to 
 the wrong things.  This ends up causing a hard loop the next time nuke() 
 gets called, which happens on the next setup IRQ.

 I'm not sure what the appropriate fix to this problem is, mostly due to my 
 lack of expertise in USB and this driver stack.  The code has been this 
 way in the kernel for a very long time, which suggests that it has been 
 working, unless USB_REQ_GET_STATUS requests are never made.  This further 
 suggests that there is something else going on that I don't understand.  
 Deleting the call to ep0_prime_status() and the following ep0stall() call 
 appears, on the surface, to get the device working again, but may have 
 side effects that I'm not seeing.

 I'm hopeful someone in the community can help provide some information on 
 what I may be missing or help come up with a solution to the problem.  A 
 big thank you to anyone who would like to help out.
>>>
>>> Run into this to a while ago. Found the bug and a few more fixes.
>>> This is against 4.19 so you may have to tweak them a bit.
>>> Feel free to upstream them.
>>
>> Curious, did my patches help? Good to known once we upgrade as well.
> 
> There's good news and bad news.
> 
> The good news is that this appears to stop the driver from entering
> an infinite loop, which prevents the Linux system from locking up and
> never recovering.  So I'm willing to say we've made the behavior
> better.
> 
> The bad news is that once we get past this point, there is new bad
> behavior.  What is on top of this driver in our system is the RNDIS
> gadget driver communicating to a Laptop running Win10 -1809.
> Everything appears to work fine with the Linux system until there is
> a USB disconnect.  After the disconnect, the Linux side appears to
> continue on just fine, but the Windows side doesn't seem to recognize
> the disconnect, which causes the USB driver on that side to hang
> forever and eventually blue screen the box.  This doesn't happen on
> all machines, just a select few.   I think we can isolate the
> behavior to a specific antivirus/security software driver that is
> inserting itself into the USB stack and filtering the disconnect
> message, but we're still proving that.
> 
> I'm about 90% certain this is a different problem and we can call
> this patchset good, at least for our test setup.  My only hesitation
> is if the Linux side is sending a set of responses that are confusing
> the Windows side (specifically this antivirus) or not.  I'd be
> content calling that a separate defect though and letting this one
> close up with that patchset.

P.S.: As a Linux kernel regression tracker I'm getting a lot of reports
on my table. I can only look briefly into most of them. Unfortunately
therefore I sometimes will get things wrong or miss something important.
I hope that's not the case here; if you think it is, don't hesitate to
tell me about it in a public reply. That's in everyone's interest, as
what I wrote above might be misleading to everyone reading this; any
suggestion I gave they thus might sent someone 

[powerpc:fixes-test] BUILD SUCCESS 5bb60ea611db1e04814426ed4bd1c95d1487678e

2021-11-25 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
fixes-test
branch HEAD: 5bb60ea611db1e04814426ed4bd1c95d1487678e  powerpc/32: Fix 
hardlockup on vmap stack overflow

elapsed time: 720m

configs tested: 54
configs skipped: 54

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
i386 randconfig-c001-20211125
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
nios2allyesconfig
nds32   defconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
i386  debian-10.3
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
riscvallmodconfig
um   x86_64_defconfig
um i386_defconfig
x86_64   allyesconfig
x86_64rhel-8.3-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-func
x86_64  kexec

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


[PATCH v4 17/17] powerpc/microwatt: add POWER9_CPU, clear PPC_64S_HASH_MMU

2021-11-25 Thread Nicholas Piggin
Microwatt implements a subset of ISA v3.0 (which is equivalent to
the POWER9_CPU option). It is radix-only, so does not require hash
MMU support.

This saves 20kB compressed dtbImage and 56kB vmlinux size.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/configs/microwatt_defconfig | 3 ++-
 arch/powerpc/platforms/microwatt/Kconfig | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/configs/microwatt_defconfig 
b/arch/powerpc/configs/microwatt_defconfig
index 07d87a4044b2..eff933ebbb9e 100644
--- a/arch/powerpc/configs/microwatt_defconfig
+++ b/arch/powerpc/configs/microwatt_defconfig
@@ -15,6 +15,8 @@ CONFIG_EMBEDDED=y
 # CONFIG_COMPAT_BRK is not set
 # CONFIG_SLAB_MERGE_DEFAULT is not set
 CONFIG_PPC64=y
+CONFIG_POWER9_CPU=y
+# CONFIG_PPC_64S_HASH_MMU is not set
 # CONFIG_PPC_KUEP is not set
 # CONFIG_PPC_KUAP is not set
 CONFIG_CPU_LITTLE_ENDIAN=y
@@ -27,7 +29,6 @@ CONFIG_PPC_MICROWATT=y
 CONFIG_CPU_FREQ=y
 CONFIG_HZ_100=y
 CONFIG_PPC_4K_PAGES=y
-# CONFIG_PPC_MEM_KEYS is not set
 # CONFIG_SECCOMP is not set
 # CONFIG_MQ_IOSCHED_KYBER is not set
 # CONFIG_COREDUMP is not set
diff --git a/arch/powerpc/platforms/microwatt/Kconfig 
b/arch/powerpc/platforms/microwatt/Kconfig
index 823192e9d38a..5e320f49583a 100644
--- a/arch/powerpc/platforms/microwatt/Kconfig
+++ b/arch/powerpc/platforms/microwatt/Kconfig
@@ -5,7 +5,6 @@ config PPC_MICROWATT
select PPC_XICS
select PPC_ICS_NATIVE
select PPC_ICP_NATIVE
-   select PPC_HASH_MMU_NATIVE if PPC_64S_HASH_MMU
select PPC_UDBG_16550
select ARCH_RANDOM
help
-- 
2.23.0



[PATCH v4 16/17] powerpc/64s: Move hash MMU support code under CONFIG_PPC_64S_HASH_MMU

2021-11-25 Thread Nicholas Piggin
Compiling out hash support code when CONFIG_PPC_64S_HASH_MMU=n saves
128kB kernel image size (90kB text) on powernv_defconfig minus KVM,
350kB on pseries_defconfig minus KVM, 40kB on a tiny config.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Kconfig  |  2 +-
 arch/powerpc/include/asm/book3s/64/mmu.h  | 21 ++--
 .../include/asm/book3s/64/tlbflush-hash.h |  6 
 arch/powerpc/include/asm/book3s/pgtable.h |  4 +++
 arch/powerpc/include/asm/mmu_context.h|  2 ++
 arch/powerpc/include/asm/paca.h   |  8 +
 arch/powerpc/kernel/asm-offsets.c |  2 ++
 arch/powerpc/kernel/entry_64.S|  4 +--
 arch/powerpc/kernel/exceptions-64s.S  | 16 ++
 arch/powerpc/kernel/mce.c |  2 +-
 arch/powerpc/kernel/mce_power.c   | 10 --
 arch/powerpc/kernel/paca.c| 18 ---
 arch/powerpc/kernel/process.c | 13 
 arch/powerpc/kernel/prom.c|  2 ++
 arch/powerpc/kernel/setup_64.c|  5 +++
 arch/powerpc/kexec/core_64.c  |  4 +--
 arch/powerpc/kexec/ranges.c   |  4 +++
 arch/powerpc/mm/book3s64/Makefile | 15 +
 arch/powerpc/mm/book3s64/hugetlbpage.c|  2 ++
 arch/powerpc/mm/book3s64/mmu_context.c| 32 +++
 arch/powerpc/mm/book3s64/pgtable.c|  2 +-
 arch/powerpc/mm/book3s64/radix_pgtable.c  |  4 +++
 arch/powerpc/mm/copro_fault.c |  2 ++
 arch/powerpc/mm/ptdump/Makefile   |  2 +-
 arch/powerpc/platforms/powernv/idle.c |  2 ++
 arch/powerpc/platforms/powernv/setup.c|  2 ++
 arch/powerpc/platforms/pseries/lpar.c | 11 +--
 arch/powerpc/platforms/pseries/lparcfg.c  |  2 +-
 arch/powerpc/platforms/pseries/mobility.c |  6 
 arch/powerpc/platforms/pseries/ras.c  |  2 ++
 arch/powerpc/platforms/pseries/reconfig.c |  2 ++
 arch/powerpc/platforms/pseries/setup.c|  6 ++--
 arch/powerpc/xmon/xmon.c  |  8 +++--
 drivers/misc/lkdtm/Makefile   |  2 +-
 drivers/misc/lkdtm/core.c |  2 +-
 35 files changed, 174 insertions(+), 53 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1fa336ec8faf..fb48823ccd62 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -129,7 +129,7 @@ config PPC
select ARCH_HAS_KCOV
select ARCH_HAS_MEMBARRIER_CALLBACKS
select ARCH_HAS_MEMBARRIER_SYNC_CORE
-   select ARCH_HAS_MEMREMAP_COMPAT_ALIGN   if PPC_BOOK3S_64
+   select ARCH_HAS_MEMREMAP_COMPAT_ALIGN   if PPC_64S_HASH_MMU
select ARCH_HAS_MMIOWB  if PPC64
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
select ARCH_HAS_PHYS_TO_DMA
diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h 
b/arch/powerpc/include/asm/book3s/64/mmu.h
index c02f42d1031e..046888f7ab6e 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu.h
@@ -98,7 +98,9 @@ typedef struct {
 * from EA and new context ids to build the new VAs.
 */
mm_context_id_t id;
+#ifdef CONFIG_PPC_64S_HASH_MMU
mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];
+#endif
};
 
/* Number of bits in the mm_cpumask */
@@ -110,7 +112,9 @@ typedef struct {
/* Number of user space windows opened in process mm_context */
atomic_t vas_windows;
 
+#ifdef CONFIG_PPC_64S_HASH_MMU
struct hash_mm_context *hash_context;
+#endif
 
void __user *vdso;
/*
@@ -133,6 +137,7 @@ typedef struct {
 #endif
 } mm_context_t;
 
+#ifdef CONFIG_PPC_64S_HASH_MMU
 static inline u16 mm_ctx_user_psize(mm_context_t *ctx)
 {
return ctx->hash_context->user_psize;
@@ -193,8 +198,15 @@ static inline struct subpage_prot_table 
*mm_ctx_subpage_prot(mm_context_t *ctx)
 extern int mmu_linear_psize;
 extern int mmu_virtual_psize;
 extern int mmu_vmalloc_psize;
-extern int mmu_vmemmap_psize;
 extern int mmu_io_psize;
+#else /* CONFIG_PPC_64S_HASH_MMU */
+#ifdef CONFIG_PPC_64K_PAGES
+#define mmu_virtual_psize MMU_PAGE_64K
+#else
+#define mmu_virtual_psize MMU_PAGE_4K
+#endif
+#endif
+extern int mmu_vmemmap_psize;
 
 /* MMU initialization */
 void mmu_early_init_devtree(void);
@@ -233,8 +245,9 @@ static inline void setup_initial_memory_limit(phys_addr_t 
first_memblock_base,
 * know which translations we will pick. Hence go with hash
 * restrictions.
 */
-   return hash__setup_initial_memory_limit(first_memblock_base,
-  first_memblock_size);
+   if (!radix_enabled())
+   hash__setup_initial_memory_limit(first_memblock_base,
+first_memblock_size);
 }
 
 #ifdef CONFIG_PPC_PSERIES
@@ -255,6 +268,7 @@ 

[PATCH v4 15/17] powerpc/64s: Make hash MMU support configurable

2021-11-25 Thread Nicholas Piggin
This adds Kconfig selection which allows 64s hash MMU support to be
disabled. It can be disabled if radix support is enabled, the minimum
supported CPU type is POWER9 (or higher), and KVM is not selected.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Kconfig |  3 ++-
 arch/powerpc/include/asm/mmu.h   | 16 +---
 arch/powerpc/kernel/dt_cpu_ftrs.c| 14 ++
 arch/powerpc/kvm/Kconfig |  1 +
 arch/powerpc/mm/init_64.c| 13 +++--
 arch/powerpc/platforms/Kconfig.cputype   | 23 +--
 arch/powerpc/platforms/microwatt/Kconfig |  2 +-
 arch/powerpc/platforms/powernv/Kconfig   |  2 +-
 8 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 27afb64d027c..1fa336ec8faf 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -845,7 +845,7 @@ config FORCE_MAX_ZONEORDER
 config PPC_SUBPAGE_PROT
bool "Support setting protections for 4k subpages (subpage_prot 
syscall)"
default n
-   depends on PPC_BOOK3S_64 && PPC_64K_PAGES
+   depends on PPC_64S_HASH_MMU && PPC_64K_PAGES
help
  This option adds support for system call to allow user programs
  to set access permissions (read/write, readonly, or no access)
@@ -943,6 +943,7 @@ config PPC_MEM_KEYS
prompt "PowerPC Memory Protection Keys"
def_bool y
depends on PPC_BOOK3S_64
+   depends on PPC_64S_HASH_MMU
select ARCH_USES_HIGH_VMA_FLAGS
select ARCH_HAS_PKEYS
help
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 8abe8e42e045..5f41565a1e5d 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -157,7 +157,7 @@ DECLARE_PER_CPU(int, next_tlbcam_idx);
 
 enum {
MMU_FTRS_POSSIBLE =
-#if defined(CONFIG_PPC_BOOK3S_64) || defined(CONFIG_PPC_BOOK3S_604)
+#if defined(CONFIG_PPC_BOOK3S_604)
MMU_FTR_HPTE_TABLE |
 #endif
 #ifdef CONFIG_PPC_8xx
@@ -184,15 +184,18 @@ enum {
MMU_FTR_USE_TLBRSRV | MMU_FTR_USE_PAIRED_MAS |
 #endif
 #ifdef CONFIG_PPC_BOOK3S_64
+   MMU_FTR_KERNEL_RO |
+#ifdef CONFIG_PPC_64S_HASH_MMU
MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL |
MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE |
MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |
-   MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA |
+   MMU_FTR_68_BIT_VA | MMU_FTR_HPTE_TABLE |
 #endif
 #ifdef CONFIG_PPC_RADIX_MMU
MMU_FTR_TYPE_RADIX |
MMU_FTR_GTSE |
 #endif /* CONFIG_PPC_RADIX_MMU */
+#endif
 #ifdef CONFIG_PPC_KUAP
MMU_FTR_BOOK3S_KUAP |
 #endif /* CONFIG_PPC_KUAP */
@@ -224,6 +227,13 @@ enum {
 #define MMU_FTRS_ALWAYSMMU_FTR_TYPE_FSL_E
 #endif
 
+/* BOOK3S_64 options */
+#if defined(CONFIG_PPC_RADIX_MMU) && !defined(CONFIG_PPC_64S_HASH_MMU)
+#define MMU_FTRS_ALWAYSMMU_FTR_TYPE_RADIX
+#elif !defined(CONFIG_PPC_RADIX_MMU) && defined(CONFIG_PPC_64S_HASH_MMU)
+#define MMU_FTRS_ALWAYSMMU_FTR_HPTE_TABLE
+#endif
+
 #ifndef MMU_FTRS_ALWAYS
 #define MMU_FTRS_ALWAYS0
 #endif
@@ -329,7 +339,7 @@ static __always_inline bool radix_enabled(void)
return mmu_has_feature(MMU_FTR_TYPE_RADIX);
 }
 
-static inline bool early_radix_enabled(void)
+static __always_inline bool early_radix_enabled(void)
 {
return early_mmu_has_feature(MMU_FTR_TYPE_RADIX);
 }
diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c 
b/arch/powerpc/kernel/dt_cpu_ftrs.c
index d2b35fb9181d..1ac8d7357195 100644
--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
+++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
@@ -273,6 +273,9 @@ static int __init feat_enable_mmu_hash(struct 
dt_cpu_feature *f)
 {
u64 lpcr;
 
+   if (!IS_ENABLED(CONFIG_PPC_64S_HASH_MMU))
+   return 0;
+
lpcr = mfspr(SPRN_LPCR);
lpcr &= ~LPCR_ISL;
 
@@ -292,6 +295,9 @@ static int __init feat_enable_mmu_hash_v3(struct 
dt_cpu_feature *f)
 {
u64 lpcr;
 
+   if (!IS_ENABLED(CONFIG_PPC_64S_HASH_MMU))
+   return 0;
+
lpcr = mfspr(SPRN_LPCR);
lpcr &= ~(LPCR_ISL | LPCR_UPRT | LPCR_HR);
mtspr(SPRN_LPCR, lpcr);
@@ -305,15 +311,15 @@ static int __init feat_enable_mmu_hash_v3(struct 
dt_cpu_feature *f)
 
 static int __init feat_enable_mmu_radix(struct dt_cpu_feature *f)
 {
-#ifdef CONFIG_PPC_RADIX_MMU
+   if (!IS_ENABLED(CONFIG_PPC_RADIX_MMU))
+   return 0;
+
+   cur_cpu_spec->mmu_features |= MMU_FTR_KERNEL_RO;
cur_cpu_spec->mmu_features |= MMU_FTR_TYPE_RADIX;
-   cur_cpu_spec->mmu_features |= MMU_FTRS_HASH_BASE;
cur_cpu_spec->mmu_features |= MMU_FTR_GTSE;
cur_cpu_spec->cpu_user_features |= PPC_FEATURE_HAS_MMU;
 
return 1;
-#endif
-   return 0;
 }
 
 static int __init feat_enable_dscr(struct dt_cpu_feature *f)
diff 

[PATCH v4 14/17] powerpc/64s: Fix radix MMU when MMU_FTR_HPTE_TABLE is clear

2021-11-25 Thread Nicholas Piggin
There are a few places that require MMU_FTR_HPTE_TABLE to be set even
when running in radix mode. Fix those up.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/pgtable.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
index ce9482383144..abb3198bd277 100644
--- a/arch/powerpc/mm/pgtable.c
+++ b/arch/powerpc/mm/pgtable.c
@@ -81,9 +81,6 @@ static struct page *maybe_pte_to_page(pte_t pte)
 
 static pte_t set_pte_filter_hash(pte_t pte)
 {
-   if (radix_enabled())
-   return pte;
-
pte = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS);
if (pte_looks_normal(pte) && !(cpu_has_feature(CPU_FTR_COHERENT_ICACHE) 
||
   cpu_has_feature(CPU_FTR_NOEXECUTE))) {
@@ -112,6 +109,9 @@ static inline pte_t set_pte_filter(pte_t pte)
 {
struct page *pg;
 
+   if (radix_enabled())
+   return pte;
+
if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
return set_pte_filter_hash(pte);
 
@@ -144,6 +144,9 @@ static pte_t set_access_flags_filter(pte_t pte, struct 
vm_area_struct *vma,
 {
struct page *pg;
 
+   if (IS_ENABLED(CONFIG_PPC_BOOK3S_64))
+   return pte;
+
if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
return pte;
 
-- 
2.23.0



[PATCH v4 13/17] powerpc/64e: remove mmu_linear_psize

2021-11-25 Thread Nicholas Piggin
mmu_linear_psize is only set at boot once on 64e, is not necessarily
the correct size of the linear map pages, and is never used anywhere.
Remove it.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/nohash/mmu-book3e.h | 1 -
 arch/powerpc/mm/nohash/tlb.c | 9 -
 2 files changed, 10 deletions(-)

diff --git a/arch/powerpc/include/asm/nohash/mmu-book3e.h 
b/arch/powerpc/include/asm/nohash/mmu-book3e.h
index e43a418d3ccd..787e6482e299 100644
--- a/arch/powerpc/include/asm/nohash/mmu-book3e.h
+++ b/arch/powerpc/include/asm/nohash/mmu-book3e.h
@@ -284,7 +284,6 @@ static inline unsigned int mmu_psize_to_shift(unsigned int 
mmu_psize)
 #error Unsupported page size
 #endif
 
-extern int mmu_linear_psize;
 extern int mmu_vmemmap_psize;
 
 struct tlb_core_data {
diff --git a/arch/powerpc/mm/nohash/tlb.c b/arch/powerpc/mm/nohash/tlb.c
index 647bf454a0fa..311281063d48 100644
--- a/arch/powerpc/mm/nohash/tlb.c
+++ b/arch/powerpc/mm/nohash/tlb.c
@@ -150,7 +150,6 @@ static inline int mmu_get_tsize(int psize)
  */
 #ifdef CONFIG_PPC64
 
-int mmu_linear_psize;  /* Page size used for the linear mapping */
 int mmu_pte_psize; /* Page size used for PTE pages */
 int mmu_vmemmap_psize; /* Page size used for the virtual mem map */
 int book3e_htw_mode;   /* HW tablewalk?  Value is PPC_HTW_* */
@@ -657,14 +656,6 @@ static void early_init_this_mmu(void)
 
 static void __init early_init_mmu_global(void)
 {
-   /* XXX This will have to be decided at runtime, but right
-* now our boot and TLB miss code hard wires it. Ideally
-* we should find out a suitable page size and patch the
-* TLB miss code (either that or use the PACA to store
-* the value we want)
-*/
-   mmu_linear_psize = MMU_PAGE_1G;
-
/* XXX This should be decided at runtime based on supported
 * page sizes in the TLB, but for now let's assume 16M is
 * always there and a good fit (which it probably is)
-- 
2.23.0



[PATCH v4 12/17] powerpc: make memremap_compat_align 64s-only

2021-11-25 Thread Nicholas Piggin
memremap_compat_align is only relevant when ZONE_DEVICE is selected.
ZONE_DEVICE depends on ARCH_HAS_PTE_DEVMAP, which is only selected
by PPC_BOOK3S_64.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Kconfig   |  2 +-
 arch/powerpc/mm/book3s64/pgtable.c | 20 
 arch/powerpc/mm/ioremap.c  | 20 
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index dea74d7717c0..27afb64d027c 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -129,7 +129,7 @@ config PPC
select ARCH_HAS_KCOV
select ARCH_HAS_MEMBARRIER_CALLBACKS
select ARCH_HAS_MEMBARRIER_SYNC_CORE
-   select ARCH_HAS_MEMREMAP_COMPAT_ALIGN
+   select ARCH_HAS_MEMREMAP_COMPAT_ALIGN   if PPC_BOOK3S_64
select ARCH_HAS_MMIOWB  if PPC64
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
select ARCH_HAS_PHYS_TO_DMA
diff --git a/arch/powerpc/mm/book3s64/pgtable.c 
b/arch/powerpc/mm/book3s64/pgtable.c
index 81f2e5b670e2..4d97d1525d49 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -533,3 +533,23 @@ static int __init pgtable_debugfs_setup(void)
return 0;
 }
 arch_initcall(pgtable_debugfs_setup);
+
+#ifdef CONFIG_ZONE_DEVICE
+/*
+ * Override the generic version in mm/memremap.c.
+ *
+ * With hash translation, the direct-map range is mapped with just one
+ * page size selected by htab_init_page_sizes(). Consult
+ * mmu_psize_defs[] to determine the minimum page size alignment.
+*/
+unsigned long memremap_compat_align(void)
+{
+   if (!radix_enabled()) {
+   unsigned int shift = mmu_psize_defs[mmu_linear_psize].shift;
+   return max(SUBSECTION_SIZE, 1UL << shift);
+   }
+
+   return SUBSECTION_SIZE;
+}
+EXPORT_SYMBOL_GPL(memremap_compat_align);
+#endif
diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c
index 57342154d2b0..4f12504fb405 100644
--- a/arch/powerpc/mm/ioremap.c
+++ b/arch/powerpc/mm/ioremap.c
@@ -98,23 +98,3 @@ void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, 
unsigned long size,
 
return NULL;
 }
-
-#ifdef CONFIG_ZONE_DEVICE
-/*
- * Override the generic version in mm/memremap.c.
- *
- * With hash translation, the direct-map range is mapped with just one
- * page size selected by htab_init_page_sizes(). Consult
- * mmu_psize_defs[] to determine the minimum page size alignment.
-*/
-unsigned long memremap_compat_align(void)
-{
-   unsigned int shift = mmu_psize_defs[mmu_linear_psize].shift;
-
-   if (radix_enabled())
-   return SUBSECTION_SIZE;
-   return max(SUBSECTION_SIZE, 1UL << shift);
-
-}
-EXPORT_SYMBOL_GPL(memremap_compat_align);
-#endif
-- 
2.23.0



[PATCH v4 11/17] powerpc/64: pcpu setup avoid reading mmu_linear_psize on 64e or radix

2021-11-25 Thread Nicholas Piggin
Radix never sets mmu_linear_psize so it's always 4K, which causes pcpu
atom_size to always be PAGE_SIZE. 64e sets it to 1GB always.

Make paths for these platforms to be explicit about what value they set
atom_size to.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/setup_64.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 6052f5d5ded3..9a493796ce66 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -880,14 +880,23 @@ void __init setup_per_cpu_areas(void)
int rc = -EINVAL;
 
/*
-* Linear mapping is one of 4K, 1M and 16M.  For 4K, no need
-* to group units.  For larger mappings, use 1M atom which
-* should be large enough to contain a number of units.
+* BookE and BookS radix are historical values and should be revisited.
 */
-   if (mmu_linear_psize == MMU_PAGE_4K)
+   if (IS_ENABLED(CONFIG_PPC_BOOK3E)) {
+   atom_size = SZ_1M;
+   } else if (radix_enabled()) {
atom_size = PAGE_SIZE;
-   else
-   atom_size = 1 << 20;
+   } else {
+   /*
+* Linear mapping is one of 4K, 1M and 16M.  For 4K, no need
+* to group units.  For larger mappings, use 1M atom which
+* should be large enough to contain a number of units.
+*/
+   if (mmu_linear_psize == MMU_PAGE_4K)
+   atom_size = PAGE_SIZE;
+   else
+   atom_size = SZ_1M;
+   }
 
if (pcpu_chosen_fc != PCPU_FC_PAGE) {
rc = pcpu_embed_first_chunk(0, dyn_size, atom_size, 
pcpu_cpu_distance,
-- 
2.23.0



[PATCH v4 10/17] powerpc/64s: Rename hash_hugetlbpage.c to hugetlbpage.c

2021-11-25 Thread Nicholas Piggin
This file contains functions and data common to radix, so rename it to
remove the hash_ prefix.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/book3s64/Makefile  | 2 +-
 arch/powerpc/mm/book3s64/{hash_hugetlbpage.c => hugetlbpage.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename arch/powerpc/mm/book3s64/{hash_hugetlbpage.c => hugetlbpage.c} (100%)

diff --git a/arch/powerpc/mm/book3s64/Makefile 
b/arch/powerpc/mm/book3s64/Makefile
index 1579e18e098d..501efadb287f 100644
--- a/arch/powerpc/mm/book3s64/Makefile
+++ b/arch/powerpc/mm/book3s64/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_PPC_HASH_MMU_NATIVE) += hash_native.o
 obj-$(CONFIG_PPC_RADIX_MMU)+= radix_pgtable.o radix_tlb.o
 obj-$(CONFIG_PPC_4K_PAGES) += hash_4k.o
 obj-$(CONFIG_PPC_64K_PAGES)+= hash_64k.o
-obj-$(CONFIG_HUGETLB_PAGE) += hash_hugetlbpage.o
+obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 ifdef CONFIG_HUGETLB_PAGE
 obj-$(CONFIG_PPC_RADIX_MMU)+= radix_hugetlbpage.o
 endif
diff --git a/arch/powerpc/mm/book3s64/hash_hugetlbpage.c 
b/arch/powerpc/mm/book3s64/hugetlbpage.c
similarity index 100%
rename from arch/powerpc/mm/book3s64/hash_hugetlbpage.c
rename to arch/powerpc/mm/book3s64/hugetlbpage.c
-- 
2.23.0



[PATCH v4 09/17] powerpc/64s: move page size definitions from hash specific file

2021-11-25 Thread Nicholas Piggin
The radix code uses some of the psize variables. Move the common
ones from hash_utils.c to pgtable.c.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/book3s64/hash_utils.c | 5 -
 arch/powerpc/mm/book3s64/pgtable.c| 7 +++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index 97a36fa3940e..eced266dc5e9 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -99,8 +99,6 @@
  */
 
 static unsigned long _SDR1;
-struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
-EXPORT_SYMBOL_GPL(mmu_psize_defs);
 
 u8 hpte_page_sizes[1 << LP_BITS];
 EXPORT_SYMBOL_GPL(hpte_page_sizes);
@@ -114,9 +112,6 @@ EXPORT_SYMBOL_GPL(mmu_linear_psize);
 int mmu_virtual_psize = MMU_PAGE_4K;
 int mmu_vmalloc_psize = MMU_PAGE_4K;
 EXPORT_SYMBOL_GPL(mmu_vmalloc_psize);
-#ifdef CONFIG_SPARSEMEM_VMEMMAP
-int mmu_vmemmap_psize = MMU_PAGE_4K;
-#endif
 int mmu_io_psize = MMU_PAGE_4K;
 int mmu_kernel_ssize = MMU_SEGSIZE_256M;
 EXPORT_SYMBOL_GPL(mmu_kernel_ssize);
diff --git a/arch/powerpc/mm/book3s64/pgtable.c 
b/arch/powerpc/mm/book3s64/pgtable.c
index 9e16c7b1a6c5..81f2e5b670e2 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -22,6 +22,13 @@
 
 #include "internal.h"
 
+struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
+EXPORT_SYMBOL_GPL(mmu_psize_defs);
+
+#ifdef CONFIG_SPARSEMEM_VMEMMAP
+int mmu_vmemmap_psize = MMU_PAGE_4K;
+#endif
+
 unsigned long __pmd_frag_nr;
 EXPORT_SYMBOL(__pmd_frag_nr);
 unsigned long __pmd_frag_size_shift;
-- 
2.23.0



[PATCH v4 08/17] powerpc/64s: Make flush_and_reload_slb a no-op when radix is enabled

2021-11-25 Thread Nicholas Piggin
The radix test can exclude slb_flush_all_realmode() from being called
because flush_and_reload_slb() is only expected to flush ERAT when
called by flush_erat(), which is only on pre-ISA v3.0 CPUs that do not
support radix.

This helps the later change to make hash support configurable to not
introduce runtime changes to radix mode behaviour.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/mce_power.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
index c2f55fe7092d..cf5263b648fc 100644
--- a/arch/powerpc/kernel/mce_power.c
+++ b/arch/powerpc/kernel/mce_power.c
@@ -80,12 +80,12 @@ static bool mce_in_guest(void)
 #ifdef CONFIG_PPC_BOOK3S_64
 void flush_and_reload_slb(void)
 {
-   /* Invalidate all SLBs */
-   slb_flush_all_realmode();
-
if (early_radix_enabled())
return;
 
+   /* Invalidate all SLBs */
+   slb_flush_all_realmode();
+
/*
 * This probably shouldn't happen, but it may be possible it's
 * called in early boot before SLB shadows are allocated.
-- 
2.23.0



[PATCH v4 07/17] powerpc/64s: move THP trace point creation out of hash specific file

2021-11-25 Thread Nicholas Piggin
In preparation for making hash MMU support configurable, move THP
trace point function definitions out of an otherwise hash-specific
file.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/book3s64/Makefile   | 2 +-
 arch/powerpc/mm/book3s64/hash_pgtable.c | 1 -
 arch/powerpc/mm/book3s64/trace.c| 8 
 3 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/mm/book3s64/trace.c

diff --git a/arch/powerpc/mm/book3s64/Makefile 
b/arch/powerpc/mm/book3s64/Makefile
index 319f4b7f3357..1579e18e098d 100644
--- a/arch/powerpc/mm/book3s64/Makefile
+++ b/arch/powerpc/mm/book3s64/Makefile
@@ -5,7 +5,7 @@ ccflags-y   := $(NO_MINIMAL_TOC)
 CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
 
 obj-y  += hash_pgtable.o hash_utils.o slb.o \
-  mmu_context.o pgtable.o hash_tlb.o
+  mmu_context.o pgtable.o hash_tlb.o trace.o
 obj-$(CONFIG_PPC_HASH_MMU_NATIVE)  += hash_native.o
 obj-$(CONFIG_PPC_RADIX_MMU)+= radix_pgtable.o radix_tlb.o
 obj-$(CONFIG_PPC_4K_PAGES) += hash_4k.o
diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c 
b/arch/powerpc/mm/book3s64/hash_pgtable.c
index ad5eff097d31..7ce8914992e3 100644
--- a/arch/powerpc/mm/book3s64/hash_pgtable.c
+++ b/arch/powerpc/mm/book3s64/hash_pgtable.c
@@ -16,7 +16,6 @@
 
 #include 
 
-#define CREATE_TRACE_POINTS
 #include 
 
 #if H_PGTABLE_RANGE > (USER_VSID_RANGE * (TASK_SIZE_USER64 / 
TASK_CONTEXT_SIZE))
diff --git a/arch/powerpc/mm/book3s64/trace.c b/arch/powerpc/mm/book3s64/trace.c
new file mode 100644
index ..b86e7b906257
--- /dev/null
+++ b/arch/powerpc/mm/book3s64/trace.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * This file is for defining trace points and trace related helpers.
+ */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#define CREATE_TRACE_POINTS
+#include 
+#endif
-- 
2.23.0



[PATCH v4 06/17] powerpc/pseries: lparcfg don't include slb_size line in radix mode

2021-11-25 Thread Nicholas Piggin
This avoids a change in behaviour in the later patch making hash
support configurable. This is possibly a user interface change, so
the alternative would be a hard-coded slb_size=0 here.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/platforms/pseries/lparcfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/lparcfg.c 
b/arch/powerpc/platforms/pseries/lparcfg.c
index f71eac74ea92..3354c00914fa 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -532,7 +532,8 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)
   lppaca_shared_proc(get_lppaca()));
 
 #ifdef CONFIG_PPC_BOOK3S_64
-   seq_printf(m, "slb_size=%d\n", mmu_slb_size);
+   if (!radix_enabled())
+   seq_printf(m, "slb_size=%d\n", mmu_slb_size);
 #endif
parse_em_data(m);
maxmem_data(m);
-- 
2.23.0



[PATCH v4 05/17] powerpc/pseries: move process table registration away from hash-specific code

2021-11-25 Thread Nicholas Piggin
This reduces ifdefs in a later change which makes hash support configurable.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/platforms/pseries/lpar.c | 56 +--
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/lpar.c 
b/arch/powerpc/platforms/pseries/lpar.c
index 3df6bdfea475..06d6a824c0dc 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -712,6 +712,34 @@ void vpa_init(int cpu)
 
 #ifdef CONFIG_PPC_BOOK3S_64
 
+static int pseries_lpar_register_process_table(unsigned long base,
+   unsigned long page_size, unsigned long table_size)
+{
+   long rc;
+   unsigned long flags = 0;
+
+   if (table_size)
+   flags |= PROC_TABLE_NEW;
+   if (radix_enabled()) {
+   flags |= PROC_TABLE_RADIX;
+   if (mmu_has_feature(MMU_FTR_GTSE))
+   flags |= PROC_TABLE_GTSE;
+   } else
+   flags |= PROC_TABLE_HPT_SLB;
+   for (;;) {
+   rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base,
+   page_size, table_size);
+   if (!H_IS_LONG_BUSY(rc))
+   break;
+   mdelay(get_longbusy_msecs(rc));
+   }
+   if (rc != H_SUCCESS) {
+   pr_err("Failed to register process table (rc=%ld)\n", rc);
+   BUG();
+   }
+   return rc;
+}
+
 static long pSeries_lpar_hpte_insert(unsigned long hpte_group,
 unsigned long vpn, unsigned long pa,
 unsigned long rflags, unsigned long vflags,
@@ -1680,34 +1708,6 @@ static int pseries_lpar_resize_hpt(unsigned long shift)
return 0;
 }
 
-static int pseries_lpar_register_process_table(unsigned long base,
-   unsigned long page_size, unsigned long table_size)
-{
-   long rc;
-   unsigned long flags = 0;
-
-   if (table_size)
-   flags |= PROC_TABLE_NEW;
-   if (radix_enabled()) {
-   flags |= PROC_TABLE_RADIX;
-   if (mmu_has_feature(MMU_FTR_GTSE))
-   flags |= PROC_TABLE_GTSE;
-   } else
-   flags |= PROC_TABLE_HPT_SLB;
-   for (;;) {
-   rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base,
-   page_size, table_size);
-   if (!H_IS_LONG_BUSY(rc))
-   break;
-   mdelay(get_longbusy_msecs(rc));
-   }
-   if (rc != H_SUCCESS) {
-   pr_err("Failed to register process table (rc=%ld)\n", rc);
-   BUG();
-   }
-   return rc;
-}
-
 void __init hpte_init_pseries(void)
 {
mmu_hash_ops.hpte_invalidate = pSeries_lpar_hpte_invalidate;
-- 
2.23.0



[PATCH v4 04/17] powerpc/64s: Move and rename do_bad_slb_fault as it is not hash specific

2021-11-25 Thread Nicholas Piggin
slb.c is hash-specific SLB management, but do_bad_slb_fault deals with
segment interrupts that occur with radix MMU as well.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/interrupt.h |  2 +-
 arch/powerpc/kernel/exceptions-64s.S |  4 ++--
 arch/powerpc/mm/book3s64/slb.c   | 16 
 arch/powerpc/mm/fault.c  | 24 
 4 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index a1d238255f07..3487aab12229 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -564,7 +564,7 @@ DECLARE_INTERRUPT_HANDLER(kernel_bad_stack);
 
 /* slb.c */
 DECLARE_INTERRUPT_HANDLER_RAW(do_slb_fault);
-DECLARE_INTERRUPT_HANDLER(do_bad_slb_fault);
+DECLARE_INTERRUPT_HANDLER(do_bad_segment_interrupt);
 
 /* hash_utils.c */
 DECLARE_INTERRUPT_HANDLER_RAW(do_hash_fault);
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index eaf1f72131a1..046c99e31d01 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1430,7 +1430,7 @@ MMU_FTR_SECTION_ELSE
 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
std r3,RESULT(r1)
addir3,r1,STACK_FRAME_OVERHEAD
-   bl  do_bad_slb_fault
+   bl  do_bad_segment_interrupt
b   interrupt_return_srr
 
 
@@ -1510,7 +1510,7 @@ MMU_FTR_SECTION_ELSE
 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
std r3,RESULT(r1)
addir3,r1,STACK_FRAME_OVERHEAD
-   bl  do_bad_slb_fault
+   bl  do_bad_segment_interrupt
b   interrupt_return_srr
 
 
diff --git a/arch/powerpc/mm/book3s64/slb.c b/arch/powerpc/mm/book3s64/slb.c
index f0037bcc47a0..31f4cef3adac 100644
--- a/arch/powerpc/mm/book3s64/slb.c
+++ b/arch/powerpc/mm/book3s64/slb.c
@@ -868,19 +868,3 @@ DEFINE_INTERRUPT_HANDLER_RAW(do_slb_fault)
return err;
}
 }
-
-DEFINE_INTERRUPT_HANDLER(do_bad_slb_fault)
-{
-   int err = regs->result;
-
-   if (err == -EFAULT) {
-   if (user_mode(regs))
-   _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar);
-   else
-   bad_page_fault(regs, SIGSEGV);
-   } else if (err == -EINVAL) {
-   unrecoverable_exception(regs);
-   } else {
-   BUG();
-   }
-}
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index a8d0ce85d39a..2d4a411c7c85 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -620,4 +621,27 @@ DEFINE_INTERRUPT_HANDLER(do_bad_page_fault_segv)
 {
bad_page_fault(regs, SIGSEGV);
 }
+
+/*
+ * In radix, segment interrupts indicate the EA is not addressable by the
+ * page table geometry, so they are always sent here.
+ *
+ * In hash, this is called if do_slb_fault returns error. Typically it is
+ * because the EA was outside the region allowed by software.
+ */
+DEFINE_INTERRUPT_HANDLER(do_bad_segment_interrupt)
+{
+   int err = regs->result;
+
+   if (err == -EFAULT) {
+   if (user_mode(regs))
+   _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar);
+   else
+   bad_page_fault(regs, SIGSEGV);
+   } else if (err == -EINVAL) {
+   unrecoverable_exception(regs);
+   } else {
+   BUG();
+   }
+}
 #endif
-- 
2.23.0



[PATCH v4 03/17] powerpc/pseries: Stop selecting PPC_HASH_MMU_NATIVE

2021-11-25 Thread Nicholas Piggin
The pseries platform does not use the native hash code but the PAPR
virtualised hash interfaces, so remove PPC_HASH_MMU_NATIVE.

This requires moving tlbiel code from hash_native.c to hash_utils.c.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/book3s/64/tlbflush.h |   4 -
 arch/powerpc/mm/book3s64/hash_native.c| 104 --
 arch/powerpc/mm/book3s64/hash_utils.c | 104 ++
 arch/powerpc/platforms/pseries/Kconfig|   1 -
 4 files changed, 104 insertions(+), 109 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush.h 
b/arch/powerpc/include/asm/book3s/64/tlbflush.h
index 215973b4cb26..d2e80f178b6d 100644
--- a/arch/powerpc/include/asm/book3s/64/tlbflush.h
+++ b/arch/powerpc/include/asm/book3s/64/tlbflush.h
@@ -14,7 +14,6 @@ enum {
TLB_INVAL_SCOPE_LPID = 1,   /* invalidate TLBs for current LPID */
 };
 
-#ifdef CONFIG_PPC_NATIVE
 static inline void tlbiel_all(void)
 {
/*
@@ -30,9 +29,6 @@ static inline void tlbiel_all(void)
else
hash__tlbiel_all(TLB_INVAL_SCOPE_GLOBAL);
 }
-#else
-static inline void tlbiel_all(void) { BUG(); }
-#endif
 
 static inline void tlbiel_all_lpid(bool radix)
 {
diff --git a/arch/powerpc/mm/book3s64/hash_native.c 
b/arch/powerpc/mm/book3s64/hash_native.c
index d8279bfe68ea..d2a320828c0b 100644
--- a/arch/powerpc/mm/book3s64/hash_native.c
+++ b/arch/powerpc/mm/book3s64/hash_native.c
@@ -43,110 +43,6 @@
 
 static DEFINE_RAW_SPINLOCK(native_tlbie_lock);
 
-static inline void tlbiel_hash_set_isa206(unsigned int set, unsigned int is)
-{
-   unsigned long rb;
-
-   rb = (set << PPC_BITLSHIFT(51)) | (is << PPC_BITLSHIFT(53));
-
-   asm volatile("tlbiel %0" : : "r" (rb));
-}
-
-/*
- * tlbiel instruction for hash, set invalidation
- * i.e., r=1 and is=01 or is=10 or is=11
- */
-static __always_inline void tlbiel_hash_set_isa300(unsigned int set, unsigned 
int is,
-   unsigned int pid,
-   unsigned int ric, unsigned int prs)
-{
-   unsigned long rb;
-   unsigned long rs;
-   unsigned int r = 0; /* hash format */
-
-   rb = (set << PPC_BITLSHIFT(51)) | (is << PPC_BITLSHIFT(53));
-   rs = ((unsigned long)pid << PPC_BITLSHIFT(31));
-
-   asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4)
-: : "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r)
-: "memory");
-}
-
-
-static void tlbiel_all_isa206(unsigned int num_sets, unsigned int is)
-{
-   unsigned int set;
-
-   asm volatile("ptesync": : :"memory");
-
-   for (set = 0; set < num_sets; set++)
-   tlbiel_hash_set_isa206(set, is);
-
-   ppc_after_tlbiel_barrier();
-}
-
-static void tlbiel_all_isa300(unsigned int num_sets, unsigned int is)
-{
-   unsigned int set;
-
-   asm volatile("ptesync": : :"memory");
-
-   /*
-* Flush the partition table cache if this is HV mode.
-*/
-   if (early_cpu_has_feature(CPU_FTR_HVMODE))
-   tlbiel_hash_set_isa300(0, is, 0, 2, 0);
-
-   /*
-* Now invalidate the process table cache. UPRT=0 HPT modes (what
-* current hardware implements) do not use the process table, but
-* add the flushes anyway.
-*
-* From ISA v3.0B p. 1078:
-* The following forms are invalid.
-*  * PRS=1, R=0, and RIC!=2 (The only process-scoped
-*HPT caching is of the Process Table.)
-*/
-   tlbiel_hash_set_isa300(0, is, 0, 2, 1);
-
-   /*
-* Then flush the sets of the TLB proper. Hash mode uses
-* partition scoped TLB translations, which may be flushed
-* in !HV mode.
-*/
-   for (set = 0; set < num_sets; set++)
-   tlbiel_hash_set_isa300(set, is, 0, 0, 0);
-
-   ppc_after_tlbiel_barrier();
-
-   asm volatile(PPC_ISA_3_0_INVALIDATE_ERAT "; isync" : : :"memory");
-}
-
-void hash__tlbiel_all(unsigned int action)
-{
-   unsigned int is;
-
-   switch (action) {
-   case TLB_INVAL_SCOPE_GLOBAL:
-   is = 3;
-   break;
-   case TLB_INVAL_SCOPE_LPID:
-   is = 2;
-   break;
-   default:
-   BUG();
-   }
-
-   if (early_cpu_has_feature(CPU_FTR_ARCH_300))
-   tlbiel_all_isa300(POWER9_TLB_SETS_HASH, is);
-   else if (early_cpu_has_feature(CPU_FTR_ARCH_207S))
-   tlbiel_all_isa206(POWER8_TLB_SETS, is);
-   else if (early_cpu_has_feature(CPU_FTR_ARCH_206))
-   tlbiel_all_isa206(POWER7_TLB_SETS, is);
-   else
-   WARN(1, "%s called on pre-POWER7 CPU\n", __func__);
-}
-
 static inline unsigned long  ___tlbie(unsigned long vpn, int psize,
int apsize, int ssize)
 {
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index 92680da5229a..97a36fa3940e 

[PATCH v4 02/17] powerpc: Rename PPC_NATIVE to PPC_HASH_MMU_NATIVE

2021-11-25 Thread Nicholas Piggin
PPC_NATIVE now only controls the native HPT code, so rename it to be
more descriptive. Restrict it to Book3S only.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/mm/book3s64/Makefile  | 2 +-
 arch/powerpc/mm/book3s64/hash_utils.c  | 2 +-
 arch/powerpc/platforms/52xx/Kconfig| 2 +-
 arch/powerpc/platforms/Kconfig | 4 ++--
 arch/powerpc/platforms/cell/Kconfig| 2 +-
 arch/powerpc/platforms/chrp/Kconfig| 2 +-
 arch/powerpc/platforms/embedded6xx/Kconfig | 2 +-
 arch/powerpc/platforms/maple/Kconfig   | 2 +-
 arch/powerpc/platforms/microwatt/Kconfig   | 2 +-
 arch/powerpc/platforms/pasemi/Kconfig  | 2 +-
 arch/powerpc/platforms/powermac/Kconfig| 2 +-
 arch/powerpc/platforms/powernv/Kconfig | 2 +-
 arch/powerpc/platforms/pseries/Kconfig | 2 +-
 13 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/Makefile 
b/arch/powerpc/mm/book3s64/Makefile
index 1b56d3af47d4..319f4b7f3357 100644
--- a/arch/powerpc/mm/book3s64/Makefile
+++ b/arch/powerpc/mm/book3s64/Makefile
@@ -6,7 +6,7 @@ CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
 
 obj-y  += hash_pgtable.o hash_utils.o slb.o \
   mmu_context.o pgtable.o hash_tlb.o
-obj-$(CONFIG_PPC_NATIVE)   += hash_native.o
+obj-$(CONFIG_PPC_HASH_MMU_NATIVE)  += hash_native.o
 obj-$(CONFIG_PPC_RADIX_MMU)+= radix_pgtable.o radix_tlb.o
 obj-$(CONFIG_PPC_4K_PAGES) += hash_4k.o
 obj-$(CONFIG_PPC_64K_PAGES)+= hash_64k.o
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index cfd45245d009..92680da5229a 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -1091,7 +1091,7 @@ void __init hash__early_init_mmu(void)
ps3_early_mm_init();
else if (firmware_has_feature(FW_FEATURE_LPAR))
hpte_init_pseries();
-   else if (IS_ENABLED(CONFIG_PPC_NATIVE))
+   else if (IS_ENABLED(CONFIG_PPC_HASH_MMU_NATIVE))
hpte_init_native();
 
if (!mmu_hash_ops.hpte_insert)
diff --git a/arch/powerpc/platforms/52xx/Kconfig 
b/arch/powerpc/platforms/52xx/Kconfig
index 99d60acc20c8..b72ed2950ca8 100644
--- a/arch/powerpc/platforms/52xx/Kconfig
+++ b/arch/powerpc/platforms/52xx/Kconfig
@@ -34,7 +34,7 @@ config PPC_EFIKA
bool "bPlan Efika 5k2. MPC5200B based computer"
depends on PPC_MPC52xx
select PPC_RTAS
-   select PPC_NATIVE
+   select PPC_HASH_MMU_NATIVE
 
 config PPC_LITE5200
bool "Freescale Lite5200 Eval Board"
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e02d29a9d12f..d41dad227de8 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -40,9 +40,9 @@ config EPAPR_PARAVIRT
 
  In case of doubt, say Y
 
-config PPC_NATIVE
+config PPC_HASH_MMU_NATIVE
bool
-   depends on PPC_BOOK3S_32 || PPC64
+   depends on PPC_BOOK3S
help
  Support for running natively on the hardware, i.e. without
  a hypervisor. This option is not user-selectable but should
diff --git a/arch/powerpc/platforms/cell/Kconfig 
b/arch/powerpc/platforms/cell/Kconfig
index cb70c5f25bc6..db4465c51b56 100644
--- a/arch/powerpc/platforms/cell/Kconfig
+++ b/arch/powerpc/platforms/cell/Kconfig
@@ -8,7 +8,7 @@ config PPC_CELL_COMMON
select PPC_DCR_MMIO
select PPC_INDIRECT_PIO
select PPC_INDIRECT_MMIO
-   select PPC_NATIVE
+   select PPC_HASH_MMU_NATIVE
select PPC_RTAS
select IRQ_EDGE_EOI_HANDLER
 
diff --git a/arch/powerpc/platforms/chrp/Kconfig 
b/arch/powerpc/platforms/chrp/Kconfig
index 9b5c5505718a..ff30ed579a39 100644
--- a/arch/powerpc/platforms/chrp/Kconfig
+++ b/arch/powerpc/platforms/chrp/Kconfig
@@ -11,6 +11,6 @@ config PPC_CHRP
select RTAS_ERROR_LOGGING
select PPC_MPC106
select PPC_UDBG_16550
-   select PPC_NATIVE
+   select PPC_HASH_MMU_NATIVE
select FORCE_PCI
default y
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 4c6d703a4284..c54786f8461e 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -55,7 +55,7 @@ config MVME5100
select FORCE_PCI
select PPC_INDIRECT_PCI
select PPC_I8259
-   select PPC_NATIVE
+   select PPC_HASH_MMU_NATIVE
select PPC_UDBG_16550
help
  This option enables support for the Motorola (now Emerson) MVME5100
diff --git a/arch/powerpc/platforms/maple/Kconfig 
b/arch/powerpc/platforms/maple/Kconfig
index 86ae210bee9a..7fd84311ade5 100644
--- a/arch/powerpc/platforms/maple/Kconfig
+++ b/arch/powerpc/platforms/maple/Kconfig
@@ -9,7 +9,7 @@ config PPC_MAPLE
select GENERIC_TBSYNC
select PPC_UDBG_16550
select PPC_970_NAP
-   select PPC_NATIVE
+   select 

[PATCH v4 01/17] powerpc: Remove unused FW_FEATURE_NATIVE references

2021-11-25 Thread Nicholas Piggin
FW_FEATURE_NATIVE_ALWAYS and FW_FEATURE_NATIVE_POSSIBLE are always
zero and never do anything. Remove them.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/firmware.h | 8 
 1 file changed, 8 deletions(-)

diff --git a/arch/powerpc/include/asm/firmware.h 
b/arch/powerpc/include/asm/firmware.h
index 97a3bd9ffeb9..9b702d2b80fb 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -80,8 +80,6 @@ enum {
FW_FEATURE_POWERNV_ALWAYS = 0,
FW_FEATURE_PS3_POSSIBLE = FW_FEATURE_LPAR | FW_FEATURE_PS3_LV1,
FW_FEATURE_PS3_ALWAYS = FW_FEATURE_LPAR | FW_FEATURE_PS3_LV1,
-   FW_FEATURE_NATIVE_POSSIBLE = 0,
-   FW_FEATURE_NATIVE_ALWAYS = 0,
FW_FEATURE_POSSIBLE =
 #ifdef CONFIG_PPC_PSERIES
FW_FEATURE_PSERIES_POSSIBLE |
@@ -91,9 +89,6 @@ enum {
 #endif
 #ifdef CONFIG_PPC_PS3
FW_FEATURE_PS3_POSSIBLE |
-#endif
-#ifdef CONFIG_PPC_NATIVE
-   FW_FEATURE_NATIVE_ALWAYS |
 #endif
0,
FW_FEATURE_ALWAYS =
@@ -105,9 +100,6 @@ enum {
 #endif
 #ifdef CONFIG_PPC_PS3
FW_FEATURE_PS3_ALWAYS &
-#endif
-#ifdef CONFIG_PPC_NATIVE
-   FW_FEATURE_NATIVE_ALWAYS &
 #endif
FW_FEATURE_POSSIBLE,
 
-- 
2.23.0



[PATCH v4 00/17] powerpc: Make hash MMU code build configurable

2021-11-25 Thread Nicholas Piggin
Now that there's a platform that can make good use of it, here's
a series that can prevent the hash MMU code being built for 64s
platforms that don't need it.

Since v3:
- Merged microwatt patches into 1.
- Fix some changelogs, titles, comments.
- Keep MMU_FTR_HPTE_TABLE in the features when booting radix if hash
  support is is configured because it will be needed for KVM radix host
  hash guest (when we extend this option to KVM).
- Accounted for hopefully all review comments (thanks Christophe)

Since v2:
- Split MMU_FTR_HPTE_TABLE clearing for radix boot into its own patch.
- Remove memremap_compat_align from other sub archs entirely.
- Flip patch order of the 2 main patches to put Kconfig change first.
- Fixed Book3S/32 xmon segment dumping bug.
- Removed a few more ifdefs, changed numbers to use SZ_ definitions,
  etc.
- Fixed microwatt defconfig so it should actually disable hash MMU now.

Since v1:
- Split out most of the Kconfig change from the conditional compilation
  changes.
- Split out several more changes into preparatory patches.
- Reduced some ifdefs.
- Caught a few missing hash bits: pgtable dump, lkdtm,
  memremap_compat_align.

Since RFC:
- Split out large code movement from other changes.
- Used mmu ftr test constant folding rather than adding new constant
  true/false for radix_enabled().
- Restore tlbie trace point that had to be commented out in the
  previous.
- Avoid minor (probably unreachable) behaviour change in machine check
  handler when hash was not compiled.
- Fix microwatt updates so !HASH is not enforced.
- Rebase, build fixes.

Thanks,
Nick

Nicholas Piggin (17):
  powerpc: Remove unused FW_FEATURE_NATIVE references
  powerpc: Rename PPC_NATIVE to PPC_HASH_MMU_NATIVE
  powerpc/pseries: Stop selecting PPC_HASH_MMU_NATIVE
  powerpc/64s: Move and rename do_bad_slb_fault as it is not hash
specific
  powerpc/pseries: move process table registration away from
hash-specific code
  powerpc/pseries: lparcfg don't include slb_size line in radix mode
  powerpc/64s: move THP trace point creation out of hash specific file
  powerpc/64s: Make flush_and_reload_slb a no-op when radix is enabled
  powerpc/64s: move page size definitions from hash specific file
  powerpc/64s: Rename hash_hugetlbpage.c to hugetlbpage.c
  powerpc/64: pcpu setup avoid reading mmu_linear_psize on 64e or radix
  powerpc: make memremap_compat_align 64s-only
  powerpc/64e: remove mmu_linear_psize
  powerpc/64s: Fix radix MMU when MMU_FTR_HPTE_TABLE is clear
  powerpc/64s: Make hash MMU support configurable
  powerpc/64s: Move hash MMU support code under CONFIG_PPC_64S_HASH_MMU
  powerpc/microwatt: add POWER9_CPU, clear PPC_64S_HASH_MMU

 arch/powerpc/Kconfig  |   5 +-
 arch/powerpc/configs/microwatt_defconfig  |   3 +-
 arch/powerpc/include/asm/book3s/64/mmu.h  |  21 +++-
 .../include/asm/book3s/64/tlbflush-hash.h |   6 +
 arch/powerpc/include/asm/book3s/64/tlbflush.h |   4 -
 arch/powerpc/include/asm/book3s/pgtable.h |   4 +
 arch/powerpc/include/asm/firmware.h   |   8 --
 arch/powerpc/include/asm/interrupt.h  |   2 +-
 arch/powerpc/include/asm/mmu.h|  16 ++-
 arch/powerpc/include/asm/mmu_context.h|   2 +
 arch/powerpc/include/asm/nohash/mmu-book3e.h  |   1 -
 arch/powerpc/include/asm/paca.h   |   8 ++
 arch/powerpc/kernel/asm-offsets.c |   2 +
 arch/powerpc/kernel/dt_cpu_ftrs.c |  14 ++-
 arch/powerpc/kernel/entry_64.S|   4 +-
 arch/powerpc/kernel/exceptions-64s.S  |  20 +++-
 arch/powerpc/kernel/mce.c |   2 +-
 arch/powerpc/kernel/mce_power.c   |  16 ++-
 arch/powerpc/kernel/paca.c|  18 ++-
 arch/powerpc/kernel/process.c |  13 +-
 arch/powerpc/kernel/prom.c|   2 +
 arch/powerpc/kernel/setup_64.c|  26 +++-
 arch/powerpc/kexec/core_64.c  |   4 +-
 arch/powerpc/kexec/ranges.c   |   4 +
 arch/powerpc/kvm/Kconfig  |   1 +
 arch/powerpc/mm/book3s64/Makefile |  19 +--
 arch/powerpc/mm/book3s64/hash_native.c| 104 
 arch/powerpc/mm/book3s64/hash_pgtable.c   |   1 -
 arch/powerpc/mm/book3s64/hash_utils.c | 111 +-
 .../{hash_hugetlbpage.c => hugetlbpage.c} |   2 +
 arch/powerpc/mm/book3s64/mmu_context.c|  32 -
 arch/powerpc/mm/book3s64/pgtable.c|  27 +
 arch/powerpc/mm/book3s64/radix_pgtable.c  |   4 +
 arch/powerpc/mm/book3s64/slb.c|  16 ---
 arch/powerpc/mm/book3s64/trace.c  |   8 ++
 arch/powerpc/mm/copro_fault.c |   2 +
 arch/powerpc/mm/fault.c   |  24 
 arch/powerpc/mm/init_64.c |  13 +-
 arch/powerpc/mm/ioremap.c |  20 
 arch/powerpc/mm/nohash/tlb.c  |   9 --
 arch/powerpc/mm/pgtable.c  

Re: [5.16.0-rc2] Kernel warning while running sigfuz w/PPC_IRQ_SOFT_MASK_DEBUG

2021-11-25 Thread Nicholas Piggin
Excerpts from Sachin Sant's message of November 25, 2021 9:37 pm:
> While running sigfuz powerpc self test following warning is seen on a Power 
> 10 LPAR. 
> This warning is seen only with CONFIG_PPC_IRQ_SOFT_MASK_DEBUG=y
> The kernel eventually panics.
> 
> [ 1032.912973] sigfuz[2061671]: bad frame in rt_sigreturn: 97830b2d 
> nip 7fff9d9a0470 lr 7fff9d9a0464
> [ 1032.913430] [ cut here ]
> [ 1032.913455] WARNING: CPU: 6 PID: 2061674 at 
> arch/powerpc/kernel/interrupt_64.S:34 system_call_common+0x150/0x268
> [ 1032.913482] Modules linked in: bonding tls nft_fib_inet nft_fib_ipv4 
> nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject 
> nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set 
> nf_tables rfkill libcrc32c nfnetlink sunrpc xts vmx_crypto pseries_rng 
> ip_tables ext4 mbcache jbd2 dm_service_time sd_mod t10_pi sg ibmvfc 
> scsi_transport_fc ibmveth dm_multipath dm_mirror dm_region_hash dm_log dm_mod 
> fuse
> [ 1032.913587] CPU: 6 PID: 2061674 Comm: sigfuz Not tainted 
> 5.16.0-rc2-g95c6ab13ec7e #1
> [ 1032.913612] NIP:  c000c730 LR: 45faa436 CTR: 
> 
> [ 1032.913636] REGS: cc7e7b70 TRAP: 0700   Not tainted  
> (5.16.0-rc2-g95c6ab13ec7e)
> [ 1032.913652] MSR:  8282b033   CR: 
> 28004474  XER: 2004
> [ 1032.913679] CFAR: c003a2d4 IRQMASK: 0 
> [ 1032.913679] GPR00: c000c6d8 cc7e7e10 2fcdac67 
> 0800 
> [ 1032.913679] GPR04: 60d67006 8280f032 45faa436 
> c001eb3d4c00 
> [ 1032.913679] GPR08: 8280f032 0001 0001 
> 60d67004 
> [ 1032.913679] GPR12: 60d67006 c0077fdf2300  
> 7fff9da0 

SRR0 == r11, regs->nip == r12

I wonder if this is just that SRR0 does not implement the bottom 2 bits 
so the check fails when the signal context sets them. Hopefully the 
panic is just due to this warning 0x700 program check hitting at a bad
time.

We could always adjust the debug check but maybe something like this 
would keep those bits clear which might be cleaner.

Thanks,
Nick

diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 3e053e2fd6b6..92a3a6982813 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -116,7 +116,7 @@ __unsafe_restore_general_regs(struct pt_regs *regs, struct 
mcontext __user *sr)
int i;
 
for (i = 0; i <= PT_RESULT; i++) {
-   if ((i == PT_MSR) || (i == PT_SOFTE))
+   if ((i == PT_NIP) || (i == PT_MSR) || (i == PT_SOFTE))
continue;
unsafe_get_user(gregs[i], >mc_gregs[i], failed);
}
@@ -156,7 +156,7 @@ static __always_inline
 int __unsafe_restore_general_regs(struct pt_regs *regs, struct mcontext __user 
*sr)
 {
/* copy up to but not including MSR */
-   unsafe_copy_from_user(regs, >mc_gregs, PT_MSR * sizeof(elf_greg_t), 
failed);
+   unsafe_copy_from_user(regs, >mc_gregs, PT_NIP * sizeof(elf_greg_t), 
failed);
 
/* copy from orig_r3 (the word after the MSR) up to the end */
unsafe_copy_from_user(>orig_gpr3, >mc_gregs[PT_ORIG_R3],
@@ -458,7 +458,7 @@ static long restore_user_regs(struct pt_regs *regs,
  struct mcontext __user *sr, int sig)
 {
unsigned int save_r2 = 0;
-   unsigned long msr;
+   unsigned long nip, msr;
 #ifdef CONFIG_VSX
int i;
 #endif
@@ -473,6 +473,8 @@ static long restore_user_regs(struct pt_regs *regs,
save_r2 = (unsigned int)regs->gpr[2];
unsafe_restore_general_regs(regs, sr, failed);
set_trap_norestart(regs);
+   unsafe_get_user(nip, >mc_gregs[PT_NIP], failed);
+   regs_set_return_ip(regs, nip & ~3);
unsafe_get_user(msr, >mc_gregs[PT_MSR], failed);
if (!sig)
regs->gpr[2] = (unsigned long) save_r2;
@@ -560,7 +562,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 struct mcontext __user *sr,
 struct mcontext __user *tm_sr)
 {
-   unsigned long msr, msr_hi;
+   unsigned long nip, msr, msr_hi;
int i;
 
if (tm_suspend_disabled)
@@ -576,7 +578,8 @@ static long restore_tm_user_regs(struct pt_regs *regs,
return 1;
 
unsafe_restore_general_regs(>thread.ckpt_regs, sr, failed);
-   unsafe_get_user(current->thread.tm_tfhar, >mc_gregs[PT_NIP], 
failed);
+   unsafe_get_user(nip, >mc_gregs[PT_NIP], failed);
+   current->thread.tm_tfhar = nip & ~3;
unsafe_get_user(msr, >mc_gregs[PT_MSR], failed);
 
/* Restore the previous little-endian mode */
@@ -646,6 +649,9 @@ static long restore_tm_user_regs(struct pt_regs *regs,
current->thread.used_vsr = true;
}
 
+   unsafe_get_user(nip, _sr->mc_gregs[PT_NIP], failed);
+   

Re: [PATCH v2 7/8] cdrom: simplify subdirectory registration with register_sysctl()

2021-11-25 Thread Phillip Potter
On Tue, Nov 23, 2021 at 12:24:21PM -0800, Luis Chamberlain wrote:
> There is no need to user boiler plate code to specify a set of base
> directories we're going to stuff sysctls under. Simplify this by using
> register_sysctl() and specifying the directory path directly.
> 
> // pycocci sysctl-subdir-register-sysctl-simplify.cocci PATH
> 
> @c1@
> expression E1;
> identifier subdir, sysctls;
> @@
> 
> static struct ctl_table subdir[] = {
>   {
>   .procname = E1,
>   .maxlen = 0,
>   .mode = 0555,
>   .child = sysctls,
>   },
>   { }
> };
> 
> @c2@
> identifier c1.subdir;
> 
> expression E2;
> identifier base;
> @@
> 
> static struct ctl_table base[] = {
>   {
>   .procname = E2,
>   .maxlen = 0,
>   .mode = 0555,
>   .child = subdir,
>   },
>   { }
> };
> 
> @c3@
> identifier c2.base;
> identifier header;
> @@
> 
> header = register_sysctl_table(base);
> 
> @r1 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.subdir, c1.sysctls;
> @@
> 
> -static struct ctl_table subdir[] = {
> - {
> - .procname = E1,
> - .maxlen = 0,
> - .mode = 0555,
> - .child = sysctls,
> - },
> - { }
> -};
> 
> @r2 depends on c1 && c2 && c3@
> identifier c1.subdir;
> 
> expression c2.E2;
> identifier c2.base;
> @@
> -static struct ctl_table base[] = {
> - {
> - .procname = E2,
> - .maxlen = 0,
> - .mode = 0555,
> - .child = subdir,
> - },
> - { }
> -};
> 
> @initialize:python@
> @@
> 
> def make_my_fresh_expression(s1, s2):
>   return '"' + s1.strip('"') + "/" + s2.strip('"') + '"'
> 
> @r3 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.sysctls;
> expression c2.E2;
> identifier c2.base;
> identifier c3.header;
> fresh identifier E3 = script:python(E2, E1) { make_my_fresh_expression(E2, 
> E1) };
> @@
> 
> header =
> -register_sysctl_table(base);
> +register_sysctl(E3, sysctls);
> 
> Generated-by: Coccinelle SmPL
> Signed-off-by: Luis Chamberlain 
> ---
>  drivers/cdrom/cdrom.c | 23 +--
>  1 file changed, 1 insertion(+), 22 deletions(-)
> 
> diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> index 9877e413fce3..1b57d4666e43 100644
> --- a/drivers/cdrom/cdrom.c
> +++ b/drivers/cdrom/cdrom.c
> @@ -3691,27 +3691,6 @@ static struct ctl_table cdrom_table[] = {
>   },
>   { }
>  };
> -
> -static struct ctl_table cdrom_cdrom_table[] = {
> - {
> - .procname   = "cdrom",
> - .maxlen = 0,
> - .mode   = 0555,
> - .child  = cdrom_table,
> - },
> - { }
> -};
> -
> -/* Make sure that /proc/sys/dev is there */
> -static struct ctl_table cdrom_root_table[] = {
> - {
> - .procname   = "dev",
> - .maxlen = 0,
> - .mode   = 0555,
> - .child  = cdrom_cdrom_table,
> - },
> - { }
> -};
>  static struct ctl_table_header *cdrom_sysctl_header;
>  
>  static void cdrom_sysctl_register(void)
> @@ -3721,7 +3700,7 @@ static void cdrom_sysctl_register(void)
>   if (!atomic_add_unless(, 1, 1))
>   return;
>  
> - cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
> + cdrom_sysctl_header = register_sysctl("dev/cdrom", cdrom_table);
>  
>   /* set the defaults */
>   cdrom_sysctl_settings.autoclose = autoclose;
> -- 
> 2.33.0
> 

Dear Luis,

Thank you for the patch. Tested and working, looks good to me. As this
has already been pulled into Andrew Morton's tree, I have added in Jens
and the linux-block list so there is awareness that the patch will go
via -mm then linux-next tree.

For what it's worth (although guess it won't be in the commit now):
Reviewed-by: Phillip Potter 

Regards,
Phil


[PATCH] powerpc: Don't bother about .data..Lubsan sections

2021-11-25 Thread Christophe Leroy
Since commit 9a427556fb8e ("vmlinux.lds.h: catch compound literals
into data and BSS") .data..Lubsan sections are taken into account
in DATA_MAIN which is included in DATA_DATA macro.

No need to take care of them anymore in powerpc vmlinux.lds.S

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/vmlinux.lds.S | 8 
 1 file changed, 8 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index 18e42c74abdd..dfc3f39d365f 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -322,10 +322,6 @@ SECTIONS
 #ifdef CONFIG_PPC32
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
-#ifdef CONFIG_UBSAN
-   *(.data..Lubsan_data*)
-   *(.data..Lubsan_type*)
-#endif
*(.data.rel*)
*(SDATA_MAIN)
*(.sdata2)
@@ -336,10 +332,6 @@ SECTIONS
 #else
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
-#ifdef CONFIG_UBSAN
-   *(.data..Lubsan_data*)
-   *(.data..Lubsan_type*)
-#endif
*(.data.rel*)
*(.toc1)
*(.branch_lt)
-- 
2.33.1



Re: [PATCH v2] powerpc64/exceptions: Refactor code to eliminate a few memory loads

2021-11-25 Thread Christophe Leroy




Le 13/11/2017 à 18:04, Naveen N. Rao a écrit :

Michael Ellerman wrote:

"Naveen N. Rao"  writes:


On 2017/06/19 03:21PM, Aneesh Kumar K.V wrote:

@@ -1445,8 +1446,8 @@ do_hash_page:
  handle_page_fault:
andis.  r0,r4,DSISR_DABRMATCH@h
bne-handle_dabr_fault
-   ld  r4,_DAR(r1)
-   ld  r5,_DSISR(r1)
+   mr  r5,r4
+   mr  r4,r3
addir3,r1,STACK_FRAME_OVERHEAD
bl  do_page_fault
cmpdi   r3,0



Can we avoid that if we rearrange args of other functions calls, so that
we can use r3 and r4 as it is ?


Here's a version that does that. Again, boot tested with radix and
disable_radix.

Thanks,
Naveen

-
Change data_access_common() and instruction_access_common() to load the
trap number in r3, DAR in r4 and DSISR in r5 (rather than in r5, r3 and
r4 respectively). This change allows us to eliminate a few un-necessary
memory loads and register move operations in handle_page_fault(),
handle_dabr_fault() and label '77'.

Signed-off-by: Naveen N. Rao 
---
  arch/powerpc/kernel/exceptions-64s.S | 38 +---
  1 file changed, 18 insertions(+), 20 deletions(-)


Sorry I missed this and now it doesn't apply. Do you mind rebasing.


No problem - this is just a small refactoring after all :).
Here's a rebased version.  Boot tested on mambo with/without radix.

Thanks,
Naveen

--
[PATCH v3] powerpc/exceptions64s: Eliminate a few un-necessary memory
loads

Change data_access_common() and instruction_access_common() to load the
trap number in r3, DAR in r4 and DSISR in r5 (rather than in r5, r3 and
r4 respectively). This change allows us to eliminate a few un-necessary
memory loads and register move operations in handle_page_fault(),
handle_dabr_fault() and label '77'.

Signed-off-by: Naveen N. Rao 
---
  arch/powerpc/kernel/exceptions-64s.S | 38 +---
  1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 72cffa0c4af6..b8166b4fa728 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -499,11 +499,11 @@ EXC_COMMON_BEGIN(data_access_common)
EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
RECONCILE_IRQ_STATE(r10, r11)
ld  r12,_MSR(r1)
-   ld  r3,PACA_EXGEN+EX_DAR(r13)
-   lwz r4,PACA_EXGEN+EX_DSISR(r13)
-   li  r5,0x300
-   std r3,_DAR(r1)
-   std r4,_DSISR(r1)
+   ld  r4,PACA_EXGEN+EX_DAR(r13)
+   lwz r5,PACA_EXGEN+EX_DSISR(r13)
+   li  r3,0x300
+   std r4,_DAR(r1)
+   std r5,_DSISR(r1)
  BEGIN_MMU_FTR_SECTION
b   do_hash_page/* Try to handle as hpte fault */
  MMU_FTR_SECTION_ELSE
@@ -543,11 +543,11 @@ EXC_COMMON_BEGIN(instruction_access_common)
EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
RECONCILE_IRQ_STATE(r10, r11)
ld  r12,_MSR(r1)
-   ld  r3,_NIP(r1)
-   andis.  r4,r12,DSISR_BAD_FAULT_64S@h
-   li  r5,0x400
-   std r3,_DAR(r1)
-   std r4,_DSISR(r1)
+   ld  r4,_NIP(r1)
+   andis.  r5,r12,DSISR_BAD_FAULT_64S@h
+   li  r3,0x400
+   std r4,_DAR(r1)
+   std r5,_DSISR(r1)
  BEGIN_MMU_FTR_SECTION
b   do_hash_page/* Try to handle as hpte fault */
  MMU_FTR_SECTION_ELSE
@@ -1523,7 +1523,7 @@ do_hash_page:
  #ifdef CONFIG_PPC_BOOK3S_64
lis r0,DSISR_BAD_FAULT_64S@h
ori r0,r0,DSISR_BAD_FAULT_64S@l
-   and.r0,r4,r0/* weird error? */
+   and.r0,r5,r0/* weird error? */
bne-handle_page_fault   /* if not, try to insert a HPTE */
CURRENT_THREAD_INFO(r11, r1)
lwz r0,TI_PREEMPT(r11)  /* If we're in an "NMI" */
@@ -1538,8 +1538,10 @@ do_hash_page:
 *
 * at return r3 = 0 for success, 1 for page fault, negative for error
 */
+   mr  r6,r5
+   mr  r5,r3
+   mr  r3,r4
  mrr4,r12
-   ld  r6,_DSISR(r1)
bl  __hash_page /* build HPTE if possible */
  cmpdi r3,0/* see if __hash_page succeeded */
  
@@ -1549,16 +1551,15 @@ do_hash_page:

/* Error */
blt-13f
  
-	/* Reload DSISR into r4 for the DABR check below */

-   ld  r4,_DSISR(r1)
+   /* Reload DAR/DSISR for handle_page_fault */
+   ld  r4,_DAR(r1)
+   ld  r5,_DSISR(r1)
  #endif /* CONFIG_PPC_BOOK3S_64 */
  
  /* Here we have a page fault that hash_page can't handle. */

  handle_page_fault:
-11:andis.  r0,r4,DSISR_DABRMATCH@h
+   andis.  r0,r5,DSISR_DABRMATCH@h
bne-handle_dabr_fault
-   ld  r4,_DAR(r1)
-   ld  r5,_DSISR(r1)
addir3,r1,STACK_FRAME_OVERHEAD
bl  do_page_fault
cmpdi   r3,0
@@ -1573,8 +1574,6 @@ handle_page_fault:
  /* We 

Re: [PATCH] powerpc/watchdog: Fix wd_smp_last_reset_tb reporting

2021-11-25 Thread Michael Ellerman
On Thu, 25 Nov 2021 20:33:46 +1000, Nicholas Piggin wrote:
> wd_smp_last_reset_tb now gets reset by watchdog_smp_panic() as part of
> marking CPUs stuck and removing them from the pending mask before it
> begins any printing. This causes last reset times reported to be off.
> 
> Fix this by reading it into a local variable before it gets reset.
> 
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/watchdog: Fix wd_smp_last_reset_tb reporting
  https://git.kernel.org/powerpc/c/3d030e301856da366380b3865fce6c03037b08a6

cheers


Re: [PATCH v2 9/9] powerpc: Simplify and move arch_randomize_brk()

2021-11-25 Thread Christophe Leroy




Le 25/11/2021 à 09:23, Christophe Leroy a écrit :

arch_randomize_brk() is only needed for hash on book3s/64, for other
platforms the one provided by the default mmap layout is good enough.

Move it to hash_utils.c and use randomize_page() like the generic one.

And properly opt out the radix case instead of making an assumption
on mmu_highuser_ssize.

Also change to a 32M range like most other architectures instead of 8M.

Signed-off-by: Christophe Leroy 
---
v2: New
---
  arch/powerpc/kernel/process.c | 40 ---
  arch/powerpc/mm/book3s64/hash_utils.c | 18 
  include/linux/sizes.h |  2 ++
  3 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 406d7ee9e322..f1f2f17543d6 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -2274,43 +2274,3 @@ unsigned long arch_align_stack(unsigned long sp)
sp -= get_random_int() & ~PAGE_MASK;
return sp & ~0xf;
  }
-
-static inline unsigned long brk_rnd(void)
-{
-unsigned long rnd = 0;
-
-   /* 8MB for 32bit, 1GB for 64bit */
-   if (is_32bit_task())
-   rnd = (get_random_long() % (1UL<<(23-PAGE_SHIFT)));
-   else
-   rnd = (get_random_long() % (1UL<<(30-PAGE_SHIFT)));
-
-   return rnd << PAGE_SHIFT;
-}
-
-unsigned long arch_randomize_brk(struct mm_struct *mm)
-{
-   unsigned long base = mm->brk;
-   unsigned long ret;
-
-#ifdef CONFIG_PPC_BOOK3S_64
-   /*
-* If we are using 1TB segments and we are allowed to randomise
-* the heap, we can put it above 1TB so it is backed by a 1TB
-* segment. Otherwise the heap will be in the bottom 1TB
-* which always uses 256MB segments and this may result in a
-* performance penalty. We don't need to worry about radix. For
-* radix, mmu_highuser_ssize remains unchanged from 256MB.
-*/
-   if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
-   base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
-#endif
-
-   ret = PAGE_ALIGN(base + brk_rnd());
-
-   if (ret < mm->brk)
-   return mm->brk;
-
-   return ret;
-}
-
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index 1d09d4aeddbf..3521fad6a479 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -37,6 +37,7 @@
  #include 
  #include 
  #include 
+#include 


Also need  to get the declaration of 
arch_randomize_brk() and make sparse happy :)


Michael can you add it if you apply this version ?

Thanks

  
  #include 

  #include 
@@ -2072,3 +2073,20 @@ void __init print_system_hash_info(void)
if (htab_hash_mask)
pr_info("htab_hash_mask= 0x%lx\n", htab_hash_mask);
  }
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+   /*
+* If we are using 1TB segments and we are allowed to randomise
+* the heap, we can put it above 1TB so it is backed by a 1TB
+* segment. Otherwise the heap will be in the bottom 1TB
+* which always uses 256MB segments and this may result in a
+* performance penalty.
+*/
+   if (is_32bit_task())
+   return randomize_page(mm->brk, SZ_32M);
+   else if (!radix_enabled() && mmu_highuser_ssize == MMU_SEGSIZE_1T)
+   return randomize_page(max_t(unsigned long, mm->brk, SZ_1T), 
SZ_1G);
+   else
+   return randomize_page(mm->brk, SZ_1G);
+}
diff --git a/include/linux/sizes.h b/include/linux/sizes.h
index 1ac79bcee2bb..84aa448d8bb3 100644
--- a/include/linux/sizes.h
+++ b/include/linux/sizes.h
@@ -47,6 +47,8 @@
  #define SZ_8G _AC(0x2, ULL)
  #define SZ_16G_AC(0x4, ULL)
  #define SZ_32G_AC(0x8, ULL)
+
+#define SZ_1T  _AC(0x100, ULL)
  #define SZ_64T_AC(0x4000, ULL)
  
  #endif /* __LINUX_SIZES_H__ */




[PATCH] powerpc/watchdog: Fix wd_smp_last_reset_tb reporting

2021-11-25 Thread Nicholas Piggin
wd_smp_last_reset_tb now gets reset by watchdog_smp_panic() as part of
marking CPUs stuck and removing them from the pending mask before it
begins any printing. This causes last reset times reported to be off.

Fix this by reading it into a local variable before it gets reset.

Fixes: 76521c4b0291 ("powerpc/watchdog: Avoid holding wd_smp_lock over printk 
and smp_send_nmi_ipi")
Signed-off-by: Nicholas Piggin 
---

This is the delta for patches 1-4 between v3 and v4 of the series which
is the result of fixing the bug in patch 3. Sending because v3 got
merged into powerpc next

Thanks,
Nick

 arch/powerpc/kernel/watchdog.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
index b6533539386b..23745af38d62 100644
--- a/arch/powerpc/kernel/watchdog.c
+++ b/arch/powerpc/kernel/watchdog.c
@@ -179,13 +179,14 @@ static void watchdog_smp_panic(int cpu)
 {
static cpumask_t wd_smp_cpus_ipi; // protected by reporting
unsigned long flags;
-   u64 tb;
+   u64 tb, last_reset;
int c;
 
wd_smp_lock();
/* Double check some things under lock */
tb = get_tb();
-   if ((s64)(tb - wd_smp_last_reset_tb) < (s64)wd_smp_panic_timeout_tb)
+   last_reset = wd_smp_last_reset_tb;
+   if ((s64)(tb - last_reset) < (s64)wd_smp_panic_timeout_tb)
goto out;
if (cpumask_test_cpu(cpu, _smp_cpus_pending))
goto out;
@@ -210,8 +211,7 @@ static void watchdog_smp_panic(int cpu)
pr_emerg("CPU %d detected hard LOCKUP on other CPUs %*pbl\n",
 cpu, cpumask_pr_args(_smp_cpus_ipi));
pr_emerg("CPU %d TB:%lld, last SMP heartbeat TB:%lld (%lldms ago)\n",
-cpu, tb, wd_smp_last_reset_tb,
-tb_to_ns(tb - wd_smp_last_reset_tb) / 100);
+cpu, tb, last_reset, tb_to_ns(tb - last_reset) / 100);
 
if (!sysctl_hardlockup_all_cpu_backtrace) {
/*
-- 
2.23.0



Re: [PATCH] powerpc: tsi108: make EXPORT_SYMBOL follow its function immediately

2021-11-25 Thread Michael Ellerman
On Sun, 14 Nov 2021 19:56:16 +0800, Jason Wang wrote:
> EXPORT_SYMBOL(foo); should immediately follow its function/variable.
> 
> 

Applied to powerpc/next.

[1/1] powerpc: tsi108: make EXPORT_SYMBOL follow its function immediately
  https://git.kernel.org/powerpc/c/a3bcfc182b2c968fd740101322bd128844724961

cheers


Re: [PATCH v4 00/53] KVM: PPC: Book3S HV P9: entry/exit optimisations

2021-11-25 Thread Michael Ellerman
On Tue, 23 Nov 2021 19:51:38 +1000, Nicholas Piggin wrote:
> This reduces radix guest full entry/exit latency on POWER9 and POWER10
> by 2x.
> 
> Nested HV guests should see smaller improvements in their L1 entry/exit,
> but this is also combined with most L0 speedups also applying to nested
> entry. nginx localhost throughput test in a SMP nested guest is improved
> about 10% (in a direct guest it doesn't change much because it uses XIVE
> for IPIs) when L0 and L1 are patched.
> 
> [...]

Applied to powerpc/next.

[01/53] powerpc/64s: Remove WORT SPR from POWER9/10 (take 2)

https://git.kernel.org/powerpc/c/f53884b1bf28497e9596cac8b44ef1d41bd6dfc5
[02/53] powerpc/64s: guard optional TIDR SPR with CPU ftr test

https://git.kernel.org/powerpc/c/736df58fd5bcd02f811f7d474bbe02a35ffaa8f0
[03/53] KMV: PPC: Book3S HV P9: Use set_dec to set decrementer to host

https://git.kernel.org/powerpc/c/5955c7469a73033f607ebd6d418058943fe13dd3
[04/53] KVM: PPC: Book3S HV P9: Use host timer accounting to avoid decrementer 
read

https://git.kernel.org/powerpc/c/4ebbd075bcde7884e078d4360510b989f559bfec
[05/53] KVM: PPC: Book3S HV P9: Use large decrementer for HDEC

https://git.kernel.org/powerpc/c/9581991a60817abe311c2581ae4554b28bfa32f1
[06/53] KVM: PPC: Book3S HV P9: Reduce mftb per guest entry/exit

https://git.kernel.org/powerpc/c/34bf08a2079fffc7206a1ae93086ab8167e0afb6
[07/53] powerpc/time: add API for KVM to re-arm the host timer/decrementer

https://git.kernel.org/powerpc/c/25aa145856cd0d94864bf501218be84a7c8062ae
[08/53] KVM: PPC: Book3S HV: POWER10 enable HAIL when running radix guests

https://git.kernel.org/powerpc/c/eacc818864bb01828280f4d64334c4e5ae6a4daf
[09/53] powerpc/64s: Keep AMOR SPR a constant ~0 at runtime

https://git.kernel.org/powerpc/c/46f9caf1a246a5c0622fa8cc7e673658e925f97e
[10/53] KVM: PPC: Book3S HV: Don't always save PMU for guest capable of nesting

https://git.kernel.org/powerpc/c/d3c8a2d3740d93778ea102d4c781746d284177bf
[11/53] powerpc/64s: Always set PMU control registers to frozen/disabled when 
not in use

https://git.kernel.org/powerpc/c/245ebf8e7380b3d84c0aac37fbfd9306b45a3a7a
[12/53] powerpc/64s: Implement PMU override command line option

https://git.kernel.org/powerpc/c/0a4b4327ce867e3ac1b3ad15f4d2b686b516b3a2
[13/53] KVM: PPC: Book3S HV P9: Implement PMU save/restore in C

https://git.kernel.org/powerpc/c/57dc0eed73caa31bfe36ce8fed234e214e37a5ae
[14/53] KVM: PPC: Book3S HV P9: Factor PMU save/load into context switch 
functions

https://git.kernel.org/powerpc/c/401e1ae372673664465d45a86975c006dc6a488d
[15/53] KVM: PPC: Book3S HV P9: Demand fault PMU SPRs when marked not inuse

https://git.kernel.org/powerpc/c/9d3ddb86d96d9f0314f3baaf0e37f987b40d3eee
[16/53] KVM: PPC: Book3S HV P9: Factor out yield_count increment

https://git.kernel.org/powerpc/c/b1adcf57ceca7eab9bfdafc754802e05e634bfcc
[17/53] KVM: PPC: Book3S HV: CTRL SPR does not require read-modify-write

https://git.kernel.org/powerpc/c/a1a19e1154e4e9c6c1136474cb040657b1c17817
[18/53] KVM: PPC: Book3S HV P9: Move SPRG restore to restore_p9_host_os_sprs

https://git.kernel.org/powerpc/c/174a3ab633392859888fc1a5cff278d5546d8474
[19/53] KVM: PPC: Book3S HV P9: Reduce mtmsrd instructions required to save 
host SPRs

https://git.kernel.org/powerpc/c/34e119c96b2b381278d1ddf6b1708678462daba4
[20/53] KVM: PPC: Book3S HV P9: Improve mtmsrd scheduling by delaying MSR[EE] 
disable

https://git.kernel.org/powerpc/c/2251fbe76395e4d89c31099984714c5f1135f052
[21/53] KVM: PPC: Book3S HV P9: Add kvmppc_stop_thread to match 
kvmppc_start_thread

https://git.kernel.org/powerpc/c/cf99dedb4b2d2a18e004b1c84852fffa810dc44c
[22/53] KVM: PPC: Book3S HV: Change dec_expires to be relative to guest timebase

https://git.kernel.org/powerpc/c/3c1a4322bba79aad2d3f6f996b7e1c336bd909b3
[23/53] KVM: PPC: Book3S HV P9: Move TB updates

https://git.kernel.org/powerpc/c/6547af3eba88e4806e853fee7547031b2cc6a560
[24/53] KVM: PPC: Book3S HV P9: Optimise timebase reads

https://git.kernel.org/powerpc/c/cb2553a093093ae46cfaee31321bcedcd0312c5d
[25/53] KVM: PPC: Book3S HV P9: Avoid SPR scoreboard stalls

https://git.kernel.org/powerpc/c/9a1e530bbbdaa2184993a7d7fc61d78871540ccd
[26/53] KVM: PPC: Book3S HV P9: Only execute mtSPR if the value changed

https://git.kernel.org/powerpc/c/9dfe7aa7bc50556063c8658f59ad475131c09b65
[27/53] KVM: PPC: Book3S HV P9: Juggle SPR switching around

https://git.kernel.org/powerpc/c/0f3b6c4851aef7a98b435c6f08b2c9c88165d254
[28/53] KVM: PPC: Book3S HV P9: Move vcpu register save/restore into functions

https://git.kernel.org/powerpc/c/516b334210b831827e0491676625323f484275dd
[29/53] KVM: PPC: Book3S HV P9: Move host OS save/restore functions to built-in


Re: [PATCH v3 0/4] powerpc: watchdog fixes

2021-11-25 Thread Michael Ellerman
On Wed, 10 Nov 2021 12:50:52 +1000, Nicholas Piggin wrote:
> These are some watchdog fixes and improvements, in particular a
> deadlock between the wd_smp_lock and console lock when the watchdog
> fires, found by Laurent.
> 
> Thanks,
> Nick
> 
> [...]

Applied to powerpc/next.

[1/4] powerpc/watchdog: Fix missed watchdog reset due to memory ordering race
  https://git.kernel.org/powerpc/c/5dad4ba68a2483fc80d70b9dc90bbe16e1f27263
[2/4] powerpc/watchdog: tighten non-atomic read-modify-write access
  https://git.kernel.org/powerpc/c/858c93c31504ac1507084493d7eafbe7e2302dc2
[3/4] powerpc/watchdog: Avoid holding wd_smp_lock over printk and 
smp_send_nmi_ipi
  https://git.kernel.org/powerpc/c/76521c4b0291ad25723638ade5a0ff4d5f659771
[4/4] powerpc/watchdog: read TB close to where it is used
  https://git.kernel.org/powerpc/c/1f01bf90765fa5f88fbae452c131c1edf5cda7ba

cheers


Re: [PATCH 0/4] powerpc/security mitigation updates

2021-11-25 Thread Michael Ellerman
On Mon, 3 May 2021 23:02:39 +1000, Nicholas Piggin wrote:
> This series adds a few missing bits added to recent pseries
> H_GET_CPU_CHARACTERISTICS and implements them, also removes
> a restriction from powernv for some of the flushes.
> 
> This is tested mianly in qemu where I just submitted a patch
> that adds support for these bits (not upstream yet).
> 
> [...]

Patch 4 applied to powerpc/next.

[4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess 
flushes
  https://git.kernel.org/powerpc/c/d02fa40d759ff9a53c93b10d8a4b591688982b26

cheers


Re: [PATCH v2 0/2] powerpc/rtas: improved busy and extended delay status handling

2021-11-25 Thread Michael Ellerman
On Wed, 17 Nov 2021 00:02:57 -0600, Nathan Lynch wrote:
> This can be considered a successor to:
> 
> https://lore.kernel.org/linuxppc-dev/20210504030358.1715034-1-nath...@linux.ibm.com/
> 
> which tried to address both the suboptimal delay behavior as well as API
> issues. This version achieves the performance improvements and leaves major
> API changes for another time.
> 
> [...]

Applied to powerpc/next.

[1/2] powerpc/rtas: rtas_busy_delay() improvements
  https://git.kernel.org/powerpc/c/38f7b7067dae0c101be573106018e8af22a90fdf
[2/2] powerpc/rtas: rtas_busy_delay_time() kernel-doc
  https://git.kernel.org/powerpc/c/dd5cde457a5eb77088d1d9eecface47c0563cd43

cheers


Re: [PATCH] powerpc/rtas: kernel-doc fixes

2021-11-25 Thread Michael Ellerman
On Tue, 16 Nov 2021 15:58:06 -0600, Nathan Lynch wrote:
> Fix the following issues reported by kernel-doc:
> 
> $ scripts/kernel-doc -v -none arch/powerpc/kernel/rtas.c
> arch/powerpc/kernel/rtas.c:810: info: Scanning doc for function 
> rtas_activate_firmware
> arch/powerpc/kernel/rtas.c:818: warning: contents before sections
> arch/powerpc/kernel/rtas.c:841: info: Scanning doc for function 
> rtas_call_reentrant
> arch/powerpc/kernel/rtas.c:893: warning: This comment starts with '/**', but 
> isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
>  * Find a specific pseries error log in an RTAS extended event log.
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/rtas: kernel-doc fixes
  https://git.kernel.org/powerpc/c/53cadf7deee0ce65d7c33770b7810c98a2a0ee6a

cheers


Re: [PATCH] powerpc/pseries: delete scanlog

2021-11-25 Thread Michael Ellerman
On Mon, 20 Sep 2021 12:32:03 -0500, Nathan Lynch wrote:
> Remove the pseries scanlog driver.
> 
> This code supports functions from Power4-era servers that are not present
> on targets currently supported by arch/powerpc. System manuals from this
> time have this description:
> 
>   Scan Dump data is a set of chip data that the service processor gathers
>   after a system malfunction. It consists of chip scan rings, chip trace
>   arrays, and Scan COM (SCOM) registers. This data is stored in the
>   scan-log partition of the system’s Nonvolatile Random Access
>   Memory (NVRAM).
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/pseries: delete scanlog
  https://git.kernel.org/powerpc/c/22887f319a39929e357810a1f964fcba7ae42c59

cheers


Re: [PATCH] powerpc/microwatt: Make microwatt_get_random_darn() static

2021-11-25 Thread Michael Ellerman
On Thu, 18 Nov 2021 11:44:15 +1100, Michael Ellerman wrote:
> Make microwatt_get_random_darn() static, because it can be.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/microwatt: Make microwatt_get_random_darn() static
  https://git.kernel.org/powerpc/c/4afc78eae10cd74c5a0b70822b9754d1d094c5d6

cheers


Re: (subset) [PATCH 0/6] add missing of_node_put

2021-11-25 Thread Michael Ellerman
On Fri, 20 Nov 2015 20:33:18 +, Julia Lawall wrote:
> The various for_each device_node iterators performs an of_node_get on each
> iteration, so a break out of the loop requires an of_node_put.
> 
> The complete semantic patch that fixes this problem is
> (http://coccinelle.lip6.fr):
> 
> // 
> @r@
> local idexpression n;
> expression e1,e2;
> iterator name for_each_node_by_name, for_each_node_by_type,
> for_each_compatible_node, for_each_matching_node,
> for_each_matching_node_and_match, for_each_child_of_node,
> for_each_available_child_of_node, for_each_node_with_property;
> iterator i;
> statement S;
> expression list [n1] es;
> @@
> 
> [...]

Patch 5 applied to powerpc/next.

[5/6] powerpc/btext: add missing of_node_put
  https://git.kernel.org/powerpc/c/a1d2b210ffa52d60acabbf7b6af3ef7e1e69cda0

cheers


Re: [PATCH] powerpc/prom_init: fix the improper check of prom_getprop

2021-11-25 Thread Michael Ellerman
On Fri, 19 Nov 2021 17:12:18 +0800, Peiwei Hu wrote:
> prom_getprop() can return PROM_ERROR. Binary operator can not identify it.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/prom_init: fix the improper check of prom_getprop
  https://git.kernel.org/powerpc/c/869fb7e5aecbc163003f93f36dcc26d0554319f6

cheers


Re: [RESEND PATCH v4 0/8] bpf powerpc: Add BPF_PROBE_MEM support in powerpc JIT compiler

2021-11-25 Thread Michael Ellerman
On Tue, 12 Oct 2021 18:00:48 +0530, Hari Bathini wrote:
> Patch #1 & #2 are simple cleanup patches. Patch #3 refactors JIT
> compiler code with the aim to simplify adding BPF_PROBE_MEM support.
> Patch #4 introduces PPC_RAW_BRANCH() macro instead of open coding
> branch instruction. Patch #5 & #7 add BPF_PROBE_MEM support for PPC64
> & PPC32 JIT compilers respectively. Patch #6 & #8 handle bad userspace
> pointers for PPC64 & PPC32 cases respectively.
> 
> [...]

Applied to powerpc/next.

[1/8] bpf powerpc: Remove unused SEEN_STACK
  https://git.kernel.org/powerpc/c/c9ce7c36e4870bd307101ba7a00a39d9aad270f3
[2/8] bpf powerpc: Remove extra_pass from bpf_jit_build_body()
  https://git.kernel.org/powerpc/c/04c04205bc35d0ecdc57146995ca9eb957d4f379
[3/8] bpf powerpc: refactor JIT compiler code
  https://git.kernel.org/powerpc/c/efa95f031bf38c85cf865413335a3dc044e3194e
[4/8] powerpc/ppc-opcode: introduce PPC_RAW_BRANCH() macro
  https://git.kernel.org/powerpc/c/f15a71b3880bf07b40810644e5ac6f177c2a7c8f
[5/8] bpf ppc64: Add BPF_PROBE_MEM support for JIT
  https://git.kernel.org/powerpc/c/983bdc0245a29cdefcd30d9d484d3edbc4b6d787
[6/8] bpf ppc64: Access only if addr is kernel address
  https://git.kernel.org/powerpc/c/9c70c7147ffec31de67d33243570a533b29f9759
[7/8] bpf ppc32: Add BPF_PROBE_MEM support for JIT
  https://git.kernel.org/powerpc/c/23b51916ee129833453d8a3d6bde0ff392f82fce
[8/8] bpf ppc32: Access only if addr is kernel address
  https://git.kernel.org/powerpc/c/e919c0b2323bedec00e1ecc6280498ff81f59b15

cheers


Re: [PATCH 1/2] eeh: Small refactor of eeh_handle_normal_event

2021-11-25 Thread Michael Ellerman
On Fri, 15 Oct 2021 18:06:27 +1100, Daniel Axtens wrote:
> The control flow of eeh_handle_normal_event is a bit tricky.
> 
> Break out one of the error handling paths - rather than be in
> an else block, we'll make it part of the regular body of the
> function and put a 'goto out;' in the true limb of the if.
> 
> 
> [...]

Applied to powerpc/next.

[1/2] eeh: Small refactor of eeh_handle_normal_event
  https://git.kernel.org/powerpc/c/10b34ece132ee46dc4e6459c765d180c422a09fa
[2/2] powerpc/eeh: Use a goto for recovery failures
  https://git.kernel.org/powerpc/c/157616f3c2284f13ca7db9897293f944e6ab8199

cheers


Re: [PATCH 00/11] powerpc/xive: Improve diagnostic and activate StoreEOI on P10 PowerNV

2021-11-25 Thread Michael Ellerman
On Fri, 5 Nov 2021 11:26:25 +0100, Cédric Le Goater wrote:
> This series tries to improve diagnostic support in the XIVE driver. It
> adds pr_debug() primitives that can be activated at run-time and changes
> the debugfs xive entry to expose more information :
> 
>   /sys/kernel/debug/powerpc/xive/
> ├── eqs/
> │   ├── cpu0
> │   ├── cpu1
> │   ├── cpu2
> .   .
> │   └── cpu99
> ├── interrupts
> ├── ipis
> ├── save-restore
> └── store-eoi
> 
> [...]

Patches 1-10 applied to powerpc/next.

[01/11] powerpc/xive: Replace pr_devel() by pr_debug() to ease debug

https://git.kernel.org/powerpc/c/44b9c8ddcbc351d47ead974f0870d09bfc74b3f7
[02/11] powerpc/xive: Introduce an helper to print out interrupt characteristics

https://git.kernel.org/powerpc/c/bd5b00c6cf0c37fce1bcd94390044d7e1dd638e7
[03/11] powerpc/xive: Activate StoreEOI on P10

https://git.kernel.org/powerpc/c/756c52c632f5c2b054bb54b1ea9177329e4b8ce5
[04/11] powerpc/xive: Introduce xive_core_debugfs_create()

https://git.kernel.org/powerpc/c/412877dfae3dc12733bc711ccbd3d02338803865
[05/11] powerpc/xive: Change the debugfs file 'xive' into a directory

https://git.kernel.org/powerpc/c/baed14de78b5ee3ca04eae43c5b16e3eeb6e33a8
[06/11] powerpc/xive: Rename the 'cpus' debugfs file to 'ipis'

https://git.kernel.org/powerpc/c/33e1d4a152ce55272b54a16884461218d12d4f1b
[07/11] powerpc/xive: Add a debugfs file to dump EQs

https://git.kernel.org/powerpc/c/08f3f610214f395561bbda03344e641579f6e917
[08/11] powerpc/xive: Add a debugfs toggle for StoreEOI

https://git.kernel.org/powerpc/c/d7bc1e376cb786e9e8483455584d89cad4b5808f
[09/11] powerpc/xive: Add a kernel parameter for StoreEOI

https://git.kernel.org/powerpc/c/c21ee04f11ae068aa132cce56d09f618d4a66259
[10/11] powerpc/xive: Add a debugfs toggle for save-restore

https://git.kernel.org/powerpc/c/1e7684dc4fc70271c8bf86d397bd4fbfb3581e65

cheers


Re: [PATCH v3] powerpc/code-patching: Improve verification of patchability

2021-11-25 Thread Michael Ellerman
On Mon, 15 Nov 2021 11:12:22 +0100, Christophe Leroy wrote:
> Today, patch_instruction() assumes that it is called exclusively on
> valid addresses, and only checks that it is not called on an init
> address after init section has been freed.
> 
> Improve verification by calling kernel_text_address() instead.
> 
> kernel_text_address() already includes a verification of
> initmem release.
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/code-patching: Improve verification of patchability
  https://git.kernel.org/powerpc/c/8b8a8f0ab3f5519e45c526f826a655817486c5bb

cheers


Re: [PATCH v2 2/8] i915: simplify subdirectory registration with register_sysctl()

2021-11-25 Thread Jani Nikula
On Tue, 23 Nov 2021, Luis Chamberlain  wrote:
> There is no need to user boiler plate code to specify a set of base
> directories we're going to stuff sysctls under. Simplify this by using
> register_sysctl() and specifying the directory path directly.

\o/

Acked-by: Jani Nikula 

>
> // pycocci sysctl-subdir-register-sysctl-simplify.cocci PATH
>
> @c1@
> expression E1;
> identifier subdir, sysctls;
> @@
>
> static struct ctl_table subdir[] = {
>   {
>   .procname = E1,
>   .maxlen = 0,
>   .mode = 0555,
>   .child = sysctls,
>   },
>   { }
> };
>
> @c2@
> identifier c1.subdir;
>
> expression E2;
> identifier base;
> @@
>
> static struct ctl_table base[] = {
>   {
>   .procname = E2,
>   .maxlen = 0,
>   .mode = 0555,
>   .child = subdir,
>   },
>   { }
> };
>
> @c3@
> identifier c2.base;
> identifier header;
> @@
>
> header = register_sysctl_table(base);
>
> @r1 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.subdir, c1.sysctls;
> @@
>
> -static struct ctl_table subdir[] = {
> - {
> - .procname = E1,
> - .maxlen = 0,
> - .mode = 0555,
> - .child = sysctls,
> - },
> - { }
> -};
>
> @r2 depends on c1 && c2 && c3@
> identifier c1.subdir;
>
> expression c2.E2;
> identifier c2.base;
> @@
> -static struct ctl_table base[] = {
> - {
> - .procname = E2,
> - .maxlen = 0,
> - .mode = 0555,
> - .child = subdir,
> - },
> - { }
> -};
>
> @initialize:python@
> @@
>
> def make_my_fresh_expression(s1, s2):
>   return '"' + s1.strip('"') + "/" + s2.strip('"') + '"'
>
> @r3 depends on c1 && c2 && c3@
> expression c1.E1;
> identifier c1.sysctls;
> expression c2.E2;
> identifier c2.base;
> identifier c3.header;
> fresh identifier E3 = script:python(E2, E1) { make_my_fresh_expression(E2, 
> E1) };
> @@
>
> header =
> -register_sysctl_table(base);
> +register_sysctl(E3, sysctls);
>
> Generated-by: Coccinelle SmPL
> Signed-off-by: Luis Chamberlain 
> ---
>  drivers/gpu/drm/i915/i915_perf.c | 22 +-
>  1 file changed, 1 insertion(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_perf.c 
> b/drivers/gpu/drm/i915/i915_perf.c
> index 2f01b8c0284c..5979e3258647 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -4273,26 +4273,6 @@ static struct ctl_table oa_table[] = {
>   {}
>  };
>  
> -static struct ctl_table i915_root[] = {
> - {
> -  .procname = "i915",
> -  .maxlen = 0,
> -  .mode = 0555,
> -  .child = oa_table,
> -  },
> - {}
> -};
> -
> -static struct ctl_table dev_root[] = {
> - {
> -  .procname = "dev",
> -  .maxlen = 0,
> -  .mode = 0555,
> -  .child = i915_root,
> -  },
> - {}
> -};
> -
>  static void oa_init_supported_formats(struct i915_perf *perf)
>  {
>   struct drm_i915_private *i915 = perf->i915;
> @@ -4488,7 +4468,7 @@ static int destroy_config(int id, void *p, void *data)
>  
>  int i915_perf_sysctl_register(void)
>  {
> - sysctl_header = register_sysctl_table(dev_root);
> + sysctl_header = register_sysctl("dev/i915", oa_table);
>   return 0;
>  }

-- 
Jani Nikula, Intel Open Source Graphics Center


Re: [PATCH v1] KVM: PPC: Book3S HV: Prevent POWER7/8 TLB flush flushing SLB

2021-11-25 Thread Michael Ellerman
On Fri, 19 Nov 2021 13:16:27 +1000, Nicholas Piggin wrote:
> The POWER9 ERAT flush instruction is a SLBIA with IH=7, which is a
> reserved value on POWER7/8. On POWER8 this invalidates the SLB entries
> above index 0, similarly to SLBIA IH=0.
> 
> If the SLB entries are invalidated, and then the guest is bypassed, the
> host SLB does not get re-loaded, so the bolted entries above 0 will be
> lost. This can result in kernel stack access causing a SLB fault.
> 
> [...]

Applied to powerpc/fixes.

[1/1] KVM: PPC: Book3S HV: Prevent POWER7/8 TLB flush flushing SLB
  https://git.kernel.org/powerpc/c/cf0b0e3712f7af90006f8317ff27278094c2c128

cheers


Re: [PATCH] powerpc/32: Fix hardlockup on vmap stack overflow

2021-11-25 Thread Michael Ellerman
On Thu, 18 Nov 2021 10:39:53 +0100, Christophe Leroy wrote:
> Since the commit c118c7303ad5 ("powerpc/32: Fix vmap stack - Do not
> activate MMU before reading task struct") a vmap stack overflow
> results in a hard lockup. This is because emergency_ctx is still
> addressed with its virtual address allthough data MMU is not active
> anymore at that time.
> 
> Fix it by using a physical address instead.
> 
> [...]

Applied to powerpc/fixes.

[1/1] powerpc/32: Fix hardlockup on vmap stack overflow
  https://git.kernel.org/powerpc/c/5bb60ea611db1e04814426ed4bd1c95d1487678e

cheers


  1   2   >