[Mesa-dev] [PATCH 2/2] i965/tiled_memcpy: Protect against wrong alignments

Jason Ekstrand jason at jlekstrand.net
Thu Apr 7 14:55:13 UTC 2016


I realized this morning that there is a lot better way to do this. Consider
these patches rescinded.
On Apr 4, 2016 6:00 PM, "Jason Ekstrand" <jason at jlekstrand.net> wrote:

> It's possible, when doing an x-tiled copy, to end up with a case where the
> bytes parameter is equal to 16 but the pointer is not actually aligned.
> This causes asserts in debug mode and segfaults in release builds due to
> doing an aligned operation on an unaligned pointer.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93962
> ---
>  src/mesa/drivers/dri/i965/intel_tiled_memcpy.c | 48
> +++++++++++++-------------
>  1 file changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> index 19079d0..823d8b0 100644
> --- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> +++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> @@ -85,19 +85,19 @@ rgba8_copy_aligned_dst(void *dst, const void *src,
> size_t bytes)
>     uint8_t const *s = src;
>
>  #ifdef __SSSE3__
> -   if (bytes == 16) {
> -      assert(!(((uintptr_t)dst) & 0xf));
> -      rgba8_copy_16_aligned_dst(d+ 0, s+ 0);
> -      return dst;
> -   }
> +   if ((((uintptr_t)dst) & 0xf) == 0) {
> +      if (bytes == 16) {
> +         rgba8_copy_16_aligned_dst(d+ 0, s+ 0);
> +         return dst;
> +      }
>
> -   if (bytes == 64) {
> -      assert(!(((uintptr_t)dst) & 0xf));
> -      rgba8_copy_16_aligned_dst(d+ 0, s+ 0);
> -      rgba8_copy_16_aligned_dst(d+16, s+16);
> -      rgba8_copy_16_aligned_dst(d+32, s+32);
> -      rgba8_copy_16_aligned_dst(d+48, s+48);
> -      return dst;
> +      if (bytes == 64) {
> +         rgba8_copy_16_aligned_dst(d+ 0, s+ 0);
> +         rgba8_copy_16_aligned_dst(d+16, s+16);
> +         rgba8_copy_16_aligned_dst(d+32, s+32);
> +         rgba8_copy_16_aligned_dst(d+48, s+48);
> +         return dst;
> +      }
>     }
>  #endif
>
> @@ -123,19 +123,19 @@ rgba8_copy_aligned_src(void *dst, const void *src,
> size_t bytes)
>     uint8_t const *s = src;
>
>  #ifdef __SSSE3__
> -   if (bytes == 16) {
> -      assert(!(((uintptr_t)src) & 0xf));
> -      rgba8_copy_16_aligned_src(d+ 0, s+ 0);
> -      return dst;
> -   }
> +   if ((((uintptr_t)src) & 0xf) == 0) {
> +      if (bytes == 16) {
> +         rgba8_copy_16_aligned_src(d+ 0, s+ 0);
> +         return dst;
> +      }
>
> -   if (bytes == 64) {
> -      assert(!(((uintptr_t)src) & 0xf));
> -      rgba8_copy_16_aligned_src(d+ 0, s+ 0);
> -      rgba8_copy_16_aligned_src(d+16, s+16);
> -      rgba8_copy_16_aligned_src(d+32, s+32);
> -      rgba8_copy_16_aligned_src(d+48, s+48);
> -      return dst;
> +      if (bytes == 64) {
> +         rgba8_copy_16_aligned_src(d+ 0, s+ 0);
> +         rgba8_copy_16_aligned_src(d+16, s+16);
> +         rgba8_copy_16_aligned_src(d+32, s+32);
> +         rgba8_copy_16_aligned_src(d+48, s+48);
> +         return dst;
> +      }
>     }
>  #endif
>
> --
> 2.5.0.400.gff86faf
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160407/dbb1a08d/attachment-0001.html>


More information about the mesa-dev mailing list