From patchwork Tue Jul 22 10:19:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 372422 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 34A6B1400DD for ; Tue, 22 Jul 2014 20:32:42 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650AbaGVKcf (ORCPT ); Tue, 22 Jul 2014 06:32:35 -0400 Received: from na3sys009aog104.obsmtp.com ([74.125.149.73]:40105 "HELO na3sys009aog104.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754504AbaGVKcd (ORCPT ); Tue, 22 Jul 2014 06:32:33 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]) (using TLSv1) by na3sys009aob104.postini.com ([74.125.148.12]) with SMTP ID DSNKU849wYiSO/hcHjmyvZLq5Iam5ZGH9mWR@postini.com; Tue, 22 Jul 2014 03:32:33 PDT Received: by mail-pd0-f172.google.com with SMTP id ft15so10940978pdb.17 for ; Tue, 22 Jul 2014 03:32:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2GmSqfB1hd2/GTHPJYFko2v3W0kx2PaEIc/HLZAcvsY=; b=AxkWXaM1PIOrtQ+kuxJ++aZdgi54LM3IUe5K+utpNOu5u2DWsPslAO0ydfEKQ3uEns lNqogfnGq8BmJZYLzI1ciSHCV+8ySDIRJsyLCusiwxRnDPdia5b3EV8IJsF993h2Wpgj tDTRDJVUv8aP/XvTBnAPyz8jw8QCQS7xV7bd8YcPHyhfkaH9arJVy8CE1h0sz/oAe4p2 GK66LrJfobXySfK3MpAVQOHP2Ylc0TxpCpjTwD8qXlHJFiLGO34CL+k2mWRo5cwsLZ5K owoXtV+LULbPRE+jkTAQZ4AQtyV9eR0COqf4cZUqrd8E1LuYwUOTp8R2pQwKPpYovmWE Yf8w== X-Received: by 10.68.57.232 with SMTP id l8mr21314480pbq.79.1406024698402; Tue, 22 Jul 2014 03:24:58 -0700 (PDT) X-Gm-Message-State: ALoCoQkA88ID1D2R9vxdizwGTiDGW2kr8ukMg1nbm4KVVU/oMbIrXPRMAO3jLjnSNYz/U15q4KhEW7GhqvF5jYbPeAVFFiFRIf7BCEVwqkfcoIdh7rAwJRu+Y/YrMw08hF0/Zic58ZaK X-Received: by 10.68.57.232 with SMTP id l8mr21314476pbq.79.1406024698359; Tue, 22 Jul 2014 03:24:58 -0700 (PDT) Received: from andy-dev-pc.eng.vmware.com ([208.91.1.14]) by mx.google.com with ESMTPSA id xk1sm68087824pac.21.2014.07.22.03.24.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Jul 2014 03:24:57 -0700 (PDT) From: Andy Zhou To: davem@davemloft.net Cc: netdev@vger.kernel.org, Jesse Gross , Andy Zhou Subject: [net-next 09/10] openvswitch: Factor out allocation and verification of actions. Date: Tue, 22 Jul 2014 03:19:52 -0700 Message-Id: <1406024393-6778-10-git-send-email-azhou@nicira.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1406024393-6778-1-git-send-email-azhou@nicira.com> References: <1406024393-6778-1-git-send-email-azhou@nicira.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jesse Gross As the size of the flow key grows, it can put some pressure on the stack. This is particularly true in ovs_flow_cmd_set(), which needs several copies of the key on the stack. One of those uses is logically separate, so this factors it out to reduce stack pressure and improve readibility. Signed-off-by: Jesse Gross Signed-off-by: Andy Zhou --- net/openvswitch/datapath.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 0ddb189..daa935f 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -929,11 +929,34 @@ error: return error; } +static struct sw_flow_actions *get_flow_actions(const struct nlattr *a, + const struct sw_flow_key *key, + const struct sw_flow_mask *mask) +{ + struct sw_flow_actions *acts; + struct sw_flow_key masked_key; + int error; + + acts = ovs_nla_alloc_flow_actions(nla_len(a)); + if (IS_ERR(acts)) + return acts; + + ovs_flow_mask_key(&masked_key, key, mask); + error = ovs_nla_copy_actions(a, &masked_key, 0, &acts); + if (error) { + OVS_NLERR("Flow actions may not be safe on all matching packets.\n"); + kfree(acts); + return ERR_PTR(error); + } + + return acts; +} + static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info) { struct nlattr **a = info->attrs; struct ovs_header *ovs_header = info->userhdr; - struct sw_flow_key key, masked_key; + struct sw_flow_key key; struct sw_flow *flow; struct sw_flow_mask mask; struct sk_buff *reply = NULL; @@ -955,17 +978,10 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info) /* Validate actions. */ if (a[OVS_FLOW_ATTR_ACTIONS]) { - acts = ovs_nla_alloc_flow_actions(nla_len(a[OVS_FLOW_ATTR_ACTIONS])); - error = PTR_ERR(acts); - if (IS_ERR(acts)) + acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask); + if (IS_ERR(acts)) { + error = PTR_ERR(acts); goto error; - - ovs_flow_mask_key(&masked_key, &key, &mask); - error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], - &masked_key, 0, &acts); - if (error) { - OVS_NLERR("Flow actions may not be safe on all matching packets.\n"); - goto err_kfree_acts; } }