From patchwork Mon Oct 21 16:35:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F23AD15DBA for ; Mon, 21 Oct 2024 16:36:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vNo-0005rM-IC; Mon, 21 Oct 2024 12:35:52 -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 1t2vNm-0005pQ-Qn for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:35:50 -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 1t2vNl-0006H6-DN for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:35:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528548; 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=QgNTM++YIgCcMVNRZLJ+GHrP659GMVVlwBbB2mHseDc=; b=aM6zRzpALTl2GzndK30rci4luqaGZ0PTPmiPpw0h/6GGSO8BhWTLAfI1Jsub4WstbYH29g 6WktRDcSGDFxgTci2olWRImg8zgzEU1u8hOMZi4zskuosNioGoaq8XLwNv65RxVg/cygI6 QkpbiGZcptJ2SUG8gmpp6oXZJ+O+JA4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-52-CmK8tIxjNW2TpSf28P-6Sg-1; Mon, 21 Oct 2024 12:35:47 -0400 X-MC-Unique: CmK8tIxjNW2TpSf28P-6Sg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so36829705e9.1 for ; Mon, 21 Oct 2024 09:35:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528545; x=1730133345; 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=QgNTM++YIgCcMVNRZLJ+GHrP659GMVVlwBbB2mHseDc=; b=hrcOb0WGBxdj8CqZMMrM6XXqvXKC0le1BVOLbPlMqRpBrrxniKAwC690JqInUAiaXR kVJitZH2V8rXRIzVkRfuLmYbBUreuEasWbONzbbOEl2I2S28a7qDw12NvZS1Lnoo9WjY xfVaIvCt4JNldtNAk3NR88cDbojc3poW6WRm/Qi4/V+2oMcN/pLq31YEHAeBhYJb2Srl 2AUYZ/IDGk/FxGow1yU/7DLsmdQrPl80mjOJa2oLwgQz7lrs2D+V9vccGKG9bDnTbGo3 6d6scQddGHGu5NjEk3n314fBQUNjQgoAKWxpT6Crs63xg6MPcx7KTsRFyx1fiojyz+K0 uoEw== X-Gm-Message-State: AOJu0YyWzsLxgEYWORdNUFqlgW0knZ14pbePBSB5Dqy/18BQy+89SM0Y i8qTxDkPFor0yQ0U85wtX2gqApeClA+OV8cBZSMQqykwZ31PnRXybIjRR+86QzVSgwWTmHw25sv V4A2Ki6rMwesdcTR6jN2/nhX0Z85S3gkQkahyC24Pj8GmH7eyjunaYa1TgUBcAQaOFNrPQZKzJA 3fQQxKb6+AVkqwFolAzUg7RQN+ALcTauc43zckHkQ= X-Received: by 2002:a05:600c:4f92:b0:431:557e:b40c with SMTP id 5b1f17b1804b1-43161686a3fmr117308245e9.27.1729528545251; Mon, 21 Oct 2024 09:35:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtO1iqb6KRvjMiC8dB0Rk81DkMIeot/0voDENG6HbftMXggPeZAB/BRJKdwJOmrXxiaPcYGg== X-Received: by 2002:a05:600c:4f92:b0:431:557e:b40c with SMTP id 5b1f17b1804b1-43161686a3fmr117307955e9.27.1729528544699; Mon, 21 Oct 2024 09:35:44 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5c3497sm62752035e9.29.2024.10.21.09.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:35:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao , Zhao Liu Subject: [PATCH v2 01/13] meson: import rust module into a global variable Date: Mon, 21 Oct 2024 18:35:26 +0200 Message-ID: <20241021163538.136941-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini Tested-by: Manos Pitsidianakis Reviewed-by: Manos Pitsidianakis --- meson.build | 1 + rust/qemu-api-macros/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d26690ce204..ffd78b6cbb3 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ meson.add_postconf_script(find_program('scripts/symlink-install-tree.py')) not_found = dependency('', required: false) keyval = import('keyval') +rust = import('rust') ss = import('sourceset') fs = import('fs') diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.build index 517b9a4d2d5..24325dea5c2 100644 --- a/rust/qemu-api-macros/meson.build +++ b/rust/qemu-api-macros/meson.build @@ -2,7 +2,7 @@ quote_dep = dependency('quote-1-rs', native: true) syn_dep = dependency('syn-2-rs', native: true) proc_macro2_dep = dependency('proc-macro2-1-rs', native: true) -_qemu_api_macros_rs = import('rust').proc_macro( +_qemu_api_macros_rs = rust.proc_macro( 'qemu_api_macros', files('src/lib.rs'), override_options: ['rust_std=2021', 'build.rust_std=2021'], From patchwork Mon Oct 21 16:35:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86838D15DBB for ; Mon, 21 Oct 2024 16:36:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vNr-0005sZ-Hd; Mon, 21 Oct 2024 12:35:55 -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 1t2vNq-0005sH-Qm for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:35:54 -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 1t2vNp-0006He-FN for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:35:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528552; 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=gqjYsCuUkJoDwHJncPx/DyxCaTkPxqR/aZbtwyZZJx4=; b=EHBD2e7Uh/DkNWq7+tQ4Z3C7kgOD5MEuIlIsxWyNHYlILjGzHCmnJPa+L+Gl04605ZVRop ATakBjMy/LMB/CyCP4eiOFA4STSUt9+l1vTHlo706v0Wc9WY4VzpWptSyglfF0e6IvBmXo Zo6MVFUv0JHtFp/rGbohy4joNYqrewQ= 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-208-fbJnxKWBNvmhrWIJ7NG5zQ-1; Mon, 21 Oct 2024 12:35:50 -0400 X-MC-Unique: fbJnxKWBNvmhrWIJ7NG5zQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-431604a3b47so28058025e9.3 for ; Mon, 21 Oct 2024 09:35:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528548; x=1730133348; 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=gqjYsCuUkJoDwHJncPx/DyxCaTkPxqR/aZbtwyZZJx4=; b=OAATNxgmhUhoseuH7/AcTrfVzBdJag6zpPZfATKW3CguQXiGRAFPWsZBZFBgnuLTNz IhT6/Lqlzz1P2OGM4PL///4IeTSwPzONHk43jRiJv6VnquolUCO1ocurvzayvNCCiJBK 2neB0z5k2WDEYkvL2Q5OiLhkI5EyufyIr2ukujs9DmLmYKhRkD0jnqGEJq5iyHRSliL0 KzEidDF6ozSMGMtuPXoDj2xDQfGF4+7PEThP2HXQBaaqsEEjMjn066F6V88vFlCU7Q4o Z6DqRQnBgI2sF49zBdRNj6o/QAuGAb6iico136GZJKLWBf4YSXDagmibAbI0syq4FGgL HQJA== X-Gm-Message-State: AOJu0YwErM+UmrSxXBgfXAiEjwee4pCKVzucOlH9davDA22TMtiFTSfP +m+JBatRexvaSZtYBBS71GwX9oPbeXWR12us5ZM1aGwE/doE2cfB5fT7qTILldmgx4quzAh+IUF BQ2xjmwq7Ayu6fXA09sLiD+t8suP0yGB5Y8KMs5Gr9dG5ayd6pnmfxf2LkAjz6rjK+meYfgRef/ GWaWbstLx6rZesDClU5jYZMT+ofVmCgI+s+rilNsc= X-Received: by 2002:a05:600c:3b16:b0:42f:80f4:ab31 with SMTP id 5b1f17b1804b1-4316163b593mr73368905e9.18.1729528548091; Mon, 21 Oct 2024 09:35:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHDjPQvDyLCeHljoFtnfsvd6Elxa7/XI+Tm9Ec5MZxKqW8MoGMw7UvhebCVmCn2UNtYDRKWg== X-Received: by 2002:a05:600c:3b16:b0:42f:80f4:ab31 with SMTP id 5b1f17b1804b1-4316163b593mr73368705e9.18.1729528547731; Mon, 21 Oct 2024 09:35:47 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58c02csm63226225e9.27.2024.10.21.09.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:35:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao , Zhao Liu Subject: [PATCH v2 02/13] meson: remove repeated search for rust_root_crate.sh Date: Mon, 21 Oct 2024 18:35:27 +0200 Message-ID: <20241021163538.136941-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Avoid repeated lines of the form Program scripts/rust/rust_root_crate.sh found: YES (/home/pbonzini/work/upstream/qemu/scripts/rust/rust_root_crate.sh) in the meson logs. Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index ffd78b6cbb3..f85bc22fbdd 100644 --- a/meson.build +++ b/meson.build @@ -3977,6 +3977,7 @@ endif feature_to_c = find_program('scripts/feature_to_c.py') +rust_root_crate = find_program('scripts/rust/rust_root_crate.sh') if host_os == 'darwin' entitlement = find_program('scripts/entitlement.sh') @@ -4078,7 +4079,7 @@ foreach target : target_dirs if crates.length() > 0 rlib_rs = custom_target('rust_' + target.underscorify() + '.rs', output: 'rust_' + target.underscorify() + '.rs', - command: [find_program('scripts/rust/rust_root_crate.sh')] + crates, + command: [rust_root_crate, crates], capture: true, build_by_default: true, build_always_stale: true) From patchwork Mon Oct 21 16:35:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C23AD15DBB for ; Mon, 21 Oct 2024 16:39:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOy-0006cb-B4; Mon, 21 Oct 2024 12:37:04 -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 1t2vNv-0005uZ-9B for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:02 -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 1t2vNt-0006I8-8A for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:35:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528555; 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=9GT7AM3dNIUTb0glH6Ier4DyJgqZCZmSaW5xm7t2d5c=; b=e/LmQLHxgYPKHwr4mxu3wK62XtOzicj0p8jgJQmfBK0hNkSzcZPyibrUDi31cHnIWhAuEi A41eLc7eavctUFVcSEVUkzcGmZia+X+NdSjnxbTe9+aePgd4gRAH6EpUyt1cnsbK9741BW AWHq9cjH0vOI/HpfncvJP6ficfFHrhs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-7VwXp7kkMZ6K6ACdEL_CNA-1; Mon, 21 Oct 2024 12:35:53 -0400 X-MC-Unique: 7VwXp7kkMZ6K6ACdEL_CNA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-431518ae047so27500045e9.0 for ; Mon, 21 Oct 2024 09:35:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528551; x=1730133351; 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=9GT7AM3dNIUTb0glH6Ier4DyJgqZCZmSaW5xm7t2d5c=; b=tZN48FZSnoq6f2G8CBP3WD3+XCmkftHsuxccsEmYOpWIRwdSsFZ3mJlwjkBm1wteZV cIyp9CHjNHI8/GgxZTxT+2X5E9AB9XKHW9sfX0KrC0P6+DOSdyORAyCM1OW2N8EqOqHu XKfzc1IdaHPqD0iJuyXkCB3BQ9wsTzppM+xDSx/gcypEmAaHbkTvHlFP89JCSjex9vZ5 Xl2wF2IG/LDXIo79kP5zAwGhXxV4vrYmbem5yxEczk2u7C1lvWm23Naip/OaOL+wNDbg 2niu3GCCHaoSKIe0XOoBxlt05qsRxve790yDhPruUgdAjZp399dTe4rK9Iy9brM2113/ R/9A== X-Gm-Message-State: AOJu0YzHIVYmsQJVt37Co4pwsa2UL7qeEZUZ7EOmltR2zcpzkUJJ21xG vACNprNDRi7akhO+Bu9U9u1d6usrOKC2Y8f3yEO7/erxHcvnginEqp9Xe9g3MnaqGHGDkzMHJfR H/Ixewa2BAa5iPvRsqlJ1ZPZ1Edfc1vmObgKLPIIBjiO9XUGQuiRxhDEM0gJ/hN6cs5WwQuprGT T7fRSFh9q+C2ZaKgRmEbiTRqWKtCRfCVUbi9HbyWM= X-Received: by 2002:a05:600c:3590:b0:431:4a82:97f2 with SMTP id 5b1f17b1804b1-4317bd7f68fmr1645255e9.6.1729528551309; Mon, 21 Oct 2024 09:35:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4SLc6xQ1Gv58wzV1GBsiZAYLjnpBGJee1+5HmHNgVb8o94h9FPGT5N+Xcvf56CjVwUR1QHQ== X-Received: by 2002:a05:600c:3590:b0:431:4a82:97f2 with SMTP id 5b1f17b1804b1-4317bd7f68fmr1645095e9.6.1729528550856; Mon, 21 Oct 2024 09:35:50 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5c2c8esm62956805e9.36.2024.10.21.09.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:35:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 03/13] meson: pass rustc_args when building all crates Date: Mon, 21 Oct 2024 18:35:28 +0200 Message-ID: <20241021163538.136941-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org rustc_args is needed to smooth the difference in warnings between the various versions of rustc. Always include those arguments. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu --- meson.build | 20 +++++++++++++------- rust/qemu-api/meson.build | 2 +- rust/qemu-api/src/device_class.rs | 10 ++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index f85bc22fbdd..63c07a5b660 100644 --- a/meson.build +++ b/meson.build @@ -3317,6 +3317,19 @@ endif genh += configure_file(output: 'config-host.h', configuration: config_host_data) +if have_rust and have_system + rustc_args = run_command( + find_program('scripts/rust/rustc_args.py'), + '--config-headers', meson.project_build_root() / 'config-host.h', + capture : true, + check: true).stdout().strip().split() + + # Prohibit code that is forbidden in Rust 2024 + rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] + add_project_arguments(rustc_args, native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') +endif + hxtool = find_program('scripts/hxtool') shaderinclude = find_program('scripts/shaderinclude.py') qapi_gen = find_program('scripts/qapi-gen.py') @@ -3909,12 +3922,6 @@ common_all = static_library('common', dependencies: common_ss.all_dependencies()) if have_rust and have_system - rustc_args = run_command( - find_program('scripts/rust/rustc_args.py'), - '--config-headers', meson.project_build_root() / 'config-host.h', - capture : true, - check: true).stdout().strip().split() - rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', @@ -4087,7 +4094,6 @@ foreach target : target_dirs rlib_rs, dependencies: target_rust.dependencies(), override_options: ['rust_std=2021', 'build.rust_std=2021'], - rust_args: rustc_args, rust_abi: 'c') arch_deps += declare_dependency(link_whole: [rlib]) endif diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index c72d34b607d..42ea815fa5a 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -10,7 +10,7 @@ _qemu_api_rs = static_library( ), override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', - rust_args: rustc_args + [ + rust_args: [ '--cfg', 'MESON', # '--cfg', 'feature="allocator"', ], diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 1ea95beb78d..b6b68cf9ce2 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -16,10 +16,12 @@ macro_rules! device_class_init { ) { let mut dc = ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); - dc.as_mut().realize = $realize_fn; - dc.as_mut().vmsd = &$vmsd; - $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + unsafe { + dc.as_mut().realize = $realize_fn; + dc.as_mut().vmsd = &$vmsd; + $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); + $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + } } }; } From patchwork Mon Oct 21 16:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 998F0D15DBC for ; Mon, 21 Oct 2024 16:37:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOE-00067b-H7; Mon, 21 Oct 2024 12:36:18 -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 1t2vNw-0005un-GM for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:02 -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 1t2vNu-0006IO-W3 for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528557; 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=+VBSGG9/QZnUbOHJ1ZUaj0+mzJGppSH57Y5XCkB20uU=; b=Yk3GtvRLSGY7iZFUV50TFOnDSVheFkVJ/YF3Qln5InL9h023DQ9J1lVWc97ktE5f68NBeM iTjtWeLCTKHPJg5fdNiIDu/JGc41zGWCVwIPpFwidsNWRSUCtW3DBW9Lg77fbpyGDsQUga TYoTihjTT8B2E9ToNHkxnxzL/CJjfIw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-5mxRttA5MCijBc4yZAYxew-1; Mon, 21 Oct 2024 12:35:56 -0400 X-MC-Unique: 5mxRttA5MCijBc4yZAYxew-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43151e4ef43so34583445e9.3 for ; Mon, 21 Oct 2024 09:35:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528555; x=1730133355; 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=+VBSGG9/QZnUbOHJ1ZUaj0+mzJGppSH57Y5XCkB20uU=; b=n3LRHWlr+ZmF2vDLli7A3s9Hk9ZAUGYKn2g2cNoTevwTpWbNnV4nYK0gfABVCPS6uO FVSCp7MqfGXfEMarD1TKAd8AAvOOf0QJY5zdt2qD69sz5HCF/HalK4w5+HDHcvsKMSO9 0UmW9yAw92y+sTnlv4PduY+5mnI1dEUrL4r5qTOYxk8iinzFaKJ+XjKKw0+V0JceE9Th 867pFzMPyX0+nBfMVcA/3dXA/fy27N0g9/pCpXG9MVpxh5E6DWhI/u+6BgnNn8UxmPKD vvmw8VdyhyvTT9dJY3iZ93ajy3jFOv1qWDX6kVuQxzQVehf9rxRyvCXzkEIW0g4z/Aws S4Gw== X-Gm-Message-State: AOJu0YwX+JZwqtWSnxFpBFXrJsnS8o63b0cYEIhhwKi+TmvB4zg+V8OA eRA6bZQbnF+9Gld6M6tUB4g6WoctEXvsGt92E3qKOH+z0jV2mVRopKtv3ApxKw8AJP2R5BaEdU3 dD8Il1/Q61AYNvL9XjQ/oP99M3klSIWZTA/EhiEyNKf2RA53WLunFgdKI1fn7GbZZzo2trAiNpG Ko5h8GyMpB7dF4lk5nS01ps7ZZ3Hpcy9gIqgTgSU8= X-Received: by 2002:a05:600c:5124:b0:431:5bf2:2d4 with SMTP id 5b1f17b1804b1-431616a388cmr100577145e9.29.1729528554862; Mon, 21 Oct 2024 09:35:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIIIJRzkemrUvKk4iyOOzbee7lZKyXOs6e3741YOKlQdEaBc8g+wXmIVejD4MgZgdKWSgxZw== X-Received: by 2002:a05:600c:5124:b0:431:5bf2:2d4 with SMTP id 5b1f17b1804b1-431616a388cmr100576935e9.29.1729528554427; Mon, 21 Oct 2024 09:35:54 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5cc1e2sm63458665e9.42.2024.10.21.09.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:35:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 04/13] rust: do not use --no-size_t-is-usize Date: Mon, 21 Oct 2024 18:35:29 +0200 Message-ID: <20241021163538.136941-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This not necessary and makes it harder to write code that is portable between 32- and 64-bit systems: it adds extra casts even though size_of, align_of or offset_of already return the right type. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu --- meson.build | 1 - rust/qemu-api/src/definitions.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 63c07a5b660..6739165908e 100644 --- a/meson.build +++ b/meson.build @@ -3934,7 +3934,6 @@ if have_rust and have_system '--no-doc-comments', '--use-core', '--with-derive-default', - '--no-size_t-is-usize', '--no-layout-tests', '--no-prepend-enum-name', '--allowlist-file', meson.project_source_root() + '/include/.*', diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 60bd3f8aaa6..0b681c593f2 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -81,13 +81,13 @@ macro_rules! type_info { } else { ::core::ptr::null_mut() }, - instance_size: ::core::mem::size_of::<$t>() as $crate::bindings::size_t, - instance_align: ::core::mem::align_of::<$t>() as $crate::bindings::size_t, + instance_size: ::core::mem::size_of::<$t>(), + instance_align: ::core::mem::align_of::<$t>(), instance_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_INIT, instance_post_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_POST_INIT, instance_finalize: <$t as $crate::definitions::ObjectImpl>::INSTANCE_FINALIZE, abstract_: <$t as $crate::definitions::ObjectImpl>::ABSTRACT, - class_size: ::core::mem::size_of::<<$t as $crate::definitions::ObjectImpl>::Class>() as $crate::bindings::size_t, + class_size: ::core::mem::size_of::<<$t as $crate::definitions::ObjectImpl>::Class>(), class_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::Class>::CLASS_INIT, class_base_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::Class>::CLASS_BASE_INIT, class_data: ::core::ptr::null_mut(), From patchwork Mon Oct 21 16:35:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63464D15DBA for ; Mon, 21 Oct 2024 16:37:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOz-0006ol-Lo; Mon, 21 Oct 2024 12:37:05 -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 1t2vOD-00067n-Va for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36: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 1t2vOA-0006K1-RG for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528572; 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=ieLsbmqkTfVjeUAmxOVRrXd6Rl3o+mJGozPICAN/5xE=; b=F0E6w98mn9oeKoZh4sjhz28+jiI4X0vrYO0gk0KT4+/hcrDS2U/V5hxQzfpcrfvJfR+QCN v7HPKTIF1GtByNhR61hcz3NRSHx11JZ5wKpg9TpSJsHZ9zod6BJv8WBZ0XTKAbCYStdWyd NJiRBliBWfT+j0RRI1Wj5x7GXvSRhs0= 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-631-rM1olqiiMguaYboKpJrx_Q-1; Mon, 21 Oct 2024 12:36:10 -0400 X-MC-Unique: rM1olqiiMguaYboKpJrx_Q-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43163a40ee0so25575105e9.0 for ; Mon, 21 Oct 2024 09:36:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528559; x=1730133359; 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=ieLsbmqkTfVjeUAmxOVRrXd6Rl3o+mJGozPICAN/5xE=; b=hC3jHqS1Ekt8PTe+Jv9B6ChxFjlwYgVQUsUMWIkgpw5v2Lccz+7BStlRS2QS0OHyNp FBoQOlKw8ARbF6z8mJ7Rw3pU3ZNbuoO+9UNGRr1I4Nks6/9jYHSTEcD9P3OWzkS63NcR atDpVszDpI5vABRd7sPGJFVXa12aK5yttKr5doxRib4o262feJzu0aABYIOsn9Z9j7sQ ckQY9A/vPjXss5fu043zVjS9nyyMS4MpvMjGX483kvbb1ANqWG/i+AAUx0dZeUL7slLE 0mmFQrYstlFpnx0KOEPo570G2NwYCljBQ7vB4BQKVlq4X7r/n/SR3jh3IX3iRrk3Pvyu c6vA== X-Gm-Message-State: AOJu0YztnBQvxRUcZJNUT7wdF6yXcyBwfwAFv64Od5XPbIgvIe/iLgkw Bz4XUdxnuPzvKfb0A7VTJo+/Beac1IEGLTtTHcxlr0KPLnJAo1ZyOMJqvhOKYOGGB2uWoMR0Vmp VWstsiqLMED+57Ay4r1Mz5cBTFkZJyRYH9pN13SwwVBNZOwgxx+1EZz5KYT2ulpCfDP71rOTl+7 kAmi4ve0nJfbq8jjb93W96gQClgvFUCq1cVvtcDxA= X-Received: by 2002:a05:600c:45cb:b0:431:3927:d1bc with SMTP id 5b1f17b1804b1-431616331f5mr86372445e9.2.1729528559291; Mon, 21 Oct 2024 09:35:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHu9Toro2BrXmSEvXUExVMxKz8xGKwSpCitVQrOvid8rCqjZyXrzFvZ3FJcdm0RkCQisHmB1Q== X-Received: by 2002:a05:600c:45cb:b0:431:3927:d1bc with SMTP id 5b1f17b1804b1-431616331f5mr86372195e9.2.1729528558754; Mon, 21 Oct 2024 09:35:58 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0b9bb15sm4711993f8f.99.2024.10.21.09.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:35:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 05/13] rust: remove uses of #[no_mangle] Date: Mon, 21 Oct 2024 18:35:30 +0200 Message-ID: <20241021163538.136941-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Mangled symbols do not cause any issue; disabling mangling is only useful if C headers reference the Rust function, which is not the case here. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/src/device.rs | 5 ----- rust/hw/char/pl011/src/device_class.rs | 2 -- rust/hw/char/pl011/src/memory_ops.rs | 2 -- rust/qemu-api/src/definitions.rs | 1 - rust/qemu-api/src/device_class.rs | 2 -- 5 files changed, 12 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c7193b41bee..2b43f5e0939 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -514,7 +514,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { unsafe { debug_assert!(!opaque.is_null()); @@ -530,7 +529,6 @@ pub fn update(&self) { /// readable/writeable from one thread at any time. /// /// The buffer and size arguments must also be valid. -#[no_mangle] pub unsafe extern "C" fn pl011_receive( opaque: *mut core::ffi::c_void, buf: *const u8, @@ -554,7 +552,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) { unsafe { debug_assert!(!opaque.is_null()); @@ -566,7 +563,6 @@ pub fn update(&self) { /// # Safety /// /// We expect the FFI user of this function to pass a valid pointer for `chr`. -#[no_mangle] pub unsafe extern "C" fn pl011_create( addr: u64, irq: qemu_irq, @@ -589,7 +585,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_init(obj: *mut Object) { unsafe { debug_assert!(!obj.is_null()); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index b7ab31af02d..2ad80451e87 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -46,7 +46,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut *mut Error) { unsafe { assert!(!dev.is_null()); @@ -60,7 +59,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { unsafe { assert!(!dev.is_null()); diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 8d066ebf6d0..5a5320e66c3 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -22,7 +22,6 @@ }, }; -#[no_mangle] unsafe extern "C" fn pl011_read( opaque: *mut core::ffi::c_void, addr: hwaddr, @@ -44,7 +43,6 @@ } } -#[no_mangle] unsafe extern "C" fn pl011_write( opaque: *mut core::ffi::c_void, addr: hwaddr, diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 0b681c593f2..49ac59af123 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -53,7 +53,6 @@ extern "C" fn __load() { #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() = { extern "C" fn __load() { - #[no_mangle] unsafe extern "C" fn $func() { $body } diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index b6b68cf9ce2..2219b9f73d0 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -9,7 +9,6 @@ #[macro_export] macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { - #[no_mangle] pub unsafe extern "C" fn $func( klass: *mut $crate::bindings::ObjectClass, _: *mut ::core::ffi::c_void, @@ -103,7 +102,6 @@ const fn _calc_prop_len() -> usize { ] } - #[no_mangle] pub static mut $ident: $crate::device_class::Properties = $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_properties); }; } From patchwork Mon Oct 21 16:35:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C83AD15DBA for ; Mon, 21 Oct 2024 16:36:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOF-0006Aq-68; Mon, 21 Oct 2024 12:36:22 -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 1t2vO4-000622-JQ for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:11 -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 1t2vO2-0006JG-Hy for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528565; 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=LC3eZXbf/MgMolpo8tNMzb8FwxljpvkDw9TXTcaEtG4=; b=a0SeJMUqcC0uc6KyUlYgiH74upYCbDi5JvUEco9lGIrUmoXA1yfq+DxsOtiow+cxwl5F+O V0aacUJzdUsTNs7SCLN0seR7YtpLHgWRu0+4YY6O4KDIEevyOVee34u3muj5kAY/eCz0Ww FhbVmhQyVOm50w2cUuWge+q4k2IUVSE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-W5rTGtOQMS-wBgFLAVDLwA-1; Mon, 21 Oct 2024 12:36:04 -0400 X-MC-Unique: W5rTGtOQMS-wBgFLAVDLwA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4316300bb15so25077875e9.2 for ; Mon, 21 Oct 2024 09:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528562; x=1730133362; 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=LC3eZXbf/MgMolpo8tNMzb8FwxljpvkDw9TXTcaEtG4=; b=bvrXJieR7NxIKBUdfAf0dgzkLI1tVcrCMnzKFiSV1jtOMZXwvNavL6JKivybmCoft/ FOM2YhLF2jrVYIgva40XwiTrQh3mgopvb+5zhwFBdlXRHYlp5JXVbwtE78e6e57WlFRQ IcuK1/7YxiDq3HLPJEaDfR3+DoIdy2adsV3r9zIf6vJj6Riu40OOJ1dOqxG19Blh9h37 cR8/Q1d3SO6d6GtSnKKfXrJsWtRM9mDwfgWcCJI/6PiP3jOFZvFg/crh5PB3J7gpckNQ ACSM38pjAnj503wwCjOaiWbmjXDLdWnS24uCdlEBIm6BM5G0Pi6aXQLgGm6iApoTu1/d jS/g== X-Gm-Message-State: AOJu0YxOYz11BX0Z+/XUOKUA601+KC9pnQ5fwa4z76YR7UYk0YFf9EXn 33xOmCmhQR9WaZ2UAdqIWOAhszoNO4fpCo0zYxQ5boz60HBsoc0CLEw2qGCF6tLiP0+G8hBDFf0 8TyzZ95tx2fHCdUpMwLGWTxWPbWvXvNbClMjH5bm29SFsziS0gBBOsdn4vBjqz1f2f426E2S5UC eqG4C24/C7Csxpch8g+xCtYsR7s67IwA6zvzr/LGw= X-Received: by 2002:a05:600c:1d04:b0:431:43c6:e868 with SMTP id 5b1f17b1804b1-4316168989amr96211185e9.23.1729528562426; Mon, 21 Oct 2024 09:36:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFysiBm3yf0tbZkEr5nT0eHMMCE9Z/zmUvvYl+CWpu6d66CLnxg2DilTYfF7Q1Kp1VDLVTd3w== X-Received: by 2002:a05:600c:1d04:b0:431:43c6:e868 with SMTP id 5b1f17b1804b1-4316168989amr96210875e9.23.1729528561868; Mon, 21 Oct 2024 09:36:01 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a47b07sm4700072f8f.25.2024.10.21.09.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 06/13] rust: modernize link_section usage for ELF platforms Date: Mon, 21 Oct 2024 18:35:31 +0200 Message-ID: <20241021163538.136941-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Some newer ABI implementations do not provide .ctors; and while some linkers rewrite .ctors into .init_array, not all of them do. Use the newer .init_array ABI, which works more reliably, and apply it to all non-Apple, non-Windows platforms. This is similar to how the ctor crate operates; without this change, "#[derive(Object)]" does not work on Fedora 41. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api-macros/src/lib.rs | 7 +++++-- rust/qemu-api/src/definitions.rs | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs index 59aba592d9a..70e3f920460 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -16,8 +16,11 @@ pub fn derive_object(input: TokenStream) -> TokenStream { let expanded = quote! { #[allow(non_upper_case_globals)] #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] + #[cfg_attr( + not(any(target_vendor = "apple", target_os = "windows")), + link_section = ".init_array" + )] + #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static #module_static: extern "C" fn() = { extern "C" fn __register() { diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 49ac59af123..3323a665d92 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -31,8 +31,11 @@ pub trait Class { macro_rules! module_init { ($func:expr, $type:expr) => { #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] + #[cfg_attr( + not(any(target_vendor = "apple", target_os = "windows")), + link_section = ".init_array" + )] + #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() = { extern "C" fn __load() { @@ -48,8 +51,11 @@ extern "C" fn __load() { // NOTE: To have custom identifiers for the ctor func we need to either supply // them directly as a macro argument or create them with a proc macro. #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] + #[cfg_attr( + not(any(target_vendor = "apple", target_os = "windows")), + link_section = ".init_array" + )] + #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() = { extern "C" fn __load() { From patchwork Mon Oct 21 16:35:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BC66D15DBA for ; Mon, 21 Oct 2024 16:37:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOz-0006oT-M0; Mon, 21 Oct 2024 12:37:05 -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 1t2vOC-00065s-2G for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:17 -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 1t2vO6-0006Ji-Si for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528569; 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=Q404IxZFk+NIfcxl+Tcr9XRM6bnBKtIpSop9l9a12Xk=; b=ictC8xMQGsEzxlhMG1jC3ioeGnlkUHdZXNr2x4/PpjPnxjdYxUORHKsUNkS7QDdsbCLJYY p9RtfwRBNpBni/6solWaxcQA7oCEPHeluKm5QU9peEmJS3nJF401oJnJDKh5ACuQg1l47I hjgOjWEG57rPsVxuRoppnjHDpG/xNZM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-xAyz1ud0OsWaj2LXtjagRw-1; Mon, 21 Oct 2024 12:36:08 -0400 X-MC-Unique: xAyz1ud0OsWaj2LXtjagRw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315f48bd70so28269635e9.2 for ; Mon, 21 Oct 2024 09:36:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528566; x=1730133366; 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=Q404IxZFk+NIfcxl+Tcr9XRM6bnBKtIpSop9l9a12Xk=; b=lcVgPOvrthamK7UnWGUQ4pn/A2TawrX4PpzUAspijK6wfrOISysleLY1jI27W5Os8p z70flVfJsTAAZXx789KhnZAj6sXxg0hRghGFoDnsqHwtpiFHydhgMa5RYqdJZhzBsQbV 1/5lmYq4xpBm+ELusc+i1Q0gb8JKTIYqWBm5XFMPzbmSVi7ty/5FyZSziaWlt9sMz/3U gt1Jlhoaa+5OCERhTE63eHwI6DRta34rCjQ7j/Y0C1ZuziN57VMvlYdkNjba4FY72aVO Qsa9Iex19sTgceURlh9LQz7vP0fDu5QpJ7Sjp3CQMZprx0FfsD34s+sCEyAq6AdMT67v O8Zg== X-Gm-Message-State: AOJu0YyavooiB/pSlnHLAIfQwtuY+LLrqHsyePz5cz5I087gwYzdZdFV J0lU3UWelfNMBpGPTyffCiKxAnPqBb+alaPJPLu+SCHCqDcHLHaLjJ4LbUZa22KEg14VzleNB2C yGs9uo6vn4edzIWwJJcZS6+pibDAM2+4CqSDHQRiTnuN0NIesm6wSFisMx6aMJ26WDTl28Lbl5I Sgjkc1CJEOvlHIhIu8do6KYBSns4EDrIdxX1uh1rw= X-Received: by 2002:a05:600c:19d2:b0:431:3c67:fb86 with SMTP id 5b1f17b1804b1-431616a404dmr88541325e9.33.1729528566373; Mon, 21 Oct 2024 09:36:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHecvCZ1N1dVcHdMc7UcS3N7JC2ht0pL/nBidv/7JzOv05qnQEXa6OPB3xkVzspDNQhi6fJOQ== X-Received: by 2002:a05:600c:19d2:b0:431:3c67:fb86 with SMTP id 5b1f17b1804b1-431616a404dmr88541095e9.33.1729528565907; Mon, 21 Oct 2024 09:36:05 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f57102asm62047065e9.1.2024.10.21.09.36.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao , Zhao Liu Subject: [PATCH v2 07/13] rust: build integration test for the qemu_api crate Date: Mon, 21 Oct 2024 18:35:32 +0200 Message-ID: <20241021163538.136941-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Adjust the integration test to compile with a subset of QEMU object files, and make it actually create an object of the class it defines. Follow the Rust filesystem conventions, where tests go in tests/ if they use the library in the same way any other code would. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao Tested-by: Zhao Liu --- meson.build | 10 ++++- rust/qemu-api/meson.build | 26 ++++++++++-- rust/qemu-api/src/lib.rs | 3 -- rust/qemu-api/src/tests.rs | 49 ---------------------- rust/qemu-api/tests/tests.rs | 78 ++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 56 deletions(-) delete mode 100644 rust/qemu-api/src/tests.rs create mode 100644 rust/qemu-api/tests/tests.rs diff --git a/meson.build b/meson.build index 6739165908e..3c71d129494 100644 --- a/meson.build +++ b/meson.build @@ -3326,7 +3326,15 @@ if have_rust and have_system # Prohibit code that is forbidden in Rust 2024 rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] - add_project_arguments(rustc_args, native: false, language: 'rust') + + # Apart from procedural macros, our Rust executables will often link + # with C code, so include all the libraries that C code needs. This + # is safe; https://github.com/rust-lang/rust/pull/54675 says that + # passing -nodefaultlibs to the linker "was more ideological to + # start with than anything". + add_project_arguments(rustc_args + ['-C', 'default-linker-libraries'], + native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') endif diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 42ea815fa5a..1fc36078027 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -14,11 +14,31 @@ _qemu_api_rs = static_library( '--cfg', 'MESON', # '--cfg', 'feature="allocator"', ], - dependencies: [ - qemu_api_macros, - ], ) qemu_api = declare_dependency( link_with: _qemu_api_rs, + dependencies: qemu_api_macros, ) + +# Rust executables do not support objects, so add an intermediate step. +rust_qemu_api_objs = static_library( + 'rust_qemu_api_objs', + objects: [libqom.extract_all_objects(recursive: false), + libhwcore.extract_all_objects(recursive: false)]) + +test('rust-qemu-api-integration', + executable( + 'rust-qemu-api-integration', + 'tests/tests.rs', + override_options: ['rust_std=2021', 'build.rust_std=2021'], + rust_args: ['--test'], + install: false, + dependencies: [qemu_api, qemu_api_macros], + link_whole: [rust_qemu_api_objs, libqemuutil]), + args: [ + '--test', + '--format', 'pretty', + ], + protocol: 'rust', + suite: ['unit', 'rust']) diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e72fb4b4bb1..6bc68076aae 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -30,9 +30,6 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod definitions; pub mod device_class; -#[cfg(test)] -mod tests; - use std::alloc::{GlobalAlloc, Layout}; #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] diff --git a/rust/qemu-api/src/tests.rs b/rust/qemu-api/src/tests.rs deleted file mode 100644 index df54edbd4e2..00000000000 --- a/rust/qemu-api/src/tests.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use crate::{ - bindings::*, declare_properties, define_property, device_class_init, vm_state_description, -}; - -#[test] -fn test_device_decl_macros() { - // Test that macros can compile. - vm_state_description! { - VMSTATE, - name: c"name", - unmigratable: true, - } - - #[repr(C)] - pub struct DummyState { - pub char_backend: CharBackend, - pub migrate_clock: bool, - } - - declare_properties! { - DUMMY_PROPERTIES, - define_property!( - c"chardev", - DummyState, - char_backend, - unsafe { &qdev_prop_chr }, - CharBackend - ), - define_property!( - c"migrate-clk", - DummyState, - migrate_clock, - unsafe { &qdev_prop_bool }, - bool - ), - } - - device_class_init! { - dummy_class_init, - props => DUMMY_PROPERTIES, - realize_fn => None, - reset_fn => None, - vmsd => VMSTATE, - } -} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs new file mode 100644 index 00000000000..aa1e0568c69 --- /dev/null +++ b/rust/qemu-api/tests/tests.rs @@ -0,0 +1,78 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::ffi::CStr; + +use qemu_api::{ + bindings::*, + declare_properties, define_property, + definitions::{Class, ObjectImpl}, + device_class_init, vm_state_description, +}; + +#[test] +fn test_device_decl_macros() { + // Test that macros can compile. + vm_state_description! { + VMSTATE, + name: c"name", + unmigratable: true, + } + + #[repr(C)] + #[derive(qemu_api_macros::Object)] + pub struct DummyState { + pub _parent: DeviceState, + pub migrate_clock: bool, + } + + #[repr(C)] + pub struct DummyClass { + pub _parent: DeviceClass, + } + + declare_properties! { + DUMMY_PROPERTIES, + define_property!( + c"migrate-clk", + DummyState, + migrate_clock, + unsafe { &qdev_prop_bool }, + bool + ), + } + + device_class_init! { + dummy_class_init, + props => DUMMY_PROPERTIES, + realize_fn => None, + legacy_reset_fn => None, + vmsd => VMSTATE, + } + + impl ObjectImpl for DummyState { + type Class = DummyClass; + const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; + const TYPE_NAME: &'static CStr = c"dummy"; + const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_DEVICE); + const ABSTRACT: bool = false; + const INSTANCE_INIT: Option = None; + const INSTANCE_POST_INIT: Option = None; + const INSTANCE_FINALIZE: Option = None; + } + + impl Class for DummyClass { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + > = Some(dummy_class_init); + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + > = None; + } + + unsafe { + module_call_init(module_init_type::MODULE_INIT_QOM); + object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); + } +} From patchwork Mon Oct 21 16:35:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77731D15DBB for ; Mon, 21 Oct 2024 16:39:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vP2-0006yC-1k; Mon, 21 Oct 2024 12:37:08 -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 1t2vOD-00067m-VV for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36: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 1t2vO9-0006Jx-Li for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528572; 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=kvb89qSp/JxmYfOj6SZi8Bx0KqHl+LVpfSQJUogsuq4=; b=UxvnHXxUvAngz3NM7pQsn7W1Gpx3F0T690YPCi24AOnJk+w6Xe1xefvLMLRwMd+ujX6MNQ qFL6eVRzFZh+y7Nf4ixodcsYlZbo6iDQSWn7PXBlW7Nf8cmvyz4D5u4VhyOz8E7LHEw4Cr t+Og0WGDuaGzGvF0i/QQHJpFU34/aTc= 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-385-IsaXhJRgMfC9XKIlxMzokA-1; Mon, 21 Oct 2024 12:36:11 -0400 X-MC-Unique: IsaXhJRgMfC9XKIlxMzokA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315544642eso37410185e9.3 for ; Mon, 21 Oct 2024 09:36:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528569; x=1730133369; 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=kvb89qSp/JxmYfOj6SZi8Bx0KqHl+LVpfSQJUogsuq4=; b=mVVkyBcrkE5nJEKV9PTTZGMDk4VTCFpShtfdtWt0G+iqWE0FyfolbCOwaZgUBIRsvK MBj6RVSHHnQUM8b/wFzOSjndi2/68AQSyDtziSv6QfXFgtBDjQekGnc/W5EpSX0zRKMl V6VGz6kGu/FwNfLrIm+aH/Z8Niu4DRyLsilkQZWOxURavFIeJmTRBXOQHIox/FWn8dLH q16fetw8Kr+/KTQRbC1XmbYutjAnjzd4XcQcvatOtdkEjHiSSm0VpirhEN1uF+sks5V2 znY+XDgpv/m54VKDWOq3WEGE19xcEdYoePGDjvLPjuheLreOfZLpi3lBulV+pOuslaNp Xoog== X-Gm-Message-State: AOJu0Yz/5yvw+LNTA6PiFRiDUlQHGckZtWxFzQ/wOAY2xJiw3rUSmTQ9 aX/BhO+4S/NeGzPHwapwWBa6iZ+0THHXInTwgID5kuXjSAMmqRDdQY5u0RouE3WWiWJMK/UILB0 Vo/KUP/szWzK4N92DAyRBuYj4MQHPq8Gd6H+lYzJwk9wSQCNyOefwFMga89p65FOKPt6YkGJheO yQX9ziN4/KIuxnCbZIn9oszFkOulu7WgqJiEyIgd4= X-Received: by 2002:a05:600c:1d01:b0:42c:b74c:d8c3 with SMTP id 5b1f17b1804b1-4316168ff01mr99496365e9.32.1729528569240; Mon, 21 Oct 2024 09:36:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoo2DZlzYa5tO9scq9rSbVdszZ2ED+SvdnMr+4+YYOsddyVtq1HlTczBGmh8mLjTphc1v7jg== X-Received: by 2002:a05:600c:1d01:b0:42c:b74c:d8c3 with SMTP id 5b1f17b1804b1-4316168ff01mr99496045e9.32.1729528568746; Mon, 21 Oct 2024 09:36:08 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f57fa4fsm62774405e9.16.2024.10.21.09.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 08/13] rust: cleanup module_init!, use it from #[derive(Object)] Date: Mon, 21 Oct 2024 18:35:33 +0200 Message-ID: <20241021163538.136941-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Remove the duplicate code by using the module_init! macro; at the same time, simplify how module_init! is used, by taking inspiration from the implementation of #[derive(Object)]. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu --- rust/qemu-api-macros/src/lib.rs | 33 +++------------- rust/qemu-api/src/definitions.rs | 66 ++++++++++++++------------------ 2 files changed, 33 insertions(+), 66 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs index 70e3f920460..a4bc5d01ee8 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -3,43 +3,20 @@ // SPDX-License-Identifier: GPL-2.0-or-later use proc_macro::TokenStream; -use quote::{format_ident, quote}; +use quote::quote; use syn::{parse_macro_input, DeriveInput}; #[proc_macro_derive(Object)] pub fn derive_object(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - let name = input.ident; - let module_static = format_ident!("__{}_LOAD_MODULE", name); let expanded = quote! { - #[allow(non_upper_case_globals)] - #[used] - #[cfg_attr( - not(any(target_vendor = "apple", target_os = "windows")), - link_section = ".init_array" - )] - #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] - #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] - pub static #module_static: extern "C" fn() = { - extern "C" fn __register() { - unsafe { - ::qemu_api::bindings::type_register_static(&<#name as ::qemu_api::definitions::ObjectImpl>::TYPE_INFO); - } + ::qemu_api::module_init! { + MODULE_INIT_QOM => unsafe { + ::qemu_api::bindings::type_register_static(&<#name as ::qemu_api::definitions::ObjectImpl>::TYPE_INFO); } - - extern "C" fn __load() { - unsafe { - ::qemu_api::bindings::register_module_init( - Some(__register), - ::qemu_api::bindings::module_init_type::MODULE_INIT_QOM - ); - } - } - - __load - }; + } }; TokenStream::from(expanded) diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 3323a665d92..f180c38bfb2 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -29,51 +29,40 @@ pub trait Class { #[macro_export] macro_rules! module_init { - ($func:expr, $type:expr) => { - #[used] - #[cfg_attr( - not(any(target_vendor = "apple", target_os = "windows")), - link_section = ".init_array" - )] - #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] - #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() = { - extern "C" fn __load() { - unsafe { - $crate::bindings::register_module_init(Some($func), $type); - } - } - - __load - }; - }; - (qom: $func:ident => $body:block) => { - // NOTE: To have custom identifiers for the ctor func we need to either supply - // them directly as a macro argument or create them with a proc macro. - #[used] - #[cfg_attr( - not(any(target_vendor = "apple", target_os = "windows")), - link_section = ".init_array" - )] - #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] - #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() = { - extern "C" fn __load() { - unsafe extern "C" fn $func() { + ($type:ident => $body:block) => { + const _: () = { + #[used] + #[cfg_attr( + not(any(target_vendor = "apple", target_os = "windows")), + link_section = ".init_array" + )] + #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] + #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] + pub static LOAD_MODULE: extern "C" fn() = { + extern "C" fn init_fn() { $body } - unsafe { - $crate::bindings::register_module_init( - Some($func), - $crate::bindings::module_init_type::MODULE_INIT_QOM, - ); + extern "C" fn ctor_fn() { + unsafe { + $crate::bindings::register_module_init( + Some(init_fn), + $crate::bindings::module_init_type::$type, + ); + } } - } - __load + ctor_fn + }; }; }; + + // shortcut because it's quite common that $body needs unsafe {} + ($type:ident => unsafe $body:block) => { + $crate::module_init! { + $type => { unsafe { $body } } + } + }; } #[macro_export] From patchwork Mon Oct 21 16:35:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DF18D15DBA for ; Mon, 21 Oct 2024 16:39:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vP2-0006yB-1t; Mon, 21 Oct 2024 12:37:08 -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 1t2vOF-0006E5-DB for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:22 -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 1t2vOD-0006KP-OI for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528575; 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=hHp8U+fC4YmDmSdyK3Hbe0MIdIfjHmGSBbEEt6avx3w=; b=ZI4pae39sOpSnJuIUw0l7jnmA9GiYvTHpFGh+EjkccWq2pn5R9AMiFEUs1WD071y1iY3nV HjWoJK0KAAH+eUAhl3MSpiNRYoRbluhjdEGguR4BLTJcNQn5GCkfN4hmbjKGU+Wi8xalgn wq20s4K0TvwEuVSv9DD28NbByXsktBk= 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-683-ra4IysxaN8yKTROnfyO01A-1; Mon, 21 Oct 2024 12:36:14 -0400 X-MC-Unique: ra4IysxaN8yKTROnfyO01A-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315c1b5befso33563535e9.1 for ; Mon, 21 Oct 2024 09:36:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528572; x=1730133372; 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=hHp8U+fC4YmDmSdyK3Hbe0MIdIfjHmGSBbEEt6avx3w=; b=FSv0QpluhBUVV5nEHlaN7CdNeNkHuTCoiVxyZqJaIOBObydXFUtT8AU2X0Rgajscdt 9JNI50XLeC+cJ9V/YLZUGf3g/GscFLcR0sOOVVxIv5XQPikRi7LsXVyU56y6sgI19LUS MgKIs/eA9NdXkN02evFLbXnbU022FiL/abcjmQn9AazZxiRI3KCCQ3V7GMwAP5Tx+hW1 xsVaGb+SiNsYHX9/5K4zuey2VCHOWqh+OXxrAS21T+eyqhyvL/9gvfiSpgHCYPVns3RI Zci9or8tw6qFeC41LXI/G5OBVU16uk1eEgf9pE5AAZkpdTNqz/26kmjeWmYlFf3AK5df GMUg== X-Gm-Message-State: AOJu0Yw1jp5j2jxYOHSQ0JRb1OGAjLs6mvPQHcZqX7FYkNjoZliv3aO/ 7GzBZ27m6wYUDjkWQ7VAGEIzB343yaLMJrR5zP3loQEchINu6d98XQVV0a8yIHy4acyH18v/a1H QKN7vQcl1ECOLPlMMfz57wh+w/5HHuw6MuBCZRzW9YdbczuAxc9hIqQA8x7XwVpIJNN0Lp7tXqx huARrC1F8twq1u9vgQU41R2c6UmE+nuUQFgk82sGY= X-Received: by 2002:a05:600c:1d8d:b0:426:5e91:3920 with SMTP id 5b1f17b1804b1-43161692d44mr99877815e9.29.1729528572039; Mon, 21 Oct 2024 09:36:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTpuBpV1Y/2bigGkfFPEf+RgAHG6s7VIKYboB4Cb69l40jGZAMLPiQQSnRKeIKdRBMrLo3ZA== X-Received: by 2002:a05:600c:1d8d:b0:426:5e91:3920 with SMTP id 5b1f17b1804b1-43161692d44mr99877635e9.29.1729528571622; Mon, 21 Oct 2024 09:36:11 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5cc5b9sm63138085e9.45.2024.10.21.09.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 09/13] rust: clean up define_property macro Date: Mon, 21 Oct 2024 18:35:34 +0200 Message-ID: <20241021163538.136941-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use the "struct update" syntax to initialize most of the fields to zero, and simplify the handmade type-checking of $name. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/device_class.rs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 2219b9f73d0..5aba426d243 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -29,44 +29,27 @@ macro_rules! device_class_init { macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr = $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr = $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: false, - defval: $crate::bindings::Property__bindgen_ty_1 { i: 0 }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; } From patchwork Mon Oct 21 16:35:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C84ED15DBB for ; Mon, 21 Oct 2024 16:37:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOw-0006bu-AC; Mon, 21 Oct 2024 12:37:04 -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 1t2vOI-0006Fw-9H for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:24 -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 1t2vOG-0006LL-Gh for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528579; 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=Q6fXeEeyQn++bTLgXgQsS/yFO40vxiI7losxFrd52jU=; b=f5VoJM674a8AWIC6FcLDvQbLk665Gjce00sd1kXuDW8UCesNJL6xImptyMbbjPAiTxyvKX BOgfBfjfVdV+r7ti9549QlQqWsjTE+FhUFKZ7QsHHeomL8c7S5vo6pa6im8TqrI68FB8Rg aS9kPdcXeC8AcwIydqgrnQt5VDCZWTw= 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-140-wo72bBCBOU6_3b8s-vCNKg-1; Mon, 21 Oct 2024 12:36:18 -0400 X-MC-Unique: wo72bBCBOU6_3b8s-vCNKg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d458087c0so3166889f8f.1 for ; Mon, 21 Oct 2024 09:36:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528576; x=1730133376; 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=Q6fXeEeyQn++bTLgXgQsS/yFO40vxiI7losxFrd52jU=; b=t6eYaX9volYjCK3imRZhvfIG1yPm+fCwpN6XBzeZaHoipkn5ALvKrfD6oF0g8dN/r3 C+ozPJE7z96DS2/0OllWB+tlYv00+Vks9lVsrcn0pd4mEIevC0D7q8votBULoS5IZ1zI aMVUrwkoGAFjp4NDPR2vCeQ2YsLSFdZMN1/9giDdnObX6bFjONNMAy0kgvm3Tj/UjVvz Jtb55BjJUIuiy67OQCR/14uaQRm0g1OcY5fCUkihZW6DA6t/t4MhCDZS9Hu2fxuOuBLw OIgePtShcIrZP6F0MpX8dXIwj2CiedVXYk97wa3VKbYz7d2PdcO6BBnrNn2NcRUKobYo V0SA== X-Gm-Message-State: AOJu0Yw+IqJ5dxdI5xc6H/4efCkLOE8xzCSJ0W9E+lPE9JENh8EK10Ql l3Drgaa5NTlersiUfH71MGqd6tvgabZLScJD1tKTDvveRfzkLYrzDu32XxZu0cZoe19xuD6REGA TZuf+8gz0Nz+WIClUzPHL2RNvd0XGB9H5CaG4/OEEJbhvLeYXlZgwPMRNaTAiyRqYBmb5FUtupi vZTNjrnTnjhUQUEclDBi9iZP7ucCMR3hDnssqfxac= X-Received: by 2002:adf:f10e:0:b0:37e:d92f:c24a with SMTP id ffacd0b85a97d-37ef12624ebmr186003f8f.7.1729528575910; Mon, 21 Oct 2024 09:36:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMK3/foCCFBtMo7wEMvC8DQ/6La2pEr8BWwn0ngNksc+uOYCltyX6UNBYr2vLrTUWfb2nrFQ== X-Received: by 2002:adf:f10e:0:b0:37e:d92f:c24a with SMTP id ffacd0b85a97d-37ef12624ebmr185978f8f.7.1729528575370; Mon, 21 Oct 2024 09:36:15 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a584f7sm4698516f8f.53.2024.10.21.09.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 10/13] qdev: make properties array "const" Date: Mon, 21 Oct 2024 18:35:35 +0200 Message-ID: <20241021163538.136941-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Constify all accesses to qdev properties, except for the ObjectPropertyAccessor itself. This makes it possible to place them in read-only memory, and also lets Rust bindings switch from "static mut" arrays to "static"; which is advantageous, because mutable statics are highly discouraged. Signed-off-by: Paolo Bonzini --- include/hw/qdev-core.h | 4 ++-- include/hw/qdev-properties.h | 4 ++-- hw/core/qdev-properties.c | 26 +++++++++++++------------- system/qdev-monitor.c | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index aa97c34a4be..f9fa291cc63 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -132,7 +132,7 @@ struct DeviceClass { * ensures a compile-time error if someone attempts to assign * dc->props directly. */ - Property *props_; + const Property *props_; /** * @user_creatable: Can user instantiate with -device / device_add? @@ -935,7 +935,7 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); * you attempt to add an existing property defined by a parent class. * To modify an inherited property you need to use???? */ -void device_class_set_props(DeviceClass *dc, Property *props); +void device_class_set_props(DeviceClass *dc, const Property *props); /** * device_class_set_parent_realize() - set up for chaining realize fns diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 09aa04ca1e2..26ebd230685 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -37,7 +37,7 @@ struct PropertyInfo { int (*print)(Object *obj, Property *prop, char *dest, size_t len); void (*set_default_value)(ObjectProperty *op, const Property *prop); ObjectProperty *(*create)(ObjectClass *oc, const char *name, - Property *prop); + const Property *prop); ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyRelease *release; @@ -223,7 +223,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, * On error, store error in @errp. Static properties access data in a struct. * The type of the QOM property is derived from prop->info. */ -void qdev_property_add_static(DeviceState *dev, Property *prop); +void qdev_property_add_static(DeviceState *dev, const Property *prop); /** * qdev_alias_all_properties: Create aliases on source for all target properties diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 86a583574dd..315196bd85a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -749,7 +749,7 @@ const PropertyInfo qdev_prop_array = { /* --- public helpers --- */ -static Property *qdev_prop_walk(Property *props, const char *name) +static const Property *qdev_prop_walk(const Property *props, const char *name) { if (!props) { return NULL; @@ -763,10 +763,10 @@ static Property *qdev_prop_walk(Property *props, const char *name) return NULL; } -static Property *qdev_prop_find(DeviceState *dev, const char *name) +static const Property *qdev_prop_find(DeviceState *dev, const char *name) { ObjectClass *class; - Property *prop; + const Property *prop; /* device properties */ class = object_get_class(OBJECT(dev)); @@ -840,7 +840,7 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value) void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) { - Property *prop; + const Property *prop; prop = qdev_prop_find(dev, name); object_property_set_str(OBJECT(dev), name, @@ -956,7 +956,7 @@ const PropertyInfo qdev_prop_size = { /* --- object link property --- */ static ObjectProperty *create_link_property(ObjectClass *oc, const char *name, - Property *prop) + const Property *prop) { return object_class_property_add_link(oc, name, prop->link_type, prop->offset, @@ -969,7 +969,7 @@ const PropertyInfo qdev_prop_link = { .create = create_link_property, }; -void qdev_property_add_static(DeviceState *dev, Property *prop) +void qdev_property_add_static(DeviceState *dev, const Property *prop) { Object *obj = OBJECT(dev); ObjectProperty *op; @@ -980,7 +980,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop) field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); object_property_set_description(obj, prop->name, prop->info->description); @@ -994,7 +994,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop) } static void qdev_class_add_property(DeviceClass *klass, const char *name, - Property *prop) + const Property *prop) { ObjectClass *oc = OBJECT_CLASS(klass); ObjectProperty *op; @@ -1007,7 +1007,7 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name, field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); } if (prop->set_default) { prop->info->set_default_value(op, prop); @@ -1046,7 +1046,7 @@ static void qdev_get_legacy_property(Object *obj, Visitor *v, * Do not use this in new code! QOM Properties added through this interface * will be given names in the "legacy" namespace. */ -static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) +static void qdev_class_add_legacy_property(DeviceClass *dc, const Property *prop) { g_autofree char *name = NULL; @@ -1058,12 +1058,12 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) name = g_strdup_printf("legacy-%s", prop->name); object_class_property_add(OBJECT_CLASS(dc), name, "str", prop->info->print ? qdev_get_legacy_property : prop->info->get, - NULL, NULL, prop); + NULL, NULL, (Property *)prop); } -void device_class_set_props(DeviceClass *dc, Property *props) +void device_class_set_props(DeviceClass *dc, const Property *props) { - Property *prop; + const Property *prop; dc->props_ = props; for (prop = props; prop && prop->name; prop++) { diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 44994ea0e16..c346ea6ae4b 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -751,7 +751,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) -static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, +static void qdev_print_props(Monitor *mon, DeviceState *dev, const Property *props, int indent) { if (!props) From patchwork Mon Oct 21 16:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 054D7D15DBB for ; Mon, 21 Oct 2024 16:37:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vOz-0006nf-KE; Mon, 21 Oct 2024 12:37:05 -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 1t2vOM-0006IJ-7T for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:30 -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 1t2vOK-0006Ln-2X for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528583; 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=Qr5dagb8vQ3bDNxUa7EXxPicbCEKo86t7f8oVBzNrBQ=; b=XENkGCsOzPl1nrfhusyvB++SFMKpgsTM86HLqFyTEt+lNNTLSdcpOUI9m3mrr5KDpfpZVT stthyp/+TKyDdflHvLoec2iVj4JQQBtzGwbK+nOnBKN0wYCHcACF2kOaErbbQ2nPryXO7g KdovhL8AAbIRyahcMzL2pDD/FGPbL0M= 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-619-5TJ3YyfQMGiyftT7h7QEfw-1; Mon, 21 Oct 2024 12:36:22 -0400 X-MC-Unique: 5TJ3YyfQMGiyftT7h7QEfw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-431518e6d8fso32226885e9.0 for ; Mon, 21 Oct 2024 09:36:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528580; x=1730133380; 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=Qr5dagb8vQ3bDNxUa7EXxPicbCEKo86t7f8oVBzNrBQ=; b=ldu/LlQqjoxSmzLkiQo8QonXVBIG6urXMYOvt/pLIlQ5w8zLic4vu/921ksD50O1zk IFVxCwOnA+t1fXJLdE2N01EN7GW6iH/Py2g6Is1IuwzyBlWs+gSVZNmvQPzDigt+CxHt 4lGyXp8lHZ3sTCLKq16ZzbWDyk+HI4DupVgv8SP2M5hCeqLc1mD1C/yJML80+gVxOz5R opmZtaOxFvjIyNJ5v28hRnXcz4Be4iiC/bBv2FLPh1bCwgTWWItcTYlMqFAkWQjpqHdn XTd0/Ity8dKqnMSN5951hjKXpwo9dRIpS1gfxGvbXWU8jawKPr4Nyb5E0S1xd2dcRGmq /3vA== X-Gm-Message-State: AOJu0Yw8x1bcbKikDrrfoCa8azw+5q11vxMdZpjFBUi1USn35z2IGd86 CLldoouL+4hbl0lJNGfjixgiIx59C7Tiui1HuU/smKInfiOxoWnUz8Kb+UBZwhI6xpiE9b/OKAZ KwSGetzs4fOSRjRBr8IdMMWUYNZFnoDoXW/kz6x6rYwCUqL2J81JlFNNYf+hCNZffXJ4UgUC1+z 2V5nqOLKvMwwSiYB7u45WMqY8T72Wrn2SlpUrjAfU= X-Received: by 2002:a05:600c:4751:b0:431:612f:189b with SMTP id 5b1f17b1804b1-43161649510mr87412265e9.12.1729528579913; Mon, 21 Oct 2024 09:36:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlDNUJ9aNFHH9akQxzvIEapV8Kx8cor6fWetajxrgiuBLxLfD496WyLG6iD92BJfxFAHhtPw== X-Received: by 2002:a05:600c:4751:b0:431:612f:189b with SMTP id 5b1f17b1804b1-43161649510mr87412035e9.12.1729528579456; Mon, 21 Oct 2024 09:36:19 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5709efsm63926925e9.10.2024.10.21.09.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 11/13] rust: make properties array immutable Date: Mon, 21 Oct 2024 18:35:36 +0200 Message-ID: <20241021163538.136941-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now that device_class_set_props() takes a const pointer, the only part of "define_property!" that needs to be non-const is the call to try_into(). This in turn will only break if offset_of returns a value with the most significant bit set (i.e. a struct size that is >=2^31 or >= 2^63, respectively on 32- and 64-bit system), which is impossible. Just use a cast and clean everything up to remove the run-time initialization. This also removes a use of OnceLock, which was only stabilized in 1.70.0. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/qemu-api/src/device_class.rs | 42 ++++++------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 5aba426d243..d885f2fcf19 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,10 +2,6 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::sync::OnceLock; - -use crate::bindings::Property; - #[macro_export] macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { @@ -19,7 +15,7 @@ macro_rules! device_class_init { dc.as_mut().realize = $realize_fn; dc.as_mut().vmsd = &$vmsd; $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_ptr()); } } }; @@ -32,9 +28,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } @@ -45,47 +39,27 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; } -#[repr(C)] -pub struct Properties(pub OnceLock<[Property; N]>, pub fn() -> [Property; N]); - -impl Properties { - pub fn as_mut_ptr(&mut self) -> *mut Property { - _ = self.0.get_or_init(self.1); - self.0.get_mut().unwrap().as_mut_ptr() - } -} - #[macro_export] macro_rules! declare_properties { ($ident:ident, $($prop:expr),*$(,)*) => { - - const fn _calc_prop_len() -> usize { + pub static $ident: [$crate::bindings::Property; { let mut len = 1; $({ _ = stringify!($prop); len += 1; })* len - } - const PROP_LEN: usize = _calc_prop_len(); - - fn _make_properties() -> [$crate::bindings::Property; PROP_LEN] { - [ - $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, - ] - } - - pub static mut $ident: $crate::device_class::Properties = $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_properties); + }] = [ + $($prop),*, + unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, + ]; }; } From patchwork Mon Oct 21 16:35:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FA8CD15DBA for ; Mon, 21 Oct 2024 16:39:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vP2-00075O-L3; Mon, 21 Oct 2024 12:37:09 -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 1t2vOU-0006Od-Ms for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:37 -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 1t2vOP-0006M2-RN for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528587; 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=2BdOoYFgTDYgcexwJMKhcnGOcBQRfOI4n0cvkFXXd3Q=; b=GVKdwsHh8jmpemc2rqEk/3kXx/wgFsxvYDQvxOVNz3dsMmmYa5MgmbavSNfhWebwZGKA2Y QLzYzKH/doBsLL6ng1IJVC5jN3XtjzgyUR+vdcyns7tqGf5Ynajka0cu9sXQ+mEaxrCZbP 9BibKmUfiL6d4gI9pf0c0DoZXDqAgvY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-huMKzoV9P2WAA8-NPzxDHQ-1; Mon, 21 Oct 2024 12:36:26 -0400 X-MC-Unique: huMKzoV9P2WAA8-NPzxDHQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4314f023f55so38157375e9.2 for ; Mon, 21 Oct 2024 09:36:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528584; x=1730133384; 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=2BdOoYFgTDYgcexwJMKhcnGOcBQRfOI4n0cvkFXXd3Q=; b=WCGMTZvX43J30n+iuBY1HwEHDd8byEu4j+v4EXKK0mNUCxhpY1SGrWZw76YKcVsDgx RP2DJFgxYk/sh0XaouZqVS4ntA3kmvqw6AFOufi0Iys4jtve/oYxGoTezyaGRYocPV1D /SiqxrO4h+mEtg7h26K76G+W0Unl3f4aQVr9Y84wYN78M/6pz1AZ79BtE1JqdiGqjRVh eLTUGBpsBjAJ14E2g4eQC6oV8q46gy7XUD+u5Ehy0YdNfuN7r5b9quILPAx/PZa/DivC XctziDPCC4qlEFJloVh8QtHlSflD0nfJmdZqnmWQqQfVX7Aij7SMoVK6lXcDnODjsV5N YJtA== X-Gm-Message-State: AOJu0Yzyk601V4lnQ/T9izXgmtdPqUJvyOln/Hn8hKQXhJJSd2uN9Ynp UAgOGan0mQ8yEZTNzOYzJCl8zXyqpmLBQBElqz/DquPgWdznZ5F5cRZwtYZKy280ohIpkq3nEFO VcNhel4D8pKt+7rz8R8Aiivxw9qxjAQG4VP6ctt2cy6S00mbS0ItHFzfwv7RlFhOnjRUWmLpMdF QgPKXoCLnGPbDUomid1thLQdby28JgInG3gJ2Ec3Y= X-Received: by 2002:a05:600c:4f09:b0:42c:c28c:e477 with SMTP id 5b1f17b1804b1-43161697686mr96761605e9.23.1729528584025; Mon, 21 Oct 2024 09:36:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGutK9twdTD9IzG41Qe+bK1s3XPTEO6ajOcTHifNBWq2SKsw0liL4BCffFEnm/joHF1lZ+bEQ== X-Received: by 2002:a05:600c:4f09:b0:42c:c28c:e477 with SMTP id 5b1f17b1804b1-43161697686mr96761325e9.23.1729528583499; Mon, 21 Oct 2024 09:36:23 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a4856fsm4713098f8f.33.2024.10.21.09.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 12/13] rust: provide safe wrapper for MaybeUninit::zeroed() Date: Mon, 21 Oct 2024 18:35:37 +0200 Message-ID: <20241021163538.136941-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org MaybeUninit::zeroed() is handy, but it introduces unsafe (and has a pretty heavy syntax in general). Introduce a trait that provides the same functionality while staying within safe Rust. In addition, MaybeUninit::zeroed() is not available as a "const" function until Rust 1.75.0, so this also prepares for having handwritten implementations of the trait until we can assume that version. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/src/device_class.rs | 8 ++++++-- rust/hw/char/pl011/src/memory_ops.rs | 11 +++++++---- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/device_class.rs | 8 ++++---- rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/zeroable.rs | 23 +++++++++++++++++++++++ 6 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 rust/qemu-api/src/zeroable.rs diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 2ad80451e87..78fa1cdd5b6 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -4,7 +4,11 @@ use core::ptr::NonNull; -use qemu_api::{bindings::*, definitions::ObjectImpl}; +use qemu_api::{ + bindings::*, + definitions::ObjectImpl, + zeroable::Zeroable, +}; use crate::device::PL011State; @@ -12,7 +16,7 @@ pub static VMSTATE_PL011: VMStateDescription = VMStateDescription { name: PL011State::TYPE_INFO.name, unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() } + ..Zeroable::ZERO }; qemu_api::declare_properties! { diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 5a5320e66c3..24ac9c870c1 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -2,9 +2,12 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::{mem::MaybeUninit, ptr::NonNull}; +use core::ptr::NonNull; -use qemu_api::bindings::*; +use qemu_api::{ + bindings::*, + zeroable::Zeroable +}; use crate::device::PL011State; @@ -14,11 +17,11 @@ read_with_attrs: None, write_with_attrs: None, endianness: device_endian::DEVICE_NATIVE_ENDIAN, - valid: unsafe { MaybeUninit::::zeroed().assume_init() }, + valid: Zeroable::ZERO, impl_: MemoryRegionOps__bindgen_ty_2 { min_access_size: 4, max_access_size: 4, - ..unsafe { MaybeUninit::::zeroed().assume_init() } + ..Zeroable::ZERO }, }; diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1fc36078027..1b0fd406378 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,6 +5,7 @@ _qemu_api_rs = static_library( 'src/lib.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/zeroable.rs', ], {'.' : bindings_rs}, ), diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index d885f2fcf19..ed2d7ce1a54 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -31,7 +31,7 @@ macro_rules! define_property { offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { @@ -41,7 +41,7 @@ macro_rules! define_property { info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; } @@ -58,7 +58,7 @@ macro_rules! declare_properties { len }] = [ $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, + $crate::zeroable::Zeroable::ZERO, ]; }; } @@ -79,7 +79,7 @@ macro_rules! vm_state_description { $vname.as_ptr() },)* unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::VMStateDescription>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO }; } } diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 6bc68076aae..e94a15bb823 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -29,6 +29,7 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod definitions; pub mod device_class; +pub mod zeroable; use std::alloc::{GlobalAlloc, Layout}; diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs new file mode 100644 index 00000000000..45ec95c9f70 --- /dev/null +++ b/rust/qemu-api/src/zeroable.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/// Encapsulates the requirement that +/// `MaybeUninit::::zeroed().assume_init()` does not cause +/// undefined behavior. +/// +/// # Safety +/// +/// Do not add this trait to a type unless all-zeroes is +/// a valid value for the type. In particular, remember that raw +/// pointers can be zero, but references and `NonNull` cannot +/// unless wrapped with `Option<>`. +pub unsafe trait Zeroable: Default { + /// SAFETY: If the trait was added to a type, then by definition + /// this is safe. + const ZERO: Self = unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() }; +} + +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::Property {} +unsafe impl Zeroable for crate::bindings::VMStateDescription {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} From patchwork Mon Oct 21 16:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13844447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4804D15DBA for ; Mon, 21 Oct 2024 16:37:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2vP7-0007kR-BG; Mon, 21 Oct 2024 12:37:13 -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 1t2vOU-0006Oc-Mm for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:37 -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 1t2vOR-0006MI-IY for qemu-devel@nongnu.org; Mon, 21 Oct 2024 12:36:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729528590; 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=LLppDWV53KItuDjPGr/az+c8hOztlyzUeTjrRwEDn8w=; b=KeTOmW+DrMHb90ndDT0Uzw3R7TVi3rLfT1B2rWezyI3Vo3qxWVabIDTpECS8flJ6xDyAzr ynWs63Qso6ESuBk6KJoUAVWO/xlfuM6gHAF8qbIbxw9Rd9R7DofKLHu6UtyOnj8/pCXn3L 7zvkZ5Ry9PyShEOYb/1rENwgpgy9XE0= 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-311-cyt-7jYsMcqxEEcvUIvI6w-1; Mon, 21 Oct 2024 12:36:29 -0400 X-MC-Unique: cyt-7jYsMcqxEEcvUIvI6w-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315ad4938fso34318985e9.0 for ; Mon, 21 Oct 2024 09:36:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528587; x=1730133387; 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=LLppDWV53KItuDjPGr/az+c8hOztlyzUeTjrRwEDn8w=; b=XwaQsqTrkHQ8Q8PBT74nE2xiuj7rx13DduLtKSIp8dWoccdgqdykFAdd6sreXrvAGv h87q+zCoDYX+RIzymMkg0lFJ/3wobNbjz2SCdtbZHQaaebbExANs1mUtO4/tLnM5Cipb 9sJFDIdFxeSJwVXvm+s/Wp0izscd8UiIT/0U/KNvhNGwRNVggFW81ZsAhvpDrrdQvMKf Q7jjITQ8RGVhm+MwGqANZC3vUtt6L9LjdQoi4qBuWWos3FPX2AMh+I1suEn6BEiZOE9v seojJzRH4fv5HYHX0JRNF1+GQsaPjlrAQtW2IeDAgadGVdRINCAYx3493Cwlm4Ce2tWB bD7A== X-Gm-Message-State: AOJu0Yx+w8XkKIQmUjieJsd+ZKCjUvxIZYwTV6olCuJTzkS1MG5rkxOz oS3p3pr2ve4o67HLbKl7iMAhwcI1kXkBzakPCE4a3ITQDODwcsA7IrnlWG+W4C1ycYnb32k/SJI n0X9SADe8LjQOw3wZ9OULpkOckvol6Rslm66Ftbne9fjN2FLt50aKALaRb9gvyvtHv8nSkQ/1bC NLmgjK8ABgj62uPdYVXlGcs7QNi6N4WZhuGxUNQsc= X-Received: by 2002:adf:f7d1:0:b0:37d:50e1:b3e1 with SMTP id ffacd0b85a97d-37eab6da72emr7715256f8f.16.1729528587139; Mon, 21 Oct 2024 09:36:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0E3RXCUgPvGNLsmyjB1DuEXohlouR9ILqS17064F9Ug1RPc47zYzAaPfTaRs9BJWxTYRhVw== X-Received: by 2002:adf:f7d1:0:b0:37d:50e1:b3e1 with SMTP id ffacd0b85a97d-37eab6da72emr7715242f8f.16.1729528586786; Mon, 21 Oct 2024 09:36:26 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a5c529sm4704753f8f.62.2024.10.21.09.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 09:36:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH v2 13/13] rust: do not use TYPE_CHARDEV unnecessarily Date: Mon, 21 Oct 2024 18:35:38 +0200 Message-ID: <20241021163538.136941-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241021163538.136941-1-pbonzini@redhat.com> References: <20241021163538.136941-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the invocation of qdev_prop_set_chr(), "chardev" is the name of a property rather than a type and has to match the name of the property in device_class.rs. Do not use TYPE_CHARDEV here, just like in the C version of pl011_create. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2b43f5e0939..0f6918dd224 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -572,7 +572,7 @@ pub fn update(&self) { let dev: *mut DeviceState = qdev_new(PL011State::TYPE_INFO.name); let sysbus: *mut SysBusDevice = dev.cast::(); - qdev_prop_set_chr(dev, bindings::TYPE_CHARDEV.as_ptr(), chr); + qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr); sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq);