Skip to contentSkip to conversation

hw/cxl/cxl-host: Fix guest crash when getting cxl-fmw property

PATCH In review Zhao Liu 2 participants 4 messages Jul 4, 2024 – Jul 5, 2024

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

PATCH 1/1 hw/cxl/cxl-host: Fix guest crash when getting cxl-fmw property

From: Zhao Liu <[email protected]>

Guest crashes (Segmentation fault) when getting cxl-fmw property via qmp:

(QEMU) qom-get path=machine property=cxl-fmw

This issue is caused by accessing wrong callback (opaque) type in machine_get_cfmw().

cxl_machine_init() sets the callback as CXLState * type but machine_get_cfmw() treats the callback as CXLFixedMemoryWindowOptionsList **.

Fix this error by casting opaque to CXLState * type in machine_get_cfmw().

Fixes 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a machine parameter.")
---
 hw/cxl/cxl-host.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/cxl/cxl-host.c +2 -1
index c5f5fcfd64d0..e9f2543c43c6 100644
@@ -315,7 +315,8 @@ static void machine_set_cxl(Object *obj, Visitor *v, const char *name,
 static void machine_get_cfmw(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
 {
-    CXLFixedMemoryWindowOptionsList **list = opaque;
+    CXLState *state = opaque;
+    CXLFixedMemoryWindowOptionsList **list = &state->cfmw_list;
 
     visit_type_CXLFixedMemoryWindowOptionsList(v, name, list, errp);
 }
Signature · 1 line
2.34.1
Reviewed-by Xingtao Yao on v1 1/1
#1 lore raw
Quoted 51 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Zhao Liu
Sent: Thursday, July 4, 2024 5:34 PM
To: Jonathan Cameron <[email protected]>; Fan Ni <[email protected]>
Cc: [email protected]; [email protected]; Zhao Liu <[email protected]>
Subject: [PATCH] hw/cxl/cxl-host: Fix guest crash when getting cxl-fmw property

From: Zhao Liu <[email protected]>

Guest crashes (Segmentation fault) when getting cxl-fmw property via qmp:

(QEMU) qom-get path=machine property=cxl-fmw

This issue is caused by accessing wrong callback (opaque) type in machine_get_cfmw().

cxl_machine_init() sets the callback as CXLState * type but machine_get_cfmw() treats the callback as CXLFixedMemoryWindowOptionsList **.

Fix this error by casting opaque to CXLState * type in machine_get_cfmw().

Fixes 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a

machine parameter.")

---
 hw/cxl/cxl-host.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/cxl/cxl-host.c +2 -1
index c5f5fcfd64d0..e9f2543c43c6 100644
@@ -315,7 +315,8 @@ static void machine_set_cxl(Object *obj, Visitor *v, const
 char *name,
 static void machine_get_cfmw(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
 {
-    CXLFixedMemoryWindowOptionsList **list = opaque;
+    CXLState *state = opaque;
+    CXLFixedMemoryWindowOptionsList **list = &state->cfmw_list;
 
     visit_type_CXLFixedMemoryWindowOptionsList(v, name, list, errp);
Quoted 4 lines

}
--
2.34.1

Reviewed-by Li Zhijian on v1 1/1
#2 lore raw
In reply to Zhao Liu
Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Guest crashes (Segmentation fault) when getting cxl-fmw property via qmp:

IMO, it's fair to say "Guest crashes" which generally means the guest kernel panic etc. I'd prefer the subject like:
hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property

Otherwise,

Quoted 32 lines

(QEMU) qom-get path=machine property=cxl-fmw

This issue is caused by accessing wrong callback (opaque) type in machine_get_cfmw().

cxl_machine_init() sets the callback as CXLState * type but machine_get_cfmw() treats the callback as CXLFixedMemoryWindowOptionsList **.

Fix this error by casting opaque to CXLState * type in machine_get_cfmw().

Fixes 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a machine parameter.")
---
  hw/cxl/cxl-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/cxl/cxl-host.c +2 -1
index c5f5fcfd64d0..e9f2543c43c6 100644
@@ -315,7 +315,8 @@ static void machine_set_cxl(Object *obj, Visitor *v, const char *name,
  static void machine_get_cfmw(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp)
  {
-    CXLFixedMemoryWindowOptionsList **list = opaque;
+    CXLState *state = opaque;
+    CXLFixedMemoryWindowOptionsList **list = &state->cfmw_list;
 
      visit_type_CXLFixedMemoryWindowOptionsList(v, name, list, errp);
  }
#3 lore raw
Quoted 10 lines · On Fri, 5 Jul 2024 02:39:51 +0000 "Zhijian Li (Fujitsu)"…
Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Guest crashes (Segmentation fault) when getting cxl-fmw property via qmp:

IMO, it's fair to say "Guest crashes" which generally means the guest kernel panic etc. I'd prefer the subject like:
hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property

Agreed. I've picked this up and edited the description.

I've just hit send on a v2 of the misc minor fixes series with this replacing the patch that dropped cfmws_list

Thanks,

Jonathan

Quoted 39 lines

Otherwise,

Quoted 32 lines

(QEMU) qom-get path=machine property=cxl-fmw

This issue is caused by accessing wrong callback (opaque) type in machine_get_cfmw().

cxl_machine_init() sets the callback as CXLState * type but machine_get_cfmw() treats the callback as CXLFixedMemoryWindowOptionsList **.

Fix this error by casting opaque to CXLState * type in machine_get_cfmw().

Fixes 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a machine parameter.")
---
  hw/cxl/cxl-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/cxl/cxl-host.c +2 -1
index c5f5fcfd64d0..e9f2543c43c6 100644
@@ -315,7 +315,8 @@ static void machine_set_cxl(Object *obj, Visitor *v, const char *name,
  static void machine_get_cfmw(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp)
  {
-    CXLFixedMemoryWindowOptionsList **list = opaque;
+    CXLState *state = opaque;
+    CXLFixedMemoryWindowOptionsList **list = &state->cfmw_list;
 
      visit_type_CXLFixedMemoryWindowOptionsList(v, name, list, errp);