From nobody Mon May 20 14:56:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614615375; cv=none; d=zohomail.com; s=zohoarc; b=hTZQHAphBG5+za+YJL58Cd2jPqRopGRqdxwZi+niAAEQCt6SyKZ9WBupDw9bXHHBGF/olbN3D8wW3y19noQU9nUOUS7ii0y5UftvlKFhYI39bGBIfPThZ25b/XS3/G4IiFbEkTub34b7+r52HaCuuUe2mSsh8+KbmUoa0EPl71Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614615375; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lCMJCAAvFCHtyAGeQeoNWmtcrKXM3POMlMJ7sF7LukU=; b=CMSOKxtKbXTLymC1lbAgI9o2kFruVOk3Kmbt/XYwgL0LfWDUd0pdVndsIEyvaMb30f79NniMNsQSBVxXLrue7FnFXc/vdDiBr/wgIVtWO5OmQTvY39ZgamJFSOe3j1kpZYS2lDKw/CajR3ou0atRAImzShBrkiDvncDhwNAi6k8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614615375158631.2212077450797; Mon, 1 Mar 2021 08:16:15 -0800 (PST) Received: from localhost ([::1]:48800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGlDR-0005cw-Sm for importer@patchew.org; Mon, 01 Mar 2021 11:16:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGl9z-0001pw-PG for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52347) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGl9y-0003Qm-6D for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-3s4z8zQmPIm7drW354rspA-1; Mon, 01 Mar 2021 11:12:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55DA4100A8C4; Mon, 1 Mar 2021 16:12:32 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD65219C45; Mon, 1 Mar 2021 16:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614615157; 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=lCMJCAAvFCHtyAGeQeoNWmtcrKXM3POMlMJ7sF7LukU=; b=bg/AppeMhsEBONgkLGhbzvvhft1cp1FwKGeswDkamqq4qsnlRU32A6ywCZffebBjMReeiO 4K/wqM5CnJ0xHvkiuNHk7NDyvpsdt/4aIAt1Xh37Iec7qKu/9cz3zOKNUoDkFR3zqVT/Rw C5nH7igTNykkrchngxaWSIOGv6wfxRI= X-MC-Unique: 3s4z8zQmPIm7drW354rspA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] tpm: mark correct memory region range dirty when clearing RAM Date: Mon, 1 Mar 2021 17:11:33 +0100 Message-Id: <20210301161137.78941-2-david@redhat.com> In-Reply-To: <20210301161137.78941-1-david@redhat.com> References: <20210301161137.78941-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Stefan Berger , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Claudio Fontana , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We might not start at the beginning of the memory region. We could also calculate via the difference in the host address; however, memory_region_set_dirty() also relies on memory_region_get_ram_addr() internally, so let's just use that. Acked-by: Stefan Berger Fixes: ffab1be70692 ("tpm: clear RAM when "memory overwrite" requested") Cc: Marc-Andr=C3=A9 Lureau Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Claudio Fontana Cc: Thomas Huth Cc: "Alex Benn=C3=A9e" Cc: Peter Xu Cc: Laurent Vivier Cc: Stefan Berger Signed-off-by: David Hildenbrand --- hw/tpm/tpm_ppi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c index 72d7a3d926..e0e2d2c8e1 100644 --- a/hw/tpm/tpm_ppi.c +++ b/hw/tpm/tpm_ppi.c @@ -30,11 +30,13 @@ void tpm_ppi_reset(TPMPPI *tpmppi) guest_phys_blocks_init(&guest_phys_blocks); guest_phys_blocks_append(&guest_phys_blocks); QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + ram_addr_t mr_start =3D memory_region_get_ram_addr(block->mr); + trace_tpm_ppi_memset(block->host_addr, block->target_end - block->target_start); memset(block->host_addr, 0, block->target_end - block->target_start); - memory_region_set_dirty(block->mr, 0, + memory_region_set_dirty(block->mr, block->target_start - mr_st= art, block->target_end - block->target_star= t); } guest_phys_blocks_free(&guest_phys_blocks); --=20 2.29.2 From nobody Mon May 20 14:56:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614615386; cv=none; d=zohomail.com; s=zohoarc; b=ZtVv7espIGijy9InMhV7CfqmP3sb3Ep//Xq0tKZWGiNC/MC8MU7MD9AoPbclXE7gYjKMwILQ1+Y6RlqGYm0IkNlEJZTiKro4yclP1gGcw7038+kAKkx6rtzoO6r20QWJ2ZTPrJ1awEAD3sTA2FyqIuaVVewLdp/x+VE45BHo0Yo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614615386; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Yaj5yeMk9DUiBWPINsWa4sjjZPOAp0urKXtZHgqVf9E=; b=SMvG8gcp73Plr9RhkEXesqmb+hLcJcOKDs6dV4ljW+soVBVlrtsKZnEXzmhJ1RLUXEtHcNWSCWMlxSTWLuXHjGOAdh274pb+f8wooHACscubVzmhktojMfpMZjmrYoBcHEcQnehOOslzZ8IUVhxcKR9uJLuUw9lCRJp2BkqIl1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614615386368522.1719206773861; Mon, 1 Mar 2021 08:16:26 -0800 (PST) Received: from localhost ([::1]:49934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGlDd-00067v-BT for importer@patchew.org; Mon, 01 Mar 2021 11:16:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGlA1-0001s9-2l for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45001) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGl9z-0003RQ-CF for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-ZIj5ay8-OdyfeWuhsuR0pg-1; Mon, 01 Mar 2021 11:12:36 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92EBE1876693; Mon, 1 Mar 2021 16:12:35 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id A717019712; Mon, 1 Mar 2021 16:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614615158; 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=Yaj5yeMk9DUiBWPINsWa4sjjZPOAp0urKXtZHgqVf9E=; b=cqfX3aUGnB3ilwVRJzEJPDiH+yzGt6bGZdDTkCF6xf1KBJbK1Ts5f76EgUR4KJ3WUAml/8 MmANg8m2SfY+vJuqE5DAoY4B2eeioi/Bl9u98R6/MUKvNyLCo320QkJkMkqKfQEsCH/KSa /AtgzZ/AFP8Wyj8AI+VYFK7OE2W00XM= X-MC-Unique: ZIj5ay8-OdyfeWuhsuR0pg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 2/5] softmmu/memory_mapping: reuse qemu_get_guest_simple_memory_mapping() Date: Mon, 1 Mar 2021 17:11:34 +0100 Message-Id: <20210301161137.78941-3-david@redhat.com> In-Reply-To: <20210301161137.78941-1-david@redhat.com> References: <20210301161137.78941-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Claudio Fontana , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's reuse qemu_get_guest_simple_memory_mapping(), which does exactly what we want. Cc: Marc-Andr=C3=A9 Lureau Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Claudio Fontana Cc: Thomas Huth Cc: "Alex Benn=C3=A9e" Cc: Peter Xu Cc: Laurent Vivier Cc: Stefan Berger Signed-off-by: David Hildenbrand --- softmmu/memory_mapping.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index 18d0b8067c..2677392de7 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -289,8 +289,6 @@ void qemu_get_guest_memory_mapping(MemoryMappingList *l= ist, Error **errp) { CPUState *cpu, *first_paging_enabled_cpu; - GuestPhysBlock *block; - ram_addr_t offset, length; =20 first_paging_enabled_cpu =3D find_paging_enabled_cpu(first_cpu); if (first_paging_enabled_cpu) { @@ -310,11 +308,7 @@ void qemu_get_guest_memory_mapping(MemoryMappingList *= list, * If the guest doesn't use paging, the virtual address is equal to ph= ysical * address. */ - QTAILQ_FOREACH(block, &guest_phys_blocks->head, next) { - offset =3D block->target_start; - length =3D block->target_end - block->target_start; - create_new_memory_mapping(list, offset, offset, length); - } + qemu_get_guest_simple_memory_mapping(list, guest_phys_blocks); } =20 void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, --=20 2.29.2 From nobody Mon May 20 14:56:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614615292; cv=none; d=zohomail.com; s=zohoarc; b=N11R6m5zTquIBZKKT2nikgyfkTJm7un+XA5Ne7BEnYQS1iFZ0Va6oeNJQQWqfSy5OKKcM0dqG7hUjx8YRXqOAhKaT46+pQcdPVw5g9w5QtlHEW9ha5osJ9+itBAGcfm15TGybXqUjJ1impTCFKaOaTJPigkDEVS1hqLWx4LpSCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614615292; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AXkXjQN2e2WYpxOfLMPaLhVjFPHFr/BaZrL4f97eIjA=; b=NaY5ezH3Pl6qstoasnP94E+D0XIl9fO4EBHDq8tk1MOkD04t4w2PoKctrx8o3AG9enLDGYp5zFFCWXl8LxurqzdwuGE2uA6mWiIol9ieMTYpnhA05le2GAObwVaKGvglDyNf7L1FZmVJD70WEYZdv1Njwn117vZbrvpJq+pEwXw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614615292358493.1587084804587; Mon, 1 Mar 2021 08:14:52 -0800 (PST) Received: from localhost ([::1]:45124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGlC7-0003vb-9O for importer@patchew.org; Mon, 01 Mar 2021 11:14:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGlA8-00025k-Mg for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGlA7-0003T0-5P for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-JdwGevtgPzKxkfF82lnTIQ-1; Mon, 01 Mar 2021 11:12:42 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5133100CCC9; Mon, 1 Mar 2021 16:12:38 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id E196019C45; Mon, 1 Mar 2021 16:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614615166; 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=AXkXjQN2e2WYpxOfLMPaLhVjFPHFr/BaZrL4f97eIjA=; b=C+E6GGWU7Vux3jLye6zsUt94djMWGWXHFmyQdDLjyra5kGZPaFt02ONxUD7Ob25uedV1Ug mrxOeYloOR3fhxtCn6qS3KoEnDtvJPISJ15JGDejLjK2F7ICKn6jHABAnuhNhDFSzXFTTM QLOISw1oR7lw8653dNM3CDqrkLKilfg= X-MC-Unique: JdwGevtgPzKxkfF82lnTIQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] softmmu/memory_mapping: never merge ranges accross memory regions Date: Mon, 1 Mar 2021 17:11:35 +0100 Message-Id: <20210301161137.78941-4-david@redhat.com> In-Reply-To: <20210301161137.78941-1-david@redhat.com> References: <20210301161137.78941-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Claudio Fontana , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's make sure to not merge when different memory regions are involved. Unlikely, but theoretically possible. Cc: Marc-Andr=C3=A9 Lureau Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Claudio Fontana Cc: Thomas Huth Cc: "Alex Benn=C3=A9e" Cc: Peter Xu Cc: Laurent Vivier Cc: Stefan Berger Signed-off-by: David Hildenbrand --- softmmu/memory_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index 2677392de7..ad4911427a 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -230,7 +230,8 @@ static void guest_phys_blocks_region_add(MemoryListener= *listener, =20 /* we want continuity in both guest-physical and host-virtual memo= ry */ if (predecessor->target_end < target_start || - predecessor->host_addr + predecessor_size !=3D host_addr) { + predecessor->host_addr + predecessor_size !=3D host_addr || + predecessor->mr !=3D section->mr) { predecessor =3D NULL; } } --=20 2.29.2 From nobody Mon May 20 14:56:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614615500; cv=none; d=zohomail.com; s=zohoarc; b=CVSgnp3ZKjbcKHdlmyYOr62NYSbZEgwnIlwk40u2xXk61F23oaMW+gQ2/HTE1zZgdwooQXi76WO9MOxU6Brvfyv/d6mvO2Piz6cwpUD7gRi3zN0ju3GYAir4i9e0UK93IMnRYWXypWnM9XX45tqLKwwngLfz3ecK8WihMQ7nizQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614615500; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AwM9dCtxEJ8ovZ3yeuLOxVCS1flJUKr+ck4QWIQO++Q=; b=J5agsn4CpCbOfq7cfmrVR4kp091fPo8GoRYwcTGQdrbHl3dnaE3DdN/83Eq21BIH0VO59LfYRmvlDnPh3k5ffTl+gcsbv3O6hzctU43hSsMg+JXAFJp+XcciK2tQAHHTPvEFJI05vqQXfIt66P1GVybF8WAYEB383H5nCP2TnlI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614615500801498.1336049903342; Mon, 1 Mar 2021 08:18:20 -0800 (PST) Received: from localhost ([::1]:57218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGlFT-0000mu-OZ for importer@patchew.org; Mon, 01 Mar 2021 11:18:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGlAD-0002FK-TM for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGlAC-0003V9-53 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-_FUtidViNU64gq9PTOW9YA-1; Mon, 01 Mar 2021 11:12:47 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2D8E107ACF9; Mon, 1 Mar 2021 16:12:41 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1266919C45; Mon, 1 Mar 2021 16:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614615171; 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=AwM9dCtxEJ8ovZ3yeuLOxVCS1flJUKr+ck4QWIQO++Q=; b=elPYSE4DZjLapJlc0M9PVZS0pwViwGTG9nGB7mdhr2/E+RwLvbJAy8qnXWvajSRvjAwWoU eSpfmXohhB3vgXp36y9aPGj2a4KLne7/IM8h84YukJ1CplD/PY2cWVOTfVJWKWVTKvbf5Q Ow544kwZAhCWddYe29VioWuPLpkRHKU= X-MC-Unique: _FUtidViNU64gq9PTOW9YA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 4/5] softmmu/memory_mapping: factor out adding physical memory ranges Date: Mon, 1 Mar 2021 17:11:36 +0100 Message-Id: <20210301161137.78941-5-david@redhat.com> In-Reply-To: <20210301161137.78941-1-david@redhat.com> References: <20210301161137.78941-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Claudio Fontana , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's factor out adding a MemoryRegionSection to the list, to be reused in RamDiscardManager context next. Cc: Marc-Andr=C3=A9 Lureau Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Claudio Fontana Cc: Thomas Huth Cc: "Alex Benn=C3=A9e" Cc: Peter Xu Cc: Laurent Vivier Cc: Stefan Berger Signed-off-by: David Hildenbrand --- softmmu/memory_mapping.c | 41 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index ad4911427a..28d28cc702 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -194,29 +194,14 @@ typedef struct GuestPhysListener { MemoryListener listener; } GuestPhysListener; =20 -static void guest_phys_blocks_region_add(MemoryListener *listener, +static void guest_phys_block_add_section(GuestPhysListener *g, MemoryRegionSection *section) { - GuestPhysListener *g; - uint64_t section_size; - hwaddr target_start, target_end; - uint8_t *host_addr; - GuestPhysBlock *predecessor; - - /* we only care about RAM */ - if (!memory_region_is_ram(section->mr) || - memory_region_is_ram_device(section->mr) || - memory_region_is_nonvolatile(section->mr)) { - return; - } - - g =3D container_of(listener, GuestPhysListener, listener); - section_size =3D int128_get64(section->size); - target_start =3D section->offset_within_address_space; - target_end =3D target_start + section_size; - host_addr =3D memory_region_get_ram_ptr(section->mr) + - section->offset_within_region; - predecessor =3D NULL; + const hwaddr target_start =3D section->offset_within_address_space; + const hwaddr target_end =3D target_start + int128_get64(section->size); + uint8_t *host_addr =3D memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + GuestPhysBlock *predecessor =3D NULL; =20 /* find continuity in guest physical address space */ if (!QTAILQ_EMPTY(&g->list->head)) { @@ -262,6 +247,20 @@ static void guest_phys_blocks_region_add(MemoryListene= r *listener, #endif } =20 +static void guest_phys_blocks_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + GuestPhysListener *g =3D container_of(listener, GuestPhysListener, lis= tener); + + /* we only care about RAM */ + if (!memory_region_is_ram(section->mr) || + memory_region_is_ram_device(section->mr) || + memory_region_is_nonvolatile(section->mr)) { + return; + } + guest_phys_block_add_section(g, section); +} + void guest_phys_blocks_append(GuestPhysBlockList *list) { GuestPhysListener g =3D { 0 }; --=20 2.29.2 From nobody Mon May 20 14:56:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614615301; cv=none; d=zohomail.com; s=zohoarc; b=MYf8PtW2Ve9WFgN6ugnwBnelSjX0A3vFDpiLLHPy9vxQfTpvTVMerDGZYyZrLEREq99Rg2T9CvdGUaPQLxzHHriQ8EXz8svBli6tWaiwo9dSSUi1arIBIfEJi9hrZvI/BUVXXoPVPBsPltzFaQR4y2RTy4HHWpopxfXBRO5yxhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614615301; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=voQ6vGrVGrtv1/Gt+CSy1bszM8wXuK7Aj5ODGwvGILE=; b=Iy2m7oxNvGJbgu5jwe3cb9OMFszwpFseW+/toGA7J6Dl9RjEULHuOJys7xFNvlkDbAF5u47NDK59e0p7aeR/dkb1QLqnrYYRr16qsoGlGUi80360HOJlRilvTLkOVedFME/1EQ+HQaoAW5iXZyVxcsx88PIogHRqoVkhrQwGFDQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614615301149777.3098328243232; Mon, 1 Mar 2021 08:15:01 -0800 (PST) Received: from localhost ([::1]:45426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGlCF-00043e-Qn for importer@patchew.org; Mon, 01 Mar 2021 11:15:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGlAA-00028y-A4 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGlA8-0003Tx-FY for qemu-devel@nongnu.org; Mon, 01 Mar 2021 11:12:50 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-xwHI_g27NO6YiInMupRbtQ-1; Mon, 01 Mar 2021 11:12:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1129CE64C; Mon, 1 Mar 2021 16:12:44 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B06619C45; Mon, 1 Mar 2021 16:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614615167; 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=voQ6vGrVGrtv1/Gt+CSy1bszM8wXuK7Aj5ODGwvGILE=; b=JZ7tUBEFeXmdsIXVMVzWU06Qa+Eo4FB7FTVD4H3I+jwxBNm5/VgY3wSWvJkkGFd/7WIZbp WzN5LPDka6FYXEXiYcDY855ItQZvTb/lIfSOrCFHv3ZB6yHf+zE5X8s3URA3TUyZRsOJdS r6Z0mj54HNx1Pv2OJwxRvCcyYmb7+18= X-MC-Unique: xwHI_g27NO6YiInMupRbtQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 5/5] softmmu/memory_mapping: optimize for RamDiscardManager sections Date: Mon, 1 Mar 2021 17:11:37 +0100 Message-Id: <20210301161137.78941-6-david@redhat.com> In-Reply-To: <20210301161137.78941-1-david@redhat.com> References: <20210301161137.78941-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Claudio Fontana , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) virtio-mem logically plugs/unplugs memory within a sparse memory region and notifies via the RamDiscardManager interface when parts become plugged (populated) or unplugged (discarded). Currently, we end up (via the two users) 1) zeroing all logically unplugged/discarded memory during TPM resets. 2) reading all logically unplugged/discarded memory when dumping, to figure out the content is zero. 1) is always bad, because we assume unplugged memory stays discarded (and is already implicitly zero). 2) isn't that bad with anonymous memory, we end up reading the zero page (slow and unnecessary, though). However, once we use some file-backed memory (future use case), even reading will populate memory. Let's cut out all parts marked as not-populated (discarded) via the RamDiscardManager. As virtio-mem is the single user, this now means that logically unplugged memory ranges will no longer be included in the dump, which results in smaller dump files and faster dumping. virtio-mem has a minimum granularity of 1 MiB (and the default is usually 2 MiB). Theoretically, we can see quite some fragmentation, in practice we won't have it completely fragmented in 1 MiB pieces. Still, we might end up with many physical ranges. Both, the ELF format and kdump seem to be ready to support many individual ranges (e.g., for ELF it seems to be UINT32_MAX, kdump has a linear bitmap). Cc: Marc-Andr=C3=A9 Lureau Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Claudio Fontana Cc: Thomas Huth Cc: "Alex Benn=C3=A9e" Cc: Peter Xu Cc: Laurent Vivier Cc: Stefan Berger Signed-off-by: David Hildenbrand --- softmmu/memory_mapping.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index 28d28cc702..30a12d4321 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -247,6 +247,15 @@ static void guest_phys_block_add_section(GuestPhysList= ener *g, #endif } =20 +static int guest_phys_ram_populate_cb(MemoryRegionSection *section, + void *opaque) +{ + GuestPhysListener *g =3D opaque; + + guest_phys_block_add_section(g, section); + return 0; +} + static void guest_phys_blocks_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -258,6 +267,17 @@ static void guest_phys_blocks_region_add(MemoryListene= r *listener, memory_region_is_nonvolatile(section->mr)) { return; } + + /* for special sparse regions, only add populated parts */ + if (memory_region_has_ram_discard_manager(section->mr)) { + RamDiscardManager *rdm; + + rdm =3D memory_region_get_ram_discard_manager(section->mr); + ram_discard_manager_replay_populated(rdm, section, + guest_phys_ram_populate_cb, g= ); + return; + } + guest_phys_block_add_section(g, section); } =20 --=20 2.29.2