From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66E21C02180 for ; Wed, 15 Jan 2025 13:09:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tY38U-0002rN-Ti; Wed, 15 Jan 2025 08:08:42 -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 1tY38S-0002qo-Ja for qemu-devel@nongnu.org; Wed, 15 Jan 2025 08:08:40 -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 1tY38Q-0001Sl-HZ for qemu-devel@nongnu.org; Wed, 15 Jan 2025 08:08:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736946515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Fc7cKU/1cAWrHZdMhH5kayTeyw/WjXePQGKlqhuh3a0=; b=EI/6WFZVX1dyA1ToAklUg6ZFIPK3HIZU56wEM8w/UPQIyEskHic4Og3kGBwyFaN5GwfmuP 8gK8LuEPAnFVLHZioT7n3I+mmePmB14TSSYRAjLghu8R9DqvSZd6I8m6IM2aQ/1frOzPeV OZ4e7xsgFKG9ZQCfoJeAUtwC4JZtfCQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-MN1Q8T-NOh-Q8gfdQ0arxg-1; Wed, 15 Jan 2025 08:08:33 -0500 X-MC-Unique: MN1Q8T-NOh-Q8gfdQ0arxg-1 X-Mimecast-MFC-AGG-ID: MN1Q8T-NOh-Q8gfdQ0arxg Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385d52591d6so395150f8f.1 for ; Wed, 15 Jan 2025 05:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736946512; x=1737551312; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fc7cKU/1cAWrHZdMhH5kayTeyw/WjXePQGKlqhuh3a0=; b=shU6gOBR5zyOTLfYhI/tEZWllGRV72doUYEDmSJp03zoxLyt0hfa3zb/lBaeJKDcif wx0q4Swbhqs+Qk5yvOxOk0Ec6ySI1Oas96phySX/nDvoavp6s+tO8wv774cf0bt3Q4V9 wZg5UDcLBeLzgFlTh8FYjHVLkxLvKoviR+UbhRdgJJ5KdefTGWedqcjJVTUTZAwrB0je ByyJnG5NtPLD3/0dh9x0NLVbteuhdwtqWCkOPGFcfdEsdKlRNyD/1peNCmhlTD4iWfPj /NuAi45FRP1qXRyRBDNDEAhKoXVUje7UiSeyZOc6GQSX1ngI/ooMG5aC5JnCzz9Zy0yT u/7w== X-Gm-Message-State: AOJu0YxPli5BzKs5pSc3z0h0EtSPqjT/UKtSauHoA5uM76/XL4shAT8r qS/5N7OkG9hxAtuFkG438PO9mzWKOJW3FlRNiMwFQKOfQ/V8Vk44tyaQ8SFcvGkEq2nfK0KIu+j GrVWpJbtj1ZvIX1GzGe3G7T0BCkif/OdBWSsYMxoFTOKANyMRWKXu X-Gm-Gg: ASbGncvZQZ9SUueVbcTcHjM2qids0+ClPGZxf35Ws12Ke+y85WUFwaXF5cqy+MNt6f6 0JoRpYHhpCNDIovKDQaKv38sMEy/qSwOpW2ZpJrhxnx6PShvGvZe9qREy0AT19paZ1zxCP/Dlg9 JoYrjMen4d9LqiMCy/db9CuEHWORZmhmAjhRHMbwEsg9H+rGSXKnMIXIDl4TGIU5DdsPw6rusli Ws158qtM/zkyMAHB/LnpGwbZcTOTF00Jc9Quszzl54xy0q247jsnsUIrQZ7 X-Received: by 2002:a05:6000:2c1:b0:386:374b:e8bc with SMTP id ffacd0b85a97d-38a8b0d3425mr21832181f8f.15.1736946512152; Wed, 15 Jan 2025 05:08:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFFLvv9fGNV3ed44rqeK71muipbLBKSIx5QwHIRdWFwIJNAaNwXcbnABzeVipixh4Jg45QQg== X-Received: by 2002:a05:6000:2c1:b0:386:374b:e8bc with SMTP id ffacd0b85a97d-38a8b0d3425mr21832163f8f.15.1736946511772; Wed, 15 Jan 2025 05:08:31 -0800 (PST) Received: from [192.168.10.3] ([176.206.124.70]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-38a8e4b81ccsm17816154f8f.65.2025.01.15.05.08.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jan 2025 05:08:30 -0800 (PST) Message-ID: Date: Wed, 15 Jan 2025 14:08:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 5/9] rust: vmstate: implement VMState for scalar types To: Zhao Liu Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, junjie.mao@hotmail.com References: <20241231002336.25931-1-pbonzini@redhat.com> <20241231002336.25931-6-pbonzini@redhat.com> From: Paolo Bonzini Content-Language: en-US Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh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tBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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.141, 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.793, 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-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 1/8/25 07:45, Zhao Liu wrote: >> #[macro_export] >> macro_rules! vmstate_of { >> - ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(,)?) => { >> + ($struct_name:ty, $field_name:ident $([0 .. $num:tt $(* $factor:expr)?])? $(,)?) => { > > Why change ident to tt? Rebase mistake. Initially I had $num:tt, however that becomes unclear if you have [0 .. 0] where the second 0 is a field name. >> +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); > > missed VMS_VARRAY_INT32 :-) I left that out intentionally, as Rust is probably going to use IndexMut instead of 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); > > If we want to expand in the future (e.g., support vmstate_info_int32_equal > and vmstate_info_int32_le), then introducing new macro variants will be > straightforward. So, fair enough. > >> +impl_vmstate_scalar!(vmstate_info_uint64, u64); > > What about applying this to "usize" with vmstate_info_uint64? There's 32-bit hosts too... So one would have to add vmstate_info_ulong which is serialized as 64-bit. We can add it later, but perhaps we could also create a derive(Index, IndexMut) macro that makes it possible to specify the type of the index. While Rust uses usize instead of uNN for array indices, that does not have to be universal; using uNN is a lot better if it means you can get rid of casts from register values to array indices and back. See for example commit 6b4f7b0705b ("rust: pl011: fix migration stream", 2024-12-19). That is indeed also an issue for HPET, but in that case it can be isolated to a couple lines, let timer_id: usize = ((addr - 0x100) / 0x20) as usize; and it could even be wrapped further fn timer_and_addr(&self, addr: hwaddr) -> Option<&BqlRefCell, hwaddr> { let timer_id: usize = ((addr - 0x100) / 0x20) as usize; if timer_id > self.num_timers.get() { // TODO: Add trace point - trace_hpet_timer_id_out_of_range(timer_id) None } else { Some((self.get_timer(timer_id), addr & 0x18)) } } ... match self.timer_and_addr(addr) { None => 0 // Reserved, Some(timer, addr) => timer.borrow_mut().read(addr, size) } So for HPET you didn't reach the threshold of having to create "pub struct HPETTimers([BqlRefCell; MAX_HPET_TIMERS])" and implement Index<>. Paolo