Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3680211ybh; Mon, 5 Aug 2019 23:28:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1/eZb3sqwtCki44CF9Ej6OEizUVvvVEER++xnDL4DbdtieMoHKhMttcp6SiR5q+vxiAUl X-Received: by 2002:a17:90a:d817:: with SMTP id a23mr1522490pjv.54.1565072897330; Mon, 05 Aug 2019 23:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565072897; cv=none; d=google.com; s=arc-20160816; b=YamQxgRa2aChwLG1FeUpE8dfcEWIFThU9MCzBjOETM9cHK8K83zDUM8S28kFmYHnKu Qe3CZ3ZHjuERVd+fZDyCZszak7fZ4E7byJ+E5MU5ZPyN8huuaVO59r6TAhGRlxmI++oP utnTfMUg5EX1lW6fVUL85c0Bryeuu9s3xCMmD8RbAFsJNb84f3RATBrr7p7DZEzETQyr Lzxb7a9G4OXl/h6Jad9F8dV0mMMF7xQ92tn9QOUGSeMiVqkXE9lnQ9Ld9Y/jd1vxQkji qYVg7ArBaM8+WLt7hBGPYN6cUd5+8YlOVKhT+XE2Okg4FTxKkJRZG1N4yedi45st8FsK xTNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:organization:subject:cc:to:from; bh=EZZK22WgmyaKxYN3ZW49U/QpNc8SQROpODEDzLaHjBk=; b=GfbgLY1V3BkvkaP20P8NWxzw5HBiubTZR1vk6AYAM8JCZzSk/+3MlUVEefCPQ1br8C bkF3SbmftCaSXBxAzmdKv2edn2xQ74I2JMwsRVXsicEgpuFHUsLCythLHEunRVrebziz io2j9XJ5UxVRlUBlGWvoW9Ktjvb791y18ApJWSMsaoYSj4yb9ydC0fwY1X0FalP1UZve vKFgh+fU8kfbCEICE1N9nWu4ZS0N0YCWQR8SQGe/hcPbbNGLcnPbufH5suGUg6R2EgW6 AaR7qLcQLv46575IQuZMsZE7uzJk1dnou50jNJx4s/AnY+Hi2dNKkZ59mipst1EOrxf2 uSqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u1si41462976plb.234.2019.08.05.23.28.01; Mon, 05 Aug 2019 23:28:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1731842AbfHFG0r (ORCPT + 99 others); Tue, 6 Aug 2019 02:26:47 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:34130 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731731AbfHFG0q (ORCPT ); Tue, 6 Aug 2019 02:26:46 -0400 Received: from localhost (unknown [IPv6:2804:431:c7f4:594:fd52:920a:1b6d:89c5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 71D7728A74B; Tue, 6 Aug 2019 07:26:44 +0100 (BST) From: Gabriel Krisman Bertazi To: Peter Zijlstra Cc: tglx@linutronix.de, mingo@redhat.com, dvhart@infradead.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Zebediah Figura , Steven Noonan , "Pierre-Loup A . Griffais" , viro@zeniv.linux.org.uk, jannh@google.com Subject: Re: [PATCH RFC 2/2] futex: Implement mechanism to wait on any of several futexes Organization: Collabora References: <20190730220602.28781-1-krisman@collabora.com> <20190730220602.28781-2-krisman@collabora.com> <20190731120600.GT31381@hirez.programming.kicks-ass.net> Date: Tue, 06 Aug 2019 02:26:38 -0400 In-Reply-To: <20190731120600.GT31381@hirez.programming.kicks-ass.net> (Peter Zijlstra's message of "Wed, 31 Jul 2019 14:06:00 +0200") Message-ID: <85imra6c81.fsf@collabora.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Peter Zijlstra writes: > >> +static int futex_wait_multiple(u32 __user *uaddr, unsigned int flags, >> + u32 count, ktime_t *abs_time) >> +{ >> + struct futex_wait_block *wb; >> + struct restart_block *restart; >> + int ret; >> + >> + if (!count) >> + return -EINVAL; >> + >> + wb = kcalloc(count, sizeof(struct futex_wait_block), GFP_KERNEL); >> + if (!wb) >> + return -ENOMEM; >> + >> + if (copy_from_user(wb, uaddr, >> + count * sizeof(struct futex_wait_block))) { >> + ret = -EFAULT; >> + goto out; >> + } > > I'm thinking we can do away with this giant copy and do it one at a time > from the other function, just extend the storage allocated there to > store whatever values are still required later. Hey Peter, Thanks for your very detailed review. it is deeply appreciated. My apologies for the style issues, I blindly trusted checkpatch.pl, when it said it was ready for submission. I'm not sure I get the suggestion here. If I understand the code correctly, once we do it one at a time, we need to queue_me() each futex and then drop the hb lock, before going to the next one. Once we go to the next one, we need to call get_user_pages (and now copy_from_user), both of which can sleep, and on return set the task state to TASK_RUNNING. This opens a window where we can wake up the task but it is not in the right sleeping state, which from the comment in futex_wait_queue_me(), seems problematic. This is also the reason why I wanted to split the key memory pin from the actual read in patch 1/2. Did you consider this problem or is it not a problem for some reason? What am I missing? -- Gabriel Krisman Bertazi