> > > An example of creating a new region: > > > > > > - Allocate a new region name: > > > region=$(cat /sys/bus/cxl/devices/decoder0.0/create_pmem_region) > > > > > > - Create a new region by name: > > > while > > > region=$(cat /sys/bus/cxl/devices/decoder0.0/create_pmem_region) > > > > Perhaps it is worth calling out the region ID allocator is shared > > with nvdimms and other usecases. I'm not really sure what the advantage > > in doing that is, but it doesn't do any real harm. > > The rationale is that there are several producers of memory regions > nvdimm, device-dax (hmem), and now cxl. Of those cases cxl can pass > regoins to nvdimm and nvdimm can pass regions to device-dax (pmem). If > each of those cases allocated their own region-id it would just > complicate debug for no benefit. I can add this a note to remind why > memregion_alloc() was introduced in the first instance. > > > > > > ! echo $region > /sys/bus/cxl/devices/decoder0.0/create_pmem_region > > > do true; done > > I recall you also asked to clarify the rationale of this complexity. It > is related to the potential proliferation of disaparate region ids, but > also a lesson learned from nvdimm which itself learned lessons from > md-raid. The lesson from md-raid in short is do not use ioctl for object > creation. After "not ioctl" the choice is configfs or a small bit of > sysfs hackery. Configfs is overkill when there is already a sysfs > hierarchy that just needs one new object injected. > > Namespace creation in nvdimm pre-created "seed" devices which let the > kernel control the naming, but confused end users that wondered about > vestigial devices. This "read to learn next object name" + "write to > atomically claim and instantiate that id" cleans up that vestigial > device problem while also constraining object naming to follow memregion > id expectations. Ok. Makes sense to me now. Thanks! > > > diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h > > > index 472ec9cb1018..ebe6197fb9b8 100644 > > > --- a/drivers/cxl/core/core.h > > > +++ b/drivers/cxl/core/core.h > > > @@ -9,6 +9,18 @@ extern const struct device_type cxl_nvdimm_type; > > > > > > extern struct attribute_group cxl_base_attribute_group; > > > > > > +#ifdef CONFIG_CXL_REGION > > > +extern struct device_attribute dev_attr_create_pmem_region; > > > +extern struct device_attribute dev_attr_delete_region; > > > +/* > > > + * Note must be used at the end of an attribute list, since it > > > + * terminates the list in the CONFIG_CXL_REGION=n case. > > > > That's rather ugly. Maybe just push the ifdef down into the c file > > where we will be shortening the list and it should be obvious what is > > going on without needing the comment? Much as I don't like ifdef > > magic in the c files, it sometimes ends up cleaner. > > No, I think ifdef in C is definitely uglier, but I also notice that > helpers like SET_SYSTEM_SLEEP_PM_OPS() are defined to be used in any > place in the list. So, I'll just duplicate that approach. Ah. That's better, though has that odd quirk of no trailing comma where the macro is called which always makes me look twice! Guess looking twice is better than not looking at all though :) Thanks, Jonathan