Skip to content

nvme: Fix get-feature on big-endian systems#2888

Merged
igaw merged 1 commit intolinux-nvme:masterfrom
maurizio-lombardi:get_feature
Aug 1, 2025
Merged

nvme: Fix get-feature on big-endian systems#2888
igaw merged 1 commit intolinux-nvme:masterfrom
maurizio-lombardi:get_feature

Conversation

@maurizio-lombardi
Copy link
Contributor

The parse_and_open() function uses OPT_BYTE to parse the feature_id and sel options. This means it writes a single byte to the memory locations for feature_id and sel in the feat_cfg struct.

However, these fields were declared as enum, which typically has the size of an int. On big-endian architectures, writing a single byte to the address of an int modifies the most significant byte, resulting in an incorrect value being read. This caused the get-feature command to fail. The command only worked on little-endian systems.

Fix the issue by changing the type for feature_id and sel to __u8. This ensures the fields are treated as single bytes, guaranteeing correct behavior on all architectures.

The `parse_and_open()` function uses `OPT_BYTE` to parse the
feature_id and sel options. This means it writes a single byte
to the memory locations for `feature_id` and `sel` in the `feat_cfg`
struct.

However, these fields were declared as `enum`, which typically has
the size of an `int`. On big-endian architectures, writing a single
byte to the address of an `int` modifies the most significant byte,
resulting in an incorrect value being read. This caused the
`get-feature` command to fail. The command only worked on little-endian
systems.

Fix the issue by changing the type for `feature_id`
and `sel` to `__u8`. This ensures the fields are treated as single
bytes, guaranteeing correct behavior on all architectures.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
@maurizio-lombardi
Copy link
Contributor Author

This bug made nvme/055 blktest fail on big endian archs like s390x

@igaw igaw merged commit 468e60f into linux-nvme:master Aug 1, 2025
15 checks passed
@igaw
Copy link
Collaborator

igaw commented Aug 1, 2025

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants