From nobody Sun Feb 8 14:59:27 2026 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=1657133251; cv=none; d=zohomail.com; s=zohoarc; b=MEtJXEy4YILWJRmlOF1BpY4ijZPvJihvgrns+QKhXQakPno3lV/kZH/2Rbp+24SEpVV9Wtk5cIMMhh5Ef9qkcyIB90dXPz3f9TuDbgWzXOumeCH2X62A7MHNlt0DskywzIgnIsf1zSakuRuwt90HBOX8AVoSCZtAAmdgn2G4wRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133251; 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=uJ6lQQL0q6ZPTMPIyDCx2xMhQaa98jnn++F4jbR5p5w=; b=AESxPn2FBVecnnG89RWOWuR6nOMnmeIL89+ArQM/tD3RDhy/NEaFmSWg7uadOfN0uO+K3gy1kUu1pR8b1ZFveyODKBmClN0U/Gd4nMAj+iGpDbCqTNJ8WcKpxLYaPOhILaJzZOTDws08KM16XLhsfzmQUa20BxjukKMg1NEVR2M= 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 1657133251153365.85601818889995; Wed, 6 Jul 2022 11:47:31 -0700 (PDT) Received: from localhost ([::1]:53160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A3e-000391-2e for importer@patchew.org; Wed, 06 Jul 2022 14:47:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99wy-00055o-I7 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99wq-0000lo-1n for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-KAAMUoRuPbCZQrUbJhFP3Q-1; Wed, 06 Jul 2022 14:40:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F006801231; Wed, 6 Jul 2022 18:40:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCAC81415116; Wed, 6 Jul 2022 18:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132824; 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=uJ6lQQL0q6ZPTMPIyDCx2xMhQaa98jnn++F4jbR5p5w=; b=XMt6UiDoaqhjb5H6MOHh0uw7ZOwxfSBsJZdrH94JUk80NgOLI2PdF185ZecsR8tFcTPggq 6JSQyd5nVJCCQYk9hzzm5PJGiqGC3Fat2P3II9MV1iFZBt3g54SO1slJtVf7qpl4kZL2xn GH7pCHwfRgRV5LVbs9/+rcVhbBRN5ow= X-MC-Unique: KAAMUoRuPbCZQrUbJhFP3Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 01/23] vhost: Return earlier if used buffers overrun Date: Wed, 6 Jul 2022 20:39:46 +0200 Message-Id: <20220706184008.1649478-2-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657133252846100001 Previous function misses the just picked avail buffer from the queue. This way keeps blocking the used queue forever, but is cleaner to check before calling to vhost_svq_get_buf. Fixes: 100890f7cad50 ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 56c96ebd13..9280285435 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -405,19 +405,21 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, vhost_svq_disable_notification(svq); while (true) { uint32_t len; - g_autofree VirtQueueElement *elem =3D vhost_svq_get_buf(svq, &= len); - if (!elem) { - break; - } + g_autofree VirtQueueElement *elem =3D NULL; =20 if (unlikely(i >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "More than %u used buffers obtained in a %u size = SVQ", i, svq->vring.num); - virtqueue_fill(vq, elem, len, i); - virtqueue_flush(vq, i); + virtqueue_flush(vq, svq->vring.num); return; } + + elem =3D vhost_svq_get_buf(svq, &len); + if (!elem) { + break; + } + virtqueue_fill(vq, elem, len, i++); } =20 --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133467; cv=none; d=zohomail.com; s=zohoarc; b=Yy+MaxpgLOX56yAQpJKslyD8YTo0Cav0yIodO9fPCn9fmvdKM0yRpT4137DOM3kLevxVIZ8r2UamkMZ+B/wDReJ162wdoLknkHPTjhtYv+cIkedLC89D+ZhwnWC42oNwVulO0ZrddzS1LcXDUrJbT75gvl0F/EubDlSBNvuXfzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133467; 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=uSWdFug0bHugEo57qqqEYlOs0IeaPAPFa6rk2TY2Lhc=; b=SrXR88PYZmZhBhZkLcMHWnGUNwjWXLc7RX6cJ+Wdjz66XbLRKTlqchQTbPavbFmxyYRk/xCUcU30GW6EAm/KZC4UkKMTCxGPXt2g6EAqRKhvGRttcvOfrMB8TEJ46ugJde7dvANJ2qv26eqwhsJ6s0QjZhk2mjVttKOOwb7NLCI= 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 16571334672868.210829547926778; Wed, 6 Jul 2022 11:51:07 -0700 (PDT) Received: from localhost ([::1]:33316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A78-0000Lg-94 for importer@patchew.org; Wed, 06 Jul 2022 14:51:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x2-00055v-7T for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25149) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99wp-0000jf-VT for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-CKG3XU3DPAmTjeE0-DOtJw-1; Wed, 06 Jul 2022 14:40:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22D3A101A58D; Wed, 6 Jul 2022 18:40:19 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 906B41415116; Wed, 6 Jul 2022 18:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132820; 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=uSWdFug0bHugEo57qqqEYlOs0IeaPAPFa6rk2TY2Lhc=; b=Kwm0fwA5qISkUrHAooBw7SKqcqq2HFLm9nCLiBE7fxcrm2tNnXRPkJfj3e4H24oRAHSkhW yKQIWXxA8UgEvJQ/d0lMERQDAdLHJvm2a9gNWc9DV9pZEMCr0Vs2EO0DkMbyMLx8/5XDKA lR09iEESdCpyODlUvmUM8nffbWp9IZc= X-MC-Unique: CKG3XU3DPAmTjeE0-DOtJw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 02/23] vhost: move descriptor translation to vhost_svq_vring_write_descs Date: Wed, 6 Jul 2022 20:39:47 +0200 Message-Id: <20220706184008.1649478-3-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1657133468150100001 It's done for both in and out descriptors so it's better placed here. Acked-by: Jason Wang Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 39 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 9280285435..2939f4a243 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -122,17 +122,35 @@ static bool vhost_svq_translate_addr(const VhostShado= wVirtqueue *svq, return true; } =20 -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, - const struct iovec *iovec, size_t num, - bool more_descs, bool write) +/** + * Write descriptors to SVQ vring + * + * @svq: The shadow virtqueue + * @sg: Cache for hwaddr + * @iovec: The iovec from the guest + * @num: iovec length + * @more_descs: True if more descriptors come in the chain + * @write: True if they are writeable descriptors + * + * Return true if success, false otherwise and print error. + */ +static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr = *sg, + const struct iovec *iovec, size_t = num, + bool more_descs, bool write) { uint16_t i =3D svq->free_head, last =3D svq->free_head; unsigned n; uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs =3D svq->vring.desc; + bool ok; =20 if (num =3D=3D 0) { - return; + return true; + } + + ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; } =20 for (n =3D 0; n < num; n++) { @@ -150,6 +168,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, hwaddr *sg, } =20 svq->free_head =3D le16_to_cpu(svq->desc_next[last]); + return true; } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -169,21 +188,19 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, return false; } =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, + elem->in_num > 0, false); if (unlikely(!ok)) { return false; } - vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, - elem->in_num > 0, false); - =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, + true); if (unlikely(!ok)) { + /* TODO unwind out_sg */ return false; } =20 - vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); - /* * Put the entry in the available array (but don't update avail->idx u= ntil * they do sync). --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133855; cv=none; d=zohomail.com; s=zohoarc; b=csKtSh++m1S/Lwge1InzuJpHv9Tig71Hak6TnKIFhuxivVsOC+DR5VQdfpwSBMuPgXMsQcALxxbZtQprUaFE5HItzaCGKcAH0atm/Z/q0n/w23q9OlI6RiSsCaibbxOiG20PTAGJZEoiVZVVJ88snMD9xeenDrFvz36pPBMTDUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133855; 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=Mro7mQDdAvykXc9MUpTOitbSw+VVbx2upRRODnnToII=; b=GRGOknKlqV6RGDDz3HS0zdU8BBVn9lHfdguqRizJWWB6pSQhFBp5rsOwOMgHgBBSVpncewEKM5x8TNIq7ymfJr1Bl0ird95PO76+izUR+Fk6G82Dun4plFxkoHUDnYNuSkWGgMA8UWsV1dyRu/Xq132C3oESwPdQt23BHIORTT4= 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 1657133855275557.6718528814836; Wed, 6 Jul 2022 11:57:35 -0700 (PDT) Received: from localhost ([::1]:49212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9ADN-0003PZ-IG for importer@patchew.org; Wed, 06 Jul 2022 14:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xG-0005Kv-AX for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x4-0000pW-A9 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:53 -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-278-yPO70intPJeUIsx7w-RDyg-1; Wed, 06 Jul 2022 14:40:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF2C7185A7BA; Wed, 6 Jul 2022 18:40:21 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D3581415116; Wed, 6 Jul 2022 18:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132838; 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=Mro7mQDdAvykXc9MUpTOitbSw+VVbx2upRRODnnToII=; b=ciVoow3Rb2ezG1k7Z0stIeJZolb3qYKMznV6R01s2tNOE0dsEylyMlacQGlJBYzwKDZsou AQz0O668FyNedCjXUOcp3m9HyCBjGB4PaegVWpg20mA8q2PI2ezflk/tNppIJi9lC3H32V bHH4PY1lO/h05zmR0JsGZNPmUjyqzTs= X-MC-Unique: yPO70intPJeUIsx7w-RDyg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 03/23] vdpa: delay set_vring_ready after DRIVER_OK Date: Wed, 6 Jul 2022 20:39:48 +0200 Message-Id: <20220706184008.1649478-4-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133856582100001 To restore the device in the destination of a live migration we send the commands through control virtqueue. For a device to read CVQ it must have received DRIVER_OK status bit. However this open a window where the device could start receiving packets in rx queue 0 before it receive the RSS configuration. To avoid that, we will not send vring_enable until all configuration is used by the device. As a first step, reverse the DRIVER_OK and SET_VRING_ENABLE steps. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 66f054a12c..2ee8009594 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -728,13 +728,18 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *= dev, int idx) return idx; } =20 +/** + * Set ready all vring of the device + * + * @dev: Vhost device + */ static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) { int i; trace_vhost_vdpa_set_vring_ready(dev); - for (i =3D 0; i < dev->nvqs; ++i) { + for (i =3D 0; i < dev->vq_index_end; ++i) { struct vhost_vring_state state =3D { - .index =3D dev->vq_index + i, + .index =3D i, .num =3D 1, }; vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state); @@ -1097,7 +1102,6 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) if (unlikely(!ok)) { return -1; } - vhost_vdpa_set_vring_ready(dev); } else { ok =3D vhost_vdpa_svqs_stop(dev); if (unlikely(!ok)) { @@ -1111,16 +1115,22 @@ static int vhost_vdpa_dev_start(struct vhost_dev *d= ev, bool started) } =20 if (started) { + int r; + memory_listener_register(&v->listener, &address_space_memory); - return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + r =3D vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + if (unlikely(r)) { + return r; + } + vhost_vdpa_set_vring_ready(dev); } else { vhost_vdpa_reset_device(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); memory_listener_unregister(&v->listener); - - return 0; } + + return 0; } =20 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133084; cv=none; d=zohomail.com; s=zohoarc; b=hMn+WPDbeu4LuUjlYsBM0A2XTJYIx5awD5HXeOTlNfwEOt24PktPNts929X63sNXL0zG2CtIJHMHUEkmLso5naj/Qtq/OqevOMaqXwULntg68pyfMROSnNo6Zn4A6HLPr6YXijQNzHwC7xaDRXZPQR9Jms0zfoZYFutF2q/HlDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133084; 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=NY2G+SGnz32QRth35C6CWxybrvutzglBHoDq5RtZ7Rc=; b=JRXUazAPvj5aEPUPswBCkyJxIZ3M1d9VTJ26qTsUvu4ioRntJcttU90qd27UuELya2GZ5Bo5xFb6cpCbgir2Oeay6U2VGQJU2gYmPvpGzbzrg09H1DoAI2XU4StVHX1rtTwrFAHMRW9aIIGfGwsjM9kKDoRY9JlxyzpGIkdh7BE= 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 1657133084423787.2121056757352; Wed, 6 Jul 2022 11:44:44 -0700 (PDT) Received: from localhost ([::1]:48366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A0x-0008Ei-AE for importer@patchew.org; Wed, 06 Jul 2022 14:44:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x2-00056F-3D for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99ws-0000nF-1H for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:37 -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-98-8mrE4SPdOjmp_Pmu7fvGEg-1; Wed, 06 Jul 2022 14:40:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE2CD294EDEC; Wed, 6 Jul 2022 18:40:24 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ACA71410F3C; Wed, 6 Jul 2022 18:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132826; 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=NY2G+SGnz32QRth35C6CWxybrvutzglBHoDq5RtZ7Rc=; b=h739M1DiprE0bTuGmkqAeQIdX3P5OYxvz37nylf9YhLYqpl8vHHs6VL2cInr+vqi+GmBB/ z4O3xeJurITrny9r2HMpD/znur0mkdZ3NTY5YyKGayhyjq/7/mKjFL+LJGxHoXcXWZSUqR 7ghArEnDdqf4eLDjNLWVsIsYVOjH+uU= X-MC-Unique: 8mrE4SPdOjmp_Pmu7fvGEg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 04/23] vhost: Get vring base from vq, not svq Date: Wed, 6 Jul 2022 20:39:49 +0200 Message-Id: <20220706184008.1649478-5-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133086015100001 The used idx used to match with this, but it will not match from the moment we introduce svq_inject. Rewind all the descriptors not used by vdpa device and get the vq state properly. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 1 + hw/virtio/vhost-vdpa.c | 7 +++---- hw/virtio/virtio.c | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index db1c0ddf6b..4b51ab9d06 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -302,6 +302,7 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, i= nt n); hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); +unsigned int virtio_queue_get_in_use(const VirtQueue *vq); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx); void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 2ee8009594..de76128030 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1189,12 +1189,10 @@ static int vhost_vdpa_get_vring_base(struct vhost_d= ev *dev, struct vhost_vring_state *ring) { struct vhost_vdpa *v =3D dev->opaque; - int vdpa_idx =3D ring->index - dev->vq_index; int ret; =20 if (v->shadow_vqs_enabled) { - VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, vdp= a_idx); - + const VirtQueue *vq =3D virtio_get_queue(dev->vdev, ring->index); /* * Setting base as last used idx, so destination will see as avail= able * all the entries that the device did not use, including the in-f= light @@ -1203,7 +1201,8 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev= *dev, * TODO: This is ok for networking, but other kinds of devices mig= ht * have problems with these retransmissions. */ - ring->num =3D svq->last_used_idx; + ring->num =3D virtio_queue_get_last_avail_idx(dev->vdev, ring->ind= ex) - + virtio_queue_get_in_use(vq); return 0; } =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5d607aeaa0..e02656f7a2 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3420,6 +3420,11 @@ unsigned int virtio_queue_get_last_avail_idx(VirtIOD= evice *vdev, int n) } } =20 +unsigned int virtio_queue_get_in_use(const VirtQueue *vq) +{ + return vq->inuse; +} + static void virtio_queue_packed_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx) { --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133182; cv=none; d=zohomail.com; s=zohoarc; b=kiYjlspeOGDOfEbRRwhC7IFBlgE35WkNoWnmHAjZosrW4te/npIc1hIkA9W9VJy9oWxKHtp7LrSWwjznSpHGcnDgey98F4GLC5l5qchLQPdY/8+q9h8qxOO7s/CO0cYl61v8ze0nbCG2sohc28IuuMJCO7wSBLiPw18UBbnUW+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133182; 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=cAyt1nJZiM/sAoSUDasg3aQN7DmNjuZNX44aTSHb5+M=; b=fa6ovE/jZyv9dfV8B50vV7jfhgV29HDu8sEdCEeiGKWmdnMXZjg0gvOELXXJRE2//TAelgboyOr80f/1lTBKfwa1YByA0njnDqlpHsW18M1fR3RKYsRyJRsv8MUbvj+AU9aSCs3fHN3Sjg6o/rdrLj9GXk8Cpb/a5Avv58GSITo= 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 1657133182913357.9727761819953; Wed, 6 Jul 2022 11:46:22 -0700 (PDT) Received: from localhost ([::1]:50304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A2X-000172-93 for importer@patchew.org; Wed, 06 Jul 2022 14:46:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x1-00056a-Pn for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99wy-0000ok-1c for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:39 -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-39-64qFTm0RP3m1Vxrm721_Lg-1; Wed, 06 Jul 2022 14:40:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 903B2804196; Wed, 6 Jul 2022 18:40:27 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C89A1415116; Wed, 6 Jul 2022 18:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132831; 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=cAyt1nJZiM/sAoSUDasg3aQN7DmNjuZNX44aTSHb5+M=; b=DwpYzhBOZ0YE2drVkDDRj+PVvH/fH/Kzka2kvl4PAN+VKXIHkSfX67Xz6v2CyAOjZUixtj JiAesnX/Qm4Lzg/NzMuTDki+qEgsKptqJlbzwuXBhSWO47DYzQkrwC/dKNgefFUL5SxELy zlj2cVBThgFQxwuW7GSZG7Vp0hlMS2Y= X-MC-Unique: 64qFTm0RP3m1Vxrm721_Lg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 05/23] vhost: Add ShadowVirtQueueStart operation Date: Wed, 6 Jul 2022 20:39:50 +0200 Message-Id: <20220706184008.1649478-6-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657133184572100001 It allows to run commands at SVQ start. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 18 +++++++++++++++++- hw/virtio/vhost-shadow-virtqueue.c | 8 +++++++- hw/virtio/vhost-vdpa.c | 17 ++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c132c994e9..91c31715d9 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,14 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/vhost-iova-tree.h" =20 +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; +typedef int (*ShadowVirtQueueStart)(VhostShadowVirtqueue *svq, + void *opaque); + +typedef struct VhostShadowVirtqueueOps { + ShadowVirtQueueStart start; +} VhostShadowVirtqueueOps; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -59,6 +67,12 @@ typedef struct VhostShadowVirtqueue { */ uint16_t *desc_next; =20 + /* Caller callbacks */ + const VhostShadowVirtqueueOps *ops; + + /* Caller callbacks opaque */ + void *ops_opaque; + /* Next head to expose to the device */ uint16_t shadow_avail_idx; =20 @@ -85,7 +99,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODev= ice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque); =20 void vhost_svq_free(gpointer vq); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 2939f4a243..be64e0b85c 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -626,12 +626,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * shadow methods and file descriptors. * * @iova_tree: Tree to perform descriptors translations + * @ops: SVQ owner callbacks + * @ops_opaque: ops opaque pointer * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; @@ -653,6 +657,8 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree) event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree =3D iova_tree; + svq->ops =3D ops; + svq->ops_opaque =3D ops_opaque; return g_steal_pointer(&svq); =20 err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index de76128030..69cfaf05d6 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -418,7 +418,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree= ); + g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree= , NULL, + NULL); =20 if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); @@ -1122,6 +1123,20 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) if (unlikely(r)) { return r; } + + if (v->shadow_vqs_enabled) { + for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_= vqs, + i); + if (svq->ops) { + r =3D svq->ops->start(svq, svq->ops_opaque); + if (unlikely(r)) { + return r; + } + } + } + } + vhost_vdpa_set_vring_ready(dev); } else { vhost_vdpa_reset_device(dev); --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133398; cv=none; d=zohomail.com; s=zohoarc; b=HBeT1AUU2nUePND6v/cNFelyEDjoIEz7Ops8cU1wwaTzPtLI6HuR95G70rCKNm5iH/aKqj7EUtqd+IhRdLJzVX6qNmSs0SxobUXKvvXtglH3xhnC8So0gzPMbnH44S+p1GPbysCH4UZdS2e8o0jBLsk4xfiisnw+3E8jJhutCWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133398; 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=BfA/rvw4pPKDoIqS9yC//2a8Afnz0cn7wf8quOrELCY=; b=V0c9Q6Kvp0F8GrWxDfe1HCOJyDtyZDZu2eLcXrcEuzZ27VbjYNA31WlZ9qviLV6P0t7wjQov4fIuDQsNBdnc3gFqZq8q7bPoOe3/BUvPEVyNJHlS+BLYYN+GGE/uaGj3kRWt84X6n2kOnn6ZSzgL9who+Lqz2sr81E6Ch+TXp/M= 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 16571333986392.282875318485935; Wed, 6 Jul 2022 11:49:58 -0700 (PDT) Received: from localhost ([::1]:58844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A60-0006xK-FG for importer@patchew.org; Wed, 06 Jul 2022 14:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x6-000587-Hk for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x4-0000pl-Kv for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:44 -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-572-A_HImYdHO0OtPA7WudJZKw-1; Wed, 06 Jul 2022 14:40:30 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6311C18E5346; Wed, 6 Jul 2022 18:40:30 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D28941415116; Wed, 6 Jul 2022 18:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132840; 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=BfA/rvw4pPKDoIqS9yC//2a8Afnz0cn7wf8quOrELCY=; b=i3axW+2XnYR5GPXKKefo7mMVsjGGHEeGy0MmYoWrleIjRd2jFxj885D4DRhL7ybDOcmJ+r WSkNn542koW4t3PlQzsH0yZAg7obfg8F1y5iMSXm2jJbH+La8jECdbx25PB0ERto++QX71 QeNOlZJHag64A8y1iVaxcsnxIpxljPY= X-MC-Unique: A_HImYdHO0OtPA7WudJZKw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 06/23] virtio-net: Expose ctrl virtqueue logic Date: Wed, 6 Jul 2022 20:39:51 +0200 Message-Id: <20220706184008.1649478-7-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133399846100001 This allows external vhost-net devices to modify the state of the VirtIO device model once vhost-vdpa device has acknowledge the control commands. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio-net.h | 4 ++ hw/net/virtio-net.c | 84 ++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index eb87032627..42caea0d1d 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -218,6 +218,10 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; }; =20 +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7ad948ee7c..53bb92c9f1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1434,57 +1434,71 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, return VIRTIO_NET_OK; } =20 -static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num) { VirtIONet *n =3D VIRTIO_NET(vdev); struct virtio_net_ctrl_hdr ctrl; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - VirtQueueElement *elem; size_t s; struct iovec *iov, *iov2; - unsigned int iov_cnt; + + if (iov_size(in_sg, in_num) < sizeof(status) || + iov_size(out_sg, out_num) < sizeof(ctrl)) { + virtio_error(vdev, "virtio-net ctrl missing headers"); + return 0; + } + + iov2 =3D iov =3D g_memdup2(out_sg, sizeof(struct iovec) * out_num); + s =3D iov_to_buf(iov, out_num, 0, &ctrl, sizeof(ctrl)); + iov_discard_front(&iov, &out_num, sizeof(ctrl)); + if (s !=3D sizeof(ctrl)) { + status =3D VIRTIO_NET_ERR; + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { + status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { + status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { + status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { + status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { + status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num); + } + + s =3D iov_from_buf(in_sg, in_num, 0, &status, sizeof(status)); + assert(s =3D=3D sizeof(status)); + + g_free(iov2); + return sizeof(status); +} + +static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; =20 for (;;) { + size_t written; elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; } - if (iov_size(elem->in_sg, elem->in_num) < sizeof(status) || - iov_size(elem->out_sg, elem->out_num) < sizeof(ctrl)) { - virtio_error(vdev, "virtio-net ctrl missing headers"); + + written =3D virtio_net_handle_ctrl_iov(vdev, elem->in_sg, elem->in= _num, + elem->out_sg, elem->out_num); + if (written > 0) { + virtqueue_push(vq, elem, written); + virtio_notify(vdev, vq); + g_free(elem); + } else { virtqueue_detach_element(vq, elem, 0); g_free(elem); break; } - - iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup2(elem->out_sg, - sizeof(struct iovec) * elem->out_num); - s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); - iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); - if (s !=3D sizeof(ctrl)) { - status =3D VIRTIO_NET_ERR; - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { - status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt= ); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { - status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { - status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_= cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { - status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cn= t); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { - status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { - status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cn= t); - } - - s =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(s= tatus)); - assert(s =3D=3D sizeof(status)); - - virtqueue_push(vq, elem, sizeof(status)); - virtio_notify(vdev, vq); - g_free(iov2); - g_free(elem); } } =20 --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133646; cv=none; d=zohomail.com; s=zohoarc; b=UcNmqo2RrX5lrcK4wkd8cQkznluLhyN8kHG8qNmbD+HE/uyAytEwQYZUrcDSVBw/zqkGwUMzatL+mPuLwTKiTvmPUxaGXfeeB/j0XxG8RnFfqgJ3lWVdfDjYmgmH6mG1hH4ODXxQK7BEOVONZBcD2U+0ryVRlUnIdv1H7yHstSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133646; 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=/sMVu1m7Wy8pn+FQex/40CAA3MHvmjXr0afNU11K+OQ=; b=Kq5/ghD3TwJgptzOuSxW07SHrJSGXzXFbJrjAgAe9PELWX9rte29AxvAUNKX5X7xCBqSQSf/P8FUgvrPZwcBLRyCzJjaPsGeSiGoaPglED5UDMll4qWvTBo7+xbvhNeMufFetCNTjLz7g9hDtP5GyO0AFwM0CUTD4f6DHKCCT+s= 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 1657133646454522.0041280304098; Wed, 6 Jul 2022 11:54:06 -0700 (PDT) Received: from localhost ([::1]:41604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AA1-00063C-5i for importer@patchew.org; Wed, 06 Jul 2022 14:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x4-00057z-LR for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20325) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x1-0000pJ-VB for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:42 -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-lWVdD7WzMueN-B90MQyghA-1; Wed, 06 Jul 2022 14:40:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31592185A7A4; Wed, 6 Jul 2022 18:40:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3E501415116; Wed, 6 Jul 2022 18:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132836; 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=/sMVu1m7Wy8pn+FQex/40CAA3MHvmjXr0afNU11K+OQ=; b=AkVEogpmhJAukGN/6RBIQzMwsuSZT7UZ+TzYdduqEqA7msWfb6KGlKnP8XB9awZb9gvfg6 bUN+Hl5lwcDbeUV7rIqaGIhKwTh/RXqU6a/D2IiqMl+5bAxxksMYS/69k/jhQ9nhke3TTQ xh/w2nACbZAZ7JkieejU7xG3vzL+LnI= X-MC-Unique: lWVdD7WzMueN-B90MQyghA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 07/23] vhost: add vhost_svq_push_elem Date: Wed, 6 Jul 2022 20:39:52 +0200 Message-Id: <20220706184008.1649478-8-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657133648563100001 This function allows external SVQ users to return guest's available buffers. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 91c31715d9..0fbdd69153 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -88,6 +88,8 @@ typedef struct VhostShadowVirtqueue { =20 bool vhost_svq_valid_features(uint64_t features, Error **errp); =20 +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index be64e0b85c..2fc5789b73 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -410,6 +410,22 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); } =20 +/** + * Push an element to SVQ, returning it to the guest. + */ +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len) +{ + virtqueue_push(svq->vq, elem, len); + if (svq->next_guest_avail_elem) { + /* + * Avail ring was full when vhost_svq_flush was called, so it's a + * good moment to make more descriptors available if possible. + */ + vhost_handle_guest_kick(svq); + } +} + static void vhost_svq_flush(VhostShadowVirtqueue *svq, bool check_for_avail_queue) { --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133209; cv=none; d=zohomail.com; s=zohoarc; b=lO/GTfWP+e3thoVSCnTQVdCLqpIp+8yXNDTzl2UlO0lyHGufNxQqmi54HRLkPSABRTR6aYzMIYo6FHjj3ber/NnJNH9CttcsD40MUg8MDfCz1/VmMSf+R0N3sT4i2L0t7HPMh+IvXLrzvVVsSxRmaHbSh5naR1SKxiAdOZJlaSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133209; 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=8v0tmzPobnEi4Wx4h6QV+k89ZEL0PYdAdrE9PK3ftP4=; b=TpRGYRZKsjK9hVx+FG9qSRIuunijB2ZkdGGEUOt4wmOWg3io2bBmepiif2SDbpjclmA12RoVkQZhajaqVEMfDN2EVJSNSrfOYTLn2GiIhhuAND5j3pIiY4b9cEiRXQb8qFzMnBO7GwaKKd13IFfu8PJl9ObjfsKZthUOA7sp1ms= 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 1657133209447226.5290609528679; Wed, 6 Jul 2022 11:46:49 -0700 (PDT) Received: from localhost ([::1]:50912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A2x-0001WQ-NI for importer@patchew.org; Wed, 06 Jul 2022 14:46:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xA-0005DR-6s for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99x4-0000pv-9P for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:47 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-FpkiOjocMwyFlupx64TZmg-1; Wed, 06 Jul 2022 14:40:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4956805B9A; Wed, 6 Jul 2022 18:40:36 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 737B71415116; Wed, 6 Jul 2022 18:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132840; 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=8v0tmzPobnEi4Wx4h6QV+k89ZEL0PYdAdrE9PK3ftP4=; b=O35PJlnBpUj60uDRu2wJPc2l+CW3Kqd5z3ahNEXFe5Um9gDMb8J3fEAkyzZPDDNQdaZ28V BgVEUInKhulq9YCdgFEQrBl1QQl7LanUKWuG4C3LcB3lGbCbTYA4ABa+dDKQKipAekyT5L nzA3rvYdtr3b0OBR2DCSNgjftPHNLRI= X-MC-Unique: FpkiOjocMwyFlupx64TZmg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 08/23] vhost: Decouple vhost_svq_add_split from VirtQueueElement Date: Wed, 6 Jul 2022 20:39:53 +0200 Message-Id: <20220706184008.1649478-9-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657133210642100001 VirtQueueElement comes from the guest, but we're heading SVQ to be able to inject element without the guest's knowledge. To do so, make this accept sg buffers directly, instead of using VirtQueueElement. Add vhost_svq_add_element to maintain element convenience Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 38 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 2fc5789b73..46d3c1d74f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -172,30 +172,32 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, unsigned *head) + const struct iovec *out_sg, size_t out_num, + const struct iovec *in_sg, size_t in_num, + unsigned *head) { unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; - g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(elem->out_num, elem->in_n= um)); + g_autofree hwaddr *sgs =3D NULL; =20 *head =3D svq->free_head; =20 /* We need some descriptors here */ - if (unlikely(!elem->out_num && !elem->in_num)) { + if (unlikely(!out_num && !in_num)) { qemu_log_mask(LOG_GUEST_ERROR, "Guest provided element with no descriptors"); return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, - elem->in_num > 0, false); + sgs =3D g_new(hwaddr, MAX(out_num, in_num)); + ok =3D vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num >= 0, + false); if (unlikely(!ok)) { return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, - true); + ok =3D vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, tru= e); if (unlikely(!ok)) { /* TODO unwind out_sg */ return false; @@ -223,10 +225,13 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, * takes ownership of the element: In case of failure, it is free and the = SVQ * is considered broken. */ -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *o= ut_sg, + size_t out_num, const struct iovec *in_sg, + size_t in_num, VirtQueueElement *elem) { unsigned qemu_head; - bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + bool ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, + &qemu_head); if (unlikely(!ok)) { g_free(elem); return false; @@ -250,6 +255,18 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) event_notifier_set(&svq->hdev_kick); } =20 +static bool vhost_svq_add_element(VhostShadowVirtqueue *svq, + VirtQueueElement *elem) +{ + bool ok =3D vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_s= g, + elem->in_num, elem); + if (ok) { + vhost_svq_kick(svq); + } + + return ok; +} + /** * Forward available buffers. * @@ -302,12 +319,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) return; } =20 - ok =3D vhost_svq_add(svq, elem); + ok =3D vhost_svq_add_element(svq, g_steal_pointer(&elem)); if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; } - vhost_svq_kick(svq); } =20 virtio_queue_set_notification(svq->vq, true); --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133586; cv=none; d=zohomail.com; s=zohoarc; b=e3+tjm8tDbdnr/sls0XsV6TmH62oPU9Cpfk8pSXMxrwqgmOMq+mSBZWdBIe21DFqarJZpC8UmTObKViagizG2tcuuZ2d3uInJqU47nXo7Lnr6q338ihsMFCqMeE/NNqEIQdrZxGtCg0xPbNXjW8PT7MTPD4pp9S4SbG3SPB6Jtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133586; 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=SqUrno67AFLGn35GLz5YA8v1mqjELXgVV+L32CRV+uY=; b=Ob3rPIBwXxx+TwMvQonO82rIckZlGQdV4PnkATyTu+1sfGfvlkyv1Hp+dqZ2aKNWhtUfh2dnJCPec2afhFUFl5wfhcySeawjH5m0diL4mMjiq1iB9G4vYo1tjDNIvdJr6Fp/2EBQUTnLxWsIfV0RweWOxQYEp9o/fSu748LRyVE= 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 1657133586615434.3167643953125; Wed, 6 Jul 2022 11:53:06 -0700 (PDT) Received: from localhost ([::1]:39050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A93-0004Je-9H for importer@patchew.org; Wed, 06 Jul 2022 14:53:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xO-0005Q8-LY for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47118) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xB-0000qU-CU for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:00 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-68l15BzuMpCHJNkc8uLr_Q-1; Wed, 06 Jul 2022 14:40:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA874833961; Wed, 6 Jul 2022 18:40:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1221C1415116; Wed, 6 Jul 2022 18:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132847; 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=SqUrno67AFLGn35GLz5YA8v1mqjELXgVV+L32CRV+uY=; b=TwtJr/dRyT00SiExbmedYcwiWVKK2Y2NpgCNIcC2jY1mXsI8IAHYt0auK0LJ2Pq7ekds95 ydefzEDBRIr/NbV7nEbUsVxjSej81MU6ec4ItQFayOYIQ7COy1t/zMU0SM0IRFknHpYSLD 3DTPeK/sdnBhTxo9yfIiReUPk7kL/uY= X-MC-Unique: 68l15BzuMpCHJNkc8uLr_Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 09/23] vhost: Add SVQElement Date: Wed, 6 Jul 2022 20:39:54 +0200 Message-Id: <20220706184008.1649478-10-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657133588340100001 This will allow SVQ to add metadata to the different queue elements. To simplify changes, only store actual element at this patch. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 8 ++++-- hw/virtio/vhost-shadow-virtqueue.c | 41 ++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 0fbdd69153..e434dc63b0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,10 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/vhost-iova-tree.h" =20 +typedef struct SVQElement { + VirtQueueElement *elem; +} SVQElement; + typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; typedef int (*ShadowVirtQueueStart)(VhostShadowVirtqueue *svq, void *opaque); @@ -55,8 +59,8 @@ typedef struct VhostShadowVirtqueue { /* IOVA mapping */ VhostIOVATree *iova_tree; =20 - /* Map for use the guest's descriptors */ - VirtQueueElement **ring_id_maps; + /* Each element context */ + SVQElement *ring_id_maps; =20 /* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 46d3c1d74f..913bca8769 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -237,7 +237,7 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, co= nst struct iovec *out_sg, return false; } =20 - svq->ring_id_maps[qemu_head] =3D elem; + svq->ring_id_maps[qemu_head].elem =3D elem; return true; } =20 @@ -385,15 +385,25 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vh= ostShadowVirtqueue *svq, return i; } =20 -static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, - uint32_t *len) +static bool vhost_svq_is_empty_elem(SVQElement elem) +{ + return elem.elem =3D=3D NULL; +} + +static SVQElement vhost_svq_empty_elem(void) +{ + return (SVQElement){}; +} + +static SVQElement vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *l= en) { const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; + SVQElement svq_elem =3D vhost_svq_empty_elem(); uint16_t last_used, last_used_chain, num; =20 if (!vhost_svq_more_used(svq)) { - return NULL; + return svq_elem; } =20 /* Only get used array entries after they have been exposed by dev */ @@ -406,24 +416,25 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShado= wVirtqueue *svq, if (unlikely(used_elem.id >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", svq->vdev->name, used_elem.id); - return NULL; + return svq_elem; } =20 - if (unlikely(!svq->ring_id_maps[used_elem.id])) { + svq_elem =3D svq->ring_id_maps[used_elem.id]; + svq->ring_id_maps[used_elem.id] =3D vhost_svq_empty_elem(); + if (unlikely(vhost_svq_is_empty_elem(svq_elem))) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", svq->vdev->name, used_elem.id); - return NULL; + return svq_elem; } =20 - num =3D svq->ring_id_maps[used_elem.id]->in_num + - svq->ring_id_maps[used_elem.id]->out_num; + num =3D svq_elem.elem->in_num + svq_elem.elem->out_num; last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); svq->desc_next[last_used_chain] =3D svq->free_head; svq->free_head =3D used_elem.id; =20 *len =3D used_elem.len; - return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); + return svq_elem; } =20 /** @@ -454,6 +465,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, vhost_svq_disable_notification(svq); while (true) { uint32_t len; + SVQElement svq_elem; g_autofree VirtQueueElement *elem =3D NULL; =20 if (unlikely(i >=3D svq->vring.num)) { @@ -464,11 +476,12 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, return; } =20 - elem =3D vhost_svq_get_buf(svq, &len); - if (!elem) { + svq_elem =3D vhost_svq_get_buf(svq, &len); + if (vhost_svq_is_empty_elem(svq_elem)) { break; } =20 + elem =3D g_steal_pointer(&svq_elem.elem); virtqueue_fill(vq, elem, len, i++); } =20 @@ -611,7 +624,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, memset(svq->vring.desc, 0, driver_size); svq->vring.used =3D qemu_memalign(qemu_real_host_page_size(), device_s= ize); memset(svq->vring.used, 0, device_size); - svq->ring_id_maps =3D g_new0(VirtQueueElement *, svq->vring.num); + svq->ring_id_maps =3D g_new0(SVQElement, svq->vring.num); svq->desc_next =3D g_new0(uint16_t, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { svq->desc_next[i] =3D cpu_to_le16(i + 1); @@ -636,7 +649,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + elem =3D g_steal_pointer(&svq->ring_id_maps[i].elem); if (elem) { virtqueue_detach_element(svq->vq, elem, 0); } --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133928; cv=none; d=zohomail.com; s=zohoarc; b=bCMN96S89WCFNaVdfl8G5VnZfsyAs0YCxs2U9ltELT4Ct51cg8FRdyM19mFtFFrKnEo7slZIuaDXLQyHcVznRPRgMxIgH5nc6ZO6Hw3uqzGagthtJ+wJIMhUk5gf/Ck3bM8TWaMiogANxfMy3F2wStwZYJGEIyjVTbdPF/lpKNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133928; 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=Hyvxf57CY8G7BEOlwpKrHzUw7rJVcCPng6Gxf79fw10=; b=QE8wYZtsAzOthikp1ehalW6pOcWJOkRk++5dTZDCEBoLgl3n7LvzXHVU7HYnOwVorPdc79Y3dH7c7XLo129mTrdweE3J2A8TUexhJaCyybYaCZOnZY9gL5n8hpfcPPIfG+0a6jZ8L5Rs1ulPImaq5GG9xS9kxITzk151wEoQRxs= 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 1657133928059479.6567281216336; Wed, 6 Jul 2022 11:58:48 -0700 (PDT) Received: from localhost ([::1]:53874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AEY-0006lm-V1 for importer@patchew.org; Wed, 06 Jul 2022 14:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xR-0005Ry-IB for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40149) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xI-0000rI-H4 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:03 -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-474-1I_eltlbMUqPe_R4HXiNOA-1; Wed, 06 Jul 2022 14:40:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A00668001EA; Wed, 6 Jul 2022 18:40:42 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18F16141511D; Wed, 6 Jul 2022 18:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132853; 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=Hyvxf57CY8G7BEOlwpKrHzUw7rJVcCPng6Gxf79fw10=; b=PAERNngwlKIyB3GuYN8Ig8vMAZy7tu3qN4BrrVnp2Beox0a8rFoQphig/htFZRp/kQ5Fgc vzlfUHqN7AZRJ3Gg2F2eDMgIbCF+KGk5apRLwRQnNXTAq31BAQQdWj1rGSfuQC4Fv+yptd 1zF4LNW6Q+Zer0NbL9n77edXL/fcsD0= X-MC-Unique: 1I_eltlbMUqPe_R4HXiNOA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 10/23] vhost: Reorder vhost_svq_last_desc_of_chain Date: Wed, 6 Jul 2022 20:39:55 +0200 Message-Id: <20220706184008.1649478-11-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133929040100001 SVQ is going to store it in SVQElement, so we need it before add functions. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 913bca8769..cf1745fd4d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -218,6 +218,16 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *= svq, return true; } =20 +static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *s= vq, + uint16_t num, uint16_t i) +{ + for (uint16_t j =3D 0; j < (num - 1); ++j) { + i =3D le16_to_cpu(svq->desc_next[i]); + } + + return i; +} + /** * Add an element to a SVQ. * @@ -375,16 +385,6 @@ static void vhost_svq_disable_notification(VhostShadow= Virtqueue *svq) svq->vring.avail->flags |=3D cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } =20 -static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *s= vq, - uint16_t num, uint16_t i) -{ - for (uint16_t j =3D 0; j < (num - 1); ++j) { - i =3D le16_to_cpu(svq->desc_next[i]); - } - - return i; -} - static bool vhost_svq_is_empty_elem(SVQElement elem) { return elem.elem =3D=3D NULL; --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133669; cv=none; d=zohomail.com; s=zohoarc; b=KIucR6dWh35STlCGgcCbFCiuFB+wp+R2bSw8ovX+ZSq8NVCrtV4wK2MVE4bPI20KmVK05ASDjnXh4Piz3P8wIzwYFugbFtGd/4c7eHE3SntPSzRfYMXa0RaYCIcX9XnI+7iXOnCPDSbcx7mgoCEurOhYO9XezZbmQLrijGPSeCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133669; 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=HqkLuM/R/jquEqE73ZqXF2MmKZ+yHkxnxkzlBIXU8m4=; b=j6HC022UF8zg6QT5tAmnq3vUoH+8hBzYppDaWamdejQmIdZyNZAURweXjMKkwrrZkxA4GjP58lEP8geQBsWs7jB6KNiqZo4qwDQtcjN7dbUQmeokzVGXzrgxAeOlLQu9sJfMIvjDOq/+Bg42fgYrYSnMj2tcqOBfToXzTZfZ3+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657133669506481.9021471078007; Wed, 6 Jul 2022 11:54:29 -0700 (PDT) Received: from localhost ([::1]:42492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AAO-0006hW-GP for importer@patchew.org; Wed, 06 Jul 2022 14:54:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xK-0005O8-Re for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xG-0000r4-1T for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:40:57 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-H4kA-yW_M7q9BReYLqm87A-1; Wed, 06 Jul 2022 14:40:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72CFE18E5380; Wed, 6 Jul 2022 18:40:45 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id E10081415116; Wed, 6 Jul 2022 18:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132850; 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=HqkLuM/R/jquEqE73ZqXF2MmKZ+yHkxnxkzlBIXU8m4=; b=jC15l/ruJZgcIt2ITVrAJhTKkMp2CSC0H8RjJB26rDRbu78bEm/Jj/VTqnKTmvlgTMIKB9 K+ZZjIRoRfHX3lxmnkfEZ8sU8WZSlWhbRoOV513IOKfutsk3Q9HsDE9gTuc7g5MCqNlF/P otoCPfS9VWE98Aff3vcnABdgEEjqwqU= X-MC-Unique: H4kA-yW_M7q9BReYLqm87A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 11/23] vhost: Move last chain id to SVQ element Date: Wed, 6 Jul 2022 20:39:56 +0200 Message-Id: <20220706184008.1649478-12-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657133670918100001 We will allow SVQ user to store opaque data for each element, so its easier if we store this kind of information just at avail. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 +++ hw/virtio/vhost-shadow-virtqueue.c | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index e434dc63b0..0e434e9fd0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,9 @@ =20 typedef struct SVQElement { VirtQueueElement *elem; + + /* Last descriptor of the chain */ + uint32_t last_chain_id; } SVQElement; =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index cf1745fd4d..c5e49e51c5 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -239,7 +239,9 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, co= nst struct iovec *out_sg, size_t out_num, const struct iovec *in_sg, size_t in_num, VirtQueueElement *elem) { + SVQElement *svq_elem; unsigned qemu_head; + size_t n; bool ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head); if (unlikely(!ok)) { @@ -247,7 +249,10 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, c= onst struct iovec *out_sg, return false; } =20 - svq->ring_id_maps[qemu_head].elem =3D elem; + n =3D out_num + in_num; + svq_elem =3D &svq->ring_id_maps[qemu_head]; + svq_elem->elem =3D elem; + svq_elem->last_chain_id =3D vhost_svq_last_desc_of_chain(svq, n, qemu_= head); return true; } =20 @@ -400,7 +405,7 @@ static SVQElement vhost_svq_get_buf(VhostShadowVirtqueu= e *svq, uint32_t *len) const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; SVQElement svq_elem =3D vhost_svq_empty_elem(); - uint16_t last_used, last_used_chain, num; + uint16_t last_used; =20 if (!vhost_svq_more_used(svq)) { return svq_elem; @@ -428,11 +433,8 @@ static SVQElement vhost_svq_get_buf(VhostShadowVirtque= ue *svq, uint32_t *len) return svq_elem; } =20 - num =3D svq_elem.elem->in_num + svq_elem.elem->out_num; - last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); - svq->desc_next[last_used_chain] =3D svq->free_head; + svq->desc_next[svq_elem.last_chain_id] =3D svq->free_head; svq->free_head =3D used_elem.id; - *len =3D used_elem.len; return svq_elem; } --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133799; cv=none; d=zohomail.com; s=zohoarc; b=YMefVBcgq7L+20uTfZo6/PFUbl39YbF6h2yFdduLzWtdCy9AyDSHxm4iO96EvpTayrRGEUeReaPypF/38RVGKdpfGcyye8qsdqyV6yN3Vcv8DpyDybJCn3UhXUR4yYWv7UzU9PIIsTteuYWdtW4NjeESujQzP98M5P0XOtr0hB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133799; 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=vHrD422Fx7h9ptVNcUIdalNxoBuTWY+5kMR5xVsqK7g=; b=gXnVS7CrcHtCX6rxif74GyTXLL65E4gRZjsAdTqaiyfa+weIOwJsAEJ6MXhMgDaEzEsJ0uGW3N8MAfBvsshnJtHSCNoDEKNCCY/araDJBbZIFgDXzbvnEnQ3zyBGAJFNyTmmI85qE4Qu8x0nbljAPNSBHyOJtv5SS2dXALmFBEA= 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 1657133799115302.103746322637; Wed, 6 Jul 2022 11:56:39 -0700 (PDT) Received: from localhost ([::1]:47578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9ACU-00026i-2k for importer@patchew.org; Wed, 06 Jul 2022 14:56:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xQ-0005RP-OO for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xM-0000rv-Bh for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:02 -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-466-TTQgDZ7uMVqXxDccFGLFHw-1; Wed, 06 Jul 2022 14:40:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42DB5811E7A; Wed, 6 Jul 2022 18:40:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4C451410F3C; Wed, 6 Jul 2022 18:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132858; 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=vHrD422Fx7h9ptVNcUIdalNxoBuTWY+5kMR5xVsqK7g=; b=cBjxlwb8z0KJ6KN3Qb4WmJGJ9uHqNBxWuxuppFz4iZGZCpMKzIdntqFcundjBwA7vk7Svr 02lehSTCY7SllKtxELazDYqTXvAY5XXOT+vgoXEOUfyPl3S7YKEkXqBZgHxQrJDyOUe/eJ 8DjXOCkBMC8Id5ZkXrqXtjl9sjrezJY= X-MC-Unique: TTQgDZ7uMVqXxDccFGLFHw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 12/23] vhost: Add opaque member to SVQElement Date: Wed, 6 Jul 2022 20:39:57 +0200 Message-Id: <20220706184008.1649478-13-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133800645100001 When qemu injects buffers to the vdpa device it will be used to maintain contextual data. If SVQ has no operation, it will be used to maintain the VirtQueueElement pointer. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 ++- hw/virtio/vhost-shadow-virtqueue.c | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 0e434e9fd0..a811f90e01 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -16,7 +16,8 @@ #include "hw/virtio/vhost-iova-tree.h" =20 typedef struct SVQElement { - VirtQueueElement *elem; + /* Opaque data */ + void *opaque; =20 /* Last descriptor of the chain */ uint32_t last_chain_id; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c5e49e51c5..492bb12b5f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -237,7 +237,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vhos= tShadowVirtqueue *svq, */ static bool vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *o= ut_sg, size_t out_num, const struct iovec *in_sg, - size_t in_num, VirtQueueElement *elem) + size_t in_num, void *opaque) { SVQElement *svq_elem; unsigned qemu_head; @@ -245,13 +245,12 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, = const struct iovec *out_sg, bool ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head); if (unlikely(!ok)) { - g_free(elem); return false; } =20 n =3D out_num + in_num; svq_elem =3D &svq->ring_id_maps[qemu_head]; - svq_elem->elem =3D elem; + svq_elem->opaque =3D opaque; svq_elem->last_chain_id =3D vhost_svq_last_desc_of_chain(svq, n, qemu_= head); return true; } @@ -277,6 +276,8 @@ static bool vhost_svq_add_element(VhostShadowVirtqueue = *svq, elem->in_num, elem); if (ok) { vhost_svq_kick(svq); + } else { + g_free(elem); } =20 return ok; @@ -392,7 +393,7 @@ static void vhost_svq_disable_notification(VhostShadowV= irtqueue *svq) =20 static bool vhost_svq_is_empty_elem(SVQElement elem) { - return elem.elem =3D=3D NULL; + return elem.opaque =3D=3D NULL; } =20 static SVQElement vhost_svq_empty_elem(void) @@ -483,7 +484,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, break; } =20 - elem =3D g_steal_pointer(&svq_elem.elem); + elem =3D g_steal_pointer(&svq_elem.opaque); virtqueue_fill(vq, elem, len, i++); } =20 @@ -651,7 +652,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i].elem); + elem =3D g_steal_pointer(&svq->ring_id_maps[i].opaque); if (elem) { virtqueue_detach_element(svq->vq, elem, 0); } --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133416; cv=none; d=zohomail.com; s=zohoarc; b=FpUsLRfMX9iI7mq2EwMg+n+WSG9WC2J9PESlkSCDc4zgMNDWURur+KKMtLJOPiCLB30L6O2wTU9FNTJbgWjFO5xq6OA8XRe2zWQfvpYTc9fqrWYMBRNE7p39bmhXu0Sj9mZ5oLT4kL3fEFwvDP+U8rSzIi17gw6/GiDEGHfQ0uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133416; 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=Zks5sbDXsApuGo8sXmlR/yY7E4sTbJYTkFc3HYQXS/M=; b=K/9YZQ/loaV+XtGq9C860iSm40s1aP57u5F+Un8vKw+F2ljlllMh8ogwHHxTh8/WkfzR5ZAjHL+yuzWdoIhlCa4uMHVZ1fr7YTFhqN0gnRHg7pzk04bO+4UzAOme7PJUeluM92L8J/vLewnNLVe2L62TkQEgturex7UG39ig6iQ= 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 1657133416553509.94851087451957; Wed, 6 Jul 2022 11:50:16 -0700 (PDT) Received: from localhost ([::1]:59360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A6J-0007IN-CN for importer@patchew.org; Wed, 06 Jul 2022 14:50:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xX-0005Up-BM for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xJ-0000rY-AQ for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:09 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-4HthpFxQOFGT8sN6FLZSoQ-1; Wed, 06 Jul 2022 14:40:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11D5A3C0F37D; Wed, 6 Jul 2022 18:40:51 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84EF91415116; Wed, 6 Jul 2022 18:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132855; 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=Zks5sbDXsApuGo8sXmlR/yY7E4sTbJYTkFc3HYQXS/M=; b=XEF+8XSy5fukC0cW7aUaxB4DmAawSHucA5vzYBLTXFutgndpheNNVVW/M3C+hRgIGKX6qY a7vu/C5g4Z4b/6i1o5qLHiiUAWxGqN0hZcGHd+r8SQk7pTgdFx34cUM081v9Cp5UCq1H3D GX/cFUMOdF500S9tWKgqvKqByyECN2M= X-MC-Unique: 4HthpFxQOFGT8sN6FLZSoQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 13/23] vhost: Add vhost_svq_inject Date: Wed, 6 Jul 2022 20:39:58 +0200 Message-Id: <20220706184008.1649478-14-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657133417883100001 This allows qemu to inject buffers to the device. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 34 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index a811f90e01..d01d2370db 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -98,6 +98,8 @@ bool vhost_svq_valid_features(uint64_t features, Error **= errp); =20 void vhost_svq_push_elem(VhostShadowVirtqueue *svq, const VirtQueueElement *elem, uint32_t len); +int vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num, void *opaque); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 492bb12b5f..bd9e34b413 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -283,6 +283,40 @@ static bool vhost_svq_add_element(VhostShadowVirtqueue= *svq, return ok; } =20 +/** + * Inject a chain of buffers to the device + * + * @svq: Shadow VirtQueue + * @iov: I/O vector + * @out_num: Number of front out descriptors + * @in_num: Number of last input descriptors + * @opaque: Contextual data to store in descriptor + * + * Return 0 on success, -ENOMEM if cannot inject + */ +int vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num, void *opaque) +{ + bool ok; + + /* + * All vhost_svq_inject calls are controlled by qemu so we won't hit t= his + * assertions. + */ + assert(out_num || in_num); + assert(svq->ops); + + if (unlikely(svq->next_guest_avail_elem)) { + error_report("Injecting in a full queue"); + return -ENOMEM; + } + + ok =3D vhost_svq_add(svq, iov, out_num, iov + out_num, in_num, opaque); + assert(ok); + vhost_svq_kick(svq); + return 0; +} + /** * Forward available buffers. * --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133870; cv=none; d=zohomail.com; s=zohoarc; b=XQG848Df3JSku2vyiNDn8doKjo1rvWetIVzzHX6Af4zzMT1QQx0lK9Z5vHTxbIL5iODhiNhZVudDb6iEU37oeet5L8CZ6heJWvwP43//8QlFOtl8/DeBHuOCei6AwjprPb1zyGwb7clXZI9azs0dVWynDQp9ERQegsFuTZNJkh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133870; 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=7ZLwu+6AF4zkR9z1JXMp2MzIWH9CQtFIHGTsbAD4Jxk=; b=lQBcBHVXiYFRIcu+NpaZm65hI7AA6U1FnzfNZIL/gZqJPv3DdHSWYj/LW8+tIfIQGYbqrlu2bD4vTjkNx7FP1zy4rcGNXwvSFB3Q5oq+8lYKOnmHW85nDNsJzmQWGQy9J4veaZ6XKZWsNcwmcS0KFuYrbxxAf8z0rnxBvLEiYNo= 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 1657133870193886.6378454594158; Wed, 6 Jul 2022 11:57:50 -0700 (PDT) Received: from localhost ([::1]:50062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9ADd-0004AI-6g for importer@patchew.org; Wed, 06 Jul 2022 14:57:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xi-0005aS-JW for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28716) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xT-0000sg-94 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41: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-660-o0mbc5fxOkST8cuBZv-bBA-1; Wed, 06 Jul 2022 14:40:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D6E0085A582; Wed, 6 Jul 2022 18:40:53 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53FD21415116; Wed, 6 Jul 2022 18:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132863; 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=7ZLwu+6AF4zkR9z1JXMp2MzIWH9CQtFIHGTsbAD4Jxk=; b=Kp/Nam1UMhk5ooTXg6uVBf2fZBHNRndKu6NFD4Hfzh8jmWUg+zykqVw3XxWe8vpvSAqJz2 3PLAaR/Ouo8PUAcy9NEeGK8/42gYiCLn+/uLvqQu8sPbjyaXWBvoteY95x5fSUjmu6kSwe +zwe1Gd/ocUk7YVTqoln/XFE9FsHpLU= X-MC-Unique: o0mbc5fxOkST8cuBZv-bBA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 14/23] vhost: add vhost_svq_poll Date: Wed, 6 Jul 2022 20:39:59 +0200 Message-Id: <20220706184008.1649478-15-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1657133870674100003 It allows the Shadow Control VirtQueue to wait the device to use the comman= ds that restore the net device state after a live migration. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 54 ++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d01d2370db..c8668fbdd6 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -100,6 +100,7 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq, const VirtQueueElement *elem, uint32_t len); int vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, size_t out_num, size_t in_num, void *opaque); +ssize_t vhost_svq_poll(VhostShadowVirtqueue *svq); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index bd9e34b413..ed7f1d0bc9 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -10,6 +10,8 @@ #include "qemu/osdep.h" #include "hw/virtio/vhost-shadow-virtqueue.h" =20 +#include + #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu/main-loop.h" @@ -490,10 +492,11 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq, } } =20 -static void vhost_svq_flush(VhostShadowVirtqueue *svq, - bool check_for_avail_queue) +static size_t vhost_svq_flush(VhostShadowVirtqueue *svq, + bool check_for_avail_queue) { VirtQueue *vq =3D svq->vq; + size_t ret =3D 0; =20 /* Forward as many used buffers as possible. */ do { @@ -510,7 +513,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, "More than %u used buffers obtained in a %u size = SVQ", i, svq->vring.num); virtqueue_flush(vq, svq->vring.num); - return; + return ret; } =20 svq_elem =3D vhost_svq_get_buf(svq, &len); @@ -520,6 +523,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, =20 elem =3D g_steal_pointer(&svq_elem.opaque); virtqueue_fill(vq, elem, len, i++); + ret++; } =20 virtqueue_flush(vq, i); @@ -533,6 +537,50 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, vhost_handle_guest_kick(svq); } } while (!vhost_svq_enable_notification(svq)); + + return ret; +} + +/** + * Poll the SVQ for device used buffers. + * + * This function race with main event loop SVQ polling, so extra + * synchronization is needed. + * + * Return the number of descriptors read from the device. + */ +ssize_t vhost_svq_poll(VhostShadowVirtqueue *svq) +{ + int fd =3D event_notifier_get_fd(&svq->hdev_call); + GPollFD poll_fd =3D { + .fd =3D fd, + .events =3D G_IO_IN, + }; + assert(fd >=3D 0); + int r =3D g_poll(&poll_fd, 1, -1); + + if (unlikely(r < 0)) { + error_report("Cannot poll device call fd "G_POLLFD_FORMAT": (%d) %= s", + poll_fd.fd, errno, g_strerror(errno)); + return -errno; + } + + if (r =3D=3D 0) { + return 0; + } + + if (unlikely(poll_fd.revents & ~(G_IO_IN))) { + error_report( + "Error polling device call fd "G_POLLFD_FORMAT": revents=3D%d", + poll_fd.fd, poll_fd.revents); + return -1; + } + + /* + * Max return value of vhost_svq_flush is (uint16_t)-1, so it's safe to + * convert to ssize_t. + */ + return vhost_svq_flush(svq, false); } =20 /** --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134224; cv=none; d=zohomail.com; s=zohoarc; b=RonlxCUy5NxQgeVBZUNw0qqsIzdF+xDupm8ixbKQpeNJHM3sYNqL4ErQFsme9+f6n1nIAxTDp526QoBUka5A+pmXaFtfw3k9qn8MwHIli2fNW7hLpg0rBMSiFCXBskEjfC0Z/bidP2QL1gYIbH/08IHSC/arWbm9tMaJ1wHJCUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134224; 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=BOWX5PpHO+1vMPlU7JIBQ/clbCyfjrR6m5We3NFT290=; b=fChRgIzXct3Bjh9lm8BG7U5MhBWNfriROdK2MZvXPXBBEn/3hglqyQEx6YUPqLrkk2PsLRREKWBiEW8nqSdKoHqeMUkVqQfhmqMgBAujESS0qeDQ4hvhufEgr9zQBlgGl7v0y4q11jQ80O1ERPpi+ajJgk17K2n2gq7o+ceVLgQ= 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 165713422479792.61791446137352; Wed, 6 Jul 2022 12:03:44 -0700 (PDT) Received: from localhost ([::1]:60206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AJL-0002oW-Q5 for importer@patchew.org; Wed, 06 Jul 2022 15:03:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xl-0005b3-R8 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xV-0000t7-Hk for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:24 -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-656-mZZRp-KMP82IDnmZsvFH0w-1; Wed, 06 Jul 2022 14:40:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6A6C811E81; Wed, 6 Jul 2022 18:40:56 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24E511415116; Wed, 6 Jul 2022 18:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132867; 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=BOWX5PpHO+1vMPlU7JIBQ/clbCyfjrR6m5We3NFT290=; b=d/bqMvcm9GP5EkxsEKHoXVrDzmzG99QXb5IhgleY5oihRUL9TmSWop8xv0BntHaYLLPgp2 Xp4wCc+Sa1Ktq0S/rSi1EQZtrd+soi+7/fSp2lRrKCu9OooR/6i2pGI2EvFRYms9tPB/61 r2lfkQDdYAFl1pFPWkgG/x17a7P/SL8= X-MC-Unique: mZZRp-KMP82IDnmZsvFH0w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 15/23] vhost: Add custom used buffer callback Date: Wed, 6 Jul 2022 20:40:00 +0200 Message-Id: <20220706184008.1649478-16-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657134225241100001 The callback allows SVQ users to know the VirtQueue requests and responses. QEMU can use this to synchronize virtio device model state, allowing to migrate it with minimum changes to the migration code. If callbacks are specified at svq creation, the buffers need to be injected to the device using vhost_svq_inject. An opaque data must be given with it, and its returned to the callback at used_handler call. In the case of networking, this will be used to inspect control virtqueue messages and to recover status injection at the first time. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 5 +++++ hw/virtio/vhost-shadow-virtqueue.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c8668fbdd6..296fef6f21 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -27,8 +27,13 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; typedef int (*ShadowVirtQueueStart)(VhostShadowVirtqueue *svq, void *opaque); =20 +typedef void (*VirtQueueUsedCallback)(VhostShadowVirtqueue *svq, + void *used_elem_opaque, + uint32_t written); + typedef struct VhostShadowVirtqueueOps { ShadowVirtQueueStart start; + VirtQueueUsedCallback used_handler; } VhostShadowVirtqueueOps; =20 /* Shadow virtqueue to relay notifications */ diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index ed7f1d0bc9..b92ca4a63f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -506,7 +506,6 @@ static size_t vhost_svq_flush(VhostShadowVirtqueue *svq, while (true) { uint32_t len; SVQElement svq_elem; - g_autofree VirtQueueElement *elem =3D NULL; =20 if (unlikely(i >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, @@ -521,13 +520,20 @@ static size_t vhost_svq_flush(VhostShadowVirtqueue *s= vq, break; } =20 - elem =3D g_steal_pointer(&svq_elem.opaque); - virtqueue_fill(vq, elem, len, i++); + if (svq->ops) { + svq->ops->used_handler(svq, svq_elem.opaque, len); + } else { + g_autofree VirtQueueElement *elem =3D NULL; + elem =3D g_steal_pointer(&svq_elem.opaque); + virtqueue_fill(vq, elem, len, i++); + } ret++; } =20 - virtqueue_flush(vq, i); - event_notifier_set(&svq->svq_call); + if (i > 0) { + virtqueue_flush(vq, i); + event_notifier_set(&svq->svq_call); + } =20 if (check_for_avail_queue && svq->next_guest_avail_elem) { /* --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133956; cv=none; d=zohomail.com; s=zohoarc; b=NmM+Xjt0/wFSAiSTJOgfEW80Dkxq76qPL1CQDTRv8m/3jQYp+k6ALHWwPoU7Dg4hyMQL1V8wmFkXhXyNzp5asQOhkwQjoNECQQILMGiD1tugku76U30Te09A1F4u22qvPc91RgzxFMcAWojRofwmNRNZiTNpfs/WA82O5pl+SMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133956; 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=mErUwknFduO65jJc0n1ezU/K63y3yE1x6XCKC1pU+Qk=; b=Gpvypm6IHTEwcmqk/ahITAoEQK3Tef4F5V2b2EEQR40RyD+ItCwKogQRuWCGWQSdtz6q8/9Ja+VVUgVJ7P0TQb20hydwua3M0tJh90riWi0v2dRnfZv+zefNBFoQbUq0iYkXIMiOKIK3WH6A8avEeGKzaCMgJxfxC9are0CZkdg= 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 1657133956196521.499761307013; Wed, 6 Jul 2022 11:59:16 -0700 (PDT) Received: from localhost ([::1]:55566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AF1-0007wK-3y for importer@patchew.org; Wed, 06 Jul 2022 14:59:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xZ-0005VR-5D for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xR-0000sb-3h for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:11 -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-492-U1B8RKULOCeUIc-_EtQBgg-1; Wed, 06 Jul 2022 14:41:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76F63294EDEF; Wed, 6 Jul 2022 18:40:59 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8C2F1415116; Wed, 6 Jul 2022 18:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132863; 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=mErUwknFduO65jJc0n1ezU/K63y3yE1x6XCKC1pU+Qk=; b=SPiKohMTUaZN4TXfx/m8Jly7OLkW0wbqcYtF0xecjOtFnpwwgvK9VstdjEP34tf+z72VQ3 fokCeslDrKewNT9cXKQZdvgKUe2NKqWm5fFFZBdS7J9ETC+3hj6am5WmarjrocWOmAoj9t qE8Jj7+SfPELq5ziaEGe0WhgjwKLlU4= X-MC-Unique: U1B8RKULOCeUIc-_EtQBgg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 16/23] vhost: Add svq avail_handler callback Date: Wed, 6 Jul 2022 20:40:01 +0200 Message-Id: <20220706184008.1649478-17-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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: 1657133957379100001 This allows external handlers to be aware of new buffers that the guest places in the virtqueue. When this callback is defined the ownership of guest's virtqueue element is transferred to the callback. This means that if the user wants to forward the descriptor it needs to manually inject it. The callback is also free to process the command by itself and use the element with svq_push. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 16 ++++++++++++++++ hw/virtio/vhost-shadow-virtqueue.c | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 296fef6f21..4300cb66f8 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -27,12 +27,28 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueu= e; typedef int (*ShadowVirtQueueStart)(VhostShadowVirtqueue *svq, void *opaque); =20 +/** + * Callback to handle an avail buffer. + * + * @svq: Shadow virtqueue + * @elem: Element placed in the queue by the guest + * @vq_callback_opaque: Opaque + * + * Returns true if the vq is running as expected, false otherwise. + * + * Note that ownership of elem is transferred to the callback. + */ +typedef bool (*VirtQueueAvailCallback)(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + void *vq_callback_opaque); + typedef void (*VirtQueueUsedCallback)(VhostShadowVirtqueue *svq, void *used_elem_opaque, uint32_t written); =20 typedef struct VhostShadowVirtqueueOps { ShadowVirtQueueStart start; + VirtQueueAvailCallback avail_handler; VirtQueueUsedCallback used_handler; } VhostShadowVirtqueueOps; =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b92ca4a63f..dffea256f1 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -371,7 +371,13 @@ static void vhost_handle_guest_kick(VhostShadowVirtque= ue *svq) return; } =20 - ok =3D vhost_svq_add_element(svq, g_steal_pointer(&elem)); + if (svq->ops) { + ok =3D svq->ops->avail_handler(svq, g_steal_pointer(&elem), + svq->ops_opaque); + } else { + ok =3D vhost_svq_add_element(svq, g_steal_pointer(&elem)); + } + if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134459; cv=none; d=zohomail.com; s=zohoarc; b=hVXCSN4c8sQqCyDcJrE8f2XWstWyKM3v9kmebs7x2f/zpst/3uNH14t+WthrjZnPbAXxMXBWncF7gYRy0lb8Y52o3VE5kmWaHUEnN3qKzD8uZy5Z8mv4gizWbqYpI9OKksi+lcF/QL6Fy1Guj6QsR88Ul/1y8jCryFMKvH8PB18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134459; 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=ziR3ctgT/CCLnNAiqZTlkOadNXJL1NwUmNcP1OIzuHA=; b=iMzneVmJWsx7pOKWJZd13Jf1zDsJXTuXS6kqb4tXDx/iuRRtrPGuZCKkGplK7kHCQeUEKsoOs1bmI1BkeqDK1Qlt2u4/dHaPBK+WncNJVMDpGDiFVzKsR43asdjPSGG1k7ktkQiawTiYCPy4zbX5lm9wfj7u3j2yxFpaJAM3zjQ= 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 16571344594407.643823125207518; Wed, 6 Jul 2022 12:07:39 -0700 (PDT) Received: from localhost ([::1]:38464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AN8-0007Kz-FX for importer@patchew.org; Wed, 06 Jul 2022 15:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xm-0005aF-7G for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xU-0000sv-1N for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:21 -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-28-1C7HMeMgNWKz2SH2kUhu2A-1; Wed, 06 Jul 2022 14:41:02 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DA591019C8B; Wed, 6 Jul 2022 18:41:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id B95531415116; Wed, 6 Jul 2022 18:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132866; 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=ziR3ctgT/CCLnNAiqZTlkOadNXJL1NwUmNcP1OIzuHA=; b=MKvgtNipkECyKuihHgO6WqDEDmva3zXTsyO7Qft0r56RhdAyQXpmp1vO3LYzdf13R2YC8t 2yAJvrkjmU6wEUsDhW1c1KFnbXuvoA4VxGJwF/1p+5ylxpMP+7dpY/w3I0f8pEWpoKB+uA UGTDzT75N/bvfqglSyl1gpCUXVfUnXQ= X-MC-Unique: 1C7HMeMgNWKz2SH2kUhu2A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 17/23] vhost: add detach SVQ operation Date: Wed, 6 Jul 2022 20:40:02 +0200 Message-Id: <20220706184008.1649478-18-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657134460533100001 To notify the caller it needs to discard the element. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 11 +++++++++++ hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 4300cb66f8..583b6fda5d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -46,10 +46,21 @@ typedef void (*VirtQueueUsedCallback)(VhostShadowVirtqu= eue *svq, void *used_elem_opaque, uint32_t written); =20 +/** + * Detach the element from the shadow virtqueue. SVQ needs to free it and= it + * cannot be pushed or discarded. + * + * @elem_opaque: The element opaque + * + * Return the guest element to detach and free if any. + */ +typedef VirtQueueElement *(*VirtQueueDetachCallback)(void *elem_opaque); + typedef struct VhostShadowVirtqueueOps { ShadowVirtQueueStart start; VirtQueueAvailCallback avail_handler; VirtQueueUsedCallback used_handler; + VirtQueueDetachCallback detach_handler; } VhostShadowVirtqueueOps; =20 /* Shadow virtqueue to relay notifications */ diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index dffea256f1..4f072f040b 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -746,7 +746,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i].opaque); + void *opaque =3D g_steal_pointer(&svq->ring_id_maps[i].opaque); + + if (!opaque) { + continue; + } else if (svq->ops) { + elem =3D svq->ops->detach_handler(opaque); + } else { + elem =3D opaque; + } + if (elem) { virtqueue_detach_element(svq->vq, elem, 0); } --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134588; cv=none; d=zohomail.com; s=zohoarc; b=N8hzrsMX2gtdR9ibPw760bH9cemIUewYmAo4zO+1NaFgnnAodLu7FHajPpUkdhsgAV6vuX3Kn5WMqNo8PsBu+iWl9Z1bMIsPj1xgUgmr2IBf1DB29aX3d9xQmtPfAysW15fFuw0+N85imUoI/ipLx87BwG+7bIGrIaqn7ZABs1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134588; 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=3QD+UF4oXCfphsAmpAc8aXI/PNUipIiY45PMK1Y5dq8=; b=iitgGSgrsy9blnPPyLL27+O1vpJ4JVIRMAVIcBCxiKspW76wveTrR+CcWVj+JYRg+sBni3fMWa2yc+FpMi2NS1E0ecubMfp1vlrtgVsoYv5Ikz9FnQrr3v/8ro5+ioG9bTqo/TrdhBVQaAt4Nz889eNNp3u1HUL6kEo+Zu/m+ww= 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 1657134588911451.13134221363646; Wed, 6 Jul 2022 12:09:48 -0700 (PDT) Received: from localhost ([::1]:45190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9APD-0003Ry-PX for importer@patchew.org; Wed, 06 Jul 2022 15:09:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xn-0005bh-C6 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xX-0000tN-MZ for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:27 -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-21-4Kfm1CBnOUu7TXI0JGjxVg-1; Wed, 06 Jul 2022 14:41:05 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30C9D3800C39; Wed, 6 Jul 2022 18:41:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1CF6141511D; Wed, 6 Jul 2022 18:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132869; 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=3QD+UF4oXCfphsAmpAc8aXI/PNUipIiY45PMK1Y5dq8=; b=F+s/rwdtRw0Uu3Zg7VV+d/0EU5OLlm+3laWwwhstAlLYSvoZ34hAXmB+NYGLBNp+RubZpM tK2VLlZ+0Y3l5TeGX2ETATgEK0bdEzXsKouWPAOIjSTc/VIvzsh3X05norQ8R3Kwfa5IZE OWQNxmtmqExmbx4d6DAQQY1frmU5iK8= X-MC-Unique: 4Kfm1CBnOUu7TXI0JGjxVg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 18/23] vdpa: Export vhost_vdpa_dma_map and unmap calls Date: Wed, 6 Jul 2022 20:40:03 +0200 Message-Id: <20220706184008.1649478-19-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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: 1657134590066100001 Shadow CVQ will copy buffers on qemu VA, so we avoid TOCTOU attacks that can set a different state in qemu device model and vdpa device. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 4 ++++ hw/virtio/vhost-vdpa.c | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index a29dbb3f53..7214eb47dc 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -39,4 +39,8 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; =20 +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly); +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size); + #endif diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 69cfaf05d6..613c3483b0 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -71,8 +71,8 @@ static bool vhost_vdpa_listener_skipped_section(MemoryReg= ionSection *section, return false; } =20 -static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr si= ze, - void *vaddr, bool readonly) +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; @@ -97,8 +97,7 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwadd= r iova, hwaddr size, return ret; } =20 -static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, - hwaddr size) +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134079; cv=none; d=zohomail.com; s=zohoarc; b=m5bUpkT1BBFGZMAP4+YljukNpq1uyeTdNlAbYsNosJpOk7omSs8HJvh1bqukLALIhEjarAfLlstOvR0sstfqi2K6GwZIQnxxpa4VITbZMqtq9nWpytTchX/FRh5cViML6cbW3WFoaDShQ+fA4eXceMyeRutuNXfl4C6K9ASQTvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134079; 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=S6RMZ31CQp3UEAC5pDU+a65ORFdNDnmqt/5vMRiq4B8=; b=kaAHFWyAYWvACufOIPq/5S4MhtsaZVbI82PInrdmgIG11G66IN2dXYgV3d6wGYKaYkuCnMXkttaBzMJoGVnuCM9hR3trNPzH4T6kJg/Ue307VCPK9P2rE92e7JIm//x7yU2AwKU5CmizG26IBOwEG4baDlEZYX4B89rrzOmsg44= 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 1657134079283724.7084308001291; Wed, 6 Jul 2022 12:01:19 -0700 (PDT) Received: from localhost ([::1]:57860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AH0-00014R-5l for importer@patchew.org; Wed, 06 Jul 2022 15:01:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xr-0005d4-PU for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xl-0000vH-4R for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:30 -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-646-A8TzJd9AP4u2vibckSVrTQ-1; Wed, 06 Jul 2022 14:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E1A0185A7A4; Wed, 6 Jul 2022 18:41:08 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72B9E1415116; Wed, 6 Jul 2022 18:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132877; 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=S6RMZ31CQp3UEAC5pDU+a65ORFdNDnmqt/5vMRiq4B8=; b=iyK2WjdFtawYUiIksSMrx+n39jJ636p57DYHu4jSsAwCDPmLm79q8R3+somwLE3yrbCHEd 5g63Xm9ieQQUF354YESbDLOFnmlgaRy9QlPiYs4En6Q3aJGrq4/EkWivOeMCsRUHwXjoYf dz1VXo0vvqX8/+Sr6mlVOaTcXp1FM98= X-MC-Unique: A8TzJd9AP4u2vibckSVrTQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 19/23] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Date: Wed, 6 Jul 2022 20:40:04 +0200 Message-Id: <20220706184008.1649478-20-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657134080090100001 To know the device features is needed for CVQ SVQ, so SVQ knows if it can handle all commands or not. Extract from vhost_vdpa_get_max_queue_pairs so we can reuse it. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- net/vhost-vdpa.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index df1e69ee72..b0158f625e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -219,20 +219,24 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, return nc; } =20 -static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **er= rp) +static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) +{ + int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); + if (ret) { + error_setg_errno(errp, errno, + "Fail to query features from vhost-vDPA device"); + } + return ret; +} + +static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, + int *has_cvq, Error **errp) { unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); g_autofree struct vhost_vdpa_config *config =3D NULL; __virtio16 *max_queue_pairs; - uint64_t features; int ret; =20 - ret =3D ioctl(fd, VHOST_GET_FEATURES, &features); - if (ret) { - error_setg(errp, "Fail to query features from vhost-vDPA device"); - return ret; - } - if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) { *has_cvq =3D 1; } else { @@ -262,10 +266,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; - int queue_pairs, i, has_cvq =3D 0; + int queue_pairs, r, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -279,7 +284,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, return -errno; } =20 - queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + r =3D vhost_vdpa_get_features(vdpa_device_fd, &features, errp); + if (r) { + return r; + } + + queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, &has_cvq, errp); if (queue_pairs < 0) { qemu_close(vdpa_device_fd); --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657133600; cv=none; d=zohomail.com; s=zohoarc; b=Sh1QBJh8zO0gokav/SuwaG2Z9fkYcEXUbDKjIIS/iaLzCUBTQCaXRK7QcNACC6z6WzM59TREz4FCRESbo+FEXYT2BD5g9hep+7qrG6Jszc+E2yL1DxU9yJWFB3P/O0SNI2u5l6kvtrpA8Mkn1zG50yQpDbEsm9n0n4U4aE/0mnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657133600; 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=yKvfOXHSuDLmmx0WvW0ZNBepkzXeLbxysaOxkM8tv8o=; b=XO/JDYg1CD5oI+P1dKwxFb178CMRccvEDEdVIzUwq1fRv+3Wn8sDXc9ReCy+5h7qY6XB0pRIWxcm+fPSvPg02/8dUqFVNBZ5bp0OVp3S3X71mNPmxPIXGDYZ3w/GX75X/LhUhYv6n08+dp2mAfoM45Fa9Bapy2JYxdh3skV6b7g= 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 1657133600685385.9089635456072; Wed, 6 Jul 2022 11:53:20 -0700 (PDT) Received: from localhost ([::1]:39626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9A9G-0004hE-Ng for importer@patchew.org; Wed, 06 Jul 2022 14:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99yF-0005lH-BF for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xm-0000wB-AV for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:45 -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-206-MRQiBnkRMqKAd4K2PDTl9Q-1; Wed, 06 Jul 2022 14:41:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7C3D811E87; Wed, 6 Jul 2022 18:41:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52F581415116; Wed, 6 Jul 2022 18:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132883; 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=yKvfOXHSuDLmmx0WvW0ZNBepkzXeLbxysaOxkM8tv8o=; b=ZmYbuCJUcCOgzICHjQsqPn8g2uP4Ulu6zw527L1LMGCT+uIO0liJ7d6nW9R1sPGo5YF7Jl ks/92uBTBeaT3b1hVkxl8H+XnOwgi/p4gJlpELX/Ehnh5KKZ1KfPerMME0zKHXOUmPYAjF 7WAnh9O4Q1qywbqQBQUK8Bcp4GE2uIY= X-MC-Unique: MRQiBnkRMqKAd4K2PDTl9Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 20/23] vdpa: Buffer CVQ support on shadow virtqueue Date: Wed, 6 Jul 2022 20:40:05 +0200 Message-Id: <20220706184008.1649478-21-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1657133602437100001 Introduce the control virtqueue support for vDPA shadow virtqueue. This is needed for advanced networking features like multiqueue. Virtio-net control VQ will copy the descriptors to qemu's VA, so we avoid TOCTOU with the guest's or device's memory every time there is a device model change. When address space isolation is implemented, this will allow, CVQ to only have access to control messages too. To demonstrate command handling, VIRTIO_NET_F_CTRL_MACADDR is implemented. If virtio-net driver changes MAC the virtio-net device model will be updated with the new one. Others cvq commands could be added here straightforwardly but they have been not tested. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 3 + hw/virtio/vhost-vdpa.c | 5 +- net/vhost-vdpa.c | 373 +++++++++++++++++++++++++++++++++ 3 files changed, 379 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 7214eb47dc..1111d85643 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -15,6 +15,7 @@ #include =20 #include "hw/virtio/vhost-iova-tree.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 @@ -35,6 +36,8 @@ typedef struct vhost_vdpa { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; + const VhostShadowVirtqueueOps *shadow_vq_ops; + void *shadow_vq_ops_opaque; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 613c3483b0..94bda07b4d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -417,9 +417,10 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev,= struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree= , NULL, - NULL); + g_autoptr(VhostShadowVirtqueue) svq =3D NULL; =20 + svq =3D vhost_svq_new(v->iova_tree, v->shadow_vq_ops, + v->shadow_vq_ops_opaque); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index b0158f625e..e415cc8de5 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,11 +11,15 @@ =20 #include "qemu/osdep.h" #include "clients.h" +#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "net/vhost-vdpa.h" #include "hw/virtio/vhost-vdpa.h" +#include "qemu/buffer.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/memalign.h" #include "qemu/option.h" #include "qapi/error.h" #include @@ -25,6 +29,26 @@ #include "monitor/monitor.h" #include "hw/virtio/vhost.h" =20 +typedef struct CVQElement { + /* Device's in and out buffer */ + void *in_buf, *out_buf; + + /* Optional guest element from where this cvqelement was created */ + VirtQueueElement *guest_elem; + + /* Control header sent by the guest. */ + struct virtio_net_ctrl_hdr ctrl; + + /* vhost-vdpa device, for cleanup reasons */ + struct vhost_vdpa *vdpa; + + /* Length of out data */ + size_t out_len; + + /* Copy of the out data sent by the guest excluding ctrl. */ + uint8_t out_data[]; +} CVQElement; + /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState { NetClientState nc; @@ -187,6 +211,351 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +/** + * Unmap a descriptor chain of a SVQ element, optionally copying its in bu= ffers + * + * @svq: Shadow VirtQueue + * @iova: SVQ IO Virtual address of descriptor + * @iov: Optional iovec to store device writable buffer + * @iov_cnt: iov length + * @buf_len: Length written by the device + * + * TODO: Use me! and adapt to net/vhost-vdpa format + * Print error message in case of error + */ +static void vhost_vdpa_cvq_unmap_buf(CVQElement *elem, void *addr) +{ + struct vhost_vdpa *v =3D elem->vdpa; + VhostIOVATree *tree =3D v->iova_tree; + DMAMap needle =3D { + /* + * No need to specify size or to look for more translations since + * this contiguous chunk was allocated by us. + */ + .translated_addr =3D (hwaddr)(uintptr_t)addr, + }; + const DMAMap *map =3D vhost_iova_tree_find_iova(tree, &needle); + int r; + + if (unlikely(!map)) { + error_report("Cannot locate expected map"); + goto err; + } + + r =3D vhost_vdpa_dma_unmap(v, map->iova, map->size + 1); + if (unlikely(r !=3D 0)) { + error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); + } + + vhost_iova_tree_remove(tree, map); + +err: + qemu_vfree(addr); +} + +static void vhost_vdpa_cvq_delete_elem(CVQElement *elem) +{ + if (elem->out_buf) { + vhost_vdpa_cvq_unmap_buf(elem, g_steal_pointer(&elem->out_buf)); + } + + if (elem->in_buf) { + vhost_vdpa_cvq_unmap_buf(elem, g_steal_pointer(&elem->in_buf)); + } + + /* Guest element must have been returned to the guest or free otherway= */ + assert(!elem->guest_elem); + + g_free(elem); +} +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CVQElement, vhost_vdpa_cvq_delete_elem); + +static int vhost_vdpa_net_cvq_svq_inject(VhostShadowVirtqueue *svq, + CVQElement *cvq_elem, + size_t out_len) +{ + const struct iovec iov[] =3D { + { + .iov_base =3D cvq_elem->out_buf, + .iov_len =3D out_len, + },{ + .iov_base =3D cvq_elem->in_buf, + .iov_len =3D sizeof(virtio_net_ctrl_ack), + } + }; + + return vhost_svq_inject(svq, iov, 1, 1, cvq_elem); +} + +static void *vhost_vdpa_cvq_alloc_buf(struct vhost_vdpa *v, + const uint8_t *out_data, size_t data= _len, + bool write) +{ + DMAMap map =3D {}; + size_t buf_len =3D ROUND_UP(data_len, qemu_real_host_page_size()); + void *buf =3D qemu_memalign(qemu_real_host_page_size(), buf_len); + int r; + + if (!write) { + memcpy(buf, out_data, data_len); + memset(buf + data_len, 0, buf_len - data_len); + } else { + memset(buf, 0, data_len); + } + + map.translated_addr =3D (hwaddr)(uintptr_t)buf; + map.size =3D buf_len - 1; + map.perm =3D write ? IOMMU_RW : IOMMU_RO, + r =3D vhost_iova_tree_map_alloc(v->iova_tree, &map); + if (unlikely(r !=3D IOVA_OK)) { + error_report("Cannot map injected element"); + goto err; + } + + r =3D vhost_vdpa_dma_map(v, map.iova, buf_len, buf, !write); + /* TODO: Handle error */ + assert(r =3D=3D 0); + + return buf; + +err: + qemu_vfree(buf); + return NULL; +} + +/** + * Allocate an element suitable to be injected + * + * @iov: The iovec + * @out_num: Number of out elements, placed first in iov + * @in_num: Number of in elements, placed after out ones + * @elem: Optional guest element from where this one was created + * + * TODO: Do we need a sg for out_num? I think not + */ +static CVQElement *vhost_vdpa_cvq_alloc_elem(VhostVDPAState *s, + struct virtio_net_ctrl_hdr ct= rl, + const struct iovec *out_sg, + size_t out_num, size_t out_si= ze, + VirtQueueElement *elem) +{ + g_autoptr(CVQElement) cvq_elem =3D g_malloc(sizeof(CVQElement) + out_s= ize); + uint8_t *out_cursor =3D cvq_elem->out_data; + struct vhost_vdpa *v =3D &s->vhost_vdpa; + + /* Start with a clean base */ + memset(cvq_elem, 0, sizeof(*cvq_elem)); + cvq_elem->vdpa =3D &s->vhost_vdpa; + + /* + * Linearize element. If guest had a descriptor chain, we expose the d= evice + * a single buffer. + */ + cvq_elem->out_len =3D out_size; + memcpy(out_cursor, &ctrl, sizeof(ctrl)); + out_size -=3D sizeof(ctrl); + out_cursor +=3D sizeof(ctrl); + iov_to_buf(out_sg, out_num, 0, out_cursor, out_size); + + cvq_elem->out_buf =3D vhost_vdpa_cvq_alloc_buf(v, cvq_elem->out_data, + out_size, false); + assert(cvq_elem->out_buf); + cvq_elem->in_buf =3D vhost_vdpa_cvq_alloc_buf(v, NULL, + sizeof(virtio_net_ctrl_ack= ), + true); + assert(cvq_elem->in_buf); + + cvq_elem->guest_elem =3D elem; + cvq_elem->ctrl =3D ctrl; + return g_steal_pointer(&cvq_elem); +} + +/** + * iov_size with an upper limit. It's assumed UINT64_MAX is an invalid + * iov_size. + */ +static uint64_t vhost_vdpa_net_iov_len(const struct iovec *iov, + unsigned int iov_cnt, size_t max) +{ + uint64_t len =3D 0; + + for (unsigned int i =3D 0; len < max && i < iov_cnt; i++) { + bool overflow =3D uadd64_overflow(iov[i].iov_len, len, &len); + if (unlikely(overflow)) { + return UINT64_MAX; + } + } + + return len; +} + +static CVQElement *vhost_vdpa_net_cvq_copy_elem(VhostVDPAState *s, + VirtQueueElement *elem) +{ + struct virtio_net_ctrl_hdr ctrl; + g_autofree struct iovec *iov =3D NULL; + struct iovec *iov2; + unsigned int out_num =3D elem->out_num; + size_t n, out_size =3D 0; + + /* TODO: in buffer MUST have only a single entry with a char? size */ + if (unlikely(vhost_vdpa_net_iov_len(elem->in_sg, elem->in_num, + sizeof(virtio_net_ctrl_ack)) + < sizeof(virtio_net_ctrl_ack= ))) { + return NULL; + } + + n =3D iov_to_buf(elem->out_sg, out_num, 0, &ctrl, sizeof(ctrl)); + if (unlikely(n !=3D sizeof(ctrl))) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid out size\n", __func__); + return NULL; + } + + iov =3D iov2 =3D g_memdup2(elem->out_sg, sizeof(struct iovec) * elem->= out_num); + iov_discard_front(&iov2, &out_num, sizeof(ctrl)); + switch (ctrl.class) { + case VIRTIO_NET_CTRL_MAC: + switch (ctrl.cmd) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + if (likely(vhost_vdpa_net_iov_len(iov2, out_num, 6))) { + out_size +=3D 6; + break; + } + + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mac size\n", __fun= c__); + return NULL; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mac cmd %u\n", + __func__, ctrl.cmd); + return NULL; + }; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid control class %u\n", + __func__, ctrl.class); + return NULL; + }; + + return vhost_vdpa_cvq_alloc_elem(s, ctrl, iov2, out_num, + sizeof(ctrl) + out_size, elem); +} + +/** + * Validate and copy control virtqueue commands. + * + * Following QEMU guidelines, we offer a copy of the buffers to the device= to + * prevent TOCTOU bugs. This functions check that the buffers length are + * expected too. + */ +static bool vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, + VirtQueueElement *guest_elem, + void *opaque) +{ + VhostVDPAState *s =3D opaque; + g_autoptr(CVQElement) cvq_elem =3D NULL; + g_autofree VirtQueueElement *elem =3D guest_elem; + size_t out_size, in_len; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + int r; + + cvq_elem =3D vhost_vdpa_net_cvq_copy_elem(s, elem); + if (unlikely(!cvq_elem)) { + goto err; + } + + /* out size validated at vhost_vdpa_net_cvq_copy_elem */ + out_size =3D iov_size(elem->out_sg, elem->out_num); + r =3D vhost_vdpa_net_cvq_svq_inject(svq, cvq_elem, out_size); + if (unlikely(r !=3D 0)) { + goto err; + } + + cvq_elem->guest_elem =3D g_steal_pointer(&elem); + /* Now CVQ elem belongs to SVQ */ + g_steal_pointer(&cvq_elem); + return true; + +err: + in_len =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, + sizeof(status)); + vhost_svq_push_elem(svq, elem, in_len); + return true; +} + +static VirtQueueElement *vhost_vdpa_net_handle_ctrl_detach(void *elem_opaq= ue) +{ + g_autoptr(CVQElement) cvq_elem =3D elem_opaque; + return g_steal_pointer(&cvq_elem->guest_elem); +} + +static void vhost_vdpa_net_handle_ctrl_used(VhostShadowVirtqueue *svq, + void *vq_elem_opaque, + uint32_t dev_written) +{ + g_autoptr(CVQElement) cvq_elem =3D vq_elem_opaque; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + const struct iovec out =3D { + .iov_base =3D cvq_elem->out_data, + .iov_len =3D cvq_elem->out_len, + }; + const DMAMap status_map_needle =3D { + .translated_addr =3D (hwaddr)(uintptr_t)cvq_elem->in_buf, + .size =3D sizeof(status), + }; + const DMAMap *in_map; + const struct iovec in =3D { + .iov_base =3D &status, + .iov_len =3D sizeof(status), + }; + g_autofree VirtQueueElement *guest_elem =3D NULL; + + if (unlikely(dev_written < sizeof(status))) { + error_report("Insufficient written data (%llu)", + (long long unsigned)dev_written); + goto out; + } + + in_map =3D vhost_iova_tree_find_iova(svq->iova_tree, &status_map_needl= e); + if (unlikely(!in_map)) { + error_report("Cannot locate out mapping"); + goto out; + } + + switch (cvq_elem->ctrl.class) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + break; + default: + error_report("Unexpected ctrl class %u", cvq_elem->ctrl.class); + goto out; + }; + + memcpy(&status, cvq_elem->in_buf, sizeof(status)); + if (status !=3D VIRTIO_NET_OK) { + goto out; + } + + status =3D VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, &out, 1); + if (status !=3D VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); + goto out; + } + +out: + guest_elem =3D g_steal_pointer(&cvq_elem->guest_elem); + if (guest_elem) { + iov_from_buf(guest_elem->in_sg, guest_elem->in_num, 0, &status, + sizeof(status)); + vhost_svq_push_elem(svq, guest_elem, sizeof(status)); + } +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { + .avail_handler =3D vhost_vdpa_net_handle_ctrl_avail, + .used_handler =3D vhost_vdpa_net_handle_ctrl_used, + .detach_handler =3D vhost_vdpa_net_handle_ctrl_detach, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -211,6 +580,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; + s->vhost_vdpa.shadow_vq_ops_opaque =3D s; + } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134454; cv=none; d=zohomail.com; s=zohoarc; b=Hm5/jLuiV1D4nllNBRISijREW4ylb5oeu/m28RLTVdyvafcx5dEwpOFVLp7K+jPe+FNggUAjPolWPvQFyd2YIwJi6oMDq38XP8tYhFLnaP8FFSaq6UaMV3wRQ44KzNIwqjVnAjS6qQnCPtP2oQ5qqKHXGNIrxOaV5Tk2Q5BD/UU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134454; 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=daEXiDWJK5Rl36PD+mqiBuzrx2naUodE57lDs3D7Kmc=; b=KPbXt06RDqHq4U0/0cgE7EajgOFwe9gOhT5vC57wBckyMmt0z92CEFvFitQkmwNkdXYnC20aDcAQ60Jpmn0tvcWEB9qfCC49toQyMsqjdF8ENgkQ1LqueKZCI2iFFfOvCNhLs9/mCdcXeixNI+/vFsiIxbaJZ/pdefgvBsubVA4= 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 1657134454588306.51394061109806; Wed, 6 Jul 2022 12:07:34 -0700 (PDT) Received: from localhost ([::1]:38084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AN3-0006zx-Ip for importer@patchew.org; Wed, 06 Jul 2022 15:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xq-0005bx-1F for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xk-0000vL-18 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:28 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-424-ETXzH_yQOoWxPM_WnYbw_Q-1; Wed, 06 Jul 2022 14:41:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8A1B185A7BA; Wed, 6 Jul 2022 18:41:13 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2561A1415116; Wed, 6 Jul 2022 18:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132878; 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=daEXiDWJK5Rl36PD+mqiBuzrx2naUodE57lDs3D7Kmc=; b=LH1rjifFEQneG0OpSFFgBo1BwLBx4Favs8UceKiaz4PYyU+CG9ZFltDk94mPmXQnUAVtQF q/N6AILNB+SRY/yxM4udOfsoDughK3QBmK6VEPiAQe/h9fxQpymm9tw6gjdP1CyN753jAy U9YQiqnLlvx1Dr1oUv/j5kopPRSpwF0= X-MC-Unique: ETXzH_yQOoWxPM_WnYbw_Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 21/23] vdpa: Add vhost_vdpa_start_control_svq Date: Wed, 6 Jul 2022 20:40:06 +0200 Message-Id: <20220706184008.1649478-22-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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: 1657134456612100001 As a first step we only enable CVQ first than others. Future patches add state restore. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e415cc8de5..77d013833f 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -370,6 +370,24 @@ static CVQElement *vhost_vdpa_cvq_alloc_elem(VhostVDPA= State *s, return g_steal_pointer(&cvq_elem); } =20 +static int vhost_vdpa_start_control_svq(VhostShadowVirtqueue *svq, + void *opaque) +{ + struct vhost_vring_state state =3D { + .index =3D virtio_get_queue_index(svq->vq), + .num =3D 1, + }; + VhostVDPAState *s =3D opaque; + struct vhost_dev *dev =3D s->vhost_vdpa.dev; + struct vhost_vdpa *v =3D dev->opaque; + int r; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + + r =3D ioctl(v->device_fd, VHOST_VDPA_SET_VRING_ENABLE, &state); + return r < 0 ? -errno : r; +} + /** * iov_size with an upper limit. It's assumed UINT64_MAX is an invalid * iov_size. @@ -554,6 +572,7 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq= _ops =3D { .avail_handler =3D vhost_vdpa_net_handle_ctrl_avail, .used_handler =3D vhost_vdpa_net_handle_ctrl_used, .detach_handler =3D vhost_vdpa_net_handle_ctrl_detach, + .start =3D vhost_vdpa_start_control_svq, }; =20 static NetClientState *net_vhost_vdpa_init(NetClientState *peer, --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134577; cv=none; d=zohomail.com; s=zohoarc; b=AVAOXzHWntZgbjM6XZn5FKB4fZzaCz1dtIvMIertCI8+rNTq6PF03ipxtfF4IG2FUA2Y4jZmOtYHBj8QN6VU7yM4Eul39u6wN3v1BDMe1W+76y+B6gNzmVwQUVW2pKZD8QWZxFJCKfwgUhBYSaTfPdcKdhdQpHnAXZKlUC0A+O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134577; 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=TA1ggoOdu7pdIK2Jv/6zj7iqgDenEJo5+cXiRpCBR7U=; b=QKJCgB6nQQVLeSAnIAPXNbjkurakITHSsor1+J3IWGGjTogoHKDC201k49rR7dQFgObx7wCRF1wiz6P+IBzNXdBaHotN7Qr5qzgAGEbdycem29X1ee6R8pidHswpQ7CHRg8mO1jiCx/SDURgqJ8HODrj85FATwT+UDPiTRdArn4= 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 1657134577501806.2307335244808; Wed, 6 Jul 2022 12:09:37 -0700 (PDT) Received: from localhost ([::1]:44720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9AP2-000390-59 for importer@patchew.org; Wed, 06 Jul 2022 15:09:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xt-0005dI-8q for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55087) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xh-0000vR-T9 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:32 -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-518-NKwkc4F2PlOV2EGfBBIUpw-1; Wed, 06 Jul 2022 14:41:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AFE7804196; Wed, 6 Jul 2022 18:41:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAFEE1415116; Wed, 6 Jul 2022 18:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132879; 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=TA1ggoOdu7pdIK2Jv/6zj7iqgDenEJo5+cXiRpCBR7U=; b=Uec1tHgSyGP/mNxB7bbql1w5EsRnzyt90EHF+QMqgav/4GLhHYUwE69jjBY9mEVAkNRLDh foDUw9ldDtjJ4Ezt79QvFnbo9fcqLBv2r6UZFn7etq1dUs4/0Ky2C3VGft6ETFezz1o2eo VLIIoOHd9VF8V8KDqEI69yK/mpUvVw0= X-MC-Unique: NKwkc4F2PlOV2EGfBBIUpw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 22/23] vdpa: Inject virtio-net mac address via CVQ at start Date: Wed, 6 Jul 2022 20:40:07 +0200 Message-Id: <20220706184008.1649478-23-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657134578268100001 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 --- net/vhost-vdpa.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 77d013833f..bb6ac7d96c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -380,12 +380,59 @@ static int vhost_vdpa_start_control_svq(VhostShadowVi= rtqueue *svq, VhostVDPAState *s =3D opaque; struct vhost_dev *dev =3D s->vhost_vdpa.dev; struct vhost_vdpa *v =3D dev->opaque; + VirtIONet *n =3D VIRTIO_NET(dev->vdev); + uint64_t features =3D dev->vdev->host_features; + size_t num =3D 0; int r; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); =20 r =3D ioctl(v->device_fd, VHOST_VDPA_SET_VRING_ENABLE, &state); - return r < 0 ? -errno : r; + if (unlikely(r < 0)) { + return -errno; + } + + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + CVQElement *cvq_elem; + 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), + }, + }; + + memcpy(mac, n->mac, sizeof(mac)); + cvq_elem =3D vhost_vdpa_cvq_alloc_elem(s, ctrl, out, ARRAY_SIZE(ou= t), + iov_size(out, ARRAY_SIZE(out)= ), + NULL); + assert(cvq_elem); + r =3D vhost_vdpa_net_cvq_svq_inject(svq, cvq_elem, + sizeof(ctrl) + sizeof(mac)); + if (unlikely(r)) { + assert(!"Need to test for pending buffers etc"); + return r; + } + num++; + } + + while (num) { + /* + * We can call vhost_svq_poll here because BQL protects calls to r= un. + */ + size_t used =3D vhost_svq_poll(svq); + assert(used <=3D num); + num -=3D used; + } + + return 0; } =20 /** --=20 2.31.1 From nobody Sun Feb 8 14:59:27 2026 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=1657134354; cv=none; d=zohomail.com; s=zohoarc; b=hDahur3K+vB64XFuxKCrmL/SH+jWa1OKOxTlTQf8Loq2G3c71VGhZ6A3mIiniH7YIGBMeYDJfPEPw8XT9hfyvCUiXGAnkx9/TYy4lDEvgsP0SKSFiok5LWg+/6OQMHCIgOP3C7KzpDQ7eutZrjg/h0Pbbo91hHPiM3nIs/xJAS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657134354; 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=BtJZn7b4co1MW7/rkvX94ipbrIMLQU0n5KUJLlLQzxE=; b=EKudD1qjS3Df1mTyxyQRXSnTnhig1QM6gEZMq3AxYaD3Mv+tDONynQ4k0TxzqJ9+lIzQPNVUod89bPoFUTdr2xt3ue5RNgVsSFh5kG1MXfobSPrM4zddT9ofuj5OAxJOLMp/ED0ddys4dudSbgAQoIcUAt25xi9gbue8vNhGCVQ= 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 1657134354956256.65150228426046; Wed, 6 Jul 2022 12:05:54 -0700 (PDT) Received: from localhost ([::1]:36022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9ALR-0005ar-3z for importer@patchew.org; Wed, 06 Jul 2022 15:05:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99yF-0005lK-I0 for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o99xn-0000vp-Pl for qemu-devel@nongnu.org; Wed, 06 Jul 2022 14:41:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-rX_840pxOeaEhPYUOygVzw-1; Wed, 06 Jul 2022 14:41:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82BC48001EA; Wed, 6 Jul 2022 18:41:19 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCE45141511D; Wed, 6 Jul 2022 18:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657132881; 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=BtJZn7b4co1MW7/rkvX94ipbrIMLQU0n5KUJLlLQzxE=; b=eJrw7d+vZYB4D00K/BaAOheKyuaXXho8J74xQrmT5LZ/XcH+pCRKr+MXD6JD+GQNhiIEm8 ZbZf//uMzHYD+LzQLT28rrLi1rcPHatlewDS1UgMr8XY59IxSvolh1TME2H+J/j+XO2T8L Aillt1bLqZ913T9fMZYwCfEksDz60qc= X-MC-Unique: rX_840pxOeaEhPYUOygVzw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Markus Armbruster , Harpreet Singh Anand , Eric Blake , Laurent Vivier , Parav Pandit , Cornelia Huck , Paolo Bonzini , Gautam Dawar , Eli Cohen , "Gonglei (Arei)" , Zhu Lingshan , "Michael S. Tsirkin" , Cindy Lu , Jason Wang Subject: [RFC PATCH v9 23/23] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Wed, 6 Jul 2022 20:40:08 +0200 Message-Id: <20220706184008.1649478-24-eperezma@redhat.com> In-Reply-To: <20220706184008.1649478-1-eperezma@redhat.com> References: <20220706184008.1649478-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.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657134355939100001 Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Markus Armbruster --- qapi/net.json | 9 +++++- net/vhost-vdpa.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 9af11e9a3b..75ba2cb989 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -445,12 +445,19 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1) +# (default: false) +# +# Features: +# @unstable: Member @x-svq is experimental. +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetdevVmnetHostOptions: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index bb6ac7d96c..3f10636e05 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -93,6 +93,30 @@ const int vdpa_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +/** Supported device specific feature bits with SVQ */ +static const uint64_t vdpa_svq_device_features =3D + BIT_ULL(VIRTIO_NET_F_CSUM) | + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | + BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | + BIT_ULL(VIRTIO_NET_F_MTU) | + BIT_ULL(VIRTIO_NET_F_MAC) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | + BIT_ULL(VIRTIO_NET_F_STATUS) | + BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_NET_F_MQ) | + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | + BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | + BIT_ULL(VIRTIO_NET_F_RSC_EXT) | + BIT_ULL(VIRTIO_NET_F_STANDBY); + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -151,7 +175,11 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev =3D &s->vhost_net->dev; =20 + if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + } if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -454,6 +482,14 @@ static uint64_t vhost_vdpa_net_iov_len(const struct io= vec *iov, return len; } =20 +static int vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_ra= nge) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + return ret < 0 ? -errno : 0; +} + static CVQElement *vhost_vdpa_net_cvq_copy_elem(VhostVDPAState *s, VirtQueueElement *elem) { @@ -628,7 +664,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, int vdpa_device_fd, int queue_pair_index, int nvqs, - bool is_datapath) + bool is_datapath, + bool svq, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -646,6 +684,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_tree =3D iova_tree; if (!is_datapath) { s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; @@ -708,6 +748,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; + g_autoptr(VhostIOVATree) iova_tree =3D NULL; NetClientState *nc; int queue_pairs, r, i, has_cvq =3D 0; =20 @@ -735,22 +776,45 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } =20 + if (opts->x_svq) { + struct vhost_vdpa_iova_range iova_range; + + uint64_t invalid_dev_features =3D + features & ~vdpa_svq_device_features & + /* Transport are all accepted at this point */ + ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_S= TART); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, + invalid_dev_features); + goto err_svq; + } + + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); + } + ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, opts->x_s= vq, + iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false); + vdpa_device_fd, i, 1, false, + opts->x_svq, iova_tree); if (!nc) goto err; } =20 + /* iova_tree ownership belongs to last NetClientState */ + g_steal_pointer(&iova_tree); return 0; =20 err: @@ -759,6 +823,8 @@ err: qemu_del_net_client(ncs[i]); } } + +err_svq: qemu_close(vdpa_device_fd); =20 return -1; --=20 2.31.1