Annotate vital static information into kmemdump:
 - prb_descs
 - prb_infos
 - prb
 - prb_data
 - printk_rb_static
 - printk_rb_dynamic

Information on these variables is stored into dedicated kmemdump section.

Register dynamic information into kmemdump:
 - new_descs
 - new_infos
 - new_log_buf
In the case when the log buffer is dynamically replaced by a runtime
allocated version, call kmemdump to register the data with a replace
flag to remove the old registered data.

Signed-off-by: Eugen Hristev <[email protected]>
---
 kernel/printk/printk.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 0efbcdda9aab..f7d60dbe5e5a 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -48,6 +48,7 @@
 #include <linux/sched/clock.h>
 #include <linux/sched/debug.h>
 #include <linux/sched/task_stack.h>
+#include <linux/kmemdump.h>
 
 #include <linux/uaccess.h>
 #include <asm/sections.h>
@@ -540,10 +541,16 @@ static u32 log_buf_len = __LOG_BUF_LEN;
 #endif
 _DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
                 PRB_AVGBITS, &__log_buf[0]);
+KMEMDUMP_VAR_CORE_NAMED(prb_descs, _printk_rb_static_descs, 
sizeof(_printk_rb_static_descs));
+KMEMDUMP_VAR_CORE_NAMED(prb_infos, _printk_rb_static_infos, 
sizeof(_printk_rb_static_infos));
+KMEMDUMP_VAR_CORE_NAMED(prb_data, __log_buf,  __LOG_BUF_LEN);
+KMEMDUMP_VAR_CORE(printk_rb_static, sizeof(printk_rb_static));
 
 static struct printk_ringbuffer printk_rb_dynamic;
+KMEMDUMP_VAR_CORE(printk_rb_dynamic, sizeof(printk_rb_dynamic));
 
 struct printk_ringbuffer *prb = &printk_rb_static;
+KMEMDUMP_VAR_CORE(prb, sizeof(prb));
 
 /*
  * We cannot access per-CPU data (e.g. per-CPU flush irq_work) before
@@ -1211,7 +1218,10 @@ void __init setup_log_buf(int early)
                goto out;
        }
 
-       new_log_buf = memblock_alloc(new_log_buf_len, LOG_ALIGN);
+       new_log_buf = 
kmemdump_alloc_id_size_replace(KMEMDUMP_ID_COREIMAGE_prb_data,
+                                                    new_log_buf_len,
+                                                    memblock_alloc,
+                                                    new_log_buf_len, 
LOG_ALIGN);
        if (unlikely(!new_log_buf)) {
                pr_err("log_buf_len: %lu text bytes not available\n",
                       new_log_buf_len);
@@ -1219,7 +1229,10 @@ void __init setup_log_buf(int early)
        }
 
        new_descs_size = new_descs_count * sizeof(struct prb_desc);
-       new_descs = memblock_alloc(new_descs_size, LOG_ALIGN);
+       new_descs = 
kmemdump_alloc_id_size_replace(KMEMDUMP_ID_COREIMAGE_prb_descs,
+                                                  new_descs_size, 
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);
@@ -1227,7 +1240,10 @@ void __init setup_log_buf(int early)
        }
 
        new_infos_size = new_descs_count * sizeof(struct printk_info);
-       new_infos = memblock_alloc(new_infos_size, LOG_ALIGN);
+       new_infos = 
kmemdump_alloc_id_size_replace(KMEMDUMP_ID_COREIMAGE_prb_infos,
+                                                  new_infos_size, 
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);
@@ -1284,9 +1300,11 @@ void __init setup_log_buf(int early)
        return;
 
 err_free_descs:
-       memblock_free(new_descs, new_descs_size);
+       kmemdump_free_id(KMEMDUMP_ID_COREIMAGE_prb_descs,
+                        memblock_free, new_descs, new_descs_size);
 err_free_log_buf:
-       memblock_free(new_log_buf, new_log_buf_len);
+       kmemdump_free_id(KMEMDUMP_ID_COREIMAGE_prb_data,
+                        memblock_free, new_log_buf, new_log_buf_len);
 out:
        print_log_buf_usage_stats();
 }
-- 
2.43.0


Reply via email to