All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: hongzha1 <hongzhan.chen@intel.com>
Cc: xenomai@xenomai.org
Subject: Re: [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont
Date: Sun, 24 Jan 2021 18:21:20 +0100	[thread overview]
Message-ID: <87y2gi6yjz.fsf@xenomai.org> (raw)
In-Reply-To: <20210122021240.18768-3-hongzhan.chen@intel.com>


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/kernel/cobalt/dovetail/kevents.c b/kernel/cobalt/dovetail/kevents.c
> index 6aec170d1..0528e2938 100644
> --- a/kernel/cobalt/dovetail/kevents.c
> +++ b/kernel/cobalt/dovetail/kevents.c
> @@ -480,7 +480,75 @@ static void handle_ptrace_cont(void)
>  	 * stopped state, which is what look for in
>  	 * handle_schedule_event().
>  	 */
> -	TODO();
> +	struct task_struct *next_task;
> +	struct xnthread *next;
> +	sigset_t pending;
> +	spl_t s;
> +
> +	cobalt_signal_yield();
> +
> +	next_task = current;
> +	next = xnthread_from_task(next_task);
> +	if (next == NULL)
> +		return;
> +
> +	xnlock_get_irqsave(&nklock, s);
> +
> +	/*
> +	 * Track tasks leaving the ptraced state.  Check both SIGSTOP
> +	 * (NPTL) and SIGINT (LinuxThreads) to detect ptrace
> +	 * continuation.
> +	 */
> +	if (xnthread_test_state(next, XNSSTEP)) {
> +		if (signal_pending(next_task)) {
> +			/*
> +			 * Do not grab the sighand lock here: it's
> +			 * useless, and we already own the runqueue
> +			 * lock, so this would expose us to deadlock
> +			 * situations on SMP.
> +			 */
> +			sigorsets(&pending,
> +				  &next_task->pending.signal,
> +				  &next_task->signal->shared_pending.signal);
> +			if (sigismember(&pending, SIGSTOP) ||
> +			    sigismember(&pending, SIGINT))
> +				goto no_ptrace;
> +		}
> +
> +		/*
> +		 * Do not unregister before the thread migrated.
> +		 * unregister_debugged_thread will then be called by our
> +		 * resume_oob_task.
> +		 */
> +		if (!xnthread_test_info(next, XNCONTHI))
> +			unregister_debugged_thread(next);
> +
> +		xnthread_set_localinfo(next, XNHICCUP);
> +	}
> +

Since we know Dovetail just called us because 'current' is about to
resume from a stopped state, we don't need the hackish code above which
was aimed at determining whether next_task was about to do so
(i.e. resuming from ptrace stop).

> +no_ptrace:
> +	xnlock_put_irqrestore(&nklock, s);
> +
> +	/*
> +	 * Do basic sanity checks on the incoming thread state.
> +	 * NOTE: we allow ptraced threads to run shortly in order to
> +	 * properly recover from a stopped state.
> +	 */
> +	if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
> +		       "hardened thread %s[%d] running in Linux domain?! "
> +		       "(status=0x%x, sig=%d)",
> +		       next->name, task_pid_nr(next_task),
> +		       xnthread_get_state(next),
> +		       signal_pending(next_task)))
> +		XENO_WARN(COBALT,
> +			  !(next_task->ptrace & PT_PTRACED) &&
> +			   !xnthread_test_state(next, XNDORMANT)
> +			  && xnthread_test_state(next, XNPEND),
> +			  "blocked thread %s[%d] rescheduled?! "
> +			  "(status=0x%x, sig=%d)",
> +			  next->name, task_pid_nr(next_task),
> +			  xnthread_get_state(next),
> +			  signal_pending(next_task));
>  }
>  
>  void handle_inband_event(enum inband_event_type event, void *data)

On second thought, we could also drop the remaining check above, since
what is being tested is a very basic Dovetail guarantee, i.e. that
'current' must be running in-band. IOW, receiving ptrace_cont should
lead to a nop when running on top of Dovetail.

-- 
Philippe.


  reply	other threads:[~2021-01-24 17:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
2021-01-24 17:05   ` Philippe Gerum
2021-01-22  2:12 ` [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont hongzha1
2021-01-24 17:21   ` Philippe Gerum [this message]
2021-01-22  2:12 ` [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP hongzha1
2021-01-24 17:06   ` Philippe Gerum
2021-01-22  2:12 ` [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick hongzha1
2021-01-24 17:06   ` Philippe Gerum
2021-01-24 17:05 ` [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot Philippe Gerum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2gi6yjz.fsf@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=hongzhan.chen@intel.com \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.