From nobody Sat Jul 11 14:56:03 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=1783496609; cv=none; d=zohomail.com; s=zohoarc; b=KKTly1WFfCTcdTxHipwF6xt0xyknlEsyzPvFtaG18diWumQX7T/c6tPkEahERoIMU5sJ0jHCDaEBck3zlhchcY8MnFLACYvitfQAddx7c3G9a21w8gkZ7Lu1nQtQ7aigLuBFPQtPlRrrjHBvIdZbDXT2AlirC0lG+gr2/bsOveY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496609; 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=9Rz1E7/QihrTQQqaNdUN3z1ecVj5FoOogXyVkTxVqEc=; b=Id8Rwuqwn9i5yFZASX0Jo+f9ua9ktZIfD7uUL/JuFh5ohMvYB6yV/0MgRyLmtdw/9R0JzmZS5bDCrvEK+AiYPwx6FCOm+vneQKkqwVoRVy9TOEDFqTHDwJ09jPBYAf5llVKog2XiEEmCcpLs28PT8qagwUxatlN/U/k9SLnU9bU= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178349660950032.88919834116814; Wed, 8 Jul 2026 00:43:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMvz-00045K-F7; Wed, 08 Jul 2026 03:43:07 -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 1whMvT-0003lF-Ga; Wed, 08 Jul 2026 03:42:35 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvQ-0004RW-DN; Wed, 08 Jul 2026 03:42:34 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:29 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496553; x=1815032553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BI6TOgdFhQ54fWSeUs+UOy7AvxWy1MB55cs1Y1rdGKI=; b=hsceRZZcbx69MKJJQPFH6JtQ0RNBzrh7czpc6lpqTIToqDiTCy7tI4U9 rJbtUEFOM61OuiYofXcc41JlLB/vIVOeJoBoCWmubAJjhXdd8uvj/Sue0 mzDTUvsYfhPFe8mCzAPzYspjWNSIfC/MqozFkwxm5Njddt0JlGi+95Fvx sBB+2Ccw2YEAAnqCbSDuihJQcmB80jnH6YyT3GN3i72hcDlm9VLyTwSY9 nWXJcPI5S9d3UuX7XGM2mAKh8H/iRSkq4J/duaHAutDnTt1DhkZsXsH0e 0UJD74uCsqXHuRAN78NeGUkmyDsmtcyYOgKaKoi2QeiJz6aVq069PJHqk g==; X-CSE-ConnectionGUID: XnbpI5pQSE+e8YipVywfgw== X-CSE-MsgGUID: azNXajVSRwO1MqGGDatfCw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343183" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343183" X-CSE-ConnectionGUID: hTd4+yO7RW+6EzhJgLUkBg== X-CSE-MsgGUID: 8GUVoGb2QeWSettsoaKp9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555894" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 01/26] rust/hpet: Fix the error caused by vm-memory Date: Wed, 8 Jul 2026 16:10:27 +0800 Message-Id: <20260708081052.2276617-2-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496611215158500 Content-Type: text/plain; charset="utf-8" error[E0283]: type annotations needed --> hw/timer/hpet/src/device.rs:884:55 | 884 | self.num_timers =3D=3D self.num_timers_save.get().into() | -- ^^^^ | | | type must be known at this point | =3D note: multiple `impl`s satisfying `usize: PartialEq<_>` found in th= e following crates: `core`, `vm_memory`: - impl PartialEq for usize; - impl PartialEq for usize; - impl PartialEq for usize where the constant `host` has type `bool`; help: try using a fully qualified path to specify the expected types | 884 | self.num_timers =3D=3D >::into(self.num_timers_= save.get()) | ++++++++++++++++++++++ = ~ For more information about this error, try `rustc --explain E0283`. error: could not compile `hpet` (lib) due to 1 previous error Signed-off-by: Zhao Liu --- Changes since v1: * Use From instead of Into. --- rust/hw/timer/hpet/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index ec0bca4496de..7c60cc0f10ab 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -959,7 +959,7 @@ fn is_offset_needed(&self) -> bool { } =20 fn validate_num_timers(&self, _version_id: u8) -> bool { - self.num_timers =3D=3D self.num_timers_save.get().into() + self.num_timers =3D=3D usize::from(self.num_timers_save.get()) } } =20 --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496596; cv=none; d=zohomail.com; s=zohoarc; b=ODMG6MEgmHgqfpQNG9yY5V8gw/5Ch4RNU+VxJWBNIhhRHi5nLZD1G2nTy2qRpTcgpqjSw1MzqVOBXfa+DufQlVqfQiFBcuUeV1CfsRD/sgV4zb76FsRHtkdEap8bAv92h/33HNM5erW5bWO18Oe9LD0UHw6Tf5Te3Oje+2EnEEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496596; 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=PibLBo5NmDCHU8UZdLnMuyc+f+67n8hCGcGnIzpwFTc=; b=hzCyhetJvejDNFBaKo1UFMG7Rc2EnWQBuHnmKEk3Zc+DzAWESVcaX/3E67HMPla/HwrUWr46w74zB8JBulmvtYuU9ha2p7IAlftoVIOD1HIaMEWwtHjsirAah1VnTU1Q4idFESvJjEc1UkDuYDrfPlILVPj5BNe4gnspTsuk7Yw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496596684331.32416706843503; Wed, 8 Jul 2026 00:43:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMvb-0003vS-JC; Wed, 08 Jul 2026 03:42:43 -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 1whMvV-0003pD-B1; Wed, 08 Jul 2026 03:42:37 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvT-0004UJ-2a; Wed, 08 Jul 2026 03:42:36 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:33 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496555; x=1815032555; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XmbGriJhJo3emug7dBCMlTqIP+4p9acUMe4lwLyzVTY=; b=M8LbQFuuP0ddNP7ZYOK0M+z0LbJOascZJJZl9hrQmeYqvLnWfpu3+4DJ /r46CRGilKD31guHjlxFVxEo18qcxS6+yS9rLaTJ5SWDJ7aqHDpH4AKIJ lY8sUNCCSsBOmwowYpY47t4jbwCFUyzXLPqm+fYf9G+L9/GQZUKoYPh9I g5d58ODz+0tmSJif8HExzOJ87egh2vxOpEMtBvTnIOlc1SQ/ri12YDnVa YCnUV1SXagGmxWNFWKgpZMeVx0oqfhjSCOTXADtoWY8adXsedijZc2vVe ZgSQ0W4BNGgdQ7ea1NwLUob2vOKbT54lbKRuWhYPbXOFgrJEk3rfTm5Gm A==; X-CSE-ConnectionGUID: rctyn/6qTC683ZDfKNMgOg== X-CSE-MsgGUID: MoM4ihgNQrWEygRMgqQl1g== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343196" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343196" X-CSE-ConnectionGUID: lxzCbgCdRYSi7+13s017FA== X-CSE-MsgGUID: 5WGrFcp6Q2+4h8+Qvf2Aww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555910" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 02/26] rust/cargo: Add the support for vm-memory Date: Wed, 8 Jul 2026 16:10:28 +0800 Message-Id: <20260708081052.2276617-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496599068158501 Content-Type: text/plain; charset="utf-8" Use vm-memory v0.18.0 for QEMU. By the way, the dependency relationship for system-sys and hwcore-sys is also updated in Cargo.lock. Signed-off-by: Zhao Liu --- Changes since v1: * Upgrade vm-memory dependency to v0.18.0 * Update Cargo.lock. --- rust/Cargo.lock | 33 ++++++++++++++++++++++++++++++++- rust/Cargo.toml | 1 + rust/system/Cargo.toml | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index cbb3ca15f77f..6d4701930419 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -184,7 +184,6 @@ dependencies =3D [ "glib-sys", "migration-sys", "qom-sys", - "system-sys", "util-sys", ] =20 @@ -410,6 +409,7 @@ dependencies =3D [ "qom", "system-sys", "util", + "vm-memory", ] =20 [[package]] @@ -431,6 +431,7 @@ version =3D "0.1.0" dependencies =3D [ "common", "glib-sys", + "hwcore-sys", "migration-sys", "qom-sys", "util-sys", @@ -456,6 +457,26 @@ dependencies =3D [ "util", ] =20 +[[package]] +name =3D "thiserror" +version =3D "2.0.18" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865= fbc4" +dependencies =3D [ + "thiserror-impl", +] + +[[package]] +name =3D "thiserror-impl" +version =3D "2.0.18" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856de= c1d5" +dependencies =3D [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name =3D "toml" version =3D "0.8.23" @@ -535,6 +556,16 @@ version =3D "0.9.4" source =3D "registry+https://github.com/rust-lang/crates.io-index" checksum =3D "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e= 483f" =20 +[[package]] +name =3D "vm-memory" +version =3D "0.18.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "9b55e753c7725603745cb32b2287ef7ef3da05c03c7702cda3fa8abe25ae= 0465" +dependencies =3D [ + "libc", + "thiserror", +] + [[package]] name =3D "winnow" version =3D "0.7.13" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0d24eb84e1cd..cfc540a77335 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -20,6 +20,7 @@ anyhow =3D "~1.0" foreign =3D "~0.3.1" libc =3D "0.2.162" glib-sys =3D { version =3D "0.21.2", features =3D ["v2_66"] } +vm-memory =3D "0.18.0" =20 [workspace.lints.rust] unexpected_cfgs =3D { level =3D "deny", check-cfg =3D ['cfg(MESON)'] } diff --git a/rust/system/Cargo.toml b/rust/system/Cargo.toml index d62173703173..179c38ecc27f 100644 --- a/rust/system/Cargo.toml +++ b/rust/system/Cargo.toml @@ -21,6 +21,7 @@ migration =3D { path =3D "../migration" } qom =3D { path =3D "../qom" } util =3D { path =3D "../util" } glib-sys.workspace =3D true +vm-memory.workspace =3D true =20 [lints] workspace =3D true --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496611; cv=none; d=zohomail.com; s=zohoarc; b=gewNYIqoZYE9uOVy80e4Yo+NFoPzckc3mggP+IVeB3k2lUuuVfj6QtdJ4eWjrLT31A8f4aP/zwEo1dTiHs7EAmFy2J2H7YExr8FDPRhCv4OGlGGuUFYLBEt6lR+NnUQZcbG7rcjIoxnnmiAesEnuHlMmYuLoM29ITUZZkFFU47s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496611; 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=nws9r12cMUMYopYuOmIx6bv6GYMuHG2Im8iDs18OSYw=; b=VDs9lRwJdQ8s0eCvfGWoypqeUaI98kGlOWzu0b5veuw5G1oPq6RKTGgoCjMiTbeR1xuZkVZH7D8QqroYI0Y9VnmlTIss1OBpGkf7UbXlekvtb1eDWQEgbTnsxwtGxbMvRjO5sL6O4dBhWnuc/SI+X6QVfsebhkIuh9Ykn+Ljgog= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496611237768.9711238944001; Wed, 8 Jul 2026 00:43:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMw0-00045O-3d; Wed, 08 Jul 2026 03:43:08 -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 1whMvZ-0003tH-3P; Wed, 08 Jul 2026 03:42:41 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvW-0004UJ-LV; Wed, 08 Jul 2026 03:42:40 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:37 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496559; x=1815032559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EJsxws4yFvbKYlREJ5MdL8C6I0Dx6ZflapaTgDMsgJs=; b=TnVt7Q4ZKGbTzrwbUdsE9g5P62ENqGutACjKLZzHgxvUtUBxo/hGwaev DecvsRQNih7QkER4doXYTeQS+rbwEI5pnY13bWCz0bsWp3rikp+x/i66f wsx8YTV526GqS0ad39qhwTKeXSzE2JuRjozCzXB2oM3JmDnU2DU113hXp AuRdzWT+GCS1y+RZ9ugVyCCF8Z6ihQ+Ckph9oKGDnMIk4L0w9vowYGKkO ImHHQ8YvgDL03cWvNsktcgzLezUjcO+8eWvs96hXuuvUtsNmPP/qpy77w u9DkbbTEb5IMHcJofHaoZ0/DcUh+a/DUxcAg7xY4Xca+ZrYdt2e8IIvxV Q==; X-CSE-ConnectionGUID: maKVqEcOQcSWQ3Yj310RvA== X-CSE-MsgGUID: jO374/lwQX6caFz2pfSrWA== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343214" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343214" X-CSE-ConnectionGUID: 7KXKxiDhS0mTtKJlsvKG1g== X-CSE-MsgGUID: BnhpTA1kSA24zktb48Nj7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555916" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 03/26] subprojects: Add thiserror-impl crate Date: Wed, 8 Jul 2026 16:10:29 +0800 Message-Id: <20260708081052.2276617-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496613175158500 Content-Type: text/plain; charset="utf-8" Use thiserror-impl-1 v1.0.65 for QEMU. Signed-off-by: Zhao Liu --- scripts/archive-source.sh | 1 + scripts/make-release | 2 +- subprojects/.gitignore | 1 + .../thiserror-impl-1-rs/meson.build | 41 +++++++++++++++++++ subprojects/thiserror-impl-1-rs.wrap | 10 +++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/thiserror-impl-1-rs/meson.build create mode 100644 subprojects/thiserror-impl-1-rs.wrap diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index a37acab524e0..b7f678872036 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -47,6 +47,7 @@ subprojects=3D( proc-macro2-1-rs quote-1-rs syn-2-rs + thiserror-impl-1-rs unicode-ident-1-rs ) sub_deinit=3D"" diff --git a/scripts/make-release b/scripts/make-release index 5f54b0e7939d..0f33522f39ba 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -44,7 +44,7 @@ SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softflo= at-3 bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs libc-0.2-rs probe-0.5-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs - syn-2-rs unicode-ident-1-rs" + syn-2-rs thiserror-impl-1-rs unicode-ident-1-rs" =20 src=3D"$1" version=3D"$2" diff --git a/subprojects/.gitignore b/subprojects/.gitignore index 011ce4dc3b77..816bc67111c9 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -22,6 +22,7 @@ /proc-macro* /quote-* /syn-* +/thiserror-impl-* /unicode-ident-* =20 # Workaround for Meson v1.9.0 https://github.com/mesonbuild/meson/issues/1= 4948 diff --git a/subprojects/packagefiles/thiserror-impl-1-rs/meson.build b/sub= projects/packagefiles/thiserror-impl-1-rs/meson.build new file mode 100644 index 000000000000..cc5546264035 --- /dev/null +++ b/subprojects/packagefiles/thiserror-impl-1-rs/meson.build @@ -0,0 +1,41 @@ +project('thiserror-impl-1-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '1.0.65', + license: 'MIT OR Apache-2.0', + default_options: []) + +subproject('quote-1-rs', required: true) +subproject('syn-2-rs', required: true) +subproject('proc-macro2-1-rs', required: true) + +quote_dep =3D dependency('quote-1-rs', native: true) +syn_dep =3D dependency('syn-2-rs', native: true) +proc_macro2_dep =3D dependency('proc-macro2-1-rs', native: true) + +rust =3D import('rust') + +_thiserror_impl_rs =3D rust.proc_macro( + 'thiserror_impl', + files('src/lib.rs'), + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_args: [ + '--cfg', 'feature=3D"proc-macro"', + '--cfg', 'feature=3D"clone-impls"', + '--cfg', 'feature=3D"derive"', + '--cfg', 'feature=3D"extra-traits"', + '--cfg', 'feature=3D"full"', + '--cfg', 'feature=3D"parsing"', + '--cfg', 'feature=3D"printing"', + ], + dependencies: [ + quote_dep, + syn_dep, + proc_macro2_dep + ], +) + +thiserror_impl_dep =3D declare_dependency( + link_with: _thiserror_impl_rs, +) + +meson.override_dependency('thiserror-impl-1-rs', thiserror_impl_dep) diff --git a/subprojects/thiserror-impl-1-rs.wrap b/subprojects/thiserror-i= mpl-1-rs.wrap new file mode 100644 index 000000000000..0f2ca85b8590 --- /dev/null +++ b/subprojects/thiserror-impl-1-rs.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory =3D thiserror-impl-1.0.65 +source_url =3D https://crates.io/api/v1/crates/thiserror-impl/1.0.65/downl= oad +source_filename =3D thiserror-impl-1.0.65.tar.gz +source_hash =3D ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b3= 7f8602 +#method =3D cargo +patch_directory =3D thiserror-impl-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496732; cv=none; d=zohomail.com; s=zohoarc; b=iQm2eiMgyeGe/lDST3oaP6bnFA6GI++uTiMz26ag3jXZUC3+S9G6qx38J8+KACFmTcHQzpQhusDoP3RUR9Y/9n19g0QsMamRqDx04pxgetjBDrdefxLWbq7DOgD65i4J26ApapH70T0cuP3UfMQf/6EX2zFjdr31toly8xmdmSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496732; 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=NJxHDFqOSK1D3t0YLz3SFglcAiLVJwZmrq6VIaj67i4=; b=izv8YBGUP9/Qg1oMj6Hvr/O31X1Zviv6HqQqN7/vZxlV2/AHSsoJl+jHTXZo02GzcuLiKCs4vjnlqCTz9zhDN7zPbBtgcFeByUjE3Hc9o17gs/d+i2RDsDz5Pp4B6XckethJfDjvlh6rYYSJ5slO6XkgHg17px0R01PxnTf272Y= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496732350903.3184201304435; Wed, 8 Jul 2026 00:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMw0-00045u-QH; Wed, 08 Jul 2026 03:43:08 -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 1whMvc-0003vz-Ay; Wed, 08 Jul 2026 03:42:44 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMva-0004UJ-HB; Wed, 08 Jul 2026 03:42:44 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:41 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496563; x=1815032563; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jsi8FvArfNfBxUexmYWdVUJgF/P5++mc/LEsJa9uVDA=; b=XR+asfFWSB9qBHsyZrvfnxrkGyhy2SMXcJ9MNGpZxx6FLJqEMJ/gDtPF w9Nv3Pbn2uQcTSVy4a/W7GcqxOBg2l+SMNOQiAolIPViyjAQsnHU0JLIh k18BERxAER4CQPZPzWtjous3JpGikrwpso7jsNH58Bd0KGY9NjGDAPypC Mhj9SPgLiOjGNsdqwLw73U5Mqg/kussucVqW7arp+FSFVNSMGcjyEEaFs y6oDDmOs/QRfrEcxZmRj33yam9azqyWKGpmfH64B/OhsHH/FRcPU3qdnB DtqIKMRCAKL3lIIBFbZZy8GEX7gXb9S5YDKGoRWMAxRSIzLmRoq9VUPdR g==; X-CSE-ConnectionGUID: ldlMDgdCRuWhlZ7rNjmuew== X-CSE-MsgGUID: neY0j/Y+Rxy22xJJW4hKpA== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343223" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343223" X-CSE-ConnectionGUID: MKh0Uf5WQJSudpC4ltu5tQ== X-CSE-MsgGUID: njNOLkdjRwq5JNeWSCfxwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555923" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 04/26] subprojects: Add thiserror crate Date: Wed, 8 Jul 2026 16:10:30 +0800 Message-Id: <20260708081052.2276617-5-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496733914158500 Content-Type: text/plain; charset="utf-8" Use thiserror v1.0.65 for QEMU. Signed-off-by: Zhao Liu --- scripts/archive-source.sh | 1 + scripts/make-release | 2 +- subprojects/.gitignore | 1 + .../packagefiles/thiserror-1-rs/meson.build | 23 +++++++++++++++++++ subprojects/thiserror-1-rs.wrap | 10 ++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/thiserror-1-rs/meson.build create mode 100644 subprojects/thiserror-1-rs.wrap diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index b7f678872036..2f3987fc0fea 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -47,6 +47,7 @@ subprojects=3D( proc-macro2-1-rs quote-1-rs syn-2-rs + thiserror-1-rs thiserror-impl-1-rs unicode-ident-1-rs ) diff --git a/scripts/make-release b/scripts/make-release index 0f33522f39ba..a5488e226298 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -44,7 +44,7 @@ SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softflo= at-3 bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs libc-0.2-rs probe-0.5-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs - syn-2-rs thiserror-impl-1-rs unicode-ident-1-rs" + syn-2-rs thiserror-1-rs thiserror-impl-1-rs unicode-ident-1-rs" =20 src=3D"$1" version=3D"$2" diff --git a/subprojects/.gitignore b/subprojects/.gitignore index 816bc67111c9..d7cf421bff07 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -22,6 +22,7 @@ /proc-macro* /quote-* /syn-* +/thiserror-* /thiserror-impl-* /unicode-ident-* =20 diff --git a/subprojects/packagefiles/thiserror-1-rs/meson.build b/subproje= cts/packagefiles/thiserror-1-rs/meson.build new file mode 100644 index 000000000000..bfaf2f8d3eb8 --- /dev/null +++ b/subprojects/packagefiles/thiserror-1-rs/meson.build @@ -0,0 +1,23 @@ +project('thiserror-1-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '1.0.65', + license: 'MIT OR Apache-2.0', + default_options: []) + +subproject('thiserror-impl-1-rs', required: true) +thiserror_impl_rs =3D dependency('thiserror-impl-1-rs') + +_thiserror_rs =3D static_library( + 'thiserror', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + dependencies: [thiserror_impl_rs], +) + +thiserror_dep =3D declare_dependency( + link_with: _thiserror_rs, +) + +meson.override_dependency('thiserror-1-rs', thiserror_dep) diff --git a/subprojects/thiserror-1-rs.wrap b/subprojects/thiserror-1-rs.w= rap new file mode 100644 index 000000000000..0f9303bebf97 --- /dev/null +++ b/subprojects/thiserror-1-rs.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory =3D thiserror-1.0.65 +source_url =3D https://crates.io/api/v1/crates/thiserror/1.0.65/download +source_filename =3D thiserror-1.0.65.tar.gz +source_hash =3D 5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a30= 57b3d5 +#method =3D cargo +patch_directory =3D thiserror-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496667; cv=none; d=zohomail.com; s=zohoarc; b=QCYUqklsgFB7oOVvrpv8H4QDsPf+WKydZDiwXLvaSwRFK60KxcpLiJ0JZ+M0Cx0dPopU4ZMQgcJ0D3FypMySLgPL8lx8zNC44y5RTi+DfWjPluTZSHborWdBqAlx2Kz93faJnHKKo3MWJh/YiDic2prVbspz/zGc4lK1SYvEolU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496667; 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=5992N9zmPZ9JcOao9v6NLrs8iRaRLqxRHqtN4ftXQwI=; b=Pil8aTbNzayYtqel3cFQsM7j8CxUedp5mLmqzA9kwZIEFNucWPgjuIvqDgE07NTxMHRnCS3t5/O6mE0dV56T9YNSVdpl6oNTEpGNvesOqKxr2aZIzRi0sXqeE+N7GnalwvzE5g3m6L2DqBmc+154T16vaFsMs1Fh8yMPCAAdjL0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496667047208.35149011707279; Wed, 8 Jul 2026 00:44:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwE-0004Xz-AU; Wed, 08 Jul 2026 03:43:22 -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 1whMvj-0003xF-Tr; Wed, 08 Jul 2026 03:42:55 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvg-0004UJ-Nx; Wed, 08 Jul 2026 03:42:51 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:46 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496569; x=1815032569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KUfCRaamEYV5a3lI5DD5JS0zaQQGj0vcpTApyu88ye0=; b=TOvojrTEpcnncWo3Z/E1DIxpJWXb+yEUlaSlx49C6ap0IJT2a6Ep+ybW UYD9mgfOKcXCcwakOrgMlLaQ9Zdaegn8USgaxOqlRJvbOpCE62QH1VpFU RTn/TUqNrl6QSply9HJvC5NkDTLIGS9ruWiYlM/c78VWhIv4bIZIwfuhN v7ZE5a0dGBhaZjip5U+SU1PKeC840pj37VSr5gUbPqKakyPl16E05kiou Kgx+2uIvuIyIxHW9t1mgeFi13J9ZW9uiu/WklPYc6OfOWfPHjZeYkspqz 75E3uvMdeCURJcQu5JpHN6jTP4FBYxJ7BIhTu0uZ1bz3veOgXMde/1zpY g==; X-CSE-ConnectionGUID: h3TuAV9HT923HB6+JqbLLA== X-CSE-MsgGUID: n0h2PwlVSliIWje7fdk2bw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343233" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343233" X-CSE-ConnectionGUID: cmd3wgbWS4aOyV0JUExX+w== X-CSE-MsgGUID: 1/9q94cKR6m3G5qGwmAkHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555927" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 05/26] subprojects: Add vm-memory crate Date: Wed, 8 Jul 2026 16:10:31 +0800 Message-Id: <20260708081052.2276617-6-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496667513158500 Content-Type: text/plain; charset="utf-8" Use vm-memory v0.18.0 for QEMU. Signed-off-by: Zhao Liu --- Changes since v1: * Upgrade vm-memory to v0.18.0 then we don't need extra patch for vm-memory subproject in QEMU. --- scripts/archive-source.sh | 1 + scripts/make-release | 3 ++- subprojects/.gitignore | 1 + .../vm-memory-0.18-rs/meson.build | 27 +++++++++++++++++++ subprojects/vm-memory-0.18-rs.wrap | 10 +++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/vm-memory-0.18-rs/meson.build create mode 100644 subprojects/vm-memory-0.18-rs.wrap diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 2f3987fc0fea..a876ec2d3480 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -49,6 +49,7 @@ subprojects=3D( syn-2-rs thiserror-1-rs thiserror-impl-1-rs + vm-memory-0.18-rs unicode-ident-1-rs ) sub_deinit=3D"" diff --git a/scripts/make-release b/scripts/make-release index a5488e226298..c0077aab3643 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -44,7 +44,8 @@ SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softflo= at-3 bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs libc-0.2-rs probe-0.5-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs - syn-2-rs thiserror-1-rs thiserror-impl-1-rs unicode-ident-1-rs" + syn-2-rs thiserror-1-rs thiserror-impl-1-rs unicode-ident-1-rs + vm-memory-0.18-rs" =20 src=3D"$1" version=3D"$2" diff --git a/subprojects/.gitignore b/subprojects/.gitignore index d7cf421bff07..29d8e26960d5 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -25,6 +25,7 @@ /thiserror-* /thiserror-impl-* /unicode-ident-* +/vm-memory-* =20 # Workaround for Meson v1.9.0 https://github.com/mesonbuild/meson/issues/1= 4948 /.wraplock diff --git a/subprojects/packagefiles/vm-memory-0.18-rs/meson.build b/subpr= ojects/packagefiles/vm-memory-0.18-rs/meson.build new file mode 100644 index 000000000000..2e5d9c50f839 --- /dev/null +++ b/subprojects/packagefiles/vm-memory-0.18-rs/meson.build @@ -0,0 +1,27 @@ +project('vm-memory-0.18-rs', 'rust', + meson_version: '>=3D1.5.0', + version : '0.18.0', + license : 'Apache-2.0 or BSD-3-Clause', + default_options: []) + +all_deps =3D [] + +subproject('thiserror-1-rs', required: true) +all_deps +=3D dependency('thiserror-1-rs') + +_vm_memory_rs =3D static_library( + 'vm_memory', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options : ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi : 'rust', + rust_args: ['--cap-lints', 'allow'], + dependencies: all_deps, + native: true, +) + +dep =3D declare_dependency( + link_with : _vm_memory_rs, +) + +meson.override_dependency('vm-memory-0.18-rs', dep, native: true) diff --git a/subprojects/vm-memory-0.18-rs.wrap b/subprojects/vm-memory-0.1= 8-rs.wrap new file mode 100644 index 000000000000..299b54d8f799 --- /dev/null +++ b/subprojects/vm-memory-0.18-rs.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory =3D vm-memory-0.18.0 +source_url =3D https://crates.io/api/v1/crates/vm-memory/0.18.0/download +source_filename =3D vm-memory-0.18.0.tar.gz +source_hash =3D 9b55e753c7725603745cb32b2287ef7ef3da05c03c7702cda3fa8abe25= ae0465 +#method =3D cargo +patch_directory =3D vm-memory-0.18-rs + +# bump this version number on every change to meson.build or the patches: +# v2 --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496615; cv=none; d=zohomail.com; s=zohoarc; b=klh2bHjJ0daYaN6EIGD6cuaqNMZYF5F5zJDbYNz/zekoHj5hhLPWWzNVAz+Ld4TCgyDl75uZbpKqelSBbga/fO7w1Hl8sfZMZubAwSTEvWXcWhHboDsOx1TtoJ29juLDFUcE2ZPGMJtq6mQ5P80qmESQgCow7ckfbXleU2Azgd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496615; 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=YZpR2A+bizymCFOBTi74YYwZ6vAiHON5zGaIvZUYG6U=; b=P9Cf+Ul5r+VJ+gCGV9alXacMKhjOmh4G6MwJLo8NREg8Nft+wgT6soQCBbUq16gFNFoaMGWpv0CjsVbXaTC1UmnafSas1rIBlNdv9LKEIwrgBgghmwi8u/ceqWr6BT+Ll0pc7/Jwe/omry4bMR9LQ0JQarG6ygTYIR5YtxNSCAg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496615472681.5149221794068; Wed, 8 Jul 2026 00:43:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwE-0004Yz-Hm; Wed, 08 Jul 2026 03:43:22 -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 1whMvl-0003xJ-Ix; Wed, 08 Jul 2026 03:42:55 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvj-0004mJ-5x; Wed, 08 Jul 2026 03:42:52 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:49 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496571; x=1815032571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WJUO2y5KHHM7rOZrzGbV4thxJgi+eLmzgdWufafbEKM=; b=Ou3zzDDs4bD2DbZ3pCBYZa6krSczU77qudas5y/0PGOSdMzFW4QnE8lS D7mRPYi37gglGQZxzdBfYaV5kpcVTP9sR04TDaHf+DaJJuTX7WcBzjUmR cgpYRIbSaZZHa0K9giVKjrAlyrbV3dFKI/391y5IRESc/4BO60WtDpA65 1SfnIxDvLz4gRav5DBEOG6C1SfL3VEegy4SKI3CoBawHQsNPppRTStMSl 7QFq2qkHu20ZRyT4DzbJPmiaTbUjBja+wIwmpchLVbHAMdwocWdkPAlSJ O4eUS7odGs7ABYf6FT8WRtd1A98bL0r0Ztamy4Gui8sdUK4dPP7kKtrin w==; X-CSE-ConnectionGUID: KcDQN6IRROC6W9wapy0NfQ== X-CSE-MsgGUID: nB2vmGqxTeyz8K+xBUhPUQ== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343245" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343245" X-CSE-ConnectionGUID: BHeSrczFRYSbzBDPXEI69w== X-CSE-MsgGUID: +GhAnFniRBG8yzRU17aLcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555935" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 06/26] rust: Add vm-memory in meson Date: Wed, 8 Jul 2026 16:10:32 +0800 Message-Id: <20260708081052.2276617-7-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496617408158500 Content-Type: text/plain; charset="utf-8" Integrate vm-memory into meson. Signed-off-by: Zhao Liu --- Changes since v1: * Upgrade vm-memory to v0.18.0. --- rust/meson.build | 2 ++ rust/system/meson.build | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/meson.build b/rust/meson.build index b6711fe77dd3..12a61c93c6c4 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -11,6 +11,7 @@ subproject('foreign-0.3-rs', required: true) subproject('glib-sys-0.21-rs', required: true) subproject('libc-0.2-rs', required: true) subproject('probe-0.5-rs', required: true) +subproject('vm-memory-0.18-rs', required: true) =20 anyhow_rs =3D dependency('anyhow-1-rs') bilge_rs =3D dependency('bilge-0.2-rs') @@ -19,6 +20,7 @@ foreign_rs =3D dependency('foreign-0.3-rs') glib_sys_rs =3D dependency('glib-sys-0.21-rs') libc_rs =3D dependency('libc-0.2-rs') probe_rs =3D dependency('probe-0.5-rs') +vm_memory_rs =3D dependency('vm-memory-0.18-rs') =20 subproject('proc-macro2-1-rs', required: true) subproject('quote-1-rs', required: true) diff --git a/rust/system/meson.build b/rust/system/meson.build index 89c1f2b84d17..d8e9f36ec1fd 100644 --- a/rust/system/meson.build +++ b/rust/system/meson.build @@ -2,7 +2,7 @@ _system_rs =3D static_library( 'system', 'src/lib.rs', link_with: [_bql_rs, _hwcore_rs, _migration_rs, _qom_rs, _util_rs], - dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs], + dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs, vm_me= mory_rs], ) =20 system_rs =3D declare_dependency(link_with: [_system_rs], --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496656; cv=none; d=zohomail.com; s=zohoarc; b=IacchUC+fXpTFKxtQqPKQwdsy0gjB69tAI0LWOWNlWe9EbUWr+E/Q+kYkLyy04d8FsryoSrI0SOYi9MAA7xcKc6+dY4ls64iVgRF+C5lOF6nHkmRmtnYnpos2qz+ox/jrZdaeqnnzxuy2vUTutsXi2+Zg1lHQ9L2QIPYhkajmqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496656; 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=W6lvNgqcevWieu08XXoURrJmpnhsYfDj0Hlcunj+8x4=; b=cTPrYQr5SmaSI3952jDILCBBKxMx4bSIO6OQ4kyAVV2CNs/Lq1Ou+IkfAPUt+ThhE419r+KL83hd2tZrl9TIZQ3B+sJU1yZpkqxPDt9IOv9pw9exz+HJIGb1kxfrKtt4SluSYCPi15WBIdHM1ECDW9GnHbX3AAP+grOfQ+pA7hs= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496656848869.4842835053588; Wed, 8 Jul 2026 00:44:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMw8-0004Nn-H7; Wed, 08 Jul 2026 03:43:16 -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 1whMvp-0003zJ-3n; Wed, 08 Jul 2026 03:42:57 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvn-0004ox-IV; Wed, 08 Jul 2026 03:42:56 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:54 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496576; x=1815032576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iU39p6y9+8iUwssZDQG7wjvu6B8h4ifB2KTeCJq8KHU=; b=S3UymKG8klMyD2pnSXkt3V3Crb7iDHOak+MHBODhJvuIvgzGhf5+4Zxs 7bYjZxrk1RIYC6v7PayBZDw/KROEI+JQ12ENy+DXnEof4Pbw7lM/7aVto uRiWTJoJeYZjBSOuo1VUfs8CJxmAuu3Ji3qKx1gFZ6ac4n35hEZSp6K9d +vAasnz6PPZsKdprZm+mFaSinhZsE3w2qb9QArp4tBMQrBy6O7kVIeJtl Wyj8j/uKE9yCWvWsLsHI5Y5D185ntTEcOMmgpFlHcLEzjrul3wAoOI42F Ika4D/U0+jSH6NLtb/EnaFRiAPtinvR2tINEDelLZVYhFosrSBZZrpVkb g==; X-CSE-ConnectionGUID: NnQLs9wBTxa/4tfMgX08Zw== X-CSE-MsgGUID: R0uN/bChSOyN732pFwaumw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343254" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343254" X-CSE-ConnectionGUID: 8DlX7vkMQVaOhNoHiUWf0g== X-CSE-MsgGUID: uUU5xOkIRZqjswroCTBqlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555942" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 07/26] rcu: Add rust wrappers for rcu_read_lock & rcu_read_unlock Date: Wed, 8 Jul 2026 16:10:33 +0800 Message-Id: <20260708081052.2276617-8-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496657423158500 Content-Type: text/plain; charset="utf-8" Add rust wrappers for rcu_read_lock & rcu_read_unlock, then bindgen could generate the bindings. Suggested-by: Paolo Bonzini Signed-off-by: Zhao Liu --- Changes since v1: * Add rust wrappers instead of dropping inline. --- include/qemu/rcu.h | 18 ++++++++++++++++++ util/rcu.c | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 020dbe4d8b77..126ec52ba38f 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -118,6 +118,24 @@ static inline void rcu_read_unlock(void) } } =20 +/** + * rust_rcu_read_lock: + * + * A wrapper over rcu_read_lock(). + * Called from Rust to acquire an RCU read lock. + * Do not touch. + */ +void rust_rcu_read_lock(void); + +/** + * rust_rcu_read_unlock: + * + * A wrapper over rcu_read_unlock(). + * Called from Rust to release an RCU read lock. + * Do not touch. + */ +void rust_rcu_read_unlock(void); + void synchronize_rcu(void); =20 /* diff --git a/util/rcu.c b/util/rcu.c index acac9446ea98..e9ba2c57bce6 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -171,6 +171,16 @@ static void wait_for_readers(void) QLIST_SWAP(®istry, &qsreaders, node); } =20 +void rust_rcu_read_lock(void) +{ + rcu_read_lock(); +} + +void rust_rcu_read_unlock(void) +{ + rcu_read_unlock(); +} + void synchronize_rcu(void) { QEMU_LOCK_GUARD(&rcu_sync_lock); --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496624; cv=none; d=zohomail.com; s=zohoarc; b=O/k3CXfxHRBmtfHpSNlLZg3qS0TVYBNAKhsR2oVXKopzj/IZ2Cd9leqA5MT/7q3ZDI50HxbnzmjIUsFzE4s8GakY6cBXYM+MD3eiUuXBoPBKC/2J2mNVKRjkSV2IkYbgfVCij4Vi05HVLX5RitYYScXs+aAROPmKiySUZZW/cAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496624; 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=MIkSHSIMd6wJv/8XiH23xmBW2VTbdfxjOMTTWU2wSqs=; b=iwTHYbCsxwZIM+OXdkeI8VQOCX636cvqudIb400KUlZXZGsypbUoeB6M4xnKTES5diZVIfEgNa6DP58g4cLozIQ70V8mSnZ/C7b1XCe5YObBkychUG+sJlpXePKWKPgD7EgtFIjnJHbeSBGzUJIKeZYUs6wK3wFAjYzCZcNasMM= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496624641888.2756664140144; Wed, 8 Jul 2026 00:43:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMw9-0004QL-45; Wed, 08 Jul 2026 03:43:17 -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 1whMvs-00040s-RF; Wed, 08 Jul 2026 03:43:02 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvq-0004ox-KP; Wed, 08 Jul 2026 03:43:00 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:42:57 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496579; x=1815032579; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=odjHL0x+MROapiVixt+s6VKPVF1LIdg6RNrAA9VuKTM=; b=gx3eoM/LFOFQtnyGx80XuSf3werD9FCQxb5+TLL8D0dlCyBPaJP74kJG k4AJBzMnSdJLw2i6NasDteblT5w0Hw2rf2HHkWurBf4HosPj2BJeTXCW2 UyQCkrjtxRyaiLO625mmVmiXM7duDx/BblvU3TLz5iL7hGYaQAwehlc4D CdmYvIvPNccDeHHWOgIGwbdx5zvNeq6+a/2LWhtky3bhLSRWns2BgG1rR rSZBYZnG5v7c83hcIUD8y/KHCz4l3eo0vtoTIRh5fFrb5/08cdxVcTo/P VM/Wq642/qsC0Wwq6XL3p2klkKyIBG/yoXxbJaYr/K8LmTMNJkSsitQyM Q==; X-CSE-ConnectionGUID: G6C/Rkw/TI2CokyQHXhwlQ== X-CSE-MsgGUID: yKH5+q73SUyE/Q/DvMz8OA== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343267" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343267" X-CSE-ConnectionGUID: 8UbpCixwTdGX59kZCt78/A== X-CSE-MsgGUID: kunUydETR2mcJBOEcpot7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555948" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 08/26] rust/bindings/util-sys: Include rcu.h in bindings wrapper Date: Wed, 8 Jul 2026 16:10:34 +0800 Message-Id: <20260708081052.2276617-9-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496625449158500 Content-Type: text/plain; charset="utf-8" rcu.h is transitively included by several crates' wrapper.h files (e.g. hwcore via hw/core/qdev.h, system via system/memory.h). Because several structs (e.g. BusChild/FlatView/AddressSpace) embed struct rcu_head, bindgen automatically generates a rcu_head definition in each crate that references it. Explicitly add rcu.h to util-sys/wrapper.h. With the allowlist-then- blocklist logic in generate_bindgen_args.py, this makes util-sys the only owner of rcu.h bindings. Then rcu.h is blocked in hwcore-sys and system-sys, thus it's necessary to import rcu_head from util_sys in hwcore-sys/lib.rs and system-sys/lib.rs. Signed-off-by: Zhao Liu --- Changes since v1: * New commit. --- rust/bindings/hwcore-sys/lib.rs | 2 +- rust/bindings/system-sys/lib.rs | 2 +- rust/bindings/util-sys/wrapper.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rust/bindings/hwcore-sys/lib.rs b/rust/bindings/hwcore-sys/lib= .rs index 8cef4a796193..9414c6639e2a 100644 --- a/rust/bindings/hwcore-sys/lib.rs +++ b/rust/bindings/hwcore-sys/lib.rs @@ -26,7 +26,7 @@ InterfaceClass, Object, ObjectClass, ObjectProperty, ObjectPropertyAcc= essor, ObjectPropertyRelease, }; -use util_sys::{Error, QDict, QList}; +use util_sys::{rcu_head, Error, QDict, QList}; =20 #[cfg(MESON)] include!("bindings.inc.rs"); diff --git a/rust/bindings/system-sys/lib.rs b/rust/bindings/system-sys/lib= .rs index 30adf683c355..8feaa76ca165 100644 --- a/rust/bindings/system-sys/lib.rs +++ b/rust/bindings/system-sys/lib.rs @@ -21,7 +21,7 @@ use common::Zeroable; use hwcore_sys::{qemu_irq, DeviceClass, DeviceState}; use qom_sys::{Object, ObjectClass}; -use util_sys::{Error, EventNotifier, QEMUBH}; +use util_sys::{rcu_head, Error, EventNotifier, QEMUBH}; =20 #[cfg(MESON)] include!("bindings.inc.rs"); diff --git a/rust/bindings/util-sys/wrapper.h b/rust/bindings/util-sys/wrap= per.h index e9c433e7dc14..5d3cf7792b92 100644 --- a/rust/bindings/util-sys/wrapper.h +++ b/rust/bindings/util-sys/wrapper.h @@ -27,6 +27,7 @@ typedef struct Visitor Visitor; #include "qemu/module.h" #include "qemu/option.h" #include "qemu/timer.h" +#include "qemu/rcu.h" #include "qapi/visitor.h" #include "qobject/qbool.h" #include "qobject/qdict.h" --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496616; cv=none; d=zohomail.com; s=zohoarc; b=lwSR9X5QqgxkNu6CxDNq66cHjIOnUMBVHK+saa2ka8jiG7E2fSZIgVFT8XmTqr1TXe6hpugrr44Sg+ZgAxZHIBYF1xzf7vDOUmjsk4GTrIukYtxdMK+Zp9fSgxukqTwymvee8QoMQQibDRyExaMMHHk0bhIe/8wheUTjvovqBs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496616; 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=H76KFiUwc2URZlg4Qm7Yld7QVFGDXS+Q7hzh1N0hHqQ=; b=CKTDBo9MBgh4DVEB0b2+5qvp760APf+wPJeyRhWBwx2OkasE2iYAUqmS+jFNNSG/xol2jBFCItTqeYn7pgWjSOMxD05LQ1VHgAQJMtDj65HPf1zpBBiBvyrT6NSSULiAPdiGxlovF0RcQJrVx/nGXiCzmCNlzx+zsRfSuDojAMQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17834966166181014.5428546158179; Wed, 8 Jul 2026 00:43:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwB-0004Rl-47; Wed, 08 Jul 2026 03:43:19 -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 1whMvw-00043b-Lk; Wed, 08 Jul 2026 03:43:04 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvu-0004ox-MJ; Wed, 08 Jul 2026 03:43:04 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:02 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:42:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496583; x=1815032583; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W0Yo/PAidXNCh/t02WCIULdm+1D7XGMULjYWmJ+pn8k=; b=ailSzGr0meK+iLEQLcHgA6wzvI3aOwJyiD6sOtyxLlJRYUYnDF3yU+Oe XP6RYxIY50DmuKyqUGat+jDj6MPUpxhKsVZ2QbqKOvndNtr2rBku3VfPK NRiPx2uuTmJFTR5H4R23hmhjNutEY8HTj/Y8vTIRokY2HQ8/eJ9P2mBsN p7nZVsy/ToFTzegiw4mUiqk2BUPk2mzQ3scU4JIABX4ZtoGisHsBLp1Mj i8W/vLhznHlRjbqKjWwuYpQXOGZbdyc1K34PsU98p9hnagYbMRsYStVTx Kx8YYOMBGWjYXjj31UIYffjtgCOHb5o2D1ERdXs9OvC2AZMqVvNzwszz4 w==; X-CSE-ConnectionGUID: 2+09BiJwSeOaJVg2BvTDsQ== X-CSE-MsgGUID: 0MF5kwKJSpihxQQHA7sOgw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343286" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343286" X-CSE-ConnectionGUID: GRxtV1fgTR2gpTNPi2/pRA== X-CSE-MsgGUID: fU63z/x0R1mdKAUoY/bvnQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555961" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 09/26] rust/util: Add RCU bindings Date: Wed, 8 Jul 2026 16:10:35 +0800 Message-Id: <20260708081052.2276617-10-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496617494158500 Content-Type: text/plain; charset="utf-8" Add RCU bindings, including an RAII guard for rcu_read_lock() & rcu_read_unlock(), and an RcuCell to model qatomic_rcu_read within an RCU critical section. Suggested-by: Paolo Bonzini Suggested-by: Manos Pitsidianakis Signed-off-by: Zhao Liu --- Changes since v1: * Use RAII pattern to guard RCU locking. * New RcuCell to simplify RCU read in Rust. --- rust/hw/char/pl011/wrapper.h | 1 + rust/util/src/lib.rs | 1 + rust/util/src/rcu.rs | 137 +++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 rust/util/src/rcu.rs diff --git a/rust/hw/char/pl011/wrapper.h b/rust/hw/char/pl011/wrapper.h index 87a5a589c8ea..2f66683fcd10 100644 --- a/rust/hw/char/pl011/wrapper.h +++ b/rust/hw/char/pl011/wrapper.h @@ -49,3 +49,4 @@ typedef enum memory_order { =20 #include "qemu/osdep.h" #include "hw/char/pl011.h" +#include "qemu/rcu.h" diff --git a/rust/util/src/lib.rs b/rust/util/src/lib.rs index 436c67e139ed..0736c1883dbf 100644 --- a/rust/util/src/lib.rs +++ b/rust/util/src/lib.rs @@ -5,6 +5,7 @@ pub mod error; pub mod log; pub mod module; +pub mod rcu; =20 // preserve one-item-per-"use" syntax, it is clearer // for prelude-like modules diff --git a/rust/util/src/rcu.rs b/rust/util/src/rcu.rs new file mode 100644 index 000000000000..e233f9698bfd --- /dev/null +++ b/rust/util/src/rcu.rs @@ -0,0 +1,137 @@ +// Copyright (C) 2026 Intel Corporation. +// Author(s): Zhao Liu +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Bindings for `rcu_read_lock` and `rcu_read_unlock`. +//! More details about RCU in QEMU, please refer docs/devel/rcu.rst. + +use std::{ + marker::PhantomData, + sync::atomic::{AtomicPtr, Ordering}, +}; + +use crate::bindings; + +/// RAII guard for the RCU read side lock. The lock is acquired on creati= on and +/// released on drop. +/// +/// This guard is not `Send` or `Sync`, so it cannot be moved to another t= hread +/// or stored in a global variable. This ensures the RCU read side lock t= o be +/// held and unlocked in the same thread. The guard is also not `Clone` or +/// `Copy`, so it cannot be duplicated and this can avoid double-unlock, w= hich +/// would be a bug. +/// +/// ```ignore +/// let guard =3D RcuGuard::new(); +/// // do some RCU read-side work +/// drop(guard); // releases the RCU read side lock +/// ``` +pub struct RcuGuard { + _marker: PhantomData<*const ()>, +} + +impl RcuGuard { + /// Acquires the RCU read side lock and returns a guard. + #[inline] + pub fn new() -> Self { + // SAFETY: An FFI call with no additional requirements. + unsafe { + bindings::rust_rcu_read_lock(); + } + // INVARIANT: The RCU read side lock was just acquired above. + Self { + _marker: PhantomData, + } + } +} + +impl Default for RcuGuard { + fn default() -> Self { + Self::new() + } +} + +impl Drop for RcuGuard { + #[inline] + fn drop(&mut self) { + // SAFETY: An FFI call with no additional requirements. + unsafe { + bindings::rust_rcu_read_unlock(); + } + } +} + +/// (Reader-side view of) an RCU-protected C pointer wrapper. +/// +/// This wrapper expresses the RCU read semantics of the C side: +/// +/// ```c +/// rcu_read_lock(); +/// p =3D qatomic_rcu_read(&foo); +/// /* do something with p. */ +/// rcu_read_unlock(); +/// ``` +/// +/// With this wrapper, the above code can be expressed as: +/// +/// ```ignore +/// // SAFETY: `foo_ptr` is a live RCU-protected pointer. +/// let cell =3D unsafe { RcuCell::from_ptr(foo_ptr) }; +/// { +/// let guard =3D RcuGuard::new(); +/// if let Some(p) =3D cell.get(&guard) { +/// /* do something with p. */ +/// } +/// } // `rcu_read_unlock()` runs here, when `guard` is dropped. +/// ``` +/// +/// # Ordering vs. C's `qatomic_rcu_read` +/// +/// C's `qatomic_rcu_read` compiles to `__ATOMIC_RELAXED` followed by +/// `smp_read_barrier_depends()` (or `__ATOMIC_CONSUME` under TSAN). +/// `smp_read_barrier_depends()` is a *compiler* barrier on all hosts QEMU +/// supports (see [docs/devel/atomics.rst](../../docs/devel/atomics.rst)), +/// providing dependency ordering. +/// +/// Rust exposes neither `Ordering::Consume` nor a dependency-barrier +/// primitive. So there is no exact Rust equivalent of `qatomic_rcu_read`. +/// Instead, use [`Ordering::Acquire`], the strictly stronger option: +/// - `Acquire` is a correct upper bound: every ordering that C's +/// `qatomic_rcu_read` guarantees is also guaranteed by `Acquire`, and it +/// correctly pairs with the updater's `qatomic_rcu_set()` (a Release st= ore). +#[repr(transparent)] +pub struct RcuCell { + data: AtomicPtr, +} + +impl RcuCell { + /// Convert a C raw pointer to an [`RcuCell`] in place, without copyin= g it. + /// + /// Note: copying the pointer first and then loading the copy would + /// synchronise with nothing: the `Ordering::Acquire` must be applied = to + /// the original pointer to pair with `qatomic_rcu_set()`. + /// + /// # Safety + /// + /// `field` must point to a valid `*mut T` updated only with + /// `qatomic_rcu_set()`, and the `T` object pointed to by `*field` must + /// remain valid during the RCU read-side critical section entered be= fore + /// calling `RcuCell::get`. + pub unsafe fn from_ptr<'a>(field: *const *mut T) -> &'a Self { + // SAFETY: `RcuCell` is `repr(transparent)` over `AtomicPtr`. + unsafe { &*(field.cast::()) } + } + + /// An almost equivalent of `qatomic_rcu_read()`, but with + /// `Ordering::Acquire`. + #[inline] + fn raw_get(&self) -> *mut T { + self.data.load(Ordering::Acquire) + } + + pub fn get<'g>(&self, _: &'g RcuGuard) -> Option<&'g T> { + // SAFETY: the reference is *shared*, which allows several readers + // to hold the RCU lock concurrently. + unsafe { self.raw_get().as_ref() } + } +} --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496611; cv=none; d=zohomail.com; s=zohoarc; b=QODcvwPJGX1DAVbJuYv5R7p4wKcjhq6XVjQhVwRaTiOypwaBoYhvSCXsiUw9Rn8dZPnnyT+E7Jcpj6tFEDWJW+MdijbQYTtocy75U4ZLGKT47k8h4t++fnkV/ObcaZ0Zkk7dVGWqUtlnyk7KW5v5sTG73df5PsZZyMaIBuGaPkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496611; 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=xmNWyHsTdNz3/H+xEWR8Ofdp4D6LR6V8Qx6eTJknnvY=; b=GXgKu5pmyCkmj0e2mnxpDwrIy7TKX4X4AWDKyV9i05XRsYvos0j+tFPI52O80MUXbP+kP9hfV28t3bEHu58uv92c05PX2sMZGlA+c1104jU20g9j9UY3p5U8nDYyJqtNizca7++6b0YheleqPDo+SmSWorpN7XeS9tCzOqSdDeo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496611401561.5233966793884; Wed, 8 Jul 2026 00:43:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwF-0004c2-Pm; Wed, 08 Jul 2026 03:43:23 -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 1whMw0-00045e-AK; Wed, 08 Jul 2026 03:43:08 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMvy-0004ox-JE; Wed, 08 Jul 2026 03:43:08 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:06 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496587; x=1815032587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+TOjti12wyjh6ysGSnrBZJk6dQHbvzcpbuZZnC8azsA=; b=avBwEriNu4IYj8EUvGE2OKw/GtR0JrZTuy84t0Z7tGxau+JsfLGcIk/q nQThn7axv5HRzawS4r7iP/RtXk97upBy/yjSG4jDYo8bP+BkImB+fsurp Td+h9b1vXQpeKG+KXqDRRl/sOtH0Glv432AHvyIUw+GbH80jAOAMzoKUW jFFFTPp+DobmbRdkeEmM2ArGpTIkHQJCUyrmUBZdsbge2p0RtNP+G3ZiJ I/4Ny9OZFB4ndjOnxVHsS+A3L40GWOMla/MgNZlkUt31vow8hWapQmpY2 5ps0vlxiF5DuvvbuhF0zzoOTFQg/KvC43OvRrzUWZ6PsNDOVrYq0acMSM w==; X-CSE-ConnectionGUID: uMcilWatTHqEwoAYYd7/1Q== X-CSE-MsgGUID: awDyd9Z6TbSxugKdgmKL1g== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343302" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343302" X-CSE-ConnectionGUID: b33HJGF6SmmFT3RagQTHvA== X-CSE-MsgGUID: UnFZ5/2hR1ywbmMOrCf8Cw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555974" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 10/26] memory: Expose FlatView refcount interfaces to Rust Date: Wed, 8 Jul 2026 16:10:36 +0800 Message-Id: <20260708081052.2276617-11-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496613169158500 Content-Type: text/plain; charset="utf-8" Move the declarations of the following functions to memory.h so that Rust can generate bindings for them: * flatview_ref * flatview_unref In addition, add documentation for these two interfaces. Note that these interfaces serve the address_space_to_flatview() logic. However, address_space_to_flatview() is not exposed to Rust because Rust can perform qatomic_rcu_read() itself. Furthermore, acquiring the RCU lock in Rust while C reads "current_map" via qatomic_rcu_read() would make for a very dangerous cross-FFI design. Instead, Rust should either use address_space_get_flatview() directly, or implement the logic entirely on the Rust side. The latter is a more worthwhile approach, as the RCU reader pattern (qatomic_rcu_read() within an RCU critical section) is a general pattern in QEMU. Signed-off-by: Zhao Liu --- Changes since v1: * Do not expose address_space_to_flatview() to Rust anymore. --- include/system/memory.h | 34 ++++++++++++++++++++++++++++++++++ system/memory-internal.h | 1 - system/memory.c | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index 47a0e06fbf8a..bf5bfa7164fb 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -948,6 +948,40 @@ static inline FlatView *address_space_to_flatview(cons= t AddressSpace *as) return qatomic_rcu_read(&as->current_map); } =20 +/** + * flatview_ref: Atomically increment the reference count of a #FlatView. + * + * @view: The #FlatView whose reference count is to be incremented. + * + * This function attempts to atomically increment the reference count + * of the given @view. This operation is conditional and will only + * succeed if the current reference count is non-zero. + * + * A non-zero reference count indicates that the #FlatView is live and + * in use. If the reference count is already zero, it indicates that the + * #FlatView is being deinitialized, and no new references can be + * acquired. + * + * Returns: + * true if the reference count was successfully incremented (i.e., it + * was non-zero before the call). + * false if the reference count was already zero and could not be + * incremented. + */ +bool flatview_ref(FlatView *view); + +/** + * flatview_unref: Atomically decrement the reference count of a + * #FlatView. + * + * @view: The #FlatView to be unreferenced. + * + * This function atomically decrements the reference count of the given + * @view. When the reference count drops to zero, the #FlatView will be + * destroyed via RCU. + */ +void flatview_unref(FlatView *view); + /** * typedef flatview_cb: callback for flatview_for_each_range() * diff --git a/system/memory-internal.h b/system/memory-internal.h index b2b9b5b0c5eb..c9264a239689 100644 --- a/system/memory-internal.h +++ b/system/memory-internal.h @@ -28,7 +28,6 @@ AddressSpaceDispatch *address_space_to_dispatch(const Add= ressSpace *as) } =20 FlatView *address_space_get_flatview(const AddressSpace *as); -void flatview_unref(FlatView *view); =20 extern const MemoryRegionOps unassigned_mem_ops; =20 diff --git a/system/memory.c b/system/memory.c index 5fc36708ec34..a18885dfd423 100644 --- a/system/memory.c +++ b/system/memory.c @@ -305,7 +305,7 @@ static void flatview_destroy(FlatView *view) g_free(view); } =20 -static bool flatview_ref(FlatView *view) +bool flatview_ref(FlatView *view) { return qatomic_fetch_inc_nonzero(&view->ref) > 0; } --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496647; cv=none; d=zohomail.com; s=zohoarc; b=Qw46S5JA1qR1ORDHMJGsmqjtXJUwai2SwKA1HL0e2nv21SV+uNoMdwfSBE1cwEVeWr12l0vTYMbYLAHhcY6TjCRz4agQYQHXsoXU1oLHmwmSFBYIDmI8nThrpj7739WFpdpYHT8j/xKri5XrYlNffqhzRTZZFEwi9bINl/T3tPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496647; 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=y6VrjL/P3NQ3IfzrCgoqQ6Uyrob6r0NlzAVDUuz6oMY=; b=bW+3/UjyUk6MWpQfw/Af1I3a3IZGLMRFcfSvre1aVj3b+T+K1TPi7yQ8K4g3BSzgoOCpepsA5nBYCddpK/1ONBLozaAiFuwVOvGLTQ9e3MuBmzxx15QeqeXbcInJ4QHDyMworAyq9mpODPSnZ8Ai0bxgVkW8lCKCDIdzOj9L2gk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496647531552.3105401008236; Wed, 8 Jul 2026 00:44:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwF-0004Zv-H7; Wed, 08 Jul 2026 03:43:23 -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 1whMw4-0004EG-Ex; Wed, 08 Jul 2026 03:43:12 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMw2-0004ox-MV; Wed, 08 Jul 2026 03:43:12 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:10 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496591; x=1815032591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VqnZQ7CrTJfaaaMOjcDnDIF8dHHxULpFm1eDfe3uLj0=; b=hnbn2/hvlVjLPpDz888/TVOW+Ui/GTjgcMWTrt6uz+Rb8lFrjxwvwr9c XsZenwrpg9QGeqZ2zKc1BfSAZsJVG624pOs3K3VNopFqe+cRUaOae8MVx IE/yOifTJtbjPA3cqllRJjM/sFGu17PGXmfyg05fCSBVvNfAUKiCC/KeL OH94t8WYI2QvedQlzagYx28eETlNkx7iLk+LAgJRWNljCx02d3FxtGPnG RV4nWwV4OGziijaAmUDRilZ78TTdXome0n7lLQP/2QNDLqqyQJ/kzZf0x 3lAjGjmTrDGtgkYJvFjWEp4Uol+gVXZOeJRQYfO/oD3+dcHFBF6zk0pvc w==; X-CSE-ConnectionGUID: 25jVDygBSKGGRK6xH06J2A== X-CSE-MsgGUID: WHDB7P+8QyuvolWQrxQdHA== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343314" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343314" X-CSE-ConnectionGUID: MOHvCCgVQr2b9OFdD1gm8A== X-CSE-MsgGUID: MiiSwpXuReeZtFi26cnlPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555978" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 11/26] memory: Rename address_space_lookup_region and expose it to Rust Date: Wed, 8 Jul 2026 16:10:37 +0800 Message-Id: <20260708081052.2276617-12-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496649388158500 Content-Type: text/plain; charset="utf-8" address_space_lookup_region() returns a pointer to a MemoryRegionSection instead of a MemoryRegion. Therefore, rename it to address_space_lookup_section(). Add its declaration to memory.h so that bindgen can generate bindings for it. This interface will be used to implement GuestMemory::find_region() in the vm_memory crate. In addition, add its documentation in memory.h. Signed-off-by: Zhao Liu --- include/system/memory.h | 21 +++++++++++++++++++++ system/physmem.c | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index bf5bfa7164fb..c32e3d01f825 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -948,6 +948,27 @@ static inline FlatView *address_space_to_flatview(cons= t AddressSpace *as) return qatomic_rcu_read(&as->current_map); } =20 +/** + * address_space_lookup_section: Find the MemoryRegionSection within a + * given #AddressSpaceDispatch. + * + * @d: The AddressSpaceDispatch to search within. + * @addr: The address to look up. + * @resolve_subpage: If 'true', resolve to a subpage section if the + * region is a subpage container. + * + * This function translates an address (@addr) into its corresponding + * #MemoryRegionSection within a given address space dispatch (@d). + * Must be called within an RCU critical section. + * + * Returns: + * A pointer to the #MemoryRegionSection. If the address is not + * mapped, this will be a pointer to the 'unassigned' section. + */ +MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d, + hwaddr addr, + bool resolve_subpage); + /** * flatview_ref: Atomically increment the reference count of a #FlatView. * diff --git a/system/physmem.c b/system/physmem.c index c21ea929153e..f807e60aa348 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -342,9 +342,9 @@ static MemoryRegionSection *phys_page_find(AddressSpace= Dispatch *d, hwaddr addr) } =20 /* Called from RCU critical section */ -static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispat= ch *d, - hwaddr addr, - bool resolve_subpa= ge) +MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d, + hwaddr addr, + bool resolve_subpage) { MemoryRegionSection *section =3D qatomic_read(&d->mru_section); subpage_t *subpage; @@ -370,7 +370,7 @@ address_space_translate_internal(AddressSpaceDispatch *= d, hwaddr addr, hwaddr *x MemoryRegion *mr; Int128 diff; =20 - section =3D address_space_lookup_region(d, addr, resolve_subpage); + section =3D address_space_lookup_section(d, addr, resolve_subpage); /* Compute offset within MemoryRegionSection */ addr -=3D section->offset_within_address_space; =20 --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496713; cv=none; d=zohomail.com; s=zohoarc; b=c80tEgTqbL1LwVy+nX4bFxbecoIq4x8JcPaBWokDSKquAxBvq0IbxYnvl6TwrhzeTEwDY+c3bwrNTxpoMFr4EIN8ltYMihcst+o4TOSpgo3/RbBtpAvRXsmg8guTggjTWuJOhOyYMkwnw9hHgYsFAIKSbqc2OFxm0TNaCQWG71s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496713; 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=/vGj9BoFkl/2B63H7acFrKRp8LGxiwFLkqlKi0Pl+B4=; b=D9V2wwVZhMxFIQQAJTJkp7/zPvyxodpkEENA0Hn+PKijdfKPWOVf7vICN0CdBLT1mhV2sUnq3dyl/VzNfKM1UnHDwqQ/RmYhhjz76RAlw8AxPv6sMr5vk2Lc0cq6gVS4HFzJSeCxsyaMThenqD7AiJDtij2TGcbxFrHi3s5RIKM= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496712872281.08697883779485; Wed, 8 Jul 2026 00:45:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwL-000531-Li; Wed, 08 Jul 2026 03:43:29 -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 1whMw9-0004Q2-0R; Wed, 08 Jul 2026 03:43:17 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMw7-0004ox-22; Wed, 08 Jul 2026 03:43:16 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:14 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496595; x=1815032595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Pd6luYiUZ33e7gYrFtn+0Tg72KmZFlQ8qruU1KkqGg=; b=khH3QPz3Rg7cP7Uc+qzAig9VZTy8lJBlpEBnzRXc5RXf3UT8Hfr3Yd9h l1XV+GFqu4atkUr1lNyAPM2HUdGa0sR0gAhh2e5qZdxJdIn6Q2cJ/Vs4r /O5jsMe2XxQ4mFtSGD0m5yfsrokXAXlB3cD/9vI60o6OYtEGuRMd0GPzT Qw1lL/xP1GT/Lp2JB/FC/SEjlmLBu1PnXSnbMjbt/03WGjgG9umnJOaSb G8PSrGsKtbc3yPiBEcfw1f7asUICQbCPyzq0Wj+j5xlRIKabrhZwSvX0r i8fyTvZw47R4HoanAS9qZouCHUwuFB36YaenIG+BxCf49hhpzezV84BEh Q==; X-CSE-ConnectionGUID: YorG+jSLS42QoL/73z5d6A== X-CSE-MsgGUID: pPQFiYRvSOi6wqiFYlHtGQ== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343325" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343325" X-CSE-ConnectionGUID: gjxw7uo1QFiU4GZycLehkw== X-CSE-MsgGUID: qsjvNvdwS6KYCIezC0tHBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555988" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 12/26] memory: Make flatview_do_translate() return a pointer to MemoryRegionSection Date: Wed, 8 Jul 2026 16:10:38 +0800 Message-Id: <20260708081052.2276617-13-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496713807158500 Content-Type: text/plain; charset="utf-8" Rust will use common::Opaque to hide the details of C structures, which helps avoid direct manipulation of C memory from the Rust side. Therefore, it is necessary to create a translation binding wrapper that returns a pointer to a MemoryRegionSection, instead of returning a copy by value. As a first step, make flatview_do_translate() return a pointer to a MemoryRegionSection so that we can build a wrapper around it. In addition, add a global variable `unassigned_section` to provide 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 f807e60aa348..418fc79ff2c0 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -104,6 +104,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 @@ -419,14 +422,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; @@ -464,10 +464,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 /** @@ -490,15 +490,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; @@ -524,14 +519,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 /* @@ -543,13 +538,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, @@ -570,13 +565,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_map_cache_enabled() && memory_access_is_direct(mr, is_write, attrs)) { @@ -3908,7 +3903,7 @@ static inline MemoryRegion *address_space_translate_c= ached( const 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; @@ -3926,7 +3921,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 From nobody Sat Jul 11 14:56:03 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=1783496646; cv=none; d=zohomail.com; s=zohoarc; b=Tt2J4VPS9HnCzMpLJEbgzS6dwbk+eF0SbF1RqzBGSXmUMmGNWa+RKaUn+FikEOZXBmaDQnKs70r/stAzhQRIMsBxElwiR1u0RVbtnKaeUmwvP2dndo3OWuq8YZXmfk/zWOYmNCkKJ5l8g70jEh/FnvxybvzpFyb6RwV56WaWS0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496646; 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=85OMYU9A8eAKPrFmskguhR94PwDUFvcLM/beBN29VDw=; b=GnYZj7f0i3ah6CW0LE/x/limORnP9Mt95JGXWhxGf0rDCKTZdfW3KgQJj4Tfh9Z1ilvgvQFMLreSJnm6YAJDJbMtIT+zQEv6Xrgg1Tz3gYFeOr3eknyvy0QnkPELHfoDW1wFZZ+tx9SBGBPArz2I8Vpmo2vzNn1OpTssLsVYkn8= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496646326805.2646083848804; Wed, 8 Jul 2026 00:44:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwF-0004bw-OU; Wed, 08 Jul 2026 03:43:23 -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 1whMwC-0004V3-Vq; Wed, 08 Jul 2026 03:43:21 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwB-0004ox-50; Wed, 08 Jul 2026 03:43:20 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:18 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496599; x=1815032599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xS9j1SfbNnXEP53X/50BOi4BX5IanNXaJwbdx5fCkPY=; b=HRiCazY5ExS8t0Rx5/MoUJtjeiJ+lcoUbTpn+j1Lua71xLVpnAfOSHVb +fSFO1BVt9wrlTzhH454DuwlHA0cEf1j2OaZMpoXy4SvVjDO0CTNmatf+ IihEbSy0/b1yqFe4/miVzt+hxh/bqIHctyNrAmUP5xEMNhLrBgq9/bovU 34GWpWZ1HA4cAQsF9ulhCbA/qijZ7H/SIsfaBC37Vhsyi70Bq+9moTWzE uudWLsujI8qTIIHPQ3RCV6mycoTZVy17jbRzQ7gFzxdJDMlelHzvkkLWE xFlcsluSp61DGxsAKpKXVRtZDzRiZqFEAPW6Kl+YNEv2+Ux/USvW9FkCv Q==; X-CSE-ConnectionGUID: 77VtcnMiS+WesUYxn2sf8Q== X-CSE-MsgGUID: SSQjaL7XQCSf+KJy6JNX+g== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343336" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343336" X-CSE-ConnectionGUID: m4NFgrQ4S86ij/sjZxG2Bw== X-CSE-MsgGUID: 0LLKhp6SReWv1r2rRw7shg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251555998" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 13/26] memory: Add a translation helper to return a MemoryRegionSection Date: Wed, 8 Jul 2026 16:10:39 +0800 Message-Id: <20260708081052.2276617-14-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496647595158500 Content-Type: text/plain; charset="utf-8" The Rust side will rely on MemoryRegionSection to organize non-overlapping memory "region" abstractions. Therefore, it is necessary to provide a translation helper variant that returns a MemoryRegionSection directly. Additionally, refine and complete the documentation for the translation helpers. Signed-off-by: Zhao Liu --- include/system/memory.h | 76 +++++++++++++++++++++++++++++++++++------ system/physmem.c | 22 +++++++++--- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index c32e3d01f825..7e64a39662be 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2609,24 +2609,80 @@ void address_space_flush_icache_range(AddressSpace = *as, IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, bool is_write, MemTxAttrs attr= s); =20 -/* address_space_translate: translate an address range into an address spa= ce - * into a MemoryRegion and an address range into that section. Should be - * called from an RCU critical section, to avoid that the last reference - * to the returned region disappears after address_space_translate returns. +/** + * flatview_translate_section: Translate a guest physical address range + * to the corresponding #MemoryRegionSection in a FlatView. * - * @fv: #FlatView to be accessed - * @addr: address within that address space - * @xlat: pointer to address within the returned memory region section's + * Must be called within an RCU critical section to prevent the last + * reference to the memory region (referenced by the returned section) + * from disappearing after the function returns. + * + * @fv: The FlatView to be accessed. + * @addr: The address to be translated within the given FlatView. + * @xlat: The translated address offset within the returned section's * #MemoryRegion. - * @len: pointer to length - * @is_write: indicates the transfer direction - * @attrs: memory attributes + * @len: Pointer to the length. On return, this will be updated to the + * valid read/write length of the translated address range. + * @is_write: Indicates the transfer direction. + * @attrs: Memory attributes. + * + * Returns: + * The #MemoryRegionSection that contains the translated address. + */ +MemoryRegionSection *flatview_translate_section(FlatView *fv, hwaddr addr, + hwaddr *xlat, hwaddr *len, + bool is_write, MemTxAttrs = attrs); + +/** + * flatview_translate: Translate a guest physical address range + * to the corresponding #MemoryRegionSection in a FlatView. + * + * Must be called within an RCU critical section to prevent the last + * reference to the returned memory region from disappearing after + * the function returns. + * + * This function is a variant of flatview_translate_section(), with the + * difference that it returns the #MemoryRegion contained in the + * #MemoryRegionSection. + * + * @fv: The FlatView to be accessed. + * @addr: The address to be translated within the given FlatView. + * @xlat: The translated address offset within the returned #MemoryRegion. + * @len: Pointer to the length. On return, this will be updated to the + * valid read/write length of the translated address range. + * @is_write: Indicates whether the translation operation is for a write. + * @attrs: Memory transaction attributes. + * + * Returns: + * The #MemoryRegion that contains the translated address. */ MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, hwaddr *len, bool is_write, MemTxAttrs attrs); =20 +/** + * address_space_translate: Translate a guest physical address range + * to the corresponding #MemoryRegionSection in a FlatView. + * + * Must be called within an RCU critical section to prevent the last + * reference to the returned memory region from disappearing after + * the function returns. + * + * This function is a variant of flatview_translate(), with the difference + * that it operates on an #AddressSpace rather than a #FlatView directly. + * + * @as: The #AddressSpace to be accessed. + * @addr: The address to be translated within the given address space. + * @xlat: The translated address offset within the returned #MemoryRegion. + * @len: Pointer to the length. On return, this will be updated to the + * valid read/write length of the translated address range. + * @is_write: Indicates whether the translation operation is for a write. + * @attrs: Memory transaction attributes. + * + * Returns: + * The #MemoryRegion that contains the translated address. + */ static inline MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, hwaddr *x= lat, hwaddr *len, bool is_w= rite, diff --git a/system/physmem.c b/system/physmem.c index 418fc79ff2c0..ff60ac7dd3aa 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -560,9 +560,9 @@ iotlb_fail: } =20 /* Called from RCU critical section */ -MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, - hwaddr *plen, bool is_write, - MemTxAttrs attrs) +MemoryRegionSection *flatview_translate_section(FlatView *fv, hwaddr addr, + hwaddr *xlat, hwaddr *plen, + bool is_write, MemTxAttrs = attrs) { MemoryRegion *mr; MemoryRegionSection *section; @@ -580,7 +580,21 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr = addr, hwaddr *xlat, *plen =3D MIN(page, *plen); } =20 - return mr; + return section; +} + +/* Called from RCU critical section */ +MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, + hwaddr *plen, bool is_write, + MemTxAttrs attrs) +{ + MemoryRegionSection *section; + + /* This can be MMIO, so setup MMIO bit. */ + section =3D flatview_translate_section(fv, addr, xlat, plen, + is_write, attrs); + + return section->mr; } =20 #ifdef CONFIG_TCG --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496670; cv=none; d=zohomail.com; s=zohoarc; b=ErA6U1whkHpYbmhFbrhLl/k8B/BO1OmEn6IR7lMiJOGa02e3wK/6jDz53FkpR706J2I8/KRQHoYM/dFLLk9ORhNl6rkvbvZvC6VKt35sjRVZV9ibgCyCooGC+tlIW5PhrZNXzsv/bNFfAlPBnqkx3+iBhxMUr4Go0Al1PBhMuag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496670; 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=tHMNRbdD+2Wk7nXgcBcXLn2t9wMGaqE6zSroVlZq+2M=; b=EX2Rw9OKsuTwYxoMIkl2XsDZ0MwWNT3QpqFvE+yxFw9bPGjtC1qLlvx6y3Ph3wJLrx/pJo9yNFAXUDZjT0kKAxW+20Z3UjkLVNQLz/zw1JFZXW3WmXCrcRfH3PV0ud8KZdopjMntOJxCe7XM6dvsq1MZFTKu2j0OIAwBYEiffPk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496670759915.9744235148077; Wed, 8 Jul 2026 00:44:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwJ-0004uG-Ml; Wed, 08 Jul 2026 03:43:27 -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 1whMwH-0004jQ-DB; Wed, 08 Jul 2026 03:43:25 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwF-0004ox-5U; Wed, 08 Jul 2026 03:43:25 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:22 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496603; x=1815032603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jGAaPjd4VCUL5nTjVuv77/GOZrZpCcneoRNxSWdnEMI=; b=Hfbv4jSDChmQJMxRWXQKD23UNZA1iKbMZbVqTzWhxBVZudoWFlFqxctB GzgY2xv8OtEOXq9VOazBxEYhSwEGmdt7YFL1ePOD7r0l5Ncfl5gQOAZEy Oq1AJQaTvA1lHH7iAXhDmM/OiB7b9GlmQY8NShoav5YHboXQkCrAvV/29 0TZEVmc8WofjeozpZDyBp+8fuUT43jdR/cnYEaQePjzqfY+KqKGLKMc3h AF5dk7VC6K8vhPFTlQWizL0u0MtQ7GWYjBmcGmpWS3WKI2d0rN6vQ0zRM lUjzLSDFMaMrcVdRCmfDk70T0f1+cqrpGPx14sm0lhbjzVq39TGXazziq Q==; X-CSE-ConnectionGUID: K1OwHT9yQRuyp7FQ9fwGag== X-CSE-MsgGUID: 2OmBiKIZSZyPMxd36TjDFw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343344" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343344" X-CSE-ConnectionGUID: sBNDDmckTcuid/io2WDkWw== X-CSE-MsgGUID: iee9mZPWSNyQWVaojHyg6w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556005" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 14/26] memory: Rename flatview_access_allowed() to memory_region_access_allowed() Date: Wed, 8 Jul 2026 16:10:40 +0800 Message-Id: <20260708081052.2276617-15-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496671570158500 Content-Type: text/plain; charset="utf-8" flatview_access_allowed() takes a `MemoryRegion *` as an argument, meaning it operates on a MemoryRegion rather than a FlatView. Therefore, rename it to memory_region_access_allowed() to accurately reflect its behavior. Signed-off-by: Zhao Liu --- system/physmem.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index ff60ac7dd3aa..1162819c1080 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3210,7 +3210,7 @@ bool prepare_mmio_access(MemoryRegion *mr) } =20 /** - * flatview_access_allowed + * memory_region_access_allowed * @mr: #MemoryRegion to be accessed * @attrs: memory transaction attributes * @addr: address within that memory region @@ -3220,8 +3220,8 @@ bool prepare_mmio_access(MemoryRegion *mr) * * Returns: true if transaction is allowed, false if denied. */ -static bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs attrs, - hwaddr addr, hwaddr len) +static bool memory_region_access_allowed(MemoryRegion *mr, MemTxAttrs attr= s, + hwaddr addr, hwaddr len) { if (likely(!attrs.memory)) { return true; @@ -3241,7 +3241,7 @@ static MemTxResult flatview_write_continue_step(MemTx= Attrs attrs, hwaddr len, hwaddr mr_addr, hwaddr *l, MemoryRegion *m= r) { - if (!flatview_access_allowed(mr, attrs, mr_addr, *l)) { + if (!memory_region_access_allowed(mr, attrs, mr_addr, *l)) { return MEMTX_ACCESS_ERROR; } =20 @@ -3325,7 +3325,7 @@ static MemTxResult flatview_write(FlatView *fv, hwadd= r addr, MemTxAttrs attrs, =20 l =3D len; mr =3D flatview_translate(fv, addr, &mr_addr, &l, true, attrs); - if (!flatview_access_allowed(mr, attrs, mr_addr, l)) { + if (!memory_region_access_allowed(mr, attrs, addr, len)) { return MEMTX_ACCESS_ERROR; } return flatview_write_continue(fv, addr, attrs, buf, len, @@ -3337,7 +3337,7 @@ static MemTxResult flatview_read_continue_step(MemTxA= ttrs attrs, uint8_t *buf, hwaddr *l, MemoryRegion *mr) { - if (!flatview_access_allowed(mr, attrs, mr_addr, *l)) { + if (!memory_region_access_allowed(mr, attrs, mr_addr, *l)) { return MEMTX_ACCESS_ERROR; } =20 @@ -3416,7 +3416,7 @@ static MemTxResult flatview_read(FlatView *fv, hwaddr= addr, =20 l =3D len; mr =3D flatview_translate(fv, addr, &mr_addr, &l, false, attrs); - if (!flatview_access_allowed(mr, attrs, mr_addr, l)) { + if (!memory_region_access_allowed(mr, attrs, addr, len)) { return MEMTX_ACCESS_ERROR; } return flatview_read_continue(fv, addr, attrs, buf, len, --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496763; cv=none; d=zohomail.com; s=zohoarc; b=geGznf8fmkWdqwHdxXAHeQoio2eZCcp5a+KlLxFA2An/PzxehRoAj4zJhb5WC2gGAjA037bABeUyIE2VjWT+Q6UdNf44ri0EiTfDRDpsoK90QRCLDtypVSIitH5hVBBdGjfNPhWziklAs5a2mulljs+aCKyVWlJ1TSYPMJOsqxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496763; 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=MjHxc/56ctxbxTYBE+vJ0PTwY0HvP7JJSoVzUc1dgRA=; b=RbINV4V5cDARmssbwE32uSUCy7EECAtYkI4T0YNTixom5UQliJb+BFDsSZR3KfFCx2YXLnrMurAq3Fpj4IH2n5ZX8tCDJooJo/teUaVHIS89pmGAS5aGEAE0iAPvK40FN4qpGBkmMcRxzUUOZfFueIlksEP+wX/HfXltTNgVyDo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496763698315.2816887878399; Wed, 8 Jul 2026 00:46:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwN-0005Ah-F1; Wed, 08 Jul 2026 03:43:31 -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 1whMwL-00050I-3U; Wed, 08 Jul 2026 03:43:29 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwJ-0004ox-C0; Wed, 08 Jul 2026 03:43:28 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:26 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496608; x=1815032608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D9f+ISIq4RvumZ8f8S94j8L5GCqYoQ10V046ev7+rdk=; b=kZAfXhr5NpqHhdq9LAre6gTzlN4D14PTAUVP63aoPxI9+eOozkdqyPm2 HPQjXeNnbPNHWh5N9rd5zWAstXJgpkVe8pAOeES4YnHi+gj2m+5Se7ztW s3HCykQlplgGBktlhfY80d/mVl5Wjq58fbUZJGuGAviVZ2U+6SX3cEdJR hodTJ4QWXZd2YjGZ2PBbWNceBN+aztm/3QE4h7afC2/m2yMAibwrd0M9N uBUwGax02hF4CNo5+LpEIyQCgn5Y95H9fp5C0PnC2+YCj2qIwRwdrMhRp CBBjcJy0+d62/2E0CUKO1oStA918vDhD2+CdVdY/DIXfiffyvOA9mkbLZ g==; X-CSE-ConnectionGUID: bTveeASnTuy5r24ydUb7Qg== X-CSE-MsgGUID: IdDcmJzTQZyQII8XXsx21g== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343355" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343355" X-CSE-ConnectionGUID: Hiz3VhIQQCmHOqBL+2Z6bw== X-CSE-MsgGUID: XKVszofZTEaSXhtkjmvApA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556016" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 15/26] memory: Add MemoryRegionSection-based misc helpers Date: Wed, 8 Jul 2026 16:10:41 +0800 Message-Id: <20260708081052.2276617-16-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496764083158500 Content-Type: text/plain; charset="utf-8" Add the following helpers: * section_access_allowed() - used to check memory access permissions. * section_covers_region_addr() - used to implement GuestMemoryRegion::check_address(). * section_fuzz_dma_read() - used to insert a fuzzing hook before read/load operations. Signed-off-by: Zhao Liu --- Changes since v1: * Drop section_get_host_addr() for two reasons: - GuestMemoryRegion::get_host_address() doesn't accept Permissions and MemTxAttrs arguments, which doesn't map well to QEMU's complex use cases. - section_get_host_addr() itself doesn't differentiate between MMIO and RAM. Although this could be fixed, the first reason makes it unnecessary. --- include/system/memory.h | 39 +++++++++++++++++++++++++++++++++++++++ system/physmem.c | 20 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 7e64a39662be..18f269ac4dab 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2878,6 +2878,45 @@ MemTxResult address_space_read(const AddressSpace *a= s, hwaddr addr, MemTxResult address_space_set(const AddressSpace *as, hwaddr addr, uint8_t c, hwaddr len, MemTxAttrs attrs); =20 +/** + * section_access_allowed: Check if a memory transaction is allowed. + * + * @section: The #MemoryRegionSection to be accessed. + * @attrs: Memory transaction attributes. + * @addr: The address within that memory region. + * @len: The number of bytes to access. + * + * Returns: true if the transaction is allowed, false if denied. + */ +bool section_access_allowed(MemoryRegionSection *section, + MemTxAttrs attrs, hwaddr addr, + hwaddr len); + +/** + * section_covers_region_addr: Check if a region address is covered by + * a #MemoryRegionSection. + * + * @section: The #MemoryRegionSection to check against. + * @region_addr: The address within the memory region referenced by the + * @section. + * + * Returns: true if the address is covered by the section, false otherwise. + */ +bool section_covers_region_addr(const MemoryRegionSection *section, + hwaddr region_addr); + +/** + * section_fuzz_dma_read: Wrapper for fuzz_dma_read_cb(). + * + * @section: The #MemoryRegionSection to be accessed. + * @addr: The memory address to be fuzzed. + * @len: The length of the memory to fuzz. + * + * This function is a wrapper for fuzz_dma_read_cb(). + */ +void section_fuzz_dma_read(MemoryRegionSection *section, + hwaddr addr, hwaddr len); + /* Coalesced MMIO regions are areas where write operations can be reordere= d. * This usually implies that write operations are side-effect free. This = allows * batching which can make a major impact on performance when using diff --git a/system/physmem.c b/system/physmem.c index 1162819c1080..c227d4680e33 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -321,6 +321,19 @@ static inline bool section_covers_addr(const MemoryReg= ionSection *section, int128_getlo(section->size), addr); } =20 +bool section_covers_region_addr(const MemoryRegionSection *section, + hwaddr region_addr) +{ + return section->offset_within_region <=3D region_addr && + section->offset_within_region + int128_get64(section->size) >= =3D region_addr; +} + +void section_fuzz_dma_read(MemoryRegionSection *section, + hwaddr addr, hwaddr len) +{ + fuzz_dma_read_cb(addr, len, section->mr); +} + static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr= addr) { PhysPageEntry lp =3D d->phys_map, *p; @@ -3236,6 +3249,13 @@ static bool memory_region_access_allowed(MemoryRegio= n *mr, MemTxAttrs attrs, return false; } =20 +bool section_access_allowed(MemoryRegionSection *section, + MemTxAttrs attrs, hwaddr addr, + hwaddr len) +{ + return memory_region_access_allowed(section->mr, attrs, addr, len); +} + static MemTxResult flatview_write_continue_step(MemTxAttrs attrs, const uint8_t *buf, hwaddr len, hwaddr mr_addr, --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496684; cv=none; d=zohomail.com; s=zohoarc; b=ASw8Sz2oiTM6bfRWAt+2HVpYbfEVVaa0w1N5evpM5HzFRg8ojgGaszxvOoqywx6uCmvVt6pQsD3nWS2uF/yHbwuNMfsZiWjhozuGw0COLaUxZbPB+jOKDS0Ebk3xDoyryQhgxPN5zbvIZ+ig1c6fVZbeqD1CXSmRE4gDTmYar24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496684; 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=8hw72sSnSaXAYaeZg+NAJ+FWj9XD+kbLkDICUX93Yj0=; b=bLqbJiawd3uMvleml82Gek07BcLnJXQEOeFhxC8R6CJ1JlJgG1IPv3/L9aBOctw7bTwv8Bu0+d4EEaiRBZXvgA7S/2vDVlm1hgXnbh/wB/LUZvWCQI7Uugfbvcdarnrs3JRDUNGK/spodLkYwKId20yAypPpKGWYwV2fm5KIokE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496684270463.5630960124556; Wed, 8 Jul 2026 00:44:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMws-0006R8-Kr; Wed, 08 Jul 2026 03:44:02 -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 1whMwj-0006AX-OX; Wed, 08 Jul 2026 03:43:54 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwh-0004ox-MA; Wed, 08 Jul 2026 03:43:53 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:31 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496632; x=1815032632; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EEg4UHmIJ9cGzWz8agv03EEjhFqp/LixB8XZva6GMqA=; b=L4QM8C1z3lNLn9ao7luKqPwCxWlUGrLCCs5YOhfNp4zxU8N/aipctGN5 kb9wkOSzJAfrbiybztOSaB4YZK3GlYQ8w8i3L37eJDtp8Xa7JYtfNoaBi aOWBBvtuYILP3dniLUSp8mFeFbKWLLYbdpkTGqcsewqI9oCgKR3/AYSc/ N5OHozr+qwuoEYWJf8sSwKFujPwiRjgmCT5t1s61ff5/V7wTnQVlpFrEB ohuXxhJyvPJ0uEEpuQgNUzy9R13UmqBSGyzptsbKY7fW+kD6C93dGfuGo pmeO8SkFyb5RDAcPgs9QlCbEtl4oCPt06dloncQB99cDHHDxfEjqVjnJX Q==; X-CSE-ConnectionGUID: sF3xLdXlTXGYSR6ZfzNziQ== X-CSE-MsgGUID: X3nkHBTXT727jGfzAwjufA== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343363" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343363" X-CSE-ConnectionGUID: rccK9LTHQrCmdRr/whod2A== X-CSE-MsgGUID: M5VA6PwqR6mMtDE6Igq8Jw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556024" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 16/26] memory: Add wrappers for intermediate read/write steps Date: Wed, 8 Jul 2026 16:10:42 +0800 Message-Id: <20260708081052.2276617-17-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496685613158500 Content-Type: text/plain; charset="utf-8" Add the following two wrappers to allow bindgen to generate bindings based on MemoryRegionSection: * rust_section_write_continue_step() * rust_section_read_continue_step() This allows the Rust side to reconstruct the full write/read process, similar to what address_space_write() and address_space_read_full() do. Signed-off-by: Zhao Liu --- include/system/memory.h | 53 +++++++++++++++++++++++++++++++++++++++++ system/physmem.c | 16 +++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 18f269ac4dab..87006ce79d47 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2917,6 +2917,59 @@ bool section_covers_region_addr(const MemoryRegionSe= ction *section, void section_fuzz_dma_read(MemoryRegionSection *section, hwaddr addr, hwaddr len); =20 +/** + * rust_section_write_continue_step: Write to a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function provides a wrapper for flatview_write_continue_step(), + * and allows the Rust side to reconstruct the full write process, similar + * to what address_space_write() does. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @attrs: Memory transaction attributes. + * @buf: Buffer containing the data to be written. + * @len: The number of bytes to write. + * @mr_addr: The address within that memory region. + * @l: Pointer to the actual length. On return, this is updated to the + * number of bytes written. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed + * (e.g., unassigned memory, device rejected the transaction, IOMMU fault). + */ +MemTxResult rust_section_write_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, const uint8_t *buf, hwaddr len, hwaddr mr_addr, hwad= dr *l); + +/** + * rust_section_read_continue_step: Read from a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function provides a wrapper for flatview_read_continue_step(), + * and allows the Rust side to reconstruct the full read process, similar + * to what address_space_read_full() does. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @attrs: Memory transaction attributes. + * @buf: Buffer to store the read data. + * @len: The expected number of bytes to read. + * @mr_addr: The address within that memory region. + * @l: Pointer to the actual length. On return, this is updated to the + * number of bytes read. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed. + */ +MemTxResult rust_section_read_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); + /* Coalesced MMIO regions are areas where write operations can be reordere= d. * This usually implies that write operations are side-effect free. This = allows * batching which can make a major impact on performance when using diff --git a/system/physmem.c b/system/physmem.c index c227d4680e33..f19709be59e5 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3398,6 +3398,14 @@ static MemTxResult flatview_read_continue_step(MemTx= Attrs attrs, uint8_t *buf, } } =20 +MemTxResult +rust_section_read_continue_step(MemoryRegionSection *section, MemTxAttrs a= ttrs, + uint8_t *buf, hwaddr len, hwaddr mr_addr, + hwaddr *l) +{ + return flatview_read_continue_step(attrs, buf, len, mr_addr, l, sectio= n->mr); +} + /* Called within RCU critical section. */ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *ptr, @@ -3987,6 +3995,14 @@ static MemTxResult address_space_write_continue_cach= ed(MemTxAttrs attrs, return result; } =20 +MemTxResult +rust_section_write_continue_step(MemoryRegionSection *section, MemTxAttrs = attrs, + const uint8_t *buf, hwaddr len, hwaddr mr= _addr, + hwaddr *l) +{ + return flatview_write_continue_step(attrs, buf, len, mr_addr, l, secti= on->mr); +} + /* Called within RCU critical section. */ static MemTxResult address_space_read_continue_cached(MemTxAttrs attrs, void *ptr, hwaddr le= n, --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496732; cv=none; d=zohomail.com; s=zohoarc; b=cGlbYFCWhBGycM/6pwgzVPx2/oKmTvwNfste9qIpSacd9YT2ouox7Y8uFYEVpDvTw+nzS1/VbpgWKub+HgbjPzYfhR2lvY9erTrKNEYSsaMS5XxLXLW8uwXttCk57S/qRIj826SW6YAyUZhyDiunYO1Obr1DA2w70/yCwZNmFN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496732; 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=Nkq0jJtLtoKVNA8LRWMvn2dsodWQssCqb1yYMcoZtdU=; b=PuvadpqKzTDRlcjOvSRhe3jAyeMwdR7PhxXhzQTszpZQmfEM0R7NkfznG4dQ4KnjVSK/l69PCBIrI7sHBRPCGXp7NqHlYcCqhGbwMIHxZAHheBVGGNO6KJySkv+/s1PsC2FxzmPt5JdTCyG31bNOPbIH/9V3mytN8+JWDlMpt1I= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496732464987.2759284698552; Wed, 8 Jul 2026 00:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwu-0006hk-Om; Wed, 08 Jul 2026 03:44:04 -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 1whMwq-0006Lt-6l; Wed, 08 Jul 2026 03:44:01 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwm-0005DU-Dt; Wed, 08 Jul 2026 03:43:59 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:35 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496637; x=1815032637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IkJHfJxKWBp8jmtuiaJL3EzwgLEqGklUHEndyr1MKuw=; b=dyRdp8LKToC2hQsTj5EvzF5bnkUrztoKRsYaOQ68NudoVS1dvrvW3YAn 4Ne8HKYJlVkXMDG1zI9ap+PzbLL5Kpw2sjiY1TqbKv8KOGHH91IcpdUgQ VhGS2knNWmsEPTY94oV4rzQJP4CDQp1MR7TSScPJSf6dI41dx3QmJXrsc G7CljAthIq+RX2tdvzGBbKlm9ypFwSHy6K0fp9RHqxLCXEvpc7zX+dcz+ K7LCbTnkJw3vMrICa5UYLRYk3L0/xcJJ//zz1/i2H0xozZTWYtAV8vO+r Zn58nDZXPnsyCDxW1qGT15gtN810bz9XYhpVHDKfoTdYhFRlLNWAuI4Va Q==; X-CSE-ConnectionGUID: MI0DzOV+Q/6o4ANxBFBbDg== X-CSE-MsgGUID: fwdTyf4TTqawtVNSinnfVw== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343371" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343371" X-CSE-ConnectionGUID: hAQfwuKERLSDatD6Xu35kA== X-CSE-MsgGUID: og8XPJtdQceZHpvl6J5pkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556038" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 17/26] memory: Add store/load interfaces for Rust Date: Wed, 8 Jul 2026 16:10:43 +0800 Message-Id: <20260708081052.2276617-18-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496733973158501 Content-Type: text/plain; charset="utf-8" Currently, there are many store/load variants defined in memory_ldst.c.inc. However, the vm-memory crate's Bytes::store() and Bytes::load() methods are bound by the AtomicAccess trait, making it almost impossible to select the proper interface (e.g., for l, w, or q) based on a specific type. Therefore, it is necessary to provide interfaces that hide these type details as much as possible. Compared to the address_space_st{size}_{endian} and address_space_ld{size}_{endian} functions, the differences include: * No address translation; they only perform memory access. * They treat the byte array as raw bytes. RAM accesses copy the bytes unchanged. For MMIO accesses, the Rust caller must use the correct endian ordering for the target device (via LeNN/BeNN), just as the C side must select the appropriate address_space_st{size}_le() or _be() variants. * They use byte arrays instead of a single uint64_t for the value being written or read, eliminating the need for the Rust side to convert generic types to u64. - However, this incurs an extra cost for MMIO accesses, as it requires conversion between byte arrays and uint64_t internally. * They do not handle cross-region MMIO accesses. The Rust side will be responsible for handling such edge cases. Signed-off-by: Zhao Liu --- Changes since v1: * Drop the native endian assumption and require the caller to use the target device's endianness. --- include/system/memory.h | 50 ++++++++++++++++++++++++++++ system/physmem.c | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 87006ce79d47..32399c111f48 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2970,6 +2970,56 @@ MemTxResult rust_section_write_continue_step(MemoryR= egionSection *section, MemTxResult rust_section_read_continue_step(MemoryRegionSection *section, MemTxAttrs attrs, uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); =20 +/** + * rust_section_store: Store data to a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function does a single-access store without translation. @buf prov= ides + * raw bytes: RAM uses direct memory copy; MMIO expects data in device + * endianness. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @mr_offset: The address within that memory region. + * @buf: Buffer containing the data to be written. + * @attrs: Memory transaction attributes. + * @len: The number of bytes to write. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed. + */ +MemTxResult rust_section_store(MemoryRegionSection *section, + hwaddr mr_offset, const uint8_t *buf, + MemTxAttrs attrs, hwaddr len); + +/** + * rust_section_load: Load data from a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function does a single-access load without translation. @buf recei= ves + * raw bytes: RAM uses direct memory copy; MMIO returns data in device + * endianness. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @mr_offset: The address within that memory region. + * @buf: The output buffer to store the read data. + * @attrs: Memory transaction attributes. + * @len: The expected number of bytes to read. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed. + */ +MemTxResult rust_section_load(MemoryRegionSection *section, + hwaddr mr_offset, uint8_t *buf, + MemTxAttrs attrs, hwaddr len); + /* Coalesced MMIO regions are areas where write operations can be reordere= d. * This usually implies that write operations are side-effect free. This = allows * batching which can make a major impact on performance when using diff --git a/system/physmem.c b/system/physmem.c index f19709be59e5..51abb6865b96 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3518,6 +3518,78 @@ void physical_memory_read(hwaddr addr, void *buf, hw= addr len) MEMTXATTRS_UNSPECIFIED, buf, len); } =20 +MemTxResult rust_section_store(MemoryRegionSection *section, + hwaddr mr_offset, const uint8_t *buf, + MemTxAttrs attrs, hwaddr len) +{ + MemoryRegion *mr =3D section->mr; + MemTxResult r; + + /* + * Rust encodes the requested endian order in @buf, via LeNN or BeNN. + * + * For RAM, store the bytes unchanged. + * For MMIO, @buf is read into a host-order temporary value, then + * adjust_endianness() converts it to the device's endianness later. + * + * Note that there is no guarantee that the endian order encoded by Ru= st + * will match the target device's endianness. Caller should use the ri= ght + * LeNN or BeNN. + */ + if (!memory_access_is_direct(mr, true, attrs)) { + bool release_lock =3D false; + uint64_t val =3D ldn_he_p(buf, len); + + release_lock |=3D prepare_mmio_access(mr); + r =3D memory_region_dispatch_write(mr, mr_offset, val, + size_memop(len), attrs); + if (release_lock) { + bql_unlock(); + } + } else { + uint8_t *ptr =3D qemu_map_ram_ptr(mr->ram_block, mr_offset); + + memcpy(ptr, buf, len); + invalidate_and_set_dirty(mr, mr_offset, len); + r =3D MEMTX_OK; + } + + return r; +} + +MemTxResult rust_section_load(MemoryRegionSection *section, + hwaddr mr_offset, uint8_t *buf, + MemTxAttrs attrs, hwaddr len) +{ + MemoryRegion *mr =3D section->mr; + MemTxResult r; + + /* + * Similar to rust_section_store(): + * For RAM, load the bytes unchanged, but for MMIO, it uses a host-ord= er + * temporary value to help with conversion. + */ + if (!memory_access_is_direct(mr, false, attrs)) { + bool release_lock =3D false; + uint64_t val; + + release_lock |=3D prepare_mmio_access(mr); + r =3D memory_region_dispatch_read(mr, mr_offset, &val, + size_memop(len), attrs); + stn_he_p(buf, len, val); + if (release_lock) { + bql_unlock(); + } + } else { + uint8_t *ptr =3D qemu_map_ram_ptr(mr->ram_block, mr_offset); + + memcpy(buf, ptr, len); + r =3D MEMTX_OK; + } + + return r; +} + void physical_memory_write(hwaddr addr, const void *buf, hwaddr len) { address_space_write(&address_space_memory, addr, --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496705; cv=none; d=zohomail.com; s=zohoarc; b=d1tiCxLDPnljDs03TkYLo5q/P8dn/UVX/zjLiVFdUMef9VLWUomlvMvfIZVxmT13Vr/bbTk2mdLYxR04fE7pE160YMFkXHC8ZN5r8RpbslIPQzbhKlKdCiqCoPjGt9iL686wS0g43zWIiYFwNT3cB5u2tiQ6QvA8s/Q41Fb2CVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496705; 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=DivmZT+vKyaT4ekwSgSCorr1mnhohePpOak5xKJ3wpM=; b=CnNELYrUgQ889Wm3991e+9LDI+d+sMkQ5hWu7tyRQE964snBVy3WZ19BXYY3AMhuD1sSeP5bUyt2dfmI2kv2t6sQ2TtgPmo/CY6VwoMx6MQi2aKZSU9bjZYoKSqHR26apE0+jrJIvbm+HwSgPIzvUtS+TtvdPXxoM87h/GHNJZ0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496705010630.0713889018223; Wed, 8 Jul 2026 00:45:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMxI-0007N7-In; Wed, 08 Jul 2026 03:44:28 -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 1whMwt-0006Zc-BO; Wed, 08 Jul 2026 03:44:03 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwq-0005Eb-Fh; Wed, 08 Jul 2026 03:44:03 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:39 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496641; x=1815032641; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rSFkOsJu2E+9YsPkkJ314w45wfR0HVp9UkR1a7Hyvls=; b=QE5BLkvAj00fN2nTbpVwC/JhlZTlBv/nAA/A8MQp0PS8rgc47+NK9EkA BymEvjgALAgllqhbjfty2LGrIp+sRNo8Q8p41h/779VTPHKwttFNyVJcC j24aV+I52vLARJYKGxxrYmge/vlbeoPA2SEO/mY73ydbg3/z7pt2C1Jqv hwiQTeUtaaTh0iX8EhJaRRP6/Jg9QXm/EuUKio++NG3czJTggDOeZ/d61 qCMpGBxMGIEYWKc56YF0kOrozE5gsSucF+SQk7dmm24c8QAm1xl3iym+1 +Iy9xf/OVUl+zOBnmr9eauhn62RZ6T9PzfCIu+fR7oYtJPQIEyIFuPCRr Q==; X-CSE-ConnectionGUID: RlsgaH3KSbinZ9Zo02vtcg== X-CSE-MsgGUID: 59LtsHbdR2uisKZo2i0KWQ== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343385" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343385" X-CSE-ConnectionGUID: 6v6yH9IkQt+xweL6p1isWw== X-CSE-MsgGUID: HKerOMJFQPSOT+aqrQoSuA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556052" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 18/26] rust/system/memory: Implement vm_memory::GuestMemoryRegion for MemoryRegionSection Date: Wed, 8 Jul 2026 16:10:44 +0800 Message-Id: <20260708081052.2276617-19-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496706234158500 Content-Type: text/plain; charset="utf-8" Although QEMU already has a native memory region abstraction (MemoryRegion), it supports overlapping regions. Since the vm-memory crate does not support overlapping memory, MemoryRegionSection is a more appropriate choice to implement the vm_memory::GuestMemoryRegion trait. To achieve this, implement vm_memory::GuestMemoryRegion for MemoryRegionSec= tion, along with its required supertrait, GuestMemoryRegionBytes. Additionally, implement Bytes<(MemoryRegionAddress, MemTxAttrs)> to properly attach QEMU's memory transaction attributes to memory operations. Furthermore, provide low-level memory write/read/store/load bindings based on MemoryRegionSection, and add the necessary helpers (fuzz_dma_read() and is_access_allowed()). Signed-off-by: Zhao Liu --- Changes since v1: * Implement GuestMemoryRegionBytes for MemoryRegionSection to satisfy supertrait requirement. * Implement Bytes<(MemoryRegionAddress, MemTxAttrs)> to attach MemTxAttrs. * For write/read, add an extra loop to ensure write/read are actually finished within the same region. --- rust/system/src/memory.rs | 449 +++++++++++++++++++++++++++++++++++++- 1 file changed, 447 insertions(+), 2 deletions(-) diff --git a/rust/system/src/memory.rs b/rust/system/src/memory.rs index 4c258201bad7..34c7b7ce04a1 100644 --- a/rust/system/src/memory.rs +++ b/rust/system/src/memory.rs @@ -2,19 +2,38 @@ // Author(s): Paolo Bonzini // SPDX-License-Identifier: GPL-2.0-or-later =20 -//! Bindings for `MemoryRegion`, `MemoryRegionOps` and `MemTxAttrs` +//! Bindings for `MemoryRegion`, `MemoryRegionOps`, `MemTxAttrs` and +//! `MemoryRegionSection`. =20 use std::{ ffi::{c_uint, c_void, CStr, CString}, + io::ErrorKind, marker::PhantomData, + mem::size_of, + ops::Deref, + sync::atomic::Ordering, }; =20 use common::{callbacks::FnCall, uninit::MaybeUninitField, zeroable::Zeroab= le, Opaque}; use qom::prelude::*; +pub use vm_memory::GuestAddress; +use vm_memory::{ + bitmap::BS, Address, AtomicAccess, Bytes, GuestMemoryError, GuestMemor= yRegion, + GuestMemoryRegionBytes, GuestMemoryResult, GuestUsize, MemoryRegionAdd= ress, ReadVolatile, + WriteVolatile, +}; =20 -use crate::bindings::{self, device_endian, memory_region_init_io}; +use crate::bindings::{ + self, device_endian, memory_region_init_io, rust_section_load, rust_se= ction_read_continue_step, + rust_section_store, rust_section_write_continue_step, section_access_a= llowed, + section_covers_region_addr, section_fuzz_dma_read, MemTxResult, +}; +// FIXME: Convert hwaddr to GuestAddress pub use crate::bindings::{hwaddr, MemTxAttrs}; =20 +/// Corresponds to C `MEMTX_OK` (#define `MEMTX_OK` 0). +const MEMTX_OK: MemTxResult =3D 0; + pub struct MemoryRegionOps( bindings::MemoryRegionOps, // Note: quite often you'll see PhantomData mentioned when dis= cussing @@ -187,3 +206,429 @@ unsafe impl ObjectType for MemoryRegion { unspecified: true, ..Zeroable::ZERO }; + +/// A safe wrapper around [`bindings::MemoryRegionSection`]. +/// +/// This struct is fundamental for integrating QEMU's memory model with +/// the `vm-memory` ecosystem. It directly maps to the concept of +/// [`GuestMemoryRegion`] and implements that trait. +/// +/// ### `MemoryRegion` vs. `MemoryRegionSection` +/// +/// Although QEMU already has native memory region abstraction, this is +/// [`MemoryRegion`], which supports overlapping. But `vm-memory` doesn't +/// support overlapped memory, so `MemoryRegionSection` is more proper +/// to implement [`GuestMemoryRegion`] trait. +/// +/// One point should pay attention is, [`MemoryRegionAddress`] represents = the +/// address or offset within the `MemoryRegionSection`. But traditional C +/// bindings treats memory region address or offset as the offset within +/// `MemoryRegion`. +/// +/// Therefore, it's necessary to do conversion when calling C bindings +/// with `MemoryRegionAddress` from the context of `MemoryRegionSection`. +/// +/// ### Usage +/// +/// Considerring memory access is almost always through `AddressSpace` +/// in QEMU, `MemoryRegionSection` is intended for **internal use only** +/// within the `vm-memory` backend implementation. +/// +/// Device and other external users should **not** use or create +/// `MemoryRegionSection`s directly. Instead, they should work with the +/// higher-level `MemoryRegion` API to create and manage their device's +/// memory. This separation of concerns mirrors the C API and avoids +/// confusion about different memory abstractions. +#[repr(transparent)] +#[derive(common::Wrapper, Debug)] +pub struct MemoryRegionSection(Opaque); + +unsafe impl Send for MemoryRegionSection {} +unsafe impl Sync for MemoryRegionSection {} + +impl Deref for MemoryRegionSection { + type Target =3D bindings::MemoryRegionSection; + + fn deref(&self) -> &Self::Target { + // SAFETY: Opaque<> wraps a pointer from C side. The validity + // of the pointer is confirmed at the creation of Opaque<>. + unsafe { &*self.0.as_ptr() } + } +} + +impl MemoryRegionSection { + /// A fuzz testing hook for DMA read. + /// + /// When `CONFIG_FUZZ` is not set, this hook will do nothing. + #[allow(dead_code)] + fn fuzz_dma_read(&self, addr: GuestAddress, len: GuestUsize) -> &Self { + // SAFETY: Opaque<> ensures the pointer is valid, and here it + // takes into account the offset conversion between MemoryRegionSe= ction + // and MemoryRegion. + unsafe { + section_fuzz_dma_read( + self.as_mut_ptr(), + addr.checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(), + len, + ); + } + self + } + + /// A helper to check if the memory access is allowed. + /// + /// This is needed for memory write/read. + #[allow(dead_code)] + fn is_access_allowed( + &self, + addr: MemoryRegionAddress, + len: GuestUsize, + attrs: MemTxAttrs, + ) -> bool { + // SAFETY: Opaque<> ensures the pointer is valid, and here it + // takes into account the offset conversion between MemoryRegionSe= ction + // and MemoryRegion. + let allowed =3D unsafe { + section_access_allowed( + self.as_mut_ptr(), + attrs, + addr.checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(), + len, + ) + }; + allowed + } +} + +/// Satisfies the `Bytes` supertrait required by +/// `GuestMemoryRegion`. +/// +/// The blanket impl fails with `HostAddressNotAvailable` because +/// `MemoryRegionSection` methods all go through `as_volatile_slice()` and +/// `get_slice()`, which by default return an error. +/// +/// QEMU's real access path is always attrs-aware and reaches this section +/// through the `Bytes<(MemoryRegionAddress, +/// MemTxAttrs)>` impl below. +impl GuestMemoryRegionBytes for MemoryRegionSection {} + +/// The attrs-aware `Bytes` implementation that actually does the C-side +/// memory access for a single `MemoryRegionSection`. +/// +/// This composite impl is the *only* real access path into a +/// `MemoryRegionSection`: QEMU always reaches it through `FlatView` +/// with the real `attrs`. The blanket `GuestMemoryRegionBytes` impl above +/// just satisfies the `GuestMemoryRegion` supertrait bound and is never +/// actually called. +impl Bytes<(MemoryRegionAddress, MemTxAttrs)> for MemoryRegionSection { + type E =3D GuestMemoryError; + + /// Write a byte buffer into guest memory at `addr`. + /// + /// This shouldn't be called to access memory directly; it is the + /// per-region worker invoked by `FlatView`'s write path. The transac= tion + /// `attrs` are forwarded to the C side. And the cross-region is handl= ed by + /// `FlatView`'s write. + fn write( + &self, + buf: &[u8], + (addr, attrs): (MemoryRegionAddress, MemTxAttrs), + ) -> GuestMemoryResult { + let base =3D addr + .checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(); + let total =3D buf.len() as u64; + let mut done: u64 =3D 0; + + while done < total { + // `step` is the attempt size on input and the bytes actually + // handled on output. + let mut step =3D total - done; + + // SAFETY: the pointers and reference are convertible and the + // offset conversion is considered. + let ret =3D unsafe { + rust_section_write_continue_step( + self.as_mut_ptr(), + attrs, + buf[done as usize..].as_ptr(), + total - done, + base + done, + &mut step, + ) + }; + + if ret !=3D MEMTX_OK { + return Err(GuestMemoryError::InvalidBackendAddress); + } + + // A zero-length step can never make progress. + if step =3D=3D 0 { + break; + } + + done +=3D step; + } + + Ok(done as usize) + } + + /// Read a byte buffer from guest memory at `addr`. + /// + /// This shouldn't be called to access memory directly; it is the + /// per-region worker invoked by `FlatView`'s read path. The transact= ion + /// `attrs` are forwarded to the C side. And the cross-region is handl= ed by + /// `FlatView`'s read. + fn read( + &self, + buf: &mut [u8], + (addr, attrs): (MemoryRegionAddress, MemTxAttrs), + ) -> GuestMemoryResult { + let base =3D addr + .checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(); + let total =3D buf.len() as u64; + let mut done: u64 =3D 0; + + while done < total { + // `step` is the attempt size on input and the bytes actually + // handled on output. + let mut step =3D total - done; + + // SAFETY: the pointers and reference are convertible and the + // offset conversion is considered. + let ret =3D unsafe { + rust_section_read_continue_step( + self.as_mut_ptr(), + attrs, + buf[done as usize..].as_mut_ptr(), + total - done, + base + done, + &mut step, + ) + }; + + if ret !=3D MEMTX_OK { + return Err(GuestMemoryError::InvalidBackendAddress); + } + + // A zero-length step can never make progress. + if step =3D=3D 0 { + break; + } + + done +=3D step; + } + + Ok(done as usize) + } + + /// Store a value into guest memory at `addr`. + /// + /// This function - as the low-level store implementation - is + /// called by `FlatView`'s `store()`. And it shouldn't be called to + /// access memory directly. + /// + /// The transaction `attrs` are forwarded to the C side; the `Ordering= ` is + /// ignored because the access is not Rust-atomic. + fn store( + &self, + val: T, + (addr, attrs): (MemoryRegionAddress, MemTxAttrs), + _order: Ordering, + ) -> GuestMemoryResult<()> { + let len =3D size_of::(); + + if len > size_of::() { + return Err(GuestMemoryError::IOError(std::io::Error::new( + ErrorKind::InvalidInput, + "failed to store the data more then 8 bytes", + ))); + } + + // Note: rust_section_store() accepts `const uint8_t *buf`. + // + // This is a "compromise" solution: vm-memory requires AtomicAccess + // but QEMU uses uint64_t as the default type. Here we can't conve= rt + // AtomicAccess to u64, since the compiler will complain "an `as` + // expression can only be used to convert between primitive types = or + // to coerce to a specific trait object", or other endless errors + // about conversion to u64. + // + // Fortunately, we can use a byte array to bridge the Rust wrapper + // and the C binding. This approach is not without a trade-off, + // however: the rust_section_store() function requires an addition= al + // conversion from bytes to a uint64_t for the MMIO case. This per= formance + // overhead is considered acceptable. + // + // SAFETY: the pointers are convertible and the offset conversion = is + // considered. + let res =3D unsafe { + rust_section_store( + self.as_mut_ptr(), + addr.checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(), + val.as_slice().as_ptr(), + attrs, + len as u64, + ) + }; + + match res { + MEMTX_OK =3D> Ok(()), + _ =3D> Err(GuestMemoryError::InvalidBackendAddress), + } + } + + /// Load a value from guest memory at `addr`. + /// + /// This function - as the low-level load implementation - is + /// called by `FlatView`'s `load()`. And it shouldn't be called to + /// access memory directly. + /// + /// The transaction `attrs` are forwarded to the C side; the `Ordering= ` is + /// ignored because the access is not Rust-atomic. + fn load( + &self, + (addr, attrs): (MemoryRegionAddress, MemTxAttrs), + _order: Ordering, + ) -> GuestMemoryResult { + let len =3D size_of::(); + + if len > size_of::() { + return Err(GuestMemoryError::IOError(std::io::Error::new( + ErrorKind::InvalidInput, + "failed to load the data more then 8 bytes", + ))); + } + + let mut val: T =3D T::zeroed(); + + // Note: rust_section_load() accepts `uint8_t *buf`. + // + // This is for a similar reason as store(), with the slight differ= ence + // that rust_section_load() requires an additional conversion from + // uint64_t to bytes. + // + // SAFETY: the pointers are convertible and the offset conversion = is + // considered. + let res =3D unsafe { + rust_section_load( + self.as_mut_ptr(), + addr.checked_add(self.deref().offset_within_region) + .unwrap() + .raw_value(), + val.as_mut_slice().as_mut_ptr(), + attrs, + size_of::() as u64, + ) + }; + + match res { + MEMTX_OK =3D> Ok(val), + _ =3D> Err(GuestMemoryError::InvalidBackendAddress), + } + } + + fn write_slice( + &self, + _buf: &[u8], + _addr: (MemoryRegionAddress, MemTxAttrs), + ) -> GuestMemoryResult<()> { + unimplemented!() + } + + fn read_slice( + &self, + _buf: &mut [u8], + _addr: (MemoryRegionAddress, MemTxAttrs), + ) -> GuestMemoryResult<()> { + unimplemented!() + } + + fn read_volatile_from( + &self, + _addr: (MemoryRegionAddress, MemTxAttrs), + _src: &mut F, + _count: usize, + ) -> GuestMemoryResult + where + F: ReadVolatile, + { + unimplemented!() + } + + fn read_exact_volatile_from( + &self, + _addr: (MemoryRegionAddress, MemTxAttrs), + _src: &mut F, + _count: usize, + ) -> GuestMemoryResult<()> + where + F: ReadVolatile, + { + unimplemented!() + } + + fn write_volatile_to( + &self, + _addr: (MemoryRegionAddress, MemTxAttrs), + _dst: &mut F, + _count: usize, + ) -> GuestMemoryResult + where + F: WriteVolatile, + { + unimplemented!() + } + + fn write_all_volatile_to( + &self, + _addr: (MemoryRegionAddress, MemTxAttrs), + _dst: &mut F, + _count: usize, + ) -> GuestMemoryResult<()> + where + F: WriteVolatile, + { + unimplemented!() + } +} + +impl GuestMemoryRegion for MemoryRegionSection { + type B =3D (); + + /// Get the memory size covered by this `MemoryRegionSection`. + fn len(&self) -> GuestUsize { + self.deref().size as GuestUsize + } + + /// Return the minimum (inclusive) Guest physical address managed by + /// this `MemoryRegionSection`. + fn start_addr(&self) -> GuestAddress { + GuestAddress(self.deref().offset_within_address_space) + } + + fn bitmap(&self) -> BS<'_, Self::B> {} + + /// Check whether the `@addr` is covered by this `MemoryRegionSection`. + fn check_address(&self, addr: MemoryRegionAddress) -> Option { + let region_addr =3D addr + .checked_add(self.deref().offset_within_region)? + .raw_value(); + // SAFETY: the pointer is convertible and the offset conversion is + // considered. + if unsafe { section_covers_region_addr(self.as_mut_ptr(), region_a= ddr) } { + Some(addr) + } else { + None + } + } +} --=20 2.34.1 From nobody Sat Jul 11 14:56:03 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=1783496747; cv=none; d=zohomail.com; s=zohoarc; b=UDvDYi4f+Ycs5XMYvcfoNGrCnsmbzsUFImgaBLa+PGob2hZUNGd1MgZf5UxpLLOwo3kAWFe2xIwE7jvPJ9DWcTA7R8o8N/X7ek4kclL8CpcqEEPv5m/NJwpDLTf72xigMyzAYb3LiKN2s3+KYSfYL18QP4St9KOETFFls0JYVVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783496747; 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=Pm3UFX7fhTh0DsKqXu7mJ8EWMlXlTp/bquwVa5c7IZk=; b=oBVeWKqIKDzi2w0f5/eZ3OMKxLA8TYeC/wT8z1M35YW4/gAApijYXAowFY+En71kqN6meFPnswPW2/7bM7e7a9ubRGfFD9HGlum/Af/zeqVNmrLgDKe1CS1zt/GAEpFRCmtPKRDvzRoiBHv5VieD6eE7W9Nw8zGpNdgEeQAqRYw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783496746985696.0916815849828; Wed, 8 Jul 2026 00:45:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1whMwu-0006gB-Hn; Wed, 08 Jul 2026 03:44:04 -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 1whMwq-0006Ls-6e; Wed, 08 Jul 2026 03:44:01 -0400 Received: from mgamail.intel.com ([198.175.65.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1whMwk-0004ox-GZ; Wed, 08 Jul 2026 03:43:58 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2026 00:43:43 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa008.fm.intel.com with ESMTP; 08 Jul 2026 00:43:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783496635; x=1815032635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s01A4TYlsdhYxVJa19FuPv1TolkBLDQE//62uZNCv2k=; b=kcHr4z06f0PSZmfVY8zZhg0hPu5BGe37LxsaVWttZdtmsTuAyzkVa5dQ TfzuuiUpog3w30QDiZwg6aaseVWYL/IG0CNsQlgDLflEx/d14P39TaFQT xR9uXKD3SsNHP268uHwtkS8QMJRihd7FFdw8xcWRFOulGra5VMX8539o/ 9fTmWYYwf1XSiaHXLorEkLM4KZLmtjmOnEBcm9qhXIDPvJrpsY0HhD1Yy 2TVxsz4tQbPGlc+GU5dkSjxfnGwo/h51svRm4+/m70vHGkKECSStdcdVT HWhlRcpkepk3fSlQaRo5zwkeehwDpMEAcfktH6+5tDfsoyb4+yjlvHfo7 w==; X-CSE-ConnectionGUID: pa/0SJaWR3eAD7Iu30gqzg== X-CSE-MsgGUID: e4I6852HSwaD6Img99OKOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11840"; a="84343391" X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="84343391" X-CSE-ConnectionGUID: RLOYSd36QCGfXERFrUfH2w== X-CSE-MsgGUID: JADoR++sSh+dQN9BKwDmxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,153,1779174000"; d="scan'208";a="251556068" From: Zhao Liu To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S . Tsirkin" , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Junjie Mao , Dapeng Mi , Chuanxiao Dong , Zhao Liu Subject: [RFC v2 19/26] rust/system/memory: Implement vm_memory::GuestMemory for FlatView Date: Wed, 8 Jul 2026 16:10:45 +0800 Message-Id: <20260708081052.2276617-20-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260708081052.2276617-1-zhao1.liu@intel.com> References: <20260708081052.2276617-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=lists1p.gnu.org; Received-SPF: pass client-ip=198.175.65.16; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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 @intel.com) X-ZM-MESSAGEID: 1783496748029158500 Content-Type: text/plain; charset="utf-8" Implement vm_memory::GuestMemory for FlatView, and provide memory write/read/store/load bindings. Note that the semantics of Bytes::read and Bytes::write in FlatView differ from those of the C functions: on the Rust side, read/write operations stop once an error occurs, while on the C side, `MemTxResult` errors are accumulated and continue accessing to subsequent memory regions. This is because the current Rust loop implementation (try_access_full()) simply returns an error and aborts the operation. To achieve the consistent semantics as the C side, it would be necessary to support accumulating MemTxResult. This can be addressed as a future enhancement. Signed-off-by: Zhao Liu --- Changes since v1: * Implement Bytes<(MemoryRegionAddress, MemTxAttrs)> to attach MemTxAttrs. * Move GuestMemoryBackend::try_access() to FlatView::try_access_full(). * Use vm-memory::Permissions to replace is_write flag. --- rust/system/src/memory.rs | 428 +++++++++++++++++++++++++++++++++++++- 1 file changed, 418 insertions(+), 10 deletions(-) diff --git a/rust/system/src/memory.rs b/rust/system/src/memory.rs index 34c7b7ce04a1..9772d1444dfb 100644 --- a/rust/system/src/memory.rs +++ b/rust/system/src/memory.rs @@ -2,8 +2,8 @@ // Author(s): Paolo Bonzini // SPDX-License-Identifier: GPL-2.0-or-later =20 -//! Bindings for `MemoryRegion`, `MemoryRegionOps`, `MemTxAttrs` and -//! `MemoryRegionSection`. +//! Bindings for `MemoryRegion`, `MemoryRegionOps`, `MemTxAttrs` +//! `MemoryRegionSection` and `FlatView`. =20 use std::{ ffi::{c_uint, c_void, CStr, CString}, @@ -18,15 +18,16 @@ use qom::prelude::*; pub use vm_memory::GuestAddress; use vm_memory::{ - bitmap::BS, Address, AtomicAccess, Bytes, GuestMemoryError, GuestMemor= yRegion, - GuestMemoryRegionBytes, GuestMemoryResult, GuestUsize, MemoryRegionAdd= ress, ReadVolatile, - WriteVolatile, + bitmap::BS, Address, AtomicAccess, Bytes, GuestMemoryBackend, GuestMem= oryError, + GuestMemoryRegion, GuestMemoryRegionBytes, GuestMemoryResult, GuestUsi= ze, MemoryRegionAddress, + Permissions, ReadVolatile, WriteVolatile, }; =20 use crate::bindings::{ - self, device_endian, memory_region_init_io, rust_section_load, rust_se= ction_read_continue_step, - rust_section_store, rust_section_write_continue_step, section_access_a= llowed, - section_covers_region_addr, section_fuzz_dma_read, MemTxResult, + self, address_space_lookup_section, device_endian, flatview_translate_= section, + memory_region_init_io, rust_section_load, rust_section_read_continue_s= tep, rust_section_store, + rust_section_write_continue_step, section_access_allowed, section_cove= rs_region_addr, + section_fuzz_dma_read, MemTxResult, }; // FIXME: Convert hwaddr to GuestAddress pub use crate::bindings::{hwaddr, MemTxAttrs}; @@ -260,7 +261,6 @@ impl MemoryRegionSection { /// A fuzz testing hook for DMA read. /// /// When `CONFIG_FUZZ` is not set, this hook will do nothing. - #[allow(dead_code)] fn fuzz_dma_read(&self, addr: GuestAddress, len: GuestUsize) -> &Self { // SAFETY: Opaque<> ensures the pointer is valid, and here it // takes into account the offset conversion between MemoryRegionSe= ction @@ -280,7 +280,6 @@ fn fuzz_dma_read(&self, addr: GuestAddress, len: GuestU= size) -> &Self { /// A helper to check if the memory access is allowed. /// /// This is needed for memory write/read. - #[allow(dead_code)] fn is_access_allowed( &self, addr: MemoryRegionAddress, @@ -632,3 +631,412 @@ fn check_address(&self, addr: MemoryRegionAddress) ->= Option