pmu.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*
  2. * Kernel-based Virtual Machine -- Performance Monitoring Unit support
  3. *
  4. * Copyright 2011 Red Hat, Inc. and/or its affiliates.
  5. *
  6. * Authors:
  7. * Avi Kivity <avi@redhat.com>
  8. * Gleb Natapov <gleb@redhat.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2. See
  11. * the COPYING file in the top-level directory.
  12. *
  13. */
  14. #include <linux/types.h>
  15. #include <linux/kvm_host.h>
  16. #include <linux/perf_event.h>
  17. #include <asm/perf_event.h>
  18. #include "x86.h"
  19. #include "cpuid.h"
  20. #include "lapic.h"
  21. static struct kvm_arch_event_perf_mapping {
  22. u8 eventsel;
  23. u8 unit_mask;
  24. unsigned event_type;
  25. bool inexact;
  26. } arch_events[] = {
  27. /* Index must match CPUID 0x0A.EBX bit vector */
  28. [0] = { 0x3c, 0x00, PERF_COUNT_HW_CPU_CYCLES },
  29. [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS },
  30. [2] = { 0x3c, 0x01, PERF_COUNT_HW_BUS_CYCLES },
  31. [3] = { 0x2e, 0x4f, PERF_COUNT_HW_CACHE_REFERENCES },
  32. [4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
  33. [5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
  34. [6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
  35. [7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
  36. };
  37. /* mapping between fixed pmc index and arch_events array */
  38. int fixed_pmc_events[] = {1, 0, 7};
  39. static bool pmc_is_gp(struct kvm_pmc *pmc)
  40. {
  41. return pmc->type == KVM_PMC_GP;
  42. }
  43. static inline u64 pmc_bitmask(struct kvm_pmc *pmc)
  44. {
  45. struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
  46. return pmu->counter_bitmask[pmc->type];
  47. }
  48. static inline bool pmc_enabled(struct kvm_pmc *pmc)
  49. {
  50. struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
  51. return test_bit(pmc->idx, (unsigned long *)&pmu->global_ctrl);
  52. }
  53. static inline struct kvm_pmc *get_gp_pmc(struct kvm_pmu *pmu, u32 msr,
  54. u32 base)
  55. {
  56. if (msr >= base && msr < base + pmu->nr_arch_gp_counters)
  57. return &pmu->gp_counters[msr - base];
  58. return NULL;
  59. }
  60. static inline struct kvm_pmc *get_fixed_pmc(struct kvm_pmu *pmu, u32 msr)
  61. {
  62. int base = MSR_CORE_PERF_FIXED_CTR0;
  63. if (msr >= base && msr < base + pmu->nr_arch_fixed_counters)
  64. return &pmu->fixed_counters[msr - base];
  65. return NULL;
  66. }
  67. static inline struct kvm_pmc *get_fixed_pmc_idx(struct kvm_pmu *pmu, int idx)
  68. {
  69. return get_fixed_pmc(pmu, MSR_CORE_PERF_FIXED_CTR0 + idx);
  70. }
  71. static struct kvm_pmc *global_idx_to_pmc(struct kvm_pmu *pmu, int idx)
  72. {
  73. if (idx < INTEL_PMC_IDX_FIXED)
  74. return get_gp_pmc(pmu, MSR_P6_EVNTSEL0 + idx, MSR_P6_EVNTSEL0);
  75. else
  76. return get_fixed_pmc_idx(pmu, idx - INTEL_PMC_IDX_FIXED);
  77. }
  78. void kvm_deliver_pmi(struct kvm_vcpu *vcpu)
  79. {
  80. if (vcpu->arch.apic)
  81. kvm_apic_local_deliver(vcpu->arch.apic, APIC_LVTPC);
  82. }
  83. static void trigger_pmi(struct irq_work *irq_work)
  84. {
  85. struct kvm_pmu *pmu = container_of(irq_work, struct kvm_pmu,
  86. irq_work);
  87. struct kvm_vcpu *vcpu = container_of(pmu, struct kvm_vcpu,
  88. arch.pmu);
  89. kvm_deliver_pmi(vcpu);
  90. }
  91. static void kvm_perf_overflow(struct perf_event *perf_event,
  92. struct perf_sample_data *data,
  93. struct pt_regs *regs)
  94. {
  95. struct kvm_pmc *pmc = perf_event->overflow_handler_context;
  96. struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
  97. if (!test_and_set_bit(pmc->idx, (unsigned long *)&pmu->reprogram_pmi)) {
  98. __set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
  99. kvm_make_request(KVM_REQ_PMU, pmc->vcpu);
  100. }
  101. }
  102. static void kvm_perf_overflow_intr(struct perf_event *perf_event,
  103. struct perf_sample_data *data, struct pt_regs *regs)
  104. {
  105. struct kvm_pmc *pmc = perf_event->overflow_handler_context;
  106. struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
  107. if (!test_and_set_bit(pmc->idx, (unsigned long *)&pmu->reprogram_pmi)) {
  108. __set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
  109. kvm_make_request(KVM_REQ_PMU, pmc->vcpu);
  110. /*
  111. * Inject PMI. If vcpu was in a guest mode during NMI PMI
  112. * can be ejected on a guest mode re-entry. Otherwise we can't
  113. * be sure that vcpu wasn't executing hlt instruction at the
  114. * time of vmexit and is not going to re-enter guest mode until,
  115. * woken up. So we should wake it, but this is impossible from
  116. * NMI context. Do it from irq work instead.
  117. */
  118. if (!kvm_is_in_guest())
  119. irq_work_queue(&pmc->vcpu->arch.pmu.irq_work);
  120. else
  121. kvm_make_request(KVM_REQ_PMI, pmc->vcpu);
  122. }
  123. }
  124. static u64 read_pmc(struct kvm_pmc *pmc)
  125. {
  126. u64 counter, enabled, running;
  127. counter = pmc->counter;
  128. if (pmc->perf_event)
  129. counter += perf_event_read_value(pmc->perf_event,
  130. &enabled, &running);
  131. /* FIXME: Scaling needed? */
  132. return counter & pmc_bitmask(pmc);
  133. }
  134. static void stop_counter(struct kvm_pmc *pmc)
  135. {
  136. if (pmc->perf_event) {
  137. pmc->counter = read_pmc(pmc);
  138. perf_event_release_kernel(pmc->perf_event);
  139. pmc->perf_event = NULL;
  140. }
  141. }
  142. static void reprogram_counter(struct kvm_pmc *pmc, u32 type,
  143. unsigned config, bool exclude_user, bool exclude_kernel,
  144. bool intr, bool in_tx, bool in_tx_cp)
  145. {
  146. struct perf_event *event;
  147. struct perf_event_attr attr = {
  148. .type = type,
  149. .size = sizeof(attr),
  150. .pinned = true,
  151. .exclude_idle = true,
  152. .exclude_host = 1,
  153. .exclude_user = exclude_user,
  154. .exclude_kernel = exclude_kernel,
  155. .config = config,
  156. };
  157. if (in_tx)
  158. attr.config |= HSW_IN_TX;
  159. if (in_tx_cp)
  160. attr.config |= HSW_IN_TX_CHECKPOINTED;
  161. attr.sample_period = (-pmc->counter) & pmc_bitmask(pmc);
  162. event = perf_event_create_kernel_counter(&attr, -1, current,
  163. intr ? kvm_perf_overflow_intr :
  164. kvm_perf_overflow, pmc);
  165. if (IS_ERR(event)) {
  166. printk_once("kvm: pmu event creation failed %ld\n",
  167. PTR_ERR(event));
  168. return;
  169. }
  170. pmc->perf_event = event;
  171. clear_bit(pmc->idx, (unsigned long*)&pmc->vcpu->arch.pmu.reprogram_pmi);
  172. }
  173. static unsigned find_arch_event(struct kvm_pmu *pmu, u8 event_select,
  174. u8 unit_mask)
  175. {
  176. int i;
  177. for (i = 0; i < ARRAY_SIZE(arch_events); i++)
  178. if (arch_events[i].eventsel == event_select
  179. && arch_events[i].unit_mask == unit_mask
  180. && (pmu->available_event_types & (1 << i)))
  181. break;
  182. if (i == ARRAY_SIZE(arch_events))
  183. return PERF_COUNT_HW_MAX;
  184. return arch_events[i].event_type;
  185. }
  186. static void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
  187. {
  188. unsigned config, type = PERF_TYPE_RAW;
  189. u8 event_select, unit_mask;
  190. if (eventsel & ARCH_PERFMON_EVENTSEL_PIN_CONTROL)
  191. printk_once("kvm pmu: pin control bit is ignored\n");
  192. pmc->eventsel = eventsel;
  193. stop_counter(pmc);
  194. if (!(eventsel & ARCH_PERFMON_EVENTSEL_ENABLE) || !pmc_enabled(pmc))
  195. return;
  196. event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
  197. unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
  198. if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
  199. ARCH_PERFMON_EVENTSEL_INV |
  200. ARCH_PERFMON_EVENTSEL_CMASK |
  201. HSW_IN_TX |
  202. HSW_IN_TX_CHECKPOINTED))) {
  203. config = find_arch_event(&pmc->vcpu->arch.pmu, event_select,
  204. unit_mask);
  205. if (config != PERF_COUNT_HW_MAX)
  206. type = PERF_TYPE_HARDWARE;
  207. }
  208. if (type == PERF_TYPE_RAW)
  209. config = eventsel & X86_RAW_EVENT_MASK;
  210. reprogram_counter(pmc, type, config,
  211. !(eventsel & ARCH_PERFMON_EVENTSEL_USR),
  212. !(eventsel & ARCH_PERFMON_EVENTSEL_OS),
  213. eventsel & ARCH_PERFMON_EVENTSEL_INT,
  214. (eventsel & HSW_IN_TX),
  215. (eventsel & HSW_IN_TX_CHECKPOINTED));
  216. }
  217. static void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 en_pmi, int idx)
  218. {
  219. unsigned en = en_pmi & 0x3;
  220. bool pmi = en_pmi & 0x8;
  221. stop_counter(pmc);
  222. if (!en || !pmc_enabled(pmc))
  223. return;
  224. reprogram_counter(pmc, PERF_TYPE_HARDWARE,
  225. arch_events[fixed_pmc_events[idx]].event_type,
  226. !(en & 0x2), /* exclude user */
  227. !(en & 0x1), /* exclude kernel */
  228. pmi, false, false);
  229. }
  230. static inline u8 fixed_en_pmi(u64 ctrl, int idx)
  231. {
  232. return (ctrl >> (idx * 4)) & 0xf;
  233. }
  234. static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data)
  235. {
  236. int i;
  237. for (i = 0; i < pmu->nr_arch_fixed_counters; i++) {
  238. u8 en_pmi = fixed_en_pmi(data, i);
  239. struct kvm_pmc *pmc = get_fixed_pmc_idx(pmu, i);
  240. if (fixed_en_pmi(pmu->fixed_ctr_ctrl, i) == en_pmi)
  241. continue;
  242. reprogram_fixed_counter(pmc, en_pmi, i);
  243. }
  244. pmu->fixed_ctr_ctrl = data;
  245. }
  246. static void reprogram_idx(struct kvm_pmu *pmu, int idx)
  247. {
  248. struct kvm_pmc *pmc = global_idx_to_pmc(pmu, idx);
  249. if (!pmc)
  250. return;
  251. if (pmc_is_gp(pmc))
  252. reprogram_gp_counter(pmc, pmc->eventsel);
  253. else {
  254. int fidx = idx - INTEL_PMC_IDX_FIXED;
  255. reprogram_fixed_counter(pmc,
  256. fixed_en_pmi(pmu->fixed_ctr_ctrl, fidx), fidx);
  257. }
  258. }
  259. static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
  260. {
  261. int bit;
  262. u64 diff = pmu->global_ctrl ^ data;
  263. pmu->global_ctrl = data;
  264. for_each_set_bit(bit, (unsigned long *)&diff, X86_PMC_IDX_MAX)
  265. reprogram_idx(pmu, bit);
  266. }
  267. bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr)
  268. {
  269. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  270. int ret;
  271. switch (msr) {
  272. case MSR_CORE_PERF_FIXED_CTR_CTRL:
  273. case MSR_CORE_PERF_GLOBAL_STATUS:
  274. case MSR_CORE_PERF_GLOBAL_CTRL:
  275. case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
  276. ret = pmu->version > 1;
  277. break;
  278. default:
  279. ret = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)
  280. || get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0)
  281. || get_fixed_pmc(pmu, msr);
  282. break;
  283. }
  284. return ret;
  285. }
  286. int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data)
  287. {
  288. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  289. struct kvm_pmc *pmc;
  290. switch (index) {
  291. case MSR_CORE_PERF_FIXED_CTR_CTRL:
  292. *data = pmu->fixed_ctr_ctrl;
  293. return 0;
  294. case MSR_CORE_PERF_GLOBAL_STATUS:
  295. *data = pmu->global_status;
  296. return 0;
  297. case MSR_CORE_PERF_GLOBAL_CTRL:
  298. *data = pmu->global_ctrl;
  299. return 0;
  300. case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
  301. *data = pmu->global_ovf_ctrl;
  302. return 0;
  303. default:
  304. if ((pmc = get_gp_pmc(pmu, index, MSR_IA32_PERFCTR0)) ||
  305. (pmc = get_fixed_pmc(pmu, index))) {
  306. *data = read_pmc(pmc);
  307. return 0;
  308. } else if ((pmc = get_gp_pmc(pmu, index, MSR_P6_EVNTSEL0))) {
  309. *data = pmc->eventsel;
  310. return 0;
  311. }
  312. }
  313. return 1;
  314. }
  315. int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
  316. {
  317. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  318. struct kvm_pmc *pmc;
  319. u32 index = msr_info->index;
  320. u64 data = msr_info->data;
  321. switch (index) {
  322. case MSR_CORE_PERF_FIXED_CTR_CTRL:
  323. if (pmu->fixed_ctr_ctrl == data)
  324. return 0;
  325. if (!(data & 0xfffffffffffff444ull)) {
  326. reprogram_fixed_counters(pmu, data);
  327. return 0;
  328. }
  329. break;
  330. case MSR_CORE_PERF_GLOBAL_STATUS:
  331. if (msr_info->host_initiated) {
  332. pmu->global_status = data;
  333. return 0;
  334. }
  335. break; /* RO MSR */
  336. case MSR_CORE_PERF_GLOBAL_CTRL:
  337. if (pmu->global_ctrl == data)
  338. return 0;
  339. if (!(data & pmu->global_ctrl_mask)) {
  340. global_ctrl_changed(pmu, data);
  341. return 0;
  342. }
  343. break;
  344. case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
  345. if (!(data & (pmu->global_ctrl_mask & ~(3ull<<62)))) {
  346. if (!msr_info->host_initiated)
  347. pmu->global_status &= ~data;
  348. pmu->global_ovf_ctrl = data;
  349. return 0;
  350. }
  351. break;
  352. default:
  353. if ((pmc = get_gp_pmc(pmu, index, MSR_IA32_PERFCTR0)) ||
  354. (pmc = get_fixed_pmc(pmu, index))) {
  355. if (!msr_info->host_initiated)
  356. data = (s64)(s32)data;
  357. pmc->counter += data - read_pmc(pmc);
  358. return 0;
  359. } else if ((pmc = get_gp_pmc(pmu, index, MSR_P6_EVNTSEL0))) {
  360. if (data == pmc->eventsel)
  361. return 0;
  362. if (!(data & pmu->reserved_bits)) {
  363. reprogram_gp_counter(pmc, data);
  364. return 0;
  365. }
  366. }
  367. }
  368. return 1;
  369. }
  370. int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc)
  371. {
  372. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  373. bool fixed = pmc & (1u << 30);
  374. pmc &= ~(3u << 30);
  375. return (!fixed && pmc >= pmu->nr_arch_gp_counters) ||
  376. (fixed && pmc >= pmu->nr_arch_fixed_counters);
  377. }
  378. int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data)
  379. {
  380. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  381. bool fast_mode = pmc & (1u << 31);
  382. bool fixed = pmc & (1u << 30);
  383. struct kvm_pmc *counters;
  384. u64 ctr;
  385. pmc &= ~(3u << 30);
  386. if (!fixed && pmc >= pmu->nr_arch_gp_counters)
  387. return 1;
  388. if (fixed && pmc >= pmu->nr_arch_fixed_counters)
  389. return 1;
  390. counters = fixed ? pmu->fixed_counters : pmu->gp_counters;
  391. ctr = read_pmc(&counters[pmc]);
  392. if (fast_mode)
  393. ctr = (u32)ctr;
  394. *data = ctr;
  395. return 0;
  396. }
  397. void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu)
  398. {
  399. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  400. struct kvm_cpuid_entry2 *entry;
  401. union cpuid10_eax eax;
  402. union cpuid10_edx edx;
  403. pmu->nr_arch_gp_counters = 0;
  404. pmu->nr_arch_fixed_counters = 0;
  405. pmu->counter_bitmask[KVM_PMC_GP] = 0;
  406. pmu->counter_bitmask[KVM_PMC_FIXED] = 0;
  407. pmu->version = 0;
  408. pmu->reserved_bits = 0xffffffff00200000ull;
  409. entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
  410. if (!entry)
  411. return;
  412. eax.full = entry->eax;
  413. edx.full = entry->edx;
  414. pmu->version = eax.split.version_id;
  415. if (!pmu->version)
  416. return;
  417. pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters,
  418. INTEL_PMC_MAX_GENERIC);
  419. pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1;
  420. pmu->available_event_types = ~entry->ebx &
  421. ((1ull << eax.split.mask_length) - 1);
  422. if (pmu->version == 1) {
  423. pmu->nr_arch_fixed_counters = 0;
  424. } else {
  425. pmu->nr_arch_fixed_counters =
  426. min_t(int, edx.split.num_counters_fixed,
  427. INTEL_PMC_MAX_FIXED);
  428. pmu->counter_bitmask[KVM_PMC_FIXED] =
  429. ((u64)1 << edx.split.bit_width_fixed) - 1;
  430. }
  431. pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) |
  432. (((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED);
  433. pmu->global_ctrl_mask = ~pmu->global_ctrl;
  434. entry = kvm_find_cpuid_entry(vcpu, 7, 0);
  435. if (entry &&
  436. (boot_cpu_has(X86_FEATURE_HLE) || boot_cpu_has(X86_FEATURE_RTM)) &&
  437. (entry->ebx & (X86_FEATURE_HLE|X86_FEATURE_RTM)))
  438. pmu->reserved_bits ^= HSW_IN_TX|HSW_IN_TX_CHECKPOINTED;
  439. }
  440. void kvm_pmu_init(struct kvm_vcpu *vcpu)
  441. {
  442. int i;
  443. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  444. memset(pmu, 0, sizeof(*pmu));
  445. for (i = 0; i < INTEL_PMC_MAX_GENERIC; i++) {
  446. pmu->gp_counters[i].type = KVM_PMC_GP;
  447. pmu->gp_counters[i].vcpu = vcpu;
  448. pmu->gp_counters[i].idx = i;
  449. }
  450. for (i = 0; i < INTEL_PMC_MAX_FIXED; i++) {
  451. pmu->fixed_counters[i].type = KVM_PMC_FIXED;
  452. pmu->fixed_counters[i].vcpu = vcpu;
  453. pmu->fixed_counters[i].idx = i + INTEL_PMC_IDX_FIXED;
  454. }
  455. init_irq_work(&pmu->irq_work, trigger_pmi);
  456. kvm_pmu_cpuid_update(vcpu);
  457. }
  458. void kvm_pmu_reset(struct kvm_vcpu *vcpu)
  459. {
  460. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  461. int i;
  462. irq_work_sync(&pmu->irq_work);
  463. for (i = 0; i < INTEL_PMC_MAX_GENERIC; i++) {
  464. struct kvm_pmc *pmc = &pmu->gp_counters[i];
  465. stop_counter(pmc);
  466. pmc->counter = pmc->eventsel = 0;
  467. }
  468. for (i = 0; i < INTEL_PMC_MAX_FIXED; i++)
  469. stop_counter(&pmu->fixed_counters[i]);
  470. pmu->fixed_ctr_ctrl = pmu->global_ctrl = pmu->global_status =
  471. pmu->global_ovf_ctrl = 0;
  472. }
  473. void kvm_pmu_destroy(struct kvm_vcpu *vcpu)
  474. {
  475. kvm_pmu_reset(vcpu);
  476. }
  477. void kvm_handle_pmu_event(struct kvm_vcpu *vcpu)
  478. {
  479. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  480. u64 bitmask;
  481. int bit;
  482. bitmask = pmu->reprogram_pmi;
  483. for_each_set_bit(bit, (unsigned long *)&bitmask, X86_PMC_IDX_MAX) {
  484. struct kvm_pmc *pmc = global_idx_to_pmc(pmu, bit);
  485. if (unlikely(!pmc || !pmc->perf_event)) {
  486. clear_bit(bit, (unsigned long *)&pmu->reprogram_pmi);
  487. continue;
  488. }
  489. reprogram_idx(pmu, bit);
  490. }
  491. }