Skip to contentSkip to conversation

cxl: Dirty shutdown followups

PATCH Superseded Davidlohr Bueso 5 participants 17 messages Feb 20, 2025 – Feb 21, 2025

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Davidlohr Bueso

author maintainer
#0 lore raw

v4 cover cxl: Dirty shutdown followups

Changes from v3 (https://lore.kernel.org/linux-cxl/[email protected]/):
- pickup reviews
- simplify patch 1 (DaveJ)
- change -1 to ULLONG_MAX in patch 3 (Ira)
- patch 4 replace int for u8 for shutdown state (DaveJ)

Hi,

Some followup patches to the GPF work. First two patches are from feedback provided by DaveJ. The third patch adds a $platform/dirty_shutdown sysfs attribute to expose the count to userspace. Fourth patch adds support emulating the set shutdown state command for the mock device.

Applies against the -next branch of cxl.git.

Thanks!

Davidlohr Bueso (4):
cxl/pci: Introduce cxl_gpf_get_dvsec()
cxl/pmem: Rename cxl_dirty_shutdown_state()
cxl/pmem: Export dirty shutdown count via sysfs
tools/testing/cxl: Set Shutdown State support

 Documentation/ABI/testing/sysfs-bus-cxl       | 12 +++
 Documentation/driver-api/cxl/maturity-map.rst |  2 +-
 drivers/cxl/core/mbox.c                       | 25 +++++-
 drivers/cxl/core/pci.c                        | 30 ++++---
 drivers/cxl/cxl.h                             |  3 +
 drivers/cxl/cxlmem.h                          | 15 +++-
 drivers/cxl/pmem.c                            | 79 ++++++++++++++++---
 tools/testing/cxl/test/mem.c                  | 23 ++++++
 8 files changed, 166 insertions(+), 23 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH v4 1/4 cxl/pci: Introduce cxl_gpf_get_dvsec()

Add a helper to fetch the port/device GPF dvsecs. This is currently only used for ports, but a later patch to export dirty count to users will make use of the device one.

---
 drivers/cxl/core/pci.c | 30 ++++++++++++++++++++----------
 drivers/cxl/cxl.h      |  2 ++
 2 files changed, 22 insertions(+), 10 deletions(-)
drivers/cxl/core/pci.c +20 -10
index a5c65f79db18..96fecb799cbc 100644
@@ -1072,6 +1072,22 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
 #define GPF_TIMEOUT_BASE_MAX 2
 #define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port)
+{
+	u16 dvsec;
+
+	if (!dev_is_pci(dev))
+		return 0;
+
+	dvsec = pci_find_dvsec_capability(to_pci_dev(dev), PCI_VENDOR_ID_CXL,
+			is_port ? CXL_DVSEC_PORT_GPF : CXL_DVSEC_DEVICE_GPF);
+	if (!dvsec)
+		dev_warn(dev, "%s GPF DVSEC not present\n",
+			 is_port ? "Port" : "Device");
+	return dvsec;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_gpf_get_dvsec, "CXL");
+
 static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
 {
 	u64 base, scale;
@@ -1116,26 +1132,20 @@ int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
 {
 	struct pci_dev *pdev;
 
-	if (!dev_is_pci(dport_dev))
-		return 0;
-
-	pdev = to_pci_dev(dport_dev);
-	if (!pdev || !port)
+	if (!port)
 		return -EINVAL;
 
 	if (!port->gpf_dvsec) {
 		int dvsec;
 
-		dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
-						  CXL_DVSEC_PORT_GPF);
-		if (!dvsec) {
-			pci_warn(pdev, "Port GPF DVSEC not present\n");
+		dvsec = cxl_gpf_get_dvsec(dport_dev, true);
+		if (!dvsec)
 			return -EINVAL;
-		}
 
 		port->gpf_dvsec = dvsec;
 	}
 
+	pdev = to_pci_dev(dport_dev);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 1);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 2);
 
drivers/cxl/cxl.h +2 -0
index 6baec4ba9141..29f2ab0d5bf6 100644
@@ -901,4 +901,6 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
 #define __mock static
 #endif
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port);
+
 #endif /* __CXL_H__ */
Signature · 1 line
2.39.5
maintainer Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH 1/4] cxl/pci: Introduce cxl_gpf_get_dvsec()

Quoted 6 lines · Davidlohr Bueso

Add a helper to fetch the port/device GPF dvsecs. This is currently only used for ports, but a later patch to export dirty count to users will make use of the device one.

Quoted 74 lines
---
 drivers/cxl/core/pci.c | 30 ++++++++++++++++++++----------
 drivers/cxl/cxl.h      |  2 ++
 2 files changed, 22 insertions(+), 10 deletions(-)
drivers/cxl/core/pci.c +20 -10
index a5c65f79db18..96fecb799cbc 100644
@@ -1072,6 +1072,22 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
 #define GPF_TIMEOUT_BASE_MAX 2
 #define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port)
+{
+	u16 dvsec;
+
+	if (!dev_is_pci(dev))
+		return 0;
+
+	dvsec = pci_find_dvsec_capability(to_pci_dev(dev), PCI_VENDOR_ID_CXL,
+			is_port ? CXL_DVSEC_PORT_GPF : CXL_DVSEC_DEVICE_GPF);
+	if (!dvsec)
+		dev_warn(dev, "%s GPF DVSEC not present\n",
+			 is_port ? "Port" : "Device");
+	return dvsec;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_gpf_get_dvsec, "CXL");
+
 static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
 {
 	u64 base, scale;
@@ -1116,26 +1132,20 @@ int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
 {
 	struct pci_dev *pdev;
 
-	if (!dev_is_pci(dport_dev))
-		return 0;
-
-	pdev = to_pci_dev(dport_dev);
-	if (!pdev || !port)
+	if (!port)
 		return -EINVAL;
 
 	if (!port->gpf_dvsec) {
 		int dvsec;
 
-		dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
-						  CXL_DVSEC_PORT_GPF);
-		if (!dvsec) {
-			pci_warn(pdev, "Port GPF DVSEC not present\n");
+		dvsec = cxl_gpf_get_dvsec(dport_dev, true);
+		if (!dvsec)
 			return -EINVAL;
-		}
 
 		port->gpf_dvsec = dvsec;
 	}
 
+	pdev = to_pci_dev(dport_dev);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 1);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 2);
 
drivers/cxl/cxl.h +2 -0
index 6baec4ba9141..29f2ab0d5bf6 100644
@@ -901,4 +901,6 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
 #define __mock static
 #endif
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port);
+
 #endif /* __CXL_H__ */
Reviewed-by on v4 1/4
#4 lore raw

Re: [PATCH 1/4] cxl/pci: Introduce cxl_gpf_get_dvsec()

In reply to Davidlohr Bueso
Quoted 6 lines · On Wed, 19 Feb 2025 17:36:01 -0800 Davidlohr Bueso <[email protected]> wrote:

Add a helper to fetch the port/device GPF dvsecs. This is currently only used for ports, but a later patch to export dirty count to users will make use of the device one.

Maybe an enum for the port vs device thing would have been nice but I'm not that bothered and a single use enum is bit nasty.

Reviewed-by on v4 1/4
#5 lore raw

Re: [PATCH 1/4] cxl/pci: Introduce cxl_gpf_get_dvsec()

In reply to Davidlohr Bueso
Quoted 7 lines · Davidlohr Bueso

Add a helper to fetch the port/device GPF dvsecs. This is currently only used for ports, but a later patch to export dirty count to users will make use of the device one.

---

Quoted 76 lines
 drivers/cxl/core/pci.c | 30 ++++++++++++++++++++----------
 drivers/cxl/cxl.h      |  2 ++
 2 files changed, 22 insertions(+), 10 deletions(-)
drivers/cxl/core/pci.c +20 -10
index a5c65f79db18..96fecb799cbc 100644
@@ -1072,6 +1072,22 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
 #define GPF_TIMEOUT_BASE_MAX 2
 #define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port)
+{
+	u16 dvsec;
+
+	if (!dev_is_pci(dev))
+		return 0;
+
+	dvsec = pci_find_dvsec_capability(to_pci_dev(dev), PCI_VENDOR_ID_CXL,
+			is_port ? CXL_DVSEC_PORT_GPF : CXL_DVSEC_DEVICE_GPF);
+	if (!dvsec)
+		dev_warn(dev, "%s GPF DVSEC not present\n",
+			 is_port ? "Port" : "Device");
+	return dvsec;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_gpf_get_dvsec, "CXL");
+
 static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
 {
 	u64 base, scale;
@@ -1116,26 +1132,20 @@ int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
 {
 	struct pci_dev *pdev;
 
-	if (!dev_is_pci(dport_dev))
-		return 0;
-
-	pdev = to_pci_dev(dport_dev);
-	if (!pdev || !port)
+	if (!port)
 		return -EINVAL;
 
 	if (!port->gpf_dvsec) {
 		int dvsec;
 
-		dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
-						  CXL_DVSEC_PORT_GPF);
-		if (!dvsec) {
-			pci_warn(pdev, "Port GPF DVSEC not present\n");
+		dvsec = cxl_gpf_get_dvsec(dport_dev, true);
+		if (!dvsec)
 			return -EINVAL;
-		}
 
 		port->gpf_dvsec = dvsec;
 	}
 
+	pdev = to_pci_dev(dport_dev);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 1);
 	update_gpf_port_dvsec(pdev, port->gpf_dvsec, 2);
 
drivers/cxl/cxl.h +2 -0
index 6baec4ba9141..29f2ab0d5bf6 100644
@@ -901,4 +901,6 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
 #define __mock static
 #endif
 
+u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port);
+
 #endif /* __CXL_H__ */
Signature · 1 line
2.39.5
author maintainer
#6 lore raw

PATCH v4 2/4 cxl/pmem: Rename cxl_dirty_shutdown_state()

In reply to Davidlohr Bueso

... to a better suited 'cxl_arm_dirty_shutdown()'.

---
 drivers/cxl/core/mbox.c | 4 ++--
 drivers/cxl/cxlmem.h    | 2 +-
 drivers/cxl/pmem.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/mbox.c +2 -2
index c5eedcae3b02..86d13f4a1c18 100644
@@ -1281,7 +1281,7 @@ int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_dpa_fetch, "CXL");
 
-int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds)
+int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds)
 {
 	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
 	struct cxl_mbox_cmd mbox_cmd;
@@ -1297,7 +1297,7 @@ int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds)
 
 	return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
 }
-EXPORT_SYMBOL_NS_GPL(cxl_dirty_shutdown_state, "CXL");
+EXPORT_SYMBOL_NS_GPL(cxl_arm_dirty_shutdown, "CXL");
 
 int cxl_set_timestamp(struct cxl_memdev_state *mds)
 {
drivers/cxl/cxlmem.h +1 -1
index 8e1e46c348f5..6d60030139df 100644
@@ -822,7 +822,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 			    enum cxl_event_log_type type,
 			    enum cxl_event_type event_type,
 			    const uuid_t *uuid, union cxl_event *evt);
-int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds);
+int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds);
 int cxl_set_timestamp(struct cxl_memdev_state *mds);
 int cxl_poison_state_init(struct cxl_memdev_state *mds);
 int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
drivers/cxl/pmem.c +1 -1
index a39e2c52d7ab..6b284962592f 100644
@@ -90,7 +90,7 @@ static int cxl_nvdimm_probe(struct device *dev)
 	 * clear it upon a successful GPF flow. The exception to this
 	 * is upon Viral detection, per CXL 3.2 section 12.4.2.
 	 */
-	if (cxl_dirty_shutdown_state(mds))
+	if (cxl_arm_dirty_shutdown(mds))
 		dev_warn(dev, "GPF: could not dirty shutdown state\n");
 
 	dev_set_drvdata(dev, nvdimm);
Signature · 1 line
2.39.5
#8 lore raw

Re: [PATCH 2/4] cxl/pmem: Rename cxl_dirty_shutdown_state()

In reply to Davidlohr Bueso
Quoted 1 line · On Wed, 19 Feb 2025 17:36:02 -0800 Davidlohr Bueso <[email protected]> wrote:

... to a better suited 'cxl_arm_dirty_shutdown()'.

But it works on x86 as well! I'll cope I suppose.

Mind you why not let it take the state as a parameter and always pass 1? From a mailbox command point of view 0 is valid. The text in table 8-152 has me a little confused but I think it says you can set it to 1 and back to 0 and then reset at which point the dirty shutdown count will not increment.

No idea why you'd do that, but just passing a 1 into this function would make a call of cxl_set_dirty_shutdown_state(mds, 1)
seem reasonable, or pass a boolean.

Quoted 32 lines
---
 drivers/cxl/core/mbox.c | 4 ++--
 drivers/cxl/cxlmem.h    | 2 +-
 drivers/cxl/pmem.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/mbox.c +2 -2
index c5eedcae3b02..86d13f4a1c18 100644
@@ -1281,7 +1281,7 @@ int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_dpa_fetch, "CXL");
 
-int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds)
+int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds)
 {
 	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
 	struct cxl_mbox_cmd mbox_cmd;
@@ -1297,7 +1297,7 @@ int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds)
 
 	return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
 }
-EXPORT_SYMBOL_NS_GPL(cxl_dirty_shutdown_state, "CXL");
+EXPORT_SYMBOL_NS_GPL(cxl_arm_dirty_shutdown, "CXL");
 
 int cxl_set_timestamp(struct cxl_memdev_state *mds)
 {
author maintainer
#9 lore raw

Re: [PATCH 2/4] cxl/pmem: Rename cxl_dirty_shutdown_state()

Quoted 14 lines · Jonathan Cameron
Quoted 1 line · On Wed, 19 Feb 2025 17:36:02 -0800 Davidlohr Bueso <[email protected]> wrote:

... to a better suited 'cxl_arm_dirty_shutdown()'.

But it works on x86 as well! I'll cope I suppose.

Mind you why not let it take the state as a parameter and always pass 1? From a mailbox command point of view 0 is valid. The text in table 8-152 has me a little confused but I think it says you can set it to 1 and back to 0 and then reset at which point the dirty shutdown count will not increment.

Quoted 4 lines

No idea why you'd do that, but just passing a 1 into this function would make a call of cxl_set_dirty_shutdown_state(mds, 1)
seem reasonable, or pass a boolean.

I prefer how it is now, really.

No point passing the arg which will always be 1, and that "arm/setup" is in the name, so passing 0 would be counter intuitive as well.

Thanks,
Davidlohr

author maintainer
#10 lore raw

PATCH v4 3/4 cxl/pmem: Export dirty shutdown count via sysfs

In reply to Davidlohr Bueso

Similar to how the acpi_nfit driver exports Optane dirty shutdown count, introduce:

/sys/bus/cxl/devices/nvdimm-bridge0/ndbusX/nmemY/cxl/dirty_shutdown

Under the conditions that 1) dirty shutdown can be set, 2) Device GPF DVSEC exists, and 3) the count itself can be retrieved.

---
 Documentation/ABI/testing/sysfs-bus-cxl       | 12 +++
 Documentation/driver-api/cxl/maturity-map.rst |  2 +-
 drivers/cxl/core/mbox.c                       | 21 +++++
 drivers/cxl/cxl.h                             |  1 +
 drivers/cxl/cxlmem.h                          | 13 +++
 drivers/cxl/pmem.c                            | 79 ++++++++++++++++---
 6 files changed, 118 insertions(+), 10 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +12 -0
index 3f5627a1210a..a7491d214098 100644
@@ -586,3 +586,15 @@ Description:
 		See Documentation/ABI/stable/sysfs-devices-node. access0 provides
 		the number to the closest initiator and access1 provides the
 		number to the closest CPU.
+
+
+What:		/sys/bus/cxl/devices/nvdimm-bridge0/ndbusX/nmemY/cxl/dirty_shutdown
+Date:		Feb, 2025
+KernelVersion:	v6.15
+Contact:	[email protected]
+Description:
+		(RO) The device dirty shutdown count value, which is the number
+		of times the device could have incurred in potential data loss.
+		The count is persistent across power loss and wraps back to 0
+		upon overflow. If this file is not present, the device does not
+		have the necessary support for dirty tracking.
Documentation/driver-api/cxl/maturity-map.rst +1 -1
index 99dd2c841e69..a2288f9df658 100644
@@ -130,7 +130,7 @@ Mailbox commands
 * [0] Switch CCI
 * [3] Timestamp
 * [1] PMEM labels
-* [1] PMEM GPF / Dirty Shutdown
+* [3] PMEM GPF / Dirty Shutdown
 * [0] Scan Media
 
 PMU
drivers/cxl/core/mbox.c +21 -0
index 86d13f4a1c18..6bc398182a5d 100644
@@ -1281,6 +1281,27 @@ int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_dpa_fetch, "CXL");
 
+int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count)
+{
+	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
+	struct cxl_mbox_get_health_info_out hi;
+	struct cxl_mbox_cmd mbox_cmd;
+	int rc;
+
+	mbox_cmd = (struct cxl_mbox_cmd) {
+		.opcode = CXL_MBOX_OP_GET_HEALTH_INFO,
+		.size_out = sizeof(hi),
+		.payload_out = &hi,
+	};
+
+	rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
+	if (!rc)
+		*count = le32_to_cpu(hi.dirty_shutdown_cnt);
+
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_get_dirty_count, "CXL");
+
 int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds)
 {
 	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
drivers/cxl/cxl.h +1 -0
index 29f2ab0d5bf6..8bdfa536262e 100644
@@ -542,6 +542,7 @@ struct cxl_nvdimm {
 	struct device dev;
 	struct cxl_memdev *cxlmd;
 	u8 dev_id[CXL_DEV_ID_LEN]; /* for nvdimm, string of 'serial' */
+	u64 dirty_shutdowns;
 };
 
 struct cxl_pmem_region_mapping {
drivers/cxl/cxlmem.h +13 -0
index 6d60030139df..3b6ef9e936c3 100644
@@ -681,6 +681,18 @@ struct cxl_mbox_set_partition_info {
 
 #define  CXL_SET_PARTITION_IMMEDIATE_FLAG	BIT(0)
 
+/* Get Health Info Output Payload CXL 3.2 Spec 8.2.10.9.3.1 Table 8-148 */
+struct cxl_mbox_get_health_info_out {
+	u8 health_status;
+	u8 media_status;
+	u8 additional_status;
+	u8 life_used;
+	__le16 device_temperature;
+	__le32 dirty_shutdown_cnt;
+	__le32 corrected_volatile_error_cnt;
+	__le32 corrected_persistent_error_cnt;
+} __packed;
+
 /* Set Shutdown State Input Payload CXL 3.2 Spec 8.2.10.9.3.5 Table 8-152 */
 struct cxl_mbox_set_shutdown_state_in {
 	u8 state;
@@ -822,6 +834,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 			    enum cxl_event_log_type type,
 			    enum cxl_event_type event_type,
 			    const uuid_t *uuid, union cxl_event *evt);
+int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count);
 int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds);
 int cxl_set_timestamp(struct cxl_memdev_state *mds);
 int cxl_poison_state_init(struct cxl_memdev_state *mds);
drivers/cxl/pmem.c +70 -9

115 lines not on this page · raw message

Signature · 1 line
2.39.5
Reviewed-by on v4 3/4
#11 lore raw

Re: [PATCH 3/4] cxl/pmem: Export dirty shutdown count via sysfs

Quoted 10 lines · Davidlohr Bueso

Similar to how the acpi_nfit driver exports Optane dirty shutdown count, introduce:

/sys/bus/cxl/devices/nvdimm-bridge0/ndbusX/nmemY/cxl/dirty_shutdown

Under the conditions that 1) dirty shutdown can be set, 2) Device GPF DVSEC exists, and 3) the count itself can be retrieved.

Quoted 1 line

[snip]

Reviewed-by on v4 3/4
#12 lore raw

Re: [PATCH 3/4] cxl/pmem: Export dirty shutdown count via sysfs

In reply to Davidlohr Bueso
Quoted 11 lines · On Wed, 19 Feb 2025 17:36:03 -0800 Davidlohr Bueso <[email protected]> wrote:

Similar to how the acpi_nfit driver exports Optane dirty shutdown count, introduce:

/sys/bus/cxl/devices/nvdimm-bridge0/ndbusX/nmemY/cxl/dirty_shutdown

Under the conditions that 1) dirty shutdown can be set, 2) Device GPF DVSEC exists, and 3) the count itself can be retrieved.

One trivial thing otherwise

drivers/cxl/pmem.c static ssize_t id_show(struct device *dev, struct device_attribute *attr, char * · line 41

Quoted 10 lines
drivers/cxl/pmem.c +1 -1
index 6b284962592f..cb039cfc62cb 100644
@@ -38,19 +38,48 @@ static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *
 	struct cxl_nvdimm *cxl_nvd = nvdimm_provider_data(nvdimm);
 	struct cxl_dev_state *cxlds = cxl_nvd->cxlmd->cxlds;
 
-	return sysfs_emit(buf, "%lld\n", cxlds->serial);
+	return sysfs_emit(buf, "%llu\n", cxlds->serial);

I guess you 'fixed' the wrong one?

drivers/cxl/pmem.c static ssize_t id_show(struct device *dev, struct device_attribute *attr, char * · line 51

Quoted 10 lines
drivers/cxl/pmem.c +7 -0
 }
 static DEVICE_ATTR_RO(id);
 
+static ssize_t dirty_shutdown_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct nvdimm *nvdimm = to_nvdimm(dev);
+	struct cxl_nvdimm *cxl_nvd = nvdimm_provider_data(nvdimm);
+
+	return sysfs_emit(buf, "%lld\n", cxl_nvd->dirty_shutdowns);

It's unsigned so %llu though I hope no one ever tests that by doing that many dirty shutdowns.

Quoted 2 lines
drivers/cxl/pmem.c +2 -0
+}
+static DEVICE_ATTR_RO(dirty_shutdown);
author maintainer
#13 lore raw

Re: [PATCH 3/4] cxl/pmem: Export dirty shutdown count via sysfs

Quoted 26 lines · Jonathan Cameron
Quoted 11 lines · On Wed, 19 Feb 2025 17:36:03 -0800 Davidlohr Bueso <[email protected]> wrote:

Similar to how the acpi_nfit driver exports Optane dirty shutdown count, introduce:

/sys/bus/cxl/devices/nvdimm-bridge0/ndbusX/nmemY/cxl/dirty_shutdown

Under the conditions that 1) dirty shutdown can be set, 2) Device GPF DVSEC exists, and 3) the count itself can be retrieved.

One trivial thing otherwise

Quoted 8 lines
drivers/cxl/pmem.c +0 -0
index 6b284962592f..cb039cfc62cb 100644
@@ -38,19 +38,48 @@ static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *
 	struct cxl_nvdimm *cxl_nvd = nvdimm_provider_data(nvdimm);
 	struct cxl_dev_state *cxlds = cxl_nvd->cxlmd->cxlds;
 
Quoted 4 lines

drivers/cxl/pmem.c static ssize_t id_show(struct device *dev, struct device_attribute *attr, char * · line 41

Quoted 2 lines
drivers/cxl/pmem.c +1 -1
-	return sysfs_emit(buf, "%lld\n", cxlds->serial);
+	return sysfs_emit(buf, "%llu\n", cxlds->serial);

I guess you 'fixed' the wrong one?

Yes, I'm an idiot. Will send a hopefully final v5 with this fix.

author maintainer
#14 lore raw

PATCH v4 4/4 tools/testing/cxl: Set Shutdown State support

In reply to Davidlohr Bueso

Add support to emulate the CXL Set Shutdown State operation.

---
 tools/testing/cxl/test/mem.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tools/testing/cxl/test/mem.c +23 -0
index 495199238335..9ca210b80e27 100644
@@ -65,6 +65,10 @@ static struct cxl_cel_entry mock_cel[] = {
 		.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
 		.effect = CXL_CMD_EFFECT_NONE,
 	},
+	{
+		.opcode = cpu_to_le16(CXL_MBOX_OP_SET_SHUTDOWN_STATE),
+		.effect = POLICY_CHANGE_IMMEDIATE,
+	},
 	{
 		.opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON),
 		.effect = CXL_CMD_EFFECT_NONE,
@@ -161,6 +165,7 @@ struct cxl_mockmem_data {
 	u8 event_buf[SZ_4K];
 	u64 timestamp;
 	unsigned long sanitize_timeout;
+	u8 shutdown_state;
 };
 
 static struct mock_event_log *event_find_log(struct device *dev, int log_type)
@@ -1088,6 +1093,21 @@ static int mock_health_info(struct cxl_mbox_cmd *cmd)
 	return 0;
 }
 
+static int mock_set_shutdown_state(struct cxl_mockmem_data *mdata,
+				   struct cxl_mbox_cmd *cmd)
+{
+	struct cxl_mbox_set_shutdown_state_in *ss = cmd->payload_in;
+
+	if (cmd->size_in != sizeof(*ss))
+		return -EINVAL;
+
+	if (cmd->size_out != 0)
+		return -EINVAL;
+
+	mdata->shutdown_state = ss->state;
+	return 0;
+}
+
 static struct mock_poison {
 	struct cxl_dev_state *cxlds;
 	u64 dpa;
@@ -1421,6 +1441,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,
 	case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE:
 		rc = mock_passphrase_secure_erase(mdata, cmd);
 		break;
+	case CXL_MBOX_OP_SET_SHUTDOWN_STATE:
+		rc = mock_set_shutdown_state(mdata, cmd);
+		break;
 	case CXL_MBOX_OP_GET_POISON:
 		rc = mock_get_poison(cxlds, cmd);
 		break;
Signature · 1 line
2.39.5
Reviewed-by on v4 4/4
#16 lore raw

Re: [PATCH 4/4] tools/testing/cxl: Set Shutdown State support

In reply to Davidlohr Bueso
Quoted 5 lines · On Wed, 19 Feb 2025 17:36:04 -0800 Davidlohr Bueso <[email protected]> wrote:

Add support to emulate the CXL Set Shutdown State operation.

FWIW looks fine to me as well.