├── test ├── dax-ext4.sh ├── dax-xfs.sh ├── nmem1.bin ├── nmem2.bin ├── nmem3.bin ├── nmem4.bin ├── cxl-security.sh ├── nfit-security.sh ├── hugetlb.c ├── cxl-features.sh ├── sector-mode.sh ├── max_available_extent_ns.sh ├── multi-dax.sh ├── track-uuid.sh ├── create.sh ├── label-compat.sh ├── cxl-security ├── nfit-security ├── device-dax-fio.sh ├── cxl-labels.sh ├── dm.sh ├── rescan-partitions.sh ├── pfn-meta-errors.sh ├── cxl-sanitize.sh ├── sub-section.sh ├── cxl-destroy-region.sh ├── daxdev-errors.sh ├── mmap.sh ├── inject-error.sh └── clear.sh ├── ndctl ├── keys.readme ├── lib │ ├── .gitignore │ ├── libndctl.pc.in │ ├── papr.h │ ├── hyperv.h │ ├── meson.build │ └── msft.h ├── ndctl-monitor.service ├── action.h ├── ndctl.conf ├── json.h ├── bat.c ├── firmware-update.h ├── test.c ├── meson.build ├── keys.h ├── monitor.conf └── libndctl-nfit.h ├── daxctl ├── lib │ ├── daxctl.conf │ ├── libdaxctl.pc.in │ ├── meson.build │ └── libdaxctl.sym ├── 90-daxctl-device.rules ├── daxdev-reconfigure@.service ├── filter.h ├── json.h ├── meson.build ├── builtin.h ├── migrate.c ├── filter.c └── daxctl.example.conf ├── version.h.in ├── clean_config.sh ├── contrib ├── nvdimm-security.conf ├── nfit_test_depmod.conf └── meson.build ├── Documentation ├── cxl │ ├── verbose-option.txt │ ├── bus-option.txt │ ├── debug-option.txt │ ├── decoder-option.txt │ ├── region-description.txt │ ├── human-option.txt │ ├── labels-description.txt │ ├── memdev-option.txt │ ├── xable-no-op.txt │ ├── labels-options.txt │ ├── cxl-zero-labels.txt │ ├── cxl.txt │ ├── cxl-enable-region.txt │ ├── cxl-read-labels.txt │ ├── cxl-destroy-region.txt │ ├── cxl-write-labels.txt │ ├── cxl-wait-sanitize.txt │ ├── lib │ │ ├── cxl_new.txt │ │ └── meson.build │ ├── cxl-enable-memdev.txt │ ├── cxl-disable-bus.txt │ ├── cxl-disable-port.txt │ ├── cxl-disable-region.txt │ ├── cxl-disable-memdev.txt │ ├── cxl-monitor.txt │ ├── cxl-enable-port.txt │ ├── cxl-free-dpa.txt │ ├── cxl-set-partition.txt │ ├── cxl-update-firmware.txt │ └── cxl-reserve-dpa.txt ├── daxctl │ ├── verbose-option.txt │ ├── region-option.txt │ ├── human-option.txt │ ├── movable-options.txt │ ├── daxctl.txt │ ├── daxctl-disable-device.txt │ ├── daxctl-enable-device.txt │ ├── daxctl-destroy-device.txt │ ├── daxctl-offline-memory.txt │ ├── daxctl-migrate-device-model.txt │ ├── daxctl-online-memory.txt │ └── daxctl-list.txt ├── ndctl │ ├── labels-description.txt │ ├── human-option.txt │ ├── xable-dimm-options.txt │ ├── xable-region-options.txt │ ├── xable-bus-options.txt │ ├── region-description.txt │ ├── ars-description.txt │ ├── xable-namespace-options.txt │ ├── ndctl-enable-namespace.txt │ ├── ndctl-disable-namespace.txt │ ├── labels-options.txt │ ├── ndctl-enable-dimm.txt │ ├── ndctl-disable-dimm.txt │ ├── ndctl-enable-region.txt │ ├── ndctl-disable-region.txt │ ├── ndctl-zero-labels.txt │ ├── ndctl-check-labels.txt │ ├── ndctl-write-labels.txt │ ├── dimm-description.txt │ ├── ndctl-wait-overwrite.txt │ ├── ndctl-destroy-namespace.txt │ ├── ndctl-remove-passphrase.txt │ ├── ndctl-read-labels.txt │ ├── ndctl-freeze-security.txt │ ├── ndctl.txt │ ├── ndctl-update-passphrase.txt │ ├── ndctl-start-scrub.txt │ ├── ndctl-load-keys.txt │ ├── ndctl-wait-scrub.txt │ ├── ndctl-setup-passphrase.txt │ ├── ndctl-init-labels.txt │ ├── ndctl-check-namespace.txt │ └── ndctl-sanitize-dimm.txt ├── copyright.txt ├── manpage-normal.xsl ├── asciidoctor-extensions.rb.in └── manpage-base.xsl ├── .gitignore ├── cxl ├── cxl-monitor.service ├── lib │ ├── libcxl.pc.in │ └── meson.build ├── meson.build ├── json.h ├── fwctl │ └── cxl.h └── builtin.h ├── ccan ├── str │ ├── str.c │ ├── str_debug.h │ └── debug.c ├── short_types │ └── short_types.h ├── array_size │ └── array_size.h ├── list │ └── list.c ├── build_assert │ └── build_assert.h ├── minmax │ └── minmax.h └── check_type │ └── check_type.h ├── git-version-gen ├── util ├── iomem.h ├── meson.build ├── fletcher.h ├── abspath.c ├── wrapper.c ├── iomem.c ├── main.h ├── size.c ├── parse-configs.h ├── json.h ├── sysfs.h ├── event_trace.h ├── list.h ├── usage.c └── strbuf.c ├── rpmbuild.sh ├── rhel └── meson.build ├── tools └── meson-vcs-tag.sh ├── COPYING ├── sles ├── header └── meson.build ├── make-git-snapshot.sh ├── LICENSES └── other │ └── MIT ├── git-version ├── scripts ├── docsurgeon_parser_generator.m4 └── do_abidiff ├── meson_options.txt └── test.h /test/dax-ext4.sh: -------------------------------------------------------------------------------- 1 | dax.sh -------------------------------------------------------------------------------- /test/dax-xfs.sh: -------------------------------------------------------------------------------- 1 | dax.sh -------------------------------------------------------------------------------- /ndctl/keys.readme: -------------------------------------------------------------------------------- 1 | See 'ndctl setup-passphrase --help' 2 | -------------------------------------------------------------------------------- /daxctl/lib/daxctl.conf: -------------------------------------------------------------------------------- 1 | blacklist dax_pmem_compat 2 | alias nd:t7* dax_pmem 3 | -------------------------------------------------------------------------------- /test/nmem1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmem/ndctl/HEAD/test/nmem1.bin -------------------------------------------------------------------------------- /test/nmem2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmem/ndctl/HEAD/test/nmem2.bin -------------------------------------------------------------------------------- /test/nmem3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmem/ndctl/HEAD/test/nmem3.bin -------------------------------------------------------------------------------- /test/nmem4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmem/ndctl/HEAD/test/nmem4.bin -------------------------------------------------------------------------------- /version.h.in: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | #define VERSION "@VCS_TAG@" 3 | -------------------------------------------------------------------------------- /clean_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git ls-files -o --exclude build | grep config.h\$ | xargs rm 3 | -------------------------------------------------------------------------------- /ndctl/lib/.gitignore: -------------------------------------------------------------------------------- 1 | .dirstamp 2 | .deps/ 3 | .libs/ 4 | *.la 5 | *.lo 6 | libabc.pc 7 | test-libabc 8 | -------------------------------------------------------------------------------- /contrib/nvdimm-security.conf: -------------------------------------------------------------------------------- 1 | install libnvdimm /usr/bin/ndctl load-keys ; /sbin/modprobe --ignore-install libnvdimm $CMDLINE_OPTS 2 | -------------------------------------------------------------------------------- /Documentation/cxl/verbose-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -v:: 4 | --verbose:: 5 | Emit more debug messages 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | release/ 3 | rhel/ndctl.spec 4 | sles/ndctl.spec 5 | *.swp 6 | tags 7 | cscope.* 8 | scripts/docsurgeon_parser.sh 9 | -------------------------------------------------------------------------------- /Documentation/daxctl/verbose-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -v:: 4 | --verbose:: 5 | Emit more debug messages 6 | -------------------------------------------------------------------------------- /Documentation/cxl/bus-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -b:: 4 | --bus=:: 5 | Restrict the operation to the specified bus. 6 | -------------------------------------------------------------------------------- /Documentation/cxl/debug-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | --debug:: 4 | Turn on additional debug messages including library debug. 5 | -------------------------------------------------------------------------------- /test/cxl-security.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2022 Intel Corporation. All rights reserved. 4 | 5 | $(dirname $0)/security.sh cxl 6 | -------------------------------------------------------------------------------- /test/nfit-security.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2022 Intel Corporation. All rights reserved. 4 | 5 | $(dirname $0)/security.sh nfit 6 | -------------------------------------------------------------------------------- /cxl/cxl-monitor.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=CXL Monitor Daemon 3 | 4 | [Service] 5 | Type=simple 6 | ExecStart=/usr/bin/cxl monitor 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | -------------------------------------------------------------------------------- /ndctl/ndctl-monitor.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Ndctl Monitor Daemon 3 | 4 | [Service] 5 | Type=simple 6 | ExecStart=/usr/bin/ndctl monitor 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | -------------------------------------------------------------------------------- /daxctl/90-daxctl-device.rules: -------------------------------------------------------------------------------- 1 | ACTION=="add", SUBSYSTEM=="dax", TAG+="systemd", \ 2 | PROGRAM="/usr/bin/systemd-escape -p --template=daxdev-reconfigure@.service $env{DEVNAME}", \ 3 | ENV{SYSTEMD_WANTS}="%c" 4 | -------------------------------------------------------------------------------- /Documentation/cxl/decoder-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -d:: 4 | --decoder=:: 5 | The root decoder to limit the operation to. Only regions that are 6 | children of the specified decoder will be acted upon. 7 | -------------------------------------------------------------------------------- /cxl/lib/libcxl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libcxl 7 | Description: Manage CXL devices 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lcxl 10 | Libs.private: 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /daxctl/daxdev-reconfigure@.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Automatic daxctl device reconfiguration 3 | Documentation=man:daxctl-reconfigure-device(1) 4 | 5 | [Service] 6 | Type=forking 7 | GuessMainPID=false 8 | ExecStart=/bin/sh -c "exec daxctl reconfigure-device --check-config %I" 9 | -------------------------------------------------------------------------------- /Documentation/cxl/region-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | A CXL region is composed of one or more slices of CXL memdevs, with configurable 6 | interleave settings - both the number of interleave ways, and the interleave 7 | granularity. 8 | -------------------------------------------------------------------------------- /daxctl/lib/libdaxctl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libdaxctl 7 | Description: Manage "Device DAX" devices 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -ldaxctl 10 | Libs.private: 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /Documentation/ndctl/labels-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | The namespace label area is a small persistent partition of capacity 6 | available on some NVDIMM devices. The label area is used to provision 7 | one, or more, namespaces from regions. 8 | -------------------------------------------------------------------------------- /Documentation/ndctl/human-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -u:: 4 | --human:: 5 | Format numbers representing storage sizes, or offsets as human 6 | readable strings with units instead of the default machine-friendly 7 | raw-integer data. Convert other numeric fields into hexadecimal strings. 8 | -------------------------------------------------------------------------------- /Documentation/ndctl/xable-dimm-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | A 'nmemX' device name, or a dimm id number. Restrict the operation to 3 | the specified dimm(s). The keyword 'all' can be specified to indicate 4 | the lack of any restriction, however this is the same as not supplying 5 | a --dimm option at all. 6 | -------------------------------------------------------------------------------- /ndctl/lib/libndctl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libndctl 7 | Description: Manage "libnvdimm" subsystem devices (Non-volatile Memory) 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lndctl 10 | Libs.private: 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /Documentation/ndctl/xable-region-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | A 'regionX' device name, or a region id number. Restrict the operation to 3 | the specified region(s). The keyword 'all' can be specified to indicate 4 | the lack of any restriction, however this is the same as not supplying a 5 | --region option at all. 6 | -------------------------------------------------------------------------------- /ccan/str/str.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: CC0-1.0 2 | #include 3 | 4 | size_t strcount(const char *haystack, const char *needle) 5 | { 6 | size_t i = 0, nlen = strlen(needle); 7 | 8 | while ((haystack = strstr(haystack, needle)) != NULL) { 9 | i++; 10 | haystack += nlen; 11 | } 12 | return i; 13 | } 14 | -------------------------------------------------------------------------------- /Documentation/ndctl/xable-bus-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | A bus id number, or a provider string (e.g. "ACPI.NFIT"). Restrict the 3 | operation to the specified bus(es). The keyword 'all' can be specified 4 | to indicate the lack of any restriction, however this is the same as 5 | not supplying a --bus option at all. 6 | -------------------------------------------------------------------------------- /Documentation/copyright.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | COPYRIGHT 4 | --------- 5 | Copyright (C) 2016 - 2022, Intel Corporation. License GPLv2: GNU GPL 6 | version 2 . This is free software: 7 | you are free to change and redistribute it. There is NO WARRANTY, to 8 | the extent permitted by law. 9 | -------------------------------------------------------------------------------- /Documentation/cxl/human-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -u:: 4 | --human:: 5 | By default the command will output machine-friendly raw-integer 6 | data. Instead, with this flag, numbers representing storage size 7 | will be formatted as human readable strings with units, other 8 | fields are converted to hexadecimal strings. 9 | -------------------------------------------------------------------------------- /Documentation/daxctl/region-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -r:: 4 | --region=:: 5 | Restrict the operation to devices belonging to the specified region(s). 6 | A device-dax region is a contiguous range of memory that hosts one or 7 | more /dev/daxX.Y devices, where X is the region id and Y is the device 8 | instance id. 9 | -------------------------------------------------------------------------------- /Documentation/cxl/labels-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | The region label area is a small persistent partition of capacity 6 | available on some CXL memory devices. The label area is used to 7 | and configure or determine the set of memory devices participating 8 | in different interleave sets. 9 | -------------------------------------------------------------------------------- /Documentation/daxctl/human-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | -u:: 4 | --human:: 5 | By default the command will output machine-friendly raw-integer 6 | data. Instead, with this flag, numbers representing storage size 7 | will be formatted as human readable strings with units, other 8 | fields are converted to hexadecimal strings. 9 | -------------------------------------------------------------------------------- /ndctl/lib/papr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* (C) Copyright IBM 2020 */ 3 | 4 | #ifndef __PAPR_H__ 5 | #define __PAPR_H__ 6 | 7 | #include 8 | 9 | /* Wraps a nd_cmd generic header with pdsm header */ 10 | struct nd_pkg_papr { 11 | struct nd_cmd_pkg gen; 12 | struct nd_pkg_pdsm pdsm; 13 | }; 14 | 15 | #endif /* __PAPR_H__ */ 16 | -------------------------------------------------------------------------------- /contrib/nfit_test_depmod.conf: -------------------------------------------------------------------------------- 1 | # For nfit_test module overriding - copy to /etc/depmod.d or so 2 | override nfit * extra 3 | override device_dax * extra 4 | override dax_pmem * extra 5 | override dax_pmem_core * extra 6 | override dax_pmem_compat * extra 7 | override libnvdimm * extra 8 | override nd_btt * extra 9 | override nd_e820 * extra 10 | override nd_pmem * extra 11 | -------------------------------------------------------------------------------- /Documentation/ndctl/region-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | A generic REGION device is registered for each PMEM range / 6 | interleave-set. LIBNVDIMM provides a built-in driver for these REGION 7 | devices. This driver is responsible for parsing namespace labels and 8 | instantiating PMEM namespaces for each coherent set of labels. 9 | -------------------------------------------------------------------------------- /git-version-gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | GVF=version.m4 4 | 5 | if test -r $GVF; then 6 | VC=$(sed -e 's/m4_define(\[GIT_VERSION], \[//' <$GVF) 7 | VC=$(echo $VC | sed -e 's/\])//') 8 | else 9 | VC=unset 10 | fi 11 | 12 | VN=$(./git-version) 13 | 14 | test "$VN" = "$VC" || { 15 | echo >&2 "GIT_VERSION = $VN" 16 | echo "m4_define([GIT_VERSION], [$VN])" >$GVF 17 | exit 0 18 | } 19 | -------------------------------------------------------------------------------- /Documentation/cxl/memdev-option.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | A 'memX' device name, or a memdev id number. Restrict the operation to 3 | the specified memdev(s). The keyword 'all' can be specified to indicate 4 | the lack of any restriction. 5 | 6 | -S:: 7 | --serial:: 8 | Rather an a memdev id number, interpret the argument(s) 9 | as a list of serial numbers. 10 | -------------------------------------------------------------------------------- /util/iomem.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2019-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef _NDCTL_IOMEM_H_ 4 | #define _NDCTL_IOMEM_H_ 5 | 6 | struct log_ctx; 7 | unsigned long long __iomem_get_dev_resource(struct log_ctx *ctx, 8 | const char *path); 9 | 10 | #define iomem_get_dev_resource(c, p) __iomem_get_dev_resource(&(c)->ctx, (p)) 11 | 12 | #endif /* _NDCTL_IOMEM_H_ */ 13 | -------------------------------------------------------------------------------- /util/meson.build: -------------------------------------------------------------------------------- 1 | util = static_library('util', [ 2 | 'parse-options.c', 3 | 'parse-configs.c', 4 | 'usage.c', 5 | 'size.c', 6 | 'json.c', 7 | 'log.c', 8 | 'main.c', 9 | 'help.c', 10 | 'strbuf.c', 11 | 'wrapper.c', 12 | 'bitmap.c', 13 | 'abspath.c', 14 | 'iomem.c', 15 | ], 16 | dependencies: iniparser, 17 | include_directories : root_inc, 18 | ) 19 | util_dep = declare_dependency(link_with : util) 20 | -------------------------------------------------------------------------------- /Documentation/ndctl/ars-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | NVDIMM Address Range Scrub is a capability provided by platform firmware 6 | that allows for the discovery of memory errors by system software. It 7 | enables system software to pre-emptively avoid accesses that could lead 8 | to uncorrectable memory error handling events, and it otherwise allows 9 | memory errors to be enumerated. 10 | -------------------------------------------------------------------------------- /Documentation/daxctl/movable-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | --no-movable:: 4 | '--movable' is the default. This can be overridden to online new 5 | memory such that it is not 'movable'. This allows any allocation 6 | to potentially be served from this memory. This may preclude subsequent 7 | removal. With the '--movable' behavior (which is default), kernel 8 | allocations will not consider this memory, and it will be reserved 9 | for application use. 10 | -------------------------------------------------------------------------------- /Documentation/cxl/xable-no-op.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: gpl-2.0 2 | 3 | Given any enable or disable command, if the operation is a no-op due to the 4 | current state of a target (i.e. already enabled or disabled), it is still 5 | considered successful when executed even if no actual operation is performed. 6 | The target can be a bus, decoder, memdev, or region. The operation will still 7 | succeed, and report the number of bus/decoder/memdev/region operated on, even 8 | if the operation is a no-op. 9 | -------------------------------------------------------------------------------- /ndctl/action.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef __NDCTL_ACTION_H__ 4 | #define __NDCTL_ACTION_H__ 5 | enum device_action { 6 | ACTION_ENABLE, 7 | ACTION_DISABLE, 8 | ACTION_CREATE, 9 | ACTION_DESTROY, 10 | ACTION_CHECK, 11 | ACTION_WAIT, 12 | ACTION_START, 13 | ACTION_CLEAR, 14 | ACTION_ACTIVATE, 15 | ACTION_READ_INFOBLOCK, 16 | ACTION_WRITE_INFOBLOCK, 17 | }; 18 | #endif /* __NDCTL_ACTION_H__ */ 19 | -------------------------------------------------------------------------------- /daxctl/filter.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef _DAXCTL_UTIL_FILTER_H_ 4 | #define _DAXCTL_UTIL_FILTER_H_ 5 | #include 6 | #include 7 | 8 | struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, 9 | const char *ident); 10 | struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region, 11 | const char *ident); 12 | #endif /* _DAXCTL_UTIL_FILTER_H_ */ 13 | -------------------------------------------------------------------------------- /Documentation/cxl/labels-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | :: 4 | include::memdev-option.txt[] 5 | 6 | -s:: 7 | --size=:: 8 | Limit the operation to the given number of bytes. A size of 0 9 | indicates to operate over the entire label capacity. 10 | 11 | -O:: 12 | --offset=:: 13 | Begin the operation at the given offset into the label area. 14 | 15 | -v:: 16 | Turn on verbose debug messages in the library (if libcxl was built with 17 | logging and debug enabled). 18 | -------------------------------------------------------------------------------- /Documentation/ndctl/xable-namespace-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | :: 4 | A 'namespaceX.Y' device name. The keyword 'all' can be specified to carry out 5 | the operation on every namespace in the system, optionally filtered by region 6 | (see --region=option) 7 | 8 | -r:: 9 | --region=:: 10 | include::xable-region-options.txt[] 11 | 12 | -b:: 13 | --bus=:: 14 | include::xable-bus-options.txt[] 15 | 16 | -v:: 17 | --verbose:: 18 | Emit debug messages for the namespace operation 19 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-enable-namespace.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-enable-namespace(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | ndctl-enable-namespace - enable the given namespace(s) 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl enable-namespace' [] 14 | 15 | include::namespace-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | include::xable-namespace-options.txt[] 20 | 21 | include::../copyright.txt[] 22 | 23 | SEE ALSO 24 | -------- 25 | linkndctl:ndctl-disable-namespace[1] 26 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-disable-namespace.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-disable-namespace(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | ndctl-disable-namespace - disable the given namespace(s) 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl disable-namespace' [] 14 | 15 | include::namespace-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | include::xable-namespace-options.txt[] 20 | 21 | include::../copyright.txt[] 22 | 23 | SEE ALSO 24 | -------- 25 | linkndctl:ndctl-enable-namespace[1] 26 | -------------------------------------------------------------------------------- /rpmbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | spec=${1:-$(dirname $0)/rhel/ndctl.spec)} 4 | 5 | pushd $(dirname $0) >/dev/null 6 | [ ! -d ~/rpmbuild/SOURCES ] && echo "rpmdev tree not found" && exit 1 7 | if ./git-version | grep -q dirty; then 8 | echo "Uncommitted changes detected, commit or undo them to proceed" 9 | git status -uno --short 10 | exit 1 11 | fi 12 | if [ ! -f $spec ]; then 13 | meson compile -C build rhel/ndctl.spec || exit 14 | spec=$(dirname $0)/build/rhel/ndctl.spec 15 | fi 16 | ./make-git-snapshot.sh 17 | popd > /dev/null 18 | rpmbuild --nocheck -ba $spec 19 | -------------------------------------------------------------------------------- /Documentation/ndctl/labels-options.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | :: 4 | include::xable-dimm-options.txt[] 5 | 6 | -s:: 7 | --size=:: 8 | Limit the operation to the given number of bytes. A size of 0 9 | indicates to operate over the entire label capacity. 10 | 11 | -O:: 12 | --offset=:: 13 | Begin the operation at the given offset into the label area. 14 | 15 | -b:: 16 | --bus=:: 17 | include::xable-bus-options.txt[] 18 | 19 | -v:: 20 | Turn on verbose debug messages in the library (if ndctl was built with 21 | logging and debug enabled). 22 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-enable-dimm.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-enable-dimm(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-enable-dimm - enable one more dimms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl enable-dimm' [] 14 | 15 | include::dimm-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | :: 20 | include::xable-dimm-options.txt[] 21 | 22 | -b:: 23 | --bus=:: 24 | include::xable-bus-options.txt[] 25 | 26 | include::../copyright.txt[] 27 | 28 | SEE ALSO 29 | -------- 30 | linkndctl:ndctl-disable-dimm[1] 31 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-disable-dimm.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-disable-dimm(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | ndctl-disable-dimm - disable one or more idle dimms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl disable-dimm' [] 14 | 15 | include::dimm-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | :: 20 | include::xable-dimm-options.txt[] 21 | 22 | -b:: 23 | --bus=:: 24 | include::xable-bus-options.txt[] 25 | 26 | include::../copyright.txt[] 27 | 28 | SEE ALSO 29 | -------- 30 | linkndctl:ndctl-enable-dimm[1] 31 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-enable-region.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-enable-region(1) 4 | ====================== 5 | 6 | NAME 7 | ---- 8 | ndctl-enable-region - enable the given region(s) and all descendant namespaces 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl enable-region' [] 14 | 15 | include::region-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | :: 20 | include::xable-region-options.txt[] 21 | 22 | -b:: 23 | --bus=:: 24 | include::xable-bus-options.txt[] 25 | 26 | include::../copyright.txt[] 27 | 28 | SEE ALSO 29 | -------- 30 | linkndctl:ndctl-disable-region[1] 31 | -------------------------------------------------------------------------------- /rhel/meson.build: -------------------------------------------------------------------------------- 1 | rhel_spec1 = vcs_tag( 2 | input : '../ndctl.spec.in', 3 | output : 'ndctl.spec.in', 4 | command: vcs_tagger, 5 | replace_string : 'VERSION', 6 | ) 7 | 8 | rhel_spec2 = custom_target('ndctl.spec', 9 | command : [ 10 | 'sed', '-e', 's,DAX_DNAME,daxctl-devel,g', 11 | '-e', 's,CXL_DNAME,cxl-devel,g', 12 | '-e', 's,DNAME,ndctl-devel,g', 13 | '-e', '/^%defattr.*/d', 14 | '-e', 's,DAX_LNAME,daxctl-libs,g', 15 | '-e', 's,CXL_LNAME,cxl-libs,g', 16 | '-e', 's,LNAME,ndctl-libs,g', 17 | '@INPUT@' 18 | ], 19 | input : rhel_spec1, 20 | output : 'ndctl.spec', 21 | capture : true, 22 | ) 23 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-disable-region.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-disable-region(1) 4 | ======================= 5 | 6 | NAME 7 | ---- 8 | ndctl-disable-region - disable the given region(s) and all descendant namespaces 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl disable-region' [] 14 | 15 | include::region-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | :: 20 | include::xable-region-options.txt[] 21 | 22 | -b:: 23 | --bus=:: 24 | include::xable-bus-options.txt[] 25 | 26 | include::../copyright.txt[] 27 | 28 | SEE ALSO 29 | -------- 30 | linkndctl:ndctl-enable-region[1] 31 | -------------------------------------------------------------------------------- /util/fletcher.h: -------------------------------------------------------------------------------- 1 | #ifndef _NDCTL_FLETCHER_H_ 2 | #define _NDCTL_FLETCHER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | * Note, fletcher64() is copied from drivers/nvdimm/label.c in the Linux kernel 10 | */ 11 | static inline u64 fletcher64(void *addr, size_t len, bool le) 12 | { 13 | u32 *buf = addr; 14 | u32 lo32 = 0; 15 | u64 hi32 = 0; 16 | size_t i; 17 | 18 | for (i = 0; i < len / sizeof(u32); i++) { 19 | lo32 += le ? le32_to_cpu((le32) buf[i]) : buf[i]; 20 | hi32 += lo32; 21 | } 22 | 23 | return hi32 << 32 | lo32; 24 | } 25 | 26 | #endif /* _NDCTL_FLETCHER_H_ */ 27 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-zero-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-zero-labels(1) 4 | ================== 5 | 6 | NAME 7 | ---- 8 | cxl-zero-labels - zero out the label area on a set of memdevs 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl zero-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | This command resets the device to its default state by 17 | deleting all labels. 18 | 19 | OPTIONS 20 | ------- 21 | include::labels-options.txt[] 22 | 23 | include::../copyright.txt[] 24 | 25 | SEE ALSO 26 | -------- 27 | linkcxl:cxl-read-labels[1], 28 | linkcxl:cxl-write-labels[1], 29 | CXL-2.0 9.13.2 30 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl(1) 4 | ====== 5 | 6 | NAME 7 | ---- 8 | cxl - Provides enumeration and provisioning commands for CXL platforms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl' [--version] [--help] COMMAND [ARGS] 14 | 15 | OPTIONS 16 | ------- 17 | -v:: 18 | --version:: 19 | Display the version of the 'cxl' utility. 20 | 21 | -h:: 22 | --help:: 23 | Run the 'cxl help' command. 24 | 25 | DESCRIPTION 26 | ----------- 27 | The cxl utility provides enumeration and provisioning commands for 28 | the CXL devices managed by the Linux kernel. 29 | 30 | include::../copyright.txt[] 31 | 32 | SEE ALSO 33 | -------- 34 | linkcxl:ndctl[1] 35 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-zero-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-zero-labels(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-zero-labels - zero out the label area on a dimm or set of dimms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl zero-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | This command resets the device to its default state by 17 | deleting all labels. 18 | 19 | OPTIONS 20 | ------- 21 | include::labels-options.txt[] 22 | 23 | include::../copyright.txt[] 24 | 25 | SEE ALSO 26 | -------- 27 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 28 | -------------------------------------------------------------------------------- /tools/meson-vcs-tag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: LGPL-2.1-or-later 3 | 4 | set -eu 5 | set -o pipefail 6 | 7 | dir="${1:?}" 8 | fallback="${2:?}" 9 | 10 | # Apparently git describe has a bug where it always considers the work-tree 11 | # dirty when invoked with --git-dir (even though 'git status' is happy). Work 12 | # around this issue by cd-ing to the source directory. 13 | cd "$dir" 14 | # Check that we have either .git/ (a normal clone) or a .git file (a work-tree) 15 | # and that we don't get confused if a tarball is extracted in a higher-level 16 | # git repository. 17 | [ -e .git ] && git describe --abbrev=7 --dirty=+ 2>/dev/null | \ 18 | sed -e 's/^v//' -e 's/-/./g' || echo "$fallback" 19 | -------------------------------------------------------------------------------- /util/abspath.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | /* originally copied from git/abspath.c */ 4 | 5 | #include 6 | #include 7 | 8 | char *prefix_filename(const char *pfx, const char *arg) 9 | { 10 | struct strbuf path = STRBUF_INIT; 11 | size_t pfx_len = pfx ? strlen(pfx) : 0; 12 | 13 | if (pfx_len && !is_absolute_path(arg)) 14 | strbuf_add(&path, pfx, pfx_len); 15 | 16 | strbuf_addstr(&path, arg); 17 | return strbuf_detach(&path, NULL); 18 | } 19 | 20 | void fix_filename(const char *prefix, const char **file) 21 | { 22 | if (!file || !*file || !prefix || is_absolute_path(*file) 23 | || !strcmp("-", *file)) 24 | return; 25 | *file = prefix_filename(prefix, *file); 26 | } 27 | -------------------------------------------------------------------------------- /test/hugetlb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static int test_hugetlb(void) 9 | { 10 | int rc, i; 11 | unsigned long aligns[] = { SZ_4K, SZ_2M, SZ_1G }; 12 | 13 | for (i = 0; i < (int) ARRAY_SIZE(aligns); i++) { 14 | fprintf(stderr, "%s: page_size: %#lx\n", __func__, aligns[i]); 15 | rc = test_dax_directio(-1, aligns[i], NULL, 0); 16 | if (rc == -ENOENT && aligns[i] == SZ_1G) 17 | continue; /* system not configured for 1G pages */ 18 | else if (rc) 19 | return 77; 20 | } 21 | return 0; 22 | } 23 | 24 | int __attribute__((weak)) main(int argc, char *argv[]) 25 | { 26 | return test_hugetlb(); 27 | } 28 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The ndctl project provides tools under: 2 | 3 | SPDX-License-Identifier: GPL-2.0 4 | 5 | Being under the terms of the GNU General Public License version 2 only, 6 | according with: 7 | 8 | LICENSES/preferred/GPL-2.0 9 | 10 | The ndctl project provides libraries under: 11 | 12 | SPDX-License-Identifier: LGPL-2.1 13 | 14 | Being under the terms of the GNU Lesser General Public License version 15 | 2.1 only, according with: 16 | 17 | LICENSES/preferred/LGPL-2.1 18 | 19 | The project incorporates helper routines from the CCAN project under 20 | CC0-1.0 and MIT licenses according with: 21 | 22 | LICENSES/other/CC0-1.0 23 | LICENSES/other/MIT 24 | 25 | All contributions to the ndctl project are subject to this COPYING file. 26 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-enable-region.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-enable-region(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | cxl-enable-region - enable specified region(s). 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl enable-region []' 14 | 15 | include::region-description.txt[] 16 | 17 | EXAMPLE 18 | ------- 19 | ---- 20 | # cxl enable-region all 21 | enabled 2 regions 22 | ---- 23 | 24 | include::xable-no-op.txt[] 25 | 26 | OPTIONS 27 | ------- 28 | include::bus-option.txt[] 29 | 30 | include::decoder-option.txt[] 31 | 32 | include::debug-option.txt[] 33 | 34 | include::../copyright.txt[] 35 | 36 | SEE ALSO 37 | -------- 38 | linkcxl:cxl-list[1], linkcxl:cxl-disable-region[1] 39 | -------------------------------------------------------------------------------- /ndctl/ndctl.conf: -------------------------------------------------------------------------------- 1 | # This is the default ndctl configuration file. It contains the 2 | # configuration directives that give ndctl instructions. 3 | # Ndctl supports multiple configuration files. All files with the 4 | # .conf suffix under {sysconfdir}/ndctl.conf.d will be regarded as 5 | # valid ndctl configuration files. 6 | 7 | # In this file, lines starting with a hash (#) are comments. 8 | # The configurations should be in a [section] and follow = 9 | # style. Multiple space-separated values are allowed, but except the 10 | # following characters: : ? / \ % " ' $ & ! * { } [ ] ( ) = < > @ 11 | 12 | [core] 13 | # The values in [core] section work for all ndctl sub commands. 14 | # dimm = all 15 | # bus = all 16 | # region = all 17 | # namespace = all 18 | -------------------------------------------------------------------------------- /test/cxl-features.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2025 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname "$0")/common 6 | 7 | FEATURES="$TEST_PATH"/fwctl 8 | rc=77 9 | # 237 is -ENODEV 10 | ERR_NODEV=237 11 | 12 | trap 'err $LINENO' ERR 13 | 14 | modprobe -r cxl_test 15 | modprobe cxl_test 16 | 17 | main() 18 | { 19 | test -x "$FEATURES" || do_skip "no CXL Features Control" 20 | 21 | rc=0 22 | "$FEATURES" || rc=$? 23 | 24 | echo "status: $rc" 25 | if [ "$rc" -eq "$ERR_NODEV" ]; then 26 | do_skip "no CXL FWCTL char dev" 27 | elif [ "$rc" -ne 0 ]; then 28 | echo "fail: $LINENO" && exit 1 29 | fi 30 | 31 | _cxl_cleanup 32 | } 33 | 34 | { 35 | main "$@"; exit "$?" 36 | } 37 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-check-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-check-labels(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-check-labels - determine if the given dimms have a valid namespace index block 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl check-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | In addition to checking if a label area has a valid index block, running 17 | this command in verbose mode reports the reason the index block is 18 | deemed invalid. 19 | 20 | OPTIONS 21 | ------- 22 | include::labels-options.txt[] 23 | 24 | include::../copyright.txt[] 25 | 26 | SEE ALSO 27 | -------- 28 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 29 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-read-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-read-labels(1) 4 | ================== 5 | 6 | NAME 7 | ---- 8 | cxl-read-labels - read out the label area on a CXL memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl read-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | This command dumps the raw binary data in a memdev's label area to stdout or a 17 | file. In the multi-memdev case the data is concatenated. 18 | 19 | OPTIONS 20 | ------- 21 | include::labels-options.txt[] 22 | 23 | include::bus-option.txt[] 24 | 25 | -o:: 26 | --output:: 27 | output file 28 | 29 | include::../copyright.txt[] 30 | 31 | SEE ALSO 32 | -------- 33 | linkcxl:cxl-write-labels[1], 34 | linkcxl:cxl-zero-labels[1], 35 | CXL-2.0 9.13.2 36 | -------------------------------------------------------------------------------- /daxctl/json.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef __DAXCTL_JSON_H__ 4 | #define __DAXCTL_JSON_H__ 5 | #include 6 | 7 | struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping, 8 | unsigned long flags); 9 | struct daxctl_region; 10 | struct daxctl_dev; 11 | struct json_object *util_daxctl_region_to_json(struct daxctl_region *region, 12 | const char *ident, unsigned long flags); 13 | struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, 14 | unsigned long flags); 15 | struct json_object *util_daxctl_devs_to_list(struct daxctl_region *region, 16 | struct json_object *jdevs, const char *ident, 17 | unsigned long flags); 18 | #endif /* __CXL_UTIL_JSON_H__ */ 19 | -------------------------------------------------------------------------------- /daxctl/meson.build: -------------------------------------------------------------------------------- 1 | daxctl_src = [ 2 | 'daxctl.c', 3 | 'acpi.c', 4 | 'list.c', 5 | 'migrate.c', 6 | 'device.c', 7 | 'json.c', 8 | 'filter.c', 9 | ] 10 | 11 | daxctl_tool = executable('daxctl', 12 | daxctl_src, 13 | include_directories : root_inc, 14 | dependencies : [ 15 | daxctl_dep, 16 | ndctl_dep, 17 | util_dep, 18 | uuid, 19 | kmod, 20 | json, 21 | versiondep, 22 | ], 23 | install : true, 24 | install_dir : rootbindir, 25 | ) 26 | 27 | install_headers('libdaxctl.h', subdir : 'daxctl') 28 | 29 | install_data('daxctl.example.conf', install_dir : daxctlconf_dir ) 30 | if get_option('systemd').enabled() 31 | install_data('90-daxctl-device.rules', install_dir : udevrulesdir) 32 | install_data('daxdev-reconfigure@.service', install_dir : systemdunitdir) 33 | endif 34 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-write-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-write-labels(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | ndctl-write-labels - write data to the label area on a dimm 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl write-labels [-i ]' 14 | 15 | include::labels-description.txt[] 16 | Read data from the input filename, or stdin, and write it to the given 17 | device. Note that the device must not be active in any region, 18 | otherwise the kernel will not allow write access to the device's label 19 | data area. 20 | 21 | OPTIONS 22 | ------- 23 | include::labels-options.txt[] 24 | -i:: 25 | --input:: 26 | input file 27 | 28 | SEE ALSO 29 | -------- 30 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 31 | -------------------------------------------------------------------------------- /sles/header: -------------------------------------------------------------------------------- 1 | # 2 | # spec file for package ndctl 3 | # 4 | # Copyright (C) 2015 SUSE LINUX GmbH, Nuernberg, Germany. 5 | # Copyright (C) 2015-2020 Intel Corporation 6 | # 7 | # All modifications and additions to the file contributed by third parties 8 | # remain the property of their copyright owners, unless otherwise agreed 9 | # upon. The license for this file, and modifications and additions to the 10 | # file, is the same license as for the pristine package itself (unless the 11 | # license for the pristine package is not an Open Source License, in which 12 | # case the license is the MIT License). An "Open Source License" is a 13 | # license that conforms to the Open Source Definition (Version 1.9) 14 | # published by the Open Source Initiative. 15 | 16 | # Please submit bugfixes or comments via http://bugs.opensuse.org/ 17 | # 18 | 19 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-destroy-region.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-destroy-region(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | cxl-destroy-region - destroy specified region(s). 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl destroy-region []' 14 | 15 | include::region-description.txt[] 16 | 17 | EXAMPLE 18 | ------- 19 | ---- 20 | # cxl destroy-region all 21 | destroyed 2 regions 22 | ---- 23 | 24 | OPTIONS 25 | ------- 26 | include::bus-option.txt[] 27 | 28 | -f:: 29 | --force:: 30 | Force a destroy operation even if the region is active. 31 | This will attempt to disable the region first. 32 | 33 | include::decoder-option.txt[] 34 | 35 | include::debug-option.txt[] 36 | 37 | include::../copyright.txt[] 38 | 39 | SEE ALSO 40 | -------- 41 | linkcxl:cxl-list[1], linkcxl:cxl-create-region[1] 42 | -------------------------------------------------------------------------------- /Documentation/manpage-normal.xsl: -------------------------------------------------------------------------------- 1 | 9 | 12 | 14 | 15 | 16 | 17 | 18 | \ 19 | . 20 | 21 | 22 | -------------------------------------------------------------------------------- /make-git-snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | NAME=ndctl 5 | 6 | if [ ! -x ./git-version ]; then 7 | echo "$0 : ERROR: Must run from top level of git tree" 8 | exit 1 9 | fi 10 | 11 | REFDIR=$PWD 12 | 13 | UPSTREAM=$REFDIR #TODO update once we have a public upstream 14 | OUTDIR=$HOME/rpmbuild/SOURCES 15 | 16 | if [ ! -d $OUTDIR ]; then 17 | mkdir -p $OUTDIR 18 | fi 19 | 20 | [ -n "$1" ] && HEAD="$1" || HEAD="HEAD" 21 | 22 | WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")" 23 | trap 'rm -rf $WORKDIR' exit 24 | 25 | [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR" 26 | git clone $REFERENCE "$UPSTREAM" "$WORKDIR" 27 | 28 | VERSION=$(./git-version) 29 | DIRNAME="ndctl-${VERSION}" 30 | git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz" 31 | 32 | echo "Written $OUTDIR/ndctl-${VERSION}.tar.gz" 33 | -------------------------------------------------------------------------------- /util/wrapper.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2005 Junio C Hamano. All rights reserved. 3 | // Copyright (C) 2005 Linus Torvalds. All rights reserved. 4 | 5 | /* originally copied from perf and git */ 6 | 7 | /* 8 | * Various trivial helper wrappers around standard functions 9 | */ 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | char *xstrdup(const char *str) 16 | { 17 | char *ret = strdup(str); 18 | if (!ret) { 19 | ret = strdup(str); 20 | if (!ret) 21 | die("Out of memory, strdup failed"); 22 | } 23 | return ret; 24 | } 25 | 26 | void *xrealloc(void *ptr, size_t size) 27 | { 28 | void *ret; 29 | 30 | if (!size) { 31 | free(ptr); 32 | return malloc(1); 33 | } 34 | 35 | ret = realloc(ptr, size); 36 | if (!ret) 37 | die("Out of memory, realloc failed"); 38 | return ret; 39 | } 40 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl(1) 4 | ========= 5 | 6 | NAME 7 | ---- 8 | daxctl - Provides enumeration and provisioning commands for the Linux kernel Device-DAX facility 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl' [--version] [--help] COMMAND [ARGS] 14 | 15 | OPTIONS 16 | ------- 17 | -v:: 18 | --version:: 19 | Display daxctl version. 20 | 21 | -h:: 22 | --help:: 23 | Run daxctl help command. 24 | 25 | DESCRIPTION 26 | ----------- 27 | The daxctl utility provides enumeration and provisioning commands for 28 | the Linux kernel Device-DAX facility. This facility enables DAX mappings 29 | of performance / feature differentiated memory without need of a 30 | filesystem. 31 | 32 | include::../copyright.txt[] 33 | 34 | SEE ALSO 35 | -------- 36 | linkdaxctl:ndctl-create-namespace[1], 37 | linkdaxctl:ndctl-list[1] 38 | -------------------------------------------------------------------------------- /ccan/str/str_debug.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_STR_DEBUG_H 3 | #define CCAN_STR_DEBUG_H 4 | 5 | /* #define CCAN_STR_DEBUG 1 */ 6 | 7 | #ifdef CCAN_STR_DEBUG 8 | /* Because we mug the real ones with macros, we need our own wrappers. */ 9 | int str_isalnum(int i); 10 | int str_isalpha(int i); 11 | int str_isascii(int i); 12 | #if HAVE_ISBLANK 13 | int str_isblank(int i); 14 | #endif 15 | int str_iscntrl(int i); 16 | int str_isdigit(int i); 17 | int str_isgraph(int i); 18 | int str_islower(int i); 19 | int str_isprint(int i); 20 | int str_ispunct(int i); 21 | int str_isspace(int i); 22 | int str_isupper(int i); 23 | int str_isxdigit(int i); 24 | 25 | char *str_strstr(const char *haystack, const char *needle); 26 | char *str_strchr(const char *s, int c); 27 | char *str_strrchr(const char *s, int c); 28 | #endif /* CCAN_STR_DEBUG */ 29 | 30 | #endif /* CCAN_STR_DEBUG_H */ 31 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-write-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-write-labels(1) 4 | =================== 5 | 6 | NAME 7 | ---- 8 | cxl-write-labels - write data to the label area on a memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl write-labels [-i ]' 14 | 15 | include::labels-description.txt[] 16 | Read data from the input filename, or stdin, and write it to the given 17 | device. Note that the device must not be active in any region, or 18 | actively registered with the nvdimm subsystem. If it is, the kernel will 19 | not allow write access to the device's label data area. 20 | 21 | OPTIONS 22 | ------- 23 | include::labels-options.txt[] 24 | 25 | include::bus-option.txt[] 26 | 27 | -i:: 28 | --input:: 29 | input file 30 | 31 | SEE ALSO 32 | -------- 33 | linkcxl:cxl-read-labels[1], 34 | linkcxl:cxl-zero-labels[1], 35 | CXL-2.0 9.13.2 36 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-wait-sanitize.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-wait-sanitize(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | cxl-wait-sanitize - wait for a sanitize operation to complete 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl wait-sanitize [..] []' 14 | 15 | DESCRIPTION 16 | ----------- 17 | 18 | A sanitize operation can take several seconds to complete. Block and wait for 19 | the sanitize operation to complete. 20 | 21 | EXAMPLE 22 | ------- 23 | ---- 24 | # cxl wait-sanitize mem0 25 | sanitize completed on 1 mem device 26 | ---- 27 | 28 | OPTIONS 29 | ------- 30 | 31 | include::bus-option.txt[] 32 | 33 | -t:: 34 | --timeout:: 35 | Milliseconds to wait before timing out and returning. Defaults 36 | to infinite. 37 | 38 | include::verbose-option.txt[] 39 | 40 | include::../copyright.txt[] 41 | 42 | SEE ALSO 43 | -------- 44 | linkcxl:cxl-list[1], 45 | -------------------------------------------------------------------------------- /test/sector-mode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | rc=77 6 | 7 | . $(dirname $0)/common 8 | 9 | check_prereq "jq" 10 | 11 | set -e 12 | trap 'err $LINENO' ERR 13 | 14 | ALIGN_SIZE=`getconf PAGESIZE` 15 | 16 | # setup (reset nfit_test dimms) 17 | modprobe nfit_test 18 | reset 19 | reset1 20 | 21 | rc=1 22 | query=". | sort_by(.available_size) | reverse | .[0].dev" 23 | REGION=$($NDCTL list -R -b $NFIT_TEST_BUS1 | jq -r "$query") 24 | echo 0 > /sys/bus/nd/devices/$REGION/read_only 25 | echo $ALIGN_SIZE > /sys/bus/nd/devices/$REGION/align 26 | NAMESPACE=$($NDCTL create-namespace --no-autolabel -r $REGION -m sector -f -l 4K | jq -r ".dev") 27 | $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a $ALIGN_SIZE 28 | $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K 29 | 30 | _cleanup 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-disable-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-disable-device(1) 4 | ======================== 5 | 6 | NAME 7 | ---- 8 | daxctl-disable-device - Disables a devdax device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl disable-device' [] 14 | 15 | EXAMPLES 16 | -------- 17 | 18 | * Disables dax0.1 19 | ---- 20 | # daxctl disable-device dax0.1 21 | ---- 22 | 23 | * Disables all devices in region id 0 24 | ---- 25 | # daxctl disable-device -r 0 all 26 | disabled 3 devices 27 | ---- 28 | 29 | DESCRIPTION 30 | ----------- 31 | 32 | Disables a dax device in 'devdax' mode. 33 | 34 | OPTIONS 35 | ------- 36 | include::region-option.txt[] 37 | 38 | include::human-option.txt[] 39 | 40 | include::verbose-option.txt[] 41 | 42 | include::../copyright.txt[] 43 | 44 | SEE ALSO 45 | -------- 46 | linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] 47 | -------------------------------------------------------------------------------- /Documentation/ndctl/dimm-description.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | DESCRIPTION 4 | ----------- 5 | A generic DIMM device object, named /dev/nmemX, is registered for each 6 | memory device indicated in the ACPI NFIT table, or other platform NVDIMM 7 | resource discovery mechanism. The LIBNVDIMM core provides a built-in 8 | driver for these DIMM devices. The driver is responsible for 9 | determining if the DIMM implements a namespace label area, and 10 | initializing the kernel's in-memory copy of that label data. 11 | 12 | The kernel performs runtime modifications of that data when namespace 13 | provisioning actions are taken, and actively blocks userspace from 14 | initiating label data changes while the DIMM is active in any region. 15 | Disabling a DIMM, after all the regions it is a member of have been 16 | disabled, allows userspace to manually update the label data to be 17 | consumed when the DIMM is next enabled. 18 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-wait-overwrite.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-wait-overwrite(1) 4 | ======================= 5 | 6 | NAME 7 | ---- 8 | ndctl-wait-overwrite - wait for an overwrite operation to complete 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl wait-overwrite' [..] [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | The kernel provides a POLL(2) capable sysfs file ('security') to indicate 18 | the state of overwrite. This command waits for a change in the state of 19 | this file across all specified dimms. 20 | 21 | OPTIONS 22 | ------- 23 | :: 24 | include::xable-dimm-options.txt[] 25 | 26 | -b:: 27 | --bus=:: 28 | include::xable-bus-options.txt[] 29 | 30 | -v:: 31 | --verbose:: 32 | Emit debug messages. 33 | 34 | include::intel-nvdimm-security.txt[] 35 | 36 | include::../copyright.txt[] 37 | 38 | SEE ALSO 39 | -------- 40 | linkndctl:ndctl-sanitize-dimm[1] 41 | -------------------------------------------------------------------------------- /ccan/short_types/short_types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_SHORT_TYPES_H 3 | #define CCAN_SHORT_TYPES_H 4 | #include 5 | 6 | /** 7 | * u64/s64/u32/s32/u16/s16/u8/s8 - short names for explicitly-sized types. 8 | */ 9 | typedef uint64_t u64; 10 | typedef int64_t s64; 11 | typedef uint32_t u32; 12 | typedef int32_t s32; 13 | typedef uint16_t u16; 14 | typedef int16_t s16; 15 | typedef uint8_t u8; 16 | typedef int8_t s8; 17 | 18 | /* Whichever they include first, they get these definitions. */ 19 | #ifdef CCAN_ENDIAN_H 20 | /** 21 | * be64/be32/be16 - 64/32/16 bit big-endian representation. 22 | */ 23 | typedef beint64_t be64; 24 | typedef beint32_t be32; 25 | typedef beint16_t be16; 26 | 27 | /** 28 | * le64/le32/le16 - 64/32/16 bit little-endian representation. 29 | */ 30 | typedef leint64_t le64; 31 | typedef leint32_t le32; 32 | typedef leint16_t le16; 33 | #endif 34 | 35 | #endif /* CCAN_SHORT_TYPES_H */ 36 | -------------------------------------------------------------------------------- /cxl/meson.build: -------------------------------------------------------------------------------- 1 | cxl_src = [ 2 | 'cxl.c', 3 | 'list.c', 4 | 'port.c', 5 | 'bus.c', 6 | 'region.c', 7 | 'memdev.c', 8 | 'json.c', 9 | 'filter.c', 10 | '../daxctl/json.c', 11 | '../daxctl/filter.c', 12 | ] 13 | 14 | if get_option('systemd').enabled() 15 | install_data('cxl-monitor.service', install_dir : systemdunitdir) 16 | endif 17 | 18 | deps = [ 19 | cxl_dep, 20 | daxctl_dep, 21 | util_dep, 22 | uuid, 23 | kmod, 24 | json, 25 | versiondep, 26 | ] 27 | 28 | if get_option('libtracefs').enabled() 29 | cxl_src += [ 30 | '../util/event_trace.c', 31 | 'monitor.c', 32 | 'json_poison.c', 33 | ] 34 | deps += [ 35 | traceevent, 36 | tracefs, 37 | ] 38 | endif 39 | 40 | cxl_tool = executable('cxl', 41 | cxl_src, 42 | include_directories : root_inc, 43 | dependencies : deps, 44 | install : true, 45 | install_dir : rootbindir, 46 | ) 47 | 48 | install_headers('libcxl.h', subdir : 'cxl') 49 | -------------------------------------------------------------------------------- /Documentation/cxl/lib/cxl_new.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.0 2 | 3 | cxl_new(3) 4 | ========== 5 | 6 | NAME 7 | ---- 8 | cxl_new - Create a new library context object that acts as a handle for all 9 | library operations 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | ---- 15 | #include 16 | 17 | int cxl_new(struct cxl_ctx **ctx); 18 | ---- 19 | 20 | DESCRIPTION 21 | ----------- 22 | Instantiates a new library context, and stores an opaque pointer in ctx. The 23 | context is freed by linklibcxl:cxl_unref[3], i.e. cxl_new(3) implies an 24 | internal linklibcxl:cxl_ref[3]. 25 | 26 | 27 | RETURN VALUE 28 | ------------ 29 | Returns 0 on success, and a negative errno on failure. 30 | Possible error codes are: 31 | 32 | * -ENOMEM 33 | * -ENXIO 34 | 35 | EXAMPLE 36 | ------- 37 | See example usage in test/libcxl.c 38 | 39 | include::../../copyright.txt[] 40 | 41 | SEE ALSO 42 | -------- 43 | linklibcxl:cxl_ref[3], linklibcxl:cxl_unref[3] 44 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-enable-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-enable-device(1) 4 | ======================= 5 | 6 | NAME 7 | ---- 8 | daxctl-enable-device - Enable a devdax device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl enable-device' [...] [] 14 | 15 | EXAMPLES 16 | -------- 17 | 18 | * Enables dax0.1 19 | ---- 20 | # daxctl enable-device dax0.1 21 | enabled 1 device 22 | ---- 23 | 24 | * Enables all devices in region id 0 25 | ---- 26 | # daxctl enable-device -r 0 all 27 | enabled 3 devices 28 | ---- 29 | 30 | DESCRIPTION 31 | ----------- 32 | 33 | Enables a dax device in 'devdax' mode. 34 | 35 | OPTIONS 36 | ------- 37 | include::region-option.txt[] 38 | 39 | include::human-option.txt[] 40 | 41 | include::verbose-option.txt[] 42 | 43 | include::../copyright.txt[] 44 | 45 | SEE ALSO 46 | -------- 47 | linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] 48 | -------------------------------------------------------------------------------- /test/max_available_extent_ns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2018, FUJITSU LIMITED. All rights reserved. 4 | 5 | rc=77 6 | 7 | . $(dirname $0)/common 8 | 9 | trap 'err $LINENO' ERR 10 | 11 | check_min_kver "4.19" || do_skip "kernel $KVER may not support max_available_size" 12 | check_prereq "jq" 13 | 14 | do_test() 15 | { 16 | region=$($NDCTL list -b $NFIT_TEST_BUS0 -R -t pmem | jq -r 'sort_by(-.size) | .[].dev' | head -1) 17 | 18 | available_sz=$($NDCTL list -r $region | jq -r .[].available_size) 19 | size=$(( available_sz/4 )) 20 | 21 | NS=() 22 | for ((i=0; i<3; i++)) 23 | do 24 | NS[$i]=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev) 25 | [[ -n ${NS[$i]} ]] 26 | done 27 | 28 | $NDCTL disable-namespace ${NS[1]} 29 | $NDCTL destroy-namespace ${NS[1]} 30 | 31 | $NDCTL create-namespace -r $region -t pmem 32 | } 33 | 34 | modprobe nfit_test 35 | rc=1 36 | reset 37 | do_test 38 | _cleanup 39 | exit 0 40 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-destroy-namespace.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-destroy-namespace(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | ndctl-destroy-namespace - destroy the given namespace(s) 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl destroy-namespace' [] 14 | 15 | include::namespace-description.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | include::xable-namespace-options.txt[] 20 | -f:: 21 | --force:: 22 | Unless this option is specified the 'destroy namespace' 23 | operation will fail if the namespace is presently active. 24 | Specifying --force causes the namespace to be disabled before 25 | the operation is attempted. However, if the namespace is 26 | mounted then the 'disable namespace' and 'destroy 27 | namespace' operations will be aborted. The namespace must be 28 | unmounted before being destroyed. 29 | 30 | include::../copyright.txt[] 31 | 32 | SEE ALSO 33 | -------- 34 | linkndctl:ndctl-create-namespace[1] 35 | -------------------------------------------------------------------------------- /ccan/array_size/array_size.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_ARRAY_SIZE_H 3 | #define CCAN_ARRAY_SIZE_H 4 | #include "config.h" 5 | #include 6 | 7 | /** 8 | * ARRAY_SIZE - get the number of elements in a visible array 9 | * @arr: the array whose size you want. 10 | * 11 | * This does not work on pointers, or arrays declared as [], or 12 | * function parameters. With correct compiler support, such usage 13 | * will cause a build error (see build_assert). 14 | */ 15 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) 16 | 17 | #if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF 18 | /* Two gcc extensions. 19 | * &a[0] degrades to a pointer: a different type from an array */ 20 | #define _array_size_chk(arr) \ 21 | BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \ 22 | typeof(&(arr)[0]))) 23 | #else 24 | #define _array_size_chk(arr) 0 25 | #endif 26 | #endif /* CCAN_ALIGNOF_H */ 27 | -------------------------------------------------------------------------------- /util/iomem.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2019-2020 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | unsigned long long __iomem_get_dev_resource(struct log_ctx *ctx, 11 | const char *devpath) 12 | { 13 | const char *devname = devpath_to_devname(devpath); 14 | FILE *fp = fopen("/proc/iomem", "r"); 15 | unsigned long long res; 16 | char name[256]; 17 | 18 | if (fp == NULL) { 19 | log_err(ctx, "%s: open /proc/iomem: %s\n", devname, 20 | strerror(errno)); 21 | return 0; 22 | } 23 | 24 | while (fscanf(fp, "%llx-%*x : %254[^\n]\n", &res, name) == 2) { 25 | if (strcmp(name, devname) == 0) { 26 | log_dbg(ctx, "%s: got resource via iomem: %#llx\n", 27 | devname, res); 28 | fclose(fp); 29 | return res; 30 | } 31 | } 32 | 33 | log_dbg(ctx, "%s: not found in iomem\n", devname); 34 | fclose(fp); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /cxl/lib/meson.build: -------------------------------------------------------------------------------- 1 | libcxl_version = '@0@.@1@.@2@'.format( 2 | LIBCXL_CURRENT - LIBCXL_AGE, 3 | LIBCXL_REVISION, 4 | LIBCXL_AGE) 5 | 6 | libcxl_dir_path = meson.current_source_dir() 7 | libcxl_sym = files('libcxl.sym') 8 | libcxl_sym_path = libcxl_dir_path / 'libcxl.sym' 9 | 10 | cxl = library('cxl', 11 | '../../util/sysfs.c', 12 | '../../util/log.c', 13 | '../../util/log.h', 14 | 'libcxl.c', 15 | include_directories : root_inc, 16 | dependencies : [ 17 | uuid, 18 | kmod, 19 | libudev, 20 | daxctl_dep, 21 | ], 22 | version : libcxl_version, 23 | install : true, 24 | install_dir : rootlibdir, 25 | link_args : '-Wl,--version-script=' + libcxl_sym_path, 26 | link_depends : libcxl_sym, 27 | ) 28 | cxl_dep = declare_dependency(link_with : cxl) 29 | 30 | custom_target( 31 | 'libcxl.pc', 32 | command : pkgconfig_script + [ '@INPUT@' ], 33 | input : 'libcxl.pc.in', 34 | output : 'libcxl.pc', 35 | capture : true, 36 | install : true, 37 | install_dir : pkgconfiglibdir, 38 | ) 39 | -------------------------------------------------------------------------------- /daxctl/builtin.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef _DAXCTL_BUILTIN_H_ 4 | #define _DAXCTL_BUILTIN_H_ 5 | 6 | struct daxctl_ctx; 7 | int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx); 8 | int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx); 9 | int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx); 10 | int cmd_destroy_device(int argc, const char **argv, struct daxctl_ctx *ctx); 11 | int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx); 12 | int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx); 13 | int cmd_enable_device(int argc, const char **argv, struct daxctl_ctx *ctx); 14 | int cmd_online_memory(int argc, const char **argv, struct daxctl_ctx *ctx); 15 | int cmd_offline_memory(int argc, const char **argv, struct daxctl_ctx *ctx); 16 | int cmd_split_acpi(int argc, const char **argv, struct daxctl_ctx *ctx); 17 | #endif /* _DAXCTL_BUILTIN_H_ */ 18 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-enable-memdev.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-enable-memdev(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | cxl-enable-memdev - activate / hot-add a given CXL memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl enable-memdev' [..] [] 14 | 15 | A memdev typically autoenables at initial device discovery. However, if 16 | it was manually disabled this command can trigger the kernel to activate 17 | it again. This involves detecting the state of the HDM (Host Managed 18 | Device Memory) Decoders and validating that CXL.mem is enabled for each 19 | port in the device's hierarchy. 20 | 21 | include::xable-no-op.txt[] 22 | 23 | OPTIONS 24 | ------- 25 | :: 26 | include::memdev-option.txt[] 27 | 28 | include::bus-option.txt[] 29 | 30 | -v:: 31 | Turn on verbose debug messages in the library (if libcxl was built with 32 | logging and debug enabled). 33 | 34 | include::../copyright.txt[] 35 | 36 | SEE ALSO 37 | -------- 38 | linkcxl:cxl-disable-memdev[1] 39 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-disable-bus.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-disable-bus(1) 4 | =================== 5 | 6 | NAME 7 | ---- 8 | cxl-disable-bus - Shutdown an entire tree of CXL devices 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl disable-bus' [..] [] 14 | 15 | For test and debug scenarios, disable a CXL bus and any associated 16 | memory devices from CXL.mem operations. 17 | 18 | include::xable-no-op.txt[] 19 | 20 | OPTIONS 21 | ------- 22 | -f:: 23 | --force:: 24 | DANGEROUS: Override the safety measure that blocks attempts to disable a 25 | bus if the tool determines a descendent memdev is in active usage. 26 | Recall that CXL memory ranges might have been established by platform 27 | firmware and disabling an active device is akin to force removing memory 28 | from a running system. 29 | 30 | --debug:: 31 | If the cxl tool was built with debug disabled, turn on debug 32 | messages. 33 | 34 | 35 | include::../copyright.txt[] 36 | 37 | SEE ALSO 38 | -------- 39 | linkcxl:cxl-disable-port[1] 40 | -------------------------------------------------------------------------------- /test/multi-dax.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | rc=77 8 | 9 | . $(dirname $0)/common 10 | 11 | check_min_kver "4.13" || do_skip "may lack multi-dax support" 12 | check_prereq "jq" 13 | 14 | trap 'err $LINENO' ERR 15 | 16 | ALIGN_SIZE=`getconf PAGESIZE` 17 | 18 | # setup (reset nfit_test dimms) 19 | modprobe nfit_test 20 | reset 21 | rc=1 22 | 23 | query=". | sort_by(.available_size) | reverse | .[0].dev" 24 | region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query") 25 | 26 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M) 27 | chardev1=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev") 28 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M) 29 | chardev2=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev") 30 | 31 | check_dmesg "$LINENO" 32 | 33 | _cleanup 34 | 35 | exit 0 36 | -------------------------------------------------------------------------------- /Documentation/asciidoctor-extensions.rb.in: -------------------------------------------------------------------------------- 1 | require 'asciidoctor' 2 | require 'asciidoctor/extensions' 3 | 4 | module @Utility@ 5 | module Documentation 6 | class Link@Utility@Processor < Asciidoctor::Extensions::InlineMacroProcessor 7 | use_dsl 8 | 9 | named :chrome 10 | 11 | def process(parent, target, attrs) 12 | if parent.document.basebackend? 'html' 13 | prefix = parent.document.attr('@utility@-relative-html-prefix') 14 | %(#{target}(#{attrs[1]})\n) 15 | elsif parent.document.basebackend? 'manpage' 16 | "#{target}(#{attrs[1]})" 17 | elsif parent.document.basebackend? 'docbook' 18 | "\n" \ 19 | "#{target}" \ 20 | "#{attrs[1]}\n" \ 21 | "\n" 22 | end 23 | end 24 | end 25 | end 26 | end 27 | 28 | Asciidoctor::Extensions.register do 29 | inline_macro @Utility@::Documentation::Link@Utility@Processor, :link@utility@ 30 | end 31 | -------------------------------------------------------------------------------- /LICENSES/other/MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-destroy-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-destroy-device(1) 4 | ======================== 5 | 6 | NAME 7 | ---- 8 | daxctl-destroy-device - Destroy a devdax device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl destroy-device' [...] [] 14 | 15 | EXAMPLES 16 | -------- 17 | 18 | * Destroys dax0.1 19 | ---- 20 | # daxctl disable-device dax0.1 21 | disabled 1 device 22 | # daxctl destroy-device dax0.1 23 | destroyed 1 device 24 | ---- 25 | 26 | * Destroys all devices in region id 0 27 | ---- 28 | # daxctl disable-device -r 0 all 29 | disabled 3 devices 30 | # daxctl destroy-device -r 0 all 31 | destroyed 2 devices 32 | ---- 33 | 34 | DESCRIPTION 35 | ----------- 36 | 37 | Destroys a dax device in 'devdax' mode. 38 | 39 | OPTIONS 40 | ------- 41 | include::region-option.txt[] 42 | 43 | include::human-option.txt[] 44 | 45 | include::verbose-option.txt[] 46 | 47 | include::../copyright.txt[] 48 | 49 | SEE ALSO 50 | -------- 51 | linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] 52 | -------------------------------------------------------------------------------- /ndctl/lib/hyperv.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2019, Microsoft Corporation. All rights reserved. */ 3 | 4 | #ifndef __NDCTL_HYPERV_H__ 5 | #define __NDCTL_HYPERV_H__ 6 | 7 | /* See http://www.uefi.org/RFIC_LIST ("Virtual NVDIMM 0x1901") */ 8 | 9 | enum { 10 | ND_HYPERV_CMD_QUERY_SUPPORTED_FUNCTIONS = 0, 11 | ND_HYPERV_CMD_GET_HEALTH_INFO = 1, 12 | ND_HYPERV_CMD_GET_SHUTDOWN_INFO = 2, 13 | }; 14 | 15 | /* Get Health Information (Function Index 1) */ 16 | struct nd_hyperv_health_info { 17 | __u32 status; 18 | __u32 health; 19 | } __attribute__((packed)); 20 | 21 | /* Get Unsafe Shutdown Count (Function Index 2) */ 22 | struct nd_hyperv_shutdown_info { 23 | __u32 status; 24 | __u32 count; 25 | } __attribute__((packed)); 26 | 27 | union nd_hyperv_cmd { 28 | __u32 status; 29 | struct nd_hyperv_health_info health_info; 30 | struct nd_hyperv_shutdown_info shutdown_info; 31 | } __attribute__((packed)); 32 | 33 | struct nd_pkg_hyperv { 34 | struct nd_cmd_pkg gen; 35 | union nd_hyperv_cmd u; 36 | } __attribute__((packed)); 37 | 38 | #endif /* __NDCTL_HYPERV_H__ */ 39 | -------------------------------------------------------------------------------- /util/main.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | /* Copyright (C) 2006 Linus Torvalds. All rights reserved. */ 4 | 5 | /* originally copied from perf and git */ 6 | 7 | #ifndef __MAIN_H__ 8 | #define __MAIN_H__ 9 | 10 | enum program { 11 | PROG_NDCTL, 12 | PROG_DAXCTL, 13 | PROG_CXL, 14 | }; 15 | 16 | struct ndctl_ctx; 17 | struct daxctl_ctx; 18 | struct cxl_ctx; 19 | 20 | struct cmd_struct { 21 | const char *cmd; 22 | union { 23 | int (*n_fn)(int, const char **, struct ndctl_ctx *ctx); 24 | int (*d_fn)(int, const char **, struct daxctl_ctx *ctx); 25 | int (*c_fn)(int, const char **, struct cxl_ctx *ctx); 26 | }; 27 | }; 28 | 29 | int main_handle_options(const char ***argv, int *argc, const char *usage_msg, 30 | struct cmd_struct *cmds, int num_cmds); 31 | void main_handle_internal_command(int argc, const char **argv, void *ctx, 32 | struct cmd_struct *cmds, int num_cmds, enum program prog); 33 | int help_show_man_page(const char *cmd, const char *util_name, 34 | const char *viewer); 35 | #endif /* __MAIN_H__ */ 36 | -------------------------------------------------------------------------------- /sles/meson.build: -------------------------------------------------------------------------------- 1 | sles_spec1 = vcs_tag( 2 | input : '../ndctl.spec.in', 3 | output : 'ndctl.spec.sles.in', 4 | command: vcs_tagger, 5 | replace_string : 'VERSION', 6 | ) 7 | 8 | header = files('header') 9 | 10 | sles_spec2 = custom_target('ndctl.spec.in', 11 | command : [ 12 | 'cat', header, '@INPUT@', 13 | ], 14 | input : sles_spec1, 15 | output : 'ndctl.spec.in', 16 | capture : true, 17 | ) 18 | 19 | sles_spec3 = custom_target('ndctl.spec', 20 | command : [ 21 | 'sed', '-e', 's,DAX_DNAME,libdaxctl-devel,g', 22 | '-e', 's,CXL_DNAME,libcxl-devel,g', 23 | '-e', 's,DNAME,libndctl-devel,g', 24 | '-e', 's,%license,%doc,g', 25 | '-e', 's,\(^License:.*GPL\)v2,\1-2.0,g', 26 | '-e', 's,DAX_LNAME,libdaxctl@0@,g'.format(LIBDAXCTL_CURRENT - LIBDAXCTL_AGE), 27 | '-e', 's,CXL_LNAME,libcxl@0@,g'.format(LIBCXL_CURRENT - LIBCXL_AGE), 28 | '-e', 's,LNAME,libndctl@0@,g'.format(LIBNDCTL_CURRENT - LIBNDCTL_AGE), 29 | '@INPUT@' 30 | ], 31 | 32 | input : sles_spec2, 33 | output : 'ndctl.spec', 34 | capture : true, 35 | ) 36 | -------------------------------------------------------------------------------- /daxctl/migrate.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright (C) 2019-2020 Intel Corporation. All rights reserved. */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx) 13 | { 14 | int i; 15 | static const struct option options[] = { 16 | OPT_END(), 17 | }; 18 | const char * const u[] = { 19 | "daxctl migrate-device-model", 20 | NULL 21 | }; 22 | 23 | argc = parse_options(argc, argv, options, u, 0); 24 | for (i = 0; i < argc; i++) 25 | error("unknown parameter \"%s\"\n", argv[i]); 26 | 27 | if (argc) 28 | usage_with_options(u, options); 29 | 30 | if (symlink(DAXCTL_MODPROBE_DATA, DAXCTL_MODPROBE_INSTALL) == 0) { 31 | fprintf(stderr, " success: installed %s\n", 32 | DAXCTL_MODPROBE_INSTALL); 33 | return EXIT_SUCCESS; 34 | } 35 | 36 | error("failed to install %s: %s\n", DAXCTL_MODPROBE_INSTALL, 37 | strerror(errno)); 38 | 39 | return EXIT_FAILURE; 40 | } 41 | -------------------------------------------------------------------------------- /git-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | to_ver() { 4 | VN=$1 5 | #drop leading 'v' out of the version so its a pure number 6 | if [ ${VN:0:1} = "v" ]; then 7 | VN=${VN:1} 8 | fi 9 | echo $VN 10 | } 11 | 12 | dirty() { 13 | VN=$(to_ver $1) 14 | git update-index -q --refresh 15 | if test -z "$(git diff-index --name-only HEAD --)"; then 16 | echo "$VN" 17 | else 18 | echo "${VN}.dirty" 19 | fi 20 | } 21 | 22 | DEF_VER=83 23 | 24 | LF=' 25 | ' 26 | 27 | # First see if there is a version file (included in release tarballs), 28 | # then try git-describe, then default. 29 | if test -f version; then 30 | VN=$(cat version) || VN="$DEF_VER" 31 | elif test -d ${GIT_DIR:-.git} -o -f .git && 32 | VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) && 33 | case "$VN" in 34 | *$LF*) (exit 1) ;; 35 | v[0-9]*) 36 | VN="$(dirty $VN)" 37 | esac; then 38 | VN=$(echo "$VN" | sed -e 's/-/./g'); 39 | else 40 | read COMMIT COMMIT_SUBJECT </dev/null) 42 | EOF 43 | if [ -z $COMMIT ]; then 44 | VN="${DEF_VER}+" 45 | else 46 | VN="$(dirty ${DEF_VER}.git$COMMIT)" 47 | fi 48 | fi 49 | 50 | echo $VN 51 | -------------------------------------------------------------------------------- /ccan/list/list.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | #include 3 | #include 4 | #include "list.h" 5 | 6 | static void *corrupt(const char *abortstr, 7 | const struct list_node *head, 8 | const struct list_node *node, 9 | unsigned int count) 10 | { 11 | if (abortstr) { 12 | fprintf(stderr, 13 | "%s: prev corrupt in node %p (%u) of %p\n", 14 | abortstr, node, count, head); 15 | abort(); 16 | } 17 | return NULL; 18 | } 19 | 20 | struct list_node *list_check_node(const struct list_node *node, 21 | const char *abortstr) 22 | { 23 | const struct list_node *p, *n; 24 | int count = 0; 25 | 26 | for (p = node, n = node->next; n != node; p = n, n = n->next) { 27 | count++; 28 | if (n->prev != p) 29 | return corrupt(abortstr, node, n, count); 30 | } 31 | /* Check prev on head node. */ 32 | if (node->prev != p) 33 | return corrupt(abortstr, node, node, 0); 34 | 35 | return (struct list_node *)node; 36 | } 37 | 38 | struct list_head *list_check(const struct list_head *h, const char *abortstr) 39 | { 40 | if (!list_check_node(&h->n, abortstr)) 41 | return NULL; 42 | return (struct list_head *)h; 43 | } 44 | -------------------------------------------------------------------------------- /test/track-uuid.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2018-2020 Intel Corporation. All rights reserved. 4 | 5 | blockdev="" 6 | rc=77 7 | 8 | . $(dirname $0)/common 9 | 10 | set -e 11 | trap 'err $LINENO' ERR 12 | 13 | # setup (reset nfit_test dimms) 14 | modprobe nfit_test 15 | reset 16 | 17 | rc=1 18 | 19 | # create a fsdax namespace and clear errors (if any) 20 | dev="x" 21 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m raw) 22 | eval "$(echo "$json" | json2var)" 23 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 24 | 25 | $NDCTL disable-namespace $dev 26 | # On broken kernels this reassignment of capacity triggers a warning 27 | # with the following signature, and results in ENXIO. 28 | # WARNING: CPU: 11 PID: 1378 at drivers/nvdimm/label.c:721 __pmem_label_update+0x55d/0x570 [libnvdimm] 29 | # Call Trace: 30 | # nd_pmem_namespace_label_update+0xd6/0x160 [libnvdimm] 31 | # uuid_store+0x15c/0x170 [libnvdimm] 32 | # kernfs_fop_write+0xf0/0x1a0 33 | # __vfs_write+0x26/0x150 34 | uuidgen > /sys/bus/nd/devices/$dev/uuid 35 | $NDCTL enable-namespace $dev 36 | 37 | _cleanup 38 | exit 0 39 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-disable-port.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-disable-port(1) 4 | =================== 5 | 6 | NAME 7 | ---- 8 | cxl-disable-port - disable / hot-remove a given CXL port and descendants 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl disable-port' [..] [] 14 | 15 | For test and debug scenarios, disable a CXL port and any memory devices 16 | dependent on this port being active for CXL.mem operation. 17 | 18 | include::xable-no-op.txt[] 19 | 20 | OPTIONS 21 | ------- 22 | -e:: 23 | --endpoint:: 24 | Toggle from treating the port arguments as Switch Port identifiers to 25 | Endpoint Port identifiers. 26 | 27 | -f:: 28 | --force:: 29 | DANGEROUS: Override the safety measure that blocks attempts to disable a 30 | port if the tool determines a descendent memdev is in active usage. 31 | Recall that CXL memory ranges might have been established by platform 32 | firmware and disabling an active device is akin to force removing memory 33 | from a running system. 34 | 35 | include::debug-option.txt[] 36 | 37 | include::../copyright.txt[] 38 | 39 | SEE ALSO 40 | -------- 41 | linkcxl:cxl-disable-port[1] 42 | -------------------------------------------------------------------------------- /contrib/meson.build: -------------------------------------------------------------------------------- 1 | bashcompletiondir = get_option('bashcompletiondir') 2 | if bashcompletiondir == '' 3 | bash_completion = dependency('bash-completion', required : false) 4 | if bash_completion.found() 5 | bashcompletiondir = bash_completion.get_variable(pkgconfig : 'completionsdir') 6 | else 7 | bashcompletiondir = datadir / 'bash-completion/completions' 8 | endif 9 | endif 10 | 11 | if bashcompletiondir != 'no' 12 | install_data('ndctl', install_dir : bashcompletiondir) 13 | 14 | # TODO Switch to symlinks once 0.61.0 is more widely available 15 | # install_symlink('daxctl', 16 | # install_dir : bashcompletiondir, 17 | # pointing_to : 'ndctl' 18 | # ) 19 | # install_symlink('cxl', 20 | # install_dir : bashcompletiondir, 21 | # pointing_to : 'ndctl' 22 | # ) 23 | install_data('ndctl', rename : 'daxctl', install_dir : bashcompletiondir) 24 | install_data('ndctl', rename : 'cxl', install_dir : bashcompletiondir) 25 | endif 26 | 27 | modprobedatadir = get_option('modprobedatadir') 28 | if modprobedatadir == '' 29 | modprobedatadir = sysconfdir + '/modprobe.d/' 30 | endif 31 | install_data('nvdimm-security.conf', install_dir : modprobedatadir) 32 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-disable-region.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-disable-region(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | cxl-disable-region - disable specified region(s). 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl disable-region []' 14 | 15 | include::region-description.txt[] 16 | 17 | If there are memory blocks that are still online, the operation will attempt to 18 | offline the relevant blocks. If the offlining fails, the operation fails when not 19 | using the -f (force) parameter. 20 | 21 | EXAMPLE 22 | ------- 23 | ---- 24 | # cxl disable-region all 25 | disabled 2 regions 26 | ---- 27 | 28 | include::xable-no-op.txt[] 29 | 30 | OPTIONS 31 | ------- 32 | include::bus-option.txt[] 33 | 34 | -f:: 35 | --force:: 36 | Attempt to disable-region even though memory cannot be offlined successfully. 37 | Will emit warning that operation will permanently leak physical address space 38 | and cannot be recovered until a reboot. 39 | 40 | include::decoder-option.txt[] 41 | 42 | include::debug-option.txt[] 43 | 44 | include::../copyright.txt[] 45 | 46 | SEE ALSO 47 | -------- 48 | linkcxl:cxl-list[1], linkcxl:cxl-enable-region[1] 49 | -------------------------------------------------------------------------------- /ndctl/json.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef __NDCTL_UTIL_JSON_H__ 4 | #define __NDCTL_UTIL_JSON_H__ 5 | #include 6 | #include 7 | 8 | struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, 9 | unsigned long flags); 10 | struct json_object *util_badblock_rec_to_json(u64 block, u64 count, 11 | unsigned long flags); 12 | struct json_object *util_region_badblocks_to_json(struct ndctl_region *region, 13 | unsigned int *bb_count, unsigned long flags); 14 | struct json_object *util_bus_to_json(struct ndctl_bus *bus, 15 | unsigned long flags); 16 | struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm, 17 | unsigned long flags); 18 | struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping, 19 | unsigned long flags); 20 | struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm); 21 | struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm, 22 | unsigned long flags); 23 | struct json_object *util_region_capabilities_to_json(struct ndctl_region *region); 24 | #endif /* __NDCTL_UTIL_JSON_H__ */ 25 | -------------------------------------------------------------------------------- /daxctl/lib/meson.build: -------------------------------------------------------------------------------- 1 | libdaxctl_version = '@0@.@1@.@2@'.format( 2 | LIBDAXCTL_CURRENT - LIBDAXCTL_AGE, 3 | LIBDAXCTL_REVISION, 4 | LIBDAXCTL_AGE, 5 | ) 6 | 7 | libdaxctl_dir_path = meson.current_source_dir() 8 | libdaxctl_sym = files('libdaxctl.sym') 9 | libdaxctl_sym_path = libdaxctl_dir_path / 'libdaxctl.sym' 10 | 11 | 12 | libdaxctl_src = [ 13 | '../../util/iomem.c', 14 | '../../util/sysfs.c', 15 | '../../util/log.c', 16 | 'libdaxctl.c', 17 | ] 18 | 19 | daxctl = library( 20 | 'daxctl', 21 | libdaxctl_src, 22 | version : libdaxctl_version, 23 | include_directories : root_inc, 24 | dependencies : [ 25 | uuid, 26 | kmod, 27 | ], 28 | install : true, 29 | install_dir : rootlibdir, 30 | link_args : '-Wl,--version-script=' + libdaxctl_sym_path, 31 | link_depends : libdaxctl_sym, 32 | ) 33 | 34 | daxctl_dep = declare_dependency(link_with : daxctl) 35 | 36 | custom_target( 37 | 'libdaxctl.pc', 38 | command : pkgconfig_script + [ '@INPUT@' ], 39 | input : 'libdaxctl.pc.in', 40 | output : 'libdaxctl.pc', 41 | capture : true, 42 | install : true, 43 | install_dir : pkgconfiglibdir, 44 | ) 45 | 46 | install_data('daxctl.conf', install_dir : datadir / 'daxctl') 47 | -------------------------------------------------------------------------------- /daxctl/filter.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | 7 | #include "filter.h" 8 | 9 | struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, 10 | const char *ident) 11 | { 12 | struct daxctl_region *region = daxctl_dev_get_region(dev); 13 | int region_id, dev_id; 14 | 15 | if (!ident || strcmp(ident, "all") == 0) 16 | return dev; 17 | 18 | if (strcmp(ident, daxctl_dev_get_devname(dev)) == 0) 19 | return dev; 20 | 21 | if (sscanf(ident, "%d.%d", ®ion_id, &dev_id) == 2 && 22 | daxctl_region_get_id(region) == region_id && 23 | daxctl_dev_get_id(dev) == dev_id) 24 | return dev; 25 | 26 | return NULL; 27 | } 28 | 29 | struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region, 30 | const char *ident) 31 | { 32 | int region_id; 33 | 34 | if (!ident || strcmp(ident, "all") == 0) 35 | return region; 36 | 37 | if ((sscanf(ident, "%d", ®ion_id) == 1 || 38 | sscanf(ident, "region%d", ®ion_id) == 1) && 39 | daxctl_region_get_id(region) == region_id) 40 | return region; 41 | 42 | return NULL; 43 | } 44 | -------------------------------------------------------------------------------- /daxctl/daxctl.example.conf: -------------------------------------------------------------------------------- 1 | # This is an example config file for daxctl 2 | # daxctl supports multiple configuration files. All files with the 3 | # .conf suffix under {sysconfdir}/daxctl.conf.d/ are valid config files. 4 | # Lines beginning with a '#' are treated as comments and ignored 5 | # The (section-name, subsection-name) tuple must be unique across all 6 | # config files. 7 | 8 | # The following example config snippet is used to automatically reconfigure 9 | # an nvdimm namespace with the specified UUID from 'devdax' mode to 10 | # 'system-ram'. 11 | 12 | # Uncomment the lines to activate it, and substitute the correct UUIDs and 13 | # other parameters for the desired behavior. 14 | 15 | # This can be replicated as many times as necessary to handle multiple 16 | # namespaces/dax devices, so long as the subsection name (e.g. 17 | # "unique_identifier_foo" in the example below) is unique across all 18 | # sections and all config files in the config path. 19 | 20 | # The nvdimm.uuid can be obtained from a command such as: 21 | # "ndctl list --device-dax" 22 | 23 | # [reconfigure-device unique_identifier_foo] 24 | # nvdimm.uuid=ed93e918-e165-49d8-921d-383d7b9660c5 25 | # mode = system-ram 26 | # online = true 27 | # movable = false 28 | -------------------------------------------------------------------------------- /ndctl/lib/meson.build: -------------------------------------------------------------------------------- 1 | libndctl_version = '@0@.@1@.@2@'.format( 2 | LIBNDCTL_CURRENT - LIBNDCTL_AGE, 3 | LIBNDCTL_REVISION, 4 | LIBNDCTL_AGE) 5 | 6 | libndctl_dir_path = meson.current_source_dir() 7 | libndctl_sym = files('libndctl.sym') 8 | libndctl_sym_path = libndctl_dir_path / 'libndctl.sym' 9 | 10 | ndctl = library( 11 | 'ndctl', 12 | '../../util/log.c', 13 | '../../util/sysfs.c', 14 | 'dimm.c', 15 | 'inject.c', 16 | 'nfit.c', 17 | 'smart.c', 18 | 'intel.c', 19 | 'hpe1.c', 20 | 'msft.c', 21 | 'hyperv.c', 22 | 'papr.c', 23 | 'ars.c', 24 | 'firmware.c', 25 | 'libndctl.c', 26 | dependencies : [ 27 | daxctl_dep, 28 | libudev, 29 | uuid, 30 | kmod, 31 | ], 32 | include_directories : root_inc, 33 | version : libndctl_version, 34 | install : true, 35 | install_dir : rootlibdir, 36 | link_args : '-Wl,--version-script=' + libndctl_sym_path, 37 | link_depends : libndctl_sym, 38 | ) 39 | ndctl_dep = declare_dependency(link_with : ndctl) 40 | 41 | custom_target( 42 | 'libndctl.pc', 43 | command : pkgconfig_script + [ '@INPUT@' ], 44 | input : 'libndctl.pc.in', 45 | output : 'libndctl.pc', 46 | capture : true, 47 | install : true, 48 | install_dir : pkgconfiglibdir, 49 | ) 50 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-remove-passphrase.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-remove-passphrase(1) 4 | =========================== 5 | 6 | NAME 7 | ---- 8 | ndctl-remove-passphrase - Stop a DIMM from locking at power-loss and requiring 9 | a passphrase to access media 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | 'ndctl remove-passphrase' [..] [] 15 | 16 | DESCRIPTION 17 | ----------- 18 | Search the user keyring for an encrypted passphrase for the NVDIMM in question. 19 | If not found, attempt to load the passphrase blob. After disabling the 20 | passphrase, remove the 'key-ID' from the keyring as well as the passphrase blob 21 | from the file system. 22 | 23 | OPTIONS 24 | ------- 25 | :: 26 | include::xable-dimm-options.txt[] 27 | 28 | -b:: 29 | --bus=:: 30 | include::xable-bus-options.txt[] 31 | 32 | -v:: 33 | --verbose:: 34 | Emit debug messages. 35 | 36 | -m:: 37 | --master-passphrase:: 38 | Indicates that we are managing the master passphrase instead of the 39 | user passphrase. 40 | 41 | include::intel-nvdimm-security.txt[] 42 | 43 | include::../copyright.txt[] 44 | 45 | SEE ALSO: 46 | --------- 47 | linkndctl:ndctl-setup-passphrase[1], linkndctl:ndctl-update-passphrase[1] 48 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-disable-memdev.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-disable-memdev(1) 4 | ===================== 5 | 6 | NAME 7 | ---- 8 | cxl-disable-memdev - deactivate / hot-remove a given CXL memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl disable-memdev' [..] [] 14 | 15 | include::xable-no-op.txt[] 16 | 17 | OPTIONS 18 | ------- 19 | :: 20 | include::memdev-option.txt[] 21 | 22 | include::bus-option.txt[] 23 | 24 | -f:: 25 | --force:: 26 | DANGEROUS: Override the safety measure that blocks attempts to disable 27 | a device if the tool determines the memdev is in active usage. Recall 28 | that CXL memory ranges might have been established by platform 29 | firmware and disabling an active device is akin to force removing 30 | memory from a running system. Going down this path does not offline 31 | active memory if they are currently online. User is recommended to 32 | offline and disable the appropriate regions before disabling the memdevs. 33 | 34 | -v:: 35 | Turn on verbose debug messages in the library (if libcxl was built with 36 | logging and debug enabled). 37 | 38 | include::../copyright.txt[] 39 | 40 | SEE ALSO 41 | -------- 42 | linkcxl:cxl-enable-memdev[1] 43 | -------------------------------------------------------------------------------- /test/create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | SECTOR_SIZE="4096" 8 | rc=77 9 | 10 | . $(dirname $0)/common 11 | 12 | check_min_kver "4.5" || do_skip "may lack namespace mode attribute" 13 | 14 | trap 'err $LINENO' ERR 15 | 16 | # setup (reset nfit_test dimms) 17 | modprobe nfit_test 18 | reset 19 | 20 | rc=1 21 | 22 | # create pmem 23 | dev="x" 24 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m raw) 25 | eval $(echo $json | json2var ) 26 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 27 | [ $mode != "raw" ] && echo "fail: $LINENO" && exit 1 28 | 29 | # convert pmem to fsdax mode 30 | json=$($NDCTL create-namespace -m fsdax -f -e $dev) 31 | eval $(echo $json | json2var) 32 | [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 33 | 34 | # convert pmem to sector mode 35 | json=$($NDCTL create-namespace -m sector -l $SECTOR_SIZE -f -e $dev) 36 | eval $(echo $json | json2var) 37 | [ $sector_size != $SECTOR_SIZE ] && echo "fail: $LINENO" && exit 1 38 | [ $mode != "sector" ] && echo "fail: $LINENO" && exit 1 39 | 40 | # free capacity for blk creation 41 | $NDCTL destroy-namespace -f $dev 42 | 43 | _cleanup 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /util/size.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | 7 | unsigned long long __parse_size64(const char *str, unsigned long long *units) 8 | { 9 | unsigned long long val, check; 10 | char *end; 11 | 12 | val = strtoull(str, &end, 0); 13 | if (val == ULLONG_MAX) 14 | return val; 15 | check = val; 16 | switch (*end) { 17 | case 'k': 18 | case 'K': 19 | if (units) 20 | *units = SZ_1K; 21 | val *= SZ_1K; 22 | end++; 23 | break; 24 | case 'm': 25 | case 'M': 26 | if (units) 27 | *units = SZ_1M; 28 | val *= SZ_1M; 29 | end++; 30 | break; 31 | case 'g': 32 | case 'G': 33 | if (units) 34 | *units = SZ_1G; 35 | val *= SZ_1G; 36 | end++; 37 | break; 38 | case 't': 39 | case 'T': 40 | if (units) 41 | *units = SZ_1T; 42 | val *= SZ_1T; 43 | end++; 44 | break; 45 | default: 46 | if (units) 47 | *units = 1; 48 | break; 49 | } 50 | 51 | if (val < check || *end != '\0') 52 | val = ULLONG_MAX; 53 | return val; 54 | } 55 | 56 | unsigned long long parse_size64(const char *str) 57 | { 58 | if (!str) 59 | return 0; 60 | return __parse_size64(str, NULL); 61 | } 62 | -------------------------------------------------------------------------------- /test/label-compat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | rc=77 8 | 9 | BASE=$(dirname $0) 10 | . $BASE/common 11 | 12 | check_min_kver "4.11" || do_skip "may not provide reliable isetcookie values" 13 | check_prereq "jq" 14 | 15 | trap 'err $LINENO' ERR 16 | 17 | # setup (reset nfit_test dimms) 18 | modprobe nfit_test 19 | $NDCTL disable-region -b $NFIT_TEST_BUS0 all 20 | $NDCTL init-labels -f -b $NFIT_TEST_BUS0 all 21 | 22 | # grab the largest pmem region on -b $NFIT_TEST_BUS0 23 | query=". | sort_by(.available_size) | reverse | .[0].dev" 24 | region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query") 25 | 26 | # we assume that $region is comprised of 4 dimms 27 | query=". | .regions[0].mappings | sort_by(.dimm) | .[].dimm" 28 | dimms=$($NDCTL list -DRi -r $region | jq -r "$query" | xargs) 29 | i=1 30 | for d in $dimms 31 | do 32 | $NDCTL write-labels $d -i $BASE/nmem${i}.bin 33 | i=$((i+1)) 34 | done 35 | 36 | $NDCTL enable-region -b $NFIT_TEST_BUS0 all 37 | 38 | len=$($NDCTL list -r $region -N | jq -r "length") 39 | 40 | if [ -z $len ]; then 41 | rc=1 42 | echo "failed to find legacy isetcookie namespace" 43 | exit 1 44 | fi 45 | 46 | _cleanup 47 | 48 | exit 0 49 | -------------------------------------------------------------------------------- /test/cxl-security: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 2 | # Copyright (C) 2022, Intel Corp. All rights reserved. 3 | 4 | detect() 5 | { 6 | dev="$($NDCTL list -b "$CXL_TEST_BUS" -D | jq -r 'sort_by(.id) | .[0].dev')" 7 | [ -n "$dev" ] || err "$LINENO" 8 | id="$($NDCTL list -b "$CXL_TEST_BUS" -D | jq -r 'sort_by(.id) | .[0].id')" 9 | [ -n "$id" ] || err "$LINENO" 10 | } 11 | 12 | lock_dimm() 13 | { 14 | $NDCTL disable-dimm "$dev" 15 | test_dimm_path="" 16 | 17 | nmem_rpath=$(readlink -f "/sys/bus/nd/devices/${dev}") 18 | nmem_bus=$(dirname ${nmem_rpath}); 19 | bus_provider_path="${nmem_bus}/provider" 20 | test -e "$bus_provider_path" || err "$LINENO" 21 | bus_provider=$(cat ${bus_provider_path}) 22 | 23 | [[ "$bus_provider" == "$CXL_TEST_BUS" ]] || err "$LINENO" 24 | bus="cxl" 25 | nmem_provider_path="/sys/bus/nd/devices/${dev}/${bus}/provider" 26 | nmem_provider=$(cat ${nmem_provider_path}) 27 | 28 | test_dimm_path=$(readlink -f /sys/bus/$bus/devices/${nmem_provider}) 29 | test_dimm_path=$(dirname $(dirname ${test_dimm_path}))/security_lock 30 | 31 | test -e "$test_dimm_path" 32 | 33 | # now lock the dimm 34 | echo 1 > "${test_dimm_path}" 35 | sstate="$(get_security_state)" 36 | if [ "$sstate" != "locked" ]; then 37 | echo "Incorrect security state: $sstate expected: locked" 38 | err "$LINENO" 39 | fi 40 | } 41 | -------------------------------------------------------------------------------- /ndctl/bat.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2014-2020 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int cmd_bat(int argc, const char **argv, struct ndctl_ctx *ctx) 10 | { 11 | int loglevel = LOG_DEBUG, i, rc; 12 | struct ndctl_test *test; 13 | bool force = false; 14 | const char * const u[] = { 15 | "ndctl bat []", 16 | NULL 17 | }; 18 | const struct option options[] = { 19 | OPT_INTEGER('l', "loglevel", &loglevel, 20 | "set the log level (default LOG_DEBUG)"), 21 | OPT_BOOLEAN('f', "force", &force, 22 | "force run all tests regardless of required kernel"), 23 | OPT_END(), 24 | }; 25 | 26 | argc = parse_options(argc, argv, options, u, 0); 27 | 28 | for (i = 0; i < argc; i++) 29 | error("unknown parameter \"%s\"\n", argv[i]); 30 | 31 | if (argc) 32 | usage_with_options(u, options); 33 | 34 | if (force) 35 | test = ndctl_test_new(UINT_MAX); 36 | else 37 | test = ndctl_test_new(0); 38 | 39 | if (!test) { 40 | fprintf(stderr, "failed to initialize test\n"); 41 | return EXIT_FAILURE; 42 | } 43 | 44 | rc = test_pmem_namespaces(loglevel, test, ctx); 45 | fprintf(stderr, "test_pmem_namespaces: %s\n", rc ? "FAIL" : "PASS"); 46 | return ndctl_test_result(test, rc); 47 | } 48 | -------------------------------------------------------------------------------- /ccan/build_assert/build_assert.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_BUILD_ASSERT_H 3 | #define CCAN_BUILD_ASSERT_H 4 | 5 | /** 6 | * BUILD_ASSERT - assert a build-time dependency. 7 | * @cond: the compile-time condition which must be true. 8 | * 9 | * Your compile will fail if the condition isn't true, or can't be evaluated 10 | * by the compiler. This can only be used within a function. 11 | * 12 | * Example: 13 | * #include 14 | * ... 15 | * static char *foo_to_char(struct foo *foo) 16 | * { 17 | * // This code needs string to be at start of foo. 18 | * BUILD_ASSERT(offsetof(struct foo, string) == 0); 19 | * return (char *)foo; 20 | * } 21 | */ 22 | #define BUILD_ASSERT(cond) \ 23 | do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) 24 | 25 | /** 26 | * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression. 27 | * @cond: the compile-time condition which must be true. 28 | * 29 | * Your compile will fail if the condition isn't true, or can't be evaluated 30 | * by the compiler. This can be used in an expression: its value is "0". 31 | * 32 | * Example: 33 | * #define foo_to_char(foo) \ 34 | * ((char *)(foo) \ 35 | * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0)) 36 | */ 37 | #define BUILD_ASSERT_OR_ZERO(cond) \ 38 | (sizeof(char [1 - 2*!(cond)]) - 1) 39 | 40 | #endif /* CCAN_BUILD_ASSERT_H */ 41 | -------------------------------------------------------------------------------- /test/nfit-security: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 2 | # Copyright (C) 2022, Intel Corp. All rights reserved. 3 | 4 | detect() 5 | { 6 | dev="$($NDCTL list -b "$NFIT_TEST_BUS0" -D | jq -r .[0].dev)" 7 | [ -n "$dev" ] || err "$LINENO" 8 | id="$($NDCTL list -b "$NFIT_TEST_BUS0" -D | jq -r .[0].id)" 9 | [ -n "$id" ] || err "$LINENO" 10 | } 11 | 12 | lock_dimm() 13 | { 14 | $NDCTL disable-dimm "$dev" 15 | # convert nmemX --> test_dimmY 16 | # For now this is the only user of such a conversion so we can leave it 17 | # inline. Once a subsequent user arrives we can refactor this to a 18 | # helper in test/common: 19 | # get_test_dimm_path "nfit_test.0" "nmem3" 20 | handle="$($NDCTL list -b "$NFIT_TEST_BUS0" -d "$dev" -i | jq -r .[].dimms[0].handle)" 21 | test_dimm_path="" 22 | for test_dimm in /sys/devices/platform/"$NFIT_TEST_BUS0"/nfit_test_dimm/test_dimm*; do 23 | td_handle_file="$test_dimm/handle" 24 | test -e "$td_handle_file" || continue 25 | td_handle="$(cat "$td_handle_file")" 26 | if [[ "$td_handle" -eq "$handle" ]]; then 27 | test_dimm_path="$test_dimm" 28 | break 29 | fi 30 | done 31 | test -d "$test_dimm_path" 32 | 33 | # now lock the dimm 34 | echo 1 > "${test_dimm_path}/lock_dimm" 35 | sstate="$(get_security_state)" 36 | if [ "$sstate" != "locked" ]; then 37 | echo "Incorrect security state: $sstate expected: locked" 38 | err "$LINENO" 39 | fi 40 | } 41 | -------------------------------------------------------------------------------- /cxl/json.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2022 Intel Corporation. All rights reserved. */ 3 | #ifndef __CXL_UTIL_JSON_H__ 4 | #define __CXL_UTIL_JSON_H__ 5 | struct cxl_memdev; 6 | struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, 7 | unsigned long flags); 8 | struct cxl_bus; 9 | struct json_object *util_cxl_bus_to_json(struct cxl_bus *bus, 10 | unsigned long flags); 11 | struct cxl_port; 12 | struct json_object *util_cxl_port_to_json(struct cxl_port *port, 13 | unsigned long flags); 14 | struct json_object *util_cxl_endpoint_to_json(struct cxl_endpoint *endpoint, 15 | unsigned long flags); 16 | struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder, 17 | unsigned long flags); 18 | struct json_object *util_cxl_region_to_json(struct cxl_region *region, 19 | unsigned long flags); 20 | void util_cxl_mappings_append_json(struct json_object *jregion, 21 | struct cxl_region *region, 22 | unsigned long flags); 23 | void util_cxl_targets_append_json(struct json_object *jdecoder, 24 | struct cxl_decoder *decoder, 25 | const char *ident, const char *serial, 26 | unsigned long flags); 27 | void util_cxl_dports_append_json(struct json_object *jport, 28 | struct cxl_port *port, const char *ident, 29 | const char *serial, unsigned long flags); 30 | #endif /* __CXL_UTIL_JSON_H__ */ 31 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-read-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-read-labels(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-read-labels - read out the label area on a dimm or set of dimms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl read-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | This command dumps the raw binary data in a dimm's label area to stdout or a 17 | file. In the multi-dimm case the data is concatenated. 18 | 19 | OPTIONS 20 | ------- 21 | include::labels-options.txt[] 22 | -I:: 23 | --index:: 24 | Limit the span of the label operation to just the index-block 25 | area. This is useful to determine if the dimm label area is 26 | initialized. Note that this option and --size/--offset are 27 | mutually exclusive. 28 | 29 | -o:: 30 | --output:: 31 | output file 32 | -j:: 33 | --json:: 34 | parse the label data into json assuming the 'NVDIMM Namespace 35 | Specification' format. 36 | 37 | -u:: 38 | --human:: 39 | enable json output and convert number formats to human readable 40 | strings, for example show the size in terms of "KB", "MB", "GB", etc 41 | instead of a signed 64-bit numbers per the JSON interchange 42 | format (implies --json). 43 | 44 | include::../copyright.txt[] 45 | 46 | SEE ALSO 47 | -------- 48 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 49 | -------------------------------------------------------------------------------- /ndctl/firmware-update.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2018-2020 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef _FIRMWARE_UPDATE_H_ 5 | #define _FIRMWARE_UPDATE_H_ 6 | 7 | #define ND_CMD_STATUS_SUCCESS 0 8 | #define ND_CMD_STATUS_NOTSUPP 1 9 | #define ND_CMD_STATUS_NOTEXIST 2 10 | #define ND_CMD_STATUS_INVALPARM 3 11 | #define ND_CMD_STATUS_HWERR 4 12 | #define ND_CMD_STATUS_RETRY 5 13 | #define ND_CMD_STATUS_UNKNOWN 6 14 | #define ND_CMD_STATUS_EXTEND 7 15 | #define ND_CMD_STATUS_NORES 8 16 | #define ND_CMD_STATUS_NOTREADY 9 17 | 18 | /* extended status through ND_CMD_STATUS_EXTEND */ 19 | #define ND_CMD_STATUS_START_BUSY 0x10000 20 | #define ND_CMD_STATUS_SEND_CTXINVAL 0x10000 21 | #define ND_CMD_STATUS_FIN_CTXINVAL 0x10000 22 | #define ND_CMD_STATUS_FIN_DONE 0x20000 23 | #define ND_CMD_STATUS_FIN_BAD 0x30000 24 | #define ND_CMD_STATUS_FIN_ABORTED 0x40000 25 | #define ND_CMD_STATUS_FQ_CTXINVAL 0x10000 26 | #define ND_CMD_STATUS_FQ_BUSY 0x20000 27 | #define ND_CMD_STATUS_FQ_BAD 0x30000 28 | #define ND_CMD_STATUS_FQ_ORDER 0x40000 29 | 30 | struct fw_info { 31 | uint32_t store_size; 32 | uint32_t update_size; 33 | uint32_t query_interval; 34 | uint32_t max_query; 35 | uint64_t run_version; 36 | uint32_t context; 37 | }; 38 | 39 | struct update_context { 40 | size_t fw_size; 41 | struct fw_info dimm_fw; 42 | struct ndctl_cmd *start; 43 | struct json_object *jdimms; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /test/device-dax-fio.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname $0)/common 6 | 7 | rc=77 8 | 9 | set -e 10 | 11 | check_min_kver "4.11" || do_skip "kernel may lack device-dax fixes" 12 | 13 | trap 'err $LINENO' ERR 14 | 15 | check_prereq "fio" 16 | if ! fio --enghelp | grep -q "dev-dax"; then 17 | echo "fio lacks dev-dax engine" 18 | exit 77 19 | fi 20 | 21 | dev=$($TEST_PATH/dax-dev) 22 | for align in 4k 2m 1g 23 | do 24 | json=$($NDCTL create-namespace -m devdax -a $align -f -e $dev) 25 | chardev=$(echo $json | jq -r ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev") 26 | if [ align = "1g" ]; then 27 | bs="1g" 28 | else 29 | bs="2m" 30 | fi 31 | 32 | cat > fio.job <<- EOF 33 | [global] 34 | ioengine=dev-dax 35 | direct=0 36 | filename=/dev/${chardev} 37 | verify=crc32c 38 | bs=${bs} 39 | 40 | [write] 41 | rw=write 42 | runtime=5 43 | 44 | [read] 45 | stonewall 46 | rw=read 47 | runtime=5 48 | EOF 49 | 50 | rc=1 51 | fio fio.job 2>&1 | tee fio.log 52 | 53 | if grep -q "fio.*got signal" fio.log; then 54 | echo "test/device-dax-fio.sh: failed with align: $align" 55 | exit 1 56 | fi 57 | 58 | # revert namespace to raw mode 59 | json=$($NDCTL create-namespace -m raw -f -e $dev) 60 | eval $(json2var <<< "$json") 61 | [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 62 | done 63 | 64 | exit 0 65 | -------------------------------------------------------------------------------- /scripts/docsurgeon_parser_generator.m4: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # m4_ignore( 4 | echo "This is just a parsing library template, not the library - pass this file to 'argbash' to fix this." >&2 5 | exit 11 #)Created by argbash-init v2.9.0 6 | # Rearrange the order of options below according to what you would like to see in the help message. 7 | # ARG_OPTIONAL_REPEATED([name], [n], [Command or function name to generate a template for.\n Can be repeated for multiple names. ], []) 8 | # ARG_OPTIONAL_BOOLEAN([edit], [e], [Edit template files after creation], [on]) 9 | # ARG_OPTIONAL_BOOLEAN([debug], [], [Debug script problems (enables set -x)], ) 10 | # ARG_OPTIONAL_BOOLEAN([dump], [], [Write generated file to stdout instead of a file], ) 11 | # ARG_OPTIONAL_SINGLE([module], [m], [Module (Docs subdir) in which to create the template], []) 12 | # ARG_OPTIONAL_SINGLE([section], [s], [man section for which to create the template], []) 13 | # ARG_OPTIONAL_BOOLEAN([human-option], [u], [Include the human option in 'OPTIONS'], ) 14 | # ARG_OPTIONAL_BOOLEAN([verbose-option], [V], [Include the verbose option in 'OPTIONS'], ) 15 | # ARG_POSITIONAL_DOUBLEDASH() 16 | # ARG_POSITIONAL_SINGLE([command], [Operation to perform:\n gen-man\n gen-include], []) 17 | # ARGBASH_SET_DELIM([ =]) 18 | # ARG_OPTION_STACKING([getopt]) 19 | # ARG_RESTRICT_VALUES([no-local-options]) 20 | # ARG_DEFAULTS_POS 21 | # ARG_HELP([Tool to aid in creating and managing man page templates]) 22 | # ARG_VERSION([echo "docsurgeon 0.1"]) 23 | # ARGBASH_GO 24 | -------------------------------------------------------------------------------- /ndctl/lib/msft.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright (C) 2016-2017 Dell, Inc. */ 3 | /* Copyright (C) 2016 Hewlett Packard Enterprise Development LP */ 4 | /* Copyright (C) 2014-2020, Intel Corporation. */ 5 | /* Copyright (C) 2022 iXsystems, Inc. */ 6 | #ifndef __NDCTL_MSFT_H__ 7 | #define __NDCTL_MSFT_H__ 8 | 9 | enum { 10 | NDN_MSFT_CMD_CHEALTH = 10, 11 | NDN_MSFT_CMD_NHEALTH = 11, 12 | NDN_MSFT_CMD_EHEALTH = 12, 13 | }; 14 | 15 | /* 16 | * This is actually function 11 data, 17 | * This is the closest I can find to match smart 18 | * Microsoft _DSM does not have smart function 19 | */ 20 | struct ndn_msft_smart_data { 21 | __u16 health; 22 | __u16 temp; 23 | __u8 err_thresh_stat; 24 | __u8 warn_thresh_stat; 25 | __u8 nvm_lifetime; 26 | __u8 count_dram_uncorr_err; 27 | __u8 count_dram_corr_err; 28 | } __attribute__((packed)); 29 | 30 | struct ndn_msft_smart { 31 | __u32 status; 32 | union { 33 | __u8 buf[9]; 34 | struct ndn_msft_smart_data data[1]; 35 | }; 36 | } __attribute__((packed)); 37 | 38 | union ndn_msft_cmd { 39 | __u32 query; 40 | struct ndn_msft_smart smart; 41 | } __attribute__((packed)); 42 | 43 | struct ndn_pkg_msft { 44 | struct nd_cmd_pkg gen; 45 | union ndn_msft_cmd u; 46 | } __attribute__((packed)); 47 | 48 | #define NDN_MSFT_STATUS_MASK 0xffff 49 | #define NDN_MSFT_STATUS_SUCCESS 0 50 | #define NDN_MSFT_STATUS_NOTSUPP 1 51 | #define NDN_MSFT_STATUS_INVALPARM 2 52 | #define NDN_MSFT_STATUS_I2CERR 3 53 | 54 | #endif /* __NDCTL_MSFT_H__ */ 55 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-freeze-security.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-freeze-security(1) 4 | ======================== 5 | 6 | NAME 7 | ---- 8 | ndctl-freeze-security - Set the given DIMM(s) to reject future security operations 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl freeze-security' [..] [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | Prevent any further security operations on the given DIMMs until the 18 | next reboot. This is used in scenarios where the administrator has 19 | taken all expected security actions for the current boot and wants the 20 | DIMM to enforce / lock the current state. 21 | 22 | EXAMPLES 23 | -------- 24 | 25 | ---- 26 | $ ndctl list -d nmem0 27 | [ 28 | { 29 | "dev":"nmem0", 30 | "id":"cdab-0a-07e0-ffffffff", 31 | "handle":0, 32 | "phys_id":0, 33 | "security":"unlocked" 34 | } 35 | ] 36 | 37 | $ ndctl freeze-security nmem0 38 | security froze 1 nmem. 39 | 40 | $ ndctl list -d nmem0 41 | [ 42 | { 43 | "dev":"nmem0", 44 | "id":"cdab-0a-07e0-ffffffff", 45 | "handle":0, 46 | "phys_id":0, 47 | "security":"unlocked", 48 | "security_frozen":true 49 | }, 50 | ] 51 | 52 | ---- 53 | 54 | OPTIONS 55 | ------- 56 | :: 57 | include::xable-dimm-options.txt[] 58 | 59 | -b:: 60 | --bus=:: 61 | include::xable-bus-options.txt[] 62 | 63 | -v:: 64 | --verbose:: 65 | Emit debug messages. 66 | 67 | include::intel-nvdimm-security.txt[] 68 | 69 | include::../copyright.txt[] 70 | -------------------------------------------------------------------------------- /ccan/minmax/minmax.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_MINMAX_H 3 | #define CCAN_MINMAX_H 4 | 5 | #include "config.h" 6 | 7 | #include 8 | 9 | #if !HAVE_STATEMENT_EXPR || !HAVE_TYPEOF 10 | /* 11 | * Without these, there's no way to avoid unsafe double evaluation of 12 | * the arguments 13 | */ 14 | #error Sorry, minmax module requires statement expressions and typeof 15 | #endif 16 | 17 | #if HAVE_BUILTIN_TYPES_COMPATIBLE_P 18 | #define MINMAX_ASSERT_COMPATIBLE(a, b) \ 19 | BUILD_ASSERT(__builtin_types_compatible_p(a, b)) 20 | #else 21 | #define MINMAX_ASSERT_COMPATIBLE(a, b) \ 22 | do { } while (0) 23 | #endif 24 | 25 | #define min(a, b) \ 26 | ({ \ 27 | typeof(a) _a = (a); \ 28 | typeof(b) _b = (b); \ 29 | MINMAX_ASSERT_COMPATIBLE(typeof(_a), typeof(_b)); \ 30 | _a < _b ? _a : _b; \ 31 | }) 32 | 33 | #define max(a, b) \ 34 | ({ \ 35 | typeof(a) __a = (a); \ 36 | typeof(b) __b = (b); \ 37 | MINMAX_ASSERT_COMPATIBLE(typeof(__a), typeof(__b)); \ 38 | __a > __b ? __a : __b; \ 39 | }) 40 | 41 | #define clamp(v, f, c) (max(min((v), (c)), (f))) 42 | 43 | 44 | #define min_t(t, a, b) \ 45 | ({ \ 46 | t _ta = (a); \ 47 | t _tb = (b); \ 48 | min(_ta, _tb); \ 49 | }) 50 | #define max_t(t, a, b) \ 51 | ({ \ 52 | t _ta = (a); \ 53 | t _tb = (b); \ 54 | max(_ta, _tb); \ 55 | }) 56 | 57 | #define clamp_t(t, v, f, c) \ 58 | ({ \ 59 | t _tv = (v); \ 60 | t _tf = (f); \ 61 | t _tc = (c); \ 62 | clamp(_tv, _tf, _tc); \ 63 | }) 64 | 65 | #endif /* CCAN_MINMAX_H */ 66 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-monitor.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-monitor(1) 4 | ============== 5 | 6 | NAME 7 | ---- 8 | cxl-monitor - Monitor the CXL trace events 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl monitor' [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | cxl-monitor is used for monitoring the CXL trace events emitted by 18 | the kernel and convert them to json objects and dumping the json format 19 | notifications to standard output or a logfile. 20 | 21 | EXAMPLES 22 | -------- 23 | 24 | Run a monitor as a daemon to monitor events and output to a log file. 25 | [verse] 26 | cxl monitor --daemon --log=/var/log/cxl-monitor.log 27 | 28 | Run a monitor as a one-shot command and output the notifications to stdio. 29 | [verse] 30 | cxl monitor 31 | 32 | Run a monitor daemon as a system service 33 | [verse] 34 | systemctl start cxl-monitor.service 35 | 36 | OPTIONS 37 | ------- 38 | -l:: 39 | --log=:: 40 | Send log messages to the specified destination. 41 | - "": 42 | Send log messages to specified . 43 | - "standard": 44 | Send messages to standard output. 45 | 46 | The default log destination is '/var/log/cxl-monitor.log' if "--daemon" is specified, 47 | otherwise 'standard'. Note that standard and relative path for 48 | will not work if "--daemon" is specified. 49 | 50 | --daemon:: 51 | Run a monitor as a daemon. 52 | 53 | include::verbose-option.txt[] 54 | 55 | include::human-option.txt[] 56 | 57 | include::../copyright.txt[] 58 | 59 | SEE ALSO 60 | -------- 61 | linkcxl:cxl-list[1] 62 | -------------------------------------------------------------------------------- /util/parse-configs.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | enum parse_conf_type { 11 | CONFIG_STRING, 12 | CONFIG_SEARCH_SECTION, 13 | CONFIG_END, 14 | MONITOR_CALLBACK, 15 | }; 16 | 17 | int filter_conf_files(const struct dirent *dir); 18 | 19 | struct config; 20 | typedef int parse_conf_cb(const struct config *, const char *config_file); 21 | 22 | struct config { 23 | enum parse_conf_type type; 24 | const char *section; 25 | const char *search_key; 26 | const char *search_val; 27 | const char *get_key; 28 | const char *key; 29 | void *value; 30 | void *defval; 31 | parse_conf_cb *callback; 32 | }; 33 | 34 | #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) 35 | 36 | #define CONF_END() { .type = CONFIG_END } 37 | #define CONF_STR(k,v,d) \ 38 | { .type = CONFIG_STRING, .key = (k), .value = check_vtype(v, const char **), .defval = (d) } 39 | #define CONF_SEARCH(s, sk, sv, gk, v, d) \ 40 | { \ 41 | .type = CONFIG_SEARCH_SECTION, \ 42 | .section = (s), \ 43 | .search_key = (sk), \ 44 | .search_val = (sv), \ 45 | .get_key = (gk), \ 46 | .value = check_vtype(v, const char **), \ 47 | .defval = (d) \ 48 | } 49 | #define CONF_MONITOR(k,f) \ 50 | { .type = MONITOR_CALLBACK, .key = (k), .callback = (f)} 51 | 52 | int parse_configs_prefix(const char *config_path, const char *prefix, 53 | const struct config *configs); 54 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-enable-port.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-enable-port(1) 4 | ================== 5 | 6 | NAME 7 | ---- 8 | cxl-enable-port - activate / hot-add a given CXL port 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl enable-port' [..] [] 14 | 15 | A port typically autoenables at initial device discovery. However, if it 16 | was manually disabled this command can trigger the kernel to activate it 17 | again. This involves detecting the state of the HDM (Host Managed Device 18 | Memory) Decoders and validating that CXL.mem is enabled for each port in 19 | the device's hierarchy. 20 | 21 | include::xable-no-op.txt[] 22 | 23 | OPTIONS 24 | ------- 25 | -e:: 26 | --endpoint:: 27 | Toggle from treating the port arguments as Switch Port identifiers to 28 | Endpoint Port identifiers. 29 | 30 | -m:: 31 | --enable-memdevs:: 32 | Try to enable descendant memdevs after enabling the port. Recall that a 33 | memdev is only enabled after all CXL ports in its device topology 34 | ancestry are enabled. 35 | 36 | Note: The '-m' option requires release v83 or newer when used with 37 | kernel v6.18 or later. Older releases (before v83) will not work 38 | because kernel v6.18 changed how CXL ports and downstream ports are 39 | enumerated. In these newer kernels, the CXL port hierarchy is only 40 | established once the memdev is probed. v83 and later remain fully 41 | compatible with both older and newer kernels. 42 | 43 | include::debug-option.txt[] 44 | 45 | include::../copyright.txt[] 46 | 47 | SEE ALSO 48 | -------- 49 | linkcxl:cxl-disable-port[1] 50 | -------------------------------------------------------------------------------- /ndctl/test.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static char *result(int rc) 10 | { 11 | if (rc == 77) 12 | return "SKIP"; 13 | else if (rc) 14 | return "FAIL"; 15 | else 16 | return "PASS"; 17 | } 18 | 19 | int cmd_test(int argc, const char **argv, struct ndctl_ctx *ctx) 20 | { 21 | struct ndctl_test *test; 22 | int loglevel = LOG_DEBUG, i, rc; 23 | const char * const u[] = { 24 | "ndctl test []", 25 | NULL 26 | }; 27 | bool force = false; 28 | const struct option options[] = { 29 | OPT_INTEGER('l', "loglevel", &loglevel, 30 | "set the log level (default LOG_DEBUG)"), 31 | OPT_BOOLEAN('f', "force", &force, 32 | "force run all tests regardless of required kernel"), 33 | OPT_END(), 34 | }; 35 | 36 | argc = parse_options(argc, argv, options, u, 0); 37 | 38 | for (i = 0; i < argc; i++) 39 | error("unknown parameter \"%s\"\n", argv[i]); 40 | 41 | if (argc) 42 | usage_with_options(u, options); 43 | 44 | if (force) 45 | test = ndctl_test_new(UINT_MAX); 46 | else 47 | test = ndctl_test_new(0); 48 | if (!test) 49 | return EXIT_FAILURE; 50 | 51 | rc = test_libndctl(loglevel, test, ctx); 52 | fprintf(stderr, "test-libndctl: %s\n", result(rc)); 53 | if (rc && rc != 77) 54 | return rc; 55 | 56 | rc = test_dsm_fail(loglevel, test, ctx); 57 | fprintf(stderr, "test-dsm-fail: %s\n", result(rc)); 58 | if (rc && rc != 77) 59 | return rc; 60 | 61 | return ndctl_test_result(test, rc); 62 | } 63 | -------------------------------------------------------------------------------- /Documentation/manpage-base.xsl: -------------------------------------------------------------------------------- 1 | 9 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 26 | 27 | 28 | 29 | sp 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | br 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /cxl/fwctl/cxl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2024-2025 Intel Corporation 4 | * 5 | * These are definitions for the mailbox command interface of CXL subsystem. 6 | */ 7 | #ifndef _UAPI_FWCTL_CXL_H_ 8 | #define _UAPI_FWCTL_CXL_H_ 9 | 10 | #include 11 | #include 12 | #include "features.h" 13 | 14 | /** 15 | * struct fwctl_rpc_cxl - ioctl(FWCTL_RPC) input for CXL 16 | * @opcode: CXL mailbox command opcode 17 | * @flags: Flags for the command (input). 18 | * @op_size: Size of input payload. 19 | * @reserved1: Reserved. Must be 0s. 20 | * @get_sup_feats_in: Get Supported Features input 21 | * @get_feat_in: Get Feature input 22 | * @set_feat_in: Set Feature input 23 | */ 24 | struct fwctl_rpc_cxl { 25 | __struct_group(fwctl_rpc_cxl_hdr, hdr, /* no attrs */, 26 | __u32 opcode; 27 | __u32 flags; 28 | __u32 op_size; 29 | __u32 reserved1; 30 | ); 31 | union { 32 | struct cxl_mbox_get_sup_feats_in get_sup_feats_in; 33 | struct cxl_mbox_get_feat_in get_feat_in; 34 | struct cxl_mbox_set_feat_in set_feat_in; 35 | }; 36 | }; 37 | 38 | /** 39 | * struct fwctl_rpc_cxl_out - ioctl(FWCTL_RPC) output for CXL 40 | * @size: Size of the output payload 41 | * @retval: Return value from device 42 | * @get_sup_feats_out: Get Supported Features output 43 | * @payload: raw byte stream of payload 44 | */ 45 | struct fwctl_rpc_cxl_out { 46 | __struct_group(fwctl_rpc_cxl_out_hdr, hdr, /* no attrs */, 47 | __u32 size; 48 | __u32 retval; 49 | ); 50 | union { 51 | struct cxl_mbox_get_sup_feats_out get_sup_feats_out; 52 | __DECLARE_FLEX_ARRAY(__u8, payload); 53 | }; 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl(1) 4 | ======= 5 | 6 | NAME 7 | ---- 8 | ndctl - Manage "libnvdimm" subsystem devices (Non-volatile Memory) 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl' [--version] [--help] [OPTIONS] COMMAND [ARGS] 14 | 15 | OPTIONS 16 | ------- 17 | -v:: 18 | --version:: 19 | Display ndctl version. 20 | 21 | -h:: 22 | --help:: 23 | Run ndctl help command. 24 | 25 | DESCRIPTION 26 | ----------- 27 | ndctl is utility for managing the "libnvdimm" kernel subsystem. 28 | The "libnvdimm" subsystem defines a kernel device model and control 29 | message interface for platform NVDIMM resources like those defined by 30 | the ACPI 6.0 NFIT (NVDIMM Firmware Interface Table). Operations 31 | supported by the tool include, provisioning capacity (namespaces), as 32 | well as enumerating/enabling/disabling the devices (dimms, regions, 33 | namespaces) associated with an NVDIMM bus. 34 | 35 | include::../copyright.txt[] 36 | 37 | SEE ALSO 38 | -------- 39 | linkndctl:ndctl-create-namespace[1], 40 | linkndctl:ndctl-destroy-namespace[1], 41 | linkndctl:ndctl-check-namespace[1], 42 | linkndctl:ndctl-enable-region[1], 43 | linkndctl:ndctl-disable-region[1], 44 | linkndctl:ndctl-enable-dimm[1], 45 | linkndctl:ndctl-disable-dimm[1], 46 | linkndctl:ndctl-enable-namespace[1], 47 | linkndctl:ndctl-disable-namespace[1], 48 | linkndctl:ndctl-zero-labels[1], 49 | linkndctl:ndctl-read-labels[1], 50 | linkndctl:ndctl-inject-error[1], 51 | linkndctl:ndctl-list[1], 52 | https://www.kernel.org/doc/Documentation/nvdimm/nvdimm.txt[LIBNVDIMM 53 | Overview], 54 | http://pmem.io/documents/NVDIMM_Driver_Writers_Guide.pdf[NVDIMM Driver 55 | Writer's Guide] 56 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-update-passphrase.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-update-passphrase(1) 4 | ========================== 5 | 6 | NAME 7 | ---- 8 | ndctl-update-passphrase - update the security passphrase for an NVDIMM 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl update-passphrase' [..] [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | Update the security passphrase for one or more NVDIMMs. 18 | Prerequisites for command to succeed: 19 | 20 | . The 'kek' has been loaded into the kernel's user keyring. 21 | . setup-passphrase has successfully been executed on the NVDIMM. 22 | * Alternatively, the NVDIMM is unlocked. 23 | 24 | The updated key blobs will be created in the {ndctl_keysdir} directory 25 | with a file name format of "nvdimm__.blob". 26 | 27 | OPTIONS 28 | ------- 29 | :: 30 | include::xable-dimm-options.txt[] 31 | 32 | -b:: 33 | --bus=:: 34 | include::xable-bus-options.txt[] 35 | 36 | -k:: 37 | --key_handle=:: 38 | Handle for the master 'kek' (key-encryption-key) that will be used for 39 | sealing the passphrase(s) for the given DIMM(s). The format is: 40 | `:` 41 | e.g. `trusted:nvdimm-master` + 42 | NOTE: The 'kek' is expected to have been loaded into the user keyring. 43 | 44 | -m:: 45 | --master-passphrase:: 46 | Indicates that we are managing the master passphrase instead of the 47 | user passphrase. 48 | 49 | -v:: 50 | --verbose:: 51 | Emit debug messages. 52 | 53 | include::intel-nvdimm-security.txt[] 54 | 55 | include::../copyright.txt[] 56 | 57 | SEE ALSO: 58 | --------- 59 | linkndctl:ndctl-setup-passphrase[1], linkndctl:ndctl-remove-passphrase[1] 60 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-free-dpa.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-free-dpa(1) 4 | =============== 5 | 6 | NAME 7 | ---- 8 | cxl-free-dpa - release device-physical address space 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl free-dpa' [..] [] 14 | 15 | The CXL region provisioning process proceeds in multiple steps. One of 16 | the steps is identifying and reserving the DPA span that each member of 17 | the interleave-set (region) contributes in advance of attaching that 18 | allocation to a region. For development, test, and debug purposes this 19 | command is a helper to find the last allocated decoder on a device and 20 | zero-out / free its DPA allocation. 21 | 22 | OPTIONS 23 | ------- 24 | :: 25 | include::memdev-option.txt[] 26 | 27 | include::bus-option.txt[] 28 | 29 | -d:: 30 | --decoder:: 31 | Specify the decoder to free. The CXL specification 32 | mandates that DPA must be released in the reverse order it was 33 | allocated. See linkcxl:cxl-reserve-dpa[1] 34 | 35 | -t:: 36 | --type:: 37 | Constrain the search for "last allocated decoder" to decoders targeting 38 | the given partition. 39 | 40 | -f:: 41 | --force:: 42 | The kernel enforces CXL DPA ordering constraints on deallocation events, 43 | and the tool anticipates those and fails operations that are expected to 44 | fail without sending them to the kernel. For test purposes, continue to 45 | attempt "expected to fail" operations to exercise the driver. 46 | 47 | -v:: 48 | Turn on verbose debug messages in the library (if libcxl was built with 49 | logging and debug enabled). 50 | 51 | include::../copyright.txt[] 52 | 53 | SEE ALSO 54 | -------- 55 | linkcxl:cxl-reserve-dpa[1] 56 | -------------------------------------------------------------------------------- /test/cxl-labels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2022 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname $0)/common 6 | 7 | rc=77 8 | 9 | set -ex 10 | 11 | trap 'err $LINENO' ERR 12 | 13 | check_prereq "jq" 14 | 15 | modprobe -r cxl_test 16 | modprobe cxl_test 17 | rc=1 18 | 19 | test_label_ops() 20 | { 21 | nmem="$1" 22 | lsa=$(mktemp /tmp/lsa-$nmem.XXXX) 23 | lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) 24 | 25 | # determine LSA size 26 | "$NDCTL" read-labels -o "$lsa_read" "$nmem" 27 | lsa_size=$(stat -c %s "$lsa_read") 28 | 29 | dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" 30 | "$NDCTL" write-labels -i "$lsa" "$nmem" 31 | "$NDCTL" read-labels -o "$lsa_read" "$nmem" 32 | 33 | # compare what was written vs read 34 | diff "$lsa" "$lsa_read" 35 | 36 | # zero the LSA and test 37 | "$NDCTL" zero-labels "$nmem" 38 | dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" 39 | "$NDCTL" read-labels -o "$lsa_read" "$nmem" 40 | diff "$lsa" "$lsa_read" 41 | 42 | # cleanup 43 | rm "$lsa" "$lsa_read" 44 | } 45 | 46 | test_label_ops_cxl() 47 | { 48 | mem="$1" 49 | lsa_read=$(mktemp /tmp/lsa-read-$mem.XXXX) 50 | 51 | "$CXL" read-labels -o "$lsa_read" "$mem" 52 | rm "$lsa_read" 53 | } 54 | 55 | # test reading labels directly through cxl-cli 56 | readarray -t mems < <("$CXL" list -b cxl_test -Mi | jq -r '.[].memdev') 57 | 58 | for mem in ${mems[@]}; do 59 | test_label_ops_cxl "$mem" 60 | done 61 | 62 | # find nmem devices corresponding to cxl memdevs 63 | readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev') 64 | 65 | for nmem in ${nmems[@]}; do 66 | test_label_ops "$nmem" 67 | done 68 | 69 | check_dmesg "$LINENO" 70 | 71 | modprobe -r cxl_test 72 | -------------------------------------------------------------------------------- /ndctl/meson.build: -------------------------------------------------------------------------------- 1 | ndctl_src = [ 2 | 'ndctl.c', 3 | 'bus.c', 4 | 'create-nfit.c', 5 | 'namespace.c', 6 | 'check.c', 7 | 'region.c', 8 | 'dimm.c', 9 | '../daxctl/filter.c', 10 | 'filter.c', 11 | 'list.c', 12 | '../daxctl/json.c', 13 | 'json.c', 14 | 'json-smart.c', 15 | 'inject-error.c', 16 | 'inject-smart.c', 17 | 'monitor.c', 18 | ] 19 | 20 | deps = [ 21 | util_dep, 22 | ndctl_dep, 23 | daxctl_dep, 24 | cxl_dep, 25 | uuid, 26 | kmod, 27 | json, 28 | versiondep, 29 | ] 30 | 31 | if get_option('keyutils').enabled() 32 | ndctl_src += [ 33 | 'keys.c', 34 | 'load-keys.c', 35 | ] 36 | deps += keyutils 37 | endif 38 | 39 | if get_option('test').enabled() 40 | ndctl_src += [ 41 | '../test/libndctl.c', 42 | '../test/dsm-fail.c', 43 | '../util/sysfs.c', 44 | '../test/core.c', 45 | 'test.c', 46 | ] 47 | endif 48 | 49 | if get_option('destructive').enabled() 50 | if get_option('test').disabled() 51 | error('\'-D=destructive=enabled\' requires \'-Dtest=enabled\'\n') 52 | endif 53 | ndctl_src += [ 54 | '../test/pmem_namespaces.c', 55 | 'bat.c', 56 | ] 57 | endif 58 | 59 | if get_option('systemd').enabled() 60 | install_data('ndctl-monitor.service', install_dir : systemdunitdir) 61 | endif 62 | install_data('monitor.conf', install_dir : ndctlconf_dir) 63 | install_data('ndctl.conf', install_dir : ndctlconf_dir) 64 | install_data('keys.readme', install_dir : ndctlkeys_dir) 65 | 66 | ndctl_tool = executable('ndctl', ndctl_src, 67 | dependencies : deps, 68 | install : true, 69 | install_dir : rootbindir, 70 | include_directories : root_inc, 71 | ) 72 | 73 | install_headers( 74 | [ 75 | 'libndctl.h', 76 | 'ndctl.h' 77 | ], 78 | subdir : 'ndctl' 79 | ) 80 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-start-scrub.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-start-scrub(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-start-scrub - start an Address Range Scrub (ARS) operation 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl start-scrub' [ ... ] [] 14 | 15 | include::ars-description.txt[] 16 | 17 | The kernel provides a sysfs file ('scrub') that when written with the 18 | string "1\n" initiates an ARS operation. The 'ndctl start-scrub' 19 | operation starts an ARS, across all specified buses, and the kernel in 20 | turn proceeds to scrub every persistent memory address region on the 21 | specified buses. 22 | 23 | EXAMPLE 24 | ------- 25 | Start a scrub on all nvdimm buses in the system. The json listing report 26 | only includes the buses that support ARS operations. 27 | ---- 28 | 29 | # ndctl start-scrub 30 | [ 31 | { 32 | "provider":"nfit_test.1", 33 | "dev":"ndbus3", 34 | "scrub_state":"active" 35 | }, 36 | { 37 | "provider":"nfit_test.0", 38 | "dev":"ndbus2", 39 | "scrub_state":"active" 40 | } 41 | ] 42 | ---- 43 | 44 | When specifying an individual bus, or if there is only one bus in the 45 | system, the command reports whether ARS support is available. 46 | ---- 47 | # ndctl start-scrub e820 48 | error starting scrub: Operation not supported 49 | ---- 50 | 51 | OPTIONS 52 | ------- 53 | -v:: 54 | --verbose:: 55 | Emit debug messages for the ARS start process 56 | 57 | include::../copyright.txt[] 58 | 59 | SEE ALSO 60 | -------- 61 | linkndctl:ndctl-wait-scrub[1], 62 | http://www.uefi.org/sites/default/files/resources/ACPI%206_2_A_Sept29.pdf[ACPI 63 | 6.2 Specification Section 9.20.7.2 Address Range Scrubbing (ARS) Overview] 64 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-load-keys.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-load-keys(1) 4 | ================== 5 | 6 | NAME 7 | ---- 8 | ndctl-load-keys - load the kek and encrypted passphrases into the keyring 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl load-keys' [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | The 'load-keys' command loads the master key ('kek') and the encrypted 18 | passphrases for all NVDIMMs into the user keyring maintained by the kernel. 19 | The command is expected to be called during initialization and before the 20 | libnvdimm kernel module is loaded, typically from an initrd. This is typically 21 | set up using a modprobe config that calls the command before module load. 22 | 23 | NOTE: All key files are expected to be in the format: nvdimm__hostname + 24 | The `'_`' character is used to delimit the different components in the file name. 25 | Within the hostname, the `'_`' character is allowed since it is the last component 26 | of the file name. 27 | 28 | NOTE: This command is typically never called directly by a user. 29 | 30 | OPTIONS 31 | ------- 32 | -p:: 33 | --key-path=:: 34 | Path to where key related files reside. This parameter is optional 35 | and the default location is {ndctl_keysdir}. 36 | 37 | -t:: 38 | --tpm-handle=:: 39 | Provide a TPM handle (should be a string such as 0x81000001). 40 | If the key path ({ndctl_keysdir}) contains a file called tpm.handle 41 | which contains the handle string, then this option may be left out, 42 | and the tpm handle will be obtained from the file. If both are present, 43 | then this option will override (but not overwrite) anything that is 44 | in the file. 45 | 46 | include::intel-nvdimm-security.txt[] 47 | 48 | include::../copyright.txt[] 49 | -------------------------------------------------------------------------------- /util/json.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef __UTIL_JSON_H__ 4 | #define __UTIL_JSON_H__ 5 | #include 6 | #include 7 | #include 8 | 9 | enum util_json_flags { 10 | UTIL_JSON_IDLE = (1 << 0), 11 | UTIL_JSON_MEDIA_ERRORS = (1 << 1), 12 | UTIL_JSON_DAX = (1 << 2), 13 | UTIL_JSON_DAX_DEVS = (1 << 3), 14 | UTIL_JSON_HUMAN = (1 << 4), 15 | UTIL_JSON_VERBOSE = (1 << 5), 16 | UTIL_JSON_CAPABILITIES = (1 << 6), 17 | UTIL_JSON_CONFIGURED = (1 << 7), 18 | UTIL_JSON_FIRMWARE = (1 << 8), 19 | UTIL_JSON_DAX_MAPPINGS = (1 << 9), 20 | UTIL_JSON_HEALTH = (1 << 10), 21 | UTIL_JSON_TARGETS = (1 << 11), 22 | UTIL_JSON_PARTITION = (1 << 12), 23 | UTIL_JSON_ALERT_CONFIG = (1 << 13), 24 | }; 25 | 26 | void util_display_json_array(FILE *f_out, struct json_object *jarray, 27 | unsigned long flags); 28 | struct json_object *util_json_object_size(unsigned long long size, 29 | unsigned long flags); 30 | struct json_object *util_json_object_hex(unsigned long long val, 31 | unsigned long flags); 32 | #if HAVE_JSON_U64 33 | static inline struct json_object *util_json_new_u64(unsigned long long val) 34 | { 35 | return json_object_new_uint64(val); 36 | } 37 | 38 | static inline unsigned long long util_json_get_u64(struct json_object *jobj) 39 | { 40 | return json_object_get_uint64(jobj); 41 | } 42 | 43 | #else /* fallback to signed */ 44 | static inline struct json_object *util_json_new_u64(unsigned long long val) 45 | { 46 | return json_object_new_int64(val); 47 | } 48 | 49 | static inline unsigned long long util_json_get_u64(struct json_object *jobj) 50 | { 51 | return json_object_get_int64(jobj); 52 | } 53 | 54 | #endif /* HAVE_JSON_U64 */ 55 | #endif /* __UTIL_JSON_H__ */ 56 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-wait-scrub.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-wait-scrub(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-wait-scrub - wait for an Address Range Scrub (ARS) operation to complete 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl wait-scrub' [ ... ] [] 14 | 15 | include::ars-description.txt[] 16 | 17 | The kernel provides a POLL(2) capable sysfs file ('scrub') to indicate 18 | the state of ARS. The 'scrub' file maintains a running count of ARS runs 19 | that have taken place. While a current run is in progress a '+' 20 | character is emitted along with the current count. The 'ndctl 21 | wait-scrub' operation waits for 'scrub', across all specified buses, to 22 | indicate not in-progress at least once. 23 | 24 | EXAMPLE 25 | ------- 26 | Wait for scrub on all nvdimm buses in the system. The json listing 27 | report at the end only includes the buses that support ARS operations. 28 | ---- 29 | # ndctl wait-scrub 30 | [ 31 | { 32 | "provider":"nfit_test.1", 33 | "dev":"ndbus3", 34 | "scrub_state":"idle" 35 | }, 36 | { 37 | "provider":"nfit_test.0", 38 | "dev":"ndbus2", 39 | "scrub_state":"idle" 40 | } 41 | ] 42 | ---- 43 | 44 | When specifying an individual bus, or if there is only one bus in the 45 | system, the command reports whether ARS support is available. 46 | ---- 47 | # ndctl wait-scrub e820 48 | error waiting for scrub completion: Operation not supported 49 | ---- 50 | 51 | OPTIONS 52 | ------- 53 | -v:: 54 | --verbose:: 55 | Emit debug messages for the ARS wait process 56 | 57 | include::../copyright.txt[] 58 | 59 | SEE ALSO 60 | -------- 61 | linkndctl:ndctl-start-scrub[1], 62 | http://www.uefi.org/sites/default/files/resources/ACPI%206_2_A_Sept29.pdf[ACPI 63 | 6.2 Specification Section 9.20.7.2 Address Range Scrubbing (ARS) Overview] 64 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('version-tag', type : 'string', 2 | description : 'override the git version string') 3 | option('docs', type : 'feature', value : 'enabled') 4 | option('asciidoctor', type : 'feature', value : 'enabled') 5 | option('libtracefs', type : 'feature', value : 'enabled') 6 | option('systemd', type : 'feature', value : 'enabled') 7 | option('keyutils', type : 'feature', value : 'enabled', 8 | description : 'enable nvdimm device passphrase management') 9 | option('test', type : 'feature', value : 'disabled', 10 | description : 'enable shipping tests in ndctl') 11 | option('destructive', type : 'feature', value : 'disabled', 12 | description : 'enable tests that may clobber live system resources') 13 | option('poison', type : 'feature', value : 'enabled', 14 | description : 'enable tests that inject poison / memory-failure') 15 | option('logging', type : 'feature', value : 'enabled', 16 | description : 'enable log infrastructure') 17 | option('dbg', type : 'feature', value : 'enabled', 18 | description : 'enable dbg messages') 19 | option('rootprefix', type : 'string', 20 | description : '''override the root prefix [default '/' if split-usr and '/usr' otherwise]''') 21 | option('rootlibdir', type : 'string', 22 | description : '''[/usr]/lib/x86_64-linux-gnu or such''') 23 | option('pkgconfiglibdir', type : 'string', value : '', 24 | description : 'directory for standard pkg-config files') 25 | option('bashcompletiondir', type : 'string', 26 | description : '''${datadir}/bash-completion/completions''') 27 | option('iniparserdir', type : 'string', 28 | description : 'Path containing the iniparser header files') 29 | option('modprobedatadir', type : 'string', 30 | description : '''${sysconfdir}/modprobe.d/''') 31 | option('fwctl', type : 'feature', value : 'enabled', 32 | description : 'enable firmware control') 33 | -------------------------------------------------------------------------------- /test/dm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | SKIP=77 8 | FAIL=1 9 | SUCCESS=0 10 | 11 | . $(dirname $0)/common 12 | 13 | MNT=test_dax_mnt 14 | TEST_DM_PMEM=/dev/mapper/test_pmem 15 | NAME=$(basename $TEST_DM_PMEM) 16 | 17 | mkdir -p $MNT 18 | 19 | TEST_SIZE=$((1<<30)) 20 | 21 | rc=$FAIL 22 | cleanup() { 23 | if [ $rc -ne $SUCCESS ]; then 24 | echo "test/dm.sh: failed at line $1" 25 | fi 26 | if mountpoint -q $MNT; then 27 | umount $MNT 28 | fi 29 | 30 | if [ -L $TEST_DM_PMEM ]; then 31 | dmsetup remove $TEST_DM_PMEM 32 | fi 33 | rm -rf $MNT 34 | # opportunistic cleanup, not fatal if these fail 35 | namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") 36 | for i in $namespaces 37 | do 38 | if ! $NDCTL destroy-namespace -f $i; then 39 | echo "test/dm.sh: cleanup() failed to destroy $i" 40 | fi 41 | done 42 | exit $rc 43 | } 44 | 45 | trap 'err $LINENO cleanup' ERR 46 | 47 | dev="x" 48 | json=$($NDCTL create-namespace -b ACPI.NFIT -s $TEST_SIZE -t pmem -m fsdax -n "$NAME") 49 | eval $(echo $json | json2var ) 50 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 51 | [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 52 | 53 | pmem0=/dev/$blockdev 54 | size0=$((size/512)) 55 | 56 | json=$($NDCTL create-namespace -b ACPI.NFIT -s $TEST_SIZE -t pmem -m fsdax -n "$NAME") 57 | eval $(echo $json | json2var ) 58 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 59 | [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 60 | 61 | pmem1=/dev/$blockdev 62 | size1=$((size/512)) 63 | 64 | cat < 7 | 8 | typedef void *(*add_dev_fn)(void *parent, int id, const char *dev_path); 9 | 10 | #define SYSFS_ATTR_SIZE 1024 11 | 12 | struct log_ctx; 13 | int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf); 14 | int __sysfs_write_attr(struct log_ctx *ctx, const char *path, const char *buf); 15 | int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path, 16 | const char *buf); 17 | int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, 18 | const char *dev_name, void *parent, add_dev_fn add_dev); 19 | 20 | #define sysfs_read_attr(c, p, b) __sysfs_read_attr(&(c)->ctx, (p), (b)) 21 | #define sysfs_write_attr(c, p, b) __sysfs_write_attr(&(c)->ctx, (p), (b)) 22 | #define sysfs_write_attr_quiet(c, p, b) __sysfs_write_attr_quiet(&(c)->ctx, (p), (b)) 23 | #define sysfs_device_parse(c, b, d, p, fn) __sysfs_device_parse(&(c)->ctx, \ 24 | (b), (d), (p), (fn)) 25 | 26 | static inline const char *devpath_to_devname(const char *devpath) 27 | { 28 | return strrchr(devpath, '/') + 1; 29 | } 30 | 31 | struct kmod_ctx; 32 | struct kmod_module; 33 | struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx, 34 | const char *alias, 35 | struct log_ctx *log); 36 | #define util_modalias_to_module(ctx, buf) \ 37 | __util_modalias_to_module((ctx)->kmod_ctx, buf, &(ctx)->ctx) 38 | 39 | int __util_bind(const char *devname, struct kmod_module *module, const char *bus, 40 | struct log_ctx *ctx); 41 | #define util_bind(n, m, b, c) __util_bind(n, m, b, &(c)->ctx) 42 | 43 | int __util_unbind(const char *devpath, struct log_ctx *ctx); 44 | #define util_unbind(p, c) __util_unbind(p, &(c)->ctx) 45 | 46 | #endif /* __UTIL_SYSFS_H__ */ 47 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-setup-passphrase.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-setup-passphrase(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | ndctl-setup-passphrase - setup and enable the security passphrase for an NVDIMM 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl setup-passphrase' [..] -k [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | Setup and enable a security passphrase for one or more NVDIMMs. 18 | 19 | For this command to succeed, it is expected that the master key has previously 20 | been loaded into the user keyring. More information on how this can be done 21 | can be found in the kernel documentation at: 22 | https://www.kernel.org/doc/html/latest/security/keys/trusted-encrypted.html 23 | 24 | The passphrase blobs are created in the {ndctl_keysdir} directory with a file 25 | name format of `"nvdimm__.blob"` 26 | 27 | The command will fail if the passphrase is already in the user keyring or if 28 | a passphrase blob already exists in {ndctl_keysdir}. 29 | 30 | OPTIONS 31 | ------- 32 | :: 33 | include::xable-dimm-options.txt[] 34 | 35 | -b:: 36 | --bus=:: 37 | include::xable-bus-options.txt[] 38 | 39 | -k:: 40 | --key_handle=:: 41 | Handle for the master 'kek' (key-encryption-key) that will be used for 42 | sealing the passphrase(s) for the given DIMM(s). The format is: 43 | `:` 44 | e.g. `trusted:nvdimm-master` + 45 | NOTE: The 'kek' is expected to have been loaded into the user keyring. 46 | 47 | -m:: 48 | --master-passphrase:: 49 | Indicates that we are managing the master passphrase instead of the 50 | user passphrase. 51 | 52 | -v:: 53 | --verbose:: 54 | Emit debug messages. 55 | 56 | include::intel-nvdimm-security.txt[] 57 | 58 | include::../copyright.txt[] 59 | 60 | SEE ALSO: 61 | --------- 62 | linkndctl:ndctl-update-passphrase[1], linkndctl:ndctl-remove-passphrase[1] 63 | -------------------------------------------------------------------------------- /test/rescan-partitions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2018-2020 Intel Corporation. All rights reserved. 4 | 5 | dev="" 6 | size="" 7 | blockdev="" 8 | rc=77 9 | 10 | . $(dirname $0)/common 11 | 12 | trap 'err $LINENO' ERR 13 | 14 | # sample json: 15 | #{ 16 | # "dev":"namespace5.0", 17 | # "mode":"sector", 18 | # "size":"60.00 MiB (62.92 MB)", 19 | # "uuid":"f1baa71a-d165-4da4-bb6a-083a2b0e6469", 20 | # "blockdev":"pmem5s", 21 | #} 22 | 23 | check_min_kver "4.16" || do_skip "may not contain fixes for partition rescanning" 24 | 25 | check_prereq "parted" 26 | check_prereq "blockdev" 27 | check_prereq "jq" 28 | 29 | test_mode() 30 | { 31 | local mode="$1" 32 | 33 | # create namespace 34 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m "$mode") 35 | rc=2 36 | eval "$(echo "$json" | json2var)" 37 | [ -n "$dev" ] || err "$LINENO" 38 | [ -n "$size" ] || err "$LINENO" 39 | [ -n "$blockdev" ] || err "$LINENO" 40 | [ $size -gt 0 ] || err "$LINENO" 41 | 42 | rc=1 43 | # create partition 44 | parted --script /dev/$blockdev mklabel gpt mkpart primary 1MiB 10MiB 45 | 46 | # verify it is created 47 | sleep 1 48 | blockdev --rereadpt /dev/$blockdev 49 | sleep 1 50 | partdev=$(lsblk -J -o NAME,SIZE /dev/$blockdev | 51 | jq -r '.blockdevices[] | .children[0] | .name') 52 | 53 | test -b /dev/$partdev 54 | 55 | # cycle the namespace, and verify the partition is read 56 | # without needing to do a blockdev --rereadpt 57 | $NDCTL disable-namespace $dev 58 | $NDCTL enable-namespace $dev 59 | if [ -b /dev/$partdev ]; then 60 | echo "mode: $mode - partition read successful" 61 | else 62 | echo "mode: $mode - partition read failed" 63 | rc=1 64 | err "$LINENO" 65 | fi 66 | 67 | $NDCTL disable-namespace $dev 68 | $NDCTL destroy-namespace $dev 69 | } 70 | 71 | modprobe nfit_test 72 | rc=1 73 | reset 74 | test_mode "raw" 75 | test_mode "fsdax" 76 | test_mode "sector" 77 | _cleanup 78 | exit 0 79 | -------------------------------------------------------------------------------- /ndctl/keys.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2019-2020 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef _NDCTL_UTIL_KEYS_H_ 5 | #define _NDCTL_UTIL_KEYS_H_ 6 | 7 | enum ndctl_key_type { 8 | ND_USER_KEY, 9 | ND_USER_OLD_KEY, 10 | ND_MASTER_KEY, 11 | ND_MASTER_OLD_KEY, 12 | ND_ZERO_KEY, 13 | }; 14 | 15 | enum key_type { 16 | KEY_USER = 0, 17 | KEY_TRUSTED, 18 | KEY_ENCRYPTED, 19 | }; 20 | 21 | #ifdef ENABLE_KEYUTILS 22 | char *ndctl_load_key_blob(const char *path, int *size, const char *postfix, 23 | int dirfd, enum key_type key_type); 24 | int ndctl_dimm_setup_key(struct ndctl_dimm *dimm, const char *kek, 25 | enum ndctl_key_type key_type); 26 | int ndctl_dimm_update_key(struct ndctl_dimm *dimm, const char *kek, 27 | enum ndctl_key_type key_type); 28 | int ndctl_dimm_remove_key(struct ndctl_dimm *dimm, 29 | enum ndctl_key_type key_type); 30 | int ndctl_dimm_secure_erase_key(struct ndctl_dimm *dimm, 31 | enum ndctl_key_type key_type); 32 | int ndctl_dimm_overwrite_key(struct ndctl_dimm *dimm); 33 | #else 34 | char *ndctl_load_key_blob(const char *path, int *size, const char *postfix, 35 | int dirfd, enum key_type key_type) 36 | { 37 | return NULL; 38 | } 39 | static inline int ndctl_dimm_setup_key(struct ndctl_dimm *dimm, 40 | const char *kek, enum ndctl_key_type key_type) 41 | { 42 | return -EOPNOTSUPP; 43 | } 44 | 45 | static inline int ndctl_dimm_update_key(struct ndctl_dimm *dimm, 46 | const char *kek, enum ndctl_key_type key_type) 47 | { 48 | return -EOPNOTSUPP; 49 | } 50 | 51 | static inline int ndctl_dimm_remove_key(struct ndctl_dimm *dimm) 52 | { 53 | return -EOPNOTSUPP; 54 | } 55 | 56 | static inline int ndctl_dimm_secure_erase_key(struct ndctl_dimm *dimm, 57 | enum ndctl_key_type key_type) 58 | { 59 | return -EOPNOTSUPP; 60 | } 61 | 62 | static inline int ndctl_dimm_overwrite_key(struct ndctl_dimm *dimm) 63 | { 64 | return -EOPNOTSUPP; 65 | } 66 | #endif /* ENABLE_KEYUTILS */ 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /test/pfn-meta-errors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2018-2020 Intel Corporation. All rights reserved. 4 | 5 | blockdev="" 6 | rc=77 7 | 8 | . $(dirname $0)/common 9 | 10 | force_raw() 11 | { 12 | raw="$1" 13 | $NDCTL disable-namespace "$dev" 14 | echo "$raw" > "/sys/bus/nd/devices/$dev/force_raw" 15 | $NDCTL enable-namespace "$dev" 16 | echo "Set $dev to raw mode: $raw" 17 | if [[ "$raw" == "1" ]]; then 18 | raw_bdev=${blockdev} 19 | test -b "/dev/$raw_bdev" 20 | else 21 | raw_bdev="" 22 | fi 23 | } 24 | 25 | check_min_kver "4.20" || do_skip "may lack PFN metadata error handling" 26 | 27 | set -e 28 | trap 'err $LINENO' ERR 29 | 30 | # setup (reset nfit_test dimms) 31 | modprobe nfit_test 32 | reset 33 | 34 | rc=1 35 | 36 | # create a fsdax namespace and clear errors (if any) 37 | dev="x" 38 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m fsdax) 39 | eval "$(echo "$json" | json2var)" 40 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 41 | 42 | force_raw 1 43 | if read -r sector len < "/sys/block/$raw_bdev/badblocks"; then 44 | dd of=/dev/$raw_bdev if=/dev/zero oflag=direct bs=512 seek="$sector" count="$len" 45 | fi 46 | force_raw 0 47 | 48 | # find dataoff from sb 49 | force_raw 1 50 | doff=$(hexdump -s $((4096 + 56)) -n 4 "/dev/$raw_bdev" | head -1 | cut -d' ' -f2-) 51 | doff=$(tr -d ' ' <<< "0x${doff#* }${doff%% *}") 52 | printf "pfn dataoff: %x\n" "$doff" 53 | dblk="$((doff/512))" 54 | 55 | metaoff="0x2000" 56 | mblk="$((metaoff/512))" 57 | 58 | # inject in the middle of the struct page area 59 | bb_inj=$(((dblk - mblk)/2)) 60 | $NDCTL inject-error --block="$bb_inj" --count=32 $dev 61 | $NDCTL start-scrub $NFIT_TEST_BUS0 && $NDCTL wait-scrub $NFIT_TEST_BUS0 62 | 63 | # after probe from the enable-namespace, the error should've been cleared 64 | force_raw 0 65 | force_raw 1 66 | if read -r sector len < "/sys/block/$raw_bdev/badblocks"; then 67 | false 68 | fi 69 | 70 | _cleanup 71 | exit 0 72 | -------------------------------------------------------------------------------- /util/event_trace.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2022 Intel Corporation. All rights reserved. */ 3 | #ifndef __UTIL_EVENT_TRACE_H__ 4 | #define __UTIL_EVENT_TRACE_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef ENABLE_LIBTRACEFS 11 | #include 12 | 13 | struct jlist_node { 14 | struct json_object *jobj; 15 | struct list_node list; 16 | }; 17 | 18 | struct cxl_poison_ctx { 19 | struct json_object *jpoison; 20 | struct cxl_region *region; 21 | struct cxl_memdev *memdev; 22 | }; 23 | 24 | struct event_ctx { 25 | const char *system; 26 | struct list_head jlist_head; 27 | const char *event_name; /* optional */ 28 | int event_pid; /* optional */ 29 | struct cxl_poison_ctx *poison_ctx; /* optional */ 30 | unsigned long json_flags; 31 | int (*parse_event)(struct tep_event *event, struct tep_record *record, 32 | struct event_ctx *ctx); 33 | }; 34 | 35 | int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx); 36 | int trace_event_enable(struct tracefs_instance *inst, const char *system, 37 | const char *event); 38 | int trace_event_disable(struct tracefs_instance *inst); 39 | u8 trace_get_field_u8(struct tep_event *event, struct tep_record *record, 40 | const char *name); 41 | u32 trace_get_field_u32(struct tep_event *event, struct tep_record *record, 42 | const char *name); 43 | u64 trace_get_field_u64(struct tep_event *event, struct tep_record *record, 44 | const char *name); 45 | struct json_object *util_cxl_poison_list_to_json(struct cxl_region *region, 46 | struct cxl_memdev *memdev, unsigned long flags); 47 | #else 48 | struct json_object *util_cxl_poison_list_to_json(struct cxl_region *region, 49 | struct cxl_memdev *memdev, unsigned long flags) 50 | { 51 | fprintf(stderr, "cxl list --media-errors support disabled at build time\n"); 52 | return NULL; 53 | } 54 | #endif /* ENABLE_LIBTRACEFS */ 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /test/cxl-sanitize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2022 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname $0)/common 6 | 7 | rc=77 8 | 9 | set -ex 10 | 11 | trap 'err $LINENO' ERR 12 | 13 | check_prereq "jq" 14 | 15 | modprobe -r cxl_test 16 | modprobe cxl_test 17 | rc=1 18 | 19 | # THEORY OF OPERATION: Find a memdev with programmed decoders, validate 20 | # that sanitize requests fail. Find a memdev without programmed 21 | # decoders, validate that submission succeeds, and validate that the 22 | # notifier fires. 23 | 24 | mem_to_host() 25 | { 26 | host=$("$CXL" list -m $1 | jq -r '.[].host') 27 | echo $host 28 | } 29 | 30 | set_timeout() 31 | { 32 | host=$(mem_to_host $1) 33 | echo $2 > /sys/bus/platform/devices/$host/sanitize_timeout 34 | } 35 | 36 | # find all memdevs 37 | readarray -t all_mem < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev') 38 | 39 | # try to sanitize an active memdev 40 | readarray -t active_mem < <("$CXL" list -b cxl_test -RT | jq -r '.[].mappings[].memdev') 41 | count=${#active_mem[@]} 42 | ((count > 0)) || err $LINENO 43 | 44 | # set timeout to 2 seconds 45 | set_timeout ${active_mem[0]} 2000 46 | 47 | # sanitize with an active memdev should fail 48 | echo 1 > /sys/bus/cxl/devices/${active_mem[0]}/security/sanitize && err $LINENO 49 | 50 | # find an inactive mem 51 | inactive="" 52 | for mem in ${all_mem[@]}; do 53 | inactive=$mem 54 | for active in ${active_mem[@]}; do 55 | if [ $mem = $active ]; then 56 | inactive="" 57 | fi 58 | done 59 | if [ -z $inactive ]; then 60 | continue; 61 | fi 62 | break 63 | done 64 | [ -z $inactive ] && err $LINENO 65 | 66 | # kickoff a background sanitize and make sure the wait takes a couple 67 | # secounds 68 | set_timeout $inactive 3000 69 | start=$SECONDS 70 | echo 1 > /sys/bus/cxl/devices/${inactive}/security/sanitize & 71 | "$CXL" wait-sanitize $inactive || err $LINENO 72 | ((SECONDS > start + 2)) || err $LINENO 73 | 74 | check_dmesg "$LINENO" 75 | 76 | modprobe -r cxl_test 77 | -------------------------------------------------------------------------------- /test/sub-section.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | SKIP=77 8 | FAIL=1 9 | SUCCESS=0 10 | 11 | . $(dirname $0)/common 12 | 13 | check_min_kver "5.3" || do_skip "may lack align sub-section hotplug support" 14 | 15 | MNT=test_dax_mnt 16 | mkdir -p $MNT 17 | 18 | TEST_SIZE=$((16<<20)) 19 | MIN_AVAIL=$((TEST_SIZE*4)) 20 | MAX_NS=10 21 | NAME="subsection-test" 22 | 23 | $NDCTL list -N | jq -r ".[] | select(.name==\"subsection-test\") | .dev" 24 | 25 | rc=$FAIL 26 | cleanup() { 27 | if [ $rc -ne $SUCCESS ]; then 28 | echo "test/sub-section.sh: failed at line $1" 29 | fi 30 | if mountpoint -q $MNT; then 31 | umount $MNT 32 | fi 33 | rm -rf $MNT 34 | # opportunistic cleanup, not fatal if these fail 35 | namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") 36 | for i in $namespaces 37 | do 38 | if ! $NDCTL destroy-namespace -f $i; then 39 | echo "test/sub-section.sh: cleanup() failed to destroy $i" 40 | fi 41 | done 42 | exit $rc 43 | } 44 | 45 | trap 'err $LINENO cleanup' ERR 46 | 47 | json=$($NDCTL list -R -b ACPI.NFIT) 48 | region=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].dev") 49 | avail=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].available_size") 50 | if [ -z $region ]; then 51 | exit $SKIP 52 | fi 53 | 54 | iter=$((avail/TEST_SIZE)) 55 | if [ $iter -gt $MAX_NS ]; then 56 | iter=$MAX_NS; 57 | fi 58 | 59 | for i in $(seq 1 $iter) 60 | do 61 | json=$($NDCTL create-namespace -s $TEST_SIZE --no-autorecover -r $region -n "$NAME") 62 | dev=$(echo $json | jq -r ".blockdev") 63 | mkfs.ext4 -b 4096 /dev/$dev 64 | mount -o dax /dev/$dev $MNT 65 | umount $MNT 66 | done 67 | 68 | namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") 69 | for i in $namespaces 70 | do 71 | $NDCTL disable-namespace $i 72 | $NDCTL enable-namespace $i 73 | $NDCTL destroy-namespace $i -f 74 | done 75 | 76 | rc=$SUCCESS 77 | cleanup $LINENO 78 | -------------------------------------------------------------------------------- /test.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2015-2020 Intel Corporation. All rights reserved. */ 3 | #ifndef __TEST_H__ 4 | #define __TEST_H__ 5 | #include 6 | 7 | struct ndctl_test; 8 | struct ndctl_ctx; 9 | struct ndctl_test *ndctl_test_new(unsigned int kver); 10 | int ndctl_test_result(struct ndctl_test *test, int rc); 11 | int ndctl_test_get_skipped(struct ndctl_test *test); 12 | int ndctl_test_get_attempted(struct ndctl_test *test); 13 | int __ndctl_test_attempt(struct ndctl_test *test, unsigned int kver, 14 | const char *caller, int line); 15 | #define ndctl_test_attempt(t, v) __ndctl_test_attempt(t, v, __func__, __LINE__) 16 | void __ndctl_test_skip(struct ndctl_test *test, const char *caller, int line); 17 | #define ndctl_test_skip(t) __ndctl_test_skip(t, __func__, __LINE__) 18 | struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx); 19 | void builtin_xaction_namespace_reset(void); 20 | 21 | struct kmod_ctx; 22 | struct kmod_module; 23 | int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod, 24 | struct ndctl_ctx *nd_ctx, int log_level, 25 | struct ndctl_test *test); 26 | 27 | struct ndctl_ctx; 28 | int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); 29 | int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t offset); 30 | int test_dax_remap(struct ndctl_test *test, int dax_fd, unsigned long align, void *dax_addr, 31 | off_t offset, bool fsdax); 32 | #ifdef ENABLE_POISON 33 | int test_dax_poison(struct ndctl_test *test, int dax_fd, unsigned long align, 34 | void *dax_addr, off_t offset, bool fsdax); 35 | #else 36 | static inline int test_dax_poison(struct ndctl_test *test, int dax_fd, 37 | unsigned long align, void *dax_addr, off_t offset, bool fsdax) 38 | { 39 | return 0; 40 | } 41 | #endif 42 | int test_dsm_fail(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); 43 | int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); 44 | int test_pmem_namespaces(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); 45 | #endif /* __TEST_H__ */ 46 | -------------------------------------------------------------------------------- /test/cxl-destroy-region.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2023 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname $0)/common 6 | 7 | rc=77 8 | 9 | set -ex 10 | 11 | trap 'err $LINENO' ERR 12 | 13 | check_prereq "jq" 14 | 15 | modprobe -r cxl_test 16 | modprobe cxl_test 17 | rc=1 18 | 19 | check_destroy_ram() 20 | { 21 | mem=$1 22 | decoder=$2 23 | 24 | region="$("$CXL" create-region -d "$decoder" -m "$mem" | jq -r ".region")" 25 | if [[ ! $region ]]; then 26 | err "$LINENO" 27 | fi 28 | "$CXL" enable-region "$region" 29 | 30 | # default is memory is system-ram offline 31 | "$CXL" disable-region "$region" 32 | "$CXL" destroy-region "$region" 33 | } 34 | 35 | check_destroy_devdax() 36 | { 37 | mem=$1 38 | decoder=$2 39 | 40 | region="$("$CXL" create-region -d "$decoder" -m "$mem" | jq -r ".region")" 41 | if [[ ! $region ]]; then 42 | err "$LINENO" 43 | fi 44 | "$CXL" enable-region "$region" 45 | 46 | dax="$("$CXL" list -X -r "$region" | jq -r ".[].daxregion.devices" | jq -r '.[].chardev')" 47 | 48 | $DAXCTL reconfigure-device -m devdax "$dax" 49 | 50 | "$CXL" disable-region "$region" 51 | "$CXL" destroy-region "$region" 52 | } 53 | 54 | # Find a memory device to create regions on to test the destroy 55 | readarray -t mems < <("$CXL" list -b "$CXL_TEST_BUS" -M | jq -r '.[].memdev') 56 | for mem in "${mems[@]}"; do 57 | ramsize="$("$CXL" list -m "$mem" | jq -r '.[].ram_size')" 58 | if [[ $ramsize == "null" || ! $ramsize ]]; then 59 | continue 60 | fi 61 | decoder="$("$CXL" list -b "$CXL_TEST_BUS" -D -d root -m "$mem" | 62 | jq -r ".[] | 63 | select(.volatile_capable == true) | 64 | select(.nr_targets == 1) | 65 | select(.max_available_extent >= ${ramsize}) | 66 | .decoder")" 67 | if [[ $decoder ]]; then 68 | check_destroy_ram "$mem" "$decoder" 69 | check_destroy_devdax "$mem" "$decoder" 70 | break 71 | fi 72 | done 73 | 74 | check_dmesg "$LINENO" 75 | 76 | modprobe -r cxl_test 77 | -------------------------------------------------------------------------------- /ndctl/monitor.conf: -------------------------------------------------------------------------------- 1 | [monitor] 2 | # The values in [monitor] section work for ndctl monitor. 3 | # You can change the configuration of ndctl monitor by editing this 4 | # file or use [--config-file=] option to override this one. 5 | # The changed value will work after restart ndctl monitor service. 6 | 7 | # In this file, lines starting with a hash (#) are comments. 8 | # The configurations should follow = style. 9 | # Multiple space-separated values are allowed, but except the following 10 | # characters: : ? / \ % " ' $ & ! * { } [ ] ( ) = < > @ 11 | 12 | # The objects to monitor are filtered via dimm's name by setting key "dimm". 13 | # If this value is different from the value of [--dimm=] option, 14 | # both of the values will work. 15 | # dimm = all 16 | 17 | # The objects to monitor are filtered via its parent bus by setting key "bus". 18 | # If this value is different from the value of [--bus=] option, 19 | # both of the values will work. 20 | # bus = all 21 | 22 | # The objects to monitor are filtered via region by setting key "region". 23 | # If this value is different from the value of [--region=] option, 24 | # both of the values will work. 25 | # region = all 26 | 27 | # The objects to monitor are filtered via namespace by setting key "namespace". 28 | # If this value is different from the value of [--namespace=] option, 29 | # both of the values will work. 30 | # namespace = all 31 | 32 | # The DIMM events to monitor are filtered via event type by setting key 33 | # "dimm-event". If this value is different from the value of 34 | # [--dimm-event=] option, both of the values will work. 35 | # dimm-event = all 36 | 37 | # Users can choose to output the notifications to syslog (log=syslog), 38 | # to standard output (log=standard) or to write into a special file (log=) 39 | # by setting key "log". If this value is in conflict with the value of 40 | # [--log=] option, this value will be ignored. 41 | # Note: Setting value to "standard" or relative path for will not work 42 | # when running monitor as a daemon. 43 | # log = /var/log/ndctl/monitor.log 44 | -------------------------------------------------------------------------------- /util/list.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2022 Intel Corporation. All rights reserved. */ 3 | #ifndef _NDCTL_LIST_H_ 4 | #define _NDCTL_LIST_H_ 5 | 6 | #include 7 | 8 | #define list_add_sorted(head, n, node, cmp) \ 9 | do { \ 10 | struct list_head *__head = (head); \ 11 | typeof(n) __iter, __next; \ 12 | typeof(n) __new = (n); \ 13 | \ 14 | if (list_empty(__head)) { \ 15 | list_add(__head, &__new->node); \ 16 | break; \ 17 | } \ 18 | \ 19 | list_for_each (__head, __iter, node) { \ 20 | if (cmp(__new, __iter) < 0) { \ 21 | list_add_before(__head, &__iter->node, \ 22 | &__new->node); \ 23 | break; \ 24 | } \ 25 | __next = list_next(__head, __iter, node); \ 26 | if (!__next) { \ 27 | list_add_after(__head, &__iter->node, \ 28 | &__new->node); \ 29 | break; \ 30 | } \ 31 | if (cmp(__new, __next) < 0) { \ 32 | list_add_before(__head, &__next->node, \ 33 | &__new->node); \ 34 | break; \ 35 | } \ 36 | } \ 37 | } while (0) 38 | 39 | #endif /* _NDCTL_LIST_H_ */ 40 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-offline-memory.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-offline-memory(1) 4 | ======================== 5 | 6 | NAME 7 | ---- 8 | daxctl-offline-memory - Offline the memory for a device that is in system-ram mode 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl offline-memory' [...] [] 14 | 15 | EXAMPLES 16 | -------- 17 | 18 | * Reconfigure dax0.0 to system-ram mode 19 | ---- 20 | # daxctl reconfigure-device --mode=system-ram --human dax0.0 21 | { 22 | "chardev":"dax0.0", 23 | "size":"7.87 GiB (8.45 GB)", 24 | "target_node":2, 25 | "mode":"system-ram" 26 | } 27 | ---- 28 | 29 | * Offline the memory 30 | ---- 31 | # daxctl offline-memory dax0.0 32 | dax0.0: 62 sections offlined 33 | offlined memory for 1 device 34 | ---- 35 | 36 | DESCRIPTION 37 | ----------- 38 | 39 | Offline the memory sections associated with a device that has been converted 40 | to the system-ram mode. If one or more blocks are already offline, attempt to 41 | offline the remaining blocks. If all blocks were already offline, print a 42 | message and return success without actually doing anything. 43 | 44 | This is complementary to the 'daxctl-online-memory' command, and may be used 45 | when it is wished to offline the memory sections, but not convert the device 46 | back to 'devdax' mode. 47 | 48 | OPTIONS 49 | ------- 50 | -r:: 51 | --region=:: 52 | Restrict the operation to devices belonging to the specified region(s). 53 | A device-dax region is a contiguous range of memory that hosts one or 54 | more /dev/daxX.Y devices, where X is the region id and Y is the device 55 | instance id. 56 | 57 | -u:: 58 | --human:: 59 | By default the command will output machine-friendly raw-integer 60 | data. Instead, with this flag, numbers representing storage size 61 | will be formatted as human readable strings with units, other 62 | fields are converted to hexadecimal strings. 63 | 64 | -v:: 65 | --verbose:: 66 | Emit more debug messages 67 | 68 | include::../copyright.txt[] 69 | 70 | SEE ALSO 71 | -------- 72 | linkdaxctl:daxctl-reconfigure-device[1],daxctl-online-memory[1] 73 | -------------------------------------------------------------------------------- /cxl/builtin.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */ 3 | #ifndef _CXL_BUILTIN_H_ 4 | #define _CXL_BUILTIN_H_ 5 | 6 | struct cxl_ctx; 7 | int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx); 8 | int cmd_write_labels(int argc, const char **argv, struct cxl_ctx *ctx); 9 | int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx); 10 | int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx); 11 | int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx); 12 | int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx); 13 | int cmd_disable_memdev(int argc, const char **argv, struct cxl_ctx *ctx); 14 | int cmd_enable_memdev(int argc, const char **argv, struct cxl_ctx *ctx); 15 | int cmd_reserve_dpa(int argc, const char **argv, struct cxl_ctx *ctx); 16 | int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx); 17 | int cmd_update_fw(int argc, const char **argv, struct cxl_ctx *ctx); 18 | int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx); 19 | int cmd_wait_sanitize(int argc, const char **argv, struct cxl_ctx *ctx); 20 | int cmd_disable_port(int argc, const char **argv, struct cxl_ctx *ctx); 21 | int cmd_enable_port(int argc, const char **argv, struct cxl_ctx *ctx); 22 | int cmd_set_partition(int argc, const char **argv, struct cxl_ctx *ctx); 23 | int cmd_disable_bus(int argc, const char **argv, struct cxl_ctx *ctx); 24 | int cmd_create_region(int argc, const char **argv, struct cxl_ctx *ctx); 25 | int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx); 26 | int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx); 27 | int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx); 28 | #ifdef ENABLE_LIBTRACEFS 29 | int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx); 30 | #else 31 | static inline int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx) 32 | { 33 | fprintf(stderr, 34 | "cxl monitor: unavailable, rebuild with '-Dlibtracefs=enabled'\n"); 35 | return EXIT_FAILURE; 36 | } 37 | #endif 38 | #endif /* _CXL_BUILTIN_H_ */ 39 | -------------------------------------------------------------------------------- /test/daxdev-errors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | rc=77 8 | 9 | . $(dirname $0)/common 10 | 11 | check_min_kver "4.12" || do_skip "lacks dax dev error handling" 12 | check_prereq "jq" 13 | 14 | trap 'err $LINENO' ERR 15 | 16 | # setup (reset nfit_test dimms) 17 | modprobe nfit_test 18 | reset 19 | 20 | rc=1 21 | 22 | query=". | sort_by(.available_size) | reverse | .[0].dev" 23 | region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query") 24 | 25 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096) 26 | chardev=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev") 27 | 28 | #{ 29 | # "dev":"namespace6.0", 30 | # "mode":"devdax", 31 | # "size":64004096, 32 | # "uuid":"83a925dd-42b5-4ac6-8588-6a50bfc0c001", 33 | # "daxregion":{ 34 | # "id":6, 35 | # "size":64004096, 36 | # "align":4096, 37 | # "devices":[ 38 | # { 39 | # "chardev":"dax6.0", 40 | # "size":64004096 41 | # } 42 | # ] 43 | # } 44 | #} 45 | 46 | json1=$($NDCTL list -b $NFIT_TEST_BUS0 --mode=devdax --namespaces) 47 | eval $(echo $json1 | json2var) 48 | nsdev=$dev 49 | 50 | json1=$($NDCTL list -b $NFIT_TEST_BUS0) 51 | eval $(echo $json1 | json2var) 52 | busdev=$dev 53 | 54 | # inject errors in the middle of the namespace 55 | err_sector="$(((size/512) / 2))" 56 | err_count=8 57 | if ! read sector len < /sys/bus/nd/devices/$region/badblocks; then 58 | $NDCTL inject-error --block="$err_sector" --count=$err_count $nsdev 59 | fi 60 | 61 | read sector len < /sys/bus/nd/devices/$region/badblocks 62 | echo "sector: $sector len: $len" 63 | 64 | # run the daxdev-errors test 65 | test -x $TEST_PATH/daxdev-errors 66 | $TEST_PATH/daxdev-errors $busdev $region 67 | 68 | # check badblocks, should be empty 69 | if read sector len < /sys/bus/platform/devices/nfit_test.0/$busdev/$region/badblocks; then 70 | echo "badblocks empty, expected" 71 | fi 72 | [ -n "$sector" ] && echo "fail: $LINENO" && exit 1 73 | 74 | check_dmesg "$LINENO" 75 | 76 | _cleanup 77 | 78 | exit 0 79 | -------------------------------------------------------------------------------- /test/mmap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | . $(dirname $0)/common 6 | 7 | MNT=test_mmap_mnt 8 | FILE=image 9 | DEV="" 10 | TEST=$TEST_PATH/mmap 11 | rc=77 12 | 13 | cleanup() { 14 | echo "test-mmap: failed at line $1" 15 | if [ -n "$DEV" ]; then 16 | umount $DEV 17 | else 18 | rc=77 19 | fi 20 | rm -rf $MNT 21 | exit $rc 22 | } 23 | 24 | test_mmap() { 25 | # SHARED 26 | $TEST -Mrwps $MNT/$FILE # mlock, populate, shared (mlock fail) 27 | $TEST -Arwps $MNT/$FILE # mlockall, populate, shared 28 | $TEST -RMrps $MNT/$FILE # read-only, mlock, populate, shared (mlock fail) 29 | $TEST -rwps $MNT/$FILE # populate, shared (populate no effect) 30 | $TEST -Rrps $MNT/$FILE # read-only populate, shared (populate no effect) 31 | $TEST -Mrws $MNT/$FILE # mlock, shared (mlock fail) 32 | $TEST -RMrs $MNT/$FILE # read-only, mlock, shared (mlock fail) 33 | $TEST -rws $MNT/$FILE # shared (ok) 34 | $TEST -Rrs $MNT/$FILE # read-only, shared (ok) 35 | 36 | # PRIVATE 37 | $TEST -Mrwp $MNT/$FILE # mlock, populate, private (ok) 38 | $TEST -RMrp $MNT/$FILE # read-only, mlock, populate, private (mlock fail) 39 | $TEST -rwp $MNT/$FILE # populate, private (ok) 40 | $TEST -Rrp $MNT/$FILE # read-only, populate, private (populate no effect) 41 | $TEST -Mrw $MNT/$FILE # mlock, private (ok) 42 | $TEST -RMr $MNT/$FILE # read-only, mlock, private (mlock fail) 43 | $TEST -MSr $MNT/$FILE # private, read before mlock (ok) 44 | $TEST -rw $MNT/$FILE # private (ok) 45 | $TEST -Rr $MNT/$FILE # read-only, private (ok) 46 | } 47 | 48 | set -e 49 | mkdir -p $MNT 50 | trap 'err $LINENO cleanup' ERR 51 | 52 | dev=$($TEST_PATH/dax-dev) 53 | json=$($NDCTL list -N -n $dev) 54 | eval $(json2var <<< "$json") 55 | DEV="/dev/${blockdev}" 56 | rc=1 57 | 58 | mkfs.ext4 $DEV 59 | mount $DEV $MNT -o dax 60 | fallocate -l 1GiB $MNT/$FILE 61 | test_mmap 62 | umount $MNT 63 | 64 | mkfs.xfs -f $DEV -m reflink=0 65 | mount $DEV $MNT -o dax 66 | fallocate -l 1GiB $MNT/$FILE 67 | test_mmap 68 | umount $MNT 69 | -------------------------------------------------------------------------------- /util/usage.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2005 Linus Torvalds. All rights reserved. 3 | 4 | /* originally copied from perf and git */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static void report(const char *prefix, const char *err, va_list params) 12 | { 13 | char msg[1024]; 14 | vsnprintf(msg, sizeof(msg), err, params); 15 | fprintf(stderr, " %s%s\n", prefix, msg); 16 | } 17 | 18 | static NORETURN void usage_builtin(const char *err) 19 | { 20 | fprintf(stderr, "\n Usage: %s\n", err); 21 | exit(129); 22 | } 23 | 24 | static NORETURN void die_builtin(const char *err, va_list params) 25 | { 26 | report(" Fatal: ", err, params); 27 | exit(128); 28 | } 29 | 30 | static void error_builtin(const char *err, va_list params) 31 | { 32 | report(" Error: ", err, params); 33 | } 34 | 35 | static void warn_builtin(const char *warn, va_list params) 36 | { 37 | report(" Warning: ", warn, params); 38 | } 39 | 40 | /* If we are in a dlopen()ed .so write to a global variable would segfault 41 | * (ugh), so keep things static. */ 42 | static void (*usage_routine)(const char *err) NORETURN = usage_builtin; 43 | static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin; 44 | static void (*error_routine)(const char *err, va_list params) = error_builtin; 45 | static void (*warn_routine)(const char *err, va_list params) = warn_builtin; 46 | 47 | void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN) 48 | { 49 | die_routine = routine; 50 | } 51 | 52 | void usage(const char *err) 53 | { 54 | usage_routine(err); 55 | } 56 | 57 | void die(const char *err, ...) 58 | { 59 | va_list params; 60 | 61 | va_start(params, err); 62 | die_routine(err, params); 63 | va_end(params); 64 | } 65 | 66 | int error(const char *err, ...) 67 | { 68 | va_list params; 69 | 70 | va_start(params, err); 71 | error_routine(err, params); 72 | va_end(params); 73 | return -1; 74 | } 75 | 76 | void warning(const char *warn, ...) 77 | { 78 | va_list params; 79 | 80 | va_start(params, warn); 81 | warn_routine(warn, params); 82 | va_end(params); 83 | } 84 | -------------------------------------------------------------------------------- /ccan/str/debug.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: CC0-1.0 2 | #include "config.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef CCAN_STR_DEBUG 9 | /* Because we mug the real ones with macros, we need our own wrappers. */ 10 | int str_isalnum(int i) 11 | { 12 | assert(i >= -1 && i < 256); 13 | return isalnum(i); 14 | } 15 | 16 | int str_isalpha(int i) 17 | { 18 | assert(i >= -1 && i < 256); 19 | return isalpha(i); 20 | } 21 | 22 | int str_isascii(int i) 23 | { 24 | assert(i >= -1 && i < 256); 25 | return isascii(i); 26 | } 27 | 28 | #if HAVE_ISBLANK 29 | int str_isblank(int i) 30 | { 31 | assert(i >= -1 && i < 256); 32 | return isblank(i); 33 | } 34 | #endif 35 | 36 | int str_iscntrl(int i) 37 | { 38 | assert(i >= -1 && i < 256); 39 | return iscntrl(i); 40 | } 41 | 42 | int str_isdigit(int i) 43 | { 44 | assert(i >= -1 && i < 256); 45 | return isdigit(i); 46 | } 47 | 48 | int str_isgraph(int i) 49 | { 50 | assert(i >= -1 && i < 256); 51 | return isgraph(i); 52 | } 53 | 54 | int str_islower(int i) 55 | { 56 | assert(i >= -1 && i < 256); 57 | return islower(i); 58 | } 59 | 60 | int str_isprint(int i) 61 | { 62 | assert(i >= -1 && i < 256); 63 | return isprint(i); 64 | } 65 | 66 | int str_ispunct(int i) 67 | { 68 | assert(i >= -1 && i < 256); 69 | return ispunct(i); 70 | } 71 | 72 | int str_isspace(int i) 73 | { 74 | assert(i >= -1 && i < 256); 75 | return isspace(i); 76 | } 77 | 78 | int str_isupper(int i) 79 | { 80 | assert(i >= -1 && i < 256); 81 | return isupper(i); 82 | } 83 | 84 | int str_isxdigit(int i) 85 | { 86 | assert(i >= -1 && i < 256); 87 | return isxdigit(i); 88 | } 89 | 90 | #undef strstr 91 | #undef strchr 92 | #undef strrchr 93 | 94 | char *str_strstr(const char *haystack, const char *needle) 95 | { 96 | return strstr(haystack, needle); 97 | } 98 | 99 | char *str_strchr(const char *haystack, int c) 100 | { 101 | return strchr(haystack, c); 102 | } 103 | 104 | char *str_strrchr(const char *haystack, int c) 105 | { 106 | return strrchr(haystack, c); 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-migrate-device-model.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-migrate-device-model(1) 4 | ============================== 5 | 6 | NAME 7 | ---- 8 | daxctl-migrate-device-model - Opt-in to the /sys/bus/dax device-model, 9 | allow for alternative Device-DAX instance drivers. 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | 'daxctl migrate-device-model' 15 | 16 | Arrange for modprobe to disable the dax_pmem_compat, if present, and 17 | instead deploy the dax_pmem module to convert to the /sys/bus/dax model. 18 | Kernel versions prior to v5.1 may not support /sys/bus/dax in which case 19 | the result of this command is a nop until the kernel is updated. The 20 | motivation for changing from /sys/class/dax to /sys/bus/dax is to allow 21 | for alternative drivers for Device-DAX instances, in particular the 22 | dax_kmem driver. 23 | 24 | By default device-dax publishes a /dev/daxX.Y character device for 25 | userspace to directly map performance differentiated memory. This is 26 | fine if the memory is to be exclusively consumed / managed by userspace. 27 | Alternatively an administrator may want the kernel to manage the memory, 28 | make it available via malloc(), allow for over-provisioning, and / or 29 | apply kernel-based resource control schemes to the memory. In that case 30 | the memory fronted by a given Device-DAX instance can be assigned to the 31 | dax_kmem driver which arranges for the core-kernel memory-management 32 | sub-system to assume management of the memory range. 33 | 34 | This behavior is opt-in for consideration of existing applications / 35 | scripts that may be hard coded to use /sys/class/dax. Fixes have been 36 | submitted to applications known to have these direct dependencies 37 | http://git.kernel.dk/cgit/fio/commit/?id=b08e7d6b18b4[FIO] 38 | https://github.com/pmem/pmdk/commit/91bc8620884e[PMDK], however, there may 39 | be others and a system-owner should be aware of the potential for 40 | regression of Device-DAX consuming scripts, applications, or older 41 | daxctl binaries. 42 | 43 | The modprobe policy established by this utility becomes effective after 44 | the next reboot, or after all DAX related modules have been removed and 45 | re-loaded with "udevadm trigger" 46 | 47 | include::../copyright.txt[] 48 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-set-partition.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-set-partition(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | cxl-set-partition - set the partitioning between volatile and persistent capacity on a CXL memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl set-partition [ [..] []' 14 | 15 | DESCRIPTION 16 | ----------- 17 | CXL devices may support both volatile and persistent memory capacity. 18 | The amount of device capacity set aside for each type is typically 19 | established at the factory, but some devices also allow for dynamic 20 | re-partitioning. 21 | 22 | Use this command to partition a device into volatile and persistent 23 | capacity. The change in partitioning becomes the “next” configuration, 24 | to become active on the next device reset. 25 | 26 | Use "cxl list -m -I" to examine the partitioning capabilities 27 | of a device. A partition_alignment_size value of zero means there is 28 | no available capacity and therefore the partitions cannot be changed. 29 | 30 | Using this command to change the size of the persistent capacity shall 31 | result in the loss of data stored. 32 | 33 | OPTIONS 34 | ------- 35 | :: 36 | include::memdev-option.txt[] 37 | 38 | include::bus-option.txt[] 39 | 40 | -t:: 41 | --type=:: 42 | Type of partition, 'pmem' or 'ram' (volatile), to modify. 43 | Default: 'pmem' 44 | 45 | -s:: 46 | --size=:: 47 | Size of the partition in bytes. Size must align to the 48 | devices alignment requirement. Use 'cxl list -m -I' 49 | to find 'partition_alignment_size', or, use the --align option. 50 | Default: All available capacity is assigned to . 51 | 52 | -a:: 53 | --align:: 54 | Select this option to allow the automatic alignment of --size 55 | to meet device alignment requirements. When using this option, 56 | specify the minimum --size of the --type partition needed. When 57 | this option is omitted, the command fails if --size is not 58 | properly aligned. Use 'cxl list -m -I' to examine the 59 | partition_alignment_size. 60 | 61 | -v:: 62 | Turn on verbose debug messages in the library (if libcxl was built with 63 | logging and debug enabled). 64 | 65 | include::../copyright.txt[] 66 | 67 | SEE ALSO 68 | -------- 69 | linkcxl:cxl-list[1], 70 | CXL-2.0 8.2.9.5.2 71 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-update-firmware.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-update-firmware(1) 4 | ====================== 5 | 6 | NAME 7 | ---- 8 | cxl-update-firmware - update the firmware on a CXL memdev 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl update-firmware [..] []' 14 | 15 | DESCRIPTION 16 | ----------- 17 | 18 | Update the firmware on one or more CXL mem devices. The mem devices 19 | must support the set of firmware related mailbox commands. 20 | 21 | This command doesn't directly issue the transfer / activate firmware 22 | mailbox commands. Instead, the kernel's firmware loader facility is 23 | used to provide the kernel with the data, and the kernel handles 24 | performing the actual update while also managing time slicing the 25 | transfer w.r.t. other background commands. 26 | 27 | EXAMPLE 28 | ------- 29 | ---- 30 | # cxl update-firmware mem0 -F firmware.bin -w 31 | [ 32 | { 33 | "memdev":"mem0", 34 | "pmem_size":1073741824, 35 | "ram_size":1073741824, 36 | "serial":0, 37 | "numa_node":0, 38 | "host":"cxl_mem.0", 39 | "firmware":{ 40 | "num_slots":3, 41 | "active_slot":2, 42 | "online_activate_capable":false, 43 | "slot_1_version":"cxl_test_fw_001", 44 | "slot_2_version":"cxl_test_fw_002", 45 | "slot_3_version":"cxl_test_new_fw", 46 | "fw_update_in_progress":false 47 | } 48 | } 49 | ] 50 | firmware update completed on 1 mem device 51 | ---- 52 | 53 | OPTIONS 54 | ------- 55 | 56 | include::bus-option.txt[] 57 | 58 | -F:: 59 | --firmware-file:: 60 | Firmware image file to use for the update. 61 | 62 | -c:: 63 | --cancel:: 64 | Attempt to abort an in-progress firmware update. This may 65 | fail depending on what stage the update process is in. 66 | 67 | -w:: 68 | --wait:: 69 | By default, the update-firmware command only initiates the 70 | firmware update, and returns, while the update operation 71 | happens asynchronously in the background. This option makes 72 | the firmware update command synchronous by waiting for it to 73 | complete before returning. 74 | 75 | If --wait is passed in without an accompanying firmware-file, 76 | it will initiate a wait on any current in-progress firmware 77 | updates, and then return. 78 | 79 | include::verbose-option.txt[] 80 | 81 | include::../copyright.txt[] 82 | 83 | SEE ALSO 84 | -------- 85 | linkcxl:cxl-list[1], 86 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-init-labels.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-init-labels(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | ndctl-init-labels - initialize the label data area on a dimm or set of dimms 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl init-labels' [..] [] 14 | 15 | include::labels-description.txt[] 16 | Starting with v4.10 the kernel will honor labels for sub-dividing PMEM 17 | if all the DIMMs in an interleave set / region have a valid namespace 18 | index block. 19 | 20 | This command can be used to initialize the namespace index block if it 21 | is missing or reinitialize it if it is damaged. Note that 22 | reinitialization effectively destroys all existing namespace labels on 23 | the DIMM. 24 | 25 | EXAMPLE 26 | ------- 27 | Find the DIMMs that comprise a given region: 28 | ---- 29 | # ndctl list -RD --region=region1 30 | { 31 | "dimms":[ 32 | { 33 | "dev":"nmem0", 34 | "id":"8680-56341200" 35 | } 36 | ], 37 | "regions":[ 38 | { 39 | "dev":"region1", 40 | "size":268435456, 41 | "available_size":0, 42 | "type":"pmem", 43 | "mappings":[ 44 | { 45 | "dimm":"nmem0", 46 | "offset":13958643712, 47 | "length":268435456 48 | } 49 | ] 50 | } 51 | ] 52 | } 53 | ---- 54 | 55 | Disable that region so the DIMM label area can be written from 56 | userspace: 57 | ---- 58 | # ndctl disable-region region1 59 | ---- 60 | 61 | Initialize labels: 62 | ---- 63 | # ndctl init-labels nmem0 64 | ---- 65 | 66 | Re-enable the region: 67 | ---- 68 | # ndctl enable-region region1 69 | ---- 70 | 71 | Create a namespace in that region: 72 | ---- 73 | # ndctl create-namespace --region=region1 74 | ---- 75 | 76 | OPTIONS 77 | ------- 78 | include::labels-options.txt[] 79 | -f:: 80 | --force:: 81 | Force initialization of the label space even if there appears to 82 | be an existing / valid namespace index. Warning, this will 83 | destroy all defined namespaces on the dimm. 84 | 85 | -V:: 86 | --label-version:: 87 | Initialize with a specific version of labels from the namespace 88 | label specification. Defaults to 1.1 89 | 90 | include::../copyright.txt[] 91 | 92 | SEE ALSO 93 | -------- 94 | linkndctl:ndctl-create-namespace[1], 95 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 96 | -------------------------------------------------------------------------------- /util/strbuf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright (C) 2005 Junio C Hamano. All rights reserved. 3 | 4 | /* originally copied from perf and git */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | int prefixcmp(const char *str, const char *prefix) 14 | { 15 | for (; ; str++, prefix++) 16 | if (!*prefix) 17 | return 0; 18 | else if (*str != *prefix) 19 | return (unsigned char)*prefix - (unsigned char)*str; 20 | } 21 | 22 | /* 23 | * Used as the default ->buf value, so that people can always assume 24 | * buf is non NULL and ->buf is NUL terminated even for a freshly 25 | * initialized strbuf. 26 | */ 27 | char strbuf_slopbuf[1]; 28 | 29 | void strbuf_init(struct strbuf *sb, ssize_t hint) 30 | { 31 | sb->alloc = sb->len = 0; 32 | sb->buf = strbuf_slopbuf; 33 | if (hint) 34 | strbuf_grow(sb, hint); 35 | } 36 | 37 | void strbuf_release(struct strbuf *sb) 38 | { 39 | if (sb->alloc) { 40 | zfree(&sb->buf); 41 | strbuf_init(sb, 0); 42 | } 43 | } 44 | 45 | char *strbuf_detach(struct strbuf *sb, size_t *sz) 46 | { 47 | char *res = sb->alloc ? sb->buf : NULL; 48 | if (sz) 49 | *sz = sb->len; 50 | strbuf_init(sb, 0); 51 | return res; 52 | } 53 | 54 | void strbuf_grow(struct strbuf *sb, size_t extra) 55 | { 56 | if (sb->len + extra + 1 <= sb->len) 57 | die("you want to use way too much memory"); 58 | if (!sb->alloc) 59 | sb->buf = NULL; 60 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); 61 | } 62 | 63 | void strbuf_add(struct strbuf *sb, const void *data, size_t len) 64 | { 65 | strbuf_grow(sb, len); 66 | memcpy(sb->buf + sb->len, data, len); 67 | strbuf_setlen(sb, sb->len + len); 68 | } 69 | 70 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) 71 | { 72 | int len; 73 | va_list ap; 74 | 75 | if (!strbuf_avail(sb)) 76 | strbuf_grow(sb, 64); 77 | va_start(ap, fmt); 78 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 79 | va_end(ap); 80 | if (len < 0) 81 | die("your vsnprintf is broken"); 82 | if (len > strbuf_avail(sb)) { 83 | strbuf_grow(sb, len); 84 | va_start(ap, fmt); 85 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 86 | va_end(ap); 87 | if (len > strbuf_avail(sb)) { 88 | die("this should not happen, your vsnprintf is broken"); 89 | } 90 | } 91 | strbuf_setlen(sb, sb->len + len); 92 | } 93 | -------------------------------------------------------------------------------- /Documentation/cxl/lib/meson.build: -------------------------------------------------------------------------------- 1 | if get_option('asciidoctor').enabled() 2 | asciidoc_conf = custom_target('asciidoctor-extensions.rb', 3 | command : [ 4 | 'sed', '-e', 's,@Utility@,Libcxl,g', '-e', 's,@utility@,cxl,g', '@INPUT@' 5 | ], 6 | input : '../../asciidoctor-extensions.rb.in', 7 | output : 'asciidoctor-extensions.rb', 8 | capture : true, 9 | ) 10 | else 11 | asciidoc_conf = custom_target('asciidoc.conf', 12 | command : [ 13 | 'sed', '-e', 's,UTILITY,libcxl,g', 14 | ], 15 | input : '../../asciidoc.conf.in', 16 | output : 'asciidoc.conf', 17 | capture : true, 18 | ) 19 | endif 20 | 21 | filedeps = [ 22 | '../../copyright.txt', 23 | ] 24 | 25 | libcxl_manpages = [ 26 | 'libcxl.txt', 27 | 'cxl_new.txt', 28 | ] 29 | 30 | foreach man : libcxl_manpages 31 | name = man.split('.')[0] 32 | output = name + '.3' 33 | output_xml = name + '.xml' 34 | if get_option('asciidoctor').enabled() 35 | custom_target(name, 36 | command : [ 37 | asciidoc, 38 | '-b', 'manpage', '-d', 'manpage', '-acompat-mode', '-I', '@OUTDIR@', 39 | '-rasciidoctor-extensions', '-amansource=libcxl', 40 | '-amanmanual=libcxl Manual', 41 | '-andctl_version=@0@'.format(meson.project_version()), 42 | '-o', '@OUTPUT@', '@INPUT@' 43 | ], 44 | input : man, 45 | output : output, 46 | depend_files : filedeps, 47 | depends : asciidoc_conf, 48 | install : get_option('docs').enabled(), 49 | install_dir : join_paths(get_option('mandir'), 'man3'), 50 | ) 51 | else 52 | xml = custom_target(output_xml, 53 | command : [ 54 | asciidoc, 55 | '-b', 'docbook', '-d', 'manpage', '-f', asciidoc_conf, '--unsafe', 56 | '-andctl_version=@0@'.format(meson.project_version()), 57 | '-o', '@OUTPUT@', '@INPUT@', 58 | ], 59 | input : man, 60 | output : output_xml, 61 | depend_files : filedeps, 62 | depends : asciidoc_conf, 63 | ) 64 | 65 | xsl = files('../../manpage-normal.xsl') 66 | 67 | custom_target(name, 68 | command : [ 69 | xmlto, '-o', '@OUTDIR@', '-m', xsl, 'man', '@INPUT@' 70 | ], 71 | depends : xml, 72 | depend_files : xsl, 73 | input : xml, 74 | output : output, 75 | install : get_option('docs').enabled(), 76 | install_dir : join_paths(get_option('mandir'), 'man3'), 77 | ) 78 | endif 79 | endforeach 80 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-online-memory.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-online-memory(1) 4 | ======================= 5 | 6 | NAME 7 | ---- 8 | daxctl-online-memory - Online the memory for a device that is in system-ram mode 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'daxctl online-memory' [...] [] 14 | 15 | EXAMPLES 16 | -------- 17 | 18 | * Reconfigure dax0.0 to system-ram mode, don't online the memory 19 | ---- 20 | # daxctl reconfigure-device --mode=system-ram --no-online --human dax0.0 21 | { 22 | "chardev":"dax0.0", 23 | "size":"7.87 GiB (8.45 GB)", 24 | "target_node":2, 25 | "mode":"system-ram" 26 | } 27 | ---- 28 | 29 | * Online the memory separately 30 | ---- 31 | # daxctl online-memory dax0.0 32 | dax0.0: 62 new sections onlined 33 | onlined memory for 1 device 34 | ---- 35 | 36 | * Onlining memory when some sections were already online 37 | ---- 38 | # daxctl online-memory dax0.0 39 | dax0.0: 1 section already online 40 | dax0.0: 61 new sections onlined 41 | onlined memory for 1 device 42 | ---- 43 | 44 | DESCRIPTION 45 | ----------- 46 | 47 | Online the memory sections associated with a device that has been converted 48 | to the system-ram mode. If one or more blocks are already online, print a 49 | message about them, and attempt to online the remaining blocks. 50 | 51 | This is complementary to the 'daxctl-reconfigure-device' command, when used with 52 | the '--no-online' option to skip onlining memory sections immediately after the 53 | reconfigure. In these scenarios, the memory can be onlined at a later time using 54 | 'daxctl-online-memory'. 55 | 56 | OPTIONS 57 | ------- 58 | -r:: 59 | --region=:: 60 | Restrict the operation to devices belonging to the specified region(s). 61 | A device-dax region is a contiguous range of memory that hosts one or 62 | more /dev/daxX.Y devices, where X is the region id and Y is the device 63 | instance id. 64 | 65 | include::movable-options.txt[] 66 | 67 | -u:: 68 | --human:: 69 | By default the command will output machine-friendly raw-integer 70 | data. Instead, with this flag, numbers representing storage size 71 | will be formatted as human readable strings with units, other 72 | fields are converted to hexadecimal strings. 73 | 74 | -v:: 75 | --verbose:: 76 | Emit more debug messages 77 | 78 | include::../copyright.txt[] 79 | 80 | SEE ALSO 81 | -------- 82 | linkdaxctl:daxctl-reconfigure-device[1],daxctl-offline-memory[1] 83 | -------------------------------------------------------------------------------- /test/inject-error.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | dev="" 6 | size="" 7 | blockdev="" 8 | rc=77 9 | err_block=42 10 | err_count=8 11 | 12 | . $(dirname $0)/common 13 | 14 | check_prereq "jq" 15 | 16 | trap 'err $LINENO' ERR 17 | 18 | # sample json: 19 | #{ 20 | # "dev":"namespace7.0", 21 | # "mode":"fsdax", 22 | # "size":"60.00 MiB (62.92 MB)", 23 | # "uuid":"f1baa71a-d165-4da4-bb6a-083a2b0e6469", 24 | # "blockdev":"pmem7", 25 | #} 26 | 27 | check_min_kver "4.15" || do_skip "kernel $KVER may not support error injection" 28 | 29 | create() 30 | { 31 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem --align=4k) 32 | rc=2 33 | eval "$(echo "$json" | json2var)" 34 | [ -n "$dev" ] || err "$LINENO" 35 | [ -n "$size" ] || err "$LINENO" 36 | [ -n "$blockdev" ] || err "$LINENO" 37 | [ $size -gt 0 ] || err "$LINENO" 38 | } 39 | 40 | check_status() 41 | { 42 | local sector="$1" 43 | local count="$2" 44 | 45 | json="$($NDCTL inject-error --status $dev)" 46 | [[ "$sector" == "$(jq ".badblocks[0].block" <<< "$json")" ]] 47 | [[ "$count" == "$(jq ".badblocks[0].count" <<< "$json")" ]] 48 | } 49 | 50 | do_tests() 51 | { 52 | # inject without notification 53 | $NDCTL inject-error --block=$err_block --count=$err_count --no-notify $dev 54 | check_status "$err_block" "$err_count" 55 | if read -r sector len < /sys/block/$blockdev/badblocks; then 56 | # fail if reading badblocks returns data 57 | echo "fail: $LINENO" && exit 1 58 | fi 59 | 60 | # clear via err-inj-clear 61 | $NDCTL inject-error --block=$err_block --count=$err_count --uninject $dev 62 | check_status 63 | 64 | # inject normally 65 | $NDCTL inject-error --block=$err_block --count=$err_count $dev 66 | $NDCTL start-scrub $NFIT_TEST_BUS0 && $NDCTL wait-scrub $NFIT_TEST_BUS0 67 | check_status "$err_block" "$err_count" 68 | if read -r sector len < /sys/block/$blockdev/badblocks; then 69 | test "$sector" -eq "$err_block" 70 | test "$len" -eq "$err_count" 71 | fi 72 | 73 | # clear via write 74 | dd if=/dev/zero of=/dev/$blockdev bs=512 count=$err_count seek=$err_block oflag=direct 75 | if read -r sector len < /sys/block/$blockdev/badblocks; then 76 | # fail if reading badblocks returns data 77 | echo "fail: $LINENO" && exit 1 78 | fi 79 | check_status 80 | } 81 | 82 | modprobe nfit_test 83 | rc=1 84 | reset && create 85 | do_tests 86 | reset 87 | _cleanup 88 | exit 0 89 | -------------------------------------------------------------------------------- /Documentation/cxl/cxl-reserve-dpa.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | cxl-reserve-dpa(1) 4 | ================== 5 | 6 | NAME 7 | ---- 8 | cxl-reserve-dpa - allocate device-physical address space 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'cxl reserve-dpa' [..] [] 14 | 15 | The CXL region provisioning process proceeds in multiple steps. One of 16 | the steps is identifying and reserving the DPA span that each member of 17 | the interleave-set (region) contributes in advance of attaching that 18 | allocation to a region. For development, test, and debug purposes this 19 | command is a helper to find the next available decoder on endpoint 20 | (memdev) and mark a span of DPA as busy. 21 | 22 | OPTIONS 23 | ------- 24 | :: 25 | include::memdev-option.txt[] 26 | 27 | include::bus-option.txt[] 28 | 29 | -d:: 30 | --decoder:: 31 | Specify the decoder to attempt the allocation. The CXL specification 32 | mandates that allocations must be ordered by DPA and decoder instance. 33 | I.e. the lowest DPA allocation on the device is covered by decoder0, and 34 | the last / highest DPA allocation is covered by the last decoder. This 35 | ordering is enforced by the kernel. By default the tool picks the 'next 36 | available' decoder. 37 | 38 | -t:: 39 | --type:: 40 | Select the partition for the allocation. CXL devices implement a 41 | partition that divides 'ram' and 'pmem' capacity, where 'pmem' capacity 42 | consumes the higher DPA capacity above the partition boundary. The type 43 | defaults to 'pmem'. Note that given CXL DPA allocation constraints, once 44 | any 'pmem' allocation is established then all remaining 'ram' capacity 45 | becomes reserved (skipped). 46 | 47 | -f:: 48 | --force:: 49 | The kernel enforces CXL DPA allocation ordering constraints, and 50 | the tool anticipates those and fails operations that are expected to 51 | fail without sending them to the kernel. For test purposes, continue to 52 | attempt "expected to fail" operations to exercise the driver. 53 | 54 | -s:: 55 | --size:: 56 | Specify the size of the allocation. This option supports the suffixes 57 | "k" or "K" for KiB, "m" or "M" for MiB, "g" or "G" for GiB and "t" or 58 | "T" for TiB. This defaults to "all available capacity of the specified 59 | type". 60 | 61 | -v:: 62 | Turn on verbose debug messages in the library (if libcxl was built with 63 | logging and debug enabled). 64 | 65 | include::../copyright.txt[] 66 | 67 | SEE ALSO 68 | -------- 69 | linkcxl:cxl-free-dpa[1] 70 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-check-namespace.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-check-namespace(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | ndctl-check-namespace - check namespace metadata consistency 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'ndctl check-namespace' [] 14 | 15 | DESCRIPTION 16 | ----------- 17 | 18 | A namespace in the 'sector' mode will have metadata on it to describe 19 | the kernel BTT (Block Translation Table). The check-namespace command 20 | can be used to check the consistency of this metadata, and optionally, 21 | also attempt to repair it, if it has enough information to do so. 22 | 23 | The namespace being checked has to be disabled before initiating a 24 | check on it as a precautionary measure. The --force option can override 25 | this. 26 | 27 | EXAMPLES 28 | -------- 29 | 30 | Check a namespace (only report errors) 31 | [verse] 32 | ndctl disable-namespace namespace0.0 33 | ndctl check-namespace namespace0.0 34 | 35 | Check a namespace, and perform repairs if possible 36 | [verse] 37 | ndctl disable-namespace namespace0.0 38 | ndctl check-namespace --repair namespace0.0 39 | 40 | OPTIONS 41 | ------- 42 | -R:: 43 | --repair:: 44 | Perform metadata repairs if possible. Without this option, 45 | the raw namespace contents will not be touched. 46 | 47 | -L:: 48 | --rewrite-log:: 49 | Regenerate the BTT log and write it to media. This can be used to 50 | convert from the old (pre 4.15) padding format that was incompatible 51 | with other BTT implementations to the updated format. This requires 52 | the --repair option to be provided. 53 | 54 | WARNING: Do not interrupt this operation as it can potentially cause 55 | unrecoverable metadata corruption. It is highly recommended to create 56 | a backup of the raw namespace before attempting this. 57 | 58 | -f:: 59 | --force:: 60 | Unless this option is specified, a check-namespace operation 61 | will fail if the namespace is presently active. Specifying 62 | --force causes the namespace to be disabled before checking. 63 | 64 | -v:: 65 | --verbose:: 66 | Emit debug messages for the namespace check process. 67 | 68 | -r:: 69 | --region=:: 70 | include::xable-region-options.txt[] 71 | 72 | -b:: 73 | --bus=:: 74 | include::xable-bus-options.txt[] 75 | 76 | include::../copyright.txt[] 77 | 78 | SEE ALSO 79 | -------- 80 | linkndctl:ndctl-disable-namespace[1], 81 | linkndctl:ndctl-enable-namespace[1], 82 | http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] 83 | -------------------------------------------------------------------------------- /test/clear.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright (C) 2015-2020 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | rc=77 8 | 9 | . $(dirname $0)/common 10 | 11 | check_min_kver "4.6" || do_skip "lacks clear poison support" 12 | 13 | trap 'err $LINENO' ERR 14 | 15 | # setup (reset nfit_test dimms) 16 | modprobe nfit_test 17 | reset 18 | 19 | rc=1 20 | 21 | # create pmem 22 | dev="x" 23 | json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m raw) 24 | eval $(echo $json | json2var) 25 | [ $dev = "x" ] && echo "fail: $LINENO" && exit 1 26 | [ $mode != "raw" ] && echo "fail: $LINENO" && exit 1 27 | 28 | # inject errors in the middle of the namespace, verify that reading fails 29 | err_sector="$(((size/512) / 2))" 30 | err_count=8 31 | if ! read sector len < /sys/block/$blockdev/badblocks; then 32 | $NDCTL inject-error --block="$err_sector" --count=$err_count $dev 33 | $NDCTL start-scrub $NFIT_TEST_BUS0 && $NDCTL wait-scrub $NFIT_TEST_BUS0 34 | fi 35 | read sector len < /sys/block/$blockdev/badblocks 36 | [ $((sector * 2)) -ne $((size /512)) ] && echo "fail: $LINENO" && exit 1 37 | if dd if=/dev/$blockdev of=/dev/null iflag=direct bs=512 skip=$sector count=$len; then 38 | echo "fail: $LINENO" && exit 1 39 | fi 40 | 41 | size_raw=$size 42 | sector_raw=$sector 43 | 44 | # convert pmem to fsdax mode 45 | json=$($NDCTL create-namespace -m fsdax -f -e $dev) 46 | eval $(echo $json | json2var) 47 | [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 48 | 49 | # check for errors relative to the offset injected by the pfn device 50 | read sector len < /sys/block/$blockdev/badblocks 51 | [ $((sector_raw - sector)) -ne $(((size_raw - size) / 512)) ] && echo "fail: $LINENO" && exit 1 52 | 53 | # check that writing clears the errors 54 | if ! dd of=/dev/$blockdev if=/dev/zero oflag=direct bs=512 seek=$sector count=$len; then 55 | echo "fail: $LINENO" && exit 1 56 | fi 57 | 58 | if read sector len < /sys/block/$blockdev/badblocks; then 59 | # fail if reading badblocks returns data 60 | echo "fail: $LINENO" && exit 1 61 | fi 62 | 63 | if check_min_kver "4.9"; then 64 | # check for re-appearance of stale badblocks from poison_list 65 | $NDCTL disable-region -b $NFIT_TEST_BUS0 all 66 | $NDCTL enable-region -b $NFIT_TEST_BUS0 all 67 | 68 | # since we have cleared the errors, a disable/reenable shouldn't bring them back 69 | if read sector len < /sys/block/$blockdev/badblocks; then 70 | # fail if reading badblocks returns data 71 | echo "fail: $LINENO" && exit 1 72 | fi 73 | fi 74 | 75 | _cleanup 76 | 77 | exit 0 78 | -------------------------------------------------------------------------------- /Documentation/daxctl/daxctl-list.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | daxctl-list(1) 4 | ============== 5 | 6 | NAME 7 | ---- 8 | daxctl-list - dump the platform Device-DAX regions, devices, and 9 | attributes in json. 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | 'daxctl list' [] 15 | 16 | Walk all the device-dax-regions in the system and list all device 17 | instances along with some of their major attributes. 18 | 19 | Options can be specified to limit the output to objects of a certain 20 | class. Where the classes are regions or devices. By default, 'daxctl 21 | list' with no options is equivalent to: 22 | [verse] 23 | daxctl list --devices 24 | 25 | EXAMPLE 26 | ------- 27 | ---- 28 | # daxctl list --regions --devices 29 | 30 | { 31 | "id":1, 32 | "devices":[ 33 | { 34 | "chardev":"dax1.0", 35 | "size":3233808384 36 | } 37 | ] 38 | } 39 | ---- 40 | 41 | OPTIONS 42 | ------- 43 | -r:: 44 | --region=:: 45 | A device-dax region is a contiguous range of memory that 46 | hosts one or more /dev/daxX.Y devices, where X is the region id 47 | and Y is the device instance id. The keyword 'all' can be 48 | specified to carry out the operation on every region in the 49 | system. 50 | 51 | -d:: 52 | --dev=:: 53 | Specify a dax device name, . 54 | tuple, or keyword 'all' to filter the listing. For 55 | example to list the first device instance in region1: 56 | 57 | ---- 58 | # daxctl list --dev=1.0 59 | 60 | { 61 | "chardev":"dax1.0", 62 | "size":3233808384 63 | } 64 | ---- 65 | 66 | -D:: 67 | --devices:: 68 | Include device-dax instance info in the listing (default) 69 | 70 | -M:: 71 | --mappings:: 72 | Include device-dax instance mappings info in the listing 73 | 74 | -R:: 75 | --regions:: 76 | Include region info in the listing 77 | 78 | -i:: 79 | --idle:: 80 | Include idle (not enabled / zero-sized) devices in the listing 81 | 82 | -u:: 83 | --human:: 84 | By default 'daxctl list' will output machine-friendly raw-integer 85 | data. Instead, with this flag, numbers representing storage size 86 | will be formatted as human readable strings with units, other 87 | fields are converted to hexadecimal strings. Example: 88 | 89 | ---- 90 | # daxctl list 91 | { 92 | "chardev":"dax1.0", 93 | "size":32828817408 94 | } 95 | 96 | # daxctl list --human 97 | { 98 | "chardev":"dax1.0", 99 | "size":"30.57 GiB (32.83 GB)" 100 | } 101 | ---- 102 | 103 | include::../copyright.txt[] 104 | -------------------------------------------------------------------------------- /daxctl/lib/libdaxctl.sym: -------------------------------------------------------------------------------- 1 | LIBDAXCTL_1 { 2 | global: 3 | daxctl_get_userdata; 4 | daxctl_set_userdata; 5 | daxctl_ref; 6 | daxctl_get_log_priority; 7 | daxctl_set_log_fn; 8 | daxctl_unref; 9 | daxctl_set_log_priority; 10 | daxctl_new; 11 | local: 12 | *; 13 | }; 14 | 15 | LIBDAXCTL_2 { 16 | global: 17 | daxctl_region_unref; 18 | daxctl_new_region; 19 | daxctl_region_ref; 20 | daxctl_region_unref; 21 | daxctl_region_get_uuid; 22 | daxctl_region_get_id; 23 | daxctl_region_get_ctx; 24 | daxctl_dev_get_first; 25 | daxctl_dev_get_next; 26 | daxctl_dev_get_region; 27 | daxctl_dev_get_id; 28 | daxctl_dev_get_devname; 29 | daxctl_dev_get_major; 30 | daxctl_dev_get_minor; 31 | daxctl_dev_get_size; 32 | } LIBDAXCTL_1; 33 | 34 | LIBDAXCTL_3 { 35 | global: 36 | daxctl_region_get_available_size; 37 | daxctl_region_get_devname; 38 | daxctl_region_get_dev_seed; 39 | } LIBDAXCTL_2; 40 | 41 | LIBDAXCTL_4 { 42 | global: 43 | daxctl_region_get_size; 44 | daxctl_region_get_align; 45 | daxctl_region_get_first; 46 | daxctl_region_get_next; 47 | } LIBDAXCTL_3; 48 | 49 | LIBDAXCTL_5 { 50 | global: 51 | daxctl_region_get_path; 52 | } LIBDAXCTL_4; 53 | 54 | LIBDAXCTL_6 { 55 | global: 56 | daxctl_dev_get_ctx; 57 | daxctl_dev_is_enabled; 58 | daxctl_dev_disable; 59 | daxctl_dev_enable_devdax; 60 | daxctl_dev_enable_ram; 61 | daxctl_dev_get_resource; 62 | daxctl_dev_get_target_node; 63 | daxctl_dev_get_memory; 64 | daxctl_memory_get_dev; 65 | daxctl_memory_get_node_path; 66 | daxctl_memory_get_block_size; 67 | daxctl_memory_online; 68 | daxctl_memory_offline; 69 | daxctl_memory_is_online; 70 | daxctl_memory_num_sections; 71 | } LIBDAXCTL_5; 72 | 73 | LIBDAXCTL_7 { 74 | global: 75 | daxctl_memory_is_movable; 76 | daxctl_memory_online_no_movable; 77 | } LIBDAXCTL_6; 78 | 79 | LIBDAXCTL_8 { 80 | global: 81 | daxctl_dev_set_size; 82 | daxctl_region_create_dev; 83 | daxctl_region_destroy_dev; 84 | daxctl_dev_get_align; 85 | daxctl_dev_set_align; 86 | daxctl_mapping_get_first; 87 | daxctl_mapping_get_next; 88 | daxctl_mapping_get_start; 89 | daxctl_mapping_get_end; 90 | daxctl_mapping_get_offset; 91 | daxctl_mapping_get_size; 92 | daxctl_dev_set_mapping; 93 | } LIBDAXCTL_7; 94 | 95 | LIBDAXCTL_9 { 96 | global: 97 | daxctl_dev_will_auto_online_memory; 98 | daxctl_dev_has_online_memory; 99 | daxctl_set_config_path; 100 | daxctl_get_config_path; 101 | } LIBDAXCTL_8; 102 | 103 | LIBDAXCTL_10 { 104 | global: 105 | daxctl_dev_is_system_ram_capable; 106 | } LIBDAXCTL_9; 107 | -------------------------------------------------------------------------------- /ccan/check_type/check_type.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: CC0-1.0 */ 2 | #ifndef CCAN_CHECK_TYPE_H 3 | #define CCAN_CHECK_TYPE_H 4 | #include "config.h" 5 | 6 | /** 7 | * check_type - issue a warning or build failure if type is not correct. 8 | * @expr: the expression whose type we should check (not evaluated). 9 | * @type: the exact type we expect the expression to be. 10 | * 11 | * This macro is usually used within other macros to try to ensure that a macro 12 | * argument is of the expected type. No type promotion of the expression is 13 | * done: an unsigned int is not the same as an int! 14 | * 15 | * check_type() always evaluates to 0. 16 | * 17 | * If your compiler does not support typeof, then the best we can do is fail 18 | * to compile if the sizes of the types are unequal (a less complete check). 19 | * 20 | * Example: 21 | * // They should always pass a 64-bit value to _set_some_value! 22 | * #define set_some_value(expr) \ 23 | * _set_some_value((check_type((expr), uint64_t), (expr))) 24 | */ 25 | 26 | /** 27 | * check_types_match - issue a warning or build failure if types are not same. 28 | * @expr1: the first expression (not evaluated). 29 | * @expr2: the second expression (not evaluated). 30 | * 31 | * This macro is usually used within other macros to try to ensure that 32 | * arguments are of identical types. No type promotion of the expressions is 33 | * done: an unsigned int is not the same as an int! 34 | * 35 | * check_types_match() always evaluates to 0. 36 | * 37 | * If your compiler does not support typeof, then the best we can do is fail 38 | * to compile if the sizes of the types are unequal (a less complete check). 39 | * 40 | * Example: 41 | * // Do subtraction to get to enclosing type, but make sure that 42 | * // pointer is of correct type for that member. 43 | * #define container_of(mbr_ptr, encl_type, mbr) \ 44 | * (check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \ 45 | * ((encl_type *) \ 46 | * ((char *)(mbr_ptr) - offsetof(enclosing_type, mbr)))) 47 | */ 48 | #if HAVE_TYPEOF 49 | #define check_type(expr, type) \ 50 | ((typeof(expr) *)0 != (type *)0) 51 | 52 | #define check_types_match(expr1, expr2) \ 53 | ((typeof(expr1) *)0 != (typeof(expr2) *)0) 54 | #else 55 | #include 56 | /* Without typeof, we can only test the sizes. */ 57 | #define check_type(expr, type) \ 58 | BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type)) 59 | 60 | #define check_types_match(expr1, expr2) \ 61 | BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2)) 62 | #endif /* HAVE_TYPEOF */ 63 | 64 | #endif /* CCAN_CHECK_TYPE_H */ 65 | -------------------------------------------------------------------------------- /ndctl/libndctl-nfit.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright (C) 2017 Hewlett Packard Enterprise Development LP */ 3 | /* Copyright (C) 2017-2020 Intel Corporation. All rights reserved. */ 4 | #ifndef __LIBNDCTL_NFIT_H__ 5 | #define __LIBNDCTL_NFIT_H__ 6 | 7 | #include 8 | #include 9 | 10 | /* 11 | * libndctl-nfit.h : definitions for NFIT related commands/functions. 12 | */ 13 | 14 | /* nfit command numbers which are called via ND_CMD_CALL */ 15 | enum { 16 | NFIT_CMD_TRANSLATE_SPA = 5, 17 | NFIT_CMD_ARS_INJECT_SET = 7, 18 | NFIT_CMD_ARS_INJECT_CLEAR = 8, 19 | NFIT_CMD_ARS_INJECT_GET = 9, 20 | }; 21 | 22 | /* error number of Translate SPA by firmware */ 23 | #define ND_TRANSLATE_SPA_STATUS_INVALID_SPA 2 24 | 25 | /* status definitions for error injection */ 26 | #define ND_ARS_ERR_INJ_STATUS_NOT_SUPP 1 27 | #define ND_ARS_ERR_INJ_STATUS_INVALID_PARAM 2 28 | 29 | enum err_inj_options { 30 | ND_ARS_ERR_INJ_OPT_NOTIFY = 0, 31 | }; 32 | 33 | /* 34 | * The following structures are command packages which are 35 | * defined by ACPI 6.2 (or later). 36 | */ 37 | 38 | /* For Translate SPA */ 39 | struct nd_cmd_translate_spa { 40 | __u64 spa; 41 | __u32 status; 42 | __u8 flags; 43 | __u8 _reserved[3]; 44 | __u64 translate_length; 45 | __u32 num_nvdimms; 46 | struct nd_nvdimm_device { 47 | __u32 nfit_device_handle; 48 | __u32 _reserved; 49 | __u64 dpa; 50 | } __attribute__((packed)) devices[0]; 51 | 52 | } __attribute__((packed)); 53 | 54 | /* For ARS Error Inject */ 55 | struct nd_cmd_ars_err_inj { 56 | __u64 err_inj_spa_range_base; 57 | __u64 err_inj_spa_range_length; 58 | __u8 err_inj_options; 59 | __u32 status; 60 | } __attribute__((packed)); 61 | 62 | /* For ARS Error Inject Clear */ 63 | struct nd_cmd_ars_err_inj_clr { 64 | __u64 err_inj_clr_spa_range_base; 65 | __u64 err_inj_clr_spa_range_length; 66 | __u32 status; 67 | } __attribute__((packed)); 68 | 69 | /* For ARS Error Inject Status Query */ 70 | struct nd_cmd_ars_err_inj_stat { 71 | __u32 status; 72 | __u32 inj_err_rec_count; 73 | struct nd_error_stat_query_record { 74 | __u64 err_inj_stat_spa_range_base; 75 | __u64 err_inj_stat_spa_range_length; 76 | } __attribute__((packed)) record[0]; 77 | } __attribute__((packed)); 78 | 79 | struct nd_cmd_bus { 80 | struct nd_cmd_pkg gen; 81 | union { 82 | struct nd_cmd_ars_err_inj_stat err_inj_stat; 83 | struct nd_cmd_ars_err_inj_clr err_inj_clr; 84 | struct nd_cmd_ars_err_inj err_inj; 85 | struct nd_cmd_translate_spa xlat_spa; 86 | }; 87 | }; 88 | 89 | int ndctl_bus_is_nfit_cmd_supported(struct ndctl_bus *bus, int cmd); 90 | 91 | #endif /* __LIBNDCTL_NFIT_H__ */ 92 | -------------------------------------------------------------------------------- /Documentation/ndctl/ndctl-sanitize-dimm.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | ndctl-sanitize-dimm(1) 4 | ====================== 5 | 6 | NAME 7 | ---- 8 | ndctl-sanitize-dimm - Perform a cryptographic destruction or overwrite of 9 | the contents of the given NVDIMM(s) 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | 'ndctl sanitize-dimm' [..] [] 15 | 16 | DESCRIPTION 17 | ----------- 18 | The 'sanitize-dimm' command performs a cryptographic destruction of the 19 | contents of the given NVDIMM. It scrambles the data, and any metadata or 20 | info-blocks, but it doesn't modify namespace labels. Therefore, any 21 | namespaces on regions associated with the given NVDIMM will be retained, 22 | but they will end up in the 'raw' mode. 23 | 24 | Additionally, after completion of this command, the security and passphrase 25 | for the given NVDIMM will be disabled, and the passphrase and any key material 26 | will also be removed from the keyring and the ndctl keys directory at 27 | {ndctl_keysdir} 28 | 29 | The command supports two different methods of performing the cryptographic 30 | erase. The default is 'crypto-erase', but additionally, an 'overwrite' option 31 | is available which overwrites not only the data area, but also the label area, 32 | thus losing record of any namespaces the given NVDIMM participates in. 33 | 34 | OPTIONS 35 | ------- 36 | :: 37 | include::xable-dimm-options.txt[] 38 | 39 | -b:: 40 | --bus=:: 41 | include::xable-bus-options.txt[] 42 | 43 | -c:: 44 | --crypto-erase:: 45 | Replace the media encryption key on the NVDIMM causing all existing 46 | data to read as cipher text with the new key. This does not change 47 | label data. Namespaces get reverted to raw mode. 48 | 49 | -o:: 50 | --overwrite:: 51 | Wipe the entire DIMM, including label data. This can take significant 52 | time, and the command is non-blocking. With this option, the overwrite 53 | request is merely submitted to the NVDIMM, and the completion is 54 | asynchronous. Depending on the medium and capacity, overwrite may take 55 | tens of minutes to many hours. 56 | 57 | -m:: 58 | --master-passphrase:: 59 | Indicate that we are using the master passphrase to perform the erase. 60 | This only is applicable to the 'crypto-erase' option. 61 | 62 | -z:: 63 | --zero-key:: 64 | Passing in a key with payload that is just 0's. 65 | 66 | --verbose:: 67 | Emit debug messages. 68 | 69 | include::intel-nvdimm-security.txt[] 70 | 71 | include::../copyright.txt[] 72 | 73 | SEE ALSO 74 | -------- 75 | linkndctl:ndctl-wait-overwrite[1], https://trustedcomputinggroup.org/wp-content/uploads/TCG_SWG_SIIS_Version_1_07_Revision_1_00.pdf 76 | -------------------------------------------------------------------------------- /scripts/do_abidiff: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | range="$*" 4 | old="${range%%..*}" 5 | new="${range##*..}" 6 | 7 | err() 8 | { 9 | echo "$1" 10 | exit 1 11 | } 12 | 13 | build_rpm() 14 | { 15 | local cur=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) 16 | local ref="$1" 17 | local version="" 18 | 19 | # prepare ndctl tree 20 | rm -rf results_ndctl build 21 | git checkout -b rel_${ref} $ref 22 | meson setup build 23 | meson compile -C build rhel/ndctl.spec 24 | cp build/rhel/ndctl.spec . 25 | 26 | # build and copy RPMs 27 | version="$(./git-version)" 28 | release="f$(basename $(readlink -f /etc/mock/default.cfg) | cut -d- -f2)" 29 | git archive --format=tar --prefix="ndctl-${version}/" HEAD | gzip > ndctl-${version}.tar.gz 30 | fedpkg --release $release --name=ndctl mockbuild 31 | [ "$?" -eq 0 ] || err "error building $ref" 32 | mkdir -p release/rel_${ref}/ 33 | cp results_ndctl/*/*/*.x86_64.rpm release/rel_${ref}/ 34 | 35 | # restore ndctl branch and cleanup 36 | git checkout $cur 37 | git branch -D rel_${ref} 38 | rm ndctl-${version}.tar.gz 39 | rm ndctl-${version}*.src.rpm 40 | rm -rf results_ndctl 41 | rm -f ndctl.spec 42 | } 43 | 44 | do_diff() 45 | { 46 | local pkg="$1" 47 | local old_base="$(find . -regex "./release/rel_${old}/${pkg}[-cli]*-[0-9]+.*" | head -1)" 48 | local new_base="$(find . -regex "./release/rel_${new}/${pkg}[-cli]*-[0-9]+.*" | head -1)" 49 | local old_dev="$(find . -regex "./release/rel_${old}/${pkg}-devel-[0-9]+.*" | head -1)" 50 | local new_dev="$(find . -regex "./release/rel_${new}/${pkg}-devel-[0-9]+.*" | head -1)" 51 | local old_lib="$(find . -regex "./release/rel_${old}/${pkg}-libs-[0-9]+.*" | head -1)" 52 | local new_lib="$(find . -regex "./release/rel_${new}/${pkg}-libs-[0-9]+.*" | head -1)" 53 | 54 | [ -n "$pkg" ] || err "specify a package for diff (ndctl, daxctl, cxl)" 55 | [ -n "$old_base" ] || err "$pkg: old_base empty, possible build failure" 56 | [ -n "$new_base" ] || err "$pkg: new_base empty, possible build failure" 57 | 58 | abipkgdiff --dso-only --no-added-syms --harmless --drop-private-types \ 59 | --devel1 "$old_dev" --devel2 "$new_dev" \ 60 | "$old_base" "$new_base" 61 | abipkgdiff --no-added-syms --harmless --drop-private-types \ 62 | --devel1 "$old_dev" --devel2 "$new_dev" \ 63 | "$old_lib" "$new_lib" 64 | } 65 | 66 | [ -e "COPYING" ] || err "Run from the top level of an ndctl tree" 67 | if ! command -v "abipkgdiff" >/dev/null; then 68 | err "missing abipkgdiff. Please install libabigail" 69 | fi 70 | rm -rf release/rel* 71 | 72 | build_rpm $old > release/buildlog_$old 2>&1 73 | build_rpm $new > release/buildlog_$new 2>&1 74 | do_diff ndctl 75 | do_diff daxctl 76 | do_diff cxl 77 | --------------------------------------------------------------------------------