From nobody Tue Feb 10 04:34:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1754569181; cv=none; d=zohomail.com; s=zohoarc; b=YOKIpPfcpDh8C7or+qlsm4Moa8Z/8CW8FkkO1VHBW4mZPSuAFCChdnsZeS+NJK3Tas28TQr3bGly1EnC88PatAqrhcQgccvaWOJf3HgbfnmgAMbbyxQ0eCrZBk/IFqYT9aWwyAVbrZTy/qC/WpgIAndInHLpllsKAcFKH2n9a40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754569181; h=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=RxWTSbrk2zLk8DAZx1et0aRrT29sEZnRs/aUhxfL+6U=; b=d0la/U/1Mn9QqI4bET1CnuRzOl6m1tynzVNyr6x1BXnVfvnUPi/19VYTpFiCNTSYdq+NiEf/p0xeVaPRwf443iJlTY59cn+xtWcSSXZRglFiIqZrQCKitPR4MpV4I+UR6Hg4NqjXTQAYSO/+sbZYRku8mNjQGjVNAM//M7C+P6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1754569181504619.2951991587346; Thu, 7 Aug 2025 05:19:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ujzSQ-0004Fh-61; Thu, 07 Aug 2025 08:10:54 -0400 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 1ujzRu-0001rw-V7; Thu, 07 Aug 2025 08:10:23 -0400 Received: from mgamail.intel.com ([192.198.163.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ujzRp-0005Cn-Jw; Thu, 07 Aug 2025 08:10:22 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2025 05:09:55 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa009.jf.intel.com with ESMTP; 07 Aug 2025 05:09:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1754568618; x=1786104618; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lbnpK8OyGgwHu5vkc+8beR3dBNzfXQc8vRTwv8yoFE8=; b=OTpkRXBJWTwAThCzTt2mRXsSFC2YOoV7fqb69UeCUWd3h9UuOp18udKh Nwyg5UqFornxIvZuwta8g6v3AAvD0oDZoe4y1TKE9wIlKYqLDgrCo7Hgk gcwSfymOCqXKD/H01VphATrHrskMvcEz4KAd6QcW7sxnXgqS77vI7cZ3S MsCCAf1UetGQwBQcB/U8QgtchQPct6R7LxnjQug04B0WPIoWCtfUpXUAK hdrlRLxPDFdQCE8Nli5rdWAQHPmJOBjxrt6qFIn+9QJ/Aq4TNC/BCWDjN W7AbDY2WK1EXlVMn7vx405+nSNCUtqGGGzi/pbVZlhmf+r8hsgVpEnTbg A==; X-CSE-ConnectionGUID: l829pqP2QrKqNzOeHri9aQ== X-CSE-MsgGUID: j9VwhQD6RCe1cdpv3Q7+/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11514"; a="57036829" X-IronPort-AV: E=Sophos;i="6.17,271,1747724400"; d="scan'208";a="57036829" X-CSE-ConnectionGUID: d/BF90LjQYusZ5jvSUIDRQ== X-CSE-MsgGUID: vCBVfKaoToqbg8jWIBvAXg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,271,1747724400"; d="scan'208";a="164701142" From: Zhao Liu To: Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Junjie Mao Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC 16/26] memory: Make flatview_do_translate() return a pointer to MemoryRegionSection Date: Thu, 7 Aug 2025 20:30:17 +0800 Message-Id: <20250807123027.2910950-17-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250807123027.2910950-1-zhao1.liu@intel.com> References: <20250807123027.2910950-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.198.163.15; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: 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 @intel.com) X-ZM-MESSAGEID: 1754569184374124100 Content-Type: text/plain; charset="utf-8" Rust side will use cell::Opaque<> to hide details of C structure, and this could help avoid the direct operation on C memory from Rust side. Therefore, it's necessary to wrap a translation binding and make it only return the pointer to MemoryRegionSection, instead of the copy. As the first step, make flatview_do_translate return a pointer to MemoryRegionSection, so that we can build a wrapper based on it. In addtion, add a global variable `unassigned_section` to help get a pointer to an invalid MemoryRegionSection. Signed-off-by: Zhao Liu --- system/physmem.c | 51 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 785c9a4050c6..4af29ea2168e 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -103,6 +103,9 @@ AddressSpace address_space_io; AddressSpace address_space_memory; =20 static MemoryRegion io_mem_unassigned; +static MemoryRegionSection unassigned_section =3D { + .mr =3D &io_mem_unassigned +}; =20 typedef struct PhysPageEntry PhysPageEntry; =20 @@ -418,14 +421,11 @@ address_space_translate_internal(AddressSpaceDispatch= *d, hwaddr addr, hwaddr *x * This function is called from RCU critical section. It is the common * part of flatview_do_translate and address_space_translate_cached. */ -static MemoryRegionSection address_space_translate_iommu(IOMMUMemoryRegion= *iommu_mr, - hwaddr *xlat, - hwaddr *plen_out, - hwaddr *page_mask= _out, - bool is_write, - bool is_mmio, - AddressSpace **ta= rget_as, - MemTxAttrs attrs) +static MemoryRegionSection * +address_space_translate_iommu(IOMMUMemoryRegion *iommu_mr, hwaddr *xlat, + hwaddr *plen_out, hwaddr *page_mask_out, + bool is_write, bool is_mmio, + AddressSpace **target_as, MemTxAttrs attrs) { MemoryRegionSection *section; hwaddr page_mask =3D (hwaddr)-1; @@ -463,10 +463,10 @@ static MemoryRegionSection address_space_translate_io= mmu(IOMMUMemoryRegion *iomm if (page_mask_out) { *page_mask_out =3D page_mask; } - return *section; + return section; =20 unassigned: - return (MemoryRegionSection) { .mr =3D &io_mem_unassigned }; + return &unassigned_section; } =20 /** @@ -489,15 +489,10 @@ unassigned: * * This function is called from RCU critical section */ -static MemoryRegionSection flatview_do_translate(FlatView *fv, - hwaddr addr, - hwaddr *xlat, - hwaddr *plen_out, - hwaddr *page_mask_out, - bool is_write, - bool is_mmio, - AddressSpace **target_as, - MemTxAttrs attrs) +static MemoryRegionSection * +flatview_do_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, hwaddr *ple= n_out, + hwaddr *page_mask_out, bool is_write, bool is_mmio, + AddressSpace **target_as, MemTxAttrs attrs) { MemoryRegionSection *section; IOMMUMemoryRegion *iommu_mr; @@ -523,14 +518,14 @@ static MemoryRegionSection flatview_do_translate(Flat= View *fv, *page_mask_out =3D ~TARGET_PAGE_MASK; } =20 - return *section; + return section; } =20 /* Called from RCU critical section */ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, bool is_write, MemTxAttrs attr= s) { - MemoryRegionSection section; + MemoryRegionSection *section; hwaddr xlat, page_mask; =20 /* @@ -542,13 +537,13 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSp= ace *as, hwaddr addr, attrs); =20 /* Illegal translation */ - if (section.mr =3D=3D &io_mem_unassigned) { + if (section->mr =3D=3D &io_mem_unassigned) { goto iotlb_fail; } =20 /* Convert memory region offset into address space offset */ - xlat +=3D section.offset_within_address_space - - section.offset_within_region; + xlat +=3D section->offset_within_address_space - + section->offset_within_region; =20 return (IOMMUTLBEntry) { .target_as =3D as, @@ -569,13 +564,13 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr= addr, hwaddr *xlat, MemTxAttrs attrs) { MemoryRegion *mr; - MemoryRegionSection section; + MemoryRegionSection *section; AddressSpace *as =3D NULL; =20 /* This can be MMIO, so setup MMIO bit. */ section =3D flatview_do_translate(fv, addr, xlat, plen, NULL, is_write, true, &as, attrs); - mr =3D section.mr; + mr =3D section->mr; =20 if (xen_enabled() && memory_access_is_direct(mr, is_write, attrs)) { hwaddr page =3D ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - a= ddr; @@ -3618,7 +3613,7 @@ static inline MemoryRegion *address_space_translate_c= ached( MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat, hwaddr *plen, bool is_write, MemTxAttrs attrs) { - MemoryRegionSection section; + MemoryRegionSection *section; MemoryRegion *mr; IOMMUMemoryRegion *iommu_mr; AddressSpace *target_as; @@ -3636,7 +3631,7 @@ static inline MemoryRegion *address_space_translate_c= ached( section =3D address_space_translate_iommu(iommu_mr, xlat, plen, NULL, is_write, true, &target_as, attrs); - return section.mr; + return section->mr; } =20 /* Called within RCU critical section. */ --=20 2.34.1