From patchwork Sat Nov 12 10:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddh Raman Pant X-Patchwork-Id: 19164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1221820wru; Sat, 12 Nov 2022 03:18:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Lv6kjiBilNAOsCTr5NpMtB2+5w4C5yCMHqnP7totTyLCORXQHPFWX+eGk7OFimOYzL+ax X-Received: by 2002:a17:90a:ab94:b0:212:ebfa:d8aa with SMTP id n20-20020a17090aab9400b00212ebfad8aamr6011638pjq.234.1668251921838; Sat, 12 Nov 2022 03:18:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668251921; cv=pass; d=google.com; s=arc-20160816; b=McPD16UQ7oRxzb1d2qNGqm63Oua8emuMhLJ/dX5QS6M48WLWOPzkB4iOmVY2EZjRvG SIfb+43VRv8PV72GLKOx5vkH3NGsl8omh5QVjyjXnE4IJXnVAeLELxFVA+8BrFCuMNuc vqq65D/XIc14jo/4Cqkf0vnLDP7Ez/IH6PXthqFqAgGN5V21F9dEDelc5hsHKmgIDZpT ehVUainw/hyDtYMBWWw2mFNEdQQPoLtXsURfEb0CycLuROwJKJ/8J7y4fDoE1yFqf7zi aCYkG9r9gjQzPTD0/DjMlrmaOC+0bR7MsHTGuGNkK8b/t6M3v8COXgciJPWW5FAACpY0 UiJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:message-id:cc:to:from :dkim-signature; bh=I7Q4D57L0Fon5Y8OnWeD+j+i4yBdJ+wVG0hPi+xhFQ8=; b=R3/PWaGMVqDAnE6yOflGaryx4BKil7Gm1RzG0TkayxveS1dobIPmTVXTWTo3NYX3yP Y6wTv8yDGkCKwF4xIRZeKg3FtQ64Ws+hcDMzGV/5aJFtO3jsyaTS4nA4zXfKqAruHPR1 +xAuj4rvt5/yfsjOI39avpjtc3Hqn28ITW4QKhgiIXIlQs0Nvr8n7yxBGO0GzryDuzIh iEEa4OIc7NlnyqS6IHG4JWFFu2jxLOlfO0BLLUMhPqH8X1bElVTkKya/k7ppMEG7QD/x duULkJZHdB79ZfJU2HjR3gn7ur0vauWNoDIm3btp3KZZ/MzZC2tQ8mm9EMaaxToSKyhd DTnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=Fi3TU3wB; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg22-20020a17090326d600b001868ef35f09si4588593plb.258.2022.11.12.03.18.27; Sat, 12 Nov 2022 03:18:41 -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=@siddh.me header.s=zmail header.b=Fi3TU3wB; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234824AbiKLLRf (ORCPT + 99 others); Sat, 12 Nov 2022 06:17:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234820AbiKLLR1 (ORCPT ); Sat, 12 Nov 2022 06:17:27 -0500 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81B8F1F607; Sat, 12 Nov 2022 03:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668249063; cv=none; d=zohomail.in; s=zohoarc; b=cCExhhTFEX3QBBDEO7eNkVH64rQHEy90REKBoYaxQvgaFH4AZlKHDMn8exZuW65rmWDMbCDWK7qP/lcgLSAjbfRyY0kOOMk4oKpRZCwaINRtegcQs7I8faLFuPyOT3TqIsvcVNGkHJYMaBN8HLTXNuz3kHB8YcGSIgZBN240O0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1668249063; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=I7Q4D57L0Fon5Y8OnWeD+j+i4yBdJ+wVG0hPi+xhFQ8=; b=UfU5qRrr5Xw5lMpe2TXVlG5nQNLpOizm3z7ffPbOl6+m/9Isl+ejHq35iFbPL929U8npPGk76RdzEuVljTTn0CRVawlhwLF8tINjrLYmlipwi2s953+El1VLr3f1YDfuk/rqnV2x9zUIKIbeBjoc0i0vd7fd+aBAVhX3+9Kihpk= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1668249063; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=I7Q4D57L0Fon5Y8OnWeD+j+i4yBdJ+wVG0hPi+xhFQ8=; b=Fi3TU3wBUF/MWae+TX25M+DpVcTzI7q7h4Re+i2nMNUP5mScOP8xWudmN6LlH7dt 039pWLOp6n4Wci7DwK61rRfc8d/0tHo5tYOfPWmFQ7NM310Gl6MLiX1aWuV7qcpOSYP A2CKstDiMgydjb7EvzdBSv+wrUoUNDXB3WeHqtcw= Received: from kampyooter.. (110.226.30.173 [110.226.30.173]) by mx.zoho.in with SMTPS id 1668249062205101.81942800584966; Sat, 12 Nov 2022 16:01:02 +0530 (IST) From: Siddh Raman Pant To: Mauro Carvalho Chehab , Randy Dunlap , David Howells , Jonathan Corbet , "Fabio M. De Francesco" , Eric Dumazet , Christophe JAILLET , Eric Biggers Cc: keyrings , linux-security-module , linux-fsdevel , linux-kernel Message-ID: <3cdc67df35a283c4d1a341d039d0c2251ff72930.1668248462.git.code@siddh.me> Subject: [RESEND PATCH v2 1/2] include/linux/watch_queue: Improve documentation Date: Sat, 12 Nov 2022 16:00:40 +0530 X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-ZohoMailClient: External X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLACK autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749288927146529510?= X-GMAIL-MSGID: =?utf-8?q?1749288927146529510?= Introduce kerneldoc-style comments, and document a couple of things explicitly. Signed-off-by: Siddh Raman Pant --- include/linux/watch_queue.h | 102 ++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index fc6bba20273b..7f8b1f15634b 100644 --- a/include/linux/watch_queue.h +++ b/include/linux/watch_queue.h @@ -18,57 +18,103 @@ struct cred; +/** + * struct watch_type_filter - Filter on watch type + * + * @type: Type of watch_notification + * @subtype_filter: Bitmask of subtypes to filter on + * @info_filter: Filter on watch_notification::info + * @info_mask: Mask of relevant bits in info_filter + */ struct watch_type_filter { enum watch_notification_type type; - __u32 subtype_filter[1]; /* Bitmask of subtypes to filter on */ - __u32 info_filter; /* Filter on watch_notification::info */ - __u32 info_mask; /* Mask of relevant bits in info_filter */ + __u32 subtype_filter[1]; + __u32 info_filter; + __u32 info_mask; }; +/** + * struct watch_filter - Filter on watch + * + * @rcu: RCU head (in union with type_filter) + * @type_filter: Bitmask of accepted types (in union with rcu) + * @nr_filters: Number of filters + * @filters: Array of watch_type_filter + */ struct watch_filter { union { struct rcu_head rcu; - /* Bitmask of accepted types */ DECLARE_BITMAP(type_filter, WATCH_TYPE__NR); }; - u32 nr_filters; /* Number of filters */ + u32 nr_filters; struct watch_type_filter filters[]; }; +/** + * struct watch_queue - General notification queue + * + * @rcu: RCU head + * @filter: Filter to use on watches + * @pipe: The pipe we're using as a buffer + * @watches: Contributory watches + * @notes: Preallocated notifications + * @notes_bitmap: Allocation bitmap for notes + * @usage: Object usage count + * @lock: To serialize accesses and removes + * @nr_notes: Number of notes + * @nr_pages: Number of pages in notes[] + * @defunct: True when queues closed + */ struct watch_queue { struct rcu_head rcu; struct watch_filter __rcu *filter; - struct pipe_inode_info *pipe; /* The pipe we're using as a buffer */ - struct hlist_head watches; /* Contributory watches */ - struct page **notes; /* Preallocated notifications */ - unsigned long *notes_bitmap; /* Allocation bitmap for notes */ - struct kref usage; /* Object usage count */ + struct pipe_inode_info *pipe; + struct hlist_head watches; + struct page **notes; + unsigned long *notes_bitmap; + struct kref usage; spinlock_t lock; - unsigned int nr_notes; /* Number of notes */ - unsigned int nr_pages; /* Number of pages in notes[] */ - bool defunct; /* T when queues closed */ + unsigned int nr_notes; + unsigned int nr_pages; + bool defunct; }; -/* - * Representation of a watch on an object. +/** + * struct watch - Representation of a watch on an object + * + * @rcu: RCU head (in union with info_id) + * @info_id: ID to be OR'd in to info field (in union with rcu) + * @queue: Queue to post events to + * @queue_node: Link in queue->watches + * @watch_list: Link in watch_list->watchers + * @list_node: The list node + * @cred: Creds of the owner of the watch + * @private: Private data for the watched object + * @id: Internal identifier + * @usage: Object usage count */ struct watch { union { struct rcu_head rcu; - u32 info_id; /* ID to be OR'd in to info field */ + u32 info_id; }; - struct watch_queue __rcu *queue; /* Queue to post events to */ - struct hlist_node queue_node; /* Link in queue->watches */ + struct watch_queue __rcu *queue; + struct hlist_node queue_node; struct watch_list __rcu *watch_list; - struct hlist_node list_node; /* Link in watch_list->watchers */ - const struct cred *cred; /* Creds of the owner of the watch */ - void *private; /* Private data for the watched object */ - u64 id; /* Internal identifier */ - struct kref usage; /* Object usage count */ + struct hlist_node list_node; + const struct cred *cred; + void *private; + u64 id; + struct kref usage; }; -/* - * List of watches on an object. +/** + * struct watch_list - List of watches on an object + * + * @rcu: RCU head + * @watchers: List head + * @release_watch: Function to release watch + * @lock: To protect addition and removal of watches */ struct watch_list { struct rcu_head rcu; @@ -118,8 +164,10 @@ static inline void remove_watch_list(struct watch_list *wlist, u64 id) } /** - * watch_sizeof - Calculate the information part of the size of a watch record, - * given the structure size. + * watch_sizeof() - Calculate the information part of the size of a watch + * record, given the structure size. + * + * @STRUCT: The structure whose size is to be given */ #define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT) From patchwork Sat Nov 12 10:30:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddh Raman Pant X-Patchwork-Id: 19165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1221881wru; Sat, 12 Nov 2022 03:18:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ucf1+Ou+Nrp92GBnZNh5O3kQVlju9IKlXypBtVfpYkDuX17cNJ4t02LQDy+3uL0LgYAoK X-Received: by 2002:a17:90a:d516:b0:213:1d14:2a27 with SMTP id t22-20020a17090ad51600b002131d142a27mr6114391pju.109.1668251929380; Sat, 12 Nov 2022 03:18:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668251929; cv=pass; d=google.com; s=arc-20160816; b=JrUB2toc+g5C5UhGaC/UZbzA4D2kVFTnN2TpCJ4fiL8Qrz4Ku0Z8Pku066X1F34jPK GGwUP6Wzad8ek7X2o4S6Oa6gACTHXIddKuFWtqEDBsJOlPuaOuLfgk0qUxZ8CeqpNlU4 MfMMj62sXwPRLLOKb+D+6il6bbboYI+nsroHquFFUgZX535k/OH9BE5BkWlmMXPjt164 AIzFRKH86qD9cbpihrmvRhKhtnbVDt1Bv24O/iGOETa5g+Xy7Xz7DIy6yB3GrXWd2y/m qSFFcs2359hTRIqrm0w17rIeROu5DLY24IFVdqJv0+LGF7k9Zy9PfcRF7UsrnL8GRxsI +VYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:message-id:cc:to:from :dkim-signature; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=jtRk28m5HDrLVGU6xcBs064AURn0u7vcTLpWDObU2tHF5SzhdQC5ppmq0TH1VEA/D4 XaH/Mf1xd67KlWEMV85nPyvQGbZriYWzhG6ckHHFkpgTsiEJyStV2J/zdnTEMpmj/hYA EBV254easGoz90u80bHUL87Ozd/V88PyGNOKsCEGFn8WGSiuTPyTevEfKsWHW7co4Zqo JzR5zaTg0TH2UJ24W/bmF7v8izl/Jw1GyxXvugcwwVtNvkdXQsbW4D0NZeWmH88duIYu g4d0/RDfXOhQEkzyOEGyQTucedtf6kfh63U/7AUgg9xfb72gcJ9+JcNSiWUR3o0w1v62 Frzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=KeYri2bD; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020a170902700500b0017ef8bf8a91si4499100plk.439.2022.11.12.03.18.36; Sat, 12 Nov 2022 03:18:49 -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=@siddh.me header.s=zmail header.b=KeYri2bD; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234850AbiKLLRm (ORCPT + 99 others); Sat, 12 Nov 2022 06:17:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233681AbiKLLR3 (ORCPT ); Sat, 12 Nov 2022 06:17:29 -0500 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9F31F9DD; Sat, 12 Nov 2022 03:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668249073; cv=none; d=zohomail.in; s=zohoarc; b=WvjIxDY9DG6YuzcAwCxhgC+1QeN+Or0Glx//RDKFYJtEKRoUf7s8ly6xpRvOkbm4JCKwyvfi36jQ9RxZGpsamB1ePt4gIVxsbGfTg3Yzoa9Vsl5IVaZjroRHh4b8gNZ6DiQDkakwI4asbsZtm2Tcgaf65o+nt1ADLspU7xnX8aQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1668249073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=degMBSnd9mGkKSPgdaapCdnzUPijGJ/a4MH85DcCllqX8o8cQ7EUSMFVg9m+rqFcL741P6czQkys9PXclLmJvjWnjpb4YTFGsJsBqMm3Cjy6FVgykzkQGl+i+APFF6LZHe8Frz9chLNlQlV4aSdB1t9LIhn4igYi90O7buSdj6s= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1668249073; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=KeYri2bDEYsjQ5ROrUNLIT/BtrfEBjYg5D/Aot2N09fxzzzUpkethOo9sk1RFEvl y3KvB3tbeR+0Q8wdSe5EcX2+0D5TxFJX4wsOz0MK6aAPHU8MS/tJzI5zx9afafbQBfw hI5vrRMIzBt/na673W7ByHSPaQoNAXhD6lCgS4hg= Received: from kampyooter.. (110.226.30.173 [110.226.30.173]) by mx.zoho.in with SMTPS id 1668249072566411.90214034857365; Sat, 12 Nov 2022 16:01:12 +0530 (IST) From: Siddh Raman Pant To: Mauro Carvalho Chehab , Randy Dunlap , David Howells , Jonathan Corbet , "Fabio M. De Francesco" , Eric Dumazet , Christophe JAILLET , Eric Biggers Cc: keyrings , linux-security-module , linux-fsdevel , linux-kernel Message-ID: <21ea7a96018db8f140d7c68ca75665064361ad1b.1668248462.git.code@siddh.me> Subject: [RESEND PATCH v2 2/2] kernel/watch_queue: NULL the dangling *pipe, and use it for clear check Date: Sat, 12 Nov 2022 16:00:41 +0530 X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-ZohoMailClient: External X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLACK autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749288934878599409?= X-GMAIL-MSGID: =?utf-8?q?1749288934878599409?= NULL the dangling pipe reference while clearing watch_queue. If not done, a reference to a freed pipe remains in the watch_queue, as this function is called before freeing a pipe in free_pipe_info() (see line 834 of fs/pipe.c). The sole use of wqueue->defunct is for checking if the watch queue has been cleared, but wqueue->pipe is also NULLed while clearing. Thus, wqueue->defunct is superfluous, as wqueue->pipe can be checked for NULL. Hence, the former can be removed. Signed-off-by: Siddh Raman Pant --- include/linux/watch_queue.h | 4 +--- kernel/watch_queue.c | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index 7f8b1f15634b..d72ad82a4435 100644 --- a/include/linux/watch_queue.h +++ b/include/linux/watch_queue.h @@ -55,7 +55,7 @@ struct watch_filter { * * @rcu: RCU head * @filter: Filter to use on watches - * @pipe: The pipe we're using as a buffer + * @pipe: The pipe we're using as a buffer, NULL when queue is cleared/closed * @watches: Contributory watches * @notes: Preallocated notifications * @notes_bitmap: Allocation bitmap for notes @@ -63,7 +63,6 @@ struct watch_filter { * @lock: To serialize accesses and removes * @nr_notes: Number of notes * @nr_pages: Number of pages in notes[] - * @defunct: True when queues closed */ struct watch_queue { struct rcu_head rcu; @@ -76,7 +75,6 @@ struct watch_queue { spinlock_t lock; unsigned int nr_notes; unsigned int nr_pages; - bool defunct; }; /** diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index a6f9bdd956c3..a70ddfd622ee 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -43,7 +43,7 @@ MODULE_LICENSE("GPL"); static inline bool lock_wqueue(struct watch_queue *wqueue) { spin_lock_bh(&wqueue->lock); - if (unlikely(wqueue->defunct)) { + if (unlikely(!wqueue->pipe)) { spin_unlock_bh(&wqueue->lock); return false; } @@ -105,9 +105,6 @@ static bool post_one_notification(struct watch_queue *wqueue, unsigned int head, tail, mask, note, offset, len; bool done = false; - if (!pipe) - return false; - spin_lock_irq(&pipe->rd_wait.lock); mask = pipe->ring_size - 1; @@ -603,8 +600,11 @@ void watch_queue_clear(struct watch_queue *wqueue) rcu_read_lock(); spin_lock_bh(&wqueue->lock); - /* Prevent new notifications from being stored. */ - wqueue->defunct = true; + /* + * This pipe will get freed by the caller free_pipe_info(). + * Removing this reference also prevents new notifications. + */ + wqueue->pipe = NULL; while (!hlist_empty(&wqueue->watches)) { watch = hlist_entry(wqueue->watches.first, struct watch, queue_node);