pmu.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright (C) 2015 Linaro Ltd.
  3. * Author: Shannon Zhao <shannon.zhao@linaro.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/cpu.h>
  18. #include <linux/kvm.h>
  19. #include <linux/kvm_host.h>
  20. #include <linux/perf_event.h>
  21. #include <linux/uaccess.h>
  22. #include <asm/kvm_emulate.h>
  23. #include <kvm/arm_pmu.h>
  24. #include <kvm/arm_vgic.h>
  25. /**
  26. * kvm_pmu_get_counter_value - get PMU counter value
  27. * @vcpu: The vcpu pointer
  28. * @select_idx: The counter index
  29. */
  30. u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx)
  31. {
  32. u64 counter, reg, enabled, running;
  33. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  34. struct kvm_pmc *pmc = &pmu->pmc[select_idx];
  35. reg = (select_idx == ARMV8_PMU_CYCLE_IDX)
  36. ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + select_idx;
  37. counter = vcpu_sys_reg(vcpu, reg);
  38. /* The real counter value is equal to the value of counter register plus
  39. * the value perf event counts.
  40. */
  41. if (pmc->perf_event)
  42. counter += perf_event_read_value(pmc->perf_event, &enabled,
  43. &running);
  44. return counter & pmc->bitmask;
  45. }
  46. /**
  47. * kvm_pmu_set_counter_value - set PMU counter value
  48. * @vcpu: The vcpu pointer
  49. * @select_idx: The counter index
  50. * @val: The counter value
  51. */
  52. void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val)
  53. {
  54. u64 reg;
  55. reg = (select_idx == ARMV8_PMU_CYCLE_IDX)
  56. ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + select_idx;
  57. vcpu_sys_reg(vcpu, reg) += (s64)val - kvm_pmu_get_counter_value(vcpu, select_idx);
  58. }
  59. /**
  60. * kvm_pmu_stop_counter - stop PMU counter
  61. * @pmc: The PMU counter pointer
  62. *
  63. * If this counter has been configured to monitor some event, release it here.
  64. */
  65. static void kvm_pmu_stop_counter(struct kvm_vcpu *vcpu, struct kvm_pmc *pmc)
  66. {
  67. u64 counter, reg;
  68. if (pmc->perf_event) {
  69. counter = kvm_pmu_get_counter_value(vcpu, pmc->idx);
  70. reg = (pmc->idx == ARMV8_PMU_CYCLE_IDX)
  71. ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx;
  72. vcpu_sys_reg(vcpu, reg) = counter;
  73. perf_event_disable(pmc->perf_event);
  74. perf_event_release_kernel(pmc->perf_event);
  75. pmc->perf_event = NULL;
  76. }
  77. }
  78. /**
  79. * kvm_pmu_vcpu_reset - reset pmu state for cpu
  80. * @vcpu: The vcpu pointer
  81. *
  82. */
  83. void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
  84. {
  85. int i;
  86. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  87. for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
  88. kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]);
  89. pmu->pmc[i].idx = i;
  90. pmu->pmc[i].bitmask = 0xffffffffUL;
  91. }
  92. }
  93. /**
  94. * kvm_pmu_vcpu_destroy - free perf event of PMU for cpu
  95. * @vcpu: The vcpu pointer
  96. *
  97. */
  98. void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
  99. {
  100. int i;
  101. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  102. for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
  103. struct kvm_pmc *pmc = &pmu->pmc[i];
  104. if (pmc->perf_event) {
  105. perf_event_disable(pmc->perf_event);
  106. perf_event_release_kernel(pmc->perf_event);
  107. pmc->perf_event = NULL;
  108. }
  109. }
  110. }
  111. u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
  112. {
  113. u64 val = vcpu_sys_reg(vcpu, PMCR_EL0) >> ARMV8_PMU_PMCR_N_SHIFT;
  114. val &= ARMV8_PMU_PMCR_N_MASK;
  115. if (val == 0)
  116. return BIT(ARMV8_PMU_CYCLE_IDX);
  117. else
  118. return GENMASK(val - 1, 0) | BIT(ARMV8_PMU_CYCLE_IDX);
  119. }
  120. /**
  121. * kvm_pmu_enable_counter - enable selected PMU counter
  122. * @vcpu: The vcpu pointer
  123. * @val: the value guest writes to PMCNTENSET register
  124. *
  125. * Call perf_event_enable to start counting the perf event
  126. */
  127. void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val)
  128. {
  129. int i;
  130. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  131. struct kvm_pmc *pmc;
  132. if (!(vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E) || !val)
  133. return;
  134. for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
  135. if (!(val & BIT(i)))
  136. continue;
  137. pmc = &pmu->pmc[i];
  138. if (pmc->perf_event) {
  139. perf_event_enable(pmc->perf_event);
  140. if (pmc->perf_event->state != PERF_EVENT_STATE_ACTIVE)
  141. kvm_debug("fail to enable perf event\n");
  142. }
  143. }
  144. }
  145. /**
  146. * kvm_pmu_disable_counter - disable selected PMU counter
  147. * @vcpu: The vcpu pointer
  148. * @val: the value guest writes to PMCNTENCLR register
  149. *
  150. * Call perf_event_disable to stop counting the perf event
  151. */
  152. void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val)
  153. {
  154. int i;
  155. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  156. struct kvm_pmc *pmc;
  157. if (!val)
  158. return;
  159. for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
  160. if (!(val & BIT(i)))
  161. continue;
  162. pmc = &pmu->pmc[i];
  163. if (pmc->perf_event)
  164. perf_event_disable(pmc->perf_event);
  165. }
  166. }
  167. static u64 kvm_pmu_overflow_status(struct kvm_vcpu *vcpu)
  168. {
  169. u64 reg = 0;
  170. if ((vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E)) {
  171. reg = vcpu_sys_reg(vcpu, PMOVSSET_EL0);
  172. reg &= vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
  173. reg &= vcpu_sys_reg(vcpu, PMINTENSET_EL1);
  174. reg &= kvm_pmu_valid_counter_mask(vcpu);
  175. }
  176. return reg;
  177. }
  178. static void kvm_pmu_update_state(struct kvm_vcpu *vcpu)
  179. {
  180. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  181. bool overflow;
  182. if (!kvm_arm_pmu_v3_ready(vcpu))
  183. return;
  184. overflow = !!kvm_pmu_overflow_status(vcpu);
  185. if (pmu->irq_level == overflow)
  186. return;
  187. pmu->irq_level = overflow;
  188. if (likely(irqchip_in_kernel(vcpu->kvm))) {
  189. int ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
  190. pmu->irq_num, overflow, pmu);
  191. WARN_ON(ret);
  192. }
  193. }
  194. bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
  195. {
  196. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  197. struct kvm_sync_regs *sregs = &vcpu->run->s.regs;
  198. bool run_level = sregs->device_irq_level & KVM_ARM_DEV_PMU;
  199. if (likely(irqchip_in_kernel(vcpu->kvm)))
  200. return false;
  201. return pmu->irq_level != run_level;
  202. }
  203. /*
  204. * Reflect the PMU overflow interrupt output level into the kvm_run structure
  205. */
  206. void kvm_pmu_update_run(struct kvm_vcpu *vcpu)
  207. {
  208. struct kvm_sync_regs *regs = &vcpu->run->s.regs;
  209. /* Populate the timer bitmap for user space */
  210. regs->device_irq_level &= ~KVM_ARM_DEV_PMU;
  211. if (vcpu->arch.pmu.irq_level)
  212. regs->device_irq_level |= KVM_ARM_DEV_PMU;
  213. }
  214. /**
  215. * kvm_pmu_flush_hwstate - flush pmu state to cpu
  216. * @vcpu: The vcpu pointer
  217. *
  218. * Check if the PMU has overflowed while we were running in the host, and inject
  219. * an interrupt if that was the case.
  220. */
  221. void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu)
  222. {
  223. kvm_pmu_update_state(vcpu);
  224. }
  225. /**
  226. * kvm_pmu_sync_hwstate - sync pmu state from cpu
  227. * @vcpu: The vcpu pointer
  228. *
  229. * Check if the PMU has overflowed while we were running in the guest, and
  230. * inject an interrupt if that was the case.
  231. */
  232. void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu)
  233. {
  234. kvm_pmu_update_state(vcpu);
  235. }
  236. static inline struct kvm_vcpu *kvm_pmc_to_vcpu(struct kvm_pmc *pmc)
  237. {
  238. struct kvm_pmu *pmu;
  239. struct kvm_vcpu_arch *vcpu_arch;
  240. pmc -= pmc->idx;
  241. pmu = container_of(pmc, struct kvm_pmu, pmc[0]);
  242. vcpu_arch = container_of(pmu, struct kvm_vcpu_arch, pmu);
  243. return container_of(vcpu_arch, struct kvm_vcpu, arch);
  244. }
  245. /**
  246. * When the perf event overflows, set the overflow status and inform the vcpu.
  247. */
  248. static void kvm_pmu_perf_overflow(struct perf_event *perf_event,
  249. struct perf_sample_data *data,
  250. struct pt_regs *regs)
  251. {
  252. struct kvm_pmc *pmc = perf_event->overflow_handler_context;
  253. struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
  254. int idx = pmc->idx;
  255. vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(idx);
  256. if (kvm_pmu_overflow_status(vcpu)) {
  257. kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu);
  258. kvm_vcpu_kick(vcpu);
  259. }
  260. }
  261. /**
  262. * kvm_pmu_software_increment - do software increment
  263. * @vcpu: The vcpu pointer
  264. * @val: the value guest writes to PMSWINC register
  265. */
  266. void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val)
  267. {
  268. int i;
  269. u64 type, enable, reg;
  270. if (val == 0)
  271. return;
  272. enable = vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
  273. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++) {
  274. if (!(val & BIT(i)))
  275. continue;
  276. type = vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i)
  277. & ARMV8_PMU_EVTYPE_EVENT;
  278. if ((type == ARMV8_PMUV3_PERFCTR_SW_INCR)
  279. && (enable & BIT(i))) {
  280. reg = vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1;
  281. reg = lower_32_bits(reg);
  282. vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg;
  283. if (!reg)
  284. vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(i);
  285. }
  286. }
  287. }
  288. /**
  289. * kvm_pmu_handle_pmcr - handle PMCR register
  290. * @vcpu: The vcpu pointer
  291. * @val: the value guest writes to PMCR register
  292. */
  293. void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
  294. {
  295. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  296. struct kvm_pmc *pmc;
  297. u64 mask;
  298. int i;
  299. mask = kvm_pmu_valid_counter_mask(vcpu);
  300. if (val & ARMV8_PMU_PMCR_E) {
  301. kvm_pmu_enable_counter(vcpu,
  302. vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask);
  303. } else {
  304. kvm_pmu_disable_counter(vcpu, mask);
  305. }
  306. if (val & ARMV8_PMU_PMCR_C)
  307. kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
  308. if (val & ARMV8_PMU_PMCR_P) {
  309. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++)
  310. kvm_pmu_set_counter_value(vcpu, i, 0);
  311. }
  312. if (val & ARMV8_PMU_PMCR_LC) {
  313. pmc = &pmu->pmc[ARMV8_PMU_CYCLE_IDX];
  314. pmc->bitmask = 0xffffffffffffffffUL;
  315. }
  316. }
  317. static bool kvm_pmu_counter_is_enabled(struct kvm_vcpu *vcpu, u64 select_idx)
  318. {
  319. return (vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E) &&
  320. (vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & BIT(select_idx));
  321. }
  322. /**
  323. * kvm_pmu_set_counter_event_type - set selected counter to monitor some event
  324. * @vcpu: The vcpu pointer
  325. * @data: The data guest writes to PMXEVTYPER_EL0
  326. * @select_idx: The number of selected counter
  327. *
  328. * When OS accesses PMXEVTYPER_EL0, that means it wants to set a PMC to count an
  329. * event with given hardware event number. Here we call perf_event API to
  330. * emulate this action and create a kernel perf event for it.
  331. */
  332. void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
  333. u64 select_idx)
  334. {
  335. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  336. struct kvm_pmc *pmc = &pmu->pmc[select_idx];
  337. struct perf_event *event;
  338. struct perf_event_attr attr;
  339. u64 eventsel, counter;
  340. kvm_pmu_stop_counter(vcpu, pmc);
  341. eventsel = data & ARMV8_PMU_EVTYPE_EVENT;
  342. /* Software increment event does't need to be backed by a perf event */
  343. if (eventsel == ARMV8_PMUV3_PERFCTR_SW_INCR &&
  344. select_idx != ARMV8_PMU_CYCLE_IDX)
  345. return;
  346. memset(&attr, 0, sizeof(struct perf_event_attr));
  347. attr.type = PERF_TYPE_RAW;
  348. attr.size = sizeof(attr);
  349. attr.pinned = 1;
  350. attr.disabled = !kvm_pmu_counter_is_enabled(vcpu, select_idx);
  351. attr.exclude_user = data & ARMV8_PMU_EXCLUDE_EL0 ? 1 : 0;
  352. attr.exclude_kernel = data & ARMV8_PMU_EXCLUDE_EL1 ? 1 : 0;
  353. attr.exclude_hv = 1; /* Don't count EL2 events */
  354. attr.exclude_host = 1; /* Don't count host events */
  355. attr.config = (select_idx == ARMV8_PMU_CYCLE_IDX) ?
  356. ARMV8_PMUV3_PERFCTR_CPU_CYCLES : eventsel;
  357. counter = kvm_pmu_get_counter_value(vcpu, select_idx);
  358. /* The initial sample period (overflow count) of an event. */
  359. attr.sample_period = (-counter) & pmc->bitmask;
  360. event = perf_event_create_kernel_counter(&attr, -1, current,
  361. kvm_pmu_perf_overflow, pmc);
  362. if (IS_ERR(event)) {
  363. pr_err_once("kvm: pmu event creation failed %ld\n",
  364. PTR_ERR(event));
  365. return;
  366. }
  367. pmc->perf_event = event;
  368. }
  369. bool kvm_arm_support_pmu_v3(void)
  370. {
  371. /*
  372. * Check if HW_PERF_EVENTS are supported by checking the number of
  373. * hardware performance counters. This could ensure the presence of
  374. * a physical PMU and CONFIG_PERF_EVENT is selected.
  375. */
  376. return (perf_num_counters() > 0);
  377. }
  378. int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
  379. {
  380. if (!vcpu->arch.pmu.created)
  381. return 0;
  382. /*
  383. * A valid interrupt configuration for the PMU is either to have a
  384. * properly configured interrupt number and using an in-kernel
  385. * irqchip, or to not have an in-kernel GIC and not set an IRQ.
  386. */
  387. if (irqchip_in_kernel(vcpu->kvm)) {
  388. int irq = vcpu->arch.pmu.irq_num;
  389. if (!kvm_arm_pmu_irq_initialized(vcpu))
  390. return -EINVAL;
  391. /*
  392. * If we are using an in-kernel vgic, at this point we know
  393. * the vgic will be initialized, so we can check the PMU irq
  394. * number against the dimensions of the vgic and make sure
  395. * it's valid.
  396. */
  397. if (!irq_is_ppi(irq) && !vgic_valid_spi(vcpu->kvm, irq))
  398. return -EINVAL;
  399. } else if (kvm_arm_pmu_irq_initialized(vcpu)) {
  400. return -EINVAL;
  401. }
  402. kvm_pmu_vcpu_reset(vcpu);
  403. vcpu->arch.pmu.ready = true;
  404. return 0;
  405. }
  406. static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
  407. {
  408. if (!kvm_arm_support_pmu_v3())
  409. return -ENODEV;
  410. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  411. return -ENXIO;
  412. if (vcpu->arch.pmu.created)
  413. return -EBUSY;
  414. if (irqchip_in_kernel(vcpu->kvm)) {
  415. int ret;
  416. /*
  417. * If using the PMU with an in-kernel virtual GIC
  418. * implementation, we require the GIC to be already
  419. * initialized when initializing the PMU.
  420. */
  421. if (!vgic_initialized(vcpu->kvm))
  422. return -ENODEV;
  423. if (!kvm_arm_pmu_irq_initialized(vcpu))
  424. return -ENXIO;
  425. ret = kvm_vgic_set_owner(vcpu, vcpu->arch.pmu.irq_num,
  426. &vcpu->arch.pmu);
  427. if (ret)
  428. return ret;
  429. }
  430. vcpu->arch.pmu.created = true;
  431. return 0;
  432. }
  433. /*
  434. * For one VM the interrupt type must be same for each vcpu.
  435. * As a PPI, the interrupt number is the same for all vcpus,
  436. * while as an SPI it must be a separate number per vcpu.
  437. */
  438. static bool pmu_irq_is_valid(struct kvm *kvm, int irq)
  439. {
  440. int i;
  441. struct kvm_vcpu *vcpu;
  442. kvm_for_each_vcpu(i, vcpu, kvm) {
  443. if (!kvm_arm_pmu_irq_initialized(vcpu))
  444. continue;
  445. if (irq_is_ppi(irq)) {
  446. if (vcpu->arch.pmu.irq_num != irq)
  447. return false;
  448. } else {
  449. if (vcpu->arch.pmu.irq_num == irq)
  450. return false;
  451. }
  452. }
  453. return true;
  454. }
  455. int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  456. {
  457. switch (attr->attr) {
  458. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  459. int __user *uaddr = (int __user *)(long)attr->addr;
  460. int irq;
  461. if (!irqchip_in_kernel(vcpu->kvm))
  462. return -EINVAL;
  463. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  464. return -ENODEV;
  465. if (get_user(irq, uaddr))
  466. return -EFAULT;
  467. /* The PMU overflow interrupt can be a PPI or a valid SPI. */
  468. if (!(irq_is_ppi(irq) || irq_is_spi(irq)))
  469. return -EINVAL;
  470. if (!pmu_irq_is_valid(vcpu->kvm, irq))
  471. return -EINVAL;
  472. if (kvm_arm_pmu_irq_initialized(vcpu))
  473. return -EBUSY;
  474. kvm_debug("Set kvm ARM PMU irq: %d\n", irq);
  475. vcpu->arch.pmu.irq_num = irq;
  476. return 0;
  477. }
  478. case KVM_ARM_VCPU_PMU_V3_INIT:
  479. return kvm_arm_pmu_v3_init(vcpu);
  480. }
  481. return -ENXIO;
  482. }
  483. int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  484. {
  485. switch (attr->attr) {
  486. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  487. int __user *uaddr = (int __user *)(long)attr->addr;
  488. int irq;
  489. if (!irqchip_in_kernel(vcpu->kvm))
  490. return -EINVAL;
  491. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  492. return -ENODEV;
  493. if (!kvm_arm_pmu_irq_initialized(vcpu))
  494. return -ENXIO;
  495. irq = vcpu->arch.pmu.irq_num;
  496. return put_user(irq, uaddr);
  497. }
  498. }
  499. return -ENXIO;
  500. }
  501. int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  502. {
  503. switch (attr->attr) {
  504. case KVM_ARM_VCPU_PMU_V3_IRQ:
  505. case KVM_ARM_VCPU_PMU_V3_INIT:
  506. if (kvm_arm_support_pmu_v3() &&
  507. test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  508. return 0;
  509. }
  510. return -ENXIO;
  511. }