Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp346865imn; Wed, 27 Jul 2022 07:54:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vY6NQy7sDGwtlGx45qy5GCQA02X5idEWMazYbZW6VshZHKWWLzwFOGSuzU7JwVsjCTJJjr X-Received: by 2002:a17:907:6096:b0:72f:1d74:b71b with SMTP id ht22-20020a170907609600b0072f1d74b71bmr18309572ejc.272.1658933696595; Wed, 27 Jul 2022 07:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658933696; cv=none; d=google.com; s=arc-20160816; b=X1MjCjJk006lXmFWuh/1q1jO3bd9qAMZygiroxzcmUT0Pz7SL+3sKSyYY/WsQ1BVKn nnp7Wtm4UGQqfyksw4EB86DmQ8JBBZzq5rkrMz5P95utkxCIs4l7uZqSesYVzKxF0tlv VST5RAKUrpfATjrzwo1aqxjuRXvhb24B3YVO7vgIPkMQrOuy7+CJbPjQ/9Bgwmj606y7 +hBxO3XHC+Pmsi328WM3coz6Onz4IIlyXuzbQLVq1cKe2HaqyP1TvLPDsloA9K0mdHZ2 I9fEMltzTTs28TVkeZSDu7IuqveIyedUDmHMkA9T8PL5KIAgwnnPnAC0TsuQGvv/JpP3 3Ttw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=xuFpOaXJaj/gAOk0ci5YpbcXaLPN1T4Ab/tSiyAfQzA=; b=VWOsKRBprzzfw313ayQlrYIgV51fOQ3wQNHVIj06zPLs0btP4iNlLtiNhCS1JsNZcN hdWHfDisFLl7duHachXDr5rwfQO2mjXokyqw9iQd/W4FVK7WEB5qFkqaTgt1N5FU0SYh U+QoLKDDup+rPROJDNhNZCareW8KTgtXoPMF/1FMBcESwqQMW7JaVzzVw+DwatZ1mFw5 BZE73tTF2rTVf51FKt+1qcNl7AWTv4lN8lNkD/2eCkx7lTAb6hLx9T0dISCYDJMbhxoJ +rDE3CQ0BjN94E6DnYcsF9aLmtRm0LG4kBFUNzZRGvD/tx2ZrsQLUElevkr44jrjUh59 GVeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EzTr3jpc; 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 i14-20020a1709064ece00b00726ecb64f2esi5289678ejv.416.2022.07.27.07.54.29; Wed, 27 Jul 2022 07:54:56 -0700 (PDT) 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=EzTr3jpc; 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 S234121AbiG0Oqv (ORCPT + 99 others); Wed, 27 Jul 2022 10:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233343AbiG0Oqu (ORCPT ); Wed, 27 Jul 2022 10:46:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 502C21EC68 for ; Wed, 27 Jul 2022 07:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658933208; 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=xuFpOaXJaj/gAOk0ci5YpbcXaLPN1T4Ab/tSiyAfQzA=; b=EzTr3jpc6kPxoCbFYwAUEIoTfmrZOPhUUPijqNTdlS4XG0drK/IpPrBBEKb9oGO1+2mqAH 801GwC4ADlWLPSJI6PVhdvJLNkGpehL9h9uvdOL4wO+86rsYKrMeC/BN4x/5yc3wboTFqV QPuN/3Ucva3NTvp5b16GaAKmPanQ338= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-zjaeplmAPJ668snlUMnWUQ-1; Wed, 27 Jul 2022 10:46:42 -0400 X-MC-Unique: zjaeplmAPJ668snlUMnWUQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FA543C10222; Wed, 27 Jul 2022 14:46:42 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id E06FA1415121; Wed, 27 Jul 2022 14:46:40 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <1822b768504.1d4e377e236061.5518350412857967240@siddh.me> References: <1822b768504.1d4e377e236061.5518350412857967240@siddh.me> <20220723135447.199557-1-code@siddh.me> To: Siddh Raman Pant Cc: dhowells@redhat.com, "Greg KH" , "Christophe JAILLET" , "Eric Dumazet" , "Fabio M. De Francesco" , "linux-security-modules" , "linux-kernel-mentees" , "linux-kernel" , "syzbot+c70d87ac1d001f29a058" Subject: Re: [PATCH] kernel/watch_queue: Make pipe NULL while clearing watch_queue MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3558069.1658933200.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 27 Jul 2022 15:46:40 +0100 Message-ID: <3558070.1658933200@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Siddh Raman Pant wrote: > Greg KH wrote: > > > - spin_unlock_bh(&wqueue->lock); > > > rcu_read_unlock(); > > > > Also you now have a spinlock held when calling rcu_read_unlock(), are > > you sure that's ok? Worse, we have softirqs disabled still, which might cause problems for rcu_read_unlock()? > We logically should not do write operations in a read critical section, = so the > nulling of `wqueue->pipe->watch_queue` should happen after rcu_read_unlo= ck(). > Also, since we already have a spinlock, we can use it to ensure the null= ing. > So I think it is okay. Read/write locks are perhaps misnamed in this sense; they perhaps should b= e shared/exclusive. But, yes, we *can* do certain write operations with the lock held - if we're careful. Locks are required if we need to pairs of related memory accesses; if we're only making a single non-dependent write= , then we don't necessarily need a write lock. However, you're referring to RCU read lock. That's a very special lock th= at has to do with maintenance of persistence of objects without taking any ot= her lock. The moment you drop that lock, anything you accessed under RCU prot= ocol rules should be considered to have evaporated. Think of it more as a way to have a deferred destructor/deallocator. So I would do: + + /* Clearing the watch queue, so we should clean the associated pipe. */ + if (wqueue->pipe) { + wqueue->pipe->watch_queue =3D NULL; + wqueue->pipe =3D NULL; + } + spin_unlock_bh(&wqueue->lock); rcu_read_unlock(); } However, since you're now changing wqueue->pipe whilst a notification is b= eing posted, you need a barrier in post_one_notification() to prevent the compi= ler from reloading the value: struct pipe_inode_info *pipe =3D READ_ONCE(wqueue->pipe); David