From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juan Quintela <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Subject: [PULL 3/7] migration/xbzrle: use ctz64 to avoid undefined result
Date: Thu, 16 Mar 2023 16:12:21 +0100 [thread overview]
Message-ID: <20230316151225.11362-4-quintela@redhat.com> (raw)
In-Reply-To: <20230316151225.11362-1-quintela@redhat.com>
From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
__builtin_ctzll() produces undefined results when the argument is 0.
This can be seen through test-xbzrle, which produces the following
warning:
../migration/xbzrle.c:265: runtime error: passing zero to ctz(), which is not a valid argument
Replace __builtin_ctzll() with our ctz64() wrapper which properly
handles 0.
Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/xbzrle.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/migration/xbzrle.c b/migration/xbzrle.c
index 05366e86c0..21b92d4eae 100644
--- a/migration/xbzrle.c
+++ b/migration/xbzrle.c
@@ -12,6 +12,7 @@
*/
#include "qemu/osdep.h"
#include "qemu/cutils.h"
+#include "qemu/host-utils.h"
#include "xbzrle.h"
/*
@@ -233,7 +234,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
break;
}
never_same = false;
- num = __builtin_ctzll(~comp);
+ num = ctz64(~comp);
num = (num < bytes_to_check) ? num : bytes_to_check;
zrun_len += num;
bytes_to_check -= num;
@@ -262,7 +263,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
nzrun_len += 64;
break;
}
- num = __builtin_ctzll(comp);
+ num = ctz64(comp);
num = (num < bytes_to_check) ? num : bytes_to_check;
nzrun_len += num;
bytes_to_check -= num;
--
2.39.2
next prev parent reply other threads:[~2023-03-16 15:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 15:12 [PULL 0/7] Migration 20230316 patches Juan Quintela
2023-03-16 15:12 ` [PULL 1/7] migration: Wait on preempt channel in preempt thread Juan Quintela
2023-03-16 15:12 ` [PULL 2/7] migration/rdma: Fix return-path case Juan Quintela
2023-03-16 15:12 ` Juan Quintela [this message]
2023-03-16 15:12 ` [PULL 4/7] migration/xbzrle: fix out-of-bounds write with axv512 Juan Quintela
2023-03-16 15:12 ` [PULL 5/7] migration/rdma: Remove deprecated variable rdma_return_path Juan Quintela
2023-03-16 15:12 ` [PULL 6/7] migration/multifd: correct multifd_send_thread to trace the flags Juan Quintela
2023-03-16 15:12 ` [PULL 7/7] migration: fix populate_vfio_info Juan Quintela
2023-03-17 13:11 ` [PULL 0/7] Migration 20230316 patches Peter Maydell
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=20230316151225.11362-4-quintela@redhat.com \
--to=quintela@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quic_mathbern@quicinc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).