[PATCH 0/3] aarch64: add some core note types name

2024-08-14 Thread Kuan-Ying Lee
Patch 1:
 - Add MTE related regset in core note
Patch 2:
 - Add PAC related regset in core note
Patch 3:
 - Add some core note types name

Kuan-Ying Lee (3):
  aarch64: Add NT_ARM_TAGGED_ADDR_CTRL regset
  aarch64: Add NT_ARM_PAC_* regset
  aarch64: add some new core note types name

 backends/aarch64_corenote.c  | 33 -
 libebl/eblcorenotetypename.c |  6 ++
 libelf/elf.h |  2 ++
 3 files changed, 40 insertions(+), 1 deletion(-)

-- 
2.43.0



[PATCH 2/3] aarch64: Add NT_ARM_PAC_* regset

2024-08-14 Thread Kuan-Ying Lee
Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
Recognize and print the new core item.

Signed-off-by: Kuan-Ying Lee 
---
 backends/aarch64_corenote.c  | 24 +++-
 libebl/eblcorenotetypename.c |  2 ++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
index bd0a4a725411..35c8e8012c7b 100644
--- a/backends/aarch64_corenote.c
+++ b/backends/aarch64_corenote.c
@@ -115,6 +115,26 @@ static const Ebl_Core_Item aarch64_mte_items [] =
 }
   };
 
+static const Ebl_Core_Item aarch64_pac_enabled_items [] =
+  {
+{
+  .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
+  .offset = 0, .group = "register"
+}
+  };
+
+static const Ebl_Core_Item aarch64_pac_mask_items [] =
+  {
+{
+  .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
+  .offset = 0, .group = "register"
+},
+{
+  .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
+  .offset = 8, .group = "register"
+}
+  };
+
 #define AARCH64_HWBP_REG(KIND, N)  \
 {  \
   .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
@@ -176,6 +196,8 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
   EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)  \
   EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)  \
   EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
-  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
+  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
+  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
+  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
 
 #include "linux-core-note.c"
diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
index 49331bdf76e8..3e2f8daa0fd5 100644
--- a/libebl/eblcorenotetypename.c
+++ b/libebl/eblcorenotetypename.c
@@ -93,6 +93,8 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, 
size_t len)
KNOWNSTYPE (ARM_HW_WATCH);
KNOWNSTYPE (ARM_SYSTEM_CALL);
KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
+   KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
+   KNOWNSTYPE (ARM_PAC_MASK);
KNOWNSTYPE (SIGINFO);
KNOWNSTYPE (FILE);
 #undef KNOWNSTYPE
-- 
2.43.0



[PATCH 3/3] aarch64: add some new core note types name

2024-08-14 Thread Kuan-Ying Lee
Recognize names of some new core note types in ebl_core_note_type_name.

Signed-off-by: Kuan-Ying Lee 
---
 libebl/eblcorenotetypename.c | 3 +++
 libelf/elf.h | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
index 3e2f8daa0fd5..18114eb9d0da 100644
--- a/libebl/eblcorenotetypename.c
+++ b/libebl/eblcorenotetypename.c
@@ -95,6 +95,9 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, 
size_t len)
KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
KNOWNSTYPE (ARM_PAC_MASK);
+   KNOWNSTYPE (ARM_SVE);
+   KNOWNSTYPE (ARM_SSVE);
+   KNOWNSTYPE (ARM_ZA);
KNOWNSTYPE (SIGINFO);
KNOWNSTYPE (FILE);
 #undef KNOWNSTYPE
diff --git a/libelf/elf.h b/libelf/elf.h
index 081742a9c38c..b17f4fdea070 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -831,6 +831,8 @@ typedef struct
   control.  */
 #define NT_ARM_PAC_ENABLED_KEYS0x40a   /* AArch64 pointer 
authentication
   enabled keys.  */
+#define NT_ARM_SSVE0x40b   /* ARM Streaming SVE registers */
+#define NT_ARM_ZA  0x40c   /* ARM SME ZA registers */
 #define NT_VMCOREDD0x700   /* Vmcore Device Dump Note.  */
 #define NT_MIPS_DSP0x800   /* MIPS DSP ASE registers.  */
 #define NT_MIPS_FP_MODE0x801   /* MIPS floating-point mode.  */
-- 
2.43.0



[PATCH 1/3] aarch64: Add NT_ARM_TAGGED_ADDR_CTRL regset

2024-08-14 Thread Kuan-Ying Lee
Add the NT_ARM_TAGGED_ADDR_CTRL regset for aarch64.
Recognize and print this new core itme.

Signed-off-by: Kuan-Ying Lee 
---
 backends/aarch64_corenote.c  | 11 ++-
 libebl/eblcorenotetypename.c |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
index 905a4b8ab9f5..bd0a4a725411 100644
--- a/backends/aarch64_corenote.c
+++ b/backends/aarch64_corenote.c
@@ -107,6 +107,14 @@ static const Ebl_Core_Item aarch64_syscall_items [] =
 }
   };
 
+static const Ebl_Core_Item aarch64_mte_items [] =
+  {
+{
+  .name = "tag_ctrl", .type = ELF_T_XWORD, .format = 'x',
+  .offset = 0, .group = "register"
+}
+  };
+
 #define AARCH64_HWBP_REG(KIND, N)  \
 {  \
   .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
@@ -167,6 +175,7 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
   EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items)   \
   EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)  \
   EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)  \
-  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items)
+  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
+  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
 
 #include "linux-core-note.c"
diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
index 0e790d062de5..49331bdf76e8 100644
--- a/libebl/eblcorenotetypename.c
+++ b/libebl/eblcorenotetypename.c
@@ -92,6 +92,7 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, 
size_t len)
KNOWNSTYPE (ARM_HW_BREAK);
KNOWNSTYPE (ARM_HW_WATCH);
KNOWNSTYPE (ARM_SYSTEM_CALL);
+   KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
KNOWNSTYPE (SIGINFO);
KNOWNSTYPE (FILE);
 #undef KNOWNSTYPE
-- 
2.43.0



Re: [PATCH 0/3] aarch64: add some core note types name

2024-08-19 Thread Kuan-Ying Lee
On Sat, Aug 17, 2024 at 12:47:03AM +0200, Mark Wielaard wrote:
> Hi,
> 
> On Wed, Aug 14, 2024 at 04:51:17PM +0800, Kuan-Ying Lee wrote:
> > Patch 1:
> >  - Add MTE related regset in core note
> > Patch 2:
> >  - Add PAC related regset in core note
> > Patch 3:
> >  - Add some core note types name
> 
> This look good. Thanks.  For elf.h we try to keep it in sync with the
> glibc elf/elf.h.  Since they recently added the same (and more)
> NT_ARM_* constants I'll sync that file seperately before incorporating
> your patch.
> 
> Did you test the output on a core file that has these new regsets and
> core notes with eu-readelf to see if it looks correct?
> 

Thank you for the review.

Yes, I have tested the output on a core file that has these new regsets.

Output is as following:
...
  LINUX544  ARM_SVE
  LINUX544  ARM_SSVE
  LINUX 16  ARM_ZA
  LINUX 16  ARM_PAC_MASK
pauth_dmask: 0x007f8000, pauth_cmask: 0x007f8000
  LINUX  8  ARM_PAC_ENABLED_KEYS
enabled_keys: 0x000f
  LINUX      8  ARM_TAGGED_ADDR_CTRL
tag_ctrl: 0x0007fff3

Thank you,
Kuan-Ying Lee

> Thanks,
> 
> Mark


Re: [PATCH 2/3] aarch64: Add NT_ARM_PAC_* regset

2024-08-19 Thread Kuan-Ying Lee
On Sat, Aug 17, 2024 at 01:36:33AM +0200, Mark Wielaard wrote:
> Hi,
> 
> On Wed, Aug 14, 2024 at 04:51:19PM +0800, Kuan-Ying Lee wrote:
> > Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
> > Recognize and print the new core item.
> 
> For NT_ARM_PAC_MASK it looks like the user_pac_mask struct, so two 8
> byte words. But for NT_ARM_PAC_ENABLED_KEYS I cannot find the
> definition. This assumes it is just one 8 byte word. Is that correct?
> Can it be more than one?
> 

Hi Mark,

Thanks for your review.

I believe it should be exactly one 8-byte word in size.
I based this on the following code[1]:

 |  [REGSET_PAC_ENABLED_KEYS] = {
 |  .core_note_type = NT_ARM_PAC_ENABLED_KEYS,
 |  .n = 1,
 |  .size = sizeof(long),
 |  .align = sizeof(long),
 |  .regset_get = pac_enabled_keys_get,
 |  .set = pac_enabled_keys_set,

The size is sizeof(long), and n is 1.
It seems that there is only 1 8-byte word for arm64.

[1] 
https://elixir.bootlin.com/linux/v6.10.5/source/arch/arm64/kernel/ptrace.c#L1595

Thanks,
Kuan-Ying Lee

> Thanks,
> 
> Mark
> 
> > Signed-off-by: Kuan-Ying Lee 
> > ---
> >  backends/aarch64_corenote.c  | 24 +++-
> >  libebl/eblcorenotetypename.c |  2 ++
> >  2 files changed, 25 insertions(+), 1 deletion(-)
> > 
> > diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> > index bd0a4a725411..35c8e8012c7b 100644
> > --- a/backends/aarch64_corenote.c
> > +++ b/backends/aarch64_corenote.c
> > @@ -115,6 +115,26 @@ static const Ebl_Core_Item aarch64_mte_items [] =
> >  }
> >};
> >  
> > +static const Ebl_Core_Item aarch64_pac_enabled_items [] =
> > +  {
> > +{
> > +  .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
> > +  .offset = 0, .group = "register"
> > +}
> > +  };
> > +
> > +static const Ebl_Core_Item aarch64_pac_mask_items [] =
> > +  {
> > +{
> > +  .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
> > +  .offset = 0, .group = "register"
> > +},
> > +{
> > +  .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
> > +  .offset = 8, .group = "register"
> > +}
> > +  };
> > +
> >  #define AARCH64_HWBP_REG(KIND, N)  \
> >  {  
> > \
> >.name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 
> > 'x', \
> > @@ -176,6 +196,8 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
> >EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)  \
> >EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)  \
> >EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> > -  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
> > +  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
> > +  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
> > +  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
> >  
> >  #include "linux-core-note.c"
> > diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
> > index 49331bdf76e8..3e2f8daa0fd5 100644
> > --- a/libebl/eblcorenotetypename.c
> > +++ b/libebl/eblcorenotetypename.c
> > @@ -93,6 +93,8 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char 
> > *buf, size_t len)
> > KNOWNSTYPE (ARM_HW_WATCH);
> > KNOWNSTYPE (ARM_SYSTEM_CALL);
> > KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
> > +   KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
> > +   KNOWNSTYPE (ARM_PAC_MASK);
> > KNOWNSTYPE (SIGINFO);
> > KNOWNSTYPE (FILE);
> >  #undef KNOWNSTYPE
> > -- 
> > 2.43.0
> >