Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1344557 > unrolled thread
| Started by | Yang Shi <yang.shi@linaro.org> |
|---|---|
| First post | 2016-02-26 19:40 +0100 |
| Last post | 2016-02-26 21:20 +0100 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path Yang Shi <yang.shi@linaro.org> - 2016-02-26 19:40 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path Steven Rostedt <rostedt@goodmis.org> - 2016-02-26 20:00 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path "Shi, Yang" <yang.shi@linaro.org> - 2016-02-26 20:40 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path "Shi, Yang" <yang.shi@linaro.org> - 2016-02-26 21:00 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path Steven Rostedt <rostedt@goodmis.org> - 2016-02-26 21:20 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path "Shi, Yang" <yang.shi@linaro.org> - 2016-02-26 21:30 +0100
Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path "Shi, Yang" <yang.shi@linaro.org> - 2016-02-26 21:20 +0100
| From | Yang Shi <yang.shi@linaro.org> |
|---|---|
| Date | 2016-02-26 19:40 +0100 |
| Subject | [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6vt1-7nJ-33@gated-at.bofh.it> |
commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update writeback
tracepoints to report cgroup") made writeback tracepoints report cgroup
writeback, but it may trigger the below bug on -rt kernel since kernfs_path
and kernfs_path_len are called by tracepoints, which acquire sleeping lock.
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:930
in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3
INFO: lockdep is turned off.
Preemption disabled at:[<ffffffc000374a5c>] wb_writeback+0xec/0x830
CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20
Hardware name: Freescale Layerscape 2085a RDB Board (DT)
Workqueue: writeback wb_workfn (flush-7:0)
Call trace:
[<ffffffc00008d708>] dump_backtrace+0x0/0x200
[<ffffffc00008d92c>] show_stack+0x24/0x30
[<ffffffc0007b0f40>] dump_stack+0x88/0xa8
[<ffffffc000127d74>] ___might_sleep+0x2ec/0x300
[<ffffffc000d5d550>] rt_spin_lock+0x38/0xb8
[<ffffffc0003e0548>] kernfs_path_len+0x30/0x90
[<ffffffc00036b360>] trace_event_raw_event_writeback_work_class+0xe8/0x2e8
[<ffffffc000374f90>] wb_writeback+0x620/0x830
[<ffffffc000376224>] wb_workfn+0x61c/0x950
[<ffffffc000110adc>] process_one_work+0x3ac/0xb30
[<ffffffc0001112fc>] worker_thread+0x9c/0x7a8
[<ffffffc00011a9e8>] kthread+0x190/0x1b0
[<ffffffc000086ca0>] ret_from_fork+0x10/0x30
Since kernfs_* functions are heavily used by cgroup, so it sounds not
reasonable to convert kernfs_rename_lock to raw lock.
Create raw version kernfs_path, kernfs_path_len and cgroup_path, which don't
acquire lock and are used by tracepoints only.
Signed-off-by: Yang Shi <yang.shi@linaro.org>
---
It should be applicable to both mainline and -rt kernel.
The change survives ftrace stress test in ltp.
fs/kernfs/dir.c | 27 ++++++++++++++++++++++++---
include/linux/cgroup.h | 10 ++++++++++
include/linux/kernfs.h | 10 ++++++++++
include/trace/events/writeback.h | 4 ++--
4 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 996b774..9249336 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -44,7 +44,7 @@ static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)
return strlcpy(buf, kn->parent ? kn->name : "/", buflen);
}
-static char * __must_check kernfs_path_locked(struct kernfs_node *kn, char *buf,
+static char * __must_check __kernfs_path(struct kernfs_node *kn, char *buf,
size_t buflen)
{
char *p = buf + buflen;
@@ -131,12 +131,33 @@ char *kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
char *p;
spin_lock_irqsave(&kernfs_rename_lock, flags);
- p = kernfs_path_locked(kn, buf, buflen);
+ p = __kernfs_path(kn, buf, buflen);
spin_unlock_irqrestore(&kernfs_rename_lock, flags);
return p;
}
EXPORT_SYMBOL_GPL(kernfs_path);
+/* Raw version. Used by tracepoints only without acquiring lock */
+size_t _kernfs_path_len(struct kernfs_node *kn)
+{
+ size_t len = 0;
+
+ do {
+ len += strlen(kn->name) + 1;
+ kn = kn->parent;
+ } while (kn && kn->parent);
+
+ return len;
+}
+
+char *_kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
+{
+ char *p;
+
+ p = __kernfs_path(kn, buf, buflen);
+ return p;
+}
+
/**
* pr_cont_kernfs_name - pr_cont name of a kernfs_node
* @kn: kernfs_node of interest
@@ -168,7 +189,7 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)
spin_lock_irqsave(&kernfs_rename_lock, flags);
- p = kernfs_path_locked(kn, kernfs_pr_cont_buf,
+ p = __kernfs_path(kn, kernfs_pr_cont_buf,
sizeof(kernfs_pr_cont_buf));
if (p)
pr_cont("%s", p);
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 2162dca..bbd88d3 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -538,6 +538,16 @@ static inline char * __must_check cgroup_path(struct cgroup *cgrp, char *buf,
return kernfs_path(cgrp->kn, buf, buflen);
}
+/*
+ * Without acquiring kernfs_rename_lock in _kernfs_path.
+ * Used by tracepoints only.
+ */
+static inline char * __must_check _cgroup_path(struct cgroup *cgrp, char *buf,
+ size_t buflen)
+{
+ return _kernfs_path(cgrp->kn, buf, buflen);
+}
+
static inline void pr_cont_cgroup_name(struct cgroup *cgrp)
{
pr_cont_kernfs_name(cgrp->kn);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index af51df3..14c01cdc 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -267,8 +267,11 @@ static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
size_t kernfs_path_len(struct kernfs_node *kn);
+size_t _kernfs_path_len(struct kernfs_node *kn);
char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
size_t buflen);
+char * __must_check _kernfs_path(struct kernfs_node *kn, char *buf,
+ size_t buflen);
void pr_cont_kernfs_name(struct kernfs_node *kn);
void pr_cont_kernfs_path(struct kernfs_node *kn);
struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
@@ -338,10 +341,17 @@ static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
static inline size_t kernfs_path_len(struct kernfs_node *kn)
{ return 0; }
+static inline size_t _kernfs_path_len(struct kernfs_node *kn)
+{ return 0; }
+
static inline char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
size_t buflen)
{ return NULL; }
+static inline char * __must_check _kernfs_path(struct kernfs_node *kn, char *buf,
+ size_t buflen)
+{ return NULL; }
+
static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index fff846b..91ceced 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -136,7 +136,7 @@ DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode,
static inline size_t __trace_wb_cgroup_size(struct bdi_writeback *wb)
{
- return kernfs_path_len(wb->memcg_css->cgroup->kn) + 1;
+ return _kernfs_path_len(wb->memcg_css->cgroup->kn) + 1;
}
static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
@@ -144,7 +144,7 @@ static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
struct cgroup *cgrp = wb->memcg_css->cgroup;
char *path;
- path = cgroup_path(cgrp, buf, kernfs_path_len(cgrp->kn) + 1);
+ path = _cgroup_path(cgrp, buf, _kernfs_path_len(cgrp->kn) + 1);
WARN_ON_ONCE(path != buf);
}
--
2.0.2
[toc] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-02-26 20:00 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6vMm-7w1-25@gated-at.bofh.it> |
| In reply to | #1344557 |
On Fri, 26 Feb 2016 10:15:05 -0800
Yang Shi <yang.shi@linaro.org> wrote:
> commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update writeback
> tracepoints to report cgroup") made writeback tracepoints report cgroup
> writeback, but it may trigger the below bug on -rt kernel since kernfs_path
> and kernfs_path_len are called by tracepoints, which acquire sleeping lock.
>
> BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:930
> in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3
> INFO: lockdep is turned off.
> Preemption disabled at:[<ffffffc000374a5c>] wb_writeback+0xec/0x830
>
> CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20
> Hardware name: Freescale Layerscape 2085a RDB Board (DT)
> Workqueue: writeback wb_workfn (flush-7:0)
> Call trace:
> [<ffffffc00008d708>] dump_backtrace+0x0/0x200
> [<ffffffc00008d92c>] show_stack+0x24/0x30
> [<ffffffc0007b0f40>] dump_stack+0x88/0xa8
> [<ffffffc000127d74>] ___might_sleep+0x2ec/0x300
> [<ffffffc000d5d550>] rt_spin_lock+0x38/0xb8
> [<ffffffc0003e0548>] kernfs_path_len+0x30/0x90
> [<ffffffc00036b360>] trace_event_raw_event_writeback_work_class+0xe8/0x2e8
> [<ffffffc000374f90>] wb_writeback+0x620/0x830
> [<ffffffc000376224>] wb_workfn+0x61c/0x950
> [<ffffffc000110adc>] process_one_work+0x3ac/0xb30
> [<ffffffc0001112fc>] worker_thread+0x9c/0x7a8
> [<ffffffc00011a9e8>] kthread+0x190/0x1b0
> [<ffffffc000086ca0>] ret_from_fork+0x10/0x30
>
> Since kernfs_* functions are heavily used by cgroup, so it sounds not
> reasonable to convert kernfs_rename_lock to raw lock.
>
> Create raw version kernfs_path, kernfs_path_len and cgroup_path, which don't
> acquire lock and are used by tracepoints only.
>
And what prevents name from being freed while the tracepoint is reading
it?
Perhaps we need this change as well:
-- Steve
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 996b7742c90b..d2ef153145c0 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -1397,6 +1397,12 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
kn->hash = kernfs_name_hash(kn->name, kn->ns);
kernfs_link_sibling(kn);
+ /*
+ * Tracepoints may be reading the old name. They are protected
+ * by rcu_read_lock_sched().
+ */
+ synchronize_sched();
+
kernfs_put(old_parent);
kfree_const(old_name);
[toc] | [prev] | [next] | [standalone]
| From | "Shi, Yang" <yang.shi@linaro.org> |
|---|---|
| Date | 2016-02-26 20:40 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6wp5-83i-19@gated-at.bofh.it> |
| In reply to | #1344587 |
On 2/26/2016 10:56 AM, Steven Rostedt wrote:
> On Fri, 26 Feb 2016 10:15:05 -0800
> Yang Shi <yang.shi@linaro.org> wrote:
>
>> commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update writeback
>> tracepoints to report cgroup") made writeback tracepoints report cgroup
>> writeback, but it may trigger the below bug on -rt kernel since kernfs_path
>> and kernfs_path_len are called by tracepoints, which acquire sleeping lock.
>>
>> BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:930
>> in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3
>> INFO: lockdep is turned off.
>> Preemption disabled at:[<ffffffc000374a5c>] wb_writeback+0xec/0x830
>>
>> CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20
>> Hardware name: Freescale Layerscape 2085a RDB Board (DT)
>> Workqueue: writeback wb_workfn (flush-7:0)
>> Call trace:
>> [<ffffffc00008d708>] dump_backtrace+0x0/0x200
>> [<ffffffc00008d92c>] show_stack+0x24/0x30
>> [<ffffffc0007b0f40>] dump_stack+0x88/0xa8
>> [<ffffffc000127d74>] ___might_sleep+0x2ec/0x300
>> [<ffffffc000d5d550>] rt_spin_lock+0x38/0xb8
>> [<ffffffc0003e0548>] kernfs_path_len+0x30/0x90
>> [<ffffffc00036b360>] trace_event_raw_event_writeback_work_class+0xe8/0x2e8
>> [<ffffffc000374f90>] wb_writeback+0x620/0x830
>> [<ffffffc000376224>] wb_workfn+0x61c/0x950
>> [<ffffffc000110adc>] process_one_work+0x3ac/0xb30
>> [<ffffffc0001112fc>] worker_thread+0x9c/0x7a8
>> [<ffffffc00011a9e8>] kthread+0x190/0x1b0
>> [<ffffffc000086ca0>] ret_from_fork+0x10/0x30
>>
>> Since kernfs_* functions are heavily used by cgroup, so it sounds not
>> reasonable to convert kernfs_rename_lock to raw lock.
>>
>> Create raw version kernfs_path, kernfs_path_len and cgroup_path, which don't
>> acquire lock and are used by tracepoints only.
>>
>
> And what prevents name from being freed while the tracepoint is reading
> it?
>
> Perhaps we need this change as well:
Thanks for pointing this out. Yes, it looks we need this since the
tracepoints are protected by rcu_read_lock_sched.
Will add this in V2.
Yang
>
> -- Steve
>
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index 996b7742c90b..d2ef153145c0 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -1397,6 +1397,12 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
> kn->hash = kernfs_name_hash(kn->name, kn->ns);
> kernfs_link_sibling(kn);
>
> + /*
> + * Tracepoints may be reading the old name. They are protected
> + * by rcu_read_lock_sched().
> + */
> + synchronize_sched();
> +
> kernfs_put(old_parent);
> kfree_const(old_name);
>
>
[toc] | [prev] | [next] | [standalone]
| From | "Shi, Yang" <yang.shi@linaro.org> |
|---|---|
| Date | 2016-02-26 21:00 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6wIp-8ao-5@gated-at.bofh.it> |
| In reply to | #1344619 |
On 2/26/2016 11:37 AM, Shi, Yang wrote:
> On 2/26/2016 10:56 AM, Steven Rostedt wrote:
>> On Fri, 26 Feb 2016 10:15:05 -0800
>> Yang Shi <yang.shi@linaro.org> wrote:
>>
>>> commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update
>>> writeback
>>> tracepoints to report cgroup") made writeback tracepoints report cgroup
>>> writeback, but it may trigger the below bug on -rt kernel since
>>> kernfs_path
>>> and kernfs_path_len are called by tracepoints, which acquire sleeping
>>> lock.
>>>
>>> BUG: sleeping function called from invalid context at
>>> kernel/locking/rtmutex.c:930
>>> in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3
>>> INFO: lockdep is turned off.
>>> Preemption disabled at:[<ffffffc000374a5c>] wb_writeback+0xec/0x830
>>>
>>> CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20
>>> Hardware name: Freescale Layerscape 2085a RDB Board (DT)
>>> Workqueue: writeback wb_workfn (flush-7:0)
>>> Call trace:
>>> [<ffffffc00008d708>] dump_backtrace+0x0/0x200
>>> [<ffffffc00008d92c>] show_stack+0x24/0x30
>>> [<ffffffc0007b0f40>] dump_stack+0x88/0xa8
>>> [<ffffffc000127d74>] ___might_sleep+0x2ec/0x300
>>> [<ffffffc000d5d550>] rt_spin_lock+0x38/0xb8
>>> [<ffffffc0003e0548>] kernfs_path_len+0x30/0x90
>>> [<ffffffc00036b360>]
>>> trace_event_raw_event_writeback_work_class+0xe8/0x2e8
>>> [<ffffffc000374f90>] wb_writeback+0x620/0x830
>>> [<ffffffc000376224>] wb_workfn+0x61c/0x950
>>> [<ffffffc000110adc>] process_one_work+0x3ac/0xb30
>>> [<ffffffc0001112fc>] worker_thread+0x9c/0x7a8
>>> [<ffffffc00011a9e8>] kthread+0x190/0x1b0
>>> [<ffffffc000086ca0>] ret_from_fork+0x10/0x30
>>>
>>> Since kernfs_* functions are heavily used by cgroup, so it sounds not
>>> reasonable to convert kernfs_rename_lock to raw lock.
>>>
>>> Create raw version kernfs_path, kernfs_path_len and cgroup_path,
>>> which don't
>>> acquire lock and are used by tracepoints only.
>>>
>>
>> And what prevents name from being freed while the tracepoint is reading
>> it?
>>
>> Perhaps we need this change as well:
>
> Thanks for pointing this out. Yes, it looks we need this since the
> tracepoints are protected by rcu_read_lock_sched.
>
> Will add this in V2.
BTW, it sounds this is not the only point where kernfs_node could be
updated, __kernfs_remove should need synchronize_sched too.
Thanks,
Yang
>
> Yang
>
>>
>> -- Steve
>>
>> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
>> index 996b7742c90b..d2ef153145c0 100644
>> --- a/fs/kernfs/dir.c
>> +++ b/fs/kernfs/dir.c
>> @@ -1397,6 +1397,12 @@ int kernfs_rename_ns(struct kernfs_node *kn,
>> struct kernfs_node *new_parent,
>> kn->hash = kernfs_name_hash(kn->name, kn->ns);
>> kernfs_link_sibling(kn);
>>
>> + /*
>> + * Tracepoints may be reading the old name. They are protected
>> + * by rcu_read_lock_sched().
>> + */
>> + synchronize_sched();
>> +
>> kernfs_put(old_parent);
>> kfree_const(old_name);
>>
>>
>
[toc] | [prev] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-02-26 21:20 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6x1L-6H-3@gated-at.bofh.it> |
| In reply to | #1344629 |
On Fri, 26 Feb 2016 11:59:40 -0800 "Shi, Yang" <yang.shi@linaro.org> wrote: > BTW, it sounds this is not the only point where kernfs_node could be > updated, __kernfs_remove should need synchronize_sched too. > Question is, can the kernfs of a cgroup be removed while the cgroup is still active? I don't see the kernfs_rename_lock being held anywhere in that remove. If it can be an issue there with this patch, then it's an issue today, because the kernfs_mutex is not held by the tracepoint. -- Steve
[toc] | [prev] | [next] | [standalone]
| From | "Shi, Yang" <yang.shi@linaro.org> |
|---|---|
| Date | 2016-02-26 21:30 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6xbr-aO-3@gated-at.bofh.it> |
| In reply to | #1344645 |
On 2/26/2016 12:15 PM, Steven Rostedt wrote: > On Fri, 26 Feb 2016 11:59:40 -0800 > "Shi, Yang" <yang.shi@linaro.org> wrote: > > >> BTW, it sounds this is not the only point where kernfs_node could be >> updated, __kernfs_remove should need synchronize_sched too. >> > > Question is, can the kernfs of a cgroup be removed while the cgroup is > still active? Hmm, it sounds unlikely to me. Yang > > I don't see the kernfs_rename_lock being held anywhere in that > remove. If it can be an issue there with this patch, then it's an issue > today, because the kernfs_mutex is not held by the tracepoint. > > -- Steve >
[toc] | [prev] | [next] | [standalone]
| From | "Shi, Yang" <yang.shi@linaro.org> |
|---|---|
| Date | 2016-02-26 21:20 +0100 |
| Subject | Re: [RFC PATCH] kernfs: create raw version kernfs_path_len and kernfs_path |
| Message-ID | <r6x1M-6H-19@gated-at.bofh.it> |
| In reply to | #1344629 |
On 2/26/2016 11:59 AM, Shi, Yang wrote:
> On 2/26/2016 11:37 AM, Shi, Yang wrote:
>> On 2/26/2016 10:56 AM, Steven Rostedt wrote:
>>> On Fri, 26 Feb 2016 10:15:05 -0800
>>> Yang Shi <yang.shi@linaro.org> wrote:
>>>
>>>> commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update
>>>> writeback
>>>> tracepoints to report cgroup") made writeback tracepoints report cgroup
>>>> writeback, but it may trigger the below bug on -rt kernel since
>>>> kernfs_path
>>>> and kernfs_path_len are called by tracepoints, which acquire sleeping
>>>> lock.
>>>>
>>>> BUG: sleeping function called from invalid context at
>>>> kernel/locking/rtmutex.c:930
>>>> in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3
>>>> INFO: lockdep is turned off.
>>>> Preemption disabled at:[<ffffffc000374a5c>] wb_writeback+0xec/0x830
>>>>
>>>> CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20
>>>> Hardware name: Freescale Layerscape 2085a RDB Board (DT)
>>>> Workqueue: writeback wb_workfn (flush-7:0)
>>>> Call trace:
>>>> [<ffffffc00008d708>] dump_backtrace+0x0/0x200
>>>> [<ffffffc00008d92c>] show_stack+0x24/0x30
>>>> [<ffffffc0007b0f40>] dump_stack+0x88/0xa8
>>>> [<ffffffc000127d74>] ___might_sleep+0x2ec/0x300
>>>> [<ffffffc000d5d550>] rt_spin_lock+0x38/0xb8
>>>> [<ffffffc0003e0548>] kernfs_path_len+0x30/0x90
>>>> [<ffffffc00036b360>]
>>>> trace_event_raw_event_writeback_work_class+0xe8/0x2e8
>>>> [<ffffffc000374f90>] wb_writeback+0x620/0x830
>>>> [<ffffffc000376224>] wb_workfn+0x61c/0x950
>>>> [<ffffffc000110adc>] process_one_work+0x3ac/0xb30
>>>> [<ffffffc0001112fc>] worker_thread+0x9c/0x7a8
>>>> [<ffffffc00011a9e8>] kthread+0x190/0x1b0
>>>> [<ffffffc000086ca0>] ret_from_fork+0x10/0x30
>>>>
>>>> Since kernfs_* functions are heavily used by cgroup, so it sounds not
>>>> reasonable to convert kernfs_rename_lock to raw lock.
>>>>
>>>> Create raw version kernfs_path, kernfs_path_len and cgroup_path,
>>>> which don't
>>>> acquire lock and are used by tracepoints only.
>>>>
>>>
>>> And what prevents name from being freed while the tracepoint is reading
>>> it?
>>>
>>> Perhaps we need this change as well:
>>
>> Thanks for pointing this out. Yes, it looks we need this since the
>> tracepoints are protected by rcu_read_lock_sched.
>>
>> Will add this in V2.
>
> BTW, it sounds this is not the only point where kernfs_node could be
> updated, __kernfs_remove should need synchronize_sched too.
Should be synchronize_sched moved into kernfs_put itself, just before
the kfree call since it is called at some places other than
kernfs_remove and kernfs_rename_ns.
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index a4b1db1..89c0c16 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -456,6 +456,12 @@ void kernfs_put(struct kernfs_node *kn)
if (kernfs_type(kn) == KERNFS_LINK)
kernfs_put(kn->symlink.target_kn);
+ /*
+ * Tracepoints may be reading the old name. They are protected
+ * by rcu_read_lock_sched().
+ */
+ synchronize_sched();
+
kfree_const(kn->name);
if (kn->iattr) {
But, kernfs_put might be called recursively, is it fine?
Thanks,
Yang
>
> Thanks,
> Yang
>
>>
>> Yang
>>
>>>
>>> -- Steve
>>>
>>> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
>>> index 996b7742c90b..d2ef153145c0 100644
>>> --- a/fs/kernfs/dir.c
>>> +++ b/fs/kernfs/dir.c
>>> @@ -1397,6 +1397,12 @@ int kernfs_rename_ns(struct kernfs_node *kn,
>>> struct kernfs_node *new_parent,
>>> kn->hash = kernfs_name_hash(kn->name, kn->ns);
>>> kernfs_link_sibling(kn);
>>>
>>> + /*
>>> + * Tracepoints may be reading the old name. They are protected
>>> + * by rcu_read_lock_sched().
>>> + */
>>> + synchronize_sched();
>>> +
>>> kernfs_put(old_parent);
>>> kfree_const(old_name);
>>>
>>>
>>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web