From patchwork Thu Nov 14 15:51:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1194943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NxOmhaFe"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47DQvL4t1Qz9sP4 for ; Fri, 15 Nov 2019 02:51:26 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4CFB7C9F; Thu, 14 Nov 2019 15:51:24 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 63B50B3E for ; Thu, 14 Nov 2019 15:51:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 64B378AE for ; Thu, 14 Nov 2019 15:51:22 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id l24so4012944pgh.10 for ; Thu, 14 Nov 2019 07:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=MA+53mahoGl8KhUYSwJ0ekQMhhMNkVpkRAS9r6tNXO8=; b=NxOmhaFe22NCdX210hO4v4RpSrqDf14q/G8huEm3xkP+qyEllfMWy52RGOVNV5MbEP kDtv5c6tIau+sw3wS3UFSE06T9c8AjT2Mna4Ov1Qzk0ed5ZQTmvU5owRM/mc0CItb3Ge hD4c3I9ikA9c/hftu/NB98z04T/jkfVGNu3MbtPX8dOT3h+npSULwwWlD8To5gqLzn1j MhHELP9Quxg7tfPhUf+HOhakizcQwCv0hnfcf3B4ozG0ko38iEdzZWhC28kQb85AEcTF hYuTkySipx891WjLH5heqmpSxu2H4g7a7T95iDK+Bcy10/3w1cI3Bc5bMSHHNBe1IN6z HEgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MA+53mahoGl8KhUYSwJ0ekQMhhMNkVpkRAS9r6tNXO8=; b=GczXKYDS7jnsuABJOLNdyhuT4EL7l2zG51lHihpkaPGUpNrC1wsLu6jQT5hfv3lO4K bfLSv7HC0BWvFMU9/X6eu0+1Z30b0x6s7/x5Fs8nW8B4+ZVPsh1vscAf7P1z9u20u9SO vyaxFeSDrPXhKA7L7r/xaI4X8EKJSGRy5XmOVqaHvCfbiBE8uTiVIxgu9Z4xeQ9YGFKq YySnbTctAkhc0PqAk169/nklLEvRNv09UnHvqqdOz2o5g9zmVlko+zDJKi1QIpZ4iW4g 5DpVRB7acOoyq3U7JAPW6oONt+NuDHX/NwynQLrqkM711cMsb/pAEsj3rlzSLMklwodF GVWA== X-Gm-Message-State: APjAAAUEE/D4d2/JjvhU1Qubr4EXEs7LD1d5O7oJX20lNDu3CjxbVtCU lDSG0b5V1b4SylRIi+6Y5bY= X-Google-Smtp-Source: APXvYqzrY1oL12EG0x6Hzknb34gwQIiReL4oHaq8opNYoK/d1Rofm4lNVgK0G62O7p5Hean5lc16sQ== X-Received: by 2002:a17:90a:77c3:: with SMTP id e3mr13654866pjs.14.1573746681923; Thu, 14 Nov 2019 07:51:21 -0800 (PST) Received: from local.opencloud.tech.localdomain ([115.171.60.86]) by smtp.gmail.com with ESMTPSA id c13sm6617409pfo.5.2019.11.14.07.51.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Nov 2019 07:51:21 -0800 (PST) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, gvrose8192@gmail.com Date: Thu, 14 Nov 2019 23:51:08 +0800 Message-Id: <1573746668-6920-1-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next] net: openvswitch: don't call pad_packet if not necessary X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Tonghao Zhang The nla_put_u16/nla_put_u32 makes sure that *attrlen is align. The call tree is that: nla_put_u16/nla_put_u32 -> nla_put attrlen = sizeof(u16) or sizeof(u32) -> __nla_put attrlen -> __nla_reserve attrlen -> skb_put(skb, nla_total_size(attrlen)) nla_total_size returns the total length of attribute including padding. Cc: Joe Stringer Cc: William Tu Signed-off-by: Tonghao Zhang --- net/openvswitch/datapath.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 8ce1f773378d..93d4991ddc1f 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -487,23 +487,17 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, } /* Add OVS_PACKET_ATTR_MRU */ - if (upcall_info->mru) { - if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, - upcall_info->mru)) { - err = -ENOBUFS; - goto out; - } - pad_packet(dp, user_skb); + if (upcall_info->mru && + nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, upcall_info->mru)) { + err = -ENOBUFS; + goto out; } /* Add OVS_PACKET_ATTR_LEN when packet is truncated */ - if (cutlen > 0) { - if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, - skb->len)) { - err = -ENOBUFS; - goto out; - } - pad_packet(dp, user_skb); + if (cutlen > 0 && + nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, skb->len)) { + err = -ENOBUFS; + goto out; } /* Add OVS_PACKET_ATTR_HASH */