Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1787935rwb; Thu, 19 Jan 2023 15:42:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXsSDwGpPblEARb5PBkzESi9J45BS60F/w5Y4wQym6yETZDuwggorXGHk9CKZu+9vAYqxeXW X-Received: by 2002:aa7:8f09:0:b0:587:364f:17f5 with SMTP id x9-20020aa78f09000000b00587364f17f5mr33154600pfr.7.1674171746258; Thu, 19 Jan 2023 15:42:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674171746; cv=none; d=google.com; s=arc-20160816; b=WiBx+wRJ4xAcWkldhsg2+zkht76kuVJSWHIETSMZKqrtNpp+MwP7SwSeXVL83sH/97 l0AKUVeSFzvYCSJZpMhGBkGBexhoeb/Gu5gcjtcmR2AdUNRDQqKJicO3ZLWkPQL4l5mi 3TGJMC9N0C4wR01dpVVDtud0COZEj45FUm7WYJdJpWTOUr0YcrBIq0sh9IMeg2zNinnK B4GWsBqhjUDEnD4vxnsvVKFS5mnDuZ1nff1a0POFU7cEfJELL6JlnfDyZbYyravQ+Ncq kw0Mc/cMS9uVlw2p8usbd/9024pMIkQx+OlUy43HLwBo7FZ/F2+EnA3fPxbT3guTMCcm 62pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=mB+S2OL/onaREtdsOFqYqpBqpOmFKA2iVsUxG9eT0bM=; b=mJ9W9ue9isu9gR2xMfcKsAZLVBggWcL5h2LkWm7u2bBcbsJQu1rFspBN8ZM0MghPDE qeJKF8GDIJWMs8SmW0YlpqsXQ2zVDtP2fa/pfxcMwurfDVTb7JIGBQDnknOHMwhchWyM 8HGomFKBnc1rDtDyltUUKAn4U6UpQFqm7NhNLbK8UES6HMZrGYTBzNvoBZOWp8OzjpR8 YWVdSBF632dqvH1vlW09kbWOh+GEAaQpgFkWb7o7uwcxX9u1hir61iSpiy552ARZhu2F CqYw/2kp09YvMxwTcVtwQ/M3hpBXkB0CIPJpXn+x8d19pZCv1t+BTgNT6TgIcth414BL vsZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=no4JGYGJ; 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 q2-20020a056a00150200b00563a0453c55si21185757pfu.268.2023.01.19.15.42.20; Thu, 19 Jan 2023 15:42:26 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=no4JGYGJ; 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 S230457AbjASXLw (ORCPT + 46 others); Thu, 19 Jan 2023 18:11:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbjASXL0 (ORCPT ); Thu, 19 Jan 2023 18:11:26 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BCBA838A for ; Thu, 19 Jan 2023 15:03:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id C4872CE25BD for ; Thu, 19 Jan 2023 23:03:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DE15C433D2; Thu, 19 Jan 2023 23:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674169401; bh=PnW6JmMe4/FWLfJmhEnYnN46VQgwGO5FtbcMab52fRM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=no4JGYGJzpL1XvlpHM0yZj6OlixeBlL0rx/jCLfGINm+BpkUqUz86PdfrW6Nhbe0r Z83y//2mFElk/Ax8ZBie0Vq/lb3xUhmaMN3ViN2lfbCjXE+RY+0dS74okH/mKRdKy1 V49TH8lrneEyw/dhFMn2qjbY5yP+dpKZzpRGTnaKXmZ+VARqarVC7C7RpcMds+Zjta YZExZx4c2E41UES32NGsel9mwgerqKVUDed+mcXeTx2wv/t/HsOCufbYKadUP+0XNf Hie+7sCf2Fa4tSeC3y8b7f5TncBBLFKMWCAZ7BpY/el+LdLmO699xZGd31PrQDsSrL /NBd0LjEPd0nw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id A32C85C1B07; Thu, 19 Jan 2023 15:03:20 -0800 (PST) Date: Thu, 19 Jan 2023 15:03:20 -0800 From: "Paul E. McKenney" To: Alan Stern Cc: Jonas Oberhauser , 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 Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test) Message-ID: <20230119230320.GB2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <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> <20230119215304.GA2948950@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Thu, Jan 19, 2023 at 05:04:49PM -0500, Alan Stern wrote: > On Thu, Jan 19, 2023 at 01:53:04PM -0800, Paul E. McKenney wrote: > > On Thu, Jan 19, 2023 at 02:51:53PM -0500, Alan Stern wrote: > > > Index: usb-devel/tools/memory-model/linux-kernel.bell > > > =================================================================== > > > --- usb-devel.orig/tools/memory-model/linux-kernel.bell > > > +++ usb-devel/tools/memory-model/linux-kernel.bell > > > @@ -53,38 +53,30 @@ let rcu-rscs = let rec > > > in matched > > > > > > (* Validate nesting *) > > > -flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking > > > -flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking > > > +flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-lock > > > +flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-unlock > > > > This renaming makes sense to me. > > But I'll put it in a separate patch, since it's not related to the main > purpose of this change. Even better! > > > (* Compute matching pairs of nested Srcu-lock and Srcu-unlock *) > > > -let srcu-rscs = let rec > > > - unmatched-locks = Srcu-lock \ domain(matched) > > > - and unmatched-unlocks = Srcu-unlock \ range(matched) > > > - and unmatched = unmatched-locks | unmatched-unlocks > > > - and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc > > > - and unmatched-locks-to-unlocks = > > > - ([unmatched-locks] ; po ; [unmatched-unlocks]) & loc > > > - and matched = matched | (unmatched-locks-to-unlocks \ > > > - (unmatched-po ; unmatched-po)) > > > - in matched > > > +let srcu-rscs = ([Srcu-lock] ; (data | rf)+ ; [Srcu-unlock]) & loc > > > > The point of the "+" instead of the "*" is to avoid LKMM being confused by > > an srcu_read_lock() immediately preceding an unrelated srcu_read_unlock(), > > right? Or am I missing something more subtle? > > No, and it's not to avoid confusion. It merely indicates that there has > to be at least one instance of data or rf here; we will never have a > case where the lock and the unlock are the same event. Got it, thank you! > > > (* Validate nesting *) > > > -flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking > > > -flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking > > > +flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-lock > > > +flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-unlock > > > +flag ~empty (srcu-rscs^-1 ; srcu-rscs) \ id as multiple-srcu-matches > > > > > > (* Check for use of synchronize_srcu() inside an RCU critical section *) > > > flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep > > > > > > (* Validate SRCU dynamic match *) > > > -flag ~empty different-values(srcu-rscs) as srcu-bad-nesting > > > +flag ~empty different-values(srcu-rscs) as bad-srcu-value-match > > > > > > (* Compute marked and plain memory accesses *) > > > let Marked = (~M) | IW | Once | Release | Acquire | domain(rmw) | range(rmw) | > > > - LKR | LKW | UL | LF | RL | RU > > > + LKR | LKW | UL | LF | RL | RU | Srcu-lock | Srcu-unlock > > > let Plain = M \ Marked > > > > > > (* Redefine dependencies to include those carried through plain accesses *) > > > -let carry-dep = (data ; rfi)* > > > +let carry-dep = (data ; [~ Srcu-unlock] ; rfi)* > > > > The "[~ Srcu-unlock]" matches the store that bridges the data and rfi", > > correct? > > Right. > > > > let addr = carry-dep ; addr > > > let ctrl = carry-dep ; ctrl > > > let data = carry-dep ; data > > > Index: usb-devel/tools/memory-model/linux-kernel.def > > > =================================================================== > > > --- usb-devel.orig/tools/memory-model/linux-kernel.def > > > +++ usb-devel/tools/memory-model/linux-kernel.def > > > @@ -49,8 +49,10 @@ synchronize_rcu() { __fence{sync-rcu}; } > > > synchronize_rcu_expedited() { __fence{sync-rcu}; } > > > > > > // 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); } > > > > And here srcu_down_read() and srcu_up_read() are synonyms for > > srcu_read_lock() and srcu_read_unlock(), respectively, which I believe > > should suffice. > > > > > synchronize_srcu(X) { __srcu{sync-srcu}(X); } > > > synchronize_srcu_expedited(X) { __srcu{sync-srcu}(X); } > > > > So this looks quite reasonable to me. > > Okay, good. In theory we could check for read_lock and read_unlock on > different CPUs, but I don't think it's worth the trouble. Given that lockdep already complains about that sort of thing in the Linux kernel, agreed, it is not worth much trouble at all. Thanx, Paul