Skip to contentSkip to conversation

kvm: powerpc: book3s: Disable preemption while accessing paca xics_phys filed

PATCH In review Denis Kirjanov 4 participants 6 messages Mar 27, 2017 – Mar 29, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: powerpc: book3s: Disable preemption while accessing paca xics_phys filed

With CONFIG_DEBUG_PREEMPT enabled we see the following trace:

[  129.314426] BUG: using smp_processor_id() in preemptible [00000000]
code: modprobe/5459
[  129.314580] caller is .kvmppc_book3s_init_hv+0x184/0x350 [kvm_hv]
[  129.314697] CPU: 11 PID: 5459 Comm: modprobe Not tainted
4.11.0-rc3-00022-gc7e790c #1
[  129.314848] Call Trace:
[  129.314915] [c0000007d624b810] [c0000000023eef10] .dump_stack+0xe4/0x150 (unreliable)
[  129.315065] [c0000007d624b8a0] [c000000001f6ec04] .check_preemption_disabled+0x134/0x150
[  129.315210] [c0000007d624b940] [d00000000a010274] .kvmppc_book3s_init_hv+0x184/0x350 [kvm_hv]
[  129.315339] [c0000007d624ba00] [c00000000191d5cc] .do_one_initcall+0x5c/0x1c0
[  129.315416] [c0000007d624bad0] [c0000000023e9494] .do_init_module+0x84/0x240
[  129.315492] [c0000007d624bb70] [c000000001aade18] .load_module+0x1f68/0x2a10
[  129.315568] [c0000007d624bd20] [c000000001aaeb30] .SyS_finit_module+0xc0/0xf0
[  129.315645] [c0000007d624be30] [c00000000191baec] system_call+0x38/0xfc

Disable preemption while accessing paca struct to avoid inconsistent state

Fixes f725758 ("KVM: PPC: Book3S HV: Use OPAL XICS emulation on POWER9")
---
 arch/powerpc/kvm/book3s_hv.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +9 -1
index 1ec86d9..8e96bab 100644
@@ -3913,6 +3913,10 @@ static int kvmppc_radix_possible(void)
 static int kvmppc_book3s_init_hv(void)
 {
 	int r;
+#ifdef CONFIG_SMP
+	unsigned long xics_phys;
+#endif
+
 	/*
 	 * FIXME!! Do we need to check on all cpus ?
 	 */
@@ -3930,7 +3934,11 @@ static int kvmppc_book3s_init_hv(void)
 	 * indirectly, via OPAL.
 	 */
 #ifdef CONFIG_SMP
-	if (!get_paca()->kvm_hstate.xics_phys) {
+	preempt_disable();
+	xics_phys = get_paca()->kvm_hstate.xics_phys;
+	preempt_enable();
+
+	if (!xics_phys) {
 		struct device_node *np;
 
 		np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 41 lines · Denis Kirjanov

With CONFIG_DEBUG_PREEMPT enabled we see the following trace:

[  129.314426] BUG: using smp_processor_id() in preemptible [00000000]
code: modprobe/5459
[  129.314580] caller is .kvmppc_book3s_init_hv+0x184/0x350 [kvm_hv]
[  129.314697] CPU: 11 PID: 5459 Comm: modprobe Not tainted
4.11.0-rc3-00022-gc7e790c #1
[  129.314848] Call Trace:
[  129.314915] [c0000007d624b810] [c0000000023eef10] .dump_stack+0xe4/0x150 (unreliable)
[  129.315065] [c0000007d624b8a0] [c000000001f6ec04] .check_preemption_disabled+0x134/0x150
[  129.315210] [c0000007d624b940] [d00000000a010274] .kvmppc_book3s_init_hv+0x184/0x350 [kvm_hv]
[  129.315339] [c0000007d624ba00] [c00000000191d5cc] .do_one_initcall+0x5c/0x1c0
[  129.315416] [c0000007d624bad0] [c0000000023e9494] .do_init_module+0x84/0x240
[  129.315492] [c0000007d624bb70] [c000000001aade18] .load_module+0x1f68/0x2a10
[  129.315568] [c0000007d624bd20] [c000000001aaeb30] .SyS_finit_module+0xc0/0xf0
[  129.315645] [c0000007d624be30] [c00000000191baec] system_call+0x38/0xfc

Disable preemption while accessing paca struct to avoid inconsistent state

Fixes f725758 ("KVM: PPC: Book3S HV: Use OPAL XICS emulation on POWER9")
---
 arch/powerpc/kvm/book3s_hv.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +4 -0
index 1ec86d9..8e96bab 100644
@@ -3913,6 +3913,10 @@ static int kvmppc_radix_possible(void)
 static int kvmppc_book3s_init_hv(void)
 {
 	int r;
+#ifdef CONFIG_SMP
+	unsigned long xics_phys;
+#endif
+
 	/*
 	 * FIXME!! Do we need to check on all cpus ?
 	 */

arch/powerpc/kvm/book3s_hv.c static int kvmppc_book3s_init_hv(void) · line 3942

Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +5 -1
@@ -3930,7 +3934,11 @@ static int kvmppc_book3s_init_hv(void)
 	 * indirectly, via OPAL.
 	 */
 #ifdef CONFIG_SMP
-	if (!get_paca()->kvm_hstate.xics_phys) {
+	preempt_disable();
+	xics_phys = get_paca()->kvm_hstate.xics_phys;
+	preempt_enable();
+
+	if (!xics_phys) {
 		struct device_node *np;

Can you tell me what actual problem (other than the warning) this is fixing?

cheers

#2 lore raw
Quoted 2 lines

Can you tell me what actual problem (other than the warning) this is fixing?

Since we're running with CONFIG_DEBUG_PREEMPT and CONFIG_SMP get_paca defined as:

#define get_paca() ((void) debug_smp_processor_id(), local_paca)

instead of direct access to r13 so it's possible that we're preempted on a different CPU.

Quoted 2 lines

cheers

--=20
Regards / Mit besten Gr=C3=BC=C3=9Fen,
Denis

#3 lore raw
In reply to Michael Ellerman
Quoted 2 lines · Michael Ellerman

Denis Kirjanov <[email protected]> writes:

[...]

Quoted 6 lines
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -3930,7 +3934,11 @@ static int kvmppc_book3s_init_hv(void)
 	 * indirectly, via OPAL.
 	 */
 #ifdef CONFIG_SMP
-	if (!get_paca()->kvm_hstate.xics_phys) {
+	preempt_disable();
Quoted 8 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_book3s_init_hv(void) · line 3942

Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +4 -0
+	xics_phys = get_paca()->kvm_hstate.xics_phys;
+	preempt_enable();
+
+	if (!xics_phys) {
 		struct device_node *np;

Can you tell me what actual problem (other than the warning) this is fixing?

If paca->kvm_hstate.xics_phys is non-zero on one cpu, it will be non-zero on them all. Therefore this is not fixing any actual problem, just the warning.

By the way, the #ifdefs are ugly, and could be removed. (Yes I know it was me that put the first #ifdef in that function.)

Paul.

#4 lore raw
Quoted 19 lines · Paul Mackerras
Quoted 2 lines · Michael Ellerman

Denis Kirjanov <[email protected] <javascript:;>> writes:

[...]

Quoted 6 lines
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -3930,7 +3934,11 @@ static int kvmppc_book3s_init_hv(void)
     * indirectly, via OPAL.
     */
 #ifdef CONFIG_SMP
-   if (!get_paca()->kvm_hstate.xics_phys) {
+   preempt_disable();
Quoted 8 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_book3s_init_hv(void) · line 3942

Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +4 -0
+   xics_phys = get_paca()->kvm_hstate.xics_phys;
+   preempt_enable();
+
+   if (!xics_phys) {
            struct device_node *np;

Can you tell me what actual problem (other than the warning) this is fixing?

Quoted 9 lines

If paca->kvm_hstate.xics_phys is non-zero on one cpu, it will be non-zero on them all. Therefore this is not fixing any actual problem, just the warning.

By the way, the #ifdefs are ugly, and could be removed. (Yes I know it was me that put the first #ifdef in that function.)

Paul.

Then we can replace get_paca with local_paca to avoid the warning, right?

Signature · 2 lines
Regards / Mit besten Grüßen,
Denis
#5 lore raw
Quoted 21 lines · Denis Kirjanov
Quoted 19 lines · Paul Mackerras
Quoted 2 lines · Michael Ellerman

Denis Kirjanov <[email protected] <javascript:;>> writes:

[...]

Quoted 14 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_book3s_init_hv(void) · line 3942

Quoted 11 lines
arch/powerpc/kvm/book3s_hv.c +5 -1
@@ -3930,7 +3934,11 @@ static int kvmppc_book3s_init_hv(void)
     * indirectly, via OPAL.
     */
 #ifdef CONFIG_SMP
-   if (!get_paca()->kvm_hstate.xics_phys) {
+   preempt_disable();
+   xics_phys = get_paca()->kvm_hstate.xics_phys;
+   preempt_enable();
+
+   if (!xics_phys) {
            struct device_node *np;

Can you tell me what actual problem (other than the warning) this is fixing?

Quoted 5 lines
Quoted 3 lines

If paca->kvm_hstate.xics_phys is non-zero on one cpu, it will be non-zero on them all. Therefore this is not fixing any actual problem, just the warning.

Then we can replace get_paca with local_paca to avoid the warning, right?

Yeah in this case I think that's fine. I dislike it somewhat because a reader of that code now needs to know about what local_paca is but I guess that's OK.

My point was that just sticking preempt_disable/enable() around every get_paca() call is not the right way to deal with these warnings.

cheers