Received: by 10.223.185.116 with SMTP id b49csp4551819wrg; Tue, 6 Mar 2018 18:51:15 -0800 (PST) X-Google-Smtp-Source: AG47ELu8bCaOHTGV9KDl/TNU8UDC7vF1y23EjzBRqG0UYqgcBuAg175UoRWdYuiB84wERgTYJerW X-Received: by 2002:a17:902:7a2:: with SMTP id 31-v6mr18716063plj.313.1520391075472; Tue, 06 Mar 2018 18:51:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520391075; cv=none; d=google.com; s=arc-20160816; b=TFs9VIzJ/J4r1wPgbWae61C9YiEeGie+O3bhzihOzkJFHoAKNvy/ZyGqk85XO0Xbnp JpchsFLVMWyVxKCil+yyMNC+fgE0hXbMPE6UDWnhAlg+Mhw7IeR22NNrct72c2Np379J lJFNx8mmpcJggIHef22g/OeKK4Nnc9DzAxoSFqgHr4BkPxn0OxFqFrxAr45nBgZS9LJ5 ONdwI6NBnJTUhC8xv9o7vLeJa9ZkZ0OAFmBzWKzi8UQRdThCfZf1g6FdkordbwaLSzgs nDuY4qgPe6esctLwZD4znfsQ9CZOPzVUoVpKqBd6YDa7jHOB4zRx0rWx4sbWxgrtO/z+ 1bJQ== 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=9U2SAxoZQlgIo4OflKJamALwgH5Ol9f48rXdlwt87Bs=; b=gPEA76JfCYSSSHcJ+qYVwcUmSDUUisF0Ek8xCTx8W9sSDXpVs9RvePzJICzYYcWeNp 7Z60qS2Ttb8ArZDh6dZljcDZ8+nTzj3ie6EFZdPqU1422PP0mXqZPJyUq6Hva3Ertq+8 7fnxrlSDLe5R4QsTGkrh3B0MddvduwrvituRDeCrOV7hlS0GuehchRbleK7nBUcNSycP qnieYSScspMcEsgD/TH6zog0p7jXw2H42MmI5v1ShO1kWaMLmYQMGEVM9Y6pCClHWKSo om1CZIwF6tyOTnjeIwAxyeQBnehFx1BoybRd++aEk7l9wOFtTSrbbdsjcnrVkbkjnslq AYXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UMRklnWX; 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 e13si12916600pff.8.2018.03.06.18.51.00; Tue, 06 Mar 2018 18:51:15 -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=UMRklnWX; 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 S933336AbeCGCtv (ORCPT + 99 others); Tue, 6 Mar 2018 21:49:51 -0500 Received: from mail-it0-f53.google.com ([209.85.214.53]:55411 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932078AbeCGCtu (ORCPT ); Tue, 6 Mar 2018 21:49:50 -0500 Received: by mail-it0-f53.google.com with SMTP id n7so1432924ita.5 for ; Tue, 06 Mar 2018 18:49:50 -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=9U2SAxoZQlgIo4OflKJamALwgH5Ol9f48rXdlwt87Bs=; b=UMRklnWXF3EoMXm+2Hs8ONZoQnTBk/N8Hu2p70fsYqfmVqB5PClZ0WgL6kHTNijm0f aYeiVPGdZVEkXC2vJY9f6XLoDBloE53usBoklibTHQFeHJzveE3whgWuWRY/0ORK+1Cw OoWgQoUlzn9XhjRtxTkPpnLirQb9rzhNNdheSmur+ZPFweCpJVw1q+zSaDmVBJCfmVYn hi7uXxz0FtMKNRDQsv5AKJPVs9m0j+0bmLih/M03HJQIdwzAus6K3w1brDk4eJmNukAO 9UumGJpGMdye3QBH488AIyS2SfVKE+vO4pHdBGJV9wmHxtGRzJUBGh6zCmVQDzFNfkgr /0Kg== 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=9U2SAxoZQlgIo4OflKJamALwgH5Ol9f48rXdlwt87Bs=; b=qhRwz/3rx4WDbDOJ8tFgjaFqSqVbVlFWDove62bxOz4Ef0oEd82glC+tYYB2JOFmZD 04qpdMvTRaF4xm9N9CGrmQEXt0JL/2C4sJTOCQimC6yy/WtzcbnyxCbrca7qCdkME7g6 V0gNbiLMuO2y8vMZ30Dd3E+NiLbBWJOdp1PEsoFnDQ224ylrm4gthaDXzNEbLK96fQDT VgOCVfNfESdzKki0Ma1tln5zmgfsObGYuDHgtGNBZszvFJikI0+SC2r2sCLFUIwJQhJF qo3vhwWBc/NPQoamAnp0m/0uMgGizTxVx4Bv6ma/DYYLYd2oAx7zzWz6SugEl4q3Wl/F lSEA== X-Gm-Message-State: AElRT7EXXHsxNJD19k9x2e80UyWnqc1Rw7NbihNRzqaJc6vDJO2DBKDP dTO7ZqnF6+d8TdfAJqEpUxNunVxA7TXuWd4bChY= X-Received: by 10.36.133.194 with SMTP id r185mr21728711itd.26.1520390990004; Tue, 06 Mar 2018 18:49:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.120.3 with HTTP; Tue, 6 Mar 2018 18:49:49 -0800 (PST) In-Reply-To: <20180306173316.3088458-7-tj@kernel.org> References: <20180306172657.3060270-1-tj@kernel.org> <20180306173316.3088458-1-tj@kernel.org> <20180306173316.3088458-7-tj@kernel.org> From: Lai Jiangshan Date: Wed, 7 Mar 2018 10:49:49 +0800 X-Google-Sender-Auth: YFjM27wPiu_4fVN1_i9GUIfKppQ Message-ID: Subject: Re: [PATCH 7/7] RCU, workqueue: Implement rcu_work To: Tejun Heo Cc: torvalds@linux-foundation.org, jannh@google.com, "Paul E. McKenney" , bcrl@kvack.org, viro@zeniv.linux.org.uk, kent.overstreet@gmail.com, 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 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. 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. > +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); > +