From nobody Wed Apr 2 13:15:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1741161096; cv=none; d=zohomail.com; s=zohoarc; b=WRlaV8fdQvoLCAktRSN1CSm8XuSNYtx+VNBMwD69xMOgLbNXka0R65DV+pmdyEkWSNB4NKov4yL4zfW13oEmhImLKqMbMUc41eszaJv92sfbgntk1zXxzKGUxjlc4Tr/GPdM6qEadx1cpLhuYof9ObT3sTNng45qlKTcy6h1Sc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741161096; 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=U2DLL5DRuBp6sKC8Xt2pwlNQ1+iiI+ge2C9GP+hRBYU=; b=k65Z4B59MSdsZgYDVbbnkvAKS3lDt8sSliXKEVJ7koIYW1Xj0q27dcA2CwFtilz4tTtCugpKw5zns2R+F0JXvLGZOTQ1pcskvs/P/INQun++0Z5SxAX5alp9CVOmFHoOR2RjvOAf2GVlH9Jhgzkx0LsCjtsrsEOpjaAFZR70p68= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741161096193476.9760872292326; Tue, 4 Mar 2025 23:51:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpjWs-0004X1-PF; Wed, 05 Mar 2025 02:50:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjWo-0004Wd-DB for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:50:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjWi-00077R-JI for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:50:54 -0500 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-hobXsJ4pOpK09Sn_XN1iLA-1; Wed, 05 Mar 2025 02:50:46 -0500 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-22356964533so94490165ad.3 for ; Tue, 04 Mar 2025 23:50:46 -0800 (PST) Received: from localhost.localdomain ([115.96.122.38]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-223501d2778sm107425355ad.36.2025.03.04.23.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 23:50:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741161047; 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=U2DLL5DRuBp6sKC8Xt2pwlNQ1+iiI+ge2C9GP+hRBYU=; b=Zedon4GzKv0gUIi1oLr/SDKI0x0k3YeuOUx7FPeV/IjNpXC34e7zjeCxFZYMGhroj1uObE RW1aY6M/+XLItdaQtqLgTjfcf8gMA4uGG6N0SXMJTYpO4Gw/2jgYBEqGeNfH3zLXMtgVv6 5ziaubvekKcEnlAlWyWdvJJ2TkfE7TA= X-MC-Unique: hobXsJ4pOpK09Sn_XN1iLA-1 X-Mimecast-MFC-AGG-ID: hobXsJ4pOpK09Sn_XN1iLA_1741161045 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741161045; x=1741765845; 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=U2DLL5DRuBp6sKC8Xt2pwlNQ1+iiI+ge2C9GP+hRBYU=; b=iixYylZiH8D/HHS39MbWOTNdp+yEqAm1afk1c/AgDvo3SaaVJ/PRrKLVz12DltDRTI pGNCcUnQWRa/mHw2w1V38ahAueWTwfbklNhZdsGcbDctsdXuzpOBU8CRIqCHl3WbybYJ VOWDg5wRA1iXSpjkfYVuHNcwuOj9EFOJ810U8BSQspEZGbt3/BQyHbMhd+jQIijx2/Ph Pwqqim0NMONA8I7DTRwfXOZr1Qdr2qLz9yV8NiUoObrRD9vgg7rJS+z8BBPumr4LQpQI 38xGGjHnV7DmmTeWCdESXhGCRubUGkXA9bzq/OUB8nnQwTkoNn68mfDZqtT886dnoDYU Iwrw== X-Forwarded-Encrypted: i=1; AJvYcCXKBGwzAQpV8Imt5syx+PMtdjoMBlQ4UTg+r5kgpahQbuz/VyodLsGxbiNv9N9mKxIvpQlVX0/FcjX3@nongnu.org X-Gm-Message-State: AOJu0YwjHQYbJ6ytHp2nmwBFADRVZbimqscJKx9ohfC8dHL2UEX5ONDu zSI/RVr+TSbBwAhgOrJYWkvvLrLYec8NyoUsfGFuQj/l0DutYBZng4IjE8gNwfmEezuvIX5Ce/r OT5RSiwZh84VSyBqmGP1JxSGmFgT47mwiX/DLhLTRgifNM5HWRfM8 X-Gm-Gg: ASbGncvSGw3pLzkAnugIs5kR2xWsVh/El8Kdax689Wumzkq8h2yI9uJuufXpcyVjBj0 /5SC1iyKaK0ZZ3cemsoCd0dJorBaE1Jjty0/r00Iz+H/xEg0mguH0ZTZUphpWf89/HEsZ1ElTLj aY3/HJwLVpI5ysSuqWGBobbM//kgM33v5Cr9GzJ7EFXtPt9LQRHy6wXRg3YD1It8jkAaKNQBjO9 zyVa/TYCA9gnrQTVkht0zEIG7Nzi2nE6P7FRSY2v5eO3u77ese3qW6hWVPcUBHEBFR6KMeJESUi g2iLPMrshUAUwoweJwuj+agYpdg= X-Received: by 2002:a17:902:ea12:b0:220:e63c:5aff with SMTP id d9443c01a7336-223f1d337ffmr26801065ad.47.1741161045025; Tue, 04 Mar 2025 23:50:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZvzBg4wNLykVDCHdYyzRVJ+wzmr/bvPDVGwrPpDci52YtVAPgtiWrZaj9Zy6tGZTFjynv6Q== X-Received: by 2002:a17:902:ea12:b0:220:e63c:5aff with SMTP id d9443c01a7336-223f1d337ffmr26800925ad.47.1741161044664; Tue, 04 Mar 2025 23:50:44 -0800 (PST) From: Ani Sinha To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, Ani Sinha Subject: [PULL 1/3] hw/i386: introduce x86_firmware_reconfigure api Date: Wed, 5 Mar 2025 13:20:13 +0530 Message-ID: <20250305075015.26892-2-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250305075015.26892-1-anisinha@redhat.com> References: <20250305075015.26892-1-anisinha@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=anisinha@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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1741161097605019000 Content-Type: text/plain; charset="utf-8" Normally, there is no need to perform firmware reconfiguration once the virtual machine has started. Hence, currently ovmf firmware parsing happens= only once. However, if the firmware changes betweeen boots then reconfiguration = needs to happen again. Firmware can change if for example the guest brings its own firmware bundle and installs it with the help of the hypervisor[1]. Therefo= re, this change introduces a new api with which firmware configuration steps can be forced again. This is mostly refactoring work. No functional changes. CI pipeline does not break with this change. 1) https://pretalx.com/kvm-forum-2024/talk/HJSKRQ/ Message-ID: <20250228114230.306852-1-anisinha@redhat.com> Signed-off-by: Ani Sinha Reviewed-by: Gerd Hoffmann --- hw/i386/pc_sysfw.c | 26 ++++++++++++++++++-------- hw/i386/pc_sysfw_ovmf-stubs.c | 5 +++++ hw/i386/pc_sysfw_ovmf.c | 5 +++++ include/hw/i386/pc.h | 1 + include/hw/i386/x86.h | 1 + 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 1eeb58ab37..a9943d95c8 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -258,16 +258,9 @@ void pc_system_firmware_init(PCMachineState *pcms, pc_system_flash_cleanup_unused(pcms); } =20 -void x86_firmware_configure(hwaddr gpa, void *ptr, int size) +static void x86_firmware_configure_sev(hwaddr gpa, void *ptr, int size) { int ret; - - /* - * OVMF places a GUIDed structures in the flash, so - * search for them - */ - pc_system_parse_ovmf_flash(ptr, size); - if (sev_enabled()) { =20 /* Copy the SEV metadata table (if it exists) */ @@ -282,3 +275,20 @@ void x86_firmware_configure(hwaddr gpa, void *ptr, int= size) sev_encrypt_flash(gpa, ptr, size, &error_fatal); } } + +void x86_firmware_configure(hwaddr gpa, void *ptr, int size) +{ + /* + * OVMF places a GUIDed structures in the flash, so + * search for them + */ + pc_system_parse_ovmf_flash(ptr, size); + x86_firmware_configure_sev(gpa, ptr, size); +} + +void x86_firmware_reconfigure(hwaddr gpa, void *ptr, int size) +{ + invalidate_ovmf_parsed_metadata(); + pc_system_parse_ovmf_flash(ptr, size); + x86_firmware_configure_sev(gpa, ptr, size); +} diff --git a/hw/i386/pc_sysfw_ovmf-stubs.c b/hw/i386/pc_sysfw_ovmf-stubs.c index aabe78b271..edf890a525 100644 --- a/hw/i386/pc_sysfw_ovmf-stubs.c +++ b/hw/i386/pc_sysfw_ovmf-stubs.c @@ -24,3 +24,8 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_= t flash_size) { g_assert_not_reached(); } + +void invalidate_ovmf_parsed_metadata(void) +{ + g_assert_not_reached(); +} diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c index 07a4c267fa..3244c17a7d 100644 --- a/hw/i386/pc_sysfw_ovmf.c +++ b/hw/i386/pc_sysfw_ovmf.c @@ -36,6 +36,11 @@ static bool ovmf_flash_parsed; static uint8_t *ovmf_table; static int ovmf_table_len; =20 +void invalidate_ovmf_parsed_metadata(void) +{ + ovmf_flash_parsed =3D false; +} + void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size) { uint8_t *ptr; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 103b54301f..7b0d0c54f5 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -211,6 +211,7 @@ void pc_system_firmware_init(PCMachineState *pcms, Memo= ryRegion *rom_memory); bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len); void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size); +void invalidate_ovmf_parsed_metadata(void); =20 /* sgx.c */ void pc_machine_init_sgx_epc(PCMachineState *pcms); diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index d43cb3908e..18c0d6851a 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -155,5 +155,6 @@ DeviceState *ioapic_init_secondary(GSIState *gsi_state); =20 /* pc_sysfw.c */ void x86_firmware_configure(hwaddr gpa, void *ptr, int size); +void x86_firmware_reconfigure(hwaddr gpa, void *ptr, int size); =20 #endif --=20 2.42.0 From nobody Wed Apr 2 13:15:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1741161090; cv=none; d=zohomail.com; s=zohoarc; b=efDMB80tUFA/IqESx8cfdKqMyXKV8E0Vb96effmGdr4TAKQkYPDa3OOO2qRdcWe6aBTc9rEV5QOtivSPFcNRwoQJj1AcKQkd3uinwnr1IfQw9YtB0B5VHBLDPxDaFfH/fftUZVP/1g5LUKoqFzSDb1kWt4hG373PBaNfob4gvbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741161090; 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=pEUuRTuxISH7VrsnrtIj3pcFJONapnsboe6eHEzJt+0=; b=BAfPAj2O7bZGdf22DPflCmb8AqCaxP3b1iIelniCgxYXlUb2q/L8dlrVc+Y5i5UBlLQ4plANQiYaXuYZNmpUZXOdKCulwhox6z8UlCxwnm/Ga+5mz9zDaAqGjxrwabJuazseAyiZtYYjDoVJ7uAPbPzMZqecVPP5BqVHrnePqgY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741161090361390.7635741868164; Tue, 4 Mar 2025 23:51:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpjWy-0004Xz-Rx; Wed, 05 Mar 2025 02:51:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjWx-0004Xo-B1 for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:51:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjWv-0007DS-Nv for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:51:03 -0500 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-sCiHA3WTNjCKybDUaNPwtQ-1; Wed, 05 Mar 2025 02:50:51 -0500 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2234c09241fso190270915ad.2 for ; Tue, 04 Mar 2025 23:50:51 -0800 (PST) Received: from localhost.localdomain ([115.96.122.38]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-223501d2778sm107425355ad.36.2025.03.04.23.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 23:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741161061; 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=pEUuRTuxISH7VrsnrtIj3pcFJONapnsboe6eHEzJt+0=; b=LbV0K9ZllB9zVZcl8lXU0sWG2sveOUh72zLnBfx4/2HjYkOpCigXl5ZoioTtJ2Yw0uanEu W+xbdUZnhSfKguXuYLejIAKidYqe1wvYX8X8pMddDFIEP28LNCA0NtRDPpwM/FIhxHhzB9 reJbrus+hliRWOMkns6pcj4pq1THoEU= X-MC-Unique: sCiHA3WTNjCKybDUaNPwtQ-1 X-Mimecast-MFC-AGG-ID: sCiHA3WTNjCKybDUaNPwtQ_1741161050 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741161050; x=1741765850; 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=pEUuRTuxISH7VrsnrtIj3pcFJONapnsboe6eHEzJt+0=; b=rc8aHAnMah6Zw1I13JB1L1ItYj58T8xFOA6YBF5IVnRquTnX0nyevQ+X2vKsdENU2K 3YseA+gJ8Btiy5WKqfUqNik90I9tUt5oqJiY2misp54HO38N8vh1EsE/HA+ihXsTQDB0 66k4znbyV2wKyRPQcD/WyT9bWG3luJgFIWnY30LqqAg3v3QPsrvzoVxXnXiE/6TaJhxt 89WN7mQeEW1p0nSIFzLiFnr7Py1XBory4GDbzsV1DEoQp4MaN6k629eN1vy4KYmXrW3h 0KC4ugsOjNJgFoPDyOz0S/1f1M+5fC4+62wlynBM5tXfTraPwgKFoDlsMMs/CJCKDYJ5 geTQ== X-Forwarded-Encrypted: i=1; AJvYcCUGSuC8welsLQBqnjbkEHkLDqDIhdkt99NBmVX+Wto+JP9keB2urXjzwPw5TariQEJsx9Z99V8Kyykb@nongnu.org X-Gm-Message-State: AOJu0YzqQwmPMAF9fYsDbT1AyEx3WfRqosvNZMJ7CWM0lPWA/djdI2bJ BJ9mWiTlZwtwp7QF0U1ki5h/h2bS+bW5LX9K6XP0CRjcOu3bTBwmZVFE34M4LLTKrNQBIXEqeWj QK7ZJtm4YBzAk5qbkPjfQUABFMmbY9JvXMaOR4RxJD5h1dCYmBJTd X-Gm-Gg: ASbGnctdwnT7P0pldAVoey7QvSCRkcy5XBnONpO3boBoZWJIJHYrAfrZEwSmDgRh+hs 9GXzkLJmwPy23HBJX4NVO4alDiab8YEBbQLF7y3L3xjEeUqgGtW1FSbr3iRFhhsOOGv0xBMINTe zVNs8xx1OMIzD4LLFXTys7kHZuCD8YCylCTDyTS0KDlLYK839NF5rTeZK5vyT+dybDi/iuElzS3 dRws9iyq+Zv1EVB8eDL3L+QmXCkDVgBWSjzAy8VM9lOfv91lixnZUIOOTiY4z36r/iOkliKMeb0 NpBPvrfCKmXrrwveu4HXjeY2cUw= X-Received: by 2002:a17:902:d48a:b0:21d:3bd7:afdd with SMTP id d9443c01a7336-223f1b879e3mr28657315ad.0.1741161050404; Tue, 04 Mar 2025 23:50:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYYrfHLc59oHWRmuqjn/V3FhP6t2iR1fJRGeNyed/dSADkLQpJ4y7/a3d2mRIpIX0/PnqGGA== X-Received: by 2002:a17:902:d48a:b0:21d:3bd7:afdd with SMTP id d9443c01a7336-223f1b879e3mr28656995ad.0.1741161050092; Tue, 04 Mar 2025 23:50:50 -0800 (PST) From: Ani Sinha To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, Ani Sinha Subject: [PULL 2/3] hw/i386/ovmf: check if ovmf is supported before calling ovmf parsing code Date: Wed, 5 Mar 2025 13:20:14 +0530 Message-ID: <20250305075015.26892-3-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250305075015.26892-1-anisinha@redhat.com> References: <20250305075015.26892-1-anisinha@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=anisinha@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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1741161091768019000 Content-Type: text/plain; charset="utf-8" Currently call to x86_firmware_configure() -> pc_system_parse_ovmf_flash() happens only when SEV is enabled. Fortunately, X86_FW_OVMF is turned on automatically when SEV is enabled and therefore, we never end up calling pc_system_parse_ovmf_flash() when X86_FW_OVMF is turned off. In future, it is possible that users call x86_firmware_configure() or x86_firmware_reconfigure() without checking if SEV is enabled. Therefore, x86_firmware_configure() or x86_firmware_reconfigure() need to check if ovmf is supported before calling ovmf parsing code. Hence, this change introduces an api ovmf_supported() that returns true wnen ovmf is enabled and false otherwise. Ovmf parsing code is only called after checking if ovmf is supported. Message-ID: <20250228170434.317306-1-anisinha@redhat.com> Signed-off-by: Ani Sinha Reviewed-by: Gerd Hoffmann --- hw/i386/pc_sysfw.c | 18 +++++++++++------- hw/i386/pc_sysfw_ovmf-stubs.c | 5 +++++ hw/i386/pc_sysfw_ovmf.c | 5 +++++ include/hw/i386/pc.h | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index a9943d95c8..725d142606 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -278,17 +278,21 @@ static void x86_firmware_configure_sev(hwaddr gpa, vo= id *ptr, int size) =20 void x86_firmware_configure(hwaddr gpa, void *ptr, int size) { - /* - * OVMF places a GUIDed structures in the flash, so - * search for them - */ - pc_system_parse_ovmf_flash(ptr, size); + if (ovmf_supported()) { + /* + * OVMF places a GUIDed structures in the flash, so + * search for them + */ + pc_system_parse_ovmf_flash(ptr, size); + } x86_firmware_configure_sev(gpa, ptr, size); } =20 void x86_firmware_reconfigure(hwaddr gpa, void *ptr, int size) { - invalidate_ovmf_parsed_metadata(); - pc_system_parse_ovmf_flash(ptr, size); + if (ovmf_supported()) { + invalidate_ovmf_parsed_metadata(); + pc_system_parse_ovmf_flash(ptr, size); + } x86_firmware_configure_sev(gpa, ptr, size); } diff --git a/hw/i386/pc_sysfw_ovmf-stubs.c b/hw/i386/pc_sysfw_ovmf-stubs.c index edf890a525..08ec18b9b7 100644 --- a/hw/i386/pc_sysfw_ovmf-stubs.c +++ b/hw/i386/pc_sysfw_ovmf-stubs.c @@ -15,6 +15,11 @@ #include "qemu/osdep.h" #include "hw/i386/pc.h" =20 +bool ovmf_supported(void) +{ + return false; +} + bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *dat= a_len) { g_assert_not_reached(); diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c index 3244c17a7d..e6497fd7a7 100644 --- a/hw/i386/pc_sysfw_ovmf.c +++ b/hw/i386/pc_sysfw_ovmf.c @@ -36,6 +36,11 @@ static bool ovmf_flash_parsed; static uint8_t *ovmf_table; static int ovmf_table_len; =20 +bool ovmf_supported(void) +{ + return true; +} + void invalidate_ovmf_parsed_metadata(void) { ovmf_flash_parsed =3D false; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 7b0d0c54f5..2e41ca8b05 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -212,6 +212,7 @@ bool pc_system_ovmf_table_find(const char *entry, uint8= _t **data, int *data_len); void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size); void invalidate_ovmf_parsed_metadata(void); +bool ovmf_supported(void); =20 /* sgx.c */ void pc_machine_init_sgx_epc(PCMachineState *pcms); --=20 2.42.0 From nobody Wed Apr 2 13:15:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1741161106; cv=none; d=zohomail.com; s=zohoarc; b=YCBWLEyDfwmHnHjDNkhXk8xWpnQRhav6JRexC3k8zz0kfYU+iwmshEXZVxMZw4pbaQhkm3MFiRE5bG1OGDmIMm4CHu9csrZKsT4qeG1OfOYMtLGxMJYiHq3BuDnE+9a2D/1jSBDm8UJdsDRJSHFC4/681aMdXHY9UuBFASFm5mc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741161106; 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=uJQO/sqhJmJh/dpa1Nv55qy+Z1WFxKUSDUXkgLMB7RI=; b=hqQgjcGHn7gn/qOsvyIQbf7JK7U/Y+B4jsf8MBUgXIyH3amgUhwGTiUSg+ML02wRij4z1Ti7t25VlSzjvm4D4Fr1lkbYmNOThTTV21T+k8NFFVwdK0mFMi95KHEV5f9x8S5Hhv9PDsiDCG1HRRkAPg30mC1GrHG1B6oRwwqTKCM= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741161106669975.2863969452816; Tue, 4 Mar 2025 23:51:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpjX8-0004Z5-Ci; Wed, 05 Mar 2025 02:51:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjX6-0004Yt-14 for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:51:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpjX4-0007Gc-8g for qemu-devel@nongnu.org; Wed, 05 Mar 2025 02:51:11 -0500 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-1VyNPR4tO1inGaYdVcKBGQ-1; Wed, 05 Mar 2025 02:50:57 -0500 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-223551ee0a3so153331385ad.1 for ; Tue, 04 Mar 2025 23:50:57 -0800 (PST) Received: from localhost.localdomain ([115.96.122.38]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-223501d2778sm107425355ad.36.2025.03.04.23.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 23:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741161069; 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=uJQO/sqhJmJh/dpa1Nv55qy+Z1WFxKUSDUXkgLMB7RI=; b=NT4puPyF9cObA5+xVqTFf1Pw8bl7ZGzaKb988ZazVEtom38ZRCnNTttL9AM+RgSxRT57jC FszjdSMwiG3s6suB0gda85lnpkeqOJDbB0z0dyeLQDx/b1Tapba8wtxTPut9mE7SQOI1c6 /kRtesmNtvTeFefciTYlrFB3ifu1Xeg= X-MC-Unique: 1VyNPR4tO1inGaYdVcKBGQ-1 X-Mimecast-MFC-AGG-ID: 1VyNPR4tO1inGaYdVcKBGQ_1741161056 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741161056; x=1741765856; 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=uJQO/sqhJmJh/dpa1Nv55qy+Z1WFxKUSDUXkgLMB7RI=; b=uCL/6tuMHBNOro1fKIDxPbSY7j1YBa/WM6kYsWQKKd12s/L4LxEewVTHeQMQem6sVw EXKdiSJdbyrNIi8QS8AwSQRhZBVrUlogRZX1B36JvNA1if7Zw5DrkMqh4zFq+uo7X4/E ThVJLNl8jU8hJrxQBlUe/8dIKB5cx/QgJA7F7yDtkikx45Muh4QC4PG3XOuEo8ixbuTO W6iy0WeVu1w2WHHWsnHwlKN3H7OReMAj0gU0iQEv6gsgu2ZbZQvqwAwS2Hh5E9kWVqel 4tYDq36AWkHWhnHWJN+m8/W1tszltdkE7a3h5ajb8wg2KPrj6CP2aZA67OSPxnuyc81z wKqg== X-Forwarded-Encrypted: i=1; AJvYcCXEDkZiJ9lVXxbxGvEzHQLs83xqotu/aJ4H17RuUgyC3f7h5hYrr5eBpvXa1SZKT9GxsxViag1Rb7Um@nongnu.org X-Gm-Message-State: AOJu0YyBpfYkLnMICdmFkb30Li6cMXAT9nPrq8Pbam336PLsykuxrcZZ 9BL6l27Ca9LgFO48y1G4IzwwVuYvQ8Wmd+S/H2d5TvO4aFoa6LGumpxDPoMdyMQ2ltIaAffR05v 1NzjXl14aUe1k6eW6nbIJwQdVs3XEDjCE0ZoYthEb+R+IMWp+7ND/ X-Gm-Gg: ASbGncu1ngAHGoj3NP3nl6k/8J0kJDkzbn2MrgiHToXpLLqAg/8QZvF1MbdBpxgaIX2 s4ibTPnY9E3F6HVgtI1bTwzTsmGal4ir0V6fJpQO8w9Snqiqffev/tG6BD2ptyCvUTeeMH+E55l xsmDi5cKj7MTQveiRjJRODAEN+n3DAMB2VCl3J+4hlEHxFDLwhZR96uLjFeyNs+q01OrSoSQys1 hOqQX5XTSo7D7c7NcoX0h3y0U7HEpEbCxP2I7+85VXR/JkyujHtD17ZWsYxZPgutfhwE8qo+m3X 56aH3dqQ/R1NBlnJbWBnjXB+7dE= X-Received: by 2002:a17:903:8c5:b0:223:f7ec:f834 with SMTP id d9443c01a7336-223f7ecf8a5mr17739665ad.31.1741161055982; Tue, 04 Mar 2025 23:50:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXU1B1JcGQTMlqXXan+JhbuUQpcbKd5VDvptLjdnXzUlMCc+I9+8T5jnWKgnhS6oWObYElUg== X-Received: by 2002:a17:903:8c5:b0:223:f7ec:f834 with SMTP id d9443c01a7336-223f7ecf8a5mr17739325ad.31.1741161055596; Tue, 04 Mar 2025 23:50:55 -0800 (PST) From: Ani Sinha To: Sergio Lopez , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Zhao Liu Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, Ani Sinha , imammedo@redhat.com Subject: [PULL 3/3] microvm: do not use the lastest cpu version Date: Wed, 5 Mar 2025 13:20:15 +0530 Message-ID: <20250305075015.26892-4-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250305075015.26892-1-anisinha@redhat.com> References: <20250305075015.26892-1-anisinha@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=anisinha@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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1741161107613019000 Content-Type: text/plain; charset="utf-8" commit 0788a56bd1ae3 ("i386: Make unversioned CPU models be aliases") introduced 'default_cpu_version' for PCMachineClass. This created three categories of CPU models: - Most unversioned CPU models would use version 1 by default. - For machines 4.0.1 and older that do not support cpu model aliases, a special default_cpu_version value of CPU_VERSION_LEGACY is used. - It was thought that future machines would use the latest value of cpu versions corresponding to default_cpu_version value of CPU_VERSION_LATEST [1]. All pc machines still use the default cpu version of 1 for unversioned cpu models. CPU_VERSION_LATEST is a moving target and changes with time. Therefore, if machines use CPU_VERSION_LATEST, it would mean that over a period of time, for the same versioned machine type, the cpu version would be different depending on what the latest was at that time. This would break guests even when they use a constant specific versioned machine type. Additionally, microvm machines are not versioned anyway and therefore there is no requirement to use the latest cpu model by default. Let microvms use the non-versioned cpu model and remove all references to CPU_VERSION_LATEST as there are no other users (nor we anticipate future consumers of CPU_VERSION_LATEST). Those users who need spefific cpu versions can use explicit version in the QEMU command line to select the specific cpu version desired. CI pipline does not break with this change. 1) See commit dcafd1ef0af227 ("i386: Register versioned CPU models") CC: imammedo@redhat.com CC: zhao1.liu@intel.com Message-ID: <20250220065326.312596-1-anisinha@redhat.com> Reviewed-by: Igor Mammedov Reviewed-by: Sergio Lopez Signed-off-by: Ani Sinha Reviewed-by: Zhao Liu --- hw/i386/microvm.c | 2 +- target/i386/cpu.c | 15 --------------- target/i386/cpu.h | 4 ---- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index d0a236c74f..a340a5fd39 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -491,7 +491,7 @@ static void microvm_machine_state_init(MachineState *ma= chine) =20 microvm_memory_init(mms); =20 - x86_cpus_init(x86ms, CPU_VERSION_LATEST); + x86_cpus_init(x86ms, 1); =20 microvm_devices_init(mms); } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0cd9b70938..2da2cf36fd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5640,18 +5640,6 @@ void x86_cpu_set_default_version(X86CPUVersion versi= on) default_cpu_version =3D version; } =20 -static X86CPUVersion x86_cpu_model_last_version(const X86CPUModel *model) -{ - int v =3D 0; - const X86CPUVersionDefinition *vdef =3D - x86_cpu_def_get_versions(model->cpudef); - while (vdef->version) { - v =3D vdef->version; - vdef++; - } - return v; -} - /* Return the actual version being used for a specific CPU model */ static X86CPUVersion x86_cpu_model_resolve_version(const X86CPUModel *mode= l) { @@ -5659,9 +5647,6 @@ static X86CPUVersion x86_cpu_model_resolve_version(co= nst X86CPUModel *model) if (v =3D=3D CPU_VERSION_AUTO) { v =3D default_cpu_version; } - if (v =3D=3D CPU_VERSION_LATEST) { - return x86_cpu_model_last_version(model); - } return v; } =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 10ce019e3f..113cf10aea 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2740,10 +2740,6 @@ void apic_handle_tpr_access_report(DeviceState *d, t= arget_ulong ip, TPRAccess access); =20 /* Special values for X86CPUVersion: */ - -/* Resolve to latest CPU version */ -#define CPU_VERSION_LATEST -1 - /* * Resolve to version defined by current machine type. * See x86_cpu_set_default_version() --=20 2.42.0