]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
19 months agotree: fix incorrect return value
Caleb Sander [Thu, 30 Nov 2023 18:58:22 +0000 (11:58 -0700)]
tree: fix incorrect return value

nvme_scan_subsystem() accidentally sets errno = -EINVAL
if the matching subsystem is filtered out.
This errno value will be overwritten by the out_free path with -ret,
where ret is the length of the path string.
Set ret = -EINVAL instead, so errno will be set to EINVAL.
This matches the behavior in the case where a new subsystem is allocated
and fails the filter function.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotree: Fix clearing application strings
Tomas Bzatek [Thu, 23 Nov 2023 17:52:20 +0000 (18:52 +0100)]
tree: Fix clearing application strings

Freeing strings without clearing to NULL may potentially lead
to double-free later when freeing the tree structs.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
20 months agoMerge pull request #749 from hreinecke/TP8018-fixes
Hannes Reinecke [Mon, 20 Nov 2023 06:17:37 +0000 (07:17 +0100)]
Merge pull request #749 from hreinecke/TP8018-fixes

Fixes for TP8018 support

20 months agolibnvme: reshuffle nvme_generate_tls_key_identity()
Hannes Reinecke [Mon, 20 Nov 2023 06:12:00 +0000 (07:12 +0100)]
libnvme: reshuffle nvme_generate_tls_key_identity()

Reshuffle nvme_generate_tls_key_identity and move it out of the
'#ifdef CONFIG_KEYUTILS' section to avoid build failures.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agolibnvme: fixup error codes
Hannes Reinecke [Mon, 20 Nov 2023 06:09:33 +0000 (07:09 +0100)]
libnvme: fixup error codes

The error code is ENOTSUP, not NOTSUP.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agoMerge pull request #748 from hreinecke/TP8018
Hannes Reinecke [Mon, 20 Nov 2023 05:40:20 +0000 (06:40 +0100)]
Merge pull request #748 from hreinecke/TP8018

Implement version 1 TLS identities as specified in TP8018

20 months agodoc: mention build helper script for muon build instruction
Daniel Wagner [Fri, 17 Nov 2023 08:56:12 +0000 (09:56 +0100)]
doc: mention build helper script for muon build instruction

The CI build steps are using the helper build.sh script. So instead
pointing to the workflow to see how this can be done, point to the build
script.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agolibnvme: Implement 'nvme_generate_tls_key_identity()'
Hannes Reinecke [Thu, 16 Nov 2023 08:03:28 +0000 (09:03 +0100)]
libnvme: Implement 'nvme_generate_tls_key_identity()'

Implement a function to generate the TLS key identity.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agolibnvme: support NVMe TLS identities version 1
Hannes Reinecke [Thu, 16 Nov 2023 06:41:37 +0000 (07:41 +0100)]
libnvme: support NVMe TLS identities version 1

With NVMe TP8018 a new version '1' for generating NVMe TLS identities
was specified; identities generated for this version require a PSK hash
to be attached to the version '0' identifier.
This patch implements a new function 'nvme_insert_tls_keys_versioned()'
to support this functionality and makes the original function
'nvme_insert_tls_keys()' a wrapper for the new function.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agolibnvme: Add base64 functions
Hannes Reinecke [Thu, 16 Nov 2023 06:28:56 +0000 (07:28 +0100)]
libnvme: Add base64 functions

Copied over from nvme-cli.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agolibnvme: separate out 'gen_tls_identity' and reshuffle 'derive_nvme_keys'
Hannes Reinecke [Thu, 16 Nov 2023 06:15:06 +0000 (07:15 +0100)]
libnvme: separate out 'gen_tls_identity' and reshuffle 'derive_nvme_keys'

Separate out a function to generate the TLS identity; this allows
us to reshuffle 'derive_nvme_keys()' to compile it only when
KEYUTILS is selected.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agobuild: Add -std=c99 for bootstrapping muon
Tokunori Ikegami [Sun, 12 Nov 2023 14:24:05 +0000 (23:24 +0900)]
build: Add -std=c99 for bootstrapping muon

On older distros the bootstrap step fails because C99 is not the
default C version. Thus explicitly set it.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[dwagner: updated commit message]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agobuild: remove the wrap feature dependency for muon
Daniel Wagner [Thu, 16 Nov 2023 15:21:11 +0000 (16:21 +0100)]
build: remove the wrap feature dependency for muon

We don't use the wrap feature for building libnvme in the minimal static
configuration. Thus we can drop the library dependency.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agobuild: pass the linker argument via muon argument
Daniel Wagner [Thu, 16 Nov 2023 15:19:44 +0000 (16:19 +0100)]
build: pass the linker argument via muon argument

Use the canonical way to set the static build using the command line
argument.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agobuild: do not rebuild muon/samu every time
Daniel Wagner [Thu, 16 Nov 2023 14:28:25 +0000 (15:28 +0100)]
build: do not rebuild muon/samu every time

There is not need to build the build tools everytime. Thus stage the
samurai and muon build into a new top level directory .build-tools and
only build them on demand.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agolibnvme: separate out a function 'select_hmac'
Hannes Reinecke [Thu, 16 Nov 2023 05:58:03 +0000 (06:58 +0100)]
libnvme: separate out a function 'select_hmac'

Separate out a function 'select_hmac' and pass in the HMAC value
to 'derive_retained_keys' and 'derive_tls_keys'.

Signed-off-by: Hannes Reinecke <hare@suse.de>
20 months agoMerge pull request #737 from prashanth-nayak/hkdf_expand_label
Hannes Reinecke [Wed, 15 Nov 2023 16:59:19 +0000 (17:59 +0100)]
Merge pull request #737 from prashanth-nayak/hkdf_expand_label

nvme: Add length field to Hkdf-Expand-Label computation

20 months agolibnvme: fix a memory leak when calling read_ssns()
Maurizio Lombardi [Tue, 7 Nov 2023 14:51:55 +0000 (15:51 +0100)]
libnvme: fix a memory leak when calling read_ssns()

If the check fails, the verify() macro executes "return -EINVAL"
without freeing the allocated memory.

Fix the bug by moving verify() before the point where we call calloc().

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
20 months agolibnvme: fix a memory leak in read_discovery()
Maurizio Lombardi [Tue, 7 Nov 2023 14:40:24 +0000 (15:40 +0100)]
libnvme: fix a memory leak in read_discovery()

In case of error, the "discovery" pointer should be freed.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
20 months agofabrics: avoid redundant args in nvme_discovery_log()
Caleb Sander [Tue, 8 Aug 2023 01:21:12 +0000 (19:21 -0600)]
fabrics: avoid redundant args in nvme_discovery_log()

nvme_discovery_log() takes nvme_get_log_args as input
and then overwrites many of its fields.
This leads to wasted code in the caller setting up unused fields.
Instead pass nvme_get_discovery_args, which more accurately
expresses the possible discovery log arguments.
As an added benefit, it also subsumes the other arguments.
And nvmf_get_discovery_wargs() can pass its arguments straight through.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agofabrics: have nvmf_get_discovery_log() call nvmf_get_discovery_wargs()
Caleb Sander [Tue, 8 Aug 2023 00:59:10 +0000 (18:59 -0600)]
fabrics: have nvmf_get_discovery_log() call nvmf_get_discovery_wargs()

There is a lot of duplicated code between nvmf_get_discovery_log()
and nvmf_get_discovery_wargs().
Since nvmf_get_discovery_wargs() is more general,
use it to implement nvmf_get_discovery_log().

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agofabrics: fetch smaller Discovery Log Page header
Caleb Sander [Tue, 1 Aug 2023 17:24:15 +0000 (11:24 -0600)]
fabrics: fetch smaller Discovery Log Page header

Most of the 1 KB Discovery Log Page header is reserved.
Only the first 18 bytes are currently defined.
So avoid transfering more data from the controller than necessary.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agofabrics: avoid redundant Get Log Page on retry
Caleb Sander [Tue, 1 Aug 2023 01:57:54 +0000 (19:57 -0600)]
fabrics: avoid redundant Get Log Page on retry

In case of a GENCTR mismatch, nvme_discovery_log() currently fetches
the Discovery Log Page header again before fetching the entries.
This is unnecessary since it was just fetched to determine GENCTR.
So only fetch the header once and re-use it for the next loop iteration.

Remove a couple of unnecessary variables in the process.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agofabrics: clear RAE for discovery log page commands
Caleb Sander [Tue, 1 Aug 2023 01:29:03 +0000 (19:29 -0600)]
fabrics: clear RAE for discovery log page commands

In several circumstances, nvme_discovery_log() leaves the RAE bit set
for all Get Log Page commands it issues.
This happens if the header indicates the log page has no records,
or if a command other than the header re-fetch errors out.
If the RAE bit is never cleared, the controller will not send more
Discovery Asynchronous Event Notifications.
Setting the RAE bit is not necessary to avoid missed events since
the use of GENCTR ensures the log page is fetched atomically.
It is better to risk receiving additional AENs
than for the discovery controller to never send more AENs
because it is waiting for a Get Log Page command that never comes.
So clear the RAE bit when fetching each piece of the log page.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agobuild, CI: Add a GitHub Action to run the checkpatch.pl script
Martin Belanger [Thu, 2 Nov 2023 14:00:56 +0000 (10:00 -0400)]
build, CI: Add a GitHub Action to run the checkpatch.pl script

Adding new workflow to run the checkpatch.pl script from the Linux kernel.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
20 months agojson-schema: add keyring and tls_key details
Martin George [Wed, 1 Nov 2023 11:27:04 +0000 (16:57 +0530)]
json-schema: add keyring and tls_key details

Update the JSON schema with the keyring and tls_key details.

Signed-off-by: Martin George <marting@netapp.com>
20 months agotypes: add Host Behavior Support field definitions
Caleb Sander [Wed, 25 Oct 2023 20:47:06 +0000 (14:47 -0600)]
types: add Host Behavior Support field definitions

Bytes 1 and 2 are now defined as fields ETDAS and LBAFEE,
so update the struct nvme_feat_host_behavior definition.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotest: Cast values to u32 if shift overflows int
Caleb Sander [Thu, 2 Nov 2023 13:29:56 +0000 (14:29 +0100)]
test: Cast values to u32 if shift overflows int

Bit shifts that overflow the resulting type are undefined behavior in C.
C arithmetic promotes to ints all smaller integer types.
There are several places where a 32-bit unsigned value
is constructed by shifting a u8 or u16 to the most significant bits.
Since this overflows a signed 32-bit integer,
explicitly cast to u32 to avoid the UB.
Technically, an int is allowed to only be 16 bits,
so any shift that could set bit 15 or higher is UB.
But platforms where int is s16 are not very common,
so it's likely not worth the effort to fix the code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agomi: Cast values to u32 if shift overflows int
Caleb Sander [Thu, 2 Nov 2023 13:29:46 +0000 (14:29 +0100)]
mi: Cast values to u32 if shift overflows int

Bit shifts that overflow the resulting type are undefined behavior in C.
C arithmetic promotes to ints all smaller integer types.
There are several places where a 32-bit unsigned value
is constructed by shifting a u8 or u16 to the most significant bits.
Since this overflows a signed 32-bit integer,
explicitly cast to u32 to avoid the UB.
Technically, an int is allowed to only be 16 bits,
so any shift that could set bit 15 or higher is UB.
But platforms where int is s16 are not very common,
so it's likely not worth the effort to fix the code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotypes: Cast values to u32 if shift overflows int
Caleb Sander [Sat, 14 Oct 2023 01:28:33 +0000 (19:28 -0600)]
types: Cast values to u32 if shift overflows int

Bit shifts that overflow the resulting type are undefined behavior in C.
C arithmetic promotes to ints all smaller integer types.
There are several places where a 32-bit unsigned value
is constructed by shifting a u8 or u16 to the most significant bits.
Since this overflows a signed 32-bit integer,
explicitly cast to u32 to avoid the UB.
Technically, an int is allowed to only be 16 bits,
so any shift that could set bit 15 or higher is UB.
But platforms where int is s16 are not very common,
so it's likely not worth the effort to fix the code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotest: Avoid unaligned pointer dereferences
Caleb Sander [Thu, 2 Nov 2023 13:26:36 +0000 (14:26 +0100)]
test: Avoid unaligned pointer dereferences

Avoid casting byte-aligned pointers to pointers with higher alignment.
Loading or storing values with higher alignment is undefined behavior,
since some processors don't allow unaligned memory accesses
and compilers may assume pointers of different types don't alias.
Perform an explicit memcpy(), which an optimizing compiler
can easily replace with a single load/store on supported architectures.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agonbft: Avoid unaligned pointer dereferences
Caleb Sander [Sat, 14 Oct 2023 04:35:43 +0000 (22:35 -0600)]
nbft: Avoid unaligned pointer dereferences

Avoid casting byte-aligned pointers to pointers with higher alignment.
Loading or storing values with higher alignment is undefined behavior,
since some processors don't allow unaligned memory accesses
and compilers may assume pointers of different types don't alias.
Perform an explicit memcpy() in two places, which an optimizing compiler
can easily replace with a single load/store on supported architectures.

While we're touching this code, also use IN6_IS_ADDR_V4MAPPED()
instead of hand-rolling it.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotest: don't pass NULL to memcmp() or memset()
Caleb Sander [Sat, 14 Oct 2023 01:28:09 +0000 (19:28 -0600)]
test: don't pass NULL to memcmp() or memset()

According to the C standard, it is undefined behavior
to pass NULL pointers to standard library functions.
This includes the mem*() family of functions,
even they are passed a length of 0.
So avoid calling these functions when the length is 0.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotest: make LD_PRELOAD tests work with ASAN
Caleb Sander [Sat, 14 Oct 2023 01:13:56 +0000 (19:13 -0600)]
test: make LD_PRELOAD tests work with ASAN

Several tests mock libc functions by setting LD_PRELOAD
to a shared library containing mock implementations of the functions.
Currently this prevents the tests from running with ASAN.
ASAN complains that libasan doesn't come first in LD_PRELOAD and aborts.
But in practice this doesn't seem to be an issue.
Sample ASAN issues added to libnvme, the test cases, and the mocks
are all correctly reported.
So suppress this warning by setting the environment variable
ASAN_OPTIONS=verify_asan_link_order=0.
In case the user does want to inject a specific libasan,
change the tests' use of LD_PRELOAD to append the mock shared library
rather than overwriting LD_PRELOAD entirely.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agoreadme: add instructions for enabling UBSAN
Caleb Sander [Sat, 14 Oct 2023 05:00:48 +0000 (23:00 -0600)]
readme: add instructions for enabling UBSAN

The undefined behavior sanitizer can catch a bunch of common C bugs.
Add instructions to the README for enabling it via meson.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agoreadme: clarify that LD_PRELOAD is not needed for ASAN
Caleb Sander [Fri, 13 Oct 2023 23:41:30 +0000 (17:41 -0600)]
readme: clarify that LD_PRELOAD is not needed for ASAN

The README currently suggests setting LD_PRELOAD to the libasan path.
However, this seems to be unnecessary (at least on my gcc 9 setup).
The test executables request to link with libasan.so (before libc.so),
so it is automatically loaded.
The recommended suggestion also ends up running ninja with ASAN
instrumentation, which causes it to fail with leaks detected.

Signed-off-by: Caleb Sander <csander@purestorage.com>
20 months agotypes: add cross-namespace copy formats, status codes, ONCS bits
Joy Gu [Wed, 25 Oct 2023 20:47:42 +0000 (13:47 -0700)]
types: add cross-namespace copy formats, status codes, ONCS bits

Add support for NVMe TP4130 ("Cross-Namespace Copy"):
- Add Copy Descriptor Formats 2h and 3h
- Add new status codes for Copy: Incompatible Namespace or Format, Fast
  Copy Not Possible, Overlapping I/O Range, and Insufficient Resources
- Add two new ONCS bits NVMCSA and NVMAFC
- Add Copy Descriptor Formats Enable (CDFE) to Host Behavior Support
  Data Structure

[dwagner: whitespace cleanups
          moved new functions to 1.7 linker section]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agonvme: Add length field to Hkdf-Expand-Label computation
Prashanth Nayak [Tue, 24 Oct 2023 17:42:40 +0000 (13:42 -0400)]
nvme: Add length field to Hkdf-Expand-Label computation

Fix to add the 2 byte length field to the HKDF-Expand-Label computation for retained and TLS PSK.

20 months agoioctl: use lsp arg in nvme_get_log_boot_partition
Daniel Wagner [Tue, 31 Oct 2023 15:41:13 +0000 (16:41 +0100)]
ioctl: use lsp arg in nvme_get_log_boot_partition

The function ask for the lsp but doesn't pass it to the command.

Fixes: 21acd638c4c9 ("types: add boot partition log support")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agobuild: do not setup python
Daniel Wagner [Tue, 31 Oct 2023 17:21:44 +0000 (18:21 +0100)]
build: do not setup python

The build container already ships the Python toolchain, so there is no
need to map the toolchain from the base container.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
20 months agofabrics: use SECTYPE to determine whether to use TLS
Caleb Sander [Tue, 20 Jun 2023 03:17:16 +0000 (21:17 -0600)]
fabrics: use SECTYPE to determine whether to use TLS

The NVMe specfications are clear that the discovery log page entry
SECTYPE field indicates whether TLS is supported.
Currently the TREQ field is used, which results in enabling TLS
even when SECTYPE = "No Security" and TREQ = "Not required".
Only enable TLS if SECTYPE indicates a TLS version is enabled.

From the NVMe/TCP transport specification, version 1.0c:
Security Type (SECTYPE): Specifies the type of security used by the
NVMe/TCP port. If SECTYPE is a value of 0h (No Security), then the host
shall set up a normal TCP connection.

From TP 8018:
The SECTYPE value of 0h (i.e., No Security) specifies that TLS is not
supported.

From TP 8025 (the "TLS Permitted" host case):
If the SECTYPE field in the TSAS field in the discovery log entry for
the remote entity is cleared to zero and the TSC field is not set to 01b
(i.e., Required), then initiate TCP connections without TLS.

Fixes: 3962a45 ("fabrics: add fabrics config option 'tls'")
Signed-off-by: Caleb Sander <csander@purestorage.com>
21 months agofabrics: Allocate aligned payloads for id_ctrl and discovery log calls
Tomas Bzatek [Thu, 12 Oct 2023 16:43:16 +0000 (18:43 +0200)]
fabrics: Allocate aligned payloads for id_ctrl and discovery log calls

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
21 months agolinux: Allocate aligned payloads for id_ctrl and id_ns calls
Tomas Bzatek [Thu, 12 Oct 2023 16:42:34 +0000 (18:42 +0200)]
linux: Allocate aligned payloads for id_ctrl and id_ns calls

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
21 months agoioctl: MSB variable-size storage/reference tags
Brandon Paupore [Mon, 9 Oct 2023 21:19:17 +0000 (16:19 -0500)]
ioctl: MSB variable-size storage/reference tags

The spec defines these values on a bitwise basis within the shared
80-bit region, stored from MSB to LSB for each tag. Mechanically this
can be achieved by setting the values as big-endian using the same logic
currently in place.

Reviewed-by: Jeffrey Lien <jeff.lien@wdc.com>
Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
21 months agobuild: upload artifacts only for upstream repo
Daniel Wagner [Wed, 11 Oct 2023 10:08:54 +0000 (12:08 +0200)]
build: upload artifacts only for upstream repo

Only upload any artifacts to linux-nvme organization if it's NOT a fork.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
21 months agotree: Allocate aligned payloads for ns scan
Tomas Bzatek [Tue, 10 Oct 2023 16:18:38 +0000 (18:18 +0200)]
tree: Allocate aligned payloads for ns scan

libnvme is actually doing some namespace identification
during tree scan, leading to stack smash on some systems.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
21 months agoutil: Introduce alloc helper with alignment support
Tomas Bzatek [Tue, 10 Oct 2023 16:16:24 +0000 (18:16 +0200)]
util: Introduce alloc helper with alignment support

Similar to nvme-cli an alloc helper is needed for a couple
of ioctls sent out during tree scan.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
21 months agobuild: remove symbol which doesn't exist in libnvme-mi.so
Alfred Wingate [Tue, 10 Oct 2023 01:22:48 +0000 (04:22 +0300)]
build: remove symbol which doesn't exist in libnvme-mi.so

* Added in bb70b874dac13a15c37ce1dd1de866d6a5dd428d, but was never used.

Signed-off-by: Alfred Wingate <parona@protonmail.com>
21 months agomeson: make building tests conditional
Sam James [Sat, 30 Sep 2023 05:43:39 +0000 (06:43 +0100)]
meson: make building tests conditional

Just like we do for docs.

Signed-off-by: Sam James <sam@gentoo.org>
21 months agotest: handle POSIX ioctl prototype
Sam James [Sat, 30 Sep 2023 05:38:53 +0000 (06:38 +0100)]
test: handle POSIX ioctl prototype

glibc has the following prototype for ioctl: int ioctl(int fd, unsigned long request, ...)
POSIX (inc. musl) has the following for ioctl: int ioctl(int fd, int request, ...)

Check which prototype is used in <sys/ioctl.h> to avoid a conflict and conditionally
define the right one for the system.

Bug: https://bugs.gentoo.org/914921
Signed-off-by: Sam James <sam@gentoo.org>
21 months agodoc: Regenerate all docs for v1.6 v1.6
Daniel Wagner [Fri, 29 Sep 2023 06:26:50 +0000 (08:26 +0200)]
doc: Regenerate all docs for v1.6

Signed-off-by: Daniel Wagner <dwagner@suse.de>
21 months agobuild: Update version to v1.6
Daniel Wagner [Fri, 29 Sep 2023 06:26:28 +0000 (08:26 +0200)]
build: Update version to v1.6

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agodocs: Fix Read-the-Docs configuration (deprecated config param)
Martin Belanger [Wed, 27 Sep 2023 15:25:41 +0000 (11:25 -0400)]
docs: Fix Read-the-Docs configuration (deprecated config param)

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agoREADME: Fix meson/python build badges
Martin Belanger [Wed, 27 Sep 2023 15:22:13 +0000 (11:22 -0400)]
README: Fix meson/python build badges

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agomi-mctp: Fix free() in error path of mi_open_mctp
Jeremy Kerr [Sat, 23 Sep 2023 16:44:50 +0000 (09:44 -0700)]
mi-mctp: Fix free() in error path of mi_open_mctp

If the malloc of our struct nvme_mi_transport_mctp fails, we'll attempt
to free ->rsp_buf of this (now zero) pointer.

Instead, structure the error path to progressively undo the
initialisation operations. This means we'll need to save the errno at
the site of each possible failure.

In doing this, add a comment to the call to nvme_mi_close(), just to
clarify behaviour with regards to the cleanups through that path.

Reported-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
22 months agotypes: Use NVME_SET for status type mask to get status value
Tokunori Ikegami [Sat, 17 Jun 2023 01:56:26 +0000 (10:56 +0900)]
types: Use NVME_SET for status type mask to get status value

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agotypes: Define FLBAS MASK and SHIFT to use NVME_GET
Tokunori Ikegami [Sat, 17 Jun 2023 01:24:56 +0000 (10:24 +0900)]
types: Define FLBAS MASK and SHIFT to use NVME_GET

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agobuild: abort CI builds on first error
Daniel Wagner [Thu, 21 Sep 2023 07:27:35 +0000 (09:27 +0200)]
build: abort CI builds on first error

Do not continue to build and hide any errors.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotypes: Support Phy Rx Eye Opening Measurement Log
Brandon Paupore [Tue, 12 Sep 2023 21:45:31 +0000 (16:45 -0500)]
types: Support Phy Rx Eye Opening Measurement Log

This implements support for TP4119a, adding various fields and functions
to enable better handling of the new Physical Receiver Eye Opening
Measurement log page.

Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
22 months agolog: Add nvme root global variable to set for default output
Tokunori Ikegami [Mon, 26 Jun 2023 15:06:59 +0000 (00:06 +0900)]
log: Add nvme root global variable to set for default output

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[dwagner: export new function, update docs, reorder free sequence]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotypes: Add support for the OAQD ID controller field
Brandon Paupore [Fri, 8 Sep 2023 20:30:33 +0000 (15:30 -0500)]
types: Add support for the OAQD ID controller field

Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
[dwagner: dropped generated documentation change]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: use non deprecated API
Daniel Wagner [Wed, 20 Sep 2023 08:30:19 +0000 (10:30 +0200)]
test: use non deprecated API

A few of the feature related function have been deprecated. Update the
test to use the new APIs instead of the old one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: add tests for Get/Set Features functions
Caleb Sander [Fri, 8 Sep 2023 19:07:36 +0000 (13:07 -0600)]
test: add tests for Get/Set Features functions

Use the mock ioctl() infrastructure to test the functions in ioctl.h
that issue Set Features and Get Features commands.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: implement nvme_set_features_lba_range()
Caleb Sander [Fri, 15 Sep 2023 01:22:58 +0000 (19:22 -0600)]
ioctl: implement nvme_set_features_lba_range()

nvme_set_features_lba_range() was missing an implementation,
so add one. Change nr_ranges to a u8 since its maximum value is 64.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass NSID in Get/Set Features commands that use it
Caleb Sander [Fri, 15 Sep 2023 19:20:19 +0000 (13:20 -0600)]
ioctl: pass NSID in Get/Set Features commands that use it

Several features are configured on a per-namespace basis
by setting the NSID in the Set Features and Get Features commands.
But the corresponding nvme_{g,s}et_features_*() functions
aren't passing the NSID in the commands.
For the functions missing a NSID parameter, define new variants
with the NSID argument added and mark the old functions as deprecated.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: fix swapped parameters in nvme_set_features_host_id()
Caleb Sander [Thu, 14 Sep 2023 21:52:17 +0000 (15:52 -0600)]
ioctl: fix swapped parameters in nvme_set_features_host_id()

nvme_set_features_host_id()'s prototype says the parameter EXHID
comes before SAVE, but its definition does the opposite,
causing the parameters to be misinterpreted.
Match the definition to the declaration.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: export nvme_{g,s}et_features_iocs_profile()
Caleb Sander [Thu, 14 Sep 2023 21:14:13 +0000 (15:14 -0600)]
ioctl: export nvme_{g,s}et_features_iocs_profile()

nvme_get_features_iocs_profile() and nvme_set_features_iocs_profile()
are defined but not exorted in libnvme.so.
nvme_set_features_iocs_profile()'s prototype was also removed,
so add it back.
IOCSI is a 9-bit value, so fix its bitmask and change its type to u16.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass ENDGID in nvme_get_features_endurance_event_cfg()
Caleb Sander [Thu, 14 Sep 2023 20:56:31 +0000 (14:56 -0600)]
ioctl: pass ENDGID in nvme_get_features_endurance_event_cfg()

The ENDGID parameter of nvme_get_features_endurance_event_cfg()
is currently unused.
According to the NVMe spec, it should be passed in CDW 11.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: don't set SAVE bit on unsaveable features
Caleb Sander [Thu, 14 Sep 2023 20:23:39 +0000 (14:23 -0600)]
ioctl: don't set SAVE bit on unsaveable features

According to the NVMe spec, the Host Behavior
and Write Protection features are not saveable.
Setting the SAVE bit may cause the Set Features command to be rejected,
so don't set it for these features.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: avoid sending uninitialized timestamp
Caleb Sander [Fri, 8 Sep 2023 19:47:16 +0000 (13:47 -0600)]
ioctl: avoid sending uninitialized timestamp

The last 2 bytes of the struct nvme_timestamp data
are not initialized in nvme_set_features_timestamp().
Add an initializer to avoid sending uninitialized stack memory
to the controller.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: pass data for Get/Set Features commands
Caleb Sander [Fri, 8 Sep 2023 18:10:08 +0000 (12:10 -0600)]
ioctl: pass data for Get/Set Features commands

Several nvme_{g,s}et_features_*() functions take a data buffer
but don't provide it to the Get/Set Features commands.
Fix them to pass the data buffer to nvme_{g,s}et_features().

Getting the Host Memory Buffer feature also returns
a struct nvme_host_mem_buf_attrs data structure,
so make a nvme_get_features_host_mem_buf2() function
that takes in a data buffer to receive it.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: set correct bits in Set Features commands
Caleb Sander [Fri, 8 Sep 2023 16:51:19 +0000 (10:51 -0600)]
ioctl: set correct bits in Set Features commands

A few nvme_set_features_*() functions are setting the wrong bits in
CDW11 based on their inputs. Correct the fields passed to NVME_SET().

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agoioctl: correct feature IDs in Get/Set Features commands
Caleb Sander [Fri, 8 Sep 2023 18:21:04 +0000 (12:21 -0600)]
ioctl: correct feature IDs in Get/Set Features commands

Several nvme_{g,s}et_features_*() functions use the wrong feature ID.
Correct them so the intended feature is requested.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agotree: Add 2 new public functions to lookup existing controllers
Martin Belanger [Tue, 12 Sep 2023 19:55:55 +0000 (15:55 -0400)]
tree: Add 2 new public functions to lookup existing controllers

There is duplicate code between libnvme and nvme-cli. When trying
to instantiate a controller, both libnvme and nvme-cli scan the
sysfs looking for an existing controller that can be reused.

This patch adds nvme_ctrl_find() and nvme_ctrl_config_match().
These functions can be used by nvme-cli to lookup existing
controllers. This will allow removing the duplicate code in
nvme-cli (separate commit to follow on the nvme-cli GitHub repo).

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agoioctl: Add debugging feature to show command outputs
Tokunori Ikegami [Tue, 12 Sep 2023 14:42:32 +0000 (23:42 +0900)]
ioctl: Add debugging feature to show command outputs

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agoFix incorrect article 'an' as 'a' to use for a description
Tokunori Ikegami [Mon, 15 May 2023 15:48:18 +0000 (00:48 +0900)]
Fix incorrect article 'an' as 'a' to use for a description

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
22 months agolinux: Added functions to enable faster telemetry data retrieval.
da Cunha, Leonardo [Wed, 23 Aug 2023 18:26:39 +0000 (11:26 -0700)]
linux: Added functions to enable faster telemetry data retrieval.
Moved telemetry data area support detection into separate function.
Added possibility to modify data transfer chunk size.
Enable telemetry extraction up to specified data area.
Removed some printf() and perror().

Signed-off-by: leonardo.da.cunha <leonardo.da.cunha@solidigm.com>
22 months agobuild(deps): bump actions/checkout from 3 to 4
dependabot[bot] [Mon, 11 Sep 2023 02:39:36 +0000 (02:39 +0000)]
build(deps): bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
22 months agotest: account for discovery log page entry stripping
Caleb Sander [Wed, 30 Aug 2023 16:45:57 +0000 (10:45 -0600)]
test: account for discovery log page entry stripping

The discovery log page tests incorrectly assumed the log page
nvmf_get_discovery_log() returns exactly matches what was fetched.
This failed to account for the trailing space trimming
of the TRSVCID and TRADDR fields.
If the arbitrary entries happened to contain trailing spaces
for these fields, the test cases would fail.
Generate arbitrary entries with space-padded strings for the log page
and corresponding expected entries with NUL-padded strings.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agofabrics: unconditionally strip discovery entry strings
Caleb Sander [Wed, 30 Aug 2023 15:53:19 +0000 (09:53 -0600)]
fabrics: unconditionally strip discovery entry strings

The NVMe base specification defines fields TRSVCID and TRADDR
as "ASCII strings", meaning they are space-padded.
Therefore, whether spaces need to be stripped from them
doesn't depend on the transport or address family.
Some combinations already appear to be missing,
such as RDMA using IB addresses.
And if new transports are added in the future,
sanitize_discovery_log_entry() would need to be updated.

So strip spaces from these fields regardless of the entry's
transport type or address family.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agofabrics: only look for spaces in strchomp()
Caleb Sander [Wed, 30 Aug 2023 15:44:48 +0000 (09:44 -0600)]
fabrics: only look for spaces in strchomp()

strchomp() is only needed to strip trailing spaces from a string.
There is no need to replace NUL characters with NUL characters.
So simplify the check for "NUL or space" to just "space".
Update the function description as well,
as it doesn't strip all whitespace, just spaces.

Signed-off-by: Caleb Sander <csander@purestorage.com>
22 months agotree: Use early return instead of else statements
Martin Belanger [Thu, 31 Aug 2023 15:01:51 +0000 (11:01 -0400)]
tree: Use early return instead of else statements

The code could be simplified and made more readable by using
early returns instead of else statements.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agobuild: use latest container instead fixed version master
Daniel Wagner [Thu, 31 Aug 2023 14:19:50 +0000 (16:19 +0200)]
build: use latest container instead fixed version

We control the build containers so there is little risk
that these randomly break. So let's go with the latest
version and avoid updating the build files all the time.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: run tests before coverage tool
Daniel Wagner [Thu, 31 Aug 2023 12:12:12 +0000 (14:12 +0200)]
build: run tests before coverage tool

Obviously, we need to run the tests before the coverage tool.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: fix coverage report build
Daniel Wagner [Thu, 31 Aug 2023 12:03:34 +0000 (14:03 +0200)]
build: fix coverage report build

We need to run the build first, before we can run the coverage tool.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: checkout repo in coverage build
Daniel Wagner [Thu, 31 Aug 2023 09:45:47 +0000 (11:45 +0200)]
build: checkout repo in coverage build

The previous commit removed accidentally the checkout step.
Add it back.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use container for coverage build
Daniel Wagner [Thu, 31 Aug 2023 09:40:17 +0000 (11:40 +0200)]
build: use container for coverage build

The coverage build also fails due missing dependency in
install step. Let's use a prebuild container here as well.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use debian container for release-python build
Daniel Wagner [Thu, 31 Aug 2023 07:37:19 +0000 (09:37 +0200)]
build: use debian container for release-python build

The build keeps failing because the dependencies can't be installed.
Let's use the prebuild container for this as well.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agobuild: use prebuild container images for cross builds
Daniel Wagner [Wed, 30 Aug 2023 17:31:11 +0000 (19:31 +0200)]
build: use prebuild container images for cross builds

The cross tool installation is breaking very often. Let's use a prebuild
container for this.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: fix lookup test case
Daniel Wagner [Wed, 30 Aug 2023 14:38:42 +0000 (16:38 +0200)]
test: fix lookup test case

The tcp lookup test is not correct. The trsvcid is mandatory and thus we
have only to try to lookup all combination of host_traddr and host_iface.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: make all function static
Daniel Wagner [Wed, 30 Aug 2023 12:54:51 +0000 (14:54 +0200)]
test: make all function static

No need to export local functions.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
22 months agotest: add tests for new tcp controller matching algorithm
Martin Belanger [Fri, 18 Aug 2023 01:36:01 +0000 (21:36 -0400)]
test: add tests for new tcp controller matching algorithm

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agotree: Improve TCP controller matching algorithm
Martin Belanger [Fri, 18 Aug 2023 01:35:34 +0000 (21:35 -0400)]
tree: Improve TCP controller matching algorithm

The configuration parameters used to connect to a TCP controller are:

1. transport - "tcp"
2. traddr - Destination address (controller's IP address)
3. trsvcid - Service ID (controller's port - typically 8009 or 4420)
4. host-traddr - Source address (host's IP address)
5. host-iface - Physical/Logical interface where the connection will be made

For TCP, transport, traddr, and trsvcid are mandatory, while the
host-traddr and host-iface are optional. The host-traddr and host-iface
can be used as "overrides" to select a different source address and
interface than those that the kernel would choose by default.

When an application using libnvme to connect to a controller does
not specify the host-traddr or host-iface, the kernel will have to
determine the best interface and source address by itself. It does that
by looking up the destination address (traddr) in the routing table to
determine the best interface for the connection. The kernel then
retrieves the primary IP address assigned to that interface and uses that
as the connection's source address. By default, the kernel always uses
the interface's primary address as the connection's source address
unless host-traddr is used to override it.

Prior to version 6.1, the kernel did not reveal the source address or
interface it selected. Therefore, it was impossible for user-space apps
to tell exactly where connections were made. With kernel 6.1 (and later),
the sysfs now exposes the source address as "src_addr=" in the nvme
"address" attribute. The src_addr not only provides us with the
connection's source address, but by scanning the interface map one can
find out which interface owns that source address and precisely determine
on which interface each connection is made.

With TP8010 and the introduction of the Centralized Discovery Controller
(CDC), it is very important for hosts to connect to CDCs with a consistent
source address. That's because of the way the CDC keeps track of all the
hosts that connect to it. In addition to the host NQN, the CDC also checks
the host IP address (the connection's source address) to uniquely identify
a host. This unique identifier is then used for fabric zoning.

With fabric zoning, administrators configure the list of I/O controllers
that a host is allowed to connect to. The CDC sends the list of I/O
controllers to the host in response to a Get Discovery Log Page (DLP)
command from the host. If a host does not connect to the CDC with the
right source address, it will receive invalid DLP entries (wrong zone).
This will cause the host to connect to the wrong I/O controllers.

libnvme tries to avoid making duplicate connections to the same
controller. This avoids consuming precious kernel resources. When an
application requests libnvme to connect to a controller (the candidate
controller), libnvme scans the sysfs to see if an existing connection
matches the candidate. If a matching connection is found, libnvme just
reuses it instead of creating a new one.

Matching the 3 mandatory parameters (transport, traddr, trsvcid) between
existing connections and a candidate connection is easy because they can
never be NULL and can therefore be compared. It is not the case for the
host-traddr and host-iface. These optional parameters can be NULL. A NULL
host-traddr or host-iface means that we have left it to the kernel to
determine the interface and source address to use for the connection.
Therefore, if we want to compare a non-NULL candidate host-traddr to
an existing connection with a NULL host-traddr, we cannot just compare the
two. They will obviously be different. Instead, we need to check the
src_addr of the existing connection to see if it matches the candidate's
host-traddr.

Prior to this patch, libnvme performed a simple string comparison
between the candidate's host-traddr (or host-iface) and the existing
connection's host-traddr (or host-iface). A match would be declared if
both were the same (including both NULL). Also, a match would even be
declared if the existing connection's host-traddr (or host-iface) was
NULL while the candidate's host-traddr (or host-iface) was non-NULL.
This is wrong and can lead to the wrong connections being reused and
the wrong DLP entries returned by the CDC.

With this patch, when a candidate wants a specific source address
(host-traddr != NULL) or interface (host-iface != NULL), libnvme will
now check the src_addr of each existing connection to ensure a 100%
match. If the src_addr is not available (kernel older than 6.1), then we
can still infer the real interface and source address of an existing
connection, if the existing connection has either its host-traddr or
host-iface defined (check code to see how it's done).

It's only when an exsiting connection's src_addr, host-iface, and
host-traddr are all NULL that we cannot clearly match to a candidate.
When that happens, libnvme will take an optimistic approach and
declare a match even though it doesn't have enough info to do so.
This "optimistic match" follows what libnvme was doing prior to this
patch.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
22 months agoutil: Add functions to parse the system's interfaces
Martin Belanger [Fri, 18 Aug 2023 01:28:57 +0000 (21:28 -0400)]
util: Add functions to parse the system's interfaces

1) nvme_iface_matching_addr() identifies which interface owns a
specific IP address.

2) nvme_iface_primary_addr_matches() checks that the primary IP
address of a given interface matches a specific IP address.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotypes: Add support for EGFEAT, Domain Identifier, TEGCAP and UEGCAP
Tokunori Ikegami [Fri, 18 Aug 2023 20:08:15 +0000 (05:08 +0900)]
types: Add support for EGFEAT, Domain Identifier, TEGCAP and UEGCAP

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
23 months agomi: remove nsid from nvme_mi_admin_identify_secondary_ctrl_list()
Daniel Wagner [Sat, 19 Aug 2023 10:44:07 +0000 (12:44 +0200)]
mi: remove nsid from nvme_mi_admin_identify_secondary_ctrl_list()

According to the NVMe specification, Identify CNS value 15h
("Secondary Controller list of controllers associated with the primary
controller processing the command") does not use the NSID field. So
remove the "nsid" argument from
nvme_mi_admin_identify_secondary_ctrl_list().

Fixes: 07b63103878 ("ioctl: remove nsid from nvme_identify_secondary_ctrl_list()")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
23 months agotest: add tests for nvme_ctrl_get_src_addr()
Martin Belanger [Thu, 17 Aug 2023 11:57:50 +0000 (07:57 -0400)]
test: add tests for nvme_ctrl_get_src_addr()

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotree: Add nvme_ctrl_get_src_addr() to get the controller's src_addr
Martin Belanger [Thu, 17 Aug 2023 10:46:26 +0000 (06:46 -0400)]
tree: Add nvme_ctrl_get_src_addr() to get the controller's src_addr

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agoutil: Split _nvme_ipaddrs_eq() from nvme_ipaddrs_eq()
Martin Belanger [Thu, 17 Aug 2023 10:44:45 +0000 (06:44 -0400)]
util: Split _nvme_ipaddrs_eq() from nvme_ipaddrs_eq()

Extract the core algorithm from nvme_ipaddrs_eq() and create
a reusable function _nvme_ipaddrs_eq().

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
23 months agotest: add tests for Identify functions
Caleb Sander [Sat, 12 Aug 2023 20:50:47 +0000 (14:50 -0600)]
test: add tests for Identify functions

Use the mock ioctl() infrastructure to test  the functions in ioctl.h
that issue Identify commands.
nvme_identify_ns_csi_user_data_format() and
nvme_identify_iocs_ns_csi_user_data_format() are omitted
since they're not defined in the NVMe specification yet
Functions tested indirectly from other functions are also omitted.

Signed-off-by: Caleb Sander <csander@purestorage.com>