linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] proc: get_wchan() stack unwind only makes sense for sleeping/non-self tasks
@ 2020-11-05 23:11 Vineet Gupta
  2020-11-07  5:08 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Vineet Gupta @ 2020-11-05 23:11 UTC (permalink / raw)
  To: Alexey Dobriyan, Andrew Morton, Ingo Molnar, Alexey Gladkov,
	Peter Zijlstra, Kees Cook, Eric W . Biederman, Vlastimil Babka,
	Michel Lespinasse, Andrei Vagin, Bernd Edlinger, John Johansen,
	Oleg Nesterov
  Cc: linux-kernel, linux-fsdevel, linux-arch, linux-snps-arc, Vineet Gupta

Most architectures currently check this in their get_wchan() implementation
(ARC doesn't hence this patch). However doing this in core code shows
the semantics better so move the check one level up (eventually remove
the boiler-plate code from arches)

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

 #	tools/perf/arch/arc/util/
---
 fs/proc/array.c | 4 +++-
 fs/proc/base.c  | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 65ec2029fa80..081fade5a361 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -519,8 +519,10 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 		unlock_task_sighand(task, &flags);
 	}
 
-	if (permitted && (!whole || num_threads < 2))
+	if (task != current && task->state != TASK_RUNNING &&
+	    permitted && (!whole || num_threads < 2))
 		wchan = get_wchan(task);
+
 	if (!whole) {
 		min_flt = task->min_flt;
 		maj_flt = task->maj_flt;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 0f707003dda5..abd7ec6324c5 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -385,13 +385,15 @@ static const struct file_operations proc_pid_cmdline_ops = {
 static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns,
 			  struct pid *pid, struct task_struct *task)
 {
-	unsigned long wchan;
+	unsigned long wchan = 0;
 	char symname[KSYM_NAME_LEN];
 
 	if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
 		goto print0;
 
-	wchan = get_wchan(task);
+	if (task != current && task->state != TASK_RUNNING)
+		wchan = get_wchan(task);
+
 	if (wchan && !lookup_symbol_name(wchan, symname)) {
 		seq_puts(m, symname);
 		return 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC] proc: get_wchan() stack unwind only makes sense for sleeping/non-self tasks
  2020-11-05 23:11 [RFC] proc: get_wchan() stack unwind only makes sense for sleeping/non-self tasks Vineet Gupta
@ 2020-11-07  5:08 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2020-11-07  5:08 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Alexey Dobriyan, Ingo Molnar, Alexey Gladkov, Peter Zijlstra,
	Kees Cook, Eric W . Biederman, Vlastimil Babka,
	Michel Lespinasse, Andrei Vagin, Bernd Edlinger, John Johansen,
	Oleg Nesterov, linux-kernel, linux-fsdevel, linux-arch,
	linux-snps-arc

On Thu,  5 Nov 2020 15:11:32 -0800 Vineet Gupta <Vineet.Gupta1@synopsys.com> wrote:

> Most architectures currently check this in their get_wchan() implementation
> (ARC doesn't hence this patch). However doing this in core code shows
> the semantics better so move the check one level up (eventually remove
> the boiler-plate code from arches)

It would be nice to clean up the arch callees in the same patch, at
least so it doesn't get forgotten about.  Are you prepared to propose
such a change?


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-07  5:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 23:11 [RFC] proc: get_wchan() stack unwind only makes sense for sleeping/non-self tasks Vineet Gupta
2020-11-07  5:08 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).