From patchwork Wed Dec 11 16:26: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: 13903800 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 34FEDE77180 for ; Wed, 11 Dec 2024 16:28:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPYn-0008GZ-FD; Wed, 11 Dec 2024 11:27:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYj-0007sf-MQ for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYg-0000CW-Ue for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934449; 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=Eybao4hIER+UtTO8XJ3/cn/2NUI2ozda1q+92b4PeHk=; b=MVFIS7v734N4sfeNPJe9oOaiBt4OFpvOVD/AS5Orki22q+hl5vhnjMpChly+dXzInImpid Ea1/eLsT9AL9UsbC853f4wvJt0e9G4/m8KMwyjQiGj8tW6PX78xQLh7Fteg/mMggJIUgp3 hi+iRbV9f/NkmCUWEXSRb0Zn6jn8yqY= 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-616-gBYZBtTxMXuAWsAWntThvg-1; Wed, 11 Dec 2024 11:27:27 -0500 X-MC-Unique: gBYZBtTxMXuAWsAWntThvg-1 X-Mimecast-MFC-AGG-ID: gBYZBtTxMXuAWsAWntThvg Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43619b135bcso4467895e9.1 for ; Wed, 11 Dec 2024 08:27:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934445; x=1734539245; 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=Eybao4hIER+UtTO8XJ3/cn/2NUI2ozda1q+92b4PeHk=; b=ibrq67Gt1R2Mtcp+J+ot5L27qx8dQF653SMqTheZx9ZiDV7kF9U1SoAZktsTYZpeAh LoUukbVpIi1w5DY1Z+qp3KqehWdur+L8ix4+pZw3PRL7EnJUzkj48xTDO2eX89B4bK+h wE1UgR1624dIN+AsGarhmHQYbpXzJnoYGBuZXjNuxIO/k5hGGFTfX0yKv+oFqp/BCqUI 5Df8BYdKoxvKJUrO8KXyYvveHLfVwy3YnJocJ+cz1E/bPIEPcPI+ycSHjC8NLOS9kgIX SxkDQ0b66uUnp3e2I4MW7W/HjRIBJQPAzTgR9QhfU6LK02sXXIISm5W9pROIPLLG3Y1w 0j6g== X-Gm-Message-State: AOJu0YzJMycYY9hFgMC4eTCnGhYJXXtRGPBYIbKn1inaripFEMwixzYE dzMo919xn7vFpSv5fZMgdgAHHM65wZR+5V5qfzRgYzk15T/xVujbTLYkBdknJ4FYO0J8mir10Pk KFU6f+9Crc/4Kv/y/AxKbMFSeVsZFW61v+CnlSZqxh2vc8UTU5Ljrjq2K1INnLjC9X3dFyUoiEO YPGY3owkJ+TXBDfhgO9FJ4+ZR7BN97QP8zPgi5 X-Gm-Gg: ASbGnct3Vd29wVHNSSeW+mOqigDhKpj6WpR7X6MsHUNMZz7r8112MhUa5bsX6JVN9M8 jD+vmmo7NXq+pEJaF0nmqjvze8c69FbVu8X+z9dDqyboRlAh1CJt2WosUyWhEsddsVYNyHDM4Yg jcpNGh3SHsmNCPnQ/kCEazjaTTXdHWbjn+q26R6587HWaY/4Zfq9lM5SMSoCr9XiRUT/U+MHmge OpzNHNGq6l7JlcrDe9o/o2/z3fSUlQNsDar+LVYOVNloAEgPMdmJ+E7 X-Received: by 2002:adf:e18a:0:b0:386:2a3b:8aa with SMTP id ffacd0b85a97d-3864cec5c0emr2916453f8f.37.1733934445220; Wed, 11 Dec 2024 08:27:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpMhtghde5G2OcyrdBwiv16Dq4/Y9DU1JcH8yB0KDK2sUGVvszcABphbnH61ucYPeSTeZ5QA== X-Received: by 2002:adf:e18a:0:b0:386:2a3b:8aa with SMTP id ffacd0b85a97d-3864cec5c0emr2916435f8f.37.1733934444794; Wed, 11 Dec 2024 08:27:24 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824a4f4dsm1603306f8f.31.2024.12.11.08.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 01/49] ci: enable rust in the Debian and Ubuntu system build job Date: Wed, 11 Dec 2024 17:26:31 +0100 Message-ID: <20241211162720.320070-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 We have fixed all incompatibilities with older versions of rustc and bindgen. Enable Rust on Debian to check that the minimum supported version of Rust is indeed 1.63.0, and 0.60.x for bindgen. Reviewed-by: Pierrick Bouvier Signed-off-by: Paolo Bonzini --- .gitlab-ci.d/buildtest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 336223484d8..4265a577834 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -40,7 +40,7 @@ build-system-ubuntu: job: amd64-ubuntu2204-container variables: IMAGE: ubuntu2204 - CONFIGURE_ARGS: --enable-docs + CONFIGURE_ARGS: --enable-docs --enable-rust TARGETS: alpha-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build @@ -71,7 +71,7 @@ build-system-debian: job: amd64-debian-container variables: IMAGE: debian - CONFIGURE_ARGS: --with-coroutine=sigaltstack + CONFIGURE_ARGS: --with-coroutine=sigaltstack --enable-rust TARGETS: arm-softmmu i386-softmmu riscv64-softmmu sh4eb-softmmu sparc-softmmu xtensa-softmmu MAKE_CHECK_ARGS: check-build From patchwork Wed Dec 11 16:26: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: 13903793 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 282E7E77180 for ; Wed, 11 Dec 2024 16:27:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPYp-0008Uh-Oi; Wed, 11 Dec 2024 11:27:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYl-000852-2d for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYh-0000Cz-JR for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UZDaJLaXxvNnfQSMhxbd05Wgutxnybe8yELIo6TkQK8=; b=jB8mf7PyQYyNx6g8o9sFHhJLzHK2mVNBjSRV91gML8Fgw8+rAV6H0zuFU0QfoC+oFb8ce4 SrcB+WUAbt/8zw+fZO/Rf6uxWgcI9L4F1EL6af+FpZx7EmfJuWBLxc/7VX9IBHuf6al8az ld3s1dzbb7zS6NUJixY0hGywTjhg10Y= 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-644-ikiZBFv9OhWXBQCYIEKkRA-1; Wed, 11 Dec 2024 11:27:29 -0500 X-MC-Unique: ikiZBFv9OhWXBQCYIEKkRA-1 X-Mimecast-MFC-AGG-ID: ikiZBFv9OhWXBQCYIEKkRA Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e1339790so4748292f8f.2 for ; Wed, 11 Dec 2024 08:27:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934448; x=1734539248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UZDaJLaXxvNnfQSMhxbd05Wgutxnybe8yELIo6TkQK8=; b=eChwZEaZBcTpWzs64dwrQogZ4b15xbRoH9UdmWFFPyw8lT57v6RBPOdggPmF8iNXbg mqAmJz6czToStYPebbYjY7vWO+XaBM+TPCvhRCXj//Cvzhml7PnFpCzefF1g0tRusQ5m 3KG/NLF3cAW4rzU+Tcfw62UN2I/IqSVzVW1jCaN4CCQIVuvLTukdiuEJnQIWiDNIfp8o wTkihBnNKImI8p8DHeh95HeR7V54iLnnVpP5iuJ/XkWMAw0uL8p4SACcWNTbqw6C8vsn duRwxTfxj67GbOte5rPXTX1LSN8cv6kS7oU9zCgOQASPqmudPnY4jpms6Qt9j/B+H/Lt QxDg== X-Gm-Message-State: AOJu0YyT5XhfCzblnLuCB0/oNKa3hDu7L6Gdn9+vCdI0r62RfdzCEFax rjuREJMD7e7we5iWRdzEisSfNJrjeO+0+KTBbVuSBUv6gA2CH0ydu+bf6RXR00jL/wmqluBrE79 iMbvpEBLbbxaeNaxSseGzo1zHCBS6TyVZ3qJaVrJYeZ/QZtZG1yMOOAQhN22e1R4UUBMHN6cEUl WdyYAYtSnG6li/nhzxbnfHI/8/dgWtqY8iJgrT X-Gm-Gg: ASbGncvRMaa3wX75HaHcio0of3R2tQDrO+tzjw+B68/FnK+SMhH+7awVrcPSD+k1J45 06wnOoi1MifO0jKQ8Nzfp4F7J3kADFxTMQIzzRDAlrEE/ahEz8l2q2Yy8h1p9V1VgT9sufyMy8S wJsMYHwslF23YMsEPIGyJZO4F6zNICn1/m1zbCXNXzt3LLgVn/zu4bztIC6MpZ4+/8Ml6YKErgN 4v11A+k3z/3fSaLpdJwN5fCgcsik8yzyIDxQZGId43PLGzWBDC3kDg3 X-Received: by 2002:a5d:6da4:0:b0:386:1ab5:f0e1 with SMTP id ffacd0b85a97d-3864ce968c0mr3420058f8f.14.1733934447963; Wed, 11 Dec 2024 08:27:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IELYwlbdIdIUQ5HDugRJgsVK67zkR1rE8rwXy521OSPCaRokZLBnNJMXfZ/4Sz955gYYC3iaw== X-Received: by 2002:a5d:6da4:0:b0:386:1ab5:f0e1 with SMTP id ffacd0b85a97d-3864ce968c0mr3420029f8f.14.1733934447531; Wed, 11 Dec 2024 08:27:27 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434fc530a2dsm89229625e9.11.2024.12.11.08.27.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/49] rust: apply --cfg MESON to all crates Date: Wed, 11 Dec 2024 17:26:32 +0100 Message-ID: <20241211162720.320070-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 We might have more uses for --cfg MESON, even though right now it's only qemu-api that has generated files. Since we're going to add more flags to the add_project_arguments calls for Rust, it makes sense to also add --cfg MESON everywhere. Signed-off-by: Paolo Bonzini --- meson.build | 7 ++++--- rust/qemu-api/meson.build | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 147097c652e..c35ce64cd61 100644 --- a/meson.build +++ b/meson.build @@ -3422,10 +3422,11 @@ if have_rust # 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'], + add_project_arguments(rustc_args + + ['--cfg', 'MESON', '-C', 'default-linker-libraries'], native: false, language: 'rust') - - add_project_arguments(rustc_args, native: true, language: 'rust') + add_project_arguments(rustc_args + ['--cfg', 'MESON'], + native: true, language: 'rust') endif hxtool = find_program('scripts/hxtool') diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 6f637af7b1b..cad9ac4844e 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,4 +1,4 @@ -_qemu_api_cfg = ['--cfg', 'MESON'] +_qemu_api_cfg = [] # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] if rustc.version().version_compare('>=1.77.0') _qemu_api_cfg += ['--cfg', 'has_offset_of'] From patchwork Wed Dec 11 16:26: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: 13903797 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 D9E51E77180 for ; Wed, 11 Dec 2024 16:28:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZ1-0001Ae-Vt; Wed, 11 Dec 2024 11:27:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYq-0000CL-Eg for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:42 -0500 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 1tLPYn-0000E7-LP for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934456; 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=d0MJJzJuoKLCtrgzhhYnAxB9tG/Gnd42DxE+/anYSSA=; b=FtT4ADe0JX6WREWyYjyzunM2O85cRd2bdNQGGiwwhUt8BQTy3LngBjCTGAEY/ssZaz/5XK zYI17IiO79ZErGepewTrESzVX3pUQ7lbSiQL1tDwn/zM0POyX5uoJZIXOPxpTc1K9gGo6y k77FC6FDKeg93P+NK1nM20WL+RDIBi8= 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-611-7LwxTnuBMP2eeaOB_tSaIw-1; Wed, 11 Dec 2024 11:27:31 -0500 X-MC-Unique: 7LwxTnuBMP2eeaOB_tSaIw-1 X-Mimecast-MFC-AGG-ID: 7LwxTnuBMP2eeaOB_tSaIw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-434f852cb35so4467935e9.0 for ; Wed, 11 Dec 2024 08:27:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934450; x=1734539250; 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=d0MJJzJuoKLCtrgzhhYnAxB9tG/Gnd42DxE+/anYSSA=; b=JoKjmkISlQ3xbuUpjT/EVLHdTmGecCBwrTR6fF9mJ61K1vXdAiNRffJiyNs5fsA61x b2zuF1fKlcYD2QAELhpSRdWbcDYvMkXnn9Pd6vsGkfEMjCPaA2JP/SHFr4724KoSkxMZ YC4kZ7feqqblUogbN8hzADAb3inTFmDwPP5aFQZEhbUCZ+3TACiky2jhWJ4RIlLTwVGM CUMnNIUZAVfdmm2Ls8WukSEZd0mTeBJKcFHtbdqXAPt/vy4QlyFGQvGCCOvei5zyqBHZ 00Tgb7EMHzTonZBEGVZJwLRU0oReMVunTTCIHhVjbQpKh+Ir6tn4fQPjw+FmOUCn3yGb YJWg== X-Gm-Message-State: AOJu0YzDLZ6jB0/MZ+IJcELv//EGYGWocaGPpyatmb9ddG3EV6Ohg8tW NjsAWaJRTcfnQEgs9+3defiyZOj+Nj6pm+1CQXjdOs4UNFgvnRyVTSYzh9iXgQ4YmnXMwyZ202J gMg2/C/+Rc0QMyFRDE+adgo3QFzwCyM9QMVOE6ntReza/nsHP/0v5Q+22RkDdvq/wHRsdBCOYgt rOOy3dH8Py8UqpO5AA9UVkH60+/NOrXOchKSwB X-Gm-Gg: ASbGncsWsv+YLtRNOyS3p76cV0v6beidsb2J7Lg4yxdcSfbELZyJxoRNJigEnhhkSBF NyqCdGLVWswg3jpbA/oQyRQq/cbDS78KQPM5+cpXTkyLZJX6FjG7JShCbEUCJlar/to0COyds43 9/XCHKnEwTQy1wKP7iyCh6FTNOgBeosXNBbjDQoz6QVFc+hrOtNDL2SY2qzeRfnEZg4MOgkBJMe n6y8Z4i7n7hkI0CgcBVq/fT4XBAfxWAhOdGA+C+Pn3SS3TQvv13309/ X-Received: by 2002:a05:600c:cc7:b0:435:194:3cdf with SMTP id 5b1f17b1804b1-4361c3a3055mr28121895e9.19.1733934449896; Wed, 11 Dec 2024 08:27:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IF207w4H+3zBCjU+x+zEs1lBOr7MsJRMmE68rOAaEOTjipch+MUf6E8QG6nPTGrZoBOPnFe9w== X-Received: by 2002:a05:600c:cc7:b0:435:194:3cdf with SMTP id 5b1f17b1804b1-4361c3a3055mr28121615e9.19.1733934449491; Wed, 11 Dec 2024 08:27:29 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361f1dd4b8sm18731095e9.3.2024.12.11.08.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao Subject: [PULL 03/49] rust: allow using build-root bindings.rs from cargo Date: Wed, 11 Dec 2024 17:26:33 +0100 Message-ID: <20241211162720.320070-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Right now, using cargo with QEMU requires copying by hand the bindings.rs to the source tree. Instead, we can use an include file to escape the cage of cargo's mandated source directory structure. By running cargo within meson's "devenv" and adding a MESON_BUILD_ROOT environment variable, it is easy for build.rs to find the file. However, the file must be symlinked into cargo's output directory for rust-analyzer to find it. Suggested-by: Junjie Mao Signed-off-by: Paolo Bonzini --- meson.build | 4 +++- rust/hw/char/pl011/.gitignore | 2 -- rust/qemu-api/.gitignore | 2 +- rust/qemu-api/README.md | 4 ++-- rust/qemu-api/build.rs | 34 +++++++++++++++++++++++++++------- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/bindings.rs | 29 +++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 22 ---------------------- 8 files changed, 63 insertions(+), 35 deletions(-) delete mode 100644 rust/hw/char/pl011/.gitignore create mode 100644 rust/qemu-api/src/bindings.rs diff --git a/meson.build b/meson.build index c35ce64cd61..ea211c2dbb4 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,8 @@ project('qemu', ['c'], meson_version: '>=1.5.0', 'b_staticpic=false', 'stdsplit=false', 'optimization=2', 'b_pie=true'], version: files('VERSION')) +meson.add_devenv({ 'MESON_BUILD_ROOT' : meson.project_build_root() }) + add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true) add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow']) add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough']) @@ -4090,7 +4092,7 @@ if have_rust bindings_rs = rust.bindgen( input: 'rust/wrapper.h', dependencies: common_ss.all_dependencies(), - output: 'bindings.rs', + output: 'bindings.inc.rs', include_directories: include_directories('.', 'include'), bindgen_version: ['>=0.60.0'], args: bindgen_args, diff --git a/rust/hw/char/pl011/.gitignore b/rust/hw/char/pl011/.gitignore deleted file mode 100644 index 71eaff2035d..00000000000 --- a/rust/hw/char/pl011/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore generated bindings file overrides. -src/bindings.rs.inc diff --git a/rust/qemu-api/.gitignore b/rust/qemu-api/.gitignore index b9e7e004c86..df6c2163e03 100644 --- a/rust/qemu-api/.gitignore +++ b/rust/qemu-api/.gitignore @@ -1,2 +1,2 @@ # Ignore generated bindings file overrides. -src/bindings.rs +/src/bindings.inc.rs diff --git a/rust/qemu-api/README.md b/rust/qemu-api/README.md index 7588fa29ef3..53810f48882 100644 --- a/rust/qemu-api/README.md +++ b/rust/qemu-api/README.md @@ -5,7 +5,7 @@ This library exports helper Rust types, Rust macros and C FFI bindings for inter The C bindings can be generated with `bindgen`, using this build target: ```console -$ ninja bindings.rs +$ ninja bindings.inc.rs ``` ## Generate Rust documentation @@ -13,5 +13,5 @@ $ ninja bindings.rs To generate docs for this crate, including private items: ```sh -cargo doc --no-deps --document-private-items +pyvenv/bin/meson devenv -w ../rust cargo doc --no-deps --document-private-items ``` diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 20f8f718b90..40644d5e4fe 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -2,22 +2,42 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::path::Path; +#[cfg(unix)] +use std::os::unix::fs::symlink as symlink_file; +#[cfg(windows)] +use std::os::windows::fs::symlink_file; +use std::{env, fs::remove_file, io::Result, path::Path}; use version_check as rustc; -fn main() { - if !Path::new("src/bindings.rs").exists() { - panic!( - "No generated C bindings found! Either build them manually with bindgen or with meson \ - (`ninja bindings.rs`) and copy them to src/bindings.rs, or build through meson." - ); +fn main() -> Result<()> { + // Placing bindings.inc.rs in the source directory is supported + // but not documented or encouraged. + let path = env::var("MESON_BUILD_ROOT") + .unwrap_or_else(|_| format!("{}/src", env!("CARGO_MANIFEST_DIR"))); + + let file = format!("{}/bindings.inc.rs", path); + let file = Path::new(&file); + if !Path::new(&file).exists() { + panic!(concat!( + "No generated C bindings found! If you want to run `cargo`, start a subshell\n", + "with `meson devenv`, or point MESON_BUILD_ROOT to the top of the build tree." + )); } + let out_dir = env::var("OUT_DIR").unwrap(); + let dest_path = format!("{}/bindings.inc.rs", out_dir); + let dest_path = Path::new(&dest_path); + if dest_path.symlink_metadata().is_ok() { + remove_file(dest_path)?; + } + symlink_file(file, dest_path)?; + // Check for available rustc features if rustc::is_min_version("1.77.0").unwrap_or(false) { println!("cargo:rustc-cfg=has_offset_of"); } println!("cargo:rerun-if-changed=build.rs"); + Ok(()) } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index cad9ac4844e..3be7b7e5ced 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -9,6 +9,7 @@ _qemu_api_rs = static_library( structured_sources( [ 'src/lib.rs', + 'src/bindings.rs', 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs new file mode 100644 index 00000000000..0b76ec58bee --- /dev/null +++ b/rust/qemu-api/src/bindings.rs @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#![allow( + dead_code, + improper_ctypes_definitions, + improper_ctypes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unsafe_op_in_unsafe_fn, + clippy::missing_const_for_fn, + clippy::too_many_arguments, + clippy::approx_constant, + clippy::use_self, + clippy::useless_transmute, + clippy::missing_safety_doc +)] + +#[cfg(MESON)] +include!("bindings.inc.rs"); + +#[cfg(not(MESON))] +include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs")); + +unsafe impl Send for Property {} +unsafe impl Sync for Property {} +unsafe impl Sync for TypeInfo {} +unsafe impl Sync for VMStateDescription {} +unsafe impl Sync for VMStateField {} +unsafe impl Sync for VMStateInfo {} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index aa8d16ec94b..440aff3817d 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -4,31 +4,9 @@ #![cfg_attr(not(MESON), doc = include_str!("../README.md"))] -#[allow( - dead_code, - improper_ctypes_definitions, - improper_ctypes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unsafe_op_in_unsafe_fn, - clippy::missing_const_for_fn, - clippy::too_many_arguments, - clippy::approx_constant, - clippy::use_self, - clippy::useless_transmute, - clippy::missing_safety_doc, -)] #[rustfmt::skip] pub mod bindings; -unsafe impl Send for bindings::Property {} -unsafe impl Sync for bindings::Property {} -unsafe impl Sync for bindings::TypeInfo {} -unsafe impl Sync for bindings::VMStateDescription {} -unsafe impl Sync for bindings::VMStateField {} -unsafe impl Sync for bindings::VMStateInfo {} - pub mod c_str; pub mod definitions; pub mod device_class; From patchwork Wed Dec 11 16:26: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: 13903826 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 8F6FFE7717D for ; Wed, 11 Dec 2024 16:31:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPYv-0000aY-UE; Wed, 11 Dec 2024 11:27:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYo-0008TQ-Kf for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYm-0000Dz-Kr for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kc+3yZr1fEE4Vxs7y1Ixn7frgKT0doT0bC1xM2Vun5Y=; b=aj7vBrSy2Y/12++YY9pDuNBoN7gOuNCCFyOAgHrm4GpzMCJXtUmXwJRsIq/Q4kYtge0NRy 6LWD4PvPi9zVATBlnAIDiH87xLYVLLDjznYRo9bD9voZfMSZbOEwcpCyLbgihE5XPbp4Gl iJpPXaqi5FwNH+vPMOinyXEHx9tZ//Q= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-mO4S-atpOYa4CJgOsniUDQ-1; Wed, 11 Dec 2024 11:27:34 -0500 X-MC-Unique: mO4S-atpOYa4CJgOsniUDQ-1 X-Mimecast-MFC-AGG-ID: mO4S-atpOYa4CJgOsniUDQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3861cd03a89so3250138f8f.1 for ; Wed, 11 Dec 2024 08:27:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934452; x=1734539252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kc+3yZr1fEE4Vxs7y1Ixn7frgKT0doT0bC1xM2Vun5Y=; b=Znpg+DK1CfiC/v+OfuG4D+tMf2OOZcPewq2neeJd6T4NGOnSAoELrF7QpqA7bQYdZY l+gPgZ9BpJqEtvTeCz6UNwwyypLmaLLqBCRjnHlTB988tx18LEyGMrbhSgQtX/PYyX3Y eXlE/s75Q8wBw/KD9bLiXE/sy2OuopYeA4MoRo5afW9xbYmuYibdt8pQXn2/J5piBaU+ BhY67SVMdsv5RPETv+GOIl1EyisTLflSF1pB1TEC6RW2LqjdcSf3ehxYuHWm2JcNsryZ zc/FOYBxtV0cNmWFhsUIv8GZYfAJmp1SoIMnP6eFiugJEssy4ELMLRfjE6XPRDnHxjCy tCkQ== X-Gm-Message-State: AOJu0Yzr5JcvXwV9DE3pl3vEq8YlAhhnVCSaXSkL7Z0XbhH1biNZSMZr uLTgJ23hzoXi6ofXl03DGjaA1OwSoofGdgDgBCaUBhOIYGnhqa3dutg62u1hR1R1V3xibzOoZqU s4WcTDq1oh+UD0hYIu3D/WPsjfBYR+5GtgNxIVVaWlRbpIVN1R0f6wRFlQP10WLKaYZmkNHDPMB 1mGHXvshC3iefO2LM459ghQrBAU4O2mKAAvA33 X-Gm-Gg: ASbGncuhylw7mEcumP6Ttom50Rlau/qWVgC7WrptRPUkrEDRWdq8ORVNAurzUsqolTG I1gzvM/Y8syy2IucI3bNu32JLw8z/S5vHK47sn6D8gIEBL7TnYhzUZuyrdpK9ZmErdjCEECNbtr eIUaS3lm0lTZNnqm7EEfzwDY9ZjQRN/sd/uHERLBA7po4FrIFNE++0SW2izFqILYi/iZtCj+/OK N2/+Ojhw6Q0qdd0RH4JuPUDMk3bMGdKu+VjVIzO/5WgAvyY3IU+ZBDx X-Received: by 2002:a05:6000:1fad:b0:385:f527:be6d with SMTP id ffacd0b85a97d-387876af7demr219735f8f.36.1733934452536; Wed, 11 Dec 2024 08:27:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWVPZ0dEUNvTFXm4EY7w2EG3OqTg1SYd3ymQqxQ8jtlB+dr9UMyOrLBDJ6eed81aoOuVak/Q== X-Received: by 2002:a05:6000:1fad:b0:385:f527:be6d with SMTP id ffacd0b85a97d-387876af7demr219710f8f.36.1733934452069; Wed, 11 Dec 2024 08:27:32 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436178bd62dsm48509675e9.36.2024.12.11.08.27.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/49] rust: build: move rustc_args.py invocation to qemu-api crate Date: Wed, 11 Dec 2024 17:26:34 +0100 Message-ID: <20241211162720.320070-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Only qemu-api needs access to the symbols in config-host.h. Remove the temptation to use them elsewhere by limiting the --cfg arguments to the qemu-api crate. Per-crate invocation of the script will also be needed to add --check-cfg options for each crate's features (when more complex, build-time configurable devices are added in the future). Signed-off-by: Paolo Bonzini --- meson.build | 56 +++++++++++++++++---------------------- rust/qemu-api/meson.build | 5 +++- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/meson.build b/meson.build index ea211c2dbb4..2f1f2aece4d 100644 --- a/meson.build +++ b/meson.build @@ -120,7 +120,30 @@ if have_rust endif if have_rust + rustc_args = find_program('scripts/rust/rustc_args.py') rustfmt = find_program('rustfmt', required: false) + + # Prohibit code that is forbidden in Rust 2024 + rustc_lint_args = ['-D', 'unsafe_op_in_unsafe_fn'] + + # Occasionally, we may need to silence warnings and clippy lints that + # were only introduced in newer Rust compiler versions. Do not croak + # in that case; a CI job with rust_strict_lints == true ensures that + # we do not have misspelled allow() attributes. + if not get_option('strict_rust_lints') + rustc_lint_args += ['-A', 'unknown_lints'] + endif + + # 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_lint_args + + ['--cfg', 'MESON', '-C', 'default-linker-libraries'], + native: false, language: 'rust') + add_project_arguments(rustc_lint_args + ['--cfg', 'MESON'], + native: true, language: 'rust') endif dtrace = not_found @@ -3399,37 +3422,8 @@ endif # Generated sources # ##################### -genh += configure_file(output: 'config-host.h', configuration: config_host_data) - -if have_rust - 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'] - - # Occasionally, we may need to silence warnings and clippy lints that - # were only introduced in newer Rust compiler versions. Do not croak - # in that case; a CI job with rust_strict_lints == true ensures that - # we do not have misspelled allow() attributes. - if not get_option('strict_rust_lints') - rustc_args += ['-A', 'unknown_lints'] - endif - - # 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 + - ['--cfg', 'MESON', '-C', 'default-linker-libraries'], - native: false, language: 'rust') - add_project_arguments(rustc_args + ['--cfg', 'MESON'], - native: true, language: 'rust') -endif +config_host_h = configure_file(output: 'config-host.h', configuration: config_host_data) +genh += config_host_h hxtool = find_program('scripts/hxtool') shaderinclude = find_program('scripts/shaderinclude.py') diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 3be7b7e5ced..5df6b35bf88 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,4 +1,7 @@ -_qemu_api_cfg = [] +_qemu_api_cfg = run_command(rustc_args, + '--config-headers', config_host_h, + capture: true, check: true).stdout().strip().split() + # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] if rustc.version().version_compare('>=1.77.0') _qemu_api_cfg += ['--cfg', 'has_offset_of'] From patchwork Wed Dec 11 16:26: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: 13903810 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 EA63FE77182 for ; Wed, 11 Dec 2024 16:28:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPYy-0000sB-JW; Wed, 11 Dec 2024 11:27:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYq-0000B0-6a for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:41 -0500 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 1tLPYo-0000EO-28 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C3gKLyE/tjMRxcMCdanJmcUrY5p/mjIojvO+9H4ft54=; b=P44DolZAZXaTq7JAQKYdnBJMOVUZLFFloGbi7ZfEUVMjm/mwcN1mrqSOl9mIzwV5TQj8It eFj/Myi5letSW0YIKg1z/6g2YqZpwVz+Mx7hFVIQ/RxOAl1Pvs1RirFIlW0YT61t/nfLgM NNSkw2/z7l0LsZAEKcm5IxcJ006EACw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-jtX8riAZOqGy9IQH4Dgv6w-1; Wed, 11 Dec 2024 11:27:35 -0500 X-MC-Unique: jtX8riAZOqGy9IQH4Dgv6w-1 X-Mimecast-MFC-AGG-ID: jtX8riAZOqGy9IQH4Dgv6w Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385df115288so2971991f8f.2 for ; Wed, 11 Dec 2024 08:27:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934454; x=1734539254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C3gKLyE/tjMRxcMCdanJmcUrY5p/mjIojvO+9H4ft54=; b=pC6oy+1OOYlohFrfG5xDFUR7aDMIaUG72yZx+jlHuooOrSBqnQDdDbund2W5jSeUIu t8wqEpgYqa5sLczXKEvIUz7ahoCU3DgnrCY2eevZuxFjLA+QWAxoYIm3S4cZuKxI9xk0 NHnT8fHCqZ5xYnkXkJQ49INYieZF8Bptz4YhjLQQu+GgmCk/hqqNQWS0rxN5sCnCVBRy VmgX/l15aQDXwiy6rWdaK8ZM4g/3WyFM99puX4LGML/FubUPrlHDNBHlMjgOPdz97A8t 24CGwK7OGBe0oSZLg+IlGQEmzMNli3dpGReI2Y0WpmNax2O2lCbV1XS2yj/se5qw2cBo 8V1w== X-Gm-Message-State: AOJu0YyNvRwW6UafDR/wFsZ9m2GPdjCJXv5jNFKbAewMQ/C/lRSePa4O KxSxsCy1PHalb6pm4AU7tHqTPURiXTFz6ZbZM+Enl4/+MU6GH2LqRqdPaw/Kwfkhyut2wq6gGHh jBUiRiPH1Gbx+L/GNXbxU20A0QuaLyAjkIPxo17l44XB24lihPjbqRWjoPNgPB5frDbC/BhtGbN ZPMpIpXvxcQjkjNVbmprR188BbeVThP3ftQqMj X-Gm-Gg: ASbGnctx0jjp1O5+3YkLQmcyFKl2lDj7mAAoXQteXX3ItnWlj/jL2LaZPe3eolM4Av3 NOKgnXy/xRO6GTVf/6IFc1Q+EFak0/+sbbTaOt0QajZUH9PKA3zyPlBf/Lw2ucH4/TAu2D7eeGF 6n8CslEOwHB5OoIv8ctbwDo0xmvWVPpcivdGdw3FUg6zwAPjDWm3fDkfvvAdZHDjGCor9wzp3wX PbYTsy2kKN7XX6V9UU1i3UbwrDK+t6sebtXcgbgP8fAj7i3mgoC6ppG X-Received: by 2002:a5d:6da4:0:b0:385:e0ea:d4ef with SMTP id ffacd0b85a97d-3864cea1edcmr2490334f8f.58.1733934454217; Wed, 11 Dec 2024 08:27:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGXbScukZBJmV0tcqFwx+LRTdB21ClwwYtGiCA0uqYHHQLS1ae7QzI3Fac+y6iFlaeThMs2A== X-Received: by 2002:a5d:6da4:0:b0:385:e0ea:d4ef with SMTP id ffacd0b85a97d-3864cea1edcmr2490309f8f.58.1733934453815; Wed, 11 Dec 2024 08:27:33 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824a3e38sm1614427f8f.23.2024.12.11.08.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/49] rust: build: restrict --cfg generation to only required symbols Date: Wed, 11 Dec 2024 17:26:35 +0100 Message-ID: <20241211162720.320070-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Parse the Cargo.toml file, looking for the unexpected_cfgs configuration. When generating --cfg options from the config-host.h file, only use those that are included in the configuration. Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 2 +- scripts/rust/rustc_args.py | 61 ++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 5df6b35bf88..2ff6d2ce3d0 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,5 +1,5 @@ _qemu_api_cfg = run_command(rustc_args, - '--config-headers', config_host_h, + '--config-headers', config_host_h, files('Cargo.toml'), capture: true, check: true).stdout().strip().split() # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index e4cc9720e16..942dd2b2bab 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -26,30 +26,51 @@ import argparse import logging +from pathlib import Path +from typing import Any, Iterable, Mapping, Optional, Set -from typing import List +try: + import tomllib +except ImportError: + import tomli as tomllib -def generate_cfg_flags(header: str) -> List[str]: +class CargoTOML: + tomldata: Mapping[Any, Any] + check_cfg: Set[str] + + def __init__(self, path: str): + with open(path, 'rb') as f: + self.tomldata = tomllib.load(f) + + self.check_cfg = set(self.find_check_cfg()) + + def find_check_cfg(self) -> Iterable[str]: + toml_lints = self.lints + rust_lints = toml_lints.get("rust", {}) + cfg_lint = rust_lints.get("unexpected_cfgs", {}) + return cfg_lint.get("check-cfg", []) + + @property + def lints(self) -> Mapping[Any, Any]: + return self.get_table("lints") + + def get_table(self, key: str) -> Mapping[Any, Any]: + table = self.tomldata.get(key, {}) + + return table + + +def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]: """Converts defines from config[..].h headers to rustc --cfg flags.""" - def cfg_name(name: str) -> str: - """Filter function for C #defines""" - if ( - name.startswith("CONFIG_") - or name.startswith("TARGET_") - or name.startswith("HAVE_") - ): - return name - return "" - with open(header, encoding="utf-8") as cfg: config = [l.split()[1:] for l in cfg if l.startswith("#define")] cfg_list = [] for cfg in config: - name = cfg_name(cfg[0]) - if not name: + name = cfg[0] + if f'cfg({name})' not in cargo_toml.check_cfg: continue if len(cfg) >= 2 and cfg[1] != "1": continue @@ -59,7 +80,6 @@ def cfg_name(name: str) -> str: def main() -> None: - # pylint: disable=missing-function-docstring parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action="store_true") parser.add_argument( @@ -71,12 +91,21 @@ def main() -> None: required=False, default=[], ) + parser.add_argument( + metavar="TOML_FILE", + action="store", + dest="cargo_toml", + help="path to Cargo.toml file", + ) args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) logging.debug("args: %s", args) + + cargo_toml = CargoTOML(args.cargo_toml) + for header in args.config_headers: - for tok in generate_cfg_flags(header): + for tok in generate_cfg_flags(header, cargo_toml): print(tok) From patchwork Wed Dec 11 16:26: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: 13903803 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 65D94E77182 for ; Wed, 11 Dec 2024 16:28:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZ5-0001fR-Nn; Wed, 11 Dec 2024 11:27:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYu-0000VH-Ce for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:44 -0500 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 1tLPYq-0000F2-Qt for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+KSm+Bbgkjh6xkJkmH8LuJ1hbwlcHQrSiZuvza+mjs=; b=Zd1W/44us+q9lBFz2LDiSdQItJK3R+vNJ3znRk5s8xo2aBsm5G3O+SgiO3zObo4MUhSvQS X0b0asYlfR7F+rvFZgaBMbd5Rb5oMZIW1TbvWYGlPKM6iKrvmWobQFTc5dlC+634EHiS/4 2r57PP75G3C7C7vrr1ExM4hy0Ka8FBc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-Ew-Mg1QTMTKX1TSoKTGDmw-1; Wed, 11 Dec 2024 11:27:37 -0500 X-MC-Unique: Ew-Mg1QTMTKX1TSoKTGDmw-1 X-Mimecast-MFC-AGG-ID: Ew-Mg1QTMTKX1TSoKTGDmw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385e03f54d0so374150f8f.3 for ; Wed, 11 Dec 2024 08:27:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934456; x=1734539256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W+KSm+Bbgkjh6xkJkmH8LuJ1hbwlcHQrSiZuvza+mjs=; b=gApdWBFdy+c/4goy8oTbQRjCvVMGgEmZ9uUhF98MbDDeiXjeqySp5uy3WpwaAFlwDt L6Y7dQOdIGGyU2X/NNdps9gcWXLf4mhrLfQUsW3zuOYytGiUvGTmC72JOUTgqp9GgWFz kBRlodHu5OYvO9rCDvmvOpAyDOfTHs4VtWUrWiz563V66cA8dSC3pCLzAGFY+xqMpPCo rtElz3siQiNdjxpISzCNh/Q6s+jRcy35yK6FilQlk7a6nIvkOghN+WutEr2+NuGOQf9T KmkMBu//Ls1Pumked3imHuVidJEsYI+Fxo5+8zMCaqU+IHPN/o62CBNfq3+BxifHci1g Wq3A== X-Gm-Message-State: AOJu0Ywj5DWAJIevE7FeHNXQ+8fZAR5J090kU1GZPXaru0eOYyJUkJdO qHizudpV7UpI4gIR3tis3I9Xvkyu7CgPxRynRgrO5dJ+DsZEFnTrb9sE/5oUveaqHrgVsD/2nQ5 6cRU+0/cuFabgO508pwRs1nLwmE/ev4svOczYBN41z58KsAacqCNOd0q+D8mnNlxyaH3bHjGwzm X06NS0UE5Qt7OItgnjxTCoEwevHvCa5UGD2PUH X-Gm-Gg: ASbGnct+2SF0qv+a4aTTQirg8/B8QKRo+H//4HyVBX6uXD3d4zcP4z5cDkrZ3e9n7fN /2okY7nkr6Q/8M9rBx2bO0Ia73IrEahTUpxMZy1cRK2vQsihPZaNFWHJYA6b2NJFmyiu5zpiBGN oipCyx3faNHg0qNQW8vdUtgvI3ic///yNeLSU5Fmhilwg8mX/gqEojh9bB81RHp4xkM6bRmEKfY 01ndIxlrJTGZ/Hy74d2WsqwCJPgGwdo3OlwrDMeZ01hGLFzoXcZhBbD X-Received: by 2002:a05:6000:2a7:b0:385:e17a:ce61 with SMTP id ffacd0b85a97d-3864ced37d6mr3463213f8f.53.1733934456099; Wed, 11 Dec 2024 08:27:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE28wpQAp7PzxHpAIfTHwYeSW9kVTW2HCZP4xPiqLGxMUDODANToF2Tb6m70R59/f/ii9r0uQ== X-Received: by 2002:a05:6000:2a7:b0:385:e17a:ce61 with SMTP id ffacd0b85a97d-3864ced37d6mr3463194f8f.53.1733934455592; Wed, 11 Dec 2024 08:27:35 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824a4ea3sm1618415f8f.28.2024.12.11.08.27.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/49] rust: build: generate lint flags from Cargo.toml Date: Wed, 11 Dec 2024 17:26:36 +0100 Message-ID: <20241211162720.320070-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Cargo.toml makes it possible to describe the desired lint level settings in a nice format. We can extend this to Meson-built crates, by teaching rustc_args.py to fetch lint and --check-cfg arguments from Cargo.toml. --check-cfg arguments come from the unexpected_cfgs lint as well as crate features Start with qemu-api, since it already has a [lints.rust] table and an invocation of rustc_args.py. Signed-off-by: Paolo Bonzini --- meson.build | 3 +- rust/qemu-api/meson.build | 4 +- scripts/rust/rustc_args.py | 83 +++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 2f1f2aece4d..1e1d8f5cd61 100644 --- a/meson.build +++ b/meson.build @@ -120,7 +120,8 @@ if have_rust endif if have_rust - rustc_args = find_program('scripts/rust/rustc_args.py') + rustc_args = [find_program('scripts/rust/rustc_args.py'), + '--rustc-version', rustc.version()] rustfmt = find_program('rustfmt', required: false) # Prohibit code that is forbidden in Rust 2024 diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 2ff6d2ce3d0..1ed79672cc9 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,6 +1,6 @@ _qemu_api_cfg = run_command(rustc_args, - '--config-headers', config_host_h, files('Cargo.toml'), - capture: true, check: true).stdout().strip().split() + '--config-headers', config_host_h, '--features', '--lints', files('Cargo.toml'), + capture: true, check: true).stdout().strip().splitlines() # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] if rustc.version().version_compare('>=1.77.0') diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 942dd2b2bab..9b9778a1cac 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -25,9 +25,10 @@ """ import argparse +from dataclasses import dataclass import logging from pathlib import Path -from typing import Any, Iterable, Mapping, Optional, Set +from typing import Any, Iterable, List, Mapping, Optional, Set try: import tomllib @@ -61,6 +62,45 @@ def get_table(self, key: str) -> Mapping[Any, Any]: return table +@dataclass +class LintFlag: + flags: List[str] + priority: int + + +def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]: + """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags.""" + + toml_lints = cargo_toml.lints + + lint_list = [] + for k, v in toml_lints.items(): + prefix = "" if k == "rust" else k + "::" + for lint, data in v.items(): + level = data if isinstance(data, str) else data["level"] + priority = 0 if isinstance(data, str) else data.get("priority", 0) + if level == "deny": + flag = "-D" + elif level == "allow": + flag = "-A" + elif level == "warn": + flag = "-W" + elif level == "forbid": + flag = "-F" + else: + raise Exception(f"invalid level {level} for {prefix}{lint}") + + # This may change if QEMU ever invokes clippy-driver or rustdoc by + # hand. For now, check the syntax but do not add non-rustc lints to + # the command line. + if k == "rust": + lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority)) + + lint_list.sort(key=lambda x: x.priority) + for lint in lint_list: + yield from lint.flags + + def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]: """Converts defines from config[..].h headers to rustc --cfg flags.""" @@ -97,13 +137,54 @@ def main() -> None: dest="cargo_toml", help="path to Cargo.toml file", ) + parser.add_argument( + "--features", + action="store_true", + dest="features", + help="generate --check-cfg arguments for features", + required=False, + default=None, + ) + parser.add_argument( + "--lints", + action="store_true", + dest="lints", + help="generate arguments from [lints] table", + required=False, + default=None, + ) + parser.add_argument( + "--rustc-version", + metavar="VERSION", + dest="rustc_version", + action="store", + help="version of rustc", + required=False, + default="1.0.0", + ) args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) logging.debug("args: %s", args) + rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2])) cargo_toml = CargoTOML(args.cargo_toml) + if args.lints: + for tok in generate_lint_flags(cargo_toml): + print(tok) + + if rustc_version >= (1, 80): + if args.lints: + for cfg in sorted(cargo_toml.check_cfg): + print("--check-cfg") + print(cfg) + if args.features: + for feature in cargo_toml.get_table("features"): + if feature != "default": + print("--check-cfg") + print(f'cfg(feature,values("{feature}"))') + for header in args.config_headers: for tok in generate_cfg_flags(header, cargo_toml): print(tok) From patchwork Wed Dec 11 16:26: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: 13903843 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 E2457E77183 for ; Wed, 11 Dec 2024 16:34:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZ0-00016I-Q7; Wed, 11 Dec 2024 11:27:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYu-0000VG-CU for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYr-0000FT-VT for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TD2OQfcDeDK+qzjMiwaAvgNRIwj56WMqMTyfSuDOEV4=; b=BooAoaGkIyM4JR+hqFLF0feOqTId6zy+0QnRVaFtvmU1OxPY1VGIuDPGd3LfmYQ4jkMKjv QdwnDHvd4mIxK4jLlkDnlonw2ZG1U3ppQxMLWpqWde2W+6vNVT18IFzIeKvahgKQ1LKIVE yfvnNJMXAvavmHYh82MV3Oq3a2eRzM4= 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-272-Abn0R33vO0eugTBPB2aV7A-1; Wed, 11 Dec 2024 11:27:39 -0500 X-MC-Unique: Abn0R33vO0eugTBPB2aV7A-1 X-Mimecast-MFC-AGG-ID: Abn0R33vO0eugTBPB2aV7A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso7260885e9.2 for ; Wed, 11 Dec 2024 08:27:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934458; x=1734539258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TD2OQfcDeDK+qzjMiwaAvgNRIwj56WMqMTyfSuDOEV4=; b=NxVNKwonilwQ2IK52Pq/UkJ+ACH09PZv88zIraHtNvXj2qOUc/V1Dfiqz1IQGmItmQ PM3Sfo7cB0sIk5zWeTOMfxaXvkZ7J3tR9MMVslvhwcy/I3BZ1DRg3EF5RRI319u9bTjf A0Galf8V+6+Zeam24Sr7R+1YJBjBR7+zmCKZuebmYxjCvaBUmIXwZLmU/PXEfqHdvRKK Y0lUXyeSI7+iSM7lxNt7UeNXkBHMkzKlqVZWNYCfm1QHH4/oK0Ps+4q37OFlbJLwIwWM 5ikSLCGHJIeafkOIscFvrD0oke3TEqNAvzo+MsLGSC6JhFCSNqakLIqibo/7dpQQMYMm I3lw== X-Gm-Message-State: AOJu0YxAYXAW1/eyhJpnni55/dunD4eREPRslMr7h3IJ5uZkcjvq7MGy CvYDwIaP7u2t3ZnMvPevfLc1vnJsTlJm98o/JOqXdqKeru1irLHWdyXkivf7b6Jw0E0nKzW3dHx /RcIXVR513PxuIDs9ZWgzMHvCEQwrzveR3iCSdHHD7KcE2xLx+2U4w7AXr+gASspO1mnfKVvn5j TMNO6NqX/KoWeY1A4d6OUmQ4c5mPFb0gEO7b/o X-Gm-Gg: ASbGnctsDgOJBVIgrYMYB8Wt1uwDO5TlIXATyylBRtbv12sEnQcb3iMzBBHXGWLMZh6 McMkDVKIFl1BiiU1A/5ygT3auOKpZ+sjWvPvniLc7OVvxyhoAVnb3uUiwmbxcrTnfwsmuxEopkb vJ2/+jgjcSOPxZYxZco2jatIbrpbExshHpoT0z4bMekxXfmKIb3FUEVUZfRavM5OE20ouOFC9Qt NPgO2uYBRcTR1Qssi5I+O4H8gmaflVR3/t5rDXjKsfonG6MvBOI/2fg X-Received: by 2002:a05:600c:b86:b0:434:a160:3647 with SMTP id 5b1f17b1804b1-4361c3741f3mr28531175e9.12.1733934458058; Wed, 11 Dec 2024 08:27:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGQ5WZgdElr7KLoROJjvPzc2comx82hrPu6QpRjt27+5NzyjopCNJrj0W0hA2ThjYzZcgyRg== X-Received: by 2002:a05:600c:b86:b0:434:a160:3647 with SMTP id 5b1f17b1804b1-4361c3741f3mr28530905e9.12.1733934457490; Wed, 11 Dec 2024 08:27:37 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-435c1833d67sm53331045e9.5.2024.12.11.08.27.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/49] rust: cargo: store desired warning levels in workspace Cargo.toml Date: Wed, 11 Dec 2024 17:26:37 +0100 Message-ID: <20241211162720.320070-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 An extra benefit of workspaces is that they allow to place lint level settings in a single Cargo.toml; the settings are then inherited by packages in the workspace. Correspondingly, teach rustc_args.py to get the unexpected_cfgs configuration from the workspace Cargo.toml. Note that it is still possible to allow or deny warnings per crate or module, via the #![] attribute syntax. The rust/qemu-api/src/bindings.rs file is an example. Signed-off-by: Paolo Bonzini --- meson.build | 7 +++--- rust/Cargo.toml | 8 +++++++ rust/hw/char/pl011/Cargo.toml | 3 +++ rust/qemu-api-macros/Cargo.toml | 3 +++ rust/qemu-api/Cargo.toml | 5 ++--- rust/qemu-api/meson.build | 2 +- scripts/rust/rustc_args.py | 38 +++++++++++++++++++++++++++------ 7 files changed, 53 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 1e1d8f5cd61..218ae441e38 100644 --- a/meson.build +++ b/meson.build @@ -121,11 +121,12 @@ endif if have_rust rustc_args = [find_program('scripts/rust/rustc_args.py'), - '--rustc-version', rustc.version()] + '--rustc-version', rustc.version(), + '--workspace', meson.project_source_root() / 'rust'] rustfmt = find_program('rustfmt', required: false) - # Prohibit code that is forbidden in Rust 2024 - rustc_lint_args = ['-D', 'unsafe_op_in_unsafe_fn'] + rustc_lint_args = run_command(rustc_args, '--lints', + capture: true, check: true).stdout().strip().splitlines() # Occasionally, we may need to silence warnings and clippy lints that # were only introduced in newer Rust compiler versions. Do not croak diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0c94d5037da..4bb52bf0bd5 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,3 +5,11 @@ members = [ "qemu-api", "hw/char/pl011", ] + +[workspace.lints.rust] +unexpected_cfgs = { level = "deny", check-cfg = [ + 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', + 'cfg(has_offset_of)'] } + +# Prohibit code that is forbidden in Rust 2024 +unsafe_op_in_unsafe_fn = "deny" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index a373906b9fb..58f3e859f7e 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -21,3 +21,6 @@ bilge = { version = "0.2.0" } bilge-impl = { version = "0.2.0" } qemu_api = { path = "../../../qemu-api" } qemu_api_macros = { path = "../../../qemu-api-macros" } + +[lints] +workspace = true diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.toml index a8f7377106b..5a27b52ee6e 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -20,3 +20,6 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["extra-traits"] } + +[lints] +workspace = true diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index cc716d75d46..669f288d1cb 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -23,6 +23,5 @@ version_check = "~0.9" default = [] allocator = [] -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', - 'cfg(has_offset_of)'] } +[lints] +workspace = true diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1ed79672cc9..d719c13f46d 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,5 +1,5 @@ _qemu_api_cfg = run_command(rustc_args, - '--config-headers', config_host_h, '--features', '--lints', files('Cargo.toml'), + '--config-headers', config_host_h, '--features', files('Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 9b9778a1cac..9df131a02bd 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -38,11 +38,21 @@ class CargoTOML: tomldata: Mapping[Any, Any] + workspace_data: Mapping[Any, Any] check_cfg: Set[str] - def __init__(self, path: str): - with open(path, 'rb') as f: - self.tomldata = tomllib.load(f) + def __init__(self, path: Optional[str], workspace: Optional[str]): + if path is not None: + with open(path, 'rb') as f: + self.tomldata = tomllib.load(f) + else: + self.tomldata = {"lints": {"workspace": True}} + + if workspace is not None: + with open(workspace, 'rb') as f: + self.workspace_data = tomllib.load(f) + if "workspace" not in self.workspace_data: + self.workspace_data["workspace"] = {} self.check_cfg = set(self.find_check_cfg()) @@ -54,10 +64,12 @@ def find_check_cfg(self) -> Iterable[str]: @property def lints(self) -> Mapping[Any, Any]: - return self.get_table("lints") + return self.get_table("lints", True) - def get_table(self, key: str) -> Mapping[Any, Any]: + def get_table(self, key: str, can_be_workspace: bool = False) -> Mapping[Any, Any]: table = self.tomldata.get(key, {}) + if can_be_workspace and table.get("workspace", False) is True: + table = self.workspace_data["workspace"].get(key, {}) return table @@ -136,6 +148,16 @@ def main() -> None: action="store", dest="cargo_toml", help="path to Cargo.toml file", + nargs='?', + ) + parser.add_argument( + "--workspace", + metavar="DIR", + action="store", + dest="workspace", + help="path to root of the workspace", + required=False, + default=None, ) parser.add_argument( "--features", @@ -168,7 +190,11 @@ def main() -> None: logging.debug("args: %s", args) rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2])) - cargo_toml = CargoTOML(args.cargo_toml) + if args.workspace: + workspace_cargo_toml = Path(args.workspace, "Cargo.toml").resolve() + cargo_toml = CargoTOML(args.cargo_toml, str(workspace_cargo_toml)) + else: + cargo_toml = CargoTOML(args.cargo_toml, None) if args.lints: for tok in generate_lint_flags(cargo_toml): From patchwork Wed Dec 11 16:26: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: 13903807 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 272CDE77184 for ; Wed, 11 Dec 2024 16:28:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZG-000344-PU; Wed, 11 Dec 2024 11:28:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ7-00023s-JW for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ5-0000Ik-MA for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yd9TqaYM4lKJdZBLeFrSdM5kPuWm4QjUX5Xc6xf+7Y8=; b=eS7ZyBEF8jYBsKIRWSYhpuM40+PkmJLWBzI/NC1FZD3q69YoU4jl1RPdRvPHWmUvz4zf1f Tlp4HKvgMcZQy0C9g3qLqN85Tn8f9MAoyPW5VFnvhRYE4hxQFcVDvKoJKY+GV7mlqztFZr qoka5/Ay2sL/YKY/JATGmEu37KewlhQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-IhZaCJlLM52sLSQWokl6eA-1; Wed, 11 Dec 2024 11:27:42 -0500 X-MC-Unique: IhZaCJlLM52sLSQWokl6eA-1 X-Mimecast-MFC-AGG-ID: IhZaCJlLM52sLSQWokl6eA Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5d3cdb9d4b1so1164323a12.1 for ; Wed, 11 Dec 2024 08:27:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934460; x=1734539260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yd9TqaYM4lKJdZBLeFrSdM5kPuWm4QjUX5Xc6xf+7Y8=; b=i//sYQmPeEn7Olh2d3f+qQYYaVYbOpyZqOMzF33tW3SnVRHwXfLdbkkYFKy1bQ7nuT Sg8/7fpFiFmYzBVRAH+JSTZjwb+n1x4zasKJo4MdJf3JGof20PExCWZ6XcEhIrT1dvwM yWkYmSAqJ6LbDCAqRgrDzsrrAMewhrc7J6co5hox1pPxzFYypcPe3IfPzMXTFxSVLuFE LXlhfAhNmIlbdGbsJBbnr6JNJ82ZmWYB8sBQLsXd4Hyase/PWnDWcGseCy+KgMDJrSB+ brEjSlxkm3LeuKxPMbgy4BImxT+rGHOLXfyK+nvo9gZJWFaG6bfA/5JPAJ+gm3wPI1Y+ LWPg== X-Gm-Message-State: AOJu0YwG7g1DXMwCUrwxAhRfjALT7AMV31GbVskeYO2aWEYs23jpWhTn YoFXhrBJt+PVTqFVcWmf+4rYMKYE82wqBZtfB9X57I5Kl3W1KJ9BuTxfOsF6DUo2KHpFK8be5LP gnxI9LMzvyCMLFgwoWHo6pietd+9LfvBkryCyULrvfs951P5ZgWSOlHeeU13wIi2Wykh5QPJ3fo QfEOOMK/IkVV2jZBaa2ZUUliey8nhq9nFJb4q/ X-Gm-Gg: ASbGncvrSkWeUl/L8ofCufLaUDw++rueuEVlTgyL5kTbw66KY/vZRDgC5pIN0UDaqx5 4aLIzwqZUOwsbY13X3TzNB5DoyAWWCqEG3QcMmWrjSRj65vpzeHzVU+WOJsFwJA2u49/8xrJz6J O0z8lRP0VQYshpGvvSGZn4Jnsvxinyr/uuwpei5bUMyUkqRDQZD56xyU4jVU01hCeHQ78fABgwe Cwniu2bGyAkZLP8ZXxHhyx4vGxkJA+ag67cWhfElWbVRhOpTGtGqrmS X-Received: by 2002:a05:6402:5215:b0:5d0:b1c4:7081 with SMTP id 4fb4d7f45d1cf-5d43317b4eamr3092289a12.4.1733934460027; Wed, 11 Dec 2024 08:27:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFB3/zvg9TsUI5Su1pYoD7XrW/AD9beYNGnmv0FbFRt5CdREs7lBQXGhu4S1oCoJcMSbkzTdg== X-Received: by 2002:a05:6402:5215:b0:5d0:b1c4:7081 with SMTP id 4fb4d7f45d1cf-5d43317b4eamr3092247a12.4.1733934459504; Wed, 11 Dec 2024 08:27:39 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm5930514a12.42.2024.12.11.08.27.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/49] rust: build: move strict lints handling to rustc_args.py Date: Wed, 11 Dec 2024 17:26:38 +0100 Message-ID: <20241211162720.320070-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Make Cargo use unknown_lints = "allow" as well. This is more future proof as we might add new lints to rust/Cargo.toml that are not supported by older versions of rustc or clippy. Signed-off-by: Paolo Bonzini --- meson.build | 12 ++++-------- rust/Cargo.toml | 6 ++++++ scripts/rust/rustc_args.py | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 218ae441e38..85f74854735 100644 --- a/meson.build +++ b/meson.build @@ -123,19 +123,15 @@ if have_rust rustc_args = [find_program('scripts/rust/rustc_args.py'), '--rustc-version', rustc.version(), '--workspace', meson.project_source_root() / 'rust'] + if get_option('strict_rust_lints') + rustc_args += ['--strict-lints'] + endif + rustfmt = find_program('rustfmt', required: false) rustc_lint_args = run_command(rustc_args, '--lints', capture: true, check: true).stdout().strip().splitlines() - # Occasionally, we may need to silence warnings and clippy lints that - # were only introduced in newer Rust compiler versions. Do not croak - # in that case; a CI job with rust_strict_lints == true ensures that - # we do not have misspelled allow() attributes. - if not get_option('strict_rust_lints') - rustc_lint_args += ['-A', 'unknown_lints'] - endif - # 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 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 4bb52bf0bd5..358c517bc56 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,5 +11,11 @@ unexpected_cfgs = { level = "deny", check-cfg = [ 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', 'cfg(has_offset_of)'] } +# Occasionally, we may need to silence warnings and clippy lints that +# were only introduced in newer Rust compiler versions. Do not croak +# in that case; a CI job with rust_strict_lints == true disables this +# and ensures that we do not have misspelled allow() attributes. +unknown_lints = "allow" + # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn = "deny" diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 9df131a02bd..5525b3886fa 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -35,6 +35,8 @@ except ImportError: import tomli as tomllib +STRICT_LINTS = {"unknown_lints", "warnings"} + class CargoTOML: tomldata: Mapping[Any, Any] @@ -80,7 +82,7 @@ class LintFlag: priority: int -def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]: +def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[str]: """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags.""" toml_lints = cargo_toml.lints @@ -105,9 +107,13 @@ def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]: # This may change if QEMU ever invokes clippy-driver or rustdoc by # hand. For now, check the syntax but do not add non-rustc lints to # the command line. - if k == "rust": + if k == "rust" and not (strict_lints and lint in STRICT_LINTS): lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority)) + if strict_lints: + for lint in STRICT_LINTS: + lint_list.append(LintFlag(flags=["-D", lint], priority=1000000)) + lint_list.sort(key=lambda x: x.priority) for lint in lint_list: yield from lint.flags @@ -184,6 +190,13 @@ def main() -> None: required=False, default="1.0.0", ) + parser.add_argument( + "--strict-lints", + action="store_true", + dest="strict_lints", + help="apply stricter checks (for nightly Rust)", + default=False, + ) args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) @@ -197,7 +210,7 @@ def main() -> None: cargo_toml = CargoTOML(args.cargo_toml, None) if args.lints: - for tok in generate_lint_flags(cargo_toml): + for tok in generate_lint_flags(cargo_toml, args.strict_lints): print(tok) if rustc_version >= (1, 80): From patchwork Wed Dec 11 16:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903827 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 4EA58E77180 for ; Wed, 11 Dec 2024 16:31:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZ3-0001W3-S4; Wed, 11 Dec 2024 11:27:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPYx-0000lT-E7 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:47 -0500 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 1tLPYv-0000GI-PP for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934465; 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=lfgHZQsWMegaPfnFVxg+hSLnTIKU6Rd3BgTVCCd8fno=; b=MmJhfIPDAM8+YlSXZK4jYHVnIIGrzeVp1D9BNtyTnirD/8emIhuuFqNwBAaEDmxxPoSc+H nflKduzz/4Y+Qf0N6NDxAdoRW1rnFsRdSPJTV4qkq8BPmztcKoSsq6gIGx7sV6fB/VMzrf khYO/Pbk6+GQVurCsrAqAixoyLastmY= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-vp5MxJovNXOZOHCUsrJAug-1; Wed, 11 Dec 2024 11:27:43 -0500 X-MC-Unique: vp5MxJovNXOZOHCUsrJAug-1 X-Mimecast-MFC-AGG-ID: vp5MxJovNXOZOHCUsrJAug Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-aa5a0a35384so503904866b.2 for ; Wed, 11 Dec 2024 08:27:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934462; x=1734539262; 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=lfgHZQsWMegaPfnFVxg+hSLnTIKU6Rd3BgTVCCd8fno=; b=DOcJ4kEXG1Hn3ZdeGZ0QGVm1ofMo4QyYMy9EcPE1nk1dBLDWBVlt0RrE4Un3njF4LH JWHRalzLJveB5itVzNZ9vcLm+LuRSj2KIrVxCOd4mpd0S7SReKgif6MyRK44wy7DCzsM pnGxKjZ1j6/QP2vkNZht2EDMzetlY2AKx9pdkDrCvMpt7DEpv5PJq4vYkgLIAtevTds0 flu0TqfNp/lNF3zaPSTOX6mFNHTHvlqi+ovAT47zjJWzecaXayclj/k4bnkZGYI1u5ps FJl4gRUcrVSeBnEJZDWKB/5xi+dH8BMez8JscQMNaWMg4KTUV82tzxzeAupl/LcGyHgD CdKQ== X-Gm-Message-State: AOJu0YyRToju9bFvPE1uVRTRQ+1F9/pGj5eQwwV5Il+/jSuzL+pyrcXO 7phrhyW4nDBawbxVnIO0qDWkf+lv19hqCnhBms8l/oKow/YJs4eXeEwM17vN+WrAvAdXIcQIOkP bgL1t9QHjwSkQB3Knkzl0ZNxw4J8naOQ1jpb/euglwmQPco5XFt4FhVSPrv+XDNGWa71i5ceGX+ SWCHJMTW43gGJJvBNq47nlEzJmZDBPKlSWeu/q X-Gm-Gg: ASbGncuCYJ2Aw3qQI/28Hm0tCwoJ5kDyElHWlRk5waayWKVJNLoLd9HS0lcU49QDbWx m/tYNbnsUypjMNw7ialhZuAJEcQCAbm8HduPr+wRZJjc6w6sgpeuHJHCs3RI5dVqAvO4O/71Kq8 lGPh27vNMf7n5wpmrfnWBwqlaeJ5GhemPca7d0U++Q2Nr6BSr6bfsg+VLw4nWXsUp9socz2F+WZ ADHPF6HBP3/GxQv51Y/2sXDDkLa8nxAkQ3x8Xz5LD9z3ehGGj4qhUW4 X-Received: by 2002:a17:906:311a:b0:aa5:2575:e75d with SMTP id a640c23a62f3a-aa6b1141c72mr348935366b.2.1733934461836; Wed, 11 Dec 2024 08:27:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqLeBPutf+x1YKZGwpLGI01fC3RgTTeOumZojvU5ZRPIXU5kWzPEkkjWFRrS1KYNPlybOtfg== X-Received: by 2002:a17:906:311a:b0:aa5:2575:e75d with SMTP id a640c23a62f3a-aa6b1141c72mr348932566b.2.1733934461379; Wed, 11 Dec 2024 08:27:41 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa650ea7369sm715147466b.74.2024.12.11.08.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao Subject: [PULL 09/49] rust: fix a couple style issues from clippy Date: Wed, 11 Dec 2024 17:26:39 +0100 Message-ID: <20241211162720.320070-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 These are reported as clippy::semicolon_inside_block and clippy::as_ptr_cast_mut. clippy::semicolon_inside_block can be configured not to lint single-line blocks; just go with the default. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 8 +++++--- rust/hw/char/pl011/src/memory_ops.rs | 4 +++- rust/qemu-api/tests/tests.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 476cacc8449..317a9b3c5ad 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,7 +2,7 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::ptr::{addr_of, addr_of_mut, NonNull}; +use core::ptr::{addr_of_mut, NonNull}; use std::{ ffi::CStr, os::raw::{c_int, c_uchar, c_uint, c_void}, @@ -499,7 +499,9 @@ pub fn update(&self) { let flags = self.int_level & self.int_enabled; for (irq, i) in self.interrupts.iter().zip(IRQMASK) { // SAFETY: self.interrupts have been initialized in init(). - unsafe { qemu_set_irq(*irq, i32::from(flags & i != 0)) }; + unsafe { + qemu_set_irq(*irq, i32::from(flags & i != 0)); + } } } @@ -601,7 +603,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { let sysbus: *mut SysBusDevice = dev.cast::(); qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); - sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error); + sysbus_realize_and_unref(sysbus, addr_of_mut!(error_fatal)); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq); dev diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 169d485a4d2..c4e8599ba43 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -33,7 +33,9 @@ // SAFETY: self.char_backend is a valid CharBackend instance after it's been // initialized in realize(). let cb_ptr = unsafe { core::ptr::addr_of_mut!(state.as_mut().char_backend) }; - unsafe { qemu_chr_fe_accept_input(cb_ptr) }; + unsafe { + qemu_chr_fe_accept_input(cb_ptr); + } val } diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 43a4827de12..925f5a3c77b 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -74,6 +74,6 @@ impl Class for DummyClass { unsafe { module_call_init(module_init_type::MODULE_INIT_QOM); - object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); + object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); } } From patchwork Wed Dec 11 16:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903936 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 B4FEAE77180 for ; Wed, 11 Dec 2024 16:50:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZ7-0001xE-63; Wed, 11 Dec 2024 11:27:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ0-00017Z-Gq for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:50 -0500 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 1tLPYy-0000HB-LD for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934467; 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=aCokOk3/ugPdPRCt0q5O4jE4HdSTP094Z8xqn4aCSq0=; b=fxdxMkkLVIFP3NrrOyxXJN599rzGuuClurH83zKvA34e+gbMKl9XplHV2FAdmZvYhmJaxN VqiKsTUUnN3QvDRP4zxI6aAP2FoZ2ZgTq73R2aV/cyR6/PaL+l3cNtZB9io4x/M+RNH94f Dw5tXe6Qj5NJ+u+x3PvJRilxPyg4ARc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-yGTUkCuDNyy7uhRp1DZRcA-1; Wed, 11 Dec 2024 11:27:46 -0500 X-MC-Unique: yGTUkCuDNyy7uhRp1DZRcA-1 X-Mimecast-MFC-AGG-ID: yGTUkCuDNyy7uhRp1DZRcA Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b6d2ae6bc0so635707285a.2 for ; Wed, 11 Dec 2024 08:27:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934466; x=1734539266; 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=aCokOk3/ugPdPRCt0q5O4jE4HdSTP094Z8xqn4aCSq0=; b=Tt9HJkFCjM2nZ+6VN5NxjZDBWBz4F1CHEmDX0GdmOSyMXKqRgtJKZSUIVSqRITwLgn GyGU1LxrV2ml5Zhr8mGFFfodlFaXTRlZScvqzk7y6NRxY/lrYR6XgZcdbJGmo3Cy7Yc2 Bci1HunFoc3cb0spr3YXuErML4/O5ajatN0Io0EYiFQTkuI4IxsIDEe2PWln5q+l12Gn nMz963FOHpJ2TUuWc2v4WEO0Kewh158m02TogAlNj5+g0hcdssAuKlAcdAo4DcG82S7N VMOY574qEi5vGkc4DjtHthYHMcPiKYZt3bbmjf46hWkIhwXjf6haa/5vvn+Qzk4zM7B5 Fgzg== X-Gm-Message-State: AOJu0YwmL1oVinSoKzye9Mw/Yscuks8vJBklmvjng1uCS0Ugg5jAurvP wVTJY1TMusQh6xfuOdKBtXRv6AclC56rWQ7pZiu10xSw8NKTtUMEmRXLIgGjZTqRAAfBLqr2h6V 551gDnDaUnk+EX6lufgOqcLhvzBSjdO8HQQQmBSnRaIIXiMbrksCEg9F77wKn/eqRbcV958X3f5 BIV0jTqY9y29c8eGk8EerXw5rH17dEXX7ZpbG8 X-Gm-Gg: ASbGncsXnvt3P0NJqwtR+6gXM3GvveT6PkytfLub2R+PSBBYF2a3mAncm2szGtDTmER B7Af9zQT+eYGEgHJhIFIb0NobkIWU1gLgYBHbJphvhpb94IMciOhJGZTrK9sxEdmGzh6tdXSLHD IrA7X5Kv0agEWyauukFCeE8+pKCNbgSnzrFT584n5uvth3+HS5Ij3KI6ZUEfGbU9q0yVf+dTm0X OuvVEHluRj+Pv/7CjN8NUplJgvMI8dednolC8leEiYXqozk+UFysp08 X-Received: by 2002:a05:620a:1a9d:b0:7b1:5089:485b with SMTP id af79cd13be357-7b6eb4202abmr624675985a.3.1733934465163; Wed, 11 Dec 2024 08:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS/4SqzqsAHfG9+nQsmZ4AVU87E5NRsWfBZmoh+8vHmlaHeKAX7VWcUJy2yTzF97D7gBHkxg== X-Received: by 2002:a05:620a:1a9d:b0:7b1:5089:485b with SMTP id af79cd13be357-7b6eb4202abmr624672285a.3.1733934464801; Wed, 11 Dec 2024 08:27:44 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6ed704f9csm57196185a.32.2024.12.11.08.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao Subject: [PULL 10/49] rust: build: establish a baseline of lints across all crates Date: Wed, 11 Dec 2024 17:26:40 +0100 Message-ID: <20241211162720.320070-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Many lints that default to allow can be helpful in detecting bugs or keeping the code style homogeneous. Add them liberally, though perhaps not as liberally as in hw/char/pl011/src/lib.rs. In particular, enabling entire groups can be problematic because of bitrot when new links are added in the future. For Clippy, this is actually a feature that is only present in Cargo 1.74.0 but, since we are not using Cargo to *build* QEMU, only developers will need a new-enough cargo and only to run tools such as clippy. The requirement does not apply to distros that are building QEMU. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- rust/Cargo.toml | 68 +++++++++++++++++++++++++++++++++++ rust/hw/char/pl011/src/lib.rs | 19 ++-------- rust/qemu-api/src/bindings.rs | 6 ++-- 3 files changed, 74 insertions(+), 19 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 358c517bc56..6ec19b67297 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -19,3 +19,71 @@ unknown_lints = "allow" # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn = "deny" + +[workspace.lints.rustdoc] +private_intra_doc_links = "allow" + +broken_intra_doc_links = "deny" +invalid_html_tags = "deny" +invalid_rust_codeblocks = "deny" +bare_urls = "deny" +unescaped_backticks = "deny" +redundant_explicit_links = "deny" + +[workspace.lints.clippy] +# default-warn lints +result_unit_err = "allow" +should_implement_trait = "deny" +# can be for a reason, e.g. in callbacks +unused_self = "allow" + +# default-allow lints +as_underscore = "deny" +assertions_on_result_states = "deny" +bool_to_int_with_if = "deny" +borrow_as_ptr = "deny" +cast_lossless = "deny" +dbg_macro = "deny" +debug_assert_with_mut_call = "deny" +derive_partial_eq_without_eq = "deny" +doc_markdown = "deny" +empty_structs_with_brackets = "deny" +ignored_unit_patterns = "deny" +implicit_clone = "deny" +macro_use_imports = "deny" +missing_const_for_fn = "deny" +missing_safety_doc = "deny" +multiple_crate_versions = "deny" +mut_mut = "deny" +needless_bitwise_bool = "deny" +needless_pass_by_ref_mut = "deny" +no_effect_underscore_binding = "deny" +option_option = "deny" +or_fun_call = "deny" +ptr_as_ptr = "deny" +pub_underscore_fields = "deny" +redundant_clone = "deny" +redundant_closure_for_method_calls = "deny" +redundant_else = "deny" +redundant_pub_crate = "deny" +ref_binding_to_reference = "deny" +ref_option_ref = "deny" +return_self_not_must_use = "deny" +same_name_method = "deny" +semicolon_inside_block = "deny" +shadow_unrelated = "deny" +significant_drop_in_scrutinee = "deny" +significant_drop_tightening = "deny" +suspicious_operation_groupings = "deny" +transmute_ptr_to_ptr = "deny" +transmute_undefined_repr = "deny" +type_repetition_in_bounds = "deny" +used_underscore_binding = "deny" + +# nice to have, but cannot be enabled yet +#wildcard_imports = "deny" # still have many bindings::* imports +#ptr_cast_constness = "deny" # needs 1.65.0 for cast_mut()/cast_const() + +# these may have false positives +#option_if_let_else = "deny" +cognitive_complexity = "deny" diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index cd0a49acb91..4dc0e8f345f 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -14,28 +14,15 @@ //! the [`registers`] module for register types. #![deny( - rustdoc::broken_intra_doc_links, - rustdoc::redundant_explicit_links, clippy::correctness, clippy::suspicious, clippy::complexity, clippy::perf, clippy::cargo, clippy::nursery, - clippy::style, - // restriction group - clippy::dbg_macro, - clippy::as_underscore, - clippy::assertions_on_result_states, - // pedantic group - clippy::doc_markdown, - clippy::borrow_as_ptr, - clippy::cast_lossless, - clippy::option_if_let_else, - clippy::missing_const_for_fn, - clippy::cognitive_complexity, - clippy::missing_safety_doc, - )] + clippy::style +)] +#![allow(clippy::upper_case_acronyms)] #![allow(clippy::result_unit_err)] extern crate bilge; diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs index 0b76ec58bee..8a9b821bb91 100644 --- a/rust/qemu-api/src/bindings.rs +++ b/rust/qemu-api/src/bindings.rs @@ -7,10 +7,10 @@ non_snake_case, non_upper_case_globals, unsafe_op_in_unsafe_fn, + clippy::pedantic, + clippy::restriction, + clippy::style, clippy::missing_const_for_fn, - clippy::too_many_arguments, - clippy::approx_constant, - clippy::use_self, clippy::useless_transmute, clippy::missing_safety_doc )] From patchwork Wed Dec 11 16:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903811 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 C2E7CE77180 for ; Wed, 11 Dec 2024 16:28:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZA-0002L1-Fp; Wed, 11 Dec 2024 11:28:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ6-0001pR-3e for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:56 -0500 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 1tLPZ2-0000J7-L5 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934471; 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=rO+WbGRzMRexJETWrTif2Ds1kn3dKu1gBbcNzz0Vto4=; b=gvksG4RB312af+yJSL6zKtgbWrp8zjXr1BN+eFAHFaOcxONUbmnz7dxyFZuEs9VfyWnYih wFaskFSAm+6LnvpVdEOU42cv0RZ5TTKCtIjRiDD9S6yHy/v7DRYpizi5Kp/6HqyxKGH9yV HX0zFH+Sza+IaFw+lLyWCJLfo/ZPpBo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-DX2w91FONjGYpf6t2Qg0LQ-1; Wed, 11 Dec 2024 11:27:50 -0500 X-MC-Unique: DX2w91FONjGYpf6t2Qg0LQ-1 X-Mimecast-MFC-AGG-ID: DX2w91FONjGYpf6t2Qg0LQ Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6e1b0373bso208758685a.2 for ; Wed, 11 Dec 2024 08:27:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934469; x=1734539269; 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=rO+WbGRzMRexJETWrTif2Ds1kn3dKu1gBbcNzz0Vto4=; b=hp5wUXkS7nL66gXh6fCe/IzcuxjYI8PlNMgdN46Jnk0ymsuOExvXZ6KEmKlJfVGBSM eM9FnnMQa25Y5ywGFnL3AT6/LC0Ypt5daCijCRbnUeSBlpTEC9qrYg/nAvcR3Ww/cJxs AYEGw31simVpDo8sljvLghvvdkK20cHueSybL+rbublBEA2tIBR0j73hg7RbxOHO4bzi 2zDqmFE9yL6VaPS0tZjZtLVZNyYhE0gwIEMm+Gi321uaNPljDbVJp8M1TwFeqa4i0QTp aQc5qCJ0C1fV3AJY40krzX8xT73f3zlT34ML63TJf8Loqw+OFKjqWSrOGtCV/pn84EoO zqjg== X-Gm-Message-State: AOJu0YzsRcqRVuGK0s/JebQX05/BH87rpwHS0BWfHyc0c6kfGiLaa7aX s1Ng+ZlQeFShU6GhbEe0BKyfe3vJXI6kIeyC42JYDBernJNld7GcBHOWP4IyD2lBaUfnxixw6uc X1p4TuiDOvuQJDSqE208g+/4VXaBMVigo1GAeJBN1uI39k2cnLOHhCazV7m2H+UGbVGY7LyKH8y htLlVG99WWaCumjL5bHv0Nt3VQVwnQ3NKN/doP X-Gm-Gg: ASbGncvo6myn6YreKfE8xpUU+JVumXTMTy/GV7VS/c1c4OSFTklFhL7pWLzmgBXKCjt yr9Rfo/c56upk/eomnGPZCBaFgiSN9IWoS6UPP4dQezz6JGXswjXBAWVhaDwiuCialvyy1FSPqE ogqr+hLxOl57VZhjy5io41PGcOPLlBI9IGAfN+GM5snTDXR8G+27DjctDkaZIxzaxMQNH1Y1LzD oZYxdw/r2zWIAxN39PNXMMsZcgXMgxyRTPqZS360zUQpFq+IOTCfHzH X-Received: by 2002:a05:620a:6007:b0:7b3:5858:1286 with SMTP id af79cd13be357-7b6eb52648bmr605127485a.47.1733934469046; Wed, 11 Dec 2024 08:27:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZe7EA/21zaW+fVwyv+kk0qIt9cxBgEdOKtPZm1zreJrfC6jp5uyoGkETsGzk02WFu72f27g== X-Received: by 2002:a05:620a:6007:b0:7b3:5858:1286 with SMTP id af79cd13be357-7b6eb52648bmr605123685a.47.1733934468599; Wed, 11 Dec 2024 08:27:48 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6f1b5c5dcsm8236285a.68.2024.12.11.08.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao Subject: [PULL 11/49] rust: build: add "make clippy", "make rustfmt", "make rustdoc" Date: Wed, 11 Dec 2024 17:26:41 +0100 Message-ID: <20241211162720.320070-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Abstract common invocations of "cargo", that do not require copying the generated bindgen file or setting up MESON_BUILD_ROOT. In the future these could also do completely without cargo and invoke the underlying programs directly. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- rust/meson.build | 22 ++++++++++++++++++++++ rust/qemu-api/README.md | 10 ++++++---- rust/qemu-api/build.rs | 9 +++++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/rust/meson.build b/rust/meson.build index def77389cdd..91e52b8fb8e 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -2,3 +2,25 @@ subdir('qemu-api-macros') subdir('qemu-api') subdir('hw') + +cargo = find_program('cargo', required: false) + +if cargo.found() + run_target('clippy', + command: [config_host['MESON'], 'devenv', + '--workdir', '@CURRENT_SOURCE_DIR@', + cargo, 'clippy', '--tests'], + depends: bindings_rs) + + run_target('rustfmt', + command: [config_host['MESON'], 'devenv', + '--workdir', '@CURRENT_SOURCE_DIR@', + cargo, 'fmt'], + depends: bindings_rs) + + run_target('rustdoc', + command: [config_host['MESON'], 'devenv', + '--workdir', '@CURRENT_SOURCE_DIR@', + cargo, 'doc', '--no-deps', '--document-private-items'], + depends: bindings_rs) +endif diff --git a/rust/qemu-api/README.md b/rust/qemu-api/README.md index 53810f48882..ed1b7ab263d 100644 --- a/rust/qemu-api/README.md +++ b/rust/qemu-api/README.md @@ -5,13 +5,15 @@ This library exports helper Rust types, Rust macros and C FFI bindings for inter The C bindings can be generated with `bindgen`, using this build target: ```console -$ ninja bindings.inc.rs +$ make bindings.inc.rs ``` ## Generate Rust documentation -To generate docs for this crate, including private items: +Common Cargo tasks can be performed from the QEMU build directory -```sh -pyvenv/bin/meson devenv -w ../rust cargo doc --no-deps --document-private-items +```console +$ make clippy +$ make rustfmt +$ make rustdoc ``` diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 40644d5e4fe..471e6c633df 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -20,8 +20,13 @@ fn main() -> Result<()> { let file = Path::new(&file); if !Path::new(&file).exists() { panic!(concat!( - "No generated C bindings found! If you want to run `cargo`, start a subshell\n", - "with `meson devenv`, or point MESON_BUILD_ROOT to the top of the build tree." + "\n", + " No generated C bindings found! Maybe you wanted one of\n", + " `make clippy`, `make rustfmt`, `make rustdoc`?\n", + "\n", + " For other uses of `cargo`, start a subshell with\n", + " `pyvenv/bin/meson devenv`, or point MESON_BUILD_ROOT to\n", + " the top of the build tree." )); } From patchwork Wed Dec 11 16:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903814 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 09AB3E77180 for ; Wed, 11 Dec 2024 16:29:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZN-0003gc-5F; Wed, 11 Dec 2024 11:28:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZG-00032Y-BY for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ9-0000L3-IQ for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xmqHi0FLBrnWkZWiScIbYdimPuw1BGqG3qZicgcwQCY=; b=ZszfHONu+6adHUEpr6BP5Uls/rbJZjvd5g1JRwppRxi+a8FCs/OZrk/4c5eNjYm7x24UaN g3bT1aiDxVfkeq6qTZF4vEy0O5XDZv6Wz8Nz7bG8c3vlEBwEm5M1q0bgIQPbSKaCUsZN9J 9hjOJIMiYefyEAGTUUzvlq/X6RruITc= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-7boqow8WMCaPdoCGoBm7RA-1; Wed, 11 Dec 2024 11:27:53 -0500 X-MC-Unique: 7boqow8WMCaPdoCGoBm7RA-1 X-Mimecast-MFC-AGG-ID: 7boqow8WMCaPdoCGoBm7RA Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6d8f0b1023bso64780306d6.0 for ; Wed, 11 Dec 2024 08:27:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934472; x=1734539272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmqHi0FLBrnWkZWiScIbYdimPuw1BGqG3qZicgcwQCY=; b=ervbHevQNFCLTwSfXX+WXZrD5ZQDvJiIIqUkvpxhHI+tP6h2Our3fm0GQRutHkZcl4 LmFw4bGndQA1cn2kzf6qx27UsQK4cEvyUzKC/2qd0uez7sPvDRZveU9wVZon//9PBFHy kj814+EPr2FZcU28aDCGIg7mnO+RCIDWy6BoOCO8qx8oQRPx1ioOTGREvyXT8VL2kWUc G4YRE3gfoVSh5RDK/xhzWQ2laT0BVqZULyQiT5ivsPLOcz3nWFz/g73RJ+eXWZhldRn3 wG3hlbZZ7Tzlsf7XCCKj8p49se5F9CP2hnfYorGyJag8o1q6BvnhBdcgXOTY4EJjPm08 03rw== X-Gm-Message-State: AOJu0Yzp0BPLXTzQI0KXxT2JnPjBpRjMwz1fbFRaEH79gGy2EqJ4vWRh 90ArgLTjl8eQk8oFq5spfU3SfXdi1FZVis3OkzLr4C6EO6BPPYd0EezF/MwFcDkn6a2qJkradzI d7vN+F3lqAedKBCLSjSwRFD3mOpHOUAPHr52NQkC5p1Jlx4wBJu0FZ6zOvRStYGJgxh7StqxRXW VBFccwnuuD64Gqrn6Q5I9+Z2QhlYPOYdhFboT7 X-Gm-Gg: ASbGncsVS6qxe3K9QlDnFwceZBnL8hQfNiqgvTCVvDYU1XwhJQnC9AaIe0B84/+DGrn jK5aBcSQLUQgR7V9Y2V+UBGeWetOtMARocM8d4bKwPpQP36nWD+QRZW6QeRkE0rpQEEXzhIa0Md EVGFBJblpHQyBrC2iuj0rfQluhDXkF1mYOdT+LsKucfTQ/TtR07N9Xz6qMxzZAMzQtn+FL7trUL JjPSeyJJ6z6lncjFnxwzkN1a125AhcRnX1q7/VHAFe5JuHOYooQvegY X-Received: by 2002:a05:6214:d8d:b0:6d4:586:6285 with SMTP id 6a1803df08f44-6dae29f2372mr5431106d6.11.1733934472547; Wed, 11 Dec 2024 08:27:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOJ0zfWh5NEixr0fhiNt+8j5REnuFEmASotm8YgE8EViDvWCnEL1Byh6RumC06in+zq8ci2w== X-Received: by 2002:a05:6214:d8d:b0:6d4:586:6285 with SMTP id 6a1803df08f44-6dae29f2372mr5430576d6.11.1733934471998; Wed, 11 Dec 2024 08:27:51 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d9004a6264sm45535776d6.87.2024.12.11.08.27.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/49] rust: ci: add job that runs Rust tools Date: Wed, 11 Dec 2024 17:26:42 +0100 Message-ID: <20241211162720.320070-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Code checks, as well as documentation generation, are not yet tied to "make check" because they need new version of the Rust toolchain (even nightly in the case of "rustfmt"). Run them in CI using the existing nightly-Rust container. Signed-off-by: Paolo Bonzini --- .gitlab-ci.d/static_checks.yml | 24 +++++++++++++++++++ .../dockerfiles/fedora-rust-nightly.docker | 4 ++++ tests/lcitool/refresh | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/.gitlab-ci.d/static_checks.yml b/.gitlab-ci.d/static_checks.yml index ad9f426a52f..c0ba4533826 100644 --- a/.gitlab-ci.d/static_checks.yml +++ b/.gitlab-ci.d/static_checks.yml @@ -46,3 +46,27 @@ check-python-tox: QEMU_JOB_OPTIONAL: 1 needs: job: python-container + +check-rust-tools-nightly: + extends: .base_job_template + stage: test + image: $CI_REGISTRY_IMAGE/qemu/fedora-rust-nightly:$QEMU_CI_CONTAINER_TAG + script: + - source scripts/ci/gitlab-ci-section + - section_start test "Running Rust code checks" + - cd build + - pyvenv/bin/meson devenv -w ../rust ${CARGO-cargo} fmt --check + - make clippy + - make rustdoc + - section_end test + variables: + GIT_DEPTH: 1 + allow_failure: true + needs: + - job: build-system-fedora-rust-nightly + artifacts: true + artifacts: + when: on_success + expire_in: 2 days + paths: + - rust/target/doc diff --git a/tests/docker/dockerfiles/fedora-rust-nightly.docker b/tests/docker/dockerfiles/fedora-rust-nightly.docker index 9180c8b5222..a8e4fb279a7 100644 --- a/tests/docker/dockerfiles/fedora-rust-nightly.docker +++ b/tests/docker/dockerfiles/fedora-rust-nightly.docker @@ -155,6 +155,7 @@ ENV PYTHON "/usr/bin/python3" RUN dnf install -y wget ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc +ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo RUN set -eux && \ rustArch='x86_64-unknown-linux-gnu' && \ rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' && \ @@ -165,10 +166,13 @@ RUN set -eux && \ ./rustup-init -y --no-modify-path --profile default --default-toolchain nightly --default-host ${rustArch} && \ chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \ /usr/local/cargo/bin/rustup --version && \ + /usr/local/cargo/bin/rustup run nightly cargo --version && \ /usr/local/cargo/bin/rustup run nightly rustc --version && \ + test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \ test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)" ENV PATH=$CARGO_HOME/bin:$PATH RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli +RUN $CARGO --list # As a final step configure the user (if env is defined) ARG USER ARG UID diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh index 51012783c0f..6720516b942 100755 --- a/tests/lcitool/refresh +++ b/tests/lcitool/refresh @@ -121,6 +121,7 @@ fedora_rustup_nightly_extras = [ "RUN dnf install -y wget\n", "ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo\n", "ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc\n", + "ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo\n", "RUN set -eux && \\\n", " rustArch='x86_64-unknown-linux-gnu' && \\\n", " rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' && \\\n", @@ -131,10 +132,13 @@ fedora_rustup_nightly_extras = [ " ./rustup-init -y --no-modify-path --profile default --default-toolchain nightly --default-host ${rustArch} && \\\n", " chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \\\n", " /usr/local/cargo/bin/rustup --version && \\\n", + " /usr/local/cargo/bin/rustup run nightly cargo --version && \\\n", " /usr/local/cargo/bin/rustup run nightly rustc --version && \\\n", + ' test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \\\n', ' test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)"\n', 'ENV PATH=$CARGO_HOME/bin:$PATH\n', 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli\n', + 'RUN $CARGO --list\n', ] ubuntu2204_bindgen_extras = [ From patchwork Wed Dec 11 16:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903798 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 75109E7717D for ; Wed, 11 Dec 2024 16:28:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZD-0002ZO-2I; Wed, 11 Dec 2024 11:28:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZA-0002L3-8r for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:00 -0500 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 1tLPZ8-0000L6-PY for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934478; 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=2MXfVs/g+bvC1GKRwZEGvjJF+Epo24jQg+cJnZuvvCU=; b=Eb6zal7OtHkDPLrcaWPi3kZS7J9VfuD8LzCDrU/kBgADoIlqXpqRi0WiXACdyqMe7OEFRf ayyrM47bSy+v6hGvpFRSq4v4X8KjVg5WzAQVpVOYoYS3AhDrg58hRLX/AUCqlAXe+4jQ/J pSE7iTcjMM+s1Cq+TfWrWTdyM3HS9WM= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-117-EVFyI356O76RMSHo03Th-Q-1; Wed, 11 Dec 2024 11:27:56 -0500 X-MC-Unique: EVFyI356O76RMSHo03Th-Q-1 X-Mimecast-MFC-AGG-ID: EVFyI356O76RMSHo03Th-Q Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-46790c5b1a5so14449681cf.2 for ; Wed, 11 Dec 2024 08:27:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934475; x=1734539275; 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=2MXfVs/g+bvC1GKRwZEGvjJF+Epo24jQg+cJnZuvvCU=; b=Rq1e2aKJjFkpTwNWLcBuQ+ksubafhLaRyOd+ALr3h2EXsEMZods+FiRr/u1QEfnbDz dSTwRoumwSziuk4tSx0hJDhL2l6xJ6gEdOENI2q6AErGPolwjmdZ/z292tA8q1eR5LAZ 193CZ4VmOSIsseEF+ppYKqI2AAufpr4K7eItbeu2W5B5QdYwICOS1eMlNyuGeyTBmFJL 0Xftq4LpxCJ8OhuSta+g8AygHJVz0CRV11NMlcD4kq0SKRcOGTXvFRWZdYIoplolm4ec cDHpTaQYDoRumhLs0Q1qBS4X4u/ZONN41JIhKnNOPVs00PDuVJNWq83J8c019l9Nsfq8 Pn3Q== X-Gm-Message-State: AOJu0YyuSjXH7LVs0DLyPX+kyo0wHvad3HZe2B/GJEHQuPcUjxw22Ouz t7Ue1fzsKC9vgXskCLWpEkxQVq7lR3xOjyXzKZZ4YaaDE0CfRiEpIgU47COLhnbvRrmTiSlQX2I luJh2/+y8RWw4QEM1uc+Rt0fCeCRXrbBg1g9rD0oLbsIWU+A/twwau6RxsfZF6KGmYfGRNIxQmn Ia4j1BiICInUzMhcCAXaw1MNEeAfP6jmlz2ims X-Gm-Gg: ASbGncsVbLBxg2z7zSVLSj0cwSYflpoo3P1k54x5oPTWyiD0FVXGa9F5rasBaAWpG0c aoVjhzpxVkMRbMky8CLEeGt3M68FB9QdE36R7OUotyZpOvU9vlMEBNVYRNZTOEfYnIzCgXrbzHg mpjLQVT/z5NxLizecwBPf7GN4m5kp5wxMURsHtqnOBEP8L2/rYDn5iUFwW8BtUqZaDF/X5R8zcv OkKNLNjaJGGJqcinCLKOVmPqu3u19r9zW2XSU8PZiOoSTEEVs1plhgn X-Received: by 2002:a05:6214:c8b:b0:6d8:a148:9ac1 with SMTP id 6a1803df08f44-6d934bbe3f9mr58259836d6.47.1733934475666; Wed, 11 Dec 2024 08:27:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZFaVyeVL6o0TvT8PnO1wf7MO78cONiIk7NqVF8a3cWsi1jHTw/VOks2DAYUXtcGeE0ONDkA== X-Received: by 2002:a05:6214:c8b:b0:6d8:a148:9ac1 with SMTP id 6a1803df08f44-6d934bbe3f9mr58259406d6.47.1733934475170; Wed, 11 Dec 2024 08:27:55 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d8da698c4csm71249116d6.51.2024.12.11.08.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao Subject: [PULL 13/49] rust: fix doc test syntax Date: Wed, 11 Dec 2024 17:26:43 +0100 Message-ID: <20241211162720.320070-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Allow "cargo test --doc" to pass. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/zeroable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 13cdb2ccba5..6125aeed8b4 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -7,9 +7,9 @@ /// behavior. This trait in principle could be implemented as just: /// /// ``` -/// const ZERO: Self = unsafe { -/// ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() -/// }, +/// pub unsafe trait Zeroable: Default { +/// const ZERO: Self = unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() }; +/// } /// ``` /// /// The need for a manual implementation is only because `zeroed()` cannot From patchwork Wed Dec 11 16:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903891 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 D8D99E77183 for ; Wed, 11 Dec 2024 16:42:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZI-0003BH-Ja; Wed, 11 Dec 2024 11:28:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZF-0002v8-05 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZC-0000Mt-La for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934481; 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=5/gPO2yFneY2SAFLMqoaZO1g8ZLO9OFPO/sZ1iMHfZo=; b=iNEr7Bb3ZFzGvp8rWusW+EF0VScGlPLDUyYxvXHNWqRFiUByeFMYJgZ3gWbsiAKFM6XRqG ltVOcJ166nUlLMumSRBpEdLPMsgwDLhwBRTk0uf2YICfqznnoA5Zg6ep36gYby3w/nf0Dw qXXhw/DP34clJnuSjopebCxIPu3snuk= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-fMWhQFAIN-m6QewmsL3XTA-1; Wed, 11 Dec 2024 11:28:00 -0500 X-MC-Unique: fMWhQFAIN-m6QewmsL3XTA-1 X-Mimecast-MFC-AGG-ID: fMWhQFAIN-m6QewmsL3XTA Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b6c51069f5so598028785a.3 for ; Wed, 11 Dec 2024 08:28:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934479; x=1734539279; 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=5/gPO2yFneY2SAFLMqoaZO1g8ZLO9OFPO/sZ1iMHfZo=; b=DXh2fakpsyYIrvD7o5oUzeE32ZtX64n48wHs3N+7HVetPTqyVLcGmr5E9Izf6doQIR 4p+emNJ1XGdIxCNfNQK3aBliuCM3ps/1ymiZ+VPkour8eNeeQe3kySuZlTLkfBNQNZaG ccfBQkpfJk9GcYBzT3gHf7nCvQse/Cqzh7Ib8XQWE1gNyBy0lIrJY+v+uZRaf32nhbq6 lSso4EdCT+JMr+QbES1vQcxb217WoWBY1mBpUwcAXPKtGwpHqHvE18saA3SWNKaQQa1+ E53D2Dwi2SPjU4I4kyZRA7KrEaLOXw3n7E9iPsm9vt8l5GpiTVw55ZiH7pDFerYm+eFG Fyew== X-Gm-Message-State: AOJu0Yzvf0hSQJYXIHy5v2B2xEwvCCGeKOAv3gBfIKpEPVUWRc5i3sAh DCqvOvGoFCI85DvOQ6sYUxjTq9m3rKAgIfdv2CYGt9RgLV08XHWgOKBnSoYWobXTOC+ePCxkS6b GbGosA9ogrB+36v4c9kFB8fsH21tq7kbl98O8aXvMljw0RCoFpAkbDfeaPP8hBYtTaub6wEE23I DcqHL9vA0iuP7Jkb+oMSyEraKx2GHOAq13wnWd X-Gm-Gg: ASbGnctmQHil8k0lP9OguEOIg/5wFXL6agipadnAVv1SlC1g4KUHeFDNmoB8asWsoHW SSltqyqJORlbxP7Js3c/WPod77C3d5HWvPB9cF8FIH27dJsJI+h2ndSLBpKkl4lI1VjuM/Cn+5N f4JQ4C9tja8ZX/zUx9KsI90WP2P94in5baNMbBifizLMV1CboCVdpJ6MonMPBxtHJGudi2JTp/0 Iep+RjLbvcAQFgwsIl9723FCSGs1vHCD8PpKYFBpHU3zj4selfJifLP X-Received: by 2002:a05:620a:191b:b0:7b6:d273:9b52 with SMTP id af79cd13be357-7b6eb4d86f2mr540882785a.24.1733934479480; Wed, 11 Dec 2024 08:27:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpohvuDi1xtSCheyj9p63ZFmjUYzmt3Bgcpvj+6T03bsNvqZaHmQ+p1DQO6Bkt4ffC5hIbfQ== X-Received: by 2002:a05:620a:191b:b0:7b6:d273:9b52 with SMTP id af79cd13be357-7b6eb4d86f2mr540878185a.24.1733934479079; Wed, 11 Dec 2024 08:27:59 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6cbf228a5sm400514785a.105.2024.12.11.08.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao , Zhao Liu Subject: [PULL 14/49] rust/qemu-api: Fix fragment-specifiers in define_property macro Date: Wed, 11 Dec 2024 17:26:44 +0100 Message-ID: <20241211162720.320070-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Junjie Mao For the matcher of macro, "expr" is used for expressions, while "ident" is used for variable/function names, and "ty" matches types. In define_property macro, $field is a member name of type $state, so it should be defined as "ident", though offset_of! doesn't complain about this. $type is the type of $field, since it is not used in the macro, so that no type mismatch error is triggered either. Fix fragment-specifiers of $field and $type. Signed-off-by: Junjie Mao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20241017143245.1248589-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/device_class.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 0ba798d3e3c..922bbce1bb8 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -27,7 +27,7 @@ macro_rules! device_class_init { #[macro_export] macro_rules! define_property { - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty, default = $defval:expr$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), @@ -38,7 +38,7 @@ macro_rules! define_property { ..$crate::zeroable::Zeroable::ZERO } }; - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr$(,)*) => { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), From patchwork Wed Dec 11 16:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903829 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 B5282E7717D for ; Wed, 11 Dec 2024 16:33:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZL-0003cn-Hj; Wed, 11 Dec 2024 11:28:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZI-0003JE-Ke for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZG-0000P0-Qt for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LqP+CF9Cn7KtMzYzo4JT11mnT2881O+4ObbCwnw7e7k=; b=GWTnYjpU3KkiBrJd1vHZr1UnT/RzJHcYyY2C+gDNIhVVRuOBI3zkBzwORteMdtSP650bqN mV4N4+zXHj49HgT8/JZFF3bcz6J/rlm7f8Q7l+sLEtI59J5URmgVWG81Se7rCggSVP9AmW UFBeS+izVSN6mRgZ9zmfL/D2YT5uiVM= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-4Y5l2xPTNQWCndCk76ZNsQ-1; Wed, 11 Dec 2024 11:28:03 -0500 X-MC-Unique: 4Y5l2xPTNQWCndCk76ZNsQ-1 X-Mimecast-MFC-AGG-ID: 4Y5l2xPTNQWCndCk76ZNsQ Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa61e72d68dso533991866b.3 for ; Wed, 11 Dec 2024 08:28:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934482; x=1734539282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LqP+CF9Cn7KtMzYzo4JT11mnT2881O+4ObbCwnw7e7k=; b=nUBRN/vdI2kzFtC3gI+cQcoOCn5h6tv+cG4uyZbIgt5Fr/wIL4e2V0UTaR0jEdqzrt yjakzElEbcScU9ZduVts5mCSWb/y1Iexgj8Rtz98D1IdspdT6u0I70YE2jfSJZ8lm2Ql 8/rWqBgEZJ/NfxpS53XwFE11bqtoWott0GxoGdWeptJcTXYBnYStKVgtIillB6Jl3JEK 9+d/Uz3csnd/+uxSJNUXTk1Mb2Bfiiy/AIycRoxsVrjR6dVZZZMU0aUSfg/e6XqkIZUk 3tmAEPIGQMFlw1/waubVPK5ZAx2LwN2J6lmon1MDAOd9eHPf0+gYGSjkU4NxndGjKVkh lshA== X-Gm-Message-State: AOJu0YwOetpmFDuZqeQv2A5AENqVGuUYScGdQUYdKZZLNRXVGLAG67e/ ZxYBOREiNUk3HmTcwvceA0Fwkd8Q98yIVxLpB2YoOong2cr0mJDPBK56KdRiVIW2xgqv6Rc9SLL N1lo/6JhzH8qiySb3cKypHdQ/4DGFhSI1zOmO4x2nrMrL2+S3HmyEww6qt1y2chYJAusuLVSln7 HnxAOX4CN3ZKTB+s+rAIDLQp590r+xgtKUPcmX X-Gm-Gg: ASbGncvyhLtfjZbNzsnSgFv7n7E1JH5B1m8iSyg+BR2dK9CUikjyDMjETqn1cMLrVkW PbcWewlp00geCLPTmpVG7/ryukFWy7BY4FuUQKXBOk6AEms3RzeRUv+wDuapTK1ErkQ+6FvUMH7 2ikP2u1FwomR65Yfql/DZpPkOUvZMNE+7u4futDuFntisnco9R5Dm0XV+GJPZ5keC9jWezSW0rh vk/dcaKhcj7gVgFdzGCj7QC6AhTRZugSWDjyneh+3ClDHUtmobSElDu X-Received: by 2002:a17:907:72cd:b0:aa6:b5e0:8c59 with SMTP id a640c23a62f3a-aa6b5e095bbmr284803866b.35.1733934481827; Wed, 11 Dec 2024 08:28:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFc6vl+2WSCOzXnfgV1+umZZeyGRF8tr8hut8ZDv9tjCDjucUv6J4ePnAKpf8+f+p/87DsWNw== X-Received: by 2002:a17:907:72cd:b0:aa6:b5e0:8c59 with SMTP id a640c23a62f3a-aa6b5e095bbmr284800166b.35.1733934481352; Wed, 11 Dec 2024 08:28:01 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa66c646defsm648486566b.181.2024.12.11.08.28.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 15/49] clock: clear callback on unparent Date: Wed, 11 Dec 2024 17:26:45 +0100 Message-ID: <20241211162720.320070-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Signed-off-by: Paolo Bonzini --- include/hw/clock.h | 8 -------- hw/core/clock.c | 22 +++++++++++++++++----- hw/core/qdev-clock.c | 5 +---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/hw/clock.h b/include/hw/clock.h index eb58599131c..a279bd4ba5e 100644 --- a/include/hw/clock.h +++ b/include/hw/clock.h @@ -141,14 +141,6 @@ Clock *clock_new(Object *parent, const char *name); void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque, unsigned int events); -/** - * clock_clear_callback: - * @clk: the clock to delete the callback from - * - * Unregister the callback registered with clock_set_callback. - */ -void clock_clear_callback(Clock *clk); - /** * clock_set_source: * @clk: the clock. diff --git a/hw/core/clock.c b/hw/core/clock.c index cbe7b1bc469..391095eb4e5 100644 --- a/hw/core/clock.c +++ b/hw/core/clock.c @@ -44,16 +44,12 @@ Clock *clock_new(Object *parent, const char *name) void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque, unsigned int events) { + assert(OBJECT(clk)->parent); clk->callback = cb; clk->callback_opaque = opaque; clk->callback_events = events; } -void clock_clear_callback(Clock *clk) -{ - clock_set_callback(clk, NULL, NULL, 0); -} - bool clock_set(Clock *clk, uint64_t period) { if (clk->period == period) { @@ -168,6 +164,16 @@ static void clock_period_prop_get(Object *obj, Visitor *v, const char *name, visit_type_uint64(v, name, &period, errp); } +static void clock_unparent(Object *obj) +{ + /* + * Callback are registered by the parent, which might die anytime after + * it's unparented the children. Avoid having a callback to a deleted + * object in case the clock is still referenced somewhere else (eg: by + * a clock output). + */ + clock_set_callback(CLOCK(obj), NULL, NULL, 0); +} static void clock_initfn(Object *obj) { @@ -200,11 +206,17 @@ static void clock_finalizefn(Object *obj) g_free(clk->canonical_path); } +static void clock_class_init(ObjectClass *klass, void *data) +{ + klass->unparent = clock_unparent; +} + static const TypeInfo clock_info = { .name = TYPE_CLOCK, .parent = TYPE_OBJECT, .instance_size = sizeof(Clock), .instance_init = clock_initfn, + .class_init = clock_class_init, .instance_finalize = clock_finalizefn, }; diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 82799577f3e..ca65685c04e 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -87,11 +87,8 @@ void qdev_finalize_clocklist(DeviceState *dev) if (!ncl->output && !ncl->alias) { /* * We kept a reference on the input clock to ensure it lives up to - * this point so we can safely remove the callback. - * It avoids having a callback to a deleted object if ncl->clock - * is still referenced somewhere else (eg: by a clock output). + * this point; it is used by the monitor to show the frequency. */ - clock_clear_callback(ncl->clock); object_unref(OBJECT(ncl->clock)); } g_free(ncl->name); From patchwork Wed Dec 11 16:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903916 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 1B3A5E7717D for ; Wed, 11 Dec 2024 16:45:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZQ-0004De-0E; Wed, 11 Dec 2024 11:28:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZL-0003ca-DQ for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZI-0000PK-C8 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FCv89ZfoHZZZqkAW0Dj5w3dxVYgBc6W+jr38uHvg65c=; b=h6GfCTbMMpTc5cGOWeRxI6q7ihnfkxZy87uy0iXlmcxzcFWoj+9X3EhE1zEkxWuUHG/LOE ncyn2wZuSCaWoI2ZO8IDJu/OW9wZ0I76OldU0GfQcaqJDW7LDk1YXR/0Jtg2OzNzqzcnIe SSy+JF4xcg4RWxfvS5oeO+KiO5BzXQE= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-HInfmtxIPkeHztmLDToxlA-1; Wed, 11 Dec 2024 11:28:05 -0500 X-MC-Unique: HInfmtxIPkeHztmLDToxlA-1 X-Mimecast-MFC-AGG-ID: HInfmtxIPkeHztmLDToxlA Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5d40c0c728aso2481671a12.2 for ; Wed, 11 Dec 2024 08:28:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934484; x=1734539284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FCv89ZfoHZZZqkAW0Dj5w3dxVYgBc6W+jr38uHvg65c=; b=wyPIh7a2e4tTj5eWB4BMhCSUUUcDDwW8HhjEckHOHiyJITu1MyFsivyBLtWLSRUjXc hXifhEY10HjExFz1UDRei8XsnLDcTvIQ4PjksCgmpdbaQiTWkjEwa0O7G1ckqi4NKr8S /hcaD5GTb1jQQGJxfksqin5Mzyj+afR7IrFyHrdQrQzlc0EY4sKdNSEOzVpL5sdlpLAV BgX9RXcl08TAcXxfeRNVVUNm7BgymizsLq2aVbbLYYtjTyKrarbuiDw0wvGNoiLnTAGl njqyvHooNnCzL890wcfVboVUxXjwGYMiG1YEdVnCbD1wl9yrmOUXlYfzJjBw+hJC5v3c SWMw== X-Gm-Message-State: AOJu0YzAXV6gi4rYIT9Lh4WNeB/9r1j+H8oJitOUjvNgiGE8p9/l8ugi eLYZeCjkh3qWd1WRlNFJqlkN4A/rPf51Yu3A87zimZSxLEV788wKvqIhAsZu3L/P9eq5FvxgooX 2qD5rHWB8eFhpI8rbS2GwSpBndEtlGXV0Ea6Y+vo6KgMN6qeuQPzlXWyseSGq6xETmGBzwBM1PT fXixmwMcuyy0aWCaFWEcCHCrJRT/2DxdYGbJvN X-Gm-Gg: ASbGnctn6X/jD1VSdW1e1mZ5C5qHUAota8XMSWAAUeBfs17LZRVVwpb9jmGFVCMljoi 4DDWPDPyyURRfotDmTz+1vgBtmfmx1dva0qs9IlstjE2ANFPykMUva5FYN7u/P7GHZuY97cGOP7 T1VOqUiZ5OONTnmvUFy4C738ZdymtOWgTUteOwo1xLeB49J5kV6Ets+R/qr29rqpXYJ8qCcFrVY lBUPUPQojTv67SeIpcyg9Hbi725h0MrDt9Ut9oppsD8n8g4xOSt7fb0 X-Received: by 2002:a05:6402:2807:b0:5d2:7270:6128 with SMTP id 4fb4d7f45d1cf-5d43314cf97mr7828196a12.25.1733934484020; Wed, 11 Dec 2024 08:28:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUtC2+/Wx3qfxjhswpuOMWQKWdituT50dTL3K3ZOBNrtdiGdhr+r2NZ/g/OHHz5DwxH7mFxw== X-Received: by 2002:a05:6402:2807:b0:5d2:7270:6128 with SMTP id 4fb4d7f45d1cf-5d43314cf97mr7828086a12.25.1733934483079; Wed, 11 Dec 2024 08:28:03 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3ebbd67c0sm5836516a12.46.2024.12.11.08.28.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:02 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/49] clock: treat outputs and inputs the same in NamedClockList Date: Wed, 11 Dec 2024 17:26:46 +0100 Message-ID: <20241211162720.320070-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Signed-off-by: Paolo Bonzini --- hw/core/qdev-clock.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index ca65685c04e..2f9d6cb7579 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -48,14 +48,6 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name, if (clk == NULL) { clk = CLOCK(object_new(TYPE_CLOCK)); object_property_add_child(OBJECT(dev), name, OBJECT(clk)); - if (output) { - /* - * Remove object_new()'s initial reference. - * Note that for inputs, the reference created by object_new() - * will be deleted in qdev_finalize_clocklist(). - */ - object_unref(OBJECT(clk)); - } } else { object_property_add_link(OBJECT(dev), name, object_get_typename(OBJECT(clk)), @@ -84,7 +76,7 @@ void qdev_finalize_clocklist(DeviceState *dev) QLIST_FOREACH_SAFE(ncl, &dev->clocks, node, ncl_next) { QLIST_REMOVE(ncl, node); - if (!ncl->output && !ncl->alias) { + if (!ncl->alias) { /* * We kept a reference on the input clock to ensure it lives up to * this point; it is used by the monitor to show the frequency. From patchwork Wed Dec 11 16:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903808 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 27312C3DA4A for ; Wed, 11 Dec 2024 16:28:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZR-0004X7-UE; Wed, 11 Dec 2024 11:28:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZM-0003pU-K4 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:12 -0500 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 1tLPZK-0000Pi-NQ for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nRrSXqg/+YjeMrLl+QDiq1syQzoZBeTQdvPr71n/Pxc=; b=Np9w7/Kkip51iBSrn7vOCK9qJ7qDTtik9ejdLnR/iyEKKQHwu4PWweT7VsN83UtXifIkHb GMXdbN4Q5HqSj/3kM2CyIRFI9IBIExsuYN8I1gCy9+TEk97JC0m3aLjUE/J5yV28zqKbQP W3qUIoWlYgZ8+eaZtyvtaU6BL4urpPk= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-dSbmF2--NtiF1v2Km6bfxQ-1; Wed, 11 Dec 2024 11:28:07 -0500 X-MC-Unique: dSbmF2--NtiF1v2Km6bfxQ-1 X-Mimecast-MFC-AGG-ID: dSbmF2--NtiF1v2Km6bfxQ Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-aa689b88293so390193666b.3 for ; Wed, 11 Dec 2024 08:28:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934486; x=1734539286; 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=nRrSXqg/+YjeMrLl+QDiq1syQzoZBeTQdvPr71n/Pxc=; b=UHdDuzuTLnIWo+4fwHYhJzFvj+sPxYs16RS8jrXUAwVSBT2wPm1RUar61Ah7+MUJnF Mbg9DtY69++6ERk3AhowsaW6vEIb0CP/iyLXSJDX1zzSfJXlE+EMlc0npfG+DW7M/8Wy Ja1Anb7RghL5EQbIDME9FKOJ6mnsvUW5Sf3Ol4ghw6oVe0sSbLr6JX35KxnezgsHuy77 FrSt4QSu+orF9ohu7q1pZ6C3BN8YVD2FyThelApkLaRbXhBOCwStaMI1Vv9DSqKNGtF2 z/axvu/Vm6d9j3ZCpLz/My0CD2PP3gDYcMAlvHo5PU3OD9PRO4kbqZln/51oKSsObgwt QgMw== X-Gm-Message-State: AOJu0YwT23aUPBQtB6c42iAgcDsSeMupG5BRE6x+ah0FyPHhSy1XV11G gbieevBF+YmRUPGkCTHiojZLSuGrOgrSfLMch++V2xGqlf1xKGedY16YrfaeU4YrnBqsJO06LQL kbHMjCVnmqeYWYxq1v6WXlMlHGSyK2NsWCUqDtrYBcpzx0IVl0rZ40L8631rVlrBKAU2OMGhnQ+ 4THw2xPhZxBoRT0l7iAVOG/fSVJwAJXgyzUQeN X-Gm-Gg: ASbGnctrolKGmdbmT/Pz/okF3YQ9BwxUnv61wiY7+cF/tBejtoJQd+/w/8d/+c46WdD mXLIBuSxKmzcfXAOWa7XuVPUnKqX+ec8LZM02O9js1QMhkN+lM4Rwulw2yAfQeZDuAGXhUeX23x X+G3juNdGDFnyZrsZzZxILkQJZZZbqj2Du6RNPLS6v2r0LHmE/9xMh8uXajEHWHs+9fCCO/VrRy JT2dPhXK/WMHuFNNpV20RCaVxxwwlQif7TuXBgGGEQYR2408ucMMys3 X-Received: by 2002:a17:906:31cc:b0:aa6:2a17:b54c with SMTP id a640c23a62f3a-aa6b10f5d0cmr363227266b.6.1733934485885; Wed, 11 Dec 2024 08:28:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXGrfANIexBy1+tEtPudrnrfGo/neSKYX8wA0P+6Xq9n/uJ/cIC2Qb9XPY0rFSFaYcDkrF2w== X-Received: by 2002:a17:906:31cc:b0:aa6:2a17:b54c with SMTP id a640c23a62f3a-aa6b10f5d0cmr363224566b.6.1733934485451; Wed, 11 Dec 2024 08:28:05 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa66c646e64sm652223666b.25.2024.12.11.08.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 17/49] clock: inline most of qdev_init_clocklist Date: Wed, 11 Dec 2024 17:26:47 +0100 Message-ID: <20241211162720.320070-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Move object creation out of qdev_init_clocklist. The input/output cases are very simple, and the aliases are completely different. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/core/qdev-clock.c | 71 +++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 2f9d6cb7579..dacafa4e036 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -22,7 +22,7 @@ * Add a new clock in a device */ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name, - bool output, Clock *clk) + bool alias, bool output, Clock *clk) { NamedClockList *ncl; @@ -38,31 +38,8 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name, */ ncl = g_new0(NamedClockList, 1); ncl->name = g_strdup(name); + ncl->alias = alias; ncl->output = output; - ncl->alias = (clk != NULL); - - /* - * Trying to create a clock whose name clashes with some other - * clock or property is a bug in the caller and we will abort(). - */ - if (clk == NULL) { - clk = CLOCK(object_new(TYPE_CLOCK)); - object_property_add_child(OBJECT(dev), name, OBJECT(clk)); - } else { - object_property_add_link(OBJECT(dev), name, - object_get_typename(OBJECT(clk)), - (Object **) &ncl->clock, - NULL, OBJ_PROP_LINK_STRONG); - /* - * Since the link property has the OBJ_PROP_LINK_STRONG flag, the clk - * object reference count gets decremented on property deletion. - * However object_property_add_link does not increment it since it - * doesn't know the linked object. Increment it here to ensure the - * aliased clock stays alive during this device life-time. - */ - object_ref(OBJECT(clk)); - } - ncl->clock = clk; QLIST_INSERT_HEAD(&dev->clocks, ncl, node); @@ -90,29 +67,25 @@ void qdev_finalize_clocklist(DeviceState *dev) Clock *qdev_init_clock_out(DeviceState *dev, const char *name) { - NamedClockList *ncl; + Clock *clk = CLOCK(object_new(TYPE_CLOCK)); + object_property_add_child(OBJECT(dev), name, OBJECT(clk)); - assert(name); - - ncl = qdev_init_clocklist(dev, name, true, NULL); - - return ncl->clock; + qdev_init_clocklist(dev, name, false, true, clk); + return clk; } Clock *qdev_init_clock_in(DeviceState *dev, const char *name, ClockCallback *callback, void *opaque, unsigned int events) { - NamedClockList *ncl; - - assert(name); - - ncl = qdev_init_clocklist(dev, name, false, NULL); + Clock *clk = CLOCK(object_new(TYPE_CLOCK)); + object_property_add_child(OBJECT(dev), name, OBJECT(clk)); + qdev_init_clocklist(dev, name, false, false, clk); if (callback) { - clock_set_callback(ncl->clock, callback, opaque, events); + clock_set_callback(clk, callback, opaque, events); } - return ncl->clock; + return clk; } void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks) @@ -183,15 +156,25 @@ Clock *qdev_get_clock_out(DeviceState *dev, const char *name) Clock *qdev_alias_clock(DeviceState *dev, const char *name, DeviceState *alias_dev, const char *alias_name) { - NamedClockList *ncl; + NamedClockList *ncl = qdev_get_clocklist(dev, name); + Clock *clk = ncl->clock; - assert(name && alias_name); + ncl = qdev_init_clocklist(alias_dev, alias_name, true, ncl->output, clk); - ncl = qdev_get_clocklist(dev, name); + object_property_add_link(OBJECT(alias_dev), alias_name, + TYPE_CLOCK, + (Object **) &ncl->clock, + NULL, OBJ_PROP_LINK_STRONG); + /* + * Since the link property has the OBJ_PROP_LINK_STRONG flag, the clk + * object reference count gets decremented on property deletion. + * However object_property_add_link does not increment it since it + * doesn't know the linked object. Increment it here to ensure the + * aliased clock stays alive during this device life-time. + */ + object_ref(OBJECT(clk)); - qdev_init_clocklist(alias_dev, alias_name, ncl->output, ncl->clock); - - return ncl->clock; + return clk; } void qdev_connect_clock_in(DeviceState *dev, const char *name, Clock *source) From patchwork Wed Dec 11 16:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903853 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 96106E77180 for ; Wed, 11 Dec 2024 16:37:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZP-0004Cd-Pe; Wed, 11 Dec 2024 11:28:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZN-0003sR-2r for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:13 -0500 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 1tLPZL-0000Q9-L2 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5J96IsavK0+zLTS8zAT5ylnqyelCMG7OfRE3uftyvc=; b=CgNoblda7PuARx717CTc6Iig9VQpXkIUx9/nuSiRu1SBYJMj9EEjC2J76C92ZwZdvlRCYL BxCShxsUQXx2LgFzUdP7sYgOm4mW7hcEJ1fv0afrfY1++mGG7nIYmx+S/9kkTwv3yerTAS gmBRi8u0Op7uiHy4tzoTH8FHEpSi9Wo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-s2RBuASKNOGSQww_RXLZSg-1; Wed, 11 Dec 2024 11:28:09 -0500 X-MC-Unique: s2RBuASKNOGSQww_RXLZSg-1 X-Mimecast-MFC-AGG-ID: s2RBuASKNOGSQww_RXLZSg Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aa6a1bf7a82so259386166b.1 for ; Wed, 11 Dec 2024 08:28:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934488; x=1734539288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D5J96IsavK0+zLTS8zAT5ylnqyelCMG7OfRE3uftyvc=; b=KQJR1bXjO1SG5/QpZ1zblcxtgkGqp8A9hVt9spVhFrIDkUQ5W13HZUJr8G/Ldbp9Zp HKgI/iAJY9nhb6+1BBTCH5ZG1StYL13aDdwZkKHaEs+1NYh3rCs7tPMjau3a7F4fKJ+E sRsCYL4j/L4JkIPHG+BDPpBzpF2nIMPcqVWM8hGWqHb1tGWAT2Ah8rngkiwhTvzRds+l ftGZmh5CbaDHpHEnK2DnGI+aQ3+KckYhdnaYGwXbV0PItcNggqsZW/Cwixn2Yoq0GE+N QFgXnDf0kKfT3MTMpREVyofMU6MkaUn9HpkPHqYi7A/DXOtdbK4Q9nAGIluvVPMapgAT SKEA== X-Gm-Message-State: AOJu0YwRwWDPyXRYtpUW/oWqyE6BoDpMdbuTbJMl9XuB5Gqty6B6m2BK VeJxeJ66EmhOKemsFhEDRyyMdqCiunCVTmducOlXVV/XS//rO6/JjTXgsPXz/8kwDFX6mfpeQ8v yRK/r9NZg7ARD2zXCIF4UD0OuWQIcJ7A7Q+fPSFz7xZW+KmckzaAe3mM4bvy+7bQcdgHiLJxpif E1z0ZrklLThSfa5WebqtwUMWhmSBWUzu7FgZ9X X-Gm-Gg: ASbGncu4T0KrGAvEy+4K4Gt5nwonhS56owjhv1z8r6HlhHJUo+GxCrVv1i7n6y6INh3 B3AzIYW+Qkmy3mJi/WqY7WoFcCqdXtrgQZcMlKudT9KPZTE6OSxqtVtwT24vfE2tT9yG19AMsnG u4OACEcLCKT5Ny285Jf/GYM4lA0z/FvqxJGCPfF5BRRSimrZo35wDK85biApGTk0Sd03e5+hmcJ WM0J2cVRGKpAeyMrA3BxbWCJ9jzAHhDZBP/VPlYfG4kYgrWGwrbIlQt X-Received: by 2002:a17:907:b1b:b0:aa6:b926:c102 with SMTP id a640c23a62f3a-aa6c1cf1b14mr50108366b.43.1733934488227; Wed, 11 Dec 2024 08:28:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGn1Bo58DoK8n8mo0K3lhk8bd2RzSerin38VigwmRR8DfvHf8J4ZxtUTLl0sbJ7UCdBG9xcEA== X-Received: by 2002:a17:907:b1b:b0:aa6:b926:c102 with SMTP id a640c23a62f3a-aa6c1cf1b14mr50105166b.43.1733934487777; Wed, 11 Dec 2024 08:28:07 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa68880b344sm480539466b.184.2024.12.11.08.28.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 18/49] kvm: remove unnecessary #ifdef Date: Wed, 11 Dec 2024 17:26:48 +0100 Message-ID: <20241211162720.320070-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm_i386.h | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 9de9c0d3038..7edb154a16e 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -13,8 +13,7 @@ #include "sysemu/kvm.h" -#ifdef CONFIG_KVM - +/* always false if !CONFIG_KVM */ #define kvm_pit_in_kernel() \ (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split()) #define kvm_pic_in_kernel() \ @@ -22,14 +21,6 @@ #define kvm_ioapic_in_kernel() \ (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split()) -#else - -#define kvm_pit_in_kernel() 0 -#define kvm_pic_in_kernel() 0 -#define kvm_ioapic_in_kernel() 0 - -#endif /* CONFIG_KVM */ - bool kvm_has_smm(void); bool kvm_enable_x2apic(void); bool kvm_hv_vpindex_settable(void); From patchwork Wed Dec 11 16:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903817 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 B1658E7717D for ; Wed, 11 Dec 2024 16:29:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZY-0005Zq-IL; Wed, 11 Dec 2024 11:28:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZP-0004D9-Mv for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:15 -0500 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 1tLPZN-0000Qu-Ts for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934493; 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=U53bRzTunzKKb0GQrA7zkMI5MCQHR4iyv2n5IEYAQ8U=; b=KvbBQkpfcJNYHjl9Fgs4GaOZ/voTHfsWmVeq7oTRwMVzomHw6yVBXW+TYZP4o/LGKEBpj2 8w3sqXvKPiQcT/QqM9WdmW8zlea3JL8SZL5n/qqO7eVmZTaqQWQnXhCzsxeJJu2WEW2qIO wS0k2+5eUfDOgdeIuzbBh2byOqn86uU= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-4GLVIrnUPOGVMh0x2jpF2g-1; Wed, 11 Dec 2024 11:28:11 -0500 X-MC-Unique: 4GLVIrnUPOGVMh0x2jpF2g-1 X-Mimecast-MFC-AGG-ID: 4GLVIrnUPOGVMh0x2jpF2g Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5d3d6d924c1so5811827a12.2 for ; Wed, 11 Dec 2024 08:28:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934490; x=1734539290; 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=U53bRzTunzKKb0GQrA7zkMI5MCQHR4iyv2n5IEYAQ8U=; b=h1j/kIRbJb7ZXOGdUKhFibyeUiv7mBb0w3rSDMAlb7VRsfpl0FuMSUOcdBZ5SGgRIl 1/cQXYUDCh/XH5xQxHjg46GNCfHdnMFttLbhajnSdCtUmhFU1Hv0pEjWUQeBSTGj31eO c6hNYH06Pba70KGaizVtUkRwNJh0TDGDYEVsiG6rFTgxxqJA0DGOZv577mXSeJncUiJ6 vlQpA3GxJNosGDN6Wa5YnziQyzt4cEBnBfxnr/VP65JW3Yts8Q9tucvHLyxanzqLF6eA wQQF0uz9qKIMy2jhxWoZR4GaFfMlyCz/0ujBsd2BzYWX6O1Sn0F9bVHEM37SlFSNTMav xlAQ== X-Gm-Message-State: AOJu0YxoTmWkNu1iiOTCX7Ap5R1rEydnd6zJXuQm3u5PNo4dlD7ouN7g Oi3Js8UNrouBSUBfqtAYfnL07t42hXLHg8TN5YbMQjeZpXyev7xOZCTXrRj5k6nRNleZf+J6ijX sgPCR20lJfSl6Bs1vV5mYn6WHbsFvTya/zGwKxj6jmx1If08/0/EdnJYYJgzUEV7BO1u8q1cXmX 8DNPPswJwbiHymQGaC4yM2hXdQvk/xrFN9FhUj X-Gm-Gg: ASbGncvPKdpqqNts8hdXnKkUK85oHqH5Q+6NdU2onEggocjWM6uFQQrTIxqAefvw3Ju Yun7nwT0x8DvA4NmBHPK8ZjgOEM1bvO0y1JZ3/SNktlfzph9rJxY2jM2OSMG4koaAzljc4UvoL8 F0Zj/09eZf7aUBVgFCdI6JMXMdYDBj+Oqvwm6P9INOams04AFlEN4ozU6rPWJIGiYlxtz9nCRVI AhHkDrq0Gn+fUDDi4NOCPQVrLldX+bmoSBjNBCHvcM4uTCY/HzC09TO X-Received: by 2002:a05:6402:348b:b0:5d1:2440:9b05 with SMTP id 4fb4d7f45d1cf-5d43316e59fmr3937133a12.28.1733934490041; Wed, 11 Dec 2024 08:28:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbDS98Odgfq44TgA7/FFlWXLa9928Q9PM0QDMwSD0nOM+fL4YHTH8H0uB04014eCD3gdXT1g== X-Received: by 2002:a05:6402:348b:b0:5d1:2440:9b05 with SMTP id 4fb4d7f45d1cf-5d43316e59fmr3937103a12.28.1733934489588; Wed, 11 Dec 2024 08:28:09 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3f3cf8c6esm5314127a12.85.2024.12.11.08.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 19/49] arm: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:49 +0100 Message-ID: <20241211162720.320070-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-2-zhao1.liu@intel.com --- hw/arm/armsse.c | 2 +- hw/arm/smmuv3.c | 4 ++-- target/arm/cpu.c | 2 +- target/arm/cpu64.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c index 255346a595a..58ed504b2bc 100644 --- a/hw/arm/armsse.c +++ b/hw/arm/armsse.c @@ -1731,7 +1731,7 @@ static void armsse_register_types(void) .class_init = armsse_class_init, .class_data = (void *)&armsse_variants[i], }; - type_register(&ti); + type_register_static(&ti); } } diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 4c49b5a885f..6e847e8773d 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -2065,8 +2065,8 @@ static const TypeInfo smmuv3_iommu_memory_region_info = { static void smmuv3_register_types(void) { - type_register(&smmuv3_type_info); - type_register(&smmuv3_iommu_memory_region_info); + type_register_static(&smmuv3_type_info); + type_register_static(&smmuv3_iommu_memory_region_info); } type_init(smmuv3_register_types) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 6938161b954..17519b5e468 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2755,7 +2755,7 @@ void arm_cpu_register(const ARMCPUInfo *info) }; type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name); - type_register(&type_info); + type_register_static(&type_info); g_free((void *)type_info.name); } diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 458d1cee012..c1cac912a08 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -841,7 +841,7 @@ void aarch64_cpu_register(const ARMCPUInfo *info) }; type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name); - type_register(&type_info); + type_register_static(&type_info); g_free((void *)type_info.name); } From patchwork Wed Dec 11 16:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903806 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 053A9E77183 for ; Wed, 11 Dec 2024 16:28:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZW-0005D6-Ip; Wed, 11 Dec 2024 11:28:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZR-0004SF-61 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:17 -0500 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 1tLPZP-0000RD-6W for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934494; 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=iRzo14bKpEKjmhkHIMTDgnInrU+hYkam34e6roO9xNA=; b=DUFTkZX4645VLOw6m7WB7B3jU5HKqUG8LgDbA7nqYQcOv+vNpq+LP0+4e323WOWXFSMPEP heDpN9uS7tnTkSTmYgeJ1VqsxdC73dKSPcI5SCaaJjo7fpOdnCEwSnfmy/CWuSDFLVhlkF tKtUPPpdw/oNIwi5wlqk/u/OorGJxXs= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-DlHRnKxoNTWm4DY7x3OG0A-1; Wed, 11 Dec 2024 11:28:13 -0500 X-MC-Unique: DlHRnKxoNTWm4DY7x3OG0A-1 X-Mimecast-MFC-AGG-ID: DlHRnKxoNTWm4DY7x3OG0A Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aa67f18cb95so389719966b.1 for ; Wed, 11 Dec 2024 08:28:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934492; x=1734539292; 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=iRzo14bKpEKjmhkHIMTDgnInrU+hYkam34e6roO9xNA=; b=Qxpkh6+IHPvdgDI5nLFvhj+HB8aI3J+wURvdaDTP5WgyIgquTHgd+Ibt8DeUNI3N7D OGYzexWxhQ86ZczodI2CygBHmh2rPhTZzvVhvExJrydh2+PeziWbkoINxpJBRh34DAlm AMr+ic9IQQfF3V8kMYXsbNzI0b3kJ96WDyBCnTcVLIPnGctT3GW70k/tpzGPY+jkwKeF kDORk3ZzRZaTDUsetcuKGhI3uBmAdJALuGfr0YJt5LcN1hFAgeTaKy6RT0oYwziQ5K0S IioPI7D3odv4FN2tTVSKcn1Mxwhoafq6Ybi2Dju6dWZ1tr51bT1V1dXdTNuQvF892i1h 9FYg== X-Gm-Message-State: AOJu0YxWr6iB4Xn9zpD/YIp7dw6ltxzDKGgTd1Qs2Ac1Ey66WFcLsQL1 XUF79xR4NDMXzU+e7jGD/VVvp9DnZkgUsb2XGVzm0E07tK6FeVijwM5qnDhMfiHHxLcN8KhEnaE vOW2fnwU/7W4zK0yTd+V44Is8dQAyxzkC6hBQtzjtT9AodAfo3ifQst0Ho4TD89jAQds6mypvui 2T8t23UeDs66t6lyg8s1VRptYKbYD9EaXM2nKU X-Gm-Gg: ASbGncspu0MdpwI5NCsHu4UTB9dSPpNdU5WAYJ9dWHd572SCxDDqerImaXDsOVoxh/H AFFxC2UrtX4bKsrflzvdpI7HJLVEVve5HUaqiIChSw7G1QR72LYUzngikZOOlKU9VVOLmv/Xzn1 b5/SuGaX5ckEZBMCtHfGYlvma2ahoVDZ2fhsEGrL65R+k94A5zJbArXosx6AUqXwbX3zBRHsmr1 BgIufE+1mIErkE8edZRMYkDUqcZXhYL4e/vv1jJb74YxsZXQ2Ggi6kh X-Received: by 2002:a17:906:2932:b0:aa6:8b4a:46a0 with SMTP id a640c23a62f3a-aa6b13faabdmr362863366b.57.1733934491830; Wed, 11 Dec 2024 08:28:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPUb7kRnCbfIIenlBIwvT9AgcRApJp1EKww8eqMa/62iY9Td5ZUPZk14Tr/+no9VStT4ssXg== X-Received: by 2002:a17:906:2932:b0:aa6:8b4a:46a0 with SMTP id a640c23a62f3a-aa6b13faabdmr362860166b.57.1733934491386; Wed, 11 Dec 2024 08:28:11 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa698e922dasm381842566b.84.2024.12.11.08.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 20/49] hw/block: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:50 +0100 Message-ID: <20241211162720.320070-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-3-zhao1.liu@intel.com --- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index e2e84f8b5f8..748594524e3 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -1894,7 +1894,7 @@ static void m25p80_register_types(void) .class_init = m25p80_class_init, .class_data = (void *)&known_devices[i], }; - type_register(&ti); + type_register_static(&ti); } } From patchwork Wed Dec 11 16:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903816 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 98853E77182 for ; Wed, 11 Dec 2024 16:29:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZY-0005br-VE; Wed, 11 Dec 2024 11:28:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZV-0005Ah-Fw for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZT-0000Sh-DH for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934498; 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=4k8q+ScOWCPKZP/2g98Fpy1OHW4u8pQDrcm/3Bs4tcQ=; b=PD/QDMk0qhVa8d3WctZHkLVv21/S+iWGvCxgCafQmkZlu7zycgDAnplpaeT9Rf17K8+nBg dSp/5z5wxljFgXbQobzQj4fqiqNIpsA65Rj3axCW3+5zJsLLSQoF2yP3gr8u1vGqPmk75c rq+S3YUmYU9XNSOAm+WTjoxE7m0M82M= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-9JN8otzIPFeoM-tNRgF3Hg-1; Wed, 11 Dec 2024 11:28:16 -0500 X-MC-Unique: 9JN8otzIPFeoM-tNRgF3Hg-1 X-Mimecast-MFC-AGG-ID: 9JN8otzIPFeoM-tNRgF3Hg Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5d09962822bso7277505a12.1 for ; Wed, 11 Dec 2024 08:28:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934494; x=1734539294; 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=4k8q+ScOWCPKZP/2g98Fpy1OHW4u8pQDrcm/3Bs4tcQ=; b=rOqWbPML4yvwqAN5NpMn4FfAIXT7L5YjCz99fVS6jhrmYoEgPPXNyG/J8DKjhmWeaN QgW9C0XLUYHkgWHq3hJFDzfJxXtwcCRKe29FWk9/vwdKZlM4gjTFnZ48+emtYC3jT1tF DSBprxyYpSC/VhY9hUng6yEKFkfP9VTjUt0L8OCCc23F8xVb896gOBEXPLwwn638i/7u fjX/Mm+aODtSAUzvsDP2mpB+3jL4Hx8psYjhnANn4ZedcjZwR+hVhurQVN7Eyop4gWIS r0lYiU7OjV1Jvqdb4xL/ZdrAW66KfjOS4s34OQ//sZBoii0xRurJpsKaYBgcvzDge9Oc UXkg== X-Gm-Message-State: AOJu0YyA5f+hae0KhXOrGRyQCPaI6N3tTGE0SOoqDnhvSKCU8GoRcOY0 w3OihpNMVdIpGdzFoHNJjy8Zyzzizcrg7z8SQltin3b1RzQMYzRpO2/gMa3YFXJcXxI4zN8Dy0R vSX10WpbPkN8Nl6Vsrfwsc5laK62VnJnteJXQjJz+JkLTe3D9XPav9qHvx00UaVmcViK0zD9NSR FGIYOgHktItvvl+rZSBgLwdytzT9sZCXRLS81K X-Gm-Gg: ASbGncuJPXw3fxksYIbfxMlGv89wFDLNzYgIgYhY3MJu6o5fmcz5cvExEEBzzIYeSpB OfBJ38q7fLrDrtspf8fJvZlWjWBYexawR55Dt9iuqGAHHiviK+i3SJbb9iwnegxW6plABCtElch MnHm2z9mpT3KSXQPGzmMnTycQFiaoWlYjBZT5apOVi/DvC7dtg6fdx9GOZNOiTDEI4s81n0c4j/ Zjk5L3ztQPmcZgaiMoVMMovE1elQfw5BPR9NTv47Z5UeTj4vbiBnD5M X-Received: by 2002:a17:906:31db:b0:aa6:23ba:d8c8 with SMTP id a640c23a62f3a-aa6b10f520dmr367229266b.11.1733934493840; Wed, 11 Dec 2024 08:28:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBiKPyw3k827tMhBFojKOcGCTTXqERQaxefBcHPL6pToXBm/WafX8bkxE4KUpx8i5Tn00HNg== X-Received: by 2002:a17:906:31db:b0:aa6:23ba:d8c8 with SMTP id a640c23a62f3a-aa6b10f520dmr367225966b.11.1733934493378; Wed, 11 Dec 2024 08:28:13 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa68f70cc47sm442307066b.123.2024.12.11.08.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 21/49] hw/net: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:51 +0100 Message-ID: <20241211162720.320070-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-4-zhao1.liu@intel.com --- hw/net/e1000.c | 2 +- hw/net/eepro100.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 5012b964640..ab72236d183 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -1774,7 +1774,7 @@ static void e1000_register_types(void) type_info.class_data = (void *)info; type_info.class_init = e1000_class_init; - type_register(&type_info); + type_register_static(&type_info); } } diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index c8a88b9813f..20b22d8e49c 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -2102,7 +2102,7 @@ static void eepro100_register_types(void) { }, }; - type_register(&type_info); + type_register_static(&type_info); } } From patchwork Wed Dec 11 16:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903815 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 7EC65E7717D for ; Wed, 11 Dec 2024 16:29:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZd-0006Du-1G; Wed, 11 Dec 2024 11:28:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZW-0005M4-Ux for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZV-0000Ta-7a for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934500; 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=Xp/Cl1MXRDbDXW7R4GInQg1UHIFQJ6brbsJU+CLkAsY=; b=d7mGJ+aX6liThU2+RJH8YlsbtebZQwWTVea4YBuBz5yfEDs4ALSOMCBomJcaStaejZa+Ug Tq5zoF0bcqog6v1NlBbeG8iv2NtT4n/FV5VklE4miTjCak7sqhPsQ/CzEobnmeeabPpgwa HVUG6SobEOIgqz1Ihy9KAV2OJVv3fbk= 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-610-fmyIeBQ2MGOsIkMk0cwe5g-1; Wed, 11 Dec 2024 11:28:17 -0500 X-MC-Unique: fmyIeBQ2MGOsIkMk0cwe5g-1 X-Mimecast-MFC-AGG-ID: fmyIeBQ2MGOsIkMk0cwe5g Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-434f3398326so4668665e9.0 for ; Wed, 11 Dec 2024 08:28:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934496; x=1734539296; 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=Xp/Cl1MXRDbDXW7R4GInQg1UHIFQJ6brbsJU+CLkAsY=; b=MD5Ji7ts3EIgObp26MPx97vkNevSK18e0gHJQBNOfVB1zG/mW4/juPzWyBZxIm+Svt O6ctui4B+PpUD6D2SxVwupHbk9EIZUAQXmczH5Bk376ITLH1ekvVeLYSIFrpuKrS1u7O iAKAinU21bao1HmQexWtzpYPObl2JqMF64gb50Dp2Yl3+YQoB94br3n/WXrJECzKzel7 jfPb1cl/rqWzpW2xorDDAdRojxx3XdFlzJWBsLIAc8LbX3lf2eXld+AB3GmfoKU3p54P Br7ecXaKlp+pNYtgZYuWIwzXNzhrPnZeF68rFHJPlKsoMV8YsogozSuzpAw4Yx9jUInB 5zxw== X-Gm-Message-State: AOJu0YxrycRrja8pk5aOpNWB9gp44lZ9krpPO7OOGjztW+FL+0p4ok3b yvTNsjDqwwlUrevcEbMnkOgp9HO/OczhcZnpaiRPeQNGGDEWM8XhIqb/7TOJ0d3E/Yn1HGxHsRe F2KqEFzWlGuvuNTEc+MAWi8s8pe3DEt/j+oHGm9oeEWD5+7XEzMw6il44SxrfvhUvSoiDjpjw6D 4SFgQPmfK2XGC1Bb37jBx+PTGdRJAaOgO2rQ1V X-Gm-Gg: ASbGncvNGHouxEl/337KmmxdMhhxCg3yxSDk2xb0e3Ezu1YYnafrGxqvy7NnD+0U2H4 0aSixcbqPgzdNEaV1mSsN/QNnztdTlPpjGN1P75wE/2ekJTKSh8OFMHJbMnOI5MZrGZkyoLTIAy +oO7IsgDWugA6J2usFrRB4q9tciSv6P8pglnnJxQLi4XcBp4uQFQodpTrYuUXe3D+pUXxbioXZ3 6cm0/wpCLzZFRbXMxKwLE1D3sIK2s4EOjpa3LS9A3TPwf1JHfhIgpVx X-Received: by 2002:a05:6000:1843:b0:386:3262:ff70 with SMTP id ffacd0b85a97d-3864de8ef4dmr2433910f8f.2.1733934496039; Wed, 11 Dec 2024 08:28:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHm2SYkr0RdJlt91nUaILw0MyL7ZvHqqEVLHpra4G31laP0c/1/KhHCoxd1EaygOOVG9F9bBQ== X-Received: by 2002:a05:6000:1843:b0:386:3262:ff70 with SMTP id ffacd0b85a97d-3864de8ef4dmr2433897f8f.2.1733934495694; Wed, 11 Dec 2024 08:28:15 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362104aa9csm10176785e9.31.2024.12.11.08.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 22/49] ppc: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:52 +0100 Message-ID: <20241211162720.320070-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-5-zhao1.liu@intel.com --- hw/ppc/spapr.c | 2 +- target/ppc/kvm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0d4efaa0c09..827e7d6b140 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4723,7 +4723,7 @@ static void spapr_machine_latest_class_options(MachineClass *mc) static void MACHINE_VER_SYM(register, spapr, __VA_ARGS__)(void) \ { \ MACHINE_VER_DELETION(__VA_ARGS__); \ - type_register(&MACHINE_VER_SYM(info, spapr, __VA_ARGS__)); \ + type_register_static(&MACHINE_VER_SYM(info, spapr, __VA_ARGS__)); \ } \ type_init(MACHINE_VER_SYM(register, spapr, __VA_ARGS__)) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 3efc28f18b3..0d464824dbc 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2633,7 +2633,7 @@ static int kvm_ppc_register_host_cpu_type(void) return -1; } type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc)); - type_register(&type_info); + type_register_static(&type_info); /* override TCG default cpu type with 'host' cpu model */ object_class_foreach(pseries_machine_class_fixup, TYPE_SPAPR_MACHINE, false, NULL); From patchwork Wed Dec 11 16:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903805 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 E3C69E77180 for ; Wed, 11 Dec 2024 16:28:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZg-0006gu-90; Wed, 11 Dec 2024 11:28:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZb-0005vc-3c for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:27 -0500 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 1tLPZY-0000UC-An for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934502; 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=bMNv818zenKVONf1gqy04t1JiQM7iMZxJ0aY8hZ0cSo=; b=OB7yc/Eg2KlWLRuNOB58bCiQenneF/2zsiCeKgMhNAfdVP1t3l97o8J+vHUtwpnIi1g1oG II/AKAQNREN0+zaeRq4d/uqlZDPGbEXD3rv36MOs2Q2knl091uzuC5tjDiM2MOxXPbtgjz Mg3hHeJ5tpCYZtcgFgcyS0GMy8T7uKo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-jUWiuBwvP6yEw8SjtPXzGA-1; Wed, 11 Dec 2024 11:28:21 -0500 X-MC-Unique: jUWiuBwvP6yEw8SjtPXzGA-1 X-Mimecast-MFC-AGG-ID: jUWiuBwvP6yEw8SjtPXzGA Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38629a685fdso2281645f8f.2 for ; Wed, 11 Dec 2024 08:28:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934498; x=1734539298; 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=bMNv818zenKVONf1gqy04t1JiQM7iMZxJ0aY8hZ0cSo=; b=QbgRbID7wQwW7A/QQIZ1+WKwyDa3MI8FYDKsneWL2gFFMlHQGiGPzCgw1Cv+1ONygf peLgRJU4BmqBIepDqhvQTxVnwluECizL0xfbOUC/9WCmAkO2yxVIDshKWdBS8MPawDqt h3GIMoTjPqMAoxEf/LLMBlRuame579bb+zYNhS/94hlPi4CGk3GwARxkJ6Yv1aJk2Ixf UuOqDASihNFxRveGz7LS4mgX7GHeC9Kn6JXB0LrZOU/RVI/z4ohKqckhM8Mvr/ONotoW HSK/DWFVN8PndnHfrmUQCXEcpxbs93HzpgWUSWZPKHrtuNHugtHNzJQz+Onb/K9q5GSV fkYw== X-Gm-Message-State: AOJu0Yxfv4sulBC1K6/VpOm3XW4scQp0ESB3vvu9rHz//vZhaRJU3YmH o6IEdkqA1s0a8vYXFvzoyubunuWBuHodPuZPcja0GvrUGMcId/LVL852mUaB/U0cqfZTe201/Sk pXKevnoO63KCUXy1doh5INdPrA1mDhADpZfNxfH6v6AFZHxJz3B2S6Nkrt0P19VoGZm3sQYgsU0 nEo/9bDU6mNBAwKclOH4aFwLCcAbodYQWHDCoC X-Gm-Gg: ASbGncvqan+ATFk+B/jy4GkbbJe+vlyAP/lZiPatQ6PzzCAspRKkrjB6EwO2nhh2Sms Q+7K5NzWJzdGdmPCtETrR0z4SIiN8khpF405+JHQM0NwjzMypjlxT7gAdc8cQ2KjjZZzKFkCbJk IbUD187bhdNIn1F9Fc8ZDhUfVGbES6x61QOvf5SVWvDTzRpMrmgZAU0lKVau428CVZzgBvct6GK XqGDoGPizUI0bYSEgUZJ4lk/xYR8zNCsxFz5qLamO4/UmHtaP2+PqaD X-Received: by 2002:a05:6000:1788:b0:385:f3fb:46aa with SMTP id ffacd0b85a97d-3864ce98548mr3374575f8f.43.1733934498435; Wed, 11 Dec 2024 08:28:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEojMbeZara4Y3arn7jlKvJ4yaL8Hv5d6W4fvlWcZX6EOBhakXlzgGIkFA3FSQlwtBftXElA== X-Received: by 2002:a05:6000:1788:b0:385:f3fb:46aa with SMTP id ffacd0b85a97d-3864ce98548mr3374549f8f.43.1733934498042; Wed, 11 Dec 2024 08:28:18 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38782514e54sm1641825f8f.85.2024.12.11.08.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:16 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 23/49] hw/rtc: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:53 +0100 Message-ID: <20241211162720.320070-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-6-zhao1.liu@intel.com --- hw/rtc/m48t59-isa.c | 2 +- hw/rtc/m48t59.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/rtc/m48t59-isa.c b/hw/rtc/m48t59-isa.c index 6e9723fdf19..b642b82680d 100644 --- a/hw/rtc/m48t59-isa.c +++ b/hw/rtc/m48t59-isa.c @@ -161,7 +161,7 @@ static void m48t59_isa_register_types(void) for (i = 0; i < ARRAY_SIZE(m48txx_isa_info); i++) { isa_type_info.name = m48txx_isa_info[i].bus_name; isa_type_info.class_data = &m48txx_isa_info[i]; - type_register(&isa_type_info); + type_register_static(&isa_type_info); } } diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c index 48846d8df40..90299ea56fe 100644 --- a/hw/rtc/m48t59.c +++ b/hw/rtc/m48t59.c @@ -679,7 +679,7 @@ static void m48t59_register_types(void) for (i = 0; i < ARRAY_SIZE(m48txx_sysbus_info); i++) { sysbus_type_info.name = m48txx_sysbus_info[i].bus_name; sysbus_type_info.class_data = &m48txx_sysbus_info[i]; - type_register(&sysbus_type_info); + type_register_static(&sysbus_type_info); } } From patchwork Wed Dec 11 16:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903819 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 01EC9E77183 for ; Wed, 11 Dec 2024 16:29:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZe-0006CN-4X; Wed, 11 Dec 2024 11:28:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZZ-0005mz-Rn for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:26 -0500 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 1tLPZY-0000UP-0r for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934503; 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=WfR3bsD3EZkoCdmWNV8N9zfVxdC7BnuxFxYvftQbw4s=; b=BZAfFDHWyMJmHwgV7KzViAbsgBi94NHzk2HzT8XzWK7hngKkGnCER+FvEOC9NQqjWueS1n sxd1Ktct8EYLidtskMGiQPgNycpwJrO94EcLnDGvwM51hfLvgubACLb3czujMml/8UHvfZ Sw3nUEHdAics2yhDjtNoME5RC3ryWD0= 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-35-d-LKAo3bOKKYMxlCez4lnw-1; Wed, 11 Dec 2024 11:28:22 -0500 X-MC-Unique: d-LKAo3bOKKYMxlCez4lnw-1 X-Mimecast-MFC-AGG-ID: d-LKAo3bOKKYMxlCez4lnw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43621907030so5609185e9.1 for ; Wed, 11 Dec 2024 08:28:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934500; x=1734539300; 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=WfR3bsD3EZkoCdmWNV8N9zfVxdC7BnuxFxYvftQbw4s=; b=DAWJb5bWL9ZMf9w6NRl1mw+eHsnI8oVH40deJAUlWcsGh2et/8hXE32WJa9LhCOf5D DCtcNMfSVLA6eYSiRYfNmmvKzDFkgMEfQ3YW8stvNFXYhFLwdgBWhlGtRWg6vlfQj9sF Cbn7qtP6qLHcxyncyUZ3W59gCcLgIH1VMpdg/hODdk5ZSZsn44gPrWmvYAsjr12AwsGz 2gnQiWxM5SK02TftgF+KSj0HUjEeumaVjpv4mWcipc6ekks6Gxc1+iEHR+EETr3TtrGZ t4zh1dhg00lXbK5kjpV9km/OowCLOirjZEcVxyUhyNjdNGa+EcgHLI/a6nWjECnveIy0 2Kzw== X-Gm-Message-State: AOJu0YzQhrH83hb3ziFWmMGk/mFK7LCiv6IzDqPSkF2NKkxUTiM7T5KE EZ2nDHoeXnca9PFbHJjvC4/MdSqrKF3TkSMPOyYPjNi3seO1SCRv9ajP/nx26eEfDN5+gvG2yYy duHYWDjV8AokgM9KI7rHtPOc0iPVit5IVLf/fuT0dyi40wemJYWX80qXtrv/bYsl3nlnBRisARz X/i2cwU2fLnWpQZr/S7WNN6v1BbVkgeQGitGcF X-Gm-Gg: ASbGncv7KHmsIsizPSgghsvGRUuVoGfOhhmckysLcNq6T9seEaNkzYtIheqJm7N3v+W e5zQQ9Gn/JMoRv0Tv0bPNYwZj/CyGpROJn/oVbdVfWTwQZberfiBa5vPXGbd0uP5XhzR8U2/CLE e5mhprR8KPrO0z8Hovw3g3CgQFzgrPKd/gkrafx5Y2NgBOncdbUyuvnwJy6gqMl/LZBdUuqNl74 ny3R2O9/ClTrla/bnkNvhOtkOjlQcytJiW72TZ5KYcHpNBeW3NRn2XS X-Received: by 2002:a05:6000:1787:b0:386:31a9:31ea with SMTP id ffacd0b85a97d-3864cea3c64mr3771950f8f.33.1733934500329; Wed, 11 Dec 2024 08:28:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiHoZt3Gpwb3xgDhc5Nq79I/SiF74+IuReGehRxJI3Jlt8QrP41XcFNzLJIxtWLiGbG6nngA== X-Received: by 2002:a05:6000:1787:b0:386:31a9:31ea with SMTP id ffacd0b85a97d-3864cea3c64mr3771930f8f.33.1733934499965; Wed, 11 Dec 2024 08:28:19 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38782514f29sm1663118f8f.77.2024.12.11.08.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 24/49] hw/scsi: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:54 +0100 Message-ID: <20241211162720.320070-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because\ type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-7-zhao1.liu@intel.com --- hw/scsi/megasas.c | 2 +- hw/scsi/mptsas.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index b33229d71a4..df58aeb9952 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -2576,7 +2576,7 @@ static void megasas_register_types(void) type_info.class_init = megasas_class_init; type_info.interfaces = info->interfaces; - type_register(&type_info); + type_register_static(&type_info); } } diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c index 361b75e633a..c6bc3479e99 100644 --- a/hw/scsi/mptsas.c +++ b/hw/scsi/mptsas.c @@ -1450,7 +1450,7 @@ static const TypeInfo mptsas_info = { static void mptsas_register_types(void) { - type_register(&mptsas_info); + type_register_static(&mptsas_info); } type_init(mptsas_register_types) From patchwork Wed Dec 11 16:26:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903809 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 2CF0BE7717D for ; Wed, 11 Dec 2024 16:28:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZi-0006tc-5z; Wed, 11 Dec 2024 11:28:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZf-0006cl-LB for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:31 -0500 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 1tLPZd-0000WH-QC for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934509; 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=Gss1FsL60dR5exmv70NK5RIAMB4XZY8Tdq7PdjogwBY=; b=PAgrJJ+XYLhf0ABVc+SEURu4xrpSiaMlwGRhcaxhjK2k9CVziFzYvSSqzWhimG7GurV1Uq CX91wJ7p6bq7hIQach7xDHJSSm/pKo6PPy0xHkLTJtxiT3uT2wLm3jM4ShAegKAYiZBYkT /ISg2b6nev9ETsPIaOO13zAQnJ8Fdg4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-8tMG5_zQMPaIP6oR6ZQ08A-1; Wed, 11 Dec 2024 11:28:24 -0500 X-MC-Unique: 8tMG5_zQMPaIP6oR6ZQ08A-1 X-Mimecast-MFC-AGG-ID: 8tMG5_zQMPaIP6oR6ZQ08A Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385ded5e92aso2724879f8f.3 for ; Wed, 11 Dec 2024 08:28:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934502; x=1734539302; 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=Gss1FsL60dR5exmv70NK5RIAMB4XZY8Tdq7PdjogwBY=; b=Lrvl1740c4ukjneM3DKQQAPHyx+SgnrT1PkJAXxUlmVX8bLtvxYI71xuEd2Lc6K3wI R8Cp/weoYolhYI4MfPtCjdkG13FSK99n8dv3OJzM/d5EjFaEzl+xQpRusEbkogXCH6VW mlosSBBenqlJu5UepQvKLi6Oqver64CZdQebHmLojUCQNgsxCyiLCVyeCkBCvIOCxSN4 BCqR4C2qM0Pg76z9fI5f6V1tjfvnB2PGkC8fGuGNR/CYqOzxwB+ZXR5z30C64Q13pTzh m8gE5DUdKQNJSuR7Jok2NC0cMTa/XT6m+sA9qAHWHOM0C8RsIxDnuoc+NNlBtNxe9Mur mS7w== X-Gm-Message-State: AOJu0YxYEQK0cqmgnGQp5cEnFU+3T0n05ij+ZcYc71t8oS15/PkLONgQ 0VuK9vXS5UofYdd2HTmyqONZCwRszZb+1Qrwq2zQIt7OsSxDV0UcnWe3DYawnl1dpFh8Di23v3V qpaxRetWLVfT9ry4igZFiJyPx24Vl8Bwvz9J4bOvMAhzsNrm3fs51pPHE4O/SfyKZBThd1XjUNe JFGhbE2wQND8gWK85/nkwQbqkQp/W7TBa9X29B X-Gm-Gg: ASbGncu1eNMusqxcKqtNzAYXOy6PIPmpkQ65opmuUVjY4qz4ohoaXhxNsVP6EdQxhTL gxqMSH6AdN/Fr259+UnrQjiFHcwhLylajLNTOWkXT3SWM7rbsz62Ao4ZHnUP0ECSJ86U6jyXT2/ OffwRKl/eART656q00fqYM693m0AeIiz3eQSUU1ymiJOYuM2fovUR6afo8T1p0ZkF9rnP+LM6iu Os3k/YBWBcFsc+INTPyNLrTY5cKbJtQhg5nvfTcSSpM8QVPy05yXq8d X-Received: by 2002:a05:6000:144f:b0:385:e30a:3945 with SMTP id ffacd0b85a97d-3864ce542b4mr2783605f8f.23.1733934502293; Wed, 11 Dec 2024 08:28:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvGs1q3jSVbR5IZ/k+HnPcfTtlGAUFIzmWsMw6WcgOFkE6ZWNMgn3gM9pYrpiujWdIHsehgQ== X-Received: by 2002:a05:6000:144f:b0:385:e30a:3945 with SMTP id ffacd0b85a97d-3864ce542b4mr2783593f8f.23.1733934501941; Wed, 11 Dec 2024 08:28:21 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248e57fsm1665175f8f.8.2024.12.11.08.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 25/49] hw/sensor: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:55 +0100 Message-ID: <20241211162720.320070-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-8-zhao1.liu@intel.com --- hw/sensor/tmp421.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sensor/tmp421.c b/hw/sensor/tmp421.c index b6f0b62ab11..82e604279c5 100644 --- a/hw/sensor/tmp421.c +++ b/hw/sensor/tmp421.c @@ -384,7 +384,7 @@ static void tmp421_register_types(void) .class_init = tmp421_class_init, .class_data = (void *) &devices[i], }; - type_register(&ti); + type_register_static(&ti); } } From patchwork Wed Dec 11 16:26:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903801 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 C09CFE77182 for ; Wed, 11 Dec 2024 16:28:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZi-0006ne-3v; Wed, 11 Dec 2024 11:28:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZe-0006Sm-GB for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZc-0000VZ-DN for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934507; 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=AKGN8P0xKhBw5wMP9OuFuNHXzgVRM0o+GLlWIKcB6dY=; b=OnWrdSRY1HadeBNEz9EModaKYoIaI/C6t9LteXaLUVkxE2OFyLx2v2gIKteckA7xPoDj4G K3P/K0yiaMcIDgRpysNP8s+pa5kONMKtvOQ1S0sKHaqYZbVT9YH6FPISAbF/1vZJHGBbuW vp8PVQJmLBeSG8o9t3+pKieNzk7r9AE= 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-624-P9zUwrZ9Nim2rMQFzzEb3Q-1; Wed, 11 Dec 2024 11:28:26 -0500 X-MC-Unique: P9zUwrZ9Nim2rMQFzzEb3Q-1 X-Mimecast-MFC-AGG-ID: P9zUwrZ9Nim2rMQFzzEb3Q Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434fe2b605eso19157105e9.2 for ; Wed, 11 Dec 2024 08:28:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934504; x=1734539304; 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=AKGN8P0xKhBw5wMP9OuFuNHXzgVRM0o+GLlWIKcB6dY=; b=A6g2gLKag1w+3rWHoB112g7AdZk6VcXGDckBQNuDjGMPJCBGAPjMUA2fJwmFL1y4X4 9lmrfuTnxiVggmM0xtIn9cD2cxHDuK2cqPAGBlUqFJBLelK5udm7K57jgj/hHY3RwBl0 8aQd+wo6dA7VKjr8Z/34fM6IQVVDadfK8vKI8q78sdwKTjRDDEX+EgZzcu+CWOcmq7pN wGM5BUQsiWetLqMd+d+yqHPJgMRTG2N2lPLZtKkReXNTPqGmcrMUBOZu7dyJoKx6AhFi iz5Mkt1bRrdfvw8ziP5rId2jXpy5J+oHAsW1yrjfGk7tv2RB3lsbfKTfxIme5nlHNiaf qDaQ== X-Gm-Message-State: AOJu0Yz5s7fkWCKSKonmrHDSJ4uBSr/3WSXNSidBn71QPjOXmLAO3JF7 BNxu0hvkMAaQd6Yy5AyywAYxtFKGZQ44G5OHsu2FSeH4HhD5uG1Y52YT99JFc7SHNedYdmWQU5c mF09625jPpVG5TUF8FGnLGNN9S8kpyh4Voqkuvpj/QbMxsNLWb4gHHqKT0NiMyx5dlE3OtN7CK/ 9itoxn806KHr4ge2518ux9npxWOTyQyJFTJJ6L X-Gm-Gg: ASbGncsz/4YSHhGc7f2AB3NUDaNyWFKoTf/nkgwn+8uQJRyoM8poGkZ/QYwjzSeeFgT 35ljyG0P7JSQ1qC/GiPmsJXMenjR2k89o62nJCfR6xpBSjuTtNB/5pFMAJDows5mx0QHrb2B8Mu cuKDpkEYXEkqPzBl+3dOS9AJw6We4ICltejcNPbMkTNNIgAoiZFd1nAwEyGB+R3zC2ANIvHZb/V K4+EbNmYxXZyCjWshVfZH6+E5FrDremeaPLzQbQy4UYqMr/crDhzIp4 X-Received: by 2002:a05:600c:3b09:b0:434:f270:a4f0 with SMTP id 5b1f17b1804b1-4361c3efb35mr25852715e9.21.1733934504041; Wed, 11 Dec 2024 08:28:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUSxvfoEJgwGuv46l93KDkV4GhoUDw3tLQs9G1k+kppYAoU5CP1zeypmAvQD6/5k88W2+oBQ== X-Received: by 2002:a05:600c:3b09:b0:434:f270:a4f0 with SMTP id 5b1f17b1804b1-4361c3efb35mr25852515e9.21.1733934503558; Wed, 11 Dec 2024 08:28:23 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434f981880csm109473675e9.44.2024.12.11.08.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 26/49] hw/usb: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:56 +0100 Message-ID: <20241211162720.320070-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-9-zhao1.liu@intel.com --- hw/usb/hcd-ehci-pci.c | 2 +- hw/usb/hcd-uhci.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c index c94fc9f6c58..dd06451e234 100644 --- a/hw/usb/hcd-ehci-pci.c +++ b/hw/usb/hcd-ehci-pci.c @@ -228,7 +228,7 @@ static void ehci_pci_register_types(void) for (i = 0; i < ARRAY_SIZE(ehci_pci_info); i++) { ehci_type_info.name = ehci_pci_info[i].name; ehci_type_info.class_data = ehci_pci_info + i; - type_register(&ehci_type_info); + type_register_static(&ehci_type_info); } } diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index 3d0339af7b9..65c1f93cc9f 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -1362,7 +1362,7 @@ static void uhci_register_types(void) for (i = 0; i < ARRAY_SIZE(uhci_info); i++) { uhci_type_info.name = uhci_info[i].name; uhci_type_info.class_data = uhci_info + i; - type_register(&uhci_type_info); + type_register_static(&uhci_type_info); } } From patchwork Wed Dec 11 16:26:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903828 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 B98CFE77180 for ; Wed, 11 Dec 2024 16:32:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZn-0007gu-B3; Wed, 11 Dec 2024 11:28:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZk-0007Cw-8L for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:36 -0500 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 1tLPZi-0000Ye-En for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934513; 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=WrsJM87R06FYnwZjzIbMSBqBQmSHO+IxGseQvEJVyVw=; b=C0PBu4B6++SK30nKE1t9BEJxqaVSXgrTwJZJAEHebUYA+1cdWcE0xFpeqiqoLp05h3lfCn vs8o6/6GvsOwZbQ7JGikndvhtnW97l5n9J2L4iYMidr7AyLKtYT2g8os4eUO+TJMT2yABv sQWi7WVcb8KuX2+hwcS2RQmU3BdIWOM= 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-151-7lPIx1_GMQ6Rt5kQYvQrQg-1; Wed, 11 Dec 2024 11:28:30 -0500 X-MC-Unique: 7lPIx1_GMQ6Rt5kQYvQrQg-1 X-Mimecast-MFC-AGG-ID: 7lPIx1_GMQ6Rt5kQYvQrQg Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso7265465e9.2 for ; Wed, 11 Dec 2024 08:28:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934509; x=1734539309; 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=WrsJM87R06FYnwZjzIbMSBqBQmSHO+IxGseQvEJVyVw=; b=vqx1A/FQbz5/0Yw40PFO+ycOsdNnpa276qbJ5QucEKCQgUQ1gTImaVjzf17Zv6nDJ8 L3GJW8yl8fhqVDyrOtcEVMMcQ7+MHMOceocOuXlpq3LRz1+YyU580ec0z8FJ+QjGoczK 95uLxGm0Cs9M9+lvkQInbcfMPajOv7sIGZF8+kH7iY0L9gJvbiulhXatlvl2Qb/oAkNP LtjY9+rSP8Zu2/gbHXzX90/4i2B8lk1lFCF/9l+JMoMcX3tsz5vgtomXFfIT9B4CA7RA L0vjp3FpBNhs986aIPaTQjEp24giNnfG6l8qNxNF6hP+ovliSvt8FhgPCr4R+xOzPczg XLlw== X-Gm-Message-State: AOJu0Yy+yN3tq7m7cn1E9S+cSUXuqhzwSQcBV/mRgUJFcCSqS+kh06zG z/a49Scwyo9o2KYlkmovEcSApOF1HAMhJ/bU8VJo78pJqZ1SqvMI0DRnVBgjHqWjIa/JoZH00zR XHF/D2IC3q/JOA7CV8EzOPqatThRmAcaOl3m+a98OScLq54PXE1W014gIvDqrOT07z6zWKFuk9x a+XvbcZ0H9ZePhXZ5pxnhAKgczGWLY14VJBbGc X-Gm-Gg: ASbGncvK9re+UdC1MxTFfJlKDbTtm6EROjTrpzfcdm6g2akrhPoHZ7XOc9i3qWFCHeG nFd9UVDJbAeaMpbONPmUD7cGJFQ14xuelW6Bcu2wyG8Fe9M5MUNtBoX5IZFmlTw0XkIDU+PGvFt oA0F1sW44NpZSKOFiXz6fXS/ZuI1Fe8UV/m3EwXpHYoDl7mT9sMK9f9nvJRWvk+7AUs6FPfmtLb uqoR5kXB0xzbgI3wqIwIEWVu4XQYSHILR32oRyYklf3JjTt0xAog2Uq X-Received: by 2002:a05:600c:468b:b0:434:fd15:3ac9 with SMTP id 5b1f17b1804b1-4361c3e3aacmr23834785e9.22.1733934507502; Wed, 11 Dec 2024 08:28:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhPFTwdeba7jDc9vZLxIlDGfiUx7pVjXqtyQxGyTljL3q6+8WaUCOz3XKXnm555ya5GD8PFQ== X-Received: by 2002:a05:600c:468b:b0:434:fd15:3ac9 with SMTP id 5b1f17b1804b1-4361c3e3aacmr23834165e9.22.1733934505598; Wed, 11 Dec 2024 08:28:25 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251dc77sm1589469f8f.100.2024.12.11.08.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 27/49] hw/virtio: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:57 +0100 Message-ID: <20241211162720.320070-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-10-zhao1.liu@intel.com --- hw/virtio/virtio-pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 5a394821da9..5c6c2019cef 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2511,9 +2511,9 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) base_type_info.class_data = (void *)t; } - type_register(&base_type_info); + type_register_static(&base_type_info); if (generic_type_info.name) { - type_register(&generic_type_info); + type_register_static(&generic_type_info); } if (t->non_transitional_name) { @@ -2527,7 +2527,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) { } }, }; - type_register(&non_transitional_type_info); + type_register_static(&non_transitional_type_info); } if (t->transitional_name) { @@ -2544,7 +2544,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) { } }, }; - type_register(&transitional_type_info); + type_register_static(&transitional_type_info); } g_free(base_name); } From patchwork Wed Dec 11 16:26:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903830 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 5A37EE77180 for ; Wed, 11 Dec 2024 16:33:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZk-0007JJ-SB; Wed, 11 Dec 2024 11:28:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZh-0006nm-FU for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:33 -0500 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 1tLPZf-0000Y5-Pl for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934510; 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=8NLLgbzYAR30822TQnyZFqYAZd1RN5I0WySMepXl6Io=; b=HW6LmZ8u1572hzC3+nCRPUnTnxvPzDpuPfpuMGUlLWiUWw6jbSqOrProfuSRYjtoS3yQ/k 57H2dF7KQRHvxpkzaJgLmVF1WTsf/v3eCROVhzGE2fCJgeV6bOab/z5LM59VD+LDQjvsE9 ZjWYkczc+XyP5MPPYaAurRTjjB71QX4= 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-647-Yr0mUX9QMbukb2uboVP5lA-1; Wed, 11 Dec 2024 11:28:29 -0500 X-MC-Unique: Yr0mUX9QMbukb2uboVP5lA-1 X-Mimecast-MFC-AGG-ID: Yr0mUX9QMbukb2uboVP5lA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso5209055e9.1 for ; Wed, 11 Dec 2024 08:28:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934508; x=1734539308; 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=8NLLgbzYAR30822TQnyZFqYAZd1RN5I0WySMepXl6Io=; b=UZ1TFwU4WWwRqryOlE6A+O/y8sS0lrBGjRgd/9QnxQG57wvPx6APpHg85G+7pY+gVy 3tRA5ty6v/j9OSQHJzscHhjDVJ/PPSbJ41OQ/qG5z7N8HGKdpaBULwKBeDhONobmITR3 E6+dSmXpIpQK7UTli9nmnEQ9iuxOsBYF4/uUx5egMN7Bc2GTe3drNj3qY26B4WIdxdOo EVEheCtuyeWiEUCmfJyObK5vkananimfLV1CA8y09a8nNT5oKAv1CCHOWKZNUhkljb5g DRP1ry+4CW5kXgXTEUyOEEb7dAEwvt3FHI3k+ZGlxbjbKCAuLuXq4k1frxwAaUv5TsBM X3Kg== X-Gm-Message-State: AOJu0YzE9WnkJ3NdAAX7RqRW0Rts5oWQTVuwUsKq8Hw6kSnpaegvGcf5 nQlvGMrarMx6DDl9f68Mp4jZcj/2z4TLkmk2ekQTSdm3Q5zUl4b4AafuKbawe+NQ8I/JcMgOFVD I7LMZgqTW1OMDQl/ZTidm9TDaFvN+GORZPnEU+2EyEu6VGsgBWeDLJUFXqH9ImPRBwxYbquqdon mGyvL17DU1Z/ndpa35wXrCzYJEae022L8s/fbP X-Gm-Gg: ASbGncu4fNs0uAin3z55lRXAYiO1R7Z6J68O2uaddm5+1d61slrjHXD1+Ly1b4I266a VbJl7knmD9rKsEED9C8JWh7H9icQHRYLRZkvhdxsR1aItMER1B8mwOlFvQHjy6u73d4Y9d4/lc9 OVD+KCPFshzxlT3qNHv0MqmvEcByTaqq/aklWN+0+hyEARrEdeE6nI14a4xVk/rwAhVPUqssIXj LFQWysq6yqBosvu2Dbpi1GH2tJ2FMhq2Q0Jt9tQFpGWOAgX8RE6nWr4 X-Received: by 2002:a05:600c:3548:b0:42a:a6d2:3270 with SMTP id 5b1f17b1804b1-4361c3e2345mr26020455e9.21.1733934507792; Wed, 11 Dec 2024 08:28:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrK+4EDxorH88C3+2cLIr9tm3wrM8PaKSvtEuIFBw+SIV6dLxduqPQT90z9QY87wYgtRXDUw== X-Received: by 2002:a05:600c:3548:b0:42a:a6d2:3270 with SMTP id 5b1f17b1804b1-4361c3e2345mr26020225e9.21.1733934507326; Wed, 11 Dec 2024 08:28:27 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248e600sm1675795f8f.7.2024.12.11.08.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 28/49] i386: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:58 +0100 Message-ID: <20241211162720.320070-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-11-zhao1.liu@intel.com --- include/hw/i386/pc.h | 4 ++-- target/i386/cpu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 14ee06287da..b3477ad6a29 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -316,7 +316,7 @@ extern const size_t pc_compat_2_3_len; }; \ static void pc_machine_init_##suffix(void) \ { \ - type_register(&pc_machine_type_##suffix); \ + type_register_static(&pc_machine_type_##suffix); \ } \ type_init(pc_machine_init_##suffix) @@ -344,7 +344,7 @@ extern const size_t pc_compat_2_3_len; static void MACHINE_VER_SYM(register, namesym, __VA_ARGS__)(void) \ { \ MACHINE_VER_DELETION(__VA_ARGS__); \ - type_register(&MACHINE_VER_SYM(info, namesym, __VA_ARGS__)); \ + type_register_static(&MACHINE_VER_SYM(info, namesym, __VA_ARGS__)); \ } \ type_init(MACHINE_VER_SYM(register, namesym, __VA_ARGS__)); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3725dbbc4b3..305f2a41cfb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6429,7 +6429,7 @@ static void x86_register_cpu_model_type(const char *name, X86CPUModel *model) .class_data = model, }; - type_register(&ti); + type_register_static(&ti); } From patchwork Wed Dec 11 16:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903822 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 2F8FDE77182 for ; Wed, 11 Dec 2024 16:30:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZo-0007ui-Dz; Wed, 11 Dec 2024 11:28:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZl-0007KT-1J for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:37 -0500 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 1tLPZj-0000Yk-Fh for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934514; 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=qBgLfBS5ZuN9Z7jRu8BauK7VaaSsZ7DmRIPGkrNFP5I=; b=TU7KpsZlJvi+jxXzBcy/BDOLQBiEZ3MN7ofzGYMh0AVKbBKc42RN+RnrXDXY01Og5BUbBe S8rxwARRK4JStnqyILew1kkRKhi6uocTADYLhpCMS7Ic6P6D++34ZFrhirzDRs9iSBhxmE 9ubcf2r3AD7/c9ZCjCyOXnCzCSRB1nM= 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-677-6lXsWJ30MoOnndM2wOt3Cg-1; Wed, 11 Dec 2024 11:28:33 -0500 X-MC-Unique: 6lXsWJ30MoOnndM2wOt3Cg-1 X-Mimecast-MFC-AGG-ID: 6lXsWJ30MoOnndM2wOt3Cg Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-434f3a758dbso36613005e9.0 for ; Wed, 11 Dec 2024 08:28:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934512; x=1734539312; 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=qBgLfBS5ZuN9Z7jRu8BauK7VaaSsZ7DmRIPGkrNFP5I=; b=CwIufvZQ2pNRdO5ch0hWI0my7iznUO6kgPF9pBq3OvlMEGc9VaPptgxUIkcFVcApgs WIE15FvF0JkeYkf2mIoPrENNEd6YLtllF/Mxzr6y51azqIAnrbyv3uHb/QCT6tBaUdsg ko5MLYJMAC91bL2rTxIYxSGm3BJye4yRF/jjOwDLZsg3IVO6v3281zz3vkCiHHoKbtZM W3DbiqB1C+HDBWf1q+C4kJwaSM18t6KlWnkuAYwUSyukpUeLWZv+m+vf7O8+qq7FkH31 Y6GIJ83gD64zd9sU5KMJdJHbKZSJqA/XdXQAdrTwDmgm8CY03gJccghJTDIgh6lENlNp 41HQ== X-Gm-Message-State: AOJu0Yx1kO+/vfyMpDav6UqpIiuu2/7oHChloIWBqjL8Vlu8f3JvTCu0 9xXakbeArP6STZBDinKyyC7pL14FHh/hxCthwtwR+YWfjJSRAaF3gd+kqTA55p3k5lfVHwcn5GS XqoQlksm7qmbJrcWpPvVA465HRveK2viPm8ZcCpxUPlr1JcbULBf3j43K3J3nStnguSOWjnk9yf hmLWqLPJJXiGAMLvndnpx7zWbPeZ5sSLiJkvxj X-Gm-Gg: ASbGncvyfB+MCuIMHiPxk0j37AB9Ek6kLPvbOOge7bitqovfC7jj8+IqgH4A/RdzwoI R0YjQBJ+cauHzCyQ8NOD9bMXFSqIzq4sOVdMIDNG45b+sp9+q++WE5ALF1cHu54Kk+rb39M/OUf lYo5ttljZch3nU+4h2SPW1oNMC8cnY24/Mip05EoktetMv5lsTmny+w7eRT+2Ac9U86lToxg1E8 8mONY1yz2y1jNzcPgs7rASiNfrM6QiKHyQvZCdFcrlswwUi5PNZVLpD X-Received: by 2002:a05:600c:5122:b0:434:f586:7520 with SMTP id 5b1f17b1804b1-4361c393894mr28479335e9.6.1733934511712; Wed, 11 Dec 2024 08:28:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+5y81OY/u8ufDzx1N4jxOVntpMsfsDLMSUQJzp/FRFvfFQs/FgDIJ4Lln7Zrb1FhXso1iNQ== X-Received: by 2002:a05:600c:5122:b0:434:f586:7520 with SMTP id 5b1f17b1804b1-4361c393894mr28478975e9.6.1733934511039; Wed, 11 Dec 2024 08:28:31 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361b7a46c1sm32662105e9.33.2024.12.11.08.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 29/49] target/mips: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:26:59 +0100 Message-ID: <20241211162720.320070-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-12-zhao1.liu@intel.com --- target/mips/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index d0a43b6d5c7..4feacc88c0b 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -626,7 +626,7 @@ static void mips_register_cpudef_type(const struct mips_def_t *def) .class_data = (void *)def, }; - type_register(&ti); + type_register_static(&ti); g_free(typename); } From patchwork Wed Dec 11 16:27:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903812 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 BFCF2E77182 for ; Wed, 11 Dec 2024 16:29:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZs-0008Li-9C; Wed, 11 Dec 2024 11:28:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZn-0007lf-9N for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:39 -0500 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 1tLPZl-0000ZB-EU for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934516; 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=5OIwR35d63e1rEw4wpchzcthjW0MxeFOPrWTnC7Wi88=; b=L9kzaSukodJfhdKO+o7A23ikWWsWe/l4rFcU6mg7gs18IeBKntM7e1Ll2IeS4/zBpZdavx Ln2aP7O82P3x3IIpAgLlZsvOccy0oM97VRUhIODQjeWJzeYYX22MCuEvrVYYO7rVkba6Jd vowu7eE75Mvuo9glCcCGk8HI1+ekCUY= 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-47-BCfykE_XO0uqv_nP199CCA-1; Wed, 11 Dec 2024 11:28:35 -0500 X-MC-Unique: BCfykE_XO0uqv_nP199CCA-1 X-Mimecast-MFC-AGG-ID: BCfykE_XO0uqv_nP199CCA Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38639b4f19cso2567934f8f.0 for ; Wed, 11 Dec 2024 08:28:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934514; x=1734539314; 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=5OIwR35d63e1rEw4wpchzcthjW0MxeFOPrWTnC7Wi88=; b=Vqf+EgPNshzxLgbzN+s2d798erHatUIDF9vOYgyS3xykFpynZzMK6B/NcHryQfWpS3 kx5yYQhBkSU27bK/TPRYb0OgEC+D17KHvsE+q6aBwSeiAzYRCi0hqDXI1E1zsMNWid7S NZqqoeEy70nIplYsaU8H23rDaBuNqm/ji1rNNMbdXNq6n6hChH4TamgvD/kPKV/1GOM6 HnARXLR73ne7C1cwRkF+v0D1aXd5stfpLBtlVlrWXIdqewsU//xmjnF2eAql+Aw96UyI YHlZ7Wd7gliQVeqsmCfs5Jro+YgTd/G6Q5hru//yNxZrjvq73s/9pwU6M22i2sw7TJmj djcg== X-Gm-Message-State: AOJu0YzgP7zrnqNXM5B4KihizVcZmTEXXzCAawTLjXdgpV1fd81DTGuG oqvAriV64szQA4kkH1VsyTV7YMhQDcBUlkfk1x6dzogxpx6ElC2eYaDOSrCWGaxG01IERjRALd0 fOZ/74EIJokSnaMCsOpQvdgQ0umYNPooOFO8GK2Qu+K7RnkIWvuE8si5bSlESjEIpyc8L7iiCI9 fylL4hdLWo6gAPulzgL/HJycRjJ/zePR94rXp0 X-Gm-Gg: ASbGncsROq3+KYBSqQddFsXwQ1EX/cfJNbXsTWHrbulegcEDNTQbuCATce3lEO0QqwC 0uJPGyaHFpLUCcMQaZPXsPq1b5m3fDRTliwb5/I8C7xkehbtHWeR2dq2WdrpFFGTULGbr8xuZ4l G9K4QVj9Bj4fmruLERa+mqbGtkVLvoExOBzUIZWWdWTsy7JMEsS2V8RKWJ7MvPYfO0KWu1Bgn/r emI280ykaZzlL8rHcqD1INRilWcPfK0Od1gZTDOMx3h3PQZ1BGyAYRT X-Received: by 2002:a5d:47c9:0:b0:385:e2d5:cdf2 with SMTP id ffacd0b85a97d-3864ce96d24mr2798066f8f.19.1733934513809; Wed, 11 Dec 2024 08:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7/QgjT1Pp9NCd7DV7Kt51LP7hQ4uWkoHPTs2nKS9PEidkIuOl+AQ8Hho/kCDMDXVOIP82oQ== X-Received: by 2002:a5d:47c9:0:b0:385:e2d5:cdf2 with SMTP id ffacd0b85a97d-3864ce96d24mr2798048f8f.19.1733934513406; Wed, 11 Dec 2024 08:28:33 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38782514dadsm1614319f8f.68.2024.12.11.08.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 30/49] target/sparc: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:27:00 +0100 Message-ID: <20241211162720.320070-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-13-zhao1.liu@intel.com --- target/sparc/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index dd7af86de73..adba24af2c6 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -1008,7 +1008,7 @@ static void sparc_register_cpudef_type(const struct sparc_def_t *def) .class_data = (void *)def, }; - type_register(&ti); + type_register_static(&ti); g_free(typename); } From patchwork Wed Dec 11 16:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903802 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 7C7A6E7717D for ; Wed, 11 Dec 2024 16:28:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZs-0008Oj-O4; Wed, 11 Dec 2024 11:28:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZp-00084B-DB for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:41 -0500 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 1tLPZn-0000ZQ-G9 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934518; 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=fir0u+8ptlpf2CF197Bj8LY/8X91SvFC4TuyE/kpTSo=; b=WGRsqXEPOOt6eOZwikI+WQObsZmnHJGJWT15Ht3U0Pajwv7cZzZ9K0cMhJkSBrYqGpPqxw tA9MlVKqcaXWSBhfgVn/ypKGJgEg3rvGUqZZB3rJLnfFSLHPsexaFyIdifUZGIgWUx0aAZ fBNky0NxK5bF0XO4hy2R8EFCnu5STK0= 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-189--K7pNdq0PqSwEOW5FIerOQ-1; Wed, 11 Dec 2024 11:28:37 -0500 X-MC-Unique: -K7pNdq0PqSwEOW5FIerOQ-1 X-Mimecast-MFC-AGG-ID: -K7pNdq0PqSwEOW5FIerOQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so16807975e9.2 for ; Wed, 11 Dec 2024 08:28:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934516; x=1734539316; 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=fir0u+8ptlpf2CF197Bj8LY/8X91SvFC4TuyE/kpTSo=; b=Gy12X5ftyPxFNQ9QgshTeHWlyFwrIgimqHXkhUmb3X9Rd1zNv9AQ8+2XFOhNySLBvL xYjOfKh/qC+lV24+Hj04UhBQnC7X38LLEYYYtRhc7b484wkp65xLD8CYEQyx9pgcMzYx uG1dI9DQeV3QCmXEdruPtAtFy1Jpvj4ae326AqgdaHcyO8Vo6saNR9RGnBjXfnxZhvYQ m2y31esO3WiSWxhFQGa9UkOUsZ72MpzA+SHRmx3tJZ+7sFYhzjjp7zNjgiHXMi+veamB +wtRx1B/zF091IZtz1wufZv6TrTE6c0vXXiMrhZkEaJG8mUEyrqAc/F8/CZWCmkNvF3Q 4C5g== X-Gm-Message-State: AOJu0Yw/GRp4LQ9GhbTLxN1dq7CBYoGFJqeL45bApNvWq1ZjaN8v2372 UUIdhzaoQagYmnp8Mwmt/5oZngN1B5gPgkOVD6JJrElAKTUdjRquiQQxhkFDexLQSAL2IQdOVEH M0CiIF20n0js4Z+j3QZcfsH0TneV+1xWlNWqdWLVrtMwVl6YWkfgkCqcQ6J5Vi3c0GUxID97+U6 C+DZtlKPHr7sBCySWuoaliyOGKRTRKQYg8mE8S X-Gm-Gg: ASbGncsVFQy2sAufVGBQ2kH/riRkhATU8F8ZPS+pbv5tnfjV7KFh31/CUiDI0XblPvG D0t1ocecbo4brYatRYQRb8HIoSHjf780fYTUFVsm8bWY4bFeukIBXlL2kHOT3lZ3j73bca164Le YW+Mg5AX7K2GHotIcTzFKKszZrlxoSXkJhrVvw2CNl5p6j8DHgpCcGsTG6PDOwjfTi2xKYmh0e2 ILs/VEH5ZOhUj50uC0E31DDHYF/NFSdQAOvS0PfkCYSjUnSqUiDUlYX X-Received: by 2002:a5d:6d89:0:b0:385:f10a:335 with SMTP id ffacd0b85a97d-3878768dc29mr173507f8f.21.1733934515769; Wed, 11 Dec 2024 08:28:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjknTRrR32eQpKOFykRk7Mt96sKD5ztFpsNMc6XcY4rXEktA2XbAyEo9NNYvRP6l1Z77UdeQ== X-Received: by 2002:a5d:6d89:0:b0:385:f10a:335 with SMTP id ffacd0b85a97d-3878768dc29mr173484f8f.21.1733934515238; Wed, 11 Dec 2024 08:28:35 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824a5005sm1631254f8f.41.2024.12.11.08.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 31/49] target/xtensa: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:27:01 +0100 Message-ID: <20241211162720.320070-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-14-zhao1.liu@intel.com --- target/xtensa/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c index ca214b948a9..2978c471c1f 100644 --- a/target/xtensa/helper.c +++ b/target/xtensa/helper.c @@ -198,7 +198,7 @@ void xtensa_register_core(XtensaConfigList *node) node->next = xtensa_cores; xtensa_cores = node; type.name = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), node->config->name); - type_register(&type); + type_register_static(&type); g_free((gpointer)type.name); } From patchwork Wed Dec 11 16:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903834 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 30C93E7717D for ; Wed, 11 Dec 2024 16:33:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZu-00008B-A6; Wed, 11 Dec 2024 11:28:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZr-0008JU-2d for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZp-0000Zg-CN for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934520; 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=FZI5/v+/ln/vWvbd1neY06KNWkby6DmmwS0Dx52j1Hw=; b=IfF9Zb7n06oCIM+oRAdDPYhvvhcBSI6fLQbP1xfOv4eOlP0iZ0ESUNjwveDD9A2ZeQYK8s HDFs/qEAYafWcqlFtD0O3VgR6JucqXVaYVLrLi9q3DyaDugbYmHvrQX7xzB5JIP+1gqdAQ 7Du4r9ML6aJ209O0iQwKx6NW8jgIgko= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-454-r4O7GqSgMCCFhFrvLSfQYw-1; Wed, 11 Dec 2024 11:28:39 -0500 X-MC-Unique: r4O7GqSgMCCFhFrvLSfQYw-1 X-Mimecast-MFC-AGG-ID: r4O7GqSgMCCFhFrvLSfQYw Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e3cbf308so1927886f8f.2 for ; Wed, 11 Dec 2024 08:28:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934518; x=1734539318; 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=FZI5/v+/ln/vWvbd1neY06KNWkby6DmmwS0Dx52j1Hw=; b=WiexRJjjWuH8ruqWaG7PFUElx8tnHy/ugIp9MI2mYfwarn5OPS0abB8KkhoXFj+XPS 9UdjvVZAnrNlIVC9JVd0jb6FrsfQ+RymC5r7cl/d7jGLkLe1cKjk+BW9O27hKgYCmQ9s vKoRX3KiD5251m1215GIiVMTbEURqCQsIwTwNlsQA8PbU13mwXVbZG2iGoLuLGs0ERUQ kmz6a2bFXNqq1wvGtCSpZ5Mbqrh7oO4+wgZlKArxsUh1ttvCaIRYk09kCwmW8YbINYRD VyBiPYvRLdlDDKTeXIYpheRpglSF/2SF1bZeayL6rWhdHf11Nf4fr5FODU99F2TNCT0l zkTQ== X-Gm-Message-State: AOJu0YxAaI67b3DNcUatycUMmyx8OGlJ94EpZOaKbAwBC9pdq/xfPPBC 3x6vCpzWC5m4P0Tf14rXN7VqUCoF6UD1anvePnnEEfL2yXUSynmooyMzX+pR3JFPkE+UJZUEjDk DV+CH6bl/LWMMGDPHm4wWMM3MO244GRLItd/WC10ypIbwMtbIwwsZZPrL9ego7zHK5m9/EsNs3W HN6iKCPodkNohn04+Ns4QEHbT2jC9/Juq9yTcp X-Gm-Gg: ASbGncsQZg6QSWd7EpQcsaBkPhTwx0VtbCH4vGlbteketwcvzzwwG5rjepje2TgwQ85 147Njuf6FDQbudP125vaeaJfXSzZHoHnL9B0BSMQ4f8lFAfyF/jTqTvcYWcEuOIUGSsJMgBVe9E mUNz/MT36LKB3T4Be7rCC5jjK/m3s+8o3woU8CezFn41agY9sGIC79S8QRzROsyKAli/BUqgyXG SBGeljQ7JWNA9oCqNUXdU3+ToV9Pes5RiubD38RNUY2vCZwB6b+XgeK X-Received: by 2002:a05:6000:1f82:b0:385:f56c:d90a with SMTP id ffacd0b85a97d-3864ced1f55mr2797834f8f.55.1733934517853; Wed, 11 Dec 2024 08:28:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjRpGkHppd0mFWYrc+FcWiiiOkRrj6DgQZcIErh/S+ASQeDpQJRSljSSFhgD7C21QMjMIIXA== X-Received: by 2002:a05:6000:1f82:b0:385:f56c:d90a with SMTP id ffacd0b85a97d-3864ced1f55mr2797814f8f.55.1733934517458; Wed, 11 Dec 2024 08:28:37 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248f440sm1622353f8f.17.2024.12.11.08.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 32/49] ui: Replace type_register() with type_register_static() Date: Wed, 11 Dec 2024 17:27:02 +0100 Message-ID: <20241211162720.320070-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Replace type_register() with type_register_static() because type_register() will be deprecated. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-15-zhao1.liu@intel.com --- ui/console-vc.c | 2 +- ui/dbus.c | 2 +- ui/gtk.c | 2 +- ui/spice-app.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 53fcee88f4a..fe20579832a 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -1073,6 +1073,6 @@ void qemu_console_early_init(void) { /* set the default vc driver */ if (!object_class_by_name(TYPE_CHARDEV_VC)) { - type_register(&char_vc_type_info); + type_register_static(&char_vc_type_info); } } diff --git a/ui/dbus.c b/ui/dbus.c index 7ecd39e784a..d60b59cc546 100644 --- a/ui/dbus.c +++ b/ui/dbus.c @@ -476,7 +476,7 @@ early_dbus_init(DisplayOptions *opts) #endif } - type_register(&dbus_vc_type_info); + type_register_static(&dbus_vc_type_info); } static void diff --git a/ui/gtk.c b/ui/gtk.c index bf9d3dd679a..f9a53ea78ed 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -2540,7 +2540,7 @@ static void early_gtk_display_init(DisplayOptions *opts) keycode_map = gd_get_keymap(&keycode_maplen); #if defined(CONFIG_VTE) - type_register(&char_gd_vc_type_info); + type_register_static(&char_gd_vc_type_info); #endif } diff --git a/ui/spice-app.c b/ui/spice-app.c index a10b4a58fe7..2a93ae59184 100644 --- a/ui/spice-app.c +++ b/ui/spice-app.c @@ -173,7 +173,7 @@ static void spice_app_display_early_init(DisplayOptions *opts) exit(1); } - type_register(&char_vc_type_info); + type_register_static(&char_vc_type_info); sock_path = g_strjoin("", app_dir, "/", "spice.sock", NULL); qopts = qemu_opts_create(list, NULL, 0, &error_abort); From patchwork Wed Dec 11 16:27:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903824 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 2E738E7717D for ; Wed, 11 Dec 2024 16:30:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZy-0000g6-Hr; Wed, 11 Dec 2024 11:28:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZt-00008C-OR for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZs-0000aD-0w for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934523; 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=yjLaRBaRdCVTJi2oAEc5ZtcK2yHd81SHmdhSzBRFY5Q=; b=DVCFTJTnOX1Abhm2PWgbBr05gTFz/uMOM2O0CeWl3pwdeJv3E51EbPSJ5v5orY1wvyPGbn CFgVLmKq1qoPqGjsRk2o7FAr+NBGTF5+CUuyobjT98XaREk2iU82dU9gEcu7T/cAIX4Jv0 Frd0GYbOE2+8hWhEc5j1bWOHfsVKN00= 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-170-3KZKh7iFPrKTxIm0yoHxtg-1; Wed, 11 Dec 2024 11:28:42 -0500 X-MC-Unique: 3KZKh7iFPrKTxIm0yoHxtg-1 X-Mimecast-MFC-AGG-ID: 3KZKh7iFPrKTxIm0yoHxtg Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-434f3a758dbso36614155e9.0 for ; Wed, 11 Dec 2024 08:28:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934520; x=1734539320; 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=yjLaRBaRdCVTJi2oAEc5ZtcK2yHd81SHmdhSzBRFY5Q=; b=hEmxNaP9ouJJOAZ8rLf8xuOlFDLnDp0T7XqmyDUY0MzbPdbeN6Q6Um4Ag/uFCMhx9V XmcjCDA8z55LNk9kP1xop4C/hozoFf/Eshw/l5Gpzg/2RaqmJKruUvbJGSNB130pd2sf 1pvQRJ3lYXlKaTWL8XA3n2HiKWlzzQk8mgRPjT+moYISbyY1dDqMMz0x/TXjbNnPX7hG hzE7/qHro+wGw8t6hthf8+C7YpHCODAY1Rk7GOWbWBS2ZinX8U8O2BxWbb4GRW2LO2ui nolKo0jPd2dxMvcT1mIsECEq8+jYIhUzlZVGG62sL3L/W2mzQpdnsRdrc+8KXrYnz1K9 krEg== X-Gm-Message-State: AOJu0YwSuXD2W6Ko0c1rmMulov9xW+tRCFrjOAyMtwuws7ezXda+49Ma qj/H7gAKzisaW9zyt6SN/zbMqKAZg99TphL50dJY/KIxfrnzwjLyz6HeE4IlW1zZwuMRrHu7US/ U9Q1DxQxaUWWop9UcSpFw8p9m1D5O3ROi/wKWd0cgc8ESfijS3uShAKgm4HeYV+9XMJKMZMp6Ne OeJ/kvwEC9elfGsFzt8pi8s36cc5ulk8NNllLp X-Gm-Gg: ASbGncvNer0Ey8XIgYpkHKUivB2za5KFNKWtXCsLigdZ82wYk9yPeNmfdNP7ELHOZAQ Bs16yf9rmuEGyBpqC+tpvkyCkgKXXyKamqXaYkX+GpFhQtpT2m1F8alfD4fXwHat8HgzZe4pr8d Nr0F3lYyCuuLh0vxCt4HOjetAB83hdt5XD5O+n0tmKIqj1i8v3K1KnDaqOpywFkJoz3nfFT4O36 RFNo/Tg7cctGbO88ewwMYtjIQvyVNyheMA8hD51+0j0JjyEtV57RUH+ X-Received: by 2002:a05:600c:384a:b0:434:f817:4492 with SMTP id 5b1f17b1804b1-4361c43dc27mr37638685e9.31.1733934520201; Wed, 11 Dec 2024 08:28:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFclGICY3jk2+EXDpcD3fL4VZvN4bOkX1OHjpfFL6jJSIObw2BqSBdDBVX4OV0spzoi+Tfv1A== X-Received: by 2002:a05:600c:384a:b0:434:f817:4492 with SMTP id 5b1f17b1804b1-4361c43dc27mr37638395e9.31.1733934519786; Wed, 11 Dec 2024 08:28:39 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251c151sm1622494f8f.90.2024.12.11.08.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 33/49] script/codeconverter/qom_type_info: Deprecate MakeTypeRegisterStatic and MakeTypeRegisterNotStatic Date: Wed, 11 Dec 2024 17:27:03 +0100 Message-ID: <20241211162720.320070-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu Deprecate MakeTypeRegisterStatic and MakeTypeRegisterNotStatic because type_register() will be deprecated, then only type_register_static() is used. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-16-zhao1.liu@intel.com --- .../codeconverter/qom_type_info.py | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/scripts/codeconverter/codeconverter/qom_type_info.py b/scripts/codeconverter/codeconverter/qom_type_info.py index 255cb59923d..f92c3a4730e 100644 --- a/scripts/codeconverter/codeconverter/qom_type_info.py +++ b/scripts/codeconverter/codeconverter/qom_type_info.py @@ -901,26 +901,6 @@ class TypeRegisterCall(FileMatch): regexp = S(r'^[ \t]*', NAMED('func_name', 'type_register'), r'\s*\(&\s*', NAMED('name', RE_IDENTIFIER), r'\s*\);[ \t]*\n') -class MakeTypeRegisterStatic(TypeRegisterCall): - """Make type_register() call static if variable is static const""" - def gen_patches(self): - var = self.file.find_match(TypeInfoVar, self.name) - if var is None: - self.warn("can't find TypeInfo var declaration for %s", self.name) - return - if var.is_static() and var.is_const(): - yield self.group_match('func_name').make_patch('type_register_static') - -class MakeTypeRegisterNotStatic(TypeRegisterStaticCall): - """Make type_register() call static if variable is static const""" - def gen_patches(self): - var = self.file.find_match(TypeInfoVar, self.name) - if var is None: - self.warn("can't find TypeInfo var declaration for %s", self.name) - return - if not var.is_static() or not var.is_const(): - yield self.group_match('func_name').make_patch('type_register') - class TypeInfoMacro(FileMatch): """TYPE_INFO macro usage""" regexp = S(r'^[ \t]*TYPE_INFO\s*\(\s*', NAMED('name', RE_IDENTIFIER), r'\s*\)[ \t]*;?[ \t]*\n') From patchwork Wed Dec 11 16:27:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903813 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 A113EE7717D for ; Wed, 11 Dec 2024 16:29:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPa0-0000yX-AI; Wed, 11 Dec 2024 11:28:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZx-0000dC-JA for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:49 -0500 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 1tLPZv-0000al-T4 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934527; 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=1qS4FLutt/4Sk0zExJZjpAJYdJnqb7SMdrl1fvxcvDM=; b=Dalm2dAyqoPE2vuKU6XKzA9jDccXBROf2ZvX1vvFs6az9fF2TjuOW8hswwVpkfYYe9Mq8B GlKjpARx//eE7TKssHLyC7Pbdxvt+xRcA/RJybQsuNWvMG0fDJ8cxFd5E4bQJZ177D+y70 0cU0ow2e7WxG86geWPePiu/uOXpBp9k= 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-133-iwXdbfABMma-r-59NgVI3g-1; Wed, 11 Dec 2024 11:28:44 -0500 X-MC-Unique: iwXdbfABMma-r-59NgVI3g-1 X-Mimecast-MFC-AGG-ID: iwXdbfABMma-r-59NgVI3g Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38634103b0dso2810435f8f.2 for ; Wed, 11 Dec 2024 08:28:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934523; x=1734539323; 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=1qS4FLutt/4Sk0zExJZjpAJYdJnqb7SMdrl1fvxcvDM=; b=WMm6Lo0PYmXxq/uJaFBtDWxqsGO3obOJb4B4MGrkY/JaLngtHRyFM20Ovj89rOpKQv E4p2KfQR1Tvg2v4EYmyxG8byX3FJsmyOyivfXzwp8MsvVyhHVrNTMKICOZEO2IhcUq5o 5pwZl9Zgn22kralLANdHC6speyjdxIb8vpw6t8SDfmgdjrjirz3j6JSsB853Zv0x5E6G /SG2vm6eCVl/Yf4NEuCoiNEoaldjA3Hpv3znbD0Ah4M5i9jKSTAFMSIQ9rGHJfIL9gl2 ucHu3983EYmqf5Vx9/VAIlfuuzjUbpHO/MdefkTv6qu/8EbsmcqM3LAvhnmaC53N/hiK b+Dg== X-Gm-Message-State: AOJu0Yy+bsyF6H9+Q/u4SlPD1vbBmZkD0pwk0JoIWvaOp31eKajIKmfZ IuHpoyxrFw3mgrKQ1N+NCG60Opt75/lKp6SiulSMPVpqKnH6O+r1ynZF8XeN6Ynwpb14nFa7ddz Mpf2NS6Ns3TZUl0+uHMwJGRoomXc8VKGCq5Ne311kYPmUVLR+8Tpf8Jx7Q/mlEtHNkl267ogLd/ nJViRWoidpLg5XokICSIF+lKZ6mukxfqwVaGia X-Gm-Gg: ASbGnctDjBkbtqYE8a3b3MKVEQLAisbnAu52mc+JkcZ4T0pkAkzzzMcdO0Whmi5zIx7 5qSGI9PmIObmk7KkP1ymx42BZj9JHb2dkH0adbh4x6lhh86Y8KzXBQNL/fAplk7svCgj44EMjD7 tk6WE2rgCDZ5sBecIVZQmiouI5bokyHJZjD/YzlcT9G6JbD38QDoNeipXjwnTclW22yrSzHIW6/ IYazPhQHHkTaejkOHkQDqAdwpOyft2+bPyfBroEluUISew8HaEyUiBA X-Received: by 2002:a05:6000:1fad:b0:382:4b2a:4683 with SMTP id ffacd0b85a97d-3878768842fmr240687f8f.2.1733934522757; Wed, 11 Dec 2024 08:28:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKkrbbkNT4OV2i5Il92UD68pQBbGj/9xVKbgcwTXTooiAB5o8AxUnKC6/SaH7JaqjDw2D37A== X-Received: by 2002:a05:6000:1fad:b0:382:4b2a:4683 with SMTP id ffacd0b85a97d-3878768842fmr240667f8f.2.1733934522309; Wed, 11 Dec 2024 08:28:42 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824c50b7sm1608536f8f.57.2024.12.11.08.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 34/49] qom/object: Remove type_register() Date: Wed, 11 Dec 2024 17:27:04 +0100 Message-ID: <20241211162720.320070-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 From: Zhao Liu At present, type_register() and type_register_static() are identical, although their documentation expects the *_static variant to accept the Typeinfo with the strings that have the static lifetime. However, the code implementation doesn't have any check or guarantee for static lifetime. In fact, this is unnecessary because type_new() duplicates all strings, thereby taking ownership of them. Therefore, type_register() and type_register_static() are redundant, so one of them should be removed. Since the changes required to remove type_register() were smaller, type_register() was replaced with type_register_static() throughout the code base. Drop its definition, and delete the requirement about string lifetime from the documentation. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241029085934.2799066-17-zhao1.liu@intel.com --- include/qom/object.h | 14 -------------- qom/object.c | 7 +------ 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 43c135984a6..a201c9712a1 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -880,24 +880,10 @@ const char *object_get_typename(const Object *obj); * type_register_static: * @info: The #TypeInfo of the new type. * - * @info and all of the strings it points to should exist for the life time - * that the type is registered. - * * Returns: the new #Type. */ Type type_register_static(const TypeInfo *info); -/** - * type_register: - * @info: The #TypeInfo of the new type - * - * Unlike type_register_static(), this call does not require @info or its - * string members to continue to exist after the call returns. - * - * Returns: the new #Type. - */ -Type type_register(const TypeInfo *info); - /** * type_register_static_array: * @infos: The array of the new type #TypeInfo structures. diff --git a/qom/object.c b/qom/object.c index 9edc06d391f..c7660f9a097 100644 --- a/qom/object.c +++ b/qom/object.c @@ -175,17 +175,12 @@ static TypeImpl *type_register_internal(const TypeInfo *info) return ti; } -TypeImpl *type_register(const TypeInfo *info) +TypeImpl *type_register_static(const TypeInfo *info) { assert(info->parent); return type_register_internal(info); } -TypeImpl *type_register_static(const TypeInfo *info) -{ - return type_register(info); -} - void type_register_static_array(const TypeInfo *infos, int nr_infos) { int i; From patchwork Wed Dec 11 16:27:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903847 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 0886FE77183 for ; Wed, 11 Dec 2024 16:35:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPa0-00019G-Mu; Wed, 11 Dec 2024 11:28:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZy-0000l4-FP for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:50 -0500 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 1tLPZw-0000aq-F0 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EK+6NhPLRnfB+w3ii90rEiEDD8OWs1ZakSYY9qmOsvM=; b=X580G6WT+7ZRiQVuOTZIu8/wqVAl5NvpAQxMnjxNydPCB8OdPVy5HxvE0IlfQU7TxXH1Wi +MKNbGd3zECcCr/lLcWma5HOS1JkLpq86cqtgZJUA72D8oyvZby0o7JL8FRO3U1MTlSalM 7E11riZRTOJW0+g+ved9TpmEeoXmfO4= 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-321-IGgLTkXOMx-7vjyvGgnRZA-1; Wed, 11 Dec 2024 11:28:46 -0500 X-MC-Unique: IGgLTkXOMx-7vjyvGgnRZA-1 X-Mimecast-MFC-AGG-ID: IGgLTkXOMx-7vjyvGgnRZA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-436228ebc5eso545515e9.3 for ; Wed, 11 Dec 2024 08:28:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934525; x=1734539325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EK+6NhPLRnfB+w3ii90rEiEDD8OWs1ZakSYY9qmOsvM=; b=wO5Bb93Hpkn52S/blx73fsBXC6GjavsfuHc14ORHi1ICN0fhb338pAlzQmYAN4DU5P /PfehYjtVqPsQm1Sjtilw1pq7QABTlp3WU3QzS0PmjF5t7P5ORPY2QW6RIdAUPw4MVUV wN1Nv5xyWF5VSgghekYrvneFGU09wVv62zpb3jjiGagfz5UWRT/rG2QEEjPrW5iCOX9r prMENmXUACMvaK4J/qOcLf3QAdfJ97JIvgzwerKz9OeRJVd+blvX9wMyUymEvijM3uc3 0RWwfTTdZ3tUb75biFLyHfo9NjX1+BM/t9SSP7Yebp8E9X1+CSX4wFfKAX+33kdcAuPK QJhA== X-Gm-Message-State: AOJu0YyQytHJE4wCAENt62aMvL1dLJClS50bsJa+4brPqtvqeVAi1auU 8jPSLfQytpe432Hd3anncU9fzVD0JEgrl9ipHxrjQaQkYC5pdbNytZ53IFxO5A47L4sU5ALDcFd bE900NGLLAQuaSFa1GED/dd9BAdR++Iht32tCU7gopItMOIncAbZPdFxcFyq0MilQk4Q1mc1oSJ LSJaABfgCwk9j/yif0Ho6Tu8XGyxZ7y9W8L2D+ X-Gm-Gg: ASbGncsITO16PcREgrcK3yU7D1NxgxmGTD3jqZVGfLhrGbIL02gVkjJ/WzC672mpzJc ox2HIEYLUPaq3s1IibVdiEExcIIC9CPWef+9iT+RX7Xe1Oh6kHNKIPkPX0DP0nk5Q8BE9Go3gA0 mAx/jA3j+qVOuWQEExqY7YcLCi0tATGWMAp4YKFzIqCgSQwJwSA2dC4topGaOPAUAQ/DrgtxOJ9 gE+M7ibcJxssUUpa6Y39+e2IjF1V9GF5KfD5T+W7H9RSiL8YGW01fn2 X-Received: by 2002:a05:600c:1c16:b0:434:a315:19c with SMTP id 5b1f17b1804b1-4361c3445a8mr31170375e9.3.1733934524960; Wed, 11 Dec 2024 08:28:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1NQSjtWwRbIgKj+KS2F0+VKRwFApGXkxJY9BRaohVm5M+WwGRd+Ack1uUA6b6Po3ix0qjOg== X-Received: by 2002:a05:600c:1c16:b0:434:a315:19c with SMTP id 5b1f17b1804b1-4361c3445a8mr31170085e9.3.1733934524448; Wed, 11 Dec 2024 08:28:44 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361ec75410sm16194305e9.1.2024.12.11.08.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 35/49] bql: check that the BQL is not dropped within marked sections Date: Wed, 11 Dec 2024 17:27:05 +0100 Message-ID: <20241211162720.320070-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 The Big QEMU Lock (BQL) is used to provide interior mutability to Rust code. While BqlCell performs indivisible accesses, an equivalent of RefCell will allow the borrower to hold to the interior content for a long time. If the BQL is dropped, another thread could come and mutate the data from C code (Rust code would panic on borrow_mut() instead). In order to prevent this, add a new BQL primitive that can mark BQL-atomic sections and aborts if the BQL is dropped within them. Signed-off-by: Paolo Bonzini --- include/qemu/main-loop.h | 15 +++++++++++++++ stubs/iothread-lock.c | 15 +++++++++++++++ system/cpus.c | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 5764db157c9..646306c272f 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -262,6 +262,21 @@ AioContext *iohandler_get_aio_context(void); */ bool bql_locked(void); +/** + * bql_block: Allow/deny releasing the BQL + * + * The Big QEMU Lock (BQL) is used to provide interior mutability to + * Rust code, but this only works if other threads cannot run while + * the Rust code has an active borrow. This is because C code in + * other threads could come in and mutate data under the Rust code's + * feet. + * + * @increase: Whether to increase or decrease the blocking counter. + * Releasing the BQL while the counter is nonzero triggers + * an assertion failure. + */ +void bql_block_unlock(bool increase); + /** * qemu_in_main_thread: return whether it's possible to safely access * the global state of the block layer. diff --git a/stubs/iothread-lock.c b/stubs/iothread-lock.c index d7890e5581c..54676598950 100644 --- a/stubs/iothread-lock.c +++ b/stubs/iothread-lock.c @@ -1,6 +1,8 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" +static uint32_t bql_unlock_blocked; + bool bql_locked(void) { return false; @@ -12,4 +14,17 @@ void bql_lock_impl(const char *file, int line) void bql_unlock(void) { + assert(!bql_unlock_blocked); +} + +void bql_block_unlock(bool increase) +{ + uint32_t new_value; + + assert(bql_locked()); + + /* check for overflow! */ + new_value = bql_unlock_blocked + increase - !increase; + assert((new_value > bql_unlock_blocked) == increase); + bql_unlock_blocked = new_value; } diff --git a/system/cpus.c b/system/cpus.c index 1c818ff6828..ba633c7688b 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -514,6 +514,20 @@ bool qemu_in_vcpu_thread(void) QEMU_DEFINE_STATIC_CO_TLS(bool, bql_locked) +static uint32_t bql_unlock_blocked; + +void bql_block_unlock(bool increase) +{ + uint32_t new_value; + + assert(bql_locked()); + + /* check for overflow! */ + new_value = bql_unlock_blocked + increase - !increase; + assert((new_value > bql_unlock_blocked) == increase); + bql_unlock_blocked = new_value; +} + bool bql_locked(void) { return get_bql_locked(); @@ -540,6 +554,7 @@ void bql_lock_impl(const char *file, int line) void bql_unlock(void) { g_assert(bql_locked()); + g_assert(!bql_unlock_blocked); set_bql_locked(false); qemu_mutex_unlock(&bql); } From patchwork Wed Dec 11 16:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903833 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 C3DB7E77183 for ; Wed, 11 Dec 2024 16:33:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPa4-0001ca-Db; Wed, 11 Dec 2024 11:28:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa1-0001J9-Ph for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:54 -0500 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 1tLPZz-0000bX-4F for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6JBMRY3yPwvZl5yJZxibeS0bOveitWDH+vkfjHoXH08=; b=DwNI6yK/e2G4lDErCwSeniAGNmqrfR5PWEcNt938xmoNN9MBjyXeuVbh/2rv0fVOym/V4f ojT5NDKD7l3hKQFOe0JPdYjOgtVm7U9q3VSPN0BY1rxvMCA5RoUBQ+yWyNGJvk1s9fMsC0 HSu3MONrltYEkIk+pg0E9VcV9nc4SeI= 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-83-eS1cTOXaMeWtLTAGAMta5g-1; Wed, 11 Dec 2024 11:28:49 -0500 X-MC-Unique: eS1cTOXaMeWtLTAGAMta5g-1 X-Mimecast-MFC-AGG-ID: eS1cTOXaMeWtLTAGAMta5g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-434e8beeed9so40375585e9.1 for ; Wed, 11 Dec 2024 08:28:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934527; x=1734539327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6JBMRY3yPwvZl5yJZxibeS0bOveitWDH+vkfjHoXH08=; b=kd+lTQCUqPI2wiGdBzQXf8u2yh/Xp5JB17PuLggOj61mvCthJakh1Xy+KCQxt2pYBa THOZFfj6w1rXUXuTkioE+PM7q7DLgBZjOiZKhVANK40sGtkHkS02PLD+qyqNl+6MDvJd 54KzdTLidefHkfjHhvDbZiqZBXAAUCMOhED2O0d45/F0l4BpH5xuSfamxXVZw8CXachE SIreLtD+bm0nUnr+A3Yp14+e2L5F/4s3kiBEbf67kxqB+XoWJzwWU6qJFOFtBofa+D7U qnnqK6Z7oxQCRMNfw37n3M43YT04iEMKoJtEzstSAC1cjQ/SuAxf0vbucSpdk7J5yKSk 4QlA== X-Gm-Message-State: AOJu0Yzg8W6hSTBCNVsco/Kb3tqxHPWUwUGAt5BBH39QLJ5zf0Uz+XV2 EkxqR2iiLS1/v18FYFRdTQUcODnNOiG7tO4/WVleUXyeP6oPE23TgUMsSx+dSJk2mJQllKIk2mp 1zLQltldr1MYOoggkzOQQ4HgYpiRlKB1pLles2w9lOiZnQTDI/gKypZr8iTJpVzsrkGqmChfkvC LLp70tMaWDUeTxM+3ypRMYPovcGg4inHJhaGAY X-Gm-Gg: ASbGncu+HOmJ6opH5qfLmj4dCxMNxU+KNb5hR6OnGvROJyHMxRWt8VtTpP4/SmjwC6M g2ivTiH60HEwN52/CceBl1xEO6Qu0vZFd1SQcG3kjHXHF4tV4hBpcA+l+EQZ8dDqg8HsWqMn3q/ SJNNvP22mjmo0k0fTJmIyZcCcrIl1xRgFET2eeqwV4DBR1EFPQp92tK3S31Sssn6mwgAoiNnsDt e7qk2/3B/UmfTo75S8zw8onO6f5kE8WhSv10S7uFb6YfCVQyFNLBh/4 X-Received: by 2002:a05:600c:46c6:b0:434:f9c4:a850 with SMTP id 5b1f17b1804b1-43622833224mr4130185e9.10.1733934527221; Wed, 11 Dec 2024 08:28:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmBkV4gwFRkT0UNGaY76lAkT+FF6TltsGX0fmVmTD3V6VkupA70p+8jJBY1LPXliYNi2IOWA== X-Received: by 2002:a05:600c:46c6:b0:434:f9c4:a850 with SMTP id 5b1f17b1804b1-43622833224mr4129685e9.10.1733934526365; Wed, 11 Dec 2024 08:28:46 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248f68bsm1610193f8f.15.2024.12.11.08.28.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 36/49] rust: cell: add BQL-enforcing Cell variant Date: Wed, 11 Dec 2024 17:27:06 +0100 Message-ID: <20241211162720.320070-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 QEMU objects usually have their pointer shared with the "outside world" very early in their lifetime, for example when they create their MemoryRegions. Because at this point it is not valid anymore to create a &mut reference to the device, individual parts of the device struct must be made mutable in a controlled manner. QEMU's Big Lock (BQL) effectively turns multi-threaded code into single-threaded code while device code runs, as long as the BQL is not released while the device is borrowed (because C code could sneak in and mutate the device). We can then introduce custom interior mutability primitives that are semantically similar to the standard library's (single-threaded) Cell and RefCell, but account for QEMU's threading model. Accessing the "BqlCell" or borrowing the "BqlRefCell" requires proving that the BQL is held, and attempting to access without the BQL is a runtime panic, similar to RefCell's already-borrowed panic. With respect to naming I also considered omitting the "Bql" prefix or moving it to the module, e.g. qemu_api::bql::{Cell, RefCell}. However, this could easily lead to mistakes and confusion; for example rustc could suggest the wrong import, leading to subtle bugs. As a start introduce the an equivalent of Cell. Almost all of the code was taken from Rust's standard library, while removing unstable features and probably-unnecessary functionality that constitute a large of the original code. A lot of what's left is documentation, as well as unit tests in the form of doctests. These are not yet integrated in "make check" but can be run with "cargo test --doc". Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/cell.rs | 298 ++++++++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + 3 files changed, 300 insertions(+) create mode 100644 rust/qemu-api/src/cell.rs diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index d719c13f46d..edc21e1a3f8 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -13,6 +13,7 @@ _qemu_api_rs = static_library( [ 'src/lib.rs', 'src/bindings.rs', + 'src/cell.rs', 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs new file mode 100644 index 00000000000..2e4ea8d590d --- /dev/null +++ b/rust/qemu-api/src/cell.rs @@ -0,0 +1,298 @@ +// SPDX-License-Identifier: MIT +// +// This file is based on library/core/src/cell.rs from +// Rust 1.82.0. +// +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the +// Software without restriction, including without +// limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software +// is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions +// of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +//! BQL-protected mutable containers. +//! +//! Rust memory safety is based on this rule: Given an object `T`, it is only +//! possible to have one of the following: +//! +//! - Having several immutable references (`&T`) to the object (also known as +//! **aliasing**). +//! - Having one mutable reference (`&mut T`) to the object (also known as +//! **mutability**). +//! +//! This is enforced by the Rust compiler. However, there are situations where +//! this rule is not flexible enough. Sometimes it is required to have multiple +//! references to an object and yet mutate it. In particular, QEMU objects +//! usually have their pointer shared with the "outside world very early in +//! their lifetime", for example when they create their +//! [`MemoryRegion`s](crate::bindings::MemoryRegion). Therefore, individual +//! parts of a device must be made mutable in a controlled manner through the +//! use of cell types. +//! +//! This module provides a way to do so via the Big QEMU Lock. While +//! [`BqlCell`] is essentially the same single-threaded primitive that is +//! available in `std::cell`, the BQL allows it to be used from a multi-threaded +//! context and to share references across threads, while maintaining Rust's +//! safety guarantees. For this reason, unlike its `std::cell` counterpart, +//! `BqlCell` implements the `Sync` trait. +//! +//! BQL checks are performed in debug builds but can be optimized away in +//! release builds, providing runtime safety during development with no overhead +//! in production. +//! +//! Warning: While `BqlCell` is similar to its `std::cell` counterpart, the two +//! are not interchangeable. Using `std::cell` types in QEMU device +//! implementations is usually incorrect and can lead to thread-safety issues. +//! +//! ## `BqlCell` +//! +//! [`BqlCell`] implements interior mutability by moving values in and out of +//! the cell. That is, an `&mut T` to the inner value can never be obtained as +//! long as the cell is shared. The value itself cannot be directly obtained +//! without copying it, cloning it, or replacing it with something else. This +//! type provides the following methods, all of which can be called only while +//! the BQL is held: +//! +//! - For types that implement [`Copy`], the [`get`](BqlCell::get) method +//! retrieves the current interior value by duplicating it. +//! - For types that implement [`Default`], the [`take`](BqlCell::take) method +//! replaces the current interior value with [`Default::default()`] and +//! returns the replaced value. +//! - All types have: +//! - [`replace`](BqlCell::replace): replaces the current interior value and +//! returns the replaced value. +//! - [`set`](BqlCell::set): this method replaces the interior value, +//! dropping the replaced value. + +use std::{cell::UnsafeCell, cmp::Ordering, fmt, mem}; + +use crate::bindings; + +// TODO: When building doctests do not include the actual BQL, because cargo +// does not know how to link them to libqemuutil. This can be fixed by +// running rustdoc from "meson test" instead of relying on cargo. +pub fn bql_locked() -> bool { + // SAFETY: the function does nothing but return a thread-local bool + !cfg!(MESON) || unsafe { bindings::bql_locked() } +} + +/// A mutable memory location that is protected by the Big QEMU Lock. +/// +/// # Memory layout +/// +/// `BqlCell` has the same in-memory representation as its inner type `T`. +#[repr(transparent)] +pub struct BqlCell { + value: UnsafeCell, +} + +// SAFETY: Same as for std::sync::Mutex. In the end this *is* a Mutex, +// except it is stored out-of-line +unsafe impl Send for BqlCell {} +unsafe impl Sync for BqlCell {} + +impl Clone for BqlCell { + #[inline] + fn clone(&self) -> BqlCell { + BqlCell::new(self.get()) + } +} + +impl Default for BqlCell { + /// Creates a `BqlCell`, with the `Default` value for T. + #[inline] + fn default() -> BqlCell { + BqlCell::new(Default::default()) + } +} + +impl PartialEq for BqlCell { + #[inline] + fn eq(&self, other: &BqlCell) -> bool { + self.get() == other.get() + } +} + +impl Eq for BqlCell {} + +impl PartialOrd for BqlCell { + #[inline] + fn partial_cmp(&self, other: &BqlCell) -> Option { + self.get().partial_cmp(&other.get()) + } +} + +impl Ord for BqlCell { + #[inline] + fn cmp(&self, other: &BqlCell) -> Ordering { + self.get().cmp(&other.get()) + } +} + +impl From for BqlCell { + /// Creates a new `BqlCell` containing the given value. + fn from(t: T) -> BqlCell { + BqlCell::new(t) + } +} + +impl fmt::Debug for BqlCell { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.get().fmt(f) + } +} + +impl fmt::Display for BqlCell { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.get().fmt(f) + } +} + +impl BqlCell { + /// Creates a new `BqlCell` containing the given value. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// ``` + #[inline] + pub const fn new(value: T) -> BqlCell { + BqlCell { + value: UnsafeCell::new(value), + } + } + + /// Sets the contained value. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// + /// c.set(10); + /// ``` + #[inline] + pub fn set(&self, val: T) { + self.replace(val); + } + + /// Replaces the contained value with `val`, and returns the old contained + /// value. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let cell = BqlCell::new(5); + /// assert_eq!(cell.get(), 5); + /// assert_eq!(cell.replace(10), 5); + /// assert_eq!(cell.get(), 10); + /// ``` + #[inline] + pub fn replace(&self, val: T) -> T { + assert!(bql_locked()); + // SAFETY: This can cause data races if called from multiple threads, + // but it won't happen as long as C code accesses the value + // under BQL protection only. + mem::replace(unsafe { &mut *self.value.get() }, val) + } + + /// Unwraps the value, consuming the cell. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// let five = c.into_inner(); + /// + /// assert_eq!(five, 5); + /// ``` + pub fn into_inner(self) -> T { + assert!(bql_locked()); + self.value.into_inner() + } +} + +impl BqlCell { + /// Returns a copy of the contained value. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// + /// let five = c.get(); + /// ``` + #[inline] + pub fn get(&self) -> T { + assert!(bql_locked()); + // SAFETY: This can cause data races if called from multiple threads, + // but it won't happen as long as C code accesses the value + // under BQL protection only. + unsafe { *self.value.get() } + } +} + +impl BqlCell { + /// Returns a raw pointer to the underlying data in this cell. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// + /// let ptr = c.as_ptr(); + /// ``` + #[inline] + pub const fn as_ptr(&self) -> *mut T { + self.value.get() + } +} + +impl BqlCell { + /// Takes the value of the cell, leaving `Default::default()` in its place. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlCell; + /// + /// let c = BqlCell::new(5); + /// let five = c.take(); + /// + /// assert_eq!(five, 5); + /// assert_eq!(c.into_inner(), 0); + /// ``` + pub fn take(&self) -> T { + self.replace(Default::default()) + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 440aff3817d..b04d110b3f5 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -8,6 +8,7 @@ pub mod bindings; pub mod c_str; +pub mod cell; pub mod definitions; pub mod device_class; pub mod offset_of; From patchwork Wed Dec 11 16:27:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903856 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 A7786E7717D for ; Wed, 11 Dec 2024 16:37:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPa8-00024A-6V; Wed, 11 Dec 2024 11:29:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa3-0001bZ-TD for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa1-0000bt-3S for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wMF7KkhAi7BwGkG3WdZkbBzWjurjR2HS0qfiOPgjOHU=; b=DL3GOY7nWiJ9jZcDufYjxkPQI8kbrHwjTckFpxa95x/74BruRYmk+lLQABWxT8LaC+lDd4 Jb6FCAJkeovCBfSCf0+i2+n0MeWnX6KnhER1tLXVgfM8zSyAtylSJdJHzjaWncg2GquHEl HYRzmday29Qou/ulREiw3zNoo5bl6w0= 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-412-zZUbhn3MP_Oan17xUZErrg-1; Wed, 11 Dec 2024 11:28:51 -0500 X-MC-Unique: zZUbhn3MP_Oan17xUZErrg-1 X-Mimecast-MFC-AGG-ID: zZUbhn3MP_Oan17xUZErrg Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385dcae001fso379230f8f.1 for ; Wed, 11 Dec 2024 08:28:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934529; x=1734539329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wMF7KkhAi7BwGkG3WdZkbBzWjurjR2HS0qfiOPgjOHU=; b=UfrSRa9HAFVoHwY+rCB1rqMY+xOjTI33CaMTNvJ4/sIt4r3Bg+mvGpzUlv0XzSi35c Zz6XxzXFfSBY1uqDlRqUNPLh/r2gj8cgImZ7ARyut/MJCp9C4mL5YOzLOQ73x0HKJ/+k /4jvgaBOO3mDx3hWt4/P4kwT/9Qg1c/wLrI2MucAN6NnHB25LU2HmgbMMgYGe8O7+6YI GRQiWVVVavfzb5mallb+KuYgdB/PN5p7yZBTwLTOC7ckegPvAXy2VwBuerMGUZgZAfOn Ub0zfec7ek4i9rNb1KLzgPOXWlOV13wph1Y2SMt7goouzvMAOSDdU2g5yl5yCH4H4P3b ISVw== X-Gm-Message-State: AOJu0YzagkxFrchcgnFjqbHPwrSZ/iVCtC5S9sqqCU3vTerZbRODGHEk eBUwmzz35tmbCNCOeXfywDiRYMlE0HQGwL85xpg/QThBt2dmQpC2AUnzylJwZJtR9MrqQ0tphTD 7ZKaOsDSR9bPioCMRUQW5Zp/nazQFx/rhmF9wHO6wCmb4pJt8fZRBTM+l8iSWkSv9vwTjT/QYMw jSPU5LP0HD2jPQqGfHWUxf+ZpuedFMUwRUSPax X-Gm-Gg: ASbGncvXRZKgXoI27vOdNdB441qasNmOldkE8kl9SMLu5Go3Ijd3rrmKemMOZeMnktw yGapzgHoTxOuFccIhJeLkDXIGmP+WM2/8k02jDs2k83CdBaL7snYaj+LQUfc0AbTgYuSlg4/ZGU HrLNSw5i/z+YRJh4jdE7zRz5xQHi1XpiYhgAePbBlYd7eQPi1ojuhzdVrUKnDmV/WqUNs7QV5nP CHTywqR0HR27wGFuYWn/dOcYC1Sv7mHXz/NlgAQkdtyYWRm0u+SUgBG X-Received: by 2002:a5d:64cf:0:b0:385:fb56:fb73 with SMTP id ffacd0b85a97d-3864ce9710dmr2889289f8f.15.1733934528969; Wed, 11 Dec 2024 08:28:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeEFH4X9xejq6i7rsQZVxT02tP0d6DDvZKBzsqtTXvvct/zg8FNgfb6rms2ODN7ntxIQsb6g== X-Received: by 2002:a5d:64cf:0:b0:385:fb56:fb73 with SMTP id ffacd0b85a97d-3864ce9710dmr2889248f8f.15.1733934528053; Wed, 11 Dec 2024 08:28:48 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248e57fsm1666207f8f.8.2024.12.11.08.28.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 37/49] rust: cell: add BQL-enforcing RefCell variant Date: Wed, 11 Dec 2024 17:27:07 +0100 Message-ID: <20241211162720.320070-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Similar to the existing BqlCell, introduce a custom interior mutability primitive that resembles RefCell but accounts for QEMU's threading model. Borrowing the RefCell requires proving that the BQL is held, and attempting to access without the BQL is a runtime panic. Almost all of the code was taken from Rust's standard library, while removing unstable features and probably-unnecessary functionality that amounts to 60% of the original code. A lot of what's left is documentation, as well as unit tests in the form of doctests. These are not yet integrated in "make check" but can be run with "cargo test --doc". Signed-off-by: Paolo Bonzini --- rust/qemu-api/Cargo.toml | 3 +- rust/qemu-api/meson.build | 3 + rust/qemu-api/src/cell.rs | 544 +++++++++++++++++++++++++++++++++++++- 3 files changed, 539 insertions(+), 11 deletions(-) diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 669f288d1cb..4aa22f31986 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -20,8 +20,9 @@ qemu_api_macros = { path = "../qemu-api-macros" } version_check = "~0.9" [features] -default = [] +default = ["debug_cell"] allocator = [] +debug_cell = [] [lints] workspace = true diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index edc21e1a3f8..cacb112c5c3 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -6,6 +6,9 @@ _qemu_api_cfg = run_command(rustc_args, if rustc.version().version_compare('>=1.77.0') _qemu_api_cfg += ['--cfg', 'has_offset_of'] endif +if get_option('debug_mutex') + _qemu_api_cfg += ['--feature', 'debug_cell'] +endif _qemu_api_rs = static_library( 'qemu_api', diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs index 2e4ea8d590d..28349de291a 100644 --- a/rust/qemu-api/src/cell.rs +++ b/rust/qemu-api/src/cell.rs @@ -46,20 +46,30 @@ //! parts of a device must be made mutable in a controlled manner through the //! use of cell types. //! -//! This module provides a way to do so via the Big QEMU Lock. While -//! [`BqlCell`] is essentially the same single-threaded primitive that is -//! available in `std::cell`, the BQL allows it to be used from a multi-threaded -//! context and to share references across threads, while maintaining Rust's -//! safety guarantees. For this reason, unlike its `std::cell` counterpart, -//! `BqlCell` implements the `Sync` trait. +//! [`BqlCell`] and [`BqlRefCell`] allow doing this via the Big QEMU Lock. +//! While they are essentially the same single-threaded primitives that are +//! available in `std::cell`, the BQL allows them to be used from a +//! multi-threaded context and to share references across threads, while +//! maintaining Rust's safety guarantees. For this reason, unlike +//! their `std::cell` counterparts, `BqlCell` and `BqlRefCell` implement the +//! `Sync` trait. //! //! BQL checks are performed in debug builds but can be optimized away in //! release builds, providing runtime safety during development with no overhead //! in production. //! -//! Warning: While `BqlCell` is similar to its `std::cell` counterpart, the two -//! are not interchangeable. Using `std::cell` types in QEMU device -//! implementations is usually incorrect and can lead to thread-safety issues. +//! The two provide different ways of handling interior mutability. +//! `BqlRefCell` is best suited for data that is primarily accessed by the +//! device's own methods, where multiple reads and writes can be grouped within +//! a single borrow and a mutable reference can be passed around. Instead, +//! [`BqlCell`] is a better choice when sharing small pieces of data with +//! external code (especially C code), because it provides simple get/set +//! operations that can be used one at a time. +//! +//! Warning: While `BqlCell` and `BqlRefCell` are similar to their `std::cell` +//! counterparts, they are not interchangeable. Using `std::cell` types in +//! QEMU device implementations is usually incorrect and can lead to +//! thread-safety issues. //! //! ## `BqlCell` //! @@ -80,8 +90,37 @@ //! returns the replaced value. //! - [`set`](BqlCell::set): this method replaces the interior value, //! dropping the replaced value. +//! +//! ## `BqlRefCell` +//! +//! [`BqlRefCell`] uses Rust's lifetimes to implement "dynamic borrowing", a +//! process whereby one can claim temporary, exclusive, mutable access to the +//! inner value: +//! +//! ```ignore +//! fn clear_interrupts(&self, val: u32) { +//! // A mutable borrow gives read-write access to the registers +//! let mut regs = self.registers.borrow_mut(); +//! let old = regs.interrupt_status(); +//! regs.update_interrupt_status(old & !val); +//! } +//! ``` +//! +//! Borrows for `BqlRefCell`s are tracked at _runtime_, unlike Rust's native +//! reference types which are entirely tracked statically, at compile time. +//! Multiple immutable borrows are allowed via [`borrow`](BqlRefCell::borrow), +//! or a single mutable borrow via [`borrow_mut`](BqlRefCell::borrow_mut). The +//! thread will panic if these rules are violated or if the BQL is not held. -use std::{cell::UnsafeCell, cmp::Ordering, fmt, mem}; +use std::{ + cell::{Cell, UnsafeCell}, + cmp::Ordering, + fmt, + marker::PhantomData, + mem, + ops::{Deref, DerefMut}, + ptr::NonNull, +}; use crate::bindings; @@ -93,6 +132,15 @@ pub fn bql_locked() -> bool { !cfg!(MESON) || unsafe { bindings::bql_locked() } } +fn bql_block_unlock(increase: bool) { + if cfg!(MESON) { + // SAFETY: this only adjusts a counter + unsafe { + bindings::bql_block_unlock(increase); + } + } +} + /// A mutable memory location that is protected by the Big QEMU Lock. /// /// # Memory layout @@ -296,3 +344,479 @@ pub fn take(&self) -> T { self.replace(Default::default()) } } + +/// A mutable memory location with dynamically checked borrow rules, +/// protected by the Big QEMU Lock. +/// +/// See the [module-level documentation](self) for more. +/// +/// # Memory layout +/// +/// `BqlRefCell` starts with the same in-memory representation as its +/// inner type `T`. +#[repr(C)] +pub struct BqlRefCell { + // It is important that this is the first field (which is not the case + // for std::cell::BqlRefCell), so that we can use offset_of! on it. + // UnsafeCell and repr(C) both prevent usage of niches. + value: UnsafeCell, + borrow: Cell, + // Stores the location of the earliest currently active borrow. + // This gets updated whenever we go from having zero borrows + // to having a single borrow. When a borrow occurs, this gets included + // in the panic message + #[cfg(feature = "debug_cell")] + borrowed_at: Cell>>, +} + +// Positive values represent the number of `BqlRef` active. Negative values +// represent the number of `BqlRefMut` active. Right now QEMU's implementation +// does not allow to create `BqlRefMut`s that refer to distinct, nonoverlapping +// components of a `BqlRefCell` (e.g., different ranges of a slice). +// +// `BqlRef` and `BqlRefMut` are both two words in size, and so there will likely +// never be enough `BqlRef`s or `BqlRefMut`s in existence to overflow half of +// the `usize` range. Thus, a `BorrowFlag` will probably never overflow or +// underflow. However, this is not a guarantee, as a pathological program could +// repeatedly create and then mem::forget `BqlRef`s or `BqlRefMut`s. Thus, all +// code must explicitly check for overflow and underflow in order to avoid +// unsafety, or at least behave correctly in the event that overflow or +// underflow happens (e.g., see BorrowRef::new). +type BorrowFlag = isize; +const UNUSED: BorrowFlag = 0; + +#[inline(always)] +const fn is_writing(x: BorrowFlag) -> bool { + x < UNUSED +} + +#[inline(always)] +const fn is_reading(x: BorrowFlag) -> bool { + x > UNUSED +} + +impl BqlRefCell { + /// Creates a new `BqlRefCell` containing `value`. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new(5); + /// ``` + #[inline] + pub const fn new(value: T) -> BqlRefCell { + BqlRefCell { + value: UnsafeCell::new(value), + borrow: Cell::new(UNUSED), + #[cfg(feature = "debug_cell")] + borrowed_at: Cell::new(None), + } + } +} + +// This ensures the panicking code is outlined from `borrow_mut` for +// `BqlRefCell`. +#[inline(never)] +#[cold] +#[cfg(feature = "debug_cell")] +fn panic_already_borrowed(source: &Cell>>) -> ! { + // If a borrow occurred, then we must already have an outstanding borrow, + // so `borrowed_at` will be `Some` + panic!("already borrowed at {:?}", source.take().unwrap()) +} + +#[inline(never)] +#[cold] +#[cfg(not(feature = "debug_cell"))] +fn panic_already_borrowed() -> ! { + panic!("already borrowed") +} + +impl BqlRefCell { + #[inline] + #[allow(clippy::unused_self)] + fn panic_already_borrowed(&self) -> ! { + #[cfg(feature = "debug_cell")] + { + panic_already_borrowed(&self.borrowed_at) + } + #[cfg(not(feature = "debug_cell"))] + { + panic_already_borrowed() + } + } + + /// Immutably borrows the wrapped value. + /// + /// The borrow lasts until the returned `BqlRef` exits scope. Multiple + /// immutable borrows can be taken out at the same time. + /// + /// # Panics + /// + /// Panics if the value is currently mutably borrowed. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new(5); + /// + /// let borrowed_five = c.borrow(); + /// let borrowed_five2 = c.borrow(); + /// ``` + /// + /// An example of panic: + /// + /// ```should_panic + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new(5); + /// + /// let m = c.borrow_mut(); + /// let b = c.borrow(); // this causes a panic + /// ``` + #[inline] + #[track_caller] + pub fn borrow(&self) -> BqlRef<'_, T> { + if let Some(b) = BorrowRef::new(&self.borrow) { + // `borrowed_at` is always the *first* active borrow + if b.borrow.get() == 1 { + #[cfg(feature = "debug_cell")] + self.borrowed_at.set(Some(std::panic::Location::caller())); + } + + bql_block_unlock(true); + + // SAFETY: `BorrowRef` ensures that there is only immutable access + // to the value while borrowed. + let value = unsafe { NonNull::new_unchecked(self.value.get()) }; + BqlRef { value, borrow: b } + } else { + self.panic_already_borrowed() + } + } + + /// Mutably borrows the wrapped value. + /// + /// The borrow lasts until the returned `BqlRefMut` or all `BqlRefMut`s + /// derived from it exit scope. The value cannot be borrowed while this + /// borrow is active. + /// + /// # Panics + /// + /// Panics if the value is currently borrowed. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new("hello".to_owned()); + /// + /// *c.borrow_mut() = "bonjour".to_owned(); + /// + /// assert_eq!(&*c.borrow(), "bonjour"); + /// ``` + /// + /// An example of panic: + /// + /// ```should_panic + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new(5); + /// let m = c.borrow(); + /// + /// let b = c.borrow_mut(); // this causes a panic + /// ``` + #[inline] + #[track_caller] + pub fn borrow_mut(&self) -> BqlRefMut<'_, T> { + if let Some(b) = BorrowRefMut::new(&self.borrow) { + #[cfg(feature = "debug_cell")] + { + self.borrowed_at.set(Some(std::panic::Location::caller())); + } + + // SAFETY: this only adjusts a counter + bql_block_unlock(true); + + // SAFETY: `BorrowRefMut` guarantees unique access. + let value = unsafe { NonNull::new_unchecked(self.value.get()) }; + BqlRefMut { + value, + _borrow: b, + marker: PhantomData, + } + } else { + self.panic_already_borrowed() + } + } + + /// Returns a raw pointer to the underlying data in this cell. + /// + /// # Examples + /// + /// ``` + /// use qemu_api::cell::BqlRefCell; + /// + /// let c = BqlRefCell::new(5); + /// + /// let ptr = c.as_ptr(); + /// ``` + #[inline] + pub const fn as_ptr(&self) -> *mut T { + self.value.get() + } +} + +// SAFETY: Same as for std::sync::Mutex. In the end this is a Mutex that is +// stored out-of-line. Even though BqlRefCell includes Cells, they are +// themselves protected by the Big QEMU Lock. Furtheremore, the Big QEMU +// Lock cannot be released while any borrows is active. +unsafe impl Send for BqlRefCell where T: Send {} +unsafe impl Sync for BqlRefCell {} + +impl Clone for BqlRefCell { + /// # Panics + /// + /// Panics if the value is currently mutably borrowed. + #[inline] + #[track_caller] + fn clone(&self) -> BqlRefCell { + BqlRefCell::new(self.borrow().clone()) + } + + /// # Panics + /// + /// Panics if `source` is currently mutably borrowed. + #[inline] + #[track_caller] + fn clone_from(&mut self, source: &Self) { + self.value.get_mut().clone_from(&source.borrow()) + } +} + +impl Default for BqlRefCell { + /// Creates a `BqlRefCell`, with the `Default` value for T. + #[inline] + fn default() -> BqlRefCell { + BqlRefCell::new(Default::default()) + } +} + +impl PartialEq for BqlRefCell { + /// # Panics + /// + /// Panics if the value in either `BqlRefCell` is currently mutably + /// borrowed. + #[inline] + fn eq(&self, other: &BqlRefCell) -> bool { + *self.borrow() == *other.borrow() + } +} + +impl Eq for BqlRefCell {} + +impl PartialOrd for BqlRefCell { + /// # Panics + /// + /// Panics if the value in either `BqlRefCell` is currently mutably + /// borrowed. + #[inline] + fn partial_cmp(&self, other: &BqlRefCell) -> Option { + self.borrow().partial_cmp(&*other.borrow()) + } +} + +impl Ord for BqlRefCell { + /// # Panics + /// + /// Panics if the value in either `BqlRefCell` is currently mutably + /// borrowed. + #[inline] + fn cmp(&self, other: &BqlRefCell) -> Ordering { + self.borrow().cmp(&*other.borrow()) + } +} + +impl From for BqlRefCell { + /// Creates a new `BqlRefCell` containing the given value. + fn from(t: T) -> BqlRefCell { + BqlRefCell::new(t) + } +} + +struct BorrowRef<'b> { + borrow: &'b Cell, +} + +impl<'b> BorrowRef<'b> { + #[inline] + fn new(borrow: &'b Cell) -> Option> { + let b = borrow.get().wrapping_add(1); + if !is_reading(b) { + // Incrementing borrow can result in a non-reading value (<= 0) in these cases: + // 1. It was < 0, i.e. there are writing borrows, so we can't allow a read + // borrow due to Rust's reference aliasing rules + // 2. It was isize::MAX (the max amount of reading borrows) and it overflowed + // into isize::MIN (the max amount of writing borrows) so we can't allow an + // additional read borrow because isize can't represent so many read borrows + // (this can only happen if you mem::forget more than a small constant amount + // of `BqlRef`s, which is not good practice) + None + } else { + // Incrementing borrow can result in a reading value (> 0) in these cases: + // 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read + // borrow + // 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize is + // large enough to represent having one more read borrow + borrow.set(b); + Some(BorrowRef { borrow }) + } + } +} + +impl Drop for BorrowRef<'_> { + #[inline] + fn drop(&mut self) { + let borrow = self.borrow.get(); + debug_assert!(is_reading(borrow)); + self.borrow.set(borrow - 1); + bql_block_unlock(false) + } +} + +impl Clone for BorrowRef<'_> { + #[inline] + fn clone(&self) -> Self { + BorrowRef::new(self.borrow).unwrap() + } +} + +/// Wraps a borrowed reference to a value in a `BqlRefCell` box. +/// A wrapper type for an immutably borrowed value from a `BqlRefCell`. +/// +/// See the [module-level documentation](self) for more. +pub struct BqlRef<'b, T: 'b> { + // NB: we use a pointer instead of `&'b T` to avoid `noalias` violations, because a + // `BqlRef` argument doesn't hold immutability for its whole scope, only until it drops. + // `NonNull` is also covariant over `T`, just like we would have with `&T`. + value: NonNull, + borrow: BorrowRef<'b>, +} + +impl Deref for BqlRef<'_, T> { + type Target = T; + + #[inline] + fn deref(&self) -> &T { + // SAFETY: the value is accessible as long as we hold our borrow. + unsafe { self.value.as_ref() } + } +} + +impl<'b, T> BqlRef<'b, T> { + /// Copies a `BqlRef`. + /// + /// The `BqlRefCell` is already immutably borrowed, so this cannot fail. + /// + /// This is an associated function that needs to be used as + /// `BqlRef::clone(...)`. A `Clone` implementation or a method would + /// interfere with the widespread use of `r.borrow().clone()` to clone + /// the contents of a `BqlRefCell`. + #[must_use] + #[inline] + #[allow(clippy::should_implement_trait)] + pub fn clone(orig: &BqlRef<'b, T>) -> BqlRef<'b, T> { + BqlRef { + value: orig.value, + borrow: orig.borrow.clone(), + } + } +} + +impl fmt::Debug for BqlRef<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (**self).fmt(f) + } +} + +impl fmt::Display for BqlRef<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (**self).fmt(f) + } +} + +struct BorrowRefMut<'b> { + borrow: &'b Cell, +} + +impl<'b> BorrowRefMut<'b> { + #[inline] + fn new(borrow: &'b Cell) -> Option> { + // There must currently be no existing references when borrow_mut() is + // called, so we explicitly only allow going from UNUSED to UNUSED - 1. + match borrow.get() { + UNUSED => { + borrow.set(UNUSED - 1); + Some(BorrowRefMut { borrow }) + } + _ => None, + } + } +} + +impl Drop for BorrowRefMut<'_> { + #[inline] + fn drop(&mut self) { + let borrow = self.borrow.get(); + debug_assert!(is_writing(borrow)); + self.borrow.set(borrow + 1); + bql_block_unlock(false) + } +} + +/// A wrapper type for a mutably borrowed value from a `BqlRefCell`. +/// +/// See the [module-level documentation](self) for more. +pub struct BqlRefMut<'b, T: 'b> { + // NB: we use a pointer instead of `&'b mut T` to avoid `noalias` violations, because a + // `BqlRefMut` argument doesn't hold exclusivity for its whole scope, only until it drops. + value: NonNull, + _borrow: BorrowRefMut<'b>, + // `NonNull` is covariant over `T`, so we need to reintroduce invariance. + marker: PhantomData<&'b mut T>, +} + +impl Deref for BqlRefMut<'_, T> { + type Target = T; + + #[inline] + fn deref(&self) -> &T { + // SAFETY: the value is accessible as long as we hold our borrow. + unsafe { self.value.as_ref() } + } +} + +impl DerefMut for BqlRefMut<'_, T> { + #[inline] + fn deref_mut(&mut self) -> &mut T { + // SAFETY: the value is accessible as long as we hold our borrow. + unsafe { self.value.as_mut() } + } +} + +impl fmt::Debug for BqlRefMut<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (**self).fmt(f) + } +} + +impl fmt::Display for BqlRefMut<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (**self).fmt(f) + } +} From patchwork Wed Dec 11 16:27:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903910 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 34DFAE77180 for ; Wed, 11 Dec 2024 16:44:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPa5-0001il-Cs; Wed, 11 Dec 2024 11:28:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa3-0001X6-Ee for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa1-0000c1-MX for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OshVopfsDLXhXQaf0FN9QUClgxDd1xn/z3ig2ZaD5Nc=; b=hTKXOx48nkQJ+BRjx+QacagfIU/0jl0m+NsikSz86wGMUw+Xej523O8fYgFI/50CM4eKBA xhiWx1Yx8d3gpxQd8QV5YPZ27GLF6uK38uAqZLupxSvwFJvmOObf54NgciVCzdcoVut1xC zU4uM7URAeJKOpB4PBoc0jxwZOIPImU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-f3cQVFXYNnKhtzCl1FwSmA-1; Wed, 11 Dec 2024 11:28:52 -0500 X-MC-Unique: f3cQVFXYNnKhtzCl1FwSmA-1 X-Mimecast-MFC-AGG-ID: f3cQVFXYNnKhtzCl1FwSmA Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385df115288so2972562f8f.2 for ; Wed, 11 Dec 2024 08:28:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934530; x=1734539330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OshVopfsDLXhXQaf0FN9QUClgxDd1xn/z3ig2ZaD5Nc=; b=nwdf6ZV4MpvGrP+6lg1VyVNVz4eNkqbFfib/SeF3Mzrpbs5A+RsE3Nmrt/hldHHdWi qehxjbfC8rBsrAcGKgK4MacqEXdEjWGJYXKadGbaM7kEfbSPDuWuwsQIDjr2a3bxN/kT 2/s0aPwOwJ+FM8YNLMk5R9v7oPKvYGbMcEfxDXx6azyNrmnKnSt8hxy2ZRlIQY8XpQNW QNMSFpyRgGyfenoQZ5R2wkZ4SBa3+mDQafUdRuxYx+EjVzLzxVc6zHWxoD71Tp3m4Hav VgFlQADBDdj5EU7FVeGRHmxUWCmV87N2Rs3kfQOh1dIUfirL15qqtmdWepGDa0UZ4DX+ 5YDw== X-Gm-Message-State: AOJu0YyTs2DNqbjNIrreDqIM5+vakwJJ67+4LCCW9mqn+j5j7NP6zQLa qA8pmER3T7YioIwL8eR34ARhIAvXdFPEJBCQ60GaG3y+NTZ8cs6jqw1vw4r5yOBBo6tBAlQqZQI 4HVL1/U74Hff4SDbfQZe05d9KqzzbOPC/jrlhWBBvVTGfs/YMMFfO4U9eY2bk7quiyNsNMfq6o9 YFPr1WVANog5FRTvOdw5tWaUEPDhrSHEBXIdxt X-Gm-Gg: ASbGnctuLEtBrEPb4v6wcxWn+iALnZoAsYq35LJC/BEuRCL6cn3OxlL5ClAowO+YGr4 2/AYKOpL1QA9GFiIBfMc4fHBUm8xDhj+C598wsoqyyOTQNOKTMpsUbs+37rlglqpv7tPCajuuSx Nusa8x8uLKLuNCFTBT4XjZwFI9pM51RH9fC2bZWykqtxRAYffnJ9Plu2IY+gti7uN06DR3aYVZ5 yMFoQrrnMlkrnyu9ewqa5mkcbiBsCk5z5AI4zHJcr/lDX4iRP/PRo83 X-Received: by 2002:a5d:5f4f:0:b0:386:1cf9:b993 with SMTP id ffacd0b85a97d-3864ce5c698mr3221018f8f.26.1733934530361; Wed, 11 Dec 2024 08:28:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm5M7JM3EqpjlRcvk5Z1HQHInM2LjSBNDpmIUu89JtJkyk9MhoHQXCm7zJk47IxTPJLXLvnw== X-Received: by 2002:a5d:5f4f:0:b0:386:1cf9:b993 with SMTP id ffacd0b85a97d-3864ce5c698mr3220990f8f.26.1733934529881; Wed, 11 Dec 2024 08:28:49 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38782514dc3sm1605176f8f.67.2024.12.11.08.28.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 38/49] rust: define prelude Date: Wed, 11 Dec 2024 17:27:08 +0100 Message-ID: <20241211162720.320070-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Add a module that will contain frequently used traits and occasionally structs. They can be included quickly with "use qemu_api::prelude::*". Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/lib.rs | 5 +++++ rust/qemu-api/src/prelude.rs | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 rust/qemu-api/src/prelude.rs diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index cacb112c5c3..f8b4cd39a26 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -21,6 +21,7 @@ _qemu_api_rs = static_library( 'src/definitions.rs', 'src/device_class.rs', 'src/offset_of.rs', + 'src/prelude.rs', 'src/vmstate.rs', 'src/zeroable.rs', ], diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index b04d110b3f5..e5956cd5eb6 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -7,6 +7,11 @@ #[rustfmt::skip] pub mod bindings; +// preserve one-item-per-"use" syntax, it is clearer +// for prelude-like modules +#[rustfmt::skip] +pub mod prelude; + pub mod c_str; pub mod cell; pub mod definitions; diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs new file mode 100644 index 00000000000..dfaddbd062a --- /dev/null +++ b/rust/qemu-api/src/prelude.rs @@ -0,0 +1,6 @@ +// Copyright 2024 Red Hat, Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +pub use crate::cell::BqlCell; +pub use crate::cell::BqlRefCell; From patchwork Wed Dec 11 16:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903818 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 50877E77182 for ; Wed, 11 Dec 2024 16:29:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaA-0002FW-NW; Wed, 11 Dec 2024 11:29:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPa5-0001lO-SH for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:57 -0500 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 1tLPa3-0000cO-VG for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:28:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kMi4xnuVX8OtBt4NvX2Y5ZrPSheVzAeHna9cNK+HRcg=; b=M0Bu97RB/WOBZ6KEM8Onc1uHs3PMGoKpuoU+ONAo7PBI50EyxXJsNizhUEEUoAFsFjfIaR bEp5mPpH3350JzFkFXHQvQSuFSWLd8MwhJFIAMQVZbDvv1mPGtHecSsgKlbEWfaz5dxwea cKqe/uns6MkzY1vTruQGaXjkrbk6cMw= 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-561-GQNWtzraMF-eMitTI3qdzA-1; Wed, 11 Dec 2024 11:28:54 -0500 X-MC-Unique: GQNWtzraMF-eMitTI3qdzA-1 X-Mimecast-MFC-AGG-ID: GQNWtzraMF-eMitTI3qdzA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-434fa6d522bso5264545e9.1 for ; Wed, 11 Dec 2024 08:28:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934532; x=1734539332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kMi4xnuVX8OtBt4NvX2Y5ZrPSheVzAeHna9cNK+HRcg=; b=gadU/An5Niae7hBilLf68uGS1DKV3COjiUCAu3krdXgwyK+WZxKrZ8OFiRSq86ziwF yLxBm29jDs0Mh47wn0NEjpaCbOpS/JW9NplxYbNPQ5glEmgyDmR3lqY6jNZg8cNjPgII pfmg9bZb1Tr1qDo27ChK46SqTXiLwl6FhGGwSInqfjD60FetNtius4FscxpaBOjHZbd1 AE/VOHSJov/9aDgIkxMSW5aDyiCN+CnM0UoaA4Sx6hfvoM/fP/QQvDphihyT0RiyF00+ Il5VwbEh3mvO/tvxTH0Lih+j4BZG7CgtnmLkgnsDmmzanQxQpIqP9DRroLk0Sm5pvg/8 727w== X-Gm-Message-State: AOJu0YzbnieeQUfV5lW4wGjTLLu9hk2XPWXGvCqC5BAJeyjFx7AZKL3C rEbdYPJf0oKNooJmaXJg9uy8W9E052Nx0nF5VhFhTzFQMIe51h/IlFMh5AKCcns0G5tY4ho0qyC 8LGwWe0P4WAJbqHDSi0JYzGSXvzlLWGp+hVh7SZ7xIQCWK+EBnATgrm1zFc6lLTyOq9vgDGnAAU 1W6jkh+Jthq0Bk2lWOHeft3GmYlBi9k/yPJZLY X-Gm-Gg: ASbGncvwa5kAS8XQlQ1EWghxo23nDl/StbErWABjx1ekGv0eTHfguC6WfPAbFFEe+jD 5aKcABm6L/N7ejs24pMRqf72TC1qSJt4SOWcbZ2h2YqZqcZrDC91C4X8snkIY5pNw6r8BEPb/Z4 BAt+agDWtGwyhioaxAXxL1Y0wp1PFoTPM+a5nHsVqvaECK3VEdq1ZczbpU0uDHFjamhf5jEhUGo TQklKoXfS4I1wgRFAnOqG8oYkGl/Ur2ofgrt+yL25ET4mzj7LXI5a6E X-Received: by 2002:a05:600c:68c9:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-4361c58f6f3mr23696085e9.2.1733934532507; Wed, 11 Dec 2024 08:28:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSW2LWG3qEqm7LQhOVVrOS4B2OOExxtfGP4i6Ap5fXSgMXPjCKKQKL8xqzg8euuc7DT5BSoQ== X-Received: by 2002:a05:600c:68c9:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-4361c58f6f3mr23695845e9.2.1733934531944; Wed, 11 Dec 2024 08:28:51 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-435aab63baesm53855385e9.38.2024.12.11.08.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 39/49] rust: add bindings for interrupt sources Date: Wed, 11 Dec 2024 17:27:09 +0100 Message-ID: <20241211162720.320070-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 The InterruptSource bindings let us call qemu_set_irq() and sysbus_init_irq() as safe code. Interrupt sources, qemu_irq in C code, are pointers to IRQState objects. They are QOM link properties and can be written to outside the control of the device (i.e. from a shared reference); therefore they must be interior-mutable in Rust. Since thread-safety is provided by the BQL, what we want here is the newly-introduced BqlCell. A pointer to the contents of the BqlCell (an IRQState**, or equivalently qemu_irq*) is then passed to the C sysbus_init_irq function. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 22 ++++---- rust/qemu-api/meson.build | 2 + rust/qemu-api/src/irq.rs | 91 ++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 2 + rust/qemu-api/src/sysbus.rs | 27 ++++++++++ 5 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 rust/qemu-api/src/irq.rs create mode 100644 rust/qemu-api/src/sysbus.rs diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 317a9b3c5ad..c5c8c463d37 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -13,6 +13,7 @@ c_str, definitions::ObjectImpl, device_class::TYPE_SYS_BUS_DEVICE, + irq::InterruptSource, }; use crate::{ @@ -94,7 +95,7 @@ pub struct PL011State { /// * sysbus IRQ 5: `UARTEINTR` (error interrupt line) /// ``` #[doc(alias = "irq")] - pub interrupts: [qemu_irq; 6usize], + pub interrupts: [InterruptSource; IRQMASK.len()], #[doc(alias = "clk")] pub clock: NonNull, #[doc(alias = "migrate_clk")] @@ -139,7 +140,8 @@ impl PL011State { unsafe fn init(&mut self) { const CLK_NAME: &CStr = c_str!("clk"); - let dev = addr_of_mut!(*self).cast::(); + let sbd = unsafe { &mut *(addr_of_mut!(*self).cast::()) }; + // SAFETY: // // self and self.iomem are guaranteed to be valid at this point since callers @@ -153,12 +155,15 @@ unsafe fn init(&mut self) { Self::TYPE_INFO.name, 0x1000, ); - let sbd = addr_of_mut!(*self).cast::(); sysbus_init_mmio(sbd, addr_of_mut!(self.iomem)); - for irq in self.interrupts.iter_mut() { - sysbus_init_irq(sbd, irq); - } } + + for irq in self.interrupts.iter() { + sbd.init_irq(irq); + } + + let dev = addr_of_mut!(*self).cast::(); + // SAFETY: // // self.clock is not initialized at this point; but since `NonNull<_>` is Copy, @@ -498,10 +503,7 @@ pub fn put_fifo(&mut self, value: c_uint) { pub fn update(&self) { let flags = self.int_level & self.int_enabled; for (irq, i) in self.interrupts.iter().zip(IRQMASK) { - // SAFETY: self.interrupts have been initialized in init(). - unsafe { - qemu_set_irq(*irq, i32::from(flags & i != 0)); - } + irq.set(flags & i != 0); } } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index f8b4cd39a26..b927eb58c8e 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -20,8 +20,10 @@ _qemu_api_rs = static_library( 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/irq.rs', 'src/offset_of.rs', 'src/prelude.rs', + 'src/sysbus.rs', 'src/vmstate.rs', 'src/zeroable.rs', ], diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs new file mode 100644 index 00000000000..6258141bdf0 --- /dev/null +++ b/rust/qemu-api/src/irq.rs @@ -0,0 +1,91 @@ +// Copyright 2024 Red Hat, Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Bindings for interrupt sources + +use core::ptr; +use std::{marker::PhantomData, os::raw::c_int}; + +use crate::{ + bindings::{qemu_set_irq, IRQState}, + prelude::*, +}; + +/// Interrupt sources are used by devices to pass changes to a value (typically +/// a boolean). The interrupt sink is usually an interrupt controller or +/// GPIO controller. +/// +/// As far as devices are concerned, interrupt sources are always active-high: +/// for example, `InterruptSource`'s [`raise`](InterruptSource::raise) +/// method sends a `true` value to the sink. If the guest has to see a +/// different polarity, that change is performed by the board between the +/// device and the interrupt controller. +/// +/// Interrupts are implemented as a pointer to the interrupt "sink", which has +/// type [`IRQState`]. A device exposes its source as a QOM link property using +/// a function such as +/// [`SysBusDevice::init_irq`](crate::sysbus::SysBusDevice::init_irq), and +/// initially leaves the pointer to a NULL value, representing an unconnected +/// interrupt. To connect it, whoever creates the device fills the pointer with +/// the sink's `IRQState *`, for example using `sysbus_connect_irq`. Because +/// devices are generally shared objects, interrupt sources are an example of +/// the interior mutability pattern. +/// +/// Interrupt sources can only be triggered under the Big QEMU Lock; `BqlCell` +/// allows access from whatever thread has it. +#[derive(Debug)] +#[repr(transparent)] +pub struct InterruptSource +where + c_int: From, +{ + cell: BqlCell<*mut IRQState>, + _marker: PhantomData, +} + +impl InterruptSource { + /// Send a low (`false`) value to the interrupt sink. + pub fn lower(&self) { + self.set(false); + } + + /// Send a high-low pulse to the interrupt sink. + pub fn pulse(&self) { + self.set(true); + self.set(false); + } + + /// Send a high (`true`) value to the interrupt sink. + pub fn raise(&self) { + self.set(true); + } +} + +impl InterruptSource +where + c_int: From, +{ + /// Send `level` to the interrupt sink. + pub fn set(&self, level: T) { + let ptr = self.cell.get(); + // SAFETY: the pointer is retrieved under the BQL and remains valid + // until the BQL is released, which is after qemu_set_irq() is entered. + unsafe { + qemu_set_irq(ptr, level.into()); + } + } + + pub(crate) const fn as_ptr(&self) -> *mut *mut IRQState { + self.cell.as_ptr() + } +} + +impl Default for InterruptSource { + fn default() -> Self { + InterruptSource { + cell: BqlCell::new(ptr::null_mut()), + _marker: PhantomData, + } + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e5956cd5eb6..0efbef47441 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -16,7 +16,9 @@ pub mod cell; pub mod definitions; pub mod device_class; +pub mod irq; pub mod offset_of; +pub mod sysbus; pub mod vmstate; pub mod zeroable; diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs new file mode 100644 index 00000000000..4e192c75898 --- /dev/null +++ b/rust/qemu-api/src/sysbus.rs @@ -0,0 +1,27 @@ +// Copyright 2024 Red Hat, Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +use std::ptr::addr_of; + +pub use bindings::{SysBusDevice, SysBusDeviceClass}; + +use crate::{bindings, cell::bql_locked, irq::InterruptSource}; + +impl SysBusDevice { + /// Return `self` cast to a mutable pointer, for use in calls to C code. + const fn as_mut_ptr(&self) -> *mut SysBusDevice { + addr_of!(*self) as *mut _ + } + + /// Expose an interrupt source outside the device as a qdev GPIO output. + /// Note that the ordering of calls to `init_irq` is important, since + /// whoever creates the sysbus device will refer to the interrupts with + /// a number that corresponds to the order of calls to `init_irq`. + pub fn init_irq(&self, irq: &InterruptSource) { + assert!(bql_locked()); + unsafe { + bindings::sysbus_init_irq(self.as_mut_ptr(), irq.as_ptr()); + } + } +} From patchwork Wed Dec 11 16:27:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903821 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 45C82E77185 for ; Wed, 11 Dec 2024 16:29:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaE-0002zF-1y; Wed, 11 Dec 2024 11:29:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaA-0002Q9-HG for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:02 -0500 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 1tLPa7-0000cx-CF for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934538; 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=BexU3VOLutJEH2IVkrvKdkdz8shoIJg8kVhXm7BVM0w=; b=JBs9Poueej7RBP7OBRGyJm0x9NDZF1zX92NHRa36rEw/W/8qu6K6wun+lZPe0GS2O2PFys xX6+OSK06285lpXhVUIwrUkYgUbSdErpqz1M0xJNcj7qkjGY6J34x+kqIbHJgeFCLcXF6K plOlGXfhQaifb0x6C/h5dPMCLHjM9ls= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-3ddq_VKuPBG60b5X23qJlQ-1; Wed, 11 Dec 2024 11:28:56 -0500 X-MC-Unique: 3ddq_VKuPBG60b5X23qJlQ-1 X-Mimecast-MFC-AGG-ID: 3ddq_VKuPBG60b5X23qJlQ Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-386321c8f4bso2692054f8f.0 for ; Wed, 11 Dec 2024 08:28:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934534; x=1734539334; 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=BexU3VOLutJEH2IVkrvKdkdz8shoIJg8kVhXm7BVM0w=; b=iAtcdjaetdrlPks4vAdcs99v+2uGa1oirNM8aD83EjKYSHIaS/VOSYt1cBgRaSiKcN qQZJ7eAWvrsUdql7skKBJwmG9YbkEEhpgommOL7faHOHgbX5fUHiBuMV4jW4dytzCegE 2hbYVw0dJOCf/oauTUhz0WrdUXPljIT7dxfgqKw4K1Jn7RB4eqwRuwNmlzo4QelE+geq 6+KnRwFKV6ZVLaKg6KNq3x30F1dyYfEbmYPTxCEyXRv7FEvZPgSu9uA6Ss0DJcSCV0aP oJc1/vxm7op14TmjpaGl9aMmfzX1/yWQv67/qb+VQOG9nOBAO+A6dZfyjvJwns4n8COh BlKA== X-Gm-Message-State: AOJu0Yz4TGWLb9gCbh0Wn/OeomtH+HHjsovgEIzteRyRXhCHzE1/KbCF oh4cNlU3mC8+wgw27cPX28XSYSTrNg+2GXuTY34WRUevxl/b9ITph71P5fKy0XeRcJGYbgGCUTx OLS/LuaeaoaExVm2ifKoukKyu/HrMV5Pqyj9AT6Zsk2zy+MfDD24x51ot+VZ0VdnLuC2I0w9CW9 Qkpw2fx+XRf+27cO6rCIpxyA5P8JQtQAJRjlX3 X-Gm-Gg: ASbGncshJzjc2d+SMSe7B7u+YnjJEbnonnoaVDwem1diD0v4qWvZgDXtJSztF6qKYfV 8ZSlM6gUHuMSgKE/+JfihBbGblV0KDej3ktEaA7RfR67Yo/WO8Am+Jm7Jl06WJYG7+eCjnyMZo9 FA6pa4bedNSYZhobR+ofgCtz24NTcVqGG1Ruq+yuYPR3e50CyGy1n6awS+x+euzdXgSGGqhCEE4 TIN+ukKoQ9eZ6p12XSQgn7hMXOAM1M4pYADqtouOETiHoI51N7KCbnf X-Received: by 2002:a5d:6d06:0:b0:386:1cd3:8a07 with SMTP id ffacd0b85a97d-3864ce7fd8emr3202734f8f.7.1733934534412; Wed, 11 Dec 2024 08:28:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeXZMoQ7yIBQprH5XCP9M7tt3DtHySdzn1TJsJEvGLe6aC7Oy6go5/SGj5TJzFiljaCxXM8w== X-Received: by 2002:a5d:6d06:0:b0:386:1cd3:8a07 with SMTP id ffacd0b85a97d-3864ce7fd8emr3202714f8f.7.1733934533963; Wed, 11 Dec 2024 08:28:53 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251dbbfsm1608503f8f.97.2024.12.11.08.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 40/49] rust: add a bit operation module Date: Wed, 11 Dec 2024 17:27:10 +0100 Message-ID: <20241211162720.320070-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 The bindgen supports `static inline` function binding since v0.64.0 as an experimental feature (`--wrap-static-fns`), and stabilizes it after v0.70.0. But the oldest version of bindgen supported by QEMU is v0.60.1, so there's no way to generate the binding for deposit64() which is `static inline` (in include/qemu/bitops.h). Instead, implement it by hand in Rust and make it available for all unsigned types through an IntegerExt trait. Since it only involves bit operations, the Rust version of the code is almost identical to the original C version, but it applies to more types than just u64. Signed-off-by: Zhao Liu Co-authored-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/bitops.rs | 119 +++++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/prelude.rs | 2 + 4 files changed, 123 insertions(+) create mode 100644 rust/qemu-api/src/bitops.rs diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index b927eb58c8e..adcee661150 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -16,6 +16,7 @@ _qemu_api_rs = static_library( [ 'src/lib.rs', 'src/bindings.rs', + 'src/bitops.rs', 'src/cell.rs', 'src/c_str.rs', 'src/definitions.rs', diff --git a/rust/qemu-api/src/bitops.rs b/rust/qemu-api/src/bitops.rs new file mode 100644 index 00000000000..023ec1a9983 --- /dev/null +++ b/rust/qemu-api/src/bitops.rs @@ -0,0 +1,119 @@ +// Copyright (C) 2024 Intel Corporation. +// Author(s): Zhao Liu +// SPDX-License-Identifier: GPL-2.0-or-later + +//! This module provides bit operation extensions to integer types. +//! It is usually included via the `qemu_api` prelude. + +use std::ops::{ + Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, + Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, +}; + +/// Trait for extensions to integer types +pub trait IntegerExt: + Add + AddAssign + + BitAnd + BitAndAssign + + BitOr + BitOrAssign + + BitXor + BitXorAssign + + Copy + + Div + DivAssign + + Eq + + Mul + MulAssign + + Not + Ord + PartialOrd + + Rem + RemAssign + + Shl + ShlAssign + + Shl + ShlAssign + // add more as needed + Shr + ShrAssign + + Shr + ShrAssign // add more as needed +{ + const BITS: u32; + const MAX: Self; + const MIN: Self; + const ONE: Self; + const ZERO: Self; + + #[inline] + #[must_use] + fn bit(start: u32) -> Self + { + debug_assert!(start < Self::BITS); + + Self::ONE << start + } + + #[inline] + #[must_use] + fn mask(start: u32, length: u32) -> Self + { + /* FIXME: Implement a more elegant check with error handling support? */ + debug_assert!(start < Self::BITS && length > 0 && length <= Self::BITS - start); + + (Self::MAX >> (Self::BITS - length)) << start + } + + #[inline] + #[must_use] + fn deposit(self, start: u32, length: u32, + fieldval: U) -> Self + where Self: From + { + debug_assert!(length <= U::BITS); + + let mask = Self::mask(start, length); + (self & !mask) | ((Self::from(fieldval) << start) & mask) + } + + #[inline] + #[must_use] + fn extract(self, start: u32, length: u32) -> Self + { + let mask = Self::mask(start, length); + (self & mask) >> start + } +} + +macro_rules! impl_num_ext { + ($type:ty) => { + impl IntegerExt for $type { + const BITS: u32 = <$type>::BITS; + const MAX: Self = <$type>::MAX; + const MIN: Self = <$type>::MIN; + const ONE: Self = 1; + const ZERO: Self = 0; + } + }; +} + +impl_num_ext!(u8); +impl_num_ext!(u16); +impl_num_ext!(u32); +impl_num_ext!(u64); + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_deposit() { + assert_eq!(15u32.deposit(8, 8, 1u32), 256 + 15); + assert_eq!(15u32.deposit(8, 1, 255u8), 256 + 15); + } + + #[test] + fn test_extract() { + assert_eq!(15u32.extract(2, 4), 3); + } + + #[test] + fn test_bit() { + assert_eq!(u8::bit(7), 128); + assert_eq!(u32::bit(16), 0x10000); + } + + #[test] + fn test_mask() { + assert_eq!(u8::mask(7, 1), 128); + assert_eq!(u32::mask(8, 8), 0xff00); + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 0efbef47441..9e007e16354 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -12,6 +12,7 @@ #[rustfmt::skip] pub mod prelude; +pub mod bitops; pub mod c_str; pub mod cell; pub mod definitions; diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index dfaddbd062a..a39e228babf 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -2,5 +2,7 @@ // Author(s): Paolo Bonzini // SPDX-License-Identifier: GPL-2.0-or-later +pub use crate::bitops::IntegerExt; + pub use crate::cell::BqlCell; pub use crate::cell::BqlRefCell; From patchwork Wed Dec 11 16:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903888 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 0C761E7717D for ; Wed, 11 Dec 2024 16:42:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaI-0003Lv-Ng; Wed, 11 Dec 2024 11:29:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaA-0002Pw-HP for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:02 -0500 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 1tLPa8-0000d2-4A for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d/CuNDAf/h1lPd4tHb600O5eISjRNvbweuEs0GGCzf8=; b=GFFiBk8X+/LhvVXtXQCqyIa6EpQ5ixk6ts1GaX4oAmFQra/8BdRr7BBqyz4LXPeeE3JIFA x1PoLyq16GfxXe3Py2BIGoHERNBmEW8eyssaDItfUOQY5k8T+OoaSjSUGMJcyYtA+JI+kK 0O0iiBcOhEER9Nw/oD2PokD2JKsqjZg= 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-roxdE5G0MUK3Ht4iIgmSAw-1; Wed, 11 Dec 2024 11:28:58 -0500 X-MC-Unique: roxdE5G0MUK3Ht4iIgmSAw-1 X-Mimecast-MFC-AGG-ID: roxdE5G0MUK3Ht4iIgmSAw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so7622915e9.3 for ; Wed, 11 Dec 2024 08:28:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934536; x=1734539336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/CuNDAf/h1lPd4tHb600O5eISjRNvbweuEs0GGCzf8=; b=uWDTuey0sTwWZp8Ozwf0x+CAtSA1/ms5SxvMnkzqikW6wP1cRP3ODY8DXE+ocgAP28 VNw7o0efjYWq1VXRWuuMjbCJXTQXIfZbBu5TQGQBmRiHorO/MvqSiiOUGEEByZWfv+wA wx3yMYQs9VT+TN/eu1u+RElRq3KdgLdf5nMQLFBeqvNFM50gmQ7xgnxGG18z2U/nVoCc mQF3kIKi5VdHPRavl6DNs4A3kuZEebi4I5PxxREhAbwCDaTfgAimQx0dcoIVmuXTw7ah 32Sxi2uNdeQylG+HxC10Pj8Fxf3tkbyNZJDEpkoQOv3YhUrMjDBXu0bFhSEnljNnsesU 4+5w== X-Gm-Message-State: AOJu0YwvCQOEZpKunh2pqdnchI42CFIoPdU/1q64zUQn0GRPpZUle/57 UN0K6/9jtIuGE6HdD1My1kROaD3x6MUNpzbwqHu8XSpCgW9tGYDwCgiYtrbUt8zoUZOEn2vB0W8 p8qJp4QQ9DKUqRm5cFpibRDv04xZhylVrQRTJn6qHNUtNcLjsLw4uc6ckzXg1FdGFskJXzIDEY+ Mw72X24NoCTcCmI8F5yyRoU1KVb8wbQ4MndaDd X-Gm-Gg: ASbGncvEsHzGjEU/eT8+tLgbDP+y84z4ajf08EvBJRqJAZc8PFVMWI6fcfh1vRAVHaq 7v/+bFmsB+apKcD4xqeIgiDmO8VRU+1dQyEjRelghMTqnLm9iZsbkS1bWMbBrMA4HUCAwcShwxD pzb0auTUxjili8S2BAc2aI6xHJ8a6Nz39Zr3WJvQuqez87qBbJfO3hQBc9Rr4U9Rvj3KdF/u5iA fC4bm8One/iMza/Qk9Ix3zz9w1alG74H8Kvnxn6UdxyvJ1eGA+zUH9i X-Received: by 2002:a05:600c:4ed1:b0:435:9ed3:5698 with SMTP id 5b1f17b1804b1-4361c3e33a6mr26455675e9.24.1733934536579; Wed, 11 Dec 2024 08:28:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIKxRQz5jLMOwrWnoDAIrwU/8F57LVsCGyig1WpJsfNdP0I/pxvObIbEhGJTwXSkXmCkA/7g== X-Received: by 2002:a05:600c:4ed1:b0:435:9ed3:5698 with SMTP id 5b1f17b1804b1-4361c3e33a6mr26455465e9.24.1733934536156; Wed, 11 Dec 2024 08:28:56 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52c0dd4sm264001935e9.34.2024.12.11.08.28.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 41/49] rust: qom: add default definitions for ObjectImpl Date: Wed, 11 Dec 2024 17:27:11 +0100 Message-ID: <20241211162720.320070-42-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Remove a bunch of duplicate const definitions. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ------ rust/qemu-api/src/definitions.rs | 8 ++++---- rust/qemu-api/tests/tests.rs | 4 ---- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c5c8c463d37..3d173ae816d 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -109,10 +109,7 @@ impl ObjectImpl for PL011State { const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = crate::TYPE_PL011; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_SYS_BUS_DEVICE); - const ABSTRACT: bool = false; const INSTANCE_INIT: Option = Some(pl011_init); - const INSTANCE_POST_INIT: Option = None; - const INSTANCE_FINALIZE: Option = None; } #[repr(C)] @@ -666,8 +663,5 @@ impl ObjectImpl for PL011Luminary { const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(crate::TYPE_PL011); - const ABSTRACT: bool = false; const INSTANCE_INIT: Option = Some(pl011_luminary_init); - const INSTANCE_POST_INIT: Option = None; - const INSTANCE_FINALIZE: Option = None; } diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 26597934bbd..92b3c6f9118 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -14,10 +14,10 @@ pub trait ObjectImpl { const TYPE_INFO: TypeInfo; const TYPE_NAME: &'static CStr; const PARENT_TYPE_NAME: Option<&'static CStr>; - const ABSTRACT: bool; - const INSTANCE_INIT: Option; - const INSTANCE_POST_INIT: Option; - const INSTANCE_FINALIZE: Option; + const ABSTRACT: bool = false; + const INSTANCE_INIT: Option = None; + const INSTANCE_POST_INIT: Option = None; + const INSTANCE_FINALIZE: Option = None; } pub trait Class { diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 925f5a3c77b..f793ff26e5d 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -58,10 +58,6 @@ impl ObjectImpl for DummyState { const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = c_str!("dummy"); const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::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 { From patchwork Wed Dec 11 16:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903849 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 55511E77180 for ; Wed, 11 Dec 2024 16:36:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaF-00038m-QW; Wed, 11 Dec 2024 11:29:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaC-0002mC-Cq for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:04 -0500 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 1tLPaA-0000dN-8N for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V2ZIv/PAvz3komJwq6oypf8CScK5YKxPKfhuCNRvYs8=; b=TNG+L+R5Z1E/nUFS29xUe6CMvSEaSIuLIgn3HTZFgha/2cBIm2LfGX/0kuE2dTYYiMrSKT QjaXfsDiOrk6OTFj19hScRA++WNPQrTN9C3ypwMvOVecCFKxZE9Ua+EaYAr6762y8/SKVd XVXPnL8IVdsIokgB+6q9oIXm1aMyqMI= 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-695-ZpyszVJ1ONeETWBfZTCnkQ-1; Wed, 11 Dec 2024 11:29:00 -0500 X-MC-Unique: ZpyszVJ1ONeETWBfZTCnkQ-1 X-Mimecast-MFC-AGG-ID: ZpyszVJ1ONeETWBfZTCnkQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385fdff9db5so3047315f8f.0 for ; Wed, 11 Dec 2024 08:28:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934538; x=1734539338; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V2ZIv/PAvz3komJwq6oypf8CScK5YKxPKfhuCNRvYs8=; b=bDUMe+ZvATKcgMRGzz5n2NC9MPU4Ov6jL+LTQ00iyLdZWHa6QO7xqe2NGzx8sZNlNY /j+kUxTY8Fo80VhfHoNAP2+ggJTo3ImOaH6cn8fDZ4ddoLmSnpGF4cPYWJfmcQgnOW08 sp2JdKFhYDaK4f6KHqvXHjszQE3AKW6uAhHU4SrHudOVir6czgQT9nKFQUHVTtqEmJEY squOuErEqqCdQ0mwW5kMnCoCbCsAasvQyHw8SLJs8ZywjOGuCU7bf/V8lan9vEHU01JM 7pFk4LMy5zab4WqGxAuQ9297HQ8IJFr7QjWDQKvXMs/6pLmI+6gl0pTNo6u+bgB/ahnM FG8g== X-Gm-Message-State: AOJu0YxdLkIYKk16/QDHSe7B2zsLOwZv0+PKuH4kRqS9VUc3+B/V4NdJ 9U8m6G1JOeFx9WEpYFiyKPg3cM+eoJE4jjdCwF9dvVAOL54Id8gJIlbXV4xjscCsFNDqYpNfQjO u1jAdu5vNt5ASYPakknvE67zsjHXI/BxOuotf6CZiVGZK6vV17z1V+HxKr/Bam+qW7aNZJCUY8v Iwcmyqnlg3eDU/6wVqkC+o52GbFvbtBKLYqhdB X-Gm-Gg: ASbGncuIdIpqKUBjbPzymL4+Sryof/ZYl52oP7QdxYCcNjyLZC3X/VXvzmZz9kqjsGp Dx9LCPy+HLEiDiaxLXccpgpZj47DNqPMw5uYIpwojuz6CMbvS3vQJN3Lt6ks+ao7B5bH2wIwf41 8Vu8zZKUbmK56tgIJWYW48a92CRt0cgv10XOkmj7lzl4D/1pd3/pcGdoowdngd6Txy5lTI6V3f7 jdyDhbgMgJHGsYGVgxe/5VL7y8ddcjWhqjUutROBCtgGmqZcgTBiJSN X-Received: by 2002:a05:6000:2d06:b0:386:36e7:f44f with SMTP id ffacd0b85a97d-3864ce54e99mr1855744f8f.18.1733934538511; Wed, 11 Dec 2024 08:28:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzZEh0zfHQt0LE3ncM/wMXoifhf+IKYgNed+nSnYPzXI3DaqzXLzJCYZ/c7t2hWNpT95Riuw== X-Received: by 2002:a05:6000:2d06:b0:386:36e7:f44f with SMTP id ffacd0b85a97d-3864ce54e99mr1855721f8f.18.1733934537812; Wed, 11 Dec 2024 08:28:57 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251c1d7sm1606234f8f.91.2024.12.11.08.28.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 42/49] rust: qom: rename Class trait to ClassInitImpl Date: Wed, 11 Dec 2024 17:27:12 +0100 Message-ID: <20241211162720.320070-43-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 While at it, document it. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/qemu-api/src/definitions.rs | 25 ++++++++++++++++++++++--- rust/qemu-api/tests/tests.rs | 4 ++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 3d173ae816d..bd12067aaf0 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -117,7 +117,7 @@ pub struct PL011Class { _inner: [u8; 0], } -impl qemu_api::definitions::Class for PL011Class { +impl qemu_api::definitions::ClassInitImpl for PL011Class { const CLASS_INIT: Option = Some(crate::device_class::pl011_class_init); const CLASS_BASE_INIT: Option< @@ -650,7 +650,7 @@ pub struct PL011LuminaryClass { } } -impl qemu_api::definitions::Class for PL011LuminaryClass { +impl qemu_api::definitions::ClassInitImpl for PL011LuminaryClass { const CLASS_INIT: Option = None; const CLASS_BASE_INIT: Option< diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 92b3c6f9118..3291f4242ce 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -20,8 +20,27 @@ pub trait ObjectImpl { const INSTANCE_FINALIZE: Option = None; } -pub trait Class { +/// Trait used to fill in a class struct. +/// +/// Each QOM class that has virtual methods describes them in a +/// _class struct_. Class structs include a parent field corresponding +/// to the vtable of the parent class, all the way up to [`ObjectClass`]. +/// Each QOM type has one such class struct. +/// +/// The Rust implementation of methods will usually come from a trait +/// like [`ObjectImpl`]. +pub trait ClassInitImpl { + /// Function that is called after all parent class initialization + /// has occurred. On entry, the virtual method pointers are set to + /// the default values coming from the parent classes; the function + /// can change them to override virtual methods of a parent class. const CLASS_INIT: Option; + + /// Called on descendent classes after all parent class initialization + /// has occurred, but before the class itself is initialized. This + /// is only useful if a class is not a leaf, and can be used to undo + /// the effects of copying the contents of the parent's class struct + /// to the descendants. const CLASS_BASE_INIT: Option< unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), >; @@ -82,8 +101,8 @@ macro_rules! type_info { 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>(), - 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_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_INIT, + class_base_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_BASE_INIT, class_data: ::core::ptr::null_mut(), interfaces: ::core::ptr::null_mut(), }; diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index f793ff26e5d..704c63c846f 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -7,7 +7,7 @@ use qemu_api::{ bindings::*, c_str, declare_properties, define_property, - definitions::{Class, ObjectImpl}, + definitions::{ClassInitImpl, ObjectImpl}, device_class, device_class_init, zeroable::Zeroable, }; @@ -60,7 +60,7 @@ impl ObjectImpl for DummyState { const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); } - impl Class for DummyClass { + impl ClassInitImpl for DummyClass { const CLASS_INIT: Option = Some(dummy_class_init); const CLASS_BASE_INIT: Option< From patchwork Wed Dec 11 16:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903846 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 02CFAE77180 for ; Wed, 11 Dec 2024 16:35:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaK-0003R2-QS; Wed, 11 Dec 2024 11:29:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaE-00031Q-AC for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:06 -0500 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 1tLPaC-0000ds-EF for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3KnA6nxj6wRieH/eonLUIy1D83UK4FyVWaqyO6ZnPKE=; b=iwCh8N/oh6wRsKYf/F9zv4/jZhCB+ITFMRcsneReZxA1zQCaPPDV6iBELeukf872Jzi0zr 9PzQW47gsaaoQHSlG6LhPhj3VxGK2xL/dackV5OQWMl3qVGlWIyHYb/G99SKgUMknV7o7M OZk4/a6CL3CxqTDEn3i8NDWS9e0cYJE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-pReGUimgPQOpmQ-O0F0hhw-1; Wed, 11 Dec 2024 11:29:02 -0500 X-MC-Unique: pReGUimgPQOpmQ-O0F0hhw-1 X-Mimecast-MFC-AGG-ID: pReGUimgPQOpmQ-O0F0hhw Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3860bc1d4f1so3755009f8f.2 for ; Wed, 11 Dec 2024 08:29:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934540; x=1734539340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3KnA6nxj6wRieH/eonLUIy1D83UK4FyVWaqyO6ZnPKE=; b=aCzISkk7X/ETi05+BZEx54XwvtdNM56nbEOlncB6GF4axr7fKFVSsuLiiz8/tOV7P0 t10x4xbHFbc9PYKVFKoallLtlZkHpeA5FYAfHY9abdknB3uXUerkt86Vw6wkLRnroK9J zeyB/3AAzpA9ZL6MEfFC1b5LLYbx7Ukqgdmdh34Y0owIJmJPMhKz5FeVWXngAIouDpSP GsRfuO8RzAz5VyMSMs8+rhFdRcOzhUnrdcKFIRYlWRUM9MO/sYcPB1/yZzeB4yCB21K5 Rb0UHeT0cJScol73gLlXIS6hzkl1qAHjzuWHnNtEHFmJxINOAASXkfQ+w7DglhwUr6Zg NeQg== X-Gm-Message-State: AOJu0Yx6cwJvYuPz8A4fF+wJzUouzxiboXlo1EJDcLMLkrzp919aj4w8 adHueBhEuzSp/RY9PbXHPzSP6MtnnRE32pAz1cqcaQDVu2duJa/Za94MmLfUCN9SleuHyjh1Zj5 O7weOG/pGs3fCxZdBleqKPIE7rboarwQJ2gudSOuRnb8M8Z8g9TN0a+ec3IvtDX4Z9OLhsdC9ni f3SgSX+IqBcTPErJuf7iQbE3B6AaWoPpGUK9Sr X-Gm-Gg: ASbGnctnJ9/qPA/gYpyuUmVwQLOYSTsge8zWtWy93y1XSsPQoHY7HjlWTQgFtz5VlOD G3aaOE5xattPg0gjZGoI2+0mAeRI7CakEe6AR6HE4epL4tqfvJNb+2yUJELhNut5q7v2jYnQ4MX NBQAlXBJJZLMvvrBSDbVBSuncssKhmHoQY8XRzyMovfRKCzqCZAoi8dLZR9vNe5p5SV7cgjkP2x 6Cz8EFg+AOj7ti/Xc2ajJhPpqJ00Af//Er5nyG6oroVPswzWHia0RdB X-Received: by 2002:a05:6000:178b:b0:385:faaa:9d1d with SMTP id ffacd0b85a97d-3864cea04aamr3370659f8f.35.1733934540432; Wed, 11 Dec 2024 08:29:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAQi60zHVnPa1mlyIjdUVJ/MZQ8K5xv5PogQnNt48xLS9Ds2sDhQOtYKyTMCJQ0w01u9Mwrw== X-Received: by 2002:a05:6000:178b:b0:385:faaa:9d1d with SMTP id ffacd0b85a97d-3864cea04aamr3370638f8f.35.1733934539899; Wed, 11 Dec 2024 08:28:59 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248f566sm1672579f8f.1.2024.12.11.08.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:28:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 43/49] rust: qom: convert type_info! macro to an associated const Date: Wed, 11 Dec 2024 17:27:13 +0100 Message-ID: <20241211162720.320070-44-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 type_info! is only used in the definition of ObjectImpl::TYPE_INFO, and in fact in all of them. Pull type_info!'s definition into the ObjectImpl trait, thus simplifying the external interface of qemu_api::definitions. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++-- rust/qemu-api/src/definitions.rs | 50 ++++++++++++++------------------ rust/qemu-api/tests/tests.rs | 1 - 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index bd12067aaf0..bcb146c24d6 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -106,7 +106,6 @@ pub struct PL011State { impl ObjectImpl for PL011State { type Class = PL011Class; - const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = crate::TYPE_PL011; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_SYS_BUS_DEVICE); const INSTANCE_INIT: Option = Some(pl011_init); @@ -149,7 +148,7 @@ unsafe fn init(&mut self) { addr_of_mut!(*self).cast::(), &PL011_OPS, addr_of_mut!(*self).cast::(), - Self::TYPE_INFO.name, + Self::TYPE_NAME.as_ptr(), 0x1000, ); sysbus_init_mmio(sbd, addr_of_mut!(self.iomem)); @@ -598,7 +597,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { chr: *mut Chardev, ) -> *mut DeviceState { unsafe { - let dev: *mut DeviceState = qdev_new(PL011State::TYPE_INFO.name); + let dev: *mut DeviceState = qdev_new(PL011State::TYPE_NAME.as_ptr()); let sysbus: *mut SysBusDevice = dev.cast::(); qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); @@ -660,7 +659,6 @@ impl qemu_api::definitions::ClassInitImpl for PL011LuminaryClass { impl ObjectImpl for PL011Luminary { type Class = PL011LuminaryClass; - const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(crate::TYPE_PL011); const INSTANCE_INIT: Option = Some(pl011_luminary_init); diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 3291f4242ce..6ecfaf51b09 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -9,15 +9,34 @@ use crate::bindings::{Object, ObjectClass, TypeInfo}; /// Trait a type must implement to be registered with QEMU. -pub trait ObjectImpl { - type Class; - const TYPE_INFO: TypeInfo; +pub trait ObjectImpl: Sized { + type Class: ClassInitImpl; const TYPE_NAME: &'static CStr; const PARENT_TYPE_NAME: Option<&'static CStr>; const ABSTRACT: bool = false; const INSTANCE_INIT: Option = None; const INSTANCE_POST_INIT: Option = None; const INSTANCE_FINALIZE: Option = None; + + const TYPE_INFO: TypeInfo = TypeInfo { + name: Self::TYPE_NAME.as_ptr(), + parent: if let Some(pname) = Self::PARENT_TYPE_NAME { + pname.as_ptr() + } else { + core::ptr::null_mut() + }, + instance_size: core::mem::size_of::(), + instance_align: core::mem::align_of::(), + instance_init: Self::INSTANCE_INIT, + instance_post_init: Self::INSTANCE_POST_INIT, + instance_finalize: Self::INSTANCE_FINALIZE, + abstract_: Self::ABSTRACT, + class_size: core::mem::size_of::(), + class_init: ::CLASS_INIT, + class_base_init: ::CLASS_BASE_INIT, + class_data: core::ptr::null_mut(), + interfaces: core::ptr::null_mut(), + }; } /// Trait used to fill in a class struct. @@ -83,28 +102,3 @@ extern "C" fn ctor_fn() { } }; } - -#[macro_export] -macro_rules! type_info { - ($t:ty) => { - $crate::bindings::TypeInfo { - name: <$t as $crate::definitions::ObjectImpl>::TYPE_NAME.as_ptr(), - parent: if let Some(pname) = <$t as $crate::definitions::ObjectImpl>::PARENT_TYPE_NAME { - pname.as_ptr() - } else { - ::core::ptr::null_mut() - }, - 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>(), - class_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_INIT, - class_base_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_BASE_INIT, - class_data: ::core::ptr::null_mut(), - interfaces: ::core::ptr::null_mut(), - }; - } -} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 704c63c846f..7f9df348b00 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -55,7 +55,6 @@ pub struct DummyClass { 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_str!("dummy"); const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); } From patchwork Wed Dec 11 16:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903841 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 523CDE7717D for ; Wed, 11 Dec 2024 16:34:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaM-0003VI-K6; Wed, 11 Dec 2024 11:29:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaF-00039r-OE for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:07 -0500 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 1tLPaD-0000eK-SV for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rnI0niveAFX2WdKfqxklK+1Zt06kPSFJCN7eFa7HF+8=; b=dopaszjgPLj38YnhAjXFPMwKZQpDY/PBs0gTLXdcSjczIaVI+70tjsZeM4w0EHWVDcWMLd nI08kwFtcSdDw/R3PMpuyG4calxlBpHew2g0+5IzFmas2wAtUzEpucejXB6VdrXEt30cm4 +AyYUvGscMy929apckodrtezyEKprxQ= 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-127-bpmbVHmZPqipX8q-fNU3dQ-1; Wed, 11 Dec 2024 11:29:04 -0500 X-MC-Unique: bpmbVHmZPqipX8q-fNU3dQ-1 X-Mimecast-MFC-AGG-ID: bpmbVHmZPqipX8q-fNU3dQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e4a759e6so4253327f8f.1 for ; Wed, 11 Dec 2024 08:29:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934542; x=1734539342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rnI0niveAFX2WdKfqxklK+1Zt06kPSFJCN7eFa7HF+8=; b=EK03DXpv91pfAwxnD/mbv5VChczfUSt8nc22lT9BuPeKWe6fOHMgXHGAwj9MlNbtfX wcUYPUED3vDD+uYIkw8Rc/b2BMa/+Drk+vIpCk2Yd6iPh1Ct0gFMNFb5Ebdg3BZIwW96 Q/xwv5BisK/5rP53NF+6ZDatyVNpWhOvydlCwXR62JEdahQHewWpVrGaeBNOqwrO0p4Y DXe8p/PwOJDgXUN4DNKaEcUGgO8/xcFt8xU1Qt45i+Ak5/orXhE+4v9UMcDPwnAo1lEG lMSXFil702iukDd5/fuX2rE6GwGUysGuvmIHbZNCXE91X52rJKd0DG8pwVDD0fdOnvF3 CN/g== X-Gm-Message-State: AOJu0YxICc1L0g5lcyUiBOcq6rM00j4yODfVFgVvPCj19wB1XJVA7iA+ 4JGpq6LIyaeFWBjRNtzTpIN2gyt7xHGZjR8xStqXzoHFEokytyb5STqzD/MxNtdZfrH1JqBWh9y lWwLkztHo4BPWKekSfgNxBTTDOb5YHzDt222N4l4SiojZrmlKWfKJv/GE7iDzjqpWpTDYNdP8pT 5eMbfyWupfLpDOL65MQEBIb8Qd7JC3Bwb2Aej9 X-Gm-Gg: ASbGncsh/z5W41TC++ZqwmeRFER60dROH8jsvtHZrJN+lCrIBsj7HlbKdPZp9/DyHdW f7anXAoBmpzyLSZ54XXmIFeJCdBelviQdQ3ZETbhOw9XvOqLHC4IMMbfgataHVLwLEjEN0Qo4uJ FxTLlp41jzPDA2KFKQpw1dkhCgAuGm2DO1W0O5rhhY+yT3elAUpUJn81685pwlZFlCwcM3xdKEp IrDlxqp8gj0Nxwn8uBypm1lY3Tve+qIlSLV/H+mRfdd390gmYnoXWYD X-Received: by 2002:a05:6000:156e:b0:386:4034:f9a6 with SMTP id ffacd0b85a97d-387877dcaa4mr161981f8f.57.1733934542300; Wed, 11 Dec 2024 08:29:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3XWggqCNpBpk7ACaBG8vZIoSmClZxjI9GWZWxPBdvSFpQnXNUxvQK/9FswNaWLBw/LXqGsg== X-Received: by 2002:a05:6000:156e:b0:386:4034:f9a6 with SMTP id ffacd0b85a97d-387877dcaa4mr161966f8f.57.1733934541807; Wed, 11 Dec 2024 08:29:01 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251bcabsm1665993f8f.87.2024.12.11.08.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 44/49] rust: qom: move ClassInitImpl to the instance side Date: Wed, 11 Dec 2024 17:27:14 +0100 Message-ID: <20241211162720.320070-45-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Put all traits on the instance struct, which makes it possible to reuse class structs if no new virtual methods or class fields are added. This is almost always the case for devices (because they are leaf classes), which is the primary use case for Rust. This is also simpler: soon we will find the implemented methods without macros, and this removes the need to go from the class struct to the instance struct to find the implementation of the *Impl traits. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/qemu-api/src/definitions.rs | 8 ++++---- rust/qemu-api/tests/tests.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index bcb146c24d6..2384d4bcb95 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -116,7 +116,7 @@ pub struct PL011Class { _inner: [u8; 0], } -impl qemu_api::definitions::ClassInitImpl for PL011Class { +impl qemu_api::definitions::ClassInitImpl for PL011State { const CLASS_INIT: Option = Some(crate::device_class::pl011_class_init); const CLASS_BASE_INIT: Option< @@ -649,7 +649,7 @@ pub struct PL011LuminaryClass { } } -impl qemu_api::definitions::ClassInitImpl for PL011LuminaryClass { +impl qemu_api::definitions::ClassInitImpl for PL011Luminary { const CLASS_INIT: Option = None; const CLASS_BASE_INIT: Option< diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 6ecfaf51b09..487712611f6 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -9,8 +9,8 @@ use crate::bindings::{Object, ObjectClass, TypeInfo}; /// Trait a type must implement to be registered with QEMU. -pub trait ObjectImpl: Sized { - type Class: ClassInitImpl; +pub trait ObjectImpl: ClassInitImpl + Sized { + type Class; const TYPE_NAME: &'static CStr; const PARENT_TYPE_NAME: Option<&'static CStr>; const ABSTRACT: bool = false; @@ -32,8 +32,8 @@ pub trait ObjectImpl: Sized { instance_finalize: Self::INSTANCE_FINALIZE, abstract_: Self::ABSTRACT, class_size: core::mem::size_of::(), - class_init: ::CLASS_INIT, - class_base_init: ::CLASS_BASE_INIT, + class_init: ::CLASS_INIT, + class_base_init: ::CLASS_BASE_INIT, class_data: core::ptr::null_mut(), interfaces: core::ptr::null_mut(), }; diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 7f9df348b00..fd0c979121c 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -59,7 +59,7 @@ impl ObjectImpl for DummyState { const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); } - impl ClassInitImpl for DummyClass { + impl ClassInitImpl for DummyState { const CLASS_INIT: Option = Some(dummy_class_init); const CLASS_BASE_INIT: Option< From patchwork Wed Dec 11 16:27:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903875 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 36307E7717D for ; Wed, 11 Dec 2024 16:39:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaO-0003gO-VY; Wed, 11 Dec 2024 11:29:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaI-0003Ng-RX for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:11 -0500 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 1tLPaG-0000ff-Qw for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934548; 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=sU9LjfrSS+1trzy9agSXX/YTJPU2Nn1jBVlPhNEmW34=; b=J53gqNVuVpSg48WUJSo144KRQSimO0fV0m98AAG6970grwQf5I/EQVsWE1IwkBxmy5uW19 cByr/dT6pYIO8Tb1ytvj41LBeRbMeipHFejVktB3Ag5wt0Sxpfe5aJZpz0Y7z2XMkxDbW6 iNKC270bmfQAdNMgD97+jPc/Ee/xvqA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-_t8prK4LMGSLo2zzRL5ekw-1; Wed, 11 Dec 2024 11:29:07 -0500 X-MC-Unique: _t8prK4LMGSLo2zzRL5ekw-1 X-Mimecast-MFC-AGG-ID: _t8prK4LMGSLo2zzRL5ekw Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e2579507so3866879f8f.1 for ; Wed, 11 Dec 2024 08:29:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934546; x=1734539346; 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=sU9LjfrSS+1trzy9agSXX/YTJPU2Nn1jBVlPhNEmW34=; b=nDTazvL2njUm+qjxOOC8gE7M75sJwjAotqfJrJ6AtnNtoJYQ5w6N+5YXMjB52skexY 376j1A0aBwat5LAwzppJL7pTm+aJOnohveAfAiDjC8tLp1nG5kbt5XxBds7XtgC8Z8Vw GgguLFgeh2Yt7Z3TBnw0BfdLGE7fD8abqjdHUcvK33CiGhwztR/JZFQXVtMXRaPBShAH UBEVb4NptN8TgDJSIvGL/w6YQEPXSCUcfT92mqqwofdGjfZyMHycGTg9w4UaPR4UTU1G 84zTRHz7N2JF963OfeUtlGpirdzDb3y8vIWUP3X7iLxKWlN8sjcowoyuzG25kOFJIqN4 /jRg== X-Gm-Message-State: AOJu0YzJvOXaRXT+5A11FnPADJ3++KbEgOuGlXC7B3mk5yURxDm1vMzb 0tquXvozdOHLrKVP/p7V3J77G5XJ+zCkrH5yrc942jD+NeoMnK3H1jxqz+JRoJmcnoAdI1w56Mt YJhEuQiceIdqnWhQ2/4PTM9rvCOdp0sDGieV3TEyIZR1R/n8PJnPIyX48U5kj7dqksqkssHNnkg qITU6uTCfxN/sqz5+IussbOg1W6BI2T0bQMQqW X-Gm-Gg: ASbGncukmuW85YIWk2owsSKhSTDHIno7jFTXmeeBxlmUI6Yi5fcJFacTGUE+Ed67VuR ZnZMr8ylGZBAprgje3QnHvyIFzetJeslewdgS4GyKaxNqS54vMT1s5M6s29Tvza72A5VDd7DL/P 4CcqUqVRVFgeIvUZHL88yrZRxfLdEy5g4lepfallxFfXEqOLG4g21o0rrWCQIBn++xYSc90olkE XxLwbbA1TBoCvxVR9PgIxMESLMn0dabuo2VZKD+5gX2NfGFsftceh2e X-Received: by 2002:a05:6000:1541:b0:385:fc70:826 with SMTP id ffacd0b85a97d-387876c3782mr161980f8f.52.1733934544172; Wed, 11 Dec 2024 08:29:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjqF7S7VouQo98MvQ/qm7NjZ0q6KaY1Z/d3XaUyd658vx1cPqT+V+fs7gq/nRx+Rd6SrhWLQ== X-Received: by 2002:a05:6000:1541:b0:385:fc70:826 with SMTP id ffacd0b85a97d-387876c3782mr161974f8f.52.1733934543640; Wed, 11 Dec 2024 08:29:03 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251bc16sm1639553f8f.86.2024.12.11.08.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 45/49] rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macro Date: Wed, 11 Dec 2024 17:27:15 +0100 Message-ID: <20241211162720.320070-46-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Use a trait to access the former parameters to device_class_init!. This allows hiding the details of the class_init implementation behind a generic function and makes higher-level functionality available from qemu_api. The implementation of ClassInitImpl is then the same for all devices and is easily macroized. Later on, we can remove the need to implement ClassInitImpl by hand for all device types, and stop making rust_device_class_init<>() public. While at it, document the members of DeviceImpl. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 34 +++++----- rust/hw/char/pl011/src/device_class.rs | 8 --- rust/qemu-api/src/device_class.rs | 87 +++++++++++++++++++++----- rust/qemu-api/tests/tests.rs | 30 ++++----- 4 files changed, 103 insertions(+), 56 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2384d4bcb95..28b1924337d 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -12,11 +12,13 @@ bindings::{self, *}, c_str, definitions::ObjectImpl, - device_class::TYPE_SYS_BUS_DEVICE, + device_class::{DeviceImpl, TYPE_SYS_BUS_DEVICE}, + impl_device_class, irq::InterruptSource, }; use crate::{ + device_class, memory_ops::PL011_OPS, registers::{self, Interrupt}, RegisterOffset, @@ -116,14 +118,20 @@ pub struct PL011Class { _inner: [u8; 0], } -impl qemu_api::definitions::ClassInitImpl for PL011State { - const CLASS_INIT: Option = - Some(crate::device_class::pl011_class_init); - const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), - > = None; +impl DeviceImpl for PL011State { + fn properties() -> &'static [Property] { + &device_class::PL011_PROPERTIES + } + fn vmsd() -> Option<&'static VMStateDescription> { + Some(&device_class::VMSTATE_PL011) + } + const REALIZE: Option = + Some(device_class::pl011_realize); + const RESET: Option = Some(device_class::pl011_reset); } +impl_device_class!(PL011State); + impl PL011State { /// Initializes a pre-allocated, unitialized instance of `PL011State`. /// @@ -649,17 +657,13 @@ pub struct PL011LuminaryClass { } } -impl qemu_api::definitions::ClassInitImpl for PL011Luminary { - const CLASS_INIT: Option = - None; - const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), - > = None; -} - impl ObjectImpl for PL011Luminary { type Class = PL011LuminaryClass; const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(crate::TYPE_PL011); const INSTANCE_INIT: Option = Some(pl011_luminary_init); } + +impl DeviceImpl for PL011Luminary {} + +impl_device_class!(PL011Luminary); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index a707fde1384..c61b6bb0258 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -93,14 +93,6 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { ), } -qemu_api::device_class_init! { - pl011_class_init, - props => PL011_PROPERTIES, - realize_fn => Some(pl011_realize), - legacy_reset_fn => Some(pl011_reset), - vmsd => VMSTATE_PL011, -} - /// # Safety /// /// We expect the FFI user of this function to pass a valid pointer, that has diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 922bbce1bb8..f683f94f2a5 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,25 +2,80 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::ffi::CStr; +use std::{ffi::CStr, os::raw::c_void}; -use crate::bindings; +use crate::{ + bindings::{self, DeviceClass, DeviceState, Error, ObjectClass, Property, VMStateDescription}, + zeroable::Zeroable, +}; + +/// Trait providing the contents of [`DeviceClass`]. +pub trait DeviceImpl { + /// _Realization_ is the second stage of device creation. It contains + /// all operations that depend on device properties and can fail (note: + /// this is not yet supported for Rust devices). + /// + /// If not `None`, the parent class's `realize` method is overridden + /// with the function pointed to by `REALIZE`. + const REALIZE: Option = None; + + /// If not `None`, the parent class's `reset` method is overridden + /// with the function pointed to by `RESET`. + /// + /// Rust does not yet support the three-phase reset protocol; this is + /// usually okay for leaf classes. + const RESET: Option = None; + + /// An array providing the properties that the user can set on the + /// device. Not a `const` because referencing statics in constants + /// is unstable until Rust 1.83.0. + fn properties() -> &'static [Property] { + &[Zeroable::ZERO; 1] + } + + /// A `VMStateDescription` providing the migration format for the device + /// Not a `const` because referencing statics in constants is unstable + /// until Rust 1.83.0. + fn vmsd() -> Option<&'static VMStateDescription> { + None + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer that +/// can be downcasted to type `DeviceClass`, because `T` implements +/// `DeviceImpl`. +pub unsafe extern "C" fn rust_device_class_init( + klass: *mut ObjectClass, + _: *mut c_void, +) { + let mut dc = ::core::ptr::NonNull::new(klass.cast::()).unwrap(); + unsafe { + let dc = dc.as_mut(); + if let Some(realize_fn) = ::REALIZE { + dc.realize = Some(realize_fn); + } + if let Some(reset_fn) = ::RESET { + bindings::device_class_set_legacy_reset(dc, Some(reset_fn)); + } + if let Some(vmsd) = ::vmsd() { + dc.vmsd = vmsd; + } + bindings::device_class_set_props(dc, ::properties().as_ptr()); + } +} #[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$(,)*) => { - pub unsafe extern "C" fn $func( - klass: *mut $crate::bindings::ObjectClass, - _: *mut ::std::os::raw::c_void, - ) { - let mut dc = - ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); - 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_ptr()); - } +macro_rules! impl_device_class { + ($type:ty) => { + impl $crate::definitions::ClassInitImpl for $type { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut ::std::os::raw::c_void), + > = Some($crate::device_class::rust_device_class_init::<$type>); + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut ::std::os::raw::c_void), + > = None; } }; } diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index fd0c979121c..b8b12a40422 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -2,13 +2,14 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::{ffi::CStr, os::raw::c_void}; +use std::ffi::CStr; use qemu_api::{ bindings::*, c_str, declare_properties, define_property, - definitions::{ClassInitImpl, ObjectImpl}, - device_class, device_class_init, + definitions::ObjectImpl, + device_class::{self, DeviceImpl}, + impl_device_class, zeroable::Zeroable, }; @@ -45,28 +46,23 @@ pub struct DummyClass { ), } - 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_NAME: &'static CStr = c_str!("dummy"); const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); } - impl ClassInitImpl for DummyState { - const CLASS_INIT: Option = - Some(dummy_class_init); - const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), - > = None; + impl DeviceImpl for DummyState { + fn properties() -> &'static [Property] { + &DUMMY_PROPERTIES + } + fn vmsd() -> Option<&'static VMStateDescription> { + Some(&VMSTATE) + } } + impl_device_class!(DummyState); + unsafe { module_call_init(module_init_type::MODULE_INIT_QOM); object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); From patchwork Wed Dec 11 16:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903823 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 87C73E77180 for ; Wed, 11 Dec 2024 16:30:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaS-0003uE-P1; Wed, 11 Dec 2024 11:29:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaL-0003Un-7v for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaJ-0000gF-6b for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934549; 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=ctCAEWtPTR324riG8wYmwkDMgtVqvsSzl7tky+ffgCc=; b=ZmunXBmBibqayVuWtgRCbYcM8dypNdGtVuxVgs6356s73GbdKPvEqKlyl7El39cSuAsdks /J5EQBIL6bY7whcjRuuhfvxerKNam9JCxXdcL8gLAQ1YwUddiEQJcEnHIHwvCOpSAu3pxJ k3Cxet9RGQYd/0a9RGmgGuSLeNokY2Q= 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-88-Lra9O63JPWaV_ykoQnWuyA-1; Wed, 11 Dec 2024 11:29:08 -0500 X-MC-Unique: Lra9O63JPWaV_ykoQnWuyA-1 X-Mimecast-MFC-AGG-ID: Lra9O63JPWaV_ykoQnWuyA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-434e8beee61so5295745e9.0 for ; Wed, 11 Dec 2024 08:29:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934546; x=1734539346; 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=ctCAEWtPTR324riG8wYmwkDMgtVqvsSzl7tky+ffgCc=; b=IRpLO00Xo+iGyYqw7YCZzsZlxiQv1luPAolqK+Btq/gxwQEsTnHzcqJIWNBYpsCSWa RrxgLPqmMq3DoUbqOx0DNsGZVWmL3qW1V2yZISLsDDmQKyMzk1aSz2jMbThNrOAxDyTK vqE3j3LGG9VbsBtWKeXrUD3/y7Fx15ibD8JSKcuXaC5f9fkN8gCVOzzkfvE78JXV9RDt wi0WSv/xjtsRSsPhOML8CrcfaPtMBUdiZ+uHVybQ7afwypSb5qtUtgVqimvjeaRC3VJy DZuSiKFsxxKOnXikkbl19YbIQ0QK4jbeDuvp497dGJD498s3QBU/I6Ly5CASjOFcqyQy O27w== X-Gm-Message-State: AOJu0YyX/msFvgnhpJ91lh4GCYVa4EWsBkichD48rcdA/s+Jn8Eun+/l 4kgcZg/PpNdmH0wnxfbnHh0eDp5oDoDsQDQp6uzQXWtvMGY2nk/AnaJcPJhz1m4m6FFqispLpik L1eHLhPJP9Tbr1loR9wHVHiw9eFfQonklErJrk4GFs3KmRKp8gFOOL1k82NR9JXcA9oC8zAHmE/ sMQlPvXNDpgv5Ajb3wcYELduxX0IeyFS7C5TDl X-Gm-Gg: ASbGncssMPErOWG0BBbRvORwldTdKcx7iaalOa3AVhWf0lgOSFzrge6AL3Q8dSWYdto uVqILe7Zq16RmnoCjKxoLwUFStKIRl1jQvlBVzPn6wyAoDPd5WqzPY0r55QaD7FmLeJD8Hp4H98 plmiBOo+utPhbk2YKvCtB5d2ilG8ePyaF60dtozVDk9ukampdhrUbOBr3TE0Uj5762L3AXGlTCd 8OZXtY3UeZjJcESn2SEPkkgVq66Xc3NNOCNINGxvuE8JoN9fUKfwKVJ X-Received: by 2002:a05:600c:68c9:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-4361c58f6f3mr23701135e9.2.1733934545873; Wed, 11 Dec 2024 08:29:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbDh5yeFqL/pLxftKDaqJ5YYLxiOSmR5k05j8koV6KT4sMdI89jGxfosqxCBfEs6b2NRzn5Q== X-Received: by 2002:a05:600c:68c9:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-4361c58f6f3mr23700955e9.2.1733934545421; Wed, 11 Dec 2024 08:29:05 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-435aab63baesm53860845e9.38.2024.12.11.08.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 46/49] rust: qdev: move bridge for realize and reset functions out of pl011 Date: Wed, 11 Dec 2024 17:27:16 +0100 Message-ID: <20241211162720.320070-47-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Allow the DeviceImpl trait to expose safe Rust functions. rust_device_class_init<> adds thunks around the functions in DeviceImpl. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 5 ++-- rust/hw/char/pl011/src/device_class.rs | 26 ------------------- rust/qemu-api/src/definitions.rs | 2 +- rust/qemu-api/src/device_class.rs | 36 +++++++++++++++++++++----- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 28b1924337d..56403c36609 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -125,9 +125,8 @@ fn properties() -> &'static [Property] { fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } - const REALIZE: Option = - Some(device_class::pl011_realize); - const RESET: Option = Some(device_class::pl011_reset); + const REALIZE: Option = Some(Self::realize); + const RESET: Option = Some(Self::reset); } impl_device_class!(PL011State); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index c61b6bb0258..975c3d42be7 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -92,29 +92,3 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { default = true ), } - -/// # Safety -/// -/// 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. -pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut *mut Error) { - unsafe { - assert!(!dev.is_null()); - let mut state = NonNull::new_unchecked(dev.cast::()); - state.as_mut().realize(); - } -} - -/// # Safety -/// -/// 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. -pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { - unsafe { - assert!(!dev.is_null()); - let mut state = NonNull::new_unchecked(dev.cast::()); - state.as_mut().reset(); - } -} diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 487712611f6..0467e6290e0 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -47,7 +47,7 @@ pub trait ObjectImpl: ClassInitImpl + Sized { /// Each QOM type has one such class struct. /// /// The Rust implementation of methods will usually come from a trait -/// like [`ObjectImpl`]. +/// like [`ObjectImpl`] or [`DeviceImpl`](crate::device_class::DeviceImpl). pub trait ClassInitImpl { /// Function that is called after all parent class initialization /// has occurred. On entry, the virtual method pointers are set to diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index f683f94f2a5..f25904be4f6 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -17,14 +17,14 @@ pub trait DeviceImpl { /// /// If not `None`, the parent class's `realize` method is overridden /// with the function pointed to by `REALIZE`. - const REALIZE: Option = None; + const REALIZE: Option = None; /// If not `None`, the parent class's `reset` method is overridden /// with the function pointed to by `RESET`. /// /// Rust does not yet support the three-phase reset protocol; this is /// usually okay for leaf classes. - const RESET: Option = None; + const RESET: Option = None; /// An array providing the properties that the user can set on the /// device. Not a `const` because referencing statics in constants @@ -41,6 +41,30 @@ fn vmsd() -> Option<&'static VMStateDescription> { } } +/// # Safety +/// +/// This function is only called through the QOM machinery and +/// the `impl_device_class!` macro. +/// We expect the FFI user of this function to pass a valid pointer that +/// can be downcasted to type `T`. We also expect the device is +/// readable/writeable from one thread at any time. +unsafe extern "C" fn rust_realize_fn(dev: *mut DeviceState, _errp: *mut *mut Error) { + assert!(!dev.is_null()); + let state = dev.cast::(); + T::REALIZE.unwrap()(unsafe { &mut *state }); +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer that +/// can be downcasted to type `T`. We also expect the device is +/// readable/writeable from one thread at any time. +unsafe extern "C" fn rust_reset_fn(dev: *mut DeviceState) { + assert!(!dev.is_null()); + let state = dev.cast::(); + T::RESET.unwrap()(unsafe { &mut *state }); +} + /// # Safety /// /// We expect the FFI user of this function to pass a valid pointer that @@ -53,11 +77,11 @@ fn vmsd() -> Option<&'static VMStateDescription> { let mut dc = ::core::ptr::NonNull::new(klass.cast::()).unwrap(); unsafe { let dc = dc.as_mut(); - if let Some(realize_fn) = ::REALIZE { - dc.realize = Some(realize_fn); + if ::REALIZE.is_some() { + dc.realize = Some(rust_realize_fn::); } - if let Some(reset_fn) = ::RESET { - bindings::device_class_set_legacy_reset(dc, Some(reset_fn)); + if ::RESET.is_some() { + bindings::device_class_set_legacy_reset(dc, Some(rust_reset_fn::)); } if let Some(vmsd) = ::vmsd() { dc.vmsd = vmsd; From patchwork Wed Dec 11 16:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903883 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 AD169E7717D for ; Wed, 11 Dec 2024 16:42:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaQ-0003nX-Nl; Wed, 11 Dec 2024 11:29:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaM-0003a1-Ox for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaK-0000hi-Lg for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934552; 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=1QBVWKJK/+NNxfBQypJGp9jx0dxljKYnV/yzXgDBlBg=; b=BQu6IjlijW/FX1vaJimyN1xJsEEs0+yeerlSaZwsdFbtMYufgm1ftEyOVtq680gKxDy70Q Ee3XdqWf5wH3xqwSwW8n6XWCeXSFmKudnkp/JOFanhEhuJac3+V1aEd2EQUxJpIRRibJ2b Zz7br6Wf0MuuiRfDrmpc+RA9Krs9Sf8= 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-332-GT7O1lEBOjG7EmPlLKyQ_w-1; Wed, 11 Dec 2024 11:29:10 -0500 X-MC-Unique: GT7O1lEBOjG7EmPlLKyQ_w-1 X-Mimecast-MFC-AGG-ID: GT7O1lEBOjG7EmPlLKyQ_w Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-434f3398326so4673915e9.0 for ; Wed, 11 Dec 2024 08:29:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934549; x=1734539349; 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=1QBVWKJK/+NNxfBQypJGp9jx0dxljKYnV/yzXgDBlBg=; b=qkmsonS35heVDNMLoEtO0VxfKhNVu6TA0LL1RGY1Eqy7oUgqcrgUqinjznVz4VUTtF 6ycmPGBubiEmUZB59lemfdFdB9158N/ghZt0Bf/ygGeUixGCcNPZvQYvdbgprZQLfadt Q0SlEE2+Yw7u6qdb0aHYOUkx1HSDkQTP3Rq05NYhkrTGeVzT8Yh/TEHSLq6Wqz0LLBwR zlABvEL2TLkrULgwit49oefnSk/PJDcbK+Qe9Y3K65JW2LAmkH4zxgJBLyfDLpZRF9iE puBofciP6+w0pTCtDLpnH8qYTzTnqTJ5aje89bIUsQpDyVfAfO5fg1ZCmFcZcZg+RQq7 QnQg== X-Gm-Message-State: AOJu0YwEXdrtOFNbRKlHapdke9Wr+KqjJ1XqjPlbgxr5sCmwycwL++Pe v4j15D7yXcHTjtxp+uQ4SfSxnK48TiLjd9sUqBSDg/CiFlOj+hfuPVe076XuvQUTVuDOqh2gHFt 8TaVqxThXKwWsVVcjJ5uYc2xz5LOtThi7nBrY8/u4fQ4RjMc/8sf99Czx0SzDeRaAxHLQQT69EY H0Y0yRwp5uTxJ+PAY1C3o2lDR8knZJ43OqFaT8 X-Gm-Gg: ASbGncun/+6nfWvP4f6OLRbLSoFe42VahUcmZEypiaj4AKeCwHCdVY9A626DzPFMMxo 6KCZnSXKYVXn5lxxBzY/75xtAgQaQoH/b5Obzjnw7XWt5EQUbVFNo9jEewywAg1kRowVMjYcIvG Be9o7qXt9GM14+sGKYYvTKrX9Yp/qTVXMDADli5teqY59691QJXoPEEkibWxoni7esOrCI6LLe+ Wx/BsW4ibslMpQht4MybJvY8yipQWVdnZA1CyLEF7kQ97tgGjt28CiK X-Received: by 2002:a05:600c:4896:b0:434:92f8:54a8 with SMTP id 5b1f17b1804b1-4361c49e385mr23250185e9.0.1733934548968; Wed, 11 Dec 2024 08:29:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/0FUuNXzvBFFDMbZiq4wYyOi0MyEdKbETCvqLZuXfqA+lUBuGNdTvOa3FP0wZjltXKn9mLw== X-Received: by 2002:a05:600c:4896:b0:434:92f8:54a8 with SMTP id 5b1f17b1804b1-4361c49e385mr23250035e9.0.1733934548451; Wed, 11 Dec 2024 08:29:08 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434f43aedb2sm128912535e9.41.2024.12.11.08.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 47/49] rust: qom: move bridge for TypeInfo functions out of pl011 Date: Wed, 11 Dec 2024 17:27:17 +0100 Message-ID: <20241211162720.320070-48-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Allow the ObjectImpl trait to expose Rust functions that avoid raw pointers (though INSTANCE_INIT for example is still unsafe). ObjectImpl::TYPE_INFO adds thunks around the functions in ObjectImpl. While at it, document `TypeInfo`. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 40 +++++++-------------- rust/qemu-api/src/definitions.rs | 61 +++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 56403c36609..b9f8fb134b5 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -110,7 +110,7 @@ impl ObjectImpl for PL011State { type Class = PL011Class; const TYPE_NAME: &'static CStr = crate::TYPE_PL011; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_SYS_BUS_DEVICE); - const INSTANCE_INIT: Option = Some(pl011_init); + const INSTANCE_INIT: Option = Some(Self::init); } #[repr(C)] @@ -615,19 +615,6 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { } } -/// # Safety -/// -/// 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. -pub unsafe extern "C" fn pl011_init(obj: *mut Object) { - unsafe { - debug_assert!(!obj.is_null()); - let mut state = NonNull::new_unchecked(obj.cast::()); - state.as_mut().init(); - } -} - #[repr(C)] #[derive(Debug, qemu_api_macros::Object)] /// PL011 Luminary device model. @@ -640,19 +627,16 @@ pub struct PL011LuminaryClass { _inner: [u8; 0], } -/// Initializes a pre-allocated, unitialized instance of `PL011Luminary`. -/// -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that has -/// the same size as [`PL011Luminary`]. We also expect the device is -/// readable/writeable from one thread at any time. -pub unsafe extern "C" fn pl011_luminary_init(obj: *mut Object) { - unsafe { - debug_assert!(!obj.is_null()); - let mut state = NonNull::new_unchecked(obj.cast::()); - let state = state.as_mut(); - state.parent_obj.device_id = DeviceId::Luminary; +impl PL011Luminary { + /// Initializes a pre-allocated, unitialized instance of `PL011Luminary`. + /// + /// # Safety + /// + /// We expect the FFI user of this function to pass a valid pointer, that + /// has the same size as [`PL011Luminary`]. We also expect the device is + /// readable/writeable from one thread at any time. + unsafe fn init(&mut self) { + self.parent_obj.device_id = DeviceId::Luminary; } } @@ -660,7 +644,7 @@ impl ObjectImpl for PL011Luminary { type Class = PL011LuminaryClass; const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY; const PARENT_TYPE_NAME: Option<&'static CStr> = Some(crate::TYPE_PL011); - const INSTANCE_INIT: Option = Some(pl011_luminary_init); + const INSTANCE_INIT: Option = Some(Self::init); } impl DeviceImpl for PL011Luminary {} diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 0467e6290e0..f2970758986 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -8,16 +8,63 @@ use crate::bindings::{Object, ObjectClass, TypeInfo}; +unsafe extern "C" fn rust_instance_init(obj: *mut Object) { + // SAFETY: obj is an instance of T, since rust_instance_init + // is called from QOM core as the instance_init function + // for class T + unsafe { T::INSTANCE_INIT.unwrap()(&mut *obj.cast::()) } +} + +unsafe extern "C" fn rust_instance_post_init(obj: *mut Object) { + // SAFETY: obj is an instance of T, since rust_instance_post_init + // is called from QOM core as the instance_post_init function + // for class T + // + // FIXME: it's not really guaranteed that there are no backpointers to + // obj; it's quite possible that they have been created by instance_init(). + // The receiver should be &self, not &mut self. + T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::() }) +} + /// Trait a type must implement to be registered with QEMU. +/// +/// # Safety +/// +/// - the struct must be `#[repr(C)]` +/// +/// - `Class` and `TYPE` must match the data in the `TypeInfo` (this is +/// automatic if the class is defined via `ObjectImpl`). +/// +/// - the first field of the struct must be of the instance struct corresponding +/// to the superclass declared as `PARENT_TYPE_NAME` pub trait ObjectImpl: ClassInitImpl + Sized { + /// The QOM class object corresponding to this struct. Not used yet. type Class; + + /// The name of the type, which can be passed to `object_new()` to + /// generate an instance of this type. const TYPE_NAME: &'static CStr; + + /// The parent of the type. This should match the first field of + /// the struct that implements `ObjectImpl`: const PARENT_TYPE_NAME: Option<&'static CStr>; + + /// Whether the object can be instantiated const ABSTRACT: bool = false; - const INSTANCE_INIT: Option = None; - const INSTANCE_POST_INIT: Option = None; const INSTANCE_FINALIZE: Option = None; + /// Function that is called to initialize an object. The parent class will + /// have already been initialized so the type is only responsible for + /// initializing its own members. + /// + /// FIXME: The argument is not really a valid reference. `&mut + /// MaybeUninit` would be a better description. + const INSTANCE_INIT: Option = None; + + /// Function that is called to finish initialization of an object, once + /// `INSTANCE_INIT` functions have been called. + const INSTANCE_POST_INIT: Option = None; + const TYPE_INFO: TypeInfo = TypeInfo { name: Self::TYPE_NAME.as_ptr(), parent: if let Some(pname) = Self::PARENT_TYPE_NAME { @@ -27,8 +74,14 @@ pub trait ObjectImpl: ClassInitImpl + Sized { }, instance_size: core::mem::size_of::(), instance_align: core::mem::align_of::(), - instance_init: Self::INSTANCE_INIT, - instance_post_init: Self::INSTANCE_POST_INIT, + instance_init: match Self::INSTANCE_INIT { + None => None, + Some(_) => Some(rust_instance_init::), + }, + instance_post_init: match Self::INSTANCE_POST_INIT { + None => None, + Some(_) => Some(rust_instance_post_init::), + }, instance_finalize: Self::INSTANCE_FINALIZE, abstract_: Self::ABSTRACT, class_size: core::mem::size_of::(), From patchwork Wed Dec 11 16:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903852 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 AF1EAE77182 for ; Wed, 11 Dec 2024 16:36:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaT-0003wt-3h; Wed, 11 Dec 2024 11:29:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaQ-0003lb-0g for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaN-0000j8-Ua for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934555; 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=goSFoLP9ZZzBeb1oQrmWlXZpCZrwinc7Rd5f+O1pfS8=; b=EGmdUqJaNGjq0j6jmDYPMx2LQKn5BKltNKQ3Cp0Gk8Jm11qdEi+1g/vJagXsDXapFWoA7h 35vLd0TtyhL6T2hLUlTSscfiFSbwmzeM5ONGIOt1AXAVQkigtS8ALNWeNY/E5v4Fi/8uvg 36CEG7UUngeWtI6ruZbcJyTyUTdXnsE= 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-472-VOG3BQeGM0C2xWZCKYqs1Q-1; Wed, 11 Dec 2024 11:29:13 -0500 X-MC-Unique: VOG3BQeGM0C2xWZCKYqs1Q-1 X-Mimecast-MFC-AGG-ID: VOG3BQeGM0C2xWZCKYqs1Q Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385df115288so2972721f8f.2 for ; Wed, 11 Dec 2024 08:29:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934552; x=1734539352; 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=goSFoLP9ZZzBeb1oQrmWlXZpCZrwinc7Rd5f+O1pfS8=; b=mLp49fFJZkSk1QoDE9w/0krxMFGSGQsm2J8CqaIegrYqtWnLhIP/wC5TN2pBFquyDt EQyyoefOdUGG06y2tMyqyzuufmYcoYUapQRV8cEHjNgYy/62huStEArZHH+BLpRlJRLY 8QaWjy1MYsY9/eLrr3Fk+R5JdTzbADOLKe22pA1iGwMnc+fmxTbYbJ6bRdsvjzg4P482 JQifMPbL5eFp0HIZSEjKQk+p5ELdam/hw+kqNXmZkkJp4OXKWeMihxk3J/9pW9ve3JqV b/t0M04u/MEHFG9MI5N65kszuic+LWZDfUzVuqq2gMQDIjjMUA5k9VYhoXsUuuXJiDwe i2hQ== X-Gm-Message-State: AOJu0Yx/sbMe/32bh7oxGYODwdfgHBFtM3VmKNFTTMjPUVTcOy7ufbMo G72qFnr/FDAx50Jh1Fku6stV75aLNkfFi1rhF6GvplcYbBAAPojfphVfFZpBzGTnb0pyYdZDCKO DFIVWrUD53uWMb3F9uQa2ziVTjyGlpgbtvu54lvTFbd+27ZgOPezf3BbLuIBqocxghZUbkYAqXX arAkWScIcVJJU46ILdvO1ehmnDamejF2vXvDr2 X-Gm-Gg: ASbGnctV3XCDV7d5FArb1OROTzuSlsti2rfMO7dTtTyOL8aYq69aMCMFFJnoYTU5tew LiXu1JiamQqKDOEeLj1IrAPTP2yzIZSZSDs09tc1YDVtFeRWm7XgHZbOL5TKdtVFX60U+llowzf HJMAbJhE/d1vT/KeI4NiG4iVArvyWVjizGfq6vNUzXl3g6ylcTnxzLDTODGW4Xlqtr9Tl48qfSf lPYXCRKyIcrMv3FWJ9xILbQQufIzy1olgTpqizml56GDXmk8mpG0b0A X-Received: by 2002:a5d:47c6:0:b0:385:f062:c2df with SMTP id ffacd0b85a97d-3864ce4968emr3330992f8f.11.1733934551558; Wed, 11 Dec 2024 08:29:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVKTEij2xde+OaauMr8jeMSHVSr8tiBVX8BoCT5vhHI9fdqWO+vH9yXfdaeYkoNJZpdRO3bg== X-Received: by 2002:a5d:47c6:0:b0:385:f062:c2df with SMTP id ffacd0b85a97d-3864ce4968emr3330964f8f.11.1733934551061; Wed, 11 Dec 2024 08:29:11 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878251dbbfsm1609110f8f.97.2024.12.11.08.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 48/49] rust: qom: split ObjectType from ObjectImpl trait Date: Wed, 11 Dec 2024 17:27:18 +0100 Message-ID: <20241211162720.320070-49-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 Define a separate trait for fields that also applies to classes that are defined by C code. This makes it possible to add metadata to core classes, which has multiple uses: - it makes it possible to access the parent struct's TYPE_* for types that are defined in Rust code, and to avoid repeating it in every subclass - implementors of ObjectType will be allowed to implement the IsA<> trait and therefore to perform typesafe casts from one class to another. - in the future, an ObjectType could be created with Foo::new() in a type-safe manner, without having to pass a TYPE_* constant. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 17 ++++++++++++----- rust/qemu-api/src/definitions.rs | 27 +++++++++++++++++++++------ rust/qemu-api/src/device_class.rs | 11 ++++++----- rust/qemu-api/src/prelude.rs | 2 ++ rust/qemu-api/src/sysbus.rs | 10 ++++++++-- rust/qemu-api/tests/tests.rs | 17 +++++++++-------- 6 files changed, 58 insertions(+), 26 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index b9f8fb134b5..0ab825b1ca4 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -12,9 +12,10 @@ bindings::{self, *}, c_str, definitions::ObjectImpl, - device_class::{DeviceImpl, TYPE_SYS_BUS_DEVICE}, + device_class::DeviceImpl, impl_device_class, irq::InterruptSource, + prelude::*, }; use crate::{ @@ -106,10 +107,13 @@ pub struct PL011State { device_id: DeviceId, } -impl ObjectImpl for PL011State { +unsafe impl ObjectType for PL011State { type Class = PL011Class; const TYPE_NAME: &'static CStr = crate::TYPE_PL011; - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_SYS_BUS_DEVICE); +} + +impl ObjectImpl for PL011State { + const PARENT_TYPE_NAME: Option<&'static CStr> = Some(::TYPE_NAME); const INSTANCE_INIT: Option = Some(Self::init); } @@ -640,10 +644,13 @@ unsafe fn init(&mut self) { } } -impl ObjectImpl for PL011Luminary { +unsafe impl ObjectType for PL011Luminary { type Class = PL011LuminaryClass; const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY; - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(crate::TYPE_PL011); +} + +impl ObjectImpl for PL011Luminary { + const PARENT_TYPE_NAME: Option<&'static CStr> = Some(::TYPE_NAME); const INSTANCE_INIT: Option = Some(Self::init); } diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index f2970758986..b98a6926785 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -26,25 +26,40 @@ T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::() }) } -/// Trait a type must implement to be registered with QEMU. +/// Trait exposed by all structs corresponding to QOM objects. /// /// # Safety /// -/// - the struct must be `#[repr(C)]` +/// For classes declared in C: /// -/// - `Class` and `TYPE` must match the data in the `TypeInfo` (this is -/// automatic if the class is defined via `ObjectImpl`). +/// - `Class` and `TYPE` must match the data in the `TypeInfo`; +/// +/// - the first field of the struct must be of the instance type corresponding +/// to the superclass, as declared in the `TypeInfo` +/// +/// - likewise, the first field of the `Class` struct must be of the class type +/// corresponding to the superclass +/// +/// For classes declared in Rust and implementing [`ObjectImpl`]: +/// +/// - the struct must be `#[repr(C)]`; /// /// - the first field of the struct must be of the instance struct corresponding -/// to the superclass declared as `PARENT_TYPE_NAME` -pub trait ObjectImpl: ClassInitImpl + Sized { +/// to the superclass, as declared in `ObjectImpl::PARENT_TYPE_NAME` +/// +/// - likewise, the first field of the `Class` must be of the class struct +/// corresponding to the superclass +pub unsafe trait ObjectType: Sized { /// The QOM class object corresponding to this struct. Not used yet. type Class; /// The name of the type, which can be passed to `object_new()` to /// generate an instance of this type. const TYPE_NAME: &'static CStr; +} +/// Trait a type must implement to be registered with QEMU. +pub trait ObjectImpl: ObjectType + ClassInitImpl { /// The parent of the type. This should match the first field of /// the struct that implements `ObjectImpl`: const PARENT_TYPE_NAME: Option<&'static CStr>; diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index f25904be4f6..03d03feee83 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -6,6 +6,7 @@ use crate::{ bindings::{self, DeviceClass, DeviceState, Error, ObjectClass, Property, VMStateDescription}, + prelude::*, zeroable::Zeroable, }; @@ -146,8 +147,8 @@ macro_rules! declare_properties { }; } -// workaround until we can use --generate-cstr in bindgen. -pub const TYPE_DEVICE: &CStr = - unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_DEVICE) }; -pub const TYPE_SYS_BUS_DEVICE: &CStr = - unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) }; +unsafe impl ObjectType for bindings::DeviceState { + type Class = bindings::DeviceClass; + const TYPE_NAME: &'static CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_DEVICE) }; +} diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index a39e228babf..1b8677b2d9a 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -6,3 +6,5 @@ pub use crate::cell::BqlCell; pub use crate::cell::BqlRefCell; + +pub use crate::definitions::ObjectType; diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index 4e192c75898..5ee068541cf 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -2,11 +2,17 @@ // Author(s): Paolo Bonzini // SPDX-License-Identifier: GPL-2.0-or-later -use std::ptr::addr_of; +use std::{ffi::CStr, ptr::addr_of}; pub use bindings::{SysBusDevice, SysBusDeviceClass}; -use crate::{bindings, cell::bql_locked, irq::InterruptSource}; +use crate::{bindings, cell::bql_locked, irq::InterruptSource, prelude::*}; + +unsafe impl ObjectType for SysBusDevice { + type Class = SysBusDeviceClass; + const TYPE_NAME: &'static CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) }; +} impl SysBusDevice { /// Return `self` cast to a mutable pointer, for use in calls to C code. diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index b8b12a40422..1d027dd6527 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -5,12 +5,8 @@ use std::ffi::CStr; use qemu_api::{ - bindings::*, - c_str, declare_properties, define_property, - definitions::ObjectImpl, - device_class::{self, DeviceImpl}, - impl_device_class, - zeroable::Zeroable, + bindings::*, c_str, declare_properties, define_property, definitions::ObjectImpl, + device_class::DeviceImpl, impl_device_class, prelude::*, zeroable::Zeroable, }; #[test] @@ -46,10 +42,15 @@ pub struct DummyClass { ), } - impl ObjectImpl for DummyState { + unsafe impl ObjectType for DummyState { type Class = DummyClass; const TYPE_NAME: &'static CStr = c_str!("dummy"); - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); + } + + impl ObjectImpl for DummyState { + const PARENT_TYPE_NAME: Option<&'static CStr> = + Some(::TYPE_NAME); + const ABSTRACT: bool = false; } impl DeviceImpl for DummyState { From patchwork Wed Dec 11 16:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13903825 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 0E46FE7717D for ; Wed, 11 Dec 2024 16:30:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPaX-00045U-8Q; Wed, 11 Dec 2024 11:29:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaS-0003tS-06 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPaP-0000ja-H5 for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:29:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934556; 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=vIfu49MPuojczIFu4d92ofEWS3l26By9bJ1+rMMpb2o=; b=O5AVtBGgzVREWQjWxFrY45tnpc2dT+oAndxICIGDR/02ug6cV8xT7dbV1sQAwn8EaKWUnL FrSLk2J6NvckTkiZ4k2gb8xsGTo/AHfSA34W4EqYqYDfYtdIxC3vGuTn2i0DoZq7VHKY21 GB8QtQdPNJXQlXioeWa499dKb2wENgU= 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-64--x7Rf_KcPFe9dnmh9cr6ew-1; Wed, 11 Dec 2024 11:29:15 -0500 X-MC-Unique: -x7Rf_KcPFe9dnmh9cr6ew-1 X-Mimecast-MFC-AGG-ID: -x7Rf_KcPFe9dnmh9cr6ew Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361efc9d23so9704985e9.3 for ; Wed, 11 Dec 2024 08:29:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934554; x=1734539354; 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=vIfu49MPuojczIFu4d92ofEWS3l26By9bJ1+rMMpb2o=; b=tp0Rt9weM/MnKlecp2md66n73dEdcG/jOZ0Kd14F2j6Oa6bBTH//beuHjsPeEi+DEv tpKmpZvf0jFos7PpGjngMJeLF9xeMhQrPA8ll+TbGeZ57kFNV5i1/IOE+ZbrOekEyzBS atvqISWVZbl3HcDjt8GJxuH0d7WHAaW/c+M1cR77Y1iPYV/F40dATabgJ93osX0ZSxkz UKN1txDNFLvksZFT0pigKEEL50NeFSzaB06Nam4yRQfMZl5fbftf/sBhmBem9SyArcad GAVPl19Qh1A7Pgjs4ywWRevWSufrQD7RE3nJdJkUl6XYFIiljC2gQRD7qseh4JJa5zI+ 9s7A== X-Gm-Message-State: AOJu0YwjDLMQe4+MgYlvroFkb8h1o4YMeIwBEfeIvv4pVMXdGcHe5yXV Q5JLVNJZjqonOQ9aRxAJfuQf/jhwg9d1gLMhhINY01e5UaWe0iZbmtCsjtqrEneN1pkWRJVF8Ly lIB7F1FQu9fc1a0Gh7EgYTm9khjWWQgEZBoZ1G1NaiVlR7dG5CodUL3VtzmOOiyr4n5f6R6Pal+ RU5tJqpXfFjH2JClFHrXnbXpvQLFuffv9pmZqH X-Gm-Gg: ASbGncvKUlB9xq3F0yBPvUPxPTJ+6zRfV4MOSe7OntQY69k7Hh7PfROlyy4d5ws0MIe pcslNifnkzpC8oRaz7Jl34HcmNO9MzJ8lnMx+cClHpLalYaWGY8knn4XcMYtP977fggBosK4y2p w+L5egpHvKs4AFivXE65YysZcUlQ6ypMYRRhRxmqH3hhlKJMK8vAl5/tqNXmUH7p+4K9hkzVjct jxcTe9SLBz1/o72OYwUtxqv06RVkuFw8YXI+S49FQQucMKjlIN3slIU X-Received: by 2002:a05:600c:2319:b0:436:2238:97f6 with SMTP id 5b1f17b1804b1-436223897fcmr6273345e9.1.1733934553704; Wed, 11 Dec 2024 08:29:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNbvpuYBMio39ieukd9leaknbfKPEdcMKwzMEi92XgaDVHG87b3v/ao3VetX6ok6YmdlcqgA== X-Received: by 2002:a05:600c:2319:b0:436:2238:97f6 with SMTP id 5b1f17b1804b1-436223897fcmr6273085e9.1.1733934553269; Wed, 11 Dec 2024 08:29:13 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436222ad969sm3767995e9.44.2024.12.11.08.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:29:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 49/49] rust: qom: change the parent type to an associated type Date: Wed, 11 Dec 2024 17:27:19 +0100 Message-ID: <20241211162720.320070-50-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, 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=-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 duplicated code to retrieve the QOM type strings from the Rust type. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++++-- rust/qemu-api/src/definitions.rs | 12 ++++-------- rust/qemu-api/tests/tests.rs | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 0ab825b1ca4..3e29442a625 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -113,7 +113,8 @@ unsafe impl ObjectType for PL011State { } impl ObjectImpl for PL011State { - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(::TYPE_NAME); + type ParentType = SysBusDevice; + const INSTANCE_INIT: Option = Some(Self::init); } @@ -650,7 +651,8 @@ unsafe impl ObjectType for PL011Luminary { } impl ObjectImpl for PL011Luminary { - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(::TYPE_NAME); + type ParentType = PL011State; + const INSTANCE_INIT: Option = Some(Self::init); } diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index b98a6926785..df91a2e31a9 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -45,10 +45,10 @@ /// - the struct must be `#[repr(C)]`; /// /// - the first field of the struct must be of the instance struct corresponding -/// to the superclass, as declared in `ObjectImpl::PARENT_TYPE_NAME` +/// to the superclass, which is `ObjectImpl::ParentType` /// /// - likewise, the first field of the `Class` must be of the class struct -/// corresponding to the superclass +/// corresponding to the superclass, which is `ObjectImpl::ParentType::Class`. pub unsafe trait ObjectType: Sized { /// The QOM class object corresponding to this struct. Not used yet. type Class; @@ -62,7 +62,7 @@ pub unsafe trait ObjectType: Sized { pub trait ObjectImpl: ObjectType + ClassInitImpl { /// The parent of the type. This should match the first field of /// the struct that implements `ObjectImpl`: - const PARENT_TYPE_NAME: Option<&'static CStr>; + type ParentType: ObjectType; /// Whether the object can be instantiated const ABSTRACT: bool = false; @@ -82,11 +82,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl { const TYPE_INFO: TypeInfo = TypeInfo { name: Self::TYPE_NAME.as_ptr(), - parent: if let Some(pname) = Self::PARENT_TYPE_NAME { - pname.as_ptr() - } else { - core::ptr::null_mut() - }, + parent: Self::ParentType::TYPE_NAME.as_ptr(), instance_size: core::mem::size_of::(), instance_align: core::mem::align_of::(), instance_init: match Self::INSTANCE_INIT { diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 1d027dd6527..278efe967fe 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -48,8 +48,7 @@ unsafe impl ObjectType for DummyState { } impl ObjectImpl for DummyState { - const PARENT_TYPE_NAME: Option<&'static CStr> = - Some(::TYPE_NAME); + type ParentType = DeviceState; const ABSTRACT: bool = false; }