From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1u53wq-0006px-4y for mharc-qemu-rust@gnu.org; Wed, 16 Apr 2025 10:41:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u53wo-0006oI-0B for qemu-rust@nongnu.org; Wed, 16 Apr 2025 10:41:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u53wj-0008IT-QO for qemu-rust@nongnu.org; Wed, 16 Apr 2025 10:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744814460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=nQOu0wwNBagY4rLOK4xIVVmnXKYUeUqtosdqYiuQrSo=; b=V5Flh483r9dd70A5lf0OgnuRwiU3jrQogVxs3fwMmNni27m6tvX6PPkgMjFTfIrqpnGOeg oF139FZdswY4ZltyVf4+KAorY1a21EHMcuWGQlbDNh4wm6mLs1/i8vDX4Gt6oHs/VXy0kY ZNuPLNtDP34iWyQlhqPMGC489nhiskk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-112-fl3-hT56Nd2O_2yfoYtWDg-1; Wed, 16 Apr 2025 10:40:58 -0400 X-MC-Unique: fl3-hT56Nd2O_2yfoYtWDg-1 X-Mimecast-MFC-AGG-ID: fl3-hT56Nd2O_2yfoYtWDg_1744814457 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43d3b211d0eso4673355e9.1 for ; Wed, 16 Apr 2025 07:40:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744814457; x=1745419257; h=in-reply-to:autocrypt:content-language:references:cc:to:subject :from:user-agent:mime-version:date:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nQOu0wwNBagY4rLOK4xIVVmnXKYUeUqtosdqYiuQrSo=; b=SY6pmxelr3iTUaua6OuiQG0l/XigoS1btxiDUXwI9T3zCv2819j7PKMOr8BD9xIZPc beAmF45VzSPTjqzypsLk5fdS2apeznOUW8/hdMm0ONf9rQMccZCdRsPXIJ3JFuoihQeO e/R4qT/eIE0k7E7jvMF+iOX/mhGH0kMLc1JnshL6Y5KrdLFWYe5W4RH9OyrYcpJQ6TW+ fNJTtZwGC2VkFCV7cGeNqakUkpF3xzaf0sIQ7b37XqvHeba/CQr8sDO59zfz3BOaKGD4 TbF1E7XXixDJiYj0uDy1rPzZb2bWPoq0+3QomN3PLFUV3ZlMSdl2aCW8VCad8nSaNlC8 tgFA== X-Forwarded-Encrypted: i=1; AJvYcCUSOxQw1z2B43WwMp9pqbtj19KL84TpphChFsKh323NumIk7e0UqRUZ687kfsOoQ995Ty7Iq1kKUWo=@nongnu.org X-Gm-Message-State: AOJu0YyF4UovAcX8Ws38d87Jav4HaHTonnnkQ2RZ8BXoOfQRZ1r9sTYk N4NV6YGjNnlmDbf/2m4Ya/XEAbqLSQaN/pwEolljyM5ID64BdD7CyamgS3C7Zs8xcrVStUzk6u7 Kbow4Lhbm7cPyVOmJOq7YYwJTYergCPBEfxzJ4zNjLeb+Ic4EPoE= X-Gm-Gg: ASbGncu17GpY963Dw2SZzKBRuPLkwoHmdBC3Tdz6ecL+tVdKDRBWMbXg/lQAp0zFJtT o0Cgp09sAHKX6B2cVeuqS8TKkRjfRVCxgkiszprbbfxHBssxYhKdVHkpwXMN322Tpau5RX34z4i AH8/MdXGkIolaHTQ63WGlz2UWsVcrk3S+BqRPb+mQ2BcIJ4ip1w2CQIK9u4eJgUeCZ9GSbMmLho Fa5Lhh/OkPMT0jZD98x2oFWV/RczP5Epbogkcls3V5f4nyqSyGK5dgkN7uK2ezQNpMo4+4Fsdeu TLxaHoBellTACM1S X-Received: by 2002:a05:6000:40cf:b0:39c:2c0b:8db4 with SMTP id ffacd0b85a97d-39ee5e9b0a5mr1953451f8f.10.1744814456612; Wed, 16 Apr 2025 07:40:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXoCNoFtA2tm+jFyRjJTbd8+NDs8ypWzRccuLIc93gdTg11MlcbXFEnVcSg3Yq3rFqOb80aA== X-Received: by 2002:a05:6000:40cf:b0:39c:2c0b:8db4 with SMTP id ffacd0b85a97d-39ee5e9b0a5mr1953418f8f.10.1744814456158; Wed, 16 Apr 2025 07:40:56 -0700 (PDT) Received: from [192.168.10.48] ([176.206.109.83]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4405b4c8028sm23194255e9.8.2025.04.16.07.40.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Apr 2025 07:40:55 -0700 (PDT) Message-ID: <71e1a026-e94a-4a5b-b3a2-e636fd597e5b@redhat.com> Date: Wed, 16 Apr 2025 16:40:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Paolo Bonzini Subject: Re: [PATCH 8/9] rust/hpet: Support migration To: Zhao Liu Cc: qemu-devel , qemu-rust@nongnu.org, Dapeng Mi References: <20250414144943.1112885-1-zhao1.liu@intel.com> <20250414144943.1112885-9-zhao1.liu@intel.com> <78fdfdaf-7c94-4d79-be39-8215c033b423@redhat.com> Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF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8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: p4mUFY4ZaaQ2uA84IFgcK0nbmQ0o32vi7rVdaiQCOOs_1744814457 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="------------EgD83Rlzq4WeYuMop45sdhmE" Content-Language: en-US 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Apr 2025 14:41:06 -0000 This is a multi-part message in MIME format. --------------EgD83Rlzq4WeYuMop45sdhmE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Il mer 16 apr 2025, 12:00 Zhao Liu ha scritto: > So the problem is that, in a "&'a Foo", T must also be "T: 'a". > One solution is for vmsd() to return an > Option>, and do Box::into_raw(Box::new(vmsd)) > in the class_init method. Once we have const_refs_static, "fn vmsd()" > can become a const and the Box is not needed anymore. Thanks so much, that's a good idea! About `Box::into_raw(Box::new(vmsd))`, do you think it's necessary to use Box::leak(Box::new(*))? (though the Box<> isn't actively dropped during the class's existence) It's the same; leak and into_raw only differ in the return type. You can use leak if you prefer. > I attach the conversion I did of the other devices and tests. I am not > sure if it's possible to avoid having a huge patch to do everything at > once (except HPET since that can be added separately). Thank you again! From my initial thoughts: Splitting is also possible, but it requires first renaming VMStateDescription to VMStateDescriptionWrapper, then replacing it in pl011 and test (and hpet) one by one, and finally renaming it back to VMStateDescription. If you prefer this approach, I can help you split your patch below. Or maybe first you keepvmsd() return Option<&bindings::VMStateDescription> and stick a get_vmsd_ref() in "fn vmsd()", then in a final patch you make it return Option> and introduce the Box::leak(Box::new(...)) trick. > > + vmstate_struct!(HPETState, timers[0 .. num_timers], > &VMSTATE_HPET_TIMER, BqlRefCell, > HPETState::validate_num_timers).with_version_id(0), > > And it seems like you don't oppose the hack in patch 1? ;-) It's not bad, but I haven't looked at why it's needed yet (i.e. why a constant function would be evaluating a destructor). Paolo --------------EgD83Rlzq4WeYuMop45sdhmE Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


Il mer 16 apr 2025, 12:00 Zhao Liu <zhao1.liu@intel.com> ha scritto:
> So the problem is that, in a "&'a Foo<T>", T must also be "T: 'a".
> One solution is for vmsd() to return an
> Option<VMStateDescription<Self>>, and do Box::into_raw(Box::new(vmsd))
> in the class_init method. Once we have const_refs_static, "fn vmsd()"
> can become a const and the Box is not needed anymore.

Thanks so much, that's a good idea!

About `Box::into_raw(Box::new(vmsd))`, do you think it's necessary to use
Box::leak(Box::new(*))? (though the Box<> isn't actively dropped during
the class's existence)

It's the same; leak and into_raw only differ in the return type. You can use leak if you prefer.

> I attach the conversion I did of the other devices and tests. I am not
> sure if it's possible to avoid having a huge patch to do everything at
> once (except HPET since that can be added separately).

Thank you again! From my initial thoughts: Splitting is also possible,
but it requires first renaming VMStateDescription<T> to
VMStateDescriptionWrapper<T>, then replacing it in pl011 and test (and
hpet) one by one, and finally renaming it back to VMStateDescription<T>.
If you prefer this approach, I can help you split your patch below.

Or maybe first you keep vmsd() return Option<&bindings::VMStateDescription> and stick a get_vmsd_ref() in "fn vmsd()", then in a final patch you make it return Option<VMStateDescription<T>> and introduce the Box::leak(Box::new(...)) trick.
> +            vmstate_struct!(HPETState, timers[0 .. num_timers], &VMSTATE_HPET_TIMER, BqlRefCell<HPETTimer>, HPETState::validate_num_timers).with_version_id(0),

And it seems like you don't oppose the hack in patch 1? ;-)
It's not bad, but I haven't looked at why it's needed yet (i.e. why a constant function would be evaluating a destructor).

Paolo
--------------EgD83Rlzq4WeYuMop45sdhmE--