Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3865693ybt; Tue, 23 Jun 2020 12:46:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXtFLPF8qLBKhYbzGqA3ulOEva0Mr6Eb5Z4ZGrpV88zd+qVjdKUgPv376anoIWdDfZB1af X-Received: by 2002:a17:906:784c:: with SMTP id p12mr21671821ejm.123.1592941570755; Tue, 23 Jun 2020 12:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592941570; cv=none; d=google.com; s=arc-20160816; b=yzWxVRUMFwdGbmFrX9VYGh80afFv101qiK3i5rc8LfEDPtf5R7qnTWx4FqC9f84H9Q +KDfbTu7sq6Bbgh1Be749OL8NjqIzzUSCi5Dch8amUsKc+DF6SBiKdItF5/RlI2T4XA4 QJeqPxPsFj2YwHmhxzbe0k3PPeyU1n6xaZXU+pdDixwR4YMcg13OvoyuR4U6Y9kckmLV 9dtxPeEtuvP64T6VwWmu6Cmm5fSVOnZsqCsOfipltOz0EgiU4vuw99t8ySC/dBdM9q+G ScALv8X5rdJuQE4t4VSMrf2cnwJmYY2TKwRbygacMUq736sR6ACwNupHzAm8cPdidBoi CLBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=a8zj1fuShwqowO3Wq+CdKkZzc+/xfslY1sGu/hpora8=; b=trnjqJjE/s2ire10MYvsOLVgDYox1smXx1IR+GpnSkrlW8KSUxYUWk+mgSb+74788D ur2gGUd/Hk9GsRwBUGrWbTaO6i2aIi6ni572M1RXl8lSi0OzO1hDFufWYZzR6xFxlrHt 8AZygHR85M5Dm8/5/pzRTmzn5ANjV2G5uhZ/BtNJwcDLN5RwHqwFn+wXHiafdvBMq2Qc wgsKHZIR+fVpVGCUMj/+84PHC1YnurVREycz9AUVz+hrqflwu+OOaO4uB4I0S85nipgN c4yUq9JjLFFG1+ve33HVpGRAnIZXXc8GU0xQPkHd96lEHtMdqKfslnlgxo4XXhnl+Ny7 eNjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uEYH/6mg"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si7281519edq.110.2020.06.23.12.45.47; Tue, 23 Jun 2020 12:46:10 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uEYH/6mg"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387438AbgFWTpe (ORCPT + 99 others); Tue, 23 Jun 2020 15:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733236AbgFWTpd (ORCPT ); Tue, 23 Jun 2020 15:45:33 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD95C061573 for ; Tue, 23 Jun 2020 12:45:32 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id d4so35320pgk.4 for ; Tue, 23 Jun 2020 12:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=a8zj1fuShwqowO3Wq+CdKkZzc+/xfslY1sGu/hpora8=; b=uEYH/6mg+aXLTRy+8y08DQPhyvQv5FbBjYDESBfb7SWp9kAXLu8qLQxnYBl05eYVLx dJm3DnxAgk7ewTRR29JeLsZxVvzkWEj5NGmIuHUcfp2LxYafb7Ku4i5GA43q6jWk3TAw 4KpXANV7PupjzcXf+SBX0zhodfp+FX0xYZFlls+MG9KzYmK938dODcqLPfMbL67dBjbT KmIdJx4vv09EFGwqClpyOW6t3IS9ud191X9VT3aMywPr6YzOck3sLN5PMAefw+di0B0W CdmcDiOt7J4C2ef5V84R7Xo3IPa8FOW3e/8SeWGCGt2/XEY4blvIm3kywZ6cDEhY9j90 fvRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=a8zj1fuShwqowO3Wq+CdKkZzc+/xfslY1sGu/hpora8=; b=ph4VmTNVuhKoQRiZTvz6xjd4lcrgvl95x7Gk/XTPMRI7z2zpqOmwvr+UakUJWk9Ai8 LbhvsdPaku8jYE37sKSN0h64PsfY9npZML0boNsVJdxl4Odmp69b+lveS/5Hj1oecl+g l81glFWRiaoEmrgfDmulx/ZLTVO7eethGaEHRn4rNF5Bgb2Oz+Z9pvFRFNfDyfRVNDLq B10IoYH0EX5OsXGGwBmIbsTWiREAaCepx1YysjvXG6RQFy0njebqTv5gEVZIKQuBRY+2 ItIr9yva4q9V4PG8SROptVU0lHcU9S7fpx413alltjK3D13N2qQvmYPf+udVa8bqPtm8 fE3w== X-Gm-Message-State: AOAM532M1YIgIwvfWt2fT/6CnuCizLBpDez98pofzwKfiVGGoMW16rLn 9wcCzUWsfqs6eKtT2V/o10I= X-Received: by 2002:a63:5461:: with SMTP id e33mr18025430pgm.56.1592941531706; Tue, 23 Jun 2020 12:45:31 -0700 (PDT) Received: from gmail.com ([2601:600:9b7f:872e:a655:30fb:7373:c762]) by smtp.gmail.com with ESMTPSA id g19sm17668046pfo.209.2020.06.23.12.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 12:45:31 -0700 (PDT) Date: Tue, 23 Jun 2020 12:45:29 -0700 From: Andrei Vagin To: Peter Oskolkov Cc: Aaron Lu , Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Vincent Guittot , Peter Oskolkov , avagin@google.com, "pjt@google.com" , Ben Segall Subject: Re: [RFC PATCH 1/3 v2] futex: introduce FUTEX_SWAP operation Message-ID: <20200623194529.GA71413@gmail.com> References: <20200623132507.GA875@aaronlu-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 11:30:30AM -0700, Peter Oskolkov wrote: ... > > > /** > > > +static int futex_swap(u32 __user *uaddr, unsigned int flags, u32 > > > val, > > > + ktime_t *abs_time, u32 __user *uaddr2) > > > +{ > > > + u32 bitset = FUTEX_BITSET_MATCH_ANY; > > > + struct task_struct *next = NULL; > > > + DEFINE_WAKE_Q(wake_q); > > > + int ret; > > > + > > > + ret = prepare_wake_q(uaddr2, flags, 1, bitset, &wake_q); > > > + if (!wake_q_empty(&wake_q)) { > > > + /* Pull the first wakee out of the queue to swap into. > > > */ > > > + next = container_of(wake_q.first, struct task_struct, > > > wake_q); > > > + wake_q.first = wake_q.first->next; > > > + next->wake_q.next = NULL; > > > + /* > > > + * Note that wake_up_q does not touch wake_q.last, so > > > we > > > + * do not bother with it here. > > > + */ > > > + wake_up_q(&wake_q); > > > > wake_up_q() doesn't seem to serve any purpose in that the above > > assignment of wake_q.first shall make it an empty queue now? > > Also, I don't see a need to touch wake_q.first either so I think we > > can > > get rid of wake_q altogether here. > > The futex at uaddr2 may have more than one waiter, so we cannot assume > that wake_q will be empty when we remove the first element. The third argument of prepare_wake_q is nr_wake which is one in this case, so we can be sure that wake_q will be empty, can't we? > > > > > > + } > > > + if (ret < 0) > > > + return ret; > > > + > > > + return futex_wait(uaddr, flags, val, abs_time, bitset, next); > > > +} > >