Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp133333rdb; Thu, 1 Feb 2024 04:30:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtSNSv2KG/drx5JIJiM+tXLG2NkTn4tLTspBcIdhje8KjhsvlZ32Ytw2Ig8Igl+9xECSjW X-Received: by 2002:a05:6358:3a0a:b0:176:7f77:a2b2 with SMTP id g10-20020a0563583a0a00b001767f77a2b2mr2278633rwe.5.1706790637841; Thu, 01 Feb 2024 04:30:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706790637; cv=pass; d=google.com; s=arc-20160816; b=0OpMUNaaqPKKZTj1wA7lqAAMJbw1GN7ke5Er6xRkN5LsBJssHJfQcOi9mNj25CNb2F LFpRCEzWLy2Txg2rlFShrB7IvbiVbsaPBYL694Ofh8JWHvJXK3TSJ7nVRBOdW5jTg6Wx 339/6Ss+Z8KKrzXZsuTS1pCONFxTDOYifafWagkqcLDV3ouy1QjreFqTB1qxPVT+rgBE WMV6XAllxnCHtuyMGT/ZH8tAqmJm3g79jg9pq7ady8EsrfB01yRxKBkJQUdBJSS/B+DZ /2myqeAHRCnVdkovImmHFtEb0kCxnj9mvYMBoMkvi6XN3SKoIzeMVeI8nmai1NGeQUBQ O4jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vez3iEbUjml7sKIB+YP3HQxWKvPju6FEy/gDopCf2TQ=; fh=8i0n2x9GTOIRIPe7WFaat44IE0CdKyLJ7k83oMWwgyY=; b=v2QGT0jNkVW8ZG+VDJ+A609StoaG2wXT0NPXBIeGxVBPcIDu56A2gA8Eoc8SkpYgZY lcb3mCEc1I1Rp0p2h1/xj4iCWdgddv9k8GaUAfb6FzBuzL8w5i0C965vQVgb7vyv1Jfm SowZ3sDXsz3lLGEmIxcgdv70SzWN93HZ30OgqiYz+sucwSn0yb/lX1yFIK655TPEKcKU pX4yX7gh5klkjRAw9s+AHbRoUyZhAcYkaquihjoqr0t9DnukzqL1CZvLfZMm8FbsgAmD Bqj10pbon0SvF7VGcKwF8l3UynnWYQaqrFCRJPVNGbho37+8dpgLKKW61/AaCVa3TlT/ 6q4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P7xPW30T; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUC9mSGxHKFIxhk3Wr/EIHZ7IB2sp2mZmMbE5DarOHp6Gu4ZOIDXDq42MQu1xelwT1/woRYAxhO7HxlAbJCzXGyo52Q5Zjt3qAaY1+ZmQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fd1-20020a056a002e8100b006dfc312f897si4525843pfb.50.2024.02.01.04.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:30:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P7xPW30T; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A4599297E0F for ; Thu, 1 Feb 2024 12:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F213626A3; Thu, 1 Feb 2024 12:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P7xPW30T" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 806FE6216D; Thu, 1 Feb 2024 12:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790305; cv=none; b=cTLRfvGM892Y+caZb1OT/GpGYiE3EHggCn3iBPfowIlQRRWBTBbxEyUag8rDb7K2pQqL0q+oIkDHJJ+y3bKs+HyY4zXFH9lybIG9f+QTl/zK322jBhmrvKS3RRik0AtlTKGL5CkkVPm4rjWzFSU3ytE2btB0AnnHlsMIr7VWlAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790305; c=relaxed/simple; bh=tciizGYemdvBRZOCIgw7Jb9cIFJ+BUDzQuABjrAFCx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PmQaivrVHnXoiGxRUModOPFVqkDVmhcNOJuBY7xueHJbvAGQPxvQsayafF/FMwIbfPKgq7+odtY9F5+wg7ot7hGEcd33XeSjcvR/4XvUaitNXunRJwTtxY/ZsOfHY/NJYwv4bjU1+DlIfEqWxsIkjwtSvp6eiQ8GjMRfG/Ltxjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=P7xPW30T; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706790302; x=1738326302; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tciizGYemdvBRZOCIgw7Jb9cIFJ+BUDzQuABjrAFCx8=; b=P7xPW30T7pn46dndW/IS2HTjbxD4S2/IRxeLvCidyKxdMj2wm/8McZE5 6nk31UoVknHvqJWiFBaoShMTpeBi9Sn0h0Gi697onWE0EezkFhzvzujYz as1lw/OmYFYayYmn5HcptJI5sNrRATkzq36ZtKTrUq9MSij6QAMGK9j9L ClJfhoBvjHynAvVBpiLS8g2w/rv+CFOirvnC/lagJb6ZzVJRRcwHOIElW yeaGHcR7kefRDH9YPxEs2pUCFHQy3xmDJ2E7YX/JQQoOqom0bOId7jmMh cDlucZxfdTjxVvZQwsjcNP0OjXwyg6BPjyPXw2QiMQfy6r9ZhJp3W4JHh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3747184" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="3747184" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 04:25:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="4499170" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa004.jf.intel.com with ESMTP; 01 Feb 2024 04:24:56 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Michal Swiatkowski , Marcin Szycik , Wojciech Drewek , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jiri Pirko , Ido Schimmel , Przemek Kitszel , Simon Horman , linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 17/21] lib/bitmap: add tests for IP tunnel flags conversion helpers Date: Thu, 1 Feb 2024 13:22:12 +0100 Message-ID: <20240201122216.2634007-18-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201122216.2634007-1-aleksander.lobakin@intel.com> References: <20240201122216.2634007-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Now that there are helpers for converting IP tunnel flags between the old __be16 format and the bitmap format, make sure they work as expected by adding a couple of tests to the bitmap testing suite. The helpers are all inline, so no dependencies on the related CONFIG_* (or a standalone module) are needed. Cover three possible cases: 1. No bits past BIT(15) are set, VTI/SIT bits are not set. This conversion is almost a direct assignment. 2. No bits past BIT(15) are set, but VTI/SIT bit is set. During the conversion, it must be transformed into BIT(16) in the bitmap, but still compatible with the __be16 format. 3. The bitmap has bits past BIT(15) set (not the VTI/SIT one). The result will be truncated. Note that currently __IP_TUNNEL_FLAG_NUM is 17 (incl. special), which means that the result of this case is currently semi-false-positive. When BIT(17) is finally here, it will be adjusted accordingly. Signed-off-by: Alexander Lobakin --- lib/test_bitmap.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 4ee1f8ceb51d..270afc0cba5c 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -14,6 +14,8 @@ #include #include +#include + #include "../tools/testing/selftests/kselftest_module.h" #define EXP1_IN_BITS (sizeof(exp1) * 8) @@ -1409,6 +1411,108 @@ static void __init test_bitmap_write_perf(void) #undef TEST_BIT_LEN +struct ip_tunnel_flags_test { + const u16 *src_bits; + const u16 *exp_bits; + u8 src_num; + u8 exp_num; + __be16 exp_val; + bool exp_comp:1; +}; + +#define IP_TUNNEL_FLAGS_TEST(src, comp, eval, exp) { \ + .src_bits = (src), \ + .src_num = ARRAY_SIZE(src), \ + .exp_comp = (comp), \ + .exp_val = (eval), \ + .exp_bits = (exp), \ + .exp_num = ARRAY_SIZE(exp), \ +} + +/* These are __be16-compatible and can be compared as is */ +static const u16 ip_tunnel_flags_1[] __initconst = { + IP_TUNNEL_KEY_BIT, + IP_TUNNEL_STRICT_BIT, + IP_TUNNEL_ERSPAN_OPT_BIT, +}; + +/* + * Due to the previous flags design limitation, setting either + * ``IP_TUNNEL_CSUM_BIT`` (on Big Endian) or ``IP_TUNNEL_DONT_FRAGMENT_BIT`` + * (on Little) also sets VTI/ISATAP bit. In the bitmap implementation, they + * correspond to ``BIT(16)``, which is bigger than ``U16_MAX``, but still is + * backward-compatible. + */ +#ifdef __BIG_ENDIAN +#define IP_TUNNEL_CONFLICT_BIT IP_TUNNEL_CSUM_BIT +#else +#define IP_TUNNEL_CONFLICT_BIT IP_TUNNEL_DONT_FRAGMENT_BIT +#endif + +static const u16 ip_tunnel_flags_2_src[] __initconst = { + IP_TUNNEL_CONFLICT_BIT, +}; + +static const u16 ip_tunnel_flags_2_exp[] __initconst = { + IP_TUNNEL_CONFLICT_BIT, + IP_TUNNEL_SIT_ISATAP_BIT, +}; + +/* Bits 17 and higher are not compatible with __be16 flags */ +static const u16 ip_tunnel_flags_3_src[] __initconst = { + IP_TUNNEL_VXLAN_OPT_BIT, + 17, + 18, + 20, +}; + +static const u16 ip_tunnel_flags_3_exp[] __initconst = { + IP_TUNNEL_VXLAN_OPT_BIT, +}; + +static const struct ip_tunnel_flags_test ip_tunnel_flags_test[] __initconst = { + IP_TUNNEL_FLAGS_TEST(ip_tunnel_flags_1, true, + cpu_to_be16(BIT(IP_TUNNEL_KEY_BIT) | + BIT(IP_TUNNEL_STRICT_BIT) | + BIT(IP_TUNNEL_ERSPAN_OPT_BIT)), + ip_tunnel_flags_1), + IP_TUNNEL_FLAGS_TEST(ip_tunnel_flags_2_src, true, VTI_ISVTI, + ip_tunnel_flags_2_exp), + IP_TUNNEL_FLAGS_TEST(ip_tunnel_flags_3_src, + /* + * This must be set to ``false`` once + * ``__IP_TUNNEL_FLAG_NUM`` goes above 17. + */ + true, + cpu_to_be16(BIT(IP_TUNNEL_VXLAN_OPT_BIT)), + ip_tunnel_flags_3_exp), +}; + +static void __init test_ip_tunnel_flags(void) +{ + for (u32 i = 0; i < ARRAY_SIZE(ip_tunnel_flags_test); i++) { + typeof(*ip_tunnel_flags_test) *test = &ip_tunnel_flags_test[i]; + IP_TUNNEL_DECLARE_FLAGS(src) = { }; + IP_TUNNEL_DECLARE_FLAGS(exp) = { }; + IP_TUNNEL_DECLARE_FLAGS(out); + + for (u32 j = 0; j < test->src_num; j++) + __set_bit(test->src_bits[j], src); + + for (u32 j = 0; j < test->exp_num; j++) + __set_bit(test->exp_bits[j], exp); + + ip_tunnel_flags_from_be16(out, test->exp_val); + + expect_eq_uint(test->exp_comp, + ip_tunnel_flags_is_be16_compat(src)); + expect_eq_uint((__force u16)test->exp_val, + (__force u16)ip_tunnel_flags_to_be16(src)); + + __ipt_flag_op(expect_eq_bitmap, exp, out); + } +} + static void __init selftest(void) { test_zero_clear(); @@ -1428,6 +1532,7 @@ static void __init selftest(void) test_bitmap_read_write(); test_bitmap_read_perf(); test_bitmap_write_perf(); + test_ip_tunnel_flags(); test_find_nth_bit(); test_for_each_set_bit(); -- 2.43.0