<div dir="ltr"><div dir="ltr">On Fri, Mar 10, 2023 at 10:28 AM HAGIO KAZUHITO(萩尾 一仁) <<a href="mailto:k-hagio-ab@nec.com">k-hagio-ab@nec.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2023/03/10 10:48, lijiang wrote:<br>
>> Thank you for the fix, Kazu.<br>
>> On Thu, Mar 9, 2023 at 9:44 AM HAGIO KAZUHITO(萩尾 一仁) <<a href="mailto:k-hagio-ab@nec.com" target="_blank">k-hagio-ab@nec.com</a> <mailto:<a href="mailto:k-hagio-ab@nec.com" target="_blank">k-hagio-ab@nec.com</a>>> wrote:<br>
>><br>
>>     Kernel commit d2bf38c088e0 ("driver core: remove private pointer from<br>
>>     struct bus_type") removed the bus_type.p member, and the "kmem -n"<br>
>>     option fails with the following error before displaying memory block<br>
>>     information on Linux 6.3-rc1 and later kernels.<br>
>><br>
>>       kmem: invalid structure member offset: bus_type_p<br>
>>             FILE: memory.c  LINE: 17852  FUNCTION: init_memory_block()<br>
>><br>
>>     Search bus_kset.list instead for subsys_private of memory subsys.<br>
>><br>
>>     Signed-off-by: Kazuhito Hagio <<a href="mailto:k-hagio-ab@nec.com" target="_blank">k-hagio-ab@nec.com</a> <mailto:<a href="mailto:k-hagio-ab@nec.com" target="_blank">k-hagio-ab@nec.com</a>>><br>
>>     ---<br>
>>      defs.h    |  2 ++<br>
>>      memory.c  | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------<br>
>>      symbols.c |  2 ++<br>
>>      3 files changed, 62 insertions(+), 6 deletions(-)<br>
>><br>
>>     diff --git a/defs.h b/defs.h<br>
>>     index 1f2cf6e0ce01..12ad6aaa0998 100644<br>
>>     --- a/defs.h<br>
>>     +++ b/defs.h<br>
>>     @@ -2214,6 +2214,8 @@ struct offset_table {                    /* stash of commonly-used offsets */<br>
>>             long inet6_ifaddr_if_list;<br>
>>             long inet6_ifaddr_if_next;<br>
>>             long in6_addr_in6_u;<br>
>>     +       long kset_kobj;<br>
>>     +       long subsys_private_subsys;<br>
>>      };<br>
>><br>
>>      struct size_table {         /* stash of commonly-used sizes */<br>
>>     diff --git a/memory.c b/memory.c<br>
>>     index c4a6ecd18004..292b15a0dbab 100644<br>
>>     --- a/memory.c<br>
>>     +++ b/memory.c<br>
>>     @@ -17822,6 +17822,13 @@ static void<br>
>>      init_memory_block_offset(void)<br>
>>      {<br>
>>             MEMBER_OFFSET_INIT(bus_type_p, "bus_type", "p");<br>
>>     +       if (INVALID_MEMBER(bus_type_p)) {<br>
>>     +               MEMBER_OFFSET_INIT(kset_list, "kset", "list");<br>
>>     +               MEMBER_OFFSET_INIT(kset_kobj, "kset", "kobj");<br>
>>     +               MEMBER_OFFSET_INIT(kobject_name, "kobject", "name");<br>
>>     +               MEMBER_OFFSET_INIT(kobject_entry, "kobject", "entry");<br>
>>     +               MEMBER_OFFSET_INIT(subsys_private_subsys, "subsys_private", "subsys");<br>
>>     +       }<br>
>>             MEMBER_OFFSET_INIT(subsys_private_klist_devices,<br>
>>                                     "subsys_private", "klist_devices");<br>
>>             MEMBER_OFFSET_INIT(klist_k_list, "klist", "k_list");<br>
>>     @@ -17842,15 +17849,61 @@ init_memory_block_offset(void)<br>
>>      }<br>
>><br>
>>      static void<br>
>>     -init_memory_block(struct list_data *ld, int *klistcnt, ulong **klistbuf)<br>
>>     +init_memory_block(int *klistcnt, ulong **klistbuf)<br>
>>      {<br>
>>     -       ulong memory_subsys = symbol_value("memory_subsys");<br>
>>             ulong private, klist, start;<br>
>>     +       struct list_data list_data, *ld;<br>
>>     +<br>
>>     +       ld = &list_data;<br>
>>     +       private = 0;<br>
>><br>
>>             init_memory_block_offset();<br>
>><br>
>>     -       readmem(memory_subsys + OFFSET(bus_type_p), KVADDR, &private,<br>
>>     -               sizeof(void *), "memory_subsys.private", FAULT_ON_ERROR);<br>
>>     +       /*<br>
>>     +        * v6.3-rc1<br>
>>     +        * d2bf38c088e0 driver core: remove private pointer from struct bus_type<br>
>>     +        */<br>
>>     +       if (INVALID_MEMBER(bus_type_p)) {<br>
>>     +               int i, cnt;<br>
>>     +               char buf[8];    /* need 8 at least to exclude "memory_tiering" */<br>
>>     +               ulong bus_kset, list, name;<br>
>>     +<br>
>>     +               BZERO(ld, sizeof(struct list_data));<br>
>>     +<br>
>>     +               get_symbol_data("bus_kset", sizeof(ulong), &bus_kset);<br>
>>     +               readmem(bus_kset + OFFSET(kset_list), KVADDR, &list,<br>
>>     +                       sizeof(ulong), "bus_kset.list", FAULT_ON_ERROR);<br>
>>     +<br>
>>     +               ld->flags |= LIST_ALLOCATE;<br>
>>     +               ld->start = list;<br>
>>     +               ld->end = bus_kset + OFFSET(kset_list);<br>
>>     +               ld->list_head_offset = OFFSET(kobject_entry);<br>
>>     +<br>
>>     +               cnt = do_list(ld);<br>
>>     +               for (i = 0; i < cnt; i++) {<br>
>>     +                       readmem(ld->list_ptr[i] + OFFSET(kobject_name), KVADDR, &name,<br>
>>     +                               sizeof(ulong), "<a href="http://kobject.name" rel="noreferrer" target="_blank">kobject.name</a> <<a href="http://kobject.name" rel="noreferrer" target="_blank">http://kobject.name</a>>", FAULT_ON_ERROR);<br>
>>     +                       read_string(name, buf, sizeof(buf));<br>
>>     +                       buf[7] = '\0';<br>
>><br>
>><br>
>> The full name will be truncated, and  the STREQ(buf, "memory") will include two kinds of the "memory" and "memory_tiering", but the above code comment says to exclude "memory_tiering", looks weird to me. Do I misunderstand this?<br>
<br>
As the buf array has 8 bytes and the last is set to \0, so<br>
<br>
   "memory"         -> memory\0\0<br>
   "memory_tiering" -> memory_\0<br>
<br>
So we can distinguish these with STREQ(buf, "memory").</blockquote><div><br></div><div>Thank you for the explanation, Kazu.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>><br>
>>     +                       if (CRASHDEBUG(1))<br>
>>     +                               fprintf(fp, "kobject: %lx name: %s\n", ld->list_ptr[i], buf);<br>
>><br>
>><br>
>> BTW:  for the debug information, it might be good to output the full name of the memory subsys.<br>
<br>
Yes, I was not sure what is the max length of the name, so chose the<br>
minimum length in order to avoid read error due to out of bounds.<br>
<br>
But ok, looking at the usage of read_string() in crash, most of them<br>
have BUF_SIZE-1.  Maybe we don't need to care about it so much.<br>
I will change it to 32 in v2.<br>
<br></blockquote><div><br></div><div>It should be good enough to distinguish it from the various subsys names.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
an example without "break;"<br>
<br>
kobject: ffff8e1d83d83a18 name: platform<br>
kobject: ffff8e1d83d80e18 name: cpu<br>
kobject: ffff8e1d83d83c18 name: memory<br>
kobject: ffff8e1d83d81c18 name: node<br>
kobject: ffff8e1d83d80c18 name: container<br>
kobject: ffff8e1d83d80a18 name: workqueue<br>
kobject: ffff8e1d83d82e18 name: gpio<br>
kobject: ffff8e1d83d83418 name: virtio<br>
kobject: ffff8e19cb77da18 name: pci<br>
kobject: ffff8e19cb77e018 name: pci_express<br>
kobject: ffff8e19cb77ce18 name: spi<br>
kobject: ffff8e19cb77f818 name: i2c<br>
kobject: ffff8e19cb7c7a18 name: memory_tiering<br>
kobject: ffff8e1d8466ee18 name: acpi<br>
kobject: ffff8e1605d4e418 name: pnp<br>
kobject: ffff8e1605d4d018 name: xen<br>
kobject: ffff8e1605d4c418 name: dax<br>
kobject: ffff8e1605d4fc18 name: cxl<br>
kobject: ffff8e1605d4fa18 name: scsi<br>
kobject: ffff8e1605d4e218 name: mdio_bus<br>
kobject: ffff8e1605d4fe18 name: usb<br>
kobject: ffff8e1605d4c018 name: typec<br>
kobject: ffff8e1605d4f618 name: serio<br>
kobject: ffff8e1605e43018 name: edac<br>
kobject: ffff8e1605e41218 name: nvmem<br>
kobject: ffff8e16047d8a18 name: thunderbolt<br>
kobject: ffff8e160451e018 name: clocksource<br>
kobject: ffff8e160451da18 name: clockevents<br>
kobject: ffff8e160451f418 name: event_source<br>
kobject: ffff8e1d83e76018 name: usb-serial<br>
kobject: ffff8e1d86135418 name: hid<br>
kobject: ffff8e1611eea418 name: machinecheck<br>
kobject: ffff8e1d8d108618 name: wmi<br>
kobject: ffff8e160c187e18 name: mei<br>
<br></blockquote><div> </div><div>Thanks for the information.</div><div><br></div><div>Thanks.</div><div>Lianbo</div></div></div>