File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -348,22 +348,34 @@ int kvm_pmu_is_valid_msr_idx(struct kvm_vcpu *vcpu, unsigned idx)
348
348
(fixed && idx >= pmu -> nr_arch_fixed_counters );
349
349
}
350
350
351
- int kvm_pmu_rdpmc (struct kvm_vcpu * vcpu , unsigned idx , u64 * data )
351
+ static struct kvm_pmc * kvm_pmu_msr_idx_to_pmc (struct kvm_vcpu * vcpu ,
352
+ unsigned idx )
352
353
{
353
354
struct kvm_pmu * pmu = vcpu_to_pmu (vcpu );
354
- bool fast_mode = idx & (1u << 31 );
355
355
bool fixed = idx & (1u << 30 );
356
356
struct kvm_pmc * counters ;
357
- u64 ctr_val ;
358
357
359
358
idx &= ~(3u << 30 );
360
359
if (!fixed && idx >= pmu -> nr_arch_gp_counters )
361
- return 1 ;
360
+ return NULL ;
362
361
if (fixed && idx >= pmu -> nr_arch_fixed_counters )
363
- return 1 ;
362
+ return NULL ;
364
363
counters = fixed ? pmu -> fixed_counters : pmu -> gp_counters ;
365
364
366
- ctr_val = pmc_read_counter (& counters [idx ]);
365
+ return & counters [idx ];
366
+ }
367
+
368
+ int kvm_pmu_rdpmc (struct kvm_vcpu * vcpu , unsigned idx , u64 * data )
369
+ {
370
+ bool fast_mode = idx & (1u << 31 );
371
+ struct kvm_pmc * pmc ;
372
+ u64 ctr_val ;
373
+
374
+ pmc = kvm_pmu_msr_idx_to_pmc (vcpu , idx );
375
+ if (!pmc )
376
+ return 1 ;
377
+
378
+ ctr_val = pmc_read_counter (pmc );
367
379
if (fast_mode )
368
380
ctr_val = (u32 )ctr_val ;
369
381
You can’t perform that action at this time.
0 commit comments