-
Notifications
You must be signed in to change notification settings - Fork 82
/
ras-mc-handler.c
304 lines (253 loc) · 7.53 KB
/
ras-mc-handler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2013 Mauro Carvalho Chehab <[email protected]>
*/
#define _GNU_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <traceevent/kbuffer.h>
#include <unistd.h>
#include "ras-logger.h"
#include "ras-mc-handler.h"
#include "ras-page-isolation.h"
#include "ras-report.h"
#include "trigger.h"
#include "types.h"
#define MAX_ENV 30
static const char *mc_ce_trigger = NULL;
static const char *mc_ue_trigger = NULL;
void mc_event_trigger_setup(void)
{
const char *trigger;
trigger = getenv("MC_CE_TRIGGER");
if (trigger && strcmp(trigger, "")) {
mc_ce_trigger = trigger_check(trigger);
if (!mc_ce_trigger) {
log(ALL, LOG_ERR,
"Cannot access mc_event ce trigger `%s`\n",
trigger);
} else {
log(ALL, LOG_INFO,
"Setup mc_event ce trigger `%s`\n",
trigger);
}
}
trigger = getenv("MC_UE_TRIGGER");
if (trigger && strcmp(trigger, "")) {
mc_ue_trigger = trigger_check(trigger);
if (!mc_ue_trigger) {
log(ALL, LOG_ERR,
"Cannot access mc_event ue trigger `%s`\n",
trigger);
} else {
log(ALL, LOG_INFO,
"Setup mc_event ue trigger `%s`\n",
trigger);
}
}
}
static void run_mc_trigger(struct ras_mc_event *ev, const char *mc_trigger)
{
char *env[MAX_ENV];
int ei = 0;
int i;
if (asprintf(&env[ei++], "PATH=%s", getenv("PATH") ?: "/sbin:/usr/sbin:/bin:/usr/bin") < 0)
goto free;
if (asprintf(&env[ei++], "TIMESTAMP=%s", ev->timestamp) < 0)
goto free;
if (asprintf(&env[ei++], "COUNT=%d", ev->error_count) < 0)
goto free;
if (asprintf(&env[ei++], "TYPE=%s", ev->error_type) < 0)
goto free;
if (asprintf(&env[ei++], "MESSAGE=%s", ev->msg) < 0)
goto free;
if (asprintf(&env[ei++], "LABEL=%s", ev->label) < 0)
goto free;
if (asprintf(&env[ei++], "MC_INDEX=%d", ev->mc_index) < 0)
goto free;
if (asprintf(&env[ei++], "TOP_LAYER=%d", ev->top_layer) < 0)
goto free;
if (asprintf(&env[ei++], "MIDDLE_LAYER=%d", ev->middle_layer) < 0)
goto free;
if (asprintf(&env[ei++], "LOWER_LAYER=%d", ev->lower_layer) < 0)
goto free;
if (asprintf(&env[ei++], "ADDRESS=%llx", ev->address) < 0)
goto free;
if (asprintf(&env[ei++], "GRAIN=%lld", ev->grain) < 0)
goto free;
if (asprintf(&env[ei++], "SYNDROME=%llx", ev->syndrome) < 0)
goto free;
if (asprintf(&env[ei++], "DRIVER_DETAIL=%s", ev->driver_detail) < 0)
goto free;
env[ei] = NULL;
assert(ei < MAX_ENV);
run_trigger(mc_trigger, NULL, env, "mc_event");
free:
for (i = 0; i < ei; i++)
free(env[i]);
}
int ras_mc_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len;
unsigned long long val;
struct ras_events *ras = context;
time_t now;
struct tm *tm;
struct ras_mc_event ev;
int parsed_fields = 0;
/*
* Newer kernels (3.10-rc1 or upper) provide an uptime clock.
* On previous kernels, the way to properly generate an event would
* be to inject a fake one, measure its timestamp and diff it against
* gettimeofday. We won't do it here. Instead, let's use uptime,
* falling-back to the event report's time, if "uptime" clock is
* not available (legacy kernels).
*/
if (ras->use_uptime)
now = record->ts / user_hz + ras->uptime_diff;
else
now = time(NULL);
tm = localtime(&now);
if (tm)
strftime(ev.timestamp, sizeof(ev.timestamp),
"%Y-%m-%d %H:%M:%S %z", tm);
trace_seq_printf(s, "%s ", ev.timestamp);
if (tep_get_field_val(s, event, "error_count", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.error_count = val;
trace_seq_printf(s, "%d ", ev.error_count);
if (tep_get_field_val(s, event, "error_type", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
switch (val) {
case HW_EVENT_ERR_CORRECTED:
ev.error_type = "Corrected";
break;
case HW_EVENT_ERR_UNCORRECTED:
ev.error_type = "Uncorrected";
break;
case HW_EVENT_ERR_FATAL:
ev.error_type = "Fatal";
break;
case HW_EVENT_ERR_INFO:
default:
ev.error_type = "Info";
}
trace_seq_puts(s, ev.error_type);
if (ev.error_count > 1)
trace_seq_puts(s, " errors:");
else
trace_seq_puts(s, " error:");
ev.msg = tep_get_field_raw(s, event, "msg", record, &len, 1);
if (!ev.msg)
goto parse_error;
parsed_fields++;
if (*ev.msg) {
trace_seq_puts(s, " ");
trace_seq_puts(s, ev.msg);
}
ev.label = tep_get_field_raw(s, event, "label", record, &len, 1);
if (!ev.label)
goto parse_error;
parsed_fields++;
if (*ev.label) {
trace_seq_puts(s, " on ");
trace_seq_puts(s, ev.label);
}
trace_seq_puts(s, " (");
if (tep_get_field_val(s, event, "mc_index", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.mc_index = val;
trace_seq_printf(s, "mc: %d", ev.mc_index);
if (tep_get_field_val(s, event, "top_layer", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.top_layer = (signed char)val;
if (tep_get_field_val(s, event, "middle_layer", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.middle_layer = (signed char)val;
if (tep_get_field_val(s, event, "lower_layer", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.lower_layer = (signed char)val;
if (ev.top_layer >= 0 || ev.middle_layer >= 0 || ev.lower_layer >= 0) {
if (ev.lower_layer >= 0)
trace_seq_printf(s, " location: %d:%d:%d",
ev.top_layer, ev.middle_layer, ev.lower_layer);
else if (ev.middle_layer >= 0)
trace_seq_printf(s, " location: %d:%d",
ev.top_layer, ev.middle_layer);
else
trace_seq_printf(s, " location: %d", ev.top_layer);
}
if (tep_get_field_val(s, event, "address", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.address = val;
if (ev.address)
trace_seq_printf(s, " address: 0x%08llx", ev.address);
if (tep_get_field_val(s, event, "grain_bits", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.grain = val;
trace_seq_printf(s, " grain: %lld", ev.grain);
if (tep_get_field_val(s, event, "syndrome", record, &val, 1) < 0)
goto parse_error;
parsed_fields++;
ev.syndrome = val;
if (val)
trace_seq_printf(s, " syndrome: 0x%08llx", ev.syndrome);
ev.driver_detail = tep_get_field_raw(s, event, "driver_detail", record,
&len, 1);
if (!ev.driver_detail)
goto parse_error;
parsed_fields++;
if (*ev.driver_detail) {
trace_seq_puts(s, " ");
trace_seq_puts(s, ev.driver_detail);
}
trace_seq_puts(s, ")");
/* Insert data into the SGBD */
ras_store_mc_event(ras, &ev);
#ifdef HAVE_MEMORY_CE_PFA
/* Account page corrected errors */
if (!strcmp(ev.error_type, "Corrected"))
ras_record_page_error(ev.address, ev.error_count, now);
#endif
#ifdef HAVE_MEMORY_ROW_CE_PFA
/* Account row corrected errors */
struct timespec ts;
clockid_t clk_id = CLOCK_MONOTONIC;
// A fault occurs, but the fault error_count BIOS reports sometimes is 0.
// This is a bug in the BIOS.
// We set the value to 1
// even if the error_count is reported 0.
if (ev.error_count == 0)
ev.error_count = 1;
if (clock_gettime(clk_id, &ts) == 0 && !strcmp(ev.error_type, "Corrected"))
ras_record_row_error(ev.driver_detail, ev.error_count,
ts.tv_sec, ev.address);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_mc_event(ras, &ev);
#endif
if (mc_ce_trigger && !strcmp(ev.error_type, "Corrected"))
run_mc_trigger(&ev, mc_ce_trigger);
if (mc_ue_trigger && !strcmp(ev.error_type, "Uncorrected"))
run_mc_trigger(&ev, mc_ue_trigger);
return 0;
parse_error:
/* FIXME: add a logic here to also store parse errors to SDBD */
log(ALL, LOG_ERR, "MC error handler: can't parse field #%d\n",
parsed_fields);
return 0;
}