From patchwork Wed Oct 2 09:44:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1991912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJVKW6y3sz1xtr for ; Wed, 2 Oct 2024 19:45:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1svvuw-0006Nl-TH; Wed, 02 Oct 2024 09:45:10 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1svvut-0006MX-3P for kernel-team@lists.ubuntu.com; Wed, 02 Oct 2024 09:45:07 +0000 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 941973F1AF for ; Wed, 2 Oct 2024 09:45:06 +0000 (UTC) Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42caf073db8so53978335e9.3 for ; Wed, 02 Oct 2024 02:45:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727862303; x=1728467103; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OCuizuvMa0H7/ZSAX9VV2jqRL+KM9drJSn2/Tl3zksg=; b=hxsH+UxXfgrECn0GBJxLTdLpW9Ze5/ao4ytn/FjwPTa/wV5kq5CSB+SFRasbJGli1C E0dfJ3hxcbtdLmorqkcUHxaESGGjN2AlPrY9Vrcc+Lgb4Y3ePZRwhGvGOFjjFu5/muoz pynGvDFxGgM/448sHajmA59PoGZ+AORwvxRZyWEJKBTjEJi0Ss8x+jk+KNXpJlNSyTg0 GFyP9s2KwFRA1VIPHBJBCcGh9xH7TT84YompF2rNftQB3aCmqbU8ErG4owk0/H+1Wgrd tshTAwBSBZGIikjKZ0PYi1gccenVslAGiINzHfJiGcmvVHnibWs5qpHlEHBoJQdurEa5 FGFg== X-Gm-Message-State: AOJu0YzXMtBWvmjEF0AFeGdFpRFw3BCccvNxsYV1oHGS697+YI3QX0sQ ExiVtCnzBw7/YfiZnY3X5dLFGqU1ysfcaMzucXbAevxaUFyuQtydjFJGu7axzmsgVUIqUZWVWLy 3wq0yD+VX2rur7+FjEfR9k6Fm8vRN4wqf5T91D9Lvwuip6thBw3FEQmG8sK7kjAS9NekjUXvhty aXK0b8Q3Tctw== X-Received: by 2002:a05:600c:5254:b0:426:5fbc:f319 with SMTP id 5b1f17b1804b1-42f778f4e11mr18164415e9.33.1727862303624; Wed, 02 Oct 2024 02:45:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBIsclTFHcMZy1fGAbIY/wPl5Rd35RQodImS4Zdvds4r6Rv3ECPpRtcAIwnQasp2G3wQxKKg== X-Received: by 2002:a05:600c:5254:b0:426:5fbc:f319 with SMTP id 5b1f17b1804b1-42f778f4e11mr18164245e9.33.1727862303153; Wed, 02 Oct 2024 02:45:03 -0700 (PDT) Received: from localhost ([81.221.247.52]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f7a01f48esm13780235e9.33.2024.10.02.02.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 02:45:02 -0700 (PDT) From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [SRU][N][PATCH 2/6] compiler_types: add Endianness-dependent __counted_by_{le, be} Date: Wed, 2 Oct 2024 11:44:53 +0200 Message-ID: <20241002094457.1777904-3-juerg.haefliger@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241002094457.1777904-1-juerg.haefliger@canonical.com> References: <20241002094457.1777904-1-juerg.haefliger@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Alexander Lobakin BugLink: https://bugs.launchpad.net/bugs/2078038 Some structures contain flexible arrays at the end and the counter for them, but the counter has explicit Endianness and thus __counted_by() can't be used directly. To increase test coverage for potential problems without breaking anything, introduce __counted_by_{le,be}() defined depending on platform's Endianness to either __counted_by() when applicable or noop otherwise. Maybe it would be a good idea to introduce such attributes on compiler level if possible, but for now let's stop on what we have. Acked-by: Kees Cook Acked-by: Gustavo A. R. Silva Signed-off-by: Alexander Lobakin Reviewed-by: Przemek Kitszel Link: https://lore.kernel.org/r/20240327142241.1745989-2-aleksander.lobakin@intel.com Signed-off-by: Jakub Kicinski (backported from commit ca7e324e8ad385a2da15049953c04ea7310687f7) [juergh: Adjusted context in include/linux/compiler_types.h.] Signed-off-by: Juerg Haefliger --- Documentation/conf.py | 2 ++ include/linux/compiler_types.h | 11 +++++++++++ scripts/kernel-doc | 1 + 3 files changed, 14 insertions(+) diff --git a/Documentation/conf.py b/Documentation/conf.py index d148f3e8dd57..0c2205d536b3 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -75,6 +75,8 @@ if major >= 3: "__rcu", "__user", "__force", + "__counted_by_le", + "__counted_by_be", # include/linux/compiler_attributes.h: "__alias", diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index a6a28952836c..454d942384a4 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -293,6 +293,17 @@ struct ftrace_likely_data { #define __no_sanitize_or_inline __always_inline #endif +/* + * Apply __counted_by() when the Endianness matches to increase test coverage. + */ +#ifdef __LITTLE_ENDIAN +#define __counted_by_le(member) __counted_by(member) +#define __counted_by_be(member) +#else +#define __counted_by_le(member) +#define __counted_by_be(member) __counted_by(member) +#endif + /* Section for code which can't be instrumented at all */ #define __noinstr_section(section) \ noinline notrace __attribute((__section__(section))) \ diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 08df66070252..b2d2f5849ed0 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1145,6 +1145,7 @@ sub dump_struct($$) { $members =~ s/\s*$attribute/ /gi; $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; + $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos; $members =~ s/\s*__packed\s*/ /gos; $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;