openvswitch: reduce stack usage in do_execute_actions
authorIlya Maximets <i.maximets@ovn.org>
Thu, 21 Sep 2023 19:42:35 +0000 (21:42 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 Oct 2023 18:07:22 +0000 (19:07 +0100)
do_execute_actions() function can be called recursively multiple
times while executing actions that require pipeline forking or
recirculations.  It may also be re-entered multiple times if the packet
leaves openvswitch module and re-enters it through a different port.

Currently, there is a 256-byte array allocated on stack in this
function that is supposed to hold NSH header.  Compilers tend to
pre-allocate that space right at the beginning of the function:

     a88:       48 81 ec b0 01 00 00    sub    $0x1b0,%rsp

NSH is not a very common protocol, but the space is allocated on every
recursive call or re-entry multiplying the wasted stack space.

Move the stack allocation to push_nsh() function that is only used
if NSH actions are actually present.  push_nsh() is also a simple
function without a possibility for re-entry, so the stack is returned
right away.

With this change the preallocated space is reduced by 256 B per call:

     b18:       48 81 ec b0 00 00 00    sub    $0xb0,%rsp

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Eelco Chaudron echaudro@redhat.com
Reviewed-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/openvswitch/actions.c

index 5f8094a..6fcd7e2 100644 (file)
@@ -311,11 +311,18 @@ static int push_eth(struct sk_buff *skb, struct sw_flow_key *key,
        return 0;
 }
 
-static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key,
-                   const struct nshhdr *nh)
+static noinline_for_stack int push_nsh(struct sk_buff *skb,
+                                      struct sw_flow_key *key,
+                                      const struct nlattr *a)
 {
+       u8 buffer[NSH_HDR_MAX_LEN];
+       struct nshhdr *nh = (struct nshhdr *)buffer;
        int err;
 
+       err = nsh_hdr_from_nlattr(a, nh, NSH_HDR_MAX_LEN);
+       if (err)
+               return err;
+
        err = nsh_push(skb, nh);
        if (err)
                return err;
@@ -1439,17 +1446,9 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                        err = pop_eth(skb, key);
                        break;
 
-               case OVS_ACTION_ATTR_PUSH_NSH: {
-                       u8 buffer[NSH_HDR_MAX_LEN];
-                       struct nshhdr *nh = (struct nshhdr *)buffer;
-
-                       err = nsh_hdr_from_nlattr(nla_data(a), nh,
-                                                 NSH_HDR_MAX_LEN);
-                       if (unlikely(err))
-                               break;
-                       err = push_nsh(skb, key, nh);
+               case OVS_ACTION_ATTR_PUSH_NSH:
+                       err = push_nsh(skb, key, nla_data(a));
                        break;
-               }
 
                case OVS_ACTION_ATTR_POP_NSH:
                        err = pop_nsh(skb, key);