mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-21 13:58:41 +07:00
2fd8eb4ad8
It does not matter if the caller of may_use_simd() migrates to
another cpu after the call, but it is still important that the
kernel_neon_busy percpu instance that is read matches the cpu the
task is running on at the time of the read.
This means that raw_cpu_read() is not sufficient. kernel_neon_busy
may appear true if the caller migrates during the execution of
raw_cpu_read() and the next task to be scheduled in on the initial
cpu calls kernel_neon_begin().
This patch replaces raw_cpu_read() with this_cpu_read() to protect
against this race.
Cc: <stable@vger.kernel.org>
Fixes: cb84d11e16
("arm64: neon: Remove support for nested or hardirq kernel-mode NEON")
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Yandong Zhao <yandong77520@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
/*
|
|
* Copyright (C) 2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
* by the Free Software Foundation.
|
|
*/
|
|
|
|
#ifndef __ASM_SIMD_H
|
|
#define __ASM_SIMD_H
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/irqflags.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/preempt.h>
|
|
#include <linux/types.h>
|
|
|
|
#ifdef CONFIG_KERNEL_MODE_NEON
|
|
|
|
DECLARE_PER_CPU(bool, kernel_neon_busy);
|
|
|
|
/*
|
|
* may_use_simd - whether it is allowable at this time to issue SIMD
|
|
* instructions or access the SIMD register file
|
|
*
|
|
* Callers must not assume that the result remains true beyond the next
|
|
* preempt_enable() or return from softirq context.
|
|
*/
|
|
static __must_check inline bool may_use_simd(void)
|
|
{
|
|
/*
|
|
* kernel_neon_busy is only set while preemption is disabled,
|
|
* and is clear whenever preemption is enabled. Since
|
|
* this_cpu_read() is atomic w.r.t. preemption, kernel_neon_busy
|
|
* cannot change under our feet -- if it's set we cannot be
|
|
* migrated, and if it's clear we cannot be migrated to a CPU
|
|
* where it is set.
|
|
*/
|
|
return !in_irq() && !irqs_disabled() && !in_nmi() &&
|
|
!this_cpu_read(kernel_neon_busy);
|
|
}
|
|
|
|
#else /* ! CONFIG_KERNEL_MODE_NEON */
|
|
|
|
static __must_check inline bool may_use_simd(void) {
|
|
return false;
|
|
}
|
|
|
|
#endif /* ! CONFIG_KERNEL_MODE_NEON */
|
|
|
|
#endif
|