From nobody Tue May 7 05:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1564584247; cv=none; d=zoho.com; s=zohoarc; b=PXHF9L66g3HMq0MxMLYNuLJuTcXVeJs/8TIvrXs0uhRXuBHdKsAq0mTgw3Umal3U8dLBHznHe07y4LYBp9UB8RC+Q9rWJeH3IqCFqLEaNEPS5NltmNQ79Z45t5mhjNpdIqB+8blbqAsiwEoDkvPGtlDjUosKcj9mSTpvv+6ujlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564584247; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=sjtrYz3HKDn/E1D325Esam0OtK7og4uD4bHXgU2/TpQ=; b=ErFTOpO66ZJKu8lp+rP3MdKdeRk6PlfsE6TJ/iC/0ZLT/ecxBu4CaDlJPNNNllpflKLF3gZ5/4R2Wri3uhejLC6dC91z/ji54r3E14AN2SKCCJe+xtTmRBjb/qG69gCpcU+nQ78OW3G3lv5mB+zGeIdWh9BI/8Dp2z2t6ju3Pv4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156458424737749.90754878916846; Wed, 31 Jul 2019 07:44:07 -0700 (PDT) Received: from localhost ([::1]:41474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsppm-0002UR-6j for importer@patchew.org; Wed, 31 Jul 2019 10:44:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44753) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hspp5-0001CO-4W for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hspp4-0000vC-0p for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:23 -0400 Received: from mga05.intel.com ([192.55.52.43]:51110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hspp3-0000sD-OH for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:21 -0400 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2019 07:43:16 -0700 Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga005.jf.intel.com with ESMTP; 31 Jul 2019 07:43:15 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,330,1559545200"; d="scan'208";a="347557226" From: Wei Yang To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 22:42:24 +0800 Message-Id: <20190731144225.3784-2-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190731144225.3784-1-richardw.yang@linux.intel.com> References: <20190731144225.3784-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH 1/2] migration/qemu-file: remove check on writev_buffer in qemu_put_compression_data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The check of writev_buffer is in qemu_fflush, which means it is not harmful if it is NULL. And removing it will make the code consistent since all other add_to_iovec() is called without the check. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 0431585502..35c22605dd 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -717,9 +717,7 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_stream= *stream, } =20 qemu_put_be32(f, blen); - if (f->ops->writev_buffer) { - add_to_iovec(f, f->buf + f->buf_index, blen, false); - } + add_to_iovec(f, f->buf + f->buf_index, blen, false); f->buf_index +=3D blen; if (f->buf_index =3D=3D IO_BUF_SIZE) { qemu_fflush(f); --=20 2.17.1 From nobody Tue May 7 05:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1564584251; cv=none; d=zoho.com; s=zohoarc; b=M1IE9QzFN5JfmOQOVCkfvZCe2Ai9KHZ9uho92iENG/9Stqhf3yym62q8aMTBWpqjUqNYOteMlLyFF9sgxP2H/WiMnWaCuAvFOs2R0avcaB50gC1GLqbJWX9jMVhl0k8kRcSAaVDWZfK3Y0IhR2+aI2xv9MBPDYPKepjTsvxammM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564584251; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gSGm1JP0lKpMxq7Rl2xr+Eaqz+ZGSmVpvz2M7t1Rk7o=; b=OFPiXCtHBVoYSKlZqRuh+kx62cftT/MeXeY7OIQ1jiKOV/lajXKqzwBy5Z7WEMrmsH/JYTP1fCqQvFXg4BIu0LS+FlTis2ROBHvxPvkP9wDG4HpBJDSOqJd8tg1D+5UTJKwrJbm4y6V76B59pYc4+lMUke8Nj/Q83x12Cb8Hk+0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564584251801236.05981812189805; Wed, 31 Jul 2019 07:44:11 -0700 (PDT) Received: from localhost ([::1]:41473 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsppm-0002Tt-IJ for importer@patchew.org; Wed, 31 Jul 2019 10:44:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44752) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hspp5-0001CN-4J for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hspp4-0000vL-1w for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:23 -0400 Received: from mga05.intel.com ([192.55.52.43]:51112) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hspp3-0000sd-OI for qemu-devel@nongnu.org; Wed, 31 Jul 2019 10:43:22 -0400 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2019 07:43:18 -0700 Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga005.jf.intel.com with ESMTP; 31 Jul 2019 07:43:17 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,330,1559545200"; d="scan'208";a="347557230" From: Wei Yang To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 22:42:25 +0800 Message-Id: <20190731144225.3784-3-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190731144225.3784-1-richardw.yang@linux.intel.com> References: <20190731144225.3784-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH 2/2] migration/qemu-file: fix potential buf waste for extra buf_index adjustment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In add_to_iovec(), qemu_fflush() will be called if iovec is full. If this happens, buf_index is reset. Currently, this is not checked and buf_index would always been adjust with buf size. This is not harmful, but will waste some space in file buffer. This patch make add_to_iovec() return 1 when it has flushed the file. Then the caller could check the return value to see whether it is necessary to adjust the buf_index any more. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 35c22605dd..05d9f42ddb 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -343,8 +343,16 @@ int qemu_fclose(QEMUFile *f) return ret; } =20 -static void add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, - bool may_free) +/* + * Add buf to iovec. Do flush if iovec is full. + * + * Return values: + * 1 iovec is full and flushed + * 0 iovec is not flushed + * + */ +static int add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free) { /* check for adjacent buffer and coalesce them */ if (f->iovcnt > 0 && buf =3D=3D f->iov[f->iovcnt - 1].iov_base + @@ -362,7 +370,10 @@ static void add_to_iovec(QEMUFile *f, const uint8_t *b= uf, size_t size, =20 if (f->iovcnt >=3D MAX_IOV_SIZE) { qemu_fflush(f); + return 1; } + + return 0; } =20 void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, @@ -391,10 +402,11 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf,= size_t size) } memcpy(f->buf + f->buf_index, buf, l); f->bytes_xfer +=3D l; - add_to_iovec(f, f->buf + f->buf_index, l, false); - f->buf_index +=3D l; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); + if (!add_to_iovec(f, f->buf + f->buf_index, l, false)) { + f->buf_index +=3D l; + if (f->buf_index =3D=3D IO_BUF_SIZE) { + qemu_fflush(f); + } } if (qemu_file_get_error(f)) { break; @@ -412,10 +424,11 @@ void qemu_put_byte(QEMUFile *f, int v) =20 f->buf[f->buf_index] =3D v; f->bytes_xfer++; - add_to_iovec(f, f->buf + f->buf_index, 1, false); - f->buf_index++; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); + if (!add_to_iovec(f, f->buf + f->buf_index, 1, false)) { + f->buf_index++; + if (f->buf_index =3D=3D IO_BUF_SIZE) { + qemu_fflush(f); + } } } =20 @@ -717,10 +730,11 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_stre= am *stream, } =20 qemu_put_be32(f, blen); - add_to_iovec(f, f->buf + f->buf_index, blen, false); - f->buf_index +=3D blen; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); + if (!add_to_iovec(f, f->buf + f->buf_index, blen, false)) { + f->buf_index +=3D blen; + if (f->buf_index =3D=3D IO_BUF_SIZE) { + qemu_fflush(f); + } } return blen + sizeof(int32_t); } --=20 2.17.1