From patchwork Tue Apr 30 15:06:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DglZPmWc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNqB07q0z1ydT for ; Wed, 1 May 2024 01:07:50 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4N-0000yG-0x; Tue, 30 Apr 2024 11:07: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 1s1p4L-0000y5-OJ for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:06:57 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4K-00009L-3L for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:06:57 -0400 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-56e1f3462caso7561387a12.3 for ; Tue, 30 Apr 2024 08:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489613; x=1715094413; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EU56KqxsaM/0HEsRCm8u8nVsVnVRC1FhJWxFNu5K1Wg=; b=DglZPmWc48z3AqwIj9zJbnoFeseEY0DRZ7re1aM8qTrARcrSLVcnp25pBq9EKWb9wH Yr4lpNHlaELhsvhx9vwk1WXMHKOyWcDN1Fnyu/e1AV79Z4VGJ14lAvsrkHGf2+1RAgza vnBkOsI0NcT8TbgkwaWqeW5dkDjog/Prhh9dGgSKZOn6PqypRxqyzMebISlPmiEBUfql riLDcrXNcmg6GGYtKX18Novk7I7AHgjbC33Z4+vSah/TNG2kzoXMuIW+GzFagLFDMKf5 X56qZ4mouapksS2TPwL7GuxRNeb+BaknZdOolA8s6x750f26a6BN8vNIc5/yscrhXkxX FEEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489613; x=1715094413; 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=EU56KqxsaM/0HEsRCm8u8nVsVnVRC1FhJWxFNu5K1Wg=; b=kshS1P9Kc8lfNbfeSGEmFyR6BYUCkI+sgUk6ztk4GlLYXbhUYHgwd6/6x7/ejIraZ2 cioKlo6vKMyBoeWU430cG2iZCYAK77FEWSKmz3CBRaleulV7jiBIppNj25kFbALA0Rf8 xZ2GUmdoYr7Oy6QOKvlHXx/OGrFkefAVsslpkosFyA81XT50qgQmuxUp7is8sKn2Skiv wboS1MxSMVaYQZadgF/DFuY1sLT5nUMDvCzyRZHkEQW+uoSFAsCrBmp8D9Z/B/Ek64e8 abYcZ8u5Sbc1VDVoAYSLARMztwoOO+I/PSihZ8LaB3fcHuKuGwwmqSxljMSWSnae5liz Scqg== X-Gm-Message-State: AOJu0YzCEEJdAzGaHAOZ9KAyQL4xeIcEdkQdRCJbC/nzkTE7KkFXMIr5 W37dX4nq1aWoawWh1vBNncYWrtGn1Jx/tHYlVlo0j5yXj8qrt3u9q+HTpg== X-Google-Smtp-Source: AGHT+IH9Jx1ZX2w4ZL4L6Dhjp9awYt3aDVnZhGdRIh3YwW78Hd5v28/yvpeWztLcaU14HH1msNj8YQ== X-Received: by 2002:a50:ccd4:0:b0:56d:fca5:4245 with SMTP id b20-20020a50ccd4000000b0056dfca54245mr72563edj.10.1714489613191; Tue, 30 Apr 2024 08:06:53 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:52 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 1/6] hw/i386/x86: Eliminate two if statements in x86_bios_rom_init() Date: Tue, 30 Apr 2024 17:06:38 +0200 Message-ID: <20240430150643.111976-2-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=shentey@gmail.com; helo=mail-ed1-x534.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Given that memory_region_set_readonly() is a no-op when the readonlyness is already as requested it is possible to simplify the pattern if (condition) { foo(true); } to foo(condition); which is shorter and allows to see the invariant of the code more easily. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé --- hw/i386/x86.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 3d5b51e92d..2a4f3ee285 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1163,9 +1163,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware, load_image_size(filename, ptr, bios_size); x86_firmware_configure(ptr, bios_size); } else { - if (!isapc_ram_fw) { - memory_region_set_readonly(bios, true); - } + memory_region_set_readonly(bios, !isapc_ram_fw); ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); if (ret != 0) { goto bios_error; @@ -1182,9 +1180,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware, 0x100000 - isa_bios_size, isa_bios, 1); - if (!isapc_ram_fw) { - memory_region_set_readonly(isa_bios, true); - } + memory_region_set_readonly(isa_bios, !isapc_ram_fw); /* map all the bios at the top of memory */ memory_region_add_subregion(rom_memory, From patchwork Tue Apr 30 15:06:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TGUkmu0Y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNrs17vlz1ydT for ; Wed, 1 May 2024 01:09:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4m-00011h-As; Tue, 30 Apr 2024 11:07: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 1s1p4S-0000zc-AP for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:05 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4K-00009U-CU for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:03 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-56e1baf0380so7360293a12.3 for ; Tue, 30 Apr 2024 08:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489614; x=1715094414; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3zb/k7/BA5E8Yw2+b7BDQbjEKFAaUUe7M+nmkaW91ig=; b=TGUkmu0YISsAkI5Z+R24wkDOek71BiY2TFGDT6RyQKoD3+ewgDSnFUFoIKFnsoqfL2 Emf+010+2vCVseST7TWGvah1wZ2R6MaRQmLLsgUMSiIo9CM9Pn+X1T/SYLsrhGM+RuAo K14e5se1mlNJXc75VJkFvL55M9nTOGFpFb244ri56ba7IKlh3HE14cg9yEqj1fSCcatN zN4rrOcjjCP/C2V6T99AkOP5jhmTadui0ZKd7iDRYk33WLbgnx8iwSdlYYYLnEolW7cH d2BjWSeupJe4EsbReZtSN0op2mP88GfEfs5Eiur33lUg+HacUZFJqFC/7tRbe0kuF/ui yhzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489614; x=1715094414; 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=3zb/k7/BA5E8Yw2+b7BDQbjEKFAaUUe7M+nmkaW91ig=; b=KMS7zzjlbG1qYpZDpPSWESZ2uDrlvwh3ZwUmqpc1s3tiNhEbA0pgPoRQdzc6a+uUJl gM1QCr39rDAqGpcQFwLHw9Ipy8LtTMZaGqkNjbY55yf65nadt5Q63BnEJ1AB+gx09Iyi f93Cu5ufMHGVLLhvtEMdJ6Q8Tp6vf9DQMXCTkP8x6ofb/oDJ+KEzmPeFjKSU0S4cTGFv Zr2ujWmo4g2kJlPR47p5ru/ZLlDHw46WkCpKzp1o/65GApLaT+x8yVyCa66AQWFPinDP x/NsXxv+nAbToOggs4YPSXjrjMlXuMhYUN/T49PwLEqPHXJrwg16j9pK8GzDMSj65dwO 0mOw== X-Gm-Message-State: AOJu0YxSg6nr9BNcPoVbcmYyz3UgkolemjkIBf2YVh5GqQ+yOdCP6UvC N7tOMEu6Kg/aI/ntEwIQOFdFfUall9Xl92Tv2dtN8TmAtZbXYZcv8dqA4A== X-Google-Smtp-Source: AGHT+IG1QXIxTgWIcvswDQifdkmYtKPmyb26XR0rv1qNcUjjgCvyPmqxiEotbxXDvbNVu9R66DOpjA== X-Received: by 2002:a50:9f28:0:b0:572:a22b:12db with SMTP id b37-20020a509f28000000b00572a22b12dbmr62406edf.28.1714489613997; Tue, 30 Apr 2024 08:06:53 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:53 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 2/6] hw/i386: Have x86_bios_rom_init() take X86MachineState rather than MachineState Date: Tue, 30 Apr 2024 17:06:39 +0200 Message-ID: <20240430150643.111976-3-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=shentey@gmail.com; helo=mail-ed1-x536.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The function creates and leaks two MemoryRegion objects regarding the BIOS which will be moved into X86MachineState in the next steps to avoid the leakage. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé --- include/hw/i386/x86.h | 2 +- hw/i386/microvm.c | 2 +- hw/i386/pc_sysfw.c | 4 ++-- hw/i386/x86.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 4dc30dcb4d..cb07618d19 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -116,7 +116,7 @@ void x86_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); -void x86_bios_rom_init(MachineState *ms, const char *default_firmware, +void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, MemoryRegion *rom_memory, bool isapc_ram_fw); void x86_load_linux(X86MachineState *x86ms, diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 61a772dfe6..fec63cacfa 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -278,7 +278,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) default_firmware = x86_machine_is_acpi_enabled(x86ms) ? MICROVM_BIOS_FILENAME : MICROVM_QBOOT_FILENAME; - x86_bios_rom_init(MACHINE(mms), default_firmware, get_system_memory(), true); + x86_bios_rom_init(x86ms, default_firmware, get_system_memory(), true); } static void microvm_memory_init(MicrovmMachineState *mms) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 87b5bf59d6..59c7a81692 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -205,7 +205,7 @@ void pc_system_firmware_init(PCMachineState *pcms, BlockBackend *pflash_blk[ARRAY_SIZE(pcms->flash)]; if (!pcmc->pci_enabled) { - x86_bios_rom_init(MACHINE(pcms), "bios.bin", rom_memory, true); + x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, true); return; } @@ -226,7 +226,7 @@ void pc_system_firmware_init(PCMachineState *pcms, if (!pflash_blk[0]) { /* Machine property pflash0 not set, use ROM mode */ - x86_bios_rom_init(MACHINE(pcms), "bios.bin", rom_memory, false); + x86_bios_rom_init(X86_MACHINE(pcms), "bios.bin", rom_memory, false); } else { if (kvm_enabled() && !kvm_readonly_mem_enabled()) { /* diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 2a4f3ee285..6d3c72f124 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1128,7 +1128,7 @@ void x86_load_linux(X86MachineState *x86ms, nb_option_roms++; } -void x86_bios_rom_init(MachineState *ms, const char *default_firmware, +void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, MemoryRegion *rom_memory, bool isapc_ram_fw) { const char *bios_name; @@ -1138,7 +1138,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware, ssize_t ret; /* BIOS load */ - bios_name = ms->firmware ?: default_firmware; + bios_name = MACHINE(x86ms)->firmware ?: default_firmware; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); if (filename) { bios_size = get_image_size(filename); From patchwork Tue Apr 30 15:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=RArW63rN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNqQ4Ws7z1ydT for ; Wed, 1 May 2024 01:08:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4T-0000zb-Dk; Tue, 30 Apr 2024 11:07: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 1s1p4O-0000yk-At for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:00 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4L-00009c-CY for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:00 -0400 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-56e78970853so11277467a12.0 for ; Tue, 30 Apr 2024 08:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489615; x=1715094415; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0i9FUHD/N+BQW7gsC/zN6TOWAHyJbmLzPXaTR2+a3Ic=; b=RArW63rN7rX6pgirg32Ox7lxHnC3itzs3fleV23M+mHpylhXkC7jfbTpYsRy0WCivd SushV+0ZrCW8+U8hnj/YUbOVM7E/ANGaEr0687IEfEHTgWEOhjWJ8NY/KZzXpqbp7rSC SiMk1RP0HfnJxdXprTjpoDOZ9XFpQAIqggQaqzZgfi+cE7qbBuHcn7aFPeCCOcPsggaP CZyMC+7hbwqnVkTg0MqQO9mHxCpTPJV2fRdmdGvG0J8Pmw51Zs/jhIhmFR+YYLgENrP/ 87/X0c45DQvrx8yVeTZF0rAusm5AKOoegliogbd77EdFsm1CVRxeQbFY/f1V2V089Wzc d+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489615; x=1715094415; 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=0i9FUHD/N+BQW7gsC/zN6TOWAHyJbmLzPXaTR2+a3Ic=; b=Hb5C6XBRGBMp1CENHaVU/5xImLcgQauuLQW8vW80LVRy1QyuE7oESSQnzlJXD2SbKn Ps0aZi4OvtwlXHu15l3xhVzTVGYSENQM7j0EZOGKDC1Uxty31HRO/2DW22Q2VUMY1I2O K6FUfnYbO0S97qujD2hSGM/BnlVW8tgg4Mj4WdMFi7bEij15Ueua7x1uET6BAGNVwHJc yWEA1bzUta5hJ+bElAc9vWBIqS/mkUZJwkPB6uFC7ZSiZoAIAe4uo9RdeXsi9RJGYiSw fIf71LL8LL/WR2QKhfKd/BJPf5WfordZcyeaFwzjJZ5qnG+oVNkQ1UUteH3fxcMHlBdv +dTw== X-Gm-Message-State: AOJu0YzMZ1QuXGG1haGx00QjScyjBgkgX5XqZrA2byRGnw/YFKZcUnVf KDvpIsmA73jDe0z2SKUXv5DeNk3z7OKSKMXNK48erXBYXAxdbfNX6BUbLQ== X-Google-Smtp-Source: AGHT+IEl/sT8uXkYHBLS25tg8JhDzAHwSfLnAl/EisDKH33OJ9zw2WR5+tZ5b7qlFYzxfk0oilSVKA== X-Received: by 2002:a50:8750:0:b0:571:da40:22d9 with SMTP id 16-20020a508750000000b00571da4022d9mr2651583edv.10.1714489614789; Tue, 30 Apr 2024 08:06:54 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:54 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 3/6] hw/i386/x86: Don't leak "isa-bios" memory regions Date: Tue, 30 Apr 2024 17:06:40 +0200 Message-ID: <20240430150643.111976-4-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=shentey@gmail.com; helo=mail-ed1-x534.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Fix the leaking in x86_bios_rom_init() and pc_isa_bios_init() by adding an "isa_bios" attribute to X86MachineState. Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé --- include/hw/i386/x86.h | 2 ++ hw/i386/pc_sysfw.c | 7 +++---- hw/i386/x86.c | 9 ++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index cb07618d19..271ad50470 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -18,6 +18,7 @@ #define HW_I386_X86_H #include "exec/hwaddr.h" +#include "exec/memory.h" #include "hw/boards.h" #include "hw/intc/ioapic.h" @@ -51,6 +52,7 @@ struct X86MachineState { DeviceState *ioapic2; GMappedFile *initrd_mapped_file; HotplugHandler *acpi_dev; + MemoryRegion isa_bios; /* RAM information (sizes, addresses, configuration): */ ram_addr_t below_4g_mem_size, above_4g_mem_size; diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 59c7a81692..82d37cb376 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -40,11 +40,10 @@ #define FLASH_SECTOR_SIZE 4096 -static void pc_isa_bios_init(MemoryRegion *rom_memory, +static void pc_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *rom_memory, MemoryRegion *flash_mem) { int isa_bios_size; - MemoryRegion *isa_bios; uint64_t flash_size; void *flash_ptr, *isa_bios_ptr; @@ -52,7 +51,6 @@ static void pc_isa_bios_init(MemoryRegion *rom_memory, /* map the last 128KB of the BIOS in ISA space */ isa_bios_size = MIN(flash_size, 128 * KiB); - isa_bios = g_malloc(sizeof(*isa_bios)); memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size, &error_fatal); memory_region_add_subregion_overlap(rom_memory, @@ -136,6 +134,7 @@ void pc_system_flash_cleanup_unused(PCMachineState *pcms) static void pc_system_flash_map(PCMachineState *pcms, MemoryRegion *rom_memory) { + X86MachineState *x86ms = X86_MACHINE(pcms); hwaddr total_size = 0; int i; BlockBackend *blk; @@ -185,7 +184,7 @@ static void pc_system_flash_map(PCMachineState *pcms, if (i == 0) { flash_mem = pflash_cfi01_get_memory(system_flash); - pc_isa_bios_init(rom_memory, flash_mem); + pc_isa_bios_init(&x86ms->isa_bios, rom_memory, flash_mem); /* Encrypt the pflash boot ROM */ if (sev_enabled()) { diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 6d3c72f124..457e8a34a5 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1133,7 +1133,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, { const char *bios_name; char *filename; - MemoryRegion *bios, *isa_bios; + MemoryRegion *bios; int bios_size, isa_bios_size; ssize_t ret; @@ -1173,14 +1173,13 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, /* map the last 128KB of the BIOS in ISA space */ isa_bios_size = MIN(bios_size, 128 * KiB); - isa_bios = g_malloc(sizeof(*isa_bios)); - memory_region_init_alias(isa_bios, NULL, "isa-bios", bios, + memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", bios, bios_size - isa_bios_size, isa_bios_size); memory_region_add_subregion_overlap(rom_memory, 0x100000 - isa_bios_size, - isa_bios, + &x86ms->isa_bios, 1); - memory_region_set_readonly(isa_bios, !isapc_ram_fw); + memory_region_set_readonly(&x86ms->isa_bios, !isapc_ram_fw); /* map all the bios at the top of memory */ memory_region_add_subregion(rom_memory, From patchwork Tue Apr 30 15:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N5h5QNbO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNqw6cy1z1ydT for ; Wed, 1 May 2024 01:08:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4q-00018l-9B; Tue, 30 Apr 2024 11:07:28 -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 1s1p4R-0000zI-5h for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:03 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4M-00009q-9T for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:02 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-572669fd9f9so5013193a12.0 for ; Tue, 30 Apr 2024 08:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489616; x=1715094416; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BnnlXuw4VnJp8XUprbE2Rl/GS20bsAEHdcUkL5+ANKg=; b=N5h5QNbOaM+oFrQOTnt0ODiygJc9UfvVeqexuFWuhHiPa9V+y6SAf8wqSl8Oj0/7wF sF0/BMtFWWbrEWjtQsrjWYWb2ECqrUhrgmLLDPb8hfgnZ/W/t2wKYItnnPeYiftLv1Wx 5TZxIZLA3jGTtfB4wDOgQwuBJPur55oyxToMXXMtwm25N4rlom5Lnhm6jyBBaX+M3kQc g7ytKXtEnDyO2qIzaweQY66f6LWEb+/qjp3m8ybw1ZFEx48o2pVTc11KL4hrmUZqep21 KRsSceXDXBFmQn3SGYxygrADfdOK5kL/ENkJIXswd8CiT19jBT0qEaKyHlfwwLkZvXhB Oj5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489616; x=1715094416; 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=BnnlXuw4VnJp8XUprbE2Rl/GS20bsAEHdcUkL5+ANKg=; b=rM4tsN17+LUQGS8ZzuTnkHS+pWx6e/b8O1V/AVrdfT6fuaZcZJ0WYSbjv3v1tVyfBd vYYlP3OL0JHFqHmFvdkblDanKWgsZsywDKCnrhSzvVAC0Du6YeE1r68nK+ad1veyMNd6 j9/pVyzK+CaSEUjZnqx52MN7+fyDGDLyg1nXRjpG2GuloE1OeSXhVY1rH3eRrzvVlTPu LsUDZurojxpaj+6Psw9gXlmZ90RlybH3oI6zC1LqKiqFgQPYTpFemTFDND+bwpMZW1Ic I/zSDoR6xVaIL0n4CU47GCIQLYqvZPmTitt4ooaE1lO/5aDyVBfZis1vB7sp7vzEt7Xw VLUg== X-Gm-Message-State: AOJu0YzIiRz+4Od/nlzMfL6ZaAcFiPYTenkNeiYN4+ki4cLq3aXz5dcf X2FHomqr3TlxpFt/23dg4Qx+KtE9VWn2celIjhNznEYAr9Lz6snwEkLRXw== X-Google-Smtp-Source: AGHT+IFwKy/oiOn/Be23vNB88dTvABXg+7CTYMa2IEAKdlBCRk5mXYP9KE3Icrx9+U8trAPn+Hz6+g== X-Received: by 2002:a50:d4d6:0:b0:572:6698:7d25 with SMTP id e22-20020a50d4d6000000b0057266987d25mr42672edj.26.1714489616219; Tue, 30 Apr 2024 08:06:56 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:55 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 4/6] hw/i386/x86: Don't leak "pc.bios" memory region Date: Tue, 30 Apr 2024 17:06:41 +0200 Message-ID: <20240430150643.111976-5-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=shentey@gmail.com; helo=mail-ed1-x533.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Fix the leaking in x86_bios_rom_init() by adding a "bios" attribute to X86MachineState. Note that it is only used in the -bios case. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé --- include/hw/i386/x86.h | 1 + hw/i386/x86.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 271ad50470..fb41263b9d 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -52,6 +52,7 @@ struct X86MachineState { DeviceState *ioapic2; GMappedFile *initrd_mapped_file; HotplugHandler *acpi_dev; + MemoryRegion bios; MemoryRegion isa_bios; /* RAM information (sizes, addresses, configuration): */ diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 457e8a34a5..29167de97d 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1133,7 +1133,6 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, { const char *bios_name; char *filename; - MemoryRegion *bios; int bios_size, isa_bios_size; ssize_t ret; @@ -1149,8 +1148,8 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, (bios_size % 65536) != 0) { goto bios_error; } - bios = g_malloc(sizeof(*bios)); - memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal); + memory_region_init_ram(&x86ms->bios, NULL, "pc.bios", bios_size, + &error_fatal); if (sev_enabled()) { /* * The concept of a "reset" simply doesn't exist for @@ -1159,11 +1158,11 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, * the firmware as rom to properly re-initialize on reset. * Just go for a straight file load instead. */ - void *ptr = memory_region_get_ram_ptr(bios); + void *ptr = memory_region_get_ram_ptr(&x86ms->bios); load_image_size(filename, ptr, bios_size); x86_firmware_configure(ptr, bios_size); } else { - memory_region_set_readonly(bios, !isapc_ram_fw); + memory_region_set_readonly(&x86ms->bios, !isapc_ram_fw); ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); if (ret != 0) { goto bios_error; @@ -1173,7 +1172,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, /* map the last 128KB of the BIOS in ISA space */ isa_bios_size = MIN(bios_size, 128 * KiB); - memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", bios, + memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", &x86ms->bios, bios_size - isa_bios_size, isa_bios_size); memory_region_add_subregion_overlap(rom_memory, 0x100000 - isa_bios_size, @@ -1184,7 +1183,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, /* map all the bios at the top of memory */ memory_region_add_subregion(rom_memory, (uint32_t)(-bios_size), - bios); + &x86ms->bios); return; bios_error: From patchwork Tue Apr 30 15:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LCuBY0yN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNqr5LRGz1ydT for ; Wed, 1 May 2024 01:08:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4w-0001BW-HA; Tue, 30 Apr 2024 11:07:34 -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 1s1p4Q-0000zD-Bl for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:02 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4O-0000A9-Bv for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:02 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so6131479a12.3 for ; Tue, 30 Apr 2024 08:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489617; x=1715094417; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rRgm75PlnTxOQz8vg7A+phJJKx6kz6lMxdJhZ2IMl6o=; b=LCuBY0yNgpQj7XtGng/pn/bb1UyyebwX89TaLlI4onMgRhYAUECMtlxPo/HUnQZ+k+ 66r6e6D5j0CSZ6zNKNjspvSdsLxrw/4nCe31r+F+powR0njOvswBtKjeMqa9jCSdQfRx c0jOyNQPRqMfkBExD3Dfx6UTGOBEXWCGZL/0yfwAJk02dF7IDG+i/tJ/ggYBgoJxMxjE R6Pr7jcGRPqksnRY7HViiwGqhZZru1glO3G64BcpIFDl/6uYcztmftUDG0bRodp7GQQo Vd4CFgmyh8UpHApqrqp7cPoYo0Bz+PMt2fJKQesX8BNA+GNGrqt1oOFDmTPBajgRbYgR f5yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489617; x=1715094417; 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=rRgm75PlnTxOQz8vg7A+phJJKx6kz6lMxdJhZ2IMl6o=; b=nMolnr0STNGG8mq5ThkQgBtmOfvAWD/TsT6lJdYfTaWqtIXYDekcdJUcUOKUdUHrgp 5L6Gwk4m4tN+SVSe2b7boe2UNjhr28H3kq68JCpCx3yF0xjI7CA5pvXkK5Akkm4OkOkP 2S8OiCAjwb9kWL1LRyIoXzgHPg8Y8NahXBVPgInLLr5JXS7moSKujQp0GLquZ5KBx3gT NKRVpbvRyAqz2hyR+eA78/bhvtIWRvYUv05fmEcvgC0GXufbnPcW/ENl5e4CyJ+UQbSA Pr7T0BDaW1znwUpf2L0HFW3wgdJuXYwYemkprQvustv7V3kZXHZBeMVm6qziYnn61j1B 1xwg== X-Gm-Message-State: AOJu0YySFRRshVT6k8LDDq37FShfUlQxO7/wjtdiGd0t1mvMfLQRQW4t cc91YYTwuv3EKwwhd6leXDrUSjwrCZTW52M0+K5tSS4B7xUNVs7BocT9VA== X-Google-Smtp-Source: AGHT+IEQIhNkOpKrzXM4VqkWubKD2NvCz6qoRTpbCaUl5t1e4lfMTekm9P7cLlqfvIMvdtz66+B4wQ== X-Received: by 2002:a50:9556:0:b0:56e:2d93:3f84 with SMTP id v22-20020a509556000000b0056e2d933f84mr54530eda.4.1714489617346; Tue, 30 Apr 2024 08:06:57 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:56 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 5/6] hw/i386/x86: Extract x86_isa_bios_init() from x86_bios_rom_init() Date: Tue, 30 Apr 2024 17:06:42 +0200 Message-ID: <20240430150643.111976-6-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=shentey@gmail.com; helo=mail-ed1-x52b.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The function is inspired by pc_isa_bios_init() and should eventually replace it. Using x86_isa_bios_init() rather than pc_isa_bios_init() fixes pflash commands to work in the isa-bios region. While at it convert the magic number 0x100000 (== 1MiB) to increase readability. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé --- include/hw/i386/x86.h | 2 ++ hw/i386/x86.c | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index fb41263b9d..e92a226d13 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -119,6 +119,8 @@ void x86_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory, + MemoryRegion *bios, bool read_only); void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, MemoryRegion *rom_memory, bool isapc_ram_fw); diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 29167de97d..c61f4ebfa6 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1128,12 +1128,25 @@ void x86_load_linux(X86MachineState *x86ms, nb_option_roms++; } +void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory, + MemoryRegion *bios, bool read_only) +{ + uint64_t bios_size = memory_region_size(bios); + uint64_t isa_bios_size = MIN(bios_size, 128 * KiB); + + memory_region_init_alias(isa_bios, NULL, "isa-bios", bios, + bios_size - isa_bios_size, isa_bios_size); + memory_region_add_subregion_overlap(isa_memory, 1 * MiB - isa_bios_size, + isa_bios, 1); + memory_region_set_readonly(isa_bios, read_only); +} + void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, MemoryRegion *rom_memory, bool isapc_ram_fw) { const char *bios_name; char *filename; - int bios_size, isa_bios_size; + int bios_size; ssize_t ret; /* BIOS load */ @@ -1171,14 +1184,8 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, g_free(filename); /* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = MIN(bios_size, 128 * KiB); - memory_region_init_alias(&x86ms->isa_bios, NULL, "isa-bios", &x86ms->bios, - bios_size - isa_bios_size, isa_bios_size); - memory_region_add_subregion_overlap(rom_memory, - 0x100000 - isa_bios_size, - &x86ms->isa_bios, - 1); - memory_region_set_readonly(&x86ms->isa_bios, !isapc_ram_fw); + x86_isa_bios_init(&x86ms->isa_bios, rom_memory, &x86ms->bios, + !isapc_ram_fw); /* map all the bios at the top of memory */ memory_region_add_subregion(rom_memory, From patchwork Tue Apr 30 15:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 1929660 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Ebnu/dBh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNrq220mz1ydT for ; Wed, 1 May 2024 01:09:15 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1p4m-000125-CC; Tue, 30 Apr 2024 11:07: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 1s1p4S-0000ze-DF for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:05 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1p4Q-0000AY-81 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 11:07:04 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5196fe87775so6471185e87.3 for ; Tue, 30 Apr 2024 08:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714489618; x=1715094418; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DGNe/5kNutRKm5uz4mTsWbXpNf42QSU6anrwo6QJebg=; b=Ebnu/dBhF2myrVXslHwCl9Vr1YR7HZcIjtkR0Ds3vAzX3jV0+DEzpc6su66qkv2Nkx G97BYDYudfsSq5hzHnIsaW5+C/iAiZD4IwvC3WC93AQ7VrSII1gas+iYHpyPE8nMIzJ8 3VTRAMKo1R8OiNhrqxygz6VRIqKRkFOsXzFz6dB6/8DOH6eoWSIB47cLsKj0EDEKPH6L 4448wBDcvj799ysMgeBrFDoLP92a6tbZF/Ji3O7WKzJoCEGrg+h6Szz8U7GdIiYMxf/P DHyaG45QqaPLUYWHk5+6LJbILtbwN3GHQqw/mcs9bSCE5vOIb37QBIq3hOcL3E4nM6Lp jDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714489618; x=1715094418; 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=DGNe/5kNutRKm5uz4mTsWbXpNf42QSU6anrwo6QJebg=; b=kTo0aDmXEdpmVmy3m+2LmaBfVCChfNyk3KXioi3HUi6k7JlN4PqoqhjVfOGF2xF438 QjWR6uJulpK0a2Cuwo03DaRaANS9LDxkfYaySVam78Iiatdz2X2t3Fh1Y+7hTOQdsYEf aTKXsHB2V/AfFk31itH/aKLLC4NdO6hV/ux9jvfIJ1xzrZ11yy0JQU7HSXL3C9RPdFKr 0WCd0L9rVCp3LY7F07t5bOAqQ9ro94Vk37Rciu3ppg3Xb5KQJ2Uv8TjifgTKcYKkhh40 IXqMNZ8McFeOF9oTNHK4sMLqZ/JHyAeY8ECcdyx+HEH7qlypQZ7CAhd31EriYvx8Ymd9 cV2g== X-Gm-Message-State: AOJu0YzU8fWuvtZqwEd6J8MFTIgImajJ1N6OAwq3Twc2yqgVpORFc+sK A7gBTwH3MfSiBoTEPVs1S23LPAg1O9DN9rhzy5HhQl95zByxzJl2k/7DTg== X-Google-Smtp-Source: AGHT+IGh1IMzyKILTn1jOKJNN/J1d60hIQ8cDdnoAbW4m5fexs4SvWWZDrg1cPKiaiv7StLNdWrpFg== X-Received: by 2002:a19:5f19:0:b0:51b:e0f0:e4f8 with SMTP id t25-20020a195f19000000b0051be0f0e4f8mr7009382lfb.31.1714489618436; Tue, 30 Apr 2024 08:06:58 -0700 (PDT) Received: from archlinux.. (pd9ed788d.dip0.t-ipconnect.de. [217.237.120.141]) by smtp.gmail.com with ESMTPSA id 11-20020a0564021f4b00b005727e826977sm2345741edz.19.2024.04.30.08.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:06:57 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Eduardo Habkost , Sergio Lopez , Marcel Apfelbaum , Michael Roth , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 6/6] hw/i386/pc_sysfw: Alias rather than copy isa-bios region Date: Tue, 30 Apr 2024 17:06:43 +0200 Message-ID: <20240430150643.111976-7-shentey@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240430150643.111976-1-shentey@gmail.com> References: <20240430150643.111976-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=shentey@gmail.com; helo=mail-lf1-x129.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In the -bios case the "isa-bios" memory region is an alias to the BIOS mapped to the top of the 4G memory boundary. Do the same in the -pflash case, but only for new machine versions for migration compatibility. This establishes common behavior and makes pflash commands work in the "isa-bios" region which some real-world legacy bioses rely on. Note that in the sev_enabled() case, the "isa-bios" memory region in the -pflash case will now also point to encrypted memory, just like it already does in the -bios case. Signed-off-by: Bernhard Beschow --- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 3 +++ hw/i386/pc_q35.c | 2 ++ hw/i386/pc_sysfw.c | 8 +++++++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index e52290916c..ad9c3d9ba8 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -119,6 +119,7 @@ struct PCMachineClass { bool enforce_aligned_dimm; bool broken_reserved_end; bool enforce_amd_1tb_hole; + bool isa_bios_alias; /* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 08c7de416f..ce61bb7fc1 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1811,6 +1811,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) pcmc->has_reserved_memory = true; pcmc->enforce_aligned_dimm = true; pcmc->enforce_amd_1tb_hole = true; + pcmc->isa_bios_alias = true; /* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size = 0x20000 + 0x8000; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 8850c49c66..d4e9deb509 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -525,12 +525,15 @@ DEFINE_I440FX_MACHINE(v9_1, "pc-i440fx-9.1", NULL, static void pc_i440fx_9_0_machine_options(MachineClass *m) { + PCMachineClass *pcmc = PC_MACHINE_CLASS(m); + pc_i440fx_9_1_machine_options(m); m->alias = NULL; m->is_default = false; compat_props_add(m->compat_props, hw_compat_9_0, hw_compat_9_0_len); compat_props_add(m->compat_props, pc_compat_9_0, pc_compat_9_0_len); + pcmc->isa_bios_alias = false; } DEFINE_I440FX_MACHINE(v9_0, "pc-i440fx-9.0", NULL, diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index bb53a51ac1..bd7db4abac 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -378,10 +378,12 @@ DEFINE_Q35_MACHINE(v9_1, "pc-q35-9.1", NULL, static void pc_q35_9_0_machine_options(MachineClass *m) { + PCMachineClass *pcmc = PC_MACHINE_CLASS(m); pc_q35_9_1_machine_options(m); m->alias = NULL; compat_props_add(m->compat_props, hw_compat_9_0, hw_compat_9_0_len); compat_props_add(m->compat_props, pc_compat_9_0, pc_compat_9_0_len); + pcmc->isa_bios_alias = false; } DEFINE_Q35_MACHINE(v9_0, "pc-q35-9.0", NULL, diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 82d37cb376..ac88ad4eb9 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -135,6 +135,7 @@ static void pc_system_flash_map(PCMachineState *pcms, MemoryRegion *rom_memory) { X86MachineState *x86ms = X86_MACHINE(pcms); + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); hwaddr total_size = 0; int i; BlockBackend *blk; @@ -184,7 +185,12 @@ static void pc_system_flash_map(PCMachineState *pcms, if (i == 0) { flash_mem = pflash_cfi01_get_memory(system_flash); - pc_isa_bios_init(&x86ms->isa_bios, rom_memory, flash_mem); + if (pcmc->isa_bios_alias) { + x86_isa_bios_init(&x86ms->isa_bios, rom_memory, flash_mem, + true); + } else { + pc_isa_bios_init(&x86ms->isa_bios, rom_memory, flash_mem); + } /* Encrypt the pflash boot ROM */ if (sev_enabled()) {