From patchwork Tue Dec 7 14:57:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12662015 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73229C433F5 for ; Tue, 7 Dec 2021 14:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238313AbhLGPBG (ORCPT ); Tue, 7 Dec 2021 10:01:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238310AbhLGPBF (ORCPT ); Tue, 7 Dec 2021 10:01:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615EBC061574 for ; Tue, 7 Dec 2021 06:57:35 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 1EA64B817EC for ; Tue, 7 Dec 2021 14:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9563C341C1; Tue, 7 Dec 2021 14:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638889052; bh=O47jmrRDjOqYaVTsMs5uVIXRfmyBjANilOvVR8A0lVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BOGDVLAQtLPYfTYXafDw9t5is/FCsw9C4UUlC3x1lV7iGTDQNb1H7PnQd7LC32nAV pIYQRHKqWNCzmRpvDJOkc2LRniwwQS6sWqEjs7eC2/URqR29aLL7Z9FAx0FI/UoVE3 Gikw53ruDMi9E3PYc2dbXWYosRVnSIc/LaiEHT3gg3O8rgl9sygaTiFJ1kcMN2Kg4m BNJKTNAY4Tskp4mVG1Wz7F5GcNXRC5Xxgvr5FAWbFNVQAHT5i3ESVSmO8VNsNWjSo8 /3dfZlFgf78R2mXerA+2+EDfowxAkUWeoDrSZkcJ/ach4TPYbCXpmcRr0xLYHMcfyH 5LM+KBDtSFPfg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , alexander.duyck@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 1/2] net-sysfs: update the queue counts in the unregistration path Date: Tue, 7 Dec 2021 15:57:24 +0100 Message-Id: <20211207145725.352657-2-atenart@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211207145725.352657-1-atenart@kernel.org> References: <20211207145725.352657-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When updating Rx and Tx queue kobjects, the queue count should always be updated to match the queue kobjects count. This was not done in the net device unregistration path, fix it. Tracking all queue count updates will allow in a following up patch to detect illegal updates. Signed-off-by: Antoine Tenart --- net/core/net-sysfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 3b2cdbbdc858..33f408c24205 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1808,6 +1808,9 @@ static void remove_queue_kobjects(struct net_device *dev) net_rx_queue_update_kobjects(dev, real_rx, 0); netdev_queue_update_kobjects(dev, real_tx, 0); + + dev->real_num_rx_queues = 0; + dev->real_num_tx_queues = 0; #ifdef CONFIG_SYSFS kset_unregister(dev->queues_kset); #endif From patchwork Tue Dec 7 14:57:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12662017 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF167C433EF for ; Tue, 7 Dec 2021 14:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238315AbhLGPBI (ORCPT ); Tue, 7 Dec 2021 10:01:08 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:55604 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238310AbhLGPBI (ORCPT ); Tue, 7 Dec 2021 10:01:08 -0500 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 ams.source.kernel.org (Postfix) with ESMTPS id 1AC43B817EE for ; Tue, 7 Dec 2021 14:57:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 290ABC341C1; Tue, 7 Dec 2021 14:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638889055; bh=16Flt33efDjvoT5248LZ4hJJ36k614a6c89HvrrFups=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSWNIVXMn/pdqpVa7T+X4rpnBVBYCkVy3lxoMRIonn2YhN5l/kxD0+HzJFhYMz+xA 6CBKpBFK4/PVuZVzChHWm/weMOg7waTO1V+sgwaTSU+zOcKLp3fHZ8WY58867MyTBD PUHc/E/az7IK2alIbRqn3XkM7QQwfV5MBBC9bxIm9npMZszYoJVh+XbFm8kUWwZuF+ nnaaVY7OiklBVfzXNE6/G4xiYmnVY76BmBxjYC543ibe60JY5btI7/l4TRdKp4qrFU RP642BifSUzy5zf4LjQ9E19uY2Y0F2Y/XjdOB1z/TX3R3FZBPGFy69YdfV6hw0nTyY oTSryttsaWA6g== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , alexander.duyck@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 2/2] net-sysfs: warn if new queue objects are being created during device unregistration Date: Tue, 7 Dec 2021 15:57:25 +0100 Message-Id: <20211207145725.352657-3-atenart@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211207145725.352657-1-atenart@kernel.org> References: <20211207145725.352657-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Calling netdev_queue_update_kobjects is allowed during device unregistration since commit 5c56580b74e5 ("net: Adjust TX queue kobjects if number of queues changes during unregister"). But this is solely to allow queue unregistrations. Any path attempting to add new queues after a device started its unregistration should be fixed. This patch adds a warning to detect such illegal use. Signed-off-by: Antoine Tenart --- net/core/net-sysfs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 33f408c24205..53ea262ecafd 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1694,6 +1694,13 @@ netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num) int i; int error = 0; + /* Tx queue kobjects are allowed to be updated when a device is being + * unregistered, but solely to remove queues from qdiscs. Any path + * adding queues should be fixed. + */ + WARN(dev->reg_state == NETREG_UNREGISTERING && new_num > old_num, + "New queues can't be registered after device unregistration."); + for (i = old_num; i < new_num; i++) { error = netdev_queue_add_kobject(dev, i); if (error) {