* Re: [PATCH] powerpc/pseries: use slab context cpumask allocation in CPU hotplug init
From: Michael Ellerman @ 2021-12-21 12:14 UTC (permalink / raw)
To: linuxppc-dev, Nicholas Piggin
In-Reply-To: <20211105132923.1582514-1-npiggin@gmail.com>
On Fri, 5 Nov 2021 23:29:23 +1000, Nicholas Piggin wrote:
> Slab is up at this point, using the bootmem allocator triggers a
> warning. Switch to using the regular cpumask allocator.
>
>
Applied to powerpc/next.
[1/1] powerpc/pseries: use slab context cpumask allocation in CPU hotplug init
https://git.kernel.org/powerpc/c/3b54c71537d7beaaca8be9c57a81045e2b641655
cheers
^ permalink raw reply
* Re: [PATCH]selftests/powerpc: skip tests for unavailable mitigations.
From: Michael Ellerman @ 2021-12-21 12:14 UTC (permalink / raw)
To: linuxppc-dev, Sachin Sant; +Cc: Nageswara R Sastry
In-Reply-To: <163941374362.36967.18016981579099073379.sendpatchset@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa>
On Mon, 13 Dec 2021 22:12:23 +0530, Sachin Sant wrote:
> Mitigation patching test iterates over a set of mitigations irrespective
> of whether a certain mitigation is supported/available in the kernel.
> This causes following messages on a kernel where some mitigations
> are unavailable:
>
> Spawned threads enabling/disabling mitigations ...
> cat: entry_flush: No such file or directory
> cat: uaccess_flush: No such file or directory
> Waiting for timeout ...
> OK
>
> [...]
Applied to powerpc/next.
[1/1] selftests/powerpc: skip tests for unavailable mitigations.
https://git.kernel.org/powerpc/c/18678591846d668649fbd4f87b4a4c470818d386
cheers
^ permalink raw reply
* Re: [PATCH 0/4] perf: Add new macros for mem_hops field
From: Michael Ellerman @ 2021-12-21 12:14 UTC (permalink / raw)
To: ak, Kajol Jain, linuxppc-dev, acme, mpe, namhyung, linux-kernel,
mingo, jolsa, peterz
Cc: mark.rutland, songliubraving, atrajeev, daniel, rnsastry,
alexander.shishkin, ast, linux-perf-users, yao.jin, maddy, paulus,
kan.liang
In-Reply-To: <20211206091749.87585-1-kjain@linux.ibm.com>
On Mon, 6 Dec 2021 14:47:45 +0530, Kajol Jain wrote:
> Patchset adds new macros for mem_hops field which can be
> used to represent remote-node, socket and board level details.
>
> Currently the code had macro for HOPS_0, which corresponds
> to data coming from another core but same node.
> Add new macros for HOPS_1 to HOPS_3 to represent
> remote-node, socket and board level data.
>
> [...]
Patches 1, 3 and 4 applied to powerpc/next.
[1/4] perf: Add new macros for mem_hops field
https://git.kernel.org/powerpc/c/cb1c4aba055f928ffae0c868e8dfe08eeab302e7
[3/4] powerpc/perf: Add encodings to represent data based on newer composite PERF_MEM_LVLNUM* fields
https://git.kernel.org/powerpc/c/4a20ee106154ac1765dea97932faad29f0ba57fc
[4/4] powerpc/perf: Add data source encodings for power10 platform
https://git.kernel.org/powerpc/c/6ed05a8efda56e5be11081954929421de19cce88
cheers
^ permalink raw reply
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Jarkko Sakkinen @ 2021-12-21 8:47 UTC (permalink / raw)
To: Stefan Berger
Cc: Korrapati.Likhitha, pavrampu, linux-kernel, jgg,
linux-security-module, gcwilson, peterhuewe, linuxppc-dev,
linux-integrity
In-Reply-To: <20211212012804.1555661-1-stefanb@linux.ibm.com>
On Sat, Dec 11, 2021 at 08:28:04PM -0500, Stefan Berger wrote:
> Fix the following crash on kexec by checking chip->ops for a NULL pointer
> in tpm_chip_start() and returning an error code if this is the case.
>
> BUG: Kernel NULL pointer dereference on read at 0x00000060
> Faulting instruction address: 0xc00000000099a06c
> Oops: Kernel access of bad area, sig: 11 [#1]
> ...
> NIP [c00000000099a06c] tpm_chip_start+0x2c/0x140
> LR [c00000000099a808] tpm_chip_unregister+0x108/0x170
> Call Trace:
> [c0000000188bfa00] [c000000002b03930] fw_devlink_strict+0x0/0x8 (unreliable)
> [c0000000188bfa30] [c00000000099a808] tpm_chip_unregister+0x108/0x170
> [c0000000188bfa70] [c0000000009a3874] tpm_ibmvtpm_remove+0x34/0x130
> [c0000000188bfae0] [c000000000110dbc] vio_bus_remove+0x5c/0xb0
> [c0000000188bfb20] [c0000000009bc154] device_shutdown+0x1d4/0x3a8
> [c0000000188bfbc0] [c000000000196e14] kernel_restart_prepare+0x54/0x70
>
> The referenced patch below introduced a function to shut down the VIO bus.
> The bus shutdown now calls tpm_del_char_device (via tpm_chip_unregister)
> after a call to tpm_class_shutdown, which already set chip->ops to NULL.
> The crash occurrs when tpm_del_char_device calls tpm_chip_start with the
> chip->ops NULL pointer.
>
> Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> drivers/char/tpm/tpm-chip.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..cca1bde296ee 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -101,6 +101,9 @@ int tpm_chip_start(struct tpm_chip *chip)
> {
> int ret;
>
> + if (!chip->ops)
> + return -EINVAL;
This triggers to all drivers, not just tpm_ibmvtpm, i.e. the fix has
side-effects.
/Jarkko
^ permalink raw reply
* Re: [PATCH kernel v4] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
From: Cédric Le Goater @ 2021-12-21 8:22 UTC (permalink / raw)
To: Alexey Kardashevskiy
Cc: kvm, Fabiano Rosas, Nicholas Piggin, kvm-ppc, David Stevens,
linuxppc-dev
In-Reply-To: <b63e0570-934e-522f-8567-c9c4c438a55e@ozlabs.ru>
>>> - xive->dentry = debugfs_create_file(name, S_IRUGO, arch_debugfs_dir,
>>> + xive->dentry = debugfs_create_file("xive", S_IRUGO, xive->kvm->debugfs_dentry,
>>> xive, &xive_debug_fops);
>>
>> The KVM XIVE device implements a "xics-on-xive" interface, the XICS hcalls
>> on top of the XIVE native PowerNV (OPAL) interface, and ...
>>
>>> - pr_debug("%s: created %s\n", __func__, name);
>>> - kfree(name);
>>> + pr_debug("%s: created\n", __func__);
>>> }
>>>
>>> static void kvmppc_xive_init(struct kvm_device *dev)
>>> diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c
>>> index 99db9ac49901..e86f5b6c2ae1 100644
>>> --- a/arch/powerpc/kvm/book3s_xive_native.c
>>> +++ b/arch/powerpc/kvm/book3s_xive_native.c
>>> @@ -1259,19 +1259,10 @@ DEFINE_SHOW_ATTRIBUTE(xive_native_debug);
>>>
>>> static void xive_native_debugfs_init(struct kvmppc_xive *xive)
>>> {
>>> - char *name;
>>> -
>>> - name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
>>> - if (!name) {
>>> - pr_err("%s: no memory for name\n", __func__);
>>> - return;
>>> - }
>>> -
>>> - xive->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
>>> + xive->dentry = debugfs_create_file("xive", 0444, xive->kvm->debugfs_dentry,
>>> xive, &xive_native_debug_fops);
>>
>> ... the KVM XIVE *native* device implements a "xive" interface", the one
>> using MMIOs for interrupt management.
>>
>> May be it's worth making the difference in the user interface ?
>
>
> The content of these xive files is quite different so I kept the same
> name as before, I can change if you think it is worth it, should I?
It's not very important. The contents differ anyhow.
> You
> are probably the only person who looked at it recently (or ever?) :) Thanks,
and you just did ! :)
Cheers,
C.
^ permalink raw reply
* [PATCH llvm 6/6] powerpc/mm/book3s64/hash: Switch pre 2.06 tlbiel to .long
From: Alexey Kardashevskiy @ 2021-12-21 5:59 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
The llvm integrated assembler does not recognise the ISA 2.05 tlbiel
version. Work around it by switching to .long when an old arch level
detected.
Signed-off-by: Daniel Axtens <dja@axtens.net>
[aik: did "Eventually do this more smartly"]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/include/asm/ppc-opcode.h | 2 ++
arch/powerpc/mm/book3s64/hash_native.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index 9fe3223e7820..efad07081cc0 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -394,6 +394,7 @@
(0x7c000264 | ___PPC_RB(rb) | ___PPC_RS(rs) | ___PPC_RIC(ric) | ___PPC_PRS(prs) | ___PPC_R(r))
#define PPC_RAW_TLBIEL(rb, rs, ric, prs, r) \
(0x7c000224 | ___PPC_RB(rb) | ___PPC_RS(rs) | ___PPC_RIC(ric) | ___PPC_PRS(prs) | ___PPC_R(r))
+#define PPC_RAW_TLBIEL_v205(rb, l) (0x7c000224 | ___PPC_RB(rb) | (l << 21))
#define PPC_RAW_TLBSRX_DOT(a, b) (0x7c0006a5 | __PPC_RA0(a) | __PPC_RB(b))
#define PPC_RAW_TLBIVAX(a, b) (0x7c000624 | __PPC_RA0(a) | __PPC_RB(b))
#define PPC_RAW_ERATWE(s, a, w) (0x7c0001a6 | __PPC_RS(s) | __PPC_RA(a) | __PPC_WS(w))
@@ -606,6 +607,7 @@
stringify_in_c(.long PPC_RAW_TLBIE_5(rb, rs, ric, prs, r))
#define PPC_TLBIEL(rb,rs,ric,prs,r) \
stringify_in_c(.long PPC_RAW_TLBIEL(rb, rs, ric, prs, r))
+#define PPC_TLBIEL_v205(rb, l) stringify_in_c(.long PPC_RAW_TLBIEL_v205(rb, l))
#define PPC_TLBSRX_DOT(a, b) stringify_in_c(.long PPC_RAW_TLBSRX_DOT(a, b))
#define PPC_TLBIVAX(a, b) stringify_in_c(.long PPC_RAW_TLBIVAX(a, b))
diff --git a/arch/powerpc/mm/book3s64/hash_native.c b/arch/powerpc/mm/book3s64/hash_native.c
index d2a320828c0b..623a7b7ab38b 100644
--- a/arch/powerpc/mm/book3s64/hash_native.c
+++ b/arch/powerpc/mm/book3s64/hash_native.c
@@ -163,7 +163,7 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)
va |= ssize << 8;
sllp = get_sllp_encoding(apsize);
va |= sllp << 5;
- asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,0", %1)
+ asm volatile(ASM_FTR_IFSET("tlbiel %0", PPC_TLBIEL_v205(%0, 0), %1)
: : "r" (va), "i" (CPU_FTR_ARCH_206)
: "memory");
break;
@@ -182,7 +182,7 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)
*/
va |= (vpn & 0xfe);
va |= 1; /* L */
- asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,1", %1)
+ asm volatile(ASM_FTR_IFSET("tlbiel %0", PPC_TLBIEL_v205(%0, 1), %1)
: : "r" (va), "i" (CPU_FTR_ARCH_206)
: "memory");
break;
--
2.30.2
^ permalink raw reply related
* [PATCH llvm 5/6] powerpc/mm: Switch obsolete dssall to .long
From: Alexey Kardashevskiy @ 2021-12-21 5:59 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
The dssall ("Data Stream Stop All") instruction is obsolete altogether
with other Data Cache Instructions since ISA 2.03 (year 2006).
LLVM IAS does not support it but PPC970 seems to be using it.
This switches dssall to .long as there is no much point in fixing LLVM.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/include/asm/ppc-opcode.h | 2 ++
arch/powerpc/kernel/idle.c | 2 +-
arch/powerpc/mm/mmu_context.c | 2 +-
arch/powerpc/kernel/idle_6xx.S | 2 +-
arch/powerpc/kernel/l2cr_6xx.S | 6 +++---
arch/powerpc/kernel/swsusp_32.S | 2 +-
arch/powerpc/kernel/swsusp_asm64.S | 2 +-
arch/powerpc/platforms/powermac/cache.S | 4 ++--
8 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index f50213e2a3e0..9fe3223e7820 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -249,6 +249,7 @@
#define PPC_INST_COPY 0x7c20060c
#define PPC_INST_DCBA 0x7c0005ec
#define PPC_INST_DCBA_MASK 0xfc0007fe
+#define PPC_INST_DSSALL 0x7e00066c
#define PPC_INST_ISEL 0x7c00001e
#define PPC_INST_ISEL_MASK 0xfc00003e
#define PPC_INST_LSWI 0x7c0004aa
@@ -577,6 +578,7 @@
#define PPC_DCBZL(a, b) stringify_in_c(.long PPC_RAW_DCBZL(a, b))
#define PPC_DIVDE(t, a, b) stringify_in_c(.long PPC_RAW_DIVDE(t, a, b))
#define PPC_DIVDEU(t, a, b) stringify_in_c(.long PPC_RAW_DIVDEU(t, a, b))
+#define PPC_DSSALL stringify_in_c(.long PPC_INST_DSSALL)
#define PPC_LQARX(t, a, b, eh) stringify_in_c(.long PPC_RAW_LQARX(t, a, b, eh))
#define PPC_STQCX(t, a, b) stringify_in_c(.long PPC_RAW_STQCX(t, a, b))
#define PPC_MADDHD(t, a, b, c) stringify_in_c(.long PPC_RAW_MADDHD(t, a, b, c))
diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index 1f835539fda4..4ad79eb638c6 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -82,7 +82,7 @@ void power4_idle(void)
return;
if (cpu_has_feature(CPU_FTR_ALTIVEC))
- asm volatile("DSSALL ; sync" ::: "memory");
+ asm volatile(PPC_DSSALL " ; sync" ::: "memory");
power4_idle_nap();
diff --git a/arch/powerpc/mm/mmu_context.c b/arch/powerpc/mm/mmu_context.c
index 735c36f26388..1fb9c99f8679 100644
--- a/arch/powerpc/mm/mmu_context.c
+++ b/arch/powerpc/mm/mmu_context.c
@@ -90,7 +90,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
* context
*/
if (cpu_has_feature(CPU_FTR_ALTIVEC))
- asm volatile ("dssall");
+ asm volatile (PPC_DSSALL);
if (!new_on_cpu)
membarrier_arch_switch_mm(prev, next, tsk);
diff --git a/arch/powerpc/kernel/idle_6xx.S b/arch/powerpc/kernel/idle_6xx.S
index 13cad9297d82..3c097356366b 100644
--- a/arch/powerpc/kernel/idle_6xx.S
+++ b/arch/powerpc/kernel/idle_6xx.S
@@ -129,7 +129,7 @@ BEGIN_FTR_SECTION
END_FTR_SECTION_IFCLR(CPU_FTR_NO_DPM)
mtspr SPRN_HID0,r4
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
sync
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
lwz r8,TI_LOCAL_FLAGS(r2) /* set napping bit */
diff --git a/arch/powerpc/kernel/l2cr_6xx.S b/arch/powerpc/kernel/l2cr_6xx.S
index 225511d73bef..f2e03ed423d0 100644
--- a/arch/powerpc/kernel/l2cr_6xx.S
+++ b/arch/powerpc/kernel/l2cr_6xx.S
@@ -96,7 +96,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_L2CR)
/* Stop DST streams */
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
sync
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
@@ -292,7 +292,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_L3CR)
isync
/* Stop DST streams */
- DSSALL
+ PPC_DSSALL
sync
/* Get the current enable bit of the L3CR into r4 */
@@ -401,7 +401,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
_GLOBAL(__flush_disable_L1)
/* Stop pending alitvec streams and memory accesses */
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
sync
diff --git a/arch/powerpc/kernel/swsusp_32.S b/arch/powerpc/kernel/swsusp_32.S
index f73f4d72fea4..e0cbd63007f2 100644
--- a/arch/powerpc/kernel/swsusp_32.S
+++ b/arch/powerpc/kernel/swsusp_32.S
@@ -181,7 +181,7 @@ _GLOBAL(swsusp_arch_resume)
#ifdef CONFIG_ALTIVEC
/* Stop pending alitvec streams and memory accesses */
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
#endif
sync
diff --git a/arch/powerpc/kernel/swsusp_asm64.S b/arch/powerpc/kernel/swsusp_asm64.S
index 96bb20715aa9..9f1903c7f540 100644
--- a/arch/powerpc/kernel/swsusp_asm64.S
+++ b/arch/powerpc/kernel/swsusp_asm64.S
@@ -141,7 +141,7 @@ END_FW_FTR_SECTION_IFCLR(FW_FEATURE_LPAR)
_GLOBAL(swsusp_arch_resume)
/* Stop pending alitvec streams and memory accesses */
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
sync
diff --git a/arch/powerpc/platforms/powermac/cache.S b/arch/powerpc/platforms/powermac/cache.S
index ced225415486..b8ae56e9f414 100644
--- a/arch/powerpc/platforms/powermac/cache.S
+++ b/arch/powerpc/platforms/powermac/cache.S
@@ -48,7 +48,7 @@ flush_disable_75x:
/* Stop DST streams */
BEGIN_FTR_SECTION
- DSSALL
+ PPC_DSSALL
sync
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
@@ -197,7 +197,7 @@ flush_disable_745x:
isync
/* Stop prefetch streams */
- DSSALL
+ PPC_DSSALL
sync
/* Disable L2 prefetching */
--
2.30.2
^ permalink raw reply related
* [PATCH llvm 4/6] powerpc/64/asm: Do not reassign labels
From: Alexey Kardashevskiy @ 2021-12-21 5:59 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
From: Daniel Axtens <dja@axtens.net>
The LLVM integrated assembler really does not like us reassigning things
to the same label:
<instantiation>:7:9: error: invalid reassignment of non-absolute variable 'fs_label'
This happens across a bunch of platforms:
https://github.com/ClangBuiltLinux/linux/issues/1043
https://github.com/ClangBuiltLinux/linux/issues/1008
https://github.com/ClangBuiltLinux/linux/issues/920
https://github.com/ClangBuiltLinux/linux/issues/1050
There is no hope of getting this fixed in LLVM (see
https://github.com/ClangBuiltLinux/linux/issues/1043#issuecomment-641571200
and https://bugs.llvm.org/show_bug.cgi?id=47798#c1 )
so if we want to build with LLVM_IAS, we need to hack
around it ourselves.
For us the big problem comes from this:
\#define USE_FIXED_SECTION(sname) \
fs_label = start_##sname; \
fs_start = sname##_start; \
use_ftsec sname;
\#define USE_TEXT_SECTION()
fs_label = start_text; \
fs_start = text_start; \
.text
and in particular fs_label.
This works around it by not setting those 'variables' and requiring
that users of the variables instead track for themselves what section
they are in. This isn't amazing, by any stretch, but it gets us further
in the compilation.
Note that even though users have to keep track of the section, using
a wrong one produces an error with both binutils and llvm which prevents
from using wrong section at the compile time:
llvm error example:
AS arch/powerpc/kernel/head_64.o
<unknown>:0: error: Cannot represent a difference across sections
make[3]: *** [/home/aik/p/kernels-llvm/llvm/scripts/Makefile.build:388: arch/powerpc/kernel/head_64.o] Error 1
binutils error example:
/home/aik/p/kernels-llvm/llvm/arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
/home/aik/p/kernels-llvm/llvm/arch/powerpc/kernel/exceptions-64s.S:1974: Error: can't resolve `system_call_common' {.text section} - `start_r
eal_vectors' {.head.text.real_vectors section}
make[3]: *** [/home/aik/p/kernels-llvm/llvm/scripts/Makefile.build:388: arch/powerpc/kernel/head_64.o] Error 1
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/include/asm/head-64.h | 12 +++++------
arch/powerpc/kernel/exceptions-64s.S | 32 ++++++++++++++--------------
arch/powerpc/kernel/head_64.S | 18 ++++++++--------
arch/powerpc/kernel/interrupt_64.S | 2 +-
4 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/arch/powerpc/include/asm/head-64.h b/arch/powerpc/include/asm/head-64.h
index 242204e12993..d73153b0275d 100644
--- a/arch/powerpc/include/asm/head-64.h
+++ b/arch/powerpc/include/asm/head-64.h
@@ -98,13 +98,9 @@ linker_stub_catch: \
. = sname##_len;
#define USE_FIXED_SECTION(sname) \
- fs_label = start_##sname; \
- fs_start = sname##_start; \
use_ftsec sname;
#define USE_TEXT_SECTION() \
- fs_label = start_text; \
- fs_start = text_start; \
.text
#define CLOSE_FIXED_SECTION(sname) \
@@ -161,13 +157,15 @@ end_##sname:
* - ABS_ADDR is used to find the absolute address of any symbol, from within
* a fixed section.
*/
-#define DEFINE_FIXED_SYMBOL(label) \
- label##_absolute = (label - fs_label + fs_start)
+// define label as being _in_ sname
+#define DEFINE_FIXED_SYMBOL(label, sname) \
+ label##_absolute = (label - start_ ## sname + sname ## _start)
#define FIXED_SYMBOL_ABS_ADDR(label) \
(label##_absolute)
-#define ABS_ADDR(label) (label - fs_label + fs_start)
+// find label from _within_ sname
+#define ABS_ADDR(label, sname) (label - start_ ## sname + sname ## _start)
#endif /* __ASSEMBLY__ */
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 83d37678f7cf..44b70bf535e3 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -48,7 +48,7 @@
.balign IFETCH_ALIGN_BYTES; \
.global name; \
_ASM_NOKPROBE_SYMBOL(name); \
- DEFINE_FIXED_SYMBOL(name); \
+ DEFINE_FIXED_SYMBOL(name, text); \
name:
#define TRAMP_REAL_BEGIN(name) \
@@ -76,18 +76,18 @@ name:
ld reg,PACAKBASE(r13); /* get high part of &label */ \
ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label)
-#define __LOAD_HANDLER(reg, label) \
+#define __LOAD_HANDLER(reg, label, section) \
ld reg,PACAKBASE(r13); \
- ori reg,reg,(ABS_ADDR(label))@l
+ ori reg,reg,(ABS_ADDR(label, section))@l
/*
* Branches from unrelocated code (e.g., interrupts) to labels outside
* head-y require >64K offsets.
*/
-#define __LOAD_FAR_HANDLER(reg, label) \
+#define __LOAD_FAR_HANDLER(reg, label, section) \
ld reg,PACAKBASE(r13); \
- ori reg,reg,(ABS_ADDR(label))@l; \
- addis reg,reg,(ABS_ADDR(label))@h
+ ori reg,reg,(ABS_ADDR(label, section))@l; \
+ addis reg,reg,(ABS_ADDR(label, section))@h
/*
* Interrupt code generation macros
@@ -363,7 +363,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
* This switches to virtual mode and sets MSR[RI].
*/
.macro __GEN_COMMON_ENTRY name
-DEFINE_FIXED_SYMBOL(\name\()_common_real)
+DEFINE_FIXED_SYMBOL(\name\()_common_real, text)
\name\()_common_real:
.if IKVM_REAL
KVMTEST \name kvm_interrupt
@@ -386,7 +386,7 @@ DEFINE_FIXED_SYMBOL(\name\()_common_real)
.endif
.balign IFETCH_ALIGN_BYTES
-DEFINE_FIXED_SYMBOL(\name\()_common_virt)
+DEFINE_FIXED_SYMBOL(\name\()_common_virt, text)
\name\()_common_virt:
.if IKVM_VIRT
KVMTEST \name kvm_interrupt
@@ -400,7 +400,7 @@ DEFINE_FIXED_SYMBOL(\name\()_common_virt)
* want to run in real mode.
*/
.macro __GEN_REALMODE_COMMON_ENTRY name
-DEFINE_FIXED_SYMBOL(\name\()_common_real)
+DEFINE_FIXED_SYMBOL(\name\()_common_real, text)
\name\()_common_real:
.if IKVM_REAL
KVMTEST \name kvm_interrupt
@@ -835,12 +835,12 @@ SOFT_MASK_TABLE(0xc000000000003000, 0xc000000000004000)
#ifdef CONFIG_RELOCATABLE
TRAMP_VIRT_BEGIN(system_call_vectored_tramp)
- __LOAD_HANDLER(r10, system_call_vectored_common)
+ __LOAD_HANDLER(r10, system_call_vectored_common, virt_trampolines)
mtctr r10
bctr
TRAMP_VIRT_BEGIN(system_call_vectored_sigill_tramp)
- __LOAD_HANDLER(r10, system_call_vectored_sigill)
+ __LOAD_HANDLER(r10, system_call_vectored_sigill, virt_trampolines)
mtctr r10
bctr
#endif
@@ -949,7 +949,7 @@ TRAMP_REAL_BEGIN(system_reset_idle_wake)
/* We are waking up from idle, so may clobber any volatile register */
cmpwi cr1,r5,2
bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */
- __LOAD_FAR_HANDLER(r12, DOTSYM(idle_return_gpr_loss))
+ __LOAD_FAR_HANDLER(r12, DOTSYM(idle_return_gpr_loss), real_trampolines)
mtctr r12
bctr
#endif
@@ -1945,12 +1945,12 @@ END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
HMT_MEDIUM
.if ! \virt
- __LOAD_HANDLER(r10, system_call_common_real)
+ __LOAD_HANDLER(r10, system_call_common_real, real_vectors)
mtctr r10
bctr
.else
#ifdef CONFIG_RELOCATABLE
- __LOAD_HANDLER(r10, system_call_common)
+ __LOAD_HANDLER(r10, system_call_common, virt_vectors)
mtctr r10
bctr
#else
@@ -2004,7 +2004,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
* Requires __LOAD_FAR_HANDLER beause kvmppc_hcall lives
* outside the head section.
*/
- __LOAD_FAR_HANDLER(r10, kvmppc_hcall)
+ __LOAD_FAR_HANDLER(r10, kvmppc_hcall, real_trampolines)
mtctr r10
bctr
#else
@@ -3028,7 +3028,7 @@ USE_FIXED_SECTION(virt_trampolines)
.align 7
.globl __end_interrupts
__end_interrupts:
-DEFINE_FIXED_SYMBOL(__end_interrupts)
+DEFINE_FIXED_SYMBOL(__end_interrupts, virt_trampolines)
CLOSE_FIXED_SECTION(real_vectors);
CLOSE_FIXED_SECTION(real_trampolines);
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index a08c050ff645..5c5181e8d5f1 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -126,7 +126,7 @@ __secondary_hold_acknowledge:
. = 0x5c
.globl __run_at_load
__run_at_load:
-DEFINE_FIXED_SYMBOL(__run_at_load)
+DEFINE_FIXED_SYMBOL(__run_at_load, first_256B)
.long RUN_AT_LOAD_DEFAULT
#endif
@@ -156,7 +156,7 @@ __secondary_hold:
/* Tell the master cpu we're here */
/* Relocation is off & we are located at an address less */
/* than 0x100, so only need to grab low order offset. */
- std r24,(ABS_ADDR(__secondary_hold_acknowledge))(0)
+ std r24,(ABS_ADDR(__secondary_hold_acknowledge, first_256B))(0)
sync
li r26,0
@@ -164,7 +164,7 @@ __secondary_hold:
tovirt(r26,r26)
#endif
/* All secondary cpus wait here until told to start. */
-100: ld r12,(ABS_ADDR(__secondary_hold_spinloop))(r26)
+100: ld r12,(ABS_ADDR(__secondary_hold_spinloop, first_256B))(r26)
cmpdi 0,r12,0
beq 100b
@@ -649,15 +649,15 @@ __after_prom_start:
3:
#endif
/* # bytes of memory to copy */
- lis r5,(ABS_ADDR(copy_to_here))@ha
- addi r5,r5,(ABS_ADDR(copy_to_here))@l
+ lis r5,(ABS_ADDR(copy_to_here, text))@ha
+ addi r5,r5,(ABS_ADDR(copy_to_here, text))@l
bl copy_and_flush /* copy the first n bytes */
/* this includes the code being */
/* executed here. */
/* Jump to the copy of this code that we just made */
- addis r8,r3,(ABS_ADDR(4f))@ha
- addi r12,r8,(ABS_ADDR(4f))@l
+ addis r8,r3,(ABS_ADDR(4f, text))@ha
+ addi r12,r8,(ABS_ADDR(4f, text))@l
mtctr r12
bctr
@@ -669,8 +669,8 @@ p_end: .8byte _end - copy_to_here
* Now copy the rest of the kernel up to _end, add
* _end - copy_to_here to the copy limit and run again.
*/
- addis r8,r26,(ABS_ADDR(p_end))@ha
- ld r8,(ABS_ADDR(p_end))@l(r8)
+ addis r8,r26,(ABS_ADDR(p_end, text))@ha
+ ld r8,(ABS_ADDR(p_end, text))@l(r8)
add r5,r5,r8
5: bl copy_and_flush /* copy the rest */
diff --git a/arch/powerpc/kernel/interrupt_64.S b/arch/powerpc/kernel/interrupt_64.S
index 2ad223597ca2..d3180139e35a 100644
--- a/arch/powerpc/kernel/interrupt_64.S
+++ b/arch/powerpc/kernel/interrupt_64.S
@@ -695,7 +695,7 @@ interrupt_return_macro hsrr
.globl __end_soft_masked
__end_soft_masked:
-DEFINE_FIXED_SYMBOL(__end_soft_masked)
+DEFINE_FIXED_SYMBOL(__end_soft_masked, text)
#endif /* CONFIG_PPC_BOOK3S */
#ifdef CONFIG_PPC_BOOK3S
--
2.30.2
^ permalink raw reply related
* [PATCH llvm 3/6] powerpc/64/asm: Inline BRANCH_TO_C000
From: Alexey Kardashevskiy @ 2021-12-21 5:59 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
It is used just once and does not really help with readability, remove it.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/kernel/exceptions-64s.S | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index a30f563bc7a8..83d37678f7cf 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -89,19 +89,6 @@ name:
ori reg,reg,(ABS_ADDR(label))@l; \
addis reg,reg,(ABS_ADDR(label))@h
-/*
- * Branch to label using its 0xC000 address. This results in instruction
- * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned
- * on using mtmsr rather than rfid.
- *
- * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than
- * load KBASE for a slight optimisation.
- */
-#define BRANCH_TO_C000(reg, label) \
- __LOAD_FAR_HANDLER(reg, label); \
- mtctr reg; \
- bctr
-
/*
* Interrupt code generation macros
*/
@@ -962,7 +949,9 @@ TRAMP_REAL_BEGIN(system_reset_idle_wake)
/* We are waking up from idle, so may clobber any volatile register */
cmpwi cr1,r5,2
bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */
- BRANCH_TO_C000(r12, DOTSYM(idle_return_gpr_loss))
+ __LOAD_FAR_HANDLER(r12, DOTSYM(idle_return_gpr_loss))
+ mtctr r12
+ bctr
#endif
#ifdef CONFIG_PPC_PSERIES
--
2.30.2
^ permalink raw reply related
* [PATCH llvm 2/6] powerpc: check for support for -Wa,-m{power4,any}
From: Alexey Kardashevskiy @ 2021-12-21 5:59 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
From: Daniel Axtens <dja@axtens.net>
LLVM's integrated assembler does not like either -Wa,-mpower4
or -Wa,-many. So just don't pass them if they're not supported.
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/Makefile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index e9aa4e8b07dd..5f16ac1583c5 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -245,7 +245,9 @@ cpu-as-$(CONFIG_E500) += -Wa,-me500
# When using '-many -mpower4' gas will first try and find a matching power4
# mnemonic and failing that it will allow any valid mnemonic that GAS knows
# about. GCC will pass -many to GAS when assembling, clang does not.
-cpu-as-$(CONFIG_PPC_BOOK3S_64) += -Wa,-mpower4 -Wa,-many
+# LLVM IAS doesn't understand either flag: https://github.com/ClangBuiltLinux/linux/issues/675
+# but LLVM IAS only supports ISA >= 2.06 for Book3S 64 anyway...
+cpu-as-$(CONFIG_PPC_BOOK3S_64) += $(call as-option,-Wa$(comma)-mpower4) $(call as-option,-Wa$(comma)-many)
cpu-as-$(CONFIG_PPC_E500MC) += $(call as-option,-Wa$(comma)-me500mc)
KBUILD_AFLAGS += $(cpu-as-y)
--
2.30.2
^ permalink raw reply related
* [PATCH llvm 1/6] powerpc/toc: PowerPC64 future proof kernel toc, revised for lld
From: Alexey Kardashevskiy @ 2021-12-21 5:58 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
In-Reply-To: <20211221055904.555763-1-aik@ozlabs.ru>
From: Alan Modra <amodra@au1.ibm.com>
This patch future-proofs the kernel against linker changes that might
put the toc pointer at some location other than .got+0x8000, by
replacing __toc_start+0x8000 with .TOC. throughout. If the kernel's
idea of the toc pointer doesn't agree with the linker, bad things
happen.
prom_init.c code relocating its toc is also changed so that a symbolic
__prom_init_toc_start toc-pointer relative address is calculated
rather than assuming that it is always at toc-pointer - 0x8000. The
length calculations loading values from the toc are also avoided.
It's a little incestuous to do that with unreloc_toc picking up
adjusted values (which is fine in practice, they both adjust by the
same amount if all goes well).
I've also changed the way .got is aligned in vmlinux.lds and
zImage.lds, mostly so that dumping out section info by objdump or
readelf plainly shows the alignment is 256. This linker script
feature was added 2005-09-27, available in FSF binutils releases from
2.17 onwards. Should be safe to use in the kernel, I think.
Finally, put *(.got) before the prom_init.o entry which only needs
*(.toc), so that the GOT header goes in the correct place. I don't
believe this makes any difference for the kernel as it would for
dynamic objects being loaded by ld.so. That change is just to stop
lusers who blindly copy kernel scripts being led astray. Of course,
this change needs the prom_init.c changes.
Some notes on .toc and .got.
.toc is a compiler generated section of addresses. .got is a linker
generated section of addresses, generally built when the linker sees
R_*_*GOT* relocations. In the case of powerpc64 ld.bfd, there are
multiple generated .got sections, one per input object file. So you
can somewhat reasonably write in a linker script an input section
statement like *prom_init.o(.got .toc) to mean "the .got and .toc
section for files matching *prom_init.o". On other architectures that
doesn't make sense, because the linker generally has just one .got
section. Even on powerpc64, note well that the GOT entries for
prom_init.o may be merged with GOT entries from other objects. That
means that if prom_init.o references, say, _end via some GOT
relocation, and some other object also references _end via a GOT
relocation, the GOT entry for _end may be in the range
__prom_init_toc_start to __prom_init_toc_end and if the kernel does
something special to GOT/TOC entries in that range then the value of
_end as seen by objects other than prom_init.o will be affected. On
the other hand the GOT entry for _end may not be in the range
__prom_init_toc_start to __prom_init_toc_end. Which way it turns out
is deterministic but a detail of linker operation that should not be
relied on.
A feature of ld.bfd is that input .toc (and .got) sections matching
one linker input section statement may be sorted, to put entries used
by small-model code first, near the toc base. This is why scripts for
powerpc64 normally use *(.got .toc) rather than *(.got) *(.toc), since
the first form allows more freedom to sort.
Another feature of ld.bfd is that indirect addressing sequences using
the GOT/TOC may be edited by the linker to relative addressing. In
many cases relative addressing would be emitted by gcc for
-mcmodel=medium if you appropriately decorate variable declarations
with non-default visibility.
The original patch is here:
https://lore.kernel.org/linuxppc-dev/20210310034813.GM6042@bubble.grove.modra.org/
Signed-off-by: Alan Modra <amodra@au1.ibm.com>
[aik: removed non-relocatable which is gone in 24d33ac5b8ffb]
[aik: added <=2.24 check]
[aik: because of llvm-as, kernel_toc_addr() uses "mr" instead of global register variable]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/Makefile | 5 +++--
arch/powerpc/include/asm/sections.h | 14 +++++++-------
arch/powerpc/boot/crt0.S | 2 +-
arch/powerpc/boot/zImage.lds.S | 7 ++-----
arch/powerpc/kernel/head_64.S | 2 +-
arch/powerpc/kernel/vmlinux.lds.S | 8 +++-----
6 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index e02568f17334..e9aa4e8b07dd 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -445,10 +445,11 @@ PHONY += checkbin
# Check toolchain versions:
# - gcc-4.6 is the minimum kernel-wide version so nothing required.
checkbin:
- @if test "x${CONFIG_CPU_LITTLE_ENDIAN}" = "xy" \
- && $(LD) --version | head -1 | grep ' 2\.24$$' >/dev/null ; then \
+ @if test "x${CONFIG_LD_IS_LLD}" != "xy" -a \
+ "x$(call ld-ifversion, -le, 22400, y)" = "xy" ; then \
echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
echo 'in some circumstances.' ; \
+ echo '*** binutils 2.23 do not define the TOC symbol ' ; \
echo -n '*** Please use a different binutils version.' ; \
false ; \
fi
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 79cb7a25a5fb..38f79e42bf3c 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -25,16 +25,16 @@ extern char start_virt_trampolines[];
extern char end_virt_trampolines[];
#endif
+/*
+ * This assumes the kernel is never compiled -mcmodel=small or
+ * the total .toc is always less than 64k.
+ */
static inline unsigned long kernel_toc_addr(void)
{
- /* Defined by the linker, see vmlinux.lds.S */
- extern unsigned long __toc_start;
+ unsigned long toc_ptr;
- /*
- * The TOC register (r2) points 32kB into the TOC, so that 64kB of
- * the TOC can be addressed using a single machine instruction.
- */
- return (unsigned long)(&__toc_start) + 0x8000UL;
+ asm volatile("mr %0, 2" : "=r" (toc_ptr));
+ return toc_ptr;
}
static inline int overlaps_interrupt_vector_text(unsigned long start,
diff --git a/arch/powerpc/boot/crt0.S b/arch/powerpc/boot/crt0.S
index e8f10a599659..feadee18e271 100644
--- a/arch/powerpc/boot/crt0.S
+++ b/arch/powerpc/boot/crt0.S
@@ -28,7 +28,7 @@ p_etext: .8byte _etext
p_bss_start: .8byte __bss_start
p_end: .8byte _end
-p_toc: .8byte __toc_start + 0x8000 - p_base
+p_toc: .8byte .TOC. - p_base
p_dyn: .8byte __dynamic_start - p_base
p_rela: .8byte __rela_dyn_start - p_base
p_prom: .8byte 0
diff --git a/arch/powerpc/boot/zImage.lds.S b/arch/powerpc/boot/zImage.lds.S
index d6f072865627..d65cd55a6f38 100644
--- a/arch/powerpc/boot/zImage.lds.S
+++ b/arch/powerpc/boot/zImage.lds.S
@@ -36,12 +36,9 @@ SECTIONS
}
#ifdef CONFIG_PPC64_BOOT_WRAPPER
- . = ALIGN(256);
- .got :
+ .got : ALIGN(256)
{
- __toc_start = .;
- *(.got)
- *(.toc)
+ *(.got .toc)
}
#endif
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index f17ae2083733..a08c050ff645 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -904,7 +904,7 @@ _GLOBAL(relative_toc)
blr
.balign 8
-p_toc: .8byte __toc_start + 0x8000 - 0b
+p_toc: .8byte .TOC. - 0b
/*
* This is where the main kernel code starts.
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index dfc3f39d365f..2bcca818136a 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -337,15 +337,13 @@ SECTIONS
*(.branch_lt)
}
- . = ALIGN(256);
- .got : AT(ADDR(.got) - LOAD_OFFSET) {
- __toc_start = .;
+ .got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
+ *(.got)
#ifndef CONFIG_RELOCATABLE
__prom_init_toc_start = .;
- arch/powerpc/kernel/prom_init.o*(.toc .got)
+ arch/powerpc/kernel/prom_init.o*(.toc)
__prom_init_toc_end = .;
#endif
- *(.got)
*(.toc)
}
#endif
--
2.30.2
^ permalink raw reply related
* [PATCH kernel 0/6] powerpc: Build with LLVM_IAS=1
From: Alexey Kardashevskiy @ 2021-12-21 5:58 UTC (permalink / raw)
To: linuxppc-dev
Cc: Alexey Kardashevskiy, llvm, Nick Desaulniers, Alan Modra,
Nicholas Piggin, Daniel Axtens
This allows compiling the upstream Linux with the upstream llvm with one fix on top;
https://reviews.llvm.org/D115419
This is based on sha1
798527287598 Michael Ellerman "Automatic merge of 'next' into merge (2021-12-14 00:12)".
Please comment. Thanks.
Alan Modra (1):
powerpc/toc: PowerPC64 future proof kernel toc, revised for lld
Alexey Kardashevskiy (3):
powerpc/64/asm: Inline BRANCH_TO_C000
powerpc/mm: Switch obsolete dssall to .long
powerpc/mm/book3s64/hash: Switch pre 2.06 tlbiel to .long
Daniel Axtens (2):
powerpc: check for support for -Wa,-m{power4,any}
powerpc/64/asm: Do not reassign labels
arch/powerpc/Makefile | 9 +++--
arch/powerpc/include/asm/head-64.h | 12 +++----
arch/powerpc/include/asm/ppc-opcode.h | 4 +++
arch/powerpc/include/asm/sections.h | 14 ++++----
arch/powerpc/kernel/idle.c | 2 +-
arch/powerpc/mm/book3s64/hash_native.c | 4 +--
arch/powerpc/mm/mmu_context.c | 2 +-
arch/powerpc/boot/crt0.S | 2 +-
arch/powerpc/boot/zImage.lds.S | 7 ++--
arch/powerpc/kernel/exceptions-64s.S | 47 ++++++++++---------------
arch/powerpc/kernel/head_64.S | 20 +++++------
arch/powerpc/kernel/idle_6xx.S | 2 +-
arch/powerpc/kernel/interrupt_64.S | 2 +-
arch/powerpc/kernel/l2cr_6xx.S | 6 ++--
arch/powerpc/kernel/swsusp_32.S | 2 +-
arch/powerpc/kernel/swsusp_asm64.S | 2 +-
arch/powerpc/kernel/vmlinux.lds.S | 8 ++---
arch/powerpc/platforms/powermac/cache.S | 4 +--
18 files changed, 69 insertions(+), 80 deletions(-)
--
2.30.2
^ permalink raw reply
* Re: [PATCH kernel v4] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
From: Alexey Kardashevskiy @ 2021-12-21 5:38 UTC (permalink / raw)
To: Cédric Le Goater
Cc: kvm, Fabiano Rosas, Nicholas Piggin, kvm-ppc, David Stevens,
linuxppc-dev
In-Reply-To: <6111f49a-6ab9-2aba-92b1-ae02db3859b2@kaod.org>
On 12/20/21 18:29, Cédric Le Goater wrote:
> On 12/20/21 02:23, Alexey Kardashevskiy wrote:
>> At the moment KVM on PPC creates 4 types of entries under the kvm debugfs:
>> 1) "%pid-%fd" per a KVM instance (for all platforms);
>> 2) "vm%pid" (for PPC Book3s HV KVM);
>> 3) "vm%u_vcpu%u_timing" (for PPC Book3e KVM);
>> 4) "kvm-xive-%p" (for XIVE PPC Book3s KVM, the same for XICS);
>>
>> The problem with this is that multiple VMs per process is not allowed for
>> 2) and 3) which makes it possible for userspace to trigger errors when
>> creating duplicated debugfs entries.
>>
>> This merges all these into 1).
>>
>> This defines kvm_arch_create_kvm_debugfs() similar to
>> kvm_arch_create_vcpu_debugfs().
>>
>> This defines 2 hooks in kvmppc_ops that allow specific KVM implementations
>> add necessary entries, this adds the _e500 suffix to
>> kvmppc_create_vcpu_debugfs_e500() to make it clear what platform it is for.
>>
>> This makes use of already existing kvm_arch_create_vcpu_debugfs() on PPC.
>>
>> This removes no more used debugfs_dir pointers from PPC kvm_arch structs.
>>
>> This stops removing vcpu entries as once created vcpus stay around
>> for the entire life of a VM and removed when the KVM instance is closed,
>> see commit d56f5136b010 ("KVM: let kvm_destroy_vm_debugfs clean up vCPU
>> debugfs directories").
>>
>> Suggested-by: Fabiano Rosas <farosas@linux.ibm.com>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
>
> One comment below.
>
>> ---
>> Changes:
>> v4:
>> * added "kvm-xive-%p"
>>
>> v3:
>> * reworked commit log, especially, the bit about removing vcpus
>>
>> v2:
>> * handled powerpc-booke
>> * s/kvm/vm/ in arch hooks
>> ---
>> arch/powerpc/include/asm/kvm_host.h | 6 ++---
>> arch/powerpc/include/asm/kvm_ppc.h | 2 ++
>> arch/powerpc/kvm/timing.h | 9 ++++----
>> arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +-
>> arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +-
>> arch/powerpc/kvm/book3s_hv.c | 31 ++++++++++----------------
>> arch/powerpc/kvm/book3s_xics.c | 13 ++---------
>> arch/powerpc/kvm/book3s_xive.c | 13 ++---------
>> arch/powerpc/kvm/book3s_xive_native.c | 13 ++---------
>> arch/powerpc/kvm/e500.c | 1 +
>> arch/powerpc/kvm/e500mc.c | 1 +
>> arch/powerpc/kvm/powerpc.c | 16 ++++++++++---
>> arch/powerpc/kvm/timing.c | 20 ++++-------------
>> 13 files changed, 47 insertions(+), 82 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
>> index 17263276189e..f5e14fa683f4 100644
>> --- a/arch/powerpc/include/asm/kvm_host.h
>> +++ b/arch/powerpc/include/asm/kvm_host.h
>> @@ -26,6 +26,8 @@
>> #include <asm/hvcall.h>
>> #include <asm/mce.h>
>>
>> +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS
>> +
>> #define KVM_MAX_VCPUS NR_CPUS
>> #define KVM_MAX_VCORES NR_CPUS
>>
>> @@ -295,7 +297,6 @@ struct kvm_arch {
>> bool dawr1_enabled;
>> pgd_t *pgtable;
>> u64 process_table;
>> - struct dentry *debugfs_dir;
>> struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */
>> #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
>> #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
>> @@ -673,7 +674,6 @@ struct kvm_vcpu_arch {
>> u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
>> u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
>> u64 timing_last_exit;
>> - struct dentry *debugfs_exit_timing;
>> #endif
>>
>> #ifdef CONFIG_PPC_BOOK3S
>> @@ -829,8 +829,6 @@ struct kvm_vcpu_arch {
>> struct kvmhv_tb_accumulator rm_exit; /* real-mode exit code */
>> struct kvmhv_tb_accumulator guest_time; /* guest execution */
>> struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */
>> -
>> - struct dentry *debugfs_dir;
>> #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
>> };
>>
>> diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
>> index 33db83b82fbd..d2b192dea0d2 100644
>> --- a/arch/powerpc/include/asm/kvm_ppc.h
>> +++ b/arch/powerpc/include/asm/kvm_ppc.h
>> @@ -316,6 +316,8 @@ struct kvmppc_ops {
>> int (*svm_off)(struct kvm *kvm);
>> int (*enable_dawr1)(struct kvm *kvm);
>> bool (*hash_v3_possible)(void);
>> + int (*create_vm_debugfs)(struct kvm *kvm);
>> + int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry);
>> };
>>
>> extern struct kvmppc_ops *kvmppc_hv_ops;
>> diff --git a/arch/powerpc/kvm/timing.h b/arch/powerpc/kvm/timing.h
>> index feef7885ba82..493a7d510fd5 100644
>> --- a/arch/powerpc/kvm/timing.h
>> +++ b/arch/powerpc/kvm/timing.h
>> @@ -14,8 +14,8 @@
>> #ifdef CONFIG_KVM_EXIT_TIMING
>> void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu);
>> void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu);
>> -void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, unsigned int id);
>> -void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu);
>> +void kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu,
>> + struct dentry *debugfs_dentry);
>>
>> static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type)
>> {
>> @@ -26,9 +26,8 @@ static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type)
>> /* if exit timing is not configured there is no need to build the c file */
>> static inline void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu) {}
>> static inline void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu) {}
>> -static inline void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu,
>> - unsigned int id) {}
>> -static inline void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu) {}
>> +static inline void kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu,
>> + struct dentry *debugfs_dentry) {}
>> static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type) {}
>> #endif /* CONFIG_KVM_EXIT_TIMING */
>>
>> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
>> index c63e263312a4..33dae253a0ac 100644
>> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
>> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
>> @@ -2112,7 +2112,7 @@ static const struct file_operations debugfs_htab_fops = {
>>
>> void kvmppc_mmu_debugfs_init(struct kvm *kvm)
>> {
>> - debugfs_create_file("htab", 0400, kvm->arch.debugfs_dir, kvm,
>> + debugfs_create_file("htab", 0400, kvm->debugfs_dentry, kvm,
>> &debugfs_htab_fops);
>> }
>>
>> diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
>> index 8cebe5542256..e4ce2a35483f 100644
>> --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
>> +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
>> @@ -1454,7 +1454,7 @@ static const struct file_operations debugfs_radix_fops = {
>>
>> void kvmhv_radix_debugfs_init(struct kvm *kvm)
>> {
>> - debugfs_create_file("radix", 0400, kvm->arch.debugfs_dir, kvm,
>> + debugfs_create_file("radix", 0400, kvm->debugfs_dentry, kvm,
>> &debugfs_radix_fops);
>> }
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index bf1eb1160ae2..4c52541b6f37 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -2768,20 +2768,17 @@ static const struct file_operations debugfs_timings_ops = {
>> };
>>
>> /* Create a debugfs directory for the vcpu */
>> -static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)
>> +static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
>> {
>> - char buf[16];
>> - struct kvm *kvm = vcpu->kvm;
>> -
>> - snprintf(buf, sizeof(buf), "vcpu%u", id);
>> - vcpu->arch.debugfs_dir = debugfs_create_dir(buf, kvm->arch.debugfs_dir);
>> - debugfs_create_file("timings", 0444, vcpu->arch.debugfs_dir, vcpu,
>> + debugfs_create_file("timings", 0444, debugfs_dentry, vcpu,
>> &debugfs_timings_ops);
>> + return 0;
>> }
>>
>> #else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
>> -static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)
>> +static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
>> {
>> + return 0;
>> }
>> #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
>>
>> @@ -2904,8 +2901,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
>> vcpu->arch.cpu_type = KVM_CPU_3S_64;
>> kvmppc_sanity_check(vcpu);
>>
>> - debugfs_vcpu_init(vcpu, id);
>> -
>> return 0;
>> }
>>
>> @@ -5226,7 +5221,6 @@ void kvmppc_free_host_rm_ops(void)
>> static int kvmppc_core_init_vm_hv(struct kvm *kvm)
>> {
>> unsigned long lpcr, lpid;
>> - char buf[32];
>> int ret;
>>
>> mutex_init(&kvm->arch.uvmem_lock);
>> @@ -5359,15 +5353,14 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
>> kvm->arch.smt_mode = 1;
>> kvm->arch.emul_smt_mode = 1;
>>
>> - /*
>> - * Create a debugfs directory for the VM
>> - */
>> - snprintf(buf, sizeof(buf), "vm%d", current->pid);
>> - kvm->arch.debugfs_dir = debugfs_create_dir(buf, kvm_debugfs_dir);
>> + return 0;
>> +}
>> +
>> +static int kvmppc_arch_create_vm_debugfs_hv(struct kvm *kvm)
>> +{
>> kvmppc_mmu_debugfs_init(kvm);
>> if (radix_enabled())
>> kvmhv_radix_debugfs_init(kvm);
>> -
>> return 0;
>> }
>>
>> @@ -5382,8 +5375,6 @@ static void kvmppc_free_vcores(struct kvm *kvm)
>>
>> static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)
>> {
>> - debugfs_remove_recursive(kvm->arch.debugfs_dir);
>> -
>> if (!cpu_has_feature(CPU_FTR_ARCH_300))
>> kvm_hv_vm_deactivated();
>>
>> @@ -6044,6 +6035,8 @@ static struct kvmppc_ops kvm_ops_hv = {
>> .svm_off = kvmhv_svm_off,
>> .enable_dawr1 = kvmhv_enable_dawr1,
>> .hash_v3_possible = kvmppc_hash_v3_possible,
>> + .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv,
>> + .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv,
>> };
>>
>> static int kvm_init_subcore_bitmap(void)
>> diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
>> index ebd5d920de8c..3dfa9285e4a4 100644
>> --- a/arch/powerpc/kvm/book3s_xics.c
>> +++ b/arch/powerpc/kvm/book3s_xics.c
>> @@ -1016,19 +1016,10 @@ DEFINE_SHOW_ATTRIBUTE(xics_debug);
>>
>> static void xics_debugfs_init(struct kvmppc_xics *xics)
>> {
>> - char *name;
>> -
>> - name = kasprintf(GFP_KERNEL, "kvm-xics-%p", xics);
>> - if (!name) {
>> - pr_err("%s: no memory for name\n", __func__);
>> - return;
>> - }
>> -
>> - xics->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
>> + xics->dentry = debugfs_create_file("xics", 0444, xics->kvm->debugfs_dentry,
>> xics, &xics_debug_fops);
>>
>> - pr_debug("%s: created %s\n", __func__, name);
>> - kfree(name);
>> + pr_debug("%s: created\n", __func__);
>> }
>>
>> static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
>> diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
>> index 225008882958..bb41afbb68fc 100644
>> --- a/arch/powerpc/kvm/book3s_xive.c
>> +++ b/arch/powerpc/kvm/book3s_xive.c
>> @@ -2351,19 +2351,10 @@ DEFINE_SHOW_ATTRIBUTE(xive_debug);
>>
>> static void xive_debugfs_init(struct kvmppc_xive *xive)
>> {
>> - char *name;
>> -
>> - name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
>> - if (!name) {
>> - pr_err("%s: no memory for name\n", __func__);
>> - return;
>> - }
>> -
>> - xive->dentry = debugfs_create_file(name, S_IRUGO, arch_debugfs_dir,
>> + xive->dentry = debugfs_create_file("xive", S_IRUGO, xive->kvm->debugfs_dentry,
>> xive, &xive_debug_fops);
>
> The KVM XIVE device implements a "xics-on-xive" interface, the XICS hcalls
> on top of the XIVE native PowerNV (OPAL) interface, and ...
>
>> - pr_debug("%s: created %s\n", __func__, name);
>> - kfree(name);
>> + pr_debug("%s: created\n", __func__);
>> }
>>
>> static void kvmppc_xive_init(struct kvm_device *dev)
>> diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c
>> index 99db9ac49901..e86f5b6c2ae1 100644
>> --- a/arch/powerpc/kvm/book3s_xive_native.c
>> +++ b/arch/powerpc/kvm/book3s_xive_native.c
>> @@ -1259,19 +1259,10 @@ DEFINE_SHOW_ATTRIBUTE(xive_native_debug);
>>
>> static void xive_native_debugfs_init(struct kvmppc_xive *xive)
>> {
>> - char *name;
>> -
>> - name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
>> - if (!name) {
>> - pr_err("%s: no memory for name\n", __func__);
>> - return;
>> - }
>> -
>> - xive->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
>> + xive->dentry = debugfs_create_file("xive", 0444, xive->kvm->debugfs_dentry,
>> xive, &xive_native_debug_fops);
>
> ... the KVM XIVE *native* device implements a "xive" interface", the one
> using MMIOs for interrupt management.
>
> May be it's worth making the difference in the user interface ?
The content of these xive files is quite different so I kept the same
name as before, I can change if you think it is worth it, should I? You
are probably the only person who looked at it recently (or ever?) :) Thanks,
>
> Thanks,
>
> C.
>
>>
>> - pr_debug("%s: created %s\n", __func__, name);
>> - kfree(name);
>> + pr_debug("%s: created\n", __func__);
>> }
>>
>> static void kvmppc_xive_native_init(struct kvm_device *dev)
>> diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
>> index 7e8b69015d20..c8b2b4478545 100644
>> --- a/arch/powerpc/kvm/e500.c
>> +++ b/arch/powerpc/kvm/e500.c
>> @@ -495,6 +495,7 @@ static struct kvmppc_ops kvm_ops_e500 = {
>> .emulate_op = kvmppc_core_emulate_op_e500,
>> .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
>> .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
>> + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
>> };
>>
>> static int __init kvmppc_e500_init(void)
>> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
>> index 1c189b5aadcc..fa0d8dbbe484 100644
>> --- a/arch/powerpc/kvm/e500mc.c
>> +++ b/arch/powerpc/kvm/e500mc.c
>> @@ -381,6 +381,7 @@ static struct kvmppc_ops kvm_ops_e500mc = {
>> .emulate_op = kvmppc_core_emulate_op_e500,
>> .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
>> .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
>> + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
>> };
>>
>> static int __init kvmppc_e500mc_init(void)
>> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
>> index a72920f4f221..2ea73dfcebb2 100644
>> --- a/arch/powerpc/kvm/powerpc.c
>> +++ b/arch/powerpc/kvm/powerpc.c
>> @@ -763,7 +763,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
>> goto out_vcpu_uninit;
>>
>> vcpu->arch.waitp = &vcpu->wait;
>> - kvmppc_create_vcpu_debugfs(vcpu, vcpu->vcpu_id);
>> return 0;
>>
>> out_vcpu_uninit:
>> @@ -780,8 +779,6 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
>> /* Make sure we're not using the vcpu anymore */
>> hrtimer_cancel(&vcpu->arch.dec_timer);
>>
>> - kvmppc_remove_vcpu_debugfs(vcpu);
>> -
>> switch (vcpu->arch.irq_type) {
>> case KVMPPC_IRQ_MPIC:
>> kvmppc_mpic_disconnect_vcpu(vcpu->arch.mpic, vcpu);
>> @@ -2505,3 +2502,16 @@ int kvm_arch_init(void *opaque)
>> }
>>
>> EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_ppc_instr);
>> +
>> +void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
>> +{
>> + if (vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs)
>> + vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs(vcpu, debugfs_dentry);
>> +}
>> +
>> +int kvm_arch_create_vm_debugfs(struct kvm *kvm)
>> +{
>> + if (kvm->arch.kvm_ops->create_vm_debugfs)
>> + kvm->arch.kvm_ops->create_vm_debugfs(kvm);
>> + return 0;
>> +}
>> diff --git a/arch/powerpc/kvm/timing.c b/arch/powerpc/kvm/timing.c
>> index ba56a5cbba97..f6d472874c85 100644
>> --- a/arch/powerpc/kvm/timing.c
>> +++ b/arch/powerpc/kvm/timing.c
>> @@ -204,21 +204,9 @@ static const struct file_operations kvmppc_exit_timing_fops = {
>> .release = single_release,
>> };
>>
>> -void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, unsigned int id)
>> +void kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu,
>> + struct dentry *debugfs_dentry)
>> {
>> - static char dbg_fname[50];
>> - struct dentry *debugfs_file;
>> -
>> - snprintf(dbg_fname, sizeof(dbg_fname), "vm%u_vcpu%u_timing",
>> - current->pid, id);
>> - debugfs_file = debugfs_create_file(dbg_fname, 0666, kvm_debugfs_dir,
>> - vcpu, &kvmppc_exit_timing_fops);
>> -
>> - vcpu->arch.debugfs_exit_timing = debugfs_file;
>> -}
>> -
>> -void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu)
>> -{
>> - debugfs_remove(vcpu->arch.debugfs_exit_timing);
>> - vcpu->arch.debugfs_exit_timing = NULL;
>> + debugfs_create_file("timing", 0666, debugfs_dentry,
>> + vcpu, &kvmppc_exit_timing_fops);
>> }
>>
>
--
Alexey
^ permalink raw reply
* [PATCH] powerpc: No need to initialise statics to 0
From: Xiang wangx @ 2021-12-21 3:34 UTC (permalink / raw)
To: mpe; +Cc: Xiang wangx, paulus, linuxppc-dev, linux-kernel
Static variables do not need to be initialised to 0, because compiler
will initialise all uninitialised statics to 0. Thus, remove the
unneeded initializations.
Signed-off-by: Xiang wangx <wangxiang@cdjrlc.com>
---
arch/powerpc/platforms/powermac/nvram.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/platforms/powermac/nvram.c b/arch/powerpc/platforms/powermac/nvram.c
index 853ccc4480e2..4d23793c2f1f 100644
--- a/arch/powerpc/platforms/powermac/nvram.c
+++ b/arch/powerpc/platforms/powermac/nvram.c
@@ -71,7 +71,7 @@ struct core99_header {
static int nvram_naddrs;
static volatile unsigned char __iomem *nvram_data;
static int is_core_99;
-static int core99_bank = 0;
+static int core99_bank;
static int nvram_partitions[3];
// XXX Turn that into a sem
static DEFINE_RAW_SPINLOCK(nv_lock);
--
2.34.1
^ permalink raw reply related
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Tyrel Datwyler @ 2021-12-21 1:37 UTC (permalink / raw)
To: Stefan Berger, Jason Gunthorpe
Cc: Korrapati.Likhitha, pavrampu, linux-security-module, linux-kernel,
jarkko, gcwilson, linux-integrity, linuxppc-dev, peterhuewe
In-Reply-To: <f80e33d2-948d-f885-b063-245eb37de8c1@linux.ibm.com>
On 12/20/21 5:31 PM, Stefan Berger wrote:
>
> On 12/20/21 20:13, Jason Gunthorpe wrote:
>> On Mon, Dec 20, 2021 at 08:05:58PM -0500, Stefan Berger wrote:
>>
>>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>>> index ddaeceb7e109..4cb908349b31 100644
>>> +++ b/drivers/char/tpm/tpm-chip.c
>>> @@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>>> mutex_unlock(&idr_lock);
>>>
>>> /* Make the driver uncallable. */
>>> - down_write(&chip->ops_sem);
>>> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>>> - if (!tpm_chip_start(chip)) {
>>> - tpm2_shutdown(chip, TPM2_SU_CLEAR);
>>> - tpm_chip_stop(chip);
>>> - }
>>> - }
>>> - chip->ops = NULL;
>>> - up_write(&chip->ops_sem);
>>> + if (chip->ops)
>> ops cannot be read without locking
>
> This here could be an alternative:
I still think code de-duplication is a good thing. Maybe combine the two
approaches. Call tpm_class_shutdown from tpm_del_char_device and add a chip->ops
check in tpm_class_shutdown to ensure we only do the shutdown when chip->ops is
valid.
-Tyrel
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..7772b475ebc0 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -474,7 +474,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>
> /* Make the driver uncallable. */
> down_write(&chip->ops_sem);
> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
> + if (chip->ops && chip->flags & TPM_CHIP_FLAG_TPM2) {
> if (!tpm_chip_start(chip)) {
> tpm2_shutdown(chip, TPM2_SU_CLEAR);
> tpm_chip_stop(chip);
>
> Stefan
>
>
>>
>> Jason
^ permalink raw reply
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Tyrel Datwyler @ 2021-12-21 1:34 UTC (permalink / raw)
To: Stefan Berger, jarkko, peterhuewe, linux-integrity
Cc: Korrapati.Likhitha, pavrampu, linux-kernel, jgg,
linux-security-module, gcwilson, linuxppc-dev
In-Reply-To: <d9eafa8f-4006-4bc2-c09b-6b02a14c6ef3@linux.ibm.com>
On 12/20/21 5:05 PM, Stefan Berger wrote:
>
> On 12/20/21 19:39, Tyrel Datwyler wrote:
>> On 12/11/21 5:28 PM, Stefan Berger wrote:
>>> Fix the following crash on kexec by checking chip->ops for a NULL pointer
>>> in tpm_chip_start() and returning an error code if this is the case.
>>>
>>> BUG: Kernel NULL pointer dereference on read at 0x00000060
>>> Faulting instruction address: 0xc00000000099a06c
>>> Oops: Kernel access of bad area, sig: 11 [#1]
>>> ...
>>> NIP [c00000000099a06c] tpm_chip_start+0x2c/0x140
>>> LR [c00000000099a808] tpm_chip_unregister+0x108/0x170
>>> Call Trace:
>>> [c0000000188bfa00] [c000000002b03930] fw_devlink_strict+0x0/0x8 (unreliable)
>>> [c0000000188bfa30] [c00000000099a808] tpm_chip_unregister+0x108/0x170
>>> [c0000000188bfa70] [c0000000009a3874] tpm_ibmvtpm_remove+0x34/0x130
>>> [c0000000188bfae0] [c000000000110dbc] vio_bus_remove+0x5c/0xb0
>>> [c0000000188bfb20] [c0000000009bc154] device_shutdown+0x1d4/0x3a8
>>> [c0000000188bfbc0] [c000000000196e14] kernel_restart_prepare+0x54/0x70
>>>
>>> The referenced patch below introduced a function to shut down the VIO bus.
>>> The bus shutdown now calls tpm_del_char_device (via tpm_chip_unregister)
>>> after a call to tpm_class_shutdown, which already set chip->ops to NULL.
>>> The crash occurrs when tpm_del_char_device calls tpm_chip_start with the
>>> chip->ops NULL pointer.
>> It was unclear to me at first, but IIUC the problem is the ibmvtpm device
>> receives two shutdown calls, the first is a class shutdown call for TPM devices,
>> followed by a bus shutdown call for VIO devices.
>>
>> It appears that the class shutdown routines are meant to be a pre-shutdown
>> routine as they are defined as class->shutdown_pre(), and it is clearly allowed
>> to call class->shutdown_pre() followed by one of but not both of the following
>> bus->shutdown() or driver->shutdown(). Even tpm_class_shutdown() mentions in the
>> function comment that bus/device shutdown to follow.
>
> I suppose you are referring to this here:
>
> /**
> * tpm_class_shutdown() - prepare the TPM device for loss of power.
> * @dev: device to which the chip is associated.
> *
> * Issues a TPM2_Shutdown command prior to loss of power, as required by the
> * TPM 2.0 spec. Then, calls bus- and device- specific shutdown code.
> *
> * Return: always 0 (i.e. success)
> */
>
> I think this comment still refers to the ancient code here:
>
> https://elixir.bootlin.com/linux/v4.4.295/source/drivers/char/tpm/tpm-chip.c#L161
>
> if (dev->bus && dev->bus->shutdown)
> dev->bus->shutdown(dev);
> else if (dev->driver && dev->driver->shutdown)
> dev->driver->shutdown(dev);
>
Right, but that was because device_shutdown didn't use to call bus or driver
shutdown routines if class->shutdown was defined. TPM is the class of devices
that implements class->shutdown and that code above was removed and
device_shutdown was made to call class and either bus/driver shutdown as well.
See: Commit 7521621e600ae ("Do not disable driver and bus shutdown hook when
class shutdown hook is set")
>
>
>>> Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and
>>> vio_bus")
>> This patch left implementing each vio driver shutdown routine as an exercise for
>> the respective maintainers, and instead just big hammers anything that doesn't
>> have a shutdown routine by calling the driver->remove().
>>
>> If tpm_class_shutdown() quiecses ibmvtpm enough implementing a no-op
>> ibmvtpm->shutdown() with a comment saying so suffices.
>>
>> However, the generic TPM code is still introducing a bug that an attempt to call
>> tpm_chip_unregister() after tpm_class_shutdown() will crash as mentioned above.
>
>
> An alternative solution may be this here:
Right, this is exactly what I was proposing in my last comment previously.
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..4cb908349b31 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
> mutex_unlock(&idr_lock);
>
> /* Make the driver uncallable. */
> - down_write(&chip->ops_sem);
> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
> - if (!tpm_chip_start(chip)) {
> - tpm2_shutdown(chip, TPM2_SU_CLEAR);
> - tpm_chip_stop(chip);
> - }
> - }
> - chip->ops = NULL;
> - up_write(&chip->ops_sem);
> + if (chip->ops)
> + tpm_class_shutdown(&chip->dev);
> }
>
> static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
>
>
> I could post this as v2 ?! Let me know...
Seeing as it is in TPM generic code and I'm not expert it would be nice if we
got some input from Jarkko, or someone else with more experience in this area to
make sure we aren't missing some other interaction. Otherwise, works for me.
-Tyrel
>
> Stefan
>
>
>>> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
>>> ---
>>> drivers/char/tpm/tpm-chip.c | 3 +++
>>> 1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>>> index ddaeceb7e109..cca1bde296ee 100644
>>> --- a/drivers/char/tpm/tpm-chip.c
>>> +++ b/drivers/char/tpm/tpm-chip.c
>>> @@ -101,6 +101,9 @@ int tpm_chip_start(struct tpm_chip *chip)
>>> {
>>> int ret;
>>>
>>> + if (!chip->ops)
>>> + return -EINVAL;
>>> +
>> I wonder if a better fix would to have tpm_del_char_device() check for valid
>> chip->ops and call tpm_class_shutdown() when the ops are still valid. Calling
>> tpm_class_shutdown() allows for some code deduplication in tpm_del_char_device().
>>
>> -Tyrel
>>
>>> tpm_clk_enable(chip);
>>>
>>> if (chip->locality == -1) {
>>>
^ permalink raw reply
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Stefan Berger @ 2021-12-21 1:31 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Korrapati.Likhitha, Tyrel Datwyler, pavrampu,
linux-security-module, linux-kernel, jarkko, gcwilson, peterhuewe,
linuxppc-dev, linux-integrity
In-Reply-To: <20211221011320.GM6467@ziepe.ca>
On 12/20/21 20:13, Jason Gunthorpe wrote:
> On Mon, Dec 20, 2021 at 08:05:58PM -0500, Stefan Berger wrote:
>
>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>> index ddaeceb7e109..4cb908349b31 100644
>> +++ b/drivers/char/tpm/tpm-chip.c
>> @@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>> mutex_unlock(&idr_lock);
>>
>> /* Make the driver uncallable. */
>> - down_write(&chip->ops_sem);
>> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>> - if (!tpm_chip_start(chip)) {
>> - tpm2_shutdown(chip, TPM2_SU_CLEAR);
>> - tpm_chip_stop(chip);
>> - }
>> - }
>> - chip->ops = NULL;
>> - up_write(&chip->ops_sem);
>> + if (chip->ops)
> ops cannot be read without locking
This here could be an alternative:
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index ddaeceb7e109..7772b475ebc0 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -474,7 +474,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)
/* Make the driver uncallable. */
down_write(&chip->ops_sem);
- if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+ if (chip->ops && chip->flags & TPM_CHIP_FLAG_TPM2) {
if (!tpm_chip_start(chip)) {
tpm2_shutdown(chip, TPM2_SU_CLEAR);
tpm_chip_stop(chip);
Stefan
>
> Jason
^ permalink raw reply related
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Jason Gunthorpe @ 2021-12-21 1:13 UTC (permalink / raw)
To: Stefan Berger
Cc: Korrapati.Likhitha, Tyrel Datwyler, pavrampu,
linux-security-module, linux-kernel, jarkko, gcwilson, peterhuewe,
linuxppc-dev, linux-integrity
In-Reply-To: <d9eafa8f-4006-4bc2-c09b-6b02a14c6ef3@linux.ibm.com>
On Mon, Dec 20, 2021 at 08:05:58PM -0500, Stefan Berger wrote:
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..4cb908349b31 100644
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
> mutex_unlock(&idr_lock);
>
> /* Make the driver uncallable. */
> - down_write(&chip->ops_sem);
> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
> - if (!tpm_chip_start(chip)) {
> - tpm2_shutdown(chip, TPM2_SU_CLEAR);
> - tpm_chip_stop(chip);
> - }
> - }
> - chip->ops = NULL;
> - up_write(&chip->ops_sem);
> + if (chip->ops)
ops cannot be read without locking
Jason
^ permalink raw reply
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Stefan Berger @ 2021-12-21 1:05 UTC (permalink / raw)
To: Tyrel Datwyler, jarkko, peterhuewe, linux-integrity
Cc: Korrapati.Likhitha, pavrampu, linux-kernel, jgg,
linux-security-module, gcwilson, linuxppc-dev
In-Reply-To: <1052cd36-1b85-5d36-045f-5c5bf9f0fc4e@linux.ibm.com>
On 12/20/21 19:39, Tyrel Datwyler wrote:
> On 12/11/21 5:28 PM, Stefan Berger wrote:
>> Fix the following crash on kexec by checking chip->ops for a NULL pointer
>> in tpm_chip_start() and returning an error code if this is the case.
>>
>> BUG: Kernel NULL pointer dereference on read at 0x00000060
>> Faulting instruction address: 0xc00000000099a06c
>> Oops: Kernel access of bad area, sig: 11 [#1]
>> ...
>> NIP [c00000000099a06c] tpm_chip_start+0x2c/0x140
>> LR [c00000000099a808] tpm_chip_unregister+0x108/0x170
>> Call Trace:
>> [c0000000188bfa00] [c000000002b03930] fw_devlink_strict+0x0/0x8 (unreliable)
>> [c0000000188bfa30] [c00000000099a808] tpm_chip_unregister+0x108/0x170
>> [c0000000188bfa70] [c0000000009a3874] tpm_ibmvtpm_remove+0x34/0x130
>> [c0000000188bfae0] [c000000000110dbc] vio_bus_remove+0x5c/0xb0
>> [c0000000188bfb20] [c0000000009bc154] device_shutdown+0x1d4/0x3a8
>> [c0000000188bfbc0] [c000000000196e14] kernel_restart_prepare+0x54/0x70
>>
>> The referenced patch below introduced a function to shut down the VIO bus.
>> The bus shutdown now calls tpm_del_char_device (via tpm_chip_unregister)
>> after a call to tpm_class_shutdown, which already set chip->ops to NULL.
>> The crash occurrs when tpm_del_char_device calls tpm_chip_start with the
>> chip->ops NULL pointer.
> It was unclear to me at first, but IIUC the problem is the ibmvtpm device
> receives two shutdown calls, the first is a class shutdown call for TPM devices,
> followed by a bus shutdown call for VIO devices.
>
> It appears that the class shutdown routines are meant to be a pre-shutdown
> routine as they are defined as class->shutdown_pre(), and it is clearly allowed
> to call class->shutdown_pre() followed by one of but not both of the following
> bus->shutdown() or driver->shutdown(). Even tpm_class_shutdown() mentions in the
> function comment that bus/device shutdown to follow.
I suppose you are referring to this here:
/**
* tpm_class_shutdown() - prepare the TPM device for loss of power.
* @dev: device to which the chip is associated.
*
* Issues a TPM2_Shutdown command prior to loss of power, as required
by the
* TPM 2.0 spec. Then, calls bus- and device- specific shutdown code.
*
* Return: always 0 (i.e. success)
*/
I think this comment still refers to the ancient code here:
https://elixir.bootlin.com/linux/v4.4.295/source/drivers/char/tpm/tpm-chip.c#L161
if (dev->bus && dev->bus->shutdown)
dev->bus->shutdown(dev);
else if (dev->driver && dev->driver->shutdown)
dev->driver->shutdown(dev);
>> Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
> This patch left implementing each vio driver shutdown routine as an exercise for
> the respective maintainers, and instead just big hammers anything that doesn't
> have a shutdown routine by calling the driver->remove().
>
> If tpm_class_shutdown() quiecses ibmvtpm enough implementing a no-op
> ibmvtpm->shutdown() with a comment saying so suffices.
>
> However, the generic TPM code is still introducing a bug that an attempt to call
> tpm_chip_unregister() after tpm_class_shutdown() will crash as mentioned above.
An alternative solution may be this here:
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index ddaeceb7e109..4cb908349b31 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
mutex_unlock(&idr_lock);
/* Make the driver uncallable. */
- down_write(&chip->ops_sem);
- if (chip->flags & TPM_CHIP_FLAG_TPM2) {
- if (!tpm_chip_start(chip)) {
- tpm2_shutdown(chip, TPM2_SU_CLEAR);
- tpm_chip_stop(chip);
- }
- }
- chip->ops = NULL;
- up_write(&chip->ops_sem);
+ if (chip->ops)
+ tpm_class_shutdown(&chip->dev);
}
static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
I could post this as v2 ?! Let me know...
Stefan
>> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
>> ---
>> drivers/char/tpm/tpm-chip.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>> index ddaeceb7e109..cca1bde296ee 100644
>> --- a/drivers/char/tpm/tpm-chip.c
>> +++ b/drivers/char/tpm/tpm-chip.c
>> @@ -101,6 +101,9 @@ int tpm_chip_start(struct tpm_chip *chip)
>> {
>> int ret;
>>
>> + if (!chip->ops)
>> + return -EINVAL;
>> +
> I wonder if a better fix would to have tpm_del_char_device() check for valid
> chip->ops and call tpm_class_shutdown() when the ops are still valid. Calling
> tpm_class_shutdown() allows for some code deduplication in tpm_del_char_device().
>
> -Tyrel
>
>> tpm_clk_enable(chip);
>>
>> if (chip->locality == -1) {
>>
^ permalink raw reply related
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Tyrel Datwyler @ 2021-12-21 0:39 UTC (permalink / raw)
To: Stefan Berger, jarkko, peterhuewe, linux-integrity
Cc: Korrapati.Likhitha, pavrampu, linux-kernel, jgg,
linux-security-module, gcwilson, linuxppc-dev
In-Reply-To: <20211212012804.1555661-1-stefanb@linux.ibm.com>
On 12/11/21 5:28 PM, Stefan Berger wrote:
> Fix the following crash on kexec by checking chip->ops for a NULL pointer
> in tpm_chip_start() and returning an error code if this is the case.
>
> BUG: Kernel NULL pointer dereference on read at 0x00000060
> Faulting instruction address: 0xc00000000099a06c
> Oops: Kernel access of bad area, sig: 11 [#1]
> ...
> NIP [c00000000099a06c] tpm_chip_start+0x2c/0x140
> LR [c00000000099a808] tpm_chip_unregister+0x108/0x170
> Call Trace:
> [c0000000188bfa00] [c000000002b03930] fw_devlink_strict+0x0/0x8 (unreliable)
> [c0000000188bfa30] [c00000000099a808] tpm_chip_unregister+0x108/0x170
> [c0000000188bfa70] [c0000000009a3874] tpm_ibmvtpm_remove+0x34/0x130
> [c0000000188bfae0] [c000000000110dbc] vio_bus_remove+0x5c/0xb0
> [c0000000188bfb20] [c0000000009bc154] device_shutdown+0x1d4/0x3a8
> [c0000000188bfbc0] [c000000000196e14] kernel_restart_prepare+0x54/0x70
>
> The referenced patch below introduced a function to shut down the VIO bus.
> The bus shutdown now calls tpm_del_char_device (via tpm_chip_unregister)
> after a call to tpm_class_shutdown, which already set chip->ops to NULL.
> The crash occurrs when tpm_del_char_device calls tpm_chip_start with the
> chip->ops NULL pointer.
It was unclear to me at first, but IIUC the problem is the ibmvtpm device
receives two shutdown calls, the first is a class shutdown call for TPM devices,
followed by a bus shutdown call for VIO devices.
It appears that the class shutdown routines are meant to be a pre-shutdown
routine as they are defined as class->shutdown_pre(), and it is clearly allowed
to call class->shutdown_pre() followed by one of but not both of the following
bus->shutdown() or driver->shutdown(). Even tpm_class_shutdown() mentions in the
function comment that bus/device shutdown to follow.
>
> Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
This patch left implementing each vio driver shutdown routine as an exercise for
the respective maintainers, and instead just big hammers anything that doesn't
have a shutdown routine by calling the driver->remove().
If tpm_class_shutdown() quiecses ibmvtpm enough implementing a no-op
ibmvtpm->shutdown() with a comment saying so suffices.
However, the generic TPM code is still introducing a bug that an attempt to call
tpm_chip_unregister() after tpm_class_shutdown() will crash as mentioned above.
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> drivers/char/tpm/tpm-chip.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..cca1bde296ee 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -101,6 +101,9 @@ int tpm_chip_start(struct tpm_chip *chip)
> {
> int ret;
>
> + if (!chip->ops)
> + return -EINVAL;
> +
I wonder if a better fix would to have tpm_del_char_device() check for valid
chip->ops and call tpm_class_shutdown() when the ops are still valid. Calling
tpm_class_shutdown() allows for some code deduplication in tpm_del_char_device().
-Tyrel
> tpm_clk_enable(chip);
>
> if (chip->locality == -1) {
>
^ permalink raw reply
* Re: [PATCH 08/17] all: replace bitmap_weight with bitmap_weight_{eq,gt,ge,lt,le} where appropriate
From: Greg Kroah-Hartman @ 2021-12-20 16:41 UTC (permalink / raw)
To: Yury Norov
Cc: Juri Lelli, Andrew Lunn, Rafael J. Wysocki, Catalin Marinas,
Guo Ren, Christoph Lameter, Christoph Hellwig, Andi Kleen,
Vincent Guittot, Ingo Molnar, Geert Uytterhoeven, Mel Gorman,
Viresh Kumar, Petr Mladek, Arnaldo Carvalho de Melo,
Michał Mirosław, Jens Axboe, Andy Lutomirski, Lee Jones,
Randy Dunlap, linux-kernel, linux-perf-users, Sergey Senozhatsky,
Thomas Gleixner, linux-crypto, Joe Perches, Andrew Morton,
Mark Rutland, Anup Patel, linux-ia64, David Airlie, Dave Hansen,
Solomon Peachy, Stephen Rothwell, Krzysztof Kozlowski,
Dennis Zhou, Matti Vaittinen, Sudeep Holla, Tejun Heo,
linux-arm-kernel, Stephen Boyd, Tariq Toukan, Jonathan Cameron,
Ulf Hansson, Emil Renner Berthing, Alexander Shishkin,
Mike Marciniszyn, Rasmus Villemoes, Subbaraya Sundeep,
Will Deacon, Sagi Grimberg, linux-csky, bcm-kernel-feedback-list,
linux-snps-arc, Kees Cook, Arnd Bergmann, James E.J. Bottomley,
Vineet Gupta, Steven Rostedt, Mark Gross, Borislav Petkov,
Mauro Carvalho Chehab, Thomas Bogendoerfer, Martin K. Petersen,
David Laight, linux-alpha, Geetha sowjanya, Ian Rogers, kvm,
Peter Zijlstra, Amitkumar Karwar, linux-mm, linux-riscv,
Jiri Olsa, Ard Biesheuvel, Marc Zyngier, Russell King, Andy Gross,
Jakub Kicinski, Vivien Didelot, Sunil Goutham, Paul E. McKenney,
linux-s390, Alexey Klimov, Heiko Carstens, Hans de Goede,
Nicholas Piggin, Marcin Wojtas, Vlastimil Babka, linuxppc-dev,
linux-mips, Palmer Dabbelt, Daniel Vetter, Jason Wessel,
Saeed Mahameed, Andy Shevchenko
In-Reply-To: <20211218212014.1315894-9-yury.norov@gmail.com>
On Sat, Dec 18, 2021 at 01:20:04PM -0800, Yury Norov wrote:
> Kernel code calls bitmap_weight() to compare the weight of bitmap with
> a given number. We can do it more efficiently with bitmap_weight_{eq, ...}
> because conditional bitmap_weight may stop traversing the bitmap earlier,
> as soon as condition is met.
>
> This patch replaces bitmap_weight with conditional versions where possible,
> except for small bitmaps which size is not configurable and known at
> constant time. In that case conditional version of bitmap_weight would not
> benefit due to small_const_nbits() optimization; but readability may
> suffer.
>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +-
> drivers/iio/dummy/iio_simple_dummy_buffer.c | 4 ++--
> drivers/iio/industrialio-trigger.c | 2 +-
> drivers/memstick/core/ms_block.c | 4 ++--
> drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 2 +-
> .../net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 2 +-
> .../net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 4 ++--
> drivers/net/ethernet/mellanox/mlx4/cmd.c | 10 +++-------
> drivers/net/ethernet/mellanox/mlx4/eq.c | 4 ++--
> drivers/net/ethernet/mellanox/mlx4/fw.c | 4 ++--
> drivers/net/ethernet/mellanox/mlx4/main.c | 2 +-
> drivers/perf/thunderx2_pmu.c | 4 ++--
> drivers/staging/media/tegra-video/vi.c | 2 +-
> 13 files changed, 21 insertions(+), 25 deletions(-)
"all" is not how to submit changes to the kernel. Please break them up
into subsystem-specific patches, and send them after your core changes
are accepted.
good luck!
greg k-h
^ permalink raw reply
* [PATCH 2/2] powerpc/fadump: opt out from freeing pages on cma activation failure
From: Hari Bathini @ 2021-12-20 19:34 UTC (permalink / raw)
To: akpm, linux-mm, mpe, linuxppc-dev
Cc: david, mahesh, sourabhjain, osalvador, Hari Bathini, mike.kravetz
In-Reply-To: <20211220193419.104242-1-hbathini@linux.ibm.com>
With commit a4e92ce8e4c8 ("powerpc/fadump: Reservationless firmware
assisted dump"), Linux kernel's Contiguous Memory Allocator (CMA)
based reservation was introduced in fadump. That change was aimed at
using CMA to let applications utilize the memory reserved for fadump
while blocking it from being used for kernel pages. The assumption
was, even if CMA activation fails for whatever reason, the memory
still remains reserved to avoid it from being used for kernel pages.
But commit 072355c1cf2d ("mm/cma: expose all pages to the buddy if
activation of an area fails") breaks this assumption as it started
exposing all pages to buddy allocator on CMA activation failure.
It led to warning messages like below while running crash-utility
on vmcore of a kernel having above two commits:
crash: seek error: kernel virtual address: <from reserved region>
To fix this problem, opt out from exposing pages to buddy allocator
on CMA activation failure for fadump reserved memory.
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/kernel/fadump.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index b7ceb041743c..d1f7f79dfbd8 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -112,6 +112,12 @@ static int __init fadump_cma_init(void)
return 1;
}
+ /*
+ * If CMA activation fails, do not let the reserved memory be exposed
+ * to buddy allocator. As good as 'fadump=nocma' case.
+ */
+ cma_dont_free_pages_on_error(fadump_cma);
+
/*
* So we now have successfully initialized cma area for fadump.
*/
--
2.33.1
^ permalink raw reply related
* [PATCH 1/2] mm/cma: provide option to opt out from exposing pages on activation failure
From: Hari Bathini @ 2021-12-20 19:34 UTC (permalink / raw)
To: akpm, linux-mm, mpe, linuxppc-dev
Cc: david, mahesh, sourabhjain, osalvador, Hari Bathini, mike.kravetz
In-Reply-To: <20211220193419.104242-1-hbathini@linux.ibm.com>
Commit 072355c1cf2d ("mm/cma: expose all pages to the buddy if
activation of an area fails") started exposing all pages to buddy
allocator on CMA activation failure. But there can be CMA users that
want to handle the reserved memory differently on CMA allocation
failure. Provide an option to opt out from exposing pages to buddy
for such cases.
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
include/linux/cma.h | 2 ++
mm/cma.c | 15 +++++++++++++--
mm/cma.h | 1 +
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/linux/cma.h b/include/linux/cma.h
index bd801023504b..8c9e229e7080 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -50,4 +50,6 @@ extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned
extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count);
extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data);
+
+extern void cma_dont_free_pages_on_error(struct cma *cma);
#endif
diff --git a/mm/cma.c b/mm/cma.c
index bc9ca8f3c487..6dffc9b2dafe 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -131,8 +131,10 @@ static void __init cma_activate_area(struct cma *cma)
bitmap_free(cma->bitmap);
out_error:
/* Expose all pages to the buddy, they are useless for CMA. */
- for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++)
- free_reserved_page(pfn_to_page(pfn));
+ if (cma->free_pages_on_error) {
+ for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++)
+ free_reserved_page(pfn_to_page(pfn));
+ }
totalcma_pages -= cma->count;
cma->count = 0;
pr_err("CMA area %s could not be activated\n", cma->name);
@@ -150,6 +152,14 @@ static int __init cma_init_reserved_areas(void)
}
core_initcall(cma_init_reserved_areas);
+void __init cma_dont_free_pages_on_error(struct cma *cma)
+{
+ if (!cma)
+ return;
+
+ cma->free_pages_on_error = false;
+}
+
/**
* cma_init_reserved_mem() - create custom contiguous area from reserved memory
* @base: Base address of the reserved area
@@ -204,6 +214,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
cma->base_pfn = PFN_DOWN(base);
cma->count = size >> PAGE_SHIFT;
cma->order_per_bit = order_per_bit;
+ cma->free_pages_on_error = true;
*res_cma = cma;
cma_area_count++;
totalcma_pages += (size / PAGE_SIZE);
diff --git a/mm/cma.h b/mm/cma.h
index 2c775877eae2..9e2438f9233d 100644
--- a/mm/cma.h
+++ b/mm/cma.h
@@ -30,6 +30,7 @@ struct cma {
/* kobject requires dynamic object */
struct cma_kobject *cma_kobj;
#endif
+ bool free_pages_on_error;
};
extern struct cma cma_areas[MAX_CMA_AREAS];
--
2.33.1
^ permalink raw reply related
* [PATCH 0/2] powerpc/fadump: handle CMA activation failure appropriately
From: Hari Bathini @ 2021-12-20 19:34 UTC (permalink / raw)
To: akpm, linux-mm, mpe, linuxppc-dev
Cc: david, mahesh, sourabhjain, osalvador, Hari Bathini, mike.kravetz
While commit a4e92ce8e4c8 ("powerpc/fadump: Reservationless firmware
assisted dump"), introduced Linux kernel's Contiguous Memory Allocator
(CMA) based reservation for fadump, it came with the assumption that
the memory remains reserved even if CMA activation fails. This
assumption ensures no kernel page resides in the reserved memory
region, which can't be mapped into the /proc/vmcore.
But commit 072355c1cf2d ("mm/cma: expose all pages to the buddy if
activation of an area fails") started returning all pages to buddy
allocator if CMA activation fails. This led to warning messages like
below while running crash-utility on vmcore of a kernel having above
two commits:
crash: seek error: kernel virtual address: <from reserved region>
as reserved memory region ended up having kernel pages crash-utility
was looking for. Fix this by introducing an option in CMA, to opt out
from exposing pages to buddy allocator, on CMA activation failure.
Hari Bathini (2):
mm/cma: provide option to opt out from exposing pages on activation
failure
powerpc/fadump: opt out from freeing pages on cma activation failure
arch/powerpc/kernel/fadump.c | 6 ++++++
include/linux/cma.h | 2 ++
mm/cma.c | 15 +++++++++++++--
mm/cma.h | 1 +
4 files changed, 22 insertions(+), 2 deletions(-)
--
2.33.1
^ permalink raw reply
* [PATCH v2 13/13] powerpc/ftrace: Remove ftrace_32.S
From: Christophe Leroy @ 2021-12-20 16:38 UTC (permalink / raw)
To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
Joe Lawrence, Steven Rostedt, Ingo Molnar, Naveen N . Rao
Cc: live-patching@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
In-Reply-To: <cover.1640017960.git.christophe.leroy@csgroup.eu>
Functions in ftrace_32.S are common with PPC64.
Reuse the ones defined for PPC64 with slight modification
when required.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/kernel/trace/Makefile | 7 +-
arch/powerpc/kernel/trace/ftrace_32.S | 152 ------------------
.../trace/{ftrace_64.S => ftrace_low.S} | 14 ++
...ftrace_64_mprofile.S => ftrace_mprofile.S} | 0
4 files changed, 17 insertions(+), 156 deletions(-)
delete mode 100644 arch/powerpc/kernel/trace/ftrace_32.S
rename arch/powerpc/kernel/trace/{ftrace_64.S => ftrace_low.S} (85%)
rename arch/powerpc/kernel/trace/{ftrace_64_mprofile.S => ftrace_mprofile.S} (100%)
diff --git a/arch/powerpc/kernel/trace/Makefile b/arch/powerpc/kernel/trace/Makefile
index 858503775c58..ac7d42a4e8d0 100644
--- a/arch/powerpc/kernel/trace/Makefile
+++ b/arch/powerpc/kernel/trace/Makefile
@@ -8,15 +8,14 @@ ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
endif
-obj32-$(CONFIG_FUNCTION_TRACER) += ftrace_32.o
-obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_64.o
+obj32-$(CONFIG_FUNCTION_TRACER) += ftrace_mprofile.o
ifdef CONFIG_MPROFILE_KERNEL
-obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_64_mprofile.o
+obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_mprofile.o
else
obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_64_pg.o
endif
obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
-obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
+obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o ftrace_low.o
obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o
obj-$(CONFIG_TRACING) += trace_clock.o
diff --git a/arch/powerpc/kernel/trace/ftrace_32.S b/arch/powerpc/kernel/trace/ftrace_32.S
deleted file mode 100644
index 2b425da97a6b..000000000000
--- a/arch/powerpc/kernel/trace/ftrace_32.S
+++ /dev/null
@@ -1,152 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Split from entry_32.S
- */
-
-#include <linux/magic.h>
-#include <asm/reg.h>
-#include <asm/ppc_asm.h>
-#include <asm/asm-offsets.h>
-#include <asm/ftrace.h>
-#include <asm/export.h>
-#include <asm/ptrace.h>
-
-_GLOBAL(mcount)
-_GLOBAL(_mcount)
- /*
- * It is required that _mcount on PPC32 must preserve the
- * link register. But we have r12 to play with. We use r12
- * to push the return address back to the caller of mcount
- * into the ctr register, restore the link register and
- * then jump back using the ctr register.
- */
- mflr r12
- mtctr r12
- mtlr r0
- bctr
-EXPORT_SYMBOL(_mcount)
-
-_GLOBAL(ftrace_caller)
- stwu r1, -INT_FRAME_SIZE(r1)
-
- SAVE_GPRS(3, 10, r1)
-
- addi r8, r1, INT_FRAME_SIZE
- stw r8, GPR1(r1)
-
- mflr r3
- stw r3, _NIP(r1)
- subi r3, r3, MCOUNT_INSN_SIZE
-
- stw r0, _LINK(r1)
- mr r4, r0
-
- lis r5,function_trace_op@ha
- lwz r5,function_trace_op@l(r5)
-
- addi r6, r1, STACK_FRAME_OVERHEAD
-.globl ftrace_call
-ftrace_call:
- bl ftrace_stub
- nop
-
- lwz r3, _NIP(r1)
- mtctr r3
-
- REST_GPRS(3, 10, r1)
-
- lwz r0, _LINK(r1)
- mtlr r0
-
- addi r1, r1, INT_FRAME_SIZE
- /* old link register ends up in ctr reg */
- bctr
-
-
-_GLOBAL(ftrace_stub)
- blr
-
-_GLOBAL(ftrace_regs_caller)
- /* Create our stack frame + pt_regs */
- stwu r1,-INT_FRAME_SIZE(r1)
-
- /* Save all gprs to pt_regs */
- stw r0, GPR0(r1)
- stmw r2, GPR2(r1)
-
- /* Save previous stack pointer (r1) */
- addi r8, r1, INT_FRAME_SIZE
- stw r8, GPR1(r1)
-
- /* Load special regs for save below */
- mfmsr r8
- mfctr r9
- mfxer r10
- mfcr r11
-
- /* Get the _mcount() call site out of LR */
- mflr r7
- /* Save it as pt_regs->nip */
- stw r7, _NIP(r1)
- /* Save the read LR in pt_regs->link */
- stw r0, _LINK(r1)
-
- lis r3,function_trace_op@ha
- lwz r5,function_trace_op@l(r3)
-
- /* Calculate ip from nip-4 into r3 for call below */
- subi r3, r7, MCOUNT_INSN_SIZE
-
- /* Put the original return address in r4 as parent_ip */
- mr r4, r0
-
- /* Save special regs */
- stw r8, _MSR(r1)
- stw r9, _CTR(r1)
- stw r10, _XER(r1)
- stw r11, _CCR(r1)
-
- /* Load &pt_regs in r6 for call below */
- addi r6, r1, STACK_FRAME_OVERHEAD
-
- /* ftrace_call(r3, r4, r5, r6) */
-.globl ftrace_regs_call
-ftrace_regs_call:
- bl ftrace_stub
- nop
-
- /* Load ctr with the possibly modified NIP */
- lwz r3, _NIP(r1)
- mtctr r3
-
- /* Restore gprs */
- lmw r2, GPR2(r1)
-
- /* Restore possibly modified LR */
- lwz r0, _LINK(r1)
- mtlr r0
-
- /* Pop our stack frame */
- addi r1, r1, INT_FRAME_SIZE
- /* old link register ends up in ctr reg */
- bctr
-
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-_GLOBAL(return_to_handler)
- /* need to save return values */
- stwu r1, -16(r1)
- stw r3, 8(r1)
- stw r4, 12(r1)
-
- bl ftrace_return_to_handler
-
- /* return value has real return address */
- mtlr r3
-
- lwz r3, 8(r1)
- lwz r4, 12(r1)
- addi r1, r1, 16
-
- /* Jump back to real return address */
- blr
-#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
diff --git a/arch/powerpc/kernel/trace/ftrace_64.S b/arch/powerpc/kernel/trace/ftrace_low.S
similarity index 85%
rename from arch/powerpc/kernel/trace/ftrace_64.S
rename to arch/powerpc/kernel/trace/ftrace_low.S
index 25e5b9e47c06..0bddf1fa6636 100644
--- a/arch/powerpc/kernel/trace/ftrace_64.S
+++ b/arch/powerpc/kernel/trace/ftrace_low.S
@@ -10,6 +10,7 @@
#include <asm/ppc-opcode.h>
#include <asm/export.h>
+#ifdef CONFIG_PPC64
.pushsection ".tramp.ftrace.text","aw",@progbits;
.globl ftrace_tramp_text
ftrace_tramp_text:
@@ -21,6 +22,7 @@ ftrace_tramp_text:
ftrace_tramp_init:
.space 64
.popsection
+#endif
_GLOBAL(mcount)
_GLOBAL(_mcount)
@@ -33,6 +35,7 @@ EXPORT_SYMBOL(_mcount)
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
_GLOBAL(return_to_handler)
/* need to save return values */
+#ifdef CONFIG_PPC64
std r4, -32(r1)
std r3, -24(r1)
/* save TOC */
@@ -46,6 +49,11 @@ _GLOBAL(return_to_handler)
* Switch to our TOC to run inside the core kernel.
*/
ld r2, PACATOC(r13)
+#else
+ stwu r1, -16(r1)
+ stw r3, 8(r1)
+ stw r4, 12(r1)
+#endif
bl ftrace_return_to_handler
nop
@@ -53,11 +61,17 @@ _GLOBAL(return_to_handler)
/* return value has real return address */
mtlr r3
+#ifdef CONFIG_PPC64
ld r1, 0(r1)
ld r4, -32(r1)
ld r3, -24(r1)
ld r2, -16(r1)
ld r31, -8(r1)
+#else
+ lwz r3, 8(r1)
+ lwz r4, 12(r1)
+ addi r1, r1, 16
+#endif
/* Jump back to real return address */
blr
diff --git a/arch/powerpc/kernel/trace/ftrace_64_mprofile.S b/arch/powerpc/kernel/trace/ftrace_mprofile.S
similarity index 100%
rename from arch/powerpc/kernel/trace/ftrace_64_mprofile.S
rename to arch/powerpc/kernel/trace/ftrace_mprofile.S
--
2.33.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox