A few minor things inline from a fresh read. Other than maybe a missing header, the others are all trivial and you can make your own minds up. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxx> > #endif /* __CXL_CORE_H__ */ > diff --git a/drivers/cxl/core/extent.c b/drivers/cxl/core/extent.c > new file mode 100644 > index 0000000000000000000000000000000000000000..315aa46252c15dcefe175da87522505f8ecf537c > --- /dev/null > +++ b/drivers/cxl/core/extent.c > @@ -0,0 +1,372 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ > + > +#include <linux/device.h> > +#include <cxl.h> > +static bool extents_contain(struct cxl_dax_region *cxlr_dax, > + struct cxl_endpoint_decoder *cxled, > + struct range *new_range) > +{ > + struct match_data md = { > + .cxled = cxled, > + .new_range = new_range, > + }; > + > + struct device *extent_device __free(put_device) > + = device_find_child(&cxlr_dax->dev, &md, match_contains); > + if (!extent_device) > + return false; > + > + return true; trivial but could do. return extent_device != NULL; > +} > +static bool extents_overlap(struct cxl_dax_region *cxlr_dax, > + struct cxl_endpoint_decoder *cxled, > + struct range *new_range) > +{ > + struct match_data md = { > + .cxled = cxled, > + .new_range = new_range, > + }; > + > + struct device *extent_device __free(put_device) > + = device_find_child(&cxlr_dax->dev, &md, match_overlaps); > + if (!extent_device) > + return false; > + > + return true; As above. > +} > +static int cxlr_rm_extent(struct device *dev, void *data) > +{ > + struct region_extent *region_extent = to_region_extent(dev); > + struct range *region_hpa_range = data; > + > + if (!region_extent) > + return 0; > + > + /* > + * Any extent which 'touches' the released range is removed. Maybe single line comment syntax is fine here. > + */ > + if (range_overlaps(region_hpa_range, ®ion_extent->hpa_range)) { > + dev_dbg(dev, "Remove region extent HPA [range 0x%016llx-0x%016llx]\n", > + region_extent->hpa_range.start, region_extent->hpa_range.end); > + region_rm_extent(region_extent); > + } > + return 0; > +} > +/* Callers are expected to ensure cxled has been attached to a region */ > +int cxl_add_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent) > +{ > + u64 start_dpa = le64_to_cpu(extent->start_dpa); > + struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; > + struct cxl_endpoint_decoder *cxled; > + struct range ed_range, ext_range; > + struct cxl_dax_region *cxlr_dax; > + struct cxled_extent *ed_extent; > + struct cxl_region *cxlr; > + struct device *dev; > + > + ext_range = (struct range) { > + .start = start_dpa, > + .end = start_dpa + le64_to_cpu(extent->length) - 1, > + }; > + > > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h > index 16e06b59d7f04762ca73a81740b0d6b2487301af..85b30a74a6fa5de1dd99c08c8318edd204e3e19d 100644 > --- a/drivers/cxl/cxlmem.h > +++ b/drivers/cxl/cxlmem.h Is the xarray header included in here already? If not it should be. > @@ -506,6 +506,7 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox) > * @pmem_perf: performance data entry matched to PMEM partition > * @nr_dc_region: number of DC regions implemented in the memory device > * @dc_region: array containing info about the DC regions