From patchwork Mon Oct 9 15:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13414867 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 749B8CD68FA for ; Tue, 10 Oct 2023 07:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696921394; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Pk2du9Xtb7Hisn0YWjCk5ceJo4NSME2O8LcwZbR9K2U=; b=PfhagJjyze4JHA9kriF7F6tPZ38aRe4Zj/Xtp3QxM+lOP0Rtbg1A4F8I5lTgfxvHOvwsCD LjleHAm8HeuapLZnlUMiQyWfweZ4QfvNzutfOImTHse5/swE6S1Gixha37cIdW1UIYHKxL F7vVqQhQDWITo1xNKSukCos0EkltGXc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-vTS_2Xk8NU-FA1ovn5XnKw-1; Tue, 10 Oct 2023 03:03:09 -0400 X-MC-Unique: vTS_2Xk8NU-FA1ovn5XnKw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8804781163A; Tue, 10 Oct 2023 07:03:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77F3F1B9C; Tue, 10 Oct 2023 07:03:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AB20619459F1; Tue, 10 Oct 2023 07:02:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BBBCE19465A0 for ; Mon, 9 Oct 2023 15:15:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9CD20C154CF; Mon, 9 Oct 2023 15:15:19 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95183C154CE for ; Mon, 9 Oct 2023 15:15:19 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 743BB3806736 for ; Mon, 9 Oct 2023 15:15:19 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-80-YbBfXN50Puy6iUm9Volo6Q-2; Mon, 09 Oct 2023 11:15:12 -0400 X-MC-Unique: YbBfXN50Puy6iUm9Volo6Q-2 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="369232558" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="369232558" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 08:13:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="869288214" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="869288214" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmsmga002.fm.intel.com with ESMTP; 09 Oct 2023 08:13:52 -0700 From: Alexander Lobakin To: Yury Norov Date: Mon, 9 Oct 2023 17:10:26 +0200 Message-ID: <20231009151026.66145-15-aleksander.lobakin@intel.com> In-Reply-To: <20231009151026.66145-1-aleksander.lobakin@intel.com> References: <20231009151026.66145-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mailman-Approved-At: Tue, 10 Oct 2023 07:02:51 +0000 Subject: [dm-devel] [PATCH 14/14] lib/bitmap: add tests for IP tunnel flags conversion helpers X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, ntfs3@lists.linux.dev, Przemek Kitszel , David Ahern , Rasmus Villemoes , dm-devel@redhat.com, linux-kernel@vger.kernel.org, Alexander Lobakin , Eric Dumazet , netdev@vger.kernel.org, Alexander Potapenko , Simon Horman , Jakub Kicinski , Andy Shevchenko , linux-btrfs@vger.kernel.org Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: intel.com 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 6037b66fd30a..23da19e1ff7e 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) @@ -1300,6 +1302,108 @@ static void __init test_bitmap_const_eval(void) BUILD_BUG_ON(!res); } +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(); @@ -1316,6 +1420,7 @@ static void __init selftest(void) test_bitmap_print_buf(); test_bitmap_getset_bits(); test_bitmap_const_eval(); + test_ip_tunnel_flags(); test_find_nth_bit(); test_for_each_set_bit();