From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51248C4338F for ; Wed, 18 Aug 2021 16:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DF8960231 for ; Wed, 18 Aug 2021 16:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbhHRQVG (ORCPT ); Wed, 18 Aug 2021 12:21:06 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:42338 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbhHRQVE (ORCPT ); Wed, 18 Aug 2021 12:21:04 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 97D4A1F427CD Subject: Re: [PATCH v5 02/11] futex2: Implement vectorized wait To: Arnd Bergmann Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Linux Kernel Mailing List , Steven Rostedt , Sebastian Andrzej Siewior , Collabora kernel ML , Gabriel Krisman Bertazi , pgriffais@valvesoftware.com, z.figura12@gmail.com, Joel Fernandes , malteskarupke@fastmail.fm, Linux API , Florian Weimer , GNU C Library , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan , Arnaldo Carvalho de Melo , Jonathan Corbet , Peter Oskolkov , Andrey Semashev , Davidlohr Bueso , Nicholas Piggin , Adhemerval Zanella References: <20210709001328.329716-1-andrealmeid@collabora.com> <20210709001328.329716-3-andrealmeid@collabora.com> From: =?UTF-8?Q?Andr=c3=a9_Almeida?= Message-ID: Date: Wed, 18 Aug 2021 13:20:16 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnd, Thank you for your feedback. Às 05:50 de 17/08/21, Arnd Bergmann escreveu: > On Fri, Jul 9, 2021 at 2:13 AM André Almeida wrote: >> >> Add support to wait on multiple futexes. This is the interface >> implemented by this syscall: >> >> futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes, >> unsigned int flags, struct timespec *timo) >> >> struct futex_waitv { >> __u64 val; >> void *uaddr; >> unsigned int flags; >> }; > > You should generally try to avoid structures with implicit padding > like this one. > >> arch/x86/entry/syscalls/syscall_32.tbl | 1 + >> arch/x86/entry/syscalls/syscall_64.tbl | 1 + >> include/linux/compat.h | 9 + >> include/linux/futex.h | 108 ++++++-- >> include/uapi/asm-generic/unistd.h | 4 +- > > I would split out the syscall table changes from the implementation, but then > do the table changes for all architectures, at least when you get to a version > that gets close to being accepted. > Ok, I'll make sure to do that. >> +#ifdef CONFIG_COMPAT >> +/** >> + * compat_futex_parse_waitv - Parse a waitv array from userspace >> + * @futexv: Kernel side list of waiters to be filled >> + * @uwaitv: Userspace list to be parsed >> + * @nr_futexes: Length of futexv >> + * >> + * Return: Error code on failure, pointer to a prepared futexv otherwise >> + */ >> +static int compat_futex_parse_waitv(struct futex_vector *futexv, >> + struct compat_futex_waitv __user *uwaitv, >> + unsigned int nr_futexes) >> +{ >> + struct compat_futex_waitv aux; >> + unsigned int i; >> + >> + for (i = 0; i < nr_futexes; i++) { >> + if (copy_from_user(&aux, &uwaitv[i], sizeof(aux))) >> + return -EFAULT; >> + >> + if ((aux.flags & ~FUTEXV_WAITER_MASK) || >> + (aux.flags & FUTEX_SIZE_MASK) != FUTEX_32) >> + return -EINVAL; >> + >> + futexv[i].w.flags = aux.flags; >> + futexv[i].w.val = aux.val; >> + futexv[i].w.uaddr = compat_ptr(aux.uaddr); >> + futexv[i].q = futex_q_init; >> + } >> + >> + return 0; >> +} >> + >> +COMPAT_SYSCALL_DEFINE4(futex_waitv, struct compat_futex_waitv __user *, waiters, >> + unsigned int, nr_futexes, unsigned int, flags, >> + struct __kernel_timespec __user *, timo) >> +{ >> + struct hrtimer_sleeper to; >> + struct futex_vector *futexv; >> + struct timespec64 ts; >> + ktime_t time; >> + int ret; > > It would be nice to reduce the duplication a little. compat_sys_futex_waitv() > and sys_futex_waitv() only differ by a single line, in which they call > a different > parse function, and the two parse functions only differ in the layout of the > user space structure. The get_timespec64() call already has an > in_compat_syscall() check in it, so I would suggest having a single entry > point for native and compat mode, but either having the parse function > add another such check or making the structure layout compatible. > > The normal way of doing this is to have a __u64 value instead of the pointer, > and then using u64_to_uptr() for the conversion. It might be nice to > add a global > > typedef __u64 __kernel_uptr_t; > > for this purpose. > You're right, I could save a lot of lines doing that. I wasn't aware that get_timespec64() was "compat-aware". I'll apply those changes for my next version. > Arnd >