Patch "LoongArch: Change __my_cpu_offset definition to avoid mis-optimization" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    LoongArch: Change __my_cpu_offset definition to avoid mis-optimization

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     loongarch-change-__my_cpu_offset-definition-to-avoid.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6c02dbfb399845c9b9352a012956df306d68130c
Author: Huacai Chen <chenhuacai@xxxxxxxxxx>
Date:   Tue Mar 19 15:50:34 2024 +0800

    LoongArch: Change __my_cpu_offset definition to avoid mis-optimization
    
    [ Upstream commit c87e12e0e8c1241410e758e181ca6bf23efa5b5b ]
    
    From GCC commit 3f13154553f8546a ("df-scan: remove ad-hoc handling of
    global regs in asms"), global registers will no longer be forced to add
    to the def-use chain. Then current_thread_info(), current_stack_pointer
    and __my_cpu_offset may be lifted out of the loop because they are no
    longer treated as "volatile variables".
    
    This optimization is still correct for the current_thread_info() and
    current_stack_pointer usages because they are associated to a thread.
    However it is wrong for __my_cpu_offset because it is associated to a
    CPU rather than a thread: if the thread migrates to a different CPU in
    the loop, __my_cpu_offset should be changed.
    
    Change __my_cpu_offset definition to treat it as a "volatile variable",
    in order to avoid such a mis-optimization.
    
    Cc: stable@xxxxxxxxxxxxxxx
    Reported-by: Xiaotian Wu <wuxiaotian@xxxxxxxxxxx>
    Reported-by: Miao Wang <shankerwangmiao@xxxxxxxxx>
    Signed-off-by: Xing Li <lixing@xxxxxxxxxxx>
    Signed-off-by: Hongchen Zhang <zhanghongchen@xxxxxxxxxxx>
    Signed-off-by: Rui Wang <wangrui@xxxxxxxxxxx>
    Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/loongarch/include/asm/percpu.h b/arch/loongarch/include/asm/percpu.h
index 9b36ac003f890..8f290e5546cf7 100644
--- a/arch/loongarch/include/asm/percpu.h
+++ b/arch/loongarch/include/asm/percpu.h
@@ -29,7 +29,12 @@ static inline void set_my_cpu_offset(unsigned long off)
 	__my_cpu_offset = off;
 	csr_write64(off, PERCPU_BASE_KS);
 }
-#define __my_cpu_offset __my_cpu_offset
+
+#define __my_cpu_offset					\
+({							\
+	__asm__ __volatile__("":"+r"(__my_cpu_offset));	\
+	__my_cpu_offset;				\
+})
 
 #define PERCPU_OP(op, asm_op, c_op)					\
 static __always_inline unsigned long __percpu_##op(void *ptr,		\




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux