pmu.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. if (!(__vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E))
  273. return;
  274. enable = __vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
  275. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++) {
  276. if (!(val & BIT(i)))
  277. continue;
  278. type = __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i)
  279. & ARMV8_PMU_EVTYPE_EVENT;
  280. if ((type == ARMV8_PMUV3_PERFCTR_SW_INCR)
  281. && (enable & BIT(i))) {
  282. reg = __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1;
  283. reg = lower_32_bits(reg);
  284. __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg;
  285. if (!reg)
  286. __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(i);
  287. }
  288. }
  289. }
  290. /**
  291. * kvm_pmu_handle_pmcr - handle PMCR register
  292. * @vcpu: The vcpu pointer
  293. * @val: the value guest writes to PMCR register
  294. */
  295. void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
  296. {
  297. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  298. struct kvm_pmc *pmc;
  299. u64 mask;
  300. int i;
  301. mask = kvm_pmu_valid_counter_mask(vcpu);
  302. if (val & ARMV8_PMU_PMCR_E) {
  303. kvm_pmu_enable_counter(vcpu,
  304. __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask);
  305. } else {
  306. kvm_pmu_disable_counter(vcpu, mask);
  307. }
  308. if (val & ARMV8_PMU_PMCR_C)
  309. kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
  310. if (val & ARMV8_PMU_PMCR_P) {
  311. for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++)
  312. kvm_pmu_set_counter_value(vcpu, i, 0);
  313. }
  314. if (val & ARMV8_PMU_PMCR_LC) {
  315. pmc = &pmu->pmc[ARMV8_PMU_CYCLE_IDX];
  316. pmc->bitmask = 0xffffffffffffffffUL;
  317. }
  318. }
  319. static bool kvm_pmu_counter_is_enabled(struct kvm_vcpu *vcpu, u64 select_idx)
  320. {
  321. return (__vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E) &&
  322. (__vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & BIT(select_idx));
  323. }
  324. /**
  325. * kvm_pmu_set_counter_event_type - set selected counter to monitor some event
  326. * @vcpu: The vcpu pointer
  327. * @data: The data guest writes to PMXEVTYPER_EL0
  328. * @select_idx: The number of selected counter
  329. *
  330. * When OS accesses PMXEVTYPER_EL0, that means it wants to set a PMC to count an
  331. * event with given hardware event number. Here we call perf_event API to
  332. * emulate this action and create a kernel perf event for it.
  333. */
  334. void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
  335. u64 select_idx)
  336. {
  337. struct kvm_pmu *pmu = &vcpu->arch.pmu;
  338. struct kvm_pmc *pmc = &pmu->pmc[select_idx];
  339. struct perf_event *event;
  340. struct perf_event_attr attr;
  341. u64 eventsel, counter;
  342. kvm_pmu_stop_counter(vcpu, pmc);
  343. eventsel = data & ARMV8_PMU_EVTYPE_EVENT;
  344. /* Software increment event does't need to be backed by a perf event */
  345. if (eventsel == ARMV8_PMUV3_PERFCTR_SW_INCR &&
  346. select_idx != ARMV8_PMU_CYCLE_IDX)
  347. return;
  348. memset(&attr, 0, sizeof(struct perf_event_attr));
  349. attr.type = PERF_TYPE_RAW;
  350. attr.size = sizeof(attr);
  351. attr.pinned = 1;
  352. attr.disabled = !kvm_pmu_counter_is_enabled(vcpu, select_idx);
  353. attr.exclude_user = data & ARMV8_PMU_EXCLUDE_EL0 ? 1 : 0;
  354. attr.exclude_kernel = data & ARMV8_PMU_EXCLUDE_EL1 ? 1 : 0;
  355. attr.exclude_hv = 1; /* Don't count EL2 events */
  356. attr.exclude_host = 1; /* Don't count host events */
  357. attr.config = (select_idx == ARMV8_PMU_CYCLE_IDX) ?
  358. ARMV8_PMUV3_PERFCTR_CPU_CYCLES : eventsel;
  359. counter = kvm_pmu_get_counter_value(vcpu, select_idx);
  360. /* The initial sample period (overflow count) of an event. */
  361. attr.sample_period = (-counter) & pmc->bitmask;
  362. event = perf_event_create_kernel_counter(&attr, -1, current,
  363. kvm_pmu_perf_overflow, pmc);
  364. if (IS_ERR(event)) {
  365. pr_err_once("kvm: pmu event creation failed %ld\n",
  366. PTR_ERR(event));
  367. return;
  368. }
  369. pmc->perf_event = event;
  370. }
  371. bool kvm_arm_support_pmu_v3(void)
  372. {
  373. /*
  374. * Check if HW_PERF_EVENTS are supported by checking the number of
  375. * hardware performance counters. This could ensure the presence of
  376. * a physical PMU and CONFIG_PERF_EVENT is selected.
  377. */
  378. return (perf_num_counters() > 0);
  379. }
  380. int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
  381. {
  382. if (!vcpu->arch.pmu.created)
  383. return 0;
  384. /*
  385. * A valid interrupt configuration for the PMU is either to have a
  386. * properly configured interrupt number and using an in-kernel
  387. * irqchip, or to not have an in-kernel GIC and not set an IRQ.
  388. */
  389. if (irqchip_in_kernel(vcpu->kvm)) {
  390. int irq = vcpu->arch.pmu.irq_num;
  391. if (!kvm_arm_pmu_irq_initialized(vcpu))
  392. return -EINVAL;
  393. /*
  394. * If we are using an in-kernel vgic, at this point we know
  395. * the vgic will be initialized, so we can check the PMU irq
  396. * number against the dimensions of the vgic and make sure
  397. * it's valid.
  398. */
  399. if (!irq_is_ppi(irq) && !vgic_valid_spi(vcpu->kvm, irq))
  400. return -EINVAL;
  401. } else if (kvm_arm_pmu_irq_initialized(vcpu)) {
  402. return -EINVAL;
  403. }
  404. kvm_pmu_vcpu_reset(vcpu);
  405. vcpu->arch.pmu.ready = true;
  406. return 0;
  407. }
  408. static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
  409. {
  410. if (!kvm_arm_support_pmu_v3())
  411. return -ENODEV;
  412. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  413. return -ENXIO;
  414. if (vcpu->arch.pmu.created)
  415. return -EBUSY;
  416. if (irqchip_in_kernel(vcpu->kvm)) {
  417. int ret;
  418. /*
  419. * If using the PMU with an in-kernel virtual GIC
  420. * implementation, we require the GIC to be already
  421. * initialized when initializing the PMU.
  422. */
  423. if (!vgic_initialized(vcpu->kvm))
  424. return -ENODEV;
  425. if (!kvm_arm_pmu_irq_initialized(vcpu))
  426. return -ENXIO;
  427. ret = kvm_vgic_set_owner(vcpu, vcpu->arch.pmu.irq_num,
  428. &vcpu->arch.pmu);
  429. if (ret)
  430. return ret;
  431. }
  432. vcpu->arch.pmu.created = true;
  433. return 0;
  434. }
  435. /*
  436. * For one VM the interrupt type must be same for each vcpu.
  437. * As a PPI, the interrupt number is the same for all vcpus,
  438. * while as an SPI it must be a separate number per vcpu.
  439. */
  440. static bool pmu_irq_is_valid(struct kvm *kvm, int irq)
  441. {
  442. int i;
  443. struct kvm_vcpu *vcpu;
  444. kvm_for_each_vcpu(i, vcpu, kvm) {
  445. if (!kvm_arm_pmu_irq_initialized(vcpu))
  446. continue;
  447. if (irq_is_ppi(irq)) {
  448. if (vcpu->arch.pmu.irq_num != irq)
  449. return false;
  450. } else {
  451. if (vcpu->arch.pmu.irq_num == irq)
  452. return false;
  453. }
  454. }
  455. return true;
  456. }
  457. int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  458. {
  459. switch (attr->attr) {
  460. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  461. int __user *uaddr = (int __user *)(long)attr->addr;
  462. int irq;
  463. if (!irqchip_in_kernel(vcpu->kvm))
  464. return -EINVAL;
  465. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  466. return -ENODEV;
  467. if (get_user(irq, uaddr))
  468. return -EFAULT;
  469. /* The PMU overflow interrupt can be a PPI or a valid SPI. */
  470. if (!(irq_is_ppi(irq) || irq_is_spi(irq)))
  471. return -EINVAL;
  472. if (!pmu_irq_is_valid(vcpu->kvm, irq))
  473. return -EINVAL;
  474. if (kvm_arm_pmu_irq_initialized(vcpu))
  475. return -EBUSY;
  476. kvm_debug("Set kvm ARM PMU irq: %d\n", irq);
  477. vcpu->arch.pmu.irq_num = irq;
  478. return 0;
  479. }
  480. case KVM_ARM_VCPU_PMU_V3_INIT:
  481. return kvm_arm_pmu_v3_init(vcpu);
  482. }
  483. return -ENXIO;
  484. }
  485. int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  486. {
  487. switch (attr->attr) {
  488. case KVM_ARM_VCPU_PMU_V3_IRQ: {
  489. int __user *uaddr = (int __user *)(long)attr->addr;
  490. int irq;
  491. if (!irqchip_in_kernel(vcpu->kvm))
  492. return -EINVAL;
  493. if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  494. return -ENODEV;
  495. if (!kvm_arm_pmu_irq_initialized(vcpu))
  496. return -ENXIO;
  497. irq = vcpu->arch.pmu.irq_num;
  498. return put_user(irq, uaddr);
  499. }
  500. }
  501. return -ENXIO;
  502. }
  503. int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
  504. {
  505. switch (attr->attr) {
  506. case KVM_ARM_VCPU_PMU_V3_IRQ:
  507. case KVM_ARM_VCPU_PMU_V3_INIT:
  508. if (kvm_arm_support_pmu_v3() &&
  509. test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features))
  510. return 0;
  511. }
  512. return -ENXIO;
  513. }