Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp914289ybb; Wed, 25 Mar 2020 12:00:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv9sj8XFCx4UPIU3Sp39sCpf+w5F/Mb95CGC/qKu+b2n0bdP7fXanxXE6knVIG/eeVmvX4g X-Received: by 2002:a9d:4009:: with SMTP id m9mr3475061ote.132.1585162813333; Wed, 25 Mar 2020 12:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585162813; cv=none; d=google.com; s=arc-20160816; b=STbyq37PDLzZz4Y18iTUXoCO48p/8tK4z7cbE4us03of0bN7PnOAzJu66QQl/14r23 ZOYH6F0HfU5y+XePkS5joS9pcd7qyjAfqSg00apy7uP8DDpkHdnI3neZuY4LzTrXmqHj yGU4F4efhciJ4yRuyYpRio5/frSr79TBYiFAA+VnA11jnGG/s60i13bPURsDbEp/gwvI Q/gkL0AylD4STXK2snn5oIXavlhIJClwdvF/TNd4ozZYln8xnlICCgCF75IY49glZsiu 2F10t/CjBPOr08H2MyhVGXzMOxcqHRrgoaqMKH2yg1YwA+OF+gJ/o32SzojGY1bMI1tB f2Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=PB69PDNHfVyEMErVZf/DOTU6Fp0S54BLxc2bNBB/fvU=; b=kyFpP24bfEUhZqMESMkrNFfKdqFsVuSTf/e4Eo14CyM2dFjoqh936Ww9ndhhKXQgJp WyfUcdg7Wx+8Zd7IbPS7lYnd/2a1BIQxweGEOtZQnC2NqLCmzxcMnoidrCeaHpkzOP/m zvOcN7mfCwDHOuL0P5P1FrA2XPozjNWMYMraqkdTB2JSW3Io68AoccYyuP9nXNGm2f/r w6IW/usKi/8ueC16RGO9Xiq8Ty/06Ou5fP0wrlxrCnZmoNB6zTcmSPWhs4PiirlogokH qZ/PfLyYgnLij3D/kHB1iGWNULjMUG8YD1t6LHFKdXYVu3Zo14xloVIZWQrahuBhIfTn Tlew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cieVYahw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si11432002otp.177.2020.03.25.11.59.58; Wed, 25 Mar 2020 12:00:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=cieVYahw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727731AbgCYS6R (ORCPT + 99 others); Wed, 25 Mar 2020 14:58:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbgCYS6R (ORCPT ); Wed, 25 Mar 2020 14:58:17 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE5F52074D; Wed, 25 Mar 2020 18:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585162695; bh=o2BxTxrj2k/0+cVDWwgkhZMSJ2JxXuAjc4rM4LKbWQI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=cieVYahw7ltmho4E7Q/hOVLLfXwjAMsqgxZvokkGkzO+orFVOyE4NVoY5pWcXrudb Br0S73Avfih96H0pJ1oOJRQqF6GD4PNS7Zv1Ht9hw5jh/ouGNkfERP+ZQWXErAoOJq Rvcgq4ETgIy9GR4NyWsd3gRF0YXfuIacIrB8b0Ys= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 8E8BA3520BDC; Wed, 25 Mar 2020 11:58:15 -0700 (PDT) Date: Wed, 25 Mar 2020 11:58:15 -0700 From: "Paul E. McKenney" To: Cong Wang Cc: Thomas Gleixner , syzbot , David Miller , Jamal Hadi Salim , Jiri Pirko , Jakub Kicinski , LKML , Linux Kernel Network Developers , syzkaller-bugs Subject: Re: WARNING: ODEBUG bug in tcindex_destroy_work (3) Message-ID: <20200325185815.GW19865@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <000000000000742e9e05a10170bc@google.com> <87a74arown.fsf@nanos.tec.linutronix.de> <87ftdypyec.fsf@nanos.tec.linutronix.de> <875zeuftwm.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 25, 2020 at 11:36:16AM -0700, Cong Wang wrote: > On Mon, Mar 23, 2020 at 6:01 PM Thomas Gleixner wrote: > > > > Cong Wang writes: > > > On Mon, Mar 23, 2020 at 2:14 PM Thomas Gleixner wrote: > > >> > We use an ordered workqueue for tc filters, so these two > > >> > works are executed in the same order as they are queued. > > >> > > >> The workqueue is ordered, but look how the work is queued on the work > > >> queue: > > >> > > >> tcf_queue_work() > > >> queue_rcu_work() > > >> call_rcu(&rwork->rcu, rcu_work_rcufn); > > >> > > >> So after the grace period elapses rcu_work_rcufn() queues it in the > > >> actual work queue. > > >> > > >> Now tcindex_destroy() is invoked via tcf_proto_destroy() which can be > > >> invoked from preemtible context. Now assume the following: > > >> > > >> CPU0 > > >> tcf_queue_work() > > >> tcf_queue_work(&r->rwork, tcindex_destroy_rexts_work); > > >> > > >> -> Migration > > >> > > >> CPU1 > > >> tcf_queue_work(&p->rwork, tcindex_destroy_work); > > >> > > >> So your RCU callbacks can be placed on different CPUs which obviously > > >> has no ordering guarantee at all. See also: > > > > > > Good catch! > > > > > > I thought about this when I added this ordered workqueue, but it > > > seems I misinterpret max_active, so despite we have max_active==1, > > > more than 1 work could still be queued on different CPU's here. > > > > The workqueue is not the problem. it works perfectly fine. The way how > > the work gets queued is the issue. > > Well, a RCU work is also a work, so the ordered workqueue should > apply to RCU works too, from users' perspective. Users should not > need to learn queue_rcu_work() is actually a call_rcu() which does > not guarantee the ordering for an ordered workqueue. And the workqueues might well guarantee the ordering in cases where the pair of RCU callbacks are invoked in a known order. But that workqueues ordering guarantee does not extend upstream to RCU, nor do I know of a reasonable way to make this happen within the confines of RCU. If you have ideas, please do not keep them a secret, but please also understand that call_rcu() must meet some pretty severe performance and scalability constraints. I suppose that queue_rcu_work() could track outstanding call_rcu() invocations, and (one way or another) defer the second queue_rcu_work() if a first one is still pending from the current task, but that might not make the common-case user of queue_rcu_work() all that happy. But perhaps there is a way to restrict these semantics to ordered workqueues. In that case, one could imagine the second and subsequent too-quick call to queue_rcu_work() using the rcu_head structure's ->next field to queue these too-quick callbacks, and then having rcu_work_rcufn() check for queued too-quick callbacks, queuing the first one. But I must defer to Tejun on this one. And one additional caution... This would meter out ordered queue_rcu_work() requests at a rate of no faster than one per RCU grace period. The queue might build up, resulting in long delays. Are you sure that your use case can live with this? > > > I don't know how to fix this properly, I think essentially RCU work > > > should be guaranteed the same ordering with regular work. But this > > > seems impossible unless RCU offers some API to achieve that. > > > > I don't think that's possible w/o putting constraints on the flexibility > > of RCU (Paul of course might disagree). > > > > I assume that the filters which hang of tcindex_data::perfect and > > tcindex_data:p must be freed before tcindex_data, right? > > > > Refcounting of tcindex_data should do the trick. I.e. any element which > > you add to a tcindex_data instance takes a refcount and when that is > > destroyed then the rcu/work callback drops a reference which once it > > reaches 0 triggers tcindex_data to be freed. > > Yeah, but the problem is more than just tcindex filter, we have many > places make the same assumption of ordering. But don't you also have a situation where there might be a large group of queue_rcu_work() invocations whose order doesn't matter, followed by a single queue_rcu_work() invocation that must be ordered after the earlier group? If so, ordering -all- of these invocations might be overkill. Or did I misread your code? Thanx, Paul