Skip to contentSkip to conversation

hw/cxl: Media Operation Discovery fixlets

PATCH In review Davidlohr Bueso 2 participants 5 messages Mar 19 – Mar 24

lore
Share & tools
lore
#0 lore raw

v3 cover hw/cxl: Media Operation Discovery fixlets

Hello,

Changes from v2: indent fix in patch 1. Added reviewed+fixes tags. Changes from v1: cleaned up comments in patch 2.

While working on the driver side of this, I tripped on two qemu issues around discovery semantics. I think this is the first time these code paths are exercised.

Davidlohr Bueso (2):
hw/cxl: Respect Media Operation max ops discovery semantics hw/cxl: Exclude Discovery from Media Operation Discovery output

 hw/cxl/cxl-mailbox-utils.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v3 1/2 hw/cxl: Respect Media Operation max ops discovery semantics

The Discovery rejects requests where start_index + num_ops exceeds the total number of supported operations. Per CXL 4.0 Table 8-332, num_ops is the "Maximum number of Media Operation to return" - a maximum, not an exact count. The device should return up to that many entries, not reject the request.

Cap num_ops to the available entries from start_index instead of erroring the command.

Fixes 77a8e9fe0ecb ("hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3)")
---
 hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
hw/cxl/cxl-mailbox-utils.c +11 -14
index a3143f3faa23..c628f775ac48 100644
@@ -2593,6 +2593,7 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
     } QEMU_PACKED *media_op_in_disc_pl = (void *)payload_in;
     struct media_op_discovery_out_pl *media_out_pl =
         (struct media_op_discovery_out_pl *)payload_out;
+    int total = ARRAY_SIZE(media_op_matrix);
     int num_ops, start_index, i;
     int count = 0;
 
@@ -2609,24 +2610,20 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
      * sub class command.
      */
     if (media_op_in_disc_pl->dpa_range_count ||
-        start_index + num_ops > ARRAY_SIZE(media_op_matrix)) {
+        start_index >= total) {
         return CXL_MBOX_INVALID_INPUT;
     }
 
     media_out_pl->dpa_range_granularity = CXL_CACHE_LINE_SIZE;
-    media_out_pl->total_supported_operations =
-                                     ARRAY_SIZE(media_op_matrix);
-    if (num_ops > 0) {
-        for (i = start_index; i < start_index + num_ops; i++) {
-            media_out_pl->entry[count].media_op_class =
-                    media_op_matrix[i].media_op_class;
-            media_out_pl->entry[count].media_op_subclass =
-                        media_op_matrix[i].media_op_subclass;
-            count++;
-            if (count == num_ops) {
-                break;
-            }
-        }
+    media_out_pl->total_supported_operations = total;
+
+    num_ops = MIN(num_ops, total - start_index);
+    for (i = 0; i < num_ops; i++) {
+        media_out_pl->entry[count].media_op_class =
+                media_op_matrix[start_index + i].media_op_class;
+        media_out_pl->entry[count].media_op_subclass =
+                media_op_matrix[start_index + i].media_op_subclass;
+        count++;
     }
 
     media_out_pl->num_of_supported_operations = count;
Signature · 1 line
2.39.5
#2 lore raw

PATCH v3 2/2 hw/cxl: Exclude Discovery from Media Operation Discovery output

In reply to Davidlohr Bueso

Per CXL 4.0 Table 8-331, the Discovery operation "returns a list of all Media Operations that the device supports, with the exception of the Discovery operation (Class=0, Subclass=0)."

Filter out Discovery entries when building the output list and adjust total_supported_operations accordingly.

Fixes 77a8e9fe0ecb ("hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3)")
---
 hw/cxl/cxl-mailbox-utils.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/cxl/cxl-mailbox-utils.c +5 -3
index c628f775ac48..9a5caf62417a 100644
@@ -2593,7 +2593,7 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
     } QEMU_PACKED *media_op_in_disc_pl = (void *)payload_in;
     struct media_op_discovery_out_pl *media_out_pl =
         (struct media_op_discovery_out_pl *)payload_out;
-    int total = ARRAY_SIZE(media_op_matrix);
+    int total = ARRAY_SIZE(media_op_matrix) - 1; /* exclude Discovery */
     int num_ops, start_index, i;
     int count = 0;
 
@@ -2619,10 +2619,12 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
 
     num_ops = MIN(num_ops, total - start_index);
     for (i = 0; i < num_ops; i++) {
+        int idx = start_index + i + 1; /* skip Discovery (first entry) */
+
         media_out_pl->entry[count].media_op_class =
-                media_op_matrix[start_index + i].media_op_class;
+                media_op_matrix[idx].media_op_class;
         media_out_pl->entry[count].media_op_subclass =
-                media_op_matrix[start_index + i].media_op_subclass;
+                media_op_matrix[idx].media_op_subclass;
         count++;
     }
 
Signature · 1 line
2.39.5
#3 lore raw
In reply to Davidlohr Bueso
Quoted 5 lines · Davidlohr Bueso

Hello,

Changes from v2: indent fix in patch 1. Added reviewed+fixes tags. Changes from v1: cleaned up comments in patch 2.

Quoted 7 lines

While working on the driver side of this, I tripped on two qemu issues around discovery semantics. I think this is the first time these code paths are exercised.

Davidlohr Bueso (2):
hw/cxl: Respect Media Operation max ops discovery semantics hw/cxl: Exclude Discovery from Media Operation Discovery output

Hi!

I'm picking this series up for qemu-stable (10.2.x).

Please let me know if I shouldn't.

Thanks,

/mjt

Quoted 3 lines
  hw/cxl/cxl-mailbox-utils.c | 27 +++++++++++++--------------
  1 file changed, 13 insertions(+), 14 deletions(-)
#4 lore raw
Quoted 10 lines · Michael Tokarev
Quoted 9 lines · Davidlohr Bueso

Hello,

Changes from v2: indent fix in patch 1. Added reviewed+fixes tags. Changes from v1: cleaned up comments in patch 2.

While working on the driver side of this, I tripped on two qemu issues around discovery semantics. I think this is the first time these code paths are exercised.

Quoted 8 lines
Quoted 3 lines

Davidlohr Bueso (2):
hw/cxl: Respect Media Operation max ops discovery semantics hw/cxl: Exclude Discovery from Media Operation Discovery output

Hi!

I'm picking this series up for qemu-stable (10.2.x).

Yes, please do. Thanks!