Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp480704imn; Wed, 27 Jul 2022 11:23:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v/QlbTbZNAF/zQsyZosVcR/dK1NohoUL1oSGM3LSvsofggcgY/xdlTNXrYGD+CP/ShMgzD X-Received: by 2002:a05:6402:2709:b0:43c:62d:7a63 with SMTP id y9-20020a056402270900b0043c062d7a63mr15957354edd.130.1658946201846; Wed, 27 Jul 2022 11:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946201; cv=none; d=google.com; s=arc-20160816; b=LAFtQAyJma8ws5iS/nDGwdxNDp961VCI8waIVXdn/42CBd6C5qSGvO2N9UA/XE3sXD KMqR+4oxl08k9zqywv/ATKxNcUcM688LyqQc2sZTK8ed8ChuAjjR62CbnEk4bt9UY5/j 1Ler+KpsSku2GsZyx5qe8sIQ0IQ7+v1Y5+fDRi6KxNSse+O/dj2IixQNIkPfIIYTDu4r DFgrhwpCmuVPICeTP/dQMqRAX0/GaQMKIetS5Ww1weFoXiW9G+gyG5PjF/qz6n3YOque 1nz1VFk5UKXJCV6u2o23328yQ3uFHQU4IrLxx3+lMeSAmBnwEvXX1TXbJy/X6kg6Slfd YYbw== 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=0nnWPrDnN8R8R00PsyW+kxXyMgzpdLhpKZl6mD4W38E=; b=K+CQheyVW8qDf5+qrxGCF/yT3vkkzir6KBs65zXwHa3yRLjhru4Z3Trm7wS++ZERw5 TxJ2TEvtaJuyA9xeNuyB1wsoWwOrkC/Z9hqYnNm6AD7RFoKtnTHIomV88O8z6YD5BQau TFBVJWQeyIJOZ2exPh0RnNnxc5tZfqDcnHtC1z01DhWTlApzJvhGO4GgrqJd3Bsyqg9o 0gQOgLJl9tO8i9gVEjj0vtXD8GllvmRVyhs+P4jMTHCmS1PF6S5+/ouPhkR9GHZsrTnY jIf642IxMiNRvSFr/tfED7cMDZfnnT6ZE4xseYIuzmjbu/y1TRsaCd2BTV6IiScfOts7 yDJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PXwVE7Od; 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 kl17-20020a170907995100b0072b32710ccbsi16935051ejc.356.2022.07.27.11.22.56; Wed, 27 Jul 2022 11:23:21 -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=PXwVE7Od; 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 S238621AbiG0Qly (ORCPT + 99 others); Wed, 27 Jul 2022 12:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239145AbiG0QlI (ORCPT ); Wed, 27 Jul 2022 12:41:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D924E623; Wed, 27 Jul 2022 09:29:34 -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 9192BB821BC; Wed, 27 Jul 2022 16:29:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B33DBC433C1; Wed, 27 Jul 2022 16:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939372; bh=Ie/6QvGoxKNOLhlHGeLDcRr4cP1nWvy+w+noycFWjNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PXwVE7OdmypK5bWlPyLSTDNfQsxsrER6X9JNcK7XAySXry9EuzCc0uAmht2ztSrav kf6rsbELy1wwPf++7ZICYmGmX45go73hbwjk6m1l37ozWQJW8nK2GatYIEY3E7SD9o Oo9hcbUVed0tC+cLByuwbwyDRAqFBaO4p0w7AoTo= 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.4 15/87] igc: Reinstate IGC_REMOVED logic and implement it properly Date: Wed, 27 Jul 2022 18:10:08 +0200 Message-Id: <20220727161009.617339738@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161008.993711844@linuxfoundation.org> References: <20220727161008.993711844@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_regs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethernet/intel/igc/igc_regs.h index 50d7c04dccf5..7bc7d7618fe1 100644 --- a/drivers/net/ethernet/intel/igc/igc_regs.h +++ b/drivers/net/ethernet/intel/igc/igc_regs.h @@ -236,4 +236,6 @@ do { \ #define array_rd32(reg, offset) (igc_rd32(hw, (reg) + ((offset) << 2))) +#define IGC_REMOVED(h) unlikely(!(h)) + #endif -- 2.35.1