Article View: linux.kernel.netdev
Article #14924Re: [PATCH net] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds
From: Hangbin Liu
Date: Thu, 12 Nov 2026 07:01
Date: Thu, 12 Nov 2026 07:01
39 lines
10254 bytes
10254 bytes
On Thu, Nov 12, 2026 at 11:51:52AM +0800, Wenbo Sun wrote: > Hi Hangbin, > > On Wed, Nov 11, 2026 at 09:02:17PM +0800, Hangbin Liu wrote: > > If ipvlan_set_port_mode() failed, the unregister_netdevice(dev) will be > > called. Does port->flags still need to restore? > > Thank you very much for taking the time to review this patch and for > pointing out the question about the commit description. > > You are completely right that when creating the first ipvlan device on a > lower device, unregister_netdevice(dev) drops the last reference to the > port in ipvlan_uninit() -> ipvlan_port_put(), destroying the port so no > flag restoration is needed. > > The issue happens when one or more ipvlan interfaces already exist on the > same lower device: > > 1. Because struct ipvl_port is shared across all ipvlan interfaces on a > lower device, ipvlan_init() takes an additional reference via > refcount_inc(&port->count) when creating a new ipvlan interface. > 2. If ipvlan_link_new() writes port->flags before calling > ipvlan_set_port_mode(), and ipvlan_set_port_mode() fails (for > instance, requesting L3S mode when CONFIG_IPVLAN_L3S is disabled), > unregister_netdevice(dev) only decrements port->count back down to at > least 1. Since ipvlan_port_destroy() is not called, the shared port > remains active for the existing ipvlan interfaces while still carrying > the newly written port->flags. > > Rather than saving and restoring port->flags on the error path, moving > the port->flags assignment after ipvlan_set_port_mode() succeeds avoids > modifying it on failure altogether, as there are no remaining failure > paths afterward in ipvlan_link_new() (matching ipvlan_nl_changelink()). Thanks for the explanation. The change makes sense to me now. Regards Hangbin
Technical Details
Message-ID:
<avVkM5XY1kNswdcY@fedora>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361543-linux-kernel-netdev=dewy.ruReferences:
<20261111064655.233265-1-sunwenbo@cmss.chinamobile.com> <avRnWUbGFbdfirZB@fedora> <20261112035152.43363-1-sunwenbo@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361543-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] ipvlan: update port flags only after ipvlan_set_port_mode() succeeds Date: Thu, 12 Nov 2026 15:01:07 +0800 Organization: Usenet Network Message-ID: <avVkM5XY1kNswdcY@fedora> References: <20261111064655.233265-1-sunwenbo@cmss.chinamobile.com> <avRnWUbGFbdfirZB@fedora> <20261112035152.43363-1-sunwenbo@cmss.chinamobile.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="1030985"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Q1UhXSKgJMqFq4a19QnuHiP94yc= sha256:3Lo+YG93UuJOGbr0p76IoBXjoGZBc6Td82mqPvuKdKg= sha1:l9qGvThb8KdnRgT9mNPw5IWV1es= sha256:effsNZeCaiwUd9WXp4YsBu3ZTawNQU+nKlee/5QGtKE= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 7D725114124; Thu, 12 Nov 2026 10:05:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ejjZDwhbPWiW; Thu, 12 Nov 2026 10:05:05 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-361543-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id EDCA11140E8; Thu, 12 Nov 2026 10:04:55 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id E9CE2A4615; Thu, 12 Nov 2026 07:01:27 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794466884; b=AFmY6KDpO4wlTg5JbKL0h3ovIffSIgfh8DS7MZQqrQaUCoLfJp9U+rkxsn/xvB6xewZL nBB7dOpAnqIrutpw1yHqu9DL+lcU6FTeN4qqqNSBL7fWS9Re4YZPrYmOpc74a3qL3LEr1 w5RRjlbJ8dnb93kJS+2wBMkRKwgP9a13J9stTpZxy5hTJ/YRpMVnTUj3etTT4Xk3ubxwS m4r5LFrkGK0d/aURmhK9wWe1OCpomfnCsnGDM4PMDgnccBWSO+QCFg2B3lyZXt0vwxVwe 15tcpCho4WnV9teTCRbikKu5Dhn1nVVNhyBfmwtUxHKTA0afjgghykB7BVtvBodPtrQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794466884; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=MWJBAoI6Q3L0rHwEVEAsPxA9+MzfVuCyWdcvDOlOHcQ=; b=3/ejBjsmLVGOMkPw+rS7ITAQMFkf6nTuSR7v//9Xlj9olN3O8SrBWREDbBS2Ov1XdaTa meW/BoajZRecD54WiO08xycKYrp4D9b3g4Fv9mOOMoxEV0jl06nD6XU9c46ToMxbuPA4n Sem4J7GP9+bIkma4WN0tmojIDJtmB1G7SPoiqNJxDZ0T+URuUGQGxccuF8OFti7NLPny4 yPMzBZm8n1LTvhN2AyCyF6QDrKjhYTbD7tGmqDiruXRS6Mge0mTADBoRdbRsHTZjkyldV P8ZlMPgGuE3hx5g2cREcHTPSp2g6quDaiBGMujC6Qt4LHZaDSw0kpzgfjBEpIJd+gMw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kNKiT5ls; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E704F606A33A; Thu, 12 Nov 2026 07:01:23 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kNKiT5ls X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.132 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794466883; b=au+aStsNyRGLL9mADTQga19GK33+aE8HhKfL8gC/cgpLN0HDPFXtJFwN+7POg5ytQv4a LKM6bqjVVBw/rxuFzpLbS1tF8tdGZeVZ6PvDFJBY/KIPrMNgl+Y1UFSWidAz+AsFZeIZP 4Mt0YhgMMlBDPc8GeAc+aPuZcT0UpZLRhap20JG3oMlPZ5aEiUfFUl8ka5HRPn/mSXyQJ JstCBRkn/753BmORjIDvmPaW5SX6M5oZ7Nbw7tsEpc4rU87h+Zsax/gYBBH5YebbcHxQ4 v2Lsh5qJpUvlrNdml+K+rl9xk0fbvQv2ZI/uhvk/j8xdQMywLVM2bkNKnswp2FaSOig== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794466883; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=MWJBAoI6Q3L0rHwEVEAsPxA9+MzfVuCyWdcvDOlOHcQ=; b=ItIZYF+WmhkmV1xDtMMffGvHHQ1oqlaqx2jiV9cjjNglOCNHcX5o4RYQ1loVBIHZvGXs +eB9iyddmUAJ1MisMXyH4FwpBxDcsJkm1TTD091xjFYRg+ogdrMYFyj1V38idOWPdXQfR /NUNS7dzZo1mLWsPIGzve4m36GxQY70XeqQ34UoMJrDwEALxxcS0vZ6kj3m+fYkNFBQ+z VRq07nO3O3NI/rs0mJQEgecZA27Isl/2QlHsXvMBXER1WS5fIufSDhIvDhGHYxLeBuno3 jLkZuLpqa3P0vAHWxh6on94TtJv4qIXspnT65HGvZGvgc84ZMl4jZvhS48CWliNaExQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kNKiT5ls; arc=none smtp.remote-ip=91.218.175.132 X-Received: from mta0.migadu.com (out-132.mta0.migadu.com [91.218.175.132]) (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 51806606A327 for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 07:01:21 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51806606A327 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=4j+AMbRycxeWs+fHLwXrjL4tOlZ+wuEL4eMEvsEOGF8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794466880; v=1; x=1795071680; b=kNKiT5lszobFGxQKLtegnsQ91t+v/tt57xGgcikSZTidFLzbh5ZlbALcHG4RXbWRDxaTqHcF pyRmEnKCCaHpaYWzZ6aysa9YoN8HPV86TSeEL7iY3szprO6MTXY+wgwBoACwvWrxOzBcgFvTGcc jbN7c+m75IqUqjbl5B/F1+gg= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta10.migadu.com with ESMTPS id b2b9d25aaa0ba4d9; Thu, 12 Nov 2026 07:01:20 +0000 X-Mizu-Trace-ID: b2b9d25aaa0ba4d9 X-Migadu-Flow: FLOW_OUT X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Kuniyuki Iwashima <kuniyu@google.com>, Mahesh Bandewar <maheshb@google.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, 1342116488@qq.com X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261112035152.43363-1-sunwenbo@cmss.chinamobile.com>