SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Kernel debug log and
console on openSUSE
August, 2019, Taipei, COSCUP
Joey Lee
SUSE Labs Taipei
2
Agenda
• Kernel log
• Consoles
• Q&A
3
Kernel log buffer and consoles
Kernel log
5
Kernel log
6
Kernel log buffer
• SLE15 / openSUSE Leap 15.1
‒ CONFIG_LOG_BUF_SHIFT=18
‒ CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=13
‒ 2^18 = 256KB
• log_buf_len=n[KMG]
‒ Sets the size of the printk ring buffer,
‒ in bytes. n must be a power of two and greater than the
minimal size. The minimal size is defined by
LOG_BUF_SHIFT kernel config parameter. There is also
CONFIG_LOG_CPU_MAX_BUF_SHIFT config parameter
that allows to increase the default size depending on the
number of CPUs. See init/Kconfig for more details. [1]
7
Kernel log buffer (cont.)
• The kmsg is an ring buffer
static char __log_buf[__LOG_BUF_LEN]
__aligned(LOG_ALIGN);
• Protected by spinlock
DEFINE_RAW_SPINLOCK(logbuf_lock);
• /dev/kmsg
[11] = { "kmsg", 0644, &kmsg_fops, 0 },
• dmesg utility accesses /dev/kmsg
8
dmesg
• Print or control the kernel ring buffer
• Default print all /dev/kmsg messages
• Restrict message level
‒ dmesg -l err,warn
‒ dmesg -l info,debug
• Set console level
‒ dmesg -n 8
• Wait for new messages
‒ dmesg -w
• Clear ring buffer
‒ sudo dmesg -C
9
loglevel
• loglevel=0..7
• Console loglevel
• All Kernel Messages with a loglevel smaller than the
console loglevel will be printed to the console.
suppress_message_printing(msg→level)
static bool suppress_message_printing(int level)
{
return (level >= console_loglevel && !ignore_loglevel);
}
10
loglevel defined
• The loglevels are defined as follows:
0 (KERN_EMERG) system is unusable
1 (KERN_ALERT) action must be taken immediately
2 (KERN_CRIT) critical conditions
3 (KERN_ERR) error conditions
4 (KERN_WARNING) warning conditions [quiet]
5 (KERN_NOTICE) normal but significant conditions
6 (KERN_INFO) informational
7 (KERN_DEBUG) debug-level messages [default]
10 (CONSOLE_LOGLEVEL_DEBUG)
11
Kernel parameters for loglevel
• ignore_loglevel
‒ Ignore loglevel setting - this will print /all/ kernel messages to
the console. Useful for debugging. We also add it as printk
module parameter, so users could change it dynamically,
usually by
/sys/module/printk/parameters/ignore_loglevel. [1]
• debug
‒ [KNL] Enable kernel debugging (events log level).
‒ console_loglevel = CONSOLE_LOGLEVEL_DEBUG; // 10
• quiet
‒ [KNL] Disable most log messages
‒ console_loglevel = CONSOLE_LOGLEVEL_QUIET; // 4
12
rsyslog
• The rsyslog overwrites loglevel when booting
• systemctl status rsyslog
• /etc/rsyslog.conf
# set log level 1 (same as in /etc/sysconfig/syslog).
$klogConsoleLogLevel 1
• # cat /proc/sys/kernel/printk
1 4 1 7
13
printk sysfs
• cat /proc/sys/kernel/printk
1 4 1 7
• console_loglevel: messages with a higher priority
than this will be printed to the console
• default_message_loglevel: messages without an
explicit priority will be printed with this priority
• minimum_console_loglevel: minimum (highest)
value to which console_loglevel can be set
• default_console_loglevel: default value for
console_loglevel
14
Default loglevel of SLE/openSUSE
• Kernel config: loglevel=7
‒ CONFIG_CONSOLE_LOGLEVEL_DEFAULT=7
• Grub2 config (grub.cfg): loglevel=4
‒ Kernel parameter: quiet
‒ GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda1
splash=silent quiet showopts"
• rsyslog config (/etc/rsyslog.conf): loglevel=1
‒ $klogConsoleLogLevel 1
• Conclusion
‒ Before rsyslog start: console_loglevel = 4
‒ After rsyslog start: console_loglevel = 1
‒ Please add loglevel=9 or debug, and also “dmesg -n 8” for debugging
15
Dynamic debug
• ddebug_query
‒ [KNL,DYNAMIC_DEBUG] Enable debug messages at
early boot time. See Documentation/dynamic-debug-
howto.txt for details. [1]
‒ Dynamic debug is designed to allow you to dynamically
enable/disable kernel code to obtain additional kernel
information. Currently, if ``CONFIG_DYNAMIC_DEBUG``
is set, then all ``pr_debug()``/``dev_dbg()`` and
``print_hex_dump_debug()``/``print_hex_dump_bytes()``
calls can be dynamically enabled per-callsite. [2]
16
Dynamic debug (cont.)
• Kernel parameter:
'ddebug_query=file drivers/firmware/efi/efi-secret-key.c +p'
'ddebug_query=file kernel/module_signing.c +p; file
crypto/asymmetric_keys/pkcs7_trust.c +p'
• Userland command:
# echo -n 'file drivers/base/firmware_class.c +p' >
/sys/kernel/debug/dynamic_debug/control
# cat /sys/kernel/debug/dynamic_debug/control
17
pr_debug() / dev_dbg()
#if defined(CONFIG_DYNAMIC_DEBUG)
#include <linux/dynamic_debug.h>
#define pr_debug(fmt, ...) 
dynamic_pr_debug(fmt, ##__VA_ARGS__)
#elif defined(DEBUG)
#define pr_debug(fmt, ...) 
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) 
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif
Consoles
19
Consoles
20
earlyprintk
• Serial port: earlyprintk=ttyS0,115200
‒ EFI framebuffer: earlyprintk=efi
‒ VGA: earlyprintk=vga
‒ USB2 debug port: earlyprintk=dbgp
‒ USB3 debug port: earlyprintk=xdbc
• earlyprintk is useful when the kernel crashes before the
normal console is initialized. It is not enabled by default
because it has some cosmetic problems.
‒ It’s a OLD parameter in kernel
• Only one of vga, efi, serial, or usb debug port can be used
at a time.
• early_printk() callers: e820, kaslr, mm(idt), perf
21
earlycon
• Output early console device and options.
• CONFIG_SERIAL_EARLYCON
‒ v3.16 kernel
‒ Support for early consoles with the earlycon parameter. This enables the console
before standard serial driver is probed. The console is enabled when early_param is
processed.
• earlycon
‒ [X86] ACPI SPCR (Serial Port Console Redirection Table)
‒ [ARM64] Device Tree
• earlycon=uart[8250],io,<addr>[,options]
=uart[8250],mmio,<addr>[,options]
...
‒ earlycon=uart,io,0x3f8,115200
• EARLYCON_DECLARE() or OF_EARLYCON_DECLARE() in kernel
‒ Set initial function to __earlycon_table section
22
console
• Output console device and options.
• tty<n>
ttyS<n>[,options]
ttyUSB0[,options]
‒ Serial: console=ttyS0,115200n8
‒ USB: console=ttyUSB0,115200n8
‒ ARM: console=ttyAMA0,115200n8
• Maximum 8 consoles
‒ console_cmdline[MAX_CMDLINECONSOLES]
‒ #define MAX_CMDLINECONSOLES 8
23
Reading messages from consoles
• screen command
‒ # screen /dev/ttyS0 115200
‒ # screen -h 10000 /dev/ttyUSB1 115200
• minicom
‒ # minicom -b 115200 -D /dev/ttyUSB0
24
When can earlcon be enabled?
No console before here
25
The debug log in early booting stage
• For booting
‒ In EFI stub, the efi_printk() log is only for expected error.
‒ In kernel, earlyprintk= or earlycon= only be enabled after
parse_early_param().
‒ “KASLR using” message should be exposed with
earlyprintk= or earlycon=
‒ KASLR (Kernel Address Space Layout Randomization)
• For problems that occur before the serial console
and EFI framebuffer are initialized [4]
‒ Debugging a mysterious reset with an infinite loop
‒ Debugging a hang by triggering a reset
26
DEBUG_LL and ARM
• Kernel low-level debugging functions
• CONFIG_DEBUG_LL
‒ ARM, Unicore32
‒ Say Y here to include definitions of printascii, printch, printhex in the kernel.
This is helpful if you are debugging code that executes before the console is
initialized.
‒ Note that selecting this option will limit the kernel to a single UART definition,
… this option should not be enabled for kernels that are intended to be
portable.
‒ CONFIG_DEBUG_BCM2835 for Raspberry Pi 1
‒ DEBUG_UART_PHYS = 0x20201000, DEBUG_UART_VIRT = 0xf0201000
‒ CONFIG_DEBUG_BCM2836 for Raspberry Pi 2
‒ DEBUG_UART_PHYS = 0x3f201000, DEBUG_UART_VIRT = 0xf0201000
• Should works with CONFIG_EARLY_PRINTK
‒ Enable by earlyprintk kernel parameter
27
netconsole
• This module logs kernel printk messages over UDP
allowing debugging of problem where disk logging fails
and serial consoles are impractical. [3]
• As a built-in, netconsole initializes immediately after NIC
cards and will bring up the specified interface as soon as
possible. While this doesn't allow capture of early kernel
panics, it does capture most of the boot process. [3]
• CONFIG_NETCONSOLE=y
‒ NIC driver must also be build-in
• CONFIG_NETCONSOLE=m
‒ /etc/modules-load.d/netconsole.conf
‒ /etc/modprobe.d/netconsole.conf
28
netconsole (cont.)
• Sender: netconsole=[+][src-port]@[src-ip]/[<dev>],
[tgt-port]@<tgt-ip>/[tgt-macaddr]
netconsole=6665@192.168.1.83/eth0,6666@192.168.1.11
/ab:cd:23:b0:14:b6
netconsole=@192.168.1.83/,@192.168.1.11/
• Receiver: netcat
netcat -k -l -u 192.168.1.11 6666
Q&A
30
Reference
• [1] Documentation/admin-guide/kernel-
parameters.txt, Linux Kernel
• [2] Documentation/admin-guide/dynamic-debug-
howto.rst, Linux Kernel
• [3] Documentation/networking/netconsole.txt, Linux
Kernel
• [4] Early x86 Linux boot debug tricks, Matt Fleming
‒ http://www.codeblueprint.co.uk/2015/04/15/early-x86-linux-
boot-debug-tricks.html
Thank you.
31
Feedback to
jlee@suse.com
Corporate Headquarters
Maxfeldstrasse 5
90409 Nuremberg
Germany
+49 911 740 53 0 (Worldwide)
www.suse.com
Join us on:
www.opensuse.org
33
Unpublished Work of SUSE. All Rights Reserved.
This work is an unpublished work and contains confidential, proprietary and trade secret information of SUSE.
Access to this work is restricted to SUSE employees who have a need to know to perform tasks within the scope of
their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated,
abridged, condensed, expanded, collected, or adapted without the prior written consent of SUSE.
Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability.
General Disclaimer
This document is not to be construed as a promise by any participating company to develop, deliver, or market a
product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making
purchasing decisions. SUSE makes no representations or warranties with respect to the contents of this document,
and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose.
The development, release, and timing of features or functionality described for SUSE products remains at the sole
discretion of SUSE. Further, SUSE reserves the right to revise this document and to make changes to its content, at
any time, without obligation to notify any person or entity of such revisions or changes. All SUSE marks referenced in
this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All
third-party trademarks are the property of their respective owners.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
semaphore & mutex.pdf
semaphore & mutex.pdfsemaphore & mutex.pdf
semaphore & mutex.pdf
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
SSL Setup for Oracle 10g AS
SSL Setup for Oracle 10g ASSSL Setup for Oracle 10g AS
SSL Setup for Oracle 10g AS
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
eBPF maps 101
eBPF maps 101eBPF maps 101
eBPF maps 101
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using Tracing
 
HKG15-107: ACPI Power Management on ARM64 Servers (v2)
HKG15-107: ACPI Power Management on ARM64 Servers (v2)HKG15-107: ACPI Power Management on ARM64 Servers (v2)
HKG15-107: ACPI Power Management on ARM64 Servers (v2)
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with schedulerLCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
 
Memory model
Memory modelMemory model
Memory model
 
LAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel Awareness
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 

Similar a Kernel debug log and console on openSUSE

Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
Kan-Ru Chen
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
Linaro
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux Awareness
Peter Griffin
 

Similar a Kernel debug log and console on openSUSE (20)

Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Fast boot
Fast bootFast boot
Fast boot
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
HKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case studyHKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case study
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and Insights
 
QEMU Sandboxing for dummies
QEMU Sandboxing for dummiesQEMU Sandboxing for dummies
QEMU Sandboxing for dummies
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux Awareness
 
Armboot process zeelogic
Armboot process zeelogicArmboot process zeelogic
Armboot process zeelogic
 
SiteGround Tech TeamBuilding
SiteGround Tech TeamBuildingSiteGround Tech TeamBuilding
SiteGround Tech TeamBuilding
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
Advanced Root Cause Analysis
Advanced Root Cause AnalysisAdvanced Root Cause Analysis
Advanced Root Cause Analysis
 
Analisis_avanzado_vmware
Analisis_avanzado_vmwareAnalisis_avanzado_vmware
Analisis_avanzado_vmware
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
Lecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports DevelopmentLecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports Development
 
kubernetes practice
kubernetes practicekubernetes practice
kubernetes practice
 

Más de SUSE Labs Taipei

Develop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build ServiceDevelop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build Service
SUSE Labs Taipei
 

Más de SUSE Labs Taipei (19)

Locked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelLocked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernel
 
SUSE shim and things related to it
SUSE shim and things related to itSUSE shim and things related to it
SUSE shim and things related to it
 
Multi-signed Kernel Module
Multi-signed Kernel ModuleMulti-signed Kernel Module
Multi-signed Kernel Module
 
Profiling the ACPICA Namespace and Event Handing
Profiling the ACPICA Namespace and Event HandingProfiling the ACPICA Namespace and Event Handing
Profiling the ACPICA Namespace and Event Handing
 
The bright future of SUSE and openSUSE
The bright future of SUSE and openSUSEThe bright future of SUSE and openSUSE
The bright future of SUSE and openSUSE
 
EFI Secure Key
EFI Secure KeyEFI Secure Key
EFI Secure Key
 
Convert your package to multibuild on Open Build Service
Convert your package to multibuild on Open Build ServiceConvert your package to multibuild on Open Build Service
Convert your package to multibuild on Open Build Service
 
Ixgbe internals
Ixgbe internalsIxgbe internals
Ixgbe internals
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 
Looking into trusted and encrypted keys
Looking into trusted and encrypted keysLooking into trusted and encrypted keys
Looking into trusted and encrypted keys
 
Use bonding driver with ethernet
Use bonding driver with ethernetUse bonding driver with ethernet
Use bonding driver with ethernet
 
Use build service API in your program
Use build service API in your programUse build service API in your program
Use build service API in your program
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
S4 sig-check-lpc-20130918
S4 sig-check-lpc-20130918S4 sig-check-lpc-20130918
S4 sig-check-lpc-20130918
 
openSUSE12.2 Review
openSUSE12.2 ReviewopenSUSE12.2 Review
openSUSE12.2 Review
 
oS KDE Repos & MM
oS KDE Repos & MMoS KDE Repos & MM
oS KDE Repos & MM
 
Develop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build ServiceDevelop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build Service
 
Coscup 2012-urfkill
Coscup 2012-urfkillCoscup 2012-urfkill
Coscup 2012-urfkill
 

Último

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 

Kernel debug log and console on openSUSE

  • 1. Kernel debug log and console on openSUSE August, 2019, Taipei, COSCUP Joey Lee SUSE Labs Taipei
  • 2. 2 Agenda • Kernel log • Consoles • Q&A
  • 3. 3 Kernel log buffer and consoles
  • 6. 6 Kernel log buffer • SLE15 / openSUSE Leap 15.1 ‒ CONFIG_LOG_BUF_SHIFT=18 ‒ CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=13 ‒ 2^18 = 256KB • log_buf_len=n[KMG] ‒ Sets the size of the printk ring buffer, ‒ in bytes. n must be a power of two and greater than the minimal size. The minimal size is defined by LOG_BUF_SHIFT kernel config parameter. There is also CONFIG_LOG_CPU_MAX_BUF_SHIFT config parameter that allows to increase the default size depending on the number of CPUs. See init/Kconfig for more details. [1]
  • 7. 7 Kernel log buffer (cont.) • The kmsg is an ring buffer static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN); • Protected by spinlock DEFINE_RAW_SPINLOCK(logbuf_lock); • /dev/kmsg [11] = { "kmsg", 0644, &kmsg_fops, 0 }, • dmesg utility accesses /dev/kmsg
  • 8. 8 dmesg • Print or control the kernel ring buffer • Default print all /dev/kmsg messages • Restrict message level ‒ dmesg -l err,warn ‒ dmesg -l info,debug • Set console level ‒ dmesg -n 8 • Wait for new messages ‒ dmesg -w • Clear ring buffer ‒ sudo dmesg -C
  • 9. 9 loglevel • loglevel=0..7 • Console loglevel • All Kernel Messages with a loglevel smaller than the console loglevel will be printed to the console. suppress_message_printing(msg→level) static bool suppress_message_printing(int level) { return (level >= console_loglevel && !ignore_loglevel); }
  • 10. 10 loglevel defined • The loglevels are defined as follows: 0 (KERN_EMERG) system is unusable 1 (KERN_ALERT) action must be taken immediately 2 (KERN_CRIT) critical conditions 3 (KERN_ERR) error conditions 4 (KERN_WARNING) warning conditions [quiet] 5 (KERN_NOTICE) normal but significant conditions 6 (KERN_INFO) informational 7 (KERN_DEBUG) debug-level messages [default] 10 (CONSOLE_LOGLEVEL_DEBUG)
  • 11. 11 Kernel parameters for loglevel • ignore_loglevel ‒ Ignore loglevel setting - this will print /all/ kernel messages to the console. Useful for debugging. We also add it as printk module parameter, so users could change it dynamically, usually by /sys/module/printk/parameters/ignore_loglevel. [1] • debug ‒ [KNL] Enable kernel debugging (events log level). ‒ console_loglevel = CONSOLE_LOGLEVEL_DEBUG; // 10 • quiet ‒ [KNL] Disable most log messages ‒ console_loglevel = CONSOLE_LOGLEVEL_QUIET; // 4
  • 12. 12 rsyslog • The rsyslog overwrites loglevel when booting • systemctl status rsyslog • /etc/rsyslog.conf # set log level 1 (same as in /etc/sysconfig/syslog). $klogConsoleLogLevel 1 • # cat /proc/sys/kernel/printk 1 4 1 7
  • 13. 13 printk sysfs • cat /proc/sys/kernel/printk 1 4 1 7 • console_loglevel: messages with a higher priority than this will be printed to the console • default_message_loglevel: messages without an explicit priority will be printed with this priority • minimum_console_loglevel: minimum (highest) value to which console_loglevel can be set • default_console_loglevel: default value for console_loglevel
  • 14. 14 Default loglevel of SLE/openSUSE • Kernel config: loglevel=7 ‒ CONFIG_CONSOLE_LOGLEVEL_DEFAULT=7 • Grub2 config (grub.cfg): loglevel=4 ‒ Kernel parameter: quiet ‒ GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda1 splash=silent quiet showopts" • rsyslog config (/etc/rsyslog.conf): loglevel=1 ‒ $klogConsoleLogLevel 1 • Conclusion ‒ Before rsyslog start: console_loglevel = 4 ‒ After rsyslog start: console_loglevel = 1 ‒ Please add loglevel=9 or debug, and also “dmesg -n 8” for debugging
  • 15. 15 Dynamic debug • ddebug_query ‒ [KNL,DYNAMIC_DEBUG] Enable debug messages at early boot time. See Documentation/dynamic-debug- howto.txt for details. [1] ‒ Dynamic debug is designed to allow you to dynamically enable/disable kernel code to obtain additional kernel information. Currently, if ``CONFIG_DYNAMIC_DEBUG`` is set, then all ``pr_debug()``/``dev_dbg()`` and ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. [2]
  • 16. 16 Dynamic debug (cont.) • Kernel parameter: 'ddebug_query=file drivers/firmware/efi/efi-secret-key.c +p' 'ddebug_query=file kernel/module_signing.c +p; file crypto/asymmetric_keys/pkcs7_trust.c +p' • Userland command: # echo -n 'file drivers/base/firmware_class.c +p' > /sys/kernel/debug/dynamic_debug/control # cat /sys/kernel/debug/dynamic_debug/control
  • 17. 17 pr_debug() / dev_dbg() #if defined(CONFIG_DYNAMIC_DEBUG) #include <linux/dynamic_debug.h> #define pr_debug(fmt, ...) dynamic_pr_debug(fmt, ##__VA_ARGS__) #elif defined(DEBUG) #define pr_debug(fmt, ...) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug(fmt, ...) no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif
  • 20. 20 earlyprintk • Serial port: earlyprintk=ttyS0,115200 ‒ EFI framebuffer: earlyprintk=efi ‒ VGA: earlyprintk=vga ‒ USB2 debug port: earlyprintk=dbgp ‒ USB3 debug port: earlyprintk=xdbc • earlyprintk is useful when the kernel crashes before the normal console is initialized. It is not enabled by default because it has some cosmetic problems. ‒ It’s a OLD parameter in kernel • Only one of vga, efi, serial, or usb debug port can be used at a time. • early_printk() callers: e820, kaslr, mm(idt), perf
  • 21. 21 earlycon • Output early console device and options. • CONFIG_SERIAL_EARLYCON ‒ v3.16 kernel ‒ Support for early consoles with the earlycon parameter. This enables the console before standard serial driver is probed. The console is enabled when early_param is processed. • earlycon ‒ [X86] ACPI SPCR (Serial Port Console Redirection Table) ‒ [ARM64] Device Tree • earlycon=uart[8250],io,<addr>[,options] =uart[8250],mmio,<addr>[,options] ... ‒ earlycon=uart,io,0x3f8,115200 • EARLYCON_DECLARE() or OF_EARLYCON_DECLARE() in kernel ‒ Set initial function to __earlycon_table section
  • 22. 22 console • Output console device and options. • tty<n> ttyS<n>[,options] ttyUSB0[,options] ‒ Serial: console=ttyS0,115200n8 ‒ USB: console=ttyUSB0,115200n8 ‒ ARM: console=ttyAMA0,115200n8 • Maximum 8 consoles ‒ console_cmdline[MAX_CMDLINECONSOLES] ‒ #define MAX_CMDLINECONSOLES 8
  • 23. 23 Reading messages from consoles • screen command ‒ # screen /dev/ttyS0 115200 ‒ # screen -h 10000 /dev/ttyUSB1 115200 • minicom ‒ # minicom -b 115200 -D /dev/ttyUSB0
  • 24. 24 When can earlcon be enabled? No console before here
  • 25. 25 The debug log in early booting stage • For booting ‒ In EFI stub, the efi_printk() log is only for expected error. ‒ In kernel, earlyprintk= or earlycon= only be enabled after parse_early_param(). ‒ “KASLR using” message should be exposed with earlyprintk= or earlycon= ‒ KASLR (Kernel Address Space Layout Randomization) • For problems that occur before the serial console and EFI framebuffer are initialized [4] ‒ Debugging a mysterious reset with an infinite loop ‒ Debugging a hang by triggering a reset
  • 26. 26 DEBUG_LL and ARM • Kernel low-level debugging functions • CONFIG_DEBUG_LL ‒ ARM, Unicore32 ‒ Say Y here to include definitions of printascii, printch, printhex in the kernel. This is helpful if you are debugging code that executes before the console is initialized. ‒ Note that selecting this option will limit the kernel to a single UART definition, … this option should not be enabled for kernels that are intended to be portable. ‒ CONFIG_DEBUG_BCM2835 for Raspberry Pi 1 ‒ DEBUG_UART_PHYS = 0x20201000, DEBUG_UART_VIRT = 0xf0201000 ‒ CONFIG_DEBUG_BCM2836 for Raspberry Pi 2 ‒ DEBUG_UART_PHYS = 0x3f201000, DEBUG_UART_VIRT = 0xf0201000 • Should works with CONFIG_EARLY_PRINTK ‒ Enable by earlyprintk kernel parameter
  • 27. 27 netconsole • This module logs kernel printk messages over UDP allowing debugging of problem where disk logging fails and serial consoles are impractical. [3] • As a built-in, netconsole initializes immediately after NIC cards and will bring up the specified interface as soon as possible. While this doesn't allow capture of early kernel panics, it does capture most of the boot process. [3] • CONFIG_NETCONSOLE=y ‒ NIC driver must also be build-in • CONFIG_NETCONSOLE=m ‒ /etc/modules-load.d/netconsole.conf ‒ /etc/modprobe.d/netconsole.conf
  • 28. 28 netconsole (cont.) • Sender: netconsole=[+][src-port]@[src-ip]/[<dev>], [tgt-port]@<tgt-ip>/[tgt-macaddr] netconsole=6665@192.168.1.83/eth0,6666@192.168.1.11 /ab:cd:23:b0:14:b6 netconsole=@192.168.1.83/,@192.168.1.11/ • Receiver: netcat netcat -k -l -u 192.168.1.11 6666
  • 29. Q&A
  • 30. 30 Reference • [1] Documentation/admin-guide/kernel- parameters.txt, Linux Kernel • [2] Documentation/admin-guide/dynamic-debug- howto.rst, Linux Kernel • [3] Documentation/networking/netconsole.txt, Linux Kernel • [4] Early x86 Linux boot debug tricks, Matt Fleming ‒ http://www.codeblueprint.co.uk/2015/04/15/early-x86-linux- boot-debug-tricks.html
  • 32.
  • 33. Corporate Headquarters Maxfeldstrasse 5 90409 Nuremberg Germany +49 911 740 53 0 (Worldwide) www.suse.com Join us on: www.opensuse.org 33
  • 34. Unpublished Work of SUSE. All Rights Reserved. This work is an unpublished work and contains confidential, proprietary and trade secret information of SUSE. Access to this work is restricted to SUSE employees who have a need to know to perform tasks within the scope of their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated, abridged, condensed, expanded, collected, or adapted without the prior written consent of SUSE. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability. General Disclaimer This document is not to be construed as a promise by any participating company to develop, deliver, or market a product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. SUSE makes no representations or warranties with respect to the contents of this document, and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. The development, release, and timing of features or functionality described for SUSE products remains at the sole discretion of SUSE. Further, SUSE reserves the right to revise this document and to make changes to its content, at any time, without obligation to notify any person or entity of such revisions or changes. All SUSE marks referenced in this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All third-party trademarks are the property of their respective owners.