[PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU

Michael S. Tsirkin posted 75 patches 1 month, 1 week ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Dongjiu Geng <gengdongjiu1@gmail.com>, Stefano Garzarella <sgarzare@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Shannon Zhao <shannon.zhaosl@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Stefan Hajnoczi <stefanha@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Richard Henderson <richard.henderson@linaro.org>, Jason Wang <jasowang@redhat.com>, Yi Liu <yi.l.liu@intel.com>, "Clément Mathieu--Drif" <clement.mathieu--drif@eviden.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>, Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>, Jesper Devantier <foss@defmacro.it>, Fam Zheng <fam@euphon.net>, David Hildenbrand <david@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Luigi Rizzo <rizzo@iet.unipi.it>, Giuseppe Lettieri <g.lettieri@iet.unipi.it>, Vincenzo Maffione <v.maffione@gmail.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
[PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Michael S. Tsirkin 1 month, 1 week ago
From: peng guo <engguopeng@buaa.edu.cn>

When using a CXL Type 3 device together with a virtio 9p device in QEMU on a
physical server, the 9p device fails to initialize properly. The kernel reports
the following error:

    virtio: device uses modern interface but does not have VIRTIO_F_VERSION_1
    9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with error -22

Further investigation revealed that the 64-bit BAR space assigned to the 9pnet
device was overlapped by the memory window allocated for the CXL devices. As a
result, the kernel could not correctly access the BAR region, causing the
virtio device to malfunction.

An excerpt from /proc/iomem shows:

    480010000-cffffffff : CXL Window 0
      480010000-4bfffffff : PCI Bus 0000:00
      4c0000000-4c01fffff : PCI Bus 0000:0c
        4c0000000-4c01fffff : PCI Bus 0000:0d
      4c0200000-cffffffff : PCI Bus 0000:00
        4c0200000-4c0203fff : 0000:00:03.0
          4c0200000-4c0203fff : virtio-pci-modern

To address this issue, this patch adds the reserved memory end calculation
for cxl devices to reserve sufficient address space and ensure that CXL memory
windows are allocated beyond all PCI 64-bit BARs. This prevents overlap with
64-bit BARs regions such as those used by virtio or other pcie devices,
resolving the conflict.

QEMU Build Configuration:

    ./configure --prefix=/home/work/qemu_master/build/ \
                --target-list=x86_64-softmmu \
                --enable-kvm \
                --enable-virtfs

QEMU Boot Command:

    sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
        -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
        -hda /home/work/gp_qemu/rootfs.img \
        -virtfs local,path=/home/work/gp_qemu/share,mount_tag=host0,security_model=passthrough,id=host0 \
        -kernel /home/work/linux_output/arch/x86/boot/bzImage \
        --append "console=ttyS0 crashkernel=256M root=/dev/sda rootfstype=ext4 rw loglevel=8" \
        -object memory-backend-ram,id=vmem0,share=on,size=4096M \
        -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
        -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
        -device cxl-type3,bus=root_port13,volatile-memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
        -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G

Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a machine parameter")
Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/pc.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index bc048a6d13..eb36d50589 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -837,6 +837,7 @@ void pc_memory_init(PCMachineState *pcms,
     hwaddr maxphysaddr, maxusedaddr;
     hwaddr cxl_base, cxl_resv_end = 0;
     X86CPU *cpu = X86_CPU(first_cpu);
+    uint64_t res_mem_end;
 
     assert(machine->ram_size == x86ms->below_4g_mem_size +
                                 x86ms->above_4g_mem_size);
@@ -978,16 +979,17 @@ void pc_memory_init(PCMachineState *pcms,
 
     rom_set_fw(fw_cfg);
 
-    if (machine->device_memory) {
-        uint64_t *val = g_malloc(sizeof(*val));
-        uint64_t res_mem_end;
+    if (pcms->cxl_devices_state.is_enabled) {
+        res_mem_end = cxl_resv_end;
+    } else if (machine->device_memory) {
+        res_mem_end = machine->device_memory->base
+                      + memory_region_size(&machine->device_memory->mr);
+    } else {
+        res_mem_end = 0;
+    }
 
-        if (pcms->cxl_devices_state.is_enabled) {
-            res_mem_end = cxl_resv_end;
-        } else {
-            res_mem_end = machine->device_memory->base
-                          + memory_region_size(&machine->device_memory->mr);
-        }
+    if (res_mem_end) {
+        uint64_t *val = g_malloc(sizeof(*val));
         *val = cpu_to_le64(ROUND_UP(res_mem_end, 1 * GiB));
         fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
     }
-- 
MST
Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Michael Tokarev 1 month, 1 week ago
On 10/5/25 22:17, Michael S. Tsirkin wrote:
> From: peng guo <engguopeng@buaa.edu.cn>
> 
> When using a CXL Type 3 device together with a virtio 9p device in QEMU on a
> physical server, the 9p device fails to initialize properly. The kernel reports
> the following error:
> 
>      virtio: device uses modern interface but does not have VIRTIO_F_VERSION_1
>      9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with error -22
> 
> Further investigation revealed that the 64-bit BAR space assigned to the 9pnet
> device was overlapped by the memory window allocated for the CXL devices. As a
> result, the kernel could not correctly access the BAR region, causing the
> virtio device to malfunction.
> 
> An excerpt from /proc/iomem shows:
> 
>      480010000-cffffffff : CXL Window 0
>        480010000-4bfffffff : PCI Bus 0000:00
>        4c0000000-4c01fffff : PCI Bus 0000:0c
>          4c0000000-4c01fffff : PCI Bus 0000:0d
>        4c0200000-cffffffff : PCI Bus 0000:00
>          4c0200000-4c0203fff : 0000:00:03.0
>            4c0200000-4c0203fff : virtio-pci-modern
> 
> To address this issue, this patch adds the reserved memory end calculation
> for cxl devices to reserve sufficient address space and ensure that CXL memory
> windows are allocated beyond all PCI 64-bit BARs. This prevents overlap with
> 64-bit BARs regions such as those used by virtio or other pcie devices,
> resolving the conflict.
> 
> QEMU Build Configuration:
> 
>      ./configure --prefix=/home/work/qemu_master/build/ \
>                  --target-list=x86_64-softmmu \
>                  --enable-kvm \
>                  --enable-virtfs
> 
> QEMU Boot Command:
> 
>      sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
>          -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
>          -hda /home/work/gp_qemu/rootfs.img \
>          -virtfs local,path=/home/work/gp_qemu/share,mount_tag=host0,security_model=passthrough,id=host0 \
>          -kernel /home/work/linux_output/arch/x86/boot/bzImage \
>          --append "console=ttyS0 crashkernel=256M root=/dev/sda rootfstype=ext4 rw loglevel=8" \
>          -object memory-backend-ram,id=vmem0,share=on,size=4096M \
>          -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
>          -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
>          -device cxl-type3,bus=root_port13,volatile-memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
>          -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
> 
> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a machine parameter")
> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   hw/i386/pc.c | 20 +++++++++++---------
>   1 file changed, 11 insertions(+), 9 deletions(-)

Hi!

Is it qemu-stable material (10.0.x & 10.1.x)?

Thanks,

/mjt
Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Michael Tokarev 2 weeks, 3 days ago
On 10/6/25 20:08, Michael Tokarev wrote:
> On 10/5/25 22:17, Michael S. Tsirkin wrote:
>> From: peng guo <engguopeng@buaa.edu.cn>
>>
>> When using a CXL Type 3 device together with a virtio 9p device in 
>> QEMU on a
>> physical server, the 9p device fails to initialize properly. The 
>> kernel reports
>> the following error:
>>
>>      virtio: device uses modern interface but does not have 
>> VIRTIO_F_VERSION_1
>>      9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with 
>> error -22
>>
>> Further investigation revealed that the 64-bit BAR space assigned to 
>> the 9pnet
>> device was overlapped by the memory window allocated for the CXL 
>> devices. As a
>> result, the kernel could not correctly access the BAR region, causing the
>> virtio device to malfunction.
>>
>> An excerpt from /proc/iomem shows:
>>
>>      480010000-cffffffff : CXL Window 0
>>        480010000-4bfffffff : PCI Bus 0000:00
>>        4c0000000-4c01fffff : PCI Bus 0000:0c
>>          4c0000000-4c01fffff : PCI Bus 0000:0d
>>        4c0200000-cffffffff : PCI Bus 0000:00
>>          4c0200000-4c0203fff : 0000:00:03.0
>>            4c0200000-4c0203fff : virtio-pci-modern
>>
>> To address this issue, this patch adds the reserved memory end 
>> calculation
>> for cxl devices to reserve sufficient address space and ensure that 
>> CXL memory
>> windows are allocated beyond all PCI 64-bit BARs. This prevents 
>> overlap with
>> 64-bit BARs regions such as those used by virtio or other pcie devices,
>> resolving the conflict.
>>
>> QEMU Build Configuration:
>>
>>      ./configure --prefix=/home/work/qemu_master/build/ \
>>                  --target-list=x86_64-softmmu \
>>                  --enable-kvm \
>>                  --enable-virtfs
>>
>> QEMU Boot Command:
>>
>>      sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
>>          -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
>>          -hda /home/work/gp_qemu/rootfs.img \
>>          -virtfs local,path=/home/work/gp_qemu/ 
>> share,mount_tag=host0,security_model=passthrough,id=host0 \
>>          -kernel /home/work/linux_output/arch/x86/boot/bzImage \
>>          --append "console=ttyS0 crashkernel=256M root=/dev/sda 
>> rootfstype=ext4 rw loglevel=8" \
>>          -object memory-backend-ram,id=vmem0,share=on,size=4096M \
>>          -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
>>          -device cxl- 
>> rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
>>          -device cxl-type3,bus=root_port13,volatile- 
>> memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
>>          -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
>>
>> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a 
>> machine parameter")
>> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
>> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
>> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> ---
>>   hw/i386/pc.c | 20 +++++++++++---------
>>   1 file changed, 11 insertions(+), 9 deletions(-)
> 
> Hi!
> 
> Is it qemu-stable material (10.0.x & 10.1.x)?

A friendly ping for the stable series?

Thanks,

/mjt

Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Jonathan Cameron via 2 weeks, 2 days ago
On Tue, 28 Oct 2025 22:26:12 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> On 10/6/25 20:08, Michael Tokarev wrote:
> > On 10/5/25 22:17, Michael S. Tsirkin wrote:  
> >> From: peng guo <engguopeng@buaa.edu.cn>
> >>
> >> When using a CXL Type 3 device together with a virtio 9p device in 
> >> QEMU on a
> >> physical server, the 9p device fails to initialize properly. The 
> >> kernel reports
> >> the following error:
> >>
> >>      virtio: device uses modern interface but does not have 
> >> VIRTIO_F_VERSION_1
> >>      9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with 
> >> error -22
> >>
> >> Further investigation revealed that the 64-bit BAR space assigned to 
> >> the 9pnet
> >> device was overlapped by the memory window allocated for the CXL 
> >> devices. As a
> >> result, the kernel could not correctly access the BAR region, causing the
> >> virtio device to malfunction.
> >>
> >> An excerpt from /proc/iomem shows:
> >>
> >>      480010000-cffffffff : CXL Window 0
> >>        480010000-4bfffffff : PCI Bus 0000:00
> >>        4c0000000-4c01fffff : PCI Bus 0000:0c
> >>          4c0000000-4c01fffff : PCI Bus 0000:0d
> >>        4c0200000-cffffffff : PCI Bus 0000:00
> >>          4c0200000-4c0203fff : 0000:00:03.0
> >>            4c0200000-4c0203fff : virtio-pci-modern
> >>
> >> To address this issue, this patch adds the reserved memory end 
> >> calculation
> >> for cxl devices to reserve sufficient address space and ensure that 
> >> CXL memory
> >> windows are allocated beyond all PCI 64-bit BARs. This prevents 
> >> overlap with
> >> 64-bit BARs regions such as those used by virtio or other pcie devices,
> >> resolving the conflict.
> >>
> >> QEMU Build Configuration:
> >>
> >>      ./configure --prefix=/home/work/qemu_master/build/ \
> >>                  --target-list=x86_64-softmmu \
> >>                  --enable-kvm \
> >>                  --enable-virtfs
> >>
> >> QEMU Boot Command:
> >>
> >>      sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
> >>          -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
> >>          -hda /home/work/gp_qemu/rootfs.img \
> >>          -virtfs local,path=/home/work/gp_qemu/ 
> >> share,mount_tag=host0,security_model=passthrough,id=host0 \
> >>          -kernel /home/work/linux_output/arch/x86/boot/bzImage \
> >>          --append "console=ttyS0 crashkernel=256M root=/dev/sda 
> >> rootfstype=ext4 rw loglevel=8" \
> >>          -object memory-backend-ram,id=vmem0,share=on,size=4096M \
> >>          -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
> >>          -device cxl- 
> >> rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
> >>          -device cxl-type3,bus=root_port13,volatile- 
> >> memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
> >>          -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
> >>
> >> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a 
> >> machine parameter")
> >> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
> >> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> >> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
> >> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >> ---
> >>   hw/i386/pc.c | 20 +++++++++++---------
> >>   1 file changed, 11 insertions(+), 9 deletions(-)  
> > 
> > Hi!
> > 
> > Is it qemu-stable material (10.0.x & 10.1.x)?  
> 
> A friendly ping for the stable series?

I think it does make sense for stable.

Thanks,

Jonathan

> 
> Thanks,
> 
> /mjt
> 
Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Michael Tokarev 2 weeks, 2 days ago
29.10.2025 14:01, Jonathan Cameron via пишет:
> On Tue, 28 Oct 2025 22:26:12 +0300
> Michael Tokarev <mjt@tls.msk.ru> wrote:
> 
>> On 10/6/25 20:08, Michael Tokarev wrote:
>>> On 10/5/25 22:17, Michael S. Tsirkin wrote:
>>>> From: peng guo <engguopeng@buaa.edu.cn>
>>>>
>>>> When using a CXL Type 3 device together with a virtio 9p device in
>>>> QEMU on a
>>>> physical server, the 9p device fails to initialize properly. The
>>>> kernel reports
>>>> the following error:
>>>>
>>>>       virtio: device uses modern interface but does not have
>>>> VIRTIO_F_VERSION_1
>>>>       9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with
>>>> error -22
>>>>
>>>> Further investigation revealed that the 64-bit BAR space assigned to
>>>> the 9pnet
>>>> device was overlapped by the memory window allocated for the CXL
>>>> devices. As a
>>>> result, the kernel could not correctly access the BAR region, causing the
>>>> virtio device to malfunction.
>>>>
>>>> An excerpt from /proc/iomem shows:
>>>>
>>>>       480010000-cffffffff : CXL Window 0
>>>>         480010000-4bfffffff : PCI Bus 0000:00
>>>>         4c0000000-4c01fffff : PCI Bus 0000:0c
>>>>           4c0000000-4c01fffff : PCI Bus 0000:0d
>>>>         4c0200000-cffffffff : PCI Bus 0000:00
>>>>           4c0200000-4c0203fff : 0000:00:03.0
>>>>             4c0200000-4c0203fff : virtio-pci-modern
>>>>
>>>> To address this issue, this patch adds the reserved memory end
>>>> calculation
>>>> for cxl devices to reserve sufficient address space and ensure that
>>>> CXL memory
>>>> windows are allocated beyond all PCI 64-bit BARs. This prevents
>>>> overlap with
>>>> 64-bit BARs regions such as those used by virtio or other pcie devices,
>>>> resolving the conflict.
>>>>
>>>> QEMU Build Configuration:
>>>>
>>>>       ./configure --prefix=/home/work/qemu_master/build/ \
>>>>                   --target-list=x86_64-softmmu \
>>>>                   --enable-kvm \
>>>>                   --enable-virtfs
>>>>
>>>> QEMU Boot Command:
>>>>
>>>>       sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
>>>>           -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
>>>>           -hda /home/work/gp_qemu/rootfs.img \
>>>>           -virtfs local,path=/home/work/gp_qemu/
>>>> share,mount_tag=host0,security_model=passthrough,id=host0 \
>>>>           -kernel /home/work/linux_output/arch/x86/boot/bzImage \
>>>>           --append "console=ttyS0 crashkernel=256M root=/dev/sda
>>>> rootfstype=ext4 rw loglevel=8" \
>>>>           -object memory-backend-ram,id=vmem0,share=on,size=4096M \
>>>>           -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
>>>>           -device cxl-
>>>> rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
>>>>           -device cxl-type3,bus=root_port13,volatile-
>>>> memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
>>>>           -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
>>>>
>>>> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a
>>>> machine parameter")
>>>> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
>>>> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
>>>> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>> ---
>>>>    hw/i386/pc.c | 20 +++++++++++---------
>>>>    1 file changed, 11 insertions(+), 9 deletions(-)
>>>
>>> Hi!
>>>
>>> Is it qemu-stable material (10.0.x & 10.1.x)?
> 
> I think it does make sense for stable.

Aha.  I remember now why I had this question to begin with.

If it should be applied to 10.0.x series too (which is an LTS series),
I need help back-porting it before commit 8b1c560937467d0d9
"hw/i386/pc: Remove PCMachineClass::broken_reserved_end field"
which touches the same code.

If it's worth the effort to begin with.

Meanwhile I picked it up for 10.1.x.

Thank you!

/mjt

Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by Jonathan Cameron via 2 weeks ago
On Wed, 29 Oct 2025 17:10:55 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> 29.10.2025 14:01, Jonathan Cameron via пишет:
> > On Tue, 28 Oct 2025 22:26:12 +0300
> > Michael Tokarev <mjt@tls.msk.ru> wrote:
> >   
> >> On 10/6/25 20:08, Michael Tokarev wrote:  
> >>> On 10/5/25 22:17, Michael S. Tsirkin wrote:  
> >>>> From: peng guo <engguopeng@buaa.edu.cn>
> >>>>
> >>>> When using a CXL Type 3 device together with a virtio 9p device in
> >>>> QEMU on a
> >>>> physical server, the 9p device fails to initialize properly. The
> >>>> kernel reports
> >>>> the following error:
> >>>>
> >>>>       virtio: device uses modern interface but does not have
> >>>> VIRTIO_F_VERSION_1
> >>>>       9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with
> >>>> error -22
> >>>>
> >>>> Further investigation revealed that the 64-bit BAR space assigned to
> >>>> the 9pnet
> >>>> device was overlapped by the memory window allocated for the CXL
> >>>> devices. As a
> >>>> result, the kernel could not correctly access the BAR region, causing the
> >>>> virtio device to malfunction.
> >>>>
> >>>> An excerpt from /proc/iomem shows:
> >>>>
> >>>>       480010000-cffffffff : CXL Window 0
> >>>>         480010000-4bfffffff : PCI Bus 0000:00
> >>>>         4c0000000-4c01fffff : PCI Bus 0000:0c
> >>>>           4c0000000-4c01fffff : PCI Bus 0000:0d
> >>>>         4c0200000-cffffffff : PCI Bus 0000:00
> >>>>           4c0200000-4c0203fff : 0000:00:03.0
> >>>>             4c0200000-4c0203fff : virtio-pci-modern
> >>>>
> >>>> To address this issue, this patch adds the reserved memory end
> >>>> calculation
> >>>> for cxl devices to reserve sufficient address space and ensure that
> >>>> CXL memory
> >>>> windows are allocated beyond all PCI 64-bit BARs. This prevents
> >>>> overlap with
> >>>> 64-bit BARs regions such as those used by virtio or other pcie devices,
> >>>> resolving the conflict.
> >>>>
> >>>> QEMU Build Configuration:
> >>>>
> >>>>       ./configure --prefix=/home/work/qemu_master/build/ \
> >>>>                   --target-list=x86_64-softmmu \
> >>>>                   --enable-kvm \
> >>>>                   --enable-virtfs
> >>>>
> >>>> QEMU Boot Command:
> >>>>
> >>>>       sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
> >>>>           -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
> >>>>           -hda /home/work/gp_qemu/rootfs.img \
> >>>>           -virtfs local,path=/home/work/gp_qemu/
> >>>> share,mount_tag=host0,security_model=passthrough,id=host0 \
> >>>>           -kernel /home/work/linux_output/arch/x86/boot/bzImage \
> >>>>           --append "console=ttyS0 crashkernel=256M root=/dev/sda
> >>>> rootfstype=ext4 rw loglevel=8" \
> >>>>           -object memory-backend-ram,id=vmem0,share=on,size=4096M \
> >>>>           -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
> >>>>           -device cxl-
> >>>> rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
> >>>>           -device cxl-type3,bus=root_port13,volatile-
> >>>> memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
> >>>>           -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
> >>>>
> >>>> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a
> >>>> machine parameter")
> >>>> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
> >>>> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> >>>> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
> >>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >>>> ---
> >>>>    hw/i386/pc.c | 20 +++++++++++---------
> >>>>    1 file changed, 11 insertions(+), 9 deletions(-)  
> >>>
> >>> Hi!
> >>>
> >>> Is it qemu-stable material (10.0.x & 10.1.x)?  
> > 
> > I think it does make sense for stable.  
> 
> Aha.  I remember now why I had this question to begin with.
> 
> If it should be applied to 10.0.x series too (which is an LTS series),
> I need help back-porting it before commit 8b1c560937467d0d9
> "hw/i386/pc: Remove PCMachineClass::broken_reserved_end field"
> which touches the same code.

I don't have strong opinions either way. peng guo, if you happen
to be in a position to backport and test with QEMU LTS that would be
great.

Jonathan

> 
> If it's worth the effort to begin with.
> 
> Meanwhile I picked it up for 10.1.x.
> 
> Thank you!
> 
> /mjt
Re: [PULL 33/75] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU
Posted by peng guo via 1 week, 3 days ago
On Fri, Oct 31, 2025 at 10:13:15AM +0000, Jonathan Cameron wrote:
> On Wed, 29 Oct 2025 17:10:55 +0300
> Michael Tokarev <mjt@tls.msk.ru> wrote:
> 
> > 29.10.2025 14:01, Jonathan Cameron via пишет:
> > > On Tue, 28 Oct 2025 22:26:12 +0300
> > > Michael Tokarev <mjt@tls.msk.ru> wrote:
> > >   
> > >> On 10/6/25 20:08, Michael Tokarev wrote:  
> > >>> On 10/5/25 22:17, Michael S. Tsirkin wrote:  
> > >>>> From: peng guo <engguopeng@buaa.edu.cn>
> > >>>>
> > >>>> When using a CXL Type 3 device together with a virtio 9p device in
> > >>>> QEMU on a
> > >>>> physical server, the 9p device fails to initialize properly. The
> > >>>> kernel reports
> > >>>> the following error:
> > >>>>
> > >>>>       virtio: device uses modern interface but does not have
> > >>>> VIRTIO_F_VERSION_1
> > >>>>       9pnet_virtio virtio0: probe with driver 9pnet_virtio failed with
> > >>>> error -22
> > >>>>
> > >>>> Further investigation revealed that the 64-bit BAR space assigned to
> > >>>> the 9pnet
> > >>>> device was overlapped by the memory window allocated for the CXL
> > >>>> devices. As a
> > >>>> result, the kernel could not correctly access the BAR region, causing the
> > >>>> virtio device to malfunction.
> > >>>>
> > >>>> An excerpt from /proc/iomem shows:
> > >>>>
> > >>>>       480010000-cffffffff : CXL Window 0
> > >>>>         480010000-4bfffffff : PCI Bus 0000:00
> > >>>>         4c0000000-4c01fffff : PCI Bus 0000:0c
> > >>>>           4c0000000-4c01fffff : PCI Bus 0000:0d
> > >>>>         4c0200000-cffffffff : PCI Bus 0000:00
> > >>>>           4c0200000-4c0203fff : 0000:00:03.0
> > >>>>             4c0200000-4c0203fff : virtio-pci-modern
> > >>>>
> > >>>> To address this issue, this patch adds the reserved memory end
> > >>>> calculation
> > >>>> for cxl devices to reserve sufficient address space and ensure that
> > >>>> CXL memory
> > >>>> windows are allocated beyond all PCI 64-bit BARs. This prevents
> > >>>> overlap with
> > >>>> 64-bit BARs regions such as those used by virtio or other pcie devices,
> > >>>> resolving the conflict.
> > >>>>
> > >>>> QEMU Build Configuration:
> > >>>>
> > >>>>       ./configure --prefix=/home/work/qemu_master/build/ \
> > >>>>                   --target-list=x86_64-softmmu \
> > >>>>                   --enable-kvm \
> > >>>>                   --enable-virtfs
> > >>>>
> > >>>> QEMU Boot Command:
> > >>>>
> > >>>>       sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \
> > >>>>           -nographic -machine q35,cxl=on -enable-kvm -m 16G -smp 8 \
> > >>>>           -hda /home/work/gp_qemu/rootfs.img \
> > >>>>           -virtfs local,path=/home/work/gp_qemu/
> > >>>> share,mount_tag=host0,security_model=passthrough,id=host0 \
> > >>>>           -kernel /home/work/linux_output/arch/x86/boot/bzImage \
> > >>>>           --append "console=ttyS0 crashkernel=256M root=/dev/sda
> > >>>> rootfstype=ext4 rw loglevel=8" \
> > >>>>           -object memory-backend-ram,id=vmem0,share=on,size=4096M \
> > >>>>           -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
> > >>>>           -device cxl-
> > >>>> rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
> > >>>>           -device cxl-type3,bus=root_port13,volatile-
> > >>>> memdev=vmem0,id=cxl-vmem0,sn=0x123456789 \
> > >>>>           -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
> > >>>>
> > >>>> Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a
> > >>>> machine parameter")
> > >>>> Signed-off-by: peng guo <engguopeng@buaa.edu.cn>
> > >>>> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > >>>> Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn>
> > >>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > >>>> ---
> > >>>>    hw/i386/pc.c | 20 +++++++++++---------
> > >>>>    1 file changed, 11 insertions(+), 9 deletions(-)  
> > >>>
> > >>> Hi!
> > >>>
> > >>> Is it qemu-stable material (10.0.x & 10.1.x)?  
> > > 
> > > I think it does make sense for stable.  
> > 
> > Aha.  I remember now why I had this question to begin with.
> > 
> > If it should be applied to 10.0.x series too (which is an LTS series),
> > I need help back-porting it before commit 8b1c560937467d0d9
> > "hw/i386/pc: Remove PCMachineClass::broken_reserved_end field"
> > which touches the same code.
> 
> I don't have strong opinions either way. peng guo, if you happen
> to be in a position to backport and test with QEMU LTS that would be
> great.
> 
> Jonathan
Hi Jonathan,

I'll move forward with back-porting and testing with the QEMU LTS as
soon as possible.

Apologies for the delayed reply. I didn't have a computer and env before
because i was on vacation.

BR
Peng.

> 
> > 
> > If it's worth the effort to begin with.
> > 
> > Meanwhile I picked it up for 10.1.x.
> > 
> > Thank you!
> > 
> > /mjt