Use write_trylock_irqsave in ptrace_attach
PATCH 2/2 Use write_trylock_irqsave in ptrace_attach
Hi,
This patch makes ptrace_attach use write_trylock_irqsave.
--- kernel/ptrace.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
kernel/ptrace.c +3 -4
@@ -160,6 +160,7 @@ int ptrace_may_attach(struct task_structint ptrace_attach (struct task_struct *task) {int retval; +unsigned long flags =0 ; retval = -EPERM ;if (task->pid <=1 )
@@ -178,9 +179,7 @@ repeat:* cpu's that may have task_lock). */ task_lock (task); -local_irq_disable (); -if (!write_trylock (&tasklist_lock)) { -local_irq_enable (); +if (!write_trylock_irqsave (&tasklist_lock, flags)) {task_unlock (task); do { cpu_relax();
@@ -208,7 +207,7 @@ repeat:force_sig_specific (SIGSTOP , task); bad: -write_unlock_irq (&tasklist_lock); +write_unlock_irqrestore (&tasklist_lock, flags);task_unlock (task); out:return retval;
Quoted 34 lines · On Wed, 9 May 2007 14:13:27 +0530 Sripathi Kodi <[email protected]> wrote:
Hi,
This patch makes
ptrace_attachusewrite_trylock_irqsave.Signed-off-by Sripathi Kodi <[email protected]>--- kernel/ptrace.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)Index:
linux-2.6.21/kernel/ptrace.c
===================================================================kernel/ptrace.c +2
-3@@ -160,6 +160,7 @@ int ptrace_may_attach(struct task_structint ptrace_attach (struct task_struct *task) {int retval; +unsigned long flags =0 ; retval = -EPERM ;if (task->pid <=1 )@@ -178,9 +179,7 @@ repeat:* cpu's that may have task_lock). */ task_lock (task); -local_irq_disable (); -if (!write_trylock (&tasklist_lock)) { -local_irq_enable (); +if (!write_trylock_irqsave (&tasklist_lock, flags)) {task_unlock (task); do { cpu_relax();
kernel/ptrace.c repeat: · line 213
Quoted 8 lines
kernel/ptrace.c +1
-1@@ -208,7 +207,7 @@ repeat:force_sig_specific (SIGSTOP , task); bad: -write_unlock_irq (&tasklist_lock); +write_unlock_irqrestore (&tasklist_lock, flags);task_unlock (task); out:return retval;
Your changelogs aren't vey logical. The context for this change is off in a different patch. I reproduce it here:
Quoted 6 lines
I am trying to fix the BUG I mentioned here:
http://lkml.org/lkml/2007/04/20/41. I noticed that an elegant way to solve this problem is to have awrite_trylock_irqsavehelper function. Since we don't have this now, the code inptrace_attachimplements it usinglocal_irq_disableandwrite_trylock. I wish to addwrite_trylock_irqsaveto mainline kernel and then fix the -rt specific problem using this.
I can't imagine why -rt's write_unlock_irq() doesn't do local_irq_enable().
I have no problem adding write_trylock_irqsave() - it fills a gap in the API.
Once we have write_trylock_irqsave() it makes sense to use it here.
One the downside, we added a few bytes to the SMP kernel, which I guess we can live with.
Whether this change is desired in -rt I don't know. Ingo?
I don't think the initialisation of `flags' there was needed?
Quoted 1 line · Andrew Morton
On Wed, 9 May 2007 14:13:27 +0530 Sripathi Kodi <[email protected]>
Quoted 54 lines · wrote:
Quoted 34 lines
Hi,
This patch makes
ptrace_attachusewrite_trylock_irqsave.Signed-off-by Sripathi Kodi <[email protected]>--- kernel/ptrace.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)Index:
linux-2.6.21/kernel/ptrace.c
===================================================================kernel/ptrace.c +2
-3@@ -160,6 +160,7 @@ int ptrace_may_attach(struct task_structint ptrace_attach (struct task_struct *task) {int retval; +unsigned long flags =0 ; retval = -EPERM ;if (task->pid <=1 )@@ -178,9 +179,7 @@ repeat:* cpu's that may have task_lock). */ task_lock (task); -local_irq_disable (); -if (!write_trylock (&tasklist_lock)) { -local_irq_enable (); +if (!write_trylock_irqsave (&tasklist_lock, flags)) {task_unlock (task); do { cpu_relax();kernel/ptrace.c repeat: · line 213
Quoted 8 lines
kernel/ptrace.c +1
-1@@ -208,7 +207,7 @@ repeat:force_sig_specific (SIGSTOP , task); bad: -write_unlock_irq (&tasklist_lock); +write_unlock_irqrestore (&tasklist_lock, flags);task_unlock (task); out:return retval;Your changelogs aren't vey logical. The context for this change is off in
a different patch. I reproduce it here:
Quoted 7 lines
I am trying to fix the BUG I mentioned here:
http://lkml.org/lkml/2007/04/20/41. I noticed that an elegant way to solve this problem is to have awrite_trylock_irqsavehelper function. Since we don't have this now, the code inptrace_attachimplements it usinglocal_irq_disableandwrite_trylock. I wish to addwrite_trylock_irqsaveto mainline kernel and then fix the -rt specific problem using this.
Quoted 1 line
I can't imagine why -rt's
write_unlock_irq()doesn't dolocal_irq_enable().
-rt's write_unlock_irq() does local_irq_enable() while dealing with 'raw' rwlock_t. However tasklist_lock is a regular rwlock_t and hence -rt doesn't save/restore irqs while dealing with it. The probelm in ptrace_attach arises because we explicitely call local_irq_disable(), whereas write_unlock_irq() doesn't restore them.
Quoted 10 lines
I have no problem adding
write_trylock_irqsave()- it fills a gap in the API.Once we have
write_trylock_irqsave()it makes sense to use it here.One the downside, we added a few bytes to the SMP kernel, which I guess we can live with.
Whether this change is desired in -rt I don't know. Ingo?
I will send a patch against -rt in a little while.
Quoted 2 lines
I don't think the initialisation of `flags' there was needed?
Yes, it was not needed. I will send a patch to remove it.
Thanks,
Sripathi.
Hi Andrew,
Quoted 1 line · you
On Wed, 9 May 2007 14:13:27 +0530 Sripathi Kodi <[email protected]>
wrote:
<snip old patch>
Quoted 16 lines
Your changelogs aren't vey logical. The context for this change is off in
a different patch. I reproduce it here:
Quoted 7 lines
I am trying to fix the BUG I mentioned here:
http://lkml.org/lkml/2007/04/20/41. I noticed that an elegant way to solve this problem is to have awrite_trylock_irqsavehelper function. Since we don't have this now, the code inptrace_attachimplements it usinglocal_irq_disableandwrite_trylock. I wish to addwrite_trylock_irqsaveto mainline kernel and then fix the -rt specific problem using this.I can't imagine why -rt's
write_unlock_irq()doesn't dolocal_irq_enable().I have no problem adding
write_trylock_irqsave()- it fills a gap in the API.
Quoted 8 lines
Once we have
write_trylock_irqsave()it makes sense to use it here.One the downside, we added a few bytes to the SMP kernel, which I guess we can live with.
Whether this change is desired in -rt I don't know. Ingo?
I don't think the initialisation of `flags' there was needed?
I removed the initialization of 'flags' in the following patch. Would you like to drop the old one and pick up this?
kernel/ptrace.c +3 -4
@@ -160,6 +160,7 @@ int ptrace_may_attach(struct task_structint ptrace_attach (struct task_struct *task) {int retval; +unsigned long flags; retval = -EPERM ;if (task->pid <=1 )
@@ -178,9 +179,7 @@ repeat:* cpu's that may have task_lock). */ task_lock (task); -local_irq_disable (); -if (!write_trylock (&tasklist_lock)) { -local_irq_enable (); +if (!write_trylock_irqsave (&tasklist_lock, flags)) {task_unlock (task); do { cpu_relax();
@@ -208,7 +207,7 @@ repeat:force_sig_specific (SIGSTOP , task); bad: -write_unlock_irq (&tasklist_lock); +write_unlock_irqrestore (&tasklist_lock, flags);task_unlock (task); out:return retval;