On Fri, Aug 9, 2024 at 12:33 AM Kees Cook <kees@xxxxxxxxxx> wrote: > > In order to process builtin alloc_tags much earlier during boot (before > register_codetag() is processed), provide codetag_early_walk() that > perform a lockless walk with a specified callback function. This will be > used to allocate required caches that cannot be allocated on demand. > > Signed-off-by: Kees Cook <kees@xxxxxxxxxx> > --- > Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> > Cc: Kent Overstreet <kent.overstreet@xxxxxxxxx> > Cc: Vlastimil Babka <vbabka@xxxxxxx> > Cc: Christoph Lameter <cl@xxxxxxxxx> > Cc: Pekka Enberg <penberg@xxxxxxxxxx> > Cc: David Rientjes <rientjes@xxxxxxxxxx> > Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx> > Cc: Hyeonggon Yoo <42.hyeyoo@xxxxxxxxx> > Cc: linux-mm@xxxxxxxxx > --- > include/linux/codetag.h | 2 ++ > lib/codetag.c | 16 ++++++++++++++++ > 2 files changed, 18 insertions(+) > > diff --git a/include/linux/codetag.h b/include/linux/codetag.h > index c2a579ccd455..9eb1fcd90570 100644 > --- a/include/linux/codetag.h > +++ b/include/linux/codetag.h > @@ -64,6 +64,8 @@ void codetag_lock_module_list(struct codetag_type *cttype, bool lock); > bool codetag_trylock_module_list(struct codetag_type *cttype); > struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype); > struct codetag *codetag_next_ct(struct codetag_iterator *iter); > +void codetag_early_walk(const struct codetag_type_desc *desc, > + void (*callback)(struct codetag *ct)); > > void codetag_to_text(struct seq_buf *out, struct codetag *ct); > > diff --git a/lib/codetag.c b/lib/codetag.c > index ef7634c7ee18..9d563c8c088a 100644 > --- a/lib/codetag.c > +++ b/lib/codetag.c > @@ -154,6 +154,22 @@ static struct codetag_range get_section_range(struct module *mod, > }; > } > > +void codetag_early_walk(const struct codetag_type_desc *desc, > + void (*callback)(struct codetag *ct)) > +{ > + struct codetag_range range; > + struct codetag *ct; > + > + range = get_section_range(NULL, desc->section); > + if (!range.start || !range.stop || > + range.start == range.stop || > + range.start > range.stop) > + return; I think this check can be simplified to: if (!range.start || range.start >= range.stop) return; nit: Technically (!range.start) should also never trigger. In a valid image these symbols are either missing (range.start == range.stop == NULL) or both are defined and (range.start < range.stop). > + > + for (ct = range.start; ct < range.stop; ct = ((void *)ct + desc->tag_size)) > + callback(ct); > +} > + > static int codetag_module_init(struct codetag_type *cttype, struct module *mod) > { > struct codetag_range range; > -- > 2.34.1 >