From nobody Sat May 18 18:13:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658478671; cv=none; d=zohomail.com; s=zohoarc; b=krGoGRjhH7t/Cq+I1XhwRr/Dp4D9PinJ/lAY1iGVac0fFN62vvUAKgQaHKMvUZrWTXuNciEFHowvy3/lhW3MPvvb14bWa2Z7EUcT5Fc9V7f7e0qn/7em4SYS6HGAsg61kSv3S8Ks+1mBgYl2rcA/VF6q5qdfp1bkE9eUFxTuy38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658478671; 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=9QLv+/qJ8f6j/mBEmoqOPGOKE98RmGOO3G3Scja4x6U=; b=UgBJNmGvppsVy74miEZ+LZqyP5yORzs8BJlpM/x1f2B6OjegvxxMOZCPaeG7jOLHDmIaRynxZlRraFLeyWTFYz4I5jDORu36ndAfp76VZKW9kJqC1lXQKs5fHVDpeSXVi9iXwkq5AIQC0tMenyt1SzunGC+Mc9mrBmvFxvMB3ew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165847867185854.000558770850034; Fri, 22 Jul 2022 01:31:11 -0700 (PDT) Received: from localhost ([::1]:36646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEo3y-00005w-Gz for importer@patchew.org; Fri, 22 Jul 2022 04:31:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEnzb-0007KD-Nk for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:26:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEnzY-0004aR-FY for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:26:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-671-LaI6-tYwNMCl0qxi6YI_Rg-1; Fri, 22 Jul 2022 04:26:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2D6EA2813D34 for ; Fri, 22 Jul 2022 08:26:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7178340C141D; Fri, 22 Jul 2022 08:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658478395; 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=9QLv+/qJ8f6j/mBEmoqOPGOKE98RmGOO3G3Scja4x6U=; b=GraOCun5GeaqA6JPsgNuz5WCqMrrLYqpzyKUxn6E26qKMvmt91RTk8erL2A4l7sJ0Luerp cYBh4q4MS5cMxb8tVh9Hfedspnsjea4NmGtfshlLEUaXsGQgOGFppHEsABPtBJEJh46Wjk UjFN8Dx0AMHXuLBunEOcjx07pzDqDDc= X-MC-Unique: LaI6-tYwNMCl0qxi6YI_Rg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Jason Wang , "Michael S. Tsirkin" Subject: [PATCH] vdpa: Fix memory listener deletions of iova tree Date: Fri, 22 Jul 2022 10:26:30 +0200 Message-Id: <20220722082630.3371384-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658478672805100001 vhost_vdpa_listener_region_del is always deleting the first iova entry of the tree, since it's using the needle iova instead of the result's one. This was detected using a vga virtual device in the VM using vdpa SVQ. It makes some extra memory adding and deleting, so the wrong one was mapped / unmapped. This was undetected before since all the memory was mappend and unmapped totally without that device, but other conditions could trigger it too: * mem_region was with .iova =3D 0, .translated_addr =3D (correct GPA). * iova_tree_find_iova returned right result, but does not update mem_region. * iova_tree_remove always removed region with .iova =3D 0. Right iova were sent to the device. * Next map will fill the first region with .iova =3D 0, causing a mapping with the same iova and device complains, if the next action is a map. * Next unmap will cause to try to unmap again iova =3D 0, causing the device to complain that no region was mapped at iova =3D 0. Fixes: 34e3c94edaef ("vdpa: Add custom IOTLB translations to SVQ") Reported-by: Lei Yang Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 291cd19054..00e990ea40 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -290,7 +290,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, result =3D vhost_iova_tree_find_iova(v->iova_tree, &mem_region); iova =3D result->iova; - vhost_iova_tree_remove(v->iova_tree, &mem_region); + vhost_iova_tree_remove(v->iova_tree, result); } vhost_vdpa_iotlb_batch_begin_once(v); ret =3D vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); -- 2.31.1