Skip to content

Commit

Permalink
perf/x86/intel/uncore: Move uncore_box_init() out of driver initializ…
Browse files Browse the repository at this point in the history
…ation

There were some issues about the uncore driver tried to access
non-existing boxes, which caused boot crashes. These issues have
been all fixed. But we should avoid boot failures if that ever
happens again.

This patch intends to prevent this kind of potential issues.
It moves uncore_box_init out of driver initialization. The box
will be initialized when it's first enabled.

Signed-off-by: Kan Liang <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Yan, Zheng <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
kliang2 authored and Ingo Molnar committed Jan 28, 2015
1 parent 4adca1c commit c05199e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
9 changes: 2 additions & 7 deletions arch/x86/kernel/cpu/perf_event_intel_uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
box->phys_id = phys_id;
box->pci_dev = pdev;
box->pmu = pmu;
uncore_box_init(box);
pci_set_drvdata(pdev, box);

raw_spin_lock(&uncore_box_lock);
Expand Down Expand Up @@ -1004,10 +1003,8 @@ static int uncore_cpu_starting(int cpu)
pmu = &type->pmus[j];
box = *per_cpu_ptr(pmu->box, cpu);
/* called by uncore_cpu_init? */
if (box && box->phys_id >= 0) {
uncore_box_init(box);
if (box && box->phys_id >= 0)
continue;
}

for_each_online_cpu(k) {
exist = *per_cpu_ptr(pmu->box, k);
Expand All @@ -1023,10 +1020,8 @@ static int uncore_cpu_starting(int cpu)
}
}

if (box) {
if (box)
box->phys_id = phys_id;
uncore_box_init(box);
}
}
}
return 0;
Expand Down
18 changes: 10 additions & 8 deletions arch/x86/kernel/cpu/perf_event_intel_uncore.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ static inline int uncore_num_counters(struct intel_uncore_box *box)
return box->pmu->type->num_counters;
}

static inline void uncore_box_init(struct intel_uncore_box *box)
{
if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) {
if (box->pmu->type->ops->init_box)
box->pmu->type->ops->init_box(box);
}
}

static inline void uncore_disable_box(struct intel_uncore_box *box)
{
if (box->pmu->type->ops->disable_box)
Expand All @@ -265,6 +273,8 @@ static inline void uncore_disable_box(struct intel_uncore_box *box)

static inline void uncore_enable_box(struct intel_uncore_box *box)
{
uncore_box_init(box);

if (box->pmu->type->ops->enable_box)
box->pmu->type->ops->enable_box(box);
}
Expand All @@ -287,14 +297,6 @@ static inline u64 uncore_read_counter(struct intel_uncore_box *box,
return box->pmu->type->ops->read_counter(box, event);
}

static inline void uncore_box_init(struct intel_uncore_box *box)
{
if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) {
if (box->pmu->type->ops->init_box)
box->pmu->type->ops->init_box(box);
}
}

static inline bool uncore_box_is_fake(struct intel_uncore_box *box)
{
return (box->phys_id < 0);
Expand Down

0 comments on commit c05199e

Please sign in to comment.