Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3233344rwb; Fri, 9 Dec 2022 11:39:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5b0x3gUIuAtC41basf3+9v37D8k4yr10odtVrGeEDK8p+GLdcYuA8xdMwBLtE9iDV70aT3 X-Received: by 2002:a05:6402:1711:b0:46c:ec97:b453 with SMTP id y17-20020a056402171100b0046cec97b453mr6035647edu.12.1670614775823; Fri, 09 Dec 2022 11:39:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670614775; cv=none; d=google.com; s=arc-20160816; b=CbHv0Mx6PuwEJN3xqvKwr8NruTcoBp6FXS/k17UNgp8pWfMY94RUSXWzPTyGtnUjoj NEUCBR6KBxQwqn4SvngpWfedv6jhESLsSkx7IgkzYrdk7SeIRAPKf0wETtHLaM6dSWLg g5vF0WNJll7Qk9HARROn/fZK7Yexo9ce61hWxwZfZRQWemfNL3wtUmkL9ZoGgtdrgTI7 /5tjht2K7aKftIovMsNafTn1EOBkg5+YeMUpMROnGIvZ+zKHl0/NFE/9oLqhGnaXm4zF okQppc/j/xUht1we2SttArAs5RUPHx+8c7cy7+BP4BOHSDYr0BWQtYgAhi6Cgbjaq9Fc KW2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=a/OvMNsAzsgvJI+DZSdj+rRXl8KhhsBZiWxKq1VinuU=; b=GoP1AYU0SQIdm93Df/bDB0hJgBOdqk/eGjd79nPhxYNzymtpTFMBOh/birhxxztGQ6 h8uu5CaVvfC+IPnOeZpJWFePO6qdt/OnPKghUkPSunHBujhkab06DFVvsyDiHOib4LNX axvlK6AB/V+VF1gbiXMO3WZhdZdZJkaABYn/KU/YxdQ+vzoiDz395SlMtkWFy/hn8KG6 GWaeybu8/sFmzThaqS1X0kbpihz7y4OeI/4367utKnOjDJjRLCeOyeAKkVaG9Fo5CWJi yR1dbhBfN4HAlYz02EwxA4HEXMRL3dytIZPPhNNGdWPtl7O3svU9tCsyR+qSfQciJH1d SGqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=jKuZ2r1d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r29-20020a50aadd000000b00467c3cbab04si1796622edc.66.2022.12.09.11.39.18; Fri, 09 Dec 2022 11:39:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=jKuZ2r1d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbiLISsA (ORCPT + 74 others); Fri, 9 Dec 2022 13:48:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbiLISr6 (ORCPT ); Fri, 9 Dec 2022 13:47:58 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE93621800 for ; Fri, 9 Dec 2022 10:47:56 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id h8-20020a1c2108000000b003d1efd60b65so495203wmh.0 for ; Fri, 09 Dec 2022 10:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=a/OvMNsAzsgvJI+DZSdj+rRXl8KhhsBZiWxKq1VinuU=; b=jKuZ2r1dZ9JWyv8xEkfsg1ahawfcwPcqDQoraXkbZWZ4QIJ++dVVmyX5gAU4P8Io6r 9coPM6MsAWm4lQxNiw38VgBJZcwIGJAWBUMlk1+7gXNnM7m96lun8idFeh5suqj+uhoc HjRULtC/TJ+I5PchhXGQJaeoZh1cEqMvLO7Q6pBzsZYhJZ0FhRlQ/OSU8F+42Sw3VJuR zvVmQSr/ljRQc5kf6d8XW9XseoXr8QlHkBNxMrXDD9+5XYT2j9NWcIjGCu+qon4a82Yh zuq7K6JFlP3qcL9NJivzznEpiEd7O4J4D03rZ+AwNgKi+nTBbUVgg0sy0CmhmwJuD9B/ BBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a/OvMNsAzsgvJI+DZSdj+rRXl8KhhsBZiWxKq1VinuU=; b=zeFgL69caF/PlbPHp/h8H9VFcWv9M35sJh1+SAjN5AKx5L5aNDuInaLpOASMg/Vhn5 k6LMVYi4z10pU6ZnjDutUPYiyMFBc2E2MBrGo3rkKTqrqnCX+AZpoUdVFK7Sdqzk8npb Eh3qoeGgnLPP3joyt0PCtQ+Jhd4zJKQisnM3/xqeZUOGRu0VgTLBrqFFUIDmgu7EYzgO wJQpCB5NIQE9uQodO9RiY9F6xejfvxETTVpiFio/TL9NMIJgL/P/+JPHGQ7IwEgC2MM7 sODjIrsZwrBV8GF6Tgx06NSK9aBCt5nqJ7bNqV2Knd3+hy/c0SWxEnDyFYh+PYoDmtTf lGnA== X-Gm-Message-State: ANoB5pmTPpw21y0GrvDiIf1er/VWO0q5YCuvsC855QcZUMOxRON+2NT4 mdruFvwjqEiSk5Z3TmVLSe97jw== X-Received: by 2002:a05:600c:5012:b0:3cf:6c16:2622 with SMTP id n18-20020a05600c501200b003cf6c162622mr5684378wmr.33.1670611675506; Fri, 09 Dec 2022 10:47:55 -0800 (PST) Received: from ?IPV6:2003:d9:9703:3100:a3be:b12f:5235:421? (p200300d997033100a3beb12f52350421.dip0.t-ipconnect.de. [2003:d9:9703:3100:a3be:b12f:5235:421]) by smtp.googlemail.com with ESMTPSA id bu26-20020a056000079a00b0024207ed4ce0sm2057346wrb.58.2022.12.09.10.47.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Dec 2022 10:47:55 -0800 (PST) Message-ID: Date: Fri, 9 Dec 2022 19:47:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: Invalid locking pattern in Documentation/kernel-hacking/locking.rst? To: "Sverdlin, Alexander" , "corbet@lwn.net" , "linux-doc@vger.kernel.org" , thomas Gleixner , Ingo Molnar Cc: "linux-kernel@vger.kernel.org" , 1vier1@web.de References: <442ecdf402f8e726f2be4ab19c7299d272e27c0b.camel@siemens.com> Content-Language: en-US From: Manfred Spraul In-Reply-To: <442ecdf402f8e726f2be4ab19c7299d272e27c0b.camel@siemens.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexander, On 12/9/22 13:23, Sverdlin, Alexander wrote: > Dear documentation maintainers, > > the latest version of locking.rst contains the following (since 2005): > > "Manfred Spraul points out that you can still do this, even if the data > is very occasionally accessed in user context or softirqs/tasklets. The > irq handler doesn't use a lock, and all other accesses are done as so:: > > spin_lock(&lock); > disable_irq(irq); > " > > Isn't it "sleeping in atomic" actually because of the sleeping > disable_irq()? Good catch! The documentation of disable_irq() claims that the function is safe to be called from IRQ context (for careful callers) But it calls synchronize_irq(). And synchronize_irq() claims that the function can be called only from preemptible code. The change was in 2009: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.1-rc8&id=3aa551c9b4c40018f0e261a178e3d25478dc04a9 @Thomas/@Ingo: What do we want? Declare disable_irq()&synchronize_irq() as safe from irq context only if no threaded irq handlers are used? Or declare both function as preemptible context only? The update for locking.rst would be to switch from spin_lock() to mutex_lock(). https://elixir.bootlin.com/linux/latest/source/kernel/irq/manage.c#L126 > /** > * synchronize_irq - wait for pending IRQ handlers (on other CPUs) > * @irq: interrupt number to wait for > * > * This function waits for any pending IRQ handlers for this interrupt > * to complete before returning. If you use this function while > * holding a resource the IRQ handler may need you will deadlock. > * > * Can only be called from preemptible code as it might sleep when > * an interrupt thread is associated to @irq. > * > * It optionally makes sure (when the irq chip supports that method) > * that the interrupt is not pending in any CPU and waiting for > * service. > */ > void synchronize_irq > (unsigned int irq) > { > struct irq_desc *desc = irq_to_desc > (irq); > > if (desc) { > __synchronize_hardirq > (desc, true ); > /* > * We made sure that no hardirq handler is > * running. Now verify that no threaded handlers are > * active. > */ > wait_event > (desc->wait_for_threads > , > !atomic_read > (&desc->threads_active > )); > } > } > EXPORT_SYMBOL > (synchronize_irq > ); https://elixir.bootlin.com/linux/latest/source/kernel/irq/manage.c#L716 > /** > * disable_irq - disable an irq and wait for completion > * @irq: Interrupt to disable > * > * Disable the selected interrupt line. Enables and Disables are > * nested. > * This function waits for any pending IRQ handlers for this interrupt > * to complete before returning. If you use this function while > * holding a resource the IRQ handler may need you will deadlock. > * > * This function may be called - with care - from IRQ context. > */ > void disable_irq > (unsigned int irq) > { > if (!__disable_irq_nosync > (irq)) > synchronize_irq > (irq); > } > --     Manfred