Skip to content

Commit 4e1db5e

Browse files
committed
Merge branch 'x86-mce-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-mce-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: apic, amd: Make firmware bug messages more meaningful mce, amd: Remove goto in threshold_create_device() mce, amd: Add helper functions to setup APIC mce, amd: Shorten local variables mci_misc_{hi,lo} mce, amd: Implement mce_threshold_block_init() helper function
2 parents 37d9a8c + eb48c9c commit 4e1db5e

3 files changed

Lines changed: 86 additions & 65 deletions

File tree

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,18 @@ int setup_APIC_eilvt(u8 offset, u8 vector, u8 msg_type, u8 mask)
431431
reserved = reserve_eilvt_offset(offset, new);
432432

433433
if (reserved != new) {
434-
pr_err(FW_BUG "cpu %d, try to setup vector 0x%x, but "
435-
"vector 0x%x was already reserved by another core, "
436-
"APIC%lX=0x%x\n",
437-
smp_processor_id(), new, reserved, reg, old);
434+
pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for "
435+
"vector 0x%x, but the register is already in use for "
436+
"vector 0x%x on another cpu\n",
437+
smp_processor_id(), reg, offset, new, reserved);
438438
return -EINVAL;
439439
}
440440

441441
if (!eilvt_entry_is_changeable(old, new)) {
442-
pr_err(FW_BUG "cpu %d, try to setup vector 0x%x but "
443-
"register already in use, APIC%lX=0x%x\n",
444-
smp_processor_id(), new, reg, old);
442+
pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for "
443+
"vector 0x%x, but the register is already in use for "
444+
"vector 0x%x on this cpu\n",
445+
smp_processor_id(), reg, offset, new, old);
445446
return -EBUSY;
446447
}
447448

‎arch/x86/kernel/cpu/mcheck/mce_amd.c‎

Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include <asm/mce.h>
3232
#include <asm/msr.h>
3333

34-
#define PFX "mce_threshold: "
35-
#define VERSION "version 1.1.1"
3634
#define NR_BANKS 6
3735
#define NR_BLOCKS 9
3836
#define THRESHOLD_MAX 0xFFF
@@ -59,12 +57,6 @@ struct threshold_block {
5957
struct list_head miscj;
6058
};
6159

62-
/* defaults used early on boot */
63-
static struct threshold_block threshold_defaults = {
64-
.interrupt_enable = 0,
65-
.threshold_limit = THRESHOLD_MAX,
66-
};
67-
6860
struct threshold_bank {
6961
struct kobject *kobj;
7062
struct threshold_block *blocks;
@@ -89,50 +81,101 @@ static void amd_threshold_interrupt(void);
8981
struct thresh_restart {
9082
struct threshold_block *b;
9183
int reset;
84+
int set_lvt_off;
85+
int lvt_off;
9286
u16 old_limit;
9387
};
9488

89+
static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
90+
{
91+
int msr = (hi & MASK_LVTOFF_HI) >> 20;
92+
93+
if (apic < 0) {
94+
pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt "
95+
"for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu,
96+
b->bank, b->block, b->address, hi, lo);
97+
return 0;
98+
}
99+
100+
if (apic != msr) {
101+
pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d "
102+
"for bank %d, block %d (MSR%08X=0x%x%08x)\n",
103+
b->cpu, apic, b->bank, b->block, b->address, hi, lo);
104+
return 0;
105+
}
106+
107+
return 1;
108+
};
109+
95110
/* must be called with correct cpu affinity */
96111
/* Called via smp_call_function_single() */
97112
static void threshold_restart_bank(void *_tr)
98113
{
99114
struct thresh_restart *tr = _tr;
100-
u32 mci_misc_hi, mci_misc_lo;
115+
u32 hi, lo;
101116

102-
rdmsr(tr->b->address, mci_misc_lo, mci_misc_hi);
117+
rdmsr(tr->b->address, lo, hi);
103118

104-
if (tr->b->threshold_limit < (mci_misc_hi & THRESHOLD_MAX))
119+
if (tr->b->threshold_limit < (hi & THRESHOLD_MAX))
105120
tr->reset = 1; /* limit cannot be lower than err count */
106121

107122
if (tr->reset) { /* reset err count and overflow bit */
108-
mci_misc_hi =
109-
(mci_misc_hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) |
123+
hi =
124+
(hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) |
110125
(THRESHOLD_MAX - tr->b->threshold_limit);
111126
} else if (tr->old_limit) { /* change limit w/o reset */
112-
int new_count = (mci_misc_hi & THRESHOLD_MAX) +
127+
int new_count = (hi & THRESHOLD_MAX) +
113128
(tr->old_limit - tr->b->threshold_limit);
114129

115-
mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) |
130+
hi = (hi & ~MASK_ERR_COUNT_HI) |
116131
(new_count & THRESHOLD_MAX);
117132
}
118133

134+
if (tr->set_lvt_off) {
135+
if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
136+
/* set new lvt offset */
137+
hi &= ~MASK_LVTOFF_HI;
138+
hi |= tr->lvt_off << 20;
139+
}
140+
}
141+
119142
tr->b->interrupt_enable ?
120-
(mci_misc_hi = (mci_misc_hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) :
121-
(mci_misc_hi &= ~MASK_INT_TYPE_HI);
143+
(hi = (hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) :
144+
(hi &= ~MASK_INT_TYPE_HI);
122145

123-
mci_misc_hi |= MASK_COUNT_EN_HI;
124-
wrmsr(tr->b->address, mci_misc_lo, mci_misc_hi);
146+
hi |= MASK_COUNT_EN_HI;
147+
wrmsr(tr->b->address, lo, hi);
148+
}
149+
150+
static void mce_threshold_block_init(struct threshold_block *b, int offset)
151+
{
152+
struct thresh_restart tr = {
153+
.b = b,
154+
.set_lvt_off = 1,
155+
.lvt_off = offset,
156+
};
157+
158+
b->threshold_limit = THRESHOLD_MAX;
159+
threshold_restart_bank(&tr);
160+
};
161+
162+
static int setup_APIC_mce(int reserved, int new)
163+
{
164+
if (reserved < 0 && !setup_APIC_eilvt(new, THRESHOLD_APIC_VECTOR,
165+
APIC_EILVT_MSG_FIX, 0))
166+
return new;
167+
168+
return reserved;
125169
}
126170

127171
/* cpu init entry point, called from mce.c with preempt off */
128172
void mce_amd_feature_init(struct cpuinfo_x86 *c)
129173
{
174+
struct threshold_block b;
130175
unsigned int cpu = smp_processor_id();
131176
u32 low = 0, high = 0, address = 0;
132177
unsigned int bank, block;
133-
struct thresh_restart tr;
134-
int lvt_off = -1;
135-
u8 offset;
178+
int offset = -1;
136179

137180
for (bank = 0; bank < NR_BANKS; ++bank) {
138181
for (block = 0; block < NR_BLOCKS; ++block) {
@@ -163,39 +206,16 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
163206
if (shared_bank[bank] && c->cpu_core_id)
164207
break;
165208
#endif
166-
offset = (high & MASK_LVTOFF_HI) >> 20;
167-
if (lvt_off < 0) {
168-
if (setup_APIC_eilvt(offset,
169-
THRESHOLD_APIC_VECTOR,
170-
APIC_EILVT_MSG_FIX, 0)) {
171-
pr_err(FW_BUG "cpu %d, failed to "
172-
"setup threshold interrupt "
173-
"for bank %d, block %d "
174-
"(MSR%08X=0x%x%08x)",
175-
smp_processor_id(), bank, block,
176-
address, high, low);
177-
continue;
178-
}
179-
lvt_off = offset;
180-
} else if (lvt_off != offset) {
181-
pr_err(FW_BUG "cpu %d, invalid threshold "
182-
"interrupt offset %d for bank %d,"
183-
"block %d (MSR%08X=0x%x%08x)",
184-
smp_processor_id(), lvt_off, bank,
185-
block, address, high, low);
186-
continue;
187-
}
188-
189-
high &= ~MASK_LVTOFF_HI;
190-
high |= lvt_off << 20;
191-
wrmsr(address, low, high);
209+
offset = setup_APIC_mce(offset,
210+
(high & MASK_LVTOFF_HI) >> 20);
192211

193-
threshold_defaults.address = address;
194-
tr.b = &threshold_defaults;
195-
tr.reset = 0;
196-
tr.old_limit = 0;
197-
threshold_restart_bank(&tr);
212+
memset(&b, 0, sizeof(b));
213+
b.cpu = cpu;
214+
b.bank = bank;
215+
b.block = block;
216+
b.address = address;
198217

218+
mce_threshold_block_init(&b, offset);
199219
mce_threshold_vector = amd_threshold_interrupt;
200220
}
201221
}
@@ -298,9 +318,8 @@ store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
298318

299319
b->interrupt_enable = !!new;
300320

321+
memset(&tr, 0, sizeof(tr));
301322
tr.b = b;
302-
tr.reset = 0;
303-
tr.old_limit = 0;
304323

305324
smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
306325

@@ -321,10 +340,10 @@ store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
321340
if (new < 1)
322341
new = 1;
323342

343+
memset(&tr, 0, sizeof(tr));
324344
tr.old_limit = b->threshold_limit;
325345
b->threshold_limit = new;
326346
tr.b = b;
327-
tr.reset = 0;
328347

329348
smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
330349

@@ -603,9 +622,9 @@ static __cpuinit int threshold_create_device(unsigned int cpu)
603622
continue;
604623
err = threshold_create_bank(cpu, bank);
605624
if (err)
606-
goto out;
625+
return err;
607626
}
608-
out:
627+
609628
return err;
610629
}
611630

‎arch/x86/oprofile/op_model_amd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ static int force_ibs_eilvt_setup(void)
610610
ret = setup_ibs_ctl(i);
611611
if (ret)
612612
return ret;
613+
pr_err(FW_BUG "using offset %d for IBS interrupts\n", i);
613614
return 0;
614615
}
615616

0 commit comments

Comments
 (0)