Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2403446rwb; Fri, 20 Jan 2023 02:26:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtkJt9tWK1G5KFjwCrJDsvYh6XnTEkfvdYr9fxhF5j1CdsEL5f3ALhMTURbREGmlby1zHn/ X-Received: by 2002:aa7:972e:0:b0:58d:b330:6e7d with SMTP id k14-20020aa7972e000000b0058db3306e7dmr16531716pfg.26.1674210417217; Fri, 20 Jan 2023 02:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674210417; cv=none; d=google.com; s=arc-20160816; b=DTVWYD4Lw6DCQ/r44719vHPnHYF126ZsFu7QQmrgEDGHg7AhylFzUH4NZ/y3IJjksO 9ahfAeuT3Jwm/OfAVEDWxe5Cqm+g4lONlR2LYUsEOiYixJ41wC1d7v3fCjgHZvnzF+vs 70rETMXsFQK6Z2BwGZBbwkjzBb8dsGUFrf4TrDNdG13id4kvMiC5zJUwMXUu4zh0egVV q3Jjh6UZB060awhNlaI65MFQq4iYxK5VrpZbrSfTU8LVtgMYDsMZ8novajtflgvacPB8 vU5pNUW7IABJX/a2oR5z1jIYPalh8ht/bX4ksldGN+bh6SJ32mmE2WbG9xZUT1Ss8evS YY3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=IrEzDd2fbgubQBfTecCSxquX5bU1prY0C9miBGqMBRw=; b=q3N/MZmy/mwMAb1tgy+Uio5lz3VkLiUaSa2RqhqIkWzTL8TWychgbre7OjL0wlgn4E dUrmoFTHaEEMtApVcsu1kQuw6E3YTH1koMd6oJCqDRgFmyuWXFrxMtXBMTOJ5uOC0yLD ML8r4mcMKXBlODvU8M3vUI2QlAwGxOZoWBSn1A0ZjCee7zo6IhwZqc8YftcxIXgpzyRl YvcgfQo80/qaWJLllu7yH4bDJ2wzp+KrXhMZC+VpCUWtS/DcBFQB7YymrV384wucvD72 CgWEOdqwTMGcnQEh3Qr4mn92bJHzWc8/pxK9KIbZvxleIrVmEspDvRj62TZ/t8A2NY3u ke3A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a056a00231000b0056c882d3d06si44858064pfh.199.2023.01.20.02.26.51; Fri, 20 Jan 2023 02:26:57 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjATKNl (ORCPT + 48 others); Fri, 20 Jan 2023 05:13:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjATKNj (ORCPT ); Fri, 20 Jan 2023 05:13:39 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334A2891E7 for ; Fri, 20 Jan 2023 02:13:38 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4Nyw9b4Bw3z9y0kg for ; Fri, 20 Jan 2023 18:05:39 +0800 (CST) Received: from [10.48.133.21] (unknown [10.48.133.21]) by APP2 (Coremail) with SMTP id GxC2BwDXXWQvacpjZRCvAA--.43987S2; Fri, 20 Jan 2023 11:13:14 +0100 (CET) Message-ID: <64b48a7b-624c-26bd-be9b-0522fc490b28@huaweicloud.com> Date: Fri, 20 Jan 2023 11:13:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test) To: paulmck@kernel.org Cc: Alan Stern , Andrea Parri , Jonas Oberhauser , Peter Zijlstra , will , "boqun.feng" , npiggin , dhowells , "j.alglave" , "luc.maranget" , akiyks , dlustig , joel , urezki , quic_neeraju , frederic , Kernel development list References: <20230118035041.GQ2948950@paulmck-ThinkPad-P17-Gen-1> <3dabbcfb-858c-6aa0-6824-05b8cc8e9cdb@gmail.com> <20230118201918.GI2948950@paulmck-ThinkPad-P17-Gen-1> <20230118211201.GL2948950@paulmck-ThinkPad-P17-Gen-1> <09f084d2-6128-7f83-b2a5-cbe236b1678d@huaweicloud.com> <20230119001147.GN2948950@paulmck-ThinkPad-P17-Gen-1> <0fae983b-2a7c-d44e-8881-53d5cc053f09@huaweicloud.com> <20230119184107.GT2948950@paulmck-ThinkPad-P17-Gen-1> From: Jonas Oberhauser In-Reply-To: <20230119184107.GT2948950@paulmck-ThinkPad-P17-Gen-1> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: GxC2BwDXXWQvacpjZRCvAA--.43987S2 X-Coremail-Antispam: 1UD129KBjvJXoWxZFyxCr4xXw4rJw43XryxXwb_yoW5GrykpF Z5tFZaywnrArn7uw1Iv3Wjqry0v34UJay5Xws5JrW8Aa98WFnIgr1Ig3WYgrZxur4xAr4j qrWYqasrZa1xJaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_ WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE 14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x07UZ18PUUUUU= X-CM-SenderInfo: 5mrqt2oorev25kdx2v3u6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS 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 1/19/2023 7:41 PM, Paul E. McKenney wrote: > On Thu, Jan 19, 2023 at 02:39:01PM +0100, Jonas Oberhauser wrote: >> >> On 1/19/2023 1:11 AM, Paul E. McKenney wrote: >>> On Wed, Jan 18, 2023 at 10:24:50PM +0100, Jonas Oberhauser wrote: >>>> What I was thinking of is more something like this: >>>> >>>> P0{ >>>>    idx1 = srcu_down(&ss); >>>>    srcu_up(&ss,idx1); >>>> } >>>> >>>> P1{ >>>>     idx2 = srcu_down(&ss); >>>>     srcu_up(&ss,idx2) >>>> } >>> And srcu_read_lock() and srcu_read_unlock() already do this. >> I think I left out too much from my example. >> And filling in the details led me down a bit of a rabbit hole of confusion >> for a while. >> But here's what I ended up with: >> >> >> P0{ >>     idx1 = srcu_down(&ss); >>     store_rel(p1, true); >> >> >>     shared cs >> >>     R x == ? >> >>     while (! load_acq(p2)); >>     R idx2 == idx1 // for some reason, we got lucky! >>     srcu_up(&ss,idx1); > Although the current Linux-kernel implementation happens to be fine with > this sort of abuse, I am quite happy to tell people "Don't do that!" > And you can do this with srcu_read_lock() and srcu_read_unlock(). > In contrast, this actually needs srcu_down_read() and srcu_up_read(): My point/clarification request wasn't about whether you could write that code with read_lock() and read_unlock(), but what it would/should mean for the operational and axiomatic models. As I wrote later in the mail, for the operational model it is quite clear that x==1 should be allowed for lock() and unlock(), but would probably be forbidden for down() and up(). My clarification request is whether that difference in the probable operational model should be reflected in the axiomatic model (as I first suspected based on the word "semaphore" being dropped a lot), or whether it's just due to abuse (i.e., yes the axiomatic model and operational model might be different here, but you're not allowed to look). Which brings us to the next point: > Could you please review the remainder to see what remains given the > usage restrictions that I called out above? Perhaps we could say that reading an index without using it later is forbidden? flag ~empty [Srcu-lock];data;rf;[~ domain(data;[Srcu-unlock])] as thrown-srcu-cookie-on-floor So if there is an srcu_down() that produces a cookie that is read by some read R, and R doesn't then pass that value into an srcu_up(), the srcu-warranty is voided. Perhaps it would also be good to add special tags for Srcu-down and Srcu-up to avoid collisions. always have fun, jonas