mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

For historic reasons there are some TSC-related functions in the <asm/msr.h> header, even though there's an <asm/tsc.h> header. To facilitate the relocation of rdtsc{,_ordered}() from <asm/msr.h> to <asm/tsc.h> and to eventually eliminate the inclusion of <asm/msr.h> in <asm/tsc.h>, add an explicit <asm/msr.h> dependency to the source files that reference definitions from <asm/msr.h>. [ mingo: Clarified the changelog. ] Signed-off-by: Xin Li (Intel) <xin@zytor.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: Juergen Gross <jgross@suse.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Kees Cook <keescook@chromium.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Uros Bizjak <ubizjak@gmail.com> Link: https://lore.kernel.org/r/20250501054241.1245648-1-xin@zytor.com
94 lines
2.2 KiB
C
94 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
* Hyper-V specific spinlock code.
|
|
*
|
|
* Copyright (C) 2018, Intel, Inc.
|
|
*
|
|
* Author : Yi Sun <yi.y.sun@intel.com>
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "Hyper-V: " fmt
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <asm/mshyperv.h>
|
|
#include <asm/paravirt.h>
|
|
#include <asm/apic.h>
|
|
#include <asm/msr.h>
|
|
|
|
static bool hv_pvspin __initdata = true;
|
|
|
|
static void hv_qlock_kick(int cpu)
|
|
{
|
|
__apic_send_IPI(cpu, X86_PLATFORM_IPI_VECTOR);
|
|
}
|
|
|
|
static void hv_qlock_wait(u8 *byte, u8 val)
|
|
{
|
|
unsigned long flags;
|
|
|
|
if (in_nmi())
|
|
return;
|
|
|
|
/*
|
|
* Reading HV_X64_MSR_GUEST_IDLE MSR tells the hypervisor that the
|
|
* vCPU can be put into 'idle' state. This 'idle' state is
|
|
* terminated by an IPI, usually from hv_qlock_kick(), even if
|
|
* interrupts are disabled on the vCPU.
|
|
*
|
|
* To prevent a race against the unlock path it is required to
|
|
* disable interrupts before accessing the HV_X64_MSR_GUEST_IDLE
|
|
* MSR. Otherwise, if the IPI from hv_qlock_kick() arrives between
|
|
* the lock value check and the rdmsrq() then the vCPU might be put
|
|
* into 'idle' state by the hypervisor and kept in that state for
|
|
* an unspecified amount of time.
|
|
*/
|
|
local_irq_save(flags);
|
|
/*
|
|
* Only issue the rdmsrq() when the lock state has not changed.
|
|
*/
|
|
if (READ_ONCE(*byte) == val) {
|
|
unsigned long msr_val;
|
|
|
|
rdmsrq(HV_X64_MSR_GUEST_IDLE, msr_val);
|
|
|
|
(void)msr_val;
|
|
}
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Hyper-V does not support this so far.
|
|
*/
|
|
__visible bool hv_vcpu_is_preempted(int vcpu)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
PV_CALLEE_SAVE_REGS_THUNK(hv_vcpu_is_preempted);
|
|
|
|
void __init hv_init_spinlocks(void)
|
|
{
|
|
if (!hv_pvspin || !apic ||
|
|
!(ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) ||
|
|
!(ms_hyperv.features & HV_MSR_GUEST_IDLE_AVAILABLE)) {
|
|
pr_info("PV spinlocks disabled\n");
|
|
return;
|
|
}
|
|
pr_info("PV spinlocks enabled\n");
|
|
|
|
__pv_init_lock_hash();
|
|
pv_ops.lock.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
|
|
pv_ops.lock.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
|
|
pv_ops.lock.wait = hv_qlock_wait;
|
|
pv_ops.lock.kick = hv_qlock_kick;
|
|
pv_ops.lock.vcpu_is_preempted = PV_CALLEE_SAVE(hv_vcpu_is_preempted);
|
|
}
|
|
|
|
static __init int hv_parse_nopvspin(char *arg)
|
|
{
|
|
hv_pvspin = false;
|
|
return 0;
|
|
}
|
|
early_param("hv_nopvspin", hv_parse_nopvspin);
|