Skip to contentSkip to conversation

cxl: avoid KVM internal error for fixed memory windows

PATCH In review Li Chen 3 participants 9 messages Mar 17 – Mar 23

lore
Share & tools
lore

Li Chen

author
#0 lore raw

cover cxl: avoid KVM internal error for fixed memory windows

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0
author
#1 lore raw

PATCH 1/3 cxl/type3: expose vmem mapping for fixed windows

CXL fixed memory windows may map linearly to a Type-3 volatile memdev. Add a helper that checks whether a host physical range is backed by the volatile memory backend and returns the backing MemoryRegion and offset.

This is used by KVM to alias fixed windows to RAM when possible.

---
 hw/mem/cxl_type3.c          | 52 +++++++++++++++++++++++++++++++++++++
 include/hw/cxl/cxl_device.h |  3 +++
 2 files changed, 55 insertions(+)
hw/mem/cxl_type3.c +52 -0
index 4739239da3..bf79db6082 100644
@@ -1314,6 +1314,58 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     return address_space_write(as, dpa_offset, attrs, &data, size);
 }
 
+bool cxl_type3_get_window_vmem_mapping(CXLType3Dev *ct3d, hwaddr host_base,
+                                       hwaddr size, MemoryRegion **mr,
+                                       hwaddr *offset, Error **errp)
+{
+    MemoryRegion *vmr;
+    uint64_t dpa_start, dpa_end;
+    uint64_t vmr_size;
+    hwaddr host_end;
+
+    if (!size) {
+        error_setg(errp, "window size must be non-zero");
+        return false;
+    }
+
+    host_end = host_base + size - 1;
+    if (host_end < host_base) {
+        error_setg(errp, "window range overflows");
+        return false;
+    }
+
+    if (!ct3d->hostvmem) {
+        error_setg(errp, "no volatile-memdev configured");
+        return false;
+    }
+    vmr = host_memory_backend_get_memory(ct3d->hostvmem);
+    if (!vmr) {
+        error_setg(errp, "volatile-memdev has no backing memory region");
+        return false;
+    }
+
+    if (!cxl_type3_dpa(ct3d, host_base, &dpa_start) ||
+        !cxl_type3_dpa(ct3d, host_end, &dpa_end)) {
+        error_setg(errp, "failed to translate HPA to DPA");
+        return false;
+    }
+
+    if (dpa_end != dpa_start + size - 1) {
+        error_setg(errp, "window is not linearly mapped to DPA");
+        return false;
+    }
+
+    vmr_size = memory_region_size(vmr);
+    if (dpa_start >= vmr_size || size > vmr_size - dpa_start) {
+        error_setg(errp, "window maps outside volatile-memdev");
+        return false;
+    }
+
+    *mr = vmr;
+    *offset = dpa_start;
+    return true;
+}
+
 static void ct3d_reset(DeviceState *dev)
 {
     CXLType3Dev *ct3d = CXL_TYPE3(dev);
include/hw/cxl/cxl_device.h +3 -0
index 393f312217..5e3da17c10 100644
@@ -827,6 +827,9 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
                            unsigned size, MemTxAttrs attrs);
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
                             unsigned size, MemTxAttrs attrs);
+bool cxl_type3_get_window_vmem_mapping(CXLType3Dev *ct3d, hwaddr host_base,
+                                       hwaddr size, MemoryRegion **mr,
+                                       hwaddr *offset, Error **errp);
 
 uint64_t cxl_device_get_timestamp(CXLDeviceState *cxlds);
 
Signature · 1 line
2.52.0
author
#2 lore raw

PATCH 2/3 cxl: alias fixed memory windows to RAM under KVM

In reply to Li Chen

CXL fixed memory windows are currently modeled as an I/O MemoryRegion, so KVM treats the whole range as MMIO. After Linux onlines the window as system RAM, normal CPU stores can land in the window and trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Turn the fixed window into a container that always contains the existing MMIO dispatcher, and add an optional RAM alias overlay when the window maps linearly to a Type-3 volatile memdev.

---
 hw/cxl/cxl-host-stubs.c   |   1 +
 hw/cxl/cxl-host.c         | 189 +++++++++++++++++++++++++++++++++++++-
 include/hw/cxl/cxl.h      |   5 +
 include/hw/cxl/cxl_host.h |   1 +
 4 files changed, 194 insertions(+), 2 deletions(-)
hw/cxl/cxl-host-stubs.c +1 -0
index c015baac81..e7e955121f 100644
@@ -16,5 +16,6 @@ hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr)
     return base;
 };
 void cxl_fmws_update_mmio(void) {};
+void cxl_fmws_update_mappings(void) {};
 
 const MemoryRegionOps cfmws_ops;
hw/cxl/cxl-host.c +187 -2

213 lines not on this page · raw message

include/hw/cxl/cxl.h +5 -0
index 998f495a98..1ccd0f7e5f 100644
@@ -38,6 +38,11 @@ typedef struct CXLFixedWindow {
     uint8_t enc_int_gran;
     /* Todo: XOR based interleaving */
     MemoryRegion mr;
+    MemoryRegion io_mr;
+    MemoryRegion direct_mr;
+    MemoryRegion *direct_target_mr;
+    hwaddr direct_target_offset;
+    bool direct_mapped;
     hwaddr base;
 } CXLFixedWindow;
 #define TYPE_CXL_FMW "cxl-fmw"
include/hw/cxl/cxl_host.h +1 -0
index 21619bb748..7d5a384838 100644
@@ -18,6 +18,7 @@ void cxl_fmws_link_targets(Error **errp);
 void cxl_hook_up_pxb_registers(PCIBus *bus, CXLState *state, Error **errp);
 hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr);
 void cxl_fmws_update_mmio(void);
+void cxl_fmws_update_mappings(void);
 GSList *cxl_fmws_get_all_sorted(void);
 
 extern const MemoryRegionOps cfmws_ops;
Signature · 1 line
2.52.0
author
#3 lore raw

PATCH 3/3 cxl: update fixed window mappings on decoder programming

In reply to Li Chen

Invoke cxl_fmws_update_mappings() when HDM decoder registers are updated on host components and Type-3 devices, so fixed memory windows can switch between the MMIO dispatcher and the RAM alias overlay as the guest commits/uncommits decoder state.

---
 hw/cxl/cxl-component-utils.c | 2 ++
 hw/mem/cxl_type3.c           | 7 +++++++
 2 files changed, 9 insertions(+)
hw/cxl/cxl-component-utils.c +2 -0
index 07aabe331c..8a36a62db0 100644
@@ -12,6 +12,7 @@
 #include "qapi/error.h"
 #include "hw/pci/pci.h"
 #include "hw/cxl/cxl.h"
+#include "hw/cxl/cxl_host.h"
 
 /* CXL r3.1 Section 8.2.4.20.1 CXL HDM Decoder Capability Register */
 int cxl_decoder_count_enc(int count)
@@ -209,6 +210,7 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value,
         if (offset >= A_CXL_HDM_DECODER_CAPABILITY &&
             offset <= A_CXL_HDM_DECODER3_TARGET_LIST_HI) {
             dumb_hdm_handler(cxl_cstate, offset, value);
+            cxl_fmws_update_mappings();
         } else if (offset == A_CXL_BI_RT_CTRL ||
                    offset == A_CXL_BI_DECODER_CTRL) {
             bi_handler(cxl_cstate, offset, value);
hw/mem/cxl_type3.c +7 -0
index bf79db6082..8ad36e6f53 100644
@@ -29,6 +29,7 @@
 #include "system/hostmem.h"
 #include "system/numa.h"
 #include "hw/cxl/cxl.h"
+#include "hw/cxl/cxl_host.h"
 #include "hw/pci/msix.h"
 
 /* type3 device private */
@@ -628,6 +629,11 @@ static void ct3d_reg_write(void *opaque, hwaddr offset, uint64_t value,
     } else if (should_uncommit) {
         hdm_decoder_uncommit(ct3d, which_hdm);
     }
+
+    if (offset >= A_CXL_HDM_DECODER_CAPABILITY &&
+        offset <= A_CXL_HDM_DECODER3_TARGET_LIST_HI) {
+        cxl_fmws_update_mappings();
+    }
 }
 
 /*
@@ -1377,6 +1383,7 @@ static void ct3d_reset(DeviceState *dev)
     cxl_component_register_init_common(reg_state, write_msk,
                                        CXL2_TYPE3_DEVICE, ct3d->hdmdb);
     cxl_device_register_init_t3(ct3d, CXL_T3_MSIX_MBOX);
+    cxl_fmws_update_mappings();
 
     /*
      * Bring up an endpoint to target with MCTP over VDM.
Signature · 1 line
2.52.0
#4 lore raw
In reply to Li Chen
Quoted 7 lines · On Tue, 17 Mar 2026 11:33:00 +0800 Li Chen <[email protected]> wrote:

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Quoted 5 lines

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Hi Li Chen,

At least at first look this looks very like:

https://lore.kernel.org/qemu-devel/[email protected]/

Which was ready for merge as far as I was concerned, but missed getting queued for 11.0 (as last PCI pull request had gone) and is currently ready to go in next cycle.

Please see if that works for your case. If there are improvements I'd prefer to see them applied on top of that series than reinventing what I think is the same thing.

It's not KVM specific as linear mappings (when valid) bring huge performance benefits on TCG as well as correctness for KVM.

Jonathan

+CC linux-cxl which is where CXL folk tend to hang out in larger numbers than on the qemu list.

Quoted 58 lines

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)
#5 lore raw

On Tue, 17 Mar 2026 16:57:02 +0000
Jonathan Cameron <[email protected]> wrote:

Hi Li,

It looks like what you achieved is quite similar to what I have done in the patchset Jonathan shared earlier.

You have used memory_region_begin_transaction and memory_region_transaction_commit calls that I believe they are useful to be there given other examples I checked in the qemu code base.

I will be using those calls and will send another version. Also, please let me know if that patchset actually addresses your usecase and fix the bug you have in the cover letter.

Thanks,
Ali

Quoted 98 lines
Quoted 7 lines · On Tue, 17 Mar 2026 11:33:00 +0800 Li Chen <[email protected]> wrote:

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Quoted 5 lines

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Hi Li Chen,

At least at first look this looks very like:

https://lore.kernel.org/qemu-devel/[email protected]/

Which was ready for merge as far as I was concerned, but missed getting queued for 11.0 (as last PCI pull request had gone) and is currently ready to go in next cycle.

Please see if that works for your case. If there are improvements I'd prefer to see them applied on top of that series than reinventing what I think is the same thing.

It's not KVM specific as linear mappings (when valid) bring huge performance benefits on TCG as well as correctness for KVM.

Jonathan

+CC linux-cxl which is where CXL folk tend to hang out in larger numbers than on the qemu list.

Quoted 58 lines

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)
author
#6 lore raw

Hi Alireza,

---- On Wed, 18 Mar 2026 23:01:08 +0800 Alireza Sanaee <[email protected]> wrote ---

Quoted 10 lines

On Tue, 17 Mar 2026 16:57:02 +0000
Jonathan Cameron <[email protected]> wrote:

Hi Li,

It looks like what you achieved is quite similar to what I have done in the patchset Jonathan shared earlier.

You have used memory_region_begin_transaction and memory_region_transaction_commit calls that I believe they are useful to be there given other examples I checked in the qemu code base.

I will be using those calls and will send another version. Also, please let me know if that patchset actually addresses your usecase and fix the bug you have in the cover letter.

Yes, exactly! Your patchset addresses my use case issue perfectly. Thank you very much for your effort!

Regards,
Li

Quoted 103 lines

Thanks,
Ali

Quoted 98 lines
Quoted 7 lines · On Tue, 17 Mar 2026 11:33:00 +0800 Li Chen <[email protected]> wrote:

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Quoted 5 lines

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Hi Li Chen,

At least at first look this looks very like:

https://lore.kernel.org/qemu-devel/[email protected]/

Which was ready for merge as far as I was concerned, but missed getting queued for 11.0 (as last PCI pull request had gone) and is currently ready to go in next cycle.

Please see if that works for your case. If there are improvements I'd prefer to see them applied on top of that series than reinventing what I think is the same thing.

It's not KVM specific as linear mappings (when valid) bring huge performance benefits on TCG as well as correctness for KVM.

Jonathan

+CC linux-cxl which is where CXL folk tend to hang out in larger numbers than on the qemu list.

Quoted 58 lines

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)

Regards,

Li​

#7 lore raw

On Sun, 22 Mar 2026 13:46:44 +0800
Li Chen <[email protected]> wrote:

Super!

Quoted 126 lines

Hi Alireza,

---- On Wed, 18 Mar 2026 23:01:08 +0800 Alireza Sanaee <[email protected]> wrote ---

Quoted 10 lines

On Tue, 17 Mar 2026 16:57:02 +0000
Jonathan Cameron <[email protected]> wrote:

Hi Li,

It looks like what you achieved is quite similar to what I have done in the patchset Jonathan shared earlier.

You have used memory_region_begin_transaction and memory_region_transaction_commit calls that I believe they are useful to be there given other examples I checked in the qemu code base.

I will be using those calls and will send another version. Also, please let me know if that patchset actually addresses your usecase and fix the bug you have in the cover letter.

Yes, exactly! Your patchset addresses my use case issue perfectly. Thank you very much for your effort!

Regards,
Li

Quoted 103 lines

Thanks,
Ali

Quoted 98 lines
Quoted 7 lines · On Tue, 17 Mar 2026 11:33:00 +0800 Li Chen <[email protected]> wrote:

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Quoted 5 lines

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Hi Li Chen,

At least at first look this looks very like:

https://lore.kernel.org/qemu-devel/[email protected]/

Which was ready for merge as far as I was concerned, but missed getting queued for 11.0 (as last PCI pull request had gone) and is currently ready to go in next cycle.

Please see if that works for your case. If there are improvements I'd prefer to see them applied on top of that series than reinventing what I think is the same thing.

It's not KVM specific as linear mappings (when valid) bring huge performance benefits on TCG as well as correctness for KVM.

Jonathan

+CC linux-cxl which is where CXL folk tend to hang out in larger numbers than on the qemu list.

Quoted 58 lines

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)

Regards,

Li​

author
#8 lore raw
In reply to Jonathan Cameron

Hi Jonathan,

---- On Wed, 18 Mar 2026 00:57:02 +0800 Jonathan Cameron <[email protected]> wrote ---

Quoted 16 lines
Quoted 7 lines · On Tue, 17 Mar 2026 11:33:00 +0800 Li Chen <[email protected]> wrote:

CXL fixed memory windows are currently modeled as an I/O MemoryRegion. When running under KVM, this makes the entire window look like MMIO. If Linux onlines the window as system RAM (e.g. for a CXL Type-3 volatile memdev), normal CPU stores into the window trigger KVM instruction emulation. Instructions like XSAVEC are not supported by the emulator and abort the VM with a KVM internal error.

Quoted 5 lines

Repro:
- Boot a guest with a CXL Type-3 volatile memdev and a fixed memory window.
- In the guest, create a RAM region and online it as system RAM:

      cxl create-region -m -t ram -d decoder0.0 -w 1 -g 4096 mem0

- QEMU exits with a KVM internal error.

Quoted 5 lines

Hi Li Chen,

At least at first look this looks very like:

https://lore.kernel.org/qemu-devel/[email protected]/

Yes, I have tested the patchset, and it can addresses my issue. Thank you very much for the information!

Regards,
Li

Quoted 77 lines

Which was ready for merge as far as I was concerned, but missed getting queued for 11.0 (as last PCI pull request had gone) and is currently ready to go in next cycle.

Please see if that works for your case. If there are improvements I'd prefer to see them applied on top of that series than reinventing what I think is the same thing.

It's not KVM specific as linear mappings (when valid) bring huge performance benefits on TCG as well as correctness for KVM.

Jonathan

+CC linux-cxl which is where CXL folk tend to hang out in larger numbers than on the qemu list.

Quoted 58 lines

Serial output excerpt:
KVM internal error. Suberror: 1
extra data[0]: 0x0000000000000001
extra data[1]: 0xc0314061c70f480f
extra data[2]: 0x024080f610478b48
extra data[3]: 0x0000000000000400
extra data[4]: 0x000000010000000f
extra data[5]: 0x00000004a0003140
extra data[6]: 0x0000000000000000
extra data[7]: 0x0000000000000000
emulation failure
RAX=0000000000000007 RBX=ffff8eace0001a40 RCX=ffff8eace0003100 RDX=0000000000000000
RSI=0000000000000007 RDI=ffff8eace00030c0 RBP=ffffd48ac1747c08 RSP=ffffd48ac1747bc8
R8 =0000000000000007 R9 =0000000000000007 R10=000000000000000d R11=0000000000000000
R12=ffff8ea945b51a40 R13=ffffd48ac166c000 R14=0000000000000000 R15=0000000001200000
RIP=ffffffffaf77a14d RFL=00000256 [---ZAP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA]
SS =0018 0000000000000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 00007f997da3fec0 00000000 00000000
GS =0000 ffff8eab0535d000 00000000 00000000
LDT=0000 fffffe7600000000 00000000 00000000
TR =0040 fffffe767cf8f000 00004087 00008b00 DPL=0 TSS64-busy
GDT= fffffe767cf8d000 0000007f
IDT= fffffe0000000000 00000fff
CR0=80050033 CR2=000055fd193a6468 CR3=000000010930c000 CR4=00350ef0
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000001d01
Code=0f 1f 44 00 00 48 8b 4f 10 48 8b 41 08 48 89 c2 48 c1 ea 20 <48> 0f c7 61 40 31 c0 48 8b 47 10 f6 80 40 02 00 00 c0 74 1e 48 8b 05 98 f8 e8 01 48 89 47

This series keeps the existing MMIO dispatcher, but turns the fixed window into a container and (when the window maps linearly to a Type-3 volatile memdev) overlays a RAM alias so KVM can create a memslot for the range. The mapping is updated when HDM decoders are committed/uncommitted by the guest.

This patchset is based on master branch 559919ce54927d59b215a4665eda7ab6118a48aa

Local validation on this base confirmed that the issue reproduces without the series and is fixed with the 3 patches below.

Li Chen (3):
cxl/type3: expose vmem mapping for fixed windows
cxl: alias fixed memory windows to RAM under KVM
cxl: update fixed window mappings on decoder programming

 hw/cxl/cxl-component-utils.c |   2 +
 hw/cxl/cxl-host-stubs.c      |   1 +
 hw/cxl/cxl-host.c            | 189 ++++++++++++++++++++++++++++++++++-
 hw/mem/cxl_type3.c           |  59 +++++++++++
 include/hw/cxl/cxl.h         |   5 +
 include/hw/cxl/cxl_device.h  |   3 +
 include/hw/cxl/cxl_host.h    |   1 +
 7 files changed, 258 insertions(+), 2 deletions(-)