Skip to contentSkip to conversation

drm/selftests/mm: Switch to bitmap_zalloc()

PATCH Superseded Andy Shevchenko 5 participants 8 messages Mar 4, 2019 – Mar 5, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/selftests/mm: Switch to bitmap_zalloc()

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/gpu/drm/selftests/test-drm_mm.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/selftests/test-drm_mm.c +5 -7
index fbed2c90fd51..d1206aef26af 100644
@@ -1615,7 +1615,7 @@ static int igt_topdown(void *ignored)
 	DRM_RND_STATE(prng, random_seed);
 	const unsigned int count = 8192;
 	unsigned int size;
-	unsigned long *bitmap = NULL;
+	unsigned long *bitmap;
 	struct drm_mm mm;
 	struct drm_mm_node *nodes, *node, *next;
 	unsigned int *order, n, m, o = 0;
@@ -1631,8 +1631,7 @@ static int igt_topdown(void *ignored)
 	if (!nodes)
 		goto err;
 
-	bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-			 GFP_KERNEL);
+	bitmap = bitmap_zalloc(count, GFP_KERNEL);
 	if (!bitmap)
 		goto err_nodes;
 
@@ -1717,7 +1716,7 @@ static int igt_topdown(void *ignored)
 	drm_mm_takedown(&mm);
 	kfree(order);
 err_bitmap:
-	kfree(bitmap);
+	bitmap_free(bitmap);
 err_nodes:
 	vfree(nodes);
 err:
@@ -1745,8 +1744,7 @@ static int igt_bottomup(void *ignored)
 	if (!nodes)
 		goto err;
 
-	bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-			 GFP_KERNEL);
+	bitmap = bitmap_zcalloc(count, GFP_KERNEL);
 	if (!bitmap)
 		goto err_nodes;
 
@@ -1818,7 +1816,7 @@ static int igt_bottomup(void *ignored)
 	drm_mm_takedown(&mm);
 	kfree(order);
 err_bitmap:
-	kfree(bitmap);
+	bitmap_free(bitmap);
 err_nodes:
 	vfree(nodes);
 err:
Signature · 6 lines
2.20.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/2 drm: i915: Switch to bitmap_zalloc()

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/gpu/drm/i915/i915_gem.c               | 2 +-
 drivers/gpu/drm/i915/i915_gem_fence_reg.c     | 3 +--
 drivers/gpu/drm/i915/i915_gem_tiling.c        | 6 +++---
 drivers/gpu/drm/i915/selftests/intel_uncore.c | 5 ++---
 4 files changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +1 -1
index 6728ea5c71d4..0d96520cfdb3 100644
@@ -4410,7 +4410,7 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
 		drm_gem_object_release(&obj->base);
 		i915_gem_info_remove_obj(i915, obj->base.size);
 
-		kfree(obj->bit_17);
+		bitmap_free(obj->bit_17);
 		i915_gem_object_free(obj);
 
 		GEM_BUG_ON(!atomic_read(&i915->mm.free_count));
drivers/gpu/drm/i915/i915_gem_fence_reg.c +1 -2
index e037e94792f3..1f880e5b79b0 100644
@@ -790,8 +790,7 @@ i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
 	int i;
 
 	if (obj->bit_17 == NULL) {
-		obj->bit_17 = kcalloc(BITS_TO_LONGS(page_count),
-				      sizeof(long), GFP_KERNEL);
+		obj->bit_17 = bitmap_zalloc(page_count, GFP_KERNEL);
 		if (obj->bit_17 == NULL) {
 			DRM_ERROR("Failed to allocate memory for bit 17 "
 				  "record\n");
drivers/gpu/drm/i915/i915_gem_tiling.c +3 -3
index 16cc9ddbce34..a9b5329dae3b 100644
@@ -301,11 +301,11 @@ i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,
 	/* Try to preallocate memory required to save swizzling on put-pages */
 	if (i915_gem_object_needs_bit17_swizzle(obj)) {
 		if (!obj->bit_17) {
-			obj->bit_17 = kcalloc(BITS_TO_LONGS(obj->base.size >> PAGE_SHIFT),
-					      sizeof(long), GFP_KERNEL);
+			obj->bit_17 = bitmap_zalloc(obj->base.size >> PAGE_SHIFT,
+						    GFP_KERNEL);
 		}
 	} else {
-		kfree(obj->bit_17);
+		bitmap_free(obj->bit_17);
 		obj->bit_17 = NULL;
 	}
 
drivers/gpu/drm/i915/selftests/intel_uncore.c +2 -3
index 81d9d31042a9..600167ebb303 100644
@@ -137,8 +137,7 @@ static int intel_uncore_check_forcewake_domains(struct drm_i915_private *dev_pri
 	if (!IS_ENABLED(CONFIG_DRM_I915_SELFTEST_BROKEN))
 		return 0;
 
-	valid = kcalloc(BITS_TO_LONGS(FW_RANGE), sizeof(*valid),
-			GFP_KERNEL);
+	valid = bitmap_zalloc(FW_RANGE, GFP_KERNEL);
 	if (!valid)
 		return -ENOMEM;
 
@@ -173,7 +172,7 @@ static int intel_uncore_check_forcewake_domains(struct drm_i915_private *dev_pri
 		}
 	}
 
-	kfree(valid);
+	bitmap_free(valid);
 	return err;
 }
 
Signature · 6 lines
2.20.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

✗ Fi.CI.BAT: failure for series starting with [v1,1/2] drm/selftests/mm: Switch to bitmap_zalloc()

In reply to Andy Shevchenko
== Series Details ==

== Series Details ==

Series: series starting with [v1,1/2] drm/selftests/mm: Switch to bitmap_zalloc()
URL : https://patchwork.freedesktop.org/series/57506/
State : failure

== Summary ==

CALL scripts/checksyscalls.sh
DESCEND objtool
CHK include/generated/compile.h
CC [M] drivers/gpu/drm/selftests/test-drm_mm.o
drivers/gpu/drm/selftests/test-drm_mm.c: In function ‘igt_bottomup’:
drivers/gpu/drm/selftests/test-drm_mm.c:1747:11: error: implicit declaration of function ‘bitmap_zcalloc’; did you mean ‘bitmap_zalloc’? [-Werror=implicit-function-declaration]

  bitmap = bitmap_zcalloc(count, GFP_KERNEL);
           ^~~~~~~~~~~~~~
           bitmap_zalloc
drivers/gpu/drm/selftests/test-drm_mm.c:1747:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  bitmap = bitmap_zcalloc(count, GFP_KERNEL);
         ^

cc1: some warnings being treated as errors
scripts/Makefile.build:282: recipe for target 'drivers/gpu/drm/selftests/test-drm_mm.o' failed make[4]: *** [drivers/gpu/drm/selftests/test-drm_mm.o] Error 1 scripts/Makefile.build:492: recipe for target 'drivers/gpu/drm/selftests' failed make[3]: *** [drivers/gpu/drm/selftests] Error 2
scripts/Makefile.build:492: recipe for target 'drivers/gpu/drm' failed
make[2]: *** [drivers/gpu/drm] Error 2
scripts/Makefile.build:492: recipe for target 'drivers/gpu' failed
make[1]: *** [drivers/gpu] Error 2
Makefile:1043: recipe for target 'drivers' failed
make: *** [drivers] Error 2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Andy Shevchenko
I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.0 next-20190301]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/drm-selftests-mm-Switch-to-bitmap_zalloc/20190304-183335
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: nds32-allyesconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 6.4.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=6.4.0 make.cross ARCH=nds32

All error/warnings (new ones prefixed by >>):

drivers/gpu/drm/selftests/test-drm_mm.c: In function 'igt_bottomup':

>> drivers/gpu/drm/selftests/test-drm_mm.c:1747:11: error: implicit declaration of function 'bitmap_zcalloc' [-Werror=implicit-function-declaration]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
              ^~~~~~~~~~~~~~
>> drivers/gpu/drm/selftests/test-drm_mm.c:1747:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
            ^

cc1: some warnings being treated as errors

vim +/bitmap_zcalloc +1747 drivers/gpu/drm/selftests/test-drm_mm.c

1725
1726 static int igt_bottomup(void *ignored)
1727 {
1728 const struct insert_mode *bottomup = &insert_modes[BOTTOMUP];
1729 DRM_RND_STATE(prng, random_seed);
1730 const unsigned int count = 8192;
1731 unsigned int size;
1732 unsigned long *bitmap;
1733 struct drm_mm mm;
1734 struct drm_mm_node *nodes, *node, *next;
1735 unsigned int *order, n, m, o = 0;
1736 int ret;
1737
1738 /* Like igt_topdown, but instead of searching for the last hole,
1739 * we search for the first.
1740 */
1741
1742 ret = -ENOMEM;
1743 nodes = vzalloc(array_size(count, sizeof(*nodes)));
1744 if (!nodes)
1745 goto err;
1746

> 1747		bitmap = bitmap_zcalloc(count, GFP_KERNEL);

1748 if (!bitmap)
1749 goto err_nodes;
1750
1751 order = drm_random_order(count, &prng);
1752 if (!order)
1753 goto err_bitmap;
1754
1755 ret = -EINVAL;
1756 for (size = 1; size <= 64; size <<= 1) {
1757 drm_mm_init(&mm, 0, size*count);
1758 for (n = 0; n < count; n++) {
1759 if (!expect_insert(&mm, &nodes[n],
1760 size, 0, n,
1761 bottomup)) {
1762 pr_err("bottomup insert failed, size %u step %d\n", size, n);
1763 goto out;
1764 }
1765
1766 if (!assert_one_hole(&mm, size*(n + 1), size*count))
1767 goto out;
1768 }
1769
1770 if (!assert_continuous(&mm, size))
1771 goto out;
1772
1773 drm_random_reorder(order, count, &prng);
1774 for_each_prime_number_from(n, 1, min(count, max_prime)) {
1775 for (m = 0; m < n; m++) {
1776 node = &nodes[order[(o + m) % count]];
1777 drm_mm_remove_node(node);
1778 __set_bit(node_index(node), bitmap);
1779 }
1780
1781 for (m = 0; m < n; m++) {
1782 unsigned int first;
1783
1784 node = &nodes[order[(o + m) % count]];
1785 if (!expect_insert(&mm, node,
1786 size, 0, 0,
1787 bottomup)) {
1788 pr_err("insert failed, step %d/%d\n", m, n);
1789 goto out;
1790 }
1791
1792 first = find_first_bit(bitmap, count);
1793 if (node_index(node) != first) {
1794 pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n",
1795 m, n, first, node_index(node));
1796 goto out;
1797 }
1798 __clear_bit(first, bitmap);
1799 }
1800
1801 DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count);
1802
1803 o += n;
1804 }
1805
1806 drm_mm_for_each_node_safe(node, next, &mm)
1807 drm_mm_remove_node(node);
1808 DRM_MM_BUG_ON(!drm_mm_clean(&mm));
1809 cond_resched();
1810 }
1811
1812 ret = 0;
1813 out:
1814 drm_mm_for_each_node_safe(node, next, &mm)
1815 drm_mm_remove_node(node);
1816 drm_mm_takedown(&mm);
1817 kfree(order);
1818 err_bitmap:
1819 bitmap_free(bitmap);
1820 err_nodes:
1821 vfree(nodes);
1822 err:
1823 return ret;
1824 }
1825

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
In reply to Andy Shevchenko
I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.0 next-20190301]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/drm-selftests-mm-Switch-to-bitmap_zalloc/20190304-183335
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.2.0 make.cross ARCH=xtensa

All error/warnings (new ones prefixed by >>):

drivers/gpu//drm/selftests/test-drm_mm.c: In function 'igt_bottomup':

>> drivers/gpu//drm/selftests/test-drm_mm.c:1747:11: error: implicit declaration of function 'bitmap_zcalloc'; did you mean 'bitmap_zalloc'? [-Werror=implicit-function-declaration]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
              ^~~~~~~~~~~~~~
              bitmap_zalloc
>> drivers/gpu//drm/selftests/test-drm_mm.c:1747:9: warning: assignment to 'long unsigned int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
            ^

cc1: some warnings being treated as errors

vim +1747 drivers/gpu//drm/selftests/test-drm_mm.c

1725
1726 static int igt_bottomup(void *ignored)
1727 {
1728 const struct insert_mode *bottomup = &insert_modes[BOTTOMUP];
1729 DRM_RND_STATE(prng, random_seed);
1730 const unsigned int count = 8192;
1731 unsigned int size;
1732 unsigned long *bitmap;
1733 struct drm_mm mm;
1734 struct drm_mm_node *nodes, *node, *next;
1735 unsigned int *order, n, m, o = 0;
1736 int ret;
1737
1738 /* Like igt_topdown, but instead of searching for the last hole,
1739 * we search for the first.
1740 */
1741
1742 ret = -ENOMEM;
1743 nodes = vzalloc(array_size(count, sizeof(*nodes)));
1744 if (!nodes)
1745 goto err;
1746

> 1747		bitmap = bitmap_zcalloc(count, GFP_KERNEL);

1748 if (!bitmap)
1749 goto err_nodes;
1750
1751 order = drm_random_order(count, &prng);
1752 if (!order)
1753 goto err_bitmap;
1754
1755 ret = -EINVAL;
1756 for (size = 1; size <= 64; size <<= 1) {
1757 drm_mm_init(&mm, 0, size*count);
1758 for (n = 0; n < count; n++) {
1759 if (!expect_insert(&mm, &nodes[n],
1760 size, 0, n,
1761 bottomup)) {
1762 pr_err("bottomup insert failed, size %u step %d\n", size, n);
1763 goto out;
1764 }
1765
1766 if (!assert_one_hole(&mm, size*(n + 1), size*count))
1767 goto out;
1768 }
1769
1770 if (!assert_continuous(&mm, size))
1771 goto out;
1772
1773 drm_random_reorder(order, count, &prng);
1774 for_each_prime_number_from(n, 1, min(count, max_prime)) {
1775 for (m = 0; m < n; m++) {
1776 node = &nodes[order[(o + m) % count]];
1777 drm_mm_remove_node(node);
1778 __set_bit(node_index(node), bitmap);
1779 }
1780
1781 for (m = 0; m < n; m++) {
1782 unsigned int first;
1783
1784 node = &nodes[order[(o + m) % count]];
1785 if (!expect_insert(&mm, node,
1786 size, 0, 0,
1787 bottomup)) {
1788 pr_err("insert failed, step %d/%d\n", m, n);
1789 goto out;
1790 }
1791
1792 first = find_first_bit(bitmap, count);
1793 if (node_index(node) != first) {
1794 pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n",
1795 m, n, first, node_index(node));
1796 goto out;
1797 }
1798 __clear_bit(first, bitmap);
1799 }
1800
1801 DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count);
1802
1803 o += n;
1804 }
1805
1806 drm_mm_for_each_node_safe(node, next, &mm)
1807 drm_mm_remove_node(node);
1808 DRM_MM_BUG_ON(!drm_mm_clean(&mm));
1809 cond_resched();
1810 }
1811
1812 ret = 0;
1813 out:
1814 drm_mm_for_each_node_safe(node, next, &mm)
1815 drm_mm_remove_node(node);
1816 drm_mm_takedown(&mm);
1817 kfree(order);
1818 err_bitmap:
1819 bitmap_free(bitmap);
1820 err_nodes:
1821 vfree(nodes);
1822 err:
1823 return ret;
1824 }
1825

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

maintainer
#5 lore raw
In reply to Andy Shevchenko

I take it that both instances are supposed to call bitmap_zalloc?

If you can send a v2 that compiles, I can merge it after it passes the CI.

Regards, Joonas

Quoting Andy Shevchenko (2019-03-04 11:03:20)

Quoted 62 lines

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 drivers/gpu/drm/selftests/test-drm_mm.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/selftests/test-drm_mm.c +5 -7
index fbed2c90fd51..d1206aef26af 100644
@@ -1615,7 +1615,7 @@ static int igt_topdown(void *ignored)
        DRM_RND_STATE(prng, random_seed);
        const unsigned int count = 8192;
        unsigned int size;
-       unsigned long *bitmap = NULL;
+       unsigned long *bitmap;
        struct drm_mm mm;
        struct drm_mm_node *nodes, *node, *next;
        unsigned int *order, n, m, o = 0;
@@ -1631,8 +1631,7 @@ static int igt_topdown(void *ignored)
        if (!nodes)
                goto err;
 
-       bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-                        GFP_KERNEL);
+       bitmap = bitmap_zalloc(count, GFP_KERNEL);
        if (!bitmap)
                goto err_nodes;
 
@@ -1717,7 +1716,7 @@ static int igt_topdown(void *ignored)
        drm_mm_takedown(&mm);
        kfree(order);
 err_bitmap:
-       kfree(bitmap);
+       bitmap_free(bitmap);
 err_nodes:
        vfree(nodes);
 err:
@@ -1745,8 +1744,7 @@ static int igt_bottomup(void *ignored)
        if (!nodes)
                goto err;
 
-       bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-                        GFP_KERNEL);
+       bitmap = bitmap_zcalloc(count, GFP_KERNEL);
        if (!bitmap)
                goto err_nodes;
 
@@ -1818,7 +1816,7 @@ static int igt_bottomup(void *ignored)
        drm_mm_takedown(&mm);
        kfree(order);
 err_bitmap:
-       kfree(bitmap);
+       bitmap_free(bitmap);
 err_nodes:
        vfree(nodes);
 err:
Signature · 1 line
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 4 lines · Joonas Lahtinen

I take it that both instances are supposed to call bitmap_zalloc?

If you can send a v2 that compiles, I can merge it after it passes the CI.

v2 had been sent yesterday.

Signature · 8 lines
With Best Regards,
Andy Shevchenko


_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Quoting Andy Shevchenko (2019-03-05 10:20:31)

Quoted 7 lines · Joonas Lahtinen
Quoted 4 lines

I take it that both instances are supposed to call bitmap_zalloc?

If you can send a v2 that compiles, I can merge it after it passes the CI.

v2 had been sent yesterday.

https://patchwork.freedesktop.org/series/57507/
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx