Skip to content

Commit b8b9ffc

Browse files
committed
Merge branch 'for-6.3/cxl-ram-region' into cxl/next
Include the support for enumerating and provisioning ram regions for v6.3. This also include a default policy change for ram / volatile device-dax instances to assign them to the dax_kmem driver by default.
2 parents dfd423e + 09d09e0 commit b8b9ffc

File tree

29 files changed

+1488
-317
lines changed

29 files changed

+1488
-317
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Description:
198198

199199
What: /sys/bus/cxl/devices/endpointX/CDAT
200200
Date: July, 2022
201-
KernelVersion: v5.20
201+
KernelVersion: v6.0
202202
203203
Description:
204204
(RO) If this sysfs entry is not present no DOE mailbox was
@@ -209,7 +209,7 @@ Description:
209209

210210
What: /sys/bus/cxl/devices/decoderX.Y/mode
211211
Date: May, 2022
212-
KernelVersion: v5.20
212+
KernelVersion: v6.0
213213
214214
Description:
215215
(RW) When a CXL decoder is of devtype "cxl_decoder_endpoint" it
@@ -229,7 +229,7 @@ Description:
229229

230230
What: /sys/bus/cxl/devices/decoderX.Y/dpa_resource
231231
Date: May, 2022
232-
KernelVersion: v5.20
232+
KernelVersion: v6.0
233233
234234
Description:
235235
(RO) When a CXL decoder is of devtype "cxl_decoder_endpoint",
@@ -240,7 +240,7 @@ Description:
240240

241241
What: /sys/bus/cxl/devices/decoderX.Y/dpa_size
242242
Date: May, 2022
243-
KernelVersion: v5.20
243+
KernelVersion: v6.0
244244
245245
Description:
246246
(RW) When a CXL decoder is of devtype "cxl_decoder_endpoint" it
@@ -260,7 +260,7 @@ Description:
260260

261261
What: /sys/bus/cxl/devices/decoderX.Y/interleave_ways
262262
Date: May, 2022
263-
KernelVersion: v5.20
263+
KernelVersion: v6.0
264264
265265
Description:
266266
(RO) The number of targets across which this decoder's host
@@ -275,7 +275,7 @@ Description:
275275

276276
What: /sys/bus/cxl/devices/decoderX.Y/interleave_granularity
277277
Date: May, 2022
278-
KernelVersion: v5.20
278+
KernelVersion: v6.0
279279
280280
Description:
281281
(RO) The number of consecutive bytes of host physical address
@@ -285,25 +285,25 @@ Description:
285285
interleave_granularity).
286286

287287

288-
What: /sys/bus/cxl/devices/decoderX.Y/create_pmem_region
289-
Date: May, 2022
290-
KernelVersion: v5.20
288+
What: /sys/bus/cxl/devices/decoderX.Y/create_{pmem,ram}_region
289+
Date: May, 2022, January, 2023
290+
KernelVersion: v6.0 (pmem), v6.3 (ram)
291291
292292
Description:
293293
(RW) Write a string in the form 'regionZ' to start the process
294-
of defining a new persistent memory region (interleave-set)
295-
within the decode range bounded by root decoder 'decoderX.Y'.
296-
The value written must match the current value returned from
297-
reading this attribute. An atomic compare exchange operation is
298-
done on write to assign the requested id to a region and
299-
allocate the region-id for the next creation attempt. EBUSY is
300-
returned if the region name written does not match the current
301-
cached value.
294+
of defining a new persistent, or volatile memory region
295+
(interleave-set) within the decode range bounded by root decoder
296+
'decoderX.Y'. The value written must match the current value
297+
returned from reading this attribute. An atomic compare exchange
298+
operation is done on write to assign the requested id to a
299+
region and allocate the region-id for the next creation attempt.
300+
EBUSY is returned if the region name written does not match the
301+
current cached value.
302302

303303

304304
What: /sys/bus/cxl/devices/decoderX.Y/delete_region
305305
Date: May, 2022
306-
KernelVersion: v5.20
306+
KernelVersion: v6.0
307307
308308
Description:
309309
(WO) Write a string in the form 'regionZ' to delete that region,
@@ -312,17 +312,18 @@ Description:
312312

313313
What: /sys/bus/cxl/devices/regionZ/uuid
314314
Date: May, 2022
315-
KernelVersion: v5.20
315+
KernelVersion: v6.0
316316
317317
Description:
318318
(RW) Write a unique identifier for the region. This field must
319319
be set for persistent regions and it must not conflict with the
320-
UUID of another region.
320+
UUID of another region. For volatile ram regions this
321+
attribute is a read-only empty string.
321322

322323

323324
What: /sys/bus/cxl/devices/regionZ/interleave_granularity
324325
Date: May, 2022
325-
KernelVersion: v5.20
326+
KernelVersion: v6.0
326327
327328
Description:
328329
(RW) Set the number of consecutive bytes each device in the
@@ -333,7 +334,7 @@ Description:
333334

334335
What: /sys/bus/cxl/devices/regionZ/interleave_ways
335336
Date: May, 2022
336-
KernelVersion: v5.20
337+
KernelVersion: v6.0
337338
338339
Description:
339340
(RW) Configures the number of devices participating in the
@@ -343,7 +344,7 @@ Description:
343344

344345
What: /sys/bus/cxl/devices/regionZ/size
345346
Date: May, 2022
346-
KernelVersion: v5.20
347+
KernelVersion: v6.0
347348
348349
Description:
349350
(RW) System physical address space to be consumed by the region.
@@ -358,9 +359,20 @@ Description:
358359
results in the same address being allocated.
359360

360361

362+
What: /sys/bus/cxl/devices/regionZ/mode
363+
Date: January, 2023
364+
KernelVersion: v6.3
365+
366+
Description:
367+
(RO) The mode of a region is established at region creation time
368+
and dictates the mode of the endpoint decoder that comprise the
369+
region. For more details on the possible modes see
370+
/sys/bus/cxl/devices/decoderX.Y/mode
371+
372+
361373
What: /sys/bus/cxl/devices/regionZ/resource
362374
Date: May, 2022
363-
KernelVersion: v5.20
375+
KernelVersion: v6.0
364376
365377
Description:
366378
(RO) A region is a contiguous partition of a CXL root decoder
@@ -372,7 +384,7 @@ Description:
372384

373385
What: /sys/bus/cxl/devices/regionZ/target[0..N]
374386
Date: May, 2022
375-
KernelVersion: v5.20
387+
KernelVersion: v6.0
376388
377389
Description:
378390
(RW) Write an endpoint decoder object name to 'targetX' where X
@@ -391,7 +403,7 @@ Description:
391403

392404
What: /sys/bus/cxl/devices/regionZ/commit
393405
Date: May, 2022
394-
KernelVersion: v5.20
406+
KernelVersion: v6.0
395407
396408
Description:
397409
(RW) Write a boolean 'true' string value to this attribute to

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6034,6 +6034,7 @@ M: Dan Williams <[email protected]>
60346034
M: Vishal Verma <[email protected]>
60356035
M: Dave Jiang <[email protected]>
60366036
6037+
60376038
S: Supported
60386039
F: drivers/dax/
60396040

drivers/acpi/numa/hmat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static void hmat_register_target_devices(struct memory_target *target)
718718
for (res = target->memregions.child; res; res = res->sibling) {
719719
int target_nid = pxm_to_node(target->memory_pxm);
720720

721-
hmem_register_device(target_nid, res);
721+
hmem_register_resource(target_nid, res);
722722
}
723723
}
724724

@@ -869,4 +869,4 @@ static __init int hmat_init(void)
869869
acpi_put_table(tbl);
870870
return 0;
871871
}
872-
device_initcall(hmat_init);
872+
subsys_initcall(hmat_init);

drivers/cxl/Kconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,22 @@ config CXL_SUSPEND
104104
depends on SUSPEND && CXL_MEM
105105

106106
config CXL_REGION
107-
bool
107+
bool "CXL: Region Support"
108108
default CXL_BUS
109109
# For MAX_PHYSMEM_BITS
110110
depends on SPARSEMEM
111111
select MEMREGION
112112
select GET_FREE_REGION
113+
help
114+
Enable the CXL core to enumerate and provision CXL regions. A CXL
115+
region is defined by one or more CXL expanders that decode a given
116+
system-physical address range. For CXL regions established by
117+
platform-firmware this option enables memory error handling to
118+
identify the devices participating in a given interleaved memory
119+
range. Otherwise, platform-firmware managed CXL is enabled by being
120+
placed in the system address map and does not need a driver.
121+
122+
If unsure say 'y'
113123

114124
config CXL_REGION_INVALIDATION_TEST
115125
bool "CXL: Region Cache Management Bypass (TEST)"

drivers/cxl/acpi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ static void __exit cxl_acpi_exit(void)
731731
cxl_bus_drain();
732732
}
733733

734-
module_init(cxl_acpi_init);
734+
/* load before dax_hmem sees 'Soft Reserved' CXL ranges */
735+
subsys_initcall(cxl_acpi_init);
735736
module_exit(cxl_acpi_exit);
736737
MODULE_LICENSE("GPL v2");
737738
MODULE_IMPORT_NS(CXL);

drivers/cxl/core/core.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ extern struct attribute_group cxl_base_attribute_group;
1111

1212
#ifdef CONFIG_CXL_REGION
1313
extern struct device_attribute dev_attr_create_pmem_region;
14+
extern struct device_attribute dev_attr_create_ram_region;
1415
extern struct device_attribute dev_attr_delete_region;
1516
extern struct device_attribute dev_attr_region;
1617
extern const struct device_type cxl_pmem_region_type;
18+
extern const struct device_type cxl_dax_region_type;
1719
extern const struct device_type cxl_region_type;
1820
void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
1921
#define CXL_REGION_ATTR(x) (&dev_attr_##x.attr)
2022
#define CXL_REGION_TYPE(x) (&cxl_region_type)
2123
#define SET_CXL_REGION_ATTR(x) (&dev_attr_##x.attr),
2224
#define CXL_PMEM_REGION_TYPE(x) (&cxl_pmem_region_type)
25+
#define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type)
2326
int cxl_region_init(void);
2427
void cxl_region_exit(void);
2528
#else
@@ -37,6 +40,7 @@ static inline void cxl_region_exit(void)
3740
#define CXL_REGION_TYPE(x) NULL
3841
#define SET_CXL_REGION_ATTR(x)
3942
#define CXL_PMEM_REGION_TYPE(x) NULL
43+
#define CXL_DAX_REGION_TYPE(x) NULL
4044
#endif
4145

4246
struct cxl_send_command;
@@ -56,9 +60,6 @@ resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled);
5660
resource_size_t cxl_dpa_resource_start(struct cxl_endpoint_decoder *cxled);
5761
extern struct rw_semaphore cxl_dpa_rwsem;
5862

59-
bool is_switch_decoder(struct device *dev);
60-
struct cxl_switch_decoder *to_cxl_switch_decoder(struct device *dev);
61-
6263
int cxl_memdev_init(void);
6364
void cxl_memdev_exit(void);
6465
void cxl_mbox_init(void);

drivers/cxl/core/hdm.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
279279
return 0;
280280
}
281281

282-
static int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
282+
int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
283283
resource_size_t base, resource_size_t len,
284284
resource_size_t skipped)
285285
{
@@ -295,6 +295,7 @@ static int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
295295

296296
return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled);
297297
}
298+
EXPORT_SYMBOL_NS_GPL(devm_cxl_dpa_reserve, CXL);
298299

299300
resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled)
300301
{
@@ -676,6 +677,14 @@ static int cxl_decoder_reset(struct cxl_decoder *cxld)
676677
port->commit_end--;
677678
cxld->flags &= ~CXL_DECODER_F_ENABLE;
678679

680+
/* Userspace is now responsible for reconfiguring this decoder */
681+
if (is_endpoint_decoder(&cxld->dev)) {
682+
struct cxl_endpoint_decoder *cxled;
683+
684+
cxled = to_cxl_endpoint_decoder(&cxld->dev);
685+
cxled->state = CXL_DECODER_STATE_MANUAL;
686+
}
687+
679688
return 0;
680689
}
681690

@@ -783,6 +792,9 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
783792
return rc;
784793
}
785794
*dpa_base += dpa_size + skip;
795+
796+
cxled->state = CXL_DECODER_STATE_AUTO;
797+
786798
return 0;
787799
}
788800

@@ -826,7 +838,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
826838
cxled = cxl_endpoint_decoder_alloc(port);
827839
if (IS_ERR(cxled)) {
828840
dev_warn(&port->dev,
829-
"Failed to allocate the decoder\n");
841+
"Failed to allocate decoder%d.%d\n",
842+
port->id, i);
830843
return PTR_ERR(cxled);
831844
}
832845
cxld = &cxled->cxld;
@@ -836,21 +849,25 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
836849
cxlsd = cxl_switch_decoder_alloc(port, target_count);
837850
if (IS_ERR(cxlsd)) {
838851
dev_warn(&port->dev,
839-
"Failed to allocate the decoder\n");
852+
"Failed to allocate decoder%d.%d\n",
853+
port->id, i);
840854
return PTR_ERR(cxlsd);
841855
}
842856
cxld = &cxlsd->cxld;
843857
}
844858

845859
rc = init_hdm_decoder(port, cxld, target_map, hdm, i, &dpa_base);
846860
if (rc) {
861+
dev_warn(&port->dev,
862+
"Failed to initialize decoder%d.%d\n",
863+
port->id, i);
847864
put_device(&cxld->dev);
848865
return rc;
849866
}
850867
rc = add_hdm_decoder(port, cxld, target_map);
851868
if (rc) {
852869
dev_warn(&port->dev,
853-
"Failed to add decoder to port\n");
870+
"Failed to add decoder%d.%d\n", port->id, i);
854871
return rc;
855872
}
856873
}

drivers/cxl/core/memdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
246246
if (rc < 0)
247247
goto err;
248248
cxlmd->id = rc;
249+
cxlmd->depth = -1;
249250

250251
dev = &cxlmd->dev;
251252
device_initialize(dev);

drivers/cxl/core/pci.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds)
214214
return devm_add_action_or_reset(host, clear_mem_enable, cxlds);
215215
}
216216

217-
static bool range_contains(struct range *r1, struct range *r2)
218-
{
219-
return r1->start <= r2->start && r1->end >= r2->end;
220-
}
221-
222217
/* require dvsec ranges to be covered by a locked platform window */
223218
static int dvsec_range_allowed(struct device *dev, void *arg)
224219
{

0 commit comments

Comments
 (0)