Received: by 2002:a9a:45c2:0:b029:115:3f2f:b9e1 with SMTP id r2csp852977lko; Mon, 5 Jul 2021 00:24:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEMOM8gtUaYiVsrurCdrvf0I2ZX1EFUPoAJB1sDA+eHlCOwFIpsgh2ptxo36xx0XGSMtJ8 X-Received: by 2002:a5e:c10e:: with SMTP id v14mr11042257iol.158.1625469873327; Mon, 05 Jul 2021 00:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625469873; cv=none; d=google.com; s=arc-20160816; b=vBYeHTVCNJ+Dq+ougxWtJVzuhw6jelK7pcjf5EvzAwEPhb47oclMYhZFkKSq/ytQNA kMS3hmQ5MMiFzU4y7QcSwNC7pjuWPJWqe6cprCRPlzvimOPrUDut+BR8aweGveHrRciF oTClvKKFu+MyVdykdPQKkfcOsBAITeqV95bnlyKhMjvDcK+nY76XbBl2dqIDC2DG5liI U72Wu+tt9GG4dxQdmiGiUNgMVdwmCXjC1p47QXv3xazBLATD3X1vaExzG6RC3KJE/FJ7 gmXtNKbzYT9Kdf30Cj8ROm8H/NDFrj6AmxWKQ25UDXldf73dCyUpw53k2qWN7mDSHL7U 3BuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=X97XXaIzaHW8nJJZO49xxMJV2rZxdGMEKEdf/SYkbZQ=; b=QVMnn3DyLpZrTwnM3st1rmTYVEZso4BJPhF4MIgylWe2H7Wj7Xgfr5PMcfx6hBsFJr 1rdeAmpwbZ1qu0+Ny09I4iBWWdxLQtzUDbb6dWqA1GEABRrPNy855YIj1KSRCe4yOWIm vmk/zUGUB+krSpkYhI4BcbbaEUo3H46Sa7fk6JrGFA4uFvbTzUxDkqLpoK0x8iA+NHfq KfdjylBPshm7AQSkI6miIkfzXjsbqHSDdL0tzfU8rqLnOvD1CxtNnh6ZJgd4EO2HmeBW efF/pvefHipocMQKA9TTMj8gY29zQtEZOTDW22o1Ux9E3zOBvlohsNLS2E4Ad2tfCGy/ BfsA== ARC-Authentication-Results: i=1; mx.google.com; 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si12238026ilc.117.2021.07.05.00.24.21; Mon, 05 Jul 2021 00:24:33 -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; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbhGEH0I (ORCPT + 99 others); Mon, 5 Jul 2021 03:26:08 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:46851 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbhGEH0I (ORCPT ); Mon, 5 Jul 2021 03:26:08 -0400 Received: from [222.129.38.159] (helo=[192.168.1.18]) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1m0Iwy-0000jS-Ew; Mon, 05 Jul 2021 07:23:28 +0000 To: =?UTF-8?Q?Pali_Roh=c3=a1r?= , Bjorn Helgaas , =?UTF-8?Q?Krzysztof_Wilczy=c5=84ski?= Cc: 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, linux-pci@vger.kernel.org, =?UTF-8?Q?Marek_Beh=c3=ban?= References: <20210702045120.22855-1-aaron.ma@canonical.com> <20210704142808.f43jbcufk37hundo@pali> From: Aaron Ma Subject: Re: [PATCH 1/2] igc: don't rd/wr iomem when PCI is removed Message-ID: <3bc507f7-3eb9-1bef-d47d-cad42fcb1c48@canonical.com> Date: Mon, 5 Jul 2021 15:23:21 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210704142808.f43jbcufk37hundo@pali> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/4/21 10:28 PM, Pali Rohár wrote: > + Bjorn, Krzysztof and linux-pci > > On Friday 02 July 2021 12:51:19 Aaron Ma wrote: >> Check PCI state when rd/wr iomem. >> Implement wr32 function as rd32 too. >> >> When unplug TBT dock with i225, rd/wr PCI iomem will cause error log: >> 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 | 16 ++++++++++++++++ >> drivers/net/ethernet/intel/igc/igc_regs.h | 7 ++----- >> 2 files changed, 18 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c >> index f1adf154ec4a..606b72cb6193 100644 >> --- a/drivers/net/ethernet/intel/igc/igc_main.c >> +++ b/drivers/net/ethernet/intel/igc/igc_main.c >> @@ -5292,6 +5292,10 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg) >> u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr); >> u32 value = 0; >> >> + if (igc->pdev && >> + igc->pdev->error_state == pci_channel_io_perm_failure) > > Hello! This code pattern and commit message looks like that we could use > pci_dev_is_disconnected() helper function for checking if device is > still connected or was disconnected. > > Apparently pci_dev_is_disconnected() is defined only in private header > file drivers/pci/pci.h and not in public include/linux/pci.h. > > Aaron: can you check if pci_dev_is_disconnected() is really something > which should be used and it helps you? > Hi Pali, How about using pci_channel_offline instead? It's ready and also safe for frozen state, and verified on hw. > Bjorn, Krzysztof: what do you think about lifting helper function > pci_dev_is_disconnected() to be available to all drivers and not only in > PCI subsystem? > > I think that such helper function makes driver code more readable and > can be useful also for other drivers which are checking if return value > is all F's. > >> + return 0; > > Aaron: should not you return all F's on error? Because few lines below > in this function is returned value with all F's when PCIe link lost. > If you agree with the above change, I can fix it to "return -1" in v2. Thanks for your comments, Aaron >> + >> value = readl(&hw_addr[reg]); > > Anyway, this code looks to be racy. When pci_channel_io_perm_failure is > set (e.g. by hotplug interrupt) after checking for pdev->error_state and > prior executing above readl() then mentioned fatal error still occurs. > >> >> /* reads should not return all F's */ >> @@ -5308,6 +5312,18 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg) >> return value; >> } >> >> +void igc_wr32(struct igc_hw *hw, u32 reg, u32 val) >> +{ >> + struct igc_adapter *igc = container_of(hw, struct igc_adapter, hw); >> + u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr); >> + >> + if (igc->pdev && >> + igc->pdev->error_state == pci_channel_io_perm_failure) >> + return; >> + >> + writel((val), &hw_addr[(reg)]); >> +} >> + >> int igc_set_spd_dplx(struct igc_adapter *adapter, u32 spd, u8 dplx) >> { >> struct igc_mac_info *mac = &adapter->hw.mac; >> diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethernet/intel/igc/igc_regs.h >> index cc174853554b..eb4be87d0e8b 100644 >> --- a/drivers/net/ethernet/intel/igc/igc_regs.h >> +++ b/drivers/net/ethernet/intel/igc/igc_regs.h >> @@ -260,13 +260,10 @@ struct igc_hw; >> u32 igc_rd32(struct igc_hw *hw, u32 reg); >> >> /* write operations, indexed using DWORDS */ >> -#define wr32(reg, val) \ >> -do { \ >> - u8 __iomem *hw_addr = READ_ONCE((hw)->hw_addr); \ >> - writel((val), &hw_addr[(reg)]); \ >> -} while (0) >> +void igc_wr32(struct igc_hw *hw, u32 reg, u32 val); >> >> #define rd32(reg) (igc_rd32(hw, reg)) >> +#define wr32(reg, val) (igc_wr32(hw, reg, val)) >> >> #define wrfl() ((void)rd32(IGC_STATUS)) >> >> -- >> 2.30.2 >>