Skip to content

Commit 2630b39

Browse files
committed
Merge branch 'for-6.7/cxl-committed' into cxl/next
Add the committed decoder sysfs attribute for v6.7.
2 parents 553ceb4 + 05e37b2 commit 2630b39

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ Description:
178178
hardware decoder target list.
179179

180180

181+
What: /sys/bus/cxl/devices/portX/decoders_committed
182+
Date: October, 2023
183+
KernelVersion: v6.7
184+
Contact: linux-cxl@vger.kernel.org
185+
Description:
186+
(RO) A memory device is considered active when any of its
187+
decoders are in the "committed" state (See CXL 3.0 8.2.4.19.7
188+
CXL HDM Decoder n Control Register). Hotplug and destructive
189+
operations like "sanitize" are blocked while device is actively
190+
decoding a Host Physical Address range. Note that this number
191+
may be elevated without any regionX objects active or even
192+
enumerated, as this may be due to decoders established by
193+
platform firwmare or a previous kernel (kexec).
194+
195+
181196
What: /sys/bus/cxl/devices/decoderX.Y
182197
Date: June, 2021
183198
KernelVersion: v5.14

drivers/cxl/core/hdm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,11 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
633633
if (cxld->flags & CXL_DECODER_F_ENABLE)
634634
return 0;
635635

636-
if (port->commit_end + 1 != id) {
636+
if (cxl_num_decoders_committed(port) != id) {
637637
dev_dbg(&port->dev,
638638
"%s: out of order commit, expected decoder%d.%d\n",
639-
dev_name(&cxld->dev), port->id, port->commit_end + 1);
639+
dev_name(&cxld->dev), port->id,
640+
cxl_num_decoders_committed(port));
640641
return -EBUSY;
641642
}
642643

@@ -853,7 +854,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
853854
cxld->target_type = CXL_DECODER_HOSTONLYMEM;
854855
else
855856
cxld->target_type = CXL_DECODER_DEVMEM;
856-
if (cxld->id != port->commit_end + 1) {
857+
if (cxld->id != cxl_num_decoders_committed(port)) {
857858
dev_warn(&port->dev,
858859
"decoder%d.%d: Committed out of order\n",
859860
port->id, cxld->id);

drivers/cxl/core/mbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)
12001200
* Require an endpoint to be safe otherwise the driver can not
12011201
* be sure that the device is unmapped.
12021202
*/
1203-
if (endpoint && endpoint->commit_end == -1)
1203+
if (endpoint && cxl_num_decoders_committed(endpoint) == 0)
12041204
rc = __cxl_mem_sanitize(mds, cmd);
12051205
else
12061206
rc = -EBUSY;

drivers/cxl/core/memdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
231231
if (rc)
232232
return rc;
233233

234-
if (port->commit_end == -1) {
234+
if (cxl_num_decoders_committed(port) == 0) {
235235
/* No regions mapped to this memdev */
236236
rc = cxl_get_poison_by_memdev(cxlmd);
237237
} else {
@@ -282,7 +282,7 @@ static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa)
282282
.dpa = dpa,
283283
};
284284
port = cxlmd->endpoint;
285-
if (port && is_cxl_endpoint(port) && port->commit_end != -1)
285+
if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
286286
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
287287

288288
return ctx.cxlr;

drivers/cxl/core/port.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ DECLARE_RWSEM(cxl_region_rwsem);
3737
static DEFINE_IDA(cxl_port_ida);
3838
static DEFINE_XARRAY(cxl_root_buses);
3939

40+
int cxl_num_decoders_committed(struct cxl_port *port)
41+
{
42+
lockdep_assert_held(&cxl_region_rwsem);
43+
44+
return port->commit_end + 1;
45+
}
46+
4047
static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
4148
char *buf)
4249
{
@@ -537,8 +544,33 @@ static void cxl_port_release(struct device *dev)
537544
kfree(port);
538545
}
539546

547+
static ssize_t decoders_committed_show(struct device *dev,
548+
struct device_attribute *attr, char *buf)
549+
{
550+
struct cxl_port *port = to_cxl_port(dev);
551+
int rc;
552+
553+
down_read(&cxl_region_rwsem);
554+
rc = sysfs_emit(buf, "%d\n", cxl_num_decoders_committed(port));
555+
up_read(&cxl_region_rwsem);
556+
557+
return rc;
558+
}
559+
560+
static DEVICE_ATTR_RO(decoders_committed);
561+
562+
static struct attribute *cxl_port_attrs[] = {
563+
&dev_attr_decoders_committed.attr,
564+
NULL,
565+
};
566+
567+
static struct attribute_group cxl_port_attribute_group = {
568+
.attrs = cxl_port_attrs,
569+
};
570+
540571
static const struct attribute_group *cxl_port_attribute_groups[] = {
541572
&cxl_base_attribute_group,
573+
&cxl_port_attribute_group,
542574
NULL,
543575
};
544576

drivers/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ static inline bool is_cxl_root(struct cxl_port *port)
689689
return port->uport_dev == port->dev.parent;
690690
}
691691

692+
int cxl_num_decoders_committed(struct cxl_port *port);
692693
bool is_cxl_port(const struct device *dev);
693694
struct cxl_port *to_cxl_port(const struct device *dev);
694695
struct pci_bus;

0 commit comments

Comments
 (0)