Dpdk: add a uevent listener helper app - #4661
Conversation
11c37af to
c867395
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a small standalone C helper (azure_uevent_listener.c) under the DPDK test suite that listens directly to NETLINK_KOBJECT_UEVENT and prints one tagged line per kernel uevent relevant to Azure NIC hotplug (net, vmbus, infiniband, pci), enabling higher-level DPDK SR-IOV hotplug tests to reliably match the precise device-add/remove sequence.
Changes:
- Add a netlink uevent listener that classifies and prints Azure NIC-related uevents with stable, parseable tags.
- Include optional modes to print all subsystems (
-a) and dump raw key/value properties (-v).
Suppressed comments (1)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:367
- The
-hoption is implemented but not documented inusage(), and the usage line doesn’t mention it. This makes CLI help incomplete.
fprintf(stderr,
"usage: %s [-a] [-v]\n"
" -a report every subsystem, not just Azure NIC events\n"
" -v dump all uevent properties for each reported event\n",
argv0);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| static void | ||
| print_event(const struct uevent *ev, const char *tag, bool vf) | ||
| { | ||
| struct timespec ts; |
| * Build: | ||
| * gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c | ||
| * |
| cm = CMSG_FIRSTHDR(&msg); | ||
| if (cm == NULL || cm->cmsg_type != SCM_CREDENTIALS) | ||
| return 0; | ||
| cred = (struct ucred *)CMSG_DATA(cm); | ||
| if (cred->uid != 0) | ||
| return 0; |
c867395 to
7c46c72
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:177
struct timespec tsis used in the timestamp (ts.tv_nsec) even ifclock_gettime()fails, leavingtsuninitialized and causing undefined behavior in the printed output. Initializetsso the fallback path is safe.
struct timespec ts;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:21
- The build command in the header comment references a non-existent source file (
azure_hotplug_mon.c). Copy/pasting this command will fail because the actual file name isazure_uevent_listener.c.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:158
classify()returnsPCI_ADD/PCI_REMOVEfor non-Azure-VF PCI events. That means the program will print unrelated PCI hotplug events even when-ais not specified, contradicting the comment that non-Azure NIC cases are dropped unless-ais given.
if (strcmp(ev->subsystem, "pci") == 0) {
if (vf)
return add ? "VF_PCI_ADD" : "VF_PCI_REMOVE";
return add ? "PCI_ADD" : "PCI_REMOVE";
}
7c46c72 to
5cd523e
Compare
5cd523e to
5686a9b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:177
tsmay be uninitialized ifclock_gettime()fails, but it is still used in the timestamp print (ts.tv_nsec). Initializing it avoids undefined behavior and keeps output deterministic on failure paths.
struct timespec ts;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:295
recvmsg()ancillary data can include multiple control messages; relying onCMSG_FIRSTHDR()beingSCM_CREDENTIALSmay cause all events to be skipped on kernels that prepend other cmsgs (e.g. pktinfo). Iterate cmsgs to findSCM_CREDENTIALSand validate it.
if (cm == NULL || cm->cmsg_type != SCM_CREDENTIALS)
return 0;
cred = (struct ucred *)CMSG_DATA(cm);
if (cred->uid != 0)
return 0;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build command in the header comment refers to
azure_hotplug_mon.c, but this file isazure_uevent_listener.c. Updating it prevents copy/paste build failures for anyone following the inline instructions.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build instruction references
azure_hotplug_mon.c, but this PR addsazure_uevent_listener.c. As written, the example command won’t compile on a fresh checkout. Update the command to use the actual source filename (or rename the file to match the documentation).
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:177
tsis used in the printf even ifclock_gettime()fails, but it’s currently uninitialized. Initialize it to avoid undefined behavior in that error path.
struct timespec ts;
5686a9b to
025ec32
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build instructions reference
azure_hotplug_mon.c, but this file doesn’t exist in the repo (this PR addsazure_uevent_listener.c). As written, the example build command will fail. Update the command to compile the actual source file name (or rename the file to match the documented command).
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:181
ts.tv_nsecis used in the printf even ifclock_gettime()fails, leavingtsuninitialized (undefined behavior and can trigger compiler warnings). Initializetsand only print milliseconds when the timestamp was captured successfully (or default to 0).
struct timespec ts;
struct tm tm;
char when[16] = "??:??:??";
if (clock_gettime(CLOCK_REALTIME, &ts) == 0 &&
bfd35bf to
205a495
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build command in the header comment references
azure_hotplug_mon.c, but this file is namedazure_uevent_listener.c. As written, the copy/paste build instructions will fail.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:177
tsis used in the printf even ifclock_gettime()fails, leavingts.tv_nsecuninitialized (undefined behavior). Initializets(or guard the sub-second print) so failure still prints deterministically.
struct timespec ts;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:294
uev_recv()assumes the first control message isSCM_CREDENTIALS. If the kernel ever sends additional cmsgs (or ordering differs), this will incorrectly drop otherwise-valid uevents. Iterate the control messages and also verifycmsg_level == SOL_SOCKET.
cm = CMSG_FIRSTHDR(&msg);
if (cm == NULL || cm->cmsg_type != SCM_CREDENTIALS)
return 0;
cred = (struct ucred *)CMSG_DATA(cm);
if (cred->uid != 0)
205a495 to
2e053c3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (4)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:294
- uev_recv() drops the message unless SCM_CREDENTIALS is present as the first control message. This makes the listener silently stop working if SO_PASSCRED can't be enabled, and it may also reject valid kernel messages if credentials aren't the first cmsg. Consider accepting messages from nl_pid==0, and only enforcing uid==0 when credentials are present (iterating over all cmsgs and checking cmsg_level/type).
cm = CMSG_FIRSTHDR(&msg);
if (cm == NULL || cm->cmsg_type != SCM_CREDENTIALS)
return 0;
cred = (struct ucred *)CMSG_DATA(cm);
if (cred->uid != 0)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build command in the file header references a different source filename (azure_hotplug_mon.c) than this file (azure_uevent_listener.c), which will confuse anyone trying to compile it from the instructions.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:185
- If clock_gettime() fails, ts is uninitialized but ts.tv_nsec is still used in the printf(), which can print garbage or trigger undefined behavior. Initialize ts and/or compute the millisecond field only on success.
if (clock_gettime(CLOCK_REALTIME, &ts) == 0 &&
localtime_r(&ts.tv_sec, &tm) != NULL)
strftime(when, sizeof(when), "%H:%M:%S", &tm);
printf("[%s.%03ld] %-18s subsystem=%s", when, ts.tv_nsec / 1000000,
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:367
- -h is supported (getopt string includes 'h'), but usage() doesn't document it. This makes the CLI help output incomplete.
fprintf(stderr,
"usage: %s [-a] [-v]\n"
" -a report every subsystem, not just Azure NIC events\n"
" -v dump all uevent properties for each reported event\n",
argv0);
2e053c3 to
e929267
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:186
tsis used in the timestamp printf even whenclock_gettime()fails, leavingts.tv_nsecuninitialized and causing undefined output. Initializets(or only print subseconds when the call succeeds).
struct timespec ts;
struct tm tm;
char when[16] = "??:??:??";
if (clock_gettime(CLOCK_REALTIME, &ts) == 0 &&
localtime_r(&ts.tv_sec, &tm) != NULL)
strftime(when, sizeof(when), "%H:%M:%S", &tm);
printf("[%s.%03ld] %-18s subsystem=%s", when, ts.tv_nsec / 1000000,
tag, ev->subsystem != NULL ? ev->subsystem : "?");
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build command in the header comment references
azure_hotplug_mon.c, but this PR addsazure_uevent_listener.c. As written, the copy/paste build instruction will fail.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
e929267 to
b066ea0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- Build instructions reference
azure_hotplug_mon.c, but this file is namedazure_uevent_listener.c. As written, the documented compile command will fail unless the file is renamed.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:181
print_event()usests.tv_nsecin the printf even ifclock_gettime()fails, which leavestsuninitialized and can print garbage milliseconds. Initializets(or gate the millisecond printing on a successfulclock_gettime).
struct timespec ts;
struct tm tm;
char when[16] = "??:??:??";
if (clock_gettime(CLOCK_REALTIME, &ts) == 0 &&
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:368
-his accepted by getopt and handled, but it is not documented inusage(). This makes the CLI help inconsistent with the actual flags.
fprintf(stderr,
"usage: %s [-a] [-v]\n"
" -a report every subsystem, not just Azure NIC events\n"
" -v dump all uevent properties for each reported event\n",
argv0);
b066ea0 to
a4f1150
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- The build command references
azure_hotplug_mon.c, but this file is namedazure_uevent_listener.cin the repo, so the command as written will fail when copy/pasted. Update the filename in the build instructions.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:177
tsis used in the printf format even whenclock_gettime()fails, which leavests.tv_nsecuninitialized and can print garbage timestamps. Initializetsto a known value before the call.
struct timespec ts;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:367
-his supported (andgetoptaccepts it), but the usage text doesn’t mention it. This makes the CLI help incomplete.
fprintf(stderr,
"usage: %s [-a] [-v]\n"
" -a report every subsystem, not just Azure NIC events\n"
" -v dump all uevent properties for each reported event\n",
argv0);
Hot plug tests need to know exactly when the kernel adds or removes a VF, its uverbs node, its ib device and its netdev, but DPDK's own rte_dev_event_monitor only parses pci, uio and vfio events that carry PCI_SLOT_NAME, so it drops every vmbus, net and infiniband uevent that matters on Azure. Add a small helper that listens on NETLINK_KOBJECT_UEVENT directly and prints a tagged, single line per event that tests can match on. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5d5f58ad-b9df-4420-ad37-22caee78e925
a4f1150 to
5ef3530
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (4)
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:186
- Major:
print_event()usests.tv_nsecin the log line even ifclock_gettime()fails, leavingtsuninitialized and resulting in undefined behavior / garbage timestamps.
struct timespec ts;
struct tm tm;
char when[16] = "??:??:??";
if (clock_gettime(CLOCK_REALTIME, &ts) == 0 &&
localtime_r(&ts.tv_sec, &tm) != NULL)
strftime(when, sizeof(when), "%H:%M:%S", &tm);
printf("[%s.%03ld] %-18s subsystem=%s", when, ts.tv_nsec / 1000000,
tag, ev->subsystem != NULL ? ev->subsystem : "?");
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:295
- Major: if
SO_PASSCREDcan't be enabled (you already warn and continue),uev_recv()will drop all messages because it requiresSCM_CREDENTIALS. Also, the cmsg check should validatecmsg_level == SOL_SOCKET. Consider treating credentials as an optional extra filter: only enforceuid==0when credentials are present.
/* Only the kernel (port id 0, uid 0) is allowed to talk to us. */
if (snl.nl_pid != 0)
return 0;
cm = CMSG_FIRSTHDR(&msg);
if (cm == NULL || cm->cmsg_type != SCM_CREDENTIALS)
return 0;
cred = (struct ucred *)CMSG_DATA(cm);
if (cred->uid != 0)
return 0;
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:22
- Minor: the build instructions reference
azure_hotplug_mon.c, but this file is namedazure_uevent_listener.c. This can confuse users trying to build the helper.
* Build:
* gcc -O2 -Wall -Wextra -o azure-hotplug-mon azure_hotplug_mon.c
*
lisa/microsoft/testsuites/dpdk/uevent_listener/azure_uevent_listener.c:367
- Nit:
-his accepted by getopt, but it isn't shown in the usage text.
fprintf(stderr,
"usage: %s [-a] [-v]\n"
" -a report every subsystem, not just Azure NIC events\n"
" -v dump all uevent properties for each reported event\n",
argv0);
Part 8 of 9 of a stacked series that reworks the DPDK SRIOV hot plug tests. Stacked on #4660, review only the last commit. This adds a single new C source file and changes no Python.
Hot plug tests need to know exactly when the kernel adds or removes a VF, its uverbs node, its ib device and its netdev. DPDK's own
rte_dev_event_monitoronly parses pci, uio and vfio events that carryPCI_SLOT_NAME, so it drops every vmbus, net and infiniband uevent that matters on Azure.This helper listens on
NETLINK_KOBJECT_UEVENTdirectly and prints a tagged, single line per event that the tests can match on. It is consumed by the next PR in the stack.Key Test Cases:
verify_dpdk_sriov_rescind_failover_send_only
Impacted LISA Features:
Sriov, NetworkInterface
Tested Azure Marketplace Images:
canonical 0001-com-ubuntu-server-jammy 22_04-lts latest