Skip to content

Commit 5120682

Browse files
dcrowell77wghoffa
authored andcommitted
Add msgsync to doorbell wakeup logic to avoid weak consistency bug
POWER9 added a new sync mode called 'msgsync' that is required to avoid weak consistency issues when you are using doorbell (msgsnd) functions. See POWER ISA Section 5.9.2 for details, excerpt here: The ordering done by sync (and ptesync) provides the appearance of "causality" across a sequence of msgsnd instructions, as in the following example. "msgsnd->T1" means "msgsnd instruction target- ting thread T1". "<DHDI 0>" means "occurrence of Directed Hypervisor Doorbell interrupt caused by msgsnd executed on T0". On T0, register r1 is assumed to contain the value 1. T0 T1 T2 std r1,X <DHDI 0> <DHDI 1> sync msgsnd->T2 msgsync msgsnd->T1 ld r1,X In this example, T2's load from X must return 1. The change here adds the msgsync call to the code that executes any time we handle a doorbell interrupt. In addition there is a POWER9 DD2 errata that indicates we also require a lwsync to ensure consistency. Change-Id: Ib0f3571926d71efcbffa205093278e2a1d58df85 CQ: SW454611 Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/70650 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com> Reviewed-by: William G. Hoffa <wghoffa@us.ibm.com>
1 parent e0d1b03 commit 5120682

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/include/arch/ppc.H

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* Contributors Listed Below - COPYRIGHT 2011,2018 */
8+
/* Contributors Listed Below - COPYRIGHT 2011,2019 */
99
/* [+] Google Inc. */
1010
/* [+] International Business Machines Corp. */
1111
/* */
@@ -225,6 +225,20 @@ inline void eieio()
225225
asm volatile("eieio" ::: "memory");
226226
}
227227

228+
ALWAYS_INLINE
229+
inline void msgsync()
230+
{
231+
// See POWER ISA 5.9.2 for details
232+
//asm volatile("msgsync" ::: "memory");
233+
asm volatile(".long 0x7C0006EC"); // Our GCC doesn't support 'msgsync' yet
234+
// [011111 ///// ///// ///// 11011 10110/]
235+
236+
// There is a P9 DD2 workaround that a lwsync is also required
237+
// after a msgsync
238+
asm volatile("lwsync" ::: "memory");
239+
}
240+
241+
228242
ALWAYS_INLINE
229243
inline uint64_t getHMER()
230244
{

src/kernel/syscall.C

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* Contributors Listed Below - COPYRIGHT 2010,2018 */
8+
/* Contributors Listed Below - COPYRIGHT 2010,2019 */
99
/* [+] International Business Machines Corp. */
1010
/* */
1111
/* */
@@ -55,6 +55,12 @@ namespace KernelIpc
5555
extern "C"
5656
void kernel_execute_hype_doorbell()
5757
{
58+
// Per POWER ISA Section 5.9.2, to avoid any weak consistency
59+
// issues we must use a msgsync instruction before consuming
60+
// any data set by a different thread following a doorbell
61+
// wakeup.
62+
msgsync();
63+
5864
task_t* t = TaskManager::getCurrentTask();
5965
doorbell_clear();
6066

0 commit comments

Comments
 (0)