Skip to contentSkip to conversation

tracing/cfi: Fix cmp_entries_* functions signature mismatch

PATCH Superseded Kalesh Singh 3 participants 6 messages Sep 23, 2021 – Oct 14, 2021 Tracing

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing/cfi: Fix cmp_entries_* functions signature mismatch

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check.

1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger
2. cat >> events/sched/sched_switch/hist
3. kernel panices on attempting to read hist

This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this.

---
 kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
kernel/trace/tracing_map.c +23 -17
index d6bddb157ef2..a8c80ebbf9da 100644
@@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map)
 	return err;
 }
 
-static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_dup(const void *__a, const void *__b)
 {
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;
 
-	if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
+	if (memcmp(a->key, b->key, a->elt->map->key_size))
 		ret = 1;
 
 	return ret;
 }
 
-static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_sum(const void *__a, const void *__b)
 {
 	const struct tracing_map_elt *elt_a, *elt_b;
 	struct tracing_map_sort_key *sort_key;
@@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
 	tracing_map_cmp_fn_t cmp_fn;
 	void *val_a, *val_b;
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;
 
-	elt_a = (*a)->elt;
-	elt_b = (*b)->elt;
+	elt_a = a->elt;
+	elt_b = b->elt;
 
 	sort_key = &elt_a->map->sort_key;
 
@@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
 	return ret;
 }
 
-static int cmp_entries_key(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_key(const void *__a, const void *__b)
 {
 	const struct tracing_map_elt *elt_a, *elt_b;
 	struct tracing_map_sort_key *sort_key;
@@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a,
 	tracing_map_cmp_fn_t cmp_fn;
 	void *val_a, *val_b;
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;
 
-	elt_a = (*a)->elt;
-	elt_b = (*b)->elt;
+	elt_a = a->elt;
+	elt_b = b->elt;
 
 	sort_key = &elt_a->map->sort_key;
 
@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
 			   struct tracing_map_sort_key *primary_key,
 			   struct tracing_map_sort_key *secondary_key)
 {
-	int (*primary_fn)(const struct tracing_map_sort_entry **,
-			  const struct tracing_map_sort_entry **);
-	int (*secondary_fn)(const struct tracing_map_sort_entry **,
-			    const struct tracing_map_sort_entry **);
+	int (*primary_fn)(const void *, const void *);
+	int (*secondary_fn)(const void *, const void *);
 	unsigned i, start = 0, n_sub = 1;
 
 	if (is_key(map, primary_key->field_idx))
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
 			     unsigned int n_sort_keys,
 			     struct tracing_map_sort_entry ***sort_entries)
 {
-	int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
-			      const struct tracing_map_sort_entry **);
+	int (*cmp_entries_fn)(const void *, const void *);
 	struct tracing_map_sort_entry *sort_entry, **entries;
 	int i, n_entries, ret;
 

base-commit: 58e2cf5d794616b84f591d4d1276c8953278ce24

Signature · 1 line
2.33.0.685.g46640cef36-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi Kalesh,

Quoted 106 lines · Kalesh Singh

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check.

1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger
2. cat >> events/sched/sched_switch/hist
3. kernel panices on attempting to read hist

This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this.

---
 kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
kernel/trace/tracing_map.c +22 -15
index d6bddb157ef2..a8c80ebbf9da 100644
@@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map)
        return err;
 }
 
-static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_dup(const void *__a, const void *__b)
 {
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
+       if (memcmp(a->key, b->key, a->elt->map->key_size))
                ret = 1;
 
        return ret;
 }
 
-static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_sum(const void *__a, const void *__b)
 {
        const struct tracing_map_elt *elt_a, *elt_b;
        struct tracing_map_sort_key *sort_key;
@@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
        tracing_map_cmp_fn_t cmp_fn;
        void *val_a, *val_b;
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       elt_a = (*a)->elt;
-       elt_b = (*b)->elt;
+       elt_a = a->elt;
+       elt_b = b->elt;
 
        sort_key = &elt_a->map->sort_key;
 
@@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
        return ret;
 }
 
-static int cmp_entries_key(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_key(const void *__a, const void *__b)
 {
        const struct tracing_map_elt *elt_a, *elt_b;
        struct tracing_map_sort_key *sort_key;
@@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a,
        tracing_map_cmp_fn_t cmp_fn;
        void *val_a, *val_b;
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       elt_a = (*a)->elt;
-       elt_b = (*b)->elt;
+       elt_a = a->elt;
+       elt_b = b->elt;
 
        sort_key = &elt_a->map->sort_key;
 
@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
                           struct tracing_map_sort_key *primary_key,
                           struct tracing_map_sort_key *secondary_key)
 {
-       int (*primary_fn)(const struct tracing_map_sort_entry **,
-                         const struct tracing_map_sort_entry **);
-       int (*secondary_fn)(const struct tracing_map_sort_entry **,
-                           const struct tracing_map_sort_entry **);
+       int (*primary_fn)(const void *, const void *);
+       int (*secondary_fn)(const void *, const void *);
        unsigned i, start = 0, n_sub = 1;
 
        if (is_key(map, primary_key->field_idx))

kernel/trace/tracing_map.c int tracing_map_sort_entries(struct tracing_map *map, · line 1074

Quoted 9 lines
kernel/trace/tracing_map.c +1 -2
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
                             unsigned int n_sort_keys,
                             struct tracing_map_sort_entry ***sort_entries)
 {
-       int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
-                             const struct tracing_map_sort_entry **);
+       int (*cmp_entries_fn)(const void *, const void *);
        struct tracing_map_sort_entry *sort_entry, **entries;
        int i, n_entries, ret;
 

Thanks for the patch! This looks correct to me and fixes the function type mismatch that trips CFI.

Sami

#2 lore raw
Quoted 123 lines · Sami Tolvanen

Hi Kalesh,

Quoted 106 lines · Kalesh Singh

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check.

1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger
2. cat >> events/sched/sched_switch/hist
3. kernel panices on attempting to read hist

This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this.

---
 kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
kernel/trace/tracing_map.c +22 -15
index d6bddb157ef2..a8c80ebbf9da 100644
@@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map)
        return err;
 }
 
-static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_dup(const void *__a, const void *__b)
 {
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
+       if (memcmp(a->key, b->key, a->elt->map->key_size))
                ret = 1;
 
        return ret;
 }
 
-static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_sum(const void *__a, const void *__b)
 {
        const struct tracing_map_elt *elt_a, *elt_b;
        struct tracing_map_sort_key *sort_key;
@@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
        tracing_map_cmp_fn_t cmp_fn;
        void *val_a, *val_b;
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       elt_a = (*a)->elt;
-       elt_b = (*b)->elt;
+       elt_a = a->elt;
+       elt_b = b->elt;
 
        sort_key = &elt_a->map->sort_key;
 
@@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
        return ret;
 }
 
-static int cmp_entries_key(const struct tracing_map_sort_entry **a,
-                          const struct tracing_map_sort_entry **b)
+static int cmp_entries_key(const void *__a, const void *__b)
 {
        const struct tracing_map_elt *elt_a, *elt_b;
        struct tracing_map_sort_key *sort_key;
@@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a,
        tracing_map_cmp_fn_t cmp_fn;
        void *val_a, *val_b;
        int ret = 0;
+       const struct tracing_map_sort_entry *a
+               = *(const struct tracing_map_sort_entry **)__a;
+       const struct tracing_map_sort_entry *b
+               = *(const struct tracing_map_sort_entry **)__b;
 
-       elt_a = (*a)->elt;
-       elt_b = (*b)->elt;
+       elt_a = a->elt;
+       elt_b = b->elt;
 
        sort_key = &elt_a->map->sort_key;
 
@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
                           struct tracing_map_sort_key *primary_key,
                           struct tracing_map_sort_key *secondary_key)
 {
-       int (*primary_fn)(const struct tracing_map_sort_entry **,
-                         const struct tracing_map_sort_entry **);
-       int (*secondary_fn)(const struct tracing_map_sort_entry **,
-                           const struct tracing_map_sort_entry **);
+       int (*primary_fn)(const void *, const void *);
+       int (*secondary_fn)(const void *, const void *);
        unsigned i, start = 0, n_sub = 1;
 
        if (is_key(map, primary_key->field_idx))

kernel/trace/tracing_map.c int tracing_map_sort_entries(struct tracing_map *map, · line 1074

Quoted 9 lines
kernel/trace/tracing_map.c +1 -2
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
                             unsigned int n_sort_keys,
                             struct tracing_map_sort_entry ***sort_entries)
 {
-       int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
-                             const struct tracing_map_sort_entry **);
+       int (*cmp_entries_fn)(const void *, const void *);
        struct tracing_map_sort_entry *sort_entry, **entries;
        int i, n_entries, ret;
 

Thanks for the patch! This looks correct to me and fixes the function type mismatch that trips CFI.

Quoted 1 line

Thanks for the review Sami.

Steve, will this get picked up for your tree?

Quoted 2 lines

Sami

maintainer
#3 lore raw
Quoted 9 lines · On Mon, 27 Sep 2021 11:15:01 -0700 Kalesh Singh <[email protected]> wrote:
Quoted 5 lines

Thanks for the patch! This looks correct to me and fixes the function type mismatch that trips CFI.

Thanks for the review Sami.

Steve, will this get picked up for your tree?

Yeah, I can pull it through my tree, but as I'm currently traveling, I can't give a proper ETA on when it will hit. But at the latest, I'll be looking at all my patch queue next week.

-- Steve

maintainer
#4 lore raw
In reply to Kalesh Singh

On Thu, 23 Sep 2021 17:09:07 +0000
Kalesh Singh <[email protected]> wrote:

This finally popped up into my queue (from all my traveling and running of conferences :-p )

Quoted 5 lines

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check.

1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger
2. cat >> events/sched/sched_switch/hist

Do you mean:

2. cat events/sched/sched_switch/hist

?

Small nits below.

Quoted 17 lines

3. kernel panices on attempting to read hist

This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this.

---
 kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
kernel/trace/tracing_map.c +0 -0
index d6bddb157ef2..a8c80ebbf9da 100644

kernel/trace/tracing_map.c int tracing_map_init(struct tracing_map *map) · line 837

Quoted 6 lines
kernel/trace/tracing_map.c +1 -2
@@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map)
 	return err;
 }
 
-static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_dup(const void *__a, const void *__b)

Instead of __a and __b, have it as:

const void *A, const void *B

kernel/trace/tracing_map.c int tracing_map_init(struct tracing_map *map) · line 843

Quoted 6 lines
kernel/trace/tracing_map.c +4 -0
 {
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;

Please put these before the ret, we like to have a "upside down xmas tree" type of declaration, where longer lines come before shorter ones. Also, this can be "prettified" as:

	const struct tracing_map_sort_entry **pa = A;
	const struct tracing_map_sort_entry **pb = B;
	const struct tracing_map_sort_entry *a = *pa;
	const struct tracing_map_sort_entry *b = *pb;
	int ret = 0;
Quoted 15 lines
kernel/trace/tracing_map.c +2 -3
-	if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
+	if (memcmp(a->key, b->key, a->elt->map->key_size))
 		ret = 1;
 
 	return ret;
 }
 
-static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_sum(const void *__a, const void *__b)
 {
 	const struct tracing_map_elt *elt_a, *elt_b;
 	struct tracing_map_sort_key *sort_key;

kernel/trace/tracing_map.c static int cmp_entries_sum(const struct tracing_map_sort_entry **a, · line 862

Quoted 7 lines
kernel/trace/tracing_map.c +4 -0
@@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
 	tracing_map_cmp_fn_t cmp_fn;
 	void *val_a, *val_b;
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;

Same here.

Quoted 19 lines
kernel/trace/tracing_map.c +3 -4
-	elt_a = (*a)->elt;
-	elt_b = (*b)->elt;
+	elt_a = a->elt;
+	elt_b = b->elt;
 
 	sort_key = &elt_a->map->sort_key;
 
@@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
 	return ret;
 }
 
-static int cmp_entries_key(const struct tracing_map_sort_entry **a,
-			   const struct tracing_map_sort_entry **b)
+static int cmp_entries_key(const void *__a, const void *__b)
 {
 	const struct tracing_map_elt *elt_a, *elt_b;
 	struct tracing_map_sort_key *sort_key;

kernel/trace/tracing_map.c static int cmp_entries_key(const struct tracing_map_sort_entry **a, · line 893

Quoted 7 lines
kernel/trace/tracing_map.c +4 -0
@@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a,
 	tracing_map_cmp_fn_t cmp_fn;
 	void *val_a, *val_b;
 	int ret = 0;
+	const struct tracing_map_sort_entry *a
+		= *(const struct tracing_map_sort_entry **)__a;
+	const struct tracing_map_sort_entry *b
+		= *(const struct tracing_map_sort_entry **)__b;

And here.

Thanks, and sorry for the long delay.

-- Steve

Quoted 33 lines
kernel/trace/tracing_map.c +5 -8
-	elt_a = (*a)->elt;
-	elt_b = (*b)->elt;
+	elt_a = a->elt;
+	elt_b = b->elt;
 
 	sort_key = &elt_a->map->sort_key;
 
@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
 			   struct tracing_map_sort_key *primary_key,
 			   struct tracing_map_sort_key *secondary_key)
 {
-	int (*primary_fn)(const struct tracing_map_sort_entry **,
-			  const struct tracing_map_sort_entry **);
-	int (*secondary_fn)(const struct tracing_map_sort_entry **,
-			    const struct tracing_map_sort_entry **);
+	int (*primary_fn)(const void *, const void *);
+	int (*secondary_fn)(const void *, const void *);
 	unsigned i, start = 0, n_sub = 1;
 
 	if (is_key(map, primary_key->field_idx))
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
 			     unsigned int n_sort_keys,
 			     struct tracing_map_sort_entry ***sort_entries)
 {
-	int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
-			      const struct tracing_map_sort_entry **);
+	int (*cmp_entries_fn)(const void *, const void *);
 	struct tracing_map_sort_entry *sort_entry, **entries;
 	int i, n_entries, ret;
 

base-commit: 58e2cf5d794616b84f591d4d1276c8953278ce24

#5 lore raw
Quoted 15 lines · Steven Rostedt

On Thu, 23 Sep 2021 17:09:07 +0000
Kalesh Singh <[email protected]> wrote:

This finally popped up into my queue (from all my traveling and running of conferences :-p )

Quoted 5 lines

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check.

1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger
2. cat >> events/sched/sched_switch/hist

Quoted 7 lines

Do you mean:

2. cat events/sched/sched_switch/hist

?

Small nits below.

Thanks Steve, v2 posted at
https://lore.kernel.org/r/[email protected]/

- Kalesh

Quoted 139 lines
Quoted 18 lines

3. kernel panices on attempting to read hist

This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this.

---
 kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
kernel/trace/tracing_map.c +0 -0
index d6bddb157ef2..a8c80ebbf9da 100644

kernel/trace/tracing_map.c int tracing_map_init(struct tracing_map *map) · line 837

Quoted 6 lines
kernel/trace/tracing_map.c +1 -2
@@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map)
      return err;
 }
 
-static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
-                        const struct tracing_map_sort_entry **b)
+static int cmp_entries_dup(const void *__a, const void *__b)

Instead of __a and __b, have it as:

const void *A, const void *B

kernel/trace/tracing_map.c int tracing_map_init(struct tracing_map *map) · line 843

Quoted 6 lines
kernel/trace/tracing_map.c +4 -0
 {
      int ret = 0;
+     const struct tracing_map_sort_entry *a
+             = *(const struct tracing_map_sort_entry **)__a;
+     const struct tracing_map_sort_entry *b
+             = *(const struct tracing_map_sort_entry **)__b;

Please put these before the ret, we like to have a "upside down xmas tree" type of declaration, where longer lines come before shorter ones. Also, this can be "prettified" as:

        const struct tracing_map_sort_entry **pa = A;
        const struct tracing_map_sort_entry **pb = B;
        const struct tracing_map_sort_entry *a = *pa;
        const struct tracing_map_sort_entry *b = *pb;
        int ret = 0;
Quoted 15 lines
kernel/trace/tracing_map.c +2 -3
-     if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
+     if (memcmp(a->key, b->key, a->elt->map->key_size))
              ret = 1;
 
      return ret;
 }
 
-static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
-                        const struct tracing_map_sort_entry **b)
+static int cmp_entries_sum(const void *__a, const void *__b)
 {
      const struct tracing_map_elt *elt_a, *elt_b;
      struct tracing_map_sort_key *sort_key;

kernel/trace/tracing_map.c static int cmp_entries_sum(const struct tracing_map_sort_entry **a, · line 862

Quoted 7 lines
kernel/trace/tracing_map.c +4 -0
@@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
      tracing_map_cmp_fn_t cmp_fn;
      void *val_a, *val_b;
      int ret = 0;
+     const struct tracing_map_sort_entry *a
+             = *(const struct tracing_map_sort_entry **)__a;
+     const struct tracing_map_sort_entry *b
+             = *(const struct tracing_map_sort_entry **)__b;

Same here.

Quoted 19 lines
kernel/trace/tracing_map.c +3 -4
-     elt_a = (*a)->elt;
-     elt_b = (*b)->elt;
+     elt_a = a->elt;
+     elt_b = b->elt;
 
      sort_key = &elt_a->map->sort_key;
 
@@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
      return ret;
 }
 
-static int cmp_entries_key(const struct tracing_map_sort_entry **a,
-                        const struct tracing_map_sort_entry **b)
+static int cmp_entries_key(const void *__a, const void *__b)
 {
      const struct tracing_map_elt *elt_a, *elt_b;
      struct tracing_map_sort_key *sort_key;

kernel/trace/tracing_map.c static int cmp_entries_key(const struct tracing_map_sort_entry **a, · line 893

Quoted 7 lines
kernel/trace/tracing_map.c +4 -0
@@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a,
      tracing_map_cmp_fn_t cmp_fn;
      void *val_a, *val_b;
      int ret = 0;
+     const struct tracing_map_sort_entry *a
+             = *(const struct tracing_map_sort_entry **)__a;
+     const struct tracing_map_sort_entry *b
+             = *(const struct tracing_map_sort_entry **)__b;

And here.

Thanks, and sorry for the long delay.

-- Steve

Quoted 33 lines
kernel/trace/tracing_map.c +5 -8
-     elt_a = (*a)->elt;
-     elt_b = (*b)->elt;
+     elt_a = a->elt;
+     elt_b = b->elt;
 
      sort_key = &elt_a->map->sort_key;
 
@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
                         struct tracing_map_sort_key *primary_key,
                         struct tracing_map_sort_key *secondary_key)
 {
-     int (*primary_fn)(const struct tracing_map_sort_entry **,
-                       const struct tracing_map_sort_entry **);
-     int (*secondary_fn)(const struct tracing_map_sort_entry **,
-                         const struct tracing_map_sort_entry **);
+     int (*primary_fn)(const void *, const void *);
+     int (*secondary_fn)(const void *, const void *);
      unsigned i, start = 0, n_sub = 1;
 
      if (is_key(map, primary_key->field_idx))
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
                           unsigned int n_sort_keys,
                           struct tracing_map_sort_entry ***sort_entries)
 {
-     int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
-                           const struct tracing_map_sort_entry **);
+     int (*cmp_entries_fn)(const void *, const void *);
      struct tracing_map_sort_entry *sort_entry, **entries;
      int i, n_entries, ret;
 

base-commit: 58e2cf5d794616b84f591d4d1276c8953278ce24