🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7818

Re: [PATCH net v4 3/3] netconsole: recheck device registration after waiting for carrier

#7818
From: Breno Leitao
Date: Tue, 27 Oct 2026 09:18
53 lines
10637 bytes
On Wed, Oct 21, 2026 at 03:19:07PM +0100, Gustavo Luiz Duarte wrote:
> netcons_netpoll_setup() drops RTNL while it waits for carrier when the
> device is not yet up. If the device is unregistered in that window, the
> NETDEV_UNREGISTER notifier runs before np->dev is set and has nothing
> to match.
> 
> We might then end up setting up netpoll on a device that is being
> unregistered while holding a reference to it, stalling
> unregister_netdevice() in netdev_wait_allrefs_any().
> 
> Add a check to confirm the device is still registered once we retake
> RTNL. Release the device reference and return -ENODEV otherwise.
> 
> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012-netcons-fixes-v3-1-1aac85ed7665@gmail.com
> Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
> ---
>  drivers/net/netconsole.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index be7eb632ee42..bd36ebd334aa 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -534,6 +534,16 @@ static int netcons_netpoll_setup(struct netconsole_target *nt)
>  		rtnl_unlock();
>  		netcons_wait_carrier(np, ndev);
>  		rtnl_lock();
> +
> +		/* Check that ndev hasn't been unregistered when we released
> +		 * the RTNL above.
> +		 */
> +		if (ndev->reg_state != NETREG_REGISTERED) {
> +			np_err(np, "%s was unregistered while waiting for carrier, aborting\n",
> +			       netcons_egress_dev(np, buf, sizeof(buf)));
> +			err = -ENODEV;
> +			goto put;
> +		}
>  	}

I think there is a better way to do it, inside netcons_wait_carrier().

netcons_wait_carrier() loops waiting for the carrier, and exit if in
time_after(). I think it will be cleaner to exit there.

then netcons_wait_carrier() would return a bool, and you goto 'put' in
both case (ndev->reg_state != NETREG_REGISTERED) or in the
time_after() exit.

Wouldn't it be better?

Thanks for the fixes,
--breno
Technical Details
Message-ID: <auBrysA0RUkVlTOA@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352320-linux-kernel-netdev=dewy.ru
References: <20261021-netcons-fixes-v4-0-3857120c6340@gmail.com> <20261021-netcons-fixes-v4-3-3857120c6340@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352320-linux-kernel-netdev=dewy.ru
From: leitao@debian.org (Breno Leitao)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4 3/3] netconsole: recheck device registration after
 waiting for carrier
Date: Tue, 27 Oct 2026 02:18:55 -0700
Organization: Usenet Network
Message-ID: <auBrysA0RUkVlTOA@gmail.com>
References: <20261021-netcons-fixes-v4-0-3857120c6340@gmail.com>
 <20261021-netcons-fixes-v4-3-3857120c6340@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="1502122"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CUPlF88VKf1VPL50qna43rxyJbc= sha256:p9aPDX3MckGQj2LcSqWJR+LlcDvI3pzKTcac06YiArg=
	sha1:Zr8bH+z+LQR1p9ckr4M4Zmsvl8o= sha256:rqG1ToFrJmEl/1Yi4PiI74vjtfHZhHCGoN3tHDiAhBY=
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 66405125BE6; Tue, 27 Oct 2026 12:24:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.388
X-Spam-Status: No, score=-3.388 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=debian.org
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 oGs3r162XL6n;
	Tue, 27 Oct 2026 12:24:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352320-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=debian.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 485E3125BE0; Tue, 27 Oct 2026 12:24:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 1A1FB3151A; Tue, 27 Oct 2026 09:19:23 +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=1793092762;
	b=Debg8OpptbllndwRCrsNeLVGvdBVW3YzOdqKNQovPeoD2GXiwThuBT4f9b8yrcYJ7Lq7
	 jpMVUZ5u86rLw86X0GqHLWacMi57r122TAUc0LlPQjaJbtHlKosFNuzK3OiL//ATZ3OAC
	 Xvoor/T7myKd7nlegOw+GMrbMoOh+69eaZOmZPD2VkCcC+fpv2UTSuN2/MO901ei6kft+
	 4lomQvZh42sxH0efNA2wmYUm67xBw5C1NEgr0m4Ytx0HEzS0LqBnu2VzEPWN1ML6Lcv+S
	 a2jdCZvHiaReFFCeRDz71TE0iG8utE6Jqujj3bvewlrPT29C1ZypPufJQf2zdhrKKbg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092762;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received: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:
	 X-Debian-User;
	bh=0caqeUvhoyd73MwX92KLCVLJ4OlRT1yAOV5WgVoUV7g=;
	b=ckYUUUnaC2sdlaoi9Ggx2N+ThjILNRH2cqrkTJxfECEuMG3m8gTLXr9oOj91v71tXGTk
	 Z1KCICNXF7I0XGWSTIzeXxbueUZO1GQGciAZSls9nUOxLMrOm3YCP8qzm0cvzD5OtYaj9
	 Ffe1L48FKLPXwCN/Ta5Ws903U2z3AdjY9QtBRWiYp1UGGyx04FEmJVE5lIpSdbsNMFYbH
	 BA4qatGhdCPrLMTfbHEKhJz9GqrYxAaOeogOS/1R80nWOAyY6NDtEHuFq8t/vFEkNq9cT
	 hcBmhLEtCIQSbY0MJmBhgHDN/EDp0awvATeUj4p73NnptRBYsPHklNf4cFf0VtAHFYw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=vX34J1gO;
	dmarc=pass header.from=debian.org;
	spf=pass smtp.mailfrom=debian.org;
	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 45FC9606A31F;
	Tue, 27 Oct 2026 09:19:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=vX34J1gO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=82.195.75.108
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793092751;
	b=XKlXDnE8+G8X3ViTn6lxssHOnP0vRtOiUM8DXYkGV/B6YcJQhCtDxPcXJRIS8PLu6PqK
	 w4f0tWAaJhn10penVmU3O2FzNDhlImX68CckRm6kAXLFN+Am0Fep7Jn5MypsVkRu2D+oE
	 r9x/fhZYgNybI+KLuPRmVsfkTusmKb67xD+jxxYKDce1Ygj8xC4uJVLXvp10Lkv9NkOSZ
	 bNmVA4tm0TsEZgj4KFO91/HInh6idIc/oJEydfhpJBWzFouZaTuHSxziyVU0zrbBbCb4G
	 qcg5hep/Sb3az5T8TYdMi+xASQSeFqSxhjh4HZU1Le1XqSn62ylAhQ8ixH1WM7vLrRw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092751;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:MIME-Version:Content-Type:Content-Disposition:
	 In-Reply-To:X-Debian-User;
	bh=0caqeUvhoyd73MwX92KLCVLJ4OlRT1yAOV5WgVoUV7g=;
	b=aSfWk8aLoBb8+8W1w4j88YiOBzsygUUGIqalOTkpMWIR6BaMaj69mbJZoeQX98ll4cTg
	 wZQwjdJPezmW7JL9xTXMbf52P9gvde7mBmcWWHRevAfa31v4kmf0c43ohQbp90SLF7b8b
	 2+z/Q8TtHaSPZAe3O4TanHzIvSawWr85yHhi4fYyf4OZkIEbuupDtJ/0zA7qdx+My7UH5
	 /n9bIL10HHQ3f0oiH+AEsBejtHUiumdHpiF1DxiNUZLiB/Z7DHpVc1gUzEQpntwVh4B04
	 4HkAdKs61j4P08LiRM0AmmYi8E01B0YKPeC77WF9ehw/XHkf9x/IBLUKuxt15WIXaoA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=debian.org;
	spf=pass smtp.mailfrom=debian.org;
	dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=vX34J1gO;
	arc=none smtp.remote-ip=82.195.75.108
X-Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDEEB606A31B;
	Tue, 27 Oct 2026 09:19:10 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BDEEB606A31B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org;
	s=smtpauto.stravinsky; h=X-Debian-User:In-Reply-To:Content-Type:MIME-Version:
	References:Message-ID:Subject:Cc:To:From:Date:Reply-To:
	Content-Transfer-Encoding:Content-ID:Content-Description;
	bh=0caqeUvhoyd73MwX92KLCVLJ4OlRT1yAOV5WgVoUV7g=; b=vX34J1gO9ozZgfa3Jw58sG6Q+3
	rL5VazSTDov9tbeKxe5PA3CQUSHnZqzZeQ3Z3AtBzt6EmOKlClFYDTW8zvKaHR40I8j8pdQv+h+JH
	zIjXw+P9x4btEh/HukiBfONb1qlhaw2lrGPOCV0fQA3BurEFLksbLS+TmmK/atmIDGQiU2/1nrqn+
	Njm+nTNYFJqbaNwxB3HFNQ15E8tki3Vks3ih5gOk12nPuqBflB50qAhXLlKfxzb1P8QqLJ2XPaVgq
	Iu7hzpy2cSeRVc7JQ4eKXuuG/h97dZkdZFRYTeKcPWaYoL1a78tb7YgHUSWM0q0QnAXFIPwz7YwA0
	j1VhnP7Q==;
X-Received: from authenticated-user
	by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)
	(Exim 4.96)
	(envelope-from <leitao@debian.org>)
	id 1xLdKf-001M1U-0y;
	Tue, 27 Oct 2026 09:19:02 +0000
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>, 
	Stephen Hemminger <stephen@networkplumber.org>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
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: <20261021-netcons-fixes-v4-3-3857120c6340@gmail.com>
X-Debian-User: leitao