Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp459840rwb; Thu, 12 Jan 2023 08:12:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXvWi9Ido80MJlQ1ezOz3uniEwJv0FRoV1HLAoIAES84OiiKioMS4gYWB46m4Jal2nF5jDT/ X-Received: by 2002:a17:906:3a85:b0:7c4:f0b5:fedc with SMTP id y5-20020a1709063a8500b007c4f0b5fedcmr64964938ejd.65.1673539947533; Thu, 12 Jan 2023 08:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673539947; cv=none; d=google.com; s=arc-20160816; b=eqI3tZtPMqu+az9HGdAiHMQpbpbcSC1i+If3dpnEhQpUrT3Jdl1c2/h8YXqBZ/og6h AlyzZhbti95rshLIy3Ybd4LAx4X7l6j23Oo3DuBV00P8xcjvDLr+gKpRQ9xAR6gPYCRx nC+Fk54PzmJiCUIaB/P1EoL8YNeI6BnA3Fixd8ErOBMoq1g27wA5JAj944iFX+s1dz/O TK+yVJsJ6mpdacRvfY4pxNR50ySVxkV1edm1Mk154VefJ4cq7/m1nYpZOVP8o3Ccavf3 pkiWNK5RLSViiJL82oUD36+UFhieabwsLBGgPH6MZxIEc7AxdT+XEXEKGzqcaS5eoxPM OOFg== 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-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=iQzipqA6tU7QZC99KHnNJid22R8cQUzLeaqWBKvJHFc=; b=0mNyhSoNFohf31N22A9Agr38F38LRUaIaRHA8vkHDzTrv4MCt0+0xzCQNAqv6CzTME HsaFdSsDeKQnCLBGj0tRUD6AUSMgDZFQXz9msVRbgb+JgTVAuCgf1Yc5AUIME7tbLr5o KLlK27+0WVZLvNcobBQZ0CjqVHJBnrXfXzO6bxyyem0ZS/89yGTxOOoExRCTwpJHB7Yn E7l4ZwEMSW2zVKQxZXG1sLqCybDEHXYFOtgz7zd1UStWNYmmHk0qJlUKqFBf1KmEvtJS I8WbKOKXIKEsEq3rHsRB3S6Z6voysZBsnGXJD2tN/rszU/0zTSzo4Vx6tFknytT/t1cb Cdqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rLIAB4+Y; 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 xf3-20020a17090731c300b0084e3eac46ccsi9272546ejb.585.2023.01.12.08.12.14; Thu, 12 Jan 2023 08:12:27 -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=rLIAB4+Y; 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 S240392AbjALP3x (ORCPT + 50 others); Thu, 12 Jan 2023 10:29:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240425AbjALP2d (ORCPT ); Thu, 12 Jan 2023 10:28:33 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCAFC78; Thu, 12 Jan 2023 07:20:52 -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 E5A8ACE1E5E; Thu, 12 Jan 2023 15:20:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0AD5C433EF; Thu, 12 Jan 2023 15:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673536849; bh=BCtqMXLEe/UrckfTQBcikiufFT6uV7gISnRdD1HnshI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=rLIAB4+YH0UkEjySHkRENtPC/rBWbpv589rl+z7ZX09HHf3UqIEsEYEaOSAFTkLhH Xp8o8rGAg+HFhCmfPublTEgYRnW3MkEvPuprCQm7z5gyJG2R0ZlkTkv+llEUd/qhT9 9hX143H78hyJzyub1ma/iIkrxUozsRG2th0G0+TgBBkdhWsbrmO4307R55MVVFoJ9U d+KyF3qo+ozgNPR2vuugPofojy6gHDiU0BSiW4laDRPOoqnnWv59bmyORkJzRajufJ t8v6oABnPEVmBdBJMjusHsRGRai3V4AbFqK75vsPhb8fHZo4sEMLIDoenZ/lTMrAjQ ZaZGtbbqXRi7A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 933835C0AF8; Thu, 12 Jan 2023 07:20:48 -0800 (PST) Date: Thu, 12 Jan 2023 07:20:48 -0800 From: "Paul E. McKenney" To: David Woodhouse Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, seanjc@google.com, Joel Fernandes , Matthew Wilcox , Josh Triplett , rcu@vger.kernel.org, Michal Luczaj , Peter Zijlstra Subject: Re: [PATCH] Documentation: kvm: fix SRCU locking order docs Message-ID: <20230112152048.GJ4028633@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230111183031.2449668-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 12, 2023 at 08:24:16AM +0000, David Woodhouse wrote: > On Wed, 2023-01-11 at 13:30 -0500, Paolo Bonzini wrote: > > > > +- ``synchronize_srcu(&kvm->srcu)`` is called inside critical sections > > +? for kvm->lock, vcpu->mutex and kvm->slots_lock.? These locks _cannot_ > > +? be taken inside a kvm->srcu read-side critical section; that is, the > > +? following is broken:: > > + > > +????? srcu_read_lock(&kvm->srcu); > > +????? mutex_lock(&kvm->slots_lock); > > + > > "Don't tell me. Tell lockdep!" > > Did we conclude in > https://lore.kernel.org/kvm/122f38e724aae9ae8ab474233da1ba19760c20d2.camel@infradead.org/ > that lockdep *could* be clever enough to catch a violation of this rule > by itself? > > The general case of the rule would be that 'if mutex A is taken in a > read-section for SCRU B, then any synchronize_srcu(B) while mutex A is > held shall be verboten'. And vice versa. > > If we can make lockdep catch it automatically, yay! Unfortunately, lockdep needs to see a writer to complain, and that patch just adds a reader. And adding that writer would make lockdep complain about things that are perfectly fine. It should be possible to make lockdep catch this sort of thing, but from what I can see, doing so requires modifications to lockdep itself. > If not, I'm inclined to suggest that we have explicit wrappers of our > own for kvm_mutex_lock() which will do the check directly. This does allow much more wiggle room. For example, you guys could decide to let lockdep complain about things that other SRCU users want to do. For completeness, here is one such scenario: CPU 0: read_lock(&rla); srcu_read_lock(&srcua); ... CPU 1: srcu_read_lock(&srcua); read_lock(&rla); ... CPU 2: synchronize_srcu(&srcua); CPU 3: write_lock(&rla); ... If you guys are OK with lockdep complaining about this, then doing a currently mythical rcu_write_acquire()/rcu_write_release() pair around your calls to synchronize_srcu() should catch the other issue. And probably break something else, but you have to start somewhere! ;-) Thanx, Paul