Skip to contentSkip to conversation

drm/amdgpu: Fix allocating extra dwords for rings (v2)

PATCH In review Timur Kristóf 4 participants 18 messages Sep 9, 2025 – Sep 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: Fix allocating extra dwords for rings (v2)

Rename extra_dw to extra_bytes and document what it's for.

The value is already used as if it were bytes in vcn_v4_0.c and in amdgpu_ring_init. Just adjust the dword count in jpeg_v1_0.c so that it becomes a byte count.

v2:
Rename extra_dw to extra_bytes as discussed during review.

Fixes c8c1a1d2ef04 ("drm/amdgpu: define and add extra dword for jpeg ring")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 11 ++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdgpu/jpeg_v1_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c    |  2 +-
 4 files changed, 20 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +6 -5
index 6379bb25bf5c..eca8b28e3fb9 100644
@@ -364,11 +364,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 
 	/* Allocate ring buffer */
 	if (ring->ring_obj == NULL) {
-		r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,
-					    AMDGPU_GEM_DOMAIN_GTT,
-					    &ring->ring_obj,
-					    &ring->gpu_addr,
-					    (void **)&ring->ring);
+		r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_bytes,
+						PAGE_SIZE,
+						AMDGPU_GEM_DOMAIN_GTT,
+						&ring->ring_obj,
+						&ring->gpu_addr,
+						(void **)&ring->ring);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring create failed\n", r);
 			kvfree(ring->ring_backup);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +12 -1
index 7670f5d82b9e..12783ea3ba0f 100644
@@ -211,7 +211,18 @@ struct amdgpu_ring_funcs {
 	bool			support_64bit_ptrs;
 	bool			no_user_fence;
 	bool			secure_submission_supported;
-	unsigned		extra_dw;
+
+	/**
+	 * @extra_bytes:
+	 *
+	 * Optional extra space in bytes that is added to the ring size
+	 * when allocating the BO that holds the contents of the ring.
+	 * This space isn't used for command submission to the ring,
+	 * but is just there to satisfy some hardware requirements or
+	 * implement workarounds. It's up to the implementation of each
+	 * specific ring to initialize this space.
+	 */
+	unsigned		extra_bytes;
 
 	/* ring read/write ptr handling */
 	u64 (*get_rptr)(struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/jpeg_v1_0.c +1 -1
index 9e428e669ada..b5bb7f4d607c 100644
@@ -557,7 +557,7 @@ static const struct amdgpu_ring_funcs jpeg_v1_0_decode_ring_vm_funcs = {
 	.nop = PACKET0(0x81ff, 0),
 	.support_64bit_ptrs = false,
 	.no_user_fence = true,
-	.extra_dw = 64,
+	.extra_bytes = 256,
 	.get_rptr = jpeg_v1_0_decode_ring_get_rptr,
 	.get_wptr = jpeg_v1_0_decode_ring_get_wptr,
 	.set_wptr = jpeg_v1_0_decode_ring_set_wptr,
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
index d0d27790b73b..099698cb1a3d 100644
@@ -1986,7 +1986,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {
 	.type = AMDGPU_RING_TYPE_VCN_ENC,
 	.align_mask = 0x3f,
 	.nop = VCN_ENC_CMD_NO_OP,
-	.extra_dw = sizeof(struct amdgpu_vcn_rb_metadata),
+	.extra_bytes = sizeof(struct amdgpu_vcn_rb_metadata),
 	.get_rptr = vcn_v4_0_unified_ring_get_rptr,
 	.get_wptr = vcn_v4_0_unified_ring_get_wptr,
 	.set_wptr = vcn_v4_0_unified_ring_set_wptr,
Signature · 1 line
2.51.0
#1 lore raw

PATCH 2/3 drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

SDMA v3-v5 can copy almost 4 MiB in a single copy operation.
Use the same value as PAL and Mesa for copy_max_bytes.

For reference, see oss2DmaCmdBuffer.cpp in PAL:
"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

See also sid.h in Mesa:
"There is apparently an undocumented HW limitation that prevents the HW from copying the last 255 bytes of (1 << 22) - 1"

Fixes dfe5c2b76b2a ("drm/amdgpu: Correct bytes limit for SDMA 3.0 copy and fill")
---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
index 1c076bd1cf73..9302cf0b5e4b 100644
@@ -1659,11 +1659,11 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
 }
 
 static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {
-	.copy_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation */
+	.copy_max_bytes = 0x3fff00, /* not 0x3fffff due to HW limitation */
 	.copy_num_dw = 7,
 	.emit_copy_buffer = sdma_v3_0_emit_copy_buffer,
 
-	.fill_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation */
+	.fill_max_bytes = 0x3fff00, /* not 0x3fffff due to HW limitation */
 	.fill_num_dw = 5,
 	.emit_fill_buffer = sdma_v3_0_emit_fill_buffer,
 };
Signature · 1 line
2.51.0
maintainer
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 6 lines · Timur Kristóf

SDMA v3-v5 can copy almost 4 MiB in a single copy operation.
Use the same value as PAL and Mesa for copy_max_bytes.

For reference, see oss2DmaCmdBuffer.cpp in PAL:
"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Ah! In this case the value the kernel uses is actually correct.

The difference is that the kernel never has start_addr[4:2] != 0 for anything larger than PAGE_SIZE while for PAL and Mesa that can happen.

Quoted 3 lines

See also sid.h in Mesa:
"There is apparently an undocumented HW limitation that prevents the HW from copying the last 255 bytes of (1 << 22) - 1"

That is actually pretty well documented and makes perfect sense. For unaligned start or dst addresses the SDMA needs to use an internal bounce buffer. That's where the limit comes from.

Not sure if we should apply that patch or not, it probably doesn't make any difference in practice.

Quoted 1 line
Fixes dfe5c2b76b2a ("drm/amdgpu: Correct bytes limit for SDMA 3.0 copy and fill")

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Regards,
Christian.

Quoted 23 lines
---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
index 1c076bd1cf73..9302cf0b5e4b 100644
@@ -1659,11 +1659,11 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
 }
 
 static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {
-	.copy_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation */
+	.copy_max_bytes = 0x3fff00, /* not 0x3fffff due to HW limitation */
 	.copy_num_dw = 7,
 	.emit_copy_buffer = sdma_v3_0_emit_copy_buffer,
 
-	.fill_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation */
+	.fill_max_bytes = 0x3fff00, /* not 0x3fffff due to HW limitation */
 	.fill_num_dw = 5,
 	.emit_fill_buffer = sdma_v3_0_emit_fill_buffer,
 };
#3 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 22 lines · Christian König
Quoted 6 lines · Timur Kristóf

SDMA v3-v5 can copy almost 4 MiB in a single copy operation.
Use the same value as PAL and Mesa for copy_max_bytes.

For reference, see oss2DmaCmdBuffer.cpp in PAL:
"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Ah! In this case the value the kernel uses is actually correct.

The difference is that the kernel never has start_addr[4:2] != 0 for anything larger than PAGE_SIZE while for PAL and Mesa that can happen.

Quoted 3 lines

See also sid.h in Mesa:
"There is apparently an undocumented HW limitation that prevents the HW from copying the last 255 bytes of (1 << 22) - 1"

That is actually pretty well documented and makes perfect sense. For unaligned start or dst addresses the SDMA needs to use an internal bounce buffer. That's where the limit comes from.

Quoted 8 lines

Not sure if we should apply that patch or not, it probably doesn't make any difference in practice.

Quoted 2 lines
Fixes dfe5c2b76b2a ("drm/amdgpu: Correct bytes limit for SDMA 3.0

copy and fill")

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Hi Christian,

The kernel and Mesa disagree on the limits for almost all SDMA versions, so it would be nice to actually understand what the limits of the SDMA HW are and use the same limit in the kernel and Mesa, or if that isn't viable, let's document why the different limits make sense.

I'm adding Marek to CC, he wrote the comment that I referenced here. As far as I understand from my conversation with Marek, the kernel is actually wrong.

If the limits depend on alignment, then we should either set a limit that is always safe, or make sure SDMA copies in the kernel are always aligned and add assertions about it. Looking at the implementation of amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with the current limit it could issue subsequent copies that aren't 256 byte aligned.

Best regards,
Timur

Quoted 33 lines

Regards,
Christian.

Quoted 29 lines

---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +0 -0
index 1c076bd1cf73..9302cf0b5e4b 100644
@@ -1659,11 +1659,11 @@ static void
 sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
  }


 static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {

drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +0 -1
-	.copy_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW

limitation */

drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +1 -0
+	.copy_max_bytes = 0x3fff00, /* not 0x3fffff due to HW

limitation */
  .copy_num_dw = 7,
  .emit_copy_buffer = sdma_v3_0_emit_copy_buffer,

drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +0 -1
-	.fill_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW

limitation */

drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +1 -0
+	.fill_max_bytes = 0x3fff00, /* not 0x3fffff due to HW

limitation */
  .fill_num_dw = 5,
  .emit_fill_buffer = sdma_v3_0_emit_fill_buffer, };

maintainer
#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 10 lines · Timur Kristóf
Quoted 2 lines

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Hi Christian,

The kernel and Mesa disagree on the limits for almost all SDMA versions, so it would be nice to actually understand what the limits of the SDMA HW are and use the same limit in the kernel and Mesa, or if that isn't viable, let's document why the different limits make sense.

Quoted 7 lines

I'm adding Marek to CC, he wrote the comment that I referenced here. As far as I understand from my conversation with Marek, the kernel is actually wrong.

If the limits depend on alignment, then we should either set a limit that is always safe, or make sure SDMA copies in the kernel are always aligned and add assertions about it.

That's already done. See the size restrictions applied to BOs and the callers of amdgpu_copy_buffer().

We could add another warning to amdgpu_copy_buffer(), but that is just the backend function.

Quoted 5 lines

Looking at the implementation of
amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with the current limit it could issue subsequent copies that aren't 256 byte aligned.

"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Well according to this comments the size restriction is 32 bytes (256 bits!) and not 256 bytes.

Were do you actually get the 256 bytes restriction from?

Regards,
Christian.

Quoted 5 lines

Best regards,
Timur

#5 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 20 lines · Christian König
Quoted 19 lines · Timur Kristóf
Quoted 2 lines

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Hi Christian,

The kernel and Mesa disagree on the limits for almost all SDMA versions, so it would be nice to actually understand what the limits of
the SDMA HW are and use the same limit in the kernel and Mesa, or if
that isn't viable, let's document why the different limits make sense.

I'm adding Marek to CC, he wrote the comment that I referenced here.
As far as I understand from my conversation with Marek, the kernel is
actually wrong.

Quoted 8 lines
Quoted 5 lines

If the limits depend on alignment, then we should either set a limit
that is always safe, or make sure SDMA copies in the kernel are always
aligned and add assertions about it.

That's already done. See the size restrictions applied to BOs and the callers of amdgpu_copy_buffer().

Based on the code comments I cited, as far as I understand, the issue is with copying the last 256 bytes of 2^22-1. Do I understood your response correctly that you are saying that the kernel isn't affected by this issue because it always copies things that are 256 byte aligned?

I checked the callers of amdgpu_copy_buffer and can't find what you are referring to. However, assuming that all callers use amdgpu_copy_buffer on 256 byte aligned addresses, there is still an issue with large BOs:

When the kernel copies a BO that is larger than 0x3fffe0 bytes then it needs to emit multiple SDMA copy packets, and the copy done by the second packet (and other subsequent packets) won't be 256 byte aligned.

Quoted 10 lines

We could add another warning to amdgpu_copy_buffer(), but that is just the backend function.

Quoted 5 lines

Looking at the implementation of
amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with the current limit it could issue subsequent copies that aren't 256 byte aligned.

Quoted 7 lines

"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Well according to this comments the size restriction is 32 bytes (256 bits!) and not 256 bytes.

Were do you actually get the 256 bytes restriction from?

The comments I cited above are from the following sources:

PAL uses 1<<22-256 = 0x3fff00 here:
https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308

Mesa also uses 0x3fff00 here:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390

The limit in Mesa was added by this commit:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
According to the commit message, Dave added this limit when hitting an issue trying to use SDMA with buffers that are larger than this.

For SDMA v5.2 and newer, a larger limit was added by Marek later:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
Which confirms the same issue copying the last 256 bytes on these versions, although in this case the kernel isn't technically wrong because it uses a smaller overall maximum.

maintainer
#6 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 27 lines · Timur Kristóf
Quoted 26 lines · Christian König
Quoted 24 lines · Timur Kristóf
Quoted 2 lines

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Hi Christian,

The kernel and Mesa disagree on the limits for almost all SDMA versions, so it would be nice to actually understand what the limits of
the SDMA HW are and use the same limit in the kernel and Mesa, or if
that isn't viable, let's document why the different limits make sense.

I'm adding Marek to CC, he wrote the comment that I referenced here.
As far as I understand from my conversation with Marek, the kernel is
actually wrong.

If the limits depend on alignment, then we should either set a limit
that is always safe, or make sure SDMA copies in the kernel are always
aligned and add assertions about it.

Quoted 8 lines
Quoted 2 lines

That's already done. See the size restrictions applied to BOs and the callers of amdgpu_copy_buffer().

Based on the code comments I cited, as far as I understand, the issue is with copying the last 256 bytes of 2^22-1. Do I understood your response correctly that you are saying that the kernel isn't affected by this issue because it always copies things that are 256 byte aligned?

Yes, see the kernel always works with at least PAGE_SIZE buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

Quoted 7 lines

I checked the callers of amdgpu_copy_buffer and can't find what you are referring to. However, assuming that all callers use amdgpu_copy_buffer on 256 byte aligned addresses, there is still an issue with large BOs:

When the kernel copies a BO that is larger than 0x3fffe0 bytes then it needs to emit multiple SDMA copy packets, and the copy done by the second packet (and other subsequent packets) won't be 256 byte aligned.

I've just double checked the documentation and for SI it clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies and that limit applies there as well.

Quoted 31 lines
Quoted 10 lines

We could add another warning to amdgpu_copy_buffer(), but that is just the backend function.

Quoted 5 lines

Looking at the implementation of
amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with the current limit it could issue subsequent copies that aren't 256 byte aligned.

Quoted 7 lines

"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Well according to this comments the size restriction is 32 bytes (256 bits!) and not 256 bytes.

Were do you actually get the 256 bytes restriction from?

The comments I cited above are from the following sources:

PAL uses 1<<22-256 = 0x3fff00 here:
https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308

Mesa also uses 0x3fff00 here:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390

The limit in Mesa was added by this commit:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
According to the commit message, Dave added this limit when hitting an issue trying to use SDMA with buffers that are larger than this.

Quoted 5 lines

For SDMA v5.2 and newer, a larger limit was added by Marek later:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
Which confirms the same issue copying the last 256 bytes on these versions, although in this case the kernel isn't technically wrong because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where src and dst are byte aligned, but size isn't:

    if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
        IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
        (*pBytesCopied >= sizeof(uint32)))

....

So it totally makes sense to use the lower limit in Mesa but not for the kernel.

Regards,
Christian.

#7 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Marek

Quoted 122 lines · Christian König
Quoted 27 lines · Timur Kristóf
Quoted 26 lines · Christian König
Quoted 24 lines · Timur Kristóf
Quoted 2 lines

Even when we apply it I think we should drop that, the value the kernel uses is correct.

Hi Christian,

The kernel and Mesa disagree on the limits for almost all SDMA versions, so it would be nice to actually understand what the limits of
the SDMA HW are and use the same limit in the kernel and Mesa, or if
that isn't viable, let's document why the different limits make sense.

I'm adding Marek to CC, he wrote the comment that I referenced here.
As far as I understand from my conversation with Marek, the kernel is
actually wrong.

If the limits depend on alignment, then we should either set a limit
that is always safe, or make sure SDMA copies in the kernel are always
aligned and add assertions about it.

Quoted 8 lines
Quoted 2 lines

That's already done. See the size restrictions applied to BOs and the callers of amdgpu_copy_buffer().

Based on the code comments I cited, as far as I understand, the issue is with copying the last 256 bytes of 2^22-1. Do I understood your response correctly that you are saying that the kernel isn't affected by this issue because it always copies things that are 256 byte aligned?

Yes, see the kernel always works with at least PAGE_SIZE buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

Quoted 7 lines

I checked the callers of amdgpu_copy_buffer and can't find what you are referring to. However, assuming that all callers use amdgpu_copy_buffer on 256 byte aligned addresses, there is still an issue with large BOs:

When the kernel copies a BO that is larger than 0x3fffe0 bytes then it needs to emit multiple SDMA copy packets, and the copy done by the second packet (and other subsequent packets) won't be 256 byte aligned.

I've just double checked the documentation and for SI it clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies and that limit applies there as well.

Quoted 13 lines
Quoted 13 lines

We could add another warning to amdgpu_copy_buffer(), but that is just the backend function.

Quoted 5 lines

Looking at the implementation of
amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with the current limit it could issue subsequent copies that aren't 256 byte aligned.

"Due to HW limitation, the maximum count may not be 2^n-1, can only be 2^n - 1 - start_addr[4:2]"

Quoted 9 lines
Quoted 4 lines

Well according to this comments the size restriction is 32 bytes (256 bits!) and not 256 bytes.

Were do you actually get the 256 bytes restriction from?

The comments I cited above are from the following sources:

PAL uses 1<<22-256 = 0x3fff00 here:

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308

Quoted 3 lines

Mesa also uses 0x3fff00 here:

https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390

Quoted 3 lines

The limit in Mesa was added by this commit:

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed

Quoted 5 lines

According to the commit message, Dave added this limit when hitting an issue trying to use SDMA with buffers that are larger than this.

For SDMA v5.2 and newer, a larger limit was added by Marek later:

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259

Quoted 3 lines

Which confirms the same issue copying the last 256 bytes on these versions, although in this case the kernel isn't technically wrong because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where src and dst are byte aligned, but size isn't:

    if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
        IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
        (*pBytesCopied >= sizeof(uint32)))

....

So it totally makes sense to use the lower limit in Mesa but not for the kernel.

Regards,
Christian.

maintainer
#8 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 1 line · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 111 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <[email protected] <mailto:[email protected]>> wrote:

On 10.09.25 11:34, Timur Kristóf wrote:
> On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
>> On 09.09.25 18:56, Timur Kristóf wrote:
>>>> Even when we apply it I think we should drop that, the value the >>>> kernel uses is correct.
>>>
>>> Hi Christian,
>>>
>>> The kernel and Mesa disagree on the limits for almost all SDMA >>> versions, so it would be nice to actually understand what the >>> limits of
>>> the SDMA HW are and use the same limit in the kernel and Mesa, or >>> if
>>> that isn't viable, let's document why the different limits make >>> sense.
>>>
>>> I'm adding Marek to CC, he wrote the comment that I referenced >>> here.
>>> As far as I understand from my conversation with Marek, the kernel >>> is
>>> actually wrong.
>>>
>>> If the limits depend on alignment, then we should either set a >>> limit
>>> that is always safe, or make sure SDMA copies in the kernel are >>> always
>>> aligned and add assertions about it.
>>
>> That's already done. See the size restrictions applied to BOs and the >> callers of amdgpu_copy_buffer().
>
> Based on the code comments I cited, as far as I understand, the issue > is with copying the last 256 bytes of 2^22-1. Do I understood your > response correctly that you are saying that the kernel isn't affected > by this issue because it always copies things that are 256 byte > aligned?

Yes, see the kernel always works with at least PAGE_SIZE buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

> I checked the callers of amdgpu_copy_buffer and can't find what you are > referring to. However, assuming that all callers use amdgpu_copy_buffer > on 256 byte aligned addresses, there is still an issue with large BOs:
>
> When the kernel copies a BO that is larger than 0x3fffe0 bytes then it > needs to emit multiple SDMA copy packets, and the copy done by the > second packet (and other subsequent packets) won't be 256 byte aligned.

I've just double checked the documentation and for SI it clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies and that limit applies there as well.

>>
>> We could add another warning to amdgpu_copy_buffer(), but that is
>> just the backend function.
>>
>>> Looking at the implementation of
>>> amdgpu_copy_buffer in the kernel, I see that it relies on
>>> copy_max_bytes and doesn't take alignment into account, so with the
>>> current limit it could issue subsequent copies that aren't 256 byte
>>> aligned.
>>
>> "Due to HW limitation, the maximum count may not be 2^n-1, can only
>> be 2^n - 1 - start_addr[4:2]"
>>
>> Well according to this comments the size restriction is 32 bytes (256
>> bits!) and not 256 bytes.
>>
>> Were do you actually get the 256 bytes restriction from?
>
> The comments I cited above are from the following sources:
>
> PAL uses 1<<22-256 = 0x3fff00 here:
> https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308 <https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308>
>
> Mesa also uses 0x3fff00 here:
> https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390 <https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390>
>
> The limit in Mesa was added by this commit:
> https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed <https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed>
> According to the commit message, Dave added this limit when hitting an
> issue trying to use SDMA with buffers that are larger than this.
>
> For SDMA v5.2 and newer, a larger limit was added by Marek later:
> https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259 <https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259>
> Which confirms the same issue copying the last 256 bytes on these
> versions, although in this case the kernel isn't technically wrong
> because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where src and dst are byte aligned, but size isn't:

    if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) && IsPow2Aligned(dstGpuAddr, sizeof(uint32)) && (*pBytesCopied >= sizeof(uint32)))
....

So it totally makes sense to use the lower limit in Mesa but not for the kernel.

Regards,
Christian.

#9 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

I added the comment into Mesa that 0x3fff00 is the limit. I did research on that bug separately from PAL, but I don't remember the details.

There is no performance to gain here. It's only about consistency and clear communication to the public what the recommended SDMA programming is.

Marek

Quoted 169 lines · Christian König
Quoted 1 line · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no

benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 4 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <

Quoted 17 lines · [email protected] <mailto:[email protected]>> wrote:

On 10.09.25 11:34, Timur Kristóf wrote:
> On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
>> On 09.09.25 18:56, Timur Kristóf wrote:
>>>> Even when we apply it I think we should drop that, the value the >>>> kernel uses is correct.
>>>
>>> Hi Christian,
>>>
>>> The kernel and Mesa disagree on the limits for almost all SDMA >>> versions, so it would be nice to actually understand what the >>> limits of
>>> the SDMA HW are and use the same limit in the kernel and Mesa, or >>> if
>>> that isn't viable, let's document why the different limits make >>> sense.
>>>

Quoted 3 lines

>>> I'm adding Marek to CC, he wrote the comment that I referenced >>> here.
>>> As far as I understand from my conversation with Marek, the

kernel

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

is
actually wrong.

If the limits depend on alignment, then we should either set a limit
that is always safe, or make sure SDMA copies in the kernel are always
aligned and add assertions about it.

That's already done. See the size restrictions applied to BOs and

the

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

callers of amdgpu_copy_buffer().

Based on the code comments I cited, as far as I understand, the

issue

Quoted 2 lines
Quoted 2 lines

is with copying the last 256 bytes of 2^22-1. Do I understood your response correctly that you are saying that the kernel isn't

affected

Quoted 4 lines
Quoted 2 lines

by this issue because it always copies things that are 256 byte aligned?

Yes, see the kernel always works with at least PAGE_SIZE buffers

(between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

Quoted 2 lines

The only exception is the debugger interface, but that always copies

< PAGE_SIZE, so the SDMA limits are irrelevant.

Quoted 2 lines
Quoted 2 lines

I checked the callers of amdgpu_copy_buffer and can't find what

you are

Quoted 1 line
Quoted 1 line

referring to. However, assuming that all callers use

amdgpu_copy_buffer

Quoted 1 line
Quoted 1 line

on 256 byte aligned addresses, there is still an issue with large

BOs:

Quoted 2 lines
Quoted 2 lines

When the kernel copies a BO that is larger than 0x3fffe0 bytes

then it

Quoted 2 lines
Quoted 2 lines

needs to emit multiple SDMA copy packets, and the copy done by the second packet (and other subsequent packets) won't be 256 byte

aligned.

Quoted 2 lines

I've just double checked the documentation and for SI it clearly

states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1
- start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

Quoted 2 lines

For backward, tiled and windowed copies a 256byte bounce buffer is

used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Quoted 2 lines

Looks like that buffer is also used for byte aligned copies and that

limit applies there as well.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

We could add another warning to amdgpu_copy_buffer(), but that is just the backend function.

Quoted 3 lines

Looking at the implementation of
amdgpu_copy_buffer in the kernel, I see that it relies on copy_max_bytes and doesn't take alignment into account, so with

the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

current limit it could issue subsequent copies that aren't 256

byte

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

aligned.

"Due to HW limitation, the maximum count may not be 2^n-1, can

only

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

be 2^n - 1 - start_addr[4:2]"

Well according to this comments the size restriction is 32 bytes

(256

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

bits!) and not 256 bytes.

Were do you actually get the 256 bytes restriction from?

The comments I cited above are from the following sources:

PAL uses 1<<22-256 = 0x3fff00 here:

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308
<
https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308

Quoted 4 lines
Quoted 4 lines

Mesa also uses 0x3fff00 here:

https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390
<
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390

Quoted 4 lines
Quoted 4 lines

The limit in Mesa was added by this commit:

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
<
https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed

Quoted 2 lines
Quoted 2 lines

According to the commit message, Dave added this limit when

hitting an

Quoted 4 lines
Quoted 4 lines

issue trying to use SDMA with buffers that are larger than this.

For SDMA v5.2 and newer, a larger limit was added by Marek later:

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
<
https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259

Quoted 6 lines
Quoted 4 lines

Which confirms the same issue copying the last 256 bytes on these versions, although in this case the kernel isn't technically wrong because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow byte

aligned copies as well then you have to use 0x3fff00 as maximum.

Quoted 2 lines

The PAL code even has extra checks to speed up copies where src and

dst are byte aligned, but size isn't:

Quoted 7 lines
        if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
            IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
            (*pBytesCopied >= sizeof(uint32)))
    ....

    So it totally makes sense to use the lower limit in Mesa but not for

the kernel.

Quoted 4 lines

Regards,
Christian.

#10 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 9 lines · Marek Olšák

I added the comment into Mesa that 0x3fff00 is the limit. I did research on that bug separately from PAL, but I don't remember the details.

There is no performance to gain here. It's only about consistency and clear communication to the public what the recommended SDMA programming is.

Marek

Hi Christian & Marek,

I'd be happy to submit a new patch series if we can agree on what the limits are for each SDMA version and how to get the best performance from it.

I trust Marek's word that he did his research when he came up with 0x3fff00 so I don't understand the pushback here.

(1) According to a conversation between Marek and myself, the most optimal way to program the SDMA would be to use 256-byte-aligned copy packets. Christian, do you agree with this? If yes, I can write a patch for that. If not, let me know what you would prefer.

(2) I'd like us to come to an agreement on the maximum amount of bytes copied per SDMA packet, and align the kernel code with Mesa. At the moment, the maximum limit is different for every SDMA version between the kernel and Mesa, which makes the whole topic super confusing.

Please keep in mind that if there is any chance that the current limit is indeed incorrect (as it sounds like it is), we risk "random" SDMA hangs on users' machines.

Thanks & best regards,
Timur

Quoted 188 lines
Quoted 185 lines · Christian König
Quoted 3 lines · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 170 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <[email protected] <mailto:[email protected]>> wrote:

     On 10.09.25 11:34, Timur Kristóf wrote:
     > On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
     >> On 09.09.25 18:56, Timur Kristóf wrote:
     >>>> Even when we apply it I think we should drop that, the value the
     >>>> kernel uses is correct.
     >>>
     >>> Hi Christian,
     >>>
     >>> The kernel and Mesa disagree on the limits for almost all SDMA
     >>> versions, so it would be nice to actually understand what the
     >>> limits of
     >>> the SDMA HW are and use the same limit in the kernel and Mesa, or
     >>> if
     >>> that isn't viable, let's document why the different limits make
     >>> sense.
     >>>
     >>> I'm adding Marek to CC, he wrote the comment that I referenced
     >>> here.
     >>> As far as I understand from my conversation with Marek, the kernel
     >>> is
     >>> actually wrong.
     >>>
     >>> If the limits depend on alignment, then we should either set a
     >>> limit
     >>> that is always safe, or make sure SDMA copies in the kernel are
     >>> always
     >>> aligned and add assertions about it.
     >>
     >> That's already done. See the size restrictions applied to BOs and the
     >> callers of amdgpu_copy_buffer().
     >
     > Based on the code comments I cited, as far as I understand, the issue
     > is with copying the last 256 bytes of 2^22-1. Do I understood your
     > response correctly that you are saying that the kernel isn't affected
     > by this issue because it always copies things that are 256 byte
     > aligned?

     Yes, see the kernel always works with at least PAGE_SIZE buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

     The only exception is the debugger interface, but that always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

     > I checked the callers of amdgpu_copy_buffer and can't find what you are
     > referring to. However, assuming that all callers use amdgpu_copy_buffer
     > on 256 byte aligned addresses, there is still an issue with large BOs:
     >
     > When the kernel copies a BO that is larger than 0x3fffe0 bytes then it
     > needs to emit multiple SDMA copy packets, and the copy done by the
     > second packet (and other subsequent packets) won't be 256 byte aligned.

     I've just double checked the documentation and for SI it clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

     For backward, tiled and windowed copies a 256byte bounce buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

     Looks like that buffer is also used for byte aligned copies and that limit applies there as well.

     >>
     >> We could add another warning to amdgpu_copy_buffer(), but that is
     >> just the backend function.
     >>
     >>> Looking at the implementation of
     >>> amdgpu_copy_buffer in the kernel, I see that it relies on
     >>> copy_max_bytes and doesn't take alignment into account, so with the
     >>> current limit it could issue subsequent copies that aren't 256 byte
     >>> aligned.
     >>
     >> "Due to HW limitation, the maximum count may not be 2^n- 1, can only
     >> be 2^n - 1 - start_addr[4:2]"
     >>
     >> Well according to this comments the size restriction is 32 bytes (256
     >> bits!) and not 256 bytes.
     >>
     >> Were do you actually get the 256 bytes restriction from? >
     > The comments I cited above are from the following sources:
     >
     > PAL uses 1<<22-256 = 0x3fff00 here:
     >
https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308
<https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d48
6a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp# L308>
     >
     > Mesa also uses 0x3fff00 here:
     >
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390
<https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd3622
4c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390>
     >
     > The limit in Mesa was added by this commit:
     >
https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be
50222411bc0d41c095004232ed>
     > According to the commit message, Dave added this limit when hitting an
     > issue trying to use SDMA with buffers that are larger than this.
     >
     > For SDMA v5.2 and newer, a larger limit was added by Marek later:
     >
https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666f
cbe38c04660cc4b3f8abbde259>
     > Which confirms the same issue copying the last 256 bytes on these
     > versions, although in this case the kernel isn't technically wrong
     > because it uses a smaller overall maximum.

     Yeah, I mean that totally makes sense. When you want allow byte aligned copies as well then you have to use 0x3fff00 as maximum.

     The PAL code even has extra checks to speed up copies where src and dst are byte aligned, but size isn't:

         if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) && IsPow2Aligned(dstGpuAddr, sizeof(uint32)) && (*pBytesCopied >= sizeof(uint32)))
     ....

     So it totally makes sense to use the lower limit in Mesa but not for the kernel.

     Regards,
     Christian.

#11 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 26 lines · Timur Kristóf
Quoted 9 lines · Marek Olšák

I added the comment into Mesa that 0x3fff00 is the limit. I did research on that bug separately from PAL, but I don't remember the details.

There is no performance to gain here. It's only about consistency and clear communication to the public what the recommended SDMA programming is.

Marek

Hi Christian & Marek,

I'd be happy to submit a new patch series if we can agree on what the limits are for each SDMA version and how to get the best performance from it.

I trust Marek's word that he did his research when he came up with 0x3fff00 so I don't understand the pushback here.

(1) According to a conversation between Marek and myself, the most optimal way to program the SDMA would be to use 256-byte-aligned copy packets. Christian, do you agree with this? If yes, I can write a patch for that. If not, let me know what you would prefer.

Quoted 5 lines

(2) I'd like us to come to an agreement on the maximum amount of bytes copied per SDMA packet, and align the kernel code with Mesa. At the moment, the maximum limit is different for every SDMA version between the kernel and Mesa, which makes the whole topic super confusing.

SI didn't have SDMA. It used the older paging and DMA engine. SDMA 2.x used byte_count directly in the packet so the limit is 0x1fffff SDMA 3.x used byte_count directly in the packet so the limit is 0x3fffe0 or 0x3fff00 depending on alignment.
SDMA 4.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 4.4.x used byte_count -1 in the packet and increased the limit to 0x4000000.
SDMA 5.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 5.2.x and newer used byte_count -1 in the packet and increased the limit to 0x4000000.

Alex

Quoted 198 lines

Please keep in mind that if there is any chance that the current limit is indeed incorrect (as it sounds like it is), we risk "random" SDMA hangs on users' machines.

Thanks & best regards,
Timur

Quoted 188 lines
Quoted 185 lines · Christian König
Quoted 3 lines · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 170 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <[email protected] <mailto:[email protected]>> wrote:

     On 10.09.25 11:34, Timur Kristóf wrote:
     > On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
     >> On 09.09.25 18:56, Timur Kristóf wrote:
     >>>> Even when we apply it I think we should drop that, the

value the
>>>> kernel uses is correct.
>>>
>>> Hi Christian,
>>>
>>> The kernel and Mesa disagree on the limits for almost
all SDMA
>>> versions, so it would be nice to actually understand
what the
>>> limits of
>>> the SDMA HW are and use the same limit in the kernel and
Mesa, or
>>> if
>>> that isn't viable, let's document why the different
limits make

     >>> sense.
     >>>
     >>> I'm adding Marek to CC, he wrote the comment that I

referenced
>>> here.
>>> As far as I understand from my conversation with Marek,
the kernel
>>> is
>>> actually wrong.
>>>
>>> If the limits depend on alignment, then we should either
set a
>>> limit
>>> that is always safe, or make sure SDMA copies in the
kernel are
>>> always
>>> aligned and add assertions about it.
>>
>> That's already done. See the size restrictions applied to
BOs and the
>> callers of amdgpu_copy_buffer().
>
> Based on the code comments I cited, as far as I
understand, the issue
> is with copying the last 256 bytes of 2^22-1. Do I
understood your
> response correctly that you are saying that the kernel
isn't affected
> by this issue because it always copies things that are 256
byte
> aligned?

Yes, see the kernel always works with at least PAGE_SIZE
buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that
always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

> I checked the callers of amdgpu_copy_buffer and can't find
what you are
> referring to. However, assuming that all callers use
amdgpu_copy_buffer
> on 256 byte aligned addresses, there is still an issue
with large BOs:

     >
     > When the kernel copies a BO that is larger than 0x3fffe0

bytes then it
> needs to emit multiple SDMA copy packets, and the copy
done by the
> second packet (and other subsequent packets) won't be 256
byte aligned.

I've just double checked the documentation and for SI it
clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce
buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies
and that limit applies there as well.

>>
>> We could add another warning to amdgpu_copy_buffer(), but
that is
>> just the backend function.
>>
>>> Looking at the implementation of
>>> amdgpu_copy_buffer in the kernel, I see that it relies
on
>>> copy_max_bytes and doesn't take alignment into account,
so with the
>>> current limit it could issue subsequent copies that
aren't 256 byte

     >>> aligned.
     >>
     >> "Due to HW limitation, the maximum count may not be 2^n-
1, can only
     >> be 2^n - 1 - start_addr[4:2]"
     >>
     >> Well according to this comments the size restriction is
32 bytes (256
     >> bits!) and not 256 bytes.
     >>
     >> Were do you actually get the 256 bytes restriction from?
     >
     > The comments I cited above are from the following sources:
     >
     > PAL uses 1<<22-256 = 0x3fff00 here:
     >

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308
<https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d48
6a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp# L308>

     >
     > Mesa also uses 0x3fff00 here:
     >
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390
<https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd3622
4c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390>
     >
     > The limit in Mesa was added by this commit:
     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be
50222411bc0d41c095004232ed>
> According to the commit message, Dave added this limit
when hitting an
> issue trying to use SDMA with buffers that are larger than
this.
>
> For SDMA v5.2 and newer, a larger limit was added by Marek
later:

     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666f
cbe38c04660cc4b3f8abbde259>
> Which confirms the same issue copying the last 256 bytes
on these
> versions, although in this case the kernel isn't
technically wrong
> because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow
byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where
src and dst are byte aligned, but size isn't:

         if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
             IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
             (*pBytesCopied >= sizeof(uint32)))
     ....

     So it totally makes sense to use the lower limit in Mesa but

not for the kernel.

Regards,
Christian.

#12 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

Quoted 33 lines · Alex Deucher
Quoted 26 lines · Timur Kristóf
Quoted 9 lines · Marek Olšák

I added the comment into Mesa that 0x3fff00 is the limit. I did research on that bug separately from PAL, but I don't remember the details.

There is no performance to gain here. It's only about consistency and clear communication to the public what the recommended SDMA programming is.

Marek

Hi Christian & Marek,

I'd be happy to submit a new patch series if we can agree on what the limits are for each SDMA version and how to get the best performance from it.

I trust Marek's word that he did his research when he came up with 0x3fff00 so I don't understand the pushback here.

(1) According to a conversation between Marek and myself, the most optimal way to program the SDMA would be to use 256-byte-aligned copy packets. Christian, do you agree with this? If yes, I can write a patch for that. If not, let me know what you would prefer.

Quoted 5 lines

(2) I'd like us to come to an agreement on the maximum amount of bytes copied per SDMA packet, and align the kernel code with Mesa. At the moment, the maximum limit is different for every SDMA version between the kernel and Mesa, which makes the whole topic super confusing.

Quoted 10 lines

SI didn't have SDMA. It used the older paging and DMA engine. SDMA 2.x used byte_count directly in the packet so the limit is 0x1fffff SDMA 3.x used byte_count directly in the packet so the limit is 0x3fffe0 or 0x3fff00 depending on alignment.
SDMA 4.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 4.4.x used byte_count -1 in the packet and increased the limit to 0x4000000.
SDMA 5.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 5.2.x and newer used byte_count -1 in the packet and increased the limit to 0x4000000.

Sorry I typed these. There are 22 bits of byte count (0x400000) sdma 4.0.x and 5.0.x, and 30 bits of byte count for sdma 4.4.x and sdma 5.2 and newer (0x40000000).

Alex

Quoted 201 lines

Alex

Quoted 198 lines

Please keep in mind that if there is any chance that the current limit is indeed incorrect (as it sounds like it is), we risk "random" SDMA hangs on users' machines.

Thanks & best regards,
Timur

Quoted 188 lines
Quoted 185 lines · Christian König
Quoted 3 lines · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 170 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <[email protected] <mailto:[email protected]>> wrote:

     On 10.09.25 11:34, Timur Kristóf wrote:
     > On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
     >> On 09.09.25 18:56, Timur Kristóf wrote:
     >>>> Even when we apply it I think we should drop that, the

value the
>>>> kernel uses is correct.
>>>
>>> Hi Christian,
>>>
>>> The kernel and Mesa disagree on the limits for almost
all SDMA
>>> versions, so it would be nice to actually understand
what the
>>> limits of
>>> the SDMA HW are and use the same limit in the kernel and
Mesa, or
>>> if
>>> that isn't viable, let's document why the different
limits make

     >>> sense.
     >>>
     >>> I'm adding Marek to CC, he wrote the comment that I

referenced
>>> here.
>>> As far as I understand from my conversation with Marek,
the kernel
>>> is
>>> actually wrong.
>>>
>>> If the limits depend on alignment, then we should either
set a
>>> limit
>>> that is always safe, or make sure SDMA copies in the
kernel are
>>> always
>>> aligned and add assertions about it.
>>
>> That's already done. See the size restrictions applied to
BOs and the
>> callers of amdgpu_copy_buffer().
>
> Based on the code comments I cited, as far as I
understand, the issue
> is with copying the last 256 bytes of 2^22-1. Do I
understood your
> response correctly that you are saying that the kernel
isn't affected
> by this issue because it always copies things that are 256
byte
> aligned?

Yes, see the kernel always works with at least PAGE_SIZE
buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that
always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

> I checked the callers of amdgpu_copy_buffer and can't find
what you are
> referring to. However, assuming that all callers use
amdgpu_copy_buffer
> on 256 byte aligned addresses, there is still an issue
with large BOs:

     >
     > When the kernel copies a BO that is larger than 0x3fffe0

bytes then it
> needs to emit multiple SDMA copy packets, and the copy
done by the
> second packet (and other subsequent packets) won't be 256
byte aligned.

I've just double checked the documentation and for SI it
clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce
buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies
and that limit applies there as well.

>>
>> We could add another warning to amdgpu_copy_buffer(), but
that is
>> just the backend function.
>>
>>> Looking at the implementation of
>>> amdgpu_copy_buffer in the kernel, I see that it relies
on
>>> copy_max_bytes and doesn't take alignment into account,
so with the
>>> current limit it could issue subsequent copies that
aren't 256 byte

     >>> aligned.
     >>
     >> "Due to HW limitation, the maximum count may not be 2^n-
1, can only
     >> be 2^n - 1 - start_addr[4:2]"
     >>
     >> Well according to this comments the size restriction is
32 bytes (256
     >> bits!) and not 256 bytes.
     >>
     >> Were do you actually get the 256 bytes restriction from?
     >
     > The comments I cited above are from the following sources:
     >
     > PAL uses 1<<22-256 = 0x3fff00 here:
     >

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308
<https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d48
6a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp# L308>

     >
     > Mesa also uses 0x3fff00 here:
     >
https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390
<https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd3622
4c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390>
     >
     > The limit in Mesa was added by this commit:
     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be
50222411bc0d41c095004232ed>
> According to the commit message, Dave added this limit
when hitting an
> issue trying to use SDMA with buffers that are larger than
this.
>
> For SDMA v5.2 and newer, a larger limit was added by Marek
later:

     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259
<https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666f
cbe38c04660cc4b3f8abbde259>
> Which confirms the same issue copying the last 256 bytes
on these
> versions, although in this case the kernel isn't
technically wrong
> because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow
byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where
src and dst are byte aligned, but size isn't:

         if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
             IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
             (*pBytesCopied >= sizeof(uint32)))
     ....

     So it totally makes sense to use the lower limit in Mesa but

not for the kernel.

Regards,
Christian.

#13 lore raw

Re: [PATCH 2/3] drm/amdgpu: Set SDMA v3 copy_max_bytes to 0x3fff00

The optimal alignment for performance would be 256B because that's the granularity of interleaving memory channels if you care about not overloading one memory channel on the packet break. In other cases, like gfx10 and newer, the next optimal alignment is 128B because that's the cache line size, which is the maximum request size. If uncached, the next optimal alignment is the minimum memory request size, which is 32B or 64B.

Since the kernel likely copies with VMID 0, the page table alignment doesn't even enter the picture, though it would be cheap because it would be a UTCL2 cache hit.

Marek

Quoted 263 lines · On Thu, Sep 11, 2025, 13:52 Alex Deucher <[email protected]> wrote:
Quoted 2 lines · Alex Deucher

On Wed, Sep 10, 2025 at 2:38 PM Timur Kristóf <[email protected]>

Quoted 31 lines · wrote:
Quoted 26 lines · Marek Olšák
Quoted 9 lines

I added the comment into Mesa that 0x3fff00 is the limit. I did research on that bug separately from PAL, but I don't remember the details.

There is no performance to gain here. It's only about consistency and clear communication to the public what the recommended SDMA programming is.

Marek

Hi Christian & Marek,

I'd be happy to submit a new patch series if we can agree on what the limits are for each SDMA version and how to get the best performance from it.

I trust Marek's word that he did his research when he came up with 0x3fff00 so I don't understand the pushback here.

(1) According to a conversation between Marek and myself, the most optimal way to program the SDMA would be to use 256-byte-aligned copy packets. Christian, do you agree with this? If yes, I can write a patch for that. If not, let me know what you would prefer.

Quoted 5 lines

(2) I'd like us to come to an agreement on the maximum amount of bytes copied per SDMA packet, and align the kernel code with Mesa. At the moment, the maximum limit is different for every SDMA version between the kernel and Mesa, which makes the whole topic super confusing.

Quoted 10 lines

SI didn't have SDMA. It used the older paging and DMA engine. SDMA 2.x used byte_count directly in the packet so the limit is 0x1fffff SDMA 3.x used byte_count directly in the packet so the limit is 0x3fffe0 or 0x3fff00 depending on alignment.
SDMA 4.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 4.4.x used byte_count -1 in the packet and increased the limit to 0x4000000.
SDMA 5.0.x used byte_count -1 in the packet so the limit is 0x400000. SDMA 5.2.x and newer used byte_count -1 in the packet and increased the limit to 0x4000000.

Sorry I typed these. There are 22 bits of byte count (0x400000) sdma 4.0.x and 5.0.x, and 30 bits of byte count for sdma 4.4.x and sdma 5.2 and newer (0x40000000).

Alex

Quoted 150 lines

Alex

Quoted 147 lines

Please keep in mind that if there is any chance that the current limit is indeed incorrect (as it sounds like it is), we risk "random" SDMA hangs on users' machines.

Thanks & best regards,
Timur

Quoted 137 lines
Quoted 134 lines · Christian König
Quoted 3 lines · Marek Olšák

It's probably better to use 0x3fff00 to match Mesa and PAL. There is no benefit in using a different limit, not even a perf benefit, and it's better to be consistent with all UMDs.

Unification with Mesa is certainly a valid argument, but just using an approach because PAL does it has proven to be troublesome before.

If we are interested in best performance we should actually round down the value to the next multiple of PAGE_SIZE.

Christian.

Quoted 120 lines

Marek

On Wed, Sep 10, 2025 at 7:54 AM Christian König <[email protected] <mailto:[email protected]>> wrote:

     On 10.09.25 11:34, Timur Kristóf wrote:
     > On Wed, 2025-09-10 at 10:34 +0200, Christian König wrote:
     >> On 09.09.25 18:56, Timur Kristóf wrote:
     >>>> Even when we apply it I think we should drop that, the

value the
>>>> kernel uses is correct.
>>>
>>> Hi Christian,
>>>
>>> The kernel and Mesa disagree on the limits for almost
all SDMA
>>> versions, so it would be nice to actually understand
what the
>>> limits of
>>> the SDMA HW are and use the same limit in the kernel and
Mesa, or
>>> if
>>> that isn't viable, let's document why the different
limits make

     >>> sense.
     >>>
     >>> I'm adding Marek to CC, he wrote the comment that I

referenced
>>> here.
>>> As far as I understand from my conversation with Marek,
the kernel
>>> is
>>> actually wrong.
>>>
>>> If the limits depend on alignment, then we should either
set a
>>> limit
>>> that is always safe, or make sure SDMA copies in the
kernel are
>>> always
>>> aligned and add assertions about it.
>>
>> That's already done. See the size restrictions applied to
BOs and the
>> callers of amdgpu_copy_buffer().
>
> Based on the code comments I cited, as far as I
understand, the issue
> is with copying the last 256 bytes of 2^22-1. Do I
understood your
> response correctly that you are saying that the kernel
isn't affected
> by this issue because it always copies things that are 256
byte
> aligned?

Yes, see the kernel always works with at least PAGE_SIZE
buffers (between 4k and 64k depending on CPU architecture). You never get anything smaller than that.

The only exception is the debugger interface, but that
always copies < PAGE_SIZE, so the SDMA limits are irrelevant.

> I checked the callers of amdgpu_copy_buffer and can't find
what you are
> referring to. However, assuming that all callers use
amdgpu_copy_buffer
> on 256 byte aligned addresses, there is still an issue
with large BOs:

     >
     > When the kernel copies a BO that is larger than 0x3fffe0

bytes then it
> needs to emit multiple SDMA copy packets, and the copy
done by the
> second packet (and other subsequent packets) won't be 256
byte aligned.

I've just double checked the documentation and for SI it
clearly states that the limit is 0x3fffe0. Documentation for later HW says 2^22 - 1 - start_addr[4:2] (which is 0x1f in the worst case so you end up with 0x3fffe0 again).

For backward, tiled and windowed copies a 256byte bounce
buffer is used instead of the 32byte buffer for the linear copy. So the limit is then 0x3fff00.

Looks like that buffer is also used for byte aligned copies
and that limit applies there as well.

>>
>> We could add another warning to amdgpu_copy_buffer(), but
that is
>> just the backend function.
>>
>>> Looking at the implementation of
>>> amdgpu_copy_buffer in the kernel, I see that it relies
on
>>> copy_max_bytes and doesn't take alignment into account,
so with the
>>> current limit it could issue subsequent copies that
aren't 256 byte

     >>> aligned.
     >>
     >> "Due to HW limitation, the maximum count may not be 2^n-
1, can only
     >> be 2^n - 1 - start_addr[4:2]"
     >>
     >> Well according to this comments the size restriction is
32 bytes (256
     >> bits!) and not 256 bytes.
     >>
     >> Were do you actually get the 256 bytes restriction from?
     >
     > The comments I cited above are from the following sources:
     >
     > PAL uses 1<<22-256 = 0x3fff00 here:
     >

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d486a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp#L308

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<

https://github.com/GPUOpen-Drivers/pal/blob/bcec463efe5260776d48

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

6a5e3da0c549bc0a75d2/src/core/hw/ossip/oss2/oss2DmaCmdBuffer.cpp# L308>

     >
     > Mesa also uses 0x3fff00 here:
     >

https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd36224c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<

https://gitlab.freedesktop.org/mesa/mesa/-/blob/47f5d25f93fd3622

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

4c112ee2d48e511ae078f8c2/src/amd/common/sid.h#L390>

     >
     > The limit in Mesa was added by this commit:
     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be50222411bc0d41c095004232ed

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<

https://gitlab.freedesktop.org/mesa/mesa/-/commit/2c1f249f2b61be

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

50222411bc0d41c095004232ed>
> According to the commit message, Dave added this limit
when hitting an
> issue trying to use SDMA with buffers that are larger than
this.
>
> For SDMA v5.2 and newer, a larger limit was added by Marek
later:

     >

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666fcbe38c04660cc4b3f8abbde259

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<

https://gitlab.freedesktop.org/mesa/mesa/-/commit/a54bcb9429666f

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines

cbe38c04660cc4b3f8abbde259>
> Which confirms the same issue copying the last 256 bytes
on these
> versions, although in this case the kernel isn't
technically wrong
> because it uses a smaller overall maximum.

Yeah, I mean that totally makes sense. When you want allow
byte aligned copies as well then you have to use 0x3fff00 as maximum.

The PAL code even has extra checks to speed up copies where
src and dst are byte aligned, but size isn't:

         if (IsPow2Aligned(srcGpuAddr, sizeof(uint32)) &&
             IsPow2Aligned(dstGpuAddr, sizeof(uint32)) &&
             (*pBytesCopied >= sizeof(uint32)))
     ....

     So it totally makes sense to use the lower limit in Mesa but

not for the kernel.

Regards,
Christian.

#14 lore raw

PATCH 3/3 drm/amdgpu: Use memset32 for ring clearing

In reply to Timur Kristóf

From: Tvrtko Ursulin <[email protected]>

Use memset32 instead of open coding it, just because it is a tiny bit nicer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -4
index 12783ea3ba0f..20133ff43af3 100644
@@ -481,10 +481,7 @@ static inline void amdgpu_ring_set_preempt_cond_exec(struct amdgpu_ring *ring,
 
 static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 {
-	int i = 0;
-	while (i <= ring->buf_mask)
-		ring->ring[i++] = ring->funcs->nop;
-
+	memset32(ring->ring, ring->funcs->nop, ring->buf_mask + 1);
 }
 
 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 3/3
#15 lore raw

Re: [PATCH 3/3] drm/amdgpu: Use memset32 for ring clearing

Quoted 6 lines · Timur Kristóf

From: Tvrtko Ursulin <[email protected]>

Use memset32 instead of open coding it, just because it is a tiny bit nicer.

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -4
index 12783ea3ba0f..20133ff43af3 100644
@@ -481,10 +481,7 @@ static inline void amdgpu_ring_set_preempt_cond_exec(struct amdgpu_ring *ring,
 
 static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 {
-	int i = 0;
-	while (i <= ring->buf_mask)
-		ring->ring[i++] = ring->funcs->nop;
-
+	memset32(ring->ring, ring->funcs->nop, ring->buf_mask + 1);
 }
 
 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
#16 lore raw

Re: [PATCH 3/3] drm/amdgpu: Use memset32 for ring clearing

In reply to Timur Kristóf

Applied patches 1 and 3.

Thanks,

Alex

Quoted 30 lines · Timur Kristóf

From: Tvrtko Ursulin <[email protected]>

Use memset32 instead of open coding it, just because it is a tiny bit nicer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -5
index 12783ea3ba0f..20133ff43af3 100644
@@ -481,10 +481,7 @@ static inline void amdgpu_ring_set_preempt_cond_exec(struct amdgpu_ring *ring,
 
 static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 {
-       int i = 0;
-       while (i <= ring->buf_mask)
-               ring->ring[i++] = ring->funcs->nop;
-
+       memset32(ring->ring, ring->funcs->nop, ring->buf_mask + 1);
 }
 
 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
--

2.51.0

maintainer Reviewed-by on v1 1/3
#17 lore raw
In reply to Timur Kristóf
Quoted 11 lines · Timur Kristóf

Rename extra_dw to extra_bytes and document what it's for.

The value is already used as if it were bytes in vcn_v4_0.c and in amdgpu_ring_init. Just adjust the dword count in jpeg_v1_0.c so that it becomes a byte count.

v2:
Rename extra_dw to extra_bytes as discussed during review.

Fixes c8c1a1d2ef04 ("drm/amdgpu: define and add extra dword for jpeg ring")
Quoted 79 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 11 ++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdgpu/jpeg_v1_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c    |  2 +-
 4 files changed, 20 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +6 -5
index 6379bb25bf5c..eca8b28e3fb9 100644
@@ -364,11 +364,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 
 	/* Allocate ring buffer */
 	if (ring->ring_obj == NULL) {
-		r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,
-					    AMDGPU_GEM_DOMAIN_GTT,
-					    &ring->ring_obj,
-					    &ring->gpu_addr,
-					    (void **)&ring->ring);
+		r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_bytes,
+						PAGE_SIZE,
+						AMDGPU_GEM_DOMAIN_GTT,
+						&ring->ring_obj,
+						&ring->gpu_addr,
+						(void **)&ring->ring);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring create failed\n", r);
 			kvfree(ring->ring_backup);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +12 -1
index 7670f5d82b9e..12783ea3ba0f 100644
@@ -211,7 +211,18 @@ struct amdgpu_ring_funcs {
 	bool			support_64bit_ptrs;
 	bool			no_user_fence;
 	bool			secure_submission_supported;
-	unsigned		extra_dw;
+
+	/**
+	 * @extra_bytes:
+	 *
+	 * Optional extra space in bytes that is added to the ring size
+	 * when allocating the BO that holds the contents of the ring.
+	 * This space isn't used for command submission to the ring,
+	 * but is just there to satisfy some hardware requirements or
+	 * implement workarounds. It's up to the implementation of each
+	 * specific ring to initialize this space.
+	 */
+	unsigned		extra_bytes;
 
 	/* ring read/write ptr handling */
 	u64 (*get_rptr)(struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/jpeg_v1_0.c +1 -1
index 9e428e669ada..b5bb7f4d607c 100644
@@ -557,7 +557,7 @@ static const struct amdgpu_ring_funcs jpeg_v1_0_decode_ring_vm_funcs = {
 	.nop = PACKET0(0x81ff, 0),
 	.support_64bit_ptrs = false,
 	.no_user_fence = true,
-	.extra_dw = 64,
+	.extra_bytes = 256,
 	.get_rptr = jpeg_v1_0_decode_ring_get_rptr,
 	.get_wptr = jpeg_v1_0_decode_ring_get_wptr,
 	.set_wptr = jpeg_v1_0_decode_ring_set_wptr,
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
index d0d27790b73b..099698cb1a3d 100644
@@ -1986,7 +1986,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {
 	.type = AMDGPU_RING_TYPE_VCN_ENC,
 	.align_mask = 0x3f,
 	.nop = VCN_ENC_CMD_NO_OP,
-	.extra_dw = sizeof(struct amdgpu_vcn_rb_metadata),
+	.extra_bytes = sizeof(struct amdgpu_vcn_rb_metadata),
 	.get_rptr = vcn_v4_0_unified_ring_get_rptr,
 	.get_wptr = vcn_v4_0_unified_ring_get_wptr,
 	.set_wptr = vcn_v4_0_unified_ring_set_wptr,