Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1373433imi; Fri, 1 Jul 2022 08:28:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1txt/sd6OSKU+fVQN3UYuKA0GNBoUlpb8enLLFjZUDtWTJJQP7tBYODAz3tYiH5J93RZ5fJ X-Received: by 2002:a17:906:20c6:b0:716:646d:c019 with SMTP id c6-20020a17090620c600b00716646dc019mr14574883ejc.529.1656689294812; Fri, 01 Jul 2022 08:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656689294; cv=none; d=google.com; s=arc-20160816; b=rzdhWCO7P55ajZEwZ/7V5WIFzaJwyNTtRwg6tqudrhmnHJGx77wtRGbbLX3foTfy2P J9VjZN8bqDlA2lrisigMgwP8pgW5V5F2zm2CBBU7+GUrD1fRYPA4XuIZ9wTIkll0/Azi jC5sg4MnXYH+MeHHYQOkyKsBRV/TsRk76vSLBJnZ0usObSYHAxFWyt8vanC4O//uM4qO hw+Gigo62QaUy8knP7qOv60zV+yGNVpMQoQNm6jqt0DgdmtgkPBFuxntNQr2Be4cP4gJ 25hWwkz/Dhb5vX9jxi7R/z7bbhKepwrtN+6yxuyTJkBx+jrJjS2/FLCZ1ec0nKGpWmCB XXlA== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=I+2hj4acVQYkBMOEcNrd1/8uHFiO17M5Y1PJGsnYfWU=; b=DjdM7D8uYnTD+/wTE4bQWo0p8oGTYraOA3JZ2b4O0u7N237bdCWuDb8TspIigoFRDW v6N/YvvN2Ry2QrwgEh37BfCYijiXrZjeX5XvARMK+8Enu1yRFgHg8+xboPlxzvM2sKSb 85lCMCo/7dLNkr7Ql8o3xblutDhVjHHIM5TMmuZjR5pySvI1uI7tztpsCU0THSdhaEtn HvksW1TuyRtvbaB7PkXccCxLHd1KJ8HIYjo0I0GMtVzTUpolmI/tqKOM3kBrp2+mDOUh PJA1WuYWH+8RhRX/2lQP0+Z4Z3V2om8Vz/735fSq8oqdHU2FWqOQbS9+ItWRWiNFUEpt E2OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vQP7Pi54; 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 d13-20020a170906640d00b007263068d526si4331591ejm.574.2022.07.01.08.27.50; Fri, 01 Jul 2022 08:28:14 -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=@kernel.org header.s=k20201202 header.b=vQP7Pi54; 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 S232799AbiGAPKJ (ORCPT + 99 others); Fri, 1 Jul 2022 11:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231732AbiGAPKH (ORCPT ); Fri, 1 Jul 2022 11:10:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA662340FB; Fri, 1 Jul 2022 08:10:06 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 5831D623C3; Fri, 1 Jul 2022 15:10:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14C0FC3411E; Fri, 1 Jul 2022 15:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656688205; bh=VE3xxCP6qqMSL2Ge+UO5AZuDtQGRgxKsVxk0c6Av2T0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vQP7Pi54fa7ZlG5vmHtJ7YP4w9Zl7R6UolfS21FRKD0FrxXep/C+ymxdztrJJKQq2 Wnodsl9qNX5zewz9cNtwNOLWVDVASDmiGvE46ybj8XTIPHyQTJSz3YtmnljPecHY5s 1GvGFt5pr/4NNT3r+1F7nyVFeksLwpSuAslTrl6SWAMnt0hGgaMPONb7h6hPoCKx5A 4450/CLeN5jlE9mXZ8+IMhcTxGVrkoA+GIlMje27H0Rn2WLZAl5pd1b9luG7HHO+d0 3TZ4IuvszhIWicsFMOYL/oVLkXIHovhGbH8HGVL0xoK1uVGbpW2c6ViGW3a1QYSPJS ts0LGRh5LZigA== Date: Fri, 1 Jul 2022 08:10:03 -0700 From: Nathan Chancellor To: Imran Khan Cc: tj@kernel.org, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, m.szyprowski@samsung.com, michael@walle.cc, robh@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, guillaume.tucker@collabora.com, pmladek@suse.com Subject: Re: [PATCH] kernfs: Avoid re-adding kernfs_node into kernfs_notify_list. Message-ID: References: <20220701145047.2206900-1-imran.f.khan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220701145047.2206900-1-imran.f.khan@oracle.com> X-Spam-Status: No, score=-7.5 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,T_SCC_BODY_TEXT_LINE 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 Sat, Jul 02, 2022 at 12:50:47AM +1000, Imran Khan wrote: > Kick fsnotify only if an event is not already scheduled for target > kernfs node. commit b8f35fa1188b ("kernfs: Change kernfs_notify_list to > llist.") changed kernfs_notify_list to a llist. > Prior to this list was a singly linked list, protected by > kernfs_notify_lock. Whenever a kernfs_node was added to the list > its ->attr.notify_next was set to head of the list and upon removal > ->attr.notify_next was reset to NULL. Addition to kernfs_notify_list > would only happen if kernfs_node was not already in the list i.e. > if ->attr.notify_next was NULL. commit b8f35fa1188b ("kernfs: Change > kernfs_notify_list to llist.") removed this checking and this was wrong > as it resulted in multiple additions for same kernfs_node. > > So far this bug only got reflected with some console related setting. > Nathan found this issue when console was specified both in DT and in > kernel command line and Marek found this issue when earlycon was enabled. > > This patch avoids adding an already added kernfs_node into notify list. > > Reported-by: Nathan Chancellor > Reported-by: Marek Szyprowski This should also include: Reported-by: Michael Walle > Tested-by: Marek Szyprowski > Fixes: b8f35fa1188b ("kernfs: Change kernfs_notify_list to llist.") > Signed-off-by: Imran Khan For the ARCH=um case that I noticed: Tested-by: Nathan Chancellor > --- > fs/kernfs/file.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c > index bb933221b4bae..e8ec054e11c63 100644 > --- a/fs/kernfs/file.c > +++ b/fs/kernfs/file.c > @@ -917,6 +917,7 @@ static void kernfs_notify_workfn(struct work_struct *work) > if (free == NULL) > return; > > + free->next = NULL; > attr = llist_entry(free, struct kernfs_elem_attr, notify_next); > kn = attribute_to_node(attr, struct kernfs_node, attr); > root = kernfs_root(kn); > @@ -992,9 +993,11 @@ void kernfs_notify(struct kernfs_node *kn) > rcu_read_unlock(); > > /* schedule work to kick fsnotify */ > - kernfs_get(kn); > - llist_add(&kn->attr.notify_next, &kernfs_notify_list); > - schedule_work(&kernfs_notify_work); > + if (kn->attr.notify_next.next != NULL) { > + kernfs_get(kn); > + llist_add(&kn->attr.notify_next, &kernfs_notify_list); > + schedule_work(&kernfs_notify_work); > + } > } > EXPORT_SYMBOL_GPL(kernfs_notify); > > > base-commit: 6cc11d2a1759275b856e464265823d94aabd5eaf > -- > 2.30.2 >