Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C3D5C05027 for ; Thu, 26 Jan 2023 16:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbjAZQcH (ORCPT ); Thu, 26 Jan 2023 11:32:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjAZQcF (ORCPT ); Thu, 26 Jan 2023 11:32:05 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A6C0210A for ; Thu, 26 Jan 2023 08:32:00 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4P2mHJ46hQz9xFHQ for ; Fri, 27 Jan 2023 00:23:56 +0800 (CST) Received: from [10.48.129.37] (unknown [10.48.129.37]) by APP1 (Coremail) with SMTP id LxC2BwD3eATbqtJjJCbMAA--.816S2; Thu, 26 Jan 2023 17:31:35 +0100 (CET) Message-ID: <10cfb309-4a12-2b57-e367-b5224a442685@huaweicloud.com> Date: Thu, 26 Jan 2023 17:31:20 +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: [Patch 2/2] tools/memory-model: Provide exact SRCU semantics To: Alan Stern Cc: "Paul E. McKenney" , 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: From: Jonas Oberhauser In-Reply-To: Content-Type: text/plain;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0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyT uYvjxUFDGOUUUUU X-CM-SenderInfo: 5mrqt2oorev25kdx2v3u6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/26/2023 5:02 PM, Alan Stern wrote: > On Thu, Jan 26, 2023 at 12:30:14PM +0100, Jonas Oberhauser wrote: >> >> On 1/25/2023 11:52 PM, Alan Stern wrote: >>> On Wed, Jan 25, 2023 at 10:04:29PM +0100, Jonas Oberhauser wrote: >>>> On 1/25/2023 9:21 PM, Alan Stern wrote: >>>>> (* Validate nesting *) >>>>> flag ~empty Srcu-lock \ domain(srcu-rscs) as unmatched-srcu-lock >>>>> flag ~empty Srcu-unlock \ range(srcu-rscs) as unmatched-srcu-unlock >>>>> +flag ~empty (srcu-rscs^-1 ; srcu-rscs) \ id as multiple-srcu-matches >>>> [...] >>>>> // SRCU >>>>> -srcu_read_lock(X) __srcu{srcu-lock}(X) >>>>> -srcu_read_unlock(X,Y) { __srcu{srcu-unlock}(X,Y); } >>>>> +srcu_read_lock(X) __load{srcu-lock}(*X) >>>>> +srcu_read_unlock(X,Y) { __store{srcu-unlock}(*X,Y); } >>>>> +srcu_down_read(X) __load{srcu-lock}(*X) >>>>> +srcu_up_read(X,Y) { __store{srcu-unlock}(*X,Y); } >>>> How do you feel about introducing Srcu-up and Srcu-down with this patch? >>> Why invent new classes for them? They are literally the same operation >>> as Srcu-lock and Srcu-unlock; the only difference is how the kernel's >>> lockdep checker treats them. >> I don't think they're necessarily implemented in a compatible way, so >> >> r = srcu_lock(s); >> srcu_up(s,r); >> >> might not actually work, but would currently be ok'ed by LKMM. > I'll let Paul answer this. > >> With >> different classes you could state >>   flag ~empty [Srcu-lock];srcu-rscs;[Srcu-up] as srcu-mismatch-lock-to-up >>   flag ~empty [Srcu-down];srcu-rscs;[Srcu-unlock] as >> srcu-mismatch-down-to-unlock >> >> I think with the current implementation this code might work, but I don't >> feel like this is inherently true. >> >> You could then also go ahead and define the "same CPU" requirement as a flag >> for lock and unlock specifically, like >>   flag ~empty [Srcu-lock];srcu-rscs & ext as srcu-lock-unlock-mismatch-CPU >> or so. > Bear in mind that the herd7 model is not obliged to find and warn about > all possible bugs in a litmus test. Especially if the same code would > generate a warning or error when run in the kernel. I  agree, and indeed it may not even possible to do so (even under a hypothetical formal proof that the list of bugs is complete, some might not be formalizable in a satisfactory way in herd). Mostly I'm just trying to see if you have considered the possibilities and decided against them intentionally, or if you just hadn't considered it. I don't have a strong opinion either way and would be ok with the patch as written. That said, I do like to think of the model as a kind of compact formal specification/documentation, including the assumptions the kernel makes about how these APIs are to be used. Best wishes, jonas