Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp595375pxb; Wed, 18 Aug 2021 09:24:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCZk5dIpE76sH8xwQNEIyjr8Jh6Z/NnwC9qyaZxeqLsHCK/eat0GcGRSC3twHY5TJsSsEH X-Received: by 2002:a17:906:dc4:: with SMTP id p4mr8163908eji.66.1629303870032; Wed, 18 Aug 2021 09:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629303870; cv=none; d=google.com; s=arc-20160816; b=WXsJNflxceUvbTRDHIatbYxRkJVqgpF60aOT+aeIkB5P9NWLP6CvyQ23lQF7U5ZlxQ f42Dz+huBO8Mlm83SUZIvHaiYVwPxOqTrToJHjbQZAN678zFhkUoHnp3yKcBP5SIDpad 6dEwqk51xJNule6PD/moBasPsB/P/aGKEsghIyp7UkNRFEirE/eUXKOrHoKr8ioYlAZ0 qNV3/h4uVpKwsBkXf4dObVQnORmrN8PxWcuCRW9k+hQ/eNVvN/bw3Jlb6XUxO8rOIuZh kpau32Ma82+cFLt1quIvWvp254V34TImsTEB8RzMuUZjJvzwV/nt3/p+LBv/70SqCvzR ylpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=gD/T+KZGXQD5TWJZF0mStYQcCho83/c1Zsy4vgIlBUs=; b=kigswx6ohWJpnmymEPR23OnLdoGJrEuG6c8fNlz3sSssZv0y1rk3ET7I02sZCRoZRq rNEzCbE6OFyO0qnbbsvEcNf04Jmidp1esEzGUGY0bmIee3QwvQ1tceHrAG03RG+sj8Sl 3EMJqGxTqwHh+0RG+ek82XA5ce34dlUSYYNqMzmlqE4GiWuiJWSd3VXo+YH/cRuXrB+O Oj0NCkZv+5EXAqrHbAJdAoMAxxT5YOOu/brLpmra/uGY26wZYinJuJTD2FbsYjMsS8pz BAsBIfrS+8T1qCKrsBC/7Go5KPiStgS0c8sNYL8c9NAqoxkhKnv52RbLUFe3IarMdbSG Hifg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si286395eji.631.2021.08.18.09.24.04; Wed, 18 Aug 2021 09:24:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbhHRQVF (ORCPT + 99 others); Wed, 18 Aug 2021 12:21:05 -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 >