From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131242; cv=none; d=zohomail.com; s=zohoarc; b=FFM77b/4znOrK6Jz3TVptnEWf7UWNViwzJX/vHczDJzfyRq7Np4uYQ7k9KwE0IuiZHtNZttXAZfhi0AC1kEvqkPWyDOW8lSEOJW65sfGtLZoBskw0qcgOd0kJzLk9qqRiU5lI2FomCexPfHxqRCrS9hJVOjYvv+RuKZfLNzaIIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131242; 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=QEj9mJF11DhrqbQX0YVXX3cnOZeSLuB42yARQjagHeY=; b=mHTeOeghuKTK0LFX7Q+FEFbZIHoZ4gIjtPUvxVf7t5HEgIA7dq2vx3fkL65koVYlwdEvqdB+2x+cd8Npfwx25wyYw7DdPWKfBctaY0eyTsrJ+VaOa2YpiIg6kFLxhB4hsM6Vdd89ZuIywK/qX2pUtn2+jd4BPXovnoe/TXdpLNY= 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 1582131242837430.0598162267497; Wed, 19 Feb 2020 08:54:02 -0800 (PST) Received: from localhost ([::1]:56442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4Sbp-0008Fs-Kg for importer@patchew.org; Wed, 19 Feb 2020 11:54:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3B-0000F4-FW for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3A-00045I-2f for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:13 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:60462 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S39-000458-UZ for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:12 -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-429-p8SZ9pRHO6a0FvpOonbEMQ-1; Wed, 19 Feb 2020 11:18:07 -0500 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 A8DD78010EB; Wed, 19 Feb 2020 16:18:06 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 283418B577; Wed, 19 Feb 2020 16:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129091; 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=QEj9mJF11DhrqbQX0YVXX3cnOZeSLuB42yARQjagHeY=; b=R2BWdF+UOPjGj+DeOYKi1vvCTgEA8sFxxZf3EAxddFxyNzdIp7hOLuhx5/4TVw0/VkNGWf 2DkDLMiuO336Y7SPjDkCYbbjzJlM1pzxmlq6ZzvFXESCb3MsAkEb2LxFuzscIDaW11c4Ru OFtJqeHVGEIZImpVR5vjwYkLLNqWdWQ= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 01/13] util: vfio-helpers: Factor out and fix processing of existing ram blocks Date: Wed, 19 Feb 2020 17:17:13 +0100 Message-Id: <20200219161725.115218-2-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: p8SZ9pRHO6a0FvpOonbEMQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor it out into common code when a new notifier is registered, just as done with the memory region notifier. This allows us to have the logic about how to process existing ram blocks at a central place (which will be extended soon). Just like when adding a new ram block, we have to register the max_length for now. We don't have a way to get notified about resizes yet, and some memory would not be mapped when growing the ram block. Note: Currently, ram blocks are only "fake resized". All memory (max_length) is accessible. We can get rid of a bunch of functions in stubs/ram-block.c . Print the warning from inside qemu_vfio_ram_block_added(). Cc: Richard Henderson Cc: Paolo Bonzini Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Alex Williamson Cc: Stefan Hajnoczi Cc: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- exec.c | 5 +++++ hw/core/numa.c | 14 ++++++++++++++ include/exec/cpu-common.h | 1 + util/vfio-helpers.c | 28 +++++++--------------------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/exec.c b/exec.c index 8e9cc3b47c..dfd43d27c6 100644 --- a/exec.c +++ b/exec.c @@ -2016,6 +2016,11 @@ ram_addr_t qemu_ram_get_used_length(RAMBlock *rb) return rb->used_length; } =20 +ram_addr_t qemu_ram_get_max_length(RAMBlock *rb) +{ + return rb->max_length; +} + bool qemu_ram_is_shared(RAMBlock *rb) { return rb->flags & RAM_SHARED; diff --git a/hw/core/numa.c b/hw/core/numa.c index 0d1b4be76a..6599c69e05 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -899,9 +899,23 @@ void query_numa_node_mem(NumaNodeMem node_mem[], Machi= neState *ms) } } =20 +static int ram_block_notify_add_single(RAMBlock *rb, void *opaque) +{ + const ram_addr_t max_size =3D qemu_ram_get_max_length(rb); + void *host =3D qemu_ram_get_host_addr(rb); + RAMBlockNotifier *notifier =3D opaque; + + if (host) { + notifier->ram_block_added(notifier, host, max_size); + } + return 0; +} + void ram_block_notifier_add(RAMBlockNotifier *n) { QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next); + /* Notify about all existing ram blocks. */ + qemu_ram_foreach_block(ram_block_notify_add_single, n); } =20 void ram_block_notifier_remove(RAMBlockNotifier *n) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 81753bbb34..9760ac9068 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -59,6 +59,7 @@ const char *qemu_ram_get_idstr(RAMBlock *rb); void *qemu_ram_get_host_addr(RAMBlock *rb); ram_addr_t qemu_ram_get_offset(RAMBlock *rb); ram_addr_t qemu_ram_get_used_length(RAMBlock *rb); +ram_addr_t qemu_ram_get_max_length(RAMBlock *rb); bool qemu_ram_is_shared(RAMBlock *rb); bool qemu_ram_is_uf_zeroable(RAMBlock *rb); void qemu_ram_set_uf_zeroable(RAMBlock *rb); diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 813f7ec564..71e02e7f35 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -376,8 +376,13 @@ static void qemu_vfio_ram_block_added(RAMBlockNotifier= *n, void *host, size_t size) { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); + int ret; + trace_qemu_vfio_ram_block_added(s, host, size); - qemu_vfio_dma_map(s, host, size, false, NULL); + ret =3D qemu_vfio_dma_map(s, host, size, false, NULL); + if (ret) { + error_report("qemu_vfio_dma_map(%p, %zu) failed: %d", host, size, = ret); + } } =20 static void qemu_vfio_ram_block_removed(RAMBlockNotifier *n, @@ -390,33 +395,14 @@ static void qemu_vfio_ram_block_removed(RAMBlockNotif= ier *n, } } =20 -static int qemu_vfio_init_ramblock(RAMBlock *rb, void *opaque) -{ - void *host_addr =3D qemu_ram_get_host_addr(rb); - ram_addr_t length =3D qemu_ram_get_used_length(rb); - int ret; - QEMUVFIOState *s =3D opaque; - - if (!host_addr) { - return 0; - } - ret =3D qemu_vfio_dma_map(s, host_addr, length, false, NULL); - if (ret) { - fprintf(stderr, "qemu_vfio_init_ramblock: failed %p %" PRId64 "\n", - host_addr, (uint64_t)length); - } - return 0; -} - static void qemu_vfio_open_common(QEMUVFIOState *s) { qemu_mutex_init(&s->lock); s->ram_notifier.ram_block_added =3D qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed =3D qemu_vfio_ram_block_removed; - ram_block_notifier_add(&s->ram_notifier); s->low_water_mark =3D QEMU_VFIO_IOVA_MIN; s->high_water_mark =3D QEMU_VFIO_IOVA_MAX; - qemu_ram_foreach_block(qemu_vfio_init_ramblock, s); + ram_block_notifier_add(&s->ram_notifier); } =20 /** --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582130401; cv=none; d=zohomail.com; s=zohoarc; b=grF98RCpwlqMbYT0nowEhRcUhCjCFNR1zCvJcRGlKlWxWsOJmuBTSArRCVS9C4PvUshJoIi1E951AAdVAs8jR6zcw/pKb/PT64dW1B8Qeryj2JF8McWHDE046LVtxYFewXQbRpGOfgzi/qCCJA5vRzlnboGrBnwwR65gs0xnyyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582130401; 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=yrdyc1ubZ2flwjzVEqH8TAqNymNfAZhQeZ7HppuDGvY=; b=Hlq3A/hEn5eHrczv/I7WPdYG0y1yiT8TH0+1c+SgfruRLrVIMwIE2qutbE8mEcyV+UPwpj87kd2jbag3Dlr5PqdBvEXGL8gXuLLgS+v7jpwEp9sK7XuxCb9fnj3ES+AzuMszT6RGxrTnimggtQ4xs68KbtD6hhRUwOJqtVgHNxE= 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 1582130401333343.94359232190016; Wed, 19 Feb 2020 08:40:01 -0800 (PST) Received: from localhost ([::1]:56020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SOG-0002Mr-Cq for importer@patchew.org; Wed, 19 Feb 2020 11:40:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39051) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3R-0000vy-IG for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3Q-0004Em-IC for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:29 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33737 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3Q-0004EE-E6 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:28 -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-321-exahv2apMWKDgnu45s4q5w-1; Wed, 19 Feb 2020 11:18:23 -0500 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 71D248017DF; Wed, 19 Feb 2020 16:18:22 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 075508AC47; Wed, 19 Feb 2020 16:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129107; 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=yrdyc1ubZ2flwjzVEqH8TAqNymNfAZhQeZ7HppuDGvY=; b=OCZoipGUo8SVHshAh/y511bZyDKlFbJn4ofBLCsEdBZ9Iz3/LTyCTzAQynXFfI7H0xIvmG 5BNRnCxzx8kjwxhPGMSgqmMCRRagOyJlW03yDlXQWKMCc55BhfDuQkL49PIG71RKEJ0IrW BEctn+j2d2+vYDO0ME1BtY76lWBGqUQ= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 02/13] stubs/ram-block: Remove stubs that are no longer needed Date: Wed, 19 Feb 2020 17:17:14 +0100 Message-Id: <20200219161725.115218-3-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: exahv2apMWKDgnu45s4q5w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Current code no longer needs these stubs to compile. Let's just remove them. Cc: Richard Henderson Cc: Paolo Bonzini Cc: Eduardo Habkost Cc: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- stubs/ram-block.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/stubs/ram-block.c b/stubs/ram-block.c index 73c0a3ee08..10855b52dd 100644 --- a/stubs/ram-block.c +++ b/stubs/ram-block.c @@ -2,21 +2,6 @@ #include "exec/ramlist.h" #include "exec/cpu-common.h" =20 -void *qemu_ram_get_host_addr(RAMBlock *rb) -{ - return 0; -} - -ram_addr_t qemu_ram_get_offset(RAMBlock *rb) -{ - return 0; -} - -ram_addr_t qemu_ram_get_used_length(RAMBlock *rb) -{ - return 0; -} - void ram_block_notifier_add(RAMBlockNotifier *n) { } @@ -24,8 +9,3 @@ void ram_block_notifier_add(RAMBlockNotifier *n) void ram_block_notifier_remove(RAMBlockNotifier *n) { } - -int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque) -{ - return 0; -} --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582129173; cv=none; d=zohomail.com; s=zohoarc; b=ayyaf6Ahum3bsnukw4YzmqEtQL/FQ9KhOOPTOTKioEG6c3FbnwmyyyCPc2VXQcm97on9zBlHWpWz1BrohJeIhp6CTUDVOtS3tjfr5c1Z4Rpcr1HE2+QDGsfzpFICIC/Deqod16ko/g2wfsXMyuOHAkuPxNmghRuVtBxe5ab5SOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582129173; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pXefZk+30GLi84gf0c+RUsXW7lCpl8b+PjJ+3KrDt6E=; b=JMhGcY3DQVTGNJymxmA0PMgoKNLfmvgBhgC3tkepzjQLZ2dHMKeJBjIXp4trFJqCqIpfH5AtCyYuwHDIK22jJk14dQI0HrXS2no6NVd5YOyXJDhhWCl923gNzX0JAr47FtTs3YKmdeIkHDlC6upW4uNkh0I0HtAhde+BK04i9sg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582129173058818.0975524873395; Wed, 19 Feb 2020 08:19:33 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4S3h-0000Pg-K7; Wed, 19 Feb 2020 16:18:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4S3f-0000Pb-O6 for xen-devel@lists.xenproject.org; Wed, 19 Feb 2020 16:18:43 +0000 Received: from us-smtp-1.mimecast.com (unknown [205.139.110.61]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 7d7a37d7-5333-11ea-83c6-12813bfff9fa; Wed, 19 Feb 2020 16:18:41 +0000 (UTC) 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-68-L6T8MO6bOrWJNOXAQQPg5g-1; Wed, 19 Feb 2020 11:18:36 -0500 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 8C3CB8EDBC1; Wed, 19 Feb 2020 16:18:35 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id C49D0857BF; Wed, 19 Feb 2020 16:18:22 +0000 (UTC) X-Inumbo-ID: 7d7a37d7-5333-11ea-83c6-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129121; 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=8PhGid55mGXBt3QR7+iEAUfsznHM9i37dSidt+A/ALk=; b=AM0G48ARtQgOssSiiOF8Y0vcyKbkMW8D+0cNF+RLG13LJuxqNCEHHy6o5B4qobdpQeW2Zv hk7C5SjCiZm3wZ44KuAh9LO3toW2m3wp4WSGHddt9+v2TCKz13ACxdA62dLE06XF+Z/MN/ 9KLfhaJIl2DRQXQ2Tb7TH/ZVqxmsbQg= From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 19 Feb 2020 17:17:15 +0100 Message-Id: <20200219161725.115218-4-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: L6T8MO6bOrWJNOXAQQPg5g-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [Xen-devel] [PATCH v1 03/13] numa: Teach ram block notifiers about resizeable ram blocks X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paul Durrant , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , xen-devel@lists.xenproject.org, Anthony Perard , Paolo Bonzini , Richard Henderson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Ram block notifiers are currently not aware of resizes. Especially to handle resizes during migration, but also to implement actually resizeable ram blocks (make everything between used_length and max_length inaccessible), we want to teach ram block notifiers about resizeable ram. Introduce the basic infrastructure but keep using max_size in the existing notifiers. Supply the max_size when adding and removing ram blocks. Also, notify on resizes. Acked-by: Paul Durrant Cc: Richard Henderson Cc: Paolo Bonzini Cc: "Dr. David Alan Gilbert" Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paul Durrant Cc: "Michael S. Tsirkin" Cc: xen-devel@lists.xenproject.org Cc: Igor Mammedov Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- exec.c | 13 +++++++++++-- hw/core/numa.c | 22 +++++++++++++++++----- hw/i386/xen/xen-mapcache.c | 7 ++++--- include/exec/ramlist.h | 13 +++++++++---- target/i386/hax-mem.c | 5 +++-- target/i386/sev.c | 18 ++++++++++-------- util/vfio-helpers.c | 17 +++++++++-------- 7 files changed, 63 insertions(+), 32 deletions(-) diff --git a/exec.c b/exec.c index dfd43d27c6..b75250e773 100644 --- a/exec.c +++ b/exec.c @@ -2129,6 +2129,8 @@ static int memory_try_enable_merging(void *addr, size= _t len) */ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) { + const ram_addr_t oldsize =3D block->used_length; + assert(block); =20 newsize =3D HOST_PAGE_ALIGN(newsize); @@ -2153,6 +2155,11 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t news= ize, Error **errp) return -EINVAL; } =20 + /* Notify before modifying the ram block and touching the bitmaps. */ + if (block->host) { + ram_block_notify_resize(block->host, oldsize, newsize); + } + cpu_physical_memory_clear_dirty_range(block->offset, block->used_lengt= h); block->used_length =3D newsize; cpu_physical_memory_set_dirty_range(block->offset, block->used_length, @@ -2312,7 +2319,8 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp, bool shared) qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_HUG= EPAGE); /* MADV_DONTFORK is also needed by KVM in absence of synchronous M= MU */ qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_DON= TFORK); - ram_block_notify_add(new_block->host, new_block->max_length); + ram_block_notify_add(new_block->host, new_block->used_length, + new_block->max_length); } } =20 @@ -2492,7 +2500,8 @@ void qemu_ram_free(RAMBlock *block) } =20 if (block->host) { - ram_block_notify_remove(block->host, block->max_length); + ram_block_notify_remove(block->host, block->used_length, + block->max_length); } =20 qemu_mutex_lock_ramlist(); diff --git a/hw/core/numa.c b/hw/core/numa.c index 6599c69e05..e28ad24fcd 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -902,11 +902,12 @@ void query_numa_node_mem(NumaNodeMem node_mem[], Mach= ineState *ms) static int ram_block_notify_add_single(RAMBlock *rb, void *opaque) { const ram_addr_t max_size =3D qemu_ram_get_max_length(rb); + const ram_addr_t size =3D qemu_ram_get_used_length(rb); void *host =3D qemu_ram_get_host_addr(rb); RAMBlockNotifier *notifier =3D opaque; =20 if (host) { - notifier->ram_block_added(notifier, host, max_size); + notifier->ram_block_added(notifier, host, size, max_size); } return 0; } @@ -923,20 +924,31 @@ void ram_block_notifier_remove(RAMBlockNotifier *n) QLIST_REMOVE(n, next); } =20 -void ram_block_notify_add(void *host, size_t size) +void ram_block_notify_add(void *host, size_t size, size_t max_size) { RAMBlockNotifier *notifier; =20 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { - notifier->ram_block_added(notifier, host, size); + notifier->ram_block_added(notifier, host, size, max_size); } } =20 -void ram_block_notify_remove(void *host, size_t size) +void ram_block_notify_remove(void *host, size_t size, size_t max_size) { RAMBlockNotifier *notifier; =20 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { - notifier->ram_block_removed(notifier, host, size); + notifier->ram_block_removed(notifier, host, size, max_size); + } +} + +void ram_block_notify_resize(void *host, size_t old_size, size_t new_size) +{ + RAMBlockNotifier *notifier; + + QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { + if (notifier->ram_block_resized) { + notifier->ram_block_resized(notifier, host, old_size, new_size= ); + } } } diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index 5b120ed44b..d6dcea65d1 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -169,7 +169,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, =20 if (entry->vaddr_base !=3D NULL) { if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) { - ram_block_notify_remove(entry->vaddr_base, entry->size); + ram_block_notify_remove(entry->vaddr_base, entry->size, + entry->size); } if (munmap(entry->vaddr_base, entry->size) !=3D 0) { perror("unmap fails"); @@ -211,7 +212,7 @@ static void xen_remap_bucket(MapCacheEntry *entry, } =20 if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) { - ram_block_notify_add(vaddr_base, size); + ram_block_notify_add(vaddr_base, size, size); } =20 entry->vaddr_base =3D vaddr_base; @@ -452,7 +453,7 @@ static void xen_invalidate_map_cache_entry_unlocked(uin= t8_t *buffer) } =20 pentry->next =3D entry->next; - ram_block_notify_remove(entry->vaddr_base, entry->size); + ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); if (munmap(entry->vaddr_base, entry->size) !=3D 0) { perror("unmap fails"); exit(-1); diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h index bc4faa1b00..293c0ddabe 100644 --- a/include/exec/ramlist.h +++ b/include/exec/ramlist.h @@ -65,15 +65,20 @@ void qemu_mutex_lock_ramlist(void); void qemu_mutex_unlock_ramlist(void); =20 struct RAMBlockNotifier { - void (*ram_block_added)(RAMBlockNotifier *n, void *host, size_t size); - void (*ram_block_removed)(RAMBlockNotifier *n, void *host, size_t size= ); + void (*ram_block_added)(RAMBlockNotifier *n, void *host, size_t size, + size_t max_size); + void (*ram_block_removed)(RAMBlockNotifier *n, void *host, size_t size, + size_t max_size); + void (*ram_block_resized)(RAMBlockNotifier *n, void *host, size_t old_= size, + size_t new_size); QLIST_ENTRY(RAMBlockNotifier) next; }; =20 void ram_block_notifier_add(RAMBlockNotifier *n); void ram_block_notifier_remove(RAMBlockNotifier *n); -void ram_block_notify_add(void *host, size_t size); -void ram_block_notify_remove(void *host, size_t size); +void ram_block_notify_add(void *host, size_t size, size_t max_size); +void ram_block_notify_remove(void *host, size_t size, size_t max_size); +void ram_block_notify_resize(void *host, size_t old_size, size_t new_size); =20 void ram_block_dump(Monitor *mon); =20 diff --git a/target/i386/hax-mem.c b/target/i386/hax-mem.c index 6bb5a24917..454d7fb212 100644 --- a/target/i386/hax-mem.c +++ b/target/i386/hax-mem.c @@ -293,7 +293,8 @@ static MemoryListener hax_memory_listener =3D { .priority =3D 10, }; =20 -static void hax_ram_block_added(RAMBlockNotifier *n, void *host, size_t si= ze) +static void hax_ram_block_added(RAMBlockNotifier *n, void *host, size_t si= ze, + size_t max_size) { /* * We must register each RAM block with the HAXM kernel module, or @@ -304,7 +305,7 @@ static void hax_ram_block_added(RAMBlockNotifier *n, vo= id *host, size_t size) * host physical pages for the RAM block as part of this registration * process, hence the name hax_populate_ram(). */ - if (hax_populate_ram((uint64_t)(uintptr_t)host, size) < 0) { + if (hax_populate_ram((uint64_t)(uintptr_t)host, max_size) < 0) { fprintf(stderr, "HAX failed to populate RAM\n"); abort(); } diff --git a/target/i386/sev.c b/target/i386/sev.c index 024bb24e51..6b4cee24a2 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -129,7 +129,8 @@ sev_set_guest_state(SevState new_state) } =20 static void -sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size) +sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size, + size_t max_size) { int r; struct kvm_enc_region range; @@ -146,19 +147,20 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, = size_t size) } =20 range.addr =3D (__u64)(unsigned long)host; - range.size =3D size; + range.size =3D max_size; =20 - trace_kvm_memcrypt_register_region(host, size); + trace_kvm_memcrypt_register_region(host, max_size); r =3D kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_REG_REGION, &range); if (r) { error_report("%s: failed to register region (%p+%#zx) error '%s'", - __func__, host, size, strerror(errno)); + __func__, host, max_size, strerror(errno)); exit(1); } } =20 static void -sev_ram_block_removed(RAMBlockNotifier *n, void *host, size_t size) +sev_ram_block_removed(RAMBlockNotifier *n, void *host, size_t size, + size_t max_size) { int r; struct kvm_enc_region range; @@ -175,13 +177,13 @@ sev_ram_block_removed(RAMBlockNotifier *n, void *host= , size_t size) } =20 range.addr =3D (__u64)(unsigned long)host; - range.size =3D size; + range.size =3D max_size; =20 - trace_kvm_memcrypt_unregister_region(host, size); + trace_kvm_memcrypt_unregister_region(host, max_size); r =3D kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_UNREG_REGION, &range); if (r) { error_report("%s: failed to unregister region (%p+%#zx)", - __func__, host, size); + __func__, host, max_size); } } =20 diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 71e02e7f35..61a0cf6e12 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -372,25 +372,26 @@ fail_container: return ret; } =20 -static void qemu_vfio_ram_block_added(RAMBlockNotifier *n, - void *host, size_t size) +static void qemu_vfio_ram_block_added(RAMBlockNotifier *n, void *host, + size_t size, size_t max_size) { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); int ret; =20 - trace_qemu_vfio_ram_block_added(s, host, size); - ret =3D qemu_vfio_dma_map(s, host, size, false, NULL); + trace_qemu_vfio_ram_block_added(s, host, max_size); + ret =3D qemu_vfio_dma_map(s, host, max_size, false, NULL); if (ret) { - error_report("qemu_vfio_dma_map(%p, %zu) failed: %d", host, size, = ret); + error_report("qemu_vfio_dma_map(%p, %zu) failed: %d", host, + max_size, ret); } } =20 -static void qemu_vfio_ram_block_removed(RAMBlockNotifier *n, - void *host, size_t size) +static void qemu_vfio_ram_block_removed(RAMBlockNotifier *n, void *host, + size_t size, size_t max_size) { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); if (host) { - trace_qemu_vfio_ram_block_removed(s, host, size); + trace_qemu_vfio_ram_block_removed(s, host, max_size); qemu_vfio_dma_unmap(s, host); } } --=20 2.24.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582130492; cv=none; d=zohomail.com; s=zohoarc; b=RMBIfq65+YqiC9LDGXyS9h2Lpnd4tLPR5FwSlGOTnfG4TWyI2hhEukz/sc136ZxclcabTvvAYNsX9u7/QXgdUt7onhaRW3oSI1xpN7XR+00qPeOepmR3S7j+BoZ4nkgrlFDz5uym7jCVz0FcTMDmG0OZwV/6zsnsTjiZl38XSgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582130492; 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=weIuyWpQ4HsRvv7hJb8wpGUr7pFtv7kXTouN3VzlJG8=; b=GVeiVt5F5b1SGS89DNchj4i3PNcp9vSHPTUAOSUGm/iF1Tz/2X+qFgvm4tq+r9VeoHUkmOUmiBfylomhwlQbIiYrstiW1L6oFTL/HNlMYZTGB2tMipQp7bFop61wTUyqeJ0Y94h9OplAHUQi12Dehrtvt9Obw0272TjKkBp0GoU= 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 158213049282594.46556947768715; Wed, 19 Feb 2020 08:41:32 -0800 (PST) Received: from localhost ([::1]:56142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SPj-00068I-UB for importer@patchew.org; Wed, 19 Feb 2020 11:41:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39124) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3j-0001gj-C2 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3i-0004SO-8m for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30180 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3i-0004SG-4n for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:46 -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-264-w2FeIq_HP8S8yURxRV0JZg-1; Wed, 19 Feb 2020 11:18:44 -0500 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 25B24109BFC6; Wed, 19 Feb 2020 16:18:43 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id E335C89F13; Wed, 19 Feb 2020 16:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129125; 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=weIuyWpQ4HsRvv7hJb8wpGUr7pFtv7kXTouN3VzlJG8=; b=NYfme8wAqtIVfndFbrelMm+bDEEjSI8aN/biru7HPcGlN1srgOmzLtNLdiCMTLUfbA8geL /jtoWV+muTBcxeLRjzLk0g5kz/TGdb9x8vhn7YE8Rdwe754WeF8r2oF5AuH+KqAGaAWXO8 pcKo/CPN9cicBY7KqmHemN6BpMLnucE= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 04/13] numa: Make all callbacks of ram block notifiers optional Date: Wed, 19 Feb 2020 17:17:16 +0100 Message-Id: <20200219161725.115218-5-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: w2FeIq_HP8S8yURxRV0JZg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's make add/remove optional. We want to introduce a RAM block notifier for RAM migration, that's only interested in resizes. Cc: Richard Henderson Cc: Paolo Bonzini Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- hw/core/numa.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/core/numa.c b/hw/core/numa.c index e28ad24fcd..4270b268c8 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -915,8 +915,11 @@ static int ram_block_notify_add_single(RAMBlock *rb, v= oid *opaque) void ram_block_notifier_add(RAMBlockNotifier *n) { QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next); + /* Notify about all existing ram blocks. */ - qemu_ram_foreach_block(ram_block_notify_add_single, n); + if (n->ram_block_added) { + qemu_ram_foreach_block(ram_block_notify_add_single, n); + } } =20 void ram_block_notifier_remove(RAMBlockNotifier *n) @@ -929,7 +932,9 @@ void ram_block_notify_add(void *host, size_t size, size= _t max_size) RAMBlockNotifier *notifier; =20 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { - notifier->ram_block_added(notifier, host, size, max_size); + if (notifier->ram_block_added) { + notifier->ram_block_added(notifier, host, size, max_size); + } } } =20 @@ -938,7 +943,9 @@ void ram_block_notify_remove(void *host, size_t size, s= ize_t max_size) RAMBlockNotifier *notifier; =20 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { - notifier->ram_block_removed(notifier, host, size, max_size); + if (notifier->ram_block_removed) { + notifier->ram_block_removed(notifier, host, size, max_size); + } } } =20 --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131418; cv=none; d=zohomail.com; s=zohoarc; b=YTsUO3Twvr8bMIDW/jRZPRMd/awapF0JwWeprrZMiX5nuvzQlVItEDmi76EYtJqoJ5vq0uRDMERboOEqHBtMOzblZ3dShEmLFRabDfznGWqttufP+pcg0CZz4+2yCXoW5HpMUAdhr/YsJXNtXGpeJuQ8ZLK0ugr3pdCvWWTXpWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131418; 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=TkVlqJ137hH9T9d4N1kD0zieB/CiWcqq2eKaC7sYXkY=; b=Cg5V11fSkHaqqGqmxBawCtFjx9CxgcwODMffNjuHeFza0ITgt6j1CIJw+cQVxTS6Zh3CwfcyvOod0wLV8JvG5w/JeDLKU0XTtmL0XXftNXHRI0hXvI4999Gls5kV9ZGLRiURUGJY0UDjEmipZEossqiJHw8hlbufkRAo65HHSaM= 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 1582131418600306.6752033315298; Wed, 19 Feb 2020 08:56:58 -0800 (PST) Received: from localhost ([::1]:56534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4Sef-0006Y6-IV for importer@patchew.org; Wed, 19 Feb 2020 11:56:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39149) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3p-0001rL-I7 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3o-0004U1-0L for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:53 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21585 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3n-0004Tq-So for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:51 -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-133-azv23k9XO3maZZJ0OQFY2A-1; Wed, 19 Feb 2020 11:18:47 -0500 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 3E27687181C; Wed, 19 Feb 2020 16:18:46 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7814D8AC45; Wed, 19 Feb 2020 16:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129131; 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=TkVlqJ137hH9T9d4N1kD0zieB/CiWcqq2eKaC7sYXkY=; b=X/seNnonnI2fYe90+g+NE0XqRk9FEv8Qo29k2Fdg5z+IADjB01nCKucMbAxp1i0gswWpzM SmMyjoEOii3piG3VqvjQKb/MaTSSgZdNEzps+BxWZusaFqblnQ4rfBujgH6JmphywfziQu Pkbixp6mw2ZeA50YJSGZ+DfWe9Hpm5A= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 05/13] migrate/ram: Handle RAM block resizes during precopy Date: Wed, 19 Feb 2020 17:17:17 +0100 Message-Id: <20200219161725.115218-6-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: azv23k9XO3maZZJ0OQFY2A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , Richard Henderson , "Dr . David Alan Gilbert" , Peter Xu , "Michael S. Tsirkin" , Shannon Zhao , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Resizing while migrating is dangerous and does not work as expected. The whole migration code works on the usable_length of ram blocks and does not expect this to change at random points in time. In the case of precopy, the ram block size must not change on the source, after syncing the RAM block list in ram_save_setup(), so as long as the guest is still running on the source. Resizing can be trigger *after* (but not during) a reset in ACPI code by the guest - hw/arm/virt-acpi-build.c:acpi_ram_update() - hw/i386/acpi-build.c:acpi_ram_update() Use the ram block notifier to get notified about resizes. Let's simply cancel migration and indicate the reason. We'll continue running on the source. No harm done. Update the documentation. Postcopy will be handled separately. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Eduardo Habkost Cc: Paolo Bonzini Cc: Igor Mammedov Cc: "Michael S. Tsirkin" Cc: Richard Henderson Cc: Shannon Zhao Cc: Alex Benn=C3=A9e Cc: Peter Xu Signed-off-by: David Hildenbrand --- exec.c | 5 +++-- include/exec/memory.h | 10 ++++++---- migration/migration.c | 9 +++++++-- migration/migration.h | 1 + migration/ram.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index b75250e773..8b015821d6 100644 --- a/exec.c +++ b/exec.c @@ -2120,8 +2120,9 @@ static int memory_try_enable_merging(void *addr, size= _t len) return qemu_madvise(addr, len, QEMU_MADV_MERGEABLE); } =20 -/* Only legal before guest might have detected the memory size: e.g. on - * incoming migration, or right after reset. +/* + * Resizing RAM while migrating can result in the migration being canceled. + * Care has to be taken if the guest might have already detected the memor= y. * * As memory core doesn't know how is memory accessed, it is up to * resize callback to update device state and/or add assertions to detect diff --git a/include/exec/memory.h b/include/exec/memory.h index e85b7de99a..de111347e8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -113,7 +113,7 @@ typedef struct IOMMUNotifier IOMMUNotifier; #define RAM_SHARED (1 << 1) =20 /* Only a portion of RAM (used_length) is actually used, and migrated. - * This used_length size can change across reboots. + * Resizing RAM while migrating can result in the migration being canceled. */ #define RAM_RESIZEABLE (1 << 2) =20 @@ -843,7 +843,9 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegi= on *mr, * RAM. Accesses into the region will * modify memory directly. Only an in= itial * portion of this RAM is actually use= d. - * The used size can change across reb= oots. + * Changing the size while migrating + * can result in the migration being + * canceled. * * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count @@ -1464,8 +1466,8 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr); =20 /* memory_region_ram_resize: Resize a RAM region. * - * Only legal before guest might have detected the memory size: e.g. on - * incoming migration, or right after reset. + * Resizing RAM while migrating can result in the migration being canceled. + * Care has to be taken if the guest might have already detected the memor= y. * * @mr: a memory region created with @memory_region_init_resizeable_ram. * @newsize: the new size the region diff --git a/migration/migration.c b/migration/migration.c index 8fb68795dc..ac9751dbe5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -175,13 +175,18 @@ void migration_object_init(void) } } =20 +void migration_cancel(void) +{ + migrate_fd_cancel(current_migration); +} + void migration_shutdown(void) { /* * Cancel the current migration - that will (eventually) * stop the migration using this structure */ - migrate_fd_cancel(current_migration); + migration_cancel(); object_unref(OBJECT(current_migration)); } =20 @@ -2019,7 +2024,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool = blk, =20 void qmp_migrate_cancel(Error **errp) { - migrate_fd_cancel(migrate_get_current()); + migration_cancel(); } =20 void qmp_migrate_continue(MigrationStatus state, Error **errp) diff --git a/migration/migration.h b/migration/migration.h index 8473ddfc88..79fd74afa5 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -343,5 +343,6 @@ int foreach_not_ignored_block(RAMBlockIterFunc func, vo= id *opaque); void migration_make_urgent_request(void); void migration_consume_urgent_request(void); bool migration_rate_limit(void); +void migration_cancel(void); =20 #endif diff --git a/migration/ram.c b/migration/ram.c index ed23ed1c7c..57f32011a3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -52,6 +52,7 @@ #include "migration/colo.h" #include "block.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "savevm.h" #include "qemu/iov.h" #include "multifd.h" @@ -3710,8 +3711,48 @@ static SaveVMHandlers savevm_ram_handlers =3D { .resume_prepare =3D ram_resume_prepare, }; =20 +static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host, + size_t old_size, size_t new_size) +{ + ram_addr_t offset; + Error *err =3D NULL; + RAMBlock *rb =3D qemu_ram_block_from_host(host, false, &offset); + + if (ramblock_is_ignored(rb)) { + return; + } + + /* + * Some resizes are triggered on the migration target by precopy code, + * when synchronizing RAM block sizes. In these cases, the VM is not + * running and migration is not idle. We have to ignore these resizes, + * as we only care about resizes during precopy on the migration sourc= e. + * This handler is always registered, so ignore when migration is idle. + */ + if (migration_is_idle() || !runstate_is_running() || + postcopy_is_running()) { + return; + } + + /* + * Precopy code cannot deal with the size of ram blocks changing at + * random points in time. We're still running on the source, abort + * the migration and continue running here. Make sure to wait until + * migration was canceled. + */ + error_setg(&err, "RAM block '%s' resized during precopy.", rb->idstr); + migrate_set_error(migrate_get_current(), err); + error_free(err); + migration_cancel(); +} + +static RAMBlockNotifier ram_mig_ram_notifier =3D { + .ram_block_resized =3D ram_mig_ram_block_resized, +}; + void ram_mig_init(void) { qemu_mutex_init(&XBZRLE.lock); register_savevm_live("ram", 0, 4, &savevm_ram_handlers, &ram_state); + ram_block_notifier_add(&ram_mig_ram_notifier); } --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582130598; cv=none; d=zohomail.com; s=zohoarc; b=kI98uA95mu3Qyt+0VdpU1M6yfA4Ij1kfLch2lbinQG49wwqtG17pQ7d/QasWgWZCjCFngMrgiwq5e9D0rjffuTr3NKG0kI+nD/2cVi7Mz3QRMve5wJj76mrJQaMI7qt6BjgBUYxmFNa7vvF8y8/jRsQz8iZ4/zxHIac9NRSZOzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582130598; 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=4eemmDcoP3QvnFaPO/GnjcJxYo3rxsRY3nqc5CLtRTI=; b=JZjOVebF3DBffA6dDQovnbBw36R7wjG7mMTBHpJH6A6E7nnOF29Hobwp88/94AzxVqTNKrWqnuvQf2mx0kwNruT0yjeRxrnwqvpE+iadDZywOHsEX6yBUoloaqHMlmmlLhc1y/BHyRK4cxRVZdeVtZR1RhoTuwWzZin2ewoILms= 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 1582130598046634.9176027148975; Wed, 19 Feb 2020 08:43:18 -0800 (PST) Received: from localhost ([::1]:56168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SRR-0001e7-3j for importer@patchew.org; Wed, 19 Feb 2020 11:43:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39161) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3r-0001sk-24 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3q-0004Uh-3I for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:32350 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3p-0004UV-Vj for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:54 -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-28-atkPe6bKOru6A9p1WmwxpA-1; Wed, 19 Feb 2020 11:18:49 -0500 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 5ACC61088385; Wed, 19 Feb 2020 16:18:48 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D529811F8; Wed, 19 Feb 2020 16:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129133; 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=4eemmDcoP3QvnFaPO/GnjcJxYo3rxsRY3nqc5CLtRTI=; b=FjsDRhqnF6VSjjz/ig8RnpOz0O2w8Mu/mnT7i7Yr0H/3MxUUVvuyAfkzSsEDkPOHRuYO/S VqGm3NBe6+KQFMhLMZ3wJoYKqsT7NklC/VABS7e/B00//YFlhE58HHY5d1y0qW2VIkqnRE eV1JqDvNb9KSzWmLSS32RjvbodTmuvg= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 06/13] migrate/ram: Discard new RAM when growing RAM blocks and the VM is stopped Date: Wed, 19 Feb 2020 17:17:18 +0100 Message-Id: <20200219161725.115218-7-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: atkPe6bKOru6A9p1WmwxpA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In case we grow our RAM after ram_postcopy_incoming_init() (e.g., when synchronizing the RAM block state with the migration source), the resized part would not get discarded. Let's perform that when being notified about a resize while postcopy has been advised and the guest is not running yet. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/ram.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 57f32011a3..cbd54947fb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3722,6 +3722,25 @@ static void ram_mig_ram_block_resized(RAMBlockNotifi= er *n, void *host, return; } =20 + /* + * Especially at the start of precopy on the migration target, before + * starting postcopy, we synchronize the RAM block sizes. Let's make s= ure + * that any resizes before starting the guest are properly handled by + * postcopy. Note: All other postcopy handling (e.g., registering hand= lers, + * disabling THP) happens after all resizes (e.g., during precopy) were + * performed. + */ + if (postcopy_is_advised() && !runstate_is_running()) { + /* Update what ram_postcopy_incoming_init()->init_range() does. */ + if (old_size < new_size) { + if (ram_discard_range(rb->idstr, old_size, new_size - old_size= )) { + error_report("RAM block '%s' discard of resized RAM failed= ", + rb->idstr); + } + } + return; + } + /* * Some resizes are triggered on the migration target by precopy code, * when synchronizing RAM block sizes. In these cases, the VM is not --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131274; cv=none; d=zohomail.com; s=zohoarc; b=Bnv6y/7Wi3RcXwn3sskhkHcVggWuArekSD70JCw8g0CmCXrcvn9L8gKZGgi5sQYyWbRg3e5japXngCrMIrrdfIovMK2GvAZLzquFc7jQQrRYk33d6b6HUa7XeQbPr6ncSbgOsqKayZl2+XJZxF++QiYiKXjTdmf1JTmKrF/wgwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131274; 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=NIbpoTPRIugC/AN/kKqRGy1bAH0u75EO9suDLoHM/2Q=; b=kmVDo96isF43W6O6ljr73jruJWSZ26tc6YbvctFQPHNnPgnbWR1OtPSfsmOqKI8pt9WCZGmP0rbC4HEWL2E+HX2DPH3wxXImJB8HmVf1lAGm7WJSAMnE56ZD0u3JxaMSDJ6JOKWVxBWyEnAGts+h9f/Nwrc+7DQFQThFh3jdqe4= 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 1582131274243287.5172762511992; Wed, 19 Feb 2020 08:54:34 -0800 (PST) Received: from localhost ([::1]:56470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4ScL-0001Ad-71 for importer@patchew.org; Wed, 19 Feb 2020 11:54:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39190) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3w-0001wd-6Y for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3u-0004WD-CH for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:59 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28755 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3t-0004VE-CL for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:58 -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-299-JoMmZ0zCMwWKVlXeSeCHBg-1; Wed, 19 Feb 2020 11:18:51 -0500 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 7AC858C8333; Wed, 19 Feb 2020 16:18:50 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB4B689F13; Wed, 19 Feb 2020 16:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129135; 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=NIbpoTPRIugC/AN/kKqRGy1bAH0u75EO9suDLoHM/2Q=; b=DQwBr8kltc01EN9sxSwraxmRIY9rLN9IdZS0h0oWRYwTmTCGDYJNsRheoYhji2DZxslenU k7Nfe57TzdRFyztm0hPH/fJhKhuGGOUFFGxk5pAOUtrcFO7pFv/5bqrZnlBmltYq+Szb3k WsywBOglY3MKRj/kw5wswgo8S+7v/Hs= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 07/13] migrate/ram: Get rid of "place_source" in ram_load_postcopy() Date: Wed, 19 Feb 2020 17:17:19 +0100 Message-Id: <20200219161725.115218-8-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: JoMmZ0zCMwWKVlXeSeCHBg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It's always the same value. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/ram.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index cbd54947fb..75014717f6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3119,7 +3119,6 @@ static int ram_load_postcopy(QEMUFile *f) ram_addr_t addr; void *host =3D NULL; void *page_buffer =3D NULL; - void *place_source =3D NULL; RAMBlock *block =3D NULL; uint8_t ch; int len; @@ -3188,7 +3187,6 @@ static int ram_load_postcopy(QEMUFile *f) place_needed =3D true; target_pages =3D 0; } - place_source =3D postcopy_host_page; } =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { @@ -3220,7 +3218,7 @@ static int ram_load_postcopy(QEMUFile *f) * buffer to make sure the buffer is valid when * placing the page. */ - qemu_get_buffer_in_place(f, (uint8_t **)&place_source, + qemu_get_buffer_in_place(f, (uint8_t **)&postcopy_host_pag= e, TARGET_PAGE_SIZE); } break; @@ -3265,8 +3263,8 @@ static int ram_load_postcopy(QEMUFile *f) ret =3D postcopy_place_page_zero(mis, place_dest, block); } else { - ret =3D postcopy_place_page(mis, place_dest, - place_source, block); + ret =3D postcopy_place_page(mis, place_dest, postcopy_host= _page, + block); } } } --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582130981; cv=none; d=zohomail.com; s=zohoarc; b=dbOJJfQxl1RZOcljxG5y8MVbciokBWw21rqjPYCo/HQKbWYmPUMoQ7yI26Ok5WOS6fOm8bpDq9RRLLIOmZ6dZvnG8wXxQg6kAjRq6VsBwm8gr5TYmccq/C/RixOdwWrYLChgYacf3Nga++p0tqE8K9IsdLNcaIK/wWOwt9w3l8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582130981; 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=rDj0rqRKbNwsakpSuBu9vsIVn5D5FKYcv2n7kjz126Y=; b=QHCD74cHq6OkEUeOtfLz1L2JJSghqMfgEutr3h/RbfB1J467HDDg4oYamJZSRJ4DjvLIXq7nRTymGUAYqSaWvW+K5jNOE9pQdy1DvqyTz6GD7RiX1uSRsca/qz/gY3gH9oyDJgd89N7di/D0hjG2e212QIwKuDGis4YAGM56HT4= 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 1582130981760655.6697371995273; Wed, 19 Feb 2020 08:49:41 -0800 (PST) Received: from localhost ([::1]:56320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SXc-0006qJ-M8 for importer@patchew.org; Wed, 19 Feb 2020 11:49:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39189) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3w-0001wc-6T for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3u-0004W8-C9 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:59 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40505 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3t-0004VL-Cd for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:18:58 -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-184-15J9vNFfONi61L6fE_p7JQ-1; Wed, 19 Feb 2020 11:18:53 -0500 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 95C7B18AB2F7; Wed, 19 Feb 2020 16:18:52 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBAF3811F8; Wed, 19 Feb 2020 16:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129135; 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=rDj0rqRKbNwsakpSuBu9vsIVn5D5FKYcv2n7kjz126Y=; b=KKV66SCA4wYn/LosBARLuZQrKW9MAf0j9anPDN6gZO7i66Y1tbDdWfGvAYa4ankiHXlViR qZwNKJPbFdf9d8cOcGjWEhCBONRq2BHLneaDiEjgM2fGa1Kt1rhO8L7mY+wfBQbD9j/u+G fmX4edkfBnOC/wUYtxIsEyQ1KOPO+KI= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 08/13] migrate/ram: Simplify host page handling in ram_load_postcopy() Date: Wed, 19 Feb 2020 17:17:20 +0100 Message-Id: <20200219161725.115218-9-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 15J9vNFfONi61L6fE_p7JQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add two new helper functions. This will in come handy once we want to handle ram block resizes while postcopy is active. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/ram.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 75014717f6..80a4e4a9ea 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2734,6 +2734,20 @@ static inline void *host_from_ram_block_offset(RAMBl= ock *block, return block->host + offset; } =20 +static void *host_page_from_ram_block_offset(RAMBlock *block, + ram_addr_t offset) +{ + /* Note: Explicitly no check against offset_in_ramblock(). */ + return (void *)QEMU_ALIGN_DOWN((uintptr_t)block->host + offset, + block->page_size); +} + +static ram_addr_t host_page_offset_from_ram_block_offset(RAMBlock *block, + ram_addr_t offset) +{ + return ((uintptr_t)block->host + offset) & (block->page_size - 1); +} + static inline void *colo_cache_from_block_offset(RAMBlock *block, ram_addr_t offset) { @@ -3111,13 +3125,12 @@ static int ram_load_postcopy(QEMUFile *f) MigrationIncomingState *mis =3D migration_incoming_get_current(); /* Temporary page that is later 'placed' */ void *postcopy_host_page =3D mis->postcopy_tmp_page; - void *this_host =3D NULL; + void *host_page =3D NULL; bool all_zero =3D false; int target_pages =3D 0; =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr; - void *host =3D NULL; void *page_buffer =3D NULL; RAMBlock *block =3D NULL; uint8_t ch; @@ -3142,9 +3155,12 @@ static int ram_load_postcopy(QEMUFile *f) if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { block =3D ram_block_from_stream(f, flags); + if (!block) { + ret =3D -EINVAL; + break; + } =20 - host =3D host_from_ram_block_offset(block, addr); - if (!host) { + if (!offset_in_ramblock(block, addr)) { error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); ret =3D -EINVAL; break; @@ -3162,21 +3178,18 @@ static int ram_load_postcopy(QEMUFile *f) * of a host page in one chunk. */ page_buffer =3D postcopy_host_page + - ((uintptr_t)host & (block->page_size - 1)); + host_page_offset_from_ram_block_offset(block, ad= dr); /* If all TP are zero then we can optimise the place */ if (target_pages =3D=3D 1) { all_zero =3D true; - this_host =3D (void *)QEMU_ALIGN_DOWN((uintptr_t)host, - block->page_size); - } else { + host_page =3D host_page_from_ram_block_offset(block, addr); + } else if (host_page !=3D host_page_from_ram_block_offset(bloc= k, + addr))= { /* not the 1st TP within the HP */ - if (QEMU_ALIGN_DOWN((uintptr_t)host, block->page_size) != =3D - (uintptr_t)this_host) { - error_report("Non-same host page %p/%p", - host, this_host); - ret =3D -EINVAL; - break; - } + error_report("Non-same host page %p/%p", host_page, + host_page_from_ram_block_offset(block, addr)); + ret =3D -EINVAL; + break; } =20 /* @@ -3255,15 +3268,10 @@ static int ram_load_postcopy(QEMUFile *f) } =20 if (!ret && place_needed) { - /* This gets called at the last target page in the host page */ - void *place_dest =3D (void *)QEMU_ALIGN_DOWN((uintptr_t)host, - block->page_size); - if (all_zero) { - ret =3D postcopy_place_page_zero(mis, place_dest, - block); + ret =3D postcopy_place_page_zero(mis, host_page, block); } else { - ret =3D postcopy_place_page(mis, place_dest, postcopy_host= _page, + ret =3D postcopy_place_page(mis, host_page, postcopy_host_= page, block); } } --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131355; cv=none; d=zohomail.com; s=zohoarc; b=NWCBiAOeisjyqF1zvNZCSZmqqe6KYdyncrFhy+tpjjBJ/GIixgySUlahzURnht03qH8+pHTd7wf1uMj/zN/plrxTyLhoZBsyzl573adqcfaIwJh7I4Z7k3avQ0IUmZicU/2t708ROv5w1+oNVzQf4shHX/CXSXndeznfvWC2XEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131355; 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=YZ/wGCtgh7Hvp5+b2Eld1rQrfaDOLbdsxZ+G2+/+Eew=; b=T8zgB7M6BoUviTR9m+hYxlqETLLPZlhLEhDMSOwZs7qJiweJrFLqjii2YHRarx1NBSx2lP7e9EfxvW5fuIYADjq0/9srzTRqifFQ9/mHr/W77+xdybUVljJTOwJeIgnEqDiGwgMSF+rTKDPtmROMuhOQy1oQn4XEFI2qeVrenOg= 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 1582131355919447.91074519674567; Wed, 19 Feb 2020 08:55:55 -0800 (PST) Received: from localhost ([::1]:56504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4Sde-0004Ry-Tj for importer@patchew.org; Wed, 19 Feb 2020 11:55:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39212) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S3x-00020l-Ql for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S3w-0004Wy-8P for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:01 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37540 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S3w-0004WS-4A for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:00 -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-270-WM12KYrjPC2AXQa484ElbA-1; Wed, 19 Feb 2020 11:18:55 -0500 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 B4E80801F96; Wed, 19 Feb 2020 16:18:54 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6066811F8; Wed, 19 Feb 2020 16:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129139; 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=YZ/wGCtgh7Hvp5+b2Eld1rQrfaDOLbdsxZ+G2+/+Eew=; b=M/SDG44ZYKWMFu+7XzZgt+nQc9i6dIZ0cHFDxCzhS+OKkmKlj+32lM8apkdv5Jrc3oWH5j +lapw03yyvHdLjpr70EMSKI/7/lR3yBt2DXZXKiJH9AgLmHbaJdXD/oFYp3dsYEmy+jpzG M0PV1flkHGd0xZybuerfwiEF3oxJ+N8= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 09/13] migrate/ram: Consolidate variable reset after placement in ram_load_postcopy() Date: Wed, 19 Feb 2020 17:17:21 +0100 Message-Id: <20200219161725.115218-10-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: WM12KYrjPC2AXQa484ElbA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's consolidate resetting the variables. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/ram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 80a4e4a9ea..ab1f5534cf 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3126,7 +3126,7 @@ static int ram_load_postcopy(QEMUFile *f) /* Temporary page that is later 'placed' */ void *postcopy_host_page =3D mis->postcopy_tmp_page; void *host_page =3D NULL; - bool all_zero =3D false; + bool all_zero =3D true; int target_pages =3D 0; =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { @@ -3151,7 +3151,6 @@ static int ram_load_postcopy(QEMUFile *f) addr &=3D TARGET_PAGE_MASK; =20 trace_ram_load_postcopy_loop((uint64_t)addr, flags); - place_needed =3D false; if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { block =3D ram_block_from_stream(f, flags); @@ -3179,9 +3178,7 @@ static int ram_load_postcopy(QEMUFile *f) */ page_buffer =3D postcopy_host_page + host_page_offset_from_ram_block_offset(block, ad= dr); - /* If all TP are zero then we can optimise the place */ if (target_pages =3D=3D 1) { - all_zero =3D true; host_page =3D host_page_from_ram_block_offset(block, addr); } else if (host_page !=3D host_page_from_ram_block_offset(bloc= k, addr))= { @@ -3198,7 +3195,6 @@ static int ram_load_postcopy(QEMUFile *f) */ if (target_pages =3D=3D (block->page_size / TARGET_PAGE_SIZE))= { place_needed =3D true; - target_pages =3D 0; } } =20 @@ -3274,6 +3270,10 @@ static int ram_load_postcopy(QEMUFile *f) ret =3D postcopy_place_page(mis, host_page, postcopy_host_= page, block); } + place_needed =3D false; + target_pages =3D 0; + /* Assume we have a zero page until we detect something differ= ent */ + all_zero =3D true; } } =20 --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131077; cv=none; d=zohomail.com; s=zohoarc; b=i8eIkzQbzHYMZXXZhElEaHwabFLL5oxZmV0oLCtQAHjan5gP3TQI5M0WYbdzYY6WdSfv8AZoB0L9ZzSwunqzvoFUqTIqAAlndyY2jpSUFRt3U9W2Bzna1DijoMG9NN8s3MKY5dm4PoDOoaEwiS9FBn5RsXXiZkbr0cTRDVbRvC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131077; 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=yPC5Hy+VE7F399uarscyVDDSRm1XhDzk8oLkrBH0Wrw=; b=Y565nCtGWkPEMs+9DIvYZIEx6kasLroeMhmi8ySmjzUK+tM+hCzj55NG89JLrXqfJ+YMjWdRpg+yBd5Wx+OmL2oEo8i4wHEKda42UXgdPhjK0V3hkI27WIJ2agTzpAZJG2K6HTJX+RKOt/WqRpSCTuCouXwB1PNZ+I4wtevnln8= 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 1582131077011447.2598988561032; Wed, 19 Feb 2020 08:51:17 -0800 (PST) Received: from localhost ([::1]:56370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SZ9-0002HP-UE for importer@patchew.org; Wed, 19 Feb 2020 11:51:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39242) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S47-0002GN-RH for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S46-0004ZT-8z for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43257 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S46-0004ZH-4r for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:10 -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-303-g072Y3JwNQ-2JeXy2Qqkvg-1; Wed, 19 Feb 2020 11:19:06 -0500 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 3F30595BBA; Wed, 19 Feb 2020 16:19:05 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 128B78AC45; Wed, 19 Feb 2020 16:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129149; 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=yPC5Hy+VE7F399uarscyVDDSRm1XhDzk8oLkrBH0Wrw=; b=YCR8u08hFvuIa4F/1mLNbckznYtO7TFk3PjXmzrFczRvotQTMSeD1FNH20Z36aCwLuHzU7 Qxkgmc/3VFIvMP5b2Tl2CJOQ5KMMJVIJ8ZH+vIViVFH5TaOfN6BEr/eU/qHf8moNVOkQxG lvM26rVSqVo6z0b8iUzOnVZacpk9B4o= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 10/13] migrate/ram: Handle RAM block resizes during postcopy Date: Wed, 19 Feb 2020 17:17:22 +0100 Message-Id: <20200219161725.115218-11-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: g072Y3JwNQ-2JeXy2Qqkvg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , Richard Henderson , "Dr . David Alan Gilbert" , Peter Xu , "Michael S. Tsirkin" , Shannon Zhao , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Resizing while migrating is dangerous and does not work as expected. The whole migration code works on the usable_length of ram blocks and does not expect this to change at random points in time. In the case of postcopy, relying on used_length is racy as soon as the guest is running. Also, when used_length changes we might leave the uffd handler registered for some memory regions, reject valid pages when migrating and fail when sending the recv bitmap to the source. Resizing can be trigger *after* (but not during) a reset in ACPI code by the guest - hw/arm/virt-acpi-build.c:acpi_ram_update() - hw/i386/acpi-build.c:acpi_ram_update() Let's remember the original used_length in a separate variable and use it in relevant postcopy code. Make sure to update it when we resize during precopy, when synchronizing the RAM block sizes with the source. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Eduardo Habkost Cc: Paolo Bonzini Cc: Igor Mammedov Cc: "Michael S. Tsirkin" Cc: Richard Henderson Cc: Shannon Zhao Cc: Alex Benn=C3=A9e Cc: Peter Xu Signed-off-by: David Hildenbrand --- include/exec/ramblock.h | 9 +++++++++ migration/postcopy-ram.c | 15 ++++++++++++--- migration/ram.c | 11 +++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 07d50864d8..0e9e9b346b 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -59,6 +59,15 @@ struct RAMBlock { */ unsigned long *clear_bmap; uint8_t clear_bmap_shift; + + /* + * RAM block used_length before the guest started running while postco= py + * was active. Once the guest is running, used_length can change. Used= to + * register/unregister uffd handlers and as the size of the recv bitma= p. + * Receiving any page beyond this length will bail out, as it could no= t have + * been valid on the source. + */ + ram_addr_t postcopy_length; }; #endif #endif diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a36402722b..c68caf4e42 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -17,6 +17,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/rcu.h" #include "exec/target_page.h" #include "migration.h" #include "qemu-file.h" @@ -31,6 +32,7 @@ #include "qemu/error-report.h" #include "trace.h" #include "hw/boards.h" +#include "exec/ramblock.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -456,6 +458,13 @@ static int init_range(RAMBlock *rb, void *opaque) ram_addr_t length =3D qemu_ram_get_used_length(rb); trace_postcopy_init_range(block_name, host_addr, offset, length); =20 + /* + * Save the used_length before running the guest. In case we have to + * resize RAM blocks when syncing RAM block sizes from the source duri= ng + * precopy, we'll update it manually via the ram block notifier. + */ + rb->postcopy_length =3D length; + /* * We need the whole of RAM to be truly empty for postcopy, so things * like ROMs and any data tables built during init must be zero'd @@ -478,7 +487,7 @@ static int cleanup_range(RAMBlock *rb, void *opaque) const char *block_name =3D qemu_ram_get_idstr(rb); void *host_addr =3D qemu_ram_get_host_addr(rb); ram_addr_t offset =3D qemu_ram_get_offset(rb); - ram_addr_t length =3D qemu_ram_get_used_length(rb); + ram_addr_t length =3D rb->postcopy_length; MigrationIncomingState *mis =3D opaque; struct uffdio_range range_struct; trace_postcopy_cleanup_range(block_name, host_addr, offset, length); @@ -600,7 +609,7 @@ static int nhp_range(RAMBlock *rb, void *opaque) const char *block_name =3D qemu_ram_get_idstr(rb); void *host_addr =3D qemu_ram_get_host_addr(rb); ram_addr_t offset =3D qemu_ram_get_offset(rb); - ram_addr_t length =3D qemu_ram_get_used_length(rb); + ram_addr_t length =3D rb->postcopy_length; trace_postcopy_nhp_range(block_name, host_addr, offset, length); =20 /* @@ -644,7 +653,7 @@ static int ram_block_enable_notify(RAMBlock *rb, void *= opaque) struct uffdio_register reg_struct; =20 reg_struct.range.start =3D (uintptr_t)qemu_ram_get_host_addr(rb); - reg_struct.range.len =3D qemu_ram_get_used_length(rb); + reg_struct.range.len =3D rb->postcopy_length; reg_struct.mode =3D UFFDIO_REGISTER_MODE_MISSING; =20 /* Now tell our userfault_fd that it's responsible for this area */ diff --git a/migration/ram.c b/migration/ram.c index ab1f5534cf..6d1dcb362c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -244,7 +244,7 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file, return -1; } =20 - nbits =3D block->used_length >> TARGET_PAGE_BITS; + nbits =3D block->postcopy_length >> TARGET_PAGE_BITS; =20 /* * Make sure the tmp bitmap buffer is big enough, e.g., on 32bit @@ -3159,7 +3159,13 @@ static int ram_load_postcopy(QEMUFile *f) break; } =20 - if (!offset_in_ramblock(block, addr)) { + /* + * Relying on used_length is racy and can result in false posi= tives. + * We might place pages beyond used_length in case RAM was shr= unk + * while in postcopy, which is fine - trying to place via + * UFFDIO_COPY/UFFDIO_ZEROPAGE will never segfault. + */ + if (!block->host || addr >=3D block->postcopy_length) { error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); ret =3D -EINVAL; break; @@ -3744,6 +3750,7 @@ static void ram_mig_ram_block_resized(RAMBlockNotifie= r *n, void *host, rb->idstr); } } + rb->postcopy_length =3D new_size; return; } =20 --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131521; cv=none; d=zohomail.com; s=zohoarc; b=ef1R/eaKf67MoZdYfOfazMzldV5bn/IpDuztmlsjoylgJpEBJ0OvNAvmh/XNUN4XJywsA9f3YruY7elRixtRNt3IAWXhg3Xh4demre+mPNy+bNpWw7QN2YcGOOFcrjk5mui9xxQGZgrY8/hLlf9/dwrBTX4Lwhv6J5zlQe9cMSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131521; 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=w/z7m5Qm4HaPOtKr9rMP0YxTInrel2WDYqHS0dY6eVE=; b=kfSHd7qra8G1oulVK6yWxt598iG8k6woiwhUH4vraWTcURH3tcYDbKd6KwgGsJJZeHakwYmpS8vTB+oRUbDPpj3JRVGK2jbBuDCsPGJuQ+oV56fXYz1jfZGM57OkonW2qjh/oZqJ5UfEuak6ueEAbfnJ/cP0Oj7Hss2KchN0r8I= 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 1582131521702325.5483097030991; Wed, 19 Feb 2020 08:58:41 -0800 (PST) Received: from localhost ([::1]:56566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SgK-0001G0-MP for importer@patchew.org; Wed, 19 Feb 2020 11:58:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39257) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S49-0002Jr-4e for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S48-0004aC-2z for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:13 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45773 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S47-0004Zw-VJ for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:12 -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-147-iIbflT23OTW15pMSxMlYGQ-1; Wed, 19 Feb 2020 11:19:08 -0500 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 5DCDC8024F0; Wed, 19 Feb 2020 16:19:07 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91D15811F8; Wed, 19 Feb 2020 16:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129151; 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=w/z7m5Qm4HaPOtKr9rMP0YxTInrel2WDYqHS0dY6eVE=; b=jIZRhnb9YP1kTaRlI1NDXKRvoKaM6aIHvk5ilA/ZUoR1aEEsFq7iSZ/1GYsLm1SnVGDRXj 9YsW1C9z/d1q1i8tJZ0dQY/mU+zCk4OdpaCN6e8tiGUzfwaoO2WU3MJNbwTQMqhljCS+q+ 0UbsZYPU/yUJh5ME+sFHrtB/jNnPYKo= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 11/13] migrate/multifd: Print used_length of memory block Date: Wed, 19 Feb 2020 17:17:23 +0100 Message-Id: <20200219161725.115218-12-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: iIbflT23OTW15pMSxMlYGQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We actually want to print the used_length, against which we check. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/multifd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/multifd.c b/migration/multifd.c index b3e8ae9bcc..dd9e88c5f1 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -222,7 +222,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) if (offset > (block->used_length - qemu_target_page_size())) { error_setg(errp, "multifd: offset too long %" PRIu64 " (max " RAM_ADDR_FMT ")", - offset, block->max_length); + offset, block->used_length); return -1; } p->pages->iov[i].iov_base =3D block->host + offset; --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131173; cv=none; d=zohomail.com; s=zohoarc; b=BU8kkxSolnIX0hXo92+8ktpFI9DZPYg/Unx3U9m8s8uPbpmiyTD/sIeUJBjvInqjQIfku3msLgKf08MOIbNMTvygkqZPRi7MNz4KPpOV1xOFpdcGO6Sl370KcQXIH70JgIMbxN0IYqkK+7LxXlu+XAk7iDrNsS5i2inJeU4J77Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131173; 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=LRZMmaOFT+YLkw4fQRIK/kcLZ/z8kwYDIvkYZGH+oZ4=; b=JnbP8e+KVWdW4vg514Q6jIRPT9wt1R2UyoPEBv6/6iL+lH7a2D+1pOEcFJrNEodgLUodaxESkEs9A9c2xG6Il/ChdOR35q8DqVvUqNeVKRPAqyWDwRvtT6asYuG2PhHX41rGj1TnjAMKzY8YfHv77RsKCwiEHYuB2eQlx+ydsus= 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 158213117367581.57806676897485; Wed, 19 Feb 2020 08:52:53 -0800 (PST) Received: from localhost ([::1]:56400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4Sai-0005i2-KP for importer@patchew.org; Wed, 19 Feb 2020 11:52:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39277) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S4C-0002QT-Mu for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S4B-0004bZ-NP for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:16 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:47161 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S4B-0004bK-Jo for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:15 -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-328-bkErZ9HwP1e2veukG39ceg-1; Wed, 19 Feb 2020 11:19:10 -0500 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 7A7D195BBE; Wed, 19 Feb 2020 16:19:09 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id B016B811F8; Wed, 19 Feb 2020 16:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129155; 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=LRZMmaOFT+YLkw4fQRIK/kcLZ/z8kwYDIvkYZGH+oZ4=; b=MYWbkq5yUehVc5FGbWV7WR726bWk72zMp6tx5HUC/Wdyqvms7/7tBfQAbLnr4vnc6VZxSM v50j0e++a6DdIXvFBFbJXXRGqBdiwEnW0GFzZailiM7Bd+X5r0cEDBjIVVdx6UvSOhOSrM S6XDKMKmjWRahGO3mdDIuoKHJMQcBJc= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 12/13] migrate/ram: Use offset_in_ramblock() in range checks Date: Wed, 19 Feb 2020 17:17:24 +0100 Message-Id: <20200219161725.115218-13-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: bkErZ9HwP1e2veukG39ceg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We never read or write beyond the used_length of memory blocks when migrating. Make this clearer by using offset_in_ramblock() consistently. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Signed-off-by: David Hildenbrand --- migration/ram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 6d1dcb362c..891dcd687a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1309,8 +1309,8 @@ static bool find_dirty_block(RAMState *rs, PageSearch= Status *pss, bool *again) *again =3D false; return false; } - if ((((ram_addr_t)pss->page) << TARGET_PAGE_BITS) - >=3D pss->block->used_length) { + if (!offset_in_ramblock(pss->block, + ((ram_addr_t)pss->page) << TARGET_PAGE_BITS)) { /* Didn't find anything in this RAM Block */ pss->page =3D 0; pss->block =3D QLIST_NEXT_RCU(pss->block, next); @@ -1514,7 +1514,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) rs->last_req_rb =3D ramblock; } trace_ram_save_queue_pages(ramblock->idstr, start, len); - if (start+len > ramblock->used_length) { + if (!offset_in_ramblock(ramblock, start + len - 1)) { error_report("%s request overrun start=3D" RAM_ADDR_FMT " len=3D" RAM_ADDR_FMT " blocklen=3D" RAM_ADDR_FMT, __func__, start, len, ramblock->used_length); @@ -3323,8 +3323,8 @@ static void colo_flush_ram_cache(void) while (block) { offset =3D migration_bitmap_find_dirty(ram_state, block, offse= t); =20 - if (((ram_addr_t)offset) << TARGET_PAGE_BITS - >=3D block->used_length) { + if (!offset_in_ramblock(block, + ((ram_addr_t)offset) << TARGET_PAGE_BI= TS)) { offset =3D 0; block =3D QLIST_NEXT_RCU(block, next); } else { --=20 2.24.1 From nobody Fri May 3 22:27:16 2024 Delivered-To: importer@patchew.org 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; 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=1582131454; cv=none; d=zohomail.com; s=zohoarc; b=Ta3Dk9wIivSKgKnJhPlSLtoGIAkWg+VX+16DhA//l2OrMmVdF5XwdPiZzqKJPXpuoKKcEVJcLpkt3yB/Q0JOB6YUzVnjvFwYch/K/EjGyMC/54Tc92N01SEN5fXWE8ANIBxJgE6Jb1z4UfrhQf5eQHM7iptihjhj1o/Z5NAIfPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582131454; 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=RYUPpy9WR4gX9r+idlmlab2lhjNaErepqbjyGHIWibo=; b=Qns7rfrMxKDpeskWYnwb/OgpNGma+IQ8Oz0uzIqtpR4/pfg18bTxW0BPPytQaynXMvqNwxszNUr8/GCK1dybOwVu13RUrssmIDUV6YKL5y9QIFzO1v9+b6tDlwSb1EhEh2rTZNY99KxkbgO925n0wX6hE8bZztBdgATlTmtBqDU= 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 1582131454710621.6296983049052; Wed, 19 Feb 2020 08:57:34 -0800 (PST) Received: from localhost ([::1]:56544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SfF-0007kf-IF for importer@patchew.org; Wed, 19 Feb 2020 11:57:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39275) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4S4C-0002QE-KX for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4S4B-0004bO-AI for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:16 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38172 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4S4B-0004bC-5j for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:19:15 -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-155-i8EiePW9Pny-NPyjic8OoQ-1; Wed, 19 Feb 2020 11:19:12 -0500 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 C11271022F89; Wed, 19 Feb 2020 16:19:11 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-151.ams2.redhat.com [10.36.116.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE19811F8; Wed, 19 Feb 2020 16:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582129154; 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=RYUPpy9WR4gX9r+idlmlab2lhjNaErepqbjyGHIWibo=; b=NkKCd1+AzgwZutL5iqqdYcyOIVw9nHLdh334cqYHkzcPwvXEoeHBoheb+3lk+3mh7M6gvm gOL50tMDgbbs+oF7SGj4YCqJ4hSMhbW02KYSuNdi+kfsYDMCCxo/IR007SBfc52L2RUZYf TGweDRHtMiDjbG/fxxj3a5L1Kx0jBYQ= From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1 13/13] migrate/ram: Tolerate partially changed mappings in postcopy code Date: Wed, 19 Feb 2020 17:17:25 +0100 Message-Id: <20200219161725.115218-14-david@redhat.com> In-Reply-To: <20200219161725.115218-1-david@redhat.com> References: <20200219161725.115218-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: i8EiePW9Pny-NPyjic8OoQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Andrea Arcangeli , Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When we partially change mappings (e.g., mmap over parts of an existing mmap) where we have a userfaultfd handler registered, the handler will implicitly be unregistered from the parts that changed. This is e.g., the case when doing a qemu_ram_remap(), but is also a preparation for RAM blocks with resizable allocations and we're shrinking RAM blocks. When the mapping is changed and the handler is removed, any waiters are woken up. Trying to place pages will fail. We can simply ignore erors due to that when placing pages - as the mapping changed on the migration destination, also the content is stale. E.g., after shrinking a RAM block, nobody should be using that memory. After doing a qemu_ram_remap(), the old memory is expected to have vanished. Let's tolerate such errors (but still warn for now) when placing pages. Also, add a comment why unregistering will continue to work even though the mapping might have changed. Cc: "Dr. David Alan Gilbert" Cc: Juan Quintela Cc: Peter Xu Cc: Andrea Arcangeli Signed-off-by: David Hildenbrand --- migration/postcopy-ram.c | 43 ++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index c68caf4e42..df9d27c004 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -506,6 +506,13 @@ static int cleanup_range(RAMBlock *rb, void *opaque) range_struct.start =3D (uintptr_t)host_addr; range_struct.len =3D length; =20 + /* + * In case the mapping was partially changed since we enabled userfault + * (esp. when whrinking RAM blocks and we have resizable allocations, = or + * via qemu_ram_remap()), the userfaultfd handler was already removed = for + * the mappings that changed. Unregistering will, however, still work = and + * ignore mappings without a registered handler. + */ if (ioctl(mis->userfault_fd, UFFDIO_UNREGISTER, &range_struct)) { error_report("%s: userfault unregister %s", __func__, strerror(err= no)); =20 @@ -1239,10 +1246,28 @@ int postcopy_place_page(MigrationIncomingState *mis= , void *host, void *from, */ if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize, rb)) { int e =3D errno; - error_report("%s: %s copy host: %p from: %p (size: %zd)", - __func__, strerror(e), host, from, pagesize); =20 - return -e; + /* + * When the mapping gets partially changed before we try to place = a page + * (esp. when whrinking RAM blocks and we have resizable allocatio= ns, or + * via qemu_ram_remap()), the userfaultfd handler will be removed = and + * placing pages will fail. In that case, any waiter was already w= oken + * up when the mapping was changed. We can safely ignore this, as + * mappings that change once we're running on the destination imply + * that memory of these mappings vanishes. Let's still print a war= ning + * for now. + * + * Old kernels report EINVAL, new kernels report ENOENT. + */ + if (e =3D=3D ENOENT || e =3D=3D EINVAL) { + warn_report("%s: %s copy host: %p from: %p (size: %zd)", + __func__, strerror(e), host, from, pagesize); + } else { + error_report("%s: %s copy host: %p from: %p (size: %zd)", + __func__, strerror(e), host, from, pagesize); + + return -e; + } } =20 trace_postcopy_place_page(host); @@ -1266,10 +1291,16 @@ int postcopy_place_page_zero(MigrationIncomingState= *mis, void *host, if (qemu_ram_is_uf_zeroable(rb)) { if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, pagesize, r= b)) { int e =3D errno; - error_report("%s: %s zero host: %p", - __func__, strerror(e), host); =20 - return -e; + /* See the comment in postcopy_place_page() */ + if (e =3D=3D ENOENT || e =3D=3D EINVAL) { + warn_report("%s: %s zero host: %p", __func__, strerror(e), + host); + } else { + error_report("%s: %s zero host: %p", __func__, strerror(e), + host); + return -e; + } } return postcopy_notify_shared_wake(rb, qemu_ram_block_host_offset(rb, --=20 2.24.1