Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4020474pxb; Wed, 13 Oct 2021 18:41:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9HkYt0En8qmFVzYwL5ED/fJQkvIirWBcnIeYrCu8hmusRr5jcwsR6F1uo9W5nBB5E9E/8 X-Received: by 2002:a17:90a:4097:: with SMTP id l23mr17558434pjg.141.1634175681758; Wed, 13 Oct 2021 18:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634175681; cv=none; d=google.com; s=arc-20160816; b=Iy6DKgqAUZh3Uum92itVQbvTfmroccCDOelilRPIoEYJAqt2P3RczwEx/B4attevbB 6kVZBPI3Wy4GElh7xkEzwLCN+VZ83nWHBpileEDXkJHrhSrLE0hzS56ZcldQhjUONZbL lL4MYkb8j99LF1xt+YikKCmC4cuuX21R/nszzSosPAcg98YRdSPIBnI/7azfWZn4smfI 9XAjrLrMVBAEjKftAQvYuD49CTurhJkX2LbEcEkUOYZc523zFjSqDfbDX0DGruZTeyHn O9KqOb3bCiU2uRjw1fbJQlnYhsVggUqabfkk326yae1WkxkJCS77d95oXj8PS0ODzuGk +Qvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Ygn1/So2L6NrJcd5boRzqswYyFbg2B+I40MS8TYVpNs=; b=wTMyBVwM58uhAI9BtZ5mWKW1zpGm1+Pkg8thAqj/6NQ1ljVaN2BV2QMGn2KuBgYrhF XSr/4IsVTRfbYIr4WjFdaJpiWPd1Gwj8LrykAZKh1i/o5rzRMhMjT61TNwkIqsG3DaJ4 IbRXJviwAfS1ibZJju/7HSSoy7oOq87s9yO/4O6j5ZXlrR/nWwO5juco5uO6UbRoq06i hbiqscK2pJ/TNOIFTpsUy6vLBuN0H1DtGSgD+1hpjz3er4UG/Nz2qHC7EBgkJVUUSIZ5 8CzwfXeAMAJwGzqftYkGulOMfLXx99U7C2yjm/yVsL4H12zb1wGlA7SoNEXEWEMGMXeu 9OiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IIdRmLJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i188si1698665pfb.206.2021.10.13.18.41.08; Wed, 13 Oct 2021 18:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IIdRmLJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbhJNBl6 (ORCPT + 99 others); Wed, 13 Oct 2021 21:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbhJNBl6 (ORCPT ); Wed, 13 Oct 2021 21:41:58 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FFE3C061570 for ; Wed, 13 Oct 2021 18:39:54 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id t11so3034520plq.11 for ; Wed, 13 Oct 2021 18:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ygn1/So2L6NrJcd5boRzqswYyFbg2B+I40MS8TYVpNs=; b=IIdRmLJFQRavjMw2MWCGuzvN3Cehb4IG454gJu1GIkzZvm4m0z4ZnV77W4Jx2fZa+K u0w6H43zkHZeg7ZNaGgenLgMEtLP2B9wQNG1QCk2dLOurbCG090ncA5dJ1GlF/4AeXKJ 1rHBPDF38+xVZKXlx9VTdKDnedmdrg1QIyVu0xMX2TwRb7V4UpiohhbH2BxMUVg2dXd7 gasIxI1rOV6PPIe/BQJKzb6GaFi3HiozPliZP3gYFCCK4VXxJUrztaCxF4MCkU3IQ2t1 8Y6FyJOYqBQLZHMXMOggW7fRqvAb2z6l9nQbvJANvcDD06v1I9yrFoV3BYCvWn9FrUQQ C/CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ygn1/So2L6NrJcd5boRzqswYyFbg2B+I40MS8TYVpNs=; b=jp32K5f+2gtBCE39Wk09lI+CqkmfRWwZEvwXZRaTTW947vaF8y41Kxoa2zZeZoq/Xk 6EdsjP5v58PRG1BTU1CGeCZ/H7jCGABfUQYue5J/GMaQuW2Q03McPHHSSr6MHth3vLfh VUlQq9BZ9xcMTXzv9q0ExIbz6SaYFtYP7Bn0PC6bPYjW9rGfhfU/ZBFH5+kUAXbAp+h3 /2h8jotEEzOgaNFY1Yo/OlHzoqMnJDe7H+PpWKwaeKVcrrligA2tNWYn5NTHFl4yTqsQ gFkHgpsKlPEni3Zo4/+HtnUw4YNWP/eItL9RGNcRH9yWZwrevDAO8DPvSkKj7sMwbf4o tY2Q== X-Gm-Message-State: AOAM533EuWylmOoqyIl5fCpc9DIHR6iMxT0T/l5PvCIyXKoRY8dy/kRd +NFdRctwR3z2fyVUmOO4Ezw5SIX4EdRzMwnWYJ+uPQ== X-Received: by 2002:a17:90b:4a81:: with SMTP id lp1mr3140101pjb.124.1634175593356; Wed, 13 Oct 2021 18:39:53 -0700 (PDT) MIME-Version: 1.0 References: <20210923170908.2184404-1-kaleshsingh@google.com> <20211013180834.73e2653e@gandalf.local.home> In-Reply-To: <20211013180834.73e2653e@gandalf.local.home> From: Kalesh Singh Date: Wed, 13 Oct 2021 18:39:42 -0700 Message-ID: Subject: Re: [PATCH] tracing/cfi: Fix cmp_entries_* functions signature mismatch To: Steven Rostedt Cc: Suren Baghdasaryan , Hridya Valsaraju , Namhyung Kim , Sami Tolvanen , Nick Desaulniers , "Cc: Android Kernel" , Ingo Molnar , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 3:08 PM Steven Rostedt wrote: > > On Thu, 23 Sep 2021 17:09:07 +0000 > Kalesh Singh wrote: > > > This finally popped up into my queue (from all my traveling and running of > conferences :-p ) > > > > 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. Thanks Steve, v2 posted at https://lore.kernel.org/r/20211014013704.2854890-1-kaleshsingh@google.com/ - Kalesh > > > 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. > > > > Signed-off-by: Kalesh Singh > > --- > > kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++---------------- > > 1 file changed, 23 insertions(+), 17 deletions(-) > > > > diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c > > index d6bddb157ef2..a8c80ebbf9da 100644 > > --- a/kernel/trace/tracing_map.c > > +++ b/kernel/trace/tracing_map.c > > @@ -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 > > > > { > > 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; > > > > > - 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; > > Same here. > > > > > - 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; > > And here. > > Thanks, and sorry for the long delay. > > -- Steve > > > > > - 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 >