From patchwork Sun Mar 19 04:06:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Yasevich X-Patchwork-Id: 740644 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 3vm5B82WKwz9ryQ for ; Sun, 19 Mar 2017 15:06:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HffmbsV/"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751398AbdCSEGz (ORCPT ); Sun, 19 Mar 2017 00:06:55 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:36659 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751090AbdCSEGw (ORCPT ); Sun, 19 Mar 2017 00:06:52 -0400 Received: by mail-qk0-f193.google.com with SMTP id n141so14356838qke.3 for ; Sat, 18 Mar 2017 21:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9fM6a11RRDGjWEGd6OMcIO1IgeWu9ZCblwk8IkvkPbw=; b=HffmbsV/PVDOnmNuEwrU9JYICx1Kuw4dSRHqhMhwLzalYD8ukf/svOhJGZUGAKSIsF Pbgnt95fCFUafqGJLlPoMbluJHGfV/SbMvknKAeK2GXA0T2Tc6NdAhy8ms3Qje+0uzil ayLxO1DaUoEsp3AMMrxEvl5jHiTvEY/4yODDItKcb+ZmSxtHI6QSYpnU7FjXkkRCS0Yn ZldwaXB1Perr6BwlRVVhCHh/A3PGqMx2nCPxTcKziQiwSjajkm4xn8MhnXyrgnrSB6pk tJI6Oma+prE7mzzajWE3FXN5r+Bu43jSL+TQCuWsByWwlaEmhjv8Tnx9otI/En9JmPwS 2SAw== 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:in-reply-to :references; bh=9fM6a11RRDGjWEGd6OMcIO1IgeWu9ZCblwk8IkvkPbw=; b=QnnWTChQxyhwiPkXkXiuV4kFWTxNrGyWoKKKeXxJgM6PdhernMx3cwMzg6JLRctC0L 6FbHIQ2qSPu3ql9JJBSUACkfMr45bxgvsWUHqjrQkJHFRDBigse0dBlr+bL0RqPF8PXf 6XRF5Qx4Wy44oRDHea5Mn20SCIt9S/9eP9gSYLy0RfSy43whdH9usI1nykIYGQXGIUfv ygBVBaB6vIyYYDWUCjNFnIXSDPVhYZJ+c0BBpPKi3aY/hE7Nm7Bc2/DcA0++6+o6ayKw zdAsUY9nF3qxNtDC1SZZGpo+/J/Ghp0znx7tI8aQtkJlStz1yobKBvVWsYwKix4yx0cv bcMQ== X-Gm-Message-State: AFeK/H0NuktO1J8sF/qieabVEx3r2aH5keaPNQ18n4ICX0yzWyf7LZCQBwg6e65GsMxQCw== X-Received: by 10.55.20.67 with SMTP id e64mr18739560qkh.148.1489896410814; Sat, 18 Mar 2017 21:06:50 -0700 (PDT) Received: from flash.localdomain ([71.181.21.149]) by smtp.gmail.com with ESMTPSA id o14sm9534650qtc.46.2017.03.18.21.06.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Mar 2017 21:06:50 -0700 (PDT) From: Vladislav Yasevich X-Google-Original-From: Vladislav Yasevich To: netdev@vger.kernel.org Cc: virtualization@list.linux-foundation.org, mst@redhat.com, Vladislav Yasevich Subject: [RFC PATCH 1/6] virtio-net: Remove the use the padded vnet_header structure Date: Sun, 19 Mar 2017 00:06:32 -0400 Message-Id: <1489896397-2275-2-git-send-email-vyasevic@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489896397-2275-1-git-send-email-vyasevic@redhat.com> References: <1489896397-2275-1-git-send-email-vyasevic@redhat.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We can replace the structure with a properly aligned size instead. The current structure attempts to align on a 16 byte boundary, so preserve it. Signed-off-by: Vlad Yaseivch --- drivers/net/virtio_net.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 37db91d..78f459d 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -161,15 +161,20 @@ struct virtnet_info { u32 speed; }; -struct padded_vnet_hdr { - struct virtio_net_hdr_mrg_rxbuf hdr; +static inline u8 padded_vnet_hdr(struct virtnet_info *vi) +{ + u8 hdr_len = vi->hdr_len; + /* * hdr is in a separate sg buffer, and data sg buffer shares same page * with this header sg. This padding makes next sg 16 byte aligned * after the header. */ - char padding[4]; -}; + if (!vi->mergeable_rx_bufs) + hdr_len = __ALIGN_KERNEL_MASK(hdr_len, 15); + + return hdr_len; +} /* Converting between virtqueue no. and kernel tx/rx queue no. * 0:rx0 1:tx0 2:rx1 3:tx1 ... 2N:rxN 2N+1:txN 2N+2:cvq @@ -276,10 +281,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, hdr = skb_vnet_hdr(skb); hdr_len = vi->hdr_len; - if (vi->mergeable_rx_bufs) - hdr_padded_len = sizeof *hdr; - else - hdr_padded_len = sizeof(struct padded_vnet_hdr); + hdr_padded_len = padded_vnet_hdr(vi); memcpy(hdr, p, hdr_len); @@ -830,7 +832,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, sg_set_buf(&rq->sg[0], p, vi->hdr_len); /* rq->sg[1] for data packet, from offset */ - offset = sizeof(struct padded_vnet_hdr); + offset = padded_vnet_hdr(vi); sg_set_buf(&rq->sg[1], p + offset, PAGE_SIZE - offset); /* chain first in list head */ @@ -1698,8 +1700,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog) { - unsigned long int max_sz = PAGE_SIZE - sizeof(struct padded_vnet_hdr); struct virtnet_info *vi = netdev_priv(dev); + unsigned long int max_sz = PAGE_SIZE - padded_vnet_hdr(vi); struct bpf_prog *old_prog; u16 xdp_qp = 0, curr_qp; int i, err;