~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/hyperv/hv_spinlock.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 /*
  4  * Hyper-V specific spinlock code.
  5  *
  6  * Copyright (C) 2018, Intel, Inc.
  7  *
  8  * Author : Yi Sun <yi.y.sun@intel.com>
  9  */
 10 
 11 #define pr_fmt(fmt) "Hyper-V: " fmt
 12 
 13 #include <linux/spinlock.h>
 14 
 15 #include <asm/mshyperv.h>
 16 #include <asm/paravirt.h>
 17 #include <asm/apic.h>
 18 
 19 static bool __initdata hv_pvspin = true;
 20 
 21 static void hv_qlock_kick(int cpu)
 22 {
 23         apic->send_IPI(cpu, X86_PLATFORM_IPI_VECTOR);
 24 }
 25 
 26 static void hv_qlock_wait(u8 *byte, u8 val)
 27 {
 28         unsigned long msr_val;
 29         unsigned long flags;
 30 
 31         if (in_nmi())
 32                 return;
 33 
 34         /*
 35          * Reading HV_X64_MSR_GUEST_IDLE MSR tells the hypervisor that the
 36          * vCPU can be put into 'idle' state. This 'idle' state is
 37          * terminated by an IPI, usually from hv_qlock_kick(), even if
 38          * interrupts are disabled on the vCPU.
 39          *
 40          * To prevent a race against the unlock path it is required to
 41          * disable interrupts before accessing the HV_X64_MSR_GUEST_IDLE
 42          * MSR. Otherwise, if the IPI from hv_qlock_kick() arrives between
 43          * the lock value check and the rdmsrl() then the vCPU might be put
 44          * into 'idle' state by the hypervisor and kept in that state for
 45          * an unspecified amount of time.
 46          */
 47         local_irq_save(flags);
 48         /*
 49          * Only issue the rdmsrl() when the lock state has not changed.
 50          */
 51         if (READ_ONCE(*byte) == val)
 52                 rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val);
 53         local_irq_restore(flags);
 54 }
 55 
 56 /*
 57  * Hyper-V does not support this so far.
 58  */
 59 bool hv_vcpu_is_preempted(int vcpu)
 60 {
 61         return false;
 62 }
 63 PV_CALLEE_SAVE_REGS_THUNK(hv_vcpu_is_preempted);
 64 
 65 void __init hv_init_spinlocks(void)
 66 {
 67         if (!hv_pvspin || !apic ||
 68             !(ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) ||
 69             !(ms_hyperv.features & HV_X64_MSR_GUEST_IDLE_AVAILABLE)) {
 70                 pr_info("PV spinlocks disabled\n");
 71                 return;
 72         }
 73         pr_info("PV spinlocks enabled\n");
 74 
 75         __pv_init_lock_hash();
 76         pv_ops.lock.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
 77         pv_ops.lock.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
 78         pv_ops.lock.wait = hv_qlock_wait;
 79         pv_ops.lock.kick = hv_qlock_kick;
 80         pv_ops.lock.vcpu_is_preempted = PV_CALLEE_SAVE(hv_vcpu_is_preempted);
 81 }
 82 
 83 static __init int hv_parse_nopvspin(char *arg)
 84 {
 85         hv_pvspin = false;
 86         return 0;
 87 }
 88 early_param("hv_nopvspin", hv_parse_nopvspin);
 89 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp