From patchwork Wed Jan 12 09:42:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Nr3XZ+wi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjL80sHDz9s0r for ; Wed, 12 Jan 2022 20:43:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B81D9428E1; Wed, 12 Jan 2022 09:43:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sxDri8lKofJ0; Wed, 12 Jan 2022 09:43:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 936FB428E6; Wed, 12 Jan 2022 09:43:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 02321C0077; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 34AA6C0075 for ; Wed, 12 Jan 2022 09:43:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B5EB183F7A for ; Wed, 12 Jan 2022 09:43:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PSnFpWhDkc1H for ; Wed, 12 Jan 2022 09:43:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 02B9B83F2E for ; Wed, 12 Jan 2022 09:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980597; x=1673516597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ZMhXyoTgawI0zXjxat+6SGh3rxPu9GJE51Ke5ZvJww=; b=Nr3XZ+wiz8wZ8g0aGL869tRd0ga39CD7Rwdy4puKZpDpI0rFoXOQLnfa pEJdXPPBFGYgdpGh5hnsD2r9haEhXpmptb4F1FZQwWjbwDFYATZGv/KDx cuNpNeLJo9PaWWO1GTZVnMtNrTe4MLo1p6tizicRJjGa6jXg8WQQbpnQ+ fkIHCgqmOBtzmvIYSkep8VnkP8goJT8W7lHCrhOLeyOHQB48EhRFj8mzB z9lKyfbfWigLJZ9abs5F8G65H8y+I5b3LPrxUUF82J32OPvka5WnHAXmd Bfm45c9V/h/DSgybhC7bXLrbN3GGBECoEN9O8YRTjOUhbrpa/WuOOSe3N w==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394758" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394758" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688294" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:15 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:39 +0000 Message-Id: <20220112094244.81402-4-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 3/8] odp-execute: Add auto validation function for actions. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit introduced the auto-validation function which allows users to compare the batch of packets obtained from different action implementations against the linear action implementation. The autovalidator function can be triggered at runtime using the following command: $ ovs-appctl dpif-netdev/action-impl-set autovalidator Signed-off-by: Emma Finn Acked-by: Harry van Haaren --- NEWS | 2 + lib/dp-packet.c | 23 +++++++++ lib/dp-packet.h | 5 ++ lib/odp-execute-private.c | 99 +++++++++++++++++++++++++++++++++++++++ lib/odp-execute-private.h | 3 ++ 5 files changed, 132 insertions(+) diff --git a/NEWS b/NEWS index afef81b40..26be454df 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Post-v2.16.0 * Add support for DPDK 21.11. * Forbid use of DPDK multiprocess feature. * Add support for running threads on cores >= RTE_MAX_LCORE. + * Add actions auto-validator function to compare different actions + implementations against default implementation. - Python: * For SSL support, the use of the pyOpenSSL library has been replaced with the native 'ssl' module. diff --git a/lib/dp-packet.c b/lib/dp-packet.c index 72f6d09ac..1e4ff35ef 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -506,3 +506,26 @@ dp_packet_resize_l2(struct dp_packet *b, int increment) dp_packet_adjust_layer_offset(&b->l2_5_ofs, increment); return dp_packet_data(b); } + +bool +dp_packet_compare_and_log(struct dp_packet *good, struct dp_packet *test, + struct ds *err_str) +{ + if ((good->l2_pad_size != test->l2_pad_size) || + (good->l2_5_ofs != test->l2_5_ofs) || + (good->l3_ofs != test->l3_ofs) || + (good->l4_ofs != test->l4_ofs)) { + ds_put_format(err_str, "Autovalidation packet offsets failed" + "\n"); + ds_put_format(err_str, "Good offsets: l2_pad_size %u," + " l2_5_ofs : %u l3_ofs %u, l4_ofs %u\n", + good->l2_pad_size, good->l2_5_ofs, + good->l3_ofs, good->l4_ofs); + ds_put_format(err_str, "Test offsets: l2_pad_size %u," + " l2_5_ofs : %u l3_ofs %u, l4_ofs %u\n", + test->l2_pad_size, test->l2_5_ofs, + test->l3_ofs, test->l4_ofs); + return false; + } + return true; +} diff --git a/lib/dp-packet.h b/lib/dp-packet.h index ee0805ae6..723215add 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -236,6 +236,11 @@ void *dp_packet_steal_data(struct dp_packet *); static inline bool dp_packet_equal(const struct dp_packet *, const struct dp_packet *); + +bool dp_packet_compare_and_log(struct dp_packet *good, + struct dp_packet *test, + struct ds *err_str); + /* Frees memory that 'b' points to, as well as 'b' itself. */ static inline void diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index d88ff4921..a4155b5df 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -30,8 +30,16 @@ int32_t action_autoval_init(struct odp_execute_action_impl *self); VLOG_DEFINE_THIS_MODULE(odp_execute_private); static uint32_t active_action_impl_index; +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); static struct odp_execute_action_impl action_impls[] = { + [ACTION_IMPL_AUTOVALIDATOR] = { + .available = 1, + .name = "autovalidator", + .probe = NULL, + .init_func = action_autoval_init, + }, + [ACTION_IMPL_SCALAR] = { .available = 1, .name = "scalar", @@ -99,3 +107,94 @@ odp_execute_action_init(void) } } } + +/* Init sequence required to be scalar first to pick up the default scalar +* implementations, allowing over-riding of the optimized functions later. +*/ +BUILD_ASSERT_DECL(ACTION_IMPL_SCALAR == 0); +BUILD_ASSERT_DECL(ACTION_IMPL_AUTOVALIDATOR == 1); + +/* Loop over packets, and validate each one for the given action. */ +static void +action_autoval_generic(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a, bool should_steal) +{ + uint32_t failed = 0; + + int type = nl_attr_type(a); + enum ovs_action_attr attr_type = (enum ovs_action_attr) type; + + struct odp_execute_action_impl *scalar = &action_impls[ACTION_IMPL_SCALAR]; + + struct dp_packet_batch good_batch; + dp_packet_batch_clone(&good_batch, batch); + + scalar->funcs[attr_type](NULL, &good_batch, a, should_steal); + + for (uint32_t impl = ACTION_IMPL_BEGIN; impl < ACTION_IMPL_MAX; impl++) { + /* Clone original batch and execute implementation under test. */ + struct dp_packet_batch test_batch; + dp_packet_batch_clone(&test_batch, batch); + action_impls[impl].funcs[attr_type](NULL, &test_batch, a, + should_steal); + + /* Loop over implementations, checking each one. */ + for (uint32_t pidx = 0; pidx < batch->count; pidx++) { + struct dp_packet *good_pkt = good_batch.packets[pidx]; + struct dp_packet *test_pkt = test_batch.packets[pidx]; + + struct ds log_msg = DS_EMPTY_INITIALIZER; + + /* Compare packet length and payload contents. */ + bool eq = dp_packet_equal(good_pkt, test_pkt); + + if (!eq) { + ds_put_format(&log_msg, "Packet: %d\nAction : ", pidx); + format_odp_actions(&log_msg, a, a->nla_len, NULL); + ds_put_format(&log_msg, "\nGood hex:\n"); + ds_put_hex_dump(&log_msg, dp_packet_data(good_pkt), + dp_packet_size(good_pkt), 0, false); + ds_put_format(&log_msg, "Test hex:\n"); + ds_put_hex_dump(&log_msg, dp_packet_data(test_pkt), + dp_packet_size(test_pkt), 0, false); + + failed = 1; + } + + /* Compare offsets and RSS */ + if (!dp_packet_compare_and_log(good_pkt, test_pkt, &log_msg)) { + failed = 1; + } + + uint32_t good_hash = dp_packet_get_rss_hash(good_pkt); + uint32_t test_hash = dp_packet_get_rss_hash(test_pkt); + + if (good_hash != test_hash) { + ds_put_format(&log_msg, "Autovalidation rss hash failed" + "\n"); + ds_put_format(&log_msg, "Good RSS hash : %u\n", good_hash); + ds_put_format(&log_msg, "Test RSS hash : %u\n", test_hash); + + failed = 1; + } + + if (failed) { + VLOG_ERR_RL(&rl, "\nAutovalidation failed details:\n%s", + ds_cstr(&log_msg)); + } + } + dp_packet_delete_batch(&test_batch, 1); + } + dp_packet_delete_batch(&good_batch, 1); + + /* Apply the action to the original batch for continued processing. */ + scalar->funcs[attr_type](NULL, batch, a, should_steal); +} + +int32_t +action_autoval_init(struct odp_execute_action_impl *self) +{ + self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_autoval_generic; + + return 0; +} diff --git a/lib/odp-execute-private.h b/lib/odp-execute-private.h index c2e86bbee..d49714bd2 100644 --- a/lib/odp-execute-private.h +++ b/lib/odp-execute-private.h @@ -68,6 +68,7 @@ struct odp_execute_action_impl { /* Order of Actions implementations. */ enum odp_execute_action_impl_idx { ACTION_IMPL_SCALAR, + ACTION_IMPL_AUTOVALIDATOR, /* See ACTION_IMPL_BEGIN below, for "first to-be-validated" impl. * Do not change the autovalidator position in this list without updating * the define below. @@ -78,6 +79,8 @@ enum odp_execute_action_impl_idx { /* Index to start verifying implementations from. */ BUILD_ASSERT_DECL(ACTION_IMPL_SCALAR == 0); +BUILD_ASSERT_DECL(ACTION_IMPL_AUTOVALIDATOR == 1); +#define ACTION_IMPL_BEGIN (ACTION_IMPL_AUTOVALIDATOR + 1) /* Odp execute init handles setting up the state of the actions functions at * initialization time. It cannot return errors, as it must always succeed in