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 B2363A034C; Wed, 31 Aug 2022 10:41:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 544FC40F17; Wed, 31 Aug 2022 10:41:17 +0200 (CEST) Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by mails.dpdk.org (Postfix) with ESMTP id 7106540395 for ; Wed, 31 Aug 2022 10:41:15 +0200 (CEST) Received: by mail-lj1-f171.google.com with SMTP id k18so7470720lji.13 for ; Wed, 31 Aug 2022 01:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netgate.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=hKTTnwbT1YbwFBhhyGzrXGONBuvVuwN/OGVhulOEQjc=; b=QgGYJ1X8xqL7xhOGOFZNsMW8e0210LLWnUQq9oJQNp1a5btAVht3iA/kF5cBBPL8aT 7gSeZwiZadfMBZolJcb8BlHpo9+XL1EUHosvyBf1N+fj0mI5gps4/p3j/eDn2Omaeohn Lfj6pjv427UeVLNYR4hiUZGW0RHPIwiWG777Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=hKTTnwbT1YbwFBhhyGzrXGONBuvVuwN/OGVhulOEQjc=; b=Vn9vEjq5uAef2A8m/K1I9a5fRMD9KFsgLg/Udjtu4jXtY3sfC2XGDjYIg9fA1/kfVC 6Z/VcQsRRGHDtuWMqk2Qf2Y8FmV1veJTTID1J2I4e2VCtxLWbTD+yZImyPGCcMS+VKI/ IvaSpLhD0fq5Gwt0i1F0yYvscFlyhJW2BoG3SoXICuu6mRGnG85LV/gOFipLeTXDKqwz VOCplbLlEcjNRaVf/mP8VlAj+w/L5vVKy0PGq7cSvkFzlne1fsdbGhv2VTGQpqHmTTcE nQabcaoo9aPb+5wKep0qS29UjqyhcOfbO/S29LB2a8iN9EaxZCf9uSMiqe7AjdpTT5MJ pd0A== X-Gm-Message-State: ACgBeo3PfKfTtjG3/lsMXtZHlUbxL3Tvq6uDbcXlGbltO5uyVPG1watS JTu9poqVKloLWO6awcQHQUuIGw== X-Google-Smtp-Source: AA6agR67ojAn1FvJrwLU6qDmt8p8f4ENnTrCBB5nnVYgNOjeuzRio9BxygbacBxhQR7zgH5xvp9YXA== X-Received: by 2002:a05:651c:1146:b0:261:d36a:7ff8 with SMTP id h6-20020a05651c114600b00261d36a7ff8mr8495867ljo.363.1661935274917; Wed, 31 Aug 2022 01:41:14 -0700 (PDT) Received: from Aspire-VN7-571G.ad.sperasoft.com ([178.155.6.52]) by smtp.gmail.com with ESMTPSA id v9-20020a056512348900b0049482979fe0sm381369lfr.179.2022.08.31.01.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 01:41:14 -0700 (PDT) From: Alexander Chernavin To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, Alexander Chernavin Subject: [PATCH] net/virtio: fix crash when dev is configured twice Date: Wed, 31 Aug 2022 11:40:59 +0300 Message-Id: <20220831084059.43918-1-achernavin@netgate.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 When first attempt to configure a device with RX interrupt enabled fails for some reason (e.g. because "Multiple intr vector not supported"), second attempt to configure the device with RX interrupt disabled and feature set unchanged will succeed but will leave virtio queues not allocated. Accessing the queues will cause a segfault. First attempt: - virtio_dev_configure() - virtio_init_device() is called to reinit the device because "dev->data->dev_conf.intr_conf.rxq" is "1" - virtio_configure_intr() fails and returns an error - virtio_free_queues() frees previously allocated virtio queues - virtio_init_device() fails and returns an error - virtio_dev_configure() fails and returns an error Second attempt: - virtio_dev_configure() - This time virtio_init_device() is not called, virtio queues are not allocated With this fix, reinit the device during configuration if virtio queues are not allocated. Signed-off-by: Alexander Chernavin --- drivers/net/virtio/virtio_ethdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index d180162abd..38bfe050b5 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -2616,6 +2616,13 @@ virtio_dev_configure(struct rte_eth_dev *dev) return ret; } + /* if queues are not allocated, reinit the device */ + if (hw->vqs == NULL) { + ret = virtio_init_device(dev, hw->req_guest_features); + if (ret < 0) + return ret; + } + if ((rxmode->mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) && !virtio_with_feature(hw, VIRTIO_NET_F_RSS)) { PMD_DRV_LOG(ERR, "RSS support requested but not supported by the device"); -- 2.25.1