From nobody Wed Nov 27 18:32:30 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=1697966535; cv=none; d=zohomail.com; s=zohoarc; b=etH179RqOsrqrn+VXeqYJBMYRNIY1sFoZ+Uw+pDVio3O2xaNIIKWW+sOEhSCv+CMK+qdP4A57j1sd/HucHOkorhc43uirlkpNnComWwAdIFYNw6+eXskwF930QEQCiC+B5Z6Sy4Cj0HGZz/PkkNNLPSIGV/bLN7b4Wvt6f6bZ/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697966535; 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=SRPeyqeQGsMjdw9AWjqyEcNcLqfcModaYX6iwGiSMT4TBpW5vl2O7HEy+4Y+HnxwgI0DNxV9ddNalpeVG923gdlq6EPL69XboKmkPMkXZqWmFqgR1X4P1YD2KwJcU2Ktx23rAtcIYckCNdtoF0LHJqcO8k5iLCpu1Qdl00wFU6A= 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 1697966535556592.1455190670198; Sun, 22 Oct 2023 02:22:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quUeu-0008JW-O6; Sun, 22 Oct 2023 05:22:08 -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 1quUet-0008JI-8u for qemu-devel@nongnu.org; Sun, 22 Oct 2023 05:22:07 -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 1quUer-00008a-LV for qemu-devel@nongnu.org; Sun, 22 Oct 2023 05:22:07 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-t05i7cn4NySz8bAsS_6CRA-1; Sun, 22 Oct 2023 05:22:02 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-32da7983d20so1125556f8f.1 for ; Sun, 22 Oct 2023 02:22:02 -0700 (PDT) Received: from redhat.com ([2.52.1.53]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c314e00b003fbe4cecc3bsm11347444wmo.16.2023.10.22.02.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 02:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697966525; 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=VIHeir8tG6TuvSJBaCqyiCiF8aZV5xWyUO4BZVA/QnHKe20cUzah5yxrb9Srwx47MS66AD TdKTXP+YaCNiGzKyK6zCePJV9yYkrUBpdj9tY57TOv5b7EgyAWN8v5GgDhc54vKzKceCca 9wUbuZxaWQ/Bw0NdnG8DBWPkDqSlV8c= X-MC-Unique: t05i7cn4NySz8bAsS_6CRA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697966521; x=1698571321; 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=QoTe5KpkUcrevt7dD2NtPjoVv8g7AEI3Uf9qMPGRmFcgH2zAaesZuR5J8tAsASYLmi 9q/TizOLrbb4eSXvqKDwd50iv/Y1gEL5xmSw62tOjQmu62zJDBjxMXHsE8uYFYTEEnEi vWwSmjE84UDcojZta+JDuy6nYok35nB3eXdMxKrnxQO1vvybA4YaJ+9HqcaEKJs5e9gZ PLClL63+AcG3ZvSaw4BFSaizq9Dbv3TROAUc8leLtZHwjEyaU3JLYIECEzVZppsyhrc/ hbgyfrESG9MoChd7VXPqsggidTSTeh/L/cdz/U5hINyUTUl8CwSPNoeOvbi8LJXoEgX/ klyw== X-Gm-Message-State: AOJu0YwAhStgfLgHEx1MBoENP+Nnlpky426priOV5bLW23uLzIMdwAG1 x5+xrRz2CX7cUfVdgK61VG8s9IgIGjIFthQK9CluCK2ekG59aFBrkMfMKJLefICfnnUpbp7jNAs c4kty7EonsOeJSgMq1IwzamYv/AW2InVjyxlGwQcO5QW/uQ/MTmL/QAZN56UdcJywDobn X-Received: by 2002:adf:8bdc:0:b0:32d:c65c:933d with SMTP id w28-20020adf8bdc000000b0032dc65c933dmr9189791wra.7.1697966521415; Sun, 22 Oct 2023 02:22:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2FarCuUHy/PgJ/lhuXoMVSSZzENKAaM2sMEdmQswTpaeUd9OaCk/W1BUqd3QiMffKGxBrsQ== X-Received: by 2002:adf:8bdc:0:b0:32d:c65c:933d with SMTP id w28-20020adf8bdc000000b0032dc65c933dmr9189776wra.7.1697966521135; Sun, 22 Oct 2023 02:22:01 -0700 (PDT) Date: Sun, 22 Oct 2023 05:21:58 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Hawkins Jiawei , Eugenio =?utf-8?B?UMOpcmV6?= , Jason Wang Subject: [PULL v3 01/62] vdpa: Use iovec for vhost_vdpa_net_cvq_add() Message-ID: <0e6bff0d43bf04c6e7a16c2775879816ca056b3d.1697966402.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: 1697966536213100003 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