Skip to contentSkip to conversation

coresight: catu: Fix number of pages while using 64k pages

PATCH Applied Ilkka Koskinen 2 participants 6 messages Jan 9, 2025 – Feb 21, 2025

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

PATCH 1/1 coresight: catu: Fix number of pages while using 64k pages

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k --per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)
---
 drivers/hwtracing/coresight/coresight-catu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -1
index 275cc0d9f505..3378bb77e6b4 100644
@@ -269,7 +269,7 @@ catu_init_sg_table(struct device *catu_dev, int node,
 	 * Each table can address upto 1MB and we can have
 	 * CATU_PAGES_PER_SYSPAGE tables in a system page.
 	 */
-	nr_tpages = DIV_ROUND_UP(size, SZ_1M) / CATU_PAGES_PER_SYSPAGE;
+	nr_tpages = DIV_ROUND_UP(size, CATU_PAGES_PER_SYSPAGE * SZ_1M);
 	catu_table = tmc_alloc_sg_table(catu_dev, node, nr_tpages,
 					size >> PAGE_SHIFT, pages);
 	if (IS_ERR(catu_table))
Signature · 1 line
2.47.0
maintainer
#1 lore raw
Quoted 7 lines · Ilkka Koskinen

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k --per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)

Needs a Fixes tag.

Fixes 8ed536b1e283 ("coresight: catu: Add support for scatter gather tables")
Quoted 10 lines
---
  drivers/hwtracing/coresight/coresight-catu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-catu.c +0 -0
index 275cc0d9f505..3378bb77e6b4 100644

drivers/hwtracing/coresight/coresight-catu.c catu_init_sg_table(struct device *catu_dev, int node, · line 275

Quoted 8 lines
drivers/hwtracing/coresight/coresight-catu.c +1 -1
@@ -269,7 +269,7 @@ catu_init_sg_table(struct device *catu_dev, int node,
  	 * Each table can address upto 1MB and we can have
  	 * CATU_PAGES_PER_SYSPAGE tables in a system page.
  	 */
-	nr_tpages = DIV_ROUND_UP(size, SZ_1M) / CATU_PAGES_PER_SYSPAGE;
+	nr_tpages = DIV_ROUND_UP(size, CATU_PAGES_PER_SYSPAGE * SZ_1M);
  	catu_table = tmc_alloc_sg_table(catu_dev, node, nr_tpages,
  					size >> PAGE_SHIFT, pages);
  	if (IS_ERR(catu_table))

Looks good to me, I will queue this later for v6.15.

Suzuki

#2 lore raw

Hi Suzuko,

Quoted 5 lines · Suzuki K Poulose
Quoted 4 lines · Ilkka Koskinen

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

Quoted 8 lines
Quoted 4 lines
$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k 
--per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)

Needs a Fixes tag.

Fixes 8ed536b1e283 ("coresight: catu: Add support for scatter gather tables")

That's a good point

Quoted 22 lines
Quoted 11 lines
---
  drivers/hwtracing/coresight/coresight-catu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-catu.c +0 -0
index 275cc0d9f505..3378bb77e6b4 100644

drivers/hwtracing/coresight/coresight-catu.c catu_init_sg_table(struct device *catu_dev, int node, · line 275

Quoted 8 lines
drivers/hwtracing/coresight/coresight-catu.c +1 -1
@@ -269,7 +269,7 @@ catu_init_sg_table(struct device *catu_dev, int node,
  	 * Each table can address upto 1MB and we can have
  	 * CATU_PAGES_PER_SYSPAGE tables in a system page.
  	 */
-	nr_tpages = DIV_ROUND_UP(size, SZ_1M) / CATU_PAGES_PER_SYSPAGE;
+	nr_tpages = DIV_ROUND_UP(size, CATU_PAGES_PER_SYSPAGE * SZ_1M);
  	catu_table = tmc_alloc_sg_table(catu_dev, node, nr_tpages,
  					size >> PAGE_SHIFT, pages);
  	if (IS_ERR(catu_table))

Looks good to me, I will queue this later for v6.15.

Quoted 1 line

Suzuki

Sounds great. Just to confirm, are you ok to add the fixes line or would you prefer me to submit v2 with it?

Cheers, Ilkka

maintainer
#3 lore raw
Quoted 43 lines · Ilkka Koskinen

Hi Suzuko,

Quoted 5 lines · Suzuki K Poulose
Quoted 4 lines · Ilkka Koskinen

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

Quoted 8 lines
Quoted 4 lines
$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k 
--per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)

Needs a Fixes tag.

Fixes 8ed536b1e283 ("coresight: catu: Add support for scatter gather tables")

That's a good point

Quoted 23 lines
Quoted 19 lines

---
  drivers/hwtracing/coresight/coresight-catu.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -1
index 275cc0d9f505..3378bb77e6b4 100644
@@ -269,7 +269,7 @@ catu_init_sg_table(struct device *catu_dev, int 
 node,
        * Each table can address upto 1MB and we can have
        * CATU_PAGES_PER_SYSPAGE tables in a system page.
        */
-    nr_tpages = DIV_ROUND_UP(size, SZ_1M) / CATU_PAGES_PER_SYSPAGE;
+    nr_tpages = DIV_ROUND_UP(size, CATU_PAGES_PER_SYSPAGE * SZ_1M);
       catu_table = tmc_alloc_sg_table(catu_dev, node, nr_tpages,
                       size >> PAGE_SHIFT, pages);
Quoted 1 line

      if (IS_ERR(catu_table))

Looks good to me, I will queue this later for v6.15.

Quoted 3 lines
Quoted 1 line

Suzuki

Sounds great. Just to confirm, are you ok to add the fixes line or would you prefer me to submit v2 with it?

No, not required. I have picked this up for v6.15, and will push it out once v6.14-rc is out.

Suzuki

Quoted 2 lines

Cheers, Ilkka

#4 lore raw
Quoted 43 lines · Suzuki K Poulose
Quoted 42 lines · Ilkka Koskinen

Hi Suzuko,

Quoted 5 lines · Suzuki K Poulose
Quoted 4 lines · Ilkka Koskinen

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

Quoted 8 lines
Quoted 4 lines
$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k 
--per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)

Needs a Fixes tag.

Fixes 8ed536b1e283 ("coresight: catu: Add support for scatter gather tables")

That's a good point

Quoted 22 lines
Quoted 11 lines

---
  drivers/hwtracing/coresight/coresight-catu.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-catu.c +0 -0
index 275cc0d9f505..3378bb77e6b4 100644

drivers/hwtracing/coresight/coresight-catu.c catu_init_sg_table(struct device *catu_dev, int node, · line 275

Quoted 8 lines
drivers/hwtracing/coresight/coresight-catu.c +1 -1
@@ -269,7 +269,7 @@ catu_init_sg_table(struct device *catu_dev, int node,
        * Each table can address upto 1MB and we can have
        * CATU_PAGES_PER_SYSPAGE tables in a system page.
        */
-    nr_tpages = DIV_ROUND_UP(size, SZ_1M) / CATU_PAGES_PER_SYSPAGE;
+    nr_tpages = DIV_ROUND_UP(size, CATU_PAGES_PER_SYSPAGE * SZ_1M);
       catu_table = tmc_alloc_sg_table(catu_dev, node, nr_tpages,
                       size >> PAGE_SHIFT, pages);
       if (IS_ERR(catu_table))

Looks good to me, I will queue this later for v6.15.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Suzuki

Sounds great. Just to confirm, are you ok to add the fixes line or would you prefer me to submit v2 with it?

No, not required. I have picked this up for v6.15, and will push it out once v6.14-rc is out.

Perfect, thanks!

--Ilkka

maintainer Applied
#5 lore raw
In reply to Ilkka Koskinen
Quoted 8 lines · Ilkka Koskinen

Trying to record a trace on kernel with 64k pages resulted in -ENOMEM. This happens due to a bug in calculating the number of table pages, which returns zero. Fix the issue by rounding up.

$ perf record --kcore -e cs_etm/@tmc_etr55,cycacc,branch_broadcast/k --per-thread taskset --cpu-list 1 dd if=/dev/zero of=/dev/null
failed to mmap with 12 (Cannot allocate memory)

[...]

Applied, thanks!

[1/1] coresight: catu: Fix number of pages while using 64k pages

      https://git.kernel.org/coresight/c/0e14e062f5ff

Best regards,

Signature · 1 line
Suzuki K Poulose <[email protected]>