From patchwork Fri Mar 11 16:12:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaya Tiwari X-Patchwork-Id: 8569381 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D301BC0553 for ; Fri, 11 Mar 2016 21:50:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DF2142026D for ; Fri, 11 Mar 2016 21:50:33 +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 003C020260 for ; Fri, 11 Mar 2016 21:50:32 +0000 (UTC) Received: from localhost ([::1]:57843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeUx6-0002ov-Fs for patchwork-qemu-devel@patchwork.kernel.org; Fri, 11 Mar 2016 16:50:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aePfm-0000hz-BV for qemu-devel@nongnu.org; Fri, 11 Mar 2016 11:12:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aePfh-0004wi-8P for qemu-devel@nongnu.org; Fri, 11 Mar 2016 11:12:18 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35309) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aePfg-0004vQ-Up for qemu-devel@nongnu.org; Fri, 11 Mar 2016 11:12:13 -0500 Received: by mail-wm0-x242.google.com with SMTP id n205so3295689wmf.2 for ; Fri, 11 Mar 2016 08:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=zEQyVDEy/thA9AkssvqbU9sQD7E1zPjvhO6mtBzd95k=; b=gTEkn2c0ZRV5Ey+yy8Q/1vs1jJMe8KWM+JZdTwL7JT59Po4Eqh7CtbSy0o5pWuby/s Gm4ZZYvYElJRNWxMy4AQzyD477DzPwGL6AsksKbdDxG1EMdJOeAqHTXIddwxmfptMEqS T+k6bG3o2iena77Qvy7yziBGeINydjhJMYr+56fGv8X587DeNX9bFzciY9srpeveqRpW 1ZazcdMSR9jf3Y3GBJQmyYX8DK0oQfQw9yj26vmAl0LG0qvWoYhLJsdbdeEvJ+21h6Xz hcbexgNDEV9k76XuiaP28xYzOGakdVVnht7hpDEjKrl1Q+XHm9NuBBdsYur0vxqP3LG5 eURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=zEQyVDEy/thA9AkssvqbU9sQD7E1zPjvhO6mtBzd95k=; b=JYGcsiJ1BgocmxM0uNExZvmEWzvFBD/9VhsiNI5BEa3QjqLZwm7ZO1r3xhN6rNLL1I o1MUNYaYxJl9coMQLvSQ7jwLhRAbeLebrjJjXWu3VPcWtF6ktaXnTWbbfxsIjj2IsLx7 2K5BHAMqdxUBw5zolD66081s0pj9WsZwWWJK4VK0ZpuJJE0aqKecE3htANQEqsZyt1BX MxuYgJ9aTgbfRGqOCgu5O9MWdv3bF9TWtBq76xnnQ9Fr8fsjabStE+josfpav4MD1UZY O+cO6U4OicmRwu1NM7A2VYnLM9rtL7K2BshVZjosi7F6hO8Cc0+r9pKi7MEzkYNu0NAd Vg/g== X-Gm-Message-State: AD7BkJJaPW95Ve/BtP+RKZpMR5sZg+pFuI0VxcZueQwre+0GyaSIHIMpEH1GWH/ByUo/9Q== X-Received: by 10.194.61.169 with SMTP id q9mr10626824wjr.77.1457712732019; Fri, 11 Mar 2016 08:12:12 -0800 (PST) Received: from pudesk113-linux.pu.imgtec.org ([115.112.131.150]) by smtp.gmail.com with ESMTPSA id za6sm9143238wjc.18.2016.03.11.08.12.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Mar 2016 08:12:11 -0800 (PST) From: Jaya Tiwari To: qemu-devel@nongnu.org Date: Fri, 11 Mar 2016 21:42:01 +0530 Message-Id: <1457712721-2933-1-git-send-email-tiwari.jaya18@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 X-Mailman-Approved-At: Fri, 11 Mar 2016 16:48:37 -0500 Subject: [Qemu-devel] [PATCH 1/1] Allocating Large sized arrays to heap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 As per the list of functions in http://wiki.qemu.org/BiteSizedTasks#Large_frames, qemu_get_virtqueue_element and qemu_put_virtqueue_element have large arrays on stack Hence, moving them to heap. This reduced their stack size from something 49248 to fit into less than 200 Signed-off-by: Jaya Tiwari Reviewed-by: Paolo Bonzini --- hw/virtio/virtio.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 08275a9..7a7afae 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -636,67 +636,66 @@ typedef struct VirtQueueElementOld { void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz) { VirtQueueElement *elem; - VirtQueueElementOld data; + VirtQueueElementOld *data = g_new(VirtQueueElementOld, 1); int i; - qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld)); + qemu_get_buffer(f, (uint8_t *)data, sizeof(VirtQueueElementOld)); - elem = virtqueue_alloc_element(sz, data.out_num, data.in_num); - elem->index = data.index; + elem = virtqueue_alloc_element(sz, data->out_num, data->in_num); + elem->index = data->index; for (i = 0; i < elem->in_num; i++) { - elem->in_addr[i] = data.in_addr[i]; + elem->in_addr[i] = data->in_addr[i]; } for (i = 0; i < elem->out_num; i++) { - elem->out_addr[i] = data.out_addr[i]; + elem->out_addr[i] = data->out_addr[i]; } for (i = 0; i < elem->in_num; i++) { /* Base is overwritten by virtqueue_map. */ elem->in_sg[i].iov_base = 0; - elem->in_sg[i].iov_len = data.in_sg[i].iov_len; + elem->in_sg[i].iov_len = data->in_sg[i].iov_len; } for (i = 0; i < elem->out_num; i++) { /* Base is overwritten by virtqueue_map. */ elem->out_sg[i].iov_base = 0; - elem->out_sg[i].iov_len = data.out_sg[i].iov_len; + elem->out_sg[i].iov_len = data->out_sg[i].iov_len; } - + g_free(data); virtqueue_map(elem); return elem; } void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem) { - VirtQueueElementOld data; + VirtQueueElementOld *data = g_new0(VirtQueueElementOld, 1); int i; - - memset(&data, 0, sizeof(data)); - data.index = elem->index; - data.in_num = elem->in_num; - data.out_num = elem->out_num; + data->index = elem->index; + data->in_num = elem->in_num; + data->out_num = elem->out_num; for (i = 0; i < elem->in_num; i++) { - data.in_addr[i] = elem->in_addr[i]; + data->in_addr[i] = elem->in_addr[i]; } for (i = 0; i < elem->out_num; i++) { - data.out_addr[i] = elem->out_addr[i]; + data->out_addr[i] = elem->out_addr[i]; } for (i = 0; i < elem->in_num; i++) { /* Base is overwritten by virtqueue_map when loading. Do not * save it, as it would leak the QEMU address space layout. */ - data.in_sg[i].iov_len = elem->in_sg[i].iov_len; + data->in_sg[i].iov_len = elem->in_sg[i].iov_len; } for (i = 0; i < elem->out_num; i++) { /* Do not save iov_base as above. */ - data.out_sg[i].iov_len = elem->out_sg[i].iov_len; + data->out_sg[i].iov_len = elem->out_sg[i].iov_len; } - qemu_put_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld)); + qemu_put_buffer(f, (uint8_t *)data, sizeof(VirtQueueElementOld)); + free(data); } /* virtio device */