Skip to contentSkip to conversation

cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

PATCH In review Robert Richter 4 participants 13 messages Feb 16, 2024 – Apr 9, 2024 CXL

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +2 -2
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 	}
 
 	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
 	}
 
 	/*
Signature · 1 line
2.39.2
#1 lore raw
Quoted 32 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +0 -0
index a0e7ed5ae25f..18616ca873e5 100644

drivers/cxl/core/pci.c int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, · line 483

Quoted 8 lines
drivers/cxl/core/pci.c +2 -2
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 	}
 
 	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
 	}

This looks good to me.

#2 lore raw
Quoted 35 lines · Dan Williams
Quoted 34 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +0 -0
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 	}
 
Quoted 8 lines

drivers/cxl/core/pci.c int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, · line 483

Quoted 6 lines
drivers/cxl/core/pci.c +2 -2
 	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
 	}

This looks good to me.

Thanks, Dan

#3 lore raw
Quoted 17 lines · Robert Richter
Quoted 16 lines · Dan Williams
Quoted 15 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

Fixes 9de321e93c3b ("cxl/pci: Refactor cxl_hdm_decode_init()")
Fixes 34e37b4c432c ("cxl/port: Enable HDM Capability after validating DVSEC Ranges")

Sorry, I forgot those tags, please add.

Thanks,

-Robert

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#4 lore raw
Quoted 21 lines · Robert Richter
Quoted 20 lines · Robert Richter
Quoted 19 lines · Dan Williams
Quoted 18 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

Fixes 9de321e93c3b ("cxl/pci: Refactor cxl_hdm_decode_init()")

This patch just moves the memory-disable call from one place to another.

Quoted 1 line
Fixes 34e37b4c432c ("cxl/port: Enable HDM Capability after validating DVSEC Ranges")

This is the proper Fixes tag.

Quoted 1 line

Added.

#5 lore raw
In reply to Robert Richter
Quoted 32 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +0 -0
index a0e7ed5ae25f..18616ca873e5 100644

drivers/cxl/core/pci.c int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, · line 482

Quoted 7 lines
drivers/cxl/core/pci.c +2 -2
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 	}
 
 	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;

While testing I found this needs the following fixup:

drivers/cxl/core/pci.c +1 -1
index e24ffae8135f..e9e6c81ce034 100644
@@ -477,7 +477,7 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
                allowed++;
        }
 
-       if (!allowed) {
+       if (!allowed && info->mem_enabled) {
                dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
                return -ENXIO;
        }

...i.e. Linux should only give up if it does not understand an active decode region.

Now this SPA/HPA mismatch will still cause problems later in region creation flow, but that's a separate issue.

#6 lore raw
Quoted 48 lines · Dan Williams
Quoted 32 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
 drivers/cxl/core/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +0 -0
index a0e7ed5ae25f..18616ca873e5 100644

drivers/cxl/core/pci.c int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, · line 482

Quoted 7 lines
drivers/cxl/core/pci.c +2 -2
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 	}
 
 	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;

While testing I found this needs the following fixup:

drivers/cxl/core/pci.c +0 -0
index e24ffae8135f..e9e6c81ce034 100644

drivers/cxl/core/pci.c int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, · line 483

Quoted 8 lines
drivers/cxl/core/pci.c +1 -1
@@ -477,7 +477,7 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
                allowed++;
        }
 
-       if (!allowed) {
+       if (!allowed && info->mem_enabled) {
                dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
                return -ENXIO;
        }

The change looks correct to me, thanks for fixing.

-Robert

Quoted 7 lines

...i.e. Linux should only give up if it does not understand an active decode region.

Now this SPA/HPA mismatch will still cause problems later in region creation flow, but that's a separate issue.

#7 lore raw

[Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

In reply to Robert Richter

Robert, Dan

It's noticed that 'cxl list' show nothing after a reboot in v6.8.(A fresh boot works) The git bisection pointed to this commit.

Haven't investigated it deeply, I'm wondering if it's a QEMU problem or something wrong with this patch.

Reproduce step:

1. Start a cxl QEMU VM
2. cxl list works
cxl list
[

   {
     "memdev":"mem0",
     "ram_size":2147483648,
     "serial":0,
     "host":"0000:54:00.0"
   },
   {
     "memdev":"mem1",
     "pmem_size":2147483648,
     "serial":0,
     "host":"0000:36:00.0"

}
]

3. reboot VM
4. cxl list show nothing and has following dmesg

cxl list
[
]
Warning: no matching devices found

...

[    6.249188]  pci0000:53: host supports CXL
[    6.258168]  pci0000:35: host supports CXL
[    6.490568] cxl_pci 0000:54:00.0: Range register decodes outside platform defined CXL ranges.
[    6.494298] cxl_mem mem0: endpoint3 failed probe
[    6.506072] cxl_pci 0000:36:00.0: Range register decodes outside platform defined CXL ranges.
[    6.515092] cxl_mem mem1: endpoint3 failed probe
[   12.181188] kauditd_printk_skb: 18 callbacks suppressed

Thanks
Zhijian

Quoted 42 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
  drivers/cxl/core/pci.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +2 -2
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
  	}
 
  	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
  	}
 
  	/*
#8 lore raw

Re: [Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

All guys,

In order to make the CXL memdev work again, i have to modify the QEMU side where it resets the "DVSEC CXL Control" during reboot. A draft changes is as below:

Per 8.1.3.2 DVSEC CXL Control (Offset 0Ch), Default value of BIT(2) is 0. So is it reasonable to have a reset dvsecs in QEMU during reboot?

Any comments @Janathan

[root@iaas-rpma qemu]# git diff

hw/mem/cxl_type3.c +21 -0
index b0a7e9f11b64..31755a9f9aab 100644
@@ -899,6 +899,26 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
      return address_space_write(as, dpa_offset, attrs, &data, size);
  }
  
+static void dvsecs_ctrl_reset(CXLType3Dev *ct3d)
+{
+
+     if (ct3d->sn != UI64_NULL) {
+        pcie_dev_ser_num_init(ct3d->cxl_cstate.pdev, 0x100, ct3d->sn);
+        ct3d->cxl_cstate.dvsec_offset = 0x100 + 0x0c;
+    } else {
+        ct3d->cxl_cstate.dvsec_offset = 0x100;
+    }
+
+    // FIXME?: only reset ctrl instead of rebuilding the whole dvsecs
+#if 0
+    memcpy(pdev->config + offset + sizeof(DVSECHeader),
+           body + sizeof(DVSECHeader),
+           length - sizeof(DVSECHeader));
+#else
+    build_dvsecs(ct3d);
+#endif
+}
+
  static void ct3d_reset(DeviceState *dev)
  {
      CXLType3Dev *ct3d = CXL_TYPE3(dev);
@@ -907,6 +927,7 @@ static void ct3d_reset(DeviceState *dev)
  
      cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE);
      cxl_device_register_init_t3(ct3d);
+    dvsecs_ctrl_reset(ct3d);
  
      /*
       * Bring up an endpoint to target with MCTP over VDM.
Quoted 95 lines · Zhijian Li (Fujitsu)

Robert, Dan

It's noticed that 'cxl list' show nothing after a reboot in v6.8.(A fresh boot works) The git bisection pointed to this commit.

Haven't investigated it deeply, I'm wondering if it's a QEMU problem or something wrong with this patch.

Reproduce step:

1. Start a cxl QEMU VM
2. cxl list works
cxl list
[

    {
      "memdev":"mem0",
      "ram_size":2147483648,
      "serial":0,
      "host":"0000:54:00.0"
    },
    {
      "memdev":"mem1",
      "pmem_size":2147483648,
      "serial":0,
      "host":"0000:36:00.0"
    }

]

3. reboot VM
4. cxl list show nothing and has following dmesg

cxl list
[
]
Warning: no matching devices found

...

[    6.249188]  pci0000:53: host supports CXL
[    6.258168]  pci0000:35: host supports CXL
[    6.490568] cxl_pci 0000:54:00.0: Range register decodes outside platform defined CXL ranges.
[    6.494298] cxl_mem mem0: endpoint3 failed probe
[    6.506072] cxl_pci 0000:36:00.0: Range register decodes outside platform defined CXL ranges.
[    6.515092] cxl_mem mem1: endpoint3 failed probe
[   12.181188] kauditd_printk_skb: 18 callbacks suppressed

Thanks
Zhijian

Quoted 42 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
   drivers/cxl/core/pci.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +2 -2
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
   	}
 
   	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
   	}
 
   	/*
#9 lore raw

Re: [Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

Quoted 9 lines · On Tue, 26 Mar 2024 08:26:21 +0000 "Zhijian Li (Fujitsu)"…

All guys,

In order to make the CXL memdev work again, i have to modify the QEMU side where it resets the "DVSEC CXL Control" during reboot. A draft changes is as below:

Per 8.1.3.2 DVSEC CXL Control (Offset 0Ch), Default value of BIT(2) is 0. So is it reasonable to have a reset dvsecs in QEMU during reboot?

Any comments @Janathan

Hi,

Sorry it took me so long to get to this.

What are you attempting to do? Use an OS reboot on QEMU to check that the flows meant for BIOS configuration work - i.e. the OS rebuilds the state correctly by reading the current state of the devices?

Would be good to fix that case but I want to check that's the aim before looking too closely at this.

Thanks,

Jonathan

Quoted 143 lines

[root@iaas-rpma qemu]# git diff

hw/mem/cxl_type3.c +21 -0
index b0a7e9f11b64..31755a9f9aab 100644
@@ -899,6 +899,26 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
      return address_space_write(as, dpa_offset, attrs, &data, size);
  }
 
+static void dvsecs_ctrl_reset(CXLType3Dev *ct3d)
+{
+
+     if (ct3d->sn != UI64_NULL) {
+        pcie_dev_ser_num_init(ct3d->cxl_cstate.pdev, 0x100, ct3d->sn);
+        ct3d->cxl_cstate.dvsec_offset = 0x100 + 0x0c;
+    } else {
+        ct3d->cxl_cstate.dvsec_offset = 0x100;
+    }
+
+    // FIXME?: only reset ctrl instead of rebuilding the whole dvsecs
+#if 0
+    memcpy(pdev->config + offset + sizeof(DVSECHeader),
+           body + sizeof(DVSECHeader),
+           length - sizeof(DVSECHeader));
+#else
+    build_dvsecs(ct3d);
+#endif
+}
+
  static void ct3d_reset(DeviceState *dev)
  {
      CXLType3Dev *ct3d = CXL_TYPE3(dev);
@@ -907,6 +927,7 @@ static void ct3d_reset(DeviceState *dev)
 
      cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE);
      cxl_device_register_init_t3(ct3d);
+    dvsecs_ctrl_reset(ct3d);
 
      /*
       * Bring up an endpoint to target with MCTP over VDM.
Quoted 95 lines · Zhijian Li (Fujitsu)

Robert, Dan

It's noticed that 'cxl list' show nothing after a reboot in v6.8.(A fresh boot works) The git bisection pointed to this commit.

Haven't investigated it deeply, I'm wondering if it's a QEMU problem or something wrong with this patch.

Reproduce step:

1. Start a cxl QEMU VM
2. cxl list works
cxl list
[

    {
      "memdev":"mem0",
      "ram_size":2147483648,
      "serial":0,
      "host":"0000:54:00.0"
    },
    {
      "memdev":"mem1",
      "pmem_size":2147483648,
      "serial":0,
      "host":"0000:36:00.0"
    }

]

3. reboot VM
4. cxl list show nothing and has following dmesg

cxl list
[
]
Warning: no matching devices found

...

[    6.249188]  pci0000:53: host supports CXL
[    6.258168]  pci0000:35: host supports CXL
[    6.490568] cxl_pci 0000:54:00.0: Range register decodes outside platform defined CXL ranges.
[    6.494298] cxl_mem mem0: endpoint3 failed probe
[    6.506072] cxl_pci 0000:36:00.0: Range register decodes outside platform defined CXL ranges.
[    6.515092] cxl_mem mem1: endpoint3 failed probe
[   12.181188] kauditd_printk_skb: 18 callbacks suppressed

Thanks
Zhijian

Quoted 42 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
   drivers/cxl/core/pci.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +2 -2
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
   	}
 
   	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
   	}
 
   	/  
#10 lore raw

Re: [Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 26 Mar 2024 08:26:21 +0000 "Zhijian Li (Fujitsu)"…

All guys,

In order to make the CXL memdev work again, i have to modify the QEMU side where it resets the "DVSEC CXL Control" during reboot. A draft changes is as below:

Per 8.1.3.2 DVSEC CXL Control (Offset 0Ch), Default value of BIT(2) is 0. So is it reasonable to have a reset dvsecs in QEMU during reboot?

Quoted 8 lines
Quoted 1 line

Any comments @Janathan

Hi,

Sorry it took me so long to get to this.

What are you attempting to do? Use an OS reboot on QEMU to check that the flows meant for BIOS configuration work -

There is no doubt that *the OS rebuilds the state correctly* is the OS's responsibility. Providing the consistent device state is the *Device*'s responsibility.

So on reboot, the device should have a consistent device state with a fresh boot. My changes intended to let *Device* emulated by QEMU provide a consistent device state.

Thanks
Zhijian

Quoted 154 lines

i.e. the OS rebuilds the state
correctly by reading the current state of the devices?>

Would be good to fix that case but I want to check that's the aim before looking too closely at this.

Thanks,

Jonathan

Quoted 143 lines

[root@iaas-rpma qemu]# git diff

hw/mem/cxl_type3.c +21 -0
index b0a7e9f11b64..31755a9f9aab 100644
@@ -899,6 +899,26 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
       return address_space_write(as, dpa_offset, attrs, &data, size);
   }
 
+static void dvsecs_ctrl_reset(CXLType3Dev *ct3d)
+{
+
+     if (ct3d->sn != UI64_NULL) {
+        pcie_dev_ser_num_init(ct3d->cxl_cstate.pdev, 0x100, ct3d->sn);
+        ct3d->cxl_cstate.dvsec_offset = 0x100 + 0x0c;
+    } else {
+        ct3d->cxl_cstate.dvsec_offset = 0x100;
+    }
+
+    // FIXME?: only reset ctrl instead of rebuilding the whole dvsecs
+#if 0
+    memcpy(pdev->config + offset + sizeof(DVSECHeader),
+           body + sizeof(DVSECHeader),
+           length - sizeof(DVSECHeader));
+#else
+    build_dvsecs(ct3d);
+#endif
+}
+
   static void ct3d_reset(DeviceState *dev)
   {
       CXLType3Dev *ct3d = CXL_TYPE3(dev);
@@ -907,6 +927,7 @@ static void ct3d_reset(DeviceState *dev)
 
       cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE);
       cxl_device_register_init_t3(ct3d);
+    dvsecs_ctrl_reset(ct3d);
 
       /*
        * Bring up an endpoint to target with MCTP over VDM.
Quoted 95 lines · Zhijian Li (Fujitsu)

Robert, Dan

It's noticed that 'cxl list' show nothing after a reboot in v6.8.(A fresh boot works) The git bisection pointed to this commit.

Haven't investigated it deeply, I'm wondering if it's a QEMU problem or something wrong with this patch.

Reproduce step:

1. Start a cxl QEMU VM
2. cxl list works
cxl list
[

     {
       "memdev":"mem0",
       "ram_size":2147483648,
       "serial":0,
       "host":"0000:54:00.0"
     },
     {
       "memdev":"mem1",
       "pmem_size":2147483648,
       "serial":0,
       "host":"0000:36:00.0"
     }

]

3. reboot VM
4. cxl list show nothing and has following dmesg

cxl list
[
]
Warning: no matching devices found

...

[    6.249188]  pci0000:53: host supports CXL
[    6.258168]  pci0000:35: host supports CXL
[    6.490568] cxl_pci 0000:54:00.0: Range register decodes outside platform defined CXL ranges.
[    6.494298] cxl_mem mem0: endpoint3 failed probe
[    6.506072] cxl_pci 0000:36:00.0: Range register decodes outside platform defined CXL ranges.
[    6.515092] cxl_mem mem1: endpoint3 failed probe
[   12.181188] kauditd_printk_skb: 18 callbacks suppressed

Thanks
Zhijian

Quoted 42 lines · Robert Richter

The Linux CXL subsystem is built on the assumption that HPA == SPA. That is, the host physical address (HPA) the HDM decoder registers are programmed with are system physical addresses (SPA).

During HDM decoder setup, the DVSEC CXL range registers (cxl-3.1, 8.1.3.8) are checked if the memory is enabled and the CXL range is in a HPA window that is described in a CFMWS structure of the CXL host bridge (cxl-3.1, 9.18.1.3).

Now, if the HPA is not an SPA, the CXL range does not match a CFMWS window and the CXL memory range will be disabled then. The HDM decoder stops working which causes system memory being disabled and further a system hang during HDM decoder initialization, typically when a CXL enabled kernel boots.

Prevent a system hang and do not disable the HDM decoder if the decoder's CXL range is not found in a CFMWS window.

Note the change only fixes a hardware hang, but does not implement HPA/SPA translation. Support for this can be added in a follow on patch series.

---
    drivers/cxl/core/pci.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/pci.c +2 -2
index a0e7ed5ae25f..18616ca873e5 100644
@@ -478,8 +478,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
    	}
 
    	if (!allowed) {
-		cxl_set_mem_enable(cxlds, 0);
-		info->mem_enabled = 0;
+		dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
+		return -ENXIO;
    	}
 
    	/
#11 lore raw

Re: [Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

Quoted 24 lines · Zhijian Li (Fujitsu)
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 26 Mar 2024 08:26:21 +0000 "Zhijian Li (Fujitsu)"…

All guys,

In order to make the CXL memdev work again, i have to modify the QEMU side where it resets the "DVSEC CXL Control" during reboot. A draft changes is as below:

Per 8.1.3.2 DVSEC CXL Control (Offset 0Ch), Default value of BIT(2) is 0. So is it reasonable to have a reset dvsecs in QEMU during reboot?

Quoted 8 lines
Quoted 1 line

Any comments @Janathan

Hi,

Sorry it took me so long to get to this.

What are you attempting to do? Use an OS reboot on QEMU to check that the flows meant for BIOS configuration work -

Quoted 6 lines

There is no doubt that *the OS rebuilds the state correctly* is the OS's responsibility. Providing the consistent device state is the *Device*'s responsibility.

So on reboot, the device should have a consistent device state with a fresh boot. My changes intended to let *Device* emulated by QEMU provide a consistent device state.

Why? Typically the QEMU CXL enabling is for basic checkout not for real-world fidelity. If QEMU reboots do not result in restoring the same device configuration as a re-launching QEMU, why is that worth fixing? Just document it as a quirk. Now, if it is a simple fix, great, but it seems low priority given the enabling is really only useful for kernel development and relaunching QEMU is expected.

#12 lore raw

Re: [Problem ?] cxl list show nothing after reboot Re: [PATCH v2] cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window

Quoted 28 lines · Dan Williams
Quoted 27 lines · Zhijian Li (Fujitsu)
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 26 Mar 2024 08:26:21 +0000 "Zhijian Li (Fujitsu)"…

All guys,

In order to make the CXL memdev work again, i have to modify the QEMU side where it resets the "DVSEC CXL Control" during reboot. A draft changes is as below:

Per 8.1.3.2 DVSEC CXL Control (Offset 0Ch), Default value of BIT(2) is 0. So is it reasonable to have a reset dvsecs in QEMU during reboot?

Quoted 8 lines
Quoted 1 line

Any comments @Janathan

Hi,

Sorry it took me so long to get to this.

What are you attempting to do? Use an OS reboot on QEMU to check that the flows meant for BIOS configuration work -

There is no doubt that *the OS rebuilds the state correctly* is the OS's responsibility. Providing the consistent device state is the *Device*'s responsibility.

Quoted 7 lines
Quoted 3 lines

So on reboot, the device should have a consistent device state with a fresh boot. My changes intended to let *Device* emulated by QEMU provide a consistent device state.

Why? Typically the QEMU CXL enabling is for basic checkout not for real-world fidelity. If QEMU reboots do not result in restoring the same device configuration as a re-launching QEMU,

It was confirmed to be true in current QEMU, so we should fix the QEMU[1].

Quoted 2 lines

why is that worth fixing?> Just document it as a quirk. Now, if it is a simple fix, great, but i> seems low priority given the enabling is really only useful for kernel development and relaunching QEMU is expected.

Personally, QEMU deserves a better solution than relaunching.

[1] https://lore.kernel.org/all/[email protected]/