From: Peter Zijlstra <peterz@infradead.org>
To: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Cc: linux-arch@vger.kernel.org, Max Filippov <jcmvbkbc@gmail.com>,
Vineet Gupta <Vineet.Gupta1@synopsys.com>,
linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ARC: Improve cmpxchng syscall implementation
Date: Tue, 19 Jun 2018 11:26:14 +0200 [thread overview]
Message-ID: <20180619092614.GD2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180319110002.27419-1-abrodkin@synopsys.com>
On Mon, Mar 19, 2018 at 02:00:02PM +0300, Alexey Brodkin wrote:
> diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c
> index 5ac3b547453f..d7d3e16133d6 100644
> --- a/arch/arc/kernel/process.c
> +++ b/arch/arc/kernel/process.c
> @@ -47,7 +47,9 @@ SYSCALL_DEFINE0(arc_gettls)
> SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
> {
> struct pt_regs *regs = current_pt_regs();
> + struct page *page;
> + u32 val;
> + int ret;
>
> /*
> * This is only for old cores lacking LLOCK/SCOND, which by defintion
> @@ -60,23 +62,48 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
> /* Z indicates to userspace if operation succeded */
> regs->status32 &= ~STATUS_Z_MASK;
>
> + ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
> + if (!ret)
> + goto fail;
>
> +again:
> preempt_disable();
>
> + ret = __get_user(val, uaddr);
> + if (ret == -EFAULT) {
> + preempt_enable();
> + ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
> + if (ret < 0)
> + goto fail;
> +
> + put_page(page);
> + goto again;
> + } else if (ret)
> + goto fail;
goto fail with preempt disabled.
> +
> + if (val == expected) {
> + ret = __put_user(new, uaddr);
> + if (!ret)
> regs->status32 |= STATUS_Z_MASK;
> }
>
> -done:
> preempt_enable();
>
> - return uval;
> + if (ret == -EFAULT) {
> + ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
> + if (ret < 0)
> + goto fail;
> +
> + put_page(page);
> + goto again;
> + } else if (ret)
> + goto fail;
> +
> + return val;
> +
> +fail:
> + force_sig(SIGSEGV, current);
> + return ret;
> }
Sorry for the delay, but I would write it like:
--- a/arch/arc/kernel/process.c
+++ b/arch/arc/kernel/process.c
@@ -47,7 +47,9 @@ SYSCALL_DEFINE0(arc_gettls)
SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
{
struct pt_regs *regs = current_pt_regs();
- int uval = -EFAULT;
+ struct page *page;
+ u32 val;
+ int ret;
/*
* This is only for old cores lacking LLOCK/SCOND, which by defintion
@@ -60,23 +62,46 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *,
/* Z indicates to userspace if operation succeded */
regs->status32 &= ~STATUS_Z_MASK;
- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
- return -EFAULT;
+ ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
+ if (!ret)
+ goto fail;
+again:
preempt_disable();
- if (__get_user(uval, uaddr))
- goto done;
+ ret = __get_user(val, uaddr);
+ if (ret)
+ goto fault;
- if (uval == expected) {
- if (!__put_user(new, uaddr))
- regs->status32 |= STATUS_Z_MASK;
- }
+ if (val != expected)
+ goto out;
-done:
+ ret = __put_user(new, uaddr);
+ if (ret)
+ goto fault;
+
+ regs->status32 |= STATUS_Z_MASK;
+
+out:
preempt_enable();
+ return val;
+
+fault:
+ preempt_enable();
+
+ if (unlikely(ret != -EFAULT))
+ goto fail;
- return uval;
+ down_read(¤t->mm->mmap_sem);
+ ret = fixup_user_fault(current, current->mm, uaddr, FAULT_FLAG_WRITE, NULL);
+ up_read(¤t->mm->mmap_sem);
+
+ if (likely(!ret))
+ goto again;
+
+fail:
+ force_sig(SIGSEGV, current);
+ return ret;
}
#ifdef CONFIG_ISA_ARCV2
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org,
Vineet Gupta <Vineet.Gupta1@synopsys.com>,
Max Filippov <jcmvbkbc@gmail.com>,
linux-arch@vger.kernel.org
Subject: Re: [PATCH] ARC: Improve cmpxchng syscall implementation
Date: Tue, 19 Jun 2018 11:26:14 +0200 [thread overview]
Message-ID: <20180619092614.GD2494@hirez.programming.kicks-ass.net> (raw)
Message-ID: <20180619092614.L_ZqLqaHMWUhNXE_v0e5hF8nc0zapds3VFRfkznGLoA@z> (raw)
In-Reply-To: <20180319110002.27419-1-abrodkin@synopsys.com>
On Mon, Mar 19, 2018 at 02:00:02PM +0300, Alexey Brodkin wrote:
> diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c
> index 5ac3b547453f..d7d3e16133d6 100644
> --- a/arch/arc/kernel/process.c
> +++ b/arch/arc/kernel/process.c
> @@ -47,7 +47,9 @@ SYSCALL_DEFINE0(arc_gettls)
> SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
> {
> struct pt_regs *regs = current_pt_regs();
> + struct page *page;
> + u32 val;
> + int ret;
>
> /*
> * This is only for old cores lacking LLOCK/SCOND, which by defintion
> @@ -60,23 +62,48 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
> /* Z indicates to userspace if operation succeded */
> regs->status32 &= ~STATUS_Z_MASK;
>
> + ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
> + if (!ret)
> + goto fail;
>
> +again:
> preempt_disable();
>
> + ret = __get_user(val, uaddr);
> + if (ret == -EFAULT) {
> + preempt_enable();
> + ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
> + if (ret < 0)
> + goto fail;
> +
> + put_page(page);
> + goto again;
> + } else if (ret)
> + goto fail;
goto fail with preempt disabled.
> +
> + if (val == expected) {
> + ret = __put_user(new, uaddr);
> + if (!ret)
> regs->status32 |= STATUS_Z_MASK;
> }
>
> -done:
> preempt_enable();
>
> - return uval;
> + if (ret == -EFAULT) {
> + ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
> + if (ret < 0)
> + goto fail;
> +
> + put_page(page);
> + goto again;
> + } else if (ret)
> + goto fail;
> +
> + return val;
> +
> +fail:
> + force_sig(SIGSEGV, current);
> + return ret;
> }
Sorry for the delay, but I would write it like:
--- a/arch/arc/kernel/process.c
+++ b/arch/arc/kernel/process.c
@@ -47,7 +47,9 @@ SYSCALL_DEFINE0(arc_gettls)
SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
{
struct pt_regs *regs = current_pt_regs();
- int uval = -EFAULT;
+ struct page *page;
+ u32 val;
+ int ret;
/*
* This is only for old cores lacking LLOCK/SCOND, which by defintion
@@ -60,23 +62,46 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *,
/* Z indicates to userspace if operation succeded */
regs->status32 &= ~STATUS_Z_MASK;
- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
- return -EFAULT;
+ ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
+ if (!ret)
+ goto fail;
+again:
preempt_disable();
- if (__get_user(uval, uaddr))
- goto done;
+ ret = __get_user(val, uaddr);
+ if (ret)
+ goto fault;
- if (uval == expected) {
- if (!__put_user(new, uaddr))
- regs->status32 |= STATUS_Z_MASK;
- }
+ if (val != expected)
+ goto out;
-done:
+ ret = __put_user(new, uaddr);
+ if (ret)
+ goto fault;
+
+ regs->status32 |= STATUS_Z_MASK;
+
+out:
preempt_enable();
+ return val;
+
+fault:
+ preempt_enable();
+
+ if (unlikely(ret != -EFAULT))
+ goto fail;
- return uval;
+ down_read(¤t->mm->mmap_sem);
+ ret = fixup_user_fault(current, current->mm, uaddr, FAULT_FLAG_WRITE, NULL);
+ up_read(¤t->mm->mmap_sem);
+
+ if (likely(!ret))
+ goto again;
+
+fail:
+ force_sig(SIGSEGV, current);
+ return ret;
}
#ifdef CONFIG_ISA_ARCV2
next prev parent reply other threads:[~2018-06-19 9:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-19 11:00 [PATCH] ARC: Improve cmpxchng syscall implementation Alexey Brodkin
2018-03-19 11:00 ` Alexey Brodkin
2018-03-19 18:29 ` Vineet Gupta
2018-03-19 18:29 ` Vineet Gupta
2018-03-21 11:54 ` Alexey Brodkin
2018-03-21 11:54 ` Alexey Brodkin
2018-04-04 8:56 ` Alexey Brodkin
2018-04-04 8:56 ` Alexey Brodkin
2018-04-18 18:16 ` Vineet Gupta
2018-04-18 18:16 ` Vineet Gupta
2018-06-19 7:58 ` Alexey Brodkin
2018-06-19 7:58 ` Alexey Brodkin
2018-06-19 9:26 ` Peter Zijlstra [this message]
2018-06-19 9:26 ` Peter Zijlstra
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=20180619092614.GD2494@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Alexey.Brodkin@synopsys.com \
--cc=Vineet.Gupta1@synopsys.com \
--cc=jcmvbkbc@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox