cregit-Linux how code gets into the kernel

Release 4.7 arch/x86/kernel/kvm.c

Directory: arch/x86/kernel
/*
 * KVM paravirt_ops implementation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright (C) 2007, Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
 * Copyright IBM Corporation, 2007
 *   Authors: Anthony Liguori <aliguori@us.ibm.com>
 */

#include <linux/context_tracking.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kvm_para.h>
#include <linux/cpu.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/hardirq.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/hash.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/kprobes.h>
#include <linux/debugfs.h>
#include <linux/nmi.h>
#include <linux/swait.h>
#include <asm/timer.h>
#include <asm/cpu.h>
#include <asm/traps.h>
#include <asm/desc.h>
#include <asm/tlbflush.h>
#include <asm/idle.h>
#include <asm/apic.h>
#include <asm/apicdef.h>
#include <asm/hypervisor.h>
#include <asm/kvm_guest.h>


static int kvmapf = 1;


static int parse_no_kvmapf(char *arg) { kvmapf = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov17100.00%2100.00%
Total17100.00%2100.00%

early_param("no-kvmapf", parse_no_kvmapf); static int steal_acc = 1;
static int parse_no_stealacc(char *arg) { steal_acc = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
glauber costaglauber costa17100.00%1100.00%
Total17100.00%1100.00%

early_param("no-steal-acc", parse_no_stealacc); static int kvmclock_vsyscall = 1;
static int parse_no_kvmclock_vsyscall(char *arg) { kvmclock_vsyscall = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
marcelo tosattimarcelo tosatti17100.00%1100.00%
Total17100.00%1100.00%

early_param("no-kvmclock-vsyscall", parse_no_kvmclock_vsyscall); static DEFINE_PER_CPU(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64); static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64); static int has_steal_clock = 0; /* * No need for any "IO delay" on KVM */
static void kvm_io_delay(void) { }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov7100.00%1100.00%
Total7100.00%1100.00%

#define KVM_TASK_SLEEP_HASHBITS 8 #define KVM_TASK_SLEEP_HASHSIZE (1<<KVM_TASK_SLEEP_HASHBITS) struct kvm_task_sleep_node { struct hlist_node link; struct swait_queue_head wq; u32 token; int cpu; bool halted; }; static struct kvm_task_sleep_head { raw_spinlock_t lock; struct hlist_head list; } async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b, u32 token) { struct hlist_node *p; hlist_for_each(p, &b->list) { struct kvm_task_sleep_node *n = hlist_entry(p, typeof(*n), link); if (n->token == token) return n; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov61100.00%1100.00%
Total61100.00%1100.00%


void kvm_async_pf_task_wait(u32 token) { u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS); struct kvm_task_sleep_head *b = &async_pf_sleepers[key]; struct kvm_task_sleep_node n, *e; DECLARE_SWAITQUEUE(wait); rcu_irq_enter(); raw_spin_lock(&b->lock); e = _find_apf_task(b, token); if (e) { /* dummy entry exist -> wake up was delivered ahead of PF */ hlist_del(&e->link); kfree(e); raw_spin_unlock(&b->lock); rcu_irq_exit(); return; } n.token = token; n.cpu = smp_processor_id(); n.halted = is_idle_task(current) || preempt_count() > 1; init_swait_queue_head(&n.wq); hlist_add_head(&n.link, &b->list); raw_spin_unlock(&b->lock); for (;;) { if (!n.halted) prepare_to_swait(&n.wq, &wait, TASK_UNINTERRUPTIBLE); if (hlist_unhashed(&n.link)) break; if (!n.halted) { local_irq_enable(); schedule(); local_irq_disable(); } else { /* * We cannot reschedule. So halt. */ rcu_irq_exit(); native_safe_halt(); rcu_irq_enter(); local_irq_disable(); } } if (!n.halted) finish_swait(&n.wq, &wait); rcu_irq_exit(); return; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov22190.95%360.00%
li zhongli zhong156.17%120.00%
rik van rielrik van riel72.88%120.00%
Total243100.00%5100.00%

EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait);
static void apf_task_wake_one(struct kvm_task_sleep_node *n) { hlist_del_init(&n->link); if (n->halted) smp_send_reschedule(n->cpu); else if (swait_active(&n->wq)) swake_up(&n->wq); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov4996.08%266.67%
rik van rielrik van riel23.92%133.33%
Total51100.00%3100.00%


static void apf_task_wake_all(void) { int i; for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) { struct hlist_node *p, *next; struct kvm_task_sleep_head *b = &async_pf_sleepers[i]; raw_spin_lock(&b->lock); hlist_for_each_safe(p, next, &b->list) { struct kvm_task_sleep_node *n = hlist_entry(p, typeof(*n), link); if (n->cpu == smp_processor_id()) apf_task_wake_one(n); } raw_spin_unlock(&b->lock); } }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov10198.06%266.67%
rik van rielrik van riel21.94%133.33%
Total103100.00%3100.00%


void kvm_async_pf_task_wake(u32 token) { u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS); struct kvm_task_sleep_head *b = &async_pf_sleepers[key]; struct kvm_task_sleep_node *n; if (token == ~0) { apf_task_wake_all(); return; } again: raw_spin_lock(&b->lock); n = _find_apf_task(b, token); if (!n) { /* * async PF was not yet handled. * Add dummy entry for the token. */ n = kzalloc(sizeof(*n), GFP_ATOMIC); if (!n) { /* * Allocation failed! Busy wait while other cpu * handles async PF. */ raw_spin_unlock(&b->lock); cpu_relax(); goto again; } n->token = token; n->cpu = smp_processor_id(); init_swait_queue_head(&n->wq); hlist_add_head(&n->link, &b->list); } else apf_task_wake_one(n); raw_spin_unlock(&b->lock); return; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov14591.77%360.00%
marcelo tosattimarcelo tosatti95.70%120.00%
rik van rielrik van riel42.53%120.00%
Total158100.00%5100.00%

EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
u32 kvm_read_and_reset_pf_reason(void) { u32 reason = 0; if (__this_cpu_read(apf_reason.enabled)) { reason = __this_cpu_read(apf_reason.reason); __this_cpu_write(apf_reason.reason, 0); } return reason; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov3068.18%133.33%
marcelo tosattimarcelo tosatti715.91%133.33%
christoph lameterchristoph lameter715.91%133.33%
Total44100.00%3100.00%

EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason); NOKPROBE_SYMBOL(kvm_read_and_reset_pf_reason);
dotraplinkage void do_async_page_fault(struct pt_regs *regs, unsigned long error_code) { enum ctx_state prev_state; switch (kvm_read_and_reset_pf_reason()) { default: trace_do_page_fault(regs, error_code); break; case KVM_PV_REASON_PAGE_NOT_PRESENT: /* page is swapped out by the host. */ prev_state = exception_enter(); exit_idle(); kvm_async_pf_task_wait((u32)read_cr2()); exception_exit(prev_state); break; case KVM_PV_REASON_PAGE_READY: rcu_irq_enter(); exit_idle(); kvm_async_pf_task_wake((u32)read_cr2()); rcu_irq_exit(); break; } }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov6375.00%228.57%
frederic weisbeckerfrederic weisbecker89.52%114.29%
sasha levinsasha levin55.95%114.29%
li zhongli zhong44.76%114.29%
marcelo tosattimarcelo tosatti33.57%114.29%
dave hansendave hansen11.19%114.29%
Total84100.00%7100.00%

NOKPROBE_SYMBOL(do_async_page_fault);
static void __init paravirt_ops_setup(void) { pv_info.name = "KVM"; if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY)) pv_cpu_ops.io_delay = kvm_io_delay; #ifdef CONFIG_X86_IO_APIC no_timer_check = 1; #endif }

Contributors

PersonTokensPropCommitsCommitProp
marcelo tosattimarcelo tosatti2670.27%480.00%
chris wrightchris wright1129.73%120.00%
Total37100.00%5100.00%


static void kvm_register_steal_time(void) { int cpu = smp_processor_id(); struct kvm_steal_time *st = &per_cpu(steal_time, cpu); if (!has_steal_clock) return; memset(st, 0, sizeof(*st)); wrmsrl(MSR_KVM_STEAL_TIME, (slow_virt_to_phys(st) | KVM_MSR_ENABLED)); pr_info("kvm-stealtime: cpu %d, msr %llx\n", cpu, (unsigned long long) slow_virt_to_phys(st)); }

Contributors

PersonTokensPropCommitsCommitProp
glauber costaglauber costa6888.31%133.33%
shuah khanshuah khan79.09%133.33%
dave hansendave hansen22.60%133.33%
Total77100.00%3100.00%

static DEFINE_PER_CPU(unsigned long, kvm_apic_eoi) = KVM_PV_EOI_DISABLED;
static void kvm_guest_apic_eoi_write(u32 reg, u32 val) { /** * This relies on __test_and_clear_bit to modify the memory * in a way that is atomic with respect to the local CPU. * The hypervisor only accesses this memory from the local CPU so * there's no need for lock or memory barriers. * An optimization barrier is implied in apic write. */ if (__test_and_clear_bit(KVM_PV_EOI_BIT, this_cpu_ptr(&kvm_apic_eoi))) return; apic_write(APIC_EOI, APIC_EOI_ACK); }

Contributors

PersonTokensPropCommitsCommitProp
michael s. tsirkinmichael s. tsirkin3294.12%266.67%
christoph lameterchristoph lameter25.88%133.33%
Total34100.00%3100.00%


static void kvm_guest_cpu_init(void) { if (!kvm_para_available()) return; if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF) && kvmapf) { u64 pa = slow_virt_to_phys(this_cpu_ptr(&apf_reason)); #ifdef CONFIG_PREEMPT pa |= KVM_ASYNC_PF_SEND_ALWAYS; #endif wrmsrl(MSR_KVM_ASYNC_PF_EN, pa | KVM_ASYNC_PF_ENABLED); __this_cpu_write(apf_reason.enabled, 1); printk(KERN_INFO"KVM setup async PF for cpu %d\n", smp_processor_id()); } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) { unsigned long pa; /* Size alignment is implied but just to make it explicit. */ BUILD_BUG_ON(__alignof__(kvm_apic_eoi) < 4); __this_cpu_write(kvm_apic_eoi, 0); pa = slow_virt_to_phys(this_cpu_ptr(&kvm_apic_eoi)) | KVM_MSR_ENABLED; wrmsrl(MSR_KVM_PV_EOI_EN, pa); } if (has_steal_clock) kvm_register_steal_time(); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov6750.76%228.57%
michael s. tsirkinmichael s. tsirkin4534.09%114.29%
christoph lameterchristoph lameter107.58%114.29%
glauber costaglauber costa75.30%114.29%
dave hansendave hansen21.52%114.29%
nicholas krausenicholas krause10.76%114.29%
Total132100.00%7100.00%


static void kvm_pv_disable_apf(void) { if (!__this_cpu_read(apf_reason.enabled)) return; wrmsrl(MSR_KVM_ASYNC_PF_EN, 0); __this_cpu_write(apf_reason.enabled, 0); printk(KERN_INFO"Unregister pv shared memory for cpu %d\n", smp_processor_id()); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov3988.64%150.00%
christoph lameterchristoph lameter511.36%150.00%
Total44100.00%2100.00%


static void kvm_pv_guest_cpu_reboot(void *unused) { /* * We disable PV EOI before we load a new kernel by kexec, * since MSR_KVM_PV_EOI_EN stores a pointer into old kernel's memory. * New kernel can re-enable when it boots. */ if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); kvm_pv_disable_apf(); kvm_disable_steal_time(); }

Contributors

PersonTokensPropCommitsCommitProp
michael s. tsirkinmichael s. tsirkin2890.32%150.00%
florian westphalflorian westphal39.68%150.00%
Total31100.00%2100.00%


static int kvm_pv_reboot_notify(struct notifier_block *nb, unsigned long code, void *unused) { if (code == SYS_RESTART) on_each_cpu(kvm_pv_guest_cpu_reboot, NULL, 1); return NOTIFY_DONE; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov3697.30%150.00%
michael s. tsirkinmichael s. tsirkin12.70%150.00%
Total37100.00%2100.00%

static struct notifier_block kvm_pv_reboot_nb = { .notifier_call = kvm_pv_reboot_notify, };
static u64 kvm_steal_clock(int cpu) { u64 steal; struct kvm_steal_time *src; int version; src = &per_cpu(steal_time, cpu); do { version = src->version; rmb(); steal = src->steal; rmb(); } while ((version & 1) || (version != src->version)); return steal; }

Contributors

PersonTokensPropCommitsCommitProp
glauber costaglauber costa71100.00%1100.00%
Total71100.00%1100.00%


void kvm_disable_steal_time(void) { if (!has_steal_clock) return; wrmsr(MSR_KVM_STEAL_TIME, 0, 0); }

Contributors

PersonTokensPropCommitsCommitProp
glauber costaglauber costa22100.00%1100.00%
Total22100.00%1100.00%

#ifdef CONFIG_SMP
static void __init kvm_smp_prepare_boot_cpu(void) { kvm_guest_cpu_init(); native_smp_prepare_boot_cpu(); kvm_spinlock_init(); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov1583.33%266.67%
srivatsa vaddagirisrivatsa vaddagiri316.67%133.33%
Total18100.00%3100.00%


static void kvm_guest_cpu_online(void *dummy) { kvm_guest_cpu_init(); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov13100.00%1100.00%
Total13100.00%1100.00%


static void kvm_guest_cpu_offline(void *dummy) { kvm_disable_steal_time(); if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); kvm_pv_disable_apf(); apf_task_wake_all(); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov1648.48%250.00%
michael s. tsirkinmichael s. tsirkin1442.42%125.00%
glauber costaglauber costa39.09%125.00%
Total33100.00%4100.00%


static int kvm_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu) { int cpu = (unsigned long)hcpu; switch (action) { case CPU_ONLINE: case CPU_DOWN_FAILED: case CPU_ONLINE_FROZEN: smp_call_function_single(cpu, kvm_guest_cpu_online, NULL, 0); break; case CPU_DOWN_PREPARE: case CPU_DOWN_PREPARE_FROZEN: smp_call_function_single(cpu, kvm_guest_cpu_offline, NULL, 1); break; default: break; } return NOTIFY_OK; }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov78100.00%1100.00%
Total78100.00%1100.00%

static struct notifier_block kvm_cpu_notifier = { .notifier_call = kvm_cpu_notify, }; #endif
static void __init kvm_apf_trap_init(void) { set_intr_gate(14, async_page_fault); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov16100.00%1100.00%
Total16100.00%1100.00%


void __init kvm_guest_init(void) { int i; if (!kvm_para_available()) return; paravirt_ops_setup(); register_reboot_notifier(&kvm_pv_reboot_nb); for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) raw_spin_lock_init(&async_pf_sleepers[i].lock); if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF)) x86_init.irqs.trap_init = kvm_apf_trap_init; if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { has_steal_clock = 1; pv_time_ops.steal_clock = kvm_steal_clock; } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) apic_set_eoi_write(kvm_guest_apic_eoi_write); if (kvmclock_vsyscall) kvm_setup_vsyscall_timeinfo(); #ifdef CONFIG_SMP smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; register_cpu_notifier(&kvm_cpu_notifier); #else kvm_guest_cpu_init(); #endif /* * Hard lockup detection is enabled by default. Disable it, as guests * can get false positives too easily, for example if the host is * overcommitted. */ hardlockup_detector_disable(); }

Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov6953.08%327.27%
marcelo tosattimarcelo tosatti2519.23%218.18%
glauber costaglauber costa1914.62%19.09%
michael s. tsirkinmichael s. tsirkin129.23%218.18%
ulrich obergfellulrich obergfell43.08%218.18%
rik van rielrik van riel10.77%19.09%
Total130100.00%11100.00%


static noinline uint32_t __kvm_cpuid_base(void) { if (boot_cpu_data.cpuid_level < 0) return 0; /* So we don't blow up on old processors */ if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo bonzinipaolo bonzini3589.74%150.00%
borislav petkovborislav petkov410.26%150.00%
Total39100.00%2100.00%


static inline uint32_t kvm_cpuid_base(void) { static int kvm_cpuid_base = -1; if (kvm_cpuid_base == -1) kvm_cpuid_base = __kvm_cpuid_base(); return kvm_cpuid_base; }

Contributors

PersonTokensPropCommitsCommitProp
paolo bonzinipaolo bonzini31100.00%1100.00%
Total31100.00%1100.00%


bool kvm_para_available(void) { return kvm_cpuid_base() != 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo bonzinipaolo bonzini13100.00%1100.00%
Total13100.00%1100.00%

EXPORT_SYMBOL_GPL(kvm_para_available);
unsigned int kvm_arch_para_features(void) { return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES); }

Contributors

PersonTokensPropCommitsCommitProp
paolo bonzinipaolo bonzini17100.00%1100.00%
Total17100.00%1100.00%


static uint32_t __init kvm_detect(void) { return kvm_cpuid_base(); }

Contributors

PersonTokensPropCommitsCommitProp
prarit bhargavaprarit bhargava1076.92%150.00%
jason wangjason wang323.08%150.00%
Total13100.00%2100.00%

const struct hypervisor_x86 x86_hyper_kvm __refconst = { .name = "KVM", .detect = kvm_detect, .x2apic_available = kvm_para_available, }; EXPORT_SYMBOL_GPL(x86_hyper_kvm);
static __init int activate_jump_labels(void) { if (has_steal_clock) { static_key_slow_inc(&paravirt_steal_enabled); if (steal_acc) static_key_slow_inc(&paravirt_steal_rq_enabled); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
glauber costaglauber costa3294.12%150.00%
ingo molnaringo molnar25.88%150.00%
Total34100.00%2100.00%

arch_initcall(activate_jump_labels); #ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */
static void kvm_kick_cpu(int cpu) { int apicid; unsigned long flags = 0; apicid = per_cpu(x86_cpu_to_apicid, cpu); kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid); }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri3597.22%150.00%
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)12.78%150.00%
Total36100.00%2100.00%

#ifdef CONFIG_QUEUED_SPINLOCKS #include <asm/qspinlock.h>
static void kvm_wait(u8 *ptr, u8 val) { unsigned long flags; if (in_nmi()) return; local_irq_save(flags); if (READ_ONCE(*ptr) != val) goto out; /* * halt until it's our turn and kicked. Note that we do safe halt * for irq enabled case to avoid hang when lock info is overwritten * in irq spinlock slowpath and no spurious interrupt occur to save us. */ if (arch_irqs_disabled_flags(flags)) halt(); else safe_halt(); out: local_irq_restore(flags); }

Contributors

PersonTokensPropCommitsCommitProp
waiman longwaiman long63100.00%1100.00%
Total63100.00%1100.00%

#else /* !CONFIG_QUEUED_SPINLOCKS */ enum kvm_contention_stat { TAKEN_SLOW, TAKEN_SLOW_PICKUP, RELEASED_SLOW, RELEASED_SLOW_KICKED, NR_CONTENTION_STATS }; #ifdef CONFIG_KVM_DEBUG_FS #define HISTO_BUCKETS 30 static struct kvm_spinlock_stats { u32 contention_stats[NR_CONTENTION_STATS]; u32 histo_spin_blocked[HISTO_BUCKETS+1]; u64 time_blocked; } spinlock_stats; static u8 zero_stats;
static inline void check_zero(void) { u8 ret; u8 old; old = READ_ONCE(zero_stats); if (unlikely(old)) { ret = cmpxchg(&zero_stats, old, 0); /* This ensures only one fellow resets the stat */ if (ret == old) memset(&spinlock_stats, 0, sizeof(spinlock_stats)); } }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri6298.41%150.00%
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)11.59%150.00%
Total63100.00%2100.00%


static inline void add_stats(enum kvm_contention_stat var, u32 val) { check_zero(); spinlock_stats.contention_stats[var] += val; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri26100.00%1100.00%
Total26100.00%1100.00%


static inline u64 spin_time_start(void) { return sched_clock(); }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri13100.00%1100.00%
Total13100.00%1100.00%


static void __spin_time_accum(u64 delta, u32 *array) { unsigned index; index = ilog2(delta); check_zero(); if (index < HISTO_BUCKETS) array[index]++; else array[HISTO_BUCKETS]++; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri45100.00%1100.00%
Total45100.00%1100.00%


static inline void spin_time_accum_blocked(u64 start) { u32 delta; delta = sched_clock() - start; __spin_time_accum(delta, spinlock_stats.histo_spin_blocked); spinlock_stats.time_blocked += delta; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri35100.00%1100.00%
Total35100.00%1100.00%

static struct dentry *d_spin_debug; static struct dentry *d_kvm_debug;
static struct dentry *kvm_init_debugfs(void) { d_kvm_debug = debugfs_create_dir("kvm-guest", NULL); if (!d_kvm_debug) printk(KERN_WARNING "Could not create 'kvm' debugfs directory\n"); return d_kvm_debug; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri3193.94%133.33%
tim gardnertim gardner13.03%133.33%
nicholas krausenicholas krause13.03%133.33%
Total33100.00%3100.00%


static int __init kvm_spinlock_debugfs(void) { struct dentry *d_kvm; d_kvm = kvm_init_debugfs(); if (d_kvm == NULL) return -ENOMEM; d_spin_debug = debugfs_create_dir("spinlocks", d_kvm); debugfs_create_u8("zero_stats", 0644, d_spin_debug, &zero_stats); debugfs_create_u32("taken_slow", 0444, d_spin_debug, &spinlock_stats.contention_stats[TAKEN_SLOW]); debugfs_create_u32("taken_slow_pickup", 0444, d_spin_debug, &spinlock_stats.contention_stats[TAKEN_SLOW_PICKUP]); debugfs_create_u32("released_slow", 0444, d_spin_debug, &spinlock_stats.contention_stats[RELEASED_SLOW]); debugfs_create_u32("released_slow_kicked", 0444, d_spin_debug, &spinlock_stats.contention_stats[RELEASED_SLOW_KICKED]); debugfs_create_u64("time_blocked", 0444, d_spin_debug, &spinlock_stats.time_blocked); debugfs_create_u32_array("histo_blocked", 0444, d_spin_debug, spinlock_stats.histo_spin_blocked, HISTO_BUCKETS + 1); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri152100.00%1100.00%
Total152100.00%1100.00%

fs_initcall(kvm_spinlock_debugfs); #else /* !CONFIG_KVM_DEBUG_FS */
static inline void add_stats(enum kvm_contention_stat var, u32 val) { }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri13100.00%1100.00%
Total13100.00%1100.00%


static inline u64 spin_time_start(void) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri12100.00%1100.00%
Total12100.00%1100.00%


static inline void spin_time_accum_blocked(u64 start) { }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri9100.00%1100.00%
Total9100.00%1100.00%

#endif /* CONFIG_KVM_DEBUG_FS */ struct kvm_lock_waiting { struct arch_spinlock *lock; __ticket_t want; }; /* cpus 'waiting' on a spinlock to become available */ static cpumask_t waiting_cpus; /* Track spinlock on which a cpu is waiting */ static DEFINE_PER_CPU(struct kvm_lock_waiting, klock_waiting);
__visible void kvm_lock_spinning(struct arch_spinlock *lock, __ticket_t want) { struct kvm_lock_waiting *w; int cpu; u64 start; unsigned long flags; __ticket_t head; if (in_nmi()) return; w = this_cpu_ptr(&klock_waiting); cpu = smp_processor_id(); start = spin_time_start(); /* * Make sure an interrupt handler can't upset things in a * partially setup state. */ local_irq_save(flags); /* * The ordering protocol on this is that the "lock" pointer * may only be set non-NULL if the "want" ticket is correct. * If we're updating "want", we must first clear "lock". */ w->lock = NULL; smp_wmb(); w->want = want; smp_wmb(); w->lock = lock; add_stats(TAKEN_SLOW, 1); /* * This uses set_bit, which is atomic but we should not rely on its * reordering gurantees. So barrier is needed after this call. */ cpumask_set_cpu(cpu, &waiting_cpus); barrier(); /* * Mark entry to slowpath before doing the pickup test to make * sure we don't deadlock with an unlocker. */ __ticket_enter_slowpath(lock); /* make sure enter_slowpath, which is atomic does not cross the read */ smp_mb__after_atomic(); /* * check again make sure it didn't become free while * we weren't looking. */ head = READ_ONCE(lock->tickets.head); if (__tickets_equal(head, want)) { add_stats(TAKEN_SLOW_PICKUP, 1); goto out; } /* * halt until it's our turn and kicked. Note that we do safe halt * for irq enabled case to avoid hang when lock info is overwritten * in irq spinlock slowpath and no spurious interrupt occur to save us. */ if (arch_irqs_disabled_flags(flags)) halt(); else safe_halt(); out: cpumask_clear_cpu(cpu, &waiting_cpus); w->lock = NULL; local_irq_restore(flags); spin_time_accum_blocked(start); }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri16988.95%125.00%
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)189.47%125.00%
christoph lameterchristoph lameter21.05%125.00%
andi kleenandi kleen10.53%125.00%
Total190100.00%4100.00%

PV_CALLEE_SAVE_REGS_THUNK(kvm_lock_spinning); /* Kick vcpu waiting on @lock->head to reach value @ticket */
static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) { int cpu; add_stats(RELEASED_SLOW, 1); for_each_cpu(cpu, &waiting_cpus) { const struct kvm_lock_waiting *w = &per_cpu(klock_waiting, cpu); if (READ_ONCE(w->lock) == lock && READ_ONCE(w->want) == ticket) { add_stats(RELEASED_SLOW_KICKED, 1); kvm_kick_cpu(cpu); break; } } }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri7997.53%150.00%
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)22.47%150.00%
Total81100.00%2100.00%

#endif /* !CONFIG_QUEUED_SPINLOCKS */ /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present. */
void __init kvm_spinlock_init(void) { if (!kvm_para_available()) return; /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return; #ifdef CONFIG_QUEUED_SPINLOCKS __pv_init_lock_hash(); pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock); pv_lock_ops.wait = kvm_wait; pv_lock_ops.kick = kvm_kick_cpu; #else /* !CONFIG_QUEUED_SPINLOCKS */ pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning); pv_lock_ops.unlock_kick = kvm_unlock_kick; #endif }

Contributors

PersonTokensPropCommitsCommitProp
srivatsa vaddagirisrivatsa vaddagiri4051.28%133.33%
waiman longwaiman long3646.15%133.33%
ingo molnaringo molnar22.56%133.33%
Total78100.00%3100.00%


static __init int kvm_spinlock_init_jump(void) { if (!kvm_para_available()) return 0; if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return 0; static_key_slow_inc(&paravirt_ticketlocks_enabled); printk(KERN_INFO "KVM setup paravirtual spinlock\n"); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)44100.00%1100.00%
Total44100.00%1100.00%

early_initcall(kvm_spinlock_init_jump); #endif /* CONFIG_PARAVIRT_SPINLOCKS */

Overall Contributors

PersonTokensPropCommitsCommitProp
gleb natapovgleb natapov119039.05%817.39%
srivatsa vaddagirisrivatsa vaddagiri84127.60%12.17%
glauber costaglauber costa2759.03%12.17%
michael s. tsirkinmichael s. tsirkin1484.86%24.35%
marcelo tosattimarcelo tosatti1284.20%510.87%
waiman longwaiman long1083.54%12.17%
paolo bonzinipaolo bonzini1013.31%24.35%
raghavendra k t* (same as raghavendra koushik)raghavendra k t* (same as raghavendra koushik)712.33%36.52%
prarit bhargavaprarit bhargava361.18%12.17%
christoph lameterchristoph lameter260.85%12.17%
rik van rielrik van riel220.72%12.17%
li zhongli zhong190.62%12.17%
chris wrightchris wright110.36%12.17%
frederic weisbeckerfrederic weisbecker110.36%24.35%
masami hiramatsumasami hiramatsu100.33%12.17%
ingo molnaringo molnar70.23%24.35%
ulrich obergfellulrich obergfell70.23%24.35%
shuah khanshuah khan70.23%12.17%
alok katariaalok kataria50.16%12.17%
dave hansendave hansen50.16%24.35%
sasha levinsasha levin50.16%12.17%
borislav petkovborislav petkov40.13%12.17%
jason wangjason wang30.10%12.17%
florian westphalflorian westphal30.10%12.17%
nicholas krausenicholas krause20.07%12.17%
tim gardnertim gardner10.03%12.17%
andi kleenandi kleen10.03%12.17%
Total3047100.00%46100.00%
Directory: arch/x86/kernel
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}