Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2632808rdg; Mon, 16 Oct 2023 09:58:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXWtZ041cYT5fw1C0zDEd+qhfZua9dDKaBXp9B3AaZiGYBGw1ecK3StjpkAVs6ScXfJe8p X-Received: by 2002:a05:6870:d107:b0:1e9:b3f6:12de with SMTP id e7-20020a056870d10700b001e9b3f612demr13451832oac.31.1697475510194; Mon, 16 Oct 2023 09:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475510; cv=none; d=google.com; s=arc-20160816; b=wzoPyR3uyhDtadH8EiuscU0mj9Axj0Vj3HjB/rn7MTyqKUROoSd49+UeFOkB7p5EOa 0czUd8dQh/Qs8uy/panDNAOzyvL2iCrTpxvGWZQ3KV/y6ZXuVwFHvTWVOfurbJ62CA4T OTfaKb+yxQ1yPFlKq/Y4ZSpxW6zbVIaKtXBP9bOxSjA0XqU/8Vo0YnrtVHZddDZafiL4 5wWiVU87c4N4chq8HjpaqbyMYPQMYZ4EFlXq4uDu/FRgAYHvfoQRB378exC6S4LMKdOz z9PRM+ol2tdKW6CNhVA/Gya7UpTJ3Tuni5Zeh71EV1WGjzAZwsbFfE1w7Y61r6vwIIZS STHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wljrgkzshiDWdcVqDZ4fRXusgukNdzfUXirX9tkFq+E=; fh=2kCdHXvcAULJv/9f8X/O+IrT3ddiMaJJNnCkHNJ/OJY=; b=penfYXkAivXClXkZeOmjScnnNFnsVLokhkf1UFMaMrNygshQkQ8C98fkktAJ3xREML lMDp8zVUxc/naDkiBx71rKsSa1gAHxMnvWVFZn/Mf2TqXuJGTNfHQyVONe50Qm0nWHfl o1AHQIRblxZ9n6rVJF04kaCEPL1Cf9Qr9PlPW3KD08/Yp83rkDs8ascsBmxaWnPP6/us Mnv+EERpDAbLemLACSI9BLpksyUEd8qGnwlzee2S7rXoJ/KqzXgoT7qAccYow9XAA5NZ TIPxTtklof6kd4tyaCwo6fGtPv9VUuFcyhw8iY3zWnm/GoRv4DjvqgzfSn9GzPaPy8CG WvEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dP5tinsn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e12-20020a63db0c000000b00565f01b9403si11496893pgg.883.2023.10.16.09.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:58:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dP5tinsn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 19997802A7D1; Mon, 16 Oct 2023 09:58:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234592AbjJPQ6T (ORCPT + 99 others); Mon, 16 Oct 2023 12:58:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234598AbjJPQ5n (ORCPT ); Mon, 16 Oct 2023 12:57:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AB161706; Mon, 16 Oct 2023 09:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697475314; x=1729011314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iMvW9Pd7slcD9HuUM6knbeG8rQ/qVzk1d8EzAuKBzzI=; b=dP5tinsnt3hf06gP2zn+spHDS1ZFM/2gYGBz5srZBYCssxbRp7At8nR/ uUC+MtQBoUwCR55rgdLCWQbzfjbgJ2bhn/UobUPjH4EK5EPbj7oA3wSha 01J2IB/4ifJUXMx7N7zVYatymZcMr29Pz84MN096DtGsSu9V8WGTTJY/J wOzsBSELy0R5jzzUn3lna7nmYqpLu4vJB7qIFzdQhDf4ciWrZ9CSMj+u2 R7tQdd1I7Khqh/8Qc/YwIfAmy/cYZGyiQkPWvM5AgMYMghjK8w335ubwc OLKTxFSrBj7l59b+FR0QgJwJHhXZpdZC8mYTWDOlbs3+4k9Cr8qWHFNnd w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364937356" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364937356" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:55:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="826084575" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="826084575" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmsmga004.fm.intel.com with ESMTP; 16 Oct 2023 09:55:09 -0700 From: Alexander Lobakin To: Yury Norov Cc: Alexander Lobakin , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jakub Kicinski , Eric Dumazet , David Ahern , Przemek Kitszel , Simon Horman , netdev@vger.kernel.org, linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 13/13] lib/bitmap: add tests for IP tunnel flags conversion helpers Date: Mon, 16 Oct 2023 18:52:47 +0200 Message-ID: <20231016165247.14212-14-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231016165247.14212-1-aleksander.lobakin@intel.com> References: <20231016165247.14212-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:58:29 -0700 (PDT) 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 a005fcd70ed7..2981277ed8d4 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) @@ -1387,6 +1389,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(); @@ -1405,6 +1509,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.41.0