All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] GDB: Support getting current task struct in UML
@ 2023-02-14 23:35 Glenn Washburn
  2023-02-14 23:35 ` [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task Glenn Washburn
  2023-02-14 23:35 ` [PATCH 2/2] scripts/gdb: Support getting current task struct in UML Glenn Washburn
  0 siblings, 2 replies; 7+ messages in thread
From: Glenn Washburn @ 2023-02-14 23:35 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham
  Cc: Glenn Washburn, linux-um, Richard Weinberger, Johannes Berg,
	Anton Ivanov

Hi all,

I noticed that running "call $lx_current()" with the kernel GDB helper
scripts was crashing when running in UML. So, I've fixed this. I'm not
100% sure this is correct or covers all corner cases, but I've done some
minimal testing. Perhaps someone on the linux-um list can review/comment
on whether this looks good or not.

There's also a trivial indentation fix in the same area.

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 | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task
  2023-02-14 23:35 [PATCH 0/2] GDB: Support getting current task struct in UML Glenn Washburn
@ 2023-02-14 23:35 ` Glenn Washburn
  2023-02-15  7:44   ` Jan Kiszka
  2023-02-14 23:35 ` [PATCH 2/2] scripts/gdb: Support getting current task struct in UML Glenn Washburn
  1 sibling, 1 reply; 7+ messages in thread
From: Glenn Washburn @ 2023-02-14 23:35 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham
  Cc: Glenn Washburn, linux-um, Richard Weinberger, Johannes Berg,
	Anton Ivanov

There is an extra space in a couple blocks in get_current_task.
Though python does not care, let's make the spacing consistent.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 scripts/gdb/linux/cpus.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 15fc4626d236..289f0bf4d2a1 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -163,16 +163,16 @@ def get_current_task(cpu):
     task_ptr_type = task_type.get_type().pointer()
 
     if utils.is_target_arch("x86"):
-         var_ptr = gdb.parse_and_eval("&current_task")
-         return per_cpu(var_ptr, cpu).dereference()
+        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)")
+        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")
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] scripts/gdb: Support getting current task struct in UML
  2023-02-14 23:35 [PATCH 0/2] GDB: Support getting current task struct in UML Glenn Washburn
  2023-02-14 23:35 ` [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task Glenn Washburn
@ 2023-02-14 23:35 ` Glenn Washburn
  2023-02-15  7:45   ` Jan Kiszka
  1 sibling, 1 reply; 7+ messages in thread
From: Glenn Washburn @ 2023-02-14 23:35 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham
  Cc: Glenn Washburn, linux-um, Richard Weinberger, Johannes Berg,
	Anton Ivanov

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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 scripts/gdb/linux/cpus.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 289f0bf4d2a1..90908653f6c7 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -163,8 +163,12 @@ def get_current_task(cpu):
     task_ptr_type = task_type.get_type().pointer()
 
     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"):
+            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):
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task
  2023-02-14 23:35 ` [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task Glenn Washburn
@ 2023-02-15  7:44   ` Jan Kiszka
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kiszka @ 2023-02-15  7:44 UTC (permalink / raw)
  To: Glenn Washburn, Kieran Bingham
  Cc: linux-um, Richard Weinberger, Johannes Berg, Anton Ivanov

On 15.02.23 00:35, Glenn Washburn wrote:
> There is an extra space in a couple blocks in get_current_task.
> Though python does not care, let's make the spacing consistent.
> 
> Signed-off-by: Glenn Washburn <development@efficientek.com>
> ---
>  scripts/gdb/linux/cpus.py | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
> index 15fc4626d236..289f0bf4d2a1 100644
> --- a/scripts/gdb/linux/cpus.py
> +++ b/scripts/gdb/linux/cpus.py
> @@ -163,16 +163,16 @@ def get_current_task(cpu):
>      task_ptr_type = task_type.get_type().pointer()
>  
>      if utils.is_target_arch("x86"):
> -         var_ptr = gdb.parse_and_eval("&current_task")
> -         return per_cpu(var_ptr, cpu).dereference()
> +        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)")
> +        current_task_addr = gdb.parse_and_eval("$SP_EL0")
> +        if((current_task_addr >> 63) != 0):

At this chance: "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")

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] scripts/gdb: Support getting current task struct in UML
  2023-02-14 23:35 ` [PATCH 2/2] scripts/gdb: Support getting current task struct in UML Glenn Washburn
@ 2023-02-15  7:45   ` Jan Kiszka
  2023-02-15 15:55     ` Glenn Washburn
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kiszka @ 2023-02-15  7:45 UTC (permalink / raw)
  To: Glenn Washburn, Kieran Bingham
  Cc: linux-um, Richard Weinberger, Johannes Berg, Anton Ivanov

On 15.02.23 00:35, Glenn Washburn wrote:
> 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.
> 
> Signed-off-by: Glenn Washburn <development@efficientek.com>
> ---
>  scripts/gdb/linux/cpus.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
> index 289f0bf4d2a1..90908653f6c7 100644
> --- a/scripts/gdb/linux/cpus.py
> +++ b/scripts/gdb/linux/cpus.py
> @@ -163,8 +163,12 @@ def get_current_task(cpu):
>      task_ptr_type = task_type.get_type().pointer()
>  
>      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"):
> +            var_ptr = gdb.parse_and_eval("(struct task_struct *)cpu_tasks[0].task")

Can't we use an UML indicator that is related to the topic? Why not
cpu_tasks itself?

> +            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):

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] scripts/gdb: Support getting current task struct in UML
  2023-02-15  7:45   ` Jan Kiszka
@ 2023-02-15 15:55     ` Glenn Washburn
  2023-02-15 16:04       ` Jan Kiszka
  0 siblings, 1 reply; 7+ messages in thread
From: Glenn Washburn @ 2023-02-15 15:55 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Kieran Bingham, linux-um, Richard Weinberger, Johannes Berg,
	Anton Ivanov

On Wed, 15 Feb 2023 08:45:20 +0100
Jan Kiszka <jan.kiszka@siemens.com> wrote:

> On 15.02.23 00:35, Glenn Washburn wrote:
> > 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.
> > 
> > Signed-off-by: Glenn Washburn <development@efficientek.com>
> > ---
> >  scripts/gdb/linux/cpus.py | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
> > index 289f0bf4d2a1..90908653f6c7 100644
> > --- a/scripts/gdb/linux/cpus.py
> > +++ b/scripts/gdb/linux/cpus.py
> > @@ -163,8 +163,12 @@ def get_current_task(cpu):
> >      task_ptr_type = task_type.get_type().pointer()
> >  
> >      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"):
> > +            var_ptr = gdb.parse_and_eval("(struct task_struct
> > *)cpu_tasks[0].task")
> 
> Can't we use an UML indicator that is related to the topic? Why not
> cpu_tasks itself?

Yes, I like that idea, and makes a lot of sense seeing as then we're
sure cpu_tasks exists right before using it. The one thing that I like
about using a symbol with a "uml_" prefix is that it makes it obvious
that this branch is for UML kernels. I ultimately decided against a
comment because using uml_kmalloc seemed self-documenting. Do you think
a comment is warranted if I make the suggested change?

Glenn

> > +            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):
> 
> Jan
> 

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] scripts/gdb: Support getting current task struct in UML
  2023-02-15 15:55     ` Glenn Washburn
@ 2023-02-15 16:04       ` Jan Kiszka
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kiszka @ 2023-02-15 16:04 UTC (permalink / raw)
  To: development
  Cc: Kieran Bingham, linux-um, Richard Weinberger, Johannes Berg,
	Anton Ivanov

On 15.02.23 16:55, Glenn Washburn wrote:
> On Wed, 15 Feb 2023 08:45:20 +0100
> Jan Kiszka <jan.kiszka@siemens.com> wrote:
> 
>> On 15.02.23 00:35, Glenn Washburn wrote:
>>> 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.
>>>
>>> Signed-off-by: Glenn Washburn <development@efficientek.com>
>>> ---
>>>  scripts/gdb/linux/cpus.py | 8 ++++++--
>>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
>>> index 289f0bf4d2a1..90908653f6c7 100644
>>> --- a/scripts/gdb/linux/cpus.py
>>> +++ b/scripts/gdb/linux/cpus.py
>>> @@ -163,8 +163,12 @@ def get_current_task(cpu):
>>>      task_ptr_type = task_type.get_type().pointer()
>>>  
>>>      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"):
>>> +            var_ptr = gdb.parse_and_eval("(struct task_struct
>>> *)cpu_tasks[0].task")
>>
>> Can't we use an UML indicator that is related to the topic? Why not
>> cpu_tasks itself?
> 
> Yes, I like that idea, and makes a lot of sense seeing as then we're
> sure cpu_tasks exists right before using it. The one thing that I like
> about using a symbol with a "uml_" prefix is that it makes it obvious
> that this branch is for UML kernels. I ultimately decided against a
> comment because using uml_kmalloc seemed self-documenting. Do you think
> a comment is warranted if I make the suggested change?

"uml" is clear, "kmalloc" is not so much again. No perfect fit, but I
would leave a commit in any case.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-15 16:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 23:35 [PATCH 0/2] GDB: Support getting current task struct in UML Glenn Washburn
2023-02-14 23:35 ` [PATCH 1/2] scripts/gdb: Correct indentation in get_current_task Glenn Washburn
2023-02-15  7:44   ` Jan Kiszka
2023-02-14 23:35 ` [PATCH 2/2] scripts/gdb: Support getting current task struct in UML Glenn Washburn
2023-02-15  7:45   ` Jan Kiszka
2023-02-15 15:55     ` Glenn Washburn
2023-02-15 16:04       ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.