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: 13585869 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8CE212EBEE for ; Thu, 7 Mar 2024 15:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824741; cv=none; b=Wxg4AHTn/2CJrT5ZKyBVvs7XjDOPQKR1SzzaXewV1GujPbyrnmxUy03d0k06Ajokf8EhJJsFvCndXbzWf65SrE/SOVcqUlL5RVcQWrE63QNK52EeNFsdkms+BrhY4we6Hn7NonrawEQBFh5YD6TnGX7YhZt2ny+/6X0uMfsp2U8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824741; c=relaxed/simple; bh=eYbBcgQQpHaHj17bq7luIYk3vIVeQHh8Pm7j5u26JuE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RmKWYyv94ZbwrkB/ZDraKAAs6vkvBO3Sfcnbhb+E5xgiImzeAYPwmK0qSwBQcBbd2E6g5mkDmwf94b5XxPvtlPndX7bPiw/+985BRO9jfdYRTXmb7JRwm0qfqlgEAUR7UUZhwLlYNVGfuIjYuwxrwVYsGO50d/s1dhhAXh5Gc38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YRu90bBu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YRu90bBu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824738; 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=YRu90bBuGpiXf33ppRpCf+P67I+W+x0LfciZkYOWCM16zZHeIndIAYvVEgaLsGyTxR56BF SwmXjCVYHwhIqc5fo5opr7vFRq2DzBojozEFeUdyAJoiS4a8NfRzHqfCFaKvZzt99Ffrlx oUQZ1ajyY6Wehdgwkn+FLEbX5BdLKO8= 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 Cc: Adrian Moreno , cmi@nvidia.com, yotam.gi@gmail.com, i.maximets@ovn.org, aconole@redhat.com, echaudro@redhat.com, horms@kernel.org Subject: [RFC PATCH 1/4] net:openvswitch: Support multicasting userspace ... 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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: 13585870 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CE3B12F372 for ; Thu, 7 Mar 2024 15:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824743; cv=none; b=ZP4Cn/rQ33w569it0BIeB9l3Ch4xFFfBUifhHQaerlrzw7zmAjf6Jx74usRnZTFpY8ZCzQOEbIAooLWzPUDImU6YTJfV3YdYbcSA0HlK8DZMUzbw6D1eGyd04vqqU86J+cwm+w6WZw/t4YDEIQHH83+eNaIBsf9KOxM28S4O++M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824743; c=relaxed/simple; bh=sFGcwT4zSlXTAgrD64IPFUcwbdDcIM4g2pBbRPOSOvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kN4uNxAOy8deYMkZjCETJMEO0AOda8Aq82VUKAiefskw2IxuLUxDyVaVWl9xy30vauVqptskmCciJ9U3rlOBokUBJ3Ei7uiI/nyMuanOTXPlfY6GLZuJcgzSG5ZteP2cVJLWHsR9Pgw/e8P2FKpbgJYyXpBBdoQhsOclS0Bhk7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gH2GygwX; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gH2GygwX" 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=tgWIo+01yUmFTfU9I51yM2BY83EjFcVmrwEVieX5L6k=; b=gH2GygwXnTuyqFETcNPw8J7kY//YPj4FoppZuYJUTmrtXrpMshxCM2Qdxbj3v7QhP0gFe7 m3kmg8gGd6OnjJ/t+7wTD2kqMKwXHNnCzdVcGPGL0vmwKeT62rf2sGG34qg7bKOffwHxlA WmDhBFsC8ZGrEkGYeY/iFdZSsHPZe8c= 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 Cc: Adrian Moreno , cmi@nvidia.com, yotam.gi@gmail.com, i.maximets@ovn.org, aconole@redhat.com, echaudro@redhat.com, horms@kernel.org Subject: [RFC PATCH 2/4] openvswitch:trace: Add ovs_dp_monitor tracepoint. 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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: 13585871 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 537F912EBEE for ; Thu, 7 Mar 2024 15:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824744; cv=none; b=JFoRh6ea0gxivPxrTX0WlbFJaSxdNrtl07LSJJPwAv/9DBHrZIJZXKHrEXvg1yanXP4hxBRggmaMjuztsGY/9h8YC08pgD9dq8BlveIn2A/qz6VwoIbSsWkzv0OpShlGiwKOH7nnSS+zQ7SAHhD5I7z8RUCxblhDmGOvt3xaMb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824744; c=relaxed/simple; bh=F538wWwrWNGys6pnOQ9df4zbII3ziF8/UbjeRm0Fg7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pTcfngRBNVQdodo4qHSdVZhVJw0mkWE96KSIyxT29cXg1eqsl3mTXgQFkKzEEDnyZ4GQSEtCxYukrsFTNymrDsAveobm4l2ruREz3fmobUrB7JOzKHdNWNjBzOkfDB2PUJsUD+TE38xyQ+5hLSGr8vD+rWck7zZNK3xEkjhh/H0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Vpj2DKEw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vpj2DKEw" 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=gIW3JyZh1fUFBM3pmhtVMUMIH3+B+DvwKnOOaDtsKkY=; b=Vpj2DKEwKp0XfhRdzxpoSINwru0EEG1+6c94ZALWA89Veg1CzmkXl208MEd3bbOUJZ7haG 3KYTrt8G8E8H5FBhicn7c6FRg3L/ANKs+0m/IxaHNyq/UaLUksNlCiik7pRQj3pBwx8+ve A7q2CfhiZbCJmhf1VJtWPBdRbteHgDg= 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 Cc: Adrian Moreno , cmi@nvidia.com, yotam.gi@gmail.com, i.maximets@ovn.org, aconole@redhat.com, echaudro@redhat.com, horms@kernel.org Subject: [RFC PATCH 3/4] net:openvswitch: Avoid extra copy if no listeners. 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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: 13585872 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E34F512F581 for ; Thu, 7 Mar 2024 15:19:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824747; cv=none; b=AhDkKMg0zOuYrJ3bKk6CZYn9sm0e1S2/712tRTQbbR0Np/6rJxGb+CtIW/kHHQJKyeHkR9kW6l6s8tGg55a6arj+9kzVCKbVxvZ6Er0PmaVBkXzZADTmwZNai/uk97tdBb6zFfXyHFXj4VbASeqm2bX/YiaEETPGa3EBS336q9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824747; c=relaxed/simple; bh=t9Gyy9Rx+cUKRqNooyQyKo1PrlA/EIfkWgt00/0lX1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fpSFGwAKvmezk2Uf14WoFvnW5s1j7FmSo/Gy9t61X6SRVIUUHeSzukJaLxwFFbvyrYViVXiWzZgIJAj3dQMP2BZ1aAwFENM/kiQMueTGUpmMY1CFNDqFaUsp6xeIyIz5qD62Dc8MaEsuVAKcSEE160zWUijrW73f43jWh+gHrZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XBfDtxNc; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XBfDtxNc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709824744; 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=XBfDtxNcY0SabOoa7rY4Plx/A5rRiJkJDDYixQekCfo3AlDcjfxbzfmaaHHyToPtnXIBoc 6/bZFFVtK6PRiILG2yOYHST0Tfj1cpCUa4+wS3he7AW4gQa/wvVsG0JwFRxk/iX7TD95sd 9hSBSfo5gFMY50KWJXgsh28gI54fAck= 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 Cc: Adrian Moreno , cmi@nvidia.com, yotam.gi@gmail.com, i.maximets@ovn.org, aconole@redhat.com, echaudro@redhat.com, horms@kernel.org Subject: [RFC PATCH 4/4] net:openvswitch: Add multicasted packets to stats 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 *,