Re: [PATCH 3/4] exec: simplify the compat syscall handling

2021-03-26 Thread Eric W. Biederman
Christoph Hellwig  writes:


> diff --git a/fs/exec.c b/fs/exec.c
> index 06e07278b456fa..b34c1eb9e7ad8e 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -391,47 +391,34 @@ static int bprm_mm_init(struct linux_binprm *bprm)
>   return err;
>  }
>  
> -struct user_arg_ptr {
> -#ifdef CONFIG_COMPAT
> - bool is_compat;
> -#endif
> - union {
> - const char __user *const __user *native;
> -#ifdef CONFIG_COMPAT
> - const compat_uptr_t __user *compat;
> -#endif
> - } ptr;
> -};
> -
> -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
> +static const char __user *
> +get_user_arg_ptr(const char __user *const __user *argv, int nr)
>  {
> - const char __user *native;
> -
> -#ifdef CONFIG_COMPAT
> - if (unlikely(argv.is_compat)) {
> + if (in_compat_syscall()) {
> + const compat_uptr_t __user *compat_argv =
> + compat_ptr((unsigned long)argv);

Ouch!  Passing a pointer around as the wrong type through the kernel!

Perhaps we should reduce everything to do_execveat and
do_execveat_compat.  Then there would be no need for anything
to do anything odd with the pointer types.

I think the big change would be to factor out a copy_string out
of copy_strings, that performs all of the work once we know the proper
pointer value.

Casting pointers from one type to another scares me as one mistake means
we are doing something wrong and probably exploitable.


Eric




>   compat_uptr_t compat;
>  
> - if (get_user(compat, argv.ptr.compat + nr))
> + if (get_user(compat, compat_argv + nr))
>   return ERR_PTR(-EFAULT);
> -
>   return compat_ptr(compat);
> - }
> -#endif
> -
> - if (get_user(native, argv.ptr.native + nr))
> - return ERR_PTR(-EFAULT);
> + } else {
> + const char __user *native;
>  
> - return native;
> + if (get_user(native, argv + nr))
> + return ERR_PTR(-EFAULT);
> + return native;
> + }
>  }
>  


Re: [PATCH V2 3/5] tools/perf: Add powerpc support for PERF_SAMPLE_WEIGHT_STRUCT

2021-03-26 Thread Athira Rajeev
On 25-Mar-2021, at 1:13 AM, Jiri Olsa  wrote:On Mon, Mar 22, 2021 at 10:57:25AM -0400, Athira Rajeev wrote:Add arch specific arch_evsel__set_sample_weight() to set the newsample type for powerpc.Add arch specific arch_perf_parse_sample_weight() to store thesample->weight values depending on the sample type applied.if the new sample type (PERF_SAMPLE_WEIGHT_STRUCT) is applied,store only the lower 32 bits to sample->weight. If sample typeis 'PERF_SAMPLE_WEIGHT', store the full 64-bit to sample->weight.Signed-off-by: Athira Rajeev ---tools/perf/arch/powerpc/util/Build   |  2 ++tools/perf/arch/powerpc/util/event.c | 32 tools/perf/arch/powerpc/util/evsel.c |  8 3 files changed, 42 insertions(+)create mode 100644 tools/perf/arch/powerpc/util/event.ccreate mode 100644 tools/perf/arch/powerpc/util/evsel.cdiff --git a/tools/perf/arch/powerpc/util/Build b/tools/perf/arch/powerpc/util/Buildindex b7945e5a543b..8a79c4126e5b 100644--- a/tools/perf/arch/powerpc/util/Build+++ b/tools/perf/arch/powerpc/util/Build@@ -4,6 +4,8 @@ perf-y += kvm-stat.operf-y += perf_regs.operf-y += mem-events.operf-y += sym-handling.o+perf-y += evsel.o+perf-y += event.operf-$(CONFIG_DWARF) += dwarf-regs.operf-$(CONFIG_DWARF) += skip-callchain-idx.odiff --git a/tools/perf/arch/powerpc/util/event.c b/tools/perf/arch/powerpc/util/event.cnew file mode 100644index ..f49d32c2c8ae--- /dev/null+++ b/tools/perf/arch/powerpc/util/event.c@@ -0,0 +1,32 @@+// SPDX-License-Identifier: GPL-2.0+#include +#include +#include ++#include "../../../util/event.h"+#include "../../../util/synthetic-events.h"+#include "../../../util/machine.h"+#include "../../../util/tool.h"+#include "../../../util/map.h"+#include "../../../util/debug.h"nit, just #include "utils/...h" should work no?other than that, the patchset looks ok to meAcked-by: Jiri Olsa Hi Jiri, ArnaldoThanks for reviewing the patch set.I checked that, just using "utils/...h" also works.Below is the change which I verified. Since the patches are presently merged in https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf/core, can you please suggest how can we go about this change ?diff --git a/tools/perf/arch/powerpc/util/event.c b/tools/perf/arch/powerpc/util/event.cindex 3bf441257466..c479d0a0e696 100644--- a/tools/perf/arch/powerpc/util/event.c+++ b/tools/perf/arch/powerpc/util/event.c@@ -3,12 +3,12 @@ #include  #include -#include "../../../util/event.h"-#include "../../../util/synthetic-events.h"-#include "../../../util/machine.h"-#include "../../../util/tool.h"-#include "../../../util/map.h"-#include "../../../util/debug.h"+#include "util/event.h"+#include "util/synthetic-events.h"+#include "util/machine.h"+#include "util/tool.h"+#include "util/map.h"+#include "util/debug.h" void arch_perf_parse_sample_weight(struct perf_sample *data,    const __u64 *array, u64 type)ThanksAthirathanks,jirka++void arch_perf_parse_sample_weight(struct perf_sample *data,+   const __u64 *array, u64 type)+{+	union perf_sample_weight weight;++	weight.full = *array;+	if (type & PERF_SAMPLE_WEIGHT)+		data->weight = weight.full;+	else+		data->weight = weight.var1_dw;+}++void arch_perf_synthesize_sample_weight(const struct perf_sample *data,+	__u64 *array, u64 type)+{+	*array = data->weight;++	if (type & PERF_SAMPLE_WEIGHT_STRUCT)+		*array &= 0x;+}diff --git a/tools/perf/arch/powerpc/util/evsel.c b/tools/perf/arch/powerpc/util/evsel.cnew file mode 100644index ..2f733cdc8dbb--- /dev/null+++ b/tools/perf/arch/powerpc/util/evsel.c@@ -0,0 +1,8 @@+// SPDX-License-Identifier: GPL-2.0+#include +#include "util/evsel.h"++void arch_evsel__set_sample_weight(struct evsel *evsel)+{+	evsel__set_sample_bit(evsel, WEIGHT_STRUCT);+}-- 1.8.3.1

Re: [PATCH] powerpc/mm/book3s64: Use the correct storage key value when calling H_PROTECT

2021-03-26 Thread Murilo Opsfelder Araújo
On Friday, March 26, 2021 4:07:55 AM -03 Aneesh Kumar K.V wrote:
> H_PROTECT expect the flag value to include
> flags: AVPN, pp0, pp1, pp2, key0-key4, Noexec, CMO Option flags
>
> This patch updates hpte_updatepp() to fetch the storage key value from the
> linux page table and use the same in H_PROTECT hcall.
>
> native_hpte_updatepp() is not updated because the kernel doesn't clear the
> existing storage key value there. The kernel also doesn't use
> hpte_updatepp() callback for updating storage keys.
>
> This fixes the below kernel crash observed with KUAP enabled.
>
>  BUG: Unable to handle kernel data access on write at 0xc009fc44
>  Faulting instruction address: 0xc00b7030
>  Key fault AMR: 0xfcff IAMR: 0xc077bc498100
>  Found HPTE: v = 0x40070adbb6fffc05 r = 0x1ff1194
>  Oops: Kernel access of bad area, sig: 11 [#1]
>  LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
> .
>  CFAR: c0010100 DAR: c009fc44 DSISR: 0220 IRQMASK: 0
> ..
>  NIP [c00b7030] memset+0x68/0x104
>  LR [c03ef00c] pcpu_alloc+0x54c/0xb50
>  Call Trace:
>  [c0001c7534f0] [c03ef01c] pcpu_alloc+0x55c/0xb50 (unreliable)
>  [c0001c753600] [c08bb214] blk_stat_alloc_callback+0x94/0x150
>  [c0001c753650] [c08b7a04]
> blk_mq_init_allocated_queue+0x64/0x560 [c0001c7536b0]
> [c08b8024] blk_mq_init_queue+0x54/0xb0 [c0001c7536e0]
> [c0b87650] scsi_mq_alloc_queue+0x30/0xa0 [c0001c753710]
> [c0b88b2c] scsi_alloc_sdev+0x1cc/0x300 [c0001c7537b0]
> [c0b897b0] scsi_probe_and_add_lun+0xb50/0x1020 [c0001c753950]
> [c0b8a35c] __scsi_scan_target+0x17c/0x790 [c0001c753a80]
> [c0b8ab90] scsi_scan_channel+0x90/0xe0 [c0001c753ad0]
> [c0b8ae48] scsi_scan_host_selected+0x148/0x1f0 [c0001c753b60]
> [c0b8b31c] do_scan_async+0x2c/0x2a0
>  [c0001c753be0] [c0187a18] async_run_entry_fn+0x78/0x220
>  [c0001c753c70] [c0176a74] process_one_work+0x264/0x540
>  [c0001c753d10] [c0177338] worker_thread+0xa8/0x600
>  [c0001c753da0] [c01807b0] kthread+0x190/0x1a0
>  [c0001c753e10] [c000d8f0] ret_from_kernel_thread+0x5c/0x6c
>
> With KUAP enabled the kernel uses storage key 3 for all its translations.
> But as shown by the debug print, in this specific case we have the hash
> page table entry created with key value 0.
>
> [2.249497] Found HPTE: v = 0x40070adbb6fffc05 r = 0x1ff1194
>
> and DSISR indicates a key fault.
>
> This can happen due to parallel fault on the same EA by different CPUs
>
> CPU 0 CPU 1
> fault on X
>
> H_PAGE_BUSY set
>   fault on X
>
> finish fault handling and
> clear H_PAGE_BUSY
>   check for H_PAGE_BUSY
>   continue with fault 
handling.
>
> This implies CPU1 will end up calling hpte_updatepp for address X
> and the kernel updated the hash pte entry with key 0
>
> Fixes: d94b827e89dc ("powerpc/book3s64/kuap: Use Key 3 for kernel mapping
> with hash translation")
>
> Debugged-by: Michael Ellerman 
> Reported-by: Murilo Opsfelder Araujo 
> Signed-off-by: Aneesh Kumar K.V 
> ---

I've tested this on top of commit db24726bfefa68c606947a86132591568a06bfb4
("Merge tag 'integrity-v5.12-fix' of git://git.kernel.org/pub/scm/linux/
kernel/git/zohar/linux-integrity"),
and the reported issue did not manifest.

Thank you, Michael and Aneesh, for the help.

Tested-by: Murilo Opsfelder Araujo 

--
Murilo



Re: VDSO ELF header

2021-03-26 Thread Dmitry Safonov
On 3/26/21 6:40 PM, Christophe Leroy wrote:
> 
> 
> Le 26/03/2021 à 18:11, Dmitry Safonov a écrit :
>> On 3/26/21 5:07 PM, Christophe Leroy wrote:
>>> No, the problem is that user access has to be allowed for the flush()
>>>
>>> A hacky solution would be to call user_access_begin() , will test that
>>> later
>>
>> Yeah, cool.
>>
>> Will it be fine if I send the vvar patch with your Tested-by?
>>
> 
> Tested-by: Christophe Leroy 

Thank you!
I'll properly submit it shortly..

> With the user access fixed on the flush, it sigreturn_vdso selftest is a
> success. I'll send a patch for it in the coming days.

Nice!

> What is the status of your series which adds generic vdso_base tracking ?

Yeah, I was doing a new version of patches and I always was unsatisfied
by the result and stuck between "good" and "best" (more code rewriting).
And then had some other work to finish.

I'll try to finish and send it next week, thanks for pinging :-)

--
   Dmitry


Re: VDSO ELF header

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 18:11, Dmitry Safonov a écrit :

On 3/26/21 5:07 PM, Christophe Leroy wrote:

No, the problem is that user access has to be allowed for the flush()

A hacky solution would be to call user_access_begin() , will test that
later


Yeah, cool.

Will it be fine if I send the vvar patch with your Tested-by?



Tested-by: Christophe Leroy 

With the user access fixed on the flush, it sigreturn_vdso selftest is a success. I'll send a patch 
for it in the coming days.


What is the status of your series which adds generic vdso_base tracking ?

Christophe


Re: [PATCH v3 05/17] arm: Convert to GENERIC_CMDLINE

2021-03-26 Thread Rob Herring
+Nico who added the line in question.

On Fri, Mar 26, 2021 at 9:50 AM Christophe Leroy
 wrote:
>
>
>
> Le 26/03/2021 à 16:47, Rob Herring a écrit :
> > On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
> >  wrote:
> >>
> >> This converts the architecture to GENERIC_CMDLINE.
> >>
> >> Signed-off-by: Christophe Leroy 
> >> ---
> >>   arch/arm/Kconfig  | 38 +--
> >>   arch/arm/kernel/atags_parse.c | 15 +-
> >>   2 files changed, 6 insertions(+), 47 deletions(-)
> >>
> >> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> >> index 5da96f5df48f..67bc75f2da81 100644
> >> --- a/arch/arm/Kconfig
> >> +++ b/arch/arm/Kconfig
> >> @@ -50,6 +50,7 @@ config ARM
> >>  select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
> >>  select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || 
> >> !AEABI
> >>  select GENERIC_CLOCKEVENTS_BROADCAST if SMP
> >> +   select GENERIC_CMDLINE if ATAGS
> >
> > Don't we need this enabled for !ATAGS (i.e. DT boot)?
> >
> > Can we always enable GENERIC_CMDLINE for OF_EARLY_FLATTREE?
> >
>
> Don't know.
>
> Today ARM has:
>
> choice
> prompt "Kernel command line type" if CMDLINE != ""
> default CMDLINE_FROM_BOOTLOADER
> depends on ATAGS

I think that's a mistake. In a DT only case (no ATAGS), we'll get
different behaviour (in fdt.c) depending if CONFIG_ATAGS is enabled or
not. Note that at the time (2012) the above was added, the DT code
only supported CONFIG_CMDLINE and CONFIG_CMDLINE_FORCE.
CONFIG_CMDLINE_EXTEND was only added in 2016. And that has different
behavior for ATAGS vs. DT. In summary, it's a mess. We should drop the
depends either before this patch or just as part of this patch IMO.
I'd go with the latter given CONFIG_ATAGS is default y and enabled for
common configs. Without that, it looks like CONFIG_CMDLINE disappears
from menuconfig for at91_dt_defconfig.

Also, I think this code should be refactored a bit to eliminate
default_command_line. Instead, we should just save a pointer to the
ATAGS command line string, and then call cmdline_build here instead of
doing the extra copy:

/* parse_early_param needs a boot_command_line */
strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);

Rob


Re: [PATCH v2 0/8] Implement EBPF on powerpc32

2021-03-26 Thread Andrii Nakryiko
On Fri, Mar 26, 2021 at 7:42 AM Christophe Leroy
 wrote:
>
>
>
> Le 22/03/2021 à 18:53, Andrii Nakryiko a écrit :
> > On Mon, Mar 22, 2021 at 9:37 AM Christophe Leroy
> >  wrote:
> >>
> >> This series implements extended BPF on powerpc32. For the implementation
> >> details, see the patch before the last.
> >>
> >> The following operations are not implemented:
> >>
> >>  case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */
> >>  case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */
> >>  case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) 
> >> += src */
> >>
> >> The following operations are only implemented for power of two constants:
> >>
> >>  case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */
> >>  case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */
> >>
> >> Below are the results on a powerpc 885:
> >> - with the patch, with and without bpf_jit_enable
> >> - without the patch, with bpf_jit_enable (ie with CBPF)
> >>
> >> With the patch, with bpf_jit_enable = 1 :
> >>
> >> [   60.826529] test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]
> >> [   60.832505] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED
> >>
> >> With the patch, with bpf_jit_enable = 0 :
> >>
> >> [   75.186337] test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]
> >> [   75.192325] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED
> >>
> >> Without the patch, with bpf_jit_enable = 1 :
> >>
> >> [  186.112429] test_bpf: Summary: 371 PASSED, 7 FAILED, [119/366 JIT'ed]
> >>
> >> Couldn't run test_progs because it doesn't build (clang 11 crashes during 
> >> the build).
> >
> > Can you please try checking out the latest clang from sources and use
> > that one instead?
>
> The crash is fixed, it builds one step more, then fails at:
>
> [root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool
>  gen skeleton
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o >
> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h
> libbpf: elf: endianness mismatch in atomic_bounds.
> Error: failed to open BPF object file: Endian mismatch
>
> I'm cross-building on x86 for powerpc/32

yeah, I'm not sure selftests/bpf supports cross-compiling. bpftool got
some patches recently to enable cross-compiling, but probably not
selftests/bpf.

>
> [root@PC-server-ldb bpf]# file atomic_bounds.o
> atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with 
> debug_info, not stripped
>
> Christophe


Re: VDSO ELF header

2021-03-26 Thread Dmitry Safonov
On 3/26/21 5:07 PM, Christophe Leroy wrote:
> No, the problem is that user access has to be allowed for the flush()
> 
> A hacky solution would be to call user_access_begin() , will test that
> later

Yeah, cool.

Will it be fine if I send the vvar patch with your Tested-by?

Thanks,
Dmitry


Re: VDSO ELF header

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 17:32, Dmitry Safonov a écrit :

On 3/26/21 4:11 PM, Christophe Leroy wrote:
[..]


Dmitry proposed the same, see
https://github.com/0x7f454c46/linux/commit/783c7a2532d2219edbcf555cc540eab05f698d2a



Discussion at https://github.com/checkpoint-restore/criu/issues/1417


Yeah, I didn't submit it officially to lkml because I couldn't test it
yet (and I usually don't send untested patches). The VM I have fails to
kexec and there's some difficulty to get serial console working, so I'd
appreciate if someone could either pick it up, or add tested-by.



Just to let everyone know, while testing your patch with selftest I
encountered the following Oops. But I also have it without your patch
thought.


Thank you, Christophe!



root@vgoip:~# ./sigreturn_vdso
test: sigreturn_vdso
tags: git_version:v5.12-rc4-1553-gc31141d460e6
VDSO is at 0x104000-0x10bfff (32768 bytes)
Signal delivered OK with VDSO mapped
VDSO moved to 0x77bf4000-0x77bfbfff (32768 bytes)
Signal delivered OK with VDSO moved
Unmapped VDSO
[ 1855.444371] Kernel attempted to read user page (7ff9ff30) - exploit
attempt? (uid: 0)
[ 1855.459404] BUG: Unable to handle kernel data access on read at
0x7ff9ff30
[ 1855.466188] Faulting instruction address: 0xc00111d4
[ 1855.471099] Oops: Kernel access of bad area, sig: 11 [#1]
[ 1855.476428] BE PAGE_SIZE=16K PREEMPT CMPC885
[ 1855.480702] SAF3000 DIE NOTIFICATION
[ 1855.484184] CPU: 0 PID: 362 Comm: sigreturn_vdso Not tainted
5.12.0-rc4-s3k-dev-01553-gc31141d460e6 #4811
[ 1855.493644] NIP:  c00111d4 LR: c0005a28 CTR: 
[ 1855.498634] REGS: cadb3dd0 TRAP: 0300   Not tainted
(5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
[ 1855.507068] MSR:  9032   CR: 48000884  XER: 2000
[ 1855.513866] DAR: 7ff9ff30 DSISR: 8800
[ 1855.513866] GPR00: c0007788 cadb3e90 c28dc000 7ff9ff30 7ff9ff40
04e0 7ff9fd50 
[ 1855.513866] GPR08: 0001 0001 7ff9ff30  28000282
1001b7e8 100a0920 
[ 1855.513866] GPR16: 100cac0c 100b 102883a4 10289685 100d
100d 100d 100b2e9e
[ 1855.513866] GPR24:  102883c8  7ff9ff38 cadb3f40
cadb3ec8 c28dc000 
[ 1855.552767] NIP [c00111d4] flush_icache_range+0x90/0xb4
[ 1855.557932] LR [c0005a28] handle_signal32+0x1bc/0x1c4
[ 1855.562925] Call Trace:
[ 1855.565332] [cadb3e90] [100d] 0x100d (unreliable)
[ 1855.570666] [cadb3ec0] [c0007788] do_notify_resume+0x260/0x314
[ 1855.576432] [cadb3f20] [c000c764] syscall_exit_prepare+0x120/0x184
[ 1855.582542] [cadb3f30] [c00100b4] ret_from_syscall+0xc/0x28
[ 1855.588050] --- interrupt: c00 at 0xfe807f8
[ 1855.592183] NIP:  0fe807f8 LR: 10001048 CTR: c0139378
[ 1855.597174] REGS: cadb3f40 TRAP: 0c00   Not tainted
(5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
[ 1855.605607] MSR:  d032   CR: 28000282  XER:
2000
[ 1855.612664]
[ 1855.612664] GPR00: 0025 7ffa0230 77c09690  000a
28000282 0001 0ff03a38
[ 1855.612664] GPR08: d032 0328 c28dc000 0009 88000282
1001b7e8 100a0920 
[ 1855.612664] GPR16: 100cac0c 100b 102883a4 10289685 100d
100d 100d 100b2e9e
[ 1855.612664] GPR24:  102883c8  77bff628 10002358
1001 1000210c 8000
[ 1855.648894] NIP [0fe807f8] 0xfe807f8
[ 1855.652426] LR [10001048] 0x10001048
[ 1855.655954] --- interrupt: c00
[ 1855.658969] Instruction dump:
[ 1855.661893] 38630010 7c001fac 38630010 4200fff0 7c0004ac 4c00012c
4e800020 7c001fac
[ 1855.669811] 2c0a 38630010 4082ffcc 4be4 <7c00186c> 2c07
39430010 4082ff8c
[ 1855.677910] ---[ end trace f071a5587092b3aa ]---
[ 1855.682462]
Remapped the stack executable
!! child died by signal 11
failure: sigreturn_vdso


Yes, it seems unrelated.
Probably, a bit hacky solution to this one could be:

--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -911,7 +911,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t
*oldset,
 }
 user_write_access_end();

-   if (tramp == (unsigned long)mctx->mc_pad)
+   if ((tramp == (unsigned long)mctx->mc_pad) && access_ok(tramp,
2*sizeof(unsigned long)))
 flush_icache_range(tramp, tramp + 2 * sizeof(unsigned
long));

 regs->link = tramp;
--

But it's up to you, it seems power-related.




No, the problem is that user access has to be allowed for the flush()

A hacky solution would be to call user_access_begin() , will test that later


Christophe


RE: [PATCH 3/4] exec: simplify the compat syscall handling

2021-03-26 Thread David Laight
From: Al Viro
> Sent: 26 March 2021 16:12
> 
> On Fri, Mar 26, 2021 at 03:38:30PM +0100, Christoph Hellwig wrote:
> 
> > +static const char __user *
> > +get_user_arg_ptr(const char __user *const __user *argv, int nr)
> >  {
> > +   if (in_compat_syscall()) {
> > +   const compat_uptr_t __user *compat_argv =
> > +   compat_ptr((unsigned long)argv);
> > compat_uptr_t compat;
> >
> > +   if (get_user(compat, compat_argv + nr))
> > return ERR_PTR(-EFAULT);
> > return compat_ptr(compat);
> > +   } else {
> > +   const char __user *native;
> >
> > +   if (get_user(native, argv + nr))
> > +   return ERR_PTR(-EFAULT);
> > +   return native;
> > +   }
> >  }
> 
> Yecchhh  So you have in_compat_syscall() called again and again, for
> each argument in the list?  I agree that current version is fucking ugly,
> but I really hate that approach ;-/

Especially since in_compat_syscall() isn't entirely trivial on x86-64.
Probably all in the noise for 'exec', but all the bits do add up.

You may not want separate get_user() on some architectures either.
The user_access_begin/end aren't cheap.

OTOH if you call copy_from_user() you get hit by the stupid
additional costs of 'user copy hardening'.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)



Re: VDSO ELF header

2021-03-26 Thread Dmitry Safonov
On 3/26/21 4:11 PM, Christophe Leroy wrote:
[..]
>>>
>>> Dmitry proposed the same, see
>>> https://github.com/0x7f454c46/linux/commit/783c7a2532d2219edbcf555cc540eab05f698d2a
>>>
>>>
>>>
>>> Discussion at https://github.com/checkpoint-restore/criu/issues/1417
>>
>> Yeah, I didn't submit it officially to lkml because I couldn't test it
>> yet (and I usually don't send untested patches). The VM I have fails to
>> kexec and there's some difficulty to get serial console working, so I'd
>> appreciate if someone could either pick it up, or add tested-by.
>>
> 
> Just to let everyone know, while testing your patch with selftest I
> encountered the following Oops. But I also have it without your patch
> thought.

Thank you, Christophe!

> 
> root@vgoip:~# ./sigreturn_vdso
> test: sigreturn_vdso
> tags: git_version:v5.12-rc4-1553-gc31141d460e6
> VDSO is at 0x104000-0x10bfff (32768 bytes)
> Signal delivered OK with VDSO mapped
> VDSO moved to 0x77bf4000-0x77bfbfff (32768 bytes)
> Signal delivered OK with VDSO moved
> Unmapped VDSO
> [ 1855.444371] Kernel attempted to read user page (7ff9ff30) - exploit
> attempt? (uid: 0)
> [ 1855.459404] BUG: Unable to handle kernel data access on read at
> 0x7ff9ff30
> [ 1855.466188] Faulting instruction address: 0xc00111d4
> [ 1855.471099] Oops: Kernel access of bad area, sig: 11 [#1]
> [ 1855.476428] BE PAGE_SIZE=16K PREEMPT CMPC885
> [ 1855.480702] SAF3000 DIE NOTIFICATION
> [ 1855.484184] CPU: 0 PID: 362 Comm: sigreturn_vdso Not tainted
> 5.12.0-rc4-s3k-dev-01553-gc31141d460e6 #4811
> [ 1855.493644] NIP:  c00111d4 LR: c0005a28 CTR: 
> [ 1855.498634] REGS: cadb3dd0 TRAP: 0300   Not tainted 
> (5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
> [ 1855.507068] MSR:  9032   CR: 48000884  XER: 2000
> [ 1855.513866] DAR: 7ff9ff30 DSISR: 8800
> [ 1855.513866] GPR00: c0007788 cadb3e90 c28dc000 7ff9ff30 7ff9ff40
> 04e0 7ff9fd50 
> [ 1855.513866] GPR08: 0001 0001 7ff9ff30  28000282
> 1001b7e8 100a0920 
> [ 1855.513866] GPR16: 100cac0c 100b 102883a4 10289685 100d
> 100d 100d 100b2e9e
> [ 1855.513866] GPR24:  102883c8  7ff9ff38 cadb3f40
> cadb3ec8 c28dc000 
> [ 1855.552767] NIP [c00111d4] flush_icache_range+0x90/0xb4
> [ 1855.557932] LR [c0005a28] handle_signal32+0x1bc/0x1c4
> [ 1855.562925] Call Trace:
> [ 1855.565332] [cadb3e90] [100d] 0x100d (unreliable)
> [ 1855.570666] [cadb3ec0] [c0007788] do_notify_resume+0x260/0x314
> [ 1855.576432] [cadb3f20] [c000c764] syscall_exit_prepare+0x120/0x184
> [ 1855.582542] [cadb3f30] [c00100b4] ret_from_syscall+0xc/0x28
> [ 1855.588050] --- interrupt: c00 at 0xfe807f8
> [ 1855.592183] NIP:  0fe807f8 LR: 10001048 CTR: c0139378
> [ 1855.597174] REGS: cadb3f40 TRAP: 0c00   Not tainted 
> (5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
> [ 1855.605607] MSR:  d032   CR: 28000282  XER:
> 2000
> [ 1855.612664]
> [ 1855.612664] GPR00: 0025 7ffa0230 77c09690  000a
> 28000282 0001 0ff03a38
> [ 1855.612664] GPR08: d032 0328 c28dc000 0009 88000282
> 1001b7e8 100a0920 
> [ 1855.612664] GPR16: 100cac0c 100b 102883a4 10289685 100d
> 100d 100d 100b2e9e
> [ 1855.612664] GPR24:  102883c8  77bff628 10002358
> 1001 1000210c 8000
> [ 1855.648894] NIP [0fe807f8] 0xfe807f8
> [ 1855.652426] LR [10001048] 0x10001048
> [ 1855.655954] --- interrupt: c00
> [ 1855.658969] Instruction dump:
> [ 1855.661893] 38630010 7c001fac 38630010 4200fff0 7c0004ac 4c00012c
> 4e800020 7c001fac
> [ 1855.669811] 2c0a 38630010 4082ffcc 4be4 <7c00186c> 2c07
> 39430010 4082ff8c
> [ 1855.677910] ---[ end trace f071a5587092b3aa ]---
> [ 1855.682462]
> Remapped the stack executable
> !! child died by signal 11
> failure: sigreturn_vdso

Yes, it seems unrelated.
Probably, a bit hacky solution to this one could be:

--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -911,7 +911,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t
*oldset,
}
user_write_access_end();

-   if (tramp == (unsigned long)mctx->mc_pad)
+   if ((tramp == (unsigned long)mctx->mc_pad) && access_ok(tramp,
2*sizeof(unsigned long)))
flush_icache_range(tramp, tramp + 2 * sizeof(unsigned
long));

regs->link = tramp;
--

But it's up to you, it seems power-related.

Thanks,
Dmitry


Re: [PATCH 3/4] exec: simplify the compat syscall handling

2021-03-26 Thread Al Viro
On Fri, Mar 26, 2021 at 03:38:30PM +0100, Christoph Hellwig wrote:

> -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
> +static const char __user *
> +get_user_arg_ptr(const char __user *const __user *argv, int nr)
>  {
> - const char __user *native;
> -
> -#ifdef CONFIG_COMPAT
> - if (unlikely(argv.is_compat)) {
> + if (in_compat_syscall()) {
> + const compat_uptr_t __user *compat_argv =
> + compat_ptr((unsigned long)argv);
>   compat_uptr_t compat;
>  
> - if (get_user(compat, argv.ptr.compat + nr))
> + if (get_user(compat, compat_argv + nr))
>   return ERR_PTR(-EFAULT);
> -
>   return compat_ptr(compat);
> - }
> -#endif
> -
> - if (get_user(native, argv.ptr.native + nr))
> - return ERR_PTR(-EFAULT);
> + } else {
> + const char __user *native;
>  
> - return native;
> + if (get_user(native, argv + nr))
> + return ERR_PTR(-EFAULT);
> + return native;
> + }
>  }

Yecchhh  So you have in_compat_syscall() called again and again, for
each argument in the list?  I agree that current version is fucking ugly,
but I really hate that approach ;-/


Re: VDSO ELF header

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 16:13, Dmitry Safonov a écrit :

Hello,

On 3/26/21 10:50 AM, Christophe Leroy wrote:



Le 26/03/2021 à 11:46, Michael Ellerman a écrit :

Laurent Dufour  writes:

Le 25/03/2021 à 17:56, Laurent Dufour a écrit :

Le 25/03/2021 à 17:46, Christophe Leroy a écrit :

Le 25/03/2021 à 17:11, Laurent Dufour a écrit :

Since v5.11 and the changes you made to the VDSO code, it no more
exposing
the ELF header at the beginning of the VDSO mapping in user space.

This is confusing CRIU which is checking for this ELF header cookie
(https://github.com/checkpoint-restore/criu/issues/1417).


How does it do on other architectures ?


Good question, I'll double check the CRIU code.


On x86, there are 2 VDSO entries:
77fcb000-77fce000 r--p  00:00
0  [vvar]
77fce000-77fcf000 r-xp  00:00
0  [vdso]

And the VDSO is starting with the ELF header.


I'm not an expert in loading and ELF part and reading the change
you made, I
can't identify how this could work now as I'm expecting the loader
to need
that ELF header to do the relocation.


I think the loader is able to find it at the expected place.


Actually, it seems the loader relies on the AUX vector
AT_SYSINFO_EHDR. I guess
CRIU should do the same.



   From my investigation it seems that the first bytes of the VDSO
area are now
the vdso_arch_data.

Is the ELF header put somewhere else?
How could the loader process the VDSO without that ELF header?



Like most other architectures, we now have the data section as
first page and
the text section follows. So you will likely find the elf header on
the second
page.


I'm wondering if the data section you're refering to is the vvar
section I can
see on x86.


Many of the other architectures have separate vm_special_mapping's for
the data page and the vdso binary, where the former is called "vvar".

eg, s390:

static struct vm_special_mapping vvar_mapping = {
 .name = "[vvar]",
 .fault = vvar_fault,
};

static struct vm_special_mapping vdso_mapping = {
 .name = "[vdso]",
 .mremap = vdso_mremap,
};


I guess we probably should be doing that too.



Dmitry proposed the same, see
https://github.com/0x7f454c46/linux/commit/783c7a2532d2219edbcf555cc540eab05f698d2a


Discussion at https://github.com/checkpoint-restore/criu/issues/1417


Yeah, I didn't submit it officially to lkml because I couldn't test it
yet (and I usually don't send untested patches). The VM I have fails to
kexec and there's some difficulty to get serial console working, so I'd
appreciate if someone could either pick it up, or add tested-by.



Just to let everyone know, while testing your patch with selftest I encountered the following Oops. 
But I also have it without your patch thought.


root@vgoip:~# ./sigreturn_vdso
test: sigreturn_vdso
tags: git_version:v5.12-rc4-1553-gc31141d460e6
VDSO is at 0x104000-0x10bfff (32768 bytes)
Signal delivered OK with VDSO mapped
VDSO moved to 0x77bf4000-0x77bfbfff (32768 bytes)
Signal delivered OK with VDSO moved
Unmapped VDSO
[ 1855.444371] Kernel attempted to read user page (7ff9ff30) - exploit attempt? 
(uid: 0)
[ 1855.459404] BUG: Unable to handle kernel data access on read at 0x7ff9ff30
[ 1855.466188] Faulting instruction address: 0xc00111d4
[ 1855.471099] Oops: Kernel access of bad area, sig: 11 [#1]
[ 1855.476428] BE PAGE_SIZE=16K PREEMPT CMPC885
[ 1855.480702] SAF3000 DIE NOTIFICATION
[ 1855.484184] CPU: 0 PID: 362 Comm: sigreturn_vdso Not tainted 
5.12.0-rc4-s3k-dev-01553-gc31141d460e6 #4811

[ 1855.493644] NIP:  c00111d4 LR: c0005a28 CTR: 
[ 1855.498634] REGS: cadb3dd0 TRAP: 0300   Not tainted  
(5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
[ 1855.507068] MSR:  9032   CR: 48000884  XER: 2000
[ 1855.513866] DAR: 7ff9ff30 DSISR: 8800
[ 1855.513866] GPR00: c0007788 cadb3e90 c28dc000 7ff9ff30 7ff9ff40 04e0 
7ff9fd50 
[ 1855.513866] GPR08: 0001 0001 7ff9ff30  28000282 1001b7e8 
100a0920 
[ 1855.513866] GPR16: 100cac0c 100b 102883a4 10289685 100d 100d 
100d 100b2e9e
[ 1855.513866] GPR24:  102883c8  7ff9ff38 cadb3f40 cadb3ec8 
c28dc000 
[ 1855.552767] NIP [c00111d4] flush_icache_range+0x90/0xb4
[ 1855.557932] LR [c0005a28] handle_signal32+0x1bc/0x1c4
[ 1855.562925] Call Trace:
[ 1855.565332] [cadb3e90] [100d] 0x100d (unreliable)
[ 1855.570666] [cadb3ec0] [c0007788] do_notify_resume+0x260/0x314
[ 1855.576432] [cadb3f20] [c000c764] syscall_exit_prepare+0x120/0x184
[ 1855.582542] [cadb3f30] [c00100b4] ret_from_syscall+0xc/0x28
[ 1855.588050] --- interrupt: c00 at 0xfe807f8
[ 1855.592183] NIP:  0fe807f8 LR: 10001048 CTR: c0139378
[ 1855.597174] REGS: cadb3f40 TRAP: 0c00   Not tainted  
(5.12.0-rc4-s3k-dev-01553-gc31141d460e6)
[ 1855.605607] MSR:  d032   CR: 28000282  XER: 2000
[ 1855.612664]
[ 1855.612664] GPR00: 0025 7ffa0230 77c09690  000a 28000282 
0001 0ff03a38
[ 1855.612664] GPR08: 

Re: [PATCH v3 01/17] cmdline: Add generic function to build command line.

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 16:42, Rob Herring a écrit :

On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
 wrote:


This code provides architectures with a way to build command line
based on what is built in the kernel and what is handed over by the
bootloader, based on selected compile-time options.


Note that I have this patch pending:

https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20210316193820.3137-1-a...@ghiti.fr/

It's going to need to be adapted for this. I've held off applying to
see if this gets settled.


good point.

Hope we can't have things like

option="beautiful weather"





Signed-off-by: Christophe Leroy 
---
v3:
- Addressed comments from Will
- Added capability to have src == dst
---
  include/linux/cmdline.h | 57 +
  1 file changed, 57 insertions(+)
  create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..dea87edd41be
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+#include 
+
+/* Allow architectures to override strlcat, powerpc can't use strings so early 
*/
+#ifndef cmdline_strlcat
+#define cmdline_strlcat strlcat
+#endif
+
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dst: The destination of the final appended/prepended string.
+ * @src: The starting string or NULL if there isn't one.
+ * @len: the length of dest buffer.
+ */
+static __always_inline void __cmdline_build(char *dst, const char *src, size_t 
len)
+{
+   if (!len || src == dst)
+   return;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !src) {
+   dst[0] = 0;
+   cmdline_strlcat(dst, CONFIG_CMDLINE, len);
+   return;
+   }
+
+   if (dst != src)
+   dst[0] = 0;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_PREPEND))
+   cmdline_strlcat(dst, CONFIG_CMDLINE " ", len);
+
+   cmdline_strlcat(dst, src, len);
+
+   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND))


Should be APPEND.


Not yet. For the time being all architectures use EXTEND only.

In patch 3 it is changed to:

-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND))
+   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || 
IS_ENABLED(CONFIG_CMDLINE_APPEND))

Then in last patch, I forgot but I should have done:

-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || 
IS_ENABLED(CONFIG_CMDLINE_APPEND))
+   if (IS_ENABLED(CONFIG_CMDLINE_APPEND))





+   cmdline_strlcat(dst, " " CONFIG_CMDLINE, len);
+}
+
+#define cmdline_build(dst, src, len) do {  \


Perhaps a comment why we need this to be a define.


Probably we don't need anymore as I finally decided to use COMMAND_LINE_SIZE instead of 'len' as the 
size of the temporary buffer.





+   char *__c_dst = (dst);  \
+   const char *__c_src = (src);\
+   \
+   if (__c_src == __c_dst) {   \
+   static char __c_tmp[COMMAND_LINE_SIZE] __initdata = ""; \
+   \
+   cmdline_strlcat(__c_tmp, __c_src, COMMAND_LINE_SIZE);   \
+   __cmdline_build(__c_dst, __c_tmp, (len));   \
+   } else {\
+   __cmdline_build(__c_dst, __c_src, (len));   \
+   }   \
+} while (0)
+
+#endif /* _LINUX_CMDLINE_H */
--
2.25.0



Christophe


Re: [PATCH V2 3/5] tools/perf: Add powerpc support for PERF_SAMPLE_WEIGHT_STRUCT

2021-03-26 Thread Arnaldo



On March 26, 2021 12:23:04 PM GMT-03:00, Athira Rajeev 
 wrote:
>
>
>On 25-Mar-2021, at 1:13 AM, Jiri Olsa  wrote:
>
>On Mon, Mar 22, 2021 at 10:57:25AM -0400, Athira Rajeev wrote:
>
>Add arch specific arch_evsel__set_sample_weight() to set the new
>sample type for powerpc.
>
>Add arch specific arch_perf_parse_sample_weight() to store the
>sample->weight values depending on the sample type applied.
>if the new sample type (PERF_SAMPLE_WEIGHT_STRUCT) is applied,
>store only the lower 32 bits to sample->weight. If sample type
>is 'PERF_SAMPLE_WEIGHT', store the full 64-bit to sample->weight.
>
>Signed-off-by: Athira Rajeev 
>---
>tools/perf/arch/powerpc/util/Build   |  2 ++
>tools/perf/arch/powerpc/util/event.c | 32
>
>tools/perf/arch/powerpc/util/evsel.c |  8 
>3 files changed, 42 insertions(+)
>create mode 100644 tools/perf/arch/powerpc/util/event.c
>create mode 100644 tools/perf/arch/powerpc/util/evsel.c
>
>diff --git a/tools/perf/arch/powerpc/util/Build
>b/tools/perf/arch/powerpc/util/Build
>index b7945e5a543b..8a79c4126e5b 100644
>--- a/tools/perf/arch/powerpc/util/Build
>+++ b/tools/perf/arch/powerpc/util/Build
>@@ -4,6 +4,8 @@ perf-y += kvm-stat.o
>perf-y += perf_regs.o
>perf-y += mem-events.o
>perf-y += sym-handling.o
>+perf-y += evsel.o
>+perf-y += event.o
>
>perf-$(CONFIG_DWARF) += dwarf-regs.o
>perf-$(CONFIG_DWARF) += skip-callchain-idx.o
>diff --git a/tools/perf/arch/powerpc/util/event.c
>b/tools/perf/arch/powerpc/util/event.c
>new file mode 100644
>index ..f49d32c2c8ae
>--- /dev/null
>+++ b/tools/perf/arch/powerpc/util/event.c
>@@ -0,0 +1,32 @@
>+// SPDX-License-Identifier: GPL-2.0
>+#include 
>+#include 
>+#include 
>+
>+#include "../../../util/event.h"
>+#include "../../../util/synthetic-events.h"
>+#include "../../../util/machine.h"
>+#include "../../../util/tool.h"
>+#include "../../../util/map.h"
>+#include "../../../util/debug.h"
>
>
>nit, just #include "utils/...h" should work no?
>
>other than that, the patchset looks ok to me
>
>Acked-by: Jiri Olsa 
>
>
>
>Hi Jiri, Arnaldo
>
>Thanks for reviewing the patch set.
>I checked that, just using "utils/...h" also works.
>Below is the change which I verified. Since the patches are presently
>merged in 
>https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf/core,
>
>can you please suggest how can we go about this change ?

I'll fix it up here,

Thanks for the patch.

- Arnaldo

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [PATCH v3 05/17] arm: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 16:47, Rob Herring a écrit :

On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
 wrote:


This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
  arch/arm/Kconfig  | 38 +--
  arch/arm/kernel/atags_parse.c | 15 +-
  2 files changed, 6 insertions(+), 47 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 5da96f5df48f..67bc75f2da81 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -50,6 +50,7 @@ config ARM
 select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
 select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI
 select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+   select GENERIC_CMDLINE if ATAGS


Don't we need this enabled for !ATAGS (i.e. DT boot)?

Can we always enable GENERIC_CMDLINE for OF_EARLY_FLATTREE?



Don't know.

Today ARM has:

choice
prompt "Kernel command line type" if CMDLINE != ""
default CMDLINE_FROM_BOOTLOADER
depends on ATAGS



Christophe


Re: [PATCH v3 05/17] arm: Convert to GENERIC_CMDLINE

2021-03-26 Thread Rob Herring
On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
 wrote:
>
> This converts the architecture to GENERIC_CMDLINE.
>
> Signed-off-by: Christophe Leroy 
> ---
>  arch/arm/Kconfig  | 38 +--
>  arch/arm/kernel/atags_parse.c | 15 +-
>  2 files changed, 6 insertions(+), 47 deletions(-)
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 5da96f5df48f..67bc75f2da81 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -50,6 +50,7 @@ config ARM
> select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
> select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI
> select GENERIC_CLOCKEVENTS_BROADCAST if SMP
> +   select GENERIC_CMDLINE if ATAGS

Don't we need this enabled for !ATAGS (i.e. DT boot)?

Can we always enable GENERIC_CMDLINE for OF_EARLY_FLATTREE?

Rob


Re: [PATCH v3 01/17] cmdline: Add generic function to build command line.

2021-03-26 Thread Rob Herring
On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
 wrote:
>
> This code provides architectures with a way to build command line
> based on what is built in the kernel and what is handed over by the
> bootloader, based on selected compile-time options.

Note that I have this patch pending:

https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20210316193820.3137-1-a...@ghiti.fr/

It's going to need to be adapted for this. I've held off applying to
see if this gets settled.

>
> Signed-off-by: Christophe Leroy 
> ---
> v3:
> - Addressed comments from Will
> - Added capability to have src == dst
> ---
>  include/linux/cmdline.h | 57 +
>  1 file changed, 57 insertions(+)
>  create mode 100644 include/linux/cmdline.h
>
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> new file mode 100644
> index ..dea87edd41be
> --- /dev/null
> +++ b/include/linux/cmdline.h
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_CMDLINE_H
> +#define _LINUX_CMDLINE_H
> +
> +#include 
> +
> +/* Allow architectures to override strlcat, powerpc can't use strings so 
> early */
> +#ifndef cmdline_strlcat
> +#define cmdline_strlcat strlcat
> +#endif
> +
> +/*
> + * This function will append or prepend a builtin command line to the command
> + * line provided by the bootloader. Kconfig options can be used to alter
> + * the behavior of this builtin command line.
> + * @dst: The destination of the final appended/prepended string.
> + * @src: The starting string or NULL if there isn't one.
> + * @len: the length of dest buffer.
> + */
> +static __always_inline void __cmdline_build(char *dst, const char *src, 
> size_t len)
> +{
> +   if (!len || src == dst)
> +   return;
> +
> +   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !src) {
> +   dst[0] = 0;
> +   cmdline_strlcat(dst, CONFIG_CMDLINE, len);
> +   return;
> +   }
> +
> +   if (dst != src)
> +   dst[0] = 0;
> +
> +   if (IS_ENABLED(CONFIG_CMDLINE_PREPEND))
> +   cmdline_strlcat(dst, CONFIG_CMDLINE " ", len);
> +
> +   cmdline_strlcat(dst, src, len);
> +
> +   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND))

Should be APPEND.

> +   cmdline_strlcat(dst, " " CONFIG_CMDLINE, len);
> +}
> +
> +#define cmdline_build(dst, src, len) do {  \

Perhaps a comment why we need this to be a define.

> +   char *__c_dst = (dst);  \
> +   const char *__c_src = (src);\
> +   \
> +   if (__c_src == __c_dst) {   \
> +   static char __c_tmp[COMMAND_LINE_SIZE] __initdata = ""; \
> +   \
> +   cmdline_strlcat(__c_tmp, __c_src, COMMAND_LINE_SIZE);   \
> +   __cmdline_build(__c_dst, __c_tmp, (len));   \
> +   } else {\
> +   __cmdline_build(__c_dst, __c_src, (len));   \
> +   }   \
> +} while (0)
> +
> +#endif /* _LINUX_CMDLINE_H */
> --
> 2.25.0
>


Re: [PATCH 2/4] exec: remove compat_do_execve

2021-03-26 Thread Andreas Schwab
On Mär 26 2021, Christoph Hellwig wrote:

> Just call compat_do_execve instead.

ITYM compat_do_execveat here.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [PATCH v3 1/1] hotplug-cpu.c: show 'last online CPU' error in dlpar_cpu_offline()

2021-03-26 Thread Andrew Donnellan

On 27/3/21 1:19 am, Daniel Henrique Barboza wrote:

One of the reasons that dlpar_cpu_offline can fail is when attempting to
offline the last online CPU of the kernel. This can be observed in a
pseries QEMU guest that has hotplugged CPUs. If the user offlines all
other CPUs of the guest, and a hotplugged CPU is now the last online
CPU, trying to reclaim it will fail. See [1] for an example.

The current error message in this situation returns rc with -EBUSY and a
generic explanation, e.g.:

pseries-hotplug-cpu: Failed to offline CPU PowerPC,POWER9, rc: -16

EBUSY can be caused by other conditions, such as cpu_hotplug_disable
being true. Throwing a more specific error message for this case,
instead of just "Failed to offline CPU", makes it clearer that the error
is in fact a known error situation instead of other generic/unknown
cause.

This patch adds a 'last online' check in dlpar_cpu_offline() to catch
the 'last online CPU' offline error, returning a more informative error
message:

pseries-hotplug-cpu: Unable to remove last online CPU PowerPC,POWER9

[1] https://bugzilla.redhat.com/1911414

Signed-off-by: Daniel Henrique Barboza 


Thanks for addressing the issues in Daniel's review.

I haven't tested it, but this patch looks sensible enough to me.

Reviewed-by: Andrew Donnellan 

--
Andrew Donnellan  OzLabs, ADL Canberra
a...@linux.ibm.com IBM Australia Limited


Re: [PATCH v3 11/17] riscv: Convert to GENERIC_CMDLINE

2021-03-26 Thread Rob Herring
On Fri, Mar 26, 2021 at 8:20 AM Christophe Leroy
 wrote:
>
>
>
> Le 26/03/2021 à 15:08, Andreas Schwab a écrit :
> > On Mär 26 2021, Christophe Leroy wrote:
> >
> >> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> >> index f8f15332caa2..e7c91ee478d1 100644
> >> --- a/arch/riscv/kernel/setup.c
> >> +++ b/arch/riscv/kernel/setup.c
> >> @@ -20,6 +20,7 @@
> >>   #include 
> >>   #include 
> >>   #include 
> >> +#include 
> >>
> >>   #include 
> >>   #include 
> >> @@ -228,10 +229,8 @@ static void __init parse_dtb(void)
> >>  }
> >>
> >>  pr_err("No DTB passed to the kernel\n");
> >> -#ifdef CONFIG_CMDLINE_FORCE
> >> -strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> >> +cmdline_build(boot_command_line, NULL, COMMAND_LINE_SIZE);
> >>  pr_info("Forcing kernel command line to: %s\n", boot_command_line);
> >
> > Shouldn't that message become conditional in some way?
> >
>
> You are right, I did something similar on ARM but looks like I missed it on 
> RISCV.

How is this hunk even useful? Under what conditions can you boot
without a DTB? Even with a built-in DTB, the DT cmdline handling would
be called.

Rob


Re: VDSO ELF header

2021-03-26 Thread Dmitry Safonov
Hello,

On 3/26/21 10:50 AM, Christophe Leroy wrote:
> 
> 
> Le 26/03/2021 à 11:46, Michael Ellerman a écrit :
>> Laurent Dufour  writes:
>>> Le 25/03/2021 à 17:56, Laurent Dufour a écrit :
 Le 25/03/2021 à 17:46, Christophe Leroy a écrit :
> Le 25/03/2021 à 17:11, Laurent Dufour a écrit :
>> Since v5.11 and the changes you made to the VDSO code, it no more
>> exposing
>> the ELF header at the beginning of the VDSO mapping in user space.
>>
>> This is confusing CRIU which is checking for this ELF header cookie
>> (https://github.com/checkpoint-restore/criu/issues/1417).
>
> How does it do on other architectures ?

 Good question, I'll double check the CRIU code.
>>>
>>> On x86, there are 2 VDSO entries:
>>> 77fcb000-77fce000 r--p  00:00
>>> 0  [vvar]
>>> 77fce000-77fcf000 r-xp  00:00
>>> 0  [vdso]
>>>
>>> And the VDSO is starting with the ELF header.
>>>
>> I'm not an expert in loading and ELF part and reading the change
>> you made, I
>> can't identify how this could work now as I'm expecting the loader
>> to need
>> that ELF header to do the relocation.
>
> I think the loader is able to find it at the expected place.

 Actually, it seems the loader relies on the AUX vector
 AT_SYSINFO_EHDR. I guess
 CRIU should do the same.

>>
>>   From my investigation it seems that the first bytes of the VDSO
>> area are now
>> the vdso_arch_data.
>>
>> Is the ELF header put somewhere else?
>> How could the loader process the VDSO without that ELF header?
>>
>
> Like most other architectures, we now have the data section as
> first page and
> the text section follows. So you will likely find the elf header on
> the second
> page.
>>>
>>> I'm wondering if the data section you're refering to is the vvar
>>> section I can
>>> see on x86.
>>
>> Many of the other architectures have separate vm_special_mapping's for
>> the data page and the vdso binary, where the former is called "vvar".
>>
>> eg, s390:
>>
>> static struct vm_special_mapping vvar_mapping = {
>> .name = "[vvar]",
>> .fault = vvar_fault,
>> };
>>
>> static struct vm_special_mapping vdso_mapping = {
>> .name = "[vdso]",
>> .mremap = vdso_mremap,
>> };
>>
>>
>> I guess we probably should be doing that too.
>>
> 
> Dmitry proposed the same, see
> https://github.com/0x7f454c46/linux/commit/783c7a2532d2219edbcf555cc540eab05f698d2a
> 
> 
> Discussion at https://github.com/checkpoint-restore/criu/issues/1417

Yeah, I didn't submit it officially to lkml because I couldn't test it
yet (and I usually don't send untested patches). The VM I have fails to
kexec and there's some difficulty to get serial console working, so I'd
appreciate if someone could either pick it up, or add tested-by.

Thanks,
  Dmitry


Re: [PATCH 4/4] exec: move the call to getname_flags into do_execveat

2021-03-26 Thread Arnd Bergmann
On Fri, Mar 26, 2021 at 3:38 PM Christoph Hellwig  wrote:
>
> Remove the duplicated copying of the pathname into the common helper.
>
> Signed-off-by: Christoph Hellwig 

Looks correct, but

> -static int do_execveat(int fd, struct filename *filename,
> +static int do_execveat(int fd, const char __user *pathname,
> const char __user *const __user *argv,
> const char __user *const __user *envp, int flags)

Maybe rename this to ksys_execveat() for consistency now? I think that
is the current trend for functions that are essentially just the syscall.

With or without that change

Reviewed-by: Arnd Bergmann 


Re: [PATCH 1/4] exec: remove do_execve

2021-03-26 Thread Arnd Bergmann
On Fri, Mar 26, 2021 at 3:38 PM Christoph Hellwig  wrote:
>
> Just call do_execveat instead.
>
> Signed-off-by: Christoph Hellwig 

Reviewed-by: Arnd Bergmann 


Re: [PATCH v3 00/17] Implement GENERIC_CMDLINE

2021-03-26 Thread Rob Herring
On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy
 wrote:
>
> The purpose of this series is to improve and enhance the
> handling of kernel boot arguments.
>
> It is first focussed on powerpc but also extends the capability
> for other arches.
>
> This is based on suggestion from Daniel Walker 
>
> Main changes in V3:
> - Also accept destination equal to source in cmdline_build() by setting a tmp 
> buffer in __initdata. Powerpc provides different source and destination and 
> call __cmdline_build() directly.
> - Taken comments received from Will and Rob
> - Converted all architectures (Only tested on powerpc)
>
> Christophe Leroy (17):
>   cmdline: Add generic function to build command line.
>   drivers: of: use cmdline building function
>   cmdline: Gives architectures opportunity to use generically defined
> boot cmdline manipulation
>   powerpc: Convert to GENERIC_CMDLINE
>   arm: Convert to GENERIC_CMDLINE
>   arm64: Convert to GENERIC_CMDLINE
>   hexagon: Convert to GENERIC_CMDLINE
>   microblaze: Convert to GENERIC_CMDLINE
>   nios2: Convert to GENERIC_CMDLINE
>   openrisc: Convert to GENERIC_CMDLINE
>   riscv: Convert to GENERIC_CMDLINE
>   sh: Convert to GENERIC_CMDLINE
>   sparc: Convert to GENERIC_CMDLINE
>   xtensa: Convert to GENERIC_CMDLINE
>   x86: Convert to GENERIC_CMDLINE
>   mips: Convert to GENERIC_CMDLINE
>   cmdline: Remove CONFIG_CMDLINE_EXTEND
>
>  arch/arm/Kconfig| 38 +-
>  arch/arm/kernel/atags_parse.c   | 15 ++
>  arch/arm64/Kconfig  | 33 +---
>  arch/arm64/kernel/idreg-override.c  |  9 ++--
>  arch/hexagon/Kconfig| 11 +---
>  arch/hexagon/kernel/setup.c | 10 +---
>  arch/microblaze/Kconfig | 24 +
>  arch/microblaze/configs/mmu_defconfig   |  2 +-
>  arch/microblaze/kernel/head.S   |  4 +-
>  arch/mips/Kconfig   |  1 +
>  arch/mips/Kconfig.debug | 44 
>  arch/mips/configs/ar7_defconfig |  1 -
>  arch/mips/configs/bcm47xx_defconfig |  1 -
>  arch/mips/configs/bcm63xx_defconfig |  1 -
>  arch/mips/configs/bmips_be_defconfig|  1 -
>  arch/mips/configs/bmips_stb_defconfig   |  1 -
>  arch/mips/configs/capcella_defconfig|  1 -
>  arch/mips/configs/ci20_defconfig|  1 -
>  arch/mips/configs/cu1000-neo_defconfig  |  1 -
>  arch/mips/configs/cu1830-neo_defconfig  |  1 -
>  arch/mips/configs/e55_defconfig |  1 -
>  arch/mips/configs/generic_defconfig |  1 -
>  arch/mips/configs/gpr_defconfig |  1 -
>  arch/mips/configs/loongson3_defconfig   |  1 -
>  arch/mips/configs/mpc30x_defconfig  |  1 -
>  arch/mips/configs/rt305x_defconfig  |  1 -
>  arch/mips/configs/tb0219_defconfig  |  1 -
>  arch/mips/configs/tb0226_defconfig  |  1 -
>  arch/mips/configs/tb0287_defconfig  |  1 -
>  arch/mips/configs/workpad_defconfig |  1 -
>  arch/mips/configs/xway_defconfig|  1 -
>  arch/mips/kernel/relocate.c |  4 +-
>  arch/mips/kernel/setup.c| 40 +--
>  arch/mips/pic32/pic32mzda/early_console.c   |  2 +-
>  arch/mips/pic32/pic32mzda/init.c|  2 -
>  arch/nios2/Kconfig  | 24 +
>  arch/nios2/kernel/setup.c   | 13 ++---
>  arch/openrisc/Kconfig   | 10 +---
>  arch/powerpc/Kconfig| 37 +
>  arch/powerpc/kernel/prom_init.c | 17 +++---
>  arch/riscv/Kconfig  | 44 +---
>  arch/riscv/kernel/setup.c   |  5 +-
>  arch/sh/Kconfig | 30 +--
>  arch/sh/configs/ap325rxa_defconfig  |  2 +-
>  arch/sh/configs/dreamcast_defconfig |  2 +-
>  arch/sh/configs/ecovec24-romimage_defconfig |  2 +-
>  arch/sh/configs/ecovec24_defconfig  |  2 +-
>  arch/sh/configs/edosk7760_defconfig |  2 +-
>  arch/sh/configs/espt_defconfig  |  2 +-
>  arch/sh/configs/j2_defconfig|  2 +-
>  arch/sh/configs/kfr2r09-romimage_defconfig  |  2 +-
>  arch/sh/configs/kfr2r09_defconfig   |  2 +-
>  arch/sh/configs/lboxre2_defconfig   |  2 +-
>  arch/sh/configs/microdev_defconfig  |  2 +-
>  arch/sh/configs/migor_defconfig |  2 +-
>  arch/sh/configs/polaris_defconfig   |  2 +-
>  arch/sh/configs/r7780mp_defconfig   |  2 +-
>  arch/sh/configs/r7785rp_defconfig   |  2 +-
>  arch/sh/configs/rsk7201_defconfig   |  2 +-
>  arch/sh/configs/rsk7203_defconfig   |  2 +-
>  arch/sh/configs/rts7751r2d1_defconfig   |  2 +-
>  arch/sh/configs/rts7751r2dplus_defconfig|  2 +-
>  arch/sh/configs/sdk7780_defconfig   |  2 +-
>  arch/sh/configs/sdk7786_defconfig 

Re: [PATCH 3/4] exec: simplify the compat syscall handling

2021-03-26 Thread Arnd Bergmann
On Fri, Mar 26, 2021 at 3:38 PM Christoph Hellwig  wrote:
>
> The only differenence betweeen the compat exec* syscalls and their
> native versions is the compat_ptr sign extension, and the fact that
> the pointer arithmetics for the two dimensional arrays needs to use
> the compat pointer size.  Instead of the compat wrappers and the
> struct user_arg_ptr machinery just use in_compat_syscall() to do the
> right thing for the compat case deep inside get_user_arg_ptr().
>
> Signed-off-by: Christoph Hellwig 

Nice cleanup!

Reviewed-by: Arnd Bergmann 


Re: [PATCH] powerpc: powernv: Remove unneeded variable: "rc"

2021-03-26 Thread Andrew Donnellan

On 26/3/21 10:53 pm, dingsen...@163.com wrote:

From: dingsenjie 

Remove unneeded variable: "rc".

Signed-off-by: dingsenjie 


This looks obviously correct and doesn't raise any checkpatch warnings.

Reviewed-by: Andrew Donnellan 

--
Andrew Donnellan  OzLabs, ADL Canberra
a...@linux.ibm.com IBM Australia Limited


Re: [PATCH v2 0/8] Implement EBPF on powerpc32

2021-03-26 Thread Christophe Leroy




Le 22/03/2021 à 18:53, Andrii Nakryiko a écrit :

On Mon, Mar 22, 2021 at 9:37 AM Christophe Leroy
 wrote:


This series implements extended BPF on powerpc32. For the implementation
details, see the patch before the last.

The following operations are not implemented:

 case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */
 case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */
 case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += 
src */

The following operations are only implemented for power of two constants:

 case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */
 case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */

Below are the results on a powerpc 885:
- with the patch, with and without bpf_jit_enable
- without the patch, with bpf_jit_enable (ie with CBPF)

With the patch, with bpf_jit_enable = 1 :

[   60.826529] test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]
[   60.832505] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

With the patch, with bpf_jit_enable = 0 :

[   75.186337] test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]
[   75.192325] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

Without the patch, with bpf_jit_enable = 1 :

[  186.112429] test_bpf: Summary: 371 PASSED, 7 FAILED, [119/366 JIT'ed]

Couldn't run test_progs because it doesn't build (clang 11 crashes during the 
build).


Can you please try checking out the latest clang from sources and use
that one instead?


The crash is fixed, it builds one step more, then fails at:

[root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o > 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h

libbpf: elf: endianness mismatch in atomic_bounds.
Error: failed to open BPF object file: Endian mismatch

I'm cross-building on x86 for powerpc/32

[root@PC-server-ldb bpf]# file atomic_bounds.o
atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with 
debug_info, not stripped

Christophe


[PATCH 4/4] exec: move the call to getname_flags into do_execveat

2021-03-26 Thread Christoph Hellwig
Remove the duplicated copying of the pathname into the common helper.

Signed-off-by: Christoph Hellwig 
---
 fs/exec.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index b34c1eb9e7ad8e..5c0dd8f85fe7b5 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1843,13 +1843,16 @@ static int bprm_execve(struct linux_binprm *bprm,
return retval;
 }
 
-static int do_execveat(int fd, struct filename *filename,
+static int do_execveat(int fd, const char __user *pathname,
const char __user *const __user *argv,
const char __user *const __user *envp, int flags)
 {
+   int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
+   struct filename *filename;
struct linux_binprm *bprm;
int retval;
 
+   filename = getname_flags(pathname, lookup_flags, NULL);
if (IS_ERR(filename))
return PTR_ERR(filename);
 
@@ -1993,7 +1996,7 @@ SYSCALL_DEFINE3(execve,
const char __user *const __user *, argv,
const char __user *const __user *, envp)
 {
-   return do_execveat(AT_FDCWD, getname(filename), argv, envp, 0);
+   return do_execveat(AT_FDCWD, filename, argv, envp, 0);
 }
 
 SYSCALL_DEFINE5(execveat,
@@ -2002,9 +2005,5 @@ SYSCALL_DEFINE5(execveat,
const char __user *const __user *, envp,
int, flags)
 {
-   int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
-
-   return do_execveat(fd,
-  getname_flags(filename, lookup_flags, NULL),
-  argv, envp, flags);
+   return do_execveat(fd, filename, argv, envp, flags);
 }
-- 
2.30.1



[PATCH 3/4] exec: simplify the compat syscall handling

2021-03-26 Thread Christoph Hellwig
The only differenence betweeen the compat exec* syscalls and their
native versions is the compat_ptr sign extension, and the fact that
the pointer arithmetics for the two dimensional arrays needs to use
the compat pointer size.  Instead of the compat wrappers and the
struct user_arg_ptr machinery just use in_compat_syscall() to do the
right thing for the compat case deep inside get_user_arg_ptr().

Signed-off-by: Christoph Hellwig 
---
 arch/arm64/include/asm/unistd32.h |   4 +-
 arch/mips/kernel/syscalls/syscall_n32.tbl |   4 +-
 arch/mips/kernel/syscalls/syscall_o32.tbl |   4 +-
 arch/parisc/kernel/syscalls/syscall.tbl   |   4 +-
 arch/powerpc/kernel/syscalls/syscall.tbl  |   4 +-
 arch/s390/kernel/syscalls/syscall.tbl |   4 +-
 arch/sparc/kernel/syscalls.S  |   4 +-
 arch/x86/entry/syscall_x32.c  |   2 +
 arch/x86/entry/syscalls/syscall_32.tbl|   4 +-
 arch/x86/entry/syscalls/syscall_64.tbl|   4 +-
 fs/exec.c | 101 --
 include/linux/compat.h|   7 --
 include/uapi/asm-generic/unistd.h |   4 +-
 tools/include/uapi/asm-generic/unistd.h   |   4 +-
 .../arch/powerpc/entry/syscalls/syscall.tbl   |   4 +-
 .../perf/arch/s390/entry/syscalls/syscall.tbl |   4 +-
 .../arch/x86/entry/syscalls/syscall_64.tbl|   4 +-
 17 files changed, 48 insertions(+), 118 deletions(-)

diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 3d874f624056b1..34360760773201 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -33,7 +33,7 @@ __SYSCALL(__NR_link, sys_link)
 #define __NR_unlink 10
 __SYSCALL(__NR_unlink, sys_unlink)
 #define __NR_execve 11
-__SYSCALL(__NR_execve, compat_sys_execve)
+__SYSCALL(__NR_execve, sys_execve)
 #define __NR_chdir 12
 __SYSCALL(__NR_chdir, sys_chdir)
/* 13 was sys_time */
@@ -785,7 +785,7 @@ __SYSCALL(__NR_memfd_create, sys_memfd_create)
 #define __NR_bpf 386
 __SYSCALL(__NR_bpf, sys_bpf)
 #define __NR_execveat 387
-__SYSCALL(__NR_execveat, compat_sys_execveat)
+__SYSCALL(__NR_execveat, sys_execveat)
 #define __NR_userfaultfd 388
 __SYSCALL(__NR_userfaultfd, sys_userfaultfd)
 #define __NR_membarrier 389
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl 
b/arch/mips/kernel/syscalls/syscall_n32.tbl
index 8fd8c1790941c6..4da26b7f95d172 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -64,7 +64,7 @@
 54 n32 getsockopt  sys_getsockopt
 55 n32 clone   __sys_clone
 56 n32 fork__sys_fork
-57 n32 execve  compat_sys_execve
+57 n32 execve  sys_execve
 58 n32 exitsys_exit
 59 n32 wait4   compat_sys_wait4
 60 n32 killsys_kill
@@ -328,7 +328,7 @@
 317n32 getrandom   sys_getrandom
 318n32 memfd_createsys_memfd_create
 319n32 bpf sys_bpf
-320n32 execveatcompat_sys_execveat
+320n32 execveatsys_execveat
 321n32 userfaultfd sys_userfaultfd
 322n32 membarrier  sys_membarrier
 323n32 mlock2  sys_mlock2
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl 
b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 090d29ca80ff8f..33818dd2462090 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -18,7 +18,7 @@
 8  o32 creat   sys_creat
 9  o32 linksys_link
 10 o32 unlink  sys_unlink
-11 o32 execve  sys_execve  
compat_sys_execve
+11 o32 execve  sys_execve
 12 o32 chdir   sys_chdir
 13 o32 timesys_time32
 14 o32 mknod   sys_mknod
@@ -367,7 +367,7 @@
 353o32 getrandom   sys_getrandom
 354o32 memfd_createsys_memfd_create
 355o32 bpf sys_bpf
-356o32 execveatsys_execveat
compat_sys_execveat
+356o32 execveatsys_execveat
 357o32 userfaultfd sys_userfaultfd
 358o32 membarrier  sys_membarrier
 359o32 mlock2  sys_mlock2
diff --git a/arch/parisc/kernel/syscalls/syscall.tbl 
b/arch/parisc/kernel/syscalls/syscall.tbl

[PATCH 2/4] exec: remove compat_do_execve

2021-03-26 Thread Christoph Hellwig
Just call compat_do_execve instead.

Signed-off-by: Christoph Hellwig 
---
 fs/exec.c | 17 +
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index b63fb020909075..06e07278b456fa 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1990,21 +1990,6 @@ static int do_execveat(int fd, struct filename *filename,
 }
 
 #ifdef CONFIG_COMPAT
-static int compat_do_execve(struct filename *filename,
-   const compat_uptr_t __user *__argv,
-   const compat_uptr_t __user *__envp)
-{
-   struct user_arg_ptr argv = {
-   .is_compat = true,
-   .ptr.compat = __argv,
-   };
-   struct user_arg_ptr envp = {
-   .is_compat = true,
-   .ptr.compat = __envp,
-   };
-   return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
-}
-
 static int compat_do_execveat(int fd, struct filename *filename,
  const compat_uptr_t __user *__argv,
  const compat_uptr_t __user *__envp,
@@ -2072,7 +2057,7 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, 
filename,
const compat_uptr_t __user *, argv,
const compat_uptr_t __user *, envp)
 {
-   return compat_do_execve(getname(filename), argv, envp);
+   return compat_do_execveat(AT_FDCWD, getname(filename), argv, envp, 0);
 }
 
 COMPAT_SYSCALL_DEFINE5(execveat, int, fd,
-- 
2.30.1



[PATCH 1/4] exec: remove do_execve

2021-03-26 Thread Christoph Hellwig
Just call do_execveat instead.

Signed-off-by: Christoph Hellwig 
---
 fs/exec.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 18594f11c31fe1..b63fb020909075 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1978,15 +1978,6 @@ int kernel_execve(const char *kernel_filename,
return retval;
 }
 
-static int do_execve(struct filename *filename,
-   const char __user *const __user *__argv,
-   const char __user *const __user *__envp)
-{
-   struct user_arg_ptr argv = { .ptr.native = __argv };
-   struct user_arg_ptr envp = { .ptr.native = __envp };
-   return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
-}
-
 static int do_execveat(int fd, struct filename *filename,
const char __user *const __user *__argv,
const char __user *const __user *__envp,
@@ -2060,7 +2051,7 @@ SYSCALL_DEFINE3(execve,
const char __user *const __user *, argv,
const char __user *const __user *, envp)
 {
-   return do_execve(getname(filename), argv, envp);
+   return do_execveat(AT_FDCWD, getname(filename), argv, envp, 0);
 }
 
 SYSCALL_DEFINE5(execveat,
-- 
2.30.1



cleanup compat exec handling

2021-03-26 Thread Christoph Hellwig
Hi all,

this series cleans up the exec code by sharing the native vs compat
versions less awkwardly.

Diffstat:
 arch/arm64/include/asm/unistd32.h  |4 
 arch/mips/kernel/syscalls/syscall_n32.tbl  |4 
 arch/mips/kernel/syscalls/syscall_o32.tbl  |4 
 arch/parisc/kernel/syscalls/syscall.tbl|4 
 arch/powerpc/kernel/syscalls/syscall.tbl   |4 
 arch/s390/kernel/syscalls/syscall.tbl  |4 
 arch/sparc/kernel/syscalls.S   |4 
 arch/x86/entry/syscall_x32.c   |2 
 arch/x86/entry/syscalls/syscall_32.tbl |4 
 arch/x86/entry/syscalls/syscall_64.tbl |4 
 fs/exec.c  |  136 +++--
 include/linux/compat.h |7 -
 include/uapi/asm-generic/unistd.h  |4 
 tools/include/uapi/asm-generic/unistd.h|4 
 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl |4 
 tools/perf/arch/s390/entry/syscalls/syscall.tbl|4 
 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl  |4 
 17 files changed, 53 insertions(+), 148 deletions(-)


Re: [PATCH v3 11/17] riscv: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 15:08, Andreas Schwab a écrit :

On Mär 26 2021, Christophe Leroy wrote:


diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index f8f15332caa2..e7c91ee478d1 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -20,6 +20,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #include 

  #include 
@@ -228,10 +229,8 @@ static void __init parse_dtb(void)
}
  
  	pr_err("No DTB passed to the kernel\n");

-#ifdef CONFIG_CMDLINE_FORCE
-   strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+   cmdline_build(boot_command_line, NULL, COMMAND_LINE_SIZE);
pr_info("Forcing kernel command line to: %s\n", boot_command_line);


Shouldn't that message become conditional in some way?



You are right, I did something similar on ARM but looks like I missed it on 
RISCV.

Christophe


[PATCH v3 1/1] hotplug-cpu.c: show 'last online CPU' error in dlpar_cpu_offline()

2021-03-26 Thread Daniel Henrique Barboza
One of the reasons that dlpar_cpu_offline can fail is when attempting to
offline the last online CPU of the kernel. This can be observed in a
pseries QEMU guest that has hotplugged CPUs. If the user offlines all
other CPUs of the guest, and a hotplugged CPU is now the last online
CPU, trying to reclaim it will fail. See [1] for an example.

The current error message in this situation returns rc with -EBUSY and a
generic explanation, e.g.:

pseries-hotplug-cpu: Failed to offline CPU PowerPC,POWER9, rc: -16

EBUSY can be caused by other conditions, such as cpu_hotplug_disable
being true. Throwing a more specific error message for this case,
instead of just "Failed to offline CPU", makes it clearer that the error
is in fact a known error situation instead of other generic/unknown
cause.

This patch adds a 'last online' check in dlpar_cpu_offline() to catch
the 'last online CPU' offline error, returning a more informative error
message:

pseries-hotplug-cpu: Unable to remove last online CPU PowerPC,POWER9

[1] https://bugzilla.redhat.com/1911414

Signed-off-by: Daniel Henrique Barboza 
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c 
b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 12cbffd3c2e3..4b9df4d645b4 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -271,6 +271,19 @@ static int dlpar_offline_cpu(struct device_node *dn)
if (!cpu_online(cpu))
break;
 
+   /* device_offline() will return -EBUSY (via cpu_down())
+* if there is only one CPU left. Check it here to fail
+* earlier and with a more informative error message,
+* while also retaining the cpu_add_remove_lock to be 
sure
+* that no CPUs are being online/offlined during this
+* check.
+*/
+   if (num_online_cpus() == 1) {
+   pr_warn("Unable to remove last online CPU 
%pOFn\n", dn);
+   rc = -EBUSY;
+   goto out_unlock;
+   }
+
cpu_maps_update_done();
rc = device_offline(get_cpu_device(cpu));
if (rc)
@@ -283,6 +296,7 @@ static int dlpar_offline_cpu(struct device_node *dn)
thread);
}
}
+out_unlock:
cpu_maps_update_done();
 
 out:
-- 
2.30.2



[PATCH v3 0/1] show 'last online CPU' error in dlpar_cpu_offline()

2021-03-26 Thread Daniel Henrique Barboza
changes in v3 after Daniel Axtens review:
- fixed typo in commit mgs
- fixed block comment format to make checkpatch happy
v2 link:
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210323205056.52768-2-danielhb...@gmail.com/

changes in v2 after Michael Ellerman review:
- moved the verification code from dlpar_cpu_remove() to
  dlpar_cpu_offline(), while holding cpu_add_remove_lock
- reworded the commit message and code comment
v1 link: 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210305173845.451158-1-danielhb...@gmail.com/


Daniel Henrique Barboza (1):
  hotplug-cpu.c: show 'last online CPU' error in dlpar_cpu_offline()

 arch/powerpc/platforms/pseries/hotplug-cpu.c | 14 ++
 1 file changed, 14 insertions(+)

-- 
2.30.2



Re: [PATCH v3 11/17] riscv: Convert to GENERIC_CMDLINE

2021-03-26 Thread Andreas Schwab
On Mär 26 2021, Christophe Leroy wrote:

> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index f8f15332caa2..e7c91ee478d1 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> @@ -228,10 +229,8 @@ static void __init parse_dtb(void)
>   }
>  
>   pr_err("No DTB passed to the kernel\n");
> -#ifdef CONFIG_CMDLINE_FORCE
> - strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> + cmdline_build(boot_command_line, NULL, COMMAND_LINE_SIZE);
>   pr_info("Forcing kernel command line to: %s\n", boot_command_line);

Shouldn't that message become conditional in some way?

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [PATCH v2 1/1] hotplug-cpu.c: show 'last online CPU' error in dlpar_cpu_offline()

2021-03-26 Thread Daniel Henrique Barboza

Hey Daniel,

On 3/26/21 2:24 AM, Daniel Axtens wrote:

Hi Daniel,

Two small nitpicks:


This patch adds a 'last online' check in dlpar_cpu_offline() to catch
the 'last online CPU' offline error, eturning a more informative error

^--- s/eturning/returning/;



+   /* device_offline() will return -EBUSY (via cpu_down())
+* if there is only one CPU left. Check it here to fail
+* earlier and with a more informative error message,
+* while also retaining the cpu_add_remove_lock to be 
sure
+* that no CPUs are being online/offlined during this
+* check. */


Checkpatch has a small issue with this comment:

WARNING: Block comments use a trailing */ on a separate line
#50: FILE: arch/powerpc/platforms/pseries/hotplug-cpu.c:279:
+* check. */

Apart from that, this patch seems sane to me, but I haven't been able to
test it.



Thanks for the review, and for letting me know of the existence of
'scripts/checkpatch.pl' to verify the patches before posting. I'll
send a v3.


Thanks,


DHB




Kind regards,
Daniel



[PATCH v3 17/17] cmdline: Remove CONFIG_CMDLINE_EXTEND

2021-03-26 Thread Christophe Leroy
All architectures providing CONFIG_CMDLINE_EXTEND
are now converted to GENERIC_CMDLINE.

This configuration item is not used anymore, drop it.

Signed-off-by: Christophe Leroy 
---
 init/Kconfig | 6 --
 1 file changed, 6 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index af0d84662cc2..fa002e3765ab 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -163,12 +163,6 @@ config CMDLINE_FORCE
  arguments provided by the bootloader.
 endchoice
 
-config CMDLINE_EXTEND
-   bool
-   default CMDLINE_APPEND
-   help
- To be removed once all architectures are converted to generic CMDLINE
-
 config COMPILE_TEST
bool "Compile also drivers which will not load"
depends on HAS_IOMEM
-- 
2.25.0



[PATCH v3 16/17] mips: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/mips/Kconfig |  1 +
 arch/mips/Kconfig.debug   | 44 ---
 arch/mips/configs/ar7_defconfig   |  1 -
 arch/mips/configs/bcm47xx_defconfig   |  1 -
 arch/mips/configs/bcm63xx_defconfig   |  1 -
 arch/mips/configs/bmips_be_defconfig  |  1 -
 arch/mips/configs/bmips_stb_defconfig |  1 -
 arch/mips/configs/capcella_defconfig  |  1 -
 arch/mips/configs/ci20_defconfig  |  1 -
 arch/mips/configs/cu1000-neo_defconfig|  1 -
 arch/mips/configs/cu1830-neo_defconfig|  1 -
 arch/mips/configs/e55_defconfig   |  1 -
 arch/mips/configs/generic_defconfig   |  1 -
 arch/mips/configs/gpr_defconfig   |  1 -
 arch/mips/configs/loongson3_defconfig |  1 -
 arch/mips/configs/mpc30x_defconfig|  1 -
 arch/mips/configs/rt305x_defconfig|  1 -
 arch/mips/configs/tb0219_defconfig|  1 -
 arch/mips/configs/tb0226_defconfig|  1 -
 arch/mips/configs/tb0287_defconfig|  1 -
 arch/mips/configs/workpad_defconfig   |  1 -
 arch/mips/configs/xway_defconfig  |  1 -
 arch/mips/kernel/relocate.c   |  4 +--
 arch/mips/kernel/setup.c  | 40 ++---
 arch/mips/pic32/pic32mzda/early_console.c |  2 +-
 arch/mips/pic32/pic32mzda/init.c  |  2 --
 26 files changed, 5 insertions(+), 108 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d89efba3d8a4..a65ce9ddbfce 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -24,6 +24,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default command line, you can supply some command-line options at
- build time by entering them here.  In other cases you can specify
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting this option to 'Y' you will have your kernel ignore
- command line arguments from firmware or second stage bootloader.
- Instead, the built-in command line will be used exclusively.
-
- Normally, you will choose 'N' here.
-
 config SB1XXX_CORELIS
bool "Corelis Debugger"
depends on SIBYTE_SB1xxx_SOC
diff --git a/arch/mips/configs/ar7_defconfig b/arch/mips/configs/ar7_defconfig
index cf9c6329b807..5e8adcd799d0 100644
--- a/arch/mips/configs/ar7_defconfig
+++ b/arch/mips/configs/ar7_defconfig
@@ -120,5 +120,4 @@ CONFIG_SQUASHFS=y
 # CONFIG_ENABLE_MUST_CHECK is not set
 CONFIG_STRIP_ASM_SYMS=y
 CONFIG_DEBUG_FS=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="rootfstype=squashfs,jffs2"
diff --git a/arch/mips/configs/bcm47xx_defconfig 
b/arch/mips/configs/bcm47xx_defconfig
index 91ce75edbfb4..690f423509f0 100644
--- a/arch/mips/configs/bcm47xx_defconfig
+++ b/arch/mips/configs/bcm47xx_defconfig
@@ -77,5 +77,4 

[PATCH v3 15/17] x86: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/x86/Kconfig| 45 ++---
 arch/x86/kernel/setup.c | 17 ++
 drivers/firmware/efi/libstub/x86-stub.c | 26 +++---
 3 files changed, 18 insertions(+), 70 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2792879d398e..66b384228ca3 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -104,6 +104,7 @@ config X86
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_USE_SYM_ANNOTATIONS
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
+   select ARCH_WANT_CMDLINE_PREPEND_BY_DEFAULT
select ARCH_WANT_DEFAULT_BPF_JITif X86_64
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
select ARCH_WANT_HUGE_PMD_SHARE
@@ -118,6 +119,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2358,49 +2360,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d883176ef2ce..93ac57ea3e64 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -5,6 +5,7 @@
  * This file contains the setup_arch() code, which handles the 
architecture-dependent
  * parts of early kernel initialization.
  */
+#include 
 #include 
 #include 
 #include 
@@ -161,9 +162,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -883,18 +881,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
+   cmdline_build(boot_command_line, boot_command_line, COMMAND_LINE_SIZE);
 
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..5413aff010ec 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -6,6 +6,7 @@
  *
  * --- */
 
+#include 
 #include 
 

[PATCH v3 13/17] sparc: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/sparc/Kconfig   | 18 +-
 arch/sparc/prom/bootstr_64.c |  2 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 164a5254c91c..2a197f3a2549 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -50,6 +50,7 @@ config SPARC
select NEED_DMA_MAP_STATE
select NEED_SG_DMA_LENGTH
select SET_FS
+   select GENERIC_CMDLINE if SPARC64
 
 config SPARC32
def_bool !64BIT
@@ -313,23 +314,6 @@ config SCHED_MC
  making when dealing with multi-core CPU chips at a cost of slightly
  increased overhead in some places. If unsure say N here.
 
-config CMDLINE_BOOL
-   bool "Default bootloader kernel arguments"
-   depends on SPARC64
-
-config CMDLINE
-   string "Initial kernel command string"
-   depends on CMDLINE_BOOL
-   default "console=ttyS0,9600 root=/dev/sda1"
-   help
- Say Y here if you want to be able to pass default arguments to
- the kernel. This will be overridden by the bootloader, if you
- use one (such as SILO). This is most useful if you want to boot
- a kernel from TFTP, and want default options to be available
- with having them passed on the command line.
-
- NOTE: This option WILL override the PROM bootargs setting!
-
 config SUN_PM
bool
default y if SPARC32
diff --git a/arch/sparc/prom/bootstr_64.c b/arch/sparc/prom/bootstr_64.c
index f1cc34d99eec..4853a45b3de9 100644
--- a/arch/sparc/prom/bootstr_64.c
+++ b/arch/sparc/prom/bootstr_64.c
@@ -25,7 +25,7 @@ struct {
char bootstr_buf[BARG_LEN];
 } bootstr_info = {
.bootstr_len = BARG_LEN,
-#ifdef CONFIG_CMDLINE
+#if CONFIG_CMDLINE != ""
.bootstr_valid = 1,
.bootstr_buf = CONFIG_CMDLINE,
 #endif
-- 
2.25.0



[PATCH v3 12/17] sh: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/sh/Kconfig | 30 +
 arch/sh/configs/ap325rxa_defconfig  |  2 +-
 arch/sh/configs/dreamcast_defconfig |  2 +-
 arch/sh/configs/ecovec24-romimage_defconfig |  2 +-
 arch/sh/configs/ecovec24_defconfig  |  2 +-
 arch/sh/configs/edosk7760_defconfig |  2 +-
 arch/sh/configs/espt_defconfig  |  2 +-
 arch/sh/configs/j2_defconfig|  2 +-
 arch/sh/configs/kfr2r09-romimage_defconfig  |  2 +-
 arch/sh/configs/kfr2r09_defconfig   |  2 +-
 arch/sh/configs/lboxre2_defconfig   |  2 +-
 arch/sh/configs/microdev_defconfig  |  2 +-
 arch/sh/configs/migor_defconfig |  2 +-
 arch/sh/configs/polaris_defconfig   |  2 +-
 arch/sh/configs/r7780mp_defconfig   |  2 +-
 arch/sh/configs/r7785rp_defconfig   |  2 +-
 arch/sh/configs/rsk7201_defconfig   |  2 +-
 arch/sh/configs/rsk7203_defconfig   |  2 +-
 arch/sh/configs/rts7751r2d1_defconfig   |  2 +-
 arch/sh/configs/rts7751r2dplus_defconfig|  2 +-
 arch/sh/configs/sdk7780_defconfig   |  2 +-
 arch/sh/configs/sdk7786_defconfig   |  2 +-
 arch/sh/configs/se7206_defconfig|  2 +-
 arch/sh/configs/se7343_defconfig|  2 +-
 arch/sh/configs/se7712_defconfig|  2 +-
 arch/sh/configs/se7721_defconfig|  2 +-
 arch/sh/configs/se7724_defconfig|  2 +-
 arch/sh/configs/se7751_defconfig|  2 +-
 arch/sh/configs/se7780_defconfig|  2 +-
 arch/sh/configs/sh03_defconfig  |  2 +-
 arch/sh/configs/sh2007_defconfig|  2 +-
 arch/sh/configs/sh7757lcr_defconfig |  2 +-
 arch/sh/configs/sh7763rdp_defconfig |  2 +-
 arch/sh/configs/shmin_defconfig |  2 +-
 arch/sh/configs/shx3_defconfig  |  2 +-
 arch/sh/configs/titan_defconfig |  2 +-
 arch/sh/configs/ul2_defconfig   |  2 +-
 arch/sh/kernel/setup.c  | 11 ++--
 38 files changed, 39 insertions(+), 74 deletions(-)

diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index e798e55915c2..fab84f62448c 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -16,6 +16,7 @@ config SUPERH
select CPU_NO_EFFICIENT_FFS
select DMA_DECLARE_COHERENT
select GENERIC_ATOMIC64
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE if SH_SH03 || SH_DREAMCAST
select GENERIC_IDLE_POLL_SETUP
select GENERIC_IRQ_SHOW
@@ -742,35 +743,6 @@ config ROMIMAGE_MMCIF
  first part of the romImage which in turn loads the rest the kernel
  image to RAM using the MMCIF hardware block.
 
-choice
-   prompt "Kernel command line"
-   optional
-   default CMDLINE_OVERWRITE
-   help
- Setting this option allows the kernel command line arguments
- to be set.
-
-config CMDLINE_OVERWRITE
-   bool "Overwrite bootloader kernel arguments"
-   help
- Given string will overwrite any arguments passed in by
- a bootloader.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- Given string will be concatenated with arguments passed in
- by a bootloader.
-
-endchoice
-
-config CMDLINE
-   string "Kernel command line arguments string"
-   depends on CMDLINE_OVERWRITE || CMDLINE_EXTEND
-   default "console=ttySC1,115200"
-
-endmenu
-
 menu "Bus options"
 
 config SUPERHYWAY
diff --git a/arch/sh/configs/ap325rxa_defconfig 
b/arch/sh/configs/ap325rxa_defconfig
index 5193b3e099b9..3997aa49c75b 100644
--- a/arch/sh/configs/ap325rxa_defconfig
+++ b/arch/sh/configs/ap325rxa_defconfig
@@ -15,7 +15,7 @@ CONFIG_SH_AP325RXA=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_SECCOMP=y
 CONFIG_PREEMPT=y
-CONFIG_CMDLINE_OVERWRITE=y
+CONFIG_CMDLINE_FORCE=y
 CONFIG_CMDLINE="console=tty1 console=ttySC5,38400 root=/dev/nfs ip=dhcp"
 CONFIG_NET=y
 CONFIG_PACKET=y
diff --git a/arch/sh/configs/dreamcast_defconfig 
b/arch/sh/configs/dreamcast_defconfig
index 6a82c7b8ff32..ac030c1a351e 100644
--- a/arch/sh/configs/dreamcast_defconfig
+++ b/arch/sh/configs/dreamcast_defconfig
@@ -22,7 +22,7 @@ CONFIG_NR_DMA_CHANNELS_BOOL=y
 CONFIG_NR_DMA_CHANNELS=9
 CONFIG_SECCOMP=y
 CONFIG_PREEMPT=y
-CONFIG_CMDLINE_OVERWRITE=y
+CONFIG_CMDLINE_FORCE=y
 CONFIG_CMDLINE="console=ttySC1,115200 panic=3"
 CONFIG_MAPLE=y
 CONFIG_PCI=y
diff --git a/arch/sh/configs/ecovec24-romimage_defconfig 
b/arch/sh/configs/ecovec24-romimage_defconfig
index 5c60e71d839e..db78857ae30f 100644
--- a/arch/sh/configs/ecovec24-romimage_defconfig
+++ b/arch/sh/configs/ecovec24-romimage_defconfig
@@ -14,7 +14,7 @@ CONFIG_FLATMEM_MANUAL=y
 CONFIG_SH_ECOVEC=y
 # CONFIG_SH_TIMER_TMU is not set
 CONFIG_KEXEC=y
-CONFIG_CMDLINE_OVERWRITE=y
+CONFIG_CMDLINE_FORCE=y
 CONFIG_CMDLINE="console=ttySC0,115200"
 # CONFIG_SUSPEND is not set
 

[PATCH v3 14/17] xtensa: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/xtensa/Kconfig | 15 +--
 arch/xtensa/configs/audio_kc705_defconfig   |  1 -
 arch/xtensa/configs/common_defconfig|  1 -
 arch/xtensa/configs/generic_kc705_defconfig |  1 -
 arch/xtensa/configs/iss_defconfig   |  1 -
 arch/xtensa/configs/nommu_kc705_defconfig   |  1 -
 arch/xtensa/configs/smp_lx200_defconfig |  1 -
 arch/xtensa/configs/virt_defconfig  |  1 -
 arch/xtensa/configs/xip_kc705_defconfig |  1 -
 arch/xtensa/kernel/setup.c  | 10 ++
 10 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 9ad6b7b82707..42309f5e9cda 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -16,6 +16,7 @@ config XTENSA
select COMMON_CLK
select DMA_REMAP if MMU
select GENERIC_ATOMIC64
+   select GENERIC_CMDLINE
select GENERIC_IRQ_SHOW
select GENERIC_PCI_IOMAP
select GENERIC_SCHED_CLOCK
@@ -353,20 +354,6 @@ config GENERIC_CALIBRATE_DELAY
help
  The BogoMIPS value can easily be derived from the CPU frequency.
 
-config CMDLINE_BOOL
-   bool "Default bootloader kernel arguments"
-
-config CMDLINE
-   string "Initial kernel command string"
-   depends on CMDLINE_BOOL
-   default "console=ttyS0,38400 root=/dev/ram"
-   help
- On some architectures (EBSA110 and CATS), there is currently no way
- for the boot loader to pass arguments to the kernel. For these
- architectures, you should supply some command-line options at build
- time by entering them here. As a minimum, you should specify the
- memory size and the root device (e.g., mem=64M root=/dev/nfs).
-
 config USE_OF
bool "Flattened Device Tree support"
select OF
diff --git a/arch/xtensa/configs/audio_kc705_defconfig 
b/arch/xtensa/configs/audio_kc705_defconfig
index 3be62da8089b..5f8661a33ab4 100644
--- a/arch/xtensa/configs/audio_kc705_defconfig
+++ b/arch/xtensa/configs/audio_kc705_defconfig
@@ -27,7 +27,6 @@ CONFIG_PREEMPT=y
 CONFIG_HIGHMEM=y
 # CONFIG_PCI is not set
 CONFIG_XTENSA_PLATFORM_XTFPGA=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 
console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=0x3800@0"
 CONFIG_USE_OF=y
 CONFIG_BUILTIN_DTB_SOURCE="kc705"
diff --git a/arch/xtensa/configs/common_defconfig 
b/arch/xtensa/configs/common_defconfig
index fa9389869154..6467ebcbb080 100644
--- a/arch/xtensa/configs/common_defconfig
+++ b/arch/xtensa/configs/common_defconfig
@@ -6,7 +6,6 @@ CONFIG_MODULES=y
 CONFIG_MODVERSIONS=y
 CONFIG_XTENSA_PLATFORM_XT2000=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="console=ttyS0,38400 ip=bootp root=nfs 
nfsroot=/opt/montavista/pro/devkit/xtensa/linux_be/target memmap=128M@0"
 CONFIG_BINFMT_MISC=y
 CONFIG_NET=y
diff --git a/arch/xtensa/configs/generic_kc705_defconfig 
b/arch/xtensa/configs/generic_kc705_defconfig
index e9d6b6f6eca1..8984c4e68a42 100644
--- a/arch/xtensa/configs/generic_kc705_defconfig
+++ b/arch/xtensa/configs/generic_kc705_defconfig
@@ -26,7 +26,6 @@ CONFIG_PREEMPT=y
 CONFIG_HIGHMEM=y
 # CONFIG_PCI is not set
 CONFIG_XTENSA_PLATFORM_XTFPGA=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 
console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=0x3800@0"
 CONFIG_USE_OF=y
 CONFIG_BUILTIN_DTB_SOURCE="kc705"
diff --git a/arch/xtensa/configs/iss_defconfig 
b/arch/xtensa/configs/iss_defconfig
index 32ce8fb068f0..996ad115264d 100644
--- a/arch/xtensa/configs/iss_defconfig
+++ b/arch/xtensa/configs/iss_defconfig
@@ -2,7 +2,6 @@ CONFIG_SYSVIPC=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_EXPERT=y
 # CONFIG_PCI is not set
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="console=ttyS0,38400 eth0=tuntap,,tap0 
ip=192.168.168.5:192.168.168.1 root=nfs 
nfsroot=192.168.168.1:/opt/montavista/pro/devkit/xtensa/linux_be/target 
memmap=128M@0"
 # CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
 CONFIG_NET=y
diff --git a/arch/xtensa/configs/nommu_kc705_defconfig 
b/arch/xtensa/configs/nommu_kc705_defconfig
index 88b2e222d4bf..54250bc74885 100644
--- a/arch/xtensa/configs/nommu_kc705_defconfig
+++ b/arch/xtensa/configs/nommu_kc705_defconfig
@@ -33,7 +33,6 @@ CONFIG_PREEMPT=y
 CONFIG_MEMMAP_CACHEATTR=0xfff2442f
 # CONFIG_PCI is not set
 CONFIG_XTENSA_PLATFORM_XTFPGA=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0x9d050020,115200n8 
console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=256M@0x6000"
 CONFIG_USE_OF=y
 CONFIG_BUILTIN_DTB_SOURCE="kc705_nommu"
diff --git a/arch/xtensa/configs/smp_lx200_defconfig 
b/arch/xtensa/configs/smp_lx200_defconfig
index a47c85638ec1..58b284fd627f 100644
--- a/arch/xtensa/configs/smp_lx200_defconfig
+++ b/arch/xtensa/configs/smp_lx200_defconfig
@@ -30,7 +30,6 

[PATCH v3 11/17] riscv: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/riscv/Kconfig| 44 +--
 arch/riscv/kernel/setup.c |  5 ++---
 2 files changed, 3 insertions(+), 46 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 87d7b52f278f..3dbd50bed037 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -39,6 +39,7 @@ config RISCV
select EDAC_SUPPORT
select GENERIC_ARCH_TOPOLOGY if SMP
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_EARLY_IOREMAP
select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
select GENERIC_IOREMAP
@@ -390,49 +391,6 @@ endmenu
 
 menu "Boot options"
 
-config CMDLINE
-   string "Built-in kernel command line"
-   help
- For most platforms, the arguments for the kernel's command line
- are provided at run-time, during boot. However, there are cases
- where either no arguments are being provided or the provided
- arguments are insufficient or even invalid.
-
- When that occurs, it is possible to define a built-in command
- line here and choose how the kernel should use it later on.
-
-choice
-   prompt "Built-in command line usage" if CMDLINE != ""
-   default CMDLINE_FALLBACK
-   help
- Choose how the kernel will handle the provided built-in command
- line.
-
-config CMDLINE_FALLBACK
-   bool "Use bootloader kernel arguments if available"
-   help
- Use the built-in command line as fallback in case we get nothing
- during boot. This is the default behaviour.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided during boot will be
- appended to the built-in command line. This is useful in
- cases where the provided arguments are insufficient and
- you don't want to or cannot modify them.
-
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   help
- Always use the built-in command line, even if we get one during
- boot. This is useful in case you need to override the provided
- command line on systems where you don't have or want control
- over it.
-
-endchoice
-
 config EFI_STUB
bool
 
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index f8f15332caa2..e7c91ee478d1 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -228,10 +229,8 @@ static void __init parse_dtb(void)
}
 
pr_err("No DTB passed to the kernel\n");
-#ifdef CONFIG_CMDLINE_FORCE
-   strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+   cmdline_build(boot_command_line, NULL, COMMAND_LINE_SIZE);
pr_info("Forcing kernel command line to: %s\n", boot_command_line);
-#endif
 }
 
 void __init setup_arch(char **cmdline_p)
-- 
2.25.0



[PATCH v3 10/17] openrisc: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/openrisc/Kconfig | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 591acc5990dc..ca1d0f18fe16 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -25,6 +25,7 @@ config OPENRISC
select HAVE_UID16
select GENERIC_ATOMIC64
select GENERIC_CLOCKEVENTS_BROADCAST
+   select GENERIC_CMDLINE
select GENERIC_STRNCPY_FROM_USER
select GENERIC_STRNLEN_USER
select GENERIC_SMP_IDLE_THREAD
@@ -162,15 +163,6 @@ config OPENRISC_HAVE_SHADOW_GPRS
  On SMP systems, this feature is mandatory.
  On a unicore system it's safe to say N here if you are unsure.
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- On some architectures there is currently no way for the boot loader
- to pass arguments to the kernel. For these architectures, you should
- supply some command-line options at build time by entering them
- here.
-
 menu "Debugging options"
 
 config JUMP_UPON_UNHANDLED_EXCEPTION
-- 
2.25.0



[PATCH v3 09/17] nios2: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/nios2/Kconfig| 24 +---
 arch/nios2/kernel/setup.c | 13 -
 2 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
index c24955c81c92..f66c97b15813 100644
--- a/arch/nios2/Kconfig
+++ b/arch/nios2/Kconfig
@@ -90,31 +90,9 @@ config NIOS2_ALIGNMENT_TRAP
 
 comment "Boot options"
 
-config CMDLINE_BOOL
-   bool "Default bootloader kernel arguments"
-   default y
-
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel. For these platforms, you can supply
- some command-line options at build time by entering them here.  In
- other cases you can specify kernel args so that you don't have
- to set them up in board prom initialization routines.
-
-config CMDLINE_FORCE
-   bool "Force default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- Set this to have arguments from the default kernel command string
- override those passed by the boot loader.
-
 config NIOS2_CMDLINE_IGNORE_DTB
bool "Ignore kernel command string from DTB"
-   depends on CMDLINE_BOOL
+   depends on CMDLINE != ""
depends on !CMDLINE_FORCE
default y
help
diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
index d2f21957e99c..42464f457a6d 100644
--- a/arch/nios2/kernel/setup.c
+++ b/arch/nios2/kernel/setup.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -108,7 +109,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, 
unsigned r5, unsigned r6,
   unsigned r7)
 {
unsigned dtb_passed = 0;
-   char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
+   char cmdline_passed[COMMAND_LINE_SIZE] = { 0, };
 
 #if defined(CONFIG_NIOS2_PASS_CMDLINE)
if (r4 == 0x534f494e) { /* r4 is magic NIOS */
@@ -127,14 +128,8 @@ asmlinkage void __init nios2_boot_init(unsigned r4, 
unsigned r5, unsigned r6,
 
early_init_devtree((void *)dtb_passed);
 
-#ifndef CONFIG_CMDLINE_FORCE
-   if (cmdline_passed[0])
-   strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
-#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
-   else
-   strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#endif
-#endif
+   if (cmdline_passed[0] || IS_ENABLED(CONFIG_NIOS2_CMDLINE_IGNORE_DTB))
+   cmdline_build(boot_command_line, cmdline_passed, 
COMMAND_LINE_SIZE);
 
parse_early_param();
 }
-- 
2.25.0



[PATCH v3 08/17] microblaze: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/microblaze/Kconfig   | 24 +---
 arch/microblaze/configs/mmu_defconfig |  2 +-
 arch/microblaze/kernel/head.S |  4 ++--
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 0660f47012bc..1242f34bc2a2 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -15,6 +15,7 @@ config MICROBLAZE
select COMMON_CLK
select DMA_DIRECT_REMAP
select GENERIC_ATOMIC64
+   select GENERIC_CMDLINE
select GENERIC_CPU_DEVICES
select GENERIC_IDLE_POLL_SETUP
select GENERIC_IRQ_PROBE
@@ -93,29 +94,6 @@ source "kernel/Kconfig.hz"
 config MMU
def_bool y
 
-comment "Boot options"
-
-config CMDLINE_BOOL
-   bool "Default bootloader kernel arguments"
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   default "console=ttyUL0,115200"
-   help
- On some architectures there is currently no way for the boot loader
- to pass arguments to the kernel. For these architectures, you should
- supply some command-line options at build time by entering them
- here.
-
-config CMDLINE_FORCE
-   bool "Force default kernel command string"
-   depends on CMDLINE_BOOL
-   default n
-   help
- Set this to have arguments from the default kernel command string
- override those passed by the boot loader.
-
 endmenu
 
 menu "Kernel features"
diff --git a/arch/microblaze/configs/mmu_defconfig 
b/arch/microblaze/configs/mmu_defconfig
index 51337fffb947..b4d2219d0a8f 100644
--- a/arch/microblaze/configs/mmu_defconfig
+++ b/arch/microblaze/configs/mmu_defconfig
@@ -16,7 +16,7 @@ CONFIG_XILINX_MICROBLAZE0_USE_DIV=1
 CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL=2
 CONFIG_XILINX_MICROBLAZE0_USE_FPU=2
 CONFIG_HZ_100=y
-CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE="console=ttyUL0,115200"
 CONFIG_CMDLINE_FORCE=y
 CONFIG_HIGHMEM=y
 CONFIG_PCI_XILINX=y
diff --git a/arch/microblaze/kernel/head.S b/arch/microblaze/kernel/head.S
index ec2fcb545e64..605b18c86ac8 100644
--- a/arch/microblaze/kernel/head.S
+++ b/arch/microblaze/kernel/head.S
@@ -105,7 +105,7 @@ _copy_fdt:
addik   r3, r3, -4 /* descrement loop */
 no_fdt_arg:
 
-#ifndef CONFIG_CMDLINE_BOOL
+#if CONFIG_CMDLINE == ""
 /*
  * handling command line
  * copy command line directly to cmd_line placed in data section.
@@ -126,7 +126,7 @@ _copy_command_line:
addik   r5, r4, 0   /* add new space for command line */
tovirt(r5,r5)
 skip:
-#endif /* CONFIG_CMDLINE_BOOL */
+#endif /* CONFIG_CMDLINE */
 
 #ifdef NOT_COMPILE
 /* save bram context */
-- 
2.25.0



[PATCH v3 07/17] hexagon: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/hexagon/Kconfig| 11 +--
 arch/hexagon/kernel/setup.c | 10 ++
 2 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 44a409967af1..1e69c99bae6b 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -18,6 +18,7 @@ config HEXAGON
select HAVE_PERF_EVENTS
# GENERIC_ALLOCATOR is used by dma_alloc_coherent()
select GENERIC_ALLOCATOR
+   select GENERIC_CMDLINE
select GENERIC_IRQ_SHOW
select HAVE_ARCH_KGDB
select HAVE_ARCH_TRACEHOOK
@@ -91,16 +92,6 @@ config HEXAGON_ARCH_VERSION
int "Architecture version"
default 2
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- On some platforms, there is currently no way for the boot loader
- to pass arguments to the kernel. For these, you should supply some
- command-line options at build time by entering them here.  At a
- minimum, you should specify the memory size and the root device
- (e.g., mem=64M root=/dev/nfs).
-
 config SMP
bool "Multi-Processing support"
help
diff --git a/arch/hexagon/kernel/setup.c b/arch/hexagon/kernel/setup.c
index 1880d9beaf2b..be586cea4076 100644
--- a/arch/hexagon/kernel/setup.c
+++ b/arch/hexagon/kernel/setup.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -22,7 +23,6 @@
 #include 
 
 char cmd_line[COMMAND_LINE_SIZE];
-static char default_command_line[COMMAND_LINE_SIZE] __initdata = 
CONFIG_CMDLINE;
 
 int on_simulator;
 
@@ -38,8 +38,6 @@ void calibrate_delay(void)
 
 void __init setup_arch(char **cmdline_p)
 {
-   char *p = _cmdline_buffer;
-
/*
 * These will eventually be pulled in via either some hypervisor
 * or devicetree description.  Hardwiring for now.
@@ -65,11 +63,7 @@ void __init setup_arch(char **cmdline_p)
else
on_simulator = 0;
 
-   if (p[0] != '\0')
-   strlcpy(boot_command_line, p, COMMAND_LINE_SIZE);
-   else
-   strlcpy(boot_command_line, default_command_line,
-   COMMAND_LINE_SIZE);
+   cmdline_build(boot_command_line, external_cmdline_buffer, 
COMMAND_LINE_SIZE);
 
/*
 * boot_command_line and the value set up by setup_arch
-- 
2.25.0



[PATCH v3 06/17] arm64: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/arm64/Kconfig | 33 +-
 arch/arm64/kernel/idreg-override.c |  9 
 2 files changed, 5 insertions(+), 37 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 5656e7aacd69..eeff7730ccf0 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -105,6 +105,7 @@ config ARM64
select GENERIC_ALLOCATOR
select GENERIC_ARCH_TOPOLOGY
select GENERIC_CLOCKEVENTS_BROADCAST
+   select GENERIC_CMDLINE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
select GENERIC_EARLY_IOREMAP
@@ -1831,38 +1832,6 @@ config ARM64_ACPI_PARKING_PROTOCOL
  protocol even if the corresponding data is present in the ACPI
  MADT table.
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- Provide a set of default command-line options at build time by
- entering them here. As a minimum, you should specify the the
- root device (e.g. root=/dev/nfs).
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-   help
- Choose how the kernel will handle the provided default kernel
- command line string.
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   help
- Always use the default kernel command string, even if the boot
- loader passes other arguments to the kernel.
- This is useful if you cannot or don't want to change the
- command-line options your boot loader passes to the kernel.
-
-endchoice
-
 config EFI_STUB
bool
 
diff --git a/arch/arm64/kernel/idreg-override.c 
b/arch/arm64/kernel/idreg-override.c
index 83f1c4b92095..8bc955cdcf82 100644
--- a/arch/arm64/kernel/idreg-override.c
+++ b/arch/arm64/kernel/idreg-override.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -187,12 +188,10 @@ static __init const u8 *get_bootargs_cmdline(void)
 static __init void parse_cmdline(void)
 {
const u8 *prop = get_bootargs_cmdline();
+   static char __initdata cmdline[COMMAND_LINE_SIZE];
 
-   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop)
-   __parse_cmdline(CONFIG_CMDLINE, true);
-
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
-   __parse_cmdline(prop, true);
+   cmdline_build(cmdline, prop, COMMAND_LINE_SIZE);
+   __parse_cmdline(cmdline, true);
 }
 
 /* Keep checkers quiet */
-- 
2.25.0



[PATCH v3 05/17] arm: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This converts the architecture to GENERIC_CMDLINE.

Signed-off-by: Christophe Leroy 
---
 arch/arm/Kconfig  | 38 +--
 arch/arm/kernel/atags_parse.c | 15 +-
 2 files changed, 6 insertions(+), 47 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 5da96f5df48f..67bc75f2da81 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -50,6 +50,7 @@ config ARM
select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+   select GENERIC_CMDLINE if ATAGS
select GENERIC_IRQ_IPI if SMP
select GENERIC_CPU_AUTOPROBE
select GENERIC_EARLY_IOREMAP
@@ -1740,43 +1741,6 @@ config ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND
 
 endchoice
 
-config CMDLINE
-   string "Default kernel command string"
-   default ""
-   help
- On some architectures (e.g. CATS), there is currently no way
- for the boot loader to pass arguments to the kernel. For these
- architectures, you should supply some command-line options at build
- time by entering them here. As a minimum, you should specify the
- memory size and the root device (e.g., mem=64M root=/dev/nfs).
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-   depends on ATAGS
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   help
- Always use the default kernel command string, even if the boot
- loader passes other arguments to the kernel.
- This is useful if you cannot or don't want to change the
- command-line options your boot loader passes to the kernel.
-endchoice
-
 config XIP_KERNEL
bool "Kernel Execute-In-Place from ROM"
depends on !ARM_LPAE && !ARCH_MULTIPLATFORM
diff --git a/arch/arm/kernel/atags_parse.c b/arch/arm/kernel/atags_parse.c
index 373b61f9a4f0..3d5bd52ee458 100644
--- a/arch/arm/kernel/atags_parse.c
+++ b/arch/arm/kernel/atags_parse.c
@@ -14,6 +14,7 @@
  * is not parsed in any way).
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -120,16 +121,10 @@ __tagtable(ATAG_REVISION, parse_tag_revision);
 
 static int __init parse_tag_cmdline(const struct tag *tag)
 {
-#if defined(CONFIG_CMDLINE_EXTEND)
-   strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
-   strlcat(default_command_line, tag->u.cmdline.cmdline,
-   COMMAND_LINE_SIZE);
-#elif defined(CONFIG_CMDLINE_FORCE)
-   pr_warn("Ignoring tag cmdline (using the default kernel command 
line)\n");
-#else
-   strlcpy(default_command_line, tag->u.cmdline.cmdline,
-   COMMAND_LINE_SIZE);
-#endif
+   cmdline_build(default_command_line, tag->u.cmdline.cmdline, 
COMMAND_LINE_SIZE);
+
+   if IS_ENABLED(CONFIG_CMDLINE_FORCE)
+   pr_warn("Ignoring tag cmdline (using the default kernel command 
line)\n");
return 0;
 }
 
-- 
2.25.0



[PATCH v3 04/17] powerpc: Convert to GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
This updates the powerpc code to use the new cmdline building function.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig| 37 +
 arch/powerpc/kernel/prom_init.c | 17 +++
 2 files changed, 8 insertions(+), 46 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 386ae12d8523..5181efd7757e 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,7 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -886,42 +887,6 @@ config PPC_DENORMALISATION
  Add support for handling denormalisation of single precision
  values.  Useful for bare metal only.  If unsure say Y here.
 
-config CMDLINE
-   string "Initial kernel command string"
-   default ""
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel. For these platforms, you can supply
- some command-line options at build time by entering them here.  In
- most cases you will need to specify the root device here.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   help
- Always use the default kernel command string, even if the boot
- loader passes other arguments to the kernel.
- This is useful if you cannot or don't want to change the
- command-line options your boot loader passes to the kernel.
-
-endchoice
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ccf77b985c8f..157d508e9fe9 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -152,7 +152,7 @@ static struct prom_t __prombss prom;
 static unsigned long __prombss prom_entry;
 
 static char __prombss of_stdout_device[256];
-static char __prombss prom_scratch[256];
+static char __prombss prom_scratch[COMMAND_LINE_SIZE];
 
 static unsigned long __prombss dt_header_start;
 static unsigned long __prombss dt_struct_start, dt_struct_end;
@@ -765,22 +765,19 @@ static unsigned long prom_memparse(const char *ptr, const 
char **retptr)
  * Early parsing of the command line passed to the kernel, used for
  * "mem=x" and the options that affect the iommu
  */
+#define cmdline_strlcat prom_strlcat
+#include 
+
 static void __init early_cmdline_parse(void)
 {
const char *opt;
-
-   char *p;
int l = 0;
 
-   prom_cmd_line[0] = 0;
-   p = prom_cmd_line;
-
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0)
-   l = prom_getprop(prom.chosen, "bootargs", p, 
COMMAND_LINE_SIZE-1);
+   l = prom_getprop(prom.chosen, "bootargs", prom_scratch,
+COMMAND_LINE_SIZE - 1);
 
-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0')
-   prom_strlcat(prom_cmd_line, " " CONFIG_CMDLINE,
-sizeof(prom_cmd_line));
+   __cmdline_build(prom_cmd_line, l > 0 ? prom_scratch : NULL, 
sizeof(prom_scratch));
 
prom_printf("command line: %s\n", prom_cmd_line);
 
-- 
2.25.0



[PATCH v3 01/17] cmdline: Add generic function to build command line.

2021-03-26 Thread Christophe Leroy
This code provides architectures with a way to build command line
based on what is built in the kernel and what is handed over by the
bootloader, based on selected compile-time options.

Signed-off-by: Christophe Leroy 
---
v3:
- Addressed comments from Will
- Added capability to have src == dst
---
 include/linux/cmdline.h | 57 +
 1 file changed, 57 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..dea87edd41be
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+#include 
+
+/* Allow architectures to override strlcat, powerpc can't use strings so early 
*/
+#ifndef cmdline_strlcat
+#define cmdline_strlcat strlcat
+#endif
+
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dst: The destination of the final appended/prepended string.
+ * @src: The starting string or NULL if there isn't one.
+ * @len: the length of dest buffer.
+ */
+static __always_inline void __cmdline_build(char *dst, const char *src, size_t 
len)
+{
+   if (!len || src == dst)
+   return;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !src) {
+   dst[0] = 0;
+   cmdline_strlcat(dst, CONFIG_CMDLINE, len);
+   return;
+   }
+
+   if (dst != src)
+   dst[0] = 0;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_PREPEND))
+   cmdline_strlcat(dst, CONFIG_CMDLINE " ", len);
+
+   cmdline_strlcat(dst, src, len);
+
+   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND))
+   cmdline_strlcat(dst, " " CONFIG_CMDLINE, len);
+}
+
+#define cmdline_build(dst, src, len) do {  \
+   char *__c_dst = (dst);  \
+   const char *__c_src = (src);\
+   \
+   if (__c_src == __c_dst) {   \
+   static char __c_tmp[COMMAND_LINE_SIZE] __initdata = ""; \
+   \
+   cmdline_strlcat(__c_tmp, __c_src, COMMAND_LINE_SIZE);   \
+   __cmdline_build(__c_dst, __c_tmp, (len));   \
+   } else {\
+   __cmdline_build(__c_dst, __c_src, (len));   \
+   }   \
+} while (0)
+
+#endif /* _LINUX_CMDLINE_H */
-- 
2.25.0



[PATCH v3 00/17] Implement GENERIC_CMDLINE

2021-03-26 Thread Christophe Leroy
The purpose of this series is to improve and enhance the
handling of kernel boot arguments.

It is first focussed on powerpc but also extends the capability
for other arches.

This is based on suggestion from Daniel Walker 

Main changes in V3:
- Also accept destination equal to source in cmdline_build() by setting a tmp 
buffer in __initdata. Powerpc provides different source and destination and 
call __cmdline_build() directly.
- Taken comments received from Will and Rob
- Converted all architectures (Only tested on powerpc)

Christophe Leroy (17):
  cmdline: Add generic function to build command line.
  drivers: of: use cmdline building function
  cmdline: Gives architectures opportunity to use generically defined
boot cmdline manipulation
  powerpc: Convert to GENERIC_CMDLINE
  arm: Convert to GENERIC_CMDLINE
  arm64: Convert to GENERIC_CMDLINE
  hexagon: Convert to GENERIC_CMDLINE
  microblaze: Convert to GENERIC_CMDLINE
  nios2: Convert to GENERIC_CMDLINE
  openrisc: Convert to GENERIC_CMDLINE
  riscv: Convert to GENERIC_CMDLINE
  sh: Convert to GENERIC_CMDLINE
  sparc: Convert to GENERIC_CMDLINE
  xtensa: Convert to GENERIC_CMDLINE
  x86: Convert to GENERIC_CMDLINE
  mips: Convert to GENERIC_CMDLINE
  cmdline: Remove CONFIG_CMDLINE_EXTEND

 arch/arm/Kconfig| 38 +-
 arch/arm/kernel/atags_parse.c   | 15 ++
 arch/arm64/Kconfig  | 33 +---
 arch/arm64/kernel/idreg-override.c  |  9 ++--
 arch/hexagon/Kconfig| 11 +---
 arch/hexagon/kernel/setup.c | 10 +---
 arch/microblaze/Kconfig | 24 +
 arch/microblaze/configs/mmu_defconfig   |  2 +-
 arch/microblaze/kernel/head.S   |  4 +-
 arch/mips/Kconfig   |  1 +
 arch/mips/Kconfig.debug | 44 
 arch/mips/configs/ar7_defconfig |  1 -
 arch/mips/configs/bcm47xx_defconfig |  1 -
 arch/mips/configs/bcm63xx_defconfig |  1 -
 arch/mips/configs/bmips_be_defconfig|  1 -
 arch/mips/configs/bmips_stb_defconfig   |  1 -
 arch/mips/configs/capcella_defconfig|  1 -
 arch/mips/configs/ci20_defconfig|  1 -
 arch/mips/configs/cu1000-neo_defconfig  |  1 -
 arch/mips/configs/cu1830-neo_defconfig  |  1 -
 arch/mips/configs/e55_defconfig |  1 -
 arch/mips/configs/generic_defconfig |  1 -
 arch/mips/configs/gpr_defconfig |  1 -
 arch/mips/configs/loongson3_defconfig   |  1 -
 arch/mips/configs/mpc30x_defconfig  |  1 -
 arch/mips/configs/rt305x_defconfig  |  1 -
 arch/mips/configs/tb0219_defconfig  |  1 -
 arch/mips/configs/tb0226_defconfig  |  1 -
 arch/mips/configs/tb0287_defconfig  |  1 -
 arch/mips/configs/workpad_defconfig |  1 -
 arch/mips/configs/xway_defconfig|  1 -
 arch/mips/kernel/relocate.c |  4 +-
 arch/mips/kernel/setup.c| 40 +--
 arch/mips/pic32/pic32mzda/early_console.c   |  2 +-
 arch/mips/pic32/pic32mzda/init.c|  2 -
 arch/nios2/Kconfig  | 24 +
 arch/nios2/kernel/setup.c   | 13 ++---
 arch/openrisc/Kconfig   | 10 +---
 arch/powerpc/Kconfig| 37 +
 arch/powerpc/kernel/prom_init.c | 17 +++---
 arch/riscv/Kconfig  | 44 +---
 arch/riscv/kernel/setup.c   |  5 +-
 arch/sh/Kconfig | 30 +--
 arch/sh/configs/ap325rxa_defconfig  |  2 +-
 arch/sh/configs/dreamcast_defconfig |  2 +-
 arch/sh/configs/ecovec24-romimage_defconfig |  2 +-
 arch/sh/configs/ecovec24_defconfig  |  2 +-
 arch/sh/configs/edosk7760_defconfig |  2 +-
 arch/sh/configs/espt_defconfig  |  2 +-
 arch/sh/configs/j2_defconfig|  2 +-
 arch/sh/configs/kfr2r09-romimage_defconfig  |  2 +-
 arch/sh/configs/kfr2r09_defconfig   |  2 +-
 arch/sh/configs/lboxre2_defconfig   |  2 +-
 arch/sh/configs/microdev_defconfig  |  2 +-
 arch/sh/configs/migor_defconfig |  2 +-
 arch/sh/configs/polaris_defconfig   |  2 +-
 arch/sh/configs/r7780mp_defconfig   |  2 +-
 arch/sh/configs/r7785rp_defconfig   |  2 +-
 arch/sh/configs/rsk7201_defconfig   |  2 +-
 arch/sh/configs/rsk7203_defconfig   |  2 +-
 arch/sh/configs/rts7751r2d1_defconfig   |  2 +-
 arch/sh/configs/rts7751r2dplus_defconfig|  2 +-
 arch/sh/configs/sdk7780_defconfig   |  2 +-
 arch/sh/configs/sdk7786_defconfig   |  2 +-
 arch/sh/configs/se7206_defconfig|  2 +-
 arch/sh/configs/se7343_defconfig|  2 +-
 arch/sh/configs/se7712_defconfig|  2 +-
 arch/sh/configs/se7721_defconfig|  2 +-
 

[PATCH v3 03/17] cmdline: Gives architectures opportunity to use generically defined boot cmdline manipulation

2021-03-26 Thread Christophe Leroy
Most architectures have similar boot command line manipulation
options. This patchs adds the definition in init/Kconfig, gated by
CONFIG_HAVE_CMDLINE that the architectures can select to use them.

CONFIG_CMDLINE_EXTEND is understood differently by architectures.
For some of them it appends built-in CMDLINE to bootloader provided
line. For others it appends the bootloader provided CMDLINE to the
built-in one.
To avoid confusion, this commit brings to different options:
- CONFIG_CMDLINE_APPEND to append the built-in CMDLINE to the
bootloader line.
- CONFIG_CMDLINE_PREPEND to prepend the built-in CMDLINE in front of
the bootloader line.

For compatibility with existing architecture which uses CONFIG_OF, as
OF has already been converted to generic cmdline, we keep
CONFIG_CMDLINE_EXTEND as a synonym to CONFIG_CMDLINE_APPEND until
arm, powerpc, riscv and sh architectures have been converted.

A few differences are identified and will have to be taken
into account when converting the architecture to generic cmdline:
- riscv has CMDLINE_FALLBACK instead of CMDLINE_FROM_BOOTLOADER
- Some architectures are using CONFIG_CMDLINE_OVERRIDE or
CONFIG_CMDLINE_OVERWRITE instead of CONFIG_CMDLINE_FORCE.

Signed-off-by: Christophe Leroy 
---
v3:
- Comments from Will.
- Remove CONFIG_CMDLINE_BOOL. Using CONFIG_CMDLINE != "" instead, like arm and 
powerpc.
- Changed EXTEND to APPEND. Keep EXTEND for backward compatibility.
---
 include/linux/cmdline.h |  2 +-
 init/Kconfig| 52 +
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
index dea87edd41be..38306c109041 100644
--- a/include/linux/cmdline.h
+++ b/include/linux/cmdline.h
@@ -36,7 +36,7 @@ static __always_inline void __cmdline_build(char *dst, const 
char *src, size_t l
 
cmdline_strlcat(dst, src, len);
 
-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND))
+   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || 
IS_ENABLED(CONFIG_CMDLINE_APPEND))
cmdline_strlcat(dst, " " CONFIG_CMDLINE, len);
 }
 
diff --git a/init/Kconfig b/init/Kconfig
index 5f5c776ef192..af0d84662cc2 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -117,6 +117,58 @@ config INIT_ENV_ARG_LIMIT
  Maximum of each of the number of arguments and environment
  variables passed to init from the kernel command line.
 
+config GENERIC_CMDLINE
+   bool
+
+config CMDLINE
+   string "Default kernel command string" if GENERIC_CMDLINE
+   default ""
+   help
+ Defines a default kernel command string.
+ If this string is not empty, additional choices are proposed
+ below to determine how it will be used by the kernel.
+
+choice
+   prompt "Kernel command line type" if CMDLINE != ""
+   default CMDLINE_PREPEND if ARCH_WANT_CMDLINE_PREPEND_BY_DEFAULT
+   default CMDLINE_FROM_BOOTLOADER
+   depends on GENERIC_CMDLINE
+   help
+ Determine how the default kernel arguments are combined with any
+ arguments passed by the bootloader if any.
+
+config CMDLINE_FROM_BOOTLOADER
+   bool "Use bootloader kernel arguments if available"
+   help
+ Uses the command-line options passed by the boot loader. If
+ the boot loader doesn't provide any, the default kernel command
+ string provided in CMDLINE will be used.
+
+config CMDLINE_APPEND
+   bool "Append to the bootloader kernel arguments"
+   help
+ The default kernel command string will be appended to the
+ command-line arguments provided by the bootloader.
+
+config CMDLINE_PREPEND
+   bool "Prepend to the bootloader kernel arguments"
+   help
+ The default kernel command string will be prepended to the
+ command-line arguments provided by the bootloader.
+
+config CMDLINE_FORCE
+   bool "Always use the default kernel command string"
+   help
+ Always use the default kernel command string, ignoring any
+ arguments provided by the bootloader.
+endchoice
+
+config CMDLINE_EXTEND
+   bool
+   default CMDLINE_APPEND
+   help
+ To be removed once all architectures are converted to generic CMDLINE
+
 config COMPILE_TEST
bool "Compile also drivers which will not load"
depends on HAS_IOMEM
-- 
2.25.0



[PATCH v3 02/17] drivers: of: use cmdline building function

2021-03-26 Thread Christophe Leroy
This patch uses the new cmdline building function to
concatenate the of provided cmdline with built-in parts
based on compile-time options.

Signed-off-by: Christophe Leroy 
---
 drivers/of/fdt.c | 23 ---
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index dcc1dd96911a..cf2b95b8f298 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,26 +1051,10 @@ int __init early_init_dt_scan_chosen(unsigned long 
node, const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", );
-   if (p != NULL && l > 0)
-   strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
+   if (l <= 0)
+   p = NULL;
 
-   /*
-* CONFIG_CMDLINE is meant to be a default in case nothing else
-* managed to set the command line, unless CONFIG_CMDLINE_FORCE
-* is set in which case we override whatever was found earlier.
-*/
-#ifdef CONFIG_CMDLINE
-#if defined(CONFIG_CMDLINE_EXTEND)
-   strlcat(data, " ", COMMAND_LINE_SIZE);
-   strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#elif defined(CONFIG_CMDLINE_FORCE)
-   strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#else
-   /* No arguments from boot loader, use kernel's  cmdl*/
-   if (!((char *)data)[0])
-   strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#endif
-#endif /* CONFIG_CMDLINE */
+   cmdline_build(data, p, COMMAND_LINE_SIZE);
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.0



[PATCH] powerpc: powernv: Remove unneeded variable: "rc"

2021-03-26 Thread dingsenjie
From: dingsenjie 

Remove unneeded variable: "rc".

Signed-off-by: dingsenjie 
---
 arch/powerpc/platforms/powernv/opal-prd.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-prd.c 
b/arch/powerpc/platforms/powernv/opal-prd.c
index deddaeb..a191f4c 100644
--- a/arch/powerpc/platforms/powernv/opal-prd.c
+++ b/arch/powerpc/platforms/powernv/opal-prd.c
@@ -105,7 +105,6 @@ static int opal_prd_mmap(struct file *file, struct 
vm_area_struct *vma)
 {
size_t addr, size;
pgprot_t page_prot;
-   int rc;
 
pr_devel("opal_prd_mmap(0x%016lx, 0x%016lx, 0x%lx, 0x%lx)\n",
vma->vm_start, vma->vm_end, vma->vm_pgoff,
@@ -121,10 +120,8 @@ static int opal_prd_mmap(struct file *file, struct 
vm_area_struct *vma)
page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
 size, vma->vm_page_prot);
 
-   rc = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size,
+   return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size,
page_prot);
-
-   return rc;
 }
 
 static bool opal_msg_queue_empty(void)
-- 
1.9.1




Re: [PATCH] docs: powerpc: Fix misspellings and grammar errors

2021-03-26 Thread Michael Ellerman
He Ying  writes:
> Reported-by: Hulk Robot 
> Signed-off-by: He Ying 
> ---
>  Documentation/powerpc/booting.rst| 2 +-
>  Documentation/powerpc/dawr-power9.rst| 2 +-
>  Documentation/powerpc/eeh-pci-error-recovery.rst | 2 +-
>  Documentation/powerpc/elfnote.rst| 2 +-
>  Documentation/powerpc/firmware-assisted-dump.rst | 2 +-
>  Documentation/powerpc/kaslr-booke32.rst  | 2 +-
>  Documentation/powerpc/mpc52xx.rst| 2 +-
>  Documentation/powerpc/papr_hcalls.rst| 4 ++--
>  Documentation/powerpc/transactional_memory.rst   | 4 ++--
>  9 files changed, 11 insertions(+), 11 deletions(-)

LGTM.

Acked-by: Michael Ellerman 

cheers


Re: [PATCH next v1 2/3] printk: remove safe buffers

2021-03-26 Thread John Ogness
On 2021-03-23, Petr Mladek  wrote:
>> --- a/kernel/printk/printk.c
>> +++ b/kernel/printk/printk.c
>> @@ -1142,8 +1126,6 @@ void __init setup_log_buf(int early)
>>   new_descs, ilog2(new_descs_count),
>>   new_infos);
>>  
>> -printk_safe_enter_irqsave(flags);
>> -
>>  log_buf_len = new_log_buf_len;
>>  log_buf = new_log_buf;
>>  new_log_buf_len = 0;
>> @@ -1159,8 +1141,6 @@ void __init setup_log_buf(int early)
>>   */
>>  prb = _rb_dynamic;
>>  
>> -printk_safe_exit_irqrestore(flags);
>
> This will allow to add new messages from the IRQ context when we
> are copying them to the new buffer. They might get lost in
> the small race window.
>
> Also the messages from NMI might get lost because they are not
> longer stored in the per-CPU buffer.
>
> A possible solution might be to do something like this:
>
>   prb_for_each_record(0, _rb_static, seq, )
>   free -= add_to_rb(_rb_dynamic, );
>
>   prb = _rb_dynamic;
>
>   /*
>* Copy the remaining messages that might have appeared
>* from IRQ or NMI context after we ended copying and
>* before we switched the buffers. They must be finalized
>* because only one CPU is up at this stage.
>*/
>   prb_for_each_record(seq, _rb_static, seq, )
>   free -= add_to_rb(_rb_dynamic, );

OK. I'll probably rework it some and combine it with the "dropped" test
so that we can identify if messages were dropped during the transition
(because of static ringbuffer overrun).

>> -
>>  if (seq != prb_next_seq(_rb_static)) {
>>  pr_err("dropped %llu messages\n",
>> prb_next_seq(_rb_static) - seq);
>> @@ -2666,7 +2631,6 @@ void console_unlock(void)
>>  size_t ext_len = 0;
>>  size_t len;
>>  
>> -printk_safe_enter_irqsave(flags);
>>  skip:
>>  if (!prb_read_valid(prb, console_seq, ))
>>  break;
>> @@ -2711,6 +2675,8 @@ void console_unlock(void)
>>  printk_time);
>>  console_seq++;
>>  
>> +printk_safe_enter_irqsave(flags);
>
> What is the purpose of the printk_safe context here, please?

console_lock_spinning_enable() needs to be called with interrupts
disabled. I should have just used local_irq_save().

I could add local_irq_save() to console_lock_spinning_enable() and
restore them at the end of console_lock_spinning_disable_and_check(),
but then I would need to add a @flags argument to both functions. I
think it is simpler to just do the disable/enable from the caller,
console_unlock().

BTW, I could not find any sane way of disabling interrupts via a
raw_spin_lock_irqsave() of @console_owner_lock because of the how it is
used with lockdep. In particular for
console_lock_spinning_disable_and_check().

John Ogness


Re: VDSO ELF header

2021-03-26 Thread Christophe Leroy




Le 26/03/2021 à 11:46, Michael Ellerman a écrit :

Laurent Dufour  writes:

Le 25/03/2021 à 17:56, Laurent Dufour a écrit :

Le 25/03/2021 à 17:46, Christophe Leroy a écrit :

Le 25/03/2021 à 17:11, Laurent Dufour a écrit :

Since v5.11 and the changes you made to the VDSO code, it no more exposing
the ELF header at the beginning of the VDSO mapping in user space.

This is confusing CRIU which is checking for this ELF header cookie
(https://github.com/checkpoint-restore/criu/issues/1417).


How does it do on other architectures ?


Good question, I'll double check the CRIU code.


On x86, there are 2 VDSO entries:
77fcb000-77fce000 r--p  00:00 0  [vvar]
77fce000-77fcf000 r-xp  00:00 0  [vdso]

And the VDSO is starting with the ELF header.


I'm not an expert in loading and ELF part and reading the change you made, I
can't identify how this could work now as I'm expecting the loader to need
that ELF header to do the relocation.


I think the loader is able to find it at the expected place.


Actually, it seems the loader relies on the AUX vector AT_SYSINFO_EHDR. I guess
CRIU should do the same.



  From my investigation it seems that the first bytes of the VDSO area are now
the vdso_arch_data.

Is the ELF header put somewhere else?
How could the loader process the VDSO without that ELF header?



Like most other architectures, we now have the data section as first page and
the text section follows. So you will likely find the elf header on the second
page.


I'm wondering if the data section you're refering to is the vvar section I can
see on x86.


Many of the other architectures have separate vm_special_mapping's for
the data page and the vdso binary, where the former is called "vvar".

eg, s390:

static struct vm_special_mapping vvar_mapping = {
.name = "[vvar]",
.fault = vvar_fault,
};

static struct vm_special_mapping vdso_mapping = {
.name = "[vdso]",
.mremap = vdso_mremap,
};


I guess we probably should be doing that too.



Dmitry proposed the same, see 
https://github.com/0x7f454c46/linux/commit/783c7a2532d2219edbcf555cc540eab05f698d2a


Discussion at https://github.com/checkpoint-restore/criu/issues/1417

Christophe


Re: VDSO ELF header

2021-03-26 Thread Michael Ellerman
Laurent Dufour  writes:
> Le 25/03/2021 à 17:56, Laurent Dufour a écrit :
>> Le 25/03/2021 à 17:46, Christophe Leroy a écrit :
>>> Le 25/03/2021 à 17:11, Laurent Dufour a écrit :
 Since v5.11 and the changes you made to the VDSO code, it no more exposing 
 the ELF header at the beginning of the VDSO mapping in user space.

 This is confusing CRIU which is checking for this ELF header cookie 
 (https://github.com/checkpoint-restore/criu/issues/1417).
>>>
>>> How does it do on other architectures ?
>> 
>> Good question, I'll double check the CRIU code.
>
> On x86, there are 2 VDSO entries:
> 77fcb000-77fce000 r--p  00:00 0  
> [vvar]
> 77fce000-77fcf000 r-xp  00:00 0  
> [vdso]
>
> And the VDSO is starting with the ELF header.
>
 I'm not an expert in loading and ELF part and reading the change you made, 
 I 
 can't identify how this could work now as I'm expecting the loader to need 
 that ELF header to do the relocation.
>>>
>>> I think the loader is able to find it at the expected place.
>> 
>> Actually, it seems the loader relies on the AUX vector AT_SYSINFO_EHDR. I 
>> guess 
>> CRIU should do the same.
>> 

  From my investigation it seems that the first bytes of the VDSO area are 
 now 
 the vdso_arch_data.

 Is the ELF header put somewhere else?
 How could the loader process the VDSO without that ELF header?

>>>
>>> Like most other architectures, we now have the data section as first page 
>>> and 
>>> the text section follows. So you will likely find the elf header on the 
>>> second 
>>> page.
>
> I'm wondering if the data section you're refering to is the vvar section I 
> can 
> see on x86.

Many of the other architectures have separate vm_special_mapping's for
the data page and the vdso binary, where the former is called "vvar".

eg, s390:

static struct vm_special_mapping vvar_mapping = {
.name = "[vvar]",
.fault = vvar_fault,
};

static struct vm_special_mapping vdso_mapping = {
.name = "[vdso]",
.mremap = vdso_mremap,
};


I guess we probably should be doing that too.

cheers


[PATCH] powerpc/64: Move security code into security.c

2021-03-26 Thread Michael Ellerman
When the original spectre/meltdown mitigations were merged we put them
in setup_64.c for lack of a better place.

Since then we created security.c for some of the other mitigation
related code. But it should all be in there.

This sort of code movement can cause trouble for backports, but
hopefully this code is relatively stable these days (famous last words).

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/security.c | 261 
 arch/powerpc/kernel/setup_64.c | 264 -
 2 files changed, 261 insertions(+), 264 deletions(-)

diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index e4e1a94ccf6a..287286ddf7dc 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -18,6 +19,7 @@
 #include 
 #include 
 
+#include "setup.h"
 
 u64 powerpc_security_features __read_mostly = SEC_FTR_DEFAULT;
 
@@ -541,6 +543,178 @@ void setup_count_cache_flush(void)
toggle_branch_cache_flush(enable);
 }
 
+static enum l1d_flush_type enabled_flush_types;
+static void *l1d_flush_fallback_area;
+static bool no_rfi_flush;
+static bool no_entry_flush;
+static bool no_uaccess_flush;
+bool rfi_flush;
+static bool entry_flush;
+static bool uaccess_flush;
+DEFINE_STATIC_KEY_FALSE(uaccess_flush_key);
+EXPORT_SYMBOL(uaccess_flush_key);
+
+static int __init handle_no_rfi_flush(char *p)
+{
+   pr_info("rfi-flush: disabled on command line.");
+   no_rfi_flush = true;
+   return 0;
+}
+early_param("no_rfi_flush", handle_no_rfi_flush);
+
+static int __init handle_no_entry_flush(char *p)
+{
+   pr_info("entry-flush: disabled on command line.");
+   no_entry_flush = true;
+   return 0;
+}
+early_param("no_entry_flush", handle_no_entry_flush);
+
+static int __init handle_no_uaccess_flush(char *p)
+{
+   pr_info("uaccess-flush: disabled on command line.");
+   no_uaccess_flush = true;
+   return 0;
+}
+early_param("no_uaccess_flush", handle_no_uaccess_flush);
+
+/*
+ * The RFI flush is not KPTI, but because users will see doco that says to use
+ * nopti we hijack that option here to also disable the RFI flush.
+ */
+static int __init handle_no_pti(char *p)
+{
+   pr_info("rfi-flush: disabling due to 'nopti' on command line.\n");
+   handle_no_rfi_flush(NULL);
+   return 0;
+}
+early_param("nopti", handle_no_pti);
+
+static void do_nothing(void *unused)
+{
+   /*
+* We don't need to do the flush explicitly, just enter+exit kernel is
+* sufficient, the RFI exit handlers will do the right thing.
+*/
+}
+
+void rfi_flush_enable(bool enable)
+{
+   if (enable) {
+   do_rfi_flush_fixups(enabled_flush_types);
+   on_each_cpu(do_nothing, NULL, 1);
+   } else
+   do_rfi_flush_fixups(L1D_FLUSH_NONE);
+
+   rfi_flush = enable;
+}
+
+static void entry_flush_enable(bool enable)
+{
+   if (enable) {
+   do_entry_flush_fixups(enabled_flush_types);
+   on_each_cpu(do_nothing, NULL, 1);
+   } else {
+   do_entry_flush_fixups(L1D_FLUSH_NONE);
+   }
+
+   entry_flush = enable;
+}
+
+static void uaccess_flush_enable(bool enable)
+{
+   if (enable) {
+   do_uaccess_flush_fixups(enabled_flush_types);
+   static_branch_enable(_flush_key);
+   on_each_cpu(do_nothing, NULL, 1);
+   } else {
+   static_branch_disable(_flush_key);
+   do_uaccess_flush_fixups(L1D_FLUSH_NONE);
+   }
+
+   uaccess_flush = enable;
+}
+
+static void __ref init_fallback_flush(void)
+{
+   u64 l1d_size, limit;
+   int cpu;
+
+   /* Only allocate the fallback flush area once (at boot time). */
+   if (l1d_flush_fallback_area)
+   return;
+
+   l1d_size = ppc64_caches.l1d.size;
+
+   /*
+* If there is no d-cache-size property in the device tree, l1d_size
+* could be zero. That leads to the loop in the asm wrapping around to
+* 2^64-1, and then walking off the end of the fallback area and
+* eventually causing a page fault which is fatal. Just default to
+* something vaguely sane.
+*/
+   if (!l1d_size)
+   l1d_size = (64 * 1024);
+
+   limit = min(ppc64_bolted_size(), ppc64_rma_size);
+
+   /*
+* Align to L1d size, and size it at 2x L1d size, to catch possible
+* hardware prefetch runoff. We don't have a recipe for load patterns to
+* reliably avoid the prefetcher.
+*/
+   l1d_flush_fallback_area = memblock_alloc_try_nid(l1d_size * 2,
+   l1d_size, MEMBLOCK_LOW_LIMIT,
+   limit, NUMA_NO_NODE);
+   if (!l1d_flush_fallback_area)
+   panic("%s: Failed to allocate %llu bytes align=0x%llx 

[PATCH] docs: powerpc: Fix misspellings and grammar errors

2021-03-26 Thread He Ying
Reported-by: Hulk Robot 
Signed-off-by: He Ying 
---
 Documentation/powerpc/booting.rst| 2 +-
 Documentation/powerpc/dawr-power9.rst| 2 +-
 Documentation/powerpc/eeh-pci-error-recovery.rst | 2 +-
 Documentation/powerpc/elfnote.rst| 2 +-
 Documentation/powerpc/firmware-assisted-dump.rst | 2 +-
 Documentation/powerpc/kaslr-booke32.rst  | 2 +-
 Documentation/powerpc/mpc52xx.rst| 2 +-
 Documentation/powerpc/papr_hcalls.rst| 4 ++--
 Documentation/powerpc/transactional_memory.rst   | 4 ++--
 9 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/Documentation/powerpc/booting.rst 
b/Documentation/powerpc/booting.rst
index 2d0ec2ff2b57..11aa440f98cc 100644
--- a/Documentation/powerpc/booting.rst
+++ b/Documentation/powerpc/booting.rst
@@ -94,7 +94,7 @@ should:
 
 a) add your platform support as a _boolean_ option in
 arch/powerpc/Kconfig, following the example of PPC_PSERIES,
-PPC_PMAC and PPC_MAPLE. The later is probably a good
+PPC_PMAC and PPC_MAPLE. The latter is probably a good
 example of a board support to start from.
 
 b) create your main platform file as
diff --git a/Documentation/powerpc/dawr-power9.rst 
b/Documentation/powerpc/dawr-power9.rst
index c96ab6befd9c..e55ac6a24b97 100644
--- a/Documentation/powerpc/dawr-power9.rst
+++ b/Documentation/powerpc/dawr-power9.rst
@@ -4,7 +4,7 @@ DAWR issues on POWER9
 
 On POWER9 the Data Address Watchpoint Register (DAWR) can cause a checkstop
 if it points to cache inhibited (CI) memory. Currently Linux has no way to
-disinguish CI memory when configuring the DAWR, so (for now) the DAWR is
+distinguish CI memory when configuring the DAWR, so (for now) the DAWR is
 disabled by this commit::
 
 commit 9654153158d3e0684a1bdb76dbababdb7111d5a0
diff --git a/Documentation/powerpc/eeh-pci-error-recovery.rst 
b/Documentation/powerpc/eeh-pci-error-recovery.rst
index 438a87ebc095..d6643a91bdf8 100644
--- a/Documentation/powerpc/eeh-pci-error-recovery.rst
+++ b/Documentation/powerpc/eeh-pci-error-recovery.rst
@@ -73,7 +73,7 @@ return all-ff's (0xff, 0x, 0x for 8/16/32-bit 
reads).
 This value was chosen because it is the same value you would
 get if the device was physically unplugged from the slot.
 This includes access to PCI memory, I/O space, and PCI config
-space.  Interrupts; however, will continued to be delivered.
+space.  Interrupts; however, will continue to be delivered.
 
 Detection and recovery are performed with the aid of ppc64
 firmware.  The programming interfaces in the Linux kernel
diff --git a/Documentation/powerpc/elfnote.rst 
b/Documentation/powerpc/elfnote.rst
index 06602248621c..3ec8d61e9a33 100644
--- a/Documentation/powerpc/elfnote.rst
+++ b/Documentation/powerpc/elfnote.rst
@@ -8,7 +8,7 @@ capabilities and information which can be used by a bootloader 
or userland.
 Types and Descriptors
 -
 
-The types to be used with the "PowerPC" namesapce are defined in [#f1]_.
+The types to be used with the "PowerPC" namespace are defined in [#f1]_.
 
1) PPC_ELFNOTE_CAPABILITIES
 
diff --git a/Documentation/powerpc/firmware-assisted-dump.rst 
b/Documentation/powerpc/firmware-assisted-dump.rst
index 6c0ae070ba67..e363fc48529a 100644
--- a/Documentation/powerpc/firmware-assisted-dump.rst
+++ b/Documentation/powerpc/firmware-assisted-dump.rst
@@ -207,7 +207,7 @@ Currently the dump will be copied from /proc/vmcore to a 
new file upon
 user intervention. The dump data available through /proc/vmcore will be
 in ELF format. Hence the existing kdump infrastructure (kdump scripts)
 to save the dump works fine with minor modifications. KDump scripts on
-major Distro releases have already been modified to work seemlessly (no
+major Distro releases have already been modified to work seamlessly (no
 user intervention in saving the dump) when FADump is used, instead of
 KDump, as dump mechanism.
 
diff --git a/Documentation/powerpc/kaslr-booke32.rst 
b/Documentation/powerpc/kaslr-booke32.rst
index 8b259fdfdf03..5681c1d1b65b 100644
--- a/Documentation/powerpc/kaslr-booke32.rst
+++ b/Documentation/powerpc/kaslr-booke32.rst
@@ -38,5 +38,5 @@ bit of the entropy to decide the index of the 64M zone. Then 
we chose a
 
   kernstart_virt_addr
 
-To enable KASLR, set CONFIG_RANDOMIZE_BASE = y. If KASLR is enable and you
+To enable KASLR, set CONFIG_RANDOMIZE_BASE = y. If KASLR is enabled and you
 want to disable it at runtime, add "nokaslr" to the kernel cmdline.
diff --git a/Documentation/powerpc/mpc52xx.rst 
b/Documentation/powerpc/mpc52xx.rst
index 30260707c3fe..5243b1763fad 100644
--- a/Documentation/powerpc/mpc52xx.rst
+++ b/Documentation/powerpc/mpc52xx.rst
@@ -34,7 +34,7 @@ To compile/use :
 Some remarks:
 
  - The port is named mpc52xxx, and config options are PPC_MPC52xx. The MGT5100
-   is not supported, and I'm not sure anyone is interesting in working on it
+   

[PATCH] arch/powerpc: Remove unneeded variable: "ret"

2021-03-26 Thread zuoqilin1
From: zuoqilin 

Remove unneeded variable: "ret".

Signed-off-by: zuoqilin 
---
 arch/powerpc/platforms/pseries/cmm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/cmm.c 
b/arch/powerpc/platforms/pseries/cmm.c
index 45a3a30..95ebb0c 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -475,8 +475,6 @@ static int cmm_reboot_notifier(struct notifier_block *nb,
 static int cmm_memory_cb(struct notifier_block *self,
unsigned long action, void *arg)
 {
-   int ret = 0;
-
switch (action) {
case MEM_GOING_OFFLINE:
mutex_lock(_mutex);
@@ -493,7 +491,7 @@ static int cmm_memory_cb(struct notifier_block *self,
break;
}
 
-   return notifier_from_errno(ret);
+   return notifier_from_errno(0);
 }
 
 static struct notifier_block cmm_mem_nb = {
-- 
1.9.1




Re: [PATCH] crypto: nx: fix incorrect kernel-doc comment syntax in files

2021-03-26 Thread Herbert Xu
On Sun, Mar 21, 2021 at 06:00:07PM +0530, Aditya Srivastava wrote:
> The opening comment mark '/**' is used for highlighting the beginning of
> kernel-doc comments.
> There are certain files in drivers/crypto/nx, which follow this syntax,
> but the content inside does not comply with kernel-doc.
> Such lines were probably not meant for kernel-doc parsing, but are parsed
> due to the presence of kernel-doc like comment syntax(i.e, '/**'), which
> causes unexpected warnings from kernel-doc.
> 
> E.g., presence of kernel-doc like comment in the header lines for
> drivers/crypto/nx/nx-sha256.c at header causes these warnings:
> "warning: Function parameter or member 'tfm' not described in 
> 'nx_crypto_ctx_sha256_init'"
> "warning: expecting prototype for SHA(). Prototype was for 
> nx_crypto_ctx_sha256_init() instead"
> 
> Similarly for other files too.
> 
> Provide a simple fix by replacing such occurrences with general comment
> format, i.e. '/*', to prevent kernel-doc from parsing it.
> 
> Signed-off-by: Aditya Srivastava 
> ---
> * Applies perfectly on next-20210319
> 
>  drivers/crypto/nx/nx-aes-cbc.c  | 2 +-
>  drivers/crypto/nx/nx-aes-ccm.c  | 2 +-
>  drivers/crypto/nx/nx-aes-ctr.c  | 2 +-
>  drivers/crypto/nx/nx-aes-ecb.c  | 2 +-
>  drivers/crypto/nx/nx-aes-gcm.c  | 2 +-
>  drivers/crypto/nx/nx-aes-xcbc.c | 2 +-
>  drivers/crypto/nx/nx-sha256.c   | 2 +-
>  drivers/crypto/nx/nx-sha512.c   | 2 +-
>  drivers/crypto/nx/nx.c  | 2 +-
>  drivers/crypto/nx/nx_debugfs.c  | 2 +-
>  10 files changed, 10 insertions(+), 10 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH] crypto: vmx: fix incorrect kernel-doc comment syntax in files

2021-03-26 Thread Herbert Xu
On Sun, Mar 21, 2021 at 01:55:25AM +0530, Aditya Srivastava wrote:
> The opening comment mark '/**' is used for highlighting the beginning of
> kernel-doc comments.
> There are certain files in drivers/crypto/vmx, which follow this syntax,
> but the content inside does not comply with kernel-doc.
> Such lines were probably not meant for kernel-doc parsing, but are parsed
> due to the presence of kernel-doc like comment syntax(i.e, '/**'), which
> causes unexpected warnings from kernel-doc.
> 
> E.g., presence of kernel-doc like comment in the header line for
> drivers/crypto/vmx/vmx.c causes this warning by kernel-doc:
> 
> "warning: expecting prototype for Routines supporting VMX instructions on the 
> Power 8(). Prototype was for p8_init() instead"
> 
> Similarly for other files too.
> 
> Provide a simple fix by replacing such occurrences with general comment
> format, i.e. '/*', to prevent kernel-doc from parsing it.
> 
> Signed-off-by: Aditya Srivastava 
> ---
> * Applies perfectly on next-20210319
> 
>  drivers/crypto/vmx/aes.c | 2 +-
>  drivers/crypto/vmx/aes_cbc.c | 2 +-
>  drivers/crypto/vmx/aes_ctr.c | 2 +-
>  drivers/crypto/vmx/aes_xts.c | 2 +-
>  drivers/crypto/vmx/ghash.c   | 2 +-
>  drivers/crypto/vmx/vmx.c | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH v3 00/10] Rid W=1 warnings in Crypto

2021-03-26 Thread Herbert Xu
On Thu, Mar 18, 2021 at 12:44:12PM +, Lee Jones wrote:
> This is set 1 of 2 sets required to fully clean Crypto.
> 
> v2: No functional changes since v1.
> v3: Description change and additional struct header fix
> 
> Lee Jones (10):
>   crypto: hisilicon: sec_drv: Supply missing description for
> 'sec_queue_empty()'s 'queue' param
>   crypto: bcm: Fix a whole host of kernel-doc misdemeanours
>   crypto: chelsio: chcr_core: Fix some kernel-doc issues
>   crypto: ux500: hash: hash_core: Fix worthy kernel-doc headers and
> remove others
>   crypto: keembay: ocs-hcu: Fix incorrectly named functions/structs
>   crypto: atmel-ecc: Struct headers need to start with keyword 'struct'
>   crypto: caam: caampkc: Provide the name of the function and provide
> missing descriptions
>   crypto: vmx: Source headers are not good kernel-doc candidates
>   crypto: nx: nx-aes-cbc: Repair some kernel-doc problems
>   crypto: cavium: nitrox_isr: Demote non-compliant kernel-doc headers
> 
>  drivers/crypto/atmel-ecc.c|  2 +-
>  drivers/crypto/bcm/cipher.c   |  7 ++--
>  drivers/crypto/bcm/spu.c  | 16 -
>  drivers/crypto/bcm/spu2.c | 43 +--
>  drivers/crypto/bcm/util.c |  4 +--
>  drivers/crypto/caam/caamalg_qi2.c |  3 ++
>  drivers/crypto/caam/caampkc.c |  3 +-
>  drivers/crypto/cavium/nitrox/nitrox_isr.c |  4 +--
>  drivers/crypto/chelsio/chcr_algo.c|  8 ++---
>  drivers/crypto/chelsio/chcr_core.c|  2 +-
>  drivers/crypto/hisilicon/sec/sec_drv.c|  1 +
>  drivers/crypto/keembay/ocs-hcu.c  |  8 ++---
>  drivers/crypto/nx/nx-aes-cbc.c|  2 +-
>  drivers/crypto/nx/nx.c|  5 +--
>  drivers/crypto/nx/nx_debugfs.c|  2 +-
>  drivers/crypto/ux500/cryp/cryp.c  |  5 +--
>  drivers/crypto/ux500/cryp/cryp_core.c |  5 +--
>  drivers/crypto/ux500/cryp/cryp_irq.c  |  2 +-
>  drivers/crypto/ux500/hash/hash_core.c | 15 +++-
>  drivers/crypto/vmx/vmx.c  |  2 +-
>  20 files changed, 73 insertions(+), 66 deletions(-)
> 
> Cc: Alexandre Belloni 
> Cc: Andreas Westin 
> Cc: Atul Gupta 
> Cc: Aymen Sghaier 
> Cc: Ayush Sawal 
> Cc: Benjamin Herrenschmidt 
> Cc: Berne Hebark 
> Cc: "Breno Leitão" 
> Cc: Daniele Alessandrelli 
> Cc: "David S. Miller" 
> Cc: Declan Murphy 
> Cc: Harsh Jain 
> Cc: Henrique Cerri 
> Cc: Herbert Xu 
> Cc: "Horia Geantă" 
> Cc: Jitendra Lulla 
> Cc: Joakim Bech 
> Cc: Jonas Linde 
> Cc: Jonathan Cameron 
> Cc: Kent Yoder 
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-cry...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Ludovic Desroches 
> Cc: Manoj Malviya 
> Cc: Michael Ellerman 
> Cc: M R Gowda 
> Cc: Nayna Jain 
> Cc: Nicolas Ferre 
> Cc: Niklas Hernaeus 
> Cc: Paul Mackerras 
> Cc: Paulo Flabiano Smorigo 
> Cc: Rob Rice 
> Cc: Rohit Maheshwari 
> Cc: Shujuan Chen 
> Cc: Tudor Ambarus 
> Cc: Vinay Kumar Yadav 
> Cc: Zaibo Xu 

All applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH] soc/fsl: qbman: fix conflicting alignment attributes

2021-03-26 Thread Arnd Bergmann
On Fri, Mar 26, 2021 at 3:17 AM Li Yang  wrote:
> On Tue, Mar 23, 2021 at 8:17 AM Arnd Bergmann  wrote:
> >
> > From: Arnd Bergmann 
> >
> > When building with W=1, gcc points out that the __packed attribute
> > on struct qm_eqcr_entry conflicts with the 8-byte alignment
> > attribute on struct qm_fd inside it:
> >
> > drivers/soc/fsl/qbman/qman.c:189:1: error: alignment 1 of 'struct 
> > qm_eqcr_entry' is less than 8 [-Werror=packed-not-aligned]
> >
> > I assume that the alignment attribute is the correct one, and
> > that qm_eqcr_entry cannot actually be unaligned in memory,
> > so add the same alignment on the outer struct.
> >
> > Fixes: c535e923bb97 ("soc/fsl: Introduce DPAA 1.x QMan device driver")
> > Signed-off-by: Arnd Bergmann 
> > ---
> >  drivers/soc/fsl/qbman/qman.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
> > index a1b9be1d105a..fde4edd83c14 100644
> > --- a/drivers/soc/fsl/qbman/qman.c
> > +++ b/drivers/soc/fsl/qbman/qman.c
> > @@ -186,7 +186,7 @@ struct qm_eqcr_entry {
> > __be32 tag;
> > struct qm_fd fd;
> > u8 __reserved3[32];
> > -} __packed;
> > +} __packed __aligned(8);
>
> The EQCR structure is actually aligned on 64-byte from the manual.
> But probably 8 is enough to let the compiler not complain.

The important bit is that all members inside are at most 8-byte long
and naturally aligned, so the compiler can now optimize the accesses
because it can assume that each member can be updated atomically.

Marking a structure as unaligned with the __packed attribute can lead
to rather unoptimized code, which is particularly important when the
structure is mapped as uncached -- accessing it one byte at a time
means you have eight times the latency for a simple read. I think on
arm64, the compiler doesn't actually have to do that, but at least if you
run a 32-bit kernel, the packing would prevent the use of ldrd or ldm
instructions that need an aligned word.

   Arnd


Re: [PATCH V2 1/5] powerpc/perf: Expose processor pipeline stage cycles using PERF_SAMPLE_WEIGHT_STRUCT

2021-03-26 Thread Madhavan Srinivasan



On 3/25/21 6:36 PM, Arnaldo Carvalho de Melo wrote:

Em Wed, Mar 24, 2021 at 10:05:23AM +0530, Madhavan Srinivasan escreveu:

On 3/22/21 8:27 PM, Athira Rajeev wrote:

Performance Monitoring Unit (PMU) registers in powerpc provides
information on cycles elapsed between different stages in the
pipeline. This can be used for application tuning. On ISA v3.1
platform, this information is exposed by sampling registers.
Patch adds kernel support to capture two of the cycle counters
as part of perf sample using the sample type:
PERF_SAMPLE_WEIGHT_STRUCT.

The power PMU function 'get_mem_weight' currently uses 64 bit weight
field of perf_sample_data to capture memory latency. But following the
introduction of PERF_SAMPLE_WEIGHT_TYPE, weight field could contain
64-bit or 32-bit value depending on the architexture support for
PERF_SAMPLE_WEIGHT_STRUCT. Patches uses WEIGHT_STRUCT to expose the
pipeline stage cycles info. Hence update the ppmu functions to work for
64-bit and 32-bit weight values.

If the sample type is PERF_SAMPLE_WEIGHT, use the 64-bit weight field.
if the sample type is PERF_SAMPLE_WEIGHT_STRUCT, memory subsystem
latency is stored in the low 32bits of perf_sample_weight structure.
Also for CPU_FTR_ARCH_31, capture the two cycle counter information in
two 16 bit fields of perf_sample_weight structure.

Changes looks fine to me.

You mean just the kernel part or can I add your Reviewed-by to all the
patchset?



Yes, kindly add it, I did review the patchset. My bad, i should have 
mentioned it here


or should have replied to the cover letter.


Maddy


  

Reviewed-by: Madhavan Srinivasan 



Signed-off-by: Athira Rajeev 
---
   arch/powerpc/include/asm/perf_event_server.h |  2 +-
   arch/powerpc/perf/core-book3s.c  |  4 ++--
   arch/powerpc/perf/isa207-common.c| 29 
+---
   arch/powerpc/perf/isa207-common.h|  6 +-
   4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/perf_event_server.h 
b/arch/powerpc/include/asm/perf_event_server.h
index 00e7e671bb4b..112cf092d7b3 100644
--- a/arch/powerpc/include/asm/perf_event_server.h
+++ b/arch/powerpc/include/asm/perf_event_server.h
@@ -43,7 +43,7 @@ struct power_pmu {
u64 alt[]);
void(*get_mem_data_src)(union perf_mem_data_src *dsrc,
u32 flags, struct pt_regs *regs);
-   void(*get_mem_weight)(u64 *weight);
+   void(*get_mem_weight)(u64 *weight, u64 type);
unsigned long   group_constraint_mask;
unsigned long   group_constraint_val;
u64 (*bhrb_filter_map)(u64 branch_sample_type);
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 766f064f00fb..6936763246bd 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -2206,9 +2206,9 @@ static void record_and_restart(struct perf_event *event, 
unsigned long val,
ppmu->get_mem_data_src)
ppmu->get_mem_data_src(_src, ppmu->flags, 
regs);
-   if (event->attr.sample_type & PERF_SAMPLE_WEIGHT &&
+   if (event->attr.sample_type & PERF_SAMPLE_WEIGHT_TYPE &&
ppmu->get_mem_weight)
-   ppmu->get_mem_weight();
+   ppmu->get_mem_weight(, 
event->attr.sample_type);
if (perf_event_overflow(event, , regs))
power_pmu_stop(event, 0);
diff --git a/arch/powerpc/perf/isa207-common.c 
b/arch/powerpc/perf/isa207-common.c
index e4f577da33d8..5dcbdbd54598 100644
--- a/arch/powerpc/perf/isa207-common.c
+++ b/arch/powerpc/perf/isa207-common.c
@@ -284,8 +284,10 @@ void isa207_get_mem_data_src(union perf_mem_data_src 
*dsrc, u32 flags,
}
   }
-void isa207_get_mem_weight(u64 *weight)
+void isa207_get_mem_weight(u64 *weight, u64 type)
   {
+   union perf_sample_weight *weight_fields;
+   u64 weight_lat;
u64 mmcra = mfspr(SPRN_MMCRA);
u64 exp = MMCRA_THR_CTR_EXP(mmcra);
u64 mantissa = MMCRA_THR_CTR_MANT(mmcra);
@@ -296,9 +298,30 @@ void isa207_get_mem_weight(u64 *weight)
mantissa = P10_MMCRA_THR_CTR_MANT(mmcra);
if (val == 0 || val == 7)
-   *weight = 0;
+   weight_lat = 0;
else
-   *weight = mantissa << (2 * exp);
+   weight_lat = mantissa << (2 * exp);
+
+   /*
+* Use 64 bit weight field (full) if sample type is
+* WEIGHT.
+*
+* if sample type is WEIGHT_STRUCT:
+* - store memory latency in the lower 32 bits.
+* - For ISA v3.1, use remaining two 16 bit fields of
+*   perf_sample_weight to store cycle counter values
+*   from sier2.
+*/
+   weight_fields = (union perf_sample_weight *)weight;
+   if (type & 

[PATCH] powerpc/mm/book3s64: Use the correct storage key value when calling H_PROTECT

2021-03-26 Thread Aneesh Kumar K.V
H_PROTECT expect the flag value to include
flags: AVPN, pp0, pp1, pp2, key0-key4, Noexec, CMO Option flags

This patch updates hpte_updatepp() to fetch the storage key value from the 
linux page
table and use the same in H_PROTECT hcall.

native_hpte_updatepp() is not updated because the kernel doesn't clear the 
existing
storage key value there. The kernel also doesn't use hpte_updatepp() callback 
for
updating storage keys.

This fixes the below kernel crash observed with KUAP enabled.

 BUG: Unable to handle kernel data access on write at 0xc009fc44
 Faulting instruction address: 0xc00b7030
 Key fault AMR: 0xfcff IAMR: 0xc077bc498100
 Found HPTE: v = 0x40070adbb6fffc05 r = 0x1ff1194
 Oops: Kernel access of bad area, sig: 11 [#1]
 LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
.
 CFAR: c0010100 DAR: c009fc44 DSISR: 0220 IRQMASK: 0
..
 NIP [c00b7030] memset+0x68/0x104
 LR [c03ef00c] pcpu_alloc+0x54c/0xb50
 Call Trace:
 [c0001c7534f0] [c03ef01c] pcpu_alloc+0x55c/0xb50 (unreliable)
 [c0001c753600] [c08bb214] blk_stat_alloc_callback+0x94/0x150
 [c0001c753650] [c08b7a04] blk_mq_init_allocated_queue+0x64/0x560
 [c0001c7536b0] [c08b8024] blk_mq_init_queue+0x54/0xb0
 [c0001c7536e0] [c0b87650] scsi_mq_alloc_queue+0x30/0xa0
 [c0001c753710] [c0b88b2c] scsi_alloc_sdev+0x1cc/0x300
 [c0001c7537b0] [c0b897b0] scsi_probe_and_add_lun+0xb50/0x1020
 [c0001c753950] [c0b8a35c] __scsi_scan_target+0x17c/0x790
 [c0001c753a80] [c0b8ab90] scsi_scan_channel+0x90/0xe0
 [c0001c753ad0] [c0b8ae48] scsi_scan_host_selected+0x148/0x1f0
 [c0001c753b60] [c0b8b31c] do_scan_async+0x2c/0x2a0
 [c0001c753be0] [c0187a18] async_run_entry_fn+0x78/0x220
 [c0001c753c70] [c0176a74] process_one_work+0x264/0x540
 [c0001c753d10] [c0177338] worker_thread+0xa8/0x600
 [c0001c753da0] [c01807b0] kthread+0x190/0x1a0
 [c0001c753e10] [c000d8f0] ret_from_kernel_thread+0x5c/0x6c

With KUAP enabled the kernel uses storage key 3 for all its translations. But as
shown by the debug print, in this specific case we have the hash page table
entry created with key value 0.

[2.249497] Found HPTE: v = 0x40070adbb6fffc05 r = 0x1ff1194

and DSISR indicates a key fault.

This can happen due to parallel fault on the same EA by different CPUs

CPU 0   CPU 1
fault on X

H_PAGE_BUSY set
fault on X

finish fault handling and
clear H_PAGE_BUSY
check for H_PAGE_BUSY
continue with fault handling.

This implies CPU1 will end up calling hpte_updatepp for address X
and the kernel updated the hash pte entry with key 0

Fixes: d94b827e89dc ("powerpc/book3s64/kuap: Use Key 3 for kernel mapping with 
hash translation")

Debugged-by: Michael Ellerman 
Reported-by: Murilo Opsfelder Araujo 
Signed-off-by: Aneesh Kumar K.V 
---

Similar change for bolted hash pte entries was done by
https://lore.kernel.org/linuxppc-dev/20210211135130.3474832-2-...@ellerman.id.au/

 arch/powerpc/platforms/pseries/lpar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/lpar.c 
b/arch/powerpc/platforms/pseries/lpar.c
index 764170fdb0f7..3805519a6469 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -887,7 +887,8 @@ static long pSeries_lpar_hpte_updatepp(unsigned long slot,
 
want_v = hpte_encode_avpn(vpn, psize, ssize);
 
-   flags = (newpp & 7) | H_AVPN;
+   flags = (newpp & (HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_LO)) | H_AVPN;
+   flags |= (newpp & HPTE_R_KEY_HI) >> 48;
if (mmu_has_feature(MMU_FTR_KERNEL_RO))
/* Move pp0 into bit 8 (IBM 55) */
flags |= (newpp & HPTE_R_PP0) >> 55;
-- 
2.30.2



Re: [PATCH -next] treewide: Remove duplicated include from tm-vmx-unavail.c

2021-03-26 Thread Christophe Leroy

Le 26/03/2021 à 07:48, Zheng Yongjun a écrit :

Remove duplicated include.



Why is that flagged "treewide" ?

Can you please combine all similar changes to tools/testing/selftests/powerpc/ into a single patch 
please ?


Thanks
Christophe


Reported-by: Hulk Robot 
Signed-off-by: Zheng Yongjun 
---
  tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c | 1 -
  1 file changed, 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c 
b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
index e2a0c07e8362..9ef37a9836ac 100644
--- a/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
+++ b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
@@ -17,7 +17,6 @@
  #include 
  #include 
  #include 
-#include 
  
  #include "tm.h"

  #include "utils.h"



[PATCH -next] treewide: Remove duplicated include from tm-vmx-unavail.c

2021-03-26 Thread Zheng Yongjun
Remove duplicated include.

Reported-by: Hulk Robot 
Signed-off-by: Zheng Yongjun 
---
 tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c 
b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
index e2a0c07e8362..9ef37a9836ac 100644
--- a/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
+++ b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "tm.h"
 #include "utils.h"



[PATCH -next] selftests/powerpc: Remove duplicated include from tm-poison.c

2021-03-26 Thread Zheng Yongjun
Remove duplicated include.

Reported-by: Hulk Robot 
Signed-off-by: Zheng Yongjun 
---
 tools/testing/selftests/powerpc/tm/tm-poison.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/tm/tm-poison.c 
b/tools/testing/selftests/powerpc/tm/tm-poison.c
index 29e5f26af7b9..27c083a03d1f 100644
--- a/tools/testing/selftests/powerpc/tm/tm-poison.c
+++ b/tools/testing/selftests/powerpc/tm/tm-poison.c
@@ -20,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "tm.h"
 



Re: [PATCH v2 6/7] cmdline: Gives architectures opportunity to use generically defined boot cmdline manipulation

2021-03-26 Thread Christophe Leroy




Le 03/03/2021 à 18:57, Will Deacon a écrit :

On Tue, Mar 02, 2021 at 05:25:22PM +, Christophe Leroy wrote:

Most architectures have similar boot command line manipulation
options. This patchs adds the definition in init/Kconfig, gated by
CONFIG_HAVE_CMDLINE that the architectures can select to use them.

In order to use this, a few architectures will have to change their
CONFIG options:
- riscv has to replace CMDLINE_FALLBACK by CMDLINE_FROM_BOOTLOADER
- architectures using CONFIG_CMDLINE_OVERRIDE or
CONFIG_CMDLINE_OVERWRITE have to replace them by CONFIG_CMDLINE_FORCE.

Architectures also have to define CONFIG_DEFAULT_CMDLINE.

Signed-off-by: Christophe Leroy 
---
  init/Kconfig | 56 
  1 file changed, 56 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index 22946fe5ded9..a0f2ad9467df 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -117,6 +117,62 @@ config INIT_ENV_ARG_LIMIT
  Maximum of each of the number of arguments and environment
  variables passed to init from the kernel command line.
  
+config HAVE_CMDLINE

+   bool
+
+config CMDLINE_BOOL
+   bool "Default bootloader kernel arguments"
+   depends on HAVE_CMDLINE
+   help
+ On some platforms, there is currently no way for the boot loader to
+ pass arguments to the kernel. For these platforms, you can supply
+ some command-line options at build time by entering them here.  In
+ most cases you will need to specify the root device here.


Why is this needed as well as CMDLINE_FROM_BOOTLOADER? IIUC, the latter
will use CONFIG_CMDLINE if it fails to get anything from the bootloader,
which sounds like the same scenario.


+config CMDLINE
+   string "Initial kernel command string"


s/Initial/Default

which is then consistent with the rest of the text here.


+   depends on CMDLINE_BOOL


Ah, so this is a bit different and I don't think lines-up with the
CMDLINE_BOOL help text.


You are right, the help text is duplicated, I will change the text for the 
CMDLINE_BOOL




+   default DEFAULT_CMDLINE
+   help
+ On some platforms, there is currently no way for the boot loader to
+ pass arguments to the kernel. For these platforms, you can supply
+ some command-line options at build time by entering them here.  In
+ most cases you will need to specify the root device here.


(same stale text)


+choice
+   prompt "Kernel command line type" if CMDLINE != ""
+   default CMDLINE_FROM_BOOTLOADER
+   help
+ Selects the way you want to use the default kernel arguments.


How about:

"Determines how the default kernel arguments are combined with any
  arguments passed by the bootloader"


+config CMDLINE_FROM_BOOTLOADER
+   bool "Use bootloader kernel arguments if available"
+   help
+ Uses the command-line options passed by the boot loader. If
+ the boot loader doesn't provide any, the default kernel command
+ string provided in CMDLINE will be used.
+
+config CMDLINE_EXTEND


Can we rename this to CMDLINE_APPEND, please? There is code in the tree
which disagrees about what CMDLINE_EXTEND means, so that will need be
to be updated to be consistent (e.g. the EFI stub parsing order). Having
the generic option with a different name means we won't accidentally end
up with the same inconsistent behaviours.


+   bool "Extend bootloader kernel arguments"


"Append to the bootloader kernel arguments"


+   help
+ The default kernel command string will be appended to the
+ command-line arguments provided during boot.


s/provided during boot/provided by the bootloader/


+
+config CMDLINE_PREPEND
+   bool "Prepend bootloader kernel arguments"


"Prepend to the bootloader kernel arguments"


+   help
+ The default kernel command string will be prepend to the
+ command-line arguments provided during boot.


s/prepend/prepended/
s/provided during boot/provided by the bootloader/


+
+config CMDLINE_FORCE
+   bool "Always use the default kernel command string"
+   help
+ Always use the default kernel command string, even if the boot
+ loader passes other arguments to the kernel.
+ This is useful if you cannot or don't want to change the
+ command-line options your boot loader passes to the kernel.


I find the "This is useful if ..." sentence really confusing, perhaps just
remove it? I'd then tweak it to be:

   "Always use the default kernel command string, ignoring any arguments
provided by the bootloader."



Taken all your suggested text.

Thanks
Christophe


Re: [PATCH v2 6/7] cmdline: Gives architectures opportunity to use generically defined boot cmdline manipulation

2021-03-26 Thread Christophe Leroy




Le 25/03/2021 à 20:32, Will Deacon a écrit :

On Thu, Mar 25, 2021 at 12:18:38PM +0100, Christophe Leroy wrote:


- For ARM it means to append the bootloader arguments to the CONFIG_CMDLINE
- For Powerpc it means to append the CONFIG_CMDLINE to the bootloader arguments
- For SH  it means to append the CONFIG_CMDLINE to the bootloader arguments
- For EFI it means to append the bootloader arguments to the CONFIG_CMDLINE
- For OF it means to append the CONFIG_CMDLINE to the bootloader arguments

So what happens on ARM for instance when it selects CONFIG_OF for instance ?


I think ARM gets different behaviour depending on whether it uses ATAGs or
FDT.


As far as I can see, ARM uses either ATAGs only or both ATAGs and FDT. ATAGs is forced to 'y' when 
USE_OF is set. Do I miss something ?





Or should we consider that EXTEND means APPEND or PREPEND, no matter which ?
Because EXTEND is for instance used for:

config INITRAMFS_FORCE
bool "Ignore the initramfs passed by the bootloader"
depends on CMDLINE_EXTEND || CMDLINE_FORCE


Oh man, I didn't spot that one :(

I think I would make the generic options explicit: either APPEND or PREPEND.
Then architectures which choose to define CMDLINE_EXTEND in their Kconfigs
can select the generic option that matches their behaviour.

INITRAMFS_FORCE sounds like it should depend on APPEND (assuming that means
CONFIG_CMDLINE is appended to the bootloader arguments).




Christophe


[PATCH 1/2] vfio/pci: remove vfio_pci_nvlink2

2021-03-26 Thread Christoph Hellwig
This driver never had any open userspace (which for VFIO would include
VM kernel drivers) that use it, and thus should never have been added
by our normal userspace ABI rules.

Signed-off-by: Christoph Hellwig 
Acked-by: Greg Kroah-Hartman 
---
 drivers/vfio/pci/Kconfig|   6 -
 drivers/vfio/pci/Makefile   |   1 -
 drivers/vfio/pci/vfio_pci.c |  18 -
 drivers/vfio/pci/vfio_pci_nvlink2.c | 490 
 drivers/vfio/pci/vfio_pci_private.h |  14 -
 include/uapi/linux/vfio.h   |  38 +--
 6 files changed, 4 insertions(+), 563 deletions(-)
 delete mode 100644 drivers/vfio/pci/vfio_pci_nvlink2.c

diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
index ac3c1dd3edeff1..53ce78d7d07be0 100644
--- a/drivers/vfio/pci/Kconfig
+++ b/drivers/vfio/pci/Kconfig
@@ -39,9 +39,3 @@ config VFIO_PCI_IGD
  and LPC bridge config space.
 
  To enable Intel IGD assignment through vfio-pci, say Y.
-
-config VFIO_PCI_NVLINK2
-   def_bool y
-   depends on VFIO_PCI && PPC_POWERNV
-   help
- VFIO PCI support for P9 Witherspoon machine with NVIDIA V100 GPUs
diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile
index eff97a7cd9f139..3ff42093962f6f 100644
--- a/drivers/vfio/pci/Makefile
+++ b/drivers/vfio/pci/Makefile
@@ -2,7 +2,6 @@
 
 vfio-pci-y := vfio_pci.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o
 vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o
-vfio-pci-$(CONFIG_VFIO_PCI_NVLINK2) += vfio_pci_nvlink2.o
 vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o
 
 obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 65e7e6b44578c2..d691006b642839 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -389,24 +389,6 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
}
}
 
-   if (pdev->vendor == PCI_VENDOR_ID_NVIDIA &&
-   IS_ENABLED(CONFIG_VFIO_PCI_NVLINK2)) {
-   ret = vfio_pci_nvdia_v100_nvlink2_init(vdev);
-   if (ret && ret != -ENODEV) {
-   pci_warn(pdev, "Failed to setup NVIDIA NV2 RAM 
region\n");
-   goto disable_exit;
-   }
-   }
-
-   if (pdev->vendor == PCI_VENDOR_ID_IBM &&
-   IS_ENABLED(CONFIG_VFIO_PCI_NVLINK2)) {
-   ret = vfio_pci_ibm_npu2_init(vdev);
-   if (ret && ret != -ENODEV) {
-   pci_warn(pdev, "Failed to setup NVIDIA NV2 ATSD 
region\n");
-   goto disable_exit;
-   }
-   }
-
vfio_pci_probe_mmaps(vdev);
 
return 0;
diff --git a/drivers/vfio/pci/vfio_pci_nvlink2.c 
b/drivers/vfio/pci/vfio_pci_nvlink2.c
deleted file mode 100644
index 9adcf6a8f88857..00
--- a/drivers/vfio/pci/vfio_pci_nvlink2.c
+++ /dev/null
@@ -1,490 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * VFIO PCI NVIDIA Whitherspoon GPU support a.k.a. NVLink2.
- *
- * Copyright (C) 2018 IBM Corp.  All rights reserved.
- * Author: Alexey Kardashevskiy 
- *
- * Register an on-GPU RAM region for cacheable access.
- *
- * Derived from original vfio_pci_igd.c:
- * Copyright (C) 2016 Red Hat, Inc.  All rights reserved.
- * Author: Alex Williamson 
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "vfio_pci_private.h"
-
-#define CREATE_TRACE_POINTS
-#include "trace.h"
-
-EXPORT_TRACEPOINT_SYMBOL_GPL(vfio_pci_nvgpu_mmap_fault);
-EXPORT_TRACEPOINT_SYMBOL_GPL(vfio_pci_nvgpu_mmap);
-EXPORT_TRACEPOINT_SYMBOL_GPL(vfio_pci_npu2_mmap);
-
-struct vfio_pci_nvgpu_data {
-   unsigned long gpu_hpa; /* GPU RAM physical address */
-   unsigned long gpu_tgt; /* TGT address of corresponding GPU RAM */
-   unsigned long useraddr; /* GPU RAM userspace address */
-   unsigned long size; /* Size of the GPU RAM window (usually 128GB) */
-   struct mm_struct *mm;
-   struct mm_iommu_table_group_mem_t *mem; /* Pre-registered RAM descr. */
-   struct pci_dev *gpdev;
-   struct notifier_block group_notifier;
-};
-
-static size_t vfio_pci_nvgpu_rw(struct vfio_pci_device *vdev,
-   char __user *buf, size_t count, loff_t *ppos, bool iswrite)
-{
-   unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - VFIO_PCI_NUM_REGIONS;
-   struct vfio_pci_nvgpu_data *data = vdev->region[i].data;
-   loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
-   loff_t posaligned = pos & PAGE_MASK, posoff = pos & ~PAGE_MASK;
-   size_t sizealigned;
-   void __iomem *ptr;
-
-   if (pos >= vdev->region[i].size)
-   return -EINVAL;
-
-   count = min(count, (size_t)(vdev->region[i].size - pos));
-
-   /*
-* We map only a bit of GPU RAM for a short time instead of mapping it
-* for the guest lifetime as:
-*
-* 1) we do not know GPU RAM size, only aperture which is 4-8 times
-*bigger than actual 

[PATCH 2/2] powerpc/powernv: remove the nvlink support

2021-03-26 Thread Christoph Hellwig
This code was only used by the vfio-nvlink2 code, which itself had no
proper use.  Drop this huge chunk of code build into every powernv
or generic build.

Signed-off-by: Christoph Hellwig 
Acked-by: Greg Kroah-Hartman 
---
 arch/powerpc/include/asm/opal.h|   3 -
 arch/powerpc/include/asm/pci-bridge.h  |   1 -
 arch/powerpc/include/asm/pci.h |   7 -
 arch/powerpc/platforms/powernv/Makefile|   2 +-
 arch/powerpc/platforms/powernv/npu-dma.c   | 705 -
 arch/powerpc/platforms/powernv/opal-call.c |   2 -
 arch/powerpc/platforms/powernv/pci-ioda.c  | 185 +-
 arch/powerpc/platforms/powernv/pci.c   |  11 -
 arch/powerpc/platforms/powernv/pci.h   |  17 +-
 arch/powerpc/platforms/pseries/pci.c   |  23 -
 10 files changed, 8 insertions(+), 948 deletions(-)
 delete mode 100644 arch/powerpc/platforms/powernv/npu-dma.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9986ac34b8e224..06eaa231697344 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -28,9 +28,6 @@ extern struct device_node *opal_node;
 
 /* API functions */
 int64_t opal_invalid_call(void);
-int64_t opal_npu_destroy_context(uint64_t phb_id, uint64_t pid, uint64_t bdf);
-int64_t opal_npu_init_context(uint64_t phb_id, int pasid, uint64_t msr,
-   uint64_t bdf);
 int64_t opal_npu_map_lpar(uint64_t phb_id, uint64_t bdf, uint64_t lparid,
uint64_t lpcr);
 int64_t opal_npu_spa_setup(uint64_t phb_id, uint32_t bdfn,
diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index d2a2a14e56f91e..74424c14515ce0 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -126,7 +126,6 @@ struct pci_controller {
 #endif /* CONFIG_PPC64 */
 
void *private_data;
-   struct npu *npu;
 };
 
 /* These are used for config access before all the PCI probing
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index 6436f0b41539e3..d1f53260725ca7 100644
--- a/arch/powerpc/include/asm/pci.h
+++ b/arch/powerpc/include/asm/pci.h
@@ -119,11 +119,4 @@ extern void pcibios_scan_phb(struct pci_controller *hose);
 
 #endif /* __KERNEL__ */
 
-extern struct pci_dev *pnv_pci_get_gpu_dev(struct pci_dev *npdev);
-extern struct pci_dev *pnv_pci_get_npu_dev(struct pci_dev *gpdev, int index);
-extern int pnv_npu2_init(struct pci_controller *hose);
-extern int pnv_npu2_map_lpar_dev(struct pci_dev *gpdev, unsigned int lparid,
-   unsigned long msr);
-extern int pnv_npu2_unmap_lpar_dev(struct pci_dev *gpdev);
-
 #endif /* __ASM_POWERPC_PCI_H */
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index 2eb6ae150d1fd5..be2546b968165e 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_SMP) += smp.o subcore.o subcore-asm.o
 obj-$(CONFIG_FA_DUMP)  += opal-fadump.o
 obj-$(CONFIG_PRESERVE_FA_DUMP) += opal-fadump.o
 obj-$(CONFIG_OPAL_CORE)+= opal-core.o
-obj-$(CONFIG_PCI)  += pci.o pci-ioda.o npu-dma.o pci-ioda-tce.o
+obj-$(CONFIG_PCI)  += pci.o pci-ioda.o pci-ioda-tce.o
 obj-$(CONFIG_PCI_IOV)   += pci-sriov.o
 obj-$(CONFIG_CXL_BASE) += pci-cxl.o
 obj-$(CONFIG_EEH)  += eeh-powernv.o
diff --git a/arch/powerpc/platforms/powernv/npu-dma.c 
b/arch/powerpc/platforms/powernv/npu-dma.c
deleted file mode 100644
index b711dc3262a308..00
--- a/arch/powerpc/platforms/powernv/npu-dma.c
+++ /dev/null
@@ -1,705 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * This file implements the DMA operations for NVLink devices. The NPU
- * devices all point to the same iommu table as the parent PCI device.
- *
- * Copyright Alistair Popple, IBM Corporation 2015.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-
-#include "pci.h"
-
-static struct pci_dev *get_pci_dev(struct device_node *dn)
-{
-   struct pci_dn *pdn = PCI_DN(dn);
-   struct pci_dev *pdev;
-
-   pdev = pci_get_domain_bus_and_slot(pci_domain_nr(pdn->phb->bus),
-  pdn->busno, pdn->devfn);
-
-   /*
-* pci_get_domain_bus_and_slot() increased the reference count of
-* the PCI device, but callers don't need that actually as the PE
-* already holds a reference to the device. Since callers aren't
-* aware of the reference count change, call pci_dev_put() now to
-* avoid leaks.
-*/
-   if (pdev)
-   pci_dev_put(pdev);
-
-   return pdev;
-}
-
-/* Given a NPU device get the associated PCI device. */
-struct pci_dev *pnv_pci_get_gpu_dev(struct pci_dev *npdev)
-{
-   struct device_node *dn;
-   struct pci_dev *gpdev;
-
-   if (WARN_ON(!npdev))
-   return NULL;
-
-   if 

remove the nvlink2 pci_vfio subdriver v2

2021-03-26 Thread Christoph Hellwig
Hi all,

the nvlink2 vfio subdriver is a weird beast.  It supports a hardware
feature without any open source component - what would normally be
the normal open source userspace that we require for kernel drivers,
although in this particular case user space could of course be a
kernel driver in a VM.  It also happens to be a complete mess that
does not properly bind to PCI IDs, is hacked into the vfio_pci driver
and also pulles in over 1000 lines of code always build into powerpc
kernels that have Power NV support enabled.  Because of all these
issues and the lack of breaking userspace when it is removed I think
the best idea is to simply kill.

Changes since v1:
 - document the removed subtypes as reserved
 - add the ACK from Greg

Diffstat:
 arch/powerpc/platforms/powernv/npu-dma.c |  705 ---
 b/arch/powerpc/include/asm/opal.h|3 
 b/arch/powerpc/include/asm/pci-bridge.h  |1 
 b/arch/powerpc/include/asm/pci.h |7 
 b/arch/powerpc/platforms/powernv/Makefile|2 
 b/arch/powerpc/platforms/powernv/opal-call.c |2 
 b/arch/powerpc/platforms/powernv/pci-ioda.c  |  185 ---
 b/arch/powerpc/platforms/powernv/pci.c   |   11 
 b/arch/powerpc/platforms/powernv/pci.h   |   17 
 b/arch/powerpc/platforms/pseries/pci.c   |   23 
 b/drivers/vfio/pci/Kconfig   |6 
 b/drivers/vfio/pci/Makefile  |1 
 b/drivers/vfio/pci/vfio_pci.c|   18 
 b/drivers/vfio/pci/vfio_pci_private.h|   14 
 b/include/uapi/linux/vfio.h  |   38 -
 drivers/vfio/pci/vfio_pci_nvlink2.c  |  490 --
 16 files changed, 12 insertions(+), 1511 deletions(-)


Re: [PATCH] powerpc/iommu/debug: Remove redundant NULL check

2021-03-26 Thread Daniel Axtens
Daniel Axtens  writes:

It looks like the kernel test robot also reported this:
"[PATCH] powerpc/iommu/debug: fix ifnullfree.cocci warnings"
Weirdly I don't see it in patchwork.

I'm not sure which one mpe will want to take but either would do.

>> Fix the following coccicheck warnings:
>>
>> ./fs/io_uring.c:5989:4-9: WARNING: NULL check before some freeing
>> functions is not needed.

(Also, while unimportant, that's technically not the error you fix here
as it's for a different file!)

>
> This looks correct to me, and matches the description of debugfs_remove
> in Documentation/filesystems/debugfs.rst.
>
> If you have a number of similar fixes it might be helpful to do them in
> a single bigger patch, but I'm not sure if coccicheck reports much else
> as I don't have coccinelle installed at the moment.
>
> Reviewed-by: Daniel Axtens 
>
> Kind regards,
> Daniel


Re: [PATCH] crypto: vmx: fix incorrect kernel-doc comment syntax in files

2021-03-26 Thread Daniel Axtens
Hi Aditya,

Thanks for your patch!

> The opening comment mark '/**' is used for highlighting the beginning of
> kernel-doc comments.
> There are certain files in drivers/crypto/vmx, which follow this syntax,
> but the content inside does not comply with kernel-doc.
> Such lines were probably not meant for kernel-doc parsing, but are parsed
> due to the presence of kernel-doc like comment syntax(i.e, '/**'), which
> causes unexpected warnings from kernel-doc.
>
> E.g., presence of kernel-doc like comment in the header line for
> drivers/crypto/vmx/vmx.c causes this warning by kernel-doc:
>
> "warning: expecting prototype for Routines supporting VMX instructions on the 
> Power 8(). Prototype was for p8_init() instead"

checkpatch (scripts/checkpatch.pl --strict -g HEAD) complains about this line:
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per 
line)
but checkpatch should be ignored here, as you did the right thing by not
breaking an error message across multiple lines.

> Similarly for other files too.
>
> Provide a simple fix by replacing such occurrences with general comment
> format, i.e. '/*', to prevent kernel-doc from parsing it.

This makes sense.

Reviewed-by: Daniel Axtens 

Kind regards,
Daniel

>
> Signed-off-by: Aditya Srivastava 
> ---
> * Applies perfectly on next-20210319
>
>  drivers/crypto/vmx/aes.c | 2 +-
>  drivers/crypto/vmx/aes_cbc.c | 2 +-
>  drivers/crypto/vmx/aes_ctr.c | 2 +-
>  drivers/crypto/vmx/aes_xts.c | 2 +-
>  drivers/crypto/vmx/ghash.c   | 2 +-
>  drivers/crypto/vmx/vmx.c | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/crypto/vmx/aes.c b/drivers/crypto/vmx/aes.c
> index d05c02baebcf..ec06189fbf99 100644
> --- a/drivers/crypto/vmx/aes.c
> +++ b/drivers/crypto/vmx/aes.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -/**
> +/*
>   * AES routines supporting VMX instructions on the Power 8
>   *
>   * Copyright (C) 2015 International Business Machines Inc.
> diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
> index d88084447f1c..ed0debc7acb5 100644
> --- a/drivers/crypto/vmx/aes_cbc.c
> +++ b/drivers/crypto/vmx/aes_cbc.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -/**
> +/*
>   * AES CBC routines supporting VMX instructions on the Power 8
>   *
>   * Copyright (C) 2015 International Business Machines Inc.
> diff --git a/drivers/crypto/vmx/aes_ctr.c b/drivers/crypto/vmx/aes_ctr.c
> index 79ba062ee1c1..9a3da8cd62f3 100644
> --- a/drivers/crypto/vmx/aes_ctr.c
> +++ b/drivers/crypto/vmx/aes_ctr.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -/**
> +/*
>   * AES CTR routines supporting VMX instructions on the Power 8
>   *
>   * Copyright (C) 2015 International Business Machines Inc.
> diff --git a/drivers/crypto/vmx/aes_xts.c b/drivers/crypto/vmx/aes_xts.c
> index 9fee1b1532a4..dabbccb41550 100644
> --- a/drivers/crypto/vmx/aes_xts.c
> +++ b/drivers/crypto/vmx/aes_xts.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -/**
> +/*
>   * AES XTS routines supporting VMX In-core instructions on Power 8
>   *
>   * Copyright (C) 2015 International Business Machines Inc.
> diff --git a/drivers/crypto/vmx/ghash.c b/drivers/crypto/vmx/ghash.c
> index 14807ac2e3b9..5bc5710a6de0 100644
> --- a/drivers/crypto/vmx/ghash.c
> +++ b/drivers/crypto/vmx/ghash.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0
> -/**
> +/*
>   * GHASH routines supporting VMX instructions on the Power 8
>   *
>   * Copyright (C) 2015, 2019 International Business Machines Inc.
> diff --git a/drivers/crypto/vmx/vmx.c b/drivers/crypto/vmx/vmx.c
> index a40d08e75fc0..7eb713cc87c8 100644
> --- a/drivers/crypto/vmx/vmx.c
> +++ b/drivers/crypto/vmx/vmx.c
> @@ -1,5 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> -/**
> +/*
>   * Routines supporting VMX instructions on the Power 8
>   *
>   * Copyright (C) 2015 International Business Machines Inc.
> -- 
> 2.17.1