Skip to content

Commit fe4846b

Browse files
author
Fox Snowpatch
committed
1 parent d88a1b4 commit fe4846b

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

arch/powerpc/kernel/time.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,8 @@ void arch_irq_work_raise(void)
471471
* which could get tangled up if we're messing with the same state
472472
* here.
473473
*/
474-
preempt_disable();
475474
set_irq_work_pending_flag();
476475
set_dec(1);
477-
preempt_enable();
478476
}
479477

480478
static void set_dec_or_work(u64 val)

drivers/misc/lkdtm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ lkdtm-$(CONFIG_LKDTM) += usercopy.o
1111
lkdtm-$(CONFIG_LKDTM) += kstack_erase.o
1212
lkdtm-$(CONFIG_LKDTM) += cfi.o
1313
lkdtm-$(CONFIG_LKDTM) += fortify.o
14-
lkdtm-$(CONFIG_PPC_64S_HASH_MMU) += powerpc.o
14+
lkdtm-$(CONFIG_PPC_BOOK3S_64) += powerpc.o
1515

1616
KASAN_SANITIZE_stackleak.o := n
1717

drivers/misc/lkdtm/powerpc.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ static void insert_slb_entry(unsigned long p, int ssize, int page_size)
1717
: "r" (mk_vsid_data(p, ssize, flags)),
1818
"r" (mk_esid_data(p, ssize, SLB_NUM_BOLTED))
1919
: "memory");
20+
isync();
2021

2122
asm volatile("slbmte %0,%1" :
2223
: "r" (mk_vsid_data(p, ssize, flags)),
2324
"r" (mk_esid_data(p, ssize, SLB_NUM_BOLTED + 1))
2425
: "memory");
26+
isync();
27+
2528
preempt_enable();
2629
}
2730

@@ -84,6 +87,7 @@ static void insert_dup_slb_entry_0(void)
8487
: "r" (vsid),
8588
"r" (esid | SLB_NUM_BOLTED)
8689
: "memory");
90+
isync();
8791

8892
asm volatile("slbmfee %0,%1" : "=r" (esid) : "r" (i));
8993
asm volatile("slbmfev %0,%1" : "=r" (vsid) : "r" (i));
@@ -93,13 +97,39 @@ static void insert_dup_slb_entry_0(void)
9397
: "r" (vsid),
9498
"r" (esid | (SLB_NUM_BOLTED + 1))
9599
: "memory");
100+
isync();
96101

97102
pr_info("%s accessing test address 0x%lx: 0x%lx\n",
98103
__func__, test_address, *test_ptr);
99104

100105
preempt_enable();
101106
}
102107

108+
static void tlbiel_va(unsigned long va,
109+
unsigned long pid,
110+
unsigned long ap,
111+
unsigned long ric)
112+
{
113+
unsigned long rb, rs, prs, r;
114+
115+
rb = va & ~(PPC_BITMASK(52, 63));
116+
rb |= ap << PPC_BITLSHIFT(58);
117+
rs = pid << PPC_BITLSHIFT(31);
118+
119+
prs = 1; /* process scoped */
120+
r = 1; /* radix format */
121+
122+
/*
123+
* Trigger an MCE by issuing radix tlbiel with an invalid operand combination.
124+
* Using PRS=1 (process-scoped) with kernel address does not correspond to
125+
* any valid process-scoped translation.
126+
* This results in an invalid tlbiel operation, causing hardware to
127+
* raise a machine check.
128+
*/
129+
asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
130+
: : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
131+
}
132+
103133
static void lkdtm_PPC_SLB_MULTIHIT(void)
104134
{
105135
if (!radix_enabled()) {
@@ -119,8 +149,22 @@ static void lkdtm_PPC_SLB_MULTIHIT(void)
119149
}
120150
}
121151

152+
static void lkdtm_PPC_RADIX_TLBIEL(void)
153+
{
154+
unsigned long addr = PAGE_OFFSET;
155+
156+
if (radix_enabled()) {
157+
pr_info("Injecting Radix TLB invalidation MCE\n");
158+
tlbiel_va(addr, 0, 0, RIC_FLUSH_ALL);
159+
pr_info("Recovered from radix tlbiel attempt\n");
160+
} else {
161+
pr_err("XFAIL: This test is for ppc64 and with radix mode MMU only\n");
162+
}
163+
}
164+
122165
static struct crashtype crashtypes[] = {
123166
CRASHTYPE(PPC_SLB_MULTIHIT),
167+
CRASHTYPE(PPC_RADIX_TLBIEL),
124168
};
125169

126170
struct crashtype_category powerpc_crashtypes = {

tools/testing/selftests/lkdtm/tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ FORTIFY_STR_MEMBER detected buffer overflow
8686
FORTIFY_MEM_OBJECT detected buffer overflow
8787
FORTIFY_MEM_MEMBER detected field-spanning write
8888
PPC_SLB_MULTIHIT Recovered
89+
#PPC_RADIX_TLBIEL Triggers unrecoverable MCE

0 commit comments

Comments
 (0)