summaryrefslogtreecommitdiffstats
path: root/drivers/virt/tegra/vm_err_sample_handler.c
blob: 69f7c7b67fbca2b8fb6b8c81dff5b3af6fcc0d91 (plain) (blame)
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
 * Copyright (c) 2019-2020, NVIDIA CORPORATION.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope 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.
 */
#define pr_fmt(fmt) "vm-err-sample-handler: " fmt

#include <linux/module.h>
#include <linux/vm_err.h>

/* Bridge error details:
 * Note: These are redefined here only to allow user friendly messages
 * describing the error.
 * This must match with "Timeout error" value in t18x_axi_errors[]
 * in nvidia/drivers/platform/tegra/bridge_mca.c
 */
static const unsigned int BRIDGE_ERROR_TIMEOUT = 18;

/* This must match with "CCPLEX" value in src_ids
 * in nvidia/drivers/platform/tegra/bridge_mca.c
 */
static const unsigned int BRIDGE_SRC_ID_CCPLEX = 1;

/* This must match with corresponding HV definition in pct.h */
static const unsigned int GUEST_UNASSIGNED = 18;

static struct tegra_hv_vm_err_handlers handlers;
static struct tegra_hv_config config;

static void print_bridge_error(const struct err_data_t * const err_data)
{
	const struct async_bridge_err_t * const br_err_data =
		&err_data->async_bridge_err;
	unsigned int protection;

	pr_crit("Bridge error details\n");
	pr_crit("--------------------------------------\n");
	pr_crit("Err count %d: %s FAULT ADDR 0x%x status1 0x%x status2 0x%x\n",
		br_err_data->count, br_err_data->br_name, br_err_data->err_addr,
		br_err_data->err_status1, br_err_data->err_status2);

	pr_crit("\tDirection: %s\n", br_err_data->rw ? "READ" : "WRITE");
	pr_crit("\tBridge ID: 0x%x\n", br_err_data->br_id);
	pr_crit("\tError type: %u %s\n",
		br_err_data->err_type,
		(br_err_data->err_type == BRIDGE_ERROR_TIMEOUT) ?
			"(Timeout)" : "");

	pr_crit("\tLength: %d\n", br_err_data->length);
	protection = br_err_data->protection;
	pr_crit("\tProtection: 0x%x %s %s %s access\n", protection,
		(protection & 0x4) ? "Instruction" : "Data",
		(protection & 0x2) ? "Non-Secure" : "Secure",
		(protection & 0x1) ? "Privileged" : "Unprivileged");

	pr_crit("\tSource ID: 0x%x -- %s\n",
		br_err_data->src_id,
		(br_err_data->src_id == BRIDGE_SRC_ID_CCPLEX) ?
			" (CCPLEX)" : "");

	pr_crit("\tAXI_ID: 0x%x\n", br_err_data->axi_id);
	pr_crit("\tCache: 0x%x\n", br_err_data->cache);
	pr_crit("\tBurst: 0x%x\n", br_err_data->burst);
	pr_crit("--------------------------------------\n");
}

static void print_cache(uint32_t cache)
{
	if ((cache & 0x3) == 0x0) {
		pr_crit("\t Cache\t\t\t: 0x%x--Non-cacheable/Non-Bufferable)\n",
			cache);
		return;
	}
	if ((cache & 0x3) == 0x1) {
		pr_crit("\t  Cache\t\t\t: 0x%x -- Device\n",
			cache);
		return;
	}

	switch (cache) {
	case 0x2:
		pr_crit("\t  Cache\t\t\t: 0x%x -- Cacheable/Non-Bufferable\n",
			cache);
		break;
	case 0x3:
		pr_crit("\t  Cache\t\t\t: 0x%x -- Cacheable/Bufferable\n",
			cache);
		break;
	default:
		pr_crit("\t  Cache\t\t\t: 0x%x -- Cacheable\n",
			cache);
	}
}

static void print_prot(uint32_t prot)
{
	char *data_str;
	char *secure_str;
	char *priv_str;

	data_str = (prot & 0x4) ? "Instruction" : "Data";
	secure_str = (prot & 0x2) ? "Non-Secure" : "Secure";
	priv_str = (prot & 0x1) ? "Privileged" : "Unprivileged";

	pr_crit("\t  Protection\t\t: 0x%x -- %s, %s, %s Access\n",
		prot, priv_str, secure_str, data_str);
}

static void print_cbb_error(const struct err_data_t * const err_data)
{
	const struct async_cbb_err_t * const cbb_err_data =
		&err_data->async_cbb_err;

	pr_crit("Control Back Bone(CBB) error details\n");
	pr_crit("--------------------------------------\n");
	pr_crit("Error:%s\n", cbb_err_data->cbb_name);
	pr_crit("\tError Logger\t\t: %d\n", cbb_err_data->error_logger);
	pr_crit("\tErrLog0\t\t\t: 0x%x\n", cbb_err_data->errlog0);
	pr_crit("\t  Transaction Type\t: %s\n", cbb_err_data->transaction_type);
	pr_crit("\t  Error Code\t\t: %s\n", cbb_err_data->error_code);
	pr_crit("\t  Error Source\t\t: %s\n",
		cbb_err_data->error_source);
	pr_crit("\t  Error Description\t: %s\n",
		cbb_err_data->error_description);
	pr_crit("\t  Packet header Lock\t: %d\n",
			cbb_err_data->packet_header_lock);
	pr_crit("\t  Packet header Len1\t: %d\n",
			cbb_err_data->packet_header_len1);

	if (cbb_err_data->header_format)
		pr_crit("\t  NOC protocol version\t: %s\n", "version >= 2.7");
	else
		pr_crit("\t  NOC protocol version\t: %s\n", "version < 2.7");
	pr_crit("\tErrLog1\t\t\t: 0x%x\n", cbb_err_data->errlog1);
	pr_crit("\tErrLog2\t\t\t: 0x%x\n", cbb_err_data->errlog2);
	pr_crit("\t  RouteId\t\t: 0x%llx\n", cbb_err_data->route_id);
	pr_crit("\t  InitFlow\t\t: %s\n", cbb_err_data->initflow);
	pr_crit("\t  Targflow\t\t: %s\n", cbb_err_data->targflow);
	pr_crit("\t  TargSubRange\t\t: %d\n", cbb_err_data->targ_subrange);
	pr_crit("\t  SeqId\t\t\t: %d\n", cbb_err_data->seqid);
	pr_crit("\tErrLog3\t\t\t: 0x%x\n", cbb_err_data->errlog3);
	pr_crit("\tErrLog4\t\t\t: 0x%x\n", cbb_err_data->errlog4);
	pr_crit("\t  Address\t\t: 0x%llx\n", cbb_err_data->address);
	pr_crit("\tErrLog5\t\t\t: 0x%x\n", cbb_err_data->errlog5);
	pr_crit("\t  Master ID\t\t: %s\n", cbb_err_data->master_id);
	pr_crit("\t  Non-Modify\t\t: 0x%x\n", cbb_err_data->non_mod);
	pr_crit("\t  AXI ID\t\t: 0x%x\n", cbb_err_data->axi_id);
	pr_crit("\t  Security Group(GRPSEC): 0x%x\n",
			cbb_err_data->security_group);

	print_cache(cbb_err_data->cache);
	print_prot(cbb_err_data->protection);

	pr_crit("\t  FALCONSEC\t\t: 0x%x\n", cbb_err_data->falconsec);
	pr_crit("\t  Virtual Queuing Channel(VQC): 0x%x\n",
		cbb_err_data->virtual_q_channel);
	pr_crit("--------------------------------------\n");
}

static void print_smmu_error(const struct err_data_t * const err_data,
				const enum err_reason reason)
{
	const struct async_smmu_err_t * const smmu_err_data =
		&err_data->async_smmu_err;

	pr_crit("SMMU error details\n");
	pr_crit("--------------------------------------\n");
	if (reason == REASON_ASYNC_SMMU_CB) {
		pr_crit("SMMU Context Bank %u error. StreamID: %d\n",
			smmu_err_data->cb_id, smmu_err_data->stream_id);
	} else if (reason == REASON_ASYNC_SMMU_GLOBAL) {
		pr_crit("Global SMMU fault. CB: %u. StreamID: %d\n",
			smmu_err_data->cb_id, smmu_err_data->stream_id);
	} else {
		pr_crit("Unexpected fault reason %d\n", reason);
	}
	pr_crit("FSR: 0x%x; FAR: 0x%llx; FSYND0: 0x%x; FSYND1: 0x%x\n",
			smmu_err_data->fsr, smmu_err_data->far,
			smmu_err_data->fsynr0, smmu_err_data->fsynr1);
	pr_crit("--------------------------------------\n");
}

static void print_mc_error(const struct err_data_t * const err_data)
{
	const struct async_mc_err_t * const mc_err_data =
		&err_data->async_mc_err;

	pr_crit("Memory Controller error details\n");
	pr_crit("--------------------------------------\n");
	pr_crit("mc_err: base: 0x%llx, int_status: 0x%08x; err_status: 0x%08x;"
		" fault_addr: 0x%llx\n",
		mc_err_data->ch_base, mc_err_data->int_status,
		mc_err_data->err_status, mc_err_data->fault_addr);
	pr_crit("vcpuid %u, client_id %u, peripheral_id %d\n",
		mc_err_data->vcpuid, mc_err_data->client_id,
		mc_err_data->peripheral_id);
	pr_crit("--------------------------------------\n");
}

static void print_data_abort(const struct err_data_t *const err_data)
{
	const struct sync_data_abort_t * const data_abort =
		&err_data->sync_data_abort;

	pr_crit("Data abort details\n");
	pr_crit("--------------------------------------\n");
	pr_crit("offending VCpu Id %u\n", data_abort->offending_vcpu_id);
	(data_abort->is_write) ?
		pr_crit("write access\n") : pr_crit("read access\n");
	pr_crit("access size %u\n", data_abort->access_size);
	pr_crit("fault address: 0x%llx\n", data_abort->fault_addr);
	pr_crit("esr: 0x%x\n", data_abort->esr_el2);
	pr_crit("spsr_el2: 0x%llx\n", data_abort->spsr_el2);
	pr_crit("elr_el1: 0x%llx\n", data_abort->elr_el1);
	pr_crit("gpr_array[0]: 0x%llx\n", data_abort->gpr_array[0]);
	pr_crit("gpr_array[15]: 0x%llx\n", data_abort->gpr_array[15]);
	pr_crit("gpr_array[30]: 0x%llx\n", data_abort->gpr_array[30]);
	pr_crit("--------------------------------------\n");
}

static bool handle_async_err_details(const struct err_data_t * const err_data)
{
	bool enter_bad_mode;

	if (err_data->err_type != ASYNC) {
		pr_crit("%s: incorrect error type: %d\n", __func__,
			err_data->err_type);
		/* Unexpected error type. Enter bad mode. */
		return true;
	}

	pr_info("%s: error reason: %s\n", __func__,
		tegra_hv_err_reason_desc[err_data->err_reason]);
	switch (err_data->err_reason) {
	case REASON_ASYNC_BRIDGE:
		print_bridge_error(err_data);
		/* Bridge error may not be fatal */
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_CBB:
		print_cbb_error(err_data);
		/* CBB error may not be fatal */
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_SMMU_CB:
		print_smmu_error(err_data, err_data->err_reason);
		/* SMMU context bank error may not be fatal */
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_SMMU_GLOBAL:
		print_smmu_error(err_data, err_data->err_reason);
		/* Can't recover from global SMMU error. */
		enter_bad_mode = true;
		break;

	case REASON_ASYNC_MC:
		print_mc_error(err_data);
		enter_bad_mode = false;
		break;

	default:
		pr_crit("%s: unhandled error. Reason id %d\n", __func__,
			err_data->err_reason);
		enter_bad_mode = true;
		break;
	}

	return enter_bad_mode;
}

static bool handle_sync_err_details(const struct err_data_t * const err_data)
{
	/* Currently only data abort error injection is supported */
	if (err_data->err_reason != REASON_SYNC_DATA_ABORT) {
		pr_crit("%s: unexpected reason id %u\n", __func__,
			err_data->err_reason);
		/* Invalid reason. Enter bad mode. */
		return true;
	}
	pr_info("%s: error reason: %s\n", __func__,
		tegra_hv_err_reason_desc[err_data->err_reason]);
	print_data_abort(err_data);

	/* Recovery from sync error could be impossible. Enter bad mode. */
	return true;
}

static bool handle_peer_err_details(const struct err_data_t * const err_data)
{
	bool enter_bad_mode;
	const unsigned int offender = err_data->offending_guest_id;

	if (offender >= config.num_guests) {
		if (offender != GUEST_UNASSIGNED) {
			pr_crit("%s: invalid offending peer guest id %u\n",
				__func__, offender);
			/* Unexpected. Cause reboot. */
			return true;
		}
		pr_crit("%s: HV can't attribute error to any guest\n",
			__func__);
	} else
		pr_crit("Peer error. Offending guest id = %u\n", offender);

	pr_crit("Error Type: %s\n", (err_data->err_type == SYNC) ?
		"Synchronous" : "Asynchronous");

	if (err_data->err_reason >= REASON_ENUM_SIZE) {
		pr_crit("%s: unexpected reason id %u\n", __func__,
			err_data->err_reason);
		/* Unexpected. Cause reboot. */
		return true;
	}
	pr_crit("%s: error reason: %s\n", __func__,
		tegra_hv_err_reason_desc[err_data->err_reason]);

	switch (err_data->err_reason) {
	case REASON_ASYNC_BRIDGE:
		print_bridge_error(err_data);
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_CBB:
		print_cbb_error(err_data);
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_SMMU_CB:
	case REASON_ASYNC_SMMU_GLOBAL:
		print_smmu_error(err_data, err_data->err_reason);
		enter_bad_mode = false;
		break;

	case REASON_ASYNC_MC:
		print_mc_error(err_data);
		enter_bad_mode = false;
		break;

	case REASON_SYNC_DATA_ABORT:
		print_data_abort(err_data);
		enter_bad_mode = false;
		break;

	default:
		pr_crit("%s: unhandled error. Reason id %d\n", __func__,
		err_data->err_reason);
		enter_bad_mode = false;
		break;
	}

	return enter_bad_mode;
}

static bool self_async_err_handler(const struct err_data_t *const err_data)
{
	return handle_async_err_details(err_data);
}

static bool self_sync_err_handler(const struct err_data_t *const err_data)
{
	return handle_sync_err_details(err_data);
}

static bool peer_err_handler(const struct err_data_t *const err_data)
{
	return handle_peer_err_details(err_data);
}

static int hooks_init(void)
{
	int ret;

	handlers.fn_self_async = self_async_err_handler;
	handlers.fn_self_sync = self_sync_err_handler;
	handlers.fn_peer =
		IS_ENABLED(CONFIG_TEGRA_EBP) ? NULL : peer_err_handler;

	ret = tegra_hv_register_vm_err_hooks(&handlers);
	if (ret)
		return ret;

	tegra_hv_get_config(&config);
	pr_info("%s: Guest Id %u\n", __func__, config.guest_id_self);

	/* EBP, being unprivileged, doesn't know about total guests */
	if (IS_ENABLED(CONFIG_TEGRA_EBP) == 0)
		pr_info("%s: Total guests %u\n", __func__, config.num_guests);

	return 0;
}

static void hooks_exit(void)
{
	struct tegra_hv_vm_err_handlers handlers;

	handlers.fn_self_async = NULL;
	handlers.fn_self_sync = NULL;
	handlers.fn_peer = NULL;

	tegra_hv_register_vm_err_hooks(&handlers);
}
subsys_initcall(hooks_init);
module_exit(hooks_exit);

MODULE_AUTHOR("Nvidia Corporation");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Sample VM Error Handler");