Skip to contentSkip to conversation

scripts/gdb: add lx_current support for riscv

PATCH RESEND In review Song Shuai 2 participants 3 messages Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore

Song Shuai

author
#0 lore raw

PATCH RESEND 1/1 scripts/gdb: add lx_current support for riscv

RISC-V uses the tp register to save the current task_struct address as its current() defines. So lx_current() of riscv just returns the dereference of the address cast via task_ptr_type.

---
 scripts/gdb/linux/cpus.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/gdb/linux/cpus.py +3 -0
index 15fc4626d236..6825a9834394 100644
@@ -173,6 +173,9 @@ def get_current_task(cpu):
          else:
              raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
                                 "while running in userspace(EL0)")
+    elif utils.is_target_arch("riscv"):
+         current_task_addr = gdb.parse_and_eval("$tp")
+         return current_task_addr.cast(task_ptr_type).dereference()
     else:
         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
                            "supported with this arch")
Signature · 1 line
2.20.1
#1 lore raw

Hey Song

Quoted 3 lines · Song Shuai

RISC-V uses the tp register to save the current task_struct address as its current() defines. So lx_current() of riscv just returns the dereference of the address cast via task_ptr_type.

FYI, there's already been some patches posted for this:
https://lore.kernel.org/all/mhng-bdcd75a5-e6d6-4090-8292-a32eb46e4464@palmer-ri-x1c9a/

That version already has review and ack tags from Palmer and others. It seems to me that Andrew is the usual applier of patches for this script, so I'm gonna add him to CC here so he is aware - but as it is the middle of the merge window the best course of action might just be reposting that patch, CCing Andrew, after v6.3-rc1.

Cheers,
Conor.

Quoted 24 lines
---
 scripts/gdb/linux/cpus.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/gdb/linux/cpus.py +3 -0
index 15fc4626d236..6825a9834394 100644
@@ -173,6 +173,9 @@ def get_current_task(cpu):
          else:
              raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
                                 "while running in userspace(EL0)")
+    elif utils.is_target_arch("riscv"):
+         current_task_addr = gdb.parse_and_eval("$tp")
+         return current_task_addr.cast(task_ptr_type).dereference()
     else:
         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
                            "supported with this arch")
Signature · 1 line
2.20.1
author
#2 lore raw
Quoted 11 lines · Conor Dooley <[email protected]> 于2023年2月22日周三 09:53写道:

Hey Song

Quoted 3 lines · Song Shuai

RISC-V uses the tp register to save the current task_struct address as its current() defines. So lx_current() of riscv just returns the dereference of the address cast via task_ptr_type.

FYI, there's already been some patches posted for this:
https://lore.kernel.org/all/mhng-bdcd75a5-e6d6-4090-8292-a32eb46e4464@palmer-ri-x1c9a/

Deepak's patch is much better than mine, which also takes the userspace and trap handler into count.
So no need to care about this patch.

Quoted 33 lines

That version already has review and ack tags from Palmer and others. It seems to me that Andrew is the usual applier of patches for this script, so I'm gonna add him to CC here so he is aware - but as it is the middle of the merge window the best course of action might just be reposting that patch, CCing Andrew, after v6.3-rc1.

Cheers,
Conor.

Quoted 24 lines
---
 scripts/gdb/linux/cpus.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/gdb/linux/cpus.py +3 -1
index 15fc4626d236..6825a9834394 100644
@@ -173,6 +173,9 @@ def get_current_task(cpu):
          else:
              raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
                                 "while running in userspace(EL0)")
+    elif utils.is_target_arch("riscv"):
+         current_task_addr = gdb.parse_and_eval("$tp")
+         return current_task_addr.cast(task_ptr_type).dereference()
     else:
         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
                            "supported with this arch")
--

2.20.1

Signature · 2 lines
Thanks,
Song