From nobody Sat May 18 21:00:27 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=1658480496; cv=none; d=zohomail.com; s=zohoarc; b=YFTVnGEZAA9ZzZzgfT5qTP1LXqEGvJy0ZiVdatq1iEjx+0aaCFoZ4mghtvGgl/dJBsFFFheIHTuEhYO8riyjaIIFy8EjawR35hVa+zmFuKgawR4+DxBkhWz10LF76X4xY0bIVa+ssdnh4Uw3HdOiRw3+A4ew7BdZEMxJ9XVHiv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658480496; 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=ZJjoWNgiO9pSxFfxgEXPumFynQaR4e570fIWsLS9YCg=; b=iPJh62U+zIC+WdxuMuABXwp4SdnEYGt2V8EPIva77MFlr1IZ/nAcSBkHlwu4qNKPrdhrFnbhUCDbHWHt4swjrIzb9X4zJ9aeGgkFQi4LHPnevRu7AsMXU/PhdmMfgscU0bv2q1DQb/sy+2fouqgXSBW2IWDGIwfjVRxOVG3NjsQ= 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 1658480496476590.4170904434862; Fri, 22 Jul 2022 02:01:36 -0700 (PDT) Received: from localhost ([::1]:51594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEoXN-0003lE-Ta for importer@patchew.org; Fri, 22 Jul 2022 05:01:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoSx-0000od-9U for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:56:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoSu-0000Ym-T7 for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:56:59 -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-155-YuEJ-CeQNQ-47b6B5vPddg-1; Fri, 22 Jul 2022 04:56:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 489EA85A585; Fri, 22 Jul 2022 08:56:52 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6289D2166B26; Fri, 22 Jul 2022 08:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480216; 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=ZJjoWNgiO9pSxFfxgEXPumFynQaR4e570fIWsLS9YCg=; b=CQU+v6kWUO8Ah4VVBCvERzLG0J0OFZsl3E/8FAr4Ky8Rz6E+x/EpsEp5+haWHFwyHATNFb KrjMwMyayBIcFQm1Nrineakf8pJOxBW2QOG5Qzx/tUEMz6PRKY7aJX4LQWqlyD1/wkMHQl h12D7tetWlP2HVN5a6ghp6iZVdiFZi4= X-MC-Unique: YuEJ-CeQNQ-47b6B5vPddg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 1/6] vhost: stop transfer elem ownership in vhost_handle_guest_kick Date: Fri, 22 Jul 2022 10:56:39 +0200 Message-Id: <20220722085644.3376708-2-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658480497985100001 It was easier to allow vhost_svq_add to handle the memory. Now that we will allow qemu to add elements to a SVQ without the guest's knowledge, it's better to handle it in the caller. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e4956728dd..ffd2b2c972 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -233,9 +233,6 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) /** * Add an element to a SVQ. * - * The caller must check that there is enough slots for the new element. It - * takes ownership of the element: In case of failure not ENOSPC, it is fr= ee. - * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, @@ -252,7 +249,6 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const stru= ct iovec *out_sg, =20 ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_= head); if (unlikely(!ok)) { - g_free(elem); return -EINVAL; } =20 @@ -293,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) virtio_queue_set_notification(svq->vq, false); =20 while (true) { - VirtQueueElement *elem; + g_autofree VirtQueueElement *elem; int r; =20 if (svq->next_guest_avail_elem) { @@ -324,12 +320,14 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) * queue the current guest descriptor and ignore kicks * until some elements are used. */ - svq->next_guest_avail_elem =3D elem; + svq->next_guest_avail_elem =3D g_steal_pointer(&elem); } =20 /* VQ is full or broken, just return and ignore kicks */ return; } + /* elem belongs to SVQ or external caller now */ + elem =3D NULL; } =20 virtio_queue_set_notification(svq->vq, true); --=20 2.31.1 From nobody Sat May 18 21:00:27 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=1658481367; cv=none; d=zohomail.com; s=zohoarc; b=VFt8i5XPefbhRjC+OfyDSrIcaq1Ry/9fqHoKOgLQQaB5JNrHGRYrbon81+PTU4H4IXFks0Gi3Khpum5arRcVERjGosJmSr2xqjiU6eE1uAHiQYcfKn8+gabNn86xT8OI6kUyE0OtivMGoS7LcUbSnc59RrSdTJQIikhtNigPj8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658481367; 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=1ONMuE+w6Q+NyNNeCgRomXaXD5/OUtQp8jNG9YgsBS8=; b=Nd7b1ku1brbfsRfMEgQNT5WHyBZZWsWlEMyeexHyObhOZYdAu0IW9LXQOkblfSMbb1P1uN9jX3qWjWT8bWntsL954FbzM74bn8yrCP6JdWDS0m3NxJgv5yWycwYwKT5b52S5W1H7fIMkmVy7yg24r+doowJV36EalJH9/J2l4jg= 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 1658481367807500.7664158302331; Fri, 22 Jul 2022 02:16:07 -0700 (PDT) Received: from localhost ([::1]:34560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEolS-000453-Aj for importer@patchew.org; Fri, 22 Jul 2022 05:16:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT4-0000rc-Jz for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT0-0000ZL-1g for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:04 -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-9-vjS4dAhIML6vaZOZ_DDXGQ-1; Fri, 22 Jul 2022 04:56:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5CB4E8037AC; Fri, 22 Jul 2022 08:56:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B61C2166B2A; Fri, 22 Jul 2022 08:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480220; 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=1ONMuE+w6Q+NyNNeCgRomXaXD5/OUtQp8jNG9YgsBS8=; b=dUY2DDApUG+FUTGERSPGFqe/TyDlF6CPteKN6v/m6HGxhtMcpfTSFIVEz1z8v7YVuhRZtM 5L4Ze3PovP2q9laRLjbvRiEDRPN+clbe5HpHbqN064nZgCwre58BWuVWFEN+EzY1bKocpp CgGqbDnfK12AsT7SioX+7Cwr94Xerio= X-MC-Unique: vjS4dAhIML6vaZOZ_DDXGQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 2/6] vdpa: Extract vhost_vdpa_net_cvq_add from vhost_vdpa_net_handle_ctrl_avail Date: Fri, 22 Jul 2022 10:56:40 +0200 Message-Id: <20220722085644.3376708-3-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658481368359100001 So we can reuse to inject state messages. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 74 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6abad276a6..1b82ac2e07 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -334,6 +334,46 @@ static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState= *s, return true; } =20 +static virtio_net_ctrl_ack vhost_vdpa_net_cvq_add(VhostShadowVirtqueue *sv= q, + const struct iovec *dev_buf= fers) +{ + /* in buffer used for device model */ + virtio_net_ctrl_ack status; + size_t dev_written; + int r; + + /* + * Add a fake non-NULL VirtQueueElement since we'll remove before SVQ + * event loop can get it. + */ + r =3D vhost_svq_add(svq, &dev_buffers[0], 1, &dev_buffers[1], 1, (void= *)1); + if (unlikely(r !=3D 0)) { + if (unlikely(r =3D=3D -ENOSPC)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", + __func__); + } + return VIRTIO_NET_ERR; + } + + /* + * 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); + return VIRTIO_NET_ERR; + } + + memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + if (status !=3D VIRTIO_NET_OK) { + return VIRTIO_NET_ERR; + } + + return VIRTIO_NET_OK; +} + /** * 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. @@ -380,19 +420,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, void *opaque) { VhostVDPAState *s =3D opaque; - size_t in_len, dev_written; + size_t in_len; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; /* out 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 */ + /* in buffer seen by virtio-net device model */ const struct iovec in =3D { .iov_base =3D &status, .iov_len =3D sizeof(status), }; - int r =3D -EINVAL; bool ok; =20 ok =3D vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); @@ -405,35 +444,16 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, goto out; } =20 - 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= ", - __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); - goto out; - } - - memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + status =3D vhost_vdpa_net_cvq_add(svq, dev_buffers); if (status !=3D VIRTIO_NET_OK) { goto out; } =20 status =3D VIRTIO_NET_ERR; - virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, 1); - if (status !=3D VIRTIO_NET_OK) { + in_len =3D virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, = 1); + if (in_len !=3D sizeof(status) || status !=3D VIRTIO_NET_OK) { error_report("Bad CVQ processing in model"); + return VIRTIO_NET_ERR; } =20 out: @@ -450,7 +470,7 @@ out: if (dev_buffers[1].iov_base) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[1].iov_base); } - return r; + return status =3D=3D VIRTIO_NET_OK ? 0 : 1; } =20 static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { --=20 2.31.1 From nobody Sat May 18 21:00:27 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=1658481024; cv=none; d=zohomail.com; s=zohoarc; b=ZQ11ORceBt4JxHMpBw6Xa2DS9+PBAcqWP2oxND676a7UiIHr/FqcnAlhnnGJU1ahhk19SzJG+LmxgE0/cDikOJhYr7cfzLih1A+x/G5GEVxs/Ek4uriAJHfvdgZt897AKe93erM3p/LON75n7+phUehxS6eUTz1Bx/acP6ewbgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658481024; 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=7+LUG03BDYPp5kNAJLMAJQOFe/AQNqvHDhHyOWlVtyY=; b=cQsYVBpZsD8dv3dU9GhrzEP09Jz4fA1LNdTAeb0SaOoKmjbj9tbN3xtBEqiXC9qYOPYVvdT1qLCC6kDthXV/BWDkyuDaIcZozXBZdxFU6QtCnzQirBCSbT/EohTosDyhWzbUZaVD7Fypjis5bkBhBXSGvcigYLUgBU6PdswF1kI= 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 1658481024878655.4323235566277; Fri, 22 Jul 2022 02:10:24 -0700 (PDT) Received: from localhost ([::1]:58288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEofv-0000Xh-NW for importer@patchew.org; Fri, 22 Jul 2022 05:10:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoTK-0000xm-LO for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55007) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoTI-0000ak-R9 for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57: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-218-3IiYwqfQODqjKuG_GANF7Q-1; Fri, 22 Jul 2022 04:56:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7DA2F811E80; Fri, 22 Jul 2022 08:56:58 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DC6D2166B26; Fri, 22 Jul 2022 08:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480235; 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=7+LUG03BDYPp5kNAJLMAJQOFe/AQNqvHDhHyOWlVtyY=; b=VmzCJH72+sv1zDaA7RwGCK5iyU4XPrhLpkF7J6VGDYodLROSd9gy1NkAJhAnaOXykbiJnh YM2PWF/Mlu5xPR9phPzNcGJfKNpr8cBj37S72wm+wFigw+mQfrY4xaRgFcVS6NFHFB6t20 QXE5L+dvQrxjtrYrQA0o89edbcDoz5U= X-MC-Unique: 3IiYwqfQODqjKuG_GANF7Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 3/6] vdpa: Make vhost_vdpa_net_cvq_map_elem accept any out sg Date: Fri, 22 Jul 2022 10:56:41 +0200 Message-Id: <20220722085644.3376708-4-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658481026078100001 So its generic enough to accept any out sg buffer and we can inject NIC state messages. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 1b82ac2e07..bbe1830824 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -302,35 +302,36 @@ dma_map_err: } =20 /** - * Copy the guest element into a dedicated buffer suitable to be sent to N= IC + * Maps out sg and in buffer into dedicated buffers suitable to be sent to= NIC * - * @iov: [0] is the out buffer, [1] is the in one + * @dev_iov: [0] is the out buffer, [1] is the in one */ -static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState *s, - VirtQueueElement *elem, - struct iovec *iov) +static bool vhost_vdpa_net_cvq_map_sg(VhostVDPAState *s, + const struct iovec *out, size_t out_= num, + struct iovec *dev_iov) { size_t in_copied; bool ok; =20 - iov[0].iov_base =3D s->cvq_cmd_out_buffer; - ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, elem->out_sg, elem->out_= num, - vhost_vdpa_net_cvq_cmd_len(), iov[0].iov_b= ase, - &iov[0].iov_len, false); + dev_iov[0].iov_base =3D s->cvq_cmd_out_buffer; + ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, out, out_num, + vhost_vdpa_net_cvq_cmd_len(), + dev_iov[0].iov_base, &dev_iov[0].iov_len, + false); if (unlikely(!ok)) { return false; } =20 - iov[1].iov_base =3D s->cvq_cmd_in_buffer; + dev_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); + sizeof(virtio_net_ctrl_ack), + dev_iov[1].iov_base, &in_copied, true); if (unlikely(!ok)) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); return false; } =20 - iov[1].iov_len =3D sizeof(virtio_net_ctrl_ack); + dev_iov[1].iov_len =3D sizeof(virtio_net_ctrl_ack); return true; } =20 @@ -434,7 +435,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadow= Virtqueue *svq, }; bool ok; =20 - ok =3D vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); + ok =3D vhost_vdpa_net_cvq_map_sg(s, elem->out_sg, elem->out_num, dev_b= uffers); if (unlikely(!ok)) { goto out; } --=20 2.31.1 From nobody Sat May 18 21:00:27 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=1658480745; cv=none; d=zohomail.com; s=zohoarc; b=g8jtrJHSbIYnQv9ZQDk2yUxgmpTK1TXjqOFLBwW3BzdxvtsXkm6ilyN+35qtqObA/S9WbbVfYeQgZOHoUjF1p+matdtOt/W1YU6y5NwVM6522UizQkPhvSwJTN6vhOtBXMOWwoYZb0pQ0sR8qxRID8/1mnvTy63/ILyRE5YQ+p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658480745; 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=HmfZTBtu31uLg6djxBfEgCKUx5K7bRKNxH5Q40BBmnY=; b=NQ+qAoh5Bjz7Ys3u8jkP3HAL8wrOnElUWwcoTh1fenzpyUBjfdQLSbDkgO1YrmcLTug1Bsy3fUDqfra+JpWuUNG+/Lt0iZWmUtdZGUJsHgbhzKdLUIf5b7PzTlskQ9EcxhJTsTjXVPMhblt/LB1HPWUZV8AyArFxLGmKCI++IkE= 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 1658480745913293.4165006858169; Fri, 22 Jul 2022 02:05:45 -0700 (PDT) Received: from localhost ([::1]:55282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEobO-0006NL-LY for importer@patchew.org; Fri, 22 Jul 2022 05:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT6-0000rz-Km for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT5-0000Zg-3P for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:08 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-aO1YX8OPN-CbucuelIAsXQ-1; Fri, 22 Jul 2022 04:57:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 920F3101AA6C; Fri, 22 Jul 2022 08:57:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE76D2166B26; Fri, 22 Jul 2022 08:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480226; 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=HmfZTBtu31uLg6djxBfEgCKUx5K7bRKNxH5Q40BBmnY=; b=M+Wm8sOj+6RrTpzyfoSq96gSf+X03hVsRglhkfqAJGTV1IxTSFEQOtKLspjSlW5zy5VyMI 12qVjoDgdDGta1/Qxzg7Q7fi7eCI0iuhJsz9SFKGYFBTkgbg8BIEFMK1HALrD9sDUELdMN OwLOACNmaQzn/LlqOLzerSVISd9Awco= X-MC-Unique: aO1YX8OPN-CbucuelIAsXQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 4/6] vdpa: add NetClientState->start() callback Date: Fri, 22 Jul 2022 10:56:42 +0200 Message-Id: <20220722085644.3376708-5-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658480748141100001 It allows per-net client operations right after device's successful start. Vhost-vdpa net will use it to add the CVQ buffers to restore the device status. Signed-off-by: Eugenio P=C3=A9rez --- include/net/net.h | 2 ++ hw/net/vhost_net.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 523136c7ac..ad9e80083a 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -44,6 +44,7 @@ typedef struct NICConf { =20 typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); +typedef int (NetStart)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); typedef void (NetCleanup) (NetClientState *); @@ -71,6 +72,7 @@ typedef struct NetClientInfo { NetReceive *receive_raw; NetReceiveIOV *receive_iov; NetCanReceive *can_receive; + NetStart *start; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; QueryRxFilter *query_rx_filter; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ccac5b7a64..ddd9ee0441 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -274,6 +274,13 @@ static int vhost_net_start_one(struct vhost_net *net, } } } + + if (net->nc->info->start) { + r =3D net->nc->info->start(net->nc); + if (r < 0) { + goto fail; + } + } return 0; fail: file.fd =3D -1; --=20 2.31.1 From nobody Sat May 18 21:00:27 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=1658481447; cv=none; d=zohomail.com; s=zohoarc; b=XhV4Ub5Pu72AjP6kJHd4glQyFz2uWTOeQc0um2A1qt1TlBmt6dmO7wlYMDFil6kh9rSlZA+wFgM6e0b53M7GFeSLR8HkZ1Iy+cqJttmk9CWiTuyd+DI/ujWmBIPLH0x9RiVycLo5vncWKD4E1VWefm9M3lviFO7BnoTLpmP3ajc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658481447; 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=b+pUrxmucxdqUhAARgri+wPkG43k1iF1iTN1sUBjuWM=; b=D5RAR1qtG/rW3Ww/kWLtOvKmreGNhF15QbzWzz/Zesq4mbXV0Pen9pJi9CL+Jtm3uGuK0xPg3mUZdwmRh+XTH/7brB8RSYFflaLUe97rK4tWBUtIAtnKLRN10Bu5pgab3iTj+/fu0oIfX0UCDANj65DoN9qg3pRNZHV5J34+vLQ= 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 1658481447698121.88161605713731; Fri, 22 Jul 2022 02:17:27 -0700 (PDT) Received: from localhost ([::1]:35312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEomk-0004h2-2f for importer@patchew.org; Fri, 22 Jul 2022 05:17:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT7-0000s5-UA for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23375) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoT5-0000Zj-AC for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:08 -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-649-eBrQtQnhNjiEvvU3Y8zIZQ-1; Fri, 22 Jul 2022 04:57:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B04583C0F37F; Fri, 22 Jul 2022 08:57:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id D31CE2166B26; Fri, 22 Jul 2022 08:57:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480226; 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=b+pUrxmucxdqUhAARgri+wPkG43k1iF1iTN1sUBjuWM=; b=J+5KAeZg30ohkmtlasIzpd3ynw3iUOvh34MD49qCOCRhOdoiic6V1i/yeZK+Ry5y2fkaNB zJtE3GtTtPKnuM37JBaCBMl22q8NfrzUj9VP+ce+6lDqxms4bt2rsOym6d1gZfPzT0NcUN yCO51Nx1Uj3j5n/Dz+EgtR3KDRNH5k0= X-MC-Unique: eBrQtQnhNjiEvvU3Y8zIZQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 5/6] vdpa: Add virtio-net mac address via CVQ at start Date: Fri, 22 Jul 2022 10:56:43 +0200 Message-Id: <20220722085644.3376708-6-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658481449010100001 This is needed so the destination vdpa device see the same state a the guest set in the source. Signed-off-by: Eugenio P=C3=A9rez --- include/net/vhost-vdpa.h | 1 + net/vhost-vdpa.c | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h index b81f9a6f2a..38d65e845d 100644 --- a/include/net/vhost-vdpa.h +++ b/include/net/vhost-vdpa.h @@ -15,6 +15,7 @@ #define TYPE_VHOST_VDPA "vhost-vdpa" =20 struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +int vhost_vdpa_start(NetClientState *nc); =20 extern const int vdpa_feature_bits[]; =20 diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index bbe1830824..84e90f067a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -375,6 +375,63 @@ static virtio_net_ctrl_ack vhost_vdpa_net_cvq_add(Vhos= tShadowVirtqueue *svq, return VIRTIO_NET_OK; } =20 +int vhost_vdpa_start(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_vdpa *v =3D &s->vhost_vdpa; + VirtIONet *n =3D VIRTIO_NET(v->dev->vdev); + uint64_t features =3D v->dev->vdev->host_features; + VhostShadowVirtqueue *svq; + + if (!v->shadow_vqs_enabled) { + return 0; + } + + if (v->dev->vq_index + v->dev->nvqs !=3D v->dev->vq_index_end) { + /* Only interested in CVQ */ + return 0; + } + + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + svq =3D g_ptr_array_index(v->shadow_vqs, 0); + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl =3D { + .class =3D VIRTIO_NET_CTRL_MAC, + .cmd =3D VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + uint8_t mac[6]; + const struct iovec out[] =3D { + { + .iov_base =3D (void *)&ctrl, + .iov_len =3D sizeof(ctrl), + },{ + .iov_base =3D mac, + .iov_len =3D sizeof(mac), + }, + }; + struct iovec dev_buffers[2] =3D { + { .iov_base =3D s->cvq_cmd_out_buffer }, + { .iov_base =3D s->cvq_cmd_in_buffer }, + }; + bool ok; + virtio_net_ctrl_ack state; + + ok =3D vhost_vdpa_net_cvq_map_sg(s, out, ARRAY_SIZE(out), dev_buff= ers); + if (unlikely(!ok)) { + return -1; + } + + memcpy(mac, n->mac, sizeof(mac)); + state =3D vhost_vdpa_net_cvq_add(svq, dev_buffers); + vhost_vdpa_cvq_unmap_buf(v, dev_buffers[0].iov_base); + vhost_vdpa_cvq_unmap_buf(v, dev_buffers[1].iov_base); + return state =3D=3D VIRTIO_NET_OK ? 0 : 1; + } + + return 0; +} + /** * 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. --=20 2.31.1 From nobody Sat May 18 21:00:27 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=1658481194; cv=none; d=zohomail.com; s=zohoarc; b=H9WjvRYMNVeNwumuUcobrB+2SBlfhV7Z/iXEucs1/ublcWUi6sIdFxA8c1SaPhYe8jOSSpOqphLu6vqDZN/pQ3sc2AI3/eIVarA/3ygSzZHjUyCjISgCLyfJxnv9YivktqKpWxHwBsRQ/UVmw0SYJXxh+TgDxGf0BAkJEoUzv8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658481194; 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=5HxchaYS2tXhXSUWY135VPp0O6zBM6kYUQbG0qbDSLo=; b=Jyl99Tm0SRhnAkLR7Wmu1HmXXsnACE9gaDXzXmFSnfdjHbHE7ZKqHSxpYK83M39xjFuKCXvFNd7MUVEdkMmun94bI2zHPs+Ka8VQN708L9NUBSOz1wSlSS2P92evI/oOzFWntapbv+fmiexdIMBSlOrZPNmKfDcP8mgmiR2NvR0= 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 1658481194799116.55217368535227; Fri, 22 Jul 2022 02:13:14 -0700 (PDT) Received: from localhost ([::1]:60386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEoia-0002FB-2s for importer@patchew.org; Fri, 22 Jul 2022 05:13:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoTD-0000uK-DH for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEoTB-0000aP-Va for qemu-devel@nongnu.org; Fri, 22 Jul 2022 04:57:15 -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-497-u0NqkHXbPImVSc9r93vm8Q-1; Fri, 22 Jul 2022 04:57:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C95661019C90; Fri, 22 Jul 2022 08:57:07 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1D982166B26; Fri, 22 Jul 2022 08:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658480232; 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=5HxchaYS2tXhXSUWY135VPp0O6zBM6kYUQbG0qbDSLo=; b=epZuLpHcTDw5OIi/j0EoQUqDjOXF4Y9/CPAvyqFCUiC7XXaHQXmbn0r3pkDQkx2D8+e26r y/cPPE6M3bPz3nPXUDJo9VW6bFA8CyyLLc6bMkCJU0GsDr149Kbr/qykZ8fLulIR9WXsJJ EFUkokkMV5MTnNem5nmT+5d+NiG/Qxs= X-MC-Unique: u0NqkHXbPImVSc9r93vm8Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gautam Dawar , "Gonglei (Arei)" , Cornelia Huck , Zhu Lingshan , Cindy Lu , Liuxiangdong , Laurent Vivier , Markus Armbruster , Paolo Bonzini , Parav Pandit , Harpreet Singh Anand , Jason Wang , "Michael S. Tsirkin" , Eli Cohen , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v3 6/6] vdpa: Delete CVQ migration blocker Date: Fri, 22 Jul 2022 10:56:44 +0200 Message-Id: <20220722085644.3376708-7-eperezma@redhat.com> In-Reply-To: <20220722085644.3376708-1-eperezma@redhat.com> References: <20220722085644.3376708-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658481196349100001 We can restore the device state in the destination via CVQ now. Remove the migration blocker. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 1 - hw/virtio/vhost-vdpa.c | 14 -------------- net/vhost-vdpa.c | 2 -- 3 files changed, 17 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index d10a89303e..1111d85643 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -35,7 +35,6 @@ typedef struct vhost_vdpa { bool shadow_vqs_enabled; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; - Error *migration_blocker; GPtrArray *shadow_vqs; const VhostShadowVirtqueueOps *shadow_vq_ops; void *shadow_vq_ops_opaque; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 3ff9ce3501..9a2daef7e3 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1023,13 +1023,6 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *= dev) return true; } =20 - if (v->migration_blocker) { - int r =3D migrate_add_blocker(v->migration_blocker, &err); - if (unlikely(r < 0)) { - return false; - } - } - for (i =3D 0; i < v->shadow_vqs->len; ++i) { VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); @@ -1072,10 +1065,6 @@ err: vhost_svq_stop(svq); } =20 - if (v->migration_blocker) { - migrate_del_blocker(v->migration_blocker); - } - return false; } =20 @@ -1095,9 +1084,6 @@ 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/net/vhost-vdpa.c b/net/vhost-vdpa.c index 84e90f067a..82c115bee4 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -573,8 +573,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; - error_setg(&s->vhost_vdpa.migration_blocker, - "Migration disabled: vhost-vdpa uses CVQ."); } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { --=20 2.31.1