From nobody Sun Nov 16 00:54:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1762261412; cv=none; d=zohomail.com; s=zohoarc; b=EHTbKZNAFd/324wusRJjyxC3TRycQ5emEDi6tnW5aJx9RV9Oe6BmsppOQAhB0Cl+XSyo5zkCPcK8/6gpAdrOXd5BO+6ko3T17izQEnhtbLHz3tvqaPafxns/IruVxebWVbYYY+q4ARGuVFV0Z+KVth69MFRbDDdCLglN4uG+6us= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762261412; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=hDsYJwSrUQSIKlAGcFW4ij8ryQIk3foonnnymDpdnyA=; b=SynuWMKY93TisdMR+75QKNiuqJBRdqM+BZhcsDtlWVBPCBOzOSo3H1SaytJgaO5TK2Rvvj0kHCYs0iaw2Jwna7o5RGMtO3OCqR3YHxWAEwv/TRApVv6bSQ8DmHLIjD0ek5rSTooLCN+jokYV8DU1TUU+jTYlaZjIZ1CSjvyGSeg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762261412197907.4039168500495; Tue, 4 Nov 2025 05:03:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGGgg-0000Xy-B7; Tue, 04 Nov 2025 08:03:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGGgb-0000Xa-LN; Tue, 04 Nov 2025 08:02:58 -0500 Received: from azure-sdnproxy.icoremail.net ([52.229.205.26]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGGgV-00032k-9y; Tue, 04 Nov 2025 08:02:56 -0500 Received: from gp-VMware-Virtual-Platform.com (unknown [223.166.13.12]) by coremail-app1 (Coremail) with SMTP id OCz+CgCnag1r+QlpczgiAA--.13617S2; Tue, 04 Nov 2025 21:02:35 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=buaa.edu.cn; s=buaa; h=Received:From:To:Cc:Subject:Date: Message-ID:MIME-Version:Content-Transfer-Encoding; bh=hDsYJwSrUQ SIKlAGcFW4ij8ryQIk3foonnnymDpdnyA=; b=bsFq1vl8EmgmhOV8SqkpfH0WRM KKq6YEC2/IxSsu2hd0jrg4Nr7UHL8NA8at9wxHntOxQBJXqxsMn7lJfaQZ5kcesR Okwa30BbTseODa1X2j3ccs346gXq3hJxpP3RPN98JYo9XdH4ZdqkVqQ12+S3c4UE hpQNznQA6okD2P3Nw= To: mst@redhat.com Cc: pbonzini@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, qemu-stable@nongnu.org, wyguopeng@163.com, peng guo Subject: [PATCH Backport] hw/i386/pc: Avoid overlap between CXL window and PCI 64bit BARs in QEMU 10.0.x Date: Tue, 4 Nov 2025 21:02:27 +0800 Message-ID: <20251104130227.19183-1-engguopeng@buaa.edu.cn> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRAN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daVFxhVjvjDU0xZFpf9x0JU-_-PUUUUU= X-CM-SenderInfo: d2isijirrujqpexdthxhgxhubq/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=52.229.205.26; envelope-from=engguopeng@buaa.edu.cn; helo=azure-sdnproxy.icoremail.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: peng guo From: peng guo via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1762261419462158500 Content-Type: text/plain; charset="utf-8" This is a backport of the fix from commit 8b1c560937467d0d9 to the QEMU 10.0.x LTS series. 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 rep= orts 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 9p= net device was overlapped by the memory window allocated for the CXL devices. A= s 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 mem= ory 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. Tested on intel Granite Rapids(GNR) servers using QEMU 10.0 LTS, resolving the issue without causing regressions. QEMU Build Configuration: ./configure --prefix=3D/home/work/qemu_master/build/ \ --target-list=3Dx86_64-softmmu \ --enable-kvm \ --enable-virtfs QEMU Boot Command: sudo /home/work/qemu_master/qemu/build/qemu-system-x86_64 \ -nographic -machine q35,cxl=3Don -enable-kvm -m 16G -smp 8 \ -hda /home/work/gp_qemu/rootfs.img \ -virtfs local,path=3D/home/work/gp_qemu/share,mount_tag=3Dhost0,sec= urity_model=3Dpassthrough,id=3Dhost0 \ -kernel /home/work/linux_output/arch/x86/boot/bzImage \ --append "console=3DttyS0 crashkernel=3D256M root=3D/dev/sda rootfs= type=3Dext4 rw loglevel=3D8" \ -device pci-testdev,membar=3D2G \ -object memory-backend-ram,id=3Dvmem0,share=3Don,size=3D4096M \ -device pxb-cxl,bus_nr=3D12,bus=3Dpcie.0,id=3Dcxl.1 \ -device cxl-rp,port=3D0,bus=3Dcxl.1,id=3Droot_port13,chassis=3D0,sl= ot=3D2 \ -device cxl-type3,bus=3Droot_port13,volatile-memdev=3Dvmem0,id=3Dcx= l-vmem0,sn=3D0x123456789 \ -M cxl-fmw.0.targets.0=3Dcxl.1,cxl-fmw.0.size=3D4G Fixes: 03b39fcf64bc ("hw/cxl: Make the CXL fixed memory window setup a mach= ine parameter") Signed-off-by: peng guo Tested-by: peng guo Reviewed-by: Michael S. Tsirkin Message-ID: <20250805142300.15226-1-engguopeng@buaa.edu.cn> Signed-off-by: Michael S. Tsirkin (cherry picked from commit d1193481dee63442fc41e47ca6ebc4cd34f1f69c) --- hw/i386/pc.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 01d0581f62a3..502cf8a47dfb 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -840,6 +840,7 @@ void pc_memory_init(PCMachineState *pcms, hwaddr maxphysaddr, maxusedaddr; hwaddr cxl_base, cxl_resv_end =3D 0; X86CPU *cpu =3D X86_CPU(first_cpu); + uint64_t res_mem_end; =20 assert(machine->ram_size =3D=3D x86ms->below_4g_mem_size + x86ms->above_4g_mem_size); @@ -993,17 +994,19 @@ void pc_memory_init(PCMachineState *pcms, =20 rom_set_fw(fw_cfg); =20 - if (machine->device_memory) { - uint64_t *val =3D g_malloc(sizeof(*val)); - uint64_t res_mem_end =3D machine->device_memory->base; - + if (pcms->cxl_devices_state.is_enabled) { + res_mem_end =3D cxl_resv_end; + } else if (machine->device_memory) { + res_mem_end =3D machine->device_memory->base; if (!pcmc->broken_reserved_end) { res_mem_end +=3D memory_region_size(&machine->device_memory->m= r); } + } else { + res_mem_end =3D 0; + } =20 - if (pcms->cxl_devices_state.is_enabled) { - res_mem_end =3D cxl_resv_end; - } + if (res_mem_end) { + uint64_t *val =3D g_malloc(sizeof(*val)); *val =3D cpu_to_le64(ROUND_UP(res_mem_end, 1 * GiB)); fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*va= l)); } --=20 2.43.0