From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95EFA455FE; Thu, 11 Jul 2024 17:03:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 70F91402D6; Thu, 11 Jul 2024 17:03:00 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E5C65402D1 for ; Thu, 11 Jul 2024 17:02:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720710178; 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=hinmL+jHyyU13d8imdNQkHiLZSI9gQeZ26880pVRNcE=; b=IOays2pRB4vQuCdNxLhIXmY8R5Y+vjX2aWnShI4Ih8BIyYQProGYPLi0wb2sLzd6AM41S2 Z9CQrvphibyq0Aq2ZOzhYCUFb48eFgb4uEsG2t7fAjyQUYWnLSIiGfR4KuszPAlGjxXfAG T57OZPZomr+kmnPuHDy3X9yZgVlewU0= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-536-mBNv1YX4Nficgt7rY79TFg-1; Thu, 11 Jul 2024 11:02:57 -0400 X-MC-Unique: mBNv1YX4Nficgt7rY79TFg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ee8e904f01so11094741fa.1 for ; Thu, 11 Jul 2024 08:02:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720710175; x=1721314975; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hinmL+jHyyU13d8imdNQkHiLZSI9gQeZ26880pVRNcE=; b=KMPT5zCKECMWSBP2Qm6WDjvhezn34QRY1plJpcX1nntZr3Ad4fBgH0GvRCT2YefywY FRIr28qNeDQuMr9HokfPB4MGbI+yBgd2Y65A/0XPDeTjYFszxt+LXsiECHaSKCUndZUU 0Z2y9NeTKFMZdnlGpigSw4M0l4uIYmCE2NNl0ETGKOVqeRdRpFzHKyyOtdxYNCcWaH79 B3o4V34E/STGlsO0nbEou6skufebPepmExvg925yA6a21RejeqYjCtSszAoT4B1ep4ev yFXhJh2cGo12AZLM3atxoVIhEnQViz903aMSr6h1ldax3kGUOlIlMZMD3EgYA3a+ainQ WAxA== X-Gm-Message-State: AOJu0YyDexL6MKz3wBytO2l1gSAkMCKVlHPGstrrxpfGKim5r9gIFjF9 IaKBLCAPgpMCu3OO85GMsb4j7ytLxa9fE9sNbdOiO502m4AjOiA/r5GA2VzJ39fcmAoxZYaU/fp w4ZL5Eq83beBCuD3uu548UM1tvu1Vgt2wf8SjpMha/YA7oKohkFIoSH1X1dc+tE50gysctICwFs ifPaPdTrcfdB+Kico= X-Received: by 2002:a2e:9bd5:0:b0:2ee:5969:e454 with SMTP id 38308e7fff4ca-2eeb30bba80mr52637711fa.1.1720710175458; Thu, 11 Jul 2024 08:02:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKElUzQdBhZ3pAbPgaOwgFkKxTGodzSGrnR/oMfVbWQ+5/Jex4l/xbJcNMfcRd+7+7umsPv2DK0hqD19aYPIY= X-Received: by 2002:a2e:9bd5:0:b0:2ee:5969:e454 with SMTP id 38308e7fff4ca-2eeb30bba80mr52637501fa.1.1720710175011; Thu, 11 Jul 2024 08:02:55 -0700 (PDT) MIME-Version: 1.0 References: <20240711124436.2383232-1-schalla@marvell.com> In-Reply-To: <20240711124436.2383232-1-schalla@marvell.com> From: David Marchand Date: Thu, 11 Jul 2024 17:02:43 +0200 Message-ID: Subject: Re: [PATCH v2] net/virtio_user: fix issue with converting cq descriptor IOVA address to VA To: Srujana Challa Cc: dev@dpdk.org, maxime.coquelin@redhat.com, chenbox@nvidia.com, jerinj@marvell.com, ndabilpuram@marvell.com, vattunuru@marvell.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, Jul 11, 2024 at 2:44=E2=80=AFPM Srujana Challa wrote: > > This patch modifies the code to convert descriptor buffer IOVA > addresses to virtual addresses only when use_va flag is false. > > This patch resolves a segmentation fault with the vhost-user backend > that occurs during the processing of the shadow control queue. > > 'Fixes: 67e9e504dae2 ("net/virtio_user: convert cq descriptor IOVA > address to Virtual address")' No single quote around the Fixes: tag, and on a single line please. As for the title, how about: "net/virtio_user: fix cq descriptor conversion with non vDPA backend" ? > > Reported-by: David Marchand > Signed-off-by: Srujana Challa > --- > v2: > - Added Reported-by tag. > > .../net/virtio/virtio_user/virtio_user_dev.c | 28 +++++++++++-------- > 1 file changed, 16 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/n= et/virtio/virtio_user/virtio_user_dev.c > index fed66d2ae9..94e0ddcb94 100644 > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c > @@ -905,12 +905,12 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, = uint16_t q_pairs) > #define CVQ_MAX_DATA_DESCS 32 > > static inline void * > -virtio_user_iova2virt(rte_iova_t iova) > +virtio_user_iova2virt(rte_iova_t iova, bool use_va) All the code in this file passes the virtio_user_dev object, please keep this convention. IOW: -virtio_user_iova2virt(rte_iova_t iova) +virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova) > { > - if (rte_eal_iova_mode() =3D=3D RTE_IOVA_VA) > - return (void *)(uintptr_t)iova; > - else > + if (rte_eal_iova_mode() =3D=3D RTE_IOVA_PA && !use_va) > return rte_mem_iova2virt(iova); > + else > + return (void *)(uintptr_t)iova; Why do we need to invert this test? I would make the change as simple as: - if (rte_eal_iova_mode() =3D=3D RTE_IOVA_VA) + if (rte_eal_iova_mode() =3D=3D RTE_IOVA_VA || dev->hw.use_va) > } > > static uint32_t > @@ -922,6 +922,7 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_= dev *dev, struct vring *vri > uint16_t i, idx_data, idx_status; > uint32_t n_descs =3D 0; > int dlen[CVQ_MAX_DATA_DESCS], nb_dlen =3D 0; > + bool use_va =3D dev->hw.use_va; > > /* locate desc for header, data, and status */ > idx_data =3D vring->desc[idx_hdr].next; > @@ -938,18 +939,18 @@ virtio_user_handle_ctrl_msg_split(struct virtio_use= r_dev *dev, struct vring *vri > idx_status =3D i; > n_descs++; > > - hdr =3D virtio_user_iova2virt(vring->desc[idx_hdr].addr); > + hdr =3D virtio_user_iova2virt(vring->desc[idx_hdr].addr, use_va); > if (hdr->class =3D=3D VIRTIO_NET_CTRL_MQ && > hdr->cmd =3D=3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { > uint16_t queues, *addr; > > - addr =3D virtio_user_iova2virt(vring->desc[idx_data].addr= ); > + addr =3D virtio_user_iova2virt(vring->desc[idx_data].addr= , use_va); > queues =3D *addr; > status =3D virtio_user_handle_mq(dev, queues); > } else if (hdr->class =3D=3D VIRTIO_NET_CTRL_MQ && hdr->cmd =3D= =3D VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { > struct virtio_net_ctrl_rss *rss; > > - rss =3D virtio_user_iova2virt(vring->desc[idx_data].addr)= ; > + rss =3D virtio_user_iova2virt(vring->desc[idx_data].addr,= use_va); > status =3D virtio_user_handle_mq(dev, rss->max_tx_vq); > } else if (hdr->class =3D=3D VIRTIO_NET_CTRL_RX || > hdr->class =3D=3D VIRTIO_NET_CTRL_MAC || > @@ -962,7 +963,8 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_= dev *dev, struct vring *vri > (struct virtio_pmd_ctrl *)hdr, dlen, nb_d= len); > > /* Update status */ > - *(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring->desc[idx_sta= tus].addr) =3D status; > + *(virtio_net_ctrl_ack *) > + virtio_user_iova2virt(vring->desc[idx_status].addr, use_v= a) =3D status; Afaics, no need for reindenting. > > return n_descs; > } > @@ -987,6 +989,7 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_user= _dev *dev, > /* initialize to one, header is first */ > uint32_t n_descs =3D 1; > int dlen[CVQ_MAX_DATA_DESCS], nb_dlen =3D 0; > + bool use_va =3D dev->hw.use_va; > > /* locate desc for header, data, and status */ > idx_data =3D idx_hdr + 1; > @@ -1004,18 +1007,18 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_= user_dev *dev, > n_descs++; > } > > - hdr =3D virtio_user_iova2virt(vring->desc[idx_hdr].addr); > + hdr =3D virtio_user_iova2virt(vring->desc[idx_hdr].addr, use_va); > if (hdr->class =3D=3D VIRTIO_NET_CTRL_MQ && > hdr->cmd =3D=3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { > uint16_t queues, *addr; > > - addr =3D virtio_user_iova2virt(vring->desc[idx_data].addr= ); > + addr =3D virtio_user_iova2virt(vring->desc[idx_data].addr= , use_va); > queues =3D *addr; > status =3D virtio_user_handle_mq(dev, queues); > } else if (hdr->class =3D=3D VIRTIO_NET_CTRL_MQ && hdr->cmd =3D= =3D VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { > struct virtio_net_ctrl_rss *rss; > > - rss =3D virtio_user_iova2virt(vring->desc[idx_data].addr)= ; > + rss =3D virtio_user_iova2virt(vring->desc[idx_data].addr,= use_va); > status =3D virtio_user_handle_mq(dev, rss->max_tx_vq); > } else if (hdr->class =3D=3D VIRTIO_NET_CTRL_RX || > hdr->class =3D=3D VIRTIO_NET_CTRL_MAC || > @@ -1028,7 +1031,8 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_us= er_dev *dev, > (struct virtio_pmd_ctrl *)hdr, dlen, nb_d= len); > > /* Update status */ > - *(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring->desc[idx_sta= tus].addr) =3D status; > + *(virtio_net_ctrl_ack *) > + virtio_user_iova2virt(vring->desc[idx_status].addr, use_v= a) =3D status; Idem, no reindenting. > > /* Update used descriptor */ > vring->desc[idx_hdr].id =3D vring->desc[idx_status].id; > -- > 2.25.1 > --=20 David Marchand