forked from mirrors/linux
		
	 d6b02199cd
			
		
	
	
		d6b02199cd
		
	
	
	
	
		
			
			reservation" from Sourabh Jain changes powerpc's kexec code to use more of the generic layers. - The 2 patch series "get_maintainer: report subsystem status separately" from Vlastimil Babka makes some long-requested improvements to the get_maintainer output. - The 4 patch series "ucount: Simplify refcounting with rcuref_t" from Sebastian Siewior cleans up and optimizing the refcounting in the ucount code. - The 12 patch series "reboot: support runtime configuration of emergency hw_protection action" from Ahmad Fatoum improves the ability for a driver to perform an emergency system shutdown or reboot. - The 16 patch series "Converge on using secs_to_jiffies() part two" from Easwar Hariharan performs further migrations from msecs_to_jiffies() to secs_to_jiffies(). - The 7 patch series "lib/interval_tree: add some test cases and cleanup" from Wei Yang permits more userspace testing of kernel library code, adds some more tests and performs some cleanups. - The 2 patch series "hung_task: Dump the blocking task stacktrace" from Masami Hiramatsu arranges for the hung_task detector to dump the stack of the blocking task and not just that of the blocked task. - The 4 patch series "resource: Split and use DEFINE_RES*() macros" from Andy Shevchenko provides some cleanups to the resource definition macros. - Plus the usual shower of singleton patches - please see the individual changelogs for details. -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTTMBEPP41GrTpTJgfdBJ7gKXxAjgUCZ+nuqwAKCRDdBJ7gKXxA jtNqAQDxqJpjWkzn4yN9CNSs1ivVx3fr6SqazlYCrt3u89WQvwEA1oRrGpETzUGq r6khQUIcQImPPcjFqEFpuiSOU0MBZA0= =Kii8 -----END PGP SIGNATURE----- Merge tag 'mm-nonmm-stable-2025-03-30-18-23' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull non-MM updates from Andrew Morton: - The series "powerpc/crash: use generic crashkernel reservation" from Sourabh Jain changes powerpc's kexec code to use more of the generic layers. - The series "get_maintainer: report subsystem status separately" from Vlastimil Babka makes some long-requested improvements to the get_maintainer output. - The series "ucount: Simplify refcounting with rcuref_t" from Sebastian Siewior cleans up and optimizing the refcounting in the ucount code. - The series "reboot: support runtime configuration of emergency hw_protection action" from Ahmad Fatoum improves the ability for a driver to perform an emergency system shutdown or reboot. - The series "Converge on using secs_to_jiffies() part two" from Easwar Hariharan performs further migrations from msecs_to_jiffies() to secs_to_jiffies(). - The series "lib/interval_tree: add some test cases and cleanup" from Wei Yang permits more userspace testing of kernel library code, adds some more tests and performs some cleanups. - The series "hung_task: Dump the blocking task stacktrace" from Masami Hiramatsu arranges for the hung_task detector to dump the stack of the blocking task and not just that of the blocked task. - The series "resource: Split and use DEFINE_RES*() macros" from Andy Shevchenko provides some cleanups to the resource definition macros. - Plus the usual shower of singleton patches - please see the individual changelogs for details. * tag 'mm-nonmm-stable-2025-03-30-18-23' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (77 commits) mailmap: consolidate email addresses of Alexander Sverdlin fs/procfs: fix the comment above proc_pid_wchan() relay: use kasprintf() instead of fixed buffer formatting resource: replace open coded variant of DEFINE_RES() resource: replace open coded variants of DEFINE_RES_*_NAMED() resource: replace open coded variant of DEFINE_RES_NAMED_DESC() resource: split DEFINE_RES_NAMED_DESC() out of DEFINE_RES_NAMED() samples: add hung_task detector mutex blocking sample hung_task: show the blocker task if the task is hung on mutex kexec_core: accept unaccepted kexec segments' destination addresses watchdog/perf: optimize bytes copied and remove manual NUL-termination lib/interval_tree: fix the comment of interval_tree_span_iter_next_gap() lib/interval_tree: skip the check before go to the right subtree lib/interval_tree: add test case for span iteration lib/interval_tree: add test case for interval_tree_iter_xxx() helpers lib/rbtree: add random seed lib/rbtree: split tests lib/rbtree: enable userland test suite for rbtree related data structure checkpatch: describe --min-conf-desc-length scripts/gdb/symbols: determine KASLR offset on s390 ...
		
			
				
	
	
		
			227 lines
		
	
	
	
		
			6.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			227 lines
		
	
	
	
		
			6.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #
 | |
| # gdb helper commands and functions for Linux kernel debugging
 | |
| #
 | |
| #  per-cpu tools
 | |
| #
 | |
| # Copyright (c) Siemens AG, 2011-2013
 | |
| #
 | |
| # Authors:
 | |
| #  Jan Kiszka <jan.kiszka@siemens.com>
 | |
| #
 | |
| # This work is licensed under the terms of the GNU GPL version 2.
 | |
| #
 | |
| 
 | |
| import gdb
 | |
| 
 | |
| from linux import tasks, utils
 | |
| 
 | |
| 
 | |
| task_type = utils.CachedType("struct task_struct")
 | |
| 
 | |
| 
 | |
| MAX_CPUS = 4096
 | |
| 
 | |
| 
 | |
| def get_current_cpu():
 | |
|     if utils.get_gdbserver_type() == utils.GDBSERVER_QEMU:
 | |
|         return gdb.selected_thread().num - 1
 | |
|     elif utils.get_gdbserver_type() == utils.GDBSERVER_KGDB:
 | |
|         return gdb.parse_and_eval("kgdb_active.counter")
 | |
|     else:
 | |
|         raise gdb.GdbError("Sorry, obtaining the current CPU is not yet "
 | |
|                            "supported with this gdb server.")
 | |
| 
 | |
| 
 | |
| def per_cpu(var_ptr, cpu):
 | |
|     if cpu == -1:
 | |
|         cpu = get_current_cpu()
 | |
|     if utils.is_target_arch("sparc:v9"):
 | |
|         offset = gdb.parse_and_eval(
 | |
|             "trap_block[{0}].__per_cpu_base".format(str(cpu)))
 | |
|     else:
 | |
|         try:
 | |
|             offset = gdb.parse_and_eval(
 | |
|                 "__per_cpu_offset[{0}]".format(str(cpu)))
 | |
|         except gdb.error:
 | |
|             # !CONFIG_SMP case
 | |
|             offset = 0
 | |
|     pointer = var_ptr.cast(utils.get_long_type()) + offset
 | |
|     return pointer.cast(var_ptr.type)
 | |
| 
 | |
| 
 | |
| cpu_mask = {}
 | |
| 
 | |
| 
 | |
| def cpu_mask_invalidate(event):
 | |
|     global cpu_mask
 | |
|     cpu_mask = {}
 | |
|     gdb.events.stop.disconnect(cpu_mask_invalidate)
 | |
|     if hasattr(gdb.events, 'new_objfile'):
 | |
|         gdb.events.new_objfile.disconnect(cpu_mask_invalidate)
 | |
| 
 | |
| 
 | |
| def cpu_list(mask_name):
 | |
|     global cpu_mask
 | |
|     mask = None
 | |
|     if mask_name in cpu_mask:
 | |
|         mask = cpu_mask[mask_name]
 | |
|     if mask is None:
 | |
|         mask = gdb.parse_and_eval(mask_name + ".bits")
 | |
|         if hasattr(gdb, 'events'):
 | |
|             cpu_mask[mask_name] = mask
 | |
|             gdb.events.stop.connect(cpu_mask_invalidate)
 | |
|             if hasattr(gdb.events, 'new_objfile'):
 | |
|                 gdb.events.new_objfile.connect(cpu_mask_invalidate)
 | |
|     bits_per_entry = mask[0].type.sizeof * 8
 | |
|     num_entries = mask.type.sizeof * 8 / bits_per_entry
 | |
|     entry = -1
 | |
|     bits = 0
 | |
| 
 | |
|     while True:
 | |
|         while bits == 0:
 | |
|             entry += 1
 | |
|             if entry == num_entries:
 | |
|                 return
 | |
|             bits = mask[entry]
 | |
|             if bits != 0:
 | |
|                 bit = 0
 | |
|                 break
 | |
| 
 | |
|         while bits & 1 == 0:
 | |
|             bits >>= 1
 | |
|             bit += 1
 | |
| 
 | |
|         cpu = entry * bits_per_entry + bit
 | |
| 
 | |
|         bits >>= 1
 | |
|         bit += 1
 | |
| 
 | |
|         yield int(cpu)
 | |
| 
 | |
| 
 | |
| def each_online_cpu():
 | |
|     for cpu in cpu_list("__cpu_online_mask"):
 | |
|         yield cpu
 | |
| 
 | |
| 
 | |
| def each_present_cpu():
 | |
|     for cpu in cpu_list("__cpu_present_mask"):
 | |
|         yield cpu
 | |
| 
 | |
| 
 | |
| def each_possible_cpu():
 | |
|     for cpu in cpu_list("__cpu_possible_mask"):
 | |
|         yield cpu
 | |
| 
 | |
| 
 | |
| def each_active_cpu():
 | |
|     for cpu in cpu_list("__cpu_active_mask"):
 | |
|         yield cpu
 | |
| 
 | |
| 
 | |
| class LxCpus(gdb.Command):
 | |
|     """List CPU status arrays
 | |
| 
 | |
| Displays the known state of each CPU based on the kernel masks
 | |
| and can help identify the state of hotplugged CPUs"""
 | |
| 
 | |
|     def __init__(self):
 | |
|         super(LxCpus, self).__init__("lx-cpus", gdb.COMMAND_DATA)
 | |
| 
 | |
|     def invoke(self, arg, from_tty):
 | |
|         gdb.write("Possible CPUs : {}\n".format(list(each_possible_cpu())))
 | |
|         gdb.write("Present CPUs  : {}\n".format(list(each_present_cpu())))
 | |
|         gdb.write("Online CPUs   : {}\n".format(list(each_online_cpu())))
 | |
|         gdb.write("Active CPUs   : {}\n".format(list(each_active_cpu())))
 | |
| 
 | |
| 
 | |
| LxCpus()
 | |
| 
 | |
| 
 | |
| class PerCpu(gdb.Function):
 | |
|     """Return per-cpu variable.
 | |
| 
 | |
| $lx_per_cpu("VAR"[, CPU]): Return the per-cpu variable called VAR for the
 | |
| given CPU number. If CPU is omitted, the CPU of the current context is used.
 | |
| Note that VAR has to be quoted as string."""
 | |
| 
 | |
|     def __init__(self):
 | |
|         super(PerCpu, self).__init__("lx_per_cpu")
 | |
| 
 | |
|     def invoke(self, var, cpu=-1):
 | |
|         return per_cpu(var.address, cpu).dereference()
 | |
| 
 | |
| 
 | |
| PerCpu()
 | |
| 
 | |
| 
 | |
| class PerCpuPtr(gdb.Function):
 | |
|     """Return per-cpu pointer.
 | |
| 
 | |
| $lx_per_cpu_ptr("VAR"[, CPU]): Return the per-cpu pointer called VAR for the
 | |
| given CPU number. If CPU is omitted, the CPU of the current context is used.
 | |
| Note that VAR has to be quoted as string."""
 | |
| 
 | |
|     def __init__(self):
 | |
|         super(PerCpuPtr, self).__init__("lx_per_cpu_ptr")
 | |
| 
 | |
|     def invoke(self, var, cpu=-1):
 | |
|         return per_cpu(var, cpu)
 | |
| 
 | |
| 
 | |
| PerCpuPtr()
 | |
| 
 | |
| 
 | |
| def get_current_task(cpu):
 | |
|     task_ptr_type = task_type.get_type().pointer()
 | |
| 
 | |
|     if utils.is_target_arch("x86"):
 | |
|         if gdb.lookup_global_symbol("cpu_tasks"):
 | |
|             # This is a UML kernel, which stores the current task
 | |
|             # differently than other x86 sub architectures
 | |
|             var_ptr = gdb.parse_and_eval("(struct task_struct *)cpu_tasks[0].task")
 | |
|             return var_ptr.dereference()
 | |
|         else:
 | |
|             var_ptr = gdb.parse_and_eval("¤t_task")
 | |
|             return per_cpu(var_ptr, cpu).dereference()
 | |
|     elif utils.is_target_arch("aarch64"):
 | |
|         current_task_addr = gdb.parse_and_eval("(unsigned long)$SP_EL0")
 | |
|         if (current_task_addr >> 63) != 0:
 | |
|             current_task = current_task_addr.cast(task_ptr_type)
 | |
|             return current_task.dereference()
 | |
|         else:
 | |
|             raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
 | |
|                                "while running in userspace(EL0)")
 | |
|     elif utils.is_target_arch("riscv"):
 | |
|         current_tp = gdb.parse_and_eval("$tp")
 | |
|         scratch_reg = gdb.parse_and_eval("$sscratch")
 | |
| 
 | |
|         # by default tp points to current task
 | |
|         current_task = current_tp.cast(task_ptr_type)
 | |
| 
 | |
|         # scratch register is set 0 in trap handler after entering kernel.
 | |
|         # When hart is in user mode, scratch register is pointing to task_struct.
 | |
|         # and tp is used by user mode. So when scratch register holds larger value
 | |
|         # (negative address as ulong is larger value) than tp, then use scratch register.
 | |
|         if (scratch_reg.cast(utils.get_ulong_type()) > current_tp.cast(utils.get_ulong_type())):
 | |
|             current_task = scratch_reg.cast(task_ptr_type)
 | |
| 
 | |
|         return current_task.dereference()
 | |
|     else:
 | |
|         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
 | |
|                            "supported with this arch")
 | |
| 
 | |
| class LxCurrentFunc(gdb.Function):
 | |
|     """Return current task.
 | |
| 
 | |
| $lx_current([CPU]): Return the per-cpu task variable for the given CPU
 | |
| number. If CPU is omitted, the CPU of the current context is used."""
 | |
| 
 | |
|     def __init__(self):
 | |
|         super(LxCurrentFunc, self).__init__("lx_current")
 | |
| 
 | |
|     def invoke(self, cpu=-1):
 | |
|         return get_current_task(cpu)
 | |
| 
 | |
| 
 | |
| LxCurrentFunc()
 |