Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1528018lqt; Wed, 20 Mar 2024 06:49:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUEBNRcaWDigNjM5k5bB2UbZl+ediaua8Olw1ZsWj4YNG3T0LxdrU16KY5fgDgHvgSzMsFlTvJgX63EPSy/dy+LKWutSF9O/dg7A4FiQ== X-Google-Smtp-Source: AGHT+IF//sEnInjegICbczcqqaTXeh9rwz0oJXwAocipclsRnj26YMpUYEoY8pR2X8tqstoqMfrM X-Received: by 2002:a17:902:e752:b0:1dd:d40b:bd30 with SMTP id p18-20020a170902e75200b001ddd40bbd30mr5542837plf.29.1710942599066; Wed, 20 Mar 2024 06:49:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710942599; cv=pass; d=google.com; s=arc-20160816; b=rropB7UgLPgVAkGevkSIgTxgfKb4JanGYNBARfwK66nv1MjdCZ0ZpucjWdXvDBfDWk hufaKq1ItkJzJf4ACf9NQ0r4TTHDROWz+vdKPPlaTKZfrbwT6nuQIfuDID6x+I2Eeimt qbzxEScta4KnHg4T6gRocqGvMWmcwsKBnIt3hvUg5k/wjirpdLhGli0ibkQcU4EveIvy B9oPl2AXM682V/vUQiXPaXJggleLIVBzgTG8PFnckKgR5GoeEAeXAScMUbKGybRPzJMz kdLd2IYj80IoHWn74GDvy/dEcrn0zYrs9U9Tuhq0eKLOfrbHT8wP4UEv7T+KuSfTDET8 v0Hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=5BP5ErPDX7sNV73TKb5sn8WEc6QIgqEEQqCHO1/4UXI=; fh=/x4dqSnk2T/3ZCGY6+4YiWE2GaK8j+RRESpfNWloltM=; b=0khhVGsrcxdvssk5c/00R1epmVSVg4jSlQeDhItlGj+3HxH1Lc0Jb+Vwmn8YL4aXuc qw9LFvDFm2ZMvDIqrvgR8OZG7W/Bv3zN3NwRIZLYIFa5UleWk4PicgsUgKzVgvEepD92 lPwYxpcHKkzvRc1ghSYvOhRZT2TNqiCTit0eS0yLbeMOYIpirn+X8ZTpb5R7Z0l2OEBA hSZbwscWo+D2NoUysXexwE6i36wzTazInGUFFVPmEAS4hQPZgIBBghTXYnGeSEpCuWfz JQB5r5Jzf8PWRRVjbSFoY84YoG6zxjJ9mjpSUmct4n15RPMw39zpXEDHDjkx5ipluC/u CBAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AA8xkoGy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108970-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p21-20020a170902ead500b001dccce7a4afsi12617967pld.241.2024.03.20.06.49.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 06:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AA8xkoGy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108970-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id ACE81285AC6 for ; Wed, 20 Mar 2024 13:49:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 955FE44C93; Wed, 20 Mar 2024 13:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AA8xkoGy" 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 ABA1645974; Wed, 20 Mar 2024 13:49:41 +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=1710942581; cv=none; b=HKiLDtDBJsshcwfM+yI0AVpDs2OpkXNfP52H4+X8uLDXSbXvmU1XNSMCeCKXcYXFLceSHdp96I9p3rONW+JJQl0oJ/rYW8YDs7P3aasJDFo/uLBAZhtz6I0NmU5HJF3Qd84y+vU3VJmsy8ikDwasd5QsbubyoKwt1ZWg6wwJIKM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710942581; c=relaxed/simple; bh=EAbJvDEPuUAEHqsHcIRB3brQrJYzFil/dHVXDW9zweU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sc5P2eoe+spqfhiMoKgKMEW5i+JC/xVEt1ifSU5uLtGT8KyWTWrJMIfKhvQ0nUlFPBDenZMojDLVrXSZOTQiRSpXTFmJTfJvkaaBZGHh5w0X+Re6YhBvd/+VlOujbwjADBLwYr5Z7jCclizmIyLddpb0T/mpri42dqfuWqOQgeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AA8xkoGy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E0C2C43330; Wed, 20 Mar 2024 13:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710942581; bh=EAbJvDEPuUAEHqsHcIRB3brQrJYzFil/dHVXDW9zweU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AA8xkoGyJTDUSmLTVP3F3lutWqk879LSCt3IDdjao/9DHtBwzFCbmcgycwK9ECMBs 5hUQ90mYCPnEQqHiJvSwm08EE1h3ZvW0QzhsD5g3jRoNpY5cVeh3TbSM9hhUW2XPwp mUiQID8k/GrCYhSxLa1A1ChsHXo67+IH7AgkZDmRbYAl/BPIPhUaydmBoBlzrbttPX Z1cviJzRTc07w3MAIamWlCEpBFznuCV5SmvsKoiQmpZ/hYpKHzaJHqxwyTs7M360Jf L6BM0ekPACyf1RcWfaLSyFs7N6f4ptbTc1eDrSdOPdfuD5PsLzeCyZwQHYq0C4o5AM 1lGTvdPT9SsyQ== Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a4644bde1d4so885777366b.3; Wed, 20 Mar 2024 06:49:41 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWxw2sTxIBQhdvbAz1z+idq/GilEPCG9Pj0cv2NG2kZp852gyRxPZwU4h1KGJmOd3ptI76x0LHcOedNsdZDkE8UuIVK1D3qc3tjkzZ9dZiZovEZxFq8hDRfYa74lUHrYoyKR8MYRXM/Gs6oR0a7Lb1h05mv3SX1cqrmOUSbOEWNbQ== X-Gm-Message-State: AOJu0YzL7nN0AzdipP8YiLuIhWg4Ss/9cYbD5HgbleKNeGjByCeMALGd PK2zej89txIgIRXcOpNnrgHnoNA1/ESyBvSuaUzgfvTntlTGjeZ4kty231Z+h4gCN23tOsD/SDS AjeV7hQ7poYpI7SXkP6TrS7Mkzj0= X-Received: by 2002:a17:906:af07:b0:a46:1fba:2c6d with SMTP id lx7-20020a170906af0700b00a461fba2c6dmr1416970ejb.20.1710942579777; Wed, 20 Mar 2024 06:49:39 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240315024526.394772-1-chenhuacai@loongson.cn> In-Reply-To: From: Huacai Chen Date: Wed, 20 Mar 2024 21:49:28 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: Change __my_cpu_offset definition to avoid mis-optimization To: Xi Ruoyao Cc: Huacai Chen , Arnd Bergmann , 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, stable@vger.kernel.org, Xiaotian Wu , Miao Wang , Xing Li , Hongchen Zhang , Rui Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Ruoyao, On Wed, Mar 20, 2024 at 6:27=E2=80=AFPM Xi Ruoyao wrot= e: > > On Fri, 2024-03-15 at 10:45 +0800, Huacai Chen wrote: > > 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". > > Ooops... I'm wondering why this issue has not blown up our systems > before. The referred GCC commit is far before LoongArch CPUs are taped. > > > 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 > > I suppose we should add Fixes: 5b0b14e550a0 ("LoongArch: Add > atomic/locking header") here. You are right, but since this patch is in loongarch-next for the pull request, I don't want to change things. Huacai > > > 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/inclu= de/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 o= ff) > > __my_cpu_offset =3D 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, = \ > > -- > Xi Ruoyao > School of Aerospace Science and Technology, Xidian University