Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp724819imm; Thu, 13 Sep 2018 06:52:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY3kCq3pBQ6WfW33xq7+iSZ5OH025ymxe6g1kTBm6wfQ+ozXB8aM8X+avatG2Lr16k0f6qA X-Received: by 2002:a65:6292:: with SMTP id f18-v6mr7225257pgv.85.1536846762111; Thu, 13 Sep 2018 06:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846762; cv=none; d=google.com; s=arc-20160816; b=G/6O2GSgBb5L0Tu71Lli0bamR3TXNmcVCGs2hQY0h4TN6psWtH2I+yqQIjcLwUA2ja 09RGdEu3QKQ+80wBS5PwEtJwKIHPE5b6FNlwh3ueJzrSWkGQ0k1b2hHMbavX/uqKBjdz 8xK/v4fugVFbe9MTKV1W4ZztD0AP2cwPQFu392KS/zIsWsosXORN4ODvh3aS6EpPNRl7 6KIlf1MG209f9sjwUKlPksAMvAMJQeb0pyGMd8S5yKUXv3NYBZkjYH93pjkftGIVsmf6 gHff0sBXwYHzxmE5yApA0mBgOwnfuey7nC/DZpJJ6W+y2MqhOj0XD6GDj+DEHJgolMQL mczQ== 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; bh=clNHfSR7dWI+EDEWN3t5gVoOkKfIohPYfoslV5TTxM8=; b=qnYspGYnPpDL9SZWo2KJ2F+1rd8sw35IYiNijsbGNsEPrSv1XA2cacqKASvcCUZHOg JeFVRGFkFAuoss0GD6GB+1YYQldke++yHK0JtMTcFMWgdnWUroT6VZKoywW70GEnNIuX r8D0H0YIOmySdgmHEsC8w1ix8uXP/DquIao25wwJ5LRDlQGRdiEtZcdXxOuzTnzLaF0H 0hvUcnGjXXZpsQvVvvcR/KfwveIimyppG589IIZxu99aafwsBZiHuP5rnSpHGCRzYtdQ +MgyYaUdkNfEYp9Laxzz8LuNDuyjI00bIDDhveuLOxqbVP/6Mv0iq4N2TpsM4+0V/uk2 udNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2-v6si4167331pgs.108.2018.09.13.06.52.26; Thu, 13 Sep 2018 06:52:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730568AbeIMTBp (ORCPT + 99 others); Thu, 13 Sep 2018 15:01:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730119AbeIMTBo (ORCPT ); Thu, 13 Sep 2018 15:01:44 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 040FED10; Thu, 13 Sep 2018 13:52:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Dirk van der Merwe , "David S. Miller" Subject: [PATCH 4.18 032/197] nfp: wait for posted reconfigs when disabling the device Date: Thu, 13 Sep 2018 15:29:41 +0200 Message-Id: <20180913131842.847021013@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jakub Kicinski [ Upstream commit 9ad716b95fd6c6be46a4f2d5936e514b5bcd744d ] To avoid leaking a running timer we need to wait for the posted reconfigs after netdev is unregistered. In common case the process of deinitializing the device will perform synchronous reconfigs which wait for posted requests, but especially with VXLAN ports being actively added and removed there can be a race condition leaving a timer running after adapter structure is freed leading to a crash. Add an explicit flush after deregistering and for a good measure a warning to check if timer is running just before structures are freed. Fixes: 3d780b926a12 ("nfp: add async reconfiguration mechanism") Signed-off-by: Jakub Kicinski Reviewed-by: Dirk van der Merwe Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 48 +++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -227,29 +227,16 @@ done: spin_unlock_bh(&nn->reconfig_lock); } -/** - * nfp_net_reconfig() - Reconfigure the firmware - * @nn: NFP Net device to reconfigure - * @update: The value for the update field in the BAR config - * - * Write the update word to the BAR and ping the reconfig queue. The - * poll until the firmware has acknowledged the update by zeroing the - * update word. - * - * Return: Negative errno on error, 0 on success - */ -int nfp_net_reconfig(struct nfp_net *nn, u32 update) +static void nfp_net_reconfig_sync_enter(struct nfp_net *nn) { bool cancelled_timer = false; u32 pre_posted_requests; - int ret; spin_lock_bh(&nn->reconfig_lock); nn->reconfig_sync_present = true; if (nn->reconfig_timer_active) { - del_timer(&nn->reconfig_timer); nn->reconfig_timer_active = false; cancelled_timer = true; } @@ -258,14 +245,43 @@ int nfp_net_reconfig(struct nfp_net *nn, spin_unlock_bh(&nn->reconfig_lock); - if (cancelled_timer) + if (cancelled_timer) { + del_timer_sync(&nn->reconfig_timer); nfp_net_reconfig_wait(nn, nn->reconfig_timer.expires); + } /* Run the posted reconfigs which were issued before we started */ if (pre_posted_requests) { nfp_net_reconfig_start(nn, pre_posted_requests); nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT); } +} + +static void nfp_net_reconfig_wait_posted(struct nfp_net *nn) +{ + nfp_net_reconfig_sync_enter(nn); + + spin_lock_bh(&nn->reconfig_lock); + nn->reconfig_sync_present = false; + spin_unlock_bh(&nn->reconfig_lock); +} + +/** + * nfp_net_reconfig() - Reconfigure the firmware + * @nn: NFP Net device to reconfigure + * @update: The value for the update field in the BAR config + * + * Write the update word to the BAR and ping the reconfig queue. The + * poll until the firmware has acknowledged the update by zeroing the + * update word. + * + * Return: Negative errno on error, 0 on success + */ +int nfp_net_reconfig(struct nfp_net *nn, u32 update) +{ + int ret; + + nfp_net_reconfig_sync_enter(nn); nfp_net_reconfig_start(nn, update); ret = nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT); @@ -3609,6 +3625,7 @@ struct nfp_net *nfp_net_alloc(struct pci */ void nfp_net_free(struct nfp_net *nn) { + WARN_ON(timer_pending(&nn->reconfig_timer) || nn->reconfig_posted); if (nn->dp.netdev) free_netdev(nn->dp.netdev); else @@ -3893,4 +3910,5 @@ void nfp_net_clean(struct nfp_net *nn) return; unregister_netdev(nn->dp.netdev); + nfp_net_reconfig_wait_posted(nn); }