All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesper Nilsson <jesper.nilsson@axis.com>
To: Rabin Vincent <rabin@rab.in>
Cc: jespern@axis.com, linux-cris-kernel@axis.com,
	viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] CRISv32: don't attempt syscall restart on irq exit
Date: Mon, 9 Feb 2015 10:49:54 +0100	[thread overview]
Message-ID: <20150209094954.GI11399@axis.com> (raw)
In-Reply-To: <1423428304-26586-1-git-send-email-rabin@rab.in>

On Sun, Feb 08, 2015 at 09:45:02PM +0100, Rabin Vincent wrote:
> r9 is used to determine whether syscall restarting must be performed or
> not.  Unfortunately, r9 is never set to zero in the non-syscall path,
> and r9 is on top of that a callee-saved register which can be set to
> non-zero by the C functions that are called during IRQ handling.
> 
> This means that if r10 (used for the syscall return value) is one of the
> -ERESTART* values when a hardware interrupt occurs which leads to a
> signal being delivered to the process, the kernel will "restart" a
> syscall which never occurred.  This will lead to the PC being moved back
> by 2 on return to user space.
> 
> Fix the problem by setting r9 to zero in the interrupt path.
> 
> Test case (should loop forever but ends up executing the break 8 trap
> instruction):
> 
>   #include <signal.h>
>   #include <stdlib.h>
>   #include <sys/time.h>
> 
>   void f(int n)
>   {
>   	register int r9 asm ("r9") = 1;
>   	register int r10 asm ("r10") = n;
> 
>           __asm__ __volatile__(
>   		"ba	1f	\n"
>   		"nop		\n"
>   		"break	8	\n"
>   		"1: ba	.	\n"
>   		"nop		\n"
>   		:
>   		: "r" (r9), "r" (r10)
>   		: "memory");
>   }
> 
>   void handler1(int sig) { }
> 
>   int main(int argc, char *argv[])
>   {
>           struct itimerval t1 = { .it_value = {1} };
> 
>           signal(SIGALRM, handler1);
>           setitimer(ITIMER_REAL, &t1, NULL);
> 
>           f(-513); /* -ERESTARTNOINTR */
> 
>           return 0;
>   }
> 
> Signed-off-by: Rabin Vincent <rabin@rab.in>

Nice, added in the CRIS tree for 3.20.

/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@axis.com

      parent reply	other threads:[~2015-02-09  9:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-08 20:45 [PATCH 1/3] CRISv32: don't attempt syscall restart on irq exit Rabin Vincent
2015-02-08 20:45 ` [PATCH 2/3] CRISv32: prevent bogus restarts on sigreturn Rabin Vincent
2015-02-09  9:51   ` Jesper Nilsson
2015-02-08 20:45 ` [PATCH 3/3] CRISv32: handle multiple signals Rabin Vincent
2015-02-09  2:03   ` Guenter Roeck
2015-02-09  9:57     ` Jesper Nilsson
2015-02-09 14:16       ` Guenter Roeck
2015-02-09 16:57       ` Guenter Roeck
2015-02-10  8:21         ` Jesper Nilsson
     [not found]           ` <CAJy5ezog4wmV13muOsVopwYhV7QYE6kwqFtJx0rsh+5Z4bf1tg@mail.gmail.com>
2015-02-10 12:26             ` Guenter Roeck
2015-02-09  9:52   ` Jesper Nilsson
2015-02-09  9:49 ` Jesper Nilsson [this message]

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=20150209094954.GI11399@axis.com \
    --to=jesper.nilsson@axis.com \
    --cc=jespern@axis.com \
    --cc=linux-cris-kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rabin@rab.in \
    --cc=viro@zeniv.linux.org.uk \
    /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.