All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Avihai Horon <avihaih@nvidia.com>,
	 qemu-devel@nongnu.org,  Juan Quintela <quintela@redhat.com>,
	 Peter Xu <peterx@redhat.com>,  Fabiano Rosas <farosas@suse.de>,
	 Leonardo Bras <leobras@redhat.com>,
	 Li Zhijian <lizhijian@fujitsu.com>
Subject: Re: [PATCH 09/11] migration: Fix migration_channel_read_peek() error path
Date: Mon, 08 Jan 2024 13:34:31 +0100	[thread overview]
Message-ID: <87edest354.fsf@pond.sub.org> (raw)
In-Reply-To: <dafc11b4-3f56-4c22-b776-a8f644b2ad26@linaro.org> ("Philippe Mathieu-Daudé"'s message of "Tue, 2 Jan 2024 11:05:56 +0100")

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> +Markus
>
> On 31/12/23 10:30, Avihai Horon wrote:
>> migration_channel_read_peek() calls qio_channel_readv_full() and handles
>> both cases of return value == 0 and return value < 0 the same way, by
>> calling error_setg() with errp. However, if return value < 0, errp is
>> already set, so calling error_setg() with errp will lead to an assert.
>
> I suppose the API would be safer by passing &len as argument and
> return a boolean.

Doubtful, unless I'm misunderstanding something.

Function comment:

 * Returns: the number of bytes read, or -1 on error,
 * or QIO_CHANNEL_ERR_BLOCK if no data is available
 * and the channel is non-blocking

I understand this as:

* Success case: return #bytes read

* Error case: return -1, @errp is set

* Would block case: return QIO_CHANNEL_ERR_BLOCK

A zero return value must be the success case.  I figure this can happen
only at EOF.  A caller might need to treat unexpected EOF as an error.

>> Fix it by handling these cases separately, calling error_setg() with
>> errp only in return value == 0 case.
>> Fixes: 6720c2b32725 ("migration: check magic value for deciding the mapping of channels")
>> Signed-off-by: Avihai Horon <avihaih@nvidia.com>
>> ---
>>   migration/channel.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>> diff --git a/migration/channel.c b/migration/channel.c
>> index ca3319a309..f9de064f3b 100644
>> --- a/migration/channel.c
>> +++ b/migration/channel.c
>> @@ -117,9 +117,12 @@ int migration_channel_read_peek(QIOChannel *ioc,
>>          len = qio_channel_readv_full(ioc, &iov, 1, NULL, NULL,
>>                                       QIO_CHANNEL_READ_FLAG_MSG_PEEK, errp);
>> -        if (len <= 0 && len != QIO_CHANNEL_ERR_BLOCK) {
>> -            error_setg(errp,
>> -                       "Failed to peek at channel");
>> +        if (len < 0 && len != QIO_CHANNEL_ERR_BLOCK) {
>> +            return -1;
>> +        }
>> +
>> +        if (len == 0) {
>> +            error_setg(errp, "Failed to peek at channel");
>>              return -1;
>>           }
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



  reply	other threads:[~2024-01-08 12:35 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31  9:30 [PATCH 00/11] migration: Misc cleanups and fixes Avihai Horon
2023-12-31  9:30 ` [PATCH 01/11] migration: Remove migrate_max_downtime() declaration Avihai Horon
2024-01-02 17:27   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 02/11] migration: Remove nulling of hostname in migrate_init() Avihai Horon
2024-01-02 18:43   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 03/11] migration: Refactor migration_incoming_setup() Avihai Horon
2024-01-02 10:02   ` Philippe Mathieu-Daudé
2024-01-02 18:53   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 04/11] migration: Remove errp parameter in migration_fd_process_incoming() Avihai Horon
2024-01-02 18:57   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 05/11] migration/multifd: Fix error message in multifd_recv_initial_packet() Avihai Horon
2024-01-02 19:05   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 06/11] migration/multifd: Simplify multifd_channel_connect() if else statement Avihai Horon
2024-01-02 10:03   ` Philippe Mathieu-Daudé
2023-12-31  9:30 ` [PATCH 07/11] migration/multifd: Fix leaking of Error in TLS error flow Avihai Horon
2024-01-02 19:32   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 08/11] migration/multifd: Remove error_setg() in migration_ioc_process_incoming() Avihai Horon
2024-01-02 19:33   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 09/11] migration: Fix migration_channel_read_peek() error path Avihai Horon
2024-01-02 10:05   ` Philippe Mathieu-Daudé
2024-01-08 12:34     ` Markus Armbruster [this message]
2024-01-02 19:39   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 10/11] migration: Remove unnecessary usage of local Error Avihai Horon
2024-01-02 19:42   ` Fabiano Rosas
2023-12-31  9:30 ` [PATCH 11/11] migration/multifd: " Avihai Horon
2024-01-02 10:07   ` Philippe Mathieu-Daudé
2024-01-04  4:38 ` [PATCH 00/11] migration: Misc cleanups and fixes Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edest354.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=farosas@suse.de \
    --cc=leobras@redhat.com \
    --cc=lizhijian@fujitsu.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.