* [PATCH -ndctl 0/2] ndctl: Back-Invalidate support
@ 2026-11-19 2:30 Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 1/2] test/cxl-back-invalidate.sh: add a Back-Invalidate region test Davidlohr Bueso
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2026-11-19 2:30 UTC (permalink / raw)
To: alison.schofield; +Cc: dave.jiang, linux-cxl, dave
Hello,
The kernel's Back-Invalidate series, now in cxl/next [1], adds two sysfs
attributes: cap_back_invalidate on a root decoder, set for a CFMWS
window carrying the BI restriction, and back_invalidate on an endpoint
decoder, set while it decodes an HDM-DB region. It also gives cxl_test
a BI window with BI-capable endpoints below it.
Patch 1 adds a cxl_test unit test: a region created on the BI root
decoder comes up device-coherent with back_invalidate set, and a
cxl_acpi rebind replays it with the model intact. It skips on kernels
without a BI window.
Patch 2 has libcxl read both attributes, reported by cxl list as
back_invalidate_capable on a root decoder and back_invalidate on an
endpoint decoder.
Tested with meson test --suite cxl against cxl/next d337784de533, 17/17
with this test included.
[1] https://lore.kernel.org/all/cover.1794172701.git.dave@stgolabs.net/
Thanks!
Davidlohr Bueso (2):
test/cxl-back-invalidate.sh: add a Back-Invalidate region test
libcxl: report Back-Invalidate decoder state
Documentation/cxl/lib/libcxl.txt | 2 +
cxl/json.c | 16 +++++
cxl/lib/libcxl.c | 15 +++++
cxl/lib/libcxl.sym | 6 ++
cxl/lib/private.h | 2 +
cxl/libcxl.h | 2 +
test/cxl-back-invalidate.sh | 111 +++++++++++++++++++++++++++++++
test/meson.build | 2 +
8 files changed, 156 insertions(+)
create mode 100755 test/cxl-back-invalidate.sh
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] test/cxl-back-invalidate.sh: add a Back-Invalidate region test
2026-11-19 2:30 [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Davidlohr Bueso
@ 2026-11-19 2:30 ` Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 2/2] libcxl: report Back-Invalidate decoder state Davidlohr Bueso
2026-11-19 21:56 ` [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Alison Schofield
2 siblings, 0 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2026-11-19 2:30 UTC (permalink / raw)
To: alison.schofield; +Cc: dave.jiang, linux-cxl, dave
cxl_test now mocks a Back-Invalidate topology: an HDM-DB window that
parses into a root decoder with cap_back_invalidate set, and BI capable
endpoints below it.
Test the coherency model a region inherits from that window: create a
region on the BI root decoder, verify the endpoint decoder came up
device-coherent with back_invalidate set, and that a cxl_acpi rebind
replays the region with the model intact. Both attributes are read from
sysfs. Skip when no BI window is present.
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
test/cxl-back-invalidate.sh | 111 ++++++++++++++++++++++++++++++++++++
test/meson.build | 2 +
2 files changed, 113 insertions(+)
create mode 100755 test/cxl-back-invalidate.sh
diff --git a/test/cxl-back-invalidate.sh b/test/cxl-back-invalidate.sh
new file mode 100755
index 000000000000..804ba63af5a8
--- /dev/null
+++ b/test/cxl-back-invalidate.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. $(dirname $0)/common
+
+rc=77
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test
+
+CXLDEV=/sys/bus/cxl/devices
+
+# A Back-Invalidate capable window is advertised by the root decoder as
+# cap_back_invalidate. Without one the kernel has no BI support, or
+# cxl_test predates the mock BI topology.
+find_bi_root()
+{
+ local d
+
+ for d in $CXLDEV/decoder*; do
+ [ -e "$d/cap_back_invalidate" ] || continue
+ [ "$(cat $d/cap_back_invalidate)" = 1 ] || continue
+ basename "$d"
+ return
+ done
+}
+
+bi_root=$(find_bi_root)
+if [ -z "$bi_root" ]; then
+ do_skip "test requires a back-invalidate capable window"
+fi
+
+# Replay support is exposed by cxl_acpi after cxl_test loads
+if [ ! -e /sys/bus/platform/devices/cxl_acpi.0/decoder_reset_preserve_registry ]; then
+ do_skip "test requires decoder registry replay support"
+fi
+
+rc=1
+
+# A region under a BI window is HDM-DB: device-coherent, with the BI bit
+# programmed into the endpoint decoder at commit. Only memdevs below the
+# host bridge the window targets can attach to it.
+create_bi_region()
+{
+ local port_dev mem
+
+ port_dev=$("$CXL" list -T -d "$bi_root" |
+ jq -r ".[] | .targets | .[0].target")
+ [[ $port_dev ]] || return 1
+
+ for mem in $("$CXL" list -M -p "$port_dev" | jq -r ".[].memdev"); do
+ BI_REGION=$("$CXL" create-region -d "$bi_root" -m "$mem" \
+ -t ram 2>/dev/null | jq -r ".region")
+ [[ $BI_REGION && $BI_REGION != null ]] || continue
+
+ BI_DECODER=$("$CXL" list -R --targets -r "$BI_REGION" |
+ jq -r ".[0].mappings | .[0].decoder")
+ [[ $BI_DECODER && $BI_DECODER != null ]] || return 1
+ return 0
+ done
+
+ echo "no memdev below $port_dev could back a region on $bi_root"
+ return 1
+}
+
+BI_REGION=""
+BI_DECODER=""
+create_bi_region || err "$LINENO"
+
+# The endpoint decoder inherits the window's coherency model: HDM-DB is
+# device-coherent with the BI bit set.
+[ "$(cat $CXLDEV/$BI_DECODER/back_invalidate)" = "1" ] || err "$LINENO"
+[ "$(cat $CXLDEV/$BI_DECODER/target_type)" = "accelerator" ] || err "$LINENO"
+
+[ "$(cat $CXLDEV/$BI_REGION/commit)" = "1" ] || err "$LINENO"
+
+# The committed HDM-DB region must survive a cxl_acpi rebind and come
+# back with its coherency model intact.
+replay_regions || err "$LINENO"
+
+bi_root=$(find_bi_root)
+[ -n "$bi_root" ] || err "$LINENO"
+
+replayed=""
+for r in $CXLDEV/region*; do
+ [ -d "$r" ] || continue
+ [ "$(cat "$r/commit" 2>/dev/null)" = "1" ] || continue
+ readlink -f "$r" | grep -q "/$bi_root/" || continue
+ [ -z "$replayed" ] || err "$LINENO"
+ replayed=$(basename "$r")
+done
+[ -n "$replayed" ] || err "$LINENO"
+
+# decoder ids are not stable across the rebind, so ask the replayed
+# region which endpoint decoder it came back on.
+replayed_dec=$("$CXL" list -R --targets -r "$replayed" |
+ jq -r ".[0].mappings | .[0].decoder")
+[[ $replayed_dec && $replayed_dec != null ]] || err "$LINENO"
+[ "$(cat $CXLDEV/$replayed_dec/back_invalidate)" = "1" ] || err "$LINENO"
+
+"$CXL" destroy-region -f -b "$CXL_TEST_BUS" "$replayed"
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
diff --git a/test/meson.build b/test/meson.build
index 56aed9cc3c9d..53297e8fcbfa 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -171,6 +171,7 @@ cxl_translate = find_program('cxl-translate.sh')
cxl_elc = find_program('cxl-elc.sh')
cxl_dax_hmem = find_program('cxl-dax-hmem.sh')
cxl_region_replay = find_program('cxl-region-replay.sh')
+cxl_back_invalidate = find_program('cxl-back-invalidate.sh')
tests = [
[ 'libndctl', libndctl, 'ndctl' ],
@@ -207,6 +208,7 @@ tests = [
[ 'cxl-elc.sh', cxl_elc, 'cxl' ],
[ 'cxl-dax-hmem.sh', cxl_dax_hmem, 'cxl' ],
[ 'cxl-region-replay.sh', cxl_region_replay, 'cxl' ],
+ [ 'cxl-back-invalidate.sh', cxl_back_invalidate, 'cxl' ],
]
if get_option('destructive').enabled()
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] libcxl: report Back-Invalidate decoder state
2026-11-19 2:30 [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 1/2] test/cxl-back-invalidate.sh: add a Back-Invalidate region test Davidlohr Bueso
@ 2026-11-19 2:30 ` Davidlohr Bueso
2026-11-19 21:56 ` [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Alison Schofield
2 siblings, 0 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2026-11-19 2:30 UTC (permalink / raw)
To: alison.schofield; +Cc: dave.jiang, linux-cxl, dave
The kernel exposes two Back-Invalidate attributes: cap_back_invalidate
on a root decoder, for a CFMWS window carrying the BI restriction, and
back_invalidate on an endpoint decoder, set while it decodes an HDM-DB
region. Update libcxl accordingly.
A root decoder whose window permits BI:
{
"decoder":"decoder0.6",
"resource":70308077764608,
"size":1073741824,
"interleave_ways":1,
"accelmem_capable":true,
"back_invalidate_capable":true,
"qos_class":42,
"nr_targets":1
}
An endpoint decoder currently decoding a region under it:
{
"decoder":"decoder9.0",
"resource":70308077764608,
"size":1073741824,
"interleave_ways":1,
"region":"region6",
"dpa_resource":0,
"dpa_size":1073741824,
"mode":"ram",
"back_invalidate":true
}
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
Documentation/cxl/lib/libcxl.txt | 2 ++
cxl/json.c | 16 ++++++++++++++++
cxl/lib/libcxl.c | 15 +++++++++++++++
cxl/lib/libcxl.sym | 6 ++++++
cxl/lib/private.h | 2 ++
cxl/libcxl.h | 2 ++
6 files changed, 43 insertions(+)
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
index 5c3ebd4b786b..187e19f99ec0 100644
--- a/Documentation/cxl/lib/libcxl.txt
+++ b/Documentation/cxl/lib/libcxl.txt
@@ -461,6 +461,8 @@ bool cxl_decoder_is_pmem_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_volatile_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_mem_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_accelmem_capable(struct cxl_decoder *decoder);
+bool cxl_decoder_is_back_invalidate_capable(struct cxl_decoder *decoder);
+bool cxl_decoder_is_back_invalidate(struct cxl_decoder *decoder);
bool cxl_decoder_is_locked(struct cxl_decoder *decoder);
----
The kernel protects the enumeration of the physical address layout of
diff --git a/cxl/json.c b/cxl/json.c
index a92548828582..ae4a936cf26c 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -927,6 +927,22 @@ struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
jobj);
}
+ if (cxl_port_is_root(port) &&
+ cxl_decoder_is_back_invalidate_capable(decoder)) {
+ jobj = json_object_new_boolean(true);
+ if (jobj)
+ json_object_object_add(jdecoder,
+ "back_invalidate_capable", jobj);
+ }
+
+ if (cxl_port_is_endpoint(port) &&
+ cxl_decoder_is_back_invalidate(decoder)) {
+ jobj = json_object_new_boolean(true);
+ if (jobj)
+ json_object_object_add(jdecoder, "back_invalidate",
+ jobj);
+ }
+
if (cxl_port_is_root(port)) {
int qos_class = cxl_root_decoder_get_qos_class(decoder);
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index e55a7b41d77a..fa8dc8b1ab3e 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -2490,6 +2490,9 @@ static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
switch (port->type) {
case CXL_PORT_ENDPOINT:
+ sprintf(path, "%s/back_invalidate", cxldecoder_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0)
+ decoder->back_invalidate = !!strtoul(buf, NULL, 0);
sprintf(path, "%s/dpa_resource", cxldecoder_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
decoder->dpa_resource = ULLONG_MAX;
@@ -2528,6 +2531,8 @@ static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
{ "cap_type3", &decoder->mem_capable },
{ "cap_ram", &decoder->volatile_capable },
{ "cap_pmem", &decoder->pmem_capable },
+ { "cap_back_invalidate",
+ &decoder->back_invalidate_capable },
{ "locked", &decoder->locked },
};
@@ -2839,6 +2844,16 @@ CXL_EXPORT bool cxl_decoder_is_accelmem_capable(struct cxl_decoder *decoder)
return decoder->accelmem_capable;
}
+CXL_EXPORT bool cxl_decoder_is_back_invalidate_capable(struct cxl_decoder *decoder)
+{
+ return decoder->back_invalidate_capable;
+}
+
+CXL_EXPORT bool cxl_decoder_is_back_invalidate(struct cxl_decoder *decoder)
+{
+ return decoder->back_invalidate;
+}
+
CXL_EXPORT bool cxl_decoder_is_locked(struct cxl_decoder *decoder)
{
return decoder->locked;
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
index ed4429f175ef..599d45e07350 100644
--- a/cxl/lib/libcxl.sym
+++ b/cxl/lib/libcxl.sym
@@ -320,3 +320,9 @@ LIBCXL_12 {
global:
cxl_region_locked_state;
} LIBCXL_11;
+
+LIBCXL_13 {
+global:
+ cxl_decoder_is_back_invalidate_capable;
+ cxl_decoder_is_back_invalidate;
+} LIBCXL_12;
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
index d2d71fc1a9f0..e5e532c52611 100644
--- a/cxl/lib/private.h
+++ b/cxl/lib/private.h
@@ -161,6 +161,8 @@ struct cxl_decoder {
bool volatile_capable;
bool mem_capable;
bool accelmem_capable;
+ bool back_invalidate_capable;
+ bool back_invalidate;
bool locked;
enum cxl_decoder_target_type target_type;
int regions_init;
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
index e91af905be3a..fcc1340d02b2 100644
--- a/cxl/libcxl.h
+++ b/cxl/libcxl.h
@@ -265,6 +265,8 @@ bool cxl_decoder_is_pmem_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_volatile_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_mem_capable(struct cxl_decoder *decoder);
bool cxl_decoder_is_accelmem_capable(struct cxl_decoder *decoder);
+bool cxl_decoder_is_back_invalidate_capable(struct cxl_decoder *decoder);
+bool cxl_decoder_is_back_invalidate(struct cxl_decoder *decoder);
bool cxl_decoder_is_locked(struct cxl_decoder *decoder);
unsigned int
cxl_decoder_get_interleave_granularity(struct cxl_decoder *decoder);
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -ndctl 0/2] ndctl: Back-Invalidate support
2026-11-19 2:30 [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 1/2] test/cxl-back-invalidate.sh: add a Back-Invalidate region test Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 2/2] libcxl: report Back-Invalidate decoder state Davidlohr Bueso
@ 2026-11-19 21:56 ` Alison Schofield
2 siblings, 0 replies; 4+ messages in thread
From: Alison Schofield @ 2026-11-19 21:56 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: dave.jiang, linux-cxl
On Wed, Nov 18, 2026 at 06:30:26PM -0800, Davidlohr Bueso wrote:
> Hello,
>
> The kernel's Back-Invalidate series, now in cxl/next [1], adds two sysfs
> attributes: cap_back_invalidate on a root decoder, set for a CFMWS
> window carrying the BI restriction, and back_invalidate on an endpoint
> decoder, set while it decodes an HDM-DB region. It also gives cxl_test
> a BI window with BI-capable endpoints below it.
>
> Patch 1 adds a cxl_test unit test: a region created on the BI root
> decoder comes up device-coherent with back_invalidate set, and a
> cxl_acpi rebind replays it with the model intact. It skips on kernels
> without a BI window.
>
> Patch 2 has libcxl read both attributes, reported by cxl list as
> back_invalidate_capable on a root decoder and back_invalidate on an
> endpoint decoder.
>
> Tested with meson test --suite cxl against cxl/next d337784de533, 17/17
> with this test included.
>
> [1] https://lore.kernel.org/all/cover.1794172701.git.dave@stgolabs.net/
>
> Thanks!
>
> Davidlohr Bueso (2):
> test/cxl-back-invalidate.sh: add a Back-Invalidate region test
> libcxl: report Back-Invalidate decoder state
Hi Dave,
Thanks for the patches!
Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commits/pending/
I did minor touchups:
libcxl patch:
[ as: document BI decoder state in libcxl.txt ]
test patch:
[ as: check BI fields in cxl list, fail on missing BI window from 7.5 ]
I also reordered the patches so the libcxl patch comes first. That lets
the test check the new cxl list fields without breaking bisect.
If you want other/different changes, let me know.
-- Alison
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 21:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 2:30 [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 1/2] test/cxl-back-invalidate.sh: add a Back-Invalidate region test Davidlohr Bueso
2026-11-19 2:30 ` [PATCH 2/2] libcxl: report Back-Invalidate decoder state Davidlohr Bueso
2026-11-19 21:56 ` [PATCH -ndctl 0/2] ndctl: Back-Invalidate support Alison Schofield
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox