From nobody Fri Nov 14 19:45:34 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1761673052; cv=none; d=zohomail.com; s=zohoarc; b=EJOxvxR332kKnKhfOBEH0Ng1Z8Ut65s/pgkCSr18O+WBbkG0XBAZwVsO3nGQhVE4727W78ZcHDO8LoVIaIHrIF1GuqirfcxP/C/JgCP+kIrtPieb1E0iFHYCQnU1YCcpBH28IXpifNYSyguMHM7kxhGS8T6HXoAWDgrWA/39H2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761673052; 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=dJJwl93Eh9oixq1cw/+plHG+ew8tbgNiOl2RmOmLQvg=; b=CD8bIqyqbGzIBrfe0/rNv2PbX4c8cCCuktAC23dJ5BxX5F8JLEVc+6SCt7AZAIrQAvdcP1RxnlNDuhbVli7LXExNVjnb58KKmAa1YJFPciaKSWG+2Erm5wDSD8KdViqIIHZMcJqLhCJiCfbNKebiGP54YiAMF3ZzEjoRacGZ/mo= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761673052905992.723024893657; Tue, 28 Oct 2025 10:37:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDnbM-0006Gw-8w; Tue, 28 Oct 2025 13:35:20 -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 1vDnbI-0006Ei-P6 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 13:35:16 -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 1vDnbE-0004fh-Eg for qemu-devel@nongnu.org; Tue, 28 Oct 2025 13:35:16 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-44-c_x6qspiPuWlaxwXr1cDbQ-1; Tue, 28 Oct 2025 13:35:09 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4770e0910a1so15819895e9.2 for ; Tue, 28 Oct 2025 10:35:09 -0700 (PDT) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47718493c61sm25002885e9.4.2025.10.28.10.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 10:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761672911; 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=dJJwl93Eh9oixq1cw/+plHG+ew8tbgNiOl2RmOmLQvg=; b=PSUWs0mkBIH+E9Ybe3HYftDW0NpzMOGaett4Y/Qp2EQ31FuWmcwoisYU86UlN0UZMDQmkE sOe6gFituD0srnpXDe27YAbqeTQMGNRMNrRfxuGakU7eaCIhIktDEaeUU0JUfpuqOSwNZd Yot/lEVxvZLaHGTPEDFlxPIZ69fAEeI= X-MC-Unique: c_x6qspiPuWlaxwXr1cDbQ-1 X-Mimecast-MFC-AGG-ID: c_x6qspiPuWlaxwXr1cDbQ_1761672908 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761672908; x=1762277708; 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=dJJwl93Eh9oixq1cw/+plHG+ew8tbgNiOl2RmOmLQvg=; b=SsTC/SSAQJGR+ME/H0VLhYu0sU0Gq55fxKfx/oPWVnev5J9uJjBtsksZ0oEiLkM1I1 xk/x1WM4YNHWE5gMXEvkoiN2d56lmRd0w9PjVM0huOYviQ4f9D57yZNXzxYw4pYA8l7H rIEzXgFXFdQ6HofhpDqQKorDrQuwf0Ah57FClZs7lTA/YmAqAYQS2+viAKPkUkB4ATUD YbkqotEwMknQW2QwnCSkH2/Bx0TiF4ak9ab1OWOco3gYB5FKzP2I+bzXX1VuuFqzNFvh RoyHFZgFOrApXG84x51pWboTGUOkhrUdmwVJCVatyVFVLO5N98CtOLwfQICktwMlHw2M UyGg== X-Gm-Message-State: AOJu0YyJfrAJFTAHnjn9CS/cr2Wzy9Q7WtpW02vMFLcyM3a28eAtMvUF eyCQFPzeYc/OYZ0prXzkqlDSHItGMyKK/fweFAB0+1JFl3sRdGyR1GE9Oij17iMI0JDhrRTnpjo RBCAFXVa24XJfuxWsuCIsEcK+2DhCOL3uzfIf6DDbfsh5qdVzF0zV75GYrcTR+uSrMVkiDfsPyU L4P31YIxc42PyMBivMcZMurbA+LY1VhXiPUfuTc1yC X-Gm-Gg: ASbGncuEQGCmIdem2Qz4YOq+1p6h3m7W9BgjdqIJ8ZZqrhrO1rQ7G9biUgmhI9uEQpz fRfv3UwAxfsho1DZOffb6iMeUQGdpjCFKAfOfzKIDLTY/yapqAtfswH5zC0BckgWi7+mD3xrS+M +v1gt76vWfavgv/HM8Yti/JxUzzmIpyjY0gO89u+oYJ5KBOZIbGfZH9AALxRA1pMjV2m2+KncKe oyZxcXhPuUBwqeMzU3hOx6mjCos9s3y0IwHuDIrGrfN8ALqR3bQJQ0IeIhL/PyIi0KqBfSMlZrD vvUEsyo338hSJMpVF1fBNJWPY73SMaerEhbpPGZDP2q3FBWJEjWN0hNYWrtT1U08dd5xlYvB19v PcBAlNz8yHpGAKQUG59Awvch9qCNtQ0Vg/H1eo557TztIdUGgRL+gPC9FVkCx15zCvTpDmViePs zDpmI= X-Received: by 2002:a05:600c:5197:b0:46e:2e93:589f with SMTP id 5b1f17b1804b1-4771e17ef8cmr2420455e9.14.1761672907614; Tue, 28 Oct 2025 10:35:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPkUU+dAv10MxRkRHfnhA0BtnY/MDOcbEVTYwfqdlHI4fPQinVEwWKurG9s7KIAA3VpwNZFQ== X-Received: by 2002:a05:600c:5197:b0:46e:2e93:589f with SMTP id 5b1f17b1804b1-4771e17ef8cmr2420215e9.14.1761672907106; Tue, 28 Oct 2025 10:35:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 12/18] rust/qemu-macros: Convert bit value to u8 within #[property] Date: Tue, 28 Oct 2025 18:34:24 +0100 Message-ID: <20251028173430.2180057-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251028173430.2180057-1-pbonzini@redhat.com> References: <20251028173430.2180057-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: -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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 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: 1761673061024158500 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For bit property, make the type conversion within the #[property] macro so that users do not need to handle the conversion. Suggested-by: Paolo Bonzini Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20251024041344.1389488-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/hw/timer/hpet/src/device.rs | 2 +- rust/qemu-macros/src/lib.rs | 23 ++++++++++++++++++----- rust/qemu-macros/src/tests.rs | 15 ++++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index 86638c07666..23f2eefd1cd 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -539,7 +539,7 @@ pub struct HPETState { // Internal state /// Capabilities that QEMU HPET supports. /// bit 0: MSI (or FSB) support. - #[property(rename =3D "msi", bit =3D HPET_FLAG_MSI_SUPPORT_SHIFT as u8= , default =3D false)] + #[property(rename =3D "msi", bit =3D HPET_FLAG_MSI_SUPPORT_SHIFT, defa= ult =3D false)] flags: u32, =20 /// Offset of main counter relative to qemu clock. diff --git a/rust/qemu-macros/src/lib.rs b/rust/qemu-macros/src/lib.rs index 50239f228be..ee417bb4b4e 100644 --- a/rust/qemu-macros/src/lib.rs +++ b/rust/qemu-macros/src/lib.rs @@ -262,12 +262,25 @@ macro_rules! str_to_c_str { }, )?; let field_ty =3D field.ty.clone(); - let qdev_prop =3D if bitnr.is_none() { - quote! { <#field_ty as ::hwcore::QDevProp>::BASE_INFO } + let (qdev_prop, bitval) =3D if let Some(bitval) =3D bitnr { + ( + quote! { <#field_ty as ::hwcore::QDevProp>::BIT_INFO }, + quote! { + { + const { + assert!(#bitval >=3D 0 && #bitval < #field_ty:= :BITS as _, + "bit number exceeds type bits range"); + } + #bitval as u8 + } + }, + ) } else { - quote! { <#field_ty as ::hwcore::QDevProp>::BIT_INFO } + ( + quote! { <#field_ty as ::hwcore::QDevProp>::BASE_INFO }, + quote! { 0 }, + ) }; - let bitnr =3D bitnr.unwrap_or(syn::Expr::Verbatim(quote! { 0 })); let set_default =3D defval.is_some(); let defval =3D defval.unwrap_or(syn::Expr::Verbatim(quote! { 0 })); properties_expanded.push(quote! { @@ -275,7 +288,7 @@ macro_rules! str_to_c_str { name: ::std::ffi::CStr::as_ptr(#prop_name), info: #qdev_prop, offset: ::core::mem::offset_of!(#name, #field_name) as isi= ze, - bitnr: #bitnr, + bitnr: #bitval, set_default: #set_default, defval: ::hwcore::bindings::Property__bindgen_ty_1 { u: #d= efval as u64 }, ..::common::Zeroable::ZERO diff --git a/rust/qemu-macros/src/tests.rs b/rust/qemu-macros/src/tests.rs index 65691412ff5..b65cf656fa3 100644 --- a/rust/qemu-macros/src/tests.rs +++ b/rust/qemu-macros/src/tests.rs @@ -179,7 +179,10 @@ unsafe impl ::hwcore::DevicePropertiesImpl for DummySt= ate { name: ::std::ffi::CStr::as_ptr(c"flags"), info: ::BIT_INFO, offset: ::core::mem::offset_of!(DummyState, flags)= as isize, - bitnr: 3, + bitnr : { + const { assert!(3 >=3D 0 && 3 < u32::BITS as _= , "bit number exceeds type bits range"); } + 3 as u8 + }, set_default: false, defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: 0 as u64 }, ..::common::Zeroable::ZERO @@ -207,7 +210,10 @@ unsafe impl ::hwcore::DevicePropertiesImpl for DummySt= ate { name: ::std::ffi::CStr::as_ptr(c"flags"), info: ::BIT_INFO, offset: ::core::mem::offset_of!(DummyState, flags)= as isize, - bitnr: 3, + bitnr : { + const { assert!(3 >=3D 0 && 3 < u32::BITS as _= , "bit number exceeds type bits range"); } + 3 as u8 + }, set_default: true, defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: true as u64 }, ..::common::Zeroable::ZERO @@ -235,7 +241,10 @@ unsafe impl ::hwcore::DevicePropertiesImpl for DummySt= ate { name: ::std::ffi::CStr::as_ptr(c"msi"), info: ::BIT_INFO, offset: ::core::mem::offset_of!(DummyState, flags)= as isize, - bitnr: 3, + bitnr : { + const { assert!(3 >=3D 0 && 3 < u64::BITS as _= , "bit number exceeds type bits range"); } + 3 as u8 + }, set_default: true, defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: false as u64 }, ..::common::Zeroable::ZERO --=20 2.51.1