Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp514140lqb; Thu, 14 Mar 2024 19:47:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGVEfp2vNEMUNCAI1e84mQA6fHRAo7iB5NpYrIcC4zj5/Gmcxy4GF+8LW1yQMIb9VYnrQRvvFTIiCqpJpBRaLy1JGuMqZSlvDOmQQymQ== X-Google-Smtp-Source: AGHT+IGVZWV7J8okaO5beN8IDS0O5RuB6dH+AC+HLErWiHN0SqGmVeMAsI++nu1Rq2+beeCmph6b X-Received: by 2002:a05:6a21:279a:b0:1a1:4a4c:ff7c with SMTP id rn26-20020a056a21279a00b001a14a4cff7cmr3220158pzb.60.1710470827860; Thu, 14 Mar 2024 19:47:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710470827; cv=pass; d=google.com; s=arc-20160816; b=CxZUvwIGgRFpX4w5RwKVOomDlxU0Ua4ePM/3A2PYxfG4B8VXOr7MgpFSF/bkeB6hYV 0pXaEczEbqC5YJg6TENr6/drMBzpOCcMS/HBpy36SL1MvblNvdecnSe98/KKqeEQ2n0D RNVThi3jgOeRKxbQekgAZwzwuQZ6HWIMhl0Iw5w1xHex7OY+pm09uOVkvSzWjHdcZcyZ RUeaNCxMwtm0p8CktYVnlbnAQZ2qBTQZV9c9VUdm9C5MrXSHZEJOxfhC3w4W/0TrPmf5 3DV99mSWDH3/uNML3xANjSkNL9MmNXvfU+VjjPYlYYIY54S5sfb6pTP1QtLF7ObusICI jykQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=FM8qBQITEL/2uCjksaygN1bKxRc0Lk5UVlWffxRsVds=; fh=SXtSV6AF1Jbge3wqo70t+KhpNnT/CDEb7WszTl7vRjA=; b=zZs4zEyoFUE9hot9dimqfxwXp3zsPwW86iouEExkWz0OhMyrOiaRHG4jHGaoLGPz1C XLhJLg47E8i4NhH5uKwy2/c+3NWjsWDLz46+uRtqz0puQ/LIrUvDCbmVC3KWWrjtEhrD W8zKUxVRuvxUj/EGS2CzbeA2fTLnz9b1GprYLyOTqtCRB9phhY3wh+857PV4IQ1LjCMw PyvYNfWmM1oV4KtSGrl1mslrYoFMT5/d5WiKN2etvIjlceW+oSDWeceWoFuzNUjinYPR L7RLF07Ay4YFaWOGzMbvcLMsYRV9FA5ChrtMbQJYAvj48ryPKAB97Z236PHFUrApc9V+ Wp9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-103995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103995-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ca13-20020a17090af30d00b0029c776b4683si1833889pjb.115.2024.03.14.19.47.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 19:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-103995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103995-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2819EB2251A for ; Fri, 15 Mar 2024 02:45:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A100C8CE; Fri, 15 Mar 2024 02:45:43 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A631379DE; Fri, 15 Mar 2024 02:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710470742; cv=none; b=TwocCCXU3tE0ZJHc/WS7cBy1BXJQNDNT3WeFtVdpGDuP0vNg6ogL2xO+IGJpxqPYq/WKmZ4XQGjyqhUejX4Zu2RnwNyC7Qvp121aMX/lXUkO5JOpwlFTg+M6W/WdOtHMCCjDP1UQecqKu+Kcga7UK3mtd44X63Tj12p5NDH3s0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710470742; c=relaxed/simple; bh=E33cKRU/0bnIopCBLTQiUg1CEGllwAlLq2Nw4I1WmE8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hiLmKSE1CE5Ja0t1fpKDhrevtLdpVbgfnXN6vDgILsyjN07rRdWnoyzjeUxK8z47oe42DANW2ogRecGvOmvAM/JrQPOiEEcj+Kg+zmivdsV6/EThdmCblYMyuJoaorxmHmRpu0WLo+uZBulCFzLsb2JF6LDEgQQBz4KzLUZG1GU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 638C9C433C7; Fri, 15 Mar 2024 02:45:38 +0000 (UTC) From: Huacai Chen To: Arnd Bergmann , Huacai Chen Cc: loongarch@lists.linux.dev, linux-arch@vger.kernel.org, Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn, Huacai Chen , stable@vger.kernel.org, Xiaotian Wu , Miao Wang , Xing Li , Hongchen Zhang , Rui Wang Subject: [PATCH] LoongArch: Change __my_cpu_offset definition to avoid mis-optimization Date: Fri, 15 Mar 2024 10:45:26 +0800 Message-ID: <20240315024526.394772-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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@vger.kernel.org Reported-by: Xiaotian Wu Reported-by: Miao Wang Signed-off-by: Xing Li Signed-off-by: Hongchen Zhang Signed-off-by: Rui Wang Signed-off-by: Huacai Chen --- arch/loongarch/include/asm/percpu.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/include/asm/percpu.h b/arch/loongarch/include/asm/percpu.h index 9b36ac003f89..03b98491d301 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, \ -- 2.43.0