Skip to contentSkip to conversation

hw/cxl: Minor CXL emulation fixes and cleanup

PATCH Applied Jonathan Cameron 5 participants 16 messages Sep 4, 2023 – Sep 22, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/cxl: Minor CXL emulation fixes and cleanup

A small set gathering patches that have been posted and reviewed on list over the last few months. Looking to get these upstream before making any significant changes to the CXL emulation for this cycle.

More wide spread cleanup will follow later this cycle (reference updates to available spec and line length improvements).

Dave Jiang (1):
hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

Fan Ni (1):
hw/cxl/cxl_device: Replace magic number in CXLError definition

Li Zhijian (2):
hw/cxl: Fix CFMW config memory leak
docs/cxl: Change to lowercase as others

 docs/system/devices/cxl.rst  |  8 ++++----
 include/hw/cxl/cxl_device.h  |  2 +-
 hw/cxl/cxl-host.c            | 12 ++++++------
 hw/pci-bridge/cxl_upstream.c |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/4 hw/cxl: Fix CFMW config memory leak

From: Li Zhijian <[email protected]>

Allocate targets and targets[n] resources when all sanity checks are passed to avoid memory leaks.

---
 hw/cxl/cxl-host.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/cxl/cxl-host.c +6 -6
index 034c7805b3..f0920da956 100644
@@ -39,12 +39,6 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         return;
     }
 
-    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
-    for (i = 0, target = object->targets; target; i++, target = target->next) {
-        /* This link cannot be resolved yet, so stash the name for now */
-        fw->targets[i] = g_strdup(target->value);
-    }
-
     if (object->size % (256 * MiB)) {
         error_setg(errp,
                    "Size of a CXL fixed memory window must be a multiple of 256MiB");
@@ -64,6 +58,12 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         fw->enc_int_gran = 0;
     }
 
+    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
+    for (i = 0, target = object->targets; target; i++, target = target->next) {
+        /* This link cannot be resolved yet, so stash the name for now */
+        fw->targets[i] = g_strdup(target->value);
+    }
+
     cxl_state->fixed_windows = g_list_append(cxl_state->fixed_windows,
                                              g_steal_pointer(&fw));
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] hw/cxl: Fix CFMW config memory leak

Quoted 9 lines · Jonathan Cameron

From: Li Zhijian <[email protected]>

Allocate targets and targets[n] resources when all sanity checks are passed to avoid memory leaks.

Quoted 37 lines
---
 hw/cxl/cxl-host.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/cxl/cxl-host.c +6 -6
index 034c7805b3..f0920da956 100644
@@ -39,12 +39,6 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         return;
     }
 
-    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
-    for (i = 0, target = object->targets; target; i++, target = target->next) {
-        /* This link cannot be resolved yet, so stash the name for now */
-        fw->targets[i] = g_strdup(target->value);
-    }
-
     if (object->size % (256 * MiB)) {
         error_setg(errp,
                    "Size of a CXL fixed memory window must be a multiple of 256MiB");
@@ -64,6 +58,12 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         fw->enc_int_gran = 0;
     }
 
+    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
+    for (i = 0, target = object->targets; target; i++, target = target->next) {
+        /* This link cannot be resolved yet, so stash the name for now */
+        fw->targets[i] = g_strdup(target->value);
+    }
+
     cxl_state->fixed_windows = g_list_append(cxl_state->fixed_windows,
                                              g_steal_pointer(&fw));
 
Signature · 1 line
2.39.2
#3 lore raw

Re: [PATCH 1/4] hw/cxl: Fix CFMW config memory leak

In reply to Jonathan Cameron

04.09.2023 16:28, Jonathan Cameron via:

Quoted 5 lines

From: Li Zhijian <[email protected]>

Allocate targets and targets[n] resources when all sanity checks are passed to avoid memory leaks.

Quoted 7 lines
---
  hw/cxl/cxl-host.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

This one has been Cc'd qemu-stable, adding the tag.

/mjt

#4 lore raw

PATCH 2/4 hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

In reply to Jonathan Cameron

From: Dave Jiang <[email protected]>

According to ACPI spec 6.5 5.2.28.4 System Locality Latency and Bandwidth Information Structure, if the "Entry Base Unit" is 1024 for BW and the matrix entry has the value of 100, the BW is 100 GB/s. So the entry_base_unit should be changed from 1000 to 1024 given the comment notes it's 16GB/s for .latency_bandwidth.

Fixes 882877fc359d ("hw/pci-bridge/cxl-upstream: Add a CDAT table access DOE")
---
 hw/pci-bridge/cxl_upstream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-bridge/cxl_upstream.c +1 -1
index 9159f48a8c..2b9cf0cc97 100644
@@ -262,7 +262,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv)
                 .length = sslbis_size,
             },
             .data_type = HMATLB_DATA_TYPE_ACCESS_BANDWIDTH,
-            .entry_base_unit = 1000,
+            .entry_base_unit = 1024,
         },
     };
 
Signature · 1 line
2.39.2
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

Quoted 8 lines · Jonathan Cameron

From: Dave Jiang <[email protected]>

According to ACPI spec 6.5 5.2.28.4 System Locality Latency and Bandwidth Information Structure, if the "Entry Base Unit" is 1024 for BW and the matrix entry has the value of 100, the BW is 100 GB/s. So the entry_base_unit should be changed from 1000 to 1024 given the comment notes it's 16GB/s for .latency_bandwidth.

Quoted 6 lines
Fixes 882877fc359d ("hw/pci-bridge/cxl-upstream: Add a CDAT table access DOE")
---
  hw/pci-bridge/cxl_upstream.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron

From: Dave Jiang <[email protected]>

According to ACPI spec 6.5 5.2.28.4 System Locality Latency and Bandwidth Information Structure, if the "Entry Base Unit" is 1024 for BW and the matrix entry has the value of 100, the BW is 100 GB/s. So the entry_base_unit should be changed from 1000 to 1024 given the comment notes it's 16GB/s for .latency_bandwidth.

Fixes 882877fc359d ("hw/pci-bridge/cxl-upstream: Add a CDAT table access DOE")
Quoted 20 lines
---
 hw/pci-bridge/cxl_upstream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-bridge/cxl_upstream.c +1 -1
index 9159f48a8c..2b9cf0cc97 100644
@@ -262,7 +262,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv)
                 .length = sslbis_size,
             },
             .data_type = HMATLB_DATA_TYPE_ACCESS_BANDWIDTH,
-            .entry_base_unit = 1000,
+            .entry_base_unit = 1024,
         },
     };
 
Signature · 1 line
2.39.2
#7 lore raw

Re: [PATCH 2/4] hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

In reply to Jonathan Cameron

04.09.2023 16:28, Jonathan Cameron:

Quoted 20 lines

From: Dave Jiang <[email protected]>

According to ACPI spec 6.5 5.2.28.4 System Locality Latency and Bandwidth Information Structure, if the "Entry Base Unit" is 1024 for BW and the matrix entry has the value of 100, the BW is 100 GB/s. So the entry_base_unit should be changed from 1000 to 1024 given the comment notes it's 16GB/s for .latency_bandwidth.

Fixes 882877fc359d ("hw/pci-bridge/cxl-upstream: Add a CDAT table access DOE")
---
  hw/pci-bridge/cxl_upstream.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-bridge/cxl_upstream.c +0 -0
index 9159f48a8c..2b9cf0cc97 100644

hw/pci-bridge/cxl_upstream.c static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv) · line 267

Quoted 7 lines
hw/pci-bridge/cxl_upstream.c +1 -1
@@ -262,7 +262,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv)
                  .length = sslbis_size,
              },
              .data_type = HMATLB_DATA_TYPE_ACCESS_BANDWIDTH,
-            .entry_base_unit = 1000,
+            .entry_base_unit = 1024,
          },
      };

BTW, is this one stable-worthly? How it's been found, - due to some real issue or just by code review?

Thanks,

/mjt

#8 lore raw

Re: [PATCH 2/4] hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

Quoted 16 lines · Michael Tokarev

04.09.2023 16:28, Jonathan Cameron:

Quoted 15 lines

From: Dave Jiang <[email protected]>

According to ACPI spec 6.5 5.2.28.4 System Locality Latency and Bandwidth Information Structure, if the "Entry Base Unit" is 1024 for BW and the matrix entry has the value of 100, the BW is 100 GB/s. So the entry_base_unit should be changed from 1000 to 1024 given the comment notes it's 16GB/s for .latency_bandwidth.

Fixes 882877fc359d ("hw/pci-bridge/cxl-upstream: Add a CDAT table access DOE")

---
  hw/pci-bridge/cxl_upstream.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

hw/pci-bridge/cxl_upstream.c static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv) · line 267

Quoted 12 lines
hw/pci-bridge/cxl_upstream.c +1 -1
index 9159f48a8c..2b9cf0cc97 100644
@@ -262,7 +262,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv)
                   .length = sslbis_size,
               },
               .data_type = HMATLB_DATA_TYPE_ACCESS_BANDWIDTH,
-            .entry_base_unit = 1000,
+            .entry_base_unit = 1024,
           },
       };

BTW, is this one stable-worthly?  How it's been found, - due to some real issue or just by code review?

Code review. I was doing CXL CDAT parsing. So I guess I'm the first user. It's small enough that it won't make much of a difference for the resulting computed data. Mostly just correctness fixing.

Quoted 6 lines

Thanks,

/mjt

#9 lore raw

PATCH 3/4 hw/cxl/cxl_device: Replace magic number in CXLError definition

In reply to Jonathan Cameron

From: Fan Ni <[email protected]>

Replace the magic number 32 with CXL_RAS_ERR_HEADER_NUM for better code readability and maintainability.

---
 include/hw/cxl/cxl_device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/cxl/cxl_device.h +1 -1
index 1978730fba..fe8b46d9f7 100644
@@ -300,7 +300,7 @@ REG64(CXL_MEM_DEV_STS, 0)
 typedef struct CXLError {
     QTAILQ_ENTRY(CXLError) node;
     int type; /* Error code as per FE definition */
-    uint32_t header[32];
+    uint32_t header[CXL_RAS_ERR_HEADER_NUM];
 } CXLError;
 
 typedef QTAILQ_HEAD(, CXLError) CXLErrorList;
Signature · 1 line
2.39.2
Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] hw/cxl/cxl_device: Replace magic number in CXLError definition

Quoted 4 lines · Jonathan Cameron

From: Fan Ni <[email protected]>

Replace the magic number 32 with CXL_RAS_ERR_HEADER_NUM for better code readability and maintainability.

Thanks :)

Quoted 7 lines
---
  include/hw/cxl/cxl_device.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
#11 lore raw

PATCH 4/4 docs/cxl: Change to lowercase as others

In reply to Jonathan Cameron

From: Li Zhijian <[email protected]>

Using the same style as elsewhere for topology / topo

---
 docs/system/devices/cxl.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
docs/system/devices/cxl.rst +4 -4
index f12011e230..b742120657 100644
@@ -157,7 +157,7 @@ responsible for allocating appropriate ranges from within the CFMWs
 and exposing those via normal memory configurations as would be done
 for system RAM.
 
-Example system Topology. x marks the match in each decoder level::
+Example system topology. x marks the match in each decoder level::
 
   |<------------------SYSTEM PHYSICAL ADDRESS MAP (1)----------------->|
   |    __________   __________________________________   __________    |
@@ -187,8 +187,8 @@ Example system Topology. x marks the match in each decoder level::
        ___________|___   __________|__   __|_________   ___|_________
    (3)|  Root Port 0  | | Root Port 1 | | Root Port 2| | Root Port 3 |
       |  Appears in   | | Appears in  | | Appears in | | Appear in   |
-      |  PCI topology | | PCI Topology| | PCI Topo   | | PCI Topo    |
-      |  As 0c:00.0   | | as 0c:01.0  | | as de:00.0 | | as de:01.0  |
+      |  PCI topology | | PCI topology| | PCI topo   | | PCI topo    |
+      |  as 0c:00.0   | | as 0c:01.0  | | as de:00.0 | | as de:01.0  |
       |_______________| |_____________| |____________| |_____________|
             |                  |               |              |
             |                  |               |              |
@@ -272,7 +272,7 @@ Example topology involving a switch::
       |  Root Port 0  |
       |  Appears in   |
       |  PCI topology |
-      |  As 0c:00.0   |
+      |  as 0c:00.0   |
       |___________x___|
                   |
                   |
Signature · 1 line
2.39.2
Reviewed-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] docs/cxl: Change to lowercase as others

Quoted 10 lines · Jonathan Cameron

From: Li Zhijian <[email protected]>

Using the same style as elsewhere for topology / topo

---
  docs/system/devices/cxl.rst | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by on v1 4/4
#13 lore raw

Re: [PATCH 4/4] docs/cxl: Change to lowercase as others

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Li Zhijian <[email protected]>

Using the same style as elsewhere for topology / topo

---

Quoted 39 lines
 docs/system/devices/cxl.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
docs/system/devices/cxl.rst +4 -4
index f12011e230..b742120657 100644
@@ -157,7 +157,7 @@ responsible for allocating appropriate ranges from within the CFMWs
 and exposing those via normal memory configurations as would be done
 for system RAM.
 
-Example system Topology. x marks the match in each decoder level::
+Example system topology. x marks the match in each decoder level::
 
   |<------------------SYSTEM PHYSICAL ADDRESS MAP (1)----------------->|
   |    __________   __________________________________   __________    |
@@ -187,8 +187,8 @@ Example system Topology. x marks the match in each decoder level::
        ___________|___   __________|__   __|_________   ___|_________
    (3)|  Root Port 0  | | Root Port 1 | | Root Port 2| | Root Port 3 |
       |  Appears in   | | Appears in  | | Appears in | | Appear in   |
-      |  PCI topology | | PCI Topology| | PCI Topo   | | PCI Topo    |
-      |  As 0c:00.0   | | as 0c:01.0  | | as de:00.0 | | as de:01.0  |
+      |  PCI topology | | PCI topology| | PCI topo   | | PCI topo    |
+      |  as 0c:00.0   | | as 0c:01.0  | | as de:00.0 | | as de:01.0  |
       |_______________| |_____________| |____________| |_____________|
             |                  |               |              |
             |                  |               |              |
@@ -272,7 +272,7 @@ Example topology involving a switch::
       |  Root Port 0  |
       |  Appears in   |
       |  PCI topology |
-      |  As 0c:00.0   |
+      |  as 0c:00.0   |
       |___________x___|
                   |
                   |
Signature · 1 line
2.39.2
#14 lore raw
In reply to Jonathan Cameron

Cc'ing qemu-trivial@

Quoted 23 lines · Jonathan Cameron

A small set gathering patches that have been posted and reviewed on list over the last few months. Looking to get these upstream before making any significant changes to the CXL emulation for this cycle.

More wide spread cleanup will follow later this cycle (reference updates to available spec and line length improvements).

Dave Jiang (1):
hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

Fan Ni (1):
hw/cxl/cxl_device: Replace magic number in CXLError definition

Li Zhijian (2):
hw/cxl: Fix CFMW config memory leak
docs/cxl: Change to lowercase as others

  docs/system/devices/cxl.rst  |  8 ++++----
  include/hw/cxl/cxl_device.h  |  2 +-
  hw/cxl/cxl-host.c            | 12 ++++++------
  hw/pci-bridge/cxl_upstream.c |  2 +-
  4 files changed, 12 insertions(+), 12 deletions(-)
#15 lore raw
In reply to Jonathan Cameron
Quoted 17 lines · Jonathan Cameron via

A small set gathering patches that have been posted and reviewed on list over the last few months. Looking to get these upstream before making any significant changes to the CXL emulation for this cycle.

More wide spread cleanup will follow later this cycle (reference updates to available spec and line length improvements).

Dave Jiang (1):
hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS

Fan Ni (1):
hw/cxl/cxl_device: Replace magic number in CXLError definition

Li Zhijian (2):
hw/cxl: Fix CFMW config memory leak
docs/cxl: Change to lowercase as others

Quoted 6 lines
  docs/system/devices/cxl.rst  |  8 ++++----
  include/hw/cxl/cxl_device.h  |  2 +-
  hw/cxl/cxl-host.c            | 12 ++++++------
  hw/pci-bridge/cxl_upstream.c |  2 +-
  4 files changed, 12 insertions(+), 12 deletions(-)

Applied to my trivial-patches tree. Thank you!

/mjt