From nobody Sat Nov 15 17:44:06 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=1748269539; cv=none; d=zohomail.com; s=zohoarc; b=LnkQe0rJbTcZ6f3Z8GtPuE+fyvhNoIuLMqXM0PGR+Z7lWDLZNivn5I907W01j7qUdkx6K+OODhwDNoNDEUP+jxPZxHlonTiLzYnEMM9/bW/Irde6v9zYAGeIngSpeu03jr6Zo2puFWvDVzIg532OUGokm6apjBQluILSJeWMb4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269539; 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=utt74FEHUZ6lFbnGNCeLg5d8BeYlcHDkUK83oW1XuqU=; b=fHnEsb0CD2MyBAPaQq80b3rhxLiRqqt1E9slclhwJNps5JH72IQZb88pb1Za44aVEqkB59KtFTlVeQrMEQnmy0rG+zYJuSGocA27a8rsDlkYPYvpNQMdVU1F72/ks+Zbx0gMz7qXacF/ExYneyGufY9yhCMWiBcM8+ZfHD6/cVw= 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 1748269539986658.992346568095; Mon, 26 May 2025 07:25:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlJ-0002tU-RS; Mon, 26 May 2025 10:25:11 -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 1uJYlE-0002s5-RR for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:05 -0400 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 1uJYlC-0007di-QI for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:04 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-HKYP0O2jMhWDo5ec2xj0jA-1; Mon, 26 May 2025 10:24:59 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-39ee4b91d1cso1527558f8f.0 for ; Mon, 26 May 2025 07:24:59 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a35ca88957sm35291467f8f.75.2025.05.26.07.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269501; 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=utt74FEHUZ6lFbnGNCeLg5d8BeYlcHDkUK83oW1XuqU=; b=SLIk1DfPUP7i21HE949IRSkireccZlVBvq5OSQUYDfVNLp24ONw+zFkRGt98sKAZPv6Udk 1NoEj8UnxTPezUwWoAVgiVasaPMZGZlsjJlN8ZCKz1hGk0S/Q5q6rXFhN0CcIKhjY1h0yJ 0cdG/FvaWj/B7E9jbgSd5pcaB3WhttY= X-MC-Unique: HKYP0O2jMhWDo5ec2xj0jA-1 X-Mimecast-MFC-AGG-ID: HKYP0O2jMhWDo5ec2xj0jA_1748269499 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269497; x=1748874297; 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=utt74FEHUZ6lFbnGNCeLg5d8BeYlcHDkUK83oW1XuqU=; b=SvM3DH3NwNoaagG6dJmoyIiorfRD5vxhiJoYsH4nUi5mr1sWN8K1bYti4iwUaMIS0W xPaO+rhIHH6Wg26wdudBE17IirtciYckhhDik54RuSczQE6Lite6dk9aRoHTss/RTt+z u9H9oYJivTBolzPD4NhNY2CpTu/fTpeytx6RdgHiLNGwLhSE4D74Xk1eSlzH4Q4R0etC m2JNYL/Fn/JZjCfJ5TkrZDIql5f3BL0lVFU+kJAPbSeLCx1Pij+sIPVQ8WaGT5uKZzse 2qXdOiAb2SwgGFAB7o3ea7tz/8o4Uic3HVyb1HkiVDbfsvYz0qKfu5PpTRHsbD226DBp 5O8w== X-Gm-Message-State: AOJu0YwDpqxtW9XZcnHcqo9okZzKvs7VmjB29jk7vKyBijzLPto36ZGa e1gHmU+1sxOALNNA5YRgFcnahy4UMsASk/UCLNn+yt+8WGC+jYekkln15UJ8DTUxe/74rSL/4rX 6t34+x/V0siuAGsOvViAznU8WHT4VhK5iXKtdG2nrWr1uBHMVbWmZHOuVKZ8D5MiCqP2f+T+fD8 +oMBEYWKWABaDtjloqsXPHLm7P+rpDnF9b9gcREtWj X-Gm-Gg: ASbGncsdYbNaZxUuePI3zsVy/3P9kyieEl2nyMJv/W6KHLSnynEmNtUNzbEpzMngn8q 8cyr/8nBVMSEyh8kmeyB8z/+ujckenKv6Sgh853rVJ/fPFNR+0Y4mEIt5/L3eu3cMqoeltwrTjt NowXbMtY0oCDVlJPCoxSwe+VABnPZZB0KLu/5x8d22qvpLj6+VblCsz00k+ZuVOHTDvUBwvRjNV Da8ZtWeby41mkOsmIJjGRohQ6+OzIByY1iZWuCrIvXq8SLjoWGHNZ/IowOOD3A26gNPL2E7M/v3 mxRRqUAeYWdm4g== X-Received: by 2002:a5d:64c6:0:b0:3a1:f724:eb15 with SMTP id ffacd0b85a97d-3a4ca123bf1mr8629112f8f.2.1748269497091; Mon, 26 May 2025 07:24:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpyKmq/vMA252LfD05Ppt1m+ZziqiFpHTleVgk+do5+ZJxWzz0YA1GzozXYYRsfq57BlsAug== X-Received: by 2002:a5d:64c6:0:b0:3a1:f724:eb15 with SMTP id ffacd0b85a97d-3a4ca123bf1mr8629088f8f.2.1748269496702; Mon, 26 May 2025 07:24:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 01/12] rust: make declaration of dependent crates more consistent Date: Mon, 26 May 2025 16:24:44 +0200 Message-ID: <20250526142455.1061519-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269542435116600 Content-Type: text/plain; charset="utf-8" Crates like "bilge" and "libc" can be shared by more than one directory, so declare them directly in rust/meson.build. While at it, make their variable names end with "_rs" and always add a subproject() statement (as that pinpoints the error better if the subproject is missing and cannot be downloaded). Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/meson.build | 12 +++--------- rust/meson.build | 16 ++++++++++++++++ rust/qemu-api-macros/meson.build | 14 +++----------- rust/qemu-api/meson.build | 4 +--- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/rust/hw/char/pl011/meson.build b/rust/hw/char/pl011/meson.build index 547cca5a96f..494b6c123cc 100644 --- a/rust/hw/char/pl011/meson.build +++ b/rust/hw/char/pl011/meson.build @@ -1,17 +1,11 @@ -subproject('bilge-0.2-rs', required: true) -subproject('bilge-impl-0.2-rs', required: true) - -bilge_dep =3D dependency('bilge-0.2-rs') -bilge_impl_dep =3D dependency('bilge-impl-0.2-rs') - _libpl011_rs =3D static_library( 'pl011', files('src/lib.rs'), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', dependencies: [ - bilge_dep, - bilge_impl_dep, + bilge_rs, + bilge_impl_rs, qemu_api, qemu_api_macros, ], @@ -21,6 +15,6 @@ rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true:= [declare_dependency( link_whole: [_libpl011_rs], # Putting proc macro crates in `dependencies` is necessary for Meson to = find # them when compiling the root per-target static rust lib. - dependencies: [bilge_impl_dep, qemu_api_macros], + dependencies: [bilge_impl_rs, qemu_api_macros], variables: {'crate': 'pl011'}, )]) diff --git a/rust/meson.build b/rust/meson.build index 91e52b8fb8e..1f0dcce7d04 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,3 +1,19 @@ +subproject('bilge-0.2-rs', required: true) +subproject('bilge-impl-0.2-rs', required: true) +subproject('libc-0.2-rs', required: true) + +bilge_rs =3D dependency('bilge-0.2-rs') +bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') +libc_rs =3D dependency('libc-0.2-rs') + +subproject('proc-macro2-1-rs', required: true) +subproject('quote-1-rs', required: true) +subproject('syn-2-rs', required: true) + +quote_rs_native =3D dependency('quote-1-rs', native: true) +syn_rs_native =3D dependency('syn-2-rs', native: true) +proc_macro2_rs_native =3D dependency('proc-macro2-1-rs', native: true) + subdir('qemu-api-macros') subdir('qemu-api') =20 diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.= build index 6f94a4bb3c2..8610ce1c844 100644 --- a/rust/qemu-api-macros/meson.build +++ b/rust/qemu-api-macros/meson.build @@ -1,11 +1,3 @@ -subproject('proc-macro2-1-rs', required: true) -subproject('quote-1-rs', required: true) -subproject('syn-2-rs', required: true) - -quote_dep =3D dependency('quote-1-rs', native: true) -syn_dep =3D dependency('syn-2-rs', native: true) -proc_macro2_dep =3D dependency('proc-macro2-1-rs', native: true) - _qemu_api_macros_rs =3D rust.proc_macro( 'qemu_api_macros', files('src/lib.rs'), @@ -16,9 +8,9 @@ _qemu_api_macros_rs =3D rust.proc_macro( '--cfg', 'feature=3D"proc-macro"', ], dependencies: [ - proc_macro2_dep, - quote_dep, - syn_dep, + proc_macro2_rs_native, + quote_rs_native, + syn_rs_native, ], ) =20 diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1696df705bf..1ea86b8bbf1 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -2,8 +2,6 @@ _qemu_api_cfg =3D run_command(rustc_args, '--config-headers', config_host_h, '--features', files('Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() =20 -libc_dep =3D dependency('libc-0.2-rs') - # _qemu_api_cfg +=3D ['--cfg', 'feature=3D"allocator"'] if get_option('debug_mutex') _qemu_api_cfg +=3D ['--cfg', 'feature=3D"debug_cell"'] @@ -37,7 +35,7 @@ _qemu_api_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, - dependencies: [libc_dep, qemu_api_macros], + dependencies: [libc_rs, qemu_api_macros], ) =20 rust.test('rust-qemu-api-tests', _qemu_api_rs, --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269626; cv=none; d=zohomail.com; s=zohoarc; b=NK9mlIRNdn5IzrdFwlnLrd/KoU1vMNrj4TZpLjRmQtHKSKwHbLvafUP8yI/h+0SiiHN3cGEwjmn4CXp5wOaJ3zsSTsFVyfJ/6fr71fXbI5ReRQG1Zw3/6j7YanUj7txRbob3uVOieVj+Q/ZZ83uHzA7VFVwcd+jDclGH0N2dFFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269626; 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=+T9glpjEX47g3WOojjbNPDPqDCh3tnGFrttxNbiujHQ=; b=EHhBBkZayUlCqG9a4YJRTIG4uiIxYZjlvafKpYSc3jTcb4VtiaWoSNzVoLaLnCSSWt0IrhcUOxRrCBM1Hoo0WoYOov+wbVbQJfQCLqHw/aXyS1ID99vi3VRgiVmtZsPS12OHev0Ba7bmfgudcnhuGW2kssf/O2ncrd2SVo0O7tI= 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 1748269626885487.26135939368726; Mon, 26 May 2025 07:27:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlo-00036N-Js; Mon, 26 May 2025 10:25:40 -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 1uJYlH-0002st-UA for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:08 -0400 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 1uJYlF-0007eM-IR for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:07 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-ByKI_eBbNYKKQhXSmiPhqA-1; Mon, 26 May 2025 10:25:03 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a4dcfc375aso483287f8f.2 for ; Mon, 26 May 2025 07:25:03 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4cd0cf5c0sm7696043f8f.12.2025.05.26.07.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269504; 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=+T9glpjEX47g3WOojjbNPDPqDCh3tnGFrttxNbiujHQ=; b=IxDt0hHF1OXy5di6p/uflGEdKXynRJqorSY+GKHqS6B4UrNRZr2s9yesx3QQpRfXuBKnJ/ VQfZzl/+DP24wHMfV50mhO43RCRa9M+VmH1mebZDOSXATNiFrlMKXEMSpklSffWLSx3nSV yKx/HK0QOMMMRL0jvvkVAR2KjNjXXE0= X-MC-Unique: ByKI_eBbNYKKQhXSmiPhqA-1 X-Mimecast-MFC-AGG-ID: ByKI_eBbNYKKQhXSmiPhqA_1748269502 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269501; x=1748874301; 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=+T9glpjEX47g3WOojjbNPDPqDCh3tnGFrttxNbiujHQ=; b=eeiVHkSsXsyhyfWR4N6i1is85HNnfx3Q1FInSFClCNgJg9JUng2L5Onq6BHI8FX1hz PRq+s2VuIj2xx4p0nzUigJfz0hnal2147NxuoUCiym49O1J28qygONUh/Tj+bgE7IsgQ LHwkyEyRmSQ6cChDNLKop7tdI4LWcH4y19fK43hrnOtD3yTRRM7TAHWFyxDf1nyPzBHH k16eJ4zpcCLXI2IGKdJ+IAzSP3mNAlpRPdjoYI3Mks/2SlDvKlBCzlcQ2y8leFmw///K Zah56Coh/7052gm0vwt45DzLnvl3ZH7MLti+eyZ2KGlHCZzS1VLGCLr5vtaq+52eQR4k xHBg== X-Gm-Message-State: AOJu0YwHnfGVm/F4h4e1b3L6nRrJHEmo0WXTfuUgl74yKSEizx1ieDKb VtmDqtO/T5tr3vRtLRk3jZ/5sDAZIIGwoF/CKcx4ms6zkFTvoOgC0HxtfhK9Wj56Q2PLhe6xC15 bOhH8h3zDfmFtyay4unJDACVYRN4DQPl8dgIgdaXOF2JDOzSLoFYQcWZNvA/jKV2FMALf648JJC IymmROusj4HVD6HpcCp+1GrSZtOmpR9I6AFwvXHTVx X-Gm-Gg: ASbGncvqP9ubQcC+7x5Rg+lntb7MRTshYs9jJJROTwxIv0OXMWttxkmSM6HYHk4LZdo ZNk4EQjQSqLdxCgp2doqEOZfQnYtmbCnt/fd8NeaPeyv3KydtEWA11G1Cv8OU7zQGTUuMHzy/C9 QBbLfxfdy5cGvS70+Nme8ctxtquevc7YykzWee0CI+b7Hvis/bzQ/wVTTMGt6XXVRlgoRqwe9eF f/rGv+OU4eJDvey/8if18sSPdR0YjMJDE2IuNPQWe6rpKEFNgkxNYDLSYA/tQcAmoy0lFJbZtqt wd5FaaP9SHjLwA== X-Received: by 2002:a05:6000:1acf:b0:3a4:d673:af99 with SMTP id ffacd0b85a97d-3a4d673b308mr4283106f8f.34.1748269500940; Mon, 26 May 2025 07:25:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdsCsEnCabdybaCJBP9FTQqrtBIVUrIopHGY08La5svZwRuDtC7+BJvTHxPAMgeGSq9neeWg== X-Received: by 2002:a05:6000:1acf:b0:3a4:d673:af99 with SMTP id ffacd0b85a97d-3a4d673b308mr4283078f8f.34.1748269500452; Mon, 26 May 2025 07:25:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 02/12] subprojects: add the anyhow crate Date: Mon, 26 May 2025 16:24:45 +0200 Message-ID: <20250526142455.1061519-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748269627527116600 Content-Type: text/plain; charset="utf-8" This is a standard replacement for Box which is more efficient (= it only occcupies one word) and provides a backtrace of the error. This could be p= lumbed into &error_abort in the future. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/meson.build | 2 ++ subprojects/.gitignore | 1 + subprojects/anyhow-1.0-rs.wrap | 7 ++++ .../packagefiles/anyhow-1.0-rs/meson.build | 33 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 subprojects/anyhow-1.0-rs.wrap create mode 100644 subprojects/packagefiles/anyhow-1.0-rs/meson.build diff --git a/rust/meson.build b/rust/meson.build index 1f0dcce7d04..3e0b6ed4afa 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,7 +1,9 @@ +subproject('anyhow-1.0-rs', required: true) subproject('bilge-0.2-rs', required: true) subproject('bilge-impl-0.2-rs', required: true) subproject('libc-0.2-rs', required: true) =20 +anyhow_rs =3D dependency('anyhow-1.0-rs') bilge_rs =3D dependency('bilge-0.2-rs') bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') libc_rs =3D dependency('libc-0.2-rs') diff --git a/subprojects/.gitignore b/subprojects/.gitignore index d12d34618cc..b9ae507b85a 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -6,6 +6,7 @@ /keycodemapdb /libvfio-user /slirp +/anyhow-1.0.98 /arbitrary-int-1.2.7 /bilge-0.2.0 /bilge-impl-0.2.0 diff --git a/subprojects/anyhow-1.0-rs.wrap b/subprojects/anyhow-1.0-rs.wrap new file mode 100644 index 00000000000..53f20b2a315 --- /dev/null +++ b/subprojects/anyhow-1.0-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory =3D anyhow-1.0.98 +source_url =3D https://crates.io/api/v1/crates/anyhow/1.0.98/download +source_filename =3D anyhow-1.0.98.tar.gz +source_hash =3D e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969b= dcd487 +#method =3D cargo +patch_directory =3D anyhow-1.0-rs diff --git a/subprojects/packagefiles/anyhow-1.0-rs/meson.build b/subprojec= ts/packagefiles/anyhow-1.0-rs/meson.build new file mode 100644 index 00000000000..67278c25af9 --- /dev/null +++ b/subprojects/packagefiles/anyhow-1.0-rs/meson.build @@ -0,0 +1,33 @@ +project('anyhow-1.0-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '1.0.98', + license: 'MIT OR Apache-2.0', + default_options: []) + +rustc =3D meson.get_compiler('rust') + +rust_args =3D ['--cap-lints', 'allow'] +rust_args +=3D ['--cfg', 'feature=3D"std"'] +if rustc.version().version_compare('<1.65.0') + error('rustc version ' + rustc.version() + ' is unsupported. Please upgr= ade to at least 1.65.0') +endif +rust_args +=3D [ '--cfg', 'std_backtrace' ] # >=3D 1.65.0 +if rustc.version().version_compare('<1.81.0') + rust_args +=3D [ '--cfg', 'anyhow_no_core_error' ] +endif + +_anyhow_rs =3D static_library( + 'anyhow', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], + rust_abi: 'rust', + rust_args: rust_args, + dependencies: [], +) + +anyhow_dep =3D declare_dependency( + link_with: _anyhow_rs, +) + +meson.override_dependency('anyhow-1.0-rs', anyhow_dep) --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269668; cv=none; d=zohomail.com; s=zohoarc; b=D+dl4x96XCGh2UXRARx3s33Qb+JSWpTe3icg/KgVZS2Gp8SsqPlETdB2kSg6QC3DtIw9ecmP7a95cYOUeKmzFYjYUtOrCF6UsXzjlTHwHhSJG+Dg9+sY1FZIFPYYfV/9ntVgnuOUdfe6bontMSKxOdfJL3PxtyViLagVf06TA04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269668; 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=KlCPu9vrL2ikpJGmpcQeDNOSLxpS9BRUCw1rNrAFygE=; b=ZkAybY+GYM1Y+TGcmWbBgpqj62rxK25vU4be+TqHYBJBbgmoiRPC6ryn+4RzkICHWHZpQHR9rXcHIrqWDL8XXY/PqJilvOJMKeoEOT9ti27r9BQMrq1/+KD7/rMWIUkXrWB+oPFtOBCB4xQD0UCwwL87csUq10DgU2mpgkKxx/0= 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 1748269668202417.85158866897086; Mon, 26 May 2025 07:27:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlo-00036g-Px; Mon, 26 May 2025 10:25:41 -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 1uJYlL-0002u7-9a for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:14 -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 1uJYlI-0007pX-TL for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:10 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-Yo0ZvqRxPcynihROrzKY1A-1; Mon, 26 May 2025 10:25:06 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43d5ca7c86aso14254435e9.0 for ; Mon, 26 May 2025 07:25:05 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f23c080asm246606405e9.22.2025.05.26.07.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269507; 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=KlCPu9vrL2ikpJGmpcQeDNOSLxpS9BRUCw1rNrAFygE=; b=MMWomK+0QtdnPL1XjwYShB79j5Dl68dXZdb2B3Q5CiyFA8M0e5Erq0JlZcAJoHU781dXNb xXMHDnbMhUfHcoQuHahmW4wgzt8/gUkHkf4Z0hj7Hzds9vbgqU64/J1ym3Yx3xsboqhbkh 14LbclYoHyUPdhN+ZCHQYHkQaqWyxY0= X-MC-Unique: Yo0ZvqRxPcynihROrzKY1A-1 X-Mimecast-MFC-AGG-ID: Yo0ZvqRxPcynihROrzKY1A_1748269505 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269504; x=1748874304; 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=KlCPu9vrL2ikpJGmpcQeDNOSLxpS9BRUCw1rNrAFygE=; b=TsyzR8jLuGJRblffGma8Pb5YGzgEXCHv9MhD2/KqUEyJocDphSbiFa53LnuvDWNh4p dTkaKeVJ1WhgMYiPlcwQ9q+4KQZNQBYzEnCFnSieqmlPD/glnD09mKHM9LnJ3zFn8PE9 PqimmS4JHzNXnmvRWe47kRJxwHHKwvR3YOBTN2EaRgwSjz/CYRXH86e92lUOrPRVAXfv jw63VO6QbJDR8un1Ukz6lTd42wLfewnKdzrZ7GTG7GtOiwpombSmbK4NhW/AX4JYF1eu faBfVN5TToZ3Emr7WwjfuCL68ovTgD1hbqyQ3DtPL2akPDwyiSs1WIefFARRCKSMxwgv gjqQ== X-Gm-Message-State: AOJu0YwP6l8Do/h64kff303hqGCbLQZ0TtMjeCZmzSgdpNWkibWJ4a/P wcjfF9LArf+OWufSil+QZ1toSUnjhjmlQ1Eqq7ye6tssD0PVElEXBQ9SLbiPmmi4q2F0Tw/ENfG bM/pmmQPIQ3Wf6bEvabCbmZ2Ygm4034Zj7Uj41hd/2LTiDWe5QsbTFhXpJG5/c0e2S6DUBYcfwx vvX+bYiF8t3Zb9MdRiSFeMN64NRCWMrU/5UuDZS9ci X-Gm-Gg: ASbGnctY3+ccGYm0jwAl4LcM0/sFAlmfLeIeVvG6g11N9eSJwVD/Vfh8/J12m+b+XBx 3Te7Vc58prXcckUH3r1Ff3iSMQyqDIHQKAiAC6Bmh4rEod0EVVQoR1WCtf1O20lBJAJauvY2b7O vqJj7mYsUDfMhD229MkLmPNohPKmPujJVOGRp8xel4H1WYP7uUv4f+0I/je2CCXzgXCS5xHXy9S x/Ao0or+pUkb6ATi/BdeOUGHH+/CmyKn4JD1oOSfwqFJxCT1PV6NTWGkYq5mBJoQCiz1ozF/JR4 cV+p9oC129cMxg== X-Received: by 2002:a05:600c:1388:b0:442:f4a3:b5f2 with SMTP id 5b1f17b1804b1-44c916fc5efmr79230845e9.6.1748269503827; Mon, 26 May 2025 07:25:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaP6wuLhtodH0ZREfjb81Kkt7FnQnrzkJlWD9VkcNaZufp6drsy9MAwkt5vJkaAXcevIcXYg== X-Received: by 2002:a05:600c:1388:b0:442:f4a3:b5f2 with SMTP id 5b1f17b1804b1-44c916fc5efmr79230565e9.6.1748269503357; Mon, 26 May 2025 07:25:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 03/12] subprojects: add the foreign crate Date: Mon, 26 May 2025 16:24:46 +0200 Message-ID: <20250526142455.1061519-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269669951116600 Content-Type: text/plain; charset="utf-8" This is a cleaned up and separated version of the patches at https://lore.kernel.org/all/20240701145853.1394967-4-pbonzini@redhat.com/ https://lore.kernel.org/all/20240701145853.1394967-5-pbonzini@redhat.com/ Its first user will be the Error bindings; for example a QEMU Error ** can = be converted to a Rust Option using unsafe { Option::::from_foreign(c_error) } Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- subprojects/.gitignore | 1 + subprojects/foreign-0.2-rs.wrap | 7 +++++ .../packagefiles/foreign-0.2-rs/meson.build | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 subprojects/foreign-0.2-rs.wrap create mode 100644 subprojects/packagefiles/foreign-0.2-rs/meson.build diff --git a/subprojects/.gitignore b/subprojects/.gitignore index b9ae507b85a..7b38c4f6281 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -11,6 +11,7 @@ /bilge-0.2.0 /bilge-impl-0.2.0 /either-1.12.0 +/foreign-0.2.0 /itertools-0.11.0 /libc-0.2.162 /proc-macro-error-1.0.4 diff --git a/subprojects/foreign-0.2-rs.wrap b/subprojects/foreign-0.2-rs.w= rap new file mode 100644 index 00000000000..bf3cab9407a --- /dev/null +++ b/subprojects/foreign-0.2-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory =3D foreign-0.2.0 +source_url =3D https://crates.io/api/v1/crates/foreign/0.2.0/download +source_filename =3D foreign-0.2.0.tar.gz +source_hash =3D 37dd09e47ea8fd592a333f59fc52b894a97fe966ae9c6b7ef21ae38de6= 043462 +#method =3D cargo +patch_directory =3D foreign-0.2-rs diff --git a/subprojects/packagefiles/foreign-0.2-rs/meson.build b/subproje= cts/packagefiles/foreign-0.2-rs/meson.build new file mode 100644 index 00000000000..56b835d3ba9 --- /dev/null +++ b/subprojects/packagefiles/foreign-0.2-rs/meson.build @@ -0,0 +1,26 @@ +project('foreign-0.2-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '0.2.0', + license: 'MIT OR Apache-2.0', + default_options: []) + +subproject('libc-0.2-rs', required: true) +libc_rs =3D dependency('libc-0.2-rs') + +_foreign_rs =3D static_library( + 'foreign', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + rust_args: [ + '--cap-lints', 'allow', + ], + dependencies: [libc_rs], +) + +foreign_dep =3D declare_dependency( + link_with: _foreign_rs, +) + +meson.override_dependency('foreign-0.2-rs', foreign_dep) --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269700; cv=none; d=zohomail.com; s=zohoarc; b=ZAtxyOf03L5kEK97twgAKW6/lqyPPNE0Rk/Cy0XZXxXgbjzWtFQQQ7DPKSlVJaCvjRifJT9JNL8XtOxkPFZHsbU/5COtwn9MAu8KCLlK4+5z6zOcyeqkC4jxASlGxU/HHwcCEnJjc3eCyg1C4c/qJm6x0AL+YYyTrNmQ/bZ4CI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269699; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=cN4hMO2ruhwviMH2fPbbj17JC3X01Zr3Gi/txQbNDf2vDup//IlqbB0uqUNBfcZr/MV0G/vQ3yzh177lUWlqVcZZHZZglwDf3gd8cpaJps5mzBnKgzkKFMYqBTLM3Hh2mjxj7Qau19k2w93OVEzSJy7k3RahgzItQYcCOYUu4Ko= 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 1748269699990854.1248359772173; Mon, 26 May 2025 07:28:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlt-0003Ex-QV; Mon, 26 May 2025 10:25:45 -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 1uJYlN-0002ul-Jn for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:18 -0400 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 1uJYlK-0007qA-Fv for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:12 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-4QdVIxRjPTus1MlpgY1ULg-1; Mon, 26 May 2025 10:25:08 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-44b1f5b91c1so17453505e9.1 for ; Mon, 26 May 2025 07:25:08 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4c8455e7dsm8965827f8f.9.2025.05.26.07.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269509; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=bxB1hSDgag3OTURYoqRcw7BzZvCJLZkcv9P14y4OqjfZ1rSUso0ZYgmwIG3jc4khfXK9mq eNJ+Xn0HXak2/e7+yfDLXjyuEhSxorXX6DbPM+cGgnB6BMOxYXg0wwl23gm9vxlSGuFYPB 6VFt1BH2kegZEB9Qu6Fvd+fgLSJ9+Tw= X-MC-Unique: 4QdVIxRjPTus1MlpgY1ULg-1 X-Mimecast-MFC-AGG-ID: 4QdVIxRjPTus1MlpgY1ULg_1748269507 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269506; x=1748874306; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=ipG1jyV8/OqRWZ/Mp4z+N2QIL0S7O/SKgKjcczz8P13m1wTBVotRFH59Nz9xO//aJz qKKEMsOBPzs3U2qBstI2OLkdO4bvjT+5QzStMQARapGDMG4PTt+KwnUO3dInsd41KZ17 cGu07aB8u5XsaMraz+SVU9hjg7UIqdEMa9c36vmdph35cvo13UroVU24Sv0rSE09Fscn jAwRD9Bn9Xco/P+BkwsX3fP8oWs/FVWlJop2F+kovveXYbVIBbJWxpw7cxUXonRfgvEQ 3P310jqITZg76W7/MKjo+DgZakXYy29obbuZOUwu8lBg1XgRIt0mEmd3kIY8Zz2+FksV 1L4Q== X-Gm-Message-State: AOJu0YwnmvLormza6ZtK9k/VXJwgd4gdKVFAJk9wX4GY7zJxVtGTnfzM niU9OUS8ZTcCkEzm0G9wYVjpuIJl31W03G7d99Akx9O0Gdksfv05uvRYdx6kGm9wLg5nymyhAit YLXprP4Rkb6H+8fpGrPDdjDGrI6VOvl0/9pOZqXPbxbF5JnzWr57QJrVizk+qzmjumC6N9GlwjA bgxLF+SGh+MLxFKInzusyRbhXNApy1Lwj/6CYzofxG X-Gm-Gg: ASbGnctBiJ8rvv5HhDHSvx/klAmuKpS9Q139623IeVJiqV6dtMdoc+Go8NDSo+HzCiq Gpt7m03E5KOYdv3wX8KDDJrb0re3sN1UHqYlaYUjUbUyn5t1ZqIMuEn4VLkgNqoryPO7C+bKD3F kMFVFJSP+/2OjzEmDX8YhrcaKTqaJbYtzdtDMGsLhjvAAbhmU+F4RuQSY9MPsKPXG7rUUco6WGw sifyT+8Om66GM2wiSgMdRM6HR+IXJF7Ia5k/v5m+/4tVhNa72NmtMuKwVoXHmDjZedoAeqtl5tO rX9ZpHXgFO4Nuw== X-Received: by 2002:a05:600c:1d0d:b0:43c:f44c:72a6 with SMTP id 5b1f17b1804b1-44c9160702fmr93560335e9.2.1748269506421; Mon, 26 May 2025 07:25:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF4prXa7demfxOifhhcdzpzGpK3l+oYECeyNWEqlGlLWMYhrm6WWLfbf5CyRl6gHIbHjLr/g== X-Received: by 2002:a05:600c:1d0d:b0:43c:f44c:72a6 with SMTP id 5b1f17b1804b1-44c9160702fmr93560005e9.2.1748269505868; Mon, 26 May 2025 07:25:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 04/12] util/error: expose Error definition to Rust code Date: Mon, 26 May 2025 16:24:47 +0200 Message-ID: <20250526142455.1061519-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269702329116600 Content-Type: text/plain; charset="utf-8" This is used to preserve the file and line in a roundtrip from C Error to Rust and back to C. Signed-off-by: Paolo Bonzini --- include/qapi/error-internal.h | 26 ++++++++++++++++++++++++++ rust/wrapper.h | 1 + util/error.c | 10 +--------- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 include/qapi/error-internal.h diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h new file mode 100644 index 00000000000..d5c3904adec --- /dev/null +++ b/include/qapi/error-internal.h @@ -0,0 +1,26 @@ +/* + * QEMU Error Objects - struct definition + * + * Copyright IBM, Corp. 2011 + * Copyright (C) 2011-2015 Red Hat, Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster , + * + * This work is licensed under the terms of the GNU LGPL, version 2. See + * the COPYING.LIB file in the top-level directory. + */ + +#ifndef QAPI_ERROR_INTERNAL_H + +struct Error +{ + char *msg; + ErrorClass err_class; + const char *src, *func; + int line; + GString *hint; +}; + +#endif diff --git a/rust/wrapper.h b/rust/wrapper.h index beddd9aab2f..6060d3ba1ab 100644 --- a/rust/wrapper.h +++ b/rust/wrapper.h @@ -60,6 +60,7 @@ typedef enum memory_order { #include "hw/qdev-properties-system.h" #include "hw/irq.h" #include "qapi/error.h" +#include "qapi/error-internal.h" #include "migration/vmstate.h" #include "chardev/char-serial.h" #include "exec/memattrs.h" diff --git a/util/error.c b/util/error.c index 673011b89e9..e5bcb7c0225 100644 --- a/util/error.c +++ b/util/error.c @@ -15,15 +15,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/error-report.h" - -struct Error -{ - char *msg; - ErrorClass err_class; - const char *src, *func; - int line; - GString *hint; -}; +#include "qapi/error-internal.h" =20 Error *error_abort; Error *error_fatal; --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269682; cv=none; d=zohomail.com; s=zohoarc; b=EXWukQuSan2fOOi2mUt47JHdz/Oje31UGtNWVaBqYF6vw0acPfE1r8HJwjRzE4V69fusW6cFnJHFqjYuNXOyyhy3wSsAzhpEYzV2NKawNxk/6UrHe8dnVLfnhOLDD1RQ7NCih4000hn9rGC22FRZxaIMsnaJ3GLYNkt7e0Ld1fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269682; 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=NpYGntv438dYQNUhSbgUIEWdF1v1wrR4ORdQOzf6Qfw=; b=H86vY0OIyNuZeMCxX8YjNnLShh6dKl91smqzOhkNG26VLCN+2Rz5zrVMgW+SKaGqRZj/J/84wqICqZS45ELCMy86DIf/FxlnZA3vURuZbk5rJ77z3o7/BNIQv5XGbgBVpQbvu5/nRWu8VRHQeKGI4tiRFijuo5S1trvOqLyxb8g= 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 1748269682320565.7134659560546; Mon, 26 May 2025 07:28:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlt-0003Ct-0r; Mon, 26 May 2025 10:25:45 -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 1uJYlQ-0002wo-8Y for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:22 -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 1uJYlN-0007qW-Ba for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:14 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-UFnIRciHO8KNoA4wDvKyHw-1; Mon, 26 May 2025 10:25:11 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a371fb826cso913061f8f.1 for ; Mon, 26 May 2025 07:25:10 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4db4e6f15sm2342195f8f.81.2025.05.26.07.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269512; 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=NpYGntv438dYQNUhSbgUIEWdF1v1wrR4ORdQOzf6Qfw=; b=IShx6BlQV0+QR15OW8R/Lntjg9SUGL1mQ1hqeCvLvqXt+Hps6giCs3bl/94OrJnooyUoUT bwJziBuyxu3R2zIIaQy5UKn47IvtEzjR0f0HBJ3xohD/E3aJOmtqJ5wuKA0i6M2Js/l9gg 4+JryhcW1P6QvZAJtV4Uk6SyriKTReM= X-MC-Unique: UFnIRciHO8KNoA4wDvKyHw-1 X-Mimecast-MFC-AGG-ID: UFnIRciHO8KNoA4wDvKyHw_1748269510 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269509; x=1748874309; 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=NpYGntv438dYQNUhSbgUIEWdF1v1wrR4ORdQOzf6Qfw=; b=Bcu5pdsuuM7cWrSxaAHu3K8mirBmdpT9BM1MqFWP1xuSNg73cLdTyOFX8RYsarfQ+9 T/zhSttqiesA3FEPwO1wVf5w1kKn/vCAtvkhZ3or4SgIBixq1dkPCWaoHA/TQJeadJ+N avOnIx2hUH0dZA+wsAgG4uNfymdj1Qc0dfiStJpJSm1S8pW3R3Oa92Lzm1q/CfiylghJ 15Ok81s6s4pbA8Px5pKOTnf62obBFaEh9QrJGWmwad5YckwDX2zpRPM26oE/SB8hm2Ys Z0xrw514Zh93OV5l02TaeZ/7UNr6IiqoFIXF6OTaJtKHJiiGOxZDdUWqqgzDWm4QD77C b9YQ== X-Gm-Message-State: AOJu0YxqDmymqIztO6hLnKk+Fhq+rDJHfeuv6GwD0Y5sd4nvQfYJTBAZ xKkTDN9Fq2WTK1e16WHiOww23YtHZ2xXNZhtMovELtkxQzd/IYhp51SyQuVF2rUCKyEepcWekZg nW4vOlt6x5ZfNHy3ljYkScjb71PZ3l61OvdF92I3lkrYXCAzKvER+7wF8cLBdcgYp2bg/RyDabt z+tBbo1BhZelHG9hmbmucAb5bWluI9sN6ojQQ+tYWh X-Gm-Gg: ASbGncvOChPZZ3G9BLGizPEnwxTz9N4DKh0NT+c7tZoIHVdUDTy+SZIqYYB0hIkYZA2 +T+KW+nQwaB5BuHKiyOVHXQ9V20NSO5RE+KpoYeYLenZ5SpGI0GA8HJkimCOoviVWO8qKsEaZHQ 7EDcyzbRGyKA/Y4SPfqlgGJ4q45O/mnWy7Wt7fuvjYDZjXyK4Re4cn13uVfOKdCtLaFl2R8YNNQ 7FbSDIQTi3KUQ5ZQSxOZ9Bih8BJVwIIaJ3zrAkRhx4uksN5ExX4kMEDTYVlEeCmt71oi3FX5Q08 aslA1Y/Ab7IG8w== X-Received: by 2002:a05:6000:1785:b0:3a3:6415:96c8 with SMTP id ffacd0b85a97d-3a4cb49dea3mr7153163f8f.41.1748269508858; Mon, 26 May 2025 07:25:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETdttXPnZfK3l9FdiP+86UXu7Z77XeMloT+ILBa2OzcxJ3YSS6IjjsnMqJXILplkExEN6PpQ== X-Received: by 2002:a05:6000:1785:b0:3a3:6415:96c8 with SMTP id ffacd0b85a97d-3a4cb49dea3mr7153137f8f.41.1748269508389; Mon, 26 May 2025 07:25:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 05/12] util/error: allow non-NUL-terminated err->src Date: Mon, 26 May 2025 16:24:48 +0200 Message-ID: <20250526142455.1061519-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748269684007116600 Content-Type: text/plain; charset="utf-8" Rust makes the current file available as a statically-allocated string, but without a NUL terminator. Allow this by storing an optional maximum length in the Error. Note that for portability I am not relying on fprintf's precision specifier not accessing memory beyond what will be printed. Signed-off-by: Paolo Bonzini --- include/qapi/error-internal.h | 1 + util/error.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h index d5c3904adec..6178ce4a63d 100644 --- a/include/qapi/error-internal.h +++ b/include/qapi/error-internal.h @@ -19,6 +19,7 @@ struct Error char *msg; ErrorClass err_class; const char *src, *func; + ssize_t src_len; int line; GString *hint; }; diff --git a/util/error.c b/util/error.c index e5bcb7c0225..6c1033eaba5 100644 --- a/util/error.c +++ b/util/error.c @@ -24,8 +24,13 @@ Error *error_warn; static void error_handle(Error **errp, Error *err) { if (errp =3D=3D &error_abort) { + const char *src =3D err->src; + if (err->src_len >=3D 0) { + /* No need to free it, the program will abort very soon... */ + src =3D g_strndup(err->src, err->src_len); + } fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", - err->func, err->src, err->line); + err->func, src, err->line); error_report("%s", error_get_pretty(err)); if (err->hint) { error_printf("%s", err->hint->str); @@ -67,6 +72,7 @@ static void error_setv(Error **errp, g_free(msg); } err->err_class =3D err_class; + err->src_len =3D -1; err->src =3D src; err->line =3D line; err->func =3D func; --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269572; cv=none; d=zohomail.com; s=zohoarc; b=Cta2p3Ob+aKjcT4ZkGI/s12B1iBzHb4vKjm7qRRQR9uOYTmY973jagav66kWTfz1//SJdu6ticDndCduL3K6K4fZr5doIJBKs0m+C2okrp2EAVCCSyvOkQtXNE9UezVGeKTkby0j2zRSkaKFihMd14plKZJrfHwYHQO3Ql4sPBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269572; 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=3EGlhQGgpmM2dQVRCh7jBtvLfB+JtoZdp0/VjpnQkgc=; b=NWHZXokxfybgGPq9Bf4vh2IpxvE8kxFdgAwfeoSNuO7Kjv1srSNzVd/HSZWGCMVjzgAlbt6Lc0WiKraSI7NB2jj3+SIQ5mPNRbbtaeyEcqDb0STE3XDpQMZ49vxtHWF7v8dN80oVr4C1skjcfwZd69VQZPSB7D2Y4VXgd5Sc7So= 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 1748269572503802.6736875961587; Mon, 26 May 2025 07:26:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlv-0003IE-Jc; Mon, 26 May 2025 10:25:47 -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 1uJYlT-0002yF-9Q for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:22 -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 1uJYlP-0007qv-WF for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:18 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-4jcbjMCQNaKceFKoWDdtOQ-1; Mon, 26 May 2025 10:25:13 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-44a3b5996d2so11304565e9.1 for ; Mon, 26 May 2025 07:25:12 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f6b29633sm251321115e9.8.2025.05.26.07.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269514; 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=3EGlhQGgpmM2dQVRCh7jBtvLfB+JtoZdp0/VjpnQkgc=; b=SCNXVLFYB+IDRFy37pgGVlhAUnAjZVWIfG6t+dQzMSXVyrv2nkwa4PkY+2wnhQ4UFi9R29 Yfi/GNJ1SobLlEmuz6ZO0UJRO59ohrGPdhsJr8P9HvWi3s1srarEp7+beZQa8Zspi1z0ni NKP4ZoZR9azuzVkf4wmdygXH0kQ3xhQ= X-MC-Unique: 4jcbjMCQNaKceFKoWDdtOQ-1 X-Mimecast-MFC-AGG-ID: 4jcbjMCQNaKceFKoWDdtOQ_1748269512 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269511; x=1748874311; 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=3EGlhQGgpmM2dQVRCh7jBtvLfB+JtoZdp0/VjpnQkgc=; b=RJQTe12jV7+G7TKH54MYcKTV5qxiP5hFQQjlbKVbilD4luZp46qB/05oVNFLHdV9aY 7FPtIkiyRc4jIXkg4AsRiAoI1k1SyWoZfyRPY5YClTjxVDGzy0+6ho5GSioUU4+7Zukd 1YR0qpWRBVIrYVbRwO9mgMTfCk51iZNKdRCVzesTTfUguigXO8vMEnMm0UYMCSGmLO2W 8vubRMLEVpBVQIk5k/y8wnI7SvE3W8Q1TYFd2G+VJd90KB8zWyAjGK1Li4faqdi7DR3U deTAQDNRuvhrl0uB0MiGmGiHps8sR3Ec7fChkp4TK+vc4n/Oa/PuqKuxZLbVGW4zvBtE GxXg== X-Gm-Message-State: AOJu0YzOrxMTpFIYxkqWFlUzPPeWOiDit37Kka3mZvAGR25EGzJ7m3vg 63xXc0pD6XBhhY798KNz44dQ/fCTx1QmWpPo8IgPsvgUutL/801ErXJX2n/5Q3/Nm5ZAPLD0wW0 1qRjKI+qobOrbYYr0MLFoMpebHmjjDWzm+BB+2OkciyvgrgTjStn0qIJvIqDnFkznMefuWETAK/ FvCLr1K1k4+twY/urtUOtzH3b5MeMXOtC5/Z8Un6Bg X-Gm-Gg: ASbGncuytHVxtoKxaIlWBAXWjytjs1SwCGdt/9VMS1yT+qzEBufafaGkkxok2pp7T8K nkk7SOefoZ8PLOJqYj+EHkwTHMiSlHSaUQ7m6+YYVyWbcXCAy7RS/uxa+nIjq48rLXtika9WLvh npYesuL8G+P5K9DBK4bwuFDn55nM80U/oSG5cjISPASzM97/qYl/oe/OIOshPUhl7I4sIc/v+Y1 IRcaHM20LgOw10PtfabwuWuMY3oyaNZzH3H6qoEagoK/jYudCv8SCXuCiLQwpWbWxdRFXtNo0vy OqPOoG5JKihq+w== X-Received: by 2002:a05:600c:5297:b0:44b:1f5b:8c85 with SMTP id 5b1f17b1804b1-44c919e1690mr78095095e9.13.1748269511008; Mon, 26 May 2025 07:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrf2JnDbM5/Xjo8vU4HZrsfTrlL6QdK7hPIzOHeUs3OcU2pEDbqB77ErRZz/tIY3keLU5t6Q== X-Received: by 2002:a05:600c:5297:b0:44b:1f5b:8c85 with SMTP id 5b1f17b1804b1-44c919e1690mr78094835e9.13.1748269510570; Mon, 26 May 2025 07:25:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 06/12] util/error: make func optional Date: Mon, 26 May 2025 16:24:49 +0200 Message-ID: <20250526142455.1061519-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748269574760116600 Content-Type: text/plain; charset="utf-8" The function name is not available in Rust, so make it optional. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- util/error.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/error.c b/util/error.c index 6c1033eaba5..b977007faaf 100644 --- a/util/error.c +++ b/util/error.c @@ -29,8 +29,12 @@ static void error_handle(Error **errp, Error *err) /* No need to free it, the program will abort very soon... */ src =3D g_strndup(err->src, err->src_len); } - fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", - err->func, src, err->line); + if (err->func) { + fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", + err->func, src, err->line); + } else { + fprintf(stderr, "Unexpected error at %s:%d:\n", src, err->line= ); + } error_report("%s", error_get_pretty(err)); if (err->hint) { error_printf("%s", err->hint->str); --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269561; cv=none; d=zohomail.com; s=zohoarc; b=g3O3VM0TnZhlCGshDdBfcYGQRIY+7xeHtagInXbESvEauVXh3YbPKAxYMIsOL/4ZmXo4H7TW8L4k1YZSq5nQmHrc9L/dvxEDIp2U8zmsUyt0orQu8p+na8e2qrOFRqyKMYpjZ4EJcPFMiTheFx0T/SZPC5+dsk6dB+1VRUxyRzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269561; 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=b83n7BN9K+QBZzi9RoIqpz7fGe04sSc+YOYqMVO8GK0=; b=ezIIflvERPXDAu/Yr055QQPSjeI5BAM5v4r3FBsVDpt3GzSUhP+08O6JGrHFOIGvQMgwop84qj3jZ0QLTjOKIYLdIksXxLtyUSK2ts33yzPen8uoA9auJWYZIA6lD0w7464o1I/4Nr5gTBZW/lXoOKYkXpuyefT7G3U3pGlwWyg= 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 1748269561837209.46691738450124; Mon, 26 May 2025 07:26:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlq-00037v-Un; Mon, 26 May 2025 10:25:43 -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 1uJYlW-0002zf-5J for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:29 -0400 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 1uJYlR-0007rF-Rx for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:20 -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-639-SHrMjAd9Pb-Znf9Jorpfog-1; Mon, 26 May 2025 10:25:15 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d007b2c79so17215475e9.2 for ; Mon, 26 May 2025 07:25:15 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f3dd99absm235569045e9.37.2025.05.26.07.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269517; 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=b83n7BN9K+QBZzi9RoIqpz7fGe04sSc+YOYqMVO8GK0=; b=RFSdtQrjcmhQzyyePZti35c44hzbNV3MJuY5S0gZCs1mRxxMIR0x9Zy5rw1poksIk76VLi qZhOU3oOK6njeVKTmk8f0rDnqgmhqXT5kL+SxIFDPAkkRUW/X0JCQEZr9K3IL9P1vnyMbw 8UYtnA5W1dBrrpgmtbt9g7phlf4dp8Y= X-MC-Unique: SHrMjAd9Pb-Znf9Jorpfog-1 X-Mimecast-MFC-AGG-ID: SHrMjAd9Pb-Znf9Jorpfog_1748269514 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269514; x=1748874314; 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=b83n7BN9K+QBZzi9RoIqpz7fGe04sSc+YOYqMVO8GK0=; b=h2sGFpl1CSFxQ0t74gdn1XpI71mWU0gazXWsB8cVJSiwicCizk9Q6syJ2VMWW2OOOK K3aBmO8z8pm8MNFYs+vAIORV2oTmJ7kjh4EnlHHm7DRqyVVtYJvGDT60+EzNjHvUvqia UO3eKP/8ySqpPlya6NUBqSztw5YjPvGFlhHUSYxju1hgpej1HwjJ4HJ4zPSi/Dgdo/Dx JY9vf0crsg/yRkbfyR/6vEhF6Bn0JuwseMTbFUxIxzddHMRjUoMZTws5ki1N9HVWXMbx DQirvxjAckmlieS/Mc5pRMDAWi8y8tFMD+IwzoiFAXCHPxDL95RyDal2r5XXpK+AnvUn tSTQ== X-Gm-Message-State: AOJu0Yy0SIA7MiA8OUWCTaRq+FQeEFMHhhTtionkauepAntsH92LKmbK wJNRKupK4XmRI09LU28/2m1m7hsG3wiWyyqepyLgxySr0xoGh4V8jrCcTfCg9l1ZJaz3wLye6sL 8aZajZfAgWWVMJhhkm6Nh9/wJ+QbG4lB6v/LwcJC4oTVumBoK9cnh6Bv2cVsm7W6Cto052aG6rL N2e/+/2RQuMc9i8cRIBQ9UcWWwZ8JhYgdh+tZBGahA X-Gm-Gg: ASbGncv90aIME3V3IsWVSunHmQX/MDecr6zHNKRDMxuG1EbEoczdbK0cIuSIq3ejN+h OK4N/MavkWIFwAnPEGP+dw6ZH6j34U3arAK3wG+X4xywdGO36Y98Gi/tPD++3deujvKU14eSP0o 6AEMD89k109IX3y2UZp6CakRD25+5RFPUF/8u2sOWpfSZdAxH/BiCZJEN+0vK2Zk1j9Nitzj1MP QnZ84W7wqlyhZ1LjcL8phQjhDLQkGQ128kOfzLlX3eH7LhOdvvGKe036oEKhRH1D0BhxEkTLIa+ R1dXX6i2wqvzeQ== X-Received: by 2002:a05:600c:3b19:b0:442:e9eb:cba2 with SMTP id 5b1f17b1804b1-44c8f25dab7mr97415795e9.0.1748269513622; Mon, 26 May 2025 07:25:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2A3zP9aqvcSQw4Bi0aQN0k9xWjyVVLsmsO1gX6OQrJ2qQcDKYfyy4FpJUNdO3EcwUS9cV0g== X-Received: by 2002:a05:600c:3b19:b0:442:e9eb:cba2 with SMTP id 5b1f17b1804b1-44c8f25dab7mr97415485e9.0.1748269513115; Mon, 26 May 2025 07:25:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 07/12] qemu-api: add bindings to Error Date: Mon, 26 May 2025 16:24:50 +0200 Message-ID: <20250526142455.1061519-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=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: 1748269562998116600 Content-Type: text/plain; charset="utf-8" Provide an implementation of std::error::Error that bridges the Rust anyhow::Error and std::panic::Location types with QEMU's Error*. It also has several utility methods, analogous to error_propagate(), that convert a Result into a return value + Error** pair. Signed-off-by: Paolo Bonzini --- rust/Cargo.lock | 17 +++ rust/Cargo.toml | 1 + rust/meson.build | 2 + rust/qemu-api/Cargo.toml | 2 + rust/qemu-api/meson.build | 3 +- rust/qemu-api/src/error.rs | 273 +++++++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 3 + 7 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 rust/qemu-api/src/error.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 13d580c693b..37fd10064f9 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version =3D 3 =20 +[[package]] +name =3D "anyhow" +version =3D "1.0.98" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdc= d487" + [[package]] name =3D "arbitrary-int" version =3D "1.2.7" @@ -37,6 +43,15 @@ version =3D "1.12.0" source =3D "registry+https://github.com/rust-lang/crates.io-index" checksum =3D "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385= b58b" =20 +[[package]] +name =3D "foreign" +version =3D "0.2.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "37dd09e47ea8fd592a333f59fc52b894a97fe966ae9c6b7ef21ae38de604= 3462" +dependencies =3D [ + "libc", +] + [[package]] name =3D "hpet" version =3D "0.1.0" @@ -106,6 +121,8 @@ dependencies =3D [ name =3D "qemu_api" version =3D "0.1.0" dependencies =3D [ + "anyhow", + "foreign", "libc", "qemu_api_macros", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index d9faeecb10b..2726b1f72e3 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -67,6 +67,7 @@ multiple_crate_versions =3D "deny" mut_mut =3D "deny" needless_bitwise_bool =3D "deny" needless_pass_by_ref_mut =3D "deny" +needless_update =3D "deny" no_effect_underscore_binding =3D "deny" option_option =3D "deny" or_fun_call =3D "deny" diff --git a/rust/meson.build b/rust/meson.build index 3e0b6ed4afa..9eb69174dea 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,11 +1,13 @@ subproject('anyhow-1.0-rs', required: true) subproject('bilge-0.2-rs', required: true) subproject('bilge-impl-0.2-rs', required: true) +subproject('foreign-0.2-rs', required: true) subproject('libc-0.2-rs', required: true) =20 anyhow_rs =3D dependency('anyhow-1.0-rs') bilge_rs =3D dependency('bilge-0.2-rs') bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') +foreign_rs =3D dependency('foreign-0.2-rs') libc_rs =3D dependency('libc-0.2-rs') =20 subproject('proc-macro2-1-rs', required: true) diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index c96cf50e7a1..ca6b81db10a 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -15,7 +15,9 @@ rust-version.workspace =3D true =20 [dependencies] qemu_api_macros =3D { path =3D "../qemu-api-macros" } +anyhow =3D "~1.0" libc =3D "0.2.162" +foreign =3D "~0.2" =20 [features] default =3D ["debug_cell"] diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1ea86b8bbf1..11cbd6d375a 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -19,6 +19,7 @@ _qemu_api_rs =3D static_library( 'src/cell.rs', 'src/chardev.rs', 'src/errno.rs', + 'src/error.rs', 'src/irq.rs', 'src/memory.rs', 'src/module.rs', @@ -35,7 +36,7 @@ _qemu_api_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, - dependencies: [libc_rs, qemu_api_macros], + dependencies: [anyhow_rs, foreign_rs, libc_rs, qemu_api_macros], ) =20 rust.test('rust-qemu-api-tests', _qemu_api_rs, diff --git a/rust/qemu-api/src/error.rs b/rust/qemu-api/src/error.rs new file mode 100644 index 00000000000..f08fed81028 --- /dev/null +++ b/rust/qemu-api/src/error.rs @@ -0,0 +1,273 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Error class for QEMU Rust code +//! +//! @author Paolo Bonzini + +use std::{ + borrow::Cow, + ffi::{c_char, c_int, c_void, CStr}, + fmt::{self, Display}, + panic, ptr, +}; + +use foreign::{prelude::*, OwnedPointer}; + +use crate::{ + bindings, + bindings::{error_free, error_get_pretty}, +}; + +pub type Result =3D std::result::Result; + +#[derive(Debug, Default)] +pub struct Error { + msg: Option>, + /// Appends the print string of the error to the msg if not None + cause: Option, + file: &'static str, + line: u32, +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + self.cause.as_ref().map(AsRef::as_ref) + } + + #[allow(deprecated)] + fn description(&self) -> &str { + self.msg + .as_deref() + .or_else(|| self.cause.as_deref().map(std::error::Error::descr= iption)) + .unwrap_or("error") + } +} + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut prefix =3D ""; + if let Some(ref msg) =3D self.msg { + write!(f, "{msg}")?; + prefix =3D ": "; + } + if let Some(ref cause) =3D self.cause { + write!(f, "{prefix}{cause}")?; + } else if prefix.is_empty() { + f.write_str("unknown error")?; + } + Ok(()) + } +} + +impl From for Error { + #[track_caller] + fn from(msg: String) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(Cow::Owned(msg)), + file: location.file(), + line: location.line(), + ..Default::default() + } + } +} + +impl From<&'static str> for Error { + #[track_caller] + fn from(msg: &'static str) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(Cow::Borrowed(msg)), + file: location.file(), + line: location.line(), + ..Default::default() + } + } +} + +impl From for Error { + #[track_caller] + fn from(error: anyhow::Error) -> Self { + let location =3D panic::Location::caller(); + Error { + cause: Some(error), + file: location.file(), + line: location.line(), + ..Default::default() + } + } +} + +impl Error { + /// Create a new error, prepending `msg` to the + /// description of `cause` + #[track_caller] + pub fn with_error(msg: &= 'static str, cause: E) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(Cow::Borrowed(msg)), + cause: Some(cause.into()), + file: location.file(), + line: location.line(), + } + } + + /// Consume a result, returning false if it is an error and + /// true if it is successful. The error is propagated into + /// `errp` like the C API `error_propagate` would do. + /// + /// # Safety + /// + /// `errp` must be valid; typically it is received from C code + pub unsafe fn bool_or_propagate(result: Result<()>, errp: *mut *mut bi= ndings::Error) -> bool { + // SAFETY: caller guarantees errp is valid + unsafe { Self::ok_or_propagate(result, errp) }.is_some() + } + + /// Consume a result, returning a `NULL` pointer if it is an + /// error and a C representation of the contents if it is + /// successful. The error is propagated into `errp` like + /// the C API `error_propagate` would do. + /// + /// # Safety + /// + /// `errp` must be valid; typically it is received from C code + #[must_use] + pub unsafe fn ptr_or_propagate( + result: Result, + errp: *mut *mut bindings::Error, + ) -> *mut T::Foreign { + // SAFETY: caller guarantees errp is valid + unsafe { Self::ok_or_propagate(result, errp) }.clone_to_foreign_pt= r() + } + + /// Consume a result in the same way as `self.ok()`, but also propagate + /// a possible error into `errp`, like the C API `error_propagate` + /// would do. + /// + /// # Safety + /// + /// `errp` must be valid; typically it is received from C code + pub unsafe fn ok_or_propagate( + result: Result, + errp: *mut *mut bindings::Error, + ) -> Option { + let Err(err) =3D result else { + return result.ok(); + }; + + // SAFETY: caller guarantees errp is valid + unsafe { + err.propagate(errp); + } + None + } + + /// Equivalent of the C function `error_propagate`. Fill `*errp` + /// with the information container in `result` if `errp` is not NULL; + /// then consume it. + /// + /// # Safety + /// + /// `errp` must be valid; typically it is received from C code + pub unsafe fn propagate(self, errp: *mut *mut bindings::Error) { + if errp.is_null() { + return; + } + + let err =3D self.clone_to_foreign_ptr(); + + // SAFETY: caller guarantees errp is valid + unsafe { + errp.write(err); + } + } + + /// Convert a C `Error*` into a Rust `Result`, using + /// `Ok(())` if `c_error` is NULL. + /// + /// # Safety + /// + /// `c_error` must be valid; typically it has been filled by a C + /// function. + pub unsafe fn err_or_unit(c_error: *mut bindings::Error) -> Result<()>= { + // SAFETY: caller guarantees c_error is valid + unsafe { Self::err_or_else(c_error, || ()) } + } + + /// Convert a C `Error*` into a Rust `Result`, calling `f()` to + /// obtain an `Ok` value if `c_error` is NULL. + /// + /// # Safety + /// + /// `c_error` must be valid; typically it has been filled by a C + /// function. + pub unsafe fn err_or_else T>( + c_error: *mut bindings::Error, + f: F, + ) -> Result { + // SAFETY: caller guarantees c_error is valid + let err =3D unsafe { Option::::from_foreign(c_error) }; + match err { + None =3D> Ok(f()), + Some(err) =3D> Err(err), + } + } +} + +impl FreeForeign for Error { + type Foreign =3D bindings::Error; + + unsafe fn free_foreign(p: *mut bindings::Error) { + // SAFETY: caller guarantees p is valid + unsafe { + error_free(p); + } + } +} + +impl CloneToForeign for Error { + fn clone_to_foreign(&self) -> OwnedPointer { + // SAFETY: all arguments are controlled by this function + unsafe { + let err: *mut c_void =3D libc::malloc(std::mem::size_of::()); + let err: &mut bindings::Error =3D &mut *err.cast(); + *err =3D bindings::Error { + msg: format!("{self}").clone_to_foreign_ptr(), + err_class: bindings::ERROR_CLASS_GENERIC_ERROR, + src_len: self.file.len() as isize, + src: self.file.as_ptr().cast::(), + line: self.line as c_int, + func: ptr::null_mut(), + hint: ptr::null_mut(), + }; + OwnedPointer::new(err) + } + } +} + +impl FromForeign for Error { + unsafe fn cloned_from_foreign(c_error: *const bindings::Error) -> Self= { + // SAFETY: caller guarantees c_error is valid + unsafe { + let error =3D &*c_error; + let file =3D if error.src_len < 0 { + // NUL-terminated + CStr::from_ptr(error.src).to_str() + } else { + // Can become str::from_utf8 with Rust 1.87.0 + std::str::from_utf8(std::slice::from_raw_parts( + &*error.src.cast::(), + error.src_len as usize, + )) + }; + + Error { + msg: FromForeign::cloned_from_foreign(error_get_pretty(err= or)), + cause: None, + file: file.unwrap(), + line: error.line as u32, + } + } + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 234a94e3c29..93902fc94bc 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -19,6 +19,7 @@ pub mod cell; pub mod chardev; pub mod errno; +pub mod error; pub mod irq; pub mod memory; pub mod module; @@ -34,6 +35,8 @@ ffi::c_void, }; =20 +pub use error::{Error, Result}; + #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] extern "C" { fn g_aligned_alloc0( --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269564; cv=none; d=zohomail.com; s=zohoarc; b=F4SkEW8uQv7nIX0E8b6Koy7nbXydTo8JrtUEroq/ocsY5p6Kar7gctP3HVHKS0BQLHI4GHaE7WGbCWZpDlGjCbWYk7WyViYwHahzyidpgpF3Thn7dAt/BXucIinrFYauu1JM/SykP/V2sxN3t+sBGSACFnLOekWRHbtz8L4wtio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269564; 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=yEirfICDV2iUFGeoHG7Gn3nAmnYWGEW5yhNDMIdDw0M=; b=DBIEvar+zBO8UTCUROggwODwoVWtrpgnQosgv6oTzomWYHK5li529fjYJEUwnH/+TBXMvndI6eH2AiDCquqAM8LuPBD3M14+RrrsW3mP3zlUJEB9yWPXJkGw5pOlhR7DbpGoVOM08lJxmATTZUqrSAGE70CZHO5MN9e9+MKjQXI= 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 1748269564369698.8668277030964; Mon, 26 May 2025 07:26:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlw-0003JJ-Aw; Mon, 26 May 2025 10:25:48 -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 1uJYld-00031S-Fk for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:31 -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 1uJYlV-0007ro-S9 for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:24 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-kF41sNprMaq6w1CtByvRrQ-1; Mon, 26 May 2025 10:25:17 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cf5196c25so13574175e9.0 for ; Mon, 26 May 2025 07:25:17 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f18251basm235241585e9.4.2025.05.26.07.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269519; 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=yEirfICDV2iUFGeoHG7Gn3nAmnYWGEW5yhNDMIdDw0M=; b=NqDNFGdP4uza9OHLwY5/v//khZbQCSM4vLvxhaaPIrc8ZNchJFFB78N6yepedJi4++LoXF B2qNrXNtO+lquBL6egFnIxU6QFdL7ixhqjk1peSJOOFD5AL76RrmOi44WYB1f/TuVJtTug jZ5Ou97esqSUk6pFxbjRQYU84SZg4SQ= X-MC-Unique: kF41sNprMaq6w1CtByvRrQ-1 X-Mimecast-MFC-AGG-ID: kF41sNprMaq6w1CtByvRrQ_1748269517 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269515; x=1748874315; 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=yEirfICDV2iUFGeoHG7Gn3nAmnYWGEW5yhNDMIdDw0M=; b=t7BvKnmYNjaAjLiQJGlUjlseJpzXPzFnS7fk9FM0utEk/Jp71+WvmCCYq+Do4Hsgag kcuzWL+sO2+4dQ03CotTyNh1WGiIX2n7RP8orDONbJtXkPZ9CCxJ+Kic3r09J224xENA 3pufE8j0TQGptdCLTkVkr9s1BqDmi3PErJkd3tTW88/TxuRrSi1W0MfwIysRR4NqZDjW PVhA2JL6+cZES8kX5L7zjVf3rvs09qLhYCLmYZz1job/sayP/PerOlLY2ac6/BOzFkhy CAVf0y4B+EdPL3qHabPFgeeuD73ppikdQht7245Al4cy0wnEyXGS7DDvCwFSUEVOQs+W oMCg== X-Gm-Message-State: AOJu0YyJdtFaaca+J1Bo2QOS0InhaskCgSz8prqq4/NpS3SU/PPtNee2 wTytoz2rzFlvmvasDDr7Ov0SFV+e1nF4s0WRNSeOoaRU8xhcOc8iT/JOJPa1EkUkqJhSiYoeEvn nrJvGwyodefhhG11a6ivlz1xBXXixUVjPMXMVZWNvdBkIwc9HC6fK6eT0K7w2slSK0hUGf36jSl WRjRmpBzvcrKTWEUFI/GaZtFd07kxrjFeUGkrShVBH X-Gm-Gg: ASbGncuftbDdd6p+uDmEh7lSiYNdFVwnBlm1K6+HXfPLUL7xioN0IwFmPXjBpRMb8Xx 6FF+TbIaIyUK54VCXJ1HebZ91a2JJyI1/WBud65FB8r51MwtZCgL6mg30NFSMDeiyBA9yFqYfIX nzh4I6T3DxeWsG5OpV9gwjGHnb2ibJyxoKqdr12J0w3Pp23KOB2i6vtQuk2ZyKwTsgTmEjgcxQt PuxAYQk1SZ99+Hz32zTaJBPynj0M+GEQGyr2llchSqY+l7V/ITQF5ka+zyNDueGUivzv1LC0UQ6 LL5A8eli/bK76w== X-Received: by 2002:a05:600c:1da6:b0:44a:4874:bdde with SMTP id 5b1f17b1804b1-44c8ed8f474mr89520835e9.0.1748269514848; Mon, 26 May 2025 07:25:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvFQhU736uPEHz30h8XKYQwp60N+KklBTccvOgW4W5S3cXm93i6WcOt9PK66MdDozUqztwEQ== X-Received: by 2002:a05:600c:1da6:b0:44a:4874:bdde with SMTP id 5b1f17b1804b1-44c8ed8f474mr89520605e9.0.1748269514409; Mon, 26 May 2025 07:25:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 08/12] rust: qdev: support returning errors from realize Date: Mon, 26 May 2025 16:24:51 +0200 Message-ID: <20250526142455.1061519-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269566792116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/src/device.rs | 5 +++-- rust/hw/timer/hpet/src/hpet.rs | 5 +++-- rust/qemu-api/src/qdev.rs | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index bde3be65c5b..95fe9a34cd2 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -175,7 +175,7 @@ fn properties() -> &'static [Property] { fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } - const REALIZE: Option =3D Some(Self::realize); + const REALIZE: Option qemu_api::Result<()>> =3D Some(Self= ::realize); } =20 impl ResettablePhasesImpl for PL011State { @@ -619,9 +619,10 @@ fn event(&self, event: Event) { } } =20 - fn realize(&self) { + fn realize(&self) -> qemu_api::Result<()> { self.char_backend .enable_handlers(self, Self::can_receive, Self::receive, Self:= :event); + Ok(()) } =20 fn reset_hold(&self, _type: ResetType) { diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 779681d6509..55eef669a9d 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -724,7 +724,7 @@ fn post_init(&self) { } } =20 - fn realize(&self) { + fn realize(&self) -> qemu_api::Result<()> { if self.int_route_cap =3D=3D 0 { // TODO: Add error binding: warn_report() println!("Hpet's hpet-intcap property not initialized"); @@ -751,6 +751,7 @@ fn realize(&self) { =20 self.init_gpio_in(2, HPETState::handle_legacy_irq); self.init_gpio_out(from_ref(&self.pit_enabled)); + Ok(()) } =20 fn reset_hold(&self, _type: ResetType) { @@ -1042,7 +1043,7 @@ fn vmsd() -> Option<&'static VMStateDescription> { Some(&VMSTATE_HPET) } =20 - const REALIZE: Option =3D Some(Self::realize); + const REALIZE: Option qemu_api::Result<()>> =3D Some(Self= ::realize); } =20 impl ResettablePhasesImpl for HPETState { diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 1279d7a58d5..81052097071 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -12,10 +12,11 @@ pub use bindings::{ClockEvent, DeviceClass, Property, ResetType}; =20 use crate::{ - bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, Error, Resetta= bleClass}, + bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClas= s}, callbacks::FnCall, cell::{bql_locked, Opaque}, chardev::Chardev, + error::{Error, Result}, irq::InterruptSource, prelude::*, qom::{ObjectClass, ObjectImpl, Owned}, @@ -108,7 +109,7 @@ pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl= + IsA { /// /// If not `None`, the parent class's `realize` method is overridden /// with the function pointed to by `REALIZE`. - const REALIZE: Option =3D None; + const REALIZE: Option Result<()>> =3D None; =20 /// An array providing the properties that the user can set on the /// device. Not a `const` because referencing statics in constants @@ -134,10 +135,11 @@ fn vmsd() -> Option<&'static VMStateDescription> { /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_realize_fn( dev: *mut bindings::DeviceState, - _errp: *mut *mut Error, + errp: *mut *mut bindings::Error, ) { let state =3D NonNull::new(dev).unwrap().cast::(); - T::REALIZE.unwrap()(unsafe { state.as_ref() }); + let result =3D T::REALIZE.unwrap()(unsafe { state.as_ref() }); + unsafe { Error::ok_or_propagate(result, errp); } } =20 unsafe impl InterfaceType for ResettableClass { --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269665; cv=none; d=zohomail.com; s=zohoarc; b=aHa7xGqEcUvAUdC2Yg/K7QKexLV6VUUVv1e9jdVS9fWGQX9UcmaDVqYq+1WP31gpFMl6nO3Y4Vo4rHsWlEeIldjS2f8PGI+hsVM4TB4bO13XRbRSEy8QrB3+RGuJ/jk4VZamRdhzKIwkE1bGEu0wFgGmhEW80/2OjrGbhibQOHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269665; 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=HCEM65czXsckVgdrE6Ug61aKfrE1AOpspM5sfXzA4Eg=; b=Sz8R2IIs0AatF7vc+Ir7bQojR75JdRBn/JESY6N5ROuTSph6PCZBw6CuufZyeAGjeIvCpHbviQXCAtchftSjbCXxIyHSyksQEz33Gyj0g0HNP8Evz1MgDd4TEB3ou4c+P1xTOrxmCxieE8sZE8hZ77VBya+Q3EHHLeE+ydorrs0= 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 1748269665355875.162771220759; Mon, 26 May 2025 07:27:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlz-0003Qk-UX; Mon, 26 May 2025 10:25:51 -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 1uJYlg-00032I-Tn for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:35 -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 1uJYld-0007sY-8B for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:32 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-JUpGXVdRNXeD1KhiecvW8g-1; Mon, 26 May 2025 10:25:20 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a3684a5655so1157634f8f.0 for ; Mon, 26 May 2025 07:25:20 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4d17266d5sm5839842f8f.68.2025.05.26.07.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269522; 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=HCEM65czXsckVgdrE6Ug61aKfrE1AOpspM5sfXzA4Eg=; b=fvdoCOpMMeqcVt0aTEMKvpPF7U0zlsrj0Zq49VQsDyqCIvsOcysfc2wjXIuWJijmDQ64e8 PKv/r+bg+NSpbyIlLLojgOsN+MBbUnIC9lc4gExzIZqkhE/CpDlu2Q5qkzsZTn63aKS+8u 1+4GJ3XCClFo19yfdJ0vsKVvM8ahFLo= X-MC-Unique: JUpGXVdRNXeD1KhiecvW8g-1 X-Mimecast-MFC-AGG-ID: JUpGXVdRNXeD1KhiecvW8g_1748269519 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269518; x=1748874318; 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=HCEM65czXsckVgdrE6Ug61aKfrE1AOpspM5sfXzA4Eg=; b=iV6+ndSg3mvwSk1UKLahTWC8LFg+WRMbAa8ffKOWQbEdGvKqK36d1NT6CafClZlQhO iXkOgfWJOr9zw+49J5MRbdU7bv8dXvDrLV28oyirhyFxoX/mEMFT8FtCK1V8XmEhchXC CgP5MW3LGA449iPF/Q1hDcogbtjcLk0zalYrY3yPc06jdxxal7eLie3UY4ykMmSCfqzV FJW2VJcozW6MjIoEVXnl7hhvRWD9Uj4ZvcDlPI12lFTXhnZbpJo2KQZzpRf2kBvMnJTZ VPt6p9flVhfHFx6SNEFWmofXmBT/hSj735HUgVpCF9nP0L0cHQHBel1kleyuEUvYR6P5 nlLA== X-Gm-Message-State: AOJu0YyUXgMeZdpUhcjw02tMUdpynTBG7AsGhRjSNs4leL6pcQe1ypJI VbVQUcgbh84Sa6qRYfIpMKAulj8whOti1XF3wOV9l0F+qVKmfkKxqihWEHn2yyNkgLIojpKxHdO /OT/Lm8UMFVAklzymq+Dma4iNQ/LDieBW/AIkQUKwzn/vrUnbLs7oET+IhfJ0+6VqWwiW0QHSGE 6nbVykSymQAAAPbCXrJApaTPkYgUD0NiNrHLSc0QMb X-Gm-Gg: ASbGnctITWz3v/6a5fC1aXFiei+8X1+BPrc6KUgjBQN9TG2mqetd5vFDp+WvdE2Wqf0 yb198XNgKLOfvrUoQ8LQFR+YQ2OUfP2rhCWbz8iSDxiAbKze4uqS5CvYS+nyC5niOfoJZ3+6kSu 7Ozbhcb69HEQfVT+n9SO1cK7GhPf6dqjiCqrSmLf+3vBKjull0eWsCeWsg+cax+iHl9ld54Fd4r HsPvuFAfdVNr2xaJS/EO366xL0X8BzBnKzxful4/L/60uTcFYxKUayG0gkk/RJl3SvXJeJbzaQL P5R78GBeELrDwQ== X-Received: by 2002:a05:6000:1a8e:b0:3a4:dff9:e67b with SMTP id ffacd0b85a97d-3a4dff9eafdmr152711f8f.17.1748269518295; Mon, 26 May 2025 07:25:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfbkehU3U+JeAZrdXdqbUjc3P++wGhCp/PpO1sFeZI7F63McqrK5ViP7tyi7bcpCsSTqZaRA== X-Received: by 2002:a05:6000:1a8e:b0:3a4:dff9:e67b with SMTP id ffacd0b85a97d-3a4dff9eafdmr152688f8f.17.1748269517799; Mon, 26 May 2025 07:25:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 09/12] rust/hpet: change timer of num_timers to usize Date: Mon, 26 May 2025 16:24:52 +0200 Message-ID: <20250526142455.1061519-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269666162116600 Content-Type: text/plain; charset="utf-8" Remove the need to convert after every read of the BqlCell. Because the vmstate uses a u8 as the size of the VARRAY, this requires switching the VARRAY to use num_timers_save; which in turn requires ensuring that the num_timers_save is always there. For simplicity do this by removing support for version 1, which QEMU has not been producing for ~15 years. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/timer/hpet/src/hpet.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 55eef669a9d..b2922e6a843 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -12,7 +12,7 @@ use qemu_api::{ bindings::{ address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_pr= op_bool, - qdev_prop_uint32, qdev_prop_uint8, + qdev_prop_uint32, qdev_prop_usize, }, cell::{BqlCell, BqlRefCell}, irq::InterruptSource, @@ -36,9 +36,9 @@ const HPET_REG_SPACE_LEN: u64 =3D 0x400; // 1024 bytes =20 /// Minimum recommended hardware implementation. -const HPET_MIN_TIMERS: u8 =3D 3; +const HPET_MIN_TIMERS: usize =3D 3; /// Maximum timers in each timer block. -const HPET_MAX_TIMERS: u8 =3D 32; +const HPET_MAX_TIMERS: usize =3D 32; =20 /// Flags that HPETState.flags supports. const HPET_FLAG_MSI_SUPPORT_SHIFT: usize =3D 0; @@ -561,8 +561,8 @@ pub struct HPETState { =20 /// HPET timer array managed by this timer block. #[doc(alias =3D "timer")] - timers: [BqlRefCell; HPET_MAX_TIMERS as usize], - num_timers: BqlCell, + timers: [BqlRefCell; HPET_MAX_TIMERS], + num_timers: BqlCell, num_timers_save: BqlCell, =20 /// Instance id (HPET timer block ID). @@ -572,7 +572,7 @@ pub struct HPETState { impl HPETState { // Get num_timers with `usize` type, which is useful to play with arra= y index. fn get_num_timers(&self) -> usize { - self.num_timers.get().into() + self.num_timers.get() } =20 const fn has_msi_flag(&self) -> bool { @@ -854,7 +854,7 @@ fn pre_save(&self) -> i32 { * also added to the migration stream. Check that it matches the = value * that was configured. */ - self.num_timers_save.set(self.num_timers.get()); + self.num_timers_save.set(self.num_timers.get() as u8); 0 } =20 @@ -884,7 +884,7 @@ fn is_offset_needed(&self) -> bool { } =20 fn validate_num_timers(&self, _version_id: u8) -> bool { - self.num_timers.get() =3D=3D self.num_timers_save.get() + self.num_timers.get() =3D=3D self.num_timers_save.get().into() } } =20 @@ -911,7 +911,7 @@ impl ObjectImpl for HPETState { c"timers", HPETState, num_timers, - unsafe { &qdev_prop_uint8 }, + unsafe { &qdev_prop_usize }, u8, default =3D HPET_MIN_TIMERS ), @@ -1016,16 +1016,16 @@ impl ObjectImpl for HPETState { static VMSTATE_HPET: VMStateDescription =3D VMStateDescription { name: c"hpet".as_ptr(), version_id: 2, - minimum_version_id: 1, + minimum_version_id: 2, pre_save: Some(hpet_pre_save), post_load: Some(hpet_post_load), fields: vmstate_fields! { vmstate_of!(HPETState, config), vmstate_of!(HPETState, int_status), vmstate_of!(HPETState, counter), - vmstate_of!(HPETState, num_timers_save).with_version_id(2), + vmstate_of!(HPETState, num_timers_save), vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::vali= date_num_timers), - vmstate_struct!(HPETState, timers[0 .. num_timers], &VMSTATE_HPET_= TIMER, BqlRefCell, HPETState::validate_num_timers).with_version_= id(0), + vmstate_struct!(HPETState, timers[0 .. num_timers_save], &VMSTATE_= HPET_TIMER, BqlRefCell, HPETState::validate_num_timers).with_ver= sion_id(0), }, subsections: vmstate_subsections! { VMSTATE_HPET_RTC_IRQ_LEVEL, --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269601; cv=none; d=zohomail.com; s=zohoarc; b=FXaJNpxQuiV8pPKLwYxdK9cRd6kPq67uj6y5f2tP7laowcYstkSA6k5zES2qGELCUQjkyr1t6aUSM2Sfa63Ox1WXbjvbmy/UuwGskSDk7jRAJEjKRpT0twQqQbK2QCYCpzAdbILFvBzK+s9Ra3+kvoo4BOy6FgUPCehoVDU0M7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269601; 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=QvZyFdDkuLWp6FY5Epn837HgIKSyXbzfGWIif8TNWJE=; b=hQOnctLo/iwHiMSI4lKBfw1x03vUgODS+9qZao3Cf7HeQyAOg0aSgGWsgsQMpxaHrGbPVKX+Z4WqBpRhF4I1RnDNsPmeSDvsGwybeF2f4YAJW1o6G1SyIrLWQUcfI+dNTZlTpqQA0VkhdUr3M9B86AmL/Au/o7snG7BLTOaVqr4= 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 1748269601029993.1386375514345; Mon, 26 May 2025 07:26:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYly-0003OG-FB; Mon, 26 May 2025 10:25:50 -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 1uJYlg-00032H-TT for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:35 -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 1uJYld-0007sg-7g for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:31 -0400 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-346-ZwVFfIeYMlC-YfQGc-PDrg-1; Mon, 26 May 2025 10:25:21 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-441c122fa56so11217445e9.2 for ; Mon, 26 May 2025 07:25:21 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442ebd6fe86sm321161945e9.0.2025.05.26.07.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269523; 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=QvZyFdDkuLWp6FY5Epn837HgIKSyXbzfGWIif8TNWJE=; b=EO6yadI5ENJIIir5ihQmhQxdTOfM2RtKXOhX5CTWgxQSgoEUrwfo+vGjKa3UkZaFCRyjHb 3AXv3N+tKtEfC7s4p7LfjsE2Idc3E36nZLE15Ku1lo/Q/jxMRRNllCOtWQrQMP5+JEFLfD +AagCMcdKbsD7QPsoJzqbWG9KerVJXU= X-MC-Unique: ZwVFfIeYMlC-YfQGc-PDrg-1 X-Mimecast-MFC-AGG-ID: ZwVFfIeYMlC-YfQGc-PDrg_1748269520 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269519; x=1748874319; 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=QvZyFdDkuLWp6FY5Epn837HgIKSyXbzfGWIif8TNWJE=; b=BbldnEMfkvOrP/VGgt5iFgrP23b6+jRGRIHHVygCdE7/olcmIfSSpgdpAa5bUA5UPB QkluydlNQI1bQRvDCniAe1x2n1smwPQqz06bT1kAh0TlMoO25lFDAxYc7iimYXhrnZW6 eQAmAgjCkdffag5Mvc4mMrRJUVlWmeLo6Le2PUDtXE/Ir11kJE+Cfon1M8Cus3uTpn2/ Z6ZJ5dsrB3RFkPTQAq505G5a10Zft2qjuQySBdYvwfcyT64tJHbtjZ8ZtUAGbghBP5BF +YSFxguXzgRtPakjFvAYny2reBDlC/Hol6qmi0j0u0NHv+hKF/ZBRyYDFLj0UrtF6z+K Mwfw== X-Gm-Message-State: AOJu0Yzr0CHLP+Q6ypgEg13Y+lpBMszwOtvDtpRhXLTj8qqYVJT6lOAV vuLtgRrASxLmL15L/w5+03pyBMVqDzwcamQYCaA+PaGdNpalaw6YuFAPPIKpupPdfNzp7BKfl8h 4+sCYpfyvIuiFwHr9TOnksETA7ozQIkkJ7ilV6YkNQ34Skydd3vs+MrQ8XfuApmIsYgA+/iGYxA mzSobM20P+hB8j5EqHj3ioG0grkKm8ChgbJ3Q/Rtyv X-Gm-Gg: ASbGncumjwseceeAbAMxgX2JrgOdhvKhhocMBWOmw0YMmXgH5sFGhDSB8kKSxcgsG7h CsjxO6v/ACf8q2Wgqusby+bpSOSrSzjQw3WGg67V/ff6xVnrBuUZ2zUxcaHuAaG6YlJ9HoO2bJS vixcJAomb5k2Sw6XP0pW1+3uI3QmZ5pbsp1h//K6VO30qCnNF5XiFN8cwbzGzOtGZC5xkno7RqN Lejz76IEVd/NwYbmG7o/W/8zwlByCWBeLlwNapdChdpIJ1Hw2jjK5xX/jKc9S/h6+TxYPs9sQwX QIX0igLVSPMEDg== X-Received: by 2002:a5d:4b0a:0:b0:3a4:d0c7:3129 with SMTP id ffacd0b85a97d-3a4d0c73965mr5407731f8f.14.1748269519348; Mon, 26 May 2025 07:25:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDeFahvOPqy2waJ/Pycb38J675xYr5da0aKZ9K1bKkU48AJTjv4Abz7rBZUhS7IgDqU9MYrg== X-Received: by 2002:a5d:4b0a:0:b0:3a4:d0c7:3129 with SMTP id ffacd0b85a97d-3a4d0c73965mr5407699f8f.14.1748269518921; Mon, 26 May 2025 07:25:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 10/12] hpet: return errors from realize if properties are incorrect Date: Mon, 26 May 2025 16:24:53 +0200 Message-ID: <20250526142455.1061519-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269603151116600 Content-Type: text/plain; charset="utf-8" Do not silently adjust num_timers, and fail if intcap is 0. Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster Reviewed-by: Zhao Liu --- hw/timer/hpet.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index d1b7bc52b7b..d78aba04bcd 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -689,8 +689,14 @@ static void hpet_realize(DeviceState *dev, Error **err= p) int i; HPETTimer *timer; =20 + if (s->num_timers < HPET_MIN_TIMERS || s->num_timers > HPET_MAX_TIMERS= ) { + error_setg(errp, "hpet.num_timers must be between %d and %d", + HPET_MIN_TIMERS, HPET_MAX_TIMERS); + return; + } if (!s->intcap) { - warn_report("Hpet's intcap not initialized"); + error_setg(errp, "hpet.hpet-intcap not initialized"); + return; } if (hpet_fw_cfg.count =3D=3D UINT8_MAX) { /* first instance */ @@ -698,7 +704,7 @@ static void hpet_realize(DeviceState *dev, Error **errp) } =20 if (hpet_fw_cfg.count =3D=3D 8) { - error_setg(errp, "Only 8 instances of HPET is allowed"); + error_setg(errp, "Only 8 instances of HPET are allowed"); return; } =20 @@ -708,11 +714,6 @@ static void hpet_realize(DeviceState *dev, Error **err= p) sysbus_init_irq(sbd, &s->irqs[i]); } =20 - if (s->num_timers < HPET_MIN_TIMERS) { - s->num_timers =3D HPET_MIN_TIMERS; - } else if (s->num_timers > HPET_MAX_TIMERS) { - s->num_timers =3D HPET_MAX_TIMERS; - } for (i =3D 0; i < HPET_MAX_TIMERS; i++) { timer =3D &s->timer[i]; timer->qemu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, hpet_timer,= timer); --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269688; cv=none; d=zohomail.com; s=zohoarc; b=limzUjm4z0BHgBScK8FW1UHWGZRF3eVLvyu6LdybPJ2y6ExZLcHHTJaG7OgjJFgcssCnJMUhFg1xMh/I5/RRtDS4vf8EAaD6RfC2owoQq0KZ26RjwdoI/Md6xG8DRc3E1jq2QJ5fOf8BNJBYt4rmEp5LvnFzD3dp2HLqIQTLJWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269688; 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=Pxg/98qXOCGxIS0+0C2ldwJ8rlIMJBaj9BLbfUFLby0=; b=O7o5VGtSe9C2o+avidPsG4/12yEZcL8YAcBIHqrFfTPEO5d3vG4ju+3au+U9FsN8iu81HJOj9AHeiamcGcNGRKc0RAbC6/ONEQ/n5Aj5bc8IVxsIFPxV1HsGXDNWLHOe5LBLO52hEyHgy5yTpDZ9vO6n+KBmNsQl+CaqyqtKWV8= 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 1748269688718676.4891947071425; Mon, 26 May 2025 07:28:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYly-0003Nk-5m; Mon, 26 May 2025 10:25:50 -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 1uJYlg-00032F-Sm for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:35 -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 1uJYld-0007sr-7g for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:32 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-Go63gHU8MWevR3JQbeKaaA-1; Mon, 26 May 2025 10:25:24 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43d0830c3f7so18158175e9.2 for ; Mon, 26 May 2025 07:25:24 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f23c07bfsm240131505e9.23.2025.05.26.07.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269526; 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=Pxg/98qXOCGxIS0+0C2ldwJ8rlIMJBaj9BLbfUFLby0=; b=S6AliX4ccYfLyGdFeO/m+LurwBNdGCx0dkPeHjrDyqUDDeB+JyGiD9ayrmZfmjaEo4Abut fbjQWOvPGRzQO4pU2PS20Huk4jAO45hb2U3H6j+jN8jHp+nPTKyNpwaq1pWICG+kS/ov6+ aiwlcXbqLqShp1+32RMLhbrR6MoVj1s= X-MC-Unique: Go63gHU8MWevR3JQbeKaaA-1 X-Mimecast-MFC-AGG-ID: Go63gHU8MWevR3JQbeKaaA_1748269523 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269522; x=1748874322; 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=Pxg/98qXOCGxIS0+0C2ldwJ8rlIMJBaj9BLbfUFLby0=; b=tsnpK2dpuUygzW16njekbhcjCYxY0ve24ps8jsYeCEIUdMtLWL0temvQ/TL71dM4+l zUysYKnuo/MdzPzPnL3s5Xa77vnHiEuI3vFlM1oORWc+bmbcY9P7tzfqJD1phVLbgLhj SgW+W/ZlQ/ck4+EF1WYA3iLarzA3wySKppK7mpe2PaIBXHZRutantOoh909upbvYwgdp WzxDYMJgSw7qT5RQ/AZDYd/FHtLpmslTvJRjoRaBgTgFEjnjcq6AQJWVF03dxzXoTl2x 8NqaNcVwIe7br2dsmTWSjs9QrMZV2gdIiwnkIRRa91q+uEA4jFw7pDNvvRu0zFgKDihd 32CQ== X-Gm-Message-State: AOJu0Yx2HxFVHNpv0e6+y8ltH23kAFGS8KXWFvjiLAsm9a7e8L9EiqTW 8SNJH8z9RIVOIRYdNSN1NVbi2MwBWOCj8qy08+WNA7JnkIth0SUaoIJ9XucCT87fGANfgbAhd/p sTo8YuMPWVC9ZDbhzr0ZvZqnlNEk/CDQ55I7vOdDgYCJJP7g9bCkvtTtlMEH6tPb+s4joAh/tBM xKdDeccUuwP1R/buzqOo5CLXXClVKTAj00kTscL/BX X-Gm-Gg: ASbGnctv2xMc0WW2EqB5kmMaSQqYmCZEs7d62u0p2fulXWaHiIN1CrVhQeVm9BMg3+t YmbB5lJ2MyScWJAnhFS/MWMPwWlRhAdtmCwnv1B2IOrlhG14HizXoWrt/59j9dB7sEwYaBoQJtJ Dx6s7TTjMCu0+jh7N1IY8LBWxEV3hyrp/SsPxsYRuZv+LV+b+SCg2rzpKOOuWgjxEH0dGpE0Sus aGhDmsajGcDvQPiE0nvcH3Q8r74VFQYBT3qjZmG11H8uAErj/DRJbnNUM4tEYoO5b6bg5geyY6G toBdQsN0rMMnQA== X-Received: by 2002:a05:600c:1d96:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-44c916071a2mr91336805e9.4.1748269522513; Mon, 26 May 2025 07:25:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvUK5+9C/DNRU1XFsc4kPWYhQfHijzyszKQNaKq7ieOf3QPlYdJXcmWbEEwWdBGsy8k7wHqA== X-Received: by 2002:a05:600c:1d96:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-44c916071a2mr91336465e9.4.1748269522016; Mon, 26 May 2025 07:25:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org Subject: [PATCH 11/12] rust/hpet: return errors from realize if properties are incorrect Date: Mon, 26 May 2025 16:24:54 +0200 Message-ID: <20250526142455.1061519-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748269690106116600 Content-Type: text/plain; charset="utf-8" Match the code in hpet.c; this also allows removing the BqlCell from the num_timers field. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/timer/hpet/src/fw_cfg.rs | 7 +++---- rust/hw/timer/hpet/src/hpet.rs | 16 +++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/rust/hw/timer/hpet/src/fw_cfg.rs b/rust/hw/timer/hpet/src/fw_c= fg.rs index aa08d283519..140692062cd 100644 --- a/rust/hw/timer/hpet/src/fw_cfg.rs +++ b/rust/hw/timer/hpet/src/fw_cfg.rs @@ -36,7 +36,7 @@ unsafe impl Zeroable for HPETFwConfig {} }; =20 impl HPETFwConfig { - pub(crate) fn assign_hpet_id() -> usize { + pub(crate) fn assign_hpet_id() -> Result { assert!(bql_locked()); // SAFETY: all accesses go through these methods, which guarantee // that the accesses are protected by the BQL. @@ -48,13 +48,12 @@ pub(crate) fn assign_hpet_id() -> usize { } =20 if fw_cfg.count =3D=3D 8 { - // TODO: Add error binding: error_setg() - panic!("Only 8 instances of HPET is allowed"); + Err("Only 8 instances of HPET are allowed")?; } =20 let id: usize =3D fw_cfg.count.into(); fw_cfg.count +=3D 1; - id + Ok(id) } =20 pub(crate) fn update_hpet_cfg(hpet_id: usize, timer_block_id: u32, add= ress: u64) { diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index b2922e6a843..b298938e4d5 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -725,18 +725,16 @@ fn post_init(&self) { } =20 fn realize(&self) -> qemu_api::Result<()> { + if self.num_timers.get() < HPET_MIN_TIMERS || self.num_timers.get(= ) > HPET_MAX_TIMERS { + Err(format!( + "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HP= ET_MAX_TIMERS}" + ))?; + } if self.int_route_cap =3D=3D 0 { - // TODO: Add error binding: warn_report() - println!("Hpet's hpet-intcap property not initialized"); + Err("hpet.hpet-intcap property not initialized")?; } =20 - self.hpet_id.set(HPETFwConfig::assign_hpet_id()); - - if self.num_timers.get() < HPET_MIN_TIMERS { - self.num_timers.set(HPET_MIN_TIMERS); - } else if self.num_timers.get() > HPET_MAX_TIMERS { - self.num_timers.set(HPET_MAX_TIMERS); - } + self.hpet_id.set(HPETFwConfig::assign_hpet_id()?); =20 self.init_timer(); // 64-bit General Capabilities and ID Register; LegacyReplacementR= oute. --=20 2.49.0 From nobody Sat Nov 15 17:44:06 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=1748269652; cv=none; d=zohomail.com; s=zohoarc; b=ERnCLYXJzci4XxJoYWjpl/BbHLZALyn+SvOrSBUKZjRq9Y2+3rXbztJl3ym4c2A7sBLynPZGBO1Lz3wKamCqiNdL+CscByqE2Bifp7fN7KLFnBClJcd9+b69GQCbu0F0C10XIvZt01dTpJITS/v3tE2AmVtAULGj1WD+6rm+Xsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748269652; 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=e7XL373PGEgSsSjnf8t+unv02/Oh406O0MVIcACVlRA=; b=irAaeMZ9/ElyQ6gdXly5KyoP9jJilfFiN11R1KA2JbF6tp3vtUlY5vfkPuZ+O5Yi+zbCfznH4mkNjDVwsk2O1Qjxcvbsn8eKosK58EFDbpUuTzcFuWuxV1d5PmySMTynmjkJvcKTgv222Cg9+wXrmfDzUfpWfutKtfXwLObvwxk= 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 1748269652510309.42140712875664; Mon, 26 May 2025 07:27:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJYlv-0003In-RR; Mon, 26 May 2025 10:25:47 -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 1uJYli-00032O-5N for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:35 -0400 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 1uJYld-0007t2-Az for qemu-devel@nongnu.org; Mon, 26 May 2025 10:25:33 -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-113-cbvXHzz7P5-WRdaqsSN2lw-1; Mon, 26 May 2025 10:25:27 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-440667e7f92so12162365e9.3 for ; Mon, 26 May 2025 07:25:27 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4cf7aa715sm7003240f8f.35.2025.05.26.07.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269528; 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=e7XL373PGEgSsSjnf8t+unv02/Oh406O0MVIcACVlRA=; b=Cb36HSbzx5/NA4+vu3ikk43p/STfhehT0n1n+ScBIIEgTTKauGf9G2qGuCLHyRm2FhDdA4 JetoN29sRvPE7pQ/qnrQh98IGkevmjEjgWu/7fGI9l+JA8e209fGwq4EUWbpRpuz1/c1uQ efg1VgDfiZkgvlgU3RWx/qBS+BcWmsQ= X-MC-Unique: cbvXHzz7P5-WRdaqsSN2lw-1 X-Mimecast-MFC-AGG-ID: cbvXHzz7P5-WRdaqsSN2lw_1748269526 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269525; x=1748874325; 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=e7XL373PGEgSsSjnf8t+unv02/Oh406O0MVIcACVlRA=; b=anVYh5QOFhOzQa9H/68KHChwYYMExnq5gNUGbgOqDhFsem7lfOkrxvwj26iuqHwZW1 LJig5Q9mnkE32Wg1VC+21wn+4p/AmuWJ5wEoXd8EfkCOI5vo5Fgf3o1jc7ZMT6bF/Li7 cwPmVDspH5CLpa9gw9Oiomyd6ZZYUZNo6tj23yUZcwuT0tXMDyJXK7gh3Z4vls+ZoE6p 8dfiFEL35DIeTGPSEORHdnGohqnbHlq+HlV9AfK/GLq8LG+LcxaidMvrwwMv7++OEsMH AjwJCogckkwiaKwTqArTnL0f/tlLSkd1yXTg+r7QX12yyxem5dux7REhBES/0cBPLLF4 J+KA== X-Gm-Message-State: AOJu0Ywe5QOstX2NtDMGoc3WHfFzrrMrMBFKDLFnuzXQ6yz3774EP00U z+AkaZdN33XWji61HWhVd58q1v5CjCPoKNeE+UNuNVKZgRWNo2TpeiGnVuGrO8JbkMxIOQQMQcs Bfl25cQDPmPURfPXCS61ZGEbY0bBWPM19m0qh3zh0+wb+OIh+JaiYYr2cK8yQ5tbUrFbAXeB+Zk JoXHlzEluFsr2zFxM3CvVD2CojvEn4q3rd02O9T/Ff X-Gm-Gg: ASbGncugwLE8Je8QCEqngqIU+Qnvv5/aJG3Aice0vEODKK/xt8cuT+6vNZvZU/Mu8Fb +sz89CZ9kAvCiXMkJTDpz0a4XGvvcQlNBahwc/jKtKpiQ08SGh0x5jyuBkiZVhnOCjQVMBzh62S z0phqLt3quKh/pNOZXYTpUhfqtCNR1jSyODxdD83sXt1QXcaKApg8ZtBdNn18iJ5DKI9zS29QyS tNmlxms2vEzp+c/fDkJEt/NQOvakiADlmuPo/EZSoFHC4TeBQbTuhnpiQ1quCMM5PLFKbviOvH1 BSgUc/kc7MhBkA== X-Received: by 2002:a05:600c:34ca:b0:441:b076:fce8 with SMTP id 5b1f17b1804b1-44c91ad7026mr86946275e9.14.1748269525415; Mon, 26 May 2025 07:25:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzoBz7wkVpIO4pdjuOW8qCuI7xCcvhjjqVOMYzJbqIs93+muKPKEJSTXNKX00Yti2oLT4ENw== X-Received: by 2002:a05:600c:34ca:b0:441:b076:fce8 with SMTP id 5b1f17b1804b1-44c91ad7026mr86945865e9.14.1748269524870; Mon, 26 May 2025 07:25:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 12/12] rust/hpet: Drop BqlCell wrapper for num_timers Date: Mon, 26 May 2025 16:24:55 +0200 Message-ID: <20250526142455.1061519-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250526142254.1061009-1-pbonzini@redhat.com> References: <20250526142254.1061009-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.903, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748269653884116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Now that the num_timers field is initialized as a property, someone may change its default value using qdev_prop_set_uint8(), but the value is fixed after the Rust code sees it first. Since there is no need to modify it after realize(), it is not to be necessary to have a BqlCell wrapper. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250520152750.2542612-4-zhao1.liu@intel.com [Remove .into() as well. - Paolo] Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/timer/hpet/src/hpet.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index b298938e4d5..3c5c65ff47d 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -562,7 +562,7 @@ pub struct HPETState { /// HPET timer array managed by this timer block. #[doc(alias =3D "timer")] timers: [BqlRefCell; HPET_MAX_TIMERS], - num_timers: BqlCell, + num_timers: usize, num_timers_save: BqlCell, =20 /// Instance id (HPET timer block ID). @@ -570,11 +570,6 @@ pub struct HPETState { } =20 impl HPETState { - // Get num_timers with `usize` type, which is useful to play with arra= y index. - fn get_num_timers(&self) -> usize { - self.num_timers.get() - } - const fn has_msi_flag(&self) -> bool { self.flags & (1 << HPET_FLAG_MSI_SUPPORT_SHIFT) !=3D 0 } @@ -636,7 +631,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) { self.hpet_offset .set(ticks_to_ns(self.counter.get()) - CLOCK_VIRTUAL.get_n= s()); =20 - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { let mut t =3D timer.borrow_mut(); =20 if t.is_int_enabled() && t.is_int_active() { @@ -648,7 +643,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) { // Halt main counter and disable interrupt generation. self.counter.set(self.get_ticks()); =20 - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { timer.borrow_mut().del_timer(); } } @@ -671,7 +666,7 @@ fn set_int_status_reg(&self, shift: u32, _len: u32, val= : u64) { let new_val =3D val << shift; let cleared =3D new_val & self.int_status.get(); =20 - for (index, timer) in self.timers.iter().take(self.get_num_timers(= )).enumerate() { + for (index, timer) in self.timers.iter().take(self.num_timers).enu= merate() { if cleared & (1 << index) !=3D 0 { timer.borrow_mut().update_irq(false); } @@ -725,7 +720,7 @@ fn post_init(&self) { } =20 fn realize(&self) -> qemu_api::Result<()> { - if self.num_timers.get() < HPET_MIN_TIMERS || self.num_timers.get(= ) > HPET_MAX_TIMERS { + if self.num_timers < HPET_MIN_TIMERS || self.num_timers > HPET_MAX= _TIMERS { Err(format!( "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HP= ET_MAX_TIMERS}" ))?; @@ -743,7 +738,7 @@ fn realize(&self) -> qemu_api::Result<()> { 1 << HPET_CAP_COUNT_SIZE_CAP_SHIFT | 1 << HPET_CAP_LEG_RT_CAP_SHIFT | HPET_CAP_VENDER_ID_VALUE << HPET_CAP_VENDER_ID_SHIFT | - ((self.get_num_timers() - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT= | // indicate the last timer + ((self.num_timers - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT | // = indicate the last timer (HPET_CLK_PERIOD * FS_PER_NS) << HPET_CAP_CNT_CLK_PERIOD_SHIFT= , // 10 ns ); =20 @@ -753,7 +748,7 @@ fn realize(&self) -> qemu_api::Result<()> { } =20 fn reset_hold(&self, _type: ResetType) { - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { timer.borrow_mut().reset(); } =20 @@ -781,7 +776,7 @@ fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAd= drDecode { GlobalRegister::try_from(addr).map(HPETRegister::Global) } else { let timer_id: usize =3D ((addr - 0x100) / 0x20) as usize; - if timer_id <=3D self.get_num_timers() { + if timer_id < self.num_timers { // TODO: Add trace point - trace_hpet_ram_[read|write]_tim= er_id(timer_id) TimerRegister::try_from(addr & 0x18) .map(|reg| HPETRegister::Timer(&self.timers[timer_id],= reg)) @@ -852,12 +847,12 @@ fn pre_save(&self) -> i32 { * also added to the migration stream. Check that it matches the = value * that was configured. */ - self.num_timers_save.set(self.num_timers.get() as u8); + self.num_timers_save.set(self.num_timers as u8); 0 } =20 fn post_load(&self, _version_id: u8) -> i32 { - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { let mut t =3D timer.borrow_mut(); =20 t.cmp64 =3D t.calculate_cmp64(t.get_state().counter.get(), t.c= mp); @@ -882,7 +877,7 @@ fn is_offset_needed(&self) -> bool { } =20 fn validate_num_timers(&self, _version_id: u8) -> bool { - self.num_timers.get() =3D=3D self.num_timers_save.get().into() + self.num_timers =3D=3D self.num_timers_save.get().into() } } =20 --=20 2.49.0