@@ -43,8 +43,6 @@ static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx)
4343
4444static __always_inline void __mwait (u32 eax , u32 ecx )
4545{
46- mds_idle_clear_cpu_buffers ();
47-
4846 /*
4947 * Use the instruction mnemonic with implicit operands, as the LLVM
5048 * assembler fails to assemble the mnemonic with explicit operands:
@@ -80,7 +78,7 @@ static __always_inline void __mwait(u32 eax, u32 ecx)
8078 */
8179static __always_inline void __mwaitx (u32 eax , u32 ebx , u32 ecx )
8280{
83- /* No MDS buffer clear as this is AMD/HYGON only */
81+ /* No need for TSA buffer clearing on AMD */
8482
8583 /* "mwaitx %eax, %ebx, %ecx" */
8684 asm volatile (".byte 0x0f, 0x01, 0xfb"
@@ -98,7 +96,6 @@ static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx)
9896 */
9997static __always_inline void __sti_mwait (u32 eax , u32 ecx )
10098{
101- mds_idle_clear_cpu_buffers ();
10299
103100 asm volatile ("sti; mwait" :: "a" (eax ), "c" (ecx ));
104101}
@@ -115,21 +112,29 @@ static __always_inline void __sti_mwait(u32 eax, u32 ecx)
115112 */
116113static __always_inline void mwait_idle_with_hints (u32 eax , u32 ecx )
117114{
115+ if (need_resched ())
116+ return ;
117+
118+ x86_idle_clear_cpu_buffers ();
119+
118120 if (static_cpu_has_bug (X86_BUG_MONITOR ) || !current_set_polling_and_test ()) {
119121 const void * addr = & current_thread_info ()-> flags ;
120122
121123 alternative_input ("" , "clflush (%[addr])" , X86_BUG_CLFLUSH_MONITOR , [addr ] "a" (addr ));
122124 __monitor (addr , 0 , 0 );
123125
124- if (!need_resched ()) {
125- if (ecx & 1 ) {
126- __mwait (eax , ecx );
127- } else {
128- __sti_mwait (eax , ecx );
129- raw_local_irq_disable ();
130- }
126+ if (need_resched ())
127+ goto out ;
128+
129+ if (ecx & 1 ) {
130+ __mwait (eax , ecx );
131+ } else {
132+ __sti_mwait (eax , ecx );
133+ raw_local_irq_disable ();
131134 }
132135 }
136+
137+ out :
133138 current_clr_polling ();
134139}
135140
0 commit comments