Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3883512pxv; Tue, 13 Jul 2021 06:08:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxwPmbNwdcOg9G+lYTGKGVe1aOkawfay2V5Eli8LLiSgPVx9yjwAw+DlYrRpdr875EfzfD X-Received: by 2002:a05:6602:2bdc:: with SMTP id s28mr3154803iov.70.1626181718466; Tue, 13 Jul 2021 06:08:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626181718; cv=none; d=google.com; s=arc-20160816; b=idsnkyBnXr1Dj3g1URy6djdqhgtgBbij5OF5Q6cgCCN2Fc7zugGZm9ttxM9rjMJUr9 /hUj8/w1kP5vdF/MlAw28C/kLjfiH+b3HHCoXnEiWQ2iXso3mJqK/2O8ylsckx1JLFSj KW6L6J5T1xEg00IsLLQOGHtnzc+W1cwteD7+z5ufGzFYd6kiqzOod9Rh/+8zrhDClxIb pMhQhV4U/oLro99nfxmC9579qCpIdhYOQh8eNrY4cO2ydOFiHJjUgwnh0/CbNF7/nV5S kCQrl/Ut85BYvq36IHcGeoJPcLWBGffGf4o+AdXEzAQPrkOldZr17GDa6/dURiXuWm+5 QX4g== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wtJCO3QYrNDXs3ubXQGWVjwF5MFQxhxZ9W+dp4w8uV8=; b=e+x4g6PB6CEUS3QQpJWHvMbVZzlpAynTQY/JGMF6g/7HgC+rwYBiCcaYa1AqFL4iVS iZ/Qq9BJ8AqweMckWKPDs/bX/JI+fgXWZMEWaKHTweklKuVGM7CzQRM1x5cqgKN/g8o1 rUBMiA5m4KJAcHMBpoE98nR5RveHINJDKsUxf9G0luzUCmk4bzJDodb76UEf5nK+Kyr4 T0zlsWuAEgTW/oFra87SGR7iIqHqOP+w4RrGcmv2RnWtXFkVyo4Rsv6r7pennW8ALV2w 12IqTeDnELa40w/+RLrzf+kXbG3DeRCCwy1MuirqMZ1EzR0K62kuca8fOH5lN3O9ZkPW 9kxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=ZbHhxMnk; 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si22938803jav.63.2021.07.13.06.08.25; Tue, 13 Jul 2021 06:08:38 -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=@canonical.com header.s=20210705 header.b=ZbHhxMnk; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236740AbhGMNKX (ORCPT + 99 others); Tue, 13 Jul 2021 09:10:23 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:45966 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236737AbhGMNKX (ORCPT ); Tue, 13 Jul 2021 09:10:23 -0400 X-Greylist: delayed 400 seconds by postgrey-1.27 at vger.kernel.org; Tue, 13 Jul 2021 09:10:22 EDT Received: from localhost.localdomain (unknown [222.129.38.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 95C6E405D1; Tue, 13 Jul 2021 13:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1626181251; bh=wtJCO3QYrNDXs3ubXQGWVjwF5MFQxhxZ9W+dp4w8uV8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ZbHhxMnkFheoGVQFyShRrFC2aHIvKFaP85Du3D2Z4ryhkQQkcRVRkx9sC/ta67HcQ Qg17jNp12JAdFxtei1VM84Er9OjKAzkHb1A79FhRkqXLku7OH5ZOXup56Zf5cdfQ7q bB2GD04rS0vbE8EZxd3rprc2n/A4aUbSwky1T2owb6IJcVa3+nTtnPnvqyC3W+iHb3 Y1uH3wP7BGYRAS1FAadkWQib39xfbr00CRRyC5SQG4sf2+isA7aHhnPl0HllgbL83q unH5tAr3pit/9oaN/ZnGn7Hr0l3nVCqTIcIGdNQhlRd3FrPIg/3QmJ6h7Agd6suO5w IQiiIz8wvXlNA== From: Aaron Ma To: aaron.ma@canonical.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, kuba@kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] igc: fix page fault when thunderbolt is unplugged Date: Tue, 13 Jul 2021 21:00:36 +0800 Message-Id: <20210713130036.741188-1-aaron.ma@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210702045120.22855-1-aaron.ma@canonical.com> References: <20210702045120.22855-1-aaron.ma@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After unplug thunerbolt dock with i225, pciehp interrupt is triggered, remove call will read/write mmio address which is already disconnected, then cause page fault and make system hang. Check PCI state to remove device safely. Trace: BUG: unable to handle page fault for address: 000000000000b604 Oops: 0000 [#1] SMP NOPTI RIP: 0010:igc_rd32+0x1c/0x90 [igc] Call Trace: igc_ptp_suspend+0x6c/0xa0 [igc] igc_ptp_stop+0x12/0x50 [igc] igc_remove+0x7f/0x1c0 [igc] pci_device_remove+0x3e/0xb0 __device_release_driver+0x181/0x240 Signed-off-by: Aaron Ma --- drivers/net/ethernet/intel/igc/igc_main.c | 32 ++++++++++++++--------- drivers/net/ethernet/intel/igc/igc_ptp.c | 3 ++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 95323095094d..3c72f135fc29 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -149,6 +149,9 @@ static void igc_release_hw_control(struct igc_adapter *adapter) struct igc_hw *hw = &adapter->hw; u32 ctrl_ext; + if (!pci_device_is_present(adapter->pdev)) + return; + /* Let firmware take over control of h/w */ ctrl_ext = rd32(IGC_CTRL_EXT); wr32(IGC_CTRL_EXT, @@ -4447,26 +4450,29 @@ void igc_down(struct igc_adapter *adapter) igc_ptp_suspend(adapter); - /* disable receives in the hardware */ - rctl = rd32(IGC_RCTL); - wr32(IGC_RCTL, rctl & ~IGC_RCTL_EN); - /* flush and sleep below */ - + if (pci_device_is_present(adapter->pdev)) { + /* disable receives in the hardware */ + rctl = rd32(IGC_RCTL); + wr32(IGC_RCTL, rctl & ~IGC_RCTL_EN); + /* flush and sleep below */ + } /* set trans_start so we don't get spurious watchdogs during reset */ netif_trans_update(netdev); netif_carrier_off(netdev); netif_tx_stop_all_queues(netdev); - /* disable transmits in the hardware */ - tctl = rd32(IGC_TCTL); - tctl &= ~IGC_TCTL_EN; - wr32(IGC_TCTL, tctl); - /* flush both disables and wait for them to finish */ - wrfl(); - usleep_range(10000, 20000); + if (pci_device_is_present(adapter->pdev)) { + /* disable transmits in the hardware */ + tctl = rd32(IGC_TCTL); + tctl &= ~IGC_TCTL_EN; + wr32(IGC_TCTL, tctl); + /* flush both disables and wait for them to finish */ + wrfl(); + usleep_range(10000, 20000); - igc_irq_disable(adapter); + igc_irq_disable(adapter); + } adapter->flags &= ~IGC_FLAG_NEED_LINK_UPDATE; diff --git a/drivers/net/ethernet/intel/igc/igc_ptp.c b/drivers/net/ethernet/intel/igc/igc_ptp.c index 69617d2c1be2..4ae19c6a3247 100644 --- a/drivers/net/ethernet/intel/igc/igc_ptp.c +++ b/drivers/net/ethernet/intel/igc/igc_ptp.c @@ -849,7 +849,8 @@ void igc_ptp_suspend(struct igc_adapter *adapter) adapter->ptp_tx_skb = NULL; clear_bit_unlock(__IGC_PTP_TX_IN_PROGRESS, &adapter->state); - igc_ptp_time_save(adapter); + if (pci_device_is_present(adapter->pdev)) + igc_ptp_time_save(adapter); } /** -- 2.30.2