From nobody Fri May 3 12:51:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593165247; cv=none; d=zohomail.com; s=zohoarc; b=cWQwrDF4NMKz3x5JEpoiiH52JZRAnk6n2Mqsay9sL9d8QrdIvE71XRRWeWdpRLdXkUk54APw8VYzByQO1mBzTz/0zGGsLNn3w4DP8N+9rJ+oBN9xczXxcdkYElt0r3qs135ktb0fVU9uSwvjz2D0mLl5s5wgKGcHlNEv9jOSYw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593165247; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9xdvHRQQH7lSMRbjh6rkU4YFq+r5z8TpLPwjrfJ+Nok=; b=KfFQjheIJtsIx69TeSHEtLTl22Wpz7vqRB8gVSOs1ddeRo4dCeQCeY49sMTiMwn28EY/sBzOqymRmk0K2dxxNnjl5VJycxoSrNkHyOV1Gjud0TrqSxExH2qaB6pPve9Qi9zbXe65U7upWqS7pdJ7vSwez8fDEXxdsPZPWxPkT38= 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 1593165247643297.0228842649818; Fri, 26 Jun 2020 02:54:07 -0700 (PDT) Received: from localhost ([::1]:50202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jol3d-0000kE-QQ for importer@patchew.org; Fri, 26 Jun 2020 05:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jol34-0000Gq-C5 for qemu-devel@nongnu.org; Fri, 26 Jun 2020 05:53:30 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:38608 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jol31-0001vY-PX for qemu-devel@nongnu.org; Fri, 26 Jun 2020 05:53:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-E9XeU4WfMN62uMx87OJDAw-1; Fri, 26 Jun 2020 05:53:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5601800D5C; Fri, 26 Jun 2020 09:53:21 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-35.ams2.redhat.com [10.36.113.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FC7560C1D; Fri, 26 Jun 2020 09:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593165205; 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; bh=9xdvHRQQH7lSMRbjh6rkU4YFq+r5z8TpLPwjrfJ+Nok=; b=iZSZm7IfNsQ96sMmTixYHUq7cM4tLzFnHXpld5TlPY8m4O0rHw5SYrODDt2g1gKu+9HTBs 2UxqRpJDXXOF/Ohtm+oKZI8hKiGKJl8f/nqQnXa5djWzTs/nzTgDLUxeVt4Nvgm0pABvRT vdEVSIztFeIkjsgQQxLIMcXaue2GP4c= X-MC-Unique: E9XeU4WfMN62uMx87OJDAw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1] virtio-balloon: always indicate S_DONE when migration fails Date: Fri, 26 Jun 2020 11:53:14 +0200 Message-Id: <20200626095314.411380-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=david@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/26 03:23:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, Wei Wang , David Hildenbrand , Alexander Duyck , "Michael S . Tsirkin" 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" If something goes wrong during precopy, before stopping the VM, we will never send a S_DONE indication to the VM, resulting in the hinted pages not getting released to be used by the guest OS (e.g., Linux). Easy to reproduce: 1. Start migration (e.g., HMP "migrate -d 'exec:gzip -c > STATEFILE.gz'") 2. Cancel migration (e.g., HMP "migrate_cancel") 3. Oberve in the guest (e.g., cat /proc/meminfo) that there is basically no free memory left. While at it, add similar locking to virtio_balloon_free_page_done() as done in virtio_balloon_free_page_stop. Locking is still weird, but that has to be sorted out separately. There is nothing to do in the PRECOPY_NOTIFY_COMPLETE case. Add some comments regarding S_DONE handling. Fixes: c13c4153f76d ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT") Cc: Wei Wang Cc: Alexander Duyck Signed-off-by: David Hildenbrand --- hw/virtio/virtio-balloon.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 10507b2a43..13ba208694 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -628,8 +628,13 @@ static void virtio_balloon_free_page_done(VirtIOBalloo= n *s) { VirtIODevice *vdev =3D VIRTIO_DEVICE(s); =20 - s->free_page_report_status =3D FREE_PAGE_REPORT_S_DONE; - virtio_notify_config(vdev); + if (s->free_page_report_status !=3D FREE_PAGE_REPORT_S_DONE) { + /* See virtio_balloon_free_page_stop() */ + qemu_mutex_lock(&s->free_page_lock); + s->free_page_report_status =3D FREE_PAGE_REPORT_S_DONE; + qemu_mutex_unlock(&s->free_page_lock); + virtio_notify_config(vdev); + } } =20 static int @@ -653,8 +658,6 @@ virtio_balloon_free_page_report_notify(NotifierWithRetu= rn *n, void *data) case PRECOPY_NOTIFY_SETUP: precopy_enable_free_page_optimization(); break; - case PRECOPY_NOTIFY_COMPLETE: - case PRECOPY_NOTIFY_CLEANUP: case PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC: virtio_balloon_free_page_stop(dev); break; @@ -662,9 +665,22 @@ virtio_balloon_free_page_report_notify(NotifierWithRet= urn *n, void *data) if (vdev->vm_running) { virtio_balloon_free_page_start(dev); } else { + /* + * Set S_DONE before migrating the vmstate, so the guest will = reuse + * all hinted pages once running on the destination. + */ virtio_balloon_free_page_done(dev); } break; + case PRECOPY_NOTIFY_CLEANUP: + /* + * Especially, if something goes wrong during precopy or if migrat= ion + * is canceled, we have to properly communicate S_DONE to the VM. + */ + virtio_balloon_free_page_done(dev); + break; + case PRECOPY_NOTIFY_COMPLETE: + break; default: virtio_error(vdev, "%s: %d reason unknown", __func__, pnd->reason); } --=20 2.26.2