mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
Merge commit 'v2.6.31-rc6' into core/rcu
Merge reason: the branch was on pre-rc1 .30, update to latest. Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
commit
fa08661af8
2538 changed files with 70259 additions and 36388 deletions
|
|
@ -69,7 +69,7 @@ obj-$(CONFIG_IKCONFIG) += configs.o
|
|||
obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o
|
||||
obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
|
||||
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
|
||||
obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
|
||||
obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o
|
||||
obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
|
||||
obj-$(CONFIG_GCOV_KERNEL) += gcov/
|
||||
obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
|
||||
|
|
@ -95,6 +95,7 @@ obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o
|
|||
obj-$(CONFIG_FUNCTION_TRACER) += trace/
|
||||
obj-$(CONFIG_TRACING) += trace/
|
||||
obj-$(CONFIG_X86_DS) += trace/
|
||||
obj-$(CONFIG_RING_BUFFER) += trace/
|
||||
obj-$(CONFIG_SMP) += sched_cpupri.o
|
||||
obj-$(CONFIG_SLOW_WORK) += slow-work.o
|
||||
obj-$(CONFIG_PERF_COUNTERS) += perf_counter.o
|
||||
|
|
|
|||
|
|
@ -215,6 +215,7 @@ static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file,
|
|||
static int acct_on(char *name)
|
||||
{
|
||||
struct file *file;
|
||||
struct vfsmount *mnt;
|
||||
int error;
|
||||
struct pid_namespace *ns;
|
||||
struct bsd_acct_struct *acct = NULL;
|
||||
|
|
@ -256,11 +257,12 @@ static int acct_on(char *name)
|
|||
acct = NULL;
|
||||
}
|
||||
|
||||
mnt_pin(file->f_path.mnt);
|
||||
mnt = file->f_path.mnt;
|
||||
mnt_pin(mnt);
|
||||
acct_file_reopen(ns->bacct, file, ns);
|
||||
spin_unlock(&acct_lock);
|
||||
|
||||
mntput(file->f_path.mnt); /* it's pinned, now give up active reference */
|
||||
mntput(mnt); /* it's pinned, now give up active reference */
|
||||
kfree(acct);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
146
kernel/audit.c
146
kernel/audit.c
|
|
@ -115,9 +115,6 @@ static atomic_t audit_lost = ATOMIC_INIT(0);
|
|||
/* The netlink socket. */
|
||||
static struct sock *audit_sock;
|
||||
|
||||
/* Inotify handle. */
|
||||
struct inotify_handle *audit_ih;
|
||||
|
||||
/* Hash for inode-based rules */
|
||||
struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];
|
||||
|
||||
|
|
@ -136,7 +133,7 @@ static DECLARE_WAIT_QUEUE_HEAD(kauditd_wait);
|
|||
static DECLARE_WAIT_QUEUE_HEAD(audit_backlog_wait);
|
||||
|
||||
/* Serialize requests from userspace. */
|
||||
static DEFINE_MUTEX(audit_cmd_mutex);
|
||||
DEFINE_MUTEX(audit_cmd_mutex);
|
||||
|
||||
/* AUDIT_BUFSIZ is the size of the temporary buffer used for formatting
|
||||
* audit records. Since printk uses a 1024 byte buffer, this buffer
|
||||
|
|
@ -375,6 +372,25 @@ static void audit_hold_skb(struct sk_buff *skb)
|
|||
kfree_skb(skb);
|
||||
}
|
||||
|
||||
/*
|
||||
* For one reason or another this nlh isn't getting delivered to the userspace
|
||||
* audit daemon, just send it to printk.
|
||||
*/
|
||||
static void audit_printk_skb(struct sk_buff *skb)
|
||||
{
|
||||
struct nlmsghdr *nlh = nlmsg_hdr(skb);
|
||||
char *data = NLMSG_DATA(nlh);
|
||||
|
||||
if (nlh->nlmsg_type != AUDIT_EOE) {
|
||||
if (printk_ratelimit())
|
||||
printk(KERN_NOTICE "type=%d %s\n", nlh->nlmsg_type, data);
|
||||
else
|
||||
audit_log_lost("printk limit exceeded\n");
|
||||
}
|
||||
|
||||
audit_hold_skb(skb);
|
||||
}
|
||||
|
||||
static void kauditd_send_skb(struct sk_buff *skb)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -427,14 +443,8 @@ static int kauditd_thread(void *dummy)
|
|||
if (skb) {
|
||||
if (audit_pid)
|
||||
kauditd_send_skb(skb);
|
||||
else {
|
||||
if (printk_ratelimit())
|
||||
printk(KERN_NOTICE "%s\n", skb->data + NLMSG_SPACE(0));
|
||||
else
|
||||
audit_log_lost("printk limit exceeded\n");
|
||||
|
||||
audit_hold_skb(skb);
|
||||
}
|
||||
else
|
||||
audit_printk_skb(skb);
|
||||
} else {
|
||||
DECLARE_WAITQUEUE(wait, current);
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
|
|
@ -495,42 +505,25 @@ int audit_send_list(void *_dest)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AUDIT_TREE
|
||||
static int prune_tree_thread(void *unused)
|
||||
{
|
||||
mutex_lock(&audit_cmd_mutex);
|
||||
audit_prune_trees();
|
||||
mutex_unlock(&audit_cmd_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void audit_schedule_prune(void)
|
||||
{
|
||||
kthread_run(prune_tree_thread, NULL, "audit_prune_tree");
|
||||
}
|
||||
#endif
|
||||
|
||||
struct sk_buff *audit_make_reply(int pid, int seq, int type, int done,
|
||||
int multi, void *payload, int size)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
struct nlmsghdr *nlh;
|
||||
int len = NLMSG_SPACE(size);
|
||||
void *data;
|
||||
int flags = multi ? NLM_F_MULTI : 0;
|
||||
int t = done ? NLMSG_DONE : type;
|
||||
|
||||
skb = alloc_skb(len, GFP_KERNEL);
|
||||
skb = nlmsg_new(size, GFP_KERNEL);
|
||||
if (!skb)
|
||||
return NULL;
|
||||
|
||||
nlh = NLMSG_PUT(skb, pid, seq, t, size);
|
||||
nlh->nlmsg_flags = flags;
|
||||
data = NLMSG_DATA(nlh);
|
||||
nlh = NLMSG_NEW(skb, pid, seq, t, size, flags);
|
||||
data = NLMSG_DATA(nlh);
|
||||
memcpy(data, payload, size);
|
||||
return skb;
|
||||
|
||||
nlmsg_failure: /* Used by NLMSG_PUT */
|
||||
nlmsg_failure: /* Used by NLMSG_NEW */
|
||||
if (skb)
|
||||
kfree_skb(skb);
|
||||
return NULL;
|
||||
|
|
@ -926,28 +919,29 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
|||
}
|
||||
|
||||
/*
|
||||
* Get message from skb (based on rtnetlink_rcv_skb). Each message is
|
||||
* processed by audit_receive_msg. Malformed skbs with wrong length are
|
||||
* discarded silently.
|
||||
* Get message from skb. Each message is processed by audit_receive_msg.
|
||||
* Malformed skbs with wrong length are discarded silently.
|
||||
*/
|
||||
static void audit_receive_skb(struct sk_buff *skb)
|
||||
{
|
||||
int err;
|
||||
struct nlmsghdr *nlh;
|
||||
u32 rlen;
|
||||
struct nlmsghdr *nlh;
|
||||
/*
|
||||
* len MUST be signed for NLMSG_NEXT to be able to dec it below 0
|
||||
* if the nlmsg_len was not aligned
|
||||
*/
|
||||
int len;
|
||||
int err;
|
||||
|
||||
while (skb->len >= NLMSG_SPACE(0)) {
|
||||
nlh = nlmsg_hdr(skb);
|
||||
if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
|
||||
return;
|
||||
rlen = NLMSG_ALIGN(nlh->nlmsg_len);
|
||||
if (rlen > skb->len)
|
||||
rlen = skb->len;
|
||||
if ((err = audit_receive_msg(skb, nlh))) {
|
||||
nlh = nlmsg_hdr(skb);
|
||||
len = skb->len;
|
||||
|
||||
while (NLMSG_OK(nlh, len)) {
|
||||
err = audit_receive_msg(skb, nlh);
|
||||
/* if err or if this message says it wants a response */
|
||||
if (err || (nlh->nlmsg_flags & NLM_F_ACK))
|
||||
netlink_ack(skb, nlh, err);
|
||||
} else if (nlh->nlmsg_flags & NLM_F_ACK)
|
||||
netlink_ack(skb, nlh, 0);
|
||||
skb_pull(skb, rlen);
|
||||
|
||||
nlh = NLMSG_NEXT(nlh, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -959,13 +953,6 @@ static void audit_receive(struct sk_buff *skb)
|
|||
mutex_unlock(&audit_cmd_mutex);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AUDITSYSCALL
|
||||
static const struct inotify_operations audit_inotify_ops = {
|
||||
.handle_event = audit_handle_ievent,
|
||||
.destroy_watch = audit_free_parent,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Initialize audit support at boot time. */
|
||||
static int __init audit_init(void)
|
||||
{
|
||||
|
|
@ -991,12 +978,6 @@ static int __init audit_init(void)
|
|||
|
||||
audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized");
|
||||
|
||||
#ifdef CONFIG_AUDITSYSCALL
|
||||
audit_ih = inotify_init(&audit_inotify_ops);
|
||||
if (IS_ERR(audit_ih))
|
||||
audit_panic("cannot initialize inotify handle");
|
||||
#endif
|
||||
|
||||
for (i = 0; i < AUDIT_INODE_BUCKETS; i++)
|
||||
INIT_LIST_HEAD(&audit_inode_hash[i]);
|
||||
|
||||
|
|
@ -1070,18 +1051,20 @@ static struct audit_buffer * audit_buffer_alloc(struct audit_context *ctx,
|
|||
goto err;
|
||||
}
|
||||
|
||||
ab->skb = alloc_skb(AUDIT_BUFSIZ, gfp_mask);
|
||||
if (!ab->skb)
|
||||
goto err;
|
||||
|
||||
ab->ctx = ctx;
|
||||
ab->gfp_mask = gfp_mask;
|
||||
nlh = (struct nlmsghdr *)skb_put(ab->skb, NLMSG_SPACE(0));
|
||||
nlh->nlmsg_type = type;
|
||||
nlh->nlmsg_flags = 0;
|
||||
nlh->nlmsg_pid = 0;
|
||||
nlh->nlmsg_seq = 0;
|
||||
|
||||
ab->skb = nlmsg_new(AUDIT_BUFSIZ, gfp_mask);
|
||||
if (!ab->skb)
|
||||
goto nlmsg_failure;
|
||||
|
||||
nlh = NLMSG_NEW(ab->skb, 0, 0, type, 0, 0);
|
||||
|
||||
return ab;
|
||||
|
||||
nlmsg_failure: /* Used by NLMSG_NEW */
|
||||
kfree_skb(ab->skb);
|
||||
ab->skb = NULL;
|
||||
err:
|
||||
audit_buffer_free(ab);
|
||||
return NULL;
|
||||
|
|
@ -1452,6 +1435,15 @@ void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
|
|||
kfree(pathname);
|
||||
}
|
||||
|
||||
void audit_log_key(struct audit_buffer *ab, char *key)
|
||||
{
|
||||
audit_log_format(ab, " key=");
|
||||
if (key)
|
||||
audit_log_untrustedstring(ab, key);
|
||||
else
|
||||
audit_log_format(ab, "(null)");
|
||||
}
|
||||
|
||||
/**
|
||||
* audit_log_end - end one audit record
|
||||
* @ab: the audit_buffer
|
||||
|
|
@ -1475,15 +1467,7 @@ void audit_log_end(struct audit_buffer *ab)
|
|||
skb_queue_tail(&audit_skb_queue, ab->skb);
|
||||
wake_up_interruptible(&kauditd_wait);
|
||||
} else {
|
||||
if (nlh->nlmsg_type != AUDIT_EOE) {
|
||||
if (printk_ratelimit()) {
|
||||
printk(KERN_NOTICE "type=%d %s\n",
|
||||
nlh->nlmsg_type,
|
||||
ab->skb->data + NLMSG_SPACE(0));
|
||||
} else
|
||||
audit_log_lost("printk limit exceeded\n");
|
||||
}
|
||||
audit_hold_skb(ab->skb);
|
||||
audit_printk_skb(ab->skb);
|
||||
}
|
||||
ab->skb = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,18 +53,7 @@ enum audit_state {
|
|||
};
|
||||
|
||||
/* Rule lists */
|
||||
struct audit_parent;
|
||||
|
||||
struct audit_watch {
|
||||
atomic_t count; /* reference count */
|
||||
char *path; /* insertion path */
|
||||
dev_t dev; /* associated superblock device */
|
||||
unsigned long ino; /* associated inode number */
|
||||
struct audit_parent *parent; /* associated parent */
|
||||
struct list_head wlist; /* entry in parent->watches list */
|
||||
struct list_head rules; /* associated rules */
|
||||
};
|
||||
|
||||
struct audit_watch;
|
||||
struct audit_tree;
|
||||
struct audit_chunk;
|
||||
|
||||
|
|
@ -108,19 +97,28 @@ struct audit_netlink_list {
|
|||
|
||||
int audit_send_list(void *);
|
||||
|
||||
struct inotify_watch;
|
||||
/* Inotify handle */
|
||||
extern struct inotify_handle *audit_ih;
|
||||
|
||||
extern void audit_free_parent(struct inotify_watch *);
|
||||
extern void audit_handle_ievent(struct inotify_watch *, u32, u32, u32,
|
||||
const char *, struct inode *);
|
||||
extern int selinux_audit_rule_update(void);
|
||||
|
||||
extern struct mutex audit_filter_mutex;
|
||||
extern void audit_free_rule_rcu(struct rcu_head *);
|
||||
extern struct list_head audit_filter_list[];
|
||||
|
||||
/* audit watch functions */
|
||||
extern unsigned long audit_watch_inode(struct audit_watch *watch);
|
||||
extern dev_t audit_watch_dev(struct audit_watch *watch);
|
||||
extern void audit_put_watch(struct audit_watch *watch);
|
||||
extern void audit_get_watch(struct audit_watch *watch);
|
||||
extern int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op);
|
||||
extern int audit_add_watch(struct audit_krule *krule);
|
||||
extern void audit_remove_watch(struct audit_watch *watch);
|
||||
extern void audit_remove_watch_rule(struct audit_krule *krule, struct list_head *list);
|
||||
extern void audit_inotify_unregister(struct list_head *in_list);
|
||||
extern char *audit_watch_path(struct audit_watch *watch);
|
||||
extern struct list_head *audit_watch_rules(struct audit_watch *watch);
|
||||
|
||||
extern struct audit_entry *audit_dupe_rule(struct audit_krule *old,
|
||||
struct audit_watch *watch);
|
||||
|
||||
#ifdef CONFIG_AUDIT_TREE
|
||||
extern struct audit_chunk *audit_tree_lookup(const struct inode *);
|
||||
extern void audit_put_chunk(struct audit_chunk *);
|
||||
|
|
@ -130,10 +128,9 @@ extern int audit_add_tree_rule(struct audit_krule *);
|
|||
extern int audit_remove_tree_rule(struct audit_krule *);
|
||||
extern void audit_trim_trees(void);
|
||||
extern int audit_tag_tree(char *old, char *new);
|
||||
extern void audit_schedule_prune(void);
|
||||
extern void audit_prune_trees(void);
|
||||
extern const char *audit_tree_path(struct audit_tree *);
|
||||
extern void audit_put_tree(struct audit_tree *);
|
||||
extern void audit_kill_trees(struct list_head *);
|
||||
#else
|
||||
#define audit_remove_tree_rule(rule) BUG()
|
||||
#define audit_add_tree_rule(rule) -EINVAL
|
||||
|
|
@ -142,6 +139,7 @@ extern void audit_put_tree(struct audit_tree *);
|
|||
#define audit_put_tree(tree) (void)0
|
||||
#define audit_tag_tree(old, new) -EINVAL
|
||||
#define audit_tree_path(rule) "" /* never called */
|
||||
#define audit_kill_trees(list) BUG()
|
||||
#endif
|
||||
|
||||
extern char *audit_unpack_string(void **, size_t *, size_t);
|
||||
|
|
@ -160,7 +158,10 @@ static inline int audit_signal_info(int sig, struct task_struct *t)
|
|||
return 0;
|
||||
}
|
||||
extern void audit_filter_inodes(struct task_struct *, struct audit_context *);
|
||||
extern struct list_head *audit_killed_trees(void);
|
||||
#else
|
||||
#define audit_signal_info(s,t) AUDIT_DISABLED
|
||||
#define audit_filter_inodes(t,c) AUDIT_DISABLED
|
||||
#endif
|
||||
|
||||
extern struct mutex audit_cmd_mutex;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <linux/inotify.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/mount.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
struct audit_tree;
|
||||
struct audit_chunk;
|
||||
|
|
@ -441,13 +442,11 @@ static void kill_rules(struct audit_tree *tree)
|
|||
if (rule->tree) {
|
||||
/* not a half-baked one */
|
||||
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
|
||||
audit_log_format(ab, "op=remove rule dir=");
|
||||
audit_log_format(ab, "op=");
|
||||
audit_log_string(ab, "remove rule");
|
||||
audit_log_format(ab, " dir=");
|
||||
audit_log_untrustedstring(ab, rule->tree->pathname);
|
||||
if (rule->filterkey) {
|
||||
audit_log_format(ab, " key=");
|
||||
audit_log_untrustedstring(ab, rule->filterkey);
|
||||
} else
|
||||
audit_log_format(ab, " key=(null)");
|
||||
audit_log_key(ab, rule->filterkey);
|
||||
audit_log_format(ab, " list=%d res=1", rule->listnr);
|
||||
audit_log_end(ab);
|
||||
rule->tree = NULL;
|
||||
|
|
@ -519,6 +518,8 @@ static void trim_marked(struct audit_tree *tree)
|
|||
}
|
||||
}
|
||||
|
||||
static void audit_schedule_prune(void);
|
||||
|
||||
/* called with audit_filter_mutex */
|
||||
int audit_remove_tree_rule(struct audit_krule *rule)
|
||||
{
|
||||
|
|
@ -824,10 +825,11 @@ int audit_tag_tree(char *old, char *new)
|
|||
|
||||
/*
|
||||
* That gets run when evict_chunk() ends up needing to kill audit_tree.
|
||||
* Runs from a separate thread, with audit_cmd_mutex held.
|
||||
* Runs from a separate thread.
|
||||
*/
|
||||
void audit_prune_trees(void)
|
||||
static int prune_tree_thread(void *unused)
|
||||
{
|
||||
mutex_lock(&audit_cmd_mutex);
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
|
||||
while (!list_empty(&prune_list)) {
|
||||
|
|
@ -844,6 +846,40 @@ void audit_prune_trees(void)
|
|||
}
|
||||
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
mutex_unlock(&audit_cmd_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void audit_schedule_prune(void)
|
||||
{
|
||||
kthread_run(prune_tree_thread, NULL, "audit_prune_tree");
|
||||
}
|
||||
|
||||
/*
|
||||
* ... and that one is done if evict_chunk() decides to delay until the end
|
||||
* of syscall. Runs synchronously.
|
||||
*/
|
||||
void audit_kill_trees(struct list_head *list)
|
||||
{
|
||||
mutex_lock(&audit_cmd_mutex);
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
|
||||
while (!list_empty(list)) {
|
||||
struct audit_tree *victim;
|
||||
|
||||
victim = list_entry(list->next, struct audit_tree, list);
|
||||
kill_rules(victim);
|
||||
list_del_init(&victim->list);
|
||||
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
|
||||
prune_one(victim);
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
}
|
||||
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
mutex_unlock(&audit_cmd_mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -854,6 +890,8 @@ void audit_prune_trees(void)
|
|||
static void evict_chunk(struct audit_chunk *chunk)
|
||||
{
|
||||
struct audit_tree *owner;
|
||||
struct list_head *postponed = audit_killed_trees();
|
||||
int need_prune = 0;
|
||||
int n;
|
||||
|
||||
if (chunk->dead)
|
||||
|
|
@ -869,15 +907,21 @@ static void evict_chunk(struct audit_chunk *chunk)
|
|||
owner->root = NULL;
|
||||
list_del_init(&owner->same_root);
|
||||
spin_unlock(&hash_lock);
|
||||
kill_rules(owner);
|
||||
list_move(&owner->list, &prune_list);
|
||||
audit_schedule_prune();
|
||||
if (!postponed) {
|
||||
kill_rules(owner);
|
||||
list_move(&owner->list, &prune_list);
|
||||
need_prune = 1;
|
||||
} else {
|
||||
list_move(&owner->list, postponed);
|
||||
}
|
||||
spin_lock(&hash_lock);
|
||||
}
|
||||
list_del_rcu(&chunk->hash);
|
||||
for (n = 0; n < chunk->count; n++)
|
||||
list_del_init(&chunk->owners[n].list);
|
||||
spin_unlock(&hash_lock);
|
||||
if (need_prune)
|
||||
audit_schedule_prune();
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
}
|
||||
|
||||
|
|
|
|||
543
kernel/audit_watch.c
Normal file
543
kernel/audit_watch.c
Normal file
|
|
@ -0,0 +1,543 @@
|
|||
/* audit_watch.c -- watching inodes
|
||||
*
|
||||
* Copyright 2003-2009 Red Hat, Inc.
|
||||
* Copyright 2005 Hewlett-Packard Development Company, L.P.
|
||||
* Copyright 2005 IBM Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/audit.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/inotify.h>
|
||||
#include <linux/security.h>
|
||||
#include "audit.h"
|
||||
|
||||
/*
|
||||
* Reference counting:
|
||||
*
|
||||
* audit_parent: lifetime is from audit_init_parent() to receipt of an IN_IGNORED
|
||||
* event. Each audit_watch holds a reference to its associated parent.
|
||||
*
|
||||
* audit_watch: if added to lists, lifetime is from audit_init_watch() to
|
||||
* audit_remove_watch(). Additionally, an audit_watch may exist
|
||||
* temporarily to assist in searching existing filter data. Each
|
||||
* audit_krule holds a reference to its associated watch.
|
||||
*/
|
||||
|
||||
struct audit_watch {
|
||||
atomic_t count; /* reference count */
|
||||
char *path; /* insertion path */
|
||||
dev_t dev; /* associated superblock device */
|
||||
unsigned long ino; /* associated inode number */
|
||||
struct audit_parent *parent; /* associated parent */
|
||||
struct list_head wlist; /* entry in parent->watches list */
|
||||
struct list_head rules; /* associated rules */
|
||||
};
|
||||
|
||||
struct audit_parent {
|
||||
struct list_head ilist; /* entry in inotify registration list */
|
||||
struct list_head watches; /* associated watches */
|
||||
struct inotify_watch wdata; /* inotify watch data */
|
||||
unsigned flags; /* status flags */
|
||||
};
|
||||
|
||||
/* Inotify handle. */
|
||||
struct inotify_handle *audit_ih;
|
||||
|
||||
/*
|
||||
* audit_parent status flags:
|
||||
*
|
||||
* AUDIT_PARENT_INVALID - set anytime rules/watches are auto-removed due to
|
||||
* a filesystem event to ensure we're adding audit watches to a valid parent.
|
||||
* Technically not needed for IN_DELETE_SELF or IN_UNMOUNT events, as we cannot
|
||||
* receive them while we have nameidata, but must be used for IN_MOVE_SELF which
|
||||
* we can receive while holding nameidata.
|
||||
*/
|
||||
#define AUDIT_PARENT_INVALID 0x001
|
||||
|
||||
/* Inotify events we care about. */
|
||||
#define AUDIT_IN_WATCH IN_MOVE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF
|
||||
|
||||
static void audit_free_parent(struct inotify_watch *i_watch)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
WARN_ON(!list_empty(&parent->watches));
|
||||
kfree(parent);
|
||||
}
|
||||
|
||||
void audit_get_watch(struct audit_watch *watch)
|
||||
{
|
||||
atomic_inc(&watch->count);
|
||||
}
|
||||
|
||||
void audit_put_watch(struct audit_watch *watch)
|
||||
{
|
||||
if (atomic_dec_and_test(&watch->count)) {
|
||||
WARN_ON(watch->parent);
|
||||
WARN_ON(!list_empty(&watch->rules));
|
||||
kfree(watch->path);
|
||||
kfree(watch);
|
||||
}
|
||||
}
|
||||
|
||||
void audit_remove_watch(struct audit_watch *watch)
|
||||
{
|
||||
list_del(&watch->wlist);
|
||||
put_inotify_watch(&watch->parent->wdata);
|
||||
watch->parent = NULL;
|
||||
audit_put_watch(watch); /* match initial get */
|
||||
}
|
||||
|
||||
char *audit_watch_path(struct audit_watch *watch)
|
||||
{
|
||||
return watch->path;
|
||||
}
|
||||
|
||||
struct list_head *audit_watch_rules(struct audit_watch *watch)
|
||||
{
|
||||
return &watch->rules;
|
||||
}
|
||||
|
||||
unsigned long audit_watch_inode(struct audit_watch *watch)
|
||||
{
|
||||
return watch->ino;
|
||||
}
|
||||
|
||||
dev_t audit_watch_dev(struct audit_watch *watch)
|
||||
{
|
||||
return watch->dev;
|
||||
}
|
||||
|
||||
/* Initialize a parent watch entry. */
|
||||
static struct audit_parent *audit_init_parent(struct nameidata *ndp)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
s32 wd;
|
||||
|
||||
parent = kzalloc(sizeof(*parent), GFP_KERNEL);
|
||||
if (unlikely(!parent))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
INIT_LIST_HEAD(&parent->watches);
|
||||
parent->flags = 0;
|
||||
|
||||
inotify_init_watch(&parent->wdata);
|
||||
/* grab a ref so inotify watch hangs around until we take audit_filter_mutex */
|
||||
get_inotify_watch(&parent->wdata);
|
||||
wd = inotify_add_watch(audit_ih, &parent->wdata,
|
||||
ndp->path.dentry->d_inode, AUDIT_IN_WATCH);
|
||||
if (wd < 0) {
|
||||
audit_free_parent(&parent->wdata);
|
||||
return ERR_PTR(wd);
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* Initialize a watch entry. */
|
||||
static struct audit_watch *audit_init_watch(char *path)
|
||||
{
|
||||
struct audit_watch *watch;
|
||||
|
||||
watch = kzalloc(sizeof(*watch), GFP_KERNEL);
|
||||
if (unlikely(!watch))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
INIT_LIST_HEAD(&watch->rules);
|
||||
atomic_set(&watch->count, 1);
|
||||
watch->path = path;
|
||||
watch->dev = (dev_t)-1;
|
||||
watch->ino = (unsigned long)-1;
|
||||
|
||||
return watch;
|
||||
}
|
||||
|
||||
/* Translate a watch string to kernel respresentation. */
|
||||
int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op)
|
||||
{
|
||||
struct audit_watch *watch;
|
||||
|
||||
if (!audit_ih)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (path[0] != '/' || path[len-1] == '/' ||
|
||||
krule->listnr != AUDIT_FILTER_EXIT ||
|
||||
op != Audit_equal ||
|
||||
krule->inode_f || krule->watch || krule->tree)
|
||||
return -EINVAL;
|
||||
|
||||
watch = audit_init_watch(path);
|
||||
if (IS_ERR(watch))
|
||||
return PTR_ERR(watch);
|
||||
|
||||
audit_get_watch(watch);
|
||||
krule->watch = watch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Duplicate the given audit watch. The new watch's rules list is initialized
|
||||
* to an empty list and wlist is undefined. */
|
||||
static struct audit_watch *audit_dupe_watch(struct audit_watch *old)
|
||||
{
|
||||
char *path;
|
||||
struct audit_watch *new;
|
||||
|
||||
path = kstrdup(old->path, GFP_KERNEL);
|
||||
if (unlikely(!path))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
new = audit_init_watch(path);
|
||||
if (IS_ERR(new)) {
|
||||
kfree(path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
new->dev = old->dev;
|
||||
new->ino = old->ino;
|
||||
get_inotify_watch(&old->parent->wdata);
|
||||
new->parent = old->parent;
|
||||
|
||||
out:
|
||||
return new;
|
||||
}
|
||||
|
||||
static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watch *w, char *op)
|
||||
{
|
||||
if (audit_enabled) {
|
||||
struct audit_buffer *ab;
|
||||
ab = audit_log_start(NULL, GFP_NOFS, AUDIT_CONFIG_CHANGE);
|
||||
audit_log_format(ab, "auid=%u ses=%u op=",
|
||||
audit_get_loginuid(current),
|
||||
audit_get_sessionid(current));
|
||||
audit_log_string(ab, op);
|
||||
audit_log_format(ab, " path=");
|
||||
audit_log_untrustedstring(ab, w->path);
|
||||
audit_log_key(ab, r->filterkey);
|
||||
audit_log_format(ab, " list=%d res=1", r->listnr);
|
||||
audit_log_end(ab);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update inode info in audit rules based on filesystem event. */
|
||||
static void audit_update_watch(struct audit_parent *parent,
|
||||
const char *dname, dev_t dev,
|
||||
unsigned long ino, unsigned invalidating)
|
||||
{
|
||||
struct audit_watch *owatch, *nwatch, *nextw;
|
||||
struct audit_krule *r, *nextr;
|
||||
struct audit_entry *oentry, *nentry;
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
list_for_each_entry_safe(owatch, nextw, &parent->watches, wlist) {
|
||||
if (audit_compare_dname_path(dname, owatch->path, NULL))
|
||||
continue;
|
||||
|
||||
/* If the update involves invalidating rules, do the inode-based
|
||||
* filtering now, so we don't omit records. */
|
||||
if (invalidating && current->audit_context)
|
||||
audit_filter_inodes(current, current->audit_context);
|
||||
|
||||
nwatch = audit_dupe_watch(owatch);
|
||||
if (IS_ERR(nwatch)) {
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
audit_panic("error updating watch, skipping");
|
||||
return;
|
||||
}
|
||||
nwatch->dev = dev;
|
||||
nwatch->ino = ino;
|
||||
|
||||
list_for_each_entry_safe(r, nextr, &owatch->rules, rlist) {
|
||||
|
||||
oentry = container_of(r, struct audit_entry, rule);
|
||||
list_del(&oentry->rule.rlist);
|
||||
list_del_rcu(&oentry->list);
|
||||
|
||||
nentry = audit_dupe_rule(&oentry->rule, nwatch);
|
||||
if (IS_ERR(nentry)) {
|
||||
list_del(&oentry->rule.list);
|
||||
audit_panic("error updating watch, removing");
|
||||
} else {
|
||||
int h = audit_hash_ino((u32)ino);
|
||||
list_add(&nentry->rule.rlist, &nwatch->rules);
|
||||
list_add_rcu(&nentry->list, &audit_inode_hash[h]);
|
||||
list_replace(&oentry->rule.list,
|
||||
&nentry->rule.list);
|
||||
}
|
||||
|
||||
audit_watch_log_rule_change(r, owatch, "updated rules");
|
||||
|
||||
call_rcu(&oentry->rcu, audit_free_rule_rcu);
|
||||
}
|
||||
|
||||
audit_remove_watch(owatch);
|
||||
goto add_watch_to_parent; /* event applies to a single watch */
|
||||
}
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
return;
|
||||
|
||||
add_watch_to_parent:
|
||||
list_add(&nwatch->wlist, &parent->watches);
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove all watches & rules associated with a parent that is going away. */
|
||||
static void audit_remove_parent_watches(struct audit_parent *parent)
|
||||
{
|
||||
struct audit_watch *w, *nextw;
|
||||
struct audit_krule *r, *nextr;
|
||||
struct audit_entry *e;
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
parent->flags |= AUDIT_PARENT_INVALID;
|
||||
list_for_each_entry_safe(w, nextw, &parent->watches, wlist) {
|
||||
list_for_each_entry_safe(r, nextr, &w->rules, rlist) {
|
||||
e = container_of(r, struct audit_entry, rule);
|
||||
audit_watch_log_rule_change(r, w, "remove rule");
|
||||
list_del(&r->rlist);
|
||||
list_del(&r->list);
|
||||
list_del_rcu(&e->list);
|
||||
call_rcu(&e->rcu, audit_free_rule_rcu);
|
||||
}
|
||||
audit_remove_watch(w);
|
||||
}
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
}
|
||||
|
||||
/* Unregister inotify watches for parents on in_list.
|
||||
* Generates an IN_IGNORED event. */
|
||||
void audit_inotify_unregister(struct list_head *in_list)
|
||||
{
|
||||
struct audit_parent *p, *n;
|
||||
|
||||
list_for_each_entry_safe(p, n, in_list, ilist) {
|
||||
list_del(&p->ilist);
|
||||
inotify_rm_watch(audit_ih, &p->wdata);
|
||||
/* the unpin matching the pin in audit_do_del_rule() */
|
||||
unpin_inotify_watch(&p->wdata);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get path information necessary for adding watches. */
|
||||
static int audit_get_nd(char *path, struct nameidata **ndp, struct nameidata **ndw)
|
||||
{
|
||||
struct nameidata *ndparent, *ndwatch;
|
||||
int err;
|
||||
|
||||
ndparent = kmalloc(sizeof(*ndparent), GFP_KERNEL);
|
||||
if (unlikely(!ndparent))
|
||||
return -ENOMEM;
|
||||
|
||||
ndwatch = kmalloc(sizeof(*ndwatch), GFP_KERNEL);
|
||||
if (unlikely(!ndwatch)) {
|
||||
kfree(ndparent);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = path_lookup(path, LOOKUP_PARENT, ndparent);
|
||||
if (err) {
|
||||
kfree(ndparent);
|
||||
kfree(ndwatch);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = path_lookup(path, 0, ndwatch);
|
||||
if (err) {
|
||||
kfree(ndwatch);
|
||||
ndwatch = NULL;
|
||||
}
|
||||
|
||||
*ndp = ndparent;
|
||||
*ndw = ndwatch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Release resources used for watch path information. */
|
||||
static void audit_put_nd(struct nameidata *ndp, struct nameidata *ndw)
|
||||
{
|
||||
if (ndp) {
|
||||
path_put(&ndp->path);
|
||||
kfree(ndp);
|
||||
}
|
||||
if (ndw) {
|
||||
path_put(&ndw->path);
|
||||
kfree(ndw);
|
||||
}
|
||||
}
|
||||
|
||||
/* Associate the given rule with an existing parent inotify_watch.
|
||||
* Caller must hold audit_filter_mutex. */
|
||||
static void audit_add_to_parent(struct audit_krule *krule,
|
||||
struct audit_parent *parent)
|
||||
{
|
||||
struct audit_watch *w, *watch = krule->watch;
|
||||
int watch_found = 0;
|
||||
|
||||
list_for_each_entry(w, &parent->watches, wlist) {
|
||||
if (strcmp(watch->path, w->path))
|
||||
continue;
|
||||
|
||||
watch_found = 1;
|
||||
|
||||
/* put krule's and initial refs to temporary watch */
|
||||
audit_put_watch(watch);
|
||||
audit_put_watch(watch);
|
||||
|
||||
audit_get_watch(w);
|
||||
krule->watch = watch = w;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!watch_found) {
|
||||
get_inotify_watch(&parent->wdata);
|
||||
watch->parent = parent;
|
||||
|
||||
list_add(&watch->wlist, &parent->watches);
|
||||
}
|
||||
list_add(&krule->rlist, &watch->rules);
|
||||
}
|
||||
|
||||
/* Find a matching watch entry, or add this one.
|
||||
* Caller must hold audit_filter_mutex. */
|
||||
int audit_add_watch(struct audit_krule *krule)
|
||||
{
|
||||
struct audit_watch *watch = krule->watch;
|
||||
struct inotify_watch *i_watch;
|
||||
struct audit_parent *parent;
|
||||
struct nameidata *ndp = NULL, *ndw = NULL;
|
||||
int ret = 0;
|
||||
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
|
||||
/* Avoid calling path_lookup under audit_filter_mutex. */
|
||||
ret = audit_get_nd(watch->path, &ndp, &ndw);
|
||||
if (ret) {
|
||||
/* caller expects mutex locked */
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* update watch filter fields */
|
||||
if (ndw) {
|
||||
watch->dev = ndw->path.dentry->d_inode->i_sb->s_dev;
|
||||
watch->ino = ndw->path.dentry->d_inode->i_ino;
|
||||
}
|
||||
|
||||
/* The audit_filter_mutex must not be held during inotify calls because
|
||||
* we hold it during inotify event callback processing. If an existing
|
||||
* inotify watch is found, inotify_find_watch() grabs a reference before
|
||||
* returning.
|
||||
*/
|
||||
if (inotify_find_watch(audit_ih, ndp->path.dentry->d_inode,
|
||||
&i_watch) < 0) {
|
||||
parent = audit_init_parent(ndp);
|
||||
if (IS_ERR(parent)) {
|
||||
/* caller expects mutex locked */
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
ret = PTR_ERR(parent);
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
|
||||
/* parent was moved before we took audit_filter_mutex */
|
||||
if (parent->flags & AUDIT_PARENT_INVALID)
|
||||
ret = -ENOENT;
|
||||
else
|
||||
audit_add_to_parent(krule, parent);
|
||||
|
||||
/* match get in audit_init_parent or inotify_find_watch */
|
||||
put_inotify_watch(&parent->wdata);
|
||||
|
||||
error:
|
||||
audit_put_nd(ndp, ndw); /* NULL args OK */
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void audit_remove_watch_rule(struct audit_krule *krule, struct list_head *list)
|
||||
{
|
||||
struct audit_watch *watch = krule->watch;
|
||||
struct audit_parent *parent = watch->parent;
|
||||
|
||||
list_del(&krule->rlist);
|
||||
|
||||
if (list_empty(&watch->rules)) {
|
||||
audit_remove_watch(watch);
|
||||
|
||||
if (list_empty(&parent->watches)) {
|
||||
/* Put parent on the inotify un-registration
|
||||
* list. Grab a reference before releasing
|
||||
* audit_filter_mutex, to be released in
|
||||
* audit_inotify_unregister().
|
||||
* If filesystem is going away, just leave
|
||||
* the sucker alone, eviction will take
|
||||
* care of it. */
|
||||
if (pin_inotify_watch(&parent->wdata))
|
||||
list_add(&parent->ilist, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Update watch data in audit rules based on inotify events. */
|
||||
static void audit_handle_ievent(struct inotify_watch *i_watch, u32 wd, u32 mask,
|
||||
u32 cookie, const char *dname, struct inode *inode)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
|
||||
if (mask & (IN_CREATE|IN_MOVED_TO) && inode)
|
||||
audit_update_watch(parent, dname, inode->i_sb->s_dev,
|
||||
inode->i_ino, 0);
|
||||
else if (mask & (IN_DELETE|IN_MOVED_FROM))
|
||||
audit_update_watch(parent, dname, (dev_t)-1, (unsigned long)-1, 1);
|
||||
/* inotify automatically removes the watch and sends IN_IGNORED */
|
||||
else if (mask & (IN_DELETE_SELF|IN_UNMOUNT))
|
||||
audit_remove_parent_watches(parent);
|
||||
/* inotify does not remove the watch, so remove it manually */
|
||||
else if(mask & IN_MOVE_SELF) {
|
||||
audit_remove_parent_watches(parent);
|
||||
inotify_remove_watch_locked(audit_ih, i_watch);
|
||||
} else if (mask & IN_IGNORED)
|
||||
put_inotify_watch(i_watch);
|
||||
}
|
||||
|
||||
static const struct inotify_operations audit_inotify_ops = {
|
||||
.handle_event = audit_handle_ievent,
|
||||
.destroy_watch = audit_free_parent,
|
||||
};
|
||||
|
||||
static int __init audit_watch_init(void)
|
||||
{
|
||||
audit_ih = inotify_init(&audit_inotify_ops);
|
||||
if (IS_ERR(audit_ih))
|
||||
audit_panic("cannot initialize inotify handle");
|
||||
return 0;
|
||||
}
|
||||
subsys_initcall(audit_watch_init);
|
||||
|
|
@ -27,7 +27,6 @@
|
|||
#include <linux/namei.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/inotify.h>
|
||||
#include <linux/security.h>
|
||||
#include "audit.h"
|
||||
|
||||
|
|
@ -44,36 +43,6 @@
|
|||
* be written directly provided audit_filter_mutex is held.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reference counting:
|
||||
*
|
||||
* audit_parent: lifetime is from audit_init_parent() to receipt of an IN_IGNORED
|
||||
* event. Each audit_watch holds a reference to its associated parent.
|
||||
*
|
||||
* audit_watch: if added to lists, lifetime is from audit_init_watch() to
|
||||
* audit_remove_watch(). Additionally, an audit_watch may exist
|
||||
* temporarily to assist in searching existing filter data. Each
|
||||
* audit_krule holds a reference to its associated watch.
|
||||
*/
|
||||
|
||||
struct audit_parent {
|
||||
struct list_head ilist; /* entry in inotify registration list */
|
||||
struct list_head watches; /* associated watches */
|
||||
struct inotify_watch wdata; /* inotify watch data */
|
||||
unsigned flags; /* status flags */
|
||||
};
|
||||
|
||||
/*
|
||||
* audit_parent status flags:
|
||||
*
|
||||
* AUDIT_PARENT_INVALID - set anytime rules/watches are auto-removed due to
|
||||
* a filesystem event to ensure we're adding audit watches to a valid parent.
|
||||
* Technically not needed for IN_DELETE_SELF or IN_UNMOUNT events, as we cannot
|
||||
* receive them while we have nameidata, but must be used for IN_MOVE_SELF which
|
||||
* we can receive while holding nameidata.
|
||||
*/
|
||||
#define AUDIT_PARENT_INVALID 0x001
|
||||
|
||||
/* Audit filter lists, defined in <linux/audit.h> */
|
||||
struct list_head audit_filter_list[AUDIT_NR_FILTERS] = {
|
||||
LIST_HEAD_INIT(audit_filter_list[0]),
|
||||
|
|
@ -97,41 +66,6 @@ static struct list_head audit_rules_list[AUDIT_NR_FILTERS] = {
|
|||
|
||||
DEFINE_MUTEX(audit_filter_mutex);
|
||||
|
||||
/* Inotify events we care about. */
|
||||
#define AUDIT_IN_WATCH IN_MOVE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF
|
||||
|
||||
void audit_free_parent(struct inotify_watch *i_watch)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
WARN_ON(!list_empty(&parent->watches));
|
||||
kfree(parent);
|
||||
}
|
||||
|
||||
static inline void audit_get_watch(struct audit_watch *watch)
|
||||
{
|
||||
atomic_inc(&watch->count);
|
||||
}
|
||||
|
||||
static void audit_put_watch(struct audit_watch *watch)
|
||||
{
|
||||
if (atomic_dec_and_test(&watch->count)) {
|
||||
WARN_ON(watch->parent);
|
||||
WARN_ON(!list_empty(&watch->rules));
|
||||
kfree(watch->path);
|
||||
kfree(watch);
|
||||
}
|
||||
}
|
||||
|
||||
static void audit_remove_watch(struct audit_watch *watch)
|
||||
{
|
||||
list_del(&watch->wlist);
|
||||
put_inotify_watch(&watch->parent->wdata);
|
||||
watch->parent = NULL;
|
||||
audit_put_watch(watch); /* match initial get */
|
||||
}
|
||||
|
||||
static inline void audit_free_rule(struct audit_entry *e)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -156,50 +90,6 @@ void audit_free_rule_rcu(struct rcu_head *head)
|
|||
audit_free_rule(e);
|
||||
}
|
||||
|
||||
/* Initialize a parent watch entry. */
|
||||
static struct audit_parent *audit_init_parent(struct nameidata *ndp)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
s32 wd;
|
||||
|
||||
parent = kzalloc(sizeof(*parent), GFP_KERNEL);
|
||||
if (unlikely(!parent))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
INIT_LIST_HEAD(&parent->watches);
|
||||
parent->flags = 0;
|
||||
|
||||
inotify_init_watch(&parent->wdata);
|
||||
/* grab a ref so inotify watch hangs around until we take audit_filter_mutex */
|
||||
get_inotify_watch(&parent->wdata);
|
||||
wd = inotify_add_watch(audit_ih, &parent->wdata,
|
||||
ndp->path.dentry->d_inode, AUDIT_IN_WATCH);
|
||||
if (wd < 0) {
|
||||
audit_free_parent(&parent->wdata);
|
||||
return ERR_PTR(wd);
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* Initialize a watch entry. */
|
||||
static struct audit_watch *audit_init_watch(char *path)
|
||||
{
|
||||
struct audit_watch *watch;
|
||||
|
||||
watch = kzalloc(sizeof(*watch), GFP_KERNEL);
|
||||
if (unlikely(!watch))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
INIT_LIST_HEAD(&watch->rules);
|
||||
atomic_set(&watch->count, 1);
|
||||
watch->path = path;
|
||||
watch->dev = (dev_t)-1;
|
||||
watch->ino = (unsigned long)-1;
|
||||
|
||||
return watch;
|
||||
}
|
||||
|
||||
/* Initialize an audit filterlist entry. */
|
||||
static inline struct audit_entry *audit_init_entry(u32 field_count)
|
||||
{
|
||||
|
|
@ -260,31 +150,6 @@ static inline int audit_to_inode(struct audit_krule *krule,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Translate a watch string to kernel respresentation. */
|
||||
static int audit_to_watch(struct audit_krule *krule, char *path, int len,
|
||||
u32 op)
|
||||
{
|
||||
struct audit_watch *watch;
|
||||
|
||||
if (!audit_ih)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (path[0] != '/' || path[len-1] == '/' ||
|
||||
krule->listnr != AUDIT_FILTER_EXIT ||
|
||||
op != Audit_equal ||
|
||||
krule->inode_f || krule->watch || krule->tree)
|
||||
return -EINVAL;
|
||||
|
||||
watch = audit_init_watch(path);
|
||||
if (IS_ERR(watch))
|
||||
return PTR_ERR(watch);
|
||||
|
||||
audit_get_watch(watch);
|
||||
krule->watch = watch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __u32 *classes[AUDIT_SYSCALL_CLASSES];
|
||||
|
||||
int __init audit_register_class(int class, unsigned *list)
|
||||
|
|
@ -766,7 +631,8 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
|
|||
break;
|
||||
case AUDIT_WATCH:
|
||||
data->buflen += data->values[i] =
|
||||
audit_pack_string(&bufp, krule->watch->path);
|
||||
audit_pack_string(&bufp,
|
||||
audit_watch_path(krule->watch));
|
||||
break;
|
||||
case AUDIT_DIR:
|
||||
data->buflen += data->values[i] =
|
||||
|
|
@ -818,7 +684,8 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
|
|||
return 1;
|
||||
break;
|
||||
case AUDIT_WATCH:
|
||||
if (strcmp(a->watch->path, b->watch->path))
|
||||
if (strcmp(audit_watch_path(a->watch),
|
||||
audit_watch_path(b->watch)))
|
||||
return 1;
|
||||
break;
|
||||
case AUDIT_DIR:
|
||||
|
|
@ -844,32 +711,6 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Duplicate the given audit watch. The new watch's rules list is initialized
|
||||
* to an empty list and wlist is undefined. */
|
||||
static struct audit_watch *audit_dupe_watch(struct audit_watch *old)
|
||||
{
|
||||
char *path;
|
||||
struct audit_watch *new;
|
||||
|
||||
path = kstrdup(old->path, GFP_KERNEL);
|
||||
if (unlikely(!path))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
new = audit_init_watch(path);
|
||||
if (IS_ERR(new)) {
|
||||
kfree(path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
new->dev = old->dev;
|
||||
new->ino = old->ino;
|
||||
get_inotify_watch(&old->parent->wdata);
|
||||
new->parent = old->parent;
|
||||
|
||||
out:
|
||||
return new;
|
||||
}
|
||||
|
||||
/* Duplicate LSM field information. The lsm_rule is opaque, so must be
|
||||
* re-initialized. */
|
||||
static inline int audit_dupe_lsm_field(struct audit_field *df,
|
||||
|
|
@ -904,8 +745,8 @@ static inline int audit_dupe_lsm_field(struct audit_field *df,
|
|||
* rule with the new rule in the filterlist, then free the old rule.
|
||||
* The rlist element is undefined; list manipulations are handled apart from
|
||||
* the initial copy. */
|
||||
static struct audit_entry *audit_dupe_rule(struct audit_krule *old,
|
||||
struct audit_watch *watch)
|
||||
struct audit_entry *audit_dupe_rule(struct audit_krule *old,
|
||||
struct audit_watch *watch)
|
||||
{
|
||||
u32 fcount = old->field_count;
|
||||
struct audit_entry *entry;
|
||||
|
|
@ -977,137 +818,6 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old,
|
|||
return entry;
|
||||
}
|
||||
|
||||
/* Update inode info in audit rules based on filesystem event. */
|
||||
static void audit_update_watch(struct audit_parent *parent,
|
||||
const char *dname, dev_t dev,
|
||||
unsigned long ino, unsigned invalidating)
|
||||
{
|
||||
struct audit_watch *owatch, *nwatch, *nextw;
|
||||
struct audit_krule *r, *nextr;
|
||||
struct audit_entry *oentry, *nentry;
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
list_for_each_entry_safe(owatch, nextw, &parent->watches, wlist) {
|
||||
if (audit_compare_dname_path(dname, owatch->path, NULL))
|
||||
continue;
|
||||
|
||||
/* If the update involves invalidating rules, do the inode-based
|
||||
* filtering now, so we don't omit records. */
|
||||
if (invalidating && current->audit_context)
|
||||
audit_filter_inodes(current, current->audit_context);
|
||||
|
||||
nwatch = audit_dupe_watch(owatch);
|
||||
if (IS_ERR(nwatch)) {
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
audit_panic("error updating watch, skipping");
|
||||
return;
|
||||
}
|
||||
nwatch->dev = dev;
|
||||
nwatch->ino = ino;
|
||||
|
||||
list_for_each_entry_safe(r, nextr, &owatch->rules, rlist) {
|
||||
|
||||
oentry = container_of(r, struct audit_entry, rule);
|
||||
list_del(&oentry->rule.rlist);
|
||||
list_del_rcu(&oentry->list);
|
||||
|
||||
nentry = audit_dupe_rule(&oentry->rule, nwatch);
|
||||
if (IS_ERR(nentry)) {
|
||||
list_del(&oentry->rule.list);
|
||||
audit_panic("error updating watch, removing");
|
||||
} else {
|
||||
int h = audit_hash_ino((u32)ino);
|
||||
list_add(&nentry->rule.rlist, &nwatch->rules);
|
||||
list_add_rcu(&nentry->list, &audit_inode_hash[h]);
|
||||
list_replace(&oentry->rule.list,
|
||||
&nentry->rule.list);
|
||||
}
|
||||
|
||||
call_rcu(&oentry->rcu, audit_free_rule_rcu);
|
||||
}
|
||||
|
||||
if (audit_enabled) {
|
||||
struct audit_buffer *ab;
|
||||
ab = audit_log_start(NULL, GFP_NOFS,
|
||||
AUDIT_CONFIG_CHANGE);
|
||||
audit_log_format(ab, "auid=%u ses=%u",
|
||||
audit_get_loginuid(current),
|
||||
audit_get_sessionid(current));
|
||||
audit_log_format(ab,
|
||||
" op=updated rules specifying path=");
|
||||
audit_log_untrustedstring(ab, owatch->path);
|
||||
audit_log_format(ab, " with dev=%u ino=%lu\n",
|
||||
dev, ino);
|
||||
audit_log_format(ab, " list=%d res=1", r->listnr);
|
||||
audit_log_end(ab);
|
||||
}
|
||||
audit_remove_watch(owatch);
|
||||
goto add_watch_to_parent; /* event applies to a single watch */
|
||||
}
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
return;
|
||||
|
||||
add_watch_to_parent:
|
||||
list_add(&nwatch->wlist, &parent->watches);
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove all watches & rules associated with a parent that is going away. */
|
||||
static void audit_remove_parent_watches(struct audit_parent *parent)
|
||||
{
|
||||
struct audit_watch *w, *nextw;
|
||||
struct audit_krule *r, *nextr;
|
||||
struct audit_entry *e;
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
parent->flags |= AUDIT_PARENT_INVALID;
|
||||
list_for_each_entry_safe(w, nextw, &parent->watches, wlist) {
|
||||
list_for_each_entry_safe(r, nextr, &w->rules, rlist) {
|
||||
e = container_of(r, struct audit_entry, rule);
|
||||
if (audit_enabled) {
|
||||
struct audit_buffer *ab;
|
||||
ab = audit_log_start(NULL, GFP_NOFS,
|
||||
AUDIT_CONFIG_CHANGE);
|
||||
audit_log_format(ab, "auid=%u ses=%u",
|
||||
audit_get_loginuid(current),
|
||||
audit_get_sessionid(current));
|
||||
audit_log_format(ab, " op=remove rule path=");
|
||||
audit_log_untrustedstring(ab, w->path);
|
||||
if (r->filterkey) {
|
||||
audit_log_format(ab, " key=");
|
||||
audit_log_untrustedstring(ab,
|
||||
r->filterkey);
|
||||
} else
|
||||
audit_log_format(ab, " key=(null)");
|
||||
audit_log_format(ab, " list=%d res=1",
|
||||
r->listnr);
|
||||
audit_log_end(ab);
|
||||
}
|
||||
list_del(&r->rlist);
|
||||
list_del(&r->list);
|
||||
list_del_rcu(&e->list);
|
||||
call_rcu(&e->rcu, audit_free_rule_rcu);
|
||||
}
|
||||
audit_remove_watch(w);
|
||||
}
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
}
|
||||
|
||||
/* Unregister inotify watches for parents on in_list.
|
||||
* Generates an IN_IGNORED event. */
|
||||
static void audit_inotify_unregister(struct list_head *in_list)
|
||||
{
|
||||
struct audit_parent *p, *n;
|
||||
|
||||
list_for_each_entry_safe(p, n, in_list, ilist) {
|
||||
list_del(&p->ilist);
|
||||
inotify_rm_watch(audit_ih, &p->wdata);
|
||||
/* the unpin matching the pin in audit_do_del_rule() */
|
||||
unpin_inotify_watch(&p->wdata);
|
||||
}
|
||||
}
|
||||
|
||||
/* Find an existing audit rule.
|
||||
* Caller must hold audit_filter_mutex to prevent stale rule data. */
|
||||
static struct audit_entry *audit_find_rule(struct audit_entry *entry,
|
||||
|
|
@ -1145,134 +855,6 @@ out:
|
|||
return found;
|
||||
}
|
||||
|
||||
/* Get path information necessary for adding watches. */
|
||||
static int audit_get_nd(char *path, struct nameidata **ndp,
|
||||
struct nameidata **ndw)
|
||||
{
|
||||
struct nameidata *ndparent, *ndwatch;
|
||||
int err;
|
||||
|
||||
ndparent = kmalloc(sizeof(*ndparent), GFP_KERNEL);
|
||||
if (unlikely(!ndparent))
|
||||
return -ENOMEM;
|
||||
|
||||
ndwatch = kmalloc(sizeof(*ndwatch), GFP_KERNEL);
|
||||
if (unlikely(!ndwatch)) {
|
||||
kfree(ndparent);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = path_lookup(path, LOOKUP_PARENT, ndparent);
|
||||
if (err) {
|
||||
kfree(ndparent);
|
||||
kfree(ndwatch);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = path_lookup(path, 0, ndwatch);
|
||||
if (err) {
|
||||
kfree(ndwatch);
|
||||
ndwatch = NULL;
|
||||
}
|
||||
|
||||
*ndp = ndparent;
|
||||
*ndw = ndwatch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Release resources used for watch path information. */
|
||||
static void audit_put_nd(struct nameidata *ndp, struct nameidata *ndw)
|
||||
{
|
||||
if (ndp) {
|
||||
path_put(&ndp->path);
|
||||
kfree(ndp);
|
||||
}
|
||||
if (ndw) {
|
||||
path_put(&ndw->path);
|
||||
kfree(ndw);
|
||||
}
|
||||
}
|
||||
|
||||
/* Associate the given rule with an existing parent inotify_watch.
|
||||
* Caller must hold audit_filter_mutex. */
|
||||
static void audit_add_to_parent(struct audit_krule *krule,
|
||||
struct audit_parent *parent)
|
||||
{
|
||||
struct audit_watch *w, *watch = krule->watch;
|
||||
int watch_found = 0;
|
||||
|
||||
list_for_each_entry(w, &parent->watches, wlist) {
|
||||
if (strcmp(watch->path, w->path))
|
||||
continue;
|
||||
|
||||
watch_found = 1;
|
||||
|
||||
/* put krule's and initial refs to temporary watch */
|
||||
audit_put_watch(watch);
|
||||
audit_put_watch(watch);
|
||||
|
||||
audit_get_watch(w);
|
||||
krule->watch = watch = w;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!watch_found) {
|
||||
get_inotify_watch(&parent->wdata);
|
||||
watch->parent = parent;
|
||||
|
||||
list_add(&watch->wlist, &parent->watches);
|
||||
}
|
||||
list_add(&krule->rlist, &watch->rules);
|
||||
}
|
||||
|
||||
/* Find a matching watch entry, or add this one.
|
||||
* Caller must hold audit_filter_mutex. */
|
||||
static int audit_add_watch(struct audit_krule *krule, struct nameidata *ndp,
|
||||
struct nameidata *ndw)
|
||||
{
|
||||
struct audit_watch *watch = krule->watch;
|
||||
struct inotify_watch *i_watch;
|
||||
struct audit_parent *parent;
|
||||
int ret = 0;
|
||||
|
||||
/* update watch filter fields */
|
||||
if (ndw) {
|
||||
watch->dev = ndw->path.dentry->d_inode->i_sb->s_dev;
|
||||
watch->ino = ndw->path.dentry->d_inode->i_ino;
|
||||
}
|
||||
|
||||
/* The audit_filter_mutex must not be held during inotify calls because
|
||||
* we hold it during inotify event callback processing. If an existing
|
||||
* inotify watch is found, inotify_find_watch() grabs a reference before
|
||||
* returning.
|
||||
*/
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
|
||||
if (inotify_find_watch(audit_ih, ndp->path.dentry->d_inode,
|
||||
&i_watch) < 0) {
|
||||
parent = audit_init_parent(ndp);
|
||||
if (IS_ERR(parent)) {
|
||||
/* caller expects mutex locked */
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
return PTR_ERR(parent);
|
||||
}
|
||||
} else
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
|
||||
/* parent was moved before we took audit_filter_mutex */
|
||||
if (parent->flags & AUDIT_PARENT_INVALID)
|
||||
ret = -ENOENT;
|
||||
else
|
||||
audit_add_to_parent(krule, parent);
|
||||
|
||||
/* match get in audit_init_parent or inotify_find_watch */
|
||||
put_inotify_watch(&parent->wdata);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u64 prio_low = ~0ULL/2;
|
||||
static u64 prio_high = ~0ULL/2 - 1;
|
||||
|
||||
|
|
@ -1282,7 +864,6 @@ static inline int audit_add_rule(struct audit_entry *entry)
|
|||
struct audit_entry *e;
|
||||
struct audit_watch *watch = entry->rule.watch;
|
||||
struct audit_tree *tree = entry->rule.tree;
|
||||
struct nameidata *ndp = NULL, *ndw = NULL;
|
||||
struct list_head *list;
|
||||
int h, err;
|
||||
#ifdef CONFIG_AUDITSYSCALL
|
||||
|
|
@ -1296,8 +877,8 @@ static inline int audit_add_rule(struct audit_entry *entry)
|
|||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
e = audit_find_rule(entry, &list);
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
if (e) {
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
err = -EEXIST;
|
||||
/* normally audit_add_tree_rule() will free it on failure */
|
||||
if (tree)
|
||||
|
|
@ -1305,22 +886,16 @@ static inline int audit_add_rule(struct audit_entry *entry)
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* Avoid calling path_lookup under audit_filter_mutex. */
|
||||
if (watch) {
|
||||
err = audit_get_nd(watch->path, &ndp, &ndw);
|
||||
if (err)
|
||||
goto error;
|
||||
}
|
||||
|
||||
mutex_lock(&audit_filter_mutex);
|
||||
if (watch) {
|
||||
/* audit_filter_mutex is dropped and re-taken during this call */
|
||||
err = audit_add_watch(&entry->rule, ndp, ndw);
|
||||
err = audit_add_watch(&entry->rule);
|
||||
if (err) {
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
goto error;
|
||||
}
|
||||
h = audit_hash_ino((u32)watch->ino);
|
||||
/* entry->rule.watch may have changed during audit_add_watch() */
|
||||
watch = entry->rule.watch;
|
||||
h = audit_hash_ino((u32)audit_watch_inode(watch));
|
||||
list = &audit_inode_hash[h];
|
||||
}
|
||||
if (tree) {
|
||||
|
|
@ -1358,11 +933,9 @@ static inline int audit_add_rule(struct audit_entry *entry)
|
|||
#endif
|
||||
mutex_unlock(&audit_filter_mutex);
|
||||
|
||||
audit_put_nd(ndp, ndw); /* NULL args OK */
|
||||
return 0;
|
||||
|
||||
error:
|
||||
audit_put_nd(ndp, ndw); /* NULL args OK */
|
||||
if (watch)
|
||||
audit_put_watch(watch); /* tmp watch, matches initial get */
|
||||
return err;
|
||||
|
|
@ -1372,7 +945,7 @@ error:
|
|||
static inline int audit_del_rule(struct audit_entry *entry)
|
||||
{
|
||||
struct audit_entry *e;
|
||||
struct audit_watch *watch, *tmp_watch = entry->rule.watch;
|
||||
struct audit_watch *watch = entry->rule.watch;
|
||||
struct audit_tree *tree = entry->rule.tree;
|
||||
struct list_head *list;
|
||||
LIST_HEAD(inotify_list);
|
||||
|
|
@ -1394,29 +967,8 @@ static inline int audit_del_rule(struct audit_entry *entry)
|
|||
goto out;
|
||||
}
|
||||
|
||||
watch = e->rule.watch;
|
||||
if (watch) {
|
||||
struct audit_parent *parent = watch->parent;
|
||||
|
||||
list_del(&e->rule.rlist);
|
||||
|
||||
if (list_empty(&watch->rules)) {
|
||||
audit_remove_watch(watch);
|
||||
|
||||
if (list_empty(&parent->watches)) {
|
||||
/* Put parent on the inotify un-registration
|
||||
* list. Grab a reference before releasing
|
||||
* audit_filter_mutex, to be released in
|
||||
* audit_inotify_unregister().
|
||||
* If filesystem is going away, just leave
|
||||
* the sucker alone, eviction will take
|
||||
* care of it.
|
||||
*/
|
||||
if (pin_inotify_watch(&parent->wdata))
|
||||
list_add(&parent->ilist, &inotify_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e->rule.watch)
|
||||
audit_remove_watch_rule(&e->rule, &inotify_list);
|
||||
|
||||
if (e->rule.tree)
|
||||
audit_remove_tree_rule(&e->rule);
|
||||
|
|
@ -1438,8 +990,8 @@ static inline int audit_del_rule(struct audit_entry *entry)
|
|||
audit_inotify_unregister(&inotify_list);
|
||||
|
||||
out:
|
||||
if (tmp_watch)
|
||||
audit_put_watch(tmp_watch); /* match initial get */
|
||||
if (watch)
|
||||
audit_put_watch(watch); /* match initial get */
|
||||
if (tree)
|
||||
audit_put_tree(tree); /* that's the temporary one */
|
||||
|
||||
|
|
@ -1527,11 +1079,9 @@ static void audit_log_rule_change(uid_t loginuid, u32 sessionid, u32 sid,
|
|||
security_release_secctx(ctx, len);
|
||||
}
|
||||
}
|
||||
audit_log_format(ab, " op=%s rule key=", action);
|
||||
if (rule->filterkey)
|
||||
audit_log_untrustedstring(ab, rule->filterkey);
|
||||
else
|
||||
audit_log_format(ab, "(null)");
|
||||
audit_log_format(ab, " op=");
|
||||
audit_log_string(ab, action);
|
||||
audit_log_key(ab, rule->filterkey);
|
||||
audit_log_format(ab, " list=%d res=%d", rule->listnr, res);
|
||||
audit_log_end(ab);
|
||||
}
|
||||
|
|
@ -1595,7 +1145,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
|
|||
return PTR_ERR(entry);
|
||||
|
||||
err = audit_add_rule(entry);
|
||||
audit_log_rule_change(loginuid, sessionid, sid, "add",
|
||||
audit_log_rule_change(loginuid, sessionid, sid, "add rule",
|
||||
&entry->rule, !err);
|
||||
|
||||
if (err)
|
||||
|
|
@ -1611,7 +1161,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
|
|||
return PTR_ERR(entry);
|
||||
|
||||
err = audit_del_rule(entry);
|
||||
audit_log_rule_change(loginuid, sessionid, sid, "remove",
|
||||
audit_log_rule_change(loginuid, sessionid, sid, "remove rule",
|
||||
&entry->rule, !err);
|
||||
|
||||
audit_free_rule(entry);
|
||||
|
|
@ -1793,7 +1343,7 @@ static int update_lsm_rule(struct audit_krule *r)
|
|||
list_del(&r->list);
|
||||
} else {
|
||||
if (watch) {
|
||||
list_add(&nentry->rule.rlist, &watch->rules);
|
||||
list_add(&nentry->rule.rlist, audit_watch_rules(watch));
|
||||
list_del(&r->rlist);
|
||||
} else if (tree)
|
||||
list_replace_init(&r->rlist, &nentry->rule.rlist);
|
||||
|
|
@ -1829,27 +1379,3 @@ int audit_update_lsm_rules(void)
|
|||
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Update watch data in audit rules based on inotify events. */
|
||||
void audit_handle_ievent(struct inotify_watch *i_watch, u32 wd, u32 mask,
|
||||
u32 cookie, const char *dname, struct inode *inode)
|
||||
{
|
||||
struct audit_parent *parent;
|
||||
|
||||
parent = container_of(i_watch, struct audit_parent, wdata);
|
||||
|
||||
if (mask & (IN_CREATE|IN_MOVED_TO) && inode)
|
||||
audit_update_watch(parent, dname, inode->i_sb->s_dev,
|
||||
inode->i_ino, 0);
|
||||
else if (mask & (IN_DELETE|IN_MOVED_FROM))
|
||||
audit_update_watch(parent, dname, (dev_t)-1, (unsigned long)-1, 1);
|
||||
/* inotify automatically removes the watch and sends IN_IGNORED */
|
||||
else if (mask & (IN_DELETE_SELF|IN_UNMOUNT))
|
||||
audit_remove_parent_watches(parent);
|
||||
/* inotify does not remove the watch, so remove it manually */
|
||||
else if(mask & IN_MOVE_SELF) {
|
||||
audit_remove_parent_watches(parent);
|
||||
inotify_remove_watch_locked(audit_ih, i_watch);
|
||||
} else if (mask & IN_IGNORED)
|
||||
put_inotify_watch(i_watch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,6 +199,7 @@ struct audit_context {
|
|||
|
||||
struct audit_tree_refs *trees, *first_trees;
|
||||
int tree_count;
|
||||
struct list_head killed_trees;
|
||||
|
||||
int type;
|
||||
union {
|
||||
|
|
@ -548,9 +549,9 @@ static int audit_filter_rules(struct task_struct *tsk,
|
|||
}
|
||||
break;
|
||||
case AUDIT_WATCH:
|
||||
if (name && rule->watch->ino != (unsigned long)-1)
|
||||
result = (name->dev == rule->watch->dev &&
|
||||
name->ino == rule->watch->ino);
|
||||
if (name && audit_watch_inode(rule->watch) != (unsigned long)-1)
|
||||
result = (name->dev == audit_watch_dev(rule->watch) &&
|
||||
name->ino == audit_watch_inode(rule->watch));
|
||||
break;
|
||||
case AUDIT_DIR:
|
||||
if (ctx)
|
||||
|
|
@ -853,6 +854,7 @@ static inline struct audit_context *audit_alloc_context(enum audit_state state)
|
|||
if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
|
||||
return NULL;
|
||||
audit_zero_context(context, state);
|
||||
INIT_LIST_HEAD(&context->killed_trees);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -1024,8 +1026,8 @@ static int audit_log_single_execve_arg(struct audit_context *context,
|
|||
{
|
||||
char arg_num_len_buf[12];
|
||||
const char __user *tmp_p = p;
|
||||
/* how many digits are in arg_num? 3 is the length of " a=" */
|
||||
size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 3;
|
||||
/* how many digits are in arg_num? 5 is the length of ' a=""' */
|
||||
size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 5;
|
||||
size_t len, len_left, to_send;
|
||||
size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN;
|
||||
unsigned int i, has_cntl = 0, too_long = 0;
|
||||
|
|
@ -1137,7 +1139,7 @@ static int audit_log_single_execve_arg(struct audit_context *context,
|
|||
if (has_cntl)
|
||||
audit_log_n_hex(*ab, buf, to_send);
|
||||
else
|
||||
audit_log_format(*ab, "\"%s\"", buf);
|
||||
audit_log_string(*ab, buf);
|
||||
|
||||
p += to_send;
|
||||
len_left -= to_send;
|
||||
|
|
@ -1372,11 +1374,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
|
|||
|
||||
|
||||
audit_log_task_info(ab, tsk);
|
||||
if (context->filterkey) {
|
||||
audit_log_format(ab, " key=");
|
||||
audit_log_untrustedstring(ab, context->filterkey);
|
||||
} else
|
||||
audit_log_format(ab, " key=(null)");
|
||||
audit_log_key(ab, context->filterkey);
|
||||
audit_log_end(ab);
|
||||
|
||||
for (aux = context->aux; aux; aux = aux->next) {
|
||||
|
|
@ -1549,6 +1547,8 @@ void audit_free(struct task_struct *tsk)
|
|||
/* that can happen only if we are called from do_exit() */
|
||||
if (context->in_syscall && context->current_state == AUDIT_RECORD_CONTEXT)
|
||||
audit_log_exit(context, tsk);
|
||||
if (!list_empty(&context->killed_trees))
|
||||
audit_kill_trees(&context->killed_trees);
|
||||
|
||||
audit_free_context(context);
|
||||
}
|
||||
|
|
@ -1692,6 +1692,9 @@ void audit_syscall_exit(int valid, long return_code)
|
|||
context->in_syscall = 0;
|
||||
context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
|
||||
|
||||
if (!list_empty(&context->killed_trees))
|
||||
audit_kill_trees(&context->killed_trees);
|
||||
|
||||
if (context->previous) {
|
||||
struct audit_context *new_context = context->previous;
|
||||
context->previous = NULL;
|
||||
|
|
@ -2525,3 +2528,11 @@ void audit_core_dumps(long signr)
|
|||
audit_log_format(ab, " sig=%ld", signr);
|
||||
audit_log_end(ab);
|
||||
}
|
||||
|
||||
struct list_head *audit_killed_trees(void)
|
||||
{
|
||||
struct audit_context *ctx = current->audit_context;
|
||||
if (likely(!ctx || !ctx->in_syscall))
|
||||
return NULL;
|
||||
return &ctx->killed_trees;
|
||||
}
|
||||
|
|
|
|||
151
kernel/cgroup.c
151
kernel/cgroup.c
|
|
@ -47,6 +47,7 @@
|
|||
#include <linux/hash.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <linux/pid_namespace.h>
|
||||
|
||||
#include <asm/atomic.h>
|
||||
|
||||
|
|
@ -734,16 +735,28 @@ static void cgroup_d_remove_dir(struct dentry *dentry)
|
|||
* reference to css->refcnt. In general, this refcnt is expected to goes down
|
||||
* to zero, soon.
|
||||
*
|
||||
* CGRP_WAIT_ON_RMDIR flag is modified under cgroup's inode->i_mutex;
|
||||
* CGRP_WAIT_ON_RMDIR flag is set under cgroup's inode->i_mutex;
|
||||
*/
|
||||
DECLARE_WAIT_QUEUE_HEAD(cgroup_rmdir_waitq);
|
||||
|
||||
static void cgroup_wakeup_rmdir_waiters(const struct cgroup *cgrp)
|
||||
static void cgroup_wakeup_rmdir_waiter(struct cgroup *cgrp)
|
||||
{
|
||||
if (unlikely(test_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags)))
|
||||
if (unlikely(test_and_clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags)))
|
||||
wake_up_all(&cgroup_rmdir_waitq);
|
||||
}
|
||||
|
||||
void cgroup_exclude_rmdir(struct cgroup_subsys_state *css)
|
||||
{
|
||||
css_get(css);
|
||||
}
|
||||
|
||||
void cgroup_release_and_wakeup_rmdir(struct cgroup_subsys_state *css)
|
||||
{
|
||||
cgroup_wakeup_rmdir_waiter(css->cgroup);
|
||||
css_put(css);
|
||||
}
|
||||
|
||||
|
||||
static int rebind_subsystems(struct cgroupfs_root *root,
|
||||
unsigned long final_bits)
|
||||
{
|
||||
|
|
@ -960,6 +973,7 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp)
|
|||
INIT_LIST_HEAD(&cgrp->children);
|
||||
INIT_LIST_HEAD(&cgrp->css_sets);
|
||||
INIT_LIST_HEAD(&cgrp->release_list);
|
||||
INIT_LIST_HEAD(&cgrp->pids_list);
|
||||
init_rwsem(&cgrp->pids_mutex);
|
||||
}
|
||||
static void init_cgroup_root(struct cgroupfs_root *root)
|
||||
|
|
@ -1357,7 +1371,7 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
|
|||
* wake up rmdir() waiter. the rmdir should fail since the cgroup
|
||||
* is no longer empty.
|
||||
*/
|
||||
cgroup_wakeup_rmdir_waiters(cgrp);
|
||||
cgroup_wakeup_rmdir_waiter(cgrp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2201,12 +2215,30 @@ err:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cache pids for all threads in the same pid namespace that are
|
||||
* opening the same "tasks" file.
|
||||
*/
|
||||
struct cgroup_pids {
|
||||
/* The node in cgrp->pids_list */
|
||||
struct list_head list;
|
||||
/* The cgroup those pids belong to */
|
||||
struct cgroup *cgrp;
|
||||
/* The namepsace those pids belong to */
|
||||
struct pid_namespace *ns;
|
||||
/* Array of process ids in the cgroup */
|
||||
pid_t *tasks_pids;
|
||||
/* How many files are using the this tasks_pids array */
|
||||
int use_count;
|
||||
/* Length of the current tasks_pids array */
|
||||
int length;
|
||||
};
|
||||
|
||||
static int cmppid(const void *a, const void *b)
|
||||
{
|
||||
return *(pid_t *)a - *(pid_t *)b;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* seq_file methods for the "tasks" file. The seq_file position is the
|
||||
* next pid to display; the seq_file iterator is a pointer to the pid
|
||||
|
|
@ -2221,45 +2253,47 @@ static void *cgroup_tasks_start(struct seq_file *s, loff_t *pos)
|
|||
* after a seek to the start). Use a binary-search to find the
|
||||
* next pid to display, if any
|
||||
*/
|
||||
struct cgroup *cgrp = s->private;
|
||||
struct cgroup_pids *cp = s->private;
|
||||
struct cgroup *cgrp = cp->cgrp;
|
||||
int index = 0, pid = *pos;
|
||||
int *iter;
|
||||
|
||||
down_read(&cgrp->pids_mutex);
|
||||
if (pid) {
|
||||
int end = cgrp->pids_length;
|
||||
int end = cp->length;
|
||||
|
||||
while (index < end) {
|
||||
int mid = (index + end) / 2;
|
||||
if (cgrp->tasks_pids[mid] == pid) {
|
||||
if (cp->tasks_pids[mid] == pid) {
|
||||
index = mid;
|
||||
break;
|
||||
} else if (cgrp->tasks_pids[mid] <= pid)
|
||||
} else if (cp->tasks_pids[mid] <= pid)
|
||||
index = mid + 1;
|
||||
else
|
||||
end = mid;
|
||||
}
|
||||
}
|
||||
/* If we're off the end of the array, we're done */
|
||||
if (index >= cgrp->pids_length)
|
||||
if (index >= cp->length)
|
||||
return NULL;
|
||||
/* Update the abstract position to be the actual pid that we found */
|
||||
iter = cgrp->tasks_pids + index;
|
||||
iter = cp->tasks_pids + index;
|
||||
*pos = *iter;
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void cgroup_tasks_stop(struct seq_file *s, void *v)
|
||||
{
|
||||
struct cgroup *cgrp = s->private;
|
||||
struct cgroup_pids *cp = s->private;
|
||||
struct cgroup *cgrp = cp->cgrp;
|
||||
up_read(&cgrp->pids_mutex);
|
||||
}
|
||||
|
||||
static void *cgroup_tasks_next(struct seq_file *s, void *v, loff_t *pos)
|
||||
{
|
||||
struct cgroup *cgrp = s->private;
|
||||
struct cgroup_pids *cp = s->private;
|
||||
int *p = v;
|
||||
int *end = cgrp->tasks_pids + cgrp->pids_length;
|
||||
int *end = cp->tasks_pids + cp->length;
|
||||
|
||||
/*
|
||||
* Advance to the next pid in the array. If this goes off the
|
||||
|
|
@ -2286,26 +2320,33 @@ static struct seq_operations cgroup_tasks_seq_operations = {
|
|||
.show = cgroup_tasks_show,
|
||||
};
|
||||
|
||||
static void release_cgroup_pid_array(struct cgroup *cgrp)
|
||||
static void release_cgroup_pid_array(struct cgroup_pids *cp)
|
||||
{
|
||||
struct cgroup *cgrp = cp->cgrp;
|
||||
|
||||
down_write(&cgrp->pids_mutex);
|
||||
BUG_ON(!cgrp->pids_use_count);
|
||||
if (!--cgrp->pids_use_count) {
|
||||
kfree(cgrp->tasks_pids);
|
||||
cgrp->tasks_pids = NULL;
|
||||
cgrp->pids_length = 0;
|
||||
BUG_ON(!cp->use_count);
|
||||
if (!--cp->use_count) {
|
||||
list_del(&cp->list);
|
||||
put_pid_ns(cp->ns);
|
||||
kfree(cp->tasks_pids);
|
||||
kfree(cp);
|
||||
}
|
||||
up_write(&cgrp->pids_mutex);
|
||||
}
|
||||
|
||||
static int cgroup_tasks_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
|
||||
struct seq_file *seq;
|
||||
struct cgroup_pids *cp;
|
||||
|
||||
if (!(file->f_mode & FMODE_READ))
|
||||
return 0;
|
||||
|
||||
release_cgroup_pid_array(cgrp);
|
||||
seq = file->private_data;
|
||||
cp = seq->private;
|
||||
|
||||
release_cgroup_pid_array(cp);
|
||||
return seq_release(inode, file);
|
||||
}
|
||||
|
||||
|
|
@ -2324,6 +2365,8 @@ static struct file_operations cgroup_tasks_operations = {
|
|||
static int cgroup_tasks_open(struct inode *unused, struct file *file)
|
||||
{
|
||||
struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
|
||||
struct pid_namespace *ns = current->nsproxy->pid_ns;
|
||||
struct cgroup_pids *cp;
|
||||
pid_t *pidarray;
|
||||
int npids;
|
||||
int retval;
|
||||
|
|
@ -2350,20 +2393,37 @@ static int cgroup_tasks_open(struct inode *unused, struct file *file)
|
|||
* array if necessary
|
||||
*/
|
||||
down_write(&cgrp->pids_mutex);
|
||||
kfree(cgrp->tasks_pids);
|
||||
cgrp->tasks_pids = pidarray;
|
||||
cgrp->pids_length = npids;
|
||||
cgrp->pids_use_count++;
|
||||
|
||||
list_for_each_entry(cp, &cgrp->pids_list, list) {
|
||||
if (ns == cp->ns)
|
||||
goto found;
|
||||
}
|
||||
|
||||
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
|
||||
if (!cp) {
|
||||
up_write(&cgrp->pids_mutex);
|
||||
kfree(pidarray);
|
||||
return -ENOMEM;
|
||||
}
|
||||
cp->cgrp = cgrp;
|
||||
cp->ns = ns;
|
||||
get_pid_ns(ns);
|
||||
list_add(&cp->list, &cgrp->pids_list);
|
||||
found:
|
||||
kfree(cp->tasks_pids);
|
||||
cp->tasks_pids = pidarray;
|
||||
cp->length = npids;
|
||||
cp->use_count++;
|
||||
up_write(&cgrp->pids_mutex);
|
||||
|
||||
file->f_op = &cgroup_tasks_operations;
|
||||
|
||||
retval = seq_open(file, &cgroup_tasks_seq_operations);
|
||||
if (retval) {
|
||||
release_cgroup_pid_array(cgrp);
|
||||
release_cgroup_pid_array(cp);
|
||||
return retval;
|
||||
}
|
||||
((struct seq_file *)file->private_data)->private = cgrp;
|
||||
((struct seq_file *)file->private_data)->private = cp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2695,34 +2755,43 @@ again:
|
|||
}
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
|
||||
/*
|
||||
* In general, subsystem has no css->refcnt after pre_destroy(). But
|
||||
* in racy cases, subsystem may have to get css->refcnt after
|
||||
* pre_destroy() and it makes rmdir return with -EBUSY. This sometimes
|
||||
* make rmdir return -EBUSY too often. To avoid that, we use waitqueue
|
||||
* for cgroup's rmdir. CGRP_WAIT_ON_RMDIR is for synchronizing rmdir
|
||||
* and subsystem's reference count handling. Please see css_get/put
|
||||
* and css_tryget() and cgroup_wakeup_rmdir_waiter() implementation.
|
||||
*/
|
||||
set_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||
|
||||
/*
|
||||
* Call pre_destroy handlers of subsys. Notify subsystems
|
||||
* that rmdir() request comes.
|
||||
*/
|
||||
ret = cgroup_call_pre_destroy(cgrp);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mutex_lock(&cgroup_mutex);
|
||||
parent = cgrp->parent;
|
||||
if (atomic_read(&cgrp->count) || !list_empty(&cgrp->children)) {
|
||||
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
return -EBUSY;
|
||||
}
|
||||
/*
|
||||
* css_put/get is provided for subsys to grab refcnt to css. In typical
|
||||
* case, subsystem has no reference after pre_destroy(). But, under
|
||||
* hierarchy management, some *temporal* refcnt can be hold.
|
||||
* To avoid returning -EBUSY to a user, waitqueue is used. If subsys
|
||||
* is really busy, it should return -EBUSY at pre_destroy(). wake_up
|
||||
* is called when css_put() is called and refcnt goes down to 0.
|
||||
*/
|
||||
set_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||
prepare_to_wait(&cgroup_rmdir_waitq, &wait, TASK_INTERRUPTIBLE);
|
||||
|
||||
if (!cgroup_clear_css_refs(cgrp)) {
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
schedule();
|
||||
/*
|
||||
* Because someone may call cgroup_wakeup_rmdir_waiter() before
|
||||
* prepare_to_wait(), we need to check this flag.
|
||||
*/
|
||||
if (test_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags))
|
||||
schedule();
|
||||
finish_wait(&cgroup_rmdir_waitq, &wait);
|
||||
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||
if (signal_pending(current))
|
||||
|
|
@ -3294,7 +3363,7 @@ void __css_put(struct cgroup_subsys_state *css)
|
|||
set_bit(CGRP_RELEASABLE, &cgrp->flags);
|
||||
check_for_release(cgrp);
|
||||
}
|
||||
cgroup_wakeup_rmdir_waiters(cgrp);
|
||||
cgroup_wakeup_rmdir_waiter(cgrp);
|
||||
}
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
#include <linux/completion.h>
|
||||
#include <linux/personality.h>
|
||||
#include <linux/tty.h>
|
||||
#include <linux/mnt_namespace.h>
|
||||
#include <linux/iocontext.h>
|
||||
#include <linux/key.h>
|
||||
#include <linux/security.h>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include <linux/module.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/mnt_namespace.h>
|
||||
#include <linux/personality.h>
|
||||
#include <linux/mempolicy.h>
|
||||
#include <linux/sem.h>
|
||||
|
|
@ -427,6 +426,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p)
|
|||
init_rwsem(&mm->mmap_sem);
|
||||
INIT_LIST_HEAD(&mm->mmlist);
|
||||
mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
|
||||
mm->oom_adj = (current->mm) ? current->mm->oom_adj : 0;
|
||||
mm->core_state = NULL;
|
||||
mm->nr_ptes = 0;
|
||||
set_mm_counter(mm, file_rss, 0);
|
||||
|
|
@ -568,18 +568,18 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
|
|||
* the value intact in a core dump, and to save the unnecessary
|
||||
* trouble otherwise. Userland only wants this done for a sys_exit.
|
||||
*/
|
||||
if (tsk->clear_child_tid
|
||||
&& !(tsk->flags & PF_SIGNALED)
|
||||
&& atomic_read(&mm->mm_users) > 1) {
|
||||
u32 __user * tidptr = tsk->clear_child_tid;
|
||||
if (tsk->clear_child_tid) {
|
||||
if (!(tsk->flags & PF_SIGNALED) &&
|
||||
atomic_read(&mm->mm_users) > 1) {
|
||||
/*
|
||||
* We don't check the error code - if userspace has
|
||||
* not set up a proper pointer then tough luck.
|
||||
*/
|
||||
put_user(0, tsk->clear_child_tid);
|
||||
sys_futex(tsk->clear_child_tid, FUTEX_WAKE,
|
||||
1, NULL, NULL, 0);
|
||||
}
|
||||
tsk->clear_child_tid = NULL;
|
||||
|
||||
/*
|
||||
* We don't check the error code - if userspace has
|
||||
* not set up a proper pointer then tough luck.
|
||||
*/
|
||||
put_user(0, tidptr);
|
||||
sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1269,6 +1269,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
|
|||
write_unlock_irq(&tasklist_lock);
|
||||
proc_fork_connector(p);
|
||||
cgroup_post_fork(p);
|
||||
perf_counter_fork(p);
|
||||
return p;
|
||||
|
||||
bad_fork_free_pid:
|
||||
|
|
@ -1408,12 +1409,6 @@ long do_fork(unsigned long clone_flags,
|
|||
if (clone_flags & CLONE_VFORK) {
|
||||
p->vfork_done = &vfork;
|
||||
init_completion(&vfork);
|
||||
} else if (!(clone_flags & CLONE_VM)) {
|
||||
/*
|
||||
* vfork will do an exec which will call
|
||||
* set_task_comm()
|
||||
*/
|
||||
perf_counter_fork(p);
|
||||
}
|
||||
|
||||
audit_finish_fork(p);
|
||||
|
|
|
|||
|
|
@ -44,12 +44,19 @@ void refrigerator(void)
|
|||
recalc_sigpending(); /* We sent fake signal, clean it up */
|
||||
spin_unlock_irq(¤t->sighand->siglock);
|
||||
|
||||
/* prevent accounting of that task to load */
|
||||
current->flags |= PF_FREEZING;
|
||||
|
||||
for (;;) {
|
||||
set_current_state(TASK_UNINTERRUPTIBLE);
|
||||
if (!frozen(current))
|
||||
break;
|
||||
schedule();
|
||||
}
|
||||
|
||||
/* Remove the accounting blocker */
|
||||
current->flags &= ~PF_FREEZING;
|
||||
|
||||
pr_debug("%s left refrigerator\n", current->comm);
|
||||
__set_current_state(save);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ again:
|
|||
if (err < 0)
|
||||
return err;
|
||||
|
||||
page = compound_head(page);
|
||||
lock_page(page);
|
||||
if (!page->mapping) {
|
||||
unlock_page(page);
|
||||
|
|
@ -284,6 +285,25 @@ void put_futex_key(int fshared, union futex_key *key)
|
|||
drop_futex_key_refs(key);
|
||||
}
|
||||
|
||||
/*
|
||||
* fault_in_user_writeable - fault in user address and verify RW access
|
||||
* @uaddr: pointer to faulting user space address
|
||||
*
|
||||
* Slow path to fixup the fault we just took in the atomic write
|
||||
* access to @uaddr.
|
||||
*
|
||||
* We have no generic implementation of a non destructive write to the
|
||||
* user address. We know that we faulted in the atomic pagefault
|
||||
* disabled section so we can as well avoid the #PF overhead by
|
||||
* calling get_user_pages() right away.
|
||||
*/
|
||||
static int fault_in_user_writeable(u32 __user *uaddr)
|
||||
{
|
||||
int ret = get_user_pages(current, current->mm, (unsigned long)uaddr,
|
||||
1, 1, 0, NULL, NULL);
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* futex_top_waiter() - Return the highest priority waiter on a futex
|
||||
* @hb: the hash bucket the futex_q's reside in
|
||||
|
|
@ -896,7 +916,6 @@ retry:
|
|||
retry_private:
|
||||
op_ret = futex_atomic_op_inuser(op, uaddr2);
|
||||
if (unlikely(op_ret < 0)) {
|
||||
u32 dummy;
|
||||
|
||||
double_unlock_hb(hb1, hb2);
|
||||
|
||||
|
|
@ -914,7 +933,7 @@ retry_private:
|
|||
goto out_put_keys;
|
||||
}
|
||||
|
||||
ret = get_user(dummy, uaddr2);
|
||||
ret = fault_in_user_writeable(uaddr2);
|
||||
if (ret)
|
||||
goto out_put_keys;
|
||||
|
||||
|
|
@ -991,15 +1010,19 @@ void requeue_futex(struct futex_q *q, struct futex_hash_bucket *hb1,
|
|||
* requeue_pi_wake_futex() - Wake a task that acquired the lock during requeue
|
||||
* q: the futex_q
|
||||
* key: the key of the requeue target futex
|
||||
* hb: the hash_bucket of the requeue target futex
|
||||
*
|
||||
* During futex_requeue, with requeue_pi=1, it is possible to acquire the
|
||||
* target futex if it is uncontended or via a lock steal. Set the futex_q key
|
||||
* to the requeue target futex so the waiter can detect the wakeup on the right
|
||||
* futex, but remove it from the hb and NULL the rt_waiter so it can detect
|
||||
* atomic lock acquisition. Must be called with the q->lock_ptr held.
|
||||
* atomic lock acquisition. Set the q->lock_ptr to the requeue target hb->lock
|
||||
* to protect access to the pi_state to fixup the owner later. Must be called
|
||||
* with both q->lock_ptr and hb->lock held.
|
||||
*/
|
||||
static inline
|
||||
void requeue_pi_wake_futex(struct futex_q *q, union futex_key *key)
|
||||
void requeue_pi_wake_futex(struct futex_q *q, union futex_key *key,
|
||||
struct futex_hash_bucket *hb)
|
||||
{
|
||||
drop_futex_key_refs(&q->key);
|
||||
get_futex_key_refs(key);
|
||||
|
|
@ -1011,6 +1034,11 @@ void requeue_pi_wake_futex(struct futex_q *q, union futex_key *key)
|
|||
WARN_ON(!q->rt_waiter);
|
||||
q->rt_waiter = NULL;
|
||||
|
||||
q->lock_ptr = &hb->lock;
|
||||
#ifdef CONFIG_DEBUG_PI_LIST
|
||||
q->list.plist.lock = &hb->lock;
|
||||
#endif
|
||||
|
||||
wake_up_state(q->task, TASK_NORMAL);
|
||||
}
|
||||
|
||||
|
|
@ -1069,7 +1097,7 @@ static int futex_proxy_trylock_atomic(u32 __user *pifutex,
|
|||
ret = futex_lock_pi_atomic(pifutex, hb2, key2, ps, top_waiter->task,
|
||||
set_waiters);
|
||||
if (ret == 1)
|
||||
requeue_pi_wake_futex(top_waiter, key2);
|
||||
requeue_pi_wake_futex(top_waiter, key2, hb2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1204,7 +1232,7 @@ retry_private:
|
|||
double_unlock_hb(hb1, hb2);
|
||||
put_futex_key(fshared, &key2);
|
||||
put_futex_key(fshared, &key1);
|
||||
ret = get_user(curval2, uaddr2);
|
||||
ret = fault_in_user_writeable(uaddr2);
|
||||
if (!ret)
|
||||
goto retry;
|
||||
goto out;
|
||||
|
|
@ -1228,8 +1256,15 @@ retry_private:
|
|||
if (!match_futex(&this->key, &key1))
|
||||
continue;
|
||||
|
||||
WARN_ON(!requeue_pi && this->rt_waiter);
|
||||
WARN_ON(requeue_pi && !this->rt_waiter);
|
||||
/*
|
||||
* FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
|
||||
* be paired with each other and no other futex ops.
|
||||
*/
|
||||
if ((requeue_pi && !this->rt_waiter) ||
|
||||
(!requeue_pi && this->rt_waiter)) {
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wake nr_wake waiters. For requeue_pi, if we acquired the
|
||||
|
|
@ -1254,7 +1289,7 @@ retry_private:
|
|||
this->task, 1);
|
||||
if (ret == 1) {
|
||||
/* We got the lock. */
|
||||
requeue_pi_wake_futex(this, &key2);
|
||||
requeue_pi_wake_futex(this, &key2, hb2);
|
||||
continue;
|
||||
} else if (ret) {
|
||||
/* -EDEADLK */
|
||||
|
|
@ -1482,7 +1517,7 @@ retry:
|
|||
handle_fault:
|
||||
spin_unlock(q->lock_ptr);
|
||||
|
||||
ret = get_user(uval, uaddr);
|
||||
ret = fault_in_user_writeable(uaddr);
|
||||
|
||||
spin_lock(q->lock_ptr);
|
||||
|
||||
|
|
@ -1807,7 +1842,6 @@ static int futex_lock_pi(u32 __user *uaddr, int fshared,
|
|||
{
|
||||
struct hrtimer_sleeper timeout, *to = NULL;
|
||||
struct futex_hash_bucket *hb;
|
||||
u32 uval;
|
||||
struct futex_q q;
|
||||
int res, ret;
|
||||
|
||||
|
|
@ -1909,16 +1943,9 @@ out:
|
|||
return ret != -EINTR ? ret : -ERESTARTNOINTR;
|
||||
|
||||
uaddr_faulted:
|
||||
/*
|
||||
* We have to r/w *(int __user *)uaddr, and we have to modify it
|
||||
* atomically. Therefore, if we continue to fault after get_user()
|
||||
* below, we need to handle the fault ourselves, while still holding
|
||||
* the mmap_sem. This can occur if the uaddr is under contention as
|
||||
* we have to drop the mmap_sem in order to call get_user().
|
||||
*/
|
||||
queue_unlock(&q, hb);
|
||||
|
||||
ret = get_user(uval, uaddr);
|
||||
ret = fault_in_user_writeable(uaddr);
|
||||
if (ret)
|
||||
goto out_put_key;
|
||||
|
||||
|
|
@ -2013,17 +2040,10 @@ out:
|
|||
return ret;
|
||||
|
||||
pi_faulted:
|
||||
/*
|
||||
* We have to r/w *(int __user *)uaddr, and we have to modify it
|
||||
* atomically. Therefore, if we continue to fault after get_user()
|
||||
* below, we need to handle the fault ourselves, while still holding
|
||||
* the mmap_sem. This can occur if the uaddr is under contention as
|
||||
* we have to drop the mmap_sem in order to call get_user().
|
||||
*/
|
||||
spin_unlock(&hb->lock);
|
||||
put_futex_key(fshared, &key);
|
||||
|
||||
ret = get_user(uval, uaddr);
|
||||
ret = fault_in_user_writeable(uaddr);
|
||||
if (!ret)
|
||||
goto retry;
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,8 @@ asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
|
|||
int cmd = op & FUTEX_CMD_MASK;
|
||||
|
||||
if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
|
||||
cmd == FUTEX_WAIT_BITSET)) {
|
||||
cmd == FUTEX_WAIT_BITSET ||
|
||||
cmd == FUTEX_WAIT_REQUEUE_PI)) {
|
||||
if (get_compat_timespec(&ts, utime))
|
||||
return -EFAULT;
|
||||
if (!timespec_valid(&ts))
|
||||
|
|
@ -191,7 +192,8 @@ asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
|
|||
t = ktime_add_safe(ktime_get(), t);
|
||||
tp = &t;
|
||||
}
|
||||
if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE)
|
||||
if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
|
||||
cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
|
||||
val2 = (int) (unsigned long) utime;
|
||||
|
||||
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
|
||||
|
|
|
|||
110
kernel/hrtimer.c
110
kernel/hrtimer.c
|
|
@ -191,6 +191,46 @@ struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the preferred target CPU for NOHZ
|
||||
*/
|
||||
static int hrtimer_get_target(int this_cpu, int pinned)
|
||||
{
|
||||
#ifdef CONFIG_NO_HZ
|
||||
if (!pinned && get_sysctl_timer_migration() && idle_cpu(this_cpu)) {
|
||||
int preferred_cpu = get_nohz_load_balancer();
|
||||
|
||||
if (preferred_cpu >= 0)
|
||||
return preferred_cpu;
|
||||
}
|
||||
#endif
|
||||
return this_cpu;
|
||||
}
|
||||
|
||||
/*
|
||||
* With HIGHRES=y we do not migrate the timer when it is expiring
|
||||
* before the next event on the target cpu because we cannot reprogram
|
||||
* the target cpu hardware and we would cause it to fire late.
|
||||
*
|
||||
* Called with cpu_base->lock of target cpu held.
|
||||
*/
|
||||
static int
|
||||
hrtimer_check_target(struct hrtimer *timer, struct hrtimer_clock_base *new_base)
|
||||
{
|
||||
#ifdef CONFIG_HIGH_RES_TIMERS
|
||||
ktime_t expires;
|
||||
|
||||
if (!new_base->cpu_base->hres_active)
|
||||
return 0;
|
||||
|
||||
expires = ktime_sub(hrtimer_get_expires(timer), new_base->offset);
|
||||
return expires.tv64 <= new_base->cpu_base->expires_next.tv64;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch the timer base to the current CPU when possible.
|
||||
*/
|
||||
|
|
@ -200,16 +240,8 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,
|
|||
{
|
||||
struct hrtimer_clock_base *new_base;
|
||||
struct hrtimer_cpu_base *new_cpu_base;
|
||||
int cpu, preferred_cpu = -1;
|
||||
|
||||
cpu = smp_processor_id();
|
||||
#if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
|
||||
if (!pinned && get_sysctl_timer_migration() && idle_cpu(cpu)) {
|
||||
preferred_cpu = get_nohz_load_balancer();
|
||||
if (preferred_cpu >= 0)
|
||||
cpu = preferred_cpu;
|
||||
}
|
||||
#endif
|
||||
int this_cpu = smp_processor_id();
|
||||
int cpu = hrtimer_get_target(this_cpu, pinned);
|
||||
|
||||
again:
|
||||
new_cpu_base = &per_cpu(hrtimer_bases, cpu);
|
||||
|
|
@ -217,7 +249,7 @@ again:
|
|||
|
||||
if (base != new_base) {
|
||||
/*
|
||||
* We are trying to schedule the timer on the local CPU.
|
||||
* We are trying to move timer to new_base.
|
||||
* However we can't change timer's base while it is running,
|
||||
* so we keep it on the same CPU. No hassle vs. reprogramming
|
||||
* the event source in the high resolution case. The softirq
|
||||
|
|
@ -233,38 +265,12 @@ again:
|
|||
spin_unlock(&base->cpu_base->lock);
|
||||
spin_lock(&new_base->cpu_base->lock);
|
||||
|
||||
/* Optimized away for NOHZ=n SMP=n */
|
||||
if (cpu == preferred_cpu) {
|
||||
/* Calculate clock monotonic expiry time */
|
||||
#ifdef CONFIG_HIGH_RES_TIMERS
|
||||
ktime_t expires = ktime_sub(hrtimer_get_expires(timer),
|
||||
new_base->offset);
|
||||
#else
|
||||
ktime_t expires = hrtimer_get_expires(timer);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get the next event on target cpu from the
|
||||
* clock events layer.
|
||||
* This covers the highres=off nohz=on case as well.
|
||||
*/
|
||||
ktime_t next = clockevents_get_next_event(cpu);
|
||||
|
||||
ktime_t delta = ktime_sub(expires, next);
|
||||
|
||||
/*
|
||||
* We do not migrate the timer when it is expiring
|
||||
* before the next event on the target cpu because
|
||||
* we cannot reprogram the target cpu hardware and
|
||||
* we would cause it to fire late.
|
||||
*/
|
||||
if (delta.tv64 < 0) {
|
||||
cpu = smp_processor_id();
|
||||
spin_unlock(&new_base->cpu_base->lock);
|
||||
spin_lock(&base->cpu_base->lock);
|
||||
timer->base = base;
|
||||
goto again;
|
||||
}
|
||||
if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
|
||||
cpu = this_cpu;
|
||||
spin_unlock(&new_base->cpu_base->lock);
|
||||
spin_lock(&base->cpu_base->lock);
|
||||
timer->base = base;
|
||||
goto again;
|
||||
}
|
||||
timer->base = new_base;
|
||||
}
|
||||
|
|
@ -1276,14 +1282,22 @@ void hrtimer_interrupt(struct clock_event_device *dev)
|
|||
|
||||
expires_next.tv64 = KTIME_MAX;
|
||||
|
||||
spin_lock(&cpu_base->lock);
|
||||
/*
|
||||
* We set expires_next to KTIME_MAX here with cpu_base->lock
|
||||
* held to prevent that a timer is enqueued in our queue via
|
||||
* the migration code. This does not affect enqueueing of
|
||||
* timers which run their callback and need to be requeued on
|
||||
* this CPU.
|
||||
*/
|
||||
cpu_base->expires_next.tv64 = KTIME_MAX;
|
||||
|
||||
base = cpu_base->clock_base;
|
||||
|
||||
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
|
||||
ktime_t basenow;
|
||||
struct rb_node *node;
|
||||
|
||||
spin_lock(&cpu_base->lock);
|
||||
|
||||
basenow = ktime_add(now, base->offset);
|
||||
|
||||
while ((node = base->first)) {
|
||||
|
|
@ -1316,11 +1330,15 @@ void hrtimer_interrupt(struct clock_event_device *dev)
|
|||
|
||||
__run_hrtimer(timer);
|
||||
}
|
||||
spin_unlock(&cpu_base->lock);
|
||||
base++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Store the new expiry value so the migration code can verify
|
||||
* against it.
|
||||
*/
|
||||
cpu_base->expires_next = expires_next;
|
||||
spin_unlock(&cpu_base->lock);
|
||||
|
||||
/* Reprogramming necessary ? */
|
||||
if (expires_next.tv64 != KTIME_MAX) {
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ static inline void unregister_handler_proc(unsigned int irq,
|
|||
|
||||
extern int irq_select_affinity_usr(unsigned int irq);
|
||||
|
||||
extern void
|
||||
irq_set_thread_affinity(struct irq_desc *desc, const struct cpumask *cpumask);
|
||||
extern void irq_set_thread_affinity(struct irq_desc *desc);
|
||||
|
||||
/*
|
||||
* Debugging printout:
|
||||
|
|
|
|||
|
|
@ -80,14 +80,22 @@ int irq_can_set_affinity(unsigned int irq)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
irq_set_thread_affinity(struct irq_desc *desc, const struct cpumask *cpumask)
|
||||
/**
|
||||
* irq_set_thread_affinity - Notify irq threads to adjust affinity
|
||||
* @desc: irq descriptor which has affitnity changed
|
||||
*
|
||||
* We just set IRQTF_AFFINITY and delegate the affinity setting
|
||||
* to the interrupt thread itself. We can not call
|
||||
* set_cpus_allowed_ptr() here as we hold desc->lock and this
|
||||
* code can be called from hard interrupt context.
|
||||
*/
|
||||
void irq_set_thread_affinity(struct irq_desc *desc)
|
||||
{
|
||||
struct irqaction *action = desc->action;
|
||||
|
||||
while (action) {
|
||||
if (action->thread)
|
||||
set_cpus_allowed_ptr(action->thread, cpumask);
|
||||
set_bit(IRQTF_AFFINITY, &action->thread_flags);
|
||||
action = action->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +120,7 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
|
|||
if (desc->status & IRQ_MOVE_PCNTXT) {
|
||||
if (!desc->chip->set_affinity(irq, cpumask)) {
|
||||
cpumask_copy(desc->affinity, cpumask);
|
||||
irq_set_thread_affinity(desc, cpumask);
|
||||
irq_set_thread_affinity(desc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -122,7 +130,7 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
|
|||
#else
|
||||
if (!desc->chip->set_affinity(irq, cpumask)) {
|
||||
cpumask_copy(desc->affinity, cpumask);
|
||||
irq_set_thread_affinity(desc, cpumask);
|
||||
irq_set_thread_affinity(desc);
|
||||
}
|
||||
#endif
|
||||
desc->status |= IRQ_AFFINITY_SET;
|
||||
|
|
@ -176,7 +184,7 @@ int irq_select_affinity_usr(unsigned int irq)
|
|||
spin_lock_irqsave(&desc->lock, flags);
|
||||
ret = setup_affinity(irq, desc);
|
||||
if (!ret)
|
||||
irq_set_thread_affinity(desc, desc->affinity);
|
||||
irq_set_thread_affinity(desc);
|
||||
spin_unlock_irqrestore(&desc->lock, flags);
|
||||
|
||||
return ret;
|
||||
|
|
@ -443,6 +451,39 @@ static int irq_wait_for_interrupt(struct irqaction *action)
|
|||
return -1;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
/*
|
||||
* Check whether we need to change the affinity of the interrupt thread.
|
||||
*/
|
||||
static void
|
||||
irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action)
|
||||
{
|
||||
cpumask_var_t mask;
|
||||
|
||||
if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags))
|
||||
return;
|
||||
|
||||
/*
|
||||
* In case we are out of memory we set IRQTF_AFFINITY again and
|
||||
* try again next time
|
||||
*/
|
||||
if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
|
||||
set_bit(IRQTF_AFFINITY, &action->thread_flags);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_lock_irq(&desc->lock);
|
||||
cpumask_copy(mask, desc->affinity);
|
||||
spin_unlock_irq(&desc->lock);
|
||||
|
||||
set_cpus_allowed_ptr(current, mask);
|
||||
free_cpumask_var(mask);
|
||||
}
|
||||
#else
|
||||
static inline void
|
||||
irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action) { }
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Interrupt handler thread
|
||||
*/
|
||||
|
|
@ -458,6 +499,8 @@ static int irq_thread(void *data)
|
|||
|
||||
while (!irq_wait_for_interrupt(action)) {
|
||||
|
||||
irq_thread_check_affinity(desc, action);
|
||||
|
||||
atomic_inc(&desc->threads_active);
|
||||
|
||||
spin_lock_irq(&desc->lock);
|
||||
|
|
@ -718,7 +761,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
|
|||
{
|
||||
struct irq_desc *desc = irq_to_desc(irq);
|
||||
struct irqaction *action, **action_ptr;
|
||||
struct task_struct *irqthread;
|
||||
unsigned long flags;
|
||||
|
||||
WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
|
||||
|
|
@ -766,9 +808,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
|
|||
desc->chip->disable(irq);
|
||||
}
|
||||
|
||||
irqthread = action->thread;
|
||||
action->thread = NULL;
|
||||
|
||||
spin_unlock_irqrestore(&desc->lock, flags);
|
||||
|
||||
unregister_handler_proc(irq, action);
|
||||
|
|
@ -776,12 +815,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
|
|||
/* Make sure it's not being used on another CPU: */
|
||||
synchronize_irq(irq);
|
||||
|
||||
if (irqthread) {
|
||||
if (!test_bit(IRQTF_DIED, &action->thread_flags))
|
||||
kthread_stop(irqthread);
|
||||
put_task_struct(irqthread);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_SHIRQ
|
||||
/*
|
||||
* It's a shared IRQ -- the driver ought to be prepared for an IRQ
|
||||
|
|
@ -797,6 +830,13 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
|
|||
local_irq_restore(flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (action->thread) {
|
||||
if (!test_bit(IRQTF_DIED, &action->thread_flags))
|
||||
kthread_stop(action->thread);
|
||||
put_task_struct(action->thread);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ void move_masked_irq(int irq)
|
|||
< nr_cpu_ids))
|
||||
if (!desc->chip->set_affinity(irq, desc->pending_mask)) {
|
||||
cpumask_copy(desc->affinity, desc->pending_mask);
|
||||
irq_set_thread_affinity(desc, desc->pending_mask);
|
||||
irq_set_thread_affinity(desc);
|
||||
}
|
||||
|
||||
cpumask_clear(desc->pending_mask);
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ out_unlock:
|
|||
|
||||
struct irq_desc *move_irq_desc(struct irq_desc *desc, int node)
|
||||
{
|
||||
/* those all static, do move them */
|
||||
if (desc->irq < NR_IRQS_LEGACY)
|
||||
/* those static or target node is -1, do not move them */
|
||||
if (desc->irq < NR_IRQS_LEGACY || node == -1)
|
||||
return desc;
|
||||
|
||||
if (desc->node != node)
|
||||
|
|
|
|||
|
|
@ -1228,7 +1228,7 @@ static int __init parse_crashkernel_mem(char *cmdline,
|
|||
} while (*cur++ == ',');
|
||||
|
||||
if (*crash_size > 0) {
|
||||
while (*cur != ' ' && *cur != '@')
|
||||
while (*cur && *cur != ' ' && *cur != '@')
|
||||
cur++;
|
||||
if (*cur == '@') {
|
||||
cur++;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include <linux/unistd.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/mnt_namespace.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/fdtable.h>
|
||||
|
|
|
|||
|
|
@ -237,13 +237,9 @@ static int __kprobes collect_garbage_slots(void)
|
|||
{
|
||||
struct kprobe_insn_page *kip;
|
||||
struct hlist_node *pos, *next;
|
||||
int safety;
|
||||
|
||||
/* Ensure no-one is preepmted on the garbages */
|
||||
mutex_unlock(&kprobe_insn_mutex);
|
||||
safety = check_safety();
|
||||
mutex_lock(&kprobe_insn_mutex);
|
||||
if (safety != 0)
|
||||
if (check_safety())
|
||||
return -EAGAIN;
|
||||
|
||||
hlist_for_each_entry_safe(kip, pos, next, &kprobe_insn_pages, hlist) {
|
||||
|
|
@ -698,7 +694,7 @@ int __kprobes register_kprobe(struct kprobe *p)
|
|||
p->addr = addr;
|
||||
|
||||
preempt_disable();
|
||||
if (!__kernel_text_address((unsigned long) p->addr) ||
|
||||
if (!kernel_text_address((unsigned long) p->addr) ||
|
||||
in_kprobes_functions((unsigned long) p->addr)) {
|
||||
preempt_enable();
|
||||
return -EINVAL;
|
||||
|
|
|
|||
|
|
@ -180,10 +180,12 @@ EXPORT_SYMBOL(kthread_bind);
|
|||
* @k: thread created by kthread_create().
|
||||
*
|
||||
* Sets kthread_should_stop() for @k to return true, wakes it, and
|
||||
* waits for it to exit. Your threadfn() must not call do_exit()
|
||||
* itself if you use this function! This can also be called after
|
||||
* kthread_create() instead of calling wake_up_process(): the thread
|
||||
* will exit without calling threadfn().
|
||||
* waits for it to exit. This can also be called after kthread_create()
|
||||
* instead of calling wake_up_process(): the thread will exit without
|
||||
* calling threadfn().
|
||||
*
|
||||
* If threadfn() may call do_exit() itself, the caller must ensure
|
||||
* task_struct can't go away.
|
||||
*
|
||||
* Returns the result of threadfn(), or %-EINTR if wake_up_process()
|
||||
* was never called.
|
||||
|
|
|
|||
|
|
@ -758,7 +758,8 @@ static int __init lockdep_proc_init(void)
|
|||
&proc_lockdep_stats_operations);
|
||||
|
||||
#ifdef CONFIG_LOCK_STAT
|
||||
proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
|
||||
proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL,
|
||||
&proc_lock_stat_operations);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1068,7 +1068,8 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
|
|||
{
|
||||
const unsigned long *crc;
|
||||
|
||||
if (!find_symbol("module_layout", NULL, &crc, true, false))
|
||||
if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL,
|
||||
&crc, true, false))
|
||||
BUG();
|
||||
return check_version(sechdrs, versindex, "module_layout", mod, crc);
|
||||
}
|
||||
|
|
@ -2451,9 +2452,9 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
|
|||
return ret;
|
||||
}
|
||||
if (ret > 0) {
|
||||
printk(KERN_WARNING "%s: '%s'->init suspiciously returned %d, "
|
||||
"it should follow 0/-E convention\n"
|
||||
KERN_WARNING "%s: loading module anyway...\n",
|
||||
printk(KERN_WARNING
|
||||
"%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n"
|
||||
"%s: loading module anyway...\n",
|
||||
__func__, mod->name, ret,
|
||||
__func__);
|
||||
dump_stack();
|
||||
|
|
|
|||
|
|
@ -301,6 +301,7 @@ int oops_may_print(void)
|
|||
*/
|
||||
void oops_enter(void)
|
||||
{
|
||||
tracing_off();
|
||||
/* can't trust the integrity of the kernel anymore: */
|
||||
debug_locks_off();
|
||||
do_oops_enter_exit();
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -521,11 +521,12 @@ void posix_cpu_timers_exit(struct task_struct *tsk)
|
|||
}
|
||||
void posix_cpu_timers_exit_group(struct task_struct *tsk)
|
||||
{
|
||||
struct task_cputime cputime;
|
||||
struct signal_struct *const sig = tsk->signal;
|
||||
|
||||
thread_group_cputimer(tsk, &cputime);
|
||||
cleanup_timers(tsk->signal->cpu_timers,
|
||||
cputime.utime, cputime.stime, cputime.sum_exec_runtime);
|
||||
cputime_add(tsk->utime, sig->utime),
|
||||
cputime_add(tsk->stime, sig->stime),
|
||||
tsk->se.sum_exec_runtime + sig->sum_sched_runtime);
|
||||
}
|
||||
|
||||
static void clear_dead_task(struct k_itimer *timer, union cpu_time_count now)
|
||||
|
|
|
|||
|
|
@ -202,6 +202,12 @@ static int no_timer_create(struct k_itimer *new_timer)
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static int no_nsleep(const clockid_t which_clock, int flags,
|
||||
struct timespec *tsave, struct timespec __user *rmtp)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return nonzero if we know a priori this clockid_t value is bogus.
|
||||
*/
|
||||
|
|
@ -254,6 +260,7 @@ static __init int init_posix_timers(void)
|
|||
.clock_get = posix_get_monotonic_raw,
|
||||
.clock_set = do_posix_clock_nosettime,
|
||||
.timer_create = no_timer_create,
|
||||
.nsleep = no_nsleep,
|
||||
};
|
||||
|
||||
register_posix_clock(CLOCK_REALTIME, &clock_realtime);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <linux/console.h>
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <scsi/scsi_scan.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
|
|
|||
|
|
@ -117,11 +117,12 @@ int __ref profile_init(void)
|
|||
|
||||
cpumask_copy(prof_cpu_mask, cpu_possible_mask);
|
||||
|
||||
prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL);
|
||||
prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL|__GFP_NOWARN);
|
||||
if (prof_buffer)
|
||||
return 0;
|
||||
|
||||
prof_buffer = alloc_pages_exact(buffer_bytes, GFP_KERNEL|__GFP_ZERO);
|
||||
prof_buffer = alloc_pages_exact(buffer_bytes,
|
||||
GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN);
|
||||
if (prof_buffer)
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -181,8 +181,8 @@ int ptrace_attach(struct task_struct *task)
|
|||
* interference; SUID, SGID and LSM creds get determined differently
|
||||
* under ptrace.
|
||||
*/
|
||||
retval = mutex_lock_interruptible(&task->cred_guard_mutex);
|
||||
if (retval < 0)
|
||||
retval = -ERESTARTNOINTR;
|
||||
if (mutex_lock_interruptible(&task->cred_guard_mutex))
|
||||
goto out;
|
||||
|
||||
task_lock(task);
|
||||
|
|
|
|||
|
|
@ -787,7 +787,7 @@ static int __init reserve_setup(char *str)
|
|||
static struct resource reserve[MAXRESERVE];
|
||||
|
||||
for (;;) {
|
||||
int io_start, io_num;
|
||||
unsigned int io_start, io_num;
|
||||
int x = reserved;
|
||||
|
||||
if (get_option (&str, &io_start) != 2)
|
||||
|
|
|
|||
|
|
@ -1039,16 +1039,14 @@ int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
|
|||
if (!rt_mutex_owner(lock) || try_to_steal_lock(lock, task)) {
|
||||
/* We got the lock for task. */
|
||||
debug_rt_mutex_lock(lock);
|
||||
|
||||
rt_mutex_set_owner(lock, task, 0);
|
||||
|
||||
spin_unlock(&lock->wait_lock);
|
||||
rt_mutex_deadlock_account_lock(lock, task);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = task_blocks_on_rt_mutex(lock, waiter, task, detect_deadlock);
|
||||
|
||||
|
||||
if (ret && !waiter->task) {
|
||||
/*
|
||||
* Reset the return value. We might have
|
||||
|
|
|
|||
|
|
@ -493,6 +493,7 @@ struct rt_rq {
|
|||
#endif
|
||||
#ifdef CONFIG_SMP
|
||||
unsigned long rt_nr_migratory;
|
||||
unsigned long rt_nr_total;
|
||||
int overloaded;
|
||||
struct plist_head pushable_tasks;
|
||||
#endif
|
||||
|
|
@ -2571,15 +2572,37 @@ static void __sched_fork(struct task_struct *p)
|
|||
p->se.avg_wakeup = sysctl_sched_wakeup_granularity;
|
||||
|
||||
#ifdef CONFIG_SCHEDSTATS
|
||||
p->se.wait_start = 0;
|
||||
p->se.sum_sleep_runtime = 0;
|
||||
p->se.sleep_start = 0;
|
||||
p->se.block_start = 0;
|
||||
p->se.sleep_max = 0;
|
||||
p->se.block_max = 0;
|
||||
p->se.exec_max = 0;
|
||||
p->se.slice_max = 0;
|
||||
p->se.wait_max = 0;
|
||||
p->se.wait_start = 0;
|
||||
p->se.wait_max = 0;
|
||||
p->se.wait_count = 0;
|
||||
p->se.wait_sum = 0;
|
||||
|
||||
p->se.sleep_start = 0;
|
||||
p->se.sleep_max = 0;
|
||||
p->se.sum_sleep_runtime = 0;
|
||||
|
||||
p->se.block_start = 0;
|
||||
p->se.block_max = 0;
|
||||
p->se.exec_max = 0;
|
||||
p->se.slice_max = 0;
|
||||
|
||||
p->se.nr_migrations_cold = 0;
|
||||
p->se.nr_failed_migrations_affine = 0;
|
||||
p->se.nr_failed_migrations_running = 0;
|
||||
p->se.nr_failed_migrations_hot = 0;
|
||||
p->se.nr_forced_migrations = 0;
|
||||
p->se.nr_forced2_migrations = 0;
|
||||
|
||||
p->se.nr_wakeups = 0;
|
||||
p->se.nr_wakeups_sync = 0;
|
||||
p->se.nr_wakeups_migrate = 0;
|
||||
p->se.nr_wakeups_local = 0;
|
||||
p->se.nr_wakeups_remote = 0;
|
||||
p->se.nr_wakeups_affine = 0;
|
||||
p->se.nr_wakeups_affine_attempts = 0;
|
||||
p->se.nr_wakeups_passive = 0;
|
||||
p->se.nr_wakeups_idle = 0;
|
||||
|
||||
#endif
|
||||
|
||||
INIT_LIST_HEAD(&p->rt.run_list);
|
||||
|
|
@ -6541,6 +6564,11 @@ SYSCALL_DEFINE0(sched_yield)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline int should_resched(void)
|
||||
{
|
||||
return need_resched() && !(preempt_count() & PREEMPT_ACTIVE);
|
||||
}
|
||||
|
||||
static void __cond_resched(void)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
|
||||
|
|
@ -6560,8 +6588,7 @@ static void __cond_resched(void)
|
|||
|
||||
int __sched _cond_resched(void)
|
||||
{
|
||||
if (need_resched() && !(preempt_count() & PREEMPT_ACTIVE) &&
|
||||
system_state == SYSTEM_RUNNING) {
|
||||
if (should_resched()) {
|
||||
__cond_resched();
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -6579,12 +6606,12 @@ EXPORT_SYMBOL(_cond_resched);
|
|||
*/
|
||||
int cond_resched_lock(spinlock_t *lock)
|
||||
{
|
||||
int resched = need_resched() && system_state == SYSTEM_RUNNING;
|
||||
int resched = should_resched();
|
||||
int ret = 0;
|
||||
|
||||
if (spin_needbreak(lock) || resched) {
|
||||
spin_unlock(lock);
|
||||
if (resched && need_resched())
|
||||
if (resched)
|
||||
__cond_resched();
|
||||
else
|
||||
cpu_relax();
|
||||
|
|
@ -6599,7 +6626,7 @@ int __sched cond_resched_softirq(void)
|
|||
{
|
||||
BUG_ON(!in_softirq());
|
||||
|
||||
if (need_resched() && system_state == SYSTEM_RUNNING) {
|
||||
if (should_resched()) {
|
||||
local_bh_enable();
|
||||
__cond_resched();
|
||||
local_bh_disable();
|
||||
|
|
@ -7277,6 +7304,7 @@ static void migrate_dead_tasks(unsigned int dead_cpu)
|
|||
static void calc_global_load_remove(struct rq *rq)
|
||||
{
|
||||
atomic_long_sub(rq->calc_load_active, &calc_load_tasks);
|
||||
rq->calc_load_active = 0;
|
||||
}
|
||||
#endif /* CONFIG_HOTPLUG_CPU */
|
||||
|
||||
|
|
@ -7503,6 +7531,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
|||
task_rq_unlock(rq, &flags);
|
||||
get_task_struct(p);
|
||||
cpu_rq(cpu)->migration_thread = p;
|
||||
rq->calc_load_update = calc_load_update;
|
||||
break;
|
||||
|
||||
case CPU_ONLINE:
|
||||
|
|
@ -7513,8 +7542,6 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
|||
/* Update our root-domain */
|
||||
rq = cpu_rq(cpu);
|
||||
spin_lock_irqsave(&rq->lock, flags);
|
||||
rq->calc_load_update = calc_load_update;
|
||||
rq->calc_load_active = 0;
|
||||
if (rq->rd) {
|
||||
BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
|
||||
|
||||
|
|
@ -9085,7 +9112,7 @@ static void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq)
|
|||
#ifdef CONFIG_SMP
|
||||
rt_rq->rt_nr_migratory = 0;
|
||||
rt_rq->overloaded = 0;
|
||||
plist_head_init(&rq->rt.pushable_tasks, &rq->lock);
|
||||
plist_head_init(&rt_rq->pushable_tasks, &rq->lock);
|
||||
#endif
|
||||
|
||||
rt_rq->rt_time = 0;
|
||||
|
|
|
|||
|
|
@ -81,8 +81,21 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p,
|
|||
if (cpumask_any_and(&p->cpus_allowed, vec->mask) >= nr_cpu_ids)
|
||||
continue;
|
||||
|
||||
if (lowest_mask)
|
||||
if (lowest_mask) {
|
||||
cpumask_and(lowest_mask, &p->cpus_allowed, vec->mask);
|
||||
|
||||
/*
|
||||
* We have to ensure that we have at least one bit
|
||||
* still set in the array, since the map could have
|
||||
* been concurrently emptied between the first and
|
||||
* second reads of vec->mask. If we hit this
|
||||
* condition, simply act as though we never hit this
|
||||
* priority level and continue on.
|
||||
*/
|
||||
if (cpumask_any(lowest_mask) >= nr_cpu_ids)
|
||||
continue;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -266,6 +266,12 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
|
|||
return min_vruntime;
|
||||
}
|
||||
|
||||
static inline int entity_before(struct sched_entity *a,
|
||||
struct sched_entity *b)
|
||||
{
|
||||
return (s64)(a->vruntime - b->vruntime) < 0;
|
||||
}
|
||||
|
||||
static inline s64 entity_key(struct cfs_rq *cfs_rq, struct sched_entity *se)
|
||||
{
|
||||
return se->vruntime - cfs_rq->min_vruntime;
|
||||
|
|
@ -605,9 +611,13 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
|
|||
static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
|
||||
{
|
||||
#ifdef CONFIG_SCHEDSTATS
|
||||
struct task_struct *tsk = NULL;
|
||||
|
||||
if (entity_is_task(se))
|
||||
tsk = task_of(se);
|
||||
|
||||
if (se->sleep_start) {
|
||||
u64 delta = rq_of(cfs_rq)->clock - se->sleep_start;
|
||||
struct task_struct *tsk = task_of(se);
|
||||
|
||||
if ((s64)delta < 0)
|
||||
delta = 0;
|
||||
|
|
@ -618,11 +628,11 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
|
|||
se->sleep_start = 0;
|
||||
se->sum_sleep_runtime += delta;
|
||||
|
||||
account_scheduler_latency(tsk, delta >> 10, 1);
|
||||
if (tsk)
|
||||
account_scheduler_latency(tsk, delta >> 10, 1);
|
||||
}
|
||||
if (se->block_start) {
|
||||
u64 delta = rq_of(cfs_rq)->clock - se->block_start;
|
||||
struct task_struct *tsk = task_of(se);
|
||||
|
||||
if ((s64)delta < 0)
|
||||
delta = 0;
|
||||
|
|
@ -633,17 +643,19 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
|
|||
se->block_start = 0;
|
||||
se->sum_sleep_runtime += delta;
|
||||
|
||||
/*
|
||||
* Blocking time is in units of nanosecs, so shift by 20 to
|
||||
* get a milliseconds-range estimation of the amount of
|
||||
* time that the task spent sleeping:
|
||||
*/
|
||||
if (unlikely(prof_on == SLEEP_PROFILING)) {
|
||||
|
||||
profile_hits(SLEEP_PROFILING, (void *)get_wchan(tsk),
|
||||
delta >> 20);
|
||||
if (tsk) {
|
||||
/*
|
||||
* Blocking time is in units of nanosecs, so shift by
|
||||
* 20 to get a milliseconds-range estimation of the
|
||||
* amount of time that the task spent sleeping:
|
||||
*/
|
||||
if (unlikely(prof_on == SLEEP_PROFILING)) {
|
||||
profile_hits(SLEEP_PROFILING,
|
||||
(void *)get_wchan(tsk),
|
||||
delta >> 20);
|
||||
}
|
||||
account_scheduler_latency(tsk, delta >> 10, 0);
|
||||
}
|
||||
account_scheduler_latency(tsk, delta >> 10, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -687,7 +699,8 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
|
|||
* all of which have the same weight.
|
||||
*/
|
||||
if (sched_feat(NORMALIZED_SLEEPER) &&
|
||||
task_of(se)->policy != SCHED_IDLE)
|
||||
(!entity_is_task(se) ||
|
||||
task_of(se)->policy != SCHED_IDLE))
|
||||
thresh = calc_delta_fair(thresh, se);
|
||||
|
||||
vruntime -= thresh;
|
||||
|
|
@ -1016,7 +1029,7 @@ static void yield_task_fair(struct rq *rq)
|
|||
/*
|
||||
* Already in the rightmost position?
|
||||
*/
|
||||
if (unlikely(!rightmost || rightmost->vruntime < se->vruntime))
|
||||
if (unlikely(!rightmost || entity_before(rightmost, se)))
|
||||
return;
|
||||
|
||||
/*
|
||||
|
|
@ -1712,7 +1725,7 @@ static void task_new_fair(struct rq *rq, struct task_struct *p)
|
|||
|
||||
/* 'curr' will be NULL if the child belongs to a different group */
|
||||
if (sysctl_sched_child_runs_first && this_cpu == task_cpu(p) &&
|
||||
curr && curr->vruntime < se->vruntime) {
|
||||
curr && entity_before(curr, se)) {
|
||||
/*
|
||||
* Upon rescheduling, sched_class::put_prev_task() will place
|
||||
* 'current' within the tree based on its new key value.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se)
|
|||
|
||||
#ifdef CONFIG_RT_GROUP_SCHED
|
||||
|
||||
#define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
|
||||
|
||||
static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
|
||||
{
|
||||
return rt_rq->rq;
|
||||
|
|
@ -22,6 +24,8 @@ static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se)
|
|||
|
||||
#else /* CONFIG_RT_GROUP_SCHED */
|
||||
|
||||
#define rt_entity_is_task(rt_se) (1)
|
||||
|
||||
static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
|
||||
{
|
||||
return container_of(rt_rq, struct rq, rt);
|
||||
|
|
@ -73,7 +77,7 @@ static inline void rt_clear_overload(struct rq *rq)
|
|||
|
||||
static void update_rt_migration(struct rt_rq *rt_rq)
|
||||
{
|
||||
if (rt_rq->rt_nr_migratory && (rt_rq->rt_nr_running > 1)) {
|
||||
if (rt_rq->rt_nr_migratory && rt_rq->rt_nr_total > 1) {
|
||||
if (!rt_rq->overloaded) {
|
||||
rt_set_overload(rq_of_rt_rq(rt_rq));
|
||||
rt_rq->overloaded = 1;
|
||||
|
|
@ -86,6 +90,12 @@ static void update_rt_migration(struct rt_rq *rt_rq)
|
|||
|
||||
static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
|
||||
{
|
||||
if (!rt_entity_is_task(rt_se))
|
||||
return;
|
||||
|
||||
rt_rq = &rq_of_rt_rq(rt_rq)->rt;
|
||||
|
||||
rt_rq->rt_nr_total++;
|
||||
if (rt_se->nr_cpus_allowed > 1)
|
||||
rt_rq->rt_nr_migratory++;
|
||||
|
||||
|
|
@ -94,6 +104,12 @@ static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
|
|||
|
||||
static void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
|
||||
{
|
||||
if (!rt_entity_is_task(rt_se))
|
||||
return;
|
||||
|
||||
rt_rq = &rq_of_rt_rq(rt_rq)->rt;
|
||||
|
||||
rt_rq->rt_nr_total--;
|
||||
if (rt_se->nr_cpus_allowed > 1)
|
||||
rt_rq->rt_nr_migratory--;
|
||||
|
||||
|
|
|
|||
|
|
@ -2454,11 +2454,9 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
|
|||
stack_t oss;
|
||||
int error;
|
||||
|
||||
if (uoss) {
|
||||
oss.ss_sp = (void __user *) current->sas_ss_sp;
|
||||
oss.ss_size = current->sas_ss_size;
|
||||
oss.ss_flags = sas_ss_flags(sp);
|
||||
}
|
||||
oss.ss_sp = (void __user *) current->sas_ss_sp;
|
||||
oss.ss_size = current->sas_ss_size;
|
||||
oss.ss_flags = sas_ss_flags(sp);
|
||||
|
||||
if (uss) {
|
||||
void __user *ss_sp;
|
||||
|
|
@ -2466,10 +2464,12 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
|
|||
int ss_flags;
|
||||
|
||||
error = -EFAULT;
|
||||
if (!access_ok(VERIFY_READ, uss, sizeof(*uss))
|
||||
|| __get_user(ss_sp, &uss->ss_sp)
|
||||
|| __get_user(ss_flags, &uss->ss_flags)
|
||||
|| __get_user(ss_size, &uss->ss_size))
|
||||
if (!access_ok(VERIFY_READ, uss, sizeof(*uss)))
|
||||
goto out;
|
||||
error = __get_user(ss_sp, &uss->ss_sp) |
|
||||
__get_user(ss_flags, &uss->ss_flags) |
|
||||
__get_user(ss_size, &uss->ss_size);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
error = -EPERM;
|
||||
|
|
@ -2501,13 +2501,16 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
|
|||
current->sas_ss_size = ss_size;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (uoss) {
|
||||
error = -EFAULT;
|
||||
if (copy_to_user(uoss, &oss, sizeof(oss)))
|
||||
if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
|
||||
goto out;
|
||||
error = __put_user(oss.ss_sp, &uoss->ss_sp) |
|
||||
__put_user(oss.ss_size, &uoss->ss_size) |
|
||||
__put_user(oss.ss_flags, &uoss->ss_flags);
|
||||
}
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
|||
return NOTIFY_BAD;
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_CPU_HOTPLUG
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
case CPU_UP_CANCELED:
|
||||
case CPU_UP_CANCELED_FROZEN:
|
||||
|
||||
|
|
|
|||
|
|
@ -345,7 +345,9 @@ void open_softirq(int nr, void (*action)(struct softirq_action *))
|
|||
softirq_vec[nr].action = action;
|
||||
}
|
||||
|
||||
/* Tasklets */
|
||||
/*
|
||||
* Tasklets
|
||||
*/
|
||||
struct tasklet_head
|
||||
{
|
||||
struct tasklet_struct *head;
|
||||
|
|
@ -493,6 +495,66 @@ void tasklet_kill(struct tasklet_struct *t)
|
|||
|
||||
EXPORT_SYMBOL(tasklet_kill);
|
||||
|
||||
/*
|
||||
* tasklet_hrtimer
|
||||
*/
|
||||
|
||||
/*
|
||||
* The trampoline is called when the hrtimer expires. If this is
|
||||
* called from the hrtimer interrupt then we schedule the tasklet as
|
||||
* the timer callback function expects to run in softirq context. If
|
||||
* it's called in softirq context anyway (i.e. high resolution timers
|
||||
* disabled) then the hrtimer callback is called right away.
|
||||
*/
|
||||
static enum hrtimer_restart __hrtimer_tasklet_trampoline(struct hrtimer *timer)
|
||||
{
|
||||
struct tasklet_hrtimer *ttimer =
|
||||
container_of(timer, struct tasklet_hrtimer, timer);
|
||||
|
||||
if (hrtimer_is_hres_active(timer)) {
|
||||
tasklet_hi_schedule(&ttimer->tasklet);
|
||||
return HRTIMER_NORESTART;
|
||||
}
|
||||
return ttimer->function(timer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function which calls the hrtimer callback from
|
||||
* tasklet/softirq context
|
||||
*/
|
||||
static void __tasklet_hrtimer_trampoline(unsigned long data)
|
||||
{
|
||||
struct tasklet_hrtimer *ttimer = (void *)data;
|
||||
enum hrtimer_restart restart;
|
||||
|
||||
restart = ttimer->function(&ttimer->timer);
|
||||
if (restart != HRTIMER_NORESTART)
|
||||
hrtimer_restart(&ttimer->timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* tasklet_hrtimer_init - Init a tasklet/hrtimer combo for softirq callbacks
|
||||
* @ttimer: tasklet_hrtimer which is initialized
|
||||
* @function: hrtimer callback funtion which gets called from softirq context
|
||||
* @which_clock: clock id (CLOCK_MONOTONIC/CLOCK_REALTIME)
|
||||
* @mode: hrtimer mode (HRTIMER_MODE_ABS/HRTIMER_MODE_REL)
|
||||
*/
|
||||
void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
|
||||
enum hrtimer_restart (*function)(struct hrtimer *),
|
||||
clockid_t which_clock, enum hrtimer_mode mode)
|
||||
{
|
||||
hrtimer_init(&ttimer->timer, which_clock, mode);
|
||||
ttimer->timer.function = __hrtimer_tasklet_trampoline;
|
||||
tasklet_init(&ttimer->tasklet, __tasklet_hrtimer_trampoline,
|
||||
(unsigned long)ttimer);
|
||||
ttimer->function = function;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tasklet_hrtimer_init);
|
||||
|
||||
/*
|
||||
* Remote softirq bits
|
||||
*/
|
||||
|
||||
DEFINE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list);
|
||||
EXPORT_PER_CPU_SYMBOL(softirq_work_list);
|
||||
|
||||
|
|
|
|||
|
|
@ -335,7 +335,10 @@ static struct ctl_table kern_table[] = {
|
|||
.data = &sysctl_timer_migration,
|
||||
.maxlen = sizeof(unsigned int),
|
||||
.mode = 0644,
|
||||
.proc_handler = &proc_dointvec,
|
||||
.proc_handler = &proc_dointvec_minmax,
|
||||
.strategy = &sysctl_intvec,
|
||||
.extra1 = &zero,
|
||||
.extra2 = &one,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
|
|
@ -743,6 +746,14 @@ static struct ctl_table kern_table[] = {
|
|||
.mode = 0644,
|
||||
.proc_handler = &proc_dointvec,
|
||||
},
|
||||
{
|
||||
.ctl_name = CTL_UNNUMBERED,
|
||||
.procname = "panic_on_io_nmi",
|
||||
.data = &panic_on_io_nmi,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = &proc_dointvec,
|
||||
},
|
||||
{
|
||||
.ctl_name = KERN_BOOTLOADER_TYPE,
|
||||
.procname = "bootloader_type",
|
||||
|
|
|
|||
|
|
@ -254,15 +254,4 @@ void clockevents_notify(unsigned long reason, void *arg)
|
|||
spin_unlock(&clockevents_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(clockevents_notify);
|
||||
|
||||
ktime_t clockevents_get_next_event(int cpu)
|
||||
{
|
||||
struct tick_device *td;
|
||||
struct clock_event_device *dev;
|
||||
|
||||
td = &per_cpu(tick_cpu_device, cpu);
|
||||
dev = td->evtdev;
|
||||
|
||||
return dev->next_event;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -513,7 +513,7 @@ static ssize_t sysfs_override_clocksource(struct sys_device *dev,
|
|||
* Check to make sure we don't switch to a non-highres capable
|
||||
* clocksource if the tick code is in oneshot mode (highres or nohz)
|
||||
*/
|
||||
if (tick_oneshot_mode_active() &&
|
||||
if (tick_oneshot_mode_active() && ovr &&
|
||||
!(ovr->flags & CLOCK_SOURCE_VALID_FOR_HRES)) {
|
||||
printk(KERN_WARNING "%s clocksource is not HRT compatible. "
|
||||
"Cannot switch while in HRT/NOHZ mode\n", ovr->name);
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ static DEFINE_MUTEX(show_mutex);
|
|||
/*
|
||||
* Collection status, active/inactive:
|
||||
*/
|
||||
static int __read_mostly active;
|
||||
int __read_mostly timer_stats_active;
|
||||
|
||||
/*
|
||||
* Beginning/end timestamps of measurement:
|
||||
|
|
@ -242,7 +242,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
|
|||
struct entry *entry, input;
|
||||
unsigned long flags;
|
||||
|
||||
if (likely(!active))
|
||||
if (likely(!timer_stats_active))
|
||||
return;
|
||||
|
||||
lock = &per_cpu(lookup_lock, raw_smp_processor_id());
|
||||
|
|
@ -254,7 +254,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
|
|||
input.timer_flag = timer_flag;
|
||||
|
||||
spin_lock_irqsave(lock, flags);
|
||||
if (!active)
|
||||
if (!timer_stats_active)
|
||||
goto out_unlock;
|
||||
|
||||
entry = tstat_lookup(&input, comm);
|
||||
|
|
@ -290,7 +290,7 @@ static int tstats_show(struct seq_file *m, void *v)
|
|||
/*
|
||||
* If still active then calculate up to now:
|
||||
*/
|
||||
if (active)
|
||||
if (timer_stats_active)
|
||||
time_stop = ktime_get();
|
||||
|
||||
time = ktime_sub(time_stop, time_start);
|
||||
|
|
@ -368,18 +368,18 @@ static ssize_t tstats_write(struct file *file, const char __user *buf,
|
|||
mutex_lock(&show_mutex);
|
||||
switch (ctl[0]) {
|
||||
case '0':
|
||||
if (active) {
|
||||
active = 0;
|
||||
if (timer_stats_active) {
|
||||
timer_stats_active = 0;
|
||||
time_stop = ktime_get();
|
||||
sync_access();
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (!active) {
|
||||
if (!timer_stats_active) {
|
||||
reset_entries();
|
||||
time_start = ktime_get();
|
||||
smp_mb();
|
||||
active = 1;
|
||||
timer_stats_active = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -380,6 +380,8 @@ static void timer_stats_account_timer(struct timer_list *timer)
|
|||
{
|
||||
unsigned int flag = 0;
|
||||
|
||||
if (likely(!timer->start_site))
|
||||
return;
|
||||
if (unlikely(tbase_get_deferrable(timer->base)))
|
||||
flag |= TIMER_STATS_FLAG_DEFERRABLE;
|
||||
|
||||
|
|
@ -712,7 +714,7 @@ int mod_timer(struct timer_list *timer, unsigned long expires)
|
|||
* networking code - if the timer is re-modified
|
||||
* to be the same thing then just return:
|
||||
*/
|
||||
if (timer->expires == expires && timer_pending(timer))
|
||||
if (timer_pending(timer) && timer->expires == expires)
|
||||
return 1;
|
||||
|
||||
return __mod_timer(timer, expires, false, TIMER_NOT_PINNED);
|
||||
|
|
|
|||
|
|
@ -226,13 +226,13 @@ config BOOT_TRACER
|
|||
the timings of the initcalls and traces key events and the identity
|
||||
of tasks that can cause boot delays, such as context-switches.
|
||||
|
||||
Its aim is to be parsed by the /scripts/bootgraph.pl tool to
|
||||
Its aim is to be parsed by the scripts/bootgraph.pl tool to
|
||||
produce pretty graphics about boot inefficiencies, giving a visual
|
||||
representation of the delays during initcalls - but the raw
|
||||
/debug/tracing/trace text output is readable too.
|
||||
|
||||
You must pass in ftrace=initcall to the kernel command line
|
||||
to enable this on bootup.
|
||||
You must pass in initcall_debug and ftrace=initcall to the kernel
|
||||
command line to enable this on bootup.
|
||||
|
||||
config TRACE_BRANCH_PROFILING
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
|
|
@ -266,8 +267,8 @@ static void blk_trace_free(struct blk_trace *bt)
|
|||
{
|
||||
debugfs_remove(bt->msg_file);
|
||||
debugfs_remove(bt->dropped_file);
|
||||
debugfs_remove(bt->dir);
|
||||
relay_close(bt->rchan);
|
||||
debugfs_remove(bt->dir);
|
||||
free_percpu(bt->sequence);
|
||||
free_percpu(bt->msg_data);
|
||||
kfree(bt);
|
||||
|
|
@ -377,18 +378,8 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
|
|||
|
||||
static int blk_remove_buf_file_callback(struct dentry *dentry)
|
||||
{
|
||||
struct dentry *parent = dentry->d_parent;
|
||||
debugfs_remove(dentry);
|
||||
|
||||
/*
|
||||
* this will fail for all but the last file, but that is ok. what we
|
||||
* care about is the top level buts->name directory going away, when
|
||||
* the last trace file is gone. Then we don't have to rmdir() that
|
||||
* manually on trace stop, so it nicely solves the issue with
|
||||
* force killing of running traces.
|
||||
*/
|
||||
|
||||
debugfs_remove(parent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -291,7 +291,9 @@ function_stat_next(void *v, int idx)
|
|||
pg = (struct ftrace_profile_page *)((unsigned long)rec & PAGE_MASK);
|
||||
|
||||
again:
|
||||
rec++;
|
||||
if (idx != 0)
|
||||
rec++;
|
||||
|
||||
if ((void *)rec >= (void *)&pg->records[pg->index]) {
|
||||
pg = pg->next;
|
||||
if (!pg)
|
||||
|
|
@ -766,7 +768,7 @@ static struct tracer_stat function_stats __initdata = {
|
|||
.stat_show = function_stat_show
|
||||
};
|
||||
|
||||
static void ftrace_profile_debugfs(struct dentry *d_tracer)
|
||||
static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
|
||||
{
|
||||
struct ftrace_profile_stat *stat;
|
||||
struct dentry *entry;
|
||||
|
|
@ -784,7 +786,6 @@ static void ftrace_profile_debugfs(struct dentry *d_tracer)
|
|||
* The files created are permanent, if something happens
|
||||
* we still do not free memory.
|
||||
*/
|
||||
kfree(stat);
|
||||
WARN(1,
|
||||
"Could not allocate stat file for cpu %d\n",
|
||||
cpu);
|
||||
|
|
@ -811,7 +812,7 @@ static void ftrace_profile_debugfs(struct dentry *d_tracer)
|
|||
}
|
||||
|
||||
#else /* CONFIG_FUNCTION_PROFILER */
|
||||
static void ftrace_profile_debugfs(struct dentry *d_tracer)
|
||||
static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
|
||||
{
|
||||
}
|
||||
#endif /* CONFIG_FUNCTION_PROFILER */
|
||||
|
|
@ -1417,10 +1418,20 @@ static void *t_hash_start(struct seq_file *m, loff_t *pos)
|
|||
{
|
||||
struct ftrace_iterator *iter = m->private;
|
||||
void *p = NULL;
|
||||
loff_t l;
|
||||
|
||||
if (!(iter->flags & FTRACE_ITER_HASH))
|
||||
*pos = 0;
|
||||
|
||||
iter->flags |= FTRACE_ITER_HASH;
|
||||
|
||||
return t_hash_next(m, p, pos);
|
||||
iter->hidx = 0;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
p = t_hash_next(m, p, &l);
|
||||
if (!p)
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static int t_hash_show(struct seq_file *m, void *v)
|
||||
|
|
@ -1467,8 +1478,6 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
|
|||
iter->pg = iter->pg->next;
|
||||
iter->idx = 0;
|
||||
goto retry;
|
||||
} else {
|
||||
iter->idx = -1;
|
||||
}
|
||||
} else {
|
||||
rec = &iter->pg->records[iter->idx++];
|
||||
|
|
@ -1497,6 +1506,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)
|
|||
{
|
||||
struct ftrace_iterator *iter = m->private;
|
||||
void *p = NULL;
|
||||
loff_t l;
|
||||
|
||||
mutex_lock(&ftrace_lock);
|
||||
/*
|
||||
|
|
@ -1508,23 +1518,21 @@ static void *t_start(struct seq_file *m, loff_t *pos)
|
|||
if (*pos > 0)
|
||||
return t_hash_start(m, pos);
|
||||
iter->flags |= FTRACE_ITER_PRINTALL;
|
||||
(*pos)++;
|
||||
return iter;
|
||||
}
|
||||
|
||||
if (iter->flags & FTRACE_ITER_HASH)
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
if (*pos > 0) {
|
||||
if (iter->idx < 0)
|
||||
return p;
|
||||
(*pos)--;
|
||||
iter->idx--;
|
||||
iter->pg = ftrace_pages_start;
|
||||
iter->idx = 0;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
p = t_next(m, p, &l);
|
||||
if (!p)
|
||||
break;
|
||||
}
|
||||
|
||||
p = t_next(m, p, pos);
|
||||
|
||||
if (!p)
|
||||
if (!p && iter->flags & FTRACE_ITER_FILTER)
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
return p;
|
||||
|
|
@ -1654,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
|
|||
|
||||
mutex_lock(&ftrace_regex_lock);
|
||||
if ((file->f_mode & FMODE_WRITE) &&
|
||||
!(file->f_flags & O_APPEND))
|
||||
(file->f_flags & O_TRUNC))
|
||||
ftrace_filter_reset(enable);
|
||||
|
||||
if (file->f_mode & FMODE_READ) {
|
||||
|
|
@ -2500,32 +2508,31 @@ int ftrace_graph_count;
|
|||
unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly;
|
||||
|
||||
static void *
|
||||
g_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
__g_next(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
unsigned long *array = m->private;
|
||||
int index = *pos;
|
||||
|
||||
(*pos)++;
|
||||
|
||||
if (index >= ftrace_graph_count)
|
||||
if (*pos >= ftrace_graph_count)
|
||||
return NULL;
|
||||
return &array[*pos];
|
||||
}
|
||||
|
||||
return &array[index];
|
||||
static void *
|
||||
g_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
{
|
||||
(*pos)++;
|
||||
return __g_next(m, pos);
|
||||
}
|
||||
|
||||
static void *g_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
void *p = NULL;
|
||||
|
||||
mutex_lock(&graph_lock);
|
||||
|
||||
/* Nothing, tell g_show to print all functions are enabled */
|
||||
if (!ftrace_graph_count && !*pos)
|
||||
return (void *)1;
|
||||
|
||||
p = g_next(m, p, pos);
|
||||
|
||||
return p;
|
||||
return __g_next(m, pos);
|
||||
}
|
||||
|
||||
static void g_stop(struct seq_file *m, void *p)
|
||||
|
|
@ -2570,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file)
|
|||
|
||||
mutex_lock(&graph_lock);
|
||||
if ((file->f_mode & FMODE_WRITE) &&
|
||||
!(file->f_flags & O_APPEND)) {
|
||||
(file->f_flags & O_TRUNC)) {
|
||||
ftrace_graph_count = 0;
|
||||
memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
|
||||
}
|
||||
|
|
@ -2588,6 +2595,14 @@ ftrace_graph_open(struct inode *inode, struct file *file)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
ftrace_graph_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
if (file->f_mode & FMODE_READ)
|
||||
seq_release(inode, file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ftrace_set_func(unsigned long *array, int *idx, char *buffer)
|
||||
{
|
||||
|
|
@ -2717,9 +2732,10 @@ ftrace_graph_write(struct file *file, const char __user *ubuf,
|
|||
}
|
||||
|
||||
static const struct file_operations ftrace_graph_fops = {
|
||||
.open = ftrace_graph_open,
|
||||
.read = seq_read,
|
||||
.write = ftrace_graph_write,
|
||||
.open = ftrace_graph_open,
|
||||
.read = seq_read,
|
||||
.write = ftrace_graph_write,
|
||||
.release = ftrace_graph_release,
|
||||
};
|
||||
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
|
||||
|
||||
|
|
@ -3152,10 +3168,10 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
|
|||
|
||||
ret = proc_dointvec(table, write, file, buffer, lenp, ppos);
|
||||
|
||||
if (ret || !write || (last_ftrace_enabled == ftrace_enabled))
|
||||
if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled))
|
||||
goto out;
|
||||
|
||||
last_ftrace_enabled = ftrace_enabled;
|
||||
last_ftrace_enabled = !!ftrace_enabled;
|
||||
|
||||
if (ftrace_enabled) {
|
||||
|
||||
|
|
|
|||
|
|
@ -735,6 +735,7 @@ ring_buffer_free(struct ring_buffer *buffer)
|
|||
|
||||
put_online_cpus();
|
||||
|
||||
kfree(buffer->buffers);
|
||||
free_cpumask_var(buffer->cpumask);
|
||||
|
||||
kfree(buffer);
|
||||
|
|
@ -1563,6 +1564,8 @@ rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TRACING
|
||||
|
||||
#define TRACE_RECURSIVE_DEPTH 16
|
||||
|
||||
static int trace_recursive_lock(void)
|
||||
|
|
@ -1593,6 +1596,13 @@ static void trace_recursive_unlock(void)
|
|||
current->trace_recursion--;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define trace_recursive_lock() (0)
|
||||
#define trace_recursive_unlock() do { } while (0)
|
||||
|
||||
#endif
|
||||
|
||||
static DEFINE_PER_CPU(int, rb_need_resched);
|
||||
|
||||
/**
|
||||
|
|
@ -1776,7 +1786,7 @@ void ring_buffer_discard_commit(struct ring_buffer *buffer,
|
|||
*/
|
||||
RB_WARN_ON(buffer, !local_read(&cpu_buffer->committing));
|
||||
|
||||
if (!rb_try_to_discard(cpu_buffer, event))
|
||||
if (rb_try_to_discard(cpu_buffer, event))
|
||||
goto out;
|
||||
|
||||
/*
|
||||
|
|
@ -2374,7 +2384,6 @@ rb_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
|
|||
* the box. Return the padding, and we will release
|
||||
* the current locks, and try again.
|
||||
*/
|
||||
rb_advance_reader(cpu_buffer);
|
||||
return event;
|
||||
|
||||
case RINGBUF_TYPE_TIME_EXTEND:
|
||||
|
|
@ -2477,7 +2486,7 @@ static inline int rb_ok_to_lock(void)
|
|||
* buffer too. A one time deal is all you get from reading
|
||||
* the ring buffer from an NMI.
|
||||
*/
|
||||
if (likely(!in_nmi() && !oops_in_progress))
|
||||
if (likely(!in_nmi()))
|
||||
return 1;
|
||||
|
||||
tracing_off_permanent();
|
||||
|
|
@ -2510,6 +2519,8 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
|
|||
if (dolock)
|
||||
spin_lock(&cpu_buffer->reader_lock);
|
||||
event = rb_buffer_peek(buffer, cpu, ts);
|
||||
if (event && event->type_len == RINGBUF_TYPE_PADDING)
|
||||
rb_advance_reader(cpu_buffer);
|
||||
if (dolock)
|
||||
spin_unlock(&cpu_buffer->reader_lock);
|
||||
local_irq_restore(flags);
|
||||
|
|
@ -2581,12 +2592,9 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
|
|||
spin_lock(&cpu_buffer->reader_lock);
|
||||
|
||||
event = rb_buffer_peek(buffer, cpu, ts);
|
||||
if (!event)
|
||||
goto out_unlock;
|
||||
if (event)
|
||||
rb_advance_reader(cpu_buffer);
|
||||
|
||||
rb_advance_reader(cpu_buffer);
|
||||
|
||||
out_unlock:
|
||||
if (dolock)
|
||||
spin_unlock(&cpu_buffer->reader_lock);
|
||||
local_irq_restore(flags);
|
||||
|
|
@ -3104,6 +3112,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(ring_buffer_read_page);
|
||||
|
||||
#ifdef CONFIG_TRACING
|
||||
static ssize_t
|
||||
rb_simple_read(struct file *filp, char __user *ubuf,
|
||||
size_t cnt, loff_t *ppos)
|
||||
|
|
@ -3171,6 +3180,7 @@ static __init int rb_init_debugfs(void)
|
|||
}
|
||||
|
||||
fs_initcall(rb_init_debugfs);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
static int rb_cpu_notify(struct notifier_block *self,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <linux/writeback.h>
|
||||
#include <linux/kallsyms.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/irqflags.h>
|
||||
#include <linux/debugfs.h>
|
||||
|
|
@ -284,13 +285,12 @@ void trace_wake_up(void)
|
|||
static int __init set_buf_size(char *str)
|
||||
{
|
||||
unsigned long buf_size;
|
||||
int ret;
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
ret = strict_strtoul(str, 0, &buf_size);
|
||||
buf_size = memparse(str, &str);
|
||||
/* nr_entries can not be zero */
|
||||
if (ret < 0 || buf_size == 0)
|
||||
if (buf_size == 0)
|
||||
return 0;
|
||||
trace_buf_size = buf_size;
|
||||
return 1;
|
||||
|
|
@ -848,6 +848,7 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
|
|||
((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
|
||||
(need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
|
||||
|
||||
struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
|
||||
int type,
|
||||
|
|
@ -2031,7 +2032,7 @@ static int tracing_open(struct inode *inode, struct file *file)
|
|||
|
||||
/* If this file was open for write, then erase contents */
|
||||
if ((file->f_mode & FMODE_WRITE) &&
|
||||
!(file->f_flags & O_APPEND)) {
|
||||
(file->f_flags & O_TRUNC)) {
|
||||
long cpu = (long) inode->i_private;
|
||||
|
||||
if (cpu == TRACE_PIPE_ALL_CPU)
|
||||
|
|
@ -2053,25 +2054,23 @@ static int tracing_open(struct inode *inode, struct file *file)
|
|||
static void *
|
||||
t_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
{
|
||||
struct tracer *t = m->private;
|
||||
struct tracer *t = v;
|
||||
|
||||
(*pos)++;
|
||||
|
||||
if (t)
|
||||
t = t->next;
|
||||
|
||||
m->private = t;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
struct tracer *t = m->private;
|
||||
struct tracer *t;
|
||||
loff_t l = 0;
|
||||
|
||||
mutex_lock(&trace_types_lock);
|
||||
for (; t && l < *pos; t = t_next(m, t, &l))
|
||||
for (t = trace_types; t && l < *pos; t = t_next(m, t, &l))
|
||||
;
|
||||
|
||||
return t;
|
||||
|
|
@ -2107,18 +2106,10 @@ static struct seq_operations show_traces_seq_ops = {
|
|||
|
||||
static int show_traces_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (tracing_disabled)
|
||||
return -ENODEV;
|
||||
|
||||
ret = seq_open(file, &show_traces_seq_ops);
|
||||
if (!ret) {
|
||||
struct seq_file *m = file->private_data;
|
||||
m->private = trace_types;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return seq_open(file, &show_traces_seq_ops);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
|
|
@ -3095,7 +3086,8 @@ tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
|
|||
break;
|
||||
}
|
||||
|
||||
trace_consume(iter);
|
||||
if (ret != TRACE_TYPE_NO_CONSUME)
|
||||
trace_consume(iter);
|
||||
rem -= count;
|
||||
if (!find_next_entry_inc(iter)) {
|
||||
rem = 0;
|
||||
|
|
@ -4243,8 +4235,11 @@ static void __ftrace_dump(bool disable_tracing)
|
|||
iter.pos = -1;
|
||||
|
||||
if (find_next_entry_inc(&iter) != NULL) {
|
||||
print_trace_line(&iter);
|
||||
trace_consume(&iter);
|
||||
int ret;
|
||||
|
||||
ret = print_trace_line(&iter);
|
||||
if (ret != TRACE_TYPE_NO_CONSUME)
|
||||
trace_consume(&iter);
|
||||
}
|
||||
|
||||
trace_printk_seq(&iter.seq);
|
||||
|
|
|
|||
|
|
@ -438,10 +438,6 @@ struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
|
|||
struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
|
||||
int *ent_cpu, u64 *ent_ts);
|
||||
|
||||
void tracing_generic_entry_update(struct trace_entry *entry,
|
||||
unsigned long flags,
|
||||
int pc);
|
||||
|
||||
void default_wait_pipe(struct trace_iterator *iter);
|
||||
void poll_wait_pipe(struct trace_iterator *iter);
|
||||
|
||||
|
|
@ -597,6 +593,7 @@ print_graph_function(struct trace_iterator *iter)
|
|||
|
||||
extern struct pid *ftrace_pid_trace;
|
||||
|
||||
#ifdef CONFIG_FUNCTION_TRACER
|
||||
static inline int ftrace_trace_task(struct task_struct *task)
|
||||
{
|
||||
if (!ftrace_pid_trace)
|
||||
|
|
@ -604,6 +601,12 @@ static inline int ftrace_trace_task(struct task_struct *task)
|
|||
|
||||
return test_tsk_trace_trace(task);
|
||||
}
|
||||
#else
|
||||
static inline int ftrace_trace_task(struct task_struct *task)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* trace_iterator_flags is an enumeration that defines bit
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ int ftrace_profile_enable(int event_id)
|
|||
|
||||
mutex_lock(&event_mutex);
|
||||
list_for_each_entry(event, &ftrace_events, list) {
|
||||
if (event->id == event_id) {
|
||||
if (event->id == event_id && event->profile_enable) {
|
||||
ret = event->profile_enable(event);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ TRACE_EVENT_FORMAT(funcgraph_exit, TRACE_GRAPH_RET,
|
|||
ftrace_graph_ret_entry, ignore,
|
||||
TRACE_STRUCT(
|
||||
TRACE_FIELD(unsigned long, ret.func, func)
|
||||
TRACE_FIELD(unsigned long long, ret.calltime, calltime)
|
||||
TRACE_FIELD(unsigned long long, ret.rettime, rettime)
|
||||
TRACE_FIELD(unsigned long, ret.overrun, overrun)
|
||||
TRACE_FIELD(int, ret.depth, depth)
|
||||
),
|
||||
TP_RAW_FMT("<-- %lx (%d)")
|
||||
|
|
|
|||
|
|
@ -300,10 +300,18 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
|
|||
|
||||
static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
struct ftrace_event_call *call = NULL;
|
||||
loff_t l;
|
||||
|
||||
mutex_lock(&event_mutex);
|
||||
if (*pos == 0)
|
||||
m->private = ftrace_events.next;
|
||||
return t_next(m, NULL, pos);
|
||||
|
||||
m->private = ftrace_events.next;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
call = t_next(m, NULL, &l);
|
||||
if (!call)
|
||||
break;
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
@ -332,10 +340,18 @@ s_next(struct seq_file *m, void *v, loff_t *pos)
|
|||
|
||||
static void *s_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
struct ftrace_event_call *call = NULL;
|
||||
loff_t l;
|
||||
|
||||
mutex_lock(&event_mutex);
|
||||
if (*pos == 0)
|
||||
m->private = ftrace_events.next;
|
||||
return s_next(m, NULL, pos);
|
||||
|
||||
m->private = ftrace_events.next;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
call = s_next(m, NULL, &l);
|
||||
if (!call)
|
||||
break;
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
static int t_show(struct seq_file *m, void *v)
|
||||
|
|
@ -360,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file)
|
|||
const struct seq_operations *seq_ops;
|
||||
|
||||
if ((file->f_mode & FMODE_WRITE) &&
|
||||
!(file->f_flags & O_APPEND))
|
||||
(file->f_flags & O_TRUNC))
|
||||
ftrace_clear_events();
|
||||
|
||||
seq_ops = inode->i_private;
|
||||
|
|
@ -924,7 +940,7 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
|
|||
entry = trace_create_file("enable", 0644, call->dir, call,
|
||||
enable);
|
||||
|
||||
if (call->id)
|
||||
if (call->id && call->profile_enable)
|
||||
entry = trace_create_file("id", 0444, call->dir, call,
|
||||
id);
|
||||
|
||||
|
|
|
|||
|
|
@ -624,9 +624,6 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps,
|
|||
return -ENOSPC;
|
||||
}
|
||||
|
||||
filter->preds[filter->n_preds] = pred;
|
||||
filter->n_preds++;
|
||||
|
||||
list_for_each_entry(call, &ftrace_events, list) {
|
||||
|
||||
if (!call->define_fields)
|
||||
|
|
@ -643,6 +640,9 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps,
|
|||
}
|
||||
replace_filter_string(call->filter, filter_string);
|
||||
}
|
||||
|
||||
filter->preds[filter->n_preds] = pred;
|
||||
filter->n_preds++;
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
|
@ -1029,12 +1029,17 @@ static int replace_preds(struct event_subsystem *system,
|
|||
|
||||
if (elt->op == OP_AND || elt->op == OP_OR) {
|
||||
pred = create_logical_pred(elt->op);
|
||||
if (!pred)
|
||||
return -ENOMEM;
|
||||
if (call) {
|
||||
err = filter_add_pred(ps, call, pred);
|
||||
filter_free_pred(pred);
|
||||
} else
|
||||
} else {
|
||||
err = filter_add_subsystem_pred(ps, system,
|
||||
pred, filter_string);
|
||||
if (err)
|
||||
filter_free_pred(pred);
|
||||
}
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
|
@ -1048,12 +1053,17 @@ static int replace_preds(struct event_subsystem *system,
|
|||
}
|
||||
|
||||
pred = create_pred(elt->op, operand1, operand2);
|
||||
if (!pred)
|
||||
return -ENOMEM;
|
||||
if (call) {
|
||||
err = filter_add_pred(ps, call, pred);
|
||||
filter_free_pred(pred);
|
||||
} else
|
||||
} else {
|
||||
err = filter_add_subsystem_pred(ps, system, pred,
|
||||
filter_string);
|
||||
if (err)
|
||||
filter_free_pred(pred);
|
||||
}
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
|
|
|||
|
|
@ -302,8 +302,7 @@ ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip,
|
|||
if (count == -1)
|
||||
seq_printf(m, ":unlimited\n");
|
||||
else
|
||||
seq_printf(m, ":count=%ld", count);
|
||||
seq_putc(m, '\n');
|
||||
seq_printf(m, ":count=%ld\n", count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -364,7 +363,7 @@ ftrace_trace_onoff_callback(char *glob, char *cmd, char *param, int enable)
|
|||
out_reg:
|
||||
ret = register_ftrace_function_probe(glob, ops, count);
|
||||
|
||||
return ret;
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
static struct ftrace_func_command ftrace_traceon_cmd = {
|
||||
|
|
|
|||
|
|
@ -843,9 +843,16 @@ print_graph_function(struct trace_iterator *iter)
|
|||
|
||||
switch (entry->type) {
|
||||
case TRACE_GRAPH_ENT: {
|
||||
struct ftrace_graph_ent_entry *field;
|
||||
/*
|
||||
* print_graph_entry() may consume the current event,
|
||||
* thus @field may become invalid, so we need to save it.
|
||||
* sizeof(struct ftrace_graph_ent_entry) is very small,
|
||||
* it can be safely saved at the stack.
|
||||
*/
|
||||
struct ftrace_graph_ent_entry *field, saved;
|
||||
trace_assign_type(field, entry);
|
||||
return print_graph_entry(field, s, iter);
|
||||
saved = *field;
|
||||
return print_graph_entry(&saved, s, iter);
|
||||
}
|
||||
case TRACE_GRAPH_RET: {
|
||||
struct ftrace_graph_ret_entry *field;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
|
|||
{
|
||||
int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
|
||||
|
||||
s->buffer[len] = 0;
|
||||
seq_puts(m, s->buffer);
|
||||
seq_write(m, s->buffer, len);
|
||||
|
||||
trace_seq_init(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,25 +155,19 @@ int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
|
|||
EXPORT_SYMBOL_GPL(__ftrace_vprintk);
|
||||
|
||||
static void *
|
||||
t_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
t_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
const char **fmt = m->private;
|
||||
const char **next = fmt;
|
||||
|
||||
(*pos)++;
|
||||
const char **fmt = __start___trace_bprintk_fmt + *pos;
|
||||
|
||||
if ((unsigned long)fmt >= (unsigned long)__stop___trace_bprintk_fmt)
|
||||
return NULL;
|
||||
|
||||
next = fmt;
|
||||
m->private = ++next;
|
||||
|
||||
return fmt;
|
||||
}
|
||||
|
||||
static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
static void *t_next(struct seq_file *m, void * v, loff_t *pos)
|
||||
{
|
||||
return t_next(m, NULL, pos);
|
||||
(*pos)++;
|
||||
return t_start(m, pos);
|
||||
}
|
||||
|
||||
static int t_show(struct seq_file *m, void *v)
|
||||
|
|
@ -182,7 +176,7 @@ static int t_show(struct seq_file *m, void *v)
|
|||
const char *str = *fmt;
|
||||
int i;
|
||||
|
||||
seq_printf(m, "0x%lx : \"", (unsigned long)fmt);
|
||||
seq_printf(m, "0x%lx : \"", *(unsigned long *)fmt);
|
||||
|
||||
/*
|
||||
* Tabs and new lines need to be converted.
|
||||
|
|
@ -224,15 +218,7 @@ static const struct seq_operations show_format_seq_ops = {
|
|||
static int
|
||||
ftrace_formats_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = seq_open(file, &show_format_seq_ops);
|
||||
if (!ret) {
|
||||
struct seq_file *m = file->private_data;
|
||||
|
||||
m->private = __start___trace_bprintk_fmt;
|
||||
}
|
||||
return ret;
|
||||
return seq_open(file, &show_format_seq_ops);
|
||||
}
|
||||
|
||||
static const struct file_operations ftrace_formats_fops = {
|
||||
|
|
|
|||
|
|
@ -301,17 +301,14 @@ static const struct seq_operations stack_trace_seq_ops = {
|
|||
|
||||
static int stack_trace_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = seq_open(file, &stack_trace_seq_ops);
|
||||
|
||||
return ret;
|
||||
return seq_open(file, &stack_trace_seq_ops);
|
||||
}
|
||||
|
||||
static const struct file_operations stack_trace_fops = {
|
||||
.open = stack_trace_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = seq_release,
|
||||
};
|
||||
|
||||
int
|
||||
|
|
@ -326,10 +323,10 @@ stack_trace_sysctl(struct ctl_table *table, int write,
|
|||
ret = proc_dointvec(table, write, file, buffer, lenp, ppos);
|
||||
|
||||
if (ret || !write ||
|
||||
(last_stack_tracer_enabled == stack_tracer_enabled))
|
||||
(last_stack_tracer_enabled == !!stack_tracer_enabled))
|
||||
goto out;
|
||||
|
||||
last_stack_tracer_enabled = stack_tracer_enabled;
|
||||
last_stack_tracer_enabled = !!stack_tracer_enabled;
|
||||
|
||||
if (stack_tracer_enabled)
|
||||
register_ftrace_function(&trace_ops);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ static struct rb_node *release_next(struct rb_node *node)
|
|||
}
|
||||
}
|
||||
|
||||
static void reset_stat_session(struct stat_session *session)
|
||||
static void __reset_stat_session(struct stat_session *session)
|
||||
{
|
||||
struct rb_node *node = session->stat_root.rb_node;
|
||||
|
||||
|
|
@ -83,10 +83,17 @@ static void reset_stat_session(struct stat_session *session)
|
|||
session->stat_root = RB_ROOT;
|
||||
}
|
||||
|
||||
static void reset_stat_session(struct stat_session *session)
|
||||
{
|
||||
mutex_lock(&session->stat_mutex);
|
||||
__reset_stat_session(session);
|
||||
mutex_unlock(&session->stat_mutex);
|
||||
}
|
||||
|
||||
static void destroy_session(struct stat_session *session)
|
||||
{
|
||||
debugfs_remove(session->file);
|
||||
reset_stat_session(session);
|
||||
__reset_stat_session(session);
|
||||
mutex_destroy(&session->stat_mutex);
|
||||
kfree(session);
|
||||
}
|
||||
|
|
@ -150,7 +157,7 @@ static int stat_seq_init(struct stat_session *session)
|
|||
int i;
|
||||
|
||||
mutex_lock(&session->stat_mutex);
|
||||
reset_stat_session(session);
|
||||
__reset_stat_session(session);
|
||||
|
||||
if (!ts->stat_cmp)
|
||||
ts->stat_cmp = dummy_cmp;
|
||||
|
|
@ -183,7 +190,7 @@ exit:
|
|||
return ret;
|
||||
|
||||
exit_free_rbtree:
|
||||
reset_stat_session(session);
|
||||
__reset_stat_session(session);
|
||||
mutex_unlock(&session->stat_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -199,17 +206,13 @@ static void *stat_seq_start(struct seq_file *s, loff_t *pos)
|
|||
mutex_lock(&session->stat_mutex);
|
||||
|
||||
/* If we are in the beginning of the file, print the headers */
|
||||
if (!*pos && session->ts->stat_headers) {
|
||||
(*pos)++;
|
||||
if (!*pos && session->ts->stat_headers)
|
||||
return SEQ_START_TOKEN;
|
||||
}
|
||||
|
||||
node = rb_first(&session->stat_root);
|
||||
for (i = 0; node && i < *pos; i++)
|
||||
node = rb_next(node);
|
||||
|
||||
(*pos)++;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
@ -254,16 +257,21 @@ static const struct seq_operations trace_stat_seq_ops = {
|
|||
static int tracing_stat_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct seq_file *m;
|
||||
struct stat_session *session = inode->i_private;
|
||||
|
||||
ret = stat_seq_init(session);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = seq_open(file, &trace_stat_seq_ops);
|
||||
if (!ret) {
|
||||
struct seq_file *m = file->private_data;
|
||||
m->private = session;
|
||||
ret = stat_seq_init(session);
|
||||
if (ret) {
|
||||
reset_stat_session(session);
|
||||
return ret;
|
||||
}
|
||||
|
||||
m = file->private_data;
|
||||
m->private = session;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -274,11 +282,9 @@ static int tracing_stat_release(struct inode *i, struct file *f)
|
|||
{
|
||||
struct stat_session *session = i->i_private;
|
||||
|
||||
mutex_lock(&session->stat_mutex);
|
||||
reset_stat_session(session);
|
||||
mutex_unlock(&session->stat_mutex);
|
||||
|
||||
return 0;
|
||||
return seq_release(i, f);
|
||||
}
|
||||
|
||||
static const struct file_operations tracing_stat_fops = {
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@
|
|||
#include <linux/wait.h>
|
||||
#include <linux/hash.h>
|
||||
|
||||
void init_waitqueue_head(wait_queue_head_t *q)
|
||||
void __init_waitqueue_head(wait_queue_head_t *q, struct lock_class_key *key)
|
||||
{
|
||||
spin_lock_init(&q->lock);
|
||||
lockdep_set_class(&q->lock, key);
|
||||
INIT_LIST_HEAD(&q->task_list);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(init_waitqueue_head);
|
||||
EXPORT_SYMBOL(__init_waitqueue_head);
|
||||
|
||||
void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue