All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] cxl: Initial support for Back-Invalidate
@ 2025-08-12  1:02 Davidlohr Bueso
  2025-08-12  1:02 ` [PATCH 1/3] cxl/pci: Back-Invalidate device discovery and setup Davidlohr Bueso
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Davidlohr Bueso @ 2025-08-12  1:02 UTC (permalink / raw)
  To: dave.jiang, dan.j.williams
  Cc: jonathan.cameron, ira.weiny, alison.schofield, alucerop,
	a.manzanares, anisa.su, linux-cxl, dave

Hello,

The following is some initial plumbing to enabling HDM-DB in Linux. This model allows devices,
specifically 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 last year's LPC type2 support session,
this series takes the type3 memory expander approach, which is more direct.

While this is an early RFC and I'm sure many thoughts, the next phase of this would be to
integrate Bi with Alejandro's Type2 work as well as with Jonathan's Cache Coherency subsystem
series (aka memregion inv)... this might be a good topic for the upcoming LPC's devmem session:
	https://lore.kernel.org/linux-cxl/20250624141355.269056-1-alejandro.lucero-palau@amd.com
	https://lore.kernel.org/linux-cxl/20250624154805.66985-1-Jonathan.Cameron@huawei.com

o Patch 1 adds the BI cachemem register discovery along with two interfaces around cxlds to allow
the setup and deallocations of BI-IDs. The idea is for type3 memdevs and future type2 devices
to make use of cxlds->bi when committing HDM decoders, such that different device coherence models
can be differentiated as:

	type2 hdm-db: cxlds->type == CXL_DEVTYPE_DEVMEM && cxlds->bi == true
	type2 hdm-d:  cxlds->type == CXL_DEVTYPE_DEVMEM && cxlds->bi == false
	type3 hdm-h:  cxlds->type == CXL_DEVTYPE_CLASSMEM && cxlds->bi == false
	type3 hdm-db: cxlds->type == CXL_DEVTYPE_CLASSMEM && cxlds->bi == true
	
Because ->bi becoming true does not depend on auto-committing upon HDM decoder port/enumeration
(port driver), for now this is set as unsupported and will error out when initializing the HDM
decoder that has its BI bit set.

o Patch 2 renames/updates some of the CXL Window coherency restrictions. This should be picked
up regardless as the spec has been updated already.

o Patch 3 deals with the HDM decoder programming changes around whether or not to set the
BI bit. Based on the model above, decoder target types are straightforward: DEVMEM or HOSTONLY
for type2 and regular type3, but for type3 HDM-DB, this is not as clear, for which this patch
will 1) rely on the HDM capability for supporting coherence models, and 2) allow, when possible,
to change it by the user when configuring the BI-capable HDM decoder. It gives the user sysfs
tools to create BI-enabled memory regions (see testing below).

Testing has been done with the qemu hdm-db type3 counterpart:
	https://lore.kernel.org/linux-cxl/20250806055708.196851-1-dave@stgolabs.net/

1. BI discovery + BI-ID setup flow.
----------------------------------
i. 1 direct attached + 1 regular (hdm-h)
-+-[0000:00]-+-00.0
 |           +-01.0
 |           +-02.0
 |           +-03.0
 |           +-1f.0
 |           +-1f.2
 |           \-1f.3
 \-[0000:0c]-+-00.0-[0d]----00.0
             \-01.0-[0e]----00.0

[    0.799322] cxl_core:cxl_probe_component_regs:102: pci 0000:0c:00.0: found BI Decoder capability (0xab4)
[    0.805787] cxl_core:cxl_probe_component_regs:102: pci 0000:0c:01.0: found BI Decoder capability (0xab4)
[    1.862826] cxl_core:cxl_probe_component_regs:102: cxl_pci 0000:0d:00.0: found BI Decoder capability (0xab4)
[    1.944015] cxl_core:__cxl_is_bi_capable:1115: cxl_pci 0000:0e:00.0: No BI Decoder registers.
[    1.994400] cxl_core:__cxl_bi_decoder_endpoint_enable:1279: cxl_pci 0000:0d:00.0: device capable of issuing BI requests

ii. 4 attached hdm-db to a 4x switch under the rp
-+-[0000:00]-+-00.0
 |           +-01.0
 |           +-02.0
 |           +-03.0
 |           +-1f.0
 |           +-1f.2
 |           \-1f.3
 \-[0000:0c]-+-00.0-[0d-12]----00.0-[0e-12]--+-00.0-[0f]----00.0
             |                               +-01.0-[10]----00.0
             |                               +-02.0-[11]----00.0
             |                               \-03.0-[12]----00.0
             \-01.0-[13]--

[    1.866181] cxl_core:cxl_probe_component_regs:102: cxl_pci 0000:10:00.0: found BI Decoder capability (0xab4)
[    1.871194] cxl_core:cxl_probe_component_regs:102: cxl_pci 0000:0f:00.0: found BI Decoder capability (0xab4)
[    1.891820] cxl_core:cxl_probe_component_regs:96: cxl port2: found BI RT capability (0xaa8)
[    1.896952] cxl_core:cxl_probe_component_regs:102: pcieport 0000:0e:00.0: found BI Decoder capability (0xab4)
[    1.897578] cxl_core:cxl_probe_component_regs:102: pcieport 0000:0e:01.0: found BI Decoder capability (0xab4)
[    1.906578] cxl_core:cxl_probe_component_regs:102: pcieport 0000:0e:02.0: found BI Decoder capability (0xab4)
[    2.036098] cxl_core:cxl_probe_component_regs:102: pcieport 0000:0e:03.0: found BI Decoder capability (0xab4)
[    3.740107] cxl_core:__cxl_bi_commit:1180: pcieport 0000:0e:03.0: BI-ID commit wait took 212059us
[    3.944239] cxl_core:__cxl_bi_commit_rt:1170: cxl_port port2: BI-ID commit wait took 202985us
[    3.950446] cxl_core:__cxl_bi_decoder_endpoint_enable:1278: cxl_pci 0000:12:00.0: device capable of issuing BI requests
[    4.192058] cxl_core:__cxl_bi_commit:1180: pcieport 0000:0e:02.0: BI-ID commit wait took 207341us
[    4.400570] cxl_core:__cxl_bi_commit_rt:1170: cxl_port port2: BI-ID commit wait took 207559us
[    4.411170] cxl_core:__cxl_bi_decoder_endpoint_enable:1278: cxl_pci 0000:11:00.0: device capable of issuing BI requests
[    4.664350] cxl_core:__cxl_bi_commit:1180: pcieport 0000:0e:01.0: BI-ID commit wait took 205648us
[    4.872299] cxl_core:__cxl_bi_commit_rt:1170: cxl_port port2: BI-ID commit wait took 204156us
[    4.884823] cxl_core:__cxl_bi_decoder_endpoint_enable:1278: cxl_pci 0000:10:00.0: device capable of issuing BI requests
[    5.128481] cxl_core:__cxl_bi_commit:1180: pcieport 0000:0e:00.0: BI-ID commit wait took 203259us
[    5.336216] cxl_core:__cxl_bi_commit_rt:1170: cxl_port port2: BI-ID commit wait took 204688us
[    5.341730] cxl_core:__cxl_bi_decoder_endpoint_enable:1278: cxl_pci 0000:0f:00.0: device capable of issuing BI requests

# echo 1 > /sys/bus/pci/devices/0000\:0f\:00.0/remove
[   52.280098] cxl_core:__cxl_bi_commit:1180: pcieport 0000:0e:00.0: BI-ID commit wait took 204661us
[   52.488101] cxl_core:__cxl_bi_commit_rt:1170: cxl_port port2: BI-ID commit wait took 206595us
[   52.497619] cxl_core:cxl_detach_ep:1500: cxl_mem mem0: disconnect mem0 from port2
[   52.500290] cxl_core:cxl_detach_ep:1500: cxl_mem mem0: disconnect mem0 from port1

2. HDM Decoder with BI through ad-hoc region creation.
------------------------------------------------------
# cxl list -D
[
  {
    "decoder":"decoder0.0",
    "resource":4563402752,
    "size":10737418240,
    "interleave_ways":1,
    "max_available_extent":10737418240,
    "pmem_capable":true,
    "volatile_capable":true,
    "accelmem_capable":true,
    "nr_targets":1
  }
]

Program the endpoint decoder
# echo ram > /sys/bus/cxl/devices/decoder2.0/mode
# echo 1 > /sys/bus/cxl/devices/decoder2.0/bi
# echo 0x40000000 > /sys/bus/cxl/devices/decoder2.0/dpa_size

Create a region in the root decoder
# echo region0 > /sys/bus/cxl/devices/decoder0.0/create_ram_bi_region
[  154.073077] cxl_core:cxl_region_can_probe:3588: cxl_region region0: config state: 0
[  154.073495] cxl_core:cxl_bus_probe:2125: cxl_region region0: probe: -6
[  154.073939] cxl_core:devm_cxl_add_region:2563: cxl_acpi ACPI0017:00: decoder0.0: created region0

Configure the region with the same IG, IW the root and endpoint decoders
# echo 256 > /sys/bus/cxl/devices/region0/interleave_granularity
# echo 1 > /sys/bus/cxl/devices/region0/interleave_ways
# echo 0x40000000 > /sys/bus/cxl/devices/region0/size
 
Link the endpoint decoder as a target in the region
# echo decoder2.0 > /sys/bus/cxl/devices/region0/target0
[  177.351922] cxl_core:cxl_port_attach_region:1174: cxl region0: mem0:endpoint2 decoder2.0 add: mem0:decoder2.0 @ 0 next: none nr_eps: 1 nr_targets: 1
[  177.353539] cxl_core:cxl_port_attach_region:1174: cxl region0: pci0000:0c:port1 decoder1.0 add: mem0:decoder2.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1
[  177.354133] cxl_core:cxl_port_setup_targets:1494: cxl region0: pci0000:0c:port1 iw: 1 ig: 256
[  177.354508] cxl_core:cxl_port_setup_targets:1518: cxl region0: pci0000:0c:port1 target[0] = 0000:0c:00.0 for mem0:decoder2.0 @ 0
[  177.355182] cxl_core:cxl_calc_interleave_pos:1885: cxl_mem mem0: decoder:decoder2.0 parent:0000:0d:00.0 port:endpoint2 range:0x120000000-0x15fffffff pos:0
[  177.355793] cxl_core:cxl_region_attach:2087: cxl decoder2.0: Test cxl_calc_interleave_pos(): success test_pos:0 cxled->pos:0

Commit the changes
# echo 1 > /sys/bus/cxl/devices/region0/commit
[  183.126515] cxl region0: Bypassing cpu_cache_invalidate_memregion() for testing!
non interleaved decoder 120000000 40000000 0
non interleaved decoder 120000000 40000000 0

# cxl list -D (tooling still needs updated to show decoder target type)
[
  {
    "root decoders":[
      {
        "decoder":"decoder0.0",
        "resource":4563402752,
        "size":10737418240,
        "interleave_ways":1,
        "max_available_extent":9395240960,
        "pmem_capable":true,
        "volatile_capable":true,
        "accelmem_capable":true,
        "nr_targets":1
      }
    ]
  },
  {
    "port decoders":[
      {
        "decoder":"decoder1.0",
        "resource":4831838208,
        "size":1073741824,
        "interleave_ways":1,
        "region":"region0",
        "nr_targets":1
      }
    ]
  },
  {
    "endpoint decoders":[
      {
        "decoder":"decoder2.0",
        "resource":4831838208,
        "size":1073741824,
        "interleave_ways":1,
        "region":"region0",
        "dpa_resource":0,
        "dpa_size":1073741824,
        "mode":"ram"
      }
    ]
  }
]

ii. On a type3 HDM-DB volatile device, create one BI and one regular region.
# echo ram > /sys/bus/cxl/devices/decoder2.0/mode
# echo 1 > /sys/bus/cxl/devices/decoder2.0/bi
# echo 0x20000000 > /sys/bus/cxl/devices/decoder2.0/dpa_size
# echo region0 > /sys/bus/cxl/devices/decoder0.0/create_ram_bi_region
# echo 256 > /sys/bus/cxl/devices/region0/interleave_granularity
# echo 1 > /sys/bus/cxl/devices/region0/interleave_ways
# echo 0x20000000 > /sys/bus/cxl/devices/region0/size
# echo decoder2.0 > /sys/bus/cxl/devices/region0/target0
# echo 1 > /sys/bus/cxl/devices/region0/commit

# echo ram > /sys/bus/cxl/devices/decoder2.1/mode
# echo 0 > /sys/bus/cxl/devices/decoder2.1/bi (this is already the default)
# echo 0x20000000 > /sys/bus/cxl/devices/decoder2.1/dpa_size
# echo region0 > /sys/bus/cxl/devices/decoder0.0/create_ram_region
# echo 256 > /sys/bus/cxl/devices/region1/interleave_granularity
# echo 1 > /sys/bus/cxl/devices/region1/interleave_ways
# echo 0x20000000 > /sys/bus/cxl/devices/region1/size
# echo decoder2.1 > /sys/bus/cxl/devices/region1/target0
# echo 1 > /sys/bus/cxl/devices/region1/commit

# cxl list -D
[
  {
    "root decoders":[
      {
        "decoder":"decoder0.0",
        "resource":4563402752,
        "size":10737418240,
        "interleave_ways":1,
        "max_available_extent":9395240960,
        "pmem_capable":true,
        "volatile_capable":true,
        "accelmem_capable":true,
        "nr_targets":1
      }
    ]
  },
  {
    "port decoders":[
      {
        "decoder":"decoder1.0",
        "resource":4831838208,
        "size":536870912,
        "interleave_ways":1,
        "region":"region0",
        "nr_targets":1
      },
      {
        "decoder":"decoder1.1",
        "resource":5368709120,
        "size":536870912,
        "interleave_ways":1,
        "region":"region1",
        "nr_targets":1
      }
    ]
  },
  {
    "endpoint decoders":[
      {
        "decoder":"decoder2.0",
        "resource":4831838208,
        "size":536870912,
        "interleave_ways":1,
        "region":"region0",
        "dpa_resource":0,
        "dpa_size":536870912,
        "mode":"ram"
      },
      {
        "decoder":"decoder2.1",
        "resource":5368709120,
        "size":536870912,
        "interleave_ways":1,
        "region":"region1",
        "dpa_resource":536870912,
        "dpa_size":536870912,
        "mode":"ram"
      }
    ]
  }
]

iii. Detect mismatch between decoder and region types.
[  217.911488] cxl_core:cxl_region_attach:1977: cxl region1: mem0:decoder2.0 type mismatch: 2 vs 3
[   23.269994] cxl_core:cxl_region_attach:1987: cxl region0: mem0:decoder2.0 type mismatch: 3 vs 2 (no HDM-DB device)

Applies against the 'next' branch of cxl.git.

Thanks!

Davidlohr Bueso (3):
  cxl/pci: Back-Invalidate device discovery and setup
  acpi, tables: Rename coherency CFMW restrictions
  cxl: Support creating HDM-DB regions

 Documentation/ABI/testing/sysfs-bus-cxl |  41 ++-
 drivers/cxl/acpi.c                      |   6 +-
 drivers/cxl/core/core.h                 |   4 +
 drivers/cxl/core/hdm.c                  |  56 ++++-
 drivers/cxl/core/pci.c                  | 318 ++++++++++++++++++++++++
 drivers/cxl/core/port.c                 |  57 ++++-
 drivers/cxl/core/region.c               |  57 ++++-
 drivers/cxl/core/regs.c                 |  13 +
 drivers/cxl/cxl.h                       |  47 +++-
 drivers/cxl/cxlmem.h                    |   3 +
 drivers/cxl/mem.c                       |   2 +
 drivers/cxl/pci.c                       |   5 +
 drivers/cxl/port.c                      |  67 +++++
 include/acpi/actbl1.h                   |   5 +-
 tools/testing/cxl/test/cxl.c            |  18 +-
 15 files changed, 661 insertions(+), 38 deletions(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-15 15:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  1:02 [PATCH RFC 0/3] cxl: Initial support for Back-Invalidate Davidlohr Bueso
2025-08-12  1:02 ` [PATCH 1/3] cxl/pci: Back-Invalidate device discovery and setup Davidlohr Bueso
2025-08-15 15:20   ` Jonathan Cameron
2025-08-12  1:02 ` [PATCH 2/3] acpi, tables: Rename coherency CFMW restrictions Davidlohr Bueso
2025-08-15 15:27   ` Jonathan Cameron
2025-08-12  1:02 ` [PATCH 3/3] cxl: Support creating HDM-DB regions Davidlohr Bueso
2025-08-15 15:41   ` Jonathan Cameron
2025-08-12 14:53 ` [PATCH RFC 0/3] cxl: Initial support for Back-Invalidate Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.