[LTP] [PATCH] uevent02: Make wait_for_uevents() order-independent

Avinesh Kumar avinesh.kumar@suse.com
Tue Aug 25 19:14:01 CEST 2026


From: Avinesh Kumar <avinesh.kumar@suse.com>

Commit 8e63c9e6179a ("net: Defer netdev KOBJ_ADD uevent until the
device is published")[0] in kernel v7.2 changed register_netdevice()
to emit a network interface's own "add" uevent only after the
interface is fully registered, instead of before its queue kobjects
are created. This flips the uevent order for tun device creation from:

    add(net), add(rx queue), add(tx queue)
to:
    add(rx queue), add(tx queue), add(net)

wait_for_uevents() matched events strictly in the order given in the
uevents array, so on kernels with the reordered uevents the "add(net)"
event only matches once the rx/tx queue events have already been
consumed from the socket, leaving wait_for_uevents() stuck waiting for
events that already went by, until uevent02 times out and fails.

Since the relative order of unrelated uevents is a kernel
implementation detail the test should not depend on, make
wait_for_uevents() track the still-unmatched events in a pending set
and match incoming uevents against any of them, regardless of
position.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8e63c9e6179a

Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
---
 testcases/kernel/uevents/uevent.h | 37 ++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/uevents/uevent.h b/testcases/kernel/uevents/uevent.h
index 1ad092d5ea39..b4e4fce2b2f5 100644
--- a/testcases/kernel/uevents/uevent.h
+++ b/testcases/kernel/uevents/uevent.h
@@ -117,15 +117,30 @@ static inline int open_uevent_netlink(void)
 	return fd;
 }
 
+#define UEVENT_MAX_PENDING 16
+
 /*
  * Reads events from uevent netlink socket until all expected events passed in
- * the uevent array are matched.
+ * the uevent array are matched. Events do not have to arrive in the order
+ * they are listed in the uevents array, since the kernel is free to reorder
+ * unrelated uevents, e.g. commit 8e63c9e6179a ("net: Defer netdev KOBJ_ADD
+ * uevent until the device is published") changed the order in which a
+ * network interface and its queues announce themselves.
  */
 static inline void wait_for_uevents(int fd, const struct uevent_desc *const uevents[])
 {
-	int i = 0;
+	const struct uevent_desc *pending[UEVENT_MAX_PENDING];
+	int i, cnt = 0, remaining;
+
+	while (uevents[cnt]) {
+		if (cnt >= UEVENT_MAX_PENDING)
+			tst_brk(TBROK, "Too many expected uevents, increase UEVENT_MAX_PENDING");
+		pending[cnt] = uevents[cnt];
+		cnt++;
+	}
+	remaining = cnt;
 
-	while (1) {
+	while (remaining) {
 		int len;
 		char buf[4096];
 
@@ -136,14 +151,20 @@ static inline void wait_for_uevents(int fd, const struct uevent_desc *const ueve
 
 		print_uevent(buf, len);
 
-		if (uevent_match(buf, len, uevents[i])) {
-			tst_res(TPASS, "Got expected UEVENT");
-			if (!uevents[++i]) {
-				close(fd);
-				return;
+		for (i = 0; i < cnt; i++) {
+			if (!pending[i])
+				continue;
+
+			if (uevent_match(buf, len, pending[i])) {
+				tst_res(TPASS, "Got expected UEVENT");
+				pending[i] = NULL;
+				remaining--;
+				break;
 			}
 		}
 	}
+
+	close(fd);
 }
 
 /*
-- 
2.55.0



More information about the ltp mailing list