All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com, bcain@quicinc.com,
	ling1.xu@intel.com, zhou.zhao@intel.com, jun.i.jin@intel.com
Subject: Re: [PATCH RESEND v2 1/2] migration/xbzrle: use ctz64 to avoid undefined result
Date: Wed, 15 Mar 2023 18:01:45 +0000	[thread overview]
Message-ID: <ZBIICT06hzn+2gp/@work-vm> (raw)
In-Reply-To: <117f3c2fdc17c319b0e04014bbd7e0c94992c197.1678733663.git.quic_mathbern@quicinc.com>

* Matheus Tavares Bernardino (quic_mathbern@quicinc.com) wrote:
> __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>

> ---
>  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.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2023-03-15 18:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 18:58 [PATCH RESEND v2 0/2] migration/xbzrle: fix two avx512 runtime issues Matheus Tavares Bernardino
2023-03-13 18:58 ` [PATCH RESEND v2 1/2] migration/xbzrle: use ctz64 to avoid undefined result Matheus Tavares Bernardino
2023-03-15 18:01   ` Dr. David Alan Gilbert [this message]
2023-03-15 20:56   ` Juan Quintela
2023-03-13 18:58 ` [PATCH RESEND v2 2/2] migration/xbzrle: fix out-of-bounds write with axv512 Matheus Tavares Bernardino
2023-03-15 18:59   ` Dr. David Alan Gilbert
2023-03-15 20:57   ` Juan Quintela

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=ZBIICT06hzn+2gp/@work-vm \
    --to=dgilbert@redhat.com \
    --cc=bcain@quicinc.com \
    --cc=jun.i.jin@intel.com \
    --cc=ling1.xu@intel.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quic_mathbern@quicinc.com \
    --cc=quintela@redhat.com \
    --cc=zhou.zhao@intel.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.