[PATCHv5,08/11] gdb/arch: assert that X86_XSTATE_MPX is not set for x32

Message ID 79e267edd3cdd68d87fef81d2a5fdf73b22b25be.1714143669.git.aburgess@redhat.com
State New
Headers
Series x86/Linux Target Description Changes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Andrew Burgess April 26, 2024, 3:01 p.m. UTC
  While rebasing this series past this commit:

  commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
  Date:   Wed Mar 20 04:13:18 2024 -0700

      gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32

I worried that there could be other paths that might result in an xcr0
value which has X86_XSTATE_MPX set in x32 mode.  As everyone
eventually calls amd64_create_target_description to build their target
description, I figured we could assert in here that if X86_XSTATE_MPX
is set then we should not be an x32 target, this will uncover any
other bugs in this area.

I'm not currently able to build/run any x32 binaries, so I have no way
to test this, but the author of commit 4bb20a6244b7091 did test this
series with that assert in place and didn't see any problems.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511
---
 gdb/arch/amd64.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Willgerodt, Felix April 29, 2024, 2:34 p.m. UTC | #1
> -----Original Message-----
> From: Andrew Burgess <aburgess@redhat.com>
> Sent: Freitag, 26. April 2024 17:02
> To: gdb-patches@sourceware.org
> Cc: Andrew Burgess <aburgess@redhat.com>; Willgerodt, Felix
> <felix.willgerodt@intel.com>; John Baldwin <jhb@FreeBSD.org>
> Subject: [PATCHv5 08/11] gdb/arch: assert that X86_XSTATE_MPX is not set for
> x32
> 
> While rebasing this series past this commit:
> 
>   commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
>   Date:   Wed Mar 20 04:13:18 2024 -0700
> 
>       gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
> 
> I worried that there could be other paths that might result in an xcr0
> value which has X86_XSTATE_MPX set in x32 mode.  As everyone
> eventually calls amd64_create_target_description to build their target
> description, I figured we could assert in here that if X86_XSTATE_MPX
> is set then we should not be an x32 target, this will uncover any
> other bugs in this area.
> 
> I'm not currently able to build/run any x32 binaries, so I have no way
> to test this, but the author of commit 4bb20a6244b7091 did test this
> series with that assert in place and didn't see any problems.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511
> ---
>  gdb/arch/amd64.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 

GDB was also checking this somewhere when I reviewed H.J.'s patch.
Though it doesn't hurt to have it here in my eyes.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Andrew Burgess May 7, 2024, 4:08 p.m. UTC | #2
"Willgerodt, Felix" <felix.willgerodt@intel.com> writes:

>> -----Original Message-----
>> From: Andrew Burgess <aburgess@redhat.com>
>> Sent: Freitag, 26. April 2024 17:02
>> To: gdb-patches@sourceware.org
>> Cc: Andrew Burgess <aburgess@redhat.com>; Willgerodt, Felix
>> <felix.willgerodt@intel.com>; John Baldwin <jhb@FreeBSD.org>
>> Subject: [PATCHv5 08/11] gdb/arch: assert that X86_XSTATE_MPX is not set for
>> x32
>> 
>> While rebasing this series past this commit:
>> 
>>   commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
>>   Date:   Wed Mar 20 04:13:18 2024 -0700
>> 
>>       gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
>> 
>> I worried that there could be other paths that might result in an xcr0
>> value which has X86_XSTATE_MPX set in x32 mode.  As everyone
>> eventually calls amd64_create_target_description to build their target
>> description, I figured we could assert in here that if X86_XSTATE_MPX
>> is set then we should not be an x32 target, this will uncover any
>> other bugs in this area.
>> 
>> I'm not currently able to build/run any x32 binaries, so I have no way
>> to test this, but the author of commit 4bb20a6244b7091 did test this
>> series with that assert in place and didn't see any problems.
>> 
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511
>> ---
>>  gdb/arch/amd64.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>
> GDB was also checking this somewhere when I reviewed H.J.'s patch.
> Though it doesn't hurt to have it here in my eyes.
>
> Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>

As this commit is only loosely tied to the rest of the series I've gone
ahead and pushed this to upstream.

Thanks,
Andrew
  

Patch

diff --git a/gdb/arch/amd64.c b/gdb/arch/amd64.c
index cb9683c6931..94d55d72a4e 100644
--- a/gdb/arch/amd64.c
+++ b/gdb/arch/amd64.c
@@ -65,8 +65,12 @@  amd64_create_target_description (uint64_t xcr0, bool is_x32, bool is_linux,
   if (xcr0 & X86_XSTATE_AVX)
     regnum = create_feature_i386_64bit_avx (tdesc.get (), regnum);
 
-  if ((xcr0 & X86_XSTATE_MPX) && !is_x32)
-    regnum = create_feature_i386_64bit_mpx (tdesc.get (), regnum);
+  if (xcr0 & X86_XSTATE_MPX)
+    {
+      /* MPX is not available on x32.  */
+      gdb_assert (!is_x32);
+      regnum = create_feature_i386_64bit_mpx (tdesc.get (), regnum);
+    }
 
   if (xcr0 & X86_XSTATE_AVX512)
     regnum = create_feature_i386_64bit_avx512 (tdesc.get (), regnum);