Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8031580rwr; Wed, 10 May 2023 16:55:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67gWVLr2195tmZyV6B+6UDQpXiWnU+bKr+cyWcynMRC+9RLfSLK3VbYXcIi8L/IQp3B47N X-Received: by 2002:a17:90b:23d7:b0:250:2311:1535 with SMTP id md23-20020a17090b23d700b0025023111535mr20747905pjb.24.1683762911899; Wed, 10 May 2023 16:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683762911; cv=none; d=google.com; s=arc-20160816; b=j+Wiih+4T5KWeDaffyYZ+bwvod3yQLHG45v/56oMxMeOdmhFhFvIxpqrD7nW3sy7eb 36iusCGCEI+2Zfaeq0teHJANFBTlBEe+SlpEqMqdXNFXS5Z5IT/s8FZ3xgb6Itpzj69W hMlU1QOstBgYvsm9RksfFoJPnDfQo5+qmjftF/WPhmUpUWy2bIjjpUlIacqtG5D5bHCZ i9y6Jp9zhI3WhXvplx2ozggnv8IBHTVkxGV2hYOh4ADJO+6h4PhHkunWAQgOZqWQLEbB G4zQzBjllsK016e7N7qsGWqiuR3OhEh+YWghce/QcPo1Mz8irEUFcswk9Q4W5Ej6DRkE Rp5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=FrYZOMsW9A6J3QrAVmIuyDXa9jjcVc3CAiJ5cETqTz4=; b=h3wMUDaJJ9k2kZlmAvpshrYRMn7dX7bQ+DlWmNH4fAVb281bdpONAg2bm38XrO+wYk vabWn+5FI3iFfZjjgcBTQvwy07X+4D0UsiAXqlThWT05b1voTAdkURqfnWbEOw2+xExP lNPOKcXocKfp/FvAmfCn8/3xC2jmeKjsLYEc1PwXqnLjxFcWsiW0yrwXPs0yL7ZuDqpX aGMTPkUp3MMQyMIFDQjHYBnjaTzNRh+tnuAi42xXNuKSjuXILJfYX+N0BDItGyl+ZUiE Snksf04Hlz5yhTiblLJ2DxvrtdvCo97/29Ai7ijovIzMANkVSi+SOJ3nadH/qeVvRG40 nVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aC5k1PPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a17090a018800b0023fb875a929si19085312pjc.106.2023.05.10.16.54.54; Wed, 10 May 2023 16:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aC5k1PPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236563AbjEJXQH (ORCPT + 99 others); Wed, 10 May 2023 19:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbjEJXQG (ORCPT ); Wed, 10 May 2023 19:16:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4C1A1 for ; Wed, 10 May 2023 16:16:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C58A635F4 for ; Wed, 10 May 2023 23:16:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C3BAC433EF; Wed, 10 May 2023 23:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683760560; bh=rBmx1yXHlgjq29yI8RX3oTegeXm2Dm3PwYKq6C9UhEg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aC5k1PPm01evQ+iK2HeIF9cSXIKcxbEuUoyZCyR2X9VeCgMB2UgdJlegPSPTlDM0F cfImJwTp0zC1idPWGAMx8O2kL9CFFgxjiHNpFk6ySlazf+34mwRNFfk97WGsXQM/+w YMcAp7SqpzgUNMnjPNeIfi4PSm4MJ4Y8PFjtaAVlJIjoy1uzXupklJvDphyPIyY4KE EDoCkvhOSTSDEnuXi7H8achdOURjdtuNnzFJrJZhGgZq/q6/NRAtkV64envQw+3CK8 6n39TVzTsKl/xb0IML5aOAsyqzJYNdh9YcL5FBrGsi9+I4EaXJic0+m1v2f50W06Ni gqzEhLRwJHUXQ== Date: Wed, 10 May 2023 16:15:59 -0700 From: Jakub Kicinski To: Peilin Ye Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang Subject: Re: [PATCH net 6/6] net/sched: qdisc_destroy() old ingress and clsact Qdiscs before grafting Message-ID: <20230510161559.2767b27a@kernel.org> In-Reply-To: References: <20230508183324.020f3ec7@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 May 2023 13:11:19 -0700 Peilin Ye wrote: > On Fri, 5 May 2023 17:16:10 -0700 Peilin Ye wrote: > > Thread 1 creates ingress Qdisc A (containing mini Qdisc a1 and a2), then > > adds a flower filter X to A. > > > > Thread 2 creates another ingress Qdisc B (containing mini Qdisc b1 and > > b2) to replace A, then adds a flower filter Y to B. > > > > Thread 1 A's refcnt Thread 2 > > RTM_NEWQDISC (A, RTNL-locked) > > qdisc_create(A) 1 > > qdisc_graft(A) 9 > > > > RTM_NEWTFILTER (X, RTNL-lockless) > > __tcf_qdisc_find(A) 10 > > tcf_chain0_head_change(A) > > mini_qdisc_pair_swap(A) (1st) > > | > > | RTM_NEWQDISC (B, RTNL-locked) > > RCU 2 qdisc_graft(B) > > | 1 notify_and_destroy(A) > > | > > tcf_block_release(A) 0 RTM_NEWTFILTER (Y, RTNL-lockless) > > qdisc_destroy(A) tcf_chain0_head_change(B) > > tcf_chain0_head_change_cb_del(A) mini_qdisc_pair_swap(B) (2nd) > > mini_qdisc_pair_swap(A) (3rd) | > > ... ... > > Looking at the code, I think there is no guarantee that (1st) cannot > happen after (2nd), although unlikely? Can RTNL-lockless RTM_NEWTFILTER > handlers get preempted? Right, we need qdisc_graft(B) to update the appropriate dev pointer to point to b1. With that the ordering should not matter. Probably using the ->attach() callback? > If (1st) happens later than (2nd), we will need to make (1st) no-op, by > detecting that we are the "old" Qdisc. I am not sure there is any > (clean) way to do it. I even thought about: > > (1) Get the containing Qdisc of "miniqp" we are working on, "qdisc"; > (2) Test if "qdisc == qdisc->dev_queue->qdisc_sleeping". If false, it > means we are the "old" Qdisc (have been replaced), and should do > nothing. > > However, for clsact Qdiscs I don't know if "miniqp" is the ingress or > egress one, so I can't container_of() during step (1) ... And we can't be using multiple pieces of information to make the decision since AFAIU mini_qdisc_pair_swap() can race with qdisc_graft(). My thinking was to make sure that dev->miniq_* pointers always point to one of the miniqs of the currently attached qdisc. Right now, on a quick look, those pointers are not initialized during initial graft, only when first filter is added, and may be cleared when filters are removed. But I don't think that's strictly required, miniq with no filters should be fine. > Eventually I created [5,6/6]. It is a workaround indeed, in the sense > that it changes sch_api.c to avoid a mini Qdisc issue. However I think it > makes the code correct in a relatively understandable way, What's your benchmark for being understandable? > without slowing down mini_qdisc_pair_swap() or sch_handle_*gress().