From nobody Sat May 18 12:12:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1602089620; cv=none; d=zohomail.com; s=zohoarc; b=MXMXhnIkZ5TvX5vhcOKJrXk6jPfey5vKY/cqNuaBPrETTOI5xv3YjA6zWjZLTW3HzJUgSQ/qa2YUDqmatmc/4O4lZiA1na7BP0u6cd+rBw5ATnZLuVKm86W3zktN2ONUC1Brrh59FtpdT2ls3gO0hI3/Rz8PSoQoz4TPzY16vV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602089620; 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=E/MoZqt6L6sAuOWHobU50Ahl9ZN3cmt9yU1hCDRDBt8=; b=YloyTOrsVUShMPA8xTp1t5xrMShyblsa0Sb8HOVaun8eru4P1fTXrdY5c9eiJA6w5I7YRsgNZwbhwDS5v6+JFcFuGTexrlnnYdRE1PJdOQ3w3rg/m7gBm+UouTj+UD/1ThnE1yriSlexsc7IHbidpot9FZb5wBKoPqtQfv4PLn8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602089620463973.5955100290049; Wed, 7 Oct 2020 09:53:40 -0700 (PDT) Received: from localhost ([::1]:40774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQCh8-0005a2-UM for importer@patchew.org; Wed, 07 Oct 2020 12:53:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQCL5-0002ht-No for qemu-devel@nongnu.org; Wed, 07 Oct 2020 12:30:52 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:53408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQCL3-0006tX-IC for qemu-devel@nongnu.org; Wed, 07 Oct 2020 12:30:51 -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-567-woNdAhJrNJaB4jyVptT_Dw-1; Wed, 07 Oct 2020 12:30:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B77681F002; Wed, 7 Oct 2020 16:30:44 +0000 (UTC) Received: from bahia.lan (ovpn-114-178.ams2.redhat.com [10.36.114.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22182756A8; Wed, 7 Oct 2020 16:30:34 +0000 (UTC) X-MC-Unique: woNdAhJrNJaB4jyVptT_Dw-1 Subject: [PATCH] vhost: Don't special case vq->used_phys in vhost_get_log_size() From: Greg Kurz To: "Michael S. Tsirkin" , Jason Wang Date: Wed, 07 Oct 2020 18:30:34 +0200 Message-ID: <160208823418.29027.15172801181796272300.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 12:30:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The first loop in vhost_get_log_size() computes the size of the dirty log bitmap so that it allows to track changes in the entire guest memory, in terms of GPA. When not using a vIOMMU, the address of the vring's used structure, vq->used_phys, is a GPA. It is thus already covered by the first loop. When using a vIOMMU, vq->used_phys is a GIOVA that will be translated to an HVA when the vhost backend needs to update the used structure. It will log the corresponding GPAs into the bitmap but it certainly won't log the GIOVA. So in any case, vq->used_phys shouldn't be explicitly used to size the bitmap. Drop the second loop. This fixes a crash of the source when migrating a guest using in-kernel vhost-net and iommu_platform=3Don on POWER, because DMA regions are put over 0x800000000000000ULL. The resulting insanely huge log size causes g_malloc0() to abort. BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1879349 Signed-off-by: Greg Kurz Acked-by: Jason Wang --- This supersedes "vhost: Ignore vrings in dirty log when using a vIOMMU" http://patchwork.ozlabs.org/project/qemu-devel/patch/160105498386.68108.214= 5229309875282336.stgit@bahia.lan/ --- hw/virtio/vhost.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 011951625442..c02b658b597f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -172,16 +172,6 @@ static uint64_t vhost_get_log_size(struct vhost_dev *d= ev) reg->memory_size); log_size =3D MAX(log_size, last / VHOST_LOG_CHUNK + 1); } - for (i =3D 0; i < dev->nvqs; ++i) { - struct vhost_virtqueue *vq =3D dev->vqs + i; - - if (!vq->used_phys && !vq->used_size) { - continue; - } - - uint64_t last =3D vq->used_phys + vq->used_size - 1; - log_size =3D MAX(log_size, last / VHOST_LOG_CHUNK + 1); - } return log_size; } =20