All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch
@ 2017-05-18  7:40 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2017-05-18  7:40 UTC (permalink / raw)
  To: wehuang; +Cc: kvm

Hello Wei Huang,

The patch 25462f7f5295: "KVM: x86/vPMU: Define kvm_pmu_ops to support
vPMU function dispatch" from Jun 19, 2015, leads to the following
static checker warning:

	arch/x86/kvm/pmu_intel.c:297 intel_pmu_refresh()
	warn: potential left shift more than type allows '0-32'

arch/x86/kvm/pmu_intel.c
   277          pmu->version = eax.split.version_id;
   278          if (!pmu->version)
   279                  return;
   280  
   281          pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters,
   282                                          INTEL_PMC_MAX_GENERIC);
                                                ^^^^^^^^^^^^^^^^^^^^^
We cap ->nr_arch_gp_counters at 32.

   283          pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1;
   284          pmu->available_event_types = ~entry->ebx &
   285                                          ((1ull << eax.split.mask_length) - 1);
   286  
   287          if (pmu->version == 1) {
   288                  pmu->nr_arch_fixed_counters = 0;
   289          } else {
   290                  pmu->nr_arch_fixed_counters =
   291                          min_t(int, edx.split.num_counters_fixed,
   292                                  INTEL_PMC_MAX_FIXED);
   293                  pmu->counter_bitmask[KVM_PMC_FIXED] =
   294                          ((u64)1 << edx.split.bit_width_fixed) - 1;
   295          }
   296  
   297          pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) |
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Potential shift wrapping bug.

   298                  (((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED);
   299          pmu->global_ctrl_mask = ~pmu->global_ctrl;
   300  
   301          entry = kvm_find_cpuid_entry(vcpu, 7, 0);
   302          if (entry &&
   303              (boot_cpu_has(X86_FEATURE_HLE) || boot_cpu_has(X86_FEATURE_RTM)) &&
   304              (entry->ebx & (X86_FEATURE_HLE|X86_FEATURE_RTM)))
   305                  pmu->reserved_bits ^= HSW_IN_TX|HSW_IN_TX_CHECKPOINTED;

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-18  7:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-18  7:40 [bug report] KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.