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
|
/*
* Copyright (C) 2014 Tony Luck <tony.luck@intel.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <traceevent/kbuffer.h>
#include "ras-extlog-handler.h"
#include "ras-record.h"
#include "ras-logger.h"
#include "ras-report.h"
static char *err_type(int etype)
{
switch (etype) {
case 0: return "unknown";
case 1: return "no error";
case 2: return "single-bit ECC";
case 3: return "multi-bit ECC";
case 4: return "single-symbol chipkill ECC";
case 5: return "multi-symbol chipkill ECC";
case 6: return "master abort";
case 7: return "target abort";
case 8: return "parity error";
case 9: return "watchdog timeout";
case 10: return "invalid address";
case 11: return "mirror Broken";
case 12: return "memory sparing";
case 13: return "scrub corrected error";
case 14: return "scrub uncorrected error";
case 15: return "physical memory map-out event";
}
return "unknown-type";
}
static char *err_severity(int severity)
{
switch (severity) {
case 0: return "recoverable";
case 1: return "fatal";
case 2: return "corrected";
case 3: return "informational";
}
return "unknown-severity";
}
static unsigned long long err_mask(int lsb)
{
if (lsb == 0xff)
return ~0ull;
return ~((1ull << lsb) - 1);
}
#define CPER_MEM_VALID_NODE 0x0008
#define CPER_MEM_VALID_CARD 0x0010
#define CPER_MEM_VALID_MODULE 0x0020
#define CPER_MEM_VALID_BANK 0x0040
#define CPER_MEM_VALID_DEVICE 0x0080
#define CPER_MEM_VALID_ROW 0x0100
#define CPER_MEM_VALID_COLUMN 0x0200
#define CPER_MEM_VALID_BIT_POSITION 0x0400
#define CPER_MEM_VALID_REQUESTOR_ID 0x0800
#define CPER_MEM_VALID_RESPONDER_ID 0x1000
#define CPER_MEM_VALID_TARGET_ID 0x2000
#define CPER_MEM_VALID_RANK_NUMBER 0x8000
#define CPER_MEM_VALID_CARD_HANDLE 0x10000
#define CPER_MEM_VALID_MODULE_HANDLE 0x20000
struct cper_mem_err_compact {
unsigned long long validation_bits;
unsigned short node;
unsigned short card;
unsigned short module;
unsigned short bank;
unsigned short device;
unsigned short row;
unsigned short column;
unsigned short bit_pos;
unsigned long long requestor_id;
unsigned long long responder_id;
unsigned long long target_id;
unsigned short rank;
unsigned short mem_array_handle;
unsigned short mem_dev_handle;
};
static char *err_cper_data(const char *c)
{
const struct cper_mem_err_compact *cpd = (struct cper_mem_err_compact *)c;
static char buf[256];
char *p = buf;
if (cpd->validation_bits == 0)
return "";
p += sprintf(p, " (");
if (cpd->validation_bits & CPER_MEM_VALID_NODE)
p += sprintf(p, "node: %d ", cpd->node);
if (cpd->validation_bits & CPER_MEM_VALID_CARD)
p += sprintf(p, "card: %d ", cpd->card);
if (cpd->validation_bits & CPER_MEM_VALID_MODULE)
p += sprintf(p, "module: %d ", cpd->module);
if (cpd->validation_bits & CPER_MEM_VALID_BANK)
p += sprintf(p, "bank: %d ", cpd->bank);
if (cpd->validation_bits & CPER_MEM_VALID_DEVICE)
p += sprintf(p, "device: %d ", cpd->device);
if (cpd->validation_bits & CPER_MEM_VALID_ROW)
p += sprintf(p, "row: %d ", cpd->row);
if (cpd->validation_bits & CPER_MEM_VALID_COLUMN)
p += sprintf(p, "column: %d ", cpd->column);
if (cpd->validation_bits & CPER_MEM_VALID_BIT_POSITION)
p += sprintf(p, "bit_pos: %d ", cpd->bit_pos);
if (cpd->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
p += sprintf(p, "req_id: 0x%llx ", cpd->requestor_id);
if (cpd->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
p += sprintf(p, "resp_id: 0x%llx ", cpd->responder_id);
if (cpd->validation_bits & CPER_MEM_VALID_TARGET_ID)
p += sprintf(p, "tgt_id: 0x%llx ", cpd->target_id);
if (cpd->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
p += sprintf(p, "rank: %d ", cpd->rank);
if (cpd->validation_bits & CPER_MEM_VALID_CARD_HANDLE)
p += sprintf(p, "card_handle: %d ", cpd->mem_array_handle);
if (cpd->validation_bits & CPER_MEM_VALID_MODULE_HANDLE)
p += sprintf(p, "module_handle: %d ", cpd->mem_dev_handle);
p += sprintf(p - 1, ")");
return buf;
}
static char *uuid_le(const char *uu)
{
static char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
char *p = uuid;
int i;
static const unsigned char le[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
for (i = 0; i < 16; i++) {
p += sprintf(p, "%.2x", (unsigned char)uu[le[i]]);
switch (i) {
case 3:
case 5:
case 7:
case 9:
*p++ = '-';
break;
}
}
*p = 0;
return uuid;
}
static void report_extlog_mem_event(struct ras_events *ras,
struct tep_record *record,
struct trace_seq *s,
struct ras_extlog_event *ev)
{
trace_seq_printf(s, "%d %s error: %s physical addr: 0x%llx mask: 0x%llx%s %s %s",
ev->error_seq, err_severity(ev->severity),
err_type(ev->etype), ev->address,
err_mask(ev->pa_mask_lsb),
err_cper_data(ev->cper_data),
ev->fru_text,
uuid_le(ev->fru_id));
}
int ras_extlog_mem_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_extlog_event ev;
/*
* 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, "etype", record, &val, 1) < 0)
return -1;
ev.etype = val;
if (tep_get_field_val(s, event, "err_seq", record, &val, 1) < 0)
return -1;
ev.error_seq = val;
if (tep_get_field_val(s, event, "sev", record, &val, 1) < 0)
return -1;
ev.severity = val;
if (tep_get_field_val(s, event, "pa", record, &val, 1) < 0)
return -1;
ev.address = val;
if (tep_get_field_val(s, event, "pa_mask_lsb", record, &val, 1) < 0)
return -1;
ev.pa_mask_lsb = val;
ev.cper_data = tep_get_field_raw(s, event, "data",
record, &len, 1);
ev.cper_data_length = len;
ev.fru_text = tep_get_field_raw(s, event, "fru_text",
record, &len, 1);
ev.fru_id = tep_get_field_raw(s, event, "fru_id",
record, &len, 1);
report_extlog_mem_event(ras, record, s, &ev);
ras_store_extlog_mem_record(ras, &ev);
return 0;
}
|