Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10539022ybi; Thu, 11 Jul 2019 06:58:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6SjrS4mnA6/xCM+MRMASXl/rC6zCdH7SbRY7S8Y6kFtUVQqa0LTF4HUwuVpSH79Cz9a1x X-Received: by 2002:a63:778a:: with SMTP id s132mr2185944pgc.242.1562853518930; Thu, 11 Jul 2019 06:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562853518; cv=none; d=google.com; s=arc-20160816; b=mfcvLLNQieSS91h4EY/27/KYWx96v5NLOOvGirEYI3jRoKZ479iSjvfuLq+rJScDEV 9Pqw1DAYp09KxUr9PhsP/JY92U2Z8fNQuFCwe+xd+hjvpdkQ1zJVuZF9pc3Irj9ufpPR LvCQfF3ultfEMljh25VtFrKrMzx+5BXQDOTVImoLzCfngQvzIl62ItQ+a2KjdLQJbZ5N bMgx2XQ0mPL1BzN5or7J32YV/9KO4HbnypzLB6aYd/uM5u7Cxt/qfqz37OWW1jo0axid Xa7dtjXP1HV5xVoe5fx7YY6cxQ8d3NgZewH11XCF1pu221tEjnuWv7qqwJyGv9Ni6zjM OBjQ== 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=CWqTgKtZ7CsdQ3wHlZGRbBW2kAhHezWzl7mbwuiIxBA=; b=svI+CxgGlugMOUxcefOYy27Jit0PE12fiALJ/q/SpmzCej5rEYj2sAMXmfZztJV0Dl VUJhPRWu2pAJQgamU+2Bl7SBByPI5Eg1r9cu6oiQbTtDj7jesQSL6FQbsTXRcHnVW/rc iU039xjTZkxPXXM1uGR9zXuPxNiiU6dUmqFWSKRpPYcUWYGfXH2sH5wQWRNoMi0JOcqK SFauomSpmfqb60Dysas9frgixCyZIP16yZg0lqN8S+aku2E0/jk3UBjoe+hSLh+aMUmQ QTPjEYuTUlG4Q8vG6Nh8AzBiGkRSH1jWv3IjoHkO6uWIT+9UClR3zbaxlQN+N8WDSK2N ajmw== 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 m128si5266573pfm.97.2019.07.11.06.58.14; Thu, 11 Jul 2019 06:58:38 -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 S1728363AbfGKN5w (ORCPT + 99 others); Thu, 11 Jul 2019 09:57:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:55748 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728274AbfGKN5v (ORCPT ); Thu, 11 Jul 2019 09:57:51 -0400 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hlZZp-0001WC-QI; Thu, 11 Jul 2019 16:57:37 +0300 Subject: Re: [PATCH v3 0/3] kernel/notifier.c: avoid duplicate registration To: Nixiaoming , "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: "Huangjianhui (Alex)" , Dailei , "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: Thu, 11 Jul 2019 16:57:27 +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: 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/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. > It may be more helpful to return an error code when someone tries to register the same > notification program a second time. You are wrong again here, it is senseless. If you have detected 2nd register -- your node is already in bad state. > But I noticed that notifier_chain_cond_register() returns 0 when duplicate registration > is detected. At the same time, in all the existing export function comments of notify, > "Currently always returns zero" > > I am a bit confused: which is better? > >> >> 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); > > Thanks > > Xiaoming Ni >