Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8772385ybi; Tue, 9 Jul 2019 22:57:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+IGmrezXmYFpfIjnigtN4ivZ8nmxUwACZ8MJNXVhBdrEcKs11McrDZ60f52ilU2zUYtDH X-Received: by 2002:a17:902:a5c7:: with SMTP id t7mr37348611plq.288.1562738221680; Tue, 09 Jul 2019 22:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562738221; cv=none; d=google.com; s=arc-20160816; b=D/ZtQscaeyzTgXxvauE4Z/hIGSRYRgEqccktZB6Q+D4PGzCH2vq8mvTd2WkfqdvHFk REGJRcaaAUr8Usv8RorShMuUe0fUvjdAVWPZ5jXn8u40NcGCBB9cWBriY4uuPUL01jqe 4yHUKa+V5VkdObGUkVaRcu4Kq8T3DLVgwmm7HjBDNF8qC++SP2IO/t2vLJl+4kFpm9af 1oejz275KRxTBNg1zpUWOpV8qzcQv7+Xf8nifOfOY3IFG+TD9588XgTOKxdLVgAHTmJL 53WhtvAmE0W/HRQk4ws7sMxPNJysZ1yHW3vWYztKVWpLh4hVnZaqmzl8dXTaGfBuny+l n4+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=DGfQenKiiOpvI9cMCE7Lks5gNkSXBpdWsBlniKVc3dw=; b=Za+iXo+KoDxyB6bAAmFTWd6tOx7jEWvBfvTjdIRKT3x3egoSzOAy5QdEaiCsFwPJLK 9Og2G0ggWl1WVSgY+vjNzOBY2qY2rkp0Ge2B8E9bzGJ6zGHeQDjxRlpmQe64C++2wiij bhFpo7hAVT2cu1C08NhixqWb01MfuvPmK0u+DFjAvObGtbwiSAGwjqUGzXTw/NmfNlec IW2NdIVu6fmg9TLNhgNRGqHeaeMMw90py06Rxw0Gcp3zCtQ3woQ6xHhP3GAho6tuX8wU FpenJxx1d/F+qgB2NujzAtqBhC8TxUT33P3VdQfBuancHNycMeeDabI0WRNgTCD3Zs6g vuaQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si1248399pld.32.2019.07.09.22.56.33; Tue, 09 Jul 2019 22:57: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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726112AbfGJFtm (ORCPT + 99 others); Wed, 10 Jul 2019 01:49:42 -0400 Received: from relay.sw.ru ([185.231.240.75]:49196 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725844AbfGJFtl (ORCPT ); Wed, 10 Jul 2019 01:49:41 -0400 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hl5Ti-0002oO-18; Wed, 10 Jul 2019 08:49:18 +0300 Subject: Re: [PATCH v3 0/3] kernel/notifier.c: avoid duplicate registration To: Xiaoming Ni , 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, gregkh@linuxfoundation.org, 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 Cc: alex.huangjianhui@huawei.com, dylix.dailei@huawei.com, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org References: <1562728147-30251-1-git-send-email-nixiaoming@huawei.com> From: Vasily Averin Message-ID: Date: Wed, 10 Jul 2019 08:49:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1562728147-30251-1-git-send-email-nixiaoming@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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. 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. Unfortunately I do not see any ways to handle such cases properly, and it seems for me your patches does not resolve this problem. Am I missed something probably? > case1: An infinite loop in notifier_chain_register() can cause soft lockup > atomic_notifier_chain_register(&test_notifier_list, &test1); > atomic_notifier_chain_register(&test_notifier_list, &test1); > atomic_notifier_chain_register(&test_notifier_list, &test2); > > case2: An infinite loop in notifier_chain_register() can cause soft lockup > atomic_notifier_chain_register(&test_notifier_list, &test1); > atomic_notifier_chain_register(&test_notifier_list, &test1); > atomic_notifier_call_chain(&test_notifier_list, 0, NULL); > > case3: lose other hook test2 > atomic_notifier_chain_register(&test_notifier_list, &test1); > atomic_notifier_chain_register(&test_notifier_list, &test2); > atomic_notifier_chain_register(&test_notifier_list, &test1); > > 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. > > so. need add a check in in notifier_chain_register() to avoid duplicate > registration > > v1: > * use notifier_chain_cond_register replace notifier_chain_register > > v2: > * Add a check in notifier_chain_register() to avoid duplicate registration > * remove notifier_chain_cond_register() to avoid duplicate code > * remove blocking_notifier_chain_cond_register() to avoid duplicate code > > v3: > * Add a cover letter. > > Xiaoming Ni (3): > kernel/notifier.c: avoid duplicate registration > kernel/notifier.c: remove notifier_chain_cond_register() > kernel/notifier.c: remove blocking_notifier_chain_cond_register() > > include/linux/notifier.h | 4 ---- > kernel/notifier.c | 41 +++-------------------------------------- > net/sunrpc/rpc_pipe.c | 2 +- > 3 files changed, 4 insertions(+), 43 deletions(-) >