From: Andrew Morton <akpm@linux-foundation.org>
To: Xiaoming Ni <nixiaoming@huawei.com>
Cc: <vvs@virtuozzo.com>, <adobriyan@sw.ru>, <adobriyan@gmail.com>,
<tglx@linutronix.de>, <gregkh@linuxfoundation.org>,
<mingo@kernel.org>, <viresh.kumar@linaro.org>, <luto@kernel.org>,
<arjan@linux.intel.com>, <Nadia.Derbey@bull.net>,
<linux-kernel@vger.kernel.org>, <torvalds@linux-foundation.org>,
<stern@rowland.harvard.edu>, <paulmck@linux.vnet.ibm.com>,
<masami.hiramatsu.pt@hitachi.com>, <alex.huangjianhui@huawei.com>,
<dylix.dailei@huawei.com>,
Stanislav Kinsbursky <skinsbursky@parallels.com>,
Trond Myklebust <Trond.Myklebust@netapp.com>
Subject: Re: [PATCH] kernel/notifier.c: remove notifier_chain_register
Date: Thu, 13 Jun 2019 12:38:23 -0700 [thread overview]
Message-ID: <20190613123823.bf75e7305e22dd1dcab04fb8@linux-foundation.org> (raw)
In-Reply-To: <1560434864-98664-1-git-send-email-nixiaoming@huawei.com>
On Thu, 13 Jun 2019 22:07:44 +0800 Xiaoming Ni <nixiaoming@huawei.com> 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.
>
> case1: An infinite loop in notifier_chain_register can cause soft lockup
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier2);
>
> case2: An infinite loop in notifier_chain_register can cause soft lockup
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
> atomic_notifier_call_chain(&test_notifier_list, 0, NULL);
>
> case3: lose other hook "test_notifier2"
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier2);
> atomic_notifier_chain_register(&test_notifier_list, &test_notifier1);
>
> case4: Unregister returns 0, but the hook is still in the linked list,
> and it is not really registered. If you call notifier_call_chain
> after ko is unloaded, it will trigger oops.
>
> If the system is configured with softlockup_panic and the same
> hook is repeatedly registered on the panic_notifier_list, it
> will cause a loop panic.
>
> The only difference between notifier_chain_cond_register and
> notifier_chain_register is that a check is added in order to
> avoid registering the same notifier multiple times to the same hook.
> So consider removing notifier_chain_register and replacing it
> with notifier_chain_cond_register.
>
> ...
>
> diff --git a/kernel/notifier.c b/kernel/notifier.c
> index d9f5081..56efd54 100644
> --- a/kernel/notifier.c
> +++ b/kernel/notifier.c
> @@ -19,20 +19,6 @@
> * are layered on top of these, with appropriate locking added.
> */
>
> -static int notifier_chain_register(struct notifier_block **nl,
> - struct notifier_block *n)
> -{
> - while ((*nl) != NULL) {
> - WARN_ONCE(((*nl) == n), "double register detected");
> - if (n->priority > (*nl)->priority)
> - break;
> - nl = &((*nl)->next);
> - }
> - n->next = *nl;
> - rcu_assign_pointer(*nl, n);
> - return 0;
> -}
Registering an already-registered notifier is a bug (except for in
net/sunrpc/rpc_pipe.c, apparently). The effect of this change is to
remove the warning about the presence of the bug, so the bug is less
likely to get fixed.
I think it would be better to remove notifier_chain_cond_register() and
blocking_notifier_chain_cond_register() and to figure out why
net/sunrpc/rpc_pipe.c is using it and to redo the rpc code so it no
longer has that need.
next prev parent reply other threads:[~2019-06-13 19:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-13 14:07 Xiaoming Ni
2019-06-13 19:38 ` Andrew Morton [this message]
2019-06-16 13:56 ` Nixiaoming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190613123823.bf75e7305e22dd1dcab04fb8@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Nadia.Derbey@bull.net \
--cc=Trond.Myklebust@netapp.com \
--cc=adobriyan@gmail.com \
--cc=adobriyan@sw.ru \
--cc=alex.huangjianhui@huawei.com \
--cc=arjan@linux.intel.com \
--cc=dylix.dailei@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=nixiaoming@huawei.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=skinsbursky@parallels.com \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viresh.kumar@linaro.org \
--cc=vvs@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®