From nobody Tue Feb 10 06:25:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683572036; cv=none; d=zohomail.com; s=zohoarc; b=oIY7Jx/Hzd81si+1iy3L0mXSxza9S7rLGKxCnGI+ro+fSlS2BBE4UR44zc0uxHynllmDYSvoShjJn58C4qj30DZC3oe+ey08JthjXFQA7XEpMDi9szdq02k5H/gsvcxcXQW19dKMoNfBTAAbgkurzpkqoMEycIbRIH5AGoBFxYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683572036; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SYscSa5qs0TT7ug+FUN3WGUBOgborh0kKbtoRyk62KQ=; b=TnGZJgCwZMyLnWxJhRUqvdfKRb3dT6sfniBsyCqQNOLxh8XzkpsQ5bEr6UVC7MBRdr7mX4EpaiM3WDiWMO1gA2GanWqLX812BqYQff0iDyRkr3ZLnfYTcM215X5d9swoQ0aZGKKyyRkXJSvqtpzXBr9eRVx9H7t3Z1TUmWTxDq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168357203616057.96019233535458; Mon, 8 May 2023 11:53:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw5yY-0004Lc-Ba; Mon, 08 May 2023 14:52:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pw5yQ-0004Hf-PJ for qemu-devel@nongnu.org; Mon, 08 May 2023 14:52:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pw5yL-00062A-Qo for qemu-devel@nongnu.org; Mon, 08 May 2023 14:52:37 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-456-BP_BAbaoO0-BqjE84rnytw-1; Mon, 08 May 2023 14:52:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93F74185A79C; Mon, 8 May 2023 18:52:29 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 471C31410F23; Mon, 8 May 2023 18:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683571953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SYscSa5qs0TT7ug+FUN3WGUBOgborh0kKbtoRyk62KQ=; b=e7ZkQlO/mecLzlinqLDX+87e8ok4GJbYJNwZ4CGcoqTyeT9GVQemnnlti9/ri/3+hkArtV PSHWP3V8/u4Qx74iwBSJA2U/PGHp4DWzbBE6xqEZlrqveFppN7t5fdMPCKmiYM/un9nZLo HiRqH/m8MXUb/rne/JRReh9xq5RV8Vs= X-MC-Unique: BP_BAbaoO0-BqjE84rnytw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Peter Xu , Leonardo Bras , Juan Quintela , Laurent Vivier , Paolo Bonzini , Lukas Straub Subject: [PULL 11/13] ram compress: Assert that the file buffer matches the result Date: Mon, 8 May 2023 20:52:07 +0200 Message-Id: <20230508185209.68604-12-quintela@redhat.com> In-Reply-To: <20230508185209.68604-1-quintela@redhat.com> References: <20230508185209.68604-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683572038167100007 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Before this series, "nothing to send" was handled by the file buffer being empty. Now it is tracked via param->result. Assert that the file buffer state matches the result. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/qemu-file.c | 11 +++++++++++ migration/qemu-file.h | 1 + migration/ram-compress.c | 5 +++++ migration/ram.c | 2 ++ 4 files changed, 19 insertions(+) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index f4cfd05c67..61fb580342 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -870,6 +870,17 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_sr= c) return len; } =20 +/* + * Check if the writable buffer is empty + */ + +bool qemu_file_buffer_empty(QEMUFile *file) +{ + assert(qemu_file_is_writable(file)); + + return !file->iovcnt; +} + /* * Get a string whose length is determined by a single preceding byte * A preallocated 256 byte buffer must be passed in. diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 4f26bf6961..4ee58a87dd 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -113,6 +113,7 @@ size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMU= File *f, uint8_t **buf, s ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, const uint8_t *p, size_t size); int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src); +bool qemu_file_buffer_empty(QEMUFile *file); =20 /* * Note that you can only peek continuous bytes from where the current poi= nter diff --git a/migration/ram-compress.c b/migration/ram-compress.c index c25562f12d..3d2a4a6329 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -194,6 +194,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f,= z_stream *stream, uint8_t *p =3D block->host + offset; int ret; =20 + assert(qemu_file_buffer_empty(f)); + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { return RES_ZEROPAGE; } @@ -208,6 +210,7 @@ static CompressResult do_compress_ram_page(QEMUFile *f,= z_stream *stream, if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); + qemu_fflush(f); return RES_NONE; } return RES_COMPRESS; @@ -239,6 +242,7 @@ void flush_compressed_data(int (send_queued_data(Compre= ssParam *))) if (!comp_param[idx].quit) { CompressParam *param =3D &comp_param[idx]; send_queued_data(param); + assert(qemu_file_buffer_empty(param->file)); compress_reset_result(param); } qemu_mutex_unlock(&comp_param[idx].mutex); @@ -268,6 +272,7 @@ retry: qemu_mutex_lock(¶m->mutex); param->done =3D false; send_queued_data(param); + assert(qemu_file_buffer_empty(param->file)); compress_reset_result(param); set_compress_params(param, block, offset); =20 diff --git a/migration/ram.c b/migration/ram.c index 009681d213..ee4ab31f25 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1321,11 +1321,13 @@ static int send_queued_data(CompressParam *param) assert(block =3D=3D pss->last_sent_block); =20 if (param->result =3D=3D RES_ZEROPAGE) { + assert(qemu_file_buffer_empty(param->file)); len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG= _ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(block->idstr, offset); } else if (param->result =3D=3D RES_COMPRESS) { + assert(!qemu_file_buffer_empty(param->file)); len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); len +=3D qemu_put_qemu_file(file, param->file); --=20 2.40.0