SlideShare a Scribd company logo
© 2009 Wind River
Merging KGDB KDB and
Kernel Mode Setting
Jason Wessel – Wind River
Jesse Barnes - Intel
© 2009 Wind River
The Glossary
• KGDB – Kernel GDB remote interface
– KGDB core merged to mainline kernel in 2.6.26
– Generic gdb serial interface for single or multi processor
systems, where gdb provides a source view of the system
– Works only with a uart based console driver
• KDB – Kernel debugger
– Never merged to mainline kernel and not likely to merge as is
– Supports only i386 and x86_64
– Provides a simple debugger via the system console or a serial
port, with no high level source
• KMS – Kernel Mode Settting
– Merged to mainline kernel in 2.6.29
– Core graphics driver in the kernel provides seamless switch
from console to graphics modes (vs reinitializing the HW each
time)
© 2009 Wind River
The Goal – Let the MERGE BEGIN!
• A simple, reliable multi-architecture debug shell
• Works with graphics or serial
• Ability to use kgdb or kdb
• Join the KDB and KGDB communities together
• Provide an API for future command expansion
– Trace dumping
– Disassembly
– Subsystem inspection commands (vfs, network, etc)
© 2009 Wind River
An example problem
• Awe MAN! If only I had a few more lines in the trace...
© 2009 Wind River
The debug shell
© 2009 Wind River
Basic KGDB design
KGDB has 4 main pieces
• Debug Core – Generic debug API
– Handles exceptions
– Syncs/saves/restores CPUs
– API for SW/HW breakpoints
• Arch specific KGDB
– Interface to read/write registers
– Arch specific exceptions and watch dogs
– Single stepping interface
• GDB Stub
– Speaks the gdb serial protocol
• Polled I/O Driver (kgdboc / kgdboe / kgdbou / kgdb_8250)
– Uses the console UART driver to multiplex a single serial line
– Another host's gdb connects to this port
Debug
Core
GDB
Stub
Polled
I/O Driver
Arch
Specific
KGDB
© 2009 Wind River
Basic KDB design
KDB has lots of parts
129 files changed, 57952 insertions(+), 10 deletions(-)
Low Level Arch Specific exceptions
kdb_main
kdb_io
Polled Keyboard driver
Polled serial driver
Assembly
set_jmp() long_jmp()
Back tracer
Other modules kdump etc...
disassembler
Single Step
BOOM!
Crash!
Thunk! Splat!
© 2009 Wind River
Merging KDB & KGDB
• The polled keyboard driver hooks into kgdboc
• The kdb_main, kdb_io and cmd handlers hook straight to the debug core
• gdb can use “monitor ...cmd...” to issue kdb cmds
• KDB got all the architecture specific pieces removed
– KDB core = 27 files changed, 6521 insertions(+), 10 deletions(-)
– KGDB changes = 9 files changed, 154 insertions(+), 31 deletions(-)
Debug
Core
kdb_main and kdb_io
Polled
I/O Driver
KGDBOC
Arch
Specific
KGDB
GDB Stub
KDB Polled Keyboard driver
© 2009 Wind River
KMS (kernel mode setting) basics
• Mode setting refers to changing the graphics console display
characteristics, such as the display type/size, screen blanking and
graphics hw management
• Mode setting in userspace causes issues:
– suspend/resume
– interaction with kernel drivers
– Ability to change from X to console on crash (BOSD)
• KMS paves the way for flicker free console switching
• Adding in console debugger support becomes desirable to analyse a crash
or inspect the system
• The hard part lies in making KMS work without locks
– Take an exception
– Transition to console atomically
– Run kdb
– Restore graphics
– Resume system
© 2009 Wind River
kgdb + kdb + kms
• KMS bolts into the debugger via kgdboc entry/exit call backs
• Configuration of using KMS is dynamic through kgdboc
Debug
Core
kdb
kgdboc
Arch
Specific
KGDB
GDB Stub
KMS
Hooks
© 2009 Wind River
Demonstration time
• KGDB, KDB and KMS in < 60 seconds
– http://www.youtube.com/watch?v=PDds73yDCNo
© 2009 Wind River
But wait there's MORE!
How about kgdb + kdb + kms + usb serial
© 2009 Wind River
Moving beyond the prototype
• The first priority is to finish cleaning kdb core and post to LKML
– kernel/kgdb.c → kernel/debug/debug_core.c and
gdbstub.c
– kernel/debug/kdb/*
– Rename arch/*/kernel/kgdb.c →
arch/*/kernel/debug_arch.c
• For KMS, there are certainly problems with the locks
+++ b/drivers/gpu/drm/drm_crtc.c
+#ifdef CONFIG_KGDB
+ if (atomic_read(&kgdb_active) == -1)
+#endif
+ mutex_lock(&dev->mode_config.idr_mutex);
• KMS needs some generic debugger API work
– Only the Intel 915 works today with kdb
– Jesse suggested the possibility for a dedicated debug
console
© 2009 Wind River
Moving beyond the prototype
• The USB keyboard driver is UGLY!!!
– The low level uchi/ohci/ehci are modified to allow for
polloing and pulling off packets of the keyboard type only
• Anyone want to help with an “alternatives” implementation?
– The debugger needs to change some code paths after entry
– The debugger should stay out of the way otherwise
• Low Level exception support
– The debug core needs the first right of breakpoint handling
– Perhaps code “alternatives”?
• panic() should allow a debug hook before calling smp_send_stop()
© 2009 Wind River
Nested Exception Support
• Prototype hack for debugging part of the code used by the debugger
proves useful
– It was possible to debug the KMS code with kgdb so long as on
the second exception kgdb jumps directly into the debug core
– Without the “hack” the debug core prints a stack dump an
panics
• The kgdb_ll_trap() was introduced by kdb to allow the debug core to step
through an atomic_notifier_call_chain
• It is now a TODO item to consider nested exception debugging because
you can also debug parts of the debugger itself
© 2009 Wind River
Displaced Stepping?
• Problems without displaced stepping
– Missed breakpoint
• free all cpus and wait for a thread to get scheduled
which uses HW single stepping
– Deadlock on lock
• single stepping by freeing only one CPU, dead locks on
any lock held by a frozen CPU
• Displaced stepping is leaving a break point planted and executing the
original instruction out of line
– An experimental patch modifies kprobes to plant a probe to
single step a kernel thread
– The down side is you cannot debug some further small pieces of
the kernel
© 2009 Wind River
Mainline for kgdboe someday?
• Today's kgdboe has a major short coming, in that it is not robust
• Network drivers can be in a state where it is impossible to use them safely
from the exception context (preempted with locks held)
• Possible solutions:
– Perhaps a dedicated queue in the HW is the answer (e1000e)
– While it would require a dedicated ethernet interface, you could
use a self contained, exception safe network stack
– A redesigned poll interface
© 2009 Wind River
kgdbou (kgdb over usb)
• It is on the mile long todo list :-)
• First up is work around improved USB console support
– 2.6.31 - merged USB sysrq support
– 2.6.32 - USB EHCI debug port console (supports early_printk)
– Stable USB console support is a work in progress
– kgdbou present state is considered “too much of a hack”
• Kgdb integration can proceed after the console support
– On the demo machine there are if (kgdb_activate...) checks in
the hot path which would need to resolved by design
© 2009 Wind River
The kernel debugger and the future
• We want to unite the all the of the kernel debugger folks
• Send patches to kgdb-bugreport@lists.sourceforge.net
• The kgdb wiki is slated to launch in late September
http://kgdb.wiki.kernel.org/
Special Thanks
– Jesse Barnes - for his KMS code
– Martin Hicks - (KDB maintainer) for kdb cleanup patches
Kgdb kdb modesetting

More Related Content

PDF
Linux kernel debugging
ODP
Linux kernel debugging(ODP format)
PPT
Linux Kernel Debugging
ODP
Performance: Observe and Tune
PDF
Linux Kernel Live Patching
PPTX
Modern Linux Tracing Landscape
PDF
Kernel Recipes 2015 - So you want to write a Linux driver framework
PPTX
Linux Network Stack
Linux kernel debugging
Linux kernel debugging(ODP format)
Linux Kernel Debugging
Performance: Observe and Tune
Linux Kernel Live Patching
Modern Linux Tracing Landscape
Kernel Recipes 2015 - So you want to write a Linux driver framework
Linux Network Stack

What's hot (20)

PDF
The Linux Block Layer - Built for Fast Storage
PPT
Linux Crash Dump Capture and Analysis
PDF
Kernel Recipes 2015 - Kernel dump analysis
PDF
Qemu Introduction
PDF
Kernel Recipes 2015 - Porting Linux to a new processor architecture
PPTX
Tech Days 2015: Embedded Product Update
PDF
Low latency & mechanical sympathy issues and solutions
PDF
LXC on Ganeti
PDF
Kernel Recipes 2015: Kernel packet capture technologies
PDF
FreeBSD and Drivers
PPTX
RHEVM - Live Storage Migration
PDF
Kernel Recipes 2015: Speed up your kernel development cycle with QEMU
PDF
Understand and optimize Linux I/O
PDF
Kernel Recipes 2015: Anatomy of an atomic KMS driver
PDF
Xdp and ebpf_maps
PDF
Kernel Recipes 2017 - Build farm again - Willy Tarreau
PDF
Linux Cluster next generation
PDF
IRQs: the Hard, the Soft, the Threaded and the Preemptible
PDF
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
PDF
NetBSD and Linux for Embedded Systems
The Linux Block Layer - Built for Fast Storage
Linux Crash Dump Capture and Analysis
Kernel Recipes 2015 - Kernel dump analysis
Qemu Introduction
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Tech Days 2015: Embedded Product Update
Low latency & mechanical sympathy issues and solutions
LXC on Ganeti
Kernel Recipes 2015: Kernel packet capture technologies
FreeBSD and Drivers
RHEVM - Live Storage Migration
Kernel Recipes 2015: Speed up your kernel development cycle with QEMU
Understand and optimize Linux I/O
Kernel Recipes 2015: Anatomy of an atomic KMS driver
Xdp and ebpf_maps
Kernel Recipes 2017 - Build farm again - Willy Tarreau
Linux Cluster next generation
IRQs: the Hard, the Soft, the Threaded and the Preemptible
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
NetBSD and Linux for Embedded Systems
Ad

Viewers also liked (20)

PDF
Linux Kernel Debugging Essentials workshop
PDF
Descripcion de nuestros servicios de Inteligencia Comercial
PDF
2012 M&A Deal Terms Study
PPTX
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
PPTX
Cybermania Mains
PDF
Linux performance
PDF
Kernel Recipes 2015: The stable Linux Kernel Tree - 10 years of insanity
PPTX
Cybermania Prelims
PPTX
A particle filter based scheme for indoor tracking on an Android Smartphone
PDF
Rootkit 102 - Kernel-Based Rootkit
ODP
Linux Internals - Kernel/Core
PDF
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
PDF
LAS16-403 - GDB Linux Kernel Awareness
PDF
ELK: a log management framework
PDF
The Linux Kernel Implementation of Pipes and FIFOs
PPT
Understanding Your Organisation
PPTX
Introduction to ELK
PDF
Rootkit on Linux X86 v2.6
PDF
Abby Covert – How to make sense of any mess
Linux Kernel Debugging Essentials workshop
Descripcion de nuestros servicios de Inteligencia Comercial
2012 M&A Deal Terms Study
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
Cybermania Mains
Linux performance
Kernel Recipes 2015: The stable Linux Kernel Tree - 10 years of insanity
Cybermania Prelims
A particle filter based scheme for indoor tracking on an Android Smartphone
Rootkit 102 - Kernel-Based Rootkit
Linux Internals - Kernel/Core
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
LAS16-403 - GDB Linux Kernel Awareness
ELK: a log management framework
The Linux Kernel Implementation of Pipes and FIFOs
Understanding Your Organisation
Introduction to ELK
Rootkit on Linux X86 v2.6
Abby Covert – How to make sense of any mess
Ad

Similar to Kgdb kdb modesetting (20)

PDF
Lecture 6 Kernel Debugging + Ports Development
PDF
Kernel development
PPT
Group 1 Presentation
PDF
ELC-E Linux Awareness
PDF
Flourish11
PDF
Crash Dump Analysis 101
PDF
Jtag Tools For Linux
PDF
Scale9x sun
PPTX
Arm architecture chapter2_steve_furber
PDF
Solaris Kernel Debugging V1.0
PDF
LAS16-403: GDB Linux Kernel Awareness
PDF
今日から始めるPlan 9 from Bell Labs
PDF
Debugging embedded devices using GDB
PDF
Lect02
PPTX
Computer Software | Lecture 4C
PPTX
Computer Software - Lecture C
ODP
coreboot@Budapest 10.2009 Meetup
PDF
2013 Indiana LinuxFest - Getting Started With PC-BSD
PPTX
Reversing with gdb
PDF
Lecture 6 Kernel Debugging + Ports Development
Kernel development
Group 1 Presentation
ELC-E Linux Awareness
Flourish11
Crash Dump Analysis 101
Jtag Tools For Linux
Scale9x sun
Arm architecture chapter2_steve_furber
Solaris Kernel Debugging V1.0
LAS16-403: GDB Linux Kernel Awareness
今日から始めるPlan 9 from Bell Labs
Debugging embedded devices using GDB
Lect02
Computer Software | Lecture 4C
Computer Software - Lecture C
coreboot@Budapest 10.2009 Meetup
2013 Indiana LinuxFest - Getting Started With PC-BSD
Reversing with gdb

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
composite construction of structures.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPT
Mechanical Engineering MATERIALS Selection
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PPT on Performance Review to get promotions
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Digital Logic Computer Design lecture notes
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
573137875-Attendance-Management-System-original
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
composite construction of structures.pdf
additive manufacturing of ss316l using mig welding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Lecture Notes Electrical Wiring System Components
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT on Performance Review to get promotions
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Digital Logic Computer Design lecture notes
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...

Kgdb kdb modesetting

  • 1. © 2009 Wind River Merging KGDB KDB and Kernel Mode Setting Jason Wessel – Wind River Jesse Barnes - Intel
  • 2. © 2009 Wind River The Glossary • KGDB – Kernel GDB remote interface – KGDB core merged to mainline kernel in 2.6.26 – Generic gdb serial interface for single or multi processor systems, where gdb provides a source view of the system – Works only with a uart based console driver • KDB – Kernel debugger – Never merged to mainline kernel and not likely to merge as is – Supports only i386 and x86_64 – Provides a simple debugger via the system console or a serial port, with no high level source • KMS – Kernel Mode Settting – Merged to mainline kernel in 2.6.29 – Core graphics driver in the kernel provides seamless switch from console to graphics modes (vs reinitializing the HW each time)
  • 3. © 2009 Wind River The Goal – Let the MERGE BEGIN! • A simple, reliable multi-architecture debug shell • Works with graphics or serial • Ability to use kgdb or kdb • Join the KDB and KGDB communities together • Provide an API for future command expansion – Trace dumping – Disassembly – Subsystem inspection commands (vfs, network, etc)
  • 4. © 2009 Wind River An example problem • Awe MAN! If only I had a few more lines in the trace...
  • 5. © 2009 Wind River The debug shell
  • 6. © 2009 Wind River Basic KGDB design KGDB has 4 main pieces • Debug Core – Generic debug API – Handles exceptions – Syncs/saves/restores CPUs – API for SW/HW breakpoints • Arch specific KGDB – Interface to read/write registers – Arch specific exceptions and watch dogs – Single stepping interface • GDB Stub – Speaks the gdb serial protocol • Polled I/O Driver (kgdboc / kgdboe / kgdbou / kgdb_8250) – Uses the console UART driver to multiplex a single serial line – Another host's gdb connects to this port Debug Core GDB Stub Polled I/O Driver Arch Specific KGDB
  • 7. © 2009 Wind River Basic KDB design KDB has lots of parts 129 files changed, 57952 insertions(+), 10 deletions(-) Low Level Arch Specific exceptions kdb_main kdb_io Polled Keyboard driver Polled serial driver Assembly set_jmp() long_jmp() Back tracer Other modules kdump etc... disassembler Single Step BOOM! Crash! Thunk! Splat!
  • 8. © 2009 Wind River Merging KDB & KGDB • The polled keyboard driver hooks into kgdboc • The kdb_main, kdb_io and cmd handlers hook straight to the debug core • gdb can use “monitor ...cmd...” to issue kdb cmds • KDB got all the architecture specific pieces removed – KDB core = 27 files changed, 6521 insertions(+), 10 deletions(-) – KGDB changes = 9 files changed, 154 insertions(+), 31 deletions(-) Debug Core kdb_main and kdb_io Polled I/O Driver KGDBOC Arch Specific KGDB GDB Stub KDB Polled Keyboard driver
  • 9. © 2009 Wind River KMS (kernel mode setting) basics • Mode setting refers to changing the graphics console display characteristics, such as the display type/size, screen blanking and graphics hw management • Mode setting in userspace causes issues: – suspend/resume – interaction with kernel drivers – Ability to change from X to console on crash (BOSD) • KMS paves the way for flicker free console switching • Adding in console debugger support becomes desirable to analyse a crash or inspect the system • The hard part lies in making KMS work without locks – Take an exception – Transition to console atomically – Run kdb – Restore graphics – Resume system
  • 10. © 2009 Wind River kgdb + kdb + kms • KMS bolts into the debugger via kgdboc entry/exit call backs • Configuration of using KMS is dynamic through kgdboc Debug Core kdb kgdboc Arch Specific KGDB GDB Stub KMS Hooks
  • 11. © 2009 Wind River Demonstration time • KGDB, KDB and KMS in < 60 seconds – http://www.youtube.com/watch?v=PDds73yDCNo
  • 12. © 2009 Wind River But wait there's MORE! How about kgdb + kdb + kms + usb serial
  • 13. © 2009 Wind River Moving beyond the prototype • The first priority is to finish cleaning kdb core and post to LKML – kernel/kgdb.c → kernel/debug/debug_core.c and gdbstub.c – kernel/debug/kdb/* – Rename arch/*/kernel/kgdb.c → arch/*/kernel/debug_arch.c • For KMS, there are certainly problems with the locks +++ b/drivers/gpu/drm/drm_crtc.c +#ifdef CONFIG_KGDB + if (atomic_read(&kgdb_active) == -1) +#endif + mutex_lock(&dev->mode_config.idr_mutex); • KMS needs some generic debugger API work – Only the Intel 915 works today with kdb – Jesse suggested the possibility for a dedicated debug console
  • 14. © 2009 Wind River Moving beyond the prototype • The USB keyboard driver is UGLY!!! – The low level uchi/ohci/ehci are modified to allow for polloing and pulling off packets of the keyboard type only • Anyone want to help with an “alternatives” implementation? – The debugger needs to change some code paths after entry – The debugger should stay out of the way otherwise • Low Level exception support – The debug core needs the first right of breakpoint handling – Perhaps code “alternatives”? • panic() should allow a debug hook before calling smp_send_stop()
  • 15. © 2009 Wind River Nested Exception Support • Prototype hack for debugging part of the code used by the debugger proves useful – It was possible to debug the KMS code with kgdb so long as on the second exception kgdb jumps directly into the debug core – Without the “hack” the debug core prints a stack dump an panics • The kgdb_ll_trap() was introduced by kdb to allow the debug core to step through an atomic_notifier_call_chain • It is now a TODO item to consider nested exception debugging because you can also debug parts of the debugger itself
  • 16. © 2009 Wind River Displaced Stepping? • Problems without displaced stepping – Missed breakpoint • free all cpus and wait for a thread to get scheduled which uses HW single stepping – Deadlock on lock • single stepping by freeing only one CPU, dead locks on any lock held by a frozen CPU • Displaced stepping is leaving a break point planted and executing the original instruction out of line – An experimental patch modifies kprobes to plant a probe to single step a kernel thread – The down side is you cannot debug some further small pieces of the kernel
  • 17. © 2009 Wind River Mainline for kgdboe someday? • Today's kgdboe has a major short coming, in that it is not robust • Network drivers can be in a state where it is impossible to use them safely from the exception context (preempted with locks held) • Possible solutions: – Perhaps a dedicated queue in the HW is the answer (e1000e) – While it would require a dedicated ethernet interface, you could use a self contained, exception safe network stack – A redesigned poll interface
  • 18. © 2009 Wind River kgdbou (kgdb over usb) • It is on the mile long todo list :-) • First up is work around improved USB console support – 2.6.31 - merged USB sysrq support – 2.6.32 - USB EHCI debug port console (supports early_printk) – Stable USB console support is a work in progress – kgdbou present state is considered “too much of a hack” • Kgdb integration can proceed after the console support – On the demo machine there are if (kgdb_activate...) checks in the hot path which would need to resolved by design
  • 19. © 2009 Wind River The kernel debugger and the future • We want to unite the all the of the kernel debugger folks • Send patches to kgdb-bugreport@lists.sourceforge.net • The kgdb wiki is slated to launch in late September http://kgdb.wiki.kernel.org/ Special Thanks – Jesse Barnes - for his KMS code – Martin Hicks - (KDB maintainer) for kdb cleanup patches

Editor's Notes

  • #2: The title of your presentation should be short and direct. The subtitle of your presentation should consist of the presenter’s name and title.