From nobody Thu Dec 18 17:48:25 2025 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=1662101219; cv=none; d=zohomail.com; s=zohoarc; b=S4+9MlwxqUdjYHtsJ2xxWlQiIn5SCYxssncH8LirxcU9ijz8P+9qKwg8bL3XGFX49E5z1w1FLA+gk5YYD4R9bkximkkg2r7agW0wuSvMJXrDtMNM74pTFZV9a9eaB0c4Gzln/SypymGC3FT7hNP38Kgful8dqnGw9xeyjEH6fWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101219; 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=Vic+0XyhfRNSP6ny+VU05BTXAsDs7H9Nq0W7LZ5xysM=; b=bYHil4EkoWP8obEqzCA8AY/FNNtNqkyjsPfO4DJ6VKpluRC9972sbbQ5SZrXCvS3KqEJprWOFxP/Jw8bMPPLLtpRzrSYvMbISZ+yc/mHfptI40mWziGKYa2grkt7IhaiakVMe5NkM58lbxE/aie3qUAD082qVUzpTJbJAYBw034= 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 1662101219985936.3165582206292; Thu, 1 Sep 2022 23:46:59 -0700 (PDT) Received: from localhost ([::1]:52296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0SA-0001dU-TO for importer@patchew.org; Fri, 02 Sep 2022 02:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NG-00074N-OG for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:41:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NE-0004kX-H4 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:41:54 -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-220-GmVYvuMqNKywlnMy_5KRdQ-1; Fri, 02 Sep 2022 02:41:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E75E61857F10; Fri, 2 Sep 2022 06:41:46 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71CD11415137; Fri, 2 Sep 2022 06:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100911; 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=Vic+0XyhfRNSP6ny+VU05BTXAsDs7H9Nq0W7LZ5xysM=; b=GyRX+sxIwX7T4fOnRwyjzwq8ln6DjbU7uYFxizT7qvf1PTzQKtbA9MvSJU+rTK4ACEV1Hj qClvZ+XCZtBR+9dCjf4ET9iN3JUF1O4k59oEuTNXwSIgT3BuyuKxQSj5UZLGEnAjN6bYwb 0Ly7sCg0wQ9qtqP5FgCL2faHLiC9BAM= X-MC-Unique: GmVYvuMqNKywlnMy_5KRdQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Jason Wang Subject: [PULL 01/21] vdpa: Skip the maps not in the iova tree Date: Fri, 2 Sep 2022 14:41:18 +0800 Message-Id: <20220902064138.56468-2-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101221885100003 From: Eugenio P=C3=A9rez 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 Signed-off-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 3ff9ce3..983d369 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.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101218; cv=none; d=zohomail.com; s=zohoarc; b=JDdAtbSGrqXuZPwJbpJLl79Z5/4ys9RqfvM8oWVnULF/n+WAe4+abIb4gbasXEsqprm16s8UGZRo5f26TI3yMrRCvGvmLZNdp3+DxnNHHqPgRwrJ1k2WSmxtOIrauKfS33kQySDgS24QUwHhezocazTCf1KNA4QAF22B0pOd7AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101218; 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=Oq3pgxHYD1TAQ56GSAAjvNLpVaC+gsB3rAkBvL0ynnY=; b=L2iaP8SGTMpQplEDCwMiDH5GhTroR5P8vIZtyi3/fMuMQ+eqnuMPm1+1hAwBtCx2/3eP03ynVgD3pblmt7kObB6sv27aTEeDLpebWeeFtRk1mw3EsI3uSN8wyjU/BMgPQlvyINmZGIm3mh2L+2D/1n8jpG9b6gmXoI5JpnMtJiA= 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 1662101218854695.2717240022237; Thu, 1 Sep 2022 23:46:58 -0700 (PDT) Received: from localhost ([::1]:52294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0S9-0001d2-0n for importer@patchew.org; Fri, 02 Sep 2022 02:46:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NM-00077i-DA for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NH-0004l8-TB for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:41:58 -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-491-LEDBWOV8O62QK4-m0Qk8Cw-1; Fri, 02 Sep 2022 02:41:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E2AC800124; Fri, 2 Sep 2022 06:41:51 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1D8B1415137; Fri, 2 Sep 2022 06:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100915; 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=Oq3pgxHYD1TAQ56GSAAjvNLpVaC+gsB3rAkBvL0ynnY=; b=bk8Jgkve2meQPke23ubkMUQZGdzzl+DL+ZcdrQ3ii6il4MoxoTSdVH+AtPVk9DpDo77J8K VvHmYNqK5jPsg0atCZaf3dFnrxVoPOxrzSnZ1N4jJvjDXiAPfIht1Urj4iDPNYi3L7FZnu toleiW1VbHMRzwMkECohBAhRRzpRwuk= X-MC-Unique: LEDBWOV8O62QK4-m0Qk8Cw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Jason Wang Subject: [PULL 02/21] vdpa: do not save failed dma maps in SVQ iova tree Date: Fri, 2 Sep 2022 14:41:19 +0800 Message-Id: <20220902064138.56468-3-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101220178100001 From: Eugenio P=C3=A9rez 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 Signed-off-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 983d369..7e28d2f 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.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101220; cv=none; d=zohomail.com; s=zohoarc; b=OrkKXtXZugo/phvrEIis4R5BATKvX10EYVOIxHJTBu4zKCKbCMK6IuM7fTG4XL/ehpGMILJApE9hD07qrgWOqLr+R/UcsewP4n0IDufwtI5u2bc7J1kaOfjmhSbee5Ny6AH9FXOBw8xVnp0GIrgyrcCVl4c+7cgUr00gtQk4vV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101220; 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=Y4sWtCltsc4cJCfYvM1chr3tdcrK1W52yvqpMwLjQ80=; b=Mz78OKserUKJPksNWbVvdk9E7Gy/wergzkD73bQtQKM6EytNwr5e2ceqoACfgPt6mw5OdAAj6N8Y3mDelv43bwTI0eslrDNPndUV3G33Kign6JJZK2yc9DgaZhrKcnHZ177CJLrmWAaAZYQBMi2rfqzJKl7aQauBGDLtkeA1luc= 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 1662101220587738.2025970512069; Thu, 1 Sep 2022 23:47:00 -0700 (PDT) Received: from localhost ([::1]:52298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0SB-0001h7-3j for importer@patchew.org; Fri, 02 Sep 2022 02:46:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NL-00075K-4a for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NI-0004lD-5B for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:41:57 -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-490-b_hcdgnjOuCr9yLkaNCt3w-1; Fri, 02 Sep 2022 02:41:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2870F1857F0F; Fri, 2 Sep 2022 06:41:54 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11FB71415138; Fri, 2 Sep 2022 06:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100915; 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=Y4sWtCltsc4cJCfYvM1chr3tdcrK1W52yvqpMwLjQ80=; b=g3DYgen0LBuzybbmlxUgtoCEPTCmameFwAX/IKYrv/B4BGzL/yckrZYdi9W07iX/Pgmhhn 8FlJ0awa2KgHYLHdSLmiotM4syGaFx2yaQ2OAxSNMlUBF510E3QrlhOlXCEP317I0vOhf4 Kp96UVYjReqFD/GGwH5a7Wl6Ffro2QA= X-MC-Unique: b_hcdgnjOuCr9yLkaNCt3w-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 03/21] util: accept iova_tree_remove_parameter by value Date: Fri, 2 Sep 2022 14:41:20 +0800 Message-Id: <20220902064138.56468-4-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101221885100004 From: Eugenio P=C3=A9rez 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 accepting the map by value, forcing 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 Signed-off-by: Jason Wang --- hw/i386/intel_iommu.c | 6 +++--- hw/virtio/vhost-iova-tree.c | 2 +- hw/virtio/vhost-iova-tree.h | 2 +- hw/virtio/vhost-vdpa.c | 6 +++--- include/qemu/iova-tree.h | 2 +- net/vhost-vdpa.c | 4 ++-- util/iova-tree.c | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 2162394..05d53a1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1187,7 +1187,7 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vt= d_page_walk_info *info) return ret; } /* Drop any existing mapping */ - iova_tree_remove(as->iova_tree, &target); + iova_tree_remove(as->iova_tree, target); /* Recover the correct type */ event->type =3D IOMMU_NOTIFIER_MAP; entry->perm =3D cache_perm; @@ -1200,7 +1200,7 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vt= d_page_walk_info *info) trace_vtd_page_walk_one_skip_unmap(entry->iova, entry->addr_ma= sk); return 0; } - iova_tree_remove(as->iova_tree, &target); + iova_tree_remove(as->iova_tree, target); } =20 trace_vtd_page_walk_one(info->domain_id, entry->iova, @@ -3563,7 +3563,7 @@ static void vtd_address_space_unmap(VTDAddressSpace *= as, IOMMUNotifier *n) =20 map.iova =3D n->start; map.size =3D size; - iova_tree_remove(as->iova_tree, &map); + iova_tree_remove(as->iova_tree, map); } =20 static void vtd_address_space_unmap_all(IntelIOMMUState *s) diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c index 67bf6d5..3d03395 100644 --- a/hw/virtio/vhost-iova-tree.c +++ b/hw/virtio/vhost-iova-tree.c @@ -104,7 +104,7 @@ int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAM= ap *map) * @iova_tree: The vhost iova tree * @map: The map to remove */ -void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map) +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map) { iova_tree_remove(iova_tree->iova_taddr_map, map); } diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h index 6a4f24e..4adfd79 100644 --- a/hw/virtio/vhost-iova-tree.h +++ b/hw/virtio/vhost-iova-tree.h @@ -22,6 +22,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_t= ree_delete); const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, const DMAMap *map); int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map); -void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map); +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map); =20 #endif diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7e28d2f..87e0ad3 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -240,7 +240,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, =20 fail_map: if (v->shadow_vqs_enabled) { - vhost_iova_tree_remove(v->iova_tree, &mem_region); + vhost_iova_tree_remove(v->iova_tree, mem_region); } =20 fail: @@ -300,7 +300,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, return; } iova =3D result->iova; - vhost_iova_tree_remove(v->iova_tree, result); + 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)); @@ -944,7 +944,7 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *= v, DMAMap *needle, needle->perm =3D=3D IOMMU_RO); if (unlikely(r !=3D 0)) { error_setg_errno(errp, -r, "Cannot map region to device"); - vhost_iova_tree_remove(v->iova_tree, needle); + vhost_iova_tree_remove(v->iova_tree, *needle); } =20 return r =3D=3D 0; diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h index 16bbfdf..8528e5c 100644 --- a/include/qemu/iova-tree.h +++ b/include/qemu/iova-tree.h @@ -73,7 +73,7 @@ int iova_tree_insert(IOVATree *tree, const DMAMap *map); * all the mappings that are included in the provided range will be * removed from the tree. Here map->translated_addr is meaningless. */ -void iova_tree_remove(IOVATree *tree, const DMAMap *map); +void iova_tree_remove(IOVATree *tree, DMAMap map); =20 /** * iova_tree_find: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 303447a..a49e7e6 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -244,7 +244,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa = *v, void *addr) error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); } =20 - vhost_iova_tree_remove(tree, map); + vhost_iova_tree_remove(tree, *map); } =20 static size_t vhost_vdpa_net_cvq_cmd_len(void) @@ -297,7 +297,7 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, return true; =20 dma_map_err: - vhost_iova_tree_remove(v->iova_tree, &map); + vhost_iova_tree_remove(v->iova_tree, map); return false; } =20 diff --git a/util/iova-tree.c b/util/iova-tree.c index fee530a..5367897 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -164,11 +164,11 @@ void iova_tree_foreach(IOVATree *tree, iova_tree_iter= ator iterator) g_tree_foreach(tree->tree, iova_tree_traverse, iterator); } =20 -void iova_tree_remove(IOVATree *tree, const DMAMap *map) +void iova_tree_remove(IOVATree *tree, DMAMap map) { const DMAMap *overlap; =20 - while ((overlap =3D iova_tree_find(tree, map))) { + while ((overlap =3D iova_tree_find(tree, &map))) { g_tree_remove(tree->tree, overlap); } } --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662103195; cv=none; d=zohomail.com; s=zohoarc; b=hiWKknKA3Uv+RAwItFEidH7tF8En8kGmd7O3JP11eaVs7i7SIIGL/yiaOx/PCRYY1uCxEd/LTIvWcygd1ahcZkH+mEpft+PRJwn+OO8dHm7vNq8GHHpB/TAw09x4CyJrj/09AlQfbKdhWDMjSuYtXM1vDWpU+9FsEdRWWd+ujmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662103195; 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=3CO8o09Cbv3EhQM8RnEVZK+OtlOPIn1lTkOLHv1CnTE=; b=W5zsRrwlF/h5kxLCaRIGUF+JOaUd+/tstzznMBjnRuHvC5atRCDd2MeZJerhZhyoNZfpCrPs/Ux2VH5rtENGrsPJR3LnPNX1FcavmvC6jYEf1+DkCaKaA6Y/4j9srLAun9hIzUO1NM2tVs8HpLHufXwnXb28M8mmDJFnNnSdK8A= 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 1662103195704327.99567477716926; Fri, 2 Sep 2022 00:19:55 -0700 (PDT) Received: from localhost ([::1]:50820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0y2-0007wX-7M for importer@patchew.org; Fri, 02 Sep 2022 03:19:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O2-0007e5-S6 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20619) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O1-0004wj-CJ for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:42 -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-550-iu3V1kjHMnS-ylObdgQ0PQ-1; Fri, 02 Sep 2022 02:41:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A14C29AA386; Fri, 2 Sep 2022 06:41:57 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0CBB1415137; Fri, 2 Sep 2022 06:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100960; 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=3CO8o09Cbv3EhQM8RnEVZK+OtlOPIn1lTkOLHv1CnTE=; b=X3wV3vFnZH5SfC9IR+zJMX82JmsIRFzj5HFR7fgz+ZXQAT/ZwsuWJ+W+GiTuRv5Ak2Uxbw RDzbTmIsfsSvxdzQBbMO49rLGcC14qF0AbliTUvEzyO1nccFtUYAM6J9iK4NV7ayEtaMlE kT8IDn1C7pQ8k1S2vPuSjHum6pjqWAg= X-MC-Unique: iu3V1kjHMnS-ylObdgQ0PQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Jason Wang Subject: [PULL 04/21] vdpa: Remove SVQ vring from iova_tree at shutdown Date: Fri, 2 Sep 2022 14:41:21 +0800 Message-Id: <20220902064138.56468-5-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662103197801100001 From: Eugenio P=C3=A9rez 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 Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 87e0ad3..e16e0e2 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -898,6 +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); + if (unlikely(r < 0)) { + error_report("Unable to unmap SVQ vring: %s (%d)", g_strerror(-r),= -r); + return false; + } + + vhost_iova_tree_remove(v->iova_tree, *result); return r =3D=3D 0; } =20 --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101707; cv=none; d=zohomail.com; s=zohoarc; b=NM2TZPjpZFvsfbSzPDP7YDPQVXjNbf94xoOfRiaamc3fTNv8Ja8Pc3+IyfDdL9D9JuGFB06dZUXbimxmgbt7W5h8zv3mijQlDDDvtqTbyABcArp67ZHbjKxp05FcNH9eB3nj40RrFy0TGdX0MfvD9qwCxGlGNkiT4SgjbadsZwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101707; 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=hpL+WzmcRefiHk4+5YNb2+iLVYt8rr8sZxmtKMXuM+4=; b=GVRyTj9R0jtbJXXhd7FFSzW1uFX0KmpyxqGbKecuEltu+tlqObtCqkMicvyyDCMASRu0kCREWq0YAdhlP65l8E5Z+ZncSs1pXebINVJT0evrhSj7U9mTh7uOZzIPYlAhxUcIU6+hUolNaF330BD7gU6hBwMaUPFAylctSx4dlQs= 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 1662101707404611.4680574371328; Thu, 1 Sep 2022 23:55:07 -0700 (PDT) Received: from localhost ([::1]:56358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0a1-0007kf-E8 for importer@patchew.org; Fri, 02 Sep 2022 02:55:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NR-0007Cc-VN for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NQ-0004m5-Ck for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:05 -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-589-8GZvU4BdOiGao3uRixSSCg-1; Fri, 02 Sep 2022 02:42:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E8283810796; Fri, 2 Sep 2022 06:42:00 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED3D11415137; Fri, 2 Sep 2022 06:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100923; 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=hpL+WzmcRefiHk4+5YNb2+iLVYt8rr8sZxmtKMXuM+4=; b=XLqS5eGiTBRUPBOxePoa0sKOUMlIGc+HXG9PkUzxcx/POYzWm2e5HJbphjj6MR6D1qFb7E 7t9h8pjVpkwdT7FNDM4spL8kAc70nJX2pzhVjgfBwrXQBi3g7KroRaDeqAzUiXP8E+buDY +8kq1JTc2gqrFjNkjUnkX0NjerY8e80= X-MC-Unique: 8GZvU4BdOiGao3uRixSSCg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Jason Wang Subject: [PULL 05/21] vdpa: Make SVQ vring unmapping return void Date: Fri, 2 Sep 2022 14:41:22 +0800 Message-Id: <20220902064138.56468-6-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101707961100001 From: Eugenio P=C3=A9rez 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 Signed-off-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 e16e0e2..e208dd0 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,38 +893,33 @@ 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)) { error_report("Unable to unmap SVQ vring: %s (%d)", g_strerror(-r),= -r); - return false; + return; } =20 vhost_iova_tree_remove(v->iova_tree, *result); - return r =3D=3D 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 /** @@ -1095,26 +1090,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) @@ -1131,10 +1122,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.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101710; cv=none; d=zohomail.com; s=zohoarc; b=FC0366wckYqv8kU7gesTfDqZ4Izm+sQpNtFLn0Hr02Uu41TTep3e8TzJ5tBwndpNRJy7o6QJtwegBihVbEtgBNsDrQfTjd8MOWXJENbkHV9nFStmoXUhUoQRRa10fnvIFocA68GfD3HhDeZVBjUiX5toCAB+YGcMzaIQ8pOQIt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101710; 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=leLZWe3M4GBhmVFw5b/TzZU049vylqkNsjkHliu3Ttw=; b=aUF/MLDdTax5UomqZjn7ojyI3q9YfNZW0iCrbWGWVWkvxHb9YBQ8iuX6489P8mR3air+GzkelbWnI03IffRVu9rpCIt7R5cCQpElYKNIsxgyOZDC+bkvpMp3GCSFiY3h9By5PLLKop0XBnVSgPBkGdcHa98yzLCXcWQUQZXWRM4= 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 166210171081183.63742256876833; Thu, 1 Sep 2022 23:55:10 -0700 (PDT) Received: from localhost ([::1]:45770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0a3-0007tE-Lo for importer@patchew.org; Fri, 02 Sep 2022 02:55:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NV-0007Dx-Ru for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NT-0004mM-RM for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:09 -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-437-MY3mFJ1hPvWhFOvQP84s-g-1; Fri, 02 Sep 2022 02:42:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91E35294EDFB; Fri, 2 Sep 2022 06:42:03 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2011A1410DD5; Fri, 2 Sep 2022 06:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100927; 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=leLZWe3M4GBhmVFw5b/TzZU049vylqkNsjkHliu3Ttw=; b=a3wFbEfnoJQhOuuHVRJ+SWKnA2zdcoWjPiKgjJPPlxcyNR0BcTmfOtqRwibKO/RNslHVQ0 cEvG4sOUhR+weCLq8YLJ6aU+/1QDz4IQffAfG50ryqaZoS3gsQNKYRUyA6BSTbLlBB8nlm rQMTntqTK3+V/DtktUZLImypVkVD8c8= X-MC-Unique: MY3mFJ1hPvWhFOvQP84s-g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Jason Wang Subject: [PULL 06/21] vhost: Always store new kick fd on vhost_svq_set_svq_kick_fd Date: Fri, 2 Sep 2022 14:41:23 +0800 Message-Id: <20220902064138.56468-7-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101711732100002 From: Eugenio P=C3=A9rez 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 Signed-off-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 e495672..82a784d 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.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101837; cv=none; d=zohomail.com; s=zohoarc; b=EkFyk6OCsdRfPUWy34+QTrRUfTiD0bVZ3TzP5MvyDqfe+VltGSG6/jx75pueJId22YrTsyHKC9Lbe+2x86FnBRq6Bh03V9bapwLD9QFljFsI3uJ+a5pmb7TPpwG/h/ViBb8pJhHEOO9D1RZqldmjE/un0F1f+Phr/QHUvkODz1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101837; 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=9GvdDv77s9cgLjNjrIRj1ihctbxD/wkmiEJstIgW/JA=; b=aBtohHFhkuz72cH7MErP9TAGZAiT/Rgfpbqfu0Gvc/4gczSc7e36f5YCs7wAefdfd8ZD5fKPAs3KZylplY7qIiKD4CVfx1pMf8vEISYmU9qSXqXubm/gNt45Kd8ZVw4LObQc8srjIMn2ePn8Kv22httdIJJA6RBhO1szI7kHumU= 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 1662101836999516.84676607357; Thu, 1 Sep 2022 23:57:16 -0700 (PDT) Received: from localhost ([::1]:34682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0c7-0001My-Sg for importer@patchew.org; Fri, 02 Sep 2022 02:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NZ-0007GS-DK for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NW-0004mq-PD for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:13 -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-57-LalUjqWQNcyGgzecuJMnMg-1; Fri, 02 Sep 2022 02:42:06 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A62185A58F; Fri, 2 Sep 2022 06:42:06 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40CB814152E0; Fri, 2 Sep 2022 06:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100930; 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=9GvdDv77s9cgLjNjrIRj1ihctbxD/wkmiEJstIgW/JA=; b=gdsBwsrCu5X1AtlnHq+eLP8YU8E7WF6wz96pUeMED+hYXQgUCVokX2UGkgsVIAaEi+GM+K oVKUpzgLxOt4w4IVbqHfJo4cgBU0cpmYs6aQh6A5m7juAgbw0wcaL05WYt6ENtdWh+FPZO QMDuYKjBnrzandoAENl9o/8QOo7QaTc= X-MC-Unique: LalUjqWQNcyGgzecuJMnMg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 07/21] vdpa: Use ring hwaddr at vhost_vdpa_svq_unmap_ring Date: Fri, 2 Sep 2022 14:41:24 +0800 Message-Id: <20220902064138.56468-8-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101838288100001 From: Eugenio P=C3=A9rez Reduce code duplication. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-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 e208dd0..23ae5ef 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 @@ -909,17 +911,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 /** @@ -997,7 +996,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.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102036; cv=none; d=zohomail.com; s=zohoarc; b=M2uCZbSwPhpsG5g0expli2jrkB3BOIVgNKZl13yMDXkb7VHRV7eY/kmBJW3iJy23dE4/vg5KiQpux92olLWzfiE7C9SBIAzVpuYrGP/hwdZw1/6P1UwRIXteTelQfSF7LlByY6x2neYiVtgB+LHAAP9ZjFUtSygZ2YM5+rDuiTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102036; 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=wnv1noCjE1V5jYpwP9EQh2A3IAfncn1XkxXLN/q4H3E=; b=eWsx2tb1iSBk0nd/dxGftsfzpeO9+mfVeXXygBkemj+jLfV+Juxsl1/e58gbSC8PRxbiAxXsE1VXBnBRheT21rR0358sf3+6sfe0R/t5nzA1BCadU98xtZJleW9jTO5uzsN3oLHfdqT9Pgk11k/pCPDzLzibU/zjVwRefAQaicg= 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 16621020365331009.6194686803668; Fri, 2 Sep 2022 00:00:36 -0700 (PDT) Received: from localhost ([::1]:35978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0fK-0005AY-F2 for importer@patchew.org; Fri, 02 Sep 2022 03:00:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Na-0007KT-Vn for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:34492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0NZ-0004oj-BZ for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:14 -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-393-TscABihZPZCjgfPqJ1l8rg-1; Fri, 02 Sep 2022 02:42:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2927E800124; Fri, 2 Sep 2022 06:42:09 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12B4D1410DD5; Fri, 2 Sep 2022 06:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100932; 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=wnv1noCjE1V5jYpwP9EQh2A3IAfncn1XkxXLN/q4H3E=; b=RLpddy1ijCAdViHtVqXp/JckH19hsqQzQKEniBmF7NwiiGRvwEeTCVqpmprTMqOmOPUKEA oUbt6dar+A5Ha1ncR/7f/rMZR33lDvn1GCI22KsehBa494JV8GC5HGzxqWCTYuLMY8poh2 JmGud0H5YfRiZNKnlu0dE2WHrNEH5UQ= X-MC-Unique: TscABihZPZCjgfPqJ1l8rg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 08/21] vhost: stop transfer elem ownership in vhost_handle_guest_kick Date: Fri, 2 Sep 2022 14:41:25 +0800 Message-Id: <20220902064138.56468-9-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102038112100001 From: Eugenio P=C3=A9rez It was easier to allow vhost_svq_add to handle the memory. Now that we will allow qemu to add elements to a SVQ without the guest's knowledge, it's better to handle it in the caller. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 82a784d..a1261d4 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -233,9 +233,6 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) /** * Add an element to a SVQ. * - * The caller must check that there is enough slots for the new element. It - * takes ownership of the element: In case of failure not ENOSPC, it is fr= ee. - * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, @@ -252,7 +249,6 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const stru= ct iovec *out_sg, =20 ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_= head); if (unlikely(!ok)) { - g_free(elem); return -EINVAL; } =20 @@ -293,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) virtio_queue_set_notification(svq->vq, false); =20 while (true) { - VirtQueueElement *elem; + g_autofree VirtQueueElement *elem; int r; =20 if (svq->next_guest_avail_elem) { @@ -324,12 +320,14 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) * queue the current guest descriptor and ignore kicks * until some elements are used. */ - svq->next_guest_avail_elem =3D elem; + svq->next_guest_avail_elem =3D g_steal_pointer(&elem); } =20 /* VQ is full or broken, just return and ignore kicks */ return; } + /* elem belongs to SVQ or external caller now */ + elem =3D NULL; } =20 virtio_queue_set_notification(svq->vq, true); --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102124; cv=none; d=zohomail.com; s=zohoarc; b=YvuGs7tkbZ3zMRuLvKxliOEWLZgk8qaJVsxNJH/RUA+dxqO8G+FwqXmNfBjeI08P4oSEFqhWL+Hu3zwzLe5rz5jvdPFWo8oF/D7e/+MTi3n7T/jvuTVIpajO3kQ1q/oSvi3k6txId+sexSeN7UAtwpuV9GdIuFzKDQvFdCNteeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102124; 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=I/lmbKOtkRyBBL+1bpv4dgCB+EGPsbTN5h0glQP4X9M=; b=AtJe/p4swGCTgBpeMT+G+lXtVxMdWKa1CdsG2di6iLydg0VHBb5tSxMVdTsqykqWAfKzmRGVBCJaLKeI23vgj4eQ3a2uE0Jref+3d+ADqlIVdR+VBV52oF6fUvrU53R37gBCn5nJR7B0k8rj9rxJ47py5UL9S1u7AJYVCFdWNhk= 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 1662102124736412.09776397159624; Fri, 2 Sep 2022 00:02:04 -0700 (PDT) Received: from localhost ([::1]:34772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0gl-0007BH-JK for importer@patchew.org; Fri, 02 Sep 2022 03:02:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Ne-0007RS-Lk for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nd-0004rW-3X for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42: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-349-3siDr3FyNI26BMpYYKk3VQ-1; Fri, 02 Sep 2022 02:42:12 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFF533C0ED68; Fri, 2 Sep 2022 06:42:11 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D491C1415138; Fri, 2 Sep 2022 06:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100935; 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=I/lmbKOtkRyBBL+1bpv4dgCB+EGPsbTN5h0glQP4X9M=; b=d1h/b3m1iB18fLYlaNqEiK5qd0mALi/86sK2C/0c2YMd9aZBdSeMkRZX9DZH68wEXw24iT TNcjreRP8cby4cgjbnPVnmP2kxW22FWF0t9hPPaXmH2Tw/Z51UElkiqf0bwcId5out/1Iq fYIX1G6a6dJtl/dXDy7El8wFFCMKfRU= X-MC-Unique: 3siDr3FyNI26BMpYYKk3VQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 09/21] vhost: use SVQ element ndescs instead of opaque data for desc validation Date: Fri, 2 Sep 2022 14:41:26 +0800 Message-Id: <20220902064138.56468-10-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102126540100001 From: Eugenio P=C3=A9rez Since we're going to allow SVQ to add elements without the guest's knowledge and without its own VirtQueueElement, it's easier to check if an element is a valid head checking a different thing than the VirtQueueElement. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index a1261d4..b35aeef 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -414,7 +414,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } =20 - if (unlikely(!svq->desc_state[used_elem.id].elem)) { + if (unlikely(!svq->desc_state[used_elem.id].ndescs)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", svq->vdev->name, used_elem.id); @@ -422,6 +422,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, } =20 num =3D svq->desc_state[used_elem.id].ndescs; + svq->desc_state[used_elem.id].ndescs =3D 0; last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); svq->desc_next[last_used_chain] =3D svq->free_head; svq->free_head =3D used_elem.id; --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662101710; cv=none; d=zohomail.com; s=zohoarc; b=GPmh2wTqyv3003ImiBaPYilgkW6CV7HIiagFvoOHDzp1vk2b/Eo24tHi3ITxrafC+oZgFmSdrP4lX18WQE7J92QFgCi0jqkavfBRTrC2SZDs2RUsqN9+p/bO8K4GJZLAFmphn8xQFqW0K62ZDQDiON/+B0rH8f0IcA7VD3UhxjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662101710; 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=Ez+pjZ5RN+UQVMXyW1wujNjESHc87Iu5UQTLDPMiMT0=; b=S49oRXQ2g793gRsC72RSdLAdYXw6hAn8G3hnVHIL1tah6FcE2F4bcRS1FTVxV4mUXyE+mlgxnVNT8ZHLOWqps+AerxeN8by9diuewLxVRANpS/Lv8jDj++kpFp8icGeZ2QV5WrIkoG7prKDp+GBpj8X3ZRii13hvk6eGj4wowo4= 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 1662101710236477.4262419453412; Thu, 1 Sep 2022 23:55:10 -0700 (PDT) Received: from localhost ([::1]:45768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0a3-0007q2-Ti for importer@patchew.org; Fri, 02 Sep 2022 02:55:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Ne-0007RH-89 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nc-0004rl-NH for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:17 -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-112-Pqc0F6uIPRWTgb2olU5HZw-1; Fri, 02 Sep 2022 02:42:15 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B675B80C8F0; Fri, 2 Sep 2022 06:42:14 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BBAA1410F3C; Fri, 2 Sep 2022 06:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100936; 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=Ez+pjZ5RN+UQVMXyW1wujNjESHc87Iu5UQTLDPMiMT0=; b=fCTBW7k1YiBbp/Jl0IXluU4+hBnACLY4ghqC4rWvAVFc6TAAzxKkmFZBI/3WEdaZWgH2r7 PuMrhpkqjTcNxInnkIKTiihMjtrWOJXnfL1Ksou9boJfkRaoBJjrsaT09vp77hjnqMQwzf nlJF1danCQBgcPzkQ88jShVDTOJwgbY= X-MC-Unique: Pqc0F6uIPRWTgb2olU5HZw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 10/21] vhost: Delete useless read memory barrier Date: Fri, 2 Sep 2022 14:41:27 +0800 Message-Id: <20220902064138.56468-11-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662101711725100001 From: Eugenio P=C3=A9rez As discussed in previous series [1], this memory barrier is useless with the atomic read of used idx at vhost_svq_more_used. Deleting it. [1] https://lists.nongnu.org/archive/html/qemu-devel/2022-07/msg02616.html Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b35aeef..8df5296 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -509,9 +509,6 @@ size_t vhost_svq_poll(VhostShadowVirtqueue *svq) if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { return 0; } - - /* Make sure we read new used_idx */ - smp_rmb(); } while (true); } =20 --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102041; cv=none; d=zohomail.com; s=zohoarc; b=NLotBk0/8+4xNHY+TUta8SJZL5tWjFJHdMi4vLSQoG0Ffh4128wyc7q1NXVZLCyzI24AqrhqU4maxapPjMHFTb4F6KTQqgW8yreb3mIGkCm4IoCqMLYkNRW1c2hpNIbNYMbZYHmIJBxZ5h7zhNmB9MiQeTvb5EwG+53qFtyKyAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102041; 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=9saPVCh8T4IehUtQlv1O2OGfG92vvOC962JAEJaw0kg=; b=BnRhDVN+vThH73Rjywi28oCqkmIX1xN7q7/Bzu4h0coAwgkdtjzKndhm8FYU6XG1gqfGHAou3iDFnyPJ+FjBQmjClwpxQXCxUjyixLz64K+rTt0DrKeg9VmMYxTdbrlHSOR9k72ithNn3J35xJK7MvkLUTy5ngoCfabpQ97Doek= 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 16621020411908.888619376516658; Fri, 2 Sep 2022 00:00:41 -0700 (PDT) Received: from localhost ([::1]:35982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0fQ-0005QL-47 for importer@patchew.org; Fri, 02 Sep 2022 03:00:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nk-0007Tf-Mg for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nh-0004sW-A4 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:23 -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-104-2nhEZQ5QPsiiR-Iun5PYAg-1; Fri, 02 Sep 2022 02:42:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 886AF2919EB3; Fri, 2 Sep 2022 06:42:17 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E5481415137; Fri, 2 Sep 2022 06:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100940; 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=9saPVCh8T4IehUtQlv1O2OGfG92vvOC962JAEJaw0kg=; b=QEcf8vl2Ln2Z6+XlUDsZFmxTvJ3bic7UBZwDO4OV/SAFojaYSc5uaWQnNHLPlhMRAmx5K8 TRNU3j8j3+ii9L9AsnzyDH13otW7QaBk+nQ4LRIZM5W5WSJD1RQnJKA0is3Nma34kZ9NcZ 5cv4EQMpLP5kFVWx/nCNIrUsI1hhFXQ= X-MC-Unique: 2nhEZQ5QPsiiR-Iun5PYAg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 11/21] vhost: Do not depend on !NULL VirtQueueElement on vhost_svq_flush Date: Fri, 2 Sep 2022 14:41:28 +0800 Message-Id: <20220902064138.56468-12-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102041926100001 From: Eugenio P=C3=A9rez Since QEMU will be able to inject new elements on CVQ to restore the state, we need not to depend on a VirtQueueElement to know if a new element has been used by the device or not. Instead of check that, check if there are new elements only using used idx on vhost_svq_flush. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 8df5296..e8e5bbc 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -499,17 +499,20 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, size_t vhost_svq_poll(VhostShadowVirtqueue *svq) { int64_t start_us =3D g_get_monotonic_time(); + uint32_t len; + do { - uint32_t len; - VirtQueueElement *elem =3D vhost_svq_get_buf(svq, &len); - if (elem) { - return len; + if (vhost_svq_more_used(svq)) { + break; } =20 if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { return 0; } } while (true); + + vhost_svq_get_buf(svq, &len); + return len; } =20 /** --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102333; cv=none; d=zohomail.com; s=zohoarc; b=J51ZuRA/xaXq1FzSD6zFbLqm1V3AJ/ghDHeSkrtdhMwQ5RINcJ0ekPSU2LksqF6/3DBnHc1F0X/NzWbaxWlWTYUbNZnKMH/eRVcujNz0e2BkZBAXQYO4olivO6VUTLea6trR/BP4oF0LqCjIaw+MfCfgo/6uOb7uzgxbY5oEkt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102333; 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=PrL/nq2PBSqRg4ImZtAPGIA5yNJmc+nFiCG6RUEFerE=; b=H/pIGgWaYBW73Jh8VLax5Yrcyhl5nx7IUWm6pNyrVha1OtUGToLCiqKKb27qLguCuwI4NKqi3C5T0yFkpvt3Plz3Fxa2s2oZg7Q22gjglyVz6CkEyACnVQQ6sF3r5GKfKzD07PS0AXujSyNtFjWuFS0+h9EUdX+MTRR1uSwfygY= 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 166210233326439.8335396381176; Fri, 2 Sep 2022 00:05:33 -0700 (PDT) Received: from localhost ([::1]:47276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0k8-0002jI-1b for importer@patchew.org; Fri, 02 Sep 2022 03:05:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nl-0007Tw-Up for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nk-0004uO-Ez for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:25 -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-154-2ZACYCNWM0WXCP8MU2TpjQ-1; Fri, 02 Sep 2022 02:42:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B79C1C0515E; Fri, 2 Sep 2022 06:42:20 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FAD91410F3C; Fri, 2 Sep 2022 06:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100943; 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=PrL/nq2PBSqRg4ImZtAPGIA5yNJmc+nFiCG6RUEFerE=; b=PAZEvIyfT6mUNxswazSbWwZEtMLUMvrzOi4Nu5agGih6PI8JGDcrwZDFN6mGvKuQSL8P0U m3p0G8YnJ/iDLXXJOIkD+CAdT9dG26ewoA+/NYUWG4S+8twTsnwoCXU4xMkyJDBvwSWWG4 gr8UyA2clKFgo8WkMOVSAjhBPcPXA+4= X-MC-Unique: 2ZACYCNWM0WXCP8MU2TpjQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 12/21] vhost_net: Add NetClientInfo start callback Date: Fri, 2 Sep 2022 14:41:29 +0800 Message-Id: <20220902064138.56468-13-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102333654100003 From: Eugenio P=C3=A9rez This is used by the backend to perform actions before the device is started. In particular, vdpa net use it to map CVQ buffers to the device, so it can send control commands using them. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 7 +++++++ include/net/net.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ccac5b7..2e0baeb 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -244,6 +244,13 @@ static int vhost_net_start_one(struct vhost_net *net, struct vhost_vring_file file =3D { }; int r; =20 + if (net->nc->info->start) { + r =3D net->nc->info->start(net->nc); + if (r < 0) { + return r; + } + } + r =3D vhost_dev_enable_notifiers(&net->dev, dev); if (r < 0) { goto fail_notifiers; diff --git a/include/net/net.h b/include/net/net.h index 523136c..ad9e800 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -44,6 +44,7 @@ typedef struct NICConf { =20 typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); +typedef int (NetStart)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); typedef void (NetCleanup) (NetClientState *); @@ -71,6 +72,7 @@ typedef struct NetClientInfo { NetReceive *receive_raw; NetReceiveIOV *receive_iov; NetCanReceive *can_receive; + NetStart *start; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; QueryRxFilter *query_rx_filter; --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102368; cv=none; d=zohomail.com; s=zohoarc; b=c5e6Hh6HAgPVj0z0NKLC5Y+9KuixW5EFU443htqRkYDYCyQwTW1RLPWQ4vjwr7FX3Xm2OqWkogxPG3wnu4rOjUe4D8GTSlUFnNYykKGAApq6p1J8KWzGXLmB/XSF5qGYYRwr8z5dmTSzvCn8eUc7AqMFiC+wiaPOZ/lEnlcBFFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102368; 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=pP8QYxxdqXx+AFoVsWcfM2sQG+bN+PKVF28RGrfE9W4=; b=ePunjup/bImP20bOkrd/G29DlDvvsP4NvhNwHYHc096rP5B+TMADgQqJjQnBaRJYRMw5lE/QEzS9F67RIjr33hLvAHzdiLpR7UuTKNQyQ8t2DNfl1ZXDnTWDy0nVQk0fkAwSefL4yiFCmtXu2JtoNMkvnE52IMP+drq1NEQ3Li8= 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 1662102368207526.1920485674818; Fri, 2 Sep 2022 00:06:08 -0700 (PDT) Received: from localhost ([::1]:47280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0kg-0002tW-J5 for importer@patchew.org; Fri, 02 Sep 2022 03:06:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0No-0007VT-KG for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nn-0004v4-5O for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:28 -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-447--SNA6DrnMuKQxojxabiOFw-1; Fri, 02 Sep 2022 02:42:23 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26CF6101A58E; Fri, 2 Sep 2022 06:42:23 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 066291415137; Fri, 2 Sep 2022 06:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100946; 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=pP8QYxxdqXx+AFoVsWcfM2sQG+bN+PKVF28RGrfE9W4=; b=Q+b84ow8kKJagGbJ0ALbLrBL6f2cU/t0JkHw1I1TzyJuMEgq7gq+jPac8rkSjtqF3VD11k 2/YYwFrPQtLn6DtVWyaDx1JRmrN1dP9YmjIsG07fiDe0qhiyTvmk/Fg4NrAOOA0EAKChyt lYJ+Gf5z/qG5ZhaFlcvhQ2sWUDin3bM= X-MC-Unique: -SNA6DrnMuKQxojxabiOFw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 13/21] vhost_net: Add NetClientInfo stop callback Date: Fri, 2 Sep 2022 14:41:30 +0800 Message-Id: <20220902064138.56468-14-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102370416100001 From: Eugenio P=C3=A9rez Used by the backend to perform actions after the device is stopped. In particular, vdpa net use it to unmap CVQ buffers to the device, cleaning the actions performed in prepare(). Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 3 +++ include/net/net.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 2e0baeb..9d4b334 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -320,6 +320,9 @@ static void vhost_net_stop_one(struct vhost_net *net, net->nc->info->poll(net->nc, true); } vhost_dev_stop(&net->dev, dev); + if (net->nc->info->stop) { + net->nc->info->stop(net->nc); + } vhost_dev_disable_notifiers(&net->dev, dev); } =20 diff --git a/include/net/net.h b/include/net/net.h index ad9e800..476ad45 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -45,6 +45,7 @@ typedef struct NICConf { typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); typedef int (NetStart)(NetClientState *); +typedef void (NetStop)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); typedef void (NetCleanup) (NetClientState *); @@ -73,6 +74,7 @@ typedef struct NetClientInfo { NetReceiveIOV *receive_iov; NetCanReceive *can_receive; NetStart *start; + NetStop *stop; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; QueryRxFilter *query_rx_filter; --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102657; cv=none; d=zohomail.com; s=zohoarc; b=lEmZeVpiod/EcqBxq3uzVUezMxTXfZS/uscVDuLz9dXXHKUVedKsTZvN9d0aVD5sVRdS/17S6JPEZBvZaXfMOR3/rwlv+M/pPgmfTmwUiUVROgrDU+wHwfq3yeSTHcOPEvmTAvYLoSGA+GRpEKihP72B3Xhzqui2+oyXvUUIt0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102657; 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=vAi25fYk/f1WEDY6ubA811W6S3cvHAheh4iU+p4Rcdc=; b=JYO7sPqL0K3DkRy6EOKSrhEIq12cvpnE1LdMsuyt+U2SL7aFf84aUsD5/t65DKwr7nKUkprY1MaumTg0SvNvA1PFDmCfhRkfgIT4J/qvXLysHC4b6hv03csW3+EHXaGdpYyY0yDpsoSMbFpqVNdreALMoG87mligzhXGmWeitPE= 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 1662102657943815.176720329487; Fri, 2 Sep 2022 00:10:57 -0700 (PDT) Received: from localhost ([::1]:57510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0pM-0008PO-TG for importer@patchew.org; Fri, 02 Sep 2022 03:10:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nr-0007Vw-Fd for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0No-0004vH-Hx for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:29 -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-515-WYX4hVC_OAClgySspIOOmw-1; Fri, 02 Sep 2022 02:42:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB882101A56C; Fri, 2 Sep 2022 06:42:25 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D01AE1410DD5; Fri, 2 Sep 2022 06:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100948; 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=vAi25fYk/f1WEDY6ubA811W6S3cvHAheh4iU+p4Rcdc=; b=LIPp8R6NiHD4qmXcMjcCazPfjaI58VhfjBfpFWYk588kztvzdLPZWbdzLG+Xvhf9A/DQau BWAaY+/sG/XdZfoOiQ+OG1nEJM2JRkCs6/97tlcVd3dDqSZ69JOe0doXXrXHQDorh2xJAz VUgEJyUdpAniHPfNhXbbSYQZFG+39JM= X-MC-Unique: WYX4hVC_OAClgySspIOOmw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 14/21] vdpa: add net_vhost_vdpa_cvq_info NetClientInfo Date: Fri, 2 Sep 2022 14:41:31 +0800 Message-Id: <20220902064138.56468-15-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102659820100001 From: Eugenio P=C3=A9rez Next patches will add a new info callback to restore NIC status through CVQ. Since only the CVQ vhost device is needed, create it with a new NetClientInfo. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a49e7e6..1a597c2 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -334,6 +334,16 @@ static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState= *s, return true; } =20 +static NetClientInfo net_vhost_vdpa_cvq_info =3D { + .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, + .size =3D sizeof(VhostVDPAState), + .receive =3D vhost_vdpa_receive, + .cleanup =3D vhost_vdpa_cleanup, + .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, + .has_ufo =3D vhost_vdpa_has_ufo, + .check_peer_type =3D vhost_vdpa_check_peer_type, +}; + /** * Do not forward commands not supported by SVQ. Otherwise, the device cou= ld * accept it and qemu would not know how to update the device model. @@ -475,7 +485,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, nc =3D qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); } else { - nc =3D qemu_new_net_control_client(&net_vhost_vdpa_info, peer, + nc =3D qemu_new_net_control_client(&net_vhost_vdpa_cvq_info, peer, device, name); } snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102629; cv=none; d=zohomail.com; s=zohoarc; b=MoAyFTAXbVO6Rt7Coh3CXLKXdcyqN20WLjwhvYyZSjXflqOSyKHZTRdS4kF/2U2X350i9oViKBjWdKwaLEBN5zVXemaBe5XXW2Fmz6lztqAwHgzEl4/mRQ8Vd5Pp3kmW8wA2S7pegZb290fwjXQYS19ZPxMOv6xPyEMULvaF6ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102629; 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=fCdSJTlJFiKcgePKI08N5ksf/ERD5GDFOmK04jsK3ms=; b=l+8sct0Bb60VI3vtQblKam6RrTVyOTUYYBpEi74FQr6CKKolmt7/k3mqSv2H4otbfwN6IDVLOp/chpcZF0czeBwV4m1YkFDxTjmUCVBBZ3PUI2qwJ3dm0e6H90uO5F7ap3Pnf+THfZtMbXJIfWxPzpV3ZA+0aimDo22w6/fBCY4= 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 1662102629415936.93956368927; Fri, 2 Sep 2022 00:10:29 -0700 (PDT) Received: from localhost ([::1]:38032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0ot-0008FL-Ap for importer@patchew.org; Fri, 02 Sep 2022 03:10:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nv-0007YQ-Qy for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38197) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nt-0004vl-UD for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:35 -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-367-fWoMBPogPlyo62gdAlBtEA-1; Fri, 02 Sep 2022 02:42:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B9D3085A58E; Fri, 2 Sep 2022 06:42:28 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E21F1415137; Fri, 2 Sep 2022 06:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100953; 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=fCdSJTlJFiKcgePKI08N5ksf/ERD5GDFOmK04jsK3ms=; b=UeODz27/YfNJCZIXLTu0uKYMTmImcOhjxAVF5Zwqp+bX1DzJR2MiGOJ+vTFxNbJExGv0XZ zxyTuX4bdrpR7mtHCL9aY4AGRM2gb0TMxuoxLXLLmGU+BrmxMrFc8boYnu7vR+QmreHe1z u2IBsXC38mwdSlZL7vowByN4HXTGn1U= X-MC-Unique: fWoMBPogPlyo62gdAlBtEA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 15/21] vdpa: Move command buffers map to start of net device Date: Fri, 2 Sep 2022 14:41:32 +0800 Message-Id: <20220902064138.56468-16-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102629637100001 From: Eugenio P=C3=A9rez As this series will reuse them to restore the device state at the end of a migration (or a device start), let's allocate only once at the device start so we don't duplicate their map and unmap. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 123 ++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 1a597c2..452d10e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -263,29 +263,20 @@ static size_t vhost_vdpa_net_cvq_cmd_page_len(void) return ROUND_UP(vhost_vdpa_net_cvq_cmd_len(), qemu_real_host_page_size= ()); } =20 -/** Copy and map a guest buffer. */ -static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, - const struct iovec *out_data, - size_t out_num, size_t data_len, void *= buf, - size_t *written, bool write) +/** Map CVQ buffer. */ +static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, void *buf, size_t = size, + bool write) { DMAMap map =3D {}; int r; =20 - if (unlikely(!data_len)) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid legnth of %s buffer\n", - __func__, write ? "in" : "out"); - return false; - } - - *written =3D iov_to_buf(out_data, out_num, 0, buf, data_len); map.translated_addr =3D (hwaddr)(uintptr_t)buf; - map.size =3D vhost_vdpa_net_cvq_cmd_page_len() - 1; + map.size =3D size - 1; map.perm =3D write ? IOMMU_RW : IOMMU_RO, r =3D vhost_iova_tree_map_alloc(v->iova_tree, &map); if (unlikely(r !=3D IOVA_OK)) { error_report("Cannot map injected element"); - return false; + return r; } =20 r =3D vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(= ), buf, @@ -294,50 +285,58 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa = *v, goto dma_map_err; } =20 - return true; + return 0; =20 dma_map_err: vhost_iova_tree_remove(v->iova_tree, map); - return false; + return r; } =20 -/** - * Copy the guest element into a dedicated buffer suitable to be sent to N= IC - * - * @iov: [0] is the out buffer, [1] is the in one - */ -static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState *s, - VirtQueueElement *elem, - struct iovec *iov) +static int vhost_vdpa_net_cvq_start(NetClientState *nc) { - size_t in_copied; - bool ok; + VhostVDPAState *s; + int r; =20 - iov[0].iov_base =3D s->cvq_cmd_out_buffer; - ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, elem->out_sg, elem->out_= num, - vhost_vdpa_net_cvq_cmd_len(), iov[0].iov_b= ase, - &iov[0].iov_len, false); - if (unlikely(!ok)) { - return false; + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + s =3D DO_UPCAST(VhostVDPAState, nc, nc); + if (!s->vhost_vdpa.shadow_vqs_enabled) { + return 0; } =20 - iov[1].iov_base =3D s->cvq_cmd_in_buffer; - ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, NULL, 0, - sizeof(virtio_net_ctrl_ack), iov[1].iov_ba= se, - &in_copied, true); - if (unlikely(!ok)) { + r =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer, + vhost_vdpa_net_cvq_cmd_page_len(), false); + if (unlikely(r < 0)) { + return r; + } + + r =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer, + vhost_vdpa_net_cvq_cmd_page_len(), true); + if (unlikely(r < 0)) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); - return false; } =20 - iov[1].iov_len =3D sizeof(virtio_net_ctrl_ack); - return true; + return r; +} + +static void vhost_vdpa_net_cvq_stop(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + if (s->vhost_vdpa.shadow_vqs_enabled) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer); + } } =20 static NetClientInfo net_vhost_vdpa_cvq_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), .receive =3D vhost_vdpa_receive, + .start =3D vhost_vdpa_net_cvq_start, + .stop =3D vhost_vdpa_net_cvq_stop, .cleanup =3D vhost_vdpa_cleanup, .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, .has_ufo =3D vhost_vdpa_has_ufo, @@ -348,19 +347,17 @@ static NetClientInfo net_vhost_vdpa_cvq_info =3D { * Do not forward commands not supported by SVQ. Otherwise, the device cou= ld * accept it and qemu would not know how to update the device model. */ -static bool vhost_vdpa_net_cvq_validate_cmd(const struct iovec *out, - size_t out_num) +static bool vhost_vdpa_net_cvq_validate_cmd(const void *out_buf, size_t le= n) { struct virtio_net_ctrl_hdr ctrl; - size_t n; =20 - n =3D iov_to_buf(out, out_num, 0, &ctrl, sizeof(ctrl)); - if (unlikely(n < sizeof(ctrl))) { + if (unlikely(len < sizeof(ctrl))) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid legnth of out buffer %zu\n", __func__, = n); + "%s: invalid legnth of out buffer %zu\n", __func__, = len); return false; } =20 + memcpy(&ctrl, out_buf, sizeof(ctrl)); switch (ctrl.class) { case VIRTIO_NET_CTRL_MAC: switch (ctrl.cmd) { @@ -392,10 +389,14 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, VhostVDPAState *s =3D opaque; size_t in_len, dev_written; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - /* out and in buffers sent to the device */ - struct iovec dev_buffers[2] =3D { - { .iov_base =3D s->cvq_cmd_out_buffer }, - { .iov_base =3D s->cvq_cmd_in_buffer }, + /* Out buffer sent to both the vdpa device and the device model */ + struct iovec out =3D { + .iov_base =3D s->cvq_cmd_out_buffer, + }; + /* In buffer sent to the device */ + const struct iovec dev_in =3D { + .iov_base =3D s->cvq_cmd_in_buffer, + .iov_len =3D sizeof(virtio_net_ctrl_ack), }; /* in buffer used for device model */ const struct iovec in =3D { @@ -405,17 +406,15 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, int r =3D -EINVAL; bool ok; =20 - ok =3D vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); - if (unlikely(!ok)) { - goto out; - } - - ok =3D vhost_vdpa_net_cvq_validate_cmd(&dev_buffers[0], 1); + out.iov_len =3D iov_to_buf(elem->out_sg, elem->out_num, 0, + s->cvq_cmd_out_buffer, + vhost_vdpa_net_cvq_cmd_len()); + ok =3D vhost_vdpa_net_cvq_validate_cmd(s->cvq_cmd_out_buffer, out.iov_= len); if (unlikely(!ok)) { goto out; } =20 - r =3D vhost_svq_add(svq, &dev_buffers[0], 1, &dev_buffers[1], 1, elem); + r =3D vhost_svq_add(svq, &out, 1, &dev_in, 1, elem); if (unlikely(r !=3D 0)) { if (unlikely(r =3D=3D -ENOSPC)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", @@ -435,13 +434,13 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, goto out; } =20 - memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status)); if (status !=3D VIRTIO_NET_OK) { goto out; } =20 status =3D VIRTIO_NET_ERR; - virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, 1); + virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, &out, 1); if (status !=3D VIRTIO_NET_OK) { error_report("Bad CVQ processing in model"); } @@ -454,12 +453,6 @@ out: } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); g_free(elem); - if (dev_buffers[0].iov_base) { - vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[0].iov_base); - } - if (dev_buffers[1].iov_base) { - vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[1].iov_base); - } return r; } =20 --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102893; cv=none; d=zohomail.com; s=zohoarc; b=jvq7VMEczmTzrCTOo72L2LQIha8+bHhn5Nb3HxoVqSHnM7beIKY6Fvv8+Ruui5seNtO/BIKsfzTWjc8RE+KJjH+VwUHoJqYiLe6Kqn0cFJg+DY8f5ZteqdtvQZAgvwpXhs6fuR5TtfUvcAf4Xatamg9SyLHw7D5ImYsFvec7e6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102893; 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=25oxyVesuZucLld4PLzEbpPV66KPt5EKpAOBu7pz71Y=; b=A5uapNA6wRyeyyEadwtRwd3bDglBAN9q0iBLxLezOUdVpzbZhaCi3mp0YwVFV40ldYPLchdIfY2LaiFWzXE+EugysyfQ0898CHL0g+kcJpYsDod7j+MI+yOgWfuQ9z0Iwq6aN7gaTmmvfW+4peraPfeusqxJJR2HCtImQ82zb/8= 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 1662102893724156.80970336291773; Fri, 2 Sep 2022 00:14:53 -0700 (PDT) Received: from localhost ([::1]:55586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0t8-0004Oc-C7 for importer@patchew.org; Fri, 02 Sep 2022 03:14:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nx-0007ZP-Bd for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nv-0004vw-LD for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:37 -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-537-WBGvePzwOQGO3y0JdQZH_w-1; Fri, 02 Sep 2022 02:42:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FEE1101A56C; Fri, 2 Sep 2022 06:42:31 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 695601415137; Fri, 2 Sep 2022 06:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100955; 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=25oxyVesuZucLld4PLzEbpPV66KPt5EKpAOBu7pz71Y=; b=A4PCWEr8JU2nT2QML3z+ZX+yOyE6H6rlbtkQXZg0lPL8dVi3tElPylHGViqS0kGRR039vh ujaU5Fd1Qt8qcydtFVK0XSkOCuh6hyxs5mE3lZpPJXkIeDJ7m84RJvu7tCmF1uAHRqN8Dq WfigzVPety+v8OIbfIfEyrfbmKyxn+w= X-MC-Unique: WBGvePzwOQGO3y0JdQZH_w-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 16/21] vdpa: extract vhost_vdpa_net_cvq_add from vhost_vdpa_net_handle_ctrl_avail Date: Fri, 2 Sep 2022 14:41:33 +0800 Message-Id: <20220902064138.56468-17-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102895492100001 From: Eugenio P=C3=A9rez So we can reuse it to inject state messages. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang -- v7: * Remove double free error v6: * Do not assume in buffer sent to the device is sizeof(virtio_net_ctrl_ack) v5: * Do not use an artificial !NULL VirtQueueElement * Use only out size instead of iovec dev_buffers for these functions. Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 59 ++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 452d10e..3575bf6 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -331,6 +331,38 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc) } } =20 +static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, + size_t in_len) +{ + /* Buffers for the device */ + const struct iovec out =3D { + .iov_base =3D s->cvq_cmd_out_buffer, + .iov_len =3D out_len, + }; + const struct iovec in =3D { + .iov_base =3D s->cvq_cmd_in_buffer, + .iov_len =3D sizeof(virtio_net_ctrl_ack), + }; + VhostShadowVirtqueue *svq =3D g_ptr_array_index(s->vhost_vdpa.shadow_v= qs, 0); + int r; + + r =3D vhost_svq_add(svq, &out, 1, &in, 1, NULL); + if (unlikely(r !=3D 0)) { + if (unlikely(r =3D=3D -ENOSPC)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", + __func__); + } + return r; + } + + /* + * We can poll here since we've had BQL from the time we sent the + * descriptor. Also, we need to take the answer before SVQ pulls by it= self, + * when BQL is released + */ + return vhost_svq_poll(svq); +} + static NetClientInfo net_vhost_vdpa_cvq_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), @@ -387,23 +419,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, void *opaque) { VhostVDPAState *s =3D opaque; - size_t in_len, dev_written; + size_t in_len; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; /* Out buffer sent to both the vdpa device and the device model */ struct iovec out =3D { .iov_base =3D s->cvq_cmd_out_buffer, }; - /* In buffer sent to the device */ - const struct iovec dev_in =3D { - .iov_base =3D s->cvq_cmd_in_buffer, - .iov_len =3D sizeof(virtio_net_ctrl_ack), - }; /* in buffer used for device model */ const struct iovec in =3D { .iov_base =3D &status, .iov_len =3D sizeof(status), }; - int r =3D -EINVAL; + ssize_t dev_written =3D -EINVAL; bool ok; =20 out.iov_len =3D iov_to_buf(elem->out_sg, elem->out_num, 0, @@ -414,21 +441,11 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, goto out; } =20 - r =3D vhost_svq_add(svq, &out, 1, &dev_in, 1, elem); - if (unlikely(r !=3D 0)) { - if (unlikely(r =3D=3D -ENOSPC)) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", - __func__); - } + dev_written =3D vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status)); + if (unlikely(dev_written < 0)) { goto out; } =20 - /* - * We can poll here since we've had BQL from the time we sent the - * descriptor. Also, we need to take the answer before SVQ pulls by it= self, - * when BQL is released - */ - dev_written =3D vhost_svq_poll(svq); if (unlikely(dev_written < sizeof(status))) { error_report("Insufficient written data (%zu)", dev_written); goto out; @@ -436,7 +453,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadow= Virtqueue *svq, =20 memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status)); if (status !=3D VIRTIO_NET_OK) { - goto out; + return VIRTIO_NET_ERR; } =20 status =3D VIRTIO_NET_ERR; @@ -453,7 +470,7 @@ out: } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); g_free(elem); - return r; + return dev_written < 0 ? dev_written : 0; } =20 static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102886; cv=none; d=zohomail.com; s=zohoarc; b=FKftswmNytLeLljF+3yr6dHUrAQFtb6Jiv37vSCu1BVl6kig4sxgUPWM88P2UEfVXcHpiWD2JFL1HFy8GMLRhOk2LrK4CpDtCtj+FPX+3WtcX3WAzABsAFqrxvAGqgcAYzZYNodgMIWDTAn82/BgceldN/DzRKwKdyGyC32URn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102886; 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=O3PvhGKdwoknSbt99qtirFcte1LSvf6Bbljcr+M3oo8=; b=Zb7qBjniA+hEGf66jTUIFR8DTsyRbOfeOx6Ddb7yOvRG5QlKtiARJdeIY8nl6uU4HXpO03KFKNyxu4zjCMTaslz0uZonRXDxPbCadcfCrmpyctt1kzfyPkJ40xSUSdesSP49L0VAxdaV6WwIEBWMmmPzCk8nhMPfTeK4QQTsT3Y= 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 1662102886046310.9680032019029; Fri, 2 Sep 2022 00:14:46 -0700 (PDT) Received: from localhost ([::1]:55584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0t1-0004KV-LX for importer@patchew.org; Fri, 02 Sep 2022 03:14:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O0-0007Zq-Mu for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0Nx-0004wF-AZ for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:38 -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-587-49HmXTqNMR6F4Vo3gEg0gg-1; Fri, 02 Sep 2022 02:42:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5232E1857F0F; Fri, 2 Sep 2022 06:42:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D6CE1415137; Fri, 2 Sep 2022 06:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100956; 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=O3PvhGKdwoknSbt99qtirFcte1LSvf6Bbljcr+M3oo8=; b=MSB59ktGwP+U50tqVvmz+1LJBcnV7grNABbTNMn6yINIBFw/NdegOwGGDWEBAkLIMu0t1m TLTL1ERdq68HW+JUUOqxPpGuDGoFdt2cxv6S4ZuOqejhdZm7A68rrgigMVUAu0kJFln4fh KC4xrK/o+6sEa2ldly1d/y59hCaJNjc= X-MC-Unique: 49HmXTqNMR6F4Vo3gEg0gg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 17/21] vhost_net: add NetClientState->load() callback Date: Fri, 2 Sep 2022 14:41:34 +0800 Message-Id: <20220902064138.56468-18-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102887776100001 From: Eugenio P=C3=A9rez It allows per-net client operations right after device's successful start. In particular, to load the device status. Vhost-vdpa net will use it to add the CVQ buffers to restore the device status. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 7 +++++++ include/net/net.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 9d4b334..d28f8b9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -281,6 +281,13 @@ static int vhost_net_start_one(struct vhost_net *net, } } } + + if (net->nc->info->load) { + r =3D net->nc->info->load(net->nc); + if (r < 0) { + goto fail; + } + } return 0; fail: file.fd =3D -1; diff --git a/include/net/net.h b/include/net/net.h index 476ad45..81d0b21 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -45,6 +45,7 @@ typedef struct NICConf { typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); typedef int (NetStart)(NetClientState *); +typedef int (NetLoad)(NetClientState *); typedef void (NetStop)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); @@ -74,6 +75,7 @@ typedef struct NetClientInfo { NetReceiveIOV *receive_iov; NetCanReceive *can_receive; NetStart *start; + NetLoad *load; NetStop *stop; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662103202; cv=none; d=zohomail.com; s=zohoarc; b=KdorCdWCAGQYuqcRHR4hyBESFJi4om88zAca/yugTc2TVFVSjn+fb2OxjPlphsrLwsZMYz7vDz2lC7Dvr6PF0C9bUU2OBcG3pwZMSCKjafjzA7SNV99ScZh74nvx6xgo7XV1iEBJlFZGR9mCkaAr/fIPjAX5uiBQtwGpO3XgUSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662103202; 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=BhyPCbno7HOfAM4E5mN/cOhZxJGtVTvduZl3+uMBpIw=; b=MG2DA3z3/CI0NGA1EfrZujkF+UE82RVnwpcjF2k7SadOsTG4ISN6aeqF69L6RmgQngiNg3mnrvprADPPswIDtCL8MLsFI096U/wDJxciHXKF6liKMvd5C91OFdHYZymGVFz7U6WkhS1v/ZeOwUEwq7vyzjPeYqzA/u7mUs62V8Q= 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 1662103202046132.544273139325; Fri, 2 Sep 2022 00:20:02 -0700 (PDT) Received: from localhost ([::1]:50822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0y8-00083z-Sw for importer@patchew.org; Fri, 02 Sep 2022 03:20:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O2-0007cg-3E for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O0-0004wU-Eu for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:41 -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-230-dae65KHMNvWS0MfxhHz8xA-1; Fri, 02 Sep 2022 02:42:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5CA9580A0BF; Fri, 2 Sep 2022 06:42:37 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08EF11410F3C; Fri, 2 Sep 2022 06:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100958; 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=BhyPCbno7HOfAM4E5mN/cOhZxJGtVTvduZl3+uMBpIw=; b=QzVreTkLOGKEmsvvqgNoR/pgNaGhZ/iCBeaRBKZ7vJ3iPXQXQozkWirdTIrBrI0Oc8jssH OYJ0AecJeRaOZTnlEK+IHz3yRb6vCx2UoqH21IM+/+J7upOGleDgKz0FNl5AA+oMgXYGYq UqZmOjp57Fp2U51oKDD2Y8li+y9H+kY= X-MC-Unique: dae65KHMNvWS0MfxhHz8xA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 18/21] vdpa: Add virtio-net mac address via CVQ at start Date: Fri, 2 Sep 2022 14:41:35 +0800 Message-Id: <20220902064138.56468-19-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662103202791100001 From: Eugenio P=C3=A9rez This is needed so the destination vdpa device see the same state a the guest set in the source. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 3575bf6..640434d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -363,11 +363,51 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState = *s, size_t out_len, return vhost_svq_poll(svq); } =20 +static int vhost_vdpa_net_load(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + const struct vhost_vdpa *v =3D &s->vhost_vdpa; + const VirtIONet *n; + uint64_t features; + + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + if (!v->shadow_vqs_enabled) { + return 0; + } + + n =3D VIRTIO_NET(v->dev->vdev); + features =3D n->parent_obj.guest_features; + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl =3D { + .class =3D VIRTIO_NET_CTRL_MAC, + .cmd =3D VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + char *cursor =3D s->cvq_cmd_out_buffer; + ssize_t dev_written; + + memcpy(cursor, &ctrl, sizeof(ctrl)); + cursor +=3D sizeof(ctrl); + memcpy(cursor, n->mac, sizeof(n->mac)); + + dev_written =3D vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + sizeof(n-= >mac), + sizeof(virtio_net_ctrl_ack)); + if (unlikely(dev_written < 0)) { + return dev_written; + } + + return *((virtio_net_ctrl_ack *)s->cvq_cmd_in_buffer) !=3D VIRTIO_= NET_OK; + } + + return 0; +} + static NetClientInfo net_vhost_vdpa_cvq_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), .receive =3D vhost_vdpa_receive, .start =3D vhost_vdpa_net_cvq_start, + .load =3D vhost_vdpa_net_load, .stop =3D vhost_vdpa_net_cvq_stop, .cleanup =3D vhost_vdpa_cleanup, .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102039; cv=none; d=zohomail.com; s=zohoarc; b=OKZmGlIEsrB8mhKunO0vWI3VOdmtRXQkQ/WP4SvrHsZ9amMaAVicPtagbWhHvt9hI/Gs4aUR3P0Dc2TJkU5DmuN8IoGsXPoTUNz8GfI+TC3El2zFkNoVQCWBiC2b/twzkeSoP7qfb+O+SJpfTzPvTDVK4ZwYi1QWWY5Uiv65V0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102039; 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=TtUTd8r1fge626PNl5J/5RzVHh5u24KgbDDd4nQWNlw=; b=iTyCNtjy1TVlmswG982D1iPpk43Lu1o/0G3FtuTlqJ5UNQFK1h4c8Oe8+vtRdY9bpd+bQQf2VZWS45K1pHNpyOMn1CTIBJqdTpuMLOU3Q3AMtEBdhdUCoOIX03j1DGKrLxeBYOttQd1WpH4fMZ3eK+Wx2+tgmhEixB7ZsDopqM4= 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 1662102039308418.1305583140012; Fri, 2 Sep 2022 00:00:39 -0700 (PDT) Received: from localhost ([::1]:35980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0fN-0005OL-V5 for importer@patchew.org; Fri, 02 Sep 2022 03:00:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O6-0007nA-3c for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37073) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0O4-0004xR-F2 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:45 -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-339-LhdPsycbMwueXnT5eGHaQw-1; Fri, 02 Sep 2022 02:42:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 481F73810797; Fri, 2 Sep 2022 06:42:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C6DE1415137; Fri, 2 Sep 2022 06:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100963; 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=TtUTd8r1fge626PNl5J/5RzVHh5u24KgbDDd4nQWNlw=; b=hNE5p3p0yPgbaiAm9h6Jy9qvxjJbxo24jPIZwgMqGOGq35THE6G88S5zkuIRoI+GmVsHOP 3c51seOjVa33DX/cFtSeZQydjXVAs3bZy8mjM5fWpoUgg6Lk4Sh24DWOkl7aE64j5GVfQP ugzD76Eis684lWLQtwQDSfwtoFMbGdA= X-MC-Unique: LhdPsycbMwueXnT5eGHaQw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang Subject: [PULL 19/21] vdpa: Delete CVQ migration blocker Date: Fri, 2 Sep 2022 14:41:36 +0800 Message-Id: <20220902064138.56468-20-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102039728100003 From: Eugenio P=C3=A9rez We can restore the device state in the destination via CVQ now. Remove the migration blocker. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 15 --------------- include/hw/virtio/vhost-vdpa.h | 1 - net/vhost-vdpa.c | 2 -- 3 files changed, 18 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 23ae5ef..7468e44 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1033,13 +1033,6 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *= dev) return true; } =20 - if (v->migration_blocker) { - int r =3D migrate_add_blocker(v->migration_blocker, &err); - if (unlikely(r < 0)) { - return false; - } - } - for (i =3D 0; i < v->shadow_vqs->len; ++i) { VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); @@ -1082,10 +1075,6 @@ err: vhost_svq_stop(svq); } =20 - if (v->migration_blocker) { - migrate_del_blocker(v->migration_blocker); - } - return false; } =20 @@ -1101,10 +1090,6 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *d= ev) VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); vhost_vdpa_svq_unmap_rings(dev, svq); } - - if (v->migration_blocker) { - migrate_del_blocker(v->migration_blocker); - } } =20 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index d10a893..1111d85 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -35,7 +35,6 @@ typedef struct vhost_vdpa { bool shadow_vqs_enabled; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; - Error *migration_blocker; GPtrArray *shadow_vqs; const VhostShadowVirtqueueOps *shadow_vq_ops; void *shadow_vq_ops_opaque; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 640434d..6ce68fc 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -555,8 +555,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; - error_setg(&s->vhost_vdpa.migration_blocker, - "Migration disabled: vhost-vdpa uses CVQ."); } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102475; cv=none; d=zohomail.com; s=zohoarc; b=Ft+XLyM0+4w/iN3e02bGzbxFqdT4YnxfrDj3brsGSmK8JCm86aqXqYh6TeLV36p6vKW39xxjDLXkQQWJaYcB2rzkV5KRrgQfzaoN6DhsR+cXpyqpaeW4aw56410gsP3a/7UbR3dt07AkUo5bmJlIfYUYZ5AxTIG5vOJgCw3Unww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102475; 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=xc0N2REmDmqyeL22Uv1jv8lmIURq2MzxLIYIY6P6MFk=; b=JI9ZSvPTa6b3+FTWezR2SWuVp+XKHtjWYZ3Qv/pUH8XwD8NvpG1E7lUEAyvBMDRcfU+nAnAsNGQhhs0z5mC1PgAzuRmtO8/WfiUO8PhW7QVN7UgOQy2EeI4nFUA9eYs/XjPMpDbifPOLc2FeEpBQAOf/0cKKRaVmaBATvI3N7So= 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 1662102475743845.4019404888394; Fri, 2 Sep 2022 00:07:55 -0700 (PDT) Received: from localhost ([::1]:52660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0mO-0004nW-Kc for importer@patchew.org; Fri, 02 Sep 2022 03:07:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0OC-00084i-Pg for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0OB-0004yB-7r for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:52 -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-639-bwJY4vwDM-SQdxZBI5uwfw-1; Fri, 02 Sep 2022 02:42:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BFC73C0ED69; Fri, 2 Sep 2022 06:42:44 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DAB71415138; Fri, 2 Sep 2022 06:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100970; 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=xc0N2REmDmqyeL22Uv1jv8lmIURq2MzxLIYIY6P6MFk=; b=Vf1vNMP6h8WDtkAX8MLFE5YCQ/3cVH+aGA/gYemx5ilMZ/+1T7MDIZdRXYT8UVDnQ9yevN upG2TdqN7LBXz4Jv2EM7TNvtah68tmeDyDwV88E+TNHm6X04Fyt8KkNBfRZ4xQ+mEsjbLk 5c10D9m2ZDKWCapXOqi9MjuE4Vsex1s= X-MC-Unique: bwJY4vwDM-SQdxZBI5uwfw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zhang Chen , Jason Wang Subject: [PULL 20/21] net/colo.c: Fix the pointer issue reported by Coverity. Date: Fri, 2 Sep 2022 14:41:37 +0800 Message-Id: <20220902064138.56468-21-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102476426100001 Content-Type: text/plain; charset="utf-8" From: Zhang Chen When enabled the virtio-net-pci, guest network packet will load the vnet_hdr. In COLO status, the primary VM's network packet maybe redirect to another VM, it needs filter-redirect enable the vnet_hdr flag at the same time, COLO-proxy will correctly parse the original network packet. If have any misconfiguration here, the vnet_hdr_len is wrong for parse the packet, the data+offset will point to wrong place. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo.c | 25 ++++++++++++++++--------- net/colo.h | 1 + net/trace-events | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/net/colo.c b/net/colo.c index 6b0ff56..fb2c36a 100644 --- a/net/colo.c +++ b/net/colo.c @@ -44,21 +44,28 @@ int parse_packet_early(Packet *pkt) { int network_length; static const uint8_t vlan[] =3D {0x81, 0x00}; - uint8_t *data =3D pkt->data + pkt->vnet_hdr_len; + uint8_t *data =3D pkt->data; uint16_t l3_proto; ssize_t l2hdr_len; =20 - if (data =3D=3D NULL) { - trace_colo_proxy_main_vnet_info("This packet is not parsed correct= ly, " - "pkt->vnet_hdr_len", pkt->vnet_hdr= _len); + assert(data); + + /* Check the received vnet_hdr_len then add the offset */ + if ((pkt->vnet_hdr_len > sizeof(struct virtio_net_hdr_v1_hash)) || + (pkt->size < sizeof(struct eth_header) + sizeof(struct vlan_header= ) + + pkt->vnet_hdr_len)) { + /* + * The received remote packet maybe misconfiguration here, + * Please enable/disable filter module's the vnet_hdr flag at + * the same time. + */ + trace_colo_proxy_main_vnet_info("This received packet load wrong ", + pkt->vnet_hdr_len, pkt->size); return 1; } - l2hdr_len =3D eth_get_l2_hdr_length(data); + data +=3D pkt->vnet_hdr_len; =20 - if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) { - trace_colo_proxy_main("pkt->size < ETH_HLEN"); - return 1; - } + l2hdr_len =3D eth_get_l2_hdr_length(data); =20 /* * TODO: support vlan. diff --git a/net/colo.h b/net/colo.h index 8b3e8d5..22fc303 100644 --- a/net/colo.h +++ b/net/colo.h @@ -18,6 +18,7 @@ #include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "standard-headers/linux/virtio_net.h" =20 #define HASHTABLE_MAX_SIZE 16384 =20 diff --git a/net/trace-events b/net/trace-events index 6af927b..823a071 100644 --- a/net/trace-events +++ b/net/trace-events @@ -9,7 +9,7 @@ vhost_user_event(const char *chr, int event) "chr: %s got e= vent: %d" =20 # colo.c colo_proxy_main(const char *chr) ": %s" -colo_proxy_main_vnet_info(const char *sta, int size) ": %s =3D %d" +colo_proxy_main_vnet_info(const char *sta, uint32_t vnet_hdr, int size) ":= %s pkt->vnet_hdr_len =3D %u, pkt->size =3D %d" =20 # colo-compare.c colo_compare_main(const char *chr) ": %s" --=20 2.7.4 From nobody Thu Dec 18 17:48:25 2025 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=1662102331; cv=none; d=zohomail.com; s=zohoarc; b=LNTQrA4f4FD+8Le60Q3dQpdSCpSZH0Hmm2+BUce6S+HzMJql25/9XpDF5QVAloH7e6Qg/DnXmDAnLDP98+mVDfy9KDVvTBT/vnb3eeK8K/X5hJNjMhsI9e9bBfpQ6/S9xPpWeFDbm9tj90PdwWS1KDyvJVgc+j/E6HQ9CQfLU1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662102331; 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=X5hlA04hUr7878cddYSPka4sAxAinhQT/7udNwXAJrI=; b=eTyqiPE78HT3HVVZLR9FrSMo38s0UJ15J5wp6qSJ1nb5BeH/RXsClgErNaUfGH6WSDn6H3+lbd/aeH80CMJ89bUVno4OM6jU7Zo0Ivsb9NirA0e9o1qu0lL4iiEVKrzEcdkr/YWKfjwAZRtDyP31HAXYL3mVLCaLFqwrLaPy+04= 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 1662102331424714.5862130498093; Fri, 2 Sep 2022 00:05:31 -0700 (PDT) Received: from localhost ([::1]:47278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU0k6-0002jg-8c for importer@patchew.org; Fri, 02 Sep 2022 03:05:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0OH-00086X-Nx for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU0OF-0004yW-MW for qemu-devel@nongnu.org; Fri, 02 Sep 2022 02:42:56 -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-20-jGMvYKeeMG2-R3aTx5hMiA-1; Fri, 02 Sep 2022 02:42:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47B9B80A0BC; Fri, 2 Sep 2022 06:42:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-152.pek2.redhat.com [10.72.12.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D02461415137; Fri, 2 Sep 2022 06:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662100974; 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=X5hlA04hUr7878cddYSPka4sAxAinhQT/7udNwXAJrI=; b=dg3U0lY5G69/CJmNLY6NBa+PXOrVKGfP/0hpAJWjHGDlrmpBY8hy+AwiUMPWOSR/WQ++U3 MG8fGofKgOZbOG/SD96o5nPqXm11dZkb1Oze/OS8Qn+DrBuU7N2DxdfvZgifVPlqaVzgwy MVOAWt1BJFFghLdofsbb/P8tPXaFT1I= X-MC-Unique: jGMvYKeeMG2-R3aTx5hMiA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zheyu Ma , Jason Wang Subject: [PULL 21/21] net: tulip: Restrict DMA engine to memories Date: Fri, 2 Sep 2022 14:41:38 +0800 Message-Id: <20220902064138.56468-22-jasowang@redhat.com> In-Reply-To: <20220902064138.56468-1-jasowang@redhat.com> References: <20220902064138.56468-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1662102331652100001 Content-Type: text/plain; charset="utf-8" From: Zheyu Ma The DMA engine is started by I/O access and then itself accesses the I/O registers, triggering a reentrancy bug. The following log can reveal it: =3D=3D5637=3D=3DERROR: AddressSanitizer: stack-overflow #0 0x5595435f6078 in tulip_xmit_list_update qemu/hw/net/tulip.c:673 #1 0x5595435f204a in tulip_write qemu/hw/net/tulip.c:805:13 #2 0x559544637f86 in memory_region_write_accessor qemu/softmmu/memory.c= :492:5 #3 0x5595446379fa in access_with_adjusted_size qemu/softmmu/memory.c:55= 4:18 #4 0x5595446372fa in memory_region_dispatch_write qemu/softmmu/memory.c #5 0x55954468b74c in flatview_write_continue qemu/softmmu/physmem.c:282= 5:23 #6 0x559544683662 in flatview_write qemu/softmmu/physmem.c:2867:12 #7 0x5595446833f3 in address_space_write qemu/softmmu/physmem.c:2963:18 #8 0x5595435fb082 in dma_memory_rw_relaxed qemu/include/sysemu/dma.h:87= :12 #9 0x5595435fb082 in dma_memory_rw qemu/include/sysemu/dma.h:130:12 #10 0x5595435fb082 in dma_memory_write qemu/include/sysemu/dma.h:171:12 #11 0x5595435fb082 in stl_le_dma qemu/include/sysemu/dma.h:272:1 #12 0x5595435fb082 in stl_le_pci_dma qemu/include/hw/pci/pci.h:910:1 #13 0x5595435fb082 in tulip_desc_write qemu/hw/net/tulip.c:101:9 #14 0x5595435f7e3d in tulip_xmit_list_update qemu/hw/net/tulip.c:706:9 #15 0x5595435f204a in tulip_write qemu/hw/net/tulip.c:805:13 Fix this bug by restricting the DMA engine to memories regions. Signed-off-by: Zheyu Ma Signed-off-by: Jason Wang --- hw/net/tulip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/tulip.c b/hw/net/tulip.c index 097e905..b9e42c3 100644 --- a/hw/net/tulip.c +++ b/hw/net/tulip.c @@ -70,7 +70,7 @@ static const VMStateDescription vmstate_pci_tulip =3D { static void tulip_desc_read(TULIPState *s, hwaddr p, struct tulip_descriptor *desc) { - const MemTxAttrs attrs =3D MEMTXATTRS_UNSPECIFIED; + const MemTxAttrs attrs =3D { .memory =3D true }; =20 if (s->csr[0] & CSR0_DBO) { ldl_be_pci_dma(&s->dev, p, &desc->status, attrs); @@ -88,7 +88,7 @@ static void tulip_desc_read(TULIPState *s, hwaddr p, static void tulip_desc_write(TULIPState *s, hwaddr p, struct tulip_descriptor *desc) { - const MemTxAttrs attrs =3D MEMTXATTRS_UNSPECIFIED; + const MemTxAttrs attrs =3D { .memory =3D true }; =20 if (s->csr[0] & CSR0_DBO) { stl_be_pci_dma(&s->dev, p, desc->status, attrs); --=20 2.7.4