From nobody Sat May 18 10:07:48 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626786981801450.9812335028214; Tue, 20 Jul 2021 06:16:21 -0700 (PDT) Received: from localhost ([::1]:46446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5pbg-00038D-7E for importer@patchew.org; Tue, 20 Jul 2021 09:16:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPS-0005c3-0D for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:03:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPQ-0001Gr-9H for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:03:41 -0400 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-373-TbIMygRcN92fF2IIdw2Acg-1; Tue, 20 Jul 2021 09:03:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 546D9195D561; Tue, 20 Jul 2021 13:03:37 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34EB869CB4; Tue, 20 Jul 2021 13:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626786219; 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=t0aTiRSVSNPIhihgMceYa2bebLkk5m+Lhw9P1mIHD50=; b=WUjN6nwWjosWCA1c0SYf7uWLE0mzSqWzkqXVogluD1fVYnEGxnTD6Q8JBYPneg9u3smTFz lyY5O188urlHnhP1TTwJTFbDgcYWd3xEARPJKR5j3g2CtvVLnAEL0cOTfK+hXutRpZnAOw W/X5RxGgwsm3pCRoC6PGIcnZy1qPvnc= X-MC-Unique: TbIMygRcN92fF2IIdw2Acg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH resend v2 1/5] tpm: mark correct memory region range dirty when clearing RAM Date: Tue, 20 Jul 2021 15:03:00 +0200 Message-Id: <20210720130304.26323-2-david@redhat.com> In-Reply-To: <20210720130304.26323-1-david@redhat.com> References: <20210720130304.26323-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.474, 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 , Eduardo Habkost , "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) X-ZM-MESSAGEID: 1626786982659100001 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: Eduardo Habkost 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 362edcc5c9..261f33431c 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.31.1 From nobody Sat May 18 10:07:48 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626786593307753.7574721548752; Tue, 20 Jul 2021 06:09:53 -0700 (PDT) Received: from localhost ([::1]:56912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5pVQ-0007XA-5Z for importer@patchew.org; Tue, 20 Jul 2021 09:09:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPf-0005sC-RI for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:03:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPe-0001JZ-54 for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:03:55 -0400 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-431-GcnuzYpgNjCK-JyLkByCjw-1; Tue, 20 Jul 2021 09:03:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4EF08CC621; Tue, 20 Jul 2021 13:03:51 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8B4218AAB; Tue, 20 Jul 2021 13:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626786233; 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=JdQD+N4Y9uU7e/4s21vkkY2fZYuVqYGiTZftNf9f1hA=; b=RwLNaQxy/R8Tcd8VwmVTVPtWhjsmdzeyOegTO4AH1nDR+ZuBUmg06EhvYZ96/ajCzCGDbE PtHzNVN1Y0L8kjuZJw8UTmq4rrY6ksUVKEuWhAB7h2oJW5EV6Slzmd/fMecxO3KojrTglk 1LkCQ8XZfjszSnsMM8KLKkhkdZsEw0E= X-MC-Unique: GcnuzYpgNjCK-JyLkByCjw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH resend v2 2/5] softmmu/memory_mapping: reuse qemu_get_guest_simple_memory_mapping() Date: Tue, 20 Jul 2021 15:03:01 +0200 Message-Id: <20210720130304.26323-3-david@redhat.com> In-Reply-To: <20210720130304.26323-1-david@redhat.com> References: <20210720130304.26323-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.474, 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 , Eduardo Habkost , "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) X-ZM-MESSAGEID: 1626786595321100001 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: Eduardo Habkost 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 e7af276546..d63f896b30 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -288,8 +288,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) { @@ -309,11 +307,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.31.1 From nobody Sat May 18 10:07:48 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626786767597755.6928987283501; Tue, 20 Jul 2021 06:12:47 -0700 (PDT) Received: from localhost ([::1]:36374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5pYE-0004b5-H4 for importer@patchew.org; Tue, 20 Jul 2021 09:12:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPs-00061R-UC for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pPq-0001KN-Tz for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:08 -0400 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-303-Vth_Rw3hNVKJxUCk-GTnqA-1; Tue, 20 Jul 2021 09:04:02 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7EAE7CC622; Tue, 20 Jul 2021 13:04:01 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id A237369CB4; Tue, 20 Jul 2021 13:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626786246; 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=Z529/eydABA0pqIocAcsEmQFLGljXmJIFgQvuEJplCo=; b=NvX+dLHoctGaMexCitUgCnWSYl06uUmlECWTfa/5yaXPzzEgftl48cmr+M53dP0BTBJAeh VgUEqJBjjg+Z9NI1yFGGMGi2+2rd6ABpqWN1S19/Gm8AGmnptFMLyFTmbQy8T3AIWWDZ6T 12FeBVprVQafpdL4zCerDLMeEA7Ksv0= X-MC-Unique: Vth_Rw3hNVKJxUCk-GTnqA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH resend v2 3/5] softmmu/memory_mapping: never merge ranges accross memory regions Date: Tue, 20 Jul 2021 15:03:02 +0200 Message-Id: <20210720130304.26323-4-david@redhat.com> In-Reply-To: <20210720130304.26323-1-david@redhat.com> References: <20210720130304.26323-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.474, 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 , Eduardo Habkost , "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) X-ZM-MESSAGEID: 1626786768595100001 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: Eduardo Habkost 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 Acked-by: Stefan Berger Reviewed-by: Peter Xu --- 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 d63f896b30..c149bad44a 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -229,7 +229,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.31.1 From nobody Sat May 18 10:07:48 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626786399476890.30644033443; Tue, 20 Jul 2021 06:06:39 -0700 (PDT) Received: from localhost ([::1]:46302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5pSI-0000UY-Em for importer@patchew.org; Tue, 20 Jul 2021 09:06:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pQ7-0006Av-AW for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pQ5-0001Ky-D3 for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:22 -0400 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-275-XnmhLWeZPgSnDXFpCriZ_A-1; Tue, 20 Jul 2021 09:04:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00D531084F4B; Tue, 20 Jul 2021 13:04:16 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id D007769CB4; Tue, 20 Jul 2021 13:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626786259; 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=9+jglctDSTZWV6NDN1qeWHoKnVrNI1JGY5uAC/iQQK8=; b=Am8lILGoYZFCZNg5LV5+oBA020+/8//x8Hx/fEokqD+pfU4WFDqyPU52cnuV0ZJ2aqW9H4 yMMmsgKJM4mj3lAFpkFJqgQVQA3DpEHll3Z3DSb2/5arIEFzOUhTeAefwQWoZaZOHFATuN Ajv7X/VU3Hb4dt+OXmuquso//eZQ5E4= X-MC-Unique: XnmhLWeZPgSnDXFpCriZ_A-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH resend v2 4/5] softmmu/memory_mapping: factor out adding physical memory ranges Date: Tue, 20 Jul 2021 15:03:03 +0200 Message-Id: <20210720130304.26323-5-david@redhat.com> In-Reply-To: <20210720130304.26323-1-david@redhat.com> References: <20210720130304.26323-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.474, 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 , Eduardo Habkost , "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) X-ZM-MESSAGEID: 1626786401766100001 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: Eduardo Habkost 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 Reviewed-by: Stefan Berger --- 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 c149bad44a..b7e4f3f788 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -193,29 +193,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)) { @@ -261,6 +246,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.31.1 From nobody Sat May 18 10:07:48 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626787153367892.9793747522622; Tue, 20 Jul 2021 06:19:13 -0700 (PDT) Received: from localhost ([::1]:53956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5peS-00087N-C6 for importer@patchew.org; Tue, 20 Jul 2021 09:19:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pQH-0006DQ-EI for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5pQF-0001LL-Di for qemu-devel@nongnu.org; Tue, 20 Jul 2021 09:04:33 -0400 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-484-BkdLB57jM-SDULKw31-Xlg-1; Tue, 20 Jul 2021 09:04:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E134804143; Tue, 20 Jul 2021 13:04:26 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514E169CB4; Tue, 20 Jul 2021 13:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626786270; 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=dvx1x+YAKC4ggmFKmjEd4OCra8Milqq4WgUXQwGODzE=; b=NCVd9XieeAfr4hiJhpiVS+yzNATCX/PdftY2MaCpyBcZMR+k2h5fhk/ho+6zvh7zOrJ9Ne NZjvanZ9PuyTnq2Un/Ri0/QVeOTiI0veNsxEDG4qhQrQ0iwl9sk6lWq2Oa7VdrRKZjxELV 84rgDxTlk3vMSuogoK9SMPwnY0MVQh8= X-MC-Unique: BkdLB57jM-SDULKw31-Xlg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH resend v2 5/5] softmmu/memory_mapping: optimize for RamDiscardManager sections Date: Tue, 20 Jul 2021 15:03:04 +0200 Message-Id: <20210720130304.26323-6-david@redhat.com> In-Reply-To: <20210720130304.26323-1-david@redhat.com> References: <20210720130304.26323-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.474, 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 , Eduardo Habkost , "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) X-ZM-MESSAGEID: 1626787155199100001 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: Eduardo Habkost 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 Reviewed-by: Peter Xu --- softmmu/memory_mapping.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index b7e4f3f788..856778a109 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -246,6 +246,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) { @@ -257,6 +266,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.31.1