Message ID | 20210122110307.934543-2-arnd@kernel.org (mailing list archive) |
---|---|
State | Accepted |
Commit | 42b20995fae6318fd2e85ddbbaf7b4f7c3724e68 |
Headers | show |
Series | [1/2] MIPS: jazz: always allow little-endian builds | expand |
On Fri, Jan 22, 2021 at 12:02:51PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > kgdb fails to build when the FPU support is disabled: > > arch/mips/kernel/kgdb.c: In function 'dbg_set_reg': > arch/mips/kernel/kgdb.c:147:35: error: 'struct thread_struct' has no member named 'fpu' > 147 | memcpy((void *)¤t->thread.fpu.fcr31, mem, > | ^ > arch/mips/kernel/kgdb.c:155:34: error: 'struct thread_struct' has no member named 'fpu' > 155 | memcpy((void *)¤t->thread.fpu.fpr[fp_reg], mem, > > This is only relevant for CONFIG_EXPERT=y, so disallowing it > in Kconfig is an easier workaround than fixing it properly. > > Reported-by: kernel test robot <lkp@intel.com> > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > arch/mips/Kconfig | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) applied to mips-next. Thomas.
On Fri, 22 Jan 2021, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > kgdb fails to build when the FPU support is disabled: > > arch/mips/kernel/kgdb.c: In function 'dbg_set_reg': > arch/mips/kernel/kgdb.c:147:35: error: 'struct thread_struct' has no member named 'fpu' > 147 | memcpy((void *)¤t->thread.fpu.fcr31, mem, > | ^ > arch/mips/kernel/kgdb.c:155:34: error: 'struct thread_struct' has no member named 'fpu' > 155 | memcpy((void *)¤t->thread.fpu.fpr[fp_reg], mem, > > This is only relevant for CONFIG_EXPERT=y, so disallowing it > in Kconfig is an easier workaround than fixing it properly. Wrapping the relevant parts of this file into #ifdef MIPS_FP_SUPPORT would be as easy though and would qualify as a proper fix given that we have no XML description support for the MIPS target (so we need to supply the inexistent registers in the protocol; or maybe we can return NULL in `dbg_get_reg' to get them padded out in the RSP packet, I haven't checked if generic KGDB code supports this feature). Maciej
On Mon, Feb 08, 2021 at 06:03:08PM +0100, Maciej W. Rozycki wrote: > On Fri, 22 Jan 2021, Arnd Bergmann wrote: > > > From: Arnd Bergmann <arnd@arndb.de> > > > > kgdb fails to build when the FPU support is disabled: > > > > arch/mips/kernel/kgdb.c: In function 'dbg_set_reg': > > arch/mips/kernel/kgdb.c:147:35: error: 'struct thread_struct' has no member named 'fpu' > > 147 | memcpy((void *)¤t->thread.fpu.fcr31, mem, > > | ^ > > arch/mips/kernel/kgdb.c:155:34: error: 'struct thread_struct' has no member named 'fpu' > > 155 | memcpy((void *)¤t->thread.fpu.fpr[fp_reg], mem, > > > > This is only relevant for CONFIG_EXPERT=y, so disallowing it > > in Kconfig is an easier workaround than fixing it properly. > > Wrapping the relevant parts of this file into #ifdef MIPS_FP_SUPPORT > would be as easy though and would qualify as a proper fix given that we > have no XML description support for the MIPS target (so we need to supply > the inexistent registers in the protocol; or maybe we can return NULL in > `dbg_get_reg' to get them padded out in the RSP packet, I haven't checked > if generic KGDB code supports this feature). Returning NULL should be fine. The generic code will cope OK. The values in the f.p. registers may act a little odd if gdb uses a 'G' packet to set them to non-zero values (since kgdb will cache the values gdb sent it) but the developer operating the debugger will probably figure out what is going on without too much pain. Daniel.
On Wed, 10 Feb 2021, Daniel Thompson wrote: > > Wrapping the relevant parts of this file into #ifdef MIPS_FP_SUPPORT > > would be as easy though and would qualify as a proper fix given that we > > have no XML description support for the MIPS target (so we need to supply > > the inexistent registers in the protocol; or maybe we can return NULL in > > `dbg_get_reg' to get them padded out in the RSP packet, I haven't checked > > if generic KGDB code supports this feature). > > Returning NULL should be fine. > > The generic code will cope OK. The values in the f.p. registers may > act a little odd if gdb uses a 'G' packet to set them to non-zero values > (since kgdb will cache the values gdb sent it) but the developer > operating the debugger will probably figure out what is going on without > too much pain. Ack, thanks! NB if GDB sees a register padded out (FAOD it means all-x's rather than a hex string placed throughout the respective slot) in a `g' packet, then it will mark the register internally as "unavailable" and present it to the receiver of the information as such rather than giving any specific value. I don't remember offhand what the syntax for the `G' packet is in that case; possibly GDB just sends all-zeros, and in any case you can't make GDB write any specific value to such a register via any user interface. The way the unavailability is shown depends on the interface used, i.e. it will be different between the `info all-registers'/`info register $reg' commands, and the `p $reg' command (or any expression involving `$reg'), and the MI interface. But in any case it will be unambiguous. In no case however there will be user confusion for such registers. Maciej
On Wed, Feb 10, 2021 at 01:11:28PM +0100, Maciej W. Rozycki wrote: > On Wed, 10 Feb 2021, Daniel Thompson wrote: > > > > Wrapping the relevant parts of this file into #ifdef MIPS_FP_SUPPORT > > > would be as easy though and would qualify as a proper fix given that we > > > have no XML description support for the MIPS target (so we need to supply > > > the inexistent registers in the protocol; or maybe we can return NULL in > > > `dbg_get_reg' to get them padded out in the RSP packet, I haven't checked > > > if generic KGDB code supports this feature). > > > > Returning NULL should be fine. > > > > The generic code will cope OK. The values in the f.p. registers may > > act a little odd if gdb uses a 'G' packet to set them to non-zero values > > (since kgdb will cache the values gdb sent it) but the developer > > operating the debugger will probably figure out what is going on without > > too much pain. > > Ack, thanks! > > NB if GDB sees a register padded out (FAOD it means all-x's rather than a > hex string placed throughout the respective slot) in a `g' packet, then it > will mark the register internally as "unavailable" and present it to the > receiver of the information as such rather than giving any specific value. > I don't remember offhand what the syntax for the `G' packet is in that > case; possibly GDB just sends all-zeros, and in any case you can't make > GDB write any specific value to such a register via any user > interface. kgdb doesn't track register validity and adding would be a fairly big change. Everything internally (including some of the interactions with arch code) is based on updating a binary shadow of register state which is only bin2hex'ed just before transmitting a packet. It will simply default them to zero and update them on a 'G' packet. > The way the unavailability is shown depends on the interface used, i.e. > it will be different between the `info all-registers'/`info register $reg' > commands, and the `p $reg' command (or any expression involving `$reg'), > and the MI interface. But in any case it will be unambiguous. I guess this probably does create a technical protocol violation since kgdb will reject per-register read/write for register that its report says are zero rather then invalid. Daniel.
On Wed, 10 Feb 2021, Daniel Thompson wrote: > > NB if GDB sees a register padded out (FAOD it means all-x's rather than a > > hex string placed throughout the respective slot) in a `g' packet, then it > > will mark the register internally as "unavailable" and present it to the > > receiver of the information as such rather than giving any specific value. > > I don't remember offhand what the syntax for the `G' packet is in that > > case; possibly GDB just sends all-zeros, and in any case you can't make > > GDB write any specific value to such a register via any user > > interface. > > kgdb doesn't track register validity and adding would be a fairly big > change. Everything internally (including some of the interactions with > arch code) is based on updating a binary shadow of register state which > is only bin2hex'ed just before transmitting a packet. I've had a peek and it doesn't appear to me it would be a big deal. We have `gdb_regs' defined as an array of longs. We'd just need a second array for a register validity bitmap, which could for simplicity just have a single bit per each byte of `gdb_regs'. It would then be updated in `pt_regs_to_gdb_regs' according to the result of `dbg_get_reg' across the number of bits given by `dbg_reg_def[i].size'. And then `kgdb_mem2hex' would interpret the bitmap given as an extra argument accordingly. It looks to me like a couple of lines of extra code really. > It will simply default them to zero and update them on a 'G' packet. Ack. > > The way the unavailability is shown depends on the interface used, i.e. > > it will be different between the `info all-registers'/`info register $reg' > > commands, and the `p $reg' command (or any expression involving `$reg'), > > and the MI interface. But in any case it will be unambiguous. > > I guess this probably does create a technical protocol violation since > kgdb will reject per-register read/write for register that its report > says are zero rather then invalid. Not a violation, as GDB won't ever issue a `p'/`P' packet for a register that is in the range covered by `g'/`G'. This is by design. I'd have to track down the justification, but this is the right thing really. Also there is no issue with returning a rubbish value written with `G', as the same already happens with any RSP debug stub (or for that matter native GDB target) that deals with read-only registers. If you attempt to write one, then all the caches will keep the new value, and you will often have to make the target resume execution before the value reported is reset to the hardwired one. Debug stubs often cache registers for performance reasons, and may not even write them out unless execution is to be resumed, which often has serious consequences if a write to a hardware registers has side effects. For example I had that with an Intel Atom CPU switching between the real and the protected mode with a CR0 register write issued via a debug probe wired through the JTAG inteface. Caching is surely what Linux `gdbserver' does, as is what all JTAG debug interfaces do that I have come across, as JTAG access is usually painfully slow. Therefore in many cases GDB's `flushregs' command won't help as the stub will happily resend what it has previously cached with any updates applied locally only. FWIW, Maciej
On Wed, Feb 10, 2021 at 03:15:10PM +0100, Maciej W. Rozycki wrote: > On Wed, 10 Feb 2021, Daniel Thompson wrote: > > > > NB if GDB sees a register padded out (FAOD it means all-x's rather than a > > > hex string placed throughout the respective slot) in a `g' packet, then it > > > will mark the register internally as "unavailable" and present it to the > > > receiver of the information as such rather than giving any specific value. > > > I don't remember offhand what the syntax for the `G' packet is in that > > > case; possibly GDB just sends all-zeros, and in any case you can't make > > > GDB write any specific value to such a register via any user > > > interface. > > > > kgdb doesn't track register validity and adding would be a fairly big > > change. Everything internally (including some of the interactions with > > arch code) is based on updating a binary shadow of register state which > > is only bin2hex'ed just before transmitting a packet. > > I've had a peek and it doesn't appear to me it would be a big deal. > > We have `gdb_regs' defined as an array of longs. We'd just need a second > array for a register validity bitmap, which could for simplicity just have > a single bit per each byte of `gdb_regs'. It would then be updated in > `pt_regs_to_gdb_regs' according to the result of `dbg_get_reg' across the > number of bits given by `dbg_reg_def[i].size'. And then `kgdb_mem2hex' > would interpret the bitmap given as an extra argument accordingly. > > It looks to me like a couple of lines of extra code really. Agree, the core changes aren't too bad. I was more concerned about whether the validity bits would leak into the arch specific code via sleeping_thread_to_gdb_regs() and also noted the effort needed to review each architectures dbg_get_reg() implementation if we are going to react differently to it's return value. It is still not an infeasible amount of work though if someone does want to go in this direction. Daniel.
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index e6bd1eee70f2..7fea149f63cf 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -41,7 +41,7 @@ config MIPS select HANDLE_DOMAIN_IRQ select HAVE_ARCH_COMPILER_H select HAVE_ARCH_JUMP_LABEL - select HAVE_ARCH_KGDB + select HAVE_ARCH_KGDB if MIPS_FP_SUPPORT select HAVE_ARCH_MMAP_RND_BITS if MMU select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT select HAVE_ARCH_SECCOMP_FILTER