From nobody Wed Nov 27 16:40:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1697739718; cv=none; d=zohomail.com; s=zohoarc; b=J7MByn65O+VSHOxoL0UixHGYNLdBzw1IXvdrh5wJKF7OXdZX6FFirgMC0yy2UHEZqqHd9/U81E3FqWZfauO/7FTwOq/elFceM3sYdKlL2Iya94fait80aTaYv70/BLfByVGfrtifVcttEiNGcpMnRewnpzuOGDHQ7OlDxlP4F88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697739718; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Aub/+wNbCvirFXr2bctIYe5dvlzn9T6vBOGQpLtPcEM=; b=k592OtyEaZpCs0LPfn5xtRP7oB0RLQm36l3LMz7B4fzzBT+cIpg0ixnDf5kxxy5ZSWkzAGGQo7RE8exiaTbwyhEDicr2RJzpmpN8mPGb1wseLKfMJ352h7PtADZI0PeXJoN9D6Ore0Fq/AaTTUwgtUexxsyT9YeUu2IhkTcHknA= 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 16977397182561002.7860753288791; Thu, 19 Oct 2023 11:21:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtXeF-0005dd-Rq; Thu, 19 Oct 2023 14:21:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtXeB-0005dP-PM for qemu-devel@nongnu.org; Thu, 19 Oct 2023 14:21:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtXe7-0000bF-AA for qemu-devel@nongnu.org; Thu, 19 Oct 2023 14:21:25 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-SPRyGp9GMLKYjbc4UMKl8A-1; Thu, 19 Oct 2023 14:21:19 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4077ee09a4eso34067755e9.1 for ; Thu, 19 Oct 2023 11:21:19 -0700 (PDT) Received: from redhat.com ([2a06:c701:73d2:bf00:e379:826:5137:6b23]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c231100b00401d8181f8bsm4998280wmo.25.2023.10.19.11.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 11:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697739681; 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=Aub/+wNbCvirFXr2bctIYe5dvlzn9T6vBOGQpLtPcEM=; b=AUglXx7ptvC4tCnPiRzh+/BZGJNwMEVWjjL9N8a8wGxgYQA0dKfur0+/SATonPRRZDxqLy kyBgKEZsSVSlPolZJOyRUei+z1LMJ6ghA9LW7E99ScbaHCFIonnKE36L8uEirtm7+LqTOR hKPlUle6TOfCtBMSmcAHsYSyAuTgvo8= X-MC-Unique: SPRyGp9GMLKYjbc4UMKl8A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697739677; x=1698344477; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Aub/+wNbCvirFXr2bctIYe5dvlzn9T6vBOGQpLtPcEM=; b=m+ZIuMfE7YIKIPJQIcwVmIpaprmK+UFVVUYgYJvsRS4dK3lvu8l4iC9ODlT6NIlZPW uNYkVVSrRa2C37oCOJx2fEyQ6usAiGp8+p6HImtsp5/zcJ8osYABAQUuSD7SqWw5W6Z9 LxyfXtCtsTmm+Izk8hIpThm7WhT/1XMvWy4QRLkcDa1OyOoz27A2gZLnNk5f9ULqOIxb Yep49nZe1FGxgTAjsX5h/Xl1OompUvG80z9oGBARWF+eioDwI4wNPCCoAkYVAKUEAFTZ 6xDxihQU+vF095gR/7lXaRl7vPB3Ld9o1vk6rj61N8pSqJp+Mq0D9X4mYwAHG6lt2VD6 l1yg== X-Gm-Message-State: AOJu0Yx6WOtZyhND6OWKjGrcP22UKW99SS0HGzmZtqgAAYdzK059QmOq L8RScqdXM/dzw4exxWm17EYe/ih5dhkU7ezYDLTRibQZ5+ID8x2Jl1uBUxHBFW9BwHgzUs5iQNv haJBLWcg5M1+FQlh4wnzFHFwh4RKFrHJ+qMKIskvvBtugSeLsRamasLl5zQe3jUGcFv2/ X-Received: by 2002:a05:600c:5118:b0:408:3739:68fd with SMTP id o24-20020a05600c511800b00408373968fdmr2441970wms.6.1697739677580; Thu, 19 Oct 2023 11:21:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG/z9puFej3FZip3+tMBYgrzCuXmm++0m+wOTRhpXNpZuZ4sLbLkWxWsSzVPWexcwr2/gKsA== X-Received: by 2002:a05:600c:5118:b0:408:3739:68fd with SMTP id o24-20020a05600c511800b00408373968fdmr2441953wms.6.1697739677127; Thu, 19 Oct 2023 11:21:17 -0700 (PDT) Date: Thu, 19 Oct 2023 14:21:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Hawkins Jiawei , Eugenio =?utf-8?B?UMOpcmV6?= , Jason Wang Subject: [PULL v2 01/78] vdpa: Use iovec for vhost_vdpa_net_cvq_add() Message-ID: <0e6bff0d43bf04c6e7a16c2775879816ca056b3d.1697739629.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697739720528100006 From: Hawkins Jiawei Next patches in this series will no longer perform an immediate poll and check of the device's used buffers for each CVQ state load command. Consequently, there will be multiple pending buffers in the shadow VirtQueue, making it a must for every control command to have its own buffer. To achieve this, this patch refactor vhost_vdpa_net_cvq_add() to accept `struct iovec`, which eliminates the coupling of control commands to `s->cvq_cmd_out_buffer` and `s->status`, allowing them to use their own buffer. Signed-off-by: Hawkins Jiawei Acked-by: Eugenio P=C3=A9rez Message-Id: <8a328f146fb043f34edb75ba6d043d2d6de88f99.1697165821.git.yin311= 49@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 939c984d5b..618758596a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -618,22 +618,14 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *n= c) vhost_vdpa_net_client_stop(nc); } =20 -static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, - size_t in_len) +static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, + const struct iovec *out_sg, size_t out= _num, + const struct iovec *in_sg, size_t in_n= um) { - /* Buffers for the device */ - const struct iovec out =3D { - .iov_base =3D s->cvq_cmd_out_buffer, - .iov_len =3D out_len, - }; - const struct iovec in =3D { - .iov_base =3D s->status, - .iov_len =3D sizeof(virtio_net_ctrl_ack), - }; VhostShadowVirtqueue *svq =3D g_ptr_array_index(s->vhost_vdpa.shadow_v= qs, 0); int r; =20 - r =3D vhost_svq_add(svq, &out, 1, &in, 1, NULL); + r =3D vhost_svq_add(svq, out_sg, out_num, in_sg, in_num, NULL); if (unlikely(r !=3D 0)) { if (unlikely(r =3D=3D -ENOSPC)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", @@ -659,6 +651,15 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState = *s, uint8_t class, .cmd =3D cmd, }; size_t data_size =3D iov_size(data_sg, data_num); + /* Buffers for the device */ + const struct iovec out =3D { + .iov_base =3D s->cvq_cmd_out_buffer, + .iov_len =3D sizeof(ctrl) + data_size, + }; + const struct iovec in =3D { + .iov_base =3D s->status, + .iov_len =3D sizeof(*s->status), + }; =20 assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl)); =20 @@ -669,8 +670,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *= s, uint8_t class, iov_to_buf(data_sg, data_num, 0, s->cvq_cmd_out_buffer + sizeof(ctrl), data_size); =20 - return vhost_vdpa_net_cvq_add(s, data_size + sizeof(ctrl), - sizeof(virtio_net_ctrl_ack)); + return vhost_vdpa_net_cvq_add(s, &out, 1, &in, 1); } =20 static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) @@ -1248,10 +1248,15 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostSh= adowVirtqueue *svq, .iov_base =3D s->cvq_cmd_out_buffer, }; /* in buffer used for device model */ - const struct iovec in =3D { + const struct iovec model_in =3D { .iov_base =3D &status, .iov_len =3D sizeof(status), }; + /* in buffer used for vdpa device */ + const struct iovec vdpa_in =3D { + .iov_base =3D s->status, + .iov_len =3D sizeof(*s->status), + }; ssize_t dev_written =3D -EINVAL; =20 out.iov_len =3D iov_to_buf(elem->out_sg, elem->out_num, 0, @@ -1285,7 +1290,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, goto out; } } else { - dev_written =3D vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(stat= us)); + dev_written =3D vhost_vdpa_net_cvq_add(s, &out, 1, &vdpa_in, 1); if (unlikely(dev_written < 0)) { goto out; } @@ -1301,7 +1306,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShad= owVirtqueue *svq, } =20 status =3D VIRTIO_NET_ERR; - virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, &out, 1); + virtio_net_handle_ctrl_iov(svq->vdev, &model_in, 1, &out, 1); if (status !=3D VIRTIO_NET_OK) { error_report("Bad CVQ processing in model"); } --=20 MST