<div dir="ltr"><br><br>On Mon, Sep 27, 2021 at 10:00 PM Tao Liu <<a href="mailto:ltao@redhat.com">ltao@redhat.com</a>> wrote:<br>><br>> Hello Lianbo and Philipp,<br>><br>> syment_is_installed is used to check if the specific syment has been<br>> installed before. It checks whether the syment address and the given<br>> address are the same.<br>> symname_hash_search is used to search the syment which has the given<br>> name. It checks whether the name field of the syment and the given<br>> name are the same.<br>><br>Thank you for the explanation, Tao.<br><br>> Please note the hash table can have more than 1 syments which have the<br>> same name but differ in address. What We want to avoid is the case if<br>> a syment has been installed before, it should never be installed<br>> again. So here we care about syment address, instead of syment name.<br>><br>If that's true, it may have a hash collision because here is a simple string hash, the<br>symname_hash_search() always returns the first symbol entry with the 'name',  seems<br>that it doesn't consider the hash collision with the <span style="background-color:rgb(255,0,0)">same</span> 'name' when searching for the<br>symbol entry with the name, right?<br><br>Currently, the symname_hash_search() handles the hash collision with the different name<div>when searching for the symbol entry.<div><br></div><div>Thanks.</div><div>Lianbo</div><div><br>> Like Philipp said, if we use symname_hash_search to implement<br>> syment_is_installed, we will use extra code to check the address of<br>> symnet returned by symname_hash_search. The code will not be as clear<br>> as we directly use syment_is_installed.<br>><br>> Thanks,<br>> Tao Liu<br>><br>> On Mon, Sep 27, 2021 at 5:54 PM Philipp Rudo <<a href="mailto:prudo@redhat.com">prudo@redhat.com</a>> wrote:<br>> ><br>> > On Mon, 27 Sep 2021 12:00:26 +0800<br>> > lijiang <<a href="mailto:lijiang@redhat.com">lijiang@redhat.com</a>> wrote:<br>> ><br>> > > > Date: Sat, 18 Sep 2021 15:59:32 +0800<br>> > > > From: Tao Liu <<a href="mailto:ltao@redhat.com">ltao@redhat.com</a>><br>> > > > To: <a href="mailto:crash-utility@redhat.com">crash-utility@redhat.com</a><br>> > > > Subject: [Crash-utility] [PATCH v4 4/4] Add check if an syment element<br>> > > >         is      installed one more time<br>> > > > Message-ID: <<a href="mailto:20210918075932.132339-5-ltao@redhat.com">20210918075932.132339-5-ltao@redhat.com</a>><br>> > > > Content-Type: text/plain; charset="US-ASCII"<br>> > > ><br>> > > > symname_hash_install won't check if spn has been installed before. If<br>> > > > it does, the second install will corrupt the hash table as well as<br>> > > > spn->cnt counting. This patch adds the check to avoid such risks.<br>> > > ><br>> > > > Signed-off-by: Tao Liu <<a href="mailto:ltao@redhat.com">ltao@redhat.com</a>><br>> > > > ---<br>> > > >  symbols.c | 16 +++++++++++++++-<br>> > > >  1 file changed, 15 insertions(+), 1 deletion(-)<br>> > > ><br>> > > > diff --git a/symbols.c b/symbols.c<br>> > > > index f7157b1..6d12c55 100644<br>> > > > --- a/symbols.c<br>> > > > +++ b/symbols.c<br>> > > > @@ -1147,6 +1147,20 @@ mod_symtable_hash_remove_range(struct syment *from, struct syment *to)<br>> > > >                 symname_hash_remove(st->mod_symname_hash, sp);<br>> > > >  }<br>> > > ><br>> > > > +static inline int<br>> > > > +syment_is_installed(struct syment *table[], struct syment *spn)<br>> > > > +{<br>> > > > +       struct syment *sp;<br>> > > > +       int index;<br>> > > > +<br>> > > > +       index = SYMNAME_HASH_INDEX(spn->name);<br>> > > > +       for (sp = table[index]; sp; sp = sp->name_hash_next) {<br>> > > > +               if (sp == spn)<br>> > > > +                       return TRUE;<br>> > > > +       }<br>> > > > +       return FALSE;<br>> > > > +}<br>> > > > +<br>> > > >  /*<br>> > > >   *  Install a single static kernel symbol into the symname_hash.<br>> > > >   */<br>> > > > @@ -1156,7 +1170,7 @@ symname_hash_install(struct syment *table[], struct syment *spn)<br>> > > >         struct syment *sp;<br>> > > >          int index;<br>> > > ><br>> > > > -       if (!spn)<br>> > > > +       if (!spn || syment_is_installed(table, spn))<br>> > > >                 return;<br>> > ><br>> > > Here, why don't we call the existing symname_hash_search() and<br>> > > redefine a new syment_is_installed()? Could you please describe more<br>> > > details?<br>> ><br>> > I thought about that, too. In my opinion the problem with reusing<br>> > symname_hash_search is that it searches for symbols with the same name.<br>> > But the name doesn't necessarily have to be unique. So when<br>> > symname_hash_search returns a symbol you still need to check if it is<br>> > the same symbol and if not iterate through all symbols with the same<br>> > name to check if any of them is. In the end I think that code will be<br>> > more complex than having this additional syment_is_installed.<br>> ><br>> > Thanks<br>> > Philipp<br>> ><br>> > ><br>> > > Thanks.<br>> > > Lianbo<br>> > ><br>> > > ><br>> > > >          index = SYMNAME_HASH_INDEX(spn->name);<br>> > > > --<br>> > > > 2.29.2<br>> > ><br>> > > --<br>> > > Crash-utility mailing list<br>> > > <a href="mailto:Crash-utility@redhat.com">Crash-utility@redhat.com</a><br>> > > <a href="https://listman.redhat.com/mailman/listinfo/crash-utility">https://listman.redhat.com/mailman/listinfo/crash-utility</a><br>> > ><br>> ><br>> > --<br>> > Crash-utility mailing list<br>> > <a href="mailto:Crash-utility@redhat.com">Crash-utility@redhat.com</a><br>> > <a href="https://listman.redhat.com/mailman/listinfo/crash-utility">https://listman.redhat.com/mailman/listinfo/crash-utility</a><br>> ><br>></div></div></div>