From nobody Sun Jul 26 13:29:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1781262241; cv=none; d=zohomail.com; s=zohoarc; b=OTs7uoPsFga4m1NfPkC09o5QAA/+zweuE9e739KxHgFBtfXzJTY4eqA73V5aSq8Ksa4oevUr9YsYvH3Cra/tqo9SVZN7SVRze4NHTbNo08dE0aWN5aKPiJstZH5CvXXFpv3ynjhMegiaaj/fqbY87icafAr3xdGl/7NQy1szRiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781262241; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3kVl/pTwoeqYvE7JfzO0Xo2V9g6eW0C/dnKycWsXo0U=; b=eIJ6yw8NvrdsB9Byo9QMzitXSwytYiKObEQhUKDqhvFt87G+Rygdz2x3NcgBfTDih8QduLPgJRdQDThx26DD87xcLftyq0xEQmEXXw+z/U+QBbSkrCmkPW7fewtYgKrSNQPaoqaR9q6Lsy0Dn6OFv/F450pT5ynPAyCZxDcHwz0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781262241462408.07302211241176; Fri, 12 Jun 2026 04:04:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wXzft-0003Vp-UX; Fri, 12 Jun 2026 07:03:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXzfr-0003Uo-QP for qemu-devel@nongnu.org; Fri, 12 Jun 2026 07:03:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXzfm-0001FM-Ck for qemu-devel@nongnu.org; Fri, 12 Jun 2026 07:03:40 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-ihGY4vHmMz66KL8Al3K-qg-1; Fri, 12 Jun 2026 07:03:36 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8932B19540E1; Fri, 12 Jun 2026 11:03:34 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.rmtau.csb (unknown [10.64.136.3]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBBCD1955BC4; Fri, 12 Jun 2026 11:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781262217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3kVl/pTwoeqYvE7JfzO0Xo2V9g6eW0C/dnKycWsXo0U=; b=BxPVfbn7lXeq5O9ii/Nws4z1rgfdv3v1cGFQh5dfdbbk3ytDZiVo9F9y2IWYf03h4mZSLc 1TtFKSh60TA6QwLNfOrHzapPuJZQ1XPGvogKbKey9o+cVJtaDUFHbNm7AJB1SFDOiMAr08 lWv4MNNWX4nQx1x+iLeWrv2R0q3cBlk= X-MC-Unique: ihGY4vHmMz66KL8Al3K-qg-1 X-Mimecast-MFC-AGG-ID: ihGY4vHmMz66KL8Al3K-qg_1781262214 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peterx@redhat.com, mst@redhat.com, peter.maydell@linaro.org, berrange@redhat.com, david@kernel.org, alex@shazbot.org, clg@redhat.com, pbonzini@redhat.com, philmd@mailo.com, phrdina@redhat.com, jugraham@redhat.com, shan.gavin@gmail.com Subject: [PATCH 1/2] system/memory: Use __builtin_mem{cpy, move} in accessors of ram device region Date: Fri, 12 Jun 2026 21:03:06 +1000 Message-ID: <20260612110307.1264798-2-gshan@redhat.com> In-Reply-To: <20260612110307.1264798-1-gshan@redhat.com> References: <20260612110307.1264798-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1781262244287158500 Content-Type: text/plain; charset="utf-8" All ram device regions was turned to be indirectly accessible by commit 4a2e242bbb ("memory: Don't use memcpy for ram_device regions"). This leads to guest hang on compiling 'cuda-samples' as reported by Julia. The guest is started by the following command lines, with a GH100 GPU card. host$ lspci | grep GH100 0009:01:00.0 3D controller: NVIDIA Corporation GH100 [GH200 120GB / 480G= B] (rev a1) host$ /home/sandbox/gavin/qemu.main/build/qemu-system-aarch64 = \ -machine virt,gic-version=3Dhost,ras=3Don,highmem-mmio-size=3D4T = \ -accel kvm -cpu host -smp cpus=3D48 -m size=3D8G = \ -drive file=3D/home/gavin/sandbox/images/disk.qcow2,if=3Dnone,id= =3Dd0 \ -device virtio-blk-pci,id=3Dvb0,bus=3Dpcie.0,drive=3Dd0,num-queues= =3D4 \ -device vfio-pci-nohotplug,host=3D0009:01:00.0,bus=3Dpcie.1.0 : guest$ cd cuda-samples/build guest$ make -j 20 clean guest$ make -j 20 : [ 54%] Linking CUDA executable graphMemoryNodes [ 54%] Built target graphMemoryNodes guest$ qemu-system-aarch64: virtio: bogus descriptor or out of resources [ 555.814025] virtio_blk virtio0: [vda] new size: 268435456 512-byte lo= gical blocks (137 GB/128 GiB) When the GPU's driver (NVidia open driver) is loaded on guest bootup, the memory blocks residing in the PCI BAR#4 can be presented to the guest through memory hot-add. The page cache can be allocated from the hot added memory blocks when cuda-samples is being compiled. Afterwards, the page cache is sent to QEMU's virtio-blk device as part of the DMA request, the bounce buffer has to be used to accomodate the request as the corresponding memory region (MemoryRegion) is a RAM DEVICE region and indirectly accessible in qemu. However, the max bounce bufer size is only 4096 bytes by default. We're running out of that space quickly. QEMU =3D=3D=3D=3D virtio_blk_handle_output virtio_blk_handle_vq virtio_blk_get_request virtqueue_pop virtqueue_split_pop virtqueue_map_desc address_space_map memory_access_is_direct # Return false memory_region_supports_direct_access (qemu) info mtree memory-region: pci_bridge_pci 0000000000000000-ffffffffffffffff (prio 0, container): pci_bridge_pci 0000042000000000-0000043fffffffff (prio 1, i/o): 0009:01:00.0 base BA= R 4 0000042000000000-0000043fffffffff (prio 0, i/o): 0009:01:00.0 BAR 4 0000042000000000-000004379fffffff (prio 0, ramd): 0009:01:00.0 BA= R 4 mmaps[0] This replaces mem{cpy, move} with __builtin_mem{cpy, move} in the memory accessors to ram device memory region, preparatory work to make ram device region directly accessible and bypass the bounce buffer in the DMA path in next patch. Reported-by: Julia Graham Suggested-by: Michael S. Tsirkin Suggested-by: Peter Xu Signed-off-by: Gavin Shan --- hw/remote/vfio-user-obj.c | 4 ++-- include/system/memory.h | 42 ++++++++++++++++++++++++++++++++++++++- system/physmem.c | 8 ++++---- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 87fa7b6572..fe6f661fe2 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -375,9 +375,9 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *= buf, hwaddr offset, ram_ptr =3D memory_region_get_ram_ptr(mr); =20 if (is_write) { - memcpy((ram_ptr + offset), buf, size); + address_space_memcpy(ram_ptr + offset, buf, size); } else { - memcpy(buf, (ram_ptr + offset), size); + address_space_memcpy(buf, ram_ptr + offset, size); } =20 return 0; diff --git a/include/system/memory.h b/include/system/memory.h index 1417132f6d..6bb2e13eea 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2938,6 +2938,46 @@ static inline bool memory_access_is_direct(const Mem= oryRegion *mr, return true; } =20 +static inline void address_space_memcpy(void *dest, const void *src, size_= t n) +{ + switch (n) { + case 1: + __builtin_memcpy(dest, src, 1); + break; + case 2: + __builtin_memcpy(dest, src, 2); + break; + case 4: + __builtin_memcpy(dest, src, 4); + break; + case 8: + __builtin_memcpy(dest, src, 8); + break; + default: + __builtin_memcpy(dest, src, n); + } +} + +static inline void address_space_memmove(void *dest, const void *src, size= _t n) +{ + switch (n) { + case 1: + __builtin_memmove(dest, src, 1); + break; + case 2: + __builtin_memmove(dest, src, 2); + break; + case 4: + __builtin_memmove(dest, src, 4); + break; + case 8: + __builtin_memmove(dest, src, 8); + break; + default: + __builtin_memmove(dest, src, n); + } +} + /** * address_space_read: read from an address space. * @@ -2970,7 +3010,7 @@ MemTxResult address_space_read(AddressSpace *as, hwad= dr addr, mr =3D flatview_translate(fv, addr, &addr1, &l, false, attrs); if (len =3D=3D l && memory_access_is_direct(mr, false, attrs))= { ptr =3D qemu_map_ram_ptr(mr->ram_block, addr1); - memcpy(buf, ptr, len); + __builtin_memcpy(buf, ptr, len); } else { result =3D flatview_read_continue(fv, addr, attrs, buf, le= n, addr1, l, mr); diff --git a/system/physmem.c b/system/physmem.c index 7bcbf87573..5f46a9d676 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3272,7 +3272,7 @@ static MemTxResult flatview_write_continue_step(MemTx= Attrs attrs, uint8_t *ram_ptr =3D qemu_ram_ptr_length(mr->ram_block, mr_addr, l, false, true); =20 - memmove(ram_ptr, buf, *l); + address_space_memmove(ram_ptr, buf, *l); invalidate_and_set_dirty(mr, mr_addr, *l); =20 return MEMTX_OK; @@ -3365,7 +3365,7 @@ static MemTxResult flatview_read_continue_step(MemTxA= ttrs attrs, uint8_t *buf, uint8_t *ram_ptr =3D qemu_ram_ptr_length(mr->ram_block, mr_addr, l, false, false); =20 - memcpy(buf, ram_ptr, *l); + address_space_memcpy(buf, ram_ptr, *l); =20 return MEMTX_OK; } @@ -3503,8 +3503,8 @@ MemTxResult address_space_write_rom(AddressSpace *as,= hwaddr addr, l =3D memory_access_size(mr, l, addr1); } else { /* ROM/RAM case */ - void *ram_ptr =3D qemu_map_ram_ptr(mr->ram_block, addr1); - memcpy(ram_ptr, buf, l); + address_space_memcpy(qemu_map_ram_ptr(mr->ram_block, addr1), + buf, l); invalidate_and_set_dirty(mr, addr1, l); } len -=3D l; --=20 2.54.0 From nobody Sun Jul 26 13:29:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1781262264; cv=none; d=zohomail.com; s=zohoarc; b=fCsxJk8Hoc2PaMQMnoS6r7YwnXF1mczteIIMDrLCw7W8qBdowgy7rxhrZpen3ngGrd3Niu6I4/VzvTLFmFswly3rtL41/OILSJh9t/QA7o0eCKWV/fqbjZa0MV4ByKQh6bJrCKnm0BKDDEFQ2BfMejqd9tqSg7aa2EtgFYPbOf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781262264; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sb0vXByTjHXCfPJQeiZkLPVssme/omDG5VeOp/DkR+8=; b=I4IedFybx8S1S1nMflpTYt6tA32tFi7LlWCpkwSDf23jp6d5PtzhHpnpeG2jFtR0Chc/2YKjPFiXA9DHJDDdkNwTaAkQldjSk0GpSnse6Cz1gOmw+z77bOufc+avUyKW5LlWMRWLYSPt3bILIuM/ZUiW9pFnqlWW8lI3yZKX0LY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781262264386855.9355972849635; Fri, 12 Jun 2026 04:04:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wXzg1-0003YP-IR; Fri, 12 Jun 2026 07:03:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXzfz-0003WB-L3 for qemu-devel@nongnu.org; Fri, 12 Jun 2026 07:03:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXzfx-0001K0-U2 for qemu-devel@nongnu.org; Fri, 12 Jun 2026 07:03:51 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-SHqdejfbMnOfHVPrOI4H_A-1; Fri, 12 Jun 2026 07:03:44 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5EC8D180025C; Fri, 12 Jun 2026 11:03:41 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.rmtau.csb (unknown [10.64.136.3]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3112E1955BC4; Fri, 12 Jun 2026 11:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781262229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sb0vXByTjHXCfPJQeiZkLPVssme/omDG5VeOp/DkR+8=; b=gisjvQjzbRom3zCIEyMRlSr3SyShOb2vgnTe4TbyAWuAk8SvxoYtfWf7Ve3dimdvcd7she GXYRkuP0HpSsDNwVyPnL4WEkddq/I3RPo6D4GtAozyvbcN/uhUyZli//KWGCRecadufntT dthZ7WQETZj+uSH5h6KOcoY7R3pnuZM= X-MC-Unique: SHqdejfbMnOfHVPrOI4H_A-1 X-Mimecast-MFC-AGG-ID: SHqdejfbMnOfHVPrOI4H_A_1781262221 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peterx@redhat.com, mst@redhat.com, peter.maydell@linaro.org, berrange@redhat.com, david@kernel.org, alex@shazbot.org, clg@redhat.com, pbonzini@redhat.com, philmd@mailo.com, phrdina@redhat.com, jugraham@redhat.com, shan.gavin@gmail.com Subject: [PATCH 2/2] system/memory: Make ram device region directly accessible Date: Fri, 12 Jun 2026 21:03:07 +1000 Message-ID: <20260612110307.1264798-3-gshan@redhat.com> In-Reply-To: <20260612110307.1264798-1-gshan@redhat.com> References: <20260612110307.1264798-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1781262265682158501 Content-Type: text/plain; charset="utf-8" This basically reverts 4a2e242bbb30 ("memory: Don't use memcpy for ram_device regions") to make ram device region directly accessible again. With this, the bounce buffer is bypassed in address_space_map() when a ram device region is involved, potentially avoid to overrun the bounce buffer. Reported-by: Julia Graham Suggested-by: Michael S. Tsirkin Suggested-by: Peter Xu Signed-off-by: Gavin Shan --- include/system/memory.h | 11 ++--------- system/memory.c | 41 +---------------------------------------- system/trace-events | 2 -- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index 6bb2e13eea..3ca6155805 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2914,15 +2914,8 @@ static inline bool memory_region_supports_direct_acc= ess(const MemoryRegion *mr) if (memory_region_is_romd(mr)) { return true; } - if (!memory_region_is_ram(mr)) { - return false; - } - /* - * RAM DEVICE regions can be accessed directly using memcpy, but it mi= ght - * be MMIO and access using mempy can be wrong (e.g., using instructio= ns not - * intended for MMIO access). So we treat this as IO. - */ - return !memory_region_is_ram_device(mr); + + return memory_region_is_ram(mr); } =20 static inline bool memory_access_is_direct(const MemoryRegion *mr, diff --git a/system/memory.c b/system/memory.c index 739ba11da6..9549dd1a94 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1362,43 +1362,6 @@ const MemoryRegionOps unassigned_mem_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 -static uint64_t memory_region_ram_device_read(void *opaque, - hwaddr addr, unsigned size) -{ - MemoryRegion *mr =3D opaque; - uint64_t data =3D ldn_he_p(mr->ram_block->host + addr, size); - - trace_memory_region_ram_device_read(get_cpu_index(), mr, addr, data, s= ize); - - return data; -} - -static void memory_region_ram_device_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) -{ - MemoryRegion *mr =3D opaque; - - trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, = size); - - stn_he_p(mr->ram_block->host + addr, size, data); -} - -static const MemoryRegionOps ram_device_mem_ops =3D { - .read =3D memory_region_ram_device_read, - .write =3D memory_region_ram_device_write, - .endianness =3D HOST_BIG_ENDIAN ? DEVICE_BIG_ENDIAN : DEVICE_LITTLE_EN= DIAN, - .valid =3D { - .min_access_size =3D 1, - .max_access_size =3D 8, - .unaligned =3D true, - }, - .impl =3D { - .min_access_size =3D 1, - .max_access_size =3D 8, - .unaligned =3D true, - }, -}; - bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, unsigned size, @@ -1676,10 +1639,8 @@ void memory_region_init_ram_device_ptr(MemoryRegion = *mr, Object *owner, const char *name, uint64_t size, void *ptr) { - memory_region_init_io(mr, owner, &ram_device_mem_ops, mr, name, size); - mr->ram =3D true; + memory_region_init_ram_ptr(mr, owner, name, size, ptr); mr->ram_device =3D true; - memory_region_set_ram_ptr(mr, size, ptr); } =20 void memory_region_init_alias(MemoryRegion *mr, Object *owner, diff --git a/system/trace-events b/system/trace-events index e6e1b61279..34af0a3a1e 100644 --- a/system/trace-events +++ b/system/trace-events @@ -20,8 +20,6 @@ memory_region_ops_read(int cpu_index, void *mr, uint64_t = addr, uint64_t value, u memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t v= alue, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value= 0x%"PRIx64" size %u name '%s'" memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint6= 4_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64= " size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint= 64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx6= 4" size %u" -memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint= 64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64"= size %u" -memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uin= t64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64= " size %u" memory_region_sync_dirty(const char *mr, const char *listener, int global)= "mr '%s' listener '%s' synced (global=3D%d)" flatview_new(void *view, void *root) "%p (root %p)" flatview_destroy(void *view, void *root) "%p (root %p)" --=20 2.54.0