]> Git Repo - linux.git/commitdiff
Merge branch 'printk-rework' into for-linus
authorPetr Mladek <[email protected]>
Mon, 12 Oct 2020 11:01:37 +0000 (13:01 +0200)
committerPetr Mladek <[email protected]>
Mon, 12 Oct 2020 11:01:37 +0000 (13:01 +0200)
1  2 
Documentation/admin-guide/kdump/vmcoreinfo.rst
MAINTAINERS
drivers/base/core.c
include/linux/printk.h
init/Kconfig
kernel/printk/printk.c

index 2baad0bfb09d015f4dc6898ada73a78f28106d03,703bb9f92a39646a8874aa6590ccf22fbb626102..e44a6c01f33622441342388a9c3979af940e16bb
@@@ -93,11 -93,6 +93,11 @@@ It exists in the sparse memory mapping 
  similar to the mem_map variable, both of them are used to translate an
  address.
  
 +MAX_PHYSMEM_BITS
 +----------------
 +
 +Defines the maximum supported physical address space memory.
 +
  page
  ----
  
@@@ -189,50 -184,123 +189,123 @@@ from this
  Free areas descriptor. User-space tools use this value to iterate the
  free_area ranges. MAX_ORDER is used by the zone buddy allocator.
  
- log_first_idx
+ prb
+ ---
+ A pointer to the printk ringbuffer (struct printk_ringbuffer). This
+ may be pointing to the static boot ringbuffer or the dynamically
+ allocated ringbuffer, depending on when the the core dump occurred.
+ Used by user-space tools to read the active kernel log buffer.
+ printk_rb_static
+ ----------------
+ A pointer to the static boot printk ringbuffer. If @prb has a
+ different value, this is useful for viewing the initial boot messages,
+ which may have been overwritten in the dynamically allocated
+ ringbuffer.
+ clear_seq
+ ---------
+ The sequence number of the printk() record after the last clear
+ command. It indicates the first record after the last
+ SYSLOG_ACTION_CLEAR, like issued by 'dmesg -c'. Used by user-space
+ tools to dump a subset of the dmesg log.
+ printk_ringbuffer
+ -----------------
+ The size of a printk_ringbuffer structure. This structure contains all
+ information required for accessing the various components of the
+ kernel log buffer.
+ (printk_ringbuffer, desc_ring|text_data_ring|dict_data_ring|fail)
+ -----------------------------------------------------------------
+ Offsets for the various components of the printk ringbuffer. Used by
+ user-space tools to view the kernel log buffer without requiring the
+ declaration of the structure.
+ prb_desc_ring
  -------------
  
- Index of the first record stored in the buffer log_buf. Used by
user-space tools to read the strings in the log_buf.
+ The size of the prb_desc_ring structure. This structure contains
information about the set of record descriptors.
  
- log_buf
- -------
+ (prb_desc_ring, count_bits|descs|head_id|tail_id)
+ -------------------------------------------------
+ Offsets for the fields describing the set of record descriptors. Used
+ by user-space tools to be able to traverse the descriptors without
+ requiring the declaration of the structure.
  
- Console output is written to the ring buffer log_buf at index
- log_first_idx. Used to get the kernel log.
+ prb_desc
+ --------
  
- log_buf_len
+ The size of the prb_desc structure. This structure contains
+ information about a single record descriptor.
+ (prb_desc, info|state_var|text_blk_lpos|dict_blk_lpos)
+ ------------------------------------------------------
+ Offsets for the fields describing a record descriptors. Used by
+ user-space tools to be able to read descriptors without requiring
+ the declaration of the structure.
+ prb_data_blk_lpos
+ -----------------
+ The size of the prb_data_blk_lpos structure. This structure contains
+ information about where the text or dictionary data (data block) is
+ located within the respective data ring.
+ (prb_data_blk_lpos, begin|next)
+ -------------------------------
+ Offsets for the fields describing the location of a data block. Used
+ by user-space tools to be able to locate data blocks without
+ requiring the declaration of the structure.
+ printk_info
  -----------
  
- log_buf's length.
+ The size of the printk_info structure. This structure contains all
+ the meta-data for a record.
  
- clear_idx
- ---------
+ (printk_info, seq|ts_nsec|text_len|dict_len|caller_id)
+ ------------------------------------------------------
  
- The index that the next printk() record to read after the last clear
- command. It indicates the first record after the last SYSLOG_ACTION
- _CLEAR, like issued by 'dmesg -c'. Used by user-space tools to dump
- the dmesg log.
+ Offsets for the fields providing the meta-data for a record. Used by
+ user-space tools to be able to read the information without requiring
+ the declaration of the structure.
  
- log_next_idx
- ------------
+ prb_data_ring
+ -------------
  
- The index of the next record to store in the buffer log_buf. Used to
compute the index of the current buffer position.
+ The size of the prb_data_ring structure. This structure contains
information about a set of data blocks.
  
- printk_log
- ----------
+ (prb_data_ring, size_bits|data|head_lpos|tail_lpos)
+ ---------------------------------------------------
  
- The size of a structure printk_log. Used to compute the size of
- messages, and extract dmesg log. It encapsulates header information for
log_buf, such as timestamp, syslog level, etc.
+ Offsets for the fields describing a set of data blocks. Used by
+ user-space tools to be able to access the data blocks without
requiring the declaration of the structure.
  
- (printk_log, ts_nsec|len|text_len|dict_len)
- -------------------------------------------
+ atomic_long_t
+ -------------
+ The size of the atomic_long_t structure. Used by user-space tools to
+ be able to copy the full structure, regardless of its
+ architecture-specific implementation.
+ (atomic_long_t, counter)
+ ------------------------
  
- It represents field offsets in struct printk_log. User space tools
- parse it and check whether the values of printk_log's members have been
changed.
+ Offset for the long value of an atomic_long_t variable. Used by
+ user-space tools to access the long value without requiring the
architecture-specific declaration.
  
  (free_area.free_list, MIGRATE_TYPES)
  ------------------------------------
@@@ -404,17 -472,6 +477,17 @@@ KERNELPACMAS
  The mask to extract the Pointer Authentication Code from a kernel virtual
  address.
  
 +TCR_EL1.T1SZ
 +------------
 +
 +Indicates the size offset of the memory region addressed by TTBR1_EL1.
 +The region size is 2^(64-T1SZ) bytes.
 +
 +TTBR1_EL1 is the table base address register specified by ARMv8-A
 +architecture which is used to lookup the page-tables for the Virtual
 +addresses in the higher VA range (refer to ARMv8 ARM document for
 +more details).
 +
  arm
  ===
  
diff --combined MAINTAINERS
index c8e8232c65da93e38c0ecc4996aa15b2192d3546,6d61252f85060bb521a50f29dd0d98aa8171a256..5134012e4d06ad3030b2934536acefb2509d9119
@@@ -782,7 -782,7 +782,7 @@@ F: include/dt-bindings/reset/altr,rst-m
  F:    include/linux/mfd/altera-a10sr.h
  
  ALTERA TRIPLE SPEED ETHERNET DRIVER
 -M:    Thor Thayer <thor.thayer@linux.intel.com>
 +M:    Joyce Ooi <joyce.ooi@intel.com>
  L:    [email protected]
  S:    Maintained
  F:    drivers/net/ethernet/altera/
@@@ -830,20 -830,11 +830,20 @@@ F:      include/uapi/rdma/efa-abi.
  
  AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER
  M:    Tom Lendacky <[email protected]>
 +M:    John Allen <[email protected]>
  L:    [email protected]
  S:    Supported
  F:    drivers/crypto/ccp/
  F:    include/linux/ccp.h
  
 +AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER - SEV SUPPORT
 +M:    Brijesh Singh <[email protected]>
 +M:    Tom Lendacky <[email protected]>
 +L:    [email protected]
 +S:    Supported
 +F:    drivers/crypto/ccp/sev*
 +F:    include/uapi/linux/psp-sev.h
 +
  AMD DISPLAY CORE
  M:    Harry Wentland <[email protected]>
  M:    Leo Li <[email protected]>
@@@ -1434,7 -1425,7 +1434,7 @@@ F:      arch/arm*/include/asm/perf_event.
  F:    arch/arm*/kernel/hw_breakpoint.c
  F:    arch/arm*/kernel/perf_*
  F:    arch/arm/oprofile/common.c
 -F:    drivers/perf/*
 +F:    drivers/perf/
  F:    include/linux/perf/arm_pmu.h
  
  ARM PORT
@@@ -1606,9 -1597,6 +1606,9 @@@ F:      sound/soc/meson
  
  ARM/Amlogic Meson SoC support
  M:    Kevin Hilman <[email protected]>
 +R:    Neil Armstrong <[email protected]>
 +R:    Jerome Brunet <[email protected]>
 +R:    Martin Blumenstingl <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  L:    [email protected]
  S:    Maintained
@@@ -1629,7 -1617,7 +1629,7 @@@ L:      [email protected]
  S:    Maintained
  F:    arch/arm/boot/dts/alpine*
  F:    arch/arm/mach-alpine/
 -F:    arch/arm64/boot/dts/al/
 +F:    arch/arm64/boot/dts/amazon/
  F:    drivers/*/*alpine*
  
  ARM/ARTPEC MACHINE SUPPORT
@@@ -1966,14 -1954,6 +1966,14 @@@ F:    drivers/irqchip/irq-ixp4xx.
  F:    include/linux/irqchip/irq-ixp4xx.h
  F:    include/linux/platform_data/timer-ixp4xx.h
  
 +ARM/INTEL KEEMBAY ARCHITECTURE
 +M:    Paul J. Murphy <[email protected]>
 +M:    Daniele Alessandrelli <[email protected]>
 +S:    Maintained
 +F:    Documentation/devicetree/bindings/arm/intel,keembay.yaml
 +F:    arch/arm64/boot/dts/intel/keembay-evm.dts
 +F:    arch/arm64/boot/dts/intel/keembay-soc.dtsi
 +
  ARM/INTEL RESEARCH IMOTE/STARGATE 2 MACHINE SUPPORT
  M:    Jonathan Cameron <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
@@@ -2131,32 -2111,12 +2131,32 @@@ X:   drivers/net/wireless/atmel
  N:    at91
  N:    atmel
  
 +ARM/Microchip Sparx5 SoC support
 +M:    Lars Povlsen <[email protected]>
 +M:    Steen Hegelund <[email protected]>
 +M:    Microchip Linux Driver Support <[email protected]>
 +L:    [email protected] (moderated for non-subscribers)
 +S:    Supported
 +F:    arch/arm64/boot/dts/microchip/
 +N:    sparx5
 +
  ARM/MIOA701 MACHINE SUPPORT
  M:    Robert Jarzmik <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  S:    Maintained
  F:    arch/arm/mach-pxa/mioa701.c
  
 +ARM/MStar/Sigmastar Armv7 SoC support
 +M:    Daniel Palmer <[email protected]>
 +L:    [email protected] (moderated for non-subscribers)
 +S:    Maintained
 +W:    http://linux-chenxing.org/
 +F:    Documentation/devicetree/bindings/arm/mstar/*
 +F:    arch/arm/boot/dts/infinity*.dtsi
 +F:    arch/arm/boot/dts/mercury*.dtsi
 +F:    arch/arm/boot/dts/mstar-v7.dtsi
 +F:    arch/arm/mach-mstar/
 +
  ARM/NEC MOBILEPRO 900/c MACHINE SUPPORT
  M:    Michael Petchkovsky <[email protected]>
  S:    Maintained
@@@ -2969,7 -2929,6 +2969,7 @@@ F:      include/uapi/linux/atm
  
  ATMEL MACB ETHERNET DRIVER
  M:    Nicolas Ferre <[email protected]>
 +M:    Claudiu Beznea <[email protected]>
  S:    Supported
  F:    drivers/net/ethernet/cadence/
  
@@@ -3347,7 -3306,7 +3347,7 @@@ X:      arch/riscv/net/bpf_jit_comp32.
  
  BPF JIT for S390
  M:    Ilya Leoshkevich <[email protected]>
 -M:    Heiko Carstens <heiko.carstens@de.ibm.com>
 +M:    Heiko Carstens <hca@linux.ibm.com>
  M:    Vasily Gorbik <[email protected]>
  L:    [email protected]
  L:    [email protected]
@@@ -3987,7 -3946,7 +3987,7 @@@ L:      [email protected]
  S:    Supported
  F:    drivers/char/hw_random/cctrng.c
  F:    drivers/char/hw_random/cctrng.h
 -F:    Documentation/devicetree/bindings/rng/arm-cctrng.txt
 +F:    Documentation/devicetree/bindings/rng/arm-cctrng.yaml
  W:    https://developer.arm.com/products/system-ip/trustzone-cryptocell/cryptocell-700-family
  
  CEC FRAMEWORK
@@@ -5062,6 -5021,7 +5062,6 @@@ F:      drivers/mfd/da91??-*.
  F:    drivers/pinctrl/pinctrl-da90??.c
  F:    drivers/power/supply/da9052-battery.c
  F:    drivers/power/supply/da91??-*.c
 -F:    drivers/regulator/da903x.c
  F:    drivers/regulator/da9???-regulator.[ch]
  F:    drivers/regulator/slg51000-regulator.[ch]
  F:    drivers/rtc/rtc-da90??.c
@@@ -5151,7 -5111,7 +5151,7 @@@ M:      Vinod Koul <[email protected]
  L:    [email protected]
  S:    Maintained
  Q:    https://patchwork.kernel.org/project/linux-dmaengine/list/
 -T:    git git://git.infradead.org/users/vkoul/slave-dma.git
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git
  F:    Documentation/devicetree/bindings/dma/
  F:    Documentation/driver-api/dmaengine/
  F:    drivers/dma/
@@@ -5530,7 -5490,7 +5530,7 @@@ F:      include/uapi/drm/r128_drm.
  DRM DRIVER FOR RAYDIUM RM67191 PANELS
  M:    Robert Chiras <[email protected]>
  S:    Maintained
 -F:    Documentation/devicetree/bindings/display/panel/raydium,rm67191.txt
 +F:    Documentation/devicetree/bindings/display/panel/raydium,rm67191.yaml
  F:    drivers/gpu/drm/panel/panel-raydium-rm67191.c
  
  DRM DRIVER FOR ROCKTECH JH057N00900 PANELS
@@@ -6996,7 -6956,6 +6996,7 @@@ M:      Timur Tabi <[email protected]
  M:    Nicolin Chen <[email protected]>
  M:    Xiubo Li <[email protected]>
  R:    Fabio Estevam <[email protected]>
 +R:    Shengjiu Wang <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  L:    [email protected]
  S:    Maintained
@@@ -8374,7 -8333,7 +8374,7 @@@ M:      Alexander Aring <[email protected]
  M:    Stefan Schmidt <[email protected]>
  L:    [email protected]
  S:    Maintained
 -W:    http://wpan.cakelab.org/
 +W:    https://linux-wpan.org/
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan.git
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan-next.git
  F:    Documentation/networking/ieee802154.rst
  S:    Maintained
  F:    drivers/platform/x86/intel_atomisp2_pm.c
  
 +INTEL ATOMISP2 LED DRIVER
 +M:    Hans de Goede <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/platform/x86/intel_atomisp2_led.c
 +
  INTEL BROXTON PMC DRIVER
  M:    Mika Westerberg <[email protected]>
  M:    Zha Qipeng <[email protected]>
@@@ -9352,17 -9305,6 +9352,17 @@@ F:    Documentation/kbuild/kconfig
  F:    scripts/Kconfig.include
  F:    scripts/kconfig/
  
 +KCOV
 +R:    Dmitry Vyukov <[email protected]>
 +R:    Andrey Konovalov <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    Documentation/dev-tools/kcov.rst
 +F:    include/linux/kcov.h
 +F:    include/uapi/linux/kcov.h
 +F:    kernel/kcov.c
 +F:    scripts/Makefile.kcov
 +
  KCSAN
  M:    Marco Elver <[email protected]>
  R:    Dmitry Vyukov <[email protected]>
@@@ -10018,7 -9960,6 +10018,7 @@@ M:    Luc Maranget <[email protected]
  M:    "Paul E. McKenney" <[email protected]>
  R:    Akira Yokosawa <[email protected]>
  R:    Daniel Lustig <[email protected]>
 +R:    Joel Fernandes <[email protected]>
  L:    [email protected]
  L:    [email protected]
  S:    Supported
@@@ -10027,7 -9968,6 +10027,7 @@@ F:    Documentation/atomic_bitops.tx
  F:    Documentation/atomic_t.txt
  F:    Documentation/core-api/atomic_ops.rst
  F:    Documentation/core-api/refcount-vs-atomic.rst
 +F:    Documentation/litmus-tests/
  F:    Documentation/memory-barriers.txt
  F:    tools/memory-model/
  
@@@ -10868,7 -10808,7 +10868,7 @@@ F:   Documentation/devicetree/bindings/dm
  F:    drivers/dma/mediatek/
  
  MEDIATEK ETHERNET DRIVER
 -M:    Felix Fietkau <nbd@openwrt.org>
 +M:    Felix Fietkau <nbd@nbd.name>
  M:    John Crispin <[email protected]>
  M:    Sean Wang <[email protected]>
  M:    Mark Lee <[email protected]>
@@@ -11145,23 -11085,6 +11145,23 @@@ F: Documentation/core-api/boot-time-mm.
  F:    include/linux/memblock.h
  F:    mm/memblock.c
  
 +MEMORY CONTROLLER DRIVERS
 +M:    Krzysztof Kozlowski <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-mem-ctrl.git
 +F:    Documentation/devicetree/bindings/memory-controllers/
 +F:    drivers/memory/
 +
 +MEMORY FREQUENCY SCALING DRIVERS FOR NVIDIA TEGRA
 +M:    Dmitry Osipenko <[email protected]>
 +L:    [email protected]
 +L:    [email protected]
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git
 +S:    Maintained
 +F:    drivers/devfreq/tegra20-devfreq.c
 +F:    drivers/devfreq/tegra30-devfreq.c
 +
  MEMORY MANAGEMENT
  M:    Andrew Morton <[email protected]>
  L:    [email protected]
@@@ -11317,7 -11240,7 +11317,7 @@@ S:   Maintaine
  F:    drivers/crypto/atmel-ecc.*
  
  MICROCHIP I2C DRIVER
 -M:    Ludovic Desroches <ludovic.desroches@microchip.com>
 +M:    Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
  L:    [email protected]
  S:    Supported
  F:    drivers/i2c/busses/i2c-at91-*.c
@@@ -11410,17 -11333,17 +11410,17 @@@ F:        drivers/iio/adc/at91-sama5d2_adc.
  F:    include/dt-bindings/iio/adc/at91-sama5d2_adc.h
  
  MICROCHIP SAMA5D2-COMPATIBLE SHUTDOWN CONTROLLER
 -M:    Nicolas Ferre <nicolas.ferre@microchip.com>
 +M:    Claudiu Beznea <claudiu.beznea@microchip.com>
  S:    Supported
  F:    drivers/power/reset/at91-sama5d2_shdwc.c
  
  MICROCHIP SPI DRIVER
 -M:    Nicolas Ferre <nicolas.ferre@microchip.com>
 +M:    Tudor Ambarus <tudor.ambarus@microchip.com>
  S:    Supported
  F:    drivers/spi/spi-atmel.*
  
  MICROCHIP SSC DRIVER
 -M:    Nicolas Ferre <nicolas.ferre@microchip.com>
 +M:    Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
  L:    [email protected] (moderated for non-subscribers)
  S:    Supported
  F:    drivers/misc/atmel-ssc.c
@@@ -12772,14 -12695,13 +12772,14 @@@ F:        arch/mips/boot/dts/ralink/omega2p.dt
  
  OP-TEE DRIVER
  M:    Jens Wiklander <[email protected]>
 -L:    [email protected].org
 +L:    [email protected].org
  S:    Maintained
 +F:    Documentation/ABI/testing/sysfs-bus-optee-devices
  F:    drivers/tee/optee/
  
  OP-TEE RANDOM NUMBER GENERATOR (RNG) DRIVER
  M:    Sumit Garg <[email protected]>
 -L:    [email protected].org
 +L:    [email protected].org
  S:    Maintained
  F:    drivers/char/hw_random/optee-rng.c
  
@@@ -13658,6 -13580,16 +13658,6 @@@ F:  drivers/block/pktcdvd.
  F:    include/linux/pktcdvd.h
  F:    include/uapi/linux/pktcdvd.h
  
 -PKUNITY SOC DRIVERS
 -M:    Guan Xuetao <[email protected]>
 -S:    Maintained
 -W:    http://mprc.pku.edu.cn/~guanxuetao/linux
 -T:    git git://github.com/gxt/linux.git
 -F:    drivers/i2c/busses/i2c-puv3.c
 -F:    drivers/input/serio/i8042-unicore32io.h
 -F:    drivers/rtc/rtc-puv3.c
 -F:    drivers/video/fbdev/fb-puv3.c
 -
  PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER
  M:    Tomasz Duszynski <[email protected]>
  S:    Maintained
@@@ -13838,6 -13770,7 +13838,7 @@@ PRINT
  M:    Petr Mladek <[email protected]>
  M:    Sergey Senozhatsky <[email protected]>
  R:    Steven Rostedt <[email protected]>
+ R:    John Ogness <[email protected]>
  S:    Maintained
  F:    include/linux/printk.h
  F:    kernel/printk/
@@@ -14244,8 -14177,7 +14245,8 @@@ F:   Documentation/devicetree/bindings/ne
  F:    drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
  
  QUALCOMM GENERIC INTERFACE I2C DRIVER
 -M:    Alok Chauhan <[email protected]>
 +M:    Akash Asthana <[email protected]>
 +M:    Mukesh Savaliya <[email protected]>
  L:    [email protected]
  L:    [email protected]
  S:    Supported
@@@ -14506,7 -14438,7 +14507,7 @@@ T:   git git://git.kernel.org/pub/scm/lin
  F:    Documentation/RCU/
  F:    include/linux/rcu*
  F:    kernel/rcu/
 -X:    Documentation/RCU/torture.txt
 +X:    Documentation/RCU/torture.rst
  X:    include/linux/srcu*.h
  X:    kernel/rcu/srcu*.c
  
@@@ -14643,8 -14575,8 +14644,8 @@@ RENESAS R-CAR THERMAL DRIVER
  M:    Niklas Söderlund <[email protected]>
  L:    [email protected]
  S:    Supported
 -F:    Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt
 -F:    Documentation/devicetree/bindings/thermal/rcar-thermal.txt
 +F:    Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.yaml
 +F:    Documentation/devicetree/bindings/thermal/rcar-thermal.yaml
  F:    drivers/thermal/rcar_gen3_thermal.c
  F:    drivers/thermal/rcar_thermal.c
  
@@@ -14900,7 -14832,7 +14901,7 @@@ S:   Maintaine
  F:    drivers/video/fbdev/savage/
  
  S390
 -M:    Heiko Carstens <heiko.carstens@de.ibm.com>
 +M:    Heiko Carstens <hca@linux.ibm.com>
  M:    Vasily Gorbik <[email protected]>
  M:    Christian Borntraeger <[email protected]>
  L:    [email protected]
@@@ -14931,8 -14863,7 +14932,8 @@@ F:   drivers/s390/block/dasd
  F:    include/linux/dasd_mod.h
  
  S390 IOMMU (PCI)
 -M:    Gerald Schaefer <[email protected]>
 +M:    Matthew Rosato <[email protected]>
 +M:    Gerald Schaefer <[email protected]>
  L:    [email protected]
  S:    Supported
  W:    http://www.ibm.com/developerworks/linux/linux390/
@@@ -14960,7 -14891,7 +14961,7 @@@ F:   drivers/s390/net
  
  S390 PCI SUBSYSTEM
  M:    Niklas Schnelle <[email protected]>
 -M:    Gerald Schaefer <gerald.schaefer@de.ibm.com>
 +M:    Gerald Schaefer <gerald.schaefer@linux.ibm.com>
  L:    [email protected]
  S:    Supported
  W:    http://www.ibm.com/developerworks/linux/linux390/
@@@ -16128,10 -16059,8 +16129,10 @@@ SPARSE CHECKE
  M:    "Luc Van Oostenryck" <[email protected]>
  L:    [email protected]
  S:    Maintained
 -W:    https://sparse.wiki.kernel.org/
 +W:    https://sparse.docs.kernel.org/
  T:    git git://git.kernel.org/pub/scm/devel/sparse/sparse.git
 +Q:    https://patchwork.kernel.org/project/linux-sparse/list/
 +B:    https://bugzilla.kernel.org/enter_bug.cgi?component=Sparse&product=Tools
  F:    include/linux/compiler.h
  
  SPEAR CLOCK FRAMEWORK SUPPORT
@@@ -16844,7 -16773,7 +16845,7 @@@ F:   include/media/i2c/tw9910.
  
  TEE SUBSYSTEM
  M:    Jens Wiklander <[email protected]>
 -L:    [email protected].org
 +L:    [email protected].org
  S:    Maintained
  F:    Documentation/tee.txt
  F:    drivers/tee/
@@@ -17358,7 -17287,7 +17359,7 @@@ M:   Josh Triplett <[email protected]
  L:    [email protected]
  S:    Supported
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev
 -F:    Documentation/RCU/torture.txt
 +F:    Documentation/RCU/torture.rst
  F:    kernel/locking/locktorture.c
  F:    kernel/rcu/rcuperf.c
  F:    kernel/rcu/rcutorture.c
@@@ -17583,7 -17512,7 +17584,7 @@@ F:   Documentation/admin-guide/ufs.rs
  F:    fs/ufs/
  
  UHID USERSPACE HID IO DRIVER
 -M:    David Herrmann <dh.herrmann@googlemail.com>
 +M:    David Rheinsberg <david.rheinsberg@gmail.com>
  L:    [email protected]
  S:    Maintained
  F:    drivers/hid/uhid.c
  S:    Supported
  F:    fs/unicode/
  
 -UNICORE32 ARCHITECTURE
 -M:    Guan Xuetao <[email protected]>
 -S:    Maintained
 -W:    http://mprc.pku.edu.cn/~guanxuetao/linux
 -T:    git git://github.com/gxt/linux.git
 -F:    arch/unicore32/
 -
  UNIFDEF
  M:    Tony Finch <[email protected]>
  S:    Maintained
@@@ -18535,7 -18471,7 +18536,7 @@@ S:   Maintaine
  F:    drivers/rtc/rtc-sd3078.c
  
  WIIMOTE HID DRIVER
 -M:    David Herrmann <dh.herrmann@googlemail.com>
 +M:    David Rheinsberg <david.rheinsberg@gmail.com>
  L:    [email protected]
  S:    Maintained
  F:    drivers/hid/hid-wiimote*
diff --combined drivers/base/core.c
index 05d414e9e8a4085a2ff4099185ec02c565e4d30b,22d83aedb64ef8b45e5a27ae7f06f1bd2c5efa78..50041a8e9821b51c7927d7395b86a716d488040e
@@@ -50,7 -50,6 +50,7 @@@ static DEFINE_MUTEX(wfs_lock)
  static LIST_HEAD(deferred_sync);
  static unsigned int defer_sync_state_count = 1;
  static unsigned int defer_fw_devlink_count;
 +static LIST_HEAD(deferred_fw_devlink);
  static DEFINE_MUTEX(defer_fw_devlink_lock);
  static bool fw_devlink_is_permissive(void);
  
@@@ -755,11 -754,11 +755,11 @@@ static void __device_links_queue_sync_s
         */
        dev->state_synced = true;
  
 -      if (WARN_ON(!list_empty(&dev->links.defer_sync)))
 +      if (WARN_ON(!list_empty(&dev->links.defer_hook)))
                return;
  
        get_device(dev);
 -      list_add_tail(&dev->links.defer_sync, list);
 +      list_add_tail(&dev->links.defer_hook, list);
  }
  
  /**
@@@ -777,8 -776,8 +777,8 @@@ static void device_links_flush_sync_lis
  {
        struct device *dev, *tmp;
  
 -      list_for_each_entry_safe(dev, tmp, list, links.defer_sync) {
 -              list_del_init(&dev->links.defer_sync);
 +      list_for_each_entry_safe(dev, tmp, list, links.defer_hook) {
 +              list_del_init(&dev->links.defer_hook);
  
                if (dev != dont_lock_dev)
                        device_lock(dev);
@@@ -816,12 -815,12 +816,12 @@@ void device_links_supplier_sync_state_r
        if (defer_sync_state_count)
                goto out;
  
 -      list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_sync) {
 +      list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_hook) {
                /*
                 * Delete from deferred_sync list before queuing it to
 -               * sync_list because defer_sync is used for both lists.
 +               * sync_list because defer_hook is used for both lists.
                 */
 -              list_del_init(&dev->links.defer_sync);
 +              list_del_init(&dev->links.defer_hook);
                __device_links_queue_sync_state(dev, &sync_list);
        }
  out:
@@@ -839,8 -838,8 +839,8 @@@ late_initcall(sync_state_resume_initcal
  
  static void __device_links_supplier_defer_sync(struct device *sup)
  {
 -      if (list_empty(&sup->links.defer_sync) && dev_has_sync_state(sup))
 -              list_add_tail(&sup->links.defer_sync, &deferred_sync);
 +      if (list_empty(&sup->links.defer_hook) && dev_has_sync_state(sup))
 +              list_add_tail(&sup->links.defer_hook, &deferred_sync);
  }
  
  static void device_link_drop_managed(struct device_link *link)
@@@ -1053,7 -1052,7 +1053,7 @@@ void device_links_driver_cleanup(struc
                WRITE_ONCE(link->status, DL_STATE_DORMANT);
        }
  
 -      list_del_init(&dev->links.defer_sync);
 +      list_del_init(&dev->links.defer_hook);
        __device_links_no_driver(dev);
  
        device_links_write_unlock();
@@@ -1245,12 -1244,6 +1245,12 @@@ static void fw_devlink_link_device(stru
                        fw_ret = -EAGAIN;
        } else {
                fw_ret = -ENODEV;
 +              /*
 +               * defer_hook is not used to add device to deferred_sync list
 +               * until device is bound. Since deferred fw devlink also blocks
 +               * probing, same list hook can be used for deferred_fw_devlink.
 +               */
 +              list_add_tail(&dev->links.defer_hook, &deferred_fw_devlink);
        }
  
        if (fw_ret == -ENODEV)
@@@ -1319,9 -1312,6 +1319,9 @@@ void fw_devlink_pause(void
   */
  void fw_devlink_resume(void)
  {
 +      struct device *dev, *tmp;
 +      LIST_HEAD(probe_list);
 +
        mutex_lock(&defer_fw_devlink_lock);
        if (!defer_fw_devlink_count) {
                WARN(true, "Unmatched fw_devlink pause/resume!");
                goto out;
  
        device_link_add_missing_supplier_links();
 -      driver_deferred_probe_force_trigger();
 +      list_splice_tail_init(&deferred_fw_devlink, &probe_list);
  out:
        mutex_unlock(&defer_fw_devlink_lock);
 +
 +      /*
 +       * bus_probe_device() can cause new devices to get added and they'll
 +       * try to grab defer_fw_devlink_lock. So, this needs to be done outside
 +       * the defer_fw_devlink_lock.
 +       */
 +      list_for_each_entry_safe(dev, tmp, &probe_list, links.defer_hook) {
 +              list_del_init(&dev->links.defer_hook);
 +              bus_probe_device(dev);
 +      }
  }
  /* Device links support end. */
  
@@@ -2192,7 -2172,7 +2192,7 @@@ void device_initialize(struct device *d
        INIT_LIST_HEAD(&dev->links.consumers);
        INIT_LIST_HEAD(&dev->links.suppliers);
        INIT_LIST_HEAD(&dev->links.needs_suppliers);
 -      INIT_LIST_HEAD(&dev->links.defer_sync);
 +      INIT_LIST_HEAD(&dev->links.defer_hook);
        dev->links.status = DL_DEV_NO_DRIVER;
  }
  EXPORT_SYMBOL_GPL(device_initialize);
@@@ -3835,22 -3815,21 +3835,21 @@@ void device_shutdown(void
   */
  
  #ifdef CONFIG_PRINTK
- static int
create_syslog_header(const struct device *dev, char *hdr, size_t hdrlen)
+ static void
set_dev_info(const struct device *dev, struct dev_printk_info *dev_info)
  {
        const char *subsys;
-       size_t pos = 0;
+       memset(dev_info, 0, sizeof(*dev_info));
  
        if (dev->class)
                subsys = dev->class->name;
        else if (dev->bus)
                subsys = dev->bus->name;
        else
-               return 0;
+               return;
  
-       pos += snprintf(hdr + pos, hdrlen - pos, "SUBSYSTEM=%s", subsys);
-       if (pos >= hdrlen)
-               goto overflow;
+       strscpy(dev_info->subsystem, subsys, sizeof(dev_info->subsystem));
  
        /*
         * Add device identifier DEVICE=:
                        c = 'b';
                else
                        c = 'c';
-               pos++;
-               pos += snprintf(hdr + pos, hdrlen - pos,
-                               "DEVICE=%c%u:%u",
-                               c, MAJOR(dev->devt), MINOR(dev->devt));
+               snprintf(dev_info->device, sizeof(dev_info->device),
+                        "%c%u:%u", c, MAJOR(dev->devt), MINOR(dev->devt));
        } else if (strcmp(subsys, "net") == 0) {
                struct net_device *net = to_net_dev(dev);
  
-               pos++;
-               pos += snprintf(hdr + pos, hdrlen - pos,
-                               "DEVICE=n%u", net->ifindex);
+               snprintf(dev_info->device, sizeof(dev_info->device),
+                        "n%u", net->ifindex);
        } else {
-               pos++;
-               pos += snprintf(hdr + pos, hdrlen - pos,
-                               "DEVICE=+%s:%s", subsys, dev_name(dev));
+               snprintf(dev_info->device, sizeof(dev_info->device),
+                        "+%s:%s", subsys, dev_name(dev));
        }
-       if (pos >= hdrlen)
-               goto overflow;
-       return pos;
- overflow:
-       dev_WARN(dev, "device/subsystem name too long");
-       return 0;
  }
  
  int dev_vprintk_emit(int level, const struct device *dev,
                     const char *fmt, va_list args)
  {
-       char hdr[128];
-       size_t hdrlen;
+       struct dev_printk_info dev_info;
  
-       hdrlen = create_syslog_header(dev, hdr, sizeof(hdr));
+       set_dev_info(dev, &dev_info);
  
-       return vprintk_emit(0, level, hdrlen ? hdr : NULL, hdrlen, fmt, args);
+       return vprintk_emit(0, level, &dev_info, fmt, args);
  }
  EXPORT_SYMBOL(dev_vprintk_emit);
  
diff --combined include/linux/printk.h
index f749a2c2e7a5c75a5b6816c7d1cb07e6a249a372,071500ee72815ea5494eab33e6f1adbbc917e66e..78479633ccfcc3b4360aeccfef8e197557500616
@@@ -7,13 -7,10 +7,13 @@@
  #include <linux/kern_levels.h>
  #include <linux/linkage.h>
  #include <linux/cache.h>
 +#include <linux/ratelimit_types.h>
  
  extern const char linux_banner[];
  extern const char linux_proc_banner[];
  
 +extern int oops_in_progress;  /* If set, an oops, panic(), BUG() or die() is in progress */
 +
  #define PRINTK_MAX_SINGLE_HEADER_LEN 2
  
  static inline int printk_get_level(const char *buffer)
@@@ -161,10 -158,12 +161,12 @@@ static inline void printk_nmi_direct_en
  static inline void printk_nmi_direct_exit(void) { }
  #endif /* PRINTK_NMI */
  
+ struct dev_printk_info;
  #ifdef CONFIG_PRINTK
- asmlinkage __printf(5, 0)
+ asmlinkage __printf(4, 0)
  int vprintk_emit(int facility, int level,
-                const char *dict, size_t dictlen,
+                const struct dev_printk_info *dev_info,
                 const char *fmt, va_list args);
  
  asmlinkage __printf(1, 0)
diff --combined init/Kconfig
index f4bffefdbed5098cb58f06d89b655ee43d3c6ef5,485f7e53a8a59edf87a08a3ad3f2d9bffd7762c9..6edb2d9cdf3f31cacf1a450f1280ae3b900c16ff
@@@ -49,13 -49,13 +49,13 @@@ config CLANG_VERSIO
  
  config CC_CAN_LINK
        bool
 -      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m64-flag)) if 64BIT
 -      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m32-flag))
 +      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag)) if 64BIT
 +      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m32-flag))
  
  config CC_CAN_LINK_STATIC
        bool
 -      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m64-flag)) if 64BIT
 -      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m32-flag))
 +      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag) -static) if 64BIT
 +      default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m32-flag) -static)
  
  config CC_HAS_ASM_GOTO
        def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
@@@ -191,16 -191,13 +191,16 @@@ config HAVE_KERNEL_LZ
  config HAVE_KERNEL_LZ4
        bool
  
 +config HAVE_KERNEL_ZSTD
 +      bool
 +
  config HAVE_KERNEL_UNCOMPRESSED
        bool
  
  choice
        prompt "Kernel compression mode"
        default KERNEL_GZIP
 -      depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 || HAVE_KERNEL_UNCOMPRESSED
 +      depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 || HAVE_KERNEL_ZSTD || HAVE_KERNEL_UNCOMPRESSED
        help
          The linux kernel is a kind of self-extracting executable.
          Several compression algorithms are available, which differ
@@@ -279,16 -276,6 +279,16 @@@ config KERNEL_LZ
          is about 8% bigger than LZO. But the decompression speed is
          faster than LZO.
  
 +config KERNEL_ZSTD
 +      bool "ZSTD"
 +      depends on HAVE_KERNEL_ZSTD
 +      help
 +        ZSTD is a compression algorithm targeting intermediate compression
 +        with fast decompression speed. It will compress better than GZIP and
 +        decompress around the same speed as LZO, but slower than LZ4. You
 +        will need at least 192 KB RAM or more for booting. The zstd command
 +        line tool is required for compression.
 +
  config KERNEL_UNCOMPRESSED
        bool "None"
        depends on HAVE_KERNEL_UNCOMPRESSED
@@@ -505,23 -492,8 +505,23 @@@ config HAVE_SCHED_AVG_IR
        depends on SMP
  
  config SCHED_THERMAL_PRESSURE
 -      bool "Enable periodic averaging of thermal pressure"
 +      bool
 +      default y if ARM && ARM_CPU_TOPOLOGY
 +      default y if ARM64
        depends on SMP
 +      depends on CPU_FREQ_THERMAL
 +      help
 +        Select this option to enable thermal pressure accounting in the
 +        scheduler. Thermal pressure is the value conveyed to the scheduler
 +        that reflects the reduction in CPU compute capacity resulted from
 +        thermal throttling. Thermal throttling occurs when the performance of
 +        a CPU is capped due to high operating temperatures.
 +
 +        If selected, the scheduler will be able to balance tasks accordingly,
 +        i.e. put less load on throttled CPUs than on non/less throttled ones.
 +
 +        This requires the architecture to implement
 +        arch_set_thermal_pressure() and arch_get_thermal_pressure().
  
  config BSD_PROCESS_ACCT
        bool "BSD Process Accounting"
@@@ -682,7 -654,8 +682,8 @@@ config IKHEADER
  
  config LOG_BUF_SHIFT
        int "Kernel log buffer size (16 => 64KB, 17 => 128KB)"
-       range 12 25
+       range 12 25 if !H8300
+       range 12 19 if H8300
        default 17
        depends on PRINTK
        help
diff --combined kernel/printk/printk.c
index 8c870ba7607167562c034b3e2dc4682eb0f904bc,f5c2945d1e3f486b391d876ed95daf991344f7c6..fe64a49344bf5231fbc80fc8f8a26d714accbe07
@@@ -55,6 -55,7 +55,7 @@@
  #define CREATE_TRACE_POINTS
  #include <trace/events/printk.h>
  
+ #include "printk_ringbuffer.h"
  #include "console_cmdline.h"
  #include "braille.h"
  #include "internal.h"
@@@ -294,30 -295,22 +295,22 @@@ enum con_msg_format_flags 
  static int console_msg_format = MSG_FORMAT_DEFAULT;
  
  /*
-  * The printk log buffer consists of a chain of concatenated variable
-  * length records. Every record starts with a record header, containing
-  * the overall length of the record.
+  * The printk log buffer consists of a sequenced collection of records, each
+  * containing variable length message text. Every record also contains its
+  * own meta-data (@info).
   *
-  * The heads to the first and last entry in the buffer, as well as the
-  * sequence numbers of these entries are maintained when messages are
-  * stored.
+  * Every record meta-data carries the timestamp in microseconds, as well as
+  * the standard userspace syslog level and syslog facility. The usual kernel
+  * messages use LOG_KERN; userspace-injected messages always carry a matching
+  * syslog facility, by default LOG_USER. The origin of every message can be
+  * reliably determined that way.
   *
-  * If the heads indicate available messages, the length in the header
-  * tells the start next message. A length == 0 for the next message
-  * indicates a wrap-around to the beginning of the buffer.
+  * The human readable log message of a record is available in @text, the
+  * length of the message text in @text_len. The stored message is not
+  * terminated.
   *
-  * Every record carries the monotonic timestamp in microseconds, as well as
-  * the standard userspace syslog level and syslog facility. The usual
-  * kernel messages use LOG_KERN; userspace-injected messages always carry
-  * a matching syslog facility, by default LOG_USER. The origin of every
-  * message can be reliably determined that way.
-  *
-  * The human readable log message directly follows the message header. The
-  * length of the message text is stored in the header, the stored message
-  * is not terminated.
-  *
-  * Optionally, a message can carry a dictionary of properties (key/value pairs),
-  * to provide userspace with a machine-readable message context.
+  * Optionally, a record can carry a dictionary of properties (key/value
+  * pairs), to provide userspace with a machine-readable message context.
   *
   * Examples for well-defined, commonly used property names are:
   *   DEVICE=b12:8               device identifier
   *                                +sound:card0  subsystem:devname
   *   SUBSYSTEM=pci              driver-core subsystem name
   *
-  * Valid characters in property names are [a-zA-Z0-9.-_]. The plain text value
-  * follows directly after a '=' character. Every property is terminated by
-  * a '\0' character. The last property is not terminated.
-  *
-  * Example of a message structure:
-  *   0000  ff 8f 00 00 00 00 00 00      monotonic time in nsec
-  *   0008  34 00                        record is 52 bytes long
-  *   000a        0b 00                  text is 11 bytes long
-  *   000c              1f 00            dictionary is 23 bytes long
-  *   000e                    03 00      LOG_KERN (facility) LOG_ERR (level)
-  *   0010  69 74 27 73 20 61 20 6c      "it's a l"
-  *         69 6e 65                     "ine"
-  *   001b           44 45 56 49 43      "DEVIC"
-  *         45 3d 62 38 3a 32 00 44      "E=b8:2\0D"
-  *         52 49 56 45 52 3d 62 75      "RIVER=bu"
-  *         67                           "g"
-  *   0032     00 00 00                  padding to next message header
-  *
-  * The 'struct printk_log' buffer header must never be directly exported to
+  * Valid characters in property names are [a-zA-Z0-9.-_]. Property names
+  * and values are terminated by a '\0' character.
+  *
+  * Example of record values:
+  *   record.text_buf                = "it's a line" (unterminated)
+  *   record.info.seq                = 56
+  *   record.info.ts_nsec            = 36863
+  *   record.info.text_len           = 11
+  *   record.info.facility           = 0 (LOG_KERN)
+  *   record.info.flags              = 0
+  *   record.info.level              = 3 (LOG_ERR)
+  *   record.info.caller_id          = 299 (task 299)
+  *   record.info.dev_info.subsystem = "pci" (terminated)
+  *   record.info.dev_info.device    = "+pci:0000:00:01.0" (terminated)
+  *
+  * The 'struct printk_info' buffer must never be directly exported to
   * userspace, it is a kernel-private implementation detail that might
   * need to be changed in the future, when the requirements change.
   *
@@@ -365,23 -355,6 +355,6 @@@ enum log_flags 
        LOG_CONT        = 8,    /* text is a fragment of a continuation line */
  };
  
- struct printk_log {
-       u64 ts_nsec;            /* timestamp in nanoseconds */
-       u16 len;                /* length of entire record */
-       u16 text_len;           /* length of text buffer */
-       u16 dict_len;           /* length of dictionary buffer */
-       u8 facility;            /* syslog facility */
-       u8 flags:5;             /* internal record flags */
-       u8 level:3;             /* syslog level */
- #ifdef CONFIG_PRINTK_CALLER
-       u32 caller_id;            /* thread id or processor id */
- #endif
- }
- #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- __packed __aligned(4)
- #endif
- ;
  /*
   * The logbuf_lock protects kmsg buffer, indices, counters.  This can be taken
   * within the scheduler's rq lock. It must be released before calling
@@@ -421,26 -394,16 +394,16 @@@ DEFINE_RAW_SPINLOCK(logbuf_lock)
  DECLARE_WAIT_QUEUE_HEAD(log_wait);
  /* the next printk record to read by syslog(READ) or /proc/kmsg */
  static u64 syslog_seq;
- static u32 syslog_idx;
  static size_t syslog_partial;
  static bool syslog_time;
  
- /* index and sequence number of the first record stored in the buffer */
- static u64 log_first_seq;
- static u32 log_first_idx;
- /* index and sequence number of the next record to store in the buffer */
- static u64 log_next_seq;
- static u32 log_next_idx;
  /* the next printk record to write to the console */
  static u64 console_seq;
- static u32 console_idx;
  static u64 exclusive_console_stop_seq;
+ static unsigned long console_dropped;
  
  /* the next printk record to read after the last 'clear' command */
  static u64 clear_seq;
- static u32 clear_idx;
  
  #ifdef CONFIG_PRINTK_CALLER
  #define PREFIX_MAX            48
  #define LOG_FACILITY(v)               ((v) >> 3 & 0xff)
  
  /* record buffer */
- #define LOG_ALIGN __alignof__(struct printk_log)
+ #define LOG_ALIGN __alignof__(unsigned long)
  #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
  #define LOG_BUF_LEN_MAX (u32)(1 << 31)
  static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
  static char *log_buf = __log_buf;
  static u32 log_buf_len = __LOG_BUF_LEN;
  
+ /*
+  * Define the average message size. This only affects the number of
+  * descriptors that will be available. Underestimating is better than
+  * overestimating (too many available descriptors is better than not enough).
+  */
+ #define PRB_AVGBITS 5 /* 32 character average length */
+ #if CONFIG_LOG_BUF_SHIFT <= PRB_AVGBITS
+ #error CONFIG_LOG_BUF_SHIFT value too small.
+ #endif
+ _DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
+                PRB_AVGBITS, &__log_buf[0]);
+ static struct printk_ringbuffer printk_rb_dynamic;
+ static struct printk_ringbuffer *prb = &printk_rb_static;
  /*
   * We cannot access per-CPU data (e.g. per-CPU flush irq_work) before
   * per_cpu_areas are initialised. This variable is set to true when
@@@ -484,108 -464,6 +464,6 @@@ u32 log_buf_len_get(void
        return log_buf_len;
  }
  
- /* human readable text of the record */
- static char *log_text(const struct printk_log *msg)
- {
-       return (char *)msg + sizeof(struct printk_log);
- }
- /* optional key/value pair dictionary attached to the record */
- static char *log_dict(const struct printk_log *msg)
- {
-       return (char *)msg + sizeof(struct printk_log) + msg->text_len;
- }
- /* get record by index; idx must point to valid msg */
- static struct printk_log *log_from_idx(u32 idx)
- {
-       struct printk_log *msg = (struct printk_log *)(log_buf + idx);
-       /*
-        * A length == 0 record is the end of buffer marker. Wrap around and
-        * read the message at the start of the buffer.
-        */
-       if (!msg->len)
-               return (struct printk_log *)log_buf;
-       return msg;
- }
- /* get next record; idx must point to valid msg */
- static u32 log_next(u32 idx)
- {
-       struct printk_log *msg = (struct printk_log *)(log_buf + idx);
-       /* length == 0 indicates the end of the buffer; wrap */
-       /*
-        * A length == 0 record is the end of buffer marker. Wrap around and
-        * read the message at the start of the buffer as *this* one, and
-        * return the one after that.
-        */
-       if (!msg->len) {
-               msg = (struct printk_log *)log_buf;
-               return msg->len;
-       }
-       return idx + msg->len;
- }
- /*
-  * Check whether there is enough free space for the given message.
-  *
-  * The same values of first_idx and next_idx mean that the buffer
-  * is either empty or full.
-  *
-  * If the buffer is empty, we must respect the position of the indexes.
-  * They cannot be reset to the beginning of the buffer.
-  */
- static int logbuf_has_space(u32 msg_size, bool empty)
- {
-       u32 free;
-       if (log_next_idx > log_first_idx || empty)
-               free = max(log_buf_len - log_next_idx, log_first_idx);
-       else
-               free = log_first_idx - log_next_idx;
-       /*
-        * We need space also for an empty header that signalizes wrapping
-        * of the buffer.
-        */
-       return free >= msg_size + sizeof(struct printk_log);
- }
- static int log_make_free_space(u32 msg_size)
- {
-       while (log_first_seq < log_next_seq &&
-              !logbuf_has_space(msg_size, false)) {
-               /* drop old messages until we have enough contiguous space */
-               log_first_idx = log_next(log_first_idx);
-               log_first_seq++;
-       }
-       if (clear_seq < log_first_seq) {
-               clear_seq = log_first_seq;
-               clear_idx = log_first_idx;
-       }
-       /* sequence numbers are equal, so the log buffer is empty */
-       if (logbuf_has_space(msg_size, log_first_seq == log_next_seq))
-               return 0;
-       return -ENOMEM;
- }
- /* compute the message size including the padding bytes */
- static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len)
- {
-       u32 size;
-       size = sizeof(struct printk_log) + text_len + dict_len;
-       *pad_len = (-size) & (LOG_ALIGN - 1);
-       size += *pad_len;
-       return size;
- }
  /*
   * Define how much of the log buffer we could take at maximum. The value
   * must be greater than two. Note that only half of the buffer is available
  #define MAX_LOG_TAKE_PART 4
  static const char trunc_msg[] = "<truncated>";
  
- static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len,
-                       u16 *dict_len, u32 *pad_len)
+ static void truncate_msg(u16 *text_len, u16 *trunc_msg_len)
  {
        /*
         * The message should not take the whole buffer. Otherwise, it might
         * get removed too soon.
         */
        u32 max_text_len = log_buf_len / MAX_LOG_TAKE_PART;
        if (*text_len > max_text_len)
                *text_len = max_text_len;
-       /* enable the warning message */
+       /* enable the warning message (if there is room) */
        *trunc_msg_len = strlen(trunc_msg);
-       /* disable the "dict" completely */
-       *dict_len = 0;
-       /* compute the size again, count also the warning message */
-       return msg_used_size(*text_len + *trunc_msg_len, 0, pad_len);
+       if (*text_len >= *trunc_msg_len)
+               *text_len -= *trunc_msg_len;
+       else
+               *trunc_msg_len = 0;
  }
  
  /* insert record into the buffer, discard old ones, update heads */
  static int log_store(u32 caller_id, int facility, int level,
                     enum log_flags flags, u64 ts_nsec,
-                    const char *dict, u16 dict_len,
+                    const struct dev_printk_info *dev_info,
                     const char *text, u16 text_len)
  {
-       struct printk_log *msg;
-       u32 size, pad_len;
+       struct prb_reserved_entry e;
+       struct printk_record r;
        u16 trunc_msg_len = 0;
  
-       /* number of '\0' padding bytes to next message */
-       size = msg_used_size(text_len, dict_len, &pad_len);
+       prb_rec_init_wr(&r, text_len);
  
-       if (log_make_free_space(size)) {
+       if (!prb_reserve(&e, prb, &r)) {
                /* truncate the message if it is too long for empty buffer */
-               size = truncate_msg(&text_len, &trunc_msg_len,
-                                   &dict_len, &pad_len);
+               truncate_msg(&text_len, &trunc_msg_len);
+               prb_rec_init_wr(&r, text_len + trunc_msg_len);
                /* survive when the log buffer is too small for trunc_msg */
-               if (log_make_free_space(size))
+               if (!prb_reserve(&e, prb, &r))
                        return 0;
        }
  
-       if (log_next_idx + size + sizeof(struct printk_log) > log_buf_len) {
-               /*
-                * This message + an additional empty header does not fit
-                * at the end of the buffer. Add an empty header with len == 0
-                * to signify a wrap around.
-                */
-               memset(log_buf + log_next_idx, 0, sizeof(struct printk_log));
-               log_next_idx = 0;
-       }
        /* fill message */
-       msg = (struct printk_log *)(log_buf + log_next_idx);
-       memcpy(log_text(msg), text, text_len);
-       msg->text_len = text_len;
-       if (trunc_msg_len) {
-               memcpy(log_text(msg) + text_len, trunc_msg, trunc_msg_len);
-               msg->text_len += trunc_msg_len;
-       }
-       memcpy(log_dict(msg), dict, dict_len);
-       msg->dict_len = dict_len;
-       msg->facility = facility;
-       msg->level = level & 7;
-       msg->flags = flags & 0x1f;
+       memcpy(&r.text_buf[0], text, text_len);
+       if (trunc_msg_len)
+               memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len);
+       r.info->text_len = text_len + trunc_msg_len;
+       r.info->facility = facility;
+       r.info->level = level & 7;
+       r.info->flags = flags & 0x1f;
        if (ts_nsec > 0)
-               msg->ts_nsec = ts_nsec;
+               r.info->ts_nsec = ts_nsec;
        else
-               msg->ts_nsec = local_clock();
- #ifdef CONFIG_PRINTK_CALLER
-       msg->caller_id = caller_id;
- #endif
-       memset(log_dict(msg) + dict_len, 0, pad_len);
-       msg->len = size;
+               r.info->ts_nsec = local_clock();
+       r.info->caller_id = caller_id;
+       if (dev_info)
+               memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info));
  
        /* insert message */
-       log_next_idx += msg->len;
-       log_next_seq++;
+       if ((flags & LOG_CONT) || !(flags & LOG_NEWLINE))
+               prb_commit(&e);
+       else
+               prb_final_commit(&e);
  
-       return msg->text_len;
+       return (text_len + trunc_msg_len);
  }
  
  int dmesg_restrict = IS_ENABLED(CONFIG_SECURITY_DMESG_RESTRICT);
@@@ -723,13 -586,13 +586,13 @@@ static void append_char(char **pp, cha
                *(*pp)++ = c;
  }
  
- static ssize_t msg_print_ext_header(char *buf, size_t size,
-                                   struct printk_log *msg, u64 seq)
+ static ssize_t info_print_ext_header(char *buf, size_t size,
+                                    struct printk_info *info)
  {
-       u64 ts_usec = msg->ts_nsec;
+       u64 ts_usec = info->ts_nsec;
        char caller[20];
  #ifdef CONFIG_PRINTK_CALLER
-       u32 id = msg->caller_id;
+       u32 id = info->caller_id;
  
        snprintf(caller, sizeof(caller), ",caller=%c%u",
                 id & 0x80000000 ? 'C' : 'T', id & ~0x80000000);
        do_div(ts_usec, 1000);
  
        return scnprintf(buf, size, "%u,%llu,%llu,%c%s;",
-                        (msg->facility << 3) | msg->level, seq, ts_usec,
-                        msg->flags & LOG_CONT ? 'c' : '-', caller);
+                        (info->facility << 3) | info->level, info->seq,
+                        ts_usec, info->flags & LOG_CONT ? 'c' : '-', caller);
  }
  
- static ssize_t msg_print_ext_body(char *buf, size_t size,
-                                 char *dict, size_t dict_len,
-                                 char *text, size_t text_len)
+ static ssize_t msg_add_ext_text(char *buf, size_t size,
+                               const char *text, size_t text_len,
+                               unsigned char endc)
  {
        char *p = buf, *e = buf + size;
        size_t i;
                else
                        append_char(&p, e, c);
        }
-       append_char(&p, e, '\n');
+       append_char(&p, e, endc);
  
-       if (dict_len) {
-               bool line = true;
+       return p - buf;
+ }
  
-               for (i = 0; i < dict_len; i++) {
-                       unsigned char c = dict[i];
+ static ssize_t msg_add_dict_text(char *buf, size_t size,
+                                const char *key, const char *val)
+ {
+       size_t val_len = strlen(val);
+       ssize_t len;
  
-                       if (line) {
-                               append_char(&p, e, ' ');
-                               line = false;
-                       }
+       if (!val_len)
+               return 0;
  
-                       if (c == '\0') {
-                               append_char(&p, e, '\n');
-                               line = true;
-                               continue;
-                       }
+       len = msg_add_ext_text(buf, size, "", 0, ' ');  /* dict prefix */
+       len += msg_add_ext_text(buf + len, size - len, key, strlen(key), '=');
+       len += msg_add_ext_text(buf + len, size - len, val, val_len, '\n');
  
-                       if (c < ' ' || c >= 127 || c == '\\') {
-                               p += scnprintf(p, e - p, "\\x%02x", c);
-                               continue;
-                       }
+       return len;
+ }
  
-                       append_char(&p, e, c);
-               }
-               append_char(&p, e, '\n');
-       }
+ static ssize_t msg_print_ext_body(char *buf, size_t size,
+                                 char *text, size_t text_len,
+                                 struct dev_printk_info *dev_info)
+ {
+       ssize_t len;
  
-       return p - buf;
+       len = msg_add_ext_text(buf, size, text, text_len, '\n');
+       if (!dev_info)
+               goto out;
+       len += msg_add_dict_text(buf + len, size - len, "SUBSYSTEM",
+                                dev_info->subsystem);
+       len += msg_add_dict_text(buf + len, size - len, "DEVICE",
+                                dev_info->device);
+ out:
+       return len;
  }
  
  /* /dev/kmsg - userspace message inject/listen interface */
  struct devkmsg_user {
        u64 seq;
-       u32 idx;
        struct ratelimit_state rs;
        struct mutex lock;
        char buf[CONSOLE_EXT_LOG_MAX];
+       struct printk_info info;
+       char text_buf[CONSOLE_EXT_LOG_MAX];
+       struct printk_record record;
  };
  
  static __printf(3, 4) __cold
@@@ -808,7 -682,7 +682,7 @@@ int devkmsg_emit(int facility, int leve
        int r;
  
        va_start(args, fmt);
-       r = vprintk_emit(facility, level, NULL, 0, fmt, args);
+       r = vprintk_emit(facility, level, NULL, fmt, args);
        va_end(args);
  
        return r;
@@@ -881,7 -755,7 +755,7 @@@ static ssize_t devkmsg_read(struct fil
                            size_t count, loff_t *ppos)
  {
        struct devkmsg_user *user = file->private_data;
-       struct printk_log *msg;
+       struct printk_record *r = &user->record;
        size_t len;
        ssize_t ret;
  
                return ret;
  
        logbuf_lock_irq();
-       while (user->seq == log_next_seq) {
+       if (!prb_read_valid(prb, user->seq, r)) {
                if (file->f_flags & O_NONBLOCK) {
                        ret = -EAGAIN;
                        logbuf_unlock_irq();
  
                logbuf_unlock_irq();
                ret = wait_event_interruptible(log_wait,
-                                              user->seq != log_next_seq);
+                                       prb_read_valid(prb, user->seq, r));
                if (ret)
                        goto out;
                logbuf_lock_irq();
        }
  
-       if (user->seq < log_first_seq) {
+       if (user->seq < prb_first_valid_seq(prb)) {
                /* our last seen message is gone, return error and reset */
-               user->idx = log_first_idx;
-               user->seq = log_first_seq;
+               user->seq = prb_first_valid_seq(prb);
                ret = -EPIPE;
                logbuf_unlock_irq();
                goto out;
        }
  
-       msg = log_from_idx(user->idx);
-       len = msg_print_ext_header(user->buf, sizeof(user->buf),
-                                  msg, user->seq);
+       len = info_print_ext_header(user->buf, sizeof(user->buf), r->info);
        len += msg_print_ext_body(user->buf + len, sizeof(user->buf) - len,
-                                 log_dict(msg), msg->dict_len,
-                                 log_text(msg), msg->text_len);
+                                 &r->text_buf[0], r->info->text_len,
+                                 &r->info->dev_info);
  
-       user->idx = log_next(user->idx);
-       user->seq++;
+       user->seq = r->info->seq + 1;
        logbuf_unlock_irq();
  
        if (len > count) {
@@@ -943,14 -813,6 +813,14 @@@ out
        return ret;
  }
  
 +/*
 + * Be careful when modifying this function!!!
 + *
 + * Only few operations are supported because the device works only with the
 + * entire variable length messages (records). Non-standard values are
 + * returned in the other cases and has been this way for quite some time.
 + * User space applications might depend on this behavior.
 + */
  static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
  {
        struct devkmsg_user *user = file->private_data;
        switch (whence) {
        case SEEK_SET:
                /* the first record */
-               user->idx = log_first_idx;
-               user->seq = log_first_seq;
+               user->seq = prb_first_valid_seq(prb);
                break;
        case SEEK_DATA:
                /*
                 * like issued by 'dmesg -c'. Reading /dev/kmsg itself
                 * changes no global state, and does not clear anything.
                 */
-               user->idx = clear_idx;
                user->seq = clear_seq;
                break;
        case SEEK_END:
                /* after the last record */
-               user->idx = log_next_idx;
-               user->seq = log_next_seq;
+               user->seq = prb_next_seq(prb);
                break;
        default:
                ret = -EINVAL;
@@@ -1000,9 -859,9 +867,9 @@@ static __poll_t devkmsg_poll(struct fil
        poll_wait(file, &log_wait, wait);
  
        logbuf_lock_irq();
-       if (user->seq < log_next_seq) {
+       if (prb_read_valid(prb, user->seq, NULL)) {
                /* return error when data has vanished underneath us */
-               if (user->seq < log_first_seq)
+               if (user->seq < prb_first_valid_seq(prb))
                        ret = EPOLLIN|EPOLLRDNORM|EPOLLERR|EPOLLPRI;
                else
                        ret = EPOLLIN|EPOLLRDNORM;
@@@ -1037,9 -896,11 +904,11 @@@ static int devkmsg_open(struct inode *i
  
        mutex_init(&user->lock);
  
+       prb_rec_init_rd(&user->record, &user->info,
+                       &user->text_buf[0], sizeof(user->text_buf));
        logbuf_lock_irq();
-       user->idx = log_first_idx;
-       user->seq = log_first_seq;
+       user->seq = prb_first_valid_seq(prb);
        logbuf_unlock_irq();
  
        file->private_data = user;
@@@ -1080,23 -941,58 +949,58 @@@ const struct file_operations kmsg_fops 
   */
  void log_buf_vmcoreinfo_setup(void)
  {
-       VMCOREINFO_SYMBOL(log_buf);
-       VMCOREINFO_SYMBOL(log_buf_len);
-       VMCOREINFO_SYMBOL(log_first_idx);
-       VMCOREINFO_SYMBOL(clear_idx);
-       VMCOREINFO_SYMBOL(log_next_idx);
+       struct dev_printk_info *dev_info = NULL;
+       VMCOREINFO_SYMBOL(prb);
+       VMCOREINFO_SYMBOL(printk_rb_static);
+       VMCOREINFO_SYMBOL(clear_seq);
        /*
-        * Export struct printk_log size and field offsets. User space tools can
+        * Export struct size and field offsets. User space tools can
         * parse it and detect any changes to structure down the line.
         */
-       VMCOREINFO_STRUCT_SIZE(printk_log);
-       VMCOREINFO_OFFSET(printk_log, ts_nsec);
-       VMCOREINFO_OFFSET(printk_log, len);
-       VMCOREINFO_OFFSET(printk_log, text_len);
-       VMCOREINFO_OFFSET(printk_log, dict_len);
- #ifdef CONFIG_PRINTK_CALLER
-       VMCOREINFO_OFFSET(printk_log, caller_id);
- #endif
+       VMCOREINFO_STRUCT_SIZE(printk_ringbuffer);
+       VMCOREINFO_OFFSET(printk_ringbuffer, desc_ring);
+       VMCOREINFO_OFFSET(printk_ringbuffer, text_data_ring);
+       VMCOREINFO_OFFSET(printk_ringbuffer, fail);
+       VMCOREINFO_STRUCT_SIZE(prb_desc_ring);
+       VMCOREINFO_OFFSET(prb_desc_ring, count_bits);
+       VMCOREINFO_OFFSET(prb_desc_ring, descs);
+       VMCOREINFO_OFFSET(prb_desc_ring, infos);
+       VMCOREINFO_OFFSET(prb_desc_ring, head_id);
+       VMCOREINFO_OFFSET(prb_desc_ring, tail_id);
+       VMCOREINFO_STRUCT_SIZE(prb_desc);
+       VMCOREINFO_OFFSET(prb_desc, state_var);
+       VMCOREINFO_OFFSET(prb_desc, text_blk_lpos);
+       VMCOREINFO_STRUCT_SIZE(prb_data_blk_lpos);
+       VMCOREINFO_OFFSET(prb_data_blk_lpos, begin);
+       VMCOREINFO_OFFSET(prb_data_blk_lpos, next);
+       VMCOREINFO_STRUCT_SIZE(printk_info);
+       VMCOREINFO_OFFSET(printk_info, seq);
+       VMCOREINFO_OFFSET(printk_info, ts_nsec);
+       VMCOREINFO_OFFSET(printk_info, text_len);
+       VMCOREINFO_OFFSET(printk_info, caller_id);
+       VMCOREINFO_OFFSET(printk_info, dev_info);
+       VMCOREINFO_STRUCT_SIZE(dev_printk_info);
+       VMCOREINFO_OFFSET(dev_printk_info, subsystem);
+       VMCOREINFO_LENGTH(printk_info_subsystem, sizeof(dev_info->subsystem));
+       VMCOREINFO_OFFSET(dev_printk_info, device);
+       VMCOREINFO_LENGTH(printk_info_device, sizeof(dev_info->device));
+       VMCOREINFO_STRUCT_SIZE(prb_data_ring);
+       VMCOREINFO_OFFSET(prb_data_ring, size_bits);
+       VMCOREINFO_OFFSET(prb_data_ring, data);
+       VMCOREINFO_OFFSET(prb_data_ring, head_lpos);
+       VMCOREINFO_OFFSET(prb_data_ring, tail_lpos);
+       VMCOREINFO_SIZE(atomic_long_t);
+       VMCOREINFO_TYPE_OFFSET(atomic_long_t, counter);
  }
  #endif
  
@@@ -1174,11 -1070,46 +1078,46 @@@ static void __init set_percpu_data_read
        __printk_percpu_data_ready = true;
  }
  
+ static unsigned int __init add_to_rb(struct printk_ringbuffer *rb,
+                                    struct printk_record *r)
+ {
+       struct prb_reserved_entry e;
+       struct printk_record dest_r;
+       prb_rec_init_wr(&dest_r, r->info->text_len);
+       if (!prb_reserve(&e, rb, &dest_r))
+               return 0;
+       memcpy(&dest_r.text_buf[0], &r->text_buf[0], r->info->text_len);
+       dest_r.info->text_len = r->info->text_len;
+       dest_r.info->facility = r->info->facility;
+       dest_r.info->level = r->info->level;
+       dest_r.info->flags = r->info->flags;
+       dest_r.info->ts_nsec = r->info->ts_nsec;
+       dest_r.info->caller_id = r->info->caller_id;
+       memcpy(&dest_r.info->dev_info, &r->info->dev_info, sizeof(dest_r.info->dev_info));
+       prb_final_commit(&e);
+       return prb_record_text_space(&e);
+ }
+ static char setup_text_buf[LOG_LINE_MAX] __initdata;
  void __init setup_log_buf(int early)
  {
+       struct printk_info *new_infos;
+       unsigned int new_descs_count;
+       struct prb_desc *new_descs;
+       struct printk_info info;
+       struct printk_record r;
+       size_t new_descs_size;
+       size_t new_infos_size;
        unsigned long flags;
        char *new_log_buf;
        unsigned int free;
+       u64 seq;
  
        /*
         * Some archs call setup_log_buf() multiple times - first is very
        if (!new_log_buf_len)
                return;
  
+       new_descs_count = new_log_buf_len >> PRB_AVGBITS;
+       if (new_descs_count == 0) {
+               pr_err("new_log_buf_len: %lu too small\n", new_log_buf_len);
+               return;
+       }
        new_log_buf = memblock_alloc(new_log_buf_len, LOG_ALIGN);
        if (unlikely(!new_log_buf)) {
-               pr_err("log_buf_len: %lu bytes not available\n",
-                       new_log_buf_len);
+               pr_err("log_buf_len: %lu text bytes not available\n",
+                      new_log_buf_len);
                return;
        }
  
+       new_descs_size = new_descs_count * sizeof(struct prb_desc);
+       new_descs = memblock_alloc(new_descs_size, LOG_ALIGN);
+       if (unlikely(!new_descs)) {
+               pr_err("log_buf_len: %zu desc bytes not available\n",
+                      new_descs_size);
+               goto err_free_log_buf;
+       }
+       new_infos_size = new_descs_count * sizeof(struct printk_info);
+       new_infos = memblock_alloc(new_infos_size, LOG_ALIGN);
+       if (unlikely(!new_infos)) {
+               pr_err("log_buf_len: %zu info bytes not available\n",
+                      new_infos_size);
+               goto err_free_descs;
+       }
+       prb_rec_init_rd(&r, &info, &setup_text_buf[0], sizeof(setup_text_buf));
+       prb_init(&printk_rb_dynamic,
+                new_log_buf, ilog2(new_log_buf_len),
+                new_descs, ilog2(new_descs_count),
+                new_infos);
        logbuf_lock_irqsave(flags);
        log_buf_len = new_log_buf_len;
        log_buf = new_log_buf;
        new_log_buf_len = 0;
-       free = __LOG_BUF_LEN - log_next_idx;
-       memcpy(log_buf, __log_buf, __LOG_BUF_LEN);
+       free = __LOG_BUF_LEN;
+       prb_for_each_record(0, &printk_rb_static, seq, &r)
+               free -= add_to_rb(&printk_rb_dynamic, &r);
+       /*
+        * This is early enough that everything is still running on the
+        * boot CPU and interrupts are disabled. So no new messages will
+        * appear during the transition to the dynamic buffer.
+        */
+       prb = &printk_rb_dynamic;
        logbuf_unlock_irqrestore(flags);
  
+       if (seq != prb_next_seq(&printk_rb_static)) {
+               pr_err("dropped %llu messages\n",
+                      prb_next_seq(&printk_rb_static) - seq);
+       }
        pr_info("log_buf_len: %u bytes\n", log_buf_len);
        pr_info("early log buf free: %u(%u%%)\n",
                free, (free * 100) / __LOG_BUF_LEN);
+       return;
+ err_free_descs:
+       memblock_free(__pa(new_descs), new_descs_size);
+ err_free_log_buf:
+       memblock_free(__pa(new_log_buf), new_log_buf_len);
  }
  
  static bool __read_mostly ignore_loglevel;
@@@ -1321,18 -1303,18 +1311,18 @@@ static size_t print_caller(u32 id, cha
  #define print_caller(id, buf) 0
  #endif
  
- static size_t print_prefix(const struct printk_log *msg, bool syslog,
-                          bool time, char *buf)
+ static size_t info_print_prefix(const struct printk_info  *info, bool syslog,
+                               bool time, char *buf)
  {
        size_t len = 0;
  
        if (syslog)
-               len = print_syslog((msg->facility << 3) | msg->level, buf);
+               len = print_syslog((info->facility << 3) | info->level, buf);
  
        if (time)
-               len += print_time(msg->ts_nsec, buf + len);
+               len += print_time(info->ts_nsec, buf + len);
  
-       len += print_caller(msg->caller_id, buf + len);
+       len += print_caller(info->caller_id, buf + len);
  
        if (IS_ENABLED(CONFIG_PRINTK_CALLER) || time) {
                buf[len++] = ' ';
        return len;
  }
  
- static size_t msg_print_text(const struct printk_log *msg, bool syslog,
-                            bool time, char *buf, size_t size)
+ /*
+  * Prepare the record for printing. The text is shifted within the given
+  * buffer to avoid a need for another one. The following operations are
+  * done:
+  *
+  *   - Add prefix for each line.
+  *   - Add the trailing newline that has been removed in vprintk_store().
+  *   - Drop truncated lines that do not longer fit into the buffer.
+  *
+  * Return: The length of the updated/prepared text, including the added
+  * prefixes and the newline. The dropped line(s) are not counted.
+  */
+ static size_t record_print_text(struct printk_record *r, bool syslog,
+                               bool time)
  {
-       const char *text = log_text(msg);
-       size_t text_size = msg->text_len;
-       size_t len = 0;
+       size_t text_len = r->info->text_len;
+       size_t buf_size = r->text_buf_size;
+       char *text = r->text_buf;
        char prefix[PREFIX_MAX];
-       const size_t prefix_len = print_prefix(msg, syslog, time, prefix);
+       bool truncated = false;
+       size_t prefix_len;
+       size_t line_len;
+       size_t len = 0;
+       char *next;
+       /*
+        * If the message was truncated because the buffer was not large
+        * enough, treat the available text as if it were the full text.
+        */
+       if (text_len > buf_size)
+               text_len = buf_size;
  
-       do {
-               const char *next = memchr(text, '\n', text_size);
-               size_t text_len;
+       prefix_len = info_print_prefix(r->info, syslog, time, prefix);
  
+       /*
+        * @text_len: bytes of unprocessed text
+        * @line_len: bytes of current line _without_ newline
+        * @text:     pointer to beginning of current line
+        * @len:      number of bytes prepared in r->text_buf
+        */
+       for (;;) {
+               next = memchr(text, '\n', text_len);
                if (next) {
-                       text_len = next - text;
-                       next++;
-                       text_size -= next - text;
+                       line_len = next - text;
                } else {
-                       text_len = text_size;
+                       /* Drop truncated line(s). */
+                       if (truncated)
+                               break;
+                       line_len = text_len;
                }
  
-               if (buf) {
-                       if (prefix_len + text_len + 1 >= size - len)
+               /*
+                * Truncate the text if there is not enough space to add the
+                * prefix and a trailing newline.
+                */
+               if (len + prefix_len + text_len + 1 > buf_size) {
+                       /* Drop even the current line if no space. */
+                       if (len + prefix_len + line_len + 1 > buf_size)
                                break;
  
-                       memcpy(buf + len, prefix, prefix_len);
-                       len += prefix_len;
-                       memcpy(buf + len, text, text_len);
-                       len += text_len;
-                       buf[len++] = '\n';
-               } else {
-                       /* SYSLOG_ACTION_* buffer size only calculation */
-                       len += prefix_len + text_len + 1;
+                       text_len = buf_size - len - prefix_len - 1;
+                       truncated = true;
                }
  
-               text = next;
-       } while (text);
+               memmove(text + prefix_len, text, text_len);
+               memcpy(text, prefix, prefix_len);
+               len += prefix_len + line_len + 1;
+               if (text_len == line_len) {
+                       /*
+                        * Add the trailing newline removed in
+                        * vprintk_store().
+                        */
+                       text[prefix_len + line_len] = '\n';
+                       break;
+               }
+               /*
+                * Advance beyond the added prefix and the related line with
+                * its newline.
+                */
+               text += prefix_len + line_len + 1;
+               /*
+                * The remaining text has only decreased by the line with its
+                * newline.
+                *
+                * Note that @text_len can become zero. It happens when @text
+                * ended with a newline (either due to truncation or the
+                * original string ending with "\n\n"). The loop is correctly
+                * repeated and (if not truncated) an empty line with a prefix
+                * will be prepared.
+                */
+               text_len -= line_len + 1;
+       }
  
        return len;
  }
  
+ static size_t get_record_print_text_size(struct printk_info *info,
+                                        unsigned int line_count,
+                                        bool syslog, bool time)
+ {
+       char prefix[PREFIX_MAX];
+       size_t prefix_len;
+       prefix_len = info_print_prefix(info, syslog, time, prefix);
+       /*
+        * Each line will be preceded with a prefix. The intermediate
+        * newlines are already within the text, but a final trailing
+        * newline will be added.
+        */
+       return ((prefix_len * line_count) + info->text_len + 1);
+ }
  static int syslog_print(char __user *buf, int size)
  {
+       struct printk_info info;
+       struct printk_record r;
        char *text;
-       struct printk_log *msg;
        int len = 0;
  
        text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
        if (!text)
                return -ENOMEM;
  
+       prb_rec_init_rd(&r, &info, text, LOG_LINE_MAX + PREFIX_MAX);
        while (size > 0) {
                size_t n;
                size_t skip;
  
                logbuf_lock_irq();
-               if (syslog_seq < log_first_seq) {
-                       /* messages are gone, move to first one */
-                       syslog_seq = log_first_seq;
-                       syslog_idx = log_first_idx;
-                       syslog_partial = 0;
-               }
-               if (syslog_seq == log_next_seq) {
+               if (!prb_read_valid(prb, syslog_seq, &r)) {
                        logbuf_unlock_irq();
                        break;
                }
+               if (r.info->seq != syslog_seq) {
+                       /* message is gone, move to next valid one */
+                       syslog_seq = r.info->seq;
+                       syslog_partial = 0;
+               }
  
                /*
                 * To keep reading/counting partial line consistent,
                        syslog_time = printk_time;
  
                skip = syslog_partial;
-               msg = log_from_idx(syslog_idx);
-               n = msg_print_text(msg, true, syslog_time, text,
-                                  LOG_LINE_MAX + PREFIX_MAX);
+               n = record_print_text(&r, true, syslog_time);
                if (n - syslog_partial <= size) {
                        /* message fits into buffer, move forward */
-                       syslog_idx = log_next(syslog_idx);
-                       syslog_seq++;
+                       syslog_seq = r.info->seq + 1;
                        n -= syslog_partial;
                        syslog_partial = 0;
                } else if (!len){
  
  static int syslog_print_all(char __user *buf, int size, bool clear)
  {
+       struct printk_info info;
+       unsigned int line_count;
+       struct printk_record r;
        char *text;
        int len = 0;
-       u64 next_seq;
        u64 seq;
-       u32 idx;
        bool time;
  
        text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
         * Find first record that fits, including all following records,
         * into the user-provided buffer for this dump.
         */
-       seq = clear_seq;
-       idx = clear_idx;
-       while (seq < log_next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
-               len += msg_print_text(msg, true, time, NULL, 0);
-               idx = log_next(idx);
-               seq++;
-       }
+       prb_for_each_info(clear_seq, prb, seq, &info, &line_count)
+               len += get_record_print_text_size(&info, line_count, true, time);
  
        /* move first record forward until length fits into the buffer */
-       seq = clear_seq;
-       idx = clear_idx;
-       while (len > size && seq < log_next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
-               len -= msg_print_text(msg, true, time, NULL, 0);
-               idx = log_next(idx);
-               seq++;
+       prb_for_each_info(clear_seq, prb, seq, &info, &line_count) {
+               if (len <= size)
+                       break;
+               len -= get_record_print_text_size(&info, line_count, true, time);
        }
  
-       /* last message fitting into this dump */
-       next_seq = log_next_seq;
+       prb_rec_init_rd(&r, &info, text, LOG_LINE_MAX + PREFIX_MAX);
  
        len = 0;
-       while (len >= 0 && seq < next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
-               int textlen = msg_print_text(msg, true, time, text,
-                                            LOG_LINE_MAX + PREFIX_MAX);
+       prb_for_each_record(seq, prb, seq, &r) {
+               int textlen;
  
-               idx = log_next(idx);
-               seq++;
+               textlen = record_print_text(&r, true, time);
+               if (len + textlen > size) {
+                       seq--;
+                       break;
+               }
  
                logbuf_unlock_irq();
                if (copy_to_user(buf + len, text, textlen))
                        len += textlen;
                logbuf_lock_irq();
  
-               if (seq < log_first_seq) {
-                       /* messages are gone, move to next one */
-                       seq = log_first_seq;
-                       idx = log_first_idx;
-               }
+               if (len < 0)
+                       break;
        }
  
-       if (clear) {
-               clear_seq = log_next_seq;
-               clear_idx = log_next_idx;
-       }
+       if (clear)
+               clear_seq = seq;
        logbuf_unlock_irq();
  
        kfree(text);
  static void syslog_clear(void)
  {
        logbuf_lock_irq();
-       clear_seq = log_next_seq;
-       clear_idx = log_next_idx;
+       clear_seq = prb_next_seq(prb);
        logbuf_unlock_irq();
  }
  
@@@ -1559,7 -1601,7 +1609,7 @@@ int do_syslog(int type, char __user *bu
                if (!access_ok(buf, len))
                        return -EFAULT;
                error = wait_event_interruptible(log_wait,
-                                                syslog_seq != log_next_seq);
+                               prb_read_valid(prb, syslog_seq, NULL));
                if (error)
                        return error;
                error = syslog_print(buf, len);
        /* Read/clear last kernel messages */
        case SYSLOG_ACTION_READ_CLEAR:
                clear = true;
 -              /* FALL THRU */
 +              fallthrough;
        /* Read last kernel messages */
        case SYSLOG_ACTION_READ_ALL:
                if (!buf || len < 0)
        /* Number of chars in the log buffer */
        case SYSLOG_ACTION_SIZE_UNREAD:
                logbuf_lock_irq();
-               if (syslog_seq < log_first_seq) {
+               if (syslog_seq < prb_first_valid_seq(prb)) {
                        /* messages are gone, move to first one */
-                       syslog_seq = log_first_seq;
-                       syslog_idx = log_first_idx;
+                       syslog_seq = prb_first_valid_seq(prb);
                        syslog_partial = 0;
                }
                if (source == SYSLOG_FROM_PROC) {
                         * for pending data, not the size; return the count of
                         * records, not the length.
                         */
-                       error = log_next_seq - syslog_seq;
+                       error = prb_next_seq(prb) - syslog_seq;
                } else {
-                       u64 seq = syslog_seq;
-                       u32 idx = syslog_idx;
                        bool time = syslog_partial ? syslog_time : printk_time;
-                       while (seq < log_next_seq) {
-                               struct printk_log *msg = log_from_idx(idx);
-                               error += msg_print_text(msg, true, time, NULL,
-                                                       0);
+                       struct printk_info info;
+                       unsigned int line_count;
+                       u64 seq;
+                       prb_for_each_info(syslog_seq, prb, seq, &info,
+                                         &line_count) {
+                               error += get_record_print_text_size(&info, line_count,
+                                                                   true, time);
                                time = printk_time;
-                               idx = log_next(idx);
-                               seq++;
                        }
                        error -= syslog_partial;
                }
@@@ -1804,10 -1843,22 +1851,22 @@@ static int console_trylock_spinning(voi
  static void call_console_drivers(const char *ext_text, size_t ext_len,
                                 const char *text, size_t len)
  {
+       static char dropped_text[64];
+       size_t dropped_len = 0;
        struct console *con;
  
        trace_console_rcuidle(text, len);
  
+       if (!console_drivers)
+               return;
+       if (console_dropped) {
+               dropped_len = snprintf(dropped_text, sizeof(dropped_text),
+                                      "** %lu printk messages dropped **\n",
+                                      console_dropped);
+               console_dropped = 0;
+       }
        for_each_console(con) {
                if (exclusive_console && con != exclusive_console)
                        continue;
                        continue;
                if (con->flags & CON_EXTENDED)
                        con->write(con, ext_text, ext_len);
-               else
+               else {
+                       if (dropped_len)
+                               con->write(con, dropped_text, dropped_len);
                        con->write(con, text, len);
+               }
        }
  }
  
@@@ -1845,97 -1899,38 +1907,38 @@@ static inline u32 printk_caller_id(void
                0x80000000 + raw_smp_processor_id();
  }
  
- /*
-  * Continuation lines are buffered, and not committed to the record buffer
-  * until the line is complete, or a race forces it. The line fragments
-  * though, are printed immediately to the consoles to ensure everything has
-  * reached the console in case of a kernel crash.
-  */
- static struct cont {
-       char buf[LOG_LINE_MAX];
-       size_t len;                     /* length == 0 means unused buffer */
-       u32 caller_id;                  /* printk_caller_id() of first print */
-       u64 ts_nsec;                    /* time of first print */
-       u8 level;                       /* log level of first message */
-       u8 facility;                    /* log facility of first message */
-       enum log_flags flags;           /* prefix, newline flags */
- } cont;
- static void cont_flush(void)
- {
-       if (cont.len == 0)
-               return;
-       log_store(cont.caller_id, cont.facility, cont.level, cont.flags,
-                 cont.ts_nsec, NULL, 0, cont.buf, cont.len);
-       cont.len = 0;
- }
- static bool cont_add(u32 caller_id, int facility, int level,
-                    enum log_flags flags, const char *text, size_t len)
- {
-       /* If the line gets too long, split it up in separate records. */
-       if (cont.len + len > sizeof(cont.buf)) {
-               cont_flush();
-               return false;
-       }
-       if (!cont.len) {
-               cont.facility = facility;
-               cont.level = level;
-               cont.caller_id = caller_id;
-               cont.ts_nsec = local_clock();
-               cont.flags = flags;
-       }
-       memcpy(cont.buf + cont.len, text, len);
-       cont.len += len;
-       // The original flags come from the first line,
-       // but later continuations can add a newline.
-       if (flags & LOG_NEWLINE) {
-               cont.flags |= LOG_NEWLINE;
-               cont_flush();
-       }
-       return true;
- }
- static size_t log_output(int facility, int level, enum log_flags lflags, const char *dict, size_t dictlen, char *text, size_t text_len)
+ static size_t log_output(int facility, int level, enum log_flags lflags,
+                        const struct dev_printk_info *dev_info,
+                        char *text, size_t text_len)
  {
        const u32 caller_id = printk_caller_id();
  
-       /*
-        * If an earlier line was buffered, and we're a continuation
-        * write from the same context, try to add it to the buffer.
-        */
-       if (cont.len) {
-               if (cont.caller_id == caller_id && (lflags & LOG_CONT)) {
-                       if (cont_add(caller_id, facility, level, lflags, text, text_len))
-                               return text_len;
-               }
-               /* Otherwise, make sure it's flushed */
-               cont_flush();
-       }
-       /* Skip empty continuation lines that couldn't be added - they just flush */
-       if (!text_len && (lflags & LOG_CONT))
-               return 0;
-       /* If it doesn't end in a newline, try to buffer the current line */
-       if (!(lflags & LOG_NEWLINE)) {
-               if (cont_add(caller_id, facility, level, lflags, text, text_len))
+       if (lflags & LOG_CONT) {
+               struct prb_reserved_entry e;
+               struct printk_record r;
+               prb_rec_init_wr(&r, text_len);
+               if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) {
+                       memcpy(&r.text_buf[r.info->text_len], text, text_len);
+                       r.info->text_len += text_len;
+                       if (lflags & LOG_NEWLINE) {
+                               r.info->flags |= LOG_NEWLINE;
+                               prb_final_commit(&e);
+                       } else {
+                               prb_commit(&e);
+                       }
                        return text_len;
+               }
        }
  
        /* Store it in the record log */
        return log_store(caller_id, facility, level, lflags, 0,
-                        dict, dictlen, text, text_len);
+                        dev_info, text, text_len);
  }
  
  /* Must be called under logbuf_lock. */
  int vprintk_store(int facility, int level,
-                 const char *dict, size_t dictlen,
+                 const struct dev_printk_info *dev_info,
                  const char *fmt, va_list args)
  {
        static char textbuf[LOG_LINE_MAX];
        if (level == LOGLEVEL_DEFAULT)
                level = default_message_loglevel;
  
-       if (dict)
+       if (dev_info)
                lflags |= LOG_NEWLINE;
  
-       return log_output(facility, level, lflags,
-                         dict, dictlen, text, text_len);
+       return log_output(facility, level, lflags, dev_info, text, text_len);
  }
  
  asmlinkage int vprintk_emit(int facility, int level,
-                           const char *dict, size_t dictlen,
+                           const struct dev_printk_info *dev_info,
                            const char *fmt, va_list args)
  {
        int printed_len;
-       bool in_sched = false, pending_output;
+       bool in_sched = false;
        unsigned long flags;
-       u64 curr_log_seq;
  
        /* Suppress unimportant messages after panic happens */
        if (unlikely(suppress_printk))
  
        /* This stops the holder of console_sem just where we want him */
        logbuf_lock_irqsave(flags);
-       curr_log_seq = log_next_seq;
-       printed_len = vprintk_store(facility, level, dict, dictlen, fmt, args);
-       pending_output = (curr_log_seq != log_next_seq);
+       printed_len = vprintk_store(facility, level, dev_info, fmt, args);
        logbuf_unlock_irqrestore(flags);
  
        /* If called from the scheduler, we can not call up(). */
-       if (!in_sched && pending_output) {
+       if (!in_sched) {
                /*
                 * Disable preemption to avoid being preempted while holding
                 * console_sem which would prevent anyone from printing to
                preempt_enable();
        }
  
-       if (pending_output)
-               wake_up_klogd();
+       wake_up_klogd();
        return printed_len;
  }
  EXPORT_SYMBOL(vprintk_emit);
@@@ -2044,7 -2034,7 +2042,7 @@@ EXPORT_SYMBOL(vprintk)
  
  int vprintk_default(const char *fmt, va_list args)
  {
-       return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args);
+       return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, fmt, args);
  }
  EXPORT_SYMBOL_GPL(vprintk_default);
  
@@@ -2088,30 -2078,31 +2086,31 @@@ EXPORT_SYMBOL(printk)
  #define PREFIX_MAX            0
  #define printk_time           false
  
+ #define prb_read_valid(rb, seq, r)    false
+ #define prb_first_valid_seq(rb)               0
  static u64 syslog_seq;
- static u32 syslog_idx;
  static u64 console_seq;
- static u32 console_idx;
  static u64 exclusive_console_stop_seq;
- static u64 log_first_seq;
- static u32 log_first_idx;
- static u64 log_next_seq;
- static char *log_text(const struct printk_log *msg) { return NULL; }
- static char *log_dict(const struct printk_log *msg) { return NULL; }
- static struct printk_log *log_from_idx(u32 idx) { return NULL; }
- static u32 log_next(u32 idx) { return 0; }
- static ssize_t msg_print_ext_header(char *buf, size_t size,
-                                   struct printk_log *msg,
-                                   u64 seq) { return 0; }
+ static unsigned long console_dropped;
+ static size_t record_print_text(const struct printk_record *r,
+                               bool syslog, bool time)
+ {
+       return 0;
+ }
+ static ssize_t info_print_ext_header(char *buf, size_t size,
+                                    struct printk_info *info)
+ {
+       return 0;
+ }
  static ssize_t msg_print_ext_body(char *buf, size_t size,
-                                 char *dict, size_t dict_len,
-                                 char *text, size_t text_len) { return 0; }
+                                 char *text, size_t text_len,
+                                 struct dev_printk_info *dev_info) { return 0; }
  static void console_lock_spinning_enable(void) { }
  static int console_lock_spinning_disable_and_check(void) { return 0; }
  static void call_console_drivers(const char *ext_text, size_t ext_len,
                                 const char *text, size_t len) {}
- static size_t msg_print_text(const struct printk_log *msg, bool syslog,
-                            bool time, char *buf, size_t size) { return 0; }
  static bool suppress_message_printing(int level) { return false; }
  
  #endif /* CONFIG_PRINTK */
@@@ -2398,12 -2389,16 +2397,16 @@@ void console_unlock(void
        static char text[LOG_LINE_MAX + PREFIX_MAX];
        unsigned long flags;
        bool do_cond_resched, retry;
+       struct printk_info info;
+       struct printk_record r;
  
        if (console_suspended) {
                up_console_sem();
                return;
        }
  
+       prb_rec_init_rd(&r, &info, text, sizeof(text));
        /*
         * Console drivers are called with interrupts disabled, so
         * @console_may_schedule should be cleared before; however, we may
         *
         * console_trylock() is not able to detect the preemptive
         * context reliably. Therefore the value must be stored before
 -       * and cleared after the the "again" goto label.
 +       * and cleared after the "again" goto label.
         */
        do_cond_resched = console_may_schedule;
  again:
        }
  
        for (;;) {
-               struct printk_log *msg;
                size_t ext_len = 0;
                size_t len;
  
                printk_safe_enter_irqsave(flags);
                raw_spin_lock(&logbuf_lock);
-               if (console_seq < log_first_seq) {
-                       len = snprintf(text, sizeof(text),
-                                      "** %llu printk messages dropped **\n",
-                                      log_first_seq - console_seq);
-                       /* messages are gone, move to first one */
-                       console_seq = log_first_seq;
-                       console_idx = log_first_idx;
-               } else {
-                       len = 0;
-               }
  skip:
-               if (console_seq == log_next_seq)
+               if (!prb_read_valid(prb, console_seq, &r))
                        break;
  
-               msg = log_from_idx(console_idx);
-               if (suppress_message_printing(msg->level)) {
+               if (console_seq != r.info->seq) {
+                       console_dropped += r.info->seq - console_seq;
+                       console_seq = r.info->seq;
+               }
+               if (suppress_message_printing(r.info->level)) {
                        /*
                         * Skip record we have buffered and already printed
                         * directly to the console when we received it, and
                         * record that has level above the console loglevel.
                         */
-                       console_idx = log_next(console_idx);
                        console_seq++;
                        goto skip;
                }
                        exclusive_console = NULL;
                }
  
-               len += msg_print_text(msg,
-                               console_msg_format & MSG_FORMAT_SYSLOG,
-                               printk_time, text + len, sizeof(text) - len);
+               /*
+                * Handle extended console text first because later
+                * record_print_text() will modify the record buffer in-place.
+                */
                if (nr_ext_console_drivers) {
-                       ext_len = msg_print_ext_header(ext_text,
+                       ext_len = info_print_ext_header(ext_text,
                                                sizeof(ext_text),
-                                               msg, console_seq);
+                                               r.info);
                        ext_len += msg_print_ext_body(ext_text + ext_len,
                                                sizeof(ext_text) - ext_len,
-                                               log_dict(msg), msg->dict_len,
-                                               log_text(msg), msg->text_len);
+                                               &r.text_buf[0],
+                                               r.info->text_len,
+                                               &r.info->dev_info);
                }
-               console_idx = log_next(console_idx);
+               len = record_print_text(&r,
+                               console_msg_format & MSG_FORMAT_SYSLOG,
+                               printk_time);
                console_seq++;
                raw_spin_unlock(&logbuf_lock);
  
         * flush, no worries.
         */
        raw_spin_lock(&logbuf_lock);
-       retry = console_seq != log_next_seq;
+       retry = prb_read_valid(prb, console_seq, NULL);
        raw_spin_unlock(&logbuf_lock);
        printk_safe_exit_irqrestore(flags);
  
@@@ -2594,8 -2584,7 +2592,7 @@@ void console_flush_on_panic(enum con_fl
                unsigned long flags;
  
                logbuf_lock_irqsave(flags);
-               console_seq = log_first_seq;
-               console_idx = log_first_idx;
+               console_seq = prb_first_valid_seq(prb);
                logbuf_unlock_irqrestore(flags);
        }
        console_unlock();
@@@ -2666,7 -2655,7 +2663,7 @@@ early_param("keep_bootcon", keep_bootco
  static int try_enable_new_console(struct console *newcon, bool user_specified)
  {
        struct console_cmdline *c;
 -      int i;
 +      int i, err;
  
        for (i = 0, c = console_cmdline;
             i < MAX_CMDLINECONSOLES && c->name[0];
                                return 0;
  
                        if (newcon->setup &&
 -                          newcon->setup(newcon, c->options) != 0)
 -                              return -EIO;
 +                          (err = newcon->setup(newcon, c->options)) != 0)
 +                              return err;
                }
                newcon->flags |= CON_ENABLED;
                if (i == preferred_console) {
        /*
         * Some consoles, such as pstore and netconsole, can be enabled even
         * without matching. Accept the pre-enabled consoles only when match()
 -       * and setup() had a change to be called.
 +       * and setup() had a chance to be called.
         */
        if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
                return 0;
@@@ -2838,7 -2827,6 +2835,6 @@@ void register_console(struct console *n
                exclusive_console = newcon;
                exclusive_console_stop_seq = console_seq;
                console_seq = syslog_seq;
-               console_idx = syslog_idx;
                logbuf_unlock_irqrestore(flags);
        }
        console_unlock();
@@@ -3062,7 -3050,7 +3058,7 @@@ int vprintk_deferred(const char *fmt, v
  {
        int r;
  
-       r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, 0, fmt, args);
+       r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args);
        defer_console_output();
  
        return r;
@@@ -3227,9 -3215,7 +3223,7 @@@ void kmsg_dump(enum kmsg_dump_reason re
  
                logbuf_lock_irqsave(flags);
                dumper->cur_seq = clear_seq;
-               dumper->cur_idx = clear_idx;
-               dumper->next_seq = log_next_seq;
-               dumper->next_idx = log_next_idx;
+               dumper->next_seq = prb_next_seq(prb);
                logbuf_unlock_irqrestore(flags);
  
                /* invoke dumper which will iterate over records */
  bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
                               char *line, size_t size, size_t *len)
  {
-       struct printk_log *msg;
+       struct printk_info info;
+       unsigned int line_count;
+       struct printk_record r;
        size_t l = 0;
        bool ret = false;
  
+       prb_rec_init_rd(&r, &info, line, size);
        if (!dumper->active)
                goto out;
  
-       if (dumper->cur_seq < log_first_seq) {
-               /* messages are gone, move to first available one */
-               dumper->cur_seq = log_first_seq;
-               dumper->cur_idx = log_first_idx;
-       }
-       /* last entry */
-       if (dumper->cur_seq >= log_next_seq)
-               goto out;
+       /* Read text or count text lines? */
+       if (line) {
+               if (!prb_read_valid(prb, dumper->cur_seq, &r))
+                       goto out;
+               l = record_print_text(&r, syslog, printk_time);
+       } else {
+               if (!prb_read_valid_info(prb, dumper->cur_seq,
+                                        &info, &line_count)) {
+                       goto out;
+               }
+               l = get_record_print_text_size(&info, line_count, syslog,
+                                              printk_time);
  
-       msg = log_from_idx(dumper->cur_idx);
-       l = msg_print_text(msg, syslog, printk_time, line, size);
+       }
  
-       dumper->cur_idx = log_next(dumper->cur_idx);
-       dumper->cur_seq++;
+       dumper->cur_seq = r.info->seq + 1;
        ret = true;
  out:
        if (len)
@@@ -3332,7 -3323,7 +3331,7 @@@ EXPORT_SYMBOL_GPL(kmsg_dump_get_line)
   * @len: length of line placed into buffer
   *
   * Start at the end of the kmsg buffer and fill the provided buffer
 - * with as many of the the *youngest* kmsg records that fit into it.
 + * with as many of the *youngest* kmsg records that fit into it.
   * If the buffer is large enough, all available kmsg records will be
   * copied with a single call.
   *
  bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
                          char *buf, size_t size, size_t *len)
  {
+       struct printk_info info;
+       unsigned int line_count;
+       struct printk_record r;
        unsigned long flags;
        u64 seq;
-       u32 idx;
        u64 next_seq;
-       u32 next_idx;
        size_t l = 0;
        bool ret = false;
        bool time = printk_time;
  
-       if (!dumper->active)
+       prb_rec_init_rd(&r, &info, buf, size);
+       if (!dumper->active || !buf || !size)
                goto out;
  
        logbuf_lock_irqsave(flags);
-       if (dumper->cur_seq < log_first_seq) {
+       if (dumper->cur_seq < prb_first_valid_seq(prb)) {
                /* messages are gone, move to first available one */
-               dumper->cur_seq = log_first_seq;
-               dumper->cur_idx = log_first_idx;
+               dumper->cur_seq = prb_first_valid_seq(prb);
        }
  
        /* last entry */
  
        /* calculate length of entire buffer */
        seq = dumper->cur_seq;
-       idx = dumper->cur_idx;
-       while (seq < dumper->next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
-               l += msg_print_text(msg, true, time, NULL, 0);
-               idx = log_next(idx);
-               seq++;
+       while (prb_read_valid_info(prb, seq, &info, &line_count)) {
+               if (r.info->seq >= dumper->next_seq)
+                       break;
+               l += get_record_print_text_size(&info, line_count, true, time);
+               seq = r.info->seq + 1;
        }
  
        /* move first record forward until length fits into the buffer */
        seq = dumper->cur_seq;
-       idx = dumper->cur_idx;
-       while (l >= size && seq < dumper->next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
-               l -= msg_print_text(msg, true, time, NULL, 0);
-               idx = log_next(idx);
-               seq++;
+       while (l >= size && prb_read_valid_info(prb, seq,
+                                               &info, &line_count)) {
+               if (r.info->seq >= dumper->next_seq)
+                       break;
+               l -= get_record_print_text_size(&info, line_count, true, time);
+               seq = r.info->seq + 1;
        }
  
        /* last message in next interation */
        next_seq = seq;
-       next_idx = idx;
  
+       /* actually read text into the buffer now */
        l = 0;
-       while (seq < dumper->next_seq) {
-               struct printk_log *msg = log_from_idx(idx);
+       while (prb_read_valid(prb, seq, &r)) {
+               if (r.info->seq >= dumper->next_seq)
+                       break;
+               l += record_print_text(&r, syslog, time);
+               /* adjust record to store to remaining buffer space */
+               prb_rec_init_rd(&r, &info, buf + l, size - l);
  
-               l += msg_print_text(msg, syslog, time, buf + l, size - l);
-               idx = log_next(idx);
-               seq++;
+               seq = r.info->seq + 1;
        }
  
        dumper->next_seq = next_seq;
-       dumper->next_idx = next_idx;
        ret = true;
        logbuf_unlock_irqrestore(flags);
  out:
@@@ -3429,9 -3422,7 +3430,7 @@@ EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer)
  void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
  {
        dumper->cur_seq = clear_seq;
-       dumper->cur_idx = clear_idx;
-       dumper->next_seq = log_next_seq;
-       dumper->next_idx = log_next_idx;
+       dumper->next_seq = prb_next_seq(prb);
  }
  
  /**
This page took 0.191648 seconds and 4 git commands to generate.