[PATCH v2 0/2] GDB: Support getting current task struct in UML

Glenn Washburn posted 2 patches 2 years, 6 months ago
There is a newer version of this series
scripts/gdb/linux/cpus.py | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
[PATCH v2 0/2] GDB: Support getting current task struct in UML
Posted by Glenn Washburn 2 years, 6 months ago
Added suggestions from Jan.

Glenn

Glenn Washburn (2):
  scripts/gdb: Correct indentation in get_current_task
  scripts/gdb: Support getting current task struct in UML

 scripts/gdb/linux/cpus.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Range-diff against v1:
1:  f33ebe524590 ! 1:  c5a916e094d9 scripts/gdb: Correct indentation in get_current_task
    @@ Commit message
     
         There is an extra space in a couple blocks in get_current_task.
         Though python does not care, let's make the spacing consistent.
    +    Also, format better an if expression, removing unneeded parenthesis.
     
      ## scripts/gdb/linux/cpus.py ##
     @@ scripts/gdb/linux/cpus.py: def get_current_task(cpu):
    @@ scripts/gdb/linux/cpus.py: def get_current_task(cpu):
     -             raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
     -                                "while running in userspace(EL0)")
     +        current_task_addr = gdb.parse_and_eval("$SP_EL0")
    -+        if((current_task_addr >> 63) != 0):
    ++        if (current_task_addr >> 63) != 0:
     +            current_task = current_task_addr.cast(task_ptr_type)
     +            return current_task.dereference()
     +        else:
2:  8c3db2291f58 ! 2:  683d10e752cd scripts/gdb: Support getting current task struct in UML
    @@ Commit message
         A running x86 UML kernel reports with architecture "i386:x86-64" as
         it is a sub-architecture. However, a difference with bare-metal x86
         kernels is in how it manages tasks and the current task struct. To
    -    identify that the inferior is a UML kernel and not bare-metal, the
    -    symbol "uml_kmalloc" is checked for. If it exists, then do the UML
    -    specific way of getting the current task struct.
    +    identify that the inferior is a UML kernel and not bare-metal, check
    +    for the existence of the UML specific symbol "cpu_tasks" which
    +    contains the current task struct.
     
      ## scripts/gdb/linux/cpus.py ##
     @@ scripts/gdb/linux/cpus.py: def get_current_task(cpu):
    @@ scripts/gdb/linux/cpus.py: def get_current_task(cpu):
          if utils.is_target_arch("x86"):
     -        var_ptr = gdb.parse_and_eval("&current_task")
     -        return per_cpu(var_ptr, cpu).dereference()
    -+        if gdb.lookup_global_symbol("uml_kmalloc"):
    ++        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:
    @@ scripts/gdb/linux/cpus.py: def get_current_task(cpu):
     +            return per_cpu(var_ptr, cpu).dereference()
          elif utils.is_target_arch("aarch64"):
              current_task_addr = gdb.parse_and_eval("$SP_EL0")
    -         if((current_task_addr >> 63) != 0):
    +         if (current_task_addr >> 63) != 0:
-- 
2.30.2
Re: [PATCH v2 0/2] GDB: Support getting current task struct in UML
Posted by Andrew Morton 2 years, 6 months ago
On Fri, 17 Feb 2023 19:11:52 -0600 Glenn Washburn <development@efficientek.com> wrote:

> Added suggestions from Jan.
> 
> Glenn
> 
> Glenn Washburn (2):
>   scripts/gdb: Correct indentation in get_current_task
>   scripts/gdb: Support getting current task struct in UML
> 

For some reason I get a bunch of rejects when applying these on top of
the latest patchpile.  Please check my end result:

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("&current_task")
            return per_cpu(var_ptr, cpu).dereference()
    elif utils.is_target_arch("aarch64"):
        current_task_addr = gdb.parse_and_eval("$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)")
    else:
        raise gdb.GdbError("Sorry, obtaining the current task is not yet "
                           "supported with this arch")
Re: [PATCH v2 0/2] GDB: Support getting current task struct in UML
Posted by Glenn Washburn 2 years, 6 months ago
On Thu, 23 Feb 2023 13:14:02 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Fri, 17 Feb 2023 19:11:52 -0600 Glenn Washburn
> <development@efficientek.com> wrote:
> 
> > Added suggestions from Jan.
> > 
> > Glenn
> > 
> > Glenn Washburn (2):
> >   scripts/gdb: Correct indentation in get_current_task
> >   scripts/gdb: Support getting current task struct in UML
> > 
> 
> For some reason I get a bunch of rejects when applying these on top of
> the latest patchpile.  Please check my end result:

It looks like there was a change from v6.2-rc8 to v6.2 that caused a
conflict.

> 
> 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()

This is missing the return statement in the second patch.

>         else:
>             var_ptr = gdb.parse_and_eval("&current_task")

It looks like "current_task" has now been changed to
"pcpu_hot.current_task" in v6.2.

Would you like me to resent the series rebased onto v6.2?

Glenn

>             return per_cpu(var_ptr, cpu).dereference()
>     elif utils.is_target_arch("aarch64"):
>         current_task_addr = gdb.parse_and_eval("$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)")
>     else:
>         raise gdb.GdbError("Sorry, obtaining the current task is not
> yet " "supported with this arch")
> 
> 
>
Re: [PATCH v2 0/2] GDB: Support getting current task struct in UML
Posted by Andrew Morton 2 years, 6 months ago
On Sun, 26 Feb 2023 00:47:19 -0600 Glenn Washburn <development@efficientek.com> wrote:

> Would you like me to resent the series rebased onto v6.2?

Yes please ;)  Against current linus tip if possible.