From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795116336; b=YU1xx/+T9/gppmQ0fzi3cDxeeQ8BgB+TGmGOmC/qbJ/JETl2X2tCAQ07YDLtBWPK+zqZ wgxCoPTxvlCfHeq3H/kUTlW/ZBjVc3GNE5ZLRe3exlUcc2yjJWf01O5Z07f7W5PS/cgYY 9gIlWnH4nwpAhz/WQCBzWH0dyFzZYcqSlKOCgfKsa7lHMzXPJCooQCQLQ541qIY2RF2Fn dJ9t5d8BcilWp9Y6PkQGW0+WZ02qBvit2EUTbmJ/McVzSnXd8OBjhtQKtaiUEVr0HPwaN rdUmNuKI44wSZFlzSOSAiUzbsH7xMjmvZW7riQTmoDZaOp1upEY4cH8XBf80kG2qu8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795116336; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=5sSK0mEpHDMvzrLQAsEFtk5LbI4UItSogecSbLV64WI=; b=AiTLhMFN49Ntlq4bDxJPjUm7xartPXsOIDIgPGHXMX7pvmSnabCRPahmU3V5nDzkOJdw VMk9sm5DcD7+7Z/mdd3gAHdxJByr/NCaRtzvSl397t34+cGnb7RgX/PWwrwhforS7CeF3 impazmpzO1VVCxlgHZMaZ1monSOVy2DV2m/gqQIe7+O3bnoDHwLHOY4aqJkbu7fcouZUt iwNn/KDukJGpD4e9l54llNVxcXXQ6ZHkU6zSRKRj8DV476t0LzfwUOxqTczidWNMRAZow x3aFY6b/e9JELhf6z7kQqHKmX/g8wsrU2do01wcd/xLLc+lo95cP5JcZjeSqcET3duQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jsDNgjK9; arc=none smtp.remote-ip=74.125.82.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9744760A2608 for ; Thu, 19 Nov 2026 19:25:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9744760A2608 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jsDNgjK9 Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-38531c1a566so110509eec.1 for ; Thu, 19 Nov 2026 11:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795116335; x=1795721135; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5sSK0mEpHDMvzrLQAsEFtk5LbI4UItSogecSbLV64WI=; b=jsDNgjK9H3WzWV1nFlC/nPOonF3As4uF8i252IB5Iayfe+YMQAx4aK1ZgtHqU3ylF1 qCQ2Aa1fRig+8MOpwaPotXPIBFHwEdGO8KETRUnHNGShaVuAoxNF908tV0EPKeu3fPPU vWoqgXqmhKSFHp+oZfm7imuSGUMmAPT109I2Mp0s4U6ugYIHi4Q6eOEZaU2wRldbmWmc 1FcQHhb9g/EEH9RV8ufzA3oOdmuFwKaZjjICjfRob0wf4QQpfiTrvMFSl4Sxmk6WDH3O O+5iY+Wj9s5hG2FiX85RjAdyzamXFz/RJ7WeP2fw3PynqrIuy4QT8YSy1FtrEnwS9I/i BbJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795116335; x=1795721135; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5sSK0mEpHDMvzrLQAsEFtk5LbI4UItSogecSbLV64WI=; b=CxBxKqPdi6Xh0ilZDqSs76Dj9xX9AI0M46ZNaJhtc9bAkbnd/OWpUyXAjoHFacZV33 Ie8olQO4C28pBjdB687uoi63VeV4X3PLIfVWZh3Tf330XLi4nqfRZ8Dqqq3T7Rq6VDYc nvmOfxqp8BbXaitYAXGNtgvQgKx3iq5TU5vZjChhOram3Sp7bcRu9A4jmyTs679CA31i hCbu8gtmfTnl83UpWyqTZIQKeyxMnYxuUy3I7rma6D5QE6g74vCXFJLCxhOD/0o2knff u/4e1nkBLsmqNHopfMvrqeg3GMlvTJBOdQBrpawH1C2PbihDUaAGo7xJDneIXu566bbA VSoQ== X-Forwarded-Encrypted: i=1; AL+hErEsJHC5ZpDtxEzahv3wJ41g+3VMfH3lYmfE5dSfJ7yKjMZTFcntuSoELKWCR82x8mN1gWjhv9PBqXvMImNO@vger.kernel.org X-Gm-Message-State: APuU4Z8MdDshlASWgLDprN2yp8lN1nl3gJ6Q5Z5l7DBuSMv+ObVtRACn DKxogngb1k4WY9fKNi2nPvxgqPJ7moHI/YyRAXLYoJ3rGDsZUsvCo6Xh0rRQ6W6uRLMCGGHxnek COvoVPkfqZA== X-Received: from dybqm10.prod.google.com ([2002:a05:7301:670a:b0:385:6c3c:3ea1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:152f:b0:381:c532:3d88 with SMTP id 5a478bee46e88-3857093c38bmr360600eec.23.1795116334302; Thu, 19 Nov 2026 11:25:34 -0800 (PST) Date: Thu, 19 Nov 2026 11:25:12 -0800 In-Reply-To: <20261119192520.1983406-1-irogers@google.com> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261119192520.1983406-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog Message-ID: <20261119192520.1983406-2-irogers@google.com> Subject: [PATCH v4 1/9] Compiler Attributes: Add __must_init macro From: Ian Rogers To: Danilo Krummrich , Greg Kroah-Hartman , Kees Cook , Miguel Ojeda , "Rafael J . Wysocki" Cc: Madhavan Srinivasan , Srish Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Nayna Jain , Mimi Zohar , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Nathan Chancellor , Nick Desaulniers , Viresh Kumar , Zhongqiu Han , Alexander Aring , Felix Kuehling , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Zhihao Cheng , Sumanth Korikkar , Bill Wendling , Justin Stitt , driver-core@lists.linux.dev, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, linux-s390@vger.kernel.org, gfs2@lists.linux.dev, xen-devel@lists.xenproject.org, linux-mtd@lists.infradead.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Clang supports the 'require_explicit_initialization' attribute on struct fields to indicate that a field must be initialized explicitly by the user when the object is constructed. When an aggregate initializer or uninitialized variable omits an annotated field, Clang emits a -Wuninitialized-explicit-init warning (enabled by default). Add the __must_init macro to include/linux/compiler_attributes.h (which is included by include/linux/compiler_types.h and include/linux/compiler.h) so kernel structs with error-prone initialization (such as mandatory callbacks or cleanup handlers) can enforce explicit initialization at compile time, as discussed at the Linux Plumbers Conference. The shorter __must_init spelling, rather than the attribute's full name, keeps annotated struct members readable and was suggested by Greg Kroah-Hartman. Note that Clang versions prior to the fix for https://github.com/llvm/llvm-project/issues/232483 do not diagnose file-scope objects declared without any initializer (initializers at file scope that omit the field are diagnosed). Also teach Sphinx (Documentation/conf.py), kernel-doc (tools/lib/python/kdoc/xforms_lists.py), and checkpatch.pl about the new attribute macro. Link: https://lpc.events/event/20/contributions/2392/ Link: https://lore.kernel.org/lkml/2026101532-fantastic-deafness-e04c@gregkh/ Acked-by: Miguel Ojeda Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Acked-by: Greg Kroah-Hartman Reviewed-by: Kees Cook Signed-off-by: Ian Rogers --- Documentation/conf.py | 1 + include/linux/compiler_attributes.h | 12 ++++++++++++ scripts/checkpatch.pl | 1 + tools/lib/python/kdoc/xforms_lists.py | 1 + 4 files changed, 15 insertions(+) diff --git a/Documentation/conf.py b/Documentation/conf.py index 5ab26ce89daf..baaa4035258c 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -203,6 +203,7 @@ c_id_attributes = [ "__noreturn", "__packed", "__pure", + "__must_init", "__section", "__always_unused", "__maybe_unused", diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 476c4c560d17..b9c0b56dd22e 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -322,6 +322,18 @@ */ #define __pure __attribute__((__pure__)) +/* + * Optional: not supported by gcc + * Optional: only supported since clang >= 20.0 + * + * clang: https://clang.llvm.org/docs/AttributeReference.html#require-explicit-initialization + */ +#if __has_attribute(__require_explicit_initialization__) +# define __must_init __attribute__((__require_explicit_initialization__)) +#else +# define __must_init +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b8b64f720191..6a091c45b1a1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6888,6 +6888,7 @@ sub process { "noreturn" => "__noreturn", "packed" => "__packed", "pure" => "__pure", + "require_explicit_initialization" => "__must_init", "section" => "__section", "used" => "__used", "weak" => "__weak" diff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py index db23fb650ea8..42956b98aae3 100644 --- a/tools/lib/python/kdoc/xforms_lists.py +++ b/tools/lib/python/kdoc/xforms_lists.py @@ -36,6 +36,7 @@ class CTransforms: (CMatch("CRYPTO_MINALIGN_ATTR"), ""), (CMatch("__private"), ""), (CMatch("__rcu"), ""), + (CMatch("__must_init"), ""), (CMatch("____cacheline_aligned_in_smp"), ""), (CMatch("____cacheline_aligned"), ""), (CMatch("__cacheline_group_(?:begin|end)"), ""), -- 2.56.1.708.g77570a6a1d-goog