From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491272; cv=none; d=zohomail.com; s=zohoarc; b=SazJxr/zM66wyy2tHpjKwQLav1Z60v7682XUZEzaO1B7Fam4hp/hidEKwT6D3U6UhztsxdcIyCVxpzmsjibJpKvnJjjyvPsD7O32saMW/m4q9U1iF+aD93aM23OVQc653j+XwynW2gH4jD8wVXLuEcBJudPMv+K54HQrjvfmWUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491272; 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=NDRZLxJKWA6sImNVSmtEek9dip1W5KzkCgPQbaRO+uY=; b=U3zXJPKeLhPa+4LUVABNznKoSK3p95s9sDV0g0mzCqkE245J/g3C44r51F3IbCV2/fNZZ70+g+QmX5M6+xwSQVockQ9RNewWZOtUDSf8QUr68hKp738wvuFj7qpCtsoSWjxbFcCOHkp1isReQGcY6ENW7kS/pdaOxr7b8qXRTjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491272390720.4737001853005; Mon, 14 Jul 2025 04:07:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH1s-0002Hb-Ty; Mon, 14 Jul 2025 07:07:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz0-0000aK-2v for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGys-0001Uo-NH for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:28 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-cfLsmY0QOpueJ8lP3r0I2A-1; Mon, 14 Jul 2025 07:04:12 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4561dbbcc7eso2087955e9.2 for ; Mon, 14 Jul 2025 04:04:11 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561a052729sm32466735e9.33.2025.07.14.04.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491056; 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=NDRZLxJKWA6sImNVSmtEek9dip1W5KzkCgPQbaRO+uY=; b=OJW54LZNomVu+1IPH3lOn1ydEBtIR6aAlyr3tt9gfT903zry3CmhspLbNkyNTGODnbfOpD /Nq264XQB3EOaHlHys8v5tBdT3Tm0onwjJxg8kg2oiVs9Cq2/X9g8nW3odEwG3wVTmsn6j giA/z6XgEoi/+FLF2GGHgYPONRDklzw= X-MC-Unique: cfLsmY0QOpueJ8lP3r0I2A-1 X-Mimecast-MFC-AGG-ID: cfLsmY0QOpueJ8lP3r0I2A_1752491051 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491050; x=1753095850; 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=NDRZLxJKWA6sImNVSmtEek9dip1W5KzkCgPQbaRO+uY=; b=k5uZUJW3NrgaV39Fp/di/nO0VIEzXdkOTbHuZv2G2zZsBaCejNMdLTxfev7xhiohVq L5jK/nCc2if2rahybWkNkwFTMV+C6mMQQg0wAaytIAc9YP3EIhrOUi9ex44lUGP/8yak ygc5Ik9N+8Fma9a6pnBybKKCDRWiYBVnGuBSkyF/gp8ZeYUQbwMjSIolzKZ+IZA2Qv8U mLs28n64IvsUOAhH87Em60loloL5hHzvX62BY+x8FbPwNafaXWeMg2NScYvavTmJFRii rrQjBewE9TcFzi7DVFnAztAUMW0lr8MVsgwifcbPsuQXy747Vf5VA1E4Crlx8ccYef65 TiWA== X-Gm-Message-State: AOJu0YzhWyLWSU16UNW1cx9QdYbFnWV5BBa6FA5tRfRAuWSBWU/4y4By rX0U4Kwuml04EQXNwVGvnkxrvuBvrDL/6lE3NigNJnBRiNtMET2ygeXl0WdrXi8UUjt7HLBdzC2 vkIq73TZ2NHTEcl3m2cwh2uf2YqRnvhHzAJfeYotHA3ziYk2SiRnsL8SfeFW1/SQ/asYdw6Lmsr uo3hACqgsDSlB1MsSPwTEtshW79d8EQ2pjSEJln+XX X-Gm-Gg: ASbGncv8xdTUvZsOYI+hN/soOMnE3AXvbvZCljsTGf2mWqe9FFjXIWWW7W9ucuQpLQG p/PP2ZWs72uGGf3DZMJtD17Se8uxKxR7TuckUfzoE8OCSXQADwosjnDS/FXuEuBqeXNJsgBZoA2 2AyEyplhn1hCH0+U3JPZtz15HQkpkpKnmTX4pp4cVCKitWe707UnUXkb4Io9yyuP6isDIajvYQo tWZSrv4l/Z7Io3yb7jBDoUub672QlbE0+gNjfA22PACVnRakp/hTDOjDvF9oXKFQ2ePVhVjTd1h ovr5+tndfp+QSaCBgtuyK4f2L9ybqhuPcnFi8i0xOh4= X-Received: by 2002:a05:600d:15a:20b0:456:214f:f78d with SMTP id 5b1f17b1804b1-456214ffcbbmr6523185e9.22.1752491050210; Mon, 14 Jul 2025 04:04:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWchi52AiVGkBDaZkhBzcfZp5vhRB5DdlQA6+9FdupEHkHxjP9CPKav7n8s/76Y2W1UB3MKQ== X-Received: by 2002:a05:600d:15a:20b0:456:214f:f78d with SMTP id 5b1f17b1804b1-456214ffcbbmr6523005e9.22.1752491049726; Mon, 14 Jul 2025 04:04:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 01/77] rust/qemu-api: Fix binding path in source directory Date: Mon, 14 Jul 2025 13:02:50 +0200 Message-ID: <20250714110406.117772-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491273639116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The build.rs had supported placing bindings.inc.rs in rust/qemu-api/src, but this "not encouraged" feature is broken. Considering that manually copying bindings.inc.rs to the development directory is also useful, fix the bindings.inc.rs path generation to give this feature another chance. Fixes: commit 1ae4ca0463d7 ("rust: move rust.bindgen to qemu-api crate") Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250623073436.1833357-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/qemu-api/build.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 7849486c1ba..29d09456257 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -9,12 +9,14 @@ use std::{env, fs::remove_file, io::Result, path::Path}; =20 fn main() -> Result<()> { - // Placing bindings.inc.rs in the source directory is supported - // but not documented or encouraged. - let path =3D env::var("MESON_BUILD_ROOT") - .unwrap_or_else(|_| format!("{}/src", env!("CARGO_MANIFEST_DIR"))); + let file =3D if let Ok(root) =3D env::var("MESON_BUILD_ROOT") { + format!("{root}/rust/qemu-api/bindings.inc.rs") + } else { + // Placing bindings.inc.rs in the source directory is supported + // but not documented or encouraged. + format!("{}/src/bindings.inc.rs", env!("CARGO_MANIFEST_DIR")) + }; =20 - let file =3D format!("{path}/rust/qemu-api/bindings.inc.rs"); let file =3D Path::new(&file); if !Path::new(&file).exists() { panic!(concat!( --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491600; cv=none; d=zohomail.com; s=zohoarc; b=jIahy4FGFU3AQA9BKH+ms6bopWVpXs2WsrNuwnVMAXJ7FZfoBTOZXMGYNrm8fk5p07UzwnFr2kDL5Q6ATMmph9LWJd35L0gsKvzC9GBNqpH2BTy0imP2suIx0epLoXny3NizF/LidR2zngpMkqiuJejxwqoEck5Xex2zjD2aczU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491600; 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=Iz1uX/fPHm96LL/GLvQKBENI0zWW46MxM6ylmWl1pqE=; b=V0qPVWImAdsJJmoYkUtxn2BrPCNlynfycd5TxvTFkqR0s36N39CjEQpSDsNKzeTE3eA5BN8bOC5K3tx8x6gfUWGKTuTcg1yA2KacCOZChKzyoPMNyUIGsazUi2rbLm6FrwaAo+TKyCzec30ugBgjAQGkGI80fTFtztII0twLqT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249160027263.02956660860764; Mon, 14 Jul 2025 04:13:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH78-0007pL-OJ; Mon, 14 Jul 2025 07:13:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyx-0000Yu-CE for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGys-0001Uv-M3 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:26 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-XEY-bza7P0y8Gl5vZlOwig-1; Mon, 14 Jul 2025 07:04:17 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-45526e19f43so10418305e9.3 for ; Mon, 14 Jul 2025 04:04:16 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d785sm12355227f8f.59.2025.07.14.04.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491058; 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=Iz1uX/fPHm96LL/GLvQKBENI0zWW46MxM6ylmWl1pqE=; b=dyveLpKV2gpd7NYI3TNbeFsLXL/yo6Cgr+xum2U0t26MUc4gYMNCZfLXOs4hsIcReVbvhv oszy7dwj/VYXcy1ltmhWoaKGYcwhWN60IZRiG8JXBZuUINlS1vrin7H9IWY0JDyonGRKIz QVfF8fqtkqLWMh4gIXR0WRQyN1P0HiA= X-MC-Unique: XEY-bza7P0y8Gl5vZlOwig-1 X-Mimecast-MFC-AGG-ID: XEY-bza7P0y8Gl5vZlOwig_1752491056 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491055; x=1753095855; 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=Iz1uX/fPHm96LL/GLvQKBENI0zWW46MxM6ylmWl1pqE=; b=pa1N4DWv0SU6nzyCOyyDdhWKdbDzoKE5kwUigFmu705O7s88gUTcVke67aVhhpGXcL r0xKmZ8unQLrqIWiXjbi0tJ6MpzIzALdUnRGWiB1AZHFUgGKVfk/0P1P7iD3o6I9t1jW WEG2zmIE3lbkP3DihsQGZNmlt4w1hJLEvaL2/McEag/ekMJTVXRupr9QU45c0Np+TGM2 QUeZP96Bq0fOsq5FIb1AjXZahqXBZjLEo6MxdooARQzYxVIHf9g4Ktpfo+H4KZcid79G rJVHB+smj7SCeyHyTuwZRSvlZThVhgAZ9tUu/tcbwHTp7V1RyuWqh/veN1m9c/aEFHKE /T9g== X-Gm-Message-State: AOJu0Yzl9+Cej7TTycaA0bpfNkLU/19SbpwgUNVSn1Fi/To/8ctz1HzX RSp7aS2THwqy5pu69j9zAoODn/8rTfGq/YpZpYZIIbuvRe9Ne/O/L/M+QOxnNx6Ina6w6p+0WoW 6S6rY4jcYddvUtXtWk9GaWGs2NyRZlXoCEk4C35JtAZUVfARv6W7ODWHGeLVwLV58VpS8HuwDLS YwhZPUcT17NUMy73/YAJk6KPS2TLsDiCO3S3r8Ewd3 X-Gm-Gg: ASbGncv+VWSJlukC0pXVmiPqSIyjgny5JdMfGLo/UFO5PlQzpnutXbUv8BuleZ41fEv VnQJX13LpkYms8su8bFFKlA5aSbI6pEaPr4NeLYJz8PBofMpk86w2plwEQt1JIwsSOtDYJbBu2d e6559J190Fao9F/so6VIZPC0X81GXrtGnoNb4PvX4TyIr3jJKyxYGhGYHWo0KGOsmEDms6/mYin o1dR1z9FISZGniWx/73oRpTQvPk+X3n7SPUHfdbQl4t0SgnFq5lhgRqw75z0zuZu9WSnfmhFwR5 GOaq/dohdH7FjsOLso5/Hxtxz+iYGX+52MeNP0+gnwE= X-Received: by 2002:a05:600c:821a:b0:456:207e:fd86 with SMTP id 5b1f17b1804b1-456207f008bmr15525845e9.2.1752491054391; Mon, 14 Jul 2025 04:04:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwA7B+PRARDDHe8M7qvyewZTH9ldlNqFXdXmb+qMMgOtnjvXHfGCnl7TC795fk/9tBHt0qiw== X-Received: by 2002:a05:600c:821a:b0:456:207e:fd86 with SMTP id 5b1f17b1804b1-456207f008bmr15525125e9.2.1752491053534; Mon, 14 Jul 2025 04:04:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis Subject: [PULL 02/77] rust/qemu-api-macros: use syn::Error directly Date: Mon, 14 Jul 2025 13:02:51 +0200 Message-ID: <20250714110406.117772-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491602054116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Our MacroError type wraps syn::Error as a variant, and uses another variant for custom errors. Fortunately syn::Error can be used directly, avoiding extra code on our side, so change the proc macro crate to use it. Signed-off-by: Manos Pitsidianakis Link: https://lore.kernel.org/r/20250703-rust_macros-v1-1-b99f82febbbf@lina= ro.org Signed-off-by: Paolo Bonzini --- docs/devel/rust.rst | 11 ++-- rust/qemu-api-macros/src/bits.rs | 58 ++++++++------------- rust/qemu-api-macros/src/lib.rs | 86 +++++++++++++++---------------- rust/qemu-api-macros/src/utils.rs | 26 ---------- 4 files changed, 70 insertions(+), 111 deletions(-) delete mode 100644 rust/qemu-api-macros/src/utils.rs diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index dc8c44109e1..b6737536c69 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -351,7 +351,7 @@ Writing procedural macros ''''''''''''''''''''''''' =20 By conventions, procedural macros are split in two functions, one -returning ``Result`` with the body of +returning ``Result`` with the body of the procedural macro, and the second returning ``proc_macro::TokenStream`` which is the actual procedural macro. The former's name is the same as the latter with the ``_or_error`` suffix. The code for the latter is more @@ -361,18 +361,19 @@ from the type after ``as`` in the invocation of ``par= se_macro_input!``:: #[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= ::into); =20 - TokenStream::from(expanded) + derive_object_or_error(input) + .unwrap_or_else(syn::Error::into_compile_error) + .into() } =20 The ``qemu_api_macros`` crate has utility functions to examine a ``DeriveInput`` and perform common checks (e.g. looking for a struct -with named fields). These functions return ``Result<..., MacroError>`` +with named fields). These functions return ``Result<..., syn::Error>`` and can be used easily in the procedural macro function:: =20 fn derive_object_or_error(input: DeriveInput) -> - Result + Result { is_c_repr(&input, "#[derive(Object)]")?; =20 diff --git a/rust/qemu-api-macros/src/bits.rs b/rust/qemu-api-macros/src/bi= ts.rs index 5ba84757ee0..a80a3b9fee1 100644 --- a/rust/qemu-api-macros/src/bits.rs +++ b/rust/qemu-api-macros/src/bits.rs @@ -6,8 +6,7 @@ use proc_macro2::{ Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree,= TokenTree as TT, }; - -use crate::utils::MacroError; +use syn::Error; =20 pub struct BitsConstInternal { typ: TokenTree, @@ -36,27 +35,21 @@ fn parse_primary( tok: TokenTree, it: &mut dyn Iterator, out: &mut TokenStream, - ) -> Result, MacroError> { + ) -> Result, Error> { let next =3D match tok { TT::Group(ref g) =3D> { if g.delimiter() !=3D Delimiter::Parenthesis && g.delimite= r() !=3D Delimiter::None { - return Err(MacroError::Message("expected parenthesis".= into(), g.span())); + return Err(Error::new(g.span(), "expected parenthesis"= )); } let mut stream =3D g.stream().into_iter(); let Some(first_tok) =3D stream.next() else { - return Err(MacroError::Message( - "expected operand, found ')'".into(), - g.span(), - )); + return Err(Error::new(g.span(), "expected operand, fou= nd ')'")); }; let mut output =3D TokenStream::new(); // start from the lowest precedence let next =3D self.parse_or(first_tok, &mut stream, &mut ou= tput)?; if let Some(tok) =3D next { - return Err(MacroError::Message( - format!("unexpected token {tok}"), - tok.span(), - )); + return Err(Error::new(tok.span(), format!("unexpected = token {tok}"))); } out.extend(Some(paren(output))); it.next() @@ -74,20 +67,17 @@ fn parse_primary( } TT::Punct(ref p) =3D> { if p.as_char() !=3D '!' { - return Err(MacroError::Message("expected operand".into= (), p.span())); + return Err(Error::new(p.span(), "expected operand")); } let Some(rhs_tok) =3D it.next() else { - return Err(MacroError::Message( - "expected operand at end of input".into(), - p.span(), - )); + return Err(Error::new(p.span(), "expected operand at e= nd of input")); }; let next =3D self.parse_primary(rhs_tok, it, out)?; out.extend([punct('.'), ident("invert"), paren(TokenStream= ::new())]); next } _ =3D> { - return Err(MacroError::Message("unexpected literal".into()= , tok.span())); + return Err(Error::new(tok.span(), "unexpected literal")); } }; Ok(next) @@ -99,7 +89,7 @@ fn parse_binop< TokenTree, &mut dyn Iterator, &mut TokenStream, - ) -> Result, MacroError>, + ) -> Result, Error>, >( &self, tok: TokenTree, @@ -108,7 +98,7 @@ fn parse_binop< ch: char, f: F, method: &'static str, - ) -> Result, MacroError> { + ) -> Result, Error> { let mut next =3D f(self, tok, it, out)?; while next.is_some() { let op =3D next.as_ref().unwrap(); @@ -118,10 +108,7 @@ fn parse_binop< } =20 let Some(rhs_tok) =3D it.next() else { - return Err(MacroError::Message( - "expected operand at end of input".into(), - p.span(), - )); + return Err(Error::new(p.span(), "expected operand at end o= f input")); }; let mut rhs =3D TokenStream::new(); next =3D f(self, rhs_tok, it, &mut rhs)?; @@ -136,7 +123,7 @@ pub fn parse_sub( tok: TokenTree, it: &mut dyn Iterator, out: &mut TokenStream, - ) -> Result, MacroError> { + ) -> Result, Error> { self.parse_binop(tok, it, out, '-', Self::parse_primary, "differen= ce") } =20 @@ -146,7 +133,7 @@ fn parse_and( tok: TokenTree, it: &mut dyn Iterator, out: &mut TokenStream, - ) -> Result, MacroError> { + ) -> Result, Error> { self.parse_binop(tok, it, out, '&', Self::parse_sub, "intersection= ") } =20 @@ -156,7 +143,7 @@ fn parse_xor( tok: TokenTree, it: &mut dyn Iterator, out: &mut TokenStream, - ) -> Result, MacroError> { + ) -> Result, Error> { self.parse_binop(tok, it, out, '^', Self::parse_and, "symmetric_di= fference") } =20 @@ -166,13 +153,13 @@ pub fn parse_or( tok: TokenTree, it: &mut dyn Iterator, out: &mut TokenStream, - ) -> Result, MacroError> { + ) -> Result, Error> { self.parse_binop(tok, it, out, '|', Self::parse_xor, "union") } =20 pub fn parse( it: &mut dyn Iterator, - ) -> Result { + ) -> Result { let mut pos =3D Span::call_site(); let mut typ =3D proc_macro2::TokenStream::new(); =20 @@ -198,15 +185,15 @@ pub fn parse( }; =20 let Some(tok) =3D next else { - return Err(MacroError::Message( - "expected expression, do not call this macro directly".int= o(), + return Err(Error::new( pos, + "expected expression, do not call this macro directly", )); }; let TT::Group(ref _group) =3D tok else { - return Err(MacroError::Message( - "expected parenthesis, do not call this macro directly".in= to(), + return Err(Error::new( tok.span(), + "expected parenthesis, do not call this macro directly", )); }; let mut out =3D TokenStream::new(); @@ -219,10 +206,7 @@ pub fn parse( // A parenthesized expression is a single production of the gramma= r, // so the input must have reached the last token. if let Some(tok) =3D next { - return Err(MacroError::Message( - format!("unexpected token {tok}"), - tok.span(), - )); + return Err(Error::new(tok.span(), format!("unexpected token {t= ok}"))); } Ok(out) } diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index c18bb4e036f..2cb79c799a2 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -6,83 +6,79 @@ use quote::quote; use syn::{ parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spann= ed, token::Comma, Data, - DeriveInput, Field, Fields, FieldsUnnamed, Ident, Meta, Path, Token, V= ariant, + DeriveInput, Error, Field, Fields, FieldsUnnamed, Ident, Meta, Path, T= oken, Variant, }; - -mod utils; -use utils::MacroError; - mod bits; use bits::BitsConstInternal; =20 fn get_fields<'a>( input: &'a DeriveInput, msg: &str, -) -> Result<&'a Punctuated, MacroError> { +) -> Result<&'a Punctuated, Error> { let Data::Struct(ref s) =3D &input.data else { - return Err(MacroError::Message( - format!("Struct required for {msg}"), + return Err(Error::new( input.ident.span(), + format!("Struct required for {msg}"), )); }; let Fields::Named(ref fs) =3D &s.fields else { - return Err(MacroError::Message( - format!("Named fields required for {msg}"), + return Err(Error::new( input.ident.span(), + format!("Named fields required for {msg}"), )); }; Ok(&fs.named) } =20 -fn get_unnamed_field<'a>(input: &'a DeriveInput, msg: &str) -> Result<&'a = Field, MacroError> { +fn get_unnamed_field<'a>(input: &'a DeriveInput, msg: &str) -> Result<&'a = Field, Error> { let Data::Struct(ref s) =3D &input.data else { - return Err(MacroError::Message( - format!("Struct required for {msg}"), + return Err(Error::new( input.ident.span(), + format!("Struct required for {msg}"), )); }; let Fields::Unnamed(FieldsUnnamed { ref unnamed, .. }) =3D &s.fields e= lse { - return Err(MacroError::Message( - format!("Tuple struct required for {msg}"), + return Err(Error::new( s.fields.span(), + format!("Tuple struct required for {msg}"), )); }; if unnamed.len() !=3D 1 { - return Err(MacroError::Message( - format!("A single field is required for {msg}"), + return Err(Error::new( s.fields.span(), + format!("A single field is required for {msg}"), )); } Ok(&unnamed[0]) } =20 -fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), MacroError> { +fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), Error> { let expected =3D parse_quote! { #[repr(C)] }; =20 if input.attrs.iter().any(|attr| attr =3D=3D &expected) { Ok(()) } else { - Err(MacroError::Message( - format!("#[repr(C)] required for {msg}"), + Err(Error::new( input.ident.span(), + format!("#[repr(C)] required for {msg}"), )) } } =20 -fn is_transparent_repr(input: &DeriveInput, msg: &str) -> Result<(), Macro= Error> { +fn is_transparent_repr(input: &DeriveInput, msg: &str) -> Result<(), Error= > { let expected =3D parse_quote! { #[repr(transparent)] }; =20 if input.attrs.iter().any(|attr| attr =3D=3D &expected) { Ok(()) } else { - Err(MacroError::Message( - format!("#[repr(transparent)] required for {msg}"), + Err(Error::new( input.ident.span(), + format!("#[repr(transparent)] required for {msg}"), )) } } =20 -fn derive_object_or_error(input: DeriveInput) -> Result { +fn derive_object_or_error(input: DeriveInput) -> Result { is_c_repr(&input, "#[derive(Object)]")?; =20 let name =3D &input.ident; @@ -103,12 +99,13 @@ fn derive_object_or_error(input: DeriveInput) -> Resul= t 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) + derive_object_or_error(input) + .unwrap_or_else(syn::Error::into_compile_error) + .into() } =20 -fn derive_opaque_or_error(input: DeriveInput) -> Result { +fn derive_opaque_or_error(input: DeriveInput) -> Result { is_transparent_repr(&input, "#[derive(Wrapper)]")?; =20 let name =3D &input.ident; @@ -149,13 +146,14 @@ pub const fn raw_get(slot: *mut Self) -> *mut ::Wr #[proc_macro_derive(Wrapper)] pub fn derive_opaque(input: TokenStream) -> TokenStream { let input =3D parse_macro_input!(input as DeriveInput); - let expanded =3D derive_opaque_or_error(input).unwrap_or_else(Into::in= to); =20 - TokenStream::from(expanded) + derive_opaque_or_error(input) + .unwrap_or_else(syn::Error::into_compile_error) + .into() } =20 #[allow(non_snake_case)] -fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result= { +fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result { 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:::= :parse_terminated)?; @@ -170,23 +168,23 @@ fn get_repr_uN(input: &DeriveInput, msg: &str) -> Res= ult { } } =20 - Err(MacroError::Message( - format!("#[repr(u8/u16/u32/u64) required for {msg}"), + Err(Error::new( input.ident.span(), + format!("#[repr(u8/u16/u32/u64) required for {msg}"), )) } =20 -fn get_variants(input: &DeriveInput) -> Result<&Punctuated= , MacroError> { +fn get_variants(input: &DeriveInput) -> Result<&Punctuated= , Error> { let Data::Enum(ref e) =3D &input.data else { - return Err(MacroError::Message( - "Cannot derive TryInto for union or struct.".to_string(), + return Err(Error::new( input.ident.span(), + "Cannot derive TryInto for union or struct.", )); }; if let Some(v) =3D e.variants.iter().find(|v| v.fields !=3D Fields::Un= it) { - return Err(MacroError::Message( - "Cannot derive TryInto for enum with non-unit variants.".to_st= ring(), + return Err(Error::new( v.fields.span(), + "Cannot derive TryInto for enum with non-unit variants.", )); } Ok(&e.variants) @@ -197,7 +195,7 @@ fn derive_tryinto_body( name: &Ident, variants: &Punctuated, repr: &Path, -) -> Result { +) -> Result { let discriminants: Vec<&Ident> =3D variants.iter().map(|f| &f.ident).c= ollect(); =20 Ok(quote! { @@ -210,7 +208,7 @@ fn derive_tryinto_body( } =20 #[rustfmt::skip::macros(quote)] -fn derive_tryinto_or_error(input: DeriveInput) -> Result { +fn derive_tryinto_or_error(input: DeriveInput) -> Result { let repr =3D get_repr_uN(&input, "#[derive(TryInto)]")?; let name =3D &input.ident; let body =3D derive_tryinto_body(name, get_variants(&input)?, &repr)?; @@ -247,9 +245,10 @@ fn try_from(value: #repr) -> Result { #[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); =20 - TokenStream::from(expanded) + derive_tryinto_or_error(input) + .unwrap_or_else(syn::Error::into_compile_error) + .into() } =20 #[proc_macro] @@ -257,6 +256,7 @@ pub fn bits_const_internal(ts: TokenStream) -> TokenStr= eam { let ts =3D proc_macro2::TokenStream::from(ts); let mut it =3D ts.into_iter(); =20 - let expanded =3D BitsConstInternal::parse(&mut it).unwrap_or_else(Into= ::into); - TokenStream::from(expanded) + BitsConstInternal::parse(&mut it) + .unwrap_or_else(syn::Error::into_compile_error) + .into() } diff --git a/rust/qemu-api-macros/src/utils.rs b/rust/qemu-api-macros/src/u= tils.rs deleted file mode 100644 index 02c91aed7f6..00000000000 --- a/rust/qemu-api-macros/src/utils.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Procedural macro utilities. -// Author(s): Paolo Bonzini -// 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 for MacroError { - fn from(err: syn::Error) -> Self { - MacroError::ParseError(err) - } -} - -impl From 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.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491224; cv=none; d=zohomail.com; s=zohoarc; b=C5RiuFBfLEwGeTTMZKiDLkAu4VLy+6oZ91An5YxCNNly7ZrNYcaTAkOO6KeZe52bnNY6RjLR1lbOlSR9Y2h2cYKd1IIG+Yaukwe0Jg6OTUNcjRKpnefKHswSBZwpXVzR+FmhQr32+le6E8iuEe3IYOSZ3C0X8iXeIwNvWs9VNeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491224; 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=667vf6t5S/DRVJXbv1nK/TLEey3e0SHyQWAEBT4VGFU=; b=Mp1pWkXal9StfeqIhIuBPN5+F6iAt37jXZBKLLDTg+kIqhPYOCBOUWj+Oi5o/uP8aOYyqsZcjKk2PersBGlsVe5s4+ukWP+gbmNfysZnK3Qqt5qiRZvGFROo+LpvzCXLs1Ri0Zxnchwg+Zy0nm2HlKA0HTI9PIXoWtj06iwvUlg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491224555902.4441888783622; Mon, 14 Jul 2025 04:07:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH0d-0001X3-8x; Mon, 14 Jul 2025 07:06:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyx-0000Yl-05 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGys-0001VA-Mp for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:26 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-BsZT-daePcyIhRE6hL-uKA-1; Mon, 14 Jul 2025 07:04:17 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4538a2f4212so24419835e9.2 for ; Mon, 14 Jul 2025 04:04:17 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561d19a21dsm19827075e9.24.2025.07.14.04.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491060; 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=667vf6t5S/DRVJXbv1nK/TLEey3e0SHyQWAEBT4VGFU=; b=Vn1STIslWmF1PlI5/MQbjVlBTwDxUBSwxi/y/tgMNjOIk6sTDX1gT1xCIEAzjbTKD1q2ku Kg7qBCRGsWKgQZhxIsl7//4xt38sMSqCbCX8FnifiBM1koHgwMC9UaWnCePQr/mPr6qKg4 Ndw0makRvgbdWz5a7WjJSWIxRwoSHB0= X-MC-Unique: BsZT-daePcyIhRE6hL-uKA-1 X-Mimecast-MFC-AGG-ID: BsZT-daePcyIhRE6hL-uKA_1752491057 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491056; x=1753095856; 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=667vf6t5S/DRVJXbv1nK/TLEey3e0SHyQWAEBT4VGFU=; b=tOIx1iwTO8sqR21wQ7NC4RHm+spJrYrU6VKXMQzHz8Py0nqOLsnSG/9TdOYQZGHfgG yiNveOdZjjT7Z+MZkxPWsNd6U0BtYzbiUMaNtBhu7dsPHK3ejsy5X5Hwp7xHhCcIdEZq y6D/X7DB3Kl/AY6RLzHRIQp9IAfBYefa3lGo+hMdxzCXuXpMZIbu9arO9KwbvKIz0IFc 5gzlARQqyXJOFxr69elg6BTTmLL+VTtXENCdm6t+J3RihhJbySQvlK6WPZvO1NegC3D8 /7ZfapB4+JvXUyq1/B06rv9A46xcsWBmTJho/kESnAzvXJEToXEIlYzNq/EAn2LWx7F8 Li6Q== X-Gm-Message-State: AOJu0YwrmrM4Mf4Fr9NvlPARKK6A87kU1Ye+Y/Ug+vnLB+hV3XIedwD1 kUJbhMGiiVEjX81BGh4SKWcJ988mYshF7WxSH0aX64DIaKjKL0kc8eZB2PtDmIgL126S3P5Jccw Be64VswiE9dBoOqUmkX8gC8wicVnB+ccPKrKpZtBbfLfvHOCE7FjXC+hMmPR333YRAkEI3qkbtL tRbONQyt6WhXVpCKPjvjcxJpJhrIKSGE1lhyAl8a/u X-Gm-Gg: ASbGncvM0NYEAQvKSu7REa9iXY8OijfpP3LQe3jPigA56bnCfoNRwBo6hYOTJav0kGp b4gPgvp6Cm9MS8KH2In8QYHTOUdyWWdVBU8KhTf3wvedZ0MCkgq3B41ArSSsLxlubPBgbVjlZM/ nN4epuj810ChQ1CSRkulSWXFEPeKATrnilCy+uByoF5Nn81U6OF1ZIBOA9Bdftez5G4peC3u03g 40ARQfFFc1HE23qgZUOT7DvViP3fU0Jd8Z9DwNkl9vat6bWPZkCTlghPH2GxL705I4xMb3vG0QU PoXikanJwEcB5kamCBEgwMCESrKmTFFAu5uurZB/CXM= X-Received: by 2002:a05:600c:8b84:b0:450:cabd:160 with SMTP id 5b1f17b1804b1-454f42722a5mr124104255e9.3.1752491055897; Mon, 14 Jul 2025 04:04:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESGHhWjE5RGHheDZpoOGG9ItJcpJ+IT9iQEwtKaRvBuRBbQHltbJRogO3jLz3kt8zqbTgK/w== X-Received: by 2002:a05:600c:8b84:b0:450:cabd:160 with SMTP id 5b1f17b1804b1-454f42722a5mr124103845e9.3.1752491055339; Mon, 14 Jul 2025 04:04:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis Subject: [PULL 03/77] rust/bindings: allow unnecessary_transmutes (1.88) Date: Mon, 14 Jul 2025 13:02:52 +0200 Message-ID: <20250714110406.117772-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491227050116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis This is a new lint introduced in Rust 1.88. It does not affect compilation when using a previous version or our MSRV, 1.77. But with 1.88 compilation fails because we deny all warnings: error: unnecessary transmute --> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:729:18 | 729 | unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize,= 24u8) as u32) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^= ^^^^^^^^^^^^^^ help: replace this with: `u32::cast_signed(self._bitfield_1.= get(0usize, 24u8) as u32)` | =3D note: `-D unnecessary-transmutes` implied by `-D warnings` =3D help: to override `-D warnings` add `#[allow(unnecessary_transmut= es)]` Allow this lint, which even though it does not exist in previous versions, it works because we allow for `unknown_lints` in rust/Cargo.toml. Signed-off-by: Manos Pitsidianakis Link: https://lore.kernel.org/r/20250703-rust_bindings_allow_unnecessary_tr= ansmutes-v1-1-692ca210d331@linaro.org Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/bindings.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs index 057de4b6467..3cdad0f0ec6 100644 --- a/rust/qemu-api/src/bindings.rs +++ b/rust/qemu-api/src/bindings.rs @@ -6,6 +6,7 @@ non_camel_case_types, non_snake_case, non_upper_case_globals, + unnecessary_transmutes, unsafe_op_in_unsafe_fn, clippy::pedantic, clippy::restriction, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491532; cv=none; d=zohomail.com; s=zohoarc; b=auD93tPngudzw2EQzFmqRACR2O3QHhkDH+sedIOFRE2KaXZ69pcjhV0O7tML7370oqnOHT2lV/7U7hCpFlsrkjQ1SzldO3GxgOw8ot3VVvNXC37ShU0k39epy0Tz1Um0Zi0eMfDMs378UHlp/mUd3B6z/s/fsgo3DoHQu25h7d4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491532; 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=pkcK2mp/r9KYf+5t7Za+iWN90GIRah00on6p/UlJAyY=; b=HwvHtaztAGxxwM9S4XPwqsMnft7tzWDTOtwelCUWxzYv4gloazcrFxL+QyUiLOl2/6qR17KrSxaCyaPfmwazciw2azj866NNZkLd2kkDS6iS3Tw/CeWhkTKVcPZT3aR/xZoOL7bHeVrjEsiGLNINAPReZc2BjCWjq0KodE+Nkx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249153274831.552059351161006; Mon, 14 Jul 2025 04:12:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH2m-0003l8-Vo; Mon, 14 Jul 2025 07:08:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyw-0000Yk-VU for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyt-0001VQ-D6 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:25 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-31PKq43aMiG_9LIsXUrfLQ-1; Mon, 14 Jul 2025 07:04:21 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4f3796779so1813760f8f.1 for ; Mon, 14 Jul 2025 04:04:21 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d732sm12320114f8f.52.2025.07.14.04.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491062; 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=pkcK2mp/r9KYf+5t7Za+iWN90GIRah00on6p/UlJAyY=; b=JTGw6UgoAr6qQylAlAYg9T1X1WIzbDJ1qN31EAxbq9b5Pwh9D2SjloDooZHfyuujTGNL6E FEmM+d2d4Px3qpp5kkSY0kjSMApPgGv3ffSA/vkKhyVVMLj+kFAXZMIulMu//sMUFaZbZ4 DG/yuj74p6xBJa7aaB/KUR0zBRENJc0= X-MC-Unique: 31PKq43aMiG_9LIsXUrfLQ-1 X-Mimecast-MFC-AGG-ID: 31PKq43aMiG_9LIsXUrfLQ_1752491060 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491059; x=1753095859; 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=pkcK2mp/r9KYf+5t7Za+iWN90GIRah00on6p/UlJAyY=; b=fXv98u+otcjg5pd7EdRiBCGfqV9wrHicV3QMti9yADRDdhXZ9AHCFiUyi5pnCI1EqU hy3GsQVbx0Vxl9oucjnVuG6ht+6NydEq41mV3mDXyoSTai1okayiIp2St7BSMt/81S8T DRoJCsgfoW+zEVF/wQRb7jOnqm0lCCY3OCrhizttp24ePQhABTbd5Oc3Ky4Vvec1J1iR Dbcl3h9mnMyN3Aa4Urjrv9mz7todJtMW3uEwurgyt4Qm3kEzuiFXvRPoDB5b7nBCmonx 0aXqYX4S1vUGN4B2XOw5lXom690+CEeMMagILxNefeFDepxDWdtxRh7bdirUJrszZcrA uHbw== X-Gm-Message-State: AOJu0YzVDuYezK3illhQv2+h4NOUedOVcOTLLgiGbFk1ANAh+8K7t8mj 5XMuFUZgBM4QA6yMxgfBejVaopzxj7H/LxcUcP8tBzPisEwm/y17AqDA5IvpYoASldj51XqT0ou RNgYDS4w4Ob2bjbP9ZsJj+6OhTjp4Fck+tiH/+rZB+HJ/IPg05gtaIeFAALckSvm/uVpeT/r0RB LDX1YOd72/OAOkJjLVn6CtZ8GPzyE9js3KJ6cbUguz X-Gm-Gg: ASbGncsg9U2CarN8X60u+iDCM8Uvg2ynWS/Yq1UpM4QvQ7HNRjAQ7bKoC/Z4iQ8GXeh KB2hojLUUU+xB9TPlY8IEml0HFaAffiN3YuPrikHFqEHTGuMWZCyI+vDXcx17aZCNOgxIBhxxQG LZ9MeqNjDs/7oa0nxppzcYFakPooftnd1BYK0jSYJMS0nOu9byfjbepZmAOJs5nQiaBBx8jgRov VormLLSiRxTpjkEh++21cVVHIA7evYAh8Dgo9lo8kw2bAGOe1pfJuTaOjHng6sah+gkwjekVpAP fH0daRe/BdcttpBEPIcxBE8LFlvpz6mFYqWTnV7g++U= X-Received: by 2002:adf:9cc3:0:b0:3a4:fe9d:1b10 with SMTP id ffacd0b85a97d-3b5f189c2a8mr10310199f8f.45.1752491059327; Mon, 14 Jul 2025 04:04:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfsUz1OocMJPypWDY8fsShkos63HbK5Air1Cf7vEnUp60fxSY8t88dUGkt83e/PyOHgeqDQA== X-Received: by 2002:adf:9cc3:0:b0:3a4:fe9d:1b10 with SMTP id ffacd0b85a97d-3b5f189c2a8mr10310155f8f.45.1752491058543; Mon, 14 Jul 2025 04:04:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Zhao Liu Subject: [PULL 04/77] rust/qemu-api-macros: normalize TryInto output Date: Mon, 14 Jul 2025 13:02:53 +0200 Message-ID: <20250714110406.117772-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491534954116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Remove extraneous `;` and add missing trailing comma to TryInto derive macro to match rustfmt style. We will add a test in the followup commit and we would like the inlined output in the test body to be properly formatted as well. No functional changes intended. Signed-off-by: Manos Pitsidianakis Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250704-rust_add_derive_macro_unit_tests-v= 1-1-ebd47fa7f78f@linaro.org Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 2cb79c799a2..5bbf8c6127a 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -199,7 +199,7 @@ fn derive_tryinto_body( let discriminants: Vec<&Ident> =3D variants.iter().map(|f| &f.ident).c= ollect(); =20 Ok(quote! { - #(const #discriminants: #repr =3D #name::#discriminants as #repr;)= *; + #(const #discriminants: #repr =3D #name::#discriminants as #repr;)* match value { #(#discriminants =3D> core::result::Result::Ok(#name::#discrim= inants),)* _ =3D> core::result::Result::Err(value), @@ -227,7 +227,7 @@ pub const fn from_bits(value: #repr) -> Self { #body }) { Ok(x) =3D> x, - Err(_) =3D> panic!(#errmsg) + Err(_) =3D> panic!(#errmsg), } } } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491258; cv=none; d=zohomail.com; s=zohoarc; b=bv9yRlQcraMl6DAJcR+BSPan1cD/FxD3iEu+xtbO0rMGGcBfdHiBMPTl3xZCvY6P4ieky5A4eq4yFgUc33DHmRJUpqZg+gJsNJ8hOlUGOtOZMdh1YrzBLC48mkskvycCTXj3CGSwdB9DS/oz4IPqonFcVtJm9ib6XQIH2Cdobrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491258; 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=RDS1zp/SwwPVp8w2l7aZW0s5Crk2/t5eywReYfE5geg=; b=c2aLEkjTAlWSpQF8/iFDE/DEdo0yc7nTQ0lyhrIt2PPW5yx5tvBQhaH4X2ZnYahrcgoNhojNeTHEbHiWFdYLjhozFPqyIGgODPKokeTxe6XY8PL8743GZhqXjCirl39m2vr0a3BWpNYdzGeTnbCWM/d7u21OQyJtVbNYvXqPAxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491258146592.0594257354446; Mon, 14 Jul 2025 04:07:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH1k-00023Z-JU; Mon, 14 Jul 2025 07:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz2-0000ao-7R for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyz-0001W7-Uw for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:31 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-201-SGLeucC_Ol-S6dHzfOXDCQ-1; Mon, 14 Jul 2025 07:04:24 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-454dee17a91so31527355e9.3 for ; Mon, 14 Jul 2025 04:04:24 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45610a39cacsm53519445e9.38.2025.07.14.04.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491066; 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=RDS1zp/SwwPVp8w2l7aZW0s5Crk2/t5eywReYfE5geg=; b=eBAghy4xe+ImXs2QN+t4KaIQYy4Si6YasB9tUw8iDl+sbRqjAoTEEiVwwgzrS7FNPAkExr s/SJdjK03fSAignLw9Xqn0V80csRavegmLQofxeiO4ZHDALvoOjTQxm4gppjPcU//V3Xjl eFFU4U3Y/zkS74QSngEwXHPFtel9RM4= X-MC-Unique: SGLeucC_Ol-S6dHzfOXDCQ-1 X-Mimecast-MFC-AGG-ID: SGLeucC_Ol-S6dHzfOXDCQ_1752491063 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491062; x=1753095862; 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=RDS1zp/SwwPVp8w2l7aZW0s5Crk2/t5eywReYfE5geg=; b=dgQ8c36EA8Gyx0kwC5mvV+Oe3vERIEUmnbidcdnnuM+KlOD1clOKTjOEk1KiqK5iRp ro8bSsljKIb3L43jFEIGC4JivEyYPRvnRLbcQoPQAz1RYMpCjveev0iLSHsJSeDHJYid TpmTmUGf+JBbIC7iDx++1UYLfTiLOHBoskzdgGhM9/0Iq0z3AXIKx95HokZxUuaL03J4 I+voWdCzZdplP3+bGEQ7Bwf+DR6JCd6dQVlBd7emLhzXLrtsCFx+isd3ptMKHKOzjktk ivkc3XNj8AJAKox0Qu1byEckAGPVWYp5c+dLB3wXF1jPMxelzEYXGb+CBIxTjJEY/fwS Gh+g== X-Gm-Message-State: AOJu0Yy0sVVVM2MMjvvqYgNZbTDK06vnkSBneQMusEgeU2eRt0l55G3+ 49Odpw+TSM2CRsPnwldeMjLqd4CIARhBzigaIlPGLzFT1EvS0eF6JOE5tsP8YuSI5Rfg7Phfh8J /A4DMuYd8UNZ7hBQZrAAWWYErcOFStSJiaRyLzoGmiJ2fHBZYRCcJQKDjdSugnSqhkX1XW/SPE3 Iuq2ylJ8NQDaVcxyuexexdAYli2ZEjIpXmEcyI/A4E X-Gm-Gg: ASbGncuNvt7KprQIYOsQDsIDbePENbGQ+HwMOAkQ11KZ8uxs7aZuNj8vb+UNnSE1NrB hMyo2PIBu+X0WzfEYtvHsbZ4DYknNjbLQaDrrSx2Ewr3aYex0j13oDi9CnXPvd8Th5GdFZHXnFz ff7CAyxICN1cIIAysZpPDoTUzFwrjD6IebU1vruoo0X0eItSuHjaK4LdXkVOLnUVSErwuy9LsFH 0QZBdmSOXeNwfidNVNdci5dH5aa/eFYfK+8rHQZNIRNNPG6lzYmZcepX0YN9Ive8NZb34xyd0MO yiY9sVqv59tbgmg/9SbvIJDASdW0nbSjGqZ/JvKzBkE= X-Received: by 2002:a05:600c:3595:b0:442:f8e7:25ef with SMTP id 5b1f17b1804b1-454ec15e5c5mr111456565e9.11.1752491062410; Mon, 14 Jul 2025 04:04:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtWbRwlvJqz7wRRBBOV5YBvPuCuEhlSNW7ZU7HRTaB6UIJUfAL9CUMrnkI0nPLPMtb0jw9Rg== X-Received: by 2002:a05:600c:3595:b0:442:f8e7:25ef with SMTP id 5b1f17b1804b1-454ec15e5c5mr111456145e9.11.1752491061592; Mon, 14 Jul 2025 04:04:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Zhao Liu Subject: [PULL 05/77] rust/qemu-api-macros: add unit tests Date: Mon, 14 Jul 2025 13:02:54 +0200 Message-ID: <20250714110406.117772-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491261922116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Add unit tests to check Derive macro output for expected error messages, or for expected correct codegen output. Signed-off-by: Manos Pitsidianakis Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250704-rust_add_derive_macro_unit_tests-v= 1-2-ebd47fa7f78f@linaro.org [Remove usage of MacroError. - Paolo] Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/meson.build | 3 + rust/qemu-api-macros/src/lib.rs | 3 + rust/qemu-api-macros/src/tests.rs | 137 ++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 rust/qemu-api-macros/src/tests.rs diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.= build index 8610ce1c844..2152bcb99b3 100644 --- a/rust/qemu-api-macros/meson.build +++ b/rust/qemu-api-macros/meson.build @@ -17,3 +17,6 @@ _qemu_api_macros_rs =3D rust.proc_macro( qemu_api_macros =3D declare_dependency( link_with: _qemu_api_macros_rs, ) + +rust.test('rust-qemu-api-macros-tests', _qemu_api_macros_rs, + suite: ['unit', 'rust']) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 5bbf8c6127a..b525d89c09e 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -11,6 +11,9 @@ mod bits; use bits::BitsConstInternal; =20 +#[cfg(test)] +mod tests; + fn get_fields<'a>( input: &'a DeriveInput, msg: &str, diff --git a/rust/qemu-api-macros/src/tests.rs b/rust/qemu-api-macros/src/t= ests.rs new file mode 100644 index 00000000000..d6dcd62fcf6 --- /dev/null +++ b/rust/qemu-api-macros/src/tests.rs @@ -0,0 +1,137 @@ +// Copyright 2025, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use quote::quote; + +use super::*; + +macro_rules! derive_compile_fail { + ($derive_fn:ident, $input:expr, $error_msg:expr) =3D> {{ + let input: proc_macro2::TokenStream =3D $input; + let error_msg: &str =3D $error_msg; + let derive_fn: fn(input: syn::DeriveInput) -> Result =3D + $derive_fn; + + let input: syn::DeriveInput =3D syn::parse2(input).unwrap(); + let result =3D derive_fn(input); + let err =3D result.unwrap_err().into_compile_error(); + assert_eq!( + err.to_string(), + quote! { ::core::compile_error! { #error_msg } }.to_string() + ); + }}; +} + +macro_rules! derive_compile { + ($derive_fn:ident, $input:expr, $($expected:tt)*) =3D> {{ + let input: proc_macro2::TokenStream =3D $input; + let expected: proc_macro2::TokenStream =3D $($expected)*; + let derive_fn: fn(input: syn::DeriveInput) -> Result =3D + $derive_fn; + + let input: syn::DeriveInput =3D syn::parse2(input).unwrap(); + let result =3D derive_fn(input).unwrap(); + assert_eq!(result.to_string(), expected.to_string()); + }}; +} + +#[test] +fn test_derive_object() { + derive_compile_fail!( + derive_object_or_error, + quote! { + #[derive(Object)] + struct Foo { + _unused: [u8; 0], + } + }, + "#[repr(C)] required for #[derive(Object)]" + ); + derive_compile!( + derive_object_or_error, + quote! { + #[derive(Object)] + #[repr(C)] + struct Foo { + _unused: [u8; 0], + } + }, + quote! { + ::qemu_api::assert_field_type!( + Foo, + _unused, + ::qemu_api::qom::ParentField<::ParentType> + ); + ::qemu_api::module_init! { + MODULE_INIT_QOM =3D> unsafe { + ::qemu_api::bindings::type_register_static(&::TYPE_INFO); + } + } + } + ); +} + +#[test] +fn test_derive_tryinto() { + derive_compile_fail!( + derive_tryinto_or_error, + quote! { + #[derive(TryInto)] + struct Foo { + _unused: [u8; 0], + } + }, + "#[repr(u8/u16/u32/u64) required for #[derive(TryInto)]" + ); + derive_compile!( + derive_tryinto_or_error, + quote! { + #[derive(TryInto)] + #[repr(u8)] + enum Foo { + First =3D 0, + Second, + } + }, + quote! { + impl Foo { + #[allow(dead_code)] + pub const fn into_bits(self) -> u8 { + self as u8 + } + + #[allow(dead_code)] + pub const fn from_bits(value: u8) -> Self { + match ({ + const First: u8 =3D Foo::First as u8; + const Second: u8 =3D Foo::Second as u8; + match value { + First =3D> core::result::Result::Ok(Foo::First= ), + Second =3D> core::result::Result::Ok(Foo::Seco= nd), + _ =3D> core::result::Result::Err(value), + } + }) { + Ok(x) =3D> x, + Err(_) =3D> panic!("invalid value for Foo"), + } + } + } + + impl core::convert::TryFrom for Foo { + type Error =3D u8; + + #[allow(ambiguous_associated_items)] + fn try_from(value: u8) -> Result { + const First: u8 =3D Foo::First as u8; + const Second: u8 =3D Foo::Second as u8; + match value { + First =3D> core::result::Result::Ok(Foo::First), + Second =3D> core::result::Result::Ok(Foo::Second), + _ =3D> core::result::Result::Err(value), + } + } + } + } + ); +} --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492059; cv=none; d=zohomail.com; s=zohoarc; b=PAw+UDe9ToDXqe5IhF9YRapZe1em5btKWaaTRnQe39rhX/J3pvxgo3HSIpOpVnPojjkWzSoWltVxvTCJ2iGEHdys5ufaM4xfgxHLZLPQnyDfEtp3fuOc4RtqxI57H4zUkQ1vWalMqtW8SSSeu1NLFbcM9PXNquX2p+w2fKhZ658= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492059; 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=MhCvQkGWRngHOw7qyfN17pVt/8jmU8Gd43OpCo3NXd4=; b=Hi487lexdM+hMBzxMXIUabHl2pX52VHMS45F9o7+109PWvnqejvvDBl06ujt0hwnsiDT0CksjFWrtPSUJvZ+YXu7zbamJMsOHt5+6Wb6ihXUu1t3U/yazTdMbfa7NT+jTjf+nZ49Sr55MD0MLmDl6qi/ZiwlzkewQtdkXNFKPyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492059031910.361206882128; Mon, 14 Jul 2025 04:20:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEM-00079S-Gr; Mon, 14 Jul 2025 07:20:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz6-0000bo-Bz for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGyz-0001XI-Rh for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:33 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-JEdMMTU0PUmIXesd-uyh8g-1; Mon, 14 Jul 2025 07:04:27 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4f6ba526eso2170451f8f.1 for ; Mon, 14 Jul 2025 04:04:27 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc217esm11772335f8f.28.2025.07.14.04.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491068; 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=MhCvQkGWRngHOw7qyfN17pVt/8jmU8Gd43OpCo3NXd4=; b=Bc+BnJ5qRVlQ0D2LQFGWzR962XlWpk4H54Ks+dPojWBk3xK1O71rGjtBDoPa3oXO+MQFjw YMVwNvVOpxSL+i5pL5RTMUnQQzt3CgT+7UFilRKACOUFoDk/LlTF3mwVfRpLcjaH0F64Hr IRrk21/zoQT+cq8ZjpyDUuWqk1NvF2M= X-MC-Unique: JEdMMTU0PUmIXesd-uyh8g-1 X-Mimecast-MFC-AGG-ID: JEdMMTU0PUmIXesd-uyh8g_1752491066 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491066; x=1753095866; 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=MhCvQkGWRngHOw7qyfN17pVt/8jmU8Gd43OpCo3NXd4=; b=BQ3+mxrJodWbCQ6LJDjttKikVXK7JVlSO8xTKU6YxmzPqRUuAmfGR951SCOYOGWr+u J5KO341NJWE7LQOieR2a6Bk84L1iS/c9q7Co0Fk/j8GrHy6rDMM0qYcldTe3QgZDKl0P ILNrr3tB8Fy0woWyec3oMS93RKO6qpzNuT6rZzJuevHJWSEI1ryiUH5smEkAZXaC3BU6 krwiPEOJFiDFmmauDp1UMCuIQuT/n9A80kvgWjGYrhFD7XQNXUyx3yS0Zzy6QK+cgoW3 ISucHk7r/4ynfSVJlvDDlzBPKY2u6JGaFg3UyWHOc1qRz4JgktuNavbl50N3aCMGan6F y9kQ== X-Gm-Message-State: AOJu0YxudkPaMgC/1L2HdHABlIYIu+HxL7hGzdHUpnN3MQZCYF14ZS+3 rXNWVhi+/plHATJaV41UmDlpLI+0eSLDMUNRD108unqIldz5sCNUyACniWVZNXm2frXV08UmTut kafkO1Vi0P6PUEcaYdxj8v8dg4mJbb7jS1IfAXE6pil32gcKeZ60B7ZHEKxgTToLqOXNedysOGD W23vhPK00wx5+FXH2WnGg4SdbHksrh4o6TAM24vWuS X-Gm-Gg: ASbGncu0ZvpN9Dh8jw25UFiEd57ZxyyMCl53nh/KzDdGPmYk4MlfsKEqfON4SmBsBfy GM9HfD+k9JnzLDQdMDi2frtJ3qu9/3soEat5f4DTpigsHmxt4sEG+LyYll/w6nIl/gRUiQwLpJz g9lzFgLJUc8mQfk+FHULr8N406+PQDN+efavIyv/Jpr5PyrUXjOgVhk8x7SYMmz39EnTfGcJKaJ 7EskocEKUXkVJCas3w9D94XIxchSyvDgu9zj/IzMCp2VhI01CvxokwjtdDayPUC0sN1iHUeIE0H iLCPowBzjKwQt6K0oh43/KojKfqGYNLWYC1tHim7xx0= X-Received: by 2002:a05:6000:26cc:b0:3a4:efbb:6df3 with SMTP id ffacd0b85a97d-3b5f187d0b9mr10639573f8f.10.1752491065360; Mon, 14 Jul 2025 04:04:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwASem7VyqV+rh7WcIhESOBDMZh37ODncYUmljd8Qc0UQf307ScSVoht8kt9qXGtOTPx/+YA== X-Received: by 2002:a05:6000:26cc:b0:3a4:efbb:6df3 with SMTP id ffacd0b85a97d-3b5f187d0b9mr10639536f8f.10.1752491064751; Mon, 14 Jul 2025 04:04:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Manos Pitsidianakis Subject: [PULL 06/77] rust/qemu-api: log: implement io::Write Date: Mon, 14 Jul 2025 13:02:55 +0200 Message-ID: <20250714110406.117772-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492061238116600 Content-Type: text/plain; charset="utf-8" This makes it possible to lock the log file; it also makes log_mask_ln! not allocate memory when logging a constant string. Reviewed-by: Zhao Liu Reviewed-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini --- include/qemu/log.h | 2 + util/log.c | 12 ++++++ rust/qemu-api/src/log.rs | 92 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index 60da703e670..aae72985f0d 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -84,6 +84,8 @@ typedef struct QEMULogItem { =20 extern const QEMULogItem qemu_log_items[]; =20 +ssize_t rust_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stre= am); + bool qemu_set_log(int log_flags, Error **errp); bool qemu_set_log_filename(const char *filename, Error **errp); bool qemu_set_log_filename_flags(const char *name, int flags, Error **errp= ); diff --git a/util/log.c b/util/log.c index b87d399e4cb..58d24de48a0 100644 --- a/util/log.c +++ b/util/log.c @@ -558,3 +558,15 @@ void qemu_print_log_usage(FILE *f) fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n= "); #endif } + +#ifdef CONFIG_HAVE_RUST +ssize_t rust_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stre= am) +{ + /* + * Same as fwrite, but return -errno because Rust libc does not provide + * portable access to errno. :( + */ + int ret =3D fwrite(ptr, size, nmemb, stream); + return ret < 0 ? -errno : 0; +} +#endif diff --git a/rust/qemu-api/src/log.rs b/rust/qemu-api/src/log.rs index d6c3d6c1b63..a441b8c1f2e 100644 --- a/rust/qemu-api/src/log.rs +++ b/rust/qemu-api/src/log.rs @@ -3,6 +3,13 @@ =20 //! Bindings for QEMU's logging infrastructure =20 +use std::{ + io::{self, Write}, + ptr::NonNull, +}; + +use crate::{bindings, errno}; + #[repr(u32)] /// Represents specific error categories within QEMU's logging system. /// @@ -11,11 +18,82 @@ pub enum Log { /// Log invalid access caused by the guest. /// Corresponds to `LOG_GUEST_ERROR` in the C implementation. - GuestError =3D crate::bindings::LOG_GUEST_ERROR, + GuestError =3D bindings::LOG_GUEST_ERROR, =20 /// Log guest access of unimplemented functionality. /// Corresponds to `LOG_UNIMP` in the C implementation. - Unimp =3D crate::bindings::LOG_UNIMP, + Unimp =3D bindings::LOG_UNIMP, +} + +/// A RAII guard for QEMU's logging infrastructure. Creating the guard +/// locks the log file, and dropping it (letting it go out of scope) unloc= ks +/// the file. +/// +/// As long as the guard lives, it can be written to using [`std::io::Writ= e`]. +/// +/// The locking is recursive, therefore owning a guard does not prevent +/// using [`log_mask_ln!()`](crate::log_mask_ln). +pub struct LogGuard(NonNull); + +impl LogGuard { + /// Return a RAII guard that writes to QEMU's logging infrastructure. + /// The log file is locked while the guard exists, ensuring that there + /// is no tearing of the messages. + /// + /// Return `None` if the log file is closed and could not be opened. + /// Do *not* use `unwrap()` on the result; failure can be handled simp= ly + /// by not logging anything. + /// + /// # Examples + /// + /// ``` + /// # use qemu_api::log::LogGuard; + /// # use std::io::Write; + /// if let Some(mut log) =3D LogGuard::new() { + /// writeln!(log, "test"); + /// } + /// ``` + pub fn new() -> Option { + let f =3D unsafe { bindings::qemu_log_trylock() }.cast(); + NonNull::new(f).map(Self) + } + + /// Writes a formatted string into the log, returning any error encoun= tered. + /// + /// This method is primarily used by the + /// [`log_mask_ln!()`](crate::log_mask_ln) macro, and it is rare for it + /// to be called explicitly. It is public because it is the only way = to + /// examine the error, which `log_mask_ln!()` ignores + /// + /// Unlike `log_mask_ln!()`, it does *not* append a newline at the end. + pub fn log_fmt(args: std::fmt::Arguments) -> io::Result<()> { + if let Some(mut log) =3D Self::new() { + log.write_fmt(args)?; + } + Ok(()) + } +} + +impl Write for LogGuard { + fn write(&mut self, bytes: &[u8]) -> io::Result { + let ret =3D unsafe { + bindings::rust_fwrite(bytes.as_ptr().cast(), 1, bytes.len(), s= elf.0.as_ptr()) + }; + errno::into_io_result(ret) + } + + fn flush(&mut self) -> io::Result<()> { + // Do nothing, dropping the guard takes care of flushing + Ok(()) + } +} + +impl Drop for LogGuard { + fn drop(&mut self) { + unsafe { + bindings::qemu_log_unlock(self.0.as_ptr()); + } + } } =20 /// A macro to log messages conditionally based on a provided mask. @@ -24,6 +102,8 @@ pub enum Log { /// log level and, if so, formats and logs the message. It is the Rust /// counterpart of the `qemu_log_mask()` macro in the C implementation. /// +/// Errors from writing to the log are ignored. +/// /// # Parameters /// /// - `$mask`: A log level mask. This should be a variant of the `Log` enu= m. @@ -62,12 +142,8 @@ macro_rules! log_mask_ln { if unsafe { (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw:= :c_int)) !=3D 0 } { - let formatted_string =3D format!("{}\n", format_args!($fmt $($= args)*)); - let c_string =3D std::ffi::CString::new(formatted_string).unwr= ap(); - - unsafe { - ::qemu_api::bindings::qemu_log(c_string.as_ptr()); - } + _ =3D ::qemu_api::log::LogGuard::log_fmt( + format_args!("{}\n", format_args!($fmt $($args)*))); } }}; } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491611; cv=none; d=zohomail.com; s=zohoarc; b=DxwqxjosxIFFp2zv04Gl98iEFMKdeXcwMZkgpVaQUkPe+R+lNTOZvwGEUSeCiaNiLIWs4+CfA4bRGNiFwvyO2z2kxIUWd7WWolE63oCU3P9s6GT/iVbIH/0O6qR17MzbihCvBYlsGVwZ9nuq+jGUsBHZ5zkEjV0oG8Nj917P8xM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491611; 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=hCVHCI24r7fBMBEIXiJinu8XMfmmZF1IzGCvCSdEy6k=; b=BB3S7WCQ7SaNybSCTQ4QvUdlsK2Zg1EaihwblT2n7YRHmoScqgR9ffpE1XhwjhqYsuWyBJbE98U0/P+R5xAup8a0VWfAnBQlJ+UUNL7RZbPCF6KVNDlhfKocNLsiDYV6ipKVD9g4VGu6kKsZEzLNsSRcAGSJheaWLquvWZM6NxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491611044390.6846645516006; Mon, 14 Jul 2025 04:13:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH6X-0007XK-F6; Mon, 14 Jul 2025 07:12:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz6-0000bn-BG for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz2-0001Xx-HR for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:34 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-zWg07cboOXWk8X5a-eBUWQ-1; Mon, 14 Jul 2025 07:04:30 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a5058f9ef4so1738564f8f.2 for ; Mon, 14 Jul 2025 04:04:30 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d719sm12234549f8f.54.2025.07.14.04.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491071; 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=hCVHCI24r7fBMBEIXiJinu8XMfmmZF1IzGCvCSdEy6k=; b=WM/5p36stv2m4IhmvEEus+IeX7sCHb4Njaqvn1vpbHWXcnRlQEja8hc9m7gQDhKgnlHY1M Ay7x/hR7MHT0lKw3IQ4PVZbyy/eiyDLMv63utQKjRaG44L/aU/epq6PI43NnstQPPLicr6 aan6s8kEAQmhPXwHYCSZN/gYbLd3nQU= X-MC-Unique: zWg07cboOXWk8X5a-eBUWQ-1 X-Mimecast-MFC-AGG-ID: zWg07cboOXWk8X5a-eBUWQ_1752491069 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491069; x=1753095869; 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=hCVHCI24r7fBMBEIXiJinu8XMfmmZF1IzGCvCSdEy6k=; b=AVQBAsK1bMbE1mhELZ1CzDxSMR11hb3kf92ld91xkLKxji/1HMa3e+LITPKTGs42Qz o5O+l8up7WRH4e53hAuBc/rYKJexDIk0xdhgwcCvkiEgheCNYi0DCX7k775AQiBNAmSa IO69wLsv3IMjphMxbuhw8/Eakzb+IpMjqAvL1dNZeN5/Sg1ItIATBAwq8p07ItG9DXCa HJ0u2EFw28mHPygAxNPIn51vrKvUcfTvx9VrC1jtPAxOkFFXjhJWHLHNaFZaDxzmj6Zk OE80V95RsUH9UsRqPxQV0a6ASAHMCr+YFq3hMnQktrQBitS6jOZ91kE6emrLZTZHz1Pu qMvw== X-Gm-Message-State: AOJu0YyvX8EDPkfOM0Y+bkRSYGDNqS2iwHGgvuGQIbpoVwp1HHz9sBzg +B/ludvWL9wDMgyIaEfX208Fwma1JVHDP6qujNLh835xgJy1qLE5OFNsfaJCqokrw0oRdtsRJXg p0vu7PsZLTlVunUOv5A8UI6c73KtkFSg/falaGAraDCQl3NqsKnuwDt7EbVE+EzYv2OsgP4CVCj /qxJbh6t61XvtGIJ7UiT2iLZDhOlySZ08AYdmsY0cT X-Gm-Gg: ASbGnct93Di08g5//FOPBu9ep+ryrsWBZ03wQaKDRsAi0zfn2IDkSn8+WnDZovrxx31 BI6GAmJuSvzzr2fa+mYYm8jgJ+EIyPTybrRRgIlhR5vg9LSlcH+vkq3RKQ5OLmh+dCstF5j1/3L XsA5L1GSABu8K/c7vgmkZOSaHDtDqM4UjfW8sn7vEoB4E3+TnBlrTBSMHH6s7vQ+DK/0iDETjZa Wnqc/2AB8h2Z3SsqHephXEbuWylrs/zNbrK4EyBws5RdW4fg4/STJlQkAFvngCbWpCmjBKwMPg4 JdPU21iCfC1995a86kSfkNsxKq2YqaaLVMXWDJsr7SE= X-Received: by 2002:a05:6000:4310:b0:3b3:a6c2:1a10 with SMTP id ffacd0b85a97d-3b5f351eb04mr9261869f8f.12.1752491068660; Mon, 14 Jul 2025 04:04:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8qBmASoRtbGGlek/AkqVmkwOsFPxJLjOTn+ZdCoWlqVIc1BAPJGvHrLizNX/jTjhEGQowAA== X-Received: by 2002:a05:6000:4310:b0:3b3:a6c2:1a10 with SMTP id ffacd0b85a97d-3b5f351eb04mr9261827f8f.12.1752491068056; Mon, 14 Jul 2025 04:04:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , Zhao Liu Subject: [PULL 07/77] target/i386: move max_features to class Date: Mon, 14 Jul 2025 13:02:56 +0200 Message-ID: <20250714110406.117772-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491611827116600 Content-Type: text/plain; charset="utf-8" max_features is always set to true for instances created by -cpu max or -cpu host; it's always false for other classes. Therefore it can be turned into a field in the X86CPUClass. Reviewed-by: Xiaoyao Li Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 2 +- target/i386/cpu.c | 7 ++++--- target/i386/hvf/hvf-cpu.c | 3 ++- target/i386/kvm/kvm-cpu.c | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 51e10139dfd..be3ae6d546e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2196,7 +2196,6 @@ struct ArchCPU { bool expose_tcg; bool migratable; bool migrate_smi_count; - bool max_features; /* Enable all supported features automatically */ uint32_t apic_id; =20 /* Enables publishing of TSC increment and Local APIC bus frequencies = to @@ -2349,6 +2348,7 @@ struct X86CPUClass { */ const X86CPUModel *model; =20 + bool max_features; /* Enable all supported features automatically */ bool host_cpuid_required; int ordering; bool migration_safe; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0d35e95430f..4d4e5234246 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6187,6 +6187,7 @@ static void max_x86_cpu_class_init(ObjectClass *oc, c= onst void *data) =20 xcc->ordering =3D 9; =20 + xcc->max_features =3D true; xcc->model_description =3D "Enables all features supported by the accelerator in the current = host"; =20 @@ -6201,7 +6202,6 @@ static void max_x86_cpu_initfn(Object *obj) /* We can't fill the features array here because we don't know yet if * "migratable" is true or false. */ - cpu->max_features =3D true; object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort); =20 /* @@ -8282,6 +8282,7 @@ static void x86_cpu_enable_xsave_components(X86CPU *c= pu) */ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) { + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); CPUX86State *env =3D &cpu->env; FeatureWord w; int i; @@ -8301,12 +8302,12 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **e= rrp) } } =20 - /*TODO: Now cpu->max_features doesn't overwrite features + /* TODO: Now xcc->max_features doesn't overwrite features * set using QOM properties, and we can convert * plus_features & minus_features to global properties * inside x86_cpu_parse_featurestr() too. */ - if (cpu->max_features) { + if (xcc->max_features) { for (w =3D 0; w < FEATURE_WORDS; w++) { /* Override only features that weren't set explicitly * by the user. diff --git a/target/i386/hvf/hvf-cpu.c b/target/i386/hvf/hvf-cpu.c index dfdda701268..2b991f2fc8e 100644 --- a/target/i386/hvf/hvf-cpu.c +++ b/target/i386/hvf/hvf-cpu.c @@ -61,13 +61,14 @@ static void hvf_cpu_xsave_init(void) static void hvf_cpu_instance_init(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); =20 host_cpu_instance_init(cpu); =20 /* Special cases not set in the X86CPUDefinition structs: */ /* TODO: in-kernel irqchip for hvf */ =20 - if (cpu->max_features) { + if (xcc->max_features) { hvf_cpu_max_instance_init(cpu); } =20 diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 16bde4de01e..0fb88a239d4 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -41,6 +41,7 @@ static void kvm_set_guest_phys_bits(CPUState *cs) static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); CPUX86State *env =3D &cpu->env; bool ret; =20 @@ -63,7 +64,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) * check/update ucode_rev, phys_bits, guest_phys_bits, mwait * cpu_common_realizefn() (via xcc->parent_realize) */ - if (cpu->max_features) { + if (xcc->max_features) { if (enable_cpu_pm) { if (kvm_has_waitpkg()) { env->features[FEAT_7_0_ECX] |=3D CPUID_7_0_ECX_WAITPKG; @@ -216,7 +217,7 @@ static void kvm_cpu_instance_init(CPUState *cs) x86_cpu_apply_props(cpu, kvm_default_props); } =20 - if (cpu->max_features) { + if (xcc->max_features) { kvm_cpu_max_instance_init(cpu); } =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492049; cv=none; d=zohomail.com; s=zohoarc; b=SGxF+MqBW80KgQdol1KzdFBY4CzE30chZHiS57JBpr9fxBBMOz44bOBCIh+KhA5zkyG/D38VtAMysYO80Mbcc69NQSplpLWlyOOVjHwCz3TT0km0Bufbl/z68cYTIFjh6UGad3DTvICKgaXw6LwbOmPnDnqs2rh2Lsy1mMFFj98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492049; 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=+3x4MUcqLXlcLNlNqAnlK7RqHXSqmeDVXTbJiZ/Tc8c=; b=e7quicSJDwvRFOzC3dguMkllgzoNECeiDu9NjcpNANNU1iODJzhsceGlfIl5ggFyHwR2LrxGXxlpX9+Lh9IFZjrThEC6zna/R8XN8Hecf5o54vqNgQfbcWNa+Pve+zcOt7P46cJBPHDqPoe/nYAGxdtE9piWZ5bq2pf/5ZgaIP0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492049937810.1057804085359; Mon, 14 Jul 2025 04:20:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEU-0007qc-Vi; Mon, 14 Jul 2025 07:20:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzD-0000da-Dx for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGz6-0001YN-Jn for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:39 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-dc4gQr8QO66R0gGQvkbs4Q-1; Mon, 14 Jul 2025 07:04:34 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3b5fe97af5fso421125f8f.2 for ; Mon, 14 Jul 2025 04:04:34 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc91d8sm11906809f8f.42.2025.07.14.04.04.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491075; 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=+3x4MUcqLXlcLNlNqAnlK7RqHXSqmeDVXTbJiZ/Tc8c=; b=bozquUh0W5wquILfB/+jhwqn+DMe72skEgRpEIPUpimLN4uMPqCtahedCgpxIrqiaRUiTx XoNZwHClWS98LG1r5b+Q/zif3uoQGzeUppf+WDyWKMrp45bk96ZSJoU95Bly02LcqED2qY K0p77Tf8oD6VDgvXKTCv4/iQaZAmuSY= X-MC-Unique: dc4gQr8QO66R0gGQvkbs4Q-1 X-Mimecast-MFC-AGG-ID: dc4gQr8QO66R0gGQvkbs4Q_1752491073 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491073; x=1753095873; 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=+3x4MUcqLXlcLNlNqAnlK7RqHXSqmeDVXTbJiZ/Tc8c=; b=dhPefBYqdG45GsuOCkEs8tglUTLPcTfrF0DXPkW4jxsZu5dbFlKLeloudnqgOg6/sC yaeZG+B6Zj3Z79EarNdbdHhAOza1zNmqCSa6WN7/HoXVB3AUsQiVsYKp1odyNR4mAvi4 e2hLT4QPdu2RnhLFW7V29r/+t1o/R62+MO/vFcOpO+8mldZlzh1/YwoI+HWeT8SZZXk1 h07/h7YQPwktFIFv0VoHThwSTCBMqHQJR5kImKgZ6d8obOCLtiaqS+15vSvtjZd8iM6D LWONRXtelL/muSBVeTidHMCZGfYMy7xJ2/bgG0GrbM3Aq6sHudLW3AL3Q3mxWq2UkQqL gC1A== X-Gm-Message-State: AOJu0YwgE1O4ko3fz7yh7Rn2aNqv89DaJU0TyDSD57+/ubSXUSBkeyzN VJFUIftRQs2dc13DB8dZEwlhjwAkLzUeGlveGDHhgIGVV1fHUxhjeA6hqbKM9f1LuX7ZV2J+XT9 Oyh3bIlj9XmPcGgABsXWlbvLQgDY1+KS2PoENsMQfPxoba2TJUdT9eZQYHnSsVnCRq4JOwGOcU8 uGMBvIN+y73ak+APALfAK3Zoi1NldfjxhnN3hRQ20u X-Gm-Gg: ASbGnctL+dQNydsqTMdC7IqDkkutT0/5LHHfK1znYmH3D41yKY7vM7RjQIS5XTjGN/J 8zJI28ENn8vMC24ldjGAhP+aNEQpqgeOqNwVP9uAURIPU1MyaKhrHdFdwdDlhQ+wgQQNtqwpZ/e 5myL5BDW3xTk91ddQkkcY8w5swomOF+vSt646WEUx8BAmkjDMG3afmNZ8hz9EPYLPzajAhbHpiM naLHqBTdQLmKsYHWcMfOa3OJyD0qL3VtTX9cV8YGlxe9JhZd/4tx7IqH5yBYoZSugM6/Ud+CefK Foj778JjLr5q1QlRVe9b3BDpPxtXKDFx5OntCIYFGBY= X-Received: by 2002:adf:e18c:0:b0:3a5:2cb5:642f with SMTP id ffacd0b85a97d-3b5f18dc494mr11353834f8f.34.1752491072616; Mon, 14 Jul 2025 04:04:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmxXO4/G4BUjMNpGvCBwoYe32V7chip4duu+HFBVzVwgbIm8LyAaG3gSLmRm6maIg0ch2rnw== X-Received: by 2002:adf:e18c:0:b0:3a5:2cb5:642f with SMTP id ffacd0b85a97d-3b5f18dc494mr11353809f8f.34.1752491072103; Mon, 14 Jul 2025 04:04:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/77] target/i386: nvmm, whpx: add accel/CPU class that sets host vendor Date: Mon, 14 Jul 2025 13:02:57 +0200 Message-ID: <20250714110406.117772-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492050943116600 Content-Type: text/plain; charset="utf-8" NVMM and WHPX are virtualizers, and therefore they need to use (at least by default) the host vendor for the guest CPUID. Add a cpu_instance_init implementation to these accelerators. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 3 ++- target/i386/nvmm/nvmm-all.c | 25 +++++++++++++++++++++++++ target/i386/whpx/whpx-all.c | 25 +++++++++++++++++++++++++ target/i386/meson.build | 2 ++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4d4e5234246..8fb74b56ddd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -44,6 +44,7 @@ #include "hw/boards.h" #include "hw/i386/sgx-epc.h" #endif +#include "system/qtest.h" #include "tcg/tcg-cpu.h" =20 #include "disas/capstone.h" @@ -1943,7 +1944,7 @@ uint32_t xsave_area_size(uint64_t mask, bool compacte= d) =20 static inline bool accel_uses_host_cpuid(void) { - return kvm_enabled() || hvf_enabled(); + return !tcg_enabled() && !qtest_enabled(); } =20 static inline uint64_t x86_cpu_xsave_xcr0_components(X86CPU *cpu) diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index b4a4d50e860..11c263004d5 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -19,6 +19,8 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu/queue.h" +#include "accel/accel-cpu-target.h" +#include "host-cpu.h" #include "migration/blocker.h" #include "strings.h" =20 @@ -1207,10 +1209,33 @@ static const TypeInfo nvmm_accel_type =3D { .class_init =3D nvmm_accel_class_init, }; =20 +static void nvmm_cpu_instance_init(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + + host_cpu_instance_init(cpu); +} + +static void nvmm_cpu_accel_class_init(ObjectClass *oc, const void *data) +{ + AccelCPUClass *acc =3D ACCEL_CPU_CLASS(oc); + + acc->cpu_instance_init =3D nvmm_cpu_instance_init; +} + +static const TypeInfo nvmm_cpu_accel_type =3D { + .name =3D ACCEL_CPU_NAME("nvmm"), + + .parent =3D TYPE_ACCEL_CPU, + .class_init =3D nvmm_cpu_accel_class_init, + .abstract =3D true, +}; + static void nvmm_type_init(void) { type_register_static(&nvmm_accel_type); + type_register_static(&nvmm_cpu_accel_type); } =20 type_init(nvmm_type_init); diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index faf56e19722..22ac609070d 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -26,6 +26,8 @@ #include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "migration/blocker.h" +#include "host-cpu.h" +#include "accel/accel-cpu-target.h" #include =20 #include "whpx-internal.h" @@ -2500,6 +2502,28 @@ static void whpx_set_kernel_irqchip(Object *obj, Vis= itor *v, } } =20 +static void whpx_cpu_instance_init(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + + host_cpu_instance_init(cpu); +} + +static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data) +{ + AccelCPUClass *acc =3D ACCEL_CPU_CLASS(oc); + + acc->cpu_instance_init =3D whpx_cpu_instance_init; +} + +static const TypeInfo whpx_cpu_accel_type =3D { + .name =3D ACCEL_CPU_NAME("whpx"), + + .parent =3D TYPE_ACCEL_CPU, + .class_init =3D whpx_cpu_accel_class_init, + .abstract =3D true, +}; + /* * Partition support */ @@ -2726,6 +2750,7 @@ static const TypeInfo whpx_accel_type =3D { static void whpx_type_init(void) { type_register_static(&whpx_accel_type); + type_register_static(&whpx_cpu_accel_type); } =20 bool init_whp_dispatch(void) diff --git a/target/i386/meson.build b/target/i386/meson.build index c1aacea6135..092af34e2d8 100644 --- a/target/i386/meson.build +++ b/target/i386/meson.build @@ -11,6 +11,8 @@ i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.= c', 'confidential-guest # x86 cpu type i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c')) i386_ss.add(when: 'CONFIG_HVF', if_true: files('host-cpu.c')) +i386_ss.add(when: 'CONFIG_WHPX', if_true: files('host-cpu.c')) +i386_ss.add(when: 'CONFIG_NVMM', if_true: files('host-cpu.c')) =20 i386_system_ss =3D ss.source_set() i386_system_ss.add(files( --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492428; cv=none; d=zohomail.com; s=zohoarc; b=BR3H9jiOpoWA9694H+QE4NXKeKMirNm+rC16I+mSVFzr6yNkStibPd91mur6jCL9FzKoO7bCYGYjzKFjMfECyh50EnCufi+NjI/fXPoZUqbjbK2xzZI72+/8LQrjTfCRk31d4S2FjLPoFLEQsQkvJkJmGzasTB1cl3vIuWpQMB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492428; 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=CB+X0oKL0G0GBjxhvtx6dLGm/O/6KlgxKe/ThDuMvsk=; b=mhMYG717to8z2ijzkPNTg+RMOty3TPmRKUMru7tlO7JUWZyC+lQ3TmClbJlMFLJsL4xVh0u1xC/e1wAms7WGa4B9Qh0/S5h3c7054NXh0aiGGRmlJzoxvm+y2G6ZfTcOY+urGNHHXAndRUo/xWS8wTR0D6fb7thRztjQnYlIcnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492428889282.6041763921877; Mon, 14 Jul 2025 04:27:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH6U-0007SL-EM; Mon, 14 Jul 2025 07:12:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzE-0000eJ-RM for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzD-0001Z7-5H for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:44 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-slW5GY8XOFykztV9WLAHKQ-1; Mon, 14 Jul 2025 07:04:37 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a4f7ebfd00so1623400f8f.2 for ; Mon, 14 Jul 2025 04:04:36 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e285sm11942604f8f.76.2025.07.14.04.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491078; 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=CB+X0oKL0G0GBjxhvtx6dLGm/O/6KlgxKe/ThDuMvsk=; b=cCikgGNKMxBv4LBwHTaax7glzPL3tlQsPOgxVOZkam4Bm4IYuRfKFhV+G3n4fieV7Zak3r iTvo/4cS2dgaWFPibee5+IGRpL+wYyXi40gG/6uF+wnso7UFK+Gu1U8guQQJW4FOlZ6XlM 6gxsUXlliLt/fZhpqyQBcBJTl7ge+Uo= X-MC-Unique: slW5GY8XOFykztV9WLAHKQ-1 X-Mimecast-MFC-AGG-ID: slW5GY8XOFykztV9WLAHKQ_1752491076 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491075; x=1753095875; 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=CB+X0oKL0G0GBjxhvtx6dLGm/O/6KlgxKe/ThDuMvsk=; b=isPT4Gkrx6twqmKMDTCHN+FuZ2AFA9PdLXpd8con89Fr7C10iSm8kMDpeD7xQBIASq ES4LDJ8+W6IhWbXz+/v6mSRIjRvtMCW4Dyo38szbJ3oeeWA9ibS4KzposzMNdUKy4YsM Fd/rIcQw69+viV29NiF7m8Qgmhpn/yd0nwWQqOpuU88pMdRIRtIV6E+sjMTGkWlh1U1t YGIeCI2j5B92faFTstTxnZZK98zMMa4vthR60mTVKncZQ37mr1oMZt14A/OCyrbqqUP1 +2BE27lH2X+hqFPNWEaBGcbYw4ccbzaVlFbBMLvaxRU1mLPGzyeBJYkN9vo0vL3V+7R9 rPpQ== X-Gm-Message-State: AOJu0YxR8aHUpjR+ce4T1xHIVYzxO0ZohkrywDw8XlYKem9Bxy7nWdgW qJvS4i6g41qQ37/DfA0kYWFf2z5104YtBqByxDbcP7a4FJJXleCGIIyc5gIarIqJCAbs91lMMMs nJPRiQWRjul50/ng+ReLDmBMEtPqGg7TR9lI1Oc6UiMp1PK4toT12sE6hhrScVovaBq+FtL7OrZ SmNIYN/gwypExm3sandwY74XQS4fxousnCjVqpazCC X-Gm-Gg: ASbGncvM/gkBo4Oek/mBfl8+bBATV7QFSxA1618lTxRiA4ASVLdZbr8bpOOv+0KsZUE DTdHSQGVMDgI6QhBCVQULzX6yZp7qx4qod0palutQ9AOzr7+oDWdgFAYrYzYrlU/X5rfyJs1vpg 0PN74eylTU5zxYthTYmn/YwO3i68OmQUNcyd8DX6PGpzI4Fb7EPV2Zd5fn1ivW6pf0uA7Eq/Kl0 O6dGYFCQdtNHJIwcKohlSuQjGXijK/aMcBCo/q/DQECrZKGwrZeDl3wlGab+/p/Ht8Csjwqckak f1QOHTS0xpipN11+pbvIGaX1urh835tijeNdv2td1wk= X-Received: by 2002:a05:6000:2a85:b0:3a6:d296:feaf with SMTP id ffacd0b85a97d-3b5f188e9d1mr8205530f8f.24.1752491075007; Mon, 14 Jul 2025 04:04:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdaJrAFm4W8M9Gw8cMwztJzLdVyMelXQNq96ku/clV/0jOkisD1qlKuu23mjtU02uzeo590Q== X-Received: by 2002:a05:6000:2a85:b0:3a6:d296:feaf with SMTP id ffacd0b85a97d-3b5f188e9d1mr8205508f8f.24.1752491074489; Mon, 14 Jul 2025 04:04:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , Zhao Liu Subject: [PULL 09/77] target/i386: allow reordering max_x86_cpu_initfn vs accel CPU init Date: Mon, 14 Jul 2025 13:02:58 +0200 Message-ID: <20250714110406.117772-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492430760116600 Content-Type: text/plain; charset="utf-8" The PMU feature is only supported by KVM, so move it there. And since all accelerators other than TCG overwrite the vendor, set it in max_x86_cpu_initfn only if it has not been initialized by the superclass. This makes it possible to run max_x86_cpu_initfn after accelerator init. Reviewed-by: Xiaoyao Li Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 24 ++++++++++++------------ target/i386/kvm/kvm-cpu.c | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8fb74b56ddd..9c5cef2c7cc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6199,21 +6199,21 @@ static void max_x86_cpu_class_init(ObjectClass *oc,= const void *data) static void max_x86_cpu_initfn(Object *obj) { X86CPU *cpu =3D X86_CPU(obj); - - /* We can't fill the features array here because we don't know yet if - * "migratable" is true or false. - */ - object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort); + CPUX86State *env =3D &cpu->env; =20 /* - * these defaults are used for TCG and all other accelerators - * besides KVM and HVF, which overwrite these values + * these defaults are used for TCG, other accelerators overwrite these + * values */ - object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD, - &error_abort); - object_property_set_str(OBJECT(cpu), "model-id", - "QEMU TCG CPU version " QEMU_HW_VERSION, - &error_abort); + if (!env->cpuid_vendor1) { + object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD, + &error_abort); + } + if (!env->cpuid_model[0]) { + object_property_set_str(OBJECT(cpu), "model-id", + "QEMU TCG CPU version " QEMU_HW_VERSION, + &error_abort); + } } =20 static const TypeInfo max_x86_cpu_type_info =3D { diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 0fb88a239d4..6fed353548e 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -111,6 +111,8 @@ static void kvm_cpu_max_instance_init(X86CPU *cpu) =20 host_cpu_max_instance_init(cpu); =20 + object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort); + if (lmce_supported()) { object_property_set_bool(OBJECT(cpu), "lmce", true, &error_abort); } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491552; cv=none; d=zohomail.com; s=zohoarc; b=Tulz/1y8lGAX0yVkoqGkScT7TL9UwSlKYiaf9sAva4Qa2nbW5TKe+hylmzq9m9DWHSwHsoRAubKdeJloWKwIZ1cBp5Gx0hJVQm2ewyqhniBIz75vUO/YlfKkiKmTqMTQgfAwXTq4hkSVu5QIXUFePNonNEmAnVYTnRTCZC1QvwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491552; 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=N+jxMWxOlg/biz4eluMLRul34alkCeegIGKe/kOpyn4=; b=aNrvTAYZtoF6MNnf78TGr8nYuosE+W8Y1QIdrs8fjpSal84xteQgkoc8b8gp7h/cqdXDfmwMv/ZvcZsJH7gU6CoCtKSK++kCaERtfP+282WUqrBUaOFM4YjP2zZ44tDljj90+Ezy5BaxWKDFqoDmIaOzJWi/t7Vkb/016HsOg2Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491552622558.1180757427234; Mon, 14 Jul 2025 04:12:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH2Q-00037h-Ni; Mon, 14 Jul 2025 07:08:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzE-0000eI-Rv for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzD-0001ZI-6K for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:44 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-5Gt_-7QYOfmwFapUq852mw-1; Mon, 14 Jul 2025 07:04:39 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4831185e9.1 for ; Mon, 14 Jul 2025 04:04:39 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45615a4551bsm41651835e9.37.2025.07.14.04.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491080; 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=N+jxMWxOlg/biz4eluMLRul34alkCeegIGKe/kOpyn4=; b=O1ohlicpyzViFCD4TYj9r0VMhR4QRtl0T17mqCW9cth5exVXkkjKt8nQLodGSlEzhTDtuw j5Nh7JTj0Mctibjay8wBtuWlr4bx7trTThP2r7eChoO05MELomx+8IMXRQzrDXhH+Knp2O Ay3c13ispup+VRaS/WXVrdV3C4xZGeM= X-MC-Unique: 5Gt_-7QYOfmwFapUq852mw-1 X-Mimecast-MFC-AGG-ID: 5Gt_-7QYOfmwFapUq852mw_1752491078 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491077; x=1753095877; 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=N+jxMWxOlg/biz4eluMLRul34alkCeegIGKe/kOpyn4=; b=RB0wIoIzP/csLwP3Oj4PAL4xdVhSv+tXpjDPVEXboyupYPteFGWJNx/X43wdbeNFps tl+l1p6X8ezrJOYejUY5HSee5I1WUuUh1zcevhatEjsYFBiAh/LDRbHTj3x7sUOzpAEh XkBIt5qdW4REg4CDyqnUjygWmTjy/9IXuWj8SYeQRAcQoaa5fxRYRc7MUPsCVTCwaqIF 6hIS2EzNNet2lXr0Y+E6eZEDWfhuY+2IBfwNhoe8Afc/2hM286hSwKIJJbRKy45R3bh6 KcNuvPGHxmxHwR70rAsU33+hcJhj0/Y7ZizpK65M8u/G9svuPzxRPKlmjV9Xu52aPVa+ 0NqA== X-Gm-Message-State: AOJu0YyA6yvOC0ZEyap+eior2kYUcAnVOTFeg0RQk3wcAdGT1JIUmVTa 5jTprZWlwCoV/9RLD+wSPZ+U24b+oBF1O+8uhsCt94oCqrEnEfq9u8y9zMQOdIOvqfkPmDRJaor Eg6suDD3LRdR2B0Qo/btQ55x29LdKGyjfnx1Iq1TO9lcZdhVk+qnxf8yR+hPiPqZc6eXBxN5+2U KtagdiBusPVFSdMJdWq/FYrbWZJyDvLeOnKJtI3ly4 X-Gm-Gg: ASbGncvvtYjlCaJSZyukkTBYYv/z4zQZgA8UrDeot/gZeCEQOC3K5SEufkoQ8QLs/Fs ixHg9sHTTH4ldmJeUKigayCwGlItI55vdJl+DNPahEkFgSu92aSxbxF9v9xPSRg+RH5e84MJumS 5BpqGyk6gmUQ9WRWaRCkYjZglZm8mIQOlYAHFYsGTFMd4cvhLolb8Kd1jFQQxMj5VrIxXdkLBje IdaHjWXwAnonCj4X1ycreFuqfKjBL3MRIvfIwhjAA+21pPjYKdOIg8Od8cGPaTpV1E8CeK+uhVA PRgvUOPnzpN3hdi1ZCbM0smR7y7sMim7u+hRzWQtigc= X-Received: by 2002:a05:600c:8505:b0:442:e0f9:394d with SMTP id 5b1f17b1804b1-45565edc90dmr96701625e9.24.1752491077324; Mon, 14 Jul 2025 04:04:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFW+AVS9Z4+gBr7HmI1Bh4NlwERimAcm0B/SOmONmzScXvlN3R5KfsCIRdN66L2fNLLCsqLxQ== X-Received: by 2002:a05:600c:8505:b0:442:e0f9:394d with SMTP id 5b1f17b1804b1-45565edc90dmr96701345e9.24.1752491076825; Mon, 14 Jul 2025 04:04:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Like Xu , Dongli Zhang , Xiaoyao Li , Zhao Liu Subject: [PULL 10/77] target/i386: move accel_cpu_instance_init to .instance_init Date: Mon, 14 Jul 2025 13:02:59 +0200 Message-ID: <20250714110406.117772-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491553133116600 Content-Type: text/plain; charset="utf-8" With the reordering of instance_post_init callbacks that is new in 10.1 accel_cpu_instance_init must execute in .instance_init as is already the case for RISC-V. Otherwise, for example, setting the vendor property is broken when using KVM or Hypervisor.framework, because KVM sets it *after* the user's value is set by DeviceState's intance_post_init callback. Reported-by: Like Xu Reported-by: Dongli Zhang Reviewed-by: Xiaoyao Li Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9c5cef2c7cc..44178bc523d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6202,8 +6202,8 @@ static void max_x86_cpu_initfn(Object *obj) CPUX86State *env =3D &cpu->env; =20 /* - * these defaults are used for TCG, other accelerators overwrite these - * values + * these defaults are used for TCG, other accelerators have overwritten + * these values */ if (!env->cpuid_vendor1) { object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD, @@ -9038,8 +9038,6 @@ static void x86_cpu_post_initfn(Object *obj) } } =20 - accel_cpu_instance_init(CPU(obj)); - #ifndef CONFIG_USER_ONLY if (current_machine && current_machine->cgs) { x86_confidential_guest_cpu_instance_init( @@ -9114,6 +9112,8 @@ static void x86_cpu_initfn(Object *obj) if (xcc->model) { x86_cpu_load_model(cpu, xcc->model); } + + accel_cpu_instance_init(CPU(obj)); } =20 static int64_t x86_cpu_get_arch_id(CPUState *cs) --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491278; cv=none; d=zohomail.com; s=zohoarc; b=IzsKoMbMH6UEsVGVMLWmqVmM5WTeBLQKZqqNVginMJShKsRvp0N4pJwxYqQ04RrDIZWSYeZiykbrWDe9qAnPeWmRaAkbZmIovO99U2Mx4TXGPQu4K9sjt/xzIexrEyEwlh2qZ1AdIkqCrNnHxa9BRLZr8Zm9w/WkEjBoqAUKu4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491278; 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=q6nTEsoCuSJ3UH4OjROxuNbEuTg0QB24XVyppadmgMI=; b=dexSEl6AlOK9+kleGI9v77c5VtiNFyI7GO2GpjT4+b+oQU6CZU/Da0Wa6saQ+14TBkOJ3yH/g226X4BCe6FuELef287nmHgex66qlzXTeQHcuIkoSd41SvqkTu3GdLOHSuiejJgFIQxebx9jjstyuwAQsXi65YT4oD/aeUY0eAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491278361584.7898132770251; Mon, 14 Jul 2025 04:07:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH2H-0002kR-Nh; Mon, 14 Jul 2025 07:07:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzG-0000ez-9X for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzE-0001Zp-3R for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:46 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-BpY4cs5HOK6y-O8KMhXIbQ-1; Mon, 14 Jul 2025 07:04:42 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a54a8a0122so2145258f8f.2 for ; Mon, 14 Jul 2025 04:04:41 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561323a488sm46946605e9.1.2025.07.14.04.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491083; 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=q6nTEsoCuSJ3UH4OjROxuNbEuTg0QB24XVyppadmgMI=; b=b5D9Q5jQ37ot49aACGv98FIK6r+qUB5ASuB/fYCxfvHLj+R6nngcsO+GJgRuXi5UydKpV9 B8OxZRi0HqhgBjkYeXEcoDdnpK/HZoPJ4SVz2RIbF5I88Ux0c8THQpm5KbIXsJMdccSmZ8 wEAvmfI1CfUpd4YxW310h4wbE0rPDpY= X-MC-Unique: BpY4cs5HOK6y-O8KMhXIbQ-1 X-Mimecast-MFC-AGG-ID: BpY4cs5HOK6y-O8KMhXIbQ_1752491081 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491080; x=1753095880; 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=q6nTEsoCuSJ3UH4OjROxuNbEuTg0QB24XVyppadmgMI=; b=Qk67iAhgfLJqSSxc8FZRANNLs0clomFKvhnMIMoytiXaXvw4uG5b+UPSQzV35AgxBw LsvQLomob4U8/IEFxzgdEkDu4qRppyQld66vofRL9KFj2wMG0Mr68GEqexdcQi7jDtN3 4bbbOlggREyc5RqQcwu7ebuij2YVL685NvCfDZV+Aenkhf6ceckubmZ5ELmIuwv86N6/ 0ZbmGhYSsJpMTBbgXOG1NL+8Y6jihhV09xSqLAigD1029h5aRHJgYg7/+VhMihc+BMbF krxsLsM7sF/mIj36xSfNbZlCxV+Au2HzHGoE97/fCBEySCkxux9A0wknZvihj5pxBv8Y WXTQ== X-Gm-Message-State: AOJu0YzXLnuA6NuUpFrtLs4gUGtGU5LmWPsX5qjwWx4yrAh/N2Uet88U huV/xMa2emIzDd9BslBsbqq0WmQHv4Lk2h6uCtzzAVY4H3UEa/YvjiSzKW+Eaoyq8cx1O6JKkFE RiyfVpH0koZCa5eYdt+x3B/zSlsVetc715Kjpq2J2U/+F6IcSVNuDMR1BAhwxi1JwM3ePaAuK6M HPbpZd3aDSDAx+LH6yVSbzmtb7s71sXn6hEpT7eF8f X-Gm-Gg: ASbGnctQcVKTKP0c7vPaTEAlJQfzbRpWHMyyrnaXzGiA/zLurTgcJCqOloa9t3cMY0B 9aM7PBWA2eRHbX6YdsV6wM79QUWixmAHdmPNeGI+I4hpp2HMSlNdKmzwLoPlqXT5/U3zLPLmcoQ sRrCt3REMCu04aWIbjq09fFiPskgUwD8EwVrTVlEHMJ4ff7RsN4dBc6m2KB7V86riA1hYI4ubaQ FgjZvIQQQLavUPE0D8PmkkhftNNDUibrxpUR4ZKZi1srt+ztWiUmRFPvu8nu5jGLK2XkrTVoiij wP5oRcEC2PvOMwD7TEOV19vKSgLNb6uVrhIhCz8E0qM= X-Received: by 2002:a05:6000:2888:b0:3a5:3b15:ef52 with SMTP id ffacd0b85a97d-3b5f187adbcmr10705905f8f.8.1752491079827; Mon, 14 Jul 2025 04:04:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOcx/Ts0EgDTHeuvCpdOtPWZD2PmI/y1hY9FF6IXW8kMqAreSs5tl34RgiPmJ5SfFAKt0EmA== X-Received: by 2002:a05:6000:2888:b0:3a5:3b15:ef52 with SMTP id ffacd0b85a97d-3b5f187adbcmr10705879f8f.8.1752491079315; Mon, 14 Jul 2025 04:04:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 11/77] target/i386: merge host_cpu_instance_init() and host_cpu_max_instance_init() Date: Mon, 14 Jul 2025 13:03:00 +0200 Message-ID: <20250714110406.117772-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491281802116600 Content-Type: text/plain; charset="utf-8" Simplify the accelerators' cpu_instance_init callbacks by doing all host-cpu setup in a single function. Based-on: <20250711000603.438312-1-pbonzini@redhat.com> Cc: Xiaoyao Li Signed-off-by: Paolo Bonzini --- target/i386/host-cpu.c | 28 ++++++++++++++-------------- target/i386/hvf/hvf-cpu.c | 2 -- target/i386/kvm/kvm-cpu.c | 2 -- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index 7512567298b..3399edc1ad0 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -132,27 +132,27 @@ void host_cpu_instance_init(X86CPU *cpu) { X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); =20 - if (xcc->model) { - char vendor[CPUID_VENDOR_SZ + 1]; - - host_cpu_vendor_fms(vendor, NULL, NULL, NULL); - object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abor= t); - } -} - -void host_cpu_max_instance_init(X86CPU *cpu) -{ char vendor[CPUID_VENDOR_SZ + 1] =3D { 0 }; char model_id[CPUID_MODEL_ID_SZ + 1] =3D { 0 }; int family, model, stepping; =20 + /* + * setting vendor applies to both max/host and builtin_x86_defs CPU. + * FIXME: this probably should warn or should be skipped if vendors do + * not match, because family numbers are incompatible between Intel an= d AMD. + */ + host_cpu_vendor_fms(vendor, &family, &model, &stepping); + object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort); + + if (!xcc->max_features) { + return; + } + + host_cpu_fill_model_id(model_id); + /* Use max host physical address bits if -cpu max option is applied */ object_property_set_bool(OBJECT(cpu), "host-phys-bits", true, &error_a= bort); =20 - host_cpu_vendor_fms(vendor, &family, &model, &stepping); - host_cpu_fill_model_id(model_id); - - object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort); object_property_set_int(OBJECT(cpu), "family", family, &error_abort); object_property_set_int(OBJECT(cpu), "model", model, &error_abort); object_property_set_int(OBJECT(cpu), "stepping", stepping, diff --git a/target/i386/hvf/hvf-cpu.c b/target/i386/hvf/hvf-cpu.c index 2b991f2fc8e..94ee096ecf7 100644 --- a/target/i386/hvf/hvf-cpu.c +++ b/target/i386/hvf/hvf-cpu.c @@ -21,8 +21,6 @@ static void hvf_cpu_max_instance_init(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; =20 - host_cpu_max_instance_init(cpu); - env->cpuid_min_level =3D hvf_get_supported_cpuid(0x0, 0, R_EAX); env->cpuid_min_xlevel =3D diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 6fed353548e..a99b8764644 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -109,8 +109,6 @@ static void kvm_cpu_max_instance_init(X86CPU *cpu) CPUX86State *env =3D &cpu->env; KVMState *s =3D kvm_state; =20 - host_cpu_max_instance_init(cpu); - object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort); =20 if (lmce_supported()) { --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491276; cv=none; d=zohomail.com; s=zohoarc; b=bdHd9vw1SpuxpsQWnHR5iRwyvGBUcXfA+pzOhwnCNxm8XpL46woY+cC7NwtXUDqd/ZWh655/LFQjDDiJyXjGfukIHxcsNjBf1AiVnoI0W+oIRwTCk45qmDXo8Zpo7ijOaviNYBzUHoq+i3o6lTaQnjMe+ERKqVf52SCWzi+kfkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491276; 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=Pz8fqySqkEOpDmp0MxM3l6r2UVHcHahwTbwglxlBYJs=; b=S1G9+0418d6LAHvwvUYJk7YXPaeBhgWnkVPRic3s8b62YGehVx9BnIs95hMaJg8g4o7wCMnTV005VYZ1cxeHZQV8LSpiZp8hkoSgndSNtwIRQHqee/6AJOr2ex/Hli87p8EXes2x1qQfA5QaGBIcTSGU1q3VJRYz7rkBZBWbV3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491276620697.9091400795515; Mon, 14 Jul 2025 04:07:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH2A-0002SL-39; Mon, 14 Jul 2025 07:07:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzI-0000fR-BY for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzG-0001ad-Nb for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:48 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-lXhQxZIbN_SHzsj6UX2eUQ-1; Mon, 14 Jul 2025 07:04:44 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4831455e9.1 for ; Mon, 14 Jul 2025 04:04:44 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561ccd6d44sm10899805e9.1.2025.07.14.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491085; 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=Pz8fqySqkEOpDmp0MxM3l6r2UVHcHahwTbwglxlBYJs=; b=a63lFUhXxvzpP9yjXMNz/vGBiHZcRwxjy5tLItdSmpccGLy6UJyMJYvHyd317ynAWZyth8 JOPhnUb/vOMkqqb8Qfi9HzpSXzNOFPLhykbHn90P6ootfnp/fMMtKJHljhcp6PGc3X75b3 FLB+0h0JuLI2cSlmDBlPTZ7sFu7QgAs= X-MC-Unique: lXhQxZIbN_SHzsj6UX2eUQ-1 X-Mimecast-MFC-AGG-ID: lXhQxZIbN_SHzsj6UX2eUQ_1752491083 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491083; x=1753095883; 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=Pz8fqySqkEOpDmp0MxM3l6r2UVHcHahwTbwglxlBYJs=; b=cgBdmGx7eVnRdpJvGKB/ONh/4l2pMGdVwkNcoJq9AxIzMsvr453lE3Ad0/ldR7D6lc caRyzCYR97IYfNVcSbNXpMjqNj+URjX8YCemOx/TKd8sszvb4mC92v+u1QfLB3nsJFHT QZ4JLX/KAtthtTnzb/QNzOcegIgN5NgAoasKJitECojKsSROn6g7mF2BD1Wj97Wou1oi 6IKNxLXNzg3a9g3QGcyVLCrERMS5572N0SJb4JPHi2o31jH+brosNJ44PHjyRreJnKGJ +gGTgQjntacOpqRNWF8Lzl/vNirTa1F24wh/i3kDwhlUjF7qIJfNh4NU2SCZFy5ySpGv cMdg== X-Gm-Message-State: AOJu0YwdkMYb0RL/h+tAMVM3Za1TvKcKog19wJYomGW4/FSwW/M/pUfr y+402YkFlp4a6euvUHn5TVjFykV7qkg43eVMFzHKAC+am1VkftKxFDUCYckiTMChjLNW/8DFIKp P5+yyw3NU+TK4dD23TmovxeSWJDHTEm/+P1XON/hpHPCARx67TNp6lOEp4tSIHW9+/ibMMkuBqw KDRA4CBS/g/Ig+5yclkZKSPUlWVXJ5i1uBSFxBSA0q X-Gm-Gg: ASbGncvolyYxyCPPOPJxIq3qK3qLU+vNqvSoDqGwNTNsxrY0rie3dPG6rfclGEZjIXs vOQn7rjlZvPYdQ99ooPUcHbjFq1wlIj12Rf3RKO5LbSf0y2pv3ZdfTOFrUqDlziClG1aG0+mb3j Yvikph7QB1q7iNP/h0W2W+gM05HIT8P0cAtVtnBrpq9FcFuRco7uI2RlsRSsc420Nvl4c4x5jQ9 Mxtr810CFK2EDOiWnEyL+kiMhqO33LQldCl7+2Jze+mJjeHgqPlmcV5YuKyYKZLnEwQQjwQgald cgnn8Nb/5sus5EiqILwDvoHHQ6Iz+29QbEjQemzVVjQ= X-Received: by 2002:a05:600c:8505:b0:453:1058:f8c1 with SMTP id 5b1f17b1804b1-4555f895526mr114787085e9.3.1752491082531; Mon, 14 Jul 2025 04:04:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCF1U4/GMjQgR+xSX+ElFMi+rQOKfH4ES83cQdWDVbK+ZVMplwsbUY4oeQlbInk4agyJdsdA== X-Received: by 2002:a05:600c:8505:b0:453:1058:f8c1 with SMTP id 5b1f17b1804b1-4555f895526mr114786835e9.3.1752491082000; Mon, 14 Jul 2025 04:04:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 12/77] i386/tdx: Remove enumeration of GetQuote in tdx_handle_get_tdvmcall_info() Date: Mon, 14 Jul 2025 13:03:01 +0200 Message-ID: <20250714110406.117772-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491277760116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li GHCI is finalized with the being one of the base VMCALLs, and not enuemrated via . Adjust tdx_handle_get_tdvmcall_info() to match with GHCI. Opportunistically fix the wrong indentation and explicitly set the ret to TDG_VP_VMCALL_SUCCESS (in case KVM leaves unexpected value). Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250703024021.3559286-2-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx.h | 2 -- target/i386/kvm/tdx.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index 35a09c19c52..d439078a876 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -32,8 +32,6 @@ typedef struct TdxGuestClass { #define TDG_VP_VMCALL_GPA_INUSE 0x8000000000000001ULL #define TDG_VP_VMCALL_ALIGN_ERROR 0x8000000000000002ULL =20 -#define TDG_VP_VMCALL_SUBFUNC_GET_QUOTE 0x0000000000000001ULL - enum TdxRamType { TDX_RAM_UNACCEPTED, TDX_RAM_ADDED, diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index e809e4b2dfa..8c661c3ecfd 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -1259,13 +1259,15 @@ out_free: void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run) { if (run->tdx.get_tdvmcall_info.leaf !=3D 1) { - return; + return; } =20 - run->tdx.get_tdvmcall_info.r11 =3D TDG_VP_VMCALL_SUBFUNC_GET_QUOTE; + run->tdx.get_tdvmcall_info.r11 =3D 0; run->tdx.get_tdvmcall_info.r12 =3D 0; run->tdx.get_tdvmcall_info.r13 =3D 0; run->tdx.get_tdvmcall_info.r14 =3D 0; + + run->tdx.get_tdvmcall_info.ret =3D TDG_VP_VMCALL_SUCCESS; } =20 static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491627; cv=none; d=zohomail.com; s=zohoarc; b=MOHxtXhwRMPzd5zL0AJlpYT8ZEa9MjH7RvsYY/rQt7uVjmRLxgAtGhHgju7IA9VkIBgzd9zT+mwvmyZylszhWNqhBqeJe1ZewrzMsE2qy847EcvVt67/7nb++yd4Uxfqz7MSzi441LuWa8mseK7J2eoZ7nIOMPeRA1Y5D5vRaEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491627; 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=qpzjtWFSpDez/U9osH7Y6wWYZcHylcUeV56dHdPFJUo=; b=MZUUO7QXUNtNJb3NphbhF73sIelqnp8rddu+NfMo5T1q62cwymdPIt4yy32AmJ9hA7L7dx8V9mz2nnBN81FBS8T1S02OXBFD02NX1EMPS4DgrxTP6xXSnFJhZIbkYs4QvH9IwbvwdA6nZSJBzO/jLG6ZUy6i96tgQ+ExDJJPTXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491627046645.9876134323516; Mon, 14 Jul 2025 04:13:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7M-0007yU-BI; Mon, 14 Jul 2025 07:13:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzO-0000hG-Em for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzI-0001ay-DM for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:53 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-zpG4uavCP3uVPw75zEEW0A-1; Mon, 14 Jul 2025 07:04:46 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4532ff43376so38559455e9.3 for ; Mon, 14 Jul 2025 04:04:46 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454dd537785sm131264925e9.23.2025.07.14.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491087; 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=qpzjtWFSpDez/U9osH7Y6wWYZcHylcUeV56dHdPFJUo=; b=NzZzvgAmicL2cA0ej82ll03KvGlohaHrrIIl96pzDZqlhVA7OmRPsA8HhZwk5PPXiYFiEW Ceioa4tzL26lSyCL3r3+Sz+kF0BN9Sa9PHbYG+en/Tr/qRSpSrzyaO44yTDjYF1aohAsZh uc6bRcUjZ+qtxLp5fFj6uxO3fXuGX58= X-MC-Unique: zpG4uavCP3uVPw75zEEW0A-1 X-Mimecast-MFC-AGG-ID: zpG4uavCP3uVPw75zEEW0A_1752491085 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491084; x=1753095884; 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=qpzjtWFSpDez/U9osH7Y6wWYZcHylcUeV56dHdPFJUo=; b=PU3hQTp53K2PeDFipKDi9reFhxAsiGD3aEjREbo3d7aKalwdmMFm4a5beMBUiJOnOb 5Ybf3nQpVbSxoYcSp6f2b56emIv1JIfUJdIK1+xTBxFBS/9DmXkeW7RINcVNetouODoF k/+9IqOFYWGMv601sLv7M3UF65xAYKzBa4xb8kp6atxuKp3BHauSJMIlYxWnlhWqEPPO MsCmE+RtYz5Fml7hL1ja467+MXkp8VwvqrQGOdGJwmyHHUC7agJIESUgdY+RrEDJo5Ha UPktsnvsWMeePpedQ/hb6xl4ARlQYPRUTeG59QfQqtsss1I6KZ+Hqy7z+XQml4VIKDdQ yX1g== X-Gm-Message-State: AOJu0YwbIQZo0QC2U9D/mval5SIawnUAyAKl4jXeiYM0X7HFFaNlhkSD w5Nt2/xeAGDda3eQ95AMHyyksoWkoioqWZwP2mHzhgWVOWBQdNufEa8mnI9wtBA9tDqzxNn2glE lMQbmxSJrqHeSn1rRUCv9KGZHUkGHsIp7Vk1sDLWtkwwyhhsoc2bQDEj94dhq/TW2gWzet7dkmJ a92faQo/Nnw4ePY0uMRHNAj6RIQp4w1x/M0yEFI/IL X-Gm-Gg: ASbGncsyk0OD71UUZ6WkGYl/YOWKmygY4jQEgKonyYmUV0n+p2YtW5Sz7Ur1lOjB32o evcrmSbYKHd1sR4lS2eOo4ml6Ikdrj+J1+yTkKECSPno2r3zyMUoG6rAVRw+3WTU4knZLRTehgm /K3y0V8csTGE3kp4urZPbiRwj+GYS8VdN4AJDGhrQvYf7RS1CV24Ui8GCj/l9IqPdDiEGddsnTP pYYQs3aOmvZC39JNJh7QY+mqNd2E9DXKaO3ArJESOCyvdTH7VYRemUWEsNTNk8tkOC49v+P48V7 H9aVecGQGgvGj+Mw4SlJrlnnpk/QjX+boopyAITnFl4= X-Received: by 2002:a05:600c:34d1:b0:456:1d4e:c127 with SMTP id 5b1f17b1804b1-4561d4ec409mr18193465e9.8.1752491084576; Mon, 14 Jul 2025 04:04:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHo3K4lSseHXvnH24+hSc89FkJbum17dHS+rRDyjbBi3ORFtjRjOQGWF8vuqhu0Xp5HlHWM9A== X-Received: by 2002:a05:600c:34d1:b0:456:1d4e:c127 with SMTP id 5b1f17b1804b1-4561d4ec409mr18193215e9.8.1752491084139; Mon, 14 Jul 2025 04:04:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 13/77] update Linux headers to KVM tree master Date: Mon, 14 Jul 2025 13:03:02 +0200 Message-ID: <20250714110406.117772-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491627822116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li To fetch the update of TDX Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250703024021.3559286-3-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- linux-headers/asm-x86/kvm.h | 8 +++++++- linux-headers/linux/kvm.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index cd275ae76d2..f0c1a730d9c 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -963,7 +963,13 @@ struct kvm_tdx_cmd { struct kvm_tdx_capabilities { __u64 supported_attrs; __u64 supported_xfam; - __u64 reserved[254]; + + __u64 kernel_tdvmcallinfo_1_r11; + __u64 user_tdvmcallinfo_1_r11; + __u64 kernel_tdvmcallinfo_1_r12; + __u64 user_tdvmcallinfo_1_r12; + + __u64 reserved[250]; =20 /* Configurable CPUID bits for userspace */ struct kvm_cpuid2 cpuid; diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 0690743944b..32c5885a3c2 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -459,6 +459,10 @@ struct kvm_run { __u64 leaf; __u64 r11, r12, r13, r14; } get_tdvmcall_info; + struct { + __u64 ret; + __u64 vector; + } setup_event_notify; }; } tdx; /* Fix the size of the union. */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491533; cv=none; d=zohomail.com; s=zohoarc; b=g9Y2NPGl3S1NNKZFlxVWj2A9zR8Cc2UPEi3YZxrjo389EApY4ntyxMTLybfWBjmLxvY1Khb9n9M95/igqCcI2UgfUP4kPvQFdhZXu2wVIY/hDouHY2IcIIhRArZlxNjfBh/6AqQdVRDZ1/8m91hrSWtxlsraHyh2oYAr/vWYGdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491533; 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=YCAKi1gu8K2x7TdZzfJVxBa70394u00QgrgkAAGqfzs=; b=WI2x3K2+3g8zD/n+zZO+ZetFqqTbgp8EY0inI7HJ2ZA/RT1qoQrIT0P5tQMn97SAQOTuQPVlIAwdF6oI4gxK6+NA6Ikx1Vf6o1DlXff+NqK8YIac7IyTYJDjnOeSBbVYUzAWf9L5ZYD+YOxzHInE9g7vrIPj01xqNxs2F2pPuPQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491533834920.9110428011668; Mon, 14 Jul 2025 04:12:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH2Y-0003Pv-58; Mon, 14 Jul 2025 07:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzN-0000gu-Dz for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzL-0001bH-KO for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:53 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-O_huOJh-MqaCndDdABbtbQ-1; Mon, 14 Jul 2025 07:04:49 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4532ff43376so38559965e9.3 for ; Mon, 14 Jul 2025 04:04:49 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45621ec53d5sm4117005e9.2.2025.07.14.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491090; 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=YCAKi1gu8K2x7TdZzfJVxBa70394u00QgrgkAAGqfzs=; b=UDpb9cecbJzLG5jSWIcOunWLpYWd6b/z+Q6VBE77roDU0xZy4bRr+K8cQCKfHykuf2T0Ld bB3YRbKnMp+w9tea/r0n2plPOArKgUa9ryYFLywgb/sXVzOWM364cKZVdNEuP7G+RoRtP8 jnr2KCSax3ZQZUu+oxvbTiYT432NmLA= X-MC-Unique: O_huOJh-MqaCndDdABbtbQ-1 X-Mimecast-MFC-AGG-ID: O_huOJh-MqaCndDdABbtbQ_1752491088 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491088; x=1753095888; 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=YCAKi1gu8K2x7TdZzfJVxBa70394u00QgrgkAAGqfzs=; b=iq8qgAb8y/l7CEJplySDin46nJHbUk27L7ZwqOVZG4z0EQM2Wxy4UfyzAeQ7Y5cXD0 opjkKFr/hIe8mb3M3mbA1YxWhYsTrazGPWjgIrC+gfbQziAHtk0tpMCm2wkOMFEGMVUn aOdpF8QvkNneM91v7hnxRKytrdUi7+tCaRQu196Ks+FfVqbcPnWuFm/WQywXIkV7macj xs4zcXQd5JuvIA+1Vx6cialVTu11/+8CxQB26cGW40YsI14i1ustOvvQF262fPSpx1CG VW9VTED9VtokL4Rg8riA2SYWO/MThXNzo5VPmV5jHPjV3cpLXXjFcaOdsbRY/S0doUSm KQlg== X-Gm-Message-State: AOJu0YzmGmXdU/9Xbe9PtcrUBZAt9rehR9TB7sgMisPjPK+Wbn/OBpYK UCN7PLoaN1ufLa6a2Xs9exdH5yR5lI/WSC7dzF/iV9B3Uu/mLqp8kfaSE2IgFXMpEKYv1KC4pH+ fO7WRiOmrMnL5fiCCDKqLTiCanZZ5I0pziTi1Ni2h5hosKnbv2cxlJwpUJ3JHNVh9BUANREVO9N x/nRz2zwo50UxagicgvkfexFq39ZSQPW+Gj2GUR4nG X-Gm-Gg: ASbGnctJbMAD2yiWTgDuV/iBiAeTivA4Y/kPFRmOXUs6oxw2AtJNdcYbZHVHOprXJak izboPwrCQ/VzH8L64GVXBupx4fZ+pW+vj3Obmkc/bG2I/Z4HRCrHLMiWZJXPHy1pPvzFTSQAUcP LhY3F1ERYy8EFjdUx6KOeYlW6P5u5xXqe7mY2EFjwqg2+t4sai8t0lfLpE/kY6ETQcHIEaqfqFQ ssFKwi162mLnzklVMALGSX9b+GlwoO6S57t+Gn0IurQM1QaGiQyhz/Z7T1GmarKvnul7SUMzCZZ gJ+UR15Q9155xXwj/pbVJHGDREgerb/+yBQkgtqsBHA= X-Received: by 2002:a05:600c:8483:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-455bd87a4a2mr101755095e9.4.1752491087729; Mon, 14 Jul 2025 04:04:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIXNlYoJFMrTFvFTc1DWR87cxRqD+30d5HiNNz+93Iy1RAyoIXbfG0hnp9s3ZR08YIouSYZw== X-Received: by 2002:a05:600c:8483:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-455bd87a4a2mr101754575e9.4.1752491087039; Mon, 14 Jul 2025 04:04:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 14/77] i386/tdx: Set value of based on capabilities of both KVM and QEMU Date: Mon, 14 Jul 2025 13:03:03 +0200 Message-ID: <20250714110406.117772-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491534961116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li KVM reports the supported TDVMCALL sub leafs in TDX capabilities. one for kernel-supported TDVMCALLs (userspace can set those blindly) and one for user-supported TDVMCALLs (userspace can set those if it knows how to handle them) Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250703024021.3559286-4-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 8c661c3ecfd..10dfb80d22e 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -1256,14 +1256,21 @@ out_free: g_free(task); } =20 +#define SUPPORTED_TDVMCALLINFO_1_R11 (0) +#define SUPPORTED_TDVMCALLINFO_1_R12 (0) + void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run) { if (run->tdx.get_tdvmcall_info.leaf !=3D 1) { return; } =20 - run->tdx.get_tdvmcall_info.r11 =3D 0; - run->tdx.get_tdvmcall_info.r12 =3D 0; + run->tdx.get_tdvmcall_info.r11 =3D (tdx_caps->user_tdvmcallinfo_1_r11 & + SUPPORTED_TDVMCALLINFO_1_R11) | + tdx_caps->kernel_tdvmcallinfo_1_r11; + run->tdx.get_tdvmcall_info.r12 =3D (tdx_caps->user_tdvmcallinfo_1_r12 & + SUPPORTED_TDVMCALLINFO_1_R12) | + tdx_caps->kernel_tdvmcallinfo_1_r12; run->tdx.get_tdvmcall_info.r13 =3D 0; run->tdx.get_tdvmcall_info.r14 =3D 0; =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491621; cv=none; d=zohomail.com; s=zohoarc; b=TPdDYNdIVHJ1PwMboGqYLTmN/9BrWt49q6LKck+lNZiIyWqckRD+DOv1gDKMfCeAUXR05AFI2yJXgMg6ldTdOUYJHTReYU73daP+M+nnATw0TfVPVbdkxwY/TNZp44rY5I88PALJFCoCUGbUenuc+q4FD1CVXJwDlZ7WpSbGvGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491621; 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=eGWtRvpv874ViWc5Pm3mZOHws7lFktTmKEM+SKQfshM=; b=KUhk4Miyu3i17WAve5vOQcIcAWMc9QyMggz0d52JzGNyBmKbtirCmWRZ+HYJwr2sbf/p0dZ5NhhhFhr3aZiBLFjir2SIPTEd1grqHs80zLDfrpzqRyjJeEphOVLvZsbhiZpIa3aernnuSAeKRvGx8KWpMQzU8NkGkausle1OXgk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491621103275.73736439597053; Mon, 14 Jul 2025 04:13:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7P-0008Ei-9P; Mon, 14 Jul 2025 07:13:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzQ-0000js-RN for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzO-0001bY-6u for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:56 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-UhQfqynSMwqQf5kMZJQ5_w-1; Mon, 14 Jul 2025 07:04:52 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4538f375e86so32944975e9.3 for ; Mon, 14 Jul 2025 04:04:51 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d5037fa0sm168013585e9.7.2025.07.14.04.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491093; 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=eGWtRvpv874ViWc5Pm3mZOHws7lFktTmKEM+SKQfshM=; b=AvN4T1sZozpFYhcyVZiWixAM14HVKTasKfC2A2EHBTu0hohn6/Jlx9EPlQcFlBdtXYxZKZ I9ruibtjIYRMFZAAuGvbb0x5W6uO3Plz/5OAW8BmK3VK7lRur0BEJCAGZERymJKPsfsIDr hl0WW+jwt0pAUzEGoy6Qf60RqlYF2JY= X-MC-Unique: UhQfqynSMwqQf5kMZJQ5_w-1 X-Mimecast-MFC-AGG-ID: UhQfqynSMwqQf5kMZJQ5_w_1752491091 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491090; x=1753095890; 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=eGWtRvpv874ViWc5Pm3mZOHws7lFktTmKEM+SKQfshM=; b=xId8j8HostJl/1uxeQhTsPkFUmMxJqlv4jZGcZ1tmvn0cD5firLZGwi+aELpvLcGkL PYizwmoycvdSXkiGwHPRZkpzhT5p/OUHPHGdRgoibskHllcR+4Aa/MRlcq5xMqrdUw5r qIchwT41xW3Ah0NZzEvAPkAyXHLAvZp7ZZvVuRLEbQmz5WEV/xD3RBn4cHl5x+q9EfdB McQ9rAi3+TNmX17TzexJNhJRt1Rj50xAwud7PCdi2lEZteQvkDIm/0IlJfNlVm/nXLvP FzIWl3OwmjuxJ192VJ+h+HVNzMu7142jvnA9gHK+MgfA8tdKFiFPqAkl7N5eOqOy0iAP d0+g== X-Gm-Message-State: AOJu0Yw+4hRKtpG90uXkUJ3y7tdJsLdhFFWGBfVUYKyi/5NZnMtA2V6t 2hZvRDSAKhKCl3fWBl0hN++QMxXRtNilRbkIObUb7wjEQtpdCu0QBaJnTr6x5yYOo/CIVLiIigc ksiXzKr9BuvNZ6KOMP6vNmQyVBQnlVzqNBa9vmYhMX7i9HCYkcgasgA+V1dQUi3czn1IuKWMZaH rdfNC0BHppPQq6DJ1UHxfALPoMvH43yNfCbk9LgptV X-Gm-Gg: ASbGncviV0UGNiMHigtHT2NKNM/I5+YaRllVF+HpPnNBTM8Ur9lKD1ryCpqQGjzeWsJ 3bAB9cOnWQHtz7rWxpKLK3BHWpVejUsc9fcwB9zvow/2Yq9LARc09MlGkTtMfIIxtYx/Ql8Ivog xjbiQPrjF8ioYsbFwJ/KNZgCAI+u622bnzG5/6xnWVwTrJkJiIXVXsrKALxWwu3A2mI58Sj29zQ 4kY6R696vDoPfBnY8eWB22726eECB1QNlbJuzuReRh6LZEveo8ohSgySonOevmrnWUy2IKFcAH2 cJxVmMaHwvT/LZBmnH8pY1jwqSXCxg2SuX0sPHp5I0o= X-Received: by 2002:a05:600c:6287:b0:43c:ec0a:ddfd with SMTP id 5b1f17b1804b1-454ec13399cmr126953895e9.6.1752491090021; Mon, 14 Jul 2025 04:04:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJstCtnalZW33ajjrVUMQ8Oh8lPSDXJXXyqx652Mvv4s0WW9gOiZI2VRAM4rbxay8xwi+iqQ== X-Received: by 2002:a05:600c:6287:b0:43c:ec0a:ddfd with SMTP id 5b1f17b1804b1-454ec13399cmr126953535e9.6.1752491089444; Mon, 14 Jul 2025 04:04:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 15/77] i386/tdx: handle TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT Date: Mon, 14 Jul 2025 13:03:04 +0200 Message-ID: <20250714110406.117772-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491621972116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li Record the interrupt vector and the apic id of the vcpu that calls TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT. Inject the interrupt to TD guest to notify the completion of when notify interrupt vector is valid. Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250703024021.3559286-5-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx.h | 7 ++++++ target/i386/kvm/kvm.c | 3 +++ target/i386/kvm/tdx-stub.c | 4 ++++ target/i386/kvm/tdx.c | 48 +++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index d439078a876..1c38faf9834 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -25,6 +25,7 @@ typedef struct TdxGuestClass { =20 #define TDVMCALL_GET_TD_VM_CALL_INFO 0x10000 #define TDVMCALL_GET_QUOTE 0x10002 +#define TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT 0x10004 =20 #define TDG_VP_VMCALL_SUCCESS 0x0000000000000000ULL #define TDG_VP_VMCALL_RETRY 0x0000000000000001ULL @@ -32,6 +33,8 @@ typedef struct TdxGuestClass { #define TDG_VP_VMCALL_GPA_INUSE 0x8000000000000001ULL #define TDG_VP_VMCALL_ALIGN_ERROR 0x8000000000000002ULL =20 +#define TDG_VP_VMCALL_SUBFUNC_SET_EVENT_NOTIFY_INTERRUPT BIT_ULL(1) + enum TdxRamType { TDX_RAM_UNACCEPTED, TDX_RAM_ADDED, @@ -64,6 +67,9 @@ typedef struct TdxGuest { /* GetQuote */ SocketAddress *qg_sock_addr; int num; + + uint32_t event_notify_vector; + uint32_t event_notify_apicid; } TdxGuest; =20 #ifdef CONFIG_TDX @@ -78,5 +84,6 @@ int tdx_parse_tdvf(void *flash_ptr, int size); int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run); void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *run); void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run); +void tdx_handle_setup_event_notify_interrupt(X86CPU *cpu, struct kvm_run *= run); =20 #endif /* QEMU_I386_TDX_H */ diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 234878c613f..fc58a23b30d 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -6182,6 +6182,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run= *run) case TDVMCALL_GET_TD_VM_CALL_INFO: tdx_handle_get_tdvmcall_info(cpu, run); break; + case TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT: + tdx_handle_setup_event_notify_interrupt(cpu, run); + break; } ret =3D 0; break; diff --git a/target/i386/kvm/tdx-stub.c b/target/i386/kvm/tdx-stub.c index 76fee49eff0..1f0e108a69e 100644 --- a/target/i386/kvm/tdx-stub.c +++ b/target/i386/kvm/tdx-stub.c @@ -26,3 +26,7 @@ void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *ru= n) void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run) { } + +void tdx_handle_setup_event_notify_interrupt(X86CPU *cpu, struct kvm_run *= run) +{ +} diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 10dfb80d22e..fb31071dd81 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -28,10 +28,13 @@ #include "cpu.h" #include "cpu-internal.h" #include "host-cpu.h" +#include "hw/i386/apic_internal.h" +#include "hw/i386/apic-msidef.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/tdvf.h" #include "hw/i386/x86.h" #include "hw/i386/tdvf-hob.h" +#include "hw/pci/msi.h" #include "kvm_i386.h" #include "tdx.h" #include "tdx-quote-generator.h" @@ -1123,6 +1126,28 @@ int tdx_parse_tdvf(void *flash_ptr, int size) return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size); } =20 +static void tdx_inject_interrupt(uint32_t apicid, uint32_t vector) +{ + int ret; + + if (vector < 32 || vector > 255) { + return; + } + + MSIMessage msg =3D { + .address =3D ((apicid & 0xff) << MSI_ADDR_DEST_ID_SHIFT) | + (((uint64_t)apicid & 0xffffff00) << 32), + .data =3D vector | (APIC_DM_FIXED << MSI_DATA_DELIVERY_MODE_SHIFT), + }; + + ret =3D kvm_irqchip_send_msi(kvm_state, msg); + if (ret < 0) { + /* In this case, no better way to tell it to guest. Log it. */ + error_report("TDX: injection interrupt %d failed, interrupt lost (= %s).", + vector, strerror(-ret)); + } +} + static void tdx_get_quote_completion(TdxGenerateQuoteTask *task) { TdxGuest *tdx =3D task->opaque; @@ -1154,6 +1179,9 @@ static void tdx_get_quote_completion(TdxGenerateQuote= Task *task) error_report("TDX: get-quote: failed to update GetQuote header."); } =20 + tdx_inject_interrupt(tdx_guest->event_notify_apicid, + tdx_guest->event_notify_vector); + g_free(task->send_data); g_free(task->receive_buf); g_free(task); @@ -1256,7 +1284,7 @@ out_free: g_free(task); } =20 -#define SUPPORTED_TDVMCALLINFO_1_R11 (0) +#define SUPPORTED_TDVMCALLINFO_1_R11 (TDG_VP_VMCALL_SUBFUNC_SET_EVENT_N= OTIFY_INTERRUPT) #define SUPPORTED_TDVMCALLINFO_1_R12 (0) =20 void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run) @@ -1277,6 +1305,21 @@ void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struc= t kvm_run *run) run->tdx.get_tdvmcall_info.ret =3D TDG_VP_VMCALL_SUCCESS; } =20 +void tdx_handle_setup_event_notify_interrupt(X86CPU *cpu, struct kvm_run *= run) +{ + uint64_t vector =3D run->tdx.setup_event_notify.vector; + + if (vector >=3D 32 && vector < 256) { + qemu_mutex_lock(&tdx_guest->lock); + tdx_guest->event_notify_vector =3D vector; + tdx_guest->event_notify_apicid =3D cpu->apic_id; + qemu_mutex_unlock(&tdx_guest->lock); + run->tdx.setup_event_notify.ret =3D TDG_VP_VMCALL_SUCCESS; + } else { + run->tdx.setup_event_notify.ret =3D TDG_VP_VMCALL_INVALID_OPERAND; + } +} + static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code, char *message, uint64_t gpa) { @@ -1477,6 +1520,9 @@ static void tdx_guest_init(Object *obj) NULL, NULL); =20 qemu_mutex_init(&tdx->lock); + + tdx->event_notify_vector =3D -1; + tdx->event_notify_apicid =3D -1; } =20 static void tdx_guest_finalize(Object *obj) --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492516; cv=none; d=zohomail.com; s=zohoarc; b=h8ix9MzTV3v4zEY1YDHQl5uFJnXsRs13BBO2TEmTw3LX2+Swo5cKngm2+BePsDrG3hzGd5fTSW4Aidm9qWaC2nRTu4DI1WJSz501uRl5Uc3b4nupm4kxSeinUFM47VNy0RzUKUAeFti35o0ZxZt5pMI3K810ddpw3bjV+7IsohY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492516; h=Content-Type: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=CHd6YlxT7SR0dUhCUOeeHWrJJQghHVPSqPxhxBe2H6I=; b=k5rKLmN/No4QnveGHLQCql3K69j/GTzpZfQYPv/UTEpzYYZaZ4SKeJlexD/4hX9Ip5aOD1U7Afg+b16nZ5LHpLhGlG1X+bC7ft90k5V0zm+U2DkOycsmYXRJQKwsrrmwI2PFvbIJhFlv9kq7NSEABcDIO06IHzGcHr3x6wIZ3SQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492516130281.0826618704549; Mon, 14 Jul 2025 04:28:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHH7-0002eT-LZ; Mon, 14 Jul 2025 07:23:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzT-0000me-9X for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzR-0001c0-9q for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:04:58 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-jYku1juNPOy5jk3J9Rh4Jg-1; Mon, 14 Jul 2025 07:04:54 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-455e9daab1cso4838865e9.1 for ; Mon, 14 Jul 2025 04:04:54 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d5easm11981807f8f.48.2025.07.14.04.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CHd6YlxT7SR0dUhCUOeeHWrJJQghHVPSqPxhxBe2H6I=; b=ST80E8NOwoiQ68VrMR4nYa7nQlYikDWTs/40BTs9gy+pHRogdgq+T8EnLpu6LSPd3UH1Cn If0Gy837kPuPtIvfMVoa6oa4KOwdQXyW6CWPdxi3CMarO5EmrqB8vvDAQB2oz3zz/7z41Y TH/JYKn+/U60oBkQHaA0kuMUYv5t2uM= X-MC-Unique: jYku1juNPOy5jk3J9Rh4Jg-1 X-Mimecast-MFC-AGG-ID: jYku1juNPOy5jk3J9Rh4Jg_1752491093 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491092; x=1753095892; 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=CHd6YlxT7SR0dUhCUOeeHWrJJQghHVPSqPxhxBe2H6I=; b=HrCFjRyO4hnEt48MAnrgoxQ8di0BMac9pIfiYmWPSceLbFH3Eot3+c30Sk3vHZkt9n HuSWft3cbt6kg8Tekey20dW1YE/qw7EtG0/+RkHdEFW15C08FKN1NH0yajS1qsWW5ZpW /wD5Z4KRjqGUOltIS5rOaWrjU2Z2WqxG9QFNxC+Tm5CRAywvaBQ+XNYO8nMhd2deJVBN VWoKTfUbapnkY2kvXLnCTbup0OdiLP3lCi5RXCx8oT+Sg+tBa1w3aFmgf2R5oDwSQSxS IJHKEc01vvzxigqmuoNEueP8IP+2PJ4UsgAzpqMfMY6i+Us6DVfxcdB46FxUad2jevL7 m7oA== X-Gm-Message-State: AOJu0Yxiaw8AM2clBw4zCFRv/CTQpMCcE/0u+sq/z/gjRoO33nod0mZC Ypaq1Y3yAQlii3DNyDn6v+CG/Cb9NtxcBsixxTW3l7XjJLneNTFjSfJsl3agDitebd490rduuWB 4DDGep0VrSTmETttjhLphjdBRIczEhIFHkBmp2pL2XKSD0ijc610P7/48YqdzZ4Zh4UmFL2GYfo p4orxDK8G5TZG/zthYKmrwU9RNs9OReO/jR4j0cj4J X-Gm-Gg: ASbGncuR9WFUR5HJMQ62Kr1ZZZbYYo9HctEdq8EB2hxrPLK2Ks8f/blkhZqZJyb48Wy X9z6qy/kXBW3yKtZNRCR7pDsnXgud8GB0I8qG/hxt3bNkM6h4Dx9v/6rns/LnY/HfAshGsGYOs7 ORVzIn0GZzSeMa2F4gQrcM3vd+qQaxBvH2BQ3EhE+HYW8Uo+20mjyUM6TWFmBZ8mvOMakAna3Cd wEiYUtpSkYSiYYHcoKRGP0D7Ld8dzkCFGOwj4+Otil73tDN5V9qlt2TCEBGDBL3Ru/rYE1LJDe5 w0dWAK///Ocu4KmkpYe+C1sA8x16WlLMx0cUsMkhMWg= X-Received: by 2002:a05:600c:c4a6:b0:455:ed0f:e8d4 with SMTP id 5b1f17b1804b1-455ed0fedc6mr144023675e9.10.1752491092324; Mon, 14 Jul 2025 04:04:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH35YT0aMEGjdBP8pzHneR6Xz9SIAbgFNNpcby+WFWSLWTUc1AM8KqQrTvm7mtM62Q/y2iodg== X-Received: by 2002:a05:600c:c4a6:b0:455:ed0f:e8d4 with SMTP id 5b1f17b1804b1-455ed0fedc6mr144023215e9.10.1752491091779; Mon, 14 Jul 2025 04:04:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhenzhong Duan , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 16/77] i386/tdx: Fix the report of gpa in QAPI Date: Mon, 14 Jul 2025 13:03:05 +0200 Message-ID: <20250714110406.117772-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492517711116600 From: Zhenzhong Duan Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture. Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code. Fixes: 6e250463b08b ("i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic= facility") Signed-off-by: Zhenzhong Duan Reviewed-by: Daniel P. Berrang=C3=A9 Link: https://lore.kernel.org/r/20250710035538.303136-1-zhenzhong.duan@inte= l.com Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index fb31071dd81..7d69d6d7b06 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -1321,7 +1321,8 @@ void tdx_handle_setup_event_notify_interrupt(X86CPU *= cpu, struct kvm_run *run) } =20 static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code, - char *message, uint64_t gpa) + char *message, bool has_gpa, + uint64_t gpa) { GuestPanicInformation *panic_info; =20 @@ -1330,6 +1331,7 @@ static void tdx_panicked_on_fatal_error(X86CPU *cpu, = uint64_t error_code, panic_info->u.tdx.error_code =3D (uint32_t) error_code; panic_info->u.tdx.message =3D message; panic_info->u.tdx.gpa =3D gpa; + panic_info->u.tdx.has_gpa =3D has_gpa; =20 qemu_system_guest_panicked(panic_info); } @@ -1349,6 +1351,7 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct= kvm_run *run) char *message =3D NULL; uint64_t *tmp; uint64_t gpa =3D -1ull; + bool has_gpa =3D false; =20 if (error_code & 0xffff) { error_report("TDX: REPORT_FATAL_ERROR: invalid error code: 0x%"PRI= x64, @@ -1381,9 +1384,10 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struc= t kvm_run *run) =20 if (error_code & TDX_REPORT_FATAL_ERROR_GPA_VALID) { gpa =3D run->system_event.data[R_R13]; + has_gpa =3D true; } =20 - tdx_panicked_on_fatal_error(cpu, error_code, message, gpa); + tdx_panicked_on_fatal_error(cpu, error_code, message, has_gpa, gpa); =20 return -1; } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492164; cv=none; d=zohomail.com; s=zohoarc; b=P2d8SdyenF1VNCh+8LZjZbQC8/0omeWLCCj9BfkTOvSgMRagqpeOjB02zcsfl5dpG7QZCF2xs4ex11TkiT/Y8dRfA2lCTcPl7l+lIxZNOX9HedeAMSveTeCK773wVoncyisKT+JvoMl05RJenp1jkIZJkbJ1yXBF9sev8xJjJwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492164; h=Content-Type: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=TvaPDebJQqrXFfnLyyiynRkEMunN2jwXGo43DBM4hqM=; b=BiKpfbO/KZgcGoZREE2/nksCPv4Y3QxzMdhBFI2Dvl5dGZEY+H/S2WQIKbq/cxCxKdwsksolh/FqjdXCKSgaLZAtQCKhWuruKd/L89mWjqsSijiBg247SdeEddvJa+1ObNkSbinC90F4qh27SiYRq28opJa3BQ5X6ExCNIRCKE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492164436683.5345223385552; Mon, 14 Jul 2025 04:22:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7U-0008UK-GY; Mon, 14 Jul 2025 07:13:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzY-0000pO-RG for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzT-0001dd-LZ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:04 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-260-TI1Zl6mEMgS7hx2Au5kZ6w-1; Mon, 14 Jul 2025 07:04:57 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-455f7b86aeeso12296545e9.0 for ; Mon, 14 Jul 2025 04:04:57 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45614aeba29sm43525615e9.11.2025.07.14.04.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TvaPDebJQqrXFfnLyyiynRkEMunN2jwXGo43DBM4hqM=; b=RGToYhc2dZ68NY69GPTP1EHogzzDDkOoIn4T39Zx0JTuggoL7t0LSCBTLXqshRs8NDScEx NqJLsu7s40E87Ll5zGykqEJld6zZla9QmHxfzukD3AIyaHLChUHfDrtDakYL98VgrQrAW0 xjVc4RyAa2XTe5ATp7ORauKpt9k0ur0= X-MC-Unique: TI1Zl6mEMgS7hx2Au5kZ6w-1 X-Mimecast-MFC-AGG-ID: TI1Zl6mEMgS7hx2Au5kZ6w_1752491096 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491095; x=1753095895; 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=TvaPDebJQqrXFfnLyyiynRkEMunN2jwXGo43DBM4hqM=; b=uddZGCCCbpA1vnGCBo24YafrvAcEJFvP0nARSAEv7deEYb40UiS5M5Zkf6IRVCEA9e xAKaw43+lq9ZDNT2vRKnsN97Ake2OzvXaVYCCJ11y5b3Tz761q1p6jb1NGFN2M5EK1kL SQihV7E6OOHKeVY+mdGhUa50A3/cpU6ng1nbZLhjVPP8FJuWdkHgpZ3YZuYNPg2KW7nv wJJVcEUfs/Dvw74+AGVNvZlrgu/JBTHWLhKEFynDgy4xUyd80rS0/dmari50aSP3vkZl kAub2HiZAD7SfbvrS8P/Wztzm4SGHsFlOkhgDGzpGJqgaDqAlqP/zLCV+mXJ/XU3v5Vv YoSg== X-Gm-Message-State: AOJu0YzSOhysREXF9P6yIxfEY12+gKjIpQeK+k0xDDG/8MzYVtG6eNRx 4xXASgI156XdTc0pTJ52kMUZFHDSlInPKRki+qs6loSPuJZxqHl9Lnmn8df+jjNdpebqBBNHq46 pQvWjxWc6eZ56NAoebFJTOqBhpOwnmsKMvHGYu+J7Mi+tkTQwAoY3eXi+UIVPq/5lVLDi871xF3 xPAwrCr6Lk09hum+et8y2W/SVMlT6gDhnlgZrSnxHK X-Gm-Gg: ASbGnct+MZtgvCrbmdIR9nklDyDZK7MotxKgVQLglaAijVIvBtDZv6zVbel3jNpX+vV ZihvuiqfPhtlVRUvwE4QEKi+w9Oenm6hbsMHyD2LjD66mR1vCwk12+FMA2hVbkJq2TQ/H75NX3T mLGY/hXmXQga9OJGXK8qjpJNRTCfHCmzJRaCMCrPE/EkOGkAWZ6eeOhXFNctLDTJ7RWUzuTBrFF 6TUF000V0Sso7S9v0o7HV8ZCwhd5JQQ9zKK5O+DcZKgGN705QkB5pF/TuK/CwUXsMcC0Ov+Qctd FwnucAmLqFyULb50iO3vX+p/PT7R+LFfQPPRXE4ZuIE= X-Received: by 2002:a05:6000:2088:b0:3b3:a6e1:135c with SMTP id ffacd0b85a97d-3b5f2e32f4fmr8643404f8f.42.1752491094902; Mon, 14 Jul 2025 04:04:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9XRIDEC+alv0gL1xVW/RCLAQXcrsdsbZhO0y1skcuB05+k8bqSJfKl5Abficiw+qZ/rYbpg== X-Received: by 2002:a05:6000:2088:b0:3b3:a6e1:135c with SMTP id ffacd0b85a97d-3b5f2e32f4fmr8643376f8f.42.1752491094316; Mon, 14 Jul 2025 04:04:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Ani Sinha Subject: [PULL 17/77] meson: Add optional dependency on IGVM library Date: Mon, 14 Jul 2025 13:03:06 +0200 Message-ID: <20250714110406.117772-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492166182116600 From: Roy Hopkins The IGVM library allows Independent Guest Virtual Machine files to be parsed and processed. IGVM files are used to configure guest memory layout, initial processor state and other configuration pertaining to secure virtual machines. This adds the --enable-igvm configure option, enabled by default, which attempts to locate and link against the IGVM library via pkgconfig and sets CONFIG_IGVM if found. The library is added to the system_ss target in backends/meson.build where the IGVM parsing will be performed by the ConfidentialGuestSupport object. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/45945a83a638c3f08e68c025f378e7b7f4f6d593.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- meson.build | 8 ++++++++ backends/meson.build | 3 +++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 16 insertions(+) diff --git a/meson.build b/meson.build index b5f74aa37a7..200352c2448 100644 --- a/meson.build +++ b/meson.build @@ -1424,6 +1424,12 @@ if host_os =3D=3D 'linux' and (have_system or have_t= ools) method: 'pkg-config', required: get_option('libudev')) endif +igvm =3D not_found +if not get_option('igvm').auto() or have_system + igvm =3D dependency('igvm', version: '>=3D 0.3.0', + method: 'pkg-config', + required: get_option('igvm')) +endif =20 mpathlibs =3D [libudev] mpathpersist =3D not_found @@ -2601,6 +2607,7 @@ config_host_data.set('CONFIG_CFI', get_option('cfi')) config_host_data.set('CONFIG_SELINUX', selinux.found()) config_host_data.set('CONFIG_XEN_BACKEND', xen.found()) config_host_data.set('CONFIG_LIBDW', libdw.found()) +config_host_data.set('CONFIG_IGVM', igvm.found()) if xen.found() # protect from xen.version() having less than three components xen_version =3D xen.version().split('.') + ['0', '0'] @@ -4965,6 +4972,7 @@ summary_info +=3D {'seccomp support': seccomp} summary_info +=3D {'GlusterFS support': glusterfs} summary_info +=3D {'hv-balloon support': hv_balloon} summary_info +=3D {'TPM support': have_tpm} +summary_info +=3D {'IGVM support': igvm} summary_info +=3D {'libssh support': libssh} summary_info +=3D {'lzo support': lzo} summary_info +=3D {'snappy support': snappy} diff --git a/backends/meson.build b/backends/meson.build index 9b88d226851..ac0fac78458 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -34,6 +34,9 @@ if have_vhost_user_crypto endif system_ss.add(when: gio, if_true: files('dbus-vmstate.c')) system_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c')) +if igvm.found() + system_ss.add(igvm) +endif =20 system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c')) =20 diff --git a/meson_options.txt b/meson_options.txt index a442be29958..1e429311a2d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -117,6 +117,8 @@ option('tpm', type : 'feature', value : 'auto', description: 'TPM support') option('valgrind', type : 'feature', value: 'auto', description: 'valgrind debug support for coroutine stacks') +option('igvm', type: 'feature', value: 'auto', + description: 'Independent Guest Virtual Machine (IGVM) file support= ') =20 # Do not enable it by default even for Mingw32, because it doesn't # work on Wine. diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 73e0770f42b..78515404450 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -130,6 +130,7 @@ meson_options_help() { printf "%s\n" ' hv-balloon hv-balloon driver (requires Glib 2.68+ = GTree API)' printf "%s\n" ' hvf HVF acceleration support' printf "%s\n" ' iconv Font glyph conversion support' + printf "%s\n" ' igvm IGVM file support' printf "%s\n" ' jack JACK sound support' printf "%s\n" ' keyring Linux keyring support' printf "%s\n" ' kvm KVM acceleration support' @@ -346,6 +347,8 @@ _meson_option_parse() { --iasl=3D*) quote_sh "-Diasl=3D$2" ;; --enable-iconv) printf "%s" -Diconv=3Denabled ;; --disable-iconv) printf "%s" -Diconv=3Ddisabled ;; + --enable-igvm) printf "%s" -Digvm=3Denabled ;; + --disable-igvm) printf "%s" -Digvm=3Ddisabled ;; --includedir=3D*) quote_sh "-Dincludedir=3D$2" ;; --enable-install-blobs) printf "%s" -Dinstall_blobs=3Dtrue ;; --disable-install-blobs) printf "%s" -Dinstall_blobs=3Dfalse ;; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493040; cv=none; d=zohomail.com; s=zohoarc; b=geb0u1/JptJZBcceKE/5+luOa0U8FmbeZitDoyoX+qISOtSqKJWgvFsOyZEp8ZevjqP9qYhwr0i0NURGM6cu+E2GM+7qjpisxbGOF97hKBDJ5ruHdnHo2bLapzFtMPY/uyESgUZwRWuQ7jUTP5+a1rjYBVQirSEOvAzvMP2pEFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493040; 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=vaxjfdU0vDkaLBJ9OuBIEHWzWgK9r6h25+trEjoxvo4=; b=jEMz/qFKeYMVIfwOiYw0leGzdZDV3TF7mqGPdRw+Mtlu+CTp8Yu/eqk9kj0SL+w3oyFBxIRPWo/Z7PCMgQ5vujs71+q4Al5vjq36t/MVOSpdnt3PXOuWhSRN9MaaoBks3d+ABIv0/H4CpOXyJK6fP09UfiZNZnDn68oSLQA8NTI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493040646537.4664916041635; Mon, 14 Jul 2025 04:37:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEa-000860-T5; Mon, 14 Jul 2025 07:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGza-0000ql-Oo for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzW-0001ez-FG for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:06 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-cqzZkWjXNO6mK7yVp0XmlA-1; Mon, 14 Jul 2025 07:05:00 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-450df53d461so32605905e9.1 for ; Mon, 14 Jul 2025 04:05:00 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e14e82sm12162020f8f.71.2025.07.14.04.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491101; 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=vaxjfdU0vDkaLBJ9OuBIEHWzWgK9r6h25+trEjoxvo4=; b=hZ9ajpD41Rt/odmehK18IcSU1ICpfVrwjWLLdxczPOoZ9AtlPuRVkeLXkFRKDJ6KPamLke DCF2PcTCQdPLcOuHxGtCrHw4aTz1K7Xk2wcbD/DKcQvN6wdcTJRMSaUZQbkRsM+WBH980L DcIf7UR4f22HJHxsOIxZhQ+9+wMgHp0= X-MC-Unique: cqzZkWjXNO6mK7yVp0XmlA-1 X-Mimecast-MFC-AGG-ID: cqzZkWjXNO6mK7yVp0XmlA_1752491099 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491098; x=1753095898; 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=vaxjfdU0vDkaLBJ9OuBIEHWzWgK9r6h25+trEjoxvo4=; b=hS37TD/kYKyrj5hsBLdJqyfmoJ8Vnjx80JborogUGgrzB4QLV+LEq9qDsG3Wqz4bU9 m0tVuCF74ioHefswPALNWyfixXzno0AsKoXgEjLGcmAXrhREhxq/eorjGYUMVTIWwqEu ltrta+qXaGJo5/fTvzK3UD1I+P/En5p0iWIWyYl30upnaoWuRMMvnEEV/oH05U8fP1l9 YWOWcUXb+EmvoP1QbC76/1EZz0kLmywQGDkZ8e3e+/frduaKgGyNcWFtOsGyauDgyvnc C/efx+AU3SNd84g9DPJ/gV5olwf29i7KzoDHtNsZMBbhYjS+GHrAxmpNOyh4YH7WQNaw dSZw== X-Gm-Message-State: AOJu0YzTSjVsAXTlm3S6b4+bhkOhjOSLpNUgR3okQPzPwKZrEWEakcG6 1lXtAUwZswivWyk45WvqSGXKL94l+wEetwcwBW4FC38pqm5Aascs75ZfPDosCQSkVcrr2JO0r98 AgRSgghTsUbeqj4niNqyg7Ww907zZ7pq5FXqYBe8qaWZphQ5a+2SIeci0rE0cm47MQV/skNZlk9 Gr4i5PzupvFzr52kTvTxfakTSxcGYpVIUOe1LMWxPR X-Gm-Gg: ASbGnctWSp4vcQrP5JfiSmlKtAT8XbAJ0G2AOl5q9CzrJHgoalKzo5oXdllvS2khZCn Jp9Ji52oHaoFa4R4Hf8dLLhsc+F6XiAC8zSZ2kAQHQcmwblNOUrSOojaXHEfw3gpytAEAI6lF8g I/Ap5e4wtkKJi1G3LnWlgUgr85+1oZLbOS4zvc5p9vBK6NSIGTfmYfg+95MiEbBx7VBVuKV4mQd MiBQnVsjSpO7t4wTfeh4Dgp3rvqcCXjGXesypY0GRgLZBr4BIHlbqL4EOydXFfPbiSd7hOV1fpM Uyd44ZU4C9e9qP57bJH95n75RKIuCJPAeWMBgYmGFR8= X-Received: by 2002:a05:600c:1d87:b0:456:2a9:f815 with SMTP id 5b1f17b1804b1-45602a9fbfcmr69093865e9.4.1752491097963; Mon, 14 Jul 2025 04:04:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsdtCFXik9rtPHoSWaaPmdB8Evf8QfR5Gw6/TJBxfzBk3sMbt3M9UBxP6v6fadb4B5RCpEoA== X-Received: by 2002:a05:600c:1d87:b0:456:2a9:f815 with SMTP id 5b1f17b1804b1-45602a9fbfcmr69093575e9.4.1752491097369; Mon, 14 Jul 2025 04:04:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , Stefano Garzarella , Ani Sinha Subject: [PULL 18/77] backends/confidential-guest-support: Add functions to support IGVM Date: Mon, 14 Jul 2025 13:03:07 +0200 Message-ID: <20250714110406.117772-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493042218116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins In preparation for supporting the processing of IGVM files to configure guests, this adds a set of functions to ConfidentialGuestSupport allowing configuration of secure virtual machines that can be implemented for each supported isolation platform type such as Intel TDX or AMD SEV-SNP. These functions will be called by IGVM processing code in subsequent patches. This commit provides a default implementation of the functions that either perform no action or generate an error when they are called. Targets that support ConfidentalGuestSupport should override these implementations. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/23e34a106da87427899f93178102e4a6ef50c966.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- include/system/confidential-guest-support.h | 67 +++++++++++++++++++++ backends/confidential-guest-support.c | 31 ++++++++++ 2 files changed, 98 insertions(+) diff --git a/include/system/confidential-guest-support.h b/include/system/c= onfidential-guest-support.h index ea46b50c56c..79ecd21f42f 100644 --- a/include/system/confidential-guest-support.h +++ b/include/system/confidential-guest-support.h @@ -19,6 +19,7 @@ #define QEMU_CONFIDENTIAL_GUEST_SUPPORT_H =20 #include "qom/object.h" +#include "exec/hwaddr.h" =20 #define TYPE_CONFIDENTIAL_GUEST_SUPPORT "confidential-guest-support" OBJECT_DECLARE_TYPE(ConfidentialGuestSupport, @@ -26,6 +27,36 @@ OBJECT_DECLARE_TYPE(ConfidentialGuestSupport, CONFIDENTIAL_GUEST_SUPPORT) =20 =20 +typedef enum ConfidentialGuestPlatformType { + CGS_PLATFORM_SEV, + CGS_PLATFORM_SEV_ES, + CGS_PLATFORM_SEV_SNP, +} ConfidentialGuestPlatformType; + +typedef enum ConfidentialGuestMemoryType { + CGS_MEM_RAM, + CGS_MEM_RESERVED, + CGS_MEM_ACPI, + CGS_MEM_NVS, + CGS_MEM_UNUSABLE, +} ConfidentialGuestMemoryType; + +typedef struct ConfidentialGuestMemoryMapEntry { + uint64_t gpa; + uint64_t size; + ConfidentialGuestMemoryType type; +} ConfidentialGuestMemoryMapEntry; + +typedef enum ConfidentialGuestPageType { + CGS_PAGE_TYPE_NORMAL, + CGS_PAGE_TYPE_VMSA, + CGS_PAGE_TYPE_ZERO, + CGS_PAGE_TYPE_UNMEASURED, + CGS_PAGE_TYPE_SECRETS, + CGS_PAGE_TYPE_CPUID, + CGS_PAGE_TYPE_REQUIRED_MEMORY, +} ConfidentialGuestPageType; + struct ConfidentialGuestSupport { Object parent; =20 @@ -64,6 +95,42 @@ typedef struct ConfidentialGuestSupportClass { =20 int (*kvm_init)(ConfidentialGuestSupport *cgs, Error **errp); int (*kvm_reset)(ConfidentialGuestSupport *cgs, Error **errp); + + /* + * Check to see if this confidential guest supports a particular + * platform or configuration. + * + * Return true if supported or false if not supported. + */ + bool (*check_support)(ConfidentialGuestPlatformType platform, + uint16_t platform_version, uint8_t highest_vtl, + uint64_t shared_gpa_boundary); + + /* + * Configure part of the state of a guest for a particular set of data= , page + * type and gpa. This can be used for example to pre-populate and meas= ure + * guest memory contents, define private ranges or set the initial CPU= state + * for one or more CPUs. + * + * If memory_type is CGS_PAGE_TYPE_VMSA then ptr points to the initial= CPU + * context for a virtual CPU. The format of the data depends on the ty= pe of + * confidential virtual machine. For example, for SEV-ES ptr will poin= t to a + * vmcb_save_area structure that should be copied into guest memory at= the + * address specified in gpa. The cpu_index parameter contains the inde= x of + * the CPU the VMSA applies to. + */ + int (*set_guest_state)(hwaddr gpa, uint8_t *ptr, uint64_t len, + ConfidentialGuestPageType memory_type, + uint16_t cpu_index, Error **errp); + + /* + * Iterate the system memory map, getting the entry with the given ind= ex + * that can be populated into guest memory. + * + * Returns 0 for ok, 1 if the index is out of range and -1 on error. + */ + int (*get_mem_map_entry)(int index, ConfidentialGuestMemoryMapEntry *e= ntry, + Error **errp); } ConfidentialGuestSupportClass; =20 static inline int confidential_guest_kvm_init(ConfidentialGuestSupport *cg= s, diff --git a/backends/confidential-guest-support.c b/backends/confidential-= guest-support.c index 8ff7bfa8570..c5bef1fbfa8 100644 --- a/backends/confidential-guest-support.c +++ b/backends/confidential-guest-support.c @@ -14,15 +14,46 @@ #include "qemu/osdep.h" =20 #include "system/confidential-guest-support.h" +#include "qapi/error.h" =20 OBJECT_DEFINE_ABSTRACT_TYPE(ConfidentialGuestSupport, confidential_guest_support, CONFIDENTIAL_GUEST_SUPPORT, OBJECT) =20 +static bool check_support(ConfidentialGuestPlatformType platform, + uint16_t platform_version, uint8_t highest_vtl, + uint64_t shared_gpa_boundary) +{ + /* Default: no support. */ + return false; +} + +static int set_guest_state(hwaddr gpa, uint8_t *ptr, uint64_t len, + ConfidentialGuestPageType memory_type, + uint16_t cpu_index, Error **errp) +{ + error_setg(errp, + "Setting confidential guest state is not supported for this= platform"); + return -1; +} + +static int get_mem_map_entry(int index, ConfidentialGuestMemoryMapEntry *e= ntry, + Error **errp) +{ + error_setg( + errp, + "Obtaining the confidential guest memory map is not supported for = this platform"); + return -1; +} + static void confidential_guest_support_class_init(ObjectClass *oc, const void *data) { + ConfidentialGuestSupportClass *cgsc =3D CONFIDENTIAL_GUEST_SUPPORT_CLA= SS(oc); + cgsc->check_support =3D check_support; + cgsc->set_guest_state =3D set_guest_state; + cgsc->get_mem_map_entry =3D get_mem_map_entry; } =20 static void confidential_guest_support_init(Object *obj) --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491627; cv=none; d=zohomail.com; s=zohoarc; b=H4FlK7vufzGwWVfxTghrRRSU6/hUejnSXcgqkG+xn7LlIvIj8XjXAZrF45tpC65+pygy+b90PYUwzZ0h19fquy1mKAsUEA6f/VODS5unYnluTCVN/kvNqYsT+eE9/vifr3UcPtZphnz9wTUofTkSELy2NYHnhiX9pj6YaLUg00Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491627; 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=cVSDzAtwaFD9fiToH2+ocY4Vipill1SaMZ1A9opcZdk=; b=iqIuryE2JlcUa4X5bTGXBC776ASkLpZl9vJynMHmh3XjPiBcbtltnQzkZO+dU3C7m0KyvJY/L2JURnLnKTdfOs+DdaPhFhRgzhRzI2hNXwwIxIKJIvRL2xmtmG/Q9UZB0i4iw/1VwJwBeSJOQQgI89STcu7xUET4/Shax5YwWfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491627843186.41043559819968; Mon, 14 Jul 2025 04:13:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7g-0000mN-2a; Mon, 14 Jul 2025 07:13:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGze-0000sh-Gt for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGza-0001qA-Dt for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:10 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-MBIEOwLPM1CoGF2tx6uINw-1; Mon, 14 Jul 2025 07:05:04 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-451ecc3be97so22098885e9.0 for ; Mon, 14 Jul 2025 04:05:03 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e211dcsm11838403f8f.84.2025.07.14.04.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491105; 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=cVSDzAtwaFD9fiToH2+ocY4Vipill1SaMZ1A9opcZdk=; b=HtCGzqtwQ/CXFYNUA2xa5z6LconCwXrsIQtL+EFnoJG11BHapnV/O6/wjUQe8v+hiIZEas 8YLdjif3niMmR4SIoKJ5s9c4/IaXb9WzdETtGxDTri6eLqSg2pAzTQnzP74IQPGqSQ+4dt 3RBX8ueEuCfK3bbN6YrxbrMmwbal3uY= X-MC-Unique: MBIEOwLPM1CoGF2tx6uINw-1 X-Mimecast-MFC-AGG-ID: MBIEOwLPM1CoGF2tx6uINw_1752491103 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491102; x=1753095902; 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=cVSDzAtwaFD9fiToH2+ocY4Vipill1SaMZ1A9opcZdk=; b=qlvEBx/l4iUpngFGrHau16uO1MaZvM1h/sPTj+4FkPGb9ErDaGJwaUiTNBRz3qPhHU b8Y4WvBxNHsxqcXH6laD/kyzgRI0u+AV9RIMyNt0+nGCD7UmudZ30LnpkiYHy0CD7HcI Tobw80L5xEBaUSseyFWBcpH8K+mIKLTHpKeNNgb0s1AgIautPwP2KINagA8r2QpBmGha cXbE8icaocM3v5Tp5Sp7E9a0txJaLh0QlrxGsxlDqcrA9KOxAbz0h61XfiuyYLZ4/M3h YLec5qjQFm6KOHRahweCJ9KBglnbYb8qCSnpF8z+ahEjoLuqIAGtYdfZxLI+Ze5mH5dH jIZQ== X-Gm-Message-State: AOJu0YxMNkAhqrwjk34IN5qfW7AHRX5ERJRwqC6JpZzcLvjelA/M7iwt XJvb6UFKZX0U+q9Mowgbg91Alo5uMamq02AsYdCMMgOlLq5IeeomQFRW57Sz0uQe//YRmOvWBkV 35H19/VJ9FkeMLAszPltcNuH/OYUgqHUSwr5gijvAIWRw5LpoY847xOjjttALGm1Y9ZjGtiSaEY SRjo4JF1vyiGcz0GjxlCvwPeM1qDdfmrfoV6HSIZBF X-Gm-Gg: ASbGncu2yIoLdWoJSMbsAMBGoMiODoYKHXqa2K+RGhFF2YRzYmOKDUC/bsKapol6XHY qqye3V2HCQIYraC5cnV0+m+bt4L9mdMtz4zhY+JGG1e2yEDNHufirgR/mUu0fFh4i4ZbyjQJndx jIyYUTNWC8no8P6KjqeLBStubI4Xt90bbCJH/oUeADQuZdYuDY8QIVTrII0l1SZ2pfBZsr2biu3 J2IDRSb7Iff5KUjuHVycdIipL69lg8QxAUZE/PSegB/DHbSCKooysVfBjaOkHee1CrZr+grvrCJ M5u4nTRURCS5pEwKm022TJZbCLR9D51dkaMNHhnkgug= X-Received: by 2002:a05:600c:34d1:b0:456:1d61:b0f2 with SMTP id 5b1f17b1804b1-4561d61b16amr21038445e9.30.1752491101236; Mon, 14 Jul 2025 04:05:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbWP3GpQ39d7rZiFAE0vqkieHgWItnvyhDL6KcBE+b/uxwV9RS7CCxtAZSnhQdyRIYJ7DauA== X-Received: by 2002:a05:600c:34d1:b0:456:1d61:b0f2 with SMTP id 5b1f17b1804b1-4561d61b16amr21037915e9.30.1752491100473; Mon, 14 Jul 2025 04:05:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , Stefano Garzarella Subject: [PULL 19/77] backends/igvm: Add IGVM loader and configuration Date: Mon, 14 Jul 2025 13:03:08 +0200 Message-ID: <20250714110406.117772-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491634233116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins Adds an IGVM loader to QEMU which processes a given IGVM file and applies the directives within the file to the current guest configuration. The IGVM loader can be used to configure both confidential and non-confidential guests. For confidential guests, the ConfidentialGuestSupport object for the system is used to encrypt memory, apply the initial CPU state and perform other confidential guest operations. The loader is configured via a new IgvmCfg QOM object which allows the user to provide a path to the IGVM file to process. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Stefano Garzarella Link: https://lore.kernel.org/r/ae3a07d8f514d93845a9c16bb155c847cb567b0d.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- qapi/qom.json | 17 + backends/igvm.h | 22 ++ include/system/igvm-cfg.h | 46 +++ backends/igvm-cfg.c | 51 +++ backends/igvm.c | 807 ++++++++++++++++++++++++++++++++++++++ backends/meson.build | 2 + 6 files changed, 945 insertions(+) create mode 100644 backends/igvm.h create mode 100644 include/system/igvm-cfg.h create mode 100644 backends/igvm-cfg.c create mode 100644 backends/igvm.c diff --git a/qapi/qom.json b/qapi/qom.json index b133b064471..bbdb56dced6 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -932,6 +932,19 @@ 'data': { '*filename': 'str' }, 'if': 'CONFIG_POSIX' } =20 +## +# @IgvmCfgProperties: +# +# Properties common to objects that handle IGVM files. +# +# @file: IGVM file to use to configure guest +# +# Since: 10.1 +## +{ 'struct': 'IgvmCfgProperties', + 'if': 'CONFIG_IGVM', + 'data': { 'file': 'str' } } + ## # @SevCommonProperties: # @@ -1142,6 +1155,8 @@ 'filter-redirector', 'filter-replay', 'filter-rewriter', + { 'name': 'igvm-cfg', + 'if': 'CONFIG_IGVM' }, 'input-barrier', { 'name': 'input-linux', 'if': 'CONFIG_LINUX' }, @@ -1218,6 +1233,8 @@ 'filter-redirector': 'FilterRedirectorProperties', 'filter-replay': 'NetfilterProperties', 'filter-rewriter': 'FilterRewriterProperties', + 'igvm-cfg': { 'type': 'IgvmCfgProperties', + 'if': 'CONFIG_IGVM' }, 'input-barrier': 'InputBarrierProperties', 'input-linux': { 'type': 'InputLinuxProperties', 'if': 'CONFIG_LINUX' }, diff --git a/backends/igvm.h b/backends/igvm.h new file mode 100644 index 00000000000..db02ea91651 --- /dev/null +++ b/backends/igvm.h @@ -0,0 +1,22 @@ +/* + * QEMU IGVM configuration backend for Confidential Guests + * + * Copyright (C) 2023-2024 SUSE + * + * Authors: + * Roy Hopkins + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BACKENDS_IGVM_H +#define BACKENDS_IGVM_H + +#include "system/confidential-guest-support.h" +#include "system/igvm-cfg.h" +#include "qapi/error.h" + +int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs, + Error **errp); + +#endif diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h new file mode 100644 index 00000000000..321b3196f09 --- /dev/null +++ b/include/system/igvm-cfg.h @@ -0,0 +1,46 @@ +/* + * QEMU IGVM interface + * + * Copyright (C) 2024 SUSE + * + * Authors: + * Roy Hopkins + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_IGVM_CFG_H +#define QEMU_IGVM_CFG_H + +#include "qom/object.h" + +typedef struct IgvmCfg { + ObjectClass parent_class; + + /* + * filename: Filename that specifies a file that contains the configur= ation + * of the guest in Independent Guest Virtual Machine (IGVM) + * format. + */ + char *filename; +} IgvmCfg; + +typedef struct IgvmCfgClass { + ObjectClass parent_class; + + /* + * If an IGVM filename has been specified then process the IGVM file. + * Performs a no-op if no filename has been specified. + * + * Returns 0 for ok and -1 on error. + */ + int (*process)(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, + Error **errp); + +} IgvmCfgClass; + +#define TYPE_IGVM_CFG "igvm-cfg" + +OBJECT_DECLARE_TYPE(IgvmCfg, IgvmCfgClass, IGVM_CFG) + +#endif diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c new file mode 100644 index 00000000000..45df63e06c1 --- /dev/null +++ b/backends/igvm-cfg.c @@ -0,0 +1,51 @@ +/* + * QEMU IGVM interface + * + * Copyright (C) 2023-2024 SUSE + * + * Authors: + * Roy Hopkins + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "system/igvm-cfg.h" +#include "igvm.h" +#include "qom/object_interfaces.h" + +static char *get_igvm(Object *obj, Error **errp) +{ + IgvmCfg *igvm =3D IGVM_CFG(obj); + return g_strdup(igvm->filename); +} + +static void set_igvm(Object *obj, const char *value, Error **errp) +{ + IgvmCfg *igvm =3D IGVM_CFG(obj); + g_free(igvm->filename); + igvm->filename =3D g_strdup(value); +} + +OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT, + { TYPE_USER_CREATABLE }, { NULL }) + +static void igvm_cfg_class_init(ObjectClass *oc, const void *data) +{ + IgvmCfgClass *igvmc =3D IGVM_CFG_CLASS(oc); + + object_class_property_add_str(oc, "file", get_igvm, set_igvm); + object_class_property_set_description(oc, "file", + "Set the IGVM filename to use"); + + igvmc->process =3D qigvm_process_file; +} + +static void igvm_cfg_init(Object *obj) +{ +} + +static void igvm_cfg_finalize(Object *obj) +{ +} diff --git a/backends/igvm.c b/backends/igvm.c new file mode 100644 index 00000000000..2a31021d449 --- /dev/null +++ b/backends/igvm.c @@ -0,0 +1,807 @@ +/* + * QEMU IGVM configuration backend for guests + * + * Copyright (C) 2023-2024 SUSE + * + * Authors: + * Roy Hopkins + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "igvm.h" +#include "qapi/error.h" +#include "system/memory.h" +#include "system/address-spaces.h" +#include "hw/core/cpu.h" + +#include +#include + +typedef struct QIgvmParameterData { + QTAILQ_ENTRY(QIgvmParameterData) next; + uint8_t *data; + uint32_t size; + uint32_t index; +} QIgvmParameterData; + +/* + * QIgvm contains the information required during processing + * of a single IGVM file. + */ +typedef struct QIgvm { + IgvmHandle file; + ConfidentialGuestSupport *cgs; + ConfidentialGuestSupportClass *cgsc; + uint32_t compatibility_mask; + unsigned current_header_index; + QTAILQ_HEAD(, QIgvmParameterData) parameter_data; + + /* These variables keep track of contiguous page regions */ + IGVM_VHS_PAGE_DATA region_prev_page_data; + uint64_t region_start; + unsigned region_start_index; + unsigned region_last_index; + unsigned region_page_count; +} QIgvm; + +static int qigvm_directive_page_data(QIgvm *ctx, const uint8_t *header_dat= a, + Error **errp); +static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_da= ta, + Error **errp); +static int qigvm_directive_parameter_area(QIgvm *ctx, + const uint8_t *header_data, + Error **errp); +static int qigvm_directive_parameter_insert(QIgvm *ctx, + const uint8_t *header_data, + Error **errp); +static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_da= ta, + Error **errp); +static int qigvm_directive_vp_count(QIgvm *ctx, const uint8_t *header_data, + Error **errp); +static int qigvm_directive_environment_info(QIgvm *ctx, + const uint8_t *header_data, + Error **errp); +static int qigvm_directive_required_memory(QIgvm *ctx, + const uint8_t *header_data, + Error **errp); + +struct QIGVMHandler { + uint32_t type; + uint32_t section; + int (*handler)(QIgvm *ctx, const uint8_t *header_data, Error **errp); +}; + +static struct QIGVMHandler handlers[] =3D { + { IGVM_VHT_PAGE_DATA, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_page_data }, + { IGVM_VHT_VP_CONTEXT, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_vp_context }, + { IGVM_VHT_PARAMETER_AREA, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_parameter_area }, + { IGVM_VHT_PARAMETER_INSERT, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_parameter_insert }, + { IGVM_VHT_MEMORY_MAP, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_memory_map }, + { IGVM_VHT_VP_COUNT_PARAMETER, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_vp_count }, + { IGVM_VHT_ENVIRONMENT_INFO_PARAMETER, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_environment_info }, + { IGVM_VHT_REQUIRED_MEMORY, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_required_memory }, +}; + +static int qigvm_handler(QIgvm *ctx, uint32_t type, Error **errp) +{ + size_t handler; + IgvmHandle header_handle; + const uint8_t *header_data; + int result; + + for (handler =3D 0; handler < G_N_ELEMENTS(handlers); handler++) { + if (handlers[handler].type !=3D type) { + continue; + } + header_handle =3D igvm_get_header(ctx->file, handlers[handler].sec= tion, + ctx->current_header_index); + if (header_handle < 0) { + error_setg( + errp, + "IGVM file is invalid: Failed to read directive header (co= de: %d)", + (int)header_handle); + return -1; + } + header_data =3D igvm_get_buffer(ctx->file, header_handle) + + sizeof(IGVM_VHS_VARIABLE_HEADER); + result =3D handlers[handler].handler(ctx, header_data, errp); + igvm_free_buffer(ctx->file, header_handle); + return result; + } + error_setg(errp, + "IGVM: Unknown header type encountered when processing file= : " + "(type 0x%X)", + type); + return -1; +} + +static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size, + int region_identifier, Error **errp) +{ + ERRP_GUARD(); + MemoryRegion *igvm_pages =3D NULL; + Int128 gpa_region_size; + MemoryRegionSection mrs =3D + memory_region_find(get_system_memory(), addr, size); + if (mrs.mr) { + if (!memory_region_is_ram(mrs.mr)) { + memory_region_unref(mrs.mr); + error_setg( + errp, + "Processing of IGVM file failed: Could not prepare memory " + "at address 0x%lX due to existing non-RAM region", + addr); + return NULL; + } + + gpa_region_size =3D int128_make64(size); + if (int128_lt(mrs.size, gpa_region_size)) { + memory_region_unref(mrs.mr); + error_setg( + errp, + "Processing of IGVM file failed: Could not prepare memory " + "at address 0x%lX: region size exceeded", + addr); + return NULL; + } + return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_regio= n); + } else { + /* + * The region_identifier is the is the index of the IGVM directive= that + * contains the page with the lowest GPA in the region. This will + * generate a unique region name. + */ + g_autofree char *region_name =3D + g_strdup_printf("igvm.%X", region_identifier); + igvm_pages =3D g_new0(MemoryRegion, 1); + if (ctx->cgs && ctx->cgs->require_guest_memfd) { + if (!memory_region_init_ram_guest_memfd(igvm_pages, NULL, + region_name, size, err= p)) { + return NULL; + } + } else { + if (!memory_region_init_ram(igvm_pages, NULL, region_name, siz= e, + errp)) { + return NULL; + } + } + memory_region_add_subregion(get_system_memory(), addr, igvm_pages); + return memory_region_get_ram_ptr(igvm_pages); + } +} + +static int qigvm_type_to_cgs_type(IgvmPageDataType memory_type, bool unmea= sured, + bool zero) +{ + switch (memory_type) { + case IGVM_PAGE_DATA_TYPE_NORMAL: { + if (unmeasured) { + return CGS_PAGE_TYPE_UNMEASURED; + } else { + return zero ? CGS_PAGE_TYPE_ZERO : CGS_PAGE_TYPE_NORMAL; + } + } + case IGVM_PAGE_DATA_TYPE_SECRETS: + return CGS_PAGE_TYPE_SECRETS; + case IGVM_PAGE_DATA_TYPE_CPUID_DATA: + return CGS_PAGE_TYPE_CPUID; + case IGVM_PAGE_DATA_TYPE_CPUID_XF: + return CGS_PAGE_TYPE_CPUID; + default: + return -1; + } +} + +static bool qigvm_page_attrs_equal(IgvmHandle igvm, unsigned header_index, + const IGVM_VHS_PAGE_DATA *page_1, + const IGVM_VHS_PAGE_DATA *page_2) +{ + IgvmHandle data_handle1, data_handle2; + + /* + * If one page has data and the other doesn't then this results in dif= ferent + * page types: NORMAL vs ZERO. + */ + data_handle1 =3D igvm_get_header_data(igvm, IGVM_HEADER_SECTION_DIRECT= IVE, + header_index - 1); + data_handle2 =3D + igvm_get_header_data(igvm, IGVM_HEADER_SECTION_DIRECTIVE, header_i= ndex); + if ((data_handle1 =3D=3D IGVMAPI_NO_DATA || + data_handle2 =3D=3D IGVMAPI_NO_DATA) && + data_handle1 !=3D data_handle2) { + return false; + } + return ((*(const uint32_t *)&page_1->flags =3D=3D + *(const uint32_t *)&page_2->flags) && + (page_1->data_type =3D=3D page_2->data_type) && + (page_1->compatibility_mask =3D=3D page_2->compatibility_mask)= ); +} + +static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index, + uint64_t gpa_start, unsigned page_coun= t, + const IgvmPageDataFlags *flags, + const IgvmPageDataType page_type, + Error **errp) +{ + uint8_t *region; + IgvmHandle data_handle; + const void *data; + uint32_t data_size; + unsigned page_index; + bool zero =3D true; + const uint64_t page_size =3D flags->is_2mb_page ? 0x200000 : 0x1000; + int result; + int cgs_page_type; + + region =3D qigvm_prepare_memory(ctx, gpa_start, page_count * page_size, + start_index, errp); + if (!region) { + return -1; + } + + for (page_index =3D 0; page_index < page_count; page_index++) { + data_handle =3D igvm_get_header_data( + ctx->file, IGVM_HEADER_SECTION_DIRECTIVE, page_index + start_i= ndex); + if (data_handle =3D=3D IGVMAPI_NO_DATA) { + /* No data indicates a zero page */ + memset(®ion[page_index * page_size], 0, page_size); + } else if (data_handle < 0) { + error_setg( + errp, + "IGVM file contains invalid page data for directive with " + "index %d", + page_index + start_index); + return -1; + } else { + zero =3D false; + data_size =3D igvm_get_buffer_size(ctx->file, data_handle); + if (data_size < page_size) { + memset(®ion[page_index * page_size], 0, page_size); + } else if (data_size > page_size) { + error_setg(errp, + "IGVM file contains page data with invalid size= for " + "directive with index %d", + page_index + start_index); + return -1; + } + data =3D igvm_get_buffer(ctx->file, data_handle); + memcpy(®ion[page_index * page_size], data, data_size); + igvm_free_buffer(ctx->file, data_handle); + } + } + + /* + * If a confidential guest support object is provided then use it to s= et the + * guest state. + */ + if (ctx->cgs) { + cgs_page_type =3D + qigvm_type_to_cgs_type(page_type, flags->unmeasured, zero); + if (cgs_page_type < 0) { + error_setg(errp, + "Invalid page type in IGVM file. Directives: %d to = %d, " + "page type: %d", + start_index, start_index + page_count, page_type); + return -1; + } + + result =3D ctx->cgsc->set_guest_state( + gpa_start, region, page_size * page_count, cgs_page_type, 0, e= rrp); + if (result < 0) { + return result; + } + } + return 0; +} + +static int qigvm_process_mem_page(QIgvm *ctx, + const IGVM_VHS_PAGE_DATA *page_data, + Error **errp) +{ + if (page_data) { + if (ctx->region_page_count =3D=3D 0) { + ctx->region_start =3D page_data->gpa; + ctx->region_start_index =3D ctx->current_header_index; + } else { + if (!qigvm_page_attrs_equal(ctx->file, ctx->current_header_ind= ex, + page_data, + &ctx->region_prev_page_data) || + ((ctx->region_prev_page_data.gpa + + (ctx->region_prev_page_data.flags.is_2mb_page ? 0x200000= : + 0x1000))= !=3D + page_data->gpa) || + (ctx->region_last_index !=3D (ctx->current_header_index - = 1))) { + /* End of current region */ + if (qigvm_process_mem_region( + ctx, ctx->region_start_index, ctx->region_start, + ctx->region_page_count, + &ctx->region_prev_page_data.flags, + ctx->region_prev_page_data.data_type, errp) < 0) { + return -1; + } + ctx->region_page_count =3D 0; + ctx->region_start =3D page_data->gpa; + ctx->region_start_index =3D ctx->current_header_index; + } + } + memcpy(&ctx->region_prev_page_data, page_data, + sizeof(ctx->region_prev_page_data)); + ctx->region_last_index =3D ctx->current_header_index; + ctx->region_page_count++; + } else { + if (ctx->region_page_count > 0) { + if (qigvm_process_mem_region( + ctx, ctx->region_start_index, ctx->region_start, + ctx->region_page_count, &ctx->region_prev_page_data.fl= ags, + ctx->region_prev_page_data.data_type, errp) < 0) { + return -1; + } + ctx->region_page_count =3D 0; + } + } + return 0; +} + +static int qigvm_directive_page_data(QIgvm *ctx, const uint8_t *header_dat= a, + Error **errp) +{ + const IGVM_VHS_PAGE_DATA *page_data =3D + (const IGVM_VHS_PAGE_DATA *)header_data; + if (page_data->compatibility_mask & ctx->compatibility_mask) { + return qigvm_process_mem_page(ctx, page_data, errp); + } + return 0; +} + +static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_da= ta, + Error **errp) +{ + const IGVM_VHS_VP_CONTEXT *vp_context =3D + (const IGVM_VHS_VP_CONTEXT *)header_data; + IgvmHandle data_handle; + uint8_t *data; + int result; + + if (!(vp_context->compatibility_mask & ctx->compatibility_mask)) { + return 0; + } + + /* + * A confidential guest support object must be provided for setting + * a VP context. + */ + if (!ctx->cgs) { + error_setg( + errp, + "A VP context is present in the IGVM file but is not supported= " + "by the current system."); + return -1; + } + + data_handle =3D igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DI= RECTIVE, + ctx->current_header_index); + if (data_handle < 0) { + error_setg(errp, "Invalid VP context in IGVM file. Error code: %X", + data_handle); + return -1; + } + + data =3D (uint8_t *)igvm_get_buffer(ctx->file, data_handle); + result =3D ctx->cgsc->set_guest_state( + vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_handle= ), + CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp); + igvm_free_buffer(ctx->file, data_handle); + if (result < 0) { + return result; + } + return 0; +} + +static int qigvm_directive_parameter_area(QIgvm *ctx, + const uint8_t *header_data, + Error **errp) +{ + const IGVM_VHS_PARAMETER_AREA *param_area =3D + (const IGVM_VHS_PARAMETER_AREA *)header_data; + QIgvmParameterData *param_entry; + + param_entry =3D g_new0(QIgvmParameterData, 1); + param_entry->size =3D param_area->number_of_bytes; + param_entry->index =3D param_area->parameter_area_index; + param_entry->data =3D g_malloc0(param_entry->size); + + QTAILQ_INSERT_TAIL(&ctx->parameter_data, param_entry, next); + return 0; +} + +static int qigvm_directive_parameter_insert(QIgvm *ctx, + const uint8_t *header_data, + Error **errp) +{ + const IGVM_VHS_PARAMETER_INSERT *param =3D + (const IGVM_VHS_PARAMETER_INSERT *)header_data; + QIgvmParameterData *param_entry; + int result; + void *region; + + if (!(param->compatibility_mask & ctx->compatibility_mask)) { + return 0; + } + + QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next) + { + if (param_entry->index =3D=3D param->parameter_area_index) { + region =3D qigvm_prepare_memory(ctx, param->gpa, param_entry->= size, + ctx->current_header_index, errp); + if (!region) { + return -1; + } + memcpy(region, param_entry->data, param_entry->size); + g_free(param_entry->data); + param_entry->data =3D NULL; + + /* + * If a confidential guest support object is provided then use= it to + * set the guest state. + */ + if (ctx->cgs) { + result =3D ctx->cgsc->set_guest_state(param->gpa, region, + param_entry->size, + CGS_PAGE_TYPE_UNMEASUR= ED, 0, + errp); + if (result < 0) { + return -1; + } + } + } + } + return 0; +} + +static int qigvm_cmp_mm_entry(const void *a, const void *b) +{ + const IGVM_VHS_MEMORY_MAP_ENTRY *entry_a =3D + (const IGVM_VHS_MEMORY_MAP_ENTRY *)a; + const IGVM_VHS_MEMORY_MAP_ENTRY *entry_b =3D + (const IGVM_VHS_MEMORY_MAP_ENTRY *)b; + if (entry_a->starting_gpa_page_number < entry_b->starting_gpa_page_num= ber) { + return -1; + } else if (entry_a->starting_gpa_page_number > + entry_b->starting_gpa_page_number) { + return 1; + } else { + return 0; + } +} + +static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_da= ta, + Error **errp) +{ + const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; + QIgvmParameterData *param_entry; + int max_entry_count; + int entry =3D 0; + IGVM_VHS_MEMORY_MAP_ENTRY *mm_entry; + ConfidentialGuestMemoryMapEntry cgmm_entry; + int retval =3D 0; + + if (!ctx->cgs) { + error_setg(errp, + "IGVM file contains a memory map but this is not suppor= ted " + "by the current system."); + return -1; + } + + /* Find the parameter area that should hold the memory map */ + QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next) + { + if (param_entry->index =3D=3D param->parameter_area_index) { + max_entry_count =3D + param_entry->size / sizeof(IGVM_VHS_MEMORY_MAP_ENTRY); + mm_entry =3D (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data; + + retval =3D ctx->cgsc->get_mem_map_entry(entry, &cgmm_entry, er= rp); + while (retval =3D=3D 0) { + if (entry > max_entry_count) { + error_setg( + errp, + "IGVM: guest memory map size exceeds parameter are= a defined in IGVM file"); + return -1; + } + mm_entry[entry].starting_gpa_page_number =3D cgmm_entry.gp= a >> 12; + mm_entry[entry].number_of_pages =3D cgmm_entry.size >> 12; + + switch (cgmm_entry.type) { + case CGS_MEM_RAM: + mm_entry[entry].entry_type =3D + IGVM_MEMORY_MAP_ENTRY_TYPE_MEMORY; + break; + case CGS_MEM_RESERVED: + mm_entry[entry].entry_type =3D + IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED; + break; + case CGS_MEM_ACPI: + mm_entry[entry].entry_type =3D + IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED; + break; + case CGS_MEM_NVS: + mm_entry[entry].entry_type =3D + IGVM_MEMORY_MAP_ENTRY_TYPE_PERSISTENT; + break; + case CGS_MEM_UNUSABLE: + mm_entry[entry].entry_type =3D + IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED; + break; + } + retval =3D + ctx->cgsc->get_mem_map_entry(++entry, &cgmm_entry, err= p); + } + if (retval < 0) { + return retval; + } + /* The entries need to be sorted */ + qsort(mm_entry, entry, sizeof(IGVM_VHS_MEMORY_MAP_ENTRY), + qigvm_cmp_mm_entry); + + break; + } + } + return 0; +} + +static int qigvm_directive_vp_count(QIgvm *ctx, const uint8_t *header_data, + Error **errp) +{ + const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; + QIgvmParameterData *param_entry; + uint32_t *vp_count; + CPUState *cpu; + + QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next) + { + if (param_entry->index =3D=3D param->parameter_area_index) { + vp_count =3D (uint32_t *)(param_entry->data + param->byte_offs= et); + *vp_count =3D 0; + CPU_FOREACH(cpu) + { + (*vp_count)++; + } + break; + } + } + return 0; +} + +static int qigvm_directive_environment_info(QIgvm *ctx, + const uint8_t *header_data, + Error **errp) +{ + const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; + QIgvmParameterData *param_entry; + IgvmEnvironmentInfo *environmental_state; + + QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next) + { + if (param_entry->index =3D=3D param->parameter_area_index) { + environmental_state =3D + (IgvmEnvironmentInfo *)(param_entry->data + param->byte_of= fset); + environmental_state->memory_is_shared =3D 1; + break; + } + } + return 0; +} + +static int qigvm_directive_required_memory(QIgvm *ctx, + const uint8_t *header_data, + Error **errp) +{ + const IGVM_VHS_REQUIRED_MEMORY *mem =3D + (const IGVM_VHS_REQUIRED_MEMORY *)header_data; + uint8_t *region; + int result; + + if (!(mem->compatibility_mask & ctx->compatibility_mask)) { + return 0; + } + + region =3D qigvm_prepare_memory(ctx, mem->gpa, mem->number_of_bytes, + ctx->current_header_index, errp); + if (!region) { + return -1; + } + if (ctx->cgs) { + result =3D + ctx->cgsc->set_guest_state(mem->gpa, region, mem->number_of_by= tes, + CGS_PAGE_TYPE_REQUIRED_MEMORY, 0, e= rrp); + if (result < 0) { + return result; + } + } + return 0; +} + +static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp) +{ + int32_t header_count; + unsigned header_index; + IgvmHandle header_handle; + IGVM_VHS_SUPPORTED_PLATFORM *platform; + uint32_t compatibility_mask_sev =3D 0; + uint32_t compatibility_mask_sev_es =3D 0; + uint32_t compatibility_mask_sev_snp =3D 0; + uint32_t compatibility_mask =3D 0; + + header_count =3D igvm_header_count(ctx->file, IGVM_HEADER_SECTION_PLAT= FORM); + if (header_count < 0) { + error_setg(errp, + "Invalid platform header count in IGVM file. Error code= : %X", + header_count); + return -1; + } + + for (header_index =3D 0; header_index < (unsigned)header_count; + header_index++) { + IgvmVariableHeaderType typ =3D igvm_get_header_type( + ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index); + if (typ =3D=3D IGVM_VHT_SUPPORTED_PLATFORM) { + header_handle =3D igvm_get_header( + ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index); + if (header_handle < 0) { + error_setg(errp, + "Invalid platform header in IGVM file. " + "Index: %d, Error code: %X", + header_index, header_handle); + return -1; + } + platform =3D + (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->file, + header_han= dle) + + sizeof( + IGVM_VHS_VARIABLE_HEAD= ER)); + if ((platform->platform_type =3D=3D IGVM_PLATFORM_TYPE_SEV_ES)= && + ctx->cgs) { + if (ctx->cgsc->check_support( + CGS_PLATFORM_SEV_ES, platform->platform_version, + platform->highest_vtl, platform->shared_gpa_bounda= ry)) { + compatibility_mask_sev_es =3D platform->compatibility_= mask; + } + } else if ((platform->platform_type =3D=3D IGVM_PLATFORM_TYPE_= SEV) && + ctx->cgs) { + if (ctx->cgsc->check_support( + CGS_PLATFORM_SEV, platform->platform_version, + platform->highest_vtl, platform->shared_gpa_bounda= ry)) { + compatibility_mask_sev =3D platform->compatibility_mas= k; + } + } else if ((platform->platform_type =3D=3D + IGVM_PLATFORM_TYPE_SEV_SNP) && + ctx->cgs) { + if (ctx->cgsc->check_support( + CGS_PLATFORM_SEV_SNP, platform->platform_version, + platform->highest_vtl, platform->shared_gpa_bounda= ry)) { + compatibility_mask_sev_snp =3D platform->compatibility= _mask; + } + } else if (platform->platform_type =3D=3D IGVM_PLATFORM_TYPE_N= ATIVE) { + compatibility_mask =3D platform->compatibility_mask; + } + igvm_free_buffer(ctx->file, header_handle); + } + } + /* Choose the strongest supported isolation technology */ + if (compatibility_mask_sev_snp !=3D 0) { + ctx->compatibility_mask =3D compatibility_mask_sev_snp; + } else if (compatibility_mask_sev_es !=3D 0) { + ctx->compatibility_mask =3D compatibility_mask_sev_es; + } else if (compatibility_mask_sev !=3D 0) { + ctx->compatibility_mask =3D compatibility_mask_sev; + } else if (compatibility_mask !=3D 0) { + ctx->compatibility_mask =3D compatibility_mask; + } else { + error_setg( + errp, + "IGVM file does not describe a compatible supported platform"); + return -1; + } + return 0; +} + +static IgvmHandle qigvm_file_init(char *filename, Error **errp) +{ + IgvmHandle igvm; + g_autofree uint8_t *buf =3D NULL; + unsigned long len; + g_autoptr(GError) gerr =3D NULL; + + if (!g_file_get_contents(filename, (gchar **)&buf, &len, &gerr)) { + error_setg(errp, "Unable to load %s: %s", filename, gerr->message); + return -1; + } + + igvm =3D igvm_new_from_binary(buf, len); + if (igvm < 0) { + error_setg(errp, "Unable to parse IGVM file %s: %d", filename, igv= m); + return -1; + } + return igvm; +} + +int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, + Error **errp) +{ + int32_t header_count; + QIgvmParameterData *parameter; + int retval =3D -1; + QIgvm ctx; + + memset(&ctx, 0, sizeof(ctx)); + ctx.file =3D qigvm_file_init(cfg->filename, errp); + if (ctx.file < 0) { + return -1; + } + + /* + * The ConfidentialGuestSupport object is optional and allows a confid= ential + * guest platform to perform extra processing, such as page measuremen= t, on + * IGVM directives. + */ + ctx.cgs =3D cgs; + ctx.cgsc =3D cgs ? CONFIDENTIAL_GUEST_SUPPORT_GET_CLASS(cgs) : NULL; + + /* + * Check that the IGVM file provides configuration for the current + * platform + */ + if (qigvm_supported_platform_compat_mask(&ctx, errp) < 0) { + goto cleanup; + } + + header_count =3D igvm_header_count(ctx.file, IGVM_HEADER_SECTION_DIREC= TIVE); + if (header_count <=3D 0) { + error_setg( + errp, "Invalid directive header count in IGVM file. Error code= : %X", + header_count); + goto cleanup; + } + + QTAILQ_INIT(&ctx.parameter_data); + + for (ctx.current_header_index =3D 0; + ctx.current_header_index < (unsigned)header_count; + ctx.current_header_index++) { + IgvmVariableHeaderType type =3D igvm_get_header_type( + ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_in= dex); + if (qigvm_handler(&ctx, type, errp) < 0) { + goto cleanup_parameters; + } + } + + /* + * Contiguous pages of data with compatible flags are grouped together= in + * order to reduce the number of memory regions we create. Make sure t= he + * last group is processed with this call. + */ + retval =3D qigvm_process_mem_page(&ctx, NULL, errp); + +cleanup_parameters: + QTAILQ_FOREACH(parameter, &ctx.parameter_data, next) + { + g_free(parameter->data); + parameter->data =3D NULL; + } + +cleanup: + igvm_free(ctx.file); + + return retval; +} diff --git a/backends/meson.build b/backends/meson.build index ac0fac78458..60021f45d12 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -36,6 +36,8 @@ system_ss.add(when: gio, if_true: files('dbus-vmstate.c')) system_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c')) if igvm.found() system_ss.add(igvm) + system_ss.add(files('igvm-cfg.c'), igvm) + system_ss.add(files('igvm.c'), igvm) endif =20 system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c')) --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491611; cv=none; d=zohomail.com; s=zohoarc; b=PZMswEeaKS1w5slsdCc+TpVaphfiS81lCQ08IasmFJcMnSoYlRWdoP+NKmk6oW8VO1MmXcok/15l9GRg9Qgx9g11IMBTnT3xqAZ3cqSifOIh8qgqoIDdrUGGLAHAmtMzp2VvXvE7IWWHKl5C0Eig3HX37+sYZURtC7ZnRsONIjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491611; 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=dW2i+oCo9ZpgCYlYnI1btj+lqBMLXuFlBbfwc0ZiH08=; b=OkzZxQpLeZYX4rpfcZGR89eOLQ2FXkyUlQKMhmvP5ebvuvS5sMElA+ODySBRDqnLvwXJgaWIJCtGIJcPuV7rWTC4eERRjrD9jupu9xiLJRpDtfgN7D7bgSwYUJbgn+HpnAFtAaTI/bg9Yc7hbbdRTVU1MIvGz8VtSw+BUhaKRps= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491611584614.3256173968174; Mon, 14 Jul 2025 04:13:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7b-0000NA-E1; Mon, 14 Jul 2025 07:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGze-0000sg-Dm for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzb-0001qc-NA for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:10 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-536-MmCOkSc_Pti22z63JITDBQ-1; Mon, 14 Jul 2025 07:05:05 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-456106b7c4aso4887315e9.0 for ; Mon, 14 Jul 2025 04:05:05 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e26ee3sm12333742f8f.96.2025.07.14.04.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491107; 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=dW2i+oCo9ZpgCYlYnI1btj+lqBMLXuFlBbfwc0ZiH08=; b=eQzyexnHnabrTngUu/kV8FGC4BZJKgqysCrutHaqmdyItcraFFhgpGgdD/3ME9feMuxASp 5KDtBFktfuk7hfV3zdz350jFrW3V1hEtEyqCP3i1Wu50IXXuihoYfWBRwsRCvDuFpMNKwA Gq7PSHLiuob+ur414KhjMBb3IHcO+yo= X-MC-Unique: MmCOkSc_Pti22z63JITDBQ-1 X-Mimecast-MFC-AGG-ID: MmCOkSc_Pti22z63JITDBQ_1752491105 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491103; x=1753095903; 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=dW2i+oCo9ZpgCYlYnI1btj+lqBMLXuFlBbfwc0ZiH08=; b=xU2FuNVmdJHzk1TLWtmTlfaz1cjTSyIwLT3s/8DOIASn+5Qf8r9t/McRNE7rVjqXFX k1njGqFczqHyyr8zCGcuunvyKwRYS6ILeON5s/k/iHdZnnzMcFhXJ32ZFJp0hGUjeYm8 OHCWel9sm0wvNczoHJVGtRsC8068aFdWnoC9XAbAUekXMhgHGrRDJEf9gZAg9LDu1tfO TQ8+s8nqYLUUftEsD3J9SwWZoP/wQnJvRmWoxlmP9Idlf+Ogq+iI8eYsFztn4CkJDck8 6DArbw+0xq2lTiMZ/iVgLSCGl7of7AaAg99AggZ3DWdUezGugqq6t+AoVgcF4eRX7FU7 5eCQ== X-Gm-Message-State: AOJu0Yxi+BEhdFmWOG0j6uhXaW4+qGz+rmYxLC3Y85Wq4amUw68LwIO5 AkAA/SFjQ2qs0y7rtMmRWg1whQGNoTBZodcBzhLyKYOrk5ZHAry3Gn4uPaZJ9osd0KI/FLcGW29 4K3AttG2EsTED1aRkYoB32rg3epaRnbiMSJomvq3H5i83CdCneMd/UcuaLxwZhkZVJTarDJ0rE7 RCVxGHRQrzk9+V+lLyCShk2v8tPz71mKy3h/gXOwGA X-Gm-Gg: ASbGnctWRBeDOtFuiQJDtCo4RKSCRaInODsEjr2mvnV6VjjPeoUUuOzIe3OMjHesNdo bi7z1u+0+FJulu54JCiFGTt40JFBMrUNGmmKo5MG6pSUTghpaLdogPfqk9hC22d74KJrSVs4k0a qUIh0AEMTqiF7ZXBC4IEM+phpWkYrV6zMT7EHeHjDiLCasucE2KGxZB6RsZ7VCfPgb2MiVPqk4V FmD9NRlTrMIjx4EPbIRX6Hb0+TcqE3D809pg54fKEnkvMwMRMFrFcbYc7CC78WWX4DT6uPJAeG5 HvOddTRlOSfXz1dFJBQXai87CRtpLmHM4EmRGrRu7w4= X-Received: by 2002:a05:600c:4746:b0:453:7713:476c with SMTP id 5b1f17b1804b1-455bd8e63aemr95401805e9.2.1752491102764; Mon, 14 Jul 2025 04:05:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF63REqR+7VypwkWaTIETl4dxA0iNTNvqaX+oeW7jJvqR3o0LBX2hgxJRtc3C5Jq0MuJbOIA== X-Received: by 2002:a05:600c:4746:b0:453:7713:476c with SMTP id 5b1f17b1804b1-455bd8e63aemr95401475e9.2.1752491102236; Mon, 14 Jul 2025 04:05:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , Gerd Hoffman , "Michael S. Tsirkin" , Stefano Garzarella , Ani Sinha Subject: [PULL 20/77] hw/i386: Add igvm-cfg object and processing for IGVM files Date: Mon, 14 Jul 2025 13:03:09 +0200 Message-ID: <20250714110406.117772-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491613927116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins An IGVM file contains configuration of guest state that should be applied during configuration of the guest, before the guest is started. This patch allows the user to add an igvm-cfg object to an X86 machine configuration that allows an IGVM file to be configured that will be applied to the guest before it is started. If an IGVM configuration is provided then the IGVM file is processed at the end of the board initialization, before the state transition to PHASE_MACHINE_INITIALIZED. Signed-off-by: Roy Hopkins Acked-by: Gerd Hoffman Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/23bc66ae4504ba5cf2134826e055b25df3fc9cd9.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- include/hw/i386/x86.h | 3 +++ hw/i386/pc.c | 12 ++++++++++++ hw/i386/pc_piix.c | 10 ++++++++++ hw/i386/pc_q35.c | 10 ++++++++++ qemu-options.hx | 28 ++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index fc460b82f82..8755cad50a3 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -25,6 +25,7 @@ #include "hw/intc/ioapic.h" #include "hw/isa/isa.h" #include "qom/object.h" +#include "system/igvm-cfg.h" =20 struct X86MachineClass { MachineClass parent; @@ -92,6 +93,8 @@ struct X86MachineState { * which means no limitation on the guest's bus locks. */ uint64_t bus_lock_ratelimit; + + IgvmCfg *igvm; }; =20 #define X86_MACHINE_SMM "smm" diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b2116335752..432ab288a87 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1833,6 +1833,18 @@ static void pc_machine_class_init(ObjectClass *oc, c= onst void *data) object_class_property_add_bool(oc, "fd-bootchk", pc_machine_get_fd_bootchk, pc_machine_set_fd_bootchk); + +#if defined(CONFIG_IGVM) + object_class_property_add_link(oc, "igvm-cfg", + TYPE_IGVM_CFG, + offsetof(X86MachineState, igvm), + object_property_allow_set_link, + OBJ_PROP_LINK_STRONG); + object_class_property_set_description(oc, "igvm-cfg", + "Set IGVM configuration"); +#endif + + } =20 static const TypeInfo pc_machine_info =3D { diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index ea7572e7831..3184ea1b378 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -366,6 +366,16 @@ static void pc_init1(MachineState *machine, const char= *pci_type) x86_nvdimm_acpi_dsmio, x86ms->fw_cfg, OBJECT(pcms)); } + +#if defined(CONFIG_IGVM) + /* Apply guest state from IGVM if supplied */ + if (x86ms->igvm) { + if (IGVM_CFG_GET_CLASS(x86ms->igvm) + ->process(x86ms->igvm, machine->cgs, &error_fatal) < 0) { + g_assert_not_reached(); + } + } +#endif } =20 typedef enum PCSouthBridgeOption { diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 33211b1876f..6990e1c6695 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -325,6 +325,16 @@ static void pc_q35_init(MachineState *machine) x86_nvdimm_acpi_dsmio, x86ms->fw_cfg, OBJECT(pcms)); } + +#if defined(CONFIG_IGVM) + /* Apply guest state from IGVM if supplied */ + if (x86ms->igvm) { + if (IGVM_CFG_GET_CLASS(x86ms->igvm) + ->process(x86ms->igvm, machine->cgs, &error_fatal) < 0) { + g_assert_not_reached(); + } + } +#endif } =20 #define DEFINE_Q35_MACHINE(major, minor) \ diff --git a/qemu-options.hx b/qemu-options.hx index 1f862b19a67..f4c05b388b5 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5992,6 +5992,34 @@ SRST -machine ...,memory-encryption=3Dsev0 \\ ..... =20 + ``-object igvm-cfg,file=3Dfile`` + Create an IGVM configuration object that defines the initial state + of the guest using a file in that conforms to the Independent Guest + Virtual Machine (IGVM) file format. + + This is currently only supported by ``-machine q35`` and + ``-machine pc``. + + The ``file`` parameter is used to specify the IGVM file to load. + When provided, the IGVM file is used to populate the initial + memory of the virtual machine and, depending on the platform, can + define the initial processor state, memory map and parameters. + + The IGVM file is expected to contain the firmware for the virtual + machine, therefore an ``igvm-cfg`` object cannot be provided along + with other ways of specifying firmware, such as the ``-bios`` + parameter on x86 machines. + + e.g to launch a machine providing the firmware in an IGVM file + + .. parsed-literal:: + + # |qemu_system_x86| \\ + ...... \\ + -object igvm-cfg,id=3Digvm0,file=3Dbios.igvm \\ + -machine ...,igvm-cfg=3Digvm0 \\ + ..... + ``-object authz-simple,id=3Did,identity=3Dstring`` Create an authorization object that will control access to network services. --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491775; cv=none; d=zohomail.com; s=zohoarc; b=NnOUx8UCUS2sEy0ty5wyMXtLFOwjDzoZJla6lxp7/Rcf9g5AbsuNWWco/YXZS59NjbymnAUpn47nAvYONYEHCxRSj39NRkE4yoMl/vWijfLfX4itUD3Cqku/UAaq7IwJZ12oEDOdIijG9OwFpeO5FTupTQvARs1DkI56+rnkJss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491775; h=Content-Type: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=lldL9pDenZld4b2liWHX3EviL3nng8YFuNx50nxDsEk=; b=Lic6ZkO95dWveOgJLDOGRIwPd122gljczYZAaBWJAThXrlFhxuKCJF2vUMk4u4ErIsa9Hyf10bbtyGxY4Kyxs9sIVgB4tYn7eI2M8ohybgR2MA+80ZHOb+0XIp1XQjNPkL4u1mGeoDUtbUnhUNvAg+wBi4kfy29dUr5FOBP+URg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249177574247.47788365494432; Mon, 14 Jul 2025 04:16:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH8K-0001yz-3D; Mon, 14 Jul 2025 07:14:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzp-00014J-1M for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzl-0001s0-Un for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:20 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-maeJKQx4MG-PNJjx1GTY0g-1; Mon, 14 Jul 2025 07:05:08 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-45597cc95d5so15265525e9.1 for ; Mon, 14 Jul 2025 04:05:08 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e262c6sm11919476f8f.85.2025.07.14.04.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lldL9pDenZld4b2liWHX3EviL3nng8YFuNx50nxDsEk=; b=Dhovk0974ADcmEVOz7R29v8Z7g3geYkuqvO8PrpqJkY/ych43R4R5yze1GG8dZtMUQMnzE yYcjinZ9ylvqwt7KxejTHXQZyuGyejNt8v2b54s35wWTYH+CcrLCrMzluG3zU90a1Sp5U+ NJoQdxNh3CzPslwYeyItdmZJjaoG9qk= X-MC-Unique: maeJKQx4MG-PNJjx1GTY0g-1 X-Mimecast-MFC-AGG-ID: maeJKQx4MG-PNJjx1GTY0g_1752491108 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491107; x=1753095907; 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=lldL9pDenZld4b2liWHX3EviL3nng8YFuNx50nxDsEk=; b=JRZoc/COWDEALQAJdmWr4NBmes/4Is5HA7RsWS5fDUEK57SYekJ9bK/PZRypxllbBB ngcia2euLMyQL6gXkygBKfcYHNiSaKUqDXQMExWNAm8cJyQsAUMMudf585gtZlRRLcub HCEcuAZaC2kmKPAa0FtFRoilAtOliAjyCXScs/7dS4WPLNWWyEVj8IwOTT8pMRhUT5Fy 2Yf9Nmt8Ld1ioIiz6OdImP4Ff4PpPUtgmhUDtBVxLRHRRoQ/sj15HfkRGU/kU27BDSuZ tO8niXV8NeZ6b+a7arLI0UI/VYepd404bJ8EQbSLBaygBrnmS99JJK+NbGqs8hk2hBC4 zZYw== X-Gm-Message-State: AOJu0Yz5aQFKyxapfgv/SezeHaJar2xuC9UfV9en9jtx6pzCzvQyxxZg 74LS7fgIM8rr+UD8PoCFqz1a7+giCVQu8QXXQ483P3ONGIUOWEcsQE3vWhjZ5qlREBX+8PiG2ZE ZrwX/SzzZSEV0CA2Z8tAAatTGb+e/jJZKC/R3dw6feKHAKEqLrQYkTpI6Hm/wTkhVEDdaN+bs5z TnZr2gEM997HmZAXOOSch6gNJ5AGicb/HGLrlAfOCx X-Gm-Gg: ASbGncvy2+W5om9Qo28wpRtIuolN3fJ62Yt6zhGvrx4TlUjbDVpSd3Q7rEyQj9cbl5q AwzoKudosJIvVXHy4C1dX0gFY4XTcSaLG7Pekp0bChREOq4j9c/Y+JaALK78P+HujluFnpbJt3C mlIDNt1vqYFEndqOCXhYINPlQ5Edug3TB6ZlQuymn9/53Vlo5e6Yvk1fyp07k+HdNc+RLCz66Y1 2TEnordb/zv/m97yzdYLFMPsmthAkJLUdhp8laG1N9BARIu86hcggvOLjC4OAxkZvS52l9vtHfj JuUD13zw9w3tsN4FnbuQCt8ut9ngc/wxYmsXvZX7xXU= X-Received: by 2002:adf:9dd2:0:b0:3a4:ec23:dba7 with SMTP id ffacd0b85a97d-3b5f2dfd169mr7852329f8f.31.1752491106680; Mon, 14 Jul 2025 04:05:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXp1U0ZHGtSGaDOLmjQpht7GMjwD1UnEwuNAmrVUl86S1NREsLe4sv2qjnpUFJdwEtjjOw9Q== X-Received: by 2002:adf:9dd2:0:b0:3a4:ec23:dba7 with SMTP id ffacd0b85a97d-3b5f2dfd169mr7852284f8f.31.1752491106073; Mon, 14 Jul 2025 04:05:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , Gerd Hoffman , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Michael S. Tsirkin" , Stefano Garzarella , Pankaj Gupta , Ani Sinha Subject: [PULL 21/77] i386/pc_sysfw: Ensure sysfw flash configuration does not conflict with IGVM Date: Mon, 14 Jul 2025 13:03:10 +0200 Message-ID: <20250714110406.117772-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491777805116600 From: Roy Hopkins When using an IGVM file the configuration of the system firmware is defined by IGVM directives contained in the file. In this case the user should not configure any pflash devices. This commit skips initialization of the ROM mode when pflash0 is not set then checks to ensure no pflash devices have been configured when using IGVM, exiting with an error message if this is not the case. Signed-off-by: Roy Hopkins Acked-by: Gerd Hoffman Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefano Garzarella Reviewed-by: Pankaj Gupta Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/c6166cfe128933b04003a9288566b7affe170dfe.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- hw/i386/pc_sysfw.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 821396c16e9..1a12b635ad9 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -220,7 +220,13 @@ void pc_system_firmware_init(PCMachineState *pcms, BlockBackend *pflash_blk[ARRAY_SIZE(pcms->flash)]; =20 if (!pcmc->pci_enabled) { - x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, true); + /* + * If an IGVM file is specified then the firmware must be provided + * in the IGVM file. + */ + if (!X86_MACHINE(pcms)->igvm) { + x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, t= rue); + } return; } =20 @@ -240,8 +246,13 @@ void pc_system_firmware_init(PCMachineState *pcms, } =20 if (!pflash_blk[0]) { - /* Machine property pflash0 not set, use ROM mode */ - x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, false= ); + /* + * Machine property pflash0 not set, use ROM mode unless using IGV= M, + * in which case the firmware must be provided by the IGVM file. + */ + if (!X86_MACHINE(pcms)->igvm) { + x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, f= alse); + } } else { if (kvm_enabled() && !kvm_readonly_mem_enabled()) { /* @@ -257,6 +268,20 @@ void pc_system_firmware_init(PCMachineState *pcms, } =20 pc_system_flash_cleanup_unused(pcms); + + /* + * The user should not have specified any pflash devices when using IG= VM + * to configure the guest. + */ + if (X86_MACHINE(pcms)->igvm) { + for (i =3D 0; i < ARRAY_SIZE(pcms->flash); i++) { + if (pcms->flash[i]) { + error_report("pflash devices cannot be configured when " + "using IGVM"); + exit(1); + } + } + } } =20 void x86_firmware_configure(hwaddr gpa, void *ptr, int size) --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491744; cv=none; d=zohomail.com; s=zohoarc; b=SDu5y0Jx3h5Z606Ql8IkXLCbmgUNGs1mBvDoaOYJthzRGTBTfZBQOTAf2d7C0w8lMihUmlKBb7tEQ1EZ4oIv9UVeoB71HxVe8/2sKjBpOr2oj/SajS4M4v4P+NoDD4bME5X9vWMF59QypaXAeZQ6a8W3Snbs32Vnthh4rr83BbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491744; 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=I1zRIxJCsznxtyS9znCCBC+gfuFhyW4LFEi/wN9lZzI=; b=b+PNvTbiX5jG6ZjhitJcoh/mVBKLoH4YqwOvvPCdevjKTe0lWKJBCy4K/agVeIX1vmyK6w5Z0iWuiRRvuiPtrvpkfH+76i3wUhY6qRTFuBokq9iqmK7EaABbscNre7usOBdjKcx9NL0AAd1XhdgBfECxoabO9N8vBATHJx941V4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491744451956.6947987361173; Mon, 14 Jul 2025 04:15:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH7n-0001Lb-N1; Mon, 14 Jul 2025 07:13:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzj-0000v0-8M for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzh-0001rM-0A for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:14 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-D4ws0uBNNtSb-bKSiBo8PA-1; Mon, 14 Jul 2025 07:05:11 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3b604541741so499930f8f.3 for ; Mon, 14 Jul 2025 04:05:11 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1a2bsm12330348f8f.14.2025.07.14.04.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491112; 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=I1zRIxJCsznxtyS9znCCBC+gfuFhyW4LFEi/wN9lZzI=; b=LwmFHHh93oLxLfEXV7g8BNfFSCqyky+X0ieJz42PdVMw0de57/eRjaMR1wjNEEsFRGukc+ kVWFxn+6jvn/OsdIq3c7fESGd9p/nsemqQEDWlgVDydbVx7M3mek3UIfGOzfudwXR82Cvr vSKIcZbXcllgkVeAOhrhTZGYonLKorc= X-MC-Unique: D4ws0uBNNtSb-bKSiBo8PA-1 X-Mimecast-MFC-AGG-ID: D4ws0uBNNtSb-bKSiBo8PA_1752491110 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491109; x=1753095909; 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=I1zRIxJCsznxtyS9znCCBC+gfuFhyW4LFEi/wN9lZzI=; b=OVJqEpc8pi2pZJSlcRtYCKbzhEMuiNa+qar+QusrJ+mqS4Ez2HiczNq64Fy05Gs2cE Y8r9JABT8omFmT9PL/FrEy4mx+cRfY0Wy/g8a5HuhxhDoxXSYOu8y4uYVCJI6lzTJDrw UxYKgZRhggzsiyOHIbV1p3oDa+qnhZ5Qj+auDEg3KF8zFB+UkEP23+AMrp8gCifblA++ nuEo2cY9fHFrOGwntrojh/HTBNTYuHZDVGlJFZTozORP20D6rBhfWY4XsGx9E4jOOGdS 6/JNqdeuuwVofhnUIAqutr59asfUVr7fgfTRqBKg5XZFzTq4rC1P8AcD8Clhi+FMYgIu 1VAg== X-Gm-Message-State: AOJu0YzNoiIdDDWnOwxFQw3XjHoaHmRVKxohWMiaE8BeW4KxsP9Fl1Z1 v+H9POFhcb7BWzdHv91sQZHdWCEY3EXua1X4TvbFf2O7DBlrzr+Lhh8PW9f6QRXc6FRRCkx0XKF gJklIA3GJsIQQyEDjfqjHa/eYHU3aWE67A5mmBrUHIPKzwpTm9PlOTSL4mOxEGLBeIgP8GTVqS7 Iwz74sbE3UqvHxz2ZOvJoRy47daLvHQgjr53BctfdY X-Gm-Gg: ASbGncuBVFJEKvPNZTh/XEOtG2PejxUfXG1hrmvlShsNo4TjYoENAvb3DFwZz9wfMG0 nk4hnpUvDjjlivev0MOtbe4iR+FF2fWsul0cvXJciPK9XaxAfTScZQ+5FkEonOoP+7o+1nBY6g4 4M6s7aHVuj8qlJWbKbZ7YPbag6ajBe0tD2+I6EKVw3UD/OHhHljBZ44691U56AIOhQ8nJAXC0vE SKteBnNaKlyvo2sRuGy8oEp7oyfmEzNZ0/X7GmVrN98lVtW7ZK/2ZCCKpf0zdW2gvxcbuGptXDi KIIkERfaU6ghUHgrwmXZKXKuLGuNPg8xJaxNI0cquEM= X-Received: by 2002:a05:6000:2dc7:b0:3a6:e6c3:6d95 with SMTP id ffacd0b85a97d-3b5f2e30860mr8304245f8f.41.1752491109278; Mon, 14 Jul 2025 04:05:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFw8JV9OsS+X6Cp+i2tew61q3Am7jsfxCLTvrOc4Qi7cUeLlpTVSA4jFdk5nvAtjnf0aCkPlw== X-Received: by 2002:a05:6000:2dc7:b0:3a6:e6c3:6d95 with SMTP id ffacd0b85a97d-3b5f2e30860mr8304204f8f.41.1752491108625; Mon, 14 Jul 2025 04:05:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , Pankaj Gupta , Stefano Garzarella , Ani Sinha Subject: [PULL 22/77] sev: Update launch_update_data functions to use Error handling Date: Mon, 14 Jul 2025 13:03:11 +0200 Message-ID: <20250714110406.117772-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491747699116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins The class function and implementations for updating launch data return a code in case of error. In some cases an error message is generated and in other cases, just the error return value is used. This small refactor adds an 'Error **errp' parameter to all functions which consistently set an error condition if a non-zero value is returned. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Pankaj Gupta Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/d59721f7b99cfc87aab71f8f551937e98e983615.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- target/i386/sev.c | 68 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 1a12f0671cc..a84f5f5d28a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -122,7 +122,8 @@ struct SevCommonStateClass { Error **errp); int (*launch_start)(SevCommonState *sev_common); void (*launch_finish)(SevCommonState *sev_common); - int (*launch_update_data)(SevCommonState *sev_common, hwaddr gpa, uint= 8_t *ptr, size_t len); + int (*launch_update_data)(SevCommonState *sev_common, hwaddr gpa, + uint8_t *ptr, size_t len, Error **errp); int (*kvm_init)(ConfidentialGuestSupport *cgs, Error **errp); }; =20 @@ -970,9 +971,8 @@ sev_snp_adjust_cpuid_features(X86ConfidentialGuest *cg,= uint32_t feature, uint32 return value; } =20 -static int -sev_launch_update_data(SevCommonState *sev_common, hwaddr gpa, - uint8_t *addr, size_t len) +static int sev_launch_update_data(SevCommonState *sev_common, hwaddr gpa, + uint8_t *addr, size_t len, Error **errp) { int ret, fw_error; struct kvm_sev_launch_update_data update; @@ -987,8 +987,8 @@ sev_launch_update_data(SevCommonState *sev_common, hwad= dr gpa, ret =3D sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, &update, &fw_error); if (ret) { - error_report("%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", - __func__, ret, fw_error, fw_error_to_str(fw_error)); + error_setg(errp, "%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", = __func__, + ret, fw_error, fw_error_to_str(fw_error)); } =20 return ret; @@ -1116,8 +1116,8 @@ sev_launch_finish(SevCommonState *sev_common) migrate_add_blocker(&sev_mig_blocker, &error_fatal); } =20 -static int -snp_launch_update_data(uint64_t gpa, void *hva, size_t len, int type) +static int snp_launch_update_data(uint64_t gpa, void *hva, size_t len, + int type, Error **errp) { SevLaunchUpdateData *data; =20 @@ -1132,23 +1132,21 @@ snp_launch_update_data(uint64_t gpa, void *hva, siz= e_t len, int type) return 0; } =20 -static int -sev_snp_launch_update_data(SevCommonState *sev_common, hwaddr gpa, - uint8_t *ptr, size_t len) +static int sev_snp_launch_update_data(SevCommonState *sev_common, hwaddr g= pa, + uint8_t *ptr, size_t len, Error **er= rp) { - int ret =3D snp_launch_update_data(gpa, ptr, len, - KVM_SEV_SNP_PAGE_TYPE_NORMAL); - return ret; + return snp_launch_update_data(gpa, ptr, len, + KVM_SEV_SNP_PAGE_TYPE_NORMAL, errp); } =20 static int sev_snp_cpuid_info_fill(SnpCpuidInfo *snp_cpuid_info, - const KvmCpuidInfo *kvm_cpuid_info) + const KvmCpuidInfo *kvm_cpuid_info, Error **errp) { size_t i; =20 if (kvm_cpuid_info->cpuid.nent > SNP_CPUID_FUNCTION_MAXCOUNT) { - error_report("SEV-SNP: CPUID entry count (%d) exceeds max (%d)", + error_setg(errp, "SEV-SNP: CPUID entry count (%d) exceeds max (%d)= ", kvm_cpuid_info->cpuid.nent, SNP_CPUID_FUNCTION_MAXCOU= NT); return -1; } @@ -1190,8 +1188,8 @@ sev_snp_cpuid_info_fill(SnpCpuidInfo *snp_cpuid_info, return 0; } =20 -static int -snp_launch_update_cpuid(uint32_t cpuid_addr, void *hva, size_t cpuid_len) +static int snp_launch_update_cpuid(uint32_t cpuid_addr, void *hva, + size_t cpuid_len, Error **errp) { KvmCpuidInfo kvm_cpuid_info =3D {0}; SnpCpuidInfo snp_cpuid_info; @@ -1208,26 +1206,25 @@ snp_launch_update_cpuid(uint32_t cpuid_addr, void *= hva, size_t cpuid_len) } while (ret =3D=3D -E2BIG); =20 if (ret) { - error_report("SEV-SNP: unable to query CPUID values for CPU: '%s'", - strerror(-ret)); - return 1; + error_setg(errp, "SEV-SNP: unable to query CPUID values for CPU: '= %s'", + strerror(-ret)); + return -1; } =20 - ret =3D sev_snp_cpuid_info_fill(&snp_cpuid_info, &kvm_cpuid_info); - if (ret) { - error_report("SEV-SNP: failed to generate CPUID table information"= ); - return 1; + ret =3D sev_snp_cpuid_info_fill(&snp_cpuid_info, &kvm_cpuid_info, errp= ); + if (ret < 0) { + return -1; } =20 memcpy(hva, &snp_cpuid_info, sizeof(snp_cpuid_info)); =20 return snp_launch_update_data(cpuid_addr, hva, cpuid_len, - KVM_SEV_SNP_PAGE_TYPE_CPUID); + KVM_SEV_SNP_PAGE_TYPE_CPUID, errp); } =20 -static int -snp_launch_update_kernel_hashes(SevSnpGuestState *sev_snp, uint32_t addr, - void *hva, uint32_t len) +static int snp_launch_update_kernel_hashes(SevSnpGuestState *sev_snp, + uint32_t addr, void *hva, + uint32_t len, Error **errp) { int type =3D KVM_SEV_SNP_PAGE_TYPE_ZERO; if (sev_snp->parent_obj.kernel_hashes) { @@ -1239,7 +1236,7 @@ snp_launch_update_kernel_hashes(SevSnpGuestState *sev= _snp, uint32_t addr, sizeof(*sev_snp->kernel_hashes_data)); type =3D KVM_SEV_SNP_PAGE_TYPE_NORMAL; } - return snp_launch_update_data(addr, hva, len, type); + return snp_launch_update_data(addr, hva, len, type, errp); } =20 static int @@ -1277,12 +1274,14 @@ snp_populate_metadata_pages(SevSnpGuestState *sev_s= np, } =20 if (type =3D=3D KVM_SEV_SNP_PAGE_TYPE_CPUID) { - ret =3D snp_launch_update_cpuid(desc->base, hva, desc->len); + ret =3D snp_launch_update_cpuid(desc->base, hva, desc->len, + &error_fatal); } else if (desc->type =3D=3D SEV_DESC_TYPE_SNP_KERNEL_HASHES) { ret =3D snp_launch_update_kernel_hashes(sev_snp, desc->base, h= va, - desc->len); + desc->len, &error_fatal); } else { - ret =3D snp_launch_update_data(desc->base, hva, desc->len, typ= e); + ret =3D snp_launch_update_data(desc->base, hva, desc->len, typ= e, + &error_fatal); } =20 if (ret) { @@ -1615,9 +1614,8 @@ sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t = len, Error **errp) if (sev_check_state(sev_common, SEV_STATE_LAUNCH_UPDATE)) { int ret; =20 - ret =3D klass->launch_update_data(sev_common, gpa, ptr, len); + ret =3D klass->launch_update_data(sev_common, gpa, ptr, len, errp); if (ret < 0) { - error_setg(errp, "SEV: Failed to encrypt pflash rom"); return ret; } } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491516; cv=none; d=zohomail.com; s=zohoarc; b=EMkbimMMMZXcM+Rri7q468kkqdTvS43E5Bj0Qkb6lLFtITCwpXK2uwc7QnoKx3aTeWMMEHX3nBgqg1ZTTpJLkG0ZdDzcGz3v+DjSvZbMPZ99p71xA3bvfcpF1KHRF1NL5U7qfJ1xqkPkNbifznyzpPKlzyZbC1GI1KLOcbu5+nc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491516; 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=d3Zq0CyZlXef+/OkfyoF0P1FjAOrvSnpLIELP6T3/J0=; b=oLCLZ1ctvbEGg0b3NklYUG8+Siwlnvf875JipEj3Ocukb3kKd//iApQXsepwMmTc2ptCxqAa3mXWNz+4sFAV1FPeNJhCJ+31dOcEyW2k7FdB2HUr0+j2huey++DxlbUhdjv0Z8wr2jOVuiZptzNOLyMfzzpNCexCT94X6rZlkw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491516357708.9809645486274; Mon, 14 Jul 2025 04:11:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH3s-0004Sm-NT; Mon, 14 Jul 2025 07:09:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzm-0000yr-7G for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzk-0001s3-73 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:17 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-SMK9wdX2OzaTtt2pi5bcHw-1; Mon, 14 Jul 2025 07:05:14 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4561c67daebso2040585e9.1 for ; Mon, 14 Jul 2025 04:05:13 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561d19a21dsm19852865e9.24.2025.07.14.04.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491115; 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=d3Zq0CyZlXef+/OkfyoF0P1FjAOrvSnpLIELP6T3/J0=; b=FiiQ+CZZO1UXqCKeRYRU6fbZru+R7eFPznK9WnLIaQc9WE44Yx0ZWPb1u7KBT0WreezmVr f24w9ufxlgbt5dGVWzC1Ai3buoectydmH+nXwxCdTX2wq9Jr3F91FsVEBsV5IErv0J8P0p k6LLPCrDrPqOGVgM+EoFTaiBDq1X1II= X-MC-Unique: SMK9wdX2OzaTtt2pi5bcHw-1 X-Mimecast-MFC-AGG-ID: SMK9wdX2OzaTtt2pi5bcHw_1752491113 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491112; x=1753095912; 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=d3Zq0CyZlXef+/OkfyoF0P1FjAOrvSnpLIELP6T3/J0=; b=aUS95E+DfP+2FoF4byNIyBdsfI0G2xYWl16/B+MiMnrMXYtEHvjaHzo5qNXbdW55MV 5CqbRkex3kvz1t25sMJVlfHIdw+BkiiNYnwwo+8yYUGD1BeRADZqDRHuaP9au7pK1kNS yL1nJ4Ioqy8NB+Cmoa7+xrV9AJTT4xN7xIh09JZJcHQylhCSwdVGfFEQdPIE/1rPWHSE j6hhe+LHsR5n9SMWTAew5gV/xbZm1uul9EsEgjH8OA4b8/Nj56r9Ar1k4UokRdo0VjzJ A+cabOMLejETQs1E9hz+E8CF9Yo9qxzCOT/t3VolqTjOAVA6UEz6vcrgMu2Aw0BpYV1G X0nQ== X-Gm-Message-State: AOJu0YxE7PHUxa5PBcLfZR6YTNt6RFwR3BZ3mlr52hISalITupFGKy41 GudNW0auYEIhkvsbd6OUx3SS2Pm0Dg0Wio2r0nDJklXQwKMRQKCpgpetrPQlTeXUIVUwUI0ohb5 9d2SgZd2g5TqwIucEEIR2yl1qOrYO3oawEF1Q84Y4uzGcPd05iXx6dF4Px8Dbtb0xUUyRizWChC yKu4jH/8/sYtAPhGpZmgiNqrsB2VIE0ZZL8hVHztNm X-Gm-Gg: ASbGncuO6Y1cE4i+/96pgxDnWISAoLGTBoOxarOvhzemlB0mWdXVmGp2+tIpxD69WCx SRLv+E/9cuRI1szmYCa8v33tS6danYxyWjnjdlUrRsAJ7Z0g2oRVFRcbxiMSVnyZZtyjEdDsgjY x8JxBwlmqEz76UozmXLmd776oE4tgziM02Iy00h7O622YgJn8qsJNvKzp02jObs9EEpwchpt2sY Rzr1UsvQZQ402+YAOggopBaMv1sSerq+cZRInv1bS6nzTExDZU9SWYsP7v3FOqOVWxIC9b+TeNc FtHEGaKq1DxpZT7oBqHI/t36iDwRO6l+NnzwpZdbtyI= X-Received: by 2002:a05:600c:3e08:b0:456:ed3:a488 with SMTP id 5b1f17b1804b1-4560ed3a67cmr65381925e9.1.1752491111953; Mon, 14 Jul 2025 04:05:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgA5QGPTwgBWV2PjSQ1oeqr2mH0pkz73s3Xy8sDZQT2r9hiJnEKG1LQ2Yo/m2wUcaW8++xdQ== X-Received: by 2002:a05:600c:3e08:b0:456:ed3:a488 with SMTP id 5b1f17b1804b1-4560ed3a67cmr65381575e9.1.1752491111485; Mon, 14 Jul 2025 04:05:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , Gerd Hoffman , "Michael S. Tsirkin" , Stefano Garzarella , Ani Sinha Subject: [PULL 23/77] target/i386: Allow setting of R_LDTR and R_TR with cpu_x86_load_seg_cache() Date: Mon, 14 Jul 2025 13:03:12 +0200 Message-ID: <20250714110406.117772-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491518665116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins The x86 segment registers are identified by the X86Seg enumeration which includes LDTR and TR as well as the normal segment registers. The function 'cpu_x86_load_seg_cache()' uses the enum to determine which segment to set. However, specifying R_LDTR or R_TR results in an out-of-bounds access of the segment array. Possibly by coincidence, the function does correctly set LDTR or TR in this case as the structures for these registers immediately follow the array which is accessed out of bounds. This patch adds correct handling for R_LDTR and R_TR in the function. Signed-off-by: Roy Hopkins Acked-by: Gerd Hoffman Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/95c69253ea4f91107625872d5e3f0c586376771d.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index be3ae6d546e..9829824ac89 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2417,7 +2417,14 @@ static inline void cpu_x86_load_seg_cache(CPUX86Stat= e *env, SegmentCache *sc; unsigned int new_hflags; =20 - sc =3D &env->segs[seg_reg]; + if (seg_reg =3D=3D R_LDTR) { + sc =3D &env->ldt; + } else if (seg_reg =3D=3D R_TR) { + sc =3D &env->tr; + } else { + sc =3D &env->segs[seg_reg]; + } + sc->selector =3D selector; sc->base =3D base; sc->limit =3D limit; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492447; cv=none; d=zohomail.com; s=zohoarc; b=SkDz9xbZH+sSBp4a/QGYEAfDIXo28bNAGL4WhPUMGCzNOx4Cqxw7Z8lB3gjK7iMusdb4sUZ6ciRUUIEgRhC1NTzt5JIwiF3OCP18oosQ7a4mupCwJLvVlNSRGZIuAhoViixGcOFeatQVmSJxT39RONBTtet3SOzk2q4IpJzvAWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492447; 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=wxMnMbD1XcPxMyEUTBLdpuoI42kvRRrLRupjHn50Puk=; b=kELeOLbZZ2iCCbjq1g64ASh3fxnsMLVV62z2c0Z71/7sguAmTPwo8khxGvh8gNV4Ing60sQxRdZLWu4TWidR+qiFcfPu1GOw2SvNASIHfVDkwisiurjRKQ0DRRfdjapbVzRHP0GEfpSYLLE3E/ncRSd+vj0GNT+Opoat75kc9xw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492447118442.95555236581765; Mon, 14 Jul 2025 04:27:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHJ0-0003L1-9u; Mon, 14 Jul 2025 07:25:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzr-00016V-01 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzn-0001sd-MH for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:22 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-TKX0yMhDN4-MUPm4CA-aDQ-1; Mon, 14 Jul 2025 07:05:17 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-451d3f03b74so24015985e9.3 for ; Mon, 14 Jul 2025 04:05:17 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45613c2d84dsm45517715e9.5.2025.07.14.04.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491119; 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=wxMnMbD1XcPxMyEUTBLdpuoI42kvRRrLRupjHn50Puk=; b=hOEYfKea9xnhxcbryvlgF0jA39OR395lTJ91j+yQkBjETTLZfbpdusutHiX5FWZpqwuKO6 YfQZUP7YaVMscmVHA1UsSps48rxFoeddMt1vfvkaQ+UcZ9qK0CyUj/F7y9zNVEQQcgmLhs Tyx9U1Kh8M51eIn9w6IHOp3fT4+UQ0Y= X-MC-Unique: TKX0yMhDN4-MUPm4CA-aDQ-1 X-Mimecast-MFC-AGG-ID: TKX0yMhDN4-MUPm4CA-aDQ_1752491116 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491115; x=1753095915; 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=wxMnMbD1XcPxMyEUTBLdpuoI42kvRRrLRupjHn50Puk=; b=EKys5WK7l5aGmdmFmvE3uBD617BEQQ77ZjimHF9aYZPNkERl3Fx/fwVf73+WsH1fBA VXAqyzj/m6nRYf8vFYjihotsY7hKbyKlarrpEw6w2ZYt2o6YCBYyUY6O4mjtfX5pyoaI M2oEjw8g3CUL6wDoXYYc5XoRARYeEV26gGzqHjQdTsmsgl2J7fp8wAeXKIyLm/y3kSGo KLboL2u6E1oQOSmosBuoIVno/3nmNcLHWx/8vVebNhzrzqiW778dTSDPMsLxLsZS86Yu 3X+w4Ke040b4YaFbKBg48n0PJr1tVQrKz6IyVzTVZcVAyxJCR9ewlc8XgO0HGTCn5gHE 5J+Q== X-Gm-Message-State: AOJu0YykxKJB2Lt84Rk/v1Hd3UAGfuxV5oKQlnGpl+6/d7fzloRyZ04y Bvqu/3OJDcgD0GNmCC6+c5myh4ntKWZNV1+wLQKWfMeHDWrExiKnBFkxPJxOGKz9+8xwTTAER/V 4N4C4UF0vh5zjuq2KbuBBkam4DIx9bwC+UOwikijc/Ow3VF0j7VaXprWP60DyXlVwqSRPmBoThM vM12a2wIg0hBnjAW7jsnPZ5xcHWxioV0EvetN7Hboa X-Gm-Gg: ASbGnctGVr6dPUcCo5M4ZvP1ENz78Eosq/McYR7DshxDQCaoTo9HBEPsdSroiZRSqg+ auekX0w09wOUPxP22YCJsmr2wwwkCvyMBwfq6MT4nu6CDKDvfW459DRhh38k0jbfAzDe9ZLCBzj LbsDPs9Ok8XhlmkaYqxXMyuKdCjIQ5s0FpkLRwS/ddDkbi/u4I7SM2jCC42z/HUiAXadPk00M9K 1WUrcJhzYMmMW9MX3wBz6KF9S8l/i+vnG5hUyzzfqYnQZeEm6z9l49xj1i34IemBNyfs2jP0PaW EVl+/LR7pE6Xv58gChVIaJcLihiJNwHKrhFKjU+vwfk= X-Received: by 2002:a05:600c:1c9a:b0:456:1608:c807 with SMTP id 5b1f17b1804b1-4561608ca40mr39533915e9.26.1752491114685; Mon, 14 Jul 2025 04:05:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGChAowa4p8SSul2OyJsN5lzkvikbK3vodneNxkz2OcsR7C0Edf+SLbgaeN8K880LzBIhyAmg== X-Received: by 2002:a05:600c:1c9a:b0:456:1608:c807 with SMTP id 5b1f17b1804b1-4561608ca40mr39533425e9.26.1752491114073; Mon, 14 Jul 2025 04:05:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Stefano Garzarella , Gerd Hoffman , Pankaj Gupta Subject: [PULL 24/77] i386/sev: Refactor setting of reset vector and initial CPU state Date: Mon, 14 Jul 2025 13:03:13 +0200 Message-ID: <20250714110406.117772-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492448852116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins When an SEV guest is started, the reset vector and state are extracted from metadata that is contained in the firmware volume. In preparation for using IGVM to setup the initial CPU state, the code has been refactored to populate vmcb_save_area for each CPU which is then applied during guest startup and CPU reset. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Stefano Garzarella Acked-by: Gerd Hoffman Reviewed-by: Pankaj Gupta Link: https://lore.kernel.org/r/d3c2debca496c4366a278b135f951908f3b9c341.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- target/i386/sev.h | 110 ++++++++++++++++ target/i386/sev.c | 326 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 401 insertions(+), 35 deletions(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 373669eaace..38caa849f5e 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -55,6 +55,116 @@ typedef struct SevKernelLoaderContext { size_t cmdline_size; } SevKernelLoaderContext; =20 +/* Save area definition for SEV-ES and SEV-SNP guests */ +struct QEMU_PACKED sev_es_save_area { + struct vmcb_seg es; + struct vmcb_seg cs; + struct vmcb_seg ss; + struct vmcb_seg ds; + struct vmcb_seg fs; + struct vmcb_seg gs; + struct vmcb_seg gdtr; + struct vmcb_seg ldtr; + struct vmcb_seg idtr; + struct vmcb_seg tr; + uint64_t vmpl0_ssp; + uint64_t vmpl1_ssp; + uint64_t vmpl2_ssp; + uint64_t vmpl3_ssp; + uint64_t u_cet; + uint8_t reserved_0xc8[2]; + uint8_t vmpl; + uint8_t cpl; + uint8_t reserved_0xcc[4]; + uint64_t efer; + uint8_t reserved_0xd8[104]; + uint64_t xss; + uint64_t cr4; + uint64_t cr3; + uint64_t cr0; + uint64_t dr7; + uint64_t dr6; + uint64_t rflags; + uint64_t rip; + uint64_t dr0; + uint64_t dr1; + uint64_t dr2; + uint64_t dr3; + uint64_t dr0_addr_mask; + uint64_t dr1_addr_mask; + uint64_t dr2_addr_mask; + uint64_t dr3_addr_mask; + uint8_t reserved_0x1c0[24]; + uint64_t rsp; + uint64_t s_cet; + uint64_t ssp; + uint64_t isst_addr; + uint64_t rax; + uint64_t star; + uint64_t lstar; + uint64_t cstar; + uint64_t sfmask; + uint64_t kernel_gs_base; + uint64_t sysenter_cs; + uint64_t sysenter_esp; + uint64_t sysenter_eip; + uint64_t cr2; + uint8_t reserved_0x248[32]; + uint64_t g_pat; + uint64_t dbgctl; + uint64_t br_from; + uint64_t br_to; + uint64_t last_excp_from; + uint64_t last_excp_to; + uint8_t reserved_0x298[80]; + uint32_t pkru; + uint32_t tsc_aux; + uint8_t reserved_0x2f0[24]; + uint64_t rcx; + uint64_t rdx; + uint64_t rbx; + uint64_t reserved_0x320; /* rsp already available at 0x01d8 */ + uint64_t rbp; + uint64_t rsi; + uint64_t rdi; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + uint8_t reserved_0x380[16]; + uint64_t guest_exit_info_1; + uint64_t guest_exit_info_2; + uint64_t guest_exit_int_info; + uint64_t guest_nrip; + uint64_t sev_features; + uint64_t vintr_ctrl; + uint64_t guest_exit_code; + uint64_t virtual_tom; + uint64_t tlb_id; + uint64_t pcpu_id; + uint64_t event_inj; + uint64_t xcr0; + uint8_t reserved_0x3f0[16]; + + /* Floating point area */ + uint64_t x87_dp; + uint32_t mxcsr; + uint16_t x87_ftw; + uint16_t x87_fsw; + uint16_t x87_fcw; + uint16_t x87_fop; + uint16_t x87_ds; + uint16_t x87_cs; + uint64_t x87_rip; + uint8_t fpreg_x87[80]; + uint8_t fpreg_xmm[256]; + uint8_t fpreg_ymm[256]; +}; + bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **err= p); =20 int sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp= ); diff --git a/target/i386/sev.c b/target/i386/sev.c index a84f5f5d28a..a13f91e615d 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -50,6 +50,12 @@ OBJECT_DECLARE_TYPE(SevSnpGuestState, SevCommonStateClas= s, SEV_SNP_GUEST) /* hard code sha256 digest size */ #define HASH_SIZE 32 =20 +/* Convert between SEV-ES VMSA and SegmentCache flags/attributes */ +#define FLAGS_VMSA_TO_SEGCACHE(flags) \ + ((((flags) & 0xff00) << 12) | (((flags) & 0xff) << 8)) +#define FLAGS_SEGCACHE_TO_VMSA(flags) \ + ((((flags) & 0xff00) >> 8) | (((flags) & 0xf00000) >> 12)) + typedef struct QEMU_PACKED SevHashTableEntry { QemuUUID guid; uint16_t len; @@ -89,6 +95,14 @@ typedef struct QEMU_PACKED SevHashTableDescriptor { uint32_t size; } SevHashTableDescriptor; =20 +typedef struct SevLaunchVmsa { + QTAILQ_ENTRY(SevLaunchVmsa) next; + + uint16_t cpu_index; + uint64_t gpa; + struct sev_es_save_area vmsa; +} SevLaunchVmsa; + struct SevCommonState { X86ConfidentialGuest parent_obj; =20 @@ -107,9 +121,7 @@ struct SevCommonState { int sev_fd; SevState state; =20 - uint32_t reset_cs; - uint32_t reset_ip; - bool reset_data_valid; + QTAILQ_HEAD(, SevLaunchVmsa) launch_vmsa; }; =20 struct SevCommonStateClass { @@ -364,6 +376,172 @@ static struct RAMBlockNotifier sev_ram_notifier =3D { .ram_block_removed =3D sev_ram_block_removed, }; =20 +static void sev_apply_cpu_context(CPUState *cpu) +{ + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + X86CPU *x86; + CPUX86State *env; + struct SevLaunchVmsa *launch_vmsa; + + /* See if an initial VMSA has been provided for this CPU */ + QTAILQ_FOREACH(launch_vmsa, &sev_common->launch_vmsa, next) + { + if (cpu->cpu_index =3D=3D launch_vmsa->cpu_index) { + x86 =3D X86_CPU(cpu); + env =3D &x86->env; + + /* + * Ideally we would provide the VMSA directly to kvm which wou= ld + * ensure that the resulting initial VMSA measurement which is + * calculated during KVM_SEV_LAUNCH_UPDATE_VMSA is calculated = from + * exactly what we provide here. Currently this is not possibl= e so + * we need to copy the parts of the VMSA structure that we cur= rently + * support into the CPU state. + */ + cpu_load_efer(env, launch_vmsa->vmsa.efer); + cpu_x86_update_cr4(env, launch_vmsa->vmsa.cr4); + cpu_x86_update_cr0(env, launch_vmsa->vmsa.cr0); + cpu_x86_update_cr3(env, launch_vmsa->vmsa.cr3); + env->xcr0 =3D launch_vmsa->vmsa.xcr0; + env->pat =3D launch_vmsa->vmsa.g_pat; + + cpu_x86_load_seg_cache( + env, R_CS, launch_vmsa->vmsa.cs.selector, + launch_vmsa->vmsa.cs.base, launch_vmsa->vmsa.cs.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.cs.attrib)); + cpu_x86_load_seg_cache( + env, R_DS, launch_vmsa->vmsa.ds.selector, + launch_vmsa->vmsa.ds.base, launch_vmsa->vmsa.ds.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.ds.attrib)); + cpu_x86_load_seg_cache( + env, R_ES, launch_vmsa->vmsa.es.selector, + launch_vmsa->vmsa.es.base, launch_vmsa->vmsa.es.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.es.attrib)); + cpu_x86_load_seg_cache( + env, R_FS, launch_vmsa->vmsa.fs.selector, + launch_vmsa->vmsa.fs.base, launch_vmsa->vmsa.fs.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.fs.attrib)); + cpu_x86_load_seg_cache( + env, R_GS, launch_vmsa->vmsa.gs.selector, + launch_vmsa->vmsa.gs.base, launch_vmsa->vmsa.gs.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.gs.attrib)); + cpu_x86_load_seg_cache( + env, R_SS, launch_vmsa->vmsa.ss.selector, + launch_vmsa->vmsa.ss.base, launch_vmsa->vmsa.ss.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.ss.attrib)); + + env->gdt.base =3D launch_vmsa->vmsa.gdtr.base; + env->gdt.limit =3D launch_vmsa->vmsa.gdtr.limit; + env->gdt.flags =3D + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.gdtr.attrib); + env->idt.base =3D launch_vmsa->vmsa.idtr.base; + env->idt.limit =3D launch_vmsa->vmsa.idtr.limit; + env->idt.flags =3D + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.idtr.attrib); + + cpu_x86_load_seg_cache( + env, R_LDTR, launch_vmsa->vmsa.ldtr.selector, + launch_vmsa->vmsa.ldtr.base, launch_vmsa->vmsa.ldtr.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.ldtr.attrib)); + cpu_x86_load_seg_cache( + env, R_TR, launch_vmsa->vmsa.tr.selector, + launch_vmsa->vmsa.ldtr.base, launch_vmsa->vmsa.tr.limit, + FLAGS_VMSA_TO_SEGCACHE(launch_vmsa->vmsa.tr.attrib)); + + env->dr[6] =3D launch_vmsa->vmsa.dr6; + env->dr[7] =3D launch_vmsa->vmsa.dr7; + + env->regs[R_EAX] =3D launch_vmsa->vmsa.rax; + env->regs[R_ECX] =3D launch_vmsa->vmsa.rcx; + env->regs[R_EDX] =3D launch_vmsa->vmsa.rdx; + env->regs[R_EBX] =3D launch_vmsa->vmsa.rbx; + env->regs[R_ESP] =3D launch_vmsa->vmsa.rsp; + env->regs[R_EBP] =3D launch_vmsa->vmsa.rbp; + env->regs[R_ESI] =3D launch_vmsa->vmsa.rsi; + env->regs[R_EDI] =3D launch_vmsa->vmsa.rdi; +#ifdef TARGET_X86_64 + env->regs[R_R8] =3D launch_vmsa->vmsa.r8; + env->regs[R_R9] =3D launch_vmsa->vmsa.r9; + env->regs[R_R10] =3D launch_vmsa->vmsa.r10; + env->regs[R_R11] =3D launch_vmsa->vmsa.r11; + env->regs[R_R12] =3D launch_vmsa->vmsa.r12; + env->regs[R_R13] =3D launch_vmsa->vmsa.r13; + env->regs[R_R14] =3D launch_vmsa->vmsa.r14; + env->regs[R_R15] =3D launch_vmsa->vmsa.r15; +#endif + env->eip =3D launch_vmsa->vmsa.rip; + env->eflags =3D launch_vmsa->vmsa.rflags; + + cpu_set_fpuc(env, launch_vmsa->vmsa.x87_fcw); + env->mxcsr =3D launch_vmsa->vmsa.mxcsr; + + break; + } + } +} + +static int sev_set_cpu_context(uint16_t cpu_index, const void *ctx, + uint32_t ctx_len, hwaddr gpa, Error **errp) +{ + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + SevLaunchVmsa *launch_vmsa; + CPUState *cpu; + bool exists =3D false; + + /* + * Setting the CPU context is only supported for SEV-ES and SEV-SNP. T= he + * context buffer will contain a sev_es_save_area from the Linux kernel + * which is defined by "Table B-4. VMSA Layout, State Save Area for SE= V-ES" + * in the AMD64 APM, Volume 2. + */ + + if (!sev_es_enabled()) { + error_setg(errp, "SEV: unable to set CPU context: Not supported"); + return -1; + } + + if (ctx_len < sizeof(struct sev_es_save_area)) { + error_setg(errp, "SEV: unable to set CPU context: " + "Invalid context provided"); + return -1; + } + + cpu =3D qemu_get_cpu(cpu_index); + if (!cpu) { + error_setg(errp, "SEV: unable to set CPU context for out of bounds= " + "CPU index %d", cpu_index); + return -1; + } + + /* + * If the context of this VP has already been set then replace it with= the + * new context. + */ + QTAILQ_FOREACH(launch_vmsa, &sev_common->launch_vmsa, next) + { + if (cpu_index =3D=3D launch_vmsa->cpu_index) { + launch_vmsa->gpa =3D gpa; + memcpy(&launch_vmsa->vmsa, ctx, sizeof(launch_vmsa->vmsa)); + exists =3D true; + break; + } + } + + if (!exists) { + /* New VP context */ + launch_vmsa =3D g_new0(SevLaunchVmsa, 1); + memcpy(&launch_vmsa->vmsa, ctx, sizeof(launch_vmsa->vmsa)); + launch_vmsa->cpu_index =3D cpu_index; + launch_vmsa->gpa =3D gpa; + QTAILQ_INSERT_TAIL(&sev_common->launch_vmsa, launch_vmsa, next); + } + + /* Synchronise the VMSA with the current CPU state */ + sev_apply_cpu_context(cpu); + + return 0; +} + bool sev_enabled(void) { @@ -998,6 +1176,16 @@ static int sev_launch_update_vmsa(SevGuestState *sev_guest) { int ret, fw_error; + CPUState *cpu; + + /* + * The initial CPU state is measured as part of KVM_SEV_LAUNCH_UPDATE_= VMSA. + * Synchronise the CPU state to any provided launch VMSA structures. + */ + CPU_FOREACH(cpu) { + sev_apply_cpu_context(cpu); + } + =20 ret =3D sev_ioctl(SEV_COMMON(sev_guest)->sev_fd, KVM_SEV_LAUNCH_UPDATE= _VMSA, NULL, &fw_error); @@ -1780,40 +1968,109 @@ sev_es_find_reset_vector(void *flash_ptr, uint64_t= flash_size, return sev_es_parse_reset_block(info, addr); } =20 + +static void seg_to_vmsa(const SegmentCache *cpu_seg, struct vmcb_seg *vmsa= _seg) +{ + vmsa_seg->selector =3D cpu_seg->selector; + vmsa_seg->base =3D cpu_seg->base; + vmsa_seg->limit =3D cpu_seg->limit; + vmsa_seg->attrib =3D FLAGS_SEGCACHE_TO_VMSA(cpu_seg->flags); +} + +static void initialize_vmsa(const CPUState *cpu, struct sev_es_save_area *= vmsa) +{ + const X86CPU *x86 =3D X86_CPU(cpu); + const CPUX86State *env =3D &x86->env; + + /* + * Initialize the SEV-ES save area from the current state of + * the CPU. The entire state does not need to be copied, only the state + * that is copied back to the CPUState in sev_apply_cpu_context. + */ + memset(vmsa, 0, sizeof(struct sev_es_save_area)); + vmsa->efer =3D env->efer; + vmsa->cr0 =3D env->cr[0]; + vmsa->cr3 =3D env->cr[3]; + vmsa->cr4 =3D env->cr[4]; + vmsa->xcr0 =3D env->xcr0; + vmsa->g_pat =3D env->pat; + + seg_to_vmsa(&env->segs[R_CS], &vmsa->cs); + seg_to_vmsa(&env->segs[R_DS], &vmsa->ds); + seg_to_vmsa(&env->segs[R_ES], &vmsa->es); + seg_to_vmsa(&env->segs[R_FS], &vmsa->fs); + seg_to_vmsa(&env->segs[R_GS], &vmsa->gs); + seg_to_vmsa(&env->segs[R_SS], &vmsa->ss); + + seg_to_vmsa(&env->gdt, &vmsa->gdtr); + seg_to_vmsa(&env->idt, &vmsa->idtr); + seg_to_vmsa(&env->ldt, &vmsa->ldtr); + seg_to_vmsa(&env->tr, &vmsa->tr); + + vmsa->dr6 =3D env->dr[6]; + vmsa->dr7 =3D env->dr[7]; + + vmsa->rax =3D env->regs[R_EAX]; + vmsa->rcx =3D env->regs[R_ECX]; + vmsa->rdx =3D env->regs[R_EDX]; + vmsa->rbx =3D env->regs[R_EBX]; + vmsa->rsp =3D env->regs[R_ESP]; + vmsa->rbp =3D env->regs[R_EBP]; + vmsa->rsi =3D env->regs[R_ESI]; + vmsa->rdi =3D env->regs[R_EDI]; + +#ifdef TARGET_X86_64 + vmsa->r8 =3D env->regs[R_R8]; + vmsa->r9 =3D env->regs[R_R9]; + vmsa->r10 =3D env->regs[R_R10]; + vmsa->r11 =3D env->regs[R_R11]; + vmsa->r12 =3D env->regs[R_R12]; + vmsa->r13 =3D env->regs[R_R13]; + vmsa->r14 =3D env->regs[R_R14]; + vmsa->r15 =3D env->regs[R_R15]; +#endif + + vmsa->rip =3D env->eip; + vmsa->rflags =3D env->eflags; +} + +static void sev_es_set_ap_context(uint32_t reset_addr) +{ + CPUState *cpu; + struct sev_es_save_area vmsa; + SegmentCache cs; + + cs.selector =3D 0xf000; + cs.base =3D reset_addr & 0xffff0000; + cs.limit =3D 0xffff; + cs.flags =3D DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | DESC_R_MASK | + DESC_A_MASK; + + CPU_FOREACH(cpu) { + if (cpu->cpu_index =3D=3D 0) { + /* Do not update the BSP reset state */ + continue; + } + initialize_vmsa(cpu, &vmsa); + seg_to_vmsa(&cs, &vmsa.cs); + vmsa.rip =3D reset_addr & 0x0000ffff; + sev_set_cpu_context(cpu->cpu_index, &vmsa, + sizeof(struct sev_es_save_area), + 0, &error_fatal); + } +} + void sev_es_set_reset_vector(CPUState *cpu) { - X86CPU *x86; - CPUX86State *env; - ConfidentialGuestSupport *cgs =3D MACHINE(qdev_get_machine())->cgs; - SevCommonState *sev_common =3D SEV_COMMON( - object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON)); - - /* Only update if we have valid reset information */ - if (!sev_common || !sev_common->reset_data_valid) { - return; + if (sev_enabled()) { + sev_apply_cpu_context(cpu); } - - /* Do not update the BSP reset state */ - if (cpu->cpu_index =3D=3D 0) { - return; - } - - x86 =3D X86_CPU(cpu); - env =3D &x86->env; - - cpu_x86_load_seg_cache(env, R_CS, 0xf000, sev_common->reset_cs, 0xffff, - DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | - DESC_R_MASK | DESC_A_MASK); - - env->eip =3D sev_common->reset_ip; } =20 int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size) { - CPUState *cpu; uint32_t addr; int ret; - SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); =20 if (!sev_es_enabled()) { return 0; @@ -1826,14 +2083,12 @@ int sev_es_save_reset_vector(void *flash_ptr, uint6= 4_t flash_size) return ret; } =20 + /* + * The reset vector is saved into a CPU context for each AP but not for + * the BSP. This is applied during guest startup or when the CPU is re= set. + */ if (addr) { - sev_common->reset_cs =3D addr & 0xffff0000; - sev_common->reset_ip =3D addr & 0x0000ffff; - sev_common->reset_data_valid =3D true; - - CPU_FOREACH(cpu) { - sev_es_set_reset_vector(cpu); - } + sev_es_set_ap_context(addr); } =20 return 0; @@ -2068,6 +2323,7 @@ sev_common_instance_init(Object *obj) object_property_add_uint32_ptr(obj, "reduced-phys-bits", &sev_common->reduced_phys_bits, OBJ_PROP_FLAG_READWRITE); + QTAILQ_INIT(&sev_common->launch_vmsa); } =20 /* sev guest info common to sev/sev-es/sev-snp */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492499; cv=none; d=zohomail.com; s=zohoarc; b=VQyP9e5cs+/0RZxzophinQVJ2YrxJu3XTCNGI8bwfFyOUPOR4rNRuerPokXr6Rfpt2hTPzm+5apfxJbBf6IUesiprHJ5pMks4E6msjnwoqCix6j7Hq0eEU+Wf5fyRRt1TPsnGV6j0EJcurIewoX6Y6viRbogSKOcFfwgkezvp3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492499; 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=EraEnuG15QUJZaSBHNd845dFPUl1vsqabBZ9Zpw8ues=; b=Zgs7VxrcbHWu6bQKS4tAa9Qua8n7D41wVZQRWf3lEwcO5cQI8bx9M8hrSkGdfkPCnX7bo09wZ+Tz2k63CpxSSfY6MlAfU0NBg3f0nj0mpBj4EUp/+R77kIwxXLqWrKb9Ec9L2e7QqJ7JYHwVLk9UReUudH9UEfYSie2udw4z7Rk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492499863458.0234701495665; Mon, 14 Jul 2025 04:28:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHK0-00042x-9x; Mon, 14 Jul 2025 07:26:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzs-00018M-AJ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzp-0001sn-Cn for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:23 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-3-SlM8aBGaNxmpua3oogU2HQ-1; Mon, 14 Jul 2025 07:05:19 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a579058758so1669246f8f.1 for ; Mon, 14 Jul 2025 04:05:18 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e14d07sm12278723f8f.66.2025.07.14.04.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491120; 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=EraEnuG15QUJZaSBHNd845dFPUl1vsqabBZ9Zpw8ues=; b=Fe91064qmNJvCwxkR0q8YRA99KXzxz8NDOM56E/CWwWl85UMlU+0naCB9WULc0+C++7FxS mS96ssiYEiAev+423OIgwz7aWbTLoxE96Fn1dYlLw/80xUIJj3qgyj9fh6y84pPnkmBj7e j9Gm9C9UXeAECNhUjlNVjWAvvbPoACQ= X-MC-Unique: SlM8aBGaNxmpua3oogU2HQ-1 X-Mimecast-MFC-AGG-ID: SlM8aBGaNxmpua3oogU2HQ_1752491118 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491116; x=1753095916; 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=EraEnuG15QUJZaSBHNd845dFPUl1vsqabBZ9Zpw8ues=; b=DzG8SKNd43ccbyeBQJe1KL2H415VSKQ3/xJavsEs6c7T4iFCVjt6xiHmzYi3N5fQ+u 48CIh9jJq2g/t8+9aLO56Bu3Lbet50Y0KI6yHoyogAFIjACHeHFhqb1WpMVb98+J8DNM DzNaV4rS4YJW/dCNkOwRKwU7/hqnwnhvZL1L64qHaKr/y4bjFDcBc/0VmepMauThhsaB xsd4uGDpT3EqYqMZA3Bc8Pa/tjpatSgr41vTqyZ6SyeN8/81oDdSDLlfwjHGuCBwDrZm 5bxzPW/eiT3AWpXk8Kk+YDvlPKM4nkSG70c0lCWWrErwJlgSZM77XDr4ONFfss5wJAzH UfCw== X-Gm-Message-State: AOJu0YyN7YaaERz9iZMv//R4Qyibhd/XJHxpclT26KKzuc4bcg0XWnyr mpoGWIG0xH38BL8ueSR+xjoElH1dQi8kM5tUovQrgIMEtZK1emNipxWHgrmbDAVn4y3XR8Vpnxp Q5owWRAGpX97bfBq5Qs/7cGtlM5TP5q4w4k97fqfnpQ4oi7wR0TXZa5xKTc4tTXUgeUPFqu/T+K kSqypIhGrCieLMsyiacGCRzheXC4hNbLNlb3M9S/kE X-Gm-Gg: ASbGncuLNwlt64qgSDzFO15WTRcCF0B9eNvi5Wr8bFY/7zMzHbGoVcxP/PeVfqM3nn2 qhXQdJ4/oj0cjFW37Eq6eQ0WwePTx795D1aUG7QxPGzFbutZBwsU02Zlctivb4WJzjRiJQf5YWT 7UO4tjLCirIlgCdy55YI2p7KNMNIiC3wJej5yJCpHXxA1pKEU4MwawXL6uCOAoA2O4iF6MoSr6+ +C+3av1F96mOWglWBP0KuABIFU2jc4jBN82EWTUJi6iCjPVhY0ojR8Za7+Nphhud6FrYpBSSXvc 2wgzJ2ajJjGf8TueDonCC9SgzLeEFbuRBuu67v3P2PI= X-Received: by 2002:a05:6000:25fc:b0:3a5:8a09:70b7 with SMTP id ffacd0b85a97d-3b5f18dc449mr11467187f8f.38.1752491116191; Mon, 14 Jul 2025 04:05:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWTPSlS+/tu2naGURDAVma1g4jFnsUJ01SV0iQPtZyWrN6+CI0BvMjBIBx9Tt5Wk3HDgjUrw== X-Received: by 2002:a05:6000:25fc:b0:3a5:8a09:70b7 with SMTP id ffacd0b85a97d-3b5f18dc449mr11467151f8f.38.1752491115612; Mon, 14 Jul 2025 04:05:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Stefano Garzarella , Gerd Hoffman , Ani Sinha Subject: [PULL 25/77] i386/sev: Implement ConfidentialGuestSupport functions for SEV Date: Mon, 14 Jul 2025 13:03:14 +0200 Message-ID: <20250714110406.117772-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492501742116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins The ConfidentialGuestSupport object defines a number of virtual functions that are called during processing of IGVM directives to query or configure initial guest state. In order to support processing of IGVM files, these functions need to be implemented by relevant isolation hardware support code such as SEV. This commit implements the required functions for SEV-ES and adds support for processing IGVM files for configuring the guest. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Stefano Garzarella Acked-by: Gerd Hoffman Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/7145835f729e6195f2fbda308aa90e089a96ae6e.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- target/i386/sev.h | 2 + target/i386/sev.c | 254 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 246 insertions(+), 10 deletions(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 38caa849f5e..d2eb06db321 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -44,6 +44,8 @@ bool sev_snp_enabled(void); #define SEV_SNP_POLICY_SMT 0x10000 #define SEV_SNP_POLICY_DBG 0x80000 =20 +#define SVM_SEV_FEAT_SNP_ACTIVE 1 + typedef struct SevKernelLoaderContext { char *setup_data; size_t setup_size; diff --git a/target/i386/sev.c b/target/i386/sev.c index a13f91e615d..1296f4feb62 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -41,7 +41,9 @@ #include "confidential-guest.h" #include "hw/i386/pc.h" #include "system/address-spaces.h" +#include "hw/i386/e820_memory_layout.h" #include "qemu/queue.h" +#include "qemu/cutils.h" =20 OBJECT_DECLARE_TYPE(SevCommonState, SevCommonStateClass, SEV_COMMON) OBJECT_DECLARE_TYPE(SevGuestState, SevCommonStateClass, SEV_GUEST) @@ -50,6 +52,9 @@ OBJECT_DECLARE_TYPE(SevSnpGuestState, SevCommonStateClass= , SEV_SNP_GUEST) /* hard code sha256 digest size */ #define HASH_SIZE 32 =20 +/* Hard coded GPA that KVM uses for the VMSA */ +#define KVM_VMSA_GPA 0xFFFFFFFFF000 + /* Convert between SEV-ES VMSA and SegmentCache flags/attributes */ #define FLAGS_VMSA_TO_SEGCACHE(flags) \ ((((flags) & 0xff00) << 12) | (((flags) & 0xff) << 8)) @@ -480,6 +485,103 @@ static void sev_apply_cpu_context(CPUState *cpu) } } =20 +static int check_vmsa_supported(hwaddr gpa, const struct sev_es_save_area = *vmsa, + Error **errp) +{ + struct sev_es_save_area vmsa_check; + + /* + * KVM always populates the VMSA at a fixed GPA which cannot be modifi= ed + * from userspace. Specifying a different GPA will not prevent the gue= st + * from starting but will cause the launch measurement to be different + * from expected. Therefore check that the provided GPA matches the KVM + * hardcoded value. + */ + if (gpa !=3D KVM_VMSA_GPA) { + error_setg(errp, + "%s: The VMSA GPA must be %lX but is specified as %lX", + __func__, KVM_VMSA_GPA, gpa); + return -1; + } + + /* + * Clear all supported fields so we can then check the entire structure + * is zero. + */ + memcpy(&vmsa_check, vmsa, sizeof(struct sev_es_save_area)); + memset(&vmsa_check.es, 0, sizeof(vmsa_check.es)); + memset(&vmsa_check.cs, 0, sizeof(vmsa_check.cs)); + memset(&vmsa_check.ss, 0, sizeof(vmsa_check.ss)); + memset(&vmsa_check.ds, 0, sizeof(vmsa_check.ds)); + memset(&vmsa_check.fs, 0, sizeof(vmsa_check.fs)); + memset(&vmsa_check.gs, 0, sizeof(vmsa_check.gs)); + memset(&vmsa_check.gdtr, 0, sizeof(vmsa_check.gdtr)); + memset(&vmsa_check.idtr, 0, sizeof(vmsa_check.idtr)); + memset(&vmsa_check.ldtr, 0, sizeof(vmsa_check.ldtr)); + memset(&vmsa_check.tr, 0, sizeof(vmsa_check.tr)); + vmsa_check.efer =3D 0; + vmsa_check.cr0 =3D 0; + vmsa_check.cr3 =3D 0; + vmsa_check.cr4 =3D 0; + vmsa_check.xcr0 =3D 0; + vmsa_check.dr6 =3D 0; + vmsa_check.dr7 =3D 0; + vmsa_check.rax =3D 0; + vmsa_check.rcx =3D 0; + vmsa_check.rdx =3D 0; + vmsa_check.rbx =3D 0; + vmsa_check.rsp =3D 0; + vmsa_check.rbp =3D 0; + vmsa_check.rsi =3D 0; + vmsa_check.rdi =3D 0; + vmsa_check.r8 =3D 0; + vmsa_check.r9 =3D 0; + vmsa_check.r10 =3D 0; + vmsa_check.r11 =3D 0; + vmsa_check.r12 =3D 0; + vmsa_check.r13 =3D 0; + vmsa_check.r14 =3D 0; + vmsa_check.r15 =3D 0; + vmsa_check.rip =3D 0; + vmsa_check.rflags =3D 0; + + vmsa_check.g_pat =3D 0; + vmsa_check.xcr0 =3D 0; + + vmsa_check.x87_fcw =3D 0; + vmsa_check.mxcsr =3D 0; + + if (sev_snp_enabled()) { + if (vmsa_check.sev_features !=3D SVM_SEV_FEAT_SNP_ACTIVE) { + error_setg(errp, + "%s: sev_features in the VMSA contains an unsupport= ed " + "value. For SEV-SNP, sev_features must be set to %x= .", + __func__, SVM_SEV_FEAT_SNP_ACTIVE); + return -1; + } + vmsa_check.sev_features =3D 0; + } else { + if (vmsa_check.sev_features !=3D 0) { + error_setg(errp, + "%s: sev_features in the VMSA contains an unsupport= ed " + "value. For SEV-ES and SEV, sev_features must be " + "set to 0.", __func__); + return -1; + } + } + + if (!buffer_is_zero(&vmsa_check, sizeof(vmsa_check))) { + error_setg(errp, + "%s: The VMSA contains fields that are not " + "synchronized with KVM. Continuing would result in " + "either unpredictable guest behavior, or a " + "mismatched launch measurement.", + __func__); + return -1; + } + return 0; +} + static int sev_set_cpu_context(uint16_t cpu_index, const void *ctx, uint32_t ctx_len, hwaddr gpa, Error **errp) { @@ -1491,18 +1593,26 @@ sev_snp_launch_finish(SevCommonState *sev_common) struct kvm_sev_snp_launch_finish *finish =3D &sev_snp->kvm_finish_conf; =20 /* - * To boot the SNP guest, the hypervisor is required to populate the C= PUID - * and Secrets page before finalizing the launch flow. The location of - * the secrets and CPUID page is available through the OVMF metadata G= UID. + * Populate all the metadata pages if not using an IGVM file. In the c= ase + * where an IGVM file is provided it will be used to configure the met= adata + * pages directly. */ - metadata =3D pc_system_get_ovmf_sev_metadata_ptr(); - if (metadata =3D=3D NULL) { - error_report("%s: Failed to locate SEV metadata header", __func__); - exit(1); - } + if (!X86_MACHINE(qdev_get_machine())->igvm) { + /* + * To boot the SNP guest, the hypervisor is required to populate t= he + * CPUID and Secrets page before finalizing the launch flow. The + * location of the secrets and CPUID page is available through the + * OVMF metadata GUID. + */ + metadata =3D pc_system_get_ovmf_sev_metadata_ptr(); + if (metadata =3D=3D NULL) { + error_report("%s: Failed to locate SEV metadata header", __fun= c__); + exit(1); + } =20 - /* Populate all the metadata pages */ - snp_populate_metadata_pages(sev_snp, metadata); + /* Populate all the metadata pages */ + snp_populate_metadata_pages(sev_snp, metadata); + } =20 QTAILQ_FOREACH(data, &launch_update, next) { ret =3D sev_snp_launch_update(sev_snp, data); @@ -2290,6 +2400,124 @@ static void sev_common_set_kernel_hashes(Object *ob= j, bool value, Error **errp) SEV_COMMON(obj)->kernel_hashes =3D value; } =20 +static bool cgs_check_support(ConfidentialGuestPlatformType platform, + uint16_t platform_version, uint8_t highest_vt= l, + uint64_t shared_gpa_boundary) +{ + return (((platform =3D=3D CGS_PLATFORM_SEV_SNP) && sev_snp_enabled()) = || + ((platform =3D=3D CGS_PLATFORM_SEV_ES) && sev_es_enabled()) || + ((platform =3D=3D CGS_PLATFORM_SEV) && sev_enabled())); +} + +static int cgs_set_guest_state(hwaddr gpa, uint8_t *ptr, uint64_t len, + ConfidentialGuestPageType memory_type, + uint16_t cpu_index, Error **errp) +{ + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + SevCommonStateClass *klass =3D SEV_COMMON_GET_CLASS(sev_common); + + if (!sev_enabled()) { + error_setg(errp, "%s: attempt to configure guest memory, but SEV " + "is not enabled", __func__); + return -1; + } + + switch (memory_type) { + case CGS_PAGE_TYPE_NORMAL: + case CGS_PAGE_TYPE_ZERO: + return klass->launch_update_data(sev_common, gpa, ptr, len, errp); + + case CGS_PAGE_TYPE_VMSA: + if (!sev_es_enabled()) { + error_setg(errp, + "%s: attempt to configure initial VMSA, but SEV-ES " + "is not supported", + __func__); + return -1; + } + if (check_vmsa_supported(gpa, (const struct sev_es_save_area *)ptr, + errp) < 0) { + return -1; + } + return sev_set_cpu_context(cpu_index, ptr, len, gpa, errp); + + case CGS_PAGE_TYPE_UNMEASURED: + if (sev_snp_enabled()) { + return snp_launch_update_data( + gpa, ptr, len, KVM_SEV_SNP_PAGE_TYPE_UNMEASURED, errp); + } + /* No action required if not SEV-SNP */ + return 0; + + case CGS_PAGE_TYPE_SECRETS: + if (!sev_snp_enabled()) { + error_setg(errp, + "%s: attempt to configure secrets page, but SEV-SNP= " + "is not supported", + __func__); + return -1; + } + return snp_launch_update_data(gpa, ptr, len, + KVM_SEV_SNP_PAGE_TYPE_SECRETS, errp); + + case CGS_PAGE_TYPE_REQUIRED_MEMORY: + if (kvm_convert_memory(gpa, len, true) < 0) { + error_setg( + errp, + "%s: failed to configure required memory. gpa: %lX, type: = %d", + __func__, gpa, memory_type); + return -1; + } + return 0; + + case CGS_PAGE_TYPE_CPUID: + if (!sev_snp_enabled()) { + error_setg(errp, + "%s: attempt to configure CPUID page, but SEV-SNP " + "is not supported", + __func__); + return -1; + } + return snp_launch_update_cpuid(gpa, ptr, len, errp); + } + error_setg(errp, "%s: failed to update guest. gpa: %lX, type: %d", __f= unc__, + gpa, memory_type); + return -1; +} + +static int cgs_get_mem_map_entry(int index, + ConfidentialGuestMemoryMapEntry *entry, + Error **errp) +{ + struct e820_entry *table; + int num_entries; + + num_entries =3D e820_get_table(&table); + if ((index < 0) || (index >=3D num_entries)) { + return 1; + } + entry->gpa =3D table[index].address; + entry->size =3D table[index].length; + switch (table[index].type) { + case E820_RAM: + entry->type =3D CGS_MEM_RAM; + break; + case E820_RESERVED: + entry->type =3D CGS_MEM_RESERVED; + break; + case E820_ACPI: + entry->type =3D CGS_MEM_ACPI; + break; + case E820_NVS: + entry->type =3D CGS_MEM_NVS; + break; + case E820_UNUSABLE: + entry->type =3D CGS_MEM_UNUSABLE; + break; + } + return 0; +} + static void sev_common_class_init(ObjectClass *oc, const void *data) { @@ -2313,6 +2541,8 @@ static void sev_common_instance_init(Object *obj) { SevCommonState *sev_common =3D SEV_COMMON(obj); + ConfidentialGuestSupportClass *cgs =3D + CONFIDENTIAL_GUEST_SUPPORT_GET_CLASS(obj); =20 sev_common->kvm_type =3D -1; =20 @@ -2323,6 +2553,10 @@ sev_common_instance_init(Object *obj) object_property_add_uint32_ptr(obj, "reduced-phys-bits", &sev_common->reduced_phys_bits, OBJ_PROP_FLAG_READWRITE); + cgs->check_support =3D cgs_check_support; + cgs->set_guest_state =3D cgs_set_guest_state; + cgs->get_mem_map_entry =3D cgs_get_mem_map_entry; + QTAILQ_INIT(&sev_common->launch_vmsa); } =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492447; cv=none; d=zohomail.com; s=zohoarc; b=QBi9eMkQuGypVxFkhu4fVCnDtGlg9hBrnO0WamQBIQDOfll9elfacVJLAoAKOkThb3BS4EexYPYQtcE3NyXjXZ6SeBxnm7omD3TrJw/qHK8MAJRhvQ3N4TrDPxKM60n0oKDHfDybpgK5zqkXUbTpJxQEPNu5K8yHW+QJZkptOJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492447; h=Content-Type: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=Tb8HqmQk65s0sIuIYN8//M0WKbWp4Ar0Piw+k8limuE=; b=Lkbr89+AAB/GsZdWdxzPN7BioSjLJmPpM9aD0UP3XW9gb2Fha2pfj+mG/5spxDxtkrA9r8g0kk4ECQ1Ky2lmUV55bM1bi6l51oT/Awya//0r/pgQ3MVBN47xUuHUPU27b/3V/3xw21abzgL5HdHgtSkwKEmdeiSdBc7rl0UzqwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492447262721.2668680305247; Mon, 14 Jul 2025 04:27:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEi-0008Mc-Em; Mon, 14 Jul 2025 07:20:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzt-00018T-LO for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzr-0001tB-5M for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:25 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-_nyjgxP5MzOLaAh_XvwWfw-1; Mon, 14 Jul 2025 07:05:20 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a579058758so1669263f8f.1 for ; Mon, 14 Jul 2025 04:05:20 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e8cfsm11756831f8f.80.2025.07.14.04.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tb8HqmQk65s0sIuIYN8//M0WKbWp4Ar0Piw+k8limuE=; b=cRqCmLgVTIebHnmAASXnQaKM3DIgAgfTi7+3jK+rtFNhJa1lub6D+OVHiDirUjNmuPV5Zy xTswTDyIBjyMqL7du23ojhCMu9iVHCnWF1ez0nQZqTWpYs3imSUClK5m++vdFkgYMSp6eS ZxzMTpLNIc4KqtF/pZN3RfBaIywLbfM= X-MC-Unique: _nyjgxP5MzOLaAh_XvwWfw-1 X-Mimecast-MFC-AGG-ID: _nyjgxP5MzOLaAh_XvwWfw_1752491120 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491118; x=1753095918; 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=Tb8HqmQk65s0sIuIYN8//M0WKbWp4Ar0Piw+k8limuE=; b=aiDXHgLczdgTNxaC6cd0P+7sELWR+vhUXqGh4/Me2ji+15VFx0oj3OFqfbNmedaO+w Mf+49qGfHYuQWEE2SQMz/39tz/ZXSqdAwmiafnDj5eGQAQoIF0mpzhI6wfMQ0dtUbPKS ddjJmiojgHrdQQmY81M2a/BFZ0UoA2NkQuFV8WL8/NI6Ue3Ur8iHkalzVBHtB9NLhWcl YF1hNw+9rshlgFs4iRKUz8bxkAWt6LUAD0/3HiFdYKoXWT2X8B5S3YzxSXgJJBk1oOQw Jn3/AyoDdR/nU5HWFm4a6H3krY3aaaJaHfyaV8ZvfA9goUDzMcqLNBWgN/62CgxgbrV4 EZOw== X-Gm-Message-State: AOJu0YyCgX5bI1Sg1GdFT6QgWgDpQSV4ejsMeIxfnIGpYrpQL0tU1hVo B6JUJBSW/vlRrGx8ywifC3FhmQI5plvhJxEff52yP8338xJtqkTxJ+Zl0TISo/JM9T/9L/RV1aP epQqfUD+e0w5817ANxudlRxf5DYBFISejSFzf6+gMRYt6aR70HNTchdb30J8pnvnE0sTY1Xnyex 1mUYJtgNvI2wFnI/MKE4WBKU7wTuHzmuI8/dJ8u2xv X-Gm-Gg: ASbGncvsjtzC6oJ4GhOqvrBzLsTjCD2vS3yTd+kCwkx4DPsUQPoFk+JAKg3fojJy5Eu yVZHWlBwpFRCtGEv3rC6dYt0SPK8q+HV3IAtNh7SVo73lMf9j10UDFzmJoUzKQlt6UP85DTAi/V xRYWZgjgacngH8uDf7S422GPa+sytxFiFgvIyKRMAa8O8swT7Kw3B1XJeZGBogxuCT2qy/1dJQ2 DOU0VJK8ITi+GPkR0cNVaWufcXpA0Z/Lxa5Q46RKpL8H6xv3E6nKQJxkURNfuj989f9305cj1Bh PSEABM07YubQd/CbSiBSz6Ulexh+iLjwczjna5MvmqM= X-Received: by 2002:a05:6000:43d8:b0:3a5:276b:1ec0 with SMTP id ffacd0b85a97d-3b5f18eb539mr7587540f8f.45.1752491118012; Mon, 14 Jul 2025 04:05:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLxe6Pv/JAq/DYpkZ9Ch0HlrtQArZruWL1hai16doCi9lEvmYo5lsLITD8YKLLtQj9syEWDg== X-Received: by 2002:a05:6000:43d8:b0:3a5:276b:1ec0 with SMTP id ffacd0b85a97d-3b5f18eb539mr7587509f8f.45.1752491117369; Mon, 14 Jul 2025 04:05:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Pankaj Gupta , "Michael S. Tsirkin" , Gerd Hoffman , Ani Sinha Subject: [PULL 26/77] docs/system: Add documentation on support for IGVM Date: Mon, 14 Jul 2025 13:03:15 +0200 Message-ID: <20250714110406.117772-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492449092116600 From: Roy Hopkins IGVM support has been implemented for Confidential Guests that support AMD SEV and AMD SEV-ES. Add some documentation that gives some background on the IGVM format and how to use it to configure a confidential guest. Signed-off-by: Roy Hopkins Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Pankaj Gupta Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/b4dc920a30717e19cd79bbbe2cc769f3b9ff3d37.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- docs/system/i386/amd-memory-encryption.rst | 2 + docs/system/igvm.rst | 173 +++++++++++++++++++++ docs/system/index.rst | 1 + 3 files changed, 176 insertions(+) create mode 100644 docs/system/igvm.rst diff --git a/docs/system/i386/amd-memory-encryption.rst b/docs/system/i386/= amd-memory-encryption.rst index 748f5094baf..6c23f3535f4 100644 --- a/docs/system/i386/amd-memory-encryption.rst +++ b/docs/system/i386/amd-memory-encryption.rst @@ -1,3 +1,5 @@ +.. _amd-sev: + AMD Secure Encrypted Virtualization (SEV) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/system/igvm.rst b/docs/system/igvm.rst new file mode 100644 index 00000000000..79508d95880 --- /dev/null +++ b/docs/system/igvm.rst @@ -0,0 +1,173 @@ +Independent Guest Virtual Machine (IGVM) support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +IGVM files are designed to encapsulate all the information required to lau= nch a +virtual machine on any given virtualization stack in a deterministic way. = This +allows the cryptographic measurement of initial guest state for Confidenti= al +Guests to be calculated when the IGVM file is built, allowing a relying pa= rty to +verify the initial state of a guest via a remote attestation. + +Although IGVM files are designed with Confidential Computing in mind, they= can +also be used to configure non-confidential guests. Multiple platforms can = be +defined by a single IGVM file, allowing a single IGVM file to configure a +virtual machine that can run on, for example, TDX, SEV and non-confidential +hosts. + +QEMU supports IGVM files through the user-creatable ``igvm-cfg`` object. T= his +object is used to define the filename of the IGVM file to process. A refer= ence +to the object is added to the ``-machine`` to configure the virtual machine +to use the IGVM file for configuration. + +Confidential platform support is provided through the use of +the ``ConfidentialGuestSupport`` object. If the virtual machine provides an +instance of this object then this is used by the IGVM loader to configure = the +isolation properties of the directives within the file. + +Further Information on IGVM +--------------------------- + +Information about the IGVM format, including links to the format specifica= tion +and documentation for the Rust and C libraries can be found at the project +repository: + +https://github.com/microsoft/igvm + + +Supported Platforms +------------------- + +Currently, IGVM files can be provided for Confidential Guests on host syst= ems +that support AMD SEV, SEV-ES and SEV-SNP with KVM. IGVM files can also be +provided for non-confidential guests. + + +Limitations when using IGVM with AMD SEV, SEV-ES and SEV-SNP +------------------------------------------------------------ + +IGVM files configure the initial state of the guest using a set of directi= ves. +Not every directive is supported by every Confidential Guest type. For exa= mple, +AMD SEV does not support encrypted save state regions, therefore setting t= he +initial CPU state using IGVM for SEV is not possible. When an IGVM file co= ntains +directives that are not supported for the active platform, an error is gen= erated +and the guest launch is aborted. + +The table below describes the list of directives that are supported for SE= V, +SEV-ES, SEV-SNP and non-confidential platforms. + +.. list-table:: SEV, SEV-ES, SEV-SNP & non-confidential Supported Directiv= es + :widths: 35 65 + :header-rows: 1 + + * - IGVM directive + - Notes + * - IGVM_VHT_PAGE_DATA + - ``NORMAL`` zero, measured and unmeasured page types are supported. = Other + page types result in an error. + * - IGVM_VHT_PARAMETER_AREA + - + * - IGVM_VHT_PARAMETER_INSERT + - + * - IGVM_VHT_VP_COUNT_PARAMETER + - The guest parameter page is populated with the CPU count. + * - IGVM_VHT_ENVIRONMENT_INFO_PARAMETER + - The ``memory_is_shared`` parameter is set to 1 in the guest paramet= er + page. + +.. list-table:: Additional SEV, SEV-ES & SEV_SNP Supported Directives + :widths: 25 75 + :header-rows: 1 + + * - IGVM directive + - Notes + * - IGVM_VHT_MEMORY_MAP + - The memory map page is populated using entries from the E820 table. + * - IGVM_VHT_REQUIRED_MEMORY + - Ensures memory is available in the guest at the specified range. + +.. list-table:: Additional SEV-ES & SEV-SNP Supported Directives + :widths: 25 75 + :header-rows: 1 + + * - IGVM directive + - Notes + * - IGVM_VHT_VP_CONTEXT + - Setting of the initial CPU state for the boot CPU and additional CP= Us is + supported with limitations on the fields that can be provided in the + VMSA. See below for details on which fields are supported. + +Initial CPU state with VMSA +--------------------------- + +The initial state of guest CPUs can be defined in the IGVM file for AMD SE= V-ES +and SEV-SNP. The state data is provided as a VMSA structure as defined in = Table +B-4 in the AMD64 Architecture Programmer's Manual, Volume 2 [1]. + +The IGVM VMSA is translated to CPU state in QEMU which is then synchronized +by KVM to the guest VMSA during the launch process where it contributes to= the +launch measurement. See :ref:`amd-sev` for details on the launch process a= nd +guest launch measurement. + +It is important that no information is lost or changed when translating the +VMSA provided by the IGVM file into the VSMA that is used to launch the gu= est. +Therefore, QEMU restricts the VMSA fields that can be provided in the IGVM +VMSA structure to the following registers: + +RAX, RCX, RDX, RBX, RBP, RSI, RDI, R8-R15, RSP, RIP, CS, DS, ES, FS, GS, S= S, +CR0, CR3, CR4, XCR0, EFER, PAT, GDT, IDT, LDTR, TR, DR6, DR7, RFLAGS, X87_= FCW, +MXCSR. + +When processing the IGVM file, QEMU will check if any fields other than the +above are non-zero and generate an error if this is the case. + +KVM uses a hardcoded GPA of 0xFFFFFFFFF000 for the VMSA. When an IGVM file +defines initial CPU state, the GPA for each VMSA must match this hardcoded +value. + +Firmware Images with IGVM +------------------------- + +When an IGVM filename is specified for a Confidential Guest Support object= it +overrides the default handling of system firmware: the firmware image, suc= h as +an OVMF binary should be contained as a payload of the IGVM file and not +provided as a flash drive or via the ``-bios`` parameter. The default QEMU +firmware is not automatically populated into the guest memory space. + +If an IGVM file is provided along with either the ``-bios`` parameter or p= flash +devices then an error is displayed and the guest startup is aborted. + +Running a guest configured using IGVM +------------------------------------- + +To run a guest configured with IGVM you firstly need to generate an IGVM f= ile +that contains a guest configuration compatible with the platform you are +targeting. + +The ``buildigvm`` tool [2] is an example of a tool that can be used to gen= erate +IGVM files for non-confidential X86 platforms as well as for SEV, SEV-ES a= nd +SEV-SNP confidential platforms. + +Example using this tool to generate an IGVM file for AMD SEV-SNP:: + + buildigvm --firmware /path/to/OVMF.fd --output sev-snp.igvm \ + --cpucount 4 sev-snp + +To run a guest configured with the generated IGVM you need to add an +``igvm-cfg`` object and refer to it from the ``-machine`` parameter: + +Example (for AMD SEV):: + + qemu-system-x86_64 \ + \ + -machine ...,confidential-guest-support=3Dsev0,igvm-cfg=3Digvm0 \ + -object sev-guest,id=3Dsev0,cbitpos=3D47,reduced-phys-bits=3D1 \ + -object igvm-cfg,id=3Digvm0,file=3D/path/to/sev-snp.igvm + +References +---------- + +[1] AMD64 Architecture Programmer's Manual, Volume 2: System Programming + Rev 3.41 + https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/pro= grammer-references/24593.pdf + +[2] ``buildigvm`` - A tool to build example IGVM files containing OVMF fir= mware + https://github.com/roy-hopkins/buildigvm \ No newline at end of file diff --git a/docs/system/index.rst b/docs/system/index.rst index 718e9d3c56b..427b0204831 100644 --- a/docs/system/index.rst +++ b/docs/system/index.rst @@ -38,5 +38,6 @@ or Hypervisor.Framework. security multi-process confidential-guest-support + igvm vm-templating sriov --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493025; cv=none; d=zohomail.com; s=zohoarc; b=MA+cWjSCuJcvPQCsfCye+iSeZQn4x6D11Q3md3QGXNHOKimm5cptwlOYztXXIbo6WuYgrwWY2yL5QLPM/FLBhsdfCNpiUkaOdwlkMD/mKLp2/SkqjRom1JbTHhkba74l/yZiIcDRXuiSVUXlvpwrazy+PaYGjRGpxa925bDqP3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493025; 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=NvpGOGtkXq9bzXlo3ev/yqxveN9qZSX3B7D9nwqE1Mo=; b=CxgUKWeckB0nxPP96a69eVdhAySseW8FdmDvfB4hCCPJdqE1NAuIHMMGUvJVI0wmtBgofj7l+VgX1PgzeKYxkUhBdKy4FO2FmpY2C3+OeBtxogPa9pyh4zLeYFPH4Q4zKaJjnZMpOy1r2UZl4NrxzFciMv/fY38N8lKJikiZ94c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493025051144.16074077918165; Mon, 14 Jul 2025 04:37:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHKA-0004OL-Ar; Mon, 14 Jul 2025 07:26:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH01-0001CK-EN for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzt-0001tq-J1 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:31 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-4k2B5JDLOdqSpcRhxDd49Q-1; Mon, 14 Jul 2025 07:05:23 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4834765e9.1 for ; Mon, 14 Jul 2025 04:05:23 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d867sm12295222f8f.61.2025.07.14.04.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491125; 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=NvpGOGtkXq9bzXlo3ev/yqxveN9qZSX3B7D9nwqE1Mo=; b=Wv9ygggiqO6kzvs35mv0YwVffHNFG2aQ+LU30VXpA5B1qoTd8TZ5zfkuk1xzymJF7O7xSC JZszJvNYfGzkNZWm9QWhzSNdant7iq4rHWLESeMjNwWyvwx1Xsk0izkenqyt5p/7k4lhR4 Wr1jrWm/+gKyP6YGqAXBs07XPKAlGvI= X-MC-Unique: 4k2B5JDLOdqSpcRhxDd49Q-1 X-Mimecast-MFC-AGG-ID: 4k2B5JDLOdqSpcRhxDd49Q_1752491122 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491122; x=1753095922; 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=NvpGOGtkXq9bzXlo3ev/yqxveN9qZSX3B7D9nwqE1Mo=; b=kCSrTIu6aJiGv5PfvPVqyRhPFItMVUyM9o3rZOXshzvxkyOQTX0JoLA5akN6bUHLq2 Z2ZXaGVJ+MvILDeQUqQj00Le9uuLFIey7ePqOgvzZvAslSpyJFFhYAfF81QsMjcqHiot aNMWXaWfYSEpTCCVxNeHFimNm/8NnR+uaf0FqE0nGjPFtGeBYU3xiM2b3ItLtzvYyenh myFvN72k315kDABwPQ/fNxDNurVD7vfQSC1ubaxjOZdIdFDh9RnaDj4qfbdEPgz6z8yN QaTKiJaV2aazsyjl38tJRuuGgsarkSI9sl8iu5lPq6z/rmOfcgzrg46q3QSN7DrL85Kg 85JQ== X-Gm-Message-State: AOJu0YwaEueWnfHOWUPpERNW32UoIM26LHR9WqPKIOFa81KY7JiFXSuO w+CJ8xPaOPJbiszZRiF6G2B6CYU4PduHkmpljz2dm9rzjKHt5UsUC0OWh/uvf2HPyzCsIhxy4TB YEs6RoGlxvAE6hg+av2e6kgyPd3NHFXG19O367OHZot9X41mxGK1+nAJj8ca5eXOVeSK0Y4BLeU 6VBE2G+FPkSaCB7vgI/Hd+hQpJ4W7GtRoAPeljSgzI X-Gm-Gg: ASbGncuhiX3HEpNlRAOThwBnuMjhcRIf7SRvdeQD+arhq7eaFley6hoDYx9ecZu3z/o iRT+9SA6+YQUlUc4LZ58Mc4A0f+N+Fkr4krg4vpKY9VVw8+UGLtBoSc70VEFban1aonjgyIw++O xMYLWLAtQV/TJfXaUt0hdW+SeZYSwS01CQxz1xAM+K470JD3/5EsZNykf6oYc/En0VUYYPhT+qa 1NbIgw9DViK2DURrjefyvtaCoxMAsBcFvZ6XpoZJMlP25XnCDoxnahVBRzPfpH5yncxIjHvgAVQ P+0PgSVnIFqz5Zt/OrgA5+fsbddtOEHfFSU8qcUnmoE= X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76216015e9.33.1752491121764; Mon, 14 Jul 2025 04:05:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4QgZIKE5BhZ6dypBvpcgrGukwpCV43ru3hLDguuRVQEgHUnwQkNvXnfqHMlDXL/jInNndow== X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76215665e9.33.1752491120958; Mon, 14 Jul 2025 04:05:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , Stefano Garzarella , Ani Sinha Subject: [PULL 27/77] docs/interop/firmware.json: Add igvm to FirmwareDevice Date: Mon, 14 Jul 2025 13:03:16 +0200 Message-ID: <20250714110406.117772-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493032423116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins Create an enum entry within FirmwareDevice for 'igvm' to describe that an IGVM file can be used to map firmware into memory as an alternative to pre-existing firmware devices. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/2eca2611d372facbffa65ee8244cf2d321eb9d17.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- docs/interop/firmware.json | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/interop/firmware.json b/docs/interop/firmware.json index 745d21d8223..0711b6f323d 100644 --- a/docs/interop/firmware.json +++ b/docs/interop/firmware.json @@ -57,10 +57,17 @@ # # @memory: The firmware is to be mapped into memory. # +# @igvm: The firmware is defined by a file conforming to the IGVM +# specification and mapped into memory according to directives +# defined in the file. This is similar to @memory but may +# include additional processing defined by the IGVM file +# including initial CPU state or population of metadata into +# the guest address space. Since: 10.1 +# # Since: 3.0 ## { 'enum' : 'FirmwareDevice', - 'data' : [ 'flash', 'kernel', 'memory' ] } + 'data' : [ 'flash', 'kernel', 'memory', 'igvm' ] } =20 ## # @FirmwareArchitecture: @@ -377,6 +384,24 @@ { 'struct' : 'FirmwareMappingMemory', 'data' : { 'filename' : 'str' } } =20 +## +# @FirmwareMappingIgvm: +# +# Describes loading and mapping properties for the firmware executable, +# when @FirmwareDevice is @igvm. +# +# @filename: Identifies the IGVM file containing the firmware executable +# along with other information used to configure the initial +# state of the guest. The IGVM file may be shared by multiple +# virtual machine definitions. This corresponds to creating +# an object on the command line with "-object igvm-cfg, +# file=3D@filename". +# +# Since: 10.1 +## +{ 'struct' : 'FirmwareMappingIgvm', + 'data' : { 'filename' : 'str' } } + ## # @FirmwareMapping: # @@ -393,7 +418,8 @@ 'discriminator' : 'device', 'data' : { 'flash' : 'FirmwareMappingFlash', 'kernel' : 'FirmwareMappingKernel', - 'memory' : 'FirmwareMappingMemory' } } + 'memory' : 'FirmwareMappingMemory', + 'igvm' : 'FirmwareMappingIgvm' } } =20 ## # @Firmware: --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491522; cv=none; d=zohomail.com; s=zohoarc; b=BQk9vPQXd82r6nzW59xJ6eX+Knc7mtms/7JQfEMDMOHQ+mqWp6W7Z2i/ljvkucOnC0TQqxCeAnp0CVyY1i50WU9Q/8AecDKFGBzRBWHGDDqVnDNe+8V/xHULtg0QiSDP8aIHx4nUzLN+B4dDh5ALZPOG9UPr7ppA9cQbCNfKp8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491522; h=Content-Type: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=4piWLg9/pXsMcb3TiD2BHuTgGHPf6VBLd1qMmuarZko=; b=QjEW/xayjxF3VacRxsvORu+5m85B2aoR0tEP+sIlNIcqSTY6ODy+wy5kINoJoSLCQFgMxkiYHnwrr8Rr93dxK3RS+RACQMYVP7xhX4oIA8H9efgh9kzpXZs0dLyZK00TzzqyZFI3dgytHEznDGkk8DttZx5jisK2AXjrcgfpFw8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491522828326.318809848862; Mon, 14 Jul 2025 04:12:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubH4X-0004zX-4q; Mon, 14 Jul 2025 07:10:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH01-0001CL-Ek for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubGzx-0001u6-9Z for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:31 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-2yRkKJEtMii5qV9BvQPvPw-1; Mon, 14 Jul 2025 07:05:26 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4561611dc2aso8324635e9.0 for ; Mon, 14 Jul 2025 04:05:25 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454dd474a9csm128750895e9.16.2025.07.14.04.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4piWLg9/pXsMcb3TiD2BHuTgGHPf6VBLd1qMmuarZko=; b=Y3zgeAZu2yLvUCOBimWIjEhrJ2nz5yxmTOIIa6NvWddZIGDRP7ukG7tsEfff6SG3rzWnn1 zsp0dfBQpgfgD4W0TiCDKck/GeFA3yDURdMoHAb2KJqBX7d0YKT8uUXCacOElgcJ7L8FPh aW/zy0DkrcOgrVbOqRaNOcDqVln5Edk= X-MC-Unique: 2yRkKJEtMii5qV9BvQPvPw-1 X-Mimecast-MFC-AGG-ID: 2yRkKJEtMii5qV9BvQPvPw_1752491125 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491124; x=1753095924; 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=4piWLg9/pXsMcb3TiD2BHuTgGHPf6VBLd1qMmuarZko=; b=JlPPm6mv3TcTWmec6Ow484mbZNH+g6D2NdwFj/0yS2YFuHP2VgSzZy2/gFO3MQYQw2 qBa4HhF5Z34UWaCIvwzgPVrwXebBWriQqQ15kusjN/E5AG91nvhzgVOzZPVqXzVg2Hoj iYH1elg8i1bfBokMuPWl1GMQ6z+YK1AoLgV54lSwt7XxQj3MZvKjAFAuW5s2f8Ati9Op FNIY1qcDwkVHqkcs48KMWYeZACQi6sQmtX/9pmKQeEv/5cmCGtP6wptweaCQLmSBKDku BGNjhb0JI4feSosBBbnCLHGOhGb2s80GhxkneN8KcW9i7EkYo/MhKOm+wtYHtlb8r3xc Ku+Q== X-Gm-Message-State: AOJu0Yyy/rK/xEgk1HO3Y7uDH7vsvDbctT7+aaNH5x81CA8Ah2EUfLNh myrKwnjec9IW+HBYYHg5V3qeR4hrY+SL5bxgRdVlQpnrhCkaqtw7XpS+DK7uN80/AfiEYTXqefg /xqVIA/8/FiKlKOAd5NzteX0D4aSSWpQa7JbfM7l/o5Z9GOXlYvBPMrbQhNg5/q0jXit1Pgsoo7 1jIn37YX7JFg0aWVDDRvBKLIlIisQhQoTQvSfm0vt8 X-Gm-Gg: ASbGncs2CyjOu4DXOGqJWJ78GFvGdwRLFfMeRuDkKDOmSrRJSnRQGyn9k1GQmrmoxRS MAtzz43jTB5tmleKrfObxzWRN+3KVFp9KEaOms6CsvOA9ZdmnOvMFrs+hznse/CFoPHFUpjIeUg phT34MAyb9Kg7w4mnJSPdpFifTw/FL+ejCA2SJUnPPsJ+1Nt5yDNRxG+ft6h4ftKH/br/NOlzYB f3CL1RkTgpLxnSgwMOSSRvKjgnjCrJd/No+nlZzrGZVDePOvPzfoHhxmWzcrtoFcD6XBOSy8NKR ZI3F65BkCl0NaWyJDf2S/lygruraHdcG/+KBiX0B3Ps= X-Received: by 2002:a05:600c:4684:b0:442:f97f:8174 with SMTP id 5b1f17b1804b1-454ec276b88mr126459285e9.18.1752491124180; Mon, 14 Jul 2025 04:05:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEc+/ULmaxrDqNpI0hd6eOH3oSnVWQyHLruBeh9qMxV1XGg356s67iG6GWieEzm8iaK5RHzpg== X-Received: by 2002:a05:600c:4684:b0:442:f97f:8174 with SMTP id 5b1f17b1804b1-454ec276b88mr126458775e9.18.1752491123588; Mon, 14 Jul 2025 04:05:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Ani Sinha , "Michael S. Tsirkin" , Gerd Hoffman Subject: [PULL 28/77] backends/confidential-guest-support: Add set_guest_policy() function Date: Mon, 14 Jul 2025 13:03:17 +0200 Message-ID: <20250714110406.117772-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491525150116600 From: Roy Hopkins For confidential guests a policy can be provided that defines the security level, debug status, expected launch measurement and other parameters that define the configuration of the confidential platform. This commit adds a new function named set_guest_policy() that can be implemented by each confidential platform, such as AMD SEV to set the policy. This will allow configuration of the policy from a multi-platform resource such as an IGVM file without the IGVM processor requiring specific implementation details for each platform. Signed-off-by: Roy Hopkins Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Ani Sinha Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Link: https://lore.kernel.org/r/d3888a2eb170c8d8c85a1c4b7e99accf3a15589c.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- include/system/confidential-guest-support.h | 21 +++++++++++++++++++++ backends/confidential-guest-support.c | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/system/confidential-guest-support.h b/include/system/c= onfidential-guest-support.h index 79ecd21f42f..0cc8b26e644 100644 --- a/include/system/confidential-guest-support.h +++ b/include/system/confidential-guest-support.h @@ -57,6 +57,10 @@ typedef enum ConfidentialGuestPageType { CGS_PAGE_TYPE_REQUIRED_MEMORY, } ConfidentialGuestPageType; =20 +typedef enum ConfidentialGuestPolicyType { + GUEST_POLICY_SEV, +} ConfidentialGuestPolicyType; + struct ConfidentialGuestSupport { Object parent; =20 @@ -123,6 +127,23 @@ typedef struct ConfidentialGuestSupportClass { ConfidentialGuestPageType memory_type, uint16_t cpu_index, Error **errp); =20 + /* + * Set the guest policy. The policy can be used to configure the + * confidential platform, such as if debug is enabled or not and can c= ontain + * information about expected launch measurements, signed verification= of + * guest configuration and other platform data. + * + * The format of the policy data is specific to each platform. For exa= mple, + * SEV-SNP uses a policy bitfield in the 'policy' argument and provide= s an + * ID block and ID authentication in the 'policy_data' parameters. The= type + * of policy data is identified by the 'policy_type' argument. + */ + int (*set_guest_policy)(ConfidentialGuestPolicyType policy_type, + uint64_t policy, + void *policy_data1, uint32_t policy_data1_size, + void *policy_data2, uint32_t policy_data2_size, + Error **errp); + /* * Iterate the system memory map, getting the entry with the given ind= ex * that can be populated into guest memory. diff --git a/backends/confidential-guest-support.c b/backends/confidential-= guest-support.c index c5bef1fbfa8..156dd15e667 100644 --- a/backends/confidential-guest-support.c +++ b/backends/confidential-guest-support.c @@ -38,6 +38,17 @@ static int set_guest_state(hwaddr gpa, uint8_t *ptr, uin= t64_t len, return -1; } =20 +static int set_guest_policy(ConfidentialGuestPolicyType policy_type, + uint64_t policy, + void *policy_data1, uint32_t policy_data1_size, + void *policy_data2, uint32_t policy_data2_size, + Error **errp) +{ + error_setg(errp, + "Setting confidential guest policy is not supported for thi= s platform"); + return -1; +} + static int get_mem_map_entry(int index, ConfidentialGuestMemoryMapEntry *e= ntry, Error **errp) { @@ -53,6 +64,7 @@ static void confidential_guest_support_class_init(ObjectC= lass *oc, ConfidentialGuestSupportClass *cgsc =3D CONFIDENTIAL_GUEST_SUPPORT_CLA= SS(oc); cgsc->check_support =3D check_support; cgsc->set_guest_state =3D set_guest_state; + cgsc->set_guest_policy =3D set_guest_policy; cgsc->get_mem_map_entry =3D get_mem_map_entry; } =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493558; cv=none; d=zohomail.com; s=zohoarc; b=a3/TTc3mSZuZMQxCs2CUfPQpCxsvce0Wi7A+u0GlUhq8iy/SxGUnG5OtfBe25kGcHUdHiQvqAMdx0AXTX8R3ObRgCOSSUklizfM4ttAVEgt36SLLDwWGz15q6LsqDX1Aq3XY/Q92+OhtuKU8Alw3pZj6JiNLVa3HVicVUFBktWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493558; 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=BVHO2u8SmUDUe3LEdxt2f5AcmTsLQh2zAS3ZSUXRVXU=; b=ekhyDgjAoSJG7jgUMf3oYaf7Z6UmC2QxTdTPvtXr9xog0ovFnamdI9F5uwGnVj9jvTs2N91UEc9iNnsRAzO383tofctSw6wSq/6koKl1DRemHQm9B2mjMZ3qmrvG6CqZvpogXbxCwKoj2Oh5ypEPkdCybuvc0xboKtIh42J769c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249355815186.4878904931195; Mon, 14 Jul 2025 04:45:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEu-0000T2-G6; Mon, 14 Jul 2025 07:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH03-0001Cw-C5 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH00-0001uO-Ec for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:34 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-ZxL0rAm4NO2aocjXxU4oiA-1; Mon, 14 Jul 2025 07:05:28 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3b5f97cb8fbso576970f8f.3 for ; Mon, 14 Jul 2025 04:05:28 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45623f4f838sm169425e9.1.2025.07.14.04.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491129; 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=BVHO2u8SmUDUe3LEdxt2f5AcmTsLQh2zAS3ZSUXRVXU=; b=S7Ixespu0aY54NX4RAFC9dcQ8mdeacPZDqe1N3JgRlvaKSzISO5RkbK5PoiV+hqKogIyUt cKlpyfRHhx2oXzTObBHn93xnM0Qd2d4xeHUTxuJ3Q81qfGVmkJeSxyyCE8sqVdjirbidRP c+r8QO7RMK6JtswoupCp7gNm6BByWPU= X-MC-Unique: ZxL0rAm4NO2aocjXxU4oiA-1 X-Mimecast-MFC-AGG-ID: ZxL0rAm4NO2aocjXxU4oiA_1752491127 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491126; x=1753095926; 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=BVHO2u8SmUDUe3LEdxt2f5AcmTsLQh2zAS3ZSUXRVXU=; b=KF1IwXmV2NzjnMnhqexM8/MjFuplp+WGIYEpfvF1XXSrRpa9iefjzOgpZ1Buy7clAg zaLjpf79YWyoRsJJC49fNf5nAd/jPQjonz5+KxK7FhluJG078cwQ+AgeII561afMdJ+6 y/8tnsRPBDXzmohlO9f6lvoIU78ByiMwZZeRSs624a9y6TRgAYHwgfvZd8fUjhr9V5KY TX8yGOaXyJ9K3kdKtk2Z/c+jG0+jiR7/0gI5JDCHXXMbmyYopPY2DV0mN2YyK6m3SICh T5PzYBaLPRAxuB8ttU5HTbgxH6D3hh5x7vVTeKxf1OOD0G0R6oSAh+nEzSYWmgo4NeGq koaQ== X-Gm-Message-State: AOJu0YxUr57X0MQib6BVUOoANVIfag3YFuxLSV/JINSYNyzkcWr3939C XKT+Vbfr47vR1jMwWlXbfDojuz7KO9NetvP5RUpb7FVDqsZmcrDdYNgJrKq+EQJZSIpiSEt/CW8 7ktYkDJr6/oKV2WQ9xQIFgYswXQgiamcnn6SdpGqnVeym3IvxdjGgLvnT6snapxPRxemsycQR9d zxe1xocOE7WVogRey99dV+q3x2zBwMlVlbXAhmeOGp X-Gm-Gg: ASbGncu0uh7z3iI+HlQ7m21fBN63JdQD0eJi8zCK5BNNaAUrQkxb1WA+D6jSNeVqBDe 6jrmHs6UNzvg2hYdfK2RJ+E9NhTt0G7zQH7RljTpPoILoVd6HDXMxvOkj7v8B+9Y8LDXrafgqg3 T0jeJBbIj+jL3H0cZZE9P8GFz1ldkYvsc+3T6a30BSLZ3VPmOU+Z1i0ukgopaLFLn/nP39Rnvgj 34y6+cFVaZ7gc7kyOkrQnDlVwWp9IML5jq2XUE2hHusgLRgPaaZe5roSIlh7j1xFupuQvr+q8fh k0ha5a7uVREXKqHVVnpQ2AVQYpvvrDS460gL4NxyL/4= X-Received: by 2002:a05:6000:23c8:b0:3a5:2b75:56cc with SMTP id ffacd0b85a97d-3b5f1895be6mr7251088f8f.23.1752491126090; Mon, 14 Jul 2025 04:05:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEu4oJOvMpEE+COZ74cajQ5huM1RITiW1sbVI+/xC7GYTvyu58ggMweSEATiVK9zfoL3qMNNg== X-Received: by 2002:a05:6000:23c8:b0:3a5:2b75:56cc with SMTP id ffacd0b85a97d-3b5f1895be6mr7251061f8f.23.1752491125577; Mon, 14 Jul 2025 04:05:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Gerd Hoffman , Stefano Garzarella Subject: [PULL 29/77] backends/igvm: Process initialization sections in IGVM file Date: Mon, 14 Jul 2025 13:03:18 +0200 Message-ID: <20250714110406.117772-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493559901116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins The initialization sections in IGVM files contain configuration that should be applied to the guest platform before it is started. This includes guest policy and other information that can affect the security level and the startup measurement of a guest. This commit introduces handling of the initialization sections during processing of the IGVM file. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Gerd Hoffman Reviewed-by: Stefano Garzarella Link: https://lore.kernel.org/r/9de24fb5df402024b40cbe02de0b13faa7cb4d84.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- backends/igvm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backends/igvm.c b/backends/igvm.c index 2a31021d449..ebdb4594d10 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -786,6 +786,27 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuest= Support *cgs, } } =20 + header_count =3D + igvm_header_count(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION); + if (header_count < 0) { + error_setg( + errp, + "Invalid initialization header count in IGVM file. Error code:= %X", + header_count); + goto cleanup_parameters; + } + + for (ctx.current_header_index =3D 0; + ctx.current_header_index < (unsigned)header_count; + ctx.current_header_index++) { + IgvmVariableHeaderType type =3D + igvm_get_header_type(ctx.file, IGVM_HEADER_SECTION_INITIALIZAT= ION, + ctx.current_header_index); + if (qigvm_handler(&ctx, type, errp) < 0) { + goto cleanup_parameters; + } + } + /* * Contiguous pages of data with compatible flags are grouped together= in * order to reduce the number of memory regions we create. Make sure t= he --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492060; cv=none; d=zohomail.com; s=zohoarc; b=NjCuQgIgbwCD4MaE7+JNImQ8mU1PFzkSFzdPg4upJcj5SLG0fTJEehSvaiID+8p8NXjxbAI4RM5Rp0IXl/lRSI6ipEdDspNG/1Jsr5mQir/hXCtHC5DNZGJcMNczF4TNILwrcTfaSDPmvMYoZwbs8dfGYukIDd6qNydvRlBxZvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492060; 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=bAFYBMqDkt14ySi0Xw+9xNW0w03TjzSq5ICCJDbgD3I=; b=bvFmRhUEf0j6AX16Ic1OEHBKmJCWqvWwFQnjdyGubJmzG1D91o6Oq8a4cDTpVfokspdhAZEpKs6COB8QdN7+2TzwpEKWPKJZC2OHf2+pfBslxKE3jX8WU6Du3LgFasFKoLqST2+/Kpk9f0oHKI/2k74ilAcWYkR5wRc5K+0ymg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17524920603241023.5084441999633; Mon, 14 Jul 2025 04:21:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEe-0008Fo-Iq; Mon, 14 Jul 2025 07:20:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH05-0001Ej-5v for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH01-0001um-8c for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:35 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-5ycy_HUiMFmIibCKqJHgiA-1; Mon, 14 Jul 2025 07:05:31 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4561c67daebso2041675e9.1 for ; Mon, 14 Jul 2025 04:05:31 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc3a62sm11962455f8f.40.2025.07.14.04.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491132; 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=bAFYBMqDkt14ySi0Xw+9xNW0w03TjzSq5ICCJDbgD3I=; b=MZ7OX2PuIA2zpED9wfAsXOk+ggb5dLXDmnMzkSG+fZCPQIl5ZWTnJtAlXzd1PvDcO9wBFY sPRGJwF0EzS0NOv2qjiy5js2jzGrs0tKu4QGtqkMWXz7fQ3asTNwyGCA+RCiRvBoAxzPoa GeH0EsKRGP1SFIKt8t52qcnH61stNrs= X-MC-Unique: 5ycy_HUiMFmIibCKqJHgiA-1 X-Mimecast-MFC-AGG-ID: 5ycy_HUiMFmIibCKqJHgiA_1752491130 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491129; x=1753095929; 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=bAFYBMqDkt14ySi0Xw+9xNW0w03TjzSq5ICCJDbgD3I=; b=FDKYOeN8vNGPodWVI6fGJpQmHCz0GoGYGrkomLhq4MJX0IepzJhos/870gHQescllf //vejiD5Rf3Zp9TMjstJBTgwzpItlqFv4NtPBl2zdQpZaSRM3eF1vdL0tq7gHVp4IDiP /LjkBVCg1vP+WLCv0/1iexZAkt0CaeFYW9eVBXr5fCI+cG/q1ujD6A+rEbh6SeAui7AB fkPxQFj2+eWSr88B7kWoi9rDucoyn3sjjm9KehS0/JTHBl/NcWCZQzrglIjq6Z0nQ7ac unkofwFwJ3KW01zmXAV33wAKBa7QvzOy2q7/S2j9WVKyu4aOf6EtcCbElu5wTxhOcL0m CDoQ== X-Gm-Message-State: AOJu0YxSW0X8Ws9LmsmwR0uA+IhieUViZvajDSkrOi3kxSPpMqcbXjIg TOumUwn9ElUpV/q4dM6Zc0Oec166ntmeQ6VJ8e/3TFSBS9mreOHLgSqtcQswvLkVx2KCE12vI2G WivIIrfZ+icoUQyyJ9hebBgSwTm3c8mYQ3OVDSt//ujkIdPopoqUqwcxLU0tSy2Cy61jOLI26QK y4el3NlXTBfshIRDISpBxieb/DSfhXeK2Y5lW/e8v/ X-Gm-Gg: ASbGncvuzCKm56oej91ZGKEZkUrMvR8hmunxHRaBfrN6p4yaKeDyUspS0au7up44Mhc SA6NZ9blJ7s15jw0mqUau+gdYWodeJzKIZ2nHqNN4ymh7TeYwW0JHd9W3gfzEEt99kPBWvujUsN cK0TE2RWL5lNrrKISQFcCC5RnlpPOQFBVYWGwvL9tYPDMPom7xXuzRzZ5NRcjHbyIeuWAsTYKEV Kk/0KfOH+w/KAimfOl3tbzcTSYqng2uEDs7ptCd13hlZohi+WGFwFa85XN3kc6S95y4ChxeveHZ FE/SsNzf1UAgi+29JoLscKi2larTFBDCzGaD4PS0Cn4= X-Received: by 2002:a05:600c:4e08:b0:439:4b23:9e8e with SMTP id 5b1f17b1804b1-454e31d6d6fmr121554365e9.3.1752491129293; Mon, 14 Jul 2025 04:05:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0vM9DOBjyUWqieFVCBul1Ha39Puft5Dh5adfBiIWwg3oFstKafSOHcmt1Ef3KM/K44eGYHQ== X-Received: by 2002:a05:600c:4e08:b0:439:4b23:9e8e with SMTP id 5b1f17b1804b1-454e31d6d6fmr121553845e9.3.1752491128648; Mon, 14 Jul 2025 04:05:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Stefano Garzarella , Gerd Hoffman , Ani Sinha Subject: [PULL 30/77] backends/igvm: Handle policy for SEV guests Date: Mon, 14 Jul 2025 13:03:19 +0200 Message-ID: <20250714110406.117772-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492067284116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins Adds a handler for the guest policy initialization IGVM section and builds an SEV policy based on this information and the ID block directive if present. The policy is applied using by calling 'set_guest_policy()' on the ConfidentialGuestSupport object. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Stefano Garzarella Acked-by: Gerd Hoffman Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/57707230bef331b53e9366ce6a23ed25cd6f1293.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- backends/igvm.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/backends/igvm.c b/backends/igvm.c index ebdb4594d10..b568f06c769 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -27,6 +27,40 @@ typedef struct QIgvmParameterData { uint32_t index; } QIgvmParameterData; =20 +/* + * Some directives are specific to particular confidential computing platf= orms. + * Define required types for each of those platforms here. + */ + +/* SEV/SEV-ES/SEV-SNP */ + +/* + * These structures are defined in "SEV Secure Nested Paging Firmware ABI + * Specification" Rev 1.58, section 8.18. + */ +struct QEMU_PACKED sev_id_block { + uint8_t ld[48]; + uint8_t family_id[16]; + uint8_t image_id[16]; + uint32_t version; + uint32_t guest_svn; + uint64_t policy; +}; + +struct QEMU_PACKED sev_id_authentication { + uint32_t id_key_alg; + uint32_t auth_key_algo; + uint8_t reserved[56]; + uint8_t id_block_sig[512]; + uint8_t id_key[1028]; + uint8_t reserved2[60]; + uint8_t id_key_sig[512]; + uint8_t author_key[1028]; + uint8_t reserved3[892]; +}; + +#define IGVM_SEV_ID_BLOCK_VERSION 1 + /* * QIgvm contains the information required during processing * of a single IGVM file. @@ -38,6 +72,17 @@ typedef struct QIgvm { uint32_t compatibility_mask; unsigned current_header_index; QTAILQ_HEAD(, QIgvmParameterData) parameter_data; + IgvmPlatformType platform_type; + + /* + * SEV-SNP platforms can contain an ID block and authentication + * that should be verified by the guest. + */ + struct sev_id_block *id_block; + struct sev_id_authentication *id_auth; + + /* Define the guest policy for SEV guests */ + uint64_t sev_policy; =20 /* These variables keep track of contiguous page regions */ IGVM_VHS_PAGE_DATA region_prev_page_data; @@ -67,6 +112,11 @@ static int qigvm_directive_environment_info(QIgvm *ctx, static int qigvm_directive_required_memory(QIgvm *ctx, const uint8_t *header_data, Error **errp); +static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_= data, + Error **errp); +static int qigvm_initialization_guest_policy(QIgvm *ctx, + const uint8_t *header_data, + Error **errp); =20 struct QIGVMHandler { uint32_t type; @@ -91,6 +141,10 @@ static struct QIGVMHandler handlers[] =3D { qigvm_directive_environment_info }, { IGVM_VHT_REQUIRED_MEMORY, IGVM_HEADER_SECTION_DIRECTIVE, qigvm_directive_required_memory }, + { IGVM_VHT_SNP_ID_BLOCK, IGVM_HEADER_SECTION_DIRECTIVE, + qigvm_directive_snp_id_block }, + { IGVM_VHT_GUEST_POLICY, IGVM_HEADER_SECTION_INITIALIZATION, + qigvm_initialization_guest_policy }, }; =20 static int qigvm_handler(QIgvm *ctx, uint32_t type, Error **errp) @@ -632,6 +686,74 @@ static int qigvm_directive_required_memory(QIgvm *ctx, return 0; } =20 +static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_= data, + Error **errp) +{ + const IGVM_VHS_SNP_ID_BLOCK *igvm_id =3D + (const IGVM_VHS_SNP_ID_BLOCK *)header_data; + + if (!(igvm_id->compatibility_mask & ctx->compatibility_mask)) { + return 0; + } + + if (ctx->id_block) { + error_setg(errp, "IGVM: Multiple ID blocks encountered " + "in IGVM file."); + return -1; + } + ctx->id_block =3D g_new0(struct sev_id_block, 1); + ctx->id_auth =3D g_new0(struct sev_id_authentication, 1); + + memcpy(ctx->id_block->family_id, igvm_id->family_id, + sizeof(ctx->id_block->family_id)); + memcpy(ctx->id_block->image_id, igvm_id->image_id, + sizeof(ctx->id_block->image_id)); + ctx->id_block->guest_svn =3D igvm_id->guest_svn; + ctx->id_block->version =3D IGVM_SEV_ID_BLOCK_VERSION; + memcpy(ctx->id_block->ld, igvm_id->ld, sizeof(ctx->id_block->ld)); + + ctx->id_auth->id_key_alg =3D igvm_id->id_key_algorithm; + assert(sizeof(igvm_id->id_key_signature) <=3D + sizeof(ctx->id_auth->id_block_sig)); + memcpy(ctx->id_auth->id_block_sig, &igvm_id->id_key_signature, + sizeof(igvm_id->id_key_signature)); + + ctx->id_auth->auth_key_algo =3D igvm_id->author_key_algorithm; + assert(sizeof(igvm_id->author_key_signature) <=3D + sizeof(ctx->id_auth->id_key_sig)); + memcpy(ctx->id_auth->id_key_sig, &igvm_id->author_key_signature, + sizeof(igvm_id->author_key_signature)); + + /* + * SEV and IGVM public key structure population are slightly different. + * See SEV Secure Nested Paging Firmware ABI Specification, Chapter 10. + */ + *((uint32_t *)ctx->id_auth->id_key) =3D igvm_id->id_public_key.curve; + memcpy(&ctx->id_auth->id_key[4], &igvm_id->id_public_key.qx, 72); + memcpy(&ctx->id_auth->id_key[76], &igvm_id->id_public_key.qy, 72); + + *((uint32_t *)ctx->id_auth->author_key) =3D + igvm_id->author_public_key.curve; + memcpy(&ctx->id_auth->author_key[4], &igvm_id->author_public_key.qx, + 72); + memcpy(&ctx->id_auth->author_key[76], &igvm_id->author_public_key.qy, + 72); + + return 0; +} + +static int qigvm_initialization_guest_policy(QIgvm *ctx, + const uint8_t *header_data, Error *= *errp) +{ + const IGVM_VHS_GUEST_POLICY *guest =3D + (const IGVM_VHS_GUEST_POLICY *)header_data; + + if (guest->compatibility_mask & ctx->compatibility_mask) { + ctx->sev_policy =3D guest->policy; + } + return 0; +} + static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp) { int32_t header_count; @@ -701,12 +823,16 @@ static int qigvm_supported_platform_compat_mask(QIgvm= *ctx, Error **errp) /* Choose the strongest supported isolation technology */ if (compatibility_mask_sev_snp !=3D 0) { ctx->compatibility_mask =3D compatibility_mask_sev_snp; + ctx->platform_type =3D IGVM_PLATFORM_TYPE_SEV_SNP; } else if (compatibility_mask_sev_es !=3D 0) { ctx->compatibility_mask =3D compatibility_mask_sev_es; + ctx->platform_type =3D IGVM_PLATFORM_TYPE_SEV_ES; } else if (compatibility_mask_sev !=3D 0) { ctx->compatibility_mask =3D compatibility_mask_sev; + ctx->platform_type =3D IGVM_PLATFORM_TYPE_SEV; } else if (compatibility_mask !=3D 0) { ctx->compatibility_mask =3D compatibility_mask; + ctx->platform_type =3D IGVM_PLATFORM_TYPE_NATIVE; } else { error_setg( errp, @@ -716,6 +842,23 @@ static int qigvm_supported_platform_compat_mask(QIgvm = *ctx, Error **errp) return 0; } =20 +static int qigvm_handle_policy(QIgvm *ctx, Error **errp) +{ + if (ctx->platform_type =3D=3D IGVM_PLATFORM_TYPE_SEV_SNP) { + int id_block_len =3D 0; + int id_auth_len =3D 0; + if (ctx->id_block) { + ctx->id_block->policy =3D ctx->sev_policy; + id_block_len =3D sizeof(struct sev_id_block); + id_auth_len =3D sizeof(struct sev_id_authentication); + } + return ctx->cgsc->set_guest_policy(GUEST_POLICY_SEV, ctx->sev_poli= cy, + ctx->id_block, id_block_len, + ctx->id_auth, id_auth_len, errp); + } + return 0; +} + static IgvmHandle qigvm_file_init(char *filename, Error **errp) { IgvmHandle igvm; @@ -814,12 +957,18 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGues= tSupport *cgs, */ retval =3D qigvm_process_mem_page(&ctx, NULL, errp); =20 + if (retval =3D=3D 0) { + retval =3D qigvm_handle_policy(&ctx, errp); + } + cleanup_parameters: QTAILQ_FOREACH(parameter, &ctx.parameter_data, next) { g_free(parameter->data); parameter->data =3D NULL; } + g_free(ctx.id_block); + g_free(ctx.id_auth); =20 cleanup: igvm_free(ctx.file); --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492984; cv=none; d=zohomail.com; s=zohoarc; b=KJ45sQ8HLUK1Vyn6flO6IYe/Y92vfz30judvlI7YcSRVWl7WUlSJel9tGhYi7D8AsUb9t+C2Wu107wd2q2kc7vEwSn3A8bxyCLtFOPkeNlzKKUITPEYQFA4C0P1VJWNkpyEYCkHIW1NT8U+uc3UK3XjJRoU1bZD3Byxzd4g4drA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492984; 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=uS8ovijzu/++v9gkFCTWnhU+isxUyJNb+e5pEgTtM48=; b=Li6EcH5V+Xc3mZsvX/H7ReNQIsak4E6hCP1ifAvAjTV/P1pY1wIEXmrTZLju+X/i6UjB+fvqFv0V7g80XzgMhgdxqsr22OWeB1vE7dLV3a1K3x1Gg0ZjaQI+9/bYZMuOD0izfDIY1nAI7BLZeatpJCIcXjK2OPxSYC4b1rcwqHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492984692818.418395925929; Mon, 14 Jul 2025 04:36:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLW-00067a-Fp; Mon, 14 Jul 2025 07:27:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH07-0001FJ-1t for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH04-0001vK-RY for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:38 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-aJmgu4DTN3iPK-Az2UqXaA-1; Mon, 14 Jul 2025 07:05:34 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451ac1b43c4so22964835e9.0 for ; Mon, 14 Jul 2025 04:05:34 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4560f22cd29sm58737245e9.34.2025.07.14.04.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491135; 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=uS8ovijzu/++v9gkFCTWnhU+isxUyJNb+e5pEgTtM48=; b=Kcs6BTtaroutoIZsuQKnJp8LskoX6MUy3mAG3aUqvB3GC66hwE9kp9mfX/U1tTx3eHZWLj cfCesF80TUEPkJ3J874eBm0fZ/rwmsm0cqCUNPopQBEXWCTsrc6QTCToGLfUNR8MCW3c1E +/QlerzOXepDEhGWkrmpVa1pY/kcSzI= X-MC-Unique: aJmgu4DTN3iPK-Az2UqXaA-1 X-Mimecast-MFC-AGG-ID: aJmgu4DTN3iPK-Az2UqXaA_1752491133 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491132; x=1753095932; 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=uS8ovijzu/++v9gkFCTWnhU+isxUyJNb+e5pEgTtM48=; b=MSHJsH/mNSbfNksXPM8c73hc5acIyaoPGk/Cga+kF3A62ft1W7wF1rF1kGvydDZbXH y0Ydqth261nT2kJEDfKT6fWmomzS0GlFSWAis72WhMr8Xnyn3klJWczwPDVbQ+k//Y+/ jpFfmYw+WAcbEJkmGohA7PxvuRKJ+8n/klYd1lNSMa/xGAdNDUVJ0Eg7EuQtiXKsrqhG 436gOAsMmNzeZK27Lv3NVFh9F4yFjxzAWPHbxWuxdET9gZi6wPEbyC/vR+HmHADN7QON xv/KXU3TYn67QUcTEG4Nn5CCLp/r7iSlFEXpwDf6NLYk4fv91WyR40MzMlirYxEMSJs/ 47rA== X-Gm-Message-State: AOJu0Yz8l6fr+GMj2m4NrYhlLWIb4IkxrnzKDL71JkB8RlXa2Eqmn9vm rvsjQy+fV2NVkz4mgKiSfkNdTZZpDjfsz5udi/VdbikhGZFa3T7H1Sf2oZg0uM712Ko1ViodUj+ 5bJOKqYME8X9yaUGRAWe75TCz7bDTyuJZQZV+n9zdhH8IDnnxs9wcvVw0uSwv63GqvY3PYEbAUO jR32Yrd8CQQJO/OrfuEemfG908BU+eb/L5PfcNGCWh X-Gm-Gg: ASbGnctp+zwGLm41sVKCJeUruhjZ/O+LKTKDghbaBH8XuJn14I09ur6SCFvaNN6jRjM ifhFz3/3f0Xd4RoDsDjJLdh9HH+z/hrA14sFxnWr2a28sD2mX/sxFTRr+DHs+1TtT2DDwibdaH8 0PZ3b9GfM4ZSnQ/7v9MFAe1bRUfB00lP2xnc05XL5pgOxlPYgZQ+gXUF8I+sGfS2/r9tyRG+8Xz 7eleesE6Y3UpMAAD0ZjYZbnmL1Ucs1IQ68aiuyVuY2WE7mxvZpcsAWwk5Lg9woK97+yYoeeHD3y BpCSzRBorlbHqIY6Jv+sXfsZwbXc/IZKPwMvyrnaajo= X-Received: by 2002:a05:600c:190b:b0:456:2020:165d with SMTP id 5b1f17b1804b1-45620201844mr15127605e9.31.1752491131889; Mon, 14 Jul 2025 04:05:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUnNoiXUV4oqzj25YhC7f5sPbYBd33GBSnilDaJTKPeddJhQOKPtyyx7uaKG/dwuMK+XL27Q== X-Received: by 2002:a05:600c:190b:b0:456:2020:165d with SMTP id 5b1f17b1804b1-45620201844mr15127285e9.31.1752491131383; Mon, 14 Jul 2025 04:05:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Stefano Garzarella , Gerd Hoffman , Ani Sinha Subject: [PULL 31/77] i386/sev: Add implementation of CGS set_guest_policy() Date: Mon, 14 Jul 2025 13:03:20 +0200 Message-ID: <20250714110406.117772-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492985435116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins The new cgs_set_guest_policy() function is provided to receive the guest policy flags, SNP ID block and SNP ID authentication from guest configuration such as an IGVM file and apply it to the platform prior to launching the guest. The policy is used to populate values for the existing 'policy', 'id_block' and 'id_auth' parameters. When provided, the guest policy is applied and the ID block configuration is used to verify the launch measurement and signatures. The guest is only successfully started if the expected launch measurements match the actual measurements and the signatures are valid. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Stefano Garzarella Acked-by: Gerd Hoffman Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/99e82ddec4ad2970c790db8bea16ea3f57eb0e53.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- target/i386/sev.h | 12 +++++++ target/i386/sev.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/target/i386/sev.h b/target/i386/sev.h index d2eb06db321..9db1a802f6b 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -167,6 +167,18 @@ struct QEMU_PACKED sev_es_save_area { uint8_t fpreg_ymm[256]; }; =20 +struct QEMU_PACKED sev_snp_id_authentication { + uint32_t id_key_alg; + uint32_t auth_key_algo; + uint8_t reserved[56]; + uint8_t id_block_sig[512]; + uint8_t id_key[1028]; + uint8_t reserved2[60]; + uint8_t id_key_sig[512]; + uint8_t author_key[1028]; + uint8_t reserved3[892]; +}; + bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **err= p); =20 int sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp= ); diff --git a/target/i386/sev.c b/target/i386/sev.c index 1296f4feb62..3e5722ba657 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -2518,6 +2518,88 @@ static int cgs_get_mem_map_entry(int index, return 0; } =20 +static int cgs_set_guest_policy(ConfidentialGuestPolicyType policy_type, + uint64_t policy, void *policy_data1, + uint32_t policy_data1_size, void *policy_d= ata2, + uint32_t policy_data2_size, Error **errp) +{ + if (policy_type !=3D GUEST_POLICY_SEV) { + error_setg(errp, "%s: Invalid guest policy type provided for SEV: = %d", + __func__, policy_type); + return -1; + } + /* + * SEV-SNP handles policy differently. The policy flags are defined in + * kvm_start_conf.policy and an ID block and ID auth can be provided. + */ + if (sev_snp_enabled()) { + SevSnpGuestState *sev_snp_guest =3D + SEV_SNP_GUEST(MACHINE(qdev_get_machine())->cgs); + struct kvm_sev_snp_launch_finish *finish =3D + &sev_snp_guest->kvm_finish_conf; + + /* + * The policy consists of flags in 'policy' and optionally an ID b= lock + * and ID auth in policy_data1 and policy_data2 respectively. The = ID + * block and auth are optional so clear any previous ID block and = auth + * and set them if provided, but always set the policy flags. + */ + g_free(sev_snp_guest->id_block); + g_free((guchar *)finish->id_block_uaddr); + g_free(sev_snp_guest->id_auth); + g_free((guchar *)finish->id_auth_uaddr); + sev_snp_guest->id_block =3D NULL; + finish->id_block_uaddr =3D 0; + sev_snp_guest->id_auth =3D NULL; + finish->id_auth_uaddr =3D 0; + + if (policy_data1_size > 0) { + struct sev_snp_id_authentication *id_auth =3D + (struct sev_snp_id_authentication *)policy_data2; + + if (policy_data1_size !=3D KVM_SEV_SNP_ID_BLOCK_SIZE) { + error_setg(errp, "%s: Invalid SEV-SNP ID block: incorrect = size", + __func__); + return -1; + } + if (policy_data2_size !=3D KVM_SEV_SNP_ID_AUTH_SIZE) { + error_setg(errp, + "%s: Invalid SEV-SNP ID auth block: incorrect s= ize", + __func__); + return -1; + } + assert(policy_data1 !=3D NULL); + assert(policy_data2 !=3D NULL); + + finish->id_block_uaddr =3D + (__u64)g_memdup2(policy_data1, KVM_SEV_SNP_ID_BLOCK_SIZE); + finish->id_auth_uaddr =3D + (__u64)g_memdup2(policy_data2, KVM_SEV_SNP_ID_AUTH_SIZE); + + /* + * Check if an author key has been provided and use that to fl= ag + * whether the author key is enabled. The first of the author = key + * must be non-zero to indicate the key type, which will curre= ntly + * always be 2. + */ + sev_snp_guest->kvm_finish_conf.auth_key_en =3D + id_auth->author_key[0] ? 1 : 0; + finish->id_block_en =3D 1; + } + sev_snp_guest->kvm_start_conf.policy =3D policy; + } else { + SevGuestState *sev_guest =3D SEV_GUEST(MACHINE(qdev_get_machine())= ->cgs); + /* Only the policy flags are supported for SEV and SEV-ES */ + if ((policy_data1_size > 0) || (policy_data2_size > 0) || !sev_gue= st) { + error_setg(errp, "%s: An ID block/ID auth block has been provi= ded " + "but SEV-SNP is not enabled", __func__); + return -1; + } + sev_guest->policy =3D policy; + } + return 0; +} + static void sev_common_class_init(ObjectClass *oc, const void *data) { @@ -2556,6 +2638,7 @@ sev_common_instance_init(Object *obj) cgs->check_support =3D cgs_check_support; cgs->set_guest_state =3D cgs_set_guest_state; cgs->get_mem_map_entry =3D cgs_get_mem_map_entry; + cgs->set_guest_policy =3D cgs_set_guest_policy; =20 QTAILQ_INIT(&sev_common->launch_vmsa); } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492525; cv=none; d=zohomail.com; s=zohoarc; b=LUtTpBwgSabYGZCi7Fd/k4Aif2klivQxdB5DgzuqPh68oz86IIENqbOfCd4tV0Yl+rHSIyf5NSTcuCYvi+U691UCy0/DbIOzqXzKSXs03gYoWeQcjTEv14r6UdFBuZXhtAtUWQIhuZzV+uCbZNhr12EKFQoS77SH+Rq+BjxExSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492525; 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=wZMuD6ZbchMZbKYlrDnV3xYP+ib1rv/vIs10rW+CJTk=; b=m7jvrNYh2BbJYlRBgXbKHxnHlrwtwN5+JVFB0jO0fcFXNI6+zDCARUn28myoLmx9EutLYShzJH3FR+Te3tqN1bGGt6TdzxcYXIM17snBgGlsut3137yIhqsD8Vi6IyEt3Qee32Z40yqgkTM6bgMhhXhcPWumn3dC2o7pT16//kA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492525428973.1408481344532; Mon, 14 Jul 2025 04:28:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLi-0006hb-5C; Mon, 14 Jul 2025 07:27:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0A-0001GI-QH for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH07-0001vv-2z for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:41 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-dUG1amopMbKUp08sRBCpgw-1; Mon, 14 Jul 2025 07:05:37 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-45600d19a2aso15968095e9.1 for ; Mon, 14 Jul 2025 04:05:37 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4560f844c2dsm57345885e9.0.2025.07.14.04.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491138; 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=wZMuD6ZbchMZbKYlrDnV3xYP+ib1rv/vIs10rW+CJTk=; b=P8s2vYZNijc2keCfHlBBjKQii40jNPwklbVkDytEQUEdhxYO6XW+Wv3sOZ/bqoZclh5KJJ xNy10fY5SQ+mM2hPFFg0mDx+0jH6Em3rhMHQEULJOvOidTjSTUsZiWSdsohZpMiTUtu/LC 9WS4eaLQjuSZ9hT2iwlYmGQJJZVGIdE= X-MC-Unique: dUG1amopMbKUp08sRBCpgw-1 X-Mimecast-MFC-AGG-ID: dUG1amopMbKUp08sRBCpgw_1752491136 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491135; x=1753095935; 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=wZMuD6ZbchMZbKYlrDnV3xYP+ib1rv/vIs10rW+CJTk=; b=Gztg3YQlkHBGXOBFksp7ZNv8FRcMv2U8FIIG3EMDQfC5tdpzFwtL5ZwrhIuFg6RD7D nRMQN5F5lb9TaC+4da6GE6TCcGuRnAr06k7xgBtlA3RFUncvdfEzaoO4uFw4k53n0Io8 jKfeL1CMiZGrz59q/8e4j9yyKXtZhD5V4frZrNVxMjA9GBjLehBUMhn5WVkkQ1mUQ3zF k1atGtEaid7aqxJ/vf582YEQe42RkKJDHyQBS2gddHOgS0syQ2N2tILidEl/ovM1XHLZ 53gmf4LfI3VyKiQ4IC50KgPBsK5RI7r8AH0G/mIeyk7mNSq/lg70n6wkhuK/g4nX8q3C RVyQ== X-Gm-Message-State: AOJu0YwJOt/05ehtSrvy7+9SJLr1rPB+DeLQzNz+bGXgbDjR991wPd8+ lX3qfQd1IbEtqZetMOczkvNeH2j08a6xo11AfTbAHEwKRAee2L95vdJ1tuMXnPRPuXuSwtNcVJC EAzAYzguEQNV8sB/w1HFo88K0SpBAY2zK3Hi9JsnyE3WUhOh5JcZE0Xx6OpmmA+rtPnd1AyUnVK GH8J03lRbQs92iVEjEGOW3w4mx8vf5DKwbZVooPs1s X-Gm-Gg: ASbGncsHxY+R6sMn7zyukrwLaud3boG+qOWuzeHCw+6FUXODrPN8tq2SJyHtmyJZmYa pxHMeBJWGiLmObsQgcOTKqkfEBKtYCUxf6yTKjMChPKCl4PUHtIk1rcoLU3ynqP/lw2eCZqPt9T AgYoTwRhKUiaYMi+/IYJvk7inWHE/+0mSNn/7EqcWe8sE1XCXTouD54i+sld6PP8NbFzfaN3jSI Vro0wpL3DTsBsP/P6PIBFURH5KNUp7eHAYSSl/SP+bEpIgcjrwIDCIwvNEhHZAKX2vHwYENdGFE 17DQS9HfxpZfnn/TKBpiIqbXOTzWTDq6JUssYOrRRMg= X-Received: by 2002:a05:600c:a316:b0:442:f97b:87e with SMTP id 5b1f17b1804b1-4550ef7b064mr84821335e9.6.1752491134986; Mon, 14 Jul 2025 04:05:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbuRw3NXbI1Lrpv2yqFFnXG1wLw1fZ9YemZaOj62kw26eBTq/ZRhJvVGIrzSOquwb4LiXyjw== X-Received: by 2002:a05:600c:a316:b0:442:f97b:87e with SMTP id 5b1f17b1804b1-4550ef7b064mr84821015e9.6.1752491134392; Mon, 14 Jul 2025 04:05:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Roy Hopkins , "Michael S. Tsirkin" , Stefano Garzarella , Gerd Hoffman , Liam Merwick , Ani Sinha Subject: [PULL 32/77] sev: Provide sev_features flags from IGVM VMSA to KVM_SEV_INIT2 Date: Mon, 14 Jul 2025 13:03:21 +0200 Message-ID: <20250714110406.117772-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492528051116600 Content-Type: text/plain; charset="utf-8" From: Roy Hopkins IGVM files can contain an initial VMSA that should be applied to each vcpu as part of the initial guest state. The sev_features flags are provided as part of the VMSA structure. However, KVM only allows sev_features to be set during initialization and not as the guest is being prepared for launch. This patch queries KVM for the supported set of sev_features flags and processes the VP context entries in the IGVM file during kvm_init to determine any sev_features flags set in the IGVM file. These are then provided in the call to KVM_SEV_INIT2 to ensure the guest state matches that specified in the IGVM file. The igvm process() function is modified to allow a partial processing of the file during initialization, with only the IGVM_VHT_VP_CONTEXT fields being processed. This means the function is called twice, firstly to extract the sev_features then secondly to actually configure the guest. Signed-off-by: Roy Hopkins Acked-by: Michael S. Tsirkin Acked-by: Stefano Garzarella Acked-by: Gerd Hoffman Tested-by: Stefano Garzarella Reviewed-by: Liam Merwick Reviewed-by: Ani Sinha Link: https://lore.kernel.org/r/b2f986aae04e1da2aee530c9be22a54c0c59a560.17= 51554099.git.roy.hopkins@randomman.co.uk Signed-off-by: Paolo Bonzini --- backends/igvm.h | 2 +- include/system/igvm-cfg.h | 5 +- backends/igvm.c | 17 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- target/i386/sev.c | 161 +++++++++++++++++++++++++++++++++----- 6 files changed, 163 insertions(+), 26 deletions(-) diff --git a/backends/igvm.h b/backends/igvm.h index db02ea91651..a4abab043a1 100644 --- a/backends/igvm.h +++ b/backends/igvm.h @@ -17,6 +17,6 @@ #include "qapi/error.h" =20 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs, - Error **errp); + bool onlyVpContext, Error **errp); =20 #endif diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h index 321b3196f09..944f23a814d 100644 --- a/include/system/igvm-cfg.h +++ b/include/system/igvm-cfg.h @@ -31,11 +31,14 @@ typedef struct IgvmCfgClass { /* * If an IGVM filename has been specified then process the IGVM file. * Performs a no-op if no filename has been specified. + * If onlyVpContext is true then only the IGVM_VHT_VP_CONTEXT entries + * in the IGVM file will be processed, allowing information about the + * CPU state to be determined before processing the entire file. * * Returns 0 for ok and -1 on error. */ int (*process)(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, - Error **errp); + bool onlyVpContext, Error **errp); =20 } IgvmCfgClass; =20 diff --git a/backends/igvm.c b/backends/igvm.c index b568f06c769..9ad41582ee5 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -880,7 +880,7 @@ static IgvmHandle qigvm_file_init(char *filename, Error= **errp) } =20 int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, - Error **errp) + bool onlyVpContext, Error **errp) { int32_t header_count; QIgvmParameterData *parameter; @@ -924,11 +924,22 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGues= tSupport *cgs, ctx.current_header_index++) { IgvmVariableHeaderType type =3D igvm_get_header_type( ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_in= dex); - if (qigvm_handler(&ctx, type, errp) < 0) { - goto cleanup_parameters; + if (!onlyVpContext || (type =3D=3D IGVM_VHT_VP_CONTEXT)) { + if (qigvm_handler(&ctx, type, errp) < 0) { + goto cleanup_parameters; + } } } =20 + /* + * If only processing the VP context then we don't need to process + * any more of the file. + */ + if (onlyVpContext) { + retval =3D 0; + goto cleanup_parameters; + } + header_count =3D igvm_header_count(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION); if (header_count < 0) { diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 3184ea1b378..a3285fbc645 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -371,7 +371,7 @@ static void pc_init1(MachineState *machine, const char = *pci_type) /* Apply guest state from IGVM if supplied */ if (x86ms->igvm) { if (IGVM_CFG_GET_CLASS(x86ms->igvm) - ->process(x86ms->igvm, machine->cgs, &error_fatal) < 0) { + ->process(x86ms->igvm, machine->cgs, false, &error_fatal) = < 0) { g_assert_not_reached(); } } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 6990e1c6695..cf871cfdad8 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -330,7 +330,7 @@ static void pc_q35_init(MachineState *machine) /* Apply guest state from IGVM if supplied */ if (x86ms->igvm) { if (IGVM_CFG_GET_CLASS(x86ms->igvm) - ->process(x86ms->igvm, machine->cgs, &error_fatal) < 0) { + ->process(x86ms->igvm, machine->cgs, false, &error_fatal) = < 0) { g_assert_not_reached(); } } diff --git a/target/i386/sev.c b/target/i386/sev.c index 3e5722ba657..1057b8ab2c6 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -118,6 +118,8 @@ struct SevCommonState { uint32_t cbitpos; uint32_t reduced_phys_bits; bool kernel_hashes; + uint64_t sev_features; + uint64_t supported_sev_features; =20 /* runtime state */ uint8_t api_major; @@ -485,7 +487,40 @@ static void sev_apply_cpu_context(CPUState *cpu) } } =20 -static int check_vmsa_supported(hwaddr gpa, const struct sev_es_save_area = *vmsa, +static int check_sev_features(SevCommonState *sev_common, uint64_t sev_fea= tures, + Error **errp) +{ + /* + * Ensure SEV_FEATURES is configured for correct SEV hardware and that + * the requested features are supported. If SEV-SNP is enabled then + * that feature must be enabled, otherwise it must be cleared. + */ + if (sev_snp_enabled() && !(sev_features & SVM_SEV_FEAT_SNP_ACTIVE)) { + error_setg( + errp, + "%s: SEV_SNP is enabled but is not enabled in VMSA sev_feature= s", + __func__); + return -1; + } else if (!sev_snp_enabled() && + (sev_features & SVM_SEV_FEAT_SNP_ACTIVE)) { + error_setg( + errp, + "%s: SEV_SNP is not enabled but is enabled in VMSA sev_feature= s", + __func__); + return -1; + } + if (sev_features & ~sev_common->supported_sev_features) { + error_setg(errp, + "%s: VMSA contains unsupported sev_features: %lX, " + "supported features: %lX", + __func__, sev_features, sev_common->supported_sev_featu= res); + return -1; + } + return 0; +} + +static int check_vmsa_supported(SevCommonState *sev_common, hwaddr gpa, + const struct sev_es_save_area *vmsa, Error **errp) { struct sev_es_save_area vmsa_check; @@ -551,24 +586,10 @@ static int check_vmsa_supported(hwaddr gpa, const str= uct sev_es_save_area *vmsa, vmsa_check.x87_fcw =3D 0; vmsa_check.mxcsr =3D 0; =20 - if (sev_snp_enabled()) { - if (vmsa_check.sev_features !=3D SVM_SEV_FEAT_SNP_ACTIVE) { - error_setg(errp, - "%s: sev_features in the VMSA contains an unsupport= ed " - "value. For SEV-SNP, sev_features must be set to %x= .", - __func__, SVM_SEV_FEAT_SNP_ACTIVE); - return -1; - } - vmsa_check.sev_features =3D 0; - } else { - if (vmsa_check.sev_features !=3D 0) { - error_setg(errp, - "%s: sev_features in the VMSA contains an unsupport= ed " - "value. For SEV-ES and SEV, sev_features must be " - "set to 0.", __func__); - return -1; - } + if (check_sev_features(sev_common, vmsa_check.sev_features, errp) < 0)= { + return -1; } + vmsa_check.sev_features =3D 0; =20 if (!buffer_is_zero(&vmsa_check, sizeof(vmsa_check))) { error_setg(errp, @@ -1722,6 +1743,39 @@ static int sev_snp_kvm_type(X86ConfidentialGuest *cg) return KVM_X86_SNP_VM; } =20 +static int sev_init_supported_features(ConfidentialGuestSupport *cgs, + SevCommonState *sev_common, Error *= *errp) +{ + X86ConfidentialGuestClass *x86_klass =3D + X86_CONFIDENTIAL_GUEST_GET_CLASS(cgs); + /* + * Older kernels do not support query or setting of sev_features. In t= his + * case the set of supported features must be zero to match the settin= gs + * in the kernel. + */ + if (x86_klass->kvm_type(X86_CONFIDENTIAL_GUEST(sev_common)) =3D=3D + KVM_X86_DEFAULT_VM) { + sev_common->supported_sev_features =3D 0; + return 0; + } + + /* Query KVM for the supported set of sev_features */ + struct kvm_device_attr attr =3D { + .group =3D KVM_X86_GRP_SEV, + .attr =3D KVM_X86_SEV_VMSA_FEATURES, + .addr =3D (unsigned long)&sev_common->supported_sev_features, + }; + if (kvm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr) < 0) { + error_setg(errp, "%s: failed to query supported sev_features", + __func__); + return -1; + } + if (sev_snp_enabled()) { + sev_common->supported_sev_features |=3D SVM_SEV_FEAT_SNP_ACTIVE; + } + return 0; +} + static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { char *devname; @@ -1802,6 +1856,10 @@ static int sev_common_kvm_init(ConfidentialGuestSupp= ort *cgs, Error **errp) } } =20 + if (sev_init_supported_features(cgs, sev_common, errp) < 0) { + return -1; + } + trace_kvm_sev_init(); switch (x86_klass->kvm_type(X86_CONFIDENTIAL_GUEST(sev_common))) { case KVM_X86_DEFAULT_VM: @@ -1813,6 +1871,40 @@ static int sev_common_kvm_init(ConfidentialGuestSupp= ort *cgs, Error **errp) case KVM_X86_SEV_ES_VM: case KVM_X86_SNP_VM: { struct kvm_sev_init args =3D { 0 }; + MachineState *machine =3D MACHINE(qdev_get_machine()); + X86MachineState *x86machine =3D X86_MACHINE(qdev_get_machine()); + + /* + * If configuration is provided via an IGVM file then the IGVM file + * might contain configuration of the initial vcpu context. For SEV + * the vcpu context includes the sev_features which should be appl= ied + * to the vcpu. + * + * KVM does not synchronize sev_features from CPU state. Instead it + * requires sev_features to be provided as part of this initializa= tion + * call which is subsequently automatically applied to the VMSA of + * each vcpu. + * + * The IGVM file is normally processed after initialization. There= fore + * we need to pre-process it here to extract sev_features in order= to + * provide it to KVM_SEV_INIT2. Each cgs_* function that is called= by + * the IGVM processor detects this pre-process by observing the st= ate + * as SEV_STATE_UNINIT. + */ + if (x86machine->igvm) { + if (IGVM_CFG_GET_CLASS(x86machine->igvm) + ->process(x86machine->igvm, machine->cgs, true, errp) = =3D=3D + -1) { + return -1; + } + /* + * KVM maintains a bitmask of allowed sev_features. This does = not + * include SVM_SEV_FEAT_SNP_ACTIVE which is set accordingly by= KVM + * itself. Therefore we need to clear this flag. + */ + args.vmsa_features =3D sev_common->sev_features & + ~SVM_SEV_FEAT_SNP_ACTIVE; + } =20 ret =3D sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_er= ror); break; @@ -2416,6 +2508,24 @@ static int cgs_set_guest_state(hwaddr gpa, uint8_t *= ptr, uint64_t len, SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); SevCommonStateClass *klass =3D SEV_COMMON_GET_CLASS(sev_common); =20 + if (sev_common->state =3D=3D SEV_STATE_UNINIT) { + /* Pre-processing of IGVM file called from sev_common_kvm_init() */ + if ((cpu_index =3D=3D 0) && (memory_type =3D=3D CGS_PAGE_TYPE_VMSA= )) { + const struct sev_es_save_area *sa =3D + (const struct sev_es_save_area *)ptr; + if (len < sizeof(*sa)) { + error_setg(errp, "%s: invalid VMSA length encountered", + __func__); + return -1; + } + if (check_sev_features(sev_common, sa->sev_features, errp) < 0= ) { + return -1; + } + sev_common->sev_features =3D sa->sev_features; + } + return 0; + } + if (!sev_enabled()) { error_setg(errp, "%s: attempt to configure guest memory, but SEV " "is not enabled", __func__); @@ -2435,7 +2545,8 @@ static int cgs_set_guest_state(hwaddr gpa, uint8_t *p= tr, uint64_t len, __func__); return -1; } - if (check_vmsa_supported(gpa, (const struct sev_es_save_area *)ptr, + if (check_vmsa_supported(sev_common, gpa, + (const struct sev_es_save_area *)ptr, errp) < 0) { return -1; } @@ -2492,6 +2603,12 @@ static int cgs_get_mem_map_entry(int index, struct e820_entry *table; int num_entries; =20 + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + if (sev_common->state =3D=3D SEV_STATE_UNINIT) { + /* Pre-processing of IGVM file called from sev_common_kvm_init() */ + return 1; + } + num_entries =3D e820_get_table(&table); if ((index < 0) || (index >=3D num_entries)) { return 1; @@ -2523,6 +2640,12 @@ static int cgs_set_guest_policy(ConfidentialGuestPol= icyType policy_type, uint32_t policy_data1_size, void *policy_d= ata2, uint32_t policy_data2_size, Error **errp) { + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + if (sev_common->state =3D=3D SEV_STATE_UNINIT) { + /* Pre-processing of IGVM file called from sev_common_kvm_init() */ + return 0; + } + if (policy_type !=3D GUEST_POLICY_SEV) { error_setg(errp, "%s: Invalid guest policy type provided for SEV: = %d", __func__, policy_type); --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491824; cv=none; d=zohomail.com; s=zohoarc; b=h77e/nwonambss05iVOkz8RMWiVP71Cx2XqzEbQK/slPOTgL3+MFz5TiohdNQxrtbWvGhSdeltQqlSCxpN9gA85tV8QhmbIzhidgD6/N6B3WjDSxlY/fUZmisC+SBwTWBAqL2EPwMp3yDoUh7Q83lZ31jPsVgkCxBgJRXQd1C+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491824; 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=9wVutdUCpdUXWQWTx6uVxLNXyVult81NQL9SKeIWPII=; b=NSVWq6/g6Yxyggwm5bhtFoHP3Mdzps6oC5VIX5uOMXWc5NC2bhKDwl1TIzLwhOjeWhRnKTslKkl1x3zDBXKeG4hnQvwl17OpkUFhxYbLZ4I42w/glE2eASFxmRjOCCQqFmN2W87mD/s9lZoCc78dOb2A39zvA/6cA8QaAoFEqK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491824875976.9907683796091; Mon, 14 Jul 2025 04:17:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHAQ-0003Zb-Aw; Mon, 14 Jul 2025 07:16:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0C-0001HD-Ru for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0A-0001wl-QK for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:44 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-FSAkJapGPpmTfs7SofwSAA-1; Mon, 14 Jul 2025 07:05:38 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a54a8a0122so2145723f8f.2 for ; Mon, 14 Jul 2025 04:05:38 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1792sm12341878f8f.13.2025.07.14.04.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491142; 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=9wVutdUCpdUXWQWTx6uVxLNXyVult81NQL9SKeIWPII=; b=G79SnrNL/MUbYyqZ0P+bIR7J9uM6lfCn3Of4v6V4UXBPlB4iQZitdOP8o0X0vjt4waeliA EF4h2FwnqTx8MEE8c7Sog0CFRJ4rLQjTH7UnxiJH2IirZQ0eYY+y1+SP7/uUHpE26tq38Q JLkwt8fQbjaLUBTq0bTblslQsUB+x3Q= X-MC-Unique: FSAkJapGPpmTfs7SofwSAA-1 X-Mimecast-MFC-AGG-ID: FSAkJapGPpmTfs7SofwSAA_1752491137 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491136; x=1753095936; 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=9wVutdUCpdUXWQWTx6uVxLNXyVult81NQL9SKeIWPII=; b=YY54xBfkScAmp0zyZ8jXMfpJephBuPKQZQ1V6vufYKIYu3jgOHlwKTeK4+KG48K6X4 Crz06KA7S6ZscjcALL47cH5nEAicMtkMucAPkg0M/l4tY2YGze2K62cgPM1Jd+APW132 l4gggLbtrNEtcIglDkvD8LE8ZT8JlmDwDUNFtMTM1mmN3S8+HJ0lweb6CVxU3IOhTCnc vONkKYKFdIg/VN6v7MAeEA/RJBrr5d8w4DG5OpDoiL2igq5xBCuwiYyiDfo3TIqHIoin 8nZHi7mYubzSy4xoYz/c0oyn0SN+gS/W412JlSPr1GVk0Qfug74xqjPgacSc1R9o8E4R 8pEA== X-Gm-Message-State: AOJu0Yw6iWpr6wagxSsi+ab5ROdbD4XcqaXpDMT0C7l14X0RC/vdQms4 sMus7E9JpiH4WXKoXgvvOXGW5NTIvKOM78H46O2X3odVct3azHS6435k/vG44LiSr4Q7Pr98PfF TN3o3aQarY3Ga02QFy7y6msiqJA2ecvuJ/FNka5IsQpNAu5agfhVrWM3RAY0tMIXxxKcTPSUNJF fkbweYvcXVmnKxJOb3ohuS+GTLTrZ/4oqaLz4CWnpq X-Gm-Gg: ASbGncvWjXyXlj1krG7z056oSpnhWBZak5oxoXLrKZRgaHusXxpVtu01ShZBJ6obUPr iq2L4FL64P/21GReK+ycI0H7lOrlvl9JZC4xMrwToPrPu8bD0qdaIa5TOZCC9FpwvDDf6n1nnNI zT/eEhJlsXM51mKa0xawAaUy7H2769DrHpq83FhQCHOMsXp3+J3flGjHIhrAtBjm9mXON2A6eT6 3DIF4dV9pbsWhq7RnqLHN31Bnfixl4A8HRhLovLc3pbd8FwLiDPZQZG16uriFpnKg0DQTQkol2N fdpJJQsyjzrIXPXCdc9Tv0TyKpE+7UyiEdU6TzyQ9TU= X-Received: by 2002:a05:6000:250f:b0:3a4:dc32:6cbc with SMTP id ffacd0b85a97d-3b5f1880f48mr11152962f8f.20.1752491136457; Mon, 14 Jul 2025 04:05:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJCI1sBoQ6qBcC7ImXJnqnI2CFv8ld4kNnXzaZ0ADKgUvv1UVyCTMP9q+j4Ij9guCpUDIBtQ== X-Received: by 2002:a05:6000:250f:b0:3a4:dc32:6cbc with SMTP id ffacd0b85a97d-3b5f1880f48mr11152929f8f.20.1752491135931; Mon, 14 Jul 2025 04:05:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 33/77] i386/cpu: Move the implementation of is_host_cpu_intel() host-cpu.c Date: Mon, 14 Jul 2025 13:03:22 +0200 Message-ID: <20250714110406.117772-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491826328116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li It's more proper to put is_host_cpu_intel() in host-cpu.c instead of vmsr_energy.c. Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250701075738.3451873-3-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/host-cpu.h | 1 + target/i386/kvm/vmsr_energy.h | 1 - target/i386/host-cpu.c | 9 +++++++++ target/i386/kvm/vmsr_energy.c | 9 --------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/target/i386/host-cpu.h b/target/i386/host-cpu.h index b97ec01c9be..10df4b3a3a7 100644 --- a/target/i386/host-cpu.h +++ b/target/i386/host-cpu.h @@ -17,4 +17,5 @@ bool host_cpu_realizefn(CPUState *cs, Error **errp); =20 void host_cpu_vendor_fms(char *vendor, int *family, int *model, int *stepp= ing); =20 +bool is_host_cpu_intel(void); #endif /* HOST_CPU_H */ diff --git a/target/i386/kvm/vmsr_energy.h b/target/i386/kvm/vmsr_energy.h index 16cc1f4814f..151bcbd6423 100644 --- a/target/i386/kvm/vmsr_energy.h +++ b/target/i386/kvm/vmsr_energy.h @@ -94,6 +94,5 @@ double vmsr_get_ratio(uint64_t e_delta, unsigned long long delta_ticks, unsigned int maxticks); void vmsr_init_topo_info(X86CPUTopoInfo *topo_info, const MachineState *ms= ); -bool is_host_cpu_intel(void); int is_rapl_enabled(void); #endif /* VMSR_ENERGY_H */ diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index 3399edc1ad0..e9a49e628f8 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -161,6 +161,15 @@ void host_cpu_instance_init(X86CPU *cpu) &error_abort); } =20 +bool is_host_cpu_intel(void) +{ + char vendor[CPUID_VENDOR_SZ + 1]; + + host_cpu_vendor_fms(vendor, NULL, NULL, NULL); + + return g_str_equal(vendor, CPUID_VENDOR_INTEL); +} + static void host_cpu_class_init(ObjectClass *oc, const void *data) { X86CPUClass *xcc =3D X86_CPU_CLASS(oc); diff --git a/target/i386/kvm/vmsr_energy.c b/target/i386/kvm/vmsr_energy.c index d6aad5246b6..58ce3df53a3 100644 --- a/target/i386/kvm/vmsr_energy.c +++ b/target/i386/kvm/vmsr_energy.c @@ -27,15 +27,6 @@ char *vmsr_compute_default_paths(void) return g_build_filename(state, "run", "qemu-vmsr-helper.sock", NULL); } =20 -bool is_host_cpu_intel(void) -{ - char vendor[CPUID_VENDOR_SZ + 1]; - - host_cpu_vendor_fms(vendor, NULL, NULL, NULL); - - return g_str_equal(vendor, CPUID_VENDOR_INTEL); -} - int is_rapl_enabled(void) { const char *path =3D "/sys/class/powercap/intel-rapl/enabled"; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492938; cv=none; d=zohomail.com; s=zohoarc; b=Ijea02SuYs08J6iNTKavwJn+6FgB/P3m9Tomn+/WqqJ6BWb30g/gIEVPChLDxyoLnLLt2oqzygJ6oIeiEFOYaAslLIEyNbnqoBqevEyK60EHb5bd3F3njzeymuBKentBLxgoCviKnXgn4J9ivo6c+zodFFm2TXb88qBxDXBW4Ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492938; h=Content-Type: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=mul+E8ln+qvRVQpsZttbXU0+kmRd+V4PH2/0PTsKNQo=; b=kqODyKDamVb/JdGPyJP4cU71eBCqsiNpNEJO4Oht5lGocv5ZE6Er2OhFpo50P814nK9uQe5mJUi5bWyEWFLCS5yVhZ1sU0DjYLVWv+o9xFr4oAlUH25JTPyD7pRwcHZ5o4XMSs7ij7udv/6BcQvU8pz0eyM00DHjmfJUuSK5jBM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 175249293826414.327524726859338; Mon, 14 Jul 2025 04:35:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLU-0005yP-3X; Mon, 14 Jul 2025 07:27:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0F-0001Kj-A7 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0B-0001wy-Q2 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:46 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-M3FmRST5Pty5xp_fMrguNg-1; Mon, 14 Jul 2025 07:05:41 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a503f28b09so2705428f8f.0 for ; Mon, 14 Jul 2025 04:05:41 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e8b1sm12005359f8f.82.2025.07.14.04.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mul+E8ln+qvRVQpsZttbXU0+kmRd+V4PH2/0PTsKNQo=; b=YewAcKef0uNU5w8S6yc4QM9j5wRNkEKAx2ZVSUHpVRJZvF3+BfrVHmVpKClt8n5r0m9omL 8nAB9GyY20Szkt+cqnUYLPZdalrCmN7H2wToKqdGxWZBKDS/T8Q9vLcW1Sh7SOKHlmda4H bESjsAUfxGcNFpcyhwqqsA6oEBoJhDs= X-MC-Unique: M3FmRST5Pty5xp_fMrguNg-1 X-Mimecast-MFC-AGG-ID: M3FmRST5Pty5xp_fMrguNg_1752491141 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491140; x=1753095940; 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=mul+E8ln+qvRVQpsZttbXU0+kmRd+V4PH2/0PTsKNQo=; b=InO5iOSmUuSiqPagKafmGYXwULYYqeG7uZTcOeqiyifD189yowWE0slX8QJqIAc5mF /ZJJXT8/KNg9iItpYon1vwHWC8EPBsOI/2MDw/mUddOY+Gw1OuP+T2PAjQb7aeqybG5z 57VRO1J76bzv3SbNqyQqo8x2V7xGgPg/ekfyyTNJIigQLiUARXfSGpr8igYQdLuu0nv7 4yjYHx9ZkN3fzdTTDUn4Xf5sAG3qKdWY8sFV/HGF9f/Fh+G4mq9DCHrKMiXAyg1oYo/m 4RqUKdCZqrZ9Se+cEXioeuAwbuAsV8LQ9HHXlNcG0ORU6selgESoG2HBk/TLXdvDKJBj 0Gxg== X-Gm-Message-State: AOJu0YyZmFn2UY9cMw/dp1CwyGbKHXxcFi2byEUvPqwvRQrlJ0iFWDGG n+tV5AzMnodS7f0rQCMfz9x1YnIPwNiBqMpd/1pd/k6NdwwYGIruVILzx9NRZppKPVcJpsf610F T4j5oLdvI9UZnz/aCm+WkERd6L0XyrPdeJFiwj4O7vUwSewpO9++vqH8FrxfUafgnx/3yfgMyEW pBpqd1/FapOELlMPhWH7gp0POHu7tiz1GYkyreXGVE X-Gm-Gg: ASbGncsF44bFgwCuzE7zNuWLsFEiMKQamVCG+i+YBGUCDviPu22O1x/aRLezW19lb14 553FWertcLe1e/McyGQKbxJof05XOkUAWqbmZ2Kx1sS2WvkGSCkwExY+l12X5Iw0tv6HBSNaGgf 2wSbPzWpPWiP+k2GPmeIDJEH1JttVoym/93CD8/iFFrtT07N/a8zEuJXhdkixfCda2MWfl0o00y ohmxAs0pe/JyASOBaESwVgdpmPDlduB9t5XfAG8Rd2WtYhF/gXal/AXvaevuSOdD2jJjz0KDGFL 5SV/seo9WaGWaIeCh+0dm8geh3QlNMVL19MH7dC35ew= X-Received: by 2002:a05:6000:4408:b0:3a5:271e:c684 with SMTP id ffacd0b85a97d-3b5e7f35328mr9939396f8f.24.1752491139577; Mon, 14 Jul 2025 04:05:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRNuDcObfokj8qx8khdsmZUz2nCbzqZmv5zSfYs0sgl3oy46tPS1e8hGKoK9VB1GMFucOdiQ== X-Received: by 2002:a05:6000:4408:b0:3a5:271e:c684 with SMTP id ffacd0b85a97d-3b5e7f35328mr9939370f8f.24.1752491139052; Mon, 14 Jul 2025 04:05:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 34/77] i386/cpu: Use CPUID_MODEL_ID_SZ instead of hardcoded 48 Date: Mon, 14 Jul 2025 13:03:23 +0200 Message-ID: <20250714110406.117772-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492940802116600 From: Xiaoyao Li There is already the MACRO CPUID_MODEL_ID_SZ defined in QEMU. Use it to replace all the hardcoded 48. Opportunistically fix the indentation of CPUID_VENDOR_SZ. Signed-off-by: Xiaoyao Li Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/r/20250630080610.3151956-2-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 3 ++- target/i386/cpu.c | 8 ++++---- target/i386/host-cpu.c | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 9829824ac89..b3bb9888579 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1159,7 +1159,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *c= pu, FeatureWord w); /* PMM enabled */ #define CPUID_C000_0001_EDX_PMM_EN (1U << 13) =20 -#define CPUID_VENDOR_SZ 12 +#define CPUID_VENDOR_SZ 12 +#define CPUID_MODEL_ID_SZ 48 =20 #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */ #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 44178bc523d..70b742fcdeb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6469,11 +6469,11 @@ static char *x86_cpuid_get_model_id(Object *obj, Er= ror **errp) char *value; int i; =20 - value =3D g_malloc(48 + 1); - for (i =3D 0; i < 48; i++) { + value =3D g_malloc(CPUID_MODEL_ID_SZ + 1); + for (i =3D 0; i < CPUID_MODEL_ID_SZ; i++) { value[i] =3D env->cpuid_model[i >> 2] >> (8 * (i & 3)); } - value[48] =3D '\0'; + value[CPUID_MODEL_ID_SZ] =3D '\0'; return value; } =20 @@ -6488,7 +6488,7 @@ static void x86_cpuid_set_model_id(Object *obj, const= char *model_id, model_id =3D ""; } len =3D strlen(model_id); - memset(env->cpuid_model, 0, 48); + memset(env->cpuid_model, 0, CPUID_MODEL_ID_SZ); for (i =3D 0; i < 48; i++) { if (i >=3D len) { c =3D '\0'; diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index e9a49e628f8..b1fb6d68161 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -80,7 +80,6 @@ bool host_cpu_realizefn(CPUState *cs, Error **errp) return true; } =20 -#define CPUID_MODEL_ID_SZ 48 /** * cpu_x86_fill_model_id: * Get CPUID model ID string from host CPU. --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492844; cv=none; d=zohomail.com; s=zohoarc; b=hOnQkBZQcCwBGVnHBfJRb0/tR1pvIingotb8nELYbnxRgX3DFYN5pFLSDbBS7f+BELO+kHAfE7JiP3EvpYggJptEsh5JUlnI+KfJongxg9lDwTt2r8fnraFO/tZ8mVHGFjn64G7RowGmkmso8hRhTXMQ0RMq2f4qelBaER5g+Lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492844; 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=CQzDH1V4w6eVY3mbdjPDXzkRBHvX/RGaS5hAPHtGK8A=; b=fjJoJMx3jgJTOkxI9/P+eDKtYfCOA9ozOX/K4f5XIcM0ZXXaH+j6u9Ofp0ZFsrrCxtvqCN2NQWjGvX3gVHd08wqnhvfF1YgPBcWGvHu78FkIZi7mg3w7S+NPwPM5A3Dg6PaAdO92JU5uu4y0DYSkDxWSNup7zICQRip+K46A3bc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249284428717.981658205767303; Mon, 14 Jul 2025 04:34:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHMh-0007pP-Ak; Mon, 14 Jul 2025 07:29:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0G-0001LB-UO for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0F-0001xH-0e for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:48 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-TncvK3AeNsqFMSrVHtOYGg-1; Mon, 14 Jul 2025 07:05:44 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4561c67daebso2042295e9.1 for ; Mon, 14 Jul 2025 04:05:44 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e285sm11945093f8f.76.2025.07.14.04.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491145; 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=CQzDH1V4w6eVY3mbdjPDXzkRBHvX/RGaS5hAPHtGK8A=; b=dTrOgc5dZqijAE9M4wv1F2+5JoKaoweqk9cejiMuD4gLPT1ZinzvYbduLQhu48pnLFFunH SQnSSc+V7XqDjAXOnfWdqQA2rUXudYw5avbFVh8bm8LWEXdYyxx1xpKFy/XkGeV3GvNlrW HZgVEyLuzZ9mwjGG2Z29NSQ7D1CXFJE= X-MC-Unique: TncvK3AeNsqFMSrVHtOYGg-1 X-Mimecast-MFC-AGG-ID: TncvK3AeNsqFMSrVHtOYGg_1752491143 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491143; x=1753095943; 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=CQzDH1V4w6eVY3mbdjPDXzkRBHvX/RGaS5hAPHtGK8A=; b=MCLCYdY/Bbh0fmLuB76YYceOgIch4C+/ExO3csjbvoykfkgAz+xvPI0hVPVzbznVGT 9+HoslWncZmN0TwIOGYiOfpY9+Jhxm+fM7SCxE/7UOV1+k6Fo+H+K8+4SjpAHXN5Uh8w I4yGuOHtBMBQpqsz6TVSROJE1pTlz3WdGejCyFRcmlT3t7/qJt7e5hB6xpKs/J2qJbaO Ec/12wym+rHZ+GXXtC0bIuHaDpkMvpZ+YfYNra9kC7+UDm2Q2f7WBvPXkIhe2NwwlJW2 MViOfVO0ZE/eiRejrqgmeY/qyKoxD3eK9647hcRTU4bXwNFUrD7Zou8IBEmw0lYIK8eF k2fw== X-Gm-Message-State: AOJu0Yyc2VWcoYVW+KeYlZcsARwcu5KYpx2HZjZjpFCyKsvOhTcM5G4k C6LOuZYM3CDBcA2PAWMdU8r2PfcHaTdAoQPS8rpE+sXj0oLM0lN0f/wNmwDHQ7Nzg/4FhhRIPiL YgYMnzOFvgmGan43XZNFldtBOQSR3luud3AC6UqnGiyWaPa5rJI/UCTSczWxEV+uZb+hAR/E2iy nNiHrF12NSBY6zjQ+spkeu8zUsFRfT7U8oYxyt2rk3 X-Gm-Gg: ASbGnctpxysYMyIlpqVc2eRpoNpI6R0HyH5GoR7Ep2XksiwrFAQeWTsHJZtGLfwk4Pe ExAMj2SjZ5p/8+XRapcCSLV+06xdciTIR0Z8w9CTpOrkiVHYrVzb4/+HUJVs03gq5FLo0zkKZMU grPsUvnqmLRnDHKdcyC7/g8zt3TtNtNV5YcdXtZQP4OgYjVi1Ui8b4AW4kZk48t0GCLgNSy+94C 3tNq+MJvvFCic+oabm9PVuAGeb6O6QrSugVPj+Dx8s9xPOH6MQNSQXd7Shk236CsvIgcJurg5L2 jS9pQs47wnZtdUSNbQrHNOmIR1Wic4s1C6ruGvCr2y8= X-Received: by 2002:a05:600c:5022:b0:456:1281:f8dd with SMTP id 5b1f17b1804b1-4561281fc0dmr46043795e9.12.1752491142634; Mon, 14 Jul 2025 04:05:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/i1joJjKHQdVeA51bGJrmR0fd4lmxgJshWvIulSYTWabOLmt+EDoNoFh6zLwZt4g99z0Chg== X-Received: by 2002:a05:600c:5022:b0:456:1281:f8dd with SMTP id 5b1f17b1804b1-4561281fc0dmr46043405e9.12.1752491142069; Mon, 14 Jul 2025 04:05:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 35/77] i386: Cleanup the usage of CPUID_VENDOR_INTEL_1 Date: Mon, 14 Jul 2025 13:03:24 +0200 Message-ID: <20250714110406.117772-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492851548116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li There are code using "env->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_1" to check if it is Intel vcpu. Cleanup them to just use IS_INTEL_CPU() Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250630080610.3151956-3-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 2 +- target/i386/tcg/decode-new.c.inc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 70b742fcdeb..d3d13b14726 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7761,7 +7761,7 @@ 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 - if (tcg_enabled() && env->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_= 1 && + if (tcg_enabled() && IS_INTEL_CPU(env) && !(env->hflags & HF_LMA_MASK)) { *edx &=3D ~CPUID_EXT2_SYSCALL; } diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 55216e0d249..853b1c8bf95 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -2722,14 +2722,14 @@ static void disas_insn(DisasContext *s, CPUState *c= pu) if (decode.e.check & X86_CHECK_i64) { goto illegal_op; } - if ((decode.e.check & X86_CHECK_i64_amd) && env->cpuid_vendor1= !=3D CPUID_VENDOR_INTEL_1) { + if ((decode.e.check & X86_CHECK_i64_amd) && !IS_INTEL_CPU(env)= ) { goto illegal_op; } } else { if (decode.e.check & X86_CHECK_o64) { goto illegal_op; } - if ((decode.e.check & X86_CHECK_o64_intel) && env->cpuid_vendo= r1 =3D=3D CPUID_VENDOR_INTEL_1) { + if ((decode.e.check & X86_CHECK_o64_intel) && IS_INTEL_CPU(env= )) { goto illegal_op; } } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493088; cv=none; d=zohomail.com; s=zohoarc; b=ApCSw72Z6sEEN2/eZFB53uSO+P8RT5+IKEW+L658pYitfF5Ldkv7sL4zDqFqkKthnWunHhr4Z3n8cpvJ07XdQSc0f69N//aty9JolPFfNOghBlXVBxbfwENXphpNAKefwYnUjT93GLL4AxbMzIaj7tQqPO4H+GIaHLPf6Xt19Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493088; 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=gEj7OUeiZaj5KbOO4n1tkdCJTwkHNuAAciWyaP56m5Q=; b=aNtnwgnBdJbrxbckmzGsp82k8zMpNAc+J72grn3qwIMyAOdhVE+sTmLR6I5nyKZGnNEhCDDsMy92zcDFXuHL46L0pma1TTL4ZeFxoVbJuxBuMGfavomCRI++HDfEWIwTb3D4jOVxBqLSHdsJq071fgFjlp+ToNuJfLdZ1jDOSmo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 1752493088443170.0414216113678; Mon, 14 Jul 2025 04:38:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHK1-00042c-D6; Mon, 14 Jul 2025 07:26:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0I-0001Ls-MD for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0G-0001xZ-MJ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:50 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-_gx5G_ljMKudNl1REvnSSA-1; Mon, 14 Jul 2025 07:05:46 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-455ea9cb0beso21441865e9.0 for ; Mon, 14 Jul 2025 04:05:46 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e2703csm12095979f8f.97.2025.07.14.04.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491147; 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=gEj7OUeiZaj5KbOO4n1tkdCJTwkHNuAAciWyaP56m5Q=; b=RXIFfQyQ+856lJZc26Fr3LxO6SgG+xTiR22T6cmtOBFuMO5VHG9yD884M9qKY+l/ttQmwe aW/MLMnU463GpY6M4JXVyupG3yMxt316TIuMSxn/a05P8vDW78Bihko/KmvhEptOY1aX7Y NNQDEnNZAlbIWqkxZSQY9xjrDP1E4ec= X-MC-Unique: _gx5G_ljMKudNl1REvnSSA-1 X-Mimecast-MFC-AGG-ID: _gx5G_ljMKudNl1REvnSSA_1752491145 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491145; x=1753095945; 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=gEj7OUeiZaj5KbOO4n1tkdCJTwkHNuAAciWyaP56m5Q=; b=LMGm2Lg0v2uYVJlyjePKYYOOiSbvx1Q+c3yAfswLU+hoj5PaiC+Cr+OvQNXIr03LZv NuPpAsUl+g/XBqZ0ajh2DeiRcKnYdig8N/Y0F7e6cKYXmtLCzY477kIiI61m+4ZDYwML fbWIsPSiQ4E4to3rRQQSmfoP0adJqwgk33esCSSfLipJ4uuRwY7aAcIWq0HDg6WlwFKz DmoTRTp/dWZpLnQ9kNlMXKAeF43DKfjgUAWFPpUn0ukxeAxPJW3yUFkRhcOKEKJwWuWS 9uuZ2FhouW+b0/FikHDaU1YofJX3iWt0bM1eL+Lvrf9YUg+0YZ8Q/djAPfNqKbQhqBEr LLDg== X-Gm-Message-State: AOJu0YzOuEvvBmGTp0GjN41mpmz8Bc7L20b86M5PBBUJUeUvZMHBL93F YFmNQ1DUW6DEFhBo4VCnjn/K2DxHaGp0lyxwng8S0qty/vO/lKW4wwNUfRFFp3ZS7aPcIi+vYkp DEaPlW4ZzwbKOW84VJja2RrQn6dPo+iTtWTKi+d+WOja6KeWRzohRbWkKifK5VgIQxA+selKVTU kiqFUcRQ3KjbFbMeXIDDN6SyAQPB46tNtcgOJQ3Qm5 X-Gm-Gg: ASbGncut6nhzlttB00cQ+xvvLqKn+GQLVAqO8bccGEFFoBVwUHCBtff4xhlpEZsYMEb O56/vNLqZh/sHX0Gewh1aCaXOQsA3jG7ogxdz9W5yvInaYF5ioNBJ+JuUE2GR+JXwoK1acDLjrq f85Grnhsx6fJjegsGnxgVc8rZbl4jmnTtZpu1wvcxLnix1TmwWBY5trjAK7zQpGCcAbYXa5M3Cx LATfedTmZNWPyfNQqZ3JPC30mJ33dzzFYGjwS5Npg+n2p14XjgfW90JyJ+iF7KzDYW1f8k1fzhK gBhC6ecrCDirwkcnTFq62TwO97vHblRMIEJM8mYavI8= X-Received: by 2002:a05:6000:2388:b0:3a0:a0d1:1131 with SMTP id ffacd0b85a97d-3b5f187d0e3mr10951920f8f.7.1752491144988; Mon, 14 Jul 2025 04:05:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnsRLedO6U/Niq8M+7MzRou9iceh2Me5J+o26pxc1ZFLlkyyQkF13iZrKDTp67gbIUBCwTmQ== X-Received: by 2002:a05:6000:2388:b0:3a0:a0d1:1131 with SMTP id ffacd0b85a97d-3b5f187d0e3mr10951897f8f.7.1752491144529; Mon, 14 Jul 2025 04:05:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 36/77] i386/kvm-cpu: Fix the indentation inside kvm_cpu_realizefn() Date: Mon, 14 Jul 2025 13:03:25 +0200 Message-ID: <20250714110406.117772-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493090722116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li The indentation of one of the } inside kvm_cpu_realizefn() isn'f correct. fix it. Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250630080610.3151956-4-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm-cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index a99b8764644..89a79536594 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -73,7 +73,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) if (env->features[FEAT_1_ECX] & CPUID_EXT_MONITOR) { host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx, &cpu->mwait.ecx, &cpu->mwait.edx); - } + } } if (cpu->ucode_rev =3D=3D 0) { cpu->ucode_rev =3D --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491878; cv=none; d=zohomail.com; s=zohoarc; b=fNoaCeJ/60OPi8wTWxTjSg5KGwXuveY/MSivjiotE5gm8NKmD9mpZIgJBJJQ+kOnhqNWNz3MHpwhhvVCf8ymHhLtslJvUqjSF/cQ4U/f0L2EPa+0eNVYehnYL22GlLkNB7VRR5GhJ681dlkzXLBa0zA2IxdVtHugr0zcExnHOTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491878; 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=YgTX+tIVcOOQ2a4srBk8j3hWHo73bhiEyasy0Vw94Pc=; b=c3wsyNoaqP2aehZYSnwpIt3HSUkJ8aqC5fBjtV1wTr3uCEKeCSSZZQvTxLBvNZCYH74GfghwxZU0SRkOAB7f9S5aHcu6JvHF8s1i3sSBab4mvm+XMV0e45I8jy6JZqM4Q6op+cH7DiOE8BmcgX4AItUu2ffFKq810p9bKCWrQGc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491878760228.09535020681028; Mon, 14 Jul 2025 04:17:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHBL-0004Br-OU; Mon, 14 Jul 2025 07:17:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0Q-0001Na-JY for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0N-0001y3-JG for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:57 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-sGPERiTyOmqhDieHR96ZIg-1; Mon, 14 Jul 2025 07:05:49 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-453a5d50b81so30307925e9.1 for ; Mon, 14 Jul 2025 04:05:49 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-456030270f8sm73345715e9.22.2025.07.14.04.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491153; 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=YgTX+tIVcOOQ2a4srBk8j3hWHo73bhiEyasy0Vw94Pc=; b=J9PSiIkS3+kJmtzjaCEWBEJaUdRBg5o504aGIMLrrMny2Wp+WekgmmZ7DhTe9DPRimLX36 ZI8J3eb8N23I73OQWsqNHPp+0/G5091JXZPA462H+R1s6hpcvYoEqnxyDhsKGki9J97ksb aPTjykTcjSn5zUdqRhxBqodH0lZoK1c= X-MC-Unique: sGPERiTyOmqhDieHR96ZIg-1 X-Mimecast-MFC-AGG-ID: sGPERiTyOmqhDieHR96ZIg_1752491148 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491148; x=1753095948; 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=YgTX+tIVcOOQ2a4srBk8j3hWHo73bhiEyasy0Vw94Pc=; b=TrGE969CpUV2//3wUnr2EMUqTlNbNE7xjVWeo0HiGYVogSk+fI3iBhGWJAsBUZcXlx alc62K7a0kxLnyT90H1DGM8eu3vqWbakqkMr0kIltBoU+Vv7avA8XpceDUXfXwhSKpVF P7Bsu7i7F/iBg6INLGAwm2f0Ht1Jv2a9w7a1utIqjeXM1IeymglXxP2shpNqNsi3j20u lNhA98mpkWCx3XBL5a++aKHABhi0CQNrZ2aKIXHM/HFrl3gnPKYnnWExOlK2gtxpDbZ5 PaHXynVJvpeSTmZgkvh4qaO3hgFETYcBatmui63xXJONia5rg9BbTNT+XHpziAZWGST/ LVKA== X-Gm-Message-State: AOJu0YwnooPcQdxT5eeh4O1N6cotnt09YYFsBlVrN1gCNPOdb2q02hRX Vw0q70HhqpCzyFWu367paLghNBdADChcGeIGKnSMJwWzcxSQiNxWDNDdpquBCIv2+L+ULAKpW0s yJl261EIWg/2HNaDpIhmxBvkQV08XNa5FT5t5VE1btqjVBy/+GNBDEPBKAceJaHh04opn972FzC HQlEVqAacPUAllvjgAyfZw266srMQxZ7tCGXilr4Dg X-Gm-Gg: ASbGncvDXkAYOGzpPHNx+AoCB9jUFCDP1EuMiG7K+FIZ2eBNBmsEqkENOIKd5/nj8OA vJyC/+OwJkp2BBtWElDaJtf87DuqY83HkB2J8cZMHW8O8OsGmIrYbmH+nSyf4zJJBP8+nqnvOTY XUBHi1ZMA8MyRCRFH6rKhqZ8N0g5pLowHiq8/hxV1C1KRcclFpQ16rtduJ7T3QZSNyWt6NRhVqi Kk64dYbUpsbzheOu9x0hnmprFTpws9gQV1MgzKBd6vdfwWnB7GDQuOCRJkNckgBLXqjvO9cYtoQ 6ZwBViIGQTTzK8XQ2TmwXduHuAMcOsqWskY+iiXse/U= X-Received: by 2002:a05:600c:37c4:b0:456:302:6dc3 with SMTP id 5b1f17b1804b1-456030271bemr65063365e9.26.1752491147413; Mon, 14 Jul 2025 04:05:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy4dLgqm1Dk8YPznbMSHiqIweOBKgO0JdPQG+paLDIK3/W0uLMBr4L67oA3QjedLZaMCMKMg== X-Received: by 2002:a05:600c:37c4:b0:456:302:6dc3 with SMTP id 5b1f17b1804b1-456030271bemr65063125e9.26.1752491146908; Mon, 14 Jul 2025 04:05:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li Subject: [PULL 37/77] i386/cpu: Unify family, model and stepping calculation for x86 CPU Date: Mon, 14 Jul 2025 13:03:26 +0200 Message-ID: <20250714110406.117772-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491880983116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li There are multiple places where CPUID family/model/stepping info are retrieved from env->cpuid_version. Besides, the calculation of family and model inside host_cpu_vendor_fms() doesn't comply to what Intel and AMD define. For family, both Intel and AMD define that Extended Family ID needs to be counted only when (base) Family is 0xF. For model, Intel counts Extended Model when (base) Family is 0x6 or 0xF, while AMD counts EXtended MOdel when (base) Family is 0xF. Introduce generic helper functions to get family, model and stepping from the EAX value of CPUID leaf 1, with the correct calculation formula. Signed-off-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250630080610.3151956-5-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 30 ++++++++++++++++++++++++++++++ target/i386/cpu.c | 12 ++++-------- target/i386/host-cpu.c | 6 +++--- target/i386/kvm/kvm.c | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b3bb9888579..a580562b3dc 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2678,6 +2678,36 @@ static inline int32_t x86_get_a20_mask(CPUX86State *= env) } } =20 +static inline uint32_t x86_cpu_family(uint32_t eax) +{ + uint32_t family =3D (eax >> 8) & 0xf; + + if (family =3D=3D 0xf) { + family +=3D (eax >> 20) & 0xff; + } + + return family; +} + +static inline uint32_t x86_cpu_model(uint32_t eax) +{ + uint32_t family, model; + + family =3D x86_cpu_family(eax); + model =3D (eax >> 4) & 0xf; + + if (family >=3D 0x6) { + model +=3D ((eax >> 16) & 0xf) << 4; + } + + return model; +} + +static inline uint32_t x86_cpu_stepping(uint32_t eax) +{ + return eax & 0xf; +} + static inline bool cpu_has_vmx(CPUX86State *env) { return env->features[FEAT_1_ECX] & CPUID_EXT_VMX; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d3d13b14726..b768838b100 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6325,10 +6325,7 @@ static void x86_cpuid_version_get_family(Object *obj= , Visitor *v, CPUX86State *env =3D &cpu->env; uint64_t value; =20 - value =3D (env->cpuid_version >> 8) & 0xf; - if (value =3D=3D 0xf) { - value +=3D (env->cpuid_version >> 20) & 0xff; - } + value =3D x86_cpu_family(env->cpuid_version); visit_type_uint64(v, name, &value, errp); } =20 @@ -6366,8 +6363,7 @@ static void x86_cpuid_version_get_model(Object *obj, = Visitor *v, CPUX86State *env =3D &cpu->env; uint64_t value; =20 - value =3D (env->cpuid_version >> 4) & 0xf; - value |=3D ((env->cpuid_version >> 16) & 0xf) << 4; + value =3D x86_cpu_model(env->cpuid_version); visit_type_uint64(v, name, &value, errp); } =20 @@ -6401,7 +6397,7 @@ static void x86_cpuid_version_get_stepping(Object *ob= j, Visitor *v, CPUX86State *env =3D &cpu->env; uint64_t value; =20 - value =3D env->cpuid_version & 0xf; + value =3D x86_cpu_stepping(env->cpuid_version); visit_type_uint64(v, name, &value, errp); } =20 @@ -8155,7 +8151,7 @@ static void mce_init(X86CPU *cpu) CPUX86State *cenv =3D &cpu->env; unsigned int bank; =20 - if (((cenv->cpuid_version >> 8) & 0xf) >=3D 6 + if (x86_cpu_family(cenv->cpuid_version) >=3D 6 && (cenv->features[FEAT_1_EDX] & (CPUID_MCE | CPUID_MCA)) =3D=3D (CPUID_MCE | CPUID_MCA)) { cenv->mcg_cap =3D MCE_CAP_DEF | MCE_BANKS_DEF | diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index b1fb6d68161..d5e2bb5e187 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -117,13 +117,13 @@ void host_cpu_vendor_fms(char *vendor, int *family, i= nt *model, int *stepping) =20 host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); if (family) { - *family =3D ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); + *family =3D x86_cpu_family(eax); } if (model) { - *model =3D ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); + *model =3D x86_cpu_model(eax); } if (stepping) { - *stepping =3D eax & 0x0F; + *stepping =3D x86_cpu_stepping(eax); } } =20 diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index fc58a23b30d..e8c8be09bae 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2259,7 +2259,7 @@ int kvm_arch_init_vcpu(CPUState *cs) cpuid_i =3D kvm_x86_build_cpuid(env, cpuid_data.entries, cpuid_i); cpuid_data.cpuid.nent =3D cpuid_i; =20 - if (((env->cpuid_version >> 8)&0xF) >=3D 6 + if (x86_cpu_family(env->cpuid_version) >=3D 6 && (env->features[FEAT_1_EDX] & (CPUID_MCE | CPUID_MCA)) =3D=3D (CPUID_MCE | CPUID_MCA)) { uint64_t mcg_cap, unsupported_caps; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492495; cv=none; d=zohomail.com; s=zohoarc; b=KRkLhtFFdCKIiu0PJ8NKKBtniSi3/pYonxrvDEAe1sgNExDhk0+VuIdvmLO7BkexWcnOtRFy9e1GzKtJZKRjluKbjUdDCRIfb8LMdRRp9FQwipeQrARcPBH0GT9KdwhhEJ1eD963lgIfQQENAVMyQUS7n5dEaxe+pkRQcb4JrRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492495; 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=MBwevjOhRk6EkhoFd3vWdZKDnsxohT7/wN7rE5aDxAg=; b=LfGAK9Uev2asVYzIqX4NkZRrd9T1115CSZrmvBqYct5hFGkL2oL5cW9n9EkuPIrn6d/qPLUHlYup/Ol30eJzuPMRfS+HipnxXBzrodEpt0rCdXGIQ2i5Resu6dvSworhQ2xS4W0oBBYRhCHIbWrVNVf6s3OmUq1FqMKBYCi5DTY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492495656764.9658974738771; Mon, 14 Jul 2025 04:28:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHKF-0004RD-GW; Mon, 14 Jul 2025 07:26:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0Q-0001NZ-JU for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0L-0001xx-J6 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:57 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-O2dXi3ngMpqN9XAxmj7idA-1; Mon, 14 Jul 2025 07:05:51 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a50816cc58so1416982f8f.3 for ; Mon, 14 Jul 2025 04:05:51 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45617dc1fccsm38365675e9.5.2025.07.14.04.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491152; 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=MBwevjOhRk6EkhoFd3vWdZKDnsxohT7/wN7rE5aDxAg=; b=aPfnXe3mVvJ7Z/Px9UsyMAp+lq0kG6aXEs1ESmC53EuOScHsd84zLZmgQsPawAuF2T/j6a ayxJ6a+kmr2TmcQ5f7EXqIaQwrhfzBrLDZtultUw/lVeWublK9IfYfC1mqT7Op0tvBQrkl GALAFNr9hQQpbk/1a26n7zIZjlU/nnY= X-MC-Unique: O2dXi3ngMpqN9XAxmj7idA-1 X-Mimecast-MFC-AGG-ID: O2dXi3ngMpqN9XAxmj7idA_1752491150 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491149; x=1753095949; 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=MBwevjOhRk6EkhoFd3vWdZKDnsxohT7/wN7rE5aDxAg=; b=dF6jki/7aEbg7+ygtOUsLQ0ryfQ/R0hBoPaxOin9KEyOYaQkhDJDfGVQxFUeeM6m7L 8cN15Wb/2z28pV3S59Gpunm8aTW3b58cxQ6v6iVt0Emta8mQ/8iCsVT/RN9pdX9x0ADn YBc0MV2cfGxB/DAvjgKqVJyD0Jbpq7/4hP7LjZEfhZAgrKG+rw9i76an8DOrHJ6d8bip w7FfDjX1imG8LdFFTFbbp5BG2597P714k10W/VGNqTKxXg2tfSXn0n+YNaEv3xoEm6oS Zf14R3/CAmDd1I6Y3iW/sv+gIvLCZgb2NSk5qDkRQ7fsEq5ozCr1b7lCRc52rnbvbpWu ujZA== X-Gm-Message-State: AOJu0YzJC7bWRz0gw4Jef925YHfkBCR8sVbzMScPPg5/FMC5zP0hC/mu h+uU/yUSw9sH3XfiQOHxYGvRS86jXxFbj6zxQp8ULVUjKdkpg8GkEZ/Z/PfEswtsY6pFHVswCuk ir/Jni85CMXgbcPftAMLdzNj3tSYalym3WuzTK94Jm7NDf1CIjeTer9gO8cG+2vxts55qSX9+dc 1v7tiP0x+b2lM3kE6rw9CfsSaa75z6UT2C1iqa6JUF X-Gm-Gg: ASbGncuH5uEz0fScMh7cHhDx9ad0Jnx9ostOrNHvaXapu/DzmY3oV0nRbjmHj4R1a1Z Svesov9MPo8ELU+41zpZnBP/n+dwcllHKpZbKElSPiHSYRjhU2CNO31CsxIOJ22elnqWPxyAzsw uxm8IFPKpRuSR3BZ+UhB+VWMVNf07Z0BjQh/FguyuuL3dZy8kCVsUggzZv8Hi0bLcFgqa6JqWs2 6XMIWm9lkbOl6AyOUdhhU4WB5Q36ri3KpMyOH0hu6QDBBvTvoBfw9DbxmeA4gaW5XmeveN7+VKy cx68L+MFmqoGWVcQDf2Bh1hNXI/Y+FZPTsj90agrGoA= X-Received: by 2002:adf:e186:0:b0:3a5:2653:7308 with SMTP id ffacd0b85a97d-3b5f18debd5mr12150444f8f.57.1752491148635; Mon, 14 Jul 2025 04:05:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3CtiCjNnS3zYqf88BuiobIylpZ9ILgZlGY8K7rcRW3Zd9I1K7jWjFuxPKGQc18OMlIomWSg== X-Received: by 2002:adf:e186:0:b0:3a5:2653:7308 with SMTP id ffacd0b85a97d-3b5f18debd5mr12150414f8f.57.1752491148166; Mon, 14 Jul 2025 04:05:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , Zhao Liu Subject: [PULL 38/77] i386/tdx: Remove task->watch only when it's valid Date: Mon, 14 Jul 2025 13:03:27 +0200 Message-ID: <20250714110406.117772-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492497557116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li In some case (e.g., failed to connect to QGS socket), tdx_generate_quote_cleanup() is called with task->watch invalid. It triggers assertion of qemu-system-x86_64: GLib: g_source_remove: assertion 'tag > 0' failed Fix it by checking task->watch. Fixes: 40da501d8989 ("i386/tdx: handle TDG.VP.VMCALL") Signed-off-by: Xiaoyao Li Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250625035505.2770580-1-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/kvm/tdx-quote-generator.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx-quote-generator.c b/target/i386/kvm/tdx-qu= ote-generator.c index f59715f6175..dee8334b27a 100644 --- a/target/i386/kvm/tdx-quote-generator.c +++ b/target/i386/kvm/tdx-quote-generator.c @@ -75,7 +75,9 @@ static void tdx_generate_quote_cleanup(TdxGenerateQuoteTa= sk *task) { timer_del(&task->timer); =20 - g_source_remove(task->watch); + if (task->watch) { + g_source_remove(task->watch); + } qio_channel_close(QIO_CHANNEL(task->sioc), NULL); object_unref(OBJECT(task->sioc)); =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493479; cv=none; d=zohomail.com; s=zohoarc; b=Z+5s1wPTY7P3E+wm1fTszPZxRkn1IfY7jqSfyF+Ql+mahbEIL+c4NR11EAz0rYAjZBw4c458JD7MlxHAieUNF/9M6JDnHiKEO/XwEfZo2DNE1PEJ29wKzKNfOviXNK4mGKbXCIi3AKSfFXmUyDID38ZbqABVMPpkwiTQF67Tbj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493479; 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=H++7bFZZz0BdH8FF5Yhc/WS1RX64LTDufArp4gDgK4o=; b=IUVtd7AI0OJ4cRnCBFGeUe1+PPuIpsh7v95xcVumqeiTm/on8uLO7tCq1i6DzSsepW3/rMqwoM4rc6DVabsb9VrwUDO4woEcpyAmTDneHEXB/gI6GCBwiA+6ymMbEr29lzsbbI4j+p2fhgGeH5fhX5a8gDKPcv/nY30nGr5tBWk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493479458568.8200852166524; Mon, 14 Jul 2025 04:44:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLK-0005YU-7H; Mon, 14 Jul 2025 07:27:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0R-0001Nt-3r for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0O-0001zO-Ia for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:05:58 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-QCEMveEvOlWWZL5H0ZwIVw-1; Mon, 14 Jul 2025 07:05:54 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451ecc3be97so22101655e9.0 for ; Mon, 14 Jul 2025 04:05:54 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d50ded8csm166809555e9.20.2025.07.14.04.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491155; 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=H++7bFZZz0BdH8FF5Yhc/WS1RX64LTDufArp4gDgK4o=; b=dJCmbhBi932eyQ87b/IQ8hx1UhTgA8byC+A94PFArFhBpwVbUDoawfmCQXK+lDU2DZY8fd MYvqnSJZrSI5nwQL4v+4NckVyIalPEZfav7N0/5ZDdt+oNZJ5Awjp3XtC92UBvWxZhLwBC xhQhDDl8oCSfZyAavqAxq6VnZvGGGv8= X-MC-Unique: QCEMveEvOlWWZL5H0ZwIVw-1 X-Mimecast-MFC-AGG-ID: QCEMveEvOlWWZL5H0ZwIVw_1752491153 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491153; x=1753095953; 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=H++7bFZZz0BdH8FF5Yhc/WS1RX64LTDufArp4gDgK4o=; b=vRo1my5gf/Vt1nV5+8GiWsrIxS5MU2TRAXo72hd+0SWuXMQLKDlcxXFJ+LlkqTy0sn hTDytZLTuReGiqWAPlxTVYMLYLAMtgz9T2XxMVNgi65w3PreKDDbJ8qEF9KwBgADXQ7j uABxUzGafFz1ryttoBb701Sjd7D9y/ok4dK0TZGbY56joEv558J7CbRMWt+mufR+jV2P wIYT2WQLNY4afWkJajQsFdFaIgHEQmwzfpUAyRXWCgnut529PKxlS9qIm1+vD7++x748 adkTavQoSQSUCZu68ecD4uPjgQptO5J6KSSng24933XOhvegq5faSy7NVDCqm+9LyMcU 8jTQ== X-Gm-Message-State: AOJu0YxU53iv48niSVtPcyIyZ7U9NIRzDSz6KbdGjp6DaRwUOVteH+5v 2NTvebA6TZgdvUil9eWLfp05eUUxl08OmKuMQ5zKbwvLM6rze5hNadttVnGcB5LAQnLaX0hvy23 zEwHuMXUPzBRHkdZ8sYgizqSyfJJ+7Kqu+CbV4RCYLlk/YytuJhKfipYPyAlQuNPMah80hCqufT HUrbfe3ydWQggJ5G5/Z9K5WYSSCPuF2w2MHFjkLWdl X-Gm-Gg: ASbGnctsP1E8iiSaXRs062j9kYkSNaGNRvxNYRDGYyqn+qmTzS76Lhu9t8W1WJmoL6a OSWcEj4w3UhxnjPy3QtDBgdfXkZWONnuHtIauKPkfW+kjwZpNwIIogvs8HWp3iDsImc+xvSYX4d BmQuZGElf/hd2gwUDWmbIy53C6sZhNvM2rDtri0RJQOIzIO/jzi/TsjN8BE3g1U8OonHUdbw8OF /dG6RrvNp3jm4iNn1cQzOVP6gDd7p/kFXv1NK1V07rX8tkSw8ytkXgr1e4nUEu4aphgAmbndAaI zrOmvyFqXdO4b1b6UDEN+4uQtRTAqVZ6hpFq8lB+JpA= X-Received: by 2002:a05:600c:34c5:b0:43c:fe5e:f040 with SMTP id 5b1f17b1804b1-45565edc8f4mr99187415e9.23.1752491152433; Mon, 14 Jul 2025 04:05:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEVLM3vTpeynBS77usHfWMNhE2tboZqaO3bZMr/ImTuMBrQQ7nqF9KAqtYPV/W60Pzy1FexQ== X-Received: by 2002:a05:600c:34c5:b0:43c:fe5e:f040 with SMTP id 5b1f17b1804b1-45565edc8f4mr99187165e9.23.1752491151874; Mon, 14 Jul 2025 04:05:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , Zhao Liu Subject: [PULL 39/77] i386/tdx: Don't mask off CPUID_EXT_PDCM Date: Mon, 14 Jul 2025 13:03:28 +0200 Message-ID: <20250714110406.117772-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493481085116600 Content-Type: text/plain; charset="utf-8" From: Xiaoyao Li It gets below warning when booting TDX VMs: warning: TDX forcibly sets the feature: CPUID[eax=3D01h].ECX.pdcm [bit 15] Because CPUID_EXT_PDCM is fixed1 for TDX, and MSR_IA32_PERF_CAPABILITIES is supported for TDX guest unconditioanlly. Don't mask off CPUID_EXT_PDCM for TDX. Signed-off-by: Xiaoyao Li Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250625035710.2770679-1-xiaoyao.li@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b768838b100..f9e6bc8d0e6 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -28,6 +28,7 @@ #include "system/hvf.h" #include "hvf/hvf-i386.h" #include "kvm/kvm_i386.h" +#include "kvm/tdx.h" #include "sev.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -8336,7 +8337,8 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **err= p) } } =20 - if (!cpu->enable_pmu) { + /* PDCM is fixed1 bit for TDX */ + if (!cpu->enable_pmu && !is_tdx_vm()) { mark_unavailable_features(cpu, FEAT_1_ECX, env->user_features[FEAT_1_ECX] & CPUID_E= XT_PDCM, "This feature is not available due to PM= U being disabled"); --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491797; cv=none; d=zohomail.com; s=zohoarc; b=XDxutVzmwL7JIf9byceTitdFBnj5HfZi7pQr1OAbNzvC2Dx0sy7Uc6B3Tux8/8sjQJSLUqO6ZgjBPZgFKOgQxuFZVF4Q73C1kRYN/N1PE526HUbC55iGm594owMgUSQs9IRhydbJ/TV4WyDC7t631X8xN2aw8uPRzbyk9oaLULw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491797; 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=BTubnZ3o2Xiym1BO+0Jx8Ne4oet/OLGfGzFGRCfDWJM=; b=SmInDGoHTxc/2I+WPeQD6Thft6sAgPkRg188BwjVD9+xiOLqlw59dqiJTIQi0QiIv9hx8dNn5RjVkKJ4HKDXQ3/flWEcLMvKHeE6osNhamsrSTFZjTvJQJiTLuqd55leTVnVctIrSeZSzRvBrpr60BwHzkF9+Wcw2novK1PSTSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17524917970491019.2802615777133; Mon, 14 Jul 2025 04:16:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHA2-00037m-86; Mon, 14 Jul 2025 07:16:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0S-0001Om-Fp for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0Q-00020g-JY for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:00 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-61AHHMq-P_qnRyEdl-Yo4Q-1; Mon, 14 Jul 2025 07:05:56 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3af3c860ed7so1840195f8f.1 for ; Mon, 14 Jul 2025 04:05:56 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454dd43906dsm130735525e9.3.2025.07.14.04.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491157; 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=BTubnZ3o2Xiym1BO+0Jx8Ne4oet/OLGfGzFGRCfDWJM=; b=c1ucV1cYhYTUD19SJe8H9d1KSwu3yhp0Cwg+ERoqdARQ+XOFm7u8Z1VeMXlEpo4LaKeUmD Sy61lZ1LXW7LTewvBv07uiXVYjvNyvWvvFW4s3Q2pXXp/09ZtcCSQKKDr6j5kpw2RnS/5z sTL6P1FcZuznFnRtmMdxn1Y7FknGjw0= X-MC-Unique: 61AHHMq-P_qnRyEdl-Yo4Q-1 X-Mimecast-MFC-AGG-ID: 61AHHMq-P_qnRyEdl-Yo4Q_1752491155 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491155; x=1753095955; 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=BTubnZ3o2Xiym1BO+0Jx8Ne4oet/OLGfGzFGRCfDWJM=; b=fM1IxynCU0yGxdBl6O+J66fsrYytdwu3hg1MDKytiZNeBmval3Y8mlhNFzAIq7EXp2 RT/qRkk1yROQzMK+Bu+WEP16/6NYEtC49AGKlIPQtwpC83EQDo8HodXlgTwDltZIG24I r0I1uMVZgAXX7LS534MU5UTLpUerLcN1QZuUkWChZNlvWVZe8lrJ5WGML+QEMoqjiNxB F/VjwcLt8vDZbFLQj5E4m1BBS5lBjvL8kejPc9POKrzjjw8FXytnV/MXZ2bay4tbt0Cs KSxgkBJhuXsaL+e/X3vtZ8kSiKn2Mmvb+xZl7jqZ94jFQTJk4iPbeasdZbgfci4iS2Km xKNQ== X-Gm-Message-State: AOJu0YxNketSVmXwwf1RXwkUqwrbYi39FVKFqyWqxibi5a5quY1eDaLv EEyqdvLnuwGPdnctXIDy9EW/GaJP1KF24ILlHqSrpiDbNiNmn2D5SD9BmUhXl1LAeJTJM2raX9D UCPXS3RhLm2Atiwabmj0n2ypeNgI2j5IqARN6c0fnUnC+PSo3Aq/wlBo77G6Db0W9X8nxa8MDob DHGz6jSN0169YVkOaZ7pmSOtKTI3QYQ+TYmXep+ETa X-Gm-Gg: ASbGncvItZ1lLZuZCD6Sd93gbq5cOK+SXUv78KOt9BENDx2qoSV9rLyQkveQfE25WmW CawnGdEaH+raOA0Xw3K7XqgPNGXGMe+jG65CdjEixVUX0vcsBwJK4DxQua2vODYGDzonjUH+5Ud tXzJBSGAG5DJiEOV70/eyyROV744eaf2DnUBn5WZKZSylXjBp0MyL/h260aRavW1WQyKauYGJBs Xc/hfTTxh3MktCBIDVcVhr+t3+5z1E8eo7jXur4J0PYGOq8kgT/r899iuokrnxJvPWljLOlhsXY s/EPTtsDuFu8sHcuvFd6nPnVUtnpovs3uEIfbXcPWl4= X-Received: by 2002:a05:6000:4012:b0:3a4:c8c1:aed8 with SMTP id ffacd0b85a97d-3b5f2e229a9mr8767497f8f.39.1752491154860; Mon, 14 Jul 2025 04:05:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxZCI6whCGuhwZJQbFjNVK4kWfAqulRs1wLCzTC1CnQkSpF9Konh5oajRVqAwnAib+rOso6g== X-Received: by 2002:a05:6000:4012:b0:3a4:c8c1:aed8 with SMTP id ffacd0b85a97d-3b5f2e229a9mr8767475f8f.39.1752491154358; Mon, 14 Jul 2025 04:05:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 40/77] i386/cpu: Refine comment of CPUID2CacheDescriptorInfo Date: Mon, 14 Jul 2025 13:03:29 +0200 Message-ID: <20250714110406.117772-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491797944116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Refer to SDM vol.3 table 1-21, add the notes about the missing descriptor, and fix the typo and comment format. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f9e6bc8d0e6..f107e586734 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -68,6 +68,7 @@ struct CPUID2CacheDescriptorInfo { =20 /* * Known CPUID 2 cache descriptors. + * TLB, prefetch and sectored cache related descriptors are not included. * From Intel SDM Volume 2A, CPUID instruction */ struct CPUID2CacheDescriptorInfo cpuid2_cache_descriptors[] =3D { @@ -89,18 +90,29 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descripto= rs[] =3D { .associativity =3D 2, .line_size =3D 64, }, [0x21] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 = * KiB, .associativity =3D 8, .line_size =3D 64, }, - /* lines per sector is not supported cpuid2_cache_descriptor(), - * so descriptors 0x22, 0x23 are not included - */ + /* + * lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x22, 0x23 are not included + */ [0x24] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 = * MiB, .associativity =3D 16, .line_size =3D 64, }, - /* lines per sector is not supported cpuid2_cache_descriptor(), - * so descriptors 0x25, 0x20 are not included - */ + /* + * lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x25, 0x29 are not included + */ [0x2C] =3D { .level =3D 1, .type =3D DATA_CACHE, .size =3D 32 = * KiB, .associativity =3D 8, .line_size =3D 64, }, [0x30] =3D { .level =3D 1, .type =3D INSTRUCTION_CACHE, .size =3D 32 = * KiB, .associativity =3D 8, .line_size =3D 64, }, + /* + * Newer Intel CPUs (having the cores without L3, e.g., Intel MTL, ARL) + * use CPUID 0x4 leaf to describe cache topology, by encoding CPUID 0x2 + * leaf with 0xFF. For older CPUs (without 0x4 leaf), it's also valid + * to just ignore L3's code if there's no L3. + * + * This already covers all the cases in QEMU, so code 0x40 is not + * included. + */ [0x41] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 128 = * KiB, .associativity =3D 4, .line_size =3D 32, }, [0x42] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 = * KiB, @@ -138,9 +150,10 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descript= ors[] =3D { .associativity =3D 4, .line_size =3D 64, }, [0x78] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 = * MiB, .associativity =3D 4, .line_size =3D 64, }, - /* lines per sector is not supported cpuid2_cache_descriptor(), - * so descriptors 0x79, 0x7A, 0x7B, 0x7C are not included. - */ + /* + * lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x79, 0x7A, 0x7B, 0x7C are not included. + */ [0x7D] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 2 = * MiB, .associativity =3D 8, .line_size =3D 64, }, [0x7F] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 = * KiB, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752491973; cv=none; d=zohomail.com; s=zohoarc; b=DML4eaPw4Ex47/mNhA2X6Zmtrr2PiTvObWIzsniQ5g35bK5fNSnizW6ysC29/cul6WGdwt7KmcURvk/HmD6IFirTP7pjkCHWKzWsD3KkBXvSm70PtVEKSYLilg+IaLfR1dLosUpwqWivm6apyNIr+yAZcSMyvIy5Xb9gic5XPHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752491973; 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=1Oo3Mq8d89aj4RwZyYW7r9/QmVUY360NGuFe7tGChvw=; b=Ho2STAzfZkT+9OQD0JB6ZKasM9eU/xmabjRn6KkeM0VJ/mTO+BAdlEA+Xqhs1grD/z+270CFhsU8D6LWb+wOfoNn9g2zBsF/VaVRrxc+pSyXwAttNlo0e+Mipy+5rMjHEAEoq5E7HbCTLiXdFVDe4Jiah9u3vMDcl/NOk8aISeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752491973252798.5820614247469; Mon, 14 Jul 2025 04:19:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHAT-0003ax-8i; Mon, 14 Jul 2025 07:16:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0V-0001QK-I9 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0T-00021q-O9 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:03 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672--VcftfWtPM-OC40ooK0sag-1; Mon, 14 Jul 2025 07:05:58 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-456013b59c1so11251865e9.3 for ; Mon, 14 Jul 2025 04:05:58 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561752340esm39317585e9.38.2025.07.14.04.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491160; 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=1Oo3Mq8d89aj4RwZyYW7r9/QmVUY360NGuFe7tGChvw=; b=I7QPBGSk6q5GYrKt3unufrhPFhtJH5SPXzVAWchg6IieytcHEKczgML12r6rZvavRS9iOs gC/KC3E53Iq2G0y3zc2ll+E1/FvyYTBdZ6WTFqJijw1V7kfse65oHnNuY62dMYvjllKubs g3aIBLzvcKtlbQUvUvYQHYT5iq/mIzo= X-MC-Unique: -VcftfWtPM-OC40ooK0sag-1 X-Mimecast-MFC-AGG-ID: -VcftfWtPM-OC40ooK0sag_1752491157 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491157; x=1753095957; 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=1Oo3Mq8d89aj4RwZyYW7r9/QmVUY360NGuFe7tGChvw=; b=i5/Hv1BSAeR9QsBCuUYRGo7onl/UZNJ1yb4NhAB6+Ju2vIGjCGgSjsWhuc/g8PPSzR oM7JJfT6m7p00Bzo3MRhWc47qLyFX7dR5bf5aT0T2NtPhdzNw/ZCmr20qdf6D844Yx3X VPRTrf/JhTgqzEmOLDYB0ulw5xiBhbzXdmi1qzYy1asStqr3LKJBpgAJZd5DDsiOGVfS tt4pSXfk0OEWZS+hfvvpxkKsPFReIbXQYkbhjez5wg0XvO2qjUhJl06fW45mowbH0zLm xc4EnA39C6xgmuMt7FNPszWgMmj0KhQYAlCJtODsjSkX4FB3Q1tuk5AABNAEKgAkEdrV zEFA== X-Gm-Message-State: AOJu0YwLdKAfNJzLpaImIc7+AIfMDJUUmP4ZIZwLu9WyrKXi8p83ch9Y ehUp3NdqUSgjlJaffVkcZ1WXNHXoSDbGnbhE2uUUpxzCmmxQWTZNOQQB/hILZN/fpmWXkUCvIBh izgoPtZdJ97bEfTBY8lMzJUVdfnkCZqwKQVCQmdYP/WLgRaqzSj7Xzxh/+TQ60JWRsEMOKmrU3W bf5EHQXdP53uvsUWCFA06Mb63aCE5KBoFmYGqrODxR X-Gm-Gg: ASbGncuDyMwz6jQZA+0rCEopdVQLBZ2rbbM+U1jRuKF/uIvgJPkQMgKTiJBSWjUsj6A 5ZOyorPD2vCpkRrO17tFtG0jLM8tILaIh9NbJ7XeiCdUbslhKq4K/5B10dT5Dhn7ugnFJN6YBc/ 0m2hofCuGUNUq/5gD8dSpb5OxZBi5G2EACna8qLMXZ845lQbCbR1sqXca4Q2hIrmdagOiGNw1Eb 8kJZjDPq9JAxwhYod8EUUsSX7/s2M8a7SYo97Xp0A2db+0VdAt6XxOSnWeA8RolZd7+DPzhU+mF NzNf5/LWGBEG2KzOlFNUya0ePi9NhRQKfNCyWBhujAU= X-Received: by 2002:a05:600c:3481:b0:456:1442:86e with SMTP id 5b1f17b1804b1-45614420b46mr36808255e9.21.1752491156797; Mon, 14 Jul 2025 04:05:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEng2ALQiQcclffqdjxyYchlIAMr7NEzhnsIKAkQtPbbwVT/TCRO0GPJXkTYXNigqqSY1yA+Q== X-Received: by 2002:a05:600c:3481:b0:456:1442:86e with SMTP id 5b1f17b1804b1-45614420b46mr36807935e9.21.1752491156284; Mon, 14 Jul 2025 04:05:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 41/77] i386/cpu: Add descriptor 0x49 for CPUID 0x2 encoding Date: Mon, 14 Jul 2025 13:03:30 +0200 Message-ID: <20250714110406.117772-42-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752491974078116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The legacy_l2_cache (2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size) corresponds to descriptor 0x49, but at present cpuid2_cache_descriptors doesn't support descriptor 0x49 because it has multiple meanings. The 0x49 is necessary when CPUID 0x2 and 0x4 leaves have the consistent cache model, and use legacy_l2_cache as the default L2 cache. Therefore, add descriptor 0x49 to represent general L2 cache. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f107e586734..4386b60ff6c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -129,7 +129,18 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descript= ors[] =3D { .associativity =3D 8, .line_size =3D 64, }, [0x48] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 3 = * MiB, .associativity =3D 12, .line_size =3D 64, }, - /* Descriptor 0x49 depends on CPU family/model, so it is not included = */ + /* + * Descriptor 0x49 has 2 cases: + * - 2nd-level cache: 4 MByte, 16-way set associative, 64 byte line s= ize. + * - 3rd-level cache: 4MB, 16-way set associative, 64-byte line size + * (Intel Xeon processor MP, Family 0FH, Model 06H). + * + * When it represents L3, then it depends on CPU family/model. Fortuna= tely, + * the legacy cache/CPU models don't have such special L3. So, just ad= d it + * to represent the general L2 case. + */ + [0x49] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 4 = * MiB, + .associativity =3D 16, .line_size =3D 64, }, [0x4A] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 6 = * MiB, .associativity =3D 12, .line_size =3D 64, }, [0x4B] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 8 = * MiB, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492976; cv=none; d=zohomail.com; s=zohoarc; b=aEx1cIi0HNtMdC6lr0ipbMJzBcQihf51hYwnaPmHfQfBRUok8Q8+u2vHowiuIRBng/aUrVpSnlCAjM2zfi+3UlMC1jWLU1TQViMKtfqtClfccFeA5+izOq4IMD/dn77QBQX0nX39ctAITWCDbX1Ctd0pri0sllN7ry23qzAaVzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492976; 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=hOyq8vxRGWTrMc2U4FZhuFke/jjaHE1X37zP4eIBRDQ=; b=aFOsdShyRnOOfv8UFjwaqu0bOjhhThjsyPmAbzk9rTaRauMZzXUXJHkIAf0sldZoYvW5VjcbS5avRc7zAqFbtMQrMUNm6hJ9HYfvrxwY6NRjKfiFDoFiUx0t9uDCBCf0TtlUqYNyCLVqo5UEwFX3QZYGlbnU2HzErxR8LHeGNLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492976334712.3062654376208; Mon, 14 Jul 2025 04:36:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHCO-0005Do-8r; Mon, 14 Jul 2025 07:18:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0c-0001WF-9C for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0V-00022R-D8 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:09 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-403-px6NXlZoOLWXp9OVyCV1RQ-1; Mon, 14 Jul 2025 07:06:01 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-453018b4ddeso21341285e9.3 for ; Mon, 14 Jul 2025 04:06:00 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1741sm12284801f8f.18.2025.07.14.04.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491162; 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=hOyq8vxRGWTrMc2U4FZhuFke/jjaHE1X37zP4eIBRDQ=; b=F2D+q8scJXOULPuWgEHU26luWF9EHhv7914VL0Yrmq6FBCuuYRw01DjKuAFEiafgYh6JLO nzFflNYj47nQkJnfdWE4ejW2XMFQJcqYoCD8xcjCQRDGSc9pK4BD7nQaUnfYP34+BucVTJ oBCeK5xRCp6GJCv/IGqe3W3PYWm5ZAg= X-MC-Unique: px6NXlZoOLWXp9OVyCV1RQ-1 X-Mimecast-MFC-AGG-ID: px6NXlZoOLWXp9OVyCV1RQ_1752491160 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491159; x=1753095959; 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=hOyq8vxRGWTrMc2U4FZhuFke/jjaHE1X37zP4eIBRDQ=; b=EdyNLnttqWtXK19BnWWB3g3U2lM+7j9UNW9BDONFwZbK+vt+njkR28HFysclD8NfwL MSsCdtAnLxOsiqgw7hd04hCUqMB6IuCl39GE3zFU5YaJ3kfP8iwpizBjRv1GaAQQv1F1 DemJ/Cfq7kWhQ0hD6pBgLYj3tGHKbGS+LRkgZ8e/tS1oZ3nhB4I0ahUQ8Dmkrj0d2Um6 XE2VV8cvPx4QIHUZB/JQiQnXedPxb3LnkVCj+mA0fy/1crYvm5UI/AXPquro+2wByt74 9/cT2taAVQltx8Q3uicIn0wnj0tXM7cxwFJXKTI7u1mxFjdfzvTw048Vtz8GFcEAdEKk Z6XA== X-Gm-Message-State: AOJu0Yzi0ipWVeUhTw9Ah2jetMWV94qLwbMziWfk1jvLCp/MghcTASUO pUy95NFZz5rhZ6RqTmxc3Cxcfm11xG75Sbgxr1h3ArqAlBSfF54Y8Bao78ZNLO2vA1L/1HpwGjc YDBvCPzj8Wa12XHQuWwWLbcJmIN/07GyFUmS7jQO77SsMBaLMX5YAmUt/06Fnwyhotp3GrP+hu0 1/eDNDLXq7ZArGCLOipX691n+tOFJol0aSYhyieOF/ X-Gm-Gg: ASbGnctFXkGweuYbMLDVhohpKW1hwxB/2t4+TDnKT6wc5MNqc3l1SofHD0K193aEmie nss0J9oM1q70Zrgd/hx0uYtdcpTfOt/xzozAtXMIQ2/ShJQVSKo39STLhBHKkfYZfBH0cA7Koa7 V2VCQjM+qUK6FWhVhPxlk0d8JmVJwQmjcj3a1wIjeeI47XtjsWP5GwO0O6k03SgdEZtDyoucSci lVg6F4+6NoPVifw/jvRYjmlXP7Wj+DLdiOoumJDQ3Bn6zWTyOrK4Xf1luScSNCORd38m3ZUlVjl 9wN+7pGS9xxibdemvVVrQCya7hLMPY9EBnWMhwSvQ7M= X-Received: by 2002:a05:600c:138d:b0:453:697:6f08 with SMTP id 5b1f17b1804b1-45565edcb1emr93713475e9.26.1752491158887; Mon, 14 Jul 2025 04:05:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHs+7nFgTyFsmAr6M2C+Wq+plja+UHVi9aZXmfI9hZ/uwk7nMcfanYgZMG6i6tNSTPiv5qhWA== X-Received: by 2002:a05:600c:138d:b0:453:697:6f08 with SMTP id 5b1f17b1804b1-45565edcb1emr93713165e9.26.1752491158301; Mon, 14 Jul 2025 04:05:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 42/77] i386/cpu: Add default cache model for Intel CPUs with level < 4 Date: Mon, 14 Jul 2025 13:03:31 +0200 Message-ID: <20250714110406.117772-43-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492977404116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Old Intel CPUs with CPUID level < 4, use CPUID 0x2 leaf (if available) to encode cache information. Introduce a cache model "legacy_intel_cpuid2_cache_info" for the CPUs with CPUID level < 4, based on legacy_l1d_cache, legacy_l1i_cache, legacy_l2_cache_cpuid2 and legacy_l3_cache. But for L2 cache, this cache model completes self_init, sets, partitions, no_invd_sharing and share_level fields, referring legacy_l2_cache, to avoid someone increases CPUID level manually and meets assert() error. But the cache information present in CPUID 0x2 leaf doesn't change. This new cache model makes it possible to remove legacy_l2_cache_cpuid2 in X86CPUState and help to clarify historical cache inconsistency issue. Furthermore, apply this legacy cache model to all Intel CPUs with CPUID level < 4. This includes not only "pentium2" and "pentium3" (which have 0x2 leaf), but also "486" and "pentium" (which only have 0x1 leaf, and cache model won't be presented, just for simplicity). A legacy_intel_cpuid2_cache_info cache model doesn't change the cache information of the above CPUs, because they just depend on 0x2 leaf. Only when someone adjusts the min-level to >=3D4 will the cache information in CPUID leaf 4 differ from before: previously, the L2 cache information in CPUID leaf 0x2 and 0x4 was different, but now with legacy_intel_cpuid2_cache_info, the information they present will be consistent. This case almost never happens, emulating a CPUID that is not supported by the "ancient" hardware is itself meaningless behavior. Therefore, even though there's the above difference (for really rare case) and considering these old CPUs ("486", "pentium", "pentium2" and "pentium3") won't be used for migration, there's no need to add new versioned CPU models Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-4-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4386b60ff6c..3278d5de5a7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -712,6 +712,67 @@ static CPUCacheInfo legacy_l3_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, }; =20 +/* + * Only used for the CPU models with CPUID level < 4. + * These CPUs (CPUID level < 4) only use CPUID leaf 2 to present + * cache information. + * + * Note: This cache model is just a default one, and is not + * guaranteed to match real hardwares. + */ +static const CPUCaches legacy_intel_cpuid2_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 2 * MiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 4096, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 3, + .size =3D 16 * MiB, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 16384, + .partitions =3D 1, + .lines_per_tag =3D 1, + .self_init =3D true, + .inclusive =3D true, + .complex_indexing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, +}; + /* TLB definitions: */ =20 #define L1_DTLB_2M_ASSOC 1 @@ -3045,6 +3106,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { I486_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium", @@ -3057,6 +3119,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium2", @@ -3069,6 +3132,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM2_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium3", @@ -3081,6 +3145,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM3_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "athlon", --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492927; cv=none; d=zohomail.com; s=zohoarc; b=hEFdFL7NqK8+/HL4SFPzPBHYtlVtitLZLzS0NtODk42Lo28LWkatTuBm8hJJ/KjAqdPNlD0dl8Of1HjPm3d3fsTgYTJJhDToS5g2vhWD6EGjH7A6jhxnZNKkwV+6mMT8SXC8M9/Wdqb5ueHU1NnHvhrhabIS9Sm29sHBF21DSrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492927; 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=RrhBM4PLka4qCB+6dapcsxkCed2Jrk/vEA3dhxvtRFQ=; b=YD8MsXiUe9Pr70lNfwjiToqrHhShDzfquKFeKuJA8s0qAXKHnuJOlty5l/FTy3OM/c2DBThgKxz46Jqy8aQ8yOOofw3gqNzSpKb3Po5F/Kc2LlktGBALaqwFUFepfwcu6vr4kXXD4AR+NeK2FYtBvRtKJBsFMyIQaBzYpYTmn70= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492927536534.123494751531; Mon, 14 Jul 2025 04:35:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLj-0006in-R6; Mon, 14 Jul 2025 07:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0b-0001UW-2Q for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0Y-00023U-LY for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:08 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-5Ep95CLpMaKodsWvzf354w-1; Mon, 14 Jul 2025 07:06:03 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a50049f8eeso1844393f8f.3 for ; Mon, 14 Jul 2025 04:06:03 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4560ceb130fsm65208045e9.26.2025.07.14.04.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491165; 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=RrhBM4PLka4qCB+6dapcsxkCed2Jrk/vEA3dhxvtRFQ=; b=Q0bOt0+5KxeZlx9w3rEW9GSVevliCnoa33qqqAfs2R4Pv1i5qwF/4UEfTDb2BHUoG7Jot7 U11Re8ncOaC2v/gk9W9beu7T12atwvx6TemFl1otw4zRMunJaQujJOTHAKsPJrcvhNuVE4 Uf0jLrt7TA6F8EbCUT/OkOXfZh3J8SU= X-MC-Unique: 5Ep95CLpMaKodsWvzf354w-1 X-Mimecast-MFC-AGG-ID: 5Ep95CLpMaKodsWvzf354w_1752491162 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491162; x=1753095962; 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=RrhBM4PLka4qCB+6dapcsxkCed2Jrk/vEA3dhxvtRFQ=; b=nn+dAwcwO3ownJruT/Zv7Br7ObVFcYA5LmO72dBze5uRbCYhHHR9n0Cmy8tEYpQF4l 6WUczcv0PCYC/sb9aadjrsVwrAnNS5XovRoZpcde4481J6j0sfBW7BUgkZcCRD3OikoR jgNxbtfiJ44/R+IgiQy9riqUmwBSWtruRpZFrwuk6SqNU7wwGnyyfLCM6CG9j6zziQp1 S9fNMD/ZfRGMtRDNoRs2R9cC5GifQR1Pj+QrLdwMcHBV0zzSLJiDq+BJ5X2bVmvYNBOs blnOo+xVT37Aemhwrceqej3Xv5+79bEPVQPxJJpkOKmi2H2TKH/9tayY1Bb+HkXRhRAJ eOwQ== X-Gm-Message-State: AOJu0YzFHoU9Vi2nth2zP20kGFIt2wUXVIIXwM0LOoSwDhrMv/Xm76QH XT64wesIFTHAvyeS3hDT/Akf3jFbNjnLKKIHtn7n93py0KkqxFhmc8cbYetNQ9alW3UGBH6AfMb DYvXXCF+TNjQLl2yHTYZxJQ0JO8EJh7QkwPthDcKQtYFyFbiVF8xEi+7ue/g3EQ0xcGmJHtIUnI T1eAnfUXnhDEZLZIckKyBHoTOFTUvtux4frVGR882H X-Gm-Gg: ASbGncsWxKlWm2FJvqHFpyT9KJOSHPkELof9C7MTa4EePUELi5IM7FzvyFspmXUGJ3n SzXTA/iK43CJqUIJS64Qs0PmkaORBASMirxJurXaRA6U5tWKvpbZAdoz1ODVpdhpQ3LrAvge3qw TuX5rTNt3Aj7/FP8BblXGV5sD6wgk2OxSOOVO7b0C1y+U/CRi3JFR1MtJgykdxsKrn1BQAZBrjo mvhmUTq6V6NpHs7L5OiCEDXI+nuUguZpIo6g5hgh9VH24oEDhV3Nera4wKNVho0X3u61TjlgsiR kL1zATG5elR4aF06uYFhOLyFz0BZsQSlpQJ/mdVTwdI= X-Received: by 2002:a05:6000:21c5:b0:3a4:f7e6:284b with SMTP id ffacd0b85a97d-3b5f187b24dmr6902547f8f.10.1752491161874; Mon, 14 Jul 2025 04:06:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGEm8iTEvNvNWXppw18Lqz1Vp+Z1FflH2t/Sf0jQj2ljdG7EUunm/s5ySBo5mRiCoXilOoTQ== X-Received: by 2002:a05:6000:21c5:b0:3a4:f7e6:284b with SMTP id ffacd0b85a97d-3b5f187b24dmr6902518f8f.10.1752491161307; Mon, 14 Jul 2025 04:06:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Alexander Graf , Yi Lai Subject: [PULL 43/77] i386/cpu: Present same cache model in CPUID 0x2 & 0x4 Date: Mon, 14 Jul 2025 13:03:32 +0200 Message-ID: <20250714110406.117772-44-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492935253116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For a long time, the default cache models used in CPUID 0x2 and 0x4 were inconsistent and had a FIXME note from Eduardo at commit 5e891bf8fd50 ("target-i386: Use #defines instead of magic numbers for CPUID cache info"): "/*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */". This difference is wrong, in principle, both 0x2 and 0x4 are used for Intel's cache description. 0x2 leaf is used for ancient machines while 0x4 leaf is a subsequent addition, and both should be based on the same cache model. Furthermore, on real hardware, 0x4 leaf should be used in preference to 0x2 when it is available. Revisiting the git history, that difference occurred much earlier. Current legacy_l2_cache_cpuid2 (hardcode: "0x2c307d"), which is used for CPUID 0x2 leaf, is introduced in commit d8134d91d9b7 ("Intel cache info, by Filip Navara."). Its commit message didn't said anything, but its patch [1] mentioned the cache model chosen is "closest to the ones reported in the AMD registers". Now it is not possible to check which AMD generation this cache model is based on (unfortunately, AMD does not use 0x2 leaf), but at least it is close to the Pentium 4. In fact, the patch description of commit d8134d91d9b7 is also a bit wrong, the original cache model in leaf 2 is from Pentium Pro, and its cache descriptor had specified the cache line size ad 32 byte by default, while the updated cache model in commit d8134d91d9b7 has 64 byte line size. But after so many years, such judgments are no longer meaningful. On the other hand, for legacy_l2_cache, which is used in CPUID 0x4 leaf, is based on Intel Core Duo (patch [2]) and Core2 Duo (commit e737b32a3688 ("Core 2 Duo specification (Alexander Graf).") The patches of Core Duo and Core 2 Duo add the cache model for CPUID 0x4, but did not update CPUID 0x2 encoding. This is the reason that Intel Guests use two cache models in 0x2 and 0x4 all the time. Of course, while no Core Duo or Core 2 Duo machines have been found for double checking, this still makes no sense to encode different cache models on a single machine. Referring to the SDM and the real hardware available, 0x2 leaf can be directly encoded 0xFF to instruct software to go to 0x4 leaf to get the cache information, when 0x4 is available. Therefore, it's time to clean up Intel's default cache models. As the first step, add "x-consistent-cache" compat option to allow newer machines (v10.1 and newer) to have the consistent cache model in CPUID 0x2 and 0x4 leaves. This doesn't affect the CPU models with CPUID level < 4 ("486", "pentium", "pentium2" and "pentium3"), because they have already had the special default cache model - legacy_intel_cpuid2_cache_info. [1]: https://lore.kernel.org/qemu-devel/5b31733c0709081227w3e5f1036odbc649e= dfdc8c79b@mail.gmail.com/ [2]: https://lore.kernel.org/qemu-devel/478B65C8.2080602@csgraf.de/ Cc: Alexander Graf Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 7 +++++++ hw/i386/pc.c | 4 +++- target/i386/cpu.c | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a580562b3dc..a3ebd3e08ce 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2259,6 +2259,13 @@ struct ArchCPU { */ bool legacy_cache; =20 + /* + * Compatibility bits for old machine types. + * If true, use the same cache model in CPUID leaf 0x2 + * and 0x4. + */ + bool consistent_cache; + /* Compatibility bits for old machine types. * If true decode the CPUID Function 0x8000001E_ECX to support multiple * nodes per processor diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 432ab288a87..a6fa7923688 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -81,7 +81,9 @@ { "qemu64-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }= ,\ { "athlon-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }, =20 -GlobalProperty pc_compat_10_0[] =3D {}; +GlobalProperty pc_compat_10_0[] =3D { + { TYPE_X86_CPU, "x-consistent-cache", "false" }, +}; const size_t pc_compat_10_0_len =3D G_N_ELEMENTS(pc_compat_10_0); =20 GlobalProperty pc_compat_9_2[] =3D {}; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3278d5de5a7..1f27fcf3ee0 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8935,7 +8935,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) /* Build legacy cache information */ env->cache_info_cpuid2.l1d_cache =3D &legacy_l1d_cache; env->cache_info_cpuid2.l1i_cache =3D &legacy_l1i_cache; - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; + if (!cpu->consistent_cache) { + env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; + } else { + env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache; + } env->cache_info_cpuid2.l3_cache =3D &legacy_l3_cache; =20 env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; @@ -9461,6 +9465,7 @@ static const Property x86_cpu_properties[] =3D { * own cache information (see x86_cpu_load_def()). */ DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, true), + DEFINE_PROP_BOOL("x-consistent-cache", X86CPU, consistent_cache, true), DEFINE_PROP_BOOL("legacy-multi-node", X86CPU, legacy_multi_node, false= ), DEFINE_PROP_BOOL("xen-vapic", X86CPU, xen_vapic, false), =20 --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492771; cv=none; d=zohomail.com; s=zohoarc; b=P9TXGVwXUJtT78dGVnTPRn8LpA3HDZkcyBK5B3bzEAVRN/2DU5QLyhUqOulAYPqVV9H0jvXFeORyPm+M0A7oqDYD1KcahAjB/4pqTTliGxmJqsLQbdW9cAYhASHIsMQgZle0Thqk6Glwl6SwCJWRsrwBNMpusFdhyyPZaS2Ki0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492771; 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=vKAR39+Qoo2PsRjRakDp2hLXY0ic7nZQK21Qh2O4ItU=; b=Izu4uzJQrlyG6vOJYJjtfVQUMu6UkaI+9D9nBdIjQ5Ocpo+xzF9PufezfqCuwxKEGqtLIwRrmkIAorSwzMoNEJuTSC66xOIE158oBCJTjY1LQi+lTzPjDjWn3MGNje0gCTshXwnAMYsjOOean7WTxOwSC2fNM4MNVMrNbvxBmU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 17524927716651014.3075251646433; Mon, 14 Jul 2025 04:32:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHLp-0007Ac-NZ; Mon, 14 Jul 2025 07:28:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0c-0001XN-Pv for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0a-00023m-M5 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:10 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-FDVUJ1EgNW-S1qlN8g6VZg-1; Mon, 14 Jul 2025 07:06:06 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-45597cc95d5so15271085e9.1 for ; Mon, 14 Jul 2025 04:06:06 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454dd43912dsm130739785e9.2.2025.07.14.04.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491167; 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=vKAR39+Qoo2PsRjRakDp2hLXY0ic7nZQK21Qh2O4ItU=; b=G5XioyEvHzSxzA92vQ3XOkVrWB7BHx9dUKbi9UN5EjEFfq4BamuUwqugjGTFN2/OyuDNuN ibqkfEuQEPuAPmoEUJ6Eql8CVTLv8tt+xf/yLiHGS+miHVwKWyuAiIGzmss2F3Kiozuf9x oQ0pjw4paH11hCw0FK9xxb/f9JfIH2Y= X-MC-Unique: FDVUJ1EgNW-S1qlN8g6VZg-1 X-Mimecast-MFC-AGG-ID: FDVUJ1EgNW-S1qlN8g6VZg_1752491165 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491164; x=1753095964; 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=vKAR39+Qoo2PsRjRakDp2hLXY0ic7nZQK21Qh2O4ItU=; b=Pn1iv6Pvjpa7O8gR9jcMdUjYWSgKMPoQOHMZEVWnTuYpJH5mToMOAigsC/65E41H6o eZSZCW0n7OmV6KcT7ENV/Od+ekCPTn7qNSKVYEsmCTyyiwRKcjykaVAqcCvqRNLCmdVG n8rjhI6FQhnYNS0L1nuG6QkFPqLkSq8iP9DyoY6tQXZ/6QZofiWDEDHWXa08Yql81KgG SK3WnCquU9GisNLLEHISrSZO2QJmDwe97hry+hYMWjcKVszu2y7lOLPIeCiH+7meYE+r 8f99RejGbwm/pWcoLhLCvh/cYiLRrgTK9cxsWfFsdVcHvd3eoleyapHAeBuDl3BujVnO Bqpw== X-Gm-Message-State: AOJu0YwhMe2Tz9Vm75fGKxCgMRWAV9SZ5M5cXBdIcV4pe7XqIp0FXB0j vklY3nur/DzPI78xzqBuVF5Wq4BZ+0FbOdfEFlihxPuEjXurYsYoZa36l2xHNGHxF7MdZccd+De 8uXnqY7dsg5eZHlVmcKgNMqjCRtA0pONy5EKIhtfYeGLO6SeQu6f6y6ZgfOdmk/VQRA7RrYb+9B vTSjF/YbadM+6ziIXW/94NfkAbBf+FqLyf5gTLu1XI X-Gm-Gg: ASbGnctaXr9efXwPDbSeX1hTHQk2+3uSbTKQj0oRivUFy15+0dWQIc8f5KEdu3fxx77 7oShUSmdbk1bE1Wc5CHVik1qkKuP2hwHk3wTBXka/IhIs3i9+LV8RcdKLvuInn/JpfaaMicw/QH LAlYp4a9/S8q2KV9fM3xWo0SdMlVwvCG4o8rlXqHYN5zSXtprxfNHlgi8pWrHP/FnkCsoAs6JTv qDw0m0bnvAWIXMhCU+Gl7cZkRak7zV84sozHKUPSq1E+817BH3J7zdD6hPJp/aFtl1cCjfrFgUK +TvIAZLhYpVqZO0QHnslzvd27NJtIfo+JCyWkGlSrpc= X-Received: by 2002:a05:600c:1c83:b0:43e:bdf7:7975 with SMTP id 5b1f17b1804b1-455e7135bbdmr86658495e9.32.1752491164343; Mon, 14 Jul 2025 04:06:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyfT5lVSL5La+qRe6r0wBd2hXC09EXivpjtDrdt0XxI0V3wtxzODpSi4/VDmYyCO3qds9YzA== X-Received: by 2002:a05:600c:1c83:b0:43e:bdf7:7975 with SMTP id 5b1f17b1804b1-455e7135bbdmr86658095e9.32.1752491163746; Mon, 14 Jul 2025 04:06:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 44/77] i386/cpu: Consolidate CPUID 0x4 leaf Date: Mon, 14 Jul 2025 13:03:33 +0200 Message-ID: <20250714110406.117772-45-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492772841116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Modern Intel CPUs use CPUID 0x4 leaf to describe cache information and leave space in 0x2 for prefetch and TLBs (even TLB has its own leaf CPUID 0x18). And 0x2 leaf provides a descriptor 0xFF to instruct software to check cache information in 0x4 leaf instead. Therefore, follow this behavior to encode 0xFF when Intel CPU has 0x4 leaf with "x-consistent-cache=3Dtrue" for compatibility. In addition, for older CPUs without 0x4 leaf, still enumerate the cache descriptor in 0x2 leaf, except the case that there's no descriptor matching the cache model, then directly encode 0xFF in 0x2 leaf. This makes sense, as in the 0x2 leaf era, all supported caches should have the corresponding descriptor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 48 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 1f27fcf3ee0..812e85b952f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -225,7 +225,7 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descripto= rs[] =3D { * Return a CPUID 2 cache descriptor for a given cache. * If no known descriptor is found, return CACHE_DESCRIPTOR_UNAVAILABLE */ -static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *cache) +static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *cache, bool *unmacthe= d) { int i; =20 @@ -242,9 +242,44 @@ static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *c= ache) } } =20 + *unmacthed |=3D true; return CACHE_DESCRIPTOR_UNAVAILABLE; } =20 +/* Encode cache info for CPUID[2] */ +static void encode_cache_cpuid2(X86CPU *cpu, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + CPUX86State *env =3D &cpu->env; + CPUCaches *caches =3D &env->cache_info_cpuid2; + int l1d, l1i, l2, l3; + bool unmatched =3D false; + + *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ + *ebx =3D *ecx =3D *edx =3D 0; + + l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); + l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); + l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); + l3 =3D cpuid2_cache_descriptor(caches->l3_cache, &unmatched); + + if (!cpu->consistent_cache || + (env->cpuid_min_level < 0x4 && !unmatched)) { + /* + * Though SDM defines code 0x40 for cases with no L2 or L3. It's + * also valid to just ignore l3's code if there's no l2. + */ + if (cpu->enable_l3_cache) { + *ecx =3D l3; + } + *edx =3D (l1d << 16) | (l1i << 8) | l2; + } else { + *ecx =3D 0; + *edx =3D CACHE_DESCRIPTOR_UNAVAILABLE; + } +} + /* CPUID Leaf 4 constants: */ =20 /* EAX: */ @@ -7446,16 +7481,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } - *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ - *ebx =3D 0; - if (!cpu->enable_l3_cache) { - *ecx =3D 0; - } else { - *ecx =3D cpuid2_cache_descriptor(env->cache_info_cpuid2.l3_cac= he); - } - *edx =3D (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1d_cache= ) << 16) | - (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1i_cache) = << 8) | - (cpuid2_cache_descriptor(env->cache_info_cpuid2.l2_cache)); + encode_cache_cpuid2(cpu, eax, ebx, ecx, edx); break; case 4: /* cache info: needed for Core compatibility */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492844; cv=none; d=zohomail.com; s=zohoarc; b=KIY53szY/F0GU6l0JfXJ3C5+6vFsedRIr75Xpl8WGT9VobVeEqs8bd+l5qSBMKLNY8WlaZ4JKhb/9GH7QK0O9W7jrFy4XhBOS6MPxuUi3zpxvadotbL5shPNZjo/ATi10V4YBIEKhzs2hFHgbjW1m2DsuNoeGXVtYCzmQFGMqi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492844; 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=Oi8bDZgPdz2Od/uSi533f6cPYkkNmFxsGsLpcHgWdeo=; b=m4VkZLllST0aSO4o87Fd7M0a3u/sO688jts7kkf5Q1ojLN156W0/THGL14mMLvqMrf8PnpF8J8hRCbvrneWXCBtbBOjaj38PlbcOXv0v4mV69l0M1rGIoudmK0BRBuUhZrBEYrEkzTtfG+KXY6GQq2zVcE7vFI2HtVddVAGI5Po= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492844580393.7522743657962; Mon, 14 Jul 2025 04:34:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHOa-0000lK-Fj; Mon, 14 Jul 2025 07:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0f-0001Zn-3i for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0c-00024F-W3 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:12 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-hwatsK3oOb6S1jMAqvHF7A-1; Mon, 14 Jul 2025 07:06:09 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4561bc2f477so5157985e9.0 for ; Mon, 14 Jul 2025 04:06:08 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561b176f87sm27426185e9.35.2025.07.14.04.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491170; 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=Oi8bDZgPdz2Od/uSi533f6cPYkkNmFxsGsLpcHgWdeo=; b=RKabXpDySgzK4c9OiAAxEcFAX8/5Sg7xDL8t1gB/g08IwK31HjwBw9SLn5nePia9AH+0cC 4Dn1akU6XHlIXKBOcsXWUXinuGWsPTjskJYEjmMTVDXlYBbL39G7lLX5BWjwNRaZQJ6T2u HMiW+rzaNecIod6cZvQHMs06QPQkD50= X-MC-Unique: hwatsK3oOb6S1jMAqvHF7A-1 X-Mimecast-MFC-AGG-ID: hwatsK3oOb6S1jMAqvHF7A_1752491168 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491167; x=1753095967; 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=Oi8bDZgPdz2Od/uSi533f6cPYkkNmFxsGsLpcHgWdeo=; b=n6fNDeFO6KReXkKhywQi9hH89NMt7A57nho7cMqYJgyHR7JwavYYKKOPaxTPnTissi JDy0bKcH/BzMuXO4hBRGOIl6RRo1qCG6dM0hehKagDdBgFdE1u9GJXuREg99drkiyakF XjbJmSNKvlPUUO92/olTGiQpMGkeamdu1SYyVZpabU2G9HXcGdmHU6Rt/E0/Ebmzjpyu btGywUQEN/TMEBGFpLEdLRpQtGutE36ddf/bOrHY5aUUfo3LsoQIA14tcLqEbwb00tY9 r9FQlakGBf74xBQquDJ9FCljjNLBCIgxC5koOZPMw4+OP9pSA08Y5tpAHNcgTF0R/xvk GNxQ== X-Gm-Message-State: AOJu0Yz3H+hjEAgYLaXFdyVyHXo3OE1HTn2+0gH7P+nZ1tXE8vpBxkrQ 2U/td2vRvv+uDIsF2D0i7E8GSSovLP9YWJ8B/4Q5LAMS4zCKrkpwqbFDTMO5F1B+tItw/Zc3mUf oTlxQMxubwKAwLp121SO19S57jUhie7imXR6oX5wBQZjEtnH/s0QEnPvdZdCoL960zNQxNmiv8P aM3Z3uZE+jlQZvRadrMZkwVdcm5E2UrFE0K86CqCGt X-Gm-Gg: ASbGncs3pKULf3xOX4mbIbziL0eKSlcB9qSmo5bIF0MwnQLYXj6phPLwDIWq7H0wajB Fa1iXGq63V7P3Qj66jef8wKdnmF/R2cWrB+pWYqtVFEmkFK7+MIDGIUVXU+ZC7LKv7mWPi5GvcV 8dgBd97Js1w66VsfDGH7EbRb/mFNbb53xSeaIRLbtZaAJTKXu8GKizhdeTjkv3+ERHvMgz16NBA V/+ul1zXWRkEoaw0SiLAIG5FdamRSjVQ7h+Od4TNNlPlAUCr4HrGWNkV/FbKbQsjf2YloMXMH7P CXPBGT5j0hgfOoUaQVrLMb9Ez6EW0vc2CpmzT5J2h2U= X-Received: by 2002:a05:600c:3595:b0:450:d3b9:4b96 with SMTP id 5b1f17b1804b1-454ec16919emr127146305e9.13.1752491166794; Mon, 14 Jul 2025 04:06:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4hWWRCIhYwp5qsZwNEkB88L2TJPp0XNC/cs+jyDqM1HHUm9IcT8wTpSwYRYADh9Im/hOKAg== X-Received: by 2002:a05:600c:3595:b0:450:d3b9:4b96 with SMTP id 5b1f17b1804b1-454ec16919emr127145955e9.13.1752491166272; Mon, 14 Jul 2025 04:06:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 45/77] i386/cpu: Drop CPUID 0x2 specific cache info in X86CPUState Date: Mon, 14 Jul 2025 13:03:34 +0200 Message-ID: <20250714110406.117772-46-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492845588116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu With the pre-defined cache model legacy_intel_cpuid2_cache_info, for X86CPUState there's no need to cache special cache information for CPUID 0x2 leaf. Drop the cache_info_cpuid2 field of X86CPUState and use the legacy_intel_cpuid2_cache_info directly. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 3 ++- target/i386/cpu.c | 31 +++++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a3ebd3e08ce..d3f7c53e301 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2077,7 +2077,8 @@ typedef struct CPUArchState { * on each CPUID leaf will be different, because we keep compatibility * with old QEMU versions. */ - CPUCaches cache_info_cpuid2, cache_info_cpuid4, cache_info_amd; + CPUCaches cache_info_cpuid4, cache_info_amd; + bool enable_legacy_cpuid2_cache; =20 /* MTRRs */ uint64_t mtrr_fixed[11]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 812e85b952f..ac22548f47d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -246,19 +246,27 @@ static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *= cache, bool *unmacthed) return CACHE_DESCRIPTOR_UNAVAILABLE; } =20 +static const CPUCaches legacy_intel_cpuid2_cache_info; + /* Encode cache info for CPUID[2] */ static void encode_cache_cpuid2(X86CPU *cpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { CPUX86State *env =3D &cpu->env; - CPUCaches *caches =3D &env->cache_info_cpuid2; + const CPUCaches *caches; int l1d, l1i, l2, l3; bool unmatched =3D false; =20 *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ *ebx =3D *ecx =3D *edx =3D 0; =20 + if (env->enable_legacy_cpuid2_cache) { + caches =3D &legacy_intel_cpuid2_cache_info; + } else { + caches =3D &env->cache_info_cpuid4; + } + l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); @@ -707,17 +715,6 @@ static CPUCacheInfo legacy_l2_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ -static CPUCacheInfo legacy_l2_cache_cpuid2 =3D { - .type =3D UNIFIED_CACHE, - .level =3D 2, - .size =3D 2 * MiB, - .line_size =3D 64, - .associativity =3D 8, - .share_level =3D CPU_TOPOLOGY_LEVEL_INVALID, -}; - - /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, @@ -8955,18 +8952,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) "CPU model '%s' doesn't support legacy-cache=3Doff"= , name); return; } - env->cache_info_cpuid2 =3D env->cache_info_cpuid4 =3D env->cache_i= nfo_amd =3D - *cache_info; + env->cache_info_cpuid4 =3D env->cache_info_amd =3D *cache_info; } else { /* Build legacy cache information */ - env->cache_info_cpuid2.l1d_cache =3D &legacy_l1d_cache; - env->cache_info_cpuid2.l1i_cache =3D &legacy_l1i_cache; if (!cpu->consistent_cache) { - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; - } else { - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache; + env->enable_legacy_cpuid2_cache =3D true; } - env->cache_info_cpuid2.l3_cache =3D &legacy_l3_cache; =20 env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; env->cache_info_cpuid4.l1i_cache =3D &legacy_l1i_cache; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492970; cv=none; d=zohomail.com; s=zohoarc; b=FNZ7PzOnXmnnsks895N1dZ3UglJB6W2nL51Lyjfy1yowbZREtK1gXWbNe6gkM5x7prTyz7g/ut1UfCjvLNHlzkG1vZNs0NsRd9lb2gnPXxw2PUobA2pzbmdeKmLyF+JailDajttxa3FW2Iqq3kVcARTHw6fxkPA6EcalSeMs43Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492970; 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=AjgJDMASZjcGOJV/vJO6lV99FBfJmaAIl4fEb4Kczgs=; b=QMq9XrnSocXe/8FLnPTw2j6O3ouhY0uyg2NJqFCJF+JshBrCudrPCX9apzEEo4vvEzQlDGiZ8RkeGQU2bRlnFLq319sVCOVB88Z7P7UZyJ11BbwkOWcsfdhradJv0YNHv5tcKXVVWJ0t8X2o82WP6FRBUct/MjHPoRsrddK3H08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492970389594.2024892806412; Mon, 14 Jul 2025 04:36:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHDd-0006Bx-UU; Mon, 14 Jul 2025 07:19:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0i-0001bL-Mv for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0f-000253-Iz for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:15 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-IVI1lenZMVi3dLRHIu8TdQ-1; Mon, 14 Jul 2025 07:06:11 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4eec544c6so1838672f8f.0 for ; Mon, 14 Jul 2025 04:06:11 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0dc3esm11976967f8f.47.2025.07.14.04.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491172; 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=AjgJDMASZjcGOJV/vJO6lV99FBfJmaAIl4fEb4Kczgs=; b=IydOuFEQ2a0EriszpFzOE6lMKCK/6RkyNhcSn4aHqoRBeoUx3CiyDHqdi9o+/dlD80CZ5k KI/aCIRTNlQII2IaVw+XBtjnM2bxNvLGIDzVU2QjWwRz9D93RxUCELlEvydoKtE4KZf2Kq VzgwqVPZEgeYj0YFqqEkjezeLCA9LWE= X-MC-Unique: IVI1lenZMVi3dLRHIu8TdQ-1 X-Mimecast-MFC-AGG-ID: IVI1lenZMVi3dLRHIu8TdQ_1752491170 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491170; x=1753095970; 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=AjgJDMASZjcGOJV/vJO6lV99FBfJmaAIl4fEb4Kczgs=; b=ucGkBbU+b9yTW9p8+ydWWrWWfG3IlNw9ZmWiGplmdGCEc8Zn6eZUI6YRJ52lw8D6W8 FYSV9cRAZwiD4u9r8C+68GJ9izMivxc7a9XWksfs/VVO1IhojsMc3veOekdcIttwVxlm 3B1BgSFunWM+Wtg7vSH8H/L5QfAx0IlnThhQgubHuFiLB2TTC4T7TIdZN8q3mCKULwLs iot/yk1v8sw/n5baB6kWB0pQ6g6ZakvwiYXzvUtQVs8WrGTMPl2u/+rbeqJBqmZdF/HS d5y9nd16RHepdqu0bhd6IPrRwEzNtXGfPphked/ZF4teOcYshE9zy2y6kELpNpYdXw4a /pGA== X-Gm-Message-State: AOJu0YycxFqBroBHL7NeBXzjLkJhdhMl3M7d8kSaxt+Q3TycUgra0QYM QkVRt+LwF89vAvncwXVI2HjnB9NtRgibGwF58tI2jFGtSDd5OMKHfWZWqDuQxArUH4TU3gzQAe6 y3o1l58IyzWBZACydttkfxTsSXg1bO8YzlAdC1FKQC9Qt90u3ebc87iZHh5EXZR+wk5ewTlNwtc vI7kYp70LnA6bvyGptQQGQ7FSOkx1qlVqa4WoPGPx8 X-Gm-Gg: ASbGncu+thPv870XslM9nBza0H0DPyk479py2Q6g76n37zo2eoJqtpdpYfjXcAcpWuL Gv3Mf8QC9PxkC+Yxbc8/xhMg+QOVcDOGXoKJioi6Gzx30Mc7Q7f0QquBLEnUOlpNQAVBAfKdjMZ 0IXB0Pq57g/lXnohHzQhBLEyKW8f9wqjnG1Gov6CgYhdBftk3KVhvTETjvSeb1AwQmDaUf4uSCf xL2FPxhg8v1IxM+H97E6mv1mTflse9KYg+7EjaJ12h2S1KeiIFFwZ+5bV3f1Qcp/0OGDuTfq8We JFfUxmrv0EngCHif/0BrRB9eBzdD7zhQ4t9x+OvY4Jg= X-Received: by 2002:a05:6000:2004:b0:3a5:1cc5:aa6f with SMTP id ffacd0b85a97d-3b5f18b3ecbmr11074738f8f.34.1752491169560; Mon, 14 Jul 2025 04:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI3avFznPtpSpEwF0WHFReGm7r1UBfMpshWt9tcKw+6HMy39a/n0KxsP61s9DC6iNSWxv4Tg== X-Received: by 2002:a05:6000:2004:b0:3a5:1cc5:aa6f with SMTP id ffacd0b85a97d-3b5f18b3ecbmr11074705f8f.34.1752491168878; Mon, 14 Jul 2025 04:06:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 46/77] i386/cpu: Add x-vendor-cpuid-only-v2 option for compatibility Date: Mon, 14 Jul 2025 13:03:35 +0200 Message-ID: <20250714110406.117772-47-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492971137116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Add a compat property "x-vendor-cpuid-only-v2" (for PC machine v10.0 and older) to keep the original behavior. This property will be used to adjust vendor specific CPUID fields. Make x-vendor-cpuid-only-v2 depend on x-vendor-cpuid-only. Although x-vendor-cpuid-only and v2 should be initernal only, QEMU doesn't support "internal" property. To avoid any other unexpected issues, check the dependency. Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-8-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 11 ++++++++++- hw/i386/pc.c | 1 + target/i386/cpu.c | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index d3f7c53e301..d88481ba8ec 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2282,9 +2282,18 @@ struct ArchCPU { /* Enable auto level-increase for all CPUID leaves */ bool full_cpuid_auto_level; =20 - /* Only advertise CPUID leaves defined by the vendor */ + /* + * Compatibility bits for old machine types (PC machine v6.0 and older= ). + * Only advertise CPUID leaves defined by the vendor. + */ bool vendor_cpuid_only; =20 + /* + * Compatibility bits for old machine types (PC machine v10.0 and olde= r). + * Only advertise CPUID leaves defined by the vendor. + */ + bool vendor_cpuid_only_v2; + /* Only advertise TOPOEXT features that AMD defines */ bool amd_topoext_features_only; =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index a6fa7923688..7cfa61c9ee6 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -83,6 +83,7 @@ =20 GlobalProperty pc_compat_10_0[] =3D { { TYPE_X86_CPU, "x-consistent-cache", "false" }, + { TYPE_X86_CPU, "x-vendor-cpuid-only-v2", "false" }, }; const size_t pc_compat_10_0_len =3D G_N_ELEMENTS(pc_compat_10_0); =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ac22548f47d..630a40d72be 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8749,6 +8749,16 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) tcg_cflags_set(cs, CF_PCREL); #endif =20 + /* + * x-vendor-cpuid-only and v2 should be initernal only. But + * QEMU doesn't support "internal" property. + */ + if (!cpu->vendor_cpuid_only && cpu->vendor_cpuid_only_v2) { + error_setg(errp, "x-vendor-cpuid-only-v2 property " + "depends on x-vendor-cpuid-only"); + return; + } + if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493403; cv=none; d=zohomail.com; s=zohoarc; b=jPF30ZA8+8lkCPNKFObX6cfgkTy1k+pHjM6t9chwxbH+BYu6WqQJoUmYQm5SEW6WDzrMpjoOa90EozumhmAMhvntMiG7j5xlJYOtKVHEOMSnGe3HkE8Xxa5UE2XrHjipkrZYPHZx+pj7xD4GhShcvd9HBBRvvp/fMNuXGQsx9X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493403; 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=9rIviJJiNhAaxQAmva2XsGdE6gnXLnG6PRcuZmt/cGY=; b=U0d9JzVK3/UIqItPAvBq+Uyb6DdC+OdNcYL2pfmCpg3U7wuL+z6m4WhIkWrhnxzO880CUrlbU13p+V/7dVw6Xa42WGDBw31Zl2BupIB+W0MBWopNeFvf+3DOqu1KVHbBfef5Qaajmxdb5AeRuitgew/4/ByA4mw8py2QAV2VaoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493403875198.42018736234854; Mon, 14 Jul 2025 04:43:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHSL-0003TG-FV; Mon, 14 Jul 2025 07:34:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0k-0001bw-G3 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0i-00025T-Ft for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:18 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-XC-OBO9ZNIS5O8aFJhmC5Q-1; Mon, 14 Jul 2025 07:06:14 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-455ea9cb0beso21445455e9.0 for ; Mon, 14 Jul 2025 04:06:13 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc2131sm11864434f8f.29.2025.07.14.04.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491175; 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=9rIviJJiNhAaxQAmva2XsGdE6gnXLnG6PRcuZmt/cGY=; b=VBt/Mw2JzB1nsfkRRWlIfCGlqEc6IvW+36Vw+MY3PyAhHUIJ+GgUTrT1AJ+Xa4aNdQo0IS p89jM/6YbKEBLdrTO1TpFzDPZFnkIYANg9nmfI7gNvAbSVYgTXXvr4Y13dhu16NOo5nLj5 gD26EQmx5TVodw50rSk3lmEQF5lRZvE= X-MC-Unique: XC-OBO9ZNIS5O8aFJhmC5Q-1 X-Mimecast-MFC-AGG-ID: XC-OBO9ZNIS5O8aFJhmC5Q_1752491173 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491172; x=1753095972; 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=9rIviJJiNhAaxQAmva2XsGdE6gnXLnG6PRcuZmt/cGY=; b=H9M72ZRSI/zSUhZSssM68xO6aZ2mntXACsJ0b2rBJDuWqQQEo9fhKzs5ahwBr7MwEa /JSTV3XcDlHLLnUhZllwTZKcVBMqRaWKPefFF7XhCxn0ZQx3uPOjz0XZnp4ZX/OGumLf M/MISrbUpsmWkZ9sPaEixw2Ny47VodhnF49ylEkEkAsDZXsOgYuw/Fie7mefG5QNipZ/ 1Tlabd5a9YGsx9QBicXBfkOvWGiTT2lPKFaetag7kUnK4tAlWgKhlcuIyG5Ga5S+4XMM zF2C1cxK2M6tQMnsk2+qxmsobmSa2/uiFfWTAEdOddg8tlW13btDMZqmjcRk2qFdhf6i 7VzQ== X-Gm-Message-State: AOJu0YxevKTfIEjQ+Q8wSycdu8rCcaoblv/15iZfZUltBqESoYxuRChr sOZPgYG6S3Qq9vC8Nw4pJJ2CgVwkTi2OvMhMwpNY7mY7RQT6XnPfK/s/0Oyxav27ElC1M0pEB6/ MHbiWRyCH0RPyxNvLhfre0dCoV6onaQFHiRZybGST9TBwqxg478J9fTV1/TGtlfmnLB92Nqeobh RuMTV8ntSWmkF+7ZxpTTSlhejMNCY6kgo56TNgn+7N X-Gm-Gg: ASbGncvr1v4h9EHztbB/7Ff97cJ2xDTJejSIT+i/+vIi2fvj7G2QB3zROamCWZmHSJU QUdJwUSncPcE5PfnxQvldvwe1e6FBM5+CUEX/nsDR2ZzQgfesIu9nXEBkNpLVRqSsek0AB+vUaD LA7+9sNUvqI6ng0Hk8frvRm6uAftTlMgNo2pgC3VovdwmGBAHgTLuQxN2RIsfVKECpgb648GByA QSJydo4zdnQ55dT16iA8MA2u8dSpUR+ZeiusEpTQeCryUPrbFEc073NQMBRKQgu1REaS/WZwBcf XfZiY8dKF1lLU1GPk3z+psFjE6/DXtdsFHlbyPl+SGg= X-Received: by 2002:a05:600c:1da7:b0:456:1b8b:b8c6 with SMTP id 5b1f17b1804b1-4561b8bbbf3mr27417235e9.14.1752491171926; Mon, 14 Jul 2025 04:06:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzZwsANSptTigDo6JPnjSG8BVa/qdPOxY9LPt6ZVFYEMHq48AF5379W2T4eUTYtBB3gPqnkQ== X-Received: by 2002:a05:600c:1da7:b0:456:1b8b:b8c6 with SMTP id 5b1f17b1804b1-4561b8bbbf3mr27416765e9.14.1752491171311; Mon, 14 Jul 2025 04:06:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 47/77] i386/cpu: Mark CPUID[0x80000005] as reserved for Intel Date: Mon, 14 Jul 2025 13:03:36 +0200 Message-ID: <20250714110406.117772-48-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493406084116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, 0x80000005 leaf is reserved for Intel CPU, and its current "assert" check blocks adding new cache model for non-AMD CPUs. And please note, although Zhaoxin mostly follows Intel behavior, this leaf is an exception [1]. So, with the compat property "x-vendor-cpuid-only-v2", for the machine since v10.1, check the vendor and encode this leaf as all-0 only for Intel CPU. In addition, drop lines_per_tag assertion in encode_cache_cpuid80000005(), since Zhaoxin will use legacy Intel cache model in this leaf - which doesn't have this field. This fix also resolves 2 FIXMEs of legacy_l1d_cache_amd and legacy_l1i_cache_amd: /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ In addition, per AMD's APM, update the comment of CPUID[0x80000005]. [1]: https://lore.kernel.org/qemu-devel/fa16f7a8-4917-4731-9d9f-7d4c1097716= 8@zhaoxin.com/ Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-9-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 630a40d72be..2abcb5acffc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -499,7 +499,6 @@ static void encode_topo_cpuid1f(CPUX86State *env, uint3= 2_t count, static uint32_t encode_cache_cpuid80000005(CPUCacheInfo *cache) { assert(cache->size % 1024 =3D=3D 0); - assert(cache->lines_per_tag > 0); assert(cache->associativity > 0); assert(cache->line_size > 0); return ((cache->size / 1024) << 24) | (cache->associativity << 16) | @@ -657,7 +656,6 @@ static CPUCacheInfo legacy_l1d_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l1d_cache_amd =3D { .type =3D DATA_CACHE, .level =3D 1, @@ -686,7 +684,6 @@ static CPUCacheInfo legacy_l1i_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l1i_cache_amd =3D { .type =3D INSTRUCTION_CACHE, .level =3D 1, @@ -7884,11 +7881,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D env->cpuid_model[(index - 0x80000002) * 4 + 3]; break; case 0x80000005: - /* cache info (L1 cache) */ + /* cache info (L1 cache/TLB Associativity Field) */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } + + if (cpu->vendor_cpuid_only_v2 && IS_INTEL_CPU(env)) { + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + break; + } + *eax =3D (L1_DTLB_2M_ASSOC << 24) | (L1_DTLB_2M_ENTRIES << 16) | (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx =3D (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | @@ -9478,6 +9481,7 @@ static const Property x86_cpu_properties[] =3D { DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor), DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true), DEFINE_PROP_BOOL("x-vendor-cpuid-only", X86CPU, vendor_cpuid_only, tru= e), + DEFINE_PROP_BOOL("x-vendor-cpuid-only-v2", X86CPU, vendor_cpuid_only_v= 2, true), DEFINE_PROP_BOOL("x-amd-topoext-features-only", X86CPU, amd_topoext_fe= atures_only, true), DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false), DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true), --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493556; cv=none; d=zohomail.com; s=zohoarc; b=hzqO95JURD0uDa1vERig0JjBMfz91bUJ6Pt3cO4r/6qfyfHzjCz4uvzqFvPIw4AIoi14t+X+Xi7LE2RhG4ibw0I1ku9ZESFwAUEdiWA6LWTDCb7u5Kx7WFV3a+3wNrf1kMnhBHlkBMW1e/fdXGpY9MLBRqOUJlKb0ADtos7E8lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493556; 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=zWXeFYYxE013tWhjiyA4F7SmPG5yy1BXn+V7I3G9oQY=; b=XKsS1SKv1McR3bbkuMgdtXWbV+GV2KudwpxxlBRYETu1ViMM6u9xpxKFxbZtDuCdgouqZ/8/1BmB4SwNd6hN896lMIAETRCXIPYVlKOCXupIuMO9Idg5vE8/nXXcXe4cBOSgBIM0CmeHmkzrfY7sbJPes4j2QwmBDR4SFaWSLls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493556174695.3191906048544; Mon, 14 Jul 2025 04:45:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHTK-0004HA-Tb; Mon, 14 Jul 2025 07:35:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0m-0001cZ-UU for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0k-00025h-Os for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:20 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571-iceFfvbDMsGiHGiNxJ8g-w-1; Mon, 14 Jul 2025 07:06:16 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-456013b59c1so11253785e9.3 for ; Mon, 14 Jul 2025 04:06:16 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561323a488sm46989245e9.1.2025.07.14.04.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491177; 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=zWXeFYYxE013tWhjiyA4F7SmPG5yy1BXn+V7I3G9oQY=; b=F963hiBZEEqijdkz0RINxHsEy3+VX14fR4LbTsRJE9saplQvRI4+FDZY+lJ+96drX3S0N6 74McoR5idZ/jUk4el/7hnhlRJrIC8LEtMYMu8aieepUkYilj3wdZ0z0F3U2pBkRMI45VGt +cHqK3Vf6DfycBFKgLvcwkkLvKyzeyc= X-MC-Unique: iceFfvbDMsGiHGiNxJ8g-w-1 X-Mimecast-MFC-AGG-ID: iceFfvbDMsGiHGiNxJ8g-w_1752491176 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491174; x=1753095974; 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=zWXeFYYxE013tWhjiyA4F7SmPG5yy1BXn+V7I3G9oQY=; b=OJC2s3SkpbOaZXl696uVK1Afva/SaPQ7P4qFAp8YvR9cTyQJjUdAsCqCb8bs68+RS+ DNTHxqdKBwDE+jTppXR4goPSBPUTpm11NpooYafk+dhDtHbunycdT4KYuLNe15+XyqEL VmWxX2ikK+rgrBukjYWMw1l4zq2wxFZ4g3+WyuN1ZkS5D8zEDhB5cPp27MsvdkM/fDV3 84oSmEsqE+DZQYHbw/H4N8a+k9vO6Zsq7pvUtaGZWWmqpByIzoI62Jxr4WI8rY0699Uz mZc1MefPF3ddEDF5kFZM/pX9eE1xc0Q1a7gxkRQZ044paHsCgU1+y2ff3MbrdnTk5VPC /3Zg== X-Gm-Message-State: AOJu0Yy29mJtwzFZj9ethnD1r9dZiE7hawDlMNHA612DxxzjExCOQmUx 9WDFS0cbQFmAPqYVZrSGCPG1MHWQaSk8DuS7Eyac4MLkExEyFu2wCdY+Z2VgOiT3qFsjg5Bvroc QV2XuqmGkbAk13lfjrnsBNqoMrOB+IESNkYV4Iy/EWm28kvD5h4z7XKGGdkxgVG6cEjlnX+Dgb3 YMvDJ0xPAHKO5R8Lseui8sZXplBp+FBJW/wEGTopoG X-Gm-Gg: ASbGncsZfxddxIAxiPpmTU/IKbua5FiZ4cB10CI8pBufyIBgc0oPVeTDVPWxAj2MU1o MN78uqQxpiK/Lu2GCgEM6sH9/kwTDLJmTcyutUwjRrZ8nDQy5ZyiWp/mQzXp4NjXL/5c1ayJZCT 7PG5r90xPyMR6vwTTpw/8PDwwGT6q5LK/lEcFSVX0PrLug9LrEazYq4RdxoPnNS61wMuUj8f8Yd 5+TMjQLYDtqjnWqItB2TNFG3IIcfou1Jn4UtR+6dOUe+JRRbcPbp/+OBZOfCK0XtSIp1mMvHDyT nVpIqxINuyJdo1HING5AzTYy7vrML2oIVnf7OsF7kKs= X-Received: by 2002:a05:600c:3481:b0:456:1442:86e with SMTP id 5b1f17b1804b1-45614420b46mr36818705e9.21.1752491174441; Mon, 14 Jul 2025 04:06:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHruzOdOb2oWIjoxWZlHmbzlpnwdHPoN2U6OGf2d8NF/5PHD++Fv5vqWVc2xHpWoyY0JRWaLw== X-Received: by 2002:a05:600c:3481:b0:456:1442:86e with SMTP id 5b1f17b1804b1-45614420b46mr36818345e9.21.1752491173829; Mon, 14 Jul 2025 04:06:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 48/77] i386/cpu: Rename AMD_ENC_ASSOC to X86_ENC_ASSOC Date: Mon, 14 Jul 2025 13:03:37 +0200 Message-ID: <20250714110406.117772-49-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493561640116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Rename AMD_ENC_ASSOC to X86_ENC_ASSOC since Intel also uses the same rules. While there are some slight differences between the rules in AMD APM v4.07 no.40332 and Intel. But considerring the needs of current QEMU, generally they are consistent and current AMD_ENC_ASSOC can be applied for Intel CPUs.. Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-10-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2abcb5acffc..8a97272b4a4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -507,8 +507,8 @@ static uint32_t encode_cache_cpuid80000005(CPUCacheInfo= *cache) =20 #define ASSOC_FULL 0xFF =20 -/* AMD associativity encoding used on CPUID Leaf 0x80000006: */ -#define AMD_ENC_ASSOC(a) (a <=3D 1 ? a : \ +/* x86 associativity encoding used on CPUID Leaf 0x80000006: */ +#define X86_ENC_ASSOC(a) (a <=3D 1 ? a : \ a =3D=3D 2 ? 0x2 : \ a =3D=3D 4 ? 0x4 : \ a =3D=3D 8 ? 0x6 : \ @@ -534,7 +534,7 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, assert(l2->lines_per_tag > 0); assert(l2->line_size > 0); *ecx =3D ((l2->size / 1024) << 16) | - (AMD_ENC_ASSOC(l2->associativity) << 12) | + (X86_ENC_ASSOC(l2->associativity) << 12) | (l2->lines_per_tag << 8) | (l2->line_size); =20 if (l3) { @@ -543,7 +543,7 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, assert(l3->lines_per_tag > 0); assert(l3->line_size > 0); *edx =3D ((l3->size / (512 * 1024)) << 18) | - (AMD_ENC_ASSOC(l3->associativity) << 12) | + (X86_ENC_ASSOC(l3->associativity) << 12) | (l3->lines_per_tag << 8) | (l3->line_size); } else { *edx =3D 0; @@ -7905,13 +7905,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } - *eax =3D (AMD_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | + *eax =3D (X86_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | (L2_DTLB_2M_ENTRIES << 16) | - (AMD_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | + (X86_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | (L2_ITLB_2M_ENTRIES); - *ebx =3D (AMD_ENC_ASSOC(L2_DTLB_4K_ASSOC) << 28) | + *ebx =3D (X86_ENC_ASSOC(L2_DTLB_4K_ASSOC) << 28) | (L2_DTLB_4K_ENTRIES << 16) | - (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | + (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, cpu->enable_l3_cache ? --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493017; cv=none; d=zohomail.com; s=zohoarc; b=e5x8bPkW3g0WKfErVNyzMVZvJyAW93mhwtbyUSzncJXbuoFhVWNQRqm5d376yNn1RE45UTd2rKhKAINom4h6ZuUAdGY7DJWOqz+PeNJ613z+/Jqqu4f9ZXgCnA/l+tIYd0paE+j5Y4eC1HVMeSlyuqs48PikSrAgO2eT2HalFk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493017; 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=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=K4mHOM9f/bw6xLhHYBjgIvtoLeWbtpEcUbAUqq/Wyj4S2LSStXnCP/IeIul35XAyCsOfpcWAxGzhBaM37m3c7sEEmdyYijYbtkAPIlBMrvpS5pqf/3Ol//INWgTPWz+cJCrAHdpB3CMB+GJKQXN7lIroOVtvJyQ7sGbhFw7MmG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493017387306.304511790107; Mon, 14 Jul 2025 04:36:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEO-0007Cm-8m; Mon, 14 Jul 2025 07:20:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH11-0001in-5P for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0s-00026P-Rh for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:29 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-ysrjcmqvO3e1xg46t3hN3Q-1; Mon, 14 Jul 2025 07:06:20 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4839705e9.1 for ; Mon, 14 Jul 2025 04:06:19 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45613c2d84dsm45545515e9.5.2025.07.14.04.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491184; 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=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=eK1po8i6QpcX18ckJLdPz4w4hSKQH6c20ghbFrUwOfGPAWAfupMu80IodAtOPXg0PXZXOS bRPKHRkKgBLR8ZxoIPTAAKwrxxrCAwbndv0N6hKn8ez7gbGEvg3FAfmaWwQrRhuV+2uN3X 8P37UD7g/PNeaIeV76XKtY6019rB5bk= X-MC-Unique: ysrjcmqvO3e1xg46t3hN3Q-1 X-Mimecast-MFC-AGG-ID: ysrjcmqvO3e1xg46t3hN3Q_1752491178 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491177; x=1753095977; 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=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=FXNP6p7SEPuguEBYTgROouZh9BTyj4hYEQMmooNi2emRWCN8q+kUbR/6h+vFEPyOqI pwZvLlVhBI/SIBizr2ElzqK7TCL8ZPpBW207+leXOfuu4q6t8TCFD91g7nhdBwcNmjrV j0wd7VVNR8MDFi5aLvZaqjT41b3SXkhsB6ocJeU84HXShBOi1A38W0VqWnG8mJod4mfS irPPuKaMYNVmkPSJ2e3iW7ypaRp0cnKFMpp1Avu78J26GftyyKR8san5LuG6TGMGRZvN TuShi1InzS+LSTBYxaD0BCseD54BN+KSQGK/5s/xOWzuML9LWArh6LuppHlum2rDRar7 nhYw== X-Gm-Message-State: AOJu0Yx7yFkoQ4XZ9d1xJX9Wgo9bF2u7II0uajXojOG8n+9GyDc4QjaN R/yg6V9HdJ0zCL3QQbJf9Pz1jFxK85r1OgGE6m/eWNmrqkSwjU4oc4aXG0jUAezj6Az+m/LN/gp 7luhmrNK3rIaUuk4FdwV2IMEID197dQuC+1lBn+Qf7KiiRjBhNJt2pSBkEV0XmGzYLYwxXZ1LVe 1CU6jdn7L/hlFX5wGCGdOHhpyVdXxSHDtXtpFfRPgU X-Gm-Gg: ASbGncuIIeDUFaAEA7l0PFBxh29gAoV9cnLORBZMGy/CFX4kC2qxsPOK7Jnr3HyxfBT UeIGQk3eF8tfiScbOIZw3TmGzI9GJBS4Tv2OVuJhdvT+6KPrJBRKyYn2V5pgSLCYgYAOu4d5Kr9 cYy0lgn/DkW+aI4hZDB6mqXXOxdOUjLkIoIlKNpPvcATd0AkqI/ySdcxfJgvCrJ7yYiu8J03uGB qdcLGJvjGSGAem+iedqdIibdB3CIxgSkcWMcaS62pLS0ImDYpQ3FN99Gwb1kTHjs0pO8rySTv7k JbMc3awe1Zn2M9PySztXA1t8OFjx4/O21M9m3A9FDtI= X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76235725e9.33.1752491177130; Mon, 14 Jul 2025 04:06:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZhdZw6QvFPipKgiclRUgJCtpW3ES2Ctlo2UUOorliEWEfdM/2KvJu6PhJjAEec3UBxHNY7Q== X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76235485e9.33.1752491176571; Mon, 14 Jul 2025 04:06:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 49/77] i386/cpu: Fix CPUID[0x80000006] for Intel CPU Date: Mon, 14 Jul 2025 13:03:38 +0200 Message-ID: <20250714110406.117772-50-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493017828116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, Intel supports CPUID[0x80000006]. But only L2 information is encoded in ECX (note that L2 associativity field encodings rules consistent with AMD are used), all other fields are reserved. Therefore, make the following changes to CPUID[0x80000006]: * Check the vendor in CPUID[0x80000006] and just encode L2 to ECX for Intel. * Drop the lines_per_tag assertion, since AMD supports this field but Intel doesn't. And this field can be easily checked via cpuid tool in Guest. * Apply the encoding change of Intel for Zhaoxin as well [1]. This fix also resolves the FIXME of legacy_l2_cache_amd: /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ In addition, per AMD's APM, update the comment of CPUID[0x80000006]. [1]: https://lore.kernel.org/qemu-devel/c522ebb5-04d5-49c6-9ad8-d755b899898= 8@zhaoxin.com/ Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-11-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8a97272b4a4..6a0e8592bbe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -531,16 +531,15 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *= l2, { assert(l2->size % 1024 =3D=3D 0); assert(l2->associativity > 0); - assert(l2->lines_per_tag > 0); assert(l2->line_size > 0); *ecx =3D ((l2->size / 1024) << 16) | (X86_ENC_ASSOC(l2->associativity) << 12) | (l2->lines_per_tag << 8) | (l2->line_size); =20 + /* For Intel, EDX is reserved. */ if (l3) { assert(l3->size % (512 * 1024) =3D=3D 0); assert(l3->associativity > 0); - assert(l3->lines_per_tag > 0); assert(l3->line_size > 0); *edx =3D ((l3->size / (512 * 1024)) << 18) | (X86_ENC_ASSOC(l3->associativity) << 12) | @@ -712,7 +711,6 @@ static CPUCacheInfo legacy_l2_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, @@ -7900,11 +7898,20 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); break; case 0x80000006: - /* cache info (L2 cache) */ + /* cache info (L2 cache/TLB/L3 cache) */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } + + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *eax =3D *ebx =3D 0; + encode_cache_cpuid80000006(env->cache_info_cpuid4.l2_cache, + NULL, ecx, edx); + break; + } + *eax =3D (X86_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | (L2_DTLB_2M_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | @@ -7913,6 +7920,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); + encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, cpu->enable_l3_cache ? env->cache_info_amd.l3_cache : NULL, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492332; cv=none; d=zohomail.com; s=zohoarc; b=d8XXVmUUvy7egbd7ue282Oxd+1bJB2iZLtY9nzYv9G4nmgEmWU2YxGCfORLnlR1ZQueTC/arNxkzLaXmJwK2FQsWC35kOU+RU26vPV+ZzkgQVWR58D2EU+Hbn3rBWgdsYaunN8WaUyC3MGKVldyN+5zT+p19GAH79EYCPPcUBGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492332; 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=thCWbzpn9tuIPYHaAUoFp+onJN6KsKkVNOqqjaM55Rk=; b=VHYso0vaB9KW64KgQa1eGetwj33ptSBavG5drZTe4xWVl/fM9zlGYnSnom3wQJEYp7wYueYXVuwxLaY1GmlV+ddeT5yth7FgzoRaS9zX8UNum2az4ANx7D68UsbaFrrMu9mAsk1OfmI6oXZfOV/7530Th1eNMxZfAJoS9HdDuO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 1752492332641356.1365137803275; Mon, 14 Jul 2025 04:25:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHDr-0006ZL-09; Mon, 14 Jul 2025 07:19:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0q-0001fm-Va for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0o-000263-QZ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:24 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-diUf87Y5MS-InqGVf24TBg-1; Mon, 14 Jul 2025 07:06:20 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451d2037f1eso27401095e9.0 for ; Mon, 14 Jul 2025 04:06:20 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4560f844c2dsm57366755e9.0.2025.07.14.04.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491182; 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=thCWbzpn9tuIPYHaAUoFp+onJN6KsKkVNOqqjaM55Rk=; b=gSn28D1CC84Nqfb3bZ+jMxCrYpSNbDMKs2coTrGbGBqeSKXADOEv11BYD/mlQrCsx5lygw hF7CP6w3vXU2RkGfrcM+QOSDnm6NWyyll7dtMHUau3kOji8VOLnSkFJXAOjETxFB0g750B 2X06xpbhzmHrm4YzyZsTWmfTBtr7Tw8= X-MC-Unique: diUf87Y5MS-InqGVf24TBg-1 X-Mimecast-MFC-AGG-ID: diUf87Y5MS-InqGVf24TBg_1752491180 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491178; x=1753095978; 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=thCWbzpn9tuIPYHaAUoFp+onJN6KsKkVNOqqjaM55Rk=; b=HSim5prEJuSalNjAtoiqmrRpKfqhhgsDruwLPpinuYRumkdBE8ZXn4gjiA5EqW09je bYQCNxBbD/31nFKas7FHM7LwKYTCcg1RTxWrATyTchZwvVXdwrjOykc2YgegKUSf5LZn nNkB0kkJJZR2q98JK9D1iYUoyKY3ohYLZpQUqhd/uFp31iN7HeWbwwq8EFuByqEYEVzM ja31rOJV8vzEdC6GZBD2qZ9rg5vQZ28x+iHjVkBko7rpC6L3du+vYtuMoJAATUwRAFwF 0a+zGhuEpQMMTZqgDQ18SBp3awy85wM0FoLDMbNXZRw5A9M7BDU8icgRbG8s+0w8pEhD 8t5Q== X-Gm-Message-State: AOJu0YwXsHQEqE9PrEWG7ILBzpd1VHyX6bFvAnV+A6KIUoj6bBZEXOh0 WVydHMtTKcrk4EyXu7DhL+ZfQNyenDZaalX4zAJWi2sKf9XWPFYwakhCRBYgJsRZ4hl22YdHk7q b/+Im6c1TquiNFU5GhuNI8ifes3xxoSvTURhehibQXAIkceQw/oJ3zDo1Obj+RNLWbn3JpWpJ+x GI0VzEGrTL9n+F8cF67ji5KmR4AZnAyh7YjWZ3tif8 X-Gm-Gg: ASbGncs0bDOMTgzjtwqSnSeutQdqFx1bD6PaZWJ0C67XLQNB8e+r/Vs9/pO09lj/CcQ cfxAaMBaLdFHyswsO6YWNNYqwasm4+Jlfq+UMzjFhwUrfLhvY7E3bps0ueLiXludKfpdwqVt7gL nAGWZ7doiiTVNPxnI2NDj7cJsDzBKWYMdK6vNqBXXvo6ZOQG+A1lxtcdZwBRorGsMMCek8Si1tu 8uzlFy+E5CVk7ioAd7vqugahMcHlL6BBoiatg8U9rxIgZERCiFW5ZQvezStdC3U1Li0MbTRDS7Z 5cANS8hwQQnFsn42cP2Euuu0vuscsItuZjiYNNKt2eo= X-Received: by 2002:a05:6000:2884:b0:3a5:2c18:b181 with SMTP id ffacd0b85a97d-3b5f2e3a02bmr8888230f8f.53.1752491178469; Mon, 14 Jul 2025 04:06:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNVX7zC3TllamP4vaK0OHrsMzqq6pSljcEdTSRvt/3fSxaZFDlk3q5MtCBqZ0+yf43Igl0Yw== X-Received: by 2002:a05:6000:2884:b0:3a5:2c18:b181 with SMTP id ffacd0b85a97d-3b5f2e3a02bmr8888197f8f.53.1752491177915; Mon, 14 Jul 2025 04:06:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 50/77] i386/cpu: Add legacy_intel_cache_info cache model Date: Mon, 14 Jul 2025 13:03:39 +0200 Message-ID: <20250714110406.117772-51-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492334352116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Based on legacy_l1d_cache, legacy_l1i_cache, legacy_l2_cache and legacy_l3_cache, build a complete legacy intel cache model, which can clarify the purpose of these trivial legacy cache models, simplify the initialization of cache info in X86CPUState, and make it easier to handle compatibility later. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-12-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 101 +++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6a0e8592bbe..d265dc81563 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -640,21 +640,6 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X86= CPUTopoInfo *topo_info, * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs */ - -/* L1 data cache: */ -static CPUCacheInfo legacy_l1d_cache =3D { - .type =3D DATA_CACHE, - .level =3D 1, - .size =3D 32 * KiB, - .self_init =3D 1, - .line_size =3D 64, - .associativity =3D 8, - .sets =3D 64, - .partitions =3D 1, - .no_invd_sharing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l1d_cache_amd =3D { .type =3D DATA_CACHE, .level =3D 1, @@ -669,20 +654,6 @@ static CPUCacheInfo legacy_l1d_cache_amd =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/* L1 instruction cache: */ -static CPUCacheInfo legacy_l1i_cache =3D { - .type =3D INSTRUCTION_CACHE, - .level =3D 1, - .size =3D 32 * KiB, - .self_init =3D 1, - .line_size =3D 64, - .associativity =3D 8, - .sets =3D 64, - .partitions =3D 1, - .no_invd_sharing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l1i_cache_amd =3D { .type =3D INSTRUCTION_CACHE, .level =3D 1, @@ -697,20 +668,6 @@ static CPUCacheInfo legacy_l1i_cache_amd =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/* Level 2 unified cache: */ -static CPUCacheInfo legacy_l2_cache =3D { - .type =3D UNIFIED_CACHE, - .level =3D 2, - .size =3D 4 * MiB, - .self_init =3D 1, - .line_size =3D 64, - .associativity =3D 16, - .sets =3D 4096, - .partitions =3D 1, - .no_invd_sharing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, @@ -800,6 +757,59 @@ static const CPUCaches legacy_intel_cpuid2_cache_info = =3D { }, }; =20 +static const CPUCaches legacy_intel_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 4 * MiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 4096, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 3, + .size =3D 16 * MiB, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 16384, + .partitions =3D 1, + .lines_per_tag =3D 1, + .self_init =3D true, + .inclusive =3D true, + .complex_indexing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, +}; + /* TLB definitions: */ =20 #define L1_DTLB_2M_ASSOC 1 @@ -8980,10 +8990,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) env->enable_legacy_cpuid2_cache =3D true; } =20 - env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; - env->cache_info_cpuid4.l1i_cache =3D &legacy_l1i_cache; - env->cache_info_cpuid4.l2_cache =3D &legacy_l2_cache; - env->cache_info_cpuid4.l3_cache =3D &legacy_l3_cache; + env->cache_info_cpuid4 =3D legacy_intel_cache_info; =20 env->cache_info_amd.l1d_cache =3D &legacy_l1d_cache_amd; env->cache_info_amd.l1i_cache =3D &legacy_l1i_cache_amd; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493479; cv=none; d=zohomail.com; s=zohoarc; b=dhtqQdtm1MCVaO+voGHh4qPJ4cufaCxxLzt+75fxpHNOf6msXzvmokenoOBayrTvn70FQSKtDvTnI3VSakH5NpEU5paU3a7BL3RXcTE7snr3utRXAA/nqMC6xYoN6a+rd6JYjuZxi1Xpj96AfesDFyyTP8/l1zagvofKllQroK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493479; 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=e5PG1jUF16fEsfrFUJ9a6f+CrhyoIvlt8q9EtqbOgag=; b=UoSG/qG6/NZoThCX7cZ7V4cusPl8bbzg7Ts3yp3UOhmcIdUS8mEZjCjUNK2+AoE48tMACQrGUYEn3pitXwpCidvsSShebct+g2u5SThcCrwwpxitvMVKyxBa+w5kDdeYwwY4nl1d5FhkAE3iOyruIR+J02uLYkqTU4pV4zjtRl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493479417891.892028178363; Mon, 14 Jul 2025 04:44:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHTb-0004zl-6Z; Mon, 14 Jul 2025 07:36:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH11-0001io-5L for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0t-00026h-5O for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:32 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-Qgi-9WzpOm6B2R5VhbAS3Q-1; Mon, 14 Jul 2025 07:06:23 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a503f28b09so2705862f8f.0 for ; Mon, 14 Jul 2025 04:06:23 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e285sm11946507f8f.76.2025.07.14.04.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491184; 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=e5PG1jUF16fEsfrFUJ9a6f+CrhyoIvlt8q9EtqbOgag=; b=D1rR8X1Tdkjt5p6/gvrM0/8pgr6UI007i9zGeHKmISUsNRQWjDU8lBzs0VXsCL2B9MbS7E YZfbrdHAj8shESkZ+IUJUKuYSWaKZ+zhpbO9Pq/cBiW88o4DRl4uUre3s4GY5FVMRduuPF X7OWJqcS4BdS7dQska/S/9IFiQdbPEo= X-MC-Unique: Qgi-9WzpOm6B2R5VhbAS3Q-1 X-Mimecast-MFC-AGG-ID: Qgi-9WzpOm6B2R5VhbAS3Q_1752491182 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491181; x=1753095981; 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=e5PG1jUF16fEsfrFUJ9a6f+CrhyoIvlt8q9EtqbOgag=; b=FkesiG05JF0+vOC3/5K9f5lsYgEoYlw5P4UH5X7d4J5kvRfwT2IYhiDiA08LSXe7rf ugnSvIRTbxPori6L+DRlAOjDru8BzuXv03zUGD5po3ktknGEJ2OQLOYqWW6sYqJ+6lwx 6DHvY65HkN80FtP/xJQoKl262ZRTclV0/OJ6tkwHUPa/IJ+LukMoo7BMnl+v66Aj/DTi l61ycFA6lqOsTTNCbM3L8huZjqHU5FhAbC27EhH+dZYa9RzG+VZlwJAN4xLyIS0pehyc kG9cU0Kpr5MPnz3uaE6j0qN+vpcWKqzPVPTAM63fdishasdi99AEnLoymp4Yur7dVjhC F9QA== X-Gm-Message-State: AOJu0YzMkFlH7UDCJfQuIZdiJ71PyQfSUFrrPPtEFJ+Z20Edmfj+7wp9 hSuj2aV3RQtueH2EjIME8O62ZvO2Gi3+dycKIOmtGtHTC2w1oL7vXQ1ibA3hzT/UavuoVWMGqi4 yMvaesLfk6uTqCmQgE0qNx8/TXUMXfOZIbtedAstI4GAa7vwhAqf9EWg+zioPQd3DjA883vNdtb e8EoLyMiSHKtYybMeyTzeGnU8ILxv9zNqymIwW91JH X-Gm-Gg: ASbGncuDGRAsQw2QULrBLfPbQLX9iHwa7T9vXy7SqZlCZxEgrbmnmGPqL+dqFFA2/V+ EYZCHpnNsyZdiXG4vncC6FWlRl+FYbrv1HCREjqn3VxVC7i8O2dtkg1AoAXCP+jBzqQNJHZskIo kUrb4PtRQhN1xwJi7dtvV9PZhY/muu7Lwl9kUsXnOrroPm2z46BUz1EoZHvzd+UqP7kz4+nflca trfSOfJHw/oR85jOlr/mC5oKzp8oBbva2zu6MEZtZgH5aNNE08YI0J6+bvF8mNT/Goe4Hghzdov wml8/cwnz59DaHRTNlcieEWHUB/qw2X3Lspk13Dq/lc= X-Received: by 2002:a5d:5d85:0:b0:3b5:f6f9:e803 with SMTP id ffacd0b85a97d-3b5f6f9e812mr8051394f8f.14.1752491181141; Mon, 14 Jul 2025 04:06:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3ufuEwfxJQ0v8ZKiVpw7HEJ9R+h/x+rD/MLQaVKNrkJpRbm35nGRWyOLs3VBb/xOiWR351Q== X-Received: by 2002:a5d:5d85:0:b0:3b5:f6f9:e803 with SMTP id ffacd0b85a97d-3b5f6f9e812mr8051359f8f.14.1752491180557; Mon, 14 Jul 2025 04:06:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 51/77] i386/cpu: Add legacy_amd_cache_info cache model Date: Mon, 14 Jul 2025 13:03:40 +0200 Message-ID: <20250714110406.117772-52-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493481152116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Based on legacy_l1d_cachei_amd, legacy_l1i_cache_amd, legacy_l2_cache_amd and legacy_l3_cache, build a complete legacy AMD cache model, which can clarify the purpose of these trivial legacy cache models, simplify the initialization of cache info in X86CPUState, and make it easier to handle compatibility later. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-13-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 112 ++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d265dc81563..92d21ce64c3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -640,60 +640,58 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X8= 6CPUTopoInfo *topo_info, * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs */ -static CPUCacheInfo legacy_l1d_cache_amd =3D { - .type =3D DATA_CACHE, - .level =3D 1, - .size =3D 64 * KiB, - .self_init =3D 1, - .line_size =3D 64, - .associativity =3D 2, - .sets =3D 512, - .partitions =3D 1, - .lines_per_tag =3D 1, - .no_invd_sharing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -static CPUCacheInfo legacy_l1i_cache_amd =3D { - .type =3D INSTRUCTION_CACHE, - .level =3D 1, - .size =3D 64 * KiB, - .self_init =3D 1, - .line_size =3D 64, - .associativity =3D 2, - .sets =3D 512, - .partitions =3D 1, - .lines_per_tag =3D 1, - .no_invd_sharing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -static CPUCacheInfo legacy_l2_cache_amd =3D { - .type =3D UNIFIED_CACHE, - .level =3D 2, - .size =3D 512 * KiB, - .line_size =3D 64, - .lines_per_tag =3D 1, - .associativity =3D 16, - .sets =3D 512, - .partitions =3D 1, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -/* Level 3 unified cache: */ -static CPUCacheInfo legacy_l3_cache =3D { - .type =3D UNIFIED_CACHE, - .level =3D 3, - .size =3D 16 * MiB, - .line_size =3D 64, - .associativity =3D 16, - .sets =3D 16384, - .partitions =3D 1, - .lines_per_tag =3D 1, - .self_init =3D true, - .inclusive =3D true, - .complex_indexing =3D true, - .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, +static const CPUCaches legacy_amd_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .level =3D 1, + .size =3D 64 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 2, + .sets =3D 512, + .partitions =3D 1, + .lines_per_tag =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .size =3D 64 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 2, + .sets =3D 512, + .partitions =3D 1, + .lines_per_tag =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 512 * KiB, + .line_size =3D 64, + .lines_per_tag =3D 1, + .associativity =3D 16, + .sets =3D 512, + .partitions =3D 1, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 3, + .size =3D 16 * MiB, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 16384, + .partitions =3D 1, + .lines_per_tag =3D 1, + .self_init =3D true, + .inclusive =3D true, + .complex_indexing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, }; =20 /* @@ -8991,11 +8989,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) } =20 env->cache_info_cpuid4 =3D legacy_intel_cache_info; - - env->cache_info_amd.l1d_cache =3D &legacy_l1d_cache_amd; - env->cache_info_amd.l1i_cache =3D &legacy_l1i_cache_amd; - env->cache_info_amd.l2_cache =3D &legacy_l2_cache_amd; - env->cache_info_amd.l3_cache =3D &legacy_l3_cache; + env->cache_info_amd =3D legacy_amd_cache_info; } =20 #ifndef CONFIG_USER_ONLY --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493025; cv=none; d=zohomail.com; s=zohoarc; b=ffXdqsvGlxg7KyfvYw74mQbCzHGDlT1o8XeXSvZ4Frk0NdEh+bi0lqAjKqdSXTM9N0toR9Np74vqFD41IFFpaLAEiA72ZiEKZFKyumc1pbFyu1+0GT8Qq/NZPQnH0rCGmiLt3SkR9J+PJvsooSzi2thnGX+CwWU1yxzWT3txDa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493025; 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=zy/rmBu1Zl2DYymVok3Ga20+R2U49w13+p4AzvdswRk=; b=Y7brskGhg2YB7hTQYNUzsmSKM+tNW8G+hpKhHDUqMZkiiz/fqYpa2oFaA6sN72DAjHqWBdMTTTAF+C+TAFcj3ARDTio22JZrkyRZQq+yrOgXEnJ3ck/rWY90/gnCs25lHCxIUMFEpdjwJDDn41AdZI7c1xsS/tnlcd6JrmgLht8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493025200395.0764003441884; Mon, 14 Jul 2025 04:37:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHTs-00064Z-Ms; Mon, 14 Jul 2025 07:36:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH13-0001jQ-4G for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0w-00026p-Ti for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:36 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-v8F6pjCWMe-rWPwJi6b4Jw-1; Mon, 14 Jul 2025 07:06:26 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a4edf5bb4dso2919763f8f.0 for ; Mon, 14 Jul 2025 04:06:25 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd17b7sm12125014f8f.11.2025.07.14.04.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491187; 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=zy/rmBu1Zl2DYymVok3Ga20+R2U49w13+p4AzvdswRk=; b=MTOVKqYt9O9pb7BQppoDmwUFcZ5F4C9aKsNYvlSoosPUFgK6USuJh5vEqCoGOVSMJCtKvr 6akvh9wd9HbQRLCp3+vlhfeyo8lYBQUwsEJO5ehEt2lDBUel6v6a9F6K/UOGypPztzow30 dELzD+ODKh9ie5pxLiapYuoPmT5kPmE= X-MC-Unique: v8F6pjCWMe-rWPwJi6b4Jw-1 X-Mimecast-MFC-AGG-ID: v8F6pjCWMe-rWPwJi6b4Jw_1752491184 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491184; x=1753095984; 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=zy/rmBu1Zl2DYymVok3Ga20+R2U49w13+p4AzvdswRk=; b=rrzrfatNxCfEoJqLrwieDhe7jbLr6PkxIxsVXS2yA/itnpwgHmy3AKnbWB0mP+5jml dzGTP5bPw40Z5QrPSspo8t6rKyO6KsZN5M4Lkj1pUag7pdJdA4ZuIZoISaQ2pEyFZU4Q GO2Aloz738pR1V+T2NQCRquJGQbiubUVvQVK76PPvz/9eVseNpFwHx04a0pg961/wb01 49JSD1rVTnjC2sBPMeR89t/FfCzElHZZDLFKWHhAIHdMBamgonZECyqpIVvvfP41E7jj j4jcDU2nOwK566cSuvU6BtNsZT6nDL8/VvzUs6FKNSrje9SEYLwZXNpWc5qghRSww7Kf S/IQ== X-Gm-Message-State: AOJu0YzxFH52IksVygnqQ6AdFtoXjj1NOVG4kJ8xxIxF1YQjPtdbbzTh EGdFT2SUE3LUHoZ5lTswZtV6tNthAeDhBbKopl2kpVdhOTwrR//fWFjqQdQKAI02xoMAO/H7Z4D RPV5O2rC7+Ld6OwoQPTvuJrIJ6lgGY9VJ6Rh6DeaP/k3BcMNF4Tqtr0gQxBmErvdbyy7TDI1nSV myyYO5Ml+Wdm2HgohhXTHyvrfrJwYTGNxC6/IK6NNf X-Gm-Gg: ASbGncuecM/vXbXFwwyf35zsg3LH7joxnH7BM4fMOVcRvVI1RrstUEPDO1NDr4nFSMO /m3CLSfKpcz9tLOfWFEqHHJyT6vepyjAnar/D5rMrfpzg59PA4Jfs/EYZMmKDsb14xd9ZNRJzOA LBxvciNeDrAPCyGgxJz6poclCNstLX2ePl+K25dE3bznoN0QUtZjxtx4/cVShZ+F2FEIa02Ehgu 8SyjjCgnw7Z/+4rvssTBukMbhYa8dguiBaafUyC+2CUq7j78L59vlVTE4UaHsbyfr/Ma0/Q8ArR i9b0u5fZkjHnT/Yl5fk4t9Yya/1O59pqo9OuAO//JNU= X-Received: by 2002:a05:6000:2b11:b0:3a4:f7e6:2b29 with SMTP id ffacd0b85a97d-3b5f185662bmr8115527f8f.5.1752491183485; Mon, 14 Jul 2025 04:06:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZVjOhWl6Ty64CM1n53fSbm8DsA392JN0N4GDOUPtbcH/vULYnhaZwbpfvYOGE1IDOGpLqaw== X-Received: by 2002:a05:6000:2b11:b0:3a4:f7e6:2b29 with SMTP id ffacd0b85a97d-3b5f185662bmr8115498f8f.5.1752491182887; Mon, 14 Jul 2025 04:06:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 52/77] i386/cpu: Select legacy cache model based on vendor in CPUID 0x2 Date: Mon, 14 Jul 2025 13:03:41 +0200 Message-ID: <20250714110406.117772-53-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493032103116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x2 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model, otherwise, select legacy Intel cache model (in cache_info_cpuid4) as before. To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x2 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x2 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x2 leaf regardless of the vendor. Only AMD CPUs have all-0 leaf due to vendor_cpuid_only=3Dtrue, and this is exactly the behavior of these old machines. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model. Similarly, only AMD CPUs have all-0 leaf, and this is exactly the behavior of these old machines. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x2 leaf regardless of the vendor. And AMD CPUs have all-0 leaf. Nothing will change. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache but still get all-0 leaf due to vendor_cpuid_only=3Dtrue. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x2 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-14-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 1 + target/i386/cpu.c | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index d88481ba8ec..20499a82a54 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2079,6 +2079,7 @@ typedef struct CPUArchState { */ CPUCaches cache_info_cpuid4, cache_info_amd; bool enable_legacy_cpuid2_cache; + bool enable_legacy_vendor_cache; =20 /* MTRRs */ uint64_t mtrr_fixed[11]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 92d21ce64c3..ca856030773 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -250,23 +250,17 @@ static const CPUCaches legacy_intel_cpuid2_cache_info; =20 /* Encode cache info for CPUID[2] */ static void encode_cache_cpuid2(X86CPU *cpu, + const CPUCaches *caches, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { CPUX86State *env =3D &cpu->env; - const CPUCaches *caches; int l1d, l1i, l2, l3; bool unmatched =3D false; =20 *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ *ebx =3D *ecx =3D *edx =3D 0; =20 - if (env->enable_legacy_cpuid2_cache) { - caches =3D &legacy_intel_cpuid2_cache_info; - } else { - caches =3D &env->cache_info_cpuid4; - } - l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); @@ -7472,8 +7466,37 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ebx |=3D threads_per_pkg << 16; } break; - case 2: - /* cache info: needed for Pentium Pro compatibility */ + case 2: { /* cache info: needed for Pentium Pro compatibility */ + const CPUCaches *caches; + + if (env->enable_legacy_cpuid2_cache) { + caches =3D &legacy_intel_cpuid2_cache_info; + } else if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_intel_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't use l= egacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD + * CPU will use cache_info_amd. But this doesn't matter for= AMD + * CPU, because this leaf encodes all-0 for AMD whatever it= s cache + * model is. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7481,8 +7504,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } - encode_cache_cpuid2(cpu, eax, ebx, ecx, edx); + encode_cache_cpuid2(cpu, caches, eax, ebx, ecx, edx); break; + } case 4: /* cache info: needed for Core compatibility */ if (cpu->cache_info_passthrough) { @@ -8988,6 +9012,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) env->enable_legacy_cpuid2_cache =3D true; } =20 + if (!cpu->vendor_cpuid_only_v2) { + env->enable_legacy_vendor_cache =3D true; + } env->cache_info_cpuid4 =3D legacy_intel_cache_info; env->cache_info_amd =3D legacy_amd_cache_info; } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494046; cv=none; d=zohomail.com; s=zohoarc; b=QtIspUsfdcdoWPVns21+hCPczeoFZM73DFCtqTMezGA3P5jXOfWGTX0IGVTxZfsrU3w25M62iwlohacXJ3fiXWs4+rLxBH/fDbJTTQw7+nACAok4YJZ7zfbL5yjUofxhYBQGdcB/6Iu1k0WK8aF1YpTKfxoS79eYAtyXZQxQ7y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494046; 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=9RKbmpC/gOn3zgkmmw8UDFJXa21Fgwk+M1UraeNcusE=; b=OiLrsvGgjvIudzQ+cqVfSyAZZSXBTUjFWZOh+zkknP4GvJJk38bOR5bElGNSkHgCjYYbWiru7TYXaC1An7q9JMPnyeilaQjpEVtEbXiYu95EZo6SOMIe7uH/NQP0sWqqzlDJFXETKz4z9boctPsHV4WOEyWeiCWK5F0gEqa1T0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752494046892192.2772453097184; Mon, 14 Jul 2025 04:54:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHTX-0004k3-1j; Mon, 14 Jul 2025 07:36:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH13-0001jr-Rf for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH10-000270-06 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:37 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-184-2E-jUCQRP-yDtKMHbiqL0g-1; Mon, 14 Jul 2025 07:06:27 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-453a5d50b81so30312945e9.1 for ; Mon, 14 Jul 2025 04:06:27 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b6039bdea0sm3216118f8f.65.2025.07.14.04.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491189; 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=9RKbmpC/gOn3zgkmmw8UDFJXa21Fgwk+M1UraeNcusE=; b=DIuCo4Xh2zkvFDk9eRFrSstLz55y2DZVY6KevGdAKAgajBySxvT55s9TEF0yo/oM2QUWRV 1hrrZogWyaFUWQPX5OJ7h+CmpYYO4b/oycU5bmsp+XzsklWM2PqGASzXo5O7RUJS6dw7z6 FcwVJF+kX8vxA87eGgSQ/Bx8qm8miIY= X-MC-Unique: 2E-jUCQRP-yDtKMHbiqL0g-1 X-Mimecast-MFC-AGG-ID: 2E-jUCQRP-yDtKMHbiqL0g_1752491187 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491185; x=1753095985; 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=9RKbmpC/gOn3zgkmmw8UDFJXa21Fgwk+M1UraeNcusE=; b=nrzMaRZyFh9GFBk3daAOC/SBdwIU81aMp3pThHtqZoHGh+b/EllnwLkMgw2paf8zR1 pn1YhfnxQweww4IGI3wVHpnl19zg4opIdIFi8mm2twM2o5vAffN7OxpESiQTpqa8Xk1Q YeJlvnyzzvQBrjqyiavelIRmsTArK+Nynj+91CcrCS/hgY9R1MUA1JlxkqIAefhYXZaV YNmEkdWzCEuxcKwjZZFxS3MfdJNyD+zh7pZN4AQmiPBzhLDp5LPwTpP7oYmg1/xZnY5x apa9KzILSPT2wntV9KUK4bWd++Y6DbM+Zggt//UlIgj0mSQEMH2/P8P/tdi6HMUrjnZ8 980A== X-Gm-Message-State: AOJu0YyPOvuWaOMLqvIgLgVTfA9Ggf35YKRYknlDvHWZoNWxq5kHhMaA iH2biRq7+wlfjgt0/bHpc/ewDlVKC6SamgH6IW9e8uah4mdJs4XGqd5nlJKRYTDdTZ5+VhR/iti jMXdk0/OULFsnJET8zaM/vZbrRAjk6GZQkfvD5VDha5w2WdGtqEtBcLVIHRHX6cxI9/CmlBK1lZ sMiM4Q4S0Er1R2uQvSI5zpNGOzUOEVPfGKAeySe5ZN X-Gm-Gg: ASbGncvt5B15uD8P0WiOky8eKPPQ1VAuo2/EfvDl5zcB6PztMil0ZNk/Qy9GBX4qR28 esUtj4oD8Y3Qr+M0cjQfu8wJaS85HG2Q6AZMsVtBqN7veMDNq3K1vcuW7SZ6bjEHQHVd61v7vJz svtCUcrDkYGWmt827SGTC+ehGWvkDLfJnuehL1+7t4+rjCrh79HN6cHTMY3vHBOGhNJrY/4TEIT l2RmR4wp2wzRIw+m8bXdLKjFl4J/ak03fMF1/ugz4rb4Q9E/bPzMrExCnInvD6eB/MEqdsZxriq HhpoCAOZ+AjldF7ACaZLYt09MqNrBvRu2qQ+XC0pVk4= X-Received: by 2002:a05:600c:a301:b0:454:ad94:4b3d with SMTP id 5b1f17b1804b1-4551743756fmr75433605e9.1.1752491184905; Mon, 14 Jul 2025 04:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ3Yu8ukdstTmrmSVwJFqdHwzIfCPOc9kA4bIc0zDw/XmxENxA4Vb9RdwbPn5A/JltZxvlQA== X-Received: by 2002:a05:600c:a301:b0:454:ad94:4b3d with SMTP id 5b1f17b1804b1-4551743756fmr75433295e9.1.1752491184343; Mon, 14 Jul 2025 04:06:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 53/77] i386/cpu: Select legacy cache model based on vendor in CPUID 0x4 Date: Mon, 14 Jul 2025 13:03:42 +0200 Message-ID: <20250714110406.117772-54-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494048526116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x4 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model, otherwise, select legacy Intel cache model (in cache_info_cpuid4) as before. To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x4 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x4 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x4 leaf regardless of the vendor. Only AMD CPUs have all-0 leaf due to vendor_cpuid_only=3Dtrue, and this is exactly the behavior of these old machines. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model. Similarly, only AMD CPUs have all-0 leaf, and this is exactly the behavior of these old machines. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x4 leaf regardless of the vendor. And AMD CPUs have all-0 leaf. Nothing will change. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache but still get all-0 leaf due to vendor_cpuid_only=3Dtrue. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x4 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-15-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ca856030773..565eaf0071c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7507,7 +7507,35 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, encode_cache_cpuid2(cpu, caches, eax, ebx, ecx, edx); break; } - case 4: + case 4: { + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_intel_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't use l= egacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD + * CPU will use cache_info_amd. But this doesn't matter for= AMD + * CPU, because this leaf encodes all-0 for AMD whatever it= s cache + * model is. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + /* cache info: needed for Core compatibility */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -7535,30 +7563,26 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, =20 switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l1d_cache, - topo_info, + encode_cache_cpuid4(caches->l1d_cache, topo_info, eax, ebx, ecx, edx); if (!cpu->l1_cache_per_core) { *eax &=3D ~MAKE_64BIT_MASK(14, 12); } break; case 1: /* L1 icache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l1i_cache, - topo_info, + encode_cache_cpuid4(caches->l1i_cache, topo_info, eax, ebx, ecx, edx); if (!cpu->l1_cache_per_core) { *eax &=3D ~MAKE_64BIT_MASK(14, 12); } break; case 2: /* L2 cache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l2_cache, - topo_info, + encode_cache_cpuid4(caches->l2_cache, 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, + encode_cache_cpuid4(caches->l3_cache, topo_info, eax, ebx, ecx, edx); break; } @@ -7569,6 +7593,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, } } break; + } case 5: /* MONITOR/MWAIT Leaf */ *eax =3D cpu->mwait.eax; /* Smallest monitor-line size in bytes */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493007; cv=none; d=zohomail.com; s=zohoarc; b=cIc9KBSEx4/aTNs1OqaTwClQHFN3trJK8oPMCDJy+LJg+/WXVl5seKbwjQOrWdUkr0EkE+34J98Pa7LG8xOCJu/RA/w0Uoh6Fgr/3lp0gv8mXtxF+SVRb9/6xdVXg3Q693ahuk2qQUIfqCaMsPISTzGkdQDpu/C6Itiz2jzAEHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493007; 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=DM3g4jGDz+IF2qu9cdV0osBtPT9IUxABMoDQ14HnLM8=; b=M65bpUMZoQYtVW+HitqTclaMPZeBtT/jnxK1gIC6rTJMi0OYWQWsiHbmMalQ4+iMw+nFUQSwIcVIHZBlihQwapXTzK/x+HVR9Cx0mm22ejizV8LdKQUAjdIdS5yW/r2HeJRfNycMZAzNo97KLzeqt94z3FnIz1yDQHF/2Q1E+jE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493006962697.7155001277622; Mon, 14 Jul 2025 04:36:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHT8-0004CI-3A; Mon, 14 Jul 2025 07:35:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH13-0001jo-Ov for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH10-00027E-Vj for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:37 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-ypSRTcKxObKdkvdOKEZtQw-1; Mon, 14 Jul 2025 07:06:30 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-451d3f03b74so24021865e9.3 for ; Mon, 14 Jul 2025 04:06:29 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45623f4f838sm184345e9.1.2025.07.14.04.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491191; 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=DM3g4jGDz+IF2qu9cdV0osBtPT9IUxABMoDQ14HnLM8=; b=cWPsDfswXEhG+J6r/L4sgIV2+xWxNQSCjbrznNY3S7YtfoUClzT9CrsznexykUqnLiQFb+ yaDbfotE0HH33EtFm8iQCIxyycYhFiBE24A8doVfhFjT/asL7rVtjgsh1vk0WXB4NLFDeg hiLIPiCSQU3f7mafOGOaYK/622LvF2I= X-MC-Unique: ypSRTcKxObKdkvdOKEZtQw-1 X-Mimecast-MFC-AGG-ID: ypSRTcKxObKdkvdOKEZtQw_1752491189 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491188; x=1753095988; 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=DM3g4jGDz+IF2qu9cdV0osBtPT9IUxABMoDQ14HnLM8=; b=VRTpOSKLmJyOmFZXffxUmn0zhsN0gdTTxp3vISROzCH0MWcG5YLqipXixr0kplWDGz JTE4tDWCyW+67peYRaa4n2VKO1gEchOYrcWwDqpHQ1ZS3LGjO1bk1XG4eAVDh8XEbdF8 xGl1wkxXJsXr+K47u4/xu7QHE1TJjG4i0qcWQKsDPf6bIM3SdVlsMCxayH/ijvt1ckTq G8d5u1ZsDD0NtoZ0wEbOxWkTbh1nOdGGXVEblmH37u0hCbkN1dQMgs9sD5LivVct3VlA orAW2zKXHZ4QvaOZShmFf8Gx9GyaMhV5S/2fmI8163c8SyH+G0MWOr+uk9Jay4hC+EYT Loeg== X-Gm-Message-State: AOJu0YzgpUgQ0/krzEmRMfg4kXD1hXwPZ9mO8zCCXE49z3ZHl6otBBUr 9Yl9BTvS26QsLn3LelqY6xeahZxisIgSoSorznPu6bt21scdsRyT9FP3JHHDRCacw2wS8s5N1fN ST4oDvspHbzJjGPrwPTVG7F5Rc7B7/GMZDqK6IYfvXyNDXmGh7VwhEBr+0P0WBn5iIDE83wdcan R0O7HHnRxl36Y/WCnzDWHnrfK7jjcXSSoCbYlbKdZq X-Gm-Gg: ASbGncutvy1v/Y5wAPIbs8sUz5WPD9GFjzFK6xS2gFgJ/PdW5ahRw24XRzuqlq4Si7X nU3ftiM9BTAvbgzH6rhoEoJEmBch3xQgyaVIEbAzEoaDzhWJ3rmbhXB98YFD/jIBojRNa4maR3e omC+TBnccVoEBO2RsLsTRbgOtcPBPpghXEJhpyL5STEZkQKQcKUl7hehN24/GXtsqu4Dy/Py1A5 dyrSGu0+DK7bLjpx/UKdaXrJ1GxxQbp0TLWsswOLLGusR9iQIhpfUYdk87A0JperNCZjKJk9BDd B8YXD/bx4gOR6dh/BhDGu1u1vBLFXIYgN1S1TH48ZDY= X-Received: by 2002:a5d:5f55:0:b0:3a4:dcfb:3118 with SMTP id ffacd0b85a97d-3b5f187599dmr10358520f8f.10.1752491188175; Mon, 14 Jul 2025 04:06:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXYOQcsuR9pPrQE0ZA1C9s7bm6CtiFo3XQuydkWlqEZQP2WRamsUR4Wnd51C1cqQ72QtRpWA== X-Received: by 2002:a5d:5f55:0:b0:3a4:dcfb:3118 with SMTP id ffacd0b85a97d-3b5f187599dmr10358488f8f.10.1752491187658; Mon, 14 Jul 2025 04:06:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , EwanHai , Yi Lai Subject: [PULL 54/77] i386/cpu: Select legacy cache model based on vendor in CPUID 0x80000005 Date: Mon, 14 Jul 2025 13:03:43 +0200 Message-ID: <20250714110406.117772-55-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493008018116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x80000005 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x80000005 leaf, enable_legacy_vendor_cache flag indicates to pick legacy AMD cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x80000005 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy AMD cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - No change, since this leaf doesn't aware vendor_cpuid_only. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x80000005 leaf regardless of the vendor. Only Intel CPUs have all-0 leaf due to vendor_cpuid_only_2=3Dtrue, and this is exactly the expected behavior. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache as expected. For Intel CPU, it will use legacy Intel cache but still get all-0 leaf due to vendor_cpuid_only_2=3Dtrue as expected. (Note) And for Zhaoxin CPU, it will use legacy Intel cache model instead of AMD's. This is the difference brought by this change! But it's correct since then Zhaoxin could have the consistent cache info in CPUID 0x2, 0x4 and 0x80000005 leaves. Here, except Zhaoxin, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. And the change for Zhaoxin is also a good improvement. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x80000005 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Cc: EwanHai Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-16-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 565eaf0071c..e98ffb11c31 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7935,8 +7935,36 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx =3D env->cpuid_model[(index - 0x80000002) * 4 + 2]; *edx =3D env->cpuid_model[(index - 0x80000002) * 4 + 3]; break; - case 0x80000005: + case 0x80000005: { /* cache info (L1 cache/TLB Associativity Field) */ + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_amd_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't uses = legacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. AMD CPUs use cache_info_amd like before and non-A= MD + * CPU will use cache_info_cpuid4. But this doesn't matter, + * because for Intel CPU, it will get all-0 leaf, and Zhaox= in CPU + * will get correct cache info. Both are expected. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7951,9 +7979,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx =3D (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | (L1_ITLB_4K_ASSOC << 8) | (L1_ITLB_4K_ENTRIES); - *ecx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1d_cache); - *edx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); + *ecx =3D encode_cache_cpuid80000005(caches->l1d_cache); + *edx =3D encode_cache_cpuid80000005(caches->l1i_cache); break; + } case 0x80000006: /* cache info (L2 cache/TLB/L3 cache) */ if (cpu->cache_info_passthrough) { --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493570; cv=none; d=zohomail.com; s=zohoarc; b=U4a9NBdUSVbexJm2Lga+fa56XF03/m5nEUdeMBxRg3JW+Bvlwc3UIGgg3QQMd90GiVpoOuGQxz6MulSk8l2HynRjTaHyNp1c5rEwxyCeIBen/XuZhjr1QCnoAYpzyLcXka+okFRJ99RQ478Y7lEZVpvghwyopOndd9DwN82G+wE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493570; 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=XR6j7BhZab0elBL4igl7ltcFzqCGAaAHJVZIJY5nUn4=; b=ZEmHUN9ez5DInZ3XM5kDlCXQZKMhsrRCySSfCBHA21AMYFNu1srX8bDLRPGJnidQqAZcC7s6J0fOsjfuG/GHozGN63x0fGBDWXXXLlQQLRTjg5kprhDRJZZlhtFHybwIVLP2+sEAC7AT82vYx7SK2TvT1jDT1vTFt9/T81ZsHRs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493570311449.0148023904228; Mon, 14 Jul 2025 04:46:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHVe-000811-Po; Mon, 14 Jul 2025 07:38:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH19-0001no-3s for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH16-00028W-JP for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:42 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-bNlMaX6oPiWs3TUWaZ-S1A-1; Mon, 14 Jul 2025 07:06:33 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a4f6ba526eso2171832f8f.1 for ; Mon, 14 Jul 2025 04:06:32 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1890sm12034273f8f.3.2025.07.14.04.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491199; 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=XR6j7BhZab0elBL4igl7ltcFzqCGAaAHJVZIJY5nUn4=; b=hzxkKC9AXkyAK7brF4kAtEwI/gNM5GHkteBVX5QoTWayBmrBzBFzPevK074oVH0e/Q81Pu EBQxu833IEFbcM7lcIsv986aD6eS/u8a/6Q++w0ZEIymUjMzc+NsPQXmlxOntrVzSytM0b 13oG720zaJOurfKjliihMId2YOOZnu0= X-MC-Unique: bNlMaX6oPiWs3TUWaZ-S1A-1 X-Mimecast-MFC-AGG-ID: bNlMaX6oPiWs3TUWaZ-S1A_1752491192 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491191; x=1753095991; 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=XR6j7BhZab0elBL4igl7ltcFzqCGAaAHJVZIJY5nUn4=; b=QJLWltDnnBkHTllBjHlLfnrh1K8EuXpIKVfrQ0z6U2gyVzuWJrkUyhstBwaJfTHztl agGWQty37g383lqkA7CV6f/TED3c2z1gcFuqZEDdJQI61+80zTu/RLXyPl/GKcrOKvaG oTx14odjuCLg+5Mlkn5Nw/lYZ46ZFXecK3DXdFIY6NX7269NWb48Qv0n+coV9AxBp9xm HykL5c0MKSnIqlF5DPRuRI/BbjZ8trA/gijxZfjwmNzFd+yYT07SLrpFcrasnwx+6HXK LhuAgWqIdHSFSj2rgWIs3LG5+xwsVVHpscS37Il/eqYKVpxKqW28gVfU87G4t+Ph73U3 /90Q== X-Gm-Message-State: AOJu0Ywo0i6TRtGSEyNaByJaIgWhz/xz97QEanLcJLL6GcOIfKCMtqiZ DzJWwf6nVvirDCM2V5Nat4S9aj8v5g4TTXoFCfUgevL8/aeiYe92szcOsx+RWIlCKMeTIXdhOji wkh+flZH/WGlDBA9PvrAHDUE2ml4I6ZXmn2k6PFJSCJ1szCX6AmArJJZQVwrBXJq7oPK0lZdms3 RtixMNszLijo262uRiXRotRxDbQU5sjiYAyEKetm5D X-Gm-Gg: ASbGncvtCMWV4qhKJDXo6NzlInsbbbVvrOMxBCQvDw+ah5ORAH72qIj5A+ALbVYU15k pAi2PplKg76NsXJbsIu0tnKppYquR1mI44PnfGDnbf/kYXy/CoGaRTBM/5wQg/payyzyliwBL0U Nw8WW4LEMjwzc49NvEyDRgnPX+cvY5HDwjTKSvQbygup6sKWVRjEPsnH8YG9pujxJiZFGuqAed+ WwxEZVElvKakByy3ZHQJH1byH/chY2JxcxNNmojwEeb8Mle4nEScslkHMgN/BzBp+27JsYS9bdm yM+ivGoX5G/yqsuq2csFzBZSYH0qWOwAXGFXsxakBFM= X-Received: by 2002:a05:6000:2388:b0:3a0:a0d1:1131 with SMTP id ffacd0b85a97d-3b5f187d0e3mr10954260f8f.7.1752491191216; Mon, 14 Jul 2025 04:06:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiuSfF84UqKQ4W78xs7PMKnFx3QFxXTNNdbpY01qa5fDTuTTtk7FQlzWP7RWBvot1k5ZUSpg== X-Received: by 2002:a05:6000:2388:b0:3a0:a0d1:1131 with SMTP id ffacd0b85a97d-3b5f187d0e3mr10954216f8f.7.1752491190566; Mon, 14 Jul 2025 04:06:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 55/77] i386/cpu: Select legacy cache model based on vendor in CPUID 0x80000006 Date: Mon, 14 Jul 2025 13:03:44 +0200 Message-ID: <20250714110406.117772-56-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493572045116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x80000006 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x80000006 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x80000006 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy AMD cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - No change, since this leaf doesn't aware vendor_cpuid_only. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x80000006 leaf regardless of the vendor. Intel and Zhaoxin CPUs have their special encoding based on SDM, which is the expected behavior and no different from before. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache as before. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache and be encoded based on SDM as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x80000006 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-17-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e98ffb11c31..b557fd01c02 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7983,8 +7983,33 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D encode_cache_cpuid80000005(caches->l1i_cache); break; } - case 0x80000006: - /* cache info (L2 cache/TLB/L3 cache) */ + case 0x80000006: { /* cache info (L2 cache/TLB/L3 cache) */ + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_amd_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't uses = legacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. AMD CPUs use cache_info_amd like before and non-A= MD + * CPU (Intel & Zhaoxin) will use cache_info_cpuid4 as expe= cted. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7993,7 +8018,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, if (cpu->vendor_cpuid_only_v2 && (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { *eax =3D *ebx =3D 0; - encode_cache_cpuid80000006(env->cache_info_cpuid4.l2_cache, + encode_cache_cpuid80000006(caches->l2_cache, NULL, ecx, edx); break; } @@ -8007,11 +8032,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); =20 - encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, + encode_cache_cpuid80000006(caches->l2_cache, cpu->enable_l3_cache ? - env->cache_info_amd.l3_cache : NULL, + caches->l3_cache : NULL, ecx, edx); break; + } case 0x80000007: *eax =3D 0; *ebx =3D env->features[FEAT_8000_0007_EBX]; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493403; cv=none; d=zohomail.com; s=zohoarc; b=D8rRnE1qgthvwaKyazZ8hs9JIWHBAFcFRRXgipOrePW4J7gaY8/JagR61iUFTNEckCNl5KuHbgdtbPLcnPqkw2M8AfsWb1eJ7D7Qwneez0Y7++VUfVSaqGTv0O3NfAMtOLekc5U2cKrwEmbv1V8++ALFUjoJU5W7zTFbT4dvZDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493403; 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=mqYPp6af6fKy8igTufJ+mf6axAEuMulVTGjst6+NyMw=; b=F2ZuI/OEIIQ6P+Zl9bWbCnTd1PiJqq3N1shh6vrEZTr9CeMpmti98a8trrxdF3wOXlELEIo/zdv6kUzqD1c48wbZZ6m2FuTvbofHhmGcdCI7ILObzKNcGfDDSCPL5JKliIaZhP84o3Wn2R0OjVvtxea6ezQT22HKMbYamijwBR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493403574198.2746206283773; Mon, 14 Jul 2025 04:43:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHVU-0007zC-3R; Mon, 14 Jul 2025 07:38:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH16-0001lS-IX for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH13-000280-Mn for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:40 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-Maf9GfTuOROBJy2lhpU0Lw-1; Mon, 14 Jul 2025 07:06:35 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4edf5bb4dso2919889f8f.0 for ; Mon, 14 Jul 2025 04:06:35 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45614aeba29sm43571045e9.11.2025.07.14.04.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491197; 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=mqYPp6af6fKy8igTufJ+mf6axAEuMulVTGjst6+NyMw=; b=M++S5f2geyZTg5csbaWhDmtXRg56Frv5KcHgeHVAE3tuJP3vyAt0dEeQx/lbeUHJMVIval 5fxh1vElaIUoJor7wZXvEdd3OM6b8fSB3+r1QRs7kVJGFnEg+00NtNSaxhX9OjiHzSM+TJ /vs8P9Hi3ubIN65f6uBi5C9gFackwbo= X-MC-Unique: Maf9GfTuOROBJy2lhpU0Lw-1 X-Mimecast-MFC-AGG-ID: Maf9GfTuOROBJy2lhpU0Lw_1752491194 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491194; x=1753095994; 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=mqYPp6af6fKy8igTufJ+mf6axAEuMulVTGjst6+NyMw=; b=XcxHIlJJ6BEx+c3GeCf5nI2R7bxUufzQ6D2ew1dGmxj83j+yerYWoGGmdXxlY+r04B GqGHxex8vdOoSYUAK1a/WudeLeGgL0h/hkCuLb51Kao/2y++32nwEMcJYfmgCeSshtya Lqfx+yu8gM/EqElodyL04T54pfBOPixw+dIyBRjrS47m1+HZi11qEXjlmvepoG4cbtvC zTlEbM+Hhq2+4aZ2svSeIPpzxD4/YHvHIoJTEhRlrDtS+PiFkWIKbD5y5DB2alBSLSO/ LMTH4fIx3K6OUHCJmEFCeqR7pWFAgAHNF+NWCZHNKJAi1EloVtpCi5Itu/GaGDwte1YD //Ng== X-Gm-Message-State: AOJu0YwDnA4cudv/AQRyJJTjv+hXaji3ClIL6B9AAvtWFyafI7h3BwcM yXgq7bQ6Ok8HTdJZZgE75/m8EKizIZ9aa2naHpNT599lwetWfEJb4mv6VhKv10L0OQXM7rF5Hev 8Nv5iU71soFK/0MPOXQCYoxWVwIBSuOJFXEUN31TmNtwaYlPW2RXzT7q58kFEJ9jCE19dasFXVk pLMQBcyKme6BXG2vkjJjl4cq92UG2aQ7zpUWZy9QpQ X-Gm-Gg: ASbGncuJtB2bc894xx3OpjVYiPtp3DU9u7RLTxu4bsCivzXVzAOygE/oibyPNo9K88d 4aeu3rse4PYaJOqF64yEg1Opfnixt5yMxNpWaOd6GLCnBX36U4105nSxvbofmiRDXIp5M56zG7e 6Oyy2r7hVP2czOEeEcgB5Q74upqbfNjRQrpNP9RZM755M+fGDw0AyR43gjUsDZhtHV+lU4IDrPd M/c61dqfMoup8ZQe2kmRSvsC2eIdLtrD70j4sUoBhAe9fpgj+0tnrTVyzFB6vvdRi1RwaiORhmR OfG6EAYiZz8Yk3btEGUb49LKOQCRfrkMMp5yfLS+/Vs= X-Received: by 2002:a05:6000:41e8:b0:3b5:e6f3:f825 with SMTP id ffacd0b85a97d-3b5f186de34mr9808038f8f.23.1752491193601; Mon, 14 Jul 2025 04:06:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAS43AfjCQyI41YcYeiuJAyk6vQMJ3d0mgkk9leiLIxw1Q/8pzfli8C53UC2PqC5e5vjwJVw== X-Received: by 2002:a05:6000:41e8:b0:3b5:e6f3:f825 with SMTP id ffacd0b85a97d-3b5f186de34mr9808008f8f.23.1752491193082; Mon, 14 Jul 2025 04:06:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 56/77] i386/cpu: Select legacy cache model based on vendor in CPUID 0x8000001D Date: Mon, 14 Jul 2025 13:03:45 +0200 Message-ID: <20250714110406.117772-57-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493406092116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x8000001D leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). In fact, for Intel (and Zhaoxin) CPU, this change is safe because the extended CPUID level supported by Intel is up to 0x80000008. So Intel Guest doesn't have this 0x8000001D leaf. Although someone could bump "xlevel" up to 0x8000001D for Intel Guest, it's meaningless and this is undefined behavior. This leaf should be considered reserved, but the SDM does not explicitly state this. So, there's no need to specifically use vendor_cpuid_only_v2 to fix anything, as it doesn't even qualify as a fix since nothing is currently broken. Therefore, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x8000001D leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-18-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b557fd01c02..5b969743bcc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8080,7 +8080,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; } break; - case 0x8000001D: + case 0x8000001D: { + const CPUCaches *caches; + + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * Intel doesn't support this leaf so that Intel Guests don't + * have this leaf. This change is harmless to Intel CPUs. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + *eax =3D 0; if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -8088,19 +8103,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, + encode_cache_cpuid8000001d(caches->l1d_cache, topo_info, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, + encode_cache_cpuid8000001d(caches->l1i_cache, topo_info, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, + encode_cache_cpuid8000001d(caches->l2_cache, topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, + encode_cache_cpuid8000001d(caches->l3_cache, topo_info, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -8111,6 +8126,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *edx &=3D CACHE_NO_INVD_SHARING | CACHE_INCLUSIVE; } break; + } case 0x8000001E: if (cpu->core_id <=3D 255) { encode_topo_cpuid8000001e(cpu, topo_info, eax, ebx, ecx, edx); --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492673; cv=none; d=zohomail.com; s=zohoarc; b=WHyQje9pRVnXqqGK4sQogmRLn956Gl50CXb9zeaBO9bmSq01vzLxjEFy2XMkdKqNSQfYLMCkpvRxFO8tg8wOZke/3cXa61XMcSsL9t52uu01bj9kcI93MZcOW9fOrvS0gYWvQ9lo5boCy5yboPHn0RrNeoOz0AHnlPV2mD/VWy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492673; 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=NWO6IlOasxNuKX/Bs+0ihYURBpNqqPnwPBbIYO1DTE0=; b=g9YOjENZoQf0/5Cuwgg5hgnnddWSRsiJOeuhTaxZgArz6yRlnbx9M5JFuJbHluIeWhWyXq48AsUYUX/fhwfZDEWESFp4zKsPLyYvifCFt/OgoHWwzImdjqeamaeewpJdSOOm2oXvOi6gERcrNqIoDYRKm4gwkSHgDSljGkHZ1RI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492673192942.8959202210218; Mon, 14 Jul 2025 04:31:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEV-0007sP-Lf; Mon, 14 Jul 2025 07:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1B-0001oe-Jd for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH17-00028r-EB for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:44 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-I2QByDFZMdinu3N8NeCj_A-1; Mon, 14 Jul 2025 07:06:39 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-451d3f03b74so24022505e9.3 for ; Mon, 14 Jul 2025 04:06:39 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-456101b616csm56717045e9.4.2025.07.14.04.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491200; 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=NWO6IlOasxNuKX/Bs+0ihYURBpNqqPnwPBbIYO1DTE0=; b=AJaXgrigPD6wbZbgmKkFzzOqPkTNsgdG3FlCab+kyqda9+V/sUMXtHXdf691pvSL4+y8KN ryBawPJ8jyQjImcougEyfCrO0VOueucG/JZ4eqkAyDxOjds+d9WPVLAwJEZo8KgUUtGBOW nvtbga07bnFlDKYFsHVIxOAkwxDs3Kg= X-MC-Unique: I2QByDFZMdinu3N8NeCj_A-1 X-Mimecast-MFC-AGG-ID: I2QByDFZMdinu3N8NeCj_A_1752491198 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491197; x=1753095997; 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=NWO6IlOasxNuKX/Bs+0ihYURBpNqqPnwPBbIYO1DTE0=; b=c1qaBlUX2Iw9WPtPVFSIx7cy27LkAtpdAn2NzbXcr4Ypa+GH5OclEi3k3SI1TbE+gu rYQJb6mvlgjQnxSAfXjYNV8hi1Gu9fLL6ydRZeDsdfrJd5Mhm9GzXKArZiwvsq1zbl+X Du6dSOA2ayW4Y48xkWK3VCU21JmwcVUyYmDok99Mgyszt0HEBegGTfVqACZwztkB0Kii tYbuPRTQ+l0B48S/PEx6kvjuUTo3zZaB4V3adi10jphCxyTqeP0fOPNCdJtdia9b2UB3 9a8ZhLQN7fDnMOsA6eA/Dwz2C7dHmFxbiTHgM7tpGocBK7n6+DG2ozwD/+45at6FYy3n GJsQ== X-Gm-Message-State: AOJu0YxZK5Y7y6sPxrm0PCQFkW05ARcjkxDYhPz6Aj/KaVhoL3/jsdBZ AdWuyPXyykpEPlJ4w0h9Unf3J9+MdHgLLVL4NzXPwdoOMjXji2M36/a22yyC8w2y2u+g4AJpu0R 3ZdR8BXaYXX6a73aaPjjpJFjfdndwZM10b7UdD8FFrlQ9fXcLHZG90bV1akVWJpnCF+rr1o7ePG Y6UQy55FZOWPDNW6ufdicbpRipDpf05VJXJuELnPto X-Gm-Gg: ASbGncsWNdSNhkQVHebqI6P4wWwxNXVMkIPR/Lhi03d/YOdeWNtSC/g8nXy4tPcZ0xu aoHCPR5dj95DoXyc2bkTdOJQxUVLqErbBBKlC67cV/dIJ36+vfj3vErHcpeyz7nlJE2HcAvrAcI SbO5ZEAV+CzCuW9hZtyu06i/+hCigVQpwOecYasCmFEJnw8mfMi751ZBlST6b0F0bFS2HWiKL46 j9+paF/22sHrA7KVVLUuOHyLM3g1+dDZjhSK5i62q8apoOM0hB5mBYJb8bTTzpryG4nQXQIwG/F gj+pm7rzQ0FOXMCObQgUIDGA+vd+pRC9HO/7+dQYnlk= X-Received: by 2002:a05:600d:10d:b0:455:e858:cd04 with SMTP id 5b1f17b1804b1-455e858cfe6mr65717135e9.25.1752491196714; Mon, 14 Jul 2025 04:06:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUL5iBKMwz5Ldx/+SI5UaM5919hrMt2sgLb6dGbqbf4hvgJTbdoadLn6fxMqlMLK/4G4cF+g== X-Received: by 2002:a05:600d:10d:b0:455:e858:cd04 with SMTP id 5b1f17b1804b1-455e858cfe6mr65716805e9.25.1752491196056; Mon, 14 Jul 2025 04:06:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Dapeng Mi , Yi Lai Subject: [PULL 57/77] i386/cpu: Use a unified cache_info in X86CPUState Date: Mon, 14 Jul 2025 13:03:46 +0200 Message-ID: <20250714110406.117772-58-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492675759116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu At present, all cases using the cache model (CPUID 0x2, 0x4, 0x80000005, 0x80000006 and 0x8000001D leaves) have been verified to be able to select either cache_info_intel or cache_info_amd based on the vendor. Therefore, further merge cache_info_intel and cache_info_amd into a unified cache_info in X86CPUState, and during its initialization, set different legacy cache models based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-19-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 5 +- target/i386/cpu.c | 150 ++++++++-------------------------------------- 2 files changed, 27 insertions(+), 128 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 20499a82a54..f977fc49a77 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2073,11 +2073,12 @@ typedef struct CPUArchState { /* Features that were explicitly enabled/disabled */ FeatureWordArray user_features; uint32_t cpuid_model[12]; - /* Cache information for CPUID. When legacy-cache=3Don, the cache data + /* + * Cache information for CPUID. When legacy-cache=3Don, the cache data * on each CPUID leaf will be different, because we keep compatibility * with old QEMU versions. */ - CPUCaches cache_info_cpuid4, cache_info_amd; + CPUCaches cache_info; bool enable_legacy_cpuid2_cache; bool enable_legacy_vendor_cache; =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5b969743bcc..ca6e4120242 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7474,27 +7474,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } else if (env->enable_legacy_vendor_cache) { caches =3D &legacy_intel_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't use l= egacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD - * CPU will use cache_info_amd. But this doesn't matter for= AMD - * CPU, because this leaf encodes all-0 for AMD whatever it= s cache - * model is. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -7513,27 +7493,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_intel_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't use l= egacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD - * CPU will use cache_info_amd. But this doesn't matter for= AMD - * CPU, because this leaf encodes all-0 for AMD whatever it= s cache - * model is. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 /* cache info: needed for Core compatibility */ @@ -7942,27 +7902,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_amd_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't uses = legacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. AMD CPUs use cache_info_amd like before and non-A= MD - * CPU will use cache_info_cpuid4. But this doesn't matter, - * because for Intel CPU, it will get all-0 leaf, and Zhaox= in CPU - * will get correct cache info. Both are expected. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -7989,25 +7929,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_amd_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't uses = legacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. AMD CPUs use cache_info_amd like before and non-A= MD - * CPU (Intel & Zhaoxin) will use cache_info_cpuid4 as expe= cted. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -8080,22 +8002,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; } break; - case 0x8000001D: { - const CPUCaches *caches; - - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * Intel doesn't support this leaf so that Intel Guests don't - * have this leaf. This change is harmless to Intel CPUs. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } - + case 0x8000001D: *eax =3D 0; if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -8103,19 +8010,19 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid8000001d(caches->l1d_cache, + encode_cache_cpuid8000001d(env->cache_info.l1d_cache, topo_info, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(caches->l1i_cache, + encode_cache_cpuid8000001d(env->cache_info.l1i_cache, topo_info, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(caches->l2_cache, + encode_cache_cpuid8000001d(env->cache_info.l2_cache, topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(caches->l3_cache, + encode_cache_cpuid8000001d(env->cache_info.l3_cache, topo_info, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -8126,7 +8033,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *edx &=3D CACHE_NO_INVD_SHARING | CACHE_INCLUSIVE; } break; - } case 0x8000001E: if (cpu->core_id <=3D 255) { encode_topo_cpuid8000001e(cpu, topo_info, eax, ebx, ecx, edx); @@ -8825,46 +8731,34 @@ static bool x86_cpu_update_smp_cache_topo(MachineSt= ate *ms, X86CPU *cpu, =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l1d_cache->share_level =3D level; - env->cache_info_amd.l1d_cache->share_level =3D level; + env->cache_info.l1d_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, - env->cache_info_cpuid4.l1d_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, - env->cache_info_amd.l1d_cache->share_level); + env->cache_info.l1d_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l1i_cache->share_level =3D level; - env->cache_info_amd.l1i_cache->share_level =3D level; + env->cache_info.l1i_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, - env->cache_info_cpuid4.l1i_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, - env->cache_info_amd.l1i_cache->share_level); + env->cache_info.l1i_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l2_cache->share_level =3D level; - env->cache_info_amd.l2_cache->share_level =3D level; + env->cache_info.l2_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, - env->cache_info_cpuid4.l2_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, - env->cache_info_amd.l2_cache->share_level); + env->cache_info.l2_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l3_cache->share_level =3D level; - env->cache_info_amd.l3_cache->share_level =3D level; + env->cache_info.l3_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, - env->cache_info_cpuid4.l3_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, - env->cache_info_amd.l3_cache->share_level); + env->cache_info.l3_cache->share_level); } =20 if (!machine_check_smp_cache(ms, errp)) { @@ -9101,7 +8995,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) "CPU model '%s' doesn't support legacy-cache=3Doff"= , name); return; } - env->cache_info_cpuid4 =3D env->cache_info_amd =3D *cache_info; + env->cache_info =3D *cache_info; } else { /* Build legacy cache information */ if (!cpu->consistent_cache) { @@ -9111,8 +9005,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) if (!cpu->vendor_cpuid_only_v2) { env->enable_legacy_vendor_cache =3D true; } - env->cache_info_cpuid4 =3D legacy_intel_cache_info; - env->cache_info_amd =3D legacy_amd_cache_info; + + if (IS_AMD_CPU(env)) { + env->cache_info =3D legacy_amd_cache_info; + } else { + env->cache_info =3D legacy_intel_cache_info; + } } =20 #ifndef CONFIG_USER_ONLY --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492068; cv=none; d=zohomail.com; s=zohoarc; b=EbGfTfG1yqeb5Lpcc0gUoTqtER48FgsZISIulkyN/g+UHPqzyjrdHqL5HCKxnvCEkurPeGTjLaiYDks9d0o3gAI8ztKu00Ubn1/EXE1otdpNDsWy5cVGXM9iPvshMKAhmTmnR4+Lj7Fpkn4z0vtAkK5NWlFQZKI3y/+REvsl/T4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492068; h=Content-Type: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=U3MRbm7BiwFLJpNktHCZXz82/ZMpqoQ6Olp5sQUIC0g=; b=ks8ihuBfz+WbFJtbxlqYDOM17N0OZyOzaDbNKUFu13rQjI3Idv13B6GPPMVwmq560TU91azAZ2FHElukj3BDgd6aRIhRD542TPctGflSGJ89laRsmbwg5DSf+BnSkvmvVD/lWUFrCKmoFG8yPA+PHtqriXshNfwlPl6q9+luMAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492068181354.68816822215206; Mon, 14 Jul 2025 04:21:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEn-000067-Os; Mon, 14 Jul 2025 07:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1E-0001pb-7O for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH19-000290-Rf for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:45 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-nUheGkeNN2i-GOpudfc_kA-1; Mon, 14 Jul 2025 07:06:41 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a58939191eso1556654f8f.0 for ; Mon, 14 Jul 2025 04:06:41 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e8b1sm12007521f8f.82.2025.07.14.04.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U3MRbm7BiwFLJpNktHCZXz82/ZMpqoQ6Olp5sQUIC0g=; b=eXsOzVVIoCxm4TJ8YVOURFjC3xSI96PSX6Olxsz0F/1vEHjkUwzIstCYKZQxeowRFd7vhm kr79r/aRIYqPk+KHGpAO9mySPn1weg/uL/59EtW9ND6KU2sN2sN8dlrO9QBLSYhjsC2xQJ vdB4ZMxm0Bax1FDEIX6tjGfJYfRArj8= X-MC-Unique: nUheGkeNN2i-GOpudfc_kA-1 X-Mimecast-MFC-AGG-ID: nUheGkeNN2i-GOpudfc_kA_1752491200 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491199; x=1753095999; 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=U3MRbm7BiwFLJpNktHCZXz82/ZMpqoQ6Olp5sQUIC0g=; b=oqczGzOLGyc5E0s3ZblkJcvtK7MjfV0hN6/7zFGWEUb4SLfhTbhx+ODKxrAu6hMWlP CkXdyOvg9DKQlcywbrSNLd/E5YXrte8kCMGdDWijqJy3rwKKUGiGDSONLhuCs6moaaw2 MbD5JVq771atxFt+JxZKNY0aC4uZxTxBG3BVAa8LQC3cc983PhQ2MororMbZbtZ7PEX7 tuCxDcQvfrLZdPpBltz3AkhXgP2ty2Sydwis6WHZ2VZ4k3qvey1M1h5YA4T5TNQ9KApu 61Ej7wzGMXOCTVeazzVNUw7QGTuFa2h9e+gnD//YuLYHFUI67f1noVUU8fgsBOdIb0Kt wRkQ== X-Gm-Message-State: AOJu0YzWtNwmpqf1v53K3BuI4IM1lR09mE9loUG6pE6ffVXyyynz+lNC taa6q/t1gndOvYC1htdKcE5SRM+T2FGUCG7NnfVecVgw7mRHD7BTD6U5IhkfMweGL9GrZ34+YmV UWBNmo6KyIfKu7tkwOhF0XoXtsNd+eTqZ7ZfBGhkCve1UXEAXYhBljQBoJgDs/VKA/PWA6lCLEy be+tGjYzwpcoGK9XpDlyEJr5Hw8pl8MsFf6ld7wIU1 X-Gm-Gg: ASbGncsrTkMABDdcZw8oXRv5rtTMeDKzFQfWhs8omfSnF/uN6D4YeHnEybhgLQAUqdT ljtJX+orB7ZkcLl24tc67Y6YSLENPucebLi4vpSNM9IFpw9XcpkgiX2FXvQc80QDMJ0rM27mqJo IjASG6To+n75gEeCXCvmuWYXkd8JAzugFEtSZN/+vzfzyo0ahXdK2P8MdIze6MYJBg0qC6pqiB3 tnvc+/ZyN33/4C4jebqj58YFtBjKWH4LXp/2EVlNrL5X+9huonfyaTo6yVjug3/KrLOm6CACekI sSoWSwpwriSBps1NmSv8TG7KYZAe+YXiHzbXQmg+FkU= X-Received: by 2002:a05:6000:2d09:b0:3a6:d967:380e with SMTP id ffacd0b85a97d-3b5f187eb90mr7210640f8f.3.1752491199411; Mon, 14 Jul 2025 04:06:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF67G9i7Tyo+jccD5Nb39QANLKCSVYm1N7GVZq5PQoZW8t9MZAVfcxI0ik7QQpsPQBtQmebCQ== X-Received: by 2002:a05:6000:2d09:b0:3a6:d967:380e with SMTP id ffacd0b85a97d-3b5f187eb90mr7210601f8f.3.1752491198724; Mon, 14 Jul 2025 04:06:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tejus GK , Jason Zeng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Dapeng Mi , Tao Su , Yi Lai Subject: [PULL 58/77] i386/cpu: Introduce cache model for SierraForest Date: Mon, 14 Jul 2025 13:03:47 +0200 Message-ID: <20250714110406.117772-59-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492069031116600 From: Zhao Liu Add the cache model to SierraForest (v3) to better emulate its environment. The cache model is based on SierraForest-SP (Scalable Performance): --- cache 0 --- cache type =3D data cache (1) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x8 (8) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 32768 (32 KB) --- cache 1 --- cache type =3D instruction cache (2) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x8 (8) number of sets =3D 0x80 (128) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 128 (size synth) =3D 65536 (64 KB) --- cache 2 --- cache type =3D unified cache (3) cache level =3D 0x2 (2) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x7 (7) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x1000 (4096) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 4096 (size synth) =3D 4194304 (4 MB) --- cache 3 --- cache type =3D unified cache (3) cache level =3D 0x3 (3) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1ff (511) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0xc (12) number of sets =3D 0x24000 (147456) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D true number of sets (s) =3D 147456 (size synth) =3D 113246208 (108 MB) --- cache 4 --- cache type =3D no more caches (0) Suggested-by: Tejus GK Suggested-by: Jason Zeng Suggested-by: "Daniel P . Berrang=C3=A9" Reviewed-by: Dapeng Mi Reviewed-by: Tao Su Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ca6e4120242..3c28e9588af 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2880,6 +2880,97 @@ static const CPUCaches epyc_turin_cache_info =3D { .no_invd_sharing =3D true, .complex_indexing =3D false, .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + } +}; + +static const CPUCaches xeon_srf_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x0.EAX */ + .type =3D DATA_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x0.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 8, + + /* CPUID 0x4.0x0.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x0.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 32 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x1.EAX */ + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x1.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 8, + + /* CPUID 0x4.0x1.ECX */ + .sets =3D 128, + + /* CPUID 0x4.0x1.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 64 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x2.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 2, + .self_init =3D true, + + /* CPUID 0x4.0x2.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x2.ECX */ + .sets =3D 4096, + + /* CPUID 0x4.0x2.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 4 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_MODULE, + }, + .l3_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x3.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 3, + .self_init =3D true, + + /* CPUID 0x4.0x3.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 12, + + /* CPUID 0x4.0x3.ECX */ + .sets =3D 147456, + + /* CPUID 0x4.0x3.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D true, + + .size =3D 108 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_SOCKET, }, }; =20 @@ -5005,6 +5096,11 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ } } }, + { + .version =3D 3, + .note =3D "with srf-sp cache model", + .cache_info =3D &xeon_srf_cache_info, + }, { /* end of list */ }, }, }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492435; cv=none; d=zohomail.com; s=zohoarc; b=oKEouktgTdexM7V9LTR41xj9esPdCNAAGeT4dxDYk0MKruIBgxUwGgKfBf7zcf8K9e3xhKy7+8E3+f6OfjFUU8C68Y9kt3NW3ZlU0+V2shOhYJ0FVoqtfwxazMEXIk/qooSsqvEYj9DIiYjcMRMOY3YenLGKw1NsUi9mEZN4wHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492435; h=Content-Type: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=IeYVflmQIXuUpiQZZ5dzz4ZXkBFzZ9p/wIY3g9/xKnE=; b=kGMHRGBGoS9OqxgH9ovS3dM3+pMOG7Bhu5kBEWGnV8V5ou8xLVp46D/APgMAlABlsyQioToMRL9+fE5wSKP94m4Ap9aVkDFwgXBs/nEvKRa32/l37KKeLnxWtXoo9P0xXLNbGiNGoqry1JDK9ztMouisjNHrjX3sWExQgRnZGYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 1752492435831441.71159515326985; Mon, 14 Jul 2025 04:27:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEw-0000Xv-Th; Mon, 14 Jul 2025 07:20:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1H-0001r0-Mc for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1D-00029p-U3 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:49 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-vnG5rIWPNe6-3mnEbyKjpQ-1; Mon, 14 Jul 2025 07:06:44 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-45597cc95d5so15274055e9.1 for ; Mon, 14 Jul 2025 04:06:44 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd180fsm11950860f8f.2.2025.07.14.04.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IeYVflmQIXuUpiQZZ5dzz4ZXkBFzZ9p/wIY3g9/xKnE=; b=d66Q0z6DhUza/SWQnnV6vZajHR8TAueZSCKSfeGGWZrxSDH8ZUR00f/my4c7xAIJhFtS8o FndBhJD77EM+IQ9eZf5u054FZvEembfnfS61UUOlUwLQzrpAnk8Dpb/mjssujX38y48DjT PyxMXJTTeZKZ8ymyk7sysYcbtEuY9Kk= X-MC-Unique: vnG5rIWPNe6-3mnEbyKjpQ-1 X-Mimecast-MFC-AGG-ID: vnG5rIWPNe6-3mnEbyKjpQ_1752491203 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491202; x=1753096002; 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=IeYVflmQIXuUpiQZZ5dzz4ZXkBFzZ9p/wIY3g9/xKnE=; b=kG89hDzIrM23TsEYMZLMQHFxsXGNDJQntHJ/kHXDrOauYjVSYPnLyQuSnGVkjYzlpu lNuHhjUVln9fNodw6/bvBHHpLB/FfjqOEw3ecDso8gUvlFf7wpV7gfp2qcKNH1c0LX9f gIvDCw31DE2XFHs7/CvI1HAxcGKJzWPwj98TvdMvaVg70vs4A4eVJkw2JKEHfuIDqRpT xv/R4AfL2BF3oE9fMuY3GUazem45Gwb9Mymn6j5da+r710zYpuqalMmq1oO/F+i1oAcE fhH+SG168g4uh6eK7Gcc8zyLH5tzRInO90SiFxsczTw2y/Fu96C0y1Omqnyg9/cIkbx/ 5f1w== X-Gm-Message-State: AOJu0YykPBpwjNLsDHvrSdH/0DgSJoOsZg+eZehDDyKq8FstH4BKdnfN 9Aj8+73r0jBNgadIFzUqywBms4NcgG8wzIkk5IGyq10CMx5D4Y4NE1f0OFs3OfiQeY/X5RSUnhY 3ca5s86pqCPPImHHQhlHTQyJn4Wr0/xYf1ulilM8/SV/UEVq8JBxYp/bK/HVA0iyXg/QkBM3AQ8 kLKCg03k/n9rlr5Ass/1p1ywrc4/umdrDHgqN3wr4J X-Gm-Gg: ASbGncsrunQ9tsXhGhRoLlXFFGmUD9fylX9OvJ9agJafRVpPCo9kx2Ssb0jC6zTyxep Ybs4C2KlNSvQ/WoWhbT45DnQrQ63jf9RU6LafWCiQbCngNFZIuW85XoT7t5N02fzSwR3VsaouDu 9XIGt3KHpob6SmGHKVC6OXHUSvrmZBeQ6/qNqLKcmFmPxCvA4x7FxC1szbpdvSzVssZuutIgFRw R4g63sv60IRFBBoYQa2thrOqhuFsHg2+/rniPMv/OV6RJvmij1WC15DOzT5jUsiUkDQDcr2t9gm CaV3rXx6ZaRZKthuB5PaVF6JgPNu8CEQIMaavJjqCUU= X-Received: by 2002:a05:600c:4eca:b0:456:1abd:fcfc with SMTP id 5b1f17b1804b1-4561abdff33mr25859685e9.25.1752491201747; Mon, 14 Jul 2025 04:06:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7Bwakdv5CcDFJq+10DU82ym/EXEdtr+XNdEpbDjiUmr1YiNkZ1m9ly+DUZbQ99Sb1BwayVQ== X-Received: by 2002:a05:600c:4eca:b0:456:1abd:fcfc with SMTP id 5b1f17b1804b1-4561abdff33mr25859345e9.25.1752491201274; Mon, 14 Jul 2025 04:06:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tejus GK , Jason Zeng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Dapeng Mi , Tao Su , Yi Lai Subject: [PULL 59/77] i386/cpu: Introduce cache model for GraniteRapids Date: Mon, 14 Jul 2025 13:03:48 +0200 Message-ID: <20250714110406.117772-60-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492436913116600 From: Zhao Liu Add the cache model to GraniteRapids (v3) to better emulate its environment. The cache model is based on GraniteRapids-SP (Scalable Performance): --- cache 0 --- cache type =3D data cache (1) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0xc (12) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 49152 (48 KB) --- cache 1 --- cache type =3D instruction cache (2) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 65536 (64 KB) --- cache 2 --- cache type =3D unified cache (3) cache level =3D 0x2 (2) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x800 (2048) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 2048 (size synth) =3D 2097152 (2 MB) --- cache 3 --- cache type =3D unified cache (3) cache level =3D 0x3 (3) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0xff (255) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x48000 (294912) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D true number of sets (s) =3D 294912 (size synth) =3D 301989888 (288 MB) --- cache 4 --- cache type =3D no more caches (0) Suggested-by: Tejus GK Suggested-by: Jason Zeng Suggested-by: "Daniel P . Berrang=C3=A9" Reviewed-by: Dapeng Mi Reviewed-by: Tao Su Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3c28e9588af..d1fc74eb0e3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2883,6 +2883,97 @@ static const CPUCaches epyc_turin_cache_info =3D { } }; =20 +static const CPUCaches xeon_gnr_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x0.EAX */ + .type =3D DATA_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x0.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 12, + + /* CPUID 0x4.0x0.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x0.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 48 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x1.EAX */ + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x1.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x1.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x1.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 64 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x2.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 2, + .self_init =3D true, + + /* CPUID 0x4.0x2.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x2.ECX */ + .sets =3D 2048, + + /* CPUID 0x4.0x2.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 2 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x3.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 3, + .self_init =3D true, + + /* CPUID 0x4.0x3.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x3.ECX */ + .sets =3D 294912, + + /* CPUID 0x4.0x3.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D true, + + .size =3D 288 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_SOCKET, + }, +}; + static const CPUCaches xeon_srf_cache_info =3D { .l1d_cache =3D &(CPUCacheInfo) { /* CPUID 0x4.0x0.EAX */ @@ -4951,6 +5042,11 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ } } }, + { + .version =3D 3, + .note =3D "with gnr-sp cache model", + .cache_info =3D &xeon_gnr_cache_info, + }, { /* end of list */ }, }, }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492978; cv=none; d=zohomail.com; s=zohoarc; b=ECdCQsF5F8X65GDt2+IBMAvBZvY5QDg7qaISP8v3I+DOUweqhfz+GjpJBJOZ6YSMWGoDtlAaN4pVNV9YGQYu1Q3D4wRXQCXxtlAmgwQS9zjXFPL9ox6RAykH3RbmBjnRBbsxXq8Vhgt071F3dgJQ6SBixRW09U+jeKhGNhd7nWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492978; h=Content-Type: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=gbO1ToDtiUiii5SeqRxswGcPOFB4IlcJ2O71e0W8uxg=; b=elgnx9rpkUbe+avqTc7d9sGSY077vrsbgJNS2WSck6nphaMHn8l1aPezaTL/BWcbTb6+qII08Z/8+YWVEgjPQ537uycZxMzcHfSM3APQEs5vY1YwrX070mrx5xw7yDZFAkAt44RWsyny4aT1MZnQrJNlrsdusGrwMQ9AzqVlTOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492978256368.54640505904626; Mon, 14 Jul 2025 04:36:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEh-0008Kj-UV; Mon, 14 Jul 2025 07:20:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1P-0001uN-2P for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1H-0002B4-C1 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:54 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-QNkXd3K9OJubumF0v90_uA-1; Mon, 14 Jul 2025 07:06:48 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4560f28b2b1so4928995e9.2 for ; Mon, 14 Jul 2025 04:06:47 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e2747fsm11855976f8f.100.2025.07.14.04.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gbO1ToDtiUiii5SeqRxswGcPOFB4IlcJ2O71e0W8uxg=; b=HwQRXB40VbTzhCJr/X7pSCd2CR54vUjI3jC5JqfhJfK43Xvx5FaIWEfZKl1Wn9kY3AhWLT TkFKUFx+7vrcHz44CRheIlvoSGtFNw5hPoWX0SxyOu+jI+BtDnUFcJW6eAaex6dNYv3CGk xoKzhc7/4RqP/AWxjNFVdD9nUfduLII= X-MC-Unique: QNkXd3K9OJubumF0v90_uA-1 X-Mimecast-MFC-AGG-ID: QNkXd3K9OJubumF0v90_uA_1752491206 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491205; x=1753096005; 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=gbO1ToDtiUiii5SeqRxswGcPOFB4IlcJ2O71e0W8uxg=; b=NZWGpz/dVdfRiS3jJG7rJICYY0Tc95VbpoieW5guz9zT/hRJ30VcaW6vPkUp7q9hvd Jxf0DxizsZmUUWfRSyDgkvOw9Z4X2F5hczP65g3ixZFKQu2ZhKi/RAfL4/teoa2b/pA1 dppl3d4XLqLjld8UH0XQF2y38ZK9JW98oGrTI+iVH3f1IN5oAFckKshnecrMfIYfpsZb KT5406eyIt9jIZY1Bd9Nfm2D82xMJE5JPAorgjkpjZtpo6tBGfn8h7FwAhiNQR5e2zdG +zbhb6POtMfA4FECRZIBIxlGz8FD5o3FcOVz20R6ce9YpjA84ZhamXJPW9EKls3dGZka 4qCQ== X-Gm-Message-State: AOJu0YxKIwiwt8VLVDCub3Cc08JDxQbAWZylR5bt9VAwkx8atneVbCux +guQc+i5Mjvqt6ts2CwBj3HhmWGhIHfLnDiE6COGfegs5OdPeXgYRpzUglzWjQKKXC3wdhumfD0 w1hphxIV6PU7xlV6PRa0XtuUMSGuYd7R5URsQtsIU5IiPZKmZVmxNtLHQVHBj8/wcWthBwdfR+f hd7oRKxVJL9YkPn3OXBRpCIKHZBbFhJJg7I7aYetrn X-Gm-Gg: ASbGncsB4RXvzbC7fhCvRA1qhkUANIlANFQD6CeHryHPpV1bRrbh5yMwRho5eXvns7B BO9DpiMJWjwtEF1SYB9vMeYpwSYZPLSCEChx9LFd3ly47pRx4XsEWaPSCq6bW88+j1SuKGMYDrD cBfqL9w4aHhNl6+GLqAlnqF0vZCDDEplpU7QtTd4pakJe4eL6EiPDwiOYWCzcCU8tMBpAsjxqSw ofmHHpBkpxhpjmII6YZDWq90m3D498Ogn6b0SJfkOCrBbbVl+08ne1Fe/W7nEK5LE1qIZkox51B oQjJqvu4EU1hGTZSh62xNhIEKxOQ00CWmJt/HaDTGmk= X-Received: by 2002:a05:600c:34c5:b0:43c:fe5e:f040 with SMTP id 5b1f17b1804b1-45565edc8f4mr99213105e9.23.1752491204644; Mon, 14 Jul 2025 04:06:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7D91aUOhqY11/funSDOFl9sVYjqIpeRmDlEvZG0s41X6toPTEeJMFBX8tx5aADgtwipU96Q== X-Received: by 2002:a05:600c:34c5:b0:43c:fe5e:f040 with SMTP id 5b1f17b1804b1-45565edc8f4mr99212695e9.23.1752491204097; Mon, 14 Jul 2025 04:06:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tejus GK , Jason Zeng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Dapeng Mi , Tao Su , Yi Lai Subject: [PULL 60/77] i386/cpu: Introduce cache model for SapphireRapids Date: Mon, 14 Jul 2025 13:03:49 +0200 Message-ID: <20250714110406.117772-61-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492979482116600 From: Zhao Liu Add the cache model to SapphireRapids (v4) to better emulate its environment. The cache model is based on SapphireRapids-SP (Scalable Performance): --- cache 0 --- cache type =3D data cache (1) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0xc (12) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 49152 (48 KB) --- cache 1 --- cache type =3D instruction cache (2) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x8 (8) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 32768 (32 KB) --- cache 2 --- cache type =3D unified cache (3) cache level =3D 0x2 (2) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x1 (1) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x800 (2048) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 2048 (size synth) =3D 2097152 (2 MB) --- cache 3 --- cache type =3D unified cache (3) cache level =3D 0x3 (3) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x7f (127) maximum IDs for cores in pkg =3D 0x3f (63) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0xf (15) number of sets =3D 0x10000 (65536) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D true number of sets (s) =3D 65536 (size synth) =3D 62914560 (60 MB) --- cache 4 --- cache type =3D no more caches (0) Suggested-by: Tejus GK Suggested-by: Jason Zeng Suggested-by: "Daniel P . Berrang=C3=A9" Reviewed-by: Dapeng Mi Reviewed-by: Tao Su Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-4-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d1fc74eb0e3..b3b29f69666 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2883,6 +2883,97 @@ static const CPUCaches epyc_turin_cache_info =3D { } }; =20 +static const CPUCaches xeon_spr_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x0.EAX */ + .type =3D DATA_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x0.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 12, + + /* CPUID 0x4.0x0.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x0.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 48 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x1.EAX */ + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x1.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 8, + + /* CPUID 0x4.0x1.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x1.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 32 * KiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x2.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 2, + .self_init =3D true, + + /* CPUID 0x4.0x2.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x2.ECX */ + .sets =3D 2048, + + /* CPUID 0x4.0x2.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + .size =3D 2 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x3.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 3, + .self_init =3D true, + + /* CPUID 0x4.0x3.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 15, + + /* CPUID 0x4.0x3.ECX */ + .sets =3D 65536, + + /* CPUID 0x4.0x3.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D true, + + .size =3D 60 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_SOCKET, + }, +}; + static const CPUCaches xeon_gnr_cache_info =3D { .l1d_cache =3D &(CPUCacheInfo) { /* CPUID 0x4.0x0.EAX */ @@ -4889,6 +4980,11 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ } } }, + { + .version =3D 4, + .note =3D "with spr-sp cache model", + .cache_info =3D &xeon_spr_cache_info, + }, { /* end of list */ } } }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493929; cv=none; d=zohomail.com; s=zohoarc; b=i6UYfkgnt3JxavgZJqiRrgO29u4uEkiV3fLEWb5r+wCitE4gUnByfPGpvlKcGDMwuYRKecHUNWo9TCqReGzbnk8gQY8s4f6GDAXPvqMTNB0kw298gaFbuLnRwLqNBYZ7joDBRZfXbahGB7/41s6SOys53yvJH1+Oe2OTL7WxLsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493929; 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=oOKJ7k5EUKjWP5vYqwIlq0vfh3oRU4VVY5lSk531NFs=; b=WYme3xWVXpbfKV5B/tYyRvdkeftgdWbjRHISWrsPKgDcgPiitHjH6ry8XFzJuYLPZDh/ohggbAVKjXDDxDIpBo/TIErG6bTfaEsefish789C0nkGVz+3ayCb9ur+HmRB0dtmdbqUZIDjirkbbCyS1WNFHJb1N/PH4Dji+pToixw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249392944173.63214468565138; Mon, 14 Jul 2025 04:52:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHYd-00019d-DS; Mon, 14 Jul 2025 07:41:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1P-0001uO-2i for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1I-0002BD-Kc for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:54 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-qzVnPUrdMsGGRBEFTP7dKg-1; Mon, 14 Jul 2025 07:06:48 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451d2037f1eso27403585e9.0 for ; Mon, 14 Jul 2025 04:06:48 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-455f2d3a1b5sm86609585e9.30.2025.07.14.04.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491211; 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=oOKJ7k5EUKjWP5vYqwIlq0vfh3oRU4VVY5lSk531NFs=; b=eUvP5iOGh37E0nCxF8sTq4PYNddrV16x425fjS79n/FjG8P9BHwQbOXKnhWn93dQFwmuX3 E/pdJztcYvXOgXGh6/JLbjXbm78Cpwn60oTKnyacFVMT82qsLI2qixdPuzWD7TUoxNsg+Z hli/iieqG9EMqei7UKQ1kom40svMs84= X-MC-Unique: qzVnPUrdMsGGRBEFTP7dKg-1 X-Mimecast-MFC-AGG-ID: qzVnPUrdMsGGRBEFTP7dKg_1752491207 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491206; x=1753096006; 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=oOKJ7k5EUKjWP5vYqwIlq0vfh3oRU4VVY5lSk531NFs=; b=BjoV8+LasCelEF85ucRs9TNd9bMK7JYlJNrGZnVdy113M7An5RzO3v6TkdztJVlGLf tF1E4TOy+NLSl9o4a+ZFGeRGfk2EGuN8vN1fP2ZHViHjCtdFH88TZWcb2CeXuf5PNktR iZzKkuA9UvlJiEu+TV87jZ8KDjUlkwHHp6uhyssvQCDLU0tQV844JVSxgNR6mhG20r+X AysjMJ/r8JKLbTNLuUwv3yLI2n2srTs0JByxt041l0sI9AIjeCnKDKnUTi8QqpAdfxiV 6RJfROXvnw8bh2yVWe5+4SMsJQVDId+2tfPhocy9RGmNkWGq5qxKXpeqUQhX0r+XAcQI YNnA== X-Gm-Message-State: AOJu0Yzg2GsAaGiza0+lXngjcXYGcGLH28w9kZBf8CsKnDt8/ssDprWy pDiRXi3yqrL8LNJ8L4QASdCZX77sVeu2TkZgukUt6pZpK2SMb/9xL5gAQVgeNl8bTSSv5JEtIxv EuJB4tKYlHsI+kONN9grr5lyga7cvQx3PNUojO5wGB2pUJhZhRxujl4VDEBXd9sAj21kWkaGZPA cxmZUvSpT2xWx7WN41TcyuYq4JYeUPkSgLkM0/Lv5k X-Gm-Gg: ASbGncuxe4zY6tZxwZGv9lsOsdt8+EPRTHBPRXxxcBZ5aLHYCDgUgxP2WtbUNLZ4oqP 7uVXCmHcdWCOnYyXIbY+ZgGcbuDdmBfXlPTbU94VeFO66nBGVdPDRPtZPINw+PY4ynBoSxt8jI2 gXwupLCOBirgbXeZMs4uSs/Df1hXNqIOTMyplY5gxwHhzQL6d4x+bmOn0BYI2VsS1j4vAhLgvYz qa0MePbk+mOIlT4jKsNTuWNDrjrN+TZTXjz2WfOBPwP+/1SV2yYiT3KE38AxjwMZfcs+Ln2H0DH paxj304B1go5QO6OEdpMjt3sy0mWv4rVGjgfGHJlh+I= X-Received: by 2002:a05:6000:1a87:b0:3a5:3930:f57 with SMTP id ffacd0b85a97d-3b5f2e3722amr9638637f8f.51.1752491205992; Mon, 14 Jul 2025 04:06:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpN4ER/MVc3ocntOVAK91nIlJUFPtS9McML9XrvTW/0Wli85ksa13lGcv/9TPQLO7TYEPjVQ== X-Received: by 2002:a05:6000:1a87:b0:3a5:3930:f57 with SMTP id ffacd0b85a97d-3b5f2e3722amr9638596f8f.51.1752491205405; Mon, 14 Jul 2025 04:06:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ewan Hai , Yi Lai , Zhao Liu Subject: [PULL 61/77] i386/cpu: Introduce cache model for YongFeng Date: Mon, 14 Jul 2025 13:03:50 +0200 Message-ID: <20250714110406.117772-62-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493931369116600 Content-Type: text/plain; charset="utf-8" From: Ewan Hai Add the cache model to YongFeng (v3) to better emulate its environment. Note, although YongFeng v2 was added after v10.0, it was also back ported to v10.0.2. Therefore, the new version (v3) is needed to avoid conflict. The cache model is as follows: --- cache 0 --- cache type =3D data cache (1) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x0 (0) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x8 (8) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 32768 (32 KB) --- cache 1 --- cache type =3D instruction cache (2) cache level =3D 0x1 (1) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x0 (0) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x40 (64) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D false complex cache indexing =3D false number of sets (s) =3D 64 (size synth) =3D 65536 (64 KB) --- cache 2 --- cache type =3D unified cache (3) cache level =3D 0x2 (2) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x0 (0) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x8 (8) number of sets =3D 0x200 (512) WBINVD/INVD acts on lower caches =3D false inclusive to lower caches =3D true complex cache indexing =3D false number of sets (s) =3D 512 (size synth) =3D 262144 (256 KB) --- cache 3 --- cache type =3D unified cache (3) cache level =3D 0x3 (3) self-initializing cache level =3D true fully associative cache =3D false maximum IDs for CPUs sharing cache =3D 0x0 (0) maximum IDs for cores in pkg =3D 0x0 (0) system coherency line size =3D 0x40 (64) physical line partitions =3D 0x1 (1) ways of associativity =3D 0x10 (16) number of sets =3D 0x2000 (8192) WBINVD/INVD acts on lower caches =3D true inclusive to lower caches =3D true complex cache indexing =3D false number of sets (s) =3D 8192 (size synth) =3D 8388608 (8 MB) --- cache 4 --- cache type =3D no more caches (0) Tested-by: Yi Lai Signed-off-by: Ewan Hai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b3b29f69666..40f3b5eac88 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3156,6 +3156,105 @@ static const CPUCaches xeon_srf_cache_info =3D { }, }; =20 +static const CPUCaches yongfeng_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x0.EAX */ + .type =3D DATA_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x0.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 8, + + /* CPUID 0x4.0x0.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x0.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + /* CPUID 0x80000005.ECX */ + .lines_per_tag =3D 1, + .size =3D 32 * KiB, + + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x1.EAX */ + .type =3D INSTRUCTION_CACHE, + .level =3D 1, + .self_init =3D true, + + /* CPUID 0x4.0x1.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x1.ECX */ + .sets =3D 64, + + /* CPUID 0x4.0x1.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D false, + .complex_indexing =3D false, + + /* CPUID 0x80000005.EDX */ + .lines_per_tag =3D 1, + .size =3D 64 * KiB, + + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x2.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 2, + .self_init =3D true, + + /* CPUID 0x4.0x2.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 8, + + /* CPUID 0x4.0x2.ECX */ + .sets =3D 512, + + /* CPUID 0x4.0x2.EDX */ + .no_invd_sharing =3D false, + .inclusive =3D true, + .complex_indexing =3D false, + + /* CPUID 0x80000006.ECX */ + .size =3D 256 * KiB, + + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + /* CPUID 0x4.0x3.EAX */ + .type =3D UNIFIED_CACHE, + .level =3D 3, + .self_init =3D true, + + /* CPUID 0x4.0x3.EBX */ + .line_size =3D 64, + .partitions =3D 1, + .associativity =3D 16, + + /* CPUID 0x4.0x3.ECX */ + .sets =3D 8192, + + /* CPUID 0x4.0x3.EDX */ + .no_invd_sharing =3D true, + .inclusive =3D true, + .complex_indexing =3D false, + + .size =3D 8 * MiB, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, +}; + /* The following VMX features are not supported by KVM and are left out in= the * CPU definitions: * @@ -6435,6 +6534,11 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ } } }, + { + .version =3D 3, + .note =3D "with the cache model", + .cache_info =3D &yongfeng_cache_info, + }, { /* end of list */ } } }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492215; cv=none; d=zohomail.com; s=zohoarc; b=dTqVrxBpGj5661crLrvAk6kYNKRtujARNHR/biR1Z7HF6bN+6+FyqbejZqJs0tTlOkb98aVyjtmgbFaTQoviK5mlmQINEmh74osXpG7x5T2nF/70TFqQGSyuiR8MC+WS6WSYSOPSc/PINH0qhrNkdwZFfVULMuLCIC0G9hR1NJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492215; 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=N8l/csJz6aqWH0HqNXLPqKmWn5tg99krkmHfDQiMl9E=; b=At++53RWw6xxdFGqaBFqaNgijjjF3RP4tyU0pLAOIi3EuzAmOVD0zzC8ACDWn8iOhvWcNBP+HqiPMwdc1FQZ7+dvcOUiIc1R9swhmvZXHTGbADwYhMW949aV3PzzDdaOb4+l3aPnODM5d7Q/sZT/rYy9z+Oq4yxidfhlS4nTF8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492215294707.4534271493573; Mon, 14 Jul 2025 04:23:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHBj-0004jX-7D; Mon, 14 Jul 2025 07:17:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1P-0001ua-FC for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1K-0002BO-IJ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:58 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-XXLVFf2hNzywSsCsjd1sKg-1; Mon, 14 Jul 2025 07:06:51 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4561dfd07bcso3354525e9.1 for ; Mon, 14 Jul 2025 04:06:51 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e1e1d5sm12164024f8f.78.2025.07.14.04.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491212; 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=N8l/csJz6aqWH0HqNXLPqKmWn5tg99krkmHfDQiMl9E=; b=MzgGAUkNZvYEYP3pqEWSC6FPekTiGnspjigF5Sji2rI2dk5oaejxlDQDM/xDJ118QGmddA qCxZiuo8nkpJdj1k5r0OjlYmQwoq5pR3OK3snWcqBvqPPHghvXf//U788m+wxPlHw+b1zx AbZ+Y8I46W3hkngxb6M9B7JeaV6zDZM= X-MC-Unique: XXLVFf2hNzywSsCsjd1sKg-1 X-Mimecast-MFC-AGG-ID: XXLVFf2hNzywSsCsjd1sKg_1752491210 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491209; x=1753096009; 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=N8l/csJz6aqWH0HqNXLPqKmWn5tg99krkmHfDQiMl9E=; b=XPF6gJoqsAuY6qBoDxzVloJxt2ePKJizzOY6eAllYaVf0wuPoFuZC2DueCwmg8DXVV Sf5Q8RAV0z9irvSA8afYuua0Bic1QYz3g4QaE/FqP0w+hcN4hH0z87qy7XtylP7tGVos 9xnpTcDfqI74cCa5AEdbe/HjI74uxAzG9sxJ+d4l8XuSWUtXCGSeJa/Ax28D7TEOItsf EEd5wShQ3cGNZ8gckusmDxbOwm6ZSTG6gFbv4C4NRm6oUSSo5Y18zLPWyyILZK1Bq13E fGUZFzNF8+tlrdiaLtFLtGnwxAu179Fjz0rT8Nx3UfTxZVyumUkIRMEp4SYuGh7rhwnC qfCA== X-Gm-Message-State: AOJu0Ywi54o4DaMl1krPuukGRRjEETveIb4o4Q/0K15Jw4GK+VQA29fQ z5QLtRJ/vSKyuuEL+BYbSGJ4+WkH3wnw7vqmnoFuyZYniUrmzImh2nJdocXUkhrjpEvd+BWv3MX 8oFyyclSrky/VoPgiZE6ZXGpx+GKmJjCAq4jc+lZLNaj1hXHHL7aJxMUZ4hBOTgWxDtKeidalTP pqsL9u2dUO+HOOOeghEriikV4XO2Y3QEU7+4OJ2puY X-Gm-Gg: ASbGnctp3aha3tZfJ2047/ZPGQSGA5d3R5nNdz8n/SB3iiAfClgM+jsr1w3UqEb5tra xbpi014s+x0366e/gOF9hD76GWCopxb5DV18hhrTDxzGlUDriTZ4bNs+QBr3ExrCUyPYjmHuT0o lI4BBpFAXY6dTKXEBU4fOkBYKFX1oEjWIMKBT5IV0F1e8cy/19fiqF/VNpM9IEGjHwkp6VYDOnK xw9V8zgwuSLzwl+vU/4QL5M/5FrOHQ06eVAAouf6/zl//0xxKtbFdED3LSJGt55w7R7/Ai5yCUT NXUb9zH4XdLx3Vd21SxLHTVvFrHuYWiwS6b1mweqem8= X-Received: by 2002:a05:6000:2d82:b0:3a4:ead4:5ea4 with SMTP id ffacd0b85a97d-3b5f1895c6dmr7159568f8f.24.1752491209217; Mon, 14 Jul 2025 04:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxmPZwIme1PXX6Qy7MSnj9mcpH8ZntQM9JI2HQvkdeKbMmt7x+0UOw4sY+A5o9bbkDAXGBEg== X-Received: by 2002:a05:6000:2d82:b0:3a4:ead4:5ea4 with SMTP id ffacd0b85a97d-3b5f1895c6dmr7159542f8f.24.1752491208641; Mon, 14 Jul 2025 04:06:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manish Mishra , Xiaoyao Li , Dapeng Mi , Yi Lai , Zhao Liu Subject: [PULL 62/77] i386/cpu: Add a "x-force-cpuid-0x1f" property Date: Mon, 14 Jul 2025 13:03:51 +0200 Message-ID: <20250714110406.117772-63-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492216720116600 Content-Type: text/plain; charset="utf-8" From: Manish Mishra Add a "x-force-cpuid-0x1f" property so that CPU models can enable it and have 0x1f CPUID leaf natually as the Host CPU. The advantage is that when the CPU model's cache model is already consistent with the Host CPU, for example, SRF defaults to l2 per module & l3 per package, 0x1f can better help users identify the topology in the VM. Adding 0x1f for specific CPU models should not cause any trouble in principle. This property is only enabled for CPU models that already have 0x1f leaf on the Host, so software that originally runs normally on the Host won't encounter issues in the Guest with corresponding CPU model. Conversely, some software that relies on checking 0x1f might have problems in the Guest due to the lack of 0x1f [*]. In summary, adding 0x1f is also intended to further emulate the Host CPU environment. [*]: https://lore.kernel.org/qemu-devel/PH0PR02MB738410511BF51B12DB09BE6CF6= AC2@PH0PR02MB7384.namprd02.prod.outlook.com/ Signed-off-by: Manish Mishra Co-authored-by: Xiaoyao Li Signed-off-by: Xiaoyao Li [Integrated and rebased 2 previous patches (ordered by post time)] Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 40f3b5eac88..482979a4437 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -9940,6 +9940,7 @@ static const Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("x-intel-pt-auto-level", X86CPU, intel_pt_auto_level, true), DEFINE_PROP_BOOL("x-l1-cache-per-thread", X86CPU, l1_cache_per_core, t= rue), + DEFINE_PROP_BOOL("x-force-cpuid-0x1f", X86CPU, force_cpuid_0x1f, false= ), }; =20 #ifndef CONFIG_USER_ONLY --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493983; cv=none; d=zohomail.com; s=zohoarc; b=g4e0jjEhv/MeAIKyWMoRF8PQZyYnQkWWCDVoI635lAjLAaCz8ZxDiRkSoziZycvhRgnsqw8veRj28OKvimjk4SaQG2IyfP2Tnmty5uHhsuvTH0tArFNXJDok2onXI0gwG9uiewZ8YCqns8y0zzA6f5/G+4PWToXQg89ff4epsn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493983; 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=pMfqWPvcVidmxEBK4/G1WoAxmiQybmAc7UCJEFyhd7U=; b=FFLQMkwN9RFo7ATNzLn8PP4PTXrvX9Azx7gaB/Ow6mBUcQzJaHe3JcTkDRh0jYffC81pgKa9BC3HGws5Cn77CT6wlqMurfn11SV7SVKzu0nJkX9Lel1pqf2PmJPeURP9HC9R0bRoMiTRRNnIyfwhw5eODGZ1smXO8QPybmwL+10= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493983060851.4337428728281; Mon, 14 Jul 2025 04:53:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEc-00088Y-5Z; Mon, 14 Jul 2025 07:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1R-0001vC-JH for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1N-0002Ba-AS for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:00 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-6pzZzK-xN92DCJHXbGK4HQ-1; Mon, 14 Jul 2025 07:06:53 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-451ecc3be97so22106885e9.0 for ; Mon, 14 Jul 2025 04:06:53 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d867sm12298615f8f.61.2025.07.14.04.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491214; 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=pMfqWPvcVidmxEBK4/G1WoAxmiQybmAc7UCJEFyhd7U=; b=Eotwra1YZoIIbkOmkRxE0dDlEsnYCVok4/LtuAynh0rQcRrmcpSf0Uj9uUgQJneDwhRoeB 4wsoC3nnTPK/yOsu0xeCM7N2cWlW3Wd9uI3ohqKI/PpK6bxMhpq45s123Yhu76/+gsWmPC P6WFF7uOoJ9v+FYvH4ZdmOtEew9aiyo= X-MC-Unique: 6pzZzK-xN92DCJHXbGK4HQ-1 X-Mimecast-MFC-AGG-ID: 6pzZzK-xN92DCJHXbGK4HQ_1752491212 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491212; x=1753096012; 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=pMfqWPvcVidmxEBK4/G1WoAxmiQybmAc7UCJEFyhd7U=; b=RkYJOZUcSnJ9uJcLsZztZfkmkXsfanE/XLfGJZH3ct1QGDRKoVhON9I27w54oizDzO +mYLnG7Zlo4qt6cmThQ6EA+Ivpc3cQDP1ob7KFJPvCfOoDwHneQVojMv6K7jMtu51Qbc OWhvuHS55mNGCAfuG+793CGyzIEOeLwyG7eTcOvtabEN0IHuhs+/N7ZRRQPTniONMMux EFpC/4hsBPdvtJ185rZQC+keRiSqdLlhYI6FMOMz9MDswR3ZUfTdJoZzYDAMJpop5zDl pqnou33o6zsXSK+zSP2LtTWLvaQRXuqQBF1hOFvRTSa+2/N62acTOmsF24mxCPT7Bh1L df4A== X-Gm-Message-State: AOJu0YwEjnTSqRDSYojruLfmpH+PvsRZINONCrO9sqDX8oGEs2MvvFjr qZRdy14CkaKtrhO6BagrerJ3QXZjoQoQJrWxAy83ko97ZZ6s2X8Zd6PEAibw51YGj91vU30Gjxw 7uOSxbnuu34b1I2YhUi6AikooVCktjlkKnIyQCUUgyt9/RDHuHaA3nm2YkLcPTvhdMbeSKdAyPT rmbMMhi2rDGllZt3m8kJ9dOecNGoEbJ95l8Mwsxaiu X-Gm-Gg: ASbGncvQVV6udI0vHNYa/WmTbU5ZMrEePEbXHMJ8Bme0u+c+pItqXAtFoIVJ+zChSsQ qrfSpHTkgIt15rW4wjqgRO1Xu4LisuGFZXtIFTHlzHrXE8q7d+yovEOsIX+CRVjnclIzQ/2T/II WPxkGt+yWOSTyatHsMZuitzT4XK17lF6COhsDX60mGDj7v3qQyPI72LtqE83XUcnng/fgh4jAyc BEwb8cz7qygAnFqsHL6iVwUmiFyG50OeujErxyy09q6ujE3n1aoORVkIN883Ef0NcxRG3YKDmLL 4WahpekAEumsAesPgVCEAnLWiuS50sg9KTBgWtlY1A4= X-Received: by 2002:a05:600c:858a:b0:453:5c30:a1fd with SMTP id 5b1f17b1804b1-4556f8a7931mr59412105e9.8.1752491211632; Mon, 14 Jul 2025 04:06:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFv5bCRunCofTJumNggl6l+ykKbwR+Rw5um5Et3CuTryT2Tg1cTsH4xsquumTaKKuEAqfXJbg== X-Received: by 2002:a05:600c:858a:b0:453:5c30:a1fd with SMTP id 5b1f17b1804b1-4556f8a7931mr59411855e9.8.1752491211040; Mon, 14 Jul 2025 04:06:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Igor Mammedov , Dapeng Mi , Yi Lai Subject: [PULL 63/77] i386/cpu: Enable 0x1f leaf for SierraForest by default Date: Mon, 14 Jul 2025 13:03:52 +0200 Message-ID: <20250714110406.117772-64-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493983528116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Host SierraForest CPU has 0x1f leaf by default, so that enable it for Guest CPU by default as well. Suggested-by: Igor Mammedov Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- 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 482979a4437..668f3e63b7b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5389,8 +5389,11 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { }, { .version =3D 3, - .note =3D "with srf-sp cache model", + .note =3D "with srf-sp cache model and 0x1f leaf", .cache_info =3D &xeon_srf_cache_info, + .props =3D (PropValue[]) { + { "x-force-cpuid-0x1f", "on" }, + } }, { /* end of list */ }, }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493450; cv=none; d=zohomail.com; s=zohoarc; b=edec2aC/NxnZb9CuNbRYp/GvVxdgU3BLMTfDbF0Ji6/yoMeAh8EPo/NCWbVsMMjthQ+fDmwsDu8KfVfj5nmu0WcGvQLFt2FdlRG74uvuNaauaCduTCHvLLETPsXrQm//35Fszmf62OsEnI5/CiUTkEFJly8wDhevyGFV3AHwfMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493450; 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=84v5GMox428L8Z2lGKdNxuVp+eJI5ucAEsNT/SLxcFs=; b=GfxFBd7Vrg1RqvMVnpq4zvZm8WYICUC3HgS7Y99idQHId4vrcnSBnbZBw2MWqhRGj5uen9YA/kRaTIXuJNSS8hxm01Jhy3ruuwvViplU50luA/Y067gFHx8r3o6/cIPpA8mpBxkbpPWPp61YNOgppl3Dwk5WtgREtgJWwiI072k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493450862719.4010097167471; Mon, 14 Jul 2025 04:44:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHXL-0000YJ-Gs; Mon, 14 Jul 2025 07:40:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1V-0001xn-Ab for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1P-0002Bt-7A for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:01 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-jiyigXauNS2BNyFo1oe9dQ-1; Mon, 14 Jul 2025 07:06:56 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a4e713e05bso1834083f8f.3 for ; Mon, 14 Jul 2025 04:06:55 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e26f45sm12230405f8f.92.2025.07.14.04.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491217; 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=84v5GMox428L8Z2lGKdNxuVp+eJI5ucAEsNT/SLxcFs=; b=iIV9RLtj+/pV8bc6gOAPvtyj7Cf4y58SJpmye27CCVP3R+gaTGyoJ/Kh4Gs9kYFoyazCzo S0OVH+n6GpN0/CsqxMBB/76jeq6+UVPEQf/VYxjN5LJujXbfYIKp3AgOfonOo71tlh8hMx Uc5L2sfioGzXSSFWNhRB0z3QoFH2AyY= X-MC-Unique: jiyigXauNS2BNyFo1oe9dQ-1 X-Mimecast-MFC-AGG-ID: jiyigXauNS2BNyFo1oe9dQ_1752491215 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491214; x=1753096014; 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=84v5GMox428L8Z2lGKdNxuVp+eJI5ucAEsNT/SLxcFs=; b=FdswvxFC5fLrR0HgbIGbpkTnO7Z6KBFFajYLsFJZYqi0L+Jq6HC+uxnPJ8bzcvu2jM Q0XFXI31kkwg1tZqjNp+e5rlHcMVowJobGrkOF2x23oJ09bWca7WPFz+8FAaVlMmYeaz kWfwlvZ1uq1Fd9GNBb3HZzfslfIGt8QFfYWQ16u4kXddbpYQJQug3QjlnezhWt03Qwws sm+WeGYUdDG31pVkrRGqXEiDaLz7BQlpMm3ZSGyTo5qpruI20XfyB1WH7+fVfPGxNXoM S/rwehA5j8PrTSCQDqedExHtYPMkQbxbEeES+KC0xUs71x0KQfbTAOK5Ptv/LFQ72nfR wWWQ== X-Gm-Message-State: AOJu0Yxi2Ke46AcGjCADM6BrH54CNath/xODC4c6W3FLS4gufsY1Nkgr PsH9USSPu4CJr08dw303NPIeLtHmGZkQV9hztuFbnQSEaFycr59ZzPsS3cnAwYoY9rxJ7h6ubpn u68CtHwgmz7WMyy8jKFwoIshsqQGvv2BAslqqpDiJc4Xu65bTBQ+cWs6QzThwthXFspbz5O2dyg r3OxDCIjU4Dq42PJ9LYarESQGaV4xCjnUMCgMaefDi X-Gm-Gg: ASbGncvnKScsnc0YHMdLbRbjScxi8jCjIlf/JmfI5KXZ3XywHX8L1MMuDNSAs80Meax u/XTvLM240SX5mOvFcwuDJi4oHVCHvlNSOicPtkTZellXUtS9N9J/CQ0kpgCkn8yvfnGWTg1Txy qOWQ9rRA0GIGh3WxrddHEBjqCty4vou5DV7rx8bePQYMjlPBqiKB1mMtdW7fEhjX8jO6Fr593X/ g8GUAmQDCbrV4DhO6rA0JjMReEj1rwT9UdtlsgfIu77AmyDIwuvzcgyIwApk5OSnLiK7t95Ii85 zqEnLUFLSnpwEmN1CHIXz0SzS23zLgJQ7ykVMPx54OE= X-Received: by 2002:a05:6000:2c09:b0:3a4:f66a:9d31 with SMTP id ffacd0b85a97d-3b5f2dc2becmr9584386f8f.16.1752491214001; Mon, 14 Jul 2025 04:06:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVcspJNQHPtRlUemC6njmJYF/Eg9SFzEzJ81zURpNKGu0W/N+/GmmXytL3LxUS7ZVMkb7FjQ== X-Received: by 2002:a05:6000:2c09:b0:3a4:f66a:9d31 with SMTP id ffacd0b85a97d-3b5f2dc2becmr9584355f8f.16.1752491213563; Mon, 14 Jul 2025 04:06:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Igor Mammedov , Dapeng Mi , Yi Lai Subject: [PULL 64/77] i386/cpu: Enable 0x1f leaf for SierraForest by default Date: Mon, 14 Jul 2025 13:03:53 +0200 Message-ID: <20250714110406.117772-65-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493452724116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Host SierraForest CPU has 0x1f leaf by default, so that enable it for Guest CPU by default as well. Suggested-by: Igor Mammedov Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 668f3e63b7b..c15082e8afa 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5393,6 +5393,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { .cache_info =3D &xeon_srf_cache_info, .props =3D (PropValue[]) { { "x-force-cpuid-0x1f", "on" }, + { /* end of list */ }, } }, { /* end of list */ }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493441; cv=none; d=zohomail.com; s=zohoarc; b=O3lh67H9o4rIO1kY79+Afr4vZADx/iCI+RFHsrVjZYz+81VtUinky9k75lm+O71mK2ho4MBgAoSrDqlzmetL9kTee+pxXNx3EByStEBGPYvkn1QB9PZBipvaCWoIVQX3SrAO6ZNJprSUdX95uLoNS6hs6bpgvYumbmAiaQWUlis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493441; 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=MV2oFzCG81p61oxBJMzjbmDGG+yfWTjq0dyOU3iCtvA=; b=CqVL0BboXWFykumEbCXMFaYg1Jpw33+3ZOAmmbiS71a2BAgHkl6Nop+WpICAV5TMHxY4ypu2Au2U/c0pVfnYflwza+OAvHun23H/AQjf9p+2J5V/VXLOaSKcLi42EBX0mNgW7VKIE6+QAwZCy2WqivLPb0rnq19uE2saluy0WUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493441605848.6443443451038; Mon, 14 Jul 2025 04:44:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHBW-0004Od-17; Mon, 14 Jul 2025 07:17:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1X-0001xy-GB for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1R-0002CL-3h for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:03 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-UCEMOoMtOyOPIWqZg17K2w-1; Mon, 14 Jul 2025 07:06:58 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-451ac1b43c4so22972345e9.0 for ; Mon, 14 Jul 2025 04:06:58 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561323a488sm47008285e9.1.2025.07.14.04.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491220; 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=MV2oFzCG81p61oxBJMzjbmDGG+yfWTjq0dyOU3iCtvA=; b=eKQ6/i7G9lpWOCCUQEOoobSFvUzXh5wLTXp80o9s8hUsKuk2CiEruZsH3AC14UeO+/DFdk VgzrgH0XloZiOq9Os0NydWbPaAEcvxEUTEhu9U7Pao8kdtlZxnSs1bSU29MR4/9rh9NeBt 6EncouhmepEtz0B/jgVsfkXYEwu9hSQ= X-MC-Unique: UCEMOoMtOyOPIWqZg17K2w-1 X-Mimecast-MFC-AGG-ID: UCEMOoMtOyOPIWqZg17K2w_1752491217 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491216; x=1753096016; 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=MV2oFzCG81p61oxBJMzjbmDGG+yfWTjq0dyOU3iCtvA=; b=d5uh64g9ZfoKuLjkvh7gzFnBCvSK5YL/YsSiwaWgVZI0mFq5nZrV6wmVMY/jH/+CXY AZ65ELNSADJpglRRTyPjeyC+Lwj8grE6v/8xyeiMKSGod6ofxhuN6yu+vUb+5hS9QIUr ymyzoByuEmXUJ4ZbPSAqAtDUMUBxJ3iN3nr7Cq7M9bXfnZmowXGQ4TrlzCkeiiGwWtHq e2BGzLa2FrverO7m/c8aBNA6x1KZk2jtBQA9rKdsjhGr/FMMgJbDM4JPMxjLX7bG5sNy HsUGY0bmKUwsRX/qGX12jSuk/E6Gb1lgpicK+KKbYwhqToA3Rg2KeCTCJXS9ie1JZHY+ T1zw== X-Gm-Message-State: AOJu0YwDFG/FcaUTrZdCVY6XYZ7WEEhlJYf9srnQfMCJw/6ffHqHvncv rXY2huNsp6PXGOoBB0BRW7oRwzJyde28i6UnQTtn64V00tLdb+PD87eMb4NY6m6jHY6zGwCPbkt SMRlDP1JttMGGacJY1TrqsCGtlHtEL1lwMo9ZAO0pDOBcGaUn2nouhQtjbfPbbNngHYJvpB/4CU /umuODUTv+eg2aZWjfKrGdI+oAYjKiwDWP5zgOA8Zi X-Gm-Gg: ASbGncspDDHEghsQy/0Fw5xcCDFUaj+3qBUaYWSQkMSgrJ45vMYRNHKWPfW1XfPWsqs qiBDe1qRlvnBtISfuw6/+AT+bFJvjWntjDr9YzEqhoRvnVurpocRuVpSirFxQzaUIPqc1EOhUXr CpoT80EIfcmqMC7LJBX1I21Rk7vUyd+L6e4KSUL7GvGvD0gwPq2uPpZQRf2W9/zkknjorL2vZob VfaOxxJMHSDeODkb0+Idqlw9pVgrL+wtOTSgIu9jFC4f1/jvG60Woelupyyl489Ycdi9nXXoqcE eAIERE2ALh0GqGFOrWMgl3RULdn74ugOQgZ6IOtHc3w= X-Received: by 2002:a05:600c:5406:b0:453:c39:d0a7 with SMTP id 5b1f17b1804b1-45600771e4dmr73957485e9.5.1752491216591; Mon, 14 Jul 2025 04:06:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEvbajeSmwsaqdEPZ55gULI1l/7NoZUhEaAEOPxPKtsv/KCnO3SAPO3RJYl/voWzSfaiW1eA== X-Received: by 2002:a05:600c:5406:b0:453:c39:d0a7 with SMTP id 5b1f17b1804b1-45600771e4dmr73957075e9.5.1752491215949; Mon, 14 Jul 2025 04:06:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Igor Mammedov , Dapeng Mi , Yi Lai Subject: [PULL 65/77] i386/cpu: Enable 0x1f leaf for GraniteRapids by default Date: Mon, 14 Jul 2025 13:03:54 +0200 Message-ID: <20250714110406.117772-66-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493442640116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Host GraniteRapids CPU has 0x1f leaf by default, so that enable it for Guest CPU by default as well. Suggested-by: Igor Mammedov Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-8-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c15082e8afa..a11e9bb1117 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5239,8 +5239,12 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { }, { .version =3D 3, - .note =3D "with gnr-sp cache model", + .note =3D "with gnr-sp cache model and 0x1f leaf", .cache_info =3D &xeon_gnr_cache_info, + .props =3D (PropValue[]) { + { "x-force-cpuid-0x1f", "on" }, + { /* end of list */ }, + } }, { /* end of list */ }, }, --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752495207; cv=none; d=zohomail.com; s=zohoarc; b=I8fJFE+/mKjv/bGpOxoLmM9qFU3xkF9fZpp2JnoQXl0A34iDltalt9OJJBlCXx0Qar9v5+8dpsIT3GkkSk4ePMG5pf9rWLvuMOH5ja2CV0CE7bNs1/E67P2/VHJtjxRku7PgqbHKn+8n+dQ4Xr8xf8IfaOX56UTaC/EowoonLps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752495207; 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=9ldzKRjoCTm1wE0lg8oM0P/4wDs9Nar/4X2QOq18lFU=; b=PmKqQnwSGiRu6qCKOl9PSw5LD/C6yEbA6pqeAhBkEt4+wFbjwNC5vP/XRrIMo160tLPF2wPOuMxgaVv+scV4XVB46mwonbs60n4cDCdStAf+RPb7tCgB1QHbA4jQW9ndus6TDIs/NU5YXSG8yDRw9Nlfy+Z4gmJ6PGGYJEY9YOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752495206991943.6345708803622; Mon, 14 Jul 2025 05:13:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHFT-0000z5-Ks; Mon, 14 Jul 2025 07:21:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1a-0001yY-2K for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1V-0002Cg-35 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:09 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-xVwKxM1jNv6cc8OiwEXAlw-1; Mon, 14 Jul 2025 07:07:01 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4538f375e86so32964175e9.3 for ; Mon, 14 Jul 2025 04:07:01 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45611651008sm50979685e9.9.2025.07.14.04.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491222; 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=9ldzKRjoCTm1wE0lg8oM0P/4wDs9Nar/4X2QOq18lFU=; b=LbQH2YB5u/FAUZMTuHCPpOJEpMJ6Xsl2rhqa8c1oW0I+QZLkIRbduq+7WrQa63Rz9P539g 8XspkFotNci3x9OcWbVtWuQ66ydOLDXKqpFTOtEgZOI4bHkelX0mSsRPxHP/vef1KsIY/P 7hD8jPk+VFnA4kbluA5mMbucbe8VQ74= X-MC-Unique: xVwKxM1jNv6cc8OiwEXAlw-1 X-Mimecast-MFC-AGG-ID: xVwKxM1jNv6cc8OiwEXAlw_1752491220 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491219; x=1753096019; 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=9ldzKRjoCTm1wE0lg8oM0P/4wDs9Nar/4X2QOq18lFU=; b=gQfDsjwBS96EXeJO/jkrv4HcViS0eOP+7S+/eNDAZE3sgHZAUl08wswEowSAmm/cdD lDfDtr+zt38YJYvhm3HhRjfrHyYHayEP2EaSPAy1Y15j1DoNHsYJ7EDNeQ+nbqq/FPTu k5bLRzxRsKqg/5UFKQnaA5S23jN7DiwoL8l74t0DiAps1VPQbMruYs78+5gdayntMeRx JUp6prU9BHG4r17tJYtKDT7HOTAWokxx20ngGXxWy4XZ6Dnvyl4duCq6tuhXxsQPeaYq sXJ8lVT8XOGXIrIKceXvFwAhVyMRfOQd082QHUT5Un8L0FFf0vwp6asi0Mqluc+6ZS1c hrqA== X-Gm-Message-State: AOJu0YyOfGqua54GNiHrohwkaI292Nj3WzIcVEIekPHKMwBKwSb2UmAq 0NB2mnSWPx5HqzvNwE0O9UnW/UkBVQWVHZcC9Z8VMJxg7Va27EOUghhbj3eDIKyzEbcENvKJRIM DpsoJI1um1jHyPBi/rjqXtWJtiqskO1MjKxqriKWSogNs3mgCfdDTGIrLHlu9QqVyIgCK4AdVhJ nDi1hme2ZijPNTnci1W1bhKHPGNS4xbiQkSoWIT5gI X-Gm-Gg: ASbGncsnu8SDUp0xBsGOgwX72wrILvVcOtstGf3Uc7hgWJRNEoNN+PjlPSgbGY28tXb hOUauUJRfTI8XvzCFUDeLLh2fEi0EnjafMBUK1hgMB0/4gZ/4FmKCDpQEE8sMuTjwlshOHaAM+F YnA4Aihek+QUEk6J0h4if5qo00dUDbx+uvnxVTjFEUX4jTrNti7UNudYwv3KhHPB3GhaRZZh2Gd P65+EzRzunUg1QavoQpzsd5nOfWfaiZ+ckolN1+cYl+/8l19v+t0n/t6wdsoJfmbH2YWkJ8oTBn WZ7jivn4ZPCGbTqF5kvmok8pGQpWNhmOjcp2DRLBS0o= X-Received: by 2002:a05:600c:4f4d:b0:456:58e:318e with SMTP id 5b1f17b1804b1-456058e338amr90480955e9.30.1752491218847; Mon, 14 Jul 2025 04:06:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/kMQ9cJHtGlnnBQusmdGrUFWNteqrNl4LYe65WSNB0AykJDQ2SdQ2sH6I32ROxrynAPo+0A== X-Received: by 2002:a05:600c:4f4d:b0:456:58e:318e with SMTP id 5b1f17b1804b1-456058e338amr90480535e9.30.1752491218376; Mon, 14 Jul 2025 04:06:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Igor Mammedov , Dapeng Mi , Yi Lai Subject: [PULL 66/77] i386/cpu: Enable 0x1f leaf for SapphireRapids by default Date: Mon, 14 Jul 2025 13:03:55 +0200 Message-ID: <20250714110406.117772-67-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752495208664116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Host SapphireRapids CPU has 0x1f leaf by default, so that enable it for Guest CPU by default as well. Suggested-by: Igor Mammedov Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-9-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a11e9bb1117..216e0232df4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5081,8 +5081,12 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { }, { .version =3D 4, - .note =3D "with spr-sp cache model", + .note =3D "with spr-sp cache model and 0x1f leaf", .cache_info =3D &xeon_spr_cache_info, + .props =3D (PropValue[]) { + { "x-force-cpuid-0x1f", "on" }, + { /* end of list */ }, + } }, { /* end of list */ } } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494182; cv=none; d=zohomail.com; s=zohoarc; b=j2RzB3A3ZYFSxC4PicVX2MCW7QUnZl1pFMLicABK8D/dW5IKWCeepQPP4VBRskzQt14A/wzZ/tSAA6tEG7A+C3amlCBrMU9z7H9mvH8ratEP1jcoaub+NsjKjozt/Atn13auaRE3aftHtUhGK6hVEi6YM3WAK5FNdtexQIREsXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494182; 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=/iwwKGi8Hmz04XjriQPgEvnyWduNEXOBdPyGuoBdR8c=; b=K6d8fsrjcCez6v1eKf9V7xlu74+SL7I9g8u5n/hfhUOvHWik3tyX43rmMJUNZMG6Lr484WACKeu94rDbC+Y/e+978Fg0Gc/uyQLIJG99i5sWBPq2hb8lhS9mfumu3AzAGOoe+oZyu1S/b7KNVnQ/xeiequcctDc4RnRdOYs1Y6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752494182967499.57731671723207; Mon, 14 Jul 2025 04:56:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHTu-0006Cy-C4; Mon, 14 Jul 2025 07:36:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1a-0001yd-Ek for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1X-0002DH-BI for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:10 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-237-Bv9sYeoCPrGYNed9Z8B5nw-1; Mon, 14 Jul 2025 07:07:04 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-455ea9cb0beso21452875e9.0 for ; Mon, 14 Jul 2025 04:07:03 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561d19a21dsm19903675e9.24.2025.07.14.04.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491225; 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=/iwwKGi8Hmz04XjriQPgEvnyWduNEXOBdPyGuoBdR8c=; b=V+r8hAAy17+J4Qo6qkBCOLUoFApPZIc/LcTnmC7rcgl4hOvZKEhZny9JYeJcxW7k9vjPWq +DINjBlcm+Cxy1TTJqhTsh0JTj8ttWklYAqyjdkcX0AEHcOGvZI6NchWPQ9Ibub5GRYkbl JlMtUcXX4qRxD2xa7cIxNOrVj5t5GC0= X-MC-Unique: Bv9sYeoCPrGYNed9Z8B5nw-1 X-Mimecast-MFC-AGG-ID: Bv9sYeoCPrGYNed9Z8B5nw_1752491223 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491222; x=1753096022; 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=/iwwKGi8Hmz04XjriQPgEvnyWduNEXOBdPyGuoBdR8c=; b=W6dK2f1o+bbXFrAdppoiGpoydCNeMyQ6ApiUXKsH8OHb2LJXgYyy/Rzl8g/ZIgGTGI g94iL9iqQgfhxrn/ePlt0kA6+a3gYioWJnXXo+LSS/MluBHYd6eOgmXB//FPmE33nCta RDymgABm57fFHxsxmzO2l+SUeYJgfhVN4EAR9Jlc98Yb+1VCGMaxm6LGZRtS0DIQnUgj 61HeAZDFstw7oxA/s6JqRx6sHv/wHcK7uipLsqCOpWHs9tsqOPo1vPftLMmQGHfTLtZJ XJ5Qy+rIqM0T/l5EVbIXtjAM334L62LZrIjeb2zJ+56zcR1/1/afT4+oPfHhSrFngwC/ hJeg== X-Gm-Message-State: AOJu0Ywoh6jg2deFwfrygeVhi7R7mlnc3qnGIWgW3VIB5sPtXsFJl79E g1CujMMOCS9tshIGGU78UvotGDTQoPR08pYA9DlHuyNgFDWHFLbzqXVd7IfNnhfEURPLRrt5J1n EQksNN5KORqevRupxhwsWXXEyWLCK7u8Kdj5TMx1vQHyZGJq4nXElnPtpTgTQsLw8/0S+gTgnAl GIbwajk8cU3vD2QHkmLhhA+p6bv30hZuUD+2G1NFcM X-Gm-Gg: ASbGncvoP+iOmpcsDTQE66IAUAHnUd6SXAl9LGG+S+VD/h66By+rM31081UVuy8hPwJ /sxJNAuA3kq/szypE1SCWamEJrgxNpFQa0H9/WOafhPnYNfCDPL3RKYGtWGE591vccdwV9+MiWs TIaD8Jh7Qw4G9cDiF85568U4Ct696R3szvU1QuElhl2R0KGKqRYVDBoATTXqP0fkC1X7kOVXhDj JiwovVgVrwMtcOf/jmAe6ntxbqhkDe+Wp3zDKoBgrpMrJuDITsNRXgSE301rX1mloDYxyhh6iLC mPRr8VSel+TgNAyajCKskAwjPj9CKlgvK+LToH3bcN4= X-Received: by 2002:a05:600c:46c8:b0:456:1dd9:943 with SMTP id 5b1f17b1804b1-4561dd90c6fmr20936705e9.3.1752491222045; Mon, 14 Jul 2025 04:07:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMn7YO8uQs1khaKFeeknkibc9dw6LlNSrF3jxMVtMU75VRfP2Gev9P37K1Xb3eFXyMFdmYOA== X-Received: by 2002:a05:600c:46c8:b0:456:1dd9:943 with SMTP id 5b1f17b1804b1-4561dd90c6fmr20936255e9.3.1752491221574; Mon, 14 Jul 2025 04:07:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Ewan Hai , Yi Lai Subject: [PULL 67/77] i386/cpu: Enable 0x1f leaf for YongFeng by default Date: Mon, 14 Jul 2025 13:03:56 +0200 Message-ID: <20250714110406.117772-68-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494183971116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Host YongFeng CPU has 0x1f leaf by default, so that enable it for Guest CPU by default as well. Suggested-by: Ewan Hai Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711104603.1634832-10-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 216e0232df4..4f0c9734461 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6548,8 +6548,12 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { }, { .version =3D 3, - .note =3D "with the cache model", + .note =3D "with the cache model and 0x1f leaf", .cache_info =3D &yongfeng_cache_info, + .props =3D (PropValue[]) { + { "x-force-cpuid-0x1f", "on" }, + { /* end of list */ }, + } }, { /* end of list */ } } --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492788; cv=none; d=zohomail.com; s=zohoarc; b=G5zwvIkX7GTWLcr6k3rDTm/kPWS6pG67YWpCmbbOBoUQDlEfSH8ei7ZWz/vPE6yC6dX8mg5bKmHEtqc4nKgzPFuRjM0F5zldkyKdXrzh0O7c48rCD1M8eKij7lTljdp4tnShyAS1kaadv4omcr0f2iluvtwCGmaK48nILos47mU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492788; 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=eoimDhc5l0wVHOgJ1eysYl454HfMabPmsqsHxip4lQg=; b=Sfyr1nIWvfpiSuUE357Ng7B4pRmGukTIwC0C6lpiznwPUSoZpROZ9feNPi5QyuPTB2Z7IPdVnsFvBCDxwRgKly3RTWE9/UCMn+N+D6HLdKvKq9ovQyRlxHS3mH1AyQv8ccejLqCpNli+RSkIH7QmatGDyqxu9ej1TErWJy+EfRM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752492788434983.0290719499442; Mon, 14 Jul 2025 04:33:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHGR-0001nO-HI; Mon, 14 Jul 2025 07:22:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1b-0001zY-Ms for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1Z-0002Dv-N7 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:11 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-b7P0X1cUMnuxNfR21EL4-A-1; Mon, 14 Jul 2025 07:07:06 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-456175dba68so8249865e9.2 for ; Mon, 14 Jul 2025 04:07:06 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4560ddf5e0esm63678815e9.18.2025.07.14.04.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491227; 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=eoimDhc5l0wVHOgJ1eysYl454HfMabPmsqsHxip4lQg=; b=LTekUaOpwkNhFCHsiFvfo+bd83UhDBmrCFqMARIhLZonVD243LQCmJPjvVpwi9zMWDp1JU 9MWr5qhyX8gZTLXTB+yp1kXvo2GzHmwjNGPU624+dZ2Qr5qHZXlQ+ExGXg1IhHY7I6qtgG u12mVmqWp1LdqKDM7QoVYzrchCrhLDw= X-MC-Unique: b7P0X1cUMnuxNfR21EL4-A-1 X-Mimecast-MFC-AGG-ID: b7P0X1cUMnuxNfR21EL4-A_1752491225 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491224; x=1753096024; 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=eoimDhc5l0wVHOgJ1eysYl454HfMabPmsqsHxip4lQg=; b=XiSNay2p2td08OWXekB22OMMn3TPjSuYUIz70qSve/tADv5Y5U42T7l3beuI9AACqd RZavRyQrGPzutrfu1zPMwGnXGZbCGBycK1/WSBzrjN05eJsSgkhwIiGVdhzjG6Ijn4eG 48m7o7EPr8cr2QcDvQpGSpg3mQhxt16whUW7dqIp6h8SjtaT8fQya7p3vC4MvIN4Pamr v+oSWYuLqg3X7BTZTM1+MZ/ONo7M/F8RKK/eW4AYy1bjQK6y1hOaNjN+ph06uQr/s0Wv rdod5+EyedRqUhGrdTFn0TJLyXm856t4K6PCL1xaIkM/+O79KXt5g4mu9X84e7eROSuW 6Hww== X-Gm-Message-State: AOJu0Yyoh3PaKO+OXoNiNHv+jOBZigwxyKowcuA2lWiIaBSRXAM9t8ou Tp1mJcODKIarA4OGshkRJSAWHKSsRab8nf1Rt1vZMrB9MxpdZQY23CWkoJv0On62oMSI9HiYO5D btClZxRC01ej7YbYIdcRLq3pS91+XzTnq+4HoNnIPZ03IsVQS4MyL2YIMb0KAZVxT/vUlbtzDFi DDmwTIwvm5TOUoKmBU2421NgFHQcneRsXTtWYWUROz X-Gm-Gg: ASbGnctvXeqU/QnIxLgN1FSUl72tEZQn79ZcxfzvPiS28x2TUjY+QuR6RY0P1PTWwRH iVo0PRG+Lj0i5iANCULWlAfgA0A+RmfKB61sfNGEbCc6i03ESzLzajkcJnRi+4i/QNIifpcoSTI kGQDJq1zzPfPPC2MDonIemSsRbky2LD2icDzXYlqtg/U0vel58RerMdqPWuKjJWOgAlsZkZm5nk oayKUHCCoYIPL29xOuo2E3+8hLD+b0JLnO33pl+bNToQZtXif/z1rJfxP18tCq3JE6LyKBDaWMl 0vTiW7EKbtyg+boSKYYB77wgWxUdWUxhWaxETmUM4Fw= X-Received: by 2002:a05:600c:4e51:b0:455:eda0:8a8e with SMTP id 5b1f17b1804b1-455eda08c8dmr89470205e9.27.1752491224243; Mon, 14 Jul 2025 04:07:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZbyNgVFefir52iWnM2DErV6Xh7OJJ9HWLIGYkGB98qDWZHSRYPuBTJmZLre/jKF1S91GeMQ== X-Received: by 2002:a05:600c:4e51:b0:455:eda0:8a8e with SMTP id 5b1f17b1804b1-455eda08c8dmr89469925e9.27.1752491223816; Mon, 14 Jul 2025 04:07:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tao Su Subject: [PULL 68/77] i386/cpu: Mark EBX/ECX/EDX in CPUID 0x80000000 leaf as reserved for Intel Date: Mon, 14 Jul 2025 13:03:57 +0200 Message-ID: <20250714110406.117772-69-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492805006116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, 80000000H EAX Maximum Input Value for Extended Function CPUID Information. EBX Reserved. ECX Reserved. EDX Reserved. EBX/ECX/EDX in CPUID 0x80000000 leaf are reserved. Intel is using 0x0 leaf to encode vendor. Signed-off-by: Zhao Liu Reviewed-by: Tao Su Link: https://lore.kernel.org/r/20250627035129.2755537-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4f0c9734461..ae508fa962d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8280,9 +8280,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, break; case 0x80000000: *eax =3D env->cpuid_xlevel; - *ebx =3D env->cpuid_vendor1; - *edx =3D env->cpuid_vendor2; - *ecx =3D env->cpuid_vendor3; + + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *ebx =3D *ecx =3D *edx =3D 0; + } else { + *ebx =3D env->cpuid_vendor1; + *edx =3D env->cpuid_vendor2; + *ecx =3D env->cpuid_vendor3; + } break; case 0x80000001: *eax =3D env->cpuid_version; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752492945; cv=none; d=zohomail.com; s=zohoarc; b=kGEZI0EjCKWHn6/q8R+yXbd1+Cd7lHShgoR/Yenp1Ja60Sr2TvbAdZq5EX66kZqdSBpgg8XHkdb053Ph2VnfQt1kX7Cjal+z+PZfuaM9x2aIcVRVIjQdL+sWCAbA+I8ypuZeeN6ByBJO/pCzUsIXZhoW1Zds2Fxq1KA2sXikVOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752492945; 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=X4vIGW+jVgxph6j7hy7m8DEr7QyusibOiGAbD/TBzyM=; b=VdYOtNp9eJpZvfyHO87BysRhI5PGtUOGqN1MuBgZa1ggaNK3wqCXnslr9ihlSfuNw529ht5+hWkf116gt2GPM6nTWm9gXhkZROC6hGZUVtLeJG8To6BDXoOyDsNWC48QsZpfVTxyU9AMuQoNcPn+HFWgwe7r0yqbnjdFJxFdwUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249294522526.229966497427085; Mon, 14 Jul 2025 04:35:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHCk-0005bj-9N; Mon, 14 Jul 2025 07:18:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1g-00025I-TK for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1b-0002ER-Oe for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:16 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-Gr4DJyvUN8iUPdqDr2s_FQ-1; Mon, 14 Jul 2025 07:07:09 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-455f79a2a16so19545975e9.2 for ; Mon, 14 Jul 2025 04:07:09 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1833sm11796439f8f.8.2025.07.14.04.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491230; 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=X4vIGW+jVgxph6j7hy7m8DEr7QyusibOiGAbD/TBzyM=; b=cMHFlFwpCs3h6mmeV5Lgc1sewy6ihZG7GvL5OVn3aDFKuUKnHMoKmOR/AyqXbz8o8cfBAr KjrMClAQxRY81cNHyb8SGi/3OqxpKQefo0Cc21TbEUwRVshQV+mqyf6MlUVnhtGrTWBwiQ In1VV+4JFJoJWyRAMH0In6zSU1mmKBQ= X-MC-Unique: Gr4DJyvUN8iUPdqDr2s_FQ-1 X-Mimecast-MFC-AGG-ID: Gr4DJyvUN8iUPdqDr2s_FQ_1752491228 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491227; x=1753096027; 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=X4vIGW+jVgxph6j7hy7m8DEr7QyusibOiGAbD/TBzyM=; b=CL1LJ9ZnRQw9hgYrDKF5T2kd6z1PgK82bi2cUQ9Gd0s0uV/fmmJ6vCSruq2Xu7oiEg cc0wDeM53/WVpOfJ4s0H7h2b0PI1Sb1xnPI/SKX6oKZaaSzM7yCRrjNWNcwYZ+LlhdDJ Kq8uMMvYQSam4rE9DyREBwKGJmFyFvpzXrlYVcDNc2eLHsUvaAlxo/5BgVc7rlItGNDt VF/ncq4tEHuylbPkSoOWbwED3U8TED+XQEBoMJ2qYlQd+82zdF4MoXjDojXbYTVf72EP ojNgM4VaCOZ16uQwUacb3GhTPvG3DDY9CpJ/yBUFdGij/DrWr7dWqiwl0/miyVXXFTdt SWwQ== X-Gm-Message-State: AOJu0Ywu6UH2lcoGSR2lRzzU0PxeFx1LBNooXLq78f5l6RdfQXVVPY/s +0flqsgWYgv7uLyCNcvYr3WDsdouHk8xAdY6stFY2iInCcI7YSvhbvBxXAEhma/Q65qhHSWB5lF Zk6f8alVfjWKCKdPYxBPm+UmtjwR63JnXINGxvsL85i+e0xWwOHm3yctY2f1RKBqtwLe6G8G7+Z E2txvdsT5pQ6sMyrVWYMn++NxB4dPfJlLYT48PLs7M X-Gm-Gg: ASbGncusdbtFFep3KEt2q610NVlMGon001t3gK4sSGAAYYb4a49Fl6myqGbAd6FNswr s7eupJUlIP1OGiDkMm0mUmlsf8197VvpXZfBCIOWW6m7AhQf+U65w5MjyTTReZi7uA4zrLViG6G CqF16QSqmW/zW/4yvtEQ8Fh3VaswnqnCUexU0EBpAZ6wBlnMuChSYa/QO/ilCdeUpxGVKyvvfWr VIuyORGEjgzrEIEWuCtstjYeZacoSagko19bl3CYAem3r0QBi09In9XanISmG/k9oXlFqshi9gV LHygaVzORlN7OPyekJIhMX+6s0FO4TTRr00ZMxceZ94= X-Received: by 2002:a05:600c:3481:b0:456:1442:854 with SMTP id 5b1f17b1804b1-45614420b17mr46988295e9.24.1752491227184; Mon, 14 Jul 2025 04:07:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE22Ji03Q7JG/6cd2n1WL9crEzQBnaoCanKn4DZ2t4b+u4X0RJjQ1zQsbt6auTjB2n39uRTxw== X-Received: by 2002:a05:600c:3481:b0:456:1442:854 with SMTP id 5b1f17b1804b1-45614420b17mr46987945e9.24.1752491226714; Mon, 14 Jul 2025 04:07:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tao Su Subject: [PULL 69/77] i386/cpu: Mark CPUID 0x80000007[EBX] as reserved for Intel Date: Mon, 14 Jul 2025 13:03:58 +0200 Message-ID: <20250714110406.117772-70-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752492946925116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, 80000007H EAX Reserved =3D 0. EBX Reserved =3D 0. ECX Reserved =3D 0. EDX Bits 07-00: Reserved =3D 0. Bit 08: Invariant TSC available if 1. Bits 31-09: Reserved =3D 0. EAX/EBX/ECX in CPUID 0x80000007 leaf are reserved for Intel. At present, EAX is reserved for AMD, too. And AMD hasn't used ECX in QEMU. So these 2 registers are both left as 0. Therefore, only fix the EBX and excode it as 0 for Intel. Signed-off-by: Zhao Liu Reviewed-by: Tao Su Link: https://lore.kernel.org/r/20250627035129.2755537-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ae508fa962d..533c9d9abc7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8376,7 +8376,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } case 0x80000007: *eax =3D 0; - *ebx =3D env->features[FEAT_8000_0007_EBX]; + if (cpu->vendor_cpuid_only_v2 && IS_INTEL_CPU(env)) { + *ebx =3D 0; + } else { + *ebx =3D env->features[FEAT_8000_0007_EBX]; + } *ecx =3D 0; *edx =3D env->features[FEAT_8000_0007_EDX]; break; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494504; cv=none; d=zohomail.com; s=zohoarc; b=FScJlzPpYofTcVwY07Y8Szkfc9QqcCfioWfUgthvPF6WEAkeJR5vdPy/IjVtCAxqcVJLFURoyTV1O2VJAcAHUDSKNgbm1x6iN/VgX08uQ3T1wg8T6xVhq/UVTsPrdryPHs+sWLe/9MuVPlfY6iVguBS9J/1mK94WB8Ta1RW1jj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494504; 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=pn1f+8iSLRhTUyqVf1Bje+hqAFutT6rdOPYDnkNfnJg=; b=d+r9iIsqzcTXXdzW7W9VMXLg4qHq+DT67vudzIp5wXDmhrgm9LecDdVP1mJ9Y6eT5wJle75sieQ2d8ptISaSwcVK6/81+9isd1+DRBo0S0uQwUGQRBg16hk3Jl5lg+eRuG2App1ckTbTNUhEVPTnM7fZlLjb0RXP2WeOoxKKg94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752494499016608.0178462868471; Mon, 14 Jul 2025 05:01:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHUs-00077m-Ne; Mon, 14 Jul 2025 07:37:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1h-00025k-AS for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1e-0002FD-SK for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:16 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-7LN-6krQN7-GXNe_-iQ21w-1; Mon, 14 Jul 2025 07:07:11 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a4eeed54c2so2276309f8f.3 for ; Mon, 14 Jul 2025 04:07:11 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e262c6sm11924008f8f.85.2025.07.14.04.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491233; 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=pn1f+8iSLRhTUyqVf1Bje+hqAFutT6rdOPYDnkNfnJg=; b=AGs5WPvheWiGMm4fQdgzinrGJCmBjtQvrdGiXjDIomj32FosJfl9tV/hmpOEieaW842r/n Wtn+/NA5qv8rVRYYhfID/1ByPBoN2dGC0BiViD9tXxL7jqAKH5cblYCFlee+IpXotCEYne Y+JxIGhPDq0+O75QaWkcAHqIDAIIYNY= X-MC-Unique: 7LN-6krQN7-GXNe_-iQ21w-1 X-Mimecast-MFC-AGG-ID: 7LN-6krQN7-GXNe_-iQ21w_1752491230 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491230; x=1753096030; 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=pn1f+8iSLRhTUyqVf1Bje+hqAFutT6rdOPYDnkNfnJg=; b=s1tja+9AgqFeADgpfH5dTvBQc4sQ8Ru9LRfhz1sVrZrzXRO4m8s/JG+6bqgiil4xUC 6VZGsitTmxA4ssQXBvSHz+cm5TVDB2IwvTeibNf2EMGSVOFtsU2hB/frTEpBTgYk+wFT VTrenMHLNVRoU/vWTiDdgZ90aPUaMe6FcxoipQK7K4SsAM1kfMCgwF0saogjNYdM5eUw mJv2C3kSF55u6watO4kpatcvk5i4+dbk5HbGcXgz5mRBysc3s19y9YUZ9Y6HOrDY7Kqa Xjz1U0OdBYlV3O1TJRKFXo6lwKR4YdVQPcEE76m1cJ+OP9BOuaAYbYIbMQKyLfGtaajM NEXg== X-Gm-Message-State: AOJu0YyMKroPimnb9m2MfFIFaa0OHeSU3BNhMFNg05cII4BHtUn1sW8q HxATncz+KQh7LlFWhogsLhXHkm+ZVTZzqxr3EttCemsifClG6ew3WReffz8C5z6gxzYI7x7kQVd suzNxEJtNoRxxVWNZKmK1C0bEfM4CID2nOU/q/U4pkiZSNCw7JEsSopsCc0/M8GnqHTuG+fTpqn io8vLLIHPKjyHYGOji6nblLfWNBznPlM85JuNK5XLZ X-Gm-Gg: ASbGncv0oeZ1pg7tjp6Lx5D4+zGBUbRjc3v17VhlKtjL/cniNw28477Ye2KJPCm/1oc aZNxseufPqEiYwfSYHJpEzCBtHazJXBR3t1VMzrymaXAfa6opt3ZcV2/5wTG+RHmWEoqK7KA/0J ODfzYpQpmVup69vNRJGK2E/gTy5wyzTE4RlpA7mUgDuon5K8lWYuFS3J2bbupKUwzwdsAJq/1SJ GVYEswvztsrf8Doc30izAaab90BsMvTN1fBEDcZPyu+DU5C3cp+OeQdlZD6xGy09w5MiyYtHlu/ VpW2FHLIMBWm3hZ5l7jA4VehzQ6/ossmgwjf2+1o4MY= X-Received: by 2002:a05:6000:40dd:b0:3a0:b940:d479 with SMTP id ffacd0b85a97d-3b5f18f8066mr11785466f8f.53.1752491229717; Mon, 14 Jul 2025 04:07:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9mBfPYxyWyRPaNNjLGf1KGTal4rWuWE4mZVIi1Y3vkGj8rznA6wAb0jCIUF1DzBY+BSYMew== X-Received: by 2002:a05:6000:40dd:b0:3a0:b940:d479 with SMTP id ffacd0b85a97d-3b5f18f8066mr11785430f8f.53.1752491229251; Mon, 14 Jul 2025 04:07:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tao Su , Yi Lai Subject: [PULL 70/77] i386/cpu: Mark CPUID 0x80000008 ECX bits[0:7] & [12:15] as reserved for Intel/Zhaoxin Date: Mon, 14 Jul 2025 13:03:59 +0200 Message-ID: <20250714110406.117772-71-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494512239116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, 80000008H EAX Linear/Physical Address size. Bits 07-00: #Physical Address Bits*. Bits 15-08: #Linear Address Bits. Bits 31-16: Reserved =3D 0. EBX Bits 08-00: Reserved =3D 0. Bit 09: WBNOINVD is available if 1. Bits 31-10: Reserved =3D 0. ECX Reserved =3D 0. EDX Reserved =3D 0. ECX/EDX in CPUID 0x80000008 leaf are reserved. Currently, in QEMU, only ECX bits[0:7] and ECX bits[12:15] are encoded, and both are emulated in QEMU. Considering that Intel and Zhaoxin are already using the 0x1f leaf to describe CPU topology, which includes similar information, Intel and Zhaoxin will not implement ECX bits[0:7] and bits[12:15] of 0x80000008. Therefore, mark these two fields as reserved and clear them for Intel and Zhaoxin guests. Reviewed-by: Tao Su Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250714080859.1960104-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 533c9d9abc7..1a2cae6ea1f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8393,6 +8393,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *eax |=3D (cpu->guest_phys_bits << 16); } *ebx =3D env->features[FEAT_8000_0008_EBX]; + + /* + * Don't emulate Bits [7:0] & Bits [15:12] for Intel/Zhaoxin, since + * they're using 0x1f leaf. + */ + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *ecx =3D *edx =3D 0; + break; + } + if (threads_per_pkg > 1) { /* * Bits 15:12 is "The number of bits in the initial --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494638; cv=none; d=zohomail.com; s=zohoarc; b=SnShS4jsoJ8KBjLGGL1DSwt1aRgp9qqd1m+/3ki0tV4RwhVnzldnCpyhp7J1lHuijnMfGniG5ND62KE/g6Mo3NgaUTcOx1DR/4MrRnTGcc0SIRYgPofAikjYJAsvrVaUM2SRRA9u921Kg0g2N11JgW9hEItEQmEps++h9cUZEWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494638; 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=NQgnwOxm8SMdCCueXNSX8RnBbLLlgFWSXKeYcZQinkg=; b=kGJpAvlV+4IddDInDkQPYPDKYADxi0/P9ngpFIDUIUkDsXpH3vhQH9DwX3qIFFOA/f8ETU98VpwGHOfH6x9+awFlGYcAvXpiIgwrlDdBgFNd7O1XWPj1GuRZ1rSFNuKAwikAFyK0VNRqek0VrzpCMGFgEpzou5EWvnZapd3Q3Jo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249463843712.924478087469879; Mon, 14 Jul 2025 05:03:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHam-0003BL-3x; Mon, 14 Jul 2025 07:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1j-00027P-LI for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1h-0002GC-1f for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:18 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-344-5tJmpG5-O3qpMolxSA9wrw-1; Mon, 14 Jul 2025 07:07:14 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3b5fe97af5fso422425f8f.2 for ; Mon, 14 Jul 2025 04:07:13 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd1736sm12262538f8f.15.2025.07.14.04.07.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491235; 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=NQgnwOxm8SMdCCueXNSX8RnBbLLlgFWSXKeYcZQinkg=; b=NDi6FecKBgcgxr1LtnnMYqgk5iPHdGyZAm63MkW1rW9rT4VPalwFuWkNsdzdU1qtr/4T5R p/Gv1F92MSqiX1E9SD4ZuQe6fLC4yHbFgvUBfi+UAT8/oOPsw2BRaGN7X1qxAWy3Whf33a uxYOTfHM5OFNRZDMwlkiv/myDZE/FFk= X-MC-Unique: 5tJmpG5-O3qpMolxSA9wrw-1 X-Mimecast-MFC-AGG-ID: 5tJmpG5-O3qpMolxSA9wrw_1752491233 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491232; x=1753096032; 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=NQgnwOxm8SMdCCueXNSX8RnBbLLlgFWSXKeYcZQinkg=; b=rt5GzcfYq5R+ct4s1mfsOo86JlZ1VmKLShulPY8zntfAz/cFh4Njy+TBc3diFDkCf8 /DV2wvv3D6qCh78oOUBlUooHtijHXD9GbbQ0bLcTNTA/1D3lpwBY9/ySHCtyIHDPZcAI UtAncZ6sorwaFdvE8rJ0iPrX3qdUqg8b6DDXfFbhAK9Py4Bak98Qrl7Tet1kzQyWnzKt 1EcVKArGUu2nZbZ+UL32VrgJOVq3bjcpnwOy67DLHE7yUNWf+Cf1Z67+vTC7IPYBxAq1 eOz/QD8cHrYXG1vF4N3scSwJ1gDAw8p55HAtR00pn/5SwZrDLXyPAeyFH8z/fyQqRS3V Rm5w== X-Gm-Message-State: AOJu0YwGPnB0hFgSFGDTdnfGaQz9K18KTXvyPjqwkFCSPsOYaggKnSUQ l1TCDFjyZGGKfLSAAA9kns0SirTfiWhw2rqtijPVdgUGSJLCgDA8BCRWyCa9GU6sk606cZC08F3 79OWNKz/cidsj0/n3PqeiKUXjc9BYypDOxDOuyO1ep+EqfBDoMj+KQFpuLNC9tuANYYNWayNf8O ApWbq3CWIjklEu2PJYoAftgANatZms/8V7LT9ibLrT X-Gm-Gg: ASbGncunlCxdhSFEtKmlJfM5l5mtQRHKlhIRr0MN47DNKmC3p2gEYWxBiHRxZmty/Ec RxrO6NUg11eQrnrsRknqKvJJ6cQFkXnIAAizLEU034YWZbK0LVjCTPQ7ZbV6SFU+b8ZSBAM8LiK 1ueaOe8n5R+i9Z5ZGZay+qSVLLl7QBuLT3VOVFFjXprdaREgHIby5lOiob+BbFrVz2GktSHuiiJ HetfkSUXZ5DPRuyY26AYATTZLoFHUO5hCa16ORl159D46D2tOaWOlir4NJk3LnkinHpul3SjWbS Oc02dhqqJZn6OU4jV4HAS++zDMCYVitU9Kgm0Bjx+RA= X-Received: by 2002:a05:6000:2d09:b0:3a6:d967:380e with SMTP id ffacd0b85a97d-3b5f187eb90mr7211842f8f.3.1752491231935; Mon, 14 Jul 2025 04:07:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVQXd3d7/7yqLaRZct+uWPNhQxB2eIwxMFqqZlpk1TrWexlIzulZk/PRVlU3xs3m9IzIFVRw== X-Received: by 2002:a05:6000:2d09:b0:3a6:d967:380e with SMTP id ffacd0b85a97d-3b5f187eb90mr7211812f8f.3.1752491231163; Mon, 14 Jul 2025 04:07:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 71/77] tests/functional: test_x86_cpu_model_versions: remove dead tests Date: Mon, 14 Jul 2025 13:04:00 +0200 Message-ID: <20250714110406.117772-72-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494639915116600 Content-Type: text/plain; charset="utf-8" Tests that require machines older than 4.2 are now unconditionally skipped. Remove them if they test legacy behavior, or use the latest machine if they test current behavior. Signed-off-by: Paolo Bonzini --- .../functional/test_x86_cpu_model_versions.py | 110 ++---------------- 1 file changed, 12 insertions(+), 98 deletions(-) diff --git a/tests/functional/test_x86_cpu_model_versions.py b/tests/functi= onal/test_x86_cpu_model_versions.py index bd18acd44fa..36c968f1c0b 100755 --- a/tests/functional/test_x86_cpu_model_versions.py +++ b/tests/functional/test_x86_cpu_model_versions.py @@ -72,44 +72,11 @@ def validate_variant_aliases(self, cpus): self.assertNotIn("EPYC-IBPB-v1", cpus, "EPYC-IBPB shouldn't be versioned") =20 - def test_4_0_alias_compatibility(self): - """ - Check if pc-*-4.0 unversioned CPU model won't be reported as alias= es - """ - self.set_machine('pc-i440fx-4.0') - # pc-*-4.0 won't expose non-versioned CPU models as aliases - # We do this to help management software to keep compatibility - # with older QEMU versions that didn't have the versioned CPU model - self.vm.add_args('-S') - self.vm.launch() - cpus =3D dict((m['name'], m) for m in - self.vm.cmd('query-cpu-definitions')) - - self.assertFalse(cpus['Cascadelake-Server']['static'], - 'unversioned Cascadelake-Server CPU model must no= t be static') - self.assertNotIn('alias-of', cpus['Cascadelake-Server'], - 'Cascadelake-Server must not be an alias') - self.assertNotIn('alias-of', cpus['Cascadelake-Server-v1'], - 'Cascadelake-Server-v1 must not be an alias') - - self.assertFalse(cpus['qemu64']['static'], - 'unversioned qemu64 CPU model must not be static') - self.assertNotIn('alias-of', cpus['qemu64'], - 'qemu64 must not be an alias') - self.assertNotIn('alias-of', cpus['qemu64-v1'], - 'qemu64-v1 must not be an alias') - - self.validate_variant_aliases(cpus) - - # On pc-*-4.0, no CPU model should be reported as an alias: - for name,c in cpus.items(): - self.assertNotIn('alias-of', c, "%s shouldn't be an alias" % (= name)) - - def test_4_1_alias(self): + def test_unversioned_alias(self): """ Check if unversioned CPU model is an alias pointing to right versi= on """ - self.set_machine('pc-i440fx-4.1') + self.set_machine('pc') self.vm.add_args('-S') self.vm.launch() =20 @@ -133,7 +100,7 @@ def test_4_1_alias(self): =20 self.validate_variant_aliases(cpus) =20 - # On pc-*-4.1, -noTSX and -IBRS models should be aliases: + # On recent PC machines, -noTSX and -IBRS models should be aliases: self.assertEqual(cpus["Haswell"].get('alias-of'), "Haswell-v1", "Haswell must be an alias") @@ -247,8 +214,8 @@ def get_cpu_prop(self, prop): cpu_path =3D self.vm.cmd('query-cpus-fast')[0].get('qom-path') return self.vm.cmd('qom-get', path=3Dcpu_path, property=3Dprop) =20 - def test_4_1(self): - self.set_machine('pc-i440fx-4.1') + def test(self): + self.set_machine('pc') # machine-type only: self.vm.add_args('-S') self.set_vm_arg('-cpu', @@ -256,80 +223,27 @@ def test_4_1(self): 'enforce=3Doff') self.vm.launch() self.assertFalse(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.1 + Cascadelake-Server should not ha= ve arch-capabilities') + 'pc + Cascadelake-Server should not have arch-cap= abilities') =20 - def test_4_0(self): - self.set_machine('pc-i440fx-4.0') - self.vm.add_args('-S') - self.set_vm_arg('-cpu', - 'Cascadelake-Server,x-force-features=3Don,check=3D= off,' - 'enforce=3Doff') - self.vm.launch() - self.assertFalse(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.0 + Cascadelake-Server should not ha= ve arch-capabilities') - - def test_set_4_0(self): - self.set_machine('pc-i440fx-4.0') - # command line must override machine-type if CPU model is not vers= ioned: - self.vm.add_args('-S') - self.set_vm_arg('-cpu', - 'Cascadelake-Server,x-force-features=3Don,check=3D= off,' - 'enforce=3Doff,+arch-capabilities') - self.vm.launch() - self.assertTrue(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.0 + Cascadelake-Server,+arch-capabili= ties should have arch-capabilities') - - def test_unset_4_1(self): - self.set_machine('pc-i440fx-4.1') + def test_unset(self): + self.set_machine('pc') self.vm.add_args('-S') self.set_vm_arg('-cpu', 'Cascadelake-Server,x-force-features=3Don,check=3D= off,' 'enforce=3Doff,-arch-capabilities') self.vm.launch() self.assertFalse(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.1 + Cascadelake-Server,-arch-capabil= ities should not have arch-capabilities') + 'pc + Cascadelake-Server,-arch-capabilities shoul= d not have arch-capabilities') =20 - def test_v1_4_0(self): - self.set_machine('pc-i440fx-4.0') - # versioned CPU model overrides machine-type: - self.vm.add_args('-S') - self.set_vm_arg('-cpu', - 'Cascadelake-Server-v1,x-force-features=3Don,check= =3Doff,' - 'enforce=3Doff') - self.vm.launch() - self.assertFalse(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.0 + Cascadelake-Server-v1 should not= have arch-capabilities') - - def test_v2_4_0(self): - self.set_machine('pc-i440fx-4.0') - self.vm.add_args('-S') - self.set_vm_arg('-cpu', - 'Cascadelake-Server-v2,x-force-features=3Don,check= =3Doff,' - 'enforce=3Doff') - self.vm.launch() - self.assertTrue(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.0 + Cascadelake-Server-v2 should have= arch-capabilities') - - def test_v1_set_4_0(self): - self.set_machine('pc-i440fx-4.0') - # command line must override machine-type and versioned CPU model: - self.vm.add_args('-S') - self.set_vm_arg('-cpu', - 'Cascadelake-Server-v1,x-force-features=3Don,check= =3Doff,' - 'enforce=3Doff,+arch-capabilities') - self.vm.launch() - self.assertTrue(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.0 + Cascadelake-Server-v1,+arch-capab= ilities should have arch-capabilities') - - def test_v2_unset_4_1(self): - self.set_machine('pc-i440fx-4.1') + def test_v2_unset(self): + self.set_machine('pc') self.vm.add_args('-S') self.set_vm_arg('-cpu', 'Cascadelake-Server-v2,x-force-features=3Don,check= =3Doff,' 'enforce=3Doff,-arch-capabilities') self.vm.launch() self.assertFalse(self.get_cpu_prop('arch-capabilities'), - 'pc-i440fx-4.1 + Cascadelake-Server-v2,-arch-capa= bilities should not have arch-capabilities') + 'pc + Cascadelake-Server-v2,-arch-capabilities sh= ould not have arch-capabilities') =20 if __name__ =3D=3D '__main__': QemuSystemTest.main() --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493441; cv=none; d=zohomail.com; s=zohoarc; b=GwaHBbJo/AlT9sgTykPf72Wbpw2WnPDGHm7/ybOtZ0yUG7IhZg/G7I4CDOJ2rfMHHePnbqR/iEaBomxDzdaF+YwEKgOmmi3XX+HI0aVo0sWDNTwfYt3tQUmJ7h0e2fs+NWlHyFUcwo5PhR8yyJSFGQD7U5IdcWke+dtS2Sxlxg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493441; 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=NvkNgqLKsXpfmLf4idce9IyO9fOJ2IHj3aUNZS4ffhE=; b=H0Ji4Ji1k7pfzIv/Z5nIQC1QdEoLdvXiaVo3EQZimponcHpDLbGXLevh7DkgMTakQ+uwba73veNVvmsAFvw+rA200GQsKIb9RMzLvxk2G18aR6Oh7r3n3GMQ3P4B0sxregayaZj+vWRYYaKh+w+AxavEq3iKxV99VwV/rwJXjVc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493441096992.9332462015434; Mon, 14 Jul 2025 04:44:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHDh-0006Jz-2Z; Mon, 14 Jul 2025 07:19:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1j-00027O-La for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1h-0002GV-R6 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:19 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-B87FIxF1PBmxo1N5lwCBAA-1; Mon, 14 Jul 2025 07:07:15 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a50816ccc6so2540679f8f.1 for ; Mon, 14 Jul 2025 04:07:15 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc2464sm12386795f8f.38.2025.07.14.04.07.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491236; 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=NvkNgqLKsXpfmLf4idce9IyO9fOJ2IHj3aUNZS4ffhE=; b=fjs2/fwzqELH4Jnjfh/L/hgO6FIWP/fNQCBjoEdMgUiLWY2Bh5ft15OiGK+BmqWiMfpFGc TAN6u8XIzfl3PdtBA9xqKOhopHBjHVxdmWq2JoYlSpAHfiuNdwtJvAfo+NhMOBHaXeMyn/ JKslr5tVOdryaMn7GHMZTYPb8ccpBfU= X-MC-Unique: B87FIxF1PBmxo1N5lwCBAA-1 X-Mimecast-MFC-AGG-ID: B87FIxF1PBmxo1N5lwCBAA_1752491234 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491233; x=1753096033; 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=NvkNgqLKsXpfmLf4idce9IyO9fOJ2IHj3aUNZS4ffhE=; b=CVvaniQXP2GPO2HjfNU2EpEdTa/uinEkysFPYWzJwI+VsksjrhgnIp8dxT60kL9s23 NAQ8GO2/0ri8CzbLohmQfigiEIOenTgtxknE9j/hco4l911yvJsnNgqjg0gn83dY9R6s KhrLENZy9twvvVHlpNaK6+MW6Bf4METLV5/koViSU6p1jroAEbYNPpI/O1M/Ime6RhFg vJYezC/yLdyT6oOqcOq3FOM+/UPetBoqtmaOhysv0bhS/e1IXbVKS3kbpjE4cdzmQdmN hsGhNDqdnrxLfvJ2mhsIEPuFkR6A9DIZ8szi0o2y1bZqAFgIwYSjay0YmzbDjUDc8b0B DQ5A== X-Gm-Message-State: AOJu0Yxx3f4ooYxNGIoPXtL6rzfLyqQhWrNlfgOeRr3C8C0dVgq1mLMK KIT0k0xTJz3ZyeHtRD8CM6/ZYQYqPZ4Uj7gRpMS5ehW6BGcpyjxa5699JWMsA2lL0kac0gM/JQb jpXofpfiHAhGX3mPm0SWwdd5RvIWWRn0UN0dUCXlTROSjd7QMurpWYIvH6BzJXPbBaTfSJ7wqMs F0h7MWjXxebY46XPKZTxaG9xWCM1Ua17Aa0bMKFr6N X-Gm-Gg: ASbGncsCuEix7OTBejDj9h0FbxcBiI63Y6/3J5HfKsZwY9VITV1WQF/nNsBk3NUm1Qs JsFDtF2Nk/GAhuL5JYuWQLMAWCjLC3agY2XKMgIjs4ae6cUDQ0MTK2mzEI0E4v+EWzIkRcDKzUW +qGg6bCChyGsxtE4qxvNmfNWre18WxUVnUXV/sonEZPyej7M3H+kbrIm/h0whOGSsg8ZkI3chg/ yR6jJUkfua6KfNLKnF6qpHIUM2cdhXZx7z+3WaGf/K+a/yE19PpSS/DMOkZ8AVjhLgz0cBhHUwM cmQNbbf427i1gAYkvprT4Y+5CIIGlZO8MKMPK/d2jis= X-Received: by 2002:a05:6000:4287:b0:3a5:5fa4:a3f7 with SMTP id ffacd0b85a97d-3b5f2e5660cmr8970307f8f.58.1752491233294; Mon, 14 Jul 2025 04:07:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVlKj1cTmFl7iZN97hnbJaqg89IjhgkH6VkzL8I/8Dmm8PJN8xBXYvIjI67WyY/8UVR9Zbpw== X-Received: by 2002:a05:6000:4287:b0:3a5:5fa4:a3f7 with SMTP id ffacd0b85a97d-3b5f2e5660cmr8970268f8f.58.1752491232745; Mon, 14 Jul 2025 04:07:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 72/77] tests/vm: bump FreeBSD image to 14.3 Date: Mon, 14 Jul 2025 13:04:01 +0200 Message-ID: <20250714110406.117772-73-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493442631116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/vm/freebsd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/vm/freebsd b/tests/vm/freebsd index 74b3b1e520a..2e96c9eba52 100755 --- a/tests/vm/freebsd +++ b/tests/vm/freebsd @@ -28,8 +28,8 @@ class FreeBSDVM(basevm.BaseVM): name =3D "freebsd" arch =3D "x86_64" =20 - link =3D "https://download.freebsd.org/releases/CI-IMAGES/14.1-RELEASE= /amd64/Latest/FreeBSD-14.1-RELEASE-amd64-BASIC-CI.raw.xz" - csum =3D "202fe27a05427f0a86d3ebb97712745186f2776ccc4f70d95466dd99a023= 8ba5" + link =3D "https://download.freebsd.org/releases/CI-IMAGES/14.3-RELEASE= /amd64/Latest/FreeBSD-14.3-RELEASE-amd64-BASIC-CI.raw.xz" + csum =3D "ec0f5a4bbe63aa50a725d9fee0f1931f850e9a21cbebdadb991df00f168d= 6805" size =3D "20G" =20 BUILD_SCRIPT =3D """ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493157; cv=none; d=zohomail.com; s=zohoarc; b=BsQ2JcKpqOjLNthg3HpMBjmYW5tHsteVHE5jtf1DSqwZOmtBVFCbcbpgYHcRKvk0POIjgpSw1q0VIHWPTsSNb59dczX1cmoCSeUi950IIjQesbOXlZnerVJbBuuNHTX3aFzcURYdbP1W+a9RGlMJOE6CZ4lc2tycK3xPCWCVg6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493157; 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=3poyEKrP2QccOsBnw3+qFZ7NtXzgmSIMZDOuRbq9Mjs=; b=W9BwkN8RHeidWxVTHRqTA8M6n+jhqjoufJrlhswNDbWMLJj4p1TewclRGG7GRekwPJWWatMeFCoBlsrtw2Ey9rqQzWqChu9ob55V6B5WrcPc3Cdx9rbt9OIzECJoqz+99tWpYh7riwnO4hJivpOZFKY/objZfQJWJcpqnLKXTy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493157849460.8060097599978; Mon, 14 Jul 2025 04:39:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHV2-0007Qb-7B; Mon, 14 Jul 2025 07:37:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1l-00028R-9T for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1i-0002HL-Hz for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:20 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-catAXm3aPIWWivKIydfJew-1; Mon, 14 Jul 2025 07:07:16 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4eec544c6so1839235f8f.0 for ; Mon, 14 Jul 2025 04:07:16 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d872sm12279345f8f.60.2025.07.14.04.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491237; 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=3poyEKrP2QccOsBnw3+qFZ7NtXzgmSIMZDOuRbq9Mjs=; b=T2TXf5Hy2vxse2dZyOdlmw4gexylmaK2aRH/8JvnFAFcy0lvBcmXIvPLEFJxMWPkA0F919 bvtPAP+O+jiXMeUMCvEBv8fUd7yiJiC5S0YY2AekoK6IuA/RKnTmGrwyKM+gt3j+Lm8e7F s+A2QtPyO18ZZ2gQUV88QFjfCjNbexo= X-MC-Unique: catAXm3aPIWWivKIydfJew-1 X-Mimecast-MFC-AGG-ID: catAXm3aPIWWivKIydfJew_1752491235 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491234; x=1753096034; 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=3poyEKrP2QccOsBnw3+qFZ7NtXzgmSIMZDOuRbq9Mjs=; b=LV9YT1bGxT7Syeery1N5TcU/hftci68cPW+2u6TIZEnqLlP/B92M4VTvjVjWWIdZZ7 APAGu/lfouHIaMbO2PJb6FG36foTKdS6fZ+PBjDn6cOJCWVE7wBQHvbVT/tGu+j7et2S LuEV/cATwI4oOiipjNmYRp7hJLMZRwrNQqU7xqpJ1tmCOT+mdZ6xnSITr+Rwu9BG1jdT LdZQ5f/lBjY+D8tWzL/JLx9VAI+4rI1y3ALNmkkuCe4zeWH7xVmZcGlHm2YpslZOyYnX 4l7heN+YKhhG+kXDr5U9mXshgGo/4aDU9ea/3icbIeE5x8C8iejnk3ux3JSmDcerG8qO BXrg== X-Gm-Message-State: AOJu0Yy8Vhe+cYlEotx1lvFzCMMs0CobXfkRq1yrWpqOS6SO/+8ii/9R YR4E5YdHFqN3dknTmz24EyA3cy1YOi1JZxHhPgKbNBZlFeSPcvF/Hjrt8mxLwioHkGWYPYEB+4W hkQ+lKFVvmQg9GDI19IB74tDEPK9Fq2i5v/vhBA3hlzlAQfIN8duC/tnuakBIa2BCDLOoKDb2in EJlXrv/8IWL8V3aovEHfkBojVzQ6dTwXRoXkST555L X-Gm-Gg: ASbGncuWe5GMQmNZppLZK2U1iMizfCmS6ITMYZ6nXbgUdwxzT11QZ3hBiouUFvPTjhk 7cmRBulcTltHrkhMX/x7b4hPSCZb47o84UrF+spe435ZuYCYlEnly104Ts24JCnGZ4nrb9ElWSJ RHnkZOvcQwoX9n/Hcv7MdzfMXu6eO26t49sRBvQiVgCBFyxRxuiGu9nYBKlz8RhMzJKOaIUkh/v GskAcj8TUjB9Dvm4p3sa0obiz4Yx5A931kuyQr/ycuR8qW3VpzalthXd2Bf8vKbB0BhHSs3v0Qz wmRnp7yEgMPQI+bOQljaBvYqPaEmA9UFw5MRxyYAg2o= X-Received: by 2002:a5d:4104:0:b0:3b3:9cc4:6830 with SMTP id ffacd0b85a97d-3b5f18d32ecmr9487307f8f.48.1752491234555; Mon, 14 Jul 2025 04:07:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqyOkV3uJ/cxXCSI6reKUeZK7KTQXaYb1TKAO9xCddGqX4pP6A5xN0IgUN4YttGEcr1jbqYg== X-Received: by 2002:a5d:4104:0:b0:3b3:9cc4:6830 with SMTP id ffacd0b85a97d-3b5f18d32ecmr9487274f8f.48.1752491234080; Mon, 14 Jul 2025 04:07:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Tao Su Subject: [PULL 73/77] i386/cpu: Reorder CPUID leaves in cpu_x86_cpuid() Date: Mon, 14 Jul 2025 13:04:02 +0200 Message-ID: <20250714110406.117772-74-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493159475116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Sort the CPUID leaves strictly by index to facilitate checking and changing. Signed-off-by: Zhao Liu Reviewed-by: Tao Su Link: https://lore.kernel.org/r/20250627035129.2755537-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 1a2cae6ea1f..3b7c22e5d38 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8052,21 +8052,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, assert(!(*eax & ~0x1f)); *ebx &=3D 0xffff; /* The count doesn't need to be reliable. */ break; - case 0x1C: - if (cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_ED= X_ARCH_LBR)) { - x86_cpu_get_supported_cpuid(0x1C, 0, eax, ebx, ecx, edx); - *edx =3D 0; - } - break; - case 0x1F: - /* V2 Extended Topology Enumeration Leaf */ - if (!x86_has_cpuid_0x1f(cpu)) { - *eax =3D *ebx =3D *ecx =3D *edx =3D 0; - break; - } - - encode_topo_cpuid1f(env, count, topo_info, eax, ebx, ecx, edx); - break; case 0xD: { /* Processor Extended State */ *eax =3D 0; @@ -8207,6 +8192,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } break; } + case 0x1C: + if (cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_ED= X_ARCH_LBR)) { + x86_cpu_get_supported_cpuid(0x1C, 0, eax, ebx, ecx, edx); + *edx =3D 0; + } + break; case 0x1D: { /* AMX TILE, for now hardcoded for Sapphire Rapids*/ *eax =3D 0; @@ -8244,6 +8235,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } break; } + case 0x1F: + /* V2 Extended Topology Enumeration Leaf */ + if (!x86_has_cpuid_0x1f(cpu)) { + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + break; + } + + encode_topo_cpuid1f(env, count, topo_info, eax, ebx, ecx, edx); + break; case 0x24: { *eax =3D 0; *ebx =3D 0; @@ -8472,6 +8472,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; } break; + case 0x8000001F: + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + if (sev_enabled()) { + *eax =3D 0x2; + *eax |=3D sev_es_enabled() ? 0x8 : 0; + *eax |=3D sev_snp_enabled() ? 0x10 : 0; + *ebx =3D sev_get_cbit_position() & 0x3f; /* EBX[5:0] */ + *ebx |=3D (sev_get_reduced_phys_bits() & 0x3f) << 6; /* EBX[11= :6] */ + } + break; + case 0x80000021: + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + *eax =3D env->features[FEAT_8000_0021_EAX]; + *ebx =3D env->features[FEAT_8000_0021_EBX]; + break; case 0x80000022: *eax =3D *ebx =3D *ecx =3D *edx =3D 0; /* AMD Extended Performance Monitoring and Debug */ @@ -8504,21 +8519,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx =3D 0; *edx =3D 0; break; - case 0x8000001F: - *eax =3D *ebx =3D *ecx =3D *edx =3D 0; - if (sev_enabled()) { - *eax =3D 0x2; - *eax |=3D sev_es_enabled() ? 0x8 : 0; - *eax |=3D sev_snp_enabled() ? 0x10 : 0; - *ebx =3D sev_get_cbit_position() & 0x3f; /* EBX[5:0] */ - *ebx |=3D (sev_get_reduced_phys_bits() & 0x3f) << 6; /* EBX[11= :6] */ - } - break; - case 0x80000021: - *eax =3D *ebx =3D *ecx =3D *edx =3D 0; - *eax =3D env->features[FEAT_8000_0021_EAX]; - *ebx =3D env->features[FEAT_8000_0021_EBX]; - break; default: /* reserved values: zero */ *eax =3D 0; --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494406; cv=none; d=zohomail.com; s=zohoarc; b=JYmF+t6CKKldgC6pmeRm6Wv5ETgk+IvVBd3VvZHZCz0s+Pp1FkRljfZHPOSyjIUknWuZP2ik5z5PzN7oSMlQTuLJDBPmEX8wwlUTPsMNU4VrxewuOfeGmuRLDSG/KPNwhJsuCSZ8ZeJEvsUa8oiogKfFKPTIYlDfUzHDtrry4JU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494406; 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=X6w/O8DUMjDwJGRTT3NN93h6bgPpbT9nKbZqZ0VqM/4=; b=T+XH73T5H/WFQzOP0M5jroZK5yJopBWQxtipqslZoIcayIo0MJN0RuIa+q+F83uXBqto59vDs10215es1TLboOKy9TgqICuKkT96eAe77KzQ/KhrRacwbh9sIFj8j8BfL19Q0YWBwrvmPl/QTCr/Fueebp3dD1sxVxPkHu4KehE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175249440619992.53995857661812; Mon, 14 Jul 2025 05:00:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHVv-0008Hl-IC; Mon, 14 Jul 2025 07:38:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1t-0002Ix-Ht for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1n-0002Hy-6h for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:29 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-326-AYbC0D4pNpOzd-b48XSbZw-1; Mon, 14 Jul 2025 07:07:19 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3b20f50da27so2494650f8f.0 for ; Mon, 14 Jul 2025 04:07:19 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454dd4b32d8sm129140415e9.17.2025.07.14.04.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491242; 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=X6w/O8DUMjDwJGRTT3NN93h6bgPpbT9nKbZqZ0VqM/4=; b=DYplQBEJYyrAPVknzTWJZn06dHtpy29wdR/P0yeg2OyW7vnZ5TcdjVXoDUJrvNUpWKVB26 g9SwanUIzTtMGv0RY1R7ajOQXLKTGyJ4X5NIvOPtSQuoxOHaA0RV3KryoSD4nF1efukiJT 9gn25stT0hP0R2lhtqAr3XWhtC4FvqY= X-MC-Unique: AYbC0D4pNpOzd-b48XSbZw-1 X-Mimecast-MFC-AGG-ID: AYbC0D4pNpOzd-b48XSbZw_1752491238 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491238; x=1753096038; 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=X6w/O8DUMjDwJGRTT3NN93h6bgPpbT9nKbZqZ0VqM/4=; b=M1qhGgFhGCMzy/RIlAM4pn0rwLCe04KnwA2EYP7cPrWtFwxwnAnYIVlOD6fyQ9z78r wHLxQfx4AUh4VLdjpJcXWBAnUxkHIVunlQBt/8O+lwu0WG0+SIUQxr1KdZw1q7jmu2k1 GvXG8usMCAqy67i3lOk3SaIqkpLP248AMxJbpQkK/+GEnGYgleVwbDOPrVKyP2fhmNqE FuFTZSGKuB4gYhE/YSv7nROs7tTniv+1/a3+7wBjlDo1td7kAbw+2wP5FvJ7zYJWiQUK krRXiPDOr8KQix3jweWHnT4aGFU5YsED/6kOSmeSbR3WGbQj58G95cMFR5jbyvEJ2SFD mzqQ== X-Gm-Message-State: AOJu0YxotDbpSU9SHon3kqEc3oZfws9CNQxEAZbK597BNV47I/nRyF+h Wa6QN6k2QjkMIbveEl59Eq7julCDq267h+xFdmgT0LyLBxP4U7QnFJanspp0cL3J93IPXqhG21w K1FwjpXUjJc3djH+Gp869XQ86t4lUIzyKMNegzNG1jTDslPyG9EtP3Sk8URTlgIxLDy96Na91U4 iqXH2OIV53+dnNEZ09nNqPTcPCCvAddUYVF6BGruxx X-Gm-Gg: ASbGncsrXnRUyEeaRG0LxR/No4w9/hd4DUdUPvxhZbiFHfdeYoYND7tX4VOhS0TjJWD XB3WNF9x5CvpFl6YbzR4l582lH4TKJcNUq5WNH8Y52GhUOhawlUmZ2A1QzARUA0VyzP4jVMZVF5 x0T2ees7XOa8hDm40c9fQBaP/Xj0MNjg3RjvMmXvEMP9JzRyA01VEgYs7UGXPUJUQtt9eidsrCc L9hgl1IghJ7eYUq3xlUlXYgBFN4cIXxOQTt4EqQyG80hIt2DrMJouwvoEA0lFCgzHl4aVJJaRa/ 0eDFlATn4tNA0KQcEonrW9wrzfWTozYOdj60fKQ4adk= X-Received: by 2002:a05:6000:642:b0:3a4:da0e:517a with SMTP id ffacd0b85a97d-3b5e7f34e49mr14461016f8f.23.1752491237763; Mon, 14 Jul 2025 04:07:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaO/Bviye0gYD4qsJFPYwbD23m4B5O57FcePslOpsQMTLobrSRkA03oP4Z76xk1dD3Pi0s4w== X-Received: by 2002:a05:6000:642:b0:3a4:da0e:517a with SMTP id ffacd0b85a97d-3b5e7f34e49mr14460985f8f.23.1752491237289; Mon, 14 Jul 2025 04:07:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Chuang Xu , Zhao Liu , Guixiong Wei , Yipeng Yin Subject: [PULL 74/77] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16] Date: Mon, 14 Jul 2025 13:04:03 +0200 Message-ID: <20250714110406.117772-75-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494408578116600 Content-Type: text/plain; charset="utf-8" From: Chuang Xu When QEMU is started with: -cpu host,migratable=3Don,host-cache-info=3Don,l3-cache=3Doff -smp 180,sockets=3D2,dies=3D1,cores=3D45,threads=3D2 On Intel platform: CPUID.01H.EBX[23:16] is defined as "max number of addressable IDs for logical processors in the physical package". When executing "cpuid -1 -l 1 -r" in the guest, we obtain a value of 90 for CPUID.01H.EBX[23:16], whereas the expected value is 128. Additionally, executing "cpuid -1 -l 4 -r" in the guest yields a value of 63 for CPUID.04H.EAX[31:26], which matches the expected result. As (1+CPUID.04H.EAX[31:26]) rounds up to the nearest power-of-2 integer, it's necessary to round up CPUID.01H.EBX[23:16] to the nearest power-of-2 integer too. Otherwise there would be unexpected results in guest with older kernel. For example, when QEMU is started with CLI above and xtopology is disabled, guest kernel 5.15.120 uses CPUID.01H.EBX[23:16]/(1+CPUID.04H.EAX[31:26]) to calculate threads-per-core in detect_ht(). Then guest will get "90/(1+63)= =3D1" as the result, even though threads-per-core should actually be 2. And on AMD platform: CPUID.01H.EBX[23:16] is defined as "Logical processor count". Current result meets our expectation. So round up CPUID.01H.EBX[23:16] to the nearest power-of-2 integer only for Intel platform to solve the unexpected result. Use the "x-vendor-cpuid-only-v2" compat option to fix this issue. Reviewed-by: Zhao Liu Signed-off-by: Guixiong Wei Signed-off-by: Yipeng Yin Signed-off-by: Chuang Xu Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250714080859.1960104-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3b7c22e5d38..12e719e9957 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7871,7 +7871,17 @@ 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; + /* + * For CPUID.01H.EBX[Bits 23-16], AMD requires logical process= or + * count, but Intel needs maximum number of addressable IDs for + * logical processors per package. + */ + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *ebx |=3D 1 << apicid_pkg_offset(topo_info) << 16; + } else { + *ebx |=3D threads_per_pkg << 16; + } } break; case 2: { /* cache info: needed for Pentium Pro compatibility */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494178; cv=none; d=zohomail.com; s=zohoarc; b=hU4sDbWBbNLfpnf/eEWe7U+6GEaJjUWFzEabVqW+QPm+Y2JsYoCrfvvdMEMGF2o1s0gfsQCtKTdKpPL5FHkSmrxRdfRYupOLWHxAYpFqRja+3JvIP6NQEucRib+zlfuvgBnlpqWPGMdX/p1YsMUG2zpNgDn8htJq9MrciFYzDfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494178; 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=Lx/3OjKQQiRwtu1QUxLqhLmOvdf3soAfb9Z3azPYw/Q=; b=V20Hm5hcWrIVjqC9XR/PaLWzcdxnEB3Mv4YV5KAM2yVP6AJ1LFTQlnPOY3xreN/B6YP0RlJ9hBqOmSKJltND/fYqk820RP8a6rEJrYAlSUYMGApB35K/WolWarbDP/jihuxhpUzRc38lB7juUxoEdsJ6ZVZkyqU7Jp4GtnU3OSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752494178949695.9849119454576; Mon, 14 Jul 2025 04:56:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHas-0003fw-AZ; Mon, 14 Jul 2025 07:43:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1r-0002Gs-Gi for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1o-0002I8-SL for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:27 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-GbReMxxdN62UnJ_54_n1SQ-1; Mon, 14 Jul 2025 07:07:22 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4845325e9.1 for ; Mon, 14 Jul 2025 04:07:22 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d587sm11907762f8f.46.2025.07.14.04.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491243; 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=Lx/3OjKQQiRwtu1QUxLqhLmOvdf3soAfb9Z3azPYw/Q=; b=H7mwPrpJYIq3UYx4OisjagINGW1EKLm3l9rpDMp/nDB9/n7BYYRgTTEN95uAL5axwCq2r/ ZiGLev/QqRV3I0uom4ZGMvLU63AB3EzCl0R8n0VINwEB2kf8QfRPjYe0cUe+yZ1b3YH/sn SpCBXhj4/rywuqz+Ngkab6lja2wlMQ4= X-MC-Unique: GbReMxxdN62UnJ_54_n1SQ-1 X-Mimecast-MFC-AGG-ID: GbReMxxdN62UnJ_54_n1SQ_1752491241 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491241; x=1753096041; 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=Lx/3OjKQQiRwtu1QUxLqhLmOvdf3soAfb9Z3azPYw/Q=; b=lAatpUyt91DrKtwrhDA7QtymlowfpKPn/syDJjOVYwkGoYab1FulcsrzXB1EHwPp2P KtiQYhtNlzssEx+wecD7WYZSqjQcusY1e7TYEPz0byMFuBnqOzM7k15ujTQIH4P62Or1 GwyZgTyA9Ft0WswaWr/FdsPN9N2cAfufxFPkxD5FCQbYN4JIao8RQCo3b88zjwZKPpmJ Z97x8+Jcy2YeZp1VqPqBmwD7LJo/IsttsuKtkDn1CUOzZyPwDScbaFnOzaPEYaVlsFDn MndgfEqABCR7AB7BaWgQD5nIM1yp5my+FCchxYfOXg5UazNhfB42cxMHxxVW6KUYzc1g qrWA== X-Gm-Message-State: AOJu0YxwwCWijPv6xMC6iMOFP1jI0UVkOeB5nS7YR3pPjKYbXXKbMj8u 1iq+A7+uBAp6kM+LBmH9PROP1o7aqLBHeTWyF1Herzlg2XMkNNGHOt1iCdNzTsDI4BEfsIdm9r3 4QiKwEq+3Fh/5OcsY+nfkoDObKycS9375vIfKNa6xZQ77fq51qIcIr04eY2zKZYv5eQLJwU+55E xWJbyMwFuOOt1eXiPPI1nFNchQU/wsPcY3YsDR3KTb X-Gm-Gg: ASbGncsZokWtBiB0qaw9yTfMNHuKbUJzyH0H0iV5TIqtGDjGOeZLBSIZ7TBuEv+KxQt eZsKPCmd0lHO95Hlm3Sz12DB8r9MSSYMsgSdv+KCoqQoUQrUVI+dkFsNPPXUV12u3XFszgsCsye Nu02P4L9KJaehkXOZGhWDk/9XfxStWuQLez9Go4jb6rcFd3wdFf/Ixy0+vxa9/x5qNdIToXhNh2 1yad2nYYrRFuhUJNLVh+Mh56HdLzwN0M/zZWhtG0pLwm7LXc+X71kJobSDi8g62a9De+sDOcvRe kDjmDsKm0rn2YD8SRzC5X9Ya9yeLjAdpuJkQ98kCx1c= X-Received: by 2002:a05:600c:1c23:b0:456:2347:3f01 with SMTP id 5b1f17b1804b1-45623474399mr4341475e9.20.1752491240714; Mon, 14 Jul 2025 04:07:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHecDM8iuOfxAcVoT02BLVouFzGYITNitOhWCHtmLENnuMQ7tX9cWWYCHnvgUBPgiaIlFfK2w== X-Received: by 2002:a05:600c:1c23:b0:456:2347:3f01 with SMTP id 5b1f17b1804b1-45623474399mr4340995e9.20.1752491239785; Mon, 14 Jul 2025 04:07:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Qian Wen , qemu-stable@nongnu.org, Xiaoyao Li , Zhao Liu Subject: [PULL 75/77] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16] Date: Mon, 14 Jul 2025 13:04:04 +0200 Message-ID: <20250714110406.117772-76-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494181807116600 Content-Type: text/plain; charset="utf-8" From: Qian Wen The legacy topology enumerated by CPUID.1.EBX[23:16] is defined in SDM Vol2: Bits 23-16: Maximum number of addressable IDs for logical processors in this physical package. When threads_per_socket > 255, it will 1) overwrite bits[31:24] which is apic_id, 2) bits [23:16] get truncated. Specifically, if launching the VM with -smp 256, the value written to EBX[23:16] is 0 because of data overflow. If the guest only supports legacy topology, without V2 Extended Topology enumerated by CPUID.0x1f or Extended Topology enumerated by CPUID.0x0b to support over 255 CPUs, the return of the kernel invoking cpu_smt_allowed() is false and APs (application processors) will fail to bring up. Then only CPU 0 is online, and others are offline. For example, launch VM via: qemu-system-x86_64 -M q35,accel=3Dkvm,kernel-irqchip=3Dsplit \ -cpu qemu64,cpuid-0xb=3Doff -smp 256 -m 32G \ -drive file=3Dguest.img,if=3Dnone,id=3Dvirtio-disk0,format=3Draw \ -device virtio-blk-pci,drive=3Dvirtio-disk0,bootindex=3D1 --nographic The guest shows: CPU(s): 256 On-line CPU(s) list: 0 Off-line CPU(s) list: 1-255 To avoid this issue caused by overflow, limit the max value written to EBX[23:16] to 255 as the HW does. Cc: qemu-stable@nongnu.org Reviewed-by: Xiaoyao Li Signed-off-by: Qian Wen Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250714080859.1960104-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 12e719e9957..608fdcf7578 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7871,6 +7871,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, } *edx =3D env->features[FEAT_1_EDX]; if (threads_per_pkg > 1) { + uint32_t num; + /* * For CPUID.01H.EBX[Bits 23-16], AMD requires logical process= or * count, but Intel needs maximum number of addressable IDs for @@ -7878,10 +7880,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, */ if (cpu->vendor_cpuid_only_v2 && (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { - *ebx |=3D 1 << apicid_pkg_offset(topo_info) << 16; + num =3D 1 << apicid_pkg_offset(topo_info); } else { - *ebx |=3D threads_per_pkg << 16; + num =3D threads_per_pkg; } + + /* Fixup overflow: max value for bits 23-16 is 255. */ + *ebx |=3D MIN(num, 255) << 16; } break; case 2: { /* cache info: needed for Pentium Pro compatibility */ --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752494415; cv=none; d=zohomail.com; s=zohoarc; b=XS/PrHHG5KN9/SC+m1Tf/mYVmwgYfHHMy8H1StBf2W8w4U5DSssyHeqTbFOqBAiqptRGrUX/DtV0U23781SnSS1JUK5AbOawUDgKmM7r5OefDLwSbk4knE0OFzIk219haDJ9U11EqQHlq3J0PPNel9tMyQbOostMERDvDWV50Q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752494415; 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=K7ivlVK8LeaiN4yE6sBu0n/7LdVsgXH72+awvNRHcSA=; b=gzmtEIL/lJHei0buD0BMI+JeGP1eGiUfK66lg8fGw6Dz/1h/R+GRhn4GrIJJnp7sMmD7x4L0WqPcT0+F3He6kjnPjuBkZwbHpmdR8qwtVrSXFcBYB2Mog3QnI2X1ssyAP0dlD4kcw4Eyo9Tw98js6+5j5OKNQ1wBhbilqJd0ZEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752494415359710.4785900978188; Mon, 14 Jul 2025 05:00:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHbk-0004hJ-79; Mon, 14 Jul 2025 07:44:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1t-0002Iz-JJ for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1r-0002Ii-H4 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:29 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-iDch3j22NOigMsAX0XG6dA-1; Mon, 14 Jul 2025 07:07:25 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a6d1394b07so2934839f8f.3 for ; Mon, 14 Jul 2025 04:07:25 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc21e7sm12141494f8f.36.2025.07.14.04.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491246; 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=K7ivlVK8LeaiN4yE6sBu0n/7LdVsgXH72+awvNRHcSA=; b=cWcHp2H9DGuiEhwSBMFfa91v/1R2Q+xA1Mlxw1WRlih6o3PaJm725v8pCpkyWvgzn6z3sG XHstjBzghNiiLpdgGb24d67CJUTwEs9vS7ZFGdCXB3fVfjWNHuEfCkr7Ke5/qQIpjR4qyG 5fxRsEUzfDWvgm0ckxi0dl+qeFAtG4Y= X-MC-Unique: iDch3j22NOigMsAX0XG6dA-1 X-Mimecast-MFC-AGG-ID: iDch3j22NOigMsAX0XG6dA_1752491244 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491244; x=1753096044; 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=K7ivlVK8LeaiN4yE6sBu0n/7LdVsgXH72+awvNRHcSA=; b=vpeWJ+3A06/Or6tDimv3unxHJNELUzM/FvTTC8Hoed5GqMiNPAv+87RpdX+W9yM6s4 SiUgHQwOVFobQ2bgQdBeNCkaq9+htxnsUwRuzc/VWhZ1H3Ge7+mIOsESwuFvpKUen/0q 7AgEWC6zJu684P6GGbRMTygkB35k9voftCOSQVFX6jcjErBohg4SlWR3SHOgyyrs8Pjz SuqH9EjfSkoYcCTiuqGw1WVI8MF3XqpdKpGfSzXD98GIWwBXjsR5BWhsWbi38DN31fKH Te0KQ1V+y3WUJ/twMYEFn9UlFdSApmVdavWicPS30ScZNXEJKyqVZAMas7efL5KslVvw gdHQ== X-Gm-Message-State: AOJu0YxXEttOfL1TefGQd1PLsoDzD/X/j8qBFoBUILqA0YrY2hV4z71Q XNgmIwiQiFsj3VjlL2e+Kp/y+blFiZ0IBhWZST02GROuBXggN7CSZFh/GdMQ95izZPtZLWFG1Es cDs1vtjkTW+l045Q1Gdg4M6U6v7tvKRQOjUvHPOxsSc6gU6QSpRQpuKmt7R35QGXXEno5+f7Z3E dZachT9DLaBf2zmCFAPkp3aoey/E36ASmdlY1CJTPj X-Gm-Gg: ASbGncu1p+vZsuPjWZEMS2hf5MK6flfprOUPnrlrpoHohI5OzStxOu2v09WunBXM5OU c5wvF+b0JYnAlUXl/if5mVGedRkVioZJS+a3dbykZHEMA/okZfDyam1QCE+pOfKNotWP6IHvT1U KlLag29AS6ad+OhBCRYHzVOvfsEWxjmXZe5M/fJjo1YUp+153dvi1Ygi4vsdxHfpW6T+OUpEotD Uy80ZHJcNplNj0dQI6kVl6QRGpv9CwLyK0zMiDG448eqMKWTKW3Qg01LwwhIuZj+3bx/sV/bW7j vPmiS4ds78WiVuGLQY/DrlQDyG15zce6g5GDjn43Bfk= X-Received: by 2002:adf:b650:0:b0:3a4:d722:5278 with SMTP id ffacd0b85a97d-3b5f1895d50mr9146919f8f.39.1752491243544; Mon, 14 Jul 2025 04:07:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEORH0RXW9jtd69kPa62/b5ZeVctH+2Slc5bUIjw63vmz7pBn7nztYSbvBhRRGvcVQ4fEkd3A== X-Received: by 2002:adf:b650:0:b0:3a4:d722:5278 with SMTP id ffacd0b85a97d-3b5f1895d50mr9146886f8f.39.1752491242953; Mon, 14 Jul 2025 04:07:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Qian Wen , Xiaoyao Li , Zhao Liu Subject: [PULL 76/77] i386/cpu: Fix overflow of cache topology fields in CPUID.04H Date: Mon, 14 Jul 2025 13:04:05 +0200 Message-ID: <20250714110406.117772-77-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752494416620116600 Content-Type: text/plain; charset="utf-8" From: Qian Wen According to SDM, CPUID.0x4:EAX[31:26] indicates the Maximum number of addressable IDs for processor cores in the physical package. If we launch over 64 cores VM, the 6-bit field will overflow, and the wrong core_id number will be reported. Since the HW reports 0x3f when the intel processor has over 64 cores, limit the max value written to EAX[31:26] to 63, so max num_cores should be 64. For EAX[14:25], though at present Q35 supports up to 4096 CPUs, by constructing a specific topology, the width of the APIC ID can be extended beyond 12 bits. For example, using `-smp threads=3D33,cores=3D9, modules=3D9` results in a die level offset of 6 + 4 + 4 =3D 14 bits, which can also cause overflow. check and honor the maximum value for EAX[14:25] as well. In addition, for host-cache-info case, also apply the same checks and fixes. Reviewed-by: Xiaoyao Li Signed-off-by: Qian Wen Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250714080859.1960104-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 608fdcf7578..fdc677614d8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -349,11 +349,17 @@ static void encode_cache_cpuid4(CPUCacheInfo *cache, assert(cache->size =3D=3D cache->line_size * cache->associativity * cache->partitions * cache->sets); =20 + /* + * The following fields have bit-width limitations, so consider the + * maximum values to avoid overflow: + * Bits 25-14: maximum 4095. + * Bits 31-26: maximum 63. + */ *eax =3D CACHE_TYPE(cache->type) | CACHE_LEVEL(cache->level) | (cache->self_init ? CACHE_SELF_INIT_LEVEL : 0) | - (max_core_ids_in_package(topo_info) << 26) | - (max_thread_ids_for_cache(topo_info, cache->share_level) << 14); + (MIN(max_core_ids_in_package(topo_info), 63) << 26) | + (MIN(max_thread_ids_for_cache(topo_info, cache->share_level), 4= 095) << 14); =20 assert(cache->line_size > 0); assert(cache->partitions > 0); @@ -7930,13 +7936,13 @@ 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 MIN(max_core_ids_in_package(topo_info), 63) << 2= 6; 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, - CPU_TOPOLOGY_LEVEL_SOCKET) << 14; + *eax |=3D MIN(max_thread_ids_for_cache(topo_info, + CPU_TOPOLOGY_LEVEL_SOCKET), 4095) << 14; } } } else if (cpu->vendor_cpuid_only && IS_AMD_CPU(env)) { --=20 2.50.0 From nobody Sat Nov 15 12:16:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493554; cv=none; d=zohomail.com; s=zohoarc; b=G3eHjZwK7SNkEk81O+oKPdH/2X73sz6syFHI/SPjDXcX7oCznPfCkABlEFhUpyVImEBA5duUz9NzM1v814IfSa7uRhSS3WHXJkaALcml3BtQgrR7FOc0q9cV+H3PcaxXu31/2ptaHJAvQIIG7U+tTpP1Dr7CKVYUoyVAkoQj3u8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493554; 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=kAj8gNQPx0+zlFmRZi9dDjnOFhk6i3lq0mODeXaaGSw=; b=OWmoY4Vq7DkZoOXizGSQu1dhDXqcmhB400TpL1v7F6vEGdlcsjjwOdgts41yMSolMET7bfLAM7NkXd+oIJsIUCXdBOEBqodEyrDmGr2LSGKbqUxNSQyio3VeI/Kpo4I38kIzYUSJwszvkHBMkZwjWHEW0qg90/RrNFYHzNC7RFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493553927702.2848610319433; Mon, 14 Jul 2025 04:45:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHXM-0000ZG-6n; Mon, 14 Jul 2025 07:40:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1x-0002Oq-Fv for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH1u-0002JI-Jz for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:07:32 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-Jh6ffjNJOj-NDO7UTE9mlA-1; Mon, 14 Jul 2025 07:07:28 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-45597cc95d5so15277355e9.1 for ; Mon, 14 Jul 2025 04:07:27 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4561d19a21dsm19914315e9.24.2025.07.14.04.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491249; 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=kAj8gNQPx0+zlFmRZi9dDjnOFhk6i3lq0mODeXaaGSw=; b=Ar8+9Z5XVeObfiQucNT7L9M7z+mjQSWOKjgHe1qRoGBGc5lONal268vY2aruHOwI0Ii1em cFye/7i+gmckUxNrlkQBj9IGGOwAymLqs9QS27AXT42rmKkJw85QnsuHNWhw/WJtD6Uvea 9mFzmpSQk6KqNa3eu3wIBLXHSuuCtwQ= X-MC-Unique: Jh6ffjNJOj-NDO7UTE9mlA-1 X-Mimecast-MFC-AGG-ID: Jh6ffjNJOj-NDO7UTE9mlA_1752491247 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491246; x=1753096046; 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=kAj8gNQPx0+zlFmRZi9dDjnOFhk6i3lq0mODeXaaGSw=; b=uRpaRYfqSQWK/KMbaAasFmwj9PUF4KXOfeFLtagy8DpSDzT3MVjdbqo59LwK7mu0Ql Lw9Vz1h2Oa6El3/I4ZLiKpGX2Gid7drBaFJuUugphJ2a1voEB4uaLuoV3w88XJeIz/sl tYqCL6VE1qVvb74DKRhlxT+8QJoXYpngq7ipxJ8KlLfTozDldbDiNhXsNWZXV3yzRpfc PC3Nz6A746vJCIAL2JHMlBU+xSzIVvYqG2xArufmT4GL9xpGvItjNgEnKUhn9kC9/Xwf YPXL0Rtzi3HJfbko6Yf0+VsnX5GYw0UeSrP3Amw8IL5j9YsUIzlJFuUp9jTKiahG4Eon nQVQ== X-Gm-Message-State: AOJu0Yz+gF4PPMXrMh1kOMcC5hqjmA9sHyMJL+cumAcDkSekbmHk6pZT pGb3GHVQgqPk7tUz6z8ceTyTi2G4OUaReDTGiPINPnyFLs5iQKCLtvCpQ7+3EDY5wvjb9p7h5TR gdz+pvDikYe7xEXw475S8oTeDY6UuV///I6HB3GpYJR4iwpqSl2efqZpZqE8hIhGpJ4cmldOFl/ VIPypQYZN+7Eh/aLycBanpYK/8yCkmdocchcrqBzFh X-Gm-Gg: ASbGncv5gjPz8wpZldlUcu4g0OUIgT1O7o4KSyeHEpL1icyA0hwl5G3k5TJQwK759QM JzRb4Up4qpLKviKQJVcKfaZ3AcFuItVR1K5h6TkvJiJHsxUJpYjwbD5Y0EGKC/y2YIu4sr/sRh5 RHC6fjgBhiRj/zPy8/Bvp1nLrC6eTcfxOoskZ9CWu7EPSPMw6OZaV8RKMfN6ThMtiMAwVmDBBO6 YbFEcckR/jomIOpIu14x1wCSmbaTvk83uIDul4v9997tGrhhEmRRZUHbBHisDFQPduyNzk4/UQ2 WmapiTuc4QjylrZ0CUVp3Sz6mJdSIFxZcJYGrYbb2w4= X-Received: by 2002:a05:600c:4f91:b0:453:62e9:125a with SMTP id 5b1f17b1804b1-454ec27dc91mr124181775e9.18.1752491245828; Mon, 14 Jul 2025 04:07:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTfQx0TSbr4qUaRQlVn5DvSM6Dn1S6BaJpd4uCbAN1z4RKQZguC7Sry47iia+2Z3aIvO6DLQ== X-Received: by 2002:a05:600c:4f91:b0:453:62e9:125a with SMTP id 5b1f17b1804b1-454ec27dc91mr124181485e9.18.1752491245371; Mon, 14 Jul 2025 04:07:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Babu Moger Subject: [PULL 77/77] i386/cpu: Honor maximum value for CPUID.8000001DH.EAX[25:14] Date: Mon, 14 Jul 2025 13:04:06 +0200 Message-ID: <20250714110406.117772-78-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493555733116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu CPUID.8000001DH:EAX[25:14] is "NumSharingCache", and the number of logical processors sharing this cache is the value of this field incremented by 1. Because of its width limitation, the maximum value currently supported is 4095. Though at present Q35 supports up to 4096 CPUs, by constructing a specific topology, the width of the APIC ID can be extended beyond 12 bits. For example, using `-smp threads=3D33,cores=3D9,modules=3D9` results = in a die level offset of 6 + 4 + 4 =3D 14 bits, which can also cause overflow. Check and honor the maximum value as CPUID.04H did. Cc: Babu Moger Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250714080859.1960104-8-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fdc677614d8..da7d8dca633 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -560,7 +560,8 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *ca= che, =20 *eax =3D CACHE_TYPE(cache->type) | CACHE_LEVEL(cache->level) | (cache->self_init ? CACHE_SELF_INIT_LEVEL : 0); - *eax |=3D max_thread_ids_for_cache(topo_info, cache->share_level) << 1= 4; + /* Bits 25:14 - NumSharingCache: maximum 4095. */ + *eax |=3D MIN(max_thread_ids_for_cache(topo_info, cache->share_level),= 4095) << 14; =20 assert(cache->line_size > 0); assert(cache->partitions > 0); --=20 2.50.0