hw/cxl: hw/cxl: Host-only default CFMW restrictions and per-window options
v2 cover hw/cxl: hw/cxl: Host-only default CFMW restrictions and per-window options
Changes since v1 [0]:
- Keep device-coherent (HDM-D) in the default alongside host-only -- 0x0f rather than v1's 0xe, dropping only Back-Invalidate. (Jonathan)
- Give the mixed HDM-DB / host-only docs example a window per host bridge so the mapping is explicit and both windows are exercised (Jonathan).
- Add qtests (new patch 5).
[0] https://lore.kernel.org/all/[email protected]/
As of commit e6742e71c24 CXL emulation is incurring in an (per spec) undefined behaviour scenario, by allowing the CXL Window to publish all three coherency models. This series addresses this issue.
The CEDT CFMWS "Window Restrictions" field (CXL r4.0 9.18.1.3) advertises which coherency models and memory types a CXL Fixed Memory Window (CFMW) permits.
- Patches 1-3 drop Back-Invalidate from the default Window Restrictions (0x2f -> 0x0f), keeping both the device-coherent and host-only coherency models plus volatile and persistent, so an unconfigured window is spec-compliant out of the box. It is split into three patches as the bios-tables-test workflow requires (exclude CEDT.cxl, change the value, regenerate the blob, please shout if I'm doing something silly).
- Patch 4 makes the restrictions configurable per window via named machine properties -- device-coherent, host-only, volatile, persistent, fixed-config, back-invalidate.
- Patch 5 adds qtests.
Thanks!
Davidlohr Bueso (5):
tests/bios-tables-test: Exclude CEDT.cxl for the CFMW restriction
change
hw/cxl: Drop Back-Invalidate from default CFMW window restrictions tests/acpi/cxl: Update CEDT.cxl for the default CFMW restrictions hw/cxl: Add configurable CXL Fixed Memory Window restriction flags tests/qtest/cxl: Add CXL Fixed Memory Window restriction flag tests
docs/system/devices/cxl.rst | 25 ++++---- hw/acpi/cxl.c | 2 +- hw/cxl/cxl-host.c | 46 +++++++++++++++ include/hw/cxl/cxl.h | 12 ++++ qapi/machine.json | 28 +++++++++ tests/data/acpi/x86/q35/CEDT.cxl | Bin 184 -> 184 bytes tests/qtest/cxl-test.c | 95 +++++++++++++++++++++++++++++++ 7 files changed, 197 insertions(+), 11 deletions(-)
base-commit: b9e9a55f9950b78ef4c940d0599409c614f36766
Signature · 1 line
2.39.5
PATCH v2 1/5 tests/bios-tables-test: Exclude CEDT.cxl for the CFMW restriction change
The next patch changes the default CXL Fixed Memory Window restrictions, dropping Back-Invalidate. Add CEDT.cxl to the allowed-diff list so the comparison passes until the expected blob is regenerated.
--- tests/qtest/bios-tables-test-allowed-diff.h | 1 + 1 file changed, 1 insertion(+)
tests/qtest/bios-tables-test-allowed-diff.h +1 -0
@@ -1 +1,2 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/x86/q35/CEDT.cxl",
Signature · 1 line
2.39.5
PATCH v2 2/5 hw/cxl: Drop Back-Invalidate from default CFMW window restrictions
In reply to Davidlohr BuesoThe default CXL Fixed Memory Window restrictions advertised host-only coherent together with Back-Invalidate. A window advertising both simultaneously is undefined behavior per CXL r4.0 9.18.1.3.
Drop Back-Invalidate from the default, leaving device-coherent + host-only + volatile + persistent.
--- hw/acpi/cxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/cxl.c +1 -1
@@ -172,7 +172,7 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)build_append_int_noprefix (table_data, fw->enc_int_gran,4 );/* Window Restrictions */ -build_append_int_noprefix (table_data,0x2f ,2 ); +build_append_int_noprefix (table_data,0x0f ,2 );/* QTG ID */ build_append_int_noprefix (table_data,0 ,2 );
Signature · 1 line
2.39.5
PATCH v2 3/5 tests/acpi/cxl: Update CEDT.cxl for the default CFMW restrictions
In reply to Davidlohr BuesoWith the default CXL Fixed Memory Window restrictions changed to drop Back-Invalidate (keeping device-coherent and host-only), update the expected CEDT to advertise 0x0f instead of 0x2f.
[064h 0100 001h] Subtable Type : 01 [CXL Fixed Memory Window Structure]
[065h 0101 001h] Reserved : 00
[066h 0102 002h] Length : 0028
[068h 0104 004h] Reserved : 00000000
[06Ch 0108 008h] Window base address : 0000000110000000
[074h 0116 008h] Window size : 0000000100000000
[07Ch 0124 001h] Interleave Members : 00
[07Dh 0125 001h] Interleave Arithmetic : 00
[07Eh 0126 002h] Reserved : 0000
[080h 0128 004h] Granularity : 00000005
[084h 0132 002h] Restrictions : 000F
[086h 0134 002h] QtgId : 0000
[088h 0136 004h] First Target : 0000000C
--- tests/data/acpi/x86/q35/CEDT.cxl | Bin 184 -> 184 bytes tests/qtest/bios-tables-test-allowed-diff.h | 1 - 2 files changed, 1 deletion(-)
tests/data/acpi/x86/q35/CEDT.cxl binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -1
@@ -1,2 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/x86/q35/CEDT.cxl",
Signature · 1 line
2.39.5
PATCH v2 4/5 hw/cxl: Add configurable CXL Fixed Memory Window restriction flags
In reply to Davidlohr BuesoExpose the CFMWS "Window Restrictions" (CXL r4.0 9.18.1.3) as named per-window machine properties -- device-coherent, host-only, volatile, persistent, fixed-config and back-invalidate -- so the advertised restrictions can be configured per window rather than left at the default.
No changes in default options. HDM-D and HDM-H are advertised by default; disabling one (device-coherent=off or host-only=off) narrows the window to the other. back-invalidate implies device-coherent (HDM-DB) and suppresses the host-only default. host-only coherent combined with back-invalidate is rejected as undefined behavior per the spec.
--- docs/system/devices/cxl.rst | 25 ++++++++++++-------- hw/acpi/cxl.c | 2 +- hw/cxl/cxl-host.c | 46 +++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl.h | 12 ++++++++++ qapi/machine.json | 28 ++++++++++++++++++++++ 5 files changed, 102 insertions(+), 11 deletions(-)
docs/system/devices/cxl.rst +15 -10
@@ -384,8 +384,13 @@ An example of 4 devices below a switch suitable for 1, 2 or 4 way interleave:: -device cxl-type3,bus=swport3,persistent-memdev=cxl-mem3,lsa=cxl-lsa3,id=cxl-pmem3,sn=0x4 \ -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=4k -An example of 4 type3 devices with volatile memory below a switch. Two of the devices -use HDM-DB for coherence, which requires operating in Flit mode:: +An example of a mixed configuration across two host bridges, each with its +own CXL window. Below cxl.1, two type3 volatile devices behind a switch use +HDM-DB for coherence, which requires operating in Flit mode and a window +that permits the device-coherent Back-Invalidate model. Below cxl.2, two +plain host-only devices are directly attached and use the default window. +Because a window targets a host bridge, giving each coherency model its own +bridge keeps the window-to-device mapping explicit:: qemu-system-x86_64 -M q35,cxl=on -m 4G,maxmem=8G,slots=8 -smp 4 \ ...
@@ -395,17 +400,17 @@ use HDM-DB for coherence, which requires operating in Flit mode:: -object memory-backend-ram,id=cxl-mem3,share=on,size=256M \ -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \ -device cxl-rp,port=0,bus=cxl.1,id=root_port0,chassis=0,slot=0 \ - -device cxl-rp,port=1,bus=cxl.1,id=root_port1,chassis=0,slot=1 \ -device cxl-upstream,bus=root_port0,id=us0,x-256b-flit=on \ -device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \ - -device cxl-type3,bus=swport0,volatile-memdev=cxl-mem0,id=cxl-mem0,sn=0x1,x-256b-flit=on,hdm-db=on \ + -device cxl-type3,bus=swport0,volatile-memdev=cxl-mem0,id=cxl-vmem0,sn=0x1,x-256b-flit=on,hdm-db=on \ -device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \ - -device cxl-type3,bus=swport1,volatile-memdev=cxl-mem1,id=cxl-mem1,sn=0x2,x-256b-flit=on,hdm-db=on \ - -device cxl-downstream,port=2,bus=us0,id=swport2,chassis=0,slot=6 \ - -device cxl-type3,bus=swport2,volatile-memdev=cxl-mem2,id=cxl-mem2,sn=0x3 \ - -device cxl-downstream,port=3,bus=us0,id=swport3,chassis=0,slot=7 \ - -device cxl-type3,bus=swport3,volatile-memdev=cxl-mem3,id=cxl-mem3,sn=0x4 \ - -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=4k + -device cxl-type3,bus=swport1,volatile-memdev=cxl-mem1,id=cxl-vmem1,sn=0x2,x-256b-flit=on,hdm-db=on \ + -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2 \ + -device cxl-rp,port=0,bus=cxl.2,id=root_port1,chassis=0,slot=6 \ + -device cxl-type3,bus=root_port1,volatile-memdev=cxl-mem2,id=cxl-vmem2,sn=0x3 \ + -device cxl-rp,port=1,bus=cxl.2,id=root_port2,chassis=0,slot=7 \ + -device cxl-type3,bus=root_port2,volatile-memdev=cxl-mem3,id=cxl-vmem3,sn=0x4 \ + -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=4k,cxl-fmw.0.back-invalidate=on,cxl-fmw.1.targets.0=cxl.2,cxl-fmw.1.size=4G,cxl-fmw.1.interleave-granularity=4k A simple arm/virt example featuring a single direct connected CXL Type 3 Volatile Memory device::
hw/acpi/cxl.c +1 -1
@@ -172,7 +172,7 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)build_append_int_noprefix (table_data, fw->enc_int_gran,4 );/* Window Restrictions */ -build_append_int_noprefix (table_data,0x0f ,2 ); +build_append_int_noprefix (table_data, fw->restrictions,2 );/* QTG ID */ build_append_int_noprefix (table_data,0 ,2 );
hw/cxl/cxl-host.c +46 -0
52 lines not on this page · raw message
include/hw/cxl/cxl.h +12 -0
@@ -27,6 +27,17 @@typedef struct PXBCXLDev PXBCXLDev ; +/* +* CEDT CFMWS "Window Restrictions" bits (CXL r4.0 9.18.1.3), advertising +* which capabilities the host bridges below this window support. +*/ +#define CXL_FMW_DEVICE_COHERENT (1 << 0)/* HDM-D */ +#define CXL_FMW_HOST_ONLY (1 << 1)/* HDM-H */ +#define CXL_FMW_VOLATILE (1 << 2) +#define CXL_FMW_PERSISTENT (1 << 3) +#define CXL_FMW_FIXED_CONFIG (1 << 4) +#define CXL_FMW_BI (1 << 5)/* HDM-DB, Back-Invalidate */ + typedef struct CXLFixedWindow { SysBusDevice parent_obj; int index;
@@ -36,6 +47,7 @@ typedef struct CXLFixedWindow {uint8_t num_targets;uint8_t enc_int_ways;uint8_t enc_int_gran; +uint16_t restrictions;/* Todo: XOR based interleaving */ MemoryRegion mr;hwaddr base;
qapi/machine.json +28 -0
@@ -551,15 +551,43 @@ # accesses will go to a given interleave target. Accepted values # [256, 512, 1k, 2k, 4k, 8k, 16k] # +# @device-coherent: Window permits device-coherent (minimally HDM-D) +# accesses. (since 11.1) +# +# @host-only: Window permits host-only coherent (HDM-H) accesses. +# (since 11.1) +# +# @volatile: Window permits volatile memory. (since 11.1) +# +# @persistent: Window permits persistent memory. (since 11.1) +# +# @fixed-config: Window has a fixed device configuration. Advertised +# in the CEDT only; not otherwise emulated. (since 11.1) +# +# @back-invalidate: Window permits Back-Invalidate (HDM-DB). Implies +# @device-coherent. (since 11.1) +# # @targets: Target root bridge IDs from -device ...,id=<ID> for each # root bridge. # +# Coherency defaults to both device-coherent and host-only; disabling +# one (host-only=off or device-coherent=off) narrows to the other. +# @back-invalidate implies device-coherent and is not host-only. +# @volatile and @persistent default on. host-only coherent combined +# with @back-invalidate is rejected as undefined behavior. +# # Since: 7.1 ## { 'struct': 'CXLFixedMemoryWindowOptions', 'data': { 'size': 'size', '*interleave-granularity': 'size', + '*device-coherent': 'bool', + '*host-only': 'bool', + '*volatile': 'bool', + '*persistent': 'bool', + '*fixed-config': 'bool', + '*back-invalidate': 'bool', 'targets': ['str'] }} ##
Signature · 1 line
2.39.5
PATCH v2 5/5 tests/qtest/cxl: Add CXL Fixed Memory Window restriction flag tests
In reply to Davidlohr BuesoAdd a /pci/cxl/cfmw group exercising the configurable CFMWS Window Restrictions.
--- tests/qtest/cxl-test.c | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
tests/qtest/cxl-test.c +95 -0
@@ -81,6 +81,13 @@"-object memory-backend-file,id=lsa3,mem-path=%s,size=256M " \"-device cxl-type3,bus=rp3,persistent-memdev=cxl-mem3,lsa=lsa3,id=pmem3 " +/* Single pxb + volatile type3 + one window; base for the CFMW tests. */ +#define QEMU_CFMW \ + "-machine q35,cxl=on " \ + "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " \ + QEMU_RP QEMU_T3D_VMEM \ + "-M cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.size=4G" +static void cxl_basic_hb (void ) {qtest_start ("-machine q35,cxl=on" );
@@ -117,6 +124,81 @@ static void cxl_2root_port(void)qtest_end (); } +/* +* CFMWS "Window Restrictions" (CXL r4.0 9.18.1.3) are configurable per +* window; check that valid restriction sets are accepted. +*/ +static void cxl_cfmw_default (void ) +{ +/* No coherency flag advertises both HDM-D and HDM-H. */ +qtest_start (QEMU_CFMW ); +qtest_end (); +} + +static void cxl_cfmw_host_only_off (void ) +{ +/* Disabling host-only leaves device-coherent (HDM-D). */ +qtest_start (QEMU_CFMW ",cxl-fmw.0.host-only=off" ); +qtest_end (); +} + +static void cxl_cfmw_device_coherent_off (void ) +{ +/* Disabling device-coherent leaves host-only (HDM-H). */ +qtest_start (QEMU_CFMW ",cxl-fmw.0.device-coherent=off" ); +qtest_end (); +} + +static void cxl_cfmw_back_invalidate (void ) +{ +/* Back-Invalidate implies device-coherent (HDM-DB). */ +qtest_start (QEMU_CFMW ",cxl-fmw.0.back-invalidate=on" ); +qtest_end (); +} + +static void cxl_cfmw_fixed_config (void ) +{ +qtest_start (QEMU_CFMW ",cxl-fmw.0.fixed-config=on" ); +qtest_end (); +} + +static void cxl_cfmw_device_and_host (void ) +{ +/* +* device-coherent and host-only may both be advertised (the spec +* permits multiple bits set); this must be accepted -- a regression +* guard against reinstating a device/host-only mutual exclusion. +*/ +qtest_start (QEMU_CFMW +",cxl-fmw.0.device-coherent=on,cxl-fmw.0.host-only=on" ); +qtest_end (); +} + +static void cxl_cfmw_volatile_only (void ) +{ +qtest_start (QEMU_CFMW ",cxl-fmw.0.persistent=off" ); +qtest_end (); +} + +static void cxl_cfmw_persistent_only (void ) +{ +qtest_start (QEMU_CFMW ",cxl-fmw.0.volatile=off" ); +qtest_end (); +} + +/* Two windows in one VM: a Back-Invalidate window and a host-only window. */ +static void cxl_cfmw_two_windows (void ) +{ +qtest_start ("-machine q35,cxl=on " +"-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " +"-device pxb-cxl,id=cxl.1,bus=pcie.0,bus_nr=53 " +QEMU_RP QEMU_T3D_VMEM +"-M cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.size=4G," +"cxl-fmw.0.back-invalidate=on," +"cxl-fmw.1.targets.0=cxl.1,cxl-fmw.1.size=4G" ); +qtest_end (); +} +#ifdef CONFIG_POSIX static void cxl_t3d_deprecated (void ) {
@@ -233,6 +315,19 @@ int main(int argc, char **argv)qtest_add_func ("/pci/cxl/pxb_x2_with_window" , cxl_2pxb_with_window);qtest_add_func ("/pci/cxl/rp" , cxl_root_port);qtest_add_func ("/pci/cxl/rp_x2" , cxl_2root_port); +qtest_add_func ("/pci/cxl/cfmw/default" , cxl_cfmw_default); +qtest_add_func ("/pci/cxl/cfmw/host_only_off" , cxl_cfmw_host_only_off); +qtest_add_func ("/pci/cxl/cfmw/device_coherent_off" , + cxl_cfmw_device_coherent_off); +qtest_add_func ("/pci/cxl/cfmw/back_invalidate" , + cxl_cfmw_back_invalidate); +qtest_add_func ("/pci/cxl/cfmw/fixed_config" , cxl_cfmw_fixed_config); +qtest_add_func ("/pci/cxl/cfmw/device_and_host" , + cxl_cfmw_device_and_host); +qtest_add_func ("/pci/cxl/cfmw/volatile_only" , cxl_cfmw_volatile_only); +qtest_add_func ("/pci/cxl/cfmw/persistent_only" , + cxl_cfmw_persistent_only); +qtest_add_func ("/pci/cxl/cfmw/two_windows" , cxl_cfmw_two_windows);#ifdef CONFIG_POSIX qtest_add_func ("/pci/cxl/type3_device" , cxl_t3d_deprecated);qtest_add_func ("/pci/cxl/type3_device_pmem" , cxl_t3d_persistent);
Signature · 1 line
2.39.5
bleh sorry, the cover letter subject should say -qemu.