From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796568314; b=jky0w2g3d94Rm6sNewUS9rVj5R4ULPeFSJIWcp2y3zU65d8kR5ugHQA2umYX4hFJFAOT r7MlwCiio6e1e1F8n83DXRUeAPQNpF2C4s+ApMcyG9Jci6Y+1wREU0rbZ8WNxAifNBfZw cd56GTMMNZ94XQ/QcSjuyPQjwEU4oNiZyjM7+JcF1/brsMbxsLCoOKNcOiID3pcIGnPyZ 59Cl6NEsqLSMQdG2GZ3rgiHDcUAlhvrUL9X3O7EpR+EYaj7VAdZk4p6weG5x+LRrYGRSj A0X6Se+w5W2mo1nhJwIMdXXdBiThQo7rLjHUEZOJs0oz1Oov8v21xeXGgTDFnxc8qYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796568314; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=ai2tK9fEeBq31V9lSgX0VAB8rkTwFuo4HUjEvNZ5h04=; b=MGnY3MsaiHnx8XA/SC34qGSms8QBkid2BBlteMu0RpXwScRHdQqiRG4xrTkcid90DF2m 1UEZVNzPUGss9WOS/CX8MgvGsa4E53TCIVJJgeq0tqMiUO5DgxkiiyIH3d5V8VxhPS317 Ch7NjykS8K6I81lmUQWD3tg9HaFIAmWvI/1uxcr+I4QVtvIfCzQiINOH7Uu8sl/Z+QAmV RruWKXxeRPDFxn5u0kVGs5SQtFTr8F6+e24Guy18LPBOom+NIH778eDYLTdRUM7seHZPO HSA+W+33B0NfLVrhCwJNggjtfD2T3PyC69UOZ2F1V/fnDaxX+EDpYqysF/un2j7f5Iw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b2+lTuOc; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 965CA606A322 for ; Sun, 6 Dec 2026 14:45:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 965CA606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b2+lTuOc Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-386c71feeeaso3207895eec.0 for ; Sun, 06 Dec 2026 06:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796568313; x=1797173113; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ai2tK9fEeBq31V9lSgX0VAB8rkTwFuo4HUjEvNZ5h04=; b=b2+lTuOcAnlXMNI/1/RZ+H/BQ70zg7270pljXxGblC6fsSmUutWAVWNnPSGVMUowfL uTM9CLFUD4keCr+V5aEwyadCyfCzyTXZf4VWcpuc3vFsQ1a9LAIdM5CFrN7BfXzJvFSd F4HERzN7JhA4uOGks5wSVhZy0z1FBc5oMThj6/8LWpeYcmmk/MaeKeMsmyQe5j4WlRTA CCYREoSrjA7Cq9fvWfOrax3404/ztkQHx6o8zA7NMkYLZniLngjGP+OTTfEA/Jw9Saph KapFe2yFh96f3yJLHNis6v1RC5HpKd9mkjnToqPHAMzQrva3QrIgLq0TORH5VbNt1UTe BsUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796568313; x=1797173113; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ai2tK9fEeBq31V9lSgX0VAB8rkTwFuo4HUjEvNZ5h04=; b=erAynz6BSpfb62Jm3H3MnTGBGVPuseASXM51ua2w+ZAebmdUNMHivoQ0PQNEYyWbLY CyvYC32nLGeLvVoZTttWdhdJVl7gKzSoa02cmcPHZrymlK+FKAlfWDOiCGEr77JUtYyN 8GAIoVpVV1Saxe4Gxcem1XAtsuPMBKxU+RtUllOBG54MY+T8P03wk4n6Wh54WIS+hr86 7tfDUjAdpjiAgQA+UCuFWthL9xRbfrFNd2IGQ26jlP+PZ6YlP7l2pHtMuaAOCA6i4aOO so9uMen+gRrr1r4YnN7pTINeZO2aNKY0OxXZyufssJ6UbnPrdNyqSpYpTpTJfLmLYFbf pREw== X-Forwarded-Encrypted: i=1; AL+hErEZp19a85DLWyDwjPPHdnlZ2rz27malSCeCyDV9uwSNEqisXAOtif+aAvSEq05KJNHW+l9R2dq69VLAf84=@vger.kernel.org X-Gm-Message-State: AB4q+uFIXMyXMwsMJHW8NfVAN+HP7y/TRLWJJ8hcP8nO4+cNXn7ZP4r5 5WGkhyQAF9R8YUSG8VTw8fKrxbS2DlcLKP2eeZk28pi6y26BAiMuce4O X-Gm-Gg: AZFdTZeGYNgYnVdgW+bTSZo9UxM44MRShsk/mKJGRNEBKyPd9o7TBFle5oRIcwut6VP EKwppeglz5tJu5HjOQ1A8KX/uPiXCRNNrBCjVp3PFTKTBg9LCikjZnefeiiWLHw9QHeXwEJwEyB 0DXeFRxuYc0BKC1sQiYjs0m/lmIGeCjVJvscxxCxhLqNaaSkDVAIjezxaAfd3FLj9qu9s+10aam BlaCNgKOul88AMKqp0OHeP83JJQAi6F2sr6nM0ROWdtmZ+Hb+Ui8qMY7yHVaVajznuCVy8iBvwE R1SgOJDzzv+OdHZ18gmUNc6QUczZHB7my7+1UelRqW5lp9Tp4+Qzvob/++aOIk+8HkfjDnhkRFt Zp5kFvahZVRFbKqiPZ1AOpjmlxTtKB6T9hWtl2CxRm76IchA+OjfLZ50x7bvL10Zi+wQKG72arW 8aK+C2PI7GfBnQlnheFtmdl17VSaJ0GSehYvHkKOCsw5FNDSVNO5azTODeOKQYNyfpkFIt2oDhu WmiQmv/K3Ob80O8g6bJgOKN02+SGPcc2ESsZosvNs7z5r6BH/aOwFdo2CfrIf0jGP/XEobTLIe9 pSBTC22HQFljXzAhX2OdYJQQDFXLh/wh0uZljArCfPgwI/bj/V3/tJYCfcxhxDr02I69gErYd6h Zh+4xiunyRhkwHvpJHTRqECanb0EnBrP3yymfcvKmHREm3PpirWbd/Q9IIh0v+PCsL59zZiJebh VTCaecpJudwk4= X-Received: by 2002:a05:7301:1804:b0:376:203e:7d7b with SMTP id 5a478bee46e88-38752015b25mr8193345eec.2.1796568312499; Sun, 06 Dec 2026 06:45:12 -0800 (PST) Received: from SeungJong-Mac-mini.local ([210.117.237.143]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e1c55sm28623252eec.16.2026.12.06.06.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 06:45:12 -0800 (PST) From: SeungJong Ha Date: Sun, 06 Dec 2026 23:44:46 +0900 Subject: [PATCH RFC net-next 5/5] net: change tx_queue_len only after all allocations succeeded X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261206-tc1-txqlen-commit-v1-5-ec9f34dce973@gmail.com> References: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> In-Reply-To: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Jamal Hadi Salim , Jiri Pirko , Andrew Lunn , Willem de Bruijn , Jason Wang Cc: "Michael S. Tsirkin" , John Fastabend , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, SeungJong Ha X-Mailer: b4 0.15.2 netif_change_tx_queue_len() sets the new length, resizes the device rings, notifies and then resizes the qdiscs. If the qdiscs fail, it restores dev->tx_queue_len, but the device rings keep the new length and RTM_NEWLINK has already reported it. Resizing the rings back on the way out does not help, as that would need to allocate again. Do it in this order instead: prepare the qdiscs may fail, leaves nothing behind resize the device rings may fail, changes all or none set the new length swap the qdisc rings in notify Whichever step fails, nothing has been changed yet, so there is nothing to revert. No in-tree listener of NETDEV_CHANGE_TX_QUEUE_LEN fails any more. Its return value is now ignored, as for NETDEV_UP and NETDEV_FEAT_CHANGE. Found with a prototype static analysis tool I am developing. The analysis, the reproducer and the fix were written with Claude Code (Claude Opus 5.5). Signed-off-by: SeungJong Ha --- include/linux/if_tap.h | 2 +- include/net/sch_generic.h | 5 ++++- net/core/dev.c | 22 +++++++++++----------- net/sched/sch_generic.c | 19 ++++--------------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/include/linux/if_tap.h b/include/linux/if_tap.h index 5b8d59e19c1c..2a8b1084122f 100644 --- a/include/linux/if_tap.h +++ b/include/linux/if_tap.h @@ -48,7 +48,7 @@ struct tap_dev { int numqueues; /* Size of the ptr_ring of all queues, as last set by * tap_queue_resize(). Can differ from dev->tx_queue_len - * if a change of the latter failed after tap_queue_resize() ran. + * while the latter is being changed. */ unsigned int ring_size; netdev_features_t tap_features; diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 8e0e774844c2..e406b32dfab9 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -723,7 +723,10 @@ void qdisc_class_hash_remove(struct Qdisc_class_hash *, void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *); void qdisc_class_hash_destroy(struct Qdisc_class_hash *); -int dev_qdisc_change_tx_queue_len(struct net_device *dev); +int dev_qdisc_prepare_tx_queue_len(struct net_device *dev, + unsigned int new_len); +void dev_qdisc_commit_tx_queue_len(struct net_device *dev); +void dev_qdisc_abort_tx_queue_len(struct net_device *dev); void dev_qdisc_change_real_num_tx(struct net_device *dev, unsigned int new_real_tx); void dev_init_scheduler(struct net_device *dev); diff --git a/net/core/dev.c b/net/core/dev.c index 9a9bfc4815e6..4a1ddafca036 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10269,26 +10269,26 @@ int netif_change_tx_queue_len(struct net_device *dev, unsigned long new_len) return -ERANGE; if (new_len != orig_len) { - WRITE_ONCE(dev->tx_queue_len, new_len); + /* Nothing may fail once the new length is set. */ + res = dev_qdisc_prepare_tx_queue_len(dev, new_len); + if (res) + goto err; if (ops && ops->change_tx_queue_len) { res = ops->change_tx_queue_len(dev, new_len); if (res) - goto err_rollback; + goto err_abort; } - res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev); - res = notifier_to_errno(res); - if (res) - goto err_rollback; - res = dev_qdisc_change_tx_queue_len(dev); - if (res) - goto err_rollback; + WRITE_ONCE(dev->tx_queue_len, new_len); + dev_qdisc_commit_tx_queue_len(dev); + call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev); } return 0; -err_rollback: +err_abort: + dev_qdisc_abort_tx_queue_len(dev); +err: netdev_err(dev, "refused to change device tx_queue_len\n"); - WRITE_ONCE(dev->tx_queue_len, orig_len); return res; } diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index c7eb4ef5411f..b72d535729d0 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1534,7 +1534,7 @@ void mq_change_real_num_tx(struct Qdisc *sch, unsigned int new_real_tx) } EXPORT_SYMBOL(mq_change_real_num_tx); -static void dev_qdisc_abort_tx_queue_len(struct net_device *dev) +void dev_qdisc_abort_tx_queue_len(struct net_device *dev) { struct Qdisc *qdisc; unsigned int i; @@ -1547,8 +1547,8 @@ static void dev_qdisc_abort_tx_queue_len(struct net_device *dev) } /* Allocate everything a tx_queue_len change needs, or nothing. */ -static int dev_qdisc_prepare_tx_queue_len(struct net_device *dev, - unsigned int new_len) +int dev_qdisc_prepare_tx_queue_len(struct net_device *dev, + unsigned int new_len) { struct Qdisc *qdisc; unsigned int i; @@ -1569,7 +1569,7 @@ static int dev_qdisc_prepare_tx_queue_len(struct net_device *dev, return 0; } -static void dev_qdisc_commit_tx_queue_len(struct net_device *dev) +void dev_qdisc_commit_tx_queue_len(struct net_device *dev) { bool up = dev->flags & IFF_UP; struct Qdisc *qdisc; @@ -1588,17 +1588,6 @@ static void dev_qdisc_commit_tx_queue_len(struct net_device *dev) dev_activate(dev); } -int dev_qdisc_change_tx_queue_len(struct net_device *dev) -{ - int ret; - - ret = dev_qdisc_prepare_tx_queue_len(dev, dev->tx_queue_len); - if (!ret) - dev_qdisc_commit_tx_queue_len(dev); - - return ret; -} - static void dev_init_scheduler_queue(struct net_device *dev, struct netdev_queue *dev_queue, void *_qdisc) -- 2.54.0