From patchwork Tue Sep 27 10:15:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Chernavin X-Patchwork-Id: 116969 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 B87A0A00C2; Tue, 27 Sep 2022 12:15:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4543541143; Tue, 27 Sep 2022 12:15:10 +0200 (CEST) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mails.dpdk.org (Postfix) with ESMTP id AEC87410D0 for ; Tue, 27 Sep 2022 12:15:08 +0200 (CEST) Received: by mail-lf1-f45.google.com with SMTP id a2so14947827lfb.6 for ; Tue, 27 Sep 2022 03:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netgate.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=0+nk4AuHhe3wNnakRnnblQ3eXeaYgx8xtNs4MSHvB48=; b=qlETIduhWAvLpTKiV4hnWW/RrZXoZJVzTpO8VSgBP7SWg2ekY6ok8Iho4Xuz7LyYOO K98L4LKQS7xpNARn0N8blS0g3RlNrBWP20QdKROKT/QHneaE8LGq9tMC18xz+GrpYX+K 6+TPCqTxXgIUop53lUC38eTdUMkksiuVWvzUk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=0+nk4AuHhe3wNnakRnnblQ3eXeaYgx8xtNs4MSHvB48=; b=yS8fKAfn46cOB0SByl8a+inp6IY7zgWuhkmuJHZVMUImr9TAqJeTfeNZ4etTj9k/Ar uwIn24iorKs88MWGcHtcn2HB4WXstZ7zU9QSoF5uJN7lRVWTA58KDvCYCwLuWCwvxMBQ qWKSBOyEv+Ztzvnzxv0DPc4vpYmVhXnAh9Z10tDBOLNiYlttM6LfKrnT+AX8ZtjjWMgO CoYGmq7gf96L+ZDBm3gFHnSm2OvY4bOjGCPlfgHi0cOjRykN6QO+uI23tsk32UxgDQEx uc1lqnq6eix6SlScON8v9YynnT+8f4wdpgheHBciQdV/qeRz28XXauSkGyCtChJbC0hb eqQA== X-Gm-Message-State: ACrzQf2H96sDvQ48lH5huYcKuqn8dEN1q4QI1K9oUD/w/XsZNaTYwRxm 8wYIlbZWAXV9iusiAdn2Zv3KNPX1jE2yy48k X-Google-Smtp-Source: AMsMyM7Lfmx63pkJlqLR89aDTHACtADSWy4Gt9dlAzqdUfFecYfF2QWD4IkjFiY3aketYhqAcmm+Uw== X-Received: by 2002:ac2:4bc7:0:b0:49a:dbf7:73e9 with SMTP id o7-20020ac24bc7000000b0049adbf773e9mr9930940lfq.529.1664273708131; Tue, 27 Sep 2022 03:15:08 -0700 (PDT) Received: from pb1-dev.ad.sperasoft.com ([188.233.188.88]) by smtp.gmail.com with ESMTPSA id z12-20020ac25dec000000b00493014c3d7csm115846lfq.309.2022.09.27.03.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 03:15:07 -0700 (PDT) From: Alexander Chernavin To: chenbo.xia@intel.com, maxime.coquelin@redhat.com Cc: dev@dpdk.org, Alexander Chernavin , stable@dpdk.org Subject: [PATCH v3] net/virtio: fix crash when dev is configured twice Date: Tue, 27 Sep 2022 10:15:04 +0000 Message-Id: <20220927101504.1220037-1-achernavin@netgate.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926083212.1178663-1-achernavin@netgate.com> References: <20220926083212.1178663-1-achernavin@netgate.com> 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. Fixes: 2b38151f745a ("net/virtio: fix queue memory leak on error") Cc: stable@dpdk.org Signed-off-by: Alexander Chernavin Reviewed-by: Chenbo Xia --- v2: Add Cc: stable@dpdk.org v3: Add Fixes: 2b38151f745a 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");