From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236749; cv=none; d=zohomail.com; s=zohoarc; b=RU8xKtV5m2J1fGIExrCYTUdxfJ4HPEVoD6sJHR7kT0jDePW9SGUeKHBua50RFYqcAUFzSO1H1l1PKTexZxnzUPSSjnEcLf28GMoatWu0/jPpTkPn7mBknogARXmu4tJl3RAvqOutzfZqPkLAonyRv8Gbx2nMWa+XMkMV53uUFQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236749; 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=LTPD93mdkwqFWoWbm4Wn8FWGSk8O98DYcyDcvL0UTvg=; b=QkaShIgHKYiJFzPgvbVe8FDm1Ov4CztL5aTuuiO8eEpSztrU4k/pu/KmPaT2UPj4oR21oGcXvExFCluwOnFAgjs83zSqK7gKNlAOoKjV1CSDVwNRJNk/RbKMt6Kmt4EtNhSpfHpGpL+B4H2DRmuabNQWvXxZnB6wPvuqfzjqFdI= 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 1658236749262687.5427002803128; Tue, 19 Jul 2022 06:19:09 -0700 (PDT) Received: from localhost ([::1]:38036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDn80-0001It-76 for importer@patchew.org; Tue, 19 Jul 2022 09:19:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn5v-0006ri-Pk for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40405) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn5s-0004nh-P6 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:16:58 -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-675-Wl2M9tt1NxqVgg0oZW8WLg-1; Tue, 19 Jul 2022 09:16:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE0DA38149A7; Tue, 19 Jul 2022 13:16:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39731400E894; Tue, 19 Jul 2022 13:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236615; 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=LTPD93mdkwqFWoWbm4Wn8FWGSk8O98DYcyDcvL0UTvg=; b=ToBSMMoBP7Y6/wkepr0zOFGvCCsoA7NYzdSTyj+8adtAUnmZy6lvA7L3kswelbF5HsJEPx sNg/fQcI3/B5QW6Ri4NAg4khzlS5C4OmKrwoEPu1DO4R/uUq/h/VI/lLE43Uhgj9A3dSE/ klPDEMSvCZoRiAm9wrpJDhyWw4M4N3M= X-MC-Unique: Wl2M9tt1NxqVgg0oZW8WLg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang , "Michael S . Tsirkin" Subject: [PULL 01/24] vhost: move descriptor translation to vhost_svq_vring_write_descs Date: Tue, 19 Jul 2022 21:16:14 +0800 Message-Id: <20220719131637.46131-2-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236751402100001 From: Eugenio P=C3=A9rez It's done for both in and out descriptors so it's better placed here. Acked-by: Jason Wang Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 38 +++++++++++++++++++++++++++-------= ---- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 56c96eb..e2184a4 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -122,17 +122,35 @@ static bool vhost_svq_translate_addr(const VhostShado= wVirtqueue *svq, return true; } =20 -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, - const struct iovec *iovec, size_t num, - bool more_descs, bool write) +/** + * Write descriptors to SVQ vring + * + * @svq: The shadow virtqueue + * @sg: Cache for hwaddr + * @iovec: The iovec from the guest + * @num: iovec length + * @more_descs: True if more descriptors come in the chain + * @write: True if they are writeable descriptors + * + * Return true if success, false otherwise and print error. + */ +static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr = *sg, + const struct iovec *iovec, size_t = num, + bool more_descs, bool write) { uint16_t i =3D svq->free_head, last =3D svq->free_head; unsigned n; uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs =3D svq->vring.desc; + bool ok; =20 if (num =3D=3D 0) { - return; + return true; + } + + ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; } =20 for (n =3D 0; n < num; n++) { @@ -150,6 +168,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, hwaddr *sg, } =20 svq->free_head =3D le16_to_cpu(svq->desc_next[last]); + return true; } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -169,21 +188,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, return false; } =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, + elem->in_num > 0, false); if (unlikely(!ok)) { return false; } - vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, - elem->in_num > 0, false); - =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, + true); if (unlikely(!ok)) { return false; } =20 - vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); - /* * Put the entry in the available array (but don't update avail->idx u= ntil * they do sync). --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236764; cv=none; d=zohomail.com; s=zohoarc; b=PPM2U3YfDSvG/qqG3hcHIvp5ZfMqR3c6XgBLyvNe6UaP4iCYd6nkmxiCbx0EMQ1NIuFgJ5Nn8H/eycRymRGPvmdAt8GMqTFQ/ST9FkzwKfnEvzDrUpMOum1REFSQLZ0pG75YwYmcdyKLLn7ySJlHDdYVayWJrMQciIdDfa46xQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236764; 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=rMx4PxSCnLAC1FnWLntqrHVUXCJmVahYyt3ivJyFxO0=; b=GRxf8oZ5h0d9TjZxPyjxBT4tQ40egi+vV7G5ZxMq2T69Vk5GxLq7Iyb7VCUswpdZgtm5n1IzbyftngziGEKYdjbcSDFsZeToyn5ZWpI+tRndZuGkuBS/8+98QJETlWkCIHwLS3XpGgbRcRuxyrOlnceiuRHmH7PmZxZgN1iVZ4s= 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 1658236764727649.1329856919139; Tue, 19 Jul 2022 06:19:24 -0700 (PDT) Received: from localhost ([::1]:38394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDn8F-0001XQ-FA for importer@patchew.org; Tue, 19 Jul 2022 09:19:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn5z-000703-Js for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn5y-0004oG-17 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:03 -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-590-wm2cV97iM-W9ALUJqtToZQ-1; Tue, 19 Jul 2022 09:16:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8EBEB2813D2A; Tue, 19 Jul 2022 13:16:56 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5192B40CF8E5; Tue, 19 Jul 2022 13:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236621; 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=rMx4PxSCnLAC1FnWLntqrHVUXCJmVahYyt3ivJyFxO0=; b=EvPhXDH5W0BtFe6NucYnjYS0G9QqIt5jc2yxy3d93NW+oDBrAOdIBpPhZ6/LTOmvvUENoC T0DQhHdLRQglgkW5f+d5myVBkG7oC7L19u61PIQ5+b1cnzqn5G7escSZGujS1bcBIiM329 7AnwwxZLsY/Fw273ynnM4rd+VLqhFMo= X-MC-Unique: wm2cV97iM-W9ALUJqtToZQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 02/24] virtio-net: Expose MAC_TABLE_ENTRIES Date: Tue, 19 Jul 2022 21:16:15 +0800 Message-Id: <20220719131637.46131-3-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236765507100001 From: Eugenio P=C3=A9rez vhost-vdpa control virtqueue needs to know the maximum entries supported by the virtio-net device, so we know if it is possible to apply the filter. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 1 - include/hw/virtio/virtio-net.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7ad948e..f83e96e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -49,7 +49,6 @@ =20 #define VIRTIO_NET_VM_VERSION 11 =20 -#define MAC_TABLE_ENTRIES 64 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ =20 /* previously fixed value */ diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index eb87032..cce1c55 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -35,6 +35,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(VirtIONet, VIRTIO_NET) * and latency. */ #define TX_BURST 256 =20 +/* Maximum VIRTIO_NET_CTRL_MAC_TABLE_SET unicast + multicast entries. */ +#define MAC_TABLE_ENTRIES 64 + typedef struct virtio_net_conf { uint32_t txtimer; --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236953; cv=none; d=zohomail.com; s=zohoarc; b=K4A8sj740wBlzZUfBSKQhRqA9oRKsG6qB3YrBUDSNK1M17JyFUfGF5JHSuNkRK554HKoGoGBI9vCpCh2p0V4C79Y/de9x9Rm5ST1yYzMu9rC9iBl4PgfpklMUMVcSeFU/21TPmcyjXJTE4s2H4s/gmzeMYeT1AXSFie2ZQJxxeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236953; 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=qx4O63vQebB/eHlIzps2qcOgx5CD1xyJef2NC1lNKug=; b=I9j6whCu02ke7PpCMWtQWnR2xbEP6qPFyETWXRk8FVxs5UQffhCbNBd3T0Gvu0UY/a0vDyvuEZQ46naulesmSvsMoZSEVT4e+cK/zt3uXW19QSRxj1oVdRCss0PuiYWAntNn/YOQEjwVHxKCO84yNx5Q7BPrjWgMll1XKjk/jcY= 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 1658236953526187.11125586519074; Tue, 19 Jul 2022 06:22:33 -0700 (PDT) Received: from localhost ([::1]:47026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnBG-0007ed-94 for importer@patchew.org; Tue, 19 Jul 2022 09:22:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn61-000739-9U for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38330) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn5z-0004oV-BY for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:04 -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-612-_az1LHK2Ou6qbAc7xwMT1w-1; Tue, 19 Jul 2022 09:16:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7286D1C0BDE6; Tue, 19 Jul 2022 13:16:59 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3314540CFD0A; Tue, 19 Jul 2022 13:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236622; 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=qx4O63vQebB/eHlIzps2qcOgx5CD1xyJef2NC1lNKug=; b=S/GW3bjieB4+XvRFWRa1Mn01qKo5dR10J+Tl5b8jtobiwoeCghiVIpR7V+Vw1oaGSrGXWu d6puEEIUt+zZtg5yo14b5+DAj6D/RuUhgqHDtfQmPWyjOmQQR1hUjVGhVMy84JUMuCQpQ9 h8aDcCkQgoaguVrDDULwgMUwV03mOv8= X-MC-Unique: _az1LHK2Ou6qbAc7xwMT1w-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 03/24] virtio-net: Expose ctrl virtqueue logic Date: Tue, 19 Jul 2022 21:16:16 +0800 Message-Id: <20220719131637.46131-4-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236954534100001 From: Eugenio P=C3=A9rez This allows external vhost-net devices to modify the state of the VirtIO device model once the vhost-vdpa device has acknowledged the control commands. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 84 ++++++++++++++++++++++++--------------= ---- include/hw/virtio/virtio-net.h | 4 ++ 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f83e96e..dd0d056 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1433,57 +1433,71 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, return VIRTIO_NET_OK; } =20 -static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num) { VirtIONet *n =3D VIRTIO_NET(vdev); struct virtio_net_ctrl_hdr ctrl; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - VirtQueueElement *elem; size_t s; struct iovec *iov, *iov2; - unsigned int iov_cnt; + + if (iov_size(in_sg, in_num) < sizeof(status) || + iov_size(out_sg, out_num) < sizeof(ctrl)) { + virtio_error(vdev, "virtio-net ctrl missing headers"); + return 0; + } + + iov2 =3D iov =3D g_memdup2(out_sg, sizeof(struct iovec) * out_num); + s =3D iov_to_buf(iov, out_num, 0, &ctrl, sizeof(ctrl)); + iov_discard_front(&iov, &out_num, sizeof(ctrl)); + if (s !=3D sizeof(ctrl)) { + status =3D VIRTIO_NET_ERR; + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { + status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { + status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { + status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { + status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { + status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num); + } + + s =3D iov_from_buf(in_sg, in_num, 0, &status, sizeof(status)); + assert(s =3D=3D sizeof(status)); + + g_free(iov2); + return sizeof(status); +} + +static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; =20 for (;;) { + size_t written; elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; } - if (iov_size(elem->in_sg, elem->in_num) < sizeof(status) || - iov_size(elem->out_sg, elem->out_num) < sizeof(ctrl)) { - virtio_error(vdev, "virtio-net ctrl missing headers"); + + written =3D virtio_net_handle_ctrl_iov(vdev, elem->in_sg, elem->in= _num, + elem->out_sg, elem->out_num); + if (written > 0) { + virtqueue_push(vq, elem, written); + virtio_notify(vdev, vq); + g_free(elem); + } else { virtqueue_detach_element(vq, elem, 0); g_free(elem); break; } - - iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup2(elem->out_sg, - sizeof(struct iovec) * elem->out_num); - s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); - iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); - if (s !=3D sizeof(ctrl)) { - status =3D VIRTIO_NET_ERR; - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { - status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt= ); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { - status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { - status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_= cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { - status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cn= t); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { - status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { - status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cn= t); - } - - s =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(s= tatus)); - assert(s =3D=3D sizeof(status)); - - virtqueue_push(vq, elem, sizeof(status)); - virtio_notify(vdev, vq); - g_free(iov2); - g_free(elem); } } =20 diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index cce1c55..ef234ff 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -221,6 +221,10 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; }; =20 +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); =20 --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237159; cv=none; d=zohomail.com; s=zohoarc; b=RJojSePCYvb5r6VDUb++WAYy4UwWOaE3t0QD6uJNNNOB5KLvgGfzzivYblGa9b09CAnM18ZG3u9qoPnGRzIO50ikWoiCqd2cW4InsiCqaKDmM80+azq1UpLfoIuG34gFMFgVi4zwMVYs2qpfOm5KfHUZAQ1sL3wXJUF4Furwyxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237159; 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=2G4CfY7T1VZeOzHmVwzEz7gw1/UKh2ZTwHQxLW6ZvAw=; b=KOuWBzKmbf3WZP1+JiqLpdCZX9H0X9LoxHEBM78nTG3VfvFFTqG2KbIhHdM5dS/ov+y9rmeaA3GLYzx+lgG2pM39TN4b9AcqEkWT0SDEClnqvAdCvxtQ4RE4+/b05QzkOA0tRmr2kDRsikELbCk7yuOcyBdkKRi13RVd8+4xURA= 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 1658237159184676.8353675148246; Tue, 19 Jul 2022 06:25:59 -0700 (PDT) Received: from localhost ([::1]:55306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnEc-00051e-4I for importer@patchew.org; Tue, 19 Jul 2022 09:25:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn63-00079f-1U for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn61-0004og-J2 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:06 -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-177-CpCpCsJONhC2YZ1kGcYNKg-1; Tue, 19 Jul 2022 09:17:02 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0569138149A7; Tue, 19 Jul 2022 13:17:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 158DB40CFD0A; Tue, 19 Jul 2022 13:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236623; 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=2G4CfY7T1VZeOzHmVwzEz7gw1/UKh2ZTwHQxLW6ZvAw=; b=ZjpaobXgHYw+J0JG7SaC7IqTJz/spQxJujmKjBl8WM3euZY/2xH50FcKDz7gSroZx1jjCd h3+vRbcKGFsQcicupLQb8Ol6w9R7v8idmQOODPeAMHKxsQNn6h8rBQTg9YSq+WnGqBlotd LHLIjvzRzV+gafezUwUyFKxtVfa6R7o= X-MC-Unique: CpCpCsJONhC2YZ1kGcYNKg-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 04/24] vdpa: Avoid compiler to squash reads to used idx Date: Tue, 19 Jul 2022 21:16:17 +0800 Message-Id: <20220719131637.46131-5-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237160869100001 From: Eugenio P=C3=A9rez In the next patch we will allow busypolling of this value. The compiler have a running path where shadow_used_idx, last_used_idx, and vring used idx are not modified within the same thread busypolling. This was not an issue before since we always cleared device event notifier before checking it, and that could act as memory barrier. However, the busypoll needs something similar to kernel READ_ONCE. Let's add it here, separated from the polling. Signed-off-by: Eugenio P=C3=A9rez 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 e2184a4..560d07a 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -327,11 +327,12 @@ static void vhost_handle_guest_kick_notifier(EventNot= ifier *n) =20 static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) { + uint16_t *used_idx =3D &svq->vring.used->idx; if (svq->last_used_idx !=3D svq->shadow_used_idx) { return true; } =20 - svq->shadow_used_idx =3D cpu_to_le16(svq->vring.used->idx); + svq->shadow_used_idx =3D cpu_to_le16(*(volatile uint16_t *)used_idx); =20 return svq->last_used_idx !=3D svq->shadow_used_idx; } --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237349; cv=none; d=zohomail.com; s=zohoarc; b=XHAqXatWSl43ptDiguYGTeD4WEnGh0dFOSS836SmZH6m1etaDLrwkEtFJpyjTvPIhS3UkQJqOoGQSccAq9PDhmd5XjARi/1A5A13KjxZZyk+BnIC9nAeBOcV/zeQQ2XJPUe9DPpEjPHzOi2U4eigKRjhCEYNeur+1PSPkeghWSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237349; 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=ryMfQclSrOUn61q4ST6zQqq0N9vt00RrcjyO/iesoEM=; b=WtmRAqyDnTAtzvDaXcmr685+RraVNNO1U2rOM9r/t2OsWLgyfv32pRjPRMxXX2G8OqOHyUfmjF+mK9N9EQcpcDAPCZqA7/gtjPOlFkpSWk4Or6udkcRhHpd6JRi5g3i8oOheINVN/5hiU96TWRQCu6GLVjU7xzs47hd1WvZX45U= 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 1658237349845559.6383766457335; Tue, 19 Jul 2022 06:29:09 -0700 (PDT) Received: from localhost ([::1]:35484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnHg-0002Nk-Oz for importer@patchew.org; Tue, 19 Jul 2022 09:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn65-0007IX-P7 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55206) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn64-0004p3-8K for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:09 -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-422-uFjwaYSHMsaPbq26dtLOmQ-1; Tue, 19 Jul 2022 09:17:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0B8318A6532; Tue, 19 Jul 2022 13:17:04 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CE0040466AE; Tue, 19 Jul 2022 13:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236627; 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=ryMfQclSrOUn61q4ST6zQqq0N9vt00RrcjyO/iesoEM=; b=eqWrPZ58jG64Lc9XaFY3SBMcXjR5uBT2614Fmo20+ae8aZOyTwtp98HIbthaW0nOU11yv7 cRHDLIsAYYb+9SZTCjoRv0guVSGnbwTlkCkLonK/Ej2cwF+SVLekMXG7DkatJu2g0k6Sf3 N+RTy7arZjSmip/UxAziTj0WbQTCi2w= X-MC-Unique: uFjwaYSHMsaPbq26dtLOmQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 05/24] vhost: Reorder vhost_svq_kick Date: Tue, 19 Jul 2022 21:16:18 +0800 Message-Id: <20220719131637.46131-6-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237350136100001 From: Eugenio P=C3=A9rez Future code needs to call it from vhost_svq_add. No functional change intended. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 560d07a..043a185 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -215,6 +215,20 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *= svq, return true; } =20 +static void vhost_svq_kick(VhostShadowVirtqueue *svq) +{ + /* + * We need to expose the available array entries before checking the u= sed + * flags + */ + smp_mb(); + if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { + return; + } + + event_notifier_set(&svq->hdev_kick); +} + /** * Add an element to a SVQ. * @@ -235,20 +249,6 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, V= irtQueueElement *elem) return true; } =20 -static void vhost_svq_kick(VhostShadowVirtqueue *svq) -{ - /* - * We need to expose the available array entries before checking the u= sed - * flags - */ - smp_mb(); - if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { - return; - } - - event_notifier_set(&svq->hdev_kick); -} - /** * Forward available buffers. * --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236867; cv=none; d=zohomail.com; s=zohoarc; b=TQORabEqvKTpVBq21ZI2qFPVXDxvN2XX62HYr9JfL3NFYtuiNXozfbus/UTqyvy1w2YaP/jyjRA2Ca/Mdqj9ILCW8zumiANKMpeMnNJ5/7nBOlNNuLuVS5VWVAs7VnPXlRF9vObE5Ak53k7YVvGJD6PWRizogvX3ZxNPZ3mXRHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236867; 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=QUC2ZaTjux0OP8bd+spjLkqxbbUezAiJZe3HC4Wb1/8=; b=Ote+LL/HGOJjkkocK1sGfNVoEuLHS3mIMrxEW6TBT4IR4p+wKWYWw7VmO1ZIxuPLNun1sjxdqcbqU6KyR1FOtz04oHOUGBKhPxLKxJMjoT03JZ7LobjkeE+ph9J6Z0Buu8AkT6jNT6LxcaZjl/itxffCSjzTIea9x8tOPEvE8ms= 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 1658236867227451.57093058709086; Tue, 19 Jul 2022 06:21:07 -0700 (PDT) Received: from localhost ([::1]:44314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDn9u-0005Vk-2N for importer@patchew.org; Tue, 19 Jul 2022 09:21:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn67-0007KM-B6 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn65-0004pT-Sg for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:11 -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-318-gi6VUfCoOaK-0ttmigt_Hg-1; Tue, 19 Jul 2022 09:17:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B9CA88039AE; Tue, 19 Jul 2022 13:17:07 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 844E440CFD0A; Tue, 19 Jul 2022 13:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236629; 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=QUC2ZaTjux0OP8bd+spjLkqxbbUezAiJZe3HC4Wb1/8=; b=AUj7gas8ync8B+Pi09zAC1qrCJgDzvGEjwRNbwi4eQplZJ3R28B1QCVdHL4wBRguKtuUx5 sQU+6vv31HyFyyhOb8qNSxYPDpRVo/BhHIwHmg/9YRvnJrZYTaR6RTQhk8aRhRJcXUmFJh O6Dy7v/Np2Hf6G+Jq1WV1n0L5jO0nkk= X-MC-Unique: gi6VUfCoOaK-0ttmigt_Hg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 06/24] vhost: Move vhost_svq_kick call to vhost_svq_add Date: Tue, 19 Jul 2022 21:16:19 +0800 Message-Id: <20220719131637.46131-7-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236868095100001 From: Eugenio P=C3=A9rez The series needs to expose vhost_svq_add with full functionality, including kick Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 043a185..e272c33 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -246,6 +246,7 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, Vi= rtQueueElement *elem) } =20 svq->ring_id_maps[qemu_head] =3D elem; + vhost_svq_kick(svq); return true; } =20 @@ -306,7 +307,6 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) /* VQ is broken, just return and ignore any other kicks */ return; } - vhost_svq_kick(svq); } =20 virtio_queue_set_notification(svq->vq, true); --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236948; cv=none; d=zohomail.com; s=zohoarc; b=gkz5A9ZJxVVZG58MCStmIZ1VlpwZFrTgyKhh7mMk9d5M1M8oeehGbgePCDXzUgTgLuvqNpWTpNS2iUAtAPH0JWdDcJyU4vFWCGpnOjdqezocTPF5gTbrr9acW6vdeKRR0Kqj7J+fG/5Mj7kydrolF9WCQsU4z3jfkQfx0rH6GMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236948; 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=9NSQaMxFBqsbZB36hr3id0dMLvZuFrBmbbdTHzoh6go=; b=kkeN2MOnPVfAh+20G7EoXq5orzZlEwKhImNf+68AGzs07w+woL/84A+8NLaAMad7rI3wUvS68gg/WcNseAeMtw/PlEC3C4R2yeEWMPbTfbATs9giQbCfeb6ufzyL8IvID5eXN8EavXiJmbFqTh8Z16nF+ab/enH9mslVah1BQsw= 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 165823694871219.609890586898132; Tue, 19 Jul 2022 06:22:28 -0700 (PDT) Received: from localhost ([::1]:46650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnBD-0007Mr-MX for importer@patchew.org; Tue, 19 Jul 2022 09:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6D-0007Wt-Gf for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6A-0004qf-Ry for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:16 -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-151-SRWU885pNweu3ECvNL8Qxw-1; Tue, 19 Jul 2022 09:17:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9A6585A586; Tue, 19 Jul 2022 13:17:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE5F40CFD0A; Tue, 19 Jul 2022 13:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236634; 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=9NSQaMxFBqsbZB36hr3id0dMLvZuFrBmbbdTHzoh6go=; b=A/clC4kBFDdQzhqd2c/OKK2IHvP5ZH594QsYX113NGfvwUiaVy7bjmDA0E7BwBLgQi/DwY RPLFIMzaHDzSlu7MSpKwjQpkMauUsFfNdghw6y0U1w7dd/jiSN3IPebFYQucNOREPRYNew gKbE7t0QWQV6oiIf6+HwAeBVKjKoOlk= X-MC-Unique: SRWU885pNweu3ECvNL8Qxw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 07/24] vhost: Check for queue full at vhost_svq_add Date: Tue, 19 Jul 2022 21:16:20 +0800 Message-Id: <20220719131637.46131-8-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236950556100001 From: Eugenio P=C3=A9rez The series need to expose vhost_svq_add with full functionality, including checking for full queue. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 59 +++++++++++++++++++++-------------= ---- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e272c33..11302ea 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -233,21 +233,29 @@ 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, it is free and the = SVQ - * is considered broken. + * 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 */ -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static int vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) { unsigned qemu_head; - bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + unsigned ndescs =3D elem->in_num + elem->out_num; + bool ok; + + if (unlikely(ndescs > vhost_svq_available_slots(svq))) { + return -ENOSPC; + } + + ok =3D vhost_svq_add_split(svq, elem, &qemu_head); if (unlikely(!ok)) { g_free(elem); - return false; + return -EINVAL; } =20 svq->ring_id_maps[qemu_head] =3D elem; vhost_svq_kick(svq); - return true; + return 0; } =20 /** @@ -274,7 +282,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) =20 while (true) { VirtQueueElement *elem; - bool ok; + int r; =20 if (svq->next_guest_avail_elem) { elem =3D g_steal_pointer(&svq->next_guest_avail_elem); @@ -286,25 +294,24 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) break; } =20 - if (elem->out_num + elem->in_num > vhost_svq_available_slots(s= vq)) { - /* - * This condition is possible since a contiguous buffer in= GPA - * does not imply a contiguous buffer in qemu's VA - * scatter-gather segments. If that happens, the buffer ex= posed - * to the device needs to be a chain of descriptors at this - * moment. - * - * SVQ cannot hold more available buffers if we are here: - * queue the current guest descriptor and ignore further k= icks - * until some elements are used. - */ - svq->next_guest_avail_elem =3D elem; - return; - } - - ok =3D vhost_svq_add(svq, elem); - if (unlikely(!ok)) { - /* VQ is broken, just return and ignore any other kicks */ + r =3D vhost_svq_add(svq, elem); + if (unlikely(r !=3D 0)) { + if (r =3D=3D -ENOSPC) { + /* + * This condition is possible since a contiguous buffe= r in + * GPA does not imply a contiguous buffer in qemu's VA + * scatter-gather segments. If that happens, the buffer + * exposed to the device needs to be a chain of descri= ptors + * at this moment. + * + * SVQ cannot hold more available buffers if we are he= re: + * queue the current guest descriptor and ignore kicks + * until some elements are used. + */ + svq->next_guest_avail_elem =3D elem; + } + + /* VQ is full or broken, just return and ignore kicks */ return; } } --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237126; cv=none; d=zohomail.com; s=zohoarc; b=kEKjbnkpNZJl6B0rZ/eUfHXAJbxV/1uQU1mnA+vLz7eZxB1hRqljhZ/TGA2up/rUvlFD6bvZkFTwSMrSduvhPolKnW4egxjIsGWJiGiAqFbON6l0Qq2sZz4CFSWmT57grVVlyBz3lQtQAXLeKoC4VwJkWi5cb6g9sBW6ApgvUiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237126; 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=56Ayv//+8j9CiDqsn4qkQ9kqfCVczNDbd8/+QS1C7lE=; b=I/xgefZZa+STfLdnJ3cMHFadMd2+cauzabFvVxdDi5lU4hwMzHyBTb5oDxKr7GPZ/z60twV14Cna3npayTI95iCODZoXYh/W/zqYJ3kOQ8RBGo6BnZ6z+JMaWbM0Bt/vXyQ4CtNQQU16gVUGYtMOeQGzZbBsIfNlkASuY83ntlo= 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 1658237126892947.2255534543076; Tue, 19 Jul 2022 06:25:26 -0700 (PDT) Received: from localhost ([::1]:54924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnE5-0004mV-Hv for importer@patchew.org; Tue, 19 Jul 2022 09:25:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6D-0007X4-Q9 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23043) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6C-0004qj-0E for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:17 -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-226-NGRRk54FM_Gqra5CXtw1HA-1; Tue, 19 Jul 2022 09:17:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 973021C0BDE6; Tue, 19 Jul 2022 13:17:13 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F87E40CFD0A; Tue, 19 Jul 2022 13:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236635; 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=56Ayv//+8j9CiDqsn4qkQ9kqfCVczNDbd8/+QS1C7lE=; b=hkXmqpmUQvQ5LcBEECavIKr8K9YmsqtwM3vJF22NS3clE97y6KeoJ/3d1hwIENOU7SsAcs DrghrO9ri5D24NJnEZIFFmks5eRbguanWf6O5e6i7HqhDDmU9bC5mudfeq60xcH+uYkkTT w9z2vWFnzwpJ2/H1iSVrn6nfgh4TIb8= X-MC-Unique: NGRRk54FM_Gqra5CXtw1HA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang , "Michael S . Tsirkin" Subject: [PULL 08/24] vhost: Decouple vhost_svq_add from VirtQueueElement Date: Tue, 19 Jul 2022 21:16:21 +0800 Message-Id: <20220719131637.46131-9-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237128856100001 From: Eugenio P=C3=A9rez VirtQueueElement comes from the guest, but we're heading SVQ to be able to modify the element presented to the device without the guest's knowledge. To do so, make SVQ accept sg buffers directly, instead of using VirtQueueElement. Add vhost_svq_add_element to maintain element convenience. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 11302ea..e3afa2b 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -172,30 +172,31 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, unsigned *head) + const struct iovec *out_sg, size_t out_num, + const struct iovec *in_sg, size_t in_num, + unsigned *head) { unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; - g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(elem->out_num, elem->in_n= um)); + g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(out_num, in_num)); =20 *head =3D svq->free_head; =20 /* We need some descriptors here */ - if (unlikely(!elem->out_num && !elem->in_num)) { + if (unlikely(!out_num && !in_num)) { qemu_log_mask(LOG_GUEST_ERROR, "Guest provided element with no descriptors"); return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, - elem->in_num > 0, false); + ok =3D vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num >= 0, + false); if (unlikely(!ok)) { return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, - true); + ok =3D vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, tru= e); if (unlikely(!ok)) { return false; } @@ -237,17 +238,19 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ -static int vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) +static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *ou= t_sg, + size_t out_num, const struct iovec *in_sg, + size_t in_num, VirtQueueElement *elem) { unsigned qemu_head; - unsigned ndescs =3D elem->in_num + elem->out_num; + unsigned ndescs =3D in_num + out_num; bool ok; =20 if (unlikely(ndescs > vhost_svq_available_slots(svq))) { return -ENOSPC; } =20 - ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + 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; @@ -258,6 +261,14 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, Vi= rtQueueElement *elem) return 0; } =20 +/* Convenience wrapper to add a guest's element to SVQ */ +static int vhost_svq_add_element(VhostShadowVirtqueue *svq, + VirtQueueElement *elem) +{ + return vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_sg, + elem->in_num, elem); +} + /** * Forward available buffers. * @@ -294,7 +305,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) break; } =20 - r =3D vhost_svq_add(svq, elem); + r =3D vhost_svq_add_element(svq, elem); if (unlikely(r !=3D 0)) { if (r =3D=3D -ENOSPC) { /* --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237339; cv=none; d=zohomail.com; s=zohoarc; b=bThzKAQ9foVax76EnPARizDjX0BcmhiF5DcuoMQ0rDsUlao9ZOzb+tOz/ZexChqsii9zJuai6XchzxJ9hSUDAETKQYCmk13U/KGh8epUg2h9/9sCkkbEhBnoXCkl96HWMI8IvBxjgQooSdCVnSprDFx5bRTSdb9CYWcx5pzya2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237339; 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=nG1vk3JRfAN8G/naqtL7sxOwdR+NkK9CJ81dnKNKHlA=; b=lE51C+dTOmPKhYvGhU3eqkDXUwUm4NY81ojCcCB/G9G/QO8LmNuBFY/M2ntBaOYmlAG/26kjgQyy0DPUtPfeuGkcol1NJWMlhoQKleeU7GmwZ6VJETRGiSRjJ0ChFNmeRd87L+sgxWP0xoNuqbpWmmQMoHCCis/pEyhhtL7JX50= 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 1658237339397535.038662128899; Tue, 19 Jul 2022 06:28:59 -0700 (PDT) Received: from localhost ([::1]:35238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnHW-0002D6-4r for importer@patchew.org; Tue, 19 Jul 2022 09:28:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6G-0007jp-Rb for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6E-0004r2-Ul for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:20 -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-471-HiVGDPi5Mk6OiCTYiC9uXw-1; Tue, 19 Jul 2022 09:17:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B01285A585; Tue, 19 Jul 2022 13:17:16 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BFD340CF8E5; Tue, 19 Jul 2022 13:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236638; 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=nG1vk3JRfAN8G/naqtL7sxOwdR+NkK9CJ81dnKNKHlA=; b=KmZ5qN0xPNUI3kaxvimUxUgGApZqX6YuQ+kecUy3Q8iDNXhMlwl9EoU1Uu1y6Q7wOFNVyh kPzEp16j2jHmsd0FsOwEDROuni9DncKs9OOCGf0a25hTsemsL9DVJnYls9ZmqzMYY+PsRc yBIr0Vjml2warPV5EmQycrKTFkYZn2I= X-MC-Unique: HiVGDPi5Mk6OiCTYiC9uXw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 09/24] vhost: Add SVQDescState Date: Tue, 19 Jul 2022 21:16:22 +0800 Message-Id: <20220719131637.46131-10-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237340098100001 From: Eugenio P=C3=A9rez This will allow SVQ to add context to the different queue elements. This patch only store the actual element, no functional change intended. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++-------- hw/virtio/vhost-shadow-virtqueue.h | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e3afa2b..e4c09e2 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -256,7 +256,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, con= st struct iovec *out_sg, return -EINVAL; } =20 - svq->ring_id_maps[qemu_head] =3D elem; + svq->desc_state[qemu_head].elem =3D elem; vhost_svq_kick(svq); return 0; } @@ -411,21 +411,21 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShado= wVirtqueue *svq, return NULL; } =20 - if (unlikely(!svq->ring_id_maps[used_elem.id])) { + if (unlikely(!svq->desc_state[used_elem.id].elem)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", svq->vdev->name, used_elem.id); return NULL; } =20 - num =3D svq->ring_id_maps[used_elem.id]->in_num + - svq->ring_id_maps[used_elem.id]->out_num; + num =3D svq->desc_state[used_elem.id].elem->in_num + + svq->desc_state[used_elem.id].elem->out_num; 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 *len =3D used_elem.len; - return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); + return g_steal_pointer(&svq->desc_state[used_elem.id].elem); } =20 static void vhost_svq_flush(VhostShadowVirtqueue *svq, @@ -595,7 +595,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, memset(svq->vring.desc, 0, driver_size); svq->vring.used =3D qemu_memalign(qemu_real_host_page_size(), device_s= ize); memset(svq->vring.used, 0, device_size); - svq->ring_id_maps =3D g_new0(VirtQueueElement *, svq->vring.num); + svq->desc_state =3D g_new0(SVQDescState, svq->vring.num); svq->desc_next =3D g_new0(uint16_t, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { svq->desc_next[i] =3D cpu_to_le16(i + 1); @@ -620,7 +620,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + elem =3D g_steal_pointer(&svq->desc_state[i].elem); if (elem) { virtqueue_detach_element(svq->vq, elem, 0); } @@ -632,7 +632,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) } svq->vq =3D NULL; g_free(svq->desc_next); - g_free(svq->ring_id_maps); + g_free(svq->desc_state); qemu_vfree(svq->vring.desc); qemu_vfree(svq->vring.used); } diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c132c99..d646c35 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,10 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/vhost-iova-tree.h" =20 +typedef struct SVQDescState { + VirtQueueElement *elem; +} SVQDescState; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -47,8 +51,8 @@ typedef struct VhostShadowVirtqueue { /* IOVA mapping */ VhostIOVATree *iova_tree; =20 - /* Map for use the guest's descriptors */ - VirtQueueElement **ring_id_maps; + /* SVQ vring descriptors state */ + SVQDescState *desc_state; =20 /* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237599; cv=none; d=zohomail.com; s=zohoarc; b=ESwxRhDG8iIXbLa9ims/+DL10SDBF3go8RAS2+fIJcrkS3Nae4d1vTHHeG1YprWSlDBcjDxCiBkDcsQqKxG+RyKmhEdPPwA1fFlnFUFiHRZyJSDWFJBWWv7YivHwRxzrG5C6emNiHaYeC9cYcdDnFIhi/2ZuHwFBIBsyJK4/ezQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237599; 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=jTuZsaVTp6bB4Hy8t2eX0EL6FRWz9JmwozvVVhtmXhw=; b=lFc8FVMKaEx3kJXeekU0jbYH27ng5oFN0BjmNzHLWXzUohKzJ+dNO1gRmPbQ0sPXBB6jnkyJjE9RG+mGyyjIrHaPLHG+Yl6pSH9B51xaFfsYrXT8QAiqyZmZ01E+ciTvCLEoOoovBnKJDwFoL3EtQSjSr3uXwyNc43XSWfUWgSE= 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 1658237599370283.2668629533673; Tue, 19 Jul 2022 06:33:19 -0700 (PDT) Received: from localhost ([::1]:43590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnLi-00081L-1r for importer@patchew.org; Tue, 19 Jul 2022 09:33:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6L-0007tv-It for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6H-0004rS-Lc for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17: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-357-9jx8PJJ8PVCvrBly9cm7jg-1; Tue, 19 Jul 2022 09:17:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6ED1A38149A5; Tue, 19 Jul 2022 13:17:19 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2064640CFD0A; Tue, 19 Jul 2022 13:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236641; 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=jTuZsaVTp6bB4Hy8t2eX0EL6FRWz9JmwozvVVhtmXhw=; b=IGPjnsE81nKLGLXaNCMDu2ofJMPMPV/kB9UpeECkED174O/SskQQXxehDr4n89EiP/j0eO vHlly0b+ZdiESKpULt13TjzixlXcLKX7BszEjatu4Qao12T+C8IHwJ3JoZ0l2E3SwJIyvc D3lAWbqYQ2duqf/HHOOhAmnxDn7B7Pw= X-MC-Unique: 9jx8PJJ8PVCvrBly9cm7jg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 10/24] vhost: Track number of descs in SVQDescState Date: Tue, 19 Jul 2022 21:16:23 +0800 Message-Id: <20220719131637.46131-11-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237600082100001 From: Eugenio P=C3=A9rez A guest's buffer continuos on GPA may need multiple descriptors on qemu's VA, so SVQ should track its length sepparatedly. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 4 ++-- hw/virtio/vhost-shadow-virtqueue.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e4c09e2..8314405 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -257,6 +257,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, con= st struct iovec *out_sg, } =20 svq->desc_state[qemu_head].elem =3D elem; + svq->desc_state[qemu_head].ndescs =3D ndescs; vhost_svq_kick(svq); return 0; } @@ -418,8 +419,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } =20 - num =3D svq->desc_state[used_elem.id].elem->in_num + - svq->desc_state[used_elem.id].elem->out_num; + num =3D svq->desc_state[used_elem.id].ndescs; 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; diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d646c35..5c7e7cb 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,12 @@ =20 typedef struct SVQDescState { VirtQueueElement *elem; + + /* + * Number of descriptors exposed to the device. May or may not match + * guest's + */ + unsigned int ndescs; } SVQDescState; =20 /* Shadow virtqueue to relay notifications */ --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237731; cv=none; d=zohomail.com; s=zohoarc; b=DDkntPxSfGV6QLRYKTV58h2KzMvKOIiv7ONqoBPbqUR+IUpVG584nntf0Q2MR3FxqiU1w+YsVkAJkJAZf96JBHVpqVLMOiTBt56SCJ2d/tUSXTp6tpb897fxf9+HQFwQJkZtiJxHeS3xO/o89UIfX1ESQk25tZo+tIuyo8f1/R4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237731; 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=0pFeeYQp3x+GoSIXdcSgiTFapgeqbB9OVnl7G9NNr70=; b=ID71Z4ZHL99+Bz55Nno4L6AHIDq1K3kvFlhxAUXCWM31IDIiuTac9CmSYfwve46vs/buD4fcDx6r9YuTDWX1YsA+cY5wIJO0ac4GCTrTRZMvlcbtYEob7tD/YqfoW4MUeol/trVdt5AbfmFak3PNikK1q8UDyQl0UHDE8KGQXYE= 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 165823773104659.772327490432986; Tue, 19 Jul 2022 06:35:31 -0700 (PDT) Received: from localhost ([::1]:50218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnNq-0004DE-1d for importer@patchew.org; Tue, 19 Jul 2022 09:35:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6W-000893-Bl for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20276) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6U-0004tD-Ot for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:36 -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-498-QPqTPSQuMNWnYbD6T0Ux3g-1; Tue, 19 Jul 2022 09:17:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4BC661C04B61; Tue, 19 Jul 2022 13:17:22 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1435740CF8E5; Tue, 19 Jul 2022 13:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236654; 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=0pFeeYQp3x+GoSIXdcSgiTFapgeqbB9OVnl7G9NNr70=; b=FB+m+J1ifFmB2c8dw/Xr77Y+snKRwMCtbGUnDT7qWpjdRL7sqOe1KmkxW0yAH2yi3H5Xgn QNlfmBRWswSULE+9MRGiSp1LJVqGveSMEA8+z+9Z4DjXnlhf0Cr9zRGkWRmIiRnKp2o6wI Pd6BjHMjE6G02pp7ije3wkH1kn5SiL8= X-MC-Unique: QPqTPSQuMNWnYbD6T0Ux3g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 11/24] vhost: add vhost_svq_push_elem Date: Tue, 19 Jul 2022 21:16:24 +0800 Message-Id: <20220719131637.46131-12-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237731394100001 From: Eugenio P=C3=A9rez This function allows external SVQ users to return guest's available buffers. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++++++++++ hw/virtio/vhost-shadow-virtqueue.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 8314405..1669b1f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -428,6 +428,22 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, return g_steal_pointer(&svq->desc_state[used_elem.id].elem); } =20 +/** + * Push an element to SVQ, returning it to the guest. + */ +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len) +{ + virtqueue_push(svq->vq, elem, len); + if (svq->next_guest_avail_elem) { + /* + * Avail ring was full when vhost_svq_flush was called, so it's a + * good moment to make more descriptors available if possible. + */ + vhost_handle_guest_kick(svq); + } +} + static void vhost_svq_flush(VhostShadowVirtqueue *svq, bool check_for_avail_queue) { diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 5c7e7cb..d9fc1f1 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -84,6 +84,9 @@ typedef struct VhostShadowVirtqueue { =20 bool vhost_svq_valid_features(uint64_t features, Error **errp); =20 +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len); + void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658236950; cv=none; d=zohomail.com; s=zohoarc; b=bndQygQwu3AIy7ICX3+4Ta3kIQX5fa0nvhl2TzCioNJ9jpgb0qGzQYThurnktb3M8elB3WiYIm6FUpMK59S+Jgila+e+qvg4OGHwjzKXIQ6EQY638u5doiCD3QOENpE6bX3w4yIhYWDcK/6lgcBN4rddVhHanSN15fiWf6vGr4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658236950; 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=dx4LH+202gDQ7H499mVVq4SmZn4/8/FrWuPqa/gEltI=; b=FeYuJ8f0hk/atkuWEjRmJfLHEpqVKtNJ74HK1frD0Xhmiz+im7G6MuiE+eB6XSGHi7Kzljfqh0o7c+jsxuV56zE63qCEzCsDOauo69O+njdVo4WCFgpteFXRstQ1HmAU8LYA3EG4tr5Tgh7Ot+fqilXSQ+t/gwxY9QjgRKl7PXk= 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 1658236950073215.35983426787982; Tue, 19 Jul 2022 06:22:30 -0700 (PDT) Received: from localhost ([::1]:46838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnBE-0007Ts-VX for importer@patchew.org; Tue, 19 Jul 2022 09:22:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6O-00080E-Qa for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6N-0004rw-7Z for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:28 -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-134-5Kqn5SMGPsCIQ4753ry9_A-1; Tue, 19 Jul 2022 09:17:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 29BB13C02193; Tue, 19 Jul 2022 13:17:25 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id E36B040CFD0A; Tue, 19 Jul 2022 13:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236646; 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=dx4LH+202gDQ7H499mVVq4SmZn4/8/FrWuPqa/gEltI=; b=fQZy+RwdAOI/bG7xUNlqIenPP0XmQtfowSKOo/9htn7LazO6gshEAxgNSRdUeC9b7q8GwX Em9ZDC+in6Um+g5jKSKZa8u5WbZPWb/nY6JDMXhZYUoIdaqLsJuxzGR7htPnS/Qe/8M05F SeijpClLDJvewEV7SHDykXCZIc3sYrQ= X-MC-Unique: 5Kqn5SMGPsCIQ4753ry9_A-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 12/24] vhost: Expose vhost_svq_add Date: Tue, 19 Jul 2022 21:16:25 +0800 Message-Id: <20220719131637.46131-13-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658236950570100002 From: Eugenio P=C3=A9rez This allows external parts of SVQ to forward custom buffers to the device. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 6 +++--- hw/virtio/vhost-shadow-virtqueue.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 1669b1f..c3a75ca 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -238,9 +238,9 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ -static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *ou= t_sg, - size_t out_num, const struct iovec *in_sg, - size_t in_num, VirtQueueElement *elem) +int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, + size_t out_num, const struct iovec *in_sg, size_t in_num, + VirtQueueElement *elem) { unsigned qemu_head; unsigned ndescs =3D in_num + out_num; diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d9fc1f1..dd78f4b 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -86,6 +86,9 @@ bool vhost_svq_valid_features(uint64_t features, Error **= errp); =20 void vhost_svq_push_elem(VhostShadowVirtqueue *svq, const VirtQueueElement *elem, uint32_t len); +int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, + size_t out_num, const struct iovec *in_sg, size_t in_num, + VirtQueueElement *elem); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237603; cv=none; d=zohomail.com; s=zohoarc; b=TsytX3x8ybRBNGkQ0rfSMOorDr1h8XUeQXSsbpOuMfvWuhpuE13OiCr4VNpYrhfjXPc9TawHVhIvSqtVPpgEuo5iola4QAE/ImsgmaUlNzynXJd/YmSWpcdtp0YY+quFiSxGAOLZ2fEQXt/uagq2ScAR/LD6q0J6XjUQ81SvPAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237603; 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=W2EAtPvsF4CeGJH8vvBNBf6Jt4GMpAr2uSF28zcF3D8=; b=Vpt7RtGZ9RGiDwv6SrTFMp1IjAjAQlKt0b3/ARPHjB1iF968cuGAx7SAF852V6VXrqCi9NrXmuzQ+vjtbZ2i2QtvgeEZ3PQBtCoT5kzAKGRgunJpqTUfye8hTrlY44ajDH6Mt0xvEGB5uUzmRY6X9LH6UFbidu/wE9NWf+8a8QI= 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 1658237603609132.53856502468307; Tue, 19 Jul 2022 06:33:23 -0700 (PDT) Received: from localhost ([::1]:43916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnLm-0008Fa-G9 for importer@patchew.org; Tue, 19 Jul 2022 09:33:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6U-00085c-MT for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6R-0004sF-He for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:34 -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-633-hPy96WQ8Mfe9OQZXt5fMmA-1; Tue, 19 Jul 2022 09:17:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F30C101A586; Tue, 19 Jul 2022 13:17:28 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0A2540CFD0A; Tue, 19 Jul 2022 13:17:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236649; 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=W2EAtPvsF4CeGJH8vvBNBf6Jt4GMpAr2uSF28zcF3D8=; b=MKcqk7Q0T+o52DeAMxRSOW0d3yiiinesP2t+H7OAT9Rt2jFAh95Zu74vzo09c3qJx06ibC BP3d8UVV69yMwkWvH9WQm5vJdKliuBxUCxuuamxEFOFxeMMyXLlCwvWzAsZpprm3tpeKAf Y0Rv2tzVcwoVOeXi3om7rDXDkBKQqG4= X-MC-Unique: hPy96WQ8Mfe9OQZXt5fMmA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 13/24] vhost: add vhost_svq_poll Date: Tue, 19 Jul 2022 21:16:26 +0800 Message-Id: <20220719131637.46131-14-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237604094100001 From: Eugenio P=C3=A9rez It allows the Shadow Control VirtQueue to wait for the device to use the available buffers. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 27 +++++++++++++++++++++++++++ hw/virtio/vhost-shadow-virtqueue.h | 1 + 2 files changed, 28 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c3a75ca..cc2ee47 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -486,6 +486,33 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, } =20 /** + * Poll the SVQ for one device used buffer. + * + * This function race with main event loop SVQ polling, so extra + * synchronization is needed. + * + * Return the length written by the device. + */ +size_t vhost_svq_poll(VhostShadowVirtqueue *svq) +{ + int64_t start_us =3D g_get_monotonic_time(); + do { + uint32_t len; + VirtQueueElement *elem =3D vhost_svq_get_buf(svq, &len); + if (elem) { + return len; + } + + if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { + return 0; + } + + /* Make sure we read new used_idx */ + smp_rmb(); + } while (true); +} + +/** * Forward used buffers. * * @n: hdev call event notifier, the one that device set to notify svq. diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index dd78f4b..cf442f7 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -89,6 +89,7 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq, int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, size_t out_num, const struct iovec *in_sg, size_t in_num, VirtQueueElement *elem); +size_t vhost_svq_poll(VhostShadowVirtqueue *svq); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237171; cv=none; d=zohomail.com; s=zohoarc; b=Ct9mUXnIa5Q5/IoiHZjyelCWjWLPnu8vbC8PuXBk1PEs1Xe+YCtt2pepeJCVXWrCjsgCk6xvB0ERVU7hbRURLAiglb75eI8bq7KlIcitHUHsHeDbFoE1Pam1/xbDvFVxuQbTEvNwC6BXb5I3fg6YPWes0OepP35rphX5hOuMLw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237171; 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=+DvHbhI5kSfDtYno+wQFg5qhn6r1KKG9eJZV4PDNEU8=; b=RDehF4jWWd0rYl8BcH0gU73suMoeckPcqA5XUFqoq86/YXx/H6z/d7Uc8dqAywaUfI+UikuSBSb3dqxPbXxZot8xpfsVYh8upkCE4kututCIaUY8U7tmjPADpg6O1xXLkEOsus1jtHUpZ1hYs9zYA62kVgqZkAw3ubNB8QrZ19E= 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 1658237171112331.11930942441904; Tue, 19 Jul 2022 06:26:11 -0700 (PDT) Received: from localhost ([::1]:55472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnEn-00058H-T9 for importer@patchew.org; Tue, 19 Jul 2022 09:26:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6V-00085d-07 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27301) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6T-0004sU-31 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:34 -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-486-UPRW8NyEPmil65_kkYMl5A-1; Tue, 19 Jul 2022 09:17:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 193812813D2C; Tue, 19 Jul 2022 13:17:31 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6D6A40CF8E5; Tue, 19 Jul 2022 13:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236652; 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=+DvHbhI5kSfDtYno+wQFg5qhn6r1KKG9eJZV4PDNEU8=; b=TxQs4InBq24y94LmM9UTYv6D3DMG+Vp0wkYDRQpSgBuqI4HYQ3cdQnlHswnpaxYVkDHf7Z oyae+7X6+bOHdxCGkk5UdPEym6BD4UVSAyZoiB+/z1NgkBFNvBLfcOFDhhkQn6d9MtaJEu 6nsK6lxu0rjtKZyzIdialpScBq8KYhY= X-MC-Unique: UPRW8NyEPmil65_kkYMl5A-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 14/24] vhost: Add svq avail_handler callback Date: Tue, 19 Jul 2022 21:16:27 +0800 Message-Id: <20220719131637.46131-15-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237172906100001 From: Eugenio P=C3=A9rez This allows external handlers to be aware of new buffers that the guest places in the virtqueue. When this callback is defined the ownership of the guest's virtqueue element is transferred to the callback. This means that if the user wants to forward the descriptor it needs to manually inject it. The callback is also free to process the command by itself and use the element with svq_push. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 14 ++++++++++++-- hw/virtio/vhost-shadow-virtqueue.h | 31 ++++++++++++++++++++++++++++++- hw/virtio/vhost-vdpa.c | 3 ++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index cc2ee47..e495672 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -306,7 +306,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtque= ue *svq) break; } =20 - r =3D vhost_svq_add_element(svq, elem); + if (svq->ops) { + r =3D svq->ops->avail_handler(svq, elem, svq->ops_opaque); + } else { + r =3D vhost_svq_add_element(svq, elem); + } if (unlikely(r !=3D 0)) { if (r =3D=3D -ENOSPC) { /* @@ -685,12 +689,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * shadow methods and file descriptors. * * @iova_tree: Tree to perform descriptors translations + * @ops: SVQ owner callbacks + * @ops_opaque: ops opaque pointer * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; @@ -712,6 +720,8 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree) event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree =3D iova_tree; + svq->ops =3D ops; + svq->ops_opaque =3D ops_opaque; return g_steal_pointer(&svq); =20 err_init_hdev_call: diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index cf442f7..d04c34a 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -25,6 +25,27 @@ typedef struct SVQDescState { unsigned int ndescs; } SVQDescState; =20 +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + +/** + * Callback to handle an avail buffer. + * + * @svq: Shadow virtqueue + * @elem: Element placed in the queue by the guest + * @vq_callback_opaque: Opaque + * + * Returns 0 if the vq is running as expected. + * + * Note that ownership of elem is transferred to the callback. + */ +typedef int (*VirtQueueAvailCallback)(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + void *vq_callback_opaque); + +typedef struct VhostShadowVirtqueueOps { + VirtQueueAvailCallback avail_handler; +} VhostShadowVirtqueueOps; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -69,6 +90,12 @@ typedef struct VhostShadowVirtqueue { */ uint16_t *desc_next; =20 + /* Caller callbacks */ + const VhostShadowVirtqueueOps *ops; + + /* Caller callbacks opaque */ + void *ops_opaque; + /* Next head to expose to the device */ uint16_t shadow_avail_idx; =20 @@ -102,7 +129,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque); =20 void vhost_svq_free(gpointer vq); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 66f054a..0b13e98 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -418,8 +418,9 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree= ); + g_autoptr(VhostShadowVirtqueue) svq; =20 + svq =3D vhost_svq_new(v->iova_tree, NULL, NULL); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237150; cv=none; d=zohomail.com; s=zohoarc; b=RrIYnNmmva9nziLspRmciJx1IMdGrQQdmTVPU+1IoaPKzN0ljVMcZbknn859Z4RTL+xuy4yFns6g4BiyzItSUbbb7hVwDVwCzGWNzNwLTHp4x5uw8+sUqYMcqDXZ/7EJGCAzgbrE8HgRMk/PFH5LbiyChz92rvAt46d1r3XU4rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237150; 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=wxlT59tu7qu7oO6FmxddDjsf6uhXLxR25JFobxvC9P8=; b=XWaag1gyhag8p5Su3rkZg+A5x03nMkZRxdT5cnyuRj7ISwIGQo6slW6FXFbIisOHaXbbLnByfg1At87TSBlkOjGw5xIcWuuOq2AWuLBbyg0oelQMJ2GlbFZCkM22AiwMEt0+tB8WCSxU5FqeaWa9zbkmzcrJTgx8TlYyOifgkbs= 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 1658237150094198.77646116642052; Tue, 19 Jul 2022 06:25:50 -0700 (PDT) Received: from localhost ([::1]:55130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnES-0004uV-AD for importer@patchew.org; Tue, 19 Jul 2022 09:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6Y-0008At-06 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53195) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6W-0004tW-9L for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17: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-621-Nk8sim4pMMWUHULqKlcsZA-1; Tue, 19 Jul 2022 09:17:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9286101A54E; Tue, 19 Jul 2022 13:17:33 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0F0140CF8E5; Tue, 19 Jul 2022 13:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236655; 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=wxlT59tu7qu7oO6FmxddDjsf6uhXLxR25JFobxvC9P8=; b=WHcWXDfVx82Ocai4k3u1TcMVD/CwAnPdKy2pnKsQngYwAwAYgZG2Z8HQIWLG3FglbCenDM YA/uiYv1ueFPQaBU731pJzPkZZvogz7F3VisNNrvNiq7eSM9vvp4zMn4imTDS2twQiBiiF XENoAC3bhgdMhULENZKOcWa1m4RvhcY= X-MC-Unique: Nk8sim4pMMWUHULqKlcsZA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang , "Michael S . Tsirkin" Subject: [PULL 15/24] vdpa: Export vhost_vdpa_dma_map and unmap calls Date: Tue, 19 Jul 2022 21:16:28 +0800 Message-Id: <20220719131637.46131-16-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237151009100001 From: Eugenio P=C3=A9rez Shadow CVQ will copy buffers on qemu VA, so we avoid TOCTOU attacks from the guest that could set a different state in qemu device model and vdpa device. To do so, it needs to be able to map these new buffers to the device. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 7 +++---- include/hw/virtio/vhost-vdpa.h | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 0b13e98..9699721 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -71,8 +71,8 @@ static bool vhost_vdpa_listener_skipped_section(MemoryReg= ionSection *section, return false; } =20 -static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr si= ze, - void *vaddr, bool readonly) +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; @@ -97,8 +97,7 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwadd= r iova, hwaddr size, return ret; } =20 -static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, - hwaddr size) +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index a29dbb3..7214eb4 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -39,4 +39,8 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; =20 +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly); +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size); + #endif --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237350; cv=none; d=zohomail.com; s=zohoarc; b=gbVhwJ+tgcRcAuFShi2qTJjkdCD416b1Kr3LGZ9VgYf/sedobtY7wdRd565TxrvZIsWXtkDxWSAWXm+z7Ig7yW+AbTOVNqvkVNlWz9134VgXA58bjVMLReqTfpwslz076aJU0Gy3Gkq4CO16E8EzztWuLJldmyoGAZf4gsGRDTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237350; 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=8B6UsG2MNeYnZ5l+lFsLztMDtncEdaH9qY7d8PisO9s=; b=SNPc2t4P3AjMCXLXrmueSiDWhaH7WjHSv0yO5AMH8/gjMatXSjVhvAugSCL1hgYS1j/snPs9Vmpg+kI5PRA+E0XzL+TfExpJidhIhK6SAThh5/0+3O4UiKDIql4RFdKOvD1ccvcTRfXlEmZSAx/IT301dWWwwu4y+b03Ym71x48= 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 1658237350525305.9494015209625; Tue, 19 Jul 2022 06:29:10 -0700 (PDT) Received: from localhost ([::1]:35504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnHh-0002Od-ET for importer@patchew.org; Tue, 19 Jul 2022 09:29:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6e-0008Fg-Kh for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6b-0004u3-2I for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:43 -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-433-CgUFf-XtPFuJOQvKGyQu1g-1; Tue, 19 Jul 2022 09:17:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C54F9101A54E; Tue, 19 Jul 2022 13:17:36 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C88340CFD0A; Tue, 19 Jul 2022 13:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236660; 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=8B6UsG2MNeYnZ5l+lFsLztMDtncEdaH9qY7d8PisO9s=; b=BWPjhBSXOj2S6mhox9BW7cam7XS1FZJ8WZLH0QKDkPtFxCAFrV63dQ73W6eQdeQOrOGCmn s7j5Z02hPP6dxMfBhCs8PFsFV1il9btH/z0Dm9tgO6YSKBfUgF8k/6FYREcb9ddQpX/FVL kFdEZ6bOAJw8vRi9hYn6Sb+nGItd4qU= X-MC-Unique: CgUFf-XtPFuJOQvKGyQu1g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 16/24] vdpa: manual forward CVQ buffers Date: Tue, 19 Jul 2022 21:16:29 +0800 Message-Id: <20220719131637.46131-17-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237352194100001 From: Eugenio P=C3=A9rez Do a simple forwarding of CVQ buffers, the same work SVQ could do but through callbacks. No functional change intended. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 3 ++- include/hw/virtio/vhost-vdpa.h | 3 +++ net/vhost-vdpa.c | 58 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9699721..beaaa70 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -419,7 +419,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, for (unsigned n =3D 0; n < hdev->nvqs; ++n) { g_autoptr(VhostShadowVirtqueue) svq; =20 - svq =3D vhost_svq_new(v->iova_tree, NULL, NULL); + svq =3D vhost_svq_new(v->iova_tree, v->shadow_vq_ops, + v->shadow_vq_ops_opaque); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 7214eb4..1111d85 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -15,6 +15,7 @@ #include =20 #include "hw/virtio/vhost-iova-tree.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 @@ -35,6 +36,8 @@ typedef struct vhost_vdpa { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; + const VhostShadowVirtqueueOps *shadow_vq_ops; + void *shadow_vq_ops_opaque; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index df1e69e..2e3b6b1 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,11 +11,14 @@ =20 #include "qemu/osdep.h" #include "clients.h" +#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "net/vhost-vdpa.h" #include "hw/virtio/vhost-vdpa.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/memalign.h" #include "qemu/option.h" #include "qapi/error.h" #include @@ -187,6 +190,57 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +/** + * Forward buffer for the moment. + */ +static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + void *opaque) +{ + unsigned int n =3D elem->out_num + elem->in_num; + g_autofree struct iovec *dev_buffers =3D g_new(struct iovec, n); + size_t in_len, dev_written; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + int r; + + memcpy(dev_buffers, elem->out_sg, elem->out_num); + memcpy(dev_buffers + elem->out_num, elem->in_sg, elem->in_num); + + r =3D vhost_svq_add(svq, &dev_buffers[0], elem->out_num, &dev_buffers[= 1], + elem->in_num, 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__); + } + goto out; + } + + /* + * 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); + } + +out: + in_len =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, + sizeof(status)); + if (unlikely(in_len < sizeof(status))) { + error_report("Bad device CVQ written length"); + } + vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); + g_free(elem); + return r; +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { + .avail_handler =3D vhost_vdpa_net_handle_ctrl_avail, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -211,6 +265,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; + s->vhost_vdpa.shadow_vq_ops_opaque =3D s; + } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237604; cv=none; d=zohomail.com; s=zohoarc; b=QSP+OhJBs8nmMcTuGcjn4F6ZOQP1M3xtTnZIv1vLvT96z3DQpUOiuxs+mRU5nrIA7mM3FbLbJXioniuDZQIWoVNh35rhY9szx681+Iapvo7n5IOMqwT0ZMDvL1UiJZHsfC8j9clad4nzqV1JSCoavkqo7p88tzJJNq0iVeLS3Og= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237604; 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=LbzuWf86QUaW/ExAyrHAqofwuZH7iERvV96Z/F5vuJs=; b=FkfBTvgNf8iBfwt56YjWrZsYOTPAau1bH49sXbkmuvODqSFZhpts+mU1Ecd/ukYKWNx1RSQnFmZwfITxW914LB9spETQ8gb09rngaMKJI+3kLEBWat+/WKzpc3tVZ/+jcHm6g5q07uaU/zL6xohqe4tmFckYr7tz+W2ywIjt3KQ= 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 165823760422426.467918884179085; Tue, 19 Jul 2022 06:33:24 -0700 (PDT) Received: from localhost ([::1]:43930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnLm-0008G6-W0 for importer@patchew.org; Tue, 19 Jul 2022 09:33:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6i-0008If-86 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6e-0004uG-8a for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:47 -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-149-_0IqtVXaMV2j2HvmUmkClw-1; Tue, 19 Jul 2022 09:17:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C88158039AC; Tue, 19 Jul 2022 13:17:39 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 698A140CFD0A; Tue, 19 Jul 2022 13:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236663; 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=LbzuWf86QUaW/ExAyrHAqofwuZH7iERvV96Z/F5vuJs=; b=OK8fcrhsJyPsmPdr/oXNEhlknMkqbhVsxODwyLy4+lLnnCsuXJnhw956T62HPJA3uUpyVk KgVXU9ycA99UANoC5X/TQYfzouFIgEJV+spCz0QggFcXY8LPojwd9nBNGv5WbtPsK10gcs dkCWxgPND6VTwAA7pcHQ2Roa7U7Gc8I= X-MC-Unique: _0IqtVXaMV2j2HvmUmkClw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 17/24] vdpa: Buffer CVQ support on shadow virtqueue Date: Tue, 19 Jul 2022 21:16:30 +0800 Message-Id: <20220719131637.46131-18-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237606890100001 From: Eugenio P=C3=A9rez Introduce the control virtqueue support for vDPA shadow virtqueue. This is needed for advanced networking features like rx filtering. Virtio-net control VQ copies the descriptors to qemu's VA, so we avoid TOCTOU with the guest's or device's memory every time there is a device model change. Otherwise, the guest could change the memory content in the time between qemu and the device read it. To demonstrate command handling, VIRTIO_NET_F_CTRL_MACADDR is implemented. If the virtio-net driver changes MAC the virtio-net device model will be updated with the new one, and a rx filtering change event will be raised. More cvq commands could be added here straightforwardly but they have not been tested. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 205 insertions(+), 8 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2e3b6b1..502f6f9 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -33,6 +33,9 @@ typedef struct VhostVDPAState { NetClientState nc; struct vhost_vdpa vhost_vdpa; VHostNetState *vhost_net; + + /* Control commands shadow buffers */ + void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; bool started; } VhostVDPAState; =20 @@ -131,6 +134,8 @@ static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); =20 + qemu_vfree(s->cvq_cmd_out_buffer); + qemu_vfree(s->cvq_cmd_in_buffer); if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -190,24 +195,191 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) +{ + VhostIOVATree *tree =3D v->iova_tree; + DMAMap needle =3D { + /* + * No need to specify size or to look for more translations since + * this contiguous chunk was allocated by us. + */ + .translated_addr =3D (hwaddr)(uintptr_t)addr, + }; + const DMAMap *map =3D vhost_iova_tree_find_iova(tree, &needle); + int r; + + if (unlikely(!map)) { + error_report("Cannot locate expected map"); + return; + } + + r =3D vhost_vdpa_dma_unmap(v, map->iova, map->size + 1); + if (unlikely(r !=3D 0)) { + error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); + } + + vhost_iova_tree_remove(tree, map); +} + +static size_t vhost_vdpa_net_cvq_cmd_len(void) +{ + /* + * MAC_TABLE_SET is the ctrl command that produces the longer out buff= er. + * In buffer is always 1 byte, so it should fit here + */ + return sizeof(struct virtio_net_ctrl_hdr) + + 2 * sizeof(struct virtio_net_ctrl_mac) + + MAC_TABLE_ENTRIES * ETH_ALEN; +} + +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= ()); +} + +/** 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) +{ + DMAMap map =3D {}; + int r; + + 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.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; + } + + r =3D vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(= ), buf, + !write); + if (unlikely(r < 0)) { + goto dma_map_err; + } + + return true; + +dma_map_err: + vhost_iova_tree_remove(v->iova_tree, &map); + return false; +} + /** - * Forward buffer for the moment. + * 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) +{ + size_t in_copied; + bool ok; + + 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; + } + + 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)) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); + return false; + } + + iov[1].iov_len =3D sizeof(virtio_net_ctrl_ack); + return true; +} + +/** + * 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) +{ + struct virtio_net_ctrl_hdr ctrl; + size_t n; + + n =3D iov_to_buf(out, out_num, 0, &ctrl, sizeof(ctrl)); + if (unlikely(n < sizeof(ctrl))) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid legnth of out buffer %zu\n", __func__, = n); + return false; + } + + switch (ctrl.class) { + case VIRTIO_NET_CTRL_MAC: + switch (ctrl.cmd) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + return true; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mac cmd %u\n", + __func__, ctrl.cmd); + }; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid control class %u\n", + __func__, ctrl.class); + }; + + return false; +} + +/** + * Validate and copy control virtqueue commands. + * + * Following QEMU guidelines, we offer a copy of the buffers to the device= to + * prevent TOCTOU bugs. */ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, VirtQueueElement *elem, void *opaque) { - unsigned int n =3D elem->out_num + elem->in_num; - g_autofree struct iovec *dev_buffers =3D g_new(struct iovec, n); + VhostVDPAState *s =3D opaque; size_t in_len, dev_written; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - int r; + /* 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 }, + }; + /* in buffer used for device model */ + const struct iovec in =3D { + .iov_base =3D &status, + .iov_len =3D sizeof(status), + }; + int r =3D -EINVAL; + bool ok; + + ok =3D vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); + if (unlikely(!ok)) { + goto out; + } =20 - memcpy(dev_buffers, elem->out_sg, elem->out_num); - memcpy(dev_buffers + elem->out_num, elem->in_sg, elem->in_num); + ok =3D vhost_vdpa_net_cvq_validate_cmd(&dev_buffers[0], 1); + if (unlikely(!ok)) { + goto out; + } =20 - r =3D vhost_svq_add(svq, &dev_buffers[0], elem->out_num, &dev_buffers[= 1], - elem->in_num, elem); + r =3D vhost_svq_add(svq, &dev_buffers[0], 1, &dev_buffers[1], 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= ", @@ -224,6 +396,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShado= wVirtqueue *svq, dev_written =3D vhost_svq_poll(svq); if (unlikely(dev_written < sizeof(status))) { error_report("Insufficient written data (%zu)", dev_written); + goto out; + } + + memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + if (status !=3D VIRTIO_NET_OK) { + goto out; + } + + status =3D VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, 1); + if (status !=3D VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); } =20 out: @@ -234,6 +418,12 @@ 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 @@ -266,6 +456,13 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; if (!is_datapath) { + s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), + vhost_vdpa_net_cvq_cmd_page_le= n()); + memset(s->cvq_cmd_out_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()= ); + s->cvq_cmd_in_buffer =3D qemu_memalign(qemu_real_host_page_size(), + vhost_vdpa_net_cvq_cmd_page_le= n()); + memset(s->cvq_cmd_in_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()); + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; } --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237867; cv=none; d=zohomail.com; s=zohoarc; b=C0NFTnFWnGC8Y6Zk16lrl8ErpVtpRw/3A++Daw+IJ1eTu6EApp+81NQ3qGYm6ftd1OexjZDLDJQrS9v4vRC/nxwlX4UprxFu10WmJOohjOb8Or4CcFKIz5XdtaxPwGzO9OKFcUtX/tdaiUdkXv3qnncFTOh/JXnOOSEuk/vMf2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237867; 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=LqGTNiKDnKCnIGR/t0saN7OUawQO+5nQonscQFSCNDs=; b=n8LfZZpwa/DNu4keTqTITNIiCBdf1WdLdSLXmY6BGqnBngfnhNegC8SgELVVNzeWf3mr1nTom6GoUGpEjYEKqEdRUx2lQ0UPhGc1giqXxdx9Q86+5D+Q7y67fCxekHFBRdVC6suj6NMAtS1fK7gZcm30KDQfyog/aVxmGIyGK90= 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 1658237867693507.68054745370694; Tue, 19 Jul 2022 06:37:47 -0700 (PDT) Received: from localhost ([::1]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnQ2-0000wp-NL for importer@patchew.org; Tue, 19 Jul 2022 09:37:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6i-0008Ie-83 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6f-0004uS-OK for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:47 -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-461-Ar9TQFqjNwSjcs63mtd3Jg-1; Tue, 19 Jul 2022 09:17:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCCAD18A6528; Tue, 19 Jul 2022 13:17:42 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C05B40CFD0A; Tue, 19 Jul 2022 13:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236664; 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=LqGTNiKDnKCnIGR/t0saN7OUawQO+5nQonscQFSCNDs=; b=eySsokmyg2Q/8tdH0zN4mnTP1jw7Z/dbTJHSHeDUdqn+FHzdTyNCQId7sBtn06a3t2v5cq /iII78NI/DxunbUXfWXUXKmGP8xGaa5cTQxz6vtmXCUOzqMQ0juReLml6O33bz35CdeAJd 9SP7knY03forF5GzZhNUlYIuaUzxvcs= X-MC-Unique: Ar9TQFqjNwSjcs63mtd3Jg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Jason Wang , "Michael S . Tsirkin" Subject: [PULL 18/24] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Date: Tue, 19 Jul 2022 21:16:31 +0800 Message-Id: <20220719131637.46131-19-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237868480100001 From: Eugenio P=C3=A9rez To know the device features is needed for CVQ SVQ, so SVQ knows if it can handle all commands or not. Extract from vhost_vdpa_get_max_queue_pairs so we can reuse it. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 502f6f9..6e3e9f3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -474,20 +474,24 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, return nc; } =20 -static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **er= rp) +static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) +{ + int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); + if (unlikely(ret < 0)) { + error_setg_errno(errp, errno, + "Fail to query features from vhost-vDPA device"); + } + return ret; +} + +static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, + int *has_cvq, Error **errp) { unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); g_autofree struct vhost_vdpa_config *config =3D NULL; __virtio16 *max_queue_pairs; - uint64_t features; int ret; =20 - ret =3D ioctl(fd, VHOST_GET_FEATURES, &features); - if (ret) { - error_setg(errp, "Fail to query features from vhost-vDPA device"); - return ret; - } - if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) { *has_cvq =3D 1; } else { @@ -517,10 +521,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; - int queue_pairs, i, has_cvq =3D 0; + int queue_pairs, r, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -534,7 +539,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, return -errno; } =20 - queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + r =3D vhost_vdpa_get_features(vdpa_device_fd, &features, errp); + if (unlikely(r < 0)) { + return r; + } + + queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, &has_cvq, errp); if (queue_pairs < 0) { qemu_close(vdpa_device_fd); --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658238162; cv=none; d=zohomail.com; s=zohoarc; b=OJOCGS+FtF+WFJy+ZlPU8GHzCsphpz+T+JJt/RqrUK8mXgAw7CdFXvoC2NVyqmGeaYFoc1aUvr9PFWf74RDNsGMJ5vAhVnSwKVVhuqGfdo0S1QoolkB0IhteMSOZih8HWvpGpQdqRItwYGJkCrqw5aa3R8qH/JL1lcBvfkkTn2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658238162; 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=tmjRmXnw+cXbZH6Ts4daW4hP6dk+7aXVj7OFJ+hv2qE=; b=kvl8bYiWutnnRuSMGFDSvBhZJdKuW0TSjdU6blt5hDrFe7keLfxiaRprR1A6OUCrpP68XX1jx4cZdXREiCZfsfrSd1UyKyz263vglwnmbcJKmqXxJiNGF1QsVGWIjCRx/vwmSGrL14Zel4fe9x6MprcPYhzYKoSOjAMLJhrFohc= 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 1658238162748995.6830113175126; Tue, 19 Jul 2022 06:42:42 -0700 (PDT) Received: from localhost ([::1]:35768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnUn-0006LL-BY for importer@patchew.org; Tue, 19 Jul 2022 09:42:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6m-0008Iz-0x for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6i-0004uo-Mv for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:50 -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-49-5YlDtTikOWmCEJcrEacpRQ-1; Tue, 19 Jul 2022 09:17:45 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 990158032F0; Tue, 19 Jul 2022 13:17:45 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6016F40CFD0B; Tue, 19 Jul 2022 13:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236668; 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=tmjRmXnw+cXbZH6Ts4daW4hP6dk+7aXVj7OFJ+hv2qE=; b=QEI5LaQBrpuSdYbzgXj264gbnOHUzk1kCxsFp0M63H1JhsiUpeOii+U+MMAQPgDEeJjngS jGR4WMETLI1mmVMCCgIc92OdK1eXpdbW2NorVxucRRPo9q1Wie4vK1w8EQwRN9K3/KBTuw Ah0i+VeEAF8uaQgVZPfFTRmRseD9ce4= X-MC-Unique: 5YlDtTikOWmCEJcrEacpRQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 19/24] vdpa: Add device migration blocker Date: Tue, 19 Jul 2022 21:16:32 +0800 Message-Id: <20220719131637.46131-20-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658238163416100001 From: Eugenio P=C3=A9rez Since the vhost-vdpa device is exposing _F_LOG, adding a migration blocker = if it uses CVQ. However, qemu is able to migrate simple devices with no CVQ as long as they use SVQ. To allow it, add a placeholder error to vhost_vdpa, and only add to vhost_dev when used. vhost_dev machinery place the migration blocker if needed. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 15 +++++++++++++++ include/hw/virtio/vhost-vdpa.h | 1 + 2 files changed, 16 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index beaaa70..291cd19 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -20,6 +20,7 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost-vdpa.h" #include "exec/address-spaces.h" +#include "migration/blocker.h" #include "qemu/cutils.h" #include "qemu/main-loop.h" #include "cpu.h" @@ -1022,6 +1023,13 @@ 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); @@ -1064,6 +1072,10 @@ err: vhost_svq_stop(svq); } =20 + if (v->migration_blocker) { + migrate_del_blocker(v->migration_blocker); + } + return false; } =20 @@ -1083,6 +1095,9 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *de= v) } } =20 + if (v->migration_blocker) { + migrate_del_blocker(v->migration_blocker); + } return true; } =20 diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 1111d85..d10a893 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -35,6 +35,7 @@ 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; --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237737; cv=none; d=zohomail.com; s=zohoarc; b=nBv8R46SI21+NyOtAMO0VCIg4ZwWrG06f03Ivb+fjFF3lulrh5/UlY5axlHPsJETyk5JLeoob6XjU+ecToWsG4ZOtu7fIFX4Mr4R4MqL0p9vEJcZVulBTnAEZzUXDSrcmnVQFH/n6NM4ISNxz1hhdqLWopFfJIqoFtAutT2dqyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237737; 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=/pL2ZxKrydkutONIq+ZR1u/YsAXLfXFqczH5+W0Bzus=; b=Zo01/PznNV+E6mSpzkxos+zEXzUv4oxzeI7YIJPCm1VoM93OhE8mg/418Q0iG0HWdUc7clyiEb6ISN328bs5FGZExXnzVglTrXdXThuIS7VTAxbGh/wmQRYuD32l2v4G71zGGADuwDzjbwvZrcMzExToEzA19gN1eGntVNqO4h8= 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 1658237737498702.4201960485993; Tue, 19 Jul 2022 06:35:37 -0700 (PDT) Received: from localhost ([::1]:50658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnNv-0004WK-JY for importer@patchew.org; Tue, 19 Jul 2022 09:35:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6n-0008Kq-UE for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6l-0004uv-Fi for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:17:53 -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-567-6PcT4V0tMlOQTPGSYiCr-Q-1; Tue, 19 Jul 2022 09:17:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E07CC38149AA; Tue, 19 Jul 2022 13:17:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4487740CFD0A; Tue, 19 Jul 2022 13:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236670; 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=/pL2ZxKrydkutONIq+ZR1u/YsAXLfXFqczH5+W0Bzus=; b=EwxyHRx3umxbcoeWeWjl0x3dTlwoJIEeSN8bgb7m6bdafSjueDc3DkaciAHQwkkX+/8JBN jSCefhWkFkOQM+G8uNVWSxes87+XT8PCNxlgUJpLrZR93kQEw7LsrECinu5Ngf7Hqeu+hw nYFE9QWabL4kPUo0e44XLi61q/rHnM0= X-MC-Unique: 6PcT4V0tMlOQTPGSYiCr-Q-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Markus Armbruster , "Michael S . Tsirkin" , Jason Wang Subject: [PULL 20/24] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Tue, 19 Jul 2022 21:16:33 +0800 Message-Id: <20220719131637.46131-21-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-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.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237739710100001 From: Eugenio P=C3=A9rez Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- qapi/net.json | 9 ++++++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6e3e9f3..6abad27 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -75,6 +75,28 @@ const int vdpa_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +/** Supported device specific feature bits with SVQ */ +static const uint64_t vdpa_svq_device_features =3D + BIT_ULL(VIRTIO_NET_F_CSUM) | + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | + BIT_ULL(VIRTIO_NET_F_MTU) | + BIT_ULL(VIRTIO_NET_F_MAC) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | + BIT_ULL(VIRTIO_NET_F_STATUS) | + BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | + BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | + BIT_ULL(VIRTIO_NET_F_RSC_EXT) | + BIT_ULL(VIRTIO_NET_F_STANDBY); + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -133,9 +155,13 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev =3D &s->vhost_net->dev; =20 qemu_vfree(s->cvq_cmd_out_buffer); qemu_vfree(s->cvq_cmd_in_buffer); + if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + } if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -437,7 +463,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, int vdpa_device_fd, int queue_pair_index, int nvqs, - bool is_datapath) + bool is_datapath, + bool svq, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -455,6 +483,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_tree =3D iova_tree; if (!is_datapath) { s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), vhost_vdpa_net_cvq_cmd_page_le= n()); @@ -465,6 +495,8 @@ 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) { @@ -474,6 +506,14 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, return nc; } =20 +static int vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_ra= nge) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + return ret < 0 ? -errno : 0; +} + static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) { int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); @@ -524,6 +564,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; + g_autoptr(VhostIOVATree) iova_tree =3D NULL; NetClientState *nc; int queue_pairs, r, i, has_cvq =3D 0; =20 @@ -551,22 +592,45 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } =20 + if (opts->x_svq) { + struct vhost_vdpa_iova_range iova_range; + + uint64_t invalid_dev_features =3D + features & ~vdpa_svq_device_features & + /* Transport are all accepted at this point */ + ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_S= TART); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, + invalid_dev_features); + goto err_svq; + } + + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); + } + ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, opts->x_s= vq, + iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false); + vdpa_device_fd, i, 1, false, + opts->x_svq, iova_tree); if (!nc) goto err; } =20 + /* iova_tree ownership belongs to last NetClientState */ + g_steal_pointer(&iova_tree); return 0; =20 err: @@ -575,6 +639,8 @@ err: qemu_del_net_client(ncs[i]); } } + +err_svq: qemu_close(vdpa_device_fd); =20 return -1; diff --git a/qapi/net.json b/qapi/net.json index 9af11e9..75ba2cb 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -445,12 +445,19 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1) +# (default: false) +# +# Features: +# @unstable: Member @x-svq is experimental. +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetdevVmnetHostOptions: --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658238825; cv=none; d=zohomail.com; s=zohoarc; b=fvfZNIxrn+P3IV015A5GfCS8bOiRJMYiY+ysN2JLnURh4upNy+9Sh+VVVcAIM/XYxcfdWekV8PWPFcoZDhP3UrHhs8yXXkAKR/4chARgbTx3T3dCLkPftMFis71rUqjswRX+eWyoLuuFUBB4jy0uUc/u1N7xRYz3l3HfQMcSpao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658238825; 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=8GvXipf6687yqbpp29H53ftxEHpjHLircYN+XUGxjUo=; b=nUn+DLd+O95OQ84Ho50itYNM7+4OtSr7DmYhRY2r1cyd0sinsgZ6hOx0jHQdlQW13ZVg4WVvoYZa6sMwDv0wNVapgp3tD2JpgXqLLcqK0Bk0quWBCU1Yd9RUQMlY8InZwV7zRdAF0kk2GiW1SS+rlIjNcGM9fO1652IwCdJsx84= 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 1658238825219680.109208081588; Tue, 19 Jul 2022 06:53:45 -0700 (PDT) Received: from localhost ([::1]:60108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnfT-0007Bm-4u for importer@patchew.org; Tue, 19 Jul 2022 09:53:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn7H-0000DF-4o for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn78-0004vq-Qh for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:22 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-356-4Ur_fR3rNyau5VQ_A5wmpQ-1; Tue, 19 Jul 2022 09:17:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33BE38039A1; Tue, 19 Jul 2022 13:17:52 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83A2A40CFD0B; Tue, 19 Jul 2022 13:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236681; 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=8GvXipf6687yqbpp29H53ftxEHpjHLircYN+XUGxjUo=; b=b5ckg6Vraejy+dQH6jGErjB65INxLmR4GMv5Kvy8xtIMzYWPK6Iul1TA3XZiNWP8UJup2Q E8MTkj19Nfc7U0/aztBv/DMCdw1mHUTvdHsbEo4kczeAEXirBt2GynWls6e/IIWCH8uXPb B7nFwMAnCnx+bW/aUlphXnCq/huxTyM= X-MC-Unique: 4Ur_fR3rNyau5VQ_A5wmpQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zhang Chen , Like Xu , "Dr . David Alan Gilbert" , Jason Wang Subject: [PULL 21/24] softmmu/runstate.c: add RunStateTransition support form COLO to PRELAUNCH Date: Tue, 19 Jul 2022 21:16:34 +0800 Message-Id: <20220719131637.46131-22-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658238826610100001 Content-Type: text/plain; charset="utf-8" From: Zhang Chen If the checkpoint occurs when the guest finishes restarting but has not started running, the runstate_set() may reject the transition from COLO to PRELAUNCH with the crash log: {"timestamp": {"seconds": 1593484591, "microseconds": 26605},\ "event": "RESET", "data": {"guest": true, "reason": "guest-reset"}} qemu-system-x86_64: invalid runstate transition: 'colo' -> 'prelaunch' Long-term testing says that it's pretty safe. Signed-off-by: Like Xu Signed-off-by: Zhang Chen Acked-by: Dr. David Alan Gilbert Signed-off-by: Jason Wang --- softmmu/runstate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softmmu/runstate.c b/softmmu/runstate.c index fac7b63..168e1b7 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -126,6 +126,7 @@ static const RunStateTransition runstate_transitions_de= f[] =3D { { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH }, =20 { RUN_STATE_COLO, RUN_STATE_RUNNING }, + { RUN_STATE_COLO, RUN_STATE_PRELAUNCH }, { RUN_STATE_COLO, RUN_STATE_SHUTDOWN}, =20 { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237903; cv=none; d=zohomail.com; s=zohoarc; b=AVYOh7wceMWsBpsM6f619FGxRJiqo+K8NEU60g3VLXSNs89C6Vm+NB3sTT8vAV9e0cIfaSye0mpxIz2RinBkdbNWffIl4eTZ2+3X8WzcgZKL4em8E+QcbY1Eot68trJw4sEUFWi4LSUZeOPgF8LcygjNvXJ0lWB9BtuUP57u9XE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237903; 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=P6BRjPpkfZnXsZ7yFJhmm/w2iJrsMZynRt2UannPfqA=; b=hJEQ1/AkbK0MoM4/n9EjP5Uf6+daIzlQF6ilpUaF21QwmtI8g2TiCL710NavkivNQKjNfIcT8Pil9QxCBwKbPN5DzmQz0h9erHK8r++Mq0ikc9f83lu1oLCL2kd5PO6UICQbc+BVdT8FZTE4keaZPLFdt4YGgZEM5PFtpOGP7yc= 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 1658237903078948.7348189427162; Tue, 19 Jul 2022 06:38:23 -0700 (PDT) Received: from localhost ([::1]:57460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnQb-0001N3-OA for importer@patchew.org; Tue, 19 Jul 2022 09:38:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6v-0008VH-IR for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn6t-0004vW-Gx for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:00 -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-115-O9k-h9XtM4uGUXBBx7GY8A-1; Tue, 19 Jul 2022 09:17:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12630185A7BA; Tue, 19 Jul 2022 13:17:55 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC0CD40466AE; Tue, 19 Jul 2022 13:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236678; 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=P6BRjPpkfZnXsZ7yFJhmm/w2iJrsMZynRt2UannPfqA=; b=NXl86EQ/NizihNwHlTRAsg05RWPEyeClCRfp3iZRIjZ1k4GBxyuF4PDVFOtzejgRzdi/dW qkF6M/68pkI7LQWoNMPONV9NrgcmrI9tyiqovtB/+kaICz6tzqNonEbr9KDI6n3ze43foG pgaXz6GrvkEKuIsBaGtC0XTtriLELSk= X-MC-Unique: O9k-h9XtM4uGUXBBx7GY8A-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zhang Chen , Like Xu , Jason Wang Subject: [PULL 22/24] net/colo: Fix a "double free" crash to clear the conn_list Date: Tue, 19 Jul 2022 21:16:35 +0800 Message-Id: <20220719131637.46131-23-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237905136100003 Content-Type: text/plain; charset="utf-8" From: Zhang Chen We notice the QEMU may crash when the guest has too many incoming network connections with the following log: 15197@1593578622.668573:colo_proxy_main : colo proxy connection hashtable f= ull, clear it free(): invalid pointer [1] 15195 abort (core dumped) qemu-system-x86_64 .... This is because we create the s->connection_track_table with g_hash_table_new_full() which is defined as: GHashTable * g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func); The fourth parameter connection_destroy() will be called to free the memory allocated for all 'Connection' values in the hashtable when we call g_hash_table_remove_all() in the connection_hashtable_reset(). But both connection_track_table and conn_list reference to the same conn instance. It will trigger double free in conn_list clear. So this patch remove free action on hash table side to avoid double free the conn. Signed-off-by: Like Xu Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 2 +- net/filter-rewriter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index d5d0965..787c740 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -1323,7 +1323,7 @@ static void colo_compare_complete(UserCreatable *uc, = Error **errp) s->connection_track_table =3D g_hash_table_new_full(connection_key_has= h, connection_key_equal, g_free, - connection_destroy); + NULL); =20 colo_compare_iothread(s); =20 diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index bf05023..c18c4c2 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -383,7 +383,7 @@ static void colo_rewriter_setup(NetFilterState *nf, Err= or **errp) s->connection_track_table =3D g_hash_table_new_full(connection_key_has= h, connection_key_equal, g_free, - connection_destroy); + NULL); s->incoming_queue =3D qemu_new_net_queue(qemu_netfilter_pass_to_next, = nf); } =20 --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658238647; cv=none; d=zohomail.com; s=zohoarc; b=ACcIs2jfXEqIbdzyMHP+piPiJWvPLl7bPDr7vkyR0oqIo5e4g7XjRn0QSuqemR4LTBWdlObCXapK1g7dxFoxV6MlTSaLUjUt9GyZjag6RLazTpUi8s2PaBdNm/dz5E3uvMV34+ETFPb3TMNzv+CPQrJ+eg1yRkZepwEmxVUvDVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658238647; 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=+BYBEYk0AmND1Fp6+gIzqlGET0qgvNnhml1N8GSZbDQ=; b=A5SXqnCzkUHSSrr/1aZArwPtiBfzBhYymGK/W4guNk5CyObcLKvRcJm/LaO7RcI4SLqmk2ZcwMQ6y1cnHugo4K5jms6zqkyrjQ/dSFBYjfNYw7gT1OTe50o+7N/TmiDNtfj8Muk2EZJNz1jqzSUtx2jIQzCADnSRkEBrtGY8ius= 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 1658238647552437.4459894540706; Tue, 19 Jul 2022 06:50:47 -0700 (PDT) Received: from localhost ([::1]:51532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDncb-000133-AF for importer@patchew.org; Tue, 19 Jul 2022 09:50:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn7H-0000Dq-AB for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn7E-0004wE-Lk for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:23 -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-542-LB-a-E6GM-25IfBkd-jHgw-1; Tue, 19 Jul 2022 09:17:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC5AB185A7BA; Tue, 19 Jul 2022 13:17:57 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id B643440CFD0A; Tue, 19 Jul 2022 13:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236687; 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=+BYBEYk0AmND1Fp6+gIzqlGET0qgvNnhml1N8GSZbDQ=; b=F8fzwo6Urd5zzjeV3vevI00HK5XpEI3Yaqu3smknM1ah9/QSkZI+uk7Z3aQe3ppFpG2OUd r2McmJ3yCO/if7dpmSs5gvjPBztWDJN6IL+M4rFvGMg75aU47AOVVGuIzxAbSkklFLX7lR Uwz03K2qid7GtvKDAUZfcuApzmu44/0= X-MC-Unique: LB-a-E6GM-25IfBkd-jHgw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zhang Chen , Li Zhijian , Jason Wang Subject: [PULL 23/24] net/colo.c: No need to track conn_list for filter-rewriter Date: Tue, 19 Jul 2022 21:16:36 +0800 Message-Id: <20220719131637.46131-24-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658238648679100001 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Filter-rewriter no need to track connection in conn_list. This patch fix the glib g_queue_is_empty assertion when COLO guest keep a lot of network connection. Signed-off-by: Zhang Chen Reviewed-by: Li Zhijian Signed-off-by: Jason Wang --- net/colo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/colo.c b/net/colo.c index 1f8162f..694f3c9 100644 --- a/net/colo.c +++ b/net/colo.c @@ -218,7 +218,7 @@ Connection *connection_get(GHashTable *connection_track= _table, /* * clear the conn_list */ - while (!g_queue_is_empty(conn_list)) { + while (conn_list && !g_queue_is_empty(conn_list)) { connection_destroy(g_queue_pop_head(conn_list)); } } --=20 2.7.4 From nobody Mon May 6 16:36:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658237731; cv=none; d=zohomail.com; s=zohoarc; b=MDhKk66+E4hpWlyMnFpCIaRmv/1qgMsHgLryquAOW+wcvELnbYlOw+tLf3d9/OsCSCboedLkEK9Whx+78SRWpHRydKtbr+SCiwdOEGKElL9CytzJrZahGcC3ejyfO1IH9fRL/fvxRQJqDkVpsEe+zdH/1tk6MKA6TxZ1AjzIJ6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658237731; 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=Z8850xtzTkB/9nDlh2gEaq+QsEQKJh2EDDPTSePnvFM=; b=WKyymAVwlD9TlEOzLEYt4TYEifTDKngKV+caO2GEyDgbhpCgoFrZgOh35XWKRmiowwEZMnrT9L1qmKe482QfXhXcx1tNkCSOQYcE8Q/97FwLmsGa2zPILYpQ2HGPoyYMihEeScNy06wznysE6Fi/JkAJkV0ZmieT8u3DYJ7Wq8w= 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 1658237731439310.9693452027493; Tue, 19 Jul 2022 06:35:31 -0700 (PDT) Received: from localhost ([::1]:50328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnNq-0004HG-6S for importer@patchew.org; Tue, 19 Jul 2022 09:35:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn7G-0000Bu-Cm for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn7E-0004w8-Kf for qemu-devel@nongnu.org; Tue, 19 Jul 2022 09:18:21 -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-244-6aMshcsWOeOJKZA0Yqx30g-1; Tue, 19 Jul 2022 09:18:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3372638149B1; Tue, 19 Jul 2022 13:18:01 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90E4640CF8E5; Tue, 19 Jul 2022 13:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236685; 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=Z8850xtzTkB/9nDlh2gEaq+QsEQKJh2EDDPTSePnvFM=; b=X5YTuHYOq0GnlX6k343Swsk+TYa7Ah1KdWiv26SyhhPrWML/+y/eF6H1mnrAjt/dIpp2Uo MB5ipUwxCuG3mHyRFTA2G0meTdabqAHZHVvaykPZX7THIuW+5umx9+p0H1gjraANEt7o2Y fQnH4MBwdVL4r/Ho6GZOzxFvTH6voXQ= X-MC-Unique: 6aMshcsWOeOJKZA0Yqx30g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Zhang Chen , Tao Xu , Li Zhijian , Jason Wang Subject: [PULL 24/24] net/colo.c: fix segmentation fault when packet is not parsed correctly Date: Tue, 19 Jul 2022 21:16:37 +0800 Message-Id: <20220719131637.46131-25-jasowang@redhat.com> In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com> References: <20220719131637.46131-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658237733423100003 Content-Type: text/plain; charset="utf-8" From: Zhang Chen When COLO use only one vnet_hdr_support parameter between filter-redirector and filter-mirror(or colo-compare), COLO will crash with segmentation fault. Back track as follow: Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000555555cb200b in eth_get_l2_hdr_length (p=3D0x0) at /home/tao/project/COLO/colo-qemu/include/net/eth.h:296 296 uint16_t proto =3D be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto); (gdb) bt 0 0x0000555555cb200b in eth_get_l2_hdr_length (p=3D0x0) at /home/tao/project/COLO/colo-qemu/include/net/eth.h:296 1 0x0000555555cb22b4 in parse_packet_early (pkt=3D0x555556a44840) at net/colo.c:49 2 0x0000555555cb2b91 in is_tcp_packet (pkt=3D0x555556a44840) at net/filter-rewriter.c:63 So wrong vnet_hdr_len will cause pkt->data become NULL. Add check to raise error and add trace-events to track vnet_hdr_len. Signed-off-by: Tao Xu Signed-off-by: Zhang Chen Reviewed-by: Li Zhijian Signed-off-by: Jason Wang --- net/colo.c | 9 ++++++++- net/trace-events | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/net/colo.c b/net/colo.c index 694f3c9..6b0ff56 100644 --- a/net/colo.c +++ b/net/colo.c @@ -46,7 +46,14 @@ int parse_packet_early(Packet *pkt) static const uint8_t vlan[] =3D {0x81, 0x00}; uint8_t *data =3D pkt->data + pkt->vnet_hdr_len; uint16_t l3_proto; - ssize_t l2hdr_len =3D eth_get_l2_hdr_length(data); + ssize_t l2hdr_len; + + 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); + return 1; + } + l2hdr_len =3D eth_get_l2_hdr_length(data); =20 if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) { trace_colo_proxy_main("pkt->size < ETH_HLEN"); diff --git a/net/trace-events b/net/trace-events index d7a1725..6af927b 100644 --- a/net/trace-events +++ b/net/trace-events @@ -9,6 +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" =20 # colo-compare.c colo_compare_main(const char *chr) ": %s" --=20 2.7.4