Skip to contentSkip to conversation

mm/damon/sysfs: add __counted_by() annotation

RFC PATCH In review SeongJae Park 2 participants 3 messages Aug 25, 2023 – Aug 26, 2023

Subsystems (2)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

RFC PATCH 1/1 mm/damon/sysfs: add __counted_by() annotation

Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro") added __counted_by() annotation. The underlying attribute for the feature is still under development, but adopting it can improve the readability of the code. Apply it to four dynamic arrays in DAMON sysfs code.

---
 mm/damon/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/sysfs.c +4 -4
index 808a8efe0523..36a176f38726 100644
@@ -93,7 +93,7 @@ static const struct kobj_type damon_sysfs_region_ktype = {
 
 struct damon_sysfs_regions {
 	struct kobject kobj;
-	struct damon_sysfs_region **regions_arr;
+	struct damon_sysfs_region **regions_arr __counted_by(nr);
 	int nr;
 };
 
@@ -289,7 +289,7 @@ static const struct kobj_type damon_sysfs_target_ktype = {
 
 struct damon_sysfs_targets {
 	struct kobject kobj;
-	struct damon_sysfs_target **targets_arr;
+	struct damon_sysfs_target **targets_arr __counted_by(nr);
 	int nr;
 };
 
@@ -812,7 +812,7 @@ static const struct kobj_type damon_sysfs_context_ktype = {
 
 struct damon_sysfs_contexts {
 	struct kobject kobj;
-	struct damon_sysfs_context **contexts_arr;
+	struct damon_sysfs_context **contexts_arr __counted_by(nr);
 	int nr;
 };
 
@@ -1590,7 +1590,7 @@ static const struct kobj_type damon_sysfs_kdamond_ktype = {
 
 struct damon_sysfs_kdamonds {
 	struct kobject kobj;
-	struct damon_sysfs_kdamond **kdamonds_arr;
+	struct damon_sysfs_kdamond **kdamonds_arr __counted_by(nr);
 	int nr;
 };
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 16 lines · SeongJae Park

Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro") added __counted_by() annotation. The underlying attribute for the feature is still under development, but adopting it can improve the readability of the code. Apply it to four dynamic arrays in DAMON sysfs code.

---
 mm/damon/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/sysfs.c +0 -0
index 808a8efe0523..36a176f38726 100644

mm/damon/sysfs.c static const struct kobj_type damon_sysfs_region_ktype = { · line 98

Quoted 7 lines
mm/damon/sysfs.c +1 -1
@@ -93,7 +93,7 @@ static const struct kobj_type damon_sysfs_region_ktype = {
 
 struct damon_sysfs_regions {
 	struct kobject kobj;
-	struct damon_sysfs_region **regions_arr;
+	struct damon_sysfs_region **regions_arr __counted_by(nr);
 	int nr;
 };

Unfortunately this isn't supported yet for non-flexible-array-members:

mm/damon/sysfs.c:96:14: error: 'counted_by' attribute may not be specified for a non-array field
96 | struct damon_sysfs_region **regions_arr __counted_by(nr);
| ^~~~~

We'll have to wait a bit before we can add this patch. Thank you for getting it ready, though! This support is next in line. :)

The FAM support is likely ready to land, though[1]. I just tested it today.

-Kees

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html

Signature · 1 line
Kees Cook
author maintainer
#2 lore raw

Hi Kees,

Quoted 27 lines · On Fri, 25 Aug 2023 14:32:34 -0700 Kees Cook <[email protected]> wrote:
Quoted 16 lines · SeongJae Park

Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro") added __counted_by() annotation. The underlying attribute for the feature is still under development, but adopting it can improve the readability of the code. Apply it to four dynamic arrays in DAMON sysfs code.

---
 mm/damon/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/sysfs.c +0 -0
index 808a8efe0523..36a176f38726 100644

mm/damon/sysfs.c static const struct kobj_type damon_sysfs_region_ktype = { · line 98

Quoted 7 lines
mm/damon/sysfs.c +1 -1
@@ -93,7 +93,7 @@ static const struct kobj_type damon_sysfs_region_ktype = {
 
 struct damon_sysfs_regions {
 	struct kobject kobj;
-	struct damon_sysfs_region **regions_arr;
+	struct damon_sysfs_region **regions_arr __counted_by(nr);
 	int nr;
 };

Unfortunately this isn't supported yet for non-flexible-array-members:

Quoted 5 lines

mm/damon/sysfs.c:96:14: error: 'counted_by' attribute may not be specified for a non-array field
96 | struct damon_sysfs_region **regions_arr __counted_by(nr);
| ^~~~~

We'll have to wait a bit before we can add this patch.

Thank you for checking this and let me know. Ok, I will wait.

Quoted 2 lines

Thank you for
getting it ready, though!

Owing to your previous contributions. Thank you for helping me make DAMON code better to read :)

Quoted 12 lines

This support is next in line. :)

The FAM support is likely ready to land, though[1]. I just tested it today.

-Kees

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html

Signature · 1 line
Kees Cook

Thanks,
SJ