From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534843; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Z6x4w5AeDkkY3Hq1L9isnf2eSNY/3jLKXmG967A3bM7e2Mbi9SZrrf+VajnVIJ7eSar3s7bKzE0UQjs3tmwTQSBU95fDMutDa9lmpq12qkTcBEtw7iYtyuJozsuMTPpgMWJGwxLg8hY9GNmQTCFjTbw5SmIu78jR2MOJi0MzPF4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534843;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=B10SRZRYGA29q+/7m3S/Wftl9lQcNQLNubrEXoeQmEM=;
	b=YPnPqrphXD8Cez4GmMMP0z2Bk3wcU66m40r6YNX5h1w24gFjl6kBtsKTwXUFip3kgcVd6HUfuHnduHY0ku9o8yhu1TTvXhj+GggO7SJjvRnXieVCWHJRDartbSnVH6A0bVga0nzn8T3pTQxP1VL5CUrmMfgY7V3bxqpzDHo9Oas=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534843931803.4105713185389;
 Fri, 10 Jan 2025 10:47:23 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK20-0000CO-Ng; Fri, 10 Jan 2025 13:46: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 <pbonzini@redhat.com>)
 id 1tWK1g-0000Ac-1P
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46: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 <pbonzini@redhat.com>)
 id 1tWK1d-00014e-RZ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:31 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-513-02Fb-KDwNqmPySjxmQgZPA-1; Fri, 10 Jan 2025 13:46:26 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d3d6d924c1so2459617a12.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:25 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903bb465sm1931155a12.36.2025.01.10.10.46.23
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:23 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534787;
 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=B10SRZRYGA29q+/7m3S/Wftl9lQcNQLNubrEXoeQmEM=;
 b=Vw2cJpMN/nR19nfaaa3AAQlm+UIFqd2g6mqUeR7gerwCKoC4ooT9JuAUUjxWYMvrOtI8I2
 UF209CwjGqO/MMlwp3V8vwdcehomSCr8f5Ka87Pnny4hAD1Ij2ooNPoe4YqEwfyba4y84a
 mxnJaVl+Vni3zGTUivG4H/gXbPBvGdI=
X-MC-Unique: 02Fb-KDwNqmPySjxmQgZPA-1
X-Mimecast-MFC-AGG-ID: 02Fb-KDwNqmPySjxmQgZPA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534784; x=1737139584;
 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=B10SRZRYGA29q+/7m3S/Wftl9lQcNQLNubrEXoeQmEM=;
 b=FIduveJL9ghVHEp09yiZCg0LmnurUFDMEa24PJrrvdv5uuYDpXbO1ci6KQpuwybOl2
 b6DNcLR9SMje76+ihGA6HktlMpsPbNAYJUmt8oak9zNifzo+ziH6Zoa4AvdUDZRkRlDw
 iSXNqnxgIljjKIYszS8I6L0XyqDrnnwlADr0S5wrMcMd8Tkt/z54r6nxY5XE1gJdUbU8
 3Av2OoXA6jxnfuf2QKqYUX10u5wecyC4UMBxW6lBMeKCsMpDSon6eDzPsccM0FP3aPai
 uoPwgp0xjslOcEodB6FkUB5eoAVHk0znsqgi+zRrtdPr+go5zlvzDD4pQTsxctq/l5Yc
 xNWQ==
X-Gm-Message-State: AOJu0YwzHPpkXOg0unJ5GdPFGIME9FC4+I1G9KlPpuePbvDymVdiCkgJ
 /7ErN9Y1yA+5a1nLg3fWEuWo7wmoE37/yBISxj6F2ci2/Zo9Ydx0hVlz57753YZmYQDX22BqT//
 NZ3BHF063H7BVCPVpb1XKXJcpUySW56wocTWbhXrB+TE/iZyez5mrMAa6d4LYstBkBrIBU2/oPi
 jwXVMxOi9++N61FWq8nTLNXNykq71o8MBZ3g03nlI=
X-Gm-Gg: ASbGncs+xIFLQfXr0q9Oov1ZGNQ9DvfCFHJGHk/RDst3FBltN+8jWYBh7Mz9eBfk05+
 A56lyySDjH26VPoR3HSkvAycLQDKw2z5blNP+GhEf6N6EGXP7Fz7lVf7aqFd+Tf/Oy2ZXPpoAWV
 4qIUucheYkdV6CQVAJ0HnG9fGFnoCovxl6Z3SVdZIY4rYEgqZG1jaPYaeBdZXM1XJubHvYt3wkW
 Z3TZkkILzrFJkmSsl07J61tmyvNX9dRjpA1PZZEMndPwdb9QcbFiB9WSTg=
X-Received: by 2002:a05:6402:3550:b0:5d0:fc80:c4d1 with SMTP id
 4fb4d7f45d1cf-5d972e0eecdmr10426061a12.14.1736534784564;
 Fri, 10 Jan 2025 10:46:24 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHEdDNrmT5oZiFA9sw23LLLZ+h7PTot/o+XeArjlRl5ERLCBKatzG0LFomgxPoAx2u68dszUA==
X-Received: by 2002:a05:6402:3550:b0:5d0:fc80:c4d1 with SMTP id
 4fb4d7f45d1cf-5d972e0eecdmr10426038a12.14.1736534784132;
 Fri, 10 Jan 2025 10:46:24 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Bernhard Beschow <shentey@gmail.com>
Subject: [PULL 01/38] rust: fix --enable-debug-mutex
Date: Fri, 10 Jan 2025 19:45:42 +0100
Message-ID: <20250110184620.408302-2-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534844931019000
Content-Type: text/plain; charset="utf-8"

--feature is an option for cargo but not for rustc.

Reported-by: Bernhard Beschow <shentey@gmail.com>
Reviewed-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
index ccb20f38c1d..9425ba7100c 100644
--- a/rust/qemu-api/meson.build
+++ b/rust/qemu-api/meson.build
@@ -7,7 +7,7 @@ if rustc.version().version_compare('>=3D1.77.0')
   _qemu_api_cfg +=3D ['--cfg', 'has_offset_of']
 endif
 if get_option('debug_mutex')
-  _qemu_api_cfg +=3D ['--feature', 'debug_cell']
+  _qemu_api_cfg +=3D ['--cfg', 'feature=3D"debug_cell"']
 endif
=20
 _qemu_api_rs =3D static_library(
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534984; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ReWW8djpPyp4pT9MjTg0C2Q7JouU8EnQVIFXqX3HbE82zPofmxhASz6VUf/7ftyTNlL21l156m6joFh3UKN0noKn2Gr4f0VTBEbb3BESpDgeWyJAhPvhinrVFZiHr5/8BDv8qe14wD4LXMa3r6bGyyiRNfPSoDuktw8lwd+QUVE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534984;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=Bvl+J5OWotTQVBe9dRZtuqKB1fUaMLXq6FgWP0i2SqQ=;
	b=DlJ8j3h899n33V9WpK8PXTDDc26JK1FeeI39AKk+J/dSTlD5emn8Z6NOlBzz9xjGEFHOh/5NeMLlFpRW0q4COKIHIkUuMhZcc9AiLwSIB7fIUGE/Ar/gLqVNn/nwi8ryCl1ivDnP5M9AZtnyO+vgOy4838Qa7Iltl3Vmx0jU2HU=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534984290336.0813173635448;
 Fri, 10 Jan 2025 10:49:44 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2W-0000NJ-Ot; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1l-0000BD-Lo
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:39 -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 <pbonzini@redhat.com>)
 id 1tWK1f-00014l-Nz
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:33 -0500
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-6-aJMt2ZhWPM6K5hMeXB7FMQ-1; Fri, 10 Jan 2025 13:46:28 -0500
Received: by mail-ej1-f70.google.com with SMTP id
 a640c23a62f3a-aaf8f016bb1so201318366b.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:28 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c905f04fsm193136266b.27.2025.01.10.10.46.25
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:25 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534790;
 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=Bvl+J5OWotTQVBe9dRZtuqKB1fUaMLXq6FgWP0i2SqQ=;
 b=AVOwjwfctDqborLU+NQHemSECpbDguGEZ5Jwug8g+4JYVsuL+CzzbkcbTlytcrfELxI/P2
 vYnv+0BlDbl/LlptF+03N6NQ+nPGmLhL7okJHr5LIXZaubtLM0Mu+Ydwp+pNOWGheoldQW
 V7LgyXGpx2cqH9YFgeGi2oSAD2ApNxs=
X-MC-Unique: aJMt2ZhWPM6K5hMeXB7FMQ-1
X-Mimecast-MFC-AGG-ID: aJMt2ZhWPM6K5hMeXB7FMQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534787; x=1737139587;
 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=Bvl+J5OWotTQVBe9dRZtuqKB1fUaMLXq6FgWP0i2SqQ=;
 b=bC9VS2r+kzx0A0P5+b/457a1bxXbD/qOiwhKXfbIf61/8yuVqMKoKYcNE175w/z675
 DCzZ0edMV7hDDvS/igSrBx1Se5Z8YnEeC4x820EKot58I/bh4qK0n/U5cCuM0qwePdyk
 qdzRGQA5powzHHoa9oiuEkY30pe+AYV0XB7rVnKqvzq1QVDkuo822xAZCV4CorOJoc+k
 SZv/bESk2YQJ6RCNPw1uf88pXtiUEI4DFu6/ibV4frsr/RxWm335XrYuv3YRvVdQlLS7
 Wt2K1Tyvj7D9ATUKlqy6JIbbIy5jcevHek6QgWtv7Zv/ArBA5ER/sq8rzZshNdpdJ+ZN
 ZUwg==
X-Gm-Message-State: AOJu0YyZuRocyfJotzGsCLGqqS1urpBEPvCdAcwrrM2zHk6O1wZvhdVe
 c59AO23jWyd36r/xSnxtOVUFJRqrMTKSFMkDxJUM1zFlY/+fdsnKD3da/jsLGQLuXqq1uM528DZ
 +j/c0/dbbBFlYLcqWmBFz6l3iJ9ZaSvK0hrtXpDWkXFTiGvPtKW4p2AJPslwwnLRsUmq8DgMmZ5
 8uI4wLLwFrp/v2jGrkr7VSnU6eQc+GozueOOZjB9A=
X-Gm-Gg: ASbGnctLpn3nNF+0QV7n0sxknmky9IzhcTDO+5SuLIp00CusedcITeARo1cGH9pILcq
 jlBxshdx7/vLQcTokVynArqvxx1E+DM9utaBq5wx+KKJMfcLzTotNGaz61Rfb7b0dG0l1vBI0oF
 TEIoLYwHN92V4pfc+EtRBftUv90EQ8xR1/GgJU2dY2PZ7mANESAgkwVsW5T6U3aG/H4+tqgNvd8
 tha0kdFswLhBCq9SRGwCqrDxlrj4s9L8xICCgF4a2hKBJTRhGY7JjV2Zk4=
X-Received: by 2002:a17:907:3f09:b0:aae:fb7c:50df with SMTP id
 a640c23a62f3a-ab2ab748e82mr991966266b.36.1736534787122;
 Fri, 10 Jan 2025 10:46:27 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IETwfDyaxMZrGSGbeuDJn19ywgfYAs+GwWmw7sKA6LISg7Ak3qlCOW94eLTAfAMu3D8MFiSzg==
X-Received: by 2002:a17:907:3f09:b0:aae:fb7c:50df with SMTP id
 a640c23a62f3a-ab2ab748e82mr991964366b.36.1736534786652;
 Fri, 10 Jan 2025 10:46:26 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 02/38] rust: add --check-cfg test to rustc arguments
Date: Fri, 10 Jan 2025 19:45:43 +0100
Message-ID: <20250110184620.408302-3-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534985882116600
Content-Type: text/plain; charset="utf-8"

rustc will check that every reachable #[cfg] matches a list of
the expected config names and values.  Recent versions of rustc are
also complaining about #[cfg(test)], even if it is basically a standard
part of the language.  So, always allow it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/rust/rustc_args.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py
index 5525b3886fa..d79dc6d81f1 100644
--- a/scripts/rust/rustc_args.py
+++ b/scripts/rust/rustc_args.py
@@ -215,6 +215,8 @@ def main() -> None:
=20
     if rustc_version >=3D (1, 80):
         if args.lints:
+            print("--check-cfg")
+            print("test")
             for cfg in sorted(cargo_toml.check_cfg):
                 print("--check-cfg")
                 print(cfg)
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534971; cv=none;
	d=zohomail.com; s=zohoarc;
	b=GMcBR5ARoTVGfSff61I1XXm1KfBzr1q4bnOvgjRo9mm/6nsVUXncxV/kIrUb5suaNhQVkteIV+4HaCWZK/fyJOrX1Xqa3ByjwUIY9nWiY0BaZ5838a2jzAI07YIwWlT6nIRiC+Q23xIo0ydkOt4RPQ4DZsx1YdkAz1Pp9uTPm1g=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534971;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=K+ve94DKbTOVXrMnq6VI7ki09hbI6XC3Vzt03Al6AE8=;
	b=HqllBgKM+GuMoSxZcHMvk3GIgp75zqoasX+mbPHtFXaa6KX7Ls83Hqskaxev/29m28reZm8nSkIPEr0Kv2Wwsmnto3rCZoXnfUfXcqj61ptzIx+S1FXkULr/SaZUQrSxVeM91ldzJ+Q7dUFmwbzrzjCo93193qkxUl6knGczd/U=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534971343339.79813180331223;
 Fri, 10 Jan 2025 10:49:31 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2d-0000PH-FG; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1p-0000Bf-K8
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:48 -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 <pbonzini@redhat.com>)
 id 1tWK1k-000150-4s
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:39 -0500
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-131-IACNSdQNNLeHXMPpA1e-yQ-1; Fri, 10 Jan 2025 13:46:31 -0500
Received: by mail-ej1-f70.google.com with SMTP id
 a640c23a62f3a-aa66f6ce6bfso197494366b.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:31 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90db325sm195677166b.65.2025.01.10.10.46.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:27 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534793;
 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=K+ve94DKbTOVXrMnq6VI7ki09hbI6XC3Vzt03Al6AE8=;
 b=hKq8ZdEnJHr9FrLZQvwu7/N3RrHBW21LuQAgH0zL3xRCETdYP2qbGDzdePC5YKFGsoJpVV
 hheWC6WtiToCf+gXziIsw/JQAcBeC92oHpTqzL8kkF+1fbyEfASHFiVXb4PB42M6lQo1nv
 UxNTJsxlPFZgBeb8TQ+X6Oy1sC2ZGIE=
X-MC-Unique: IACNSdQNNLeHXMPpA1e-yQ-1
X-Mimecast-MFC-AGG-ID: IACNSdQNNLeHXMPpA1e-yQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534789; x=1737139589;
 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=K+ve94DKbTOVXrMnq6VI7ki09hbI6XC3Vzt03Al6AE8=;
 b=kM9tbVw5IVA+o9aVZgO8QaIL81DrpROp8WPSaY1pkIsRfK8SjweT9oau2BNDEdIQ1R
 9EE9cSbsXY4CkJgqbwsMaDnRX3zk3KivPsWgnomILsOIOl0YWtNL0t49O1Pc6l0WWBhp
 p9LN8e5gGrBzsUOV1CBlYGBbW7v+Ygq8+V6vdkqMjAUB2tk6klgVBmvTvq5kVlNxsTXF
 8kVmvb5fH4xj0NJiKxd5PUzQZeh5x8/da2GuNUowjIH5iGQeTyRavAfRaXjaJdghohDX
 BFZRa8PalpJ8bL0HHV622qHN7QeprHWJu4lJVu4e4OF8ZEkSow2H/+D4zVk+1vr0u+iq
 R3Kg==
X-Gm-Message-State: AOJu0Yz0SNyBgjAhuRHw9lmwnLK3P8QqooYTELkg9lsasbKK7iGLIhL5
 FLicp/zYDSqVO5K4SJmd45VDH9T0Re4PA8pDLzaFFUNht9Okqx7qUI6VNSCnXxsL/RjpBArJpj+
 Y0CqJXt9lowXOrSv9qCPzgGnT6lk9cIpKgH+c44nMMoqotBZCeVLLLUq95utAPUp6ugcpiYP7Z1
 2AcZUW58nYECWaNSbEs29GC+A2dZ5v7s42ElZmXW0=
X-Gm-Gg: ASbGncsmk/3b/Sw7EGiZh5tbrSmEA1+SDhpq3g/lZOPJuJbV41Srk2scHvUkXCZft6c
 BVhtoeZio1ZEAUrBJ04Gm0TweUNAhHCKzM2fY4ZrGHRnZ2kyDT03kO/5XVtyk1QBZdgpLit5pzI
 gpkjbiumMYw9WesqK8aMJ1v2a3NiPSn2nDfrgkPHhMuiSV9Zu60g1dx2Hl3eLBhZTDOFLzo/KsR
 hJTD2PRHtJz8dNwcKjA+UJIs4OKVqOprMx/Un0MqQVKu8ulMnlLaHpYq9U=
X-Received: by 2002:a17:907:2d1e:b0:aa6:93c4:c685 with SMTP id
 a640c23a62f3a-ab2ab6bfe87mr1050800766b.23.1736534789193;
 Fri, 10 Jan 2025 10:46:29 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHzmdYqPe86rzk8xjbj3VeKJGaUx3BwcVwm5HoG/DGpRmH9YlJxYAPnEMUNvMmodfJCCj4grA==
X-Received: by 2002:a17:907:2d1e:b0:aa6:93c4:c685 with SMTP id
 a640c23a62f3a-ab2ab6bfe87mr1050798566b.23.1736534788635;
 Fri, 10 Jan 2025 10:46:28 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 03/38] rust: qom: add ParentField
Date: Fri, 10 Jan 2025 19:45:44 +0100
Message-ID: <20250110184620.408302-4-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534973108019000
Content-Type: text/plain; charset="utf-8"

Add a type that, together with the C function object_deinit, ensures the
correct drop order for QOM objects relative to their superclasses.

Right now it is not possible to implement the Drop trait for QOM classes
that are defined in Rust, as the drop() function would not be called when
the object goes away; instead what is called is ObjectImpl::INSTANCE_FINALI=
ZE.
It would be nice for INSTANCE_FINALIZE to just drop the object, but this has
a problem: suppose you have

   pub struct MySuperclass {
       parent: DeviceState,
       field: Box<MyData>,
       ...
   }

   impl Drop for MySuperclass {
       ...
   }

   pub struct MySubclass {
       parent: MySuperclass,
       ...
   }

and an instance_finalize implementation that is like

    unsafe extern "C" fn drop_object<T: ObjectImpl>(obj: *mut Object) {
        unsafe { std::ptr::drop_in_place(obj.cast::<T>()) }
    }

When instance_finalize is called for MySubclass, it will walk the struct's
list of fields and call the drop method for MySuperclass.  Then, object_dei=
nit
recurses to the superclass and calls the same drop method again.  This
will cause double-freeing of the Box<Data>.

What's happening here is that QOM wants to control the drop order of
MySuperclass and MySubclass's fields.  To do so, the parent field must
be marked ManuallyDrop<>, which is quite ugly.  Instead, add a wrapper
type ParentField<> that is specific to QOM.  This hides the implementation
detail of *what* is special about the ParentField, and will also be easy
to check in the #[derive(Object)] macro.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs |  6 +--
 rust/qemu-api/src/qom.rs         | 64 +++++++++++++++++++++++++++++---
 rust/qemu-api/tests/tests.rs     |  4 +-
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi=
ce.rs
index 18cc122951d..689202f4550 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -14,7 +14,7 @@
     irq::InterruptSource,
     prelude::*,
     qdev::DeviceImpl,
-    qom::ObjectImpl,
+    qom::{ObjectImpl, ParentField},
 };
=20
 use crate::{
@@ -86,7 +86,7 @@ fn index(&self, idx: u32) -> &Self::Output {
 #[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)]
 /// PL011 Device Model in QEMU
 pub struct PL011State {
-    pub parent_obj: SysBusDevice,
+    pub parent_obj: ParentField<SysBusDevice>,
     pub iomem: MemoryRegion,
     #[doc(alias =3D "fr")]
     pub flags: registers::Flags,
@@ -645,7 +645,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result=
<(), ()> {
 #[derive(Debug, qemu_api_macros::Object)]
 /// PL011 Luminary device model.
 pub struct PL011Luminary {
-    parent_obj: PL011State,
+    parent_obj: ParentField<PL011State>,
 }
=20
 impl PL011Luminary {
diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs
index 7d5fbef1e17..40d17a92e1f 100644
--- a/rust/qemu-api/src/qom.rs
+++ b/rust/qemu-api/src/qom.rs
@@ -55,6 +55,7 @@
=20
 use std::{
     ffi::CStr,
+    fmt,
     ops::{Deref, DerefMut},
     os::raw::c_void,
 };
@@ -105,6 +106,52 @@ fn as_ref(&self) -> &$parent {
     };
 }
=20
+/// This is the same as [`ManuallyDrop<T>`](std::mem::ManuallyDrop), though
+/// it hides the standard methods of `ManuallyDrop`.
+///
+/// The first field of an `ObjectType` must be of type `ParentField<T>`.
+/// (Technically, this is only necessary if there is at least one Rust
+/// superclass in the hierarchy).  This is to ensure that the parent field=
 is
+/// dropped after the subclass; this drop order is enforced by the C
+/// `object_deinit` function.
+///
+/// # Examples
+///
+/// ```ignore
+/// #[repr(C)]
+/// #[derive(qemu_api_macros::Object)]
+/// pub struct MyDevice {
+///     parent: ParentField<DeviceState>,
+///     ...
+/// }
+/// ```
+#[derive(Debug)]
+#[repr(transparent)]
+pub struct ParentField<T: ObjectType>(std::mem::ManuallyDrop<T>);
+
+impl<T: ObjectType> Deref for ParentField<T> {
+    type Target =3D T;
+
+    #[inline(always)]
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+
+impl<T: ObjectType> DerefMut for ParentField<T> {
+    #[inline(always)]
+    fn deref_mut(&mut self) -> &mut Self::Target {
+        &mut self.0
+    }
+}
+
+impl<T: fmt::Display + ObjectType> fmt::Display for ParentField<T> {
+    #[inline(always)]
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
+        self.0.fmt(f)
+    }
+}
+
 unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut Object) {
     // SAFETY: obj is an instance of T, since rust_instance_init<T>
     // is called from QOM core as the instance_init function
@@ -151,11 +198,16 @@ fn as_ref(&self) -> &$parent {
 ///
 /// - the struct must be `#[repr(C)]`;
 ///
-/// - the first field of the struct must be of the instance struct corresp=
onding
-///   to the superclass, which is `ObjectImpl::ParentType`
+/// - the first field of the struct must be of type
+///   [`ParentField<T>`](ParentField), where `T` is the parent type
+///   [`ObjectImpl::ParentType`]
 ///
-/// - likewise, the first field of the `Class` must be of the class struct
-///   corresponding to the superclass, which is `ObjectImpl::ParentType::C=
lass`.
+/// - the first field of the `Class` must be of the class struct correspon=
ding
+///   to the superclass, which is `ObjectImpl::ParentType::Class`. `Parent=
Field`
+///   is not needed here.
+///
+/// In both cases, having a separate class type is not necessary if the su=
bclass
+/// does not add any field.
 pub unsafe trait ObjectType: Sized {
     /// The QOM class object corresponding to this struct.  This is used
     /// to automatically generate a `class_init` method.
@@ -384,8 +436,8 @@ impl<T: ObjectType> ObjectCastMut for &mut T {}
=20
 /// Trait a type must implement to be registered with QEMU.
 pub trait ObjectImpl: ObjectType + ClassInitImpl<Self::Class> {
-    /// The parent of the type.  This should match the first field of
-    /// the struct that implements `ObjectImpl`:
+    /// The parent of the type.  This should match the first field of the
+    /// struct that implements `ObjectImpl`, minus the `ParentField<_>` wr=
apper.
     type ParentType: ObjectType;
=20
     /// Whether the object can be instantiated
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index 1d2825b0986..526c3f4f8ea 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -15,7 +15,7 @@
     declare_properties, define_property,
     prelude::*,
     qdev::{DeviceImpl, DeviceState, Property},
-    qom::ObjectImpl,
+    qom::{ObjectImpl, ParentField},
     vmstate::VMStateDescription,
     zeroable::Zeroable,
 };
@@ -31,7 +31,7 @@
 #[repr(C)]
 #[derive(qemu_api_macros::Object)]
 pub struct DummyState {
-    parent: DeviceState,
+    parent: ParentField<DeviceState>,
     migrate_clock: bool,
 }
=20
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535145; cv=none;
	d=zohomail.com; s=zohoarc;
	b=E/w2dY1FMswAbZoB9+O3LKMnSbyKexuF7pIHNMcNaB0+uTLHSvtmehpAtjHCgbWn83EW2mSa8l3ScL1i23yD88UrjLQ82NYeZP8hMYGd3e5cI7hWFIj7JOA7hBCRCxVPq7EvuafUfOnr++sotXzFanj1utV2BB0/LADCUE5bxoU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535145;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=+Y7AVIgYdOQkLjAuEs4LCi+iFSpj9VAgo8xznKQsbL4=;
	b=YnZSwxOM34qPhgr/6ScgaHazb0TydvK3to9cwCNXIpvpT0rh8bSUTHIhKYBgbFHMWNuI5HAaiYhxBs8LOuRtegcVUijqMsmj9XsSHnJ+fPQRX+S5PS/++KMlFno/nJzcHmKOPaoXwWHsUVEhl03QcSKE6m17vZCueVLEZbFjPGA=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535145477833.1126742753637;
 Fri, 10 Jan 2025 10:52:25 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2j-0000QT-8e; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1v-0000C0-K5
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:48 -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 <pbonzini@redhat.com>)
 id 1tWK1o-00015R-V9
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:44 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-584-SAEOOldKMU2uJxEkpbutnA-1; Fri, 10 Jan 2025 13:46:34 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d40c0c728aso1909503a12.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:34 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c9565517sm193586366b.130.2025.01.10.10.46.29
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:29 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534798;
 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=+Y7AVIgYdOQkLjAuEs4LCi+iFSpj9VAgo8xznKQsbL4=;
 b=WdArafX6GiUxBMfsWX2I74c0+uL5qa9Bj21OsQQgiGL0BX6JVjUF0CiRXqPBy+eV424R/f
 ExIiqyQYG+BQQcmtAMB7bZDtXBHdtTgcBEu5BuE0Vay8aEvlF0cTg5QGlHCwQmORgw/3n/
 o0EjlKIhH7QjEZFzd/KmSHJvWh8FD5A=
X-MC-Unique: SAEOOldKMU2uJxEkpbutnA-1
X-Mimecast-MFC-AGG-ID: SAEOOldKMU2uJxEkpbutnA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534792; x=1737139592;
 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=+Y7AVIgYdOQkLjAuEs4LCi+iFSpj9VAgo8xznKQsbL4=;
 b=RnRp4tNF5v+uVbPLe8CnxdOR4Nia0ib+WPn/5KDfVgMnsp/EIA99ovVMuAVj54nM+p
 F0FKWfgtTsF1QoilCCabDUmqMZ+hpDcOIgOdxFhsNrDRmjmKZQEDFQ4NWkWFQp2QDWj1
 ACPTAP2pgoXbdBRqlret2auhrjy/rag9Asjy5IcwoDdN8fCpFd9KYkEQaPOhnLs/HY6C
 EIYYi0CUl7VBR87W6tCNrKa1YqPoVXyb6vgskf+/ateG69F4+TBMKAtwNDedIfNCLpPh
 o361AjFbGrz+kAY5T0cFGBOVcmN3RPJxk4m+G+s5e0Gq6oBRp3+ajZ8OrXkJQUNm8B1g
 XLdw==
X-Gm-Message-State: AOJu0YxERnytULLOXIUmJvP4lIfVwzE0L/En0zdCm+kZuSAlKGLhU4Zg
 8G6z+gQLPrkoNrj8MzB9wfdqy+B9Z09G+4gu8QS/3MZ/FI1J5kXc6ZyPEHhq+0a0itw3SJG4qau
 ywC0vHq/2bJ/fLuTZfnpKOpDBbzZDV9ErvScS4g8Wj+kQve2/a2Oqvd25O+PLtXvRSlx8tPPd9C
 belqlniy2kjpkiz9VrFSJw73drNsVMU9lVMAxmxic=
X-Gm-Gg: ASbGncsRkmbNcoyx/r4T9qwou/WCgT0Bfvp1NNJMBfjOQmPguULeIi0TW1PI9NDu1GX
 ydGcb4+KG1anYsFlrBTHzs3Th0o8ptKe7AmNO8maa9gZ14lzFBDv+XzI3YYor/VITvD/kjPjaia
 e50QSDN4NSMb36/ZzcM60g5vJHv8r/P6l+LDHn01P75KO+ha0B2B0g5d1AKDEtdcKohxc1KmQGL
 2ApO4f14qayPFRC3kDLPPIrQ2Fpq+5xaFjDkicHuRCA4LjVD41UOahX390=
X-Received: by 2002:a50:858c:0:b0:5d9:857e:b259 with SMTP id
 4fb4d7f45d1cf-5d9857eb31cmr14539987a12.31.1736534792228;
 Fri, 10 Jan 2025 10:46:32 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IF8VRoiJfpZr0lg1yBx64xa8aIqBuoVsf5dw2dNq6dFmoBLLLE+69EJNK2jsn3Md+08LeNebA==
X-Received: by 2002:a50:858c:0:b0:5d9:857e:b259 with SMTP id
 4fb4d7f45d1cf-5d9857eb31cmr14539956a12.31.1736534791809;
 Fri, 10 Jan 2025 10:46:31 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 04/38] rust: add a utility module for compile-time type checks
Date: Fri, 10 Jan 2025 19:45:45 +0100
Message-ID: <20250110184620.408302-5-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535147862019000
Content-Type: text/plain; charset="utf-8"

It is relatively common in the low-level qemu_api code to assert that
a field of a struct has a specific type; for example, it can be used
to ensure that the fields match what the qemu_api and C code expects
for safety.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api/meson.build       |  1 +
 rust/qemu-api/src/assertions.rs | 90 +++++++++++++++++++++++++++++++++
 rust/qemu-api/src/lib.rs        |  1 +
 3 files changed, 92 insertions(+)
 create mode 100644 rust/qemu-api/src/assertions.rs

diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
index 9425ba7100c..60944a657de 100644
--- a/rust/qemu-api/meson.build
+++ b/rust/qemu-api/meson.build
@@ -15,6 +15,7 @@ _qemu_api_rs =3D static_library(
   structured_sources(
     [
       'src/lib.rs',
+      'src/assertions.rs',
       'src/bindings.rs',
       'src/bitops.rs',
       'src/callbacks.rs',
diff --git a/rust/qemu-api/src/assertions.rs b/rust/qemu-api/src/assertions=
.rs
new file mode 100644
index 00000000000..6e420469806
--- /dev/null
+++ b/rust/qemu-api/src/assertions.rs
@@ -0,0 +1,90 @@
+// Copyright 2024, Red Hat Inc.
+// Author(s): Paolo Bonzini <pbonzini@redhat.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+//! This module provides macros to check the equality of types and
+//! the type of `struct` fields.  This can be useful to ensure that
+//! types match the expectations of C code.
+
+// Based on https://stackoverflow.com/questions/64251852/x/70978292#709782=
92
+// (stackoverflow answers are released under MIT license).
+
+#[doc(hidden)]
+pub trait EqType {
+    type Itself;
+}
+
+impl<T> EqType for T {
+    type Itself =3D T;
+}
+
+/// Assert that two types are the same.
+///
+/// # Examples
+///
+/// ```
+/// # use qemu_api::assert_same_type;
+/// # use std::ops::Deref;
+/// assert_same_type!(u32, u32);
+/// assert_same_type!(<Box<u32> as Deref>::Target, u32);
+/// ```
+///
+/// Different types will cause a compile failure
+///
+/// ```compile_fail
+/// # use qemu_api::assert_same_type;
+/// assert_same_type!(&Box<u32>, &u32);
+/// ```
+#[macro_export]
+macro_rules! assert_same_type {
+    ($t1:ty, $t2:ty) =3D> {
+        const _: () =3D {
+            #[allow(unused)]
+            fn assert_same_type(v: $t1) {
+                fn types_must_be_equal<T, U>(_: T)
+                where
+                    T: $crate::assertions::EqType<Itself =3D U>,
+                {
+                }
+                types_must_be_equal::<_, $t2>(v);
+            }
+        };
+    };
+}
+
+/// Assert that a field of a struct has the given type.
+///
+/// # Examples
+///
+/// ```
+/// # use qemu_api::assert_field_type;
+/// pub struct A {
+///     field1: u32,
+/// }
+///
+/// assert_field_type!(A, field1, u32);
+/// ```
+///
+/// Different types will cause a compile failure
+///
+/// ```compile_fail
+/// # use qemu_api::assert_field_type;
+/// # pub struct A { field1: u32 }
+/// assert_field_type!(A, field1, i32);
+/// ```
+#[macro_export]
+macro_rules! assert_field_type {
+    ($t:ty, $i:tt, $ti:ty) =3D> {
+        const _: () =3D {
+            #[allow(unused)]
+            fn assert_field_type(v: $t) {
+                fn types_must_be_equal<T, U>(_: T)
+                where
+                    T: $crate::assertions::EqType<Itself =3D U>,
+                {
+                }
+                types_must_be_equal::<_, $ti>(v.$i);
+            }
+        };
+    };
+}
diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs
index 4b43e02c0f9..83c6a987c05 100644
--- a/rust/qemu-api/src/lib.rs
+++ b/rust/qemu-api/src/lib.rs
@@ -12,6 +12,7 @@
 #[rustfmt::skip]
 pub mod prelude;
=20
+pub mod assertions;
 pub mod bitops;
 pub mod c_str;
 pub mod callbacks;
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534975; cv=none;
	d=zohomail.com; s=zohoarc;
	b=D9cF8bhJRr3oQq9s7nytVW+D2er1Ct+u0mWxgB25pKLsnc5pnOcUmADwvSIMxmvkNS1/wDJM5uZEA22aee+slaG+V69tHJJmCNtHl5gh0uGc9emZPS4M0DgOXNZILa5nNrqKo8syWRHjEyHucjpwfmtvQP4Y5gEJFoQmE+3ljnI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534975;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=XJMegQJf6w9b9nRXNq7/z8d5kYstt5nQEzXDaVstUso=;
	b=eHwguF+/g4iAV+RBikxTGNu/hd4Z1Xx9UIw0bvPmx7TJcO+yClfXQ7UmX66SjwZDLCAmKklZm+KJDFzlK5NuI7Fa63dypQqH/pLOTATJ6P2FLm9IG1Pg70pAg63wO7MAyMM5tUD+283zyhOSK06bKECZbiVjOqUqcxg1HKdi9UI=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173653497576323.778185359312374;
 Fri, 10 Jan 2025 10:49:35 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2l-0000S1-Bp; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1t-0000Bt-LL
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:48 -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 <pbonzini@redhat.com>)
 id 1tWK1m-00015K-82
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:42 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-494-WMeDq7btO0GgeBT4EUoCqQ-1; Fri, 10 Jan 2025 13:46:36 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa68952272bso273191866b.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:35 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90d9a7dsm194409066b.50.2025.01.10.10.46.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:32 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534797;
 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=XJMegQJf6w9b9nRXNq7/z8d5kYstt5nQEzXDaVstUso=;
 b=XYEXANFEMDp+y9nPloSjZzE/BBgj4JRSBaXJNUnKiqiGjMibQnNe/3xGY3+1T+wjTFJuJq
 JnD0YiLLhzZ0ioZjRN5ZPR/jvXkMeWjkRT2LXoo613hFXld/lbVVcBJljLsM8oluY+PM25
 6jMsUqcuFPrfQyBdBLDRHh7+BTucJ/Y=
X-MC-Unique: WMeDq7btO0GgeBT4EUoCqQ-1
X-Mimecast-MFC-AGG-ID: WMeDq7btO0GgeBT4EUoCqQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534794; x=1737139594;
 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=XJMegQJf6w9b9nRXNq7/z8d5kYstt5nQEzXDaVstUso=;
 b=i0UlFLQq9pGjVmIjDG/52GigVQ7MieKdC67Oy/q9mTBqZ9FanX7Q+fvIxwGMV2kGLC
 Z9mSuN3x14maPFDGFPmWrrs/+4W2CgijlGtdXsIvoAmybCd6p1uIZv4BTVYXUbobOVLk
 n/RgQzt3P4KPTgACRK8qZ8hQFuZ7WgpbttfKjTVFjIj1myBiVz+cqe18eDFYEw0Uhc4v
 dhPLle8JNu0yOo5ewXb8IFXBU53pRMvD+EImAxy5WW+q2CeDAv/hj7peol56eJUs184F
 hq4qJU2iK5HWbpBHcwrVVcu0BZ0vZINzkNk4B+zBT0A/WHejliUU1Inq4IeNwXmNLd48
 3XQw==
X-Gm-Message-State: AOJu0YwOlTvdRZtUTw16rQ4APhVbt8CGuwySWrVMEeyqY5mFSmkJHCpj
 CK1dUJ6pE9BnL0bBErzGn/5ESomH6Fzub729kZ+BS0Lc8EYelH+WJtEBOsaah2apT9RUY88/Svh
 2GZ1tjP2qXHD2hJCoKmiw4MlVevyTw5SB6Jq+aH/oWLy2/9cJ5KEe8rsbe0yBjcjNTBNPC2InqC
 UBh7laHNz8Oq0v3Wy77Kg/txDeGcT/q2BKC9PUa3U=
X-Gm-Gg: ASbGncscic7IcTLo2tjGC8fcPr9j62nbpQAZ1hiotieb8xwLfCTukBPxQTyJQu0J4rF
 OgodRV2bB6QGmTubOKdyDyn15zfjHPsx53FL96y7SZJWg8RfMaWCoH8vWEZEjvmSwG0FtRgUDYR
 s7t5wuFoFFzpcZvdu5EDxvOcB75klhXyoS6WZmTK4tDOCiJR9Qxo6m43DLsXQC1K+wnIq7CGIky
 Dj+SO84X+qqHIjtafUo9OFzdZJRFqYotlzlcoIauspcLQm0IIptyUyA7u0=
X-Received: by 2002:a17:906:ef0b:b0:aa6:8096:204d with SMTP id
 a640c23a62f3a-ab2ab6a8e78mr1134929866b.3.1736534794403;
 Fri, 10 Jan 2025 10:46:34 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFkijy8mmWURrs2JHVq/CKL0tbHIq6BzWi2GGaeqKkL4kLCd1ZN/g4bpGYfQYyYHDHC4LGoIw==
X-Received: by 2002:a17:906:ef0b:b0:aa6:8096:204d with SMTP id
 a640c23a62f3a-ab2ab6a8e78mr1134927966b.3.1736534793969;
 Fri, 10 Jan 2025 10:46:33 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 05/38] rust: macros: check that #[derive(Object)] requires
 #[repr(C)]
Date: Fri, 10 Jan 2025 19:45:46 +0100
Message-ID: <20250110184620.408302-6-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534976928019000
Content-Type: text/plain; charset="utf-8"

Convert derive_object to the same pattern of first making a
Result<proc_macro2::TokenStream, CompileError>, and then doing
.unwrap_or_else(Into::into) to support checking the validity of
the input.  Add is_c_repr to check that all QOM structs include
a #[repr(C)] attribute.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api-macros/src/lib.rs | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib=
.rs
index 74a8bc7503e..160b283d7fd 100644
--- a/rust/qemu-api-macros/src/lib.rs
+++ b/rust/qemu-api-macros/src/lib.rs
@@ -32,18 +32,23 @@ fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<=
(), CompileError> {
     }
 }
=20
-#[proc_macro_derive(Object)]
-pub fn derive_object(input: TokenStream) -> TokenStream {
-    let input =3D parse_macro_input!(input as DeriveInput);
-    let name =3D input.ident;
+fn derive_object_or_error(input: DeriveInput) -> Result<proc_macro2::Token=
Stream, CompileError> {
+    is_c_repr(&input, "#[derive(Object)]")?;
=20
-    let expanded =3D quote! {
+    let name =3D &input.ident;
+    Ok(quote! {
         ::qemu_api::module_init! {
             MODULE_INIT_QOM =3D> unsafe {
                 ::qemu_api::bindings::type_register_static(&<#name as ::qe=
mu_api::qom::ObjectImpl>::TYPE_INFO);
             }
         }
-    };
+    })
+}
+
+#[proc_macro_derive(Object)]
+pub fn derive_object(input: TokenStream) -> TokenStream {
+    let input =3D parse_macro_input!(input as DeriveInput);
+    let expanded =3D derive_object_or_error(input).unwrap_or_else(Into::in=
to);
=20
     TokenStream::from(expanded)
 }
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535340; cv=none;
	d=zohomail.com; s=zohoarc;
	b=K1j09dRcRrS2HkMaIh9KMeXBx90bA+ZTAR2SbK6Nke4ZyxnsfcOvp5gX6nTaOxerVzsMQW0d0XteMkDyrLNyDhD6+AtI7gMGV9kMLzyGX3F5fSRG44yft5dbOGD69Od/36gU1Cb47QGcz72NyuvhTrxFjAh2sZg/jAxjJsTA8A8=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535340;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=VgkejbxfBm5Z+fcfrq4PM2AVjZL5LxnPI4rmsBdS2Ng=;
	b=FcijFcZgOA9TxmQzU4pnvMVmGiEtvP3JuDp4SagxXTng7UftKtInLDlSu3pqgD5DTq3RVsn1o0B4feDtQhN7/lBKEsNf2vj2de6C8TS3NiBjXal/v4y7N5tSDLUmC3ETstn1gxXKFKPOjYYIVIH0/JzIbTJVqvdJgWGctnEMP8w=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535340750707.6908043356381;
 Fri, 10 Jan 2025 10:55:40 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2x-00012u-9W; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1w-0000C3-3w
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:49 -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 <pbonzini@redhat.com>)
 id 1tWK1q-00015Z-56
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:46 -0500
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-632-wvQozBUSMjWkSxFN08LEcg-1; Fri, 10 Jan 2025 13:46:38 -0500
Received: by mail-ed1-f69.google.com with SMTP id
 4fb4d7f45d1cf-5d3fe75a9f0so2264524a12.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:38 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99008c39fsm1936935a12.13.2025.01.10.10.46.34
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:34 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534799;
 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=VgkejbxfBm5Z+fcfrq4PM2AVjZL5LxnPI4rmsBdS2Ng=;
 b=Gju39WL4RiUyRssQ6YMfbe44ZNK4wpsNIyysq4ErXdD+koVF+tbvuYk+Ecu8i2HtX1pjxr
 UogesI3XpyIeuhuDeiE6h7iwyvgDQQDsGnYyNklG2phDi7y99Vc4kHp9zaznOhzoDw63V6
 9kDbn7v53z6+U9zuk1eNgkU7dbEYaws=
X-MC-Unique: wvQozBUSMjWkSxFN08LEcg-1
X-Mimecast-MFC-AGG-ID: wvQozBUSMjWkSxFN08LEcg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534796; x=1737139596;
 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=VgkejbxfBm5Z+fcfrq4PM2AVjZL5LxnPI4rmsBdS2Ng=;
 b=HOoXA2lFwIDPtYoxS+Im3RNy6nu1VCrsJxLsvKdV63Ir6A/XwykTNqg24tmv25cgwd
 mR967HVOr05TkDNy8vwKgkFBv9r8wQdd9XiHJ1SmaGesKKDylZzZvexeCixebu2jxj+o
 3BWN3J908zZguy/RToGA2VUM1WVtCtYz0mgwGzv3kptUI64mU7FBMFtj5fyXCkwNeRWZ
 jVF3t4JEmzxyOLwK5BzhPaCpBr843bPHIbD/ovJ3acqzowx2ID1M3RFLPQS2tzpe/1V/
 RgU6mWx61xlrgk+e0cVeeSbBwYGXAQNlJHg49tw8542N9YRq1a7uJ4uJD7PG9cyRd9Qh
 F7Zw==
X-Gm-Message-State: AOJu0YxaaRSqTCCLpBqmc5dSXp3lvTlD/pEe3FyW2qoGI3ZYP7pPoW7/
 /1sKMU3V5w5CI+15RGyishY/tgWywMpwNsVAlW8lVFgHqVDFNDlBrw82sP1eq2BzrBI/tdJgOZA
 yP4FrofHJO1EHXaPj7UADogMsVTxVNeH1qsRG3uQBtRaweQQDwJ92jX1Wa9XyINZcfOvnQcMT/O
 Nfy/+lFtbEbM2djosKIP7FoAsEUShqeRi+VqyiEI8=
X-Gm-Gg: ASbGncuFiNGY08GJm460fJzIC80ZjIE5x/LHADFZ3wSHiDwVRoC4a8rt/zw2EW4d4+9
 rZFeHLgrbJ5T8kY7MwLKa1xtsk/05gAx88g8A/q7NkZOfMqmXHLyXP9bktVtJmzVuSXi2CrBsle
 sGOkQzwygURjxo0NlgklLeoiB4I+i3nPygH/8EzCH0QE1He4s2cWhSELxGNYOwRFOwvSQ99B6F7
 Gvj9sAHxNCsI35m1JjnVal9FOTCtPq9A2PRJvP4lMDgeAnCnzHJggPPBMM=
X-Received: by 2002:a05:6402:51cf:b0:5d3:bc1d:e56d with SMTP id
 4fb4d7f45d1cf-5d972e70310mr10034831a12.31.1736534796159;
 Fri, 10 Jan 2025 10:46:36 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IH6TPbCmZKnWbaWfGBaUn0/ENicWa7Esf12w48vFKCAWso9g2vdYvh+njXfN1tUVVQD5xHnAw==
X-Received: by 2002:a05:6402:51cf:b0:5d3:bc1d:e56d with SMTP id
 4fb4d7f45d1cf-5d972e70310mr10034801a12.31.1736534795644;
 Fri, 10 Jan 2025 10:46:35 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 06/38] rust: macros: check that the first field of a
 #[derive(Object)] struct is a ParentField
Date: Fri, 10 Jan 2025 19:45:47 +0100
Message-ID: <20250110184620.408302-7-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535342817019000
Content-Type: text/plain; charset="utf-8"

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api-macros/src/lib.rs | 46 +++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib=
.rs
index 160b283d7fd..0f04cca3841 100644
--- a/rust/qemu-api-macros/src/lib.rs
+++ b/rust/qemu-api-macros/src/lib.rs
@@ -19,6 +19,27 @@ fn from(err: CompileError) -> Self {
     }
 }
=20
+fn get_fields<'a>(
+    input: &'a DeriveInput,
+    msg: &str,
+) -> Result<&'a Punctuated<Field, Comma>, CompileError> {
+    if let Data::Struct(s) =3D &input.data {
+        if let Fields::Named(fs) =3D &s.fields {
+            Ok(&fs.named)
+        } else {
+            Err(CompileError(
+                format!("Named fields required for {}", msg),
+                input.ident.span(),
+            ))
+        }
+    } else {
+        Err(CompileError(
+            format!("Struct required for {}", msg),
+            input.ident.span(),
+        ))
+    }
+}
+
 fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), CompileError> {
     let expected =3D parse_quote! { #[repr(C)] };
=20
@@ -36,7 +57,12 @@ fn derive_object_or_error(input: DeriveInput) -> Result<=
proc_macro2::TokenStream
     is_c_repr(&input, "#[derive(Object)]")?;
=20
     let name =3D &input.ident;
+    let parent =3D &get_fields(&input, "#[derive(Object)]")?[0].ident;
+
     Ok(quote! {
+        ::qemu_api::assert_field_type!(#name, #parent,
+            ::qemu_api::qom::ParentField<<#name as ::qemu_api::qom::Object=
Impl>::ParentType>);
+
         ::qemu_api::module_init! {
             MODULE_INIT_QOM =3D> unsafe {
                 ::qemu_api::bindings::type_register_static(&<#name as ::qe=
mu_api::qom::ObjectImpl>::TYPE_INFO);
@@ -53,30 +79,12 @@ pub fn derive_object(input: TokenStream) -> TokenStream=
 {
     TokenStream::from(expanded)
 }
=20
-fn get_fields(input: &DeriveInput) -> Result<&Punctuated<Field, Comma>, Co=
mpileError> {
-    if let Data::Struct(s) =3D &input.data {
-        if let Fields::Named(fs) =3D &s.fields {
-            Ok(&fs.named)
-        } else {
-            Err(CompileError(
-                "Cannot generate offsets for unnamed fields.".to_string(),
-                input.ident.span(),
-            ))
-        }
-    } else {
-        Err(CompileError(
-            "Cannot generate offsets for union or enum.".to_string(),
-            input.ident.span(),
-        ))
-    }
-}
-
 #[rustfmt::skip::macros(quote)]
 fn derive_offsets_or_error(input: DeriveInput) -> Result<proc_macro2::Toke=
nStream, CompileError> {
     is_c_repr(&input, "#[derive(offsets)]")?;
=20
     let name =3D &input.ident;
-    let fields =3D get_fields(&input)?;
+    let fields =3D get_fields(&input, "#[derive(offsets)]")?;
     let field_names: Vec<&Ident> =3D fields.iter().map(|f| f.ident.as_ref(=
).unwrap()).collect();
     let field_types: Vec<&Type> =3D fields.iter().map(|f| &f.ty).collect();
     let field_vis: Vec<&Visibility> =3D fields.iter().map(|f| &f.vis).coll=
ect();
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534844; cv=none;
	d=zohomail.com; s=zohoarc;
	b=gJ1PnsUl1Di89fCS8KkL8mG5mLHjF4wpf+PMVjzbFBxBGxX8KVcYtINGSh/l9u8oqDSBSdNJON5kNOz6zv7islZRivuia4R+fOAchDrA9RfGypnnpBxLjrXPWJySqRP3lsnwGtC+uHHK1cj9XvgKGGec6K+dDlWd6By/p8pQ91c=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534844;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=KBR/uFjAg+sgDERa7azkccUfvjafKjeZQfYH4Q0wXiM=;
	b=DJzDLHr7MamfPxBd4eYQCX5L22oStwZFVkUSUYjVNzWVnIFXDKbJb7/yu8gw7c4t8GhjDhv1jPzuCQC9bZVJBzx4TX028UPxuqC91WDedxqGU4WOqekN4nhwXi2EBLeta3QjI7f9PWPUgkLtOb8Cz6ggPBIur+tTqT4p41XO7gw=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534844137609.9446196817499;
 Fri, 10 Jan 2025 10:47:24 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK21-0000El-VQ; Fri, 10 Jan 2025 13:46: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 <pbonzini@redhat.com>)
 id 1tWK1w-0000C4-4d
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:49 -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 <pbonzini@redhat.com>)
 id 1tWK1s-00015k-0J
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:46 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-684-RxBQcHLxMMqZJvy3iFAsfQ-1; Fri, 10 Jan 2025 13:46:40 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa69c41994dso170101366b.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:39 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c905cd15sm193313866b.5.2025.01.10.10.46.36
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534801;
 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=KBR/uFjAg+sgDERa7azkccUfvjafKjeZQfYH4Q0wXiM=;
 b=UIA4Hbl7Sca1ijj2jTHhBlcDMNquO04Y91AryojHqfiz8luDXtXg/3Hy+hrDINNmt1jTzr
 +CU2ZKb/Ne5c3+KVmrYq4y5AxhVerQDUYn5VCrPMSD/UpRTE8QrRTKgV5qBjznmQt2iGQr
 BHS0lFMGXfcghjed3dB2x3AC/VZC+qs=
X-MC-Unique: RxBQcHLxMMqZJvy3iFAsfQ-1
X-Mimecast-MFC-AGG-ID: RxBQcHLxMMqZJvy3iFAsfQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534798; x=1737139598;
 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=KBR/uFjAg+sgDERa7azkccUfvjafKjeZQfYH4Q0wXiM=;
 b=Q8IYDyDgi8Mgi4+J79VbUx269c4Rr1HcG5J8OAi1ecV4Sr8bKaa5f9MerephvqjoW2
 w9KcUt0ckZmGy5KtE3r1BRW+yJege3h+Gqxlxbl/KazfcJx1YylaeFe3ivv+6nNuVdbR
 4Xz2AvNyToaBqu/ZtpuVJ/CWkTs7w+Vj5ZbLjZeDMlJh2hhjKbdv1dxeRn0Lw7BR5IMY
 xZz6gzLb2RepV1UEVXB905f4vPhkNMU7EKKVqyGVwuuVwN97gP8l+JBSnvnQ3q+mY868
 Q5IXhHeX3KwGlJcw3j6RgTg3vcI3UXzFQtPADXHtbsQIehenkRGoPhL3HPXhu9mQuuap
 /Nbg==
X-Gm-Message-State: AOJu0YyyMqGQPzwR9iv/7ThmbkhpK0m4YeI94aGkuXchgbRXqaZ8iyuF
 XRa0zngFVmEaykathysqYzc/i1k9zxBKXgcNxF+1DdIGgaraUMyXHKk83g3RAnZ9OdJydkbsOQ5
 sY7wtjGzRTGoXCfxrBb3AKFy0hYH0s+CqwlYAG67ixcgthGzy6P50xQ/2V2rhTWCgWzT2JQICNt
 RKfvGjSXwqMZn0ONR0eb5rprQo5f1WXxSmFaP4Ud4=
X-Gm-Gg: ASbGncuZZufOTyXC1TJ9r4HvL0/e4N4Ji0Dp8lEc2ORsOAT5MlQE7U4H0e992ZelqTO
 63Zj4eofFujQNA0poMaqmm2d/mwZeDaJCUBvpN6pQLCKLq91XnpQDL4mwIOda9krEZ0WlEq81NU
 SBiPx3A1cIfFx1c4xCQtAcHtYtElr4lLdyISbFPFN9jS5AuacUaaA7hKigqdWiLShVKxE+P8uWg
 eaJbquUVYqQyUpRvajsGYoluK4afTct/cFvoKV6dLx3hAxf90o/a59GGWI=
X-Received: by 2002:a05:6402:4310:b0:5d6:48ef:c19f with SMTP id
 4fb4d7f45d1cf-5d972e708a1mr26256487a12.29.1736534798464;
 Fri, 10 Jan 2025 10:46:38 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGmJX3Pubw9RmVY5LHah+mvaqqwDsZjHdPSmVQYMun/126OcezaDJLjyocjjwnGRGRCTFgxFQ==
X-Received: by 2002:a05:6402:4310:b0:5d6:48ef:c19f with SMTP id
 4fb4d7f45d1cf-5d972e708a1mr26256439a12.29.1736534798034;
 Fri, 10 Jan 2025 10:46:38 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 07/38] rust: qom: automatically use Drop trait to implement
 instance_finalize
Date: Fri, 10 Jan 2025 19:45:48 +0100
Message-ID: <20250110184620.408302-8-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534845114116600
Content-Type: text/plain; charset="utf-8"

Replace the customizable INSTANCE_FINALIZE with a generic function
that drops the Rust object.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api/src/qom.rs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs
index 40d17a92e1f..b0332ba2477 100644
--- a/rust/qemu-api/src/qom.rs
+++ b/rust/qemu-api/src/qom.rs
@@ -180,6 +180,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<()=
, fmt::Error> {
     T::class_init(unsafe { &mut *klass.cast::<T::Class>() })
 }
=20
+unsafe extern "C" fn drop_object<T: ObjectImpl>(obj: *mut Object) {
+    // SAFETY: obj is an instance of T, since drop_object<T> is called
+    // from the QOM core function object_deinit() as the instance_finalize
+    // function for class T.  Note that while object_deinit() will drop the
+    // superclass field separately after this function returns, `T` must
+    // implement the unsafe trait ObjectType; the safety rules for the
+    // trait mandate that the parent field is manually dropped.
+    unsafe { std::ptr::drop_in_place(obj.cast::<T>()) }
+}
+
 /// Trait exposed by all structs corresponding to QOM objects.
 ///
 /// # Safety
@@ -442,7 +452,6 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl<Self::=
Class> {
=20
     /// Whether the object can be instantiated
     const ABSTRACT: bool =3D false;
-    const INSTANCE_FINALIZE: Option<unsafe extern "C" fn(obj: *mut Object)=
> =3D None;
=20
     /// Function that is called to initialize an object.  The parent class=
 will
     /// have already been initialized so the type is only responsible for
@@ -478,7 +487,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl<Self::=
Class> {
             None =3D> None,
             Some(_) =3D> Some(rust_instance_post_init::<Self>),
         },
-        instance_finalize: Self::INSTANCE_FINALIZE,
+        instance_finalize: Some(drop_object::<Self>),
         abstract_: Self::ABSTRACT,
         class_size: core::mem::size_of::<Self::Class>(),
         class_init: Some(rust_class_init::<Self>),
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535167; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Fiouy3wIlxi6eUD2FTtm3WMtVH4EFNoWjwBsPVsIfxzzjzGSnIzX714Qhi1JPDJyVAa+3AZkn/YjoM8PFgoNtzl0P+SJGVBn7vbYrYDLIClUfAtrmgSk5awBNL9IL0bRQ7X1CXv0ClmzdxYSD4EMFG4wdd7iEiWD01VN5g1xs+g=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535167;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=oM5g6F4YfpoFPC4IDdAwTmKbiMsdCMsOt3B3qFLoUYk=;
	b=PP7qz04I+Vw0WFT61+aHT7NmadQE0/rXq0OWaryfgDscoAw/1MB41ZFiQ2AsGni5f9L7SKMKnL/lpCs+vmnNvzZ4PVOoY6Lrb7zkeuw3PzR/3mhmZGgizro6FLP71t/hXfHcdx+QWQlBRzcDouMtHJklOybT4YxgFWiiFd39dDA=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173653516795652.614812488372195;
 Fri, 10 Jan 2025 10:52:47 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2v-0000tJ-IC; Fri, 10 Jan 2025 13:47:49 -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 <pbonzini@redhat.com>)
 id 1tWK1y-0000Dg-EQ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:52 -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 <pbonzini@redhat.com>)
 id 1tWK1v-000164-DX
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:49 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-15-eK5bjl9-NsergkTmhB73Cg-1; Fri, 10 Jan 2025 13:46:42 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d43ec75bc4so2329311a12.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:42 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99008c394sm1932559a12.7.2025.01.10.10.46.38
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:39 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534804;
 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=oM5g6F4YfpoFPC4IDdAwTmKbiMsdCMsOt3B3qFLoUYk=;
 b=hsX7HI23dGg+fHDNpDzvIlw8hrgxOZjKDFi+8POr2zST7gOq/C4/m5ij60DKyMDp+f7frn
 qw/4e5yYO5hOcT7aOYmcFhtykoIrLbTXU9vVJ8M++LvYKrGGfFf+7t4iG3Zgs8qS0fCeDo
 3N2ZC5tlEjgSlC6U0FourLbUTXBeJ6w=
X-MC-Unique: eK5bjl9-NsergkTmhB73Cg-1
X-Mimecast-MFC-AGG-ID: eK5bjl9-NsergkTmhB73Cg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534800; x=1737139600;
 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=oM5g6F4YfpoFPC4IDdAwTmKbiMsdCMsOt3B3qFLoUYk=;
 b=rwHPbCqgsNIzk5TN3QyYhC6bWaBkH493Yk9LK5Fyk9Gg0J8sO2UKYC1HVEjIKmA13r
 X5KctayOjZukofXXkGA66B+ir+Y9aImpo5+xPhQoIRWWUGYpRsu8x3c5/Hf+7nAlzowp
 3c4ccDuIfU+V5y0jmM9lQe1XjsNnuCjEF6sR+esOC9Be8FucpVwWmeGHkoQpONSRj/QI
 nnHn8VjV/vAHPHce/spL+IX5sIPfNzvz3tI5ESkCGPPR0b6EYeu3w92Q98J8woOtp9wd
 aCvI3vSc7RKH+cWNQLbxHP/kDMlhT3eWExNOz30leg385itfoAtmljWl2QXE3qxw6/Ag
 VYLw==
X-Gm-Message-State: AOJu0YzQck1fo1tIwlKcBj7fMOgYJPBR92VeHFL7Pa2z9O3MxUckKUG6
 vi3s1ScFoFuu5CCB5Oxgbcnzd71gM142Aj+9MfOH93B8yiT0TddpSmF7WXDNUgTXeUXdOnkhcaS
 UQKatwDEPoYgwZabQanY2k+9uSS0d5/tntt7MYVsi+0WOHKrO2exwXWH9lF7bA9n0md9do4RX7G
 pXpumPEkfMPRxtdmsb7Zu5ac6zR01LGKFz3qk5s5E=
X-Gm-Gg: ASbGncvpITgKBBK/+oS+6IDDOo6BIFHfw6xJDCo0czdxKcOrrU/oOY8JPTfhmnSN9FN
 oG9P/F5fWkRTWLYqJRdmhW3DsLM61R07iWpwmanJMZPa6YgiZixyBjb1Dumq+StQWPwJbbNGMTo
 8rhvNsEVU1LcQAXkOBjvKMioHo63Dc/sM/+q8olh810+Sy+a/YB0smTDmDSabQ+3vL2SHH530wm
 MiJI3qYqx8U0G2AJO4o7Tyy9USK5bLCXretuk0nC41BIY2KUCpUGF/BFt4=
X-Received: by 2002:a05:6402:354b:b0:5d3:eceb:9c6c with SMTP id
 4fb4d7f45d1cf-5d972e6cf63mr10771365a12.29.1736534800413;
 Fri, 10 Jan 2025 10:46:40 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHQ0AN9agflhE/kpP30UyIwTg5OxImpp8QkX9J4x/wpJ6aT+Rbfv07lC1hK1OiseZNq0a7tng==
X-Received: by 2002:a05:6402:354b:b0:5d3:eceb:9c6c with SMTP id
 4fb4d7f45d1cf-5d972e6cf63mr10771343a12.29.1736534799911;
 Fri, 10 Jan 2025 10:46:39 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 08/38] rust: qom: move device_id to PL011 class side
Date: Fri, 10 Jan 2025 19:45:49 +0100
Message-ID: <20250110184620.408302-9-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535168506116600
Content-Type: text/plain; charset="utf-8"

There is no need to monkeypatch DeviceId::Luminary into the already-initial=
ized
PL011State.  Instead, now that we can define a class hierarchy, we can defi=
ne
PL011Class and make device_id a field in there.

There is also no need anymore to have "Arm" as zero, so change DeviceId int=
o a
wrapper for the array; all it does is provide an Index<hwaddr> implementati=
on
because arrays can only be indexed by usize.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs | 59 +++++++++++++++-----------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi=
ce.rs
index 689202f4550..215f94a6e4a 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -5,7 +5,7 @@
 use core::ptr::{addr_of_mut, NonNull};
 use std::{
     ffi::CStr,
-    os::raw::{c_int, c_uchar, c_uint, c_void},
+    os::raw::{c_int, c_uint, c_void},
 };
=20
 use qemu_api::{
@@ -14,7 +14,7 @@
     irq::InterruptSource,
     prelude::*,
     qdev::DeviceImpl,
-    qom::{ObjectImpl, ParentField},
+    qom::{ClassInitImpl, ObjectImpl, ParentField},
 };
=20
 use crate::{
@@ -33,27 +33,20 @@
 /// QEMU sourced constant.
 pub const PL011_FIFO_DEPTH: u32 =3D 16;
=20
-#[derive(Clone, Copy, Debug)]
-enum DeviceId {
-    #[allow(dead_code)]
-    Arm =3D 0,
-    Luminary,
-}
+#[derive(Clone, Copy)]
+struct DeviceId(&'static [u8; 8]);
=20
 impl std::ops::Index<hwaddr> for DeviceId {
-    type Output =3D c_uchar;
+    type Output =3D u8;
=20
     fn index(&self, idx: hwaddr) -> &Self::Output {
-        match self {
-            Self::Arm =3D> &Self::PL011_ID_ARM[idx as usize],
-            Self::Luminary =3D> &Self::PL011_ID_LUMINARY[idx as usize],
-        }
+        &self.0[idx as usize]
     }
 }
=20
 impl DeviceId {
-    const PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0x=
f0, 0x05, 0xb1];
-    const PL011_ID_LUMINARY: [c_uchar; 8] =3D [0x11, 0x00, 0x18, 0x01, 0x0=
d, 0xf0, 0x05, 0xb1];
+    const ARM: Self =3D Self(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0=
xb1]);
+    const LUMINARY: Self =3D Self(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x=
05, 0xb1]);
 }
=20
 // FIFOs use 32-bit indices instead of usize, for compatibility with
@@ -126,17 +119,28 @@ pub struct PL011State {
     pub clock: NonNull<Clock>,
     #[doc(alias =3D "migrate_clk")]
     pub migrate_clock: bool,
-    /// The byte string that identifies the device.
-    device_id: DeviceId,
 }
=20
 qom_isa!(PL011State : SysBusDevice, DeviceState, Object);
=20
+pub struct PL011Class {
+    parent_class: <SysBusDevice as ObjectType>::Class,
+    /// The byte string that identifies the device.
+    device_id: DeviceId,
+}
+
 unsafe impl ObjectType for PL011State {
-    type Class =3D <SysBusDevice as ObjectType>::Class;
+    type Class =3D PL011Class;
     const TYPE_NAME: &'static CStr =3D crate::TYPE_PL011;
 }
=20
+impl ClassInitImpl<PL011Class> for PL011State {
+    fn class_init(klass: &mut PL011Class) {
+        klass.device_id =3D DeviceId::ARM;
+        <Self as ClassInitImpl<SysBusDeviceClass>>::class_init(&mut klass.=
parent_class);
+    }
+}
+
 impl ObjectImpl for PL011State {
     type ParentType =3D SysBusDevice;
=20
@@ -214,7 +218,8 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -=
> std::ops::ControlFlow<u
=20
         let value =3D match RegisterOffset::try_from(offset) {
             Err(v) if (0x3f8..0x400).contains(&(v >> 2)) =3D> {
-                u32::from(self.device_id[(offset - 0xfe0) >> 2])
+                let device_id =3D self.get_class().device_id;
+                u32::from(device_id[(offset - 0xfe0) >> 2])
             }
             Err(_) =3D> {
                 // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset =
0x%x\n", (int)offset);
@@ -648,16 +653,10 @@ pub struct PL011Luminary {
     parent_obj: ParentField<PL011State>,
 }
=20
-impl PL011Luminary {
-    /// Initializes a pre-allocated, unitialized instance of `PL011Luminar=
y`.
-    ///
-    /// # Safety
-    ///
-    /// We expect the FFI user of this function to pass a valid pointer, t=
hat
-    /// 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 =3D DeviceId::Luminary;
+impl ClassInitImpl<PL011Class> for PL011Luminary {
+    fn class_init(klass: &mut PL011Class) {
+        klass.device_id =3D DeviceId::LUMINARY;
+        <Self as ClassInitImpl<SysBusDeviceClass>>::class_init(&mut klass.=
parent_class);
     }
 }
=20
@@ -670,8 +669,6 @@ unsafe impl ObjectType for PL011Luminary {
=20
 impl ObjectImpl for PL011Luminary {
     type ParentType =3D PL011State;
-
-    const INSTANCE_INIT: Option<unsafe fn(&mut Self)> =3D Some(Self::init);
 }
=20
 impl DeviceImpl for PL011Luminary {}
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534962; cv=none;
	d=zohomail.com; s=zohoarc;
	b=DR2yz0/sJPQu5TYhBVq71XrNLJaFQ7KAlqfGAQqvxJMfbWBiVa8bZKx1djQYgz3HRL+/JbMvQNukPABw2ifkAdejS9cpeHHci6nPTLkA3O2AXB6DUfHjCK6ION3koHNJ9/peBqZQbNN17AYhvwOdZ4I0J/5vT+nPiezNYR3oUxg=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534962;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=aX24Q+tB77pzEZ+uLwRAl7jQIydZqUxNNDKMiOl7mBs=;
	b=TxXTlm+xDrBYgC0hSqo7694cy8obY1OI2scWkz+BOVefbNUn7NZVwoLI4cjEBKLAzApwKvy3Q2D6cDrhzW2sY4aDcqivMdG4qeuuPANuABTPgfj+pSELL8rpJRCDmYduo4quaXRMvhHtw+9Lk6V6gPOt0KGXeqxEmxA0rtX9GFc=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534962721111.10659309166886;
 Fri, 10 Jan 2025 10:49:22 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2t-0000jv-VR; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK1y-0000Dc-Du
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:52 -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 <pbonzini@redhat.com>)
 id 1tWK1v-000168-T3
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:49 -0500
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-374-sR28UJ-6PPqAS5NupQN1mA-1; Fri, 10 Jan 2025 13:46:44 -0500
Received: by mail-ed1-f69.google.com with SMTP id
 4fb4d7f45d1cf-5d88d37abd0so2352981a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:43 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99008c39fsm1936978a12.13.2025.01.10.10.46.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:40 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534805;
 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=aX24Q+tB77pzEZ+uLwRAl7jQIydZqUxNNDKMiOl7mBs=;
 b=U+/7rWXKMesPdOqR4EiUSMHxQXfTinlbXrazhUbOA3+JEECCjF6VcFpBPkbVajiq5wlbzc
 MAXsmPmHMrDhMLOxCIIZpbuv9sui1jAsZ4QwpMlqjlC5cMYiLrWB9zctSIMfdPMGJw3Mca
 +9TSk8XXeD+ts+M/jSnXXgx+WaPmdXM=
X-MC-Unique: sR28UJ-6PPqAS5NupQN1mA-1
X-Mimecast-MFC-AGG-ID: sR28UJ-6PPqAS5NupQN1mA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534802; x=1737139602;
 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=aX24Q+tB77pzEZ+uLwRAl7jQIydZqUxNNDKMiOl7mBs=;
 b=hHgYGFCFPxpips8+xMI0kzO0jk6mb6gddV7FoH5MHujdv4TqXwiKd1RfvX/OOwm1jT
 XiV/J6njzyROgR7vl30YMGrbPt4ZwNdUF89eCjbHOOGcdhu2XCl/IpXcZviBRmR2XPki
 4XJW+N8QBGYA/eYaFMpEoubZU9KXkyFJULQmQLfIe2Jo04Flb3dBtoo+CnLLTN8xX6tK
 iW0dipvobOYPZjiyn61JOU0OoX3BCaAmURYY6pmDlXElt3C2eIcD1HIxzy5E/AhDdRTW
 NLahCyr1owAcBarUWi0ZqjcouaHCbIZJ9/rTyAzJTCTBL5zEGIfxLWGVqjeTzjVfx0nz
 QicA==
X-Gm-Message-State: AOJu0Yz54Rx6MpzTQ5vOUtXnVLWXORSSaB9FBFDnJJT39gd4fs0Z6gx+
 jmUT66Tm4Kupqv0YmwlvM2SJ8kYhFTpZ9CzL0qX3CKge++YGJfbg44/xzFl8IYXAnAF50I5rnFU
 q+VwKJLLyvG+QGPdDIAaVjdthJvUZLlREN1Pm9rgYGYqPrWWlYLIuSnefimiyMFhhAC+tZZyJdy
 OlE9vclWCmWBa5+wSWQWr3ir5Cq9TTtCKdWidi4yA=
X-Gm-Gg: ASbGncs9MkGZfvLjI+Pvj8185V38AxB/PO6OIHi/eESYeHweeB/bU8dBWK7eE81J132
 waZqyvq/OQS3LjUxCSkabwij89mxgA2GIddsCsJk0TBBNcwettDHaANRrLSKlFCRflv519cH4BD
 EX20SashnskHU4QjSXiYztjlBtoHnzNxSOgoDnUKrIMmx8ukNd1gf2u3FwvbyLRciIYy8CjhQPY
 m6oVQg9Hl7YKIS5Uy+GIxQ5CspIP2BBjCL/TGkz8BnF6nMdUn2qbf6FkkY=
X-Received: by 2002:a05:6402:358a:b0:5d9:a62:33e with SMTP id
 4fb4d7f45d1cf-5d972e162b0mr10754146a12.15.1736534802480;
 Fri, 10 Jan 2025 10:46:42 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IEyMqyWmrW0lTH/osdKXu5ANogZss5mgSvFJOeeXdy9sX4c4pbArHla0T+meklCekNzPvBYjA==
X-Received: by 2002:a05:6402:358a:b0:5d9:a62:33e with SMTP id
 4fb4d7f45d1cf-5d972e162b0mr10754132a12.15.1736534802098;
 Fri, 10 Jan 2025 10:46:42 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 09/38] rust: pl011: only leave embedded object initialization
 in instance_init
Date: Fri, 10 Jan 2025 19:45:50 +0100
Message-ID: <20250110184620.408302-10-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534965277019000
Content-Type: text/plain; charset="utf-8"

Leave IRQ and MMIO initialization to instance_post_init.  In Rust the
two callbacks are more distinct, because only instance_post_init has a
fully initialized object available.

While at it, add a wrapper for sysbus_init_mmio so that accesses to
the SysBusDevice correctly use shared references.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs | 18 ++++++++++--------
 rust/qemu-api/src/sysbus.rs      | 12 ++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi=
ce.rs
index 215f94a6e4a..72a4cea042c 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -145,6 +145,7 @@ impl ObjectImpl for PL011State {
     type ParentType =3D SysBusDevice;
=20
     const INSTANCE_INIT: Option<unsafe fn(&mut Self)> =3D Some(Self::init);
+    const INSTANCE_POST_INIT: Option<fn(&mut Self)> =3D Some(Self::post_in=
it);
 }
=20
 impl DeviceImpl for PL011State {
@@ -183,14 +184,6 @@ unsafe fn init(&mut self) {
                 Self::TYPE_NAME.as_ptr(),
                 0x1000,
             );
-
-            let sbd: &mut SysBusDevice =3D self.upcast_mut();
-            sysbus_init_mmio(sbd, addr_of_mut!(self.iomem));
-        }
-
-        for irq in self.interrupts.iter() {
-            let sbd: &SysBusDevice =3D self.upcast();
-            sbd.init_irq(irq);
         }
=20
         // SAFETY:
@@ -213,6 +206,15 @@ unsafe fn init(&mut self) {
         }
     }
=20
+    fn post_init(&mut self) {
+        let sbd: &SysBusDevice =3D self.upcast();
+
+        sbd.init_mmio(&self.iomem);
+        for irq in self.interrupts.iter() {
+            sbd.init_irq(irq);
+        }
+    }
+
     pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::Con=
trolFlow<u64, u64> {
         use RegisterOffset::*;
=20
diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs
index 8193734bde4..b96eaaf25f2 100644
--- a/rust/qemu-api/src/sysbus.rs
+++ b/rust/qemu-api/src/sysbus.rs
@@ -38,6 +38,18 @@ const fn as_mut_ptr(&self) -> *mut SysBusDevice {
         addr_of!(*self) as *mut _
     }
=20
+    /// Expose a memory region to the board so that it can give it an addr=
ess
+    /// in guest memory.  Note that the ordering of calls to `init_mmio` is
+    /// important, since whoever creates the sysbus device will refer to t=
he
+    /// region with a number that corresponds to the order of calls to
+    /// `init_mmio`.
+    pub fn init_mmio(&self, iomem: &bindings::MemoryRegion) {
+        assert!(bql_locked());
+        unsafe {
+            bindings::sysbus_init_mmio(self.as_mut_ptr(), addr_of!(*iomem)=
 as *mut _);
+        }
+    }
+
     /// Expose an interrupt source outside the device as a qdev GPIO outpu=
t.
     /// Note that the ordering of calls to `init_irq` is important, since
     /// whoever creates the sysbus device will refer to the interrupts with
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534950; cv=none;
	d=zohomail.com; s=zohoarc;
	b=WhTbClXI+CJBO/bFfLNMpLx3g0oscfl2K2qChckyD2RRfh8ZG/hZdFiNQWLVX4JHu9upg7KvZTs5O4BVdwp8x3rMM4JZ+EUENAJ9nQm0uQXocWCeKLgDCAVEdPvvgh/AZDqLBCmNhjfNnXSebc+guB6nCWDYxknqN+L9MsFoCG4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534950;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=yyNO/JTwvXtw4mxmLChlF/whck0cJNX1PORaIe032Kw=;
	b=RVBG3B/5apSonta2Hbh8vuXlvltCP9z7Q7IspJjXTvqwN/ZCE13YTmNxb5x4Vf7sAoNW6jgnHOSVk/1pU76SjvQNOscUnKtg0Gzn5Pxbn7MIoRw71RMOEb1rZfn6qp66/TiPq1M8jgL5SdBp4oN7NpKTnfFnB+wwvRl5dA2MF7M=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173653495054179.81345965170419;
 Fri, 10 Jan 2025 10:49:10 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2z-0001Fy-CI; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK22-0000FE-BR
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46: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 <pbonzini@redhat.com>)
 id 1tWK1y-00016W-5X
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:54 -0500
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-78-QVZ9-NVoPSeA8xFFXH49jg-1; Fri, 10 Jan 2025 13:46:46 -0500
Received: by mail-ej1-f71.google.com with SMTP id
 a640c23a62f3a-aab954d1116so237129466b.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:46 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90dace5sm196437966b.60.2025.01.10.10.46.42
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:43 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534808;
 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=yyNO/JTwvXtw4mxmLChlF/whck0cJNX1PORaIe032Kw=;
 b=SnD7tT270G72zMcKXjAVvrtvzkP/jp/ryqRzVIt3aq91s8DIrFj65lcnoN4ZbbkDSMnhIH
 qoaq8PVkPq1KNDS/DtN6il2Kb1s0ci4wa3I6JUrdkKR5MKVTtXBWfzSpczrkIZSennDl04
 aO+DAR4Fd//dPghsW8V0+ElCs4FihH0=
X-MC-Unique: QVZ9-NVoPSeA8xFFXH49jg-1
X-Mimecast-MFC-AGG-ID: QVZ9-NVoPSeA8xFFXH49jg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534804; x=1737139604;
 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=yyNO/JTwvXtw4mxmLChlF/whck0cJNX1PORaIe032Kw=;
 b=ho1vyIJf98SfCJIlViK0o1bXiYlgbk4ZxeUvomT1tDv4QFqcde8DjlxA/jauY1JrMe
 PJVtlUUQ4wAkbkza6OOMZWAiDga+9KHZhQv8TsrXY1xHNjwAyUDn3SumgSuA/rmylhiY
 CIccWLRM6ujpZAZ3nlryaWWOkULCZ3uL+A9/aCp6IyE+o/FcVkjv6jCve8zrC5+kQxyw
 HBoRAsTyAUEWdalD4jWFV9S5/cYLvHE9o6mPke5Nmo+QN7rrPuTNc3qOcwO6EwTlZQ6R
 1u2l5U9yROHngck0zlYuJs4sfbpzS6p0TJb01LbXBtZo3BAF7UPVZXwxYYaPtAb9rXcH
 t2iw==
X-Gm-Message-State: AOJu0Yy5xkpKSrvLfXhlHVZbDVIvTvEz9LlDgVXvA9hEfdQVr5h6QsVx
 SXGEQBIPoYRHnicLfGtRDHIbZweuyO0XOA0C1LsIOQkboXBSIi6laWvgOqpM6K804wZBfe99sXh
 wzf9nP1YVXRYCXkZRXCez/zuUvELz2Ku474/9DXUru+k9z0BW1bxYt/m0zXpFHlZqh+pWeI38Su
 yzf6XSfjy3RpD93IjBWyP/hzfTx5mEi36GY+v0j8w=
X-Gm-Gg: ASbGncucMVgupFEx/fq5VKhiO6pZCmBlJbyquo/1UVZZ5XUz4vrIfoNIVGbeMjdeY1n
 DjiOw2aoiP9cT8KgHvmvoXcN7YmXODIU7EiEy0OLcNz4RxzmAQoAMRl7i/Yh2qLpM9MyNAwF74o
 5dTd6gtYuZzLMbyB1rl3UlRmCun3CgAH9GNSAKci1ECT390tFyGQQGx0Ed102HWeK3hpo4Lnrwu
 5mi2dV3jx90YgYi7xqt8RQGA+wsxNNTfwKlLvRlOv4yePXLv32o8St9fsA=
X-Received: by 2002:a17:907:3da1:b0:aaf:3f57:9d2e with SMTP id
 a640c23a62f3a-ab2aaaf6571mr1070985866b.0.1736534804237;
 Fri, 10 Jan 2025 10:46:44 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IE+EbD5AWg+0Aviz6NYcbc6h9WY6tyecY758T69z79KF5nM936PvF/63yBLePnhWQC3laN2hA==
X-Received: by 2002:a17:907:3da1:b0:aaf:3f57:9d2e with SMTP id
 a640c23a62f3a-ab2aaaf6571mr1070983866b.0.1736534803802;
 Fri, 10 Jan 2025 10:46:43 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 10/38] rust: qom: make INSTANCE_POST_INIT take a shared
 reference
Date: Fri, 10 Jan 2025 19:45:51 +0100
Message-ID: <20250110184620.408302-11-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534951528116600
Content-Type: text/plain; charset="utf-8"

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs | 4 ++--
 rust/qemu-api/src/qom.rs         | 8 ++------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi=
ce.rs
index 72a4cea042c..6792d13fb77 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -145,7 +145,7 @@ impl ObjectImpl for PL011State {
     type ParentType =3D SysBusDevice;
=20
     const INSTANCE_INIT: Option<unsafe fn(&mut Self)> =3D Some(Self::init);
-    const INSTANCE_POST_INIT: Option<fn(&mut Self)> =3D Some(Self::post_in=
it);
+    const INSTANCE_POST_INIT: Option<fn(&Self)> =3D Some(Self::post_init);
 }
=20
 impl DeviceImpl for PL011State {
@@ -206,7 +206,7 @@ unsafe fn init(&mut self) {
         }
     }
=20
-    fn post_init(&mut self) {
+    fn post_init(&self) {
         let sbd: &SysBusDevice =3D self.upcast();
=20
         sbd.init_mmio(&self.iomem);
diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs
index b0332ba2477..97901fb9084 100644
--- a/rust/qemu-api/src/qom.rs
+++ b/rust/qemu-api/src/qom.rs
@@ -163,11 +163,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<()=
, fmt::Error> {
     // SAFETY: obj is an instance of T, since rust_instance_post_init<T>
     // 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_in=
it().
-    // The receiver should be &self, not &mut self.
-    T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::<T>() })
+    T::INSTANCE_POST_INIT.unwrap()(unsafe { &*obj.cast::<T>() })
 }
=20
 unsafe extern "C" fn rust_class_init<T: ObjectType + ClassInitImpl<T::Clas=
s>>(
@@ -463,7 +459,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl<Self::=
Class> {
=20
     /// Function that is called to finish initialization of an object, once
     /// `INSTANCE_INIT` functions have been called.
-    const INSTANCE_POST_INIT: Option<fn(&mut Self)> =3D None;
+    const INSTANCE_POST_INIT: Option<fn(&Self)> =3D None;
=20
     /// Called on descendent classes after all parent class initialization
     /// has occurred, but before the class itself is initialized.  This
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535230; cv=none;
	d=zohomail.com; s=zohoarc;
	b=QSIkyAQkcIpns1CrRRnSj00CcW3v83oVcMAJcDwO77kVS4DqwMM0TK0vTnK8GAGBk7fV5QkkNsiQVRR3YNsyXEMppbBGkiFBDWFQZvtR13UREaN2H+Yqma/b+yIgLyvqkXfVxsE/fhdsiGFSUjakJTQ6jZw0dBrSGkjGlgWucTQ=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535230;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=S8n0kCt4mcc85Mr2w6mSqVhxshepjHtJ4wm1nMTk3V4=;
	b=hwMsbkXQMYRCq55QfcH1kx1tJQJH7OBjvTMbt1y7zmWsaInvw9F3hS52wvwM6+FM2dQYoHcltRQ0a8fxpo51C5GZAjOxwYnrV4i5B7RsTyLPaOBz3rIDWTOxgg3inOUK7GWWGJyc8b83ptT/1S1PeW9YO7Nok/mDmQb/JoOduSo=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535230507551.4880386267131;
 Fri, 10 Jan 2025 10:53:50 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2e-0000PZ-MU; Fri, 10 Jan 2025 13:47:35 -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 <pbonzini@redhat.com>)
 id 1tWK23-0000FJ-B7
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK21-00016x-73
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:46:54 -0500
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-237--YjIaeWzPGarHuSdY7cdaA-1; Fri, 10 Jan 2025 13:46:49 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-ab2e44dc9b8so133750966b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:49 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2eadb6638sm57728466b.43.2025.01.10.10.46.44
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534811;
 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=S8n0kCt4mcc85Mr2w6mSqVhxshepjHtJ4wm1nMTk3V4=;
 b=d6/xXZv/mr91602SGiCXm6gsQaOCK6TR6ZRpvZtYeUiq2Eg5LNX7/C4YlV+Ot7PPBtbAYF
 sLtcBvhnY69vhQWiPeGlG3NIOUXPxjfaekVjuG/6ks7Iu2m61cEU0v13cHiVgQc0N4qF6b
 On2W2tc8t3siV+ZhXfibPzfVRAVpGzk=
X-MC-Unique: -YjIaeWzPGarHuSdY7cdaA-1
X-Mimecast-MFC-AGG-ID: -YjIaeWzPGarHuSdY7cdaA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534807; x=1737139607;
 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=S8n0kCt4mcc85Mr2w6mSqVhxshepjHtJ4wm1nMTk3V4=;
 b=wlNJBxpVIPXbE0LkK362ZbWkybelT1j6ZebPgbCqL1QInBuhpki3em7kB8e5VXVcRF
 /+3bCk/18cIVD3nL0b1ucP6Ka0c3HcZOvKBfPhBgT9qioeY6DbfmjreTSMjGKcMC6jA/
 C7LDiQ3weyb64LPteNV1UQJscXQUx+50Tmq6OXYiUeO4nRIzfW7sPB92QLuN6wXQLhmv
 7Qx5Sbtsi+XnoqyYe3PYa1ePPNUyGGe434A+0k5bJFX/Hnm1HbCJ/5SNQHiZs756sRq2
 eaZQ4CFfacb8q+FeTzvYpxTdr2SiO+b71+bSlkg/erUDrreUmkxiG+FrrI5y1B8PsSJ4
 Ak2A==
X-Gm-Message-State: AOJu0Ywu1ctc3PiIRdu5GqvVPiq08fqc+Hfh/Pn4HQTVxZwRCfSynDZt
 xuwz31iM+lm6LXAbYav26NySKOK5RZv/KlIb0xatZVF07ssUKlnM/Y6762zYrX75lLKZ2px8pL2
 igRACcf0KSY7fvcLc3myfSCaxvXKvj4Ilaa369j0wPCQOO/sfK+uUGglGv1Z3Fg1VuSW+Q5S2jx
 WHngsgHZoFEf6IH70fXUh0qi/qd7pos5/iQZWtEB4=
X-Gm-Gg: ASbGncvP5E5r8ypj0x1ziOeHV7c28tjn0nw/rKuvnWr5m/FrFujwlMwzJpfS+9QALgu
 xshJDWmxCuk7hl9MrRAsrZQJkQI5WyoDEwOMDjev61N7cRLsOjoMBAy0i/oXuyHIc5ralsxlVPT
 or3It9vMpC54LL+4x8I2qm1wniFoDwRtnypEmpvXbeXKCTXUXcEe2hKc6vyGdiOoQbHYgujkunG
 GsImEP6JGSDZtcGjlYXTpT4/dAXRWiFHWWo42nnUJ8ddfK1+AlxGt8AZsg=
X-Received: by 2002:a17:907:a089:b0:ab2:f255:59f5 with SMTP id
 a640c23a62f3a-ab2f2555c3dmr87351066b.16.1736534807187;
 Fri, 10 Jan 2025 10:46:47 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IF/pE4egY3x8fmRItuhx93k3akiy43aBObtP9ylLHepB4lkfHNm544iV4bQfjZku5L7XD7++A==
X-Received: by 2002:a17:907:a089:b0:ab2:f255:59f5 with SMTP id
 a640c23a62f3a-ab2f2555c3dmr87348466b.16.1736534806738;
 Fri, 10 Jan 2025 10:46:46 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 11/38] rust: qemu-api-macros: extend error reporting facility
 to parse errors
Date: Fri, 10 Jan 2025 19:45:52 +0100
Message-ID: <20250110184620.408302-12-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535231970019000
Content-Type: text/plain; charset="utf-8"

Generalize the CompileError tuple to an enum, that can be either an error
message or a parse error from syn.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api-macros/src/lib.rs   | 27 ++++++++++-----------------
 rust/qemu-api-macros/src/utils.rs | 26 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 17 deletions(-)
 create mode 100644 rust/qemu-api-macros/src/utils.rs

diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib=
.rs
index 0f04cca3841..539c48df298 100644
--- a/rust/qemu-api-macros/src/lib.rs
+++ b/rust/qemu-api-macros/src/lib.rs
@@ -3,57 +3,50 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
=20
 use proc_macro::TokenStream;
-use proc_macro2::Span;
-use quote::{quote, quote_spanned};
+use quote::quote;
 use syn::{
     parse_macro_input, parse_quote, punctuated::Punctuated, token::Comma, =
Data, DeriveInput, Field,
     Fields, Ident, Type, Visibility,
 };
=20
-struct CompileError(String, Span);
-
-impl From<CompileError> for proc_macro2::TokenStream {
-    fn from(err: CompileError) -> Self {
-        let CompileError(msg, span) =3D err;
-        quote_spanned! { span =3D> compile_error!(#msg); }
-    }
-}
+mod utils;
+use utils::MacroError;
=20
 fn get_fields<'a>(
     input: &'a DeriveInput,
     msg: &str,
-) -> Result<&'a Punctuated<Field, Comma>, CompileError> {
+) -> Result<&'a Punctuated<Field, Comma>, MacroError> {
     if let Data::Struct(s) =3D &input.data {
         if let Fields::Named(fs) =3D &s.fields {
             Ok(&fs.named)
         } else {
-            Err(CompileError(
+            Err(MacroError::Message(
                 format!("Named fields required for {}", msg),
                 input.ident.span(),
             ))
         }
     } else {
-        Err(CompileError(
+        Err(MacroError::Message(
             format!("Struct required for {}", msg),
             input.ident.span(),
         ))
     }
 }
=20
-fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), CompileError> {
+fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), MacroError> {
     let expected =3D parse_quote! { #[repr(C)] };
=20
     if input.attrs.iter().any(|attr| attr =3D=3D &expected) {
         Ok(())
     } else {
-        Err(CompileError(
+        Err(MacroError::Message(
             format!("#[repr(C)] required for {}", msg),
             input.ident.span(),
         ))
     }
 }
=20
-fn derive_object_or_error(input: DeriveInput) -> Result<proc_macro2::Token=
Stream, CompileError> {
+fn derive_object_or_error(input: DeriveInput) -> Result<proc_macro2::Token=
Stream, MacroError> {
     is_c_repr(&input, "#[derive(Object)]")?;
=20
     let name =3D &input.ident;
@@ -80,7 +73,7 @@ pub fn derive_object(input: TokenStream) -> TokenStream {
 }
=20
 #[rustfmt::skip::macros(quote)]
-fn derive_offsets_or_error(input: DeriveInput) -> Result<proc_macro2::Toke=
nStream, CompileError> {
+fn derive_offsets_or_error(input: DeriveInput) -> Result<proc_macro2::Toke=
nStream, MacroError> {
     is_c_repr(&input, "#[derive(offsets)]")?;
=20
     let name =3D &input.ident;
diff --git a/rust/qemu-api-macros/src/utils.rs b/rust/qemu-api-macros/src/u=
tils.rs
new file mode 100644
index 00000000000..02c91aed7f6
--- /dev/null
+++ b/rust/qemu-api-macros/src/utils.rs
@@ -0,0 +1,26 @@
+// Procedural macro utilities.
+// Author(s): Paolo Bonzini <pbonzini@redhat.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+use proc_macro2::Span;
+use quote::quote_spanned;
+
+pub enum MacroError {
+    Message(String, Span),
+    ParseError(syn::Error),
+}
+
+impl From<syn::Error> for MacroError {
+    fn from(err: syn::Error) -> Self {
+        MacroError::ParseError(err)
+    }
+}
+
+impl From<MacroError> for proc_macro2::TokenStream {
+    fn from(err: MacroError) -> Self {
+        match err {
+            MacroError::Message(msg, span) =3D> quote_spanned! { span =3D>=
 compile_error!(#msg); },
+            MacroError::ParseError(err) =3D> err.into_compile_error(),
+        }
+    }
+}
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534994; cv=none;
	d=zohomail.com; s=zohoarc;
	b=WNl4OTLQJiWgfpXpcOcMZzkKcF1QBia/A4PVENGCn9aEWzDkuESEwX1Sk2dyhCfCFr9J+QVs3YDm9+AKrVC/jxWjMxkBcqpOzpty2etPynXhEJUh2xx6sBpeIYEyc0RkLmkKpfMm3oy6HVr9Z/PV7nujORaxawTeDD/wOwKOOSM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534994;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=88Lnido+/J4sUIJeN8buUF3YDTjA0MP2vOjpZog+Shs=;
	b=MHUTPmkvL89LA6AzXfUqzaOQBBBZYDP5nWJqg15JaSl0BGuZL9z8gEOg98aN2UtN+hx1/6jQUHyQaGnZJst7OlXTUofaOu4Od31cj9L9WC+T1hK/UpVn6ToqwgjZfel/6BYT3gCl4Ss1ytcs2N6Kjh0QqiEG+qVK1OonZInU+7c=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173653499406956.53471472758531;
 Fri, 10 Jan 2025 10:49:54 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4E-0003Os-7z; Fri, 10 Jan 2025 13:49:10 -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 <pbonzini@redhat.com>)
 id 1tWK3C-000278-0n
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:48: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 <pbonzini@redhat.com>)
 id 1tWK3A-0001Gj-4J
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:48:05 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-103-9dVBjbP1NsucWMs2csdnCw-1; Fri, 10 Jan 2025 13:46:51 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d3d2cccbe4so2692479a12.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:51 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9904a411csm1906598a12.72.2025.01.10.10.46.47
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534883;
 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=88Lnido+/J4sUIJeN8buUF3YDTjA0MP2vOjpZog+Shs=;
 b=VwDGUHuYuYMDt+eri9QMuuSpKqjitn4TaTjF4eTM5r40VmgkCaoGbsrmakf/I/MaCsu2z0
 Ux8l/PJWtXLyXUnL7Ph6tSzJ4YLIv9jXJjeubRvsumS3RQtfhj3f/slgeKsLn9qd5SM34B
 havj8RzkLJyiyu5p70mDTE3/7tjWlDg=
X-MC-Unique: 9dVBjbP1NsucWMs2csdnCw-1
X-Mimecast-MFC-AGG-ID: 9dVBjbP1NsucWMs2csdnCw
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534809; x=1737139609;
 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=88Lnido+/J4sUIJeN8buUF3YDTjA0MP2vOjpZog+Shs=;
 b=RbswvjpwF/D16yhKi9L1+w5bSSNvOyNgrOZcGS3Z52o152o8Q1nh1cdlH36zRmbbRY
 7s7AR5FsZ0rg21QGVZtEI0jWzHAxzJHzIoV41rMwYJdNWlIxgdqo6uIW3eqiwqREe2gU
 5T0xpU1xVipuxPpA2df4UBic3YGcT4CfmXvdlOZdRYYVAjBRCk0N81oQuLZwQi8tcIcE
 DCRq8yoyqJf30i0rCmiVQ2rHmJQTxrU5n2OteVt6Qpt0NeZX1U5Ej8kE2emy8SjEdaR3
 OH7Z/2mDy+rs2Dmi9Q+bRTOq1ygp1++lasSSBaxU28gZ6699obxOin+JWnGfKSW1VRCh
 /6tQ==
X-Gm-Message-State: AOJu0YxTeUdpqnnzqcm6Lj8MNJ8aulutjRIyU3ZHyx1oOIKO4zQsYsNR
 xBF5g9Klp7lBsiHrs20ZVI5gtzMW/UJIl2ZFOW39Yokbqp2nOVaw1MRHER+Lw5AVTJmMPg/eAN5
 BYM4qDxvI4scIRqseVrcO/PvybLnGx8xn+l9fzyXbzO31uuf6scNFBDpuGvpaOZcE7x348rS9hw
 A+lVcxNyspoOMfjg3jxtDPUMa8icQoeTvkNnC/mdU=
X-Gm-Gg: ASbGnctE1do1vqMlj1QQc3cHBhD8YhI1+RSuOON6Je/7DLufsvGWr6NI4vyZwDaRC3w
 J158Fz2Vv533dlxMFDMx/gZdpJEi+nragaSInWp8KleqSPD+muOmacaK1Xp9P9MWeNzuTNk8vCW
 +mN6U9Mc0xO4dvD+OtJaGgz94s9yMzejT/9qrRXLJ8DIyxXgztHz8OjUpsGnoWPWr9bLATNaHZd
 othsij4wCbUGSYLqYErjbmQnhU0gUNploDtIiscfUC27qNS9EDEixWiv24=
X-Received: by 2002:a05:6402:270d:b0:5d3:d4cf:fea0 with SMTP id
 4fb4d7f45d1cf-5d972e4c62emr9669957a12.21.1736534809379;
 Fri, 10 Jan 2025 10:46:49 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGZNtxcF55o60VmqOVUIE+KIBufqGCdUqcSEtMDqK+albPDR+2ofPFhcgVnrPoRnId0rX2fkQ==
X-Received: by 2002:a05:6402:270d:b0:5d3:d4cf:fea0 with SMTP id
 4fb4d7f45d1cf-5d972e4c62emr9669946a12.21.1736534808928;
 Fri, 10 Jan 2025 10:46:48 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 12/38] rust: qemu-api-macros: add automatic TryFrom/TryInto
 derivation
Date: Fri, 10 Jan 2025 19:45:53 +0100
Message-ID: <20250110184620.408302-13-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534995127019000
Content-Type: text/plain; charset="utf-8"

This is going to be fairly common. Using a custom procedural macro
provides better error messages and automatically finds the right
type.

Note that this is different from the same-named macro in the
derive_more crate.  That one provides conversion from e.g. tuples
to enums with tuple variants, not from integers to enums.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/lib.rs   | 28 +------------
 rust/qemu-api-macros/src/lib.rs | 74 ++++++++++++++++++++++++++++++++-
 2 files changed, 73 insertions(+), 29 deletions(-)

diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs
index 69064d6929b..0a89d393e0f 100644
--- a/rust/hw/char/pl011/src/lib.rs
+++ b/rust/hw/char/pl011/src/lib.rs
@@ -45,7 +45,7 @@
 #[doc(alias =3D "offset")]
 #[allow(non_camel_case_types)]
 #[repr(u64)]
-#[derive(Debug)]
+#[derive(Debug, qemu_api_macros::TryInto)]
 pub enum RegisterOffset {
     /// Data Register
     ///
@@ -102,32 +102,6 @@ pub enum RegisterOffset {
     //Reserved =3D 0x04C,
 }
=20
-impl core::convert::TryFrom<u64> for RegisterOffset {
-    type Error =3D u64;
-
-    fn try_from(value: u64) -> Result<Self, Self::Error> {
-        macro_rules! case {
-            ($($discriminant:ident),*$(,)*) =3D> {
-                /* check that matching on all macro arguments compiles, wh=
ich means we are not
-                 * missing any enum value; if the type definition ever cha=
nges this will stop
-                 * compiling.
-                 */
-                const fn _assert_exhaustive(val: RegisterOffset) {
-                    match val {
-                        $(RegisterOffset::$discriminant =3D> (),)*
-                    }
-                }
-
-                match value {
-                    $(x if x =3D=3D Self::$discriminant as u64 =3D> Ok(Sel=
f::$discriminant),)*
-                     _ =3D> Err(value),
-                }
-            }
-        }
-        case! { DR, RSR, FR, FBRD, ILPR, IBRD, LCR_H, CR, FLS, IMSC, RIS, =
MIS, ICR, DMACR }
-    }
-}
-
 pub mod registers {
     //! Device registers exposed as typed structs which are backed by arbi=
trary
     //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc.
diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib=
.rs
index 539c48df298..7ec218202f4 100644
--- a/rust/qemu-api-macros/src/lib.rs
+++ b/rust/qemu-api-macros/src/lib.rs
@@ -5,8 +5,8 @@
 use proc_macro::TokenStream;
 use quote::quote;
 use syn::{
-    parse_macro_input, parse_quote, punctuated::Punctuated, token::Comma, =
Data, DeriveInput, Field,
-    Fields, Ident, Type, Visibility,
+    parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spann=
ed, token::Comma, Data,
+    DeriveInput, Field, Fields, Ident, Meta, Path, Token, Type, Variant, V=
isibility,
 };
=20
 mod utils;
@@ -98,3 +98,73 @@ pub fn derive_offsets(input: TokenStream) -> TokenStream=
 {
=20
     TokenStream::from(expanded)
 }
+
+#[allow(non_snake_case)]
+fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result<Path, MacroError>=
 {
+    let repr =3D input.attrs.iter().find(|attr| attr.path().is_ident("repr=
"));
+    if let Some(repr) =3D repr {
+        let nested =3D repr.parse_args_with(Punctuated::<Meta, Token![,]>:=
:parse_terminated)?;
+        for meta in nested {
+            match meta {
+                Meta::Path(path) if path.is_ident("u8") =3D> return Ok(pat=
h),
+                Meta::Path(path) if path.is_ident("u16") =3D> return Ok(pa=
th),
+                Meta::Path(path) if path.is_ident("u32") =3D> return Ok(pa=
th),
+                Meta::Path(path) if path.is_ident("u64") =3D> return Ok(pa=
th),
+                _ =3D> {}
+            }
+        }
+    }
+
+    Err(MacroError::Message(
+        format!("#[repr(u8/u16/u32/u64) required for {}", msg),
+        input.ident.span(),
+    ))
+}
+
+fn get_variants(input: &DeriveInput) -> Result<&Punctuated<Variant, Comma>=
, MacroError> {
+    if let Data::Enum(e) =3D &input.data {
+        if let Some(v) =3D e.variants.iter().find(|v| v.fields !=3D Fields=
::Unit) {
+            return Err(MacroError::Message(
+                "Cannot derive TryInto for enum with non-unit variants.".t=
o_string(),
+                v.fields.span(),
+            ));
+        }
+        Ok(&e.variants)
+    } else {
+        Err(MacroError::Message(
+            "Cannot derive TryInto for union or struct.".to_string(),
+            input.ident.span(),
+        ))
+    }
+}
+
+#[rustfmt::skip::macros(quote)]
+fn derive_tryinto_or_error(input: DeriveInput) -> Result<proc_macro2::Toke=
nStream, MacroError> {
+    let repr =3D get_repr_uN(&input, "#[derive(TryInto)]")?;
+
+    let name =3D &input.ident;
+    let variants =3D get_variants(&input)?;
+    let discriminants: Vec<&Ident> =3D variants.iter().map(|f| &f.ident).c=
ollect();
+
+    Ok(quote! {
+        impl core::convert::TryFrom<#repr> for #name {
+            type Error =3D #repr;
+
+            fn try_from(value: #repr) -> Result<Self, Self::Error> {
+                #(const #discriminants: #repr =3D #name::#discriminants as=
 #repr;)*;
+                match value {
+                    #(#discriminants =3D> Ok(Self::#discriminants),)*
+                    _ =3D> Err(value),
+                }
+            }
+        }
+    })
+}
+
+#[proc_macro_derive(TryInto)]
+pub fn derive_tryinto(input: TokenStream) -> TokenStream {
+    let input =3D parse_macro_input!(input as DeriveInput);
+    let expanded =3D derive_tryinto_or_error(input).unwrap_or_else(Into::i=
nto);
+
+    TokenStream::from(expanded)
+}
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535145; cv=none;
	d=zohomail.com; s=zohoarc;
	b=QXrHFpO5bVoIvFLvWcs7Y6YZBrL3d76S1GC43CKD+3q42RL2pjVaQbY1ORlGPG61bRms4EZxJDqj1GCkkj2XTYYqjJN30G7iuA3AvHjyLd0BbMRZhG5VBXJF9CC2F8T7DpST1BnUKcrOY8K81RdeZ12Zv40qAnA4laHIHbjMEhw=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535145;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=T21y/qv6KGXhkm5awrBknNed29ZtW5ncvJ4QzS+vajE=;
	b=TPbd8GZSWFe9qJaKIZH1CF5FxzwsVbPPFofqKlW8jCfvBzJtRxQWVfiw/M7gZk25Fa1ysJ8J6VSgYYDJZxaTkOThDKlXKchIvRZwOHV62AEJC318gYjWo/m7P0RKDGGYb8CiVUoE8X9V4NMckY9CBfbR50w+aNhe2l+kz/xJrLE=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535145552267.7055100767685;
 Fri, 10 Jan 2025 10:52:25 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK35-0001n8-Bx; Fri, 10 Jan 2025 13:48: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 <pbonzini@redhat.com>)
 id 1tWK28-0000Fg-VS
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK26-00017V-AW
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:00 -0500
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-371-zTxq1llnMIqKZX99AAlpWw-1; Fri, 10 Jan 2025 13:46:54 -0500
Received: by mail-ed1-f69.google.com with SMTP id
 4fb4d7f45d1cf-5d124077928so1969239a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:54 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c906004fsm192989866b.30.2025.01.10.10.46.49
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:50 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534816;
 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=T21y/qv6KGXhkm5awrBknNed29ZtW5ncvJ4QzS+vajE=;
 b=BYq2cpHY79G++F6IwUc/ZGN8l8zUGT6igoX5X+XQnnOgUHVeE1TBtyq+JoN0ejJDxjnvO7
 J5baogjkRI+W0tRtq2sQ94Kskt8lBoW6xYomXk1aW3ynlEj7rveTscIFUxBs8tIylVwKX3
 3hZIJj/rkEzILCNBkE+DC/Z6TnktoBs=
X-MC-Unique: zTxq1llnMIqKZX99AAlpWw-1
X-Mimecast-MFC-AGG-ID: zTxq1llnMIqKZX99AAlpWw
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534812; x=1737139612;
 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=T21y/qv6KGXhkm5awrBknNed29ZtW5ncvJ4QzS+vajE=;
 b=ZVXYa3zX9UOhqxKF+Rkjfj390xZx3knbp6erDAf2dZjsmhmqDFeQDl0fi+QDlHfL51
 Tm6kSy2A3opDWLIUcFh2WRikkAiEtgJVkZoZTxCEa7zKxhwyj0ZyncKTUg6gA7H9G/w5
 5ftbTQ50saov0w1Rzm+GDxT3aZa+zgUbtBSnZdUi9waqsfZ5lDPo+wziSGQzsbgLfAbW
 pfgfOetqI1/EI5KL2NwXp5CymEXhTKvEYHL/Uh38t97hvSsLKs09hqAGVQvqo/zFVIj8
 yAWN9HX0cKqqTPW5FZ5NQey7w9WT6hH/FvYgxnyDmnM8Lh5cQjBLVBiLcmzKTek9ChjW
 /MiQ==
X-Gm-Message-State: AOJu0YyexqaRY2RreN7Kpz/SgztNj0JOjBOwbD6oyIIr+hdaUi1ZYuJL
 1Y4XktUtMxFBv54Ji2bZuOOMRk3gWedUJJYRouxzNNtisLkJ/jwQ/dIkkyGJkyFxCGMhlzUhzBo
 o7DDFJfYdoB6xmwnpaSUl9Wq9/VQW6M7d6n5c43+67EJIhLjphpnmAqFoP8VUN8VW/laotK0WX0
 gXxkzPjShc3y5p00w05sVSyaIedM/BLsGtnM0Uhw4=
X-Gm-Gg: ASbGncvyb0IbdvruJbL4q/XlgHxpGX+iKrgyJTFmV0cTiYTJ35rkY/2YFYo5Sc1OIf3
 1M5A/VlWxebeJug1YIbsfQuZIR/azIeQUjLZmIgR+/g2gz0+hILOwb8fnuoNK+74fPyxmnZL4Km
 J+JvZIi/P2BBOSIgLKs00qSaAr74vkroJIzpCsF+KvtUu+Zehv92XGcPuTWGPWxa+rQhUnl31nY
 Wl/4bpQG7/BriTpaqXylpFJ+o440Rc+hBB7scNxtbIc9OUIoAv4Ul3uxF0=
X-Received: by 2002:a17:907:2cc5:b0:aab:cd45:5d3c with SMTP id
 a640c23a62f3a-ab2abdbfa0bmr1140054866b.50.1736534812444;
 Fri, 10 Jan 2025 10:46:52 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFulgBXuRMrjbpVT2zuHYlxQVC5eIzqdaSHJsjFaLi/GNflO8mx/XmyaQVqrH6VZQ+Dt0rXEA==
X-Received: by 2002:a17:907:2cc5:b0:aab:cd45:5d3c with SMTP id
 a640c23a62f3a-ab2abdbfa0bmr1140052566b.50.1736534811930;
 Fri, 10 Jan 2025 10:46:51 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 13/38] rust: qdev: expose inherited methods to subclasses of
 SysBusDevice
Date: Fri, 10 Jan 2025 19:45:54 +0100
Message-ID: <20250110184620.408302-14-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535147955019000
Content-Type: text/plain; charset="utf-8"

The ObjectDeref trait now provides all the magic that is required to fake
inheritance.  Replace the "impl SysBusDevice" block of qemu_api::sysbus
with a trait, so that sysbus_init_irq() can be invoked as "self.init_irq()"
without any intermediate upcast.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs |  6 ++----
 rust/qemu-api/src/irq.rs         |  3 +--
 rust/qemu-api/src/prelude.rs     |  2 ++
 rust/qemu-api/src/sysbus.rs      | 17 +++++++++--------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi=
ce.rs
index 6792d13fb77..994c2fc0593 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -207,11 +207,9 @@ unsafe fn init(&mut self) {
     }
=20
     fn post_init(&self) {
-        let sbd: &SysBusDevice =3D self.upcast();
-
-        sbd.init_mmio(&self.iomem);
+        self.init_mmio(&self.iomem);
         for irq in self.interrupts.iter() {
-            sbd.init_irq(irq);
+            self.init_irq(irq);
         }
     }
=20
diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs
index 6258141bdf0..378e5202951 100644
--- a/rust/qemu-api/src/irq.rs
+++ b/rust/qemu-api/src/irq.rs
@@ -24,8 +24,7 @@
 ///
 /// 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
+/// a function such as [`SysBusDeviceMethods::init_irq`], and
 /// initially leaves the pointer to a NULL value, representing an unconnec=
ted
 /// interrupt. To connect it, whoever creates the device fills the pointer=
 with
 /// the sink's `IRQState *`, for example using `sysbus_connect_irq`.  Beca=
use
diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs
index 6f32deeb2ed..4ea70b9c823 100644
--- a/rust/qemu-api/src/prelude.rs
+++ b/rust/qemu-api/src/prelude.rs
@@ -16,3 +16,5 @@
 pub use crate::qom::ObjectType;
=20
 pub use crate::qom_isa;
+
+pub use crate::sysbus::SysBusDeviceMethods;
diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs
index b96eaaf25f2..e6762b5c145 100644
--- a/rust/qemu-api/src/sysbus.rs
+++ b/rust/qemu-api/src/sysbus.rs
@@ -32,18 +32,17 @@ fn class_init(sdc: &mut SysBusDeviceClass) {
     }
 }
=20
-impl SysBusDevice {
-    /// Return `self` cast to a mutable pointer, for use in calls to C cod=
e.
-    const fn as_mut_ptr(&self) -> *mut SysBusDevice {
-        addr_of!(*self) as *mut _
-    }
-
+/// Trait for methods of [`SysBusDevice`] and its subclasses.
+pub trait SysBusDeviceMethods: ObjectDeref
+where
+    Self::Target: IsA<SysBusDevice>,
+{
     /// Expose a memory region to the board so that it can give it an addr=
ess
     /// in guest memory.  Note that the ordering of calls to `init_mmio` is
     /// important, since whoever creates the sysbus device will refer to t=
he
     /// region with a number that corresponds to the order of calls to
     /// `init_mmio`.
-    pub fn init_mmio(&self, iomem: &bindings::MemoryRegion) {
+    fn init_mmio(&self, iomem: &bindings::MemoryRegion) {
         assert!(bql_locked());
         unsafe {
             bindings::sysbus_init_mmio(self.as_mut_ptr(), addr_of!(*iomem)=
 as *mut _);
@@ -54,10 +53,12 @@ pub fn init_mmio(&self, iomem: &bindings::MemoryRegion)=
 {
     /// 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) {
+    fn init_irq(&self, irq: &InterruptSource) {
         assert!(bql_locked());
         unsafe {
             bindings::sysbus_init_irq(self.as_mut_ptr(), irq.as_ptr());
         }
     }
 }
+
+impl<R: ObjectDeref> SysBusDeviceMethods for R where R::Target: IsA<SysBus=
Device> {}
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535001; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Fgcp3D3BMnMLbFF+2CZfeDEBhaoNl2x1j8Cyghn/GbcBh/5NHTpSPK17CVwDQMnRmOYdLcKIzWfmTWOySzjJ2Sv9EW/rdKgRKWrp0QAawCkuMFvyM2vd95dc38kYOdAGc2n7K3Rbnk6Y3L7hMehFUYypFmnU6DCbdRtKVWnIWas=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535001;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=PUb46DKoHBmGAkluDAsTMlpBG23EsSqfrfrjdnr3nng=;
	b=mLQJ4gNNw7+3FQWZoresoSWjeWUNLd/UOxiw90JARfDmhAD191YkJl8ufZiPB6Jy8ZG0Rnrm1qKdbaH1sCox9fVkpkqYXCa+LFkKTWkUyYX59cgagMRp4OE1E4M2jqK5iQuRieHYGMnoPglyFlLNEFvXltDYa9paTYPtSDugYiM=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535001214407.78291520909534;
 Fri, 10 Jan 2025 10:50:01 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2W-0000MP-Dt; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2D-0000Fy-4E
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK28-00017h-NT
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:04 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-458-aJ7ayszdO5mmNLzzI4LZ6A-1; Fri, 10 Jan 2025 13:46:58 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa67855b3deso200696666b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:46:57 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c9060bccsm192107166b.22.2025.01.10.10.46.52
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:52 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534819;
 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=PUb46DKoHBmGAkluDAsTMlpBG23EsSqfrfrjdnr3nng=;
 b=Q0Q3N5I9z9OuhsEd9QXAaROzXVdFShw391ZDoh60ECH1Z+Itqs/pvGHhesBEHeuRFZozSG
 9HulCmrmKvHw4bSDrsiGQaTgfHCCjtatCne3m0lugc4Dmn8+gJ5EOnmbtJNXLQZfVCHqMi
 nwDU8fIvoJW5KZiFPTcihg5ZcG643IA=
X-MC-Unique: aJ7ayszdO5mmNLzzI4LZ6A-1
X-Mimecast-MFC-AGG-ID: aJ7ayszdO5mmNLzzI4LZ6A
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534816; x=1737139616;
 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=PUb46DKoHBmGAkluDAsTMlpBG23EsSqfrfrjdnr3nng=;
 b=sSZPPbjfkwdRupuDi/FdKxy5Rq64C4b8QeeBJLbEHqzMB8iJ2ly4XHc1eYYM8ykRKR
 /LIZYEs1n1pv97mr/cmowQpBMUXqrBBkdd+h2wJlYOp0a/XivKxuXz/vc8AXruO5Gbvl
 +W1CM7sUWLGezus4xIIYFlu6WJoDDwGxWj45P59v9B4dyEArub3BxK7pk6hgERGC5vm4
 5Dm0aHi+ImJhkE1ge+s9wavhB6QVG3RzlFlZkvPapRJdq8u322/OAJZZ5LOkixsw2B97
 hAwp5FJrkcL8IiAis2NlOVuXwpqGIDFTuKFcLNosqaAN1rhstKjTXY4u04DEg1Fm4zCw
 dxnQ==
X-Gm-Message-State: AOJu0YxmBlSYfeoT3u6NyvFWYTMfUUWySHEIiUlp6kGb+jeQ1Szb2QIE
 HxKYFvY631iKascR85LuIt9RZ9aoxIlutLOe8fpZ5lRng3H377C2/9bmUWfY8y9KfjjaJBg8GG8
 OmPv3mpJPz72pfVWviDcMAwV43pLECp+Y/KMHpCP7J/AwE/r769WxTer6FbvijJSQkl/wyjODkF
 zoozoGFwHpGtpYR00+E1S/pCJPnysk8ZK/xf6R1B4=
X-Gm-Gg: ASbGncvrzOfLNLeG7tUWJVNU0WF+64R8tVCdu0LioxQa4YZFWovrGZIOWFxZAvENn8r
 LeDykQRNw5Gus6zYr9uzTk5HsgS+zcudMONkZGsgxqPeZlaTs5v2NuN0Uyu4CzwRMRwn8pZ3yUt
 78ROm0qoDT2rpGK/KvmCHeqDIYjERrhNp3Yxo0cAaGbgp8JHXzY7HblCouRYZ8/9XlfywJuPaJV
 hJJ3PHA6OYoJlmQo50xzYjue0FwHEpZBU6+qNTyBKkMRuXJiK1sK07EB3Q=
X-Received: by 2002:a17:907:1a4f:b0:aaf:c27e:12e8 with SMTP id
 a640c23a62f3a-ab2abc78ab3mr786867266b.37.1736534815705;
 Fri, 10 Jan 2025 10:46:55 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGl8WNxoQIigC26olgCKQG4D3dx+ko3Ug3aFqe/B7ue5pu9kI0MxOysyqQu/bMNDKKEPdh2Ig==
X-Received: by 2002:a17:907:1a4f:b0:aaf:c27e:12e8 with SMTP id
 a640c23a62f3a-ab2abc78ab3mr786865166b.37.1736534815028;
 Fri, 10 Jan 2025 10:46:55 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 14/38] rust: hide warnings for subprojects
Date: Fri, 10 Jan 2025 19:45:55 +0100
Message-ID: <20250110184620.408302-15-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535003560019000
Content-Type: text/plain; charset="utf-8"

This matches cargo's own usage of "--cap-lints allow" when building
dependencies.  The dummy changes to the .wrap files help Meson notice
that the subproject is out of date.

Also remove an unnecessary subprojects/unicode-ident-1-rs/meson.build file.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 subprojects/arbitrary-int-1-rs.wrap           |  3 +++
 subprojects/bilge-0.2-rs.wrap                 |  3 +++
 subprojects/bilge-impl-0.2-rs.wrap            |  3 +++
 subprojects/either-1-rs.wrap                  |  3 +++
 subprojects/itertools-0.11-rs.wrap            |  3 +++
 .../arbitrary-int-1-rs/meson.build            |  1 +
 .../packagefiles/bilge-0.2-rs/meson.build     |  1 +
 .../bilge-impl-0.2-rs/meson.build             |  1 +
 .../packagefiles/either-1-rs/meson.build      |  1 +
 .../itertools-0.11-rs/meson.build             |  1 +
 .../proc-macro-error-1-rs/meson.build         |  1 +
 .../proc-macro-error-attr-1-rs/meson.build    |  1 +
 .../packagefiles/proc-macro2-1-rs/meson.build |  1 +
 .../packagefiles/quote-1-rs/meson.build       |  1 +
 subprojects/packagefiles/syn-2-rs/meson.build |  1 +
 .../unicode-ident-1-rs/meson.build            |  1 +
 subprojects/proc-macro-error-1-rs.wrap        |  3 +++
 subprojects/proc-macro-error-attr-1-rs.wrap   |  3 +++
 subprojects/proc-macro2-1-rs.wrap             |  3 +++
 subprojects/quote-1-rs.wrap                   |  3 +++
 subprojects/syn-2-rs.wrap                     |  3 +++
 subprojects/unicode-ident-1-rs.wrap           |  3 +++
 subprojects/unicode-ident-1-rs/meson.build    | 20 -------------------
 23 files changed, 44 insertions(+), 20 deletions(-)
 delete mode 100644 subprojects/unicode-ident-1-rs/meson.build

diff --git a/subprojects/arbitrary-int-1-rs.wrap b/subprojects/arbitrary-in=
t-1-rs.wrap
index e580538a877..a1838b20b0f 100644
--- a/subprojects/arbitrary-int-1-rs.wrap
+++ b/subprojects/arbitrary-int-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D arbitrary-int-1.2.7.tar.gz
 source_hash =3D c84fc003e338a6f69fbd4f7fe9f92b535ff13e9af8997f3b14b6ddff8b=
1df46d
 #method =3D cargo
 patch_directory =3D arbitrary-int-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/bilge-0.2-rs.wrap b/subprojects/bilge-0.2-rs.wrap
index 7a4339d2989..900bb1497b9 100644
--- a/subprojects/bilge-0.2-rs.wrap
+++ b/subprojects/bilge-0.2-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D bilge-0.2.0.tar.gz
 source_hash =3D dc707ed8ebf81de5cd6c7f48f54b4c8621760926cdf35a57000747c512=
e67b57
 #method =3D cargo
 patch_directory =3D bilge-0.2-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.=
2-rs.wrap
index b24c34a9043..d14c3dc769b 100644
--- a/subprojects/bilge-impl-0.2-rs.wrap
+++ b/subprojects/bilge-impl-0.2-rs.wrap
@@ -6,3 +6,6 @@ source_hash =3D feb11e002038ad243af39c2068c8a72bcf147acf050=
25dcdb916fcc000adb2d8
 #method =3D cargo
 patch_directory =3D bilge-impl-0.2-rs
 diff_files =3D bilge-impl-1.63.0.patch
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/either-1-rs.wrap b/subprojects/either-1-rs.wrap
index 6046712036c..352e11cfee6 100644
--- a/subprojects/either-1-rs.wrap
+++ b/subprojects/either-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D either-1.12.0.tar.gz
 source_hash =3D 3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb233=
85b58b
 #method =3D cargo
 patch_directory =3D either-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/itertools-0.11-rs.wrap b/subprojects/itertools-0.1=
1-rs.wrap
index 66b05252cd5..ee12d0053bc 100644
--- a/subprojects/itertools-0.11-rs.wrap
+++ b/subprojects/itertools-0.11-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D itertools-0.11.0.tar.gz
 source_hash =3D b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418=
c3fe57
 #method =3D cargo
 patch_directory =3D itertools-0.11-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/packagefiles/arbitrary-int-1-rs/meson.build b/subp=
rojects/packagefiles/arbitrary-int-1-rs/meson.build
index cff3f62ce74..00733d1faab 100644
--- a/subprojects/packagefiles/arbitrary-int-1-rs/meson.build
+++ b/subprojects/packagefiles/arbitrary-int-1-rs/meson.build
@@ -9,6 +9,7 @@ _arbitrary_int_rs =3D static_library(
   files('src/lib.rs'),
   gnu_symbol_visibility: 'hidden',
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
+  rust_args: ['--cap-lints', 'allow'],
   rust_abi: 'rust',
   dependencies: [],
 )
diff --git a/subprojects/packagefiles/bilge-0.2-rs/meson.build b/subproject=
s/packagefiles/bilge-0.2-rs/meson.build
index e69bac91b40..ce13d0fe80f 100644
--- a/subprojects/packagefiles/bilge-0.2-rs/meson.build
+++ b/subprojects/packagefiles/bilge-0.2-rs/meson.build
@@ -17,6 +17,7 @@ lib =3D static_library(
   'src/lib.rs',
   override_options : ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_abi : 'rust',
+  rust_args: ['--cap-lints', 'allow'],
   dependencies: [
     arbitrary_int_dep,
     bilge_impl_dep,
diff --git a/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build b/subpr=
ojects/packagefiles/bilge-impl-0.2-rs/meson.build
index f8f3486fc08..42b03dcd53c 100644
--- a/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build
+++ b/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build
@@ -25,6 +25,7 @@ _bilge_impl_rs =3D rust.proc_macro(
   files('src/lib.rs'),
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'use_fallback',
     '--cfg', 'feature=3D"syn-error"',
     '--cfg', 'feature=3D"proc-macro"',
diff --git a/subprojects/packagefiles/either-1-rs/meson.build b/subprojects=
/packagefiles/either-1-rs/meson.build
index 608e64e31fc..04c96cc5fb3 100644
--- a/subprojects/packagefiles/either-1-rs/meson.build
+++ b/subprojects/packagefiles/either-1-rs/meson.build
@@ -11,6 +11,7 @@ _either_rs =3D static_library(
   override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'feature=3D"use_std"',
     '--cfg', 'feature=3D"use_alloc"',
   ],
diff --git a/subprojects/packagefiles/itertools-0.11-rs/meson.build b/subpr=
ojects/packagefiles/itertools-0.11-rs/meson.build
index 30982a4ee76..2a3fbe9ee5a 100644
--- a/subprojects/packagefiles/itertools-0.11-rs/meson.build
+++ b/subprojects/packagefiles/itertools-0.11-rs/meson.build
@@ -15,6 +15,7 @@ _itertools_rs =3D static_library(
   override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'feature=3D"use_std"',
     '--cfg', 'feature=3D"use_alloc"',
   ],
diff --git a/subprojects/packagefiles/proc-macro-error-1-rs/meson.build b/s=
ubprojects/packagefiles/proc-macro-error-1-rs/meson.build
index ae27a696862..10c2741085c 100644
--- a/subprojects/packagefiles/proc-macro-error-1-rs/meson.build
+++ b/subprojects/packagefiles/proc-macro-error-1-rs/meson.build
@@ -20,6 +20,7 @@ _proc_macro_error_rs =3D static_library(
   override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'use_fallback',
     '--cfg', 'feature=3D"syn-error"',
     '--cfg', 'feature=3D"proc-macro"',
diff --git a/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.buil=
d b/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build
index 3281b264333..c4c4c5e397c 100644
--- a/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build
+++ b/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build
@@ -16,6 +16,7 @@ _proc_macro_error_attr_rs =3D rust.proc_macro(
   files('src/lib.rs'),
   override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'],
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'use_fallback',
     '--cfg', 'feature=3D"syn-error"',
     '--cfg', 'feature=3D"proc-macro"'
diff --git a/subprojects/packagefiles/proc-macro2-1-rs/meson.build b/subpro=
jects/packagefiles/proc-macro2-1-rs/meson.build
index f9c8675ebad..5759df3ecc9 100644
--- a/subprojects/packagefiles/proc-macro2-1-rs/meson.build
+++ b/subprojects/packagefiles/proc-macro2-1-rs/meson.build
@@ -15,6 +15,7 @@ _proc_macro2_rs =3D static_library(
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'feature=3D"proc-macro"',
     '--cfg', 'no_literal_byte_character',
     '--cfg', 'no_literal_c_string',
diff --git a/subprojects/packagefiles/quote-1-rs/meson.build b/subprojects/=
packagefiles/quote-1-rs/meson.build
index 7f7792569b9..bf41fad99bb 100644
--- a/subprojects/packagefiles/quote-1-rs/meson.build
+++ b/subprojects/packagefiles/quote-1-rs/meson.build
@@ -15,6 +15,7 @@ _quote_rs =3D static_library(
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'feature=3D"proc-macro"',
   ],
   dependencies: [
diff --git a/subprojects/packagefiles/syn-2-rs/meson.build b/subprojects/pa=
ckagefiles/syn-2-rs/meson.build
index 2c62cf7e1b0..a0094174084 100644
--- a/subprojects/packagefiles/syn-2-rs/meson.build
+++ b/subprojects/packagefiles/syn-2-rs/meson.build
@@ -19,6 +19,7 @@ _syn_rs =3D static_library(
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_abi: 'rust',
   rust_args: [
+    '--cap-lints', 'allow',
     '--cfg', 'feature=3D"full"',
     '--cfg', 'feature=3D"derive"',
     '--cfg', 'feature=3D"parsing"',
diff --git a/subprojects/packagefiles/unicode-ident-1-rs/meson.build b/subp=
rojects/packagefiles/unicode-ident-1-rs/meson.build
index 9d76ebbd1ad..11a5dab97df 100644
--- a/subprojects/packagefiles/unicode-ident-1-rs/meson.build
+++ b/subprojects/packagefiles/unicode-ident-1-rs/meson.build
@@ -10,6 +10,7 @@ _unicode_ident_rs =3D static_library(
   gnu_symbol_visibility: 'hidden',
   override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
   rust_abi: 'rust',
+  rust_args: ['--cap-lints', 'allow'],
   dependencies: [],
   native: true,
 )
diff --git a/subprojects/proc-macro-error-1-rs.wrap b/subprojects/proc-macr=
o-error-1-rs.wrap
index b7db03b06a0..59f892f7825 100644
--- a/subprojects/proc-macro-error-1-rs.wrap
+++ b/subprojects/proc-macro-error-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D proc-macro-error-1.0.4.tar.gz
 source_hash =3D da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a=
5ce38c
 #method =3D cargo
 patch_directory =3D proc-macro-error-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/proc-macro-error-attr-1-rs.wrap b/subprojects/proc=
-macro-error-attr-1-rs.wrap
index d13d8a239ac..5aeb224a103 100644
--- a/subprojects/proc-macro-error-attr-1-rs.wrap
+++ b/subprojects/proc-macro-error-attr-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D proc-macro-error-attr-1.0.4.tar.gz
 source_hash =3D a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b=
35f869
 #method =3D cargo
 patch_directory =3D proc-macro-error-attr-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/proc-macro2-1-rs.wrap b/subprojects/proc-macro2-1-=
rs.wrap
index 7053e2c013c..6c9369f0df3 100644
--- a/subprojects/proc-macro2-1-rs.wrap
+++ b/subprojects/proc-macro2-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D proc-macro2-1.0.84.0.tar.gz
 source_hash =3D ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc1202=
4a49d6
 #method =3D cargo
 patch_directory =3D proc-macro2-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/quote-1-rs.wrap b/subprojects/quote-1-rs.wrap
index 6e7ea69049f..8b721dfa00b 100644
--- a/subprojects/quote-1-rs.wrap
+++ b/subprojects/quote-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D quote-1.0.36.0.tar.gz
 source_hash =3D 0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208=
acaca7
 #method =3D cargo
 patch_directory =3D quote-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/syn-2-rs.wrap b/subprojects/syn-2-rs.wrap
index 13ffdac3c3b..d79cf750fb4 100644
--- a/subprojects/syn-2-rs.wrap
+++ b/subprojects/syn-2-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D syn-2.0.66.0.tar.gz
 source_hash =3D c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3=
cdcff5
 #method =3D cargo
 patch_directory =3D syn-2-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/unicode-ident-1-rs.wrap b/subprojects/unicode-iden=
t-1-rs.wrap
index 4609f96ed97..50988f612e2 100644
--- a/subprojects/unicode-ident-1-rs.wrap
+++ b/subprojects/unicode-ident-1-rs.wrap
@@ -5,3 +5,6 @@ source_filename =3D unicode-ident-1.0.12.tar.gz
 source_hash =3D 3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec=
0fee4b
 #method =3D cargo
 patch_directory =3D unicode-ident-1-rs
+
+# bump this version number on every change to meson.build or the patches:
+# v2
diff --git a/subprojects/unicode-ident-1-rs/meson.build b/subprojects/unico=
de-ident-1-rs/meson.build
deleted file mode 100644
index 54f23768545..00000000000
--- a/subprojects/unicode-ident-1-rs/meson.build
+++ /dev/null
@@ -1,20 +0,0 @@
-project('unicode-ident-1-rs', 'rust',
-  version: '1.0.12',
-  license: '(MIT OR Apache-2.0) AND Unicode-DFS-2016',
-  default_options: [])
-
-_unicode_ident_rs =3D static_library(
-  'unicode_ident',
-  files('src/lib.rs'),
-  gnu_symbol_visibility: 'hidden',
-  override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'],
-  rust_abi: 'rust',
-  dependencies: [],
-  native: true,
-)
-
-unicode_ident_dep =3D declare_dependency(
-  link_with: _unicode_ident_rs,
-)
-
-meson.override_dependency('unicode-ident-1-rs', unicode_ident_dep, native:=
 true)
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535263; cv=none;
	d=zohomail.com; s=zohoarc;
	b=OBDKSsSaDt5XYsKfMRxKdy4OMxvC7jfmC0ZRyno0pTHoJXSHK8F/WhlN3lapr6Dgsb+6RHx/XJf6SfVYv0XdSFcRv+f9q3jD4l48TG9iRAb1B9CjL6umZ8dOI4s+kpX4F9jXtfkY7PlWFebwF0tDhbj+5BV+Y3VIzY2XxhFCvRo=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535263;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=i4cw780DN/LGmTQ/ybrMWyZ0EkmQUgapSHvCxCFoy5k=;
	b=Xpjxw3SW5il+7Efa35c1CwWPEdIwG889lx0anb5zdYYD8t/1h3PSI0wqGD3Q4RKKZc9VD1szOByEYqFY+lsYuVxVo+FS6S0KRhR6ndfWz11aU8VuzmEKJtoP4uSV8klhtIfTPrz+8SU3AVU1BhhM42kKxln7V0Q91QsoK5UH7AU=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535263649187.70194498333979;
 Fri, 10 Jan 2025 10:54:23 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK32-0001Y3-Th; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2E-0000GF-II
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2A-000187-Rg
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:04 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-658-ZM3R3ENRPT2MAUJyh_IjdA-1; Fri, 10 Jan 2025 13:47:00 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa680e17f6dso173599066b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:00 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90dacf1sm195757366b.63.2025.01.10.10.46.55
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:55 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534822;
 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=i4cw780DN/LGmTQ/ybrMWyZ0EkmQUgapSHvCxCFoy5k=;
 b=BNJIdnKfiw62MdRRB6E+r9r1dJNskRYv5ZAXiKCvWw1RJTSSzt1vP+DYoctCOCbRt4diAC
 UeAhK4VD2W6POxlvgA595EIt/H3LKC1Pds4GxWaLoH++kjVQFndM2vAm3XPg3FYWEVgEOi
 gO6FfHVhlnJDh3A+OiKfM0pV+FVJiJo=
X-MC-Unique: ZM3R3ENRPT2MAUJyh_IjdA-1
X-Mimecast-MFC-AGG-ID: ZM3R3ENRPT2MAUJyh_IjdA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534819; x=1737139619;
 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=i4cw780DN/LGmTQ/ybrMWyZ0EkmQUgapSHvCxCFoy5k=;
 b=HGQxFnI71MMwdT8vdbEHO2gndMDGI1Z3zRB5zUzP+c9j6wi8dAxiL924pkcCczTNBr
 3YnZ6puJVP+QA8TSyMnvemIk3aqLA2Sp7Ezpz+rB4Vivg0MjRH+xaMZx9/4PQW34MH23
 Ey8a3a0V+VmIgkAIu1n+nCZmftIoo6mYtZFgizgtUKikfbDv7JirBDlqG5mIZEBCzwQB
 4gUMnGyd1abj268HoOuLXELZBjyQDgwTr17gH4KTvzaA1jLq5dSKkfijb72Ont3V/16F
 SG+GkGLVkwZthTbGH5Ii4c3kbIPRRxBrWIqToxAJLHrUwL3YqoF4MJ/LfeEQTngHZoOL
 FMKA==
X-Gm-Message-State: AOJu0Yyg6j89ZHIV/ZceNJI3SMsHgoQVXrn60f+IRdYUXuqtUpTKovX+
 KOKP7D7+4sKi2X9Z/C0t+neLOF77NSrdVaA1EhycLQJSMeaOmLpN+7rBuJh9vwBVcjUm0LNAL/l
 QLg7kloLIztATkPfcf0pudo2f0svm3BmfhYpNttkXr24f2GoUDTgzmKyGKyUGhtUvQX+DvWToXM
 ++gPekvDZHMu5EqHd0iIaVaJgDQYYH9qZsMspoU/w=
X-Gm-Gg: ASbGncvZA/hqtyZrpiXLigFpZCAC794WVF8FsTaIT4dCmvTXrBJspDlrG7YgPoEF345
 ly9V+aR7tb9xVwjs+IK8aORF9SprwT1zFN+vzXvwFobwb8IOOVJXVIAlIAlSPLTKDQXW8o8BZcn
 mmgqx6I9Xd+aJNgucmh9CqcPqNwunA8ZbSCzjNWK1Iqc/KwHuHoVu9j9zYfXzAMJxMgwTw+fJI4
 bHIDIqEJQ5ehfnuHQDN5hGLrmW/fVELWtO1le0emjiyKeWovbM8JDBdXag=
X-Received: by 2002:a05:6402:2814:b0:5d0:ced8:d22d with SMTP id
 4fb4d7f45d1cf-5d972e63dc9mr26575763a12.22.1736534818439;
 Fri, 10 Jan 2025 10:46:58 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFa5socmm5yd1SDbmSBLMuMpKplEFcH3+/QsNge+wdKVsAZ+VfBqmnprKmGulJMofkYctwX3A==
X-Received: by 2002:a05:6402:2814:b0:5d0:ced8:d22d with SMTP id
 4fb4d7f45d1cf-5d972e63dc9mr26575547a12.22.1736534816507;
 Fri, 10 Jan 2025 10:46:56 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 15/38] qom: remove unused field
Date: Fri, 10 Jan 2025 19:45:56 +0100
Message-ID: <20250110184620.408302-16-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535264790116600
Content-Type: text/plain; charset="utf-8"

The "concrete_class" field of InterfaceClass is only ever written, and as f=
ar
as I can tell is not particularly useful when debugging either; remove it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qom/object.h | 5 ++++-
 qom/object.c         | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 95d6e064d9b..f28ffea9a64 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -573,12 +573,15 @@ struct InterfaceInfo {
  *
  * The class for all interfaces.  Subclasses of this class should only add
  * virtual methods.
+ *
+ * Note that most of the fields of ObjectClass are unused (all except
+ * "type", in fact).  They are only present in InterfaceClass to allow
+ * @object_class_dynamic_cast to work with both regular classes and interf=
aces.
  */
 struct InterfaceClass
 {
     ObjectClass parent_class;
     /* private: */
-    ObjectClass *concrete_class;
     Type interface_type;
 };
=20
diff --git a/qom/object.c b/qom/object.c
index b4c52d055d9..e9dfad854bd 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -314,7 +314,6 @@ static void type_initialize_interface(TypeImpl *ti, Typ=
eImpl *interface_type,
     g_free((char *)info.name);
=20
     new_iface =3D (InterfaceClass *)iface_impl->class;
-    new_iface->concrete_class =3D ti->class;
     new_iface->interface_type =3D interface_type;
=20
     ti->class->interfaces =3D g_slist_append(ti->class->interfaces, new_if=
ace);
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534880; cv=none;
	d=zohomail.com; s=zohoarc;
	b=gybVoV6cNITew6f5foSJ8bO3SQJnasoMbPGL/DQym0rRROrYShooT6nnkaZBV5Gie88WZSpxBfDQql/YOr9Pw+BCTt4VbRNSwZmYeCdq04pRnlgrAvzV8yYe0UfzxUKnW1vqrVDwTptuj51S/AZnSm1AzxgUF0+P6vlV6Or3VR4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534880;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=+6XkrDw8kJ0urdDIGPNF7dyGN4vEh7W7PLxyHD9bMc0=;
	b=MZH0s7TO61XFxE4jH1gMIh2F3Fs7rb/oGDMQ5pFey9C4DJoMkagzzJqReTlZCbrbjxC6ERioZjHETZBwShMnTSG7QcRHb5uUJITNxGqqzkEW7i1ubvGPtELiyycueuMO+7GQfgIida6AwVDtrZQKwtlT4jGg0NwjZfKeUj+qwq0=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534880370126.17204043715321;
 Fri, 10 Jan 2025 10:48:00 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2u-0000q1-UD; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2E-0000GG-K8
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2A-00017z-NU
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:05 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-679-Jgp3aVYmNHOJdqjRaNu_BA-1; Fri, 10 Jan 2025 13:47:00 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aaf8f016bb1so201343166b.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:00 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90da0fcsm192073766b.75.2025.01.10.10.46.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:57 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534821;
 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=+6XkrDw8kJ0urdDIGPNF7dyGN4vEh7W7PLxyHD9bMc0=;
 b=eak63UM/WZ0LeNrYojY/85u1xpJAYSXIgtb7/wDou8gBukz4zf/0aRs7WLwy8lf5+iETbB
 pHcyBgB4Bd14A7CRRDqOqvOgCk6WEHRfgPJhJHveiE6s0pfVoJwExM8Y9fYHF37Q0Cgn9e
 RwtVUQzCaRKrfFQgf0MX94juXMec6ss=
X-MC-Unique: Jgp3aVYmNHOJdqjRaNu_BA-1
X-Mimecast-MFC-AGG-ID: Jgp3aVYmNHOJdqjRaNu_BA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534818; x=1737139618;
 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=+6XkrDw8kJ0urdDIGPNF7dyGN4vEh7W7PLxyHD9bMc0=;
 b=oNvvG+jFwpN6qFFSNLla6AucRStkXyejE5OuQFyHmUk9q5gO/qQNVW5llX9MZNMxZu
 shVNOKwLFBE9IQOFG3thFTZihycmnzhHIXGjjT2CATWpuZbbLBRidgqNyLp+kIisSRsu
 lyOLvqHfSJTwhYl/v9rp9Lsl7d4cf29ZXvipziPCT9KoVnd6/DgYbQFNH0iDcvm26+Yy
 c3XXs2BsciRuAOYiExrbo74zZ0WK7j51TVZeIeOe5Q6hl9sNctqODM8OfBsmqyZOXmBr
 lVuTI+kSSvi/V0vmvqQ30/IFDDBAPB2SwtZdSzQ4U3mJ82yuURSxyIOtkuSUgQjQArU7
 4GjQ==
X-Gm-Message-State: AOJu0YxwkWO266ua71fxYDIVm1e85XdZ8mzKsKoIwomLzabShJ3wcGYN
 C5bRTTFTFJt/U30fr+sS9K7dsailizdwKs5JaYliVG4vktFy3G08pXI3mswJIiD6pSggn1l3e7u
 V+1UhuQhVuOSWcK5/duBgwpt6Nfng8EK4iRxgvdCtbVdzfD/tvbBt7h1EW755ZjPJ2YCSoBzBEy
 h4q8Wn7L6XO2Byq7oBN69WZxWpbZZOtXCf/Wggxp0=
X-Gm-Gg: ASbGnctxtuCL44LG9JgaYi/lUbzRrsEC4kcyRS/nekkHujMvKHeUnS4vSVS4y9rZkeq
 5FptipnJ9g7MZEBliwxpJkvHuzLuKbUQ3HwoZ1MDmC8w860log0PJ1yKeW2VrG8xcYj0u0b0fqh
 oHjF1bi52g6ZbTS0Fx243gJDnENIxZoV0VvRFItG0hV9EE83MOHZHDj3bP9wp52HzbWRVE4eCF2
 AKXL36GVpNgBQiQotPjk6vgDd9A5VhJ0tYUUNsHyz/hFMrDPAJAyAca+l8=
X-Received: by 2002:a17:907:3e9e:b0:aa6:a572:49fd with SMTP id
 a640c23a62f3a-ab2abdc0262mr1198578066b.54.1736534818639;
 Fri, 10 Jan 2025 10:46:58 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHYEMhI0YzgUraPEZEgdXI+yEOZm99hSqlIjBdY8coVoxSYFMiXRDZ9Wo1R8u8hlxP1qgBWJA==
X-Received: by 2002:a17:907:3e9e:b0:aa6:a572:49fd with SMTP id
 a640c23a62f3a-ab2abdc0262mr1198575766b.54.1736534818174;
 Fri, 10 Jan 2025 10:46:58 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Michael Tokarev <mjt@tls.msk.ru>
Subject: [PULL 16/38] make-release: only leave tarball of wrap-file
 subprojects
Date: Fri, 10 Jan 2025 19:45:57 +0100
Message-ID: <20250110184620.408302-17-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534881444116600
Content-Type: text/plain; charset="utf-8"

The QEMU source archive is including the sources downloaded from crates.io
in both tarball form (in subprojects/packagecache) and expanded/patched
form (in the subprojects directory).  The former is the more authoritative
form, as it has a hash that can be verified in the wrap file and checked
against the download URL, so keep that one only.  This works also with
--disable-download; when building QEMU for the first time from the
tarball, Meson will print something like

    Using proc-macro2-1-rs source from cache.

for each subproject, and then go on to extract the tarball and apply the
overlay or the patches in subprojects/packagefiles.

Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2719
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/make-release | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/scripts/make-release b/scripts/make-release
index 8dc939124c4..2885e872109 100755
--- a/scripts/make-release
+++ b/scripts/make-release
@@ -10,6 +10,27 @@
 # This work is licensed under the terms of the GNU GPLv2 or later.
 # See the COPYING file in the top-level directory.
=20
+function subproject_dir() {
+    if test ! -f "subprojects/$1.wrap"; then
+      error "scripts/archive-source.sh should only process wrap subproject=
s"
+    fi
+
+    # Print the directory key of the wrap file, defaulting to the
+    # subproject name.  The wrap file is in ini format and should
+    # have a single section only.  There should be only one section
+    # named "[wrap-*]", which helps keeping the script simple.
+    local dir
+    dir=3D$(sed -n \
+      -e '/^\[wrap-[a-z][a-z]*\]$/,/^\[/{' \
+      -e    '/^directory *=3D */!b' \
+      -e    's///p' \
+      -e    'q' \
+      -e '}' \
+      "subprojects/$1.wrap")
+
+    echo "${dir:-$1}"
+}
+
 if [ $# -ne 2 ]; then
     echo "Usage:"
     echo " $0 gitrepo version"
@@ -51,5 +72,13 @@ meson subprojects download $SUBPROJECTS
         CryptoPkg/Library/OpensslLib/openssl \
         MdeModulePkg/Library/BrotliCustomDecompressLib/brotli)
 popd
-tar --exclude=3D.git -cJf ${destination}.tar.xz ${destination}
+
+exclude=3D(--exclude=3D.git)
+# include the tarballs in subprojects/packagecache but not their expansion
+for sp in $SUBPROJECTS; do
+    if grep -xqF "[wrap-file]" subprojects/$sp.wrap; then
+      exclude+=3D(--exclude=3Dsubprojects/"$(subproject_dir $sp)")
+    fi
+done
+tar "${exclude[@]}" -cJf ${destination}.tar.xz ${destination}
 rm -rf ${destination}
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535337; cv=none;
	d=zohomail.com; s=zohoarc;
	b=MCIcxcmx54eKCkKSQqBEBWsh1oma3fhpMahKGeEoQ8r9UzILU7El9NE2nTjJYkw6o+WGhwIOTjno9/UoxZqMqV2CqkRdEMBDTf2gDuFbF8g3Z4ubI9HirOFcNptuGOJrE4GknOox4hfHK3in06QghWC27kkDGu4kngFjW66WZNU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535337;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=+9XJTJSHDsdt0DlshXhAnXl9FWfBL5KYyt2ZALl3vTc=;
	b=GMGRQMQaGz6ZTPeZ3YDzLNqRjGdnjU0hyocGZmwQIMnfSD9xUmmE7EdB9m+sBcF6n/h3qUc9lVvEXRAzKbxtoghFcenqp2ofjnQQ30zgjwtV+iKWniFgaX3kLZ5P3XveCwJZhn/nFEv/m6UAiyeLVr8VRD9UVOpkqMtTCdd6hV0=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535337082281.73130538275507;
 Fri, 10 Jan 2025 10:55:37 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2x-00011Y-2p; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2G-0000Gd-LO
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2D-00018L-12
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:07 -0500
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-52-Xj2uOyKgMLyftcuwS6HTqw-1; Fri, 10 Jan 2025 13:47:03 -0500
Received: by mail-ed1-f69.google.com with SMTP id
 4fb4d7f45d1cf-5d3cff6aedbso2893518a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:02 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903c32a0sm1975682a12.44.2025.01.10.10.46.58
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:46:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534824;
 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=+9XJTJSHDsdt0DlshXhAnXl9FWfBL5KYyt2ZALl3vTc=;
 b=SZQvfekT+hUVblLrNc9yts7NDWnadGBl4bytMUWbp72FDJ46IzAUQpJvCsQru4HoLTWFTW
 bXDXyQ6sU/bjw8+uEwzZTJxpEd5tnc852EbHC24Z3n9LFgMbEOE7/AIzwVN61nriN3HB+w
 EkVDglweAH1lTwX1dJNR1dFNOiesWB8=
X-MC-Unique: Xj2uOyKgMLyftcuwS6HTqw-1
X-Mimecast-MFC-AGG-ID: Xj2uOyKgMLyftcuwS6HTqw
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534821; x=1737139621;
 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=+9XJTJSHDsdt0DlshXhAnXl9FWfBL5KYyt2ZALl3vTc=;
 b=rpSZqcBCveZl6YF+ZdxdLlMb4SeZ2rX8W8xC2Ccj2x0cZXnYYZ6j5pI2gOhUVXsKiK
 xD8TJvtFhbjx+eKUadrzppYnqIGgGnvIhfTVl3Uo1+98/dKeP6M829JosTgofTEI0PG9
 w8eGGtSUi5+16WKrD5tWUBQzFXinGOr6sI5eeTNEthOza9wc2t+p1kS4EYKXn2N+w1zj
 igI4gq0a6cZL2tQ+JPUNwch+OcqsLI21e83lVG0QLnIDaBRqh0pZnmGG7E1TgOtMmitD
 UIgjAaJOl6eQKVfPDUfjleFu4kA4/BemmvIpxBtVTCShPffQ2Do1RWzsQPOuv5Glk7mB
 ddbw==
X-Gm-Message-State: AOJu0YzSyRUSkdhra49Une2lut4Mh1hNsCJfXZiwWVMXJDvMHDZETq/C
 DtGXqj7rGherwpQdsIIx5MTD0WaT8jnghhPbMVGucxTnQ28Yjj8hVEQMAponJ0HktEgySixmreE
 0R7BPYKoAgqC4sIAd24c0uluO+3NAJadi4K7tHAIDvq6gACoKdkZWcVlA05f3snO+aO+BD7l4i2
 +GEws6NU/0RTazrA1803PLhkS3lLkBkUolhrMLVHs=
X-Gm-Gg: ASbGncslYPY+mrIoETl/AzgTC5xq/19scx4HCwhwoZgTAyVTVNuWXgSvVFlzIzLNeRr
 MtYJ/UqWqeQHYB1Ovp0Gv6X/tAggpsBA4+tZ1pvn2RG6vZM69jOwJR/dDN/ESbSuR5RQH+/66f0
 Kq7Ec4SoOcw/kTFVQQs5EqNqVquwIWiCHTphzDKHDPKhjrd2BV+YnyGYUQssrWaNcGCTlmVtNdd
 6G0750F7yN9HB6yY3kNew8YvR6roCvHyWN1Oqs6zUDtSZHy8qUKBSFPYw4=
X-Received: by 2002:a05:6402:84d:b0:5d3:fcca:cab1 with SMTP id
 4fb4d7f45d1cf-5d986288138mr6146084a12.15.1736534821534;
 Fri, 10 Jan 2025 10:47:01 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IEKPOHbDEGpbpAsy3zpmvKziXAAFWoWus6eaNc2RMe8b04O8pFx2/U5PBE0KMxQAZHk7PZgzw==
X-Received: by 2002:a05:6402:84d:b0:5d3:fcca:cab1 with SMTP id
 4fb4d7f45d1cf-5d986288138mr6146053a12.15.1736534820974;
 Fri, 10 Jan 2025 10:47:00 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 17/38] target/i386: improve code generation for BT
Date: Fri, 10 Jan 2025 19:45:58 +0100
Message-ID: <20250110184620.408302-18-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535338537019000
Content-Type: text/plain; charset="utf-8"

Because BT does not write back to the source operand, it can modify it to
ensure that one of the operands of TSTNE is a constant (after either gen_BT
or the optimizer's constant propagation).  This produces better and more
optimizable TCG ops.  For example, the sequence

  movl $0x60013f, %ebx
  btl %ecx, %ebx

becomes just

  and_i32 tmp1,ecx,$0x1f                   dead: 1 2  pref=3D0xffff
  shr_i32 tmp0,$0x60013f,tmp1              dead: 1 2  pref=3D0xffff
  and_i32 tmp16,tmp0,$0x1                  dead: 1  pref=3D0xbf80

On s390x, it can use four instructions to isolate bit 0 of 0x60013f >> (ecx=
 & 31):

  nilf     %r12, 0x1f
  lgfi     %r11, 0x60013f
  srlk     %r12, %r11, 0(%r12)
  nilf     %r12, 1

Previously, it used five instructions to build 1 << (ecx & 31) and compute
TSTEQ, and also needed two more to construct the result of setcond:

  nilf     %r12, 0x1f
  lghi     %r11, 1
  sllk     %r12, %r11, 0(%r12)
  lgfi     %r9, 0x60013f
  nrk      %r0, %r12, %r9
  lghi     %r12, 0
  locghilh %r12, 1

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/tcg/emit.c.inc | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index 785ff63f2ac..5c115429350 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -1443,8 +1443,9 @@ static TCGv gen_bt_mask(DisasContext *s, X86DecodedIn=
sn *decode)
     return mask;
 }
=20
-/* Expects truncated bit index in s->T1, 1 << s->T1 in MASK.  */
-static void gen_bt_flags(DisasContext *s, X86DecodedInsn *decode, TCGv src=
, TCGv mask)
+/* Expects truncated bit index in COUNT, 1 << COUNT in MASK.  */
+static void gen_bt_flags(DisasContext *s, X86DecodedInsn *decode, TCGv src,
+                         TCGv count, TCGv mask)
 {
     TCGv cf;
=20
@@ -1467,15 +1468,34 @@ static void gen_bt_flags(DisasContext *s, X86Decode=
dInsn *decode, TCGv src, TCGv
         decode->cc_src =3D tcg_temp_new();
         decode->cc_dst =3D cpu_cc_dst;
         decode->cc_op =3D CC_OP_SARB + cc_op_size(s->cc_op);
-        tcg_gen_shr_tl(decode->cc_src, src, s->T1);
+        tcg_gen_shr_tl(decode->cc_src, src, count);
     }
 }
=20
 static void gen_BT(DisasContext *s, X86DecodedInsn *decode)
 {
-    TCGv mask =3D gen_bt_mask(s, decode);
+    TCGv count =3D s->T1;
+    TCGv mask;
=20
-    gen_bt_flags(s, decode, s->T0, mask);
+    /*
+     * Try to ensure that the rhs of the TSTNE condition is a constant (an=
d a
+     * power of two), as that is more readily available on most TCG backen=
ds.
+     *
+     * For immediate bit number gen_bt_mask()'s output is already a consta=
nt;
+     * for register bit number, shift the source right and check bit 0.
+     */
+    if (decode->e.op2 =3D=3D X86_TYPE_I) {
+        mask =3D gen_bt_mask(s, decode);
+    } else {
+        MemOp ot =3D decode->op[1].ot;
+
+        tcg_gen_andi_tl(s->T1, s->T1, (8 << ot) - 1);
+        tcg_gen_shr_tl(s->T0, s->T0, s->T1);
+
+        count =3D tcg_constant_tl(0);
+        mask =3D tcg_constant_tl(1);
+    }
+    gen_bt_flags(s, decode, s->T0, count, mask);
 }
=20
 static void gen_BTC(DisasContext *s, X86DecodedInsn *decode)
@@ -1491,7 +1511,7 @@ static void gen_BTC(DisasContext *s, X86DecodedInsn *=
decode)
         tcg_gen_xor_tl(s->T0, s->T0, mask);
     }
=20
-    gen_bt_flags(s, decode, old, mask);
+    gen_bt_flags(s, decode, old, s->T1, mask);
 }
=20
 static void gen_BTR(DisasContext *s, X86DecodedInsn *decode)
@@ -1509,7 +1529,7 @@ static void gen_BTR(DisasContext *s, X86DecodedInsn *=
decode)
         tcg_gen_andc_tl(s->T0, s->T0, mask);
     }
=20
-    gen_bt_flags(s, decode, old, mask);
+    gen_bt_flags(s, decode, old, s->T1, mask);
 }
=20
 static void gen_BTS(DisasContext *s, X86DecodedInsn *decode)
@@ -1525,7 +1545,7 @@ static void gen_BTS(DisasContext *s, X86DecodedInsn *=
decode)
         tcg_gen_or_tl(s->T0, s->T0, mask);
     }
=20
-    gen_bt_flags(s, decode, old, mask);
+    gen_bt_flags(s, decode, old, s->T1, mask);
 }
=20
 static void gen_BZHI(DisasContext *s, X86DecodedInsn *decode)
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535171; cv=none;
	d=zohomail.com; s=zohoarc;
	b=JpO1QEv0l+GFtZ0M8yp717iXBVlpqqlG4JwLuyT61nbpQe9hw2q2BxDGt75ExzISe9l4ykppya0yI/do0Fz13V5SFHOhu9c1FdfP4D3RspTArFTe/Bw3njv33zVlkpNZc/bpIiXKcU/uMKR6E7K49gDi9OW5cNhws+luYaKvJWE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535171;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=zYLEPuXNZY1l/qQd9EilKn0wQkuhUcyTj4C8X86e2cE=;
	b=bVDL4QC8ehcdCgI5nWHNcY0VwEQT7ed9VVkETHj5aSMx24wMs4SIaljUQkcksW96CLcllIe1k0KSKNFYvyNIFHBQB46Tt8mQhe3S03w7UtipQNRBAawHb43DQc9+t87dA6C0NDgBTH6regR1M5+C0C3pEJ+GU0uXuvS99ZLwvos=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535171658366.06629987373583;
 Fri, 10 Jan 2025 10:52:51 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK32-0001PN-5A; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2K-0000H6-BE
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:15 -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 <pbonzini@redhat.com>)
 id 1tWK2E-000196-VP
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:08 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-572-meoc3DHmM5Kic8U8sQB2-Q-1; Fri, 10 Jan 2025 13:47:04 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d3f3d6a999so2400783a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:04 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903c32absm1971106a12.41.2025.01.10.10.47.01
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:02 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534826;
 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=zYLEPuXNZY1l/qQd9EilKn0wQkuhUcyTj4C8X86e2cE=;
 b=HAqVZyGH47CVIwfZDf2EgAe0wxmw54k6rVGXdlBVkj81bfTqCkb2jH7fs/FjAL2M9YQCBv
 AZU1prPkwXv85uJfv873MTSXc7wHLrOc4iYPUAPmF7bNmU8Uy+rC032qlQF0FQxR4bwcrm
 Fz6ARKrz6ccSzBCDAXzA7c2FrZoQ0c4=
X-MC-Unique: meoc3DHmM5Kic8U8sQB2-Q-1
X-Mimecast-MFC-AGG-ID: meoc3DHmM5Kic8U8sQB2-Q
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534823; x=1737139623;
 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=zYLEPuXNZY1l/qQd9EilKn0wQkuhUcyTj4C8X86e2cE=;
 b=h7xJg922dGuT6GWCAmyM4e1MGQJZjeGxAx5vLTjN/Q+brvYjspfA+HFwcJKnxcrqEC
 85zl7aNryxnKHkvm+XmEnv/BghE/WVetmFiCpcbpXSUNevAkWJQLcGbbsQOqlSJC1uGa
 NuFkkmCkJ2Skdm7YJ9M8pkzTinbTI9zfEDmYdSI2srq7Hyjje/Z228XZ7PoRQmi0U6BR
 Ss9o9UoldGxaD9pjEWvL2fSTQImykSkjSWWhCI6Pk2sqtv8DiCP2D5uHw5onK5mh1Tc2
 pJKKn0Vgsu3xhaSHYwvfvisfu56gzOrrJzC+S/qfWcSFJURjTK/eZWiURlBouZHhNgim
 d+hg==
X-Gm-Message-State: AOJu0YyugtawXOGV6dBAJ3/8JfMctyq8lLkrzlvV/pXrmIjdZxSchw5n
 yH+yOmBZA9qfpzMJOlqhyBXj7gPPNRsrzvyzLByjYCM5eCSXrg+7SIxD0o0Yfjmm+QoMayvdLKH
 SDhaGWpVK2oxfQ7olhiP0CVIBrXQtJO13GyVPkdt30nSux4nIF7aa4XyLwcLodJ/mZp2b78thIc
 WeV7HvYebyhMm9DxT1yOrIagXrb2Al34OGlvOVsEA=
X-Gm-Gg: ASbGncvj225eZmFqos3W5BFraHvDF7nDub4vSAGBLna1/+Gelm6msOUtl3PTIgZO0+7
 hGjdKM4nWToXyCsuOrzNL3YUGej4W4MReTPqQ7zejSqtZwpJ9g0ns/4c7JzJFeY/x2kYmR4Es/X
 nUZ84TTgFmuj7RbJzweh1rGvroKqAD3hp4UgZPYiKNFX90HGAMliGZOVLEq0GmgHOsBATW9992e
 H8sFWgU0OkuSBjbdvGn2k0Ej7qFkO9x7N+R1IDj5GkjzOBKnvmna+cighk=
X-Received: by 2002:a50:c88a:0:b0:5d9:856c:9a08 with SMTP id
 4fb4d7f45d1cf-5d9856c9cf3mr6506074a12.18.1736534823174;
 Fri, 10 Jan 2025 10:47:03 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGOsqO8JlZaq2DPQWxNrok5ro3KK/a+wrybrkqbAUV+iWCUJOuxOCPgd/bbuqjLNW+r2fLmrw==
X-Received: by 2002:a50:c88a:0:b0:5d9:856c:9a08 with SMTP id
 4fb4d7f45d1cf-5d9856c9cf3mr6506058a12.18.1736534822753;
 Fri, 10 Jan 2025 10:47:02 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 18/38] target/i386: use shr to load high-byte registers into
 T0/T1
Date: Fri, 10 Jan 2025 19:45:59 +0100
Message-ID: <20250110184620.408302-19-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535172456116600
Content-Type: text/plain; charset="utf-8"

Using a sextract or extract operation is only necessary if a
sign or zero extended value is needed.  If not, a shift is
enough.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/tcg/translate.c |  2 +-
 target/i386/tcg/emit.c.inc  | 23 ++++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 834aea1e594..dbc9d637c4b 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -486,7 +486,7 @@ static inline
 void gen_op_mov_v_reg(DisasContext *s, MemOp ot, TCGv t0, int reg)
 {
     if (ot =3D=3D MO_8 && byte_reg_is_xH(s, reg)) {
-        tcg_gen_extract_tl(t0, cpu_regs[reg - 4], 8, 8);
+        tcg_gen_shri_tl(t0, cpu_regs[reg - 4], 8);
     } else {
         tcg_gen_mov_tl(t0, cpu_regs[reg]);
     }
diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index 5c115429350..c4cc5f48d83 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -286,24 +286,25 @@ static void gen_load(DisasContext *s, X86DecodedInsn =
*decode, int opn, TCGv v)
                 gen_op_ld_v(s, op->ot, v, s->A0);
             }
=20
-        } else if (op->ot =3D=3D MO_8 && byte_reg_is_xH(s, op->n)) {
-            if (v =3D=3D s->T0 && decode->e.special =3D=3D X86_SPECIAL_SEx=
tT0) {
-                tcg_gen_sextract_tl(v, cpu_regs[op->n - 4], 8, 8);
-            } else {
-                tcg_gen_extract_tl(v, cpu_regs[op->n - 4], 8, 8);
-            }
-
         } else if (op->ot < MO_TL && v =3D=3D s->T0 &&
                    (decode->e.special =3D=3D X86_SPECIAL_SExtT0 ||
                     decode->e.special =3D=3D X86_SPECIAL_ZExtT0)) {
-            if (decode->e.special =3D=3D X86_SPECIAL_SExtT0) {
-                tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot | MO_SIGN);
+            if (op->ot =3D=3D MO_8 && byte_reg_is_xH(s, op->n)) {
+                if (decode->e.special =3D=3D X86_SPECIAL_SExtT0) {
+                    tcg_gen_sextract_tl(v, cpu_regs[op->n - 4], 8, 8);
+                } else {
+                    tcg_gen_extract_tl(v, cpu_regs[op->n - 4], 8, 8);
+                }
             } else {
-                tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot);
+                if (decode->e.special =3D=3D X86_SPECIAL_SExtT0) {
+                    tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot | MO_SIGN);
+                } else {
+                    tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot);
+                }
             }
=20
         } else {
-            tcg_gen_mov_tl(v, cpu_regs[op->n]);
+            gen_op_mov_v_reg(s, op->ot, v, op->n);
         }
         break;
     case X86_OP_IMM:
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534996; cv=none;
	d=zohomail.com; s=zohoarc;
	b=lzp30MmsbmW9Ya5UcJ3H6L9tMTTEJl3VTq3u7je4YEZsOIYmsfbBaiHcROjhgjcdzWZCr0DbK5Z/NTC1RCNueppznDsCqH/FBcfeHvFR7WmC+ijpzzk9tqZH9cye1OkZDzeigusCK4Tv+GVDxWXvlvmtfAG8+BuTRRe4WWwEXjk=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534996;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=lheQe9oBiSwdA3AEighJH8+9qG+im1PfUhZWsSUYH5o=;
	b=ex3SWmPENjHANRNFNrnCIXLhEi6E43FSdygKkOQ8ADL10XQsOR1C8d9aJWOLRawLqyGQXCzE74fmwYJWBBmXdySvZUu2qnsf2UxHAn16nZ1oNUuwwuobVfWWma6u6jGHNxzap87HeoQF0uJpjKhagXfIJjPMd9rA5DVzKXJVxdE=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534996845682.3965028547915;
 Fri, 10 Jan 2025 10:49:56 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2w-0000xA-SZ; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2O-0000HR-Av
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:18 -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 <pbonzini@redhat.com>)
 id 1tWK2I-00019f-9p
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:15 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-637-NxLL07ZxPcG-Bde8gCqCqA-1; Fri, 10 Jan 2025 13:47:07 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa66f6ce6bfso197519066b.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:07 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90d4f92sm195595866b.57.2025.01.10.10.47.03
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:03 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534828;
 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=lheQe9oBiSwdA3AEighJH8+9qG+im1PfUhZWsSUYH5o=;
 b=WKy0OlwwazpGG7z+dWAsO3RTT+RotdIy9jZQfu/oHSYHnbWwkOjw3VhTkH9mKB3Axs8sKR
 h1OZ0CXngYYvr0NW7ckJJulPQ52lCx0ZEVPtHC91fF1Ks8SETYNVe+fMy1tLStd2nslGd7
 qN1xntgJeiDrZzydhJJlzicSekrY+cE=
X-MC-Unique: NxLL07ZxPcG-Bde8gCqCqA-1
X-Mimecast-MFC-AGG-ID: NxLL07ZxPcG-Bde8gCqCqA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534825; x=1737139625;
 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=lheQe9oBiSwdA3AEighJH8+9qG+im1PfUhZWsSUYH5o=;
 b=XXy4NDBbyrYXFe3WgvnTY3BYl7NZESaf77FJjk+ZORFdyWCkHjdNAzrCWers7PpVH2
 ehw7wCN2MIjDeQX/6us36FuSzQpdXxz4oRi7oKvjrP32ElrLVDn3jMAnJU3XV6xY/rqI
 WKoSPgwuyGKyoDaFzP6oSwceXYq1nbWO/tY5HZr4uDtBlZ+QFv3SVh9GY1ZEI5Uhcw92
 ZvnQYtEzVlNVu4s73gnyMdJDri6RWnIAbrGKTzZsEJyMY8rhM90s7i76Zd5aaI0YI5wF
 NtcKH3kuAqnVB+5X/0ZD4L4UODw7ANaMeu9WQCFELBEKuXbHf1wGxSUVpHeg9G71wPsk
 XSuw==
X-Gm-Message-State: AOJu0YzVjgzW9k49GBWI8XR5pCY+dsne4jgiBMvFYdREPLxd2GE7lAAz
 6pX+RYSyz+vN17Jsm/jgH2YLUEuXCZmUcmc8kqi1K6ekBBkVPMzwvloY9p2+FgOLNM+psZn85Wu
 G002cJUUei4NPEqu4wJYAVn/2OyJfdim1L+lCfri8I35/Io6BzqVhcTVpAdMDTcs53yFpWrIRQt
 W5yphQVHtfL2gOh/x7BpzPGe3q3u6n4LLT30OffCs=
X-Gm-Gg: ASbGncsSF4b9Z9bUZL52U6LOD03BucOKSrJfqlcM31cA83hGZxs47djXlYf1ULjUMhV
 o8DpUU0o+PMk8ftETGg28eQIUmpTPQ3JeF9VMBL15jCHVCFdkotFGLoscnlVU/urv7fEFNLKXLn
 2rmdDJxO38vk7hHqs1wMQYFTJp0o5JN+PABlrDnPYWNJrYbfrAX9JxbqVIho7gW3d0913cec4qm
 dRCJBJ91M6lrdD/Xl+ymqruwtIZnSH4MI+QPll8rM9/BfwefMwD5s3SznM=
X-Received: by 2002:a17:907:60cf:b0:aab:92bd:1a8f with SMTP id
 a640c23a62f3a-ab2ab6fd014mr1014827166b.26.1736534825033;
 Fri, 10 Jan 2025 10:47:05 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFQSbyE0lVRU+apt9SfK90NVRCicY/pU3NyB9MxKJa39+IGoQLl3jKVvSXJhkXuisJ1e5Xe4A==
X-Received: by 2002:a17:907:60cf:b0:aab:92bd:1a8f with SMTP id
 a640c23a62f3a-ab2ab6fd014mr1014824566b.26.1736534824555;
 Fri, 10 Jan 2025 10:47:04 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>, qemu-stable@nongnu.org,
 Tao Su <tao1.su@linux.intel.com>
Subject: [PULL 19/38] i386/cpu: Mark avx10_version filtered when prefix is
 NULL
Date: Fri, 10 Jan 2025 19:46:00 +0100
Message-ID: <20250110184620.408302-20-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_VALIDITY_CERTIFIED_BLOCKED=0.001,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534997969116600
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

In x86_cpu_filter_features(), if host doesn't support AVX10, the
configured avx10_version should be marked as filtered regardless of
whether prefix is NULL or not.

Check prefix before warn_report() instead of checking for
have_filtered_features.

Cc: qemu-stable@nongnu.org
Fixes: commit bccfb846fd52 ("target/i386: add AVX10 feature and AVX10 versi=
on property")
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Tao Su <tao1.su@linux.intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-2-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0b639848cd6..579d9bac955 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7719,8 +7719,10 @@ static bool x86_cpu_filter_features(X86CPU *cpu, boo=
l verbose)
             env->avx10_version =3D version;
             have_filtered_features =3D true;
         }
-    } else if (env->avx10_version && prefix) {
-        warn_report("%s: avx10.%d.", prefix, env->avx10_version);
+    } else if (env->avx10_version) {
+        if (prefix) {
+            warn_report("%s: avx10.%d.", prefix, env->avx10_version);
+        }
         have_filtered_features =3D true;
     }
=20
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534909; cv=none;
	d=zohomail.com; s=zohoarc;
	b=aake+44v/6vmm3o3d4SMB05d0jHJOa3NrKR40UPYRuo5OJsLDPCX/j3T1wVhZw4b361ieVYFcs9PFM4YwVgrhHJM78c/X9BvNuf/ccYES/xvw+ae0YapX1qCmo/xfe/SQgB6NsSAZP8Ede823nVNqSWRZvXoJoomDAnDgYRa/+A=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534909;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=9PzOKGHTdjqT/fLNp0Y32SFtMZUofMI3zc+qmo4xiFc=;
	b=EgfRRJWlKxfgHi7VbsGekFP/wi5Pyvjp3fn9ePu6h3F3sBUSZHXV1lGIXngBwCZ2Y8age1ZLx0eYCCi3MeZbQ9KgkzqhRb4HT+mfXsNPMtHqZBX39ddf5UlhWEKfRPMmD87vbUOXgN2A1ycrd1QZSlTdyEozeHekCqjdlRrUQ/c=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534909104705.726158654638;
 Fri, 10 Jan 2025 10:48:29 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2t-0000il-PJ; Fri, 10 Jan 2025 13:47:47 -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 <pbonzini@redhat.com>)
 id 1tWK2O-0000HS-CB
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:18 -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 <pbonzini@redhat.com>)
 id 1tWK2M-00019u-5R
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:15 -0500
Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com
 [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-685-HnZTJNAPORq9GBivPgjqPA-1; Fri, 10 Jan 2025 13:47:10 -0500
Received: by mail-ed1-f71.google.com with SMTP id
 4fb4d7f45d1cf-5d90b88322aso2681036a12.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:10 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99083fbd7sm1910524a12.73.2025.01.10.10.47.05
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:05 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534831;
 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=9PzOKGHTdjqT/fLNp0Y32SFtMZUofMI3zc+qmo4xiFc=;
 b=YRA67H0TPi1ST4vsCp2EPL1cHA7+FFjxFAnPOKgttMmmDeGhaphoW8D9VMAla7nqWoZo4L
 a5852W4YcnhkacYdd7IbmGrRGdxk5wPQ11PBFBnrDDpy7cmee7pbdwipv7J3HapIzrFyba
 X1yCIwSj89IPPcheXc7Lkw+t/aJUa58=
X-MC-Unique: HnZTJNAPORq9GBivPgjqPA-1
X-Mimecast-MFC-AGG-ID: HnZTJNAPORq9GBivPgjqPA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534828; x=1737139628;
 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=9PzOKGHTdjqT/fLNp0Y32SFtMZUofMI3zc+qmo4xiFc=;
 b=MwkuN3HRdYOPIj2Cv7BTzCl7AAxYkJFFxNXdg+GHJ1Ff2cqdohskSwzXFJhCHmx9Xg
 nmE1hcunh8HdtqpxLThibRXhXyXhhjUHGB0X9fQbbbT4y7niLzSiVWH6xyyyQ6lC+k7/
 mXLF+sRMME9zqiJnzIB5tU7G5VS6592wCJjF5QvDXDd5yNnMGhsAEBi4OlRmElifn1Iv
 O136kZYSSo/qvcJriskTG8NU8zRZcRtJfmQSPDIcefGWqDOGs/FI5SHoa1SQZGP3ByLP
 RqS3O48AhmqNBsKi3oLwMgccZvgV9OWPGWNl5zWlufWHP0wwGrt66uYIRMI0PFdMGOBG
 CtJA==
X-Gm-Message-State: AOJu0YxaBafWEnr24Vn9iZRDBv/nIM3dbrliRrANWgAtZlkarq7Pipzf
 WuyzCQel8B9Hh6wa1R970YC7apb7zgzK20ahwYHZIZOL8I7UPe/+DNs9J4qjkP/2uMur9byXgyF
 yBE5Yz5Y562luKb96E0q86Vr7S9rTbep33owzcl0RE7G8/KrjrWVcx4DTB0P0N+f0yTGyIjEUiS
 2Wi2/6DOye16660cQyx3jfuB77hvbc91kY+3bmik4=
X-Gm-Gg: ASbGncuxplwbByRzUiXV9vi03bCLp3aFI0NRH7BYKpcMEp7myVhpUIm2UwU82PIG5MX
 Xsm+fVowbl/qzoMGPVaCWC8O01dUyb2+E5+Gjy0PZYI9ZUMI6QOvW0McqlLCnIwzStCvDSDG1Eo
 N961jjZN435eFhlx+3FfxG0sS4fmq+cqK06kcQ/xAq8Huch9Q2Kq8xJV1CyP5EUS6qlKAgy3+81
 /5shFYc09xSpM9y6TJ1rhXeSktBYCTSrISogUxDkZGdaLKfyAUPpyBokQ8=
X-Received: by 2002:a05:6402:274d:b0:5cf:420a:9 with SMTP id
 4fb4d7f45d1cf-5d972dfb8bamr10380524a12.5.1736534827946;
 Fri, 10 Jan 2025 10:47:07 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHHt1zOfjWnlkKsG7HnWG4EE1yHppd0C4HckyeXQyQLMTHKfs/mkwTPwyqoG5yH/8B5AhB52w==
X-Received: by 2002:a05:6402:274d:b0:5cf:420a:9 with SMTP id
 4fb4d7f45d1cf-5d972dfb8bamr10380504a12.5.1736534827478;
 Fri, 10 Jan 2025 10:47:07 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PULL 20/38] target/i386/kvm: Add feature bit definitions for KVM
 CPUID
Date: Fri, 10 Jan 2025 19:46:01 +0100
Message-ID: <20250110184620.408302-21-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534909355116600
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

Add feature definitions for KVM_CPUID_FEATURES in CPUID (
CPUID[4000_0001].EAX and CPUID[4000_0001].EDX), to get rid of lots of
offset calculations.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-3-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.h     | 23 +++++++++++++++++++++++
 hw/i386/kvm/clock.c   |  5 ++---
 target/i386/kvm/kvm.c | 28 ++++++++++++++--------------
 3 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index dbd8f1ffc79..f41462d8c19 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -29,6 +29,7 @@
 #include "qapi/qapi-types-common.h"
 #include "qemu/cpu-float.h"
 #include "qemu/timer.h"
+#include "standard-headers/asm-x86/kvm_para.h"
=20
 #define XEN_NR_VIRQS 24
=20
@@ -1010,6 +1011,28 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *=
cpu, FeatureWord w);
 #define CPUID_8000_0007_EBX_OVERFLOW_RECOV    (1U << 0)
 #define CPUID_8000_0007_EBX_SUCCOR      (1U << 1)
=20
+/* (Old) KVM paravirtualized clocksource */
+#define CPUID_KVM_CLOCK            (1U << KVM_FEATURE_CLOCKSOURCE)
+/* (New) KVM specific paravirtualized clocksource */
+#define CPUID_KVM_CLOCK2           (1U << KVM_FEATURE_CLOCKSOURCE2)
+/* KVM asynchronous page fault */
+#define CPUID_KVM_ASYNCPF          (1U << KVM_FEATURE_ASYNC_PF)
+/* KVM stolen (when guest vCPU is not running) time accounting */
+#define CPUID_KVM_STEAL_TIME       (1U << KVM_FEATURE_STEAL_TIME)
+/* KVM paravirtualized end-of-interrupt signaling */
+#define CPUID_KVM_PV_EOI           (1U << KVM_FEATURE_PV_EOI)
+/* KVM paravirtualized spinlocks support */
+#define CPUID_KVM_PV_UNHALT        (1U << KVM_FEATURE_PV_UNHALT)
+/* KVM host-side polling on HLT control from the guest */
+#define CPUID_KVM_POLL_CONTROL     (1U << KVM_FEATURE_POLL_CONTROL)
+/* KVM interrupt based asynchronous page fault*/
+#define CPUID_KVM_ASYNCPF_INT      (1U << KVM_FEATURE_ASYNC_PF_INT)
+/* KVM 'Extended Destination ID' support for external interrupts */
+#define CPUID_KVM_MSI_EXT_DEST_ID  (1U << KVM_FEATURE_MSI_EXT_DEST_ID)
+
+/* Hint to KVM that vCPUs expect never preempted for an unlimited time */
+#define CPUID_KVM_HINTS_REALTIME    (1U << KVM_HINTS_REALTIME)
+
 /* CLZERO instruction */
 #define CPUID_8000_0008_EBX_CLZERO      (1U << 0)
 /* Always save/restore FP error pointers */
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index 63be5088420..17443552e91 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -27,7 +27,6 @@
 #include "qapi/error.h"
=20
 #include <linux/kvm.h>
-#include "standard-headers/asm-x86/kvm_para.h"
 #include "qom/object.h"
=20
 #define TYPE_KVM_CLOCK "kvmclock"
@@ -333,8 +332,8 @@ void kvmclock_create(bool create_always)
=20
     assert(kvm_enabled());
     if (create_always ||
-        cpu->env.features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
-                                       (1ULL << KVM_FEATURE_CLOCKSOURCE2))=
) {
+        cpu->env.features[FEAT_KVM] & (CPUID_KVM_CLOCK |
+                                       CPUID_KVM_CLOCK2)) {
         sysbus_create_simple(TYPE_KVM_CLOCK, -1, NULL);
     }
 }
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 2f66e63b880..d6fb3bee86d 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -564,13 +564,13 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, ui=
nt32_t function,
          * be enabled without the in-kernel irqchip
          */
         if (!kvm_irqchip_in_kernel()) {
-            ret &=3D ~(1U << KVM_FEATURE_PV_UNHALT);
+            ret &=3D ~CPUID_KVM_PV_UNHALT;
         }
         if (kvm_irqchip_is_split()) {
-            ret |=3D 1U << KVM_FEATURE_MSI_EXT_DEST_ID;
+            ret |=3D CPUID_KVM_MSI_EXT_DEST_ID;
         }
     } else if (function =3D=3D KVM_CPUID_FEATURES && reg =3D=3D R_EDX) {
-        ret |=3D 1U << KVM_HINTS_REALTIME;
+        ret |=3D CPUID_KVM_HINTS_REALTIME;
     }
=20
     if (current_machine->cgs) {
@@ -3978,20 +3978,20 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
         kvm_msr_entry_add(cpu, MSR_IA32_TSC, env->tsc);
         kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_msr);
         kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr);
-        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF_INT)) {
+        if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) {
             kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int=
_msr);
         }
-        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF)) {
+        if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF) {
             kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_EN, env->async_pf_en_m=
sr);
         }
-        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) {
+        if (env->features[FEAT_KVM] & CPUID_KVM_PV_EOI) {
             kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, env->pv_eoi_en_msr);
         }
-        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
+        if (env->features[FEAT_KVM] & CPUID_KVM_STEAL_TIME) {
             kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, env->steal_time_msr=
);
         }
=20
-        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) {
+        if (env->features[FEAT_KVM] & CPUID_KVM_POLL_CONTROL) {
             kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, env->poll_control=
_msr);
         }
=20
@@ -4456,19 +4456,19 @@ static int kvm_get_msrs(X86CPU *cpu)
 #endif
     kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0);
     kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0);
-    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF_INT)) {
+    if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) {
         kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0);
     }
-    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_ASYNC_PF)) {
+    if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF) {
         kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_EN, 0);
     }
-    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) {
+    if (env->features[FEAT_KVM] & CPUID_KVM_PV_EOI) {
         kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, 0);
     }
-    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
+    if (env->features[FEAT_KVM] & CPUID_KVM_STEAL_TIME) {
         kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, 0);
     }
-    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) {
+    if (env->features[FEAT_KVM] & CPUID_KVM_POLL_CONTROL) {
         kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, 1);
     }
     if (has_architectural_pmu_version > 0) {
@@ -6195,7 +6195,7 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address)
         return address;
     }
     env =3D &X86_CPU(first_cpu)->env;
-    if (!(env->features[FEAT_KVM] & (1 << KVM_FEATURE_MSI_EXT_DEST_ID))) {
+    if (!(env->features[FEAT_KVM] & CPUID_KVM_MSI_EXT_DEST_ID)) {
         return address;
     }
=20
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534896; cv=none;
	d=zohomail.com; s=zohoarc;
	b=N1HwMbNY+A8+HNA+x1uvcUi6KYCmX1RKHJpJ5GSOYoA5C021kkFEaS0zddRtX/Yfza3X7oUp+j5gKOepJlL0i5hblH1GozwpyHJItSB8UG1GQ3DGsffQ23IoGmG8WgJyqkUt2NXp8qAL1Xkxzx6E1fBF2z4+3MEgBcXj+URoK5w=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534896;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=4nAGqhO6HWRVdOGt5ty+L8yX0pw1om5Lb+vMQSsKXoE=;
	b=lxSny0N2s47n2lRsJkgs7Wm3EznYcXcb5g3V3rfPc16PcMzIr4VsZmJl+tKh1joIuBr6DO7F5XIguEoHFigWW8OW6xY9Qddcg7w+Z6YnKIzHIwUbECAJkcWiDn++L51j5qOqr0Ab292V9orGUa6a0subKthh+pnCTzAfCpcHDic=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534896354325.68734581283366;
 Fri, 10 Jan 2025 10:48:16 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK3F-0002BZ-Jn; Fri, 10 Jan 2025 13:48:10 -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 <pbonzini@redhat.com>)
 id 1tWK2Q-0000IQ-8H
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:22 -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 <pbonzini@redhat.com>)
 id 1tWK2M-0001AG-KJ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:17 -0500
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-692-GZ2VwdCXMn6-3KNFs-H2Gg-1; Fri, 10 Jan 2025 13:47:12 -0500
Received: by mail-ej1-f71.google.com with SMTP id
 a640c23a62f3a-aaf9d0f4e0eso210605666b.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:12 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99008c394sm1932855a12.7.2025.01.10.10.47.08
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534834;
 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=4nAGqhO6HWRVdOGt5ty+L8yX0pw1om5Lb+vMQSsKXoE=;
 b=KcdVEV5aZXwfOp84gJHqz9JM7EJ02EU573ZYgkWXRDSGEJXKVdgx62qNhsbMzdtVYcSYxz
 Sh68VUrSoIchPTLvCdzqo7UlBEcfFaRK7J4umHoe7fJWnehQ4ejNbqwnBJPkvdgO4L064B
 hEvf346IxFfz8fFCosGABlSpw+LEitE=
X-MC-Unique: GZ2VwdCXMn6-3KNFs-H2Gg-1
X-Mimecast-MFC-AGG-ID: GZ2VwdCXMn6-3KNFs-H2Gg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534831; x=1737139631;
 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=4nAGqhO6HWRVdOGt5ty+L8yX0pw1om5Lb+vMQSsKXoE=;
 b=XiYSoWKnznrZH5vPB8UHD2DP4II9FPLWIam506qZWX5GUlZM/bpAm+7KaFnQ7O0QRF
 Fq4Pp6eevrj+SEbJ4x6vhEahN8NBDtPtgEcGiD7xxVTqGNKc4SunwojwC1PBrdwttna1
 XPN5CmDcJnpvljskp8g6AEbMaMWnxXsz33K1KThkQhzPeFSLzkNvkqHsb86XeQmjHE5N
 RiRlHLzAAxzA4/H6zp1r/GTpwZ+JpQv3Jqxe4L8mSexKeRM2hptfiTk+rtvZjov8FlJJ
 X2dEtJ9Q8FENpqO/yahgdQC+ouqYwvXjpcEm2KHynbhbIAkY22TJmGGq6/N1b8ZcZu7j
 XC/w==
X-Gm-Message-State: AOJu0YwVAKQA2fh3x/PZvBDsWsIMzJsYlneIlWsWklPtMgSV6mzQLSZZ
 MA+Uen1zl6Z2jg4m6c1W3OUeAVRbbiXYQ1LjFitX2k5oxpWVBQcUywI5xu8iFJiVnqfwQsYYtA6
 ZDYyHoYRUYSfwSqamTlAdxV5OFIABuQJsFDnZA48HQ5vhYXEaxc9yuP8Na1UUSWXyVWrU5Lgva5
 bhaz9zMuh+S40iAa3hpkarPDwwFMoLgJhPgoyi17c=
X-Gm-Gg: ASbGncu5Rh7HuC0cv8cHG6XHfCzXOjai9lBEGSdMmIGI36CE4aFtqyV24MOcOQhj5TH
 KI5YIx5wiUh+dYmw37a9by6AAzKhzgvmOh5YS3skzR0Wbgv0FnFhzKBezxBWSM4AOFz45OqLC/0
 gIVyOtGtfNo5W0J+vI2/pDels2lwc6Zdl+a0erigaZ8zCUu2Wk6aX53plvEzoA3EXWX6IMl/glv
 hYcAfj00dEtzNx7Bka0ylHqEUW9O14jkOPBsy+pqfas5+Ii702a+5vWwm4=
X-Received: by 2002:a17:907:1c22:b0:aa6:80fa:f692 with SMTP id
 a640c23a62f3a-ab2abcb0a84mr1205409866b.49.1736534830990;
 Fri, 10 Jan 2025 10:47:10 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHADCMOYKrxysLC1uNIuRomKcWOxr9/vYoKlTm9B1LZIXqHJ0mQw9Q60mIh1cBtA2d3q91x7Q==
X-Received: by 2002:a17:907:1c22:b0:aa6:80fa:f692 with SMTP id
 a640c23a62f3a-ab2abcb0a84mr1205407366b.49.1736534830511;
 Fri, 10 Jan 2025 10:47:10 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>, Xiaoyao Li <xiaoyao.li@intel.com>,
 Zide Chen <zide.chen@intel.com>
Subject: [PULL 21/38] target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and
 MSR_KVM_SYSTEM_TIME definitions
Date: Fri, 10 Jan 2025 19:46:02 +0100
Message-ID: <20250110184620.408302-22-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534897205116600
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

These 2 MSRs have been already defined in kvm_para.h (standard-headers/
asm-x86/kvm_para.h).

Remove QEMU local definitions to avoid duplication.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-4-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index d6fb3bee86d..7870820a2b6 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -95,9 +95,6 @@
 #define KVM_APIC_BUS_CYCLE_NS       1
 #define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
=20
-#define MSR_KVM_WALL_CLOCK  0x11
-#define MSR_KVM_SYSTEM_TIME 0x12
-
 /* A 4096-byte buffer can hold the 8-byte kvm_msrs header, plus
  * 255 kvm_msr_entry structs */
 #define MSR_BUF_SIZE 4096
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534890; cv=none;
	d=zohomail.com; s=zohoarc;
	b=aX9t0WdFYjA5JlpvcX28Tudlp9S72hATJmCPWztFKg/2vSeTcxDJIbXvwPMZC2WAvP28QefOyoOJltl+G8BWDFFzr7bAQpQCdVe5Pr0g1KXxXV2R+ozRtPLdjGSdMH1qkHMzKbxbGdW1Qs1i7EfZ1uzZ/fSXAaD+6d7eOO6TpRk=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534890;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=8MQ2MjMB7jb1D3OQnYs66viar17UNTxK/JIEnyWAIok=;
	b=Lo7ksRxbWeVFzTqlZmC1/zeXqWq1PySXfh72YJdyHNfymQTNptqAMqdWaraG9db0bTxf0JjzdYxsFkjwKK2DGFFx8ngcC3gb9CS5UJhsMgZaRbF8c9UM+ncXA/PvtfErjJL4peiASsQTBAqzI6lhPukkSz8kkWe+M4g4RZJ27Sc=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534890733648.8616922292435;
 Fri, 10 Jan 2025 10:48:10 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK39-00020g-EZ; Fri, 10 Jan 2025 13:48:04 -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 <pbonzini@redhat.com>)
 id 1tWK2S-0000Ii-Ae
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:24 -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 <pbonzini@redhat.com>)
 id 1tWK2P-0001Ai-9T
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:19 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-100-cpqEE92TMOmb_du2iKJR_A-1; Fri, 10 Jan 2025 13:47:14 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aa6b904a886so229341266b.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:14 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c9060e27sm195956366b.13.2025.01.10.10.47.11
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:11 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534836;
 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=8MQ2MjMB7jb1D3OQnYs66viar17UNTxK/JIEnyWAIok=;
 b=X4WZKvKqzk054hlKaD5YVIkn6oG+2KnX+lXmHVweLbDA0CSuZyXU3IKe5fOC9sb3YkhwxO
 4XQRQMZRIV65W5xYiA+7bkFFEHUwghnZ2gQ8NnXUshA8hQsR1kVZV/P/ORr7M6MTeyAu9R
 htzy6wKbD5xbAwRQeYYIBE77EiOLTfc=
X-MC-Unique: cpqEE92TMOmb_du2iKJR_A-1
X-Mimecast-MFC-AGG-ID: cpqEE92TMOmb_du2iKJR_A
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534833; x=1737139633;
 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=8MQ2MjMB7jb1D3OQnYs66viar17UNTxK/JIEnyWAIok=;
 b=RjBBoOZQj3NfeQMDaMbBHjGpd/XORkEgfllJHTNpBJYWed2d5s3JoNN9i+c+gVBEM0
 81+yTgc9Zd4aB8QOkT+GfTOhpKzaGQEQS/GsNJB+DZu3f0BOhgVaflDvem7ByOvZhB3e
 apbYxihn/o64RxsABO3qmXYsus1JK3gP8A/saelrw6/LL+atiL/EKpqrdWBQ1PnE3/7b
 kWS6kerSY/t1foU0d5hE7tMH4hZWcKQVQxpLwUC9mEVngsJFy0IX2Sm9HU32So7EGh12
 S3im3cc8oi1tOIJSrSlkImBuZ9zZfJgjruVn1v+TpIK/Som6Z8xgZft5mmHhR32f18zN
 SW0g==
X-Gm-Message-State: AOJu0YwWpcvC/YefDJ3y8n00gfSRUgm2B+aiC351dfqDKUWwb3DD93W8
 dotx5vjHLpflsSIwG0OzXA64dXTaw/MNpECloKIQ9BBvwfku3aCcsxKxaR8NB75bboH/EA7i+SG
 7zDMdZf0NsPJl9qQoXFUjyMmxS6+fNK6MYXEfju92RIY9CI6A1kJMf92Fx/q4aDhOuqINxCe46b
 GB0XXA/uwsaegusjVYzwGx/hcG1Oww46tNqdgPwVs=
X-Gm-Gg: ASbGnctujpfI7eZ51h6WQAE6uInZfCzIFmToj6uTJTURoB6KCFQ/OSfxTcDGk51RvQk
 1i9re+ExVUKuRlWJ7lq2rsNZ6GN9ZtPu2i3maQmtHzrfedily2vZEvL8lEd2tS8OTZEtFXZX/PJ
 TeH+EZaqnFAXqMx19zMUtQpWZyP8rogxcswW6HBc4yw1cZZesc9Gx7pnXBHuK6oUI9BWycq/ZVb
 zkRPegHRpYrrMTHv+T773ymG9szjp+R04UPrLQ3gzDWF2f2P9W3/qVzC5o=
X-Received: by 2002:a17:907:7b8d:b0:aab:7461:fbe5 with SMTP id
 a640c23a62f3a-ab2abdc0a98mr1140708766b.45.1736534832983;
 Fri, 10 Jan 2025 10:47:12 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFQ94RtGDZN63sOroT2lh+YsP0P1ThWnpxMz7Wr20WQT9DSuEFB27/AqLzPxBjLnM7VMQOEZA==
X-Received: by 2002:a17:907:7b8d:b0:aab:7461:fbe5 with SMTP id
 a640c23a62f3a-ab2abdc0a98mr1140706366b.45.1736534832563;
 Fri, 10 Jan 2025 10:47:12 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PULL 22/38] target/i386/kvm: Only save/load kvmclock MSRs when
 kvmclock enabled
Date: Fri, 10 Jan 2025 19:46:03 +0100
Message-ID: <20250110184620.408302-23-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534892758019000
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

MSR_KVM_SYSTEM_TIME and MSR_KVM_WALL_CLOCK are attached with the (old)
kvmclock feature (KVM_FEATURE_CLOCKSOURCE).

So, just save/load them only when kvmclock (KVM_FEATURE_CLOCKSOURCE) is
enabled.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-5-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 7870820a2b6..7536a3c9fd0 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -3973,8 +3973,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
      */
     if (level >=3D KVM_PUT_RESET_STATE) {
         kvm_msr_entry_add(cpu, MSR_IA32_TSC, env->tsc);
-        kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_msr);
-        kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr);
+        if (env->features[FEAT_KVM] & (CPUID_KVM_CLOCK | CPUID_KVM_CLOCK2)=
) {
+            kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, env->system_time_m=
sr);
+            kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, env->wall_clock_msr=
);
+        }
         if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) {
             kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, env->async_pf_int=
_msr);
         }
@@ -4451,8 +4453,10 @@ static int kvm_get_msrs(X86CPU *cpu)
         }
     }
 #endif
-    kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0);
-    kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0);
+    if (env->features[FEAT_KVM] & (CPUID_KVM_CLOCK | CPUID_KVM_CLOCK2)) {
+        kvm_msr_entry_add(cpu, MSR_KVM_SYSTEM_TIME, 0);
+        kvm_msr_entry_add(cpu, MSR_KVM_WALL_CLOCK, 0);
+    }
     if (env->features[FEAT_KVM] & CPUID_KVM_ASYNCPF_INT) {
         kvm_msr_entry_add(cpu, MSR_KVM_ASYNC_PF_INT, 0);
     }
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535320; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ip5qziwnJpFi5RCUn8Dbt4znjbQ87mu64ZrIbUGMEFuJN8fKTMIsKv/w2WdUfws9o9AzcQdwUF4C+FPom5SoUhNfN8FpG1zLG/piF7LEN8iJ+mWL5qrukhr0ahD0stQTB/DD9lfPMguQe+gkF84+FEnggO7V5HG5STJoGm5UspA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535320;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=QD2muu0CYvy6M9Q4xI+b2Xo6yFDVXnxkK2RJi0em5XA=;
	b=KWiYsNNlXKoohPA2TBuj39AfBCJHamUEMLjNwtGGeZqEcmf9uq8GAzl4MDJTCe+J1XGNt3cfLFzuUe97jCquxQ3iumhHIXkeZ2Esqk76rdK3p7JMlmW9i+Zd3SwBMM+3pOT4mmWKbKWH0af6vY+Rqo7cY0HQ9fbctvrj7s8eZFc=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535320376669.8424678622471;
 Fri, 10 Jan 2025 10:55:20 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK34-0001iW-Lq; Fri, 10 Jan 2025 13:47:58 -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 <pbonzini@redhat.com>)
 id 1tWK2U-0000J0-Bu
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:24 -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 <pbonzini@redhat.com>)
 id 1tWK2Q-0001At-HC
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:21 -0500
Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com
 [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-467-YJhGpRBzPji6QeAJMCrghA-1; Fri, 10 Jan 2025 13:47:16 -0500
Received: by mail-ed1-f71.google.com with SMTP id
 4fb4d7f45d1cf-5d821f9730aso3652981a12.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:16 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c905e283sm192956366b.31.2025.01.10.10.47.13
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534837;
 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=QD2muu0CYvy6M9Q4xI+b2Xo6yFDVXnxkK2RJi0em5XA=;
 b=X3UDPmhGh1dYNEYrmXHXzDPtSOgby5zDpS7GHxnj3vDOFbfEPMlCSc89FlcIparJqYe+TJ
 Pq7t6MVgBKy2Ig68D0WQcsgrf4/HwKVF4jKI2qSIpt17cdiGWqhufOQpsXBbGPL43KqmCs
 fiwQaKbFDlKSdP19p2wZ0Mu9RUFUoS4=
X-MC-Unique: YJhGpRBzPji6QeAJMCrghA-1
X-Mimecast-MFC-AGG-ID: YJhGpRBzPji6QeAJMCrghA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534835; x=1737139635;
 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=QD2muu0CYvy6M9Q4xI+b2Xo6yFDVXnxkK2RJi0em5XA=;
 b=hcvqZbytOSZEkll/wFIRgON0w/A6zfOBllz828ArhT6aOURvZI28AQNEeiszYrYI8z
 6kldKRjsILL8JK9Xl9wXF3Yj4ea7y5MmNIrDSPws4H1mchqDhGAXmOpD3E/Chq34Rhrj
 3jnGPQKAeGLM01q2/k53AOJUnX9ZTcfVD9NYLMezZaQ0CYAxCCTCopPU3JXoFxj8h5JX
 T3QlmHm4HHdCXC3uCl4iEqy01yyWufJuxm+xpswAGIQm9FNR0bgo2bkK5wRbQYA3bFT9
 UqXDQ6WpjHxlodQb6MIdFm7N7z95ure/ycZKGGLG6hZNFZCYLGSJi/lC5hID3DLtTSQ/
 7DhQ==
X-Gm-Message-State: AOJu0YwsTLP+63PqjLd2TP6OqsahRLr4jPD+50Ie9w0yWf8+QeE5ZMQ0
 GYUIZcnBIIJzoSyipC957fkXAl0jPmS79DN27lx7lgfHM1M81zJ9aW1l9mlaoF4dvL/ByYlQRGF
 F8oBfsBcG7lHOe5kc0ZzgZxl/JA3apcVSnKt/MZoxivLCvKwnUaF85zkD7cb6jICnVPIT9jx/OO
 krw6fwvzvwix8DJkIrey0+pOldQAFLg3QzRM0qnEM=
X-Gm-Gg: ASbGncuBoJUi9u9RhZNOYZf8xP6wEpka/Upd3HumNpefnxd7v6BTItIRtme6JMLC5ii
 IfuNV7sYrhYkHLf+b/bnF6ECOD2Atubo3+VzL2xEBGHvdLDNa4bT1eRAT29dqYaJFGPRN1XFY7x
 YGpN58nF03cwVBdzDhOkJL4iQ5XuabXRMjKs50SW6P3J2t+YKUN+0TZo1Bpr/5hzh0kmB4/3N4i
 a1h1jLIsJF47XTJv98G20SjzRwtdm8fUQ4+d8dMLRNyxCRuwade/bqgGpI=
X-Received: by 2002:a17:906:f5aa:b0:aa6:945c:4531 with SMTP id
 a640c23a62f3a-ab2c3c5c93dmr817943066b.7.1736534834990;
 Fri, 10 Jan 2025 10:47:14 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGmKMjJLhbC5/lwN6KWSHDST+TBBjTHyDflWfxYUSVdAcjcV+3OqTbB/O/vPD6ZZlIfK5OTEw==
X-Received: by 2002:a17:906:f5aa:b0:aa6:945c:4531 with SMTP id
 a640c23a62f3a-ab2c3c5c93dmr817941066b.7.1736534834566;
 Fri, 10 Jan 2025 10:47:14 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PULL 23/38] target/i386/kvm: Drop workaround for
 KVM_X86_DISABLE_EXITS_HTL typo
Date: Fri, 10 Jan 2025 19:46:04 +0100
Message-ID: <20250110184620.408302-24-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535322382019000
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

The KVM_X86_DISABLE_EXITS_HTL typo has been fixed in commit
77d361b13c19 ("linux-headers: Update to kernel mainline commit
b357bf602").

Drop the related workaround.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-7-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 7536a3c9fd0..17f23607ed0 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -3100,10 +3100,7 @@ static int kvm_vm_set_tss_addr(KVMState *s, uint64_t=
 tss_base)
 static int kvm_vm_enable_disable_exits(KVMState *s)
 {
     int disable_exits =3D kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS=
);
-/* Work around for kernel header with a typo. TODO: fix header and drop. */
-#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_H=
LT)
-#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL
-#endif
+
     if (disable_exits) {
         disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT |
                           KVM_X86_DISABLE_EXITS_HLT |
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535227; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Hn2w9tj7vzP537tvuDmFeIiArchB16PLAUByvS5XaaJganMs1B7VaTj7b0zMopGr5D7LgwZymcHNA8GWEv5U/Idkfo6W/4nLlV4WwnwQ04+BYSqNhNyzRMDoXfzvfrBJxt6pYmvaTOyF/bjakKvmNwZsZ5TkmjfD5JOXQCPADNA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535227;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=IZZpz1I4nrrOQRN+TRsF/5PkMw69HmjZiuT6tDsXbT4=;
	b=eJMqo/dPMZtwciRAsW1o6xxuQpw1D9e0yTSX471tJjcLi6uRHvOe1s/7CUhuv8G5G+XvgIjr0dTX52qWKDLIPGC3xaVOiOYjAxR7GA/2/q6hipwiEuQGC98wmMMQQPew/m1TX2LWMeiKeGL3JnsTBkhQvQfEE3wwDLe8f6z46Yg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535227614729.6552467795004;
 Fri, 10 Jan 2025 10:53:47 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4M-0003v2-Vg; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2W-0000MR-8x
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:24 -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 <pbonzini@redhat.com>)
 id 1tWK2T-0001BJ-0s
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:23 -0500
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-648-QaHz8nPAPlqIOEONLei_WA-1; Fri, 10 Jan 2025 13:47:19 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-aa67855b3deso200719866b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:18 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c96485aasm194854066b.176.2025.01.10.10.47.15
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:15 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534840;
 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=IZZpz1I4nrrOQRN+TRsF/5PkMw69HmjZiuT6tDsXbT4=;
 b=Z/6RDpkMXZ92zIHqlpZxH+uJjBEQ0U5tluLWradpwmvdkBd0qMnvj6+8Jh3HHWW7W2nbSc
 gnB30mEZ5sVxmXCPugcplk2rsfoEbeA7EKAziZkIXLhv6CWKUtteL0uBORyqGnCRv/E/IT
 FcvHEao7LiYrNb0uOWeLspP/lxn3/mU=
X-MC-Unique: QaHz8nPAPlqIOEONLei_WA-1
X-Mimecast-MFC-AGG-ID: QaHz8nPAPlqIOEONLei_WA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534837; x=1737139637;
 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=IZZpz1I4nrrOQRN+TRsF/5PkMw69HmjZiuT6tDsXbT4=;
 b=wC8ZDXkAvl5/xx0ohmxL6zW9dHSJUOvhY887tGN8waTpc0cP8q2N7RSdjUo/WNIftI
 yePuk00Yl+MCptz4X82jlGo6YgSJ0cuHCp17wU4MmlvT4VJoLb/vYOUQ3AMxVGyFJW8X
 CGvzOilj2pGGugYnHF3K2yYcFFm/YqbA0TtO1TrfVXLlwJlTSLDraZaODXi2l3CUwqej
 O1tXzjOz/PFXvL63SdIlW1TCIlc1nHiTAEZaUDQEIC9f6dGlhPPSBE5hF4cZjgWFglcw
 Ifc/THqH/iZJfvShaQZcSiV0SJZIso46u32ln6SiKjpzD4tyxhqnMIJz9M44JxEtRdCZ
 QINg==
X-Gm-Message-State: AOJu0YzJhFYXr7c9ldqLxHyaCMjndyl3PB0IQC8wqDKdJF0eOglzPQo4
 /wT9rQXG+3G2WoUYYXhxlaKG9vIUHtqGlPxo/6l8qk7i/xSF+kScOcnui0x9t78b8+whdExPTOQ
 mPv3Qagl3JipdUPKfJzYXmOC7Mh2bXDi+AJXc1vTotS5ey8Qusq+9SscCG2ptUNz+E+wKLeZku5
 Iuh2rWstIYhyGedRadYNz3OIx29y0RpHmzrcX/5VY=
X-Gm-Gg: ASbGncuOHUW6HaJ9j9+xVPgC1IaNCXjsdG3aAhhBAlS+4trB5MgnZz9uxGPJi5/njuE
 PhMDguHts6mj3xd/rrSlS1bePfjl8mVEj2KRW849GfiCIlBF+iIAh6lVvH/bGZLaAqGKzhrcf1V
 PdagppUvAyntFHJ5/KzvwDHVOgJm1w4tZk2DHBpaFo8zjI9uBsg58d/gAFM4oX2rWzVTVkAAquN
 9zeCVo/Dhid/78gzHHP7U+FHf1mANi6WwTRpd6aiTT06c/ai1Pfh+aTlJI=
X-Received: by 2002:a17:906:db04:b0:aab:eefc:92e5 with SMTP id
 a640c23a62f3a-ab2ab6c46a0mr922132366b.14.1736534836991;
 Fri, 10 Jan 2025 10:47:16 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFHwbxf+HDdzW3foNxEh1+dCID7p8h+pNbaC/OmiN7IsVgNWVbfVRRe//1Dc+tnvITau2jOfw==
X-Received: by 2002:a17:906:db04:b0:aab:eefc:92e5 with SMTP id
 a640c23a62f3a-ab2ab6c46a0mr922130366b.14.1736534836543;
 Fri, 10 Jan 2025 10:47:16 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>, Xiaoyao Li <xiaoyao.li@intel.com>,
 Pankaj Gupta <pankaj.gupta@amd.com>, Zide Chen <zide.chen@intel.com>
Subject: [PULL 24/38] target/i386/confidential-guest: Fix comment of
 x86_confidential_guest_kvm_type()
Date: Fri, 10 Jan 2025 19:46:05 +0100
Message-ID: <20250110184620.408302-25-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535228644116600
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

Update the comment to match the X86ConfidentialGuestClass
implementation.

Reported-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-8-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/confidential-guest.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu=
est.h
index 0afb8317b58..164be7633a2 100644
--- a/target/i386/confidential-guest.h
+++ b/target/i386/confidential-guest.h
@@ -46,7 +46,7 @@ struct X86ConfidentialGuestClass {
 /**
  * x86_confidential_guest_kvm_type:
  *
- * Calls #X86ConfidentialGuestClass.unplug callback of @plug_handler.
+ * Calls #X86ConfidentialGuestClass.kvm_type() callback.
  */
 static inline int x86_confidential_guest_kvm_type(X86ConfidentialGuest *cg)
 {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535266; cv=none;
	d=zohomail.com; s=zohoarc;
	b=YooxAa03E9CifstZHussz8t/c6r33lTFZpllvzGj+7mxjajHQnq8WPiRZIHZ1KnR6hNTi8HrLs9hNYhOPUI+RfSUTbvvwPi4ZdFcs13I5Qveo4sdnJQee4loeTx10KUzmCjXjRad1KiUW2BGP3NUStscyslvTzpooO+7DD3mtEU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535266;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=HQJ66dju737femJRsMpPCtvgIC+UUMnbAS70jNpxfeo=;
	b=a/fOTJbiRXOpTfOpMMYpkVgGoVbR0NjEfyNSsqjZMjacKKRD3Z2SFW5rXHYlMUmCU83Bdt8P9TVN9oMUv0TCXTHGMBNeaMKwttYRaC8Myee6fWZkLmgX1Zkd8RJv7sLzADeEzsLIwQ1C2gu3Cus7WnIeh8AYFc9iVWCp0jJSavI=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535266105179.53653062373905;
 Fri, 10 Jan 2025 10:54:26 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4T-0004d8-2r; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2Y-0000OG-Pm
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:28 -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 <pbonzini@redhat.com>)
 id 1tWK2W-0001Bc-JC
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:26 -0500
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-93-QFQTHwO4OwOTvLVjgjifTA-1; Fri, 10 Jan 2025 13:47:21 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-aa680e17f6dso173624666b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:21 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99083fbd7sm1910629a12.73.2025.01.10.10.47.17
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:17 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534843;
 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=HQJ66dju737femJRsMpPCtvgIC+UUMnbAS70jNpxfeo=;
 b=cVkrRV3MqMvYCsBr2ISH2ECpYj+fDoJfnsc9ZrwYZfteqW32+Yd015SU0gdzYExCHDh60z
 cXmEtA2Q/vHT7bl4cg+/s4at6GRuiIczkh5zQVTyKVdPaoQ5cCDxW0Pt5eHtCYsERIxVkX
 ghJh4thNUsLoRjdwtX63B/HpXodcMKI=
X-MC-Unique: QFQTHwO4OwOTvLVjgjifTA-1
X-Mimecast-MFC-AGG-ID: QFQTHwO4OwOTvLVjgjifTA
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534839; x=1737139639;
 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=HQJ66dju737femJRsMpPCtvgIC+UUMnbAS70jNpxfeo=;
 b=r6CJOfZryFy4ZokqhF+Jqm7bwWODWyCLvvpnzp647Ofs6a5n/bwd5jXFc7LvboFFVS
 Q0ZQ5dc/hwD9s9Prl13ZOx8PsqpWdnAZTXX7+ojKnHHgONpSnqdIaG9uvF5GaiSlD1A5
 R3G28q4pXhzAooAPov+rfwt3yvY7gf9CtCXmFPlV6xCsJT9Hu4xiEv4YABloIJHOHsHX
 N0GjGMqpxjYd0AngxLsp0cOxNmDuJtUFHQ/Pkg9ITxlozIW3UgDh3j4sn5r0vY/ksO+H
 N6fv2ZrhHG1jmNzFPL0DE7ysUnF70/ZfFLtwa1GbgNKKFXzL16x49iQQS+ASnBcJtZ0v
 ehDg==
X-Gm-Message-State: AOJu0YyN9s3K17AujH8df74j0/ryDsnAg265VLbI5ElBfhCa9cjZY8+G
 msYaZYLvjApyluRTDtcINxg6HXq+9jnfM08MDT1hUDx2DubiSqsa1WCTZ8MugbHGq/sCS0M5bJi
 aT4jU+Y4fTI1Csp1pU7VLYsJPbJTbCzPGj0RfJhnruO4CStaxbstbEyzpne4kkb3xZofGZXO4g+
 RDstIW50UBnJIWyjQXN7QsMVsbsGfVYUCBtCBiP0w=
X-Gm-Gg: ASbGncv95U/Hecb90niLbOf26Vry4Xm5hbQHDR7LjR8adXSdIb8MHtTeuz+yHIZU5tp
 bDhzlHTXCBUjLq06F3LpV1iM2vwGLoPwWHJ2hBqVtRa0x+j7OEgoamZSaM1Me8m+XV5GIm4MD0V
 YFZNKYT3+9y26PRmlX0IMFGyMWHqD7f2eXJRrYE56twUlc8Pz2mLADB6XA0Cvft8tBKXY0ROIoJ
 dTAEDt3IzzxjC5zTyEV+a2RuhFsvUnJDgjPE8BcPu8bbIdJEruH96zrCO4=
X-Received: by 2002:a05:6402:2548:b0:5d4:2ef7:1c with SMTP id
 4fb4d7f45d1cf-5d972e639e4mr25747704a12.24.1736534839122;
 Fri, 10 Jan 2025 10:47:19 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IEWmpI1umUMUwPRgZY6i1mxDThPk3FoW637c1jJtDAv45Lh1mt1m9Uz1B+TozVgFeYi2tgeJw==
X-Received: by 2002:a05:6402:2548:b0:5d4:2ef7:1c with SMTP id
 4fb4d7f45d1cf-5d972e639e4mr25747657a12.24.1736534838679;
 Fri, 10 Jan 2025 10:47:18 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PULL 25/38] target/i386/kvm: Clean up return values of MSR filter
 related functions
Date: Fri, 10 Jan 2025 19:46:06 +0100
Message-ID: <20250110184620.408302-26-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535268536019000
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

Before commit 0cc42e63bb54 ("kvm/i386: refactor kvm_arch_init and split
it into smaller functions"), error_report() attempts to print the error
code from kvm_filter_msr(). However, printing error code does not work
due to kvm_filter_msr() returns bool instead int.

0cc42e63bb54 fixed the error by removing error code printing, but this
lost useful error messages. Bring it back by making kvm_filter_msr()
return int.

This also makes the function call chain processing clearer, allowing for
better handling of error result propagation from kvm_filter_msr() to
kvm_arch_init(), preparing for the subsequent cleanup work of error
handling in kvm_arch_init().

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-9-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 87 ++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 43 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 17f23607ed0..097a040da30 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -108,8 +108,8 @@ typedef struct {
 } KVMMSRHandlers;
=20
 static void kvm_init_msrs(X86CPU *cpu);
-static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rd=
msr,
-                           QEMUWRMSRHandler *wrmsr);
+static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdm=
sr,
+                          QEMUWRMSRHandler *wrmsr);
=20
 const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D {
     KVM_CAP_INFO(SET_TSS_ADDR),
@@ -3150,17 +3150,21 @@ static int kvm_vm_enable_notify_vmexit(KVMState *s)
=20
 static int kvm_vm_enable_userspace_msr(KVMState *s)
 {
-    int ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0,
-                                KVM_MSR_EXIT_REASON_FILTER);
+    int ret;
+
+    ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0,
+                            KVM_MSR_EXIT_REASON_FILTER);
     if (ret < 0) {
         error_report("Could not enable user space MSRs: %s",
                      strerror(-ret));
         exit(1);
     }
=20
-    if (!kvm_filter_msr(s, MSR_CORE_THREAD_COUNT,
-                        kvm_rdmsr_core_thread_count, NULL)) {
-        error_report("Could not install MSR_CORE_THREAD_COUNT handler!");
+    ret =3D kvm_filter_msr(s, MSR_CORE_THREAD_COUNT,
+                         kvm_rdmsr_core_thread_count, NULL);
+    if (ret < 0) {
+        error_report("Could not install MSR_CORE_THREAD_COUNT handler: %s",
+                     strerror(-ret));
         exit(1);
     }
=20
@@ -3169,36 +3173,37 @@ static int kvm_vm_enable_userspace_msr(KVMState *s)
=20
 static void kvm_vm_enable_energy_msrs(KVMState *s)
 {
-    bool r;
+    int ret;
+
     if (s->msr_energy.enable =3D=3D true) {
-        r =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT,
-                           kvm_rdmsr_rapl_power_unit, NULL);
-        if (!r) {
-            error_report("Could not install MSR_RAPL_POWER_UNIT \
-                                handler");
+        ret =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT,
+                             kvm_rdmsr_rapl_power_unit, NULL);
+        if (ret < 0) {
+            error_report("Could not install MSR_RAPL_POWER_UNIT handler: %=
s",
+                         strerror(-ret));
             exit(1);
         }
=20
-        r =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT,
-                           kvm_rdmsr_pkg_power_limit, NULL);
-        if (!r) {
-            error_report("Could not install MSR_PKG_POWER_LIMIT \
-                                handler");
+        ret =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT,
+                             kvm_rdmsr_pkg_power_limit, NULL);
+        if (ret < 0) {
+            error_report("Could not install MSR_PKG_POWER_LIMIT handler: %=
s",
+                         strerror(-ret));
             exit(1);
         }
=20
-        r =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO,
-                           kvm_rdmsr_pkg_power_info, NULL);
-        if (!r) {
-            error_report("Could not install MSR_PKG_POWER_INFO \
-                                handler");
+        ret =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO,
+                             kvm_rdmsr_pkg_power_info, NULL);
+        if (ret < 0) {
+            error_report("Could not install MSR_PKG_POWER_INFO handler: %s=
",
+                         strerror(-ret));
             exit(1);
         }
-        r =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS,
-                           kvm_rdmsr_pkg_energy_status, NULL);
-        if (!r) {
-            error_report("Could not install MSR_PKG_ENERGY_STATUS \
-                                handler");
+        ret =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS,
+                             kvm_rdmsr_pkg_energy_status, NULL);
+        if (ret < 0) {
+            error_report("Could not install MSR_PKG_ENERGY_STATUS handler:=
 %s",
+                         strerror(-ret));
             exit(1);
         }
     }
@@ -5841,13 +5846,13 @@ void kvm_arch_update_guest_debug(CPUState *cpu, str=
uct kvm_guest_debug *dbg)
     }
 }
=20
-static bool kvm_install_msr_filters(KVMState *s)
+static int kvm_install_msr_filters(KVMState *s)
 {
     uint64_t zero =3D 0;
     struct kvm_msr_filter filter =3D {
         .flags =3D KVM_MSR_FILTER_DEFAULT_ALLOW,
     };
-    int r, i, j =3D 0;
+    int i, j =3D 0;
=20
     for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) {
         KVMMSRHandlers *handler =3D &msr_handlers[i];
@@ -5871,18 +5876,13 @@ static bool kvm_install_msr_filters(KVMState *s)
         }
     }
=20
-    r =3D kvm_vm_ioctl(s, KVM_X86_SET_MSR_FILTER, &filter);
-    if (r) {
-        return false;
-    }
-
-    return true;
+    return kvm_vm_ioctl(s, KVM_X86_SET_MSR_FILTER, &filter);
 }
=20
-static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rd=
msr,
-                    QEMUWRMSRHandler *wrmsr)
+static int kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdm=
sr,
+                          QEMUWRMSRHandler *wrmsr)
 {
-    int i;
+    int i, ret;
=20
     for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) {
         if (!msr_handlers[i].msr) {
@@ -5892,16 +5892,17 @@ static bool kvm_filter_msr(KVMState *s, uint32_t ms=
r, QEMURDMSRHandler *rdmsr,
                 .wrmsr =3D wrmsr,
             };
=20
-            if (!kvm_install_msr_filters(s)) {
+            ret =3D kvm_install_msr_filters(s);
+            if (ret) {
                 msr_handlers[i] =3D (KVMMSRHandlers) { };
-                return false;
+                return ret;
             }
=20
-            return true;
+            return 0;
         }
     }
=20
-    return false;
+    return -EINVAL;
 }
=20
 static int kvm_handle_rdmsr(X86CPU *cpu, struct kvm_run *run)
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534952; cv=none;
	d=zohomail.com; s=zohoarc;
	b=lC/VdoqBZu5ei6ZCMZVaDEsuFD5AU2TRVUq0VMP8sN2+slulJ0x7tvxDy7nrqIdLqE2zCoHLisciOovt6t+lU8My2b3aTZLOgsDjAzls/fGXxlmwlOJhKxiSwHgvuBqj0/3+nwTm6dzOJjTQAQ60lcHemc7dRxmoXsBpIEdkyno=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534952;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=KwvMlaaL+tPMbyB1+Vl82XLEBLQqNeaz0XWCjaoRtTw=;
	b=YQPMHkraS54f0TsQePxYrGfwHg5Fzhz+6tl5TiyPNaUMAzGambBb5RMTVAJUGGcpKWPlp5ylev+LuZbFcs4qS9kHS3YoWf72/Cg9gluLHjOTMP9IzYcAEHWyWegC7+NYDDziiX1zzFu/D/9HciA4G3FQ/5PvcFaaS1KzhZ+Rba8=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534952000684.8889553095979;
 Fri, 10 Jan 2025 10:49:12 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK3J-0002OD-Mn; Fri, 10 Jan 2025 13:48: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 <pbonzini@redhat.com>)
 id 1tWK2a-0000ON-Ah
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:29 -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 <pbonzini@redhat.com>)
 id 1tWK2X-0001C6-PV
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:27 -0500
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-686-sNHVW9b6OMS7Fso_hPYbAg-1; Fri, 10 Jan 2025 13:47:24 -0500
Received: by mail-ej1-f70.google.com with SMTP id
 a640c23a62f3a-aa67855b3deso200726566b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:24 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c95648b1sm192320666b.112.2025.01.10.10.47.19
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534845;
 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=KwvMlaaL+tPMbyB1+Vl82XLEBLQqNeaz0XWCjaoRtTw=;
 b=VGLjURof/tVcmHj1tVssuS3BILZFW0gmcZRjwegxsumHaJocoLk7xFQQLQvD5An80Fd5a4
 ifF/o6FQIpmUhm7l+us9N+kGctQZbDsFyjdcUPSE676oLHFe0wL9M6BRsoF7OfkDUEOL9/
 bUxEE8yIGux8bfK8+kB1/1+jyW6pYm8=
X-MC-Unique: sNHVW9b6OMS7Fso_hPYbAg-1
X-Mimecast-MFC-AGG-ID: sNHVW9b6OMS7Fso_hPYbAg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534842; x=1737139642;
 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=KwvMlaaL+tPMbyB1+Vl82XLEBLQqNeaz0XWCjaoRtTw=;
 b=Lox7jsoKcGlYxXlx/u4U7l0e/iOqKHcMLJ78J59nyx9PjRnXhcWJdpMF64oJsOeAQ1
 SCBzp/f7hMm+7R88RZJRYZpPQbMhJyxdzUu5n4I+yDtqT0FJhVv4q7bibyN3iIKZpDMA
 weoVe8ZrruBi21Or1pC5gG8uWIhX4WUo5ZTar6fbgPokY78nb4VX8u8VQ3HDizbxiprL
 WDJKFgxskBaVhtDe9s+SqFtUal500JmvxjtWZQ5bDxSI4BL5ZL+FZmE9YllVmOe1/HT2
 lZIKte8f9zlnHCAppe3j3LKwoGl8B+odrIZ4MEuERSQTB6Zzqmt/OHM6iocybkJrUt5B
 kODg==
X-Gm-Message-State: AOJu0Yz8V761u9PfXp6SLulaD5LJeOerVpgwDGsmHhl+2X2RIl63H8Kl
 CTsbgZ/aPyBzXdKrR216frSc/gZtVk5/853NGSNT2gD9WDn3ZzQZZfiCNEiXMjI7Xz5FGrmTugD
 BchA1rbbD7IVUH78oU+GcjGNxD0X0I+lBjczpP1Bnh31KKtsnCrvneL52ISsiFM3h+O+X5XRNWX
 CkzYJ0G6d1fALnGMIy0HzKB8tNLjCeADjBklZ/kgY=
X-Gm-Gg: ASbGnct6KbFVDoie2quhDrsiGkJPcglpE65PpyDl+sRaivswyGxJ6vTGverT1GveerV
 oi8+rTUUYK4BmJsixUbtT7ANitskGY3zlztyLgTwT3KtpHn7iEhahxFA05softUfE4lc9nGKnoS
 97wB4+YtfxSyr8jU6c7JqTMWZiz/LgoT8+PyK08P1q2uKGi0uasxEjp7YygqxTv5U9k/svqwsYC
 79jDnWRWubhBmQDmoEwn1FFUjLMkKDtnRgHLgc85uwtU7bZCIKuAjJQXWQ=
X-Received: by 2002:a17:906:c102:b0:aa6:7f99:81aa with SMTP id
 a640c23a62f3a-ab2ab676541mr974933266b.6.1736534842209;
 Fri, 10 Jan 2025 10:47:22 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFSOtxbDmrlKrcpt/J7ZFm/gGnj3omYM4o1KKX8yxlVl+duSSQJUFniPqFWRRSA9ObS5oIJiA==
X-Received: by 2002:a17:906:c102:b0:aa6:7f99:81aa with SMTP id
 a640c23a62f3a-ab2ab676541mr974930866b.6.1736534841748;
 Fri, 10 Jan 2025 10:47:21 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 26/38] target/i386/kvm: Return -1 when
 kvm_msr_energy_thread_init() fails
Date: Fri, 10 Jan 2025 19:46:07 +0100
Message-ID: <20250110184620.408302-27-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534953566116600
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

It is common practice to return a negative value (like -1) to indicate
an error, and other functions in kvm_arch_init() follow this style.

To avoid confusion (sometimes returned -1 indicates failure, and
sometimes -1, in a same function), return -1 when
kvm_msr_energy_thread_init() fails.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-10-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 097a040da30..3624abbb397 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2936,7 +2936,6 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma=
chineState *ms)
 {
     MachineClass *mc =3D MACHINE_GET_CLASS(ms);
     struct KVMMsrEnergy *r =3D &s->msr_energy;
-    int ret =3D 0;
=20
     /*
      * Sanity check
@@ -2946,13 +2945,11 @@ static int kvm_msr_energy_thread_init(KVMState *s, =
MachineState *ms)
     if (!is_host_cpu_intel()) {
         error_report("The RAPL feature can only be enabled on hosts "
                      "with Intel CPU models");
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     if (!is_rapl_enabled()) {
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     /* Retrieve the virtual topology */
@@ -2974,16 +2971,14 @@ static int kvm_msr_energy_thread_init(KVMState *s, =
MachineState *ms)
     r->host_topo.maxcpus =3D vmsr_get_maxcpus();
     if (r->host_topo.maxcpus =3D=3D 0) {
         error_report("host max cpus =3D 0");
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     /* Max number of packages on the host */
     r->host_topo.maxpkgs =3D vmsr_get_max_physical_package(r->host_topo.ma=
xcpus);
     if (r->host_topo.maxpkgs =3D=3D 0) {
         error_report("host max pkgs =3D 0");
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     /* Allocate memory for each package on the host */
@@ -2995,8 +2990,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma=
chineState *ms)
     for (int i =3D 0; i < r->host_topo.maxpkgs; i++) {
         if (r->host_topo.pkg_cpu_count[i] =3D=3D 0) {
             error_report("cpu per packages =3D 0 on package_%d", i);
-            ret =3D 1;
-            goto out;
+            return -1;
         }
     }
=20
@@ -3013,8 +3007,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, Ma=
chineState *ms)
=20
     if (s->msr_energy.sioc =3D=3D NULL) {
         error_report("vmsr socket opening failed");
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     /* Those MSR values should not change */
@@ -3026,15 +3019,13 @@ static int kvm_msr_energy_thread_init(KVMState *s, =
MachineState *ms)
                                     s->msr_energy.sioc);
     if (r->msr_unit =3D=3D 0 || r->msr_limit =3D=3D 0 || r->msr_info =3D=
=3D 0) {
         error_report("can't read any virtual msr");
-        ret =3D 1;
-        goto out;
+        return -1;
     }
=20
     qemu_thread_create(&r->msr_thr, "kvm-msr",
                        kvm_msr_energy_thread,
                        s, QEMU_THREAD_JOINABLE);
-out:
-    return ret;
+    return 0;
 }
=20
 int kvm_arch_get_default_type(MachineState *ms)
@@ -3342,7 +3333,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
=20
         if (s->msr_energy.enable =3D=3D true) {
             kvm_vm_enable_energy_msrs(s);
-            if (kvm_msr_energy_thread_init(s, ms)) {
+
+            ret =3D kvm_msr_energy_thread_init(s, ms);
+            if (ret < 0) {
                 error_report("kvm : error RAPL feature requirement not met=
");
                 exit(1);
             }
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534965; cv=none;
	d=zohomail.com; s=zohoarc;
	b=e6Uc35nWnr1RQbEXe8Z80j6C3TdgSRr0i3u5Ijpq07J17Oatj97XF2eLJavDkJEPwsPSmUpCXjpvAs1mPZbc5RhlYwl9CF18+XPe3XuDLWuO792OJTRa1OILP+0l8bl7w1WRPHj3/Hh4uZyYqIo3yqlFz3VpO9X3a5Z0fvQRTco=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534965;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=u/jSh3phCjmXrmFZbNzmUVTDDUThSgA5sAsWR34V2mc=;
	b=LL8vvNbp1l33xhKpPzICM/vEcyOSgR3NVKy3On6622pjpi0H1jN51z4NHfC5xi6RiPO9Gth5KhCwrKPBCVO05eRstbw6Qmp72cmtghY2GDB9mNWchSVbB65+XmPkNyzTDY5F/vUHVPliJ8iI+CUIcd74BWvf/Twx8CzFHlr2QDg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173653496527034.41240863732787;
 Fri, 10 Jan 2025 10:49:25 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK49-0002rB-EC; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2d-0000PU-2A
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2a-0001CI-L3
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:30 -0500
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-509-WU6jeKFLPOuGBUeTUMlDLw-1; Fri, 10 Jan 2025 13:47:26 -0500
Received: by mail-ed1-f69.google.com with SMTP id
 4fb4d7f45d1cf-5d3fe991854so2899197a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:26 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99046a17fsm1919522a12.62.2025.01.10.10.47.22
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:22 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534847;
 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=u/jSh3phCjmXrmFZbNzmUVTDDUThSgA5sAsWR34V2mc=;
 b=fua/zNkyp9iOeYlThrzYkbV2bTGHfQrA3fxVi/WfmBIX3yXmchYpRKyvW0AAlJNqOJZX80
 Mnhu33HSAw9iW6LXbMUzDWL7cDi/2L+pxIkvmW1202vFfpUX5drpcdfE1FrCJMovd4XLCt
 usnNyRd0Ii74hCMkXU9odnA0rVqxomw=
X-MC-Unique: WU6jeKFLPOuGBUeTUMlDLw-1
X-Mimecast-MFC-AGG-ID: WU6jeKFLPOuGBUeTUMlDLw
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534844; x=1737139644;
 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=u/jSh3phCjmXrmFZbNzmUVTDDUThSgA5sAsWR34V2mc=;
 b=hr1bnFONqmYCT7lKrIW9jfupKz7mXKB4T7A3SFDeuiilcmBInccvjepPCeWutTvfTH
 3m5/siE93qnBd5GM6c/NtD+h3pXLx1dG85jc8OU87aN24hCszdM4vZoCpR25FgXypwFN
 nGwTwgNBfd5lwwVx3HVqGm2+2jaU6I9q30hydLJxNemfdrlGwjDKpMI610yjyHgKDsV/
 2UGB4h3n1NCfpRKUuumca1PKMSrf3BjLWWiD4UjDvXVNEZcn2V6+MVDwCFey60+KfD7b
 f3bzWO9SUlYRfUjvSjRcHctpRrLVnu2ZpXcB0LRWRmC52fpDkgBSvI+NO5nPVplMZqyi
 GOJQ==
X-Gm-Message-State: AOJu0YzEaUZCyN/fEl4rsO3mS/Q7pwvbQ+x2/rQKFJVtIw2InwffhQbA
 UqZ9P/RnVn39GrNXkNsL5GhuWRk9ysan3Yf4/kG119ve/8CvYdYxAJGjZg1DkSpsHRUhwRFIi2j
 cAu33Dpc6nT9Hd3hLuUJL4LO9erEQLGyCeYlXGAj8iYqLhyZfDNDgO6gfY+L01v/634J5NAeaGN
 asVzc5eI9liI3N2KC1HUSiY3gx7hn7vcbctcT2u50=
X-Gm-Gg: ASbGncvajycP4qAz7y4biwaowztwQnuxozobCSF6HVpz6jI88MnLtda9xGGsCWjpFg7
 7XDsinHkFtIA+dAhoioQrzeLANBN2I+z3R7zlAsK7FGDsMYRPNlDdBQ4PdvxVAnzukZGpPVjf3/
 tujmi//RZsz6clAxPYoSFsPi+JXJOmlQ13wiSQ56avtgcDejzD/TJTq3M/FQMb771gn0T4rzyrE
 Nx3fw0Eco/+Ox2PLa95yD4Bic7EgpnujBUVIviHFAiaY8CcTOGZVO0fDC8=
X-Received: by 2002:a05:6402:27cd:b0:5d9:a55:8104 with SMTP id
 4fb4d7f45d1cf-5d972e4cb87mr9775250a12.21.1736534844393;
 Fri, 10 Jan 2025 10:47:24 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IE5AWBFycH3ZDFwFvcgt0PbW2JGhLn4J43JPcA3/Zjz9FOKUBh+wWU4/ykqP6ahu/b3Ku3UIg==
X-Received: by 2002:a05:6402:27cd:b0:5d9:a55:8104 with SMTP id
 4fb4d7f45d1cf-5d972e4cb87mr9775239a12.21.1736534843887;
 Fri, 10 Jan 2025 10:47:23 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PULL 27/38] target/i386/kvm: Clean up error handling in
 kvm_arch_init()
Date: Fri, 10 Jan 2025 19:46:08 +0100
Message-ID: <20250110184620.408302-28-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534967087019000
Content-Type: text/plain; charset="utf-8"

From: Zhao Liu <zhao1.liu@intel.com>

Currently, there're following incorrect error handling cases in
kvm_arch_init():
* Missed to handle failure of kvm_get_supported_feature_msrs().
* Missed to return when kvm_vm_enable_disable_exits() fails.
* MSR filter related cases called exit() directly instead of returning
  to kvm_init(). (The caller of kvm_arch_init() - kvm_init() - needs to
  know if kvm_arch_init() fails in order to perform cleanup).

Fix the above cases.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://lore.kernel.org/r/20241106030728.553238-11-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 3624abbb397..6f424774b33 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -3162,7 +3162,7 @@ static int kvm_vm_enable_userspace_msr(KVMState *s)
     return 0;
 }
=20
-static void kvm_vm_enable_energy_msrs(KVMState *s)
+static int kvm_vm_enable_energy_msrs(KVMState *s)
 {
     int ret;
=20
@@ -3172,7 +3172,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
         if (ret < 0) {
             error_report("Could not install MSR_RAPL_POWER_UNIT handler: %=
s",
                          strerror(-ret));
-            exit(1);
+            return ret;
         }
=20
         ret =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT,
@@ -3180,7 +3180,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
         if (ret < 0) {
             error_report("Could not install MSR_PKG_POWER_LIMIT handler: %=
s",
                          strerror(-ret));
-            exit(1);
+            return ret;
         }
=20
         ret =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO,
@@ -3188,17 +3188,17 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
         if (ret < 0) {
             error_report("Could not install MSR_PKG_POWER_INFO handler: %s=
",
                          strerror(-ret));
-            exit(1);
+            return ret;
         }
         ret =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS,
                              kvm_rdmsr_pkg_energy_status, NULL);
         if (ret < 0) {
             error_report("Could not install MSR_PKG_ENERGY_STATUS handler:=
 %s",
                          strerror(-ret));
-            exit(1);
+            return ret;
         }
     }
-    return;
+    return 0;
 }
=20
 int kvm_arch_init(MachineState *ms, KVMState *s)
@@ -3265,7 +3265,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
         return ret;
     }
=20
-    kvm_get_supported_feature_msrs(s);
+    ret =3D kvm_get_supported_feature_msrs(s);
+    if (ret < 0) {
+        return ret;
+    }
=20
     uname(&utsname);
     lm_capable_kernel =3D strcmp(utsname.machine, "x86_64") =3D=3D 0;
@@ -3301,6 +3304,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
         if (ret < 0) {
             error_report("kvm: guest stopping CPU not supported: %s",
                          strerror(-ret));
+            return ret;
         }
     }
=20
@@ -3332,12 +3336,15 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
         }
=20
         if (s->msr_energy.enable =3D=3D true) {
-            kvm_vm_enable_energy_msrs(s);
+            ret =3D kvm_vm_enable_energy_msrs(s);
+            if (ret < 0) {
+                return ret;
+            }
=20
             ret =3D kvm_msr_energy_thread_init(s, ms);
             if (ret < 0) {
                 error_report("kvm : error RAPL feature requirement not met=
");
-                exit(1);
+                return ret;
             }
         }
     }
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535136; cv=none;
	d=zohomail.com; s=zohoarc;
	b=Dt0jAXeUVo2AUciz2arLDhaLv4Fc9Cn2/WajR+kaohz1sCBccpHtP91Julizy/m3PWylMQWDLDgBXrb9SkubeauRDXq0TVmXJoizYKt61YwAdflCmeF3TLXsDVdFJc4d5qWI771ZHLW+PVKBUyAPjYcKlpk8CYeh8FMFIy7v82M=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535136;
 h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=e/SgEHIcRdBYgVQTtKD0/BCAD1nVvQXOmSgaoZuaiys=;
	b=Gq+oH+Kjec+fqf/ib2Lhv4uf+k6BO5rU7LkAgdA6O7GJgOnvFNV24O7T79mRuFUau+oGUDYRQUDePhZsVzLvgiuWemtZmp8nNJTfMXo3sNY2QWmuVvpmxBu5WnpKDOT6vA2GaBaX7kUlIQbIvtF6dWeVjZcKiGIJOGpiOvLzm1Q=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535136192590.2480185258943;
 Fri, 10 Jan 2025 10:52:16 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK3G-0002Bi-0D; Fri, 10 Jan 2025 13:48:10 -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 <pbonzini@redhat.com>)
 id 1tWK2h-0000QW-Hu
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:37 -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 <pbonzini@redhat.com>)
 id 1tWK2f-0001Cm-OJ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:35 -0500
Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com
 [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-84-BaeizroDMzWZMDR9xpe9DQ-1; Fri, 10 Jan 2025 13:47:29 -0500
Received: by mail-ed1-f71.google.com with SMTP id
 4fb4d7f45d1cf-5d88d37abd0so2353299a12.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:29 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9904a55f9sm1845875a12.81.2025.01.10.10.47.24
 for <qemu-devel@nongnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534851;
 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=e/SgEHIcRdBYgVQTtKD0/BCAD1nVvQXOmSgaoZuaiys=;
 b=AKx8CcEB0N0MbMszofn4Qi0UdspMlhLcklgZCyIz7qL5yokTX0gRwTrZSA6iK1F1DUq4xg
 HqMaRILnB8eeVzxRnB4SuzaGSs5Bi+qCM2h+SqOOjMookHFmIdyP5ZgGOd22QAlK9RQHm5
 XFMo42OL8boALXGrhbBH4LgcreKKXR8=
X-MC-Unique: BaeizroDMzWZMDR9xpe9DQ-1
X-Mimecast-MFC-AGG-ID: BaeizroDMzWZMDR9xpe9DQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534848; x=1737139648;
 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=e/SgEHIcRdBYgVQTtKD0/BCAD1nVvQXOmSgaoZuaiys=;
 b=hPRRRP0gpRYT2L1JHpOyZ0DEgFinlqQ1cmhP4IgL/z3qxOcVDzpRFgqbtS7f8Z6sS3
 ZuCRhrrMYRoYS65+ssORk4pnwAeMvXgSwLr3cimg/oKwBpEsdwoCiQkUoZBZcMd+/dxK
 PsQ0spJCQ8bRIztBd0p5l3XUXtZ0SyVwVivPEb0u2wfWeGU0vsUcefIN1aia+6oIcPXz
 HkGZyFpx5+J11lfsfNvcJ4ENut0Z08SoVPypNzYikGwIB9PAL1JnTtE2KmrnGIJy1xBO
 J5N12Vn0FJnBNPkUlcFHetscIKXTAysL6vZv6Z2hRnWRtIAFSJU8RQTp9qrGRo2YCFR7
 65KQ==
X-Gm-Message-State: AOJu0YwMeDDLf8gK+kamCYyN/D0X8soBE7AoKscJONdNxPhGFWhZGOtz
 JMAh7B9qaMilita/0lXQSI9v1bx16imBATFGg4CMnhP5SsT+9HZ7oMGfxLmYfLFx7gMViL3tWo8
 qRyHxnSUaEnyL1pyFYHqsvIAtdMDAyexCzESpoad2IIOdoEcOCOKTSwlma13uiZyRtN/AiFma+f
 GRvXI8m+DmfzPjJTL/g/EpRSdQVybb/7Ky+7BJo9Y=
X-Gm-Gg: ASbGncs+Jv5jBQb6aGT5HaL9MbbkTuEb51+Y/Nhy4JSsIzeqhQddF0ltTak40Ob2y75
 J0YvAa/IlQDSTwx6Nuix7fuZZp3YCBQhn1twH4z8RfFe5mhs0R/8LeXBfMf1zx9msIh63QBB2j8
 y+hbDpAlWgjQASX0P/JSBzuRtwUgEWGac6GM4rNUEtfOlIIZ5GETP1Vjd3CgtV0EW7x95pI1CCh
 +BTVvAb0Ei/SS9Cw3b9uu8f63zYO9QVCh+OFvF7l8f/ZZHEaYeWkEHLyCo=
X-Received: by 2002:a05:6402:270d:b0:5d3:d4cf:fea0 with SMTP id
 4fb4d7f45d1cf-5d972e4c62emr9671029a12.21.1736534847684;
 Fri, 10 Jan 2025 10:47:27 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IHIwj9LGgzLXpOlyrrP/5XeuHgE/B/qaqZwaKSFqT8+BbtGDlrD+yBRMx0lARlI0LjGgsEsWA==
X-Received: by 2002:a05:6402:270d:b0:5d3:d4cf:fea0 with SMTP id
 4fb4d7f45d1cf-5d972e4c62emr9671019a12.21.1736534847210;
 Fri, 10 Jan 2025 10:47:27 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 28/38] target/i386/kvm: Replace ARRAY_SIZE(msr_handlers) with
 KVM_MSR_FILTER_MAX_RANGES
Date: Fri, 10 Jan 2025 19:46:09 +0100
Message-ID: <20250110184620.408302-29-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535138285116600
Content-Type: text/plain; charset="utf-8"

kvm_install_msr_filters() uses KVM_MSR_FILTER_MAX_RANGES as the bound
when traversing msr_handlers[], while other places still compute the
size by ARRAY_SIZE(msr_handlers).

In fact, msr_handlers[] is an array with the fixed size
KVM_MSR_FILTER_MAX_RANGES, and this has to be true because
kvm_install_msr_filters copies from one array to the other.
For code consistency, assert that they match and use
ARRAY_SIZE(msr_handlers) everywehere.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm/kvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 6f424774b33..1d7214b6a65 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5854,7 +5854,8 @@ static int kvm_install_msr_filters(KVMState *s)
     };
     int i, j =3D 0;
=20
-    for (i =3D 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) {
+    QEMU_BUILD_BUG_ON(ARRAY_SIZE(msr_handlers) !=3D ARRAY_SIZE(filter.rang=
es));
+    for (i =3D 0; i < ARRAY_SIZE(msr_handlers); i++) {
         KVMMSRHandlers *handler =3D &msr_handlers[i];
         if (handler->msr) {
             struct kvm_msr_filter_range *range =3D &filter.ranges[j++];
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535217; cv=none;
	d=zohomail.com; s=zohoarc;
	b=j5xR2D7OuLBdy+rmDH8xRICqOYVPMoAVm1xhxxl16l8vY6nUOAeng+dSQ2KxDPccHHl0lPQqkv3zgKNEgiYXpo38/OAS80UDM0nJE2EJFHKh067P2L9oLbrf/aqUiO8NXJOsn/1tBCL8CcPRgCaLyxQGv5UaSi4KqhedzFu98TY=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535217;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=2yAqjTt2W/272b7bDml1UKHxI7+gCBOSOR6mlAaYf50=;
	b=LYtjfhQ44uNf5lDg9jnrVI9pIUUw0rcMyGSkW+bnE4K3OjcCqWr1j2SbAmGX9cZrqJvh9z9TfCPqAWXZM0bSiri1gdRVcqApOZPM9V8CzIdWtx4faLED992JXrD9bk9wGIwXYg9GjvN0kmVn0ZX/wbbY3QOp5Lba6JgJjbx7FB0=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535217763956.2092399422642;
 Fri, 10 Jan 2025 10:53:37 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4a-0004yV-4U; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2j-0000RT-G3
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:37 -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 <pbonzini@redhat.com>)
 id 1tWK2g-0001Cu-AJ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:36 -0500
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-408-iFtRjx6lNl-iFgIK_48ERQ-1; Fri, 10 Jan 2025 13:47:32 -0500
Received: by mail-ej1-f70.google.com with SMTP id
 a640c23a62f3a-aa691c09772so216185366b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:32 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c9060badsm193246066b.29.2025.01.10.10.47.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:28 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534853;
 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=2yAqjTt2W/272b7bDml1UKHxI7+gCBOSOR6mlAaYf50=;
 b=a4+hJs2TcVMdJiUIr3p1erFyn/MWtVBv8oMjJ8p2FHH9KJCxWsPCL3KoHNlZpf0e21bIaL
 pkAOsGOa28+vNHhYuVrJVTXhyrQ7MeTSbLt0ksBYduk2RjCk2YcMkgXwed2BU8EPmwJzOS
 eDM2lDEITFxi1U5GwznaxGmC0O3bOW0=
X-MC-Unique: iFtRjx6lNl-iFgIK_48ERQ-1
X-Mimecast-MFC-AGG-ID: iFtRjx6lNl-iFgIK_48ERQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534850; x=1737139650;
 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=2yAqjTt2W/272b7bDml1UKHxI7+gCBOSOR6mlAaYf50=;
 b=Kzfsk/TInSwtqM12GUPveC6qC8vOfGqH0vJnXuCHst6xDuOvBoqrL29QtWMQDF2heH
 sKz6oFEvV2CT7MTFgwIaNG44fU2UT7WOD7QIunrcPYevJuo+ekV5z5IdXp6Jvppu95Bo
 XGn8UwBrZaW37iaL6oRa/w/HpL5s8+7/QWhtWd2LKpkWVO1c+9ngMBMeQ9ZzqCF2VRv7
 nnY4pg/oXqaZI91xGVBc7DrkLPW6QdzI9YZ5DfvFVc8bn4aaxreTjKT7hb/jt6xlwDPj
 Ce2/4ZGbpH77fN4Kj4Bi0JqqjlETH4AriF1hxK8G97v1ht0TtZupuXnciAkXJMNvsxGb
 HJsQ==
X-Gm-Message-State: AOJu0YyZBOSRmAXO/74PdKuJi77PLaprJAxRpg0+AO+maF88qflZ9eSZ
 dSg+dxjg1grKjQmOEhSTWQc5JtLdxdERDRUIjrsnENxPOrza9y6lWtIt2gPtDE3TjhruWJdlYTV
 R0i1KU6GV2nCUkkMYRn09HndYJ6+WaY3zYzq1uet1uBuvLpphGgH5AgKpIywnzAKskxBdmGYMm0
 vW1F5fMGk2WVV/aUv1RasXcUBw6YtQ2uLYip0fOE8=
X-Gm-Gg: ASbGncuLFyi8sxhTwbyBglA1lGIht6oWDGxhccfD5ozEhnlWQyFvT5tMeBjCyp6NNg0
 vjLyUXSdg4b0/uQxPqGZhpru4FAvJrLOadSgrf2Ry56ryjWRVwOcDprdJELk2dMUV9EroqPDKoz
 EVIZvHqa2nuND2LAbTYb5W5lJ2jN/uah+jS9pUDuRu2dWqVOGmpOOASHJxu0klAe4mEMFFwQvMl
 +xsevhKRk1bktEvByWCFTVhUNcQxBQ4Vd01NF2MIldFfmgDsGacw2MOLdA=
X-Received: by 2002:a17:906:c106:b0:aa5:b1b9:5d6a with SMTP id
 a640c23a62f3a-ab2abc91217mr1012730266b.54.1736534849695;
 Fri, 10 Jan 2025 10:47:29 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IE2HeeieMfsxgWtHVTCcYPf4OIH1KPZaVR31h1wJvzTFkdegDKEtvoRei+tPTeEFoeQOBjHgg==
X-Received: by 2002:a17:906:c106:b0:aa5:b1b9:5d6a with SMTP id
 a640c23a62f3a-ab2abc91217mr1012728766b.54.1736534849271;
 Fri, 10 Jan 2025 10:47:29 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 29/38] i386/cpu: Extract a common fucntion to setup value of
 MSR_CORE_THREAD_COUNT
Date: Fri, 10 Jan 2025 19:46:10 +0100
Message-ID: <20250110184620.408302-30-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535220199019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

There are duplicated code to setup the value of MSR_CORE_THREAD_COUNT.
Extract a common function for it.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-2-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.h                    |  2 ++
 target/i386/cpu-system.c             | 11 +++++++++++
 target/i386/hvf/x86_emu.c            |  3 +--
 target/i386/kvm/kvm.c                |  5 +----
 target/i386/tcg/system/misc_helper.c |  3 +--
 5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index f41462d8c19..e8c46d877e0 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2413,6 +2413,8 @@ static inline void cpu_x86_load_seg_cache_sipi(X86CPU=
 *cpu,
     cs->halted =3D 0;
 }
=20
+uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu);
+
 int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
                             target_ulong *base, unsigned int *limit,
                             unsigned int *flags);
diff --git a/target/i386/cpu-system.c b/target/i386/cpu-system.c
index 9d007afdab5..eb38cca68ff 100644
--- a/target/i386/cpu-system.c
+++ b/target/i386/cpu-system.c
@@ -309,3 +309,14 @@ void x86_cpu_get_crash_info_qom(Object *obj, Visitor *=
v,
                                      errp);
     qapi_free_GuestPanicInformation(panic_info);
 }
+
+uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu)
+{
+    CPUState *cs =3D CPU(cpu);
+    uint64_t val;
+
+    val =3D cs->nr_threads * cs->nr_cores;  /* thread count, bits 15..0 */
+    val |=3D ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
+
+    return val;
+}
diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c
index 015f760acb3..69c61c9c073 100644
--- a/target/i386/hvf/x86_emu.c
+++ b/target/i386/hvf/x86_emu.c
@@ -765,8 +765,7 @@ void simulate_rdmsr(CPUX86State *env)
         val =3D env->mtrr_deftype;
         break;
     case MSR_CORE_THREAD_COUNT:
-        val =3D cs->nr_threads * cs->nr_cores;  /* thread count, bits 15..=
0 */
-        val |=3D ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..1=
6 */
+        val =3D cpu_x86_get_msr_core_thread_count(cpu);
         break;
     default:
         /* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 1d7214b6a65..6c749d4ee81 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2614,10 +2614,7 @@ static bool kvm_rdmsr_core_thread_count(X86CPU *cpu,
                                         uint32_t msr,
                                         uint64_t *val)
 {
-    CPUState *cs =3D CPU(cpu);
-
-    *val =3D cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
-    *val |=3D ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
+    *val =3D cpu_x86_get_msr_core_thread_count(cpu);
=20
     return true;
 }
diff --git a/target/i386/tcg/system/misc_helper.c b/target/i386/tcg/system/=
misc_helper.c
index ffed8a3215e..c9c4d42f844 100644
--- a/target/i386/tcg/system/misc_helper.c
+++ b/target/i386/tcg/system/misc_helper.c
@@ -468,8 +468,7 @@ void helper_rdmsr(CPUX86State *env)
         val =3D x86_cpu->ucode_rev;
         break;
     case MSR_CORE_THREAD_COUNT: {
-        CPUState *cs =3D CPU(x86_cpu);
-        val =3D (cs->nr_threads * cs->nr_cores) | (cs->nr_cores << 16);
+        val =3D cpu_x86_get_msr_core_thread_count(x86_cpu);
         break;
     }
     case MSR_APIC_START ... MSR_APIC_END: {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736534984; cv=none;
	d=zohomail.com; s=zohoarc;
	b=h4m7P0wf504M/hzyHIUkuvpoG62lSekLuz44xLRbMHmBli0a54Kwsmt8PbOxdhR9Is1zAVRVaMqfPTS3Xc6amU+DcKzt7m4rjubtux2Q3YkD905RNYqXg+yT1JeBAVnhLWbNEogaTweOnooLslaEgAzSMfLcya5j4noeUNyolPY=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736534984;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=fJMQwMv56LSiqWYeYKdbo7EuNXacm0XCkWqmd0PHSvI=;
	b=WzCAPXe0OzidDCF+UGD70ZGkxF756s9sHHg8keSMBTCdPPnNK8UfrJdL1mgBdj3smTmMd+74GOTGXFv3T29nE6nEZTt2KXO6cSmmJ8IKRqQtT8eYWxCFuMcBwL2nlSSZD9Q1JivOLDl5ypqvqyoS32oKMFHbUpDrluQnBVzYClg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736534984040784.2627148709295;
 Fri, 10 Jan 2025 10:49:44 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4E-0003TT-Uz; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2m-0000Vb-JK
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2j-0001DD-Ht
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:40 -0500
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-647-QTEA5NPfNMWMyyCLvhuScQ-1; Fri, 10 Jan 2025 13:47:35 -0500
Received: by mail-ej1-f72.google.com with SMTP id
 a640c23a62f3a-aaf921b8a85so217744566b.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:35 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99046dbe0sm1833189a12.64.2025.01.10.10.47.30
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:30 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534856;
 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=fJMQwMv56LSiqWYeYKdbo7EuNXacm0XCkWqmd0PHSvI=;
 b=XFTrrVPqvdiwwhjwfpGMJ+4y0gN/V2HAR4LP+5erKYL/XddAI8y/YobCewmNXLMxrYlCRX
 /QJHjXIkQJ0wVlVHt8XUCBGXxXuumsEfnULbiTuPJetPCVi4W8aS0tQ8ZxHq344IcdTunM
 LPLTyPWGNErlCpSgM+cRB9pvPr7pe08=
X-MC-Unique: QTEA5NPfNMWMyyCLvhuScQ-1
X-Mimecast-MFC-AGG-ID: QTEA5NPfNMWMyyCLvhuScQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534853; x=1737139653;
 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=fJMQwMv56LSiqWYeYKdbo7EuNXacm0XCkWqmd0PHSvI=;
 b=prLZ7hj95Ff3o8Wn8rJJon8ncA0GebFwTyIJFYtllD4BRRtelL8Vs9WMg9sVMl8IRg
 1klYNe7JqHsQSo4gXHtVTVw/WcG+vwWTX0emd95Y56OAXHSUG66hxPUylt1pmBMO36nj
 38b37f6f4qJpYuXHJf/t8e+aLzd+Vj4QPmE8feiYPs2gIQFpdGpw1ciY9ayExmPUWWvY
 8JisV7OWn7KT4iCZA8fdx0owbM2lYrNZa+tGbchvlbDca2oNxEN7DIta1xj1Hg/g7p92
 M1puxTQHQ5RKtcUgThpA9qld/jQWPlBBxzfjdy2uE5hCk15q0vVKu4KG/0WKYxq+dVkx
 EmhA==
X-Gm-Message-State: AOJu0Yytq7EfbNIf/29Ax6F4PL9gmZGQBf6MG7hDY+9H8GxY40V+fjtC
 TL32pEPqDVFJUQFJONlsDgyN/xx6VjmfMR8xA/bDF1kE2xTe7u0qeSe/N+tg0dNR/r4RoFqS1a+
 cgzGMMZ2P56Dl15gmM2vEm5T6nSBp6PMCUXfOtA5mhT/qzjv6GaYynAgWvPqRzoDI/GuQugYMxY
 bcPwyLPUxTkxqUKnFaHF8eYoykqG9NKGcdvFGC+pE=
X-Gm-Gg: ASbGncv2pBrGjflmJHuUYTbGP6TncbDXOK3O152kbr6yO9brKzP64ouYq/GOnI4gv3w
 oXDDbilBMtoKwzUe0wKaHyblSN2igmlOeETvNOJ8u6USvkC0R+FCGRNz9ft0vW+1kPa0yst7eUz
 //XaUVL4gRTc28hX/3ilmDcOVeAMAiTEf9nBrJf31PCtbtq8hbNzj8F2A/xUNsjUQ2mxlIpvbGz
 7iSdIu8kT+6BbsXXler/OddS7MKc2YOfNMibSsM0dUJiyWlRzB1XVOnX3o=
X-Received: by 2002:a17:907:9491:b0:aa6:b5d8:d5c2 with SMTP id
 a640c23a62f3a-ab2abca7737mr1222597066b.41.1736534853482;
 Fri, 10 Jan 2025 10:47:33 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGoyJ4mD42/O45kHGvZGOebOQ4srHmzT+UlkzwzYenVGgRxWeCiaXIj2Kpx+yqfBOJ5N3shAA==
X-Received: by 2002:a17:907:9491:b0:aa6:b5d8:d5c2 with SMTP id
 a640c23a62f3a-ab2abca7737mr1222594866b.41.1736534853110;
 Fri, 10 Jan 2025 10:47:33 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 30/38] i386/cpu: Drop the variable smp_cores and smp_threads in
 x86_cpu_pre_plug()
Date: Fri, 10 Jan 2025 19:46:11 +0100
Message-ID: <20250110184620.408302-31-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736534985014019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

No need to define smp_cores and smp_threads, just using ms->smp.cores
and ms->smp.threads is straightforward. It's also consistent with other
checks of socket/die/module.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-3-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/i386/x86-common.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index a7d46c31059..5b0629f9ad3 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -248,8 +248,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
     CPUX86State *env =3D &cpu->env;
     MachineState *ms =3D MACHINE(hotplug_dev);
     X86MachineState *x86ms =3D X86_MACHINE(hotplug_dev);
-    unsigned int smp_cores =3D ms->smp.cores;
-    unsigned int smp_threads =3D ms->smp.threads;
     X86CPUTopoInfo topo_info;
=20
     if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
@@ -329,17 +327,17 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
         if (cpu->core_id < 0) {
             error_setg(errp, "CPU core-id is not set");
             return;
-        } else if (cpu->core_id > (smp_cores - 1)) {
+        } else if (cpu->core_id > (ms->smp.cores - 1)) {
             error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%=
u",
-                       cpu->core_id, smp_cores - 1);
+                       cpu->core_id, ms->smp.cores - 1);
             return;
         }
         if (cpu->thread_id < 0) {
             error_setg(errp, "CPU thread-id is not set");
             return;
-        } else if (cpu->thread_id > (smp_threads - 1)) {
+        } else if (cpu->thread_id > (ms->smp.threads - 1)) {
             error_setg(errp, "Invalid CPU thread-id: %u must be in range 0=
:%u",
-                       cpu->thread_id, smp_threads - 1);
+                       cpu->thread_id, ms->smp.threads - 1);
             return;
         }
=20
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535227; cv=none;
	d=zohomail.com; s=zohoarc;
	b=c4+Ek3+d5ZPGW1uMsIFd8WvgMAcCQjcmxIOEVvay3kqgPeOCg/JQf3gqSzRe9Q2VfNoDZTA4kXD5VZQMMQNViYJlF7YfjOb1XBTo4k2SKgYFV7rPXufEbszvxzJtgpdoUuF9WEB6sbvEVEy05k8/ByETTVdkGTOI+M4HMFzplTI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535227;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=aaRigbghLhObFLWkYcE9jy7wD6yeALPcuEP9ikC2TVQ=;
	b=W/WpLmpGIDoFcFl5+v54XTzxjkLalGtTFO0DCCDoUE1It/2x9CPOOoOdKIZHxQi858+Cbc18/dgiX5X5LBm9NLdoDYIs3Sq6pe9B+J6X6+aSRgIi2mENmMRSRVqHwCI89WCZzC9OBR6LouelO+OT73mxgHNeQ3LTUgY8FVlvVTY=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535227767851.0778845741029;
 Fri, 10 Jan 2025 10:53:47 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4M-0003oQ-6m; Fri, 10 Jan 2025 13:49:18 -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 <pbonzini@redhat.com>)
 id 1tWK2p-0000ZD-Aw
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:47 -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 <pbonzini@redhat.com>)
 id 1tWK2n-0001Dd-BJ
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:42 -0500
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-222-0D773l_DPdqI3AexS2IpQQ-1; Fri, 10 Jan 2025 13:47:38 -0500
Received: by mail-ej1-f70.google.com with SMTP id
 a640c23a62f3a-aa6a7bea04cso162678066b.3
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:38 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c95b1ccasm193366566b.158.2025.01.10.10.47.33
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:34 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534860;
 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=aaRigbghLhObFLWkYcE9jy7wD6yeALPcuEP9ikC2TVQ=;
 b=Ir+C5l9rnfr4f8xTZBsIXjUw/ov5Ab219TMO3cZ0e0dLyB7DIy+S2zb3Mr0xPDn+QVpgnN
 l1ilS5RLBBdp3We8/5mCV2+Dj4eGBxVEnTbpmmITuIszX5yvbHPpqyW+wAFxiV4kWoxXFf
 qxCrcTacOF47N9hQvgyFG1FmzRHyW5E=
X-MC-Unique: 0D773l_DPdqI3AexS2IpQQ-1
X-Mimecast-MFC-AGG-ID: 0D773l_DPdqI3AexS2IpQQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534856; x=1737139656;
 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=aaRigbghLhObFLWkYcE9jy7wD6yeALPcuEP9ikC2TVQ=;
 b=e3DTyi4dTt3T17st8nlilD5SR3x4+x2960Nz0/KXywDsVhIfdEyIlh8rBsoXEaHmfO
 BskM/u9CqHi3hvcnSiajtqIJqXmS0t8YoLm4LW0VD++5iQg5lT+VtdTUdB9OduQ6dqWD
 Hq6Oc3J9fiKn1sloUiWNR8Wv//j1QRAW2okESZjgIsUF1sKTxQV5vopX2A4bMRAbiG8n
 vQmM4rYb98U1yiomi60RZ46pSuEuHeq49ppL426aKHcJlclUZU64HBNTpQZK23o297Jf
 ohXWLgj2MIqw6te31Qr4G2rugPSoaUDaKpkuWrrXCcPPznEMBn79XS1d8nIvUKBQMzwQ
 vcPA==
X-Gm-Message-State: AOJu0YzjRLkjlKfnibV4DkUL8hy3lEDqWGxWfNH9YeaTVq7wk9Zr0wvd
 V1ck4x/rLhIvkQuo6HY5PW29IgX4jjiMaaZCokdmr/QNX2Zf/ulZuIi97AJoFDZ+bPxzU/1t6ei
 vtaEEBiAz7yPnRaUglX9hzpa5FDGGkOA/YqnGT52JE7+mJ1E/HNbcmBUM+Eu01DhBCQr+04ntb4
 oLlaD9B4SHuzSPaA3fY4Z84PzFsJl3E9LPKfMw+RE=
X-Gm-Gg: ASbGncunJxBUT+fcgm5J64BedEA5ZsFqG4jLsz27TBw/tvIltvvWxBv1umtINWmzPhK
 RZAtgovb5+P7F7vXip/I2rwYly/1zNBUyStBtamMwSMQk3Z7ffpfsIUjW5yUoex//pOasuTMqxk
 noKbGCWN+uTmzXlFduS2x9YQVglTjCwCEUvEQos+4tLGuoKAiv81LnnbZpetoAMwket6m+3X3M/
 RNld4tXQbmxHTk/V0Aten15ZZD4tbG50h5q9kV3lifMODyiMRJpxHCy2cs=
X-Received: by 2002:a17:907:787:b0:aa6:af4b:7c87 with SMTP id
 a640c23a62f3a-ab2ab6c5072mr1015355866b.21.1736534856038;
 Fri, 10 Jan 2025 10:47:36 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IEjbRGvz/SJOrjdhXjBii7Z3nMPcidNi5AiVXh3hP/dZ/TSUPmZ7nug7sk3A7pZT5Ay6fZIrw==
X-Received: by 2002:a17:907:787:b0:aa6:af4b:7c87 with SMTP id
 a640c23a62f3a-ab2ab6c5072mr1015354166b.21.1736534855515;
 Fri, 10 Jan 2025 10:47:35 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 31/38] i386/cpu: Drop cores_per_pkg in cpu_x86_cpuid()
Date: Fri, 10 Jan 2025 19:46:12 +0100
Message-ID: <20250110184620.408302-32-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535227992019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

Local variable cores_per_pkg is only used to calculate threads_per_pkg.
No need for it. Drop it and open-code it instead.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-4-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 579d9bac955..6d9c85576f6 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6499,7 +6499,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
     uint32_t limit;
     uint32_t signature[3];
     X86CPUTopoInfo topo_info;
-    uint32_t cores_per_pkg;
     uint32_t threads_per_pkg;
=20
     topo_info.dies_per_pkg =3D env->nr_dies;
@@ -6507,9 +6506,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
     topo_info.cores_per_module =3D cs->nr_cores / env->nr_dies / env->nr_m=
odules;
     topo_info.threads_per_core =3D cs->nr_threads;
=20
-    cores_per_pkg =3D topo_info.cores_per_module * topo_info.modules_per_d=
ie *
-                    topo_info.dies_per_pkg;
-    threads_per_pkg =3D cores_per_pkg * topo_info.threads_per_core;
+    threads_per_pkg =3D topo_info.threads_per_core * topo_info.cores_per_m=
odule *
+                      topo_info.modules_per_die * topo_info.dies_per_pkg;
=20
     /* Calculate & apply limits for different index ranges */
     if (index >=3D 0xC0000000) {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535137; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ZTDJaEamYA3X+x3v+m8Ko4vFBqPfU4xp283ikVOn7isYekDJ44bDBd8rKZo/8ecwChfqwIryQQ0phzRu3TA2ZdvrbEIXXWd0x2HY7P8ylJWlypDrq7/hRFESx1CF7lTkszP+YP7UmibKM5wGribdPDmhXF91MOD50++DSzN8JcU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535137;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=InB+d98viNQRxuvtICKG8ck6jnh084gdrT4/wIgZzao=;
	b=SYEBj6VE/w2dRAesfW2KOZKwcuyeZb2zhwBsQspMNQGK1wWILsWJfqY4QEDMvon/KZtc51HtM5AAP7/1ajLPrN+WcrzuFnYPQLItUb26dgECXDe7Q/Jd/cWfiJwDPDwHltWRjs6NNdhdROR+TaMizG2nZAuMMyEv7ImzA3PX600=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535137235282.1136070421787;
 Fri, 10 Jan 2025 10:52:17 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK2y-000197-So; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2r-0000ZS-E5
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2p-0001Dn-3u
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:44 -0500
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-685-_XQtdgh1NcG1UI1IpoZB4Q-1; Fri, 10 Jan 2025 13:47:40 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-aabf8e856e2so249462866b.0
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:40 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d99008c366sm1937639a12.17.2025.01.10.10.47.36
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534862;
 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=InB+d98viNQRxuvtICKG8ck6jnh084gdrT4/wIgZzao=;
 b=XpcsOCQ9r0fUut2TIV7b+HTK4NwtN0fg2Zc1UIpAmRJbX41oTGDskO9jFsxBcHSza+nUh2
 5AFMzwL/sUk0FPEvuUSQNsTcie8/IxXS07silrnRPqDLOqgJmlF5/OwfxzaeVFRLWM0/cH
 IecYnIwaneCKHo5ToWYJcLedO0OpQ9g=
X-MC-Unique: _XQtdgh1NcG1UI1IpoZB4Q-1
X-Mimecast-MFC-AGG-ID: _XQtdgh1NcG1UI1IpoZB4Q
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534859; x=1737139659;
 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=InB+d98viNQRxuvtICKG8ck6jnh084gdrT4/wIgZzao=;
 b=sAuJWvJ5v3JypNpv0f8LikjzfkcjWk6vHubCJDfqwMa19CM6eHb7k00+WpSyz7qcZw
 hkGQktYcR0Vdm+SzQ0ADy7zk0IcnxDsFasP42RJ+3aB27zCZkcllv4HDLc1mrs7tMwJA
 pHGxNJ9ILtNYk3ltYWHwZB0qVuzt9DNI6xPltxfP9IqQGmV5c8mmh17FYsCtFus8tNdH
 A/H4RgU6NLpBHt99rxCchwVolsf5OGLfcxVd37GeIkMvyY3aUnLFP3XwigGD49feeHZu
 pATcJypseGKJEBF+1dAye1scel+7eWudgHph0Oil6bVOj65X+xBgv1r8ktPEHuS8exRR
 I9nw==
X-Gm-Message-State: AOJu0Yw8pree1wjvFKkaoJIgEsHE8d+EQVxZpA31/PsqSm5qHmZ5Xan+
 GveoYkq7l/Si/ExmLcas8PvcaVRoaPPvUhXw7s+wCLZNlPqhYEG21SViWhNAdQuj9g45AwtLQIL
 Be4ZNIJ5rgSZWXukb6gPHprEM+HJJGoCtEPSGpExxGLRDW/4bpw5Wjy0nghED9/u0y5aEPWlLIR
 T61VZ2/HbJsy1DQnjOuGCJpq7p9QTI5R9WllWf+z8=
X-Gm-Gg: ASbGncv5xU0cI3NLVOCOHgUhHSMJwj7/cVmJTlqL+D3tmPtZZEr6vqQVicL2T/9QIwU
 qEMdijCinCPKy/evf8tMJzfvNBnCH0hl/xaDOPXtRf/Qae2W769jxf3FmSYDGoiTt9DaDotbO5Q
 Fqx8nDMu78XD0P2Uki1vTE5FDTNBdEksnNsFhMg+RDlsUJWZv7tfFGUeUsZZY0BaM58avoNNt2c
 vKEswEKdmjeNXnGaXlwj0qoEe1JnZ6RxUMwJ7+vFk+7Uw6VUirclALZRgs=
X-Received: by 2002:a05:6402:400b:b0:5d0:e63e:21ca with SMTP id
 4fb4d7f45d1cf-5d972e1c0d3mr11387890a12.19.1736534858884;
 Fri, 10 Jan 2025 10:47:38 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IG7ym9xWJ3fuQQ9Y7UtIIw9DV1pHPm+O1GGbaXXBAacoVfbsIU03xjaY1IS5zV+X7psX/TmnQ==
X-Received: by 2002:a05:6402:400b:b0:5d0:e63e:21ca with SMTP id
 4fb4d7f45d1cf-5d972e1c0d3mr11387876a12.19.1736534858442;
 Fri, 10 Jan 2025 10:47:38 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 32/38] i386/topology: Update the comment of
 x86_apicid_from_topo_ids()
Date: Fri, 10 Jan 2025 19:46:13 +0100
Message-ID: <20250110184620.408302-33-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535138285116601
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

Update the comment of x86_apicid_from_topo_ids() to match the current
implementation,

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-5-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/hw/i386/topology.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index b2c8bf2de15..21b65219a5c 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -121,9 +121,10 @@ static inline unsigned apicid_pkg_offset(X86CPUTopoInf=
o *topo_info)
 }
=20
 /*
- * Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID
+ * Make APIC ID for the CPU based on topology and IDs of each topology lev=
el.
  *
- * The caller must make sure core_id < nr_cores and smt_id < nr_threads.
+ * The caller must make sure the ID of each level doesn't exceed the width=
 of
+ * the level.
  */
 static inline apic_id_t x86_apicid_from_topo_ids(X86CPUTopoInfo *topo_info,
                                                  const X86CPUTopoIDs *topo=
_ids)
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535259; cv=none;
	d=zohomail.com; s=zohoarc;
	b=hO0KpfdTVzfAhslMDZiDw9NCQa8wK3vZM3kjhkEG5fvPnOGkMepnfBgFozELzXyaO6+iQ0e/wMwQ2/tillP42SEAZ+QG3uOccee7XVxw+HdaAb25UHALUibeFSXbffwjERRE18trSa37Oz8YKZW07VQA9Vym3q/0ewt+GX3BDbU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535259;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=BIu31oS8+7nxNH6NjsiGP5t1yaCBDHTs3K4alVxgO68=;
	b=bx84izauJsoA83wcx1X7jWi3SwnGmMhF5zQ+R8ky1piOiD3A+e8BB7PW6vdaxDTyitmHlgJ1XU916k2tDg8bKomlw47EfX68Gb15rzCMbcxAE61iVg9ahx/n4s7Y+So4CtZDVbBxqOLPx/3FtdjQIG413E33J6U/9CWKcNLz8NQ=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535259098605.0205243363872;
 Fri, 10 Jan 2025 10:54:19 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK32-0001Sp-NE; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2t-0000h7-3y
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2r-0001E2-74
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:46 -0500
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-33-JByqUyVmP3mjQZWgOh294A-1; Fri, 10 Jan 2025 13:47:42 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-aa69e84128aso194055966b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:42 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c9562ea8sm194331766b.93.2025.01.10.10.47.39
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:39 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534864;
 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=BIu31oS8+7nxNH6NjsiGP5t1yaCBDHTs3K4alVxgO68=;
 b=Q9B+IIw0q9ugwH1Kl4QmAUmNJF+tNwdN2rAAW5k9J8mbKGpljmrxaK+gANkfO/T7bN/eTC
 iFsT0+za644vZqKON9QbtWsNAwKM/xZk05RqQQXryrfs+MsWxHke435ie08p5IRwfnVtfl
 +I+z0orJkEjYZVUtWB1NrTzjLtjpgQ4=
X-MC-Unique: JByqUyVmP3mjQZWgOh294A-1
X-Mimecast-MFC-AGG-ID: JByqUyVmP3mjQZWgOh294A
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534861; x=1737139661;
 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=BIu31oS8+7nxNH6NjsiGP5t1yaCBDHTs3K4alVxgO68=;
 b=hjAcwYt/ePwz5d7EQAoUT7sv+XI/DB5N2WCNfVAHDzgXUXN6tp25G0E6pmog7rz3RN
 MQ4e+o/tCSvYa9XbXTaXo8OyqT3wX2cnQeOR9Q7Ufrn6OvgpE72LvRfwaB2RqQDI0ofo
 w8cByjxPE+8AiKB9myvBB7nncBZDpmSIHuLnqsvR47FdAEHEkUMypXCK+IfXnQWveZr0
 hHZXO7sBW/nikh3iMUCH+uhj1raRMAvoBAfgLKRK1EqhonGlFe4eaR8YQTlGbEwgO4yD
 uYbifgXGA2ENMss8J7k3GnK2Tz531yI88Voou11g7hlSxMqsVISLNkXwAWW9qxDZ5IBW
 1fpA==
X-Gm-Message-State: AOJu0Yx2kb10DU18oluvEH1DX1Khj7tjXKGngBifxNg9QfjlqsW2gkoX
 NkZ5j9GXX8PTbwFFdYyJ7kX5L+q9lWbAHNzgs+dxkQ+xU479GmW7xYfRV1wFr4YK391HaI6qPeD
 uIBzFLbCCgyfEEKbK+9zsFCwNPhIZtrLUq8fbIqs5mzHU/zPo728wc4s0GpRaogsfZ20Dl1tmzz
 msSGxaIkCfMCPb1mD9czFVm/WWp3xzIF9VehEPJWY=
X-Gm-Gg: ASbGncsxlXzBV3CHFaFnET7I2/yOBPb3uJ4wkRVGUP7worfdTOmVtB3cgksQE7E4erz
 +y93t6tWqjr8k0Mw34ruUR4uWHl+0G5Qjo9mdpupD11u7ryIVRdKSBpYZGPYAPtkkmYi5BM0p67
 CK1l4gYhS/iRsImvfYBVrAL8k9vHoxQ/aFyV/Y6K0zcWz2kE+wMGq2JhBfjGBtAMYlRFgdO2H67
 oW99dzfq1TvYq076LVXfMqLkmMSb/wDGnwVOeRqG8b1faVrG/KiB5fyqik=
X-Received: by 2002:a17:907:d87:b0:aa6:80ed:e9a3 with SMTP id
 a640c23a62f3a-ab2ab70a87amr1250821766b.35.1736534861032;
 Fri, 10 Jan 2025 10:47:41 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGxCDexzyCKkD1qSpaJ7j5lqbnxMrj4YGUapHDkO+PUoAWfFzkKpnnQ1JlQK3U/LdJYnhdHyA==
X-Received: by 2002:a17:907:d87:b0:aa6:80ed:e9a3 with SMTP id
 a640c23a62f3a-ab2ab70a87amr1250819866b.35.1736534860551;
 Fri, 10 Jan 2025 10:47:40 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 33/38] i386/topology: Introduce helpers for various topology
 info of different level
Date: Fri, 10 Jan 2025 19:46:14 +0100
Message-ID: <20250110184620.408302-34-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535260210019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

Introduce various helpers for getting the topology info of different
semantics. Using the helper is more self-explanatory.

Besides, the semantic of the helper will stay unchanged even when new
topology is added in the future. At that time, updating the
implementation of the helper without affecting the callers.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-6-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/hw/i386/topology.h | 25 +++++++++++++++++++++++++
 target/i386/cpu.c          | 11 ++++-------
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index 21b65219a5c..f6380f1ed75 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -203,4 +203,29 @@ static inline bool x86_has_extended_topo(unsigned long=
 *topo_bitmap)
            test_bit(CPU_TOPOLOGY_LEVEL_DIE, topo_bitmap);
 }
=20
+static inline unsigned x86_module_per_pkg(X86CPUTopoInfo *topo_info)
+{
+    return topo_info->modules_per_die * topo_info->dies_per_pkg;
+}
+
+static inline unsigned x86_cores_per_pkg(X86CPUTopoInfo *topo_info)
+{
+    return topo_info->cores_per_module * x86_module_per_pkg(topo_info);
+}
+
+static inline unsigned x86_threads_per_pkg(X86CPUTopoInfo *topo_info)
+{
+    return topo_info->threads_per_core * x86_cores_per_pkg(topo_info);
+}
+
+static inline unsigned x86_threads_per_module(X86CPUTopoInfo *topo_info)
+{
+    return topo_info->threads_per_core * topo_info->cores_per_module;
+}
+
+static inline unsigned x86_threads_per_die(X86CPUTopoInfo *topo_info)
+{
+    return x86_threads_per_module(topo_info) * topo_info->modules_per_die;
+}
+
 #endif /* HW_I386_TOPOLOGY_H */
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6d9c85576f6..a58c719e90c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -312,13 +312,11 @@ static uint32_t num_threads_by_topo_level(X86CPUTopoI=
nfo *topo_info,
     case CPU_TOPOLOGY_LEVEL_CORE:
         return topo_info->threads_per_core;
     case CPU_TOPOLOGY_LEVEL_MODULE:
-        return topo_info->threads_per_core * topo_info->cores_per_module;
+        return x86_threads_per_module(topo_info);
     case CPU_TOPOLOGY_LEVEL_DIE:
-        return topo_info->threads_per_core * topo_info->cores_per_module *
-               topo_info->modules_per_die;
+        return x86_threads_per_die(topo_info);
     case CPU_TOPOLOGY_LEVEL_SOCKET:
-        return topo_info->threads_per_core * topo_info->cores_per_module *
-               topo_info->modules_per_die * topo_info->dies_per_pkg;
+        return x86_threads_per_pkg(topo_info);
     default:
         g_assert_not_reached();
     }
@@ -6506,8 +6504,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
     topo_info.cores_per_module =3D cs->nr_cores / env->nr_dies / env->nr_m=
odules;
     topo_info.threads_per_core =3D cs->nr_threads;
=20
-    threads_per_pkg =3D topo_info.threads_per_core * topo_info.cores_per_m=
odule *
-                      topo_info.modules_per_die * topo_info.dies_per_pkg;
+    threads_per_pkg =3D x86_threads_per_pkg(&topo_info);
=20
     /* Calculate & apply limits for different index ranges */
     if (index >=3D 0xC0000000) {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535230; cv=none;
	d=zohomail.com; s=zohoarc;
	b=YE9aiX8OPYS28Irz/GYrfY+cApEJ5AbaCz+TUd7ddocr7IlUpGeQx/FlyVJCI7i/u7pKYf9il4GG8xaB1uFLWGqLmWKGiVOzFn3BQulgcGSEuk+PjxpAx/g6zdh6XgQ9mUjgpphF2VIEKMjY92rAkixVxGhzsjgIX+eqS1LldFM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535230;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=T6QSpBB0Gnj+6e3q85vSXCFs8g+WJlM85mplVWUJQJk=;
	b=cC/uSGmNkHcVpgQjj+EXJIAimxx+81v1w6S78O3WrQ7CEpOU5RWy/Lh8TOqmc3IzZeKLl03Jt/sa0CrzBrzFM3MKDOkIwxgHuM+Vd6RyU1FLFMbB+izgx6PuCN3uaU318TDpMqCvPTESX5XNu4W+PDTQ9bLm4kvn0BbJPOd1bN8=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535230476376.5147249095153;
 Fri, 10 Jan 2025 10:53:50 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4m-0005a5-8t; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK2w-0000yU-LW
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2u-0001EQ-BF
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:50 -0500
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-317-NwG7qLR7OEOr42ukQpKWCg-1; Fri, 10 Jan 2025 13:47:46 -0500
Received: by mail-ed1-f70.google.com with SMTP id
 4fb4d7f45d1cf-5d3f4cbbbbcso2451147a12.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:46 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903c2d58sm1912386a12.39.2025.01.10.10.47.41
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:41 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534867;
 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=T6QSpBB0Gnj+6e3q85vSXCFs8g+WJlM85mplVWUJQJk=;
 b=B88DgoH+8FYpAqnJjnqRQU7NErwv1JvzpwwXZF9poZz3AWYXTxGn+2lmWNfXZv+0xudxgI
 2lizk3ykq9bnss/+zPfIYQ6RVplOYt9TRCrK5JM6/qVess3c6CjJPlcKN4ZfA1wThXez7o
 H2EvDqCCoK8offO28jsmw2NptBzGEOc=
X-MC-Unique: NwG7qLR7OEOr42ukQpKWCg-1
X-Mimecast-MFC-AGG-ID: NwG7qLR7OEOr42ukQpKWCg
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534864; x=1737139664;
 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=T6QSpBB0Gnj+6e3q85vSXCFs8g+WJlM85mplVWUJQJk=;
 b=Ep9jkCqngzu31kZJFiaTvdN8RbBV6MCKWSCMjN+WKntRxY7jfr3nsFWe23iuiCwPcz
 Ed2YkVqt5TavLo4n43gI/YnbJ9SdxjhAIYZPkBL90uwPG+Nw3yQtSlJD67eFnWWfQOAb
 jl95jpRHDdohjW3osPRSY863vF1AJE9KV1R5NdOlwM5i6KeHCse0aUH6Wuu30GpWziNr
 GZf1p+BJ6p8Y0KhrWXn3vzdq4eiV3ImnBLMDP3YPovkwz/84pC2uvcBHPCg7fG08eZjH
 Hm9q+7gn/hlgLL6tFzz1AnI60XwrnGCydGbJgQBMNxC8hg5F3oSf44cIvup4n3tFY9PD
 /L3g==
X-Gm-Message-State: AOJu0Yy/AcOxRfl2FAMTUE+aR03n648YoJT6AMW3OYiXFpizXuOR9KjT
 4g+5zV76z+F8bcIcMbHET6Zdu3ekLrndpr9Yfpb6XaRQKsx6IcH2UfenOJ2fdRA3AWfZn5L9k8D
 X6kyrCuH7ZG5KXzt1co853RoXm3bS9Jv1Jvcoxs1GacQSeh1oRl1bFdG+7L8SyCtRZvuip5gRkC
 WNFUelra5e4F+jYPNlVgjIEpW7eXYeDVSZAXxeXKs=
X-Gm-Gg: ASbGncscKiopJBOdpNSGeZmiH20F5zHhrCO6PzBOMliUEoZjfXRkNvJmX61nujAxt0/
 ro1gdK2yNkfZVywvczLlW5nNEKaqFYqXbdZrUJJK9b59tL7kFLjHVO7agO8S81eTVboMmIt35oX
 Hu2klAbQTU7eRJ77f6HyWAzvRVla1iT1S7Rkw+ojn2IS0kIn3xDCEelRhIeaiBWLUh5UMH0ESII
 PgBq0cxIkN1a1I/DhTa7LcP/uzDGRMDYx+M8KNCc9Tp5gJdmtpgL81eL1A=
X-Received: by 2002:a05:6402:3888:b0:5d1:2377:5ae2 with SMTP id
 4fb4d7f45d1cf-5d972dfb857mr10928611a12.7.1736534864387;
 Fri, 10 Jan 2025 10:47:44 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IH59bT2K+fXcTLzJEC5GaAJkmIOn2LgxaSF5XsO3TeGo8e62Cz92AB4QIzZk7XgaWvCKHichA==
X-Received: by 2002:a05:6402:3888:b0:5d1:2377:5ae2 with SMTP id
 4fb4d7f45d1cf-5d972dfb857mr10928593a12.7.1736534863869;
 Fri, 10 Jan 2025 10:47:43 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 34/38] i386/cpu: Track a X86CPUTopoInfo directly in CPUX86State
Date: Fri, 10 Jan 2025 19:46:15 +0100
Message-ID: <20250110184620.408302-35-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535232920116600
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

The name of nr_modules/nr_dies are ambiguous and they mislead people.

The purpose of them is to record and form the topology information. So
just maintain a X86CPUTopoInfo member in CPUX86State instead. Then
nr_modules and nr_dies can be dropped.

As the benefit, x86 can switch to use information in
CPUX86State::topo_info and get rid of the nr_cores and nr_threads in
CPUState. This helps remove the dependency on qemu_init_vcpu(), so that
x86 can get and use topology info earlier in x86_cpu_realizefn(); drop
the comment that highlighted the depedency.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-7-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.h        |  6 +----
 hw/i386/x86-common.c     | 12 ++++------
 target/i386/cpu-system.c |  6 ++---
 target/i386/cpu.c        | 51 +++++++++++++++++-----------------------
 4 files changed, 30 insertions(+), 45 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index e8c46d877e0..b26e25ba15e 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2068,11 +2068,7 @@ typedef struct CPUArchState {
=20
     TPRAccess tpr_access_type;
=20
-    /* Number of dies within this CPU package. */
-    unsigned nr_dies;
-
-    /* Number of modules within one die. */
-    unsigned nr_modules;
+    X86CPUTopoInfo topo_info;
=20
     /* Bitmap of available CPU topology levels for this CPU. */
     DECLARE_BITMAP(avail_cpu_topo, CPU_TOPOLOGY_LEVEL__MAX);
diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index 5b0629f9ad3..d5a44af2433 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -248,7 +248,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
     CPUX86State *env =3D &cpu->env;
     MachineState *ms =3D MACHINE(hotplug_dev);
     X86MachineState *x86ms =3D X86_MACHINE(hotplug_dev);
-    X86CPUTopoInfo topo_info;
+    X86CPUTopoInfo *topo_info =3D &env->topo_info;
=20
     if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
         error_setg(errp, "Invalid CPU type, expected cpu type: '%s'",
@@ -267,15 +267,13 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
         }
     }
=20
-    init_topo_info(&topo_info, x86ms);
+    init_topo_info(topo_info, x86ms);
=20
     if (ms->smp.modules > 1) {
-        env->nr_modules =3D ms->smp.modules;
         set_bit(CPU_TOPOLOGY_LEVEL_MODULE, env->avail_cpu_topo);
     }
=20
     if (ms->smp.dies > 1) {
-        env->nr_dies =3D ms->smp.dies;
         set_bit(CPU_TOPOLOGY_LEVEL_DIE, env->avail_cpu_topo);
     }
=20
@@ -346,12 +344,12 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
         topo_ids.module_id =3D cpu->module_id;
         topo_ids.core_id =3D cpu->core_id;
         topo_ids.smt_id =3D cpu->thread_id;
-        cpu->apic_id =3D x86_apicid_from_topo_ids(&topo_info, &topo_ids);
+        cpu->apic_id =3D x86_apicid_from_topo_ids(topo_info, &topo_ids);
     }
=20
     cpu_slot =3D x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx);
     if (!cpu_slot) {
-        x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids);
+        x86_topo_ids_from_apicid(cpu->apic_id, topo_info, &topo_ids);
=20
         error_setg(errp,
             "Invalid CPU [socket: %u, die: %u, module: %u, core: %u, threa=
d: %u]"
@@ -374,7 +372,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
     /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizef=
n()
      * once -smp refactoring is complete and there will be CPU private
      * CPUState::nr_cores and CPUState::nr_threads fields instead of globa=
ls */
-    x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids);
+    x86_topo_ids_from_apicid(cpu->apic_id, topo_info, &topo_ids);
     if (cpu->socket_id !=3D -1 && cpu->socket_id !=3D topo_ids.pkg_id) {
         error_setg(errp, "property socket-id: %u doesn't match set apic-id=
:"
             " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id,
diff --git a/target/i386/cpu-system.c b/target/i386/cpu-system.c
index eb38cca68ff..b56a2821af2 100644
--- a/target/i386/cpu-system.c
+++ b/target/i386/cpu-system.c
@@ -312,11 +312,11 @@ void x86_cpu_get_crash_info_qom(Object *obj, Visitor =
*v,
=20
 uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu)
 {
-    CPUState *cs =3D CPU(cpu);
+    CPUX86State *env =3D &cpu->env;
     uint64_t val;
=20
-    val =3D cs->nr_threads * cs->nr_cores;  /* thread count, bits 15..0 */
-    val |=3D ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
+    val =3D x86_threads_per_pkg(&env->topo_info);  /* thread count, bits 1=
5..0 */
+    val |=3D x86_cores_per_pkg(&env->topo_info) << 16; /* core count, bits=
 31..16 */
=20
     return val;
 }
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index a58c719e90c..1797bd8c071 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6496,15 +6496,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index=
, uint32_t count,
     CPUState *cs =3D env_cpu(env);
     uint32_t limit;
     uint32_t signature[3];
-    X86CPUTopoInfo topo_info;
+    X86CPUTopoInfo *topo_info =3D &env->topo_info;
     uint32_t threads_per_pkg;
=20
-    topo_info.dies_per_pkg =3D env->nr_dies;
-    topo_info.modules_per_die =3D env->nr_modules;
-    topo_info.cores_per_module =3D cs->nr_cores / env->nr_dies / env->nr_m=
odules;
-    topo_info.threads_per_core =3D cs->nr_threads;
-
-    threads_per_pkg =3D x86_threads_per_pkg(&topo_info);
+    threads_per_pkg =3D x86_threads_per_pkg(topo_info);
=20
     /* Calculate & apply limits for different index ranges */
     if (index >=3D 0xC0000000) {
@@ -6581,12 +6576,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index=
, uint32_t count,
                 int host_vcpus_per_cache =3D 1 + ((*eax & 0x3FFC000) >> 14=
);
=20
                 *eax &=3D ~0xFC000000;
-                *eax |=3D max_core_ids_in_package(&topo_info) << 26;
+                *eax |=3D max_core_ids_in_package(topo_info) << 26;
                 if (host_vcpus_per_cache > threads_per_pkg) {
                     *eax &=3D ~0x3FFC000;
=20
                     /* Share the cache at package level. */
-                    *eax |=3D max_thread_ids_for_cache(&topo_info,
+                    *eax |=3D max_thread_ids_for_cache(topo_info,
                                 CPU_TOPOLOGY_LEVEL_SOCKET) << 14;
                 }
             }
@@ -6598,7 +6593,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
             switch (count) {
             case 0: /* L1 dcache info */
                 encode_cache_cpuid4(env->cache_info_cpuid4.l1d_cache,
-                                    &topo_info,
+                                    topo_info,
                                     eax, ebx, ecx, edx);
                 if (!cpu->l1_cache_per_core) {
                     *eax &=3D ~MAKE_64BIT_MASK(14, 12);
@@ -6606,7 +6601,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
                 break;
             case 1: /* L1 icache info */
                 encode_cache_cpuid4(env->cache_info_cpuid4.l1i_cache,
-                                    &topo_info,
+                                    topo_info,
                                     eax, ebx, ecx, edx);
                 if (!cpu->l1_cache_per_core) {
                     *eax &=3D ~MAKE_64BIT_MASK(14, 12);
@@ -6614,13 +6609,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index=
, uint32_t count,
                 break;
             case 2: /* L2 cache info */
                 encode_cache_cpuid4(env->cache_info_cpuid4.l2_cache,
-                                    &topo_info,
+                                    topo_info,
                                     eax, ebx, ecx, edx);
                 break;
             case 3: /* L3 cache info */
                 if (cpu->enable_l3_cache) {
                     encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache,
-                                        &topo_info,
+                                        topo_info,
                                         eax, ebx, ecx, edx);
                     break;
                 }
@@ -6703,12 +6698,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index=
, uint32_t count,
=20
         switch (count) {
         case 0:
-            *eax =3D apicid_core_offset(&topo_info);
-            *ebx =3D topo_info.threads_per_core;
+            *eax =3D apicid_core_offset(topo_info);
+            *ebx =3D topo_info->threads_per_core;
             *ecx |=3D CPUID_B_ECX_TOPO_LEVEL_SMT << 8;
             break;
         case 1:
-            *eax =3D apicid_pkg_offset(&topo_info);
+            *eax =3D apicid_pkg_offset(topo_info);
             *ebx =3D threads_per_pkg;
             *ecx |=3D CPUID_B_ECX_TOPO_LEVEL_CORE << 8;
             break;
@@ -6734,7 +6729,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
             break;
         }
=20
-        encode_topo_cpuid1f(env, count, &topo_info, eax, ebx, ecx, edx);
+        encode_topo_cpuid1f(env, count, topo_info, eax, ebx, ecx, edx);
         break;
     case 0xD: {
         /* Processor Extended State */
@@ -7037,7 +7032,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
              * thread ID within a package".
              * Bits 7:0 is "The number of threads in the package is NC+1"
              */
-            *ecx =3D (apicid_pkg_offset(&topo_info) << 12) |
+            *ecx =3D (apicid_pkg_offset(topo_info) << 12) |
                    (threads_per_pkg - 1);
         } else {
             *ecx =3D 0;
@@ -7066,19 +7061,19 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index=
, uint32_t count,
         switch (count) {
         case 0: /* L1 dcache info */
             encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache,
-                                       &topo_info, eax, ebx, ecx, edx);
+                                       topo_info, eax, ebx, ecx, edx);
             break;
         case 1: /* L1 icache info */
             encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache,
-                                       &topo_info, eax, ebx, ecx, edx);
+                                       topo_info, eax, ebx, ecx, edx);
             break;
         case 2: /* L2 cache info */
             encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache,
-                                       &topo_info, eax, ebx, ecx, edx);
+                                       topo_info, eax, ebx, ecx, edx);
             break;
         case 3: /* L3 cache info */
             encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache,
-                                       &topo_info, eax, ebx, ecx, edx);
+                                       topo_info, eax, ebx, ecx, edx);
             break;
         default: /* end of info */
             *eax =3D *ebx =3D *ecx =3D *edx =3D 0;
@@ -7090,7 +7085,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
         break;
     case 0x8000001E:
         if (cpu->core_id <=3D 255) {
-            encode_topo_cpuid8000001e(cpu, &topo_info, eax, ebx, ecx, edx);
+            encode_topo_cpuid8000001e(cpu, topo_info, eax, ebx, ecx, edx);
         } else {
             *eax =3D 0;
             *ebx =3D 0;
@@ -7997,17 +7992,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Err=
or **errp)
      * fixes this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_00=
08_ECX
      * based on inputs (sockets,cores,threads), it is still better to give
      * users a warning.
-     *
-     * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
-     * cs->nr_threads hasn't be populated yet and the checking is incorrec=
t.
      */
     if (IS_AMD_CPU(env) &&
         !(env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) &&
-        cs->nr_threads > 1) {
+        env->topo_info.threads_per_core > 1) {
             warn_report_once("This family of AMD CPU doesn't support "
                              "hyperthreading(%d). Please configure -smp "
                              "options properly or try enabling topoext "
-                             "feature.", cs->nr_threads);
+                             "feature.", env->topo_info.threads_per_core);
     }
=20
 #ifndef CONFIG_USER_ONLY
@@ -8168,8 +8160,7 @@ static void x86_cpu_init_default_topo(X86CPU *cpu)
 {
     CPUX86State *env =3D &cpu->env;
=20
-    env->nr_modules =3D 1;
-    env->nr_dies =3D 1;
+    env->topo_info =3D (X86CPUTopoInfo) {1, 1, 1, 1};
=20
     /* thread, core and socket levels are set by default. */
     set_bit(CPU_TOPOLOGY_LEVEL_THREAD, env->avail_cpu_topo);
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535216; cv=none;
	d=zohomail.com; s=zohoarc;
	b=dHMPD5NsXVa3lp2W2dNG2MxAEk8hem5gylkdcTCVuQEYztypyBel6fvvhXmKGZeTFkpv0wTSSUp+LsLzvYL8MX29BD1X38tubKnC8K3i4+czPVkEVKeOydG/amCCRmBMpUKPVQVP+cx5LS3wvEwgZIZjH9u1m4VSRLfqT7CWor0=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535216;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=3I28akyrgNRO85WGd2WX/Mawn2r7ecEtUfOeL4OylPc=;
	b=GiQ/wdbnFpJoaI9o7ROl77tQjiSqJa3l3u3evRoZwYePzeOjwTedfGEr46QeHg2wbz4XjUnR7vPePDSlQTmK0Oqx/nlg/+ub2JLmJixEhiWXfqhN4XFzNSdYFwB6SlqTy2c2WYfofSwKVpinIRq6Z1XbP1/q7xl2ihGUY8JMM8M=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535216485572.2121249261506;
 Fri, 10 Jan 2025 10:53:36 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4G-0003ZN-Ez; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK32-0001SI-69
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2w-0001Ee-VN
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:55 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-365-Hfvfhgx-Pp-TynRSo7alvQ-1; Fri, 10 Jan 2025 13:47:49 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d3ff30b566so2427016a12.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:48 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903c3333sm1980993a12.47.2025.01.10.10.47.44
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534870;
 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=3I28akyrgNRO85WGd2WX/Mawn2r7ecEtUfOeL4OylPc=;
 b=f+No8aihFMkcYOSMJllTWxu3BKYb50nw8j502ZPFp+vh/+J9XAMfEWAUiIYUKEKlBABNtv
 WQzojIfBUdQnVaGOtAwE7pPUz4o8dA6dz05c1OsVQuJ24WXpy496bFfmUveruYoq/mQlAs
 Gy44K8Bol7LFjBKoqiy5Ea25JoRnpDM=
X-MC-Unique: Hfvfhgx-Pp-TynRSo7alvQ-1
X-Mimecast-MFC-AGG-ID: Hfvfhgx-Pp-TynRSo7alvQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534867; x=1737139667;
 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=3I28akyrgNRO85WGd2WX/Mawn2r7ecEtUfOeL4OylPc=;
 b=HPEaToPxuJSdbEgvJQtr1n0WJrv6WMB7LjSKVGhnpZEvZ237otkILYiUCVh41TN9qh
 7qrkbRSnC28pwfLdULSbYjttb/0cHywJSH0sEShjctW2DX5/KvUZpk+sVSkVK9Jqptx1
 MzwJgrjCRmgUGnH6F4+e92d510Q9PPNseDCpsMzJeEtON1o3Pvr2SrtXwOYLdNnwYOY7
 F9k4YcDXFQ5f1i1ow8KAKx/Qn8O0ePoTOebK/wJIaY6BxlYfAnJJY5gSYpheTzKE0O0D
 yLW2XePdAa8xynaz1CmgFuuuZUH1A3jVSX6rrpjfkDDwsjqbFZFRlgzHdIaZM4gyuj6U
 4rJg==
X-Gm-Message-State: AOJu0Yw0zkFDsUIYkK+IwsBF0HRLh+Qk14J4eY34zohYX0DY633NuAC4
 U2e9ykRjcw8SIt9MAwBb8O5EXAszSrec0plgs5PhrkO3R466ypMcE9bmAyNsYmS1ndH5Xjdg/BO
 7z3K+Y9tqxfcztH3mYvLg2Qal4FtGxJ5JWBtuit/R/5rm8nwASnycO7UvuYiA5MWaqNHkHn51S0
 bDosuMoQ3eHO/sYdbY15HPgrwLRewsoTcpO0KsT/c=
X-Gm-Gg: ASbGncuic1Y4PwsI14DBl/ljb/NiyS5IqwVEcOiP2OjqjB2QlwKjpDKoOPyNGiU20Mg
 y/7FIsogyVbWtxQivSeE5eIGpsBGCWSFnoNnn4VyaUKfI2hHPYtn0mfUrF7BUlmFzZTCB9KA3KQ
 IYJFcXD4j2i2GTVHC+4mZK82mv6B/X5a+igFXfwMeOHWkfwmfFolffyDqFcUF+pKGRItQllMbtZ
 +3mS69613Cf4njT80WKY4geSavkkDlyTeVSOpr7J0gcMh/zQvkOwNTC8FI=
X-Received: by 2002:a05:6402:354b:b0:5d0:bf4a:3dfe with SMTP id
 4fb4d7f45d1cf-5d972e4e7b6mr10309143a12.23.1736534866761;
 Fri, 10 Jan 2025 10:47:46 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFbby1OGsGkfTIQcEh7LJZw3q8Z7dQXwnh9y7cbY3Pf2UcNEBE0eA9lINn9sofDdRtCyXbkRQ==
X-Received: by 2002:a05:6402:354b:b0:5d0:bf4a:3dfe with SMTP id
 4fb4d7f45d1cf-5d972e4e7b6mr10309124a12.23.1736534866306;
 Fri, 10 Jan 2025 10:47:46 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 35/38] i386/cpu: Hoist check of CPUID_EXT3_TOPOEXT against
 threads_per_core
Date: Fri, 10 Jan 2025 19:46:16 +0100
Message-ID: <20250110184620.408302-36-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535218047019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

Now it changes to use env->topo_info.threads_per_core and doesn't depend
on qemu_init_vcpu() anymore.  Put it together with other feature checks
before qemu_init_vcpu()

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-8-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1797bd8c071..3f9475b4856 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7883,6 +7883,21 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro=
r **errp)
      */
     cpu->mwait.ecx |=3D CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
=20
+    /*
+     * Most Intel and certain AMD CPUs support hyperthreading. Even though=
 QEMU
+     * fixes this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_00=
08_ECX
+     * based on inputs (sockets,cores,threads), it is still better to give
+     * users a warning.
+     */
+    if (IS_AMD_CPU(env) &&
+        !(env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) &&
+        env->topo_info.threads_per_core > 1) {
+            warn_report_once("This family of AMD CPU doesn't support "
+                             "hyperthreading(%d). Please configure -smp "
+                             "options properly or try enabling topoext "
+                             "feature.", env->topo_info.threads_per_core);
+    }
+
     /* For 64bit systems think about the number of physical bits to presen=
t.
      * ideally this should be the same as the host; anything other than ma=
tching
      * the host can cause incorrect guest behaviour.
@@ -7987,21 +8002,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro=
r **errp)
     x86_cpu_gdb_init(cs);
     qemu_init_vcpu(cs);
=20
-    /*
-     * Most Intel and certain AMD CPUs support hyperthreading. Even though=
 QEMU
-     * fixes this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_00=
08_ECX
-     * based on inputs (sockets,cores,threads), it is still better to give
-     * users a warning.
-     */
-    if (IS_AMD_CPU(env) &&
-        !(env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) &&
-        env->topo_info.threads_per_core > 1) {
-            warn_report_once("This family of AMD CPU doesn't support "
-                             "hyperthreading(%d). Please configure -smp "
-                             "options properly or try enabling topoext "
-                             "feature.", env->topo_info.threads_per_core);
-    }
-
 #ifndef CONFIG_USER_ONLY
     x86_cpu_apic_realize(cpu, &local_err);
     if (local_err !=3D NULL) {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535008; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ChCRWpAaaI/wT9iaxg2iGlS0lsm0XxvYAEFVj9E/LFuuBErHazz+iMv875U719YM51FlINa/Msv3n0m82M5WKJ7QyaEq0rPb0F54j+H1K6Kmmsfo0CidFq/l8O1kZUNFf9TstjpJGGZG4f2A9BGsKUt3I67ho5y7MUUTjX6DB4U=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535008;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=DTFKgODEFPxb1Rk0GJF65qhyFgCjbUlVyAYk2qcRkJ8=;
	b=DA8K9yuezeTsum3YCAdetlUEuZq+jJsU2oJFCwtf7tNYt+f+3FocO9blr5T3ayK3KUMcQYH353ifqmpmszR85b/W0++GISvMxl80FDJREjI3PWyExG5WzdwKb07YUzRWcZaO3Fx3Fa9Z1IfXUgDHDpsighGfLOaZ76bMMwv1gMg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535008280579.0766269730074;
 Fri, 10 Jan 2025 10:50:08 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4p-000626-Gx; Fri, 10 Jan 2025 13:49:47 -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 <pbonzini@redhat.com>)
 id 1tWK32-0001SY-7T
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47: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 <pbonzini@redhat.com>)
 id 1tWK2z-0001Ez-Ni
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:55 -0500
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-133-bxlRSeUDPJKGInhb95j1KQ-1; Fri, 10 Jan 2025 13:47:51 -0500
Received: by mail-ej1-f69.google.com with SMTP id
 a640c23a62f3a-aa6a87f324cso211710966b.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:51 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c90d81c4sm194760666b.64.2025.01.10.10.47.47
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534873;
 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=DTFKgODEFPxb1Rk0GJF65qhyFgCjbUlVyAYk2qcRkJ8=;
 b=HijdWrKS8o/VmQYHyFYcPcjS5v0DJbks91+1/Pb39VE8VwBW+v4YZ82ckGeD6bS+ndFFgN
 HM5ekbTacBpc96WPk0X+F1Z/Hkvbhr/B8424Cc94EF1fKQftmO+SQ9uky8Ap2cbzxZ9D8v
 Gto7VD9JTGhtw5srsQK5ml9QcW3cA6w=
X-MC-Unique: bxlRSeUDPJKGInhb95j1KQ-1
X-Mimecast-MFC-AGG-ID: bxlRSeUDPJKGInhb95j1KQ
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534870; x=1737139670;
 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=DTFKgODEFPxb1Rk0GJF65qhyFgCjbUlVyAYk2qcRkJ8=;
 b=aXmTty6bgCoNMxiR6wYd57xHVhoNIvjKC1UcdNh48MHx6xTPJAem6fTFyDgueVH3c0
 Y7AdBTxUCAoMgJ6fZnV+h1SSGasNzZ5q+GdQfh651v+elGP1b8hy8I0tCkMetTGt8sMz
 ZmkySrxAl31kcn2OIBkFVwF8U2iPyDCCq2UpqOFMWOoqZzDZ/ail9aNCnm9/2Mqhyww/
 tqykx2ae9jz8wGeXHwAxW0XsMFN5pAdTSb8L4WHtVsu9h0YhqicsmEadvonxtH+RpSHM
 VxZiRoPiMDRiCD02P8Rl35orjuzaKLW08qumvzQQ4hFkOg/l93tFaBH6FciZHeRy1eXU
 Otcg==
X-Gm-Message-State: AOJu0YxpNyN3pEEWiOyoEB/D1BkvCuGC1J9tljmr1WGFccg+RDy4NKFl
 yC65Yqo+4GM23xe9dME8JeelQQO78dUHBfwMk+BxiYo2ThyZsNBbTyWA76xJ+9zyBfKSn1eOxWJ
 nU32CCXH47NKQYOUSiAv3RlP6kFAkHfKOIJWRxgAC2wJSFsQErkx9cUMTvwZKxRaIOKrDS2Jku9
 lXvHU03rjtL1X0VDuKicY5btra9UOtWUHqv/UIcxY=
X-Gm-Gg: ASbGncur6JuhH4h3nNOEAUlvergIrGJoh8iD5yaE22oHFYU9B7ZJTKljv9cf8MiQLkF
 QL0xLiZRpwfHSkLxlYmKaXWTFIsmDAUjoI4Tlh5pl/Rl9Zg014E96LHzjIt87tq6MRgznAC9OS6
 mKJfiXmxAtG8e3PyQqdnq9DBJF4VuFWOAlfnR1juTJ2cMpT60PATVlt3pbWtO2x3cqfeYwJEdWH
 9wF/1rYDj2FRSy2Hh9UmJEZOC4WtYEwKXHmiMSeayduNPnCzpdOttPAjh0=
X-Received: by 2002:a17:907:a0cf:b0:ab2:b77e:f421 with SMTP id
 a640c23a62f3a-ab2b77ef683mr944977166b.23.1736534869653;
 Fri, 10 Jan 2025 10:47:49 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IEbWzlDo6ABCULYQ3HbbqUBaIWyRM+E2vNUe/ywyNxFncIrLZi8ztJhNHx1J4l8pon4+aTp+Q==
X-Received: by 2002:a17:907:a0cf:b0:ab2:b77e:f421 with SMTP id
 a640c23a62f3a-ab2b77ef683mr944974866b.23.1736534869138;
 Fri, 10 Jan 2025 10:47:49 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 36/38] cpu: Remove nr_cores from struct CPUState
Date: Fri, 10 Jan 2025 19:46:17 +0100
Message-ID: <20250110184620.408302-37-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535009093019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

There is no user of it now, remove it.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-9-xiaoyao.li@intel.c=
om
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/hw/core/cpu.h | 2 --
 hw/core/cpu-common.c  | 1 -
 system/cpus.c         | 1 -
 3 files changed, 4 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c3ca0babcb3..fb397cdfc53 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -407,7 +407,6 @@ struct qemu_work_item;
  *   Under TCG this value is propagated to @tcg_cflags.
  *   See TranslationBlock::TCG CF_CLUSTER_MASK.
  * @tcg_cflags: Pre-computed cflags for this cpu.
- * @nr_cores: Number of cores within this CPU package.
  * @nr_threads: Number of threads within this CPU core.
  * @thread: Host thread details, only live once @created is #true
  * @sem: WIN32 only semaphore used only for qtest
@@ -466,7 +465,6 @@ struct CPUState {
     CPUClass *cc;
     /*< public >*/
=20
-    int nr_cores;
     int nr_threads;
=20
     struct QemuThread *thread;
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 1edc16f65c8..cb79566cc51 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -243,7 +243,6 @@ static void cpu_common_initfn(Object *obj)
     cpu->cluster_index =3D UNASSIGNED_CLUSTER_INDEX;
     /* user-mode doesn't have configurable SMP topology */
     /* the default value is changed by qemu_init_vcpu() for system-mode */
-    cpu->nr_cores =3D 1;
     cpu->nr_threads =3D 1;
     cpu->cflags_next_tb =3D -1;
=20
diff --git a/system/cpus.c b/system/cpus.c
index 99f83806c16..37e5892c240 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -687,7 +687,6 @@ void qemu_init_vcpu(CPUState *cpu)
 {
     MachineState *ms =3D MACHINE(qdev_get_machine());
=20
-    cpu->nr_cores =3D machine_topo_get_cores_per_socket(ms);
     cpu->nr_threads =3D  ms->smp.threads;
     cpu->stopped =3D true;
     cpu->random_seed =3D qemu_guest_random_seed_thread_part1();
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535145; cv=none;
	d=zohomail.com; s=zohoarc;
	b=eTSAF4SlGQbeGVr5Peict4XskMR8Em8RtnDpem8Y5yrSTTiRG6q1paX47P2xVa7MQhtwim8Yt4n6+uml0LI5Tw7JfzeCgW2VyUsIDLN82XyZL9MZDOyEoShhegwr+gc0AHq9/lHvEt6bWXC9ecDzncs2mkWswFlTDT2S6h2MZ9A=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535145;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=9tXrkESM7KbpebY71/8nCs2zuzSL+b7tMHIIwxW8rds=;
	b=WPDBxvT0fPF0akYjn6uPWQEGmeZGJ70RMmLfrtfFq8Dij9loCokhMD2BQylPormk8C8ns0wobAUTGhHT8WoK2tXv/QjpwaH1P1lubUVmK1SDMfJRc5wZrplY7dTFVC4UPdc8GrA2TcYujZojS6eWqNobzV2Yr6332J/SBntqrFM=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535145896473.3434550271429;
 Fri, 10 Jan 2025 10:52:25 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4s-0006P6-Pp; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK34-0001g0-4A
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:58 -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 <pbonzini@redhat.com>)
 id 1tWK32-0001FH-CK
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:47:57 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-604-EF-P-xqUMgq4k-9zWcRgSw-1; Fri, 10 Jan 2025 13:47:53 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d3d6d924c1so2460716a12.2
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:53 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-ab2c8ccc1b5sm192880466b.0.2025.01.10.10.47.50
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:50 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534874;
 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=9tXrkESM7KbpebY71/8nCs2zuzSL+b7tMHIIwxW8rds=;
 b=NDfc6co9OMvGr/I0VScBvJTkYIjDjCnfzRmopXQfP0wVJTJReYRNhnbtN7528yJqxaUB9E
 Rihfihwrd1Vyp07SUiGirfAqdy5ZNZ0hRpqkeTcxr3NTDLC9my6lhdEXJb39zRzVZP7v7Z
 sRTQWuiyIctFZNT8icdSwfmMJkzR8ik=
X-MC-Unique: EF-P-xqUMgq4k-9zWcRgSw-1
X-Mimecast-MFC-AGG-ID: EF-P-xqUMgq4k-9zWcRgSw
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534872; x=1737139672;
 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=9tXrkESM7KbpebY71/8nCs2zuzSL+b7tMHIIwxW8rds=;
 b=Qsok9LA113mpRrA1dy4B5pLp7Yk9mm10vftxqeC5O/M0xhnRnm3QmAl7SI5V1CMB5t
 plw0IcVGxbGB/UUZphXr+QJFtuXl9Gg4v/PrF0qkSR4TPTMQURAIdg6iLwFpCPcjBC/U
 fesO+gAPIyLSshRHzDOitpgYqDV14t37RsjMpkZZKYQbGpI6SRKBqpIXjsXj+RL+5OGP
 p1YfR36z41A1/OO0wWc05ZVFNC7iLK8Kk/s49B4EQ9KgrKqYfx63j5OIUYOaDRgEtYod
 9Ucj50QOoKY6hK+QJw3Skadox/oCvz9T8RFf8P7hGAqLbPsNZKEFMVRF9CdGO12is6y7
 O6Sw==
X-Gm-Message-State: AOJu0YwpMS92YozGXOspCOQuVByZ2V90gnWHvVl1iz2T6QaG+xHyrYnm
 B67RUoMdo28KVmitX5p7j1Gy7cDlbck7FCdq3PBHd1fJtZaZoy0btW9n3dlDCwnQp0tDVbj2P7a
 Ag0b4xMF80c8dd/4Z3Xof3kv+DSOkjrU4F7YduhhGVNkXDSEP/svr5OaC3+qAYVpfH65er6kFEM
 SnczYKMpq+1DI+zVxPtjERss1hyq2GLQ5Srwxkynk=
X-Gm-Gg: ASbGnctJr4zhRJWl8DGmLEvxqNJ2fzciq6zJZlVL/stqQ4sUD201RJ/GZD/vhtgb95W
 +jm3UQsnI9vLIoPaIy7yZtiRDssee+Sk0BeCPWkyvGC6hSyln9wlCgPIrMasT3qfiQL9VT1T8+V
 vZK+ESXeX/ne20vlzgqkPa2QrQUA7FN1/mXdUVrFZMe3hkVloAm5fupnok26/4lfrOiQnXDmR0A
 Hu7LvewLR836M+/IqfZ7bpaV/6po4Fi9E1REvfrRawR2lzZ5oK4Y9l1vdY=
X-Received: by 2002:a17:907:6ea5:b0:aa6:558b:fcc3 with SMTP id
 a640c23a62f3a-ab2ab6a850fmr1086958166b.4.1736534871690;
 Fri, 10 Jan 2025 10:47:51 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IGfLkeoFbiBY7tuKOJngWRrGK7B0DWI4K7EXVQq4naPpWzKQk04SautNQ6OAhwAnsigRQ8+HQ==
X-Received: by 2002:a17:907:6ea5:b0:aa6:558b:fcc3 with SMTP id
 a640c23a62f3a-ab2ab6a850fmr1086955666b.4.1736534871287;
 Fri, 10 Jan 2025 10:47:51 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 37/38] i386/cpu: Set up CPUID_HT in x86_cpu_expand_features()
 instead of cpu_x86_cpuid()
Date: Fri, 10 Jan 2025 19:46:18 +0100
Message-ID: <20250110184620.408302-38-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.133.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535147779019000
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

Currently CPUID_HT is evaluated in cpu_x86_cpuid() each time. It's not a
correct usage of how feature bit is maintained and evaluated. The
expected practice is that features are tracked in env->features[] and
cpu_x86_cpuid() should be the consumer of env->features[].

Track CPUID_HT in env->features[FEAT_1_EDX] instead and evaluate it in
cpu's realizefn().

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-10-xiaoyao.li@intel.=
com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 3f9475b4856..3f0821c15f2 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6538,7 +6538,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, =
uint32_t count,
         *edx =3D env->features[FEAT_1_EDX];
         if (threads_per_pkg > 1) {
             *ebx |=3D threads_per_pkg << 16;
-            *edx |=3D CPUID_HT;
         }
         if (!cpu->enable_pmu) {
             *ecx &=3D ~CPUID_EXT_PDCM;
@@ -7529,6 +7528,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **er=
rp)
         }
     }
=20
+    if (x86_threads_per_pkg(&env->topo_info) > 1) {
+        env->features[FEAT_1_EDX] |=3D CPUID_HT;
+    }
+
     for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) {
         FeatureDep *d =3D &feature_dependencies[i];
         if (!(env->features[d->from.index] & d->from.mask)) {
--=20
2.47.1
From nobody Sat May 10 08:17:40 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1736535135; cv=none;
	d=zohomail.com; s=zohoarc;
	b=ZV8kfgNgPqMEqDSsEcLP9gLQPuNKR1a/Smmp6ueqDDmU0ahnAE3DnbN2l7j488lywAwuG2L5A95zjiaspyO2RgpiUY8TjdpwFvTr1wlvteu5AcnIC8XzxFKA143gz64msfTSmk1PGVqSJbtHZpWYstsyK4mUE/D88mAO5EhV18U=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1736535135;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=aZwSEYQVpte/NSCKZ3yifhKY5nLmZ34Bel3Y7xhbE78=;
	b=PAVSWWmaGN05QfA1sfreMf9HxaS9uIdyUiS0YaosUZZChhDR4ghDSvA2bCWwaOX4OfTFF6ID49vgkcnuk9QTbMxW91U1iQxz4Epv5UZ1BWrica413upwJpDTFSqa/5HTDaO49PdC1eNxh8eYGGMGXTAEAUMS7DJ6MnKIn9/DR6M=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<pbonzini@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1736535135376316.8757232490186;
 Fri, 10 Jan 2025 10:52:15 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tWK4z-00070z-49; Fri, 10 Jan 2025 13:49: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 <pbonzini@redhat.com>)
 id 1tWK36-0001xI-TH
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:48:01 -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 <pbonzini@redhat.com>)
 id 1tWK34-0001Ft-CS
 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 13:48:00 -0500
Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com
 [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-53-f_ot_YczOhifiXb24KF2_w-1; Fri, 10 Jan 2025 13:47:56 -0500
Received: by mail-ed1-f72.google.com with SMTP id
 4fb4d7f45d1cf-5d09962822bso2304073a12.1
 for <qemu-devel@nongnu.org>; Fri, 10 Jan 2025 10:47:56 -0800 (PST)
Received: from [192.168.10.3] ([151.62.105.73])
 by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5d9903c3333sm1981068a12.47.2025.01.10.10.47.51
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 10 Jan 2025 10:47:52 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1736534877;
 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=aZwSEYQVpte/NSCKZ3yifhKY5nLmZ34Bel3Y7xhbE78=;
 b=QjQoyXJfCgm5/WA0BkY74Ou0bBpLNECQDU8Ep6aZfxqkK3fYlSBX2gQQizUxjvdnQNkKps
 KN5VuZ70uR61kAfpzlWQ8bACVhbmNk0bvCmj2NeAdzMVzXKBWMlqn5ZclZiYgnkKwBuumq
 nwqOIRQA+9Cd7Xl7Y2XRuOYQHU/6lpg=
X-MC-Unique: f_ot_YczOhifiXb24KF2_w-1
X-Mimecast-MFC-AGG-ID: f_ot_YczOhifiXb24KF2_w
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736534874; x=1737139674;
 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=aZwSEYQVpte/NSCKZ3yifhKY5nLmZ34Bel3Y7xhbE78=;
 b=WVxzWUor6ygtLvjcrMWBO/kjDH9aFJqcKmVkNF7t8oOcKxV0IAoeAOdIGjHo/HqI4v
 8qZOYCK6iPQ5Z20ejYd4Y71UZrS0E7Jzi70hY8Jb/vKQSe0fcNS2OLkvPUIZYBWNW9Sc
 Ry3T9Jip73sDeNMGndbqgvvgzEWrXB0r76ZH7hVy7AF2aiYZEGVrzP9LGaBpis/zp2g7
 KDu+nK7mj2BaaRo0FHA89nHiyGRx52Bwsr6ZO/mPzKC+FXWctd1oceejSe4lREo0dkjr
 jdqbtsA8JZz6VDxTfS6+RO8cnkVS3MmGy4stOk954oPsxCl5SyRGKjQ4fHzk5vaPOp7e
 Bcjg==
X-Gm-Message-State: AOJu0YytlI9GUGIJF6clCqV08w01JahqO1BNFP6nngc3pJcUtXUNoJzc
 8EypHUBCKJ4LqH06E2/W6Y+TMMP0Ce9KoxYwKC8SYAdiVSs0PwcDe6DpS9hWk4C+Dq8a9cLtjYc
 eqwVxfMXK8YRe27Nz1z0T6WKseLWLfhCQEphd2JCH8pfLsVcyvUEXZDX/DWsdiWzM4l7ezTur67
 KKrjT137KLCXTOKDbVCgtxzrb7vjtse+sGK9FE8Fg=
X-Gm-Gg: ASbGnctWw6aj2qUsIQS3yMdGXoQ/aCw1mRBmX3374bbf1qaEADFcqQoyHK6coeClBl/
 Z8XNd/cUkm7ihrHr7F0Fw3+2r5iOr+Z4+pBKadSfzdHBBGklEtsqFH6KcS51DVjuid0WEawaAWE
 DqCNl4oKxBsdC5hCtxroF500hR1qtxzq4Mzjmqku9ZDsx84pro6XNIDJ2zL2IenGpkuiGlsAXy9
 fXsFvLBZNL6sEOfqE9Hq6koqvS0PEgmQ64R5ieyNJKZeakgw7DktZpNcD8=
X-Received: by 2002:a05:6402:274c:b0:5d3:e766:6143 with SMTP id
 4fb4d7f45d1cf-5d972e7247cmr11355882a12.30.1736534873883;
 Fri, 10 Jan 2025 10:47:53 -0800 (PST)
X-Google-Smtp-Source: 
 AGHT+IFZOB2XuhTyTVWuqOQ3YoS5HysxqigKzBLiM1JgK9WKbLfI8QQCsKAIf/hy1tU7KyfhsB8QIA==
X-Received: by 2002:a05:6402:274c:b0:5d3:e766:6143 with SMTP id
 4fb4d7f45d1cf-5d972e7247cmr11355854a12.30.1736534873292;
 Fri, 10 Jan 2025 10:47:53 -0800 (PST)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 38/38] i386/cpu: Set and track CPUID_EXT3_CMP_LEG in
 env->features[FEAT_8000_0001_ECX]
Date: Fri, 10 Jan 2025 19:46:19 +0100
Message-ID: <20250110184620.408302-39-pbonzini@redhat.com>
X-Mailer: git-send-email 2.47.1
In-Reply-To: <20250110184620.408302-1-pbonzini@redhat.com>
References: <20250110184620.408302-1-pbonzini@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124;
 envelope-from=pbonzini@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -24
X-Spam_score: -2.5
X-Spam_bar: --
X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.432,
 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_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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1736535136556116600
Content-Type: text/plain; charset="utf-8"

From: Xiaoyao Li <xiaoyao.li@intel.com>

The correct usage is tracking and maintaining features in env->features[]
instead of manually set it in cpu_x86_cpuid().

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241219110125.1266461-11-xiaoyao.li@intel.=
com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 3f0821c15f2..1b9c11022c4 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6953,17 +6953,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,=
 uint32_t count,
         *ecx =3D env->features[FEAT_8000_0001_ECX];
         *edx =3D env->features[FEAT_8000_0001_EDX];
=20
-        /* The Linux kernel checks for the CMPLegacy bit and
-         * discards multiple thread information if it is set.
-         * So don't set it here for Intel to make Linux guests happy.
-         */
-        if (threads_per_pkg > 1) {
-            if (env->cpuid_vendor1 !=3D CPUID_VENDOR_INTEL_1 ||
-                env->cpuid_vendor2 !=3D CPUID_VENDOR_INTEL_2 ||
-                env->cpuid_vendor3 !=3D CPUID_VENDOR_INTEL_3) {
-                *ecx |=3D 1 << 1;    /* CmpLegacy bit */
-            }
-        }
         if (tcg_enabled() && env->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_=
1 &&
             !(env->hflags & HF_LMA_MASK)) {
             *edx &=3D ~CPUID_EXT2_SYSCALL;
@@ -7530,6 +7519,15 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **er=
rp)
=20
     if (x86_threads_per_pkg(&env->topo_info) > 1) {
         env->features[FEAT_1_EDX] |=3D CPUID_HT;
+
+        /*
+         * The Linux kernel checks for the CMPLegacy bit and
+         * discards multiple thread information if it is set.
+         * So don't set it here for Intel to make Linux guests happy.
+         */
+        if (!IS_INTEL_CPU(env)) {
+            env->features[FEAT_8000_0001_ECX] |=3D CPUID_EXT3_CMP_LEG;
+        }
     }
=20
     for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) {
--=20
2.47.1