From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104596; cv=none; d=zohomail.com; s=zohoarc; b=bY/RIkthRCAbBQt6awfh+15zC5vcvI2l4FZFLeSHd4qIZFvLFTukOZamN3Bdn8p/P46bu2PEbi6pw8UmTlAqolTOqs5sbZE73y1NEmzHGOu6im1oGan9Vbnj8jRhg3PmGbolsAhyBHmGVN+lio+c2gveQdw7S8x/Wj3kr42/vWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104596; 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=cvXKMgEe/XNJgIWOzfE8NdJOesl0DV+BIsQqqBzCXzQ=; b=bDdEvkFwAxS/QJzlJJbjy8+R+guIbWbcFrZDYHGFaQ4X77TISey1VrOK5S6k/8zVdzDNKDA/OBMm5JKlc2EcG3MftVoUdtsZvmBoP0PfUOJdTt9AsASXGxRd/mHorCLUQfnL88aJvE2GueWrHS4XqXL7pAajp9uORzYfX40nZ80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104596358967.7467508929831; Fri, 17 Jan 2025 01:03:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiE0-0001r8-0g; Fri, 17 Jan 2025 04:01:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiDs-0001pH-AL for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiDq-00082V-Au for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:00 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-k7XQP0jwNBC-3wNu7Bfecw-1; Fri, 17 Jan 2025 04:00:55 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aa6a87f324cso207798366b.1 for ; Fri, 17 Jan 2025 01:00:55 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384ce1f1asm138026466b.58.2025.01.17.01.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:00:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cvXKMgEe/XNJgIWOzfE8NdJOesl0DV+BIsQqqBzCXzQ=; b=JGnQ4OmNe2KT/bAuFXKMfxM01hAfja+RIscWwwPYsS292uWYtqoK9Da4Kp/HH79Q3VxhVA U/2io2dppbiGJycoRCkQ0QkykJBsIDDYgZnE49vcHB29BWunNlTg5AXMB2JdEQpq2Cbkbm 1zSxNNZwyZiCF2xMVJ5/J7Z1ZhOIwBQ= X-MC-Unique: k7XQP0jwNBC-3wNu7Bfecw-1 X-Mimecast-MFC-AGG-ID: k7XQP0jwNBC-3wNu7Bfecw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104453; x=1737709253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cvXKMgEe/XNJgIWOzfE8NdJOesl0DV+BIsQqqBzCXzQ=; b=t4psl1318frx7dNJlwVlaiXtPYbtRAhPd5vhKrx/FiWq8z9sIVN45YqQjbh0uRHqx/ oKDuO2Ep/Ns6ce+ksyP9EFUuKw6ROu5GjKK5JpAq2T+9oNDne55QEwKMsuLUL4mYQnTh d2kAD0CLyM5CAN2vZhXxQnYROSaWZtK/HVubGZwsc4qERnkMyVTYwcwH4RSPvoqhY5ZH oa9D96RImm8zc9NkTpyRRL67asyDdTqOjFfKdRnOVYcF3TAHDlLAnCqNjHfsAmSPP7EU V3jwXWbf8CZpMHzSPfWB2y76Wl7ZNs3/kQiwr8KkB4VBFj6MNgRaBTLgWqCOxNLGeUyI 9G0A== X-Gm-Message-State: AOJu0YzLN4vHAL4wYYV8sTFxOURup5sJEFUKKiODuA/Ym9DLCVokSXyf Fedh2+nYgOMcYOiNEDgr+9yd1QVRHX6FX/lHihR904bYiB/3dvoWQfX48dMBtTJB8jC7xKwgWho 7gL/+yMiWmuiRYyGcpTvnvBV5LGO6XpbCOzI3UpM5ddR+YCQ52qwJ6DYoEQqumlyhNZKdEBRA9E J7QI6hyEe3qEnt2DPerkY1jkGc8GwLBgddn4pEBEU= X-Gm-Gg: ASbGncvIWlBoKwmQCMseTSMn/sd59L0oNVUQYxxVt6VgJoDNIiCTSaL8vtlgj1Rc40s GoWmySDVw1Hygjpegb3GK5VjX7vTk62a6HjQmx9FsgXgyU9K3uALfyxB4DI8EJJlftw1iBJ0c8R O8/gI/lukXR3iQLKuZPtXCmo+2NzAhXhnh3iDzHYDg3K5D334J9rpV1reJhXmo3nKeN0t3Pd0a3 iIk4AWgGMggK6eFgw4a4Dxh1FT3V9m+wKRvr9P6ogxDemBq94VWb2mEVmC0 X-Received: by 2002:a17:907:3f90:b0:aa6:6f92:74b1 with SMTP id a640c23a62f3a-ab38b231a83mr181801066b.13.1737104452969; Fri, 17 Jan 2025 01:00:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvqhUySBEw8Q64pnKUaRda8OnfrPnt/UYfBdTwM2ymJyrk5d86ahPNa4PT2etge9Az8gYbtQ== X-Received: by 2002:a17:907:3f90:b0:aa6:6f92:74b1 with SMTP id a640c23a62f3a-ab38b231a83mr181793666b.13.1737104452035; Fri, 17 Jan 2025 01:00:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 01/10] rust: vmstate: add new type safe implementation Date: Fri, 17 Jan 2025 10:00:37 +0100 Message-ID: <20250117090046.1045010-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104596716019000 Content-Type: text/plain; charset="utf-8" The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration. Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type. The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame. Introduce the trait and some functions to access it; the actual implementation comes later. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/prelude.rs | 2 + rust/qemu-api/src/vmstate.rs | 113 +++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 6 deletions(-) diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index 4ea70b9c823..2dc86e19b29 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -18,3 +18,5 @@ pub use crate::qom_isa; =20 pub use crate::sysbus::SysBusDeviceMethods; + +pub use crate::vmstate::VMState; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 63c897abcdf..b839a7d6b7f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -4,13 +4,114 @@ =20 //! Helper macros to declare migration state for device models. //! -//! Some macros are direct equivalents to the C macros declared in -//! `include/migration/vmstate.h` while -//! [`vmstate_subsections`](crate::vmstate_subsections) and -//! [`vmstate_fields`](crate::vmstate_fields) are meant to be used when -//! declaring a device model state struct. +//! This module includes three families of macros: +//! +//! * [`vmstate_unused!`](crate::vmstate_unused) and +//! [`vmstate_of!`](crate::vmstate_of), which are used to express the +//! migration format for a struct. This is based on the [`VMState`] tra= it, +//! which is defined by all migrateable types. +//! +//! * helper macros to declare a device model state struct, in particular +//! [`vmstate_subsections`](crate::vmstate_subsections) and +//! [`vmstate_fields`](crate::vmstate_fields). +//! +//! * direct equivalents to the C macros declared in +//! `include/migration/vmstate.h`. These are not type-safe and should no= t be +//! used if the equivalent functionality is available with `vmstate_of!`. =20 -pub use crate::bindings::VMStateDescription; +use core::marker::PhantomData; + +pub use crate::bindings::{VMStateDescription, VMStateField}; + +/// This macro is used to call a function with a generic argument bound +/// to the type of a field. The function must take a +/// [`PhantomData`]`` argument; `T` is the type of +/// field `$field` in the `$typ` type. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::call_func_with_field; +/// # use core::marker::PhantomData; +/// const fn size_of_field(_: PhantomData) -> usize { +/// std::mem::size_of::() +/// } +/// +/// struct Foo { +/// x: u16, +/// }; +/// // calls size_of_field::() +/// assert_eq!(call_func_with_field!(size_of_field, Foo, x), 2); +/// ``` +#[macro_export] +macro_rules! call_func_with_field { + // Based on the answer by user steffahn (Frank Steffahn) at + // https://users.rust-lang.org/t/inferring-type-of-field/122857 + // and used under MIT license + ($func:expr, $typ:ty, $($field:tt).+) =3D> { + $func(loop { + #![allow(unreachable_code)] + const fn phantom__(_: &T) -> ::core::marker::PhantomData= { ::core::marker::PhantomData } + // Unreachable code is exempt from checks on uninitialized val= ues. + // Use that trick to infer the type of this PhantomData. + break ::core::marker::PhantomData; + break phantom__(&{ let value__: $typ; value__.$($field).+ }); + }) + }; +} + +/// A trait for types that can be included in a device's migration stream.= It +/// provides the base contents of a `VMStateField` (minus the name and off= set). +/// +/// # Safety +/// +/// The contents of this trait go straight into structs that are parsed by= C +/// code and used to introspect into other structs. Be careful. +pub unsafe trait VMState { + /// The base contents of a `VMStateField` (minus the name and offset) = for + /// the type that is implementing the trait. + const BASE: VMStateField; +} + +/// Internal utility function to retrieve a type's `VMStateField`; +/// used by [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_base(_: PhantomData) -> VMStateField { + T::BASE +} + +/// Return the `VMStateField` for a field of a struct. The field must be +/// visible in the current scope. +/// +/// In order to support other types, the trait `VMState` must be implement= ed +/// for them. +#[macro_export] +macro_rules! vmstate_of { + ($struct_name:ty, $field_name:ident $(,)?) =3D> { + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + offset: $crate::offset_of!($struct_name, $field_name), + // Compute most of the VMStateField from the type of the field. + ..$crate::call_func_with_field!( + $crate::vmstate::vmstate_base, + $struct_name, + $field_name + ) + } + }; +} + +// Add a couple builder-style methods to VMStateField, allowing +// easy derivation of VMStateField constants from other types. +impl VMStateField { + #[must_use] + pub const fn with_version_id(mut self, version_id: i32) -> Self { + assert!(version_id >=3D 0); + self.version_id =3D version_id; + self + } +} =20 #[doc(alias =3D "VMSTATE_UNUSED_BUFFER")] #[macro_export] --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104566; cv=none; d=zohomail.com; s=zohoarc; b=C0/ZLZRNzwIUrBONsdODVjfx2gslEyap66vDn0sp5VpjwoZBNtsWbuEIssK5gYicb2g/9xyaOJ4y1IFF7/nNafUoCKBzh0DNTwslPN4nE0BGI8EVv5P4nXZEs4tE+Dz5RXgj8q7/GxJICrgBd23ztIiqxaisdnjQPSI0Pzava/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104566; 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=QcKUQtrDueRo7pBQ0SWKWSoQ8r+x6BtzsurQvn4mXbk=; b=UE5kD6tLaJ71Yn0cpPD46K8dqsXLwHJnwi+cvoggAUkaaEaLBffaoTC6mz6Ug8+7PfOvaQXviuKw/DnEPL8+UxNU0LUseD168lyrzlI4Ku+zPZcwfaa434yaRzLOz29mzXgrRI5NFnckwXZV71HvwskT0IhAVjnConnx3HHLLzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17371045660771005.9134549840693; Fri, 17 Jan 2025 01:02:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiF7-0002tL-Cn; Fri, 17 Jan 2025 04:02:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiF0-0002ag-At for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:02:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEx-0008Bi-9S for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:02:10 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-k64KPMpxN_Kur8GO7tj0QA-1; Fri, 17 Jan 2025 04:00:57 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa6a7bea04cso142818966b.3 for ; Fri, 17 Jan 2025 01:00:57 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384c5700bsm135155566b.24.2025.01.17.01.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:00:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QcKUQtrDueRo7pBQ0SWKWSoQ8r+x6BtzsurQvn4mXbk=; b=JKq3n+1XRUMf1oW5o96wzsM923qsimntJRhspO9/TecPZesEY2Jv1wXdK9A1cP1UOpCVep OADDb9b7fmq2j+eGxoYJg6DerYBQ6o09T4aENtOvgOOpZZVoxRjYtvWiXW8EIo7gJHi1kX ZCgP0o4z9SZoIzaE/5XDE9IOPhQUM0c= X-MC-Unique: k64KPMpxN_Kur8GO7tj0QA-1 X-Mimecast-MFC-AGG-ID: k64KPMpxN_Kur8GO7tj0QA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104456; x=1737709256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QcKUQtrDueRo7pBQ0SWKWSoQ8r+x6BtzsurQvn4mXbk=; b=cfBzl7Jb9p+kZ8j1SP32FgmtNbzuhlZu0j/cfoQBoZjArnO6C/lozg8SAQwc/Vnqfv 8iVUCrlFdNv1HSx5PzddZdg9jTqSkf+ahCjH0VCDD5g7Gc3XFdxnYRS04Yu7kilHcjTx n7ILzfE3kmNKms1w+9RwxT7wWYnlbIpTDBMZhjhdtvm/4q+hkB8S99kJXVu4ikxJ2IDZ Qq1j7YhQ9awRsO0aw2zqE2CyHgf66tXfYusFgYr/f+PcNZ9o8HyLPXethnPY095UyD27 IdPMdndKRFWeFiA6nV9f4RYo7bWRvtNJucDj0YZQEsB+sv1u0r+G1CyWjknIcUKfwrVZ NkIg== X-Gm-Message-State: AOJu0YwKIFnCC2Ssk2BsB6CkZYXvViu/4w22QUU6jYQvza5ehA6PiZte iiUcsTUFpPM958KGe67/KgGRFktrpTa1XXM2RevdaeQHpSvTUG4uZICvpI/kbMFOZAMmwZqUBPp CxNV/1aMlhy9wO5pF4sqcUAn0rHM9IqsWNEV/O07zgj6EJpMCwIrnBsskrf9TZR4IJlm3vl12zQ m4BQD2ImS1MvED9E3fiMITevog2mYIsSMXoE7tnAo= X-Gm-Gg: ASbGnctBp86uldt2SGBh6CrHgjSWqnfx+VQc4JT9mjf9U/g3SwKyQslhROghCuBdOUw oKkC9cdTCDmqQFZhmLQTm429UhfXxMQJHVopyL0ceGaQlK3scdDc3q9K2vlHaxgGzyvp0CVuO+/ 2gY+zjj0rcwzHwNqWcYpM6uTaQa1+rovRS5C8W7+whx9g6brL7NbhW5FEPFRj/zFWNgcaYJU1qu HR1T1Ae46ECsLM0lisjlOeErxw3iug7cF36T6bfAQ0Gii3BWPqNHsSqq+Xj X-Received: by 2002:a17:907:7e92:b0:aab:eefc:92e5 with SMTP id a640c23a62f3a-ab38b1f33e1mr162784566b.14.1737104455598; Fri, 17 Jan 2025 01:00:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZ7Vgh8tE9VcpYMeLU4Fo6rPJMcIyAgL7R/UTRL3pnynHVBJn2jPO6XB7YvXYDHkRMvb27Dw== X-Received: by 2002:a17:907:7e92:b0:aab:eefc:92e5 with SMTP id a640c23a62f3a-ab38b1f33e1mr162778966b.14.1737104454943; Fri, 17 Jan 2025 01:00:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 02/10] rust: vmstate: implement VMState for non-leaf types Date: Fri, 17 Jan 2025 10:00:38 +0100 Message-ID: <20250117090046.1045010-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104568630019000 Content-Type: text/plain; charset="utf-8" Arrays, pointers and cells use a VMStateField that is based on that for the inner type. The implementation therefore delegates to the VMState implementation of the inner type. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/vmstate.rs | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index b839a7d6b7f..abe15c96011 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -19,8 +19,9 @@ //! `include/migration/vmstate.h`. These are not type-safe and should no= t be //! used if the equivalent functionality is available with `vmstate_of!`. =20 -use core::marker::PhantomData; +use core::{marker::PhantomData, mem, ptr::NonNull}; =20 +use crate::bindings::VMStateFlags; pub use crate::bindings::{VMStateDescription, VMStateField}; =20 /// This macro is used to call a function with a generic argument bound @@ -102,6 +103,15 @@ macro_rules! vmstate_of { }; } =20 +impl VMStateFlags { + const VMS_VARRAY_FLAGS: VMStateFlags =3D VMStateFlags( + VMStateFlags::VMS_VARRAY_INT32.0 | + VMStateFlags::VMS_VARRAY_UINT8.0 | + VMStateFlags::VMS_VARRAY_UINT16.0 | + VMStateFlags::VMS_VARRAY_UINT32.0 + ); +} + // Add a couple builder-style methods to VMStateField, allowing // easy derivation of VMStateField constants from other types. impl VMStateField { @@ -111,6 +121,73 @@ pub const fn with_version_id(mut self, version_id: i32= ) -> Self { self.version_id =3D version_id; self } + + #[must_use] + pub const fn with_array_flag(mut self, num: usize) -> Self { + assert!(num <=3D 0x7FFF_FFFFusize); + assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) =3D=3D 0); + assert!((self.flags.0 & VMStateFlags::VMS_VARRAY_FLAGS.0) =3D=3D 0= ); + if (self.flags.0 & VMStateFlags::VMS_POINTER.0) !=3D 0 { + self.flags =3D VMStateFlags(self.flags.0 & !VMStateFlags::VMS_= POINTER.0); + self.flags =3D VMStateFlags(self.flags.0 | VMStateFlags::VMS_A= RRAY_OF_POINTER.0); + } + self.flags =3D VMStateFlags(self.flags.0 & !VMStateFlags::VMS_SING= LE.0); + self.flags =3D VMStateFlags(self.flags.0 | VMStateFlags::VMS_ARRAY= .0); + self.num =3D num as i32; + self + } + + #[must_use] + pub const fn with_pointer_flag(mut self) -> Self { + assert!((self.flags.0 & VMStateFlags::VMS_POINTER.0) =3D=3D 0); + self.flags =3D VMStateFlags(self.flags.0 | VMStateFlags::VMS_POINT= ER.0); + self + } +} + +// Transparent wrappers: just use the internal type + +macro_rules! impl_vmstate_transparent { + ($type:ty where $base:tt: VMState $($where:tt)*) =3D> { + unsafe impl<$base> VMState for $type where $base: VMState $($where= )* { + const BASE: VMStateField =3D VMStateField { + size: mem::size_of::<$type>(), + ..<$base as VMState>::BASE + }; + } + }; +} + +impl_vmstate_transparent!(std::cell::Cell where T: VMState); +impl_vmstate_transparent!(std::cell::UnsafeCell where T: VMState); +impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); +impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); + +// Pointer types using the underlying type's VMState plus VMS_POINTER +// Note that references are not supported, though references to cells +// could be allowed. + +macro_rules! impl_vmstate_pointer { + ($type:ty where $base:tt: VMState $($where:tt)*) =3D> { + unsafe impl<$base> VMState for $type where $base: VMState $($where= )* { + const BASE: VMStateField =3D <$base as VMState>::BASE.with_poi= nter_flag(); + } + }; +} + +impl_vmstate_pointer!(*const T where T: VMState); +impl_vmstate_pointer!(*mut T where T: VMState); +impl_vmstate_pointer!(NonNull where T: VMState); + +// Unlike C pointers, Box is always non-null therefore there is no need +// to specify VMS_ALLOC. +impl_vmstate_pointer!(Box where T: VMState); + +// Arrays using the underlying type's VMState plus +// VMS_ARRAY/VMS_ARRAY_OF_POINTER + +unsafe impl VMState for [T; N] { + const BASE: VMStateField =3D ::BASE.with_array_flag(N); } =20 #[doc(alias =3D "VMSTATE_UNUSED_BUFFER")] --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104529; cv=none; d=zohomail.com; s=zohoarc; b=hYmcKra3y9GwSloRRRDWO6IACitra49dHp/4CUlb8sOcPf/INRucQbOvdoPpUW6Zrb0NMYiLZhf0VNuHvEDDNj/e2tTfMesErWO3e3V7VO3nOCMFpiQbF/gu6enAeTSOnptnndRj4Hcv4q7El/yce06NkSFNPUrd66gt4nBREl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104529; 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=akeAMDk9FwMfEl5tkTkqUI3vd74PME5w9KJGiAUAlW4=; b=BrNrqZ/H6VfAEW02QQmiWyVOuBbeSQUgfzS9SC1HS8wVcln8EMMSsUQPYgRISFAM3oBaTGZrk9ulGeYKJdFdmhR4kqSF1B1js/0K+BIyNJm3ZpZ7+8wM8tI1kQvegygI/uWdeDLC5/0iVdG+ZrX4TDCT9iL340S8EDV/kSIz6bw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104529629642.8001079891856; Fri, 17 Jan 2025 01:02:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEC-0001uO-50; Fri, 17 Jan 2025 04:01:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE8-0001uC-JZ for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiDu-00083K-JN for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:12 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-iuEmghAWPkCWFfheFOdIyA-1; Fri, 17 Jan 2025 04:01:00 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab2e529dc35so200578466b.3 for ; Fri, 17 Jan 2025 01:01:00 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5db73edce5csm1179535a12.75.2025.01.17.01.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=akeAMDk9FwMfEl5tkTkqUI3vd74PME5w9KJGiAUAlW4=; b=Lt6D5qXa3fGaTIzQXTr+K0TKkagPhBpMb9zx/bhOewZr2OBkRdYXW9ohj+PXfE7hFQsa8w smLWMEkO7WNCG9UBGrrCP0XrzrnBgn1PbdcqgYNLkfxuxOfwIkgIbkDT2v/9UudAiccg56 kSdDd03VdBOZZDRv6K7130Vhh5dVUUM= X-MC-Unique: iuEmghAWPkCWFfheFOdIyA-1 X-Mimecast-MFC-AGG-ID: iuEmghAWPkCWFfheFOdIyA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104458; x=1737709258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=akeAMDk9FwMfEl5tkTkqUI3vd74PME5w9KJGiAUAlW4=; b=ToiSj263aKjEj2bC7nD4it+7Gg4S2PSJvMsVUkr0eWQ//7xMVIFaHqOrKLr8c+etaE ppnkfvHdD4QUzLVIONApXTZWfe9rxOSHNQnmYK3zirg2gEMZZQcmvpf1MMXpeE2xuhud zYm1zommyx6Frrsch4f9XMqViv2cWlw+3jg+4PzMNsIrO66MiIaFn65aFyJqTwtkkowt c+ktgIuPnDfu15+LikFjknyAEEP1YQoL7XrhmACBQwdv6k7QYiZw4K3ohO6hfgl1oohB 2oa1/zvPI3Ja6HLk27R4S7kD40WvO0QACGGLMjWng8T+qTqS4LqXFOXoy6Jl1yO6C32a bOeA== X-Gm-Message-State: AOJu0YyLbLUEmZsNmc4mJ81qvz+Ft1ZGh7Ylq6AmK28S1wzmkYnXLxQs l9eil4wYbbgzUCSUzjxc5F40MRKPJnytjIXrKWokd8U4NpV8Kzo/jV+M/Lq9Thg1VJMpVXoVTvj BOmxiCzOzE0ou6BHGzYlOYPYX+4UIfpu+muNDCueVJsN5RbjcSr5CA1qB/gS0GVKVbuxWPiPfOP ht9JuQe4av6ssdTKauK/PGmAekHu4PHbYf1usaIfY= X-Gm-Gg: ASbGncsapr91wXOWFbQAlh/LQriKu35bA144b/Pbe+LsRYQ5vnuKgxyk34FdTas0r1/ 1WvTkHsD5xStNqaTgag1FFs0XG4lmJ7eGabb/iHNTFgPlWyOr7PboBMfyMWCROU3Kd9w0LK7xVG qY+77QtSuEaRejnDGLu3CqMjl1iFw5eHKKiy75t6BNgNCb4xilhDyn/0705DMFOABHODJAf9NXI x6JrciaJzZo/4htp3WYzKvb0DdDGOYPoyYEvp2zK0pm2YVjyqCWSkHgWrBp X-Received: by 2002:a17:907:96a9:b0:ab2:f8e9:5f57 with SMTP id a640c23a62f3a-ab38b10f619mr195299766b.21.1737104458389; Fri, 17 Jan 2025 01:00:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxHOU9OwRqV68XgP0xQ6V7I/WKMru/CxBrLxzuAJA1jP+I0o91Um4xqk7vMiXXcJ8BtwNJ5A== X-Received: by 2002:a17:907:96a9:b0:ab2:f8e9:5f57 with SMTP id a640c23a62f3a-ab38b10f619mr195295466b.21.1737104457898; Fri, 17 Jan 2025 01:00:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 03/10] rust: vmstate: add varray support to vmstate_of! Date: Fri, 17 Jan 2025 10:00:39 +0100 Message-ID: <20250117090046.1045010-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104532108019000 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/vmstate.rs | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index abe15c96011..3c3ed8510ab 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -72,6 +72,15 @@ pub unsafe trait VMState { /// The base contents of a `VMStateField` (minus the name and offset) = for /// the type that is implementing the trait. const BASE: VMStateField; + + /// A flag that is added to another field's `VMStateField` to specify = the + /// length's type in a variable-sized array. If this is not a support= ed + /// type for the length (i.e. if it is not `u8`, `u16`, `u32`), using = it + /// in a call to [`vmstate_of!`](crate::vmstate_of) will cause a + /// compile-time error. + const VARRAY_FLAG: VMStateFlags =3D { + panic!("invalid type for variable-sized array"); + }; } =20 /// Internal utility function to retrieve a type's `VMStateField`; @@ -80,6 +89,13 @@ pub const fn vmstate_base(_: PhantomData)= -> VMStateField { T::BASE } =20 +/// Internal utility function to retrieve a type's `VMStateFlags` when it +/// is used as the element count of a `VMSTATE_VARRAY`; used by +/// [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_varray_flag(_: PhantomData) -> VMState= Field { + T::VARRAY_FLAG +} + /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// @@ -87,18 +103,23 @@ pub const fn vmstate_base(_: PhantomData) -> VMStateField { /// for them. #[macro_export] macro_rules! vmstate_of { - ($struct_name:ty, $field_name:ident $(,)?) =3D> { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:exp= r)?])? $(,)?) =3D> { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, offset: $crate::offset_of!($struct_name, $field_name), // Compute most of the VMStateField from the type of the field. + $(.num_offset: $crate::offset_of!($struct_name, $num),)? ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name, $field_name - ) + )$(.with_varray_flag($crate::call_func_with_field!( + $crate::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply($factor))?)? } }; } @@ -143,6 +164,22 @@ pub const fn with_pointer_flag(mut self) -> Self { self.flags =3D VMStateFlags(self.flags.0 | VMStateFlags::VMS_POINT= ER.0); self } + + #[must_use] + pub const fn with_varray_flag(mut self, flag: VMStateFlags= ) -> VMStateField { + assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) !=3D 0); + self.flags =3D VMStateFlags(self.flags.0 & !VMStateFlags::VMS_ARRA= Y.0); + self.flags =3D VMStateFlags(self.flags.0 | flag.0); + self + } + + #[must_use] + pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField { + assert!(num <=3D 0x7FFF_FFFFu32); + self.flags =3D VMStateFlags(self.flags.0 | VMStateFlags::VMS_MULTI= PLY_ELEMENTS.0); + self.num =3D num as i32; + self + } } =20 // Transparent wrappers: just use the internal type @@ -154,6 +191,7 @@ unsafe impl<$base> VMState for $type where $base: VMSta= te $($where)* { size: mem::size_of::<$type>(), ..<$base as VMState>::BASE }; + const VARRAY_FLAG: VMStateFlags =3D <$base as VMState>::VARRAY= _FLAG; } }; } --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104559; cv=none; d=zohomail.com; s=zohoarc; b=COcd7p6n1DcJTonlPleF91sq9J77yiBNRPGg17TXqWdAEvOprSbbwNFSb48SpT8Kbf+sejTE5qkyeLPnUZ9uN6EcXY9vgcm5372B4HdREmg+zabhtemmPgFcRNbpXxzg7tzhtBo9Zuecd2tKxiy4Px1b3jxjTTMmBKWpnjaITDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104559; 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=CL3TI60x6PujqVqUZyFN6Jp1dFCTcnvDg29W8z5vXdA=; b=GxVvwM/BL1fsalLxz6U8nGpXyb+NIUJYuvW6qn610LonQUjoLA9OLM36YJ5uUBerLJ4u/QjN5GtzymlBC8wPzqfBA29y9it3fhBk2o7dUkQUfFCALDeCKyvh6id/sUyrNuldujilctH/4e58LlXPNdd3Gb08cAvEo+B5wJYYijg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104559833404.47732084443305; Fri, 17 Jan 2025 01:02:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiE2-0001ry-69; Fri, 17 Jan 2025 04:01:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiDz-0001rC-TP for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiDx-00083l-63 for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:07 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-371-_4aKho1oOtSQhpRQ3F7z8w-1; Fri, 17 Jan 2025 04:01:02 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab2b300e5daso238025366b.1 for ; Fri, 17 Jan 2025 01:01:02 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384ce208fsm137249466b.65.2025.01.17.01.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CL3TI60x6PujqVqUZyFN6Jp1dFCTcnvDg29W8z5vXdA=; b=f/wJfXgSfENkhkwtJ880fLgO40CBo3ZRuZNPd0aMGvEFuM9wJmwhPgdBqLPYZC/ObTHLi0 MN4yq3tdlAnxgcX8sUGwaBMCq0xdkFIo2yq6RFN3jKQXJ1ctuN7+aX+5mcXSG86hetf0Ty fKI3r+Q8nxi4RCYJK5EtSBE7rr7GSXM= X-MC-Unique: _4aKho1oOtSQhpRQ3F7z8w-1 X-Mimecast-MFC-AGG-ID: _4aKho1oOtSQhpRQ3F7z8w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104461; x=1737709261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CL3TI60x6PujqVqUZyFN6Jp1dFCTcnvDg29W8z5vXdA=; b=Z5qLBcB1LgaMsodN8Xb6RSGYOTsNdq8UnrlH1z8QedYEzksKT4nhjJ7aFDSJKpj9qx /FaNOKU5F0FwAE8+kXostOKx3a+EfbhJrmiCLh6ZSPKeGQkyKJlQPToF+oTn8JBopcsV OO5B4trTTlc3ZG1U+y41nk+rxyVyDGYtR3q04bGEllXeU5OYZ9Hvh3Q+ofEcLyFH0+/J +ZgGUI+F/DlDLXv2RqJVLzgj6e1fQkDPlyyQiVD37KVTlatQVa3EVFflfc0MoCWvi2L1 GyHtMpdjjtkio8DKBkG5JtfKOqJDncVhXtBAJCEbSiYVQZr7/kmS2NBs3vkVqfJMHTu+ Bfiw== X-Gm-Message-State: AOJu0Ywsv2pqb1oQN9OjnBKM9y6TM+KJLIoP2MQM0A3tuI7UcaGJtItP K/dUk2+4dLWA7ObMbytBdG4yMh+WMP2avtcH2HD2TbKApLgBKYjgEE67TtIG9X8v43tEoUchUhD FKMoMXoI1GPrBNWhQUWOXaWk9vBmJhoRimyekCR5PDeKCpDg20phDJqfrgtoePmTpWkyJSK8/W2 PKRTJ/b/WAosT48D9jLvsAUPkK3PhJ8BjtO2xnWbk= X-Gm-Gg: ASbGncuHR3lDc4p4eEVFBCFChUYtRpZ5UQR49Kvcv3ASABzQWG3o1mMxCu9fz88yTxj 4zQo5O7XTLcCxEwxRkZlKas8mYIP4c9iI1N9TY9EUNIBojSPpqryV2LicZjHe4isrtHt9JWetP7 d7k5sHdEQGuNixoHRY4lDMQS2qE0UnFatM6u6cyKU4pFm9x4PBsqjQTEdUD78qKBN8b+/xPdEzH zFY+ByB0oKBldvxjdM20bfMu2F3XQAjMz8kVEYvWZdpivCFZtc00v68fctZ X-Received: by 2002:a17:907:d1b:b0:aab:cd45:5d3c with SMTP id a640c23a62f3a-ab38b3c7729mr176996166b.50.1737104460532; Fri, 17 Jan 2025 01:01:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2xtuKFEQyhaT4qfnZUOyLzwjzCVzPWwIpe1FuAD/FuO/UZ04ZG/uqpK/6mcmqh86Kf+OsDA== X-Received: by 2002:a17:907:d1b:b0:aab:cd45:5d3c with SMTP id a640c23a62f3a-ab38b3c7729mr176992666b.50.1737104460026; Fri, 17 Jan 2025 01:01:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 04/10] rust: vmstate: implement Zeroable for VMStateField Date: Fri, 17 Jan 2025 10:00:40 +0100 Message-ID: <20250117090046.1045010-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104560287019000 Content-Type: text/plain; charset="utf-8" This shortens a bit the constants. Do not bother using it in the vmstate macros since most of them will go away soon. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 18 +++--------------- rust/qemu-api/src/zeroable.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 3c3ed8510ab..22a5ed50d4a 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -21,8 +21,8 @@ =20 use core::{marker::PhantomData, mem, ptr::NonNull}; =20 -use crate::bindings::VMStateFlags; pub use crate::bindings::{VMStateDescription, VMStateField}; +use crate::bindings::VMStateFlags; =20 /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -503,20 +503,8 @@ macro_rules! vmstate_fields { static _FIELDS: &[$crate::bindings::VMStateField] =3D &[ $($field),*, $crate::bindings::VMStateField { - name: ::core::ptr::null(), - err_hint: ::core::ptr::null(), - offset: 0, - size: 0, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: ::core::ptr::null(), - flags: VMStateFlags::VMS_END, - vmsd: ::core::ptr::null(), - version_id: 0, - struct_version_id: 0, - field_exists: None, + flags: $crate::bindings::VMStateFlags::VMS_END, + ..$crate::zeroable::Zeroable::ZERO } ]; _FIELDS.as_ptr() diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 6125aeed8b4..57cac96de06 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -49,6 +49,37 @@ unsafe impl Zeroable for crate::bindings::Property { }; } =20 +// bindgen does not derive Default here +#[allow(clippy::derivable_impls)] +impl Default for crate::bindings::VMStateFlags { + fn default() -> Self { + Self(0) + } +} + +unsafe impl Zeroable for crate::bindings::VMStateFlags { + const ZERO: Self =3D Self(0); +} + +unsafe impl Zeroable for crate::bindings::VMStateField { + const ZERO: Self =3D Self { + name: ptr::null(), + err_hint: ptr::null(), + offset: 0, + size: 0, + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: ptr::null(), + flags: Zeroable::ZERO, + vmsd: ptr::null(), + version_id: 0, + struct_version_id: 0, + field_exists: None, + }; +} + unsafe impl Zeroable for crate::bindings::VMStateDescription { const ZERO: Self =3D Self { name: ptr::null(), --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104625; cv=none; d=zohomail.com; s=zohoarc; b=iozDd7kdjDxaoCY+BsPPITnTrrMgi8Mu6txrBQ4v6+8v3PRBOP71V5h6ebTSbMYQ4YlU2PMZN9i9QiLrC04k8qjhQ7YgmsQ0fWKBUpJ4hZHCGQsvj+czs1kRIxZkBwWsEpzmqwIHnE2pkYgDHxJ26gcW73Lm0g8uc6GGishlndQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104625; 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=xdreYeMEubtp69jK34KWNVurrSUZ81kztZbhs4Qnr14=; b=TI/wkmmZSvG52iF+vzUErY501c9z2Y65hi44i2VH/QrQqOC4KO691Rd8JdHfzT4IXdCyy8aAKFHkNOD7PwaDkZ+j4B6Eb0ClsXcN9lxRVbC8YpcjOeHe7fC+/shkcgmsEOuUw21KFQUK0JkvGRzp6EgSqr3TU2Gk7HRHSVkS5co= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104625566159.3758119251603; Fri, 17 Jan 2025 01:03:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiE7-0001tu-GV; Fri, 17 Jan 2025 04:01:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE2-0001s1-UQ for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE0-00084L-HL for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:10 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-N_B46DiSM2iOIbcn9FCbXA-1; Fri, 17 Jan 2025 04:01:06 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aa689b88293so167627966b.3 for ; Fri, 17 Jan 2025 01:01:06 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384fcbb46sm133128666b.166.2025.01.17.01.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xdreYeMEubtp69jK34KWNVurrSUZ81kztZbhs4Qnr14=; b=Qy/ohh0AMHR5VkGHJAtXMlHJOt8Ngo/f1EnZyoYNNKGXeTy6RoX0BE2V+GX9O5RVUjZZOP DjbeMUvzynvSTL2HWI0Lus9U66ACr2OwDV6oUfP4obkb3ZR5f87fHvputn4FQrK9tPsVZX XZsZv4vHWyTyxnsrGcEYrkSo6EA9jdE= X-MC-Unique: N_B46DiSM2iOIbcn9FCbXA-1 X-Mimecast-MFC-AGG-ID: N_B46DiSM2iOIbcn9FCbXA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104465; x=1737709265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xdreYeMEubtp69jK34KWNVurrSUZ81kztZbhs4Qnr14=; b=Y77JlAoePOeE2iXQ8OE9p866y26K1ILzmC1XX5Oy0QgRIM86cc2getR4ARts/41SQZ oJ3ma7K0aRfiKdf1KmuGNf4fKi3nnB5MVMbFXqonMZl/tET6+gKjx/wU+JcqNrBu90S1 u3p+J9Fdod+Qixtt230/nQvcmtN/t3JawjAsxhs+2S+WvizKxWjGkULqwaoJkgR0SkAm /KGHpqBAy/iUCxuOS5uwURqHYCvU5sPfZLTzwN7atnGm2A47RE6KFhL0WHoVko6/uGdO wcCkFy1+mB3DaYMYVrqKIs360E3YqPFP//2B4Ox4BMux0YxsDVEei66WSxTDD0GQYwuP /QhQ== X-Gm-Message-State: AOJu0YzrWBmEAnSEcijRL64QJc9D3WqyEdN6Y9hwHDsxYAiQ26Lfq/MI 6XwRanLauU++/HBqnFJPWtJ259GQN8rF4rbZwCiNE2A3JW4D6dXEs6ZJRL7i3HI+S6fxgLpuvWA 2rbGED5AVJlA7YfjcFLYfaDhArFRgXnG3/f9Fq4/I3DMzPu+dYD6iyKW8im7acxcHfLy8x9KlAX YrQ8IgyKRzVVO+lFuSic+wb8c7wMo1MQSc3eoJWuk= X-Gm-Gg: ASbGnctcKmzgs+M8d/bAGwyOPOp/wg0Q85p2iaujjUFh/TgzphRCly4CCZAsRptfAC8 CknGGvdIvbl6lI9iFBJLrii2fJZU2NJ5tJbIUjIkppxcYb5gwAUhb0s9441JgGo8UtyKNr+56Oc 2fpHeGQXRsIpe9gDlfSfzVSq4qUOIXrBCnUCeULaCHS+zpmznK6IlVqPX+pVZyYeCDIaNO3QDou qpGluT1DEGfcyCDQtqLzfAvJomomsEA37aEbiV4InP63m0ZoRGGGIcfNEpz X-Received: by 2002:a17:907:da1:b0:aa6:2a17:b54c with SMTP id a640c23a62f3a-ab38b0b90cemr140565866b.6.1737104464193; Fri, 17 Jan 2025 01:01:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZaX3okgIENGKGPd3rboDkpet2tArpnH9QQT90G2DeRuoPWbhXI0s19A0Ujf9WwzIfjHfobw== X-Received: by 2002:a17:907:da1:b0:aa6:2a17:b54c with SMTP id a640c23a62f3a-ab38b0b90cemr140562066b.6.1737104463613; Fri, 17 Jan 2025 01:01:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 05/10] rust: vmstate: implement VMState for scalar types Date: Fri, 17 Jan 2025 10:00:41 +0100 Message-ID: <20250117090046.1045010-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104626966019000 Content-Type: text/plain; charset="utf-8" Scalar types are those that have their own VMStateInfo. This poses a problem in that references to VMStateInfo can only be included in associated consts starting with Rust 1.83.0, when the const_refs_static was stabilized. Removing the requirement is done by placing a limited list of VMStateInfos in an enum, and going from enum to &VMStateInfo only when building the VMStateField. The same thing cannot be done with VMS_STRUCT because the set of VMStateDescriptions extends to structs defined by the devices. Therefore, structs and cells cannot yet use vmstate_of!. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/vmstate.rs | 128 ++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 22a5ed50d4a..b0a2ce105cc 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -21,8 +21,11 @@ =20 use core::{marker::PhantomData, mem, ptr::NonNull}; =20 -pub use crate::bindings::{VMStateDescription, VMStateField}; use crate::bindings::VMStateFlags; +pub use crate::{ + bindings::{self, VMStateDescription, VMStateField}, + zeroable::Zeroable, +}; =20 /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -61,6 +64,70 @@ const fn phantom__(_: &T) -> ::core::marker::PhantomD= ata { ::core::marker: }; } =20 +/// Workaround for lack of `const_refs_static`: references to global varia= bles +/// can be included in a `static`, but not in a `const`; unfortunately, th= is +/// is exactly what would go in the `VMStateField`'s `info` member. +/// +/// This enum contains the contents of the `VMStateField`'s `info` member, +/// but as an `enum` instead of a pointer. +#[allow(non_camel_case_types)] +pub enum VMStateFieldType { + null, + vmstate_info_bool, + vmstate_info_int8, + vmstate_info_int16, + vmstate_info_int32, + vmstate_info_int64, + vmstate_info_uint8, + vmstate_info_uint16, + vmstate_info_uint32, + vmstate_info_uint64, + vmstate_info_timer, +} + +/// Workaround for lack of `const_refs_static`. Converts a `VMStateFieldT= ype` +/// to a `*const VMStateInfo`, for inclusion in a `VMStateField`. +#[macro_export] +macro_rules! info_enum_to_ref { + ($e:expr) =3D> { + unsafe { + match $e { + $crate::vmstate::VMStateFieldType::null =3D> ::core::ptr::= null(), + $crate::vmstate::VMStateFieldType::vmstate_info_bool =3D> { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_b= ool) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int8 =3D> { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_i= nt8) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int16 =3D>= { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_i= nt16) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int32 =3D>= { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_i= nt32) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int64 =3D>= { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_i= nt64) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint8 =3D>= { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_u= int8) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint16 =3D= > { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_u= int16) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint32 =3D= > { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_u= int32) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint64 =3D= > { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_u= int64) + } + $crate::vmstate::VMStateFieldType::vmstate_info_timer =3D>= { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_t= imer) + } + } + } + }; +} + /// A trait for types that can be included in a device's migration stream.= It /// provides the base contents of a `VMStateField` (minus the name and off= set). /// @@ -69,6 +136,12 @@ const fn phantom__(_: &T) -> ::core::marker::Phantom= Data { ::core::marker: /// The contents of this trait go straight into structs that are parsed by= C /// code and used to introspect into other structs. Be careful. pub unsafe trait VMState { + /// The `info` member of a `VMStateField` is a pointer and as such can= not + /// yet be included in the [`BASE`](VMState::BASE) associated constant; + /// this is only allowed by Rust 1.83.0 and newer. For now, include t= he + /// member as an enum which is stored in a separate constant. + const SCALAR_TYPE: VMStateFieldType =3D VMStateFieldType::null; + /// The base contents of a `VMStateField` (minus the name and offset) = for /// the type that is implementing the trait. const BASE: VMStateField; @@ -83,6 +156,12 @@ pub unsafe trait VMState { }; } =20 +/// Internal utility function to retrieve a type's `VMStateFieldType`; +/// used by [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_scalar_type(_: PhantomData) -> VMState= FieldType { + T::SCALAR_TYPE +} + /// Internal utility function to retrieve a type's `VMStateField`; /// used by [`vmstate_of!`](crate::vmstate_of). pub const fn vmstate_base(_: PhantomData) -> VMStateField { @@ -99,6 +178,15 @@ pub const fn vmstate_varray_flag(_: Phantom= Data) -> VMStateField /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// +/// Only a limited set of types is supported out of the box: +/// * scalar types (integer and `bool`) +/// * the C struct `QEMUTimer` +/// * a transparent wrapper for any of the above (`Cell`, `UnsafeCell`, +/// [`BqlCell`](crate::cell::BqlCell), [`BqlRefCell`](crate::cell::BqlRe= fCell) +/// * a raw pointer to any of the above +/// * a `NonNull` pointer to any of the above, possibly wrapped with `Opti= on` +/// * an array of any of the above +/// /// In order to support other types, the trait `VMState` must be implement= ed /// for them. #[macro_export] @@ -109,8 +197,14 @@ macro_rules! vmstate_of { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, offset: $crate::offset_of!($struct_name, $field_name), - // Compute most of the VMStateField from the type of the field. $(.num_offset: $crate::offset_of!($struct_name, $num),)? + // The calls to `call_func_with_field!` are the magic that + // computes most of the VMStateField from the type of the fiel= d. + info: $crate::info_enum_to_ref!($crate::call_func_with_field!( + $crate::vmstate::vmstate_scalar_type, + $struct_name, + $field_name + )), ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name, @@ -187,6 +281,7 @@ pub const fn with_varray_multiply(mut self, num: u32) -= > VMStateField { macro_rules! impl_vmstate_transparent { ($type:ty where $base:tt: VMState $($where:tt)*) =3D> { unsafe impl<$base> VMState for $type where $base: VMState $($where= )* { + const SCALAR_TYPE: VMStateFieldType =3D <$base as VMState>::SC= ALAR_TYPE; const BASE: VMStateField =3D VMStateField { size: mem::size_of::<$type>(), ..<$base as VMState>::BASE @@ -201,6 +296,33 @@ unsafe impl<$base> VMState for $type where $base: VMSt= ate $($where)* { impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); =20 +// Scalar types using predefined VMStateInfos + +macro_rules! impl_vmstate_scalar { + ($info:ident, $type:ty$(, $varray_flag:ident)?) =3D> { + unsafe impl VMState for $type { + const SCALAR_TYPE: VMStateFieldType =3D VMStateFieldType::$inf= o; + const BASE: VMStateField =3D VMStateField { + size: mem::size_of::<$type>(), + flags: VMStateFlags::VMS_SINGLE, + ..Zeroable::ZERO + }; + $(const VARRAY_FLAG: VMStateFlags =3D VMStateFlags::$varray_fl= ag;)? + } + }; +} + +impl_vmstate_scalar!(vmstate_info_bool, bool); +impl_vmstate_scalar!(vmstate_info_int8, i8); +impl_vmstate_scalar!(vmstate_info_int16, i16); +impl_vmstate_scalar!(vmstate_info_int32, i32); +impl_vmstate_scalar!(vmstate_info_int64, i64); +impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY_UINT8); +impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY_UINT16); +impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY_UINT32); +impl_vmstate_scalar!(vmstate_info_uint64, u64); +impl_vmstate_scalar!(vmstate_info_timer, bindings::QEMUTimer); + // Pointer types using the underlying type's VMState plus VMS_POINTER // Note that references are not supported, though references to cells // could be allowed. @@ -208,6 +330,7 @@ unsafe impl<$base> VMState for $type where $base: VMSta= te $($where)* { macro_rules! impl_vmstate_pointer { ($type:ty where $base:tt: VMState $($where:tt)*) =3D> { unsafe impl<$base> VMState for $type where $base: VMState $($where= )* { + const SCALAR_TYPE: VMStateFieldType =3D ::SCALAR= _TYPE; const BASE: VMStateField =3D <$base as VMState>::BASE.with_poi= nter_flag(); } }; @@ -225,6 +348,7 @@ unsafe impl<$base> VMState for $type where $base: VMSta= te $($where)* { // VMS_ARRAY/VMS_ARRAY_OF_POINTER =20 unsafe impl VMState for [T; N] { + const SCALAR_TYPE: VMStateFieldType =3D ::SCALAR_TYPE; const BASE: VMStateField =3D ::BASE.with_array_flag(N); } =20 --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104494; cv=none; d=zohomail.com; s=zohoarc; b=ThfjzF4/kbxngk3AJs6gD3NV4v1WerJgJA7qWV8l6xzCRQ43XXR7BwNpHHHeIowpwiVQ4SMMxKyNJodTo4QU8UAkTwSEPHh7DlCx6j5mNZpElzxtKzD9fiIkXy191v1Ojmrz5dAp/ULdN1V8eOl3sU8GNc+SqCj+wDRSv++9y3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104494; 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=EthFAxtcH1LlnwWWbd3845lmR+MXoAUnpKNrFECKNWo=; b=fKVDzhe9clUuw2sgfN3x42Jh+kECO0jNcpdWPV3iVSOwYEDjoeN8cd+4AGFnrSTJMp1mjqRgHdXxXVC46ckx6Id5wj/5pI0b0os9ctW8PjdbN79Prhc9EnEymijSbCq+XvPzJMWCAgsjBhtVUVpe4baJ3aCLXZrMpZJIbu1HzFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173710449435746.84199237038786; Fri, 17 Jan 2025 01:01:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEF-0001wk-8I; Fri, 17 Jan 2025 04:01:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEA-0001uM-JT for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE8-00084n-BU for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:17 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-nuoTdXq2Nca4KxLCrrsEJA-1; Fri, 17 Jan 2025 04:01:09 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aa67f18cb95so183429266b.1 for ; Fri, 17 Jan 2025 01:01:09 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384c5c486sm138716166b.12.2025.01.17.01.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EthFAxtcH1LlnwWWbd3845lmR+MXoAUnpKNrFECKNWo=; b=gA63xjTlXq2gfnT9Lv2u+JGuupX6+UA3tFi8j/Uk4PGEV4so39C/Y9Oj+r5dT8qMnHq9zD SMYkEunKsS5q09Ot2SYTzl5Cppo/rYhqjVu9zMixTwbsRR6SjOFIfWupIvIXN8hQ0k/he7 WDf/g/ClRvVKwDIhipyl1/6Bp9sB+8M= X-MC-Unique: nuoTdXq2Nca4KxLCrrsEJA-1 X-Mimecast-MFC-AGG-ID: nuoTdXq2Nca4KxLCrrsEJA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104467; x=1737709267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EthFAxtcH1LlnwWWbd3845lmR+MXoAUnpKNrFECKNWo=; b=F6QDnAzEq1+6L3GJImUKtOZsq9x3f6M6gckQxqQP/fcgxfBfdwFDL+WwwI+JPwlU0B g6rFJZLaZsD5LNNAzkwF5ZXKgX+W75x/GyuFpQpxkIksKjX6qqBTLlgLhXc/PaGt5LOS CPFqzY0N5XYjKzzNjZ/7VTBi2tQPN9+zIkkSCZtTSlh8Ofz0A7Aul48YdmCSvGBZEGxw TV/wgFhdko6m83iWA9aGIrCx2mNBPPBuJ4HGVQSFSkrvnwATOPCsdhoaCc48xev/t7sZ BTtmx/beVwF7oDOXBpwgiyc1Z6hDSggBJWPw77B4eBAeOtA1ZG8p43ljsnKG/1CsiAnK tBVA== X-Gm-Message-State: AOJu0YyBt/HVFPT/6eqD1UPxiafy6/V3HBo1py6ydMrU2Urp3wOmYwMo czIOzTawQJ79i9XmLzRThVd4qPNXITx4gcuwnchcYg1E2VcL6oLx8MTHS8mMRR3+uOry41qErRi 77DMda48vvCrl7P8xUi6kkxE6BjSxNWLCwNLzf70CIpMEm1aYM5OXvLqYt8P+a56epbXnAvsSYx mT+6Cldvf5XiBKiMekHZ8c0ui6z8T+2S7oi+gmGWY= X-Gm-Gg: ASbGncvr/DspVENR/T/gVSy3qv+88JxWp0CH229YDR6HNQCXXQHSDkzIWvBprzWKvG0 yh5BvytpkmI27I56zWZ84kweovBmNLPZqxkh19rw1M/tmoVj1jfDzkmiFZK8VuGqGZjdxDVAv6D gOFwqJwcLPS2T3L+ry0BQhaWi/RuYzKVbYKNyeHQe7L0FukwW4SlHLhzFxfDV2W29knvqeSadfz ghyuNsYH3ZHGHq213z6KXtFoR7sblroYCOoCb3vJA9F5A1zsgJYiQpLy8Fc X-Received: by 2002:a17:907:6d09:b0:aa6:8935:ae71 with SMTP id a640c23a62f3a-ab38b0b7f21mr158639866b.12.1737104466879; Fri, 17 Jan 2025 01:01:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHl/IKBTGZxcZgEsrNvJ9xZiD9KHQ8ZGesgLhiG9rSCCkYdsh+PBqgBcViTMwpptnt2vvXy/g== X-Received: by 2002:a17:907:6d09:b0:aa6:8935:ae71 with SMTP id a640c23a62f3a-ab38b0b7f21mr158636166b.12.1737104466250; Fri, 17 Jan 2025 01:01:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 06/10] rust: vmstate: add public utility macros to implement VMState Date: Fri, 17 Jan 2025 10:00:42 +0100 Message-ID: <20250117090046.1045010-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104495930019000 Content-Type: text/plain; charset="utf-8" Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 61 ++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index b0a2ce105cc..8f32c72a0fd 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -4,13 +4,18 @@ =20 //! Helper macros to declare migration state for device models. //! -//! This module includes three families of macros: +//! This module includes four families of macros: //! //! * [`vmstate_unused!`](crate::vmstate_unused) and //! [`vmstate_of!`](crate::vmstate_of), which are used to express the //! migration format for a struct. This is based on the [`VMState`] tra= it, //! which is defined by all migrateable types. //! +//! * [`impl_vmstate_forward`](crate::impl_vmstate_forward) and +//! [`impl_vmstate_bitsized`](crate::impl_vmstate_bitsized), which help = with +//! the definition of the [`VMState`] trait (respectively for transparent +//! structs and for `bilge`-defined types) +//! //! * helper macros to declare a device model state struct, in particular //! [`vmstate_subsections`](crate::vmstate_subsections) and //! [`vmstate_fields`](crate::vmstate_fields). @@ -134,7 +139,9 @@ macro_rules! info_enum_to_ref { /// # Safety /// /// The contents of this trait go straight into structs that are parsed by= C -/// code and used to introspect into other structs. Be careful. +/// code and used to introspect into other structs. Generally, you don't = need +/// to implement it except via macros that do it for you, such as +/// `impl_vmstate_bitsized!`. pub unsafe trait VMState { /// The `info` member of a `VMStateField` is a pointer and as such can= not /// yet be included in the [`BASE`](VMState::BASE) associated constant; @@ -188,7 +195,9 @@ pub const fn vmstate_varray_flag(_: Phantom= Data) -> VMStateField /// * an array of any of the above /// /// In order to support other types, the trait `VMState` must be implement= ed -/// for them. +/// for them. The macros +/// [`impl_vmstate_bitsized!`](crate::impl_vmstate_bitsized) +/// and [`impl_vmstate_forward!`](crate::impl_vmstate_forward) help with t= his. #[macro_export] macro_rules! vmstate_of { ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:exp= r)?])? $(,)?) =3D> { @@ -276,6 +285,32 @@ pub const fn with_varray_multiply(mut self, num: u32) = -> VMStateField { } } =20 +/// This macro can be used (by just passing it a type) to forward the `VMS= tate` +/// trait to the first field of a tuple. This is a workaround for lack of +/// support of nested [`offset_of`](core::mem::offset_of) until Rust 1.82.= 0. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::vmstate::impl_vmstate_forward; +/// pub struct Fifo([u8; 16]); +/// impl_vmstate_forward!(Fifo); +/// ``` +#[macro_export] +macro_rules! impl_vmstate_forward { + // This is similar to impl_vmstate_transparent below, but it + // uses the same trick as vmstate_of! to obtain the type of + // the first field of the tuple + ($tuple:ty) =3D> { + unsafe impl $crate::vmstate::VMState for $tuple { + const SCALAR_TYPE: $crate::vmstate::VMStateFieldType =3D + $crate::call_func_with_field!($crate::vmstate::vmstate_sca= lar_type, $tuple, 0); + const BASE: $crate::bindings::VMStateField =3D + $crate::call_func_with_field!($crate::vmstate::vmstate_bas= e, $tuple, 0); + } + }; +} + // Transparent wrappers: just use the internal type =20 macro_rules! impl_vmstate_transparent { @@ -296,6 +331,26 @@ unsafe impl<$base> VMState for $type where $base: VMSt= ate $($where)* { impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); =20 +#[macro_export] +macro_rules! impl_vmstate_bitsized { + ($type:ty) =3D> { + unsafe impl $crate::vmstate::VMState for $type { + const SCALAR_TYPE: $crate::vmstate::VMStateFieldType =3D + <<<$type as ::bilge::prelude::Bits= ized>::ArbitraryInt + as ::bilge::prelude::Number>::Un= derlyingType + as $crate::vmstate::VMState>::SCA= LAR_TYPE; + const BASE: $crate::bindings::VMStateField =3D + <<<$type as ::bilge::prelude::Bits= ized>::ArbitraryInt + as ::bilge::prelude::Number>::Un= derlyingType + as $crate::vmstate::VMState>::BAS= E; + const VARRAY_FLAG: $crate::bindings::VMStateFlags =3D + <<<$type as ::bilge::prelude::Bits= ized>::ArbitraryInt + as ::bilge::prelude::Number>::Un= derlyingType + as $crate::vmstate::VMState>::VAR= RAY_FLAG; + } + }; +} + // Scalar types using predefined VMStateInfos =20 macro_rules! impl_vmstate_scalar { --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104607; cv=none; d=zohomail.com; s=zohoarc; b=FRFQ3dmB4oQmg6apGZuYmgYSsVJiPRthb3ps//vyj7b+70WM1R1olh4zd0pdUVxa68yWM2mN1vGAUU6YvTYKJJo4gwq/zmxgbEfjw5BFguWy9VLFha6d2z2lAvXYagVevqVYahgx77PbArLxjUIa0/NumLaEbp4FXtXpszckuaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104607; 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=0eYY5eNnWTT8Na4EOEM5TaLYcFyvLxA//Me2yYZ88AI=; b=eJ3KXT29IQmhlJTwbQ685WJCIWJqQ8niu77Q4aoD3tZ7UWlouptmeXiOg4sSD3sd619YJ7EhJgSxA4qHlx7+hyGf+EEY1ES1qAkkmuSN2DfYQWbMzQLUk9lzG60J80zF+jEAChRSjDKUNyDqN5LqxXFJYQVr/9OrnSOoLgfsb5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104607272842.8243842306724; Fri, 17 Jan 2025 01:03:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEE-0001wE-KH; Fri, 17 Jan 2025 04:01:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEA-0001uN-JO for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE8-000856-Bw for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:17 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-496-JgS_0ldWMlmOdZkpj9afgw-1; Fri, 17 Jan 2025 04:01:10 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa680e17f6dso141356366b.1 for ; Fri, 17 Jan 2025 01:01:10 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384f8d86esm135654166b.154.2025.01.17.01.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0eYY5eNnWTT8Na4EOEM5TaLYcFyvLxA//Me2yYZ88AI=; b=HRrvef+cE9sNb2blJEeEZrdIxTTLn/Nhtnkt4dX1U22hSOyVIHmDyNrRCKU0VcKTIgVd8K El+B1iyM1H2/y4nZl9WO26vAgPLStqml+HNTke+PM+oKwnLSNEg5i091a0z7zFd7TrKUr2 Duk+bmnDDMrJ+2vSQXO7UKXslFpRayo= X-MC-Unique: JgS_0ldWMlmOdZkpj9afgw-1 X-Mimecast-MFC-AGG-ID: JgS_0ldWMlmOdZkpj9afgw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104469; x=1737709269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0eYY5eNnWTT8Na4EOEM5TaLYcFyvLxA//Me2yYZ88AI=; b=No1AMMjXaEsbmZXs0A0btGYg6121cLCjLrvasuCF6vIkwU3czl0jSPTRlig2SNrwIF dggyfNRGbuQKFnkRhwl3PqorjLUlnlTP61iqW9jG1aMn4WuQOMs9L6c62ftfswi86OYa iQpammT0NaCNOmouMYUJNV6xxQGoA4ZRBGRxbdlAotJ48CAHRsz/7ZMKbWBIr+J/kBWP Prxz+mVZ2F9WtOiu/Q6+qrDYHAm31yrdOWk+yLIWXbWQDKS/xssFmshnWQBQISAAPGUS fcu+CjlJq6NHPujcpjiMfaNgnRKopYfUurdGYuIZJ980+u0OFfD6cU+9Nd9vTEIbZA1v 9NHg== X-Gm-Message-State: AOJu0Yy8Y5aDvNNlISQEkI1YjqNBXunbNOLU9w5TSX0XTa/7IcrwEiBz /uKk1Ti3PIYYiH7xan3NWrwGVj6T4CMfSnrA7NYUAQB/IR3wvV2QOdoHHvX2Hn1FcPo1PFtr+tW UWzb/idOLaonwBsufZ56zyhxYld3zSEigdKDjNC1ckbl8KWhnbuyAFFUl1ksZtSmodykr3Yu9h7 kOgc+ZIhZPZsbG0+SdLAMsX0clN5Dd9Yl4iFjJ+10= X-Gm-Gg: ASbGnctGQNEG9S4hV7Pkg9QQQBfWa/DMcqpzgmg9eFcMHCNQ8lEdvXkWqBDufXeNmND 1k/T3oehLCVx8GJ1T9eZwtt/Fhdjc76HYxclOCjeDkluMNTpLtVKiQEMSTibfq4gqdPSvqad+Yu 2Wulfv+NAvaZP+y04BboPYhY1MQv0H4Ya/b5ISLOVn3YhSHfgw4nLArePvRX0CMNvM5aUylVCaV s4X7AyipkLnhFWuXWfOnljEcQexQtwxYgdUT5snlclmZh7j47CuXPyXh8+H X-Received: by 2002:a05:6402:518d:b0:5d0:ed92:cdf6 with SMTP id 4fb4d7f45d1cf-5db7d30114amr3798742a12.19.1737104468683; Fri, 17 Jan 2025 01:01:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSTfN0PC8UGWM2PPeDtDBZUuiUqq+gLt/lv4Iz/gcM/WQEzHZWsLe/ftmEPpF/FM3io9g/Qw== X-Received: by 2002:a05:6402:518d:b0:5d0:ed92:cdf6 with SMTP id 4fb4d7f45d1cf-5db7d30114amr3798684a12.19.1737104468117; Fri, 17 Jan 2025 01:01:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 07/10] rust: qemu_api: add vmstate_struct Date: Fri, 17 Jan 2025 10:00:43 +0100 Message-ID: <20250117090046.1045010-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104608682019000 Content-Type: text/plain; charset="utf-8" It is not type safe, but it's the best that can be done without const_refs_static. It can also be used with BqlCell and BqlRefCell. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/vmstate.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 8f32c72a0fd..94a2a29fe7e 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -628,6 +628,39 @@ macro_rules! vmstate_array_of_pointer_to_struct { }}; } =20 +// FIXME: including the `vmsd` field in a `const` is not possible without +// the const_refs_static feature (stabilized in Rust 1.83.0). Without it, +// it is not possible to use VMS_STRUCT in a transparent manner using +// `vmstate_of!`. While VMSTATE_CLOCK can at least try to be type-safe, +// VMSTATE_STRUCT includes $type only for documentation purposes; it +// is checked against $field_name and $struct_name, but not against $vmsd +// which is what really would matter. +#[doc(alias =3D "VMSTATE_STRUCT")] +#[macro_export] +macro_rules! vmstate_struct { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:exp= r)?])?, $vmsd:expr, $type:ty $(,)?) =3D> { + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + $(.num_offset: $crate::offset_of!($struct_name, $num),)? + offset: { + $crate::assert_field_type!($struct_name, $field_name, $typ= e); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of::<$type>(), + flags: $crate::bindings::VMStateFlags::VMS_STRUCT, + vmsd: unsafe { $vmsd }, + ..$crate::zeroable::Zeroable::ZERO $( + .with_varray_flag($crate::call_func_with_field!( + $crate::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply($factor))?)? + } + }; +} + #[doc(alias =3D "VMSTATE_CLOCK_V")] #[macro_export] macro_rules! vmstate_clock_v { --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104533; cv=none; d=zohomail.com; s=zohoarc; b=jc322H9R4gjXhSKCDklxoMBMVD415upVG/Ha2Pz74mTWl8tYTulZ3PT4wpld7UQAUjYH1+7yuIhaDiUMStHz92EZdz8V7BUVp9LUizZ1QqaGIRPZbBpVsCihYAH5exOSj4fU2b37ty3Ox6Z7UjBu1+pR6oTThydYZpbY+BFhGps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104533; 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=mVJNc6AglKjjRuDFE0OkssFaL2nSeryQ2XLRS9fMKB0=; b=KxijdhP0eM7hChE+6MuL3aRK5ZgGx6ZUJCwUty83zNy8P47il+jlDZIB2nLx9lDdU/1W5gYLjsPhdYvKF0k8TZ2bFH+DLm43csnONqzrdvITAUrsPAFhrkYdmZGIoeqOg5jR8sMOVS8RHsjTmjvLaSvjsjMOR+XSDqD5MKu/en0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104533237227.34223778089233; Fri, 17 Jan 2025 01:02:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEF-0001yi-Vr; Fri, 17 Jan 2025 04:01:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiED-0001vQ-0e for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEA-00085Z-CD for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:20 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-oaa2pydNM2iW1K5KlmFTvQ-1; Fri, 17 Jan 2025 04:01:13 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-aafba50f3a6so153966466b.2 for ; Fri, 17 Jan 2025 01:01:13 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384ce106csm134567866b.45.2025.01.17.01.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mVJNc6AglKjjRuDFE0OkssFaL2nSeryQ2XLRS9fMKB0=; b=MwUKrkFilCR9H3WsT/X66yQh+oNGyPLeABusN4rYNhxOn/9umSyZfpNHTf3NenO/Fckzpq yi83FDXPK4FtHMoYDtIeUMOEERmAaOF6lCrpXp3in5F4BszCMihRgBsAUqTlb6zTgCn0Q+ 6KJxkrH3dT7/GcbQslpPVkhdO4TaoHU= X-MC-Unique: oaa2pydNM2iW1K5KlmFTvQ-1 X-Mimecast-MFC-AGG-ID: oaa2pydNM2iW1K5KlmFTvQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104471; x=1737709271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mVJNc6AglKjjRuDFE0OkssFaL2nSeryQ2XLRS9fMKB0=; b=OmOUMZHSixs0T+B9RDGainj2AhM/bsFMcFUIYn57DDs7msO2LoNqQuteZmZsNnwvhf HVti8acauqc3+g6pCKxJcYfS+ESGstTix4jIfw26Af3lU1h1NdN+X2tt924nUhqboMe2 DtRurv+6vEVan2MgMantCBiF+TNJ/lriOKkrpDodI8DydfczpL0KcHjyf3ts6v4/BzwZ oQqAvZsJkw+Z1juLeAwI3TkG4LYN6cheVCgUcJX9/UvKAJG8Wkwr4BY/B/znfOljjDmI ZxS3IlS6wV0aC0iW1wBoy8+8+JANiWlu9Vl7Vxm99lS81tC+IGZKwetaHzsNG0QU/ZNs ZjBw== X-Gm-Message-State: AOJu0YzQ0omlqhWtnpczfQt2Elm0T33Xycam4fHap/py3oQvPK6ABP17 RFl7aaSUrzp5iTVnDFfk35q2IrZwXulfoeqq3ntjRlPlF35zfkpLWEaekgxOd/wHtgYLol6OORs qhpuB+5qnaEN1MWCTMDqwSvs/AH/25PgGh45koNxRxU9vqemF+orHGicrwEqJu+UGFFJ0+4x+/W o0700Ugvhpmwf0b8cgX9iyqLBINP8M/Jm7gjA8c4U= X-Gm-Gg: ASbGncuQLU9d1/HWkCAPltMyB4ANRXPEMSRIu2AlTLlAxelatGNGJIkzA3GjmeIV/Zw hgPx7cOHsjZl/TbqTWM7hwC/KeHMyTPAL7PoYdcNQeodYkptXcbxAqyX5OzIquHajUk/lVBuoUf SeRFQgo/LSd0wtM2qML+BBzc1g+r9GW5jm733UoeHNziTdPbJwb/R/rFT0+egEIpnCDeAMxfFIv c9+E6i/HO8vyfhLgOQhHwxmEkHR1Qxj0I9M3Q5ALAzs9+rm0Rm9niLAoh3P X-Received: by 2002:a17:907:7d94:b0:aaf:a2d9:234 with SMTP id a640c23a62f3a-ab38b3854f1mr165247866b.39.1737104471048; Fri, 17 Jan 2025 01:01:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IH83FiXv9YRjp81EkpVQaRkyUnAcloLnSxcemqiGi8X9ztQ+Lrl/JnJQo+c+1/Js/qDIu7dzQ== X-Received: by 2002:a17:907:7d94:b0:aaf:a2d9:234 with SMTP id a640c23a62f3a-ab38b3854f1mr165243566b.39.1737104470401; Fri, 17 Jan 2025 01:01:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 08/10] rust: pl011: switch vmstate to new-style macros Date: Fri, 17 Jan 2025 10:00:44 +0100 Message-ID: <20250117090046.1045010-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104534163019000 Content-Type: text/plain; charset="utf-8" Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 3 ++- rust/hw/char/pl011/src/device_class.rs | 36 +++++++++++++------------- rust/hw/char/pl011/src/lib.rs | 6 +++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 994c2fc0593..11a87664c7a 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -10,7 +10,7 @@ =20 use qemu_api::{ bindings::{self, *}, - c_str, + c_str, impl_vmstate_forward, irq::InterruptSource, prelude::*, qdev::DeviceImpl, @@ -54,6 +54,7 @@ impl DeviceId { #[repr(transparent)] #[derive(Debug, Default)] pub struct Fifo([registers::Data; PL011_FIFO_DEPTH as usize]); +impl_vmstate_forward!(Fifo); =20 impl Fifo { const fn len(&self) -> u32 { diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index 7f3ca895071..e0d3532e956 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -6,11 +6,11 @@ use std::os::raw::{c_int, c_void}; =20 use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_subsections= , vmstate_uint32, - vmstate_uint32_array, vmstate_unused, zeroable::Zeroable, + bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate= _subsections, + vmstate_unused, zeroable::Zeroable, }; =20 -use crate::device::{PL011State, PL011_FIFO_DEPTH}; +use crate::device::PL011State; =20 extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { unsafe { @@ -52,21 +52,21 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, vers= ion_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! { vmstate_unused!(core::mem::size_of::()), - vmstate_uint32!(flags, PL011State), - vmstate_uint32!(line_control, PL011State), - vmstate_uint32!(receive_status_error_clear, PL011State), - vmstate_uint32!(control, PL011State), - vmstate_uint32!(dmacr, PL011State), - vmstate_uint32!(int_enabled, PL011State), - vmstate_uint32!(int_level, PL011State), - vmstate_uint32_array!(read_fifo, PL011State, PL011_FIFO_DEPTH), - vmstate_uint32!(ilpr, PL011State), - vmstate_uint32!(ibrd, PL011State), - vmstate_uint32!(fbrd, PL011State), - vmstate_uint32!(ifl, PL011State), - vmstate_uint32!(read_pos, PL011State), - vmstate_uint32!(read_count, PL011State), - vmstate_uint32!(read_trigger, PL011State), + vmstate_of!(PL011State, flags), + vmstate_of!(PL011State, line_control), + vmstate_of!(PL011State, receive_status_error_clear), + vmstate_of!(PL011State, control), + vmstate_of!(PL011State, dmacr), + vmstate_of!(PL011State, int_enabled), + vmstate_of!(PL011State, int_level), + vmstate_of!(PL011State, read_fifo), + vmstate_of!(PL011State, ilpr), + vmstate_of!(PL011State, ibrd), + vmstate_of!(PL011State, fbrd), + vmstate_of!(PL011State, ifl), + vmstate_of!(PL011State, read_pos), + vmstate_of!(PL011State, read_count), + vmstate_of!(PL011State, read_trigger), }, subsections: vmstate_subsections! { VMSTATE_PL011_CLOCK diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 0a89d393e0f..f30f9850ad4 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -106,6 +106,7 @@ pub mod registers { //! Device registers exposed as typed structs which are backed by arbi= trary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. use bilge::prelude::*; + use qemu_api::impl_vmstate_bitsized; =20 /// Receive Status Register / Data Register common error bits /// @@ -172,6 +173,7 @@ pub struct Data { pub errors: Errors, _reserved: u16, } + impl_vmstate_bitsized!(Data); =20 impl Data { // bilge is not very const-friendly, unfortunately @@ -208,6 +210,7 @@ pub struct ReceiveStatusErrorClear { pub errors: Errors, _reserved_unpredictable: u24, } + impl_vmstate_bitsized!(ReceiveStatusErrorClear); =20 impl ReceiveStatusErrorClear { pub fn set_from_data(&mut self, data: Data) { @@ -280,6 +283,7 @@ pub struct Flags { pub ring_indicator: bool, _reserved_zero_no_modify: u23, } + impl_vmstate_bitsized!(Flags); =20 impl Flags { pub fn reset(&mut self) { @@ -354,6 +358,7 @@ pub struct LineControl { /// 31:8 - Reserved, do not modify, read as zero. _reserved_zero_no_modify: u24, } + impl_vmstate_bitsized!(LineControl); =20 impl LineControl { pub fn reset(&mut self) { @@ -498,6 +503,7 @@ pub struct Control { /// 31:16 - Reserved, do not modify, read as zero. _reserved_zero_no_modify2: u16, } + impl_vmstate_bitsized!(Control); =20 impl Control { pub fn reset(&mut self) { --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104648; cv=none; d=zohomail.com; s=zohoarc; b=fDSBlTRcjlhFwU+sgKyqsDwfUZi/9cNy+mIVUgKcg03xO66fS8ToNTBvGgFwNnd7CDrxLBVU29Y1E2JpzLNGQolKPtqzs6SvX0Shs8tuZVaqLof652kpxzihCWJtOsydtNphdKLqbh4kU8WLLAMTysad+BgEzfREFBPYSJiREYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104648; 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=dOt3f+8UTPP9tgmhHLRL6fKjbSiAqZOk7IsRwsCirFA=; b=b5io0g5HCoE5z+h6uaYH1Av99eUOUIeIEo6MM7WZm+43P/M6nZ94cZrLI38itQ5bDOOBdLpYzQYyRTCHxDq/G5tl0PD6/qAXZJtFaLlV9WsDEz/OJVKHRAacMzCj2gItUUCGv+GnEvP9qOF5QOeNT2qp1jCh0ioXRz6jclqPZYI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104648775923.1087202727398; Fri, 17 Jan 2025 01:04:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEI-00021d-Pc; Fri, 17 Jan 2025 04:01:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEH-00020R-3A for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiE9-00085T-5P for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:23 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-OJxVoxQ6PkCGqWmGv9bJ8g-1; Fri, 17 Jan 2025 04:01:14 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aafc90962ffso211913566b.0 for ; Fri, 17 Jan 2025 01:01:14 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384f8442esm133647466b.129.2025.01.17.01.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dOt3f+8UTPP9tgmhHLRL6fKjbSiAqZOk7IsRwsCirFA=; b=VNBp+/yMoAGFqh9za6rEHrG4Txai2lUhcupUMtMEthilNoBTccRBBs5yedqhw2PYkFIVIo d0opxUnkurQ62H/58YVVnCWQeyXPE+pN735joVo3tHchbmX46n/fIkYeAugjTmkyt3JhVd n0Rc9gkXF9rj64ZcqlE8sm64A/2Ov8M= X-MC-Unique: OJxVoxQ6PkCGqWmGv9bJ8g-1 X-Mimecast-MFC-AGG-ID: OJxVoxQ6PkCGqWmGv9bJ8g X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104473; x=1737709273; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dOt3f+8UTPP9tgmhHLRL6fKjbSiAqZOk7IsRwsCirFA=; b=pAwbwf8xpim9pidb4wWOu01RfFv3pRxGlNoB4aJKkeNd/6VAoVJM8D3hnf+alwIUMf ZUqsPjt7CiqsxcxFR7+0jzYM6xBJq4OTs6r5PEqwCPLQqxP5yYu46iLDKbkoiq3iPYhA RwzYi3l8acZpfLIMZUAPLej7gz5UKypVqHZVEbSVCkC5KCUCEfFjqDebK1Upe4QsUfCY UT4oegf/bo3ulAZSxcubNv+ThVBkd+0D1zii4DhNQ+M5A+gHqTr7c4kit4VASss/JHpM 5d1w8P8VHpSAjYITVjG+X52BsZfVEebLhavKIqz/TOq+TEpSqCica2ek7ZkRgXEOdTvt M1qA== X-Gm-Message-State: AOJu0YwW5FUyie359DEGdNn1yPLWDbbfbfSpXhlzGLs1My0u53B1eJqQ 1xW8hOECvQokAXqg8AaHxlnoHNfoeoO0rOYiVTKG504cPoOVcB5TkxLow1KM3pKrRRrXVXzx0Li h4knVWuo1x7Va9u5hsNcArXytSwYSDP4fKCYq9fxLSWHU2PdrkEpwmDuiPour2dcXa/hFxn8dZl GQuyGvuPu44XRUVYtSTDdhzLgR9QuLIzXDrFjI3ps= X-Gm-Gg: ASbGncvaa7NxH6b69k5sBmPFdv93x2hqzFlpY2Q1c2ttYYfLVJHTKhSKDAFilEjAYEs RgE3YSHZwIXBS29t7jy7uWH83DNZ6YMdrz2DxvwaI/7mlg+vWJcUgNaIEi1gYLoiyuBKA8wPM9w iMj6LtDylDStWdjiTRHtiTYDH0N+an3sn0/PC0hLkAjA8e1/5W8I+WBhz3HoFvIsyvcWrmTgHDR VCBz7dXthiky7Z5vC/pZDWv7UjFmbokuCY5HDhmwxPmFnfgJBMDrrT4lHd2 X-Received: by 2002:a17:907:97ca:b0:aa6:7881:1e84 with SMTP id a640c23a62f3a-ab38b231d63mr146345166b.15.1737104472745; Fri, 17 Jan 2025 01:01:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IF90MTO1Q4FoHoXxivuEUIRCUnY5Wx26PnCJeB1XPqPFzYUIszV5CcOn3jBnQ9CRzS194WjpA== X-Received: by 2002:a17:907:97ca:b0:aa6:7881:1e84 with SMTP id a640c23a62f3a-ab38b231d63mr146341266b.15.1737104471920; Fri, 17 Jan 2025 01:01:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 09/10] rust: vmstate: remove translation of C vmstate macros Date: Fri, 17 Jan 2025 10:00:45 +0100 Message-ID: <20250117090046.1045010-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104651281019000 Content-Type: text/plain; charset="utf-8" Keep vmstate_clock!; because it uses a field of type VMStateDescription, it cannot be converted to the VMState trait without access to the const_refs_static feature. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 274 +++-------------------------------- 1 file changed, 23 insertions(+), 251 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 94a2a29fe7e..70dd3c4fc48 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -21,8 +21,8 @@ //! [`vmstate_fields`](crate::vmstate_fields). //! //! * direct equivalents to the C macros declared in -//! `include/migration/vmstate.h`. These are not type-safe and should no= t be -//! used if the equivalent functionality is available with `vmstate_of!`. +//! `include/migration/vmstate.h`. These are not type-safe and only prov= ide +//! functionality that is missing from `vmstate_of!`. =20 use core::{marker::PhantomData, mem, ptr::NonNull}; =20 @@ -407,223 +407,16 @@ unsafe impl<$base> VMState for $type where $base: VM= State $($where)* { const BASE: VMStateField =3D ::BASE.with_array_flag(N); } =20 -#[doc(alias =3D "VMSTATE_UNUSED_BUFFER")] -#[macro_export] -macro_rules! vmstate_unused_buffer { - ($field_exists_fn:expr, $version_id:expr, $size:expr) =3D> {{ - $crate::bindings::VMStateField { - name: c_str!("unused").as_ptr(), - err_hint: ::core::ptr::null(), - offset: 0, - size: $size, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate= _info_unused_buffer) }, - flags: VMStateFlags::VMS_BUFFER, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias =3D "VMSTATE_UNUSED_V")] -#[macro_export] -macro_rules! vmstate_unused_v { - ($version_id:expr, $size:expr) =3D> {{ - $crate::vmstate_unused_buffer!(None, $version_id, $size) - }}; -} - #[doc(alias =3D "VMSTATE_UNUSED")] #[macro_export] macro_rules! vmstate_unused { ($size:expr) =3D> {{ - $crate::vmstate_unused_v!(0, $size) - }}; -} - -#[doc(alias =3D "VMSTATE_SINGLE_TEST")] -#[macro_export] -macro_rules! vmstate_single_test { - ($field_name:ident, $struct_name:ty, $field_exists_fn:expr, $version_i= d:expr, $info:expr, $size:expr) =3D> {{ $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), + name: $crate::c_str!("unused").as_ptr(), size: $size, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: unsafe { $info }, - flags: VMStateFlags::VMS_SINGLE, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias =3D "VMSTATE_SINGLE")] -#[macro_export] -macro_rules! vmstate_single { - ($field_name:ident, $struct_name:ty, $version_id:expr, $info:expr, $si= ze:expr) =3D> {{ - $crate::vmstate_single_test!($field_name, $struct_name, None, $ver= sion_id, $info, $size) - }}; -} - -#[doc(alias =3D "VMSTATE_UINT32_V")] -#[macro_export] -macro_rules! vmstate_uint32_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) =3D> {{ - $crate::vmstate_single!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), - ::core::mem::size_of::() - ) - }}; -} - -#[doc(alias =3D "VMSTATE_UINT32")] -#[macro_export] -macro_rules! vmstate_uint32 { - ($field_name:ident, $struct_name:ty) =3D> {{ - $crate::vmstate_uint32_v!($field_name, $struct_name, 0) - }}; -} - -#[doc(alias =3D "VMSTATE_ARRAY")] -#[macro_export] -macro_rules! vmstate_array { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr, $= info:expr, $size:expr) =3D> {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), - size: $size, - start: 0, - num: $length as _, - num_offset: 0, - size_offset: 0, - info: unsafe { $info }, - flags: VMStateFlags::VMS_ARRAY, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias =3D "VMSTATE_UINT32_ARRAY_V")] -#[macro_export] -macro_rules! vmstate_uint32_array_v { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr) = =3D> {{ - $crate::vmstate_array!( - $field_name, - $struct_name, - $length, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), - ::core::mem::size_of::() - ) - }}; -} - -#[doc(alias =3D "VMSTATE_UINT32_ARRAY")] -#[macro_export] -macro_rules! vmstate_uint32_array { - ($field_name:ident, $struct_name:ty, $length:expr) =3D> {{ - $crate::vmstate_uint32_array_v!($field_name, $struct_name, $length= , 0) - }}; -} - -#[doc(alias =3D "VMSTATE_STRUCT_POINTER_V")] -#[macro_export] -macro_rules! vmstate_struct_pointer_v { - ($field_name:ident, $struct_name:ty, $version_id:expr, $vmsd:expr, $ty= pe:ty) =3D> {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), - size: ::core::mem::size_of::<*const $type>(), - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: ::core::ptr::null(), - flags: VMStateFlags(VMStateFlags::VMS_STRUCT.0 | VMStateFlags:= :VMS_POINTER.0), - vmsd: unsafe { $vmsd }, - version_id: $version_id, - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias =3D "VMSTATE_ARRAY_OF_POINTER")] -#[macro_export] -macro_rules! vmstate_array_of_pointer { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $inf= o:expr, $type:ty) =3D> {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - version_id: $version_id, - num: $num as _, - info: unsafe { $info }, - size: ::core::mem::size_of::<*const $type>(), - flags: VMStateFlags(VMStateFlags::VMS_ARRAY.0 | VMStateFlags::= VMS_ARRAY_OF_POINTER.0), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null(), - start: 0, - num_offset: 0, - size_offset: 0, - vmsd: ::core::ptr::null(), - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias =3D "VMSTATE_ARRAY_OF_POINTER_TO_STRUCT")] -#[macro_export] -macro_rules! vmstate_array_of_pointer_to_struct { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $vms= d:expr, $type:ty) =3D> {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - version_id: $version_id, - num: $num as _, - vmsd: unsafe { $vmsd }, - size: ::core::mem::size_of::<*const $type>(), - flags: VMStateFlags( - VMStateFlags::VMS_ARRAY.0 - | VMStateFlags::VMS_STRUCT.0 - | VMStateFlags::VMS_ARRAY_OF_POINTER.0, - ), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null(), - start: 0, - num_offset: 0, - size_offset: 0, - vmsd: ::core::ptr::null(), - struct_version_id: 0, - field_exists: None, + info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate= _info_unused_buffer) }, + flags: $crate::bindings::VMStateFlags::VMS_BUFFER, + ..$crate::zeroable::Zeroable::ZERO } }}; } @@ -661,48 +454,27 @@ macro_rules! vmstate_struct { }; } =20 -#[doc(alias =3D "VMSTATE_CLOCK_V")] -#[macro_export] -macro_rules! vmstate_clock_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) =3D> {{ - $crate::vmstate_struct_pointer_v!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_clock), - $crate::bindings::Clock - ) - }}; -} - #[doc(alias =3D "VMSTATE_CLOCK")] #[macro_export] macro_rules! vmstate_clock { ($field_name:ident, $struct_name:ty) =3D> {{ - $crate::vmstate_clock_v!($field_name, $struct_name, 0) - }}; -} - -#[doc(alias =3D "VMSTATE_ARRAY_CLOCK_V")] -#[macro_export] -macro_rules! vmstate_array_clock_v { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr) =3D>= {{ - $crate::vmstate_array_of_pointer_to_struct!( - $field_name, - $struct_name, - $num, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_clock), - $crate::bindings::Clock - ) - }}; -} - -#[doc(alias =3D "VMSTATE_ARRAY_CLOCK")] -#[macro_export] -macro_rules! vmstate_array_clock { - ($field_name:ident, $struct_name:ty, $num:expr) =3D> {{ - $crate::vmstate_array_clock_v!($field_name, $struct_name, $name, 0) + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + offset: { + $crate::assert_field_type!( + $struct_name, + $field_name, + core::ptr::NonNull<$crate::bindings::Clock> + ); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of::<*const $crate::bindings::Clock>(), + flags: VMStateFlags(VMStateFlags::VMS_STRUCT.0 | VMStateFlags:= :VMS_POINTER.0), + vmsd: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate= _clock) }, + ..$crate::zeroable::Zeroable::ZERO + } }}; } =20 --=20 2.47.1 From nobody Wed Feb 5 12:41:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737104639; cv=none; d=zohomail.com; s=zohoarc; b=ZpoiWn7jZTWzgFuya9jlzkBQCXuxHCoI0XeMDvf6jW6e+pklS7z90hQiYkVpGDmFfYlisjKXmxj2xhhDl/kU+uRtsdiOOpadY5f1QyxJMzsq8IkbjQHcwLu/qaiKCoxVIBRPUApcRAM31jRiQ5cz/gRprhkgbz5ljH/iuBwyneo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737104639; 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=BPqO3KKHtl5ANg7/aro6hR1uN7oeqpunby/BKuICj8Q=; b=RFwu/JpEzlCSVY25nH4RFabpnjJkhELRKCHj8JjQUChB7xArhVtBILkfeXSsE0339i/VVKcjlz/tdgz3V0fD0cbE9Xsea70+g9PKfThDw17Ewl5vFkRnznAtziFnwYIEgtAS1PAm/GBCob6tJirbn1+C0SfwwmnvnWqtSFMBfV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737104639802544.5806653524146; Fri, 17 Jan 2025 01:03:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYiEH-00020V-KL; Fri, 17 Jan 2025 04:01:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEC-0001vP-UF for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tYiEB-00085p-Db for qemu-devel@nongnu.org; Fri, 17 Jan 2025 04:01:20 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-hNB8QV7_PZONVlQJyXG4Hw-1; Fri, 17 Jan 2025 04:01:16 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aaf901a0ef9so164145566b.0 for ; Fri, 17 Jan 2025 01:01:15 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384f223fesm135133266b.105.2025.01.17.01.01.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737104477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BPqO3KKHtl5ANg7/aro6hR1uN7oeqpunby/BKuICj8Q=; b=SqLIJGQsHuPlT6AfrKKICz0VExj78Ky4I3Fl9imPamuuBA+KDXXZDXSm3vzr1PGj2mg36a 8FdKx1O2NlX5zly8s2qGrO2fjQU7hUiL9tyAkhBkbNQuIv9gpN6XNLmW+CNbgSFzTYQPab 0PY4W148kASR47Fvukp9ANQtj/98ScM= X-MC-Unique: hNB8QV7_PZONVlQJyXG4Hw-1 X-Mimecast-MFC-AGG-ID: hNB8QV7_PZONVlQJyXG4Hw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737104474; x=1737709274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BPqO3KKHtl5ANg7/aro6hR1uN7oeqpunby/BKuICj8Q=; b=H1iEvGDhCPSywU8cycOQcQRBlgCk1DKe583gja0wx2H79bF8ugF3iERFs1WENPeUE6 GiTeBBqB8UIDQt2q/zD6adYy3Ke5/fll14RHZKoRaOTD16x5HvTK2bJeoBlJsOOQcJ78 NWWtwTeARayRe0JJuTZZ6q1nuVf1TXJhFSA4b4r/KcibUfWLuPn9iXO8AjGoT1LCBYxZ FiOdcV5cCff41uIIKYTBYeTeYcBCNKfzZZkOqvBzpBqR2e1jMOx4EH8619Y41cMiakP1 Xlu6cWVgcJqZrU1gPwkFOrDK8pUhHTmi0+wJe0UKm+rp0QIJzs1jqD5Upu2J6ZKNGEW1 Me1w== X-Gm-Message-State: AOJu0Yw7xZntvJYEOQzOO75vW5o2raRE/eGKd5hf8O+hqcvzOIVP6q8V mzjkOWBkLnlwPc78BsZof4WyVx2tKHo8daUyXZztfDeOaXTecwihZrG7xScNwGEPRmgeuUg3ORR VeFJtFnEYAQMjpuAzG5UR3thX9ths9t7IinIRZFIVhgEd7OSJXNeGLKlXe5unVeM3DjJ2LeiXkh MtSkGD9Zz0JCAhYf3P/XXNnlL2H6ARSeW/zIgFmMY= X-Gm-Gg: ASbGncvC6QkV/j6sy+30mwwIuheuMSzlk9I1363rmyIgz6BGFWo5esJZKZCo5myhEaO rgdatS1DmMkSc6pRnwtBUohF6rfBBmCqLHRD8R7k47MX/RWgUZ3ZREo7eHhsqbPHO9nNI7kfg7z x+ZsvBrN9DSPQ0mk/GRAT9O6zMdREeQ5aLbzQSTQYYKulebsBKB3K7gw1b0wNX+0cF20SrrmRRD 1NHGx1t1AZqhawkwHnoRSBnW5aSfrbE0OW0u0LkJQy5sNUcsDAL/0ggpdyL X-Received: by 2002:a17:907:86a3:b0:ab2:db7b:5db3 with SMTP id a640c23a62f3a-ab38b4c8520mr216833766b.54.1737104473914; Fri, 17 Jan 2025 01:01:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqVVadJoAURPuj9qG6UA2d1Ww6Do42aCy9rlg3bBLIvmHMy9EWjTbuoQ4KFXomFtmR5sShBQ== X-Received: by 2002:a17:907:86a3:b0:ab2:db7b:5db3 with SMTP id a640c23a62f3a-ab38b4c8520mr216829166b.54.1737104473456; Fri, 17 Jan 2025 01:01:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, qemu-rust@nongnu.org Subject: [PATCH 10/10] rust: vmstate: make order of parameters consistent in vmstate_clock Date: Fri, 17 Jan 2025 10:00:46 +0100 Message-ID: <20250117090046.1045010-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117090046.1045010-1-pbonzini@redhat.com> References: <20250117090046.1045010-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.093, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737104640914019000 Content-Type: text/plain; charset="utf-8" Place struct_name before field_name, similar to offset_of. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Zhao Liu --- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/qemu-api/src/vmstate.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index e0d3532e956..b052d98803f 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -27,7 +27,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> = bool { minimum_version_id: 1, needed: Some(pl011_clock_needed), fields: vmstate_fields! { - vmstate_clock!(clock, PL011State), + vmstate_clock!(PL011State, clock), }, ..Zeroable::ZERO }; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 70dd3c4fc48..89ca643a58f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -457,7 +457,7 @@ macro_rules! vmstate_struct { #[doc(alias =3D "VMSTATE_CLOCK")] #[macro_export] macro_rules! vmstate_clock { - ($field_name:ident, $struct_name:ty) =3D> {{ + ($struct_name:ty, $field_name:ident) =3D> {{ $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() --=20 2.47.1