powerpc: Fix reschedule bug in KUAP-unlocked user copy
authorNicholas Piggin <npiggin@gmail.com>
Thu, 13 Oct 2022 15:16:47 +0000 (01:16 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 18 Oct 2022 11:46:19 +0000 (22:46 +1100)
commit00ff1eaac129a24516a3f6d75adfb9df1efb55dd
treeac7902ba33874fa1ca2b6740e9d4f9b1a4cbd8c5
parent2b2095f3a6b43ec36ff890febc588df1ec32e826
powerpc: Fix reschedule bug in KUAP-unlocked user copy

schedule must not be explicitly called while KUAP is unlocked, because
the AMR register will not be saved across the context switch on
64s (preemption is allowed because that is driven by interrupts which do
save the AMR).

exit_vmx_usercopy() runs inside an unlocked user access region, and it
calls preempt_enable() which will call schedule() if need_resched() was
set while non-preemptible. This can cause tasks to run unprotected when
the should not, and can cause the user copy to be improperly blocked
when scheduling back to it.

Fix this by avoiding the explicit resched for preempt kernels by
generating an interrupt to reschedule the context if need_resched() got
set.

Reported-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221013151647.1857994-3-npiggin@gmail.com
arch/powerpc/lib/vmx-helper.c