From patchwork Thu Mar 7 15:18:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1909315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eJonnHOv; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrCd91TXhz23hR for ; Fri, 8 Mar 2024 02:19:09 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 619D9610AB; Thu, 7 Mar 2024 15:19:06 +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 oqac3k0DQU2W; Thu, 7 Mar 2024 15:19:04 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7B0566104B Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eJonnHOv Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7B0566104B; Thu, 7 Mar 2024 15:19:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5FF22C0077; Thu, 7 Mar 2024 15:19:04 +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 57A4CC0037 for ; Thu, 7 Mar 2024 15:19:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 41F0F6101F for ; Thu, 7 Mar 2024 15:19:03 +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 6vZJLKfNHdEd for ; Thu, 7 Mar 2024 15:19:02 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 3377161028 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3377161028 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3377161028 for ; Thu, 7 Mar 2024 15:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m3QHk3gZDzu+lQdUT48rZodxOgOgf1lVBanw+R4FyF4=; b=eJonnHOvdp0XV9xg/JMdq27cB+5qf625oarsxj/FBN4wam2mbzLpL3JkK4FsLASDQHvcmk 9Y+zVMET9M91R0d8VcL58A/Q2TmvZOdQ58/du5rjW5DpXSJVy7iJaC56T40jGAiHaK04Up mpBvkToJd0PTSo+UZuzNUU8afO1BUhU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-qx3w7DA5NSiU9Qemm0VdHQ-1; Thu, 07 Mar 2024 10:18:55 -0500 X-MC-Unique: qx3w7DA5NSiU9Qemm0VdHQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1BF93830092; Thu, 7 Mar 2024 15:18:54 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.194.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A4172166B33; Thu, 7 Mar 2024 15:18:53 +0000 (UTC) From: Adrian Moreno To: netdev@vger.kernel.org, dev@openvswitch.org Date: Thu, 7 Mar 2024 16:18:45 +0100 Message-ID: <20240307151849.394962-2-amorenoz@redhat.com> In-Reply-To: <20240307151849.394962-1-amorenoz@redhat.com> References: <20240307151849.394962-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Cc: yotam.gi@gmail.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC PATCH 1/4] net:openvswitch: Support multicasting userspace ... X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" actions. Some userspace actions, such as the ones derived from OFP_CONTROLLER action or slow path, have to be handled by ovs-vswitchd, so they are unicasted through the netlink socket that corresponds. However, some other userspace actions require little processing by ovs-vswitchd and their end consumer is typically some external entity. This is the case for IPFIX sampling which can provide very useful observability on the OVS datapath. Having these samples share the netlink socket and the userspace cpu time with flow misses can easily lead to higher latency and packet drops. This is clearly a price too high to pay for observability. In order to allow observability applications safely consume data that include OVN metadata, this patch makes the existing "ovs_packet" netlink family also contain a multicast group and adds a new attribute to the userspace action so that ovs-vswitchd can indicate that an action must be multicasted. Signed-off-by: Adrian Moreno --- include/uapi/linux/openvswitch.h | 6 +++++- net/openvswitch/actions.c | 5 +++++ net/openvswitch/datapath.c | 14 +++++++++++++- net/openvswitch/datapath.h | 1 + net/openvswitch/flow_netlink.c | 6 ++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index efc82c318fa2..77525a1c648a 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -144,6 +144,7 @@ struct ovs_vport_stats { /* Packet transfer. */ #define OVS_PACKET_FAMILY "ovs_packet" +#define OVS_PACKET_MCGROUP "ovs_packet" #define OVS_PACKET_VERSION 0x1 enum ovs_packet_cmd { @@ -678,7 +679,8 @@ struct sample_arg { /** * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action. * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION - * message should be sent. Required. + * message should be sent. If the PID is 0, the message will be sent to the + * "ovs_packet" netlink multicast group. Required. * @OVS_USERSPACE_ATTR_USERDATA: If present, its variable-length argument is * copied to the %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA. * @OVS_USERSPACE_ATTR_EGRESS_TUN_PORT: If present, u32 output port to get @@ -692,6 +694,8 @@ enum ovs_userspace_attr { OVS_USERSPACE_ATTR_EGRESS_TUN_PORT, /* Optional, u32 output port * to get tunnel info. */ OVS_USERSPACE_ATTR_ACTIONS, /* Optional flag to get actions. */ + OVS_USERSPACE_ATTR_MCAST, /* Optional flag to send the packet to + the "ovs_packet" multicast group. */ __OVS_USERSPACE_ATTR_MAX }; diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 6fcd7e2ca81f..c5774613faeb 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -1004,6 +1004,11 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb, break; } + case OVS_USERSPACE_ATTR_MCAST: { + upcall.portid = MCAST_PID; + break; + } + } /* End of switch. */ } diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 11c69415c605..15bad6f4b645 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -70,6 +70,10 @@ static const struct genl_multicast_group ovs_dp_vport_multicast_group = { .name = OVS_VPORT_MCGROUP, }; +static const struct genl_multicast_group ovs_dp_packet_multicast_group = { + .name = OVS_PACKET_MCGROUP, +}; + /* Check if need to build a reply message. * OVS userspace sets the NLM_F_ECHO flag if it needs the reply. */ static bool ovs_must_notify(struct genl_family *family, struct genl_info *info, @@ -577,7 +581,13 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len; - err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid); + if (upcall_info->portid == MCAST_PID) + err = genlmsg_multicast_netns(&dp_packet_genl_family, + ovs_dp_get_net(dp), user_skb, 0, 0, GFP_KERNEL); + else + err = genlmsg_unicast(ovs_dp_get_net(dp), + user_skb, upcall_info->portid); + user_skb = NULL; out: if (err) @@ -717,6 +727,8 @@ static struct genl_family dp_packet_genl_family __ro_after_init = { .small_ops = dp_packet_genl_ops, .n_small_ops = ARRAY_SIZE(dp_packet_genl_ops), .resv_start_op = OVS_PACKET_CMD_EXECUTE + 1, + .mcgrps = &ovs_dp_packet_multicast_group, + .n_mcgrps = 1, .module = THIS_MODULE, }; diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h index 0cd29971a907..d0b1b8afafbb 100644 --- a/net/openvswitch/datapath.h +++ b/net/openvswitch/datapath.h @@ -124,6 +124,7 @@ struct ovs_skb_cb { }; #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb) +#define MCAST_PID 0xFFFFFFFF /** * struct dp_upcall - metadata to include with a packet to send to userspace * @cmd: One of %OVS_PACKET_CMD_*. diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index ebc5728aab4e..4c95fa1aa15d 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -3043,6 +3043,8 @@ static int validate_userspace(const struct nlattr *attr) [OVS_USERSPACE_ATTR_PID] = {.type = NLA_U32 }, [OVS_USERSPACE_ATTR_USERDATA] = {.type = NLA_UNSPEC }, [OVS_USERSPACE_ATTR_EGRESS_TUN_PORT] = {.type = NLA_U32 }, + [OVS_USERSPACE_ATTR_ACTIONS] = {.type = NLA_FLAG }, + [OVS_USERSPACE_ATTR_MCAST] = {.type = NLA_FLAG }, }; struct nlattr *a[OVS_USERSPACE_ATTR_MAX + 1]; int error; @@ -3052,8 +3054,8 @@ static int validate_userspace(const struct nlattr *attr) if (error) return error; - if (!a[OVS_USERSPACE_ATTR_PID] || - !nla_get_u32(a[OVS_USERSPACE_ATTR_PID])) + if (!a[OVS_USERSPACE_ATTR_MCAST] && (!a[OVS_USERSPACE_ATTR_PID] || + !nla_get_u32(a[OVS_USERSPACE_ATTR_PID]))) return -EINVAL; return 0; From patchwork Thu Mar 7 15:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1909317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ibj2t8IJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrCdH6WDtz23hR for ; Fri, 8 Mar 2024 02:19:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3F4AE610AA; Thu, 7 Mar 2024 15:19:13 +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 1uoEYueKEioS; Thu, 7 Mar 2024 15:19:11 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B803F61050 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ibj2t8IJ Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id B803F61050; Thu, 7 Mar 2024 15:19:07 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 26A5FC0DD9; Thu, 7 Mar 2024 15:19:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 02D96C0DD4 for ; Thu, 7 Mar 2024 15:19:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 47A426103C for ; Thu, 7 Mar 2024 15:19:04 +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 fKoY2OQbYKjW for ; Thu, 7 Mar 2024 15:19:03 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 65C1161028 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 65C1161028 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 65C1161028 for ; Thu, 7 Mar 2024 15:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tgWIo+01yUmFTfU9I51yM2BY83EjFcVmrwEVieX5L6k=; b=ibj2t8IJlyT4yNSFdyAsGb2BADvWCjCCd/h/mnIsBstY38p80Broa6JTD00I2JBud31VsY yuJeRX3OWCGJLbV3mRNvwnyXxYihoMn6AquibMli7cHTYNrRD+e+fczDw2AmgrjaRlFYxH ctzb3EkjNLHF8TAGjfubwnIA86g5nfc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-sam_km4wNbaX2iHTQBUDhg-1; Thu, 07 Mar 2024 10:18:56 -0500 X-MC-Unique: sam_km4wNbaX2iHTQBUDhg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 710EF29AB42E; Thu, 7 Mar 2024 15:18:56 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.194.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF6A12166B33; Thu, 7 Mar 2024 15:18:54 +0000 (UTC) From: Adrian Moreno To: netdev@vger.kernel.org, dev@openvswitch.org Date: Thu, 7 Mar 2024 16:18:46 +0100 Message-ID: <20240307151849.394962-3-amorenoz@redhat.com> In-Reply-To: <20240307151849.394962-1-amorenoz@redhat.com> References: <20240307151849.394962-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Cc: yotam.gi@gmail.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC PATCH 2/4] openvswitch:trace: Add ovs_dp_monitor tracepoint. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The existing dp_upcall tracepoint was intented to provide visibility on flow-misses (what we typically refer as upcalls). It's used to measure things like upcall latency. However, if a monitoring userspace action (such as IPFIX) is multicasted, using the same tracepoint will only add confusion as ovs-vswithcd will not receive this upcall. In order to make things clearer, create a new tracepoint called "ovs_dp_monitor" and use it instead of the existing one for multicasted packets. Signed-off-by: Adrian Moreno --- net/openvswitch/datapath.c | 6 ++- net/openvswitch/openvswitch_trace.h | 71 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 15bad6f4b645..5a2c0b3b4112 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -316,12 +316,16 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, const struct dp_upcall_info *upcall_info, uint32_t cutlen) { + const bool mcast = upcall_info->portid == MCAST_PID; struct dp_stats_percpu *stats; int err; - if (trace_ovs_dp_upcall_enabled()) + if (!mcast && trace_ovs_dp_upcall_enabled()) trace_ovs_dp_upcall(dp, skb, key, upcall_info); + if (mcast && trace_ovs_dp_monitor_enabled()) + trace_ovs_dp_monitor(dp, skb, key, upcall_info); + if (upcall_info->portid == 0) { err = -ENOTCONN; goto err; diff --git a/net/openvswitch/openvswitch_trace.h b/net/openvswitch/openvswitch_trace.h index 3eb35d9eb700..76e9612e3555 100644 --- a/net/openvswitch/openvswitch_trace.h +++ b/net/openvswitch/openvswitch_trace.h @@ -148,6 +148,77 @@ TRACE_EVENT(ovs_dp_upcall, __entry->upcall_mru) ); +TRACE_EVENT(ovs_dp_monitor, + + TP_PROTO(struct datapath *dp, struct sk_buff *skb, + const struct sw_flow_key *key, + const struct dp_upcall_info *upcall_info), + + TP_ARGS(dp, skb, key, upcall_info), + + TP_STRUCT__entry( + __field( void *, dpaddr ) + __string( dp_name, ovs_dp_name(dp) ) + __string( dev_name, skb->dev->name ) + __field( void *, skbaddr ) + __field( unsigned int, len ) + __field( unsigned int, data_len ) + __field( unsigned int, truesize ) + __field( u8, nr_frags ) + __field( u16, gso_size ) + __field( u16, gso_type ) + __field( u32, ovs_flow_hash ) + __field( u32, recirc_id ) + __field( const void *, keyaddr ) + __field( u16, key_eth_type ) + __field( u8, key_ct_state ) + __field( u8, key_ct_orig_proto ) + __field( u16, key_ct_zone ) + __field( unsigned int, flow_key_valid ) + __field( u32, upcall_port ) + __field( void *, upcall_udata ) + __field( u16, upcall_ulen ) + ), + + TP_fast_assign( + __entry->dpaddr = dp; + __assign_str(dp_name, ovs_dp_name(dp)); + __assign_str(dev_name, skb->dev->name); + __entry->skbaddr = skb; + __entry->len = skb->len; + __entry->data_len = skb->data_len; + __entry->truesize = skb->truesize; + __entry->nr_frags = skb_shinfo(skb)->nr_frags; + __entry->gso_size = skb_shinfo(skb)->gso_size; + __entry->gso_type = skb_shinfo(skb)->gso_type; + __entry->ovs_flow_hash = key->ovs_flow_hash; + __entry->recirc_id = key->recirc_id; + __entry->keyaddr = key; + __entry->key_eth_type = key->eth.type; + __entry->key_ct_state = key->ct_state; + __entry->key_ct_orig_proto = key->ct_orig_proto; + __entry->key_ct_zone = key->ct_zone; + __entry->flow_key_valid = !(key->mac_proto & SW_FLOW_KEY_INVALID); + __entry->upcall_port = upcall_info->portid; + __entry->upcall_udata = upcall_info->userdata ? + nla_data(upcall_info->userdata): NULL; + __entry->upcall_ulen = upcall_info->userdata ? + nla_len(upcall_info->userdata): 0; + ), + + TP_printk("dpaddr=%p dp_name=%s dev=%s skbaddr=%p len=%u data_len=%u truesize=%u nr_frags=%d gso_size=%d gso_type=%#x ovs_flow_hash=0x%08x recirc_id=0x%08x keyaddr=%p eth_type=0x%04x ct_state=%02x ct_orig_proto=%02x ct_zone=%04x flow_key_valid=%d upcall_port=%u upcall_udata=%p upcall_ulen=%d", + __entry->dpaddr, __get_str(dp_name), __get_str(dev_name), + __entry->skbaddr, __entry->len, __entry->data_len, + __entry->truesize, __entry->nr_frags, __entry->gso_size, + __entry->gso_type, __entry->ovs_flow_hash, + __entry->recirc_id, __entry->keyaddr, __entry->key_eth_type, + __entry->key_ct_state, __entry->key_ct_orig_proto, + __entry->key_ct_zone, + __entry->flow_key_valid, + __entry->upcall_port, + __entry->upcall_udata, __entry->upcall_ulen) +); + #endif /* _TRACE_OPENVSWITCH_H */ /* This part must be outside protection */ From patchwork Thu Mar 7 15:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1909316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AQrGDle3; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrCdF1z1qz23hR for ; Fri, 8 Mar 2024 02:19:13 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 1566141BB4; Thu, 7 Mar 2024 15:19:11 +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 lfqUGkIGm4wU; Thu, 7 Mar 2024 15:19:08 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 8E1FA41B98 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AQrGDle3 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8E1FA41B98; Thu, 7 Mar 2024 15:19:08 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D0986C0DD5; Thu, 7 Mar 2024 15:19:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1AA26C0DD7 for ; Thu, 7 Mar 2024 15:19:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E4E2041BEF for ; Thu, 7 Mar 2024 15:19:04 +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 goq7ae-sKuEB for ; Thu, 7 Mar 2024 15:19:04 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 35D1C41BCD Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 35D1C41BCD Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AQrGDle3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 35D1C41BCD for ; Thu, 7 Mar 2024 15:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gIW3JyZh1fUFBM3pmhtVMUMIH3+B+DvwKnOOaDtsKkY=; b=AQrGDle3pZXg2Cc1rPvCDVQL47QSAYkWVE/BMlebX2PwbfFaQCSoSTo/O1hfkqwD/QAdgg iKu8swsToufR91CI3MdsVewk+eByMg3TnKl7yIV+lHd0HpaBNjXe9vl+NNa+n7tZe/N+D0 XxzQ3YcvSuTAVdqwH7dWleJ0oR/CvQQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-gU3X7Bb4M6qhkm3DDtoInA-1; Thu, 07 Mar 2024 10:18:58 -0500 X-MC-Unique: gU3X7Bb4M6qhkm3DDtoInA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34FB08007A7; Thu, 7 Mar 2024 15:18:58 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.194.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFD152166AF0; Thu, 7 Mar 2024 15:18:56 +0000 (UTC) From: Adrian Moreno To: netdev@vger.kernel.org, dev@openvswitch.org Date: Thu, 7 Mar 2024 16:18:47 +0100 Message-ID: <20240307151849.394962-4-amorenoz@redhat.com> In-Reply-To: <20240307151849.394962-1-amorenoz@redhat.com> References: <20240307151849.394962-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Cc: yotam.gi@gmail.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC PATCH 3/4] net:openvswitch: Avoid extra copy if no listeners. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" If there are no listeneres in the multicast group, there is no need for building the upcall packet. Exit early in that case. Signed-off-by: Adrian Moreno --- net/openvswitch/datapath.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 5a2c0b3b4112..5171aefa6a7c 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -455,6 +455,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, if (!dp_ifindex) return -ENODEV; + if (upcall_info->portid == MCAST_PID && + !genl_has_listeners(&dp_packet_genl_family, ovs_dp_get_net(dp), 0)) + return 0; + if (skb_vlan_tag_present(skb)) { nskb = skb_clone(skb, GFP_ATOMIC); if (!nskb) From patchwork Thu Mar 7 15:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1909319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ewVBJRZR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrCdL5ftHz23qT for ; Fri, 8 Mar 2024 02:19:18 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0461761083; Thu, 7 Mar 2024 15:19:16 +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 v-pO3eaneDEM; Thu, 7 Mar 2024 15:19:13 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 637CB61046 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ewVBJRZR Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 637CB61046; Thu, 7 Mar 2024 15:19:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 05F19C0DD4; Thu, 7 Mar 2024 15:19:10 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 186D8C0DD6 for ; Thu, 7 Mar 2024 15:19:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9491A82C8E for ; Thu, 7 Mar 2024 15:19:06 +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 89AjUQ2Z1FXk for ; Thu, 7 Mar 2024 15:19:05 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org D7C3F82C8F Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org D7C3F82C8F Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ewVBJRZR Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id D7C3F82C8F for ; Thu, 7 Mar 2024 15:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9jmx+YaI5ayJ4tS4SNgOtRv03CU7/WTXqQ4vzYMtif0=; b=ewVBJRZRg4WijBMOENCHWq6uY2tTxkAH+Miu1iaEQhc2JN+OeiqcjDXuec8tzBFcjo54/y FyFL8KQcPfPi87UzXr1czd+PKCjNNIfVf+1nzvK1/qFJHsrHDobp/zOHm2Cqs8hCMPPgPX b90jqyK2Z/Zn2dEh8BBu5CBalu+hiao= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-NueeuX66MhS-rXX-TYIB5Q-1; Thu, 07 Mar 2024 10:19:00 -0500 X-MC-Unique: NueeuX66MhS-rXX-TYIB5Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC96B811E81; Thu, 7 Mar 2024 15:18:59 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.194.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72FF92166B33; Thu, 7 Mar 2024 15:18:58 +0000 (UTC) From: Adrian Moreno To: netdev@vger.kernel.org, dev@openvswitch.org Date: Thu, 7 Mar 2024 16:18:48 +0100 Message-ID: <20240307151849.394962-5-amorenoz@redhat.com> In-Reply-To: <20240307151849.394962-1-amorenoz@redhat.com> References: <20240307151849.394962-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Cc: yotam.gi@gmail.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC PATCH 4/4] net:openvswitch: Add multicasted packets to stats X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" If we mix multicasted and unicasted statistics, there could be a serious discrepancy between the stats reported by the kernel and the ones read by userspace, leading to increased confusion. Signed-off-by: Adrian Moreno --- include/uapi/linux/openvswitch.h | 2 ++ net/openvswitch/datapath.c | 9 ++++++--- net/openvswitch/vport.c | 8 ++++++++ net/openvswitch/vport.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index 77525a1c648a..25e35b627fe5 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -288,10 +288,12 @@ enum ovs_vport_attr { * enum ovs_vport_upcall_attr - attributes for %OVS_VPORT_UPCALL* commands * @OVS_VPORT_UPCALL_SUCCESS: 64-bit upcall success packets. * @OVS_VPORT_UPCALL_FAIL: 64-bit upcall fail packets. + * @OVS_VPORT_UPCALL_MCAST: 64-bit multicasted upcall packets. */ enum ovs_vport_upcall_attr { OVS_VPORT_UPCALL_ATTR_SUCCESS, OVS_VPORT_UPCALL_ATTR_FAIL, + OVS_VPORT_UPCALL_ATTR_MCAST, __OVS_VPORT_UPCALL_ATTR_MAX }; diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 5171aefa6a7c..a457a07adb52 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -217,7 +217,7 @@ static struct vport *new_vport(const struct vport_parms *parms) static void ovs_vport_update_upcall_stats(struct sk_buff *skb, const struct dp_upcall_info *upcall_info, - bool upcall_result) + bool mcast, bool upcall_result) { struct vport *p = OVS_CB(skb)->input_vport; struct vport_upcall_stats_percpu *stats; @@ -229,7 +229,10 @@ static void ovs_vport_update_upcall_stats(struct sk_buff *skb, stats = this_cpu_ptr(p->upcall_stats); u64_stats_update_begin(&stats->syncp); if (upcall_result) - u64_stats_inc(&stats->n_success); + if (mcast) + u64_stats_inc(&stats->n_mcast); + else + u64_stats_inc(&stats->n_success); else u64_stats_inc(&stats->n_fail); u64_stats_update_end(&stats->syncp); @@ -336,7 +339,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, else err = queue_gso_packets(dp, skb, key, upcall_info, cutlen); - ovs_vport_update_upcall_stats(skb, upcall_info, !err); + ovs_vport_update_upcall_stats(skb, upcall_info, mcast, !err); if (err) goto err; diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 972ae01a70f7..b78287e443d1 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c @@ -315,6 +315,7 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb) __u64 tx_success = 0; __u64 tx_fail = 0; + __u64 mcast = 0; for_each_possible_cpu(i) { const struct vport_upcall_stats_percpu *stats; @@ -325,6 +326,7 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb) start = u64_stats_fetch_begin(&stats->syncp); tx_success += u64_stats_read(&stats->n_success); tx_fail += u64_stats_read(&stats->n_fail); + mcast += u64_stats_read(&stats->n_mcast); } while (u64_stats_fetch_retry(&stats->syncp, start)); } @@ -343,6 +345,12 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb) nla_nest_cancel(skb, nla); return -EMSGSIZE; } + + if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_ATTR_MCAST, mcast, + OVS_VPORT_ATTR_PAD)) { + nla_nest_cancel(skb, nla); + return -EMSGSIZE; + } nla_nest_end(skb, nla); return 0; diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h index 3e71ca8ad8a7..e9817b2b3b61 100644 --- a/net/openvswitch/vport.h +++ b/net/openvswitch/vport.h @@ -151,6 +151,7 @@ struct vport_upcall_stats_percpu { struct u64_stats_sync syncp; u64_stats_t n_success; u64_stats_t n_fail; + u64_stats_t n_mcast; }; struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,