From patchwork Mon Jul 29 09:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744649 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAFD13DDC0; Mon, 29 Jul 2024 09:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245082; cv=none; b=quc7vsnHxdljB1tpIKsSMA44PzK3KzdwhSiaRKD1Y4nqWJT5CDA9+NsMb9Q4XAerelDkkTTsY5PHdEMiU9AJeTmc2ga8cxGnNxvFg7KB0b116uMZx7zPuKMkoRTkSo69j1KEKZidyZqvjOzA9GYzVPqrz0xCQs7dJ5wt9LyduoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245082; c=relaxed/simple; bh=mqau6BYFCsnrLX9rIGpXbOOrld7xoidDlOUjA0t1Ii4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qCNGY2alNQXiN9hx4p8qUTv9XIFzpCbRsL47LfBQyaX9nZDLum1eMswgdbD72DCyxsEczniuExB8JD/vYj/9S7LahZb7jVYIsGuPpaw/AZ6GhgUvCqPlD5brA9upCeJPNoRRfMmaCuue5DJmk1SzP++TQW9Jj0Nrau+PDaEJRBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FK26g7xM; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FK26g7xM" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc66fc35f2so17230305ad.0; Mon, 29 Jul 2024 02:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245080; x=1722849880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q8u/O4Ht4iTO9/a3lv5vZK9Oe8/7dFCMI+nDwx91aig=; b=FK26g7xM+81OXxuZqO3u5GtlurkM0ZAi8XyiISmQmUt3r9+o5zIfc6tRzsVyuGZ4J9 45x6jU5sTUeHhmljWWH8zSd3NaijZtRjvDH9y46xn4n2Ki+U/dTIIEmUtKzIeYnmoz+j T+Ln1aMpTZai0FjrqB9g8Y2stJA0dPt/ID32iVcoX7wJtDINWoaVnW0QqsjWOSOuyP6F 60PrnDikIk9/WkhDUsUFkKm/BIKCGQ4+3VQsxuNVWT23Ra5rnNXi5KRhIanQfhM7IYwQ IGudlJ2HNALKCybwQHAOQvITfrYnsnHXePuUtvhRM0eB3yj0ISWBPPrZ+JZqHm+g2iXc CFTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245080; x=1722849880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q8u/O4Ht4iTO9/a3lv5vZK9Oe8/7dFCMI+nDwx91aig=; b=A6fgWmrbLy3ZxPogJyz4UhoLM7A32wQrCgcXjL/api0wgdSgLwwRQv751pDJVzX0Nt 9ehXvD3KHDSb1rrOrqWvTeMiMpA2ZBXNYFlUPF5EQlp7E5oVo4BtYHqzVuvePM+vRiB/ cKkb7zsiyj85xiHafB4JJaSMRTTrfuLnuKpKFMkwXMIEaifUTct05KW6Ya6YalQ7aMBU 8EGFZtudwfjiIjHQ0y+uW5bv3v2dTyS5synwAy3ZdwTAB4E5faTlmqbcotGLPMez4SxS +vzI9nSjhjy4ACOrQBkUwXy0i1fs2hHMrhhppFIQW/NJKN9+q1rUDwN3O8dQKXi+Gatm KB6w== X-Forwarded-Encrypted: i=1; AJvYcCXgIx7HrTwtB3RV0DKuVyGEvmDcc8txesKz7qIaz3AxDsg4azyBf3mXvq1C4hhdPKcqnEhe8Ak2cvTEG0OWvE4vxfwvPpKoPbw9J7FtfObcrDXJCSbVFU25k/FlhYL6OeTGiVkoPkLG X-Gm-Message-State: AOJu0Yx3HJ+7w+C4loOBLKKFwM9Yc/4tOuRnntni4JkooeKIgKZUTMY6 kQc3bcf+drghDknfnsGKvnbCwEY4fZdA0+qQyFHV9HBnziKC5/rVlrEXjzql X-Google-Smtp-Source: AGHT+IElBtnb9CIfRmzOh33uMoXdwdd5Cp0grdAW8W2Yt+zJ9cicqpZdnsTVmNNCgcFzUHdGv03QRg== X-Received: by 2002:a17:903:40cb:b0:1fd:8f7b:1e88 with SMTP id d9443c01a7336-1ff04a4f98cmr95439365ad.12.1722245079478; Mon, 29 Jul 2024 02:24:39 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:24:39 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 1/8] selftests/bpf: Use portable POSIX basename() Date: Mon, 29 Jul 2024 02:24:17 -0700 Message-Id: <0fd3c9f3c605e6cba33504213c9df287817ade04.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Use the POSIX version of basename() to allow compilation against non-gnu libc (e.g. musl). Include ahead of to enable using functions from the latter while preferring POSIX over GNU basename(). In veristat.c, rely on strdupa() to avoid basename() altering the passed "const char" argument. This is not needed in xskxceiver.c since the arg is mutable and the program exits immediately after usage. Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/veristat.c | 8 +++++--- tools/testing/selftests/bpf/xskxceiver.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c index b2854238d4a0..11ec1190d582 100644 --- a/tools/testing/selftests/bpf/veristat.c +++ b/tools/testing/selftests/bpf/veristat.c @@ -2,6 +2,7 @@ /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ #define _GNU_SOURCE #include +#include #include #include #include @@ -988,8 +989,8 @@ static void fixup_obj(struct bpf_object *obj, struct bpf_program *prog, const ch static int process_prog(const char *filename, struct bpf_object *obj, struct bpf_program *prog) { + const char *base_filename = basename(strdupa(filename)); const char *prog_name = bpf_program__name(prog); - const char *base_filename = basename(filename); char *buf; int buf_sz, log_level; struct verif_stats *stats; @@ -1056,13 +1057,14 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf static int process_obj(const char *filename) { + const char *base_filename = basename(strdupa(filename)); struct bpf_object *obj = NULL, *tobj; struct bpf_program *prog, *tprog, *lprog; libbpf_print_fn_t old_libbpf_print_fn; LIBBPF_OPTS(bpf_object_open_opts, opts); int err = 0, prog_cnt = 0; - if (!should_process_file_prog(basename(filename), NULL)) { + if (!should_process_file_prog(base_filename, NULL)) { if (env.verbose) printf("Skipping '%s' due to filters...\n", filename); env.files_skipped++; @@ -1076,7 +1078,7 @@ static int process_obj(const char *filename) } if (!env.quiet && env.out_fmt == RESFMT_TABLE) - printf("Processing '%s'...\n", basename(filename)); + printf("Processing '%s'...\n", base_filename); old_libbpf_print_fn = libbpf_set_print(libbpf_print_fn); obj = bpf_object__open_file(filename, &opts); diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c index 8144fd145237..92af633faea8 100644 --- a/tools/testing/selftests/bpf/xskxceiver.c +++ b/tools/testing/selftests/bpf/xskxceiver.c @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include From patchwork Mon Jul 29 09:24:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744650 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D065013DDC0; Mon, 29 Jul 2024 09:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245090; cv=none; b=U5oqUC/BPF7ZWcNfABrL+Zf5cqZNJQnYzpJxqteVUw2kDxF5b6QQxqbS9vrpiy0rglSGvTiCqEJYAKeHqAlAqKva+/wJLCG9rBXQ7KBGOZK8kW52XkY4UCPSuOV5FS+2ZKkPDjxDffpbSnLbIGUa88ONhZTZ0I5RUc+6YWer+Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245090; c=relaxed/simple; bh=OcXxk0CIiELOuzTAgpqOy3sTWCmDOgat+/mD5MZ1xJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=msbk+xkWRO3Utv65oPPbuDuiw9EiCOB0fQKRO9GFVMhWmbXRvb3gV5VHrUcv17WHh172Iw2buALqB9GWl4QNWgXznyrwXGLjNj64jSkE7n8Bc97IrDhEMPFq25ch7MNLF74kOegYa3Tf8Qk41m2Yjn91bqBE+5XR8SCogfabqSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LFrPp9dx; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LFrPp9dx" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70eb0ae23e4so1970553b3a.0; Mon, 29 Jul 2024 02:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245088; x=1722849888; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+ab7qTGK95IGxwGu7fOI+kWJZ+ROn9a3NpPs5CH6feo=; b=LFrPp9dxgH2NTaWlFdQlPWdKn18rlW0OIDTvEvYcE5dcxx2/j+ay2KOLCqXSl1GtzT m948xZcLiH07QLjNVzAjwrN+Rvj6NeEOpow7uA6MBAEmSHasaYWgxhsUjzY8p0NmkzjO uv6Zf5Hn7MdQm21nfYkAidG151CjPUFLgR3I7reO0VRFafgIIQAnlHfuHMD84RvYAe7j MLigwxFwOYAEQovXozx9bdiUqlVNOi01vkbUJgpO1OzRzFnrmeui2tKLHg5Lk0LTQlbI FXk99aPB1vMc6hPGaUiJeVCGY8Meo8pmvJKAXoi2Zb1dzkyNhaQFe9e5DfVciely77Yq LQoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245088; x=1722849888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+ab7qTGK95IGxwGu7fOI+kWJZ+ROn9a3NpPs5CH6feo=; b=IpbdGMdlx3LjKStqIwvfkoMxV4oFFbjjaI16BvGbh3LOW2ss/4igX7RjPl9LzZZyeB k0k+VlcMlsojHSSThmWQl82vEbkZjkw1WnK/4aAETcOmEfeMBfWfP7vCfzJM9BixwLhV /RNjKtLpWSdG8lmhbatdapHagyQIKfLujcZ0EqWDiN47usXqGhrSNAo9ngoiA0CnT/pU 53/3NBpoWm/QXDfCaTYbn5iBqI5x3mGcmXBRSyzZv5sVzJ8TKgvi2rmRpeTHii7LeAsl rcQ+uBMdjmq30YsJUpCwGcQeUKUpo4icbxwTIQmDqcXfKeFsh6OSZ5bfgbyLj9rsQp9H wX0w== X-Forwarded-Encrypted: i=1; AJvYcCUtHo/h9MNauaeBAQnImcQHpQ1PAeovijsq4Pq7XXkXX6cjQsIaE0wn7k6hp8BCt2/e40OkUurh6YWHjixuuJY0pKZbeLhRvWdGqwMAJ0VSWymX/wSuEGAlnIEXcEy6fDpBHHky23Ny X-Gm-Message-State: AOJu0YwFcYFbqNP2avobl6uXjeafPWtAT6y91CsH/7EQD8uauKSlsfU6 /8hWuYi1xK+ZIbK7VL/eKEX02WFeeV+XJ1+FswMch9WraxJStMKX3RcWngfi X-Google-Smtp-Source: AGHT+IF2wnHsO5khzhMrlfvvjeTPT4ZCH5TdwIstPXUs2IuZbX4lw6WFDCqkVENe9qHFJaMoNJHuxg== X-Received: by 2002:a05:6a20:6a20:b0:1c2:8cf4:7664 with SMTP id adf61e73a8af0-1c4a130d0aamr5895014637.31.1722245086912; Mon, 29 Jul 2024 02:24:46 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:24:46 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 2/8] selftests/bpf: Fix arg parsing in veristat, test_progs Date: Mon, 29 Jul 2024 02:24:18 -0700 Message-Id: <392d8bf5559f85fa37926c1494e62312ef252c3d.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Current code parses arguments with strtok_r() using a construct like char *state = NULL; while ((next = strtok_r(state ? NULL : input, ",", &state))) { ... } where logic assumes the 'state' var can distinguish between first and subsequent strtok_r() calls, and adjusts parameters accordingly. However, 'state' is strictly internal context for strtok_r() and no such assumptions are supported in the man page. Moreover, the exact behaviour of 'state' depends on the libc implementation, making the above code fragile. Indeed, invoking "./test_progs -t " on mips64el/musl will hang, with the above code in an infinite loop. Similarly, we see strange behaviour running 'veristat' on mips64el/musl: $ ./veristat -e file,prog,verdict,insns -C two-ok add-failure Can't specify more than 9 stats Rewrite code using a counter to distinguish between strtok_r() calls. Fixes: 61ddff373ffa ("selftests/bpf: Improve by-name subtest selection logic in prog_tests") Fixes: 394169b079b5 ("selftests/bpf: add comparison mode to veristat") Fixes: c8bc5e050976 ("selftests/bpf: Add veristat tool for mass-verifying BPF object files") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/testing_helpers.c | 4 ++-- tools/testing/selftests/bpf/veristat.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index ac7c66f4fc7b..c217e12bd9da 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -221,13 +221,13 @@ int parse_test_list(const char *s, bool is_glob_pattern) { char *input, *state = NULL, *test_spec; - int err = 0; + int err = 0, cnt = 0; input = strdup(s); if (!input) return -ENOMEM; - while ((test_spec = strtok_r(state ? NULL : input, ",", &state))) { + while ((test_spec = strtok_r(cnt++ ? NULL : input, ",", &state))) { err = insert_test(set, test_spec, is_glob_pattern); if (err) break; diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c index 11ec1190d582..1ec5c4c47235 100644 --- a/tools/testing/selftests/bpf/veristat.c +++ b/tools/testing/selftests/bpf/veristat.c @@ -785,13 +785,13 @@ static int parse_stat(const char *stat_name, struct stat_specs *specs) static int parse_stats(const char *stats_str, struct stat_specs *specs) { char *input, *state = NULL, *next; - int err; + int err, cnt = 0; input = strdup(stats_str); if (!input) return -ENOMEM; - while ((next = strtok_r(state ? NULL : input, ",", &state))) { + while ((next = strtok_r(cnt++ ? NULL : input, ",", &state))) { err = parse_stat(next, specs); if (err) { free(input); @@ -1495,7 +1495,7 @@ static int parse_stats_csv(const char *filename, struct stat_specs *specs, while (fgets(line, sizeof(line), f)) { char *input = line, *state = NULL, *next; struct verif_stats *st = NULL; - int col = 0; + int col = 0, cnt = 0; if (!header) { void *tmp; @@ -1513,7 +1513,7 @@ static int parse_stats_csv(const char *filename, struct stat_specs *specs, *stat_cntp += 1; } - while ((next = strtok_r(state ? NULL : input, ",\n", &state))) { + while ((next = strtok_r(cnt++ ? NULL : input, ",\n", &state))) { if (header) { /* for the first line, set up spec stats */ err = parse_stat(next, specs); From patchwork Mon Jul 29 09:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744651 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5EB5139568; Mon, 29 Jul 2024 09:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245095; cv=none; b=jF515a9wXtWHbo/V8WUQiZ9SvfO6NDLcu8xHUZjI1cn4IlRn4WeCUsXMqoqr91nqcadj45SJa8kRyvpa20AeIzY8mNUytXF1vz6aper6HwP2/JdPdKktp0HTAvIgCJ1N1OVmdD6Hy1Nxf4l/LxlQ8UXOpwLCdmNkYbDaADq2Izk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245095; c=relaxed/simple; bh=GgpBzyfhRSLYC+TLXnY4y4ChT4cl4MHuMO36o+bpnTw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f44vp6Qi7pcbUiZ2h9QcfUKMfjxyZMYA3QS3z6f+mxeN3O0G3THlmKoYFBATt8yzFh8vYAFaoRa1eQ5d380iZTxJ90rJsa+jEav/thShHlP9yq8u15opNAHqQOvh2c6M/NGAQ6t5vLhmZTuRxsLfltndsGUQy79pfRZNvuvvE3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kb9NNUyb; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kb9NNUyb" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fd66cddd07so17021445ad.2; Mon, 29 Jul 2024 02:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245092; x=1722849892; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8KCgWkgZpj/xjXSot0+cYlFbdfSHY/0HVZ5q0fJohp8=; b=kb9NNUybzOSZig45zqDc0/4vDCbKcsm5fxPPlYjHYQsqNIMagh+BCF7F9iJoQVZJMU 6bOtd4qXIIayjNmG3l3dxPfdCkoMQa33Iwq/F0AjZuxestJ5r9ntSeIe3u3dpCEhGrsp E0SmnLJPrKJwSGWV5ETf2UireEJrS+YOAsVhvXi3Coz+NaJoWgUtfkPObR+lMvwQxnsJ 3rPPtzjtgzrwi7OnytttfZ+kJtaI/X4P+9Tz8dGV2toX/mdJZjlHaPu/dM9OA6Daxqjy qluw9aGgHAbEBe+RibquBvC1PlDMS0/XiwHi7pY2PwlAtkVbyQEv5RfFtP1RVoQH5GIr a5fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245092; x=1722849892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8KCgWkgZpj/xjXSot0+cYlFbdfSHY/0HVZ5q0fJohp8=; b=G/z7CJrrU02/JD9wFBT865yl/nz85kIjvrWEpKX3Kf7NW5ho543Lxcs2jwW4cI3Uf1 aTG4R8U6pNpBCM4TZKMO31h/BusOUXPJA4wZlSZkt0VwJ1alCuoIHUg0zQuRN+E/c/6r Rtzr1oWD4dmShqvGeVj7QsmEP5cPTpsuGCY4NRcGsZUFmcAypwsDexkaKEMeH+wAjg/N NRuKDeJl7fZqGfNXjDLJWODl/bnzQWhsjRYUJiT+aYs/W9MFPtiVahb33qDCZHH8o4DQ p1dwEw0h4J5FPoeXgO+aUiOfTbpz9JB56gYU0nYFPWhpSf7aqU9+RfgmXLfEkBOs0VCT 17Vw== X-Forwarded-Encrypted: i=1; AJvYcCU5k6VmlTNLDZjpOzm60TCeM2EAemBtzU2heKKXa8PWvP5kwDrFixZUzHdpsaH2pr/1EL/FamcDXeEPpM0tGTrqdNTu3Q05+rKjda1ZO9CvznavU44ramIdWbfDhq+rKQu6NI+v78Ag X-Gm-Message-State: AOJu0YxQdFKYvcnA1gEfPYyxcglB7TXI2Tta8iUAx/3lmKIfHBH8QV1q Y8Tt0nuIw6BAIBgEA1rLKGgsfqrr3kVfQH/nxpWKp5TlBTwWpcqMm1DO34xw X-Google-Smtp-Source: AGHT+IHSomnBFfcQ/Q1STjT0wbSvVrxsNvJahShlp3GqWRbvdrcQ9ZyRRWcqcR5do1ulTXeCQQSipg== X-Received: by 2002:a17:902:c411:b0:1fd:6eec:1b4 with SMTP id d9443c01a7336-1ff0483805cmr41067875ad.19.1722245092514; Mon, 29 Jul 2024 02:24:52 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:24:52 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 3/8] selftests/bpf: Fix error compiling test_lru_map.c Date: Mon, 29 Jul 2024 02:24:19 -0700 Message-Id: <22993dfb11ccf27925a626b32672fd3324cb76c4.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Although the post-increment in macro 'CPU_SET(next++, &cpuset)' seems safe, the sequencing can raise compile errors, so move the increment outside the macro. This avoids an error seen using gcc 12.3.0 for mips64el/musl-libc: In file included from test_lru_map.c:11: test_lru_map.c: In function 'sched_next_online': test_lru_map.c:129:29: error: operation on 'next' may be undefined [-Werror=sequence-point] 129 | CPU_SET(next++, &cpuset); | ^ cc1: all warnings being treated as errors Fixes: 3fbfadce6012 ("bpf: Fix test_lru_sanity5() in test_lru_map.c") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/test_lru_map.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_lru_map.c b/tools/testing/selftests/bpf/test_lru_map.c index 4d0650cfb5cd..fda7589c5023 100644 --- a/tools/testing/selftests/bpf/test_lru_map.c +++ b/tools/testing/selftests/bpf/test_lru_map.c @@ -126,7 +126,8 @@ static int sched_next_online(int pid, int *next_to_try) while (next < nr_cpus) { CPU_ZERO(&cpuset); - CPU_SET(next++, &cpuset); + CPU_SET(next, &cpuset); + next++; if (!sched_setaffinity(pid, sizeof(cpuset), &cpuset)) { ret = 0; break; From patchwork Mon Jul 29 09:24:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744652 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 720E2135A63; Mon, 29 Jul 2024 09:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245105; cv=none; b=YvaDn7j7ErAS/F4Y5MRFMkrs8l+r4aEdoeGpcFabz+Ifydm+lSrfUSBOBye/BGxqBA4YwO4Th9bvW8yxyDKm/cDvz7QPb0f6edBX+jGT6uuWLopUVYPVtN6MxTAC6PcDA8IeAeWSRYAxAamuHaOyljkcRtaWCY+6wzZKIn5AHSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245105; c=relaxed/simple; bh=FQrcOOy+m/blf8ix9UP7S4A0ij3wHldqUVHF9z9y2/I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g2e8hQIoc01+HEpIHLyTeG+ZLsxRQ2NuH9OMY3qo2GZyVxhy9h3pkfRoTrsCl5qtyD1JCLviih9ZEIMM54zehcdvwuqDiqd4k+QIq7l0E9Qn0UK3DbL6DBE6o3Y2f1jvvM1nNqSiXLKtp3vyBnV+2gD2DtIw6R1y0seB05cZ9cU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aB/PTN4r; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aB/PTN4r" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fd6ed7688cso18289055ad.3; Mon, 29 Jul 2024 02:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245104; x=1722849904; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ss5Trmaz8d1KChsteoiB0CfEnS7j0drXtuJsrgRgs5k=; b=aB/PTN4rx+Y0dyni48NWpC4rDOtbvoHIGu0hsKY2X7vtek94Btwy56Pgj6jWAaVcP7 Xm1vx3mjqoSSv0zxt71Rvh6+6aEf+109NroYssPxBPhlxlMWJZySotl1IPvLffH3cNL5 u5Siqtj56NdC360QDc8QDyx1PorKpisjlrQo2EZN+oij3zKF8tRUM9alvN8JXFkwNLSF WUP8zlvQd5GZ7KViNyojVV1DvVT80/GzgGPZx0NWwuT3XVvKqvwQMpbx+bVxMZexVWZy 9JTo2uBPX/wDwtYVYrXFSHZEVEgg1Q0QQmljN0+QnKNtEbq0b1AOWdSCGipvNcBxjJlx /V4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245104; x=1722849904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ss5Trmaz8d1KChsteoiB0CfEnS7j0drXtuJsrgRgs5k=; b=eQ7ES/8G0D09Vl94975d7CGcVtyp+EBK4TngFA+S314Q8Pa6Ybsx7LbjscOPmZO0NJ b1dGcByZL8WjCKF39hFAH23mXa2MaJiC3dBzuLM1v/deUvhES5cSzrCRVcSi1FU5t6lc shMbDzogcAWa5ELyklnVhy7mQZ/M97BZG/A/Nutz3qWHmfaP8lgXESvikKjxJjDYhQyZ /TAf1jCBWc7aG+UzGJdpaTbBZodLoLYRSt7NpVn1k8yuZ1MvJJjW8PywvOg4l03aon7s u2Sp7zf+BiwAi/lTlSpNR0Y8dVWRzVeHjwJ0Fa0P0SwaEG5qKfQAsrcTNSrE+E9f/XS1 JjVA== X-Forwarded-Encrypted: i=1; AJvYcCW03z6BWaANlg5mNH02So4Ow+DwVTVyJSa4dujGsqavVHQBhRsxkzYawPdM9lIRIXPDUgfsPGWNxsByYzgQM8nVWnyOq76/J+7q8pDjxwvO/DX0dS2vpevLLwKPqWqfR6N2I3EjEPI5 X-Gm-Message-State: AOJu0Yw/u3SN4kXhHIoi6QD8fUG4B5WZoTuGpFuFdtb7mQ6N7eGW2nq2 qIMZ1DjQL0cjyi+P02G9bYSls9Zrql+f9woXOmXkpSfw9qWmeXzJY3yp9WBq X-Google-Smtp-Source: AGHT+IGWUH5D5srqRgCA4MK0mZYlxqSGcj/oxvfwHH4bGr19xe12SQdBOw+pnofS/O5kftsXZxojGQ== X-Received: by 2002:a17:903:2304:b0:1fc:6a13:a394 with SMTP id d9443c01a7336-1ff0483e1e7mr54259495ad.23.1722245103531; Mon, 29 Jul 2024 02:25:03 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:25:03 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 4/8] selftests/bpf: Fix C++ compile error from missing _Bool type Date: Mon, 29 Jul 2024 02:24:20 -0700 Message-Id: <6fc1dd28b8bda49e51e4f610bdc9d22f4455632d.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net While building, bpftool makes a skeleton from test_core_extern.c, which itself includes and uses the 'bool' type. However, the skeleton test_core_extern.skel.h generated *does not* include or use the 'bool' type, instead using the C-only '_Bool' type. Compiling test_cpp.cpp with g++ 12.3 for mips64el/musl-libc then fails with error: In file included from test_cpp.cpp:9: test_core_extern.skel.h:45:17: error: '_Bool' does not name a type 45 | _Bool CONFIG_BOOL; | ^~~~~ This was likely missed previously because glibc uses a GNU extension for with C++ (#define _Bool bool), not supported by musl libc. Normally, a C fragment would include and use the 'bool' type, and thus cleanly work after import by C++. The ideal fix would be for 'bpftool gen skeleton' to output the correct type/include supporting C++, but in the meantime add a conditional define as above. Fixes: 7c8dce4b1661 ("bpftool: Make skeleton C code compilable with C++ compiler") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/test_cpp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/bpf/test_cpp.cpp b/tools/testing/selftests/bpf/test_cpp.cpp index dde0bb16e782..abc2a56ab261 100644 --- a/tools/testing/selftests/bpf/test_cpp.cpp +++ b/tools/testing/selftests/bpf/test_cpp.cpp @@ -6,6 +6,10 @@ #include #include #include + +#ifndef _Bool +#define _Bool bool +#endif #include "test_core_extern.skel.h" #include "struct_ops_module.skel.h" From patchwork Mon Jul 29 09:24:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744653 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C36A613E032; Mon, 29 Jul 2024 09:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245116; cv=none; b=YRlJgHIiiObYrKjMBysewC8RiLuvArW+mG78gxad0QfM4WFdHjuf8YBxozj7bJt6FiXk/vIG/wKMqL07NEu/vJmgj4ww4W29KiY6KTlwteIdex6HCOZwcXBpzj1pCged4liJGoc3bI6uwg+NQ1h0reuZ6IZd6KMU2xRQEDcUnd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245116; c=relaxed/simple; bh=U+72Zu68YsWKSCq/gROuLbLA0RkiJaRjm3nFdugE3VM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rZTf9DO2AzhFJJE8TTw65P4JPoFFzn7W2AcpA12vMKZkQCMUKPlALkD/cNpDiU7LWI5vM8P+rAhtgvzh9nVOZARlZGmq4Gd6ZNXojc+7w8vFHmBQP90F1w4d9grBVr3W5UlP4s3XbTityVnbiep0sN8TRViJTWzm+MNomJz3dfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kX2ED9Tx; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kX2ED9Tx" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fd78c165eeso23989835ad.2; Mon, 29 Jul 2024 02:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245114; x=1722849914; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4NI7AuS3CWDWcwh3iYGbh1+P/lJIWDLh+u4INWitysM=; b=kX2ED9TxjNqyRIsp3RHYgnuSSejUSuYp6OVapkWWnoDT6p9+OcJjCOe3Knhp30nRIv GfR4IzxfhwhlCa1WANog0mSyDEJCbvtXDH866g5Dbf2TIRIM4DbQHsux1LlQQYg8WI90 SxfYAEiy4JTn7CFYOxz8vryB6YemRHAleICaeEMHoSoD7WuKWE7McrDwRknQ1BLjsdAn tDe3EZMIsQ4Vo89BJ1xv1c7vxDP3R2isSgk9849REcBT7Mro0qPikpdAzHyb1wrEPnVN kIC2NQX3SGJPO5txhp8dn86EVLKN/qYqHmURqtNRi5JpGze2MozFefCHU7K7V+xNFCaX BZKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245114; x=1722849914; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4NI7AuS3CWDWcwh3iYGbh1+P/lJIWDLh+u4INWitysM=; b=YSMYtsRfnw8U3xMxKh8p8Exf536XfBX2db9g5MeIMI6+o9FsT2rz9m71tArQMDZ9OM l/GJJkexdOnGxMMZFcNYHZ7GEJlSROk9D3Y0bDmVAmoYskx0KFUkgD8R3VgoBOtuBdlS MzReoSAcV00j7Gl5oqGaM5RnFC5Exp6oYl+CqG/bbgahkmvKZ66qzrvb7ft2zgw7aqyi Oz3HMo5vzEM3t7ijvrFyjFGjMxKky4xs503LbJ5/U5hdtEi8oNEABKH2O1kAZ9uy83RG I3D3q42BPBT5emg/173XIRSS8R2CnwAq9/qoeta2OoglS/OooIToxMOpa8Q1ZcjqzMTT IJkA== X-Forwarded-Encrypted: i=1; AJvYcCXCi0dC/dB56Oeo9LGgFunyAkFv3CFsaVdG1DvlCdT9qSUhHDHcFle5ggLnB0Tc1cpMNprGqcF0Au49yWTSyALNVUhU58OP/XvYaKDJTQf3uj+Io/djGcXg4CrKiSJUS6w0VgVyBz8f X-Gm-Message-State: AOJu0YwninBHb7iaR2+ZRdcXxi+L/Y7W4dSr0sxLWUOWGrad+lGe0aq6 pRAHLcOAj9g+HkpabhyREjL3RNpF1pWknpCPBx0Nz+b17lfgUsy4bWHWxiJS X-Google-Smtp-Source: AGHT+IGaaHe7YvfpkEUFCTmGQ1zmd0UBbH2J5zDAyfeOGm/x+Af4UIn2PMOsotW1EqUw0dNPaz/+kg== X-Received: by 2002:a17:902:b090:b0:1fc:5879:1d08 with SMTP id d9443c01a7336-1ff0483bf36mr82870165ad.32.1722245113875; Mon, 29 Jul 2024 02:25:13 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:25:13 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 5/8] selftests/bpf: Fix redefinition errors compiling lwt_reroute.c Date: Mon, 29 Jul 2024 02:24:21 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Compiling lwt_reroute.c with GCC 12.3 for mips64el/musl-libc yields errors: In file included from .../include/arpa/inet.h:9, from ./test_progs.h:18, from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:11, from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52: .../include/netinet/in.h:23:8: error: redefinition of 'struct in6_addr' 23 | struct in6_addr { | ^~~~~~~~ In file included from .../include/linux/icmp.h:24, from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:9: .../include/linux/in6.h:33:8: note: originally defined here 33 | struct in6_addr { | ^~~~~~~~ .../include/netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6' 34 | struct sockaddr_in6 { | ^~~~~~~~~~~~ .../include/linux/in6.h:50:8: note: originally defined here 50 | struct sockaddr_in6 { | ^~~~~~~~~~~~ .../include/netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq' 42 | struct ipv6_mreq { | ^~~~~~~~~ .../include/linux/in6.h:60:8: note: originally defined here 60 | struct ipv6_mreq { | ^~~~~~~~~ These errors occur because is included before , bypassing the Linux uapi/libc compat mechanism's partial musl support. As described in [1] and [2], fix these errors by including in lwt_reroute.c before any uapi headers. [1]: commit c0bace798436 ("uapi libc compat: add fallback for unsupported libcs") [2]: https://git.musl-libc.org/cgit/musl/commit/?id=04983f227238 Fixes: 6c77997bc639 ("selftests/bpf: Add lwt_xmit tests for BPF_REROUTE") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/prog_tests/lwt_reroute.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/prog_tests/lwt_reroute.c b/tools/testing/selftests/bpf/prog_tests/lwt_reroute.c index 03825d2b45a8..6c50c0f63f43 100644 --- a/tools/testing/selftests/bpf/prog_tests/lwt_reroute.c +++ b/tools/testing/selftests/bpf/prog_tests/lwt_reroute.c @@ -49,6 +49,7 @@ * is not crashed, it is considered successful. */ #define NETNS "ns_lwt_reroute" +#include #include "lwt_helpers.h" #include "network_helpers.h" #include From patchwork Mon Jul 29 09:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744654 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A9DC139568; Mon, 29 Jul 2024 09:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245123; cv=none; b=ckyqzDds7TlyJ/zRHc+VQQjOA+5uQCwjKbWRtTSvDbzxbGpG03kVCpCEX+G1KXwifd2k4B6gMbviNb8xcgZrPzF5zsqVmAg6yOWGHkMl4vK0nkD84oB4d8SiUmi4NLxzYyw7nx3jtt9v/QaO1t/tGrX3lO9Cm8C91QMZ4PLGCEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245123; c=relaxed/simple; bh=S4CH8iGlwN8+2X01xU5p4ifa0Xxtjty5cyPwjOQSZb8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pOl6iRaHk7KRq8xZ9f8AEuQrLtuMDXLznpV0UG57t6c0fYaCMs4xD5V+KoV4PQ2XBgHMU1LXwrgYnhfMBCZM4NU2+71Is3LhLCQghArQxo1nGdE9bKT8oHWUmxYY5/aBeessTfaVrYtiBE9vdF4nJRkoSz6fN17Z4+vYLEEjAzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=guJPp+3w; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="guJPp+3w" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fd9e70b592so15841475ad.3; Mon, 29 Jul 2024 02:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245121; x=1722849921; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=97RFtqxKV1tDanXoh3iDjlFW9B65/Wlhvry0/woasgU=; b=guJPp+3wKsvXJbTulYrtbwoo09Xly1kZSwsUYjkH4uOHdsvormO9Rw+2uZar7DXYGL 5ZI+JaBlOoNDY1FZNPUE88DOiT87OnYGND1xi5CGLc0qFHO11mo0mI0LJ+1aLS0guLB6 NPQBXhNfiNbLJukLvx8Z9mlRU6OA/csM8Fab5LdwccVte78e7dRn9bEfyBDUqdZqUuMI qGf4jOqKZLVuqrTNwyCoiY01zYX8yoT2YBo2zeeY8LeJLFzbgwl/h1V2rDsoCizXPUOb ErumQw+mymx56D4pCKr+NceG8hTZW4Aow0Xcz7Aw4NeZ5quktkjBtLhHWY+YthSBE+Ns bTjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245121; x=1722849921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=97RFtqxKV1tDanXoh3iDjlFW9B65/Wlhvry0/woasgU=; b=hCMbIfPAgE7ay5cp83zlaEamGQcsmuSzSTTU7EUrkQWjROzx7LU8Hj6gqm9r/QAqJr M+pUMxRga2xDUxHDj7OhRlgr9WgkQL6VjwoF30uh/UPlpTzMdoGx1V2J+wuiIr+5ZOZH nDKG5oSlQH4af0+buWNzTrDbgaYmaH8TGRdknUvHEpMCipFB5WwtXLkR5ozyQFM00P73 FxGH0FwbwHhcxdx2xfSFE8gUspypYRWzTOvQcZFcs/6LLLvN3iCGdRLeorxTvjo121bb VoKpvxwohPaFfQyhUl7mCwiV8hrQAyEVYBbfgPouMT+vudYei8kZtePWTHTgkfOHCxpk GVYw== X-Forwarded-Encrypted: i=1; AJvYcCUxCaOQEmwe06qWrxwABM82R6NIhlGWUA27fqTovI36PX7uuA9bZJmG6ODII1Qrvdilxiwjd+NKvvHG/ZTlh4UU+EQHmWcmw9Ch9tmKTTQpS3xgE5PzO6oLL38fQhMzXmS+YrLbIu4N X-Gm-Message-State: AOJu0YwLaXD+31Xh2WFNWUWWWflzs5UAtLOkNuKqajX2ycRpckJMBBw3 TjctHric2OVHISWAr6xzHUcB/x/rUcgpxevDKyjfsXutjKNUmn+l/U1kv2Dy X-Google-Smtp-Source: AGHT+IHp+J1QWRbn/WpF8YMiUiaSgf0ZS8cTUL9W412rawZYWAluLxNaQC6rABvsWFOvil0bWZuJ4w== X-Received: by 2002:a17:902:c40e:b0:1fb:8797:befb with SMTP id d9443c01a7336-1ff047dd2edmr50976205ad.35.1722245121227; Mon, 29 Jul 2024 02:25:21 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:25:20 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 6/8] selftests/bpf: Fix compile if backtrace support missing in libc Date: Mon, 29 Jul 2024 02:24:22 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Include GNU header only with glibc and provide weak, stubbed backtrace functions as a fallback in test_progs.c. This allows for non-GNU replacements while avoiding compile errors (e.g. with musl libc) like: test_progs.c:13:10: fatal error: execinfo.h: No such file or directory 13 | #include /* backtrace */ | ^~~~~~~~~~~~ test_progs.c: In function 'crash_handler': test_progs.c:1034:14: error: implicit declaration of function 'backtrace' [-Werror=implicit-function-declaration] 1034 | sz = backtrace(bt, ARRAY_SIZE(bt)); | ^~~~~~~~~ test_progs.c:1045:9: error: implicit declaration of function 'backtrace_symbols_fd' [-Werror=implicit-function-declaration] 1045 | backtrace_symbols_fd(bt, sz, STDERR_FILENO); | ^~~~~~~~~~~~~~~~~~~~ Fixes: 9fb156bb82a3 ("selftests/bpf: Print backtrace on SIGSEGV in test_progs") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/test_progs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index 60c5ec0f6abf..d5d0cb4eb197 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -10,7 +10,6 @@ #include #include #include -#include /* backtrace */ #include /* get_nprocs */ #include #include @@ -19,6 +18,21 @@ #include #include "json_writer.h" +#ifdef __GLIBC__ +#include /* backtrace */ +#endif + +/* Default backtrace funcs if missing at link */ +__weak int backtrace(void **buffer, int size) +{ + return 0; +} + +__weak void backtrace_symbols_fd(void *const *buffer, int size, int fd) +{ + dprintf(fd, "\n"); +} + static bool verbose(void) { return env.verbosity > VERBOSE_NONE; From patchwork Mon Jul 29 09:24:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744655 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA6E13E41D; Mon, 29 Jul 2024 09:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245130; cv=none; b=G2EAjic4OkOOqhI4bJrR2vnMo3gFyJapuG3nT+FmJcBIJAZqiQQAdHlcz2ZH26jfHTqumgj1ceG5KxKdf+YpjrugZk6fS2EL7/JIdDxZqayADYQmc40Rcef1bW5d5JIUmKPNTXPIp+Zr+fs536qItfKQKlkENJGtTBB7CvXJEms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245130; c=relaxed/simple; bh=a4rVH09KS5AcB6gKjH/TsV/iGRHYsyJRdLeEhzYEkRg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t+o1oacNSJ6bL48wWf6ROpgiUr0/utW7F+yBTqhVIOWtXDRn4q0x/x2uIOzmawfxxPJftNJygpoasW1ln19HVmnh8j7chrG3/HoIiHQ0LqiIkGgQedzlhtCiP4DoSZwB6/ZrrQsz914aF+bblOAJO0rRht5hZG6XLAi/GyyxC+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fvFwHYWc; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fvFwHYWc" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fd78c165eeso23991345ad.2; Mon, 29 Jul 2024 02:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245128; x=1722849928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t5OcL9wh7BbULCDEEEFB1/1k389rERhjFZGL7w2BMEU=; b=fvFwHYWc3tY+ilChcl4GUvGCWOnhGelHjUBnmc8tdx6j05xZdvWPBDYKvP9bi6YnNK AsQrqiA3zppNAbi8zRSQfmhZHwpBABodts0yxpDiHcgC0SNXsqxMc/PkfrNsnmfS6GRf Zl0VhFGzONZ2wSZK73qJru7S7iGd1SJagG3IdK6R+clPdtNUuPakigLmXmeukDIFZfXo FohoixA7R3Rkd63ex6E1PtqTVvUEeF5EkEa7DHDetUQmBKxMd9sASZ4iEC3cFvSNflDU uxjHHZ9f1UTkNpiERwNJfnBRpBVQtuIDSAPjHV4Z1m+1GDq5GkFKfRbk/61pw2aY/ULy Pplg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245128; x=1722849928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t5OcL9wh7BbULCDEEEFB1/1k389rERhjFZGL7w2BMEU=; b=G0R1TPzkYJzAUXdTylEScWss5ZHl+kVAyRKMR9hlLGa5or1+bsMJQmAfZRR/rk7Plw ba36DWYKycI/xK3o5G6Hg4f4+CWlkCIDULflU4BMkyGegpY0um7CTIAuurQVcTinBigS ZaYQ2e9Wu7jDWUpMIk6Mr55QqnfxDR7sWmstiLdZxWvkzftcEW5N2Wk95oWCY2OOHeTl E2se0MsOXqSrOMvp0inWrQw8BoiF5uljxcUBI9x0LLGgfdBgjN3hlWtMndLcFAhwSzC6 5DoDcO8KGGG1s1nTYOLXK1jkdEaFL/G4hjAif7U+7RPzCje/xYHXTZn6WyY++1uI9uPQ nEnw== X-Forwarded-Encrypted: i=1; AJvYcCUFs2qgi2d/n9fX1jT6bI2i9jr4qIcr/yl2/BxIcVhCRQF89+fsVrNewjdG/88tVzeqOb1st61xTMMT0LA+WxZfzrVON3a0WAKfb7xPtvGLD8nDI9WHVLemRNE3pTZutPYKdSoYxWqP X-Gm-Message-State: AOJu0Yz2nZuRrG1+iOuQSCLUJK/T7yFHhLh6bhhTnXPIPktDfZiFvn+L SErcCmP0eXlQ+LGIzeVTqI28/bBqZDCIHDbPe0GnmeroJD6u2xdHncoSP4BF X-Google-Smtp-Source: AGHT+IFA/f/KYUIVsqZx7eEo2TXW49TP3+d4xeQX9e3B0VckaNJ3Z1UHQypEhgCVuehYY//K5HAhQA== X-Received: by 2002:a17:902:da92:b0:1fc:5820:8940 with SMTP id d9443c01a7336-1ff0481138fmr89707995ad.20.1722245127985; Mon, 29 Jul 2024 02:25:27 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:25:27 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 7/8] selftests/bpf: Fix using stdout, stderr as struct field names Date: Mon, 29 Jul 2024 02:24:23 -0700 Message-Id: <684ea17548e237f39dfb3f7a3d33450069015b21.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Typically stdin, stdout, stderr are treated as reserved identifiers under ISO/ANSI C and libc implementations further define these as macros, both in glibc and musl . However, while glibc defines: ... /* Standard streams. */ extern FILE *stdin; /* Standard input stream. */ extern FILE *stdout; /* Standard output stream. */ extern FILE *stderr; /* Standard error output stream. */ /* C89/C99 say they're macros. Make them happy. */ #define stdin stdin #define stdout stdout #define stderr stderr ... musl instead uses (legally): ... extern FILE *const stdin; extern FILE *const stdout; extern FILE *const stderr; #define stdin (stdin) #define stdout (stdout) #define stderr (stderr) ... The latter results in compile errors when the names are reused as fields of 'struct test_env' and elsewhere in test_progs.[ch] and reg_bounds.c. Rename the fields to stdout_saved and stderr_saved to avoid many errors seen building against musl, e.g.: In file included from test_progs.h:6, from test_progs.c:5: test_progs.c: In function 'print_test_result': test_progs.c:237:21: error: expected identifier before '(' token 237 | fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); | ^~~~~~ test_progs.c:237:9: error: too few arguments to function 'fprintf' 237 | fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); | ^~~~~~~ Link: https://lore.kernel.org/bpf/ZqR2DuHdBXPX%2Fyx8@kodidev-ubuntu/ Signed-off-by: Tony Ambardar --- .../selftests/bpf/prog_tests/reg_bounds.c | 2 +- tools/testing/selftests/bpf/test_progs.c | 66 +++++++++---------- tools/testing/selftests/bpf/test_progs.h | 8 +-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c index 0da4225749bd..467027236d30 100644 --- a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c +++ b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c @@ -1487,7 +1487,7 @@ static int verify_case_opt(struct ctx *ctx, enum num_t init_t, enum num_t cond_t u64 elapsed_ns = get_time_ns() - ctx->start_ns; double remain_ns = elapsed_ns / progress * (1 - progress); - fprintf(env.stderr, "PROGRESS (%s): %d/%d (%.2lf%%), " + fprintf(env.stderr_saved, "PROGRESS (%s): %d/%d (%.2lf%%), " "elapsed %llu mins (%.2lf hrs), " "ETA %.0lf mins (%.2lf hrs)\n", ctx->progress_ctx, diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index d5d0cb4eb197..60fafa2f1ed7 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -51,15 +51,15 @@ static void stdio_hijack_init(char **log_buf, size_t *log_cnt) stdout = open_memstream(log_buf, log_cnt); if (!stdout) { - stdout = env.stdout; + stdout = env.stdout_saved; perror("open_memstream"); return; } if (env.subtest_state) - env.subtest_state->stdout = stdout; + env.subtest_state->stdout_saved = stdout; else - env.test_state->stdout = stdout; + env.test_state->stdout_saved = stdout; stderr = stdout; #endif @@ -73,8 +73,8 @@ static void stdio_hijack(char **log_buf, size_t *log_cnt) return; } - env.stdout = stdout; - env.stderr = stderr; + env.stdout_saved = stdout; + env.stderr_saved = stderr; stdio_hijack_init(log_buf, log_cnt); #endif @@ -91,13 +91,13 @@ static void stdio_restore_cleanup(void) fflush(stdout); if (env.subtest_state) { - fclose(env.subtest_state->stdout); - env.subtest_state->stdout = NULL; - stdout = env.test_state->stdout; - stderr = env.test_state->stdout; + fclose(env.subtest_state->stdout_saved); + env.subtest_state->stdout_saved = NULL; + stdout = env.test_state->stdout_saved; + stderr = env.test_state->stdout_saved; } else { - fclose(env.test_state->stdout); - env.test_state->stdout = NULL; + fclose(env.test_state->stdout_saved); + env.test_state->stdout_saved = NULL; } #endif } @@ -110,13 +110,13 @@ static void stdio_restore(void) return; } - if (stdout == env.stdout) + if (stdout == env.stdout_saved) return; stdio_restore_cleanup(); - stdout = env.stdout; - stderr = env.stderr; + stdout = env.stdout_saved; + stderr = env.stderr_saved; #endif } @@ -244,25 +244,25 @@ static void print_test_result(const struct prog_test_def *test, const struct tes int skipped_cnt = test_state->skip_cnt; int subtests_cnt = test_state->subtest_num; - fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); + fprintf(env.stdout_saved, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); if (test_state->error_cnt) - fprintf(env.stdout, "FAIL"); + fprintf(env.stdout_saved, "FAIL"); else if (!skipped_cnt) - fprintf(env.stdout, "OK"); + fprintf(env.stdout_saved, "OK"); else if (skipped_cnt == subtests_cnt || !subtests_cnt) - fprintf(env.stdout, "SKIP"); + fprintf(env.stdout_saved, "SKIP"); else - fprintf(env.stdout, "OK (SKIP: %d/%d)", skipped_cnt, subtests_cnt); + fprintf(env.stdout_saved, "OK (SKIP: %d/%d)", skipped_cnt, subtests_cnt); - fprintf(env.stdout, "\n"); + fprintf(env.stdout_saved, "\n"); } static void print_test_log(char *log_buf, size_t log_cnt) { log_buf[log_cnt] = '\0'; - fprintf(env.stdout, "%s", log_buf); + fprintf(env.stdout_saved, "%s", log_buf); if (log_buf[log_cnt - 1] != '\n') - fprintf(env.stdout, "\n"); + fprintf(env.stdout_saved, "\n"); } static void print_subtest_name(int test_num, int subtest_num, @@ -273,14 +273,14 @@ static void print_subtest_name(int test_num, int subtest_num, snprintf(test_num_str, sizeof(test_num_str), "%d/%d", test_num, subtest_num); - fprintf(env.stdout, "#%-*s %s/%s", + fprintf(env.stdout_saved, "#%-*s %s/%s", TEST_NUM_WIDTH, test_num_str, test_name, subtest_name); if (result) - fprintf(env.stdout, ":%s", result); + fprintf(env.stdout_saved, ":%s", result); - fprintf(env.stdout, "\n"); + fprintf(env.stdout_saved, "\n"); } static void jsonw_write_log_message(json_writer_t *w, char *log_buf, size_t log_cnt) @@ -465,7 +465,7 @@ bool test__start_subtest(const char *subtest_name) memset(subtest_state, 0, sub_state_size); if (!subtest_name || !subtest_name[0]) { - fprintf(env.stderr, + fprintf(env.stderr_saved, "Subtest #%d didn't provide sub-test name!\n", state->subtest_num); return false; @@ -473,7 +473,7 @@ bool test__start_subtest(const char *subtest_name) subtest_state->name = strdup(subtest_name); if (!subtest_state->name) { - fprintf(env.stderr, + fprintf(env.stderr_saved, "Subtest #%d: failed to copy subtest name!\n", state->subtest_num); return false; @@ -1043,7 +1043,7 @@ void crash_handler(int signum) sz = backtrace(bt, ARRAY_SIZE(bt)); - if (env.stdout) + if (env.stdout_saved) stdio_restore(); if (env.test) { env.test_state->error_cnt++; @@ -1359,7 +1359,7 @@ static void calculate_summary_and_print_errors(struct test_env *env) if (env->json) { w = jsonw_new(env->json); if (!w) - fprintf(env->stderr, "Failed to create new JSON stream."); + fprintf(env->stderr_saved, "Failed to create new JSON stream."); } if (w) { @@ -1708,8 +1708,8 @@ int main(int argc, char **argv) return -1; } - env.stdout = stdout; - env.stderr = stderr; + env.stdout_saved = stdout; + env.stderr_saved = stderr; env.has_testmod = true; if (!env.list_test_names) { @@ -1717,7 +1717,7 @@ int main(int argc, char **argv) unload_bpf_testmod(verbose()); if (load_bpf_testmod(verbose())) { - fprintf(env.stderr, "WARNING! Selftests relying on bpf_testmod.ko will be skipped.\n"); + fprintf(env.stderr_saved, "WARNING! Selftests relying on bpf_testmod.ko will be skipped.\n"); env.has_testmod = false; } } @@ -1795,7 +1795,7 @@ int main(int argc, char **argv) } if (env.list_test_names) { - fprintf(env.stdout, "%s\n", test->test_name); + fprintf(env.stdout_saved, "%s\n", test->test_name); env.succ_cnt++; continue; } diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h index b1e949fb16cf..cb9d6d46826b 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -75,7 +75,7 @@ struct subtest_state { bool skipped; bool filtered; - FILE *stdout; + FILE *stdout_saved; }; struct test_state { @@ -92,7 +92,7 @@ struct test_state { size_t log_cnt; char *log_buf; - FILE *stdout; + FILE *stdout_saved; }; struct test_env { @@ -111,8 +111,8 @@ struct test_env { struct test_state *test_state; /* current running test state */ struct subtest_state *subtest_state; /* current running subtest state */ - FILE *stdout; - FILE *stderr; + FILE *stdout_saved; + FILE *stderr_saved; int nr_cpus; FILE *json; From patchwork Mon Jul 29 09:24:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 13744656 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86F80135A63; Mon, 29 Jul 2024 09:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245138; cv=none; b=sMiXHYBm8kp2sPYy5r80TLg7mA2vLbBkioC3/FHHlUKQJn666UzFY4AmISyJ0LRM65AKwJx7ubYehI5bDwtloL28goHhQsNNkFUj6XkB9t760vqPmYFXW/gOFfrxSx4GM1H7CcTw4pCAOrSFjcyGOx5edB80tqMurI/j2sflONc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245138; c=relaxed/simple; bh=GDXN/Px7sT3XLuGz2x/yVck36QUenL3LLygwRSBF8o0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k00MOyQs0RIJfqAp1RticHrrMqAy4FxI92R4qgmBCwxN/KOmqA+uRZUWN1tyfLC3jaoeE8jE6MZ35AhsfjMypYwMv60nZAIRKDBhCMJA4TmjS+Sl871iB5wp/6R2Rx09trNTPcEnC+GdzBUfR1ntA9lDvG7rouxvKbuahE4cBKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YsjlZCaT; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YsjlZCaT" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1fc6a017abdso15506935ad.0; Mon, 29 Jul 2024 02:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722245135; x=1722849935; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SRvsG0Mnzi7FmdMnkPufWtMOmBcHwMKR25Zel1SkEgw=; b=YsjlZCaT2+seqFQma2UwWbQgi0MnAbH57/kvCc7spwlrDAEOdXkCkTb0jBMJUmc8tQ SYJXZtKb6L8IHvIvkoOpGXEeVdMZTUgWS1aOE5T/Ej3hYaLf7sHycy/8a1gADmHMzs8c qYjA/ngMKwBz+sA9DuQzBG/1eUGaPeYVO1SVMtssn6GrxYIwMcMNfmKHB2dgPsViKIPg F5kkZA+hkZ39Tmpzs8TIQf9nTFhYP/DB93iCRM5SI4lDyQSftZ33snk/dnHpx1kdk1qf z2V04yMG5hKIbnAW76YDGBicxmqcwgRSBBaEgRSynyswmsa4+C8xfIaUJGySPPehWmQX zTEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722245135; x=1722849935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SRvsG0Mnzi7FmdMnkPufWtMOmBcHwMKR25Zel1SkEgw=; b=Ict8QzuIFzh0IuTH6gKz7Yo7ewo+TZtg4ChY+0LGqj9fLUcRSqoCofZ9f8AjJIXYVd 4JcBXJn66tWSvsFASqAqIxkqe0hYsLewQw46BEiwV6XSya/OT4TOX2/Yk9ITumvrROuz ziX+l0tJgO8jJgF61wRrZ4eOE1Vlnx5fOggXpkQEFtmRqc9nft9T2BiQpeeeRyh7fUSc LBCXXubhsOSnvT2rduJb30FD7TH2ki/XL+FFuKFHdfaLl7ogZ+UG8y6jYZEIzurU39/b m6ldJC5U6hvl8taKNznZfAB3uGT8nYTDwUFMWd+10AGmPGqU50I8NQdiTFytTrjOycPa XOqg== X-Forwarded-Encrypted: i=1; AJvYcCWwXDmh9bv6e1g5lQxjN7T2du7/xe3axvhUAODJNKLzosaVzIYSPBHCpxSWWv0g9lPNijWUw4nmYsICSQh2yngL2ck2GkMPmjyhGz24HBVoqpn/Vol6N5mIe+agL91QZEqfNKWLHUwF X-Gm-Message-State: AOJu0YyEKoQwt/gRnNlUzl7+94+LdWqO6jKBOwdQC4VPImdEapnckzWk 55ppfdGm9z8jYWGkdoGudvMK/UMLZ7OmUC3OcabQG6VXsA1vIzhOnSBWj0DC X-Google-Smtp-Source: AGHT+IFLwa5khv/aHDVxMtQSVoU6DgS9rtncTw3VVOOCsh+a96EXefz+yMLUf4y1iipVpW9c7AvByg== X-Received: by 2002:a17:903:1c1:b0:1fd:aac9:a72e with SMTP id d9443c01a7336-1ff0489f469mr65241195ad.43.1722245135501; Mon, 29 Jul 2024 02:25:35 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8c19dsm78119145ad.54.2024.07.29.02.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 02:25:35 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Yan Zhai Subject: [PATCH bpf-next v2 8/8] selftests/bpf: Fix error compiling tc_redirect.c with musl libc Date: Mon, 29 Jul 2024 02:24:24 -0700 Message-Id: <031d656c058b4e55ceae56ef49c4e1729b5090f3.1722244708.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Linux 5.1 implemented 64-bit time types and related syscalls to address the Y2038 problem generally across archs. Userspace handling of Y2038 varies with the libc however. While musl libc uses 64-bit time across all 32-bit and 64-bit platforms, GNU glibc uses 64-bit time on 64-bit platforms but defaults to 32-bit time on 32-bit platforms unless they "opt-in" to 64-bit time or explicitly use 64-bit syscalls and time structures. One specific area is the standard setsockopt() call, SO_TIMESTAMPNS option used for timestamping, and the related output 'struct timespec'. GNU glibc defaults as above, also exposing the SO_TIMESTAMPNS_NEW flag to explicitly use a 64-bit call and 'struct __kernel_timespec'. Since these are not exposed or needed with musl libc, their use in tc_redirect.c leads to compile errors building for mips64el/musl: tc_redirect.c: In function 'rcv_tstamp': tc_redirect.c:425:32: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'? 425 | cmsg->cmsg_type == SO_TIMESTAMPNS_NEW) | ^~~~~~~~~~~~~~~~~~ | SO_TIMESTAMPNS tc_redirect.c:425:32: note: each undeclared identifier is reported only once for each function it appears in tc_redirect.c: In function 'test_inet_dtime': tc_redirect.c:491:49: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'? 491 | err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW, | ^~~~~~~~~~~~~~~~~~ | SO_TIMESTAMPNS However, using SO_TIMESTAMPNS_NEW isn't strictly needed, nor is Y2038 being explicitly tested. The timestamp checks in tc_redirect.c are simple: the packet receive timestamp is non-zero and processed/handled in less than 5 seconds. Switch to using the standard setsockopt() call and SO_TIMESTAMPNS option to ensure compatibility across glibc and musl libc. In the worst-case, there is a 5-second window 14 years from now where tc_redirect tests may fail on 32-bit systems. However, we should reasonably expect glibc to adopt a 64-bit mandate rather than the current "opt-in" policy before the Y2038 roll-over. Fixes: ce6f6cffaeaa ("selftests/bpf: Wait for the netstamp_needed_key static key to be turned on") Fixes: c803475fd8dd ("bpf: selftests: test skb->tstamp in redirect_neigh") Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c index 327d51f59142..53b8ffc943dc 100644 --- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c @@ -471,7 +471,7 @@ static int set_forwarding(bool enable) static int __rcv_tstamp(int fd, const char *expected, size_t s, __u64 *tstamp) { - struct __kernel_timespec pkt_ts = {}; + struct timespec pkt_ts = {}; char ctl[CMSG_SPACE(sizeof(pkt_ts))]; struct timespec now_ts; struct msghdr msg = {}; @@ -495,7 +495,7 @@ static int __rcv_tstamp(int fd, const char *expected, size_t s, __u64 *tstamp) cmsg = CMSG_FIRSTHDR(&msg); if (cmsg && cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SO_TIMESTAMPNS_NEW) + cmsg->cmsg_type == SO_TIMESTAMPNS) memcpy(&pkt_ts, CMSG_DATA(cmsg), sizeof(pkt_ts)); pkt_ns = pkt_ts.tv_sec * NSEC_PER_SEC + pkt_ts.tv_nsec; @@ -537,9 +537,9 @@ static int wait_netstamp_needed_key(void) if (!ASSERT_GE(srv_fd, 0, "start_server")) goto done; - err = setsockopt(srv_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW, + err = setsockopt(srv_fd, SOL_SOCKET, SO_TIMESTAMPNS, &opt, sizeof(opt)); - if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS_NEW)")) + if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS)")) goto done; cli_fd = connect_to_fd(srv_fd, TIMEOUT_MILLIS); @@ -621,9 +621,9 @@ static void test_inet_dtime(int family, int type, const char *addr, __u16 port) return; /* Ensure the kernel puts the (rcv) timestamp for all skb */ - err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW, + err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS, &opt, sizeof(opt)); - if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS_NEW)")) + if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS)")) goto done; if (type == SOCK_STREAM) {