Files
OrangePi_CM5/arch/s390/kernel/debug.c
T

1458 lines
35 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0
2005-04-16 15:20:36 -07:00
/*
* S/390 debug facility
*
2012-03-11 11:59:32 -04:00
* Copyright IBM Corp. 1999, 2012
*
2005-04-16 15:20:36 -07:00
* Author(s): Michael Holzheu (holzheu@de.ibm.com),
2017-10-13 09:06:29 +02:00
* Holger Smolinski (Holger.Smolinski@de.ibm.com)
2005-04-16 15:20:36 -07:00
*
* Bugreports to: <Linux390@de.ibm.com>
*/
#define KMSG_COMPONENT "s390dbf"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
2005-04-16 15:20:36 -07:00
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/string.h>
2005-04-16 15:20:36 -07:00
#include <linux/sysctl.h>
#include <linux/uaccess.h>
#include <linux/export.h>
2005-04-16 15:20:36 -07:00
#include <linux/init.h>
2005-06-25 14:55:33 -07:00
#include <linux/fs.h>
#include <linux/debugfs.h>
2005-04-16 15:20:36 -07:00
#include <asm/debug.h>
#define DEBUG_PROLOG_ENTRY -1
2005-06-25 14:55:33 -07:00
#define ALL_AREAS 0 /* copy all debug areas */
#define NO_AREAS 1 /* copy no debug areas */
2005-04-16 15:20:36 -07:00
/* typedefs */
typedef struct file_private_info {
loff_t offset; /* offset of last read in file */
2017-10-13 09:06:29 +02:00
int act_area; /* number of last formated area */
int act_page; /* act page in given area */
int act_entry; /* last formated entry (offset */
/* relative to beginning of last */
/* formated page) */
size_t act_entry_offset; /* up to this offset we copied */
2005-04-16 15:20:36 -07:00
/* in last read the last formated */
/* entry to userland */
char temp_buf[2048]; /* buffer for output */
2017-10-13 09:06:29 +02:00
debug_info_t *debug_info_org; /* original debug information */
2005-04-16 15:20:36 -07:00
debug_info_t *debug_info_snap; /* snapshot of debug information */
struct debug_view *view; /* used view of debug info */
} file_private_info_t;
2017-10-13 09:06:29 +02:00
typedef struct {
2005-04-16 15:20:36 -07:00
char *string;
2017-10-13 09:06:29 +02:00
/*
* This assumes that all args are converted into longs
* on L/390 this is the case for all types of parameter
* except of floats, and long long (32 bit)
2005-06-25 14:55:33 -07:00
*
*/
2005-04-16 15:20:36 -07:00
long args[0];
} debug_sprintf_entry_t;
/* internal function prototyes */
static int debug_init(void);
static ssize_t debug_output(struct file *file, char __user *user_buf,
2017-10-13 09:06:29 +02:00
size_t user_len, loff_t *offset);
2005-04-16 15:20:36 -07:00
static ssize_t debug_input(struct file *file, const char __user *user_buf,
2017-10-13 09:06:29 +02:00
size_t user_len, loff_t *offset);
2005-04-16 15:20:36 -07:00
static int debug_open(struct inode *inode, struct file *file);
static int debug_close(struct inode *inode, struct file *file);
static debug_info_t *debug_info_create(const char *name, int pages_per_area,
2017-10-13 09:06:29 +02:00
int nr_areas, int buf_size, umode_t mode);
2005-04-16 15:20:36 -07:00
static void debug_info_get(debug_info_t *);
static void debug_info_put(debug_info_t *);
2017-10-13 09:06:29 +02:00
static int debug_prolog_level_fn(debug_info_t *id,
struct debug_view *view, char *out_buf);
static int debug_input_level_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t *offset);
static int debug_prolog_pages_fn(debug_info_t *id,
struct debug_view *view, char *out_buf);
static int debug_input_pages_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t *offset);
static int debug_input_flush_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t *offset);
static int debug_hex_ascii_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, const char *in_buf);
static int debug_raw_format_fn(debug_info_t *id,
struct debug_view *view, char *out_buf,
const char *in_buf);
static int debug_raw_header_fn(debug_info_t *id, struct debug_view *view,
int area, debug_entry_t *entry, char *out_buf);
static int debug_sprintf_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, debug_sprintf_entry_t *curr_event);
2005-04-16 15:20:36 -07:00
/* globals */
struct debug_view debug_raw_view = {
"raw",
NULL,
&debug_raw_header_fn,
&debug_raw_format_fn,
NULL,
NULL
};
EXPORT_SYMBOL(debug_raw_view);
2005-04-16 15:20:36 -07:00
struct debug_view debug_hex_ascii_view = {
"hex_ascii",
NULL,
&debug_dflt_header_fn,
&debug_hex_ascii_format_fn,
NULL,
NULL
};
EXPORT_SYMBOL(debug_hex_ascii_view);
2005-04-16 15:20:36 -07:00
2007-02-05 21:16:47 +01:00
static struct debug_view debug_level_view = {
2005-04-16 15:20:36 -07:00
"level",
&debug_prolog_level_fn,
NULL,
NULL,
&debug_input_level_fn,
NULL
};
2007-02-05 21:16:47 +01:00
static struct debug_view debug_pages_view = {
2005-06-25 14:55:33 -07:00
"pages",
&debug_prolog_pages_fn,
NULL,
NULL,
&debug_input_pages_fn,
NULL
};
2007-02-05 21:16:47 +01:00
static struct debug_view debug_flush_view = {
2017-10-13 09:06:29 +02:00
"flush",
NULL,
NULL,
NULL,
&debug_input_flush_fn,
NULL
2005-04-16 15:20:36 -07:00
};
struct debug_view debug_sprintf_view = {
"sprintf",
NULL,
&debug_dflt_header_fn,
2017-10-13 09:06:29 +02:00
(debug_format_proc_t *)&debug_sprintf_format_fn,
2005-04-16 15:20:36 -07:00
NULL,
NULL
};
EXPORT_SYMBOL(debug_sprintf_view);
2005-04-16 15:20:36 -07:00
2007-02-05 21:16:47 +01:00
/* used by dump analysis tools to determine version of debug feature */
2008-04-17 07:46:26 +02:00
static unsigned int __used debug_feature_version = __DEBUG_FEATURE_VERSION;
2005-04-16 15:20:36 -07:00
/* static globals */
2017-10-13 09:06:29 +02:00
static debug_info_t *debug_area_first;
static debug_info_t *debug_area_last;
static DEFINE_MUTEX(debug_mutex);
2005-04-16 15:20:36 -07:00
static int initialized;
2012-03-11 11:59:32 -04:00
static int debug_critical;
2005-04-16 15:20:36 -07:00
2007-02-12 00:55:31 -08:00
static const struct file_operations debug_file_ops = {
2017-10-13 09:06:29 +02:00
.owner = THIS_MODULE,
.read = debug_output,
.write = debug_input,
.open = debug_open,
2005-04-16 15:20:36 -07:00
.release = debug_close,
2010-08-15 18:52:59 +02:00
.llseek = no_llseek,
2005-04-16 15:20:36 -07:00
};
2005-06-25 14:55:33 -07:00
static struct dentry *debug_debugfs_root_entry;
2005-04-16 15:20:36 -07:00
/* functions */
2005-06-25 14:55:33 -07:00
/*
* debug_areas_alloc
* - Debug areas are implemented as a threedimensonal array:
* areas[areanumber][pagenumber][pageoffset]
*/
2017-10-13 09:06:29 +02:00
static debug_entry_t ***debug_areas_alloc(int pages_per_area, int nr_areas)
2005-06-25 14:55:33 -07:00
{
2017-10-13 09:06:29 +02:00
debug_entry_t ***areas;
int i, j;
2005-06-25 14:55:33 -07:00
2017-10-13 09:06:29 +02:00
areas = kmalloc(nr_areas * sizeof(debug_entry_t **), GFP_KERNEL);
2005-06-25 14:55:33 -07:00
if (!areas)
goto fail_malloc_areas;
for (i = 0; i < nr_areas; i++) {
2017-10-13 09:06:29 +02:00
areas[i] = kmalloc(pages_per_area * sizeof(debug_entry_t *), GFP_KERNEL);
if (!areas[i])
2005-06-25 14:55:33 -07:00
goto fail_malloc_areas2;
2017-10-13 09:06:29 +02:00
for (j = 0; j < pages_per_area; j++) {
areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
2017-10-13 09:06:29 +02:00
if (!areas[i][j]) {
for (j--; j >= 0 ; j--)
2005-06-25 14:55:33 -07:00
kfree(areas[i][j]);
kfree(areas[i]);
goto fail_malloc_areas2;
}
}
}
return areas;
fail_malloc_areas2:
2017-10-13 09:06:29 +02:00
for (i--; i >= 0; i--) {
for (j = 0; j < pages_per_area; j++)
2005-06-25 14:55:33 -07:00
kfree(areas[i][j]);
kfree(areas[i]);
}
kfree(areas);
fail_malloc_areas:
return NULL;
}
2005-04-16 15:20:36 -07:00
/*
* debug_info_alloc
* - alloc new debug-info
*/
2017-10-13 09:06:29 +02:00
static debug_info_t *debug_info_alloc(const char *name, int pages_per_area,
int nr_areas, int buf_size, int level,
int mode)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
debug_info_t *rc;
2005-04-16 15:20:36 -07:00
/* alloc everything */
rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
2017-10-13 09:06:29 +02:00
if (!rc)
2005-04-16 15:20:36 -07:00
goto fail_malloc_rc;
rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
2017-10-13 09:06:29 +02:00
if (!rc->active_entries)
2005-06-25 14:55:33 -07:00
goto fail_malloc_active_entries;
rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
2017-10-13 09:06:29 +02:00
if (!rc->active_pages)
2005-06-25 14:55:33 -07:00
goto fail_malloc_active_pages;
2017-10-13 09:06:29 +02:00
if ((mode == ALL_AREAS) && (pages_per_area != 0)) {
2005-06-25 14:55:33 -07:00
rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
2017-10-13 09:06:29 +02:00
if (!rc->areas)
2005-06-25 14:55:33 -07:00
goto fail_malloc_areas;
} else {
rc->areas = NULL;
2005-04-16 15:20:36 -07:00
}
/* initialize members */
spin_lock_init(&rc->lock);
2005-06-25 14:55:33 -07:00
rc->pages_per_area = pages_per_area;
2017-10-13 09:06:29 +02:00
rc->nr_areas = nr_areas;
2005-06-25 14:55:33 -07:00
rc->active_area = 0;
2017-10-13 09:06:29 +02:00
rc->level = level;
rc->buf_size = buf_size;
rc->entry_size = sizeof(debug_entry_t) + buf_size;
2007-03-19 13:18:53 +01:00
strlcpy(rc->name, name, sizeof(rc->name));
2005-04-16 15:20:36 -07:00
memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
2017-10-13 09:06:29 +02:00
memset(rc->debugfs_entries, 0, DEBUG_MAX_VIEWS * sizeof(struct dentry *));
refcount_set(&(rc->ref_count), 0);
2005-04-16 15:20:36 -07:00
return rc;
fail_malloc_areas:
2005-06-25 14:55:33 -07:00
kfree(rc->active_pages);
fail_malloc_active_pages:
kfree(rc->active_entries);
fail_malloc_active_entries:
2005-04-16 15:20:36 -07:00
kfree(rc);
fail_malloc_rc:
return NULL;
}
/*
2005-06-25 14:55:33 -07:00
* debug_areas_free
* - free all debug areas
2005-04-16 15:20:36 -07:00
*/
2017-10-13 09:06:29 +02:00
static void debug_areas_free(debug_info_t *db_info)
2005-06-25 14:55:33 -07:00
{
2017-10-13 09:06:29 +02:00
int i, j;
2005-06-25 14:55:33 -07:00
2017-10-13 09:06:29 +02:00
if (!db_info->areas)
2005-06-25 14:55:33 -07:00
return;
2005-04-16 15:20:36 -07:00
for (i = 0; i < db_info->nr_areas; i++) {
2017-10-13 09:06:29 +02:00
for (j = 0; j < db_info->pages_per_area; j++)
2005-06-25 14:55:33 -07:00
kfree(db_info->areas[i][j]);
kfree(db_info->areas[i]);
2005-04-16 15:20:36 -07:00
}
kfree(db_info->areas);
2005-06-25 14:55:33 -07:00
db_info->areas = NULL;
}
/*
* debug_info_free
* - free memory debug-info
*/
2017-10-13 09:06:29 +02:00
static void debug_info_free(debug_info_t *db_info)
{
2005-06-25 14:55:33 -07:00
debug_areas_free(db_info);
kfree(db_info->active_entries);
kfree(db_info->active_pages);
2005-04-16 15:20:36 -07:00
kfree(db_info);
}
/*
* debug_info_create
* - create new debug-info
*/
2017-10-13 09:06:29 +02:00
static debug_info_t *debug_info_create(const char *name, int pages_per_area,
int nr_areas, int buf_size, umode_t mode)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
debug_info_t *rc;
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
DEBUG_DEFAULT_LEVEL, ALL_AREAS);
if (!rc)
2005-04-16 15:20:36 -07:00
goto out;
rc->mode = mode & ~S_IFMT;
2005-06-25 14:55:33 -07:00
/* create root directory */
2017-10-13 09:06:29 +02:00
rc->debugfs_root_entry = debugfs_create_dir(rc->name,
debug_debugfs_root_entry);
2005-04-16 15:20:36 -07:00
/* append new element to linked list */
2017-10-13 09:06:29 +02:00
if (!debug_area_first) {
/* first element in list */
debug_area_first = rc;
rc->prev = NULL;
} else {
/* append element to end of list */
debug_area_last->next = rc;
rc->prev = debug_area_last;
}
debug_area_last = rc;
rc->next = NULL;
2005-04-16 15:20:36 -07:00
refcount_set(&rc->ref_count, 1);
2005-04-16 15:20:36 -07:00
out:
return rc;
}
/*
* debug_info_copy
* - copy debug-info
*/
2017-10-13 09:06:29 +02:00
static debug_info_t *debug_info_copy(debug_info_t *in, int mode)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
unsigned long flags;
debug_info_t *rc;
int i, j;
2005-09-03 15:57:58 -07:00
/* get a consistent copy of the debug areas */
do {
rc = debug_info_alloc(in->name, in->pages_per_area,
in->nr_areas, in->buf_size, in->level, mode);
spin_lock_irqsave(&in->lock, flags);
2017-10-13 09:06:29 +02:00
if (!rc)
2005-09-03 15:57:58 -07:00
goto out;
/* has something changed in the meantime ? */
2017-10-13 09:06:29 +02:00
if ((rc->pages_per_area == in->pages_per_area) &&
(rc->nr_areas == in->nr_areas)) {
2005-09-03 15:57:58 -07:00
break;
}
spin_unlock_irqrestore(&in->lock, flags);
debug_info_free(rc);
} while (1);
2005-06-25 14:55:33 -07:00
2008-12-25 13:39:30 +01:00
if (mode == NO_AREAS)
2017-10-13 09:06:29 +02:00
goto out;
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
for (i = 0; i < in->nr_areas; i++) {
for (j = 0; j < in->pages_per_area; j++)
memcpy(rc->areas[i][j], in->areas[i][j], PAGE_SIZE);
}
2005-04-16 15:20:36 -07:00
out:
2017-10-13 09:06:29 +02:00
spin_unlock_irqrestore(&in->lock, flags);
return rc;
2005-04-16 15:20:36 -07:00
}
/*
* debug_info_get
* - increments reference count for debug-info
*/
2017-10-13 09:06:29 +02:00
static void debug_info_get(debug_info_t *db_info)
2005-04-16 15:20:36 -07:00
{
if (db_info)
refcount_inc(&db_info->ref_count);
2005-04-16 15:20:36 -07:00
}
/*
* debug_info_put:
* - decreases reference count for debug-info and frees it if necessary
*/
2017-10-13 09:06:29 +02:00
static void debug_info_put(debug_info_t *db_info)
2005-04-16 15:20:36 -07:00
{
int i;
if (!db_info)
return;
if (refcount_dec_and_test(&db_info->ref_count)) {
2005-04-16 15:20:36 -07:00
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
2005-06-25 14:55:33 -07:00
if (!db_info->views[i])
2005-04-16 15:20:36 -07:00
continue;
2005-06-25 14:55:33 -07:00
debugfs_remove(db_info->debugfs_entries[i]);
2005-04-16 15:20:36 -07:00
}
2005-06-25 14:55:33 -07:00
debugfs_remove(db_info->debugfs_root_entry);
2017-10-13 09:06:29 +02:00
if (db_info == debug_area_first)
2005-04-16 15:20:36 -07:00
debug_area_first = db_info->next;
2017-10-13 09:06:29 +02:00
if (db_info == debug_area_last)
2005-04-16 15:20:36 -07:00
debug_area_last = db_info->prev;
2017-10-13 09:06:29 +02:00
if (db_info->prev)
db_info->prev->next = db_info->next;
if (db_info->next)
db_info->next->prev = db_info->prev;
2005-04-16 15:20:36 -07:00
debug_info_free(db_info);
}
}
/*
* debug_format_entry:
* - format one debug entry and return size of formated data
*/
2017-10-13 09:06:29 +02:00
static int debug_format_entry(file_private_info_t *p_info)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
debug_info_t *id_snap = p_info->debug_info_snap;
2005-04-16 15:20:36 -07:00
struct debug_view *view = p_info->view;
debug_entry_t *act_entry;
size_t len = 0;
2017-10-13 09:06:29 +02:00
if (p_info->act_entry == DEBUG_PROLOG_ENTRY) {
2005-04-16 15:20:36 -07:00
/* print prolog */
2017-10-13 09:06:29 +02:00
if (view->prolog_proc)
len += view->prolog_proc(id_snap, view, p_info->temp_buf);
2005-04-16 15:20:36 -07:00
goto out;
}
2005-06-25 14:55:33 -07:00
if (!id_snap->areas) /* this is true, if we have a prolog only view */
goto out; /* or if 'pages_per_area' is 0 */
2017-10-13 09:06:29 +02:00
act_entry = (debug_entry_t *) ((char *)id_snap->areas[p_info->act_area]
[p_info->act_page] + p_info->act_entry);
2005-04-16 15:20:36 -07:00
if (act_entry->id.stck == 0LL)
2017-10-13 09:06:29 +02:00
goto out; /* empty entry */
2005-04-16 15:20:36 -07:00
if (view->header_proc)
2005-06-25 14:55:33 -07:00
len += view->header_proc(id_snap, view, p_info->act_area,
2017-10-13 09:06:29 +02:00
act_entry, p_info->temp_buf + len);
2005-04-16 15:20:36 -07:00
if (view->format_proc)
2005-06-25 14:55:33 -07:00
len += view->format_proc(id_snap, view, p_info->temp_buf + len,
2017-10-13 09:06:29 +02:00
DEBUG_DATA(act_entry));
2005-06-25 14:55:33 -07:00
out:
2017-10-13 09:06:29 +02:00
return len;
2005-04-16 15:20:36 -07:00
}
/*
* debug_next_entry:
* - goto next entry in p_info
*/
2017-10-13 09:06:29 +02:00
static inline int debug_next_entry(file_private_info_t *p_info)
2005-04-16 15:20:36 -07:00
{
2005-06-25 14:55:33 -07:00
debug_info_t *id;
id = p_info->debug_info_snap;
2017-10-13 09:06:29 +02:00
if (p_info->act_entry == DEBUG_PROLOG_ENTRY) {
2005-04-16 15:20:36 -07:00
p_info->act_entry = 0;
2005-06-25 14:55:33 -07:00
p_info->act_page = 0;
2005-04-16 15:20:36 -07:00
goto out;
}
2017-10-13 09:06:29 +02:00
if (!id->areas)
2005-06-25 14:55:33 -07:00
return 1;
p_info->act_entry += id->entry_size;
/* switch to next page, if we reached the end of the page */
2017-10-13 09:06:29 +02:00
if (p_info->act_entry > (PAGE_SIZE - id->entry_size)) {
2005-06-25 14:55:33 -07:00
/* next page */
2005-04-16 15:20:36 -07:00
p_info->act_entry = 0;
2005-06-25 14:55:33 -07:00
p_info->act_page += 1;
2017-10-13 09:06:29 +02:00
if ((p_info->act_page % id->pages_per_area) == 0) {
2005-06-25 14:55:33 -07:00
/* next area */
2017-10-13 09:06:29 +02:00
p_info->act_area++;
p_info->act_page = 0;
2005-06-25 14:55:33 -07:00
}
2017-10-13 09:06:29 +02:00
if (p_info->act_area >= id->nr_areas)
2005-04-16 15:20:36 -07:00
return 1;
}
out:
2017-10-13 09:06:29 +02:00
return 0;
2005-04-16 15:20:36 -07:00
}
/*
* debug_output:
* - called for user read()
* - copies formated debug entries to the user buffer
*/
2017-10-13 09:06:29 +02:00
static ssize_t debug_output(struct file *file, /* file descriptor */
char __user *user_buf, /* user buffer */
size_t len, /* length of buffer */
loff_t *offset) /* offset in the file */
2005-04-16 15:20:36 -07:00
{
size_t count = 0;
2005-06-25 14:55:33 -07:00
size_t entry_offset;
2005-04-16 15:20:36 -07:00
file_private_info_t *p_info;
2017-10-13 09:06:29 +02:00
p_info = (file_private_info_t *) file->private_data;
if (*offset != p_info->offset)
2005-04-16 15:20:36 -07:00
return -EPIPE;
2017-10-13 09:06:29 +02:00
if (p_info->act_area >= p_info->debug_info_snap->nr_areas)
2005-04-16 15:20:36 -07:00
return 0;
entry_offset = p_info->act_entry_offset;
2017-10-13 09:06:29 +02:00
while (count < len) {
2005-06-25 14:55:33 -07:00
int formatted_line_residue;
2017-10-13 09:06:29 +02:00
int formatted_line_size;
2005-06-25 14:55:33 -07:00
int user_buf_residue;
size_t copy_size;
formatted_line_size = debug_format_entry(p_info);
formatted_line_residue = formatted_line_size - entry_offset;
user_buf_residue = len-count;
copy_size = min(user_buf_residue, formatted_line_residue);
2017-10-13 09:06:29 +02:00
if (copy_size) {
2005-06-25 14:55:33 -07:00
if (copy_to_user(user_buf + count, p_info->temp_buf
2017-10-13 09:06:29 +02:00
+ entry_offset, copy_size))
2005-06-25 14:55:33 -07:00
return -EFAULT;
count += copy_size;
entry_offset += copy_size;
2005-04-16 15:20:36 -07:00
}
2017-10-13 09:06:29 +02:00
if (copy_size == formatted_line_residue) {
2005-06-25 14:55:33 -07:00
entry_offset = 0;
2017-10-13 09:06:29 +02:00
if (debug_next_entry(p_info))
2005-04-16 15:20:36 -07:00
goto out;
2005-06-25 14:55:33 -07:00
}
2005-04-16 15:20:36 -07:00
}
out:
2017-10-13 09:06:29 +02:00
p_info->offset = *offset + count;
2005-06-25 14:55:33 -07:00
p_info->act_entry_offset = entry_offset;
2005-04-16 15:20:36 -07:00
*offset = p_info->offset;
return count;
}
/*
* debug_input:
* - called for user write()
* - calls input function of view
*/
2017-10-13 09:06:29 +02:00
static ssize_t debug_input(struct file *file, const char __user *user_buf,
size_t length, loff_t *offset)
2005-04-16 15:20:36 -07:00
{
file_private_info_t *p_info;
2017-10-13 09:06:29 +02:00
int rc = 0;
2005-04-16 15:20:36 -07:00
mutex_lock(&debug_mutex);
2005-04-16 15:20:36 -07:00
p_info = ((file_private_info_t *) file->private_data);
2017-10-13 09:06:29 +02:00
if (p_info->view->input_proc) {
2005-04-16 15:20:36 -07:00
rc = p_info->view->input_proc(p_info->debug_info_org,
p_info->view, file, user_buf,
length, offset);
2017-10-13 09:06:29 +02:00
} else {
2005-04-16 15:20:36 -07:00
rc = -EPERM;
2017-10-13 09:06:29 +02:00
}
mutex_unlock(&debug_mutex);
2017-10-13 09:06:29 +02:00
return rc; /* number of input characters */
2005-04-16 15:20:36 -07:00
}
/*
* debug_open:
* - called for user open()
* - copies formated output to private_data area of the file
* handle
*/
2017-10-13 09:06:29 +02:00
static int debug_open(struct inode *inode, struct file *file)
2005-04-16 15:20:36 -07:00
{
debug_info_t *debug_info, *debug_info_snapshot;
2017-10-13 09:06:29 +02:00
file_private_info_t *p_info;
int i, rc = 0;
2005-04-16 15:20:36 -07:00
mutex_lock(&debug_mutex);
2013-01-23 17:07:38 -05:00
debug_info = file_inode(file)->i_private;
2005-09-03 15:57:58 -07:00
/* find debug view */
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (!debug_info->views[i])
continue;
2017-10-13 09:06:29 +02:00
else if (debug_info->debugfs_entries[i] == file->f_path.dentry)
goto found; /* found view ! */
2005-04-16 15:20:36 -07:00
}
/* no entry found */
rc = -EINVAL;
goto out;
2005-06-25 14:55:33 -07:00
found:
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
/* Make snapshot of current debug areas to get it consistent. */
2005-06-25 14:55:33 -07:00
/* To copy all the areas is only needed, if we have a view which */
/* formats the debug areas. */
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
if (!debug_info->views[i]->format_proc && !debug_info->views[i]->header_proc)
2005-06-25 14:55:33 -07:00
debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
2017-10-13 09:06:29 +02:00
else
2005-06-25 14:55:33 -07:00
debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
if (!debug_info_snapshot) {
2005-04-16 15:20:36 -07:00
rc = -ENOMEM;
goto out;
}
2017-10-13 09:06:29 +02:00
p_info = kmalloc(sizeof(file_private_info_t), GFP_KERNEL);
if (!p_info) {
debug_info_free(debug_info_snapshot);
2005-04-16 15:20:36 -07:00
rc = -ENOMEM;
goto out;
}
p_info->offset = 0;
p_info->debug_info_snap = debug_info_snapshot;
2017-10-13 09:06:29 +02:00
p_info->debug_info_org = debug_info;
2005-04-16 15:20:36 -07:00
p_info->view = debug_info->views[i];
p_info->act_area = 0;
2005-06-25 14:55:33 -07:00
p_info->act_page = 0;
2005-04-16 15:20:36 -07:00
p_info->act_entry = DEBUG_PROLOG_ENTRY;
p_info->act_entry_offset = 0;
2005-06-25 14:55:33 -07:00
file->private_data = p_info;
2005-04-16 15:20:36 -07:00
debug_info_get(debug_info);
2010-05-17 10:00:07 +02:00
nonseekable_open(inode, file);
2005-06-25 14:55:33 -07:00
out:
mutex_unlock(&debug_mutex);
2005-04-16 15:20:36 -07:00
return rc;
}
/*
* debug_close:
* - called for user close()
* - deletes private_data area of the file handle
*/
2017-10-13 09:06:29 +02:00
static int debug_close(struct inode *inode, struct file *file)
2005-04-16 15:20:36 -07:00
{
file_private_info_t *p_info;
2017-10-13 09:06:29 +02:00
2005-04-16 15:20:36 -07:00
p_info = (file_private_info_t *) file->private_data;
2017-10-13 09:06:29 +02:00
if (p_info->debug_info_snap)
2005-06-25 14:55:33 -07:00
debug_info_free(p_info->debug_info_snap);
2005-04-16 15:20:36 -07:00
debug_info_put(p_info->debug_info_org);
kfree(file->private_data);
2017-10-13 09:06:29 +02:00
return 0; /* success */
2005-04-16 15:20:36 -07:00
}
/*
* debug_register_mode:
* - Creates and initializes debug area for the caller
* The mode parameter allows to specify access rights for the s390dbf files
* - Returns handle for debug area
2005-04-16 15:20:36 -07:00
*/
debug_info_t *debug_register_mode(const char *name, int pages_per_area,
2011-07-24 04:33:43 -04:00
int nr_areas, int buf_size, umode_t mode,
uid_t uid, gid_t gid)
2005-04-16 15:20:36 -07:00
{
debug_info_t *rc = NULL;
/* Since debugfs currently does not support uid/gid other than root, */
/* we do not allow gid/uid != 0 until we get support for that. */
if ((uid != 0) || (gid != 0))
2016-03-03 20:49:57 -08:00
pr_warn("Root becomes the owner of all s390dbf files in sysfs\n");
2009-03-26 15:24:47 +01:00
BUG_ON(!initialized);
mutex_lock(&debug_mutex);
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
/* create new debug_info */
rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
2017-10-13 09:06:29 +02:00
if (!rc)
2005-04-16 15:20:36 -07:00
goto out;
debug_register_view(rc, &debug_level_view);
2017-10-13 09:06:29 +02:00
debug_register_view(rc, &debug_flush_view);
2005-06-25 14:55:33 -07:00
debug_register_view(rc, &debug_pages_view);
out:
2017-10-13 09:06:29 +02:00
if (!rc)
pr_err("Registering debug feature %s failed\n", name);
mutex_unlock(&debug_mutex);
2005-04-16 15:20:36 -07:00
return rc;
}
EXPORT_SYMBOL(debug_register_mode);
/*
* debug_register:
* - creates and initializes debug area for the caller
* - returns handle for debug area
*/
debug_info_t *debug_register(const char *name, int pages_per_area,
int nr_areas, int buf_size)
{
return debug_register_mode(name, pages_per_area, nr_areas, buf_size,
S_IRUSR | S_IWUSR, 0, 0);
}
EXPORT_SYMBOL(debug_register);
2005-04-16 15:20:36 -07:00
/*
* debug_unregister:
* - give back debug area
*/
2017-10-13 09:06:29 +02:00
void debug_unregister(debug_info_t *id)
2005-04-16 15:20:36 -07:00
{
if (!id)
2017-10-13 09:06:29 +02:00
return;
mutex_lock(&debug_mutex);
2005-04-16 15:20:36 -07:00
debug_info_put(id);
mutex_unlock(&debug_mutex);
2005-04-16 15:20:36 -07:00
}
EXPORT_SYMBOL(debug_unregister);
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
/*
* debug_set_size:
* - set area size (number of pages) and number of areas
*/
2017-10-13 09:06:29 +02:00
static int debug_set_size(debug_info_t *id, int nr_areas, int pages_per_area)
2005-06-25 14:55:33 -07:00
{
2017-10-13 09:06:29 +02:00
debug_entry_t ***new_areas;
2005-06-25 14:55:33 -07:00
unsigned long flags;
2017-10-13 09:06:29 +02:00
int rc = 0;
2005-06-25 14:55:33 -07:00
2017-10-13 09:06:29 +02:00
if (!id || (nr_areas <= 0) || (pages_per_area < 0))
2005-06-25 14:55:33 -07:00
return -EINVAL;
2017-10-13 09:06:29 +02:00
if (pages_per_area > 0) {
2005-06-25 14:55:33 -07:00
new_areas = debug_areas_alloc(pages_per_area, nr_areas);
2017-10-13 09:06:29 +02:00
if (!new_areas) {
pr_info("Allocating memory for %i pages failed\n",
pages_per_area);
2005-06-25 14:55:33 -07:00
rc = -ENOMEM;
goto out;
}
} else {
new_areas = NULL;
}
2017-10-13 09:06:29 +02:00
spin_lock_irqsave(&id->lock, flags);
2005-06-25 14:55:33 -07:00
debug_areas_free(id);
id->areas = new_areas;
id->nr_areas = nr_areas;
id->pages_per_area = pages_per_area;
id->active_area = 0;
2017-10-13 09:06:29 +02:00
memset(id->active_entries, 0, sizeof(int)*id->nr_areas);
2005-06-25 14:55:33 -07:00
memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
2017-10-13 09:06:29 +02:00
spin_unlock_irqrestore(&id->lock, flags);
pr_info("%s: set new size (%i pages)\n", id->name, pages_per_area);
2005-06-25 14:55:33 -07:00
out:
return rc;
}
2005-04-16 15:20:36 -07:00
/*
* debug_set_level:
* - set actual debug level
*/
2017-10-13 09:06:29 +02:00
void debug_set_level(debug_info_t *id, int new_level)
2005-04-16 15:20:36 -07:00
{
unsigned long flags;
2017-10-13 09:06:29 +02:00
if (!id)
return;
spin_lock_irqsave(&id->lock, flags);
if (new_level == DEBUG_OFF_LEVEL) {
id->level = DEBUG_OFF_LEVEL;
pr_info("%s: switched off\n", id->name);
} else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
pr_info("%s: level %i is out of range (%i - %i)\n",
2017-10-13 09:06:29 +02:00
id->name, new_level, 0, DEBUG_MAX_LEVEL);
} else {
id->level = new_level;
}
spin_unlock_irqrestore(&id->lock, flags);
2005-04-16 15:20:36 -07:00
}
EXPORT_SYMBOL(debug_set_level);
2005-04-16 15:20:36 -07:00
/*
* proceed_active_entry:
* - set active entry to next in the ring buffer
*/
2017-10-13 09:06:29 +02:00
static inline void proceed_active_entry(debug_info_t *id)
2005-04-16 15:20:36 -07:00
{
2005-06-25 14:55:33 -07:00
if ((id->active_entries[id->active_area] += id->entry_size)
2017-10-13 09:06:29 +02:00
> (PAGE_SIZE - id->entry_size)) {
2005-06-25 14:55:33 -07:00
id->active_entries[id->active_area] = 0;
id->active_pages[id->active_area] =
(id->active_pages[id->active_area] + 1) %
id->pages_per_area;
}
2005-04-16 15:20:36 -07:00
}
/*
* proceed_active_area:
* - set active area to next in the ring buffer
*/
2017-10-13 09:06:29 +02:00
static inline void proceed_active_area(debug_info_t *id)
2005-04-16 15:20:36 -07:00
{
id->active_area++;
id->active_area = id->active_area % id->nr_areas;
}
/*
* get_active_entry:
*/
2017-10-13 09:06:29 +02:00
static inline debug_entry_t *get_active_entry(debug_info_t *id)
2005-04-16 15:20:36 -07:00
{
2005-06-25 14:55:33 -07:00
return (debug_entry_t *) (((char *) id->areas[id->active_area]
2017-10-13 09:06:29 +02:00
[id->active_pages[id->active_area]]) +
id->active_entries[id->active_area]);
2005-04-16 15:20:36 -07:00
}
/*
* debug_finish_entry:
* - set timestamp, caller address, cpu number etc.
*/
2017-10-13 09:06:29 +02:00
static inline void debug_finish_entry(debug_info_t *id, debug_entry_t *active,
int level, int exception)
2005-04-16 15:20:36 -07:00
{
active->id.stck = get_tod_clock_fast() -
*(unsigned long long *) &tod_clock_base[1];
2005-04-16 15:20:36 -07:00
active->id.fields.cpuid = smp_processor_id();
active->caller = __builtin_return_address(0);
active->id.fields.exception = exception;
2017-10-13 09:06:29 +02:00
active->id.fields.level = level;
2005-04-16 15:20:36 -07:00
proceed_active_entry(id);
2017-10-13 09:06:29 +02:00
if (exception)
2005-04-16 15:20:36 -07:00
proceed_active_area(id);
}
2017-10-13 09:06:29 +02:00
static int debug_stoppable = 1;
static int debug_active = 1;
2005-04-16 15:20:36 -07:00
#define CTL_S390DBF_STOPPABLE 5678
#define CTL_S390DBF_ACTIVE 5679
/*
* proc handler for the running debug_active sysctl
* always allow read, allow write only if debug_stoppable is set or
* if debug_active is already off
*/
2017-10-13 09:06:29 +02:00
static int s390dbf_procactive(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
2005-04-16 15:20:36 -07:00
{
if (!write || debug_stoppable || !debug_active)
return proc_dointvec(table, write, buffer, lenp, ppos);
2005-04-16 15:20:36 -07:00
else
return 0;
}
static struct ctl_table s390dbf_table[] = {
{
2017-10-13 09:06:29 +02:00
.procname = "debug_stoppable",
2005-04-16 15:20:36 -07:00
.data = &debug_stoppable,
.maxlen = sizeof(int),
2017-10-13 09:06:29 +02:00
.mode = S_IRUGO | S_IWUSR,
.proc_handler = proc_dointvec,
2005-04-16 15:20:36 -07:00
},
2017-10-13 09:06:29 +02:00
{
.procname = "debug_active",
2005-04-16 15:20:36 -07:00
.data = &debug_active,
.maxlen = sizeof(int),
2017-10-13 09:06:29 +02:00
.mode = S_IRUGO | S_IWUSR,
.proc_handler = s390dbf_procactive,
2005-04-16 15:20:36 -07:00
},
{ }
2005-04-16 15:20:36 -07:00
};
static struct ctl_table s390dbf_dir_table[] = {
{
2017-10-13 09:06:29 +02:00
.procname = "s390dbf",
.maxlen = 0,
.mode = S_IRUGO | S_IXUGO,
.child = s390dbf_table,
2005-04-16 15:20:36 -07:00
},
{ }
2005-04-16 15:20:36 -07:00
};
2007-02-05 21:16:47 +01:00
static struct ctl_table_header *s390dbf_sysctl_header;
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
void debug_stop_all(void)
2005-04-16 15:20:36 -07:00
{
if (debug_stoppable)
debug_active = 0;
}
EXPORT_SYMBOL(debug_stop_all);
2005-04-16 15:20:36 -07:00
2012-03-11 11:59:32 -04:00
void debug_set_critical(void)
{
debug_critical = 1;
}
2005-04-16 15:20:36 -07:00
/*
* debug_event_common:
* - write debug entry with given size
*/
2017-10-13 09:06:29 +02:00
debug_entry_t *debug_event_common(debug_info_t *id, int level, const void *buf,
int len)
2005-04-16 15:20:36 -07:00
{
debug_entry_t *active;
2017-10-13 09:06:29 +02:00
unsigned long flags;
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
if (!debug_active || !id->areas)
2005-04-16 15:20:36 -07:00
return NULL;
2012-03-11 11:59:32 -04:00
if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags))
return NULL;
2017-10-13 09:06:29 +02:00
} else {
2012-03-11 11:59:32 -04:00
spin_lock_irqsave(&id->lock, flags);
2017-10-13 09:06:29 +02:00
}
2017-10-09 17:49:38 +02:00
do {
active = get_active_entry(id);
memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
2017-10-12 13:57:26 +02:00
if (len < id->buf_size)
memset((DEBUG_DATA(active)) + len, 0, id->buf_size - len);
2017-10-09 17:49:38 +02:00
debug_finish_entry(id, active, level, 0);
len -= id->buf_size;
buf += id->buf_size;
} while (len > 0);
2005-04-16 15:20:36 -07:00
2017-10-09 17:49:38 +02:00
spin_unlock_irqrestore(&id->lock, flags);
2005-04-16 15:20:36 -07:00
return active;
}
EXPORT_SYMBOL(debug_event_common);
2005-04-16 15:20:36 -07:00
/*
* debug_exception_common:
* - write debug entry with given size and switch to next debug area
*/
2017-10-13 09:06:29 +02:00
debug_entry_t *debug_exception_common(debug_info_t *id, int level,
const void *buf, int len)
2005-04-16 15:20:36 -07:00
{
debug_entry_t *active;
2017-10-13 09:06:29 +02:00
unsigned long flags;
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
if (!debug_active || !id->areas)
2005-04-16 15:20:36 -07:00
return NULL;
2012-03-11 11:59:32 -04:00
if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags))
return NULL;
2017-10-13 09:06:29 +02:00
} else {
2012-03-11 11:59:32 -04:00
spin_lock_irqsave(&id->lock, flags);
2017-10-13 09:06:29 +02:00
}
2017-10-09 17:49:38 +02:00
do {
active = get_active_entry(id);
memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
2017-10-12 13:57:26 +02:00
if (len < id->buf_size)
memset((DEBUG_DATA(active)) + len, 0, id->buf_size - len);
2017-10-09 17:49:38 +02:00
debug_finish_entry(id, active, level, len <= id->buf_size);
len -= id->buf_size;
buf += id->buf_size;
} while (len > 0);
2005-04-16 15:20:36 -07:00
2017-10-09 17:49:38 +02:00
spin_unlock_irqrestore(&id->lock, flags);
2005-04-16 15:20:36 -07:00
return active;
}
EXPORT_SYMBOL(debug_exception_common);
2005-04-16 15:20:36 -07:00
/*
* counts arguments in format string for sprintf view
*/
2017-10-13 09:06:29 +02:00
static inline int debug_count_numargs(char *string)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
int numargs = 0;
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
while (*string) {
if (*string++ == '%')
2005-04-16 15:20:36 -07:00
numargs++;
}
2017-10-13 09:06:29 +02:00
return numargs;
2005-04-16 15:20:36 -07:00
}
/*
* debug_sprintf_event:
*/
2017-10-13 09:06:29 +02:00
debug_entry_t *__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
2005-04-16 15:20:36 -07:00
{
debug_sprintf_entry_t *curr_event;
debug_entry_t *active;
2017-10-13 09:06:29 +02:00
unsigned long flags;
int numargs, idx;
va_list ap;
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
if (!debug_active || !id->areas)
2005-04-16 15:20:36 -07:00
return NULL;
2017-10-13 09:06:29 +02:00
numargs = debug_count_numargs(string);
2005-04-16 15:20:36 -07:00
2012-03-11 11:59:32 -04:00
if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags))
return NULL;
2017-10-13 09:06:29 +02:00
} else {
2012-03-11 11:59:32 -04:00
spin_lock_irqsave(&id->lock, flags);
2017-10-13 09:06:29 +02:00
}
2005-04-16 15:20:36 -07:00
active = get_active_entry(id);
2017-10-13 09:06:29 +02:00
curr_event = (debug_sprintf_entry_t *) DEBUG_DATA(active);
va_start(ap, string);
curr_event->string = string;
for (idx = 0; idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1); idx++)
curr_event->args[idx] = va_arg(ap, long);
2005-04-16 15:20:36 -07:00
va_end(ap);
debug_finish_entry(id, active, level, 0);
spin_unlock_irqrestore(&id->lock, flags);
return active;
}
EXPORT_SYMBOL(__debug_sprintf_event);
2005-04-16 15:20:36 -07:00
/*
* debug_sprintf_exception:
*/
2017-10-13 09:06:29 +02:00
debug_entry_t *__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
2005-04-16 15:20:36 -07:00
{
debug_sprintf_entry_t *curr_event;
debug_entry_t *active;
2017-10-13 09:06:29 +02:00
unsigned long flags;
int numargs, idx;
va_list ap;
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
if (!debug_active || !id->areas)
2005-04-16 15:20:36 -07:00
return NULL;
2017-10-13 09:06:29 +02:00
numargs = debug_count_numargs(string);
2005-04-16 15:20:36 -07:00
2012-03-11 11:59:32 -04:00
if (debug_critical) {
if (!spin_trylock_irqsave(&id->lock, flags))
return NULL;
2017-10-13 09:06:29 +02:00
} else {
2012-03-11 11:59:32 -04:00
spin_lock_irqsave(&id->lock, flags);
2017-10-13 09:06:29 +02:00
}
2005-04-16 15:20:36 -07:00
active = get_active_entry(id);
2017-10-13 09:06:29 +02:00
curr_event = (debug_sprintf_entry_t *)DEBUG_DATA(active);
va_start(ap, string);
curr_event->string = string;
for (idx = 0; idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1); idx++)
curr_event->args[idx] = va_arg(ap, long);
2005-04-16 15:20:36 -07:00
va_end(ap);
debug_finish_entry(id, active, level, 1);
spin_unlock_irqrestore(&id->lock, flags);
return active;
}
EXPORT_SYMBOL(__debug_sprintf_exception);
2005-04-16 15:20:36 -07:00
/*
* debug_register_view:
*/
2017-10-13 09:06:29 +02:00
int debug_register_view(debug_info_t *id, struct debug_view *view)
2005-04-16 15:20:36 -07:00
{
unsigned long flags;
2005-06-25 14:55:33 -07:00
struct dentry *pde;
2017-10-13 09:06:29 +02:00
umode_t mode;
int rc = 0;
int i;
2005-04-16 15:20:36 -07:00
if (!id)
goto out;
mode = (id->mode | S_IFREG) & ~S_IXUGO;
if (!(view->prolog_proc || view->format_proc || view->header_proc))
mode &= ~(S_IRUSR | S_IRGRP | S_IROTH);
if (!view->input_proc)
mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
2005-06-25 14:55:33 -07:00
pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
2017-10-13 09:06:29 +02:00
id, &debug_file_ops);
if (!pde) {
pr_err("Registering view %s/%s failed due to out of "
2017-10-13 09:06:29 +02:00
"memory\n", id->name, view->name);
2005-04-16 15:20:36 -07:00
rc = -1;
goto out;
}
spin_lock_irqsave(&id->lock, flags);
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
2005-06-25 14:55:33 -07:00
if (!id->views[i])
2005-04-16 15:20:36 -07:00
break;
}
if (i == DEBUG_MAX_VIEWS) {
pr_err("Registering view %s/%s would exceed the maximum "
"number of views %i\n", id->name, view->name, i);
2005-04-16 15:20:36 -07:00
rc = -1;
2005-06-25 14:55:33 -07:00
} else {
2005-04-16 15:20:36 -07:00
id->views[i] = view;
2005-06-25 14:55:33 -07:00
id->debugfs_entries[i] = pde;
2005-04-16 15:20:36 -07:00
}
spin_unlock_irqrestore(&id->lock, flags);
if (rc)
debugfs_remove(pde);
2005-06-25 14:55:33 -07:00
out:
2005-04-16 15:20:36 -07:00
return rc;
}
EXPORT_SYMBOL(debug_register_view);
2005-04-16 15:20:36 -07:00
/*
* debug_unregister_view:
*/
2017-10-13 09:06:29 +02:00
int debug_unregister_view(debug_info_t *id, struct debug_view *view)
2005-04-16 15:20:36 -07:00
{
struct dentry *dentry = NULL;
2005-04-16 15:20:36 -07:00
unsigned long flags;
int i, rc = 0;
2005-04-16 15:20:36 -07:00
if (!id)
goto out;
spin_lock_irqsave(&id->lock, flags);
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (id->views[i] == view)
break;
}
2017-10-13 09:06:29 +02:00
if (i == DEBUG_MAX_VIEWS) {
2005-04-16 15:20:36 -07:00
rc = -1;
2017-10-13 09:06:29 +02:00
} else {
dentry = id->debugfs_entries[i];
2005-04-16 15:20:36 -07:00
id->views[i] = NULL;
id->debugfs_entries[i] = NULL;
2005-04-16 15:20:36 -07:00
}
spin_unlock_irqrestore(&id->lock, flags);
debugfs_remove(dentry);
2005-06-25 14:55:33 -07:00
out:
return rc;
}
EXPORT_SYMBOL(debug_unregister_view);
2005-06-25 14:55:33 -07:00
2017-10-13 09:06:29 +02:00
static inline char *debug_get_user_string(const char __user *user_buf,
size_t user_len)
2005-06-25 14:55:33 -07:00
{
2017-10-13 09:06:29 +02:00
char *buffer;
2005-06-25 14:55:33 -07:00
buffer = kmalloc(user_len + 1, GFP_KERNEL);
if (!buffer)
return ERR_PTR(-ENOMEM);
if (copy_from_user(buffer, user_buf, user_len) != 0) {
kfree(buffer);
return ERR_PTR(-EFAULT);
}
/* got the string, now strip linefeed. */
if (buffer[user_len - 1] == '\n')
buffer[user_len - 1] = 0;
else
buffer[user_len] = 0;
2017-10-13 09:06:29 +02:00
return buffer;
2005-06-25 14:55:33 -07:00
}
2017-10-13 09:06:29 +02:00
static inline int debug_get_uint(char *buf)
2005-06-25 14:55:33 -07:00
{
int rc;
buf = skip_spaces(buf);
2005-06-25 14:55:33 -07:00
rc = simple_strtoul(buf, &buf, 10);
2017-10-13 09:06:29 +02:00
if (*buf)
2005-06-25 14:55:33 -07:00
rc = -EINVAL;
2005-04-16 15:20:36 -07:00
return rc;
}
/*
* functions for debug-views
***********************************
*/
/*
* prints out actual debug level
*/
2017-10-13 09:06:29 +02:00
static int debug_prolog_pages_fn(debug_info_t *id, struct debug_view *view,
char *out_buf)
2005-06-25 14:55:33 -07:00
{
return sprintf(out_buf, "%i\n", id->pages_per_area);
}
/*
* reads new size (number of pages per debug area)
*/
2017-10-13 09:06:29 +02:00
static int debug_input_pages_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_len, loff_t *offset)
2005-06-25 14:55:33 -07:00
{
2017-10-13 09:06:29 +02:00
int rc, new_pages;
2005-06-25 14:55:33 -07:00
char *str;
if (user_len > 0x10000)
2017-10-13 09:06:29 +02:00
user_len = 0x10000;
if (*offset != 0) {
2005-06-25 14:55:33 -07:00
rc = -EPIPE;
goto out;
}
2017-10-13 09:06:29 +02:00
str = debug_get_user_string(user_buf, user_len);
if (IS_ERR(str)) {
2005-06-25 14:55:33 -07:00
rc = PTR_ERR(str);
goto out;
}
new_pages = debug_get_uint(str);
2017-10-13 09:06:29 +02:00
if (new_pages < 0) {
2005-06-25 14:55:33 -07:00
rc = -EINVAL;
goto free_str;
}
2017-10-13 09:06:29 +02:00
rc = debug_set_size(id, id->nr_areas, new_pages);
if (rc != 0) {
2005-06-25 14:55:33 -07:00
rc = -EINVAL;
goto free_str;
}
rc = user_len;
free_str:
kfree(str);
out:
*offset += user_len;
return rc; /* number of input characters */
}
/*
* prints out actual debug level
*/
2017-10-13 09:06:29 +02:00
static int debug_prolog_level_fn(debug_info_t *id, struct debug_view *view,
char *out_buf)
2005-04-16 15:20:36 -07:00
{
int rc = 0;
2017-10-13 09:06:29 +02:00
if (id->level == DEBUG_OFF_LEVEL)
rc = sprintf(out_buf, "-\n");
else
2005-06-25 14:55:33 -07:00
rc = sprintf(out_buf, "%i\n", id->level);
2005-04-16 15:20:36 -07:00
return rc;
}
/*
* reads new debug level
*/
2017-10-13 09:06:29 +02:00
static int debug_input_level_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_len, loff_t *offset)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
int rc, new_level;
2005-06-25 14:55:33 -07:00
char *str;
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
if (user_len > 0x10000)
2017-10-13 09:06:29 +02:00
user_len = 0x10000;
if (*offset != 0) {
2005-06-25 14:55:33 -07:00
rc = -EPIPE;
2005-04-16 15:20:36 -07:00
goto out;
2005-06-25 14:55:33 -07:00
}
2017-10-13 09:06:29 +02:00
str = debug_get_user_string(user_buf, user_len);
if (IS_ERR(str)) {
2005-06-25 14:55:33 -07:00
rc = PTR_ERR(str);
2005-04-16 15:20:36 -07:00
goto out;
}
2017-10-13 09:06:29 +02:00
if (str[0] == '-') {
2005-04-16 15:20:36 -07:00
debug_set_level(id, DEBUG_OFF_LEVEL);
2005-06-25 14:55:33 -07:00
rc = user_len;
goto free_str;
2005-04-16 15:20:36 -07:00
} else {
2005-06-25 14:55:33 -07:00
new_level = debug_get_uint(str);
2005-04-16 15:20:36 -07:00
}
2017-10-13 09:06:29 +02:00
if (new_level < 0) {
2016-03-03 20:49:57 -08:00
pr_warn("%s is not a valid level for a debug feature\n", str);
2005-06-25 14:55:33 -07:00
rc = -EINVAL;
} else {
debug_set_level(id, new_level);
rc = user_len;
}
free_str:
kfree(str);
out:
*offset += user_len;
2005-04-16 15:20:36 -07:00
return rc; /* number of input characters */
}
/*
* flushes debug areas
*/
2017-10-13 09:06:29 +02:00
static void debug_flush(debug_info_t *id, int area)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
unsigned long flags;
int i, j;
if (!id || !id->areas)
return;
spin_lock_irqsave(&id->lock, flags);
if (area == DEBUG_FLUSH_ALL) {
id->active_area = 0;
memset(id->active_entries, 0, id->nr_areas * sizeof(int));
for (i = 0; i < id->nr_areas; i++) {
2005-06-25 14:55:33 -07:00
id->active_pages[i] = 0;
2017-10-13 09:06:29 +02:00
for (j = 0; j < id->pages_per_area; j++)
memset(id->areas[i][j], 0, PAGE_SIZE);
2005-06-25 14:55:33 -07:00
}
2017-10-13 09:06:29 +02:00
} else if (area >= 0 && area < id->nr_areas) {
id->active_entries[area] = 0;
2005-06-25 14:55:33 -07:00
id->active_pages[area] = 0;
2017-10-13 09:06:29 +02:00
for (i = 0; i < id->pages_per_area; i++)
memset(id->areas[area][i], 0, PAGE_SIZE);
}
spin_unlock_irqrestore(&id->lock, flags);
2005-04-16 15:20:36 -07:00
}
/*
2017-10-13 09:06:29 +02:00
* view function: flushes debug areas
2005-04-16 15:20:36 -07:00
*/
2017-10-13 09:06:29 +02:00
static int debug_input_flush_fn(debug_info_t *id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_len, loff_t *offset)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
char input_buf[1];
int rc = user_len;
2005-06-25 14:55:33 -07:00
if (user_len > 0x10000)
2017-10-13 09:06:29 +02:00
user_len = 0x10000;
if (*offset != 0) {
2005-06-25 14:55:33 -07:00
rc = -EPIPE;
2017-10-13 09:06:29 +02:00
goto out;
}
if (copy_from_user(input_buf, user_buf, 1)) {
rc = -EFAULT;
goto out;
}
if (input_buf[0] == '-') {
debug_flush(id, DEBUG_FLUSH_ALL);
goto out;
}
if (isdigit(input_buf[0])) {
int area = ((int) input_buf[0] - (int) '0');
debug_flush(id, area);
goto out;
2005-06-25 14:55:33 -07:00
}
2005-04-16 15:20:36 -07:00
pr_info("Flushing debug data failed because %c is not a valid "
"area\n", input_buf[0]);
2005-04-16 15:20:36 -07:00
2005-06-25 14:55:33 -07:00
out:
2017-10-13 09:06:29 +02:00
*offset += user_len;
return rc; /* number of input characters */
2005-04-16 15:20:36 -07:00
}
/*
* prints debug header in raw format
*/
2017-10-13 09:06:29 +02:00
static int debug_raw_header_fn(debug_info_t *id, struct debug_view *view,
int area, debug_entry_t *entry, char *out_buf)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
int rc;
2005-04-16 15:20:36 -07:00
rc = sizeof(debug_entry_t);
2017-10-13 09:06:29 +02:00
memcpy(out_buf, entry, sizeof(debug_entry_t));
return rc;
2005-04-16 15:20:36 -07:00
}
/*
* prints debug data in raw format
*/
2017-10-13 09:06:29 +02:00
static int debug_raw_format_fn(debug_info_t *id, struct debug_view *view,
2005-04-16 15:20:36 -07:00
char *out_buf, const char *in_buf)
{
int rc;
rc = id->buf_size;
memcpy(out_buf, in_buf, id->buf_size);
return rc;
}
/*
* prints debug data in hex/ascii format
*/
2017-10-13 09:06:29 +02:00
static int debug_hex_ascii_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, const char *in_buf)
2005-04-16 15:20:36 -07:00
{
int i, rc = 0;
2017-10-13 09:06:29 +02:00
for (i = 0; i < id->buf_size; i++)
rc += sprintf(out_buf + rc, "%02x ", ((unsigned char *) in_buf)[i]);
2005-04-16 15:20:36 -07:00
rc += sprintf(out_buf + rc, "| ");
for (i = 0; i < id->buf_size; i++) {
unsigned char c = in_buf[i];
2017-10-13 09:06:29 +02:00
2012-03-11 11:59:32 -04:00
if (isascii(c) && isprint(c))
2005-04-16 15:20:36 -07:00
rc += sprintf(out_buf + rc, "%c", c);
2012-03-11 11:59:32 -04:00
else
rc += sprintf(out_buf + rc, ".");
2005-04-16 15:20:36 -07:00
}
rc += sprintf(out_buf + rc, "\n");
return rc;
}
/*
* prints header for debug entry
*/
2017-10-13 09:06:29 +02:00
int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
int area, debug_entry_t *entry, char *out_buf)
2005-04-16 15:20:36 -07:00
{
unsigned long base, sec, usec;
2005-04-16 15:20:36 -07:00
unsigned long caller;
unsigned int level;
2017-10-13 09:06:29 +02:00
char *except_str;
int rc = 0;
2005-04-16 15:20:36 -07:00
level = entry->id.fields.level;
base = (*(unsigned long *) &tod_clock_base[0]) >> 4;
sec = (entry->id.stck >> 12) + base - (TOD_UNIX_EPOCH >> 12);
usec = do_div(sec, USEC_PER_SEC);
2005-04-16 15:20:36 -07:00
if (entry->id.fields.exception)
except_str = "*";
else
except_str = "-";
2016-01-18 13:12:19 +01:00
caller = (unsigned long) entry->caller;
2017-11-23 19:26:20 +01:00
rc += sprintf(out_buf, "%02i %011ld:%06lu %1u %1s %02i %pK ",
area, sec, usec, level, except_str,
entry->id.fields.cpuid, (void *)caller);
2005-04-16 15:20:36 -07:00
return rc;
}
EXPORT_SYMBOL(debug_dflt_header_fn);
2005-04-16 15:20:36 -07:00
/*
* prints debug data sprintf-formated:
* debug_sprinf_event/exception calls must be used together with this view
*/
#define DEBUG_SPRINTF_MAX_ARGS 10
2017-10-13 09:06:29 +02:00
static int debug_sprintf_format_fn(debug_info_t *id, struct debug_view *view,
char *out_buf, debug_sprintf_entry_t *curr_event)
2005-04-16 15:20:36 -07:00
{
2017-10-13 09:06:29 +02:00
int num_longs, num_used_args = 0, i, rc = 0;
2005-04-16 15:20:36 -07:00
int index[DEBUG_SPRINTF_MAX_ARGS];
/* count of longs fit into one entry */
2017-10-13 09:06:29 +02:00
num_longs = id->buf_size / sizeof(long);
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
if (num_longs < 1)
2005-04-16 15:20:36 -07:00
goto out; /* bufsize of entry too small */
2017-10-13 09:06:29 +02:00
if (num_longs == 1) {
2005-04-16 15:20:36 -07:00
/* no args, we use only the string */
strcpy(out_buf, curr_event->string);
rc = strlen(curr_event->string);
goto out;
}
/* number of arguments used for sprintf (without the format string) */
2017-10-13 09:06:29 +02:00
num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
memset(index, 0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
2005-04-16 15:20:36 -07:00
2017-10-13 09:06:29 +02:00
for (i = 0; i < num_used_args; i++)
2005-04-16 15:20:36 -07:00
index[i] = i;
2017-10-13 09:06:29 +02:00
rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
curr_event->args[index[1]], curr_event->args[index[2]],
curr_event->args[index[3]], curr_event->args[index[4]],
curr_event->args[index[5]], curr_event->args[index[6]],
curr_event->args[index[7]], curr_event->args[index[8]],
curr_event->args[index[9]]);
2005-04-16 15:20:36 -07:00
out:
return rc;
}
/*
* debug_init:
* - is called exactly once to initialize the debug feature
2005-04-16 15:20:36 -07:00
*/
static int __init debug_init(void)
2005-04-16 15:20:36 -07:00
{
s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table);
mutex_lock(&debug_mutex);
debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT, NULL);
initialized = 1;
mutex_unlock(&debug_mutex);
return 0;
2005-04-16 15:20:36 -07:00
}
2005-06-25 14:55:33 -07:00
postcore_initcall(debug_init);