pmu.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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_check_overflow(struct kvm_vcpu *vcpu)
  179. {
  180. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  181. bool overflow = !!kvm_pmu_overflow_status(vcpu);
  182. if (pmu->irq_level == overflow)
  183. return;
  184. pmu->irq_level = overflow;
  185. if (likely(irqchip_in_kernel(vcpu->kvm))) {
  186. int ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
  187. pmu->irq_num, overflow);
  188. WARN_ON(ret);
  189. }
  190. }
  191. /**
  192. * kvm_pmu_overflow_set - set PMU overflow interrupt
  193. * @vcpu: The vcpu pointer
  194. * @val: the value guest writes to PMOVSSET register
  195. */
  196. void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val)
  197. {
  198. if (val == 0)
  199. return;
  200. vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= val;
  201. kvm_pmu_check_overflow(vcpu);
  202. }
  203. static void kvm_pmu_update_state(struct kvm_vcpu *vcpu)
  204. {
  205. if (!kvm_arm_pmu_v3_ready(vcpu))
  206. return;
  207. kvm_pmu_check_overflow(vcpu);
  208. }
  209. bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
  210. {
  211. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  212. struct kvm_sync_regs *sregs = &vcpu->run->s.regs;
  213. bool run_level = sregs->device_irq_level & KVM_ARM_DEV_PMU;
  214. if (likely(irqchip_in_kernel(vcpu->kvm)))
  215. return false;
  216. return pmu->irq_level != run_level;
  217. }
  218. /*
  219. * Reflect the PMU overflow interrupt output level into the kvm_run structure
  220. */
  221. void kvm_pmu_update_run(struct kvm_vcpu *vcpu)
  222. {
  223. struct kvm_sync_regs *regs = &vcpu->run->s.regs;
  224. /* Populate the timer bitmap for user space */
  225. regs->device_irq_level &= ~KVM_ARM_DEV_PMU;
  226. if (vcpu->arch.pmu.irq_level)
  227. regs->device_irq_level |= KVM_ARM_DEV_PMU;
  228. }
  229. /**
  230. * kvm_pmu_flush_hwstate - flush pmu state to cpu
  231. * @vcpu: The vcpu pointer
  232. *
  233. * Check if the PMU has overflowed while we were running in the host, and inject
  234. * an interrupt if that was the case.
  235. */
  236. void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu)
  237. {
  238. kvm_pmu_update_state(vcpu);
  239. }
  240. /**
  241. * kvm_pmu_sync_hwstate - sync pmu state from cpu
  242. * @vcpu: The vcpu pointer
  243. *
  244. * Check if the PMU has overflowed while we were running in the guest, and
  245. * inject an interrupt if that was the case.
  246. */
  247. void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu)
  248. {
  249. kvm_pmu_update_state(vcpu);
  250. }
  251. static inline struct kvm_vcpu *kvm_pmc_to_vcpu(struct kvm_pmc *pmc)
  252. {
  253. struct kvm_pmu *pmu;
  254. struct kvm_vcpu_arch *vcpu_arch;
  255. pmc -= pmc->idx;
  256. pmu = container_of(pmc, struct kvm_pmu, pmc[0]);
  257. vcpu_arch = container_of(pmu, struct kvm_vcpu_arch, pmu);
  258. return container_of(vcpu_arch, struct kvm_vcpu, arch);
  259. }
  260. /**
  261. * When perf event overflows, call kvm_pmu_overflow_set to set overflow status.
  262. */
  263. static void kvm_pmu_perf_overflow(struct perf_event *perf_event,
  264. struct perf_sample_data *data,
  265. struct pt_regs *regs)
  266. {
  267. struct kvm_pmc *pmc = perf_event->overflow_handler_context;
  268. struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
  269. int idx = pmc->idx;
  270. kvm_pmu_overflow_set(vcpu, BIT(idx));
  271. }
  272. /**
  273. * kvm_pmu_software_increment - do software increment
  274. * @vcpu: The vcpu pointer
  275. * @val: the value guest writes to PMSWINC register
  276. */
  277. void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val)
  278. {
  279. int i;
  280. u64 type, enable, reg;
  281. if (val == 0)
  282. return;
  283. enable = vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
  284. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++) {
  285. if (!(val & BIT(i)))
  286. continue;
  287. type = vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i)
  288. & ARMV8_PMU_EVTYPE_EVENT;
  289. if ((type == ARMV8_PMUV3_PERFCTR_SW_INCR)
  290. && (enable & BIT(i))) {
  291. reg = vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1;
  292. reg = lower_32_bits(reg);
  293. vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg;
  294. if (!reg)
  295. kvm_pmu_overflow_set(vcpu, BIT(i));
  296. }
  297. }
  298. }
  299. /**
  300. * kvm_pmu_handle_pmcr - handle PMCR register
  301. * @vcpu: The vcpu pointer
  302. * @val: the value guest writes to PMCR register
  303. */
  304. void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
  305. {
  306. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  307. struct kvm_pmc *pmc;
  308. u64 mask;
  309. int i;
  310. mask = kvm_pmu_valid_counter_mask(vcpu);
  311. if (val & ARMV8_PMU_PMCR_E) {
  312. kvm_pmu_enable_counter(vcpu,
  313. vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask);
  314. } else {
  315. kvm_pmu_disable_counter(vcpu, mask);
  316. }
  317. if (val & ARMV8_PMU_PMCR_C)
  318. kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
  319. if (val & ARMV8_PMU_PMCR_P) {
  320. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++)
  321. kvm_pmu_set_counter_value(vcpu, i, 0);
  322. }
  323. if (val & ARMV8_PMU_PMCR_LC) {
  324. pmc = &pmu->pmc[ARMV8_PMU_CYCLE_IDX];
  325. pmc->bitmask = 0xffffffffffffffffUL;
  326. }
  327. }
  328. static bool kvm_pmu_counter_is_enabled(struct kvm_vcpu *vcpu, u64 select_idx)
  329. {
  330. return (vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E) &&
  331. (vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & BIT(select_idx));
  332. }
  333. /**
  334. * kvm_pmu_set_counter_event_type - set selected counter to monitor some event
  335. * @vcpu: The vcpu pointer
  336. * @data: The data guest writes to PMXEVTYPER_EL0
  337. * @select_idx: The number of selected counter
  338. *
  339. * When OS accesses PMXEVTYPER_EL0, that means it wants to set a PMC to count an
  340. * event with given hardware event number. Here we call perf_event API to
  341. * emulate this action and create a kernel perf event for it.
  342. */
  343. void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
  344. u64 select_idx)
  345. {
  346. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  347. struct kvm_pmc *pmc = &pmu->pmc[select_idx];
  348. struct perf_event *event;
  349. struct perf_event_attr attr;
  350. u64 eventsel, counter;
  351. kvm_pmu_stop_counter(vcpu, pmc);
  352. eventsel = data & ARMV8_PMU_EVTYPE_EVENT;
  353. /* Software increment event does't need to be backed by a perf event */
  354. if (eventsel == ARMV8_PMUV3_PERFCTR_SW_INCR &&
  355. select_idx != ARMV8_PMU_CYCLE_IDX)
  356. return;
  357. memset(&attr, 0, sizeof(struct perf_event_attr));
  358. attr.type = PERF_TYPE_RAW;
  359. attr.size = sizeof(attr);
  360. attr.pinned = 1;
  361. attr.disabled = !kvm_pmu_counter_is_enabled(vcpu, select_idx);
  362. attr.exclude_user = data & ARMV8_PMU_EXCLUDE_EL0 ? 1 : 0;
  363. attr.exclude_kernel = data & ARMV8_PMU_EXCLUDE_EL1 ? 1 : 0;
  364. attr.exclude_hv = 1; /* Don't count EL2 events */
  365. attr.exclude_host = 1; /* Don't count host events */
  366. attr.config = (select_idx == ARMV8_PMU_CYCLE_IDX) ?
  367. ARMV8_PMUV3_PERFCTR_CPU_CYCLES : eventsel;
  368. counter = kvm_pmu_get_counter_value(vcpu, select_idx);
  369. /* The initial sample period (overflow count) of an event. */
  370. attr.sample_period = (-counter) & pmc->bitmask;
  371. event = perf_event_create_kernel_counter(&attr, -1, current,
  372. kvm_pmu_perf_overflow, pmc);
  373. if (IS_ERR(event)) {
  374. pr_err_once("kvm: pmu event creation failed %ld\n",
  375. PTR_ERR(event));
  376. return;
  377. }
  378. pmc->perf_event = event;
  379. }
  380. bool kvm_arm_support_pmu_v3(void)
  381. {
  382. /*
  383. * Check if HW_PERF_EVENTS are supported by checking the number of
  384. * hardware performance counters. This could ensure the presence of
  385. * a physical PMU and CONFIG_PERF_EVENT is selected.
  386. */
  387. return (perf_num_counters() > 0);
  388. }
  389. int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
  390. {
  391. if (!vcpu->arch.pmu.created)
  392. return 0;
  393. /*
  394. * A valid interrupt configuration for the PMU is either to have a
  395. * properly configured interrupt number and using an in-kernel
  396. * irqchip, or to neither set an IRQ nor create an in-kernel irqchip.
  397. */
  398. if (kvm_arm_pmu_irq_initialized(vcpu) != irqchip_in_kernel(vcpu->kvm))
  399. return -EINVAL;
  400. kvm_pmu_vcpu_reset(vcpu);
  401. vcpu->arch.pmu.ready = true;
  402. return 0;
  403. }
  404. static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
  405. {
  406. if (!kvm_arm_support_pmu_v3())
  407. return -ENODEV;
  408. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  409. return -ENXIO;
  410. if (vcpu->arch.pmu.created)
  411. return -EBUSY;
  412. if (irqchip_in_kernel(vcpu->kvm)) {
  413. /*
  414. * If using the PMU with an in-kernel virtual GIC
  415. * implementation, we require the GIC to be already
  416. * initialized when initializing the PMU.
  417. */
  418. if (!vgic_initialized(vcpu->kvm))
  419. return -ENODEV;
  420. if (!kvm_arm_pmu_irq_initialized(vcpu))
  421. return -ENXIO;
  422. }
  423. vcpu->arch.pmu.created = true;
  424. return 0;
  425. }
  426. /*
  427. * For one VM the interrupt type must be same for each vcpu.
  428. * As a PPI, the interrupt number is the same for all vcpus,
  429. * while as an SPI it must be a separate number per vcpu.
  430. */
  431. static bool pmu_irq_is_valid(struct kvm *kvm, int irq)
  432. {
  433. int i;
  434. struct kvm_vcpu *vcpu;
  435. kvm_for_each_vcpu(i, vcpu, kvm) {
  436. if (!kvm_arm_pmu_irq_initialized(vcpu))
  437. continue;
  438. if (irq_is_ppi(irq)) {
  439. if (vcpu->arch.pmu.irq_num != irq)
  440. return false;
  441. } else {
  442. if (vcpu->arch.pmu.irq_num == irq)
  443. return false;
  444. }
  445. }
  446. return true;
  447. }
  448. int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  449. {
  450. switch (attr->attr) {
  451. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  452. int __user *uaddr = (int __user *)(long)attr->addr;
  453. int irq;
  454. if (!irqchip_in_kernel(vcpu->kvm))
  455. return -EINVAL;
  456. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  457. return -ENODEV;
  458. if (get_user(irq, uaddr))
  459. return -EFAULT;
  460. /* The PMU overflow interrupt can be a PPI or a valid SPI. */
  461. if (!(irq_is_ppi(irq) || vgic_valid_spi(vcpu->kvm, irq)))
  462. return -EINVAL;
  463. if (!pmu_irq_is_valid(vcpu->kvm, irq))
  464. return -EINVAL;
  465. if (kvm_arm_pmu_irq_initialized(vcpu))
  466. return -EBUSY;
  467. kvm_debug("Set kvm ARM PMU irq: %d\n", irq);
  468. vcpu->arch.pmu.irq_num = irq;
  469. return 0;
  470. }
  471. case KVM_ARM_VCPU_PMU_V3_INIT:
  472. return kvm_arm_pmu_v3_init(vcpu);
  473. }
  474. return -ENXIO;
  475. }
  476. int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  477. {
  478. switch (attr->attr) {
  479. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  480. int __user *uaddr = (int __user *)(long)attr->addr;
  481. int irq;
  482. if (!irqchip_in_kernel(vcpu->kvm))
  483. return -EINVAL;
  484. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  485. return -ENODEV;
  486. if (!kvm_arm_pmu_irq_initialized(vcpu))
  487. return -ENXIO;
  488. irq = vcpu->arch.pmu.irq_num;
  489. return put_user(irq, uaddr);
  490. }
  491. }
  492. return -ENXIO;
  493. }
  494. int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  495. {
  496. switch (attr->attr) {
  497. case KVM_ARM_VCPU_PMU_V3_IRQ:
  498. case KVM_ARM_VCPU_PMU_V3_INIT:
  499. if (kvm_arm_support_pmu_v3() &&
  500. test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  501. return 0;
  502. }
  503. return -ENXIO;
  504. }