Skip to contentSkip to conversation

drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem

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

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem

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

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

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_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() for all tests, 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
[2] 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

---

v2:

- Move fix to drm_gem_shmem_test_init() (Thomas Zimmermann)
- Link to v1: https://lore.kernel.org/dri-devel/[email protected]/

---
 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/tests/drm_gem_shmem_test.c +9 -8
index 44a190109249..6e6b4f4902c2 100644
@@ -94,14 +94,6 @@ static void drm_gem_shmem_test_obj_create_private(struct kunit *test)
 
 	sg_init_one(sgt->sgl, buf, TEST_SIZE);
 
-	/*
-	 * Set the DMA mask to 64-bits and map the sgtables
-	 * otherwise drm_gem_shmem_free will cause a warning
-	 * on debug kernels.
-	 */
-	ret = dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64));
-	KUNIT_ASSERT_EQ(test, ret, 0);
-
 	ret = dma_map_sgtable(drm_dev->dev, sgt, DMA_BIDIRECTIONAL, 0);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
@@ -352,11 +344,20 @@ static int drm_gem_shmem_test_init(struct kunit *test)
 {
 	struct device *dev;
 	struct drm_device *drm_dev;
+	int ret;
 
 	/* Allocate a parent device */
 	dev = drm_kunit_helper_alloc_device(test);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
+	/*
+	 * Set the DMA mask to 64-bits and map the sgtables
+	 * otherwise drm_gem_shmem_free will cause a warning
+	 * on debug kernels.
+	 */
+	ret = dma_set_mask(dev, DMA_BIT_MASK(64));
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	/*
 	 * The DRM core will automatically initialize the GEM core and create
 	 * a DRM Memory Manager object which provides an address space pool
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] A moved comment describes operations that are not performed in its new location. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] A moved comment describes operations that are not performed in its new location. --

Note: The format of this report has been altered to provide a free-form summary without direct code quotes due to recitation restrictions.

commit 80b1922edca70f8edc78748fddf0120eb2612fec
Author: José Expósito <[email protected]>
Subject: drm/tests: shmem: Set DMA mask to 64-bit in drm_gem_shmem

This commit fixes intermittent DMA address overflow failures on ppc64le and s390x CI systems during drm_gem_shmem tests. It does this by moving the configuration of the 64-bit DMA mask into the test initialization phase, ensuring it applies to all tests rather than just one.

In drivers/gpu/drm/tests/drm_gem_shmem_test.c:

[Severity: Low]
This isn't a bug, but does the moved comment in drm_gem_shmem_test_init need to be updated?

The patch moves a block comment alongside the dma_set_mask call into the test initialization function. This comment explicitly states "and map the sgtables otherwise drm_gem_shmem_free will cause a warning".

However, the actual dma_map_sgtable call was not moved and remains in the original function. Leaving this text in the new location is slightly misleading, as it implies the sgtables are being mapped during device init.

Could we update the comment to remove the reference to mapping the sgtables?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to José Expósito

Am 03.07.26 um 16:27 schrieb José Expósito:

Quoted 86 lines

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

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

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_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() for all tests, 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
[2] 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

---

v2:

- Move fix to drm_gem_shmem_test_init() (Thomas Zimmermann)
- Link to v1: https://lore.kernel.org/dri-devel/[email protected]/

---
  drivers/gpu/drm/tests/drm_gem_shmem_test.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/tests/drm_gem_shmem_test.c +1 -8
index 44a190109249..6e6b4f4902c2 100644
@@ -94,14 +94,6 @@ static void drm_gem_shmem_test_obj_create_private(struct kunit *test)
 
  	sg_init_one(sgt->sgl, buf, TEST_SIZE);
 
-	/*
-	 * Set the DMA mask to 64-bits and map the sgtables
-	 * otherwise drm_gem_shmem_free will cause a warning
-	 * on debug kernels.
-	 */
-	ret = dma_set_mask(drm_dev->dev, DMA_BIT_MASK(64));
-	KUNIT_ASSERT_EQ(test, ret, 0);
-
  	ret = dma_map_sgtable(drm_dev->dev, sgt, DMA_BIDIRECTIONAL, 0);
  	KUNIT_ASSERT_EQ(test, ret, 0);
 
@@ -352,11 +344,20 @@ static int drm_gem_shmem_test_init(struct kunit *test)
  {
  	struct device *dev;
  	struct drm_device *drm_dev;
+	int ret;
 
  	/* Allocate a parent device */
  	dev = drm_kunit_helper_alloc_device(test);

drivers/gpu/drm/tests/drm_gem_shmem_test.c static int drm_gem_shmem_test_init(struct kunit *test) · line 360

Quoted 10 lines
drivers/gpu/drm/tests/drm_gem_shmem_test.c +8 -0
  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
+	/*
+	 * Set the DMA mask to 64-bits and map the sgtables
+	 * otherwise drm_gem_shmem_free will cause a warning
+	 * on debug kernels.
+	 */
+	ret = dma_set_mask(dev, DMA_BIT_MASK(64));
+	KUNIT_ASSERT_EQ(test, ret, 0);
+

The comment sounds a bit off, but still

Quoted 3 lines
drivers/gpu/drm/tests/drm_gem_shmem_test.c +0 -0
  	/*
  	 * The DRM core will automatically initialize the GEM core and create
  	 * a DRM Memory Manager object which provides an address space pool
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)