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 BFB22EB64D7 for ; Mon, 26 Jun 2023 17:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjFZRWm (ORCPT ); Mon, 26 Jun 2023 13:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbjFZRWO (ORCPT ); Mon, 26 Jun 2023 13:22:14 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3C7C1BC9 for ; Mon, 26 Jun 2023 10:21:48 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f14865fcc0so211e87.0 for ; Mon, 26 Jun 2023 10:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687800107; x=1690392107; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=EXUwrqbW0CXJtQS1yFwwf9wv/D/LvsteOPvVyPaUfSk=; b=joXIcqK3i0h55kc3s/d55vUiOTlQn7SbDLMMwxUdUM32dFRmUikiTbdHjDkcwnmwN6 PPRmf2gf7wIFemHUiB+cbt7ZOlP9kCbfsztX9lftQAfYs5JRPqwFhrPhZvLyYJYkbZnj ftxvRH5aEru0CqtiHCIW7k7WIB6U1R6D8pdSJZLx0GH9BTZIKfilbrHcnnGLPFk+Btzi VoxskFgaeZksRGudmUxt4UDBTtmipInWBm+wVj5JgoITmadJPzMFDCSniRjQSRT8+WQs RaMjBz7Ta3BWcbsFlukXE/YfevMKzd2z/60B4UoAGUa3avALlD0bZyB5Kcbo6Kqn82P3 t2VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687800107; x=1690392107; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EXUwrqbW0CXJtQS1yFwwf9wv/D/LvsteOPvVyPaUfSk=; b=ka4brX8DdK8iFyFabQ2gmZOlkfbKgNtGuohmFMzA0tLJmtFNUA4mPtoWkuT5N7hcxg LYnprA+hIqQqEMWy8PAwMlG7QTfUh/iZp64Yx8SAqFTnXb36fQVzCZ85LyQEynnQ/wKo fzo5BDnjaGt3e/AcJ8f5dO2iDm8hNVzUF0dzupIguVB1Ac21YnPpEaoQVBBZPmmvF+md gNEN15Ux4vd2dwK6nrDuqySakEEgVA3cMp8z7rW7IGasC2ECSc/Eyo07Aunb35+770DV 0exx/tNm/r6e0qQq4U2AvDjDC6x7nOyS0BL719MFgGyJO6KCp+SqhbvNJfuOrdydtM9t 6Lzg== X-Gm-Message-State: AC+VfDx7RgYoEFwgtevRvK94+M9TrACNL5ZGnhC7Wh3M9zd/JJkaEUh+ DNlYrGkh5LuxI0O62q+6zlC4zu9K6MzOwEKHuegctQ== X-Google-Smtp-Source: ACHHUZ49Xf5imMxxHbAmq1pZx/TUMlMscTGGSxt0e3GzZZiP4TlUcTbpNc4E0xG6h1gjBiXYnz/qs9qKmdpeeaaY9Do= X-Received: by 2002:ac2:4470:0:b0:4f3:a7c6:590e with SMTP id y16-20020ac24470000000b004f3a7c6590emr116784lfl.7.1687800106702; Mon, 26 Jun 2023 10:21:46 -0700 (PDT) MIME-Version: 1.0 From: Dmitry Vyukov Date: Mon, 26 Jun 2023 19:21:34 +0200 Message-ID: Subject: Thread-safety annotations for irq/rcu/atomic contexts To: clang-built-linux , Lukas Bulwahn Cc: LKML , Marco Elver Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Previous Lukas' attempt to apply clang thread-safety annotations to the kernel: https://clangbuiltlinux.github.io/CBL-meetup-2020-slides/lukas/tsa.pdf I am thinking if the annotations can be used to check for functions that must/must not be called from irq/atomic/rcu_read/etc contexts. Namely, we create global fake locks that denote these contexts, then annotate spin_lock_irqsave/irqrestore/etc as taking releasing these locks, and finally annotate functions are requiring/excluding these contexts: void foo() require(irq_context); void bar() exclude(irq_context); void baz() require(rcu_read_context); This may help to catch "suspicious RCU usage", "scheduling while atomic" and similar bug types statically. I suspect it may also be simpler (?) to do rather than annotating all normal locks. Does it make any sense?