From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afTDV-0000uL-Qk for qemu-devel@nongnu.org; Mon, 14 Mar 2016 10:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afTDS-0003Qd-6W for qemu-devel@nongnu.org; Mon, 14 Mar 2016 10:11:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afTDS-0003QX-0e for qemu-devel@nongnu.org; Mon, 14 Mar 2016 10:11:26 -0400 References: <1457771973-23208-1-git-send-email-dhannawatpooja1@gmail.com> From: Eric Blake Message-ID: <56E6C68C.7000700@redhat.com> Date: Mon, 14 Mar 2016 08:11:24 -0600 MIME-Version: 1.0 In-Reply-To: <1457771973-23208-1-git-send-email-dhannawatpooja1@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eWD28PNt4cx7rfe9oACRFh5utHQ4knnOl" Subject: Re: [Qemu-devel] [Patch 1/1] net/net: Allocating Large sized arrays to heap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pooja Dhannawat , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --eWD28PNt4cx7rfe9oACRFh5utHQ4knnOl Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/12/2016 01:39 AM, Pooja Dhannawat wrote: > Signed-off-by: Pooja Dhannawat > --- > net/net.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) >=20 > diff --git a/net/net.c b/net/net.c > index b0c832e..5399758 100644 > --- a/net/net.c > +++ b/net/net.c > @@ -709,16 +709,18 @@ ssize_t qemu_send_packet_raw(NetClientState *nc, = const uint8_t *buf, int size) > static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec = *iov, > int iovcnt, unsigned flags) > { > - uint8_t buf[NET_BUFSIZE]; > + uint8_t *buf; > uint8_t *buffer; > size_t offset; > =20 > + buf =3D g_new(uint8_t, 1); If you're only going to malloc() one byte, it's more efficient to just stack-allocate it: uint8_t buf[1]; Did you mean to do: buf =3D g_new(uint8_t, NET_BUFSIZE) instead? > + > if (iovcnt =3D=3D 1) { > buffer =3D iov[0].iov_base; > offset =3D iov[0].iov_len; > } else { > buffer =3D buf; > - offset =3D iov_to_buf(iov, iovcnt, 0, buf, sizeof(buf)); > + offset =3D iov_to_buf(iov, iovcnt, 0, (uint8_t *)buf, sizeof(u= int8_t)); This is wrong. The old code used NET_BUFSIZE bytes for iov_to_buf(), the new code uses only one byte. By the way, sizeof(char) and sizeof(uint8_t) are pointless in code, as they are strictly equivalent to= 1. I agree that the idea behind the patch is useful (NET_BUFSIZE is 68k, which is too large for our goal of at most 4k stack allocation if we never want to overflow a stack guard page), but you'll need a correct working version of the patch. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --eWD28PNt4cx7rfe9oACRFh5utHQ4knnOl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJW5saMAAoJEKeha0olJ0Nqb28H/2NFKw9/3kcIn8uNcqqRsjhQ t1foZ3R2QNzg4JLUjNVdFE5W5p4AZvgF35nY4QFdPbqL2/Xdcyu8fqC8Om9KHfVf lPYREPR/dNfPdFuh9pJMzcE3J4OlO/KWk3k9IH6/qc2LG9pmWS7ADgHU1pDYFu7w 4xZsfhwWOlkILqEEqykC/BmPAn7K+7IlkyQXN7AiX7fIkx93OsNzE57CsfOGXgrY viRl9aj3e9jG7J8MR58y+/zz4udI55e+Xt5ACsNxl9KVd5sj9ji0B3tQ4KyZ2w2e esgJguIFP3rBHKd5HGWqUaONT9aQRfYHRuO9x3lCq2bySrBa2XGHAriKjLACW1Q= =dKJV -----END PGP SIGNATURE----- --eWD28PNt4cx7rfe9oACRFh5utHQ4knnOl--