Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1946156ybk; Mon, 11 May 2020 08:08:28 -0700 (PDT) X-Google-Smtp-Source: APiQypL+W3P02//73zrEWZE6mzZMwIJblX9l89dBqefDz6mN8EnJi0x+iKvyPl55NxzvwwCCjq/k X-Received: by 2002:a17:906:49c7:: with SMTP id w7mr14150921ejv.29.1589209707903; Mon, 11 May 2020 08:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589209707; cv=none; d=google.com; s=arc-20160816; b=bS3Ml3xzKJwq2utVfJubgzVCYJznzg4l7ZdzmT7cjpJr3WN6BdhYIgb/u6AChZQant Dv0UMKfgTVPEOrJ8aCCyR8Ac1VGymWukCdHNAwAsIiNp0Y+JE4aBa1v+MQUTdjGzDdgI FSf2tiD45T3ZcDyg9KIGaM7ae1nRIQ/gaDV8WlSXQ2+KIWl23dxgr1aF9sbYuEFv9C+N MWlOVGB4KoXlS7nsD1GziIuC5vgNlXhFnZL6vIonZ6iYGhugTaYj1JRLLVtXLyWSZv/L k7r0aweYUq9wM2uOW8AxghBCU4KdNGGgRB6tAVTDAO6wQ3YIBnJxLnMEqbC7j6Ys4Nc/ aC7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7qV0qj2vY3QMnSRpzrXrBmdMrKIn2fose2w49TIcUwA=; b=FcNIHGnVoQjFna0yihVmztZnvpBtYsjgm2C0fJzSFhXFO1NxP5mifcmTR4ww3UIv4D zShXh2k6bz+avHV43mVG9kn1iBtWUExdK3zMimGFXijv1d6FzIZjgJxb0AAL2bz/OlBD 5KC73fdhhaJSQaIAfCWm9Zi4EbzjxhrJ0eDV0ia+/8I20JLNa3hdK4gcav/olH8KYLza b5rYkje3+/qDPin+0jGl7ZD+tj3Q4HBZvdMOVKcBZEF4B87eKqaNP5rGFf0MeVb1ehL+ OAfx2H2R4F8iO6zqhPFN3AAAIbGkeCLVhU+yYOgp7pMHIAd7pqw6ZSU46fONCCy89tuu PYuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=a72v2Ahl; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx17si1547469ejb.467.2020.05.11.08.07.49; Mon, 11 May 2020 08:08:27 -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=@ffwll.ch header.s=google header.b=a72v2Ahl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729659AbgEKPDM (ORCPT + 99 others); Mon, 11 May 2020 11:03:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726438AbgEKPDL (ORCPT ); Mon, 11 May 2020 11:03:11 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F9AC061A0C for ; Mon, 11 May 2020 08:03:10 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id c124so15122008oib.13 for ; Mon, 11 May 2020 08:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7qV0qj2vY3QMnSRpzrXrBmdMrKIn2fose2w49TIcUwA=; b=a72v2AhlK0RMWvywkFLjZmfhzZvIhJmPEoTvBRAk/SnK/GdMXVYpYNlhlUjfan9HTI AYtNSsKZ6jFvdDP3utjWR5R1FanExkscDVG4oyyb4sjLyrHCghImpPzcEV6eLXWps7gE LW8KG+jisGg9a8JULKt2vAZ1gfNW/YVyhRCxg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7qV0qj2vY3QMnSRpzrXrBmdMrKIn2fose2w49TIcUwA=; b=GHeue4DeMonQCgXw/Q0V4GsIgNGs5Jo3Uhe6ZI/1XDv9K9XzqYWaPQDg6E/F5qUnem EOqPTIJZJpqDQWjshQt1JYR3tGf1wBQJjHjhb8zGoo7zB4n/AESt9qFovNl54BmSg38F dafXTPlA4llX0ouSeJLkindJFmAX5heJiqZaWLa7kOgiWyc+vtkGhccNcJX2U762F8h7 ZP3JaZykQT3XoNkMPSXJPqo7Ytu1QvCYfwjAP4T8+f8SVjsgP/E0Q9/DCM0KGokUR/P5 GRTTjrwOeI6Qa15XsIxOrMBJtzZ5DyAPI8PenCmmt7Rp4W6ewlGlWk3BeYi/ieLxBaQz jjDw== X-Gm-Message-State: AGi0PuYrf/DESggcw0VH7rVZDYEzgBsHGhczXnseUdEbm5a8mtWRnQ+X DnsMqNc151PgoAaeB0WgZp8wZYxo1UFwihYyUVKneA== X-Received: by 2002:aca:52d5:: with SMTP id g204mr19998120oib.14.1589209389691; Mon, 11 May 2020 08:03:09 -0700 (PDT) MIME-Version: 1.0 References: <20200508204751.155488-1-lyude@redhat.com> <20200508204751.155488-2-lyude@redhat.com> <20200511144935.GD16815@mtj.duckdns.org> In-Reply-To: <20200511144935.GD16815@mtj.duckdns.org> From: Daniel Vetter Date: Mon, 11 May 2020 17:02:58 +0200 Message-ID: Subject: Re: [RFC v4 01/12] kthread: Add kthread_queue_flush_work() To: Tejun Heo Cc: Lyude Paul , Nouveau Dev , dri-devel , Linux Kernel Mailing List , =?UTF-8?B?VmlsbGUgU3lyasOkbMOk?= , Andrew Morton , Suren Baghdasaryan , Petr Mladek , Greg Kroah-Hartman , "Steven Rostedt (VMware)" , Thomas Gleixner , Ben Dooks , Liang Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 11, 2020 at 4:49 PM Tejun Heo wrote: > > Hello, > > On Fri, May 08, 2020 at 04:46:51PM -0400, Lyude Paul wrote: > > +bool kthread_queue_flush_work(struct kthread_work *work, > > + struct kthread_flush_work *fwork); > > +void __kthread_flush_work_fn(struct kthread_work *work); > > As an exposed interface, this doesn't seem great. What the user wants to say > is "wait for the current instance of this guy" and the interface is asking > them to queue an extra work item whose queueing return state should be > checked and depending on that result wait on its internal completion. > > I'm skeptical this is a good idea in general given that unless you define > "this instance" at the time of queueing the work item which is being > waited-upon, there's no way to guarantee that the instance you're queueing > the flush work item on is the instance you want unless the queuer is holding > external synchronization which prevents the instance from running. That's a > really confusing semantics to expose in the interface. > > What the above means is that the ordering that you want is only defined > through your own locking and that maybe suggests that the sequencing should > be implemented on that side too. It may be a bit more code but a sequence > counter + wait queue might be the better solution here. Aside from this, flush_$stuff interfaces are very easy to deadlock. That's why e.g. flush_work() for normal workqueues has lockdep annotations (lockdep doesn't see through wait/wake_up dependencies without some help because cross-release didn't land for real). So I think if we need something like this, it needs to be a lot more explicit, and come with the right lockdep annotations. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch