From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DD31C43219 for ; Fri, 10 Dec 2021 18:52:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245612AbhLJSzm (ORCPT ); Fri, 10 Dec 2021 13:55:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245600AbhLJSzm (ORCPT ); Fri, 10 Dec 2021 13:55:42 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C255C0617A1; Fri, 10 Dec 2021 10:52:06 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id b1so19598432lfs.13; Fri, 10 Dec 2021 10:52:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=j1hvlB2w2BrWNScbCJyLwX4oBGKG9hr6NJqtvFkNM/U=; b=DpLCPmMgrOty3y0HrpqopSxxp/qGs/dwG/CgN0apuyA6on28PorJtUybksa6iWzXUQ 1nC+svp1ZReaFc8Ho69TZxII0UpyuP8U7xwSjZaJzyMIRrgh64VdMWwWLpT7FD5pRO3K REVQTxyYOO3tzHZOXPhjO1pz+wC6sFrKKUXdbaxaG08xMkm/2y6DNn/B8j1qrJKM7+bp P06T1NhQFOSTeILIcDdZiYIbm1FILYdO04vFRszXD6zy1FhLrwMPIaNrfLI1p4FempaK JIbIyvDEnU7xy4tOpOMAsYn+ngt9JZU69+QjylTYb0y426O41rF96XAtvzhN80gJmNuF j5Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=j1hvlB2w2BrWNScbCJyLwX4oBGKG9hr6NJqtvFkNM/U=; b=3ZsJMtkoZirHmHbtWCQWjhyEWlHvgvc8zux5rplsI9f4VOHxw/aUt1EPe2jrX/LnQp iqLWzV9X1NXHQqau+xX+rRCY+eyWx4oU8shnVGgz2tyzr681RM67MfEL/2w4lyurWgz5 lsJrpyvN3zb6gLWtGLs0pIg8Y8aYynF2t+PuERKIIGVKeStOU7L0Y5Ve68LaBTnxxefy XeLOdq2eFXaVhNzm+FziWbE2TZZb5bacFlSH0A7RigNlUH+JhtpAGkMHk2/cdLXfX4Mf L3tKKCVYymwgvo5vW1bxbvzgmzpWwQktWMJOxsiintkRkoycTpYBTrLf7o3C8RIECId6 l0OA== X-Gm-Message-State: AOAM533OFt8HpoXb56XjtNLLrkUp0Ra6BVbqLH/VeqySuEhONEhfk6Un 8wvuBWjdzYaDeJzyM081iTTuLj50f7A= X-Google-Smtp-Source: ABdhPJwwyZAuw0wQQ6Dju/0DgEoENSIDq2aqqR4iP7Vldq5bfh8DtMEIrZOS6poEr19ZPeaYgjpDkg== X-Received: by 2002:ac2:58d9:: with SMTP id u25mr14351127lfo.514.1639162324540; Fri, 10 Dec 2021 10:52:04 -0800 (PST) Received: from [192.168.2.145] (94-29-46-111.dynamic.spd-mgts.ru. [94.29.46.111]) by smtp.googlemail.com with ESMTPSA id c21sm387216lfv.29.2021.12.10.10.52.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Dec 2021 10:52:04 -0800 (PST) Subject: Re: [PATCH v4 03/25] notifier: Add atomic/blocking_notifier_has_unique_priority() To: "Rafael J. Wysocki" Cc: Thierry Reding , Jonathan Hunter , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Geert Uytterhoeven , Greg Ungerer , Joshua Thompson , Thomas Bogendoerfer , Sebastian Reichel , Linus Walleij , Philipp Zabel , Greentime Hu , Vincent Chen , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Yoshinori Sato , Rich Felker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , the arch/x86 maintainers , "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Len Brown , Santosh Shilimkar , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Pavel Machek , Lee Jones , Andrew Morton , Guenter Roeck , Daniel Lezcano , Andy Shevchenko , Ulf Hansson , alankao@andestech.com, "K . C . Kuen-Chern Lin" , Linux ARM , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev , linux-riscv@lists.infradead.org, Linux-sh list , xen-devel@lists.xenproject.org, ACPI Devel Maling List , Linux PM , linux-tegra References: <20211126180101.27818-1-digetx@gmail.com> <20211126180101.27818-4-digetx@gmail.com> From: Dmitry Osipenko Message-ID: Date: Fri, 10 Dec 2021 21:52:01 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 10.12.2021 21:19, Rafael J. Wysocki пишет: ... >> +bool atomic_notifier_has_unique_priority(struct atomic_notifier_head *nh, >> + struct notifier_block *n) >> +{ >> + unsigned long flags; >> + bool ret; >> + >> + spin_lock_irqsave(&nh->lock, flags); >> + ret = notifier_has_unique_priority(&nh->head, n); >> + spin_unlock_irqrestore(&nh->lock, flags); > > This only works if the caller can prevent new entries from being added > to the list at this point or if the caller knows that they cannot be > added for some reason, but the kerneldoc doesn't mention this > limitation. I'll update the comment. .. >> +bool blocking_notifier_has_unique_priority(struct blocking_notifier_head *nh, >> + struct notifier_block *n) >> +{ >> + bool ret; >> + >> + /* >> + * This code gets used during boot-up, when task switching is >> + * not yet working and interrupts must remain disabled. At such >> + * times we must not call down_read(). >> + */ >> + if (system_state != SYSTEM_BOOTING) > > No, please don't do this, it makes the whole thing error-prone. What should I do then? >> + down_read(&nh->rwsem); >> + >> + ret = notifier_has_unique_priority(&nh->head, n); >> + >> + if (system_state != SYSTEM_BOOTING) >> + up_read(&nh->rwsem); > > And still what if a new entry with a non-unique priority is added to > the chain at this point? If entry with a non-unique priority is added after the check, then obviously it won't be detected. I don't understand the question. These down/up_read() are the locks that prevent the race, if that's the question.