Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1592495
| From | Russell King - ARM Linux <linux@armlinux.org.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/3] futex: remove duplicated code |
| Date | 2017-03-04 14:20 +0100 |
| Message-ID | <thhLk-18A-9@gated-at.bofh.it> (permalink) |
| References | <tgUF4-1cK-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Mar 03, 2017 at 01:27:10PM +0100, Jiri Slaby wrote:
> diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
> index 6795368ad023..cc414382dab4 100644
> --- a/arch/arm/include/asm/futex.h
> +++ b/arch/arm/include/asm/futex.h
> @@ -128,20 +128,10 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
> #endif /* !SMP */
>
> static inline int
> -futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
> +arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
> {
> - int op = (encoded_op >> 28) & 7;
> - int cmp = (encoded_op >> 24) & 15;
> - int oparg = (encoded_op << 8) >> 20;
> - int cmparg = (encoded_op << 20) >> 20;
> int oldval = 0, ret, tmp;
>
> - if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
> - oparg = 1 << oparg;
> -
> - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
> - return -EFAULT;
> -
> #ifndef CONFIG_SMP
> preempt_disable();
> #endif
> @@ -172,17 +162,9 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
> preempt_enable();
> #endif
>
> - if (!ret) {
> - switch (cmp) {
> - case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
> - case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
> - case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
> - case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
> - case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
> - case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
> - default: ret = -ENOSYS;
> - }
> - }
> + if (!ret)
> + *oval = oldval;
> +
> return ret;
> }
>
> diff --git a/kernel/futex.c b/kernel/futex.c
> index b687cb22301c..c5ff9850952f 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -1457,6 +1457,42 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
> return ret;
> }
>
> +static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
> +{
> + int op = (encoded_op >> 28) & 7;
> + int cmp = (encoded_op >> 24) & 15;
> + int oparg = (encoded_op << 8) >> 20;
> + int cmparg = (encoded_op << 20) >> 20;
Hmm. oparg and cmparg look like they're doing these shifts to get sign
extension of the 12-bit values by assuming that "int" is 32-bit -
probably worth a comment, or for safety, they should be "s32" so it's
not dependent on the bit-width of "int".
> + int oldval, ret;
> +
> + if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
> + oparg = 1 << oparg;
I guess it doesn't matter that oparg can be >= the bit size of oparg
(so large values produce an undefined result) as it's no different
from userspace trying to do the same with large shifts.
> +
> + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
> + return -EFAULT;
> +
> + ret = arch_futex_atomic_op_inuser(op, oparg, &oldval, uaddr);
> + if (ret)
> + return ret;
> +
> + switch (cmp) {
> + case FUTEX_OP_CMP_EQ:
> + return oldval == cmparg;
> + case FUTEX_OP_CMP_NE:
> + return oldval != cmparg;
> + case FUTEX_OP_CMP_LT:
> + return oldval < cmparg;
> + case FUTEX_OP_CMP_GE:
> + return oldval >= cmparg;
> + case FUTEX_OP_CMP_LE:
> + return oldval <= cmparg;
> + case FUTEX_OP_CMP_GT:
> + return oldval > cmparg;
> + default:
> + return -ENOSYS;
> + }
> +}
> +
> /*
> * Wake up all waiters hashed on the physical page that is mapped
> * to this virtual address:
As it's no worse than our existing code, for the above,
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Thanks.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/3] futex: remove duplicated code Jiri Slaby <jslaby@suse.cz> - 2017-03-03 13:40 +0100
[PATCH 2/3] futex: fix decoding of operation Jiri Slaby <jslaby@suse.cz> - 2017-03-03 19:30 +0100
[PATCH 3/3] futex: make the encoded_op decoding readable Jiri Slaby <jslaby@suse.cz> - 2017-03-03 19:30 +0100
Re: [PATCH 3/3] futex: make the encoded_op decoding readable Jiri Slaby <jslaby@suse.cz> - 2017-03-05 09:00 +0100
Re: [PATCH 1/3] futex: remove duplicated code Heiko Carstens <heiko.carstens@de.ibm.com> - 2017-03-03 21:10 +0100
Re: [PATCH 1/3] futex: remove duplicated code Michael Ellerman <mpe@ellerman.id.au> - 2017-03-04 14:00 +0100
Re: [PATCH 1/3] futex: remove duplicated code Russell King - ARM Linux <linux@armlinux.org.uk> - 2017-03-04 14:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code "H. Peter Anvin" <hpa@zytor.com> - 2017-03-04 20:30 +0100
Re: [PATCH 1/3] futex: remove duplicated code Stafford Horne <shorne@gmail.com> - 2017-03-04 22:40 +0100
Re: [PATCH 1/3] futex: remove duplicated code "H. Peter Anvin" <hpa@zytor.com> - 2017-03-05 00:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code Stafford Horne <shorne@gmail.com> - 2017-03-05 00:40 +0100
Re: [PATCH 1/3] futex: remove duplicated code Jiri Slaby <jslaby@suse.cz> - 2017-03-06 09:50 +0100
Re: [PATCH 1/3] futex: remove duplicated code "H. Peter Anvin" <hpa@zytor.com> - 2017-03-06 10:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code Geert Uytterhoeven <geert@linux-m68k.org> - 2017-03-06 15:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code "H. Peter Anvin" <hpa@zytor.com> - 2017-03-05 00:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code Rob Landley <rob@landley.net> - 2017-03-09 05:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code "H. Peter Anvin" <hpa@zytor.com> - 2017-03-09 06:10 +0100
Re: [PATCH 1/3] futex: remove duplicated code Rich Felker <dalias@libc.org> - 2017-03-09 23:50 +0100
Re: [PATCH 1/3] futex: remove duplicated code Rich Felker <dalias@libc.org> - 2017-03-06 03:20 +0100
Re: [PATCH 1/3] futex: remove duplicated code Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2017-03-09 23:50 +0100
csiph-web