Skip to content

Commit 696207d

Browse files
Sebastian Andrzej Siewiorctmarinas
authored andcommitted
arm64/sve: Make kernel FPU protection RT friendly
Non RT kernels need to protect FPU against preemption and bottom half processing. This is achieved by disabling bottom halves via local_bh_disable() which implictly disables preemption. On RT kernels this protection mechanism is not sufficient because local_bh_disable() does not disable preemption. It serializes bottom half related processing via a CPU local lock. As bottom halves are running always in thread context on RT kernels disabling preemption is the proper choice as it implicitly prevents bottom half processing. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Acked-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent a1259dd commit 696207d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arch/arm64/kernel/fpsimd.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,19 @@ static void __get_cpu_fpsimd_context(void)
237237
*
238238
* The double-underscore version must only be called if you know the task
239239
* can't be preempted.
240+
*
241+
* On RT kernels local_bh_disable() is not sufficient because it only
242+
* serializes soft interrupt related sections via a local lock, but stays
243+
* preemptible. Disabling preemption is the right choice here as bottom
244+
* half processing is always in thread context on RT kernels so it
245+
* implicitly prevents bottom half processing as well.
240246
*/
241247
static void get_cpu_fpsimd_context(void)
242248
{
243-
local_bh_disable();
249+
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
250+
local_bh_disable();
251+
else
252+
preempt_disable();
244253
__get_cpu_fpsimd_context();
245254
}
246255

@@ -261,7 +270,10 @@ static void __put_cpu_fpsimd_context(void)
261270
static void put_cpu_fpsimd_context(void)
262271
{
263272
__put_cpu_fpsimd_context();
264-
local_bh_enable();
273+
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
274+
local_bh_enable();
275+
else
276+
preempt_enable();
265277
}
266278

267279
static bool have_cpu_fpsimd_context(void)

0 commit comments

Comments
 (0)