From patchwork Thu Mar 17 01:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606335 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=RJGhNhfv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 4KJpzl2mCjz9sCD for ; Thu, 17 Mar 2022 12:13:07 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5BD8961262; Thu, 17 Mar 2022 01:13:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ik7i0x2ufiTX; Thu, 17 Mar 2022 01:13:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5783261250; Thu, 17 Mar 2022 01:13:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2DD74C001D; Thu, 17 Mar 2022 01:13:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 754F7C0012 for ; Thu, 17 Mar 2022 01:13:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 54EE661260 for ; Thu, 17 Mar 2022 01:13:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iEHeKo-k-z4D for ; Thu, 17 Mar 2022 01:13:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on20618.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8b::618]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7CB2861254 for ; Thu, 17 Mar 2022 01:13:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CigHPiu38NeolVbVPB/S2XlkSY2pwSZeYva0LC3yN7lTBDl+A+wux72D+qLiTKEARqsUA7Cw0Pa6ndnXptpku/p9Mo2AA/InaRnFXejK+PDfvIV0JegxwM58IR1he340a4O057VDRavE0OOslC/IliawEPWHhrwuFYigZhZyr1su2JlHCEbj+4RefrzAUCy8IZh30A8HOkdA7wIpEx+waDntQu0w/70qZvVe/8dPYUqyO8GinOhMrYkUYhSc+L397u3Wy8HHAR40sYsqwypjZxVZ31sFUzMS8hXfgXzEilQDR0fV9VJ2AvVpAQUU+UVL3E7rUc8PpRaTv3V0U1kaHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FTTJfINLyEMkZO5P7cAWNCUB7VBTaAnlgyd88lEyPV8=; b=bGJzPOs9soCyowKbDZ1folzOK4hPL6IUJFmj2HJHkJ3ukEoEma/Kd74vUUpxmmrUzDzJTyeo8DSPJUdm8F9v8t4OHOfOIQgRJcTp6bWlJzpsdMz9XoReTws7gGmcphoBozD6YrFj1Bxd/0Qab7DQb+q50HIedr+qVBj3DNNF4ndtj3XER506LDYFNIm3c23+Nf7AzpLpvpywKMdqfkrsNUL6g77G/40ZWzhsvHFDHSUV9bLP644joVqE20SwEl7YAVx+RaAvIIVwWKc1sYupm19D/8aMwaAC7ovrG/MqYJm4i57dhRUsFrR3jRa514ujcPQFgBIE9rIkPMoqaoRYsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FTTJfINLyEMkZO5P7cAWNCUB7VBTaAnlgyd88lEyPV8=; b=RJGhNhfvvK4a9yuCKeZvmMrZc47uEj6fNn2CVnSmn7IjhtavBh4uid8VixnstGURXdlQ4AkLr4qeIc3WBDbch4Oe6RyeHohJLIZs9+S/iiioTN9bq8b1SH2SEVKsLd6A9fMbXuCxIVXlIgj8L1VWG3NmcjLTgfB3XBXRZyLhSdqssl4en6zSOgmn3jW+xYzQ//4kdwNVCVp0ZeUejThuuB+20Bx8hcmJHQc+TWt5BrrU2HE0KhILLp6NZjMFPy9sA0Npx6guK14BvGRe7il4OvVViUdI09wafh13PY0xekS1n3whNEpNPIXAw+kZ+sLL92u2qs6Xn2/a58DyPAocqw== Received: from DS7PR03CA0339.namprd03.prod.outlook.com (2603:10b6:8:55::18) by CY4PR12MB1590.namprd12.prod.outlook.com (2603:10b6:910:a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25; Thu, 17 Mar 2022 01:12:58 +0000 Received: from DM6NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:8:55:cafe::67) by DS7PR03CA0339.outlook.office365.com (2603:10b6:8:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25 via Frontend Transport; Thu, 17 Mar 2022 01:12:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT038.mail.protection.outlook.com (10.13.173.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:12:57 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:12:57 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:12:56 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:12:54 -0700 To: Date: Thu, 17 Mar 2022 09:12:42 +0800 Message-ID: <20220317011249.46787-2-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c15f3ac-49a0-46fe-1296-08da07b345e1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1590:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5L2W191HXBvgu9onTvRcEBRvaEYj8vnlXtdYy9KzdIuUKYUQnnHo/Bh4cGF6tfYvBr9fsQ7xl0iSR+Gfzt+Xy+x5t0begm9SO4CsFr0eXZuLLfFhWmjDsGGvv27FXMNahFmDcuXseBiZOl4wBHseSm5Q52AmaRjtPUktzlRDrqkkxWiACjFgBVEidghsS5neBSv17j6Vg2gJBGThyIgfocnsjRdwJKBA6wY5F+L0CztWq+kok6YdprfP/48TFZYWw8i3srjQrCvW5MofFzqd5D5rHIBTRVhkl2YFAck+OBjBsHyT+ZpxBsnoLDD6X6LhSK+pExZ+ZUaLv5/wxw+4NFkXT80FN0stQnlozpJLk7m2MHAHBka8wmd3v+47ZXdNEEURGbDdBS7OFw0hdxvbd9k1UKRee51a9ICJis3w6XDnyH3c7cnaPif5LH0Db3yfNWTTcTL+AbJ3r7CE0klaT9oRfyqxjf9UNAOd8HqnfHmWm7VWQa/29Idh3+6NfjDzLlnvcsvVHAyW9hAeUflGXMT/ASCNCqYxJR7oDAJXyS1x4AUIm2WSgmuQ/5ecxg30z6JQqV8lH90rkN9vlTZ5hYnlktj0nuzg1ncf+FkRcMZmwIlTJMMVvNzWscMVnjKsCwe1y0U8PDcd0SZEtwhABbOXcsorv4dvxIM6fiMmAD76Twi1eJ2ux1XLtoSWugME+4B3RdhxwPZihTCTjCUSMQ== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(8676002)(86362001)(2616005)(316002)(6916009)(40460700003)(356005)(6666004)(508600001)(82310400004)(70206006)(4326008)(70586007)(47076005)(83380400001)(8936002)(54906003)(5660300002)(336012)(36756003)(2906002)(426003)(1076003)(81166007)(36860700001)(26005)(186003)(107886003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:12:57.8015 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c15f3ac-49a0-46fe-1296-08da07b345e1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1590 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 1/8] compat: Add psample and tc sample action defines for older kernels 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Update kernel UAPI to support psample and the tc sample action. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- include/linux/automake.mk | 4 ++- include/linux/psample.h | 62 ++++++++++++++++++++++++++++++++ include/linux/tc_act/tc_sample.h | 25 +++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 include/linux/psample.h create mode 100644 include/linux/tc_act/tc_sample.h diff --git a/include/linux/automake.mk b/include/linux/automake.mk index f857c7e08..fc842289b 100644 --- a/include/linux/automake.mk +++ b/include/linux/automake.mk @@ -8,4 +8,6 @@ noinst_HEADERS += \ include/linux/tc_act/tc_skbedit.h \ include/linux/tc_act/tc_tunnel_key.h \ include/linux/tc_act/tc_vlan.h \ - include/linux/tc_act/tc_ct.h + include/linux/tc_act/tc_ct.h \ + include/linux/tc_act/tc_sample.h \ + include/linux/psample.h diff --git a/include/linux/psample.h b/include/linux/psample.h new file mode 100644 index 000000000..e585db5bf --- /dev/null +++ b/include/linux/psample.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UAPI_PSAMPLE_H +#define __UAPI_PSAMPLE_H + +enum { + PSAMPLE_ATTR_IIFINDEX, + PSAMPLE_ATTR_OIFINDEX, + PSAMPLE_ATTR_ORIGSIZE, + PSAMPLE_ATTR_SAMPLE_GROUP, + PSAMPLE_ATTR_GROUP_SEQ, + PSAMPLE_ATTR_SAMPLE_RATE, + PSAMPLE_ATTR_DATA, + PSAMPLE_ATTR_GROUP_REFCOUNT, + PSAMPLE_ATTR_TUNNEL, + + PSAMPLE_ATTR_PAD, + PSAMPLE_ATTR_OUT_TC, /* u16 */ + PSAMPLE_ATTR_OUT_TC_OCC, /* u64, bytes */ + PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */ + PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */ + PSAMPLE_ATTR_PROTO, /* u16 */ + + __PSAMPLE_ATTR_MAX +}; + +enum psample_command { + PSAMPLE_CMD_SAMPLE, + PSAMPLE_CMD_GET_GROUP, + PSAMPLE_CMD_NEW_GROUP, + PSAMPLE_CMD_DEL_GROUP, +}; + +enum psample_tunnel_key_attr { + PSAMPLE_TUNNEL_KEY_ATTR_ID, /* be64 Tunnel ID */ + PSAMPLE_TUNNEL_KEY_ATTR_IPV4_SRC, /* be32 src IP address. */ + PSAMPLE_TUNNEL_KEY_ATTR_IPV4_DST, /* be32 dst IP address. */ + PSAMPLE_TUNNEL_KEY_ATTR_TOS, /* u8 Tunnel IP ToS. */ + PSAMPLE_TUNNEL_KEY_ATTR_TTL, /* u8 Tunnel IP TTL. */ + PSAMPLE_TUNNEL_KEY_ATTR_DONT_FRAGMENT, /* No argument, set DF. */ + PSAMPLE_TUNNEL_KEY_ATTR_CSUM, /* No argument. CSUM packet. */ + PSAMPLE_TUNNEL_KEY_ATTR_OAM, /* No argument. OAM frame. */ + PSAMPLE_TUNNEL_KEY_ATTR_GENEVE_OPTS, /* Array of Geneve options. */ + PSAMPLE_TUNNEL_KEY_ATTR_TP_SRC, /* be16 src Transport Port. */ + PSAMPLE_TUNNEL_KEY_ATTR_TP_DST, /* be16 dst Transport Port. */ + PSAMPLE_TUNNEL_KEY_ATTR_VXLAN_OPTS, /* Nested VXLAN opts* */ + PSAMPLE_TUNNEL_KEY_ATTR_IPV6_SRC, /* struct in6_addr src IPv6 address. */ + PSAMPLE_TUNNEL_KEY_ATTR_IPV6_DST, /* struct in6_addr dst IPv6 address. */ + PSAMPLE_TUNNEL_KEY_ATTR_PAD, + PSAMPLE_TUNNEL_KEY_ATTR_ERSPAN_OPTS, /* struct erspan_metadata */ + PSAMPLE_TUNNEL_KEY_ATTR_IPV4_INFO_BRIDGE, /* No argument. IPV4_INFO_BRIDGE mode.*/ + __PSAMPLE_TUNNEL_KEY_ATTR_MAX +}; + +/* Can be overridden at runtime by module option */ +#define PSAMPLE_ATTR_MAX (__PSAMPLE_ATTR_MAX - 1) + +#define PSAMPLE_NL_MCGRP_CONFIG_NAME "config" +#define PSAMPLE_NL_MCGRP_SAMPLE_NAME "packets" +#define PSAMPLE_GENL_NAME "psample" +#define PSAMPLE_GENL_VERSION 1 + +#endif diff --git a/include/linux/tc_act/tc_sample.h b/include/linux/tc_act/tc_sample.h new file mode 100644 index 000000000..fee1bcc20 --- /dev/null +++ b/include/linux/tc_act/tc_sample.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __LINUX_TC_SAMPLE_H +#define __LINUX_TC_SAMPLE_H + +#include +#include +#include + +struct tc_sample { + tc_gen; +}; + +enum { + TCA_SAMPLE_UNSPEC, + TCA_SAMPLE_TM, + TCA_SAMPLE_PARMS, + TCA_SAMPLE_RATE, + TCA_SAMPLE_TRUNC_SIZE, + TCA_SAMPLE_PSAMPLE_GROUP, + TCA_SAMPLE_PAD, + __TCA_SAMPLE_MAX +}; +#define TCA_SAMPLE_MAX (__TCA_SAMPLE_MAX - 1) + +#endif From patchwork Thu Mar 17 01:12:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606336 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=XwLgcbfH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.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 4KJpzp5X3Jz9sCD for ; Thu, 17 Mar 2022 12:13:10 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 11C6241838; Thu, 17 Mar 2022 01:13:09 +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 auqv7ZBSfUBB; Thu, 17 Mar 2022 01:13:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id F253B4182C; Thu, 17 Mar 2022 01:13:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D4556C001D; Thu, 17 Mar 2022 01:13:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5648BC000B for ; Thu, 17 Mar 2022 01:13:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4578E4049F for ; Thu, 17 Mar 2022 01:13:05 +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 cTA10QvrWZc5 for ; Thu, 17 Mar 2022 01:13:04 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20610.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::610]) by smtp4.osuosl.org (Postfix) with ESMTPS id 660B9402A2 for ; Thu, 17 Mar 2022 01:13:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bgWZuYBfWugVXXUqbNjq8c7/pEHnspxV7cFrX2CwKm2lkDS4HfDJFjAAiWX4lgphw2LHKvU3RtUeObo9Wv5YpYDF3pJKLhzbSHp/r3gTdmOF94E26PTOTo7oVRfIlyY9IzwgqrrhixlsSs9Pu6d4CM4/raFYFU1PKVMrMAm7MT3UzPmvEjEyVOEDr5DArEwRfJJlli/P9xzFFDKZ+iFoiw6qN91uJEvSQhioJ9CF9DGSenjB0o10JFjKD/sujuHeapdp2B720uL3y4vQsM1kLNbDQHSW3riP8knCoQ8PKUv4LoxBKCxmlAOAxNYFRj0Mv/b70YWYU3mr+Q66NA8JVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tVAx2dfBvVOYxoEH2FU4Eo6XZgCor4UnIBx5U5XhyzE=; b=gvABhZhfwB+A63OApuYBRo4QNECVn+hND2PSYzt+9zYnwctwXJb9US+yHSsql6CWrLGEFc8qi4x/C6yZ81ebAC+DplHkwD1yzRKl7xIph5LoP6AKwN+Ael+s/bvbu4RF27ZaULy0pGI/2PwQ6OWUO7s00kexfZvPlGAccrn1a5ltU35Wx6aIX2253KALO6vklVJiiwZ20+1OpWaSYeJqKtlEi+3tgYo2pnoX3ZVj/+0UxTVN/xE6yCwTY5hXBT/R9RVjD5HFE736y57/yXyVsvXzhPXAJiu1wz+92+QpXs5Ui89xcDRT8+Uua0JHYJxyxXH/DkpnzJ07bddyLtIJYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tVAx2dfBvVOYxoEH2FU4Eo6XZgCor4UnIBx5U5XhyzE=; b=XwLgcbfHK6D/k9t8SBKbzhZgxWmVl5WU/iA6QlLf6egUX9helOQWWb57H3N/cqyolCGdBOvFPSGgFcpkEticPJJGnyiSR6u0+Iw2chU3bnf228IupynSQ5V8aFw4tZLNkBUSWE/gLH8pyFW5ZexYmX59auYjBNcQ7kZFr7nNM7f68RgduAvSSbQucLVE7qa2/byE1b/jxzgYcSFyKOoxAfysPgcMVtjNDJOfAKND02iwN/GkTEtfUF/AXA61CCmK21DcaFA+Lxknm80fsXjYj6/YJH72W7YaZpP1FzTUh7RG2GjOtM6zCRjx/1zBkE9PC5NOLade5TdHeTJft7+Sdg== Received: from BN9PR03CA0376.namprd03.prod.outlook.com (2603:10b6:408:f7::21) by MN2PR12MB4639.namprd12.prod.outlook.com (2603:10b6:208:a4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 01:13:01 +0000 Received: from BN8NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::a5) by BN9PR03CA0376.outlook.office365.com (2603:10b6:408:f7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.17 via Frontend Transport; Thu, 17 Mar 2022 01:13:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT033.mail.protection.outlook.com (10.13.177.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:00 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:00 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:12:59 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:12:56 -0700 To: Date: Thu, 17 Mar 2022 09:12:43 +0800 Message-ID: <20220317011249.46787-3-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4956bbb-38ec-4aab-4659-08da07b347b4 X-MS-TrafficTypeDiagnostic: MN2PR12MB4639:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6etx/z/ETangRp0IW9zL5T4xqa8w2OEgc12HrWN/lbcd5IlzSB6oAKwsOlkFYMIU+6wgBA10+lSK0DlsR+HTUUE5US0i4ounuOW05dkbUo9JY32kFmBU9SZ/W3NogbXvSvEq1TWwfv4ciqtNxH75+xb1qneOzgfLpnimvvCqTjzAHiQCckwhObJ21VouDIFeiAYApicJviiLgDY2l1IU3xKU8mkVk4BBCFLkIcRcBq7+/Ib4IfcOAWJ0TAZyyS46kowhFYNZth7o6hwj/C+AYmfd28+8Ovywo1DN3yYEtH3lp2LPx9jo10v+qdKisq8J8vauzOJlBOeq7h5elbTglPPJ7Kbr8DeX/Rn0w9JgUKxSHm3sWZRxPp9d7WIlSQu3Bjn9JfG5t4UyK3EeipZ/pYvr7vbwUMhH7VAeQm57mDtlae3PFMQRNJ+aHnIepMjY5CcX1dfxt32unCc2+vPCPyEktvxjwyf2Dw1pqRjsq0k45pnPTYTEn9QGK7QvE6sthzHJUPwszbKaw2SKKqjtKeoJZO0nr+6MCUZOHytF2V3hqjvFDqPqZ5CGMZP4YeqCfCSCzPpjPrVU37JAShA+bndjv8uz/gqG78JnPvmNdBGUGMQRAQ98lnehMPe2VVZxMs+ebJ27Y5v8dK3FXDRT4KATFIrpn+WD+oiAK1YMarVg0g5J1dfpU4rN/S0l/rgaWlYxNSHZNKiMEdVgRPt7aQ== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(356005)(2906002)(82310400004)(81166007)(83380400001)(5660300002)(508600001)(8936002)(40460700003)(86362001)(70206006)(70586007)(4326008)(8676002)(6666004)(186003)(426003)(2616005)(47076005)(336012)(316002)(107886003)(36756003)(1076003)(6916009)(54906003)(36860700001)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:00.8008 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4956bbb-38ec-4aab-4659-08da07b347b4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4639 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 2/8] ovs-kmod-ctl: Load kernel module psample 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Load kernel module psample to receive sampled packets from TC. Before removing kernel module psample, remove act_sample first. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- utilities/ovs-kmod-ctl.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utilities/ovs-kmod-ctl.in b/utilities/ovs-kmod-ctl.in index 19f100964..6fa945a83 100644 --- a/utilities/ovs-kmod-ctl.in +++ b/utilities/ovs-kmod-ctl.in @@ -28,6 +28,14 @@ for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do done insert_mods () { + # Try loading psample kernel module. + modinfo psample > /dev/null 2>&1 + if test $? = 0; then + action "Inserting psample module" modprobe psample + else + log_warning_msg "No psample module, can't offload sFlow action" + fi + # Try loading openvswitch kernel module. action "Inserting openvswitch module" modprobe openvswitch } @@ -95,6 +103,12 @@ remove_kmods() { if test -e /sys/module/vxlan; then action "Forcing removal of vxlan module" rmmod vxlan fi + if test -e /sys/module/act_sample; then + action "Forcing removal of act_sample module" rmmod act_sample + fi + if test -e /sys/module/psample; then + action "Forcing removal of psample module" rmmod psample + fi } usage () { From patchwork Thu Mar 17 01:12:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606337 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tzsaaJBp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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 4KJpzy1sqLz9sCD for ; Thu, 17 Mar 2022 12:13:18 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8DB448473E; Thu, 17 Mar 2022 01:13:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org 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 V7nUiUlHJX4U; Thu, 17 Mar 2022 01:13:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 847CF84749; Thu, 17 Mar 2022 01:13:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 522B0C0073; Thu, 17 Mar 2022 01:13:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15BAAC0012 for ; Thu, 17 Mar 2022 01:13:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 05F26402A2 for ; Thu, 17 Mar 2022 01:13:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 L0ChMUCNhN2a for ; Thu, 17 Mar 2022 01:13:08 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2060b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5b::60b]) by smtp4.osuosl.org (Postfix) with ESMTPS id 817564182D for ; Thu, 17 Mar 2022 01:13:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BVNGFei1MVnT4lEzfiPWP6s6jR2eGDZt9AAK4g9dpzWLwEtK9FE8Pn8JNN/orLjQx7H2+SEtE8cwlZvwk/mUTcAN4GNcQ9xaDeUkMmCWGEWEUPUVqEuWEqHScKx7lfEfXoKBBUdGXae0kilFyqllcAuBLG3OQgaW8Oa5puN+KaJVsBE/BLKbtzjTwrUeHbL3hqE6CBc6vBJ1vowzxgYrV7XiuXyOvnIEASZm1mwsNU2m3mj3enFep8Vj/WVVXLSCTBqNeVjRsJQ+pCEENKWsL5U9I0/e1jtlj1qP3rzRLmKetMdONdbYM/arwGR+mmwazTlSuDUS92P4kzqORZDhRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vkHyFTQJFdhHtUfKc7ggK0ezK17ZcoY2HvgZ42oqrpk=; b=G0iOHohcgu7Nk0CaLNd3PGhUv+d3mOuzxoYRwADKmaKY1cs+q4lsCchVxR9N8EKrUZvazt0IGzxbk11zTt61L3qCnuMCQ2Hpy+iEZij7UIvK30eRlVxDC3JLeu3bkxYWJmMQm2Bbf1pSje0T1Ijh4BvqRzLU/5OnIqp+aWFeM5zUmQeepaNJx4EsWLZwFYERYPJAC8d6at44VC3K7lCx4s7jREgcsTK8DYMRfbAy0WZxZFxwi5PPm/gBIsZLcWOTm8ZNYVdwND9mMFVuVekr6I15w2aD0pG6SaKDYhNqRKZs8DJdRU+CcgFXXWrrn4/1h7piOOinNThJbuB1YbjbLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vkHyFTQJFdhHtUfKc7ggK0ezK17ZcoY2HvgZ42oqrpk=; b=tzsaaJBpZexaPTWFPPTQNYBNQIos7953q93Qcjo2kKBqVWZmcSL65Ojsbqtj0pJLKMO5NJ4dd1Z5rJc3lBw5GxQBGfdZHbTh2xvgzZDqQo9/svCOrETfibwdBcZ1NM5xNXBU/SftnI/8WLPINE4QfW0uZI+bGhQMeFglt3P1zcCZnVQrdc3pr1n0Zs35HViFKo5FUmmudiYB9zAstyAMDWsWj+GpVYQFAdjfV8v2seyT3IsYycYRX8xak4pDzJypO116eH3qh2V0PYFflT/WOL5SmW0F51zU4pzswDzZM7Mr4a9Z5SDymreRcPF+2W2Iv9MsxO7voPpomnMCFVxzYw== Received: from DM5PR10CA0003.namprd10.prod.outlook.com (2603:10b6:4:2::13) by MWHPR12MB1247.namprd12.prod.outlook.com (2603:10b6:300:10::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25; Thu, 17 Mar 2022 01:13:03 +0000 Received: from DM6NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:4:2:cafe::92) by DM5PR10CA0003.outlook.office365.com (2603:10b6:4:2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.16 via Frontend Transport; Thu, 17 Mar 2022 01:13:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT047.mail.protection.outlook.com (10.13.172.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:03 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:02 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:01 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:12:59 -0700 To: Date: Thu, 17 Mar 2022 09:12:44 +0800 Message-ID: <20220317011249.46787-4-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 390c0abf-8626-48ee-281e-08da07b348fe X-MS-TrafficTypeDiagnostic: MWHPR12MB1247:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eKQgLoDM/3ylCAVOyLT9lDKNxIfHXXGdjIL1V9QDu9qFmH/OzKaFFDk9bc6iSQlJ/q1BJaOwUYayH7RD+X0sW1T4Vfg+PJY8Of+4jg+pbPtwOslpaqfcdZRfuWVb6YF+/WWwzgPwqFnFijycTLHXF7ZodvcWJmAX3kwVAIXVW0uXUHhyQQR1IN9+bosU9z/vblRUstcrIx2qz0q1gYTDbyE56GX3Fm33Gx/RTwlVOAqObqAockLKqSnhUIoJMOlHUmsuE3Lr7XkvbW7j4PMHPtuxX7iiUKon0EhJDW2IWExYdpYFKHGq9ZWXf75uHdYA+xVaQMhFFtp4Yp0L5wDhK1XBzCYQZ/x4xYG1X3ROvoXUnY61w8bJprds7olqSBoo38h7AyLN0grqU/+PMjTZHYbEFuQx3+cg8tOVMkjBqxe+6AVTLBceUYY3KqMN5pNio5Xt7IOHvlqtHpcGKwZm+S52eG5fLCne+/9vI5laK8lJY/gnJdBzUnI+3sEliKkT52HE9sqNkSPO+Hz2YfCLyfnVjbR9QOfahM4mf2Ke3fnhv9r7a6uPeIabBCoILwZJksO819aNWUOWHKhBRvye4/wrOUbP1M83KNo3KMFeopgiL98ugMt+Wnq9s/2Uagipzi2gpECXT+nRUeB7QJvqO5ysYOkk8Y7s+kqlkkzfCWKvoGI/Ju43VmcTY2pNnwdt9G/OzvSVUpw+70Vj27A3LOEnz0RxdKG3yC4/EVgDP9iXy9V6tL7fFCwyBnC/j9sxkKZfq7ntQRLDcy1RiC4fGk6wvI8Q30ZzxZia/bj9bp8= X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(86362001)(107886003)(8676002)(426003)(6666004)(70586007)(26005)(186003)(70206006)(336012)(966005)(1076003)(2906002)(40460700003)(5660300002)(508600001)(8936002)(356005)(4326008)(82310400004)(81166007)(2616005)(6916009)(36860700001)(54906003)(83380400001)(47076005)(36756003)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:03.0409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 390c0abf-8626-48ee-281e-08da07b348fe X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1247 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 3/8] dpif-offload-provider: Introduce dpif-offload-provider layer 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Some offload actions require functionality that is not netdev based, but dpif. For example, sFlow action requires to create a psample netlink socket to receive the sampled packets from TC or kernel driver. Create dpif-offload-provider layer to support such actions. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein --- lib/automake.mk | 2 ++ lib/dpif-offload-provider.h | 52 +++++++++++++++++++++++++++++++++++++ lib/dpif-offload.c | 43 ++++++++++++++++++++++++++++++ lib/dpif-provider.h | 4 ++- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 lib/dpif-offload-provider.h create mode 100644 lib/dpif-offload.c diff --git a/lib/automake.mk b/lib/automake.mk index a23cdc4ad..781fba47a 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -129,6 +129,8 @@ lib_libopenvswitch_la_SOURCES = \ lib/dpif-netdev-private.h \ lib/dpif-netdev-perf.c \ lib/dpif-netdev-perf.h \ + lib/dpif-offload.c \ + lib/dpif-offload-provider.h \ lib/dpif-provider.h \ lib/dpif.c \ lib/dpif.h \ diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h new file mode 100644 index 000000000..3b94740df --- /dev/null +++ b/lib/dpif-offload-provider.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DPIF_OFFLOAD_PROVIDER_H +#define DPIF_OFFLOAD_PROVIDER_H + +struct dpif; +struct dpif_offload_sflow; + +/* Datapath interface offload structure, to be defined by each implementation + * of a datapath interface. + */ +struct dpif_offload_class { + /* Type of dpif offload in this class, e.g. "system", "netdev", etc. + * + * One of the providers should supply a "system" type, since this is + * the type assumed if no type is specified when opening a dpif. */ + const char *type; + + /* Called when the dpif offload provider is registered. */ + int (*init)(void); + + /* Free all dpif offload resources. */ + void (*destroy)(void); + + /* Arranges for the poll loop for an upcall handler to wake up when psample + * has a message queued to be received. */ + void (*sflow_recv_wait)(void); + + /* Polls for an upcall from psample for an upcall handler. + * Return 0 for success. */ + int (*sflow_recv)(struct dpif_offload_sflow *sflow); +}; + +void dpif_offload_sflow_recv_wait(const struct dpif *dpif); +int dpif_offload_sflow_recv(const struct dpif *dpif, + struct dpif_offload_sflow *sflow); + +#endif /* DPIF_OFFLOAD_PROVIDER_H */ diff --git a/lib/dpif-offload.c b/lib/dpif-offload.c new file mode 100644 index 000000000..f2bf3e634 --- /dev/null +++ b/lib/dpif-offload.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "dpif-provider.h" + +void +dpif_offload_sflow_recv_wait(const struct dpif *dpif) +{ + const struct dpif_offload_class *offload_class = dpif->offload_class; + + if (offload_class && offload_class->sflow_recv_wait) { + offload_class->sflow_recv_wait(); + } +} + +int +dpif_offload_sflow_recv(const struct dpif *dpif, + struct dpif_offload_sflow *sflow) +{ + const struct dpif_offload_class *offload_class = dpif->offload_class; + + if (offload_class && offload_class->sflow_recv) { + return offload_class->sflow_recv(sflow); + } + + return EOPNOTSUPP; +} diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 12477a24f..99009722a 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -22,8 +22,9 @@ * exposed over OpenFlow as a single switch. Datapaths and the collections of * ports that they contain may be fixed or dynamic. */ -#include "openflow/openflow.h" #include "dpif.h" +#include "dpif-offload-provider.h" +#include "openflow/openflow.h" #include "util.h" #ifdef __cplusplus @@ -35,6 +36,7 @@ extern "C" { * This structure should be treated as opaque by dpif implementations. */ struct dpif { const struct dpif_class *dpif_class; + const struct dpif_offload_class *offload_class; char *base_name; char *full_name; uint8_t netflow_engine_type; From patchwork Thu Mar 17 01:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606338 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=BrcuydxM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4KJq056glkz9sCD for ; Thu, 17 Mar 2022 12:13:25 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 3509540AED; Thu, 17 Mar 2022 01:13:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zeeF749-4rjw; Thu, 17 Mar 2022 01:13:20 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 5FCCC40B2F; Thu, 17 Mar 2022 01:13:19 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 12A23C0012; Thu, 17 Mar 2022 01:13:19 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 28D58C0033 for ; Thu, 17 Mar 2022 01:13:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 2DECE40347 for ; Thu, 17 Mar 2022 01:13:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 9bv91r2JCPY9 for ; Thu, 17 Mar 2022 01:13:08 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20606.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::606]) by smtp4.osuosl.org (Postfix) with ESMTPS id D794141832 for ; Thu, 17 Mar 2022 01:13:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l86NtuOErATXINXaJW6XaQdJKGMV5bc+rAYH1NLvrqjsIDK9AF6Q1x0cK1656Zkom7p03RRwc9HJ0SkBWI1NJxC0+AaWpubFtPZkniI7wP7a0aSjdW5yHL9nnNS5gxU5QPj0BVL8UtwqWDAyc+BeFmPt8AzieAPzxZitJlTb/Jd51CfGfCK1YcO5wqGk2lBTC2XR6bpZUzyc92I1A8mGkgsqPQ95enBpfi8uQ1lhD/8K5HXVTXHPO7kqNAuxkFulIabntgr8yp4iKz3YT0eRzyzPRZnX4jLARYjysRUB4smEIAJfNe4uGpt6dI0DNvJmtuYDFNB9sUsObAUguFfJbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y7tJrATKj3uzm1Smpk6qBf5URuD69a4/xpnWZVkObeM=; b=LshMWcwD+hRGu2MDpxfJyX4zuDQPBflWzyKLL+yH6hn6w6NGgnhstOtPCxnlQvGBlL4p2MxVZrui7M5/ZfBT9jLHKhyB6E1oeGMMi2sOLWdNgkAlwZ4fnwJJ44lvbKxYbaTlWXrnj/IYDhQ6vPHUw3KcbO0gdrlJKP+DNT+xXVtJEucOcE+BQ2pcAjgwkeT27izoitV2m5FXn0MJ1LOP/8Z6POAhARyqAtqjaJUE1CGojXlOXQD/vp0EOmOR5xGdS/yNp0lQt4SyhriRwIBYt/6S2Bc4aJ6kWFOAzbJzxHf2veptzEbWALHLL/OQWcsbYcYJ03A7VcMrz4wAgSFsSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y7tJrATKj3uzm1Smpk6qBf5URuD69a4/xpnWZVkObeM=; b=BrcuydxMtd1lsZOOrgElA5juXPVzaDswz9d3lzigJg/ycbKF92Ir/DKHoeilOCrC3zBNX+ddltGuf2vBnIVC8MOgqv1mFbVLkVacOgBArP6oRpn46c/XZkMO6U2kmyYSTbroub19RY94qnDL2iWDUX54F4cTBPYD0q4l9pGw94W6urJ98YyYkE7mHfGJyx0a+jxnZDti2selILHhDO76wCEYvnG2a9XinmE/dFjkrRgiACUSSaYAnwzbSqxEGQadY58joJsocmFiPiBY7Vl0oKcZOB4+GXZlN0i6ibiEQHXw1E9hjiWls5+ErlIClazy+aASfExxacUAzLSc55iXkg== Received: from DS7PR03CA0201.namprd03.prod.outlook.com (2603:10b6:5:3b6::26) by DM6PR12MB3033.namprd12.prod.outlook.com (2603:10b6:5:11e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 01:13:06 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::95) by DS7PR03CA0201.outlook.office365.com (2603:10b6:5:3b6::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25 via Frontend Transport; Thu, 17 Mar 2022 01:13:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:05 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:04 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:04 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:13:02 -0700 To: Date: Thu, 17 Mar 2022 09:12:45 +0800 Message-ID: <20220317011249.46787-5-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 827a9fa3-4527-4e20-dfbd-08da07b34a81 X-MS-TrafficTypeDiagnostic: DM6PR12MB3033:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8WdAmA6LqSDe+X7ISLc5wn/IO9Z1MIarHFFPbB/grr4S+SwzIkuetZa6Zdy0Z0uUSgPRgsT/r8Csfjupf08ptJRib/HM3V4hRBdMkQBfGvtwk41pA+DiSVTl8HEiLcbDhtN27EVi/YMXjtIdAFMx3NYSrWqsh2aWmCgk//UdjAynRvFtV6l4hnpay2VhjFoPy2OPAcTiRYeIxTiB/mPXWvUmsdg4197dT9yskAGCxW5KlogBlE3JoVkvBNC4iNJyRxVA5840ir4NexAG6w44rTQzIdWmRSV8aVM5+Dk57oiJCP3un3o80nekSwrioFM4Iwufsw7eUWXZ4aTiHBTm20afptOAmNzaTq9WBK3wDdKuH3c9hNb8RAPe19wJLEtRKFBp5TKQ+h1aHngKE+cGE23hBG9Q9wXmpGY2B1Xy5tEvPBAuAaIk1B5M03G3jSIHA3mOpOnl0COmv1S2tbfiGWOEzHBa7qnFavhpPSt8TaJe4YCvaJmHDmF/DK53mEB6E6TTD2pmFfv8uHCVl32m2yYmh9fZ8xbsd7aM9EDX+zUqrHHsjRoTwcB316dK6lTtAJ+heGZM2s64iVbJSUWID/9RS5qKoZi4ITOCsdcuK9pEQbenmrYHy4mA6GNZSYDe8gZ2398BnflvjQRJZDPo7TM7wNWeJd4rKe2qX95ZtK2xjzrrb4dB7TWEFxdyPq8Fo5FQhdT4aw3rfLvjjKBtsos83U7zRk5NtTo0ssx21js3tceCxGjv7O43YmOk58vg X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(47076005)(83380400001)(54906003)(6916009)(36860700001)(316002)(36756003)(2906002)(30864003)(336012)(1076003)(40460700003)(107886003)(8676002)(426003)(86362001)(26005)(186003)(70206006)(6666004)(70586007)(356005)(4326008)(2616005)(82310400004)(81166007)(508600001)(5660300002)(8936002)(36900700001)(473944003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:05.5193 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 827a9fa3-4527-4e20-dfbd-08da07b34a81 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3033 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 4/8] netdev-offload-tc: Introduce group ID management API 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading sample action to TC, userspace creates a unique ID to map sFlow action and tunnel info and passes this ID to kernel instead of the sFlow info. psample will send this ID and sampled packet to userspace. Using the ID, userspace can recover the sFlow info and send sampled packet to the right sFlow monitoring host. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- lib/dpif-offload-provider.h | 17 +++ lib/netdev-offload-tc.c | 246 +++++++++++++++++++++++++++++++++++- lib/netdev-offload.h | 2 + lib/tc.h | 1 + 4 files changed, 260 insertions(+), 6 deletions(-) diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h index 3b94740df..af49eedb9 100644 --- a/lib/dpif-offload-provider.h +++ b/lib/dpif-offload-provider.h @@ -17,9 +17,26 @@ #ifndef DPIF_OFFLOAD_PROVIDER_H #define DPIF_OFFLOAD_PROVIDER_H +#include "netlink-protocol.h" +#include "openvswitch/packets.h" +#include "openvswitch/types.h" + struct dpif; struct dpif_offload_sflow; +/* When offloading sample action, userspace creates a unique ID to map + * sFlow action and tunnel info and passes this ID to datapath instead + * of the sFlow info. Datapath will send this ID and sampled packet to + * userspace. Using the ID, userspace can recover the sFlow info and send + * sampled packet to the right sFlow monitoring host. + */ +struct dpif_sflow_attr { + const struct nlattr *action; /* SFlow action. */ + const struct nlattr *userdata; /* Struct user_action_cookie. */ + struct flow_tnl *tunnel; /* Tunnel info. */ + ovs_u128 ufid; /* Flow ufid. */ +}; + /* Datapath interface offload structure, to be defined by each implementation * of a datapath interface. */ diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 93e89e88c..acc1dfdff 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -40,6 +40,7 @@ #include "unaligned.h" #include "util.h" #include "dpif-provider.h" +#include "cmap.h" VLOG_DEFINE_THIS_MODULE(netdev_offload_tc); @@ -62,6 +63,233 @@ struct chain_node { uint32_t chain; }; +/* This maps a psample group ID to struct dpif_sflow_attr for sFlow */ +struct sgid_node { + struct ovs_list exp_node OVS_GUARDED; + struct cmap_node metadata_node; + struct cmap_node id_node; + struct ovs_refcount refcount; + uint32_t hash; + uint32_t id; + const struct dpif_sflow_attr sflow; +}; + +static struct ovs_rwlock sgid_rwlock = OVS_RWLOCK_INITIALIZER; +static struct cmap sgid_map = CMAP_INITIALIZER; +static struct cmap sgid_metadata_map = CMAP_INITIALIZER; +static struct ovs_list sgid_expiring OVS_GUARDED_BY(sgid_rwlock) + = OVS_LIST_INITIALIZER(&sgid_expiring); +static uint32_t next_sample_group_id OVS_GUARDED_BY(sgid_rwlock) = 1; + +static void +sgid_node_free(struct sgid_node *node) +{ + free(node->sflow.tunnel); + free(CONST_CAST(void *, node->sflow.action)); + free(CONST_CAST(void *, node->sflow.userdata)); + free(node); +} + +/* Lockless RCU protected lookup. If node is needed accross RCU quiescent + * state, caller should copy the contents. */ +static const struct sgid_node * +sgid_find(uint32_t id) +{ + const struct cmap_node *node = cmap_find(&sgid_map, id); + + return node ? CONTAINER_OF(node, const struct sgid_node, id_node) : NULL; +} + +const struct dpif_sflow_attr * +dpif_offload_sflow_attr_find(uint32_t id) +{ + const struct sgid_node *node; + + node = sgid_find(id); + if (!node) { + return NULL; + } + + return &node->sflow; +} + +static uint32_t +dpif_sflow_attr_hash(const struct dpif_sflow_attr *sflow) +{ + return hash_bytes(&sflow->ufid, sizeof sflow->ufid, 0); +} + +static bool +dpif_sflow_attr_equal(const struct dpif_sflow_attr *a, + const struct dpif_sflow_attr *b) +{ + if (!ovs_u128_equals(a->ufid, b->ufid)) { + return false; + } + if (!a->action || !b->action) { + return false; + } + if (a->action->nla_len != b->action->nla_len + || memcmp(a->action, b->action, a->action->nla_len)) { + return false; + } + if (!a->tunnel && !b->tunnel) { + return true; + } + if (!a->tunnel || !b->tunnel) { + return false; + } + + return !memcmp(a->tunnel, b->tunnel, sizeof *a->tunnel); +} + +/* Lockless RCU protected lookup. If node is needed accross RCU quiescent + * state, caller should take a reference. */ +static struct sgid_node * +sgid_find_equal(const struct dpif_sflow_attr *target, uint32_t hash) +{ + struct sgid_node *node; + + CMAP_FOR_EACH_WITH_HASH (node, metadata_node, hash, &sgid_metadata_map) { + if (dpif_sflow_attr_equal(&node->sflow, target)) { + return node; + } + } + return NULL; +} + +static struct sgid_node * +sgid_ref_equal(const struct dpif_sflow_attr *target, uint32_t hash) +{ + struct sgid_node *node; + + do { + node = sgid_find_equal(target, hash); + /* Try again if the node was released before we get the reference. */ + } while (node && !ovs_refcount_try_ref_rcu(&node->refcount)); + + return node; +} + +static void +dpif_sflow_attr_clone(struct dpif_sflow_attr *new, + const struct dpif_sflow_attr *old) +{ + new->action = xmemdup(old->action, old->action->nla_len); + new->userdata = xmemdup(old->userdata, old->userdata->nla_len); + new->tunnel = old->tunnel + ? xmemdup(old->tunnel, sizeof *old->tunnel) + : NULL; + new->ufid = old->ufid; +} + +/* We use the id as the hash value, which works due to cmap internal rehashing. + * We also only insert nodes with unique IDs, so all possible hash collisions + * remain internal to the cmap. */ +static struct sgid_node * +sgid_find__(uint32_t id) + OVS_REQUIRES(sgid_rwlock) +{ + struct cmap_node *node = cmap_find_protected(&sgid_map, id); + + return node ? CONTAINER_OF(node, struct sgid_node, id_node) : NULL; +} + +/* Allocate a unique group id for the given set of flow metadata. The id + * space is 2^^32, but if looping too many times, we still can't find a + * free one, that means something is wrong, return NULL. + */ +#define SGID_ALLOC_RETRY_MAX 8192 +static struct sgid_node * +sgid_alloc__(const struct dpif_sflow_attr *sflow, uint32_t hash) +{ + struct sgid_node *node = xzalloc(sizeof *node); + int i = 0; + + node->hash = hash; + ovs_refcount_init(&node->refcount); + dpif_sflow_attr_clone(CONST_CAST(struct dpif_sflow_attr *, + &node->sflow), sflow); + + ovs_rwlock_wrlock(&sgid_rwlock); + for (;;) { + node->id = next_sample_group_id++; + if (OVS_UNLIKELY(!node->id)) { + next_sample_group_id = 1; + node->id = next_sample_group_id++; + } + /* Find if the id is free. */ + if (OVS_LIKELY(!sgid_find__(node->id))) { + break; + } + if (++i == SGID_ALLOC_RETRY_MAX) { + VLOG_ERR("Can't find a free group ID after %d retries", i); + ovs_rwlock_unlock(&sgid_rwlock); + sgid_node_free(node); + return NULL; + } + } + cmap_insert(&sgid_map, &node->id_node, node->id); + cmap_insert(&sgid_metadata_map, &node->metadata_node, node->hash); + ovs_rwlock_unlock(&sgid_rwlock); + return node; +} + +/* Allocate a unique group id for the given set of flow metadata and + optional actions. */ +static uint32_t +sgid_alloc_ctx(const struct dpif_sflow_attr *sflow) +{ + uint32_t hash = dpif_sflow_attr_hash(sflow); + struct sgid_node *node = sgid_ref_equal(sflow, hash); + + if (!node) { + node = sgid_alloc__(sflow, hash); + } + + return node ? node->id : 0; +} + +static void +sgid_node_unref(const struct sgid_node *node_) + OVS_EXCLUDED(sgid_rwlock) +{ + struct sgid_node *node = CONST_CAST(struct sgid_node *, node_); + + ovs_rwlock_wrlock(&sgid_rwlock); + if (node && ovs_refcount_unref(&node->refcount) == 1) { + cmap_remove(&sgid_metadata_map, &node->metadata_node, node->hash); + cmap_remove(&sgid_map, &node->id_node, node->id); + ovsrcu_postpone(sgid_node_free, node); + } + ovs_rwlock_unlock(&sgid_rwlock); +} + +static void +sgid_free(uint32_t id) +{ + const struct sgid_node *node; + + if (!id) { + return; + } + + node = sgid_find(id); + if (node) { + sgid_node_unref(node); + } else { + VLOG_ERR("Freeing nonexistent group ID: %"PRIu32, id); + } +} + +static int +del_filter_and_sgid(struct tcf_id *id) +{ + sgid_free(id->sample_group_id); + id->sample_group_id = 0; + return tc_del_filter(id); +} + static bool is_internal_port(const char *type) { @@ -198,13 +426,13 @@ del_ufid_tc_mapping(const ovs_u128 *ufid) ovs_mutex_unlock(&ufid_lock); } -/* Wrapper function to delete filter and ufid tc mapping */ +/* Wrapper function to delete filter, sgid and ufid tc mapping */ static int -del_filter_and_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid) +del_filter_sgid_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid) { int err; - err = tc_del_filter(id); + err = del_filter_and_sgid(id); if (!err) { del_ufid_tc_mapping(ufid); } @@ -426,7 +654,7 @@ netdev_tc_flow_flush(struct netdev *netdev) continue; } - err = tc_del_filter(&data->id); + err = del_filter_and_sgid(&data->id); if (!err) { del_ufid_tc_mapping_unlocked(&data->ufid); } @@ -1913,6 +2141,11 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) { + struct dpif_sflow_attr sflow_attr; + + memset(&sflow_attr, 0, sizeof sflow_attr); + sgid_alloc_ctx(&sflow_attr); } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); @@ -1928,7 +2161,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, if (get_ufid_tc_mapping(ufid, &id) == 0) { VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", id.handle, id.prio); - info->tc_modify_flow_deleted = !del_filter_and_ufid_mapping(&id, ufid); + info->tc_modify_flow_deleted = !del_filter_sgid_ufid_mapping(&id, + ufid); } prio = get_prio_for_tc_flower(&flower); @@ -2015,7 +2249,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, } } - error = del_filter_and_ufid_mapping(&id, ufid); + error = del_filter_sgid_ufid_mapping(&id, ufid); return error; } diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 8237a85dd..be19f33e6 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -158,6 +158,8 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, int netdev_ports_get_n_flows(const char *dpif_type, odp_port_t port_no, uint64_t *n_flows); +const struct dpif_sflow_attr *dpif_offload_sflow_attr_find(uint32_t id); + #ifdef __cplusplus } #endif diff --git a/lib/tc.h b/lib/tc.h index d6cdddd16..2bcff80b9 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -288,6 +288,7 @@ struct tcf_id { uint32_t chain; uint16_t prio; uint32_t handle; + uint32_t sample_group_id; }; static inline struct tcf_id From patchwork Thu Mar 17 01:12:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606339 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HH1nlxF1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 4KJq0D2MHcz9sCD for ; Thu, 17 Mar 2022 12:13:32 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 3E70380C38; Thu, 17 Mar 2022 01:13:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org 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 fKR5G2iFSydH; Thu, 17 Mar 2022 01:13:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 683AA8477A; Thu, 17 Mar 2022 01:13:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3406CC0012; Thu, 17 Mar 2022 01:13:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 10F9FC008B for ; Thu, 17 Mar 2022 01:13:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 2454E8475A for ; Thu, 17 Mar 2022 01:13:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org 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 DGK60rG7Ir_U for ; Thu, 17 Mar 2022 01:13:11 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20627.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::627]) by smtp1.osuosl.org (Postfix) with ESMTPS id A4E7684752 for ; Thu, 17 Mar 2022 01:13:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c6O6NkWb/9hueYsg4XPdOuVfVEZeIP5nj3uwwcpGZaFenVv37RF5T5D8C6N7yYO8ec0NdeoT/5QmW78/E9XnaEpdctpDFPDdrWU4G2Zk3OvJt5exLbjxmQsFNGUkyabsN0FTHTWMv7lk1pQmQLI1tcy4GIn6WQgOejyeH9ph0XUNCTL//AD+Cv+9N8prylPsy2kscH0btlCzgyB4HTuVrI+vooe2w0z4RgvXcIcdnLeSkxf+rJM/To8VanZ07Sw1/tu7ypAIUEHKn8UZCPDvzrv8UHHeRGEyZGWGxcxyGH37ryB+1Sru/4CQ6B4qT0QPpWfLDQvr0u4NOloeA1zgGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DxaRH0p0TJNSwQbjiSAsK32e5srXD2ZCAaxnuoh16UA=; b=K7iOgaAoSXnDi0xGtzwREFjBiP0SlJVfeoAJj1O1Ge7OO2cIoJotILEJeYFkNGnD4oBeC6yhPCHmaziWmRpkxtkKzVOBvRK5qC2FW/0x+PJrgqM7a8oAe9H4h6tnHZQ9HTYBSJzyJq+3ciG6Ggt/NmAderWLJTwCR8su+bcKgTI6EZSaNGJTSnR7fAayWcHn719fsvuhAnZ3ANEFuAjriXqL4ChBdFcK9aAxz6VOhUoh6uC5O0gCQ2qNo5ysRS9MaNnEAAj6aao+LLbaelkjk4iwcvuPaHHN/NNwB10eRPd6acKf1d5REEYKqA7EX/OaufH3mNZLcriXJ5AymmRsvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DxaRH0p0TJNSwQbjiSAsK32e5srXD2ZCAaxnuoh16UA=; b=HH1nlxF163G+RacX28qdCSjprDiuNaBVj4OYWkAYkC5qbOoQYSjG6vIQm66FHM6MKeAKm9vAbP2LAj1QTtQp5MWkRmepzecKNnLjpMAFlBu77Gwyddpp9ljWxRSClaoeyqD1CSmt8I+yK0qpoKsul3yzgSRclCPmRQa8z50bLbwFN8Sn6C443T5Gwo4pYrdU9QoaaZ7qKC4r2S06U9YYaoW+uYPC2hTLdj8vLClycyLi7Ho3OdgRxVKY7/dZT/hXerSY4U5YLXl1n20n9IlAOLj8ISrAnFVDbuN+NgLXf1Im5/V3ZkuohuqUclA5mtVZTFo9sga//CLBrqPPTa4CBw== Received: from BN0PR04CA0142.namprd04.prod.outlook.com (2603:10b6:408:ed::27) by DM6PR12MB3900.namprd12.prod.outlook.com (2603:10b6:5:1c9::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 01:13:08 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::cc) by BN0PR04CA0142.outlook.office365.com (2603:10b6:408:ed::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 17 Mar 2022 01:13:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:08 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:07 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:06 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:13:04 -0700 To: Date: Thu, 17 Mar 2022 09:12:46 +0800 Message-ID: <20220317011249.46787-6-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1dd76d4b-10fb-4abe-a5b5-08da07b34c27 X-MS-TrafficTypeDiagnostic: DM6PR12MB3900:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wk/ZFE0n2nGyqKzjgZieaEtl/cZiFokyUqByugxWAHlP6QnplrjW/gPSEjsQY4CgD5UbvjByvKy2EfjdkH/gW8Tp23o6liMNlFty/Glr1wDExxaixD5UFWFUFQq77D5tCpoh9Iip3fZqUVew6X6djdfe9/aU6vFG0esMuH3lyoEWQ+raSzuVZSTf7iLJvCfJUGcKuWOGE7w2sbLK53MLiAVhIRwidZ/Y0Z1bQ78bjmSucffEDo1a2YNVwievp/1sMfLZO9Lvbdx45C5H+YNtaGJpficvqOADYGaz818NTCx6fqkEZeytomhOPT216HDBGGJxUhx/t2XhPfAPS+qJQDL5QG2JbKsYEWb6d5r4LadyeYqxGgFTkmF2ejoYPKz9ogLhEY53lRTUBCvdwLsw+FxpN3X5bv/KZ8rxO5vIkhdDPY3cPMNW6+eDlqUn5tRYcMTaQAmczB6zuIoyrLjP65CEZy0DqowNiu9nZXOt/gft8A0CHFrH0rou0ev9b4kX3fP9D3jH7uqtNp6EtW9oKX7FKA/kz3TDNU6gw0PZJYWd87wp1gfE2gcpYtxbAkFaVZwaMy9xuHB7XVi+hn3K7FjombDyngUmkxbluqZS77g23I/jdlxeR+1niQxih965jepqdm1e7k/XYBO9h+rDaDxMup6Qo1dAvVKZCZrHRp/0yccYcltcGy/PG587YLHODKH6DoKnH+K23jGoJh66CUL2/3srmhHZ6nRQX42ITKML5BoEqfOVlerdgK311NORPZ63ZSicLWxgJRLtsGoy0pTsC4Tk+bIpmgh33NXsjnw= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(1076003)(2616005)(426003)(86362001)(186003)(336012)(26005)(36860700001)(70206006)(70586007)(4326008)(8676002)(107886003)(47076005)(82310400004)(83380400001)(5660300002)(356005)(508600001)(966005)(30864003)(81166007)(8936002)(40460700003)(6916009)(6666004)(54906003)(316002)(2906002)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:08.2209 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1dd76d4b-10fb-4abe-a5b5-08da07b34c27 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3900 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 5/8] dpif-offload-netlink: Implement dpif-offload-provider API 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Implement dpif-offload API for netlink datapath. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein --- lib/automake.mk | 1 + lib/dpif-netdev.c | 3 +- lib/dpif-netlink.c | 20 +++- lib/dpif-offload-netlink.c | 221 ++++++++++++++++++++++++++++++++++++ lib/dpif-offload-provider.h | 25 +++- lib/dpif-offload.c | 104 +++++++++++++++++ lib/dpif-provider.h | 6 +- lib/dpif.c | 3 +- 8 files changed, 375 insertions(+), 8 deletions(-) create mode 100644 lib/dpif-offload-netlink.c diff --git a/lib/automake.mk b/lib/automake.mk index 781fba47a..b4cff234a 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -453,6 +453,7 @@ lib_libopenvswitch_la_SOURCES += \ lib/dpif-netlink.h \ lib/dpif-netlink-rtnl.c \ lib/dpif-netlink-rtnl.h \ + lib/dpif-offload-netlink.c \ lib/if-notifier.c \ lib/netdev-linux.c \ lib/netdev-linux.h \ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 9f35713ef..b0ace7f1e 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1684,7 +1684,8 @@ create_dpif_netdev(struct dp_netdev *dp) ovs_refcount_ref(&dp->ref_cnt); dpif = xmalloc(sizeof *dpif); - dpif_init(&dpif->dpif, dp->class, dp->name, netflow_id >> 8, netflow_id); + dpif_init(&dpif->dpif, dp->class, NULL, dp->name, netflow_id >> 8, + netflow_id); dpif->dp = dp; dpif->last_port_seq = seq_read(dp->port_seq); diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 71e35ccdd..f00159063 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -455,20 +455,33 @@ dpif_netlink_open(const struct dpif_class *class OVS_UNUSED, const char *name, static int open_dpif(const struct dpif_netlink_dp *dp, struct dpif **dpifp) { + struct registered_dpif_offload_class *registered_offload_class; + const char *type = dpif_netlink_class.type; struct dpif_netlink *dpif; + int error = 0; dpif = xzalloc(sizeof *dpif); dpif->port_notifier = NULL; fat_rwlock_init(&dpif->upcall_lock); - dpif_init(&dpif->dpif, &dpif_netlink_class, dp->name, - dp->dp_ifindex, dp->dp_ifindex); + dp_offload_initialize(); + registered_offload_class = dp_offload_class_lookup(type); + if (!registered_offload_class) { + VLOG_WARN("Could not find offload class for type %s", type); + error = EAFNOSUPPORT; + goto exit; + } + + dpif_init(&dpif->dpif, &dpif_netlink_class, + registered_offload_class->offload_class, + dp->name, dp->dp_ifindex, dp->dp_ifindex); dpif->dp_ifindex = dp->dp_ifindex; dpif->user_features = dp->user_features; *dpifp = &dpif->dpif; - return 0; +exit: + return error; } #ifdef _WIN32 @@ -713,6 +726,7 @@ dpif_netlink_close(struct dpif *dpif_) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); + dpif_offload_close(dpif_); nl_sock_destroy(dpif->port_notifier); fat_rwlock_wrlock(&dpif->upcall_lock); diff --git a/lib/dpif-offload-netlink.c b/lib/dpif-offload-netlink.c new file mode 100644 index 000000000..02aea7e2d --- /dev/null +++ b/lib/dpif-offload-netlink.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "dpif-offload-provider.h" +#include "netdev-offload.h" +#include "netlink-protocol.h" +#include "netlink-socket.h" +#include "openvswitch/vlog.h" + +VLOG_DEFINE_THIS_MODULE(dpif_offload_netlink); + +static struct nl_sock *psample_sock; +static int psample_family; + +/* Receive psample netlink message and save the attributes. */ +struct offload_psample { + struct nlattr *packet; /* Packet data. */ + int dp_group_id; /* Mapping id for sFlow offload. */ + int iifindex; /* Input ifindex. */ +}; + +/* In order to keep compatibility with kernels without psample module, + * return success even if psample is not initialized successfully. */ +static void +psample_init(void) +{ + unsigned int psample_mcgroup; + int err; + + if (!netdev_is_flow_api_enabled()) { + VLOG_DBG("Flow API is not enabled."); + return; + } + + if (psample_sock) { + VLOG_DBG("Psample socket is already initialized."); + return; + } + + err = nl_lookup_genl_family(PSAMPLE_GENL_NAME, + &psample_family); + if (err) { + VLOG_WARN("Generic Netlink family '%s' does not exist: %s\n" + "Please make sure the kernel module psample is loaded.", + PSAMPLE_GENL_NAME, ovs_strerror(err)); + return; + } + + err = nl_lookup_genl_mcgroup(PSAMPLE_GENL_NAME, + PSAMPLE_NL_MCGRP_SAMPLE_NAME, + &psample_mcgroup); + if (err) { + VLOG_WARN("Failed to join Netlink multicast group '%s': %s", + PSAMPLE_NL_MCGRP_SAMPLE_NAME, ovs_strerror(err)); + return; + } + + err = nl_sock_create(NETLINK_GENERIC, &psample_sock); + if (err) { + VLOG_WARN("Failed to create psample socket: %s", ovs_strerror(err)); + return; + } + + err = nl_sock_join_mcgroup(psample_sock, psample_mcgroup); + if (err) { + VLOG_WARN("Failed to join psample mcgroup: %s", ovs_strerror(err)); + nl_sock_destroy(psample_sock); + psample_sock = NULL; + return; + } +} + +static int +dpif_offload_netlink_init(void) +{ + psample_init(); + + return 0; +} + +static void +psample_destroy(void) +{ + if (!psample_sock) { + return; + } + + nl_sock_destroy(psample_sock); + psample_sock = NULL; +} + +static void +dpif_offload_netlink_destroy(void) +{ + psample_destroy(); +} + +static void +dpif_offload_netlink_sflow_recv_wait(void) +{ + if (psample_sock) { + nl_sock_wait(psample_sock, POLLIN); + } +} + +static int +psample_from_ofpbuf(struct offload_psample *psample, + const struct ofpbuf *buf) +{ + static const struct nl_policy ovs_psample_policy[] = { + [PSAMPLE_ATTR_IIFINDEX] = { .type = NL_A_U16 }, + [PSAMPLE_ATTR_SAMPLE_GROUP] = { .type = NL_A_U32 }, + [PSAMPLE_ATTR_GROUP_SEQ] = { .type = NL_A_U32 }, + [PSAMPLE_ATTR_DATA] = { .type = NL_A_UNSPEC }, + }; + struct nlattr *a[ARRAY_SIZE(ovs_psample_policy)]; + struct genlmsghdr *genl; + struct nlmsghdr *nlmsg; + struct ofpbuf b; + + b = ofpbuf_const_initializer(buf->data, buf->size); + nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg); + genl = ofpbuf_try_pull(&b, sizeof *genl); + if (!nlmsg || !genl || nlmsg->nlmsg_type != psample_family + || !nl_policy_parse(&b, 0, ovs_psample_policy, a, + ARRAY_SIZE(ovs_psample_policy))) { + return EINVAL; + } + + psample->iifindex = nl_attr_get_u16(a[PSAMPLE_ATTR_IIFINDEX]); + psample->dp_group_id = nl_attr_get_u32(a[PSAMPLE_ATTR_SAMPLE_GROUP]); + psample->packet = a[PSAMPLE_ATTR_DATA]; + + return 0; +} + +static int +psample_parse_packet(struct offload_psample *psample, + struct dpif_offload_sflow *sflow) +{ + dp_packet_use_stub(&sflow->packet, + CONST_CAST(struct nlattr *, + nl_attr_get(psample->packet)) - 1, + nl_attr_get_size(psample->packet) + + sizeof(struct nlattr)); + dp_packet_set_data(&sflow->packet, + (char *) dp_packet_data(&sflow->packet) + + sizeof(struct nlattr)); + dp_packet_set_size(&sflow->packet, nl_attr_get_size(psample->packet)); + + sflow->attr = dpif_offload_sflow_attr_find(psample->dp_group_id); + if (!sflow->attr) { + return ENOENT; + } + sflow->iifindex = psample->iifindex; + + return 0; +} + +static int +dpif_offload_netlink_sflow_recv(struct dpif_offload_sflow *sflow) +{ + if (!psample_sock) { + return ENOENT; + } + + for (;;) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + struct offload_psample psample; + struct ofpbuf buf; + int error; + + ofpbuf_use_stub(&buf, sflow->buf_stub, sizeof sflow->buf_stub); + error = nl_sock_recv(psample_sock, &buf, NULL, false); + + if (!error) { + error = psample_from_ofpbuf(&psample, &buf); + if (!error) { + ofpbuf_uninit(&buf); + error = psample_parse_packet(&psample, sflow); + return error; + } + } else if (error != EAGAIN) { + VLOG_WARN_RL(&rl, "Error reading or parsing netlink (%s).", + ovs_strerror(error)); + nl_sock_drain(psample_sock); + error = ENOBUFS; + } + + ofpbuf_uninit(&buf); + if (error) { + return error; + } + } +} + +const struct dpif_offload_class dpif_offload_netlink_class = { + .type = "system", + .init = dpif_offload_netlink_init, + .destroy = dpif_offload_netlink_destroy, + .sflow_recv_wait = dpif_offload_netlink_sflow_recv_wait, + .sflow_recv = dpif_offload_netlink_sflow_recv, +}; diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h index af49eedb9..51a374868 100644 --- a/lib/dpif-offload-provider.h +++ b/lib/dpif-offload-provider.h @@ -17,12 +17,20 @@ #ifndef DPIF_OFFLOAD_PROVIDER_H #define DPIF_OFFLOAD_PROVIDER_H +#include "dp-packet.h" #include "netlink-protocol.h" #include "openvswitch/packets.h" #include "openvswitch/types.h" struct dpif; -struct dpif_offload_sflow; +struct registered_dpif_offload_class { + const struct dpif_offload_class *offload_class; + int refcount; +}; + +#ifdef __linux__ +extern const struct dpif_offload_class dpif_offload_netlink_class; +#endif /* When offloading sample action, userspace creates a unique ID to map * sFlow action and tunnel info and passes this ID to datapath instead @@ -37,6 +45,14 @@ struct dpif_sflow_attr { ovs_u128 ufid; /* Flow ufid. */ }; +/* Parse the specific dpif message to sFlow. So OVS can process it. */ +struct dpif_offload_sflow { + struct dp_packet packet; /* Packet data. */ + uint64_t buf_stub[4096 / 8]; /* Buffer stub for packet data. */ + uint32_t iifindex; /* Input ifindex. */ + const struct dpif_sflow_attr *attr; /* SFlow attribute. */ +}; + /* Datapath interface offload structure, to be defined by each implementation * of a datapath interface. */ @@ -62,6 +78,13 @@ struct dpif_offload_class { int (*sflow_recv)(struct dpif_offload_sflow *sflow); }; +void dp_offload_initialize(void); +void dpif_offload_close(struct dpif *); + +int dp_offload_register_provider(const struct dpif_offload_class *); +void dp_offload_class_unref(struct registered_dpif_offload_class *rc); +struct registered_dpif_offload_class *dp_offload_class_lookup(const char *); + void dpif_offload_sflow_recv_wait(const struct dpif *dpif); int dpif_offload_sflow_recv(const struct dpif *dpif, struct dpif_offload_sflow *sflow); diff --git a/lib/dpif-offload.c b/lib/dpif-offload.c index f2bf3e634..bea6a9e95 100644 --- a/lib/dpif-offload.c +++ b/lib/dpif-offload.c @@ -18,6 +18,110 @@ #include #include "dpif-provider.h" +#include "openvswitch/shash.h" +#include "openvswitch/vlog.h" + +VLOG_DEFINE_THIS_MODULE(dpif_offload); + +static const struct dpif_offload_class *base_dpif_offload_classes[] = { +#if defined(__linux__) + &dpif_offload_netlink_class, +#endif +}; + +static struct shash dpif_offload_classes = + SHASH_INITIALIZER(&dpif_offload_classes); + +/* Protects 'dpif_offload_classes', including the refcount. */ +static struct ovs_mutex dpif_offload_mutex = OVS_MUTEX_INITIALIZER; + +void +dp_offload_initialize(void) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + + if (ovsthread_once_start(&once)) { + for (int i = 0; i < ARRAY_SIZE(base_dpif_offload_classes); i++) { + dp_offload_register_provider(base_dpif_offload_classes[i]); + } + ovsthread_once_done(&once); + } +} + +static int +dp_offload_register_provider__(const struct dpif_offload_class *new_class) + OVS_REQUIRES(dpif_offload_mutex) +{ + struct registered_dpif_offload_class *registered_class; + int error; + + if (shash_find(&dpif_offload_classes, new_class->type)) { + VLOG_WARN("Attempted to register duplicate datapath offload " + "provider: %s", new_class->type); + return EEXIST; + } + + error = new_class->init ? new_class->init() : 0; + if (error) { + VLOG_WARN("Failed to initialize %s datapath offload class: %s", + new_class->type, ovs_strerror(error)); + return error; + } + + registered_class = xmalloc(sizeof *registered_class); + registered_class->offload_class = new_class; + registered_class->refcount = 0; + + shash_add(&dpif_offload_classes, new_class->type, registered_class); + + return 0; +} + +void dpif_offload_close(struct dpif *dpif) +{ + if (dpif->offload_class) { + struct registered_dpif_offload_class *rc; + + rc = shash_find_data(&dpif_offload_classes, dpif->offload_class->type); + dp_offload_class_unref(rc); + } +} + +int +dp_offload_register_provider(const struct dpif_offload_class *new_class) +{ + int error; + + ovs_mutex_lock(&dpif_offload_mutex); + error = dp_offload_register_provider__(new_class); + ovs_mutex_unlock(&dpif_offload_mutex); + + return error; +} + +void +dp_offload_class_unref(struct registered_dpif_offload_class *rc) +{ + ovs_mutex_lock(&dpif_offload_mutex); + ovs_assert(rc->refcount); + rc->refcount--; + ovs_mutex_unlock(&dpif_offload_mutex); +} + +struct registered_dpif_offload_class * +dp_offload_class_lookup(const char *type) +{ + struct registered_dpif_offload_class *rc; + + ovs_mutex_lock(&dpif_offload_mutex); + rc = shash_find_data(&dpif_offload_classes, type); + if (rc) { + rc->refcount++; + } + ovs_mutex_unlock(&dpif_offload_mutex); + + return rc; +} void dpif_offload_sflow_recv_wait(const struct dpif *dpif) diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 99009722a..c8ed385a1 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -47,8 +47,10 @@ struct dpif { struct dpif_ipf_status; struct ipf_dump_ctx; -void dpif_init(struct dpif *, const struct dpif_class *, const char *name, - uint8_t netflow_engine_type, uint8_t netflow_engine_id); +void dpif_init(struct dpif *, const struct dpif_class *, + const struct dpif_offload_class *offload_class, + const char *name, uint8_t netflow_engine_type, + uint8_t netflow_engine_id); void dpif_uninit(struct dpif *dpif, bool close); static inline void dpif_assert_class(const struct dpif *dpif, diff --git a/lib/dpif.c b/lib/dpif.c index 40f5fe446..5fb8ee0a7 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1699,10 +1699,11 @@ dpif_queue_to_priority(const struct dpif *dpif, uint32_t queue_id, void dpif_init(struct dpif *dpif, const struct dpif_class *dpif_class, - const char *name, + const struct dpif_offload_class *offload_class, const char *name, uint8_t netflow_engine_type, uint8_t netflow_engine_id) { dpif->dpif_class = dpif_class; + dpif->offload_class = offload_class; dpif->base_name = xstrdup(name); dpif->full_name = xasprintf("%s@%s", dpif_class->type, name); dpif->netflow_engine_type = netflow_engine_type; From patchwork Thu Mar 17 01:12:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606340 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=nWIkQr0r; 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 4KJq0K1v0Dz9sCD for ; Thu, 17 Mar 2022 12:13:37 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 76776418A6; Thu, 17 Mar 2022 01:13:34 +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 HN6DSHeuKSo8; Thu, 17 Mar 2022 01:13:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 306E441871; Thu, 17 Mar 2022 01:13:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F2BECC0012; Thu, 17 Mar 2022 01:13:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 137CDC0012 for ; Thu, 17 Mar 2022 01:13:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 8650D40AFD for ; Thu, 17 Mar 2022 01:13:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R1T92L6A1VDJ for ; Thu, 17 Mar 2022 01:13:16 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2062d.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::62d]) by smtp2.osuosl.org (Postfix) with ESMTPS id 6C00840B12 for ; Thu, 17 Mar 2022 01:13:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iw0w+ghVojcqNwAoke2G3suBQ3A1oqHdB0PstJszOV3UQGTstSd2LVGpF9DjupReIHQ27TZCmLpP7hIRXVJAE+YSwK0Dzo3i6P7YErdqPKlAYK0QqlbXKP7mH7HqbeiyYWqaVfs0/+SsOCgUbweiLzNrFVsockXBtw3jPS+H4hocZUgqUhWStiQP775LiPY4Z1RNqabu8djOh+U4VnBKWE/7As0PmiQtiv8piYZSBvM9cloX6UxKVeveGoMTz07XE/CSg+CcmayzDvpaFiGr5jFSSoQVFhH1VIH0na17PsaZG7b13BIIvB0AI9a9284MBk+HryvQXoVOA0J4/Dr3qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zltD8sQWOnnfJN5Zcno3u0h1UE9o6NaYFKkgaXc35Pc=; b=OjEKvIFcSQoAxMaZG81VeYUvwhG35kONdagza8LYxUpR4uv0QRZj6nQ4b391z5MQEKhi2/C8AKaIoB2jAj+6mPc3eEvPijnPWh1e9SOECt+aSWSFCJql52+RzYF8fPcy7IBOfvGYudMwfOfaIp6nVCsaY34stiVNYvU3joM0G5DBwYqoPlldorJ+XIthuXiQPJA81aCPPLrWCgEHEDlF6WNVsXsnRvKS/F29U14Ciuyd3Z8SewRw5CnZsNEMpbQj838inkTK284HLWmEdyWUYmNd5lyUxSEjli7i/tuKeIlaAtlVnUK9LtpR6RhNYYq8Vk9E/hl77APodVPWHl8BkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zltD8sQWOnnfJN5Zcno3u0h1UE9o6NaYFKkgaXc35Pc=; b=nWIkQr0r1NezRhgEGnqezCLH1om4U4bEAuHseytp+ODu7DgUcsoAQi7ryRRwLq5CWFtNV0kYsbJcDCePTpg1rr/2OVQK29OWRdd4oDYEnc3BP21hRmmbdoTtbA/V6oHbwaSeJSfkqtOwP9eZJyALBMmzkb/eaZEy/R3XL4AxHfL4ydfI/MRQrlakZdXACHa5UNAjA+NTSpaGfzGYIlRBmZWwvM/VPQOTpbDKCmDSKY5Ad5hO59LoQVh0fN6z0LGLsYHHipOceUDyqnU+KT/R2JyoFYNE1Yz5caCuPeUsAeEKxuM+fCB/oXKHNMD/HsbAjMm9+z8BQLlYiv+upRrlaA== Received: from DM6PR14CA0055.namprd14.prod.outlook.com (2603:10b6:5:18f::32) by DM6PR12MB4449.namprd12.prod.outlook.com (2603:10b6:5:2a5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Thu, 17 Mar 2022 01:13:11 +0000 Received: from DM6NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::45) by DM6PR14CA0055.outlook.office365.com (2603:10b6:5:18f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.26 via Frontend Transport; Thu, 17 Mar 2022 01:13:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT013.mail.protection.outlook.com (10.13.173.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:10 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:09 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:09 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:13:06 -0700 To: Date: Thu, 17 Mar 2022 09:12:47 +0800 Message-ID: <20220317011249.46787-7-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 184f43b4-caa4-43b4-7fcd-08da07b34d6a X-MS-TrafficTypeDiagnostic: DM6PR12MB4449:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RNBXvRXxbZCBCqLFoZNThwr9J/llDSihUIbHOMCdt10ky47KhsIDZZou505TUVVjYK9uB5vtWfEx1PL0trVNdbo7pW8C0I+FGeIt9cp7o1jMcvOcAxKpYJGWbzP4NtqbDJYeVR9R6sJzl0bd7b8DRN1WSQkVFsp/EcvOSKKAV9xYO7/x6U+FcvN8nsSsix1pqJpk8mydRN4FZvEOQCfFZTE9cfHYekJI+2x20Cr5Zueu17NY0WNujeCBeZzePC/ZdCX4RDCqHCPDZtqpaTWU7OZzs37AUBU7LwnT9lNW+PrC7+AzLrjXWTnQx+6mM2FaXlTYhSRyPPiQ/zitw5XoqCnJ+niXxFo08pwJ1t55mREDfhF0XBWJusa8cUjGAj6/hnx7UvR/jwhktCZ1IjvsvdNs0rQx6fIr23fYuz9oK8FSFJUem981RIwNSwAMf/vpHeVXQZn8aClueWQZ0/rqp45UXS/hvs4szR3oCG4ZfDvt59GNaFFPznpk1ein3bkhD3RwdiFkAYyjIcpB/fXCbQAcxfEfugyuQUldjUsu4mWiSnYy3+m0fhCTtluRpkK6pawSjvEUFfuFS2vvb6EvkysCJppS8R3DjaUPLTthjXqakP47bnrU4oo6fhG3gYZgxKRvwaUYwJAJamM2QxpQu/+GpQcVuYeEQ66Vr3JuUqKYRnU2VnJ3gtNIs6zkCLHaMy8vF6C7HT9+S1vOVPUUnQ== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(2906002)(36756003)(47076005)(70206006)(2616005)(70586007)(1076003)(107886003)(82310400004)(36860700001)(336012)(426003)(186003)(8676002)(26005)(356005)(54906003)(8936002)(6916009)(86362001)(83380400001)(6666004)(81166007)(4326008)(5660300002)(316002)(40460700003)(508600001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:10.4462 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 184f43b4-caa4-43b4-7fcd-08da07b34d6a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4449 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 6/8] ofproto: Introduce API to process sFlow offload packet 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Process sFlow offload packet in handler thread if handler id is 0. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- ofproto/ofproto-dpif-upcall.c | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 57f94df54..6e05466d5 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -22,6 +22,7 @@ #include "connmgr.h" #include "coverage.h" #include "cmap.h" +#include "lib/dpif-offload-provider.h" #include "lib/dpif-provider.h" #include "dpif.h" #include "openvswitch/dynamic-string.h" @@ -779,6 +780,74 @@ udpif_get_n_flows(struct udpif *udpif) return flow_count; } +static void +process_offload_sflow(struct udpif *udpif, struct dpif_offload_sflow *sflow) +{ + const struct dpif_sflow_attr *attr = sflow->attr; + const struct user_action_cookie *cookie; + struct dpif_sflow *dpif_sflow; + struct ofproto_dpif *ofproto; + struct upcall upcall; + struct flow flow; + + if (!attr) { + VLOG_WARN_RL(&rl, "sFlow upcall is missing its attribute"); + return; + } + + cookie = nl_attr_get(attr->userdata); + if (!cookie) { + VLOG_WARN_RL(&rl, "sFlow user action cookie is missing"); + return; + } + if (nl_attr_get_size(attr->userdata) < sizeof(struct user_action_cookie)) { + VLOG_WARN_RL(&rl, "sFlow user action cookie is corrupted"); + return; + } + ofproto = ofproto_dpif_lookup_by_uuid(&cookie->ofproto_uuid); + if (!ofproto) { + VLOG_WARN_RL(&rl, "sFlow upcall can't find ofproto dpif for UUID " + UUID_FMT, UUID_ARGS(&cookie->ofproto_uuid)); + return; + } + dpif_sflow = ofproto->sflow; + if (!dpif_sflow) { + VLOG_WARN_RL(&rl, "sFlow upcall is missing dpif information"); + return; + } + + memset(&flow, 0, sizeof flow); + if (attr->tunnel) { + memcpy(&flow.tunnel, attr->tunnel, sizeof flow.tunnel); + } + flow.in_port.odp_port = netdev_ifindex_to_odp_port(sflow->iifindex); + memset(&upcall, 0, sizeof upcall); + upcall.flow = &flow; + upcall.cookie = *cookie; + upcall.packet = &sflow->packet; + upcall.sflow = dpif_sflow; + upcall.ufid = &attr->ufid; + upcall.type = SFLOW_UPCALL; + process_upcall(udpif, &upcall, NULL, NULL); +} + +static void +recv_offload_sflow(struct udpif *udpif) +{ + size_t n_sflow = 0; + + while (n_sflow < UPCALL_MAX_BATCH) { + struct dpif_offload_sflow sflow; + + if (dpif_offload_sflow_recv(udpif->dpif, &sflow)) { + break; + } + process_offload_sflow(udpif, &sflow); + n_sflow++; + } + dpif_offload_sflow_recv_wait(udpif->dpif); +} + /* The upcall handler thread tries to read a batch of UPCALL_MAX_BATCH * upcalls from dpif, processes the batch and installs corresponding flows * in dpif. */ @@ -795,6 +864,10 @@ udpif_upcall_handler(void *arg) dpif_recv_wait(udpif->dpif, handler->handler_id); latch_wait(&udpif->exit_latch); } + /* Only handler id 0 thread process sFlow offload packet. */ + if (handler->handler_id == 0) { + recv_offload_sflow(udpif); + } poll_block(); } From patchwork Thu Mar 17 01:12:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606342 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ltEMSnAz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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 4KJq1G2wL8z9sCD for ; Thu, 17 Mar 2022 12:14:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DCF7384782; Thu, 17 Mar 2022 01:14:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org 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 jiEl9nphhw52; Thu, 17 Mar 2022 01:14:22 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 58D1484732; Thu, 17 Mar 2022 01:14:21 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3C6A7C0012; Thu, 17 Mar 2022 01:14:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id BA5F4C000B for ; Thu, 17 Mar 2022 01:14:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A7ACC8474C for ; Thu, 17 Mar 2022 01:13:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org 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 QoDM7Kq1XUdM for ; Thu, 17 Mar 2022 01:13:30 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20627.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::627]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8CE2484745 for ; Thu, 17 Mar 2022 01:13:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fTGuwyZqQE7b34/i3UoSV7gcSwaG+/j6xn7sScHLWmTu1QVaPvU15gCtDijEQ5FJRCmbO22bQJth5AWc5SwoCe9huxBjkjnyvpFMsmqhrTmINnva5b2FOQObnmEhR9jLmC0h+uU4vALP6MZImQFHhWzffcQuHt0g1AnhSHgltqs5RBp45Ag4wYwhhEvH5pwyzqF7qf4GFyEwW5P44ycNfKvo3v7I/xNchR4F3Z3zh2+2GuUTs8ImphoqxSdYeG7o22oLLOH2DXovGAhCQJaXSwCAYWZ8Qcf7Y2cxCr2Jab+hlTSaqAJ6K0WBuTHsQPpGIM1rjjqFCk00Vdk+Spfz/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CB7VQXpc1FOSUkc1Y7r56tJIC+QfXm2D07kCGlaX1fY=; b=CHc4GQtU999FER3mbPx1FuerUlrX68muEJIQ16AZJPw72zoLs283PBo9tRl7K0qnTtfTzDkPWp3MVh9rVrjtHdJqmfdQGPrVLyN6nbQ6sdm8qUwYpS4ZXihTvABqAsV0Wv/7Gee5ZnNRe5MJc3soHaoKCbBv31Ri1Lhua70nas/1ufkp7e16zKYKLvLc5n5ZgQEtO6y4Xne1qE8z7oY03AAL3j1e0PLQz27dwrokdcxzm43BoPyrQ/hytBnBCZE1qje09JzbDEbi0brxFvnli1pXrH3F2H8bjjBDfjWzq3EBbIRXd2/T6AoqTYcNIt2QOOdeJch3T/QI5byB2r75wg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CB7VQXpc1FOSUkc1Y7r56tJIC+QfXm2D07kCGlaX1fY=; b=ltEMSnAzPMWRyiBzfC+EKdg9jwvUgF8FoX7b2P623JLbfnVFxHQTZO6ODY1lxG9GctOtsMa24P3SwOaYLBvWlhlllsOea+kbtgLbzrxcwQTu0E9Ytt9zhivJGIGg2iYIa7n8VZuRtEIq3PidhHHDmHZV6hUZ4hvdra8jPxOVHYJucfeHQVOdpAE+PBTpMLjlzpEIEtHnBqyiGp4ydoGctZ6M9l9+NGhlR3gYFQYatt+KmTEUgchppj8+Luvwh6m3Ujdf9h1yEmV+PPMtaYKmEtT1EG8o5wAJ8nD/pKzwNxoKKPmAH8SNbR3R8YTOncFNGMOwbSZzLrJfZbAbscP6FQ== Received: from BN6PR13CA0022.namprd13.prod.outlook.com (2603:10b6:404:10a::32) by BYAPR12MB3063.namprd12.prod.outlook.com (2603:10b6:a03:d6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Thu, 17 Mar 2022 01:13:24 +0000 Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:404:10a:cafe::d3) by BN6PR13CA0022.outlook.office365.com (2603:10b6:404:10a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:22 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:12 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:11 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:13:09 -0700 To: Date: Thu, 17 Mar 2022 09:12:48 +0800 Message-ID: <20220317011249.46787-8-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4cdb3f47-cb4c-4c74-5fdb-08da07b3550c X-MS-TrafficTypeDiagnostic: BYAPR12MB3063:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ActI4bRwOP9yCSaDBXNJ6PLF+gOddrdRzW38qpy/R0huWL5+csnsbOkAz9K7pD1ibqgiQYRxowZi45IOSipYVVXdEdf7Da0nu+jWx6vqKdqR6lYcos+PKLQ8fPHrO1172UVHR1J7h/cf5ocpAZ4opr/T3LCy07kjqPoVMB06RYaCOuj9VoeAyTMolFzVVhnD13jx8x3FeIz1mjej2oQylzzV3UT7Kb/1D9CCxMdcEbcr1bccQgRCVhTLDVeceUZ5NcCv4U5P27vJ2M+ko8YV2AahPURubXT1mwseHUTEece8rqavu/d/AsAOsICC6C7pm1nqaG008SDN+sWjqkqR4FF3sftV/k4ptWNQYXzShd/lhHjXG/2LdtAJnOdvsoi15yTGON1uOZn1pmwjIpieT+lDY9Z82VY9VHbmf33Z3fYRprumJqGfML5TTHGe79WyV3e4o5ATz+dHT5GVODoGSSSVK0zldMkLnjUZTjFqPVuibVnyVm4LnApgolAGehXYMPTNPz7q6hJwSgG/935cRPuzgMdD8NrNIbS8HSNAhZM2Iwi5NFxQAtfQJ4AI3TGB3CjNBDd7lR2LvxViyjPlzEHmF3nYaJcjhgywUl/1rARXpyUq8v/6OAh+DGycrdjhT76IkXAiuJR27CgWqXhf3GfeoMlrKsq6WyShFss6O3qYiewjd4qwMKrVbLEA8P4LMlF1SitliYNBwiIvyTk5sahMeuXV6pHd+QfTXgXNkNw= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(426003)(336012)(36756003)(316002)(47076005)(30864003)(4326008)(8676002)(70586007)(508600001)(70206006)(26005)(186003)(81166007)(54906003)(6916009)(356005)(2906002)(86362001)(40460700003)(2616005)(6666004)(82310400004)(8936002)(5660300002)(36860700001)(1076003)(107886003)(83380400001)(21314003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:22.0324 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4cdb3f47-cb4c-4c74-5fdb-08da07b3550c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3063 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 7/8] netdev-offload-tc: Add offload support for sFlow 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Create a unique group ID to map the sFlow info when offloading sFlow action to TC. When showing the offloaded datapath flows, translate the group ID from TC sample action to sFlow info using the mapping. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- NEWS | 1 + lib/dpif-offload-netlink.c | 6 + lib/dpif-offload-provider.h | 2 + lib/netdev-offload-tc.c | 228 +++++++++++++++++++++++++++++++++--- lib/tc.c | 61 +++++++++- lib/tc.h | 15 ++- 6 files changed, 291 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index df633e8e2..ed93c5c6e 100644 --- a/NEWS +++ b/NEWS @@ -54,6 +54,7 @@ v2.17.0 - xx xxx xxxx - Ingress policing on Linux now uses 'matchall' classifier instead of 'basic', if available. - Add User Statically-Defined Tracing (USDT) probe framework support. + - Add sFlow offload support for kernel (netlink) datapath. v2.16.0 - 16 Aug 2021 diff --git a/lib/dpif-offload-netlink.c b/lib/dpif-offload-netlink.c index 02aea7e2d..b94818ee1 100644 --- a/lib/dpif-offload-netlink.c +++ b/lib/dpif-offload-netlink.c @@ -219,3 +219,9 @@ const struct dpif_offload_class dpif_offload_netlink_class = { .sflow_recv_wait = dpif_offload_netlink_sflow_recv_wait, .sflow_recv = dpif_offload_netlink_sflow_recv, }; + +bool +dpif_offload_netlink_psample_supported(void) +{ + return psample_sock != NULL; +} diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h index 51a374868..6306c2746 100644 --- a/lib/dpif-offload-provider.h +++ b/lib/dpif-offload-provider.h @@ -89,4 +89,6 @@ void dpif_offload_sflow_recv_wait(const struct dpif *dpif); int dpif_offload_sflow_recv(const struct dpif *dpif, struct dpif_offload_sflow *sflow); +bool dpif_offload_netlink_psample_supported(void); + #endif /* DPIF_OFFLOAD_PROVIDER_H */ diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index acc1dfdff..53540ec22 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -20,6 +20,7 @@ #include #include "dpif.h" +#include "dpif-offload-provider.h" #include "hash.h" #include "openvswitch/hmap.h" #include "openvswitch/match.h" @@ -1054,6 +1055,19 @@ parse_tc_flower_to_match(struct tc_flower *flower, action = flower->actions; for (i = 0; i < flower->action_count; i++, action++) { switch (action->type) { + case TC_ACT_SAMPLE: { + const struct sgid_node *node; + + node = sgid_find(action->sample.group_id); + if (!node) { + VLOG_WARN("Can't find sample group ID data for ID: %u", + action->sample.group_id); + return ENOENT; + } + nl_msg_put(buf, node->sflow.action, + node->sflow.action->nla_len); + } + break; case TC_ACT_VLAN_POP: { nl_msg_put_flag(buf, OVS_ACTION_ATTR_POP_VLAN); } @@ -1786,6 +1800,151 @@ parse_match_ct_state_to_flower(struct tc_flower *flower, struct match *match) } } +static int +parse_userspace_attributes(const struct nlattr *actions, + struct dpif_sflow_attr *sflow_attr) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + const struct nlattr *nla; + unsigned int left; + + NL_NESTED_FOR_EACH_UNSAFE (nla, left, actions) { + if (nl_attr_type(nla) == OVS_USERSPACE_ATTR_USERDATA) { + struct user_action_cookie *cookie; + + cookie = CONST_CAST(struct user_action_cookie *, nl_attr_get(nla)); + if (cookie->type == USER_ACTION_COOKIE_SFLOW) { + sflow_attr->userdata = nla; + return 0; + } + } + } + + VLOG_DBG_RL(&rl, "Can't offload userspace action other than sFlow"); + return EOPNOTSUPP; +} + +static int +parse_sample_actions_attribute(const struct nlattr *actions, + struct dpif_sflow_attr *sflow_attr) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + const struct nlattr *nla; + unsigned int left; + int err = EINVAL; + + NL_NESTED_FOR_EACH_UNSAFE (nla, left, actions) { + if (nl_attr_type(nla) == OVS_ACTION_ATTR_USERSPACE) { + err = parse_userspace_attributes(nla, sflow_attr); + } else { + /* We can't offload other nested actions */ + VLOG_DBG_RL(&rl, "Can only offload OVS_ACTION_ATTR_USERSPACE" + " attribute"); + return EINVAL; + } + } + + if (err) { + VLOG_ERR_RL(&error_rl, "No OVS_ACTION_ATTR_USERSPACE attribute"); + } + return err; +} + +static int +parse_sample_action(struct tc_flower *flower, struct tc_action *tc_action, + const struct nlattr *sample_action, + const struct flow_tnl *tnl, uint32_t *group_id, + const ovs_u128 *ufid) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct dpif_sflow_attr sflow_attr; + const struct nlattr *nla; + unsigned int left; + int ret = EINVAL; + + if (*group_id) { + VLOG_ERR_RL(&error_rl, + "Only a single TC_SAMPLE action per flow is supported"); + return EOPNOTSUPP; + } + + memset(&sflow_attr, 0, sizeof sflow_attr); + sflow_attr.ufid = *ufid; + sflow_attr.action = sample_action; + + if (flower->tunnel) { + sflow_attr.tunnel = CONST_CAST(struct flow_tnl *, tnl); + } + + NL_NESTED_FOR_EACH_UNSAFE (nla, left, sample_action) { + if (nl_attr_type(nla) == OVS_SAMPLE_ATTR_ACTIONS) { + ret = parse_sample_actions_attribute(nla, &sflow_attr); + } else if (nl_attr_type(nla) == OVS_SAMPLE_ATTR_PROBABILITY) { + tc_action->type = TC_ACT_SAMPLE; + tc_action->sample.rate = UINT32_MAX / nl_attr_get_u32(nla); + } else { + return EINVAL; + } + } + + if (!tc_action->sample.rate || ret) { + return EINVAL; + } + + *group_id = sgid_alloc_ctx(&sflow_attr); + if (!*group_id) { + VLOG_DBG_RL(&rl, "Failed allocating group id for sample action"); + return ENOENT; + } + tc_action->sample.group_id = *group_id; + flower->action_count++; + + return 0; +} + +static int +parse_userspace_action(struct tc_flower *flower, struct tc_action *tc_action, + const struct nlattr *userspace_action, + const struct flow_tnl *tnl, uint32_t *group_id, + const ovs_u128 *ufid) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct dpif_sflow_attr sflow_attr; + int err; + + if (*group_id) { + VLOG_ERR_RL(&error_rl, + "Only a single TC_SAMPLE action per flow is supported"); + return EOPNOTSUPP; + } + + /* If sampling rate is 1, there is only a sFlow cookie inside of a + * userspace action, but no sample attribute. That means we can + * only offload userspace actions for sFlow. + */ + memset(&sflow_attr, 0, sizeof sflow_attr); + sflow_attr.ufid = *ufid; + if (flower->tunnel) { + sflow_attr.tunnel = CONST_CAST(struct flow_tnl *, tnl); + } + err = parse_userspace_attributes(userspace_action, &sflow_attr); + if (err) { + return err; + } + sflow_attr.action = userspace_action; + *group_id = sgid_alloc_ctx(&sflow_attr); + if (!*group_id) { + VLOG_DBG_RL(&rl, "Failed allocating group id for sample action"); + return ENOENT; + } + tc_action->type = TC_ACT_SAMPLE; + tc_action->sample.group_id = *group_id; + tc_action->sample.rate = 1; + flower->action_count++; + + return 0; +} + static int netdev_tc_flow_put(struct netdev *netdev, struct match *match, struct nlattr *actions, size_t actions_len, @@ -1801,6 +1960,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, const struct flow_tnl *tnl_mask = &mask->tunnel; struct tc_action *action; bool recirc_act = false; + uint32_t sample_gid = 0; uint32_t block_id = 0; struct nlattr *nla; struct tcf_id id; @@ -2053,7 +2213,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, NL_ATTR_FOR_EACH(nla, left, actions, actions_len) { if (flower.action_count >= TCA_ACT_MAX_NUM) { VLOG_DBG_RL(&rl, "Can only support %d actions", TCA_ACT_MAX_NUM); - return EOPNOTSUPP; + err = EOPNOTSUPP; + goto out; } action = &flower.actions[flower.action_count]; if (nl_attr_type(nla) == OVS_ACTION_ATTR_OUTPUT) { @@ -2063,7 +2224,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, if (!outdev) { VLOG_DBG_RL(&rl, "Can't find netdev for output port %d", port); - return ENODEV; + err = ENODEV; + goto out; } action->out.ifindex_out = netdev_get_ifindex(outdev); action->out.ingress = is_internal_port(netdev_get_type(outdev)); @@ -2101,7 +2263,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, err = parse_put_flow_set_action(&flower, action, set, set_len); if (err) { - return err; + goto out; } if (action->type == TC_ACT_ENCAP) { action->encap.tp_dst = info->tp_dst_port; @@ -2114,7 +2276,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, err = parse_put_flow_set_masked_action(&flower, action, set, set_len, true); if (err) { - return err; + goto out; } } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_CT) { const struct nlattr *ct = nl_attr_get(nla); @@ -2126,7 +2288,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, err = parse_put_flow_ct_action(&flower, action, ct, ct_len); if (err) { - return err; + goto out; } } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_CT_CLEAR) { action->type = TC_ACT_CT; @@ -2142,20 +2304,41 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) { - struct dpif_sflow_attr sflow_attr; - - memset(&sflow_attr, 0, sizeof sflow_attr); - sgid_alloc_ctx(&sflow_attr); + if (!dpif_offload_netlink_psample_supported()) { + VLOG_DBG_RL(&rl, "Unsupported put action type: %d, psample is " + "not initialized successfully", nl_attr_type(nla)); + err = EOPNOTSUPP; + goto out; + } + err = parse_sample_action(&flower, action, nla, tnl, &sample_gid, + ufid); + if (err) { + goto out; + } + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_USERSPACE) { + if (!dpif_offload_netlink_psample_supported()) { + VLOG_DBG_RL(&rl, "Unsupported put action type: %d, psample is " + "not initialized successfully", nl_attr_type(nla)); + err = EOPNOTSUPP; + goto out; + } + err = parse_userspace_action(&flower, action, nla, tnl, + &sample_gid, ufid); + if (err) { + goto out; + } } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); - return EOPNOTSUPP; + err = EOPNOTSUPP; + goto out; } } if ((chain || recirc_act) && !info->recirc_id_shared_with_tc) { VLOG_ERR_RL(&error_rl, "flow_put: recirc_id sharing not supported"); - return EOPNOTSUPP; + err = EOPNOTSUPP; + goto out; } if (get_ufid_tc_mapping(ufid, &id) == 0) { @@ -2168,20 +2351,29 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, prio = get_prio_for_tc_flower(&flower); if (prio == 0) { VLOG_ERR_RL(&rl, "couldn't get tc prio: %s", ovs_strerror(ENOSPC)); - return ENOSPC; + err = ENOSPC; + goto out; } flower.act_cookie.data = ufid; flower.act_cookie.len = sizeof *ufid; block_id = get_block_id_from_netdev(netdev); - id = tc_make_tcf_id_chain(ifindex, block_id, chain, prio, hook); + id = tc_make_tcf_id_all(ifindex, block_id, chain, prio, hook, sample_gid); err = tc_replace_flower(&id, &flower); - if (!err) { - if (stats) { - memset(stats, 0, sizeof *stats); - } - add_ufid_tc_mapping(netdev, ufid, &id); + if (err) { + goto out; + } + + if (stats) { + memset(stats, 0, sizeof *stats); + } + add_ufid_tc_mapping(netdev, ufid, &id); + return 0; + +out: + if (sample_gid) { + sgid_free(sample_gid); } return err; diff --git a/lib/tc.c b/lib/tc.c index 703febc25..a66fbf0d0 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -23,14 +23,15 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include -#include #include #include #include @@ -1340,6 +1341,38 @@ nl_parse_act_gact(struct nlattr *options, struct tc_flower *flower) return 0; } +static const struct nl_policy sample_policy[] = { + [TCA_SAMPLE_PARMS] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_sample), + .optional = false, }, + [TCA_SAMPLE_PSAMPLE_GROUP] = { .type = NL_A_U32, + .optional = false, }, + [TCA_SAMPLE_RATE] = { .type = NL_A_U32, + .optional = false, }, +}; + +static int +nl_parse_act_sample(struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *sample_attrs[ARRAY_SIZE(sample_policy)]; + struct tc_action *action; + + if (!nl_parse_nested(options, sample_policy, sample_attrs, + ARRAY_SIZE(sample_policy))) { + VLOG_ERR_RL(&error_rl, "Failed to parse sample action options"); + return EPROTO; + } + + action = &flower->actions[flower->action_count++]; + action->type = TC_ACT_SAMPLE; + action->sample.group_id = + nl_attr_get_u32(sample_attrs[TCA_SAMPLE_PSAMPLE_GROUP]); + action->sample.rate = + nl_attr_get_u32(sample_attrs[TCA_SAMPLE_RATE]); + + return 0; +} + static const struct nl_policy mirred_policy[] = { [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct tc_mirred), @@ -1754,6 +1787,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, /* Added for TC rule only (not in OvS rule) so ignore. */ } else if (!strcmp(act_kind, "ct")) { nl_parse_act_ct(act_options, flower); + } else if (!strcmp(act_kind, "sample")) { + nl_parse_act_sample(act_options, flower); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; @@ -2396,6 +2431,23 @@ nl_msg_put_act_mirred(struct ofpbuf *request, int ifindex, int action, nl_msg_end_nested(request, offset); } +static void +nl_msg_put_act_sample(struct ofpbuf *request, uint32_t rate, uint32_t group_id) +{ + size_t offset; + + nl_msg_put_string(request, TCA_ACT_KIND, "sample"); + offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS | NLA_F_NESTED); + { + struct tc_sample parm = { .action = TC_ACT_PIPE }; + + nl_msg_put_unspec(request, TCA_SAMPLE_PARMS, &parm, sizeof parm); + nl_msg_put_u32(request, TCA_SAMPLE_RATE, rate); + nl_msg_put_u32(request, TCA_SAMPLE_PSAMPLE_GROUP, group_id); + } + nl_msg_end_nested(request, offset); +} + static inline void nl_msg_put_act_cookie(struct ofpbuf *request, struct tc_cookie *ck) { if (ck->len) { @@ -2697,6 +2749,13 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) nl_msg_end_nested(request, act_offset); } break; + case TC_ACT_SAMPLE: { + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_sample(request, action->sample.rate, + action->sample.group_id); + nl_msg_end_nested(request, act_offset); + } + break; case TC_ACT_OUTPUT: { if (!released && flower->tunnel) { nl_msg_put_flower_acts_release(request, act_index++); diff --git a/lib/tc.h b/lib/tc.h index 2bcff80b9..611198b64 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -174,6 +174,7 @@ enum tc_action_type { TC_ACT_MPLS_SET, TC_ACT_GOTO, TC_ACT_CT, + TC_ACT_SAMPLE, }; enum nat_type { @@ -261,6 +262,11 @@ struct tc_action { struct tc_flower_key key; struct tc_flower_key mask; } rewrite; + + struct { + uint32_t rate; + uint32_t group_id; + } sample; }; enum tc_action_type type; @@ -306,12 +312,14 @@ tc_make_tcf_id(int ifindex, uint32_t block_id, uint16_t prio, } static inline struct tcf_id -tc_make_tcf_id_chain(int ifindex, uint32_t block_id, uint32_t chain, - uint16_t prio, enum tc_qdisc_hook hook) +tc_make_tcf_id_all(int ifindex, uint32_t block_id, uint32_t chain, + uint16_t prio, enum tc_qdisc_hook hook, + uint32_t sample_group_id) { struct tcf_id id = tc_make_tcf_id(ifindex, block_id, prio, hook); id.chain = chain; + id.sample_group_id = sample_group_id; return id; } @@ -325,7 +333,8 @@ is_tcf_id_eq(struct tcf_id *id1, struct tcf_id *id2) && id1->hook == id2->hook && id1->block_id == id2->block_id && id1->ifindex == id2->ifindex - && id1->chain == id2->chain; + && id1->chain == id2->chain + && id1->sample_group_id == id2->sample_group_id; } enum tc_offload_policy { From patchwork Thu Mar 17 01:12:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1606341 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tmNO4RWY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4KJq0Q4H19z9sCD for ; Thu, 17 Mar 2022 12:13:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DABFC40B39; Thu, 17 Mar 2022 01:13:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TTvIsmO_j9WG; Thu, 17 Mar 2022 01:13:38 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id AFB6840B6E; Thu, 17 Mar 2022 01:13:36 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 717F8C0012; Thu, 17 Mar 2022 01:13:36 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1AA5AC0073 for ; Thu, 17 Mar 2022 01:13:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CD9726126C for ; Thu, 17 Mar 2022 01:13:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yfOrNj-3BZ0R for ; Thu, 17 Mar 2022 01:13:18 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20618.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::618]) by smtp3.osuosl.org (Postfix) with ESMTPS id C3ECD61277 for ; Thu, 17 Mar 2022 01:13:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KjR+Lpu+HeNVRWUE0WM/g2d6n7ch9kdSYQnaJAf2nOzVi+AHAb9qeYVQpQpJ6xdQiZsTo5rvOyncEjgR4xjWG6CAkwV0V5BT8gkBthMcKE8nf8/XTbF/bEaZekAavOLIZv51BMON2/AdTmIsJ2mhPjUoai8bD5eDeWbkjwDG9Nb500GQK4SjLACJi4/ZAspIwL5XzKMvRPyG4GRyVOzDT1AAm2tdr1vOZlB0WiWz9IucNhoSjdzgNJxIFP3PzEZkxn8CTkS4LM4jCU8jcwp4vFjru2Ip5f4OUo/Ntf2cjv3wvLEsTmSNHB3q1b361FeQ6EuZ4FaI+eC/lTVXYDgpKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fX85bq+T7Pj3oCVCXXERg5IC766l2hjj2bGtafcZIis=; b=AGGLxbHfscCX5s2520nFx0cV10BitBjvinoFo1LjWezfh6Q5JOZObzWajcfvr0rnVwly/rsZZ7YL+Pmnnhkh1qW+bQAEatRH7WYKdXDdPBTzweExg4tOsic0IWcYsTjoabjBwbW3tYLUYTDjN/I5twgTKoTYh1tVLHy2DlRsr9ALL3HAFhN+pwLQYrUQRxPx7Dg6DWvQ1imWJkBy1vg8nkdnOr98CUOxW9Qtb6jiB5/Osf8KsqJDi7XdCZDP6Dx6g9O9tKDZs+y8sOasvVofIWCJlKx0o1/XfUXHTsGb6sAOH4089L6KhEfHl22NIN8dX7g5EsgZUR+G9NkTCVXvHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fX85bq+T7Pj3oCVCXXERg5IC766l2hjj2bGtafcZIis=; b=tmNO4RWYdadwAulh3RlKHEfXEcQpwqe9VBLo6nPzxB3T8FHpn5MskqcjQ/iTcaDuk54c5FGy6pYsoiDi0/1RFLHS8n6vdFtSXmgzZxP7nlnmBKnD7L8tVDD7KfMxvlxo8ZvDR5QGL6E5SgejByvOaI+OQY3f4A9k8Bv2nl4Hx7I3lONg7LA0k91ytNmr78/jB0XkSGqodheuKu4LeCefZc6DFs2QqjqU/yus1sLuYZ++2N4FPEQfEo0FeRi2L3SXQFNHkiPnF2OO/B1Otd/jCrSSDQAs1J1VgFLYMljnD8wfnVqMgpcCgikSgFLFKZTJlPcjdVrrzNRrqeQadwslig== Received: from DM5PR15CA0071.namprd15.prod.outlook.com (2603:10b6:3:ae::33) by DM6PR12MB3979.namprd12.prod.outlook.com (2603:10b6:5:1cd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 01:13:16 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ae:cafe::2f) by DM5PR15CA0071.outlook.office365.com (2603:10b6:3:ae::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 01:13:15 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 17 Mar 2022 01:13:14 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 16 Mar 2022 18:13:14 -0700 Received: from dev-r630-03.lab.mtl.com (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Wed, 16 Mar 2022 18:13:12 -0700 To: Date: Thu, 17 Mar 2022 09:12:49 +0800 Message-ID: <20220317011249.46787-9-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220317011249.46787-1-cmi@nvidia.com> References: <20220317011249.46787-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6291257-c494-471a-834c-08da07b35086 X-MS-TrafficTypeDiagnostic: DM6PR12MB3979:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vv+40eED2H4TWu7qr7lOAdlF/I1gQDBfGVASUv5REpLwcSQkkdSFjDv61J5KpLqegOyWLIc0rsLQafrjctCu3ZsBIvK8bJkKRWmMUjIkXqO6kzME1zdSXlfK7jhBvCOr8nIMcT0wdzVffKoEJ0NkrNmU5/9gBzhOsvvLNPbXbbHOp6kSRW7oE4KgoXgJoRDXEN62SlpqmeMA6r6Fzj28lVEkVkBhLQTn1LOAfP5eW9jUjx7sqvi8iG2VN9Z9/rLsailMiNGWPoxb2eRo/Fyc53IR2QcQJJ7cCB0tXGvYUfHymzTkKdX1gZ0eAjkLhEE6DVCZTwBViy+5fXH7s18UM2lulFZRyb3vi4nCjKXJe89DCndF5r6wzdXiD8dIscgBSF46WlMLrc7p8jJszsa7iKp1eBVhp5IKMEiIVnbpAo2nWt9uP63HCXCHolPKoR4YzajYbjOmyXcz0Y3RmAJsw40PwHqyMPOi9sUHRLLAQFu/l0UAlHrDTJN747j2ns93Uk9tTPe/8tEDJQtGvSy4/TW8xrM5sztJW6v7O40YwVFTmMtwxvGHsFo/mb6pYEwUGWmxVMM1lD0n3ruIenTTkMON5stWXbk+Kvbz+NzrC+yukcIa28cU7hoExS4xwswoOS0s9oSnMLVUN4pvB16QkrnRfHGJeJ+fynWE9vToIileYqVDEn4kC5da/AJJQt2wbEQRMr5QlFVvSxyEeiY48w== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(6916009)(40460700003)(54906003)(86362001)(508600001)(6666004)(107886003)(8936002)(1076003)(81166007)(5660300002)(316002)(36756003)(356005)(82310400004)(83380400001)(2906002)(36860700001)(2616005)(70206006)(70586007)(47076005)(4326008)(8676002)(186003)(26005)(426003)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 01:13:15.6785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6291257-c494-471a-834c-08da07b35086 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3979 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v21 8/8] system-offloads-traffic.at: Add sFlow offload test cases 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add two sFlow offload test caes: 3: sflow offloads with sampling=1 - ping between two ports - offloads enabled ok 4: sflow offloads with sampling=2 - ping between two ports - offloads enabled ok Signed-off-by: Chris Mi Acked-by: Eelco Chaudron --- tests/system-offloads-traffic.at | 101 +++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/tests/system-offloads-traffic.at b/tests/system-offloads-traffic.at index 80bc1dd5c..19dd2137f 100644 --- a/tests/system-offloads-traffic.at +++ b/tests/system-offloads-traffic.at @@ -71,6 +71,107 @@ AT_CHECK([ovs-appctl upcall/show | grep -E "offloaded flows : [[1-9]]"], [0], [i OVS_TRAFFIC_VSWITCHD_STOP AT_CLEANUP +AT_SETUP([sflow offloads with sampling=1 - ping between two ports - offloads enabled]) +OVS_TRAFFIC_VSWITCHD_START() + +on_exit 'kill `cat test-sflow.pid`' +AT_CHECK([ovstest test-sflow --log-file --detach --no-chdir --pidfile 0:127.0.0.1 > sflow.log], [0], [], [ignore]) +AT_CAPTURE_FILE([sflow.log]) +PARSE_LISTENING_PORT([test-sflow.log], [SFLOW_PORT]) + +AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:hw-offload=true]) + +AT_CHECK([ovs-appctl -t ovsdb-server exit]) +AT_CHECK([ovs-appctl -t ovs-vswitchd exit]) +AT_CHECK([rm -f ovsdb-server.pid]) +AT_CHECK([rm -f ovs-vswitchd.pid]) +AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr]) +AT_CHECK([ovs-vswitchd --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr]) +on_exit "kill `cat ovsdb-server.pid`" +on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`" + +AT_CHECK([ovs-ofctl add-flow br0 "actions=normal"]) + +ADD_NAMESPACES(at_ns0, at_ns1) + +ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24") +ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24") +AT_CHECK([ovs-appctl dpctl/dump-flows], [0], [ignore]) + +NS_CHECK_EXEC([at_ns0], [ping -c 10 -w 12 10.1.1.2 | FORMAT_PING], [0], [dnl +10 packets transmitted, 10 received, 0% packet loss, time 0ms +]) +AT_CHECK([ovs-vsctl -- --id=@sflow create sflow agent=lo target=\"127.0.0.1:$SFLOW_PORT\" header=128 sampling=1 polling=100 -- set bridge br0 sflow=@sflow], [0], [ignore]) +NS_CHECK_EXEC([at_ns0], [ping -c 10 -w 12 10.1.1.2 | FORMAT_PING], [0], [dnl +10 packets transmitted, 10 received, 0% packet loss, time 0ms +]) + +m4_define([DUMP_SFLOW], [sed -e "s/used:[[0-9]].[[0-9]]*s/used:0.001s/;s/eth(src=[[a-z0-9:]]*,dst=[[a-z0-9:]]*)/eth(macs)/;s/pid=[[0-9]]*/pid=1/;s/output=$P1_IFINDEX/output=1/"]) +P1_IFINDEX=$(cat /sys/class/net/ovs-p1/ifindex) +AT_CHECK([ovs-appctl dpctl/dump-flows type=tc,offloaded | grep "in_port(2)" | grep "eth_type(0x0800)" | grep "actions:userspace" | grep "sFlow" | DUMP_SFLOW], [0], [dnl +recirc_id(0),in_port(2),eth(macs),eth_type(0x0800),ipv4(frag=no), packets:10, bytes:840, used:0.001s, actions:userspace(pid=1,sFlow(vid=0,pcp=0,output=1),actions),3 +]) + +m4_define([DUMP_SFLOW], [sed -e "s/used:[[0-9]].[[0-9]]*s/used:0.001s/;s/eth(src=[[a-z0-9:]]*,dst=[[a-z0-9:]]*)/eth(macs)/;s/pid=[[0-9]]*/pid=1/;s/output=$P0_IFINDEX/output=1/"]) +P0_IFINDEX=$(cat /sys/class/net/ovs-p0/ifindex) +AT_CHECK([ovs-appctl dpctl/dump-flows type=tc,offloaded | grep "in_port(3)" | grep "eth_type(0x0800)" | grep "actions:userspace" | grep "sFlow" | DUMP_SFLOW], [0], [dnl +recirc_id(0),in_port(3),eth(macs),eth_type(0x0800),ipv4(frag=no), packets:10, bytes:840, used:0.001s, actions:userspace(pid=1,sFlow(vid=0,pcp=0,output=1),actions),2 +]) + +OVS_TRAFFIC_VSWITCHD_STOP +OVS_APP_EXIT_AND_WAIT([test-sflow]) +count=`cat sflow.log | wc -l` +AT_CHECK([[[[ $count -le 22 && $count -ge 18 ]]]]) +AT_CLEANUP + +AT_SETUP([sflow offloads with sampling=2 - ping between two ports - offloads enabled]) +OVS_TRAFFIC_VSWITCHD_START() + +on_exit 'kill `cat test-sflow.pid`' +AT_CHECK([ovstest test-sflow --log-file --detach --no-chdir --pidfile 0:127.0.0.1 > sflow.log], [0], [], [ignore]) +AT_CAPTURE_FILE([sflow.log]) +PARSE_LISTENING_PORT([test-sflow.log], [SFLOW_PORT]) + +AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:hw-offload=true]) + +AT_CHECK([ovs-appctl -t ovsdb-server exit]) +AT_CHECK([ovs-appctl -t ovs-vswitchd exit]) +AT_CHECK([rm -f ovsdb-server.pid]) +AT_CHECK([rm -f ovs-vswitchd.pid]) +AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr]) +AT_CHECK([ovs-vswitchd --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr]) +on_exit "kill `cat ovsdb-server.pid`" +on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`" + +AT_CHECK([ovs-ofctl add-flow br0 "actions=normal"]) + +ADD_NAMESPACES(at_ns0, at_ns1) + +ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24") +ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24") +AT_CHECK([ovs-appctl dpctl/dump-flows], [0], [ignore]) + +AT_CHECK([ovs-vsctl -- --id=@sflow create sflow agent=lo target=\"127.0.0.1:$SFLOW_PORT\" header=128 sampling=2 polling=100 -- set bridge br0 sflow=@sflow], [0], [ignore]) +NS_CHECK_EXEC([at_ns0], [ping -c 1000 -i 0.01 -w 12 10.1.1.2], [0], [ignore]) + +P1_IFINDEX=$(cat /sys/class/net/ovs-p1/ifindex) +m4_define([DUMP_SFLOW], [sed -e "s/packets:[[0-9]]*/packets:1/;s/bytes:[[0-9]]*/bytes:1/;s/used:[[0-9]].[[0-9]]*s/used:0.001s/;s/eth(src=[[a-z0-9:]]*,dst=[[a-z0-9:]]*)/eth(macs)/;s/pid=[[0-9]]*/pid=1/;s/output=$P1_IFINDEX/output=1/"]) +AT_CHECK([ovs-appctl dpctl/dump-flows type=tc,offloaded | grep "in_port(2)" | grep "eth_type(0x0800)" | grep "actions:sample" | grep "sFlow" | DUMP_SFLOW], [0], [dnl +recirc_id(0),in_port(2),eth(macs),eth_type(0x0800),ipv4(frag=no), packets:1, bytes:1, used:0.001s, actions:sample(sample=50.0%,actions(userspace(pid=1,sFlow(vid=0,pcp=0,output=1),actions))),3 +]) + +P0_IFINDEX=$(cat /sys/class/net/ovs-p0/ifindex) +m4_define([DUMP_SFLOW], [sed -e "s/packets:[[0-9]]*/packets:1/;s/bytes:[[0-9]]*/bytes:1/;s/used:[[0-9]].[[0-9]]*s/used:0.001s/;s/eth(src=[[a-z0-9:]]*,dst=[[a-z0-9:]]*)/eth(macs)/;s/pid=[[0-9]]*/pid=1/;s/output=$P0_IFINDEX/output=1/"]) +AT_CHECK([ovs-appctl dpctl/dump-flows type=tc,offloaded | grep "in_port(3)" | grep "eth_type(0x0800)" | grep "actions:sample" | grep "sFlow" | DUMP_SFLOW], [0], [dnl +recirc_id(0),in_port(3),eth(macs),eth_type(0x0800),ipv4(frag=no), packets:1, bytes:1, used:0.001s, actions:sample(sample=50.0%,actions(userspace(pid=1,sFlow(vid=0,pcp=0,output=1),actions))),2 +]) + +OVS_TRAFFIC_VSWITCHD_STOP +OVS_APP_EXIT_AND_WAIT([test-sflow]) +count=`cat sflow.log | wc -l` +AT_CHECK([[[[ $count -le 1100 && $count -ge 900 ]]]]) +AT_CLEANUP + AT_SETUP([offloads - set ingress_policing_rate and ingress_policing_burst - offloads disabled]) AT_KEYWORDS([ingress_policing]) AT_SKIP_IF([test $HAVE_TC = "no"])