Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3492870pxp; Tue, 8 Mar 2022 15:52:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE2OFnL8p4wT0cNzHNxgEN0C8tMETdpck1A17AiEcitS6ux3DDZEoztGizrgQbUpjPyiPw X-Received: by 2002:a65:67c4:0:b0:380:189a:181a with SMTP id b4-20020a6567c4000000b00380189a181amr13353483pgs.401.1646783522176; Tue, 08 Mar 2022 15:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646783522; cv=none; d=google.com; s=arc-20160816; b=csHvOYU4qZfdeEK9i6hQY0UnUtHkheB28zgaLBil2E9ZLY2vMx0simo5dEn1CWr+s6 H1Kpb4J4UG+Ootc26mjo/gnoZibdVNfxBobuFiYh2DDzG/jS9FF1Hrod2hI4nL4SoSJ0 bGBl6Idk1u1hbRVQZ0KT289xl3XHEY6uDVCz/KffnXL+51qp2L3KGgdzJqXSlLCfic6y Gd27oRdd7nhl1HBKnA1Xee+E8VyEtMclrqD9vEWzv8Brnuco2q0EDhFjSYSZdGOTRx2x IK5GlMPKRIsfVQVpDunx5d0NRzdKWIfG6v86rOPd7Juz2WSrYUmpdeuHTVH5V3blZXxJ KbfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject; bh=LzXkQK1Cn6EFWKq6iMBN6ZfYR9Stati8GBpxjOV5XhQ=; b=yAPALjGBHLm7pC65h7QbjIa81BosbnrKcsz0PTarA4sB1eRxZLQpTGnhyRKhV1j5fG 1XkGsskrkhst7nYgRPl7goxBBtCBj69QBDbxCkm+HVAH9g16jmeNv4eGni41P3pJIRQ5 Cef0GTQx5YNOi3CcBmOaezhEFK6bRzZUgWcK9V1g0AJq5lqmJNVTaZJHTlr49mijgVAF 0qL9p9nEY2dJhM99dDrA3hmEdD0a+bomDAE7emvboKaPmzXKaiimLJV4NhdDugA03q/r mH/JAx75Pnz6KdF0wtRdlB1L4dPgsyhu86jKf7e859oIkXL01Ei5jGuuMR9o2M7PhjEF KWuA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v10-20020a63610a000000b0038053973764si274158pgb.177.2022.03.08.15.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:52:02 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F215ACA73D; Tue, 8 Mar 2022 15:31:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347747AbiCHPBx (ORCPT + 99 others); Tue, 8 Mar 2022 10:01:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237601AbiCHPBw (ORCPT ); Tue, 8 Mar 2022 10:01:52 -0500 X-Greylist: delayed 87 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 08 Mar 2022 07:00:56 PST Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27FF522B39; Tue, 8 Mar 2022 07:00:56 -0800 (PST) Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1nRbK3-0007bV-Mq; Tue, 08 Mar 2022 16:00:23 +0100 Received: from [85.1.206.226] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRbK3-0002yZ-7c; Tue, 08 Mar 2022 16:00:23 +0100 Subject: Re: [PATCH] selftests/bpf: fix array_size.cocci warning From: Daniel Borkmann To: Guo Zhengkui , Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Dave Marchevsky , Yucong Sun , Christy Lee , Delyan Kratunov , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgense?= =?UTF-8?Q?n?= , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:BPF (Safe dynamic programs and tools)" , "open list:BPF (Safe dynamic programs and tools)" , open list Cc: zhengkui_guo@outlook.com References: <20220308091813.28574-1-guozhengkui@vivo.com> Message-ID: Date: Tue, 8 Mar 2022 16:00:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.5/26475/Tue Mar 8 10:31:43 2022) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On 3/8/22 3:59 PM, Daniel Borkmann wrote: > On 3/8/22 10:17 AM, Guo Zhengkui wrote: >> Fix the array_size.cocci warning in tools/testing/selftests/bpf/ >> >> Use `ARRAY_SIZE(arr)` instead of forms like `sizeof(arr)/sizeof(arr[0])`. >> >> syscall.c and test_rdonly_maps.c don't contain header files which >> implement ARRAY_SIZE() macro. So I add `#include `, >> in which ARRAY_SIZE(arr) not only calculates the size of `arr`, but also >> checks that `arr` is really an array (using __must_be_array(arr)). >> >> Signed-off-by: Guo Zhengkui > [...] >> diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c >> index e550f728962d..85c6e7849463 100644 >> --- a/tools/testing/selftests/bpf/progs/syscall.c >> +++ b/tools/testing/selftests/bpf/progs/syscall.c >> @@ -6,6 +6,7 @@ >>   #include >>   #include <../../../tools/include/linux/filter.h> >>   #include >> +#include >>   char _license[] SEC("license") = "GPL"; >> @@ -82,7 +83,7 @@ int bpf_prog(struct args *ctx) >>       static __u64 value = 34; >>       static union bpf_attr prog_load_attr = { >>           .prog_type = BPF_PROG_TYPE_XDP, >> -        .insn_cnt = sizeof(insns) / sizeof(insns[0]), >> +        .insn_cnt = ARRAY_SIZE(insns), >>       }; >>       int ret; >> diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c >> index fc8e8a34a3db..ca75aac745a4 100644 >> --- a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c >> +++ b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c >> @@ -3,6 +3,7 @@ >>   #include >>   #include >> +#include >>   #include >>   const struct { >> @@ -64,7 +65,7 @@ int full_loop(struct pt_regs *ctx) >>   { >>       /* prevent compiler to optimize everything out */ >>       unsigned * volatile p = (void *)&rdonly_values.a; >> -    int i = sizeof(rdonly_values.a) / sizeof(rdonly_values.a[0]); >> +    int i = ARRAY_SIZE(rdonly_values.a); >>       unsigned iters = 0, sum = 0; > > There's bpf_util.h with ARRAY_SIZE definition which is used in selftests, pls change to > reuse that one. Also, CI failed with your patch: https://github.com/kernel-patches/bpf/runs/5462211251?check_suite_focus=true In file included from progs/test_rdonly_maps.c:6: In file included from /usr/include/linux/kernel.h:5: /usr/include/linux/sysinfo.h:9:2: error: unknown type name '__kernel_long_t' __kernel_long_t uptime; /* Seconds since boot */ ^ /usr/include/linux/sysinfo.h:10:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */ ^ /usr/include/linux/sysinfo.h:11:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t totalram; /* Total usable main memory size */ ^ /usr/include/linux/sysinfo.h:12:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t freeram; /* Available memory size */ ^ /usr/include/linux/sysinfo.h:13:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t sharedram; /* Amount of shared memory */ ^ /usr/include/linux/sysinfo.h:14:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t bufferram; /* Memory used by buffers */ ^ /usr/include/linux/sysinfo.h:15:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t totalswap; /* Total swap space size */ ^ /usr/include/linux/sysinfo.h:16:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t freeswap; /* swap space still available */ ^ /usr/include/linux/sysinfo.h:19:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t totalhigh; /* Total high memory size */ ^ /usr/include/linux/sysinfo.h:20:2: error: unknown type name '__kernel_ulong_t' __kernel_ulong_t freehigh; /* Available high memory size */ ^ /usr/include/linux/sysinfo.h:22:22: error: use of undeclared identifier '__kernel_ulong_t' char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */ ^ progs/test_rdonly_maps.c:68:10: error: implicit declaration of function 'ARRAY_SIZE' is invalid in C99 [-Werror,-Wimplicit-function-declaration] int i = ARRAY_SIZE(rdonly_values.a); ^ 12 errors generated. make: *** [Makefile:488: /tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/test_rdonly_maps.o] Error 1 make: *** Waiting for unfinished jobs.... Error: Process completed with exit code 2.