Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2289657pxb; Mon, 11 Jan 2021 06:09:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVMDIZOzcSvdlQ84OgyH5Ae8sZ/1DKr+lgB1+0ZxI+eoujR71270yX1otB5535tyj0zHXO X-Received: by 2002:a17:906:1199:: with SMTP id n25mr10575854eja.293.1610374198527; Mon, 11 Jan 2021 06:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610374198; cv=none; d=google.com; s=arc-20160816; b=S13S4qvzw+hd+52uXSw93Q3Gw4O5lCwgBF3hw0TIHyHfkJZMSoyuUmeh5xzrkjDAWW kN6FepCkU0Ey456eidMsvMprtMdKGzLMG3DaKeqgq3xTApNOs0J6VWopyuahq+JgCMvZ SOUKa3XmDAvrSqLc/38WStlHFwLFsyQyMQ5cdm3IsGrdeFiYmUi2cinvaIcqWurMA8U+ bW2Ruo0LZtY+hlYERsDYGaHxNnC1S9RNMTRZ9xrGKPft4jeHGkhk7/It6SOjZQtzHJ9h 9K1l6d9kppWlhXn5no+7Dff6UQL0F+W84F/NyEPwY0lBZFg6HHa260Ybn6g/xk/xJUuj 8sPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Cz6gBfglF8eoHJMduiJQcTT8mTCrOHuzqS2D0b/oVoY=; b=ZM7mykV5+NlDwds8/UMVhDvAEBwBdFRgZB6yMfEPBSDn3bJv2M0mYbomNVeK1YOR0X sxEAHR5hf5zHagT9dZwUUPratx8RXj3ncByw3H/Hgx1/b25g4uPOvPHTRrgm87elg8aC IzV+CkSwqXfrMR+kuonsqKd+2dbSlFwTtwswpHH0LooeGsusPW05fBLXOxFdmCoCVqGh BGcH3aptLcRTl0s/eXdN1DsEhUuVEalaHxYADjYAhgJnDFm1RNscj6KadnOGahmGDArj MxV2fL3xEEqcLX1XXCv4oLn79f7z6OBVNhRWGaKDZ09wxA+ZrtY5x+GxbHrEqr0SKfDg tOzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mUy0GWH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si7108709edw.403.2021.01.11.06.09.22; Mon, 11 Jan 2021 06:09:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mUy0GWH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387927AbhAKOEg (ORCPT + 99 others); Mon, 11 Jan 2021 09:04:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:51268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728453AbhAKNEa (ORCPT ); Mon, 11 Jan 2021 08:04:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B338E2225E; Mon, 11 Jan 2021 13:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370229; bh=rlJCZaBn2wZZtcLRZY2q/ooWUVjQvUEIhZ/A3xI2WVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUy0GWH7sI6IPH31z7CPccr52dcGz+LKm/Kgzaoq1C52meAInj/3LeHnAH6OTBLn9 Bnut9I6ZQi4TefWu3zqysaArxx7+2BE7NtAcgUcWq8XMY+ksTeccpUVUn5KSKJ+YGB apuzeVOhWNzE5mrBMmLKVdCwfdYXSAbHyvxpx5K8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Dike , Jason Wang , "Michael S. Tsirkin" , Jakub Kicinski Subject: [PATCH 4.9 16/45] virtio_net: Fix recursive call to cpus_read_lock() Date: Mon, 11 Jan 2021 14:00:54 +0100 Message-Id: <20210111130034.437141773@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130033.676306636@linuxfoundation.org> References: <20210111130033.676306636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeff Dike [ Upstream commit de33212f768c5d9e2fe791b008cb26f92f0aa31c ] virtnet_set_channels can recursively call cpus_read_lock if CONFIG_XPS and CONFIG_HOTPLUG are enabled. The path is: virtnet_set_channels - calls get_online_cpus(), which is a trivial wrapper around cpus_read_lock() netif_set_real_num_tx_queues netif_reset_xps_queues_gt netif_reset_xps_queues - calls cpus_read_lock() This call chain and potential deadlock happens when the number of TX queues is reduced. This commit the removes netif_set_real_num_[tr]x_queues calls from inside the get/put_online_cpus section, as they don't require that it be held. Fixes: 47be24796c13 ("virtio-net: fix the set affinity bug when CPU IDs are not consecutive") Signed-off-by: Jeff Dike Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20201223025421.671-1-jdike@akamai.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/virtio_net.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1357,14 +1357,16 @@ static int virtnet_set_channels(struct n get_online_cpus(); err = virtnet_set_queues(vi, queue_pairs); - if (!err) { - netif_set_real_num_tx_queues(dev, queue_pairs); - netif_set_real_num_rx_queues(dev, queue_pairs); - - virtnet_set_affinity(vi); + if (err) { + put_online_cpus(); + goto err; } + virtnet_set_affinity(vi); put_online_cpus(); + netif_set_real_num_tx_queues(dev, queue_pairs); + netif_set_real_num_rx_queues(dev, queue_pairs); +err: return err; }