ioctl: defer ioctl version probing until first use#3357
Merged
Conversation
The eager ioctl probing with a dummy command causes the kernel to emit log messages. In addition, probing is performed for every handle, which becomes unnecessarily expensive when iterating over large setups with many fabrics controllers. Defer ioctl version probing until the first actual command submission. Prefer the 64-bit ioctl opportunistically and fall back to the 32-bit variant only when the kernel returns -ENOTTY. When --no-ioctl-probing is specified, skip probing entirely and use the 32-bit ioctl directly. Signed-off-by: Daniel Wagner <wagi@kernel.org>
There was a problem hiding this comment.
Pull request overview
This PR changes libnvme’s ioctl selection strategy to avoid eager “dummy command” probing (which can trigger kernel log noise) and to reduce per-handle overhead by deferring probing until the first real passthru submission. It opportunistically tries the 64-bit ioctl first and falls back to the 32-bit ioctl only when the kernel returns -ENOTTY; --no-ioctl-probing skips the 64-bit attempt.
Changes:
- Replace per-handle boolean flags (
ioctl_admin64,ioctl_io64) with an explicit cachedenum ioctl_statefor admin and I/O ioctl selection. - Remove eager ioctl probing during direct-handle open and instead probe lazily on the first command submission.
- Factor direct admin passthru submission into a helper that applies the new probe/cache behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
libnvme/src/nvme/private.h |
Introduces enum ioctl_state and stores cached ioctl capability state on the transport handle. |
libnvme/src/nvme/lib.c |
Removes eager probing during direct open; updates test-handle setup to use the new state enum. |
libnvme/src/nvme/ioctl.c |
Implements lazy 64-bit-first submission with -ENOTTY fallback and caches the selected ioctl state. |
Comments suppressed due to low confidence (1)
libnvme/src/nvme/ioctl.c:247
- Same as the IO passthru path: when ioctl_admin_state is UNKNOWN and probing is enabled, this code may issue the admin command via the 64-bit ioctl, observe -ENOTTY, and then re-issue it via the 32-bit ioctl. Because both submit helpers run submit_entry/submit_exit, callers will see duplicate logging/metrics and an extra failure callback for the probe attempt. Please restructure the probe so that submit_entry/exit are only invoked once for the actual submission.
if (hdl->ioctl_admin_state == IOCTL_STATE_IOCTL64)
return libnvme_submit_passthru64(hdl,
LIBNVME_IOCTL_ADMIN64_CMD, cmd);
if (hdl->ioctl_admin_state == IOCTL_STATE_IOCTL32 ||
!hdl->ctx->ioctl_probing)
goto do_ioctl32;
err = libnvme_submit_passthru64(hdl, LIBNVME_IOCTL_ADMIN64_CMD, cmd);
if (err >= 0 || err != -ENOTTY) {
hdl->ioctl_admin_state = IOCTL_STATE_IOCTL64;
return err;
}
hdl->ioctl_admin_state = IOCTL_STATE_IOCTL32;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+211
to
224
| if (hdl->ioctl_io_state == IOCTL_STATE_IOCTL32 || | ||
| !hdl->ctx->ioctl_probing) | ||
| goto do_ioctl32; | ||
|
|
||
| err = libnvme_submit_passthru64(hdl, LIBNVME_IOCTL_IO64_CMD, cmd); | ||
| if (err >= 0 || err != -ENOTTY) { | ||
| hdl->ioctl_io_state = IOCTL_STATE_IOCTL64; | ||
| return err; | ||
| } | ||
|
|
||
| hdl->ioctl_io_state = IOCTL_STATE_IOCTL32; | ||
|
|
||
| do_ioctl32: | ||
| return libnvme_submit_passthru32(hdl, LIBNVME_IOCTL_IO_CMD, cmd); |
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The eager ioctl probing with a dummy command causes the kernel to emit log messages. In addition, probing is performed for every handle, which becomes unnecessarily expensive when iterating over large setups with many fabrics controllers.
Defer ioctl version probing until the first actual command submission. Prefer the 64-bit ioctl opportunistically and fall back to the 32-bit variant only when the kernel returns -ENOTTY.
When --no-ioctl-probing is specified, skip probing entirely and use the 32-bit ioctl directly.
Fixes: #3349 #3348 #3312