Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp943779ybi; Fri, 12 Jul 2019 07:08:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqJnAf9jnQAJpeZHa8buT54/eCtcPl7Vip3jldORqXSB43uqW7GDqfHCs9Zp3jMV7t+69x X-Received: by 2002:a65:4808:: with SMTP id h8mr10980019pgs.22.1562940481327; Fri, 12 Jul 2019 07:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562940481; cv=none; d=google.com; s=arc-20160816; b=aQEyakMcb9lNEKHsu31s/kyQi77KYJSymNq5C3QPkEoYNrSnxGKsHqfVC9TxBiL3kk 9qzYEwnTG+17iar66gMxB/bGBtJ2DX1BrPuSVnbxsjcZgN/q7BJIKnjhzYjIMLT/XioP 1mAcM+gXl89xecIBc2jXn1rYy/FUkgfsJdg8JFhjxCm+gG9qw3Mn71P6lb4fpzl2M8tW +fxwaSoVSX8pBLDWjGtY1s33pm4Z/u6mFgpFNtFn0Ck5juVAa7ugyPJ99fjMfTE/5Uz4 XranO4/7eA6deK/t2WMlRsDkgwL2s2hiUbitGRfbRllHnN0L3cc6pCnaVOwA66dydwx1 MYrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=V2yhk/ZkGaa8worjxy3y7ZGXhhSqJYa7AYfxbWfJRYY=; b=V12cpfSLvoh+1FuxXq3SW/6rfV89elOUL1zZlC1D0lhkcd0n2scNzktx2vIpO0kJbU 7ru+y8rnWviihvueljQ+jG9KgLi69EwDibwIpbj2A2vJiglv5JGp6R9xO8+SwvPSWchk cN3KIRfQ1HBk0VmeqwRQeCl1Y4NKMKx+beuwTX2GurSh4gv6ArHBI6DAfokv7k5BralF vUwxWMmEIHLAVgNL19o+QhJhwt33LUy9khINZF2ZgwctrBQFZp3kyJ7XcgQbJtRJK4h5 rPEnLaTPeoVYm0VgRtnrPxvYMC+Aghv5+GEYomrgAuYF0dc3efYWMyTRMuLXXt8isZoJ 9aaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="A/oAdNTd"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si8116592pgm.368.2019.07.12.07.07.36; Fri, 12 Jul 2019 07:08:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="A/oAdNTd"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfGLOHe (ORCPT + 99 others); Fri, 12 Jul 2019 10:07:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:48538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbfGLOHd (ORCPT ); Fri, 12 Jul 2019 10:07:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 13EEB206B8; Fri, 12 Jul 2019 14:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562940452; bh=l2jxhcxb3H5zHl1HLHLMhC6OaCKayvurXGn4TEVXXoE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A/oAdNTdeI+UFzMuaoy4DvzeHOzCWLaMqM4Z0jDa0fCTZdnnVMmVzbxFV54ca2D35 keNuDhJQelKhNkBrLYHxdMcUwGrOPDYBJxPTDuvPjVhJfRHoIeifkRu+IK8/R2Lkff ht6sVwffhqeUmPUg9qiRYQW91VgWhz3KGlahak+0= Date: Fri, 12 Jul 2019 16:07:29 +0200 From: "gregkh@linuxfoundation.org" To: Xiaoming Ni Cc: Vasily Averin , "adobriyan@gmail.com" , "akpm@linux-foundation.org" , "anna.schumaker@netapp.com" , "arjan@linux.intel.com" , "bfields@fieldses.org" , "chuck.lever@oracle.com" , "davem@davemloft.net" , "jlayton@kernel.org" , "luto@kernel.org" , "mingo@kernel.org" , "Nadia.Derbey@bull.net" , "paulmck@linux.vnet.ibm.com" , "semen.protsenko@linaro.org" , "stable@kernel.org" , "stern@rowland.harvard.edu" , "tglx@linutronix.de" , "torvalds@linux-foundation.org" , "trond.myklebust@hammerspace.com" , "viresh.kumar@linaro.org" , "Huangjianhui (Alex)" , Dailei , "linux-kernel@vger.kernel.org" , "linux-nfs@vger.kernel.org" , "netdev@vger.kernel.org" Subject: Re: [PATCH v3 0/3] kernel/notifier.c: avoid duplicate registration Message-ID: <20190712140729.GA11583@kroah.com> References: <1562728147-30251-1-git-send-email-nixiaoming@huawei.com> <8ee6f763-ccce-ab58-3d96-21f5e1622916@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ee6f763-ccce-ab58-3d96-21f5e1622916@huawei.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Fri, Jul 12, 2019 at 09:11:57PM +0800, Xiaoming Ni wrote: > On 2019/7/11 21:57, Vasily Averin wrote: > > On 7/11/19 4:55 AM, Nixiaoming wrote: > >> On Wed, July 10, 2019 1:49 PM Vasily Averin wrote: > >>> On 7/10/19 6:09 AM, Xiaoming Ni wrote: > >>>> Registering the same notifier to a hook repeatedly can cause the hook > >>>> list to form a ring or lose other members of the list. > >>> > >>> I think is not enough to _prevent_ 2nd register attempt, > >>> it's enough to detect just attempt and generate warning to mark host in bad state. > >>> > >> > >> Duplicate registration is prevented in my patch, not just "mark host in bad state" > >> > >> Duplicate registration is checked and exited in notifier_chain_cond_register() > >> > >> Duplicate registration was checked in notifier_chain_register() but only > >> the alarm was triggered without exiting. added by commit 831246570d34692e > >> ("kernel/notifier.c: double register detection") > >> > >> My patch is like a combination of 831246570d34692e and notifier_chain_cond_register(), > >> which triggers an alarm and exits when a duplicate registration is detected. > >> > >>> Unexpected 2nd register of the same hook most likely will lead to 2nd unregister, > >>> and it can lead to host crash in any time: > >>> you can unregister notifier on first attempt it can be too early, it can be still in use. > >>> on the other hand you can never call 2nd unregister at all. > >> > >> Since the member was not added to the linked list at the time of the second registration, > >> no linked list ring was formed. > >> The member is released on the first unregistration and -ENOENT on the second unregistration. > >> After patching, the fault has been alleviated > > > > You are wrong here. > > 2nd notifier's registration is a pure bug, this should never happen. > > If you know the way to reproduce this situation -- you need to fix it. > > > > 2nd registration can happen in 2 cases: > > 1) missed rollback, when someone forget to call unregister after successfull registration, > > and then tried to call register again. It can lead to crash for example when according module will be unloaded. > > 2) some subsystem is registered twice, for example from different namespaces. > > in this case unregister called during sybsystem cleanup in first namespace will incorrectly remove notifier used > > in second namespace, it also can lead to unexpacted behaviour. > > > So in these two cases, is it more reasonable to trigger BUG() directly when checking for duplicate registration ? > But why does current notifier_chain_register() just trigger WARN() without exiting ? > notifier_chain_cond_register() direct exit without triggering WARN() ? It should recover from this, if it can be detected. The main point is that not all apis have to be this "robust" when used within the kernel as we do allow for the callers to know what they are doing :) If this does not cause any additional problems or slow downs, it's probably fine to add. thanks, greg k-h