ndctl: Back-Invalidate support
Subsystems (2)
cover ndctl: Back-Invalidate support
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/[email protected]/
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
Signature · 1 line
2.39.5
PATCH 1/2 test/cxl-back-invalidate.sh: add a Back-Invalidate region test
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.
--- test/cxl-back-invalidate.sh | 111 ++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 113 insertions(+) create mode 100755 test/cxl-back-invalidate.sh
test/cxl-back-invalidate.sh new file +111 -0
@@ -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
test/meson.build +2 -0
@@ -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()
Signature · 1 line
2.39.5
PATCH 2/2 libcxl: report Back-Invalidate decoder state
In reply to Davidlohr BuesoThe 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
}--- 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(+)
Documentation/cxl/lib/libcxl.txt +2 -0
@@ -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
cxl/json.c +16 -0
@@ -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);
cxl/lib/libcxl.c +15 -0
@@ -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;
cxl/lib/libcxl.sym +6 -0
@@ -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;
cxl/lib/private.h +2 -0
@@ -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;
cxl/libcxl.h +2 -0
@@ -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);
Signature · 1 line
2.39.5
Alison Schofield
AppliedQuoted 20 lines · Davidlohr Bueso
Hello,
The kernel's Back-Invalidate series, now in cxl/next [1], adds two sysfs
attributes:cap_back_invalidateon a root decoder, set for a CFMWS window carrying the BI restriction, andback_invalidateon an endpoint decoder, set while it decodes an HDM-DB region. It also givescxl_testa BI window with BI-capable endpoints below it.Patch 1 adds a
cxl_testunit test: a region created on the BI root decoder comes up device-coherent withback_invalidateset, and acxl_acpirebind 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_capableon a root decoder andback_invalidateon an endpoint decoder.Tested with meson test --suite cxl against cxl/next
d337784de533, 17/17 with this test included.
Quoted 7 lines
[1] https://lore.kernel.org/all/[email protected]/
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