Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp2353837pja; Thu, 26 Mar 2020 13:48:37 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuSbjgum3IU+s95p7la/OG5AaXxjzWMq8ptnrLAx648T6we2QiNrxJmi6oL7+LCudisNoyX X-Received: by 2002:aca:c488:: with SMTP id u130mr1726034oif.154.1585255717568; Thu, 26 Mar 2020 13:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585255717; cv=none; d=google.com; s=arc-20160816; b=XlY2IfcbF1bVd8tf7o4oVtJd/Dys/IH4irGplVbZQNm+iAUPkLOV4dn89iaQdYV2Re NwDo3yCyGKPONHY1j6EG3qxCeIedBgW5lScMNCG147dW7+xOCnOp21Vgh73VuXGzQND1 rHarU0BHDO0XhzNgvGtlWuXuwfIOa6V+N+0aVs67PARVZo8h2Ftr535fkRTVMrmmyTTM BvIJDKtbxwOC2uwA4dS0ouYoS7ShiO2QA0QdPwjfrY6tzVUbTlu5bsr/peBRA+rEXdFx O2Abaxj4B8xCFfQajrs4avAmS3jE0Bx1VdxrQgx5VQOUSzy/RMmNebGpHJGcRtGuKqBa gaaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=BzH++czIx5VDkgujxMSZ8f42MZPdjUUtNDzTWPYfTW4=; b=jPbe5By/zotuvVFlnuw1YVclG7B9PTdjXCsRu2vQED90KHzzLV18KWJmJH3W+bttFT 9Xxy6oWqdR17lil16xe1ddoGpxB38IIlMEdGSAD07kUcjF2FHQfqPEsaDHu1OV0WOQq7 sN4TdRUM94GvAlvQiDJhmSKEbbrfuTRKOIfpM+FAzMd+Je3nd7a9m0haXnFt8L7hlUDx WSL/cZNhCFYDf3Urbef/1h2/ih8HUGvkS+Op6LXO7gRivdFfUNUILGKQxA/4xS08pY9g m5Mpq0i1HPL1+xmW5ntnVBDt+5mmVWEI4X1xpzC7NagrGjvSoKh1+snv5ck8peI1bEDw seVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vkbsDVHf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si1516025oia.62.2020.03.26.13.48.24; Thu, 26 Mar 2020 13:48:37 -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; dkim=pass header.i=@kernel.org header.s=default header.b=vkbsDVHf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbgCZUsK (ORCPT + 99 others); Thu, 26 Mar 2020 16:48:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:53104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbgCZUsJ (ORCPT ); Thu, 26 Mar 2020 16:48:09 -0400 Received: from localhost (mobile-166-175-186-165.mycingular.net [166.175.186.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B60FF2070A; Thu, 26 Mar 2020 20:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585255689; bh=6RKen0ioTy65oeuJuXAtJ6M2BJxU8YbCxuM+rKEX6NY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=vkbsDVHff3CZYPxtxcc0HH1/CZg3CSmvig9OJyTv8xuiWi01uIYoBe5p1UK/juO07 W2cirk8UdPTFG/Fx2mEs/VvE9am3rbh8UJYQ7Dufa7Y1+2lSDW8ps9HN3qv87cQc1I XwxIrq10sk/x+sVNQpLiRH+unIfFfgKFXSCP8zwc= Date: Thu, 26 Mar 2020 15:48:07 -0500 From: Bjorn Helgaas To: Ray Jui Cc: Srinath Mannam , Lorenzo Pieralisi , Florian Fainelli , Ray Jui , Andrew Murray , bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bharat Gooty Subject: Re: [PATCH 1/3] PCI: iproc: fix out of bound array access Message-ID: <20200326204807.GA87784@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a836faf-645d-a1ab-d525-738a318758a0@broadcom.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2020 at 01:27:36PM -0700, Ray Jui wrote: > On 3/26/2020 12:48 PM, Bjorn Helgaas wrote: > > ... > > It's outside the scope of this patch, but I'm not really a fan of the > > pcie->reg_offsets[] scheme this driver uses to deal with these > > differences. There usually seems to be *something* that keeps the > > driver from referencing registers that don't exist, but it doesn't > > seem like the mechanism is very consistent or robust: > > > > - IPROC_PCIE_LINK_STATUS is implemented by PAXB but not PAXC. > > iproc_pcie_check_link() avoids using it if "ep_is_internal", which > > is set for PAXC and PAXC_V2. Not an obvious connection. > > > > - IPROC_PCIE_CLK_CTRL is implemented for PAXB and PAXC_V1, but not > > PAXC_V2. iproc_pcie_perst_ctrl() avoids using it ep_is_internal", > > so it *doesn't* use it for PAXC_V1, which does implement it. > > Maybe a bug, maybe intentional; I can't tell. > > > > - IPROC_PCIE_INTX_EN is only implemented by PAXB (not PAXC), but > > AFAICT, we always call iproc_pcie_enable() and rely on > > iproc_pcie_write_reg() silently drop the write to it on PAXC. > > > > - IPROC_PCIE_OARR0 is implemented by PAXB and PAXB_V2 and used by > > iproc_pcie_map_ranges(), which is called if "need_ob_cfg", which > > is set if there's a "brcm,pcie-ob" DT property. No clear > > connection to PAXB. > > > > I think it would be more readable if we used a single variant > > identifier consistently, e.g., the "pcie->type" already used in > > iproc_pcie_msi_steer(), or maybe a set of variant-specific function > > pointers as pcie-qcom.c does. > > It is not possible to use a single variant identifier consistently, > i.e., 'pcie->type'. Many of these features are controller revision > specific, and certain revisions of the controllers may all have a > certain feature, while other revisions of the controllers do not. In > addition, there are overlap in features across different controllers. > > IMO, it makes sense to have feature specific flags or booleans, and have > those features enabled or disabled based on 'pcie->type', which is what > the current driver does, but like you pointed out, what the driver > failed is to do this consistently. There are several drivers that have the same problem of dealing with different revisions of hardware. It would be nice to do it in a consistent style, whatever that is. > The IPROC_PCIE_INTX_EN example you pointed out is a good example. I > agree with you that we shouldn't rely on iproc_pcie_write_reg to > silently drop the operation for PAXC. We should add code to make it > explictly obvious that legacy interrupt is not supported in all PAXC > controllers. > > pcie->pcie->reg_offsets[] scheme was not intended to be used to silently > drop register access that are activated based on features. It's a > mistake that should be fixed if some code in the driver is done that > way, as you pointed out. That's actually why I dug into this a bit -- the iproc_pcie_reg_is_invalid() case is really a design-time error, so it seemed like there should be a WARN() there instead of silently returning 0 or ignoring a write. Bjorn