Received: by 10.223.185.116 with SMTP id b49csp5682759wrg; Wed, 7 Mar 2018 16:31:02 -0800 (PST) X-Google-Smtp-Source: AG47ELtOQhJ6aEfUbtNGP455x6R9Oemoga5SpMo896L3QvJhC2MGy0tZA9prR1do80l4o1yUJTOZ X-Received: by 10.101.76.204 with SMTP id n12mr19759494pgt.249.1520469062119; Wed, 07 Mar 2018 16:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520469062; cv=none; d=google.com; s=arc-20160816; b=ncxcGbK05KG17/gmgWIAH6EIUAoYvVrBB739YOMZnN/UsTT+nVZyMnOWdAZOZnSM7D Fs7/ZSIWFv4kVtCn7EwWgrv9O0Vc2mEMoGXMGNZpkg8GAoL6IpyGoDGiTdIGVGYmhXB8 TkEeFORCIhzFmUly96k8hd0VRd5S8xiitntaFgh3fbyNdS03kE+hTVNZ6cFtwQsO1Luc 2RZBmzqC9cyO625iS8FPCYeynAGIt0imnCtn8stR4t9udUYH9WhhyHhO81EhXyrQenna KT9Hzktk/2i0mTwF9H1sc7e2mskWNXNM4HmLV6mOUjc7Fr3PURlAoiOccyA9/G7cLvde +8iA== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=b7Atjb3/Cn8uhXMIhl6D3zKcvUw79heaG8esWd5XXV8=; b=jbqBLN16SugrG62kqZushAJ9jW68NWk+bDdRMEb6rVktEXB579GtoMW+3jwHEhlqfo C6jHroOtpzNIwrbibLUF/J+7Piil2g2oZ5zI0dy12q+t4lon9U75TVvZVNO1Bz8F1NDx nKKLe1DYyUH27/zYHro26gevYPvcuBicGtOUixMiME//4i3nTuigYs8vctBKK7bGPzIw 1m2mqxIGWYztbIkS9nmXJGUToPz6uQtc3LRcmWVOZ3bcaPv1kk6Nk8SEBoZ5fJAeRdxo n5Bk5WFzwpcZPZl7knYUIoqQuR5agBFAK6HLrhZdh/iLj2dFX2Alxo0hToyINkk6fTqf 38DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=P2hUtp6l; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si12076184pge.565.2018.03.07.16.30.47; Wed, 07 Mar 2018 16:31:02 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=P2hUtp6l; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934387AbeCHA3z (ORCPT + 99 others); Wed, 7 Mar 2018 19:29:55 -0500 Received: from mail-io0-f172.google.com ([209.85.223.172]:46710 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932905AbeCHA3y (ORCPT ); Wed, 7 Mar 2018 19:29:54 -0500 Received: by mail-io0-f172.google.com with SMTP id p78so5093849iod.13 for ; Wed, 07 Mar 2018 16:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=b7Atjb3/Cn8uhXMIhl6D3zKcvUw79heaG8esWd5XXV8=; b=P2hUtp6lDkda661lmnsS60R0t65Ad51LXTjsJBd7QCD9SjCZZYQqJ/DORRQEmHeCVL q85nG0gtUg+rYQiquXJ0Blk+XnI0AaxO6jFM7ylIZElE/v7CUC4W/4ngp7diMq0w1Pvf BcSLSlJG2V18lk4TlRRnH8SunMuV4rNoOxMTmS2qASaiflS8KbgDTdCeGeLh4AueP9kC 2ct+QxahdhvLYdMC1ZO6FqSnxfey4aNVSiaHwoRSDAcDH4kcZd6hmBAU0AxcF4OcRjlI 26u+WnJduBVpe115IjjDhg/ss06xxQesxDhMF6RUgXq/uZk3k21KL81t6BQUW9wEelLf wvHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=b7Atjb3/Cn8uhXMIhl6D3zKcvUw79heaG8esWd5XXV8=; b=VztDoShhT6zsbGtNATjV4Wx0DPjHi7UKL5gWxX9FL3fRlVGP1MAsNAD7Zt3VjdSM4h X1W90QpaU5ghWuFqKL51+RjPSYRxSt7/8Ojt1LFGUOaEZLa2ub/UJMQUmF6dRwHka6pA PfnxcmYA/VfawvH3TVr1p/0NBWclf0/BtpHBRmWucf6ORoDC5HosXb02l5D/UOxkna51 yw1w54c7iIeaFw8lvIBw2jf0v9Uhh6rAPbdAXwRIv3kMuQCkTfOR5K8Ia7bYku7WypPY OZhgIrI2Nf4KrtAUAqk1y3mq/9QfOiEuqkkbe1Y8FUMGHkhUjmDitcwfev9/B6uuq6rb J+Ag== X-Gm-Message-State: APf1xPDjsKvCvKsDGj4qKaGHsK2IQcjZoCqtGldhd/xNClFjFHAyNf/v poVuh1XCbIC4v0/q4Ocnu1bRY6ov84x1GC9fGg4= X-Received: by 10.107.174.14 with SMTP id x14mr28553773ioe.67.1520468993892; Wed, 07 Mar 2018 16:29:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.120.3 with HTTP; Wed, 7 Mar 2018 16:29:53 -0800 (PST) In-Reply-To: <20180307145408.GC3918@linux.vnet.ibm.com> References: <20180306172657.3060270-1-tj@kernel.org> <20180306173316.3088458-1-tj@kernel.org> <20180306173316.3088458-7-tj@kernel.org> <20180307145408.GC3918@linux.vnet.ibm.com> From: Lai Jiangshan Date: Thu, 8 Mar 2018 08:29:53 +0800 X-Google-Sender-Auth: 5N6FE972owGHOrjp14CjfLmu6Oc Message-ID: Subject: Re: [PATCH 7/7] RCU, workqueue: Implement rcu_work To: "Paul E. McKenney" Cc: Tejun Heo , torvalds@linux-foundation.org, Jann Horn , bcrl@kvack.org, viro@zeniv.linux.org.uk, Kent Overstreet , security@kernel.org, LKML , kernel-team@fb.com 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 Wed, Mar 7, 2018 at 10:54 PM, Paul E. McKenney wrote: > On Wed, Mar 07, 2018 at 10:49:49AM +0800, Lai Jiangshan wrote: >> On Wed, Mar 7, 2018 at 1:33 AM, Tejun Heo wrote: >> >> > +/** >> > + * queue_rcu_work_on - queue work on specific CPU after a RCU grace period >> > + * @cpu: CPU number to execute work on >> > + * @wq: workqueue to use >> > + * @rwork: work to queue >> >> For many people, "RCU grace period" is clear enough, but not ALL. >> >> So please make it a little more clear that it just queues work after >> a *Normal* RCU grace period. it supports only one RCU variant. >> >> >> > + * >> > + * Return: %false if @work was already on a queue, %true otherwise. >> > + */ >> >> I'm afraid this will be a hard-using API. >> >> The user can't find a plan B when it returns false, especially when >> the user expects the work must be called at least once again >> after an RCU grace period. >> >> And the error-prone part of it is that, like other queue_work() functions, >> the return value of it is often ignored and makes the problem worse. >> >> So, since workqueue.c provides this API, it should handle this >> problem. For example, by calling call_rcu() again in this case, but >> everything will be much more complex: a synchronization is needed >> for "calling call_rcu() again" and allowing the work item called >> twice after the last queue_rcu_work() is not workqueue style. > > I confess that I had not thought of this aspect, but doesn't the > rcu_barrier() in v2 of this patchset guarantee that it has passed > the RCU portion of the overall wait time? Given that, what I am > missing is now this differs from flush_work() on a normal work item. > > So could you please show me the sequence of events that leads to this > problem? (Again, against v2 of this patch, which replaces the > synchronize_rcu() with rcu_barrier().) I mentioned a subtle use case that user would think it is supported since the comment doesn't disallow it. It is clear that the user expects the work must be called at least once after the API returns the work must be called after an RCU grace period But in the case when the user expects the work must be called at least once again after "queue_rcu_work() + an RCU grace period", the API is not competent to it if the work is queued. Although the user can detect it by the return value of queue_rcu_work(), the user hardly makes his expectation happen by adding appropriate code. > >> Some would argue that the delayed_work has the same problem >> when the user expects the work must be called at least once again >> after a period of time. But time interval is easy to detect, the user >> can check the time and call the queue_delayed_work() again >> when needed which is also a frequent design pattern. And >> for rcu, it is hard to use this design pattern since it is hard >> to detect (new) rcu grace period without using call_rcu(). >> >> I would not provide this API. it is not a NACK. I'm just trying >> expressing my thinking about the API. I'd rather RCU be changed >> and RCU callbacks are changed to be sleepable. But a complete >> overhaul cleanup on the whole source tree for compatibility >> is needed at first, an even more complex job. > > One downside of allowing RCU callback functions to sleep is that > one poorly written callback can block a bunch of other ones. > One advantage of Tejun's approach is that such delays only affect > the workqueues, which are already designed to handle such delays. > > Thanx, Paul > >> > +bool queue_rcu_work_on(int cpu, struct workqueue_struct *wq, >> > + struct rcu_work *rwork) >> > +{ >> > + struct work_struct *work = &rwork->work; >> > + >> > + if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) { >> > + rwork->wq = wq; >> > + rwork->cpu = cpu; >> > + call_rcu(&rwork->rcu, rcu_work_rcufn); >> > + return true; >> > + } >> > + >> > + return false; >> > +} >> > +EXPORT_SYMBOL(queue_rcu_work_on); >> > + >> >