summaryrefslogtreecommitdiffstats
path: root/arch/s390/mm/extable.c
blob: 0a0738a473af05e3149ebf2500ea0a79a3da5d73 (plain)
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
// SPDX-License-Identifier: GPL-2.0

#include <linux/bitfield.h>
#include <linux/extable.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/panic.h>
#include <asm/asm-extable.h>
#include <asm/extable.h>

const struct exception_table_entry *s390_search_extables(unsigned long addr)
{
	const struct exception_table_entry *fixup;
	size_t num;

	fixup = search_exception_tables(addr);
	if (fixup)
		return fixup;
	num = __stop_amode31_ex_table - __start_amode31_ex_table;
	return search_extable(__start_amode31_ex_table, num, addr);
}

static bool ex_handler_fixup(const struct exception_table_entry *ex, struct pt_regs *regs)
{
	regs->psw.addr = extable_fixup(ex);
	return true;
}

static bool ex_handler_ua_store(const struct exception_table_entry *ex, struct pt_regs *regs)
{
	unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);

	regs->gprs[reg_err] = -EFAULT;
	regs->psw.addr = extable_fixup(ex);
	return true;
}

static bool ex_handler_ua_load_mem(const struct exception_table_entry *ex, struct pt_regs *regs)
{
	unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
	unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
	size_t len = FIELD_GET(EX_DATA_LEN, ex->data);

	regs->gprs[reg_err] = -EFAULT;
	memset((void *)regs->gprs[reg_addr], 0, len);
	regs->psw.addr = extable_fixup(ex);
	return true;
}

static bool ex_handler_ua_load_reg(const struct exception_table_entry *ex,
				   bool pair, struct pt_regs *regs)
{
	unsigned int reg_zero = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
	unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);

	regs->gprs[reg_err] = -EFAULT;
	regs->gprs[reg_zero] = 0;
	if (pair)
		regs->gprs[reg_zero + 1] = 0;
	regs->psw.addr = extable_fixup(ex);
	return true;
}

static bool ex_handler_zeropad(const struct exception_table_entry *ex, struct pt_regs *regs)
{
	unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
	unsigned int reg_data = FIELD_GET(EX_DATA_REG_ERR, ex->data);
	unsigned long data, addr, offset;

	addr = regs->gprs[reg_addr];
	offset = addr & (sizeof(unsigned long) - 1);
	addr &= ~(sizeof(unsigned long) - 1);
	data = *(unsigned long *)addr;
	data <<= BITS_PER_BYTE * offset;
	regs->gprs[reg_data] = data;
	regs->psw.addr = extable_fixup(ex);
	return true;
}

bool fixup_exception(struct pt_regs *regs)
{
	const struct exception_table_entry *ex;

	ex = s390_search_extables(instruction_pointer(regs));
	if (!ex)
		return false;
	switch (ex->type) {
	case EX_TYPE_FIXUP:
		return ex_handler_fixup(ex, regs);
	case EX_TYPE_BPF:
		return ex_handler_bpf(ex, regs);
	case EX_TYPE_UA_STORE:
		return ex_handler_ua_store(ex, regs);
	case EX_TYPE_UA_LOAD_MEM:
		return ex_handler_ua_load_mem(ex, regs);
	case EX_TYPE_UA_LOAD_REG:
		return ex_handler_ua_load_reg(ex, false, regs);
	case EX_TYPE_UA_LOAD_REGPAIR:
		return ex_handler_ua_load_reg(ex, true, regs);
	case EX_TYPE_ZEROPAD:
		return ex_handler_zeropad(ex, regs);
	}
	panic("invalid exception table entry");
}