From patchwork Tue Apr 26 08:05:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhou Jie X-Patchwork-Id: 8935821 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 60DBA9F441 for ; Tue, 26 Apr 2016 08:06:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B444D20142 for ; Tue, 26 Apr 2016 08:06:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F207320125 for ; Tue, 26 Apr 2016 08:06:16 +0000 (UTC) Received: from localhost ([::1]:36796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auy0e-0005ah-5S for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Apr 2016 04:06:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auy0P-0005RD-IC for qemu-devel@nongnu.org; Tue, 26 Apr 2016 04:06:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1auy0I-0008Vd-GN for qemu-devel@nongnu.org; Tue, 26 Apr 2016 04:06:01 -0400 Received: from [59.151.112.132] (port=1913 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auy0H-0008NK-Nu; Tue, 26 Apr 2016 04:05:54 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="5962978" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Apr 2016 16:05:42 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 7968E408D262; Tue, 26 Apr 2016 16:05:37 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.45) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Tue, 26 Apr 2016 16:05:37 +0800 From: Zhou Jie To: Date: Tue, 26 Apr 2016 16:05:24 +0800 Message-ID: <1461657924-1933-1-git-send-email-zhoujie2011@cn.fujitsu.com> X-Mailer: git-send-email 2.5.5 MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-yoursite-MailScanner-ID: 7968E408D262.A8A2D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhoujie2011@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH] hw/net/virtio-net: Allocating Large sized arrays to heap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Zhou Jie , mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP virtio_net_flush_tx has a huge stack usage of 16392 bytes approx. Moving large arrays to heap to reduce stack usage. Signed-off-by: Zhou Jie --- hw/net/virtio-net.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 5798f87..cab7bbc 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1213,6 +1213,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) VirtIONet *n = q->n; VirtIODevice *vdev = VIRTIO_DEVICE(n); VirtQueueElement *elem; + struct iovec *sg = NULL, *sg2 = NULL; int32_t num_packets = 0; int queue_index = vq2q(virtio_get_queue_index(q->tx_vq)); if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { @@ -1224,10 +1225,12 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) return num_packets; } + sg = g_new(struct iovec, VIRTQUEUE_MAX_SIZE); + sg2 = g_new(struct iovec, VIRTQUEUE_MAX_SIZE + 1); for (;;) { ssize_t ret; unsigned int out_num; - struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE + 1], *out_sg; + struct iovec *out_sg; struct virtio_net_hdr_mrg_rxbuf mhdr; elem = virtqueue_pop(q->tx_vq, sizeof(VirtQueueElement)); @@ -1252,7 +1255,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) virtio_net_hdr_swap(vdev, (void *) &mhdr); sg2[0].iov_base = &mhdr; sg2[0].iov_len = n->guest_hdr_len; - out_num = iov_copy(&sg2[1], ARRAY_SIZE(sg2) - 1, + out_num = iov_copy(&sg2[1], VIRTQUEUE_MAX_SIZE, out_sg, out_num, n->guest_hdr_len, -1); if (out_num == VIRTQUEUE_MAX_SIZE) { @@ -1269,10 +1272,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) */ assert(n->host_hdr_len <= n->guest_hdr_len); if (n->host_hdr_len != n->guest_hdr_len) { - unsigned sg_num = iov_copy(sg, ARRAY_SIZE(sg), + unsigned sg_num = iov_copy(sg, VIRTQUEUE_MAX_SIZE, out_sg, out_num, 0, n->host_hdr_len); - sg_num += iov_copy(sg + sg_num, ARRAY_SIZE(sg) - sg_num, + sg_num += iov_copy(sg + sg_num, VIRTQUEUE_MAX_SIZE - sg_num, out_sg, out_num, n->guest_hdr_len, -1); out_num = sg_num; @@ -1284,6 +1287,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) if (ret == 0) { virtio_queue_set_notification(q->tx_vq, 0); q->async_tx.elem = elem; + g_free(sg); + g_free(sg2); return -EBUSY; } @@ -1296,6 +1301,8 @@ drop: break; } } + g_free(sg); + g_free(sg2); return num_packets; }