Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp591678rwb; Fri, 13 Jan 2023 01:31:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWTosOiGGQZl/ZwHVYnmmrDJfzSyrr4nh7AsbLb9hj6q8FEHzg1WmNhugCpUjbrkFP+wVq X-Received: by 2002:a17:906:d1cc:b0:85f:5d72:1841 with SMTP id bs12-20020a170906d1cc00b0085f5d721841mr7521052ejb.39.1673602284697; Fri, 13 Jan 2023 01:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673602284; cv=none; d=google.com; s=arc-20160816; b=lu6Y/EbGzbIN9tWgWlMvP5q8+KTsb8owBCMNYVIHysJiIKpv+FKRgm0gKPozcCj+UD zhXd7LLIo9hvuRxfN/xJ3cOgeMunf4prXZxvKQ2UxuRRGepoVoZNSdmrduF7bBk04c7/ A19lTFTKDSew2Ys/srZeFDUAGZj4hPnsNhm+Gppr+P6N9Ctv3h5hU9w/d8Wb4xyZqxjL rMhnK8xvzlQfxZrOguNRnukSiW/IOtSQ52gZcU7jjfZLKYCaw9cgL/ZNlEidQiULHP2v ceLE9WeuZoJHUlVR36+sgV15hhRxeEOm3w0Aj+PzPKVTc/RkyCUNXI9+HfVIZMoQCHeZ W3Wg== 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:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=E39P6xJFtKdnbgiloEzSc7PdC9n7NpO9iAPJ8YamLms=; b=zRhznJwiQDk/1dzaJFtR80KFkyIEphvekmnXobxpOly72ibZqjQJKW57Dl3ffbxdUe BCd64NRPdOkM4hAf8il08UGIYhf4Dq4pdSwos1697AXn5ChDY7NOO6masd0FuvN2vZe/ myheIr7K+jk+reZ337XpMrPxP454N1ucehDF9shVGBL4zSsVnGmxuLWO/eNYQ3np8phZ Dm4nIt9kMxr47ziyrphn4Ne6d4ieP/sytbol3xUhi3fXiAu34HecZhzG+fpK4neYramW lHzhGJ1wYvN6t/xmyk2XqKxV7livICnkX2AKsrQkihpIjw9aUlt/Tm6dICOdcRmCUDqk 1sVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jHwRJZYJ; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa11-20020a170906fd8b00b007c11812c621si21290336ejb.459.2023.01.13.01.31.12; Fri, 13 Jan 2023 01:31:24 -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=@redhat.com header.s=mimecast20190719 header.b=jHwRJZYJ; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241136AbjAMJ2R (ORCPT + 51 others); Fri, 13 Jan 2023 04:28:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240992AbjAMJ1P (ORCPT ); Fri, 13 Jan 2023 04:27:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D0256CFE4 for ; Fri, 13 Jan 2023 01:20:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673601627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E39P6xJFtKdnbgiloEzSc7PdC9n7NpO9iAPJ8YamLms=; b=jHwRJZYJOlbMye34UJd1QDO2OC/7OLox0JvkaMH6C1hVEnKXKzeBA/E0b78Rc5TWPfZ20u dLdlK00eG8eOuSZXf/LMFozd5gvp4nkq1rj4eH5aAai3Qh7vW7bS7ic/+UJpO0jxL1Kiq+ jsqm6To5lec5Cbt/LIKEuJtAxa8bpZ8= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-66-R6Igy8NsMnGmGemgLm0PfA-1; Fri, 13 Jan 2023 04:20:26 -0500 X-MC-Unique: R6Igy8NsMnGmGemgLm0PfA-1 Received: by mail-ej1-f72.google.com with SMTP id xj11-20020a170906db0b00b0077b6ecb23fcso14674175ejb.5 for ; Fri, 13 Jan 2023 01:20:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E39P6xJFtKdnbgiloEzSc7PdC9n7NpO9iAPJ8YamLms=; b=sSZZtSsL7ctl1ND1H/I+7VEtSwCxbn+vuPjB8pkmxtwab0OhSggt2vuE8MRD2gF8kq fZu+XmlRk/z1PetpSWLwjA5tpKsL9uPLWX1Qa76dV2w2MR5fTSqoD+ZXWylPTFyqu3N7 ezGKhaDd1nHXRnM6CTY8lFbQMEEHQlVeph+oZalwMcvUnQInV+p/VQVzZP3nF6TdPgpw 28qAWSJK78WXoNN/I1gnJq+pYsUhZuiBAv38Cm0rDX9JhwqE5/V0TXEYVOiBKKgIDRSi NowdmNxgED9Q7Oy5p+BRw88+wejerwRv9kt6t9MtfrlhXAV6JWIuGswwz1VB08dA1zE4 XU2A== X-Gm-Message-State: AFqh2krEiKNhrgMaVffjdvWjl6x9UG/p1DPXAQY9Bxhcy7aa88T5bHsR Okrd00yUPgEj0cWjR2wcaOQLms4HhQJVjBYDRXgEO9Ne6LsMAQZzN3TWLQssP6X7t7zCMqdm53b UmlhPTfyg04fxqz5gg37/3HbE X-Received: by 2002:a17:906:d052:b0:7c1:5098:907a with SMTP id bo18-20020a170906d05200b007c15098907amr70409399ejb.35.1673601625179; Fri, 13 Jan 2023 01:20:25 -0800 (PST) X-Received: by 2002:a17:906:d052:b0:7c1:5098:907a with SMTP id bo18-20020a170906d05200b007c15098907amr70409391ejb.35.1673601624959; Fri, 13 Jan 2023 01:20:24 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:63a7:c72e:ea0e:6045? ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.googlemail.com with ESMTPSA id ad7-20020a170907258700b0084bfd0a117bsm8405899ejc.16.2023.01.13.01.20.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Jan 2023 01:20:24 -0800 (PST) Message-ID: Date: Fri, 13 Jan 2023 10:20:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] Documentation: kvm: fix SRCU locking order docs Content-Language: en-US To: Boqun Feng , "Paul E. McKenney" Cc: David Woodhouse , 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 References: <20230111183031.2449668-1-pbonzini@redhat.com> <20230112152048.GJ4028633@paulmck-ThinkPad-P17-Gen-1> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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/13/23 08:18, Boqun Feng wrote: > On Thu, Jan 12, 2023 at 07:20:48AM -0800, Paul E. McKenney wrote: >> 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. >> > > Please see if the follow patchset works: > > https://lore.kernel.org/lkml/20230113065955.815667-1-boqun.feng@gmail.com > > "I have been called. I must answer. Always." ;-) It's missing an important testcase; if it passes (does not warn), then it should work: CPU 1 CPU 2 ---------------------------- ------------------------------ mutex_lock(&m1); srcu_read_lock(&srcu1); srcu_read_lock(&srcu1); mutex_lock(&m1); srcu_read_unlock(&srcu1); mutex_unlock(&m1); mutex_unlock(&m1); srcu_read_unlock(&srcu1); This is the main difference, lockdep-wise, between SRCU and an rwlock. Paolo