Skip to contentSkip to conversation

hw/cxl: Add tracing for component I/O region

PATCH In review Philippe Mathieu-Daudé 2 participants 8 messages Jan 22, 2025 – Jan 31, 2025

lore
Share & tools
lore
#0 lore raw

cover hw/cxl: Add tracing for component I/O region

Allow tracing component I/O accesses,
remove unused io_registers[] array.

Philippe Mathieu-Daudé (2):
hw/cxl: Remove unused component_registers::io_registers[] array hw/cxl: Allow tracing component I/O accesses

 include/hw/cxl/cxl_component.h |  4 ++--
 hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
 hw/cxl/Kconfig                 |  1 +
 3 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/2 hw/cxl: Remove unused component_registers::io_registers[] array

Avoid wasting 4K for each component, remove unused io_registers[].

---
 include/hw/cxl/cxl_component.h | 1 -
 1 file changed, 1 deletion(-)
include/hw/cxl/cxl_component.h +0 -1
index 945ee6ffd04..ac61c3f33a5 100644
@@ -218,7 +218,6 @@ typedef struct component_registers {
      *   0xe000 - 0xe3ff CXL ARB/MUX registers
      *   0xe400 - 0xffff RSVD
      */
-    uint32_t io_registers[CXL2_COMPONENT_IO_REGION_SIZE >> 2];
     MemoryRegion io;
 
     uint32_t cache_mem_registers[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
Signature · 1 line
2.47.1
Reviewed-by Jonathan Cameron on v1 1/2
#2 lore raw

Re: [PATCH 1/2] hw/cxl: Remove unused component_registers::io_registers[] array

Quoted 3 lines · On Wed, 22 Jan 2025 07:56:23 +0100 Philippe Mathieu-Daudé <[email protected]>…

Avoid wasting 4K for each component, remove unused io_registers[].

These may need to come back for correctness if anyone starts actually accessing them in the OS, but for now this is fine. We'd have to deal with filling them with plausible values anyway if that becomes an issue.

I can pick these up and send on in a set to mst, or mst pick up directly, or got through another tree. Don't mind!

Quoted 16 lines
---
 include/hw/cxl/cxl_component.h | 1 -
 1 file changed, 1 deletion(-)
include/hw/cxl/cxl_component.h +0 -1
index 945ee6ffd04..ac61c3f33a5 100644
@@ -218,7 +218,6 @@ typedef struct component_registers {
      *   0xe000 - 0xe3ff CXL ARB/MUX registers
      *   0xe400 - 0xffff RSVD
      */
-    uint32_t io_registers[CXL2_COMPONENT_IO_REGION_SIZE >> 2];
     MemoryRegion io;
 
     uint32_t cache_mem_registers[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
#3 lore raw

PATCH 2/2 hw/cxl: Allow tracing component I/O accesses

In reply to Philippe Mathieu-Daudé

Map the component I/O region as UnimplementedDevice to be able to trace guest I/O accesses with '-d unimp'.

---
 include/hw/cxl/cxl_component.h |  3 ++-
 hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
 hw/cxl/Kconfig                 |  1 +
 3 files changed, 14 insertions(+), 4 deletions(-)
include/hw/cxl/cxl_component.h +2 -1
index ac61c3f33a5..54fd369a838 100644
@@ -18,6 +18,7 @@
 #include "qemu/range.h"
 #include "hw/cxl/cxl_cdat.h"
 #include "hw/register.h"
+#include "hw/misc/unimp.h"
 #include "qapi/error.h"
 
 enum reg_type {
@@ -218,7 +219,7 @@ typedef struct component_registers {
      *   0xe000 - 0xe3ff CXL ARB/MUX registers
      *   0xe400 - 0xffff RSVD
      */
-    MemoryRegion io;
+    UnimplementedDeviceState io;
 
     uint32_t cache_mem_registers[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
     uint32_t cache_mem_regs_write_mask[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
hw/cxl/cxl-component-utils.c +11 -3
index cd116c04012..6d593475d00 100644
@@ -192,17 +192,25 @@ void cxl_component_register_block_init(Object *obj,
                                        const char *type)
 {
     ComponentRegisters *cregs = &cxl_cstate->crb;
+    DeviceState *io_dev;
+    SysBusDevice *io_sbd;
 
     memory_region_init(&cregs->component_registers, obj, type,
                        CXL2_COMPONENT_BLOCK_SIZE);
 
     /* io registers controls link which we don't care about in QEMU */
-    memory_region_init_io(&cregs->io, obj, NULL, NULL, ".io",
-                          CXL2_COMPONENT_IO_REGION_SIZE);
+    object_initialize_child(obj, "io", &cregs->io, TYPE_UNIMPLEMENTED_DEVICE);
+    io_dev = DEVICE(&cregs->io);
+    io_sbd = SYS_BUS_DEVICE(&cregs->io);
+    qdev_prop_set_string(io_dev, "name", ".io");
+    qdev_prop_set_uint64(io_dev, "size", CXL2_COMPONENT_IO_REGION_SIZE);
+    sysbus_realize(io_sbd, &error_fatal);
+
     memory_region_init_io(&cregs->cache_mem, obj, &cache_mem_ops, cxl_cstate,
                           ".cache_mem", CXL2_COMPONENT_CM_REGION_SIZE);
 
-    memory_region_add_subregion(&cregs->component_registers, 0, &cregs->io);
+    memory_region_add_subregion(&cregs->component_registers, 0,
+                                sysbus_mmio_get_region(io_sbd, 0));
     memory_region_add_subregion(&cregs->component_registers,
                                 CXL2_COMPONENT_IO_REGION_SIZE,
                                 &cregs->cache_mem);
hw/cxl/Kconfig +1 -0
index 8e67519b161..d6c7536001e 100644
@@ -1,3 +1,4 @@
 config CXL
     bool
     default y if PCI_EXPRESS
+    select UNIMP
Signature · 1 line
2.47.1
Reviewed-by Jonathan Cameron on v1 2/2
#4 lore raw

Re: [PATCH 2/2] hw/cxl: Allow tracing component I/O accesses

Quoted 4 lines · On Wed, 22 Jan 2025 07:56:24 +0100 Philippe Mathieu-Daudé <[email protected]>…

Map the component I/O region as UnimplementedDevice to be able to trace guest I/O accesses with '-d unimp'.

I'm not that familiar with this infrastructure but seems fine to me.

I'd definitely be curious if anything is touching this space so tracing may be helpful for that!

Quoted 69 lines
---
 include/hw/cxl/cxl_component.h |  3 ++-
 hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
 hw/cxl/Kconfig                 |  1 +
 3 files changed, 14 insertions(+), 4 deletions(-)
include/hw/cxl/cxl_component.h +2 -1
index ac61c3f33a5..54fd369a838 100644
@@ -18,6 +18,7 @@
 #include "qemu/range.h"
 #include "hw/cxl/cxl_cdat.h"
 #include "hw/register.h"
+#include "hw/misc/unimp.h"
 #include "qapi/error.h"
 
 enum reg_type {
@@ -218,7 +219,7 @@ typedef struct component_registers {
      *   0xe000 - 0xe3ff CXL ARB/MUX registers
      *   0xe400 - 0xffff RSVD
      */
-    MemoryRegion io;
+    UnimplementedDeviceState io;
 
     uint32_t cache_mem_registers[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
     uint32_t cache_mem_regs_write_mask[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
hw/cxl/cxl-component-utils.c +11 -3
index cd116c04012..6d593475d00 100644
@@ -192,17 +192,25 @@ void cxl_component_register_block_init(Object *obj,
                                        const char *type)
 {
     ComponentRegisters *cregs = &cxl_cstate->crb;
+    DeviceState *io_dev;
+    SysBusDevice *io_sbd;
 
     memory_region_init(&cregs->component_registers, obj, type,
                        CXL2_COMPONENT_BLOCK_SIZE);
 
     /* io registers controls link which we don't care about in QEMU */
-    memory_region_init_io(&cregs->io, obj, NULL, NULL, ".io",
-                          CXL2_COMPONENT_IO_REGION_SIZE);
+    object_initialize_child(obj, "io", &cregs->io, TYPE_UNIMPLEMENTED_DEVICE);
+    io_dev = DEVICE(&cregs->io);
+    io_sbd = SYS_BUS_DEVICE(&cregs->io);
+    qdev_prop_set_string(io_dev, "name", ".io");
+    qdev_prop_set_uint64(io_dev, "size", CXL2_COMPONENT_IO_REGION_SIZE);
+    sysbus_realize(io_sbd, &error_fatal);
+
     memory_region_init_io(&cregs->cache_mem, obj, &cache_mem_ops, cxl_cstate,
                           ".cache_mem", CXL2_COMPONENT_CM_REGION_SIZE);
 
-    memory_region_add_subregion(&cregs->component_registers, 0, &cregs->io);
+    memory_region_add_subregion(&cregs->component_registers, 0,
+                                sysbus_mmio_get_region(io_sbd, 0));
     memory_region_add_subregion(&cregs->component_registers,
                                 CXL2_COMPONENT_IO_REGION_SIZE,
                                 &cregs->cache_mem);
hw/cxl/Kconfig +1 -0
index 8e67519b161..d6c7536001e 100644
@@ -1,3 +1,4 @@
 config CXL
     bool
     default y if PCI_EXPRESS
+    select UNIMP
#5 lore raw

Re: [PATCH 2/2] hw/cxl: Allow tracing component I/O accesses

Quoted 6 lines · On Thu, 23 Jan 2025 09:51:51 +0000 Jonathan Cameron via…
Quoted 3 lines · On Wed, 22 Jan 2025 07:56:24 +0100 Philippe Mathieu-Daudé <[email protected]>…

Map the component I/O region as UnimplementedDevice to be able to trace guest I/O accesses with '-d unimp'.

Quoted 6 lines
Quoted 1 line

I'm not that familiar with this infrastructure but seems fine to me.

I'd definitely be curious if anything is touching this space so tracing may be helpful for that!

Hi Philippe

Quoted 2 lines

Retract that.

Can't instantiate a CXL device with this patch because:

Device unimplemented-device can not be dynamically instantiated.

Reverting this patch on my tree fixes that.

Quoted 71 lines
Quoted 69 lines
---
 include/hw/cxl/cxl_component.h |  3 ++-
 hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
 hw/cxl/Kconfig                 |  1 +
 3 files changed, 14 insertions(+), 4 deletions(-)
include/hw/cxl/cxl_component.h +2 -1
index ac61c3f33a5..54fd369a838 100644
@@ -18,6 +18,7 @@
 #include "qemu/range.h"
 #include "hw/cxl/cxl_cdat.h"
 #include "hw/register.h"
+#include "hw/misc/unimp.h"
 #include "qapi/error.h"
 
 enum reg_type {
@@ -218,7 +219,7 @@ typedef struct component_registers {
      *   0xe000 - 0xe3ff CXL ARB/MUX registers
      *   0xe400 - 0xffff RSVD
      */
-    MemoryRegion io;
+    UnimplementedDeviceState io;
 
     uint32_t cache_mem_registers[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
     uint32_t cache_mem_regs_write_mask[CXL2_COMPONENT_CM_REGION_SIZE >> 2];
hw/cxl/cxl-component-utils.c +11 -3
index cd116c04012..6d593475d00 100644
@@ -192,17 +192,25 @@ void cxl_component_register_block_init(Object *obj,
                                        const char *type)
 {
     ComponentRegisters *cregs = &cxl_cstate->crb;
+    DeviceState *io_dev;
+    SysBusDevice *io_sbd;
 
     memory_region_init(&cregs->component_registers, obj, type,
                        CXL2_COMPONENT_BLOCK_SIZE);
 
     /* io registers controls link which we don't care about in QEMU */
-    memory_region_init_io(&cregs->io, obj, NULL, NULL, ".io",
-                          CXL2_COMPONENT_IO_REGION_SIZE);
+    object_initialize_child(obj, "io", &cregs->io, TYPE_UNIMPLEMENTED_DEVICE);
+    io_dev = DEVICE(&cregs->io);
+    io_sbd = SYS_BUS_DEVICE(&cregs->io);
+    qdev_prop_set_string(io_dev, "name", ".io");
+    qdev_prop_set_uint64(io_dev, "size", CXL2_COMPONENT_IO_REGION_SIZE);
+    sysbus_realize(io_sbd, &error_fatal);
+
     memory_region_init_io(&cregs->cache_mem, obj, &cache_mem_ops, cxl_cstate,
                           ".cache_mem", CXL2_COMPONENT_CM_REGION_SIZE);
 
-    memory_region_add_subregion(&cregs->component_registers, 0, &cregs->io);
+    memory_region_add_subregion(&cregs->component_registers, 0,
+                                sysbus_mmio_get_region(io_sbd, 0));
     memory_region_add_subregion(&cregs->component_registers,
                                 CXL2_COMPONENT_IO_REGION_SIZE,
                                 &cregs->cache_mem);
hw/cxl/Kconfig +1 -0
index 8e67519b161..d6c7536001e 100644
@@ -1,3 +1,4 @@
 config CXL
     bool
     default y if PCI_EXPRESS
+    select UNIMP  
#6 lore raw

Re: [PATCH 2/2] hw/cxl: Allow tracing component I/O accesses

Quoted 18 lines · Jonathan Cameron
Quoted 6 lines · On Thu, 23 Jan 2025 09:51:51 +0000 Jonathan Cameron via…
Quoted 3 lines · On Wed, 22 Jan 2025 07:56:24 +0100 Philippe Mathieu-Daudé <[email protected]>…

Map the component I/O region as UnimplementedDevice to be able to trace guest I/O accesses with '-d unimp'.

Quoted 6 lines
Quoted 1 line

I'm not that familiar with this infrastructure but seems fine to me.

I'd definitely be curious if anything is touching this space so tracing may be helpful for that!

Hi Philippe

Quoted 1 line
Quoted 6 lines
Quoted 1 line

Retract that.

Can't instantiate a CXL device with this patch because:

Device unimplemented-device can not be dynamically instantiated.

Hmm the qtests using CXL devices pass, how do you trigger that?

Quoted 8 lines

Reverting this patch on my tree fixes that.

Quoted 5 lines
Quoted 5 lines
---
  include/hw/cxl/cxl_component.h |  3 ++-
  hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
  hw/cxl/Kconfig                 |  1 +
  3 files changed, 14 insertions(+), 4 deletions(-)
#7 lore raw

Re: [PATCH 2/2] hw/cxl: Allow tracing component I/O accesses

Quoted 19 lines · On Fri, 24 Jan 2025 17:28:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 18 lines · Jonathan Cameron
Quoted 6 lines · On Thu, 23 Jan 2025 09:51:51 +0000 Jonathan Cameron via…
Quoted 3 lines · On Wed, 22 Jan 2025 07:56:24 +0100 Philippe Mathieu-Daudé <[email protected]>…

Map the component I/O region as UnimplementedDevice to be able to trace guest I/O accesses with '-d unimp'.

Quoted 6 lines
Quoted 1 line

I'm not that familiar with this infrastructure but seems fine to me.

I'd definitely be curious if anything is touching this space so tracing may be helpful for that!

Hi Philippe

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Retract that.

Can't instantiate a CXL device with this patch because:

Device unimplemented-device can not be dynamically instantiated.

Hmm the qtests using CXL devices pass, how do you trigger that?

Seems oddly enough to be arm64 only (well not x86 - there is
no support for other arches than those two) which isn't upstream yet hence no tests upstream - I'll get back to that sometime soonish as the blocker of dt-bindings for PXBs may be less of an issue than it was.

source of that print seems to be hw/core/sysbus-fdt.c add_fdt_node(). Seems it is looking for sysbus devices and gets confused when it finds this one. I'm not sure if it is in /peripheral or /peripheral-anon.

For now you could try my gitlab tree
gitlab.com/jic23/qemu.git cxl-* whatever has latest date.

Or shout if you want me to try anything.

Jonathan

Quoted 10 lines
Quoted 9 lines

Reverting this patch on my tree fixes that.

Quoted 5 lines
Quoted 5 lines
---
  include/hw/cxl/cxl_component.h |  3 ++-
  hw/cxl/cxl-component-utils.c   | 14 +++++++++++---
  hw/cxl/Kconfig                 |  1 +
  3 files changed, 14 insertions(+), 4 deletions(-)