Subject: [RFC PATCH 2/7] net: openvswitch: Reduce execute_push_nsh stack overhead

From: Nicholas Piggin <[email-masked]>
Date: Wed, 27 Sep 2023 10:13:03 +1000

Use dynamic allocation to reduce execute_push_nsh stack consumption
from 336 bytes to 64 bytes, at the cost of introducing a GFP_ATOMIC
allocation.

Signed-off-by: Nicholas Piggin <[email-masked]>
---
 net/openvswitch/actions.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 8933caa92794..af177701a606 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -1290,13 +1290,17 @@ static noinline_for_stack int execute_push_nsh(struct sk_buff *skb,
 					       struct sw_flow_key *key,
 					       const struct nlattr *attr)
 {
-	u8 buffer[NSH_HDR_MAX_LEN];
-	struct nshhdr *nh = (struct nshhdr *)buffer;
+	struct nshhdr *nh;
 	int err;
 
+	nh = kmalloc(NSH_HDR_MAX_LEN, GFP_ATOMIC);
+	if (unlikely(!nh))
+		return -ENOMEM; /* XXX: should this skip action like clone? */
+
 	err = nsh_hdr_from_nlattr(attr, nh, NSH_HDR_MAX_LEN);
 	if (likely(!err))
 		err = push_nsh(skb, key, nh);
+	kfree(nh);
 
 	return err;
 }
-- 
2.40.1