From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753195AbbIWTjr (ORCPT ); Wed, 23 Sep 2015 15:39:47 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:50180 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751033AbbIWTjp (ORCPT ); Wed, 23 Sep 2015 15:39:45 -0400 From: Arnd Bergmann To: Will Deacon Cc: "linux-arm-kernel@lists.infradead.org" , David Daney , Mark Rutland , "devicetree@vger.kernel.org" , Pawel Moll , Ian Campbell , Marc Zyngier , "linux-pci@vger.kernel.org" , David Daney , "linux-kernel@vger.kernel.org" , Rob Herring , David Daney , Kumar Gala , Bjorn Helgaas Subject: Re: [PATCH v2 4/5] PCI: generic: Correct, and avoid overflow, in bus_max calculation. Date: Wed, 23 Sep 2015 21:39:27 +0200 Message-ID: <1707525.QvfFzUYq4E@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20150923193545.GZ7356@arm.com> References: <1442527332-1174-1-git-send-email-ddaney.cavm@gmail.com> <3751968.n8LRgots8n@wuerfel> <20150923193545.GZ7356@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:pl54us28WuUqB2/vKi/puL9i+CXRHG3gkKjJApiE9DUXUE88d5V C8wM3h8BVpdy7ojsOErBekHX+Yc3Nr3ccMvfpZ6fgcZn754w21IPcRVjmNB/z9Br1I1TxMd 1rt6qVX20qErq+vfaaKU8eik0FejrMyV0mQA0WwY1a8zCqo1D1KpIKRTmE/Gs/iC6GCE0ti 9LBrHSdsqoLhqWdDO9EYA== X-UI-Out-Filterresults: notjunk:1;V01:K0:YQHfNRVH5Tc=:Du+K5c80z6hVGPYWfsE0xb U0BybNydXZyr2AkhCBKatt5g4qDxkMIOvwmHBp+XGJjjgcmUU/mxWQctZmsaMvTJXvOGCUpd6 pgvkEG4BGPvSfK1IJyMiZWWgY62mVRLCgWQ1o+3pWE8Khfq4rnge54tMFVb9/k6zntmpzbQH5 l9NJ9MXguvlaXQ9c+VtvDivTaU+NYwYY9BJ3mJ4PaCdeuIh7Fu8wptvYTtC9tr0XCn04h40Iw cak9dvBELTJYsCEsEX04TaBl/nUJ/Yb6VcZTOvLK91W1X8s0FWOs2h/ghG14R4ot9lz6rFl+R Q0x+Nr6ABmOP1ioOiTmUUOoSyYlgY6wRmY7KzOy64WgQVG/9v5G8LTNX7jzRWo3qB7nFrFLrk /gWGgjDXox7/xvacIZZcxc+LO5bwPIdL49Fdl4Y0Rgb9P6X9mEMO3N+0uGLvfST2zCbN7csG/ 7MzN/Qd3dT565Bfntcsx/u+BhjoyTfK/CY0RN6N95QQYzH7MJF22PmRxaOOrMS4R3icnr+XuY v2c9J3zyDGcXdXY58VWVP3m7AStbxEvad2cXJj1vq9YFotpF4aPtyj0tKmVJ5e7lWzWsl6/e2 7bzH5qK2qgpo5LzCTK0TqbfYGBIME3HrG+6xGJQSQ22rB/cObEfDZQkE4lLuHYO0HkWx5+NU2 sqKvL/ik7jTvKAer031Fk7wBacZVHp0Zi10Gb7QOss84ngYA/GqkXcjGWEuRM5zR0QkMOLLG8 qPcz+j/KxHQuqOLG Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 23 September 2015 20:35:45 Will Deacon wrote: > On Wed, Sep 23, 2015 at 08:27:41PM +0100, Arnd Bergmann wrote: > > On Wednesday 23 September 2015 11:21:56 David Daney wrote: > > > >> > > > >> /* Limit the bus-range to fit within reg */ > > > >> - bus_max = pci->cfg.bus_range->start + > > > >> - (resource_size(&pci->cfg.res) >> pci->cfg.ops.bus_shift) - 1; > > > >> + bus_max = (resource_size(&pci->cfg.res) >> pci->cfg.ops.bus_shift) - 1; > > > >> + if (bus_max > 255) > > > >> + bus_max = 255; > > > > > > > > I still don't understand the need for this part. If the cfg space is bigger > > > > than bus_max, isn't that simply an invalid resource? Given that the resource > > > > could be broken in other ways too, this check feels more like a specific > > > > workaround rather than generally useful code. > > > > > > Imagine... > > > > > > bus-range [0x80 .. 0xff], this requires a cfg.res that will cover the > > > entire range of 0..0xff. > > > > > > according to the calculations above, (resource_size(&pci->cfg.res) >> > > > pci->cfg.ops.bus_shift) - 1 will have a value of 0xff, so... > > > > Extending the computation to 32 bit seems fine, but I'd rather warn loudly > > if the bus range does not fit within the registers. > > > > Also note that the computation is already correct with my interpretation > > of the reg property. > > From what Lorenzo was saying, ACPI shares the interpretation that David is > implementing here and, given that the DT version seems to be subjective, > aligning this reg property with MMCFG seems to make sense. We should then make it very clear in the binding that the driver is not allowed to actually map the registers for the buses outside of the bus-range, as that is highly unusual. We would also need a special exception for this if we ever get to implement the DT source checker that we have been talking about for years, as the reg property might then overlap with a property from another device. Arnd