Skip to contentSkip to conversation

drm/tests: shmem: Fix intermittent DMA overflow on ppc64le/s390x

PATCH Superseded José Expósito 2 participants 7 messages Jul 3

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover drm/tests: shmem: Fix intermittent DMA overflow on ppc64le/s390x

Two drm_gem_shmem KUnit tests, drm_gem_shmem_test_get_pages_sgt() and drm_gem_shmem_test_purge(), intermittently fail on ppc64le and s390x CI with a DMA address overflow warning followed by -EIO:

DMA addr 0x00000001130b0000+65536 overflow (mask ffffffff, bus limit 0). Expected sgt is not error, but is: -5

Both tests call drm_gem_shmem_get_pages_sgt(), which internally pins backing pages and DMA-maps them via dma_map_sgtable(). The DMA mapping path is:

drm_gem_shmem_test_purge()

    drm_gem_shmem_get_pages_sgt()
      drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
        dma_map_sgtable()                  [mapping.c]
          __dma_map_sg_attrs()
            dma_direct_map_sg()            [direct.c]
              dma_direct_map_phys()        [kernel/dma/direct.h]
                dma_capable()              Checks addr against DMA mask
                  -> FAILS: addr > 0xFFFFFFFF

KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On systems where the kernel allocates backing pages at physical addresses above 4GB, dma_capable() returns false because the address exceeds the 32-bit mask. The dma_set_mask() function updates *dev->dma_mask to the given value; setting it to DMA_BIT_MASK(64) allows any physical address to pass the check.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

A third test in the same suite, drm_gem_shmem_test_obj_create_private, already calls dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64)) before its DMA mapping. This series applies the same fix to the two remaining tests.

José Expósito (2):
drm/tests: shmem: Set DMA mask to 64-bit in
drm_gem_shmem_test_get_pages_sgt
drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_get_pages_sgt

From: José Expósito <[email protected]>

drm_gem_shmem_test_get_pages_sgt intermittently fails on ppc64le and s390x CI systems with a DMA address overflow: [1]

DMA addr 0x00000001b6110000+65536 overflow (mask ffffffff, bus limit 0)

  WARNING: kernel/dma/direct.h:114 dma_direct_map_phys+0x298/0x300

drm_gem_shmem_test_get_pages_sgt: ASSERTION FAILED at
drivers/gpu/drm/tests/drm_gem_shmem_test.c:255 Expected sgt is not error, but is: -5

The call chain leading to the failure is:

drm_gem_shmem_test_get_pages_sgt()

    drm_gem_shmem_get_pages_sgt()
      drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
        dma_map_sgtable()                  [mapping.c]
          __dma_map_sg_attrs()
            dma_direct_map_sg()            [direct.c]
              dma_direct_map_phys()        [kernel/dma/direct.h]
                dma_capable()              Checks addr against DMA mask
                  -> FAILS: addr > 0xFFFFFFFF

The root cause is that KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On ppc64le and s390x systems with physical memory above 4GB, page allocations can land at addresses that exceed this mask. When drm_gem_shmem_get_pages_sgt() attempts to DMA-map these pages via dma_map_sgtable(), the DMA layer rejects the mapping because the physical address overflows the 32-bit mask.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

Fix by setting a 64-bit DMA mask on the device before calling drm_gem_shmem_get_pages_sgt(), following the same pattern already used in drm_gem_shmem_test_obj_create_private().

[1] https://s3.amazonaws.com/arr-cki-prod-trusted-artifacts/trusted-artifacts/2643976103/test_ppc64le/15128551933/artifacts/jobwatch/logs/recipes/21561041/tasks/220716705/results/1014628163/logs/dmesg.log

Fixes 93032ae634d4 ("drm/test: add a test suite for GEM objects backed by shmem")
Assisted-by Claude:claude-4.6-opus
---
 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/tests/drm_gem_shmem_test.c +5 -1
index 44a190109249..c217a9ec7240 100644
@@ -250,7 +250,11 @@ static void drm_gem_shmem_test_get_pages_sgt(struct kunit *test)
 	struct drm_gem_shmem_object *shmem;
 	struct sg_table *sgt;
 	struct scatterlist *sg;
-	unsigned int si, ret, len = 0;
+	unsigned int si, len = 0;
+	int ret;
+
+	ret = dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64));
+	KUNIT_ASSERT_EQ(test, ret, 0);
 
 	shmem = drm_gem_shmem_create(drm_dev, TEST_SIZE);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem);
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/2 drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

In reply to José Expósito

From: José Expósito <[email protected]>

drm_gem_shmem_test_purge intermittently fails on ppc64le and s390x CI systems with a DMA address overflow: [1]

DMA addr 0x0000000100307000+4096 overflow (mask ffffffff, bus limit 0)

  WARNING: kernel/dma/direct.h:114 dma_direct_map_sg+0x778/0x920

drm_gem_shmem_test_purge: ASSERTION FAILED at
drivers/gpu/drm/tests/drm_gem_shmem_test.c:330 Expected sgt is not error, but is: -5

The call chain leading to the failure is:

drm_gem_shmem_test_purge()

    drm_gem_shmem_get_pages_sgt()
      drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
        dma_map_sgtable()                  [mapping.c]
          __dma_map_sg_attrs()
            dma_direct_map_sg()            [direct.c]
              dma_direct_map_phys()        [kernel/dma/direct.h]
                dma_capable()              Checks addr against DMA mask
                  -> FAILS: addr > 0xFFFFFFFF

The root cause is that KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On ppc64le and s390x systems with physical memory above 4GB, page allocations can land at addresses that exceed this mask. When drm_gem_shmem_get_pages_sgt() attempts to DMA-map these pages via dma_map_sgtable(), the DMA layer rejects the mapping because the physical address overflows the 32-bit mask.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

Fix by setting a 64-bit DMA mask on the device before calling drm_gem_shmem_get_pages_sgt(), following the same pattern already used in drm_gem_shmem_test_obj_create_private().

[1] https://s3.amazonaws.com/arr-cki-prod-trusted-artifacts/trusted-artifacts/2643976103/test_s390x/15128551935/artifacts/jobwatch/logs/recipes/21561049/tasks/220716793/results/1014626315/logs/dmesg.log

Fixes 93032ae634d4 ("drm/test: add a test suite for GEM objects backed by shmem")
Assisted-by Claude:claude-4.6-opus
---
 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/tests/drm_gem_shmem_test.c +3 -0
index c217a9ec7240..66dea51ac456 100644
@@ -325,6 +325,9 @@ static void drm_gem_shmem_test_purge(struct kunit *test)
 	struct sg_table *sgt;
 	int ret;
 
+	ret = dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64));
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	shmem = drm_gem_shmem_create(drm_dev, TEST_SIZE);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem);
 
Signature · 1 line
2.54.0
#3 lore raw
In reply to José Expósito

Hi

Am 03.07.26 um 08:34 schrieb José Expósito:

Quoted 28 lines

Two drm_gem_shmem KUnit tests, drm_gem_shmem_test_get_pages_sgt() and drm_gem_shmem_test_purge(), intermittently fail on ppc64le and s390x CI with a DMA address overflow warning followed by -EIO:

DMA addr 0x00000001130b0000+65536 overflow (mask ffffffff, bus limit 0). Expected sgt is not error, but is: -5

Both tests call drm_gem_shmem_get_pages_sgt(), which internally pins backing pages and DMA-maps them via dma_map_sgtable(). The DMA mapping path is:

   drm_gem_shmem_test_purge()
     drm_gem_shmem_get_pages_sgt()
       drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
         dma_map_sgtable()                  [mapping.c]
           __dma_map_sg_attrs()
             dma_direct_map_sg()            [direct.c]
               dma_direct_map_phys()        [kernel/dma/direct.h]
                 dma_capable()              Checks addr against DMA mask
                   -> FAILS: addr > 0xFFFFFFFF

KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On systems where the kernel allocates backing pages at physical addresses above 4GB, dma_capable() returns false because the address exceeds the 32-bit mask. The dma_set_mask() function updates *dev->dma_mask to the given value; setting it to DMA_BIT_MASK(64) allows any physical address to pass the check.

Quoted 6 lines

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

A third test in the same suite, drm_gem_shmem_test_obj_create_private, already calls dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64)) before its DMA mapping. This series applies the same fix to the two remaining tests.

Instead of doing whack-a-mole, is it possible to move the existing fix from drm_gem_shmem_test_obj_create_private() to _test_init at [1] ? The DMA mask would then be the same on all tests. [1] https://elixir.bootlin.com/linux/v7.1.2/source/drivers/gpu/drm/tests/drm_gem_shmem_test.c#L359 Best regards Thomas

Quoted 9 lines

José Expósito (2):
drm/tests: shmem: Set DMA mask to 64-bit in
drm_gem_shmem_test_get_pages_sgt
drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

  drivers/gpu/drm/tests/drm_gem_shmem_test.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#4 lore raw

Hi Thomas,

Thanks for your review.

Quoted 34 lines · Thomas Zimmermann

Hi

Am 03.07.26 um 08:34 schrieb José Expósito:

Quoted 31 lines

Two drm_gem_shmem KUnit tests, drm_gem_shmem_test_get_pages_sgt() and drm_gem_shmem_test_purge(), intermittently fail on ppc64le and s390x CI with a DMA address overflow warning followed by -EIO:

DMA addr 0x00000001130b0000+65536 overflow (mask ffffffff, bus limit 0). Expected sgt is not error, but is: -5

Both tests call drm_gem_shmem_get_pages_sgt(), which internally pins backing pages and DMA-maps them via dma_map_sgtable(). The DMA mapping path is:

   drm_gem_shmem_test_purge()
     drm_gem_shmem_get_pages_sgt()
       drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
         dma_map_sgtable()                  [mapping.c]
           __dma_map_sg_attrs()
             dma_direct_map_sg()            [direct.c]
               dma_direct_map_phys()        [kernel/dma/direct.h]
                 dma_capable()              Checks addr against DMA mask
                   -> FAILS: addr > 0xFFFFFFFF

KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On systems where the kernel allocates backing pages at physical addresses above 4GB, dma_capable() returns false because the address exceeds the 32-bit mask. The dma_set_mask() function updates *dev->dma_mask to the given value; setting it to DMA_BIT_MASK(64) allows any physical address to pass the check.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

Quoted 7 lines
Quoted 3 lines

A third test in the same suite, drm_gem_shmem_test_obj_create_private, already calls dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64)) before its DMA mapping. This series applies the same fix to the two remaining tests.

Instead of doing whack-a-mole, is it possible to move the existing fix from drm_gem_shmem_test_obj_create_private() to _test_init at [1] ? The DMA mask
would then be the same on all tests. [1] https://elixir.bootlin.com/linux/v7.1.2/source/drivers/gpu/drm/tests/drm_gem_shmem_test.c#L359

Yes, I think it is possible. However, this is an intermittent failure that I couldn't reproduce locally and I tried to reduce as much as possible the risk of regression limitting the change to the 2 affected tests.

I'm afraid I don't have enough knoledge about GEM's internals to know if moving the fix to the init function could introduce unwanted side-effects in the other tests. If you think it'd be safe, I'll trust you and move it.

Jose

PS - Next week I'll be away from keyboard, so any change would need to wait a bit

Quoted 20 lines

Best regards Thomas

Quoted 9 lines

José Expósito (2):
drm/tests: shmem: Set DMA mask to 64-bit in
drm_gem_shmem_test_get_pages_sgt
drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

  drivers/gpu/drm/tests/drm_gem_shmem_test.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#5 lore raw

Hi José
Am 03.07.26 um 11:00 schrieb José Expósito:

Quoted 45 lines

Hi Thomas,

Thanks for your review.

Quoted 34 lines · Thomas Zimmermann

Hi

Am 03.07.26 um 08:34 schrieb José Expósito:

Quoted 31 lines

Two drm_gem_shmem KUnit tests, drm_gem_shmem_test_get_pages_sgt() and drm_gem_shmem_test_purge(), intermittently fail on ppc64le and s390x CI with a DMA address overflow warning followed by -EIO:

DMA addr 0x00000001130b0000+65536 overflow (mask ffffffff, bus limit 0). Expected sgt is not error, but is: -5

Both tests call drm_gem_shmem_get_pages_sgt(), which internally pins backing pages and DMA-maps them via dma_map_sgtable(). The DMA mapping path is:

    drm_gem_shmem_test_purge()
      drm_gem_shmem_get_pages_sgt()
        drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
          dma_map_sgtable()                  [mapping.c]
            __dma_map_sg_attrs()
              dma_direct_map_sg()            [direct.c]
                dma_direct_map_phys()        [kernel/dma/direct.h]
                  dma_capable()              Checks addr against DMA mask
                    -> FAILS: addr > 0xFFFFFFFF

KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On systems where the kernel allocates backing pages at physical addresses above 4GB, dma_capable() returns false because the address exceeds the 32-bit mask. The dma_set_mask() function updates *dev->dma_mask to the given value; setting it to DMA_BIT_MASK(64) allows any physical address to pass the check.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

Quoted 6 lines
Quoted 3 lines

A third test in the same suite, drm_gem_shmem_test_obj_create_private, already calls dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64)) before its DMA mapping. This series applies the same fix to the two remaining tests.

Instead of doing whack-a-mole, is it possible to move the existing fix from drm_gem_shmem_test_obj_create_private() to _test_init at [1] ? The DMA mask
would then be the same on all tests. [1] https://elixir.bootlin.com/linux/v7.1.2/source/drivers/gpu/drm/tests/drm_gem_shmem_test.c#L359

Quoted 7 lines

Yes, I think it is possible. However, this is an intermittent failure that I couldn't reproduce locally and I tried to reduce as much as possible the risk of regression limitting the change to the 2 affected tests.

I'm afraid I don't have enough knoledge about GEM's internals to know if moving the fix to the init function could introduce unwanted side-effects in the other tests. If you think it'd be safe, I'll trust you and move it.

Please do. I don't see why it should not work, and it's an easy revert it doesn't.

Best regards
Thomas

Quoted 23 lines

Jose

PS - Next week I'll be away from keyboard, so any change would need to wait a bit

Quoted 18 lines

Best regards Thomas

Quoted 8 lines

José Expósito (2):
drm/tests: shmem: Set DMA mask to 64-bit in
drm_gem_shmem_test_get_pages_sgt
drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

   drivers/gpu/drm/tests/drm_gem_shmem_test.c | 9 ++++++++-
   1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#6 lore raw
Quoted 51 lines · Thomas Zimmermann

Hi José
Am 03.07.26 um 11:00 schrieb José Expósito:

Quoted 49 lines

Hi Thomas,

Thanks for your review.

Quoted 34 lines · Thomas Zimmermann

Hi

Am 03.07.26 um 08:34 schrieb José Expósito:

Quoted 31 lines

Two drm_gem_shmem KUnit tests, drm_gem_shmem_test_get_pages_sgt() and drm_gem_shmem_test_purge(), intermittently fail on ppc64le and s390x CI with a DMA address overflow warning followed by -EIO:

DMA addr 0x00000001130b0000+65536 overflow (mask ffffffff, bus limit 0). Expected sgt is not error, but is: -5

Both tests call drm_gem_shmem_get_pages_sgt(), which internally pins backing pages and DMA-maps them via dma_map_sgtable(). The DMA mapping path is:

    drm_gem_shmem_test_purge()
      drm_gem_shmem_get_pages_sgt()
        drm_gem_shmem_get_pages_sgt_locked() [drm_gem_shmem_helper.c]
          dma_map_sgtable()                  [mapping.c]
            __dma_map_sg_attrs()
              dma_direct_map_sg()            [direct.c]
                dma_direct_map_phys()        [kernel/dma/direct.h]
                  dma_capable()              Checks addr against DMA mask
                    -> FAILS: addr > 0xFFFFFFFF

KUnit devices are initialized with a 32-bit DMA mask (DMA_BIT_MASK(32)) in lib/kunit/device.c. On systems where the kernel allocates backing pages at physical addresses above 4GB, dma_capable() returns false because the address exceeds the 32-bit mask. The dma_set_mask() function updates *dev->dma_mask to the given value; setting it to DMA_BIT_MASK(64) allows any physical address to pass the check.

The failure is intermittent because pages may or may not be allocated above 4GB on any given run depend on memory pressure.

Quoted 6 lines
Quoted 3 lines

A third test in the same suite, drm_gem_shmem_test_obj_create_private, already calls dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64)) before its DMA mapping. This series applies the same fix to the two remaining tests.

Instead of doing whack-a-mole, is it possible to move the existing fix from drm_gem_shmem_test_obj_create_private() to _test_init at [1] ? The DMA mask
would then be the same on all tests. [1] https://elixir.bootlin.com/linux/v7.1.2/source/drivers/gpu/drm/tests/drm_gem_shmem_test.c#L359

Yes, I think it is possible. However, this is an intermittent failure that I couldn't reproduce locally and I tried to reduce as much as possible the risk of regression limitting the change to the 2 affected tests.

Quoted 6 lines
Quoted 3 lines

I'm afraid I don't have enough knoledge about GEM's internals to know if moving the fix to the init function could introduce unwanted side-effects in the other tests. If you think it'd be safe, I'll trust you and move it.

Please do. I don't see why it should not work, and it's an easy revert it doesn't.

I just sent v2 with the suggested change. I run the test in several architectures and I didn't run into any issue:

https://lore.kernel.org/dri-devel/[email protected]/

Thanks,
Jose

Quoted 37 lines

Best regards
Thomas

Quoted 23 lines

Jose

PS - Next week I'll be away from keyboard, so any change would need to wait a bit

Quoted 18 lines

Best regards Thomas

Quoted 8 lines

José Expósito (2):
drm/tests: shmem: Set DMA mask to 64-bit in
drm_gem_shmem_test_get_pages_sgt
drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem_test_purge

   drivers/gpu/drm/tests/drm_gem_shmem_test.c | 9 ++++++++-
   1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)