From nobody Sun May 5 15:10:47 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=1660928859; cv=none; d=zohomail.com; s=zohoarc; b=Nl//+AqlrNP+B+56pH1GoPpSQwRkaFDmreRb4ldT4PJ+MyUXrQoIGc6HIEXPYfc9ELfT1GJDVDnU8wscfvWEnNGij6sb0NKBjvKWl3tvWT82xIJixiUgKs3FIFQyGPbiEq2P9nLiHTNb7/B7qEgkZ8+CgsxRsufenCXn71RNMX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928859; 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=qnVGWjSMIp3mECXi5SalJudL78dZzeCiGZ1sn97SGrQ=; b=A2wCWYNm6kdM5I3k/40idk630V0l1DSlsDVjNWSqAI03x2ofsU8grlyL/Ls//fc8sVbjrBtUoAe+ETIC/BnaQ+E6MBkMlnPXLfw3rQS4bB0JJgEB8U2BX3gXg0McyhN5/3rNzLjvNp/l7yNWcJCG71Z/lPfB7e2sX5BO6Gl8P3Q= 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 1660928859392710.5497206292504; Fri, 19 Aug 2022 10:07:39 -0700 (PDT) Received: from localhost ([::1]:50388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5T8-00052H-AE for importer@patchew.org; Fri, 19 Aug 2022 13:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GG-0006bK-12 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5G2-0000Z7-C0 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:18 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-hiIAhPsXN3WqWIK6xEnJXw-1; Fri, 19 Aug 2022 12:54:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80246811E75 for ; Fri, 19 Aug 2022 16:54:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C38B2027EB4; Fri, 19 Aug 2022 16:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928044; 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=qnVGWjSMIp3mECXi5SalJudL78dZzeCiGZ1sn97SGrQ=; b=F3RKZqkpc5a3GcVkQo3PWJec0kyg3CD55ubL8RbQoGQ+zPzr721P1ZiEq0ujDHSFH9LiBG yzytzX9raZOAT3H0qqbUxAWF34nTTDALSGkpEm1zanY6+6QeVGQAx2ZoWZdEv6wb4aPHzf 0eymEeOdL1V1PcGnDY2kRaZYj2KrQL8= X-MC-Unique: hiIAhPsXN3WqWIK6xEnJXw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 1/7] vdpa: Skip the maps not in the iova tree Date: Fri, 19 Aug 2022 18:53:51 +0200 Message-Id: <20220819165357.3591965-2-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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, 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: 1660928860206100001 Next patch will skip the registering of dma maps that the vdpa device rejects in the iova tree. We need to consider that here or we cause a SIGSEGV accessing result. Reported-by: Lei Yang Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 3ff9ce3501..983d3697b0 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -289,6 +289,10 @@ static void vhost_vdpa_listener_region_del(MemoryListe= ner *listener, }; =20 result =3D vhost_iova_tree_find_iova(v->iova_tree, &mem_region); + if (!result) { + /* The memory listener map wasn't mapped */ + return; + } iova =3D result->iova; vhost_iova_tree_remove(v->iova_tree, result); } --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928264; cv=none; d=zohomail.com; s=zohoarc; b=BfucibwmF4GfCXatMloQ0x7RzzgHmF/jIbQt3BP2FnWxWC3vde1cCto3mdN8yCzYcyXSUDPLnwIxBnl0kBlSgxBzPoZRFZzIbAjLNL7VEzN056dkXvIVF6TlY2q/7aLv4Ih/lfParlTdzO0+TQVUzCTiHQbEHgASAAVIuRyX4K8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928264; 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=PKFdaN2tkUi5mrhylR6MDQmGbp3hAyCJTgJURDlH6rQ=; b=mXj0e0knUw/ZC7V8vJP8a5EuCXJIQrwp67yICPsv6y4AC6NEI13Jth5uMU8DDqfHkeLh/Dvnr+3i4Ot6FJYZgmN7fRI7+367YmNrBGBTHbRLVBq9hZbcYLETDcK8QYFR3i2zn27XoG5SJX46b7VGk06tMw78KnA21uXU4b0K7sY= 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 1660928264748362.36863539519254; Fri, 19 Aug 2022 09:57:44 -0700 (PDT) Received: from localhost ([::1]:39404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5JX-0001EE-87 for importer@patchew.org; Fri, 19 Aug 2022 12:57:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GE-0006am-UP for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55393) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5G2-0000ZF-Af for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:08 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486-76VmXHK_MEmIHMhCsZJZig-1; Fri, 19 Aug 2022 12:54:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 111798039A1 for ; Fri, 19 Aug 2022 16:54:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id C17832026D4C; Fri, 19 Aug 2022 16:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928045; 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=PKFdaN2tkUi5mrhylR6MDQmGbp3hAyCJTgJURDlH6rQ=; b=Xff/86Lx6KZmzExHmoM4k+Vg7wZGxO7u/yN1Yey0pyq7h99kIAeAOYNcZsXbltGr99cOuG +KiZu0xDQuKwlKK+lFBpmPAJzBsQzbcs91f/Pm+TD6voBosO5csZYXAjjWn51ycg6eQbLA trWZXAw8v/jOj9TUZcT1jq+Kns/f+Kk= X-MC-Unique: 76VmXHK_MEmIHMhCsZJZig-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 2/7] vdpa: do not save failed dma maps in SVQ iova tree Date: Fri, 19 Aug 2022 18:53:52 +0200 Message-Id: <20220819165357.3591965-3-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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_NONE=-0.0001, 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: 1660928265991100003 If a map fails for whatever reason, it must not be saved in the tree. Otherwise, qemu will try to unmap it in cleanup, leaving to more errors. Fixes: 34e3c94eda ("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 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 983d3697b0..7e28d2f674 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -176,6 +176,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) static void vhost_vdpa_listener_region_add(MemoryListener *listener, MemoryRegionSection *section) { + DMAMap mem_region =3D {}; struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); hwaddr iova; Int128 llend, llsize; @@ -212,13 +213,13 @@ static void vhost_vdpa_listener_region_add(MemoryList= ener *listener, =20 llsize =3D int128_sub(llend, int128_make64(iova)); if (v->shadow_vqs_enabled) { - DMAMap mem_region =3D { - .translated_addr =3D (hwaddr)(uintptr_t)vaddr, - .size =3D int128_get64(llsize) - 1, - .perm =3D IOMMU_ACCESS_FLAG(true, section->readonly), - }; + int r; =20 - int r =3D vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); + mem_region.translated_addr =3D (hwaddr)(uintptr_t)vaddr, + mem_region.size =3D int128_get64(llsize) - 1, + mem_region.perm =3D IOMMU_ACCESS_FLAG(true, section->readonly), + + r =3D vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); if (unlikely(r !=3D IOVA_OK)) { error_report("Can't allocate a mapping (%d)", r); goto fail; @@ -232,11 +233,16 @@ static void vhost_vdpa_listener_region_add(MemoryList= ener *listener, vaddr, section->readonly); if (ret) { error_report("vhost vdpa map fail!"); - goto fail; + goto fail_map; } =20 return; =20 +fail_map: + if (v->shadow_vqs_enabled) { + vhost_iova_tree_remove(v->iova_tree, &mem_region); + } + fail: /* * On the initfn path, store the first error in the container so we --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928540; cv=none; d=zohomail.com; s=zohoarc; b=ND+DOltCgepGAyxUcfwlXgEwim7rjl0EUxfe94QvjFWAb/M4PO1eyzOIcgfFtNJ4nYWCOKuN/vs08rdAc833306yGkk9IRrfjTEfJcrcojSNOAuOXrGLtvR9Yu7GiQfHkMdKp98BeMYRB+JzZanGYc1SBy5Ey/111EeqhwTEdRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928540; 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=AkQl3YdAHyUKV2KU5QLoaoaqz7lW4yv5zlw7uXbjozk=; b=D2RKBxufj1RAE0sybjewxokCLobzikFQDxyB/k4y3J5XPb9eRbOIl+nhgzAakhIicEfvJggbI9MjEXFwnGNINm7TYanrzP03aVV6sBuvW+Na/ZNbxCTl7ZC8MeOMU3qQzjaRKLEdYiCKDRIFJ0ScTQzE0A9tKgVK7ESlg1n66Mk= 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 1660928540839118.30269070521717; Fri, 19 Aug 2022 10:02:20 -0700 (PDT) Received: from localhost ([::1]:53892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5Nz-0006rJ-Ie for importer@patchew.org; Fri, 19 Aug 2022 13:02:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GF-0006bM-VT for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GD-0000Zd-H1 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:18 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-3mYo78DpOYydgTSSy33d1w-1; Fri, 19 Aug 2022 12:54:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B3CA185A794 for ; Fri, 19 Aug 2022 16:54:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55ABD2026D4C; Fri, 19 Aug 2022 16:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928049; 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=AkQl3YdAHyUKV2KU5QLoaoaqz7lW4yv5zlw7uXbjozk=; b=NKbVb+BlgJVZrBe5LFdh14iXy/9WVPMscN4J8bTq1/sPpoKPCMZc6t1Izbbj4j1ljJpK3H gSvM3tkvmmGCvNMhysa0CWBmhoxqsQU4FEJAarOsc5vZWwT4y7zJcW5SxbsOgN55VCXHwv r3mnbbskfofmNxCWOXMK4ihSYqNtoYM= X-MC-Unique: 3mYo78DpOYydgTSSy33d1w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 3/7] util: make a copy of iova_tree_remove_parameter Date: Fri, 19 Aug 2022 18:53:53 +0200 Message-Id: <20220819165357.3591965-4-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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_NONE=-0.0001, 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: 1660928542540100001 It's convenient to call iova_tree_remove from a map returned from iova_tree_find or iova_tree_find_iova. With the current code this is not possible, since we will free it, and then we will try to search for it again. Fix it making a copy of the argument. Not applying a fixes tag, since there is no use like that at the moment. Signed-off-by: Eugenio P=C3=A9rez --- util/iova-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/iova-tree.c b/util/iova-tree.c index fee530a579..713e3edd7b 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -166,9 +166,11 @@ void iova_tree_foreach(IOVATree *tree, iova_tree_itera= tor iterator) =20 void iova_tree_remove(IOVATree *tree, const DMAMap *map) { + /* Just in case caller is calling iova_tree_remove from a result of fi= nd */ + const DMAMap needle =3D *map; const DMAMap *overlap; =20 - while ((overlap =3D iova_tree_find(tree, map))) { + while ((overlap =3D iova_tree_find(tree, &needle))) { g_tree_remove(tree->tree, overlap); } } --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928543; cv=none; d=zohomail.com; s=zohoarc; b=dXXHTRX6dJ0DE4UqVRWhZg0S7vFOODYjWjrIqr0S7HVNHsTlc0tJCwo0Gc1dbXPdim6G+GMJSaZBUyB8R3DbVos5PeqtDNFIXyhC2iTt2O0u5DGg9Sg8YxB5vQH+Vd5Ddej7ExgrLvAzlAd7OexFaulEb2EhekDffCFYVEkIomU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928543; 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=EusLDS+ofqEpjMUNoDF7839TtwKi1nMz+yVCRr8xqJM=; b=hImTGkvz6PvG2T2OFEYkim2qiihArGxEO/+MIciQTRyKTJR1aM90q/+TOlANkloJYOhxiPaKRvMs+BosHdmVWaUo43COvWiLS6+PANcEBM9n2yTyiZ71ACi2NjjFd4YRH5JdbA/hAxVFI/LCqhOC3CJ77DBGKXkjo0HV8CxlJXc= 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 1660928543477184.89001247902752; Fri, 19 Aug 2022 10:02:23 -0700 (PDT) Received: from localhost ([::1]:53900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5O2-0006xh-Fo for importer@patchew.org; Fri, 19 Aug 2022 13:02:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GG-0006bJ-59 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41535) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5G9-0000ZY-BG for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:18 -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-60-L_ZU7HVJNvqUjRzgOm-U-w-1; Fri, 19 Aug 2022 12:54:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B87D3801F6C for ; Fri, 19 Aug 2022 16:54:07 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD3C12026D4C; Fri, 19 Aug 2022 16:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928048; 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=EusLDS+ofqEpjMUNoDF7839TtwKi1nMz+yVCRr8xqJM=; b=ZMahQLr07muQlnXhPBxT5MqGQwTWJ39gTNsvMI5qEXo8RDqTjh9kr4aZmL+HNgclZDn0vB ElwRtPNoShTLe+FSlnBdAY5HQMwN5ZZFP1cp8c9CBwabxYY5WC6DekNLbmqacDNYreFac4 kVqlfeIisVcCFiJ1XJQSJKo3MVp5uH0= X-MC-Unique: L_ZU7HVJNvqUjRzgOm-U-w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 4/7] vdpa: Remove SVQ vring from iova_tree at shutdown Date: Fri, 19 Aug 2022 18:53:54 +0200 Message-Id: <20220819165357.3591965-5-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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_NONE=-0.0001, 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: 1660928544603100003 Although the device will be reset before usage, the right thing to do is to clean it. Reported-by: Lei Yang Fixes: 34e3c94eda ("vdpa: Add custom IOTLB translations to SVQ") Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7e28d2f674..943799c17c 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -898,7 +898,12 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdp= a *v, =20 size =3D ROUND_UP(result->size, qemu_real_host_page_size()); r =3D vhost_vdpa_dma_unmap(v, result->iova, size); - return r =3D=3D 0; + if (unlikely(r < 0)) { + return false; + } + + vhost_iova_tree_remove(v->iova_tree, result); + return 0; } =20 static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928265; cv=none; d=zohomail.com; s=zohoarc; b=gNPmcLE3d3IH7NtVVucD2KvtJ62HJsVZyDvCXza6s87tPiIc+zCj0pI81KclbLJ1xlQDioAh3RrDfYut4P3oUDSLKSQQx9ToxgtT/8pgNObouLsYUTARi3H+2RSVcnXIfHfO3EHbpyD8IKkog+KZ4pGEX1DTVPAJLE+1JgEfzLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928265; 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=EGKCrHfWyk+48LQ4AbcCYbjB5Buw/lbISq6Ne0M6TtM=; b=QLDb3sos1ycc1tlVxHb+oJAoLVUtG9WzG/Mpn3wDprl1zpohvtZLal044J331toEl6lcDnz85S6wYvipdjP+eVpFr+/UFNP96HxqSKgJkpSz4UooxKarT6vB3DK/opG14spsSARqJAKAby3DCFdUUXryWHCobo1Cx/DPaCeEcr8= 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 1660928265314209.98070861341398; Fri, 19 Aug 2022 09:57:45 -0700 (PDT) Received: from localhost ([::1]:39408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5JY-0001HF-AE for importer@patchew.org; Fri, 19 Aug 2022 12:57:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GJ-0006dD-Hg for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GD-0000Zm-I8 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:22 -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-265-hanN21knP3y4isPBmNrXlg-1; Fri, 19 Aug 2022 12:54:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B12CC3C025B2 for ; Fri, 19 Aug 2022 16:54:08 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE6E2026D4C; Fri, 19 Aug 2022 16:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928050; 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=EGKCrHfWyk+48LQ4AbcCYbjB5Buw/lbISq6Ne0M6TtM=; b=AP44tCkIr8qETK6JHXR2TvNfyMO7A/OBYUssklRopuT7QKigTo6aFC7t9j7dTb260/3inf f+6I5uSTYGOKepAAS/MTBRfm/I3Kgq9t7OwZoaXQ6Scp0RW9O7VicbhkS8xZxCZV+eYiP2 jDs6zGTXL4SAgquoSPbhlMjPGxl31HY= X-MC-Unique: hanN21knP3y4isPBmNrXlg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 5/7] vdpa: Make SVQ vring unmapping return void Date: Fri, 19 Aug 2022 18:53:55 +0200 Message-Id: <20220819165357.3591965-6-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 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: 1660928265981100001 Nothing actually reads the return value, but an error in cleaning some entries could cause device stop to abort, making a restart impossible. Better ignore explicitely the return value. Reported-by: Lei Yang Fixes: 34e3c94eda ("vdpa: Add custom IOTLB translations to SVQ") Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 943799c17c..07d00f5284 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -884,7 +884,7 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, /** * Unmap a SVQ area in the device */ -static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, +static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, const DMAMap *needle) { const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, needl= e); @@ -893,37 +893,32 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vd= pa *v, =20 if (unlikely(!result)) { error_report("Unable to find SVQ address to unmap"); - return false; + return; } =20 size =3D ROUND_UP(result->size, qemu_real_host_page_size()); r =3D vhost_vdpa_dma_unmap(v, result->iova, size); if (unlikely(r < 0)) { - return false; + return; } =20 vhost_iova_tree_remove(v->iova_tree, result); - return 0; } =20 -static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, +static void vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, const VhostShadowVirtqueue *svq) { DMAMap needle =3D {}; struct vhost_vdpa *v =3D dev->opaque; struct vhost_vring_addr svq_addr; - bool ok; =20 vhost_svq_get_vring_addr(svq, &svq_addr); =20 needle.translated_addr =3D svq_addr.desc_user_addr; - ok =3D vhost_vdpa_svq_unmap_ring(v, &needle); - if (unlikely(!ok)) { - return false; - } + vhost_vdpa_svq_unmap_ring(v, &needle); =20 needle.translated_addr =3D svq_addr.used_user_addr; - return vhost_vdpa_svq_unmap_ring(v, &needle); + vhost_vdpa_svq_unmap_ring(v, &needle); } =20 /** @@ -1094,26 +1089,22 @@ err: return false; } =20 -static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev) +static void vhost_vdpa_svqs_stop(struct vhost_dev *dev) { struct vhost_vdpa *v =3D dev->opaque; =20 if (!v->shadow_vqs) { - return true; + return; } =20 for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); - bool ok =3D vhost_vdpa_svq_unmap_rings(dev, svq); - if (unlikely(!ok)) { - return false; - } + vhost_vdpa_svq_unmap_rings(dev, svq); } =20 if (v->migration_blocker) { migrate_del_blocker(v->migration_blocker); } - return true; } =20 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) @@ -1130,10 +1121,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) } vhost_vdpa_set_vring_ready(dev); } else { - ok =3D vhost_vdpa_svqs_stop(dev); - if (unlikely(!ok)) { - return -1; - } + vhost_vdpa_svqs_stop(dev); vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } =20 --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928545; cv=none; d=zohomail.com; s=zohoarc; b=f/tEc0c04XElR1PXoTnyU3vmT1FvDgUvdrsZUaDuU+1nWLBNb5gub9bYgutV/RLgnhNN1kUhpAq167Ka7dWFzTEMT9p2vUULjzTi/JRPtb6uGEULJhHI6GtkOs33+ueOg08e5jJq/d1Ov/d46PMNxhmUHz2nMQZed5YtvMWqt9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928545; 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=fFAaId1uFIThEgAvJmcI88AUm2jppv3aFgHjdbZAtUM=; b=SlfgRfYbi3ap3w251QJiqStvIQbVb2i/ejsibHBOHqlPss+wVmH5YGJymZfx+YSt36SEhynrSeE5xY8tf32XJ7fQDpAT97h5yqNoEsLuP8vWY3D9j0isB18iktIJS4MBz+PwLGuEsNy+6rdBkCaMhwN4915ZBELNd7DOPmSOCGI= 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 1660928545803986.3891721896696; Fri, 19 Aug 2022 10:02:25 -0700 (PDT) Received: from localhost ([::1]:53904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5O3-00072T-Ot for importer@patchew.org; Fri, 19 Aug 2022 13:02:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GJ-0006dG-IA for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GD-0000Zs-Hv for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:22 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-qGiAc2V_MYqLzrrml9XArQ-1; Fri, 19 Aug 2022 12:54:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 415F31029F77 for ; Fri, 19 Aug 2022 16:54:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id F28732026609; Fri, 19 Aug 2022 16:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928051; 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=fFAaId1uFIThEgAvJmcI88AUm2jppv3aFgHjdbZAtUM=; b=fe4xi2HQ/IInysVeA5WBEw9e2ARkgoi1Pfz9bjvCaK/BbC81ORtC27JlxSuFla8634gzvn YvZ0K7xXxN95w5mYJqa57jgQDPPrX0V6VFdiUuciebsj4zEg0+H/ld+8jCeLDfeuYkVA2U xnN9pADPztc+0f9zadhYADUiIxNpYL0= X-MC-Unique: qGiAc2V_MYqLzrrml9XArQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 6/7] vhost: Always store new kick fd on vhost_svq_set_svq_kick_fd Date: Fri, 19 Aug 2022 18:53:56 +0200 Message-Id: <20220819165357.3591965-7-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 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: 1660928546868100001 We can unbind twice a file descriptor if we call twice vhost_svq_set_svq_kick_fd because of this. Since it comes from vhost and not from SVQ, that file descriptor could be a different thing that guest's vhost notifier. Likewise, it can happens the same if a guest start and stop the device multiple times. Reported-by: Lei Yang Fixes: dff4426fa6 ("vhost: Add Shadow VirtQueue kick forwarding capabilitie= s") Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e4956728dd..82a784d250 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -602,13 +602,13 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *= svq, int svq_kick_fd) event_notifier_set_handler(svq_kick, NULL); } =20 + event_notifier_init_fd(svq_kick, svq_kick_fd); /* * event_notifier_set_handler already checks for guest's notifications= if * they arrive at the new file descriptor in the switch, so there is no * need to explicitly check for them. */ if (poll_start) { - event_notifier_init_fd(svq_kick, svq_kick_fd); event_notifier_set(svq_kick); event_notifier_set_handler(svq_kick, vhost_handle_guest_kick_notif= ier); } @@ -655,7 +655,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, */ void vhost_svq_stop(VhostShadowVirtqueue *svq) { - event_notifier_set_handler(&svq->svq_kick, NULL); + vhost_svq_set_svq_kick_fd(svq, VHOST_FILE_UNBIND); g_autofree VirtQueueElement *next_avail_elem =3D NULL; =20 if (!svq->vq) { --=20 2.31.1 From nobody Sun May 5 15:10:47 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=1660928264; cv=none; d=zohomail.com; s=zohoarc; b=U/k0teAv8VQt9bh+/oTRZDGkAzWRzurpr+u5Wj81YvfrHEb0mEHEPzZE/uYTMJ5UIXpnI6gxMHAMCWAybiB3yfewlG36Hugl6pptq2HiXqQCwQBa2kT7yvcK3dnCedoNTUJyH/9aQSGYI9uSdnskZqf5zHcz4pLGRH9rCwEgjfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660928264; 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=8ZrDFQPvA2ha/NNE0Gf5lA5+keNhWYZOdGwM1beFqHQ=; b=hAPV5IrQ5PW5xOCdIrQf4iSuD43Cw4NHvlVt1sh+DJYGUQYrvg+WiK3KPg9O8ElCQXpZO/NoaF1gy02AqWU9IZyoozcvfnXMs9FQgYTgo3CMAzpzpi1GbMjjt/3I9NnuAOpVJ1utMVHeNOm5ZNJAbksMSj3W1H98hrdIjIlOcyA= 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 1660928264506178.0671448426301; Fri, 19 Aug 2022 09:57:44 -0700 (PDT) Received: from localhost ([::1]:39406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP5JW-0001FP-Iv for importer@patchew.org; Fri, 19 Aug 2022 12:57:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GJ-0006dE-HK for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43732) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oP5GD-0000Zx-I3 for qemu-devel@nongnu.org; Fri, 19 Aug 2022 12:54:22 -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-393-3piho8MkOMqMDZOz2zQLfg-1; Fri, 19 Aug 2022 12:54:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAA4D3C025B2 for ; Fri, 19 Aug 2022 16:54:11 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86C442026D4C; Fri, 19 Aug 2022 16:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660928053; 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=8ZrDFQPvA2ha/NNE0Gf5lA5+keNhWYZOdGwM1beFqHQ=; b=DLb42c7hocgUrh1gIyoNZJLM4QPTArqk3umDSNbHggaLgt74Qb9QtMn45ehyqoiSbO8/SC DFJTVGxLVmJaKS6mQTA0mASyGwRq5a6QUTA9N5mta3W0pQMNBzTBbHuqHEByTAqCEfCyTd jkc/GMpmz8ZnuIOdVenwO015BkWGzJw= X-MC-Unique: 3piho8MkOMqMDZOz2zQLfg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Lei Yang , Jason Wang , Laurent Vivier , Cindy Lu , Peter Xu , "Michael S. Tsirkin" Subject: [PATCH 7/7] vdpa: Use ring hwaddr at vhost_vdpa_svq_unmap_ring Date: Fri, 19 Aug 2022 18:53:57 +0200 Message-Id: <20220819165357.3591965-8-eperezma@redhat.com> In-Reply-To: <20220819165357.3591965-1-eperezma@redhat.com> References: <20220819165357.3591965-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.78 on 10.11.54.4 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: 1660928265986100002 Reduce code duplication. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 07d00f5284..45d6e86b45 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -884,10 +884,12 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *d= ev, /** * Unmap a SVQ area in the device */ -static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, - const DMAMap *needle) +static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr addr) { - const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, needl= e); + const DMAMap needle =3D { + .translated_addr =3D addr, + }; + const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, &need= le); hwaddr size; int r; =20 @@ -908,17 +910,14 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vd= pa *v, static void vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, const VhostShadowVirtqueue *svq) { - DMAMap needle =3D {}; struct vhost_vdpa *v =3D dev->opaque; struct vhost_vring_addr svq_addr; =20 vhost_svq_get_vring_addr(svq, &svq_addr); =20 - needle.translated_addr =3D svq_addr.desc_user_addr; - vhost_vdpa_svq_unmap_ring(v, &needle); + vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr); =20 - needle.translated_addr =3D svq_addr.used_user_addr; - vhost_vdpa_svq_unmap_ring(v, &needle); + vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr); } =20 /** @@ -996,7 +995,7 @@ static bool vhost_vdpa_svq_map_rings(struct vhost_dev *= dev, ok =3D vhost_vdpa_svq_map_ring(v, &device_region, errp); if (unlikely(!ok)) { error_prepend(errp, "Cannot create vq device region: "); - vhost_vdpa_svq_unmap_ring(v, &driver_region); + vhost_vdpa_svq_unmap_ring(v, driver_region.translated_addr); } addr->used_user_addr =3D device_region.iova; =20 --=20 2.31.1