From patchwork Thu Aug 4 18:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34342C19F2A for ; Thu, 4 Aug 2022 18:21:54 +0000 (UTC) Received: from localhost ([::1]:56310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfTl-0001DX-9N for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:21:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPu-0005yW-QL for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPr-0001Ei-QL for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637071; 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=Nv7dQgo9IBDKRdHrkEQ8Fu3FMnJagx8kXt1iU0gzeHT9aYBMEkaj1AfzNxWg6au++9dZfV joZ1VoY4+CJijJibYJ5fVjfgkVrLDGpaKyahnrbl4wa8mr/CMKTCVApeiC1R6SYbBxsagS 8d0utcHX8jpVrX7JUYq/AC6KuO0ChgY= 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-544-4zXFXU4CMx6tSiYqmq2GQQ-1; Thu, 04 Aug 2022 14:17:47 -0400 X-MC-Unique: 4zXFXU4CMx6tSiYqmq2GQQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7CB6818B53EB; Thu, 4 Aug 2022 18:17:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FFB8492C3B; Thu, 4 Aug 2022 18:17:28 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 01/12] vhost: stop transfer elem ownership in vhost_handle_guest_kick Date: Thu, 4 Aug 2022 20:17:11 +0200 Message-Id: <20220804181722.701067-2-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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érez --- 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-virtqueue.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 free. - * * 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 struct iovec *out_sg, ok = vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head); if (unlikely(!ok)) { - g_free(elem); return -EINVAL; } @@ -293,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) virtio_queue_set_notification(svq->vq, false); while (true) { - VirtQueueElement *elem; + g_autofree VirtQueueElement *elem; int r; if (svq->next_guest_avail_elem) { @@ -324,12 +320,14 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) * queue the current guest descriptor and ignore kicks * until some elements are used. */ - svq->next_guest_avail_elem = elem; + svq->next_guest_avail_elem = g_steal_pointer(&elem); } /* VQ is full or broken, just return and ignore kicks */ return; } + /* elem belongs to SVQ or external caller now */ + elem = NULL; } virtio_queue_set_notification(svq->vq, true); From patchwork Thu Aug 4 18:17:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D8EFC19F2A for ; Thu, 4 Aug 2022 18:24:23 +0000 (UTC) Received: from localhost ([::1]:35954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfWA-0006iW-N5 for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:24:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPu-0005yG-Nf for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPr-0001EO-7p for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637070; 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=mFcSWUZrd/1meZg3dITq3TzQyarfrxoNesnu+w7BZmQ=; b=W+2tf65PxDJVcxrkGfwNaEG8clYD/cZDE+1BPns33u76WZZLgSP1yaeTUxfe9vZgfKRx1S w+egZKZwdrYSULbgTzd6So3+bDSycUKdhENUgydGQiomzY11T+f6wsED0gBmhm8qLibM9e 5O77VaoxWB4WS2JCPlEStfvOccRmQ28= 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-35-4ybmrivsN8Cw15iNeI7m3g-1; Thu, 04 Aug 2022 14:17:48 -0400 X-MC-Unique: 4ybmrivsN8Cw15iNeI7m3g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC856800DBE; Thu, 4 Aug 2022 18:17:34 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id C42B2492C3B; Thu, 4 Aug 2022 18:17:31 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 02/12] vhost: use SVQ element ndescs instead of opaque data for desc validation Date: Thu, 4 Aug 2022 20:17:12 +0200 Message-Id: <20220804181722.701067-3-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Since we're going to allow SVQ to add elements without the guest's knowledge and without its own VirtQueueElement, it's easier to check if an element is a valid head checking a different thing than the VirtQueueElement. Signed-off-by: Eugenio Pérez --- 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-virtqueue.c index ffd2b2c972..e6eebd0e8d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -414,7 +414,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, return NULL; } - if (unlikely(!svq->desc_state[used_elem.id].elem)) { + if (unlikely(!svq->desc_state[used_elem.id].ndescs)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", svq->vdev->name, used_elem.id); @@ -422,6 +422,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, } num = svq->desc_state[used_elem.id].ndescs; + svq->desc_state[used_elem.id].ndescs = 0; last_used_chain = vhost_svq_last_desc_of_chain(svq, num, used_elem.id); svq->desc_next[last_used_chain] = svq->free_head; svq->free_head = used_elem.id; From patchwork Thu Aug 4 18:17:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3226C19F2A for ; Thu, 4 Aug 2022 18:25:00 +0000 (UTC) Received: from localhost ([::1]:36664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfWl-0007Dv-RT for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPv-0005zJ-4l for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPs-0001Eq-3c for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637071; 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=buucNH6UPudgudlKQDxV5Skj8xgGaEiYKwfKh+0154k=; b=OS60kcMnGYfaecKqEoL03tytjWcw/3u1FKEsuJy6LaoaKBZhqhNbW0eVB4OWRnxZdOCLEX zFWqSYNfVvt07C5exia8uXomBevlH4ta5MHwzNpRLU9qNb6FzTfN+hIP91XWnqOEXeWCjy eehBXzuhJLepXb9HXYC7sN4nBKJpdw8= 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-132-uBiaOGByPP20Y8RgoGCBNQ-1; Thu, 04 Aug 2022 14:17:48 -0400 X-MC-Unique: uBiaOGByPP20Y8RgoGCBNQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 348A48057B9; Thu, 4 Aug 2022 18:17:38 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E7B9492C3B; Thu, 4 Aug 2022 18:17:35 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 03/12] vhost: Delete useless read memory barrier Date: Thu, 4 Aug 2022 20:17:13 +0200 Message-Id: <20220804181722.701067-4-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As discussed in previous series [1], this memory barrier is useless with the atomic read of used idx at vhost_svq_more_used. Deleting it. [1] https://lists.nongnu.org/archive/html/qemu-devel/2022-07/msg02616.html Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-shadow-virtqueue.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c index e6eebd0e8d..1b49bf54f2 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -509,9 +509,6 @@ size_t vhost_svq_poll(VhostShadowVirtqueue *svq) if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { return 0; } - - /* Make sure we read new used_idx */ - smp_rmb(); } while (true); } From patchwork Thu Aug 4 18:17:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DA2EC19F2A for ; Thu, 4 Aug 2022 18:32:21 +0000 (UTC) Received: from localhost ([::1]:52808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfds-0002XG-AC for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPv-0005zL-4b for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPs-0001Eu-If for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637072; 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=0B8KI4/fnEok6w2Efz5xLoWx7wcqHk6mQq7G+EE1gok=; b=gyGKROFTgC+bhrxNJ4GgcYjP1zrJjwixyF8IUxrRRqtLqNz/F9Z+74BoF/aW7cpHPntAcH 2vRqNIUGebM0N7FI0ZEW5u3OLlsmEjdwCeIOuBoU2aaf9q9f68OVefKrIRmxZaMsMF4aOU VMD9E5vxkqVxbjGPdDhiGI1MHLl6vMU= 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-g_EtLKGPOfCG1pxft7bN3Q-1; Thu, 04 Aug 2022 14:17:48 -0400 X-MC-Unique: g_EtLKGPOfCG1pxft7bN3Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 882EB8039AE; Thu, 4 Aug 2022 18:17:41 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82EB6492C3B; Thu, 4 Aug 2022 18:17:38 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 04/12] vhost: Do not depend on !NULL VirtQueueElement on vhost_svq_flush Date: Thu, 4 Aug 2022 20:17:14 +0200 Message-Id: <20220804181722.701067-5-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Since QEMU will be able to inject new elements on CVQ to restore the state, we need not to depend on a VirtQueueElement to know if a new element has been used by the device or not. Instead of check that, check if there are new elements only using used idx on vhost_svq_flush. Signed-off-by: Eugenio Pérez --- v6: Change less from the previous function --- hw/virtio/vhost-shadow-virtqueue.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c index 1b49bf54f2..f863b08627 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -499,17 +499,20 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, size_t vhost_svq_poll(VhostShadowVirtqueue *svq) { int64_t start_us = g_get_monotonic_time(); + uint32_t len; + do { - uint32_t len; - VirtQueueElement *elem = vhost_svq_get_buf(svq, &len); - if (elem) { - return len; + if (vhost_svq_more_used(svq)) { + break; } if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { return 0; } } while (true); + + vhost_svq_get_buf(svq, &len); + return len; } /** From patchwork Thu Aug 4 18:17:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936560 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59567C19F2A for ; Thu, 4 Aug 2022 18:21:29 +0000 (UTC) Received: from localhost ([::1]:55502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfTL-0000dp-MX for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:21:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPw-0005zY-R5 for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPv-0001FS-Ao for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637074; 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=pSOYJFmCUIy0mfnEqXO1DVzB+00pvt/ixLKLNmEb53A=; b=YcUB0LD24Xx/gyAQq7MMrCMXpKEJVyxQY3brz1/VQZxeaSjr3WJewjvTHIfm9yGfuB5juj LF2CMAKD3ntofwhaIK0ptaS3W2aqSsWkx1ciNP9a6Pl6pNXss29pUMK74HbY5n7s+WLCGE H/T+RDLuTLtAhlAlcStXLx1uvp1fvI4= 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-113-NydWgWClM32tq-KzrWtq-Q-1; Thu, 04 Aug 2022 14:17:48 -0400 X-MC-Unique: NydWgWClM32tq-KzrWtq-Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D867810AF63C; Thu, 4 Aug 2022 18:17:44 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4E40492C3B; Thu, 4 Aug 2022 18:17:41 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 05/12] vhost_net: Add NetClientInfo prepare callback Date: Thu, 4 Aug 2022 20:17:15 +0200 Message-Id: <20220804181722.701067-6-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is used by the backend to perform actions before the device is started. In particular, vdpa net use it to map CVQ buffers to the device, so it can send control commands using them. Signed-off-by: Eugenio Pérez --- 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..3416bb3d46 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -44,6 +44,7 @@ typedef struct NICConf { typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); +typedef int (NetPrepare)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); typedef void (NetCleanup) (NetClientState *); @@ -71,6 +72,7 @@ typedef struct NetClientInfo { NetReceive *receive_raw; NetReceiveIOV *receive_iov; NetCanReceive *can_receive; + NetPrepare *prepare; 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..e1150d7532 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -244,6 +244,13 @@ static int vhost_net_start_one(struct vhost_net *net, struct vhost_vring_file file = { }; int r; + if (net->nc->info->prepare) { + r = net->nc->info->prepare(net->nc); + if (r < 0) { + return r; + } + } + r = vhost_dev_enable_notifiers(&net->dev, dev); if (r < 0) { goto fail_notifiers; From patchwork Thu Aug 4 18:17:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90E2FC19F2A for ; Thu, 4 Aug 2022 18:27:22 +0000 (UTC) Received: from localhost ([::1]:44592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfZ3-0004UR-Ld for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:27:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPv-0005zX-Vf for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPu-0001FD-Bo for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637073; 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=BSRnyzTJnZsFHFDCrpPS135y1ud3kS4PVdpPYIF/UdY=; b=Vs483XQPrgqbsGK7NyibSBcAfW2dyLjOsQnDykXb6CwjxvmroAkptnqbTCfOV0KjmD+ru8 X/3g+zfsTuMcrGXB3fFNmjsZT/w1EHhK+hTwDH1+v295Yc7IxUewF+HSI4zv2lk2L4IZt7 5naTZvBygh6ssYtXiOyAGo4CD1o+YjE= 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-41-_-BOvVVrPsqRC6VGeSbJPg-1; Thu, 04 Aug 2022 14:17:49 -0400 X-MC-Unique: _-BOvVVrPsqRC6VGeSbJPg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DA5394EF84; Thu, 4 Aug 2022 18:17:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A182492C3B; Thu, 4 Aug 2022 18:17:45 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 06/12] vhost_net: Add NetClientInfo stop callback Date: Thu, 4 Aug 2022 20:17:16 +0200 Message-Id: <20220804181722.701067-7-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Used by the backend to perform actions after the device is stopped. In particular, vdpa net use it to unmap CVQ buffers to the device, cleaning the actions performend in prepare(). Signed-off-by: Eugenio Pérez --- include/net/net.h | 2 ++ hw/net/vhost_net.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 3416bb3d46..7aa1ec0974 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -45,6 +45,7 @@ typedef struct NICConf { typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); typedef int (NetPrepare)(NetClientState *); +typedef void (NetStop)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); typedef void (NetCleanup) (NetClientState *); @@ -73,6 +74,7 @@ typedef struct NetClientInfo { NetReceiveIOV *receive_iov; NetCanReceive *can_receive; NetPrepare *prepare; + NetStop *stop; 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 e1150d7532..10bca15446 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -320,6 +320,9 @@ static void vhost_net_stop_one(struct vhost_net *net, net->nc->info->poll(net->nc, true); } vhost_dev_stop(&net->dev, dev); + if (net->nc->info->stop) { + net->nc->info->stop(net->nc); + } vhost_dev_disable_notifiers(&net->dev, dev); } From patchwork Thu Aug 4 18:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 244BFC19F2D for ; Thu, 4 Aug 2022 18:39:03 +0000 (UTC) Received: from localhost ([::1]:60756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfkK-0001Yl-08 for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPw-0005zW-7T for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPu-0001FA-33 for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:17:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637073; 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=0YxI/0ZTCBCCZEzbzofzIBZ7fTOGvTQV1XF3Qc6vPOM=; b=Wgxo1DykkC3VbwqJfp5MCFe3zJ5H2UiGz7gqXimK7tlabaXbh2/UTNmBzTKMhabLJ98G9b BxGLPi+ojtCeCbXawezsJ9mUgJnpVdcoEOvMuBelDVOfj6QmETO6yIbxgOm3ouQfJzY8+n WcY9NQdM0j8kty4L/NQzbaZTsZmM+tU= 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-83-pH5NxgfqN6qdb87ixJEqhg-1; Thu, 04 Aug 2022 14:17:52 -0400 X-MC-Unique: pH5NxgfqN6qdb87ixJEqhg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA4AD85A584; Thu, 4 Aug 2022 18:17:51 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1309492C3B; Thu, 4 Aug 2022 18:17:48 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 07/12] vdpa: add net_vhost_vdpa_cvq_info NetClientInfo Date: Thu, 4 Aug 2022 20:17:17 +0200 Message-Id: <20220804181722.701067-8-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Next patches will add a new info callback to restore NIC status through CVQ. Since only the CVQ vhost device is needed, create it with a new NetClientInfo. Signed-off-by: Eugenio Pérez --- v5: Create a new NetClientInfo instead of reusing the dataplane one. --- net/vhost-vdpa.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index ac1810723c..55e8a39a56 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -334,6 +334,16 @@ static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState *s, return true; } +static NetClientInfo net_vhost_vdpa_cvq_info = { + .type = NET_CLIENT_DRIVER_VHOST_VDPA, + .size = sizeof(VhostVDPAState), + .receive = vhost_vdpa_receive, + .cleanup = vhost_vdpa_cleanup, + .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, + .has_ufo = vhost_vdpa_has_ufo, + .check_peer_type = vhost_vdpa_check_peer_type, +}; + /** * Do not forward commands not supported by SVQ. Otherwise, the device could * accept it and qemu would not know how to update the device model. @@ -475,7 +485,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); } else { - nc = qemu_new_net_control_client(&net_vhost_vdpa_info, peer, + nc = qemu_new_net_control_client(&net_vhost_vdpa_cvq_info, peer, device, name); } snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); From patchwork Thu Aug 4 18:17:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45533C19F2A for ; Thu, 4 Aug 2022 18:27:45 +0000 (UTC) Received: from localhost ([::1]:45036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfZQ-0004me-9I for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:27:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQ1-00061z-Mt for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfPz-0001G4-Ow for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637079; 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=CxXOKA/Fw5lDrXBqL8eBVuEh61tj8tNUT0uOYD2kVDA=; b=R+UV9vLVHYis9DG47Jxi+IyhmeFghCm/u43l6E5BKs8GkNPhJiTNHv+G3jFpFUnZhYjRCj nV0abdQB1cHWOB4ftg4etOSNagmMoPD8BOmXD76lNRNWDqyr/8VLDaNS/k8pPM3fi6hDN1 kOcARDc8Xol06NRqGHz8GXACKhn7y0I= 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-13-l7Nhhv_EPVejjZGqJ4HB5A-1; Thu, 04 Aug 2022 14:17:55 -0400 X-MC-Unique: l7Nhhv_EPVejjZGqJ4HB5A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3BAF0280400A; Thu, 4 Aug 2022 18:17:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D33E492CA5; Thu, 4 Aug 2022 18:17:52 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 08/12] vdpa: Move command buffers map to start of net device Date: Thu, 4 Aug 2022 20:17:18 +0200 Message-Id: <20220804181722.701067-9-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As this series will reuse them to restore the device state at the end of a migration (or a device start), let's allocate only once at the device start so we don't duplicate their map and unmap. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 123 ++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 55e8a39a56..2c6a26cca0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -263,29 +263,20 @@ static size_t vhost_vdpa_net_cvq_cmd_page_len(void) return ROUND_UP(vhost_vdpa_net_cvq_cmd_len(), qemu_real_host_page_size()); } -/** Copy and map a guest buffer. */ -static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, - const struct iovec *out_data, - size_t out_num, size_t data_len, void *buf, - size_t *written, bool write) +/** Map CVQ buffer. */ +static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, void *buf, size_t size, + bool write) { DMAMap map = {}; 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 = iov_to_buf(out_data, out_num, 0, buf, data_len); map.translated_addr = (hwaddr)(uintptr_t)buf; - map.size = vhost_vdpa_net_cvq_cmd_page_len() - 1; + map.size = size - 1; map.perm = write ? IOMMU_RW : IOMMU_RO, r = vhost_iova_tree_map_alloc(v->iova_tree, &map); if (unlikely(r != IOVA_OK)) { error_report("Cannot map injected element"); - return false; + return r; } r = vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(), buf, @@ -294,50 +285,58 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, goto dma_map_err; } - return true; + return 0; dma_map_err: vhost_iova_tree_remove(v->iova_tree, &map); - return false; + return r; } -/** - * Copy the guest element into a dedicated buffer suitable to be sent to NIC - * - * @iov: [0] is the out buffer, [1] is the in one - */ -static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState *s, - VirtQueueElement *elem, - struct iovec *iov) +static int vhost_vdpa_net_cvq_prepare(NetClientState *nc) { - size_t in_copied; - bool ok; + VhostVDPAState *s; + int r; - iov[0].iov_base = s->cvq_cmd_out_buffer; - ok = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, elem->out_sg, elem->out_num, - vhost_vdpa_net_cvq_cmd_len(), iov[0].iov_base, - &iov[0].iov_len, false); - if (unlikely(!ok)) { - return false; + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + + s = DO_UPCAST(VhostVDPAState, nc, nc); + if (!s->vhost_vdpa.shadow_vqs_enabled) { + return 0; } - iov[1].iov_base = s->cvq_cmd_in_buffer; - ok = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, NULL, 0, - sizeof(virtio_net_ctrl_ack), iov[1].iov_base, - &in_copied, true); - if (unlikely(!ok)) { + r = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer, + vhost_vdpa_net_cvq_cmd_page_len(), false); + if (unlikely(r < 0)) { + return r; + } + + r = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer, + vhost_vdpa_net_cvq_cmd_page_len(), true); + if (unlikely(r < 0)) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); - return false; } - iov[1].iov_len = sizeof(virtio_net_ctrl_ack); - return true; + return r; +} + +static void vhost_vdpa_net_cvq_stop(NetClientState *nc) +{ + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + + if (s->vhost_vdpa.shadow_vqs_enabled) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer); + } } static NetClientInfo net_vhost_vdpa_cvq_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, + .prepare = vhost_vdpa_net_cvq_prepare, + .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, .has_ufo = vhost_vdpa_has_ufo, @@ -348,19 +347,17 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { * Do not forward commands not supported by SVQ. Otherwise, the device could * accept it and qemu would not know how to update the device model. */ -static bool vhost_vdpa_net_cvq_validate_cmd(const struct iovec *out, - size_t out_num) +static bool vhost_vdpa_net_cvq_validate_cmd(const void *out_buf, size_t len) { struct virtio_net_ctrl_hdr ctrl; - size_t n; - n = iov_to_buf(out, out_num, 0, &ctrl, sizeof(ctrl)); - if (unlikely(n < sizeof(ctrl))) { + if (unlikely(len < sizeof(ctrl))) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid legnth of out buffer %zu\n", __func__, n); + "%s: invalid legnth of out buffer %zu\n", __func__, len); return false; } + memcpy(&ctrl, out_buf, sizeof(ctrl)); switch (ctrl.class) { case VIRTIO_NET_CTRL_MAC: switch (ctrl.cmd) { @@ -392,10 +389,14 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, VhostVDPAState *s = opaque; size_t in_len, dev_written; virtio_net_ctrl_ack status = VIRTIO_NET_ERR; - /* out and in buffers sent to the device */ - struct iovec dev_buffers[2] = { - { .iov_base = s->cvq_cmd_out_buffer }, - { .iov_base = s->cvq_cmd_in_buffer }, + /* Out buffer sent to both the vdpa device and the device model */ + struct iovec out = { + .iov_base = s->cvq_cmd_out_buffer, + }; + /* In buffer sent to the device */ + const struct iovec dev_in = { + .iov_base = s->cvq_cmd_in_buffer, + .iov_len = sizeof(virtio_net_ctrl_ack), }; /* in buffer used for device model */ const struct iovec in = { @@ -405,17 +406,15 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, int r = -EINVAL; bool ok; - ok = vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); - if (unlikely(!ok)) { - goto out; - } - - ok = vhost_vdpa_net_cvq_validate_cmd(&dev_buffers[0], 1); + out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0, + s->cvq_cmd_out_buffer, + vhost_vdpa_net_cvq_cmd_len()); + ok = vhost_vdpa_net_cvq_validate_cmd(s->cvq_cmd_out_buffer, out.iov_len); if (unlikely(!ok)) { goto out; } - r = vhost_svq_add(svq, &dev_buffers[0], 1, &dev_buffers[1], 1, elem); + r = vhost_svq_add(svq, &out, 1, &dev_in, 1, elem); if (unlikely(r != 0)) { if (unlikely(r == -ENOSPC)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n", @@ -435,13 +434,13 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, goto out; } - memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status)); if (status != VIRTIO_NET_OK) { goto out; } status = VIRTIO_NET_ERR; - virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, 1); + virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, &out, 1); if (status != VIRTIO_NET_OK) { error_report("Bad CVQ processing in model"); } @@ -454,12 +453,6 @@ out: } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); g_free(elem); - if (dev_buffers[0].iov_base) { - vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[0].iov_base); - } - if (dev_buffers[1].iov_base) { - vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[1].iov_base); - } return r; } From patchwork Thu Aug 4 18:17:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24475C19F2A for ; Thu, 4 Aug 2022 18:40:21 +0000 (UTC) Received: from localhost ([::1]:33490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJflQ-0002Du-HJ for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:40:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQK-00063M-Jv for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46257) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQ8-0001Hc-Bv for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637082; 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=lcWJZ7r7rDSBaq7/c5DlnatQGIShGzZfiLVLuXOlGmI=; b=XyB3U3cRvZWyWDsuOKDelGiPbOIbSb0o4QDgirqzwAxIH+D60WNQ3AbbaQqVoJDKXLmUOR 6DIZwd6Nvr4SgOJLfcRBxiq39mK8XLF+dnot7UpWgpX8U7nlFOY7XIlUFA8mjf+qQRC8MR sxx9rTt/L/FXtjPujXYuOU9XID10LVA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-ms1bUeo4NxSNzCxDJcedvg-1; Thu, 04 Aug 2022 14:17:59 -0400 X-MC-Unique: ms1bUeo4NxSNzCxDJcedvg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 149BA2804007; Thu, 4 Aug 2022 18:17:59 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EF6A492C3B; Thu, 4 Aug 2022 18:17:55 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 09/12] vdpa: Extract vhost_vdpa_net_cvq_add from vhost_vdpa_net_handle_ctrl_avail Date: Thu, 4 Aug 2022 20:17:19 +0200 Message-Id: <20220804181722.701067-10-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" So we can reuse it to inject state messages. Signed-off-by: Eugenio Pérez --- v6: * Do not assume in buffer sent to the device is sizeof(virtio_net_ctrl_ack) v5: * Do not use an artificial !NULL VirtQueueElement * Use only out size instead of iovec dev_buffers for these functions. --- net/vhost-vdpa.c | 59 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2c6a26cca0..a3ca6af69f 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -331,6 +331,38 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc) } } +static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, + size_t in_len) +{ + /* Buffers for the device */ + const struct iovec out = { + .iov_base = s->cvq_cmd_out_buffer, + .iov_len = out_len, + }; + const struct iovec in = { + .iov_base = s->cvq_cmd_in_buffer, + .iov_len = sizeof(virtio_net_ctrl_ack), + }; + VhostShadowVirtqueue *svq = g_ptr_array_index(s->vhost_vdpa.shadow_vqs, 0); + int r; + + r = vhost_svq_add(svq, &out, 1, &in, 1, NULL); + if (unlikely(r != 0)) { + if (unlikely(r == -ENOSPC)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n", + __func__); + } + return r; + } + + /* + * We can poll here since we've had BQL from the time we sent the + * descriptor. Also, we need to take the answer before SVQ pulls by itself, + * when BQL is released + */ + return vhost_svq_poll(svq); +} + static NetClientInfo net_vhost_vdpa_cvq_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), @@ -387,23 +419,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, void *opaque) { VhostVDPAState *s = opaque; - size_t in_len, dev_written; + size_t in_len; virtio_net_ctrl_ack status = VIRTIO_NET_ERR; /* Out buffer sent to both the vdpa device and the device model */ struct iovec out = { .iov_base = s->cvq_cmd_out_buffer, }; - /* In buffer sent to the device */ - const struct iovec dev_in = { - .iov_base = s->cvq_cmd_in_buffer, - .iov_len = sizeof(virtio_net_ctrl_ack), - }; /* in buffer used for device model */ const struct iovec in = { .iov_base = &status, .iov_len = sizeof(status), }; - int r = -EINVAL; + ssize_t dev_written = -EINVAL; bool ok; out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0, @@ -414,21 +441,11 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, goto out; } - r = vhost_svq_add(svq, &out, 1, &dev_in, 1, elem); - if (unlikely(r != 0)) { - if (unlikely(r == -ENOSPC)) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n", - __func__); - } + dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status)); + if (unlikely(dev_written < 0)) { 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 itself, - * when BQL is released - */ - dev_written = vhost_svq_poll(svq); if (unlikely(dev_written < sizeof(status))) { error_report("Insufficient written data (%zu)", dev_written); goto out; @@ -436,7 +453,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status)); if (status != VIRTIO_NET_OK) { - goto out; + return VIRTIO_NET_ERR; } status = VIRTIO_NET_ERR; @@ -453,7 +470,7 @@ out: } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); g_free(elem); - return r; + return MAX(dev_written, 0); } static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { From patchwork Thu Aug 4 18:17:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1733C19F2A for ; Thu, 4 Aug 2022 18:32:44 +0000 (UTC) Received: from localhost ([::1]:53408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfeF-00037x-Os for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:32:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQK-00063N-KK for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQH-0001Ho-E8 for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637089; 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=B4ZrLRDwhepJQ17mV/bK0uaEPIPpjZawGXOV8Rt2wjM=; b=PgwidoqZmyT8/3wD5arUgZJZpTVDUWktev31fonEHZbG9oxVwmVFsD2ZLqVW9Pyxww+/WO FTFyFe6kR7qW6qaCj3GG3eSF+IKoOxehrX43dcXXEkW3dvVALiCjS71R5EoXgbETWgT21o +hzh6dTzzFtZcMu48b6c1MEHV6N3I/Q= 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-248-_VEJrczlPEuTWUzOsUI9eg-1; Thu, 04 Aug 2022 14:18:06 -0400 X-MC-Unique: _VEJrczlPEuTWUzOsUI9eg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9F1285A588; Thu, 4 Aug 2022 18:18:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 592DB492C3B; Thu, 4 Aug 2022 18:17:59 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 10/12] vhost_net: add NetClientState->load() callback Date: Thu, 4 Aug 2022 20:17:20 +0200 Message-Id: <20220804181722.701067-11-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It allows per-net client operations right after device's successful start. In particular, to load the device status. Vhost-vdpa net will use it to add the CVQ buffers to restore the device status. Signed-off-by: Eugenio Pérez --- v5: Rename start / load, naming it more specifically. --- 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 7aa1ec0974..356e682ab6 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -45,6 +45,7 @@ typedef struct NICConf { typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); typedef int (NetPrepare)(NetClientState *); +typedef int (NetLoad)(NetClientState *); typedef void (NetStop)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); @@ -74,6 +75,7 @@ typedef struct NetClientInfo { NetReceiveIOV *receive_iov; NetCanReceive *can_receive; NetPrepare *prepare; + NetLoad *load; NetStop *stop; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 10bca15446..6b83d5503f 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -281,6 +281,13 @@ static int vhost_net_start_one(struct vhost_net *net, } } } + + if (net->nc->info->load) { + r = net->nc->info->load(net->nc); + if (r < 0) { + goto fail; + } + } return 0; fail: file.fd = -1; From patchwork Thu Aug 4 18:17:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB8E7C19F2A for ; Thu, 4 Aug 2022 18:44:05 +0000 (UTC) Received: from localhost ([::1]:42046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfpE-0008HC-OE for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQK-00063J-JH for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQH-0001Hx-EC for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637090; 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=F3tadPuSrBqodjKYPy0q2EEHu/LjR7giDgt+48GrVZs=; b=Ba55iWEjCvH4+waGWL3DekxDBFHj4e06QtVLKR3Y6cFUw1fICWy+Qv8ZUCIQupVaGybABd 5fwIiHEmW5EiH7uyOh9uyPYxeMKHmRHja2ePxlGPdjvZAuNysZoT+U2rBNzElRHlONpmF2 vyMgEi39k2zl0d6AOLAYVj0jxOdh170= 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-418-SwyLWpHPOc6sMRdWVuEQ5g-1; Thu, 04 Aug 2022 14:18:06 -0400 X-MC-Unique: SwyLWpHPOc6sMRdWVuEQ5g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C2A685A585; Thu, 4 Aug 2022 18:18:06 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20D6A492C3B; Thu, 4 Aug 2022 18:18:02 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 11/12] vdpa: Add virtio-net mac address via CVQ at start Date: Thu, 4 Aug 2022 20:17:21 +0200 Message-Id: <20220804181722.701067-12-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is needed so the destination vdpa device see the same state a the guest set in the source. Signed-off-by: Eugenio Pérez --- v6: * Map and unmap command buffers at the start and end of device usage. v5: * Rename s/start/load/ * Use independent NetClientInfo to only add load callback on cvq. --- net/vhost-vdpa.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a3ca6af69f..7a50d46dae 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -363,11 +363,54 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, return vhost_svq_poll(svq); } +static int vhost_vdpa_net_load(NetClientState *nc) +{ + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_vdpa *v = &s->vhost_vdpa; + VirtIONet *n; + uint64_t features; + + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + + if (!v->shadow_vqs_enabled) { + return 0; + } + + n = VIRTIO_NET(v->dev->vdev); + features = v->dev->vdev->host_features; + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl = { + .class = VIRTIO_NET_CTRL_MAC, + .cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + char *cursor = s->cvq_cmd_out_buffer; + ssize_t dev_written; + virtio_net_ctrl_ack state; + + memcpy(cursor, &ctrl, sizeof(ctrl)); + cursor += sizeof(ctrl); + memcpy(cursor, n->mac, sizeof(n->mac)); + cursor += sizeof(n->mac); + + dev_written = vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + sizeof(n->mac), + sizeof(state)); + if (unlikely(dev_written < 0)) { + return dev_written; + } + + memcpy(&state, s->cvq_cmd_in_buffer, sizeof(state)); + return state == VIRTIO_NET_OK ? 0 : -1; + } + + return 0; +} + static NetClientInfo net_vhost_vdpa_cvq_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, .prepare = vhost_vdpa_net_cvq_prepare, + .load = vhost_vdpa_net_load, .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, From patchwork Thu Aug 4 18:17:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12936561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5117C3F6B0 for ; Thu, 4 Aug 2022 18:21:29 +0000 (UTC) Received: from localhost ([::1]:55618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJfTM-0000il-RP for qemu-devel@archiver.kernel.org; Thu, 04 Aug 2022 14:21:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQL-00063Z-GN for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58426) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJfQH-0001I1-KI for qemu-devel@nongnu.org; Thu, 04 Aug 2022 14:18:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659637092; 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=iu0w8mrva1JwCjiySaxBWZ1T7+21/ldqKukYwsnWfUM=; b=Hhe2ubSInCQnxSGwMImKVWP4ulD9BcBtk/BXm+mIjJuMwnNuKIIbAup5iV80ywb9AMp8v0 1A18jv7wmql40j2wb21L7JPvP2GqmlBw1A4g2nZKz0adsn+8RvZhpfHMVDG3aln5cpnTwV pYN+z+vG8JnOavyxVUa/j9+c0CYaPvE= 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-554-5QNCKa_fOcy1z64SYDxY2A-1; Thu, 04 Aug 2022 14:18:11 -0400 X-MC-Unique: 5QNCKa_fOcy1z64SYDxY2A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DA0F3803900; Thu, 4 Aug 2022 18:18:09 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9310B492C3B; Thu, 4 Aug 2022 18:18:06 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , "Gonglei (Arei)" , Cornelia Huck , Liuxiangdong , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Laurent Vivier , Eli Cohen , Zhu Lingshan , Cindy Lu , Stefan Hajnoczi , Parav Pandit , Paolo Bonzini , Harpreet Singh Anand , Eric Blake , Markus Armbruster Subject: [PATCH v6 12/12] vdpa: Delete CVQ migration blocker Date: Thu, 4 Aug 2022 20:17:22 +0200 Message-Id: <20220804181722.701067-13-eperezma@redhat.com> In-Reply-To: <20220804181722.701067-1-eperezma@redhat.com> References: <20220804181722.701067-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We can restore the device state in the destination via CVQ now. Remove the migration blocker. Signed-off-by: Eugenio Pérez --- 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 7e28d2f674..4b0cfc0f56 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1033,13 +1033,6 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) return true; } - if (v->migration_blocker) { - int r = migrate_add_blocker(v->migration_blocker, &err); - if (unlikely(r < 0)) { - return false; - } - } - for (i = 0; i < v->shadow_vqs->len; ++i) { VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); @@ -1082,10 +1075,6 @@ err: vhost_svq_stop(svq); } - if (v->migration_blocker) { - migrate_del_blocker(v->migration_blocker); - } - return false; } @@ -1105,9 +1094,6 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev) } } - if (v->migration_blocker) { - migrate_del_blocker(v->migration_blocker); - } return true; } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7a50d46dae..b70fdb49f5 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -558,8 +558,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; - error_setg(&s->vhost_vdpa.migration_blocker, - "Migration disabled: vhost-vdpa uses CVQ."); } ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs); if (ret) {