cxl: Support Back-Invalidate
Subsystems (2)
Davidlohr Bueso
maintainerv9 cover cxl: Support Back-Invalidate
Hello,
Changes from v8 (https://lore.kernel.org/all/[email protected]/):
- Patch 2: small cleanups (Jonathan)
- Patch 2: cxl_bi_reset_detected() upgraded to dev_warn (Ming)
- Patch 2: increased commit timeout from 5s to 20s.
- Patch 4: fixed a race when a reset occurs while commiting a decoder (sashiko)
- Patch 4: extra safety check in HDM-H region refuses a Type 2 device outright.
- Patch 4: also program the ISP (Interleave Set Position), per Table 8-123.
- Patch 7: fixed the bogus code movement (Jonathan)
- Patch 8: changelog cleanups
- Patch 8: fixed rollback to only cleanup after the levels that were not adopted.
- Collected Reviewed-by tags.
This series is the plumbing to enable HDM-DB in Linux. The model allows Type 2 and Type 3 devices to expose their local memory to the host CPU in a coherent manner. In alignment with what was discussed at 2024 LPC type2 support session, this series takes the Type 3 memory expander approach, which is more direct. Further, afaik there is no Type 2 + BI hardware out there.
A flagship use case of Type 3 + BI is coherent shared memory, and there is currently a big gap in this regard (ie: GFAM). Another is P2P via PCIe UIO, which is also lacking today. Media Operation (4402h) for ranged sanitize/zero also trigger snoops and there are some patches out there[0]. As such this series focuses on BI enablement in terms of discovery and configuration.
The idea is for Type 3 memdevs and Type 2 devices to make use of cxlds->bi when committing HDM decoders, such that different device coherence models can be differentiated as:
type2 hdm-d: cxlds->type == CXL_DEVTYPE_DEVMEM && cxlds->bi == false type2 hdm-db: cxlds->type == CXL_DEVTYPE_DEVMEM && cxlds->bi == true type3 hdm-h: cxlds->type == CXL_DEVTYPE_CLASSMEM && cxlds->bi == false type3 hdm-db: cxlds->type == CXL_DEVTYPE_CLASSMEM && cxlds->bi == true
An auto-committed BI decoder found during enumeration is adopted when the device and its path are BI capable, and only broken combinations are refused (patches 7-8). See the auto-discovery tests section below.
o Patch 1 probes BI capabilities during register discovery, and maps BI Decoder registers.
o Patch 2 implements the BI-ID allocation (and deallocation) from the endpoint port's lifecycle, at any switch depth, and detects a reset that wiped the device's BI Enable.
o Patch 3 adds coherency support for endpoint decoders based on what the root decoder restricts.
o Patch 4 adds support for HDM-DB region creation.
o Patch 5 trivially renames some coherency flags.
o Patch 6 logs the coherency model (HDM-H, HDM-D, HDM-DB) when a region is created.
o Patch 7 splits the BI capability walk from BI-ID allocation so the answer is available when committed decoders are first parsed.
o Patch 8 allows committed BI decoders. Overall this series could be picked up with or without this patch.
o Patch 9 adds a mock BI topology to cxl_test.
o Patch 10 updates the maturity map.
Testing
-------
The qemu-based test suite covers 35 topologies, including cascaded switches, interleaves across switches, firmware-adopted paths, device hotplug, resets and AER recovery:
https://github.com/davidlohr/cxl-bi-tests
This passes regression testing (nothing breaks) ndctl suite via cxl_test, with the mock HDM-DB window of patch 9 and the BI phase covering HDM-DB assembly, cxl_acpi rebind replay and the Type 2 accelerator. The BI mock device test script along with tooling to consume the new sysfs ABI from this series is in the ndctl tree here:
https://github.com/davidlohr/ndctl/tree/cxl-back-invalidate-test
1. HDM Decoder with BI through ad-hoc region creation.
------------------------------------------------------
# cxl list -D
[
{
"decoder":"decoder0.0",
"resource":6710886400,
"size":4294967296,
"interleave_ways":1,
"accelmem_capable":true,
"nr_targets":1
}
]
# echo region0 > $ROOT/create_ram_region
[ 24.993387] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0
# echo ram > $EP/mode
# echo 0x40000000 > $EP/dpa_size
# echo 1 > $REG/interleave_ways
# echo 4096 > $REG/interleave_granularity
# echo 0x40000000 > $REG/size
# cat $EP/back_invalidate
0
# echo decoder2.0 > $REG/target0
[ 25.297164] cxl_core:cxl_port_attach_region:1337: cxl region0: mem0:endpoint2 decoder2.0 add: mem0:decoder2.0 @ 0 next: none nr_eps: 1 nr_targets: 1
[ 25.298015] cxl_core:cxl_port_attach_region:1337: cxl region0: pci0000:0c:port1 decoder1.0 add: mem0:decoder2.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1
[ 25.298028] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port1 iw: 1 ig: 4096
[ 25.298033] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem0:decoder2.0 @ 0
[ 25.298100] cxl_core:cxl_calc_interleave_pos:2095: cxl_mem mem0: decoder:decoder2.0 parent:0000:0d:00.0 port:endpoint2 range:0x190000000-0x1cfffffff pos:0
[ 25.298107] cxl_core:cxl_region_attach:2345: cxl decoder2.0: Test cxl_calc_interleave_pos(): success test_pos:0 target->pos:0
# cat $EP/back_invalidate
1
# echo 1 > $REG/commit
# cat $EP/back_invalidate
1
# cxl list -D
[
{
"root decoders":[
{
"decoder":"decoder0.0",
"resource":6710886400,
"size":4294967296,
"interleave_ways":1,
"accelmem_capable":true,
"nr_targets":1
}
]
},
{
"port decoders":[
{
"decoder":"decoder1.0",
"resource":6710886400,
"size":1073741824,
"interleave_ways":1,
"region":"region0",
"nr_targets":1
}
]
},
{
"endpoint decoders":[
{
"decoder":"decoder2.0",
"resource":6710886400,
"size":1073741824,
"interleave_ways":1,
"region":"region0",
"dpa_resource":0,
"dpa_size":1073741824,
"mode":"ram"
}
]
}
]2. Type3 device does not support BI, but CFMW has BI restriction
----------------------------------------------------------------
# echo decoder3.0 > $REG/target0 [ 23.899220] cxl region0: mem0:decoder3.0 BI not enabled on device [ 23.899232] cxl_port endpoint3: failed to attach decoder3.0 to region0: -6
3. Type3 device supports BI but CFMW does not, create HDM-H region
------------------------------------------------------------------
# cxl list -D
[
{
"decoder":"decoder0.0",
"resource":6710886400,
"size":4294967296,
"interleave_ways":1,
"max_available_extent":4294967296,
"pmem_capable":true,
"volatile_capable":true,
"accelmem_capable":true,
"nr_targets":1
}
]
# echo region0 > $ROOT/create_ram_region
[ 31.490138] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-H region0
# cat $EP/back_invalidate
0
# echo decoder3.0 > $REG/target0
[ 31.632582] cxl_core:cxl_port_attach_region:1337: cxl region0: mem0:endpoint3 decoder3.0 add: mem0:decoder3.0 @ 0 next: none nr_eps: 1 nr_targets: 1
[ 31.633610] cxl_core:cxl_port_attach_region:1337: cxl region0: 0000:0d:00.0:port2 decoder2.0 add: mem0:decoder3.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1
[ 31.634202] cxl_core:cxl_port_attach_region:1337: cxl region0: pci0000:0c:port1 decoder1.0 add: mem0:decoder3.0 @ 0 next: 0000:0d:00.0 nr_eps: 1 nr_targets: 1
[ 31.634213] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port1 iw: 1 ig: 4096
[ 31.634220] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem0:decoder3.0 @ 0
[ 31.634229] cxl_core:cxl_port_setup_targets:1656: cxl region0: 0000:0d:00.0:port2 iw: 1 ig: 4096
[ 31.634233] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:0d:00.0:port2 target[0] = 0000:0e:00.0 for mem0:decoder3.0 @ 0
[ 31.634308] cxl_core:cxl_calc_interleave_pos:2095: cxl_mem mem0: decoder:decoder3.0 parent:0000:0f:00.0 port:endpoint3 range:0x190000000-0x1cfffffff pos:0
[ 31.634315] cxl_core:cxl_region_attach:2345: cxl decoder3.0: Test cxl_calc_interleave_pos(): success test_pos:0 target->pos:0
# echo 1 > $REG/commit
# cat $EP/back_invalidate
04. Unbind + Bind
----------------
# echo mem0 > /sys/bus/cxl/drivers/cxl_mem/unbind [ 26.194997] cxl_core:cxl_port_commit_reap:896: cxl_port endpoint2: reap: decoder2.0 commit_end: -1 [ 26.197733] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests disabled [ 26.201748] cxl_core:cxl_detach_ep:1564: cxl_mem mem0: disconnect mem0 from port1 # echo mem0 > /sys/bus/cxl/drivers/cxl_mem/bind [ 26.256271] cxl_core:devm_cxl_enumerate_ports:1879: cxl_mem mem0: scan: iter: mem0 dport_dev: 0000:0c:00.0 parent: pci0000:0c [ 26.256292] cxl_core:devm_cxl_enumerate_ports:1885: cxl_mem mem0: found already registered port port1:pci0000:0c [ 26.269012] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests enabled [ 26.291271] cxl_core:init_hdm_decoder:1124: cxl_port endpoint2: decoder2.0: range: 0x0-0xffffffffffffffff iw: 1 ig: 4096 [ 26.293837] cxl_core:add_hdm_decoder:39: cxl_mem mem0: decoder2.0 added to endpoint2 [ 26.307375] cxl_core:cxl_bus_probe:2307: cxl_port endpoint2: probe: 0 [ 26.308261] cxl_core:cxl_bus_probe:2307: cxl_mem mem0: probe: 0
The same applies to the endpoint port, with the memdev rebind recovering the endpoint:
# echo endpoint2 > /sys/bus/cxl/drivers/cxl_port/unbind [ 28.405676] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests disabled [ 28.407658] cxl_core:cxl_detach_ep:1564: cxl_mem mem0: disconnect mem0 from port1 # echo mem0 > /sys/bus/cxl/drivers/cxl_mem/bind [ 28.434197] cxl_core:devm_cxl_enumerate_ports:1879: cxl_mem mem0: scan: iter: mem0 dport_dev: 0000:0c:00.0 parent: pci0000:0c [ 28.434212] cxl_core:devm_cxl_enumerate_ports:1885: cxl_mem mem0: found already registered port port1:pci0000:0c [ 28.443657] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests enabled [ 28.463701] cxl_core:init_hdm_decoder:1124: cxl_port endpoint2: decoder2.0: range: 0x0-0xffffffffffffffff iw: 1 ig: 4096 [ 28.465437] cxl_core:add_hdm_decoder:39: cxl_mem mem0: decoder2.0 added to endpoint2 [ 28.477717] cxl_core:cxl_bus_probe:2307: cxl_port endpoint2: probe: 0 [ 28.478784] cxl_core:cxl_bus_probe:2307: cxl_mem mem0: probe: 0
From a cold boot, without a region ever created, the endpoint port unbind only disables BI - there is no committed decoder to reap:
# echo endpoint2 > /sys/bus/cxl/drivers/cxl_port/unbind [ 23.966972] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests disabled [ 23.974945] cxl_core:cxl_detach_ep:1564: cxl_mem mem0: disconnect mem0 from port1 # echo mem0 > /sys/bus/cxl/drivers/cxl_mem/bind [ 24.027859] cxl_core:devm_cxl_enumerate_ports:1879: cxl_mem mem0: scan: iter: mem0 dport_dev: 0000:0c:00.0 parent: pci0000:0c [ 24.028120] cxl_core:devm_cxl_enumerate_ports:1885: cxl_mem mem0: found already registered port port1:pci0000:0c [ 24.044858] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests enabled [ 24.066776] cxl_core:init_hdm_decoder:1124: cxl_port endpoint2: decoder2.0: range: 0x0-0xffffffffffffffff iw: 1 ig: 256 [ 24.071118] cxl_core:add_hdm_decoder:39: cxl_mem mem0: decoder2.0 added to endpoint2 [ 24.093375] cxl_core:cxl_bus_probe:2307: cxl_port endpoint2: probe: 0 [ 24.095149] cxl_core:cxl_bus_probe:2307: cxl_mem mem0: probe: 0
5. Discovery behind a Switch
----------------------------
One BI-capable device on a switch downstream port, the switch under a root port, all in 256B flit. The capability walk finds a BI Decoder on the device, the root port and the downstream port, and the route table on the switch upstream port:
[ 4.586464] cxl_core:cxl_probe_component_regs:103: cxl_pci 0000:0f:00.0: found BI Decoder capability (0xab4) [ 4.614453] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0c:00.0: found BI Decoder capability (0xab4) [ 4.626522] cxl_core:cxl_probe_component_regs:97: cxl_port port2: found BI RT capability (0xaa8) [ 4.659230] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0e:00.0: found BI Decoder capability (0xab4) [ 4.886128] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:0e:00.0: BI-ID commit wait took 205136us [ 5.086370] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port2: BI-ID commit wait took 200129us [ 5.086462] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0f:00.0: BI requests enabled
6. Corrupted hw (commit timeout handling)
-----------------------------------------
A switch downstream port that never completes its BI Decoder commit, advertising a ten second window. The walk has already enabled the level below it, the two commits here, and waits the window out.
[ 4.193899] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:10:00.0: BI-ID commit wait took 200066us [ 4.449016] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port3: BI-ID commit wait took 255032us [ 14.828756] pcieport 0000:0e:00.0: BI-ID commit timed out (10000000us) [ 14.932637] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:10:00.0: BI-ID commit wait took 103738us [ 15.132948] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port3: BI-ID commit wait took 200221us [ 15.132962] cxl_core:devm_cxl_endpoint_decoders_setup:1328: cxl_port endpoint4: BI setup failed rc=-110
7. Mixed Configurations (BI-capable Type 3 behind a 68B hop)
------------------------------------------------------------
[ 4.173147] cxl_core:cxl_probe_component_regs:103: cxl_pci 0000:0f:00.0: found BI Decoder capability (0xab4) [ 4.200485] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0c:00.0: found BI Decoder capability (0xab4) [ 4.244721] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0e:00.0: found BI Decoder capability (0xab4) [ 4.260459] cxl_core:cxl_bi_probe_capable:1437: cxl_pci 0000:0f:00.0: BI not supported by USP # cat /sys/bus/cxl/devices/endpoint3/decoder3.0/back_invalidate 0 # echo decoder3.0 > /sys/bus/cxl/devices/region0/target0 [ 23.861378] cxl region0: mem0:decoder3.0 BI not enabled on device [ 23.861390] cxl_port endpoint3: failed to attach decoder3.0 to region0: -6
The same endpoint decoder still commits into an HDM-H region on the plain window:
# echo region1 > /sys/bus/cxl/devices/decoder0.1/create_ram_region [ 23.919038] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.1: created HDM-H region1 # echo decoder3.0 > /sys/bus/cxl/devices/region1/target0 # echo 1 > /sys/bus/cxl/devices/region1/commit # cat /sys/bus/cxl/devices/endpoint3/decoder3.0/back_invalidate 0
8. Auto-discovered (committed) BI decoders
------------------------------------------
For testing, qemu emulates a firmware-committed decoder (x-committed) with this patch:
https://lore.kernel.org/all/20260909184728.mznbg6ox6nqnvv5p@offworld/
[ 3.580967] cxl_core:devm_cxl_switch_port_decoders_setup:1278: cxl_port port1: Fallback to passthrough decoder [ 3.600179] cxl_core:__cxl_bi_ctrl_endpoint:1246: cxl_pci 0000:0d:00.0: adopting firmware-enabled BI [ 3.622024] cxl_core:init_hdm_decoder:1124: cxl_port endpoint2: decoder2.0: range: 0x190000000-0x19fffffff iw: 1 ig: 256 [ 3.702584] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 [ 3.704378] cxl_core:__construct_region:3881: cxl_pci 0000:0d:00.0: mem0:decoder2.0: __construct_region region0 res: [mem 0x190000000-0x19fffffff flags 0x200] iw: 1 ig: 256 [ 3.704496] cxl_core:cxl_region_sort_targets:2125: cxl region0: region sort successful [ 3.711326] cxl_core:devm_cxl_add_dax_region:101: cxl_region region0: region0: register dax_region0 [ 3.711418] cxl_core:cxl_bus_probe:2307: cxl_region region0: probe: 0 # cat /sys/bus/cxl/devices/region0/commit 1 # cat /sys/bus/cxl/devices/decoder2.0/back_invalidate 1
A committed BI decoder under a window without the BI restriction is refused at region assembly, the refusal naming the window:
[ 2.234650] cxl decoder0.0: mem0:decoder2.0 coherency model not permitted by the window [ 2.234660] cxl_port:discover_region:55: cxl decoder2.0: failed to add to region: 0x190000000-0x1cfffffff
A committed 2-way set mixing a BI
decoder with a host-only one under a BI window has its host-only member refused whichever is discovered first: constructing a host-only region under the window is refused by the window check above, and joining the HDM-DB region the BI member constructed is refused at attach. The set never reaches a committed region:
[ 4.560729] cxl_core:__construct_region:3881: cxl_pci 0000:0d:00.0: mem1:decoder3.0: __construct_region region0 res: [mem 0x190000000-0x1afffffff flags 0x200] iw: 2 ig: 4096 [ 4.560897] cxl region0: mem0:decoder4.0 BI not enabled on device [ 4.560907] cxl_port endpoint4: failed to attach decoder4.0 to region0: -6 # cat /sys/bus/cxl/devices/region*/commit 0
And a committed decoder cannot inherit a region's coherency model the way a decoder the driver programs does: a committed HDM-H decoder joining the region a committed HDM-D (device coherent, BI clear) accelerator decoder constructed is refused (t16):
[ 4.018297] cxl region0: mem1:decoder4.0 coherency model mismatch: HDM-H vs HDM-D
9. Device reset
---------------
A Secondary Bus Reset through the kernel's reset attribute clears the device's BI Enable, whose reset default is 0. .reset_done compares cxlds->bi against the hardware and fails closed. With a region attached but not yet committed (t34), the commit is refused rather than programming BI into a device that no longer has it, and a rebind recovers:
# echo region0 > $ROOT/create_ram_region [ 29.218817] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 # echo ram > $EP/mode # echo 0x40000000 > $EP/dpa_size # echo 1 > $REG/interleave_ways # echo 4096 > $REG/interleave_granularity # echo 0x40000000 > $REG/size # echo decoder2.0 > $REG/target0 [ 29.509650] cxl_core:cxl_port_attach_region:1337: cxl region0: mem0:endpoint2 decoder2.0 add: mem0:decoder2.0 @ 0 next: none nr_eps: 1 nr_targets: 1 [ 29.512124] cxl_core:cxl_port_attach_region:1337: cxl region0: pci0000:0c:port1 decoder1.0 add: mem0:decoder2.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1 [ 29.512147] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port1 iw: 1 ig: 4096 [ 29.512156] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem0:decoder2.0 @ 0 [ 29.512250] cxl_core:cxl_calc_interleave_pos:2095: cxl_mem mem0: decoder:decoder2.0 parent:0000:0d:00.0 port:endpoint2 range:0x190000000-0x1cfffffff pos:0 [ 29.512261] cxl_core:cxl_region_attach:2345: cxl decoder2.0: Test cxl_calc_interleave_pos(): success test_pos:0 target->pos:0 # cat $EP/target_type accelerator # echo cxl_bus > /sys/bus/pci/devices/0000:0d:00.0/reset_method # echo 1 > /sys/bus/pci/devices/0000:0d:00.0/reset [ 29.689264] cxl_pci 0000:0d:00.0: resetting [ 29.693340] cxl_pci 0000:0d:00.0: reset via cxl_bus [ 29.706996] cxl_pci 0000:0d:00.0: BI disabled by reset # echo 1 > $REG/commit [ 29.778974] cxl region0: mem0:decoder2.0 BI not enabled on device # cat $EP/back_invalidate 0 # echo region0 > $ROOT/delete_region # echo mem0 > /sys/bus/cxl/drivers/cxl_mem/unbind [ 29.951722] cxl_core:cxl_detach_ep:1564: cxl_mem mem0: disconnect mem0 from port1 # echo mem0 > /sys/bus/cxl/drivers/cxl_mem/bind [ 29.991544] cxl_core:devm_cxl_enumerate_ports:1879: cxl_mem mem0: scan: iter: mem0 dport_dev: 0000:0c:00.0 parent: pci0000:0c [ 29.991690] cxl_core:devm_cxl_enumerate_ports:1885: cxl_mem mem0: found already registered port port1:pci0000:0c [ 30.010281] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests enabled [ 30.033870] cxl_core:init_hdm_decoder:1124: cxl_port endpoint2: decoder2.0: range: 0x0-0xffffffffffffffff iw: 1 ig: 256 [ 30.036668] cxl_core:add_hdm_decoder:39: cxl_mem mem0: decoder2.0 added to endpoint2 [ 30.058387] cxl_core:cxl_bus_probe:2307: cxl_port endpoint2: probe: 0 [ 30.059643] cxl_core:cxl_bus_probe:2307: cxl_mem mem0: probe: 0 # echo region0 > $ROOT/create_ram_region [ 32.117872] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 # echo ram > $EP/mode # echo 0x40000000 > $EP/dpa_size # echo 1 > $REG/interleave_ways # echo 4096 > $REG/interleave_granularity # echo 0x40000000 > $REG/size # echo decoder2.0 > $REG/target0 [ 32.277068] cxl_core:cxl_port_attach_region:1337: cxl region0: mem0:endpoint2 decoder2.0 add: mem0:decoder2.0 @ 0 next: none nr_eps: 1 nr_targets: 1 [ 32.279775] cxl_core:cxl_port_attach_region:1337: cxl region0: pci0000:0c:port1 decoder1.0 add: mem0:decoder2.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1 [ 32.279787] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port1 iw: 1 ig: 4096 [ 32.279791] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem0:decoder2.0 @ 0 [ 32.279829] cxl_core:cxl_calc_interleave_pos:2095: cxl_mem mem0: decoder:decoder2.0 parent:0000:0d:00.0 port:endpoint2 range:0x190000000-0x1cfffffff pos:0 [ 32.279834] cxl_core:cxl_region_attach:2345: cxl decoder2.0: Test cxl_calc_interleave_pos(): success test_pos:0 target->pos:0 # echo 1 > $REG/commit # cat $EP/back_invalidate 1
The same reset with the HDM-DB region committed (t27) trips the existing decoder-loss detection alongside the BI invalidation:
# echo 1 > /sys/bus/pci/devices/0000:0d:00.0/reset [ 32.911044] cxl_pci 0000:0d:00.0: resetting [ 32.914293] cxl_pci 0000:0d:00.0: reset via cxl_bus [ 32.924874] cxl_pci 0000:0d:00.0: BI disabled by reset [ 32.924933] cxl_pci 0000:0d:00.0: SBR happened without memory regions removal. [ 32.924939] cxl_pci 0000:0d:00.0: System may be unstable if regions hosted system memory. # cat $EP/back_invalidate 0
A reset landing after the commit's own check but before the decoder is programmed is caught by re-reading BI Decoder Control once the target is committed, and the target is undone (t34):
[ 20.297283] cxl region0: mem0:decoder2.0 BI disabled by reset during commit
An FLR leaves the CXL.cache/mem component registers alone, so BI Enable, the region and its decoders all survive it and nothing is invalidated (t27 flr-region). The unbind after an invalidation still unwinds the dport refcounts, and a reset below a switch leaves the DSP's Enable and the Root Port's Forward in place for the unbind to clear (t27 switch).
10. AER recovery
----------------
An AER Uncorrectable Fatal error injected into the endpoint (t28) runs the recovery flow, which never reaches .reset_done: the memdev bounce brings BI down through devres before the link reset, and the re-attach after slot reset runs the enable path from scratch. An HDM-DB region commits again afterwards.
[ 17.897615] pcieport 0000:0c:00.0: AER: Uncorrectable (Fatal) Error message received from 0000:0d:00.0 [ 17.897625] cxl_pci 0000:0d:00.0: AER: CXL Bus Error: severity=Uncorrectable (Fatal) (Inaccessible) [ 17.897640] pcieport 0000:0c:00.0: AER: broadcast error_detected message [ 17.962187] cxl_pci 0000:0d:00.0: mem0: frozen state error detected, disable CXL.mem [ 17.964566] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests disabled [ 17.971633] pcieport 0000:0c:00.0: AER: Root Port link has been reset (0) [ 17.971669] pcieport 0000:0c:00.0: AER: broadcast slot_reset message [ 17.971673] cxl_pci 0000:0d:00.0: mem0: restart CXL.mem after slot reset [ 17.978508] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:0d:00.0: BI requests enabled [ 18.002146] pcieport 0000:0c:00.0: AER: broadcast resume message [ 18.002149] cxl_pci 0000:0d:00.0: mem0: error resume successful [ 18.002264] pcieport 0000:0c:00.0: AER: device recovery successful
11. Cascaded switches and interleaves across switches
-----------------------------------------------------
Two cascaded switches (t9): both route tables are found and committed, the transit DSP takes Forward and the device-adjacent DSP Enable, and an HDM-DB region commits two switch hops down next to an HDM-H one:
[ 3.925810] cxl_core:cxl_probe_component_regs:103: cxl_pci 0000:11:00.0: found BI Decoder capability (0xab4) [ 3.952095] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0c:00.0: found BI Decoder capability (0xab4) [ 3.962438] cxl_core:cxl_probe_component_regs:97: cxl_port port2: found BI RT capability (0xaa8) [ 3.994843] cxl_core:cxl_probe_component_regs:103: pcieport 0000:0e:00.0: found BI Decoder capability (0xab4) [ 4.005908] cxl_core:cxl_probe_component_regs:97: cxl_port port3: found BI RT capability (0xaa8) [ 4.038754] cxl_core:cxl_probe_component_regs:103: pcieport 0000:10:00.0: found BI Decoder capability (0xab4) [ 4.254819] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:10:00.0: BI-ID commit wait took 199243us [ 4.521752] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port3: BI-ID commit wait took 266850us [ 4.722287] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:0e:00.0: BI-ID commit wait took 200248us [ 4.922630] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port2: BI-ID commit wait took 200306us [ 4.922904] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:11:00.0: BI requests enabled [ 18.222672] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 [ 19.199474] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.1: created HDM-H region1
Three switch levels (t25), one commit per DSP and per route table:
[ 4.023015] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:12:00.0: BI-ID commit wait took 199517us [ 4.131842] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port4: BI-ID commit wait took 108731us [ 4.333385] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:10:00.0: BI-ID commit wait took 201430us [ 4.533024] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port3: BI-ID commit wait took 199604us [ 4.733365] cxl_core:__cxl_bi_wait_commit:1036: pcieport 0000:0e:00.0: BI-ID commit wait took 200222us [ 4.854051] cxl_core:__cxl_bi_wait_commit:1036: cxl_port port2: BI-ID commit wait took 120593us [ 4.854130] cxl_core:__cxl_bi_ctrl_endpoint:1263: cxl_pci 0000:13:00.0: BI requests enabled
A 4-way HDM-DB region across two host bridges, each a switch with two BI endpoints (t32): the root interleaves across the host bridges and each USP decoder lands iw=2 below it, all four endpoints at bi=1:
[ 25.637378] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 [ 26.175977] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port2 iw: 1 ig: 8192 [ 26.175981] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port2 target[0] = 0000:0c:00.0 for mem2:decoder6.0 @ 0 [ 26.175991] cxl_core:cxl_port_setup_targets:1656: cxl region0: 0000:0d:00.0:port4 iw: 2 ig: 8192 [ 26.175994] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:0d:00.0:port4 target[0] = 0000:0e:00.0 for mem2:decoder6.0 @ 0 [ 26.176000] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:40:port1 iw: 1 ig: 8192 [ 26.176003] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:40:port1 target[0] = 0000:40:00.0 for mem0:decoder5.0 @ 1 [ 26.176011] cxl_core:cxl_port_setup_targets:1656: cxl region0: 0000:41:00.0:port3 iw: 2 ig: 8192 [ 26.176013] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:41:00.0:port3 target[0] = 0000:42:00.0 for mem0:decoder5.0 @ 1 [ 26.176020] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port2 target[0] = 0000:0c:00.0 for mem3:decoder8.0 @ 2 [ 26.176027] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:0d:00.0:port4 target[1] = 0000:0e:01.0 for mem3:decoder8.0 @ 2 [ 26.176034] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:40:port1 target[0] = 0000:40:00.0 for mem1:decoder7.0 @ 3 [ 26.176041] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:41:00.0:port3 target[1] = 0000:42:01.0 for mem1:decoder7.0 @ 3
The same under one host bridge with two root ports (t33), the host bridge decoder interleaving across the root ports:
[ 21.913291] cxl_core:devm_cxl_add_region:2893: cxl_acpi ACPI0017:00: decoder0.0: created HDM-DB region0 [ 22.506974] cxl_core:cxl_port_setup_targets:1656: cxl region0: pci0000:0c:port1 iw: 2 ig: 1024 [ 22.506981] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem1:decoder5.0 @ 0 [ 22.506997] cxl_core:cxl_port_setup_targets:1656: cxl region0: 0000:0d:00.0:port3 iw: 2 ig: 2048 [ 22.507003] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:0d:00.0:port3 target[0] = 0000:0e:00.0 for mem1:decoder5.0 @ 0 [ 22.507015] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[1] = 0000:0c:01.0 for mem3:decoder6.0 @ 1 [ 22.507026] cxl_core:cxl_port_setup_targets:1656: cxl region0: 0000:11:00.0:port2 iw: 2 ig: 2048 [ 22.507031] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:11:00.0:port2 target[0] = 0000:12:00.0 for mem3:decoder6.0 @ 1 [ 22.507044] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[1] = 0000:0c:00.0 for mem2:decoder7.0 @ 2 [ 22.507056] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:0d:00.0:port3 target[1] = 0000:0e:01.0 for mem2:decoder7.0 @ 2 [ 22.507068] cxl_core:cxl_port_setup_targets:1682: cxl region0: pci0000:0c:port1 target[1] = 0000:0c:01.0 for mem0:decoder4.0 @ 3 [ 22.507080] cxl_core:cxl_port_setup_targets:1682: cxl region0: 0000:11:00.0:port2 target[1] = 0000:12:01.0 for mem0:decoder4.0 @ 3
Applies against v7.3-rc4. Please consider for v7.4.
[0] https://lore.kernel.org/linux-cxl/[email protected]/
Thanks!
Davidlohr Bueso (10):
cxl: Add BI register probing and port initialization cxl/pci: Add BI topology enable/disable cxl/hdm: Add BI coherency support for endpoint decoders
cxl: Add HDM-DB region creation
cxl/hdm: Rename decoder coherency flags cxl/region: Log the coherency model at region creation cxl/pci: Split BI capability probe from setup
cxl: Allow auto-committed BI hdm decoders cxl/test: Add mock BI topology support cxl/doc: Update maturity map with BI support
Documentation/ABI/testing/sysfs-bus-cxl | 22 + Documentation/driver-api/cxl/maturity-map.rst | 16 +- drivers/cxl/acpi.c | 31 +- drivers/cxl/core/core.h | 9 + drivers/cxl/core/hdm.c | 75 ++- drivers/cxl/core/pci.c | 545 ++++++++++++++++++ drivers/cxl/core/port.c | 48 +- drivers/cxl/core/region.c | 160 ++++- drivers/cxl/core/regs.c | 14 + drivers/cxl/cxl.h | 58 +- drivers/cxl/cxlmem.h | 2 + drivers/cxl/pci.c | 8 +- drivers/cxl/port.c | 46 ++ include/cxl/cxl.h | 13 +- tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/test/accel.c | 2 +- tools/testing/cxl/test/cxl.c | 171 +++++- tools/testing/cxl/test/mock.c | 13 + tools/testing/cxl/test/mock.h | 1 + 19 files changed, 1188 insertions(+), 47 deletions(-)
--
2.39.5
Davidlohr Bueso
maintainerPATCH v9 1/10 cxl: Add BI register probing and port initialization
Add register probing for BI Route Table and BI Decoder capability structures in cxl_probe_component_regs(), and helpers to map them.
cxl_dport_map_bi() maps the BI Decoder of a downstream port (root port or switch DSP) at dport-creation time via cxl_port_add_dport(); devm_cxl_port_bi_setup() maps a port's own BI capability when the upstream link is in 256B Flit operation - the BI Decoder during endpoint port probe, the BI RT of a switch USP on first-dport setup.
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/pci.c | 38 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 4 +++- drivers/cxl/core/regs.c | 14 +++++++++++++ drivers/cxl/cxl.h | 7 +++++++ drivers/cxl/port.c | 45 +++++++++++++++++++++++++++++++++++++++++ include/cxl/cxl.h | 6 ++++++ 7 files changed, 114 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +1 -0
@@ -208,6 +208,7 @@ static inline void devm_cxl_dport_ras_setup(struct cxl_dport *dport) { }#endif /* CONFIG_CXL_RAS */ int cxl_gpf_port_setup (struct cxl_dport *dport); +void devm_cxl_dport_bi_setup (struct cxl_dport *dport);struct cxl_hdm ; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
drivers/cxl/core/pci.c +38 -0
@@ -927,3 +927,41 @@ int cxl_port_get_possible_dports(struct cxl_port *port)return ctx.count; } + +static void cxl_dport_map_bi (struct cxl_dport *dport) +{ +struct cxl_register_map *map = &dport->reg_map; +struct device *dev = dport->dport_dev; + +if (!map->component_map.bi_decoder.valid) { +dev_dbg (dev,"BI Decoder registers not found\n" ); +return ; + } + +if (cxl_map_component_regs (map, &dport->regs.component, +BIT (CXL_CM_CAP_CAP_ID_BI_DECODER ))) +dev_dbg (dev,"Failed to map BI Decoder capability\n" ); +} + +/** +* devm_cxl_dport_bi_setup - Map BI Decoder registers on a CXL dport +* @dport: the cxl_dport that needs to be initialized +* +* Must be called while the dport's devres group is open so iomap +* allocations are released on dport removal. +*/ +void devm_cxl_dport_bi_setup (struct cxl_dport *dport) +{ +if (!dev_is_pci (dport->dport_dev)) +return ; + +switch (pci_pcie_type (to_pci_dev (dport->dport_dev))) { +case PCI_EXP_TYPE_ROOT_PORT : +case PCI_EXP_TYPE_DOWNSTREAM : + dport->reg_map.host =dport_to_host (dport); +cxl_dport_map_bi (dport); +break ; +default : +break ; + } +}
drivers/cxl/core/port.c +3 -1
@@ -1242,8 +1242,10 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,cxl_debugfs_create_dport_dir (dport); -if (!dport->rch) +if (!dport->rch) {devm_cxl_dport_ras_setup (dport); +devm_cxl_dport_bi_setup (dport); + }/* keep the group, and mark the end of devm actions */ cxl_dport_close_dr_group (dport,no_free_ptr (dport_dr_group));
drivers/cxl/core/regs.c +14 -0
@@ -93,6 +93,18 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base, length =CXL_RAS_CAPABILITY_LENGTH ; rmap = &map->ras;break ; +case CXL_CM_CAP_CAP_ID_BI_RT : +dev_dbg (dev,"found BI RT capability (0x%x)\n" , + offset); + length =CXL_BI_RT_CAPABILITY_LENGTH ; + rmap = &map->bi_rt; +break ; +case CXL_CM_CAP_CAP_ID_BI_DECODER : +dev_dbg (dev,"found BI Decoder capability (0x%x)\n" , + offset); + length =CXL_BI_DECODER_CAPABILITY_LENGTH ; + rmap = &map->bi_decoder; +break ;default :dev_dbg (dev,"Unknown CM cap ID: %d (0x%x)\n" , cap_id, offset);
@@ -212,6 +224,8 @@ int cxl_map_component_regs(const struct cxl_register_map *map, } mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, + { &map->component_map.bi_rt, ®s->bi_rt }, + { &map->component_map.bi_decoder, ®s->bi_decoder }, }; int i;
drivers/cxl/cxl.h +7 -0
@@ -39,9 +39,16 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_CM_CAP_HDR_ARRAY_SIZE_MASK GENMASK(31, 24)#define CXL_CM_CAP_PTR_MASK GENMASK(31, 20) +/* CXL 4.0 8.2.4 Table 8-74 */ #define CXL_CM_CAP_CAP_ID_RAS 0x2#define CXL_CM_CAP_CAP_ID_HDM 0x5#define CXL_CM_CAP_CAP_HDM_VERSION 1 +#define CXL_CM_CAP_CAP_ID_BI_RT 0xB +#define CXL_CM_CAP_CAP_ID_BI_DECODER 0xC + +/* CXL 4.0 8.2.4.26 / 8.2.4.27 BI Capability Structures */ +#define CXL_BI_RT_CAPABILITY_LENGTH 0xC +#define CXL_BI_DECODER_CAPABILITY_LENGTH 0xC/* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */ #define CXL_HDM_DECODER_CAP_OFFSET 0x0
drivers/cxl/port.c +45 -0
63 lines not on this page · raw message
include/cxl/cxl.h +6 -0
@@ -34,10 +34,14 @@ struct cxl_regs {* Common set of CXL Component register block base pointers * @hdm_decoder: CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure * @ras: CXL 2.0 8.2.5.9 CXL RAS Capability Structure +* @bi_rt: CXL 4.0 8.2.4.26 CXL BI Route Table Capability Structure +* @bi_decoder: CXL 4.0 8.2.4.27 CXL BI Decoder Capability Structure */ struct_group_tagged (cxl_component_regs, component, void __iomem *hdm_decoder;void __iomem *ras; +void __iomem *bi_rt; +void __iomem *bi_decoder; );/* * Common set of CXL Device register block base pointers
@@ -80,6 +84,8 @@ struct cxl_reg_map {struct cxl_component_reg_map {struct cxl_reg_map hdm_decoder;struct cxl_reg_map ras; +struct cxl_reg_map bi_rt; +struct cxl_reg_map bi_decoder; };struct cxl_device_reg_map {
Signature · 1 line
2.39.5
Re: [PATCH v9 01/10] cxl: Add BI register probing and port initialization
Quoted 9 lines · Davidlohr Bueso
Add register probing for BI Route Table and BI Decoder capability structures in
cxl_probe_component_regs(), and helpers to map them.
cxl_dport_map_bi()maps the BI Decoder of a downstream port (root port or switch DSP) at dport-creation time viacxl_port_add_dport();devm_cxl_port_bi_setup()maps a port's own BI capability when the upstream link is in 256B Flit operation - the BI Decoder during endpoint port probe, the BI RT of a switch USP on first-dport setup.
Quoted 5 lines
Reviewed-by Dave Jiang <[email protected]>Reviewed-by Alison Schofield <[email protected]>Reviewed-by Li Ming <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Just a nit below, no blocker.
Quoted 125 lines
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/pci.c | 38 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 4 +++- drivers/cxl/core/regs.c | 14 +++++++++++++ drivers/cxl/cxl.h | 7 +++++++ drivers/cxl/port.c | 45 +++++++++++++++++++++++++++++++++++++++++ include/cxl/cxl.h | 6 ++++++ 7 files changed, 114 insertions(+), 1 deletion(-)drivers/cxl/core/core.h +1
-0@@ -208,6 +208,7 @@ static inline void devm_cxl_dport_ras_setup(struct cxl_dport *dport) { }#endif /* CONFIG_CXL_RAS */ int cxl_gpf_port_setup (struct cxl_dport *dport); +void devm_cxl_dport_bi_setup (struct cxl_dport *dport);struct cxl_hdm ; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,drivers/cxl/core/pci.c +38
-0@@ -927,3 +927,41 @@ int cxl_port_get_possible_dports(struct cxl_port *port)return ctx.count; } + +static void cxl_dport_map_bi (struct cxl_dport *dport) +{ +struct cxl_register_map *map = &dport->reg_map; +struct device *dev = dport->dport_dev; + +if (!map->component_map.bi_decoder.valid) { +dev_dbg (dev,"BI Decoder registers not found\n" ); +return ; + } + +if (cxl_map_component_regs (map, &dport->regs.component, +BIT (CXL_CM_CAP_CAP_ID_BI_DECODER ))) +dev_dbg (dev,"Failed to map BI Decoder capability\n" ); +} + +/** +* devm_cxl_dport_bi_setup - Map BI Decoder registers on a CXL dport +* @dport: the cxl_dport that needs to be initialized +* +* Must be called while the dport's devres group is open so iomap +* allocations are released on dport removal. +*/ +void devm_cxl_dport_bi_setup (struct cxl_dport *dport) +{ +if (!dev_is_pci (dport->dport_dev)) +return ; + +switch (pci_pcie_type (to_pci_dev (dport->dport_dev))) { +case PCI_EXP_TYPE_ROOT_PORT : +case PCI_EXP_TYPE_DOWNSTREAM : + dport->reg_map.host =dport_to_host (dport); +cxl_dport_map_bi (dport); +break ; +default : +break ; + } +}drivers/cxl/core/port.c +3
-1@@ -1242,8 +1242,10 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,cxl_debugfs_create_dport_dir (dport); -if (!dport->rch) +if (!dport->rch) {devm_cxl_dport_ras_setup (dport); +devm_cxl_dport_bi_setup (dport); + }/* keep the group, and mark the end of devm actions */ cxl_dport_close_dr_group (dport,no_free_ptr (dport_dr_group));drivers/cxl/core/regs.c +14
-0@@ -93,6 +93,18 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base, length =CXL_RAS_CAPABILITY_LENGTH ; rmap = &map->ras;break ; +case CXL_CM_CAP_CAP_ID_BI_RT : +dev_dbg (dev,"found BI RT capability (0x%x)\n" , + offset); + length =CXL_BI_RT_CAPABILITY_LENGTH ; + rmap = &map->bi_rt; +break ; +case CXL_CM_CAP_CAP_ID_BI_DECODER : +dev_dbg (dev,"found BI Decoder capability (0x%x)\n" , + offset); + length =CXL_BI_DECODER_CAPABILITY_LENGTH ; + rmap = &map->bi_decoder; +break ;default :dev_dbg (dev,"Unknown CM cap ID: %d (0x%x)\n" , cap_id, offset);@@ -212,6 +224,8 @@ int cxl_map_component_regs(const struct cxl_register_map *map, } mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, + { &map->component_map.bi_rt, ®s->bi_rt }, + { &map->component_map.bi_decoder, ®s->bi_decoder }, }; int i;drivers/cxl/cxl.h +1
-0@@ -39,9 +39,16 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_CM_CAP_HDR_ARRAY_SIZE_MASK GENMASK(31, 24)#define CXL_CM_CAP_PTR_MASK GENMASK(31, 20) +/* CXL 4.0 8.2.4 Table 8-74 */
drivers/cxl/cxl.h extern const struct nvdimm_security_ops *cxl_security_ops; · line 52
Quoted 10 lines
drivers/cxl/cxl.h +6
-0#define CXL_CM_CAP_CAP_ID_RAS 0x2#define CXL_CM_CAP_CAP_ID_HDM 0x5#define CXL_CM_CAP_CAP_HDM_VERSION 1 +#define CXL_CM_CAP_CAP_ID_BI_RT 0xB +#define CXL_CM_CAP_CAP_ID_BI_DECODER 0xC + +/* CXL 4.0 8.2.4.26 / 8.2.4.27 BI Capability Structures */ +#define CXL_BI_RT_CAPABILITY_LENGTH 0xC +#define CXL_BI_DECODER_CAPABILITY_LENGTH 0xC
These 3 macro all refers to 0xC , should we add comment that they're independent of each other so if in the future someone wants to refactor, they won't accidently treat them as dependent value ?
Best regards,
Richard Cheng.
Quoted 103 lines
drivers/cxl/cxl.h +0
-0/* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */ #define CXL_HDM_DECODER_CAP_OFFSET 0x0drivers/cxl/port.c +45
-0@@ -58,6 +58,47 @@ static int discover_region(struct device *dev, void *unused)return 0 ; } +static void devm_cxl_port_bi_setup (struct cxl_port *port) +{ +struct cxl_register_map *map = &port->reg_map; +struct cxl_dport *parent_dport = port->parent_dport; +struct device *udev; +int cap_id; + +/* no upstream BI registers above host bridges or the cxl_root */ +if (!parent_dport ||is_cxl_root (parent_dport->port)) +return ; + + udev =is_cxl_endpoint (port) ? + port->uport_dev->parent : port->uport_dev; +if (!dev_is_pci (udev)) +return ; + +/* BI requires 256B Flit on the upstream link */ +if (!cxl_pci_flit_256 (to_pci_dev (udev))) +return ; + +/* map this port's own BI capability */ +if (is_cxl_endpoint (port)) { +if (!map->component_map.bi_decoder.valid) { +dev_dbg (&port->dev,"BI Decoder registers not found\n" ); +return ; + } + cap_id =CXL_CM_CAP_CAP_ID_BI_DECODER ; + }else { +if (!map->component_map.bi_rt.valid) { +dev_dbg (&port->dev,"BI RT registers not found\n" ); +return ; + } + cap_id =CXL_CM_CAP_CAP_ID_BI_RT ; + } + + map->host = &port->dev; +if (cxl_map_component_regs (map, &port->regs,BIT (cap_id))) +dev_dbg (&port->dev,"Failed to map BI capability 0x%x\n" , + cap_id); +} +static int cxl_switch_port_probe (struct cxl_port *port) {/* Reset nr_dports for rebind of driver */ @@ -128,6 +169,8 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)read_cdat_data (port);cxl_endpoint_parse_cdat (port); +devm_cxl_port_bi_setup (port); +get_device (&cxlmd->dev); rc =devm_add_action_or_reset (&port->dev, schedule_detach, cxlmd);if (rc)@@ -252,6 +295,8 @@ static struct cxl_dport *cxl_port_add_dport(struct cxl_port *port,* on failure, or the device does not implement RAS registers. */ devm_cxl_port_ras_setup (port); + +devm_cxl_port_bi_setup (port); } dport =devm_cxl_add_dport_by_dev (port, dport_dev);include/cxl/cxl.h +6
-0@@ -34,10 +34,14 @@ struct cxl_regs {* Common set of CXL Component register block base pointers * @hdm_decoder: CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure * @ras: CXL 2.0 8.2.5.9 CXL RAS Capability Structure +* @bi_rt: CXL 4.0 8.2.4.26 CXL BI Route Table Capability Structure +* @bi_decoder: CXL 4.0 8.2.4.27 CXL BI Decoder Capability Structure */ struct_group_tagged (cxl_component_regs, component, void __iomem *hdm_decoder;void __iomem *ras; +void __iomem *bi_rt; +void __iomem *bi_decoder; );/* * Common set of CXL Device register block base pointers @@ -80,6 +84,8 @@ struct cxl_reg_map {struct cxl_component_reg_map {struct cxl_reg_map hdm_decoder;struct cxl_reg_map ras; +struct cxl_reg_map bi_rt; +struct cxl_reg_map bi_decoder; };struct cxl_device_reg_map {Signature · 1 line
2.39.5
Davidlohr Bueso
maintainerPATCH v9 2/10 cxl/pci: Add BI topology enable/disable
In reply to Davidlohr BuesoImplement cxl_bi_setup() to enable BI flows on the device and every component in the path, and its teardown counterpart cxl_bi_dealloc(). Setup runs from devm_cxl_endpoint_decoders_setup(), between the port's HDM state and its decoders. Registered there, its devres teardown brings BI down after the decoders quiesce and before the HDM state is freed, and BI is settled before the decoders, and later the regions, are looked at. The BI-ID and path enablement belong to the endpoint port's lifetime.
Setup is safe in endpoint port probe context. The port probes synchronously from cxl_mem_probe(), pinning the memdev state the walk consumes, and the whole ancestor path already exists with BI registers mapped (dports at dport-add time, the switch USP RT at first-dport setup) because devm_cxl_enumerate_ports() completes before the endpoint is created.
Dealloc is safe in endpoint devres context. Both setup and dealloc walk the endpoint's parent_dport topology rather than getting the port by bus lookup - an ancestor teardown delists the parent port before the endpoint's devres runs.
The topology walk is stable as parent_dport pointers are fixed at port creation; ancestors cannot be reaped while holding this memdev's cxl_ep; and their own teardown frees dports only after the endpoint is gone.
Likewise, the device state outlives the walk - cxlmd->cxlds is nulled only after cxl_memdev_unregister() has torn the endpoint down, and delete_endpoint() clears cxlmd->endpoint only after the endpoint devres has run.
Each dport is programmed by its position - the one immediately above the device takes BI Enable, every dport above it takes BI Forward (Table 8-157, Table 9-13), at any switch depth (Table 7-97). Any level can be shared, so nr_bi refcounts endpoints at every dport. Registers are written on the first endpoint and cleared on the last, but only downstream ports commit (Table 8-156), once per endpoint (Table 8-152), and a failed commit undoes its write and commits the undo. A USP advertising a BI Route Table that failed to map is refused rather than treated as absent. nr_bi counts only the endpoints this driver enabled, so a level can be cleared while firmware still has an unbound device on it.
A reset may wipe the device's BI Enable, whose reset default is 0 (Table 8-157). .reset_done reads the hardware rather than assume which reset ran, and invalidates cxlds->bi, failing closed with recovery by rebind as for decoder loss; dealloc unwinds the dport refcounts regardless. It also clears cxlds->bi unconditionally - the endpoint disable fails when the hardware already shows BI Enable clear, from a reset .reset_done never saw, and the flag must not outlive the BI Decoder mapping it describes, which the endpoint port releases moments later.
With dealloc in the endpoint's devres, delete_endpoint() already holds the parent port's device lock, so to avoid deadlocking, add a per-port bi_lock, serializing the dports that share state (nr_bi and the control register at any shared level, the switch USP's BI RT).
--- drivers/cxl/core/core.h | 7 + drivers/cxl/core/hdm.c | 10 + drivers/cxl/core/pci.c | 427 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 1 + drivers/cxl/cxl.h | 31 +++ drivers/cxl/pci.c | 8 +- include/cxl/cxl.h | 2 + 7 files changed, 484 insertions(+), 2 deletions(-)
drivers/cxl/core/core.h +7 -0
@@ -210,6 +210,13 @@ static inline void devm_cxl_dport_ras_setup(struct cxl_dport *dport) { }int cxl_gpf_port_setup (struct cxl_dport *dport);void devm_cxl_dport_bi_setup (struct cxl_dport *dport); +static inline bool cxl_bi_decoder_enabled (struct cxl_port *port) +{ +return FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (port->regs.bi_decoder + +CXL_BI_DECODER_CTRL_OFFSET )); +} +struct cxl_hdm ;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm,struct cxl_endpoint_dvsec_info *info);
drivers/cxl/core/hdm.c +10 -0
@@ -1274,6 +1274,16 @@ int devm_cxl_endpoint_decoders_setup(struct cxl_port *port)if (rc)return rc; +/* +* Between the port's HDM state and its decoders: devres, +* unwinding in reverse, brings BI down only after the decoders +* quiesce, while its slow walk still precedes the HDM state +* free. +*/ + rc =cxl_bi_setup (port); +if (rc) +dev_dbg (&port->dev,"BI setup failed rc=%d\n" , rc); +return devm_cxl_enumerate_decoders (cxlhdm, &info); }EXPORT_SYMBOL_NS_GPL (devm_cxl_endpoint_decoders_setup,"CXL" );
drivers/cxl/core/pci.c +427 -0
442 lines not on this page · raw message
drivers/cxl/core/port.c +1 -0
@@ -742,6 +742,7 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev,xa_init (&port->dports);xa_init (&port->endpoints);xa_init (&port->regions); +mutex_init (&port->bi_lock); port->component_reg_phys =CXL_RESOURCE_NONE ;device_initialize (dev);
drivers/cxl/cxl.h +31 -0
@@ -180,6 +180,31 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_HEADERLOG_TRACE_SIZE SZ_512#define CXL_HEADERLOG_TRACE_SIZE_U32 (CXL_HEADERLOG_TRACE_SIZE / sizeof(u32)) +/* CXL 4.0 8.2.4.26 CXL BI Route Table Capability Structure */ +#define CXL_BI_RT_CAPS_OFFSET 0x0 +#define CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ BIT(0) +#define CXL_BI_RT_CTRL_OFFSET 0x4 +#define CXL_BI_RT_CTRL_BI_COMMIT BIT(0) +#define CXL_BI_RT_STATUS_OFFSET 0x8 +#define CXL_BI_RT_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_RT_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) + +/* CXL 4.0 8.2.4.27 CXL BI Decoder Capability Structure */ +#define CXL_BI_DECODER_CAPS_OFFSET 0x0 +#define CXL_BI_DECODER_CAPS_HDMD_CAP BIT(0) +#define CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ BIT(1) +#define CXL_BI_DECODER_CTRL_OFFSET 0x4 +#define CXL_BI_DECODER_CTRL_BI_FW BIT(0) +#define CXL_BI_DECODER_CTRL_BI_ENABLE BIT(1) +#define CXL_BI_DECODER_CTRL_BI_COMMIT BIT(2) +#define CXL_BI_DECODER_STATUS_OFFSET 0x8 +#define CXL_BI_DECODER_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_DECODER_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) +/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0#define CXLDEV_CAP_ARRAY_CAP_ID 0
@@ -565,6 +590,7 @@ struct cxl_dax_region {* @decoder_ida: allocator for decoder ids * @reg_map: component and ras register mapping parameters * @regs: mapped component registers +* @bi_lock: serializes BI Decoder/RT state of this port's dports * @nr_dports: number of entries in @dports * @hdm_end: track last allocated HDM decoder instance for allocation ordering * @commit_end: cursor to track highest committed decoder for commit ordering
@@ -587,6 +613,7 @@ struct cxl_port {struct ida decoder_ida;struct cxl_register_map reg_map;struct cxl_component_regs regs; +struct mutex bi_lock;/* dport BI state shared below this port */ int nr_dports;int hdm_end;int commit_end;
@@ -650,6 +677,7 @@ struct cxl_rcrb_info {* @coord: access coordinates (bandwidth and latency performance attributes) * @link_latency: calculated PCIe downstream latency * @gpf_dvsec: Cached GPF port DVSEC +* @nr_bi: number of BI-enabled endpoints below this dport */ struct cxl_dport {struct device *dport_dev;
@@ -662,6 +690,7 @@ struct cxl_dport {struct access_coordinate coord[ACCESS_COORDINATE_MAX ];long link_latency;int gpf_dvsec; +int nr_bi; };/**
@@ -920,6 +949,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, struct access_coordinate *c2);bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +int cxl_bi_setup (struct cxl_port *endpoint); +void cxl_bi_reset_detected (struct cxl_port *endpoint);struct cxl_dport *devm_cxl_add_dport_by_dev (struct cxl_port *port,struct device *dport_dev);
drivers/cxl/pci.c +6 -2
@@ -987,8 +987,12 @@ static void cxl_reset_done(struct pci_dev *pdev)if (!cxlmd->dev.driver)return ; -if (cxlmd->endpoint && -cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +if (!cxlmd->endpoint) +return ; + +cxl_bi_reset_detected (cxlmd->endpoint); + +if (cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) {device_for_each_child (&cxlmd->endpoint->dev,NULL , cxl_endpoint_decoder_clear_reset_flags);
include/cxl/cxl.h +2 -0
@@ -168,6 +168,7 @@ struct cxl_dpa_partition {* @regs: Parsed register blocks * @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) +* @bi: device is BI (Back-Invalidate) enabled * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array
@@ -187,6 +188,7 @@ struct cxl_dev_state {struct cxl_device_regs regs;int cxl_dvsec;bool rcd; +bool bi;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];
Signature · 1 line
2.39.5
[email protected]
AI reviewRe: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] cxl/pci: TOCTOU race in BI setup against concurrent AER reset --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cxl/pci: TOCTOU race in BI setup against concurrent AER reset
--
commit 1daa4037cbac0ebc16630c3d4f45c358bd7890f9
Author: Davidlohr Bueso <[email protected]>
cxl/pci: Add BI topology enable/disable
This patch implements setup and teardown of the Back-Invalidate (BI) topology on CXL endpoints and upstream components. It also adds a reset detection mechanism to verify whether a reset cleared the hardware BI Enable state.
Quoted 4 lines
drivers/cxl/core/pci.c +0
-0
[ ... ]
Quoted 2 lines
drivers/cxl/core/pci.c +2
-0+static int __cxl_bi_ctrl_endpoint (struct cxl_dev_state *cxlds,bool enable) +{
[ ... ]
drivers/cxl/core/pci.c void devm_cxl_dport_bi_setup(struct cxl_dport *dport) · line 1219
Quoted 3 lines
drivers/cxl/core/pci.c +3
-0+FIELD_MODIFY (CXL_BI_DECODER_CTRL_BI_ENABLE , &ctrl, enable); +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); + cxlds->bi = enable;
[Severity: Medium]
Could this lockless update of cxlds->bi race with a concurrent AER reset handled by cxl_bi_reset_detected()?
If a user manually binds the cxl_port driver via sysfs concurrently with a PCI AER reset (SBR), the manual sysfs bind takes the endpoint->dev lock, while the AER recovery (cxl_reset_done()) takes the cxlmd->dev lock, allowing them to execute concurrently.
There is a window between the writel() that sets the hardware bit and the assignment of cxlds->bi. If the AER SBR wipes the hardware bit in this window, could cxl_bi_reset_detected() check the still-false cxlds->bi and ignore the reset?
Quoted 5 lines
drivers/cxl/core/pci.c +5
-0+ +dev_dbg (cxlds->dev,"BI requests %s\n" ,str_enabled_disabled (enable)); + +return 0 ; +}
[ ... ]
drivers/cxl/core/pci.c void devm_cxl_dport_bi_setup(struct cxl_dport *dport) · line 1325
Quoted 7 lines
drivers/cxl/core/pci.c +7
-0+void cxl_bi_reset_detected (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; + +if (!cxlds->bi) +return ;
If cxl_bi_reset_detected() returns early here because cxlds->bi is false, and then __cxl_bi_ctrl_endpoint() resumes and sets cxlds->bi = true, the software state becomes permanently desynchronized from the hardware state (BI_ENABLE = 0), breaking the fail-closed coherency recovery model.
Quoted 7 lines
drivers/cxl/core/pci.c +7
-0+ +if (cxl_bi_decoder_enabled (endpoint)) +return ; + +dev_warn (cxlds->dev,"BI disabled by reset\n" ); + cxlds->bi = false; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Davidlohr Bueso
maintainerRe: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
Quoted 2 lines · On Wed, 23 Sep 2026, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cxl/pci: TOCTOU race in BI setup against concurrent AER reset
False positive, see below.
Quoted 27 lines
--
commit
1daa4037cbac0ebc16630c3d4f45c358bd7890f9
Author: Davidlohr Bueso <[email protected]>cxl/pci: Add BI topology enable/disable
This patch implements setup and teardown of the Back-Invalidate (BI) topology on CXL endpoints and upstream components. It also adds a reset detection mechanism to verify whether a reset cleared the hardware BI Enable state.
Quoted 4 lines
drivers/cxl/core/pci.c +0
-0[ ... ]
Quoted 2 lines
drivers/cxl/core/pci.c +2
-0+static int __cxl_bi_ctrl_endpoint (struct cxl_dev_state *cxlds,bool enable) +{[ ... ]
drivers/cxl/core/pci.c void devm_cxl_dport_bi_setup(struct cxl_dport *dport) · line 1219
Quoted 3 lines
drivers/cxl/core/pci.c +3
-0+FIELD_MODIFY (CXL_BI_DECODER_CTRL_BI_ENABLE , &ctrl, enable); +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); + cxlds->bi = enable;[Severity: Medium]
Could this lockless update ofcxlds->birace with a concurrent AER reset handled bycxl_bi_reset_detected()?
Quoted 4 lines
If a user manually binds the
cxl_portdriver via sysfs concurrently with a PCI AER reset (SBR), the manual sysfs bind takes theendpoint->devlock, while the AER recovery (cxl_reset_done()) takes thecxlmd->devlock, allowing them to execute concurrently.
The endpoint port cannot be bound on its own. Unbinding it from cxl_port tears it down through cxl_detach_ep() and a subsequent sysfs bind fails with -ENODEV. The only path that reaches __cxl_bi_ctrl_endpoint(enable) is the endpoint port probe, and that runs synchronously from devm_cxl_add_endpoint().
The driver core holds device_lock(&cxlmd->dev) across cxl_mem_probe(), and cxl_reset_done() takes that same lock before calling cxl_bi_reset_detected(). The reset side therefore cannot observe the window between the writel() and the cxlds->bi store; it waits for the probe to return and only then compares the flag against the hardware bit.
Quoted 5 lines
There is a window between the
writel()that sets the hardware bit and the assignment ofcxlds->bi. If the AER SBR wipes the hardware bit in this window, couldcxl_bi_reset_detected()check the still-falsecxlds->biand ignore the reset?
I widened the window with a 4s msleep() between the writel() and the store, rebinded mem0 and issued an SBR through sysfs while the probe was sleeping in that window:
[16.846] cxl_pci 0000:0d:00.0: reset via cxl_bus [19.290] cxl_pci 0000:0d:00.0: BI requests enabled [19.335] cxl_mem mem0: probe: 0 [19.337] cxl_pci 0000:0d:00.0: BI disabled by reset
The SBR itself lands in the window and clears BI Enable, but the reset write blocks on the memdev lock until the probe completes. .reset_done then runs, sees cxlds->bi set with the hardware bit clear, and clears the flag. A subsequent HDM-DB attach is refused with "BI not enabled on device". The software state does not desynchronize.
Independently of this, patch 4 re-reads BI Enable after committing each endpoint decoder, so a stale flag could not commit a decoder with BI on a device whose BI Enable is clear.
Thanks,
Davidlohr
Re: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
In reply to Davidlohr BuesoQuoted 53 lines · Davidlohr Bueso
Implement
cxl_bi_setup()to enable BI flows on the device and every component in the path, and its teardown counterpartcxl_bi_dealloc(). Setup runs fromdevm_cxl_endpoint_decoders_setup(), between the port's HDM state and its decoders. Registered there, its devres teardown brings BI down after the decoders quiesce and before the HDM state is freed, and BI is settled before the decoders, and later the regions, are looked at. The BI-ID and path enablement belong to the endpoint port's lifetime.Setup is safe in endpoint port probe context. The port probes synchronously from
cxl_mem_probe(), pinning the memdev state the walk consumes, and the whole ancestor path already exists with BI registers mapped (dports at dport-add time, the switch USP RT at first-dport setup) becausedevm_cxl_enumerate_ports()completes before the endpoint is created.Dealloc is safe in endpoint devres context. Both setup and dealloc walk the endpoint's
parent_dporttopology rather than getting the port by bus lookup - an ancestor teardown delists the parent port before the endpoint's devres runs.The topology walk is stable as
parent_dportpointers are fixed at port creation; ancestors cannot be reaped while holding this memdev'scxl_ep; and their own teardown frees dports only after the endpoint is gone.Likewise, the device state outlives the walk -
cxlmd->cxldsis nulled only aftercxl_memdev_unregister()has torn the endpoint down, anddelete_endpoint()clearscxlmd->endpointonly after the endpoint devres has run.Each dport is programmed by its position - the one immediately above the device takes BI Enable, every dport above it takes BI Forward (Table 8-157, Table 9-13), at any switch depth (Table 7-97). Any level can be shared, so
nr_birefcounts endpoints at every dport. Registers are written on the first endpoint and cleared on the last, but only downstream ports commit (Table 8-156), once per endpoint (Table 8-152), and a failed commit undoes its write and commits the undo. A USP advertising a BI Route Table that failed to map is refused rather than treated as absent.nr_bicounts only the endpoints this driver enabled, so a level can be cleared while firmware still has an unbound device on it.A reset may wipe the device's BI Enable, whose reset default is 0 (Table 8-157). .reset_done reads the hardware rather than assume which reset ran, and invalidates
cxlds->bi, failing closed with recovery by rebind as for decoder loss; dealloc unwinds the dport refcounts regardless. It also clearscxlds->biunconditionally - the endpoint disable fails when the hardware already shows BI Enable clear, from a reset .reset_done never saw, and the flag must not outlive the BI Decoder mapping it describes, which the endpoint port releases moments later.
Quoted 7 lines
With dealloc in the endpoint's devres,
delete_endpoint()already holds the parent port's device lock, so to avoid deadlocking, add a per-portbi_lock, serializing the dports that share state (nr_biand the control register at any shared level, the switch USP's BI RT).Reviewed-by Ben Cheatham <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Just one minor comment below
Quoted 368 lines
--- drivers/cxl/core/core.h | 7 + drivers/cxl/core/hdm.c | 10 + drivers/cxl/core/pci.c | 427 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 1 + drivers/cxl/cxl.h | 31 +++ drivers/cxl/pci.c | 8 +- include/cxl/cxl.h | 2 + 7 files changed, 484 insertions(+), 2 deletions(-)drivers/cxl/core/core.h +7
-0@@ -210,6 +210,13 @@ static inline void devm_cxl_dport_ras_setup(struct cxl_dport *dport) { }int cxl_gpf_port_setup (struct cxl_dport *dport);void devm_cxl_dport_bi_setup (struct cxl_dport *dport); +static inline bool cxl_bi_decoder_enabled (struct cxl_port *port) +{ +return FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (port->regs.bi_decoder + +CXL_BI_DECODER_CTRL_OFFSET )); +} +struct cxl_hdm ;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm,struct cxl_endpoint_dvsec_info *info);drivers/cxl/core/hdm.c +10
-0@@ -1274,6 +1274,16 @@ int devm_cxl_endpoint_decoders_setup(struct cxl_port *port)if (rc)return rc; +/* +* Between the port's HDM state and its decoders: devres, +* unwinding in reverse, brings BI down only after the decoders +* quiesce, while its slow walk still precedes the HDM state +* free. +*/ + rc =cxl_bi_setup (port); +if (rc) +dev_dbg (&port->dev,"BI setup failed rc=%d\n" , rc); +return devm_cxl_enumerate_decoders (cxlhdm, &info); }EXPORT_SYMBOL_NS_GPL (devm_cxl_endpoint_decoders_setup,"CXL" );drivers/cxl/core/pci.c +298
-0@@ -2,12 +2,14 @@/* Copyright(c) 2021 Intel Corporation. All rights reserved. */ #include <linux/units.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/iopoll.h> #include <linux/device.h> #include <linux/delay.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <cxl/pci.h> #include <linux/aer.h> +#include <linux/string_choices.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -965,3 +967,428 @@ void devm_cxl_dport_bi_setup(struct cxl_dport *dport)break ; } } + +/* +* BI requires 256B Flit operation on the link. RP/DSP/endpoint must +* also have the BI Decoder cap mapped (@bi); for USPs the BI RT cap +* is optional per CXL 4.0 8.2.4.26, so absent @bi is allowed. +*/ +static bool cxl_is_bi_capable (struct pci_dev *pdev,void __iomem *bi) +{ +if (!cxl_pci_flit_256 (pdev)) +return false; + +if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_UPSTREAM && !bi) { +dev_dbg (&pdev->dev,"No BI Decoder registers.\n" ); +return false; + } + +return true; +} + +/* limit any insane timeouts from hw */ +#define CXL_BI_COMMIT_MAXTMO_US (20 * USEC_PER_SEC) + +static unsigned long __cxl_bi_get_timeout_us (struct device *dev, +unsigned int scale, +unsigned int base) +{ +static const unsigned long scale_tbl[] = { +1 ,10 ,100 ,1000 ,10000 ,100000 ,1000000 ,10000000 , + }; + +if (scale >=ARRAY_SIZE (scale_tbl) || !base) { +dev_dbg (dev,"Invalid BI commit timeout: scale=%u base=%u\n" , + scale, base); +return CXL_BI_COMMIT_MAXTMO_US ; + } + +return scale_tbl[scale] * base; +} + +static int __cxl_bi_wait_commit (struct device *dev,void __iomem *status_reg, +u32 committed_bit,u32 err_bit, +unsigned int scale,unsigned int base) +{ +unsigned long tmo_us, poll_us; +ktime_t start; +u32 status; +int rc; + + tmo_us = min_t(unsigned long, CXL_BI_COMMIT_MAXTMO_US, +__cxl_bi_get_timeout_us (dev, scale, base)); + poll_us = max_t(unsigned long, tmo_us / 10, 1); /* ~10% */ + start =ktime_get (); + + rc =readx_poll_timeout (readl, status_reg, status, + status & (committed_bit | err_bit), + poll_us, tmo_us); +if (rc) { +dev_err (dev,"BI-ID commit timed out (%luus)\n" , tmo_us); +return rc;/* -ETIMEDOUT */ + } + +if (status & err_bit) { +dev_err (dev,"BI-ID commit rejected by hardware\n" ); +return -EIO ; + } + +dev_dbg (dev,"BI-ID commit wait took %lluus\n" , +ktime_to_us (ktime_sub (ktime_get (), start))); +return 0 ; +} + +/* BI RT only exists on switch upstream ports. */ +static int __cxl_bi_commit_rt (struct device *dev,void __iomem *bi) +{ +u32 status, ctrl; +unsigned int scale, base; + +if (!FIELD_GET (CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ , +readl (bi +CXL_BI_RT_CAPS_OFFSET ))) +return 0 ; + + ctrl =readl (bi +CXL_BI_RT_CTRL_OFFSET ); +writel (ctrl & ~CXL_BI_RT_CTRL_BI_COMMIT , bi +CXL_BI_RT_CTRL_OFFSET ); +writel (ctrl |CXL_BI_RT_CTRL_BI_COMMIT , bi +CXL_BI_RT_CTRL_OFFSET ); + + status =readl (bi +CXL_BI_RT_STATUS_OFFSET ); + scale =FIELD_GET (CXL_BI_RT_STATUS_BI_COMMIT_TM_SCALE , status); + base =FIELD_GET (CXL_BI_RT_STATUS_BI_COMMIT_TM_BASE , status); + +return __cxl_bi_wait_commit (dev, bi +CXL_BI_RT_STATUS_OFFSET , +CXL_BI_RT_STATUS_BI_COMMITTED , +CXL_BI_RT_STATUS_BI_ERR_NOT_COMMITTED , + scale, base); +} + +static int __cxl_bi_commit_decoder (struct device *dev,void __iomem *bi) +{ +u32 status, ctrl; +unsigned int scale, base; + +if (!FIELD_GET (CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ , +readl (bi +CXL_BI_DECODER_CAPS_OFFSET ))) +return 0 ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl & ~CXL_BI_DECODER_CTRL_BI_COMMIT , + bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl |CXL_BI_DECODER_CTRL_BI_COMMIT , + bi +CXL_BI_DECODER_CTRL_OFFSET ); + + status =readl (bi +CXL_BI_DECODER_STATUS_OFFSET ); + scale =FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMIT_TM_SCALE , status); + base =FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMIT_TM_BASE , status); + +return __cxl_bi_wait_commit (dev, bi +CXL_BI_DECODER_STATUS_OFFSET , +CXL_BI_DECODER_STATUS_BI_COMMITTED , +CXL_BI_DECODER_STATUS_BI_ERR_NOT_COMMITTED , + scale, base); +} + +static int cxl_bi_commit_dport (struct cxl_dport *dport) +{ +struct cxl_port *port = dport->port; +int rc; + +lockdep_assert_held (&port->bi_lock); + +/* root ports never require the explicit commit */ +if (pci_pcie_type (to_pci_dev (dport->dport_dev)) != +PCI_EXP_TYPE_DOWNSTREAM ) +return 0 ; + + rc =__cxl_bi_commit_decoder (dport->dport_dev, dport->regs.bi_decoder); +if (rc) +return rc; + +if (port->regs.bi_rt) + rc =__cxl_bi_commit_rt (&port->dev, port->regs.bi_rt); + +return rc; +} + +/* +* Enable BI-ID changes in the given level of the topology. +* @direct says the device is connected directly to this dport, which +* takes BI Enable; every dport above it takes BI Forward. +*/ +static int cxl_bi_ctrl_dport_enable (struct cxl_dport *dport,bool direct) +{ +struct cxl_port *port = dport->port; +u32 ctrl, value, set, clr; +void __iomem *bi; +int rc; + +guard (mutex)(&port->bi_lock); + + bi = dport->regs.bi_decoder; +if (!bi) +return -EINVAL ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); + + set = direct ?CXL_BI_DECODER_CTRL_BI_ENABLE : +CXL_BI_DECODER_CTRL_BI_FW ; + clr = direct ?CXL_BI_DECODER_CTRL_BI_FW : +CXL_BI_DECODER_CTRL_BI_ENABLE ; + + value = (ctrl | set) & ~clr; +if (value != ctrl) +writel (value, bi +CXL_BI_DECODER_CTRL_OFFSET ); + +/* owed per new device below, not per register change */ + rc =cxl_bi_commit_dport (dport); +if (rc) { +if (value != ctrl) { +/* the undo is a BI-ID change owing its own commit */ +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); +cxl_bi_commit_dport (dport); + } +return rc; + } + dport->nr_bi++; + +return 0 ; +} + +/* +* Dealloc BI-ID changes in the given level of the topology. Called +* once per endpoint that enabled this level: on teardown, or to +* unwind a path that failed partway up. +*/ +static int cxl_bi_ctrl_dport_disable (struct cxl_dport *dport) +{ +struct cxl_port *port = dport->port; +void __iomem *bi; +u32 ctrl; + +guard (mutex)(&port->bi_lock); + + bi = dport->regs.bi_decoder; +if (!bi) +return -EINVAL ; + +if (WARN_ON_ONCE (dport->nr_bi ==0 )) +return -EINVAL ; + +/* others below still need this level */ +if (--dport->nr_bi >0 ) +return 0 ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl & ~(CXL_BI_DECODER_CTRL_BI_FW | +CXL_BI_DECODER_CTRL_BI_ENABLE ), + bi +CXL_BI_DECODER_CTRL_OFFSET ); + +return cxl_bi_commit_dport (dport); +} + +static int __cxl_bi_ctrl_endpoint (struct cxl_dev_state *cxlds,bool enable) +{ +struct cxl_port *endpoint = cxlds->cxlmd->endpoint; +void __iomem *bi = endpoint->regs.bi_decoder; +u32 ctrl; + +if (!bi) +return -EINVAL ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); + +if (enable) { +if (FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , ctrl)) { +if (cxlds->bi) +return 0 ; +dev_err (cxlds->dev, +"BI already enabled in hardware\n" ); +return -EBUSY ; + } + }else { +if (!FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , ctrl)) { +if (!cxlds->bi) +return 0 ; +dev_err (cxlds->dev, +"BI already disabled in hardware\n" ); +return -EBUSY ; + } + } + +FIELD_MODIFY (CXL_BI_DECODER_CTRL_BI_ENABLE , &ctrl, enable); +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); + cxlds->bi = enable; + +dev_dbg (cxlds->dev,"BI requests %s\n" ,str_enabled_disabled (enable)); + +return 0 ; +} + +static int cxl_bi_ctrl_endpoint_enable (struct cxl_dev_state *cxlds) +{ +return __cxl_bi_ctrl_endpoint (cxlds, true); +} + +static int cxl_bi_ctrl_endpoint_disable (struct cxl_dev_state *cxlds) +{ +return __cxl_bi_ctrl_endpoint (cxlds, false); +} + +/* +* devm teardown on endpoint port destruction. Registered before the +* decoders, so devres runs it after them: regions are detached and +* decoders unregistered by the time BI comes down. +*/ +static void cxl_bi_dealloc (void *data) +{ +struct cxl_port *endpoint = data; +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_dport *dport_iter; +struct cxl_port *port_iter; + +cxl_bi_ctrl_endpoint_disable (cxlds); + cxlds->bi = false; + +/* +* Walk the same parent_dport chain that enabled the path. A bus +* lookup cannot stand in for it: an ancestor-driven teardown +* delists the parent port before this devres action runs. +*/ + dport_iter = endpoint->parent_dport; + port_iter = dport_iter->port; +while (!is_cxl_root (port_iter)) { +int rc =cxl_bi_ctrl_dport_disable (dport_iter); + +/* best effort */ +if (rc) +dev_dbg (&port_iter->dev, +"BI dport disable failed: %d\n" , rc);
drivers/cxl/core/pci.c void devm_cxl_dport_bi_setup(struct cxl_dport *dport) · line 1275
Quoted 10 lines
drivers/cxl/core/pci.c +10
-0+ + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } +} + +/* +* Enable BI on every dport in the path, then on the device itself. +* On failure, unwind only the dports that enabled. +*/
I think it is better to mention the enable/disable flow implementation based on the description of CXL r4.0 Section 9.14 Back-Invalidate Configuration.
Quoted 247 lines
drivers/cxl/core/pci.c +119
-0+static int cxl_bi_enable_path (struct cxl_dev_state *cxlds, +struct cxl_port *port,struct cxl_dport *dport) +{ +struct cxl_dport *dport_iter, *failed; +struct cxl_port *port_iter; +int rc; + + port_iter = port; + dport_iter = dport; +while (!is_cxl_root (port_iter)) { + rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport); +if (rc) + goto err_rollback; + + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } + + rc =cxl_bi_ctrl_endpoint_enable (cxlds); +if (rc) + goto err_rollback; + +return 0 ; + +err_rollback: + failed = dport_iter; + dport_iter = dport; + port_iter = port; +while (!is_cxl_root (port_iter) && dport_iter != failed) { +cxl_bi_ctrl_dport_disable (dport_iter); + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } +return rc; +} + +/* +* An SBR wipes the device's BI Enable; an FLR leaves it alone. +* The check is against the hardware, not decoder state: BI is +* enabled at probe, so it can be wiped with no decoder ever +* committed. A wipe invalidates the software state; BI is never +* re-enabled here. +*/ +void cxl_bi_reset_detected (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; + +if (!cxlds->bi) +return ; + +if (cxl_bi_decoder_enabled (endpoint)) +return ; + +dev_warn (cxlds->dev,"BI disabled by reset\n" ); + cxlds->bi = false; +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_reset_detected,"CXL" ); + +int cxl_bi_setup (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_dport *dport = endpoint->parent_dport; +struct cxl_dport *dport_iter; +struct cxl_port *port_iter; +int rc; + +if (!dev_is_pci (cxlds->dev)) +return 0 ; + +/* BI is VH-only */ +if (cxlds->rcd) +return 0 ; + +if (!cxl_is_bi_capable (to_pci_dev (cxlds->dev), + endpoint->regs.bi_decoder)) +return 0 ; + + port_iter = dport->port; + dport_iter = dport; +while (!is_cxl_root (port_iter)) { +/* check rp, dsp */ +if (!cxl_is_bi_capable (to_pci_dev (dport_iter->dport_dev), + dport_iter->regs.bi_decoder)) { +dev_dbg (cxlds->dev,"BI not supported by topology\n" ); +return 0 ; + } + +/* check usp */ +if (dev_is_pci (port_iter->uport_dev) && +pci_pcie_type (to_pci_dev (port_iter->uport_dev)) == +PCI_EXP_TYPE_UPSTREAM ) { +if (!cxl_is_bi_capable (to_pci_dev (port_iter->uport_dev), +NULL )) { +dev_dbg (cxlds->dev, +"BI not supported by USP\n" ); +return 0 ; + } +if (port_iter->reg_map.component_map.bi_rt.valid && + !port_iter->regs.bi_rt) { +dev_dbg (cxlds->dev, +"BI RT advertised but unmapped\n" ); +return 0 ; + } + } + + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } + + rc =cxl_bi_enable_path (cxlds, dport->port, dport); +if (rc) +return rc; + +return devm_add_action_or_reset (&endpoint->dev, cxl_bi_dealloc, + endpoint); +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_setup,"CXL" );drivers/cxl/core/port.c +1
-0@@ -742,6 +742,7 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev,xa_init (&port->dports);xa_init (&port->endpoints);xa_init (&port->regions); +mutex_init (&port->bi_lock); port->component_reg_phys =CXL_RESOURCE_NONE ;device_initialize (dev);drivers/cxl/cxl.h +31
-0@@ -180,6 +180,31 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_HEADERLOG_TRACE_SIZE SZ_512#define CXL_HEADERLOG_TRACE_SIZE_U32 (CXL_HEADERLOG_TRACE_SIZE / sizeof(u32)) +/* CXL 4.0 8.2.4.26 CXL BI Route Table Capability Structure */ +#define CXL_BI_RT_CAPS_OFFSET 0x0 +#define CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ BIT(0) +#define CXL_BI_RT_CTRL_OFFSET 0x4 +#define CXL_BI_RT_CTRL_BI_COMMIT BIT(0) +#define CXL_BI_RT_STATUS_OFFSET 0x8 +#define CXL_BI_RT_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_RT_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) + +/* CXL 4.0 8.2.4.27 CXL BI Decoder Capability Structure */ +#define CXL_BI_DECODER_CAPS_OFFSET 0x0 +#define CXL_BI_DECODER_CAPS_HDMD_CAP BIT(0) +#define CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ BIT(1) +#define CXL_BI_DECODER_CTRL_OFFSET 0x4 +#define CXL_BI_DECODER_CTRL_BI_FW BIT(0) +#define CXL_BI_DECODER_CTRL_BI_ENABLE BIT(1) +#define CXL_BI_DECODER_CTRL_BI_COMMIT BIT(2) +#define CXL_BI_DECODER_STATUS_OFFSET 0x8 +#define CXL_BI_DECODER_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_DECODER_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) +/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0#define CXLDEV_CAP_ARRAY_CAP_ID 0@@ -565,6 +590,7 @@ struct cxl_dax_region {* @decoder_ida: allocator for decoder ids * @reg_map: component and ras register mapping parameters * @regs: mapped component registers +* @bi_lock: serializes BI Decoder/RT state of this port's dports * @nr_dports: number of entries in @dports * @hdm_end: track last allocated HDM decoder instance for allocation ordering * @commit_end: cursor to track highest committed decoder for commit ordering @@ -587,6 +613,7 @@ struct cxl_port {struct ida decoder_ida;struct cxl_register_map reg_map;struct cxl_component_regs regs; +struct mutex bi_lock;/* dport BI state shared below this port */ int nr_dports;int hdm_end;int commit_end;@@ -650,6 +677,7 @@ struct cxl_rcrb_info {* @coord: access coordinates (bandwidth and latency performance attributes) * @link_latency: calculated PCIe downstream latency * @gpf_dvsec: Cached GPF port DVSEC +* @nr_bi: number of BI-enabled endpoints below this dport */ struct cxl_dport {struct device *dport_dev;@@ -662,6 +690,7 @@ struct cxl_dport {struct access_coordinate coord[ACCESS_COORDINATE_MAX ];long link_latency;int gpf_dvsec; +int nr_bi; };/** @@ -920,6 +949,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, struct access_coordinate *c2);bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +int cxl_bi_setup (struct cxl_port *endpoint); +void cxl_bi_reset_detected (struct cxl_port *endpoint);struct cxl_dport *devm_cxl_add_dport_by_dev (struct cxl_port *port,struct device *dport_dev);drivers/cxl/pci.c +6
-2@@ -987,8 +987,12 @@ static void cxl_reset_done(struct pci_dev *pdev)if (!cxlmd->dev.driver)return ; -if (cxlmd->endpoint && -cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +if (!cxlmd->endpoint) +return ; + +cxl_bi_reset_detected (cxlmd->endpoint); + +if (cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) {device_for_each_child (&cxlmd->endpoint->dev,NULL , cxl_endpoint_decoder_clear_reset_flags);include/cxl/cxl.h +2
-0@@ -168,6 +168,7 @@ struct cxl_dpa_partition {* @regs: Parsed register blocks * @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) +* @bi: device is BI (Back-Invalidate) enabled * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array @@ -187,6 +188,7 @@ struct cxl_dev_state {struct cxl_device_regs regs;int cxl_dvsec;bool rcd; +bool bi;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];
Re: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
In reply to Davidlohr BuesoQuoted 53 lines · On Tue, 22 Sep 2026 16:38:39 -0700 Davidlohr Bueso <[email protected]> wrote:
Implement
cxl_bi_setup()to enable BI flows on the device and every component in the path, and its teardown counterpartcxl_bi_dealloc(). Setup runs fromdevm_cxl_endpoint_decoders_setup(), between the port's HDM state and its decoders. Registered there, its devres teardown brings BI down after the decoders quiesce and before the HDM state is freed, and BI is settled before the decoders, and later the regions, are looked at. The BI-ID and path enablement belong to the endpoint port's lifetime.Setup is safe in endpoint port probe context. The port probes synchronously from
cxl_mem_probe(), pinning the memdev state the walk consumes, and the whole ancestor path already exists with BI registers mapped (dports at dport-add time, the switch USP RT at first-dport setup) becausedevm_cxl_enumerate_ports()completes before the endpoint is created.Dealloc is safe in endpoint devres context. Both setup and dealloc walk the endpoint's
parent_dporttopology rather than getting the port by bus lookup - an ancestor teardown delists the parent port before the endpoint's devres runs.The topology walk is stable as
parent_dportpointers are fixed at port creation; ancestors cannot be reaped while holding this memdev'scxl_ep; and their own teardown frees dports only after the endpoint is gone.Likewise, the device state outlives the walk -
cxlmd->cxldsis nulled only aftercxl_memdev_unregister()has torn the endpoint down, anddelete_endpoint()clearscxlmd->endpointonly after the endpoint devres has run.Each dport is programmed by its position - the one immediately above the device takes BI Enable, every dport above it takes BI Forward (Table 8-157, Table 9-13), at any switch depth (Table 7-97). Any level can be shared, so
nr_birefcounts endpoints at every dport. Registers are written on the first endpoint and cleared on the last, but only downstream ports commit (Table 8-156), once per endpoint (Table 8-152), and a failed commit undoes its write and commits the undo. A USP advertising a BI Route Table that failed to map is refused rather than treated as absent.nr_bicounts only the endpoints this driver enabled, so a level can be cleared while firmware still has an unbound device on it.A reset may wipe the device's BI Enable, whose reset default is 0 (Table 8-157). .reset_done reads the hardware rather than assume which reset ran, and invalidates
cxlds->bi, failing closed with recovery by rebind as for decoder loss; dealloc unwinds the dport refcounts regardless. It also clearscxlds->biunconditionally - the endpoint disable fails when the hardware already shows BI Enable clear, from a reset .reset_done never saw, and the flag must not outlive the BI Decoder mapping it describes, which the endpoint port releases moments later.
Quoted 7 lines
With dealloc in the endpoint's devres,
delete_endpoint()already holds the parent port's device lock, so to avoid deadlocking, add a per-portbi_lock, serializing the dports that share state (nr_biand the control register at any shared level, the switch USP's BI RT).Reviewed-by Ben Cheatham <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Re: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
In reply to Davidlohr BuesoQuoted 404 lines · Davidlohr Bueso
Implement
cxl_bi_setup()to enable BI flows on the device and every component in the path, and its teardown counterpartcxl_bi_dealloc(). Setup runs fromdevm_cxl_endpoint_decoders_setup(), between the port's HDM state and its decoders. Registered there, its devres teardown brings BI down after the decoders quiesce and before the HDM state is freed, and BI is settled before the decoders, and later the regions, are looked at. The BI-ID and path enablement belong to the endpoint port's lifetime.Setup is safe in endpoint port probe context. The port probes synchronously from
cxl_mem_probe(), pinning the memdev state the walk consumes, and the whole ancestor path already exists with BI registers mapped (dports at dport-add time, the switch USP RT at first-dport setup) becausedevm_cxl_enumerate_ports()completes before the endpoint is created.Dealloc is safe in endpoint devres context. Both setup and dealloc walk the endpoint's
parent_dporttopology rather than getting the port by bus lookup - an ancestor teardown delists the parent port before the endpoint's devres runs.The topology walk is stable as
parent_dportpointers are fixed at port creation; ancestors cannot be reaped while holding this memdev'scxl_ep; and their own teardown frees dports only after the endpoint is gone.Likewise, the device state outlives the walk -
cxlmd->cxldsis nulled only aftercxl_memdev_unregister()has torn the endpoint down, anddelete_endpoint()clearscxlmd->endpointonly after the endpoint devres has run.Each dport is programmed by its position - the one immediately above the device takes BI Enable, every dport above it takes BI Forward (Table 8-157, Table 9-13), at any switch depth (Table 7-97). Any level can be shared, so
nr_birefcounts endpoints at every dport. Registers are written on the first endpoint and cleared on the last, but only downstream ports commit (Table 8-156), once per endpoint (Table 8-152), and a failed commit undoes its write and commits the undo. A USP advertising a BI Route Table that failed to map is refused rather than treated as absent.nr_bicounts only the endpoints this driver enabled, so a level can be cleared while firmware still has an unbound device on it.A reset may wipe the device's BI Enable, whose reset default is 0 (Table 8-157). .reset_done reads the hardware rather than assume which reset ran, and invalidates
cxlds->bi, failing closed with recovery by rebind as for decoder loss; dealloc unwinds the dport refcounts regardless. It also clearscxlds->biunconditionally - the endpoint disable fails when the hardware already shows BI Enable clear, from a reset .reset_done never saw, and the flag must not outlive the BI Decoder mapping it describes, which the endpoint port releases moments later.With dealloc in the endpoint's devres,
delete_endpoint()already holds the parent port's device lock, so to avoid deadlocking, add a per-portbi_lock, serializing the dports that share state (nr_biand the control register at any shared level, the switch USP's BI RT).Reviewed-by Ben Cheatham <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/core.h | 7 + drivers/cxl/core/hdm.c | 10 + drivers/cxl/core/pci.c | 427 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 1 + drivers/cxl/cxl.h | 31 +++ drivers/cxl/pci.c | 8 +- include/cxl/cxl.h | 2 + 7 files changed, 484 insertions(+), 2 deletions(-)drivers/cxl/core/core.h +7
-0@@ -210,6 +210,13 @@ static inline void devm_cxl_dport_ras_setup(struct cxl_dport *dport) { }int cxl_gpf_port_setup (struct cxl_dport *dport);void devm_cxl_dport_bi_setup (struct cxl_dport *dport); +static inline bool cxl_bi_decoder_enabled (struct cxl_port *port) +{ +return FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (port->regs.bi_decoder + +CXL_BI_DECODER_CTRL_OFFSET )); +} +struct cxl_hdm ;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm,struct cxl_endpoint_dvsec_info *info);drivers/cxl/core/hdm.c +10
-0@@ -1274,6 +1274,16 @@ int devm_cxl_endpoint_decoders_setup(struct cxl_port *port)if (rc)return rc; +/* +* Between the port's HDM state and its decoders: devres, +* unwinding in reverse, brings BI down only after the decoders +* quiesce, while its slow walk still precedes the HDM state +* free. +*/ + rc =cxl_bi_setup (port); +if (rc) +dev_dbg (&port->dev,"BI setup failed rc=%d\n" , rc); +return devm_cxl_enumerate_decoders (cxlhdm, &info); }EXPORT_SYMBOL_NS_GPL (devm_cxl_endpoint_decoders_setup,"CXL" );drivers/cxl/core/pci.c +274
-0@@ -2,12 +2,14 @@/* Copyright(c) 2021 Intel Corporation. All rights reserved. */ #include <linux/units.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/iopoll.h> #include <linux/device.h> #include <linux/delay.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <cxl/pci.h> #include <linux/aer.h> +#include <linux/string_choices.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -965,3 +967,428 @@ void devm_cxl_dport_bi_setup(struct cxl_dport *dport)break ; } } + +/* +* BI requires 256B Flit operation on the link. RP/DSP/endpoint must +* also have the BI Decoder cap mapped (@bi); for USPs the BI RT cap +* is optional per CXL 4.0 8.2.4.26, so absent @bi is allowed. +*/ +static bool cxl_is_bi_capable (struct pci_dev *pdev,void __iomem *bi) +{ +if (!cxl_pci_flit_256 (pdev)) +return false; + +if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_UPSTREAM && !bi) { +dev_dbg (&pdev->dev,"No BI Decoder registers.\n" ); +return false; + } + +return true; +} + +/* limit any insane timeouts from hw */ +#define CXL_BI_COMMIT_MAXTMO_US (20 * USEC_PER_SEC) + +static unsigned long __cxl_bi_get_timeout_us (struct device *dev, +unsigned int scale, +unsigned int base) +{ +static const unsigned long scale_tbl[] = { +1 ,10 ,100 ,1000 ,10000 ,100000 ,1000000 ,10000000 , + }; + +if (scale >=ARRAY_SIZE (scale_tbl) || !base) { +dev_dbg (dev,"Invalid BI commit timeout: scale=%u base=%u\n" , + scale, base); +return CXL_BI_COMMIT_MAXTMO_US ; + } + +return scale_tbl[scale] * base; +} + +static int __cxl_bi_wait_commit (struct device *dev,void __iomem *status_reg, +u32 committed_bit,u32 err_bit, +unsigned int scale,unsigned int base) +{ +unsigned long tmo_us, poll_us; +ktime_t start; +u32 status; +int rc; + + tmo_us = min_t(unsigned long, CXL_BI_COMMIT_MAXTMO_US, +__cxl_bi_get_timeout_us (dev, scale, base)); + poll_us = max_t(unsigned long, tmo_us / 10, 1); /* ~10% */ + start =ktime_get (); + + rc =readx_poll_timeout (readl, status_reg, status, + status & (committed_bit | err_bit), + poll_us, tmo_us); +if (rc) { +dev_err (dev,"BI-ID commit timed out (%luus)\n" , tmo_us); +return rc;/* -ETIMEDOUT */ + } + +if (status & err_bit) { +dev_err (dev,"BI-ID commit rejected by hardware\n" ); +return -EIO ; + } + +dev_dbg (dev,"BI-ID commit wait took %lluus\n" , +ktime_to_us (ktime_sub (ktime_get (), start))); +return 0 ; +} + +/* BI RT only exists on switch upstream ports. */ +static int __cxl_bi_commit_rt (struct device *dev,void __iomem *bi) +{ +u32 status, ctrl; +unsigned int scale, base; + +if (!FIELD_GET (CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ , +readl (bi +CXL_BI_RT_CAPS_OFFSET ))) +return 0 ; + + ctrl =readl (bi +CXL_BI_RT_CTRL_OFFSET ); +writel (ctrl & ~CXL_BI_RT_CTRL_BI_COMMIT , bi +CXL_BI_RT_CTRL_OFFSET ); +writel (ctrl |CXL_BI_RT_CTRL_BI_COMMIT , bi +CXL_BI_RT_CTRL_OFFSET ); + + status =readl (bi +CXL_BI_RT_STATUS_OFFSET ); + scale =FIELD_GET (CXL_BI_RT_STATUS_BI_COMMIT_TM_SCALE , status); + base =FIELD_GET (CXL_BI_RT_STATUS_BI_COMMIT_TM_BASE , status); + +return __cxl_bi_wait_commit (dev, bi +CXL_BI_RT_STATUS_OFFSET , +CXL_BI_RT_STATUS_BI_COMMITTED , +CXL_BI_RT_STATUS_BI_ERR_NOT_COMMITTED , + scale, base); +} + +static int __cxl_bi_commit_decoder (struct device *dev,void __iomem *bi) +{ +u32 status, ctrl; +unsigned int scale, base; + +if (!FIELD_GET (CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ , +readl (bi +CXL_BI_DECODER_CAPS_OFFSET ))) +return 0 ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl & ~CXL_BI_DECODER_CTRL_BI_COMMIT , + bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl |CXL_BI_DECODER_CTRL_BI_COMMIT , + bi +CXL_BI_DECODER_CTRL_OFFSET ); + + status =readl (bi +CXL_BI_DECODER_STATUS_OFFSET ); + scale =FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMIT_TM_SCALE , status); + base =FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMIT_TM_BASE , status); + +return __cxl_bi_wait_commit (dev, bi +CXL_BI_DECODER_STATUS_OFFSET , +CXL_BI_DECODER_STATUS_BI_COMMITTED , +CXL_BI_DECODER_STATUS_BI_ERR_NOT_COMMITTED , + scale, base); +} + +static int cxl_bi_commit_dport (struct cxl_dport *dport) +{ +struct cxl_port *port = dport->port; +int rc; + +lockdep_assert_held (&port->bi_lock); + +/* root ports never require the explicit commit */ +if (pci_pcie_type (to_pci_dev (dport->dport_dev)) != +PCI_EXP_TYPE_DOWNSTREAM ) +return 0 ; + + rc =__cxl_bi_commit_decoder (dport->dport_dev, dport->regs.bi_decoder); +if (rc) +return rc; + +if (port->regs.bi_rt) + rc =__cxl_bi_commit_rt (&port->dev, port->regs.bi_rt); + +return rc; +} + +/* +* Enable BI-ID changes in the given level of the topology. +* @direct says the device is connected directly to this dport, which +* takes BI Enable; every dport above it takes BI Forward. +*/ +static int cxl_bi_ctrl_dport_enable (struct cxl_dport *dport,bool direct) +{ +struct cxl_port *port = dport->port; +u32 ctrl, value, set, clr; +void __iomem *bi; +int rc; + +guard (mutex)(&port->bi_lock); + + bi = dport->regs.bi_decoder; +if (!bi) +return -EINVAL ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); + + set = direct ?CXL_BI_DECODER_CTRL_BI_ENABLE : +CXL_BI_DECODER_CTRL_BI_FW ; + clr = direct ?CXL_BI_DECODER_CTRL_BI_FW : +CXL_BI_DECODER_CTRL_BI_ENABLE ; + + value = (ctrl | set) & ~clr; +if (value != ctrl) +writel (value, bi +CXL_BI_DECODER_CTRL_OFFSET ); + +/* owed per new device below, not per register change */ + rc =cxl_bi_commit_dport (dport); +if (rc) { +if (value != ctrl) { +/* the undo is a BI-ID change owing its own commit */ +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); +cxl_bi_commit_dport (dport); + } +return rc; + } + dport->nr_bi++; + +return 0 ; +} + +/* +* Dealloc BI-ID changes in the given level of the topology. Called +* once per endpoint that enabled this level: on teardown, or to +* unwind a path that failed partway up. +*/ +static int cxl_bi_ctrl_dport_disable (struct cxl_dport *dport) +{ +struct cxl_port *port = dport->port; +void __iomem *bi; +u32 ctrl; + +guard (mutex)(&port->bi_lock); + + bi = dport->regs.bi_decoder; +if (!bi) +return -EINVAL ; + +if (WARN_ON_ONCE (dport->nr_bi ==0 )) +return -EINVAL ; + +/* others below still need this level */ +if (--dport->nr_bi >0 ) +return 0 ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); +writel (ctrl & ~(CXL_BI_DECODER_CTRL_BI_FW | +CXL_BI_DECODER_CTRL_BI_ENABLE ), + bi +CXL_BI_DECODER_CTRL_OFFSET ); + +return cxl_bi_commit_dport (dport); +} + +static int __cxl_bi_ctrl_endpoint (struct cxl_dev_state *cxlds,bool enable) +{ +struct cxl_port *endpoint = cxlds->cxlmd->endpoint; +void __iomem *bi = endpoint->regs.bi_decoder; +u32 ctrl; + +if (!bi) +return -EINVAL ; + + ctrl =readl (bi +CXL_BI_DECODER_CTRL_OFFSET ); + +if (enable) { +if (FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , ctrl)) { +if (cxlds->bi) +return 0 ; +dev_err (cxlds->dev, +"BI already enabled in hardware\n" ); +return -EBUSY ; + } + }else { +if (!FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , ctrl)) { +if (!cxlds->bi) +return 0 ; +dev_err (cxlds->dev, +"BI already disabled in hardware\n" ); +return -EBUSY ; + } + } + +FIELD_MODIFY (CXL_BI_DECODER_CTRL_BI_ENABLE , &ctrl, enable); +writel (ctrl, bi +CXL_BI_DECODER_CTRL_OFFSET ); + cxlds->bi = enable; + +dev_dbg (cxlds->dev,"BI requests %s\n" ,str_enabled_disabled (enable)); + +return 0 ; +} + +static int cxl_bi_ctrl_endpoint_enable (struct cxl_dev_state *cxlds) +{ +return __cxl_bi_ctrl_endpoint (cxlds, true); +} + +static int cxl_bi_ctrl_endpoint_disable (struct cxl_dev_state *cxlds) +{ +return __cxl_bi_ctrl_endpoint (cxlds, false); +} + +/* +* devm teardown on endpoint port destruction. Registered before the +* decoders, so devres runs it after them: regions are detached and +* decoders unregistered by the time BI comes down. +*/ +static void cxl_bi_dealloc (void *data)
drivers/cxl/core/pci.c void devm_cxl_dport_bi_setup(struct cxl_dport *dport) · line 1251
Quoted 10 lines
drivers/cxl/core/pci.c +10
-0+{ +struct cxl_port *endpoint = data; +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_dport *dport_iter; +struct cxl_port *port_iter; + +cxl_bi_ctrl_endpoint_disable (cxlds); + cxlds->bi = false; +
Is it safe to disable BI unconditionally ?
For a FW-configured HDM-DB region with locked decoders, resetting decoders can leave the HW mapping active. If that memory is boot System RAM, it can remain in use after driver unbind, while the cleanup here disable BI.
I think one of the scenario is when decoders are boot-programmed and locked. FW could configure such a range with BI enabled and expose it
Should we preserve BI when those locked mapping remain active ?
Best regards,
Richard Cheng.
Quoted 274 lines
drivers/cxl/core/pci.c +143
-0+/* +* Walk the same parent_dport chain that enabled the path. A bus +* lookup cannot stand in for it: an ancestor-driven teardown +* delists the parent port before this devres action runs. +*/ + dport_iter = endpoint->parent_dport; + port_iter = dport_iter->port; +while (!is_cxl_root (port_iter)) { +int rc =cxl_bi_ctrl_dport_disable (dport_iter); + +/* best effort */ +if (rc) +dev_dbg (&port_iter->dev, +"BI dport disable failed: %d\n" , rc); + + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } +} + +/* +* Enable BI on every dport in the path, then on the device itself. +* On failure, unwind only the dports that enabled. +*/ +static int cxl_bi_enable_path (struct cxl_dev_state *cxlds, +struct cxl_port *port,struct cxl_dport *dport) +{ +struct cxl_dport *dport_iter, *failed; +struct cxl_port *port_iter; +int rc; + + port_iter = port; + dport_iter = dport; +while (!is_cxl_root (port_iter)) { + rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport); +if (rc) + goto err_rollback; + + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } + + rc =cxl_bi_ctrl_endpoint_enable (cxlds); +if (rc) + goto err_rollback; + +return 0 ; + +err_rollback: + failed = dport_iter; + dport_iter = dport; + port_iter = port; +while (!is_cxl_root (port_iter) && dport_iter != failed) { +cxl_bi_ctrl_dport_disable (dport_iter); + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } +return rc; +} + +/* +* An SBR wipes the device's BI Enable; an FLR leaves it alone. +* The check is against the hardware, not decoder state: BI is +* enabled at probe, so it can be wiped with no decoder ever +* committed. A wipe invalidates the software state; BI is never +* re-enabled here. +*/ +void cxl_bi_reset_detected (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; + +if (!cxlds->bi) +return ; + +if (cxl_bi_decoder_enabled (endpoint)) +return ; + +dev_warn (cxlds->dev,"BI disabled by reset\n" ); + cxlds->bi = false; +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_reset_detected,"CXL" ); + +int cxl_bi_setup (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_dport *dport = endpoint->parent_dport; +struct cxl_dport *dport_iter; +struct cxl_port *port_iter; +int rc; + +if (!dev_is_pci (cxlds->dev)) +return 0 ; + +/* BI is VH-only */ +if (cxlds->rcd) +return 0 ; + +if (!cxl_is_bi_capable (to_pci_dev (cxlds->dev), + endpoint->regs.bi_decoder)) +return 0 ; + + port_iter = dport->port; + dport_iter = dport; +while (!is_cxl_root (port_iter)) { +/* check rp, dsp */ +if (!cxl_is_bi_capable (to_pci_dev (dport_iter->dport_dev), + dport_iter->regs.bi_decoder)) { +dev_dbg (cxlds->dev,"BI not supported by topology\n" ); +return 0 ; + } + +/* check usp */ +if (dev_is_pci (port_iter->uport_dev) && +pci_pcie_type (to_pci_dev (port_iter->uport_dev)) == +PCI_EXP_TYPE_UPSTREAM ) { +if (!cxl_is_bi_capable (to_pci_dev (port_iter->uport_dev), +NULL )) { +dev_dbg (cxlds->dev, +"BI not supported by USP\n" ); +return 0 ; + } +if (port_iter->reg_map.component_map.bi_rt.valid && + !port_iter->regs.bi_rt) { +dev_dbg (cxlds->dev, +"BI RT advertised but unmapped\n" ); +return 0 ; + } + } + + dport_iter = port_iter->parent_dport; + port_iter = dport_iter->port; + } + + rc =cxl_bi_enable_path (cxlds, dport->port, dport); +if (rc) +return rc; + +return devm_add_action_or_reset (&endpoint->dev, cxl_bi_dealloc, + endpoint); +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_setup,"CXL" );drivers/cxl/core/port.c +1
-0@@ -742,6 +742,7 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev,xa_init (&port->dports);xa_init (&port->endpoints);xa_init (&port->regions); +mutex_init (&port->bi_lock); port->component_reg_phys =CXL_RESOURCE_NONE ;device_initialize (dev);drivers/cxl/cxl.h +31
-0@@ -180,6 +180,31 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_HEADERLOG_TRACE_SIZE SZ_512#define CXL_HEADERLOG_TRACE_SIZE_U32 (CXL_HEADERLOG_TRACE_SIZE / sizeof(u32)) +/* CXL 4.0 8.2.4.26 CXL BI Route Table Capability Structure */ +#define CXL_BI_RT_CAPS_OFFSET 0x0 +#define CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ BIT(0) +#define CXL_BI_RT_CTRL_OFFSET 0x4 +#define CXL_BI_RT_CTRL_BI_COMMIT BIT(0) +#define CXL_BI_RT_STATUS_OFFSET 0x8 +#define CXL_BI_RT_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_RT_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_RT_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) + +/* CXL 4.0 8.2.4.27 CXL BI Decoder Capability Structure */ +#define CXL_BI_DECODER_CAPS_OFFSET 0x0 +#define CXL_BI_DECODER_CAPS_HDMD_CAP BIT(0) +#define CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ BIT(1) +#define CXL_BI_DECODER_CTRL_OFFSET 0x4 +#define CXL_BI_DECODER_CTRL_BI_FW BIT(0) +#define CXL_BI_DECODER_CTRL_BI_ENABLE BIT(1) +#define CXL_BI_DECODER_CTRL_BI_COMMIT BIT(2) +#define CXL_BI_DECODER_STATUS_OFFSET 0x8 +#define CXL_BI_DECODER_STATUS_BI_COMMITTED BIT(0) +#define CXL_BI_DECODER_STATUS_BI_ERR_NOT_COMMITTED BIT(1) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_SCALE GENMASK(11, 8) +#define CXL_BI_DECODER_STATUS_BI_COMMIT_TM_BASE GENMASK(15, 12) +/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0#define CXLDEV_CAP_ARRAY_CAP_ID 0@@ -565,6 +590,7 @@ struct cxl_dax_region {* @decoder_ida: allocator for decoder ids * @reg_map: component and ras register mapping parameters * @regs: mapped component registers +* @bi_lock: serializes BI Decoder/RT state of this port's dports * @nr_dports: number of entries in @dports * @hdm_end: track last allocated HDM decoder instance for allocation ordering * @commit_end: cursor to track highest committed decoder for commit ordering @@ -587,6 +613,7 @@ struct cxl_port {struct ida decoder_ida;struct cxl_register_map reg_map;struct cxl_component_regs regs; +struct mutex bi_lock;/* dport BI state shared below this port */ int nr_dports;int hdm_end;int commit_end;@@ -650,6 +677,7 @@ struct cxl_rcrb_info {* @coord: access coordinates (bandwidth and latency performance attributes) * @link_latency: calculated PCIe downstream latency * @gpf_dvsec: Cached GPF port DVSEC +* @nr_bi: number of BI-enabled endpoints below this dport */ struct cxl_dport {struct device *dport_dev;@@ -662,6 +690,7 @@ struct cxl_dport {struct access_coordinate coord[ACCESS_COORDINATE_MAX ];long link_latency;int gpf_dvsec; +int nr_bi; };/** @@ -920,6 +949,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, struct access_coordinate *c2);bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +int cxl_bi_setup (struct cxl_port *endpoint); +void cxl_bi_reset_detected (struct cxl_port *endpoint);struct cxl_dport *devm_cxl_add_dport_by_dev (struct cxl_port *port,struct device *dport_dev);drivers/cxl/pci.c +6
-2@@ -987,8 +987,12 @@ static void cxl_reset_done(struct pci_dev *pdev)if (!cxlmd->dev.driver)return ; -if (cxlmd->endpoint && -cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +if (!cxlmd->endpoint) +return ; + +cxl_bi_reset_detected (cxlmd->endpoint); + +if (cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) {device_for_each_child (&cxlmd->endpoint->dev,NULL , cxl_endpoint_decoder_clear_reset_flags);include/cxl/cxl.h +2
-0@@ -168,6 +168,7 @@ struct cxl_dpa_partition {* @regs: Parsed register blocks * @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) +* @bi: device is BI (Back-Invalidate) enabled * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array @@ -187,6 +188,7 @@ struct cxl_dev_state {struct cxl_device_regs regs;int cxl_dvsec;bool rcd; +bool bi;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];Signature · 1 line
2.39.5
Davidlohr Bueso
maintainerRe: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
Quoted 21 lines · Richard Cheng
Quoted 6 lines · Davidlohr Bueso
(quoted diff) +6
-0+/* + * devm teardown on endpoint port destruction. Registered before the + * decoders, so devres runs it after them: regions are detached and + * decoders unregistered by the time BI comes down. + */ +static void cxl_bi_dealloc(void *data)Review
Quoted 10 lines
(quoted diff) +10
-0+{ + struct cxl_port *endpoint = data; + struct cxl_memdev *cxlmd = to_cxl_memdev(endpoint->uport_dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_dport *dport_iter; + struct cxl_port *port_iter; + + cxl_bi_ctrl_endpoint_disable(cxlds); + cxlds->bi = false; +Is it safe to disable BI unconditionally ?
Quoted 8 lines
For a FW-configured HDM-DB region with locked decoders, resetting decoders can leave the HW mapping active. If that memory is boot System RAM, it can remain in use after driver unbind, while the cleanup here disable BI.
I think one of the scenario is when decoders are boot-programmed and locked. FW could configure such a range with BI enabled and expose it
Should we preserve BI when those locked mapping remain active ?
The HDM decoder BI bit is RWL, while the BI Decoder/RT are not locked; which makes this a policy decision, afaict.
So your example scenario makes sense not to disable the endpoint, but the same applies to the dports, essentially making cxl_bi_dealloc() a nop for the locked BI enabled HDM decoder. In terms of BI-ID this seems ok as the device is actually not dissapearing.
Is this something we want? Should the spec pronounce itself in the cases of locked decoders?
Thoughts?
Thanks,
Davidlohr
----8<-----------------------
drivers/cxl/core/core.h +2 -0
@@ -231,4 +231,6 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); +bool cxl_bi_enabled (struct cxl_port *endpoint); +#endif /* __CXL_CORE_H__ */
drivers/cxl/core/pci.c +10 -3
@@ -1355,6 +1355,15 @@ static int cxl_bi_enable_path(struct cxl_dev_state *cxlds,return rc; } +/* the device's BI Enable as the hardware has it right now */ +bool cxl_bi_enabled (struct cxl_port *endpoint) +{ +void __iomem *bi = endpoint->regs.bi_decoder; + +return FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (bi +CXL_BI_DECODER_CTRL_OFFSET )); +} +/* * An SBR wipes the device's BI Enable; an FLR leaves it alone. * The check is against the hardware, not decoder state: BI is
@@ -1366,13 +1375,11 @@ void cxl_bi_reset_detected(struct cxl_port *endpoint) {struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev);struct cxl_dev_state *cxlds = cxlmd->cxlds; -void __iomem *bi = endpoint->regs.bi_decoder;if (!cxlds->bi)return ; -if (FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , -readl (bi +CXL_BI_DECODER_CTRL_OFFSET ))) +if (cxl_bi_enabled (endpoint))return ;dev_warn (cxlds->dev,"BI disabled by reset\n" );
drivers/cxl/core/region.c +17 -0
@@ -361,6 +361,23 @@ static int cxl_region_decode_commit(struct cxl_region *cxlr) } } +/* a reset during the commits: only the device can tell */ +for (i =0 ; i < p->nr_targets; i++) { +struct cxl_endpoint_decoder *cxled = p->targets[i]; +struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); + +if (cxlr->type ==CXL_DECODER_DEVMEM && +cxl_root_decoder_is_bi (cxlr->cxlrd) && + !cxl_bi_enabled (cxled_to_port (cxled))) { +dev_err (&cxlr->dev, +"%s:%s BI disabled by reset during commit\n" , +dev_name (&cxlmd->dev), +dev_name (&cxled->cxld.dev)); +cxl_region_decode_reset (cxlr, p->nr_targets); +return -ENXIO ; + } + } +return 0 ; err:
drivers/cxl/core/hdm.c +18 -0
@@ -822,6 +824,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev);void __iomem *hdm = cxlhdm->regs.hdm_decoder;int id = cxld->id, rc; +u32 ctrl;if (cxld->flags &CXL_DECODER_F_ENABLE )return 0 ;
@@ -865,6 +868,17 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld) port->commit_end++; cxld->flags |=CXL_DECODER_F_ENABLE ; +/* an armed Lock On Commit fires here, not at enumeration */ + ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (id)); +if ((ctrl &CXL_HDM_DECODER0_CTRL_LOCK ) && + (ctrl &CXL_HDM_DECODER0_CTRL_BI ) && +is_endpoint_decoder (&cxld->dev)) { +struct cxl_endpoint_decoder *cxled = +to_cxl_endpoint_decoder (&cxld->dev); + +cxled_to_memdev (cxled)->cxlds->bi_locked = true; + } +return 0 ; }
@@ -1057,6 +1071,12 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, cxld->flags |=CXL_DECODER_F_ENABLE ;if (ctrl &CXL_HDM_DECODER0_CTRL_LOCK ) cxld->flags |=CXL_DECODER_F_LOCK ; + +/* Lock On Commit froze this BI bit set */ +if (cxled && (cxld->flags &CXL_DECODER_F_LOCK ) && + (ctrl &CXL_HDM_DECODER0_CTRL_BI )) +cxled_to_memdev (cxled)->cxlds->bi_locked = true; +if (FIELD_GET (CXL_HDM_DECODER0_CTRL_HOSTONLY , ctrl)) cxld->target_type =CXL_DECODER_HOSTONLYMEM ;else
drivers/cxl/core/pci.c +19 -0
@@ -1305,6 +1305,15 @@ static void cxl_bi_dealloc(void *data)struct cxl_dport *dport_iter;struct cxl_port *port_iter; +/* +* A locked HDM decoder keeps its BI bit set and keeps decoding +* after this driver lets go, and BI Enable is the device-wide +* permission behind it, so neither it nor the levels forwarding +* for it are released. +*/ +if (cxlds->bi_locked) +return ; +cxl_bi_ctrl_endpoint_disable (cxlds); cxlds->bi = false;
@@ -1478,6 +1489,16 @@ int cxl_bi_setup(struct cxl_port *endpoint)if (!cxlds->bi_capable)return 0 ; +/* +* A locked decoder already has this device's BI-ID routed and no +* new BI device is being enabled, so nothing below is owed a +* commit (CXL 4.0 Tables 8-152 and 8-156). +*/ +if (cxlds->bi_locked) { +dev_dbg (cxlds->dev,"BI held by a locked decoder\n" ); +return 0 ; + } + rc =cxl_bi_enable_path (cxlds, dport->port, dport);if (rc)return rc;
include/cxl/cxl.h +2 -0
@@ -171,6 +171,7 @@ struct cxl_dpa_partition {* @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) * @bi: device is BI (Back-Invalidate) enabled * @bi_capable: device and topology path are BI capable +* @bi_locked: a locked HDM decoder has BI set, so BI outlives each binding * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array
@@ -192,6 +193,7 @@ struct cxl_dev_state {bool rcd;bool bi;bool bi_capable; +bool bi_locked;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];
Davidlohr Bueso
maintainerRe: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
Quoted 40 lines · Davidlohr Bueso
Quoted 21 lines · Richard Cheng
Quoted 6 lines · Davidlohr Bueso
(quoted diff) +6
-0+/* + * devm teardown on endpoint port destruction. Registered before the + * decoders, so devres runs it after them: regions are detached and + * decoders unregistered by the time BI comes down. + */ +static void cxl_bi_dealloc(void *data)Review
Quoted 10 lines
(quoted diff) +10
-0+{ + struct cxl_port *endpoint = data; + struct cxl_memdev *cxlmd = to_cxl_memdev(endpoint->uport_dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_dport *dport_iter; + struct cxl_port *port_iter; + + cxl_bi_ctrl_endpoint_disable(cxlds); + cxlds->bi = false; +Is it safe to disable BI unconditionally ?
Quoted 8 lines
For a FW-configured HDM-DB region with locked decoders, resetting decoders can leave the HW mapping active. If that memory is boot System RAM, it can remain in use after driver unbind, while the cleanup here disable BI.
I think one of the scenario is when decoders are boot-programmed and locked. FW could configure such a range with BI enabled and expose it
Should we preserve BI when those locked mapping remain active ?
The HDM decoder BI bit is RWL, while the BI Decoder/RT are not locked; which makes this a policy decision, afaict.
So your example scenario makes sense not to disable the endpoint, but the same applies to the dports, essentially making
cxl_bi_dealloc()a nop for the locked BI enabled HDM decoder. In terms of BI-ID this seems ok as the device is actually not dissapearing.
Quoted 4 lines
Is this something we want? Should the spec pronounce itself in the cases of locked decoders?
Thoughts?
fyi, I have added these BI auto-commit locked semantics to the testing infrastructure:
https://github.com/davidlohr/cxl-bi-tests/blob/main/topos/t24-adopt.sh
(direct+switch topologies: fw-locked and fw-switch-locked)
Thanks,
Davidlohr
Re: [PATCH v9 02/10] cxl/pci: Add BI topology enable/disable
In reply to Davidlohr BuesoQuoted 53 lines · Davidlohr Bueso
Implement
cxl_bi_setup()to enable BI flows on the device and every component in the path, and its teardown counterpartcxl_bi_dealloc(). Setup runs fromdevm_cxl_endpoint_decoders_setup(), between the port's HDM state and its decoders. Registered there, its devres teardown brings BI down after the decoders quiesce and before the HDM state is freed, and BI is settled before the decoders, and later the regions, are looked at. The BI-ID and path enablement belong to the endpoint port's lifetime.Setup is safe in endpoint port probe context. The port probes synchronously from
cxl_mem_probe(), pinning the memdev state the walk consumes, and the whole ancestor path already exists with BI registers mapped (dports at dport-add time, the switch USP RT at first-dport setup) becausedevm_cxl_enumerate_ports()completes before the endpoint is created.Dealloc is safe in endpoint devres context. Both setup and dealloc walk the endpoint's
parent_dporttopology rather than getting the port by bus lookup - an ancestor teardown delists the parent port before the endpoint's devres runs.The topology walk is stable as
parent_dportpointers are fixed at port creation; ancestors cannot be reaped while holding this memdev'scxl_ep; and their own teardown frees dports only after the endpoint is gone.Likewise, the device state outlives the walk -
cxlmd->cxldsis nulled only aftercxl_memdev_unregister()has torn the endpoint down, anddelete_endpoint()clearscxlmd->endpointonly after the endpoint devres has run.Each dport is programmed by its position - the one immediately above the device takes BI Enable, every dport above it takes BI Forward (Table 8-157, Table 9-13), at any switch depth (Table 7-97). Any level can be shared, so
nr_birefcounts endpoints at every dport. Registers are written on the first endpoint and cleared on the last, but only downstream ports commit (Table 8-156), once per endpoint (Table 8-152), and a failed commit undoes its write and commits the undo. A USP advertising a BI Route Table that failed to map is refused rather than treated as absent.nr_bicounts only the endpoints this driver enabled, so a level can be cleared while firmware still has an unbound device on it.A reset may wipe the device's BI Enable, whose reset default is 0 (Table 8-157). .reset_done reads the hardware rather than assume which reset ran, and invalidates
cxlds->bi, failing closed with recovery by rebind as for decoder loss; dealloc unwinds the dport refcounts regardless. It also clearscxlds->biunconditionally - the endpoint disable fails when the hardware already shows BI Enable clear, from a reset .reset_done never saw, and the flag must not outlive the BI Decoder mapping it describes, which the endpoint port releases moments later.
Quoted 4 lines
With dealloc in the endpoint's devres,
delete_endpoint()already holds the parent port's device lock, so to avoid deadlocking, add a per-portbi_lock, serializing the dports that share state (nr_biand the control register at any shared level, the switch USP's BI RT).
Davidlohr Bueso
maintainerPATCH v9 3/10 cxl/hdm: Add BI coherency support for endpoint decoders
In reply to Davidlohr BuesoCache the HDM decoder's Supported Coherency Models on struct cxl_hdm. A later patch has region attach consult it to verify the HDM supports the region's coherency type.
For uncommitted endpoint decoders, init_hdm_decoder() defaults target_type from supported_coherency: Type 3 devices default to HDM-DB when the HDM is device-coherent-only, HDM-H otherwise.
Pre-committed decoders with the BI bit set are refused. cxl_bi_setup() does not yet take over a path firmware already enabled, so nothing verifies that such a decoder's topology can route BISnp.
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/hdm.c | 35 ++++++++++++++++++++++++----------- drivers/cxl/cxl.h | 8 +++++++- drivers/cxl/cxlmem.h | 2 ++ 4 files changed, 34 insertions(+), 12 deletions(-)
drivers/cxl/core/core.h +1 -0
@@ -221,6 +221,7 @@ struct cxl_hdm;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm,struct cxl_endpoint_dvsec_info *info);int cxl_port_get_possible_dports (struct cxl_port *port); +enum cxl_decoder_type cxled_default_type (struct cxl_endpoint_decoder *cxled);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *
drivers/cxl/core/hdm.c +24 -11
@@ -87,6 +87,8 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->iw_cap_mask |=BIT (3 ) |BIT (6 ) |BIT (12 );if (FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , hdm_cap)) cxlhdm->iw_cap_mask |=BIT (16 ); + cxlhdm->supported_coherency = +FIELD_GET (CXL_HDM_DECODER_SUPPORTED_COHERENCY_MASK , hdm_cap); }static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info)
@@ -968,6 +970,19 @@ static int cxl_setup_hdm_decoder_from_dvsec(return 0 ; } +enum cxl_decoder_type cxled_default_type (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds; +struct cxl_port *port =cxled_to_port (cxled); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); + +if (cxlds->type ==CXL_DEVTYPE_CLASSMEM && + cxlhdm->supported_coherency !=CXL_HDM_DECODER_COHERENCY_DEV ) +return CXL_DECODER_HOSTONLYMEM ; + +return CXL_DECODER_DEVMEM ; +} +static int init_hdm_decoder (struct cxl_port *port,struct cxl_decoder *cxld,void __iomem *hdm,int which,u64 *dpa_base,struct cxl_endpoint_dvsec_info *info)
@@ -1023,6 +1038,14 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,else cxld->target_type =CXL_DECODER_DEVMEM ; +/* +* Autocommit BI-enabled decoders is not supported. A path +* firmware enabled is not taken over, so nothing verifies +* it can route BISnp. +*/ +if (FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl)) +return -ENXIO ; +guard (rwsem_write)(&cxl_rwsem.region);if (cxld->id !=cxl_num_decoders_committed (port)) { dev_warn(&port->dev,
@@ -1040,17 +1063,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, port->commit_end = cxld->id; }else {if (cxled) { -struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -struct cxl_dev_state *cxlds = cxlmd->cxlds; - -/* -* Default by devtype until a device arrives that needs -* more precision. -*/ -if (cxlds->type ==CXL_DEVTYPE_CLASSMEM ) - cxld->target_type =CXL_DECODER_HOSTONLYMEM ; -else - cxld->target_type =CXL_DECODER_DEVMEM ; + cxld->target_type =cxled_default_type (cxled); }else {/* To be overridden by region type at commit time */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ;
drivers/cxl/cxl.h +7 -1
@@ -50,7 +50,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_BI_RT_CAPABILITY_LENGTH 0xC#define CXL_BI_DECODER_CAPABILITY_LENGTH 0xC -/* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */ +/* HDM decoders CXL 4.0 8.2.4.20 CXL HDM Decoder Capability Structure */ #define CXL_HDM_DECODER_CAP_OFFSET 0x0#define CXL_HDM_DECODER_COUNT_MASK GENMASK(3, 0)#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)
@@ -58,6 +58,11 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9)#define CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY BIT(11)#define CXL_HDM_DECODER_INTERLEAVE_16_WAY BIT(12) +#define CXL_HDM_DECODER_SUPPORTED_COHERENCY_MASK GENMASK(22, 21) +#define CXL_HDM_DECODER_COHERENCY_UNKNOWN 0x0 +#define CXL_HDM_DECODER_COHERENCY_DEV 0x1 +#define CXL_HDM_DECODER_COHERENCY_HOST 0x2 +#define CXL_HDM_DECODER_COHERENCY_BOTH 0x3#define CXL_HDM_DECODER_CTRL_OFFSET 0x4#define CXL_HDM_DECODER_ENABLE BIT(1)#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10)
@@ -72,6 +77,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_HDM_DECODER0_CTRL_COMMITTED BIT(10)#define CXL_HDM_DECODER0_CTRL_COMMIT_ERROR BIT(11)#define CXL_HDM_DECODER0_CTRL_HOSTONLY BIT(12) +#define CXL_HDM_DECODER0_CTRL_BI BIT(13)#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24)#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)#define CXL_HDM_DECODER0_SKIP_LOW (i) CXL_HDM_DECODER0_TL_LOW(i)
drivers/cxl/cxlmem.h +2 -0
@@ -857,6 +857,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);* @target_count: for switch decoders, max downstream port targets * @interleave_mask: interleave granularity capability, see check_interleave_cap() * @iw_cap_mask: bitmask of supported interleave ways, see check_interleave_cap() +* @supported_coherency: HDM Decoder Capability supported coherency models * @port: mapped cxl_port, see devm_cxl_setup_hdm() */ struct cxl_hdm {
@@ -865,6 +866,7 @@ struct cxl_hdm {unsigned int target_count;unsigned int interleave_mask;unsigned long iw_cap_mask; +unsigned int supported_coherency;struct cxl_port *port; };
Signature · 1 line
2.39.5
Re: [PATCH v9 03/10] cxl/hdm: Add BI coherency support for endpoint decoders
Quoted 8 lines · Davidlohr Bueso
Cache the HDM decoder's Supported Coherency Models on struct
cxl_hdm. A later patch has region attach consult it to verify the HDM supports the region's coherency type.For uncommitted endpoint decoders,
init_hdm_decoder()defaultstarget_typefromsupported_coherency: Type 3 devices default to HDM-DB when the HDM is device-coherent-only, HDM-H otherwise.
Quoted 7 lines
Pre-committed decoders with the BI bit set are refused.
cxl_bi_setup()does not yet take over a path firmware already enabled, so nothing verifies that such a decoder's topology can route BISnp.Reviewed-by Dave Jiang <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 139 lines
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/hdm.c | 35 ++++++++++++++++++++++++----------- drivers/cxl/cxl.h | 8 +++++++- drivers/cxl/cxlmem.h | 2 ++ 4 files changed, 34 insertions(+), 12 deletions(-)drivers/cxl/core/core.h +1
-0@@ -221,6 +221,7 @@ struct cxl_hdm;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm,struct cxl_endpoint_dvsec_info *info);int cxl_port_get_possible_dports (struct cxl_port *port); +enum cxl_decoder_type cxled_default_type (struct cxl_endpoint_decoder *cxled);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *drivers/cxl/core/hdm.c +24
-11@@ -87,6 +87,8 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->iw_cap_mask |=BIT (3 ) |BIT (6 ) |BIT (12 );if (FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , hdm_cap)) cxlhdm->iw_cap_mask |=BIT (16 ); + cxlhdm->supported_coherency = +FIELD_GET (CXL_HDM_DECODER_SUPPORTED_COHERENCY_MASK , hdm_cap); }static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info)@@ -968,6 +970,19 @@ static int cxl_setup_hdm_decoder_from_dvsec(return 0 ; } +enum cxl_decoder_type cxled_default_type (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds; +struct cxl_port *port =cxled_to_port (cxled); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); + +if (cxlds->type ==CXL_DEVTYPE_CLASSMEM && + cxlhdm->supported_coherency !=CXL_HDM_DECODER_COHERENCY_DEV ) +return CXL_DECODER_HOSTONLYMEM ; + +return CXL_DECODER_DEVMEM ; +} +static int init_hdm_decoder (struct cxl_port *port,struct cxl_decoder *cxld,void __iomem *hdm,int which,u64 *dpa_base,struct cxl_endpoint_dvsec_info *info)@@ -1023,6 +1038,14 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,else cxld->target_type =CXL_DECODER_DEVMEM ; +/* +* Autocommit BI-enabled decoders is not supported. A path +* firmware enabled is not taken over, so nothing verifies +* it can route BISnp. +*/ +if (FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl)) +return -ENXIO ; +guard (rwsem_write)(&cxl_rwsem.region);if (cxld->id !=cxl_num_decoders_committed (port)) { dev_warn(&port->dev,@@ -1040,17 +1063,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, port->commit_end = cxld->id; }else {if (cxled) { -struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -struct cxl_dev_state *cxlds = cxlmd->cxlds; - -/* -* Default by devtype until a device arrives that needs -* more precision. -*/ -if (cxlds->type ==CXL_DEVTYPE_CLASSMEM ) - cxld->target_type =CXL_DECODER_HOSTONLYMEM ; -else - cxld->target_type =CXL_DECODER_DEVMEM ; + cxld->target_type =cxled_default_type (cxled); }else {/* To be overridden by region type at commit time */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ;drivers/cxl/cxl.h +7
-1@@ -50,7 +50,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_BI_RT_CAPABILITY_LENGTH 0xC#define CXL_BI_DECODER_CAPABILITY_LENGTH 0xC -/* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */ +/* HDM decoders CXL 4.0 8.2.4.20 CXL HDM Decoder Capability Structure */ #define CXL_HDM_DECODER_CAP_OFFSET 0x0#define CXL_HDM_DECODER_COUNT_MASK GENMASK(3, 0)#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)@@ -58,6 +58,11 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9)#define CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY BIT(11)#define CXL_HDM_DECODER_INTERLEAVE_16_WAY BIT(12) +#define CXL_HDM_DECODER_SUPPORTED_COHERENCY_MASK GENMASK(22, 21) +#define CXL_HDM_DECODER_COHERENCY_UNKNOWN 0x0 +#define CXL_HDM_DECODER_COHERENCY_DEV 0x1 +#define CXL_HDM_DECODER_COHERENCY_HOST 0x2 +#define CXL_HDM_DECODER_COHERENCY_BOTH 0x3#define CXL_HDM_DECODER_CTRL_OFFSET 0x4#define CXL_HDM_DECODER_ENABLE BIT(1)#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10)@@ -72,6 +77,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_HDM_DECODER0_CTRL_COMMITTED BIT(10)#define CXL_HDM_DECODER0_CTRL_COMMIT_ERROR BIT(11)#define CXL_HDM_DECODER0_CTRL_HOSTONLY BIT(12) +#define CXL_HDM_DECODER0_CTRL_BI BIT(13)#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24)#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)#define CXL_HDM_DECODER0_SKIP_LOW (i) CXL_HDM_DECODER0_TL_LOW(i)drivers/cxl/cxlmem.h +2
-0@@ -857,6 +857,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);* @target_count: for switch decoders, max downstream port targets * @interleave_mask: interleave granularity capability, see check_interleave_cap() * @iw_cap_mask: bitmask of supported interleave ways, see check_interleave_cap() +* @supported_coherency: HDM Decoder Capability supported coherency models * @port: mapped cxl_port, see devm_cxl_setup_hdm() */ struct cxl_hdm {@@ -865,6 +866,7 @@ struct cxl_hdm {unsigned int target_count;unsigned int interleave_mask;unsigned long iw_cap_mask; +unsigned int supported_coherency;struct cxl_port *port; };
Re: [PATCH v9 03/10] cxl/hdm: Add BI coherency support for endpoint decoders
In reply to Davidlohr BuesoQuoted 11 lines · Davidlohr Bueso
Cache the HDM decoder's Supported Coherency Models on struct
cxl_hdm. A later patch has region attach consult it to verify the HDM supports the region's coherency type.For uncommitted endpoint decoders,
init_hdm_decoder()defaultstarget_typefromsupported_coherency: Type 3 devices default to HDM-DB when the HDM is device-coherent-only, HDM-H otherwise.Pre-committed decoders with the BI bit set are refused.
cxl_bi_setup()does not yet take over a path firmware already enabled, so nothing verifies that such a decoder's topology can route BISnp.
Davidlohr Bueso
maintainerPATCH v9 4/10 cxl: Add HDM-DB region creation
In reply to Davidlohr BuesoA region inherits its coherency from the chosen root decoder - HDM-DB if the root has CXL_DECODER_F_BI, otherwise HDM-H.
cxl_acpi_cfmws_verify() rejects a Window that declares no coherency model at all (neither Device Coherent nor Host-only Coherent), one that sets BI together with Host-only Coherent, which the CFMWS definition calls undefined behavior, and one that sets BI without Device Coherent, since HDM-DB is defined only as bit[0] and bit[5] together. A BI Window therefore always exposes device-coherent memory and nothing else. The root decoder's target_type follows the Window as well - device-coherent when only Device Coherent is set, host-only otherwise.
Introduce the following read-only sysfs ABI.
- decoderX.Y/cap_back_invalidate (root) reports the CFMWS BI restriction.
- decoderX.Y/back_invalidate (endpoint) reads '1' when configured for HDM-DB.
cxl_region_attach() rejects endpoints whose device or HDM cannot serve the region's type; target_type is inherited from cxlr->type in cxl_rr_assign_decoder(), restored to the endpoint default on detach, and to whatever it was on a failed attach - a refusal may come before any inheritance, for a decoder another region owns or one firmware committed, and must not relabel it.
An HDM that reports Unknown coherency support is not rejected. Supported Coherency Models is how a device declares whether Target Range Type is writable - Host-only+Device Coherent means RW, a single model means the bit may be hardwired to it, Unknown declares neither
- so refusing Unknown would also exclude devices that support both models without saying so.
A Type 3 decoder defaults to host-only, unless its HDM supports only device-coherent, and inherits device-coherent when it joins an HDM-DB region, which requires cxlds->bi. A Type 2 decoder defaults to device-coherent and an HDM-H region refuses it outright, since the spec reserves HDM-H for Type 3 devices. An HDM-D region is only assembled from a committed decoder, taking that decoder's type, so no inheritance is involved.
The HDM Decoder Control BI bit is set at commit time for a device-coherent decoder in a region under a BI root, endpoint and switch decoders alike. Whether the device has BI enabled (cxlds->bi) is checked when an endpoint attaches and again for every target before a commit programs anything, since a reset in between invalidates it; the refusal is the same in both places.
--- Documentation/ABI/testing/sysfs-bus-cxl | 22 ++++++ drivers/cxl/acpi.c | 27 +++++++ drivers/cxl/core/hdm.c | 19 +++++ drivers/cxl/core/port.c | 39 +++++++++- drivers/cxl/core/region.c | 99 +++++++++++++++++++++---- drivers/cxl/cxl.h | 7 ++ include/cxl/cxl.h | 3 +- 7 files changed, 197 insertions(+), 19 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +22 -0
@@ -432,6 +432,28 @@ Description: current cached value. +What: /sys/bus/cxl/devices/decoderX.Y/cap_back_invalidate +Date: September, 2026 +KernelVersion: v7.4 +Contact: [email protected] +Description: + (RO) When a CXL decoder is of devtype "cxl_decoder_root", '1' + indicates the fixed memory window carries the CFMWS + Back-Invalidate restriction, so HDM-DB memory may be mapped + behind it. + + +What: /sys/bus/cxl/devices/decoderX.Y/back_invalidate +Date: September, 2026 +KernelVersion: v7.4 +Contact: [email protected] +Description: + (RO) Shows '1' if this endpoint decoder is currently configured + for HDM-DB (device-managed coherency with back-invalidate). + The HDM-DB state is inherited from the region the decoder is + attached to, which is in turn set from the chosen root + decoder's CFMWS BI restriction (see cap_back_invalidate). + What: /sys/bus/cxl/devices/decoderX.Y/delete_region Date: May, 2022 KernelVersion: v6.0
drivers/cxl/acpi.c +27 -0
@@ -152,6 +152,8 @@ static unsigned long cfmws_to_decoder_flags(int restrictions) flags |=CXL_DECODER_F_PMEM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_FIXED ) flags |=CXL_DECODER_F_LOCK ; +if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) + flags |=CXL_DECODER_F_BI ;return flags; }
@@ -198,6 +200,24 @@ static int cxl_acpi_cfmws_verify(struct device *dev,dev_dbg (dev,"CFMWS length %d greater than expected %d\n" , cfmws->header.length, expected_len); +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) && + (cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI )) { +dev_err (dev,"CFMWS cannot have both HDM-H and HDM-DB\n" ); +return -EINVAL ; + } + +if (!(cfmws->restrictions & (ACPI_CEDT_CFMWS_RESTRICT_DEVMEM | +ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ))) { +dev_err (dev,"CFMWS has no coherency model\n" ); +return -EINVAL ; + } + +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) && + !(cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM )) { +dev_err (dev,"CFMWS BI requires device-coherent\n" ); +return -EINVAL ; + } +return 0 ; }
@@ -437,7 +457,14 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, cxld = &cxlrd->cxlsd.cxld; cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions); +/* host-only wins if firmware sets both coherency restrictions */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ; +if (cxld->flags &CXL_DECODER_F_TYPE2 ) { +if (cxld->flags &CXL_DECODER_F_TYPE3 ) +dev_dbg (dev,"CFMWS has both HDM-H and HDM-D\n" ); +else + cxld->target_type =CXL_DECODER_DEVMEM ; + } cxld->hpa_range = (struct range ) { .start = cfmws->base_hpa, .end = cfmws->base_hpa + cfmws->window_size -1 ,
drivers/cxl/core/hdm.c +19 -0
@@ -705,9 +705,21 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)static void cxld_set_type (struct cxl_decoder *cxld,u32 *ctrl) { +bool bi = cxld->target_type ==CXL_DECODER_DEVMEM && + cxld->region &&cxl_root_decoder_is_bi (cxld->region->cxlrd); +u32p_replace_bits (ctrl, !!(cxld->target_type ==CXL_DECODER_HOSTONLYMEM ),CXL_HDM_DECODER0_CTRL_HOSTONLY ); +u32p_replace_bits (ctrl, bi,CXL_HDM_DECODER0_CTRL_BI ); + +if (bi &&is_endpoint_decoder (&cxld->dev)) { +struct cxl_endpoint_decoder *cxled = +to_cxl_endpoint_decoder (&cxld->dev); + +u32p_replace_bits (ctrl, cxled->pos, +CXL_HDM_DECODER0_CTRL_ISP_MASK ); + } }static void cxlsd_set_targets (struct cxl_switch_decoder *cxlsd,u64 *tgt)
@@ -970,6 +982,13 @@ static int cxl_setup_hdm_decoder_from_dvsec(return 0 ; } +/* +* HDMs that advertise support for both coherency modes +* (CXL_HDM_DECODER_COHERENCY_BOTH) default to host-only; the region +* attach path switches target_type to device-coherent if the region's +* root decoder has the CFMWS BI bit set. Only HDMs that strictly +* support device-coherent mode default to HDM-DB. +*/ enum cxl_decoder_type cxled_default_type (struct cxl_endpoint_decoder *cxled) {struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds;
drivers/cxl/core/port.c +35 -4
@@ -132,6 +132,7 @@ CXL_DECODER_FLAG_ATTR(cap_ram, CXL_DECODER_F_RAM);CXL_DECODER_FLAG_ATTR (cap_type2,CXL_DECODER_F_TYPE2 );CXL_DECODER_FLAG_ATTR (cap_type3,CXL_DECODER_F_TYPE3 );CXL_DECODER_FLAG_ATTR (locked,CXL_DECODER_F_LOCK ); +CXL_DECODER_FLAG_ATTR (cap_back_invalidate,CXL_DECODER_F_BI );static ssize_t target_type_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -234,6 +235,26 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RW (mode); +static ssize_t back_invalidate_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct cxl_endpoint_decoder *cxled =to_cxl_endpoint_decoder (dev); +struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds; +struct cxl_region *cxlr; + +guard (rwsem_read)(&cxl_rwsem.region); +/* +* An endpoint decoder is HDM-DB when the device has BI enabled +* (cxlds->bi) and it is attached to a device-coherent (DEVMEM) +* region whose root decoder advertises the CFMWS BI restriction. +*/ + cxlr = cxled->cxld.region; +return sysfs_emit (buf,"%d\n" , cxlds->bi && cxlr && + cxled->cxld.target_type ==CXL_DECODER_DEVMEM && +cxl_root_decoder_is_bi (cxlr->cxlrd)); +} +static DEVICE_ATTR_RO (back_invalidate); +static ssize_t dpa_resource_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -330,6 +351,7 @@ static struct attribute *cxl_decoder_root_attrs[] = { &dev_attr_cap_ram.attr, &dev_attr_cap_type2.attr, &dev_attr_cap_type3.attr, + &dev_attr_cap_back_invalidate.attr, &dev_attr_target_list.attr, &dev_attr_qos_class.attr,SET_CXL_REGION_ATTR (create_pmem_region)
@@ -340,16 +362,24 @@ static struct attribute *cxl_decoder_root_attrs[] = {static bool can_create_pmem (struct cxl_root_decoder *cxlrd) { -unsigned long flags =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_PMEM ; +unsigned long flags = cxlrd->cxlsd.cxld.flags; +unsigned long hdm_h, hdm_db; -return (cxlrd->cxlsd.cxld.flags & flags) == flags; + hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_PMEM ; + hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_PMEM ; + +return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }static bool can_create_ram (struct cxl_root_decoder *cxlrd) { -unsigned long flags =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_RAM ; +unsigned long flags = cxlrd->cxlsd.cxld.flags; +unsigned long hdm_h, hdm_db; + + hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_RAM ; + hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_RAM ; -return (cxlrd->cxlsd.cxld.flags & flags) == flags; +return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }static umode_t cxl_root_decoder_visible (struct kobject *kobj,struct attribute *a,int n)
@@ -403,6 +433,7 @@ static const struct attribute_group *cxl_decoder_switch_attribute_groups[] = {static struct attribute *cxl_decoder_endpoint_attrs[] = { &dev_attr_target_type.attr, &dev_attr_mode.attr, + &dev_attr_back_invalidate.attr, &dev_attr_dpa_size.attr, &dev_attr_dpa_resource.attr,SET_CXL_REGION_ATTR (region)
drivers/cxl/core/region.c +85 -14
162 lines not on this page · raw message
drivers/cxl/cxl.h +7 -0
@@ -78,6 +78,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_HDM_DECODER0_CTRL_COMMIT_ERROR BIT(11)#define CXL_HDM_DECODER0_CTRL_HOSTONLY BIT(12)#define CXL_HDM_DECODER0_CTRL_BI BIT(13) +#define CXL_HDM_DECODER0_CTRL_ISP_MASK GENMASK(27, 24)#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24)#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)#define CXL_HDM_DECODER0_SKIP_LOW (i) CXL_HDM_DECODER0_TL_LOW(i)
@@ -300,6 +301,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6) +#define CXL_DECODER_F_BI BIT(7)#define CXL_DECODER_F_RESET_MASK (CXL_DECODER_F_ENABLE | CXL_DECODER_F_LOCK)enum cxl_decoder_type {
@@ -829,6 +831,11 @@ static inline int cxl_root_decoder_autoremove(struct device *host, {return cxl_decoder_autoremove (host, &cxlrd->cxlsd.cxld); } + +static inline bool cxl_root_decoder_is_bi (struct cxl_root_decoder *cxlrd) +{ +return cxlrd->cxlsd.cxld.flags &CXL_DECODER_F_BI ; +}int cxl_endpoint_autoremove (struct cxl_memdev *cxlmd,struct cxl_port *endpoint);/**
include/cxl/cxl.h +2 -1
@@ -16,7 +16,8 @@* mailbox, or other memory-device-standard manageability * flows. * @CXL_DEVTYPE_CLASSMEM: Common class definition of a CXL Type-3 device with -* HDM-H and class-mandatory memory device registers +* HDM-H or HDM-DB, and class-mandatory memory device +* registers */ enum cxl_devtype {CXL_DEVTYPE_DEVMEM ,
Signature · 1 line
2.39.5
Alison Schofield
maintainerRe: [PATCH v9 04/10] cxl: Add HDM-DB region creation
Quoted 2 lines · Davidlohr Bueso
A region inherits its coherency from the chosen root decoder - HDM-DB if the root has
CXL_DECODER_F_BI, otherwise HDM-H.
Above holds for regions created from sysfs. An auto region takes its type from the first committed endpoint decoder in construct_region(), without looking at the root decoder. A committed host-only decoder in a BI window becomes an HDM-H region under a BI root, and an HDM-D region is neither HDM-DB nor HDM-H. Can this say which regions it applies to?
Quoted 7 lines
cxl_acpi_cfmws_verify()rejects a Window that declares no coherency model at all (neither Device Coherent nor Host-only Coherent), one that sets BI together with Host-only Coherent, which the CFMWS definition calls undefined behavior, and one that sets BI without Device Coherent, since HDM-DB is defined only as bit[0] and bit[5] together. A BI Window therefore always exposes device-coherent memory and nothing else.
These rejections drop windows that are accepted and usable today. See the cxl_acpi_cfmws_verify() comment inline below.
Quoted 2 lines
The root decoder's
target_typefollows the Window as well - device-coherent when only Device Coherent is set, host-only otherwise.
I'll comment inline on this one too, acpi.c hunk below. I think this describes dead code and opportunity for cleanup.
Quoted 8 lines
Introduce the following read-only sysfs ABI.
- decoderX.Y/cap_back_invalidate (root) reports the CFMWS BI restriction.
- decoderX.Y/back_invalidate (endpoint) reads '1' when configured for HDM-DB.
Quoted 6 lines
cxl_region_attach()rejects endpoints whose device or HDM cannot serve the region's type;target_typeis inherited fromcxlr->typeincxl_rr_assign_decoder(), restored to the endpoint default on detach, and to whatever it was on a failed attach - a refusal may come before any inheritance, for a decoder another region owns or one firmware committed, and must not relabel it.
A decoder firmware committed is still relabelled when its attach succeeds, since the type mismatch check is gone. More inline at cxl_region_attach()
snip
Quoted 41 lines
Documentation/ABI/testing/sysfs-bus-cxl +13
-0+ + +What: /sys/bus/cxl/devices/decoderX.Y/back_invalidate +Date: September, 2026 +KernelVersion: v7.4 +Contact: [email protected] +Description: + (RO) Shows '1' if this endpoint decoder is currently configured + for HDM-DB (device-managed coherency with back-invalidate). + The HDM-DB state is inherited from the region the decoder is + attached to, which is in turn set from the chosen root + decoder's CFMWS BI restriction (see cap_back_invalidate). + What: /sys/bus/cxl/devices/decoderX.Y/delete_region Date: May, 2022 KernelVersion: v6.0drivers/cxl/acpi.c +10
-0@@ -152,6 +152,8 @@ static unsigned long cfmws_to_decoder_flags(int restrictions) flags |=CXL_DECODER_F_PMEM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_FIXED ) flags |=CXL_DECODER_F_LOCK ; +if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) + flags |=CXL_DECODER_F_BI ;return flags; }@@ -198,6 +200,24 @@ static int cxl_acpi_cfmws_verify(struct device *dev,dev_dbg (dev,"CFMWS length %d greater than expected %d\n" , cfmws->header.length, expected_len); +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) && + (cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI )) { +dev_err (dev,"CFMWS cannot have both HDM-H and HDM-DB\n" ); +return -EINVAL ; + } + +if (!(cfmws->restrictions & (ACPI_CEDT_CFMWS_RESTRICT_DEVMEM | +ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ))) {
drivers/cxl/acpi.c static int cxl_acpi_cfmws_verify(struct device *dev, · line 220
Quoted 10 lines
drivers/cxl/acpi.c +10
-0+dev_err (dev,"CFMWS has no coherency model\n" ); +return -EINVAL ; + } + +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) && + !(cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM )) { +dev_err (dev,"CFMWS BI requires device-coherent\n" ); +return -EINVAL ; + } +
Can these checks break windows that are accepted and usable today? A rejected window gets no root decoder, and auto-assembly then fails with "no CXL window for range".
A window that sets neither coherency bit is accepted today and can hold auto regions, since assembly never looks at the restriction flags.
A window that sets BI together with Host-only, or BI without Device Coherent, is accepted today as a non-BI window, because BI is ignored. Manual HDM-H region creation in it is lost as well.
Even if no shipping firmware does this, is cxl_acpi_cfmws_verify() the right place for these checks? Til now it has only rejected windows that cannot be decoded (arithmetic, alignment, ways, length). What a window may be used for is decided later, by cfmws_to_decoder_flags() and can_create_ram|pmem(). Might it be enough to withhold CXL_DECODER_F_BI for an invalid combination, so that only HDM-DB is refused?
Quoted 5 lines
drivers/cxl/acpi.c +0
-0return 0 ; }@@ -437,7 +457,14 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,
drivers/cxl/acpi.c static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, · line 467
Quoted 10 lines
drivers/cxl/acpi.c +7
-0cxld = &cxlrd->cxlsd.cxld; cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions); +/* host-only wins if firmware sets both coherency restrictions */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ; +if (cxld->flags &CXL_DECODER_F_TYPE2 ) { +if (cxld->flags &CXL_DECODER_F_TYPE3 ) +dev_dbg (dev,"CFMWS has both HDM-H and HDM-D\n" ); +else + cxld->target_type =CXL_DECODER_DEVMEM ; + }
Mentioned in commit msg, I think this is dead code needing cleanup. I don't see a consumer of a root decoder's target_type.
Building window-derived logic and a dev_dbg() on top of it makes it look as if the root decoder's type matters when it doesn't. Can this hunk be dropped? Removing the old line can be a separate cleanup.
Quoted 16 lines
drivers/cxl/acpi.c +0
-0cxld->hpa_range = (struct range ) { .start = cfmws->base_hpa, .end = cfmws->base_hpa + cfmws->window_size -1 ,drivers/cxl/core/hdm.c +3
-0@@ -705,9 +705,21 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)static void cxld_set_type (struct cxl_decoder *cxld,u32 *ctrl) { +bool bi = cxld->target_type ==CXL_DECODER_DEVMEM && + cxld->region &&cxl_root_decoder_is_bi (cxld->region->cxlrd); + u32p_replace_bits(ctrl, !!(cxld->target_type == CXL_DECODER_HOSTONLYMEM),
drivers/cxl/core/hdm.c static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) · line 722
Quoted 10 lines
drivers/cxl/core/hdm.c +9
-0CXL_HDM_DECODER0_CTRL_HOSTONLY); +u32p_replace_bits (ctrl, bi,CXL_HDM_DECODER0_CTRL_BI ); + +if (bi &&is_endpoint_decoder (&cxld->dev)) { +struct cxl_endpoint_decoder *cxled = +to_cxl_endpoint_decoder (&cxld->dev); + +u32p_replace_bits (ctrl, cxled->pos, +CXL_HDM_DECODER0_CTRL_ISP_MASK ); + }
The commit message does not mention ISP programming. Can it get a sentence with the spec reference for ISP being required when BI is set?
snip
Quoted 1 line
drivers/cxl/core/region.c +0
-0
snip
Quoted 9 lines
drivers/cxl/core/region.c +2
-3@@ -1131,16 +1163,11 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, }/* -* Endpoints should already match the region type, but backstop that -* assumption with an assertion. Switch-decoders change mapping-type -* based on what is mapped when they are assigned to a region. +* Endpoint decoders inherit their type from cxlr->type; broken +* pairings were already rejected by the coherency checks in
drivers/cxl/core/region.c static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, · line 1171
Quoted 10 lines
drivers/cxl/core/region.c +2
-6+* cxl_region_attach(). Switch-decoders change mapping-type based +* on what is mapped when they are assigned to a region. */ -dev_WARN_ONCE (&cxlr->dev, - port ==cxled_to_port (cxled) && - cxld->target_type != cxlr->type, -"%s:%s mismatch decoder type %d -> %d\n" , -dev_name (&cxled_to_memdev (cxled)->dev), -dev_name (&cxld->dev), cxld->target_type, cxlr->type); cxld->target_type = cxlr->type;
A Type 3 endpoint decoder in an HDM-DB region now reads "accelerator" from decoderX.Y/target_type, and the ndctl test on the branch linked in the cover letter checks for that. So I take it target_type is now being used to report the decoder's coherency model, device-coherent vs host-only, rather than the Type-2/Type-3 as documented by the existing ABI.
Does this need sysfs ABI update?
cxl list doesn't show target_type, but libcxl exports it through cxl_decoder_get_target_type(). If that is intentional, libcxl.txt will need the same semantic update with the ndctl patches.
Quoted 28 lines
drivers/cxl/core/region.c +4
-0cxl_rr->decoder = cxld;return 0 ;@@ -1803,6 +1830,7 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,struct cxl_root_decoder *cxlrd = cxlr->cxlrd;struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_switch_decoder *cxlsd = &cxlrd->cxlsd; +enum cxl_decoder_type type = cxled->cxld.target_type;struct cxl_decoder *cxld = &cxlsd->cxld;int iw = cxld->interleave_ways;struct cxl_port *iter;@@ -1828,6 +1856,8 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,for (iter =cxled_to_port (cxled); !is_cxl_root (iter); iter =to_cxl_port (iter->dev.parent))cxl_port_detach_region (iter, cxlr, cxled); +/* undo cxl_rr_assign_decoder() type inheritance */ + cxled->cxld.target_type = type;return rc; }@@ -2056,6 +2086,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_region_params *p = &cxlr->params;struct cxl_port *ep_port, *root_port;struct cxl_dport *dport; +struct cxl_hdm *cxlhdm;int rc = -ENXIO ; rc = check_interleave_cap(&cxled->cxld, p->interleave_ways,
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2111
Quoted 7 lines
drivers/cxl/core/region.c +0
-4@@ -2105,10 +2136,39 @@ static int cxl_region_attach(struct cxl_region *cxlr,return -ENXIO ; } -if (cxled->cxld.target_type != cxlr->type) { -dev_dbg (&cxlr->dev,"%s:%s type mismatch: %d vs %d\n" , -dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev), - cxled->cxld.target_type, cxlr->type);
Should the type check stay for committed decoders? With it gone, a second auto-assembled decoder whose committed Target Range Type differs from the region's is accepted, and cxl_rr_assign_decoder() then overwrites its target_type while the hardware keeps the committed value. I think this changes in Patch 8 - which really makes patch 8 required, not optional. (more on that in patch 8)
Maybe the CXL_DECODER_STATE_AUTO mismatch check fits better in here, since this patch that removes the old one?
Quoted 25 lines
drivers/cxl/core/region.c +25
-0+/* +* Verify the device and HDM are capable of the region's flavor before +* proceeding. The endpoint decoder's target_type is then inherited +* from cxlr->type later in cxl_rr_assign_decoder(). +*/ +if (cxlr->type ==CXL_DECODER_DEVMEM && +cxl_root_decoder_is_bi (cxlrd) && !cxlds->bi) { +dev_err (&cxlr->dev,"%s:%s BI not enabled on device\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } + +if (cxled->state !=CXL_DECODER_STATE_AUTO && + cxlr->type ==CXL_DECODER_HOSTONLYMEM && + cxlds->type ==CXL_DEVTYPE_DEVMEM ) { +dev_warn (&cxlr->dev,"%s:%s HDM-H requires a Type 3 device\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } + + cxlhdm =dev_get_drvdata (&ep_port->dev); +if (!cxlhdm) +return -ENXIO ; +if (cxlr->type ==CXL_DECODER_HOSTONLYMEM && + cxlhdm->supported_coherency ==CXL_HDM_DECODER_COHERENCY_DEV ) {
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2173
Quoted 10 lines
drivers/cxl/core/region.c +8
-0+dev_warn (&cxlr->dev,"%s:%s HDM is device-coherent only\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } +if (cxlr->type ==CXL_DECODER_DEVMEM && + cxlhdm->supported_coherency ==CXL_HDM_DECODER_COHERENCY_HOST ) { +dev_warn (&cxlr->dev,"%s:%s HDM is host-only coherent\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev));return -ENXIO ; }
Why dev_err()/dev_warn() here? The type mismatch refusal this replaces was a dev_dbg(). The attach fail here would be reported as -ENXIO.
Tidy up opportunity, maybe move the 4 coherency checks into a helper so cxl_region_attach() stays cleaner.
Another cleanup - the 'is this reion HDM-DB test is now coded in a few places, my look may have been limited:
cxld_set_type(): target_type == DEVMEM && cxl_root_decoder_is_bi() back_invalidate_show(): same, plus cxlds->bi cxl_region_decode_commit(): cxlr->type == DEVMEM && cxl_root_decoder_is_bi() cxl_region_attach(): same
Maybe a single cxl_region_is_hdm_db() would be clearer and cleaner.
snip to end
Davidlohr Bueso
maintainerRe: [PATCH v9 04/10] cxl: Add HDM-DB region creation
Quoted 9 lines · Alison Schofield
Quoted 2 lines · Davidlohr Bueso
A region inherits its coherency from the chosen root decoder - HDM-DB if the root has
CXL_DECODER_F_BI, otherwise HDM-H.Above holds for regions created from sysfs. An auto region takes its type from the first committed endpoint decoder in
construct_region(), without looking at the root decoder. A committed host-only decoder in a BI window becomes an HDM-H region under a BI root, and an HDM-D region is neither HDM-DB nor HDM-H. Can this say which regions it applies to?
Right, that only describes regions created through sysfs. An auto-assembled region still takes its type from the committed decoder it is built from, so under a BI root a committed host-only decoder gives an HDM-H region and an HDM-D region is neither, as you say. Nothing here consults the Window for a committed decoder; that starts with patch 8, which also removes the refusal of committed BI decoders at enumeration, so auto HDM-DB regions do not exist before it.
I'll scope the sentence to sysfs regions.
Quoted 95 lines
Quoted 8 lines
cxl_acpi_cfmws_verify()rejects a Window that declares no coherency model at all (neither Device Coherent nor Host-only Coherent), one that sets BI together with Host-only Coherent, which the CFMWS definition calls undefined behavior, and one that sets BI without Device Coherent, since HDM-DB is defined only as bit[0] and bit[5] together. A BI Window therefore always exposes device-coherent memory and nothing else.These rejections drop windows that are accepted and usable today. See the
cxl_acpi_cfmws_verify()comment inline below.Quoted 2 lines
The root decoder's
target_typefollows the Window as well - device-coherent when only Device Coherent is set, host-only otherwise.I'll comment inline on this one too,
acpi.chunk below. I think this describes dead code and opportunity for cleanup.Quoted 8 lines
Introduce the following read-only sysfs ABI.
- decoderX.Y/cap_back_invalidate (root) reports the CFMWS BI restriction.
- decoderX.Y/back_invalidate (endpoint) reads '1' when configured for HDM-DB.Quoted 6 lines
cxl_region_attach()rejects endpoints whose device or HDM cannot serve the region's type;target_typeis inherited fromcxlr->typeincxl_rr_assign_decoder(), restored to the endpoint default on detach, and to whatever it was on a failed attach - a refusal may come before any inheritance, for a decoder another region owns or one firmware committed, and must not relabel it.A decoder firmware committed is still relabelled when its attach succeeds, since the type mismatch check is gone. More inline at
cxl_region_attach()snip
Quoted 41 lines
Documentation/ABI/testing/sysfs-bus-cxl +13
-0+ + +What: /sys/bus/cxl/devices/decoderX.Y/back_invalidate +Date: September, 2026 +KernelVersion: v7.4 +Contact: [email protected] +Description: + (RO) Shows '1' if this endpoint decoder is currently configured + for HDM-DB (device-managed coherency with back-invalidate). + The HDM-DB state is inherited from the region the decoder is + attached to, which is in turn set from the chosen root + decoder's CFMWS BI restriction (see cap_back_invalidate). + What: /sys/bus/cxl/devices/decoderX.Y/delete_region Date: May, 2022 KernelVersion: v6.0drivers/cxl/acpi.c +10
-0@@ -152,6 +152,8 @@ static unsigned long cfmws_to_decoder_flags(int restrictions) flags |=CXL_DECODER_F_PMEM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_FIXED ) flags |=CXL_DECODER_F_LOCK ; +if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) + flags |=CXL_DECODER_F_BI ;return flags; }@@ -198,6 +200,24 @@ static int cxl_acpi_cfmws_verify(struct device *dev,dev_dbg (dev,"CFMWS length %d greater than expected %d\n" , cfmws->header.length, expected_len); +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) && + (cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI )) { +dev_err (dev,"CFMWS cannot have both HDM-H and HDM-DB\n" ); +return -EINVAL ; + } + +if (!(cfmws->restrictions & (ACPI_CEDT_CFMWS_RESTRICT_DEVMEM | +ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ))) {drivers/cxl/acpi.c static int cxl_acpi_cfmws_verify(struct device *dev, · line 220
Quoted 10 lines
drivers/cxl/acpi.c +10
-0+dev_err (dev,"CFMWS has no coherency model\n" ); +return -EINVAL ; + } + +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) && + !(cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM )) { +dev_err (dev,"CFMWS BI requires device-coherent\n" ); +return -EINVAL ; + } +Can these checks break windows that are accepted and usable today? A rejected window gets no root decoder, and auto-assembly then fails with "no CXL window for range".
Quoted 2 lines
A window that sets neither coherency bit is accepted today and can hold auto regions, since assembly never looks at the restriction flags.
I could remove the check for no ACPI_CEDT_CFMWS_RESTRICT_DEVMEM/HOSTONLYMEM, but would rather break bogus firmware.
Quoted 4 lines
A window that sets BI together with Host-only, or BI without Device Coherent, is accepted today as a non-BI window, because BI is ignored. Manual HDM-H region creation in it is lost as well.
We cannot accept UB scenarios, I think these should be rejected regardless.
Quoted 7 lines
Even if no shipping firmware does this, is
cxl_acpi_cfmws_verify()the right place for these checks? Til now it has only rejected windows that cannot be decoded (arithmetic, alignment, ways, length). What a window may be used for is decided later, bycfmws_to_decoder_flags()and can_create_ram|pmem(). Might it be enough to withholdCXL_DECODER_F_BIfor an invalid combination, so that only HDM-DB is refused?
Yes, I think this is the right place for these checks, aligned with its name cxl_acpi_cfmws_verify(). These are minimum sanity checks, just as you point out with those that cannot be decoded.
I will leave these checks as is.
Quoted 22 lines
Quoted 7 lines
drivers/cxl/acpi.c +0
-0return 0 ; }@@ -437,7 +457,14 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,drivers/cxl/acpi.c static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, · line 467
Quoted 10 lines
drivers/cxl/acpi.c +7
-0cxld = &cxlrd->cxlsd.cxld; cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions); +/* host-only wins if firmware sets both coherency restrictions */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ; +if (cxld->flags &CXL_DECODER_F_TYPE2 ) { +if (cxld->flags &CXL_DECODER_F_TYPE3 ) +dev_dbg (dev,"CFMWS has both HDM-H and HDM-D\n" ); +else + cxld->target_type =CXL_DECODER_DEVMEM ; + }Mentioned in commit msg, I think this is dead code needing cleanup. I don't see a consumer of a root decoder's
target_type.
Quoted 3 lines
Building window-derived logic and a
dev_dbg()on top of it makes it look as if the root decoder's type matters when it doesn't. Can this hunk be dropped? Removing the old line can be a separate cleanup.
Agreed. I justified this because we already had the old line doing the host-only assignment, but this can be removed.
Quoted 24 lines
Quoted 24 lines
drivers/cxl/acpi.c +0
-0cxld->hpa_range = (struct range ) { .start = cfmws->base_hpa, .end = cfmws->base_hpa + cfmws->window_size -1 ,drivers/cxl/core/hdm.c +8
-0@@ -705,9 +705,21 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)static void cxld_set_type (struct cxl_decoder *cxld,u32 *ctrl) { +bool bi = cxld->target_type ==CXL_DECODER_DEVMEM && + cxld->region &&cxl_root_decoder_is_bi (cxld->region->cxlrd); +u32p_replace_bits (ctrl, !!(cxld->target_type ==CXL_DECODER_HOSTONLYMEM ),CXL_HDM_DECODER0_CTRL_HOSTONLY ); +u32p_replace_bits (ctrl, bi,CXL_HDM_DECODER0_CTRL_BI ); + +if (bi &&is_endpoint_decoder (&cxld->dev)) { +struct cxl_endpoint_decoder *cxled = +to_cxl_endpoint_decoder (&cxld->dev);
Quoted 8 lines
drivers/cxl/core/hdm.c static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) · line 722
Quoted 4 lines
drivers/cxl/core/hdm.c +4
-0+ +u32p_replace_bits (ctrl, cxled->pos, +CXL_HDM_DECODER0_CTRL_ISP_MASK ); + }The commit message does not mention ISP programming. Can it get a sentence with the spec reference for ISP being required when BI is set?
It's per Table 8-123, will add a comment.
Quoted 25 lines
snip
Quoted 1 line
drivers/cxl/core/region.c +0
-0snip
Quoted 18 lines
drivers/cxl/core/region.c +4
-9@@ -1131,16 +1163,11 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, }/* -* Endpoints should already match the region type, but backstop that -* assumption with an assertion. Switch-decoders change mapping-type -* based on what is mapped when they are assigned to a region. +* Endpoint decoders inherit their type from cxlr->type; broken +* pairings were already rejected by the coherency checks in +* cxl_region_attach(). Switch-decoders change mapping-type based +* on what is mapped when they are assigned to a region. */ -dev_WARN_ONCE (&cxlr->dev, - port ==cxled_to_port (cxled) && - cxld->target_type != cxlr->type, -"%s:%s mismatch decoder type %d -> %d\n" , -dev_name (&cxled_to_memdev (cxled)->dev), -dev_name (&cxld->dev), cxld->target_type, cxlr->type);
Quoted 8 lines
drivers/cxl/core/region.c static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, · line 1171
Quoted 1 line
drivers/cxl/core/region.c +0
-0cxld->target_type = cxlr->type;A Type 3 endpoint decoder in an HDM-DB region now reads "accelerator" from decoderX.Y/target_type, and the ndctl test on the branch linked in the cover letter checks for that. So I take it
target_typeis now being used to report the decoder's coherency model, device-coherent vs host-only, rather than the Type-2/Type-3 as documented by the existing ABI.
Type2 and Type3 are names from the old pre-BI CXL (and were later renamed by the spec, per patch 5), but the intent behind was always about coherency type.
Quoted 2 lines
Does this need sysfs ABI update?
I don't think so, the doc already mentions:
""
The 'target_type' attribute indicates the current setting which may dynamically change based on what memory regions are activated in this decode hierarchy.
""
Quoted 37 lines
cxl list doesn't show
target_type, but libcxl exports it throughcxl_decoder_get_target_type(). If that is intentional, libcxl.txt will need the same semantic update with the ndctl patches.Quoted 31 lines
drivers/cxl/core/region.c +4
-0cxl_rr->decoder = cxld;return 0 ;@@ -1803,6 +1830,7 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,struct cxl_root_decoder *cxlrd = cxlr->cxlrd;struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_switch_decoder *cxlsd = &cxlrd->cxlsd; +enum cxl_decoder_type type = cxled->cxld.target_type;struct cxl_decoder *cxld = &cxlsd->cxld;int iw = cxld->interleave_ways;struct cxl_port *iter;@@ -1828,6 +1856,8 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,for (iter =cxled_to_port (cxled); !is_cxl_root (iter); iter =to_cxl_port (iter->dev.parent))cxl_port_detach_region (iter, cxlr, cxled); +/* undo cxl_rr_assign_decoder() type inheritance */ + cxled->cxld.target_type = type;return rc; }@@ -2056,6 +2086,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_region_params *p = &cxlr->params;struct cxl_port *ep_port, *root_port;struct cxl_dport *dport; +struct cxl_hdm *cxlhdm;int rc = -ENXIO ; rc = check_interleave_cap(&cxled->cxld, p->interleave_ways,@@ -2105,10 +2136,39 @@ static int cxl_region_attach(struct cxl_region *cxlr,return -ENXIO ; }
Quoted 12 lines
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2111
Quoted 4 lines
drivers/cxl/core/region.c +0
-4-if (cxled->cxld.target_type != cxlr->type) { -dev_dbg (&cxlr->dev,"%s:%s type mismatch: %d vs %d\n" , -dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev), - cxled->cxld.target_type, cxlr->type);Should the type check stay for committed decoders? With it gone, a second auto-assembled decoder whose committed Target Range Type differs from the region's is accepted, and
cxl_rr_assign_decoder()then overwrites itstarget_typewhile the hardware keeps the committed value. I think this changes in Patch 8 - which really makes patch 8 required, not optional. (more on that in patch 8)
Yeah I see what you mean, I will move that logic from cxl_region_attach() in patch 8 in here.
Quoted 2 lines
Maybe the
CXL_DECODER_STATE_AUTOmismatch check fits better in here, since this patch that removes the old one?
Agreed.
Quoted 33 lines
Quoted 33 lines
drivers/cxl/core/region.c +31
-0+/* +* Verify the device and HDM are capable of the region's flavor before +* proceeding. The endpoint decoder's target_type is then inherited +* from cxlr->type later in cxl_rr_assign_decoder(). +*/ +if (cxlr->type ==CXL_DECODER_DEVMEM && +cxl_root_decoder_is_bi (cxlrd) && !cxlds->bi) { +dev_err (&cxlr->dev,"%s:%s BI not enabled on device\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } + +if (cxled->state !=CXL_DECODER_STATE_AUTO && + cxlr->type ==CXL_DECODER_HOSTONLYMEM && + cxlds->type ==CXL_DEVTYPE_DEVMEM ) { +dev_warn (&cxlr->dev,"%s:%s HDM-H requires a Type 3 device\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } + + cxlhdm =dev_get_drvdata (&ep_port->dev); +if (!cxlhdm) +return -ENXIO ; +if (cxlr->type ==CXL_DECODER_HOSTONLYMEM && + cxlhdm->supported_coherency ==CXL_HDM_DECODER_COHERENCY_DEV ) { +dev_warn (&cxlr->dev,"%s:%s HDM is device-coherent only\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return -ENXIO ; + } +if (cxlr->type ==CXL_DECODER_DEVMEM && + cxlhdm->supported_coherency ==CXL_HDM_DECODER_COHERENCY_HOST ) {
Quoted 8 lines
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2173
Quoted 4 lines
drivers/cxl/core/region.c +2
-0+dev_warn (&cxlr->dev,"%s:%s HDM is host-only coherent\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev));return -ENXIO ; }Why dev_err()/dev_warn() here? The type mismatch refusal this replaces was a
dev_dbg(). The attach fail here would be reported as-ENXIO.
Ok, will change to dev_dbg().
Quoted 3 lines
Tidy up opportunity, maybe move the 4 coherency checks into a helper so
cxl_region_attach()stays cleaner.
Ok
Quoted 9 lines
Another cleanup - the 'is this reion HDM-DB test is now coded in a few places, my look may have been limited:
cxld_set_type(): target_type == DEVMEM && cxl_root_decoder_is_bi() back_invalidate_show(): same, plus cxlds->bi cxl_region_decode_commit(): cxlr->type == DEVMEM && cxl_root_decoder_is_bi() cxl_region_attach(): sameMaybe a single
cxl_region_is_hdm_db()would be clearer and cleaner.
Ok, makes sense.
Thanks,
Davidlohr
Alison Schofield
maintainerRe: [PATCH v9 04/10] cxl: Add HDM-DB region creation
Quoted 2 lines · Davidlohr Bueso
On Wed, 30 Sep 2026, Alison Schofield wrote:
I'm OK w responses on this, with exception of what really is a new concern about qemu version compatibility -
snip
Quoted 49 lines
Quoted 28 lines
Quoted 12 lines
drivers/cxl/acpi.c +8
-0@@ -198,6 +200,24 @@ static int cxl_acpi_cfmws_verify(struct device *dev,dev_dbg (dev,"CFMWS length %d greater than expected %d\n" , cfmws->header.length, expected_len); +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) && + (cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI )) { +dev_err (dev,"CFMWS cannot have both HDM-H and HDM-DB\n" ); +return -EINVAL ; + } + +if (!(cfmws->restrictions & (ACPI_CEDT_CFMWS_RESTRICT_DEVMEM | +ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ))) {drivers/cxl/acpi.c static int cxl_acpi_cfmws_verify(struct device *dev, · line 220
Quoted 10 lines
drivers/cxl/acpi.c +10
-0+dev_err (dev,"CFMWS has no coherency model\n" ); +return -EINVAL ; + } + +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) && + !(cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM )) { +dev_err (dev,"CFMWS BI requires device-coherent\n" ); +return -EINVAL ; + } +Can these checks break windows that are accepted and usable today? A rejected window gets no root decoder, and auto-assembly then fails with "no CXL window for range".
Quoted 2 lines
A window that sets neither coherency bit is accepted today and can hold auto regions, since assembly never looks at the restriction flags.
I could remove the check for no ACPI_CEDT_CFMWS_RESTRICT_DEVMEM/HOSTONLYMEM, but would rather break bogus firmware.
Quoted 4 lines
A window that sets BI together with Host-only, or BI without Device Coherent, is accepted today as a non-BI window, because BI is ignored. Manual HDM-H region creation in it is lost as well.
We cannot accept UB scenarios, I think these should be rejected regardless.
Quoted 7 lines
Even if no shipping firmware does this, is
cxl_acpi_cfmws_verify()the right place for these checks? Til now it has only rejected windows that cannot be decoded (arithmetic, alignment, ways, length). What a window may be used for is decided later, bycfmws_to_decoder_flags()and can_create_ram|pmem(). Might it be enough to withholdCXL_DECODER_F_BIfor an invalid combination, so that only HDM-DB is refused?
Quoted 5 lines
Yes, I think this is the right place for these checks, aligned with its name
cxl_acpi_cfmws_verify(). These are minimum sanity checks, just as you point out with those that cannot be decoded.I will leave these checks as is.
Hi Davidlohr,
This patch makes the currently released QEMU unusable for CXL. With released QEMU versions from v11.0 onward, the CXL windows are rejected with:
cxl_acpi ACPI0017:00: CFMWS cannot have both HDM-H and HDM-DB
That comes from the first of the three new checks added above.
Git history tells me this started w Jonathan's patch, in v11:e6742e71c24c "Update CXL Fixed Memory Window ACPI description to include Back Invalidate support"
And goes away when your commit sitting on qemu/master releases:cb52f088f221
"hw/cxl: Add configurable CXL Fixed Memory Window restriction flags"
Was there already a thought on how to handle that compatibility issue? I can certainly test this series against QEMU master or Jonathan's working branch, but it seems problematic for this patch to make the currently released QEMU unusable for CXL.
Could we instead avoid failing the entire window for the Host-only + BI combination?
-- Alison
Davidlohr Bueso
maintainerRe: [PATCH v9 04/10] cxl: Add HDM-DB region creation
Quoted 73 lines · Alison Schofield
Quoted 2 lines · Davidlohr Bueso
On Wed, 30 Sep 2026, Alison Schofield wrote:
I'm OK w responses on this, with exception of what really is a new concern about qemu version compatibility -
snip
Quoted 49 lines
Quoted 28 lines
Quoted 12 lines
drivers/cxl/acpi.c +8
-0@@ -198,6 +200,24 @@ static int cxl_acpi_cfmws_verify(struct device *dev,dev_dbg (dev,"CFMWS length %d greater than expected %d\n" , cfmws->header.length, expected_len); +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) && + (cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI )) { +dev_err (dev,"CFMWS cannot have both HDM-H and HDM-DB\n" ); +return -EINVAL ; + } + +if (!(cfmws->restrictions & (ACPI_CEDT_CFMWS_RESTRICT_DEVMEM | +ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ))) {drivers/cxl/acpi.c static int cxl_acpi_cfmws_verify(struct device *dev, · line 220
Quoted 10 lines
drivers/cxl/acpi.c +10
-0+dev_err (dev,"CFMWS has no coherency model\n" ); +return -EINVAL ; + } + +if ((cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_BI ) && + !(cfmws->restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM )) { +dev_err (dev,"CFMWS BI requires device-coherent\n" ); +return -EINVAL ; + } +Can these checks break windows that are accepted and usable today? A rejected window gets no root decoder, and auto-assembly then fails with "no CXL window for range".
Quoted 2 lines
A window that sets neither coherency bit is accepted today and can hold auto regions, since assembly never looks at the restriction flags.
I could remove the check for no ACPI_CEDT_CFMWS_RESTRICT_DEVMEM/HOSTONLYMEM, but would rather break bogus firmware.
Quoted 4 lines
A window that sets BI together with Host-only, or BI without Device Coherent, is accepted today as a non-BI window, because BI is ignored. Manual HDM-H region creation in it is lost as well.
We cannot accept UB scenarios, I think these should be rejected regardless.
Quoted 7 lines
Even if no shipping firmware does this, is
cxl_acpi_cfmws_verify()the right place for these checks? Til now it has only rejected windows that cannot be decoded (arithmetic, alignment, ways, length). What a window may be used for is decided later, bycfmws_to_decoder_flags()and can_create_ram|pmem(). Might it be enough to withholdCXL_DECODER_F_BIfor an invalid combination, so that only HDM-DB is refused?Quoted 5 lines
Yes, I think this is the right place for these checks, aligned with its name
cxl_acpi_cfmws_verify(). These are minimum sanity checks, just as you point out with those that cannot be decoded.I will leave these checks as is.
Hi Davidlohr,
This patch makes the currently released QEMU unusable for CXL. With released QEMU versions from v11.0 onward, the CXL windows are rejected with:
cxl_acpiACPI0017:00: CFMWS cannot have both HDM-H and HDM-DB
That comes from the first of the three new checks added above.
Quoted 7 lines
Git history tells me this started w Jonathan's patch, in v11:
e6742e71c24c"Update CXL Fixed Memory Window ACPI description to include Back Invalidate support"And goes away when your commit sitting on qemu/master releases:
cb52f088f221
"hw/cxl: Add configurable CXL Fixed Memory Window restriction flags"
Yeah this was an unfortunately situation, thank you for taking the time to run into it and raising this (I'm normally the only person running this stuff :)
Quoted 8 lines
Was there already a thought on how to handle that compatibility issue? I can certainly test this series against QEMU master or Jonathan's working branch, but it seems problematic for this patch to make the currently released QEMU unusable for CXL.
Could we instead avoid failing the entire window for the Host-only + BI combination?
I really think the kernel should do the right thing and forbid UB, regardless of qemu (users that care enough can just upgrade). One thing we could do is drop it temporarily and add the check a few kernel versions later (which would give distros some time to catch up with the new knobs and mitigate some of the exposure).
Jonathan?
Thanks,
Davidlohr
Davidlohr Bueso
maintainerRe: [PATCH v9 04/10] cxl: Add HDM-DB region creation
In reply to Davidlohr Buesodrivers/cxl/core/hdm.c static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) · line 714
Quoted 9 lines · Davidlohr Bueso
static void
cxld_set_type(struct cxl_decoder *cxld, u32 *ctrl){drivers/cxl/core/hdm.c +3
-0+bool bi = cxld->target_type ==CXL_DECODER_DEVMEM && + cxld->region &&cxl_root_decoder_is_bi (cxld->region->cxlrd); +u32p_replace_bits(ctrl, !!(cxld->target_type == CXL_DECODER_HOSTONLYMEM), CXL_HDM_DECODER0_CTRL_HOSTONLY);drivers/cxl/core/hdm.c +1
-0+u32p_replace_bits (ctrl, bi,CXL_HDM_DECODER0_CTRL_BI );
For the record, this should be conditional:
+ /* BI is reserved unless the component is BI capable */
+ if (bi || FIELD_GET(CXL_HDM_DECODER0_CTRL_BI, *ctrl))
+ u32p_replace_bits(ctrl, bi, CXL_HDM_DECODER0_CTRL_BI);
Quoted 9 lines
drivers/cxl/core/hdm.c +8
-0+ +if (bi &&is_endpoint_decoder (&cxld->dev)) { +struct cxl_endpoint_decoder *cxled = +to_cxl_endpoint_decoder (&cxld->dev); + +u32p_replace_bits (ctrl, cxled->pos, +CXL_HDM_DECODER0_CTRL_ISP_MASK ); + }}
Davidlohr Bueso
maintainerPATCH v9 5/10 cxl/hdm: Rename decoder coherency flags
In reply to Davidlohr BuesoAlign with the ACPI CXL Window restriction naming and convert CXL_DECODER_F_TYPE2/F_TYPE3 to F_DEVMEM/F_HOSTONLY. Type2 and Type3 coherency models were named prior to Back-Invalidate.
--- drivers/cxl/acpi.c | 8 ++++---- drivers/cxl/core/port.c | 12 ++++++------ drivers/cxl/cxl.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)
drivers/cxl/acpi.c +4 -4
@@ -143,9 +143,9 @@ static unsigned long cfmws_to_decoder_flags(int restrictions)unsigned long flags =CXL_DECODER_F_ENABLE ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM ) - flags |=CXL_DECODER_F_TYPE2 ; + flags |=CXL_DECODER_F_DEVMEM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) - flags |=CXL_DECODER_F_TYPE3 ; + flags |=CXL_DECODER_F_HOSTONLY ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_VOLATILE ) flags |=CXL_DECODER_F_RAM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_PMEM )
@@ -459,8 +459,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions);/* host-only wins if firmware sets both coherency restrictions */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ; -if (cxld->flags &CXL_DECODER_F_TYPE2 ) { -if (cxld->flags &CXL_DECODER_F_TYPE3 ) +if (cxld->flags &CXL_DECODER_F_DEVMEM ) { +if (cxld->flags &CXL_DECODER_F_HOSTONLY )dev_dbg (dev,"CFMWS has both HDM-H and HDM-D\n" );else cxld->target_type =CXL_DECODER_DEVMEM ;
drivers/cxl/core/port.c +6 -6
@@ -129,8 +129,8 @@ static DEVICE_ATTR_RO(name)CXL_DECODER_FLAG_ATTR (cap_pmem,CXL_DECODER_F_PMEM );CXL_DECODER_FLAG_ATTR (cap_ram,CXL_DECODER_F_RAM ); -CXL_DECODER_FLAG_ATTR (cap_type2,CXL_DECODER_F_TYPE2 ); -CXL_DECODER_FLAG_ATTR (cap_type3,CXL_DECODER_F_TYPE3 ); +CXL_DECODER_FLAG_ATTR (cap_type2,CXL_DECODER_F_DEVMEM ); +CXL_DECODER_FLAG_ATTR (cap_type3,CXL_DECODER_F_HOSTONLY );CXL_DECODER_FLAG_ATTR (locked,CXL_DECODER_F_LOCK );CXL_DECODER_FLAG_ATTR (cap_back_invalidate,CXL_DECODER_F_BI );
@@ -365,8 +365,8 @@ static bool can_create_pmem(struct cxl_root_decoder *cxlrd)unsigned long flags = cxlrd->cxlsd.cxld.flags;unsigned long hdm_h, hdm_db; - hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_PMEM ; - hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_PMEM ; + hdm_h =CXL_DECODER_F_HOSTONLY |CXL_DECODER_F_PMEM ; + hdm_db =CXL_DECODER_F_DEVMEM |CXL_DECODER_F_BI |CXL_DECODER_F_PMEM ;return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }
@@ -376,8 +376,8 @@ static bool can_create_ram(struct cxl_root_decoder *cxlrd)unsigned long flags = cxlrd->cxlsd.cxld.flags;unsigned long hdm_h, hdm_db; - hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_RAM ; - hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_RAM ; + hdm_h =CXL_DECODER_F_HOSTONLY |CXL_DECODER_F_RAM ; + hdm_db =CXL_DECODER_F_DEVMEM |CXL_DECODER_F_BI |CXL_DECODER_F_RAM ;return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }
drivers/cxl/cxl.h +2 -2
@@ -296,8 +296,8 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);*/ #define CXL_DECODER_F_RAM BIT(0)#define CXL_DECODER_F_PMEM BIT(1) -#define CXL_DECODER_F_TYPE2 BIT(2) -#define CXL_DECODER_F_TYPE3 BIT(3) +#define CXL_DECODER_F_DEVMEM BIT(2) +#define CXL_DECODER_F_HOSTONLY BIT(3)#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6)
Signature · 1 line
2.39.5
Re: [PATCH v9 05/10] cxl/hdm: Rename decoder coherency flags
Quoted 9 lines · Davidlohr Bueso
Align with the ACPI CXL Window restriction naming and convert CXL_DECODER_F_TYPE2/F_TYPE3 to F_DEVMEM/F_HOSTONLY. Type2 and Type3 coherency models were named prior to Back-Invalidate.
Reviewed-by Ben Cheatham <[email protected]>Reviewed-by Dave Jiang <[email protected]>Reviewed-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 85 lines
--- drivers/cxl/acpi.c | 8 ++++---- drivers/cxl/core/port.c | 12 ++++++------ drivers/cxl/cxl.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)drivers/cxl/acpi.c +4
-4@@ -143,9 +143,9 @@ static unsigned long cfmws_to_decoder_flags(int restrictions)unsigned long flags =CXL_DECODER_F_ENABLE ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_DEVMEM ) - flags |=CXL_DECODER_F_TYPE2 ; + flags |=CXL_DECODER_F_DEVMEM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM ) - flags |=CXL_DECODER_F_TYPE3 ; + flags |=CXL_DECODER_F_HOSTONLY ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_VOLATILE ) flags |=CXL_DECODER_F_RAM ;if (restrictions &ACPI_CEDT_CFMWS_RESTRICT_PMEM )@@ -459,8 +459,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions);/* host-only wins if firmware sets both coherency restrictions */ cxld->target_type =CXL_DECODER_HOSTONLYMEM ; -if (cxld->flags &CXL_DECODER_F_TYPE2 ) { -if (cxld->flags &CXL_DECODER_F_TYPE3 ) +if (cxld->flags &CXL_DECODER_F_DEVMEM ) { +if (cxld->flags &CXL_DECODER_F_HOSTONLY )dev_dbg (dev,"CFMWS has both HDM-H and HDM-D\n" );else cxld->target_type =CXL_DECODER_DEVMEM ;drivers/cxl/core/port.c +6
-6@@ -129,8 +129,8 @@ static DEVICE_ATTR_RO(name)CXL_DECODER_FLAG_ATTR (cap_pmem,CXL_DECODER_F_PMEM );CXL_DECODER_FLAG_ATTR (cap_ram,CXL_DECODER_F_RAM ); -CXL_DECODER_FLAG_ATTR (cap_type2,CXL_DECODER_F_TYPE2 ); -CXL_DECODER_FLAG_ATTR (cap_type3,CXL_DECODER_F_TYPE3 ); +CXL_DECODER_FLAG_ATTR (cap_type2,CXL_DECODER_F_DEVMEM ); +CXL_DECODER_FLAG_ATTR (cap_type3,CXL_DECODER_F_HOSTONLY );CXL_DECODER_FLAG_ATTR (locked,CXL_DECODER_F_LOCK );CXL_DECODER_FLAG_ATTR (cap_back_invalidate,CXL_DECODER_F_BI );@@ -365,8 +365,8 @@ static bool can_create_pmem(struct cxl_root_decoder *cxlrd)unsigned long flags = cxlrd->cxlsd.cxld.flags;unsigned long hdm_h, hdm_db; - hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_PMEM ; - hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_PMEM ; + hdm_h =CXL_DECODER_F_HOSTONLY |CXL_DECODER_F_PMEM ; + hdm_db =CXL_DECODER_F_DEVMEM |CXL_DECODER_F_BI |CXL_DECODER_F_PMEM ;return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }@@ -376,8 +376,8 @@ static bool can_create_ram(struct cxl_root_decoder *cxlrd)unsigned long flags = cxlrd->cxlsd.cxld.flags;unsigned long hdm_h, hdm_db; - hdm_h =CXL_DECODER_F_TYPE3 |CXL_DECODER_F_RAM ; - hdm_db =CXL_DECODER_F_TYPE2 |CXL_DECODER_F_BI |CXL_DECODER_F_RAM ; + hdm_h =CXL_DECODER_F_HOSTONLY |CXL_DECODER_F_RAM ; + hdm_db =CXL_DECODER_F_DEVMEM |CXL_DECODER_F_BI |CXL_DECODER_F_RAM ;return (flags & hdm_h) == hdm_h || (flags & hdm_db) == hdm_db; }drivers/cxl/cxl.h +2
-2@@ -296,8 +296,8 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);*/ #define CXL_DECODER_F_RAM BIT(0)#define CXL_DECODER_F_PMEM BIT(1) -#define CXL_DECODER_F_TYPE2 BIT(2) -#define CXL_DECODER_F_TYPE3 BIT(3) +#define CXL_DECODER_F_DEVMEM BIT(2) +#define CXL_DECODER_F_HOSTONLY BIT(3)#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6)
Davidlohr Bueso
maintainerPATCH v9 6/10 cxl/region: Log the coherency model at region creation
In reply to Davidlohr BuesoRegion assembly emits plenty of debug information - resources, interleave geometry, target placement - but not the coherency model the region operates in.
--- drivers/cxl/core/region.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +11 -2
@@ -1861,6 +1861,13 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,return rc; } +static const char *cxl_coherency_name (enum cxl_decoder_type type,bool bi) +{ +if (type ==CXL_DECODER_HOSTONLYMEM ) +return "HDM-H" ; +return bi ?"HDM-DB" :"HDM-D" ; +} +static int cxl_region_attach_auto (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {
@@ -2823,8 +2830,10 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,return ERR_PTR (rc); } -dev_dbg (port->uport_dev,"%s: created %s\n" , -dev_name (&cxlrd->cxlsd.cxld.dev),dev_name (dev)); +dev_dbg (port->uport_dev,"%s: created %s %s\n" , +dev_name (&cxlrd->cxlsd.cxld.dev), +cxl_coherency_name (cxlr->type,cxl_root_decoder_is_bi (cxlrd)), +dev_name (dev));return cxlr; err:put_device (dev);
Signature · 1 line
2.39.5
Re: [PATCH v9 06/10] cxl/region: Log the coherency model at region creation
Quoted 7 lines · Davidlohr Bueso
Region assembly emits plenty of debug information - resources, interleave geometry, target placement - but not the coherency model the region operates in.
Reviewed-by Dave Jiang <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 35 lines
--- drivers/cxl/core/region.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/cxl/core/region.c +11
-2@@ -1861,6 +1861,13 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,return rc; } +static const char *cxl_coherency_name (enum cxl_decoder_type type,bool bi) +{ +if (type ==CXL_DECODER_HOSTONLYMEM ) +return "HDM-H" ; +return bi ?"HDM-DB" :"HDM-D" ; +} +static int cxl_region_attach_auto (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {@@ -2823,8 +2830,10 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,return ERR_PTR (rc); } -dev_dbg (port->uport_dev,"%s: created %s\n" , -dev_name (&cxlrd->cxlsd.cxld.dev),dev_name (dev)); +dev_dbg (port->uport_dev,"%s: created %s %s\n" , +dev_name (&cxlrd->cxlsd.cxld.dev), +cxl_coherency_name (cxlr->type,cxl_root_decoder_is_bi (cxlrd)), +dev_name (dev));return cxlr; err:put_device (dev);
Re: [PATCH v9 06/10] cxl/region: Log the coherency model at region creation
In reply to Davidlohr BuesoQuoted 3 lines · Davidlohr Bueso
Region assembly emits plenty of debug information - resources, interleave geometry, target placement - but not the coherency model the region operates in.
Davidlohr Bueso
maintainerPATCH v9 7/10 cxl/pci: Split BI capability probe from setup
In reply to Davidlohr BuesoDecouple the topology read-only capability verification phase from cxl_bi_setup() into cxl_bi_probe_capable(), recording the result in cxlds->bi_capable.
This allows further dealing with auto-committed BI hdm decoders; having such knowledge upon decoder enumeration time.
No functional change intended.
--- drivers/cxl/core/pci.c | 40 +++++++++++++++++++++++++++++----------- drivers/cxl/cxl.h | 1 + drivers/cxl/port.c | 1 + include/cxl/cxl.h | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)
drivers/cxl/core/pci.c +29 -11
@@ -1332,34 +1332,38 @@ void cxl_bi_reset_detected(struct cxl_port *endpoint) }EXPORT_SYMBOL_NS_GPL (cxl_bi_reset_detected,"CXL" ); -int cxl_bi_setup (struct cxl_port *endpoint) +/* +* Verify the device and every component in the path up to the root +* are BI capable. +*/ +void cxl_bi_probe_capable (struct cxl_port *endpoint) {struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev);struct cxl_dev_state *cxlds = cxlmd->cxlds; -struct cxl_dport *dport = endpoint->parent_dport;struct cxl_dport *dport_iter;struct cxl_port *port_iter; -int rc; + + cxlds->bi_capable = false;if (!dev_is_pci (cxlds->dev)) -return 0 ; +return ;/* BI is VH-only */ if (cxlds->rcd) -return 0 ; +return ;if (!cxl_is_bi_capable (to_pci_dev (cxlds->dev), endpoint->regs.bi_decoder)) -return 0 ; +return ; - port_iter = dport->port; - dport_iter = dport; + dport_iter = endpoint->parent_dport; + port_iter = dport_iter->port;while (!is_cxl_root (port_iter)) {/* check rp, dsp */ if (!cxl_is_bi_capable (to_pci_dev (dport_iter->dport_dev), dport_iter->regs.bi_decoder)) {dev_dbg (cxlds->dev,"BI not supported by topology\n" ); -return 0 ; +return ; }/* check usp */
@@ -1370,13 +1374,13 @@ int cxl_bi_setup(struct cxl_port *endpoint) NULL)) {dev_dbg (cxlds->dev,"BI not supported by USP\n" ); -return 0 ; +return ; }if (port_iter->reg_map.component_map.bi_rt.valid && !port_iter->regs.bi_rt) {dev_dbg (cxlds->dev,"BI RT advertised but unmapped\n" ); -return 0 ; +return ; } }
@@ -1384,6 +1388,20 @@ int cxl_bi_setup(struct cxl_port *endpoint) port_iter = dport_iter->port; } + cxlds->bi_capable = true; +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_probe_capable,"CXL" ); + +int cxl_bi_setup (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dport *dport = endpoint->parent_dport; +struct cxl_dev_state *cxlds = cxlmd->cxlds; +int rc; + +if (!cxlds->bi_capable) +return 0 ; + rc =cxl_bi_enable_path (cxlds, dport->port, dport);if (rc)return rc;
drivers/cxl/cxl.h +1 -0
@@ -962,6 +962,7 @@ void cxl_coordinates_combine(struct access_coordinate *out, struct access_coordinate *c2);bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +void cxl_bi_probe_capable (struct cxl_port *endpoint);int cxl_bi_setup (struct cxl_port *endpoint);void cxl_bi_reset_detected (struct cxl_port *endpoint); struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
drivers/cxl/port.c +1 -0
@@ -170,6 +170,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)cxl_endpoint_parse_cdat (port);devm_cxl_port_bi_setup (port); +cxl_bi_probe_capable (port);get_device (&cxlmd->dev); rc =devm_add_action_or_reset (&port->dev, schedule_detach, cxlmd);
include/cxl/cxl.h +2 -0
@@ -170,6 +170,7 @@ struct cxl_dpa_partition {* @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) * @bi: device is BI (Back-Invalidate) enabled +* @bi_capable: device and topology path are BI capable * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array
@@ -190,6 +191,7 @@ struct cxl_dev_state {int cxl_dvsec;bool rcd;bool bi; +bool bi_capable;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];
Signature · 1 line
2.39.5
Re: [PATCH v9 07/10] cxl/pci: Split BI capability probe from setup
Quoted 4 lines · Davidlohr Bueso
Decouple the topology read-only capability verification phase from
cxl_bi_setup()intocxl_bi_probe_capable(), recording the result incxlds->bi_capable.
Quoted 8 lines
This allows further dealing with auto-committed BI hdm decoders; having such knowledge upon decoder enumeration time.
No functional change intended.
Reviewed-by Dave Jiang <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 140 lines
--- drivers/cxl/core/pci.c | 40 +++++++++++++++++++++++++++++----------- drivers/cxl/cxl.h | 1 + drivers/cxl/port.c | 1 + include/cxl/cxl.h | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-)drivers/cxl/core/pci.c +29
-11@@ -1332,34 +1332,38 @@ void cxl_bi_reset_detected(struct cxl_port *endpoint) }EXPORT_SYMBOL_NS_GPL (cxl_bi_reset_detected,"CXL" ); -int cxl_bi_setup (struct cxl_port *endpoint) +/* +* Verify the device and every component in the path up to the root +* are BI capable. +*/ +void cxl_bi_probe_capable (struct cxl_port *endpoint) {struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev);struct cxl_dev_state *cxlds = cxlmd->cxlds; -struct cxl_dport *dport = endpoint->parent_dport;struct cxl_dport *dport_iter;struct cxl_port *port_iter; -int rc; + + cxlds->bi_capable = false;if (!dev_is_pci (cxlds->dev)) -return 0 ; +return ;/* BI is VH-only */ if (cxlds->rcd) -return 0 ; +return ;if (!cxl_is_bi_capable (to_pci_dev (cxlds->dev), endpoint->regs.bi_decoder)) -return 0 ; +return ; - port_iter = dport->port; - dport_iter = dport; + dport_iter = endpoint->parent_dport; + port_iter = dport_iter->port;while (!is_cxl_root (port_iter)) {/* check rp, dsp */ if (!cxl_is_bi_capable (to_pci_dev (dport_iter->dport_dev), dport_iter->regs.bi_decoder)) {dev_dbg (cxlds->dev,"BI not supported by topology\n" ); -return 0 ; +return ; }/* check usp */ @@ -1370,13 +1374,13 @@ int cxl_bi_setup(struct cxl_port *endpoint) NULL)) {dev_dbg (cxlds->dev,"BI not supported by USP\n" ); -return 0 ; +return ; }if (port_iter->reg_map.component_map.bi_rt.valid && !port_iter->regs.bi_rt) {dev_dbg (cxlds->dev,"BI RT advertised but unmapped\n" ); -return 0 ; +return ; } }@@ -1384,6 +1388,20 @@ int cxl_bi_setup(struct cxl_port *endpoint) port_iter = dport_iter->port; } + cxlds->bi_capable = true; +} +EXPORT_SYMBOL_NS_GPL (cxl_bi_probe_capable,"CXL" ); + +int cxl_bi_setup (struct cxl_port *endpoint) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (endpoint->uport_dev); +struct cxl_dport *dport = endpoint->parent_dport; +struct cxl_dev_state *cxlds = cxlmd->cxlds; +int rc; + +if (!cxlds->bi_capable) +return 0 ; + rc =cxl_bi_enable_path (cxlds, dport->port, dport);if (rc)return rc;drivers/cxl/cxl.h +1
-0@@ -962,6 +962,7 @@ void cxl_coordinates_combine(struct access_coordinate *out, struct access_coordinate *c2);bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +void cxl_bi_probe_capable (struct cxl_port *endpoint);int cxl_bi_setup (struct cxl_port *endpoint);void cxl_bi_reset_detected (struct cxl_port *endpoint); struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,drivers/cxl/port.c +1
-0@@ -170,6 +170,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)cxl_endpoint_parse_cdat (port);devm_cxl_port_bi_setup (port); +cxl_bi_probe_capable (port);get_device (&cxlmd->dev); rc =devm_add_action_or_reset (&port->dev, schedule_detach, cxlmd);include/cxl/cxl.h +2
-0@@ -170,6 +170,7 @@ struct cxl_dpa_partition {* @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) * @bi: device is BI (Back-Invalidate) enabled +* @bi_capable: device and topology path are BI capable * @media_ready: Indicate whether the device media is usable * @dpa_res: Overall DPA resource tree for the device * @part: DPA partition array @@ -190,6 +191,7 @@ struct cxl_dev_state {int cxl_dvsec;bool rcd;bool bi; +bool bi_capable;bool media_ready;struct resource dpa_res;struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX ];
Re: [PATCH v9 07/10] cxl/pci: Split BI capability probe from setup
In reply to Davidlohr BuesoQuoted 8 lines · Davidlohr Bueso
Decouple the topology read-only capability verification phase from
cxl_bi_setup()intocxl_bi_probe_capable(), recording the result incxlds->bi_capable.This allows further dealing with auto-committed BI hdm decoders; having such knowledge upon decoder enumeration time.
No functional change intended.
Davidlohr Bueso
maintainerPATCH v9 8/10 cxl: Allow auto-committed BI hdm decoders
In reply to Davidlohr BuesoAn HDM decoder that firmware committed with the BI bit set was refused outright. Accept it, and refuse only what is broken - BI paired with a host-only target range type, or for an endpoint decoder BI on a path that cannot route BISnp.
Taking over such a path must not re-program what firmware already did, and a dport's committed state does not say which device it was committed for, only that firmware committed for something below it. Two endpoints sharing a level show why that is not enough to go on.
RP Forward set, but for mem0
|
USP
/ \
DSP0 DSP1
| |
mem0 mem1
BI Enable BI Enable
set clear
Adoption is therefore seeded from the endpoint's own BI Enable, since only a device firmware itself enabled can have had its BI-ID accounted for above, and carried up the walk. A level is taken as found, with no register write and no commit, when nothing this driver routed sits below it, the value this driver would write is already there, and both the decoder and the switch's route table are committed - the table carries a commit of its own that firmware may not have performed. The first level to fall short ends adoption, and from it up the driver programs and commits as for any other device.
RP Forward, written but never committed
|
USP0 route table committed by the driver
|
DSP0 Forward, written and committed
| ..... adoption ended here .....
USP1 route table already committed
|
DSP1 Enable, taken as found
|
mem0 BI Enable already set by firmware
An adopted level owes no commit either way. Table 8-152 and Table 8-156 owe one per new BI device enabled below the port, and an adopted level is not seeing one.
The endpoint is adopted the same way. BI Enable already set was an error before, since only this driver set it; it is now kept and cxlds->bi taken up without a write.
On failure the walk unwinds only the levels it did not adopt. Since adoption is a prefix, the unwind drops the refcount below the first non-adopted level and leaves those registers alone. Teardown is unchanged and still deallocates every level.
A committed decoder is refused when its coherency model does not fit where it lands. The window must permit it, and unlike a decoder this driver programs it cannot inherit a region's model, so its committed Target Range Type and BI bit must already match. Assembly never validated these bits, so setting them wrongly costs a platform the auto-assembly of the affected decoders.
--- drivers/cxl/core/hdm.c | 27 ++++++++---- drivers/cxl/core/pci.c | 90 +++++++++++++++++++++++++++++++++------ drivers/cxl/core/region.c | 48 +++++++++++++++++++++ 3 files changed, 143 insertions(+), 22 deletions(-)
drivers/cxl/core/hdm.c +19 -8
@@ -1057,13 +1057,23 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,else cxld->target_type =CXL_DECODER_DEVMEM ; -/* -* Autocommit BI-enabled decoders is not supported. A path -* firmware enabled is not taken over, so nothing verifies -* it can route BISnp. -*/ -if (FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl)) -return -ENXIO ; +if (FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl)) { +struct cxl_dev_state *cxlds = cxled ? +cxled_to_memdev (cxled)->cxlds :NULL ; + +if (cxld->target_type ==CXL_DECODER_HOSTONLYMEM ) { +dev_warn (&port->dev, +"decoder%d.%d: BI with host-only\n" , + port->id, cxld->id); +return -ENXIO ; + } +if (cxlds && !cxlds->bi_capable) { +dev_warn (&port->dev, +"decoder%d.%d: path not BI capable\n" , + port->id, cxld->id); +return -ENXIO ; + } + }guard (rwsem_write)(&cxl_rwsem.region);if (cxld->id !=cxl_num_decoders_committed (port)) {
@@ -1310,7 +1320,8 @@ int devm_cxl_endpoint_decoders_setup(struct cxl_port *port)* Between the port's HDM state and its decoders: devres, * unwinding in reverse, brings BI down only after the decoders * quiesce, while its slow walk still precedes the HDM state -* free. +* free. Must also precede region discovery, where HDM-DB +* assembly requires cxlds->bi. */ rc =cxl_bi_setup (port);if (rc)
drivers/cxl/core/pci.c +76 -14
169 lines not on this page · raw message
drivers/cxl/core/region.c +48 -0
70 lines not on this page · raw message
Signature · 1 line
2.39.5
Alison Schofield
maintainerRe: [PATCH v9 08/10] cxl: Allow auto-committed BI hdm decoders
On Tue, Sep 22, 2026 at 04:38:45PM -0700, Davidlohr Bueso wrote:
The cover letter says the series could be picked up with or without this patch. I'm guessing that is a stale statement. Today a committed BI decoder is enumerated like any other. After patch 3 it fails port enumeration, and this patch is what fixes that. So not really optional?
Quoted 55 lines
An HDM decoder that firmware committed with the BI bit set was refused outright. Accept it, and refuse only what is broken - BI paired with a host-only target range type, or for an endpoint decoder BI on a path that cannot route BISnp.
Taking over such a path must not re-program what firmware already did, and a dport's committed state does not say which device it was committed for, only that firmware committed for something below it. Two endpoints sharing a level show why that is not enough to go on.
RP Forward set, but for mem0
|
USP
/ \
DSP0 DSP1
| |
mem0 mem1
BI Enable BI Enable
set clearAdoption is therefore seeded from the endpoint's own BI Enable, since only a device firmware itself enabled can have had its BI-ID accounted for above, and carried up the walk. A level is taken as found, with no register write and no commit, when nothing this driver routed sits below it, the value this driver would write is already there, and both the decoder and the switch's route table are committed - the table carries a commit of its own that firmware may not have performed. The first level to fall short ends adoption, and from it up the driver programs and commits as for any other device.
RP Forward, written but never committed
|
USP0 route table committed by the driver
|
DSP0 Forward, written and committed
| ..... adoption ended here .....
USP1 route table already committed
|
DSP1 Enable, taken as found
|
mem0 BI Enable already set by firmwareAn adopted level owes no commit either way. Table 8-152 and Table 8-156 owe one per new BI device enabled below the port, and an adopted level is not seeing one.
The endpoint is adopted the same way. BI Enable already set was an error before, since only this driver set it; it is now kept and
cxlds->bitaken up without a write.On failure the walk unwinds only the levels it did not adopt. Since adoption is a prefix, the unwind drops the refcount below the first non-adopted level and leaves those registers alone. Teardown is unchanged and still deallocates every level.
Quoted 6 lines
A committed decoder is refused when its coherency model does not fit where it lands. The window must permit it, and unlike a decoder this driver programs it cannot inherit a region's model, so its committed Target Range Type and BI bit must already match. Assembly never validated these bits, so setting them wrongly costs a platform the auto-assembly of the affected decoders.
Assembly did validate Target Range Type until patch 4. cxl_region_attach() refused a decoder whose type differed from the region's. The window check this adds also refuses non-BI auto regions that assemble today. More inline at construct_region()...
snip
Quoted 21 lines
drivers/cxl/core/pci.c +13
-0@@ -1087,6 +1087,29 @@ static int __cxl_bi_commit_decoder(struct device *dev, void __iomem *bi) scale, base); } +/* Committed, or no explicit commit required */ +static bool cxl_bi_decoder_committed (void __iomem *bi) +{ +u32 caps =readl (bi +CXL_BI_DECODER_CAPS_OFFSET ); +u32 sts =readl (bi +CXL_BI_DECODER_STATUS_OFFSET ); + +if (!FIELD_GET (CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ , caps)) +return true; + +return FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMITTED , sts); +} + +static bool cxl_bi_rt_committed (void __iomem *bi)
drivers/cxl/core/pci.c static int __cxl_bi_commit_decoder(struct device *dev, void __iomem *bi) · line 1112
Quoted 10 lines
drivers/cxl/core/pci.c +10
-0+{ +u32 caps =readl (bi +CXL_BI_RT_CAPS_OFFSET ); +u32 sts =readl (bi +CXL_BI_RT_STATUS_OFFSET ); + +if (!FIELD_GET (CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ , caps)) +return true; + +return FIELD_GET (CXL_BI_RT_STATUS_BI_COMMITTED , sts); +} +
Above 2 helpers differ only in register offsets and masks, and repeat the EXPLICIT_COMMIT_REQ caps test already in __cxl_bi_commit_rt() and __cxl_bi_commit_decoder().
Could they be one helper taking offsets and masks, like __cxl_bi_wait_commit() does?
snip
Quoted 9 lines
drivers/cxl/core/pci.c +3
-1static int cxl_bi_enable_path (struct cxl_dev_state *cxlds,struct cxl_port *port,struct cxl_dport *dport) { -struct cxl_dport *dport_iter, *failed; +struct cxl_dport *dport_iter, *failed, *programmed =NULL ; +struct cxl_port *endpoint = cxlds->cxlmd->endpoint;struct cxl_port *port_iter; +bool adopt, clear;int rc;
drivers/cxl/core/pci.c static void cxl_bi_dealloc(void *data) · line 1336
Quoted 10 lines
drivers/cxl/core/pci.c +9
-0+/* +* Adoption is a path property, not a per-dport one: only when +* firmware enabled the device itself does a dport's committed +* state cover this device's BI-ID. +*/ + adopt =FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (endpoint->regs.bi_decoder + +CXL_BI_DECODER_CTRL_OFFSET )); +
Is this cxl_bi_decoder_enabled(endpoint) from core.h?
Quoted 38 lines
drivers/cxl/core/pci.c +10
-2port_iter = port; dport_iter = dport;while (!is_cxl_root (port_iter)) { - rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport); + rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport, + &adopt);if (rc) goto err_rollback; +/* adoption is a prefix: this is the first level not adopted */ +if (!adopt && !programmed) + programmed = dport_iter; + dport_iter = port_iter->parent_dport; port_iter = dport_iter->port; }@@ -1301,8 +1360,11 @@ static int cxl_bi_enable_path(struct cxl_dev_state *cxlds, failed = dport_iter; dport_iter = dport; port_iter = port; + clear = false;while (!is_cxl_root (port_iter) && dport_iter != failed) { -cxl_bi_ctrl_dport_disable (dport_iter); +if (dport_iter == programmed) + clear = true; +cxl_bi_ctrl_dport_disable (dport_iter, clear); dport_iter = port_iter->parent_dport; port_iter = dport_iter->port; }drivers/cxl/core/region.c +1
-0@@ -1861,6 +1861,20 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,return rc; } +static bool cxled_committed_bi (struct cxl_endpoint_decoder *cxled)
drivers/cxl/core/region.c static int cxl_region_attach_position(struct cxl_region *cxlr, · line 1874
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+{ +struct cxl_port *port =cxled_to_port (cxled); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +u32 ctrl; + +if (!cxlhdm || !cxlhdm->regs.hdm_decoder) +return false; + + ctrl =readl (cxlhdm->regs.hdm_decoder + +CXL_HDM_DECODER0_CTRL_OFFSET (cxled->cxld.id));
I'm having some deja vu here. I may have asked and you answered this on an earlier version, but now that I see Patch 9 it makes me ask again. Patch 9 wouldn't need to mock this if we stored it as committed BI state instead. Maybe in cxld->flags using CXL_DECODE_F_BI.
Quoted 10 lines
drivers/cxl/core/region.c +3
-0+return FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl); +} +static const char *cxl_coherency_name (enum cxl_decoder_type type,bool bi) {if (type ==CXL_DECODER_HOSTONLYMEM )@@ -2179,6 +2193,24 @@ static int cxl_region_attach(struct cxl_region *cxlr,return -ENXIO ; }
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2205
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+/* a committed decoder cannot inherit the region's flavor */ +if (cxled->state ==CXL_DECODER_STATE_AUTO ) { +bool bi =cxled_committed_bi (cxled); +const char *have, *want; + + have =cxl_coherency_name (cxled->cxld.target_type, bi); + want =cxl_coherency_name (cxlr->type, +cxl_root_decoder_is_bi (cxlrd)); +if (cxled->cxld.target_type != cxlr->type || + bi !=cxl_root_decoder_is_bi (cxlrd)) {
Looks like only need have and want computed when mismatch is detected. cxl_root_decoder_is_bi could also be cached once.
Quoted 19 lines
drivers/cxl/core/region.c +9
-0+dev_err (&cxlr->dev, +"%s:%s coherency model mismatch: %s vs %s\n" , +dev_name (&cxlmd->dev), +dev_name (&cxled->cxld.dev), have, want); +return -ENXIO ; + } + } +if (!cxled->dpa_res) {dev_dbg (&cxlr->dev,"%s:%s: missing DPA allocation.\n" ,dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev));@@ -3838,10 +3870,26 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,struct cxl_dev_state *cxlds = cxlmd->cxlds;int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +unsigned long need;if (part <0 )return ERR_PTR (-EBUSY );
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 3886
Quoted 10 lines
drivers/cxl/core/region.c +9
-0+/* +* A committed decoder defines the region built from it, so no +* attach check can find its coherency model wrong. Only the +* window's restrictions can, on the BI and range type axes. +*/ + need = cxled->cxld.target_type ==CXL_DECODER_DEVMEM ? +CXL_DECODER_F_DEVMEM :CXL_DECODER_F_HOSTONLY ; +if (cxled_committed_bi (cxled) !=cxl_root_decoder_is_bi (cxlrd) || + !(cxlrd->cxlsd.cxld.flags & need)) {
This refuses non BI auto regions that assemble before this patch. Why is this in a patch called 'Allow auto-committed BI hdm decoders'.
Quoted 12 lines
drivers/cxl/core/region.c +6
-0+dev_err (&cxlrd->cxlsd.cxld.dev, +"%s:%s coherency model not permitted by the window\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return ERR_PTR (-ENXIO ); + } + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id),Signature · 1 line
2.39.5
Davidlohr Bueso
maintainerRe: [PATCH v9 08/10] cxl: Allow auto-committed BI hdm decoders
Quoted 7 lines · Alison Schofield
On Tue, Sep 22, 2026 at 04:38:45PM -0700, Davidlohr Bueso wrote:
The cover letter says the series could be picked up with or without this patch. I'm guessing that is a stale statement. Today a committed BI decoder is enumerated like any other. After patch 3 it fails port enumeration, and this patch is what fixes that. So not really optional?
You are correct about the fully auto committed BI topology case, the problem today is that bogus topologies can still be onlined.
I will rephrase the cover letter for patch 8, drop the refusal in patch 3, and have patch 2 adopt a device firmware already enabled, so that through patch 7 the auto-committed semantics are identical to upstream and patch 8 refuses only what cannot route BISnp.
Quoted 111 lines
Quoted 56 lines
An HDM decoder that firmware committed with the BI bit set was refused outright. Accept it, and refuse only what is broken - BI paired with a host-only target range type, or for an endpoint decoder BI on a path that cannot route BISnp.
Taking over such a path must not re-program what firmware already did, and a dport's committed state does not say which device it was committed for, only that firmware committed for something below it. Two endpoints sharing a level show why that is not enough to go on.
RP Forward set, but for mem0
|
USP
/ \
DSP0 DSP1
| |
mem0 mem1
BI Enable BI Enable
set clearAdoption is therefore seeded from the endpoint's own BI Enable, since only a device firmware itself enabled can have had its BI-ID accounted for above, and carried up the walk. A level is taken as found, with no register write and no commit, when nothing this driver routed sits below it, the value this driver would write is already there, and both the decoder and the switch's route table are committed - the table carries a commit of its own that firmware may not have performed. The first level to fall short ends adoption, and from it up the driver programs and commits as for any other device.
RP Forward, written but never committed
|
USP0 route table committed by the driver
|
DSP0 Forward, written and committed
| ..... adoption ended here .....
USP1 route table already committed
|
DSP1 Enable, taken as found
|
mem0 BI Enable already set by firmwareAn adopted level owes no commit either way. Table 8-152 and Table 8-156 owe one per new BI device enabled below the port, and an adopted level is not seeing one.
The endpoint is adopted the same way. BI Enable already set was an error before, since only this driver set it; it is now kept and
cxlds->bitaken up without a write.On failure the walk unwinds only the levels it did not adopt. Since adoption is a prefix, the unwind drops the refcount below the first non-adopted level and leaves those registers alone. Teardown is unchanged and still deallocates every level.
Quoted 6 lines
A committed decoder is refused when its coherency model does not fit where it lands. The window must permit it, and unlike a decoder this driver programs it cannot inherit a region's model, so its committed Target Range Type and BI bit must already match. Assembly never validated these bits, so setting them wrongly costs a platform the auto-assembly of the affected decoders.
Assembly did validate Target Range Type until patch 4.
cxl_region_attach()refused a decoder whose type differed from the region's. The window check this adds also refuses non-BI auto regions that assemble today. More inline atconstruct_region()...snip
Quoted 21 lines
drivers/cxl/core/pci.c +13
-0@@ -1087,6 +1087,29 @@ static int __cxl_bi_commit_decoder(struct device *dev, void __iomem *bi) scale, base); } +/* Committed, or no explicit commit required */ +static bool cxl_bi_decoder_committed (void __iomem *bi) +{ +u32 caps =readl (bi +CXL_BI_DECODER_CAPS_OFFSET ); +u32 sts =readl (bi +CXL_BI_DECODER_STATUS_OFFSET ); + +if (!FIELD_GET (CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ , caps)) +return true; + +return FIELD_GET (CXL_BI_DECODER_STATUS_BI_COMMITTED , sts); +} + +static bool cxl_bi_rt_committed (void __iomem *bi)drivers/cxl/core/pci.c static int __cxl_bi_commit_decoder(struct device *dev, void __iomem *bi) · line 1112
Quoted 10 lines
drivers/cxl/core/pci.c +10
-0+{ +u32 caps =readl (bi +CXL_BI_RT_CAPS_OFFSET ); +u32 sts =readl (bi +CXL_BI_RT_STATUS_OFFSET ); + +if (!FIELD_GET (CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ , caps)) +return true; + +return FIELD_GET (CXL_BI_RT_STATUS_BI_COMMITTED , sts); +} +Above 2 helpers differ only in register offsets and masks, and repeat the
EXPLICIT_COMMIT_REQcaps test already in__cxl_bi_commit_rt()and__cxl_bi_commit_decoder().
Quoted 2 lines
Could they be one helper taking offsets and masks, like
__cxl_bi_wait_commit()does?
I went ahead with the following, which I'm not sure is particularly better, but at least abstracts the core logic:
/* Committed, or no explicit commit required */
static bool __cxl_bi_committed(void __iomem *caps_reg, void __iomem *status_reg,
u32 req_bit, u32 committed_bit)
{
if (!(readl(caps_reg) & req_bit))
return true;
return readl(status_reg) & committed_bit;
} static bool cxl_bi_rt_committed(void __iomem *bi)
{
return __cxl_bi_committed(bi + CXL_BI_RT_CAPS_OFFSET,
bi + CXL_BI_RT_STATUS_OFFSET, CXL_BI_RT_CAPS_EXPLICIT_COMMIT_REQ, CXL_BI_RT_STATUS_BI_COMMITTED);
}
static bool cxl_bi_decoder_committed(void __iomem *bi)
{
return __cxl_bi_committed(bi + CXL_BI_DECODER_CAPS_OFFSET,
bi + CXL_BI_DECODER_STATUS_OFFSET, CXL_BI_DECODER_CAPS_EXPLICIT_COMMIT_REQ, CXL_BI_DECODER_STATUS_BI_COMMITTED);
}
Quoted 14 lines
snip
Quoted 10 lines
static int cxl_bi_enable_path(struct
cxl_dev_state*cxlds,drivers/cxl/core/pci.c +3
-1struct cxl_port *port, struct cxl_dport *dport) { - struct cxl_dport *dport_iter, *failed; + struct cxl_dport *dport_iter, *failed, *programmed = NULL; +struct cxl_port *endpoint = cxlds->cxlmd->endpoint;struct cxl_port *port_iter; +bool adopt, clear;int rc;
Quoted 12 lines
drivers/cxl/core/pci.c
Quoted 9 lines
drivers/cxl/core/pci.c +9
-0+/* +* Adoption is a path property, not a per-dport one: only when +* firmware enabled the device itself does a dport's committed +* state cover this device's BI-ID. +*/ + adopt =FIELD_GET (CXL_BI_DECODER_CTRL_BI_ENABLE , +readl (endpoint->regs.bi_decoder + +CXL_BI_DECODER_CTRL_OFFSET )); +Is this
cxl_bi_decoder_enabled(endpoint)fromcore.h?
It is, will update.
Quoted 49 lines
Quoted 49 lines
drivers/cxl/core/pci.c +10
-2port_iter = port; dport_iter = dport;while (!is_cxl_root (port_iter)) { - rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport); + rc =cxl_bi_ctrl_dport_enable (dport_iter, dport_iter == dport, + &adopt);if (rc) goto err_rollback; +/* adoption is a prefix: this is the first level not adopted */ +if (!adopt && !programmed) + programmed = dport_iter; + dport_iter = port_iter->parent_dport; port_iter = dport_iter->port; }@@ -1301,8 +1360,11 @@ static int cxl_bi_enable_path(struct cxl_dev_state *cxlds, failed = dport_iter; dport_iter = dport; port_iter = port; + clear = false;while (!is_cxl_root (port_iter) && dport_iter != failed) { -cxl_bi_ctrl_dport_disable (dport_iter); +if (dport_iter == programmed) + clear = true; +cxl_bi_ctrl_dport_disable (dport_iter, clear); dport_iter = port_iter->parent_dport; port_iter = dport_iter->port; }drivers/cxl/core/region.c +9
-0@@ -1861,6 +1861,20 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,return rc; } +static bool cxled_committed_bi (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_port *port =cxled_to_port (cxled); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +u32 ctrl; + +if (!cxlhdm || !cxlhdm->regs.hdm_decoder) +return false; +
Quoted 9 lines
drivers/cxl/core/region.c static int cxl_region_attach_position(struct cxl_region *cxlr, · line 1874
Quoted 2 lines
drivers/cxl/core/region.c +2
-0+ ctrl =readl (cxlhdm->regs.hdm_decoder + +CXL_HDM_DECODER0_CTRL_OFFSET (cxled->cxld.id));I'm having some deja vu here. I may have asked and you answered this on an earlier version, but now that I see Patch 9 it makes me ask again. Patch 9 wouldn't need to mock this if we stored it as committed BI state instead. Maybe in
cxld->flagsusingCXL_DECODE_F_BI.
Ok.
Quoted 12 lines
Quoted 12 lines
drivers/cxl/core/region.c +3
-0+return FIELD_GET (CXL_HDM_DECODER0_CTRL_BI , ctrl); +} +static const char *cxl_coherency_name (enum cxl_decoder_type type,bool bi) {if (type ==CXL_DECODER_HOSTONLYMEM )@@ -2179,6 +2193,24 @@ static int cxl_region_attach(struct cxl_region *cxlr,return -ENXIO ; }
Quoted 14 lines
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 2205
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+/* a committed decoder cannot inherit the region's flavor */ +if (cxled->state ==CXL_DECODER_STATE_AUTO ) { +bool bi =cxled_committed_bi (cxled); +const char *have, *want; + + have =cxl_coherency_name (cxled->cxld.target_type, bi); + want =cxl_coherency_name (cxlr->type, +cxl_root_decoder_is_bi (cxlrd)); +if (cxled->cxld.target_type != cxlr->type || + bi !=cxl_root_decoder_is_bi (cxlrd)) {Looks like only need have and want computed when mismatch is detected.
cxl_root_decoder_is_bicould also be cached once.
Yep, I've cleaned these up as such:
drivers/cxl/core/region.c +6 -9
@@ -2133,6 +2133,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_region_params *p = &cxlr->params; +bool root_bi =cxl_root_decoder_is_bi (cxlrd);struct cxl_port *ep_port, *root_port;struct cxl_dport *dport;struct cxl_hdm *cxlhdm;
@@ -2190,8 +2191,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,* proceeding. The endpoint decoder's target_type is then inherited * from cxlr->type later in cxl_rr_assign_decoder(). */ -if (cxlr->type ==CXL_DECODER_DEVMEM && -cxl_root_decoder_is_bi (cxlrd) && !cxlds->bi) { +if (cxlr->type ==CXL_DECODER_DEVMEM && root_bi && !cxlds->bi) {dev_dbg (&cxlr->dev,"%s:%s BI not enabled on device\n" ,dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev));return -ENXIO ;
@@ -2224,17 +2224,14 @@ static int cxl_region_attach(struct cxl_region *cxlr,/* a committed decoder cannot inherit the region's flavor */ if (cxled->state ==CXL_DECODER_STATE_AUTO ) {bool bi =cxled_committed_bi (cxled); -const char *have, *want; - have =cxl_coherency_name (cxled->cxld.target_type, bi); - want =cxl_coherency_name (cxlr->type, -cxl_root_decoder_is_bi (cxlrd)); -if (cxled->cxld.target_type != cxlr->type || - bi !=cxl_root_decoder_is_bi (cxlrd)) { +if (cxled->cxld.target_type != cxlr->type || bi != root_bi) {dev_err (&cxlr->dev,"%s:%s coherency model mismatch: %s vs %s\n" ,dev_name (&cxlmd->dev), -dev_name (&cxled->cxld.dev), have, want); +dev_name (&cxled->cxld.dev), +cxl_coherency_name (cxled->cxld.target_type, bi), +cxl_coherency_name (cxlr->type, root_bi));return -ENXIO ; } }
Quoted 22 lines
Quoted 22 lines
drivers/cxl/core/region.c +9
-0+dev_err (&cxlr->dev, +"%s:%s coherency model mismatch: %s vs %s\n" , +dev_name (&cxlmd->dev), +dev_name (&cxled->cxld.dev), have, want); +return -ENXIO ; + } + } +if (!cxled->dpa_res) {dev_dbg (&cxlr->dev,"%s:%s: missing DPA allocation.\n" ,dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev));@@ -3838,10 +3870,26 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,struct cxl_dev_state *cxlds = cxlmd->cxlds;int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +unsigned long need;if (part <0 )return ERR_PTR (-EBUSY );
Quoted 13 lines
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 3886
Quoted 9 lines
drivers/cxl/core/region.c +9
-0+/* +* A committed decoder defines the region built from it, so no +* attach check can find its coherency model wrong. Only the +* window's restrictions can, on the BI and range type axes. +*/ + need = cxled->cxld.target_type ==CXL_DECODER_DEVMEM ? +CXL_DECODER_F_DEVMEM :CXL_DECODER_F_HOSTONLY ; +if (cxled_committed_bi (cxled) !=cxl_root_decoder_is_bi (cxlrd) || + !(cxlrd->cxlsd.cxld.flags & need)) {This refuses non BI auto regions that assemble before this patch. Why is this in a patch called 'Allow auto-committed BI hdm decoders'.
The range type half belongs in patch 4 with the other coherency checks, and I will move it there. The BI half is this patch's.
Thanks,
Davidlohr
Quoted 15 lines
Quoted 15 lines
drivers/cxl/core/region.c +6
-1+dev_err (&cxlrd->cxlsd.cxld.dev, +"%s:%s coherency model not permitted by the window\n" , +dev_name (&cxlmd->dev),dev_name (&cxled->cxld.dev)); +return ERR_PTR (-ENXIO ); + } + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id), --2.39.5
Davidlohr Bueso
maintainerPATCH v9 9/10 cxl/test: Add mock BI topology support
In reply to Davidlohr BuesoExtend the mock topology with a Back-Invalidate path covering both the type3 memdevs and the type2 accelerator.
Following the framework's convention of substituting software state for register programming, cxl_bi_probe_capable() gains a --wrap shim dispatching through cxl_mock_ops, and the mock decoder setup enables BI in software in place of cxl_bi_setup(). The mock setup mirrors cxl_bi_enable_path()'s walk - dport nr_bi accounting up to the root, unwound by a devm action - and the capability check keeps the VH-only rule.
A single HDM-DB window (BI | DEVMEM | VOLATILE, targeting host bridge 0) is emitted in every topology mode and parses into a CXL_DECODER_F_BI root decoder; DEVMEM satisfies can_create_ram(). In type2 mode it coexists with the accelerator's HDM-D window.
cxled_committed_bi() reads the BI bit from the HDM decoder registers, so each mock port's cxl_hdm carries a page of plain memory as that register block, maintained on decoder commit/reset and restored on saved-decoder replay - letting a committed HDM-DB region survive a cxl_acpi rebind. Endpoints get a second such page standing in for BI Decoder Control, with BI Enable set, since committing an HDM-DB region reads it back. The accelerator grows to 1G of capacity so the boot-time auto region leaves DPA for a BI region.
--- tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/test/accel.c | 2 +- tools/testing/cxl/test/cxl.c | 171 ++++++++++++++++++++++++++++++++- tools/testing/cxl/test/mock.c | 13 +++ tools/testing/cxl/test/mock.h | 1 + 5 files changed, 184 insertions(+), 4 deletions(-)
tools/testing/cxl/Kbuild +1 -0
@@ -14,6 +14,7 @@ ldflags-y += --wrap=devm_cxl_switch_port_decoders_setup ldflags-y += --wrap=walk_hmem_resources ldflags-y += --wrap=region_intersects ldflags-y += --wrap=region_intersects_soft_reserve +ldflags-y += --wrap=cxl_bi_probe_capable DRIVERS := ../../../drivers DAX_HMEM_SRC := $(DRIVERS)/dax/hmem
tools/testing/cxl/test/accel.c +1 -1
@@ -31,7 +31,7 @@ static int cxl_mock_accel_probe(struct platform_device *pdev) cxlds = &cxl_accel->cxlds; cxlds->media_ready = true; - rc =cxl_set_capacity (cxlds,SZ_512M ); + rc =cxl_set_capacity (cxlds,SZ_1G );if (rc)return rc;
tools/testing/cxl/test/cxl.c +168 -3
255 lines not on this page · raw message
tools/testing/cxl/test/mock.c +13 -0
@@ -181,6 +181,19 @@ int __wrap_devm_cxl_endpoint_decoders_setup(struct cxl_port *port) }EXPORT_SYMBOL_NS_GPL (__wrap_devm_cxl_endpoint_decoders_setup,"CXL" ); +void __wrap_cxl_bi_probe_capable (struct cxl_port *endpoint) +{ +int index; +struct cxl_mock_ops *ops =get_cxl_mock_ops (&index); + +if (ops && ops->is_mock_port (endpoint->uport_dev)) + ops->cxl_bi_probe_capable (endpoint); +else +cxl_bi_probe_capable (endpoint); +put_cxl_mock_ops (index); +} +EXPORT_SYMBOL_NS_GPL (__wrap_cxl_bi_probe_capable,"CXL" ); +int __wrap_cxl_await_media_ready (struct cxl_dev_state *cxlds) {int rc, index;
tools/testing/cxl/test/mock.h +1 -0
@@ -35,6 +35,7 @@ struct cxl_mock_ops { unsigned long flags, unsigned long desc);int (*region_intersects_soft_reserve)(resource_size_t start,size_t size); +void (*cxl_bi_probe_capable)(struct cxl_port *endpoint); };int hmem_test_init (void );
Signature · 1 line
2.39.5
Re: [PATCH v9 09/10] cxl/test: Add mock BI topology support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] cxl/test: Use-After-Free in mock_cxl_setup_hdm() on unbind/rebind --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cxl/test: Use-After-Free in mock_cxl_setup_hdm() on unbind/rebind --
commit 943579b999ae7670b28d433527c8563008ab779f
Author: Davidlohr Bueso <[email protected]>
cxl/test: Add mock BI topology support
Extend the mock topology with a Back-Invalidate path covering both the type3 memdevs and the type2 accelerator.
[ ... ]
Quoted 4 lines
tools/testing/cxl/test/cxl.c +0
-0
[ ... ]
Quoted 19 lines
tools/testing/cxl/test/cxl.c +15
-0@@ -736,10 +767,65 @@ static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, cxlhdm->port = port; cxlhdm->interleave_mask = ~0U ; cxlhdm->iw_cap_mask = ~0UL ; + +/* +* A page of plain memory stands in for the HDM decoder register +* block: cxled_committed_bi() reads the per-decoder BI bit from +* it, which mock_decoder_commit()/reset() maintain below. All +* other consumers of these registers are bypassed by the mocked +* decoder setup and commit paths. +*/ + cxlhdm->regs.hdm_decoder = + (void __iomem *)devm_get_free_pages (dev, +GFP_KERNEL | __GFP_ZERO,0 ); +if (!cxlhdm->regs.hdm_decoder) +return ERR_PTR (-ENOMEM ); + +/* likewise for the endpoint's BI Decoder block, BI Enable set */
tools/testing/cxl/test/cxl.c static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, · line 794
Quoted 10 lines
tools/testing/cxl/test/cxl.c +10
-0+if (is_cxl_endpoint (port) && !port->regs.bi_decoder) { +void __iomem *bi = (void __iomem *) +devm_get_free_pages (dev,GFP_KERNEL | __GFP_ZERO,0 ); + +if (!bi) +return ERR_PTR (-ENOMEM ); +writel (CXL_BI_DECODER_CTRL_BI_ENABLE , + bi +CXL_BI_DECODER_CTRL_OFFSET ); + port->regs.bi_decoder = bi; + }
[Severity: Medium]
Could this lead to a use-after-free during a driver unbind/rebind cycle?
In mock_cxl_setup_hdm(), devm_get_free_pages() is used to allocate memory for port->regs.bi_decoder. During a cxl_test unbind, devres will free this memory, but the pointer remains set in the long-lived struct cxl_port.
On a subsequent rebind, the condition !port->regs.bi_decoder will evaluate to false, skipping the allocation of new memory. This leaves a dangling pointer that could be dereferenced later by cxl_bi_decoder_enabled().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Davidlohr Bueso
maintainerRe: [PATCH v9 09/10] cxl/test: Add mock BI topology support
Quoted 2 lines · On Wed, 23 Sep 2026, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cxl/test: Use-After-Free inmock_cxl_setup_hdm()on unbind/rebind
This is valid, but just affects the mock device, I have fixed it per the below.
Quoted 53 lines
--
commit
943579b999ae7670b28d433527c8563008ab779f
Author: Davidlohr Bueso <[email protected]>cxl/test: Add mock BI topology support
Extend the mock topology with a Back-Invalidate path covering both the type3 memdevs and the type2 accelerator.
[ ... ]
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>Quoted 4 lines
tools/testing/cxl/test/cxl.c +0
-0[ ... ]
Quoted 19 lines
tools/testing/cxl/test/cxl.c +15
-0@@ -736,10 +767,65 @@ static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, cxlhdm->port = port; cxlhdm->interleave_mask = ~0U ; cxlhdm->iw_cap_mask = ~0UL ; + +/* +* A page of plain memory stands in for the HDM decoder register +* block: cxled_committed_bi() reads the per-decoder BI bit from +* it, which mock_decoder_commit()/reset() maintain below. All +* other consumers of these registers are bypassed by the mocked +* decoder setup and commit paths. +*/ + cxlhdm->regs.hdm_decoder = + (void __iomem *)devm_get_free_pages (dev, +GFP_KERNEL | __GFP_ZERO,0 ); +if (!cxlhdm->regs.hdm_decoder) +return ERR_PTR (-ENOMEM ); + +/* likewise for the endpoint's BI Decoder block, BI Enable set */ tools/testing/cxl/test/cxl.c static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, · line 794
Quoted 10 lines
tools/testing/cxl/test/cxl.c +10
-0+if (is_cxl_endpoint (port) && !port->regs.bi_decoder) { +void __iomem *bi = (void __iomem *) +devm_get_free_pages (dev,GFP_KERNEL | __GFP_ZERO,0 ); + +if (!bi) +return ERR_PTR (-ENOMEM ); +writel (CXL_BI_DECODER_CTRL_BI_ENABLE , + bi +CXL_BI_DECODER_CTRL_OFFSET ); + port->regs.bi_decoder = bi; + }[Severity: Medium]
Could this lead to a use-after-free during a driver unbind/rebind cycle?
Quoted 7 lines
In
mock_cxl_setup_hdm(),devm_get_free_pages()is used to allocate memory forport->regs.bi_decoder. During acxl_testunbind, devres will free this memory, but the pointer remains set in the long-lived structcxl_port.On a subsequent rebind, the condition !port->regs.bi_decoder will evaluate to false, skipping the allocation of new memory. This leaves a dangling pointer that could be dereferenced later by
cxl_bi_decoder_enabled().
I was able to reproduce this pounding with the mock device with:
echo endpoint16 > /sys/bus/cxl/drivers/cxl_port/unbind echo endpoint16 > /sys/bus/cxl/drivers/cxl_port/bind <create an HDM-DB region on decoder16.0 and commit it>
The bind mostly fails with ENODEV, but for a window where that bind beats the the unbind's queued detach work, that reprobes the same cxl_port, so we run into:
[ 25.154927] cxl_port endpoint14: probe: 0
[ 25.229702] cxl region6: mem7:decoder14.0 BI disabled by reset during commitNothing had cleared BI Enable on that endpoint.
I will fold this fix fix with:
- if (is_cxl_endpoint(port) && !port->regs.bi_decoder) {
+ if (is_cxl_endpoint(port)) {
(mock device only, real driver not affected since devm_cxl_port_bi_setup() re-maps on every probe and cxl_map_component_regs() assigns unconditionally).
Davidlohr Bueso
maintainerPATCH v9 10/10 cxl/doc: Update maturity map with BI support
In reply to Davidlohr BuesoAdd the respective Back-Invalidate info to the maturity map document.
--- Documentation/driver-api/cxl/maturity-map.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Documentation/driver-api/cxl/maturity-map.rst +15 -1
@@ -63,6 +63,11 @@ in place, but there are several corner cases that are pending closure. * [0] Decoder target and granularity constraints +* [1] :ref:`Back-Invalidate (HDM-DB) <back-invalidate>` + + * [3] BI topology enable / disable (endpoint, DSP, USP route table, RP) + * [2] Firmware-enabled path adoption + * [2] Performance enumeration * [3] Endpoint CDAT
@@ -166,7 +171,7 @@ Accelerator ----------- * [0] Accelerator memory enumeration HDM-D (CXL 1.1/2.0 Type-2) -* [0] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) +* [1] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) * [0] CXL.cache 68b (CXL 2.0) * [0] CXL.cache 256b Cache IDs (CXL 3.0)
@@ -192,6 +197,15 @@ Details hiding some standard registers like PCIe Link Status / Capabilities in the CXL RCRB (Root Complex Register Block). +.. _back-invalidate: + +* **Back-Invalidate**: HDM-DB lets a device snoop the host over the + CXL.mem BISnp channel instead of CXL.cache. The kernel enables BI on + every port between a device and its root port, requires 256B Flit + mode on the path, adopts paths firmware already enabled, and creates + HDM-DB regions under CFMWS windows carrying the Back-Invalidate + restriction for Type 3 and Type 2 devices alike. + .. _background-commands: * **Background commands**: The CXL background command mechanism is
Signature · 1 line
2.39.5
Re: [PATCH v9 10/10] cxl/doc: Update maturity map with BI support
Quoted 4 lines · Davidlohr Bueso
Add the respective Back-Invalidate info to the maturity map document.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 45 lines
--- Documentation/driver-api/cxl/maturity-map.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)Documentation/driver-api/cxl/maturity-map.rst +15
-1@@ -63,6 +63,11 @@ in place, but there are several corner cases that are pending closure. * [0] Decoder target and granularity constraints +* [1] :ref:`Back-Invalidate (HDM-DB) <back-invalidate>` + + * [3] BI topology enable / disable (endpoint, DSP, USP route table, RP) + * [2] Firmware-enabled path adoption + * [2] Performance enumeration * [3] Endpoint CDAT@@ -166,7 +171,7 @@ Accelerator ----------- * [0] Accelerator memory enumeration HDM-D (CXL 1.1/2.0 Type-2) -* [0] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) +* [1] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) * [0] CXL.cache 68b (CXL 2.0) * [0] CXL.cache 256b Cache IDs (CXL 3.0)@@ -192,6 +197,15 @@ Details hiding some standard registers like PCIe Link Status / Capabilities in the CXL RCRB (Root Complex Register Block). +.. _back-invalidate: + +* **Back-Invalidate**: HDM-DB lets a device snoop the host over the + CXL.mem BISnp channel instead of CXL.cache. The kernel enables BI on + every port between a device and its root port, requires 256B Flit + mode on the path, adopts paths firmware already enabled, and creates + HDM-DB regions under CFMWS windows carrying the Back-Invalidate + restriction for Type 3 and Type 2 devices alike. + .. _background-commands: * **Background commands**: The CXL background command mechanism is
Re: [PATCH v9 10/10] cxl/doc: Update maturity map with BI support
In reply to Davidlohr BuesoQuoted 1 line · Davidlohr Bueso
Add the respective Back-Invalidate info to the maturity map document.
Looks like this actually updates BI and Type2 status, which is good, just not stated in the commit subject or message.
If you're reving anyways, please fix that up.
Quoted 51 lines
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>--- Documentation/driver-api/cxl/maturity-map.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)Documentation/driver-api/cxl/maturity-map.rst +15
-1@@ -63,6 +63,11 @@ in place, but there are several corner cases that are pending closure. * [0] Decoder target and granularity constraints +* [1] :ref:`Back-Invalidate (HDM-DB) <back-invalidate>` + + * [3] BI topology enable / disable (endpoint, DSP, USP route table, RP) + * [2] Firmware-enabled path adoption + * [2] Performance enumeration * [3] Endpoint CDAT@@ -166,7 +171,7 @@ Accelerator ----------- * [0] Accelerator memory enumeration HDM-D (CXL 1.1/2.0 Type-2) -* [0] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) +* [1] Accelerator memory enumeration HDM-DB (CXL 3.0 Type-2) * [0] CXL.cache 68b (CXL 2.0) * [0] CXL.cache 256b Cache IDs (CXL 3.0)@@ -192,6 +197,15 @@ Details hiding some standard registers like PCIe Link Status / Capabilities in the CXL RCRB (Root Complex Register Block). +.. _back-invalidate: + +* **Back-Invalidate**: HDM-DB lets a device snoop the host over the + CXL.mem BISnp channel instead of CXL.cache. The kernel enables BI on + every port between a device and its root port, requires 256B Flit + mode on the path, adopts paths firmware already enabled, and creates + HDM-DB regions under CFMWS windows carrying the Back-Invalidate + restriction for Type 3 and Type 2 devices alike. + .. _background-commands: * **Background commands**: The CXL background command mechanism isSignature · 1 line
2.39.5
Alison Schofield
maintainerOn Tue, Sep 22, 2026 at 04:38:37PM -0700, Davidlohr Bueso wrote:
snip
Quoted 8 lines
This passes regression testing (nothing breaks) ndctl suite via
cxl_test, with the mock HDM-DB window of patch 9 and the BI phase covering HDM-DB assembly,cxl_acpirebind replay and the Type 2 accelerator. The BI mock device test script along with tooling to consume the new sysfs ABI from this series is in the ndctl tree here:https://github.com/davidlohr/ndctl/tree/cxl-back-invalidate-test
Please post this to linux-cxl and [email protected] Thanks!