Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp299186pxk; Fri, 11 Sep 2020 07:16:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCC+/cJgkX6ZQG7cbrYa1vtYnZ3XE9LkfcAnnMZxeUpVZJF6soxW9BSQLL05crSKuDHxKv X-Received: by 2002:a50:ab59:: with SMTP id t25mr2156116edc.364.1599833811819; Fri, 11 Sep 2020 07:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599833811; cv=none; d=google.com; s=arc-20160816; b=pak4ZPp0RgPfVQV5hDjBkvKGN4UTVAFNcavuH1vSUTUBynn3JUutJJTgd93EBzfFel xnzPXgyfW7dGPMNdYktu+dIHIqYM/Ef9FOlMBTq1brmz6Z+kIt0psoJj3rRF/JCnxU37 t1n33qhDSI3TCQ9gUOvR6PA1IbgvBRB48fDfz28xyDOwAQ06KTSAhENDl++mICYu+VJe zpnP96fApxxBpOF9XdJHv9S0ucVJN5n4ECoI8v7JIzdhUC+Udunx+7+zGK2/zhY67Y5H l5H7gpauvpKP2Tygsb8eIABppN6qCmL81qPMBkkZrSfwDNt6MvRG5D8uwI+3CO4GiSMX wHqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zZXwWvFWymK5IqSPhdS6KpNQmGRlGw3E1endPLaw2R8=; b=CAamVAPgLbg3Ai9M5XF92wFDmWN59lj+OyOC2pDVF5L3Og7BIHLWBjJhCB3xZveWgd IicI71ZyLILAVdg36APVPreS6Fy8HPzIbPgQTV4MABDwOfLX6IyOBYHVvv2aQ1Z/khPj t1eTVB7LxDZSnxD9oZMhByFn4MEIgdR9EwNRA8kUN3dMWZGzgmIHinEUKkjO1Nz9Elix TV465umJ05eqDDPLqEWYDSPi69uL+wHyQRxRSAgNff32ekGlc80n1Udf+n/0JaWoQ1KA vw1gcTmIV6b0zg6k3RDQxnhwuNemozEh4K1hGnl/poSsOAW/aBmEHd7rzc/n4aqTlvGf Ppzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tZz12LH5; 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=fail (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 c8si1538706edn.87.2020.09.11.07.16.28; Fri, 11 Sep 2020 07:16:51 -0700 (PDT) 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=@kernel.org header.s=default header.b=tZz12LH5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725999AbgIKONp (ORCPT + 99 others); Fri, 11 Sep 2020 10:13:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:32772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbgIKNVa (ORCPT ); Fri, 11 Sep 2020 09:21:30 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 139CA223EA; Fri, 11 Sep 2020 12:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829142; bh=UAs3Q/Zz9F5+9bZ42uUtir1voEsU5TfKbTq5cMt4HEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tZz12LH5l7veTMDSJjDe3roefZRkQpr+qBcPF+3wWb4Ao4pZRsFdm3WS9oW7nypoW wiJpJU2wE/68XTJivVsTOz+jDtLMEGsdp6/x44JdgGquTKpLqncZu2Fh3WSTBas3bK 1TnE8+Fu0fAtoVKl/e1SeKXK7dqMvAjJlsxUrKyw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rob Sherwood , Jakub Kicinski , "David S. Miller" Subject: [PATCH 4.14 12/12] net: disable netpoll on fresh napis Date: Fri, 11 Sep 2020 14:47:06 +0200 Message-Id: <20200911122459.015758062@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122458.413137406@linuxfoundation.org> References: <20200911122458.413137406@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski [ Upstream commit 96e97bc07e90f175a8980a22827faf702ca4cb30 ] napi_disable() makes sure to set the NAPI_STATE_NPSVC bit to prevent netpoll from accessing rings before init is complete. However, the same is not done for fresh napi instances in netif_napi_add(), even though we expect NAPI instances to be added as disabled. This causes crashes during driver reconfiguration (enabling XDP, changing the channel count) - if there is any printk() after netif_napi_add() but before napi_enable(). To ensure memory ordering is correct we need to use RCU accessors. Reported-by: Rob Sherwood Fixes: 2d8bff12699a ("netpoll: Close race condition between poll_one_napi and napi_disable") Signed-off-by: Jakub Kicinski Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 3 ++- net/core/netpoll.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5532,12 +5532,13 @@ void netif_napi_add(struct net_device *d pr_err_once("netif_napi_add() called with weight %d on device %s\n", weight, dev->name); napi->weight = weight; - list_add(&napi->dev_list, &dev->napi_list); napi->dev = dev; #ifdef CONFIG_NETPOLL napi->poll_owner = -1; #endif set_bit(NAPI_STATE_SCHED, &napi->state); + set_bit(NAPI_STATE_NPSVC, &napi->state); + list_add_rcu(&napi->dev_list, &dev->napi_list); napi_hash_add(napi); } EXPORT_SYMBOL(netif_napi_add); --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -179,7 +179,7 @@ static void poll_napi(struct net_device struct napi_struct *napi; int cpu = smp_processor_id(); - list_for_each_entry(napi, &dev->napi_list, dev_list) { + list_for_each_entry_rcu(napi, &dev->napi_list, dev_list) { if (cmpxchg(&napi->poll_owner, -1, cpu) == -1) { poll_one_napi(napi); smp_store_release(&napi->poll_owner, -1);