All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -qemu 0/4] hw/cxl: Mailbox fixes
@ 2026-11-30 15:45 Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 1/4] hw/cxl: Use runtime for bg cmd running semantics Davidlohr Bueso
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Davidlohr Bueso @ 2026-11-30 15:45 UTC (permalink / raw)
  To: mst, jic23; +Cc: junjie.cao, anisa.su, qemu-devel, linux-cxl, dave

Hello,

A few fixes for the CXL mailbox emulation, found while testing the
kernel's handling of background commands. Patch 3 depends on patch 2,
the others are independent.

Patch 1 fixes the Background Operation bit of the Mailbox Status
register, which reads as set from reset until the first background
command completes.

Patch 2 fixes the positions of the CEL command effect bits from bit 7
onwards, which are off by one.

Patch 3 sets CEL[11:10] Valid for the FM DCD commands, which report a
configuration change after a Conventional and a CXL Reset without it.

Patch 4 fixes Get Log for the CEL, which takes the Offset as a number
of entries and checks it against the wrong size, so that it returns
the wrong data and can read beyond the array. Found while adding
support to Component State Dump Log (for further testing of bg cmds).

Applies on top of v11.2.0-rc2.

Thanks,
Davidlohr

Davidlohr Bueso (4):
  hw/cxl: Use runtime for bg cmd running semantics
  hw/cxl: Fix CEL command effect bit positions
  hw/cxl: Set CEL[11:10] Valid for the FM DCD commands
  hw/cxl: Fix out of bounds read of the CEL in Get Log

 hw/cxl/cxl-device-utils.c    |  5 +----
 hw/cxl/cxl-mailbox-utils.c   | 14 +++++++++-----
 include/hw/cxl/cxl_mailbox.h | 11 +++++------
 3 files changed, 15 insertions(+), 15 deletions(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] hw/cxl: Use runtime for bg cmd running semantics
  2026-11-30 15:45 [PATCH -qemu 0/4] hw/cxl: Mailbox fixes Davidlohr Bueso
@ 2026-11-30 15:45 ` Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions Davidlohr Bueso
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Davidlohr Bueso @ 2026-11-30 15:45 UTC (permalink / raw)
  To: mst, jic23; +Cc: junjie.cao, anisa.su, qemu-devel, linux-cxl, dave

The current check incorrectly misses the 0% case, which semantically
can either be not running or one that just started. The runtime
is a better way to check for 0%, 100% or aborted. This is currently
benign in the kernel equivalent without cancel support.

Fixes: 98cbac128f1c ("hw/cxl: Support aborting background commands")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 hw/cxl/cxl-device-utils.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c
index e150d7445762..add0ab615976 100644
--- a/hw/cxl/cxl-device-utils.c
+++ b/hw/cxl/cxl-device-utils.c
@@ -95,13 +95,10 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)
         }
         if (offset == A_CXL_DEV_MAILBOX_STS) {
             uint64_t status_reg = cxl_dstate->mbox_reg_state64[offset / size];
-            int bgop;
 
             qemu_mutex_lock(&cci->bg.lock);
-            bgop = !(cci->bg.complete_pct == 100 || cci->bg.aborted);
-
             status_reg = FIELD_DP64(status_reg, CXL_DEV_MAILBOX_STS, BG_OP,
-                                    bgop);
+                                    !!cci->bg.runtime);
             cxl_dstate->mbox_reg_state64[offset / size] = status_reg;
             qemu_mutex_unlock(&cci->bg.lock);
         }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions
  2026-11-30 15:45 [PATCH -qemu 0/4] hw/cxl: Mailbox fixes Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 1/4] hw/cxl: Use runtime for bg cmd running semantics Davidlohr Bueso
@ 2026-11-30 15:45 ` Davidlohr Bueso
  2026-12-01 22:44   ` Anisa Su
  2026-11-30 15:45 ` [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 4/4] hw/cxl: Fix out of bounds read of the CEL in Get Log Davidlohr Bueso
  3 siblings, 1 reply; 7+ messages in thread
From: Davidlohr Bueso @ 2026-11-30 15:45 UTC (permalink / raw)
  To: mst, jic23; +Cc: junjie.cao, anisa.su, qemu-devel, linux-cxl, dave

The command effects from bit 7 onwards are off by one, and one of them
is there twice. Per CXL r4.0 Table 8-254 (CEL Entry Structure), bit 7
is Secondary Mailbox Supported, bit 8 Request Abort Background
Operation Supported, bit 9 CEL[11:10] Valid, and bits 10 and 11 the
configuration changes after a Conventional and after a CXL Reset.

As a result every abortable background command advertised Secondary
Mailbox Supported instead, so software could not find out that Request
Abort Background Operation applies to it, and the FM DCD commands set
the reserved bit 12.

Fixes: 98cbac128f1c ("hw/cxl: Support aborting background commands")
Fixes: 1befc7bde30d ("hw/cxl: mailbox-utils: 0x5602 - FMAPI Set DC Region Config")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 include/hw/cxl/cxl_mailbox.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
index a05d7cb5b7d1..752758219792 100644
--- a/include/hw/cxl/cxl_mailbox.h
+++ b/include/hw/cxl/cxl_mailbox.h
@@ -15,11 +15,10 @@
 #define CXL_MBOX_IMMEDIATE_LOG_CHANGE (1 << 4)
 #define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5)
 #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
-#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
-#define CXL_MBOX_SECONDARY_MBOX_SUPPORTED (1 << 8)
-#define CXL_MBOX_REQUEST_ABORT_BACKGROUND_OP_SUPPORTED (1 << 9)
-#define CXL_MBOX_CEL_10_TO_11_VALID (1 << 10)
-#define CXL_MBOX_CONFIG_CHANGE_CONV_RESET (1 << 11)
-#define CXL_MBOX_CONFIG_CHANGE_CXL_RESET (1 << 12)
+#define CXL_MBOX_SECONDARY_MBOX_SUPPORTED (1 << 7)
+#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 8)
+#define CXL_MBOX_CEL_10_TO_11_VALID (1 << 9)
+#define CXL_MBOX_CONFIG_CHANGE_CONV_RESET (1 << 10)
+#define CXL_MBOX_CONFIG_CHANGE_CXL_RESET (1 << 11)
 
 #endif
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands
  2026-11-30 15:45 [PATCH -qemu 0/4] hw/cxl: Mailbox fixes Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 1/4] hw/cxl: Use runtime for bg cmd running semantics Davidlohr Bueso
  2026-11-30 15:45 ` [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions Davidlohr Bueso
@ 2026-11-30 15:45 ` Davidlohr Bueso
  2026-12-01 23:25   ` Anisa Su
  2026-11-30 15:45 ` [PATCH 4/4] hw/cxl: Fix out of bounds read of the CEL in Get Log Davidlohr Bueso
  3 siblings, 1 reply; 7+ messages in thread
From: Davidlohr Bueso @ 2026-11-30 15:45 UTC (permalink / raw)
  To: mst, jic23; +Cc: junjie.cao, anisa.su, qemu-devel, linux-cxl, dave

Set DC Region Configuration, Initiate Dynamic Capacity Add and Initiate
Dynamic Capacity Release report a configuration change after a
Conventional and after a CXL Reset, bits 10 and 11 of their command
effects. Per CXL r4.0 Table 8-254 (CEL Entry Structure) those two bits
are only valid when bit 9, CEL[11:10] Valid, is set as well.

Fixes: 1befc7bde30d ("hw/cxl: mailbox-utils: 0x5602 - FMAPI Set DC Region Config")
Fixes: 42cbc937d4f6 ("hw/cxl: mailbox-utils: 0x5604 - FMAPI Initiate DC Add")
Fixes: fdd48ce20ce1 ("hw/cxl: mailbox-utils: 0x5605 - FMAPI Initiate DC Release")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 hw/cxl/cxl-mailbox-utils.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index cbd6ebf9fea2..5d225ff4dd28 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -4571,6 +4571,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
     [FMAPI_DCD_MGMT][SET_DC_REGION_CONFIG] = { "SET_DC_REGION_CONFIG",
         cmd_fm_set_dc_region_config, 16,
         (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
+         CXL_MBOX_CEL_10_TO_11_VALID |
          CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
          CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
          CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
@@ -4580,6 +4581,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
     [FMAPI_DCD_MGMT][INITIATE_DC_ADD] = { "INIT_DC_ADD",
         cmd_fm_initiate_dc_add, ~0,
         (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
+        CXL_MBOX_CEL_10_TO_11_VALID |
         CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
         CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
         CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
@@ -4587,6 +4589,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
     [FMAPI_DCD_MGMT][INITIATE_DC_RELEASE] = { "INIT_DC_RELEASE",
         cmd_fm_initiate_dc_release, ~0,
         (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
+         CXL_MBOX_CEL_10_TO_11_VALID |
          CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
          CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
          CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] hw/cxl: Fix out of bounds read of the CEL in Get Log
  2026-11-30 15:45 [PATCH -qemu 0/4] hw/cxl: Mailbox fixes Davidlohr Bueso
                   ` (2 preceding siblings ...)
  2026-11-30 15:45 ` [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands Davidlohr Bueso
@ 2026-11-30 15:45 ` Davidlohr Bueso
  3 siblings, 0 replies; 7+ messages in thread
From: Davidlohr Bueso @ 2026-11-30 15:45 UTC (permalink / raw)
  To: mst, jic23; +Cc: junjie.cao, anisa.su, qemu-devel, linux-cxl, dave

Get Log treats the Offset of a Command Effects Log request as a number
of entries, not of bytes: it is added to a pointer to the four byte
entries. It is then checked, as bytes, against the size of the whole
cel_log array, when the log is only as large as the entries built for
the CCI, which is what Get Supported Logs reports.

So a read at any Offset but zero returns the wrong data, one beyond the
log succeeds when the spec asks for Invalid Input, and the guest can
read up to four times the size of the array, most of it past its end.

Use the Offset in bytes, and check it against the size of the log.

Fixes: 056172691bbf ("hw/cxl/device: Add log commands (8.2.9.4) + CEL")
Fixes: a3de73c2a835 ("hw/cxl: Avoid accesses beyond the end of cel_log.")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 hw/cxl/cxl-mailbox-utils.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 5d225ff4dd28..f2dfdb9ca4eb 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -1206,18 +1206,19 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
      *   fields attempt to access beyond the size of the log as reported by Get
      *   Supported Log.
      *
-     * Only valid for there to be one entry per opcode, but the length + offset
-     * may still be greater than that if the inputs are not valid and so access
-     * beyond the end of cci->cel_log.
+     * The log is as large as the entries built for this CCI, which is what
+     * Get Supported Logs reports, not the cel_log array that holds them.
      */
-    if ((uint64_t)get_log->offset + get_log->length >= sizeof(cci->cel_log)) {
+    if ((uint64_t)get_log->offset + get_log->length >
+        sizeof(cci->cel_log[0]) * cci->cel_size) {
         return CXL_MBOX_INVALID_INPUT;
     }
 
     /* Store off everything to local variables so we can wipe out the payload */
     *len_out = get_log->length;
 
-    memmove(payload_out, cci->cel_log + get_log->offset, get_log->length);
+    memmove(payload_out, (uint8_t *)cci->cel_log + get_log->offset,
+            get_log->length);
 
     return CXL_MBOX_SUCCESS;
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions
  2026-11-30 15:45 ` [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions Davidlohr Bueso
@ 2026-12-01 22:44   ` Anisa Su
  0 siblings, 0 replies; 7+ messages in thread
From: Anisa Su @ 2026-12-01 22:44 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: mst, jic23, junjie.cao, qemu-devel, linux-cxl

On Mon, Nov 30, 2026 at 07:45:15AM -0800, Davidlohr Bueso wrote:
> The command effects from bit 7 onwards are off by one, and one of them
> is there twice. Per CXL r4.0 Table 8-254 (CEL Entry Structure), bit 7
> is Secondary Mailbox Supported, bit 8 Request Abort Background
> Operation Supported, bit 9 CEL[11:10] Valid, and bits 10 and 11 the
> configuration changes after a Conventional and after a CXL Reset.
> 
> As a result every abortable background command advertised Secondary
> Mailbox Supported instead, so software could not find out that Request
> Abort Background Operation applies to it, and the FM DCD commands set
> the reserved bit 12.
> 
> Fixes: 98cbac128f1c ("hw/cxl: Support aborting background commands")
> Fixes: 1befc7bde30d ("hw/cxl: mailbox-utils: 0x5602 - FMAPI Set DC Region Config")
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Thanks for fixing.
Reviewed-by: Anisa Su <anisa.su@samsung.com>
> ---
>  include/hw/cxl/cxl_mailbox.h | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> index a05d7cb5b7d1..752758219792 100644
> --- a/include/hw/cxl/cxl_mailbox.h
> +++ b/include/hw/cxl/cxl_mailbox.h
> @@ -15,11 +15,10 @@
>  #define CXL_MBOX_IMMEDIATE_LOG_CHANGE (1 << 4)
>  #define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5)
>  #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> -#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> -#define CXL_MBOX_SECONDARY_MBOX_SUPPORTED (1 << 8)
> -#define CXL_MBOX_REQUEST_ABORT_BACKGROUND_OP_SUPPORTED (1 << 9)
> -#define CXL_MBOX_CEL_10_TO_11_VALID (1 << 10)
> -#define CXL_MBOX_CONFIG_CHANGE_CONV_RESET (1 << 11)
> -#define CXL_MBOX_CONFIG_CHANGE_CXL_RESET (1 << 12)
> +#define CXL_MBOX_SECONDARY_MBOX_SUPPORTED (1 << 7)
> +#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 8)
> +#define CXL_MBOX_CEL_10_TO_11_VALID (1 << 9)
> +#define CXL_MBOX_CONFIG_CHANGE_CONV_RESET (1 << 10)
> +#define CXL_MBOX_CONFIG_CHANGE_CXL_RESET (1 << 11)
>  
>  #endif
> -- 
> 2.39.5
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands
  2026-11-30 15:45 ` [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands Davidlohr Bueso
@ 2026-12-01 23:25   ` Anisa Su
  0 siblings, 0 replies; 7+ messages in thread
From: Anisa Su @ 2026-12-01 23:25 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: mst, jic23, junjie.cao, qemu-devel, linux-cxl

On Mon, Nov 30, 2026 at 07:45:16AM -0800, Davidlohr Bueso wrote:
> Set DC Region Configuration, Initiate Dynamic Capacity Add and Initiate
> Dynamic Capacity Release report a configuration change after a
> Conventional and after a CXL Reset, bits 10 and 11 of their command
> effects. Per CXL r4.0 Table 8-254 (CEL Entry Structure) those two bits
> are only valid when bit 9, CEL[11:10] Valid, is set as well.
> 
> Fixes: 1befc7bde30d ("hw/cxl: mailbox-utils: 0x5602 - FMAPI Set DC Region Config")
> Fixes: 42cbc937d4f6 ("hw/cxl: mailbox-utils: 0x5604 - FMAPI Initiate DC Add")
> Fixes: fdd48ce20ce1 ("hw/cxl: mailbox-utils: 0x5605 - FMAPI Initiate DC Release")
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Thanks for fixing.
Reviewed-by: Anisa Su <anisa.su@samsung.com>
> ---
>  hw/cxl/cxl-mailbox-utils.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index cbd6ebf9fea2..5d225ff4dd28 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -4571,6 +4571,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
>      [FMAPI_DCD_MGMT][SET_DC_REGION_CONFIG] = { "SET_DC_REGION_CONFIG",
>          cmd_fm_set_dc_region_config, 16,
>          (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
> +         CXL_MBOX_CEL_10_TO_11_VALID |
>           CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
>           CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
>           CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
> @@ -4580,6 +4581,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
>      [FMAPI_DCD_MGMT][INITIATE_DC_ADD] = { "INIT_DC_ADD",
>          cmd_fm_initiate_dc_add, ~0,
>          (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
> +        CXL_MBOX_CEL_10_TO_11_VALID |
>          CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
>          CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
>          CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
> @@ -4587,6 +4589,7 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
>      [FMAPI_DCD_MGMT][INITIATE_DC_RELEASE] = { "INIT_DC_RELEASE",
>          cmd_fm_initiate_dc_release, ~0,
>          (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
> +         CXL_MBOX_CEL_10_TO_11_VALID |
>           CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
>           CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
>           CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
> -- 
> 2.39.5
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-01 23:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 15:45 [PATCH -qemu 0/4] hw/cxl: Mailbox fixes Davidlohr Bueso
2026-11-30 15:45 ` [PATCH 1/4] hw/cxl: Use runtime for bg cmd running semantics Davidlohr Bueso
2026-11-30 15:45 ` [PATCH 2/4] hw/cxl: Fix CEL command effect bit positions Davidlohr Bueso
2026-12-01 22:44   ` Anisa Su
2026-11-30 15:45 ` [PATCH 3/4] hw/cxl: Set CEL[11:10] Valid for the FM DCD commands Davidlohr Bueso
2026-12-01 23:25   ` Anisa Su
2026-11-30 15:45 ` [PATCH 4/4] hw/cxl: Fix out of bounds read of the CEL in Get Log Davidlohr Bueso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.