From patchwork Thu Jun 29 20:30:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 13297287 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 4AC1E23C8E for ; Thu, 29 Jun 2023 20:31:18 +0000 (UTC) X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 29 Jun 2023 13:31:16 PDT Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41780213D for ; Thu, 29 Jun 2023 13:31:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244--k4yb8QzN_eDwI-TdIp0Ew-1; Thu, 29 Jun 2023 16:30:08 -0400 X-MC-Unique: -k4yb8QzN_eDwI-TdIp0Ew-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D98C11C07542; Thu, 29 Jun 2023 20:30:05 +0000 (UTC) Received: from wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com (wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com [10.19.188.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id B843DC00049; Thu, 29 Jun 2023 20:30:05 +0000 (UTC) From: Eric Garver To: netdev@vger.kernel.org Cc: dev@openvswitch.org, Pravin B Shelar , Ilya Maximets Subject: [PATCH net-next 1/2] net: openvswitch: add drop reasons Date: Thu, 29 Jun 2023 16:30:04 -0400 Message-Id: <20230629203005.2137107-2-eric@garver.life> In-Reply-To: <20230629203005.2137107-1-eric@garver.life> References: <20230629203005.2137107-1-eric@garver.life> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: garver.life X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,FROM_SUSPICIOUS_NTLD, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org These are counterparts to userspace's xlate_error values. Signed-off-by: Eric Garver --- include/net/dropreason.h | 6 ++++++ net/openvswitch/datapath.c | 17 +++++++++++++++++ net/openvswitch/drop.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 net/openvswitch/drop.h diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 685fb37df8e8..653675bba758 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -23,6 +23,12 @@ enum skb_drop_reason_subsys { */ SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR, + /** + * @SKB_DROP_REASON_SUBSYS_OPENVSWITCH: openvswitch drop reasons + * see net/openvswitch/drop.h + */ + SKB_DROP_REASON_SUBSYS_OPENVSWITCH, + /** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ SKB_DROP_REASON_SUBSYS_NUM }; diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index a6d2a0b1aa21..4ebdc52856ab 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -48,6 +48,7 @@ #include "openvswitch_trace.h" #include "vport-internal_dev.h" #include "vport-netdev.h" +#include "drop.h" unsigned int ovs_net_id __read_mostly; @@ -2702,6 +2703,18 @@ static struct pernet_operations ovs_net_ops = { .size = sizeof(struct ovs_net), }; +static const char * const ovs_drop_reasons[] = { + [0] = "OVS_XLATE_OK", +#define S(x) #x, + OVS_DROP_REASONS(S) +#undef S +}; + +static struct drop_reason_list drop_reason_list_ovs = { + .reasons = ovs_drop_reasons, + .n_reasons = ARRAY_SIZE(ovs_drop_reasons), +}; + static int __init dp_init(void) { int err; @@ -2743,6 +2756,9 @@ static int __init dp_init(void) if (err < 0) goto error_unreg_netdev; + drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_OPENVSWITCH, + &drop_reason_list_ovs); + return 0; error_unreg_netdev: @@ -2769,6 +2785,7 @@ static void dp_cleanup(void) ovs_netdev_exit(); unregister_netdevice_notifier(&ovs_dp_device_notifier); unregister_pernet_device(&ovs_net_ops); + drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_OPENVSWITCH); rcu_barrier(); ovs_vport_exit(); ovs_flow_exit(); diff --git a/net/openvswitch/drop.h b/net/openvswitch/drop.h new file mode 100644 index 000000000000..787eda0083c1 --- /dev/null +++ b/net/openvswitch/drop.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * openvswitch drop reason list + */ + +#ifndef OPENVSWITCH_DROP_H +#define OPENVSWITCH_DROP_H +#include + +/* these are counterparts to userspace xlate_error */ +#define OVS_DROP_REASONS(R) \ + R(OVS_XLATE_BRIDGE_NOT_FOUND) \ + R(OVS_XLATE_RECURSION_TOO_DEEP) \ + R(OVS_XLATE_TOO_MANY_RESUBMITS) \ + R(OVS_XLATE_STACK_TOO_DEEP) \ + R(OVS_XLATE_NO_RECIRCULATION_CONTEXT) \ + R(OVS_XLATE_RECIRCULATION_CONFLICT) \ + R(OVS_XLATE_TOO_MANY_MPLS_LABELS) \ + R(OVS_XLATE_INVALID_TUNNEL_METADATA) \ + R(OVS_XLATE_UNSUPPORTED_PACKET_TYPE) \ + R(OVS_XLATE_CONGESTION_DROP) \ + R(OVS_XLATE_FORWARDING_DISABLED) \ + /* deliberate comment for trailing \ */ + +enum ovs_drop_reason { + OVS_XLATE_OK = SKB_DROP_REASON_SUBSYS_OPENVSWITCH << + SKB_DROP_REASON_SUBSYS_SHIFT, +#define ENUM(x) x, + OVS_DROP_REASONS(ENUM) +#undef ENUM + OVS_XLATE_MAX, +}; + +#endif /* OPENVSWITCH_DROP_H */ From patchwork Thu Jun 29 20:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 13297289 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 BF658171CC for ; Thu, 29 Jun 2023 20:32:03 +0000 (UTC) Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFC3E30DF for ; Thu, 29 Jun 2023 13:32:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-VV3UmycvMBqzWEaIfccp4Q-1; Thu, 29 Jun 2023 16:30:08 -0400 X-MC-Unique: VV3UmycvMBqzWEaIfccp4Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E7FC1C07546; Thu, 29 Jun 2023 20:30:06 +0000 (UTC) Received: from wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com (wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com [10.19.188.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E138CC00049; Thu, 29 Jun 2023 20:30:05 +0000 (UTC) From: Eric Garver To: netdev@vger.kernel.org Cc: dev@openvswitch.org, Pravin B Shelar , Ilya Maximets Subject: [PATCH net-next 2/2] net: openvswitch: add drop action Date: Thu, 29 Jun 2023 16:30:05 -0400 Message-Id: <20230629203005.2137107-3-eric@garver.life> In-Reply-To: <20230629203005.2137107-1-eric@garver.life> References: <20230629203005.2137107-1-eric@garver.life> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: garver.life X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,FROM_SUSPICIOUS_NTLD, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org This adds an explicit drop action. This is used by OVS to drop packets for which it cannot determine what to do. An explicit action in the kernel allows passing the reason _why_ the packet is being dropped. We can then use perf tracing to match on the drop reason. e.g. trace all OVS dropped skbs # perf trace -e skb:kfree_skb --filter="reason >= 0x30000" [..] 106.023 ping/2465 skb:kfree_skb(skbaddr: 0xffffa0e8765f2000, \ location:0xffffffffc0d9b462, protocol: 2048, reason: 196610) reason: 196610 --> 0x30002 (OVS_XLATE_RECURSION_TOO_DEEP) Signed-off-by: Eric Garver --- include/uapi/linux/openvswitch.h | 2 ++ net/openvswitch/actions.c | 13 +++++++++++++ net/openvswitch/flow_netlink.c | 12 +++++++++++- .../testing/selftests/net/openvswitch/ovs-dpctl.py | 3 +++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index e94870e77ee9..a967dbca3574 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -965,6 +965,7 @@ struct check_pkt_len_arg { * start of the packet or at the start of the l3 header depending on the value * of l3 tunnel flag in the tun_flags field of OVS_ACTION_ATTR_ADD_MPLS * argument. + * @OVS_ACTION_ATTR_DROP: Explicit drop action. * * Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all * fields within a header are modifiable, e.g. the IPv4 protocol and fragment @@ -1002,6 +1003,7 @@ enum ovs_action_attr { OVS_ACTION_ATTR_CHECK_PKT_LEN, /* Nested OVS_CHECK_PKT_LEN_ATTR_*. */ OVS_ACTION_ATTR_ADD_MPLS, /* struct ovs_action_add_mpls. */ OVS_ACTION_ATTR_DEC_TTL, /* Nested OVS_DEC_TTL_ATTR_*. */ + OVS_ACTION_ATTR_DROP, /* u32 xlate_error. */ __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted * from userspace. */ diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index cab1e02b63e0..4ad9a45dc042 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -32,6 +32,7 @@ #include "vport.h" #include "flow_netlink.h" #include "openvswitch_trace.h" +#include "drop.h" struct deferred_action { struct sk_buff *skb; @@ -1477,6 +1478,18 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, return dec_ttl_exception_handler(dp, skb, key, a); break; + + case OVS_ACTION_ATTR_DROP: + u32 reason = nla_get_u32(a); + + reason |= SKB_DROP_REASON_SUBSYS_OPENVSWITCH << + SKB_DROP_REASON_SUBSYS_SHIFT; + + if (reason == OVS_XLATE_OK) + break; + + kfree_skb_reason(skb, reason); + return 0; } if (unlikely(err)) { diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index 41116361433d..23d39eae9a0d 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -39,6 +39,7 @@ #include #include "flow_netlink.h" +#include "drop.h" struct ovs_len_tbl { int len; @@ -61,6 +62,7 @@ static bool actions_may_change_flow(const struct nlattr *actions) case OVS_ACTION_ATTR_RECIRC: case OVS_ACTION_ATTR_TRUNC: case OVS_ACTION_ATTR_USERSPACE: + case OVS_ACTION_ATTR_DROP: break; case OVS_ACTION_ATTR_CT: @@ -2394,7 +2396,7 @@ static void ovs_nla_free_nested_actions(const struct nlattr *actions, int len) /* Whenever new actions are added, the need to update this * function should be considered. */ - BUILD_BUG_ON(OVS_ACTION_ATTR_MAX != 23); + BUILD_BUG_ON(OVS_ACTION_ATTR_MAX != 24); if (!actions) return; @@ -3182,6 +3184,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, [OVS_ACTION_ATTR_CHECK_PKT_LEN] = (u32)-1, [OVS_ACTION_ATTR_ADD_MPLS] = sizeof(struct ovs_action_add_mpls), [OVS_ACTION_ATTR_DEC_TTL] = (u32)-1, + [OVS_ACTION_ATTR_DROP] = sizeof(u32), }; const struct ovs_action_push_vlan *vlan; int type = nla_type(a); @@ -3453,6 +3456,13 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, skip_copy = true; break; + case OVS_ACTION_ATTR_DROP: + if (nla_get_u32(a) >= + u32_get_bits(OVS_XLATE_MAX, + ~SKB_DROP_REASON_SUBSYS_MASK)) + return -EINVAL; + break; + default: OVS_NLERR(log, "Unknown Action type %d", type); return -EINVAL; diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py index 1c8b36bc15d4..526ebad7d514 100644 --- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py +++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py @@ -115,6 +115,7 @@ class ovsactions(nla): ("OVS_ACTION_ATTR_CHECK_PKT_LEN", "none"), ("OVS_ACTION_ATTR_ADD_MPLS", "none"), ("OVS_ACTION_ATTR_DEC_TTL", "none"), + ("OVS_ACTION_ATTR_DROP", "uint32"), ) class ctact(nla): @@ -261,6 +262,8 @@ class ovsactions(nla): print_str += "recirc(0x%x)" % int(self.get_attr(field[0])) elif field[0] == "OVS_ACTION_ATTR_TRUNC": print_str += "trunc(%d)" % int(self.get_attr(field[0])) + elif field[0] == "OVS_ACTION_ATTR_DROP": + print_str += "drop" elif field[1] == "flag": if field[0] == "OVS_ACTION_ATTR_CT_CLEAR": print_str += "ct_clear"