Message ID | 169747907439.272156.10261062080830155662.stgit@djiang5-mobl3 |
---|---|
State | Accepted |
Commit | 05e37b2138a6deb1f23daf1282dc86b29968a1ab |
Headers | show |
Series | [v3,1/2] cxl: Add cxl_decoders_committed() helper | expand |
On Mon, 16 Oct 2023 10:57:54 -0700 Dave Jiang <dave.jiang@intel.com> wrote: > This attribute allows cxl-cli to determine whether there are decoders > committed to a memdev. This is only a snapshot of the state, and > doesn't offer any protection or serialization against a concurrent > disable-region operation. > > Reviewed-by: Jim Harris <jim.harris@samsung.com> > Suggested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Dave Jiang <dave.jiang@intel.com> Seems reasonable, but it is adding ABI so the docs are missing. Documentation/ABI/testing/sysfs-bus-cxl > --- > v2: > - Use cxl_region_rwsem to protect reading of decoder info. (Dan) > --- > drivers/cxl/core/port.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c > index d0ed98a6bade..0adee1e406ec 100644 > --- a/drivers/cxl/core/port.c > +++ b/drivers/cxl/core/port.c > @@ -534,8 +534,33 @@ static void cxl_port_release(struct device *dev) > kfree(port); > } > > +static ssize_t decoders_committed_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct cxl_port *port = to_cxl_port(dev); > + int rc; > + > + down_read(&cxl_region_rwsem); > + rc = sysfs_emit(buf, "%d\n", cxl_num_decoders_committed(port)); > + up_read(&cxl_region_rwsem); > + > + return rc; > +} > + > +static DEVICE_ATTR_RO(decoders_committed); > + > +static struct attribute *cxl_port_attrs[] = { > + &dev_attr_decoders_committed.attr, > + NULL, > +}; > + > +static struct attribute_group cxl_port_attribute_group = { > + .attrs = cxl_port_attrs, > +}; > + > static const struct attribute_group *cxl_port_attribute_groups[] = { > &cxl_base_attribute_group, > + &cxl_port_attribute_group, > NULL, > }; > > > >
Jonathan Cameron wrote: > On Mon, 16 Oct 2023 10:57:54 -0700 > Dave Jiang <dave.jiang@intel.com> wrote: > > > This attribute allows cxl-cli to determine whether there are decoders > > committed to a memdev. This is only a snapshot of the state, and > > doesn't offer any protection or serialization against a concurrent > > disable-region operation. > > > > Reviewed-by: Jim Harris <jim.harris@samsung.com> > > Suggested-by: Dan Williams <dan.j.williams@intel.com> > > Signed-off-by: Dave Jiang <dave.jiang@intel.com> > Seems reasonable, but it is adding ABI so the docs are missing. > Documentation/ABI/testing/sysfs-bus-cxl Agreed, folded in the following: diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 087f762ebfd5..432610f41aee 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -178,6 +178,21 @@ Description: hardware decoder target list. +What: /sys/bus/cxl/devices/portX/decoders_committed +Date: October, 2023 +KernelVersion: v6.7 +Contact: linux-cxl@vger.kernel.org +Description: + (RO) A memory device is considered active when any of its + decoders are in the "committed" state (See CXL 3.0 8.2.4.19.7 + CXL HDM Decoder n Control Register). Hotplug and destructive + operations like "sanitize" are blocked while device is actively + decoding a Host Physical Address range. Note that this number + may be elevated without any regionX objects active or even + enumerated, as this may be due to decoders established by + platform firwmare or a previous kernel (kexec). + + What: /sys/bus/cxl/devices/decoderX.Y Date: June, 2021 KernelVersion: v5.14
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index d0ed98a6bade..0adee1e406ec 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -534,8 +534,33 @@ static void cxl_port_release(struct device *dev) kfree(port); } +static ssize_t decoders_committed_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cxl_port *port = to_cxl_port(dev); + int rc; + + down_read(&cxl_region_rwsem); + rc = sysfs_emit(buf, "%d\n", cxl_num_decoders_committed(port)); + up_read(&cxl_region_rwsem); + + return rc; +} + +static DEVICE_ATTR_RO(decoders_committed); + +static struct attribute *cxl_port_attrs[] = { + &dev_attr_decoders_committed.attr, + NULL, +}; + +static struct attribute_group cxl_port_attribute_group = { + .attrs = cxl_port_attrs, +}; + static const struct attribute_group *cxl_port_attribute_groups[] = { &cxl_base_attribute_group, + &cxl_port_attribute_group, NULL, };