linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: David Wang <00107082@163.com>
Cc: kent.overstreet@linux.dev, akpm@linux-foundation.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] alloc_tag: add sequence number for module and iterator
Date: Mon, 9 Jun 2025 09:41:49 -0700	[thread overview]
Message-ID: <CAJuCfpGsb5MVc35Y21uG3r8c6+duOXzd_y2KyLOKYNddrKy3FA@mail.gmail.com> (raw)
In-Reply-To: <20250609064200.112639-1-00107082@163.com>

On Sun, Jun 8, 2025 at 11:42 PM David Wang <00107082@163.com> wrote:
>
> Codetag iterator use <id,address> pair to guarantee the
> validness. But both id and address can be reused, there is
> theoretical possibility when module inserted right after
> another module removed, kmalloc returns an address same as
> the address kfree by previous module and IDR key reuses
> the key recently removed.
>
> Add a sequence number to codetag_module and code_iterator,
> the sequence number is strickly incremented whenever a module
> is loaded. An iterator is valid if and only if its sequence
> number match codetag_module's.
>
> Signed-off-by: David Wang <00107082@163.com>
> ---
> Changes since v2:
> Rebase to 6.16-rc1

If all you did is rebase then please add my Acked-by. Thanks!

> ---
>  include/linux/codetag.h |  1 +
>  lib/codetag.c           | 17 ++++++++++++++---
>  2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/codetag.h b/include/linux/codetag.h
> index 5f2b9a1f722c..457ed8fd3214 100644
> --- a/include/linux/codetag.h
> +++ b/include/linux/codetag.h
> @@ -54,6 +54,7 @@ struct codetag_iterator {
>         struct codetag_module *cmod;
>         unsigned long mod_id;
>         struct codetag *ct;
> +       unsigned long mod_seq;
>  };
>
>  #ifdef MODULE
> diff --git a/lib/codetag.c b/lib/codetag.c
> index 650d54d7e14d..545911cebd25 100644
> --- a/lib/codetag.c
> +++ b/lib/codetag.c
> @@ -11,8 +11,14 @@ struct codetag_type {
>         struct list_head link;
>         unsigned int count;
>         struct idr mod_idr;
> -       struct rw_semaphore mod_lock; /* protects mod_idr */
> +       /*
> +        * protects mod_idr, next_mod_seq,
> +        * iter->mod_seq and cmod->mod_seq
> +        */
> +       struct rw_semaphore mod_lock;
>         struct codetag_type_desc desc;
> +       /* generates unique sequence number for module load */
> +       unsigned long next_mod_seq;
>  };
>
>  struct codetag_range {
> @@ -23,6 +29,7 @@ struct codetag_range {
>  struct codetag_module {
>         struct module *mod;
>         struct codetag_range range;
> +       unsigned long mod_seq;
>  };
>
>  static DEFINE_MUTEX(codetag_lock);
> @@ -48,6 +55,7 @@ struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype)
>                 .cmod = NULL,
>                 .mod_id = 0,
>                 .ct = NULL,
> +               .mod_seq = 0,
>         };
>
>         return iter;
> @@ -91,11 +99,13 @@ struct codetag *codetag_next_ct(struct codetag_iterator *iter)
>                 if (!cmod)
>                         break;
>
> -               if (cmod != iter->cmod) {
> +               if (!iter->cmod || iter->mod_seq != cmod->mod_seq) {
>                         iter->cmod = cmod;
> +                       iter->mod_seq = cmod->mod_seq;
>                         ct = get_first_module_ct(cmod);
> -               } else
> +               } else {
>                         ct = get_next_module_ct(iter);
> +               }
>
>                 if (ct)
>                         break;
> @@ -191,6 +201,7 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
>         cmod->range = range;
>
>         down_write(&cttype->mod_lock);
> +       cmod->mod_seq = ++cttype->next_mod_seq;
>         mod_id = idr_alloc(&cttype->mod_idr, cmod, 0, 0, GFP_KERNEL);
>         if (mod_id >= 0) {
>                 if (cttype->desc.module_load) {
> --
> 2.39.2
>

  reply	other threads:[~2025-06-09 16:42 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 17:55 [PATCH] alloc_tag: avoid mem alloc and iter reset when reading allocinfo David Wang
2025-05-07 18:19 ` David Wang
2025-05-07 23:42   ` [PATCH] " Suren Baghdasaryan
2025-05-08  0:01     ` Kent Overstreet
2025-05-08  3:06       ` David Wang
2025-05-08  3:31         ` Kent Overstreet
2025-05-08  3:35           ` David Wang
2025-05-08  4:07             ` Kent Overstreet
2025-05-08  5:51               ` David Wang
2025-05-08 13:33                 ` Kent Overstreet
2025-05-08 16:24                   ` David Wang
2025-05-08 16:34                     ` Kent Overstreet
2025-05-08 16:58                       ` David Wang
2025-05-08 17:17                         ` David Wang
2025-05-08 17:26                           ` Kent Overstreet
2025-05-08  2:24     ` David Wang
2025-05-07 23:36 ` Suren Baghdasaryan
2025-05-08  3:10   ` David Wang
2025-05-08 15:32   ` David Wang
2025-05-08 21:41     ` Suren Baghdasaryan
2025-05-09  5:51 ` [PATCH 1/2] alloc_tag: add timestamp to codetag iterator David Wang
2025-05-09 16:10   ` Suren Baghdasaryan
2025-05-09 16:16     ` David Wang
2025-05-09  5:53 ` [PATCH 2/2] alloc_tag: keep codetag iterator cross read() calls David Wang
2025-05-09 17:34   ` Suren Baghdasaryan
2025-05-09 17:45     ` David Wang
2025-05-09 17:38 ` [PATCH v2 1/2] alloc_tag: add sequence number for module and iterator David Wang
2025-05-09 19:25   ` Suren Baghdasaryan
2025-06-09  6:42     ` [PATCH v3 " David Wang
2025-06-09 16:41       ` Suren Baghdasaryan [this message]
2025-05-09 17:39 ` [PATCH v2 2/2] alloc_tag: keep codetag iterator active between read() calls David Wang
2025-05-09 18:33   ` Tim Chen
2025-05-09 19:36     ` Suren Baghdasaryan
2025-05-09 19:46       ` Tim Chen
2025-05-09 20:46         ` Suren Baghdasaryan
2025-05-09 21:15           ` Suren Baghdasaryan
2025-05-10  3:10             ` David Wang
2025-05-10  3:30               ` Suren Baghdasaryan
2025-05-10  3:58                 ` David Wang
2025-05-10  4:03                   ` Suren Baghdasaryan
2025-06-09  6:44                     ` [PATCH v3 2/2] alloc_tag: keep codetag iterator active between read() David Wang
2025-06-10 16:22                       ` Suren Baghdasaryan
2025-05-10  3:35         ` [PATCH v2 2/2] alloc_tag: keep codetag iterator active between read() calls David Wang
2025-05-10  3:25     ` David Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJuCfpGsb5MVc35Y21uG3r8c6+duOXzd_y2KyLOKYNddrKy3FA@mail.gmail.com \
    --to=surenb@google.com \
    --cc=00107082@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).