12 #define KMSG_COMPONENT "s390dbf"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/ctype.h>
20 #include <linux/string.h>
21 #include <linux/sysctl.h>
22 #include <asm/uaccess.h>
23 #include <linux/module.h>
28 #include <asm/debug.h>
30 #define DEBUG_PROLOG_ENTRY -1
68 static int debug_init(
void);
70 size_t user_len, loff_t *
offset);
71 static ssize_t debug_input(
struct file *
file,
const char __user *user_buf,
72 size_t user_len, loff_t *
offset);
82 struct file *
file,
const char __user *user_buf,
83 size_t user_buf_size, loff_t *
offset);
87 struct file *
file,
const char __user *user_buf,
88 size_t user_buf_size, loff_t *
offset);
90 struct file *
file,
const char __user *user_buf,
91 size_t user_buf_size, loff_t *
offset);
93 char *out_buf,
const char *in_buf);
108 &debug_raw_header_fn,
109 &debug_raw_format_fn,
119 &debug_hex_ascii_format_fn,
127 &debug_prolog_level_fn,
130 &debug_input_level_fn,
136 &debug_prolog_pages_fn,
139 &debug_input_pages_fn,
148 &debug_input_flush_fn,
172 static int debug_critical;
177 .write = debug_input,
179 .release = debug_close,
183 static struct dentry *debug_debugfs_root_entry;
194 debug_areas_alloc(
int pages_per_area,
int nr_areas)
203 goto fail_malloc_areas;
204 for (i = 0; i < nr_areas; i++) {
208 goto fail_malloc_areas2;
210 for(j = 0; j < pages_per_area; j++) {
213 for(j--; j >=0 ; j--) {
217 goto fail_malloc_areas2;
224 for(i--; i >= 0; i--){
225 for(j=0; j < pages_per_area;j++){
243 debug_info_alloc(
const char *
name,
int pages_per_area,
int nr_areas,
255 goto fail_malloc_active_entries;
258 goto fail_malloc_active_pages;
259 if((mode ==
ALL_AREAS) && (pages_per_area != 0)){
260 rc->
areas = debug_areas_alloc(pages_per_area, nr_areas);
262 goto fail_malloc_areas;
286 fail_malloc_active_pages:
288 fail_malloc_active_entries:
306 for (i = 0; i < db_info->
nr_areas; i++) {
323 debug_areas_free(db_info);
335 debug_info_create(
const char *name,
int pages_per_area,
int nr_areas,
340 rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
349 debug_debugfs_root_entry);
352 if (!debug_area_first) {
354 debug_area_first =
rc;
358 debug_area_last->
next =
rc;
359 rc->
prev = debug_area_last;
361 debug_area_last =
rc;
393 spin_unlock_irqrestore(&in->
lock, flags);
406 spin_unlock_irqrestore(&in->
lock, flags);
436 if (!db_info->
views[i])
441 if(db_info == debug_area_first)
442 debug_area_first = db_info->
next;
443 if(db_info == debug_area_last)
444 debug_area_last = db_info->
prev;
447 debug_info_free(db_info);
539 if (*offset != p_info->
offset)
545 int formatted_line_size;
546 int formatted_line_residue;
547 int user_buf_residue;
550 formatted_line_size = debug_format_entry(p_info);
551 formatted_line_residue = formatted_line_size - entry_offset;
552 user_buf_residue = len-
count;
553 copy_size =
min(user_buf_residue, formatted_line_residue);
556 + entry_offset, copy_size))
559 entry_offset += copy_size;
561 if(copy_size == formatted_line_residue){
563 if(debug_next_entry(p_info))
581 debug_input(
struct file *file,
const char __user *user_buf,
size_t length,
589 if (p_info->
view->input_proc)
591 p_info->
view, file, user_buf,
607 debug_open(
struct inode *
inode,
struct file *file)
614 debug_info = file->
f_path.dentry->d_inode->i_private;
617 if (!debug_info->
views[i])
634 if(!debug_info->
views[i]->format_proc &&
635 !debug_info->
views[i]->header_proc){
636 debug_info_snapshot = debug_info_copy(debug_info,
NO_AREAS);
638 debug_info_snapshot = debug_info_copy(debug_info,
ALL_AREAS);
641 if(!debug_info_snapshot){
648 debug_info_free(debug_info_snapshot);
661 debug_info_get(debug_info);
675 debug_close(
struct inode *inode,
struct file *file)
694 int nr_areas,
int buf_size,
umode_t mode,
701 if ((uid != 0) || (gid != 0))
702 pr_warning(
"Root becomes the owner of all s390dbf files "
709 rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
717 pr_err(
"Registering debug feature %s failed\n", name);
731 int nr_areas,
int buf_size)
762 debug_set_size(
debug_info_t*
id,
int nr_areas,
int pages_per_area)
768 if(!
id || (nr_areas <= 0) || (pages_per_area < 0))
770 if(pages_per_area > 0){
771 new_areas = debug_areas_alloc(pages_per_area, nr_areas);
773 pr_info(
"Allocating memory for %i pages failed\n",
782 debug_areas_free(
id);
783 id->areas = new_areas;
784 id->nr_areas = nr_areas;
785 id->pages_per_area = pages_per_area;
789 spin_unlock_irqrestore(&id->
lock,flags);
790 pr_info(
"%s: set new size (%i pages)\n" ,id->
name, pages_per_area);
811 pr_info(
"%s: level %i is out of range (%i - %i)\n",
814 id->level = new_level;
816 spin_unlock_irqrestore(&id->
lock,flags);
830 id->active_entries[
id->active_area] = 0;
831 id->active_pages[
id->active_area] =
832 (
id->active_pages[
id->active_area] + 1) %
846 id->active_area =
id->active_area %
id->nr_areas;
858 id->active_entries[
id->active_area]);
872 active->
caller = __builtin_return_address(0);
875 proceed_active_entry(
id);
877 proceed_active_area(
id);
880 static int debug_stoppable=1;
881 static int debug_active=1;
883 #define CTL_S390DBF_STOPPABLE 5678
884 #define CTL_S390DBF_ACTIVE 5679
893 void __user *
buffer,
size_t *lenp, loff_t *ppos)
895 if (!write || debug_stoppable || !debug_active)
902 static struct ctl_table s390dbf_table[] = {
904 .procname =
"debug_stoppable",
905 .data = &debug_stoppable,
906 .maxlen =
sizeof(
int),
911 .procname =
"debug_active",
912 .data = &debug_active,
913 .maxlen =
sizeof(
int),
920 static struct ctl_table s390dbf_dir_table[] = {
922 .procname =
"s390dbf",
925 .child = s390dbf_table,
956 if (!debug_active || !id->
areas)
958 if (debug_critical) {
963 active = get_active_entry(
id);
966 debug_finish_entry(
id, active, level, 0);
967 spin_unlock_irqrestore(&id->
lock, flags);
984 if (!debug_active || !id->
areas)
986 if (debug_critical) {
991 active = get_active_entry(
id);
994 debug_finish_entry(
id, active, level, 1);
995 spin_unlock_irqrestore(&id->
lock, flags);
1006 debug_count_numargs(
char *
string)
1026 unsigned long flags;
1030 if((!
id) || (level > id->
level))
1032 if (!debug_active || !id->
areas)
1034 numargs=debug_count_numargs(
string);
1036 if (debug_critical) {
1041 active = get_active_entry(
id);
1045 for(idx=0;idx<
min(numargs,(
int)(id->
buf_size /
sizeof(
long))-1);idx++)
1048 debug_finish_entry(
id, active, level, 0);
1049 spin_unlock_irqrestore(&id->
lock, flags);
1064 unsigned long flags;
1068 if((!
id) || (level > id->
level))
1070 if (!debug_active || !id->
areas)
1073 numargs=debug_count_numargs(
string);
1075 if (debug_critical) {
1080 active = get_active_entry(
id);
1084 for(idx=0;idx<
min(numargs,(
int)(id->
buf_size /
sizeof(
long))-1);idx++)
1087 debug_finish_entry(
id, active, level, 1);
1088 spin_unlock_irqrestore(&id->
lock, flags);
1103 unsigned long flags;
1115 id , &debug_file_ops);
1117 pr_err(
"Registering view %s/%s failed due to out of "
1127 if (i == DEBUG_MAX_VIEWS) {
1128 pr_err(
"Registering view %s/%s would exceed the maximum "
1129 "number of views %i\n", id->
name, view->
name, i);
1133 id->views[
i] = view;
1134 id->debugfs_entries[
i] = pde;
1136 spin_unlock_irqrestore(&id->
lock, flags);
1151 unsigned long flags;
1157 if (id->
views[i] == view)
1160 if (i == DEBUG_MAX_VIEWS)
1164 id->views[
i] =
NULL;
1166 spin_unlock_irqrestore(&id->
lock, flags);
1172 static inline char *
1173 debug_get_user_string(
const char __user *user_buf,
size_t user_len)
1185 if (buffer[user_len - 1] ==
'\n')
1186 buffer[user_len - 1] = 0;
1188 buffer[user_len] = 0;
1193 debug_get_uint(
char *
buf)
1227 struct file *file,
const char __user *user_buf,
1228 size_t user_len, loff_t * offset)
1233 if (user_len > 0x10000)
1239 str = debug_get_user_string(user_buf,user_len);
1244 new_pages = debug_get_uint(str);
1249 rc = debug_set_size(
id,id->
nr_areas, new_pages);
1258 *offset += user_len;
1286 struct file *file,
const char __user *user_buf,
1287 size_t user_len, loff_t * offset)
1292 if (user_len > 0x10000)
1298 str = debug_get_user_string(user_buf,user_len);
1308 new_level = debug_get_uint(str);
1311 pr_warning(
"%s is not a valid level for a debug "
1321 *offset += user_len;
1332 unsigned long flags;
1335 if(!
id || !id->
areas)
1339 id->active_area = 0;
1341 for (i = 0; i <
id->nr_areas; i++) {
1342 id->active_pages[
i] = 0;
1343 for(j = 0; j <
id->pages_per_area; j++) {
1347 }
else if(area >= 0 && area < id->nr_areas) {
1348 id->active_entries[area] = 0;
1349 id->active_pages[area] = 0;
1350 for(i = 0; i <
id->pages_per_area; i++) {
1354 spin_unlock_irqrestore(&id->
lock,flags);
1363 struct file *file,
const char __user *user_buf,
1364 size_t user_len, loff_t * offset)
1369 if (user_len > 0x10000)
1379 if(input_buf[0] ==
'-') {
1384 int area = ((
int) input_buf[0] - (
int)
'0');
1385 debug_flush(
id, area);
1389 pr_info(
"Flushing debug data failed because %c is not a valid "
1390 "area\n", input_buf[0]);
1393 *offset += user_len;
1418 char *out_buf,
const char *in_buf)
1433 char *out_buf,
const char *in_buf)
1437 for (i = 0; i <
id->buf_size; i++) {
1438 rc +=
sprintf(out_buf + rc,
"%02x ",
1439 ((
unsigned char *) in_buf)[i]);
1441 rc +=
sprintf(out_buf + rc,
"| ");
1442 for (i = 0; i <
id->buf_size; i++) {
1443 unsigned char c = in_buf[
i];
1445 rc +=
sprintf(out_buf + rc,
"%c", c);
1447 rc +=
sprintf(out_buf + rc,
".");
1449 rc +=
sprintf(out_buf + rc,
"\n");
1468 stck_to_timespec(entry->
id.
stck, &time_spec);
1475 rc +=
sprintf(out_buf,
"%02i %011lu:%06lu %1u %1s %02i %p ",
1477 except_str, entry->
id.
fields.cpuid, (
void *) caller);
1487 #define DEBUG_SPRINTF_MAX_ARGS 10
1493 int num_longs, num_used_args = 0,
i, rc = 0;
1497 num_longs =
id->buf_size /
sizeof(
long);
1501 if(num_longs == 1) {
1513 for(i = 0; i < num_used_args; i++)
1517 curr_event->
args[index[1]], curr_event->
args[index[2]],
1518 curr_event->
args[index[3]], curr_event->
args[index[4]],
1519 curr_event->
args[index[5]], curr_event->
args[index[6]],
1520 curr_event->
args[index[7]], curr_event->
args[index[8]],
1521 curr_event->
args[index[9]]);
1532 static int __init debug_init(
void)