Skip to content

Commit 926bc2f

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Fix compiler store ordering to SLB shadow area
The stores to update the SLB shadow area must be made as they appear in the C code, so that the hypervisor does not see an entry with mismatched vsid and esid. Use WRITE_ONCE for this. GCC has been observed to elide the first store to esid in the update, which means that if the hypervisor interrupts the guest after storing to vsid, it could see an entry with old esid and new vsid, which may possibly result in memory corruption. Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 0cef77c commit 926bc2f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/powerpc/mm/slb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ static inline void slb_shadow_update(unsigned long ea, int ssize,
6363
* updating it. No write barriers are needed here, provided
6464
* we only update the current CPU's SLB shadow buffer.
6565
*/
66-
p->save_area[index].esid = 0;
67-
p->save_area[index].vsid = cpu_to_be64(mk_vsid_data(ea, ssize, flags));
68-
p->save_area[index].esid = cpu_to_be64(mk_esid_data(ea, ssize, index));
66+
WRITE_ONCE(p->save_area[index].esid, 0);
67+
WRITE_ONCE(p->save_area[index].vsid, cpu_to_be64(mk_vsid_data(ea, ssize, flags)));
68+
WRITE_ONCE(p->save_area[index].esid, cpu_to_be64(mk_esid_data(ea, ssize, index)));
6969
}
7070

7171
static inline void slb_shadow_clear(enum slb_index index)
7272
{
73-
get_slb_shadow()->save_area[index].esid = 0;
73+
WRITE_ONCE(get_slb_shadow()->save_area[index].esid, 0);
7474
}
7575

7676
static inline void create_shadowed_slbe(unsigned long ea, int ssize,

0 commit comments

Comments
 (0)