]> www.infradead.org Git - users/sagi/libnvme.git/log
users/sagi/libnvme.git
16 months agonvme: allow to overwrite base sysfs path
Daniel Wagner [Tue, 30 Jan 2024 17:28:40 +0000 (18:28 +0100)]
nvme: allow to overwrite base sysfs path

In order to be able to test the topology scan code, make the
lookup paths flexible. Check if the LIBNVME_SYSFS_PATH environment
variable is set and if so use this as base path.

We could also introduce a setter for this, but this is really
a debugging interface and thus I don't really want it to be
visible in the public API.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
16 months agojson: dump the output to the user selected filedescriptor
Daniel Wagner [Wed, 31 Jan 2024 11:39:08 +0000 (12:39 +0100)]
json: dump the output to the user selected filedescriptor

Allow the user to select the output filedescriptor instead always
dumping it to stdout.

This allows to write the output to a file.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
16 months agolibnvme: export nvme_dump_tree
Daniel Wagner [Tue, 30 Jan 2024 17:26:04 +0000 (18:26 +0100)]
libnvme: export nvme_dump_tree

This function is available since the 1.0 release. Export it.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
16 months agofabrics: add 'concat' option
Hannes Reinecke [Thu, 18 Jan 2024 11:34:25 +0000 (12:34 +0100)]
fabrics: add 'concat' option

Add an option 'concat' to enable secure concatenation for TCP.

Signed-off-by: Hannes Reinecke <hare@suse.de>
16 months agomi: set correct rc and errno when crc mismatch
Jinliang Wang [Fri, 19 Jan 2024 07:47:04 +0000 (23:47 -0800)]
mi: set correct rc and errno when crc mismatch

Before the fix, when we meet crc mismatch response, the errno is 0
and rc is 1. This combination will be mistaken as Admin Generic Command
Status code value 0x1 (Invalid Command Opcode):
  $ nvme id-ctrl mctp:1,20
  crc mismatch
  NVMe status: Invalid Command Opcode: A reserved coded value or an
    unsupported value in the command opcode field(0x1

After the fix, the rc is -1, and errno is set to Bad message.
  $ nvme id-ctrl mctp:1,20
  crc mismatch
  identify controller: Bad message

Signed-off-by: Jinliang Wang <jinliangw@google.com>
16 months agotree: use logical block size for lba
Daniel Wagner [Fri, 19 Jan 2024 12:07:42 +0000 (13:07 +0100)]
tree: use logical block size for lba

The kernel export the LBA size via the logical_block_size sysfs entry
not the physical_block_size.

Fixes: 7959f52960fd ("tree: read all attributes from sysfs when available")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agojson-schema: add keyring and tls_key details
Daniel Wagner [Thu, 18 Jan 2024 13:40:40 +0000 (14:40 +0100)]
json-schema: add keyring and tls_key details

Update the JSON schema with the keyring and tls_key details.

Fixes: 7d1a68f13155 ("json-schema: add keyring and tls_key details")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: checkout full repo for checkpatch
Daniel Wagner [Thu, 18 Jan 2024 14:20:59 +0000 (15:20 +0100)]
build: checkout full repo for checkpatch

checkpatch likes to verify git references. Thus we need to checkout the
full repo to get this working.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agolinux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn
Martin George [Thu, 11 Jan 2024 09:31:22 +0000 (15:01 +0530)]
linux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn

Running nvme check-tls-key hits a segfault as seen below:

nvme check-tls-key
-d NVMeTLSkey-1:01:bB7soUnpHfxVg53sCY21KY3nLbqLit2RcIO8Rbdf3mKhcKaM:

Segmentation fault (core dumped)

This is because the strlen check on subsysnqn or hostnqn crashes at
src/nvme/linux.c due to either of them being null. Avoid this segfault
by checking these strings before running a strlen on them.

Signed-off-by: Martin George <marting@netapp.com>
17 months agoMerge pull request #770 from hreinecke/fix-join.v2 origin/HEAD origin/master
Hannes Reinecke [Thu, 18 Jan 2024 12:56:39 +0000 (13:56 +0100)]
Merge pull request #770 from hreinecke/fix-join.v2

meson.build: fixup 'join' syntax

17 months agomeson.build: fixup 'join' syntax
Hannes Reinecke [Thu, 18 Jan 2024 11:31:28 +0000 (12:31 +0100)]
meson.build: fixup 'join' syntax

The 'join' function only takes one argument, so use the correct
syntax here.

Signed-off-by: Hannes Reinecke <hare@suse.de>
17 months agoutil: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:44 +0000 (18:49 +0100)]
util: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
17 months agotree: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:36 +0000 (18:49 +0100)]
tree: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
17 months agolinux: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:49:25 +0000 (18:49 +0100)]
linux: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
17 months agofabrics: Explicitly initialize auto-cleanup variables
Tomas Bzatek [Fri, 29 Dec 2023 17:37:41 +0000 (18:37 +0100)]
fabrics: Explicitly initialize auto-cleanup variables

gcc complains about potentially uninitialized variables used
in the cleanup function even though such scenario is unlikely
to happen. Still, an explicit initializer makes the warnings
go away.

E.g.

../src/nvme/fabrics.c: In function ‘nvmf_hostnqn_generate’:
../src/nvme/fabrics.c:1297:30: note: ‘stream’ was declared here
 1297 |         _cleanup_file_ FILE *stream;
      |                              ^~~~~~
In function ‘cleanup_fd’,
    inlined from ‘uuid_from_device_tree’ at ../src/nvme/fabrics.c:1189:19,
    inlined from ‘nvmf_hostnqn_generate’ at ../src/nvme/fabrics.c:1350:9:
../src/nvme/cleanup.h:37:17: warning: ‘f’ may be used uninitialized [-Wmaybe-uninitialized]
   37 |                 close(*fd);
      |                 ^~~~~~~~~~

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
17 months agoutil: Added function to find specific UUID in UUID list.
Leonardo da Cunha [Fri, 15 Dec 2023 15:53:28 +0000 (07:53 -0800)]
util: Added function to find specific UUID in UUID list.

Finds a given UUID in the UUID list returned by identify UUID.

Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>
17 months agobuild: fix release python tag match
Daniel Wagner [Wed, 20 Dec 2023 10:04:24 +0000 (11:04 +0100)]
build: fix release python tag match

The version match should also accept patch level strings.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agodoc: Regenerate all docs for v1.7.1 v1.7.1
Daniel Wagner [Wed, 20 Dec 2023 09:51:58 +0000 (10:51 +0100)]
doc: Regenerate all docs for v1.7.1

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: Update version to v1.7.1
Daniel Wagner [Wed, 20 Dec 2023 09:51:34 +0000 (10:51 +0100)]
build: Update version to v1.7.1

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: handle patch level versioning
Daniel Wagner [Wed, 20 Dec 2023 09:48:31 +0000 (10:48 +0100)]
build: handle patch level versioning

Use the patch level identifier from the version string when it is
provided instead blindly extending the version string with '.0'. This
prevents patch level releases.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agotree: do no free ns on error in nvme_ns_init
Daniel Wagner [Wed, 20 Dec 2023 07:26:16 +0000 (08:26 +0100)]
tree: do no free ns on error in nvme_ns_init

The ns pointer is owned by the caller not by nvme_ns_init, thus we can't
just free it on error.

Fixes: 7959f52960fd ("tree: read all attributes from sysfs when available")
Reported-by: Tomasz Kłoczko <kloczek@fedoraproject.org>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: use build container with python support
Daniel Wagner [Tue, 19 Dec 2023 21:19:24 +0000 (22:19 +0100)]
build: use build container with python support

We should also build the Python binding, thus use the Debian container
with all Python dependencies installed.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: use single string to name tests
Daniel Wagner [Tue, 19 Dec 2023 21:11:53 +0000 (22:11 +0100)]
build: use single string to name tests

In order to be able to select to run a given test by name, use a single
string which makes it way simpler to execute, e.g.

  meson test -C .build --gdb python-import-libnvme

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agodoc: Regenerate all docs for v1.7 v1.7
Daniel Wagner [Tue, 19 Dec 2023 10:33:19 +0000 (11:33 +0100)]
doc: Regenerate all docs for v1.7

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: Update version to v1.7
Daniel Wagner [Tue, 19 Dec 2023 10:32:57 +0000 (11:32 +0100)]
build: Update version to v1.7

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: update json-c and openssl wrap
Daniel Wagner [Tue, 19 Dec 2023 10:12:43 +0000 (11:12 +0100)]
build: update json-c and openssl wrap

Update the two dependency to the latest upstream released one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agobuild: construct path to config.h manually
Daniel Wagner [Tue, 19 Dec 2023 09:40:21 +0000 (10:40 +0100)]
build: construct path to config.h manually

meson reports:

  internal/meson.build:25: DEPRECATION: Project uses feature that was
  always broken, and is now deprecated since '1.3.0': str.format: Value
  other than strings, integers, bools, options, dictionaries and lists
  thereof.

Thus just hardcode the config file path by using current_build_dir. Note
this changes the path from a relative one to an absolute one.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agotree: do not open blk device on default
Daniel Wagner [Thu, 7 Dec 2023 12:52:59 +0000 (13:52 +0100)]
tree: do not open blk device on default

The fd is not needed anymore if the kernel exposes all necessary sysfs
entries to fully scan the nvme subsystem. Thus do not alwyas open the
blk device and do it only when necessary.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
17 months agotree: read all attributes from sysfs when available
Daniel Wagner [Fri, 1 Dec 2023 09:23:29 +0000 (10:23 +0100)]
tree: read all attributes from sysfs when available

The kernel already exposes parts or all attributes we are looking up
with the ns id command. By reading these from the sysfs we can remove
the last command we are issuing during the topology scan.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
18 months agobuild(deps): bump actions/download-artifact from 3 to 4
dependabot[bot] [Mon, 18 Dec 2023 02:32:10 +0000 (02:32 +0000)]
build(deps): bump actions/download-artifact from 3 to 4

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4)

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

Signed-off-by: dependabot[bot] <support@github.com>
18 months agobuild(deps): bump actions/upload-artifact from 3 to 4
dependabot[bot] [Mon, 18 Dec 2023 02:32:06 +0000 (02:32 +0000)]
build(deps): bump actions/upload-artifact from 3 to 4

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

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

Signed-off-by: dependabot[bot] <support@github.com>
18 months agobuild: add codecov configuration
Daniel Wagner [Wed, 13 Dec 2023 08:29:40 +0000 (09:29 +0100)]
build: add codecov configuration

Unfortunatly, the codecov configuration wants to have it's own
configurtion file on top level of the project.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
18 months agobuild: ignore external code for code coverage check
Daniel Wagner [Wed, 13 Dec 2023 08:08:40 +0000 (09:08 +0100)]
build: ignore external code for code coverage check

Signed-off-by: Daniel Wagner <dwagner@suse.de>
18 months agoioctl: set data length when retrieving LBA status
Nate Thornton [Thu, 7 Dec 2023 22:02:16 +0000 (16:02 -0600)]
ioctl: set data length when retrieving LBA status

Current nvme_get_lba_status() function does specify any data_len in the
admin command, resulting in zero data being returned.

This is the least intrusive change as it requires no update to nvme-cli.

Signed-off-by: Nate Thornton <n.thornton@samsung.com>
18 months agobuild: add CFLAGS back when building with muon
Daniel Wagner [Thu, 16 Nov 2023 16:04:56 +0000 (17:04 +0100)]
build: add CFLAGS back when building with muon

Previous commit dropped the CLFAGS from the muon
configuration step. Add it back.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
18 months agotypes: fix regression for vendor-specific field in nvme_id_ns
Chris Patterson [Fri, 1 Dec 2023 06:21:15 +0000 (22:21 -0800)]
types: fix regression for vendor-specific field in nvme_id_ns

Recent versions of nvme-cli have started reading vs from offset
392 instead of 384. Previous PRs coupled the use of nvme_id_ns
for use in namespace management (create_ns).  However, the NVMe
spec has a different structure for namespace management, with
only a subset of the fields allowed/shared and some additional
fields.

To fix this, remove lbstm and restore the proper length for vs
from nvme_id_ns.

I expect that create_ns() should fully switch over to the
nvme_ns_mgmt_host_sw_specified struct which seems aligned with
the spec (though has some newer fields than what is available in
the latest NVMe Command Set Specification Revision 1.0c). This
will have to be addressed separately in nvme-cli.

https://github.com/linux-nvme/libnvme/pull/307
https://github.com/linux-nvme/nvme-cli/pull/1452

Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
18 months agoutil: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 02:15:34 +0000 (19:15 -0700)]
util: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 months agolinux: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 02:13:42 +0000 (19:13 -0700)]
linux: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 months agojson: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 01:33:43 +0000 (18:33 -0700)]
json: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.
Introduce _cleanup_tokener_ to call json_tokener_free() on cleanup.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 months agofabrics: use cleanup functions
Caleb Sander [Wed, 29 Nov 2023 01:21:29 +0000 (18:21 -0700)]
fabrics: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 months agotree: use cleanup functions
Caleb Sander [Tue, 28 Nov 2023 21:32:21 +0000 (14:32 -0700)]
tree: use cleanup functions

Use cleanup attributes from cleanup.h to avoid boilerplate cleanup code.
Introduce struct dirents and the corresponding _cleanup_dirents_
to clean up arrays of directory entries.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 months agocleanup: add cleanup functions
Caleb Sander [Tue, 28 Nov 2023 20:35:01 +0000 (13:35 -0700)]
cleanup: add cleanup functions

Introduce _cleanup_free_ from nvme-cli to call free() on cleanup,
_cleanup_file_ to call fclose(), _cleanup_dir_ to call closedir(),
and _cleanup_fd_ to call close().

_cleanup_free_ generalizes __cleanup__(cleanup_charp),
so remove it along with cleanup.c.

Signed-off-by: Caleb Sander <csander@purestorage.com>
18 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>
18 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>
18 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

18 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>
18 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>
18 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

19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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

19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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.

19 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>
19 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>
19 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>
20 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>