From patchwork Wed Aug 31 08:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Chernavin X-Patchwork-Id: 115691 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 29C29A034C; Wed, 31 Aug 2022 10:54:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBB3840F17; Wed, 31 Aug 2022 10:54:00 +0200 (CEST) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by mails.dpdk.org (Postfix) with ESMTP id C593240395 for ; Wed, 31 Aug 2022 10:53:58 +0200 (CEST) Received: by mail-lf1-f52.google.com with SMTP id p7so7854005lfu.3 for ; Wed, 31 Aug 2022 01:53:58 -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=QB/tMONCxwTAY2hTX/y94xl/pGJUBctbBQOtk0ocjKrboRktQB1jV2ue71PVKwYpQq Wu395kT6KpCTY9PCY9HBbDnYVJmbszJpU3UpcKXsdcejla2wJp5p+sY1ykb3P7XF0f7w c3nbRxAS96JLDy5rwjU9K/u0oHClwf0BC3IWU= 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=DVZG0fmpzhBMUPBsm/59U7dbOGKhhAqEfgISV0M18Zvpft91Fzr9UJZDXcwROGJtpV S4hWkqPj4ev0GFhhM1URNfl9qdqxqva524Saz7+KoXX0NEShqsevV8CrWb2Ve1xHaJ/c YCRuWJO9HWJ3MtfNJouVe/ArHvfw065zOAguQg2u3bedA8tLmdHiRWDQOpxPRdn3X2qC ZItQRICcPydlnHqAtKSnqg5rs9es4kkO1kutUJUPMCSx4Qx/zE9MjymJRMOX5CHqfCdE +OQAawGayILIoa9wGduaZf4N5FzgrIPltecsoH4er098QfXS8tJtUdCLjuxD77XBby8r mTPA== X-Gm-Message-State: ACgBeo2C8K5IN0Ks+ixb5dCpIybkFU8yK4Xun6K38srqDb61nAoYlnNw NHTQhk7OibIM7acEooa9Es9f/A== X-Google-Smtp-Source: AA6agR66xsxxWgib53BhintQ0grsLnpEAlVWf/QaTEdAmwbDlOMH9di+HlEU5xbH98talPdwZw9CHQ== X-Received: by 2002:ac2:4144:0:b0:492:eb38:d8e9 with SMTP id c4-20020ac24144000000b00492eb38d8e9mr9873050lfi.215.1661936038209; Wed, 31 Aug 2022 01:53:58 -0700 (PDT) Received: from Aspire-VN7-571G.ad.sperasoft.com ([178.155.6.52]) by smtp.gmail.com with ESMTPSA id t2-20020a056512068200b00492e3a8366esm1921560lfe.9.2022.08.31.01.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 01:53:57 -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:53:44 +0300 Message-Id: <20220831085344.47995-1-achernavin@netgate.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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");