Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5428696rwb; Tue, 1 Aug 2023 02:20:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFBnJFp+jqyUcPWvyGF7YiRUNOtjEOqj3IDJS9aB/xB69LDSsLqVVmok8qL+CIi3It/oRuv X-Received: by 2002:a17:902:ce8b:b0:1b7:fd82:973c with SMTP id f11-20020a170902ce8b00b001b7fd82973cmr14732645plg.39.1690881607733; Tue, 01 Aug 2023 02:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690881607; cv=none; d=google.com; s=arc-20160816; b=crwn4kKxiGO1vNV/DlWKkNxe6LxDe3Br1eblD39HHP7zxi1Vv05ZsVB1Vgsz4YAV5v Dk/UqpJ30Hqszg1knMFgGCJ8tFIZ0l7SyszLTw0t77/OPhav+vcPB5ha0qxJmsvaAeHu Htkc9TWDb/uZLPNGdw7ZqbmYrFnkUZfzBLMYYR+YZ/lwxqvfrqzpGLyUihGDilxJ7WiD QB129SROiUfIgVo4ZVFfLB9K9CjXI6mkTWxxi/fgnHTh3V0yt2ZXxOuhouxyXocCDWWf vyO7F/W1YCTS2yleVlXSqsUBwjMohkKaiNf4j4iIv6J3otY8xWQ28zSReRz0JWTq3PHY RAmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RvyHh4jnNSdEErER51BdfMoQWrdPHIOkCtFbE0Fm89w=; fh=vAoEAjNZCjfQkEcdTrv/sg+0BydeFefaCjHXBJUqZyg=; b=yyq9b4yrRFMKZ5Vzuqt55+BmVZmqH986XZBRG+cL8JRS0z4nu/4V5tywz/xnUQrbP8 RXKlE6ipxLIQRX+pcQOeNC3zJlzURj3uY+JQV+Jj3qz0rhkzcCIYtIXzICofU3cfKNmE /TNxXbdx/cbyRULjgdIxo99cMz+KU/pk0s1nKnZea+4LRQV5G8NCdACAyIvyxqY1h1WR NXJeZW+2fS4fClkn4VTiew/rOIFCiNpjHAmgYNDsb0OvEtW1dxvr6MPWJhITMhUXN8YX 5BPbMq3tBXF7HWD8YYcsdLvj47Oq2JfYtF+MMMdYQrLYDMyMP9lBgR1+1BNksyuf9Rwr +Myw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L9Gz8w1Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170902d2c600b001b39e50bfdasi5903958plc.638.2023.08.01.02.19.55; Tue, 01 Aug 2023 02:20:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L9Gz8w1Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbjHAJKo (ORCPT + 99 others); Tue, 1 Aug 2023 05:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232823AbjHAJK2 (ORCPT ); Tue, 1 Aug 2023 05:10:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4536F46B7 for ; Tue, 1 Aug 2023 02:07:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C9BD614E1 for ; Tue, 1 Aug 2023 09:05:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF87CC43140 for ; Tue, 1 Aug 2023 09:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690880749; bh=ahFDZkG3uB6gt5CXk13eA4lfV0UiHUFqChNpbvLIrZk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=L9Gz8w1Y8zXgHls4hV9dnWrTg6XbW620mjJn1nYcUdu09Blf/K/IHj+85KJ6mqviJ P69WzDeCdaaVwLmh87f4EpDj6Um2vREBh6nwX6FHlOT75F1Tb6j6m+8tuDfN2uZInU JM+0EcwPO/gkDMuy2BT2gxrWNuPhGkqSSBpkGgD67zvdEi065neRqQEvpZ/gunH83D IwcDnwOS5bEE4IofrFQrG0+YbGzRpujvvhQ4WqFtAzQVrbPqbt650d8UXQn0AEGxpV 03gRdwMrmsN9b0+sHOhnYj213Z3xn/HRszJ8v0zg/2nNcWMwJazzbF7oVw2BnwK410 KjuFYBdcOxwIg== Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2b9f48b6796so13060511fa.3 for ; Tue, 01 Aug 2023 02:05:49 -0700 (PDT) X-Gm-Message-State: ABy/qLZSf0ISN5guPFlAWgGKd18YdCy1pfV9R8i7134a+8HeA0caTgnE XOP12q1MTh6Y7FLUJsP7xn60KDQTl2Cqo5Rr6aQ= X-Received: by 2002:a19:6908:0:b0:4f8:4512:c846 with SMTP id e8-20020a196908000000b004f84512c846mr1443298lfc.49.1690880747644; Tue, 01 Aug 2023 02:05:47 -0700 (PDT) MIME-Version: 1.0 References: <20230801011554.3950435-1-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 1 Aug 2023 17:05:35 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: Fixup cmpxchg sematic for memory barrier To: WANG Rui Cc: chenhuacai@kernel.or, kernel@xen0n.name, arnd@arndb.de, andi.shyti@linux.intel.com, andrzej.hajda@intel.com, peterz@infradead.org, will@kernel.org, boqun.feng@gmail.com, mark.rutland@arm.com, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Guo Ren Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 1, 2023 at 5:02=E2=80=AFPM Guo Ren wrote: > > On Tue, Aug 1, 2023 at 10:29=E2=80=AFAM WANG Rui wr= ote: > > > > Hello, > > > > On Tue, Aug 1, 2023 at 9:16=E2=80=AFAM wrote: > > > diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/in= clude/asm/cmpxchg.h > > > index 979fde61bba8..6a05b92814b6 100644 > > > --- a/arch/loongarch/include/asm/cmpxchg.h > > > +++ b/arch/loongarch/include/asm/cmpxchg.h > > > @@ -102,8 +102,8 @@ __arch_xchg(volatile void *ptr, unsigned long x, = int size) > > > " move $t0, %z4 \n" = \ > > > " " st " $t0, %1 \n" = \ > > > " beqz $t0, 1b \n" = \ > > > - "2: \n" = \ > > > __WEAK_LLSC_MB = \ > > > + "2: \n" = \ > > > > Thanks for the patch. > > > > This would look pretty good if it weren't for the special memory > > barrier semantics of the LoongArch's LL and SC instructions. > > > > The LL/SC memory barrier behavior of LoongArch: > > > > * LL: + > > * SC: + > > > > and the LoongArch's weak memory model allows load/load reorder for the > > same address. > The CoRR problem would cause wider problems than this.For this case, > do you mean your LL -> LL would be reordered? > > CPU 0 > CPU1 > LL(2) (set ex-monitor) > > store (break the ex-monitor) > LL(1) (reordered instruction set ex-monitor > SC(3) (successes ?) Sorry for the mail client reformat, I mean: CPU0 LL(2) (set ex-monitor) CPU1 STORE (break the ex-monitor) CPU0 LL(1) (reordered instruction set ex-monitor CPU0 SC(3) (success?) > > > > > So, the __WEAK_LLSC_MB[1] is used to prevent load/load reorder and no > > explicit barrier instruction is required after SC. > > > > [1] https://lore.kernel.org/loongarch/20230516124536.535343-1-chenhuaca= i@loongson.cn/ > > > > Regards, > > -- > > WANG Rui > > > > > -- > Best Regards > Guo Ren --=20 Best Regards Guo Ren