From nobody Wed May 15 17:41:48 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163400324562714.831862726575082; Mon, 11 Oct 2021 18:47:25 -0700 (PDT) Received: from localhost ([::1]:33104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ma6t2-0005bV-9M for importer@patchew.org; Mon, 11 Oct 2021 21:47:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ma6rg-0004pT-Hi; Mon, 11 Oct 2021 21:46:00 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ma6rd-0006wn-2v; Mon, 11 Oct 2021 21:46:00 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HSyzm47RDz8yfT; Tue, 12 Oct 2021 09:40:52 +0800 (CST) Received: from huawei.com (10.174.187.17) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Tue, 12 Oct 2021 09:45:41 +0800 From: MingWang Li To: , , Subject: [PATCH v2] hw/riscv: virt: bugfix the memory-backend-file command is invalid Date: Tue, 12 Oct 2021 09:45:01 +0800 Message-ID: <20211012014501.24996-1-limingwang@huawei.com> X-Mailer: git-send-email 2.19.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.17] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=limingwang@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Mingwang Li , qemu-devel@nongnu.org, jiangyifei@huawei.com, wanghaibin.wang@huawei.com, fanliang@huawei.com, wu.wubin@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1634003246380100001 Content-Type: text/plain; charset="utf-8" From: Mingwang Li When I start the VM with the following command: $ ./qemu-system-riscv64 -M virt,accel=3Dkvm -m 4096M -cpu host -nographic \ -name guest=3Driscv-guset \ -smp 2 \ -bios none \ -kernel ./Image \ -drive file=3D./guest.img,format=3Draw,id=3Dhd0 \ -device virtio-blk-device,drive=3Dhd0 \ -append "root=3D/dev/vda rw console=3DttyS0 earlycon=3Dsbi" \ -object memory-backend-file,id=3Dmem,size=3D4096M,mem-path=3D/dev/hugep= ages,share=3Don \ -numa node,memdev=3Dmem -mem-prealloc \ -chardev socket,id=3Dchar0,path=3D/mnt/vhost-net0 \ -netdev type=3Dvhost-user,id=3Dmynet1,chardev=3Dchar0,vhostforce \ -device virtio-net-pci,mac=3D52:54:00:00:00:01,netdev=3Dmynet1,mrg_rxbu= f=3Don,csum=3Don,guest_csum=3Don,guest_ecn=3Don \ Then, QEMU displays the following error information: qemu-system-riscv64: Failed initializing vhost-user memory map, consider us= ing -object memory-backend-file share=3Don qemu-system-riscv64: vhost_set_mem_table failed: Interrupted system call (4) qemu-system-riscv64: unable to start vhost net: 4: falling back on userspac= e virtio Note that, before starting the kvm-acceled QEMU VM, following temporarily unaccepted QEMU patches should be used: https://lists.gnu.org/archive/html/qemu-devel/2021-08/msg02516.html This error was made bacause default main_mem is used to be registered as the system memory, other memory cannot be initialized. Therefore, the system memory should be initialized to the machine->ram, which consists of the default main_mem and other possible memory required by applications, such as shared hugepage memory in DPDK. Also, the mc->defaul_ram_id should be set to the default main_mem, such as "riscv_virt_board.ram" for the virt machine. Signed-off-by: Mingwang Li Signed-off-by: Yifei Jiang Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index ec0cb69b8c..b3b431c847 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -771,7 +771,6 @@ static void virt_machine_init(MachineState *machine) const MemMapEntry *memmap =3D virt_memmap; RISCVVirtState *s =3D RISCV_VIRT_MACHINE(machine); MemoryRegion *system_memory =3D get_system_memory(); - MemoryRegion *main_mem =3D g_new(MemoryRegion, 1); MemoryRegion *mask_rom =3D g_new(MemoryRegion, 1); char *plic_hart_config, *soc_name; target_ulong start_addr =3D memmap[VIRT_DRAM].base; @@ -890,10 +889,8 @@ static void virt_machine_init(MachineState *machine) } =20 /* register system main memory (actual RAM) */ - memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram", - machine->ram_size, &error_fatal); memory_region_add_subregion(system_memory, memmap[VIRT_DRAM].base, - main_mem); + machine->ram); =20 /* create device tree */ create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, @@ -1032,6 +1029,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->cpu_index_to_instance_props =3D riscv_numa_cpu_index_to_props; mc->get_default_cpu_node_id =3D riscv_numa_get_default_cpu_node_id; mc->numa_mem_supported =3D true; + mc->default_ram_id =3D "riscv_virt_board.ram"; =20 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); =20 --=20 2.19.1