Re: [PATCH v3 1/4] x86/split_lock: Move Split and Bus lock code to a dedicated file
From: Tom Lendacky
Date: Tue Aug 06 2024 - 09:50:00 EST
On 8/6/24 07:54, Ravi Bangoria wrote:
> Bus Lock Detect functionality on AMD platforms works identical to Intel.
> Move split_lock and bus_lock specific code from intel.c to a dedicated
> file so that it can be compiled and supported on non-Intel platforms.
>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>
> ---
> arch/x86/include/asm/cpu.h | 4 +
> arch/x86/kernel/cpu/Makefile | 1 +
> arch/x86/kernel/cpu/bus_lock.c | 410 +++++++++++++++++++++++++++++++++
> arch/x86/kernel/cpu/intel.c | 406 --------------------------------
> 4 files changed, 415 insertions(+), 406 deletions(-)
> create mode 100644 arch/x86/kernel/cpu/bus_lock.c
>
> diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
> index aa30fd8cad7f..051d872d2faf 100644
> --- a/arch/x86/include/asm/cpu.h
> +++ b/arch/x86/include/asm/cpu.h
> @@ -31,6 +31,8 @@ extern void __init sld_setup(struct cpuinfo_x86 *c);
> extern bool handle_user_split_lock(struct pt_regs *regs, long error_code);
> extern bool handle_guest_split_lock(unsigned long ip);
> extern void handle_bus_lock(struct pt_regs *regs);
> +void split_lock_init(void);
> +void bus_lock_init(void);
> u8 get_this_hybrid_cpu_type(void);
> #else
> static inline void __init sld_setup(struct cpuinfo_x86 *c) {}
> @@ -45,6 +47,8 @@ static inline bool handle_guest_split_lock(unsigned long ip)
> }
>
> static inline void handle_bus_lock(struct pt_regs *regs) {}
> +static inline void split_lock_init(void) {}
> +static inline void bus_lock_init(void) {}
>
> static inline u8 get_this_hybrid_cpu_type(void)
> {
> diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
> index 5857a0f5d514..9f74e0011f01 100644
> --- a/arch/x86/kernel/cpu/Makefile
> +++ b/arch/x86/kernel/cpu/Makefile
> @@ -27,6 +27,7 @@ obj-y += aperfmperf.o
> obj-y += cpuid-deps.o
> obj-y += umwait.o
> obj-y += capflags.o powerflags.o
> +obj-y += bus_lock.o
Since the whole file is protected by a "#if defined", why not just use
that here and conditionally build it?
You could also create a Kconfig that is set when CPU_SUP_INTEL is
selected and, later when CPU_SUP_AMD is selected, and use that
(CONFIG_X86_BUS_LOCK or such).
Either way:
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
>
> obj-$(CONFIG_X86_LOCAL_APIC) += topology.o
>