From nobody Fri Jun 12 12:46:29 2026 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5B08390CA9 for ; Thu, 14 May 2026 18:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778784431; cv=none; b=s8LB4Ab4w/wUdsUJqNMec7Vfr0oAUC7bMvMwc1C8IyB0eK68N+Rq6OBshRO3lRAcxTHmIzM1v1IMctlirBdueEEvXaUq110IcLp3N7OEjfEJ3pwvClHgrRCTqae+ObQmp3ATiwTy4NfXKQi22qfHC+U/F9ySp3p0Qfgmcehgg/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778784431; c=relaxed/simple; bh=ueUCl0EtJ8kWvVEv/1v3KaiqrbdukBjoCfFKdjqTu3I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nMNozPHCNzA9ALzYGAu+wzhNWxbMKBXrdUWz6JXzZ5IDowGKD1CCKYGPvby2OWxHq0NDAJo+rHeIfzWLVQv6oL5HKrMU4QTeoX3hNDAVreyf+5OevEljK2jAGFQ548qMr11UWxNgmMitibIm0LI4JM1ztBKmCSh+sImrYms/Zj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f66.google.com with SMTP id 5b1f17b1804b1-4891d7164ddso45808205e9.3 for ; Thu, 14 May 2026 11:47:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778784427; x=1779389227; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gbyuYskHezDgvxCcvU19slfVinGu/cOvscyqTQLVYVU=; b=NhhhiEocDM89gOrKbJ0I6DWru1UTSFApgh5iZW45JOz5nn/DBaGJlFLCoxUDaTU+Lb y8PSlBVVxUgx/rlthQMN5TNivBvgsCK0FTSpA8Fy1r7Y4v4Mgf3RZ1feXe3Mb1/2jjWq lAWNgYdkgH4IKYlfQKYHXMgeThqKQoH7Mdk3EUvj9Zik/LJsZsUUKwvUGNGxxr8HsCY/ J7xycyYLRqOMw3GiB8rxF9rnu+di/GstMemDR0x546DUzTbL12Yk4QykatZO4NdMiKK/ R3QVDdqQcnwJpHNkXHc+IT13qo9tMAhjVsgtjouVXRwlUvtbsdbUlIlbjBp2QpvMVgGZ KhzA== X-Forwarded-Encrypted: i=1; AFNElJ/zjin+fv50ksM1QrJJr5vw3SNK8o2YoT8UEd8I1U0d9DUwxPIxOtlPftMJi9DdiuzJxWsZ9AjeJj3GLMo=@vger.kernel.org X-Gm-Message-State: AOJu0YzP7Dl6k/mrjgD95tbds95z+7vLamrd6c/K6aiEJPUOR18yAs4r kxBopDaKjQz8BN6ELIcdtAk2dazUNdBuahwX1xQqoByY8oicaiefYnt6 X-Gm-Gg: Acq92OE1dVTyw/Db7+zfaL1/aoc1EmnhagICqevhGDVEmJqNYqaLEctx9v+Bt+pv8bQ mO+XoPbZji99EKvLtrifbIZDpiBeHNA4neYiwhCNgzRYofUWpxyPrlz2RtZD7Q6E0UjlTXKRDzv OI8e8qw3aGNzEIkhweuPOY7njfqLdMBG5FCi5TEHlpwDSodcIj+n7Uo7HEN5vzAU7wkxIZN5vNB 5PL/0F9/By3Q2yo6UWXZgasK3HzRNv5iDzXpin52HkHOE1FgQXZbW+rB2QY73tZ/vZMAJlaFHIZ fJ4TGZP9XKUslFdBweKAJ7fl/eD1azoKd88hMirw6nutJtV3E6KzztMV+3tmmDr0UqkJxSpDg+t Q8IkZMahQ5LulpO2RojCz8qtWY4UoHKhrC4Au8frnmAIHYlmayHb9ZInlLtg7BQM6hC61GRpKFi jWJ65Za9sJrCYkI54pI8svVV8nLQ1Uxc2/qfRfwaO1a9sr9FqakCAFeGgqBoHK07uS5bzreo8EF q9muSSE X-Received: by 2002:a05:600c:34d4:b0:48f:e230:c3fa with SMTP id 5b1f17b1804b1-48fe6626a58mr7011795e9.32.1778784426674; Thu, 14 May 2026 11:47:06 -0700 (PDT) Received: from im-t490s.redhat.com (89-24-32-159.nat.epc.tmcz.cz. [89.24.32.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fd62dad0esm24037965e9.6.2026.05.14.11.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 11:47:06 -0700 (PDT) From: Ilya Maximets To: netdev@vger.kernel.org Cc: Aaron Conole , Eelco Chaudron , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , dev@openvswitch.org, linux-kernel@vger.kernel.org, Ilya Maximets Subject: [PATCH net v2] openvswitch: vport: fix race between linking and the device notifier Date: Thu, 14 May 2026 20:46:31 +0200 Message-ID: <20260514184702.2461435-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sashiko reports that it is technically possible that we got the device reference, but by the time we're linking it to the OVS datapath, it may be already in the process of being deleted. In this case if the notifier wins the race for RTNL, it will see that the device is not yet in the OVS datapath (ovs_netdev_get_vport() will fail in the dp_device_event()) and will do nothing. Then the ovs_netdev_link() will take the RTNL and link the unregistering device to OVS datapath. Eventually, netdev_wait_allrefs_any() will re-broadcast the event and the device will be properly detached, but it will take at least a second before that happens, so it's not something we should rely on. Let's avoid linking the non-registered device in the first place. Note: As per documentation, RTNL doesn't protect the reg_state, but it actually does for all the state transitions we care about here, so it should not be necessary to use READ_ONCE or taking the instance lock. We can still do that, but we have a few more places even in this file where the reg_state is accessed without those while under RTNL, and many more places like this across the kernel code, so it might make more sense to change all of them in a more centralized fashion in the future, if necessary. Fixes: ccb1352e76cf ("net: Add Open vSwitch kernel components.") Signed-off-by: Ilya Maximets Acked-by: Eelco Chaudron Reviewed-by: Aaron Conole --- Version 2: * Added a comment. [Aaron] Version 1: * https://lore.kernel.org/netdev/20260513095541.2010516-1-i.maximets@ovn.o= rg/ net/openvswitch/vport-netdev.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/openvswitch/vport-netdev.c b/net/openvswitch/vport-netdev.c index c42642075685d..e7e8490a53d80 100644 --- a/net/openvswitch/vport-netdev.c +++ b/net/openvswitch/vport-netdev.c @@ -83,6 +83,14 @@ struct vport *ovs_netdev_link(struct vport *vport, bool = tunnel) } =20 rtnl_lock(); + /* Do not link devices that are not registered to avoid a potential + * race with the NETDEV_UNREGISTER notification in dp_device_event(). + */ + if (vport->dev->reg_state !=3D NETREG_REGISTERED) { + err =3D -ENODEV; + goto error_put_unlock; + } + err =3D netdev_master_upper_dev_link(vport->dev, get_dpdev(vport->dp), NULL, NULL, NULL); --=20 2.53.0