Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp486108imn; Wed, 27 Jul 2022 11:32:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t859PsBgq+brBXOyaESn3ALZ8r0gCoq9dVhZptxaBJuJw1BlAspNmlb4acvvm653oQjIYu X-Received: by 2002:a63:5cd:0:b0:412:b163:b7e1 with SMTP id 196-20020a6305cd000000b00412b163b7e1mr20135322pgf.451.1658946734426; Wed, 27 Jul 2022 11:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946734; cv=none; d=google.com; s=arc-20160816; b=G1x1FkQS6homX2Z4Rud0eDxn8BW6vkF2FxMP7+9BVtK39tEwwWPm4krOLSY256EtnT HfJgJWab+LGRdigRAox69xpPhnVL+Bdixv2+QuccLbG3XLRp0d23CZo1+ZyIHON2iTMD 8/2dnh60j4y7rh+hjgxhAXuX+gfPW6XoRD0brj5JwaqXcHcOQkN6urie1uhkGzW2ENP3 3fjGkJzVVuGiTFl94TzRVFWHxHdzmt2WOG7eOYte3rIOCJZHjKRSoGyROMNotn9JvoLj F7j44gQpfo9Z7r5UOK5YLJZpGP6UpLw57LmObE24H1Wk75RJJQaobMimaaHW2qVwDFKA EJrw== 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=+dnCKrquQ2xgS14KZnMpGPn74GDbLZPAYn2S5FW+BjE=; b=gpmfbXG23bkFFg8clVlOChnz82aTtCuNurLYR3v/ckurm+LEQUwwR/m2CVd6lXx+2W XqPASVWFp3T80hg6GpgBBPMbPTCAcNAOhxFX4JpK8u6zuBSeMrkbYJrorIK31VdAN06h qVh7pY0fxCH0fT/OFX/qkhRO+vBD1GC6WU3CHKaPls3HsQduVZfSCudavZRLFsvriPV8 AWl6LNn34KOx+ji+J5ZRovf+Zk51Z9PHaLVoYtXxLhK4WD8D0DRRwSHkds16ynFmFeoj oFceo1am002kYtgWzFtk+ter8qiyX3YbuIDZo/NUGvY/p858r8MfPJiVEQpoIqP74JYn rrsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q0G1QmdY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t73-20020a63784c000000b0040d9515987asi21316084pgc.62.2022.07.27.11.31.59; Wed, 27 Jul 2022 11:32:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q0G1QmdY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240743AbiG0Qxa (ORCPT + 99 others); Wed, 27 Jul 2022 12:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240517AbiG0QwS (ORCPT ); Wed, 27 Jul 2022 12:52:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3B84F188; Wed, 27 Jul 2022 09:34:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 84774B821BA; Wed, 27 Jul 2022 16:34:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE717C433D6; Wed, 27 Jul 2022 16:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939658; bh=Y6eKHf7YnFlT7L+au4LdTlAYiMv2LAqvSJSkWSCCpZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0G1QmdYPbAz0WVvUlw3yhtr7t+itKU4fH79RHU2gPyepyFJJoqs46EVm7ta8p31J FNW4bGZYJhfKxYZQO0Er9ex64co3t8cvV92DpVW71oAYGO634OaPFVu18YjV4B21ku P+hRdfmpnkKh4Yy4mvS93G3CNjgUg/ElHkpWMswk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lennert Buytenhek , Naama Meir , Sasha Neftin , Tony Nguyen , Sasha Levin Subject: [PATCH 5.10 027/105] igc: Reinstate IGC_REMOVED logic and implement it properly Date: Wed, 27 Jul 2022 18:10:13 +0200 Message-Id: <20220727161013.192674456@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161012.056867467@linuxfoundation.org> References: <20220727161012.056867467@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lennert Buytenhek [ Upstream commit 7c1ddcee5311f3315096217881d2dbe47cc683f9 ] The initially merged version of the igc driver code (via commit 146740f9abc4, "igc: Add support for PF") contained the following IGC_REMOVED checks in the igc_rd32/wr32() MMIO accessors: u32 igc_rd32(struct igc_hw *hw, u32 reg) { u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr); u32 value = 0; if (IGC_REMOVED(hw_addr)) return ~value; value = readl(&hw_addr[reg]); /* reads should not return all F's */ if (!(~value) && (!reg || !(~readl(hw_addr)))) hw->hw_addr = NULL; return value; } And: #define wr32(reg, val) \ do { \ u8 __iomem *hw_addr = READ_ONCE((hw)->hw_addr); \ if (!IGC_REMOVED(hw_addr)) \ writel((val), &hw_addr[(reg)]); \ } while (0) E.g. igb has similar checks in its MMIO accessors, and has a similar macro E1000_REMOVED, which is implemented as follows: #define E1000_REMOVED(h) unlikely(!(h)) These checks serve to detect and take note of an 0xffffffff MMIO read return from the device, which can be caused by a PCIe link flap or some other kind of PCI bus error, and to avoid performing MMIO reads and writes from that point onwards. However, the IGC_REMOVED macro was not originally implemented: #ifndef IGC_REMOVED #define IGC_REMOVED(a) (0) #endif /* IGC_REMOVED */ This led to the IGC_REMOVED logic to be removed entirely in a subsequent commit (commit 3c215fb18e70, "igc: remove IGC_REMOVED function"), with the rationale that such checks matter only for virtualization and that igc does not support virtualization -- but a PCIe device can become detached even without virtualization being in use, and without proper checks, a PCIe bus error affecting an igc adapter will lead to various NULL pointer dereferences, as the first access after the error will set hw->hw_addr to NULL, and subsequent accesses will blindly dereference this now-NULL pointer. This patch reinstates the IGC_REMOVED checks in igc_rd32/wr32(), and implements IGC_REMOVED the way it is done for igb, by checking for the unlikely() case of hw_addr being NULL. This change prevents the oopses seen when a PCIe link flap occurs on an igc adapter. Fixes: 146740f9abc4 ("igc: Add support for PF") Signed-off-by: Lennert Buytenhek Tested-by: Naama Meir Acked-by: Sasha Neftin Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igc/igc_main.c | 3 +++ drivers/net/ethernet/intel/igc/igc_regs.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 53e31002ce52..e7ffe63925fd 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -4933,6 +4933,9 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg) u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr); u32 value = 0; + if (IGC_REMOVED(hw_addr)) + return ~value; + value = readl(&hw_addr[reg]); /* reads should not return all F's */ diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethernet/intel/igc/igc_regs.h index b52dd9d737e8..a273e1c33b3f 100644 --- a/drivers/net/ethernet/intel/igc/igc_regs.h +++ b/drivers/net/ethernet/intel/igc/igc_regs.h @@ -252,7 +252,8 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg); #define wr32(reg, val) \ do { \ u8 __iomem *hw_addr = READ_ONCE((hw)->hw_addr); \ - writel((val), &hw_addr[(reg)]); \ + if (!IGC_REMOVED(hw_addr)) \ + writel((val), &hw_addr[(reg)]); \ } while (0) #define rd32(reg) (igc_rd32(hw, reg)) @@ -264,4 +265,6 @@ do { \ #define array_rd32(reg, offset) (igc_rd32(hw, (reg) + ((offset) << 2))) +#define IGC_REMOVED(h) unlikely(!(h)) + #endif -- 2.35.1