From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755116AbbIWPu4 (ORCPT ); Wed, 23 Sep 2015 11:50:56 -0400 Received: from mail-bn1bon0080.outbound.protection.outlook.com ([157.56.111.80]:4176 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752363AbbIWPux (ORCPT ); Wed, 23 Sep 2015 11:50:53 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Daney@caviumnetworks.com; Message-ID: <5602CA55.10604@caviumnetworks.com> Date: Wed, 23 Sep 2015 08:50:45 -0700 From: David Daney User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Arnd Bergmann CC: , David Daney , , Bjorn Helgaas , , Will Deacon , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , , Marc Zyngier , David Daney Subject: Re: [PATCH v3 4/6] PCI: generic: Correct, and avoid overflow, in bus_max calculation. References: <1442965757-12925-1-git-send-email-ddaney.cavm@gmail.com> <1442965757-12925-5-git-send-email-ddaney.cavm@gmail.com> <1496061.0ds89jTH75@wuerfel> In-Reply-To: <1496061.0ds89jTH75@wuerfel> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [64.2.3.194] X-ClientProxiedBy: SN2PR07CA012.namprd07.prod.outlook.com (10.255.174.29) To BLUPR0701MB1715.namprd07.prod.outlook.com (25.163.85.141) X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1715;2:NzosvD0Eux3dr9rAXfXkJ75OBjJJkE3TzZRvS/D2vD2l4XyN5/bhPMEJ5Kj0Igu4lf5ANGfnVvepLHO5tHud+g85k3QHMu2aM/rkcz7Y6nq70ahyyna2Jeryy76eUlhITvht6qdeVQAGSq8+02etVcge30wL/oUqMN57JDw/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P5Zc0oM5twABPh9s/hMwVaDZ+1DcfEZ/XNVMPbobjTD2xkoPToEq/DiZ8H5oCdkNWfr2NPU3A6RU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001);SRVR:BLUPR0701MB1715;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0701MB1715; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1715;4:ZTnlIqECCy/wNV41+mpCyIFLxy6AchxYRCgs8G+RQRNCgoxauZp/jrJCU49VgRZsNOJrm6RlDJ3uV8NfCf0i2jxYDDaEkFp2l5GDwovjpFnMJDHsjUMxQ1kFQwyGuBXe7bh65zOSosS2Ha+Ff26aW/P44HSbYe/zjA3TZnC0V6QutFjMGAyRZLHrtUgohkhhsjSI2mWsn//99PyYWYhfeK3tdcXOMWO2QPUoER4lq6oaSdHKQciIBlWGvoeWTZlwUIo444Z6e4hGvSY0hvFYBpLdpeI3RG0g1XTXc8nzm+yKUnR0oE+lFyYgjaigTf6IhUJO/BnFS3i7GpfY81O2IdLnmT9QozNcPkBHAP/VEgY= X-Forefront-PRVS: 07083FF734 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(189002)(243025005)(377454003)(479174004)(24454002)(199003)(33656002)(106356001)(105586002)(101416001)(68736005)(77096005)(50466002)(110136002)(5001960100002)(189998001)(83506001)(15975445007)(65816999)(77156002)(62966003)(54356999)(50986999)(76176999)(5004730100002)(46102003)(5007970100001)(40100003)(2950100001)(87976001)(19580395003)(36756003)(19580405001)(122386002)(69596002)(97736004)(92566002)(5001830100001)(5001860100001)(64126003)(81156007)(23756003)(4001540100001)(4001350100001)(66066001)(65806001)(65956001)(47776003)(64706001)(53416004)(42186005)(41533002);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0701MB1715;H:dl.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;BLUPR0701MB1715;23:aWY5wJeq+ogZDOUkZACvTHuPFFiruHoSZPiue?= =?iso-8859-1?Q?Lb8/nwRZ0I1V+KdBj/1tBYtfxcL5Fq10pANKrECnELPrpqaLL9ywNjqkER?= =?iso-8859-1?Q?+RZjnte3zZq1XOKPjdnEDyEY+y5dVlXnKTL7xVyEL/UVS5WW+wqUP2q8eV?= =?iso-8859-1?Q?m6H7ysTPT8jRuai5wz8EDmflGGNtRqvOj3OjiD9OFxHDZ3uNZg+sPNpFt7?= =?iso-8859-1?Q?7TZoNWNKNkTIQ+hnwgKyYHmzsQu+ph8aeAq7B/Az03xgmM0W1MOv70gmPr?= =?iso-8859-1?Q?IKt+Yc4thNoq3N2n7YVnzajXH92CporxbaRkDUoNuuEpJq/k2kWQbT1EnZ?= =?iso-8859-1?Q?eheW1VSASh6cs3ciTykSVB03dZ8vWDHDHwnC6etWDzfmObjHeRMqO1fsQq?= =?iso-8859-1?Q?yVor3chbTqJF2oB4kJbCXs3VMkUokfpaxdbXVCjZjP3Uk8OzvPapHrPkpw?= =?iso-8859-1?Q?tGr39M0uFtkt1Np3o4QrrPw09z5eq3lJXnGc8VgpWba9CfDAa6KAsKlITb?= =?iso-8859-1?Q?vGoIwTBPN3BHmV/1qbslK3nOkwXYu5ULnB4jaxdSyZn9FingdQN9zEKTSY?= =?iso-8859-1?Q?1LvPTGE65IaOGH1gdk91XVMCzm+GsiG+ZeGWrB2l+OyA0wd+tA4FD8MN6x?= =?iso-8859-1?Q?7oSFI2iFOyas1iY14Jx1j1RZ8psv9WYO+20RBlCL9MAIXWBnFGWZUr36Zl?= =?iso-8859-1?Q?6HFIbj2YKjTQFsaTpbWErxxW0GRettxLf3FpA+43wMA8MsllMGNiCjJNn8?= =?iso-8859-1?Q?S58Iii2dT/7uvh5tNcCKJzzmEEglbfgrUTt6WeRTMuB0uHKIvJjX4/Tlr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iRbqFBS2tsu1xpAsL37CL3q6IxEEfs=;20:qDc1HGrOTOaMpOAKkHtGIdty/s739KPauFHNJULI4XwLfLg16/jDFOOgTz+jCLilEwsk+6SDwar9Fsu7DJC00g== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2015 15:50:49.4064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1715 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/23/2015 01:01 AM, Arnd Bergmann wrote: > On Tuesday 22 September 2015 16:49:15 David Daney wrote: >> From: David Daney >> >> There are two problems with the bus_max calculation: >> >> 1) The u8 data type can overflow for large config space windows. >> >> 2) The calculation is incorrect for a bus range that doesn't start at >> zero. >> >> Since the configuration space is relative to bus zero, make bus_max >> just be the size of the config window scaled by bus_shift. Then clamp >> it to a maximum of 255, per PCI. Use a data type of int to avoid >> overflow problems. >> >> Update host-generic-pci.txt to clarify the semantics of the "reg" >> property with respect to non-zero starting bus numbers. >> >> Signed-off-by: David Daney > > Not sure about this one > >> diff --git a/Documentation/devicetree/bindings/pci/host-generic-pci.txt b/Documentation/devicetree/bindings/pci/host-generic-pci.txt >> index cf3e205..105a968 100644 >> --- a/Documentation/devicetree/bindings/pci/host-generic-pci.txt >> +++ b/Documentation/devicetree/bindings/pci/host-generic-pci.txt >> @@ -34,7 +34,9 @@ Properties of the host controller node: >> - #size-cells : Must be 2. >> >> - reg : The Configuration Space base address and size, as accessed >> - from the parent bus. >> + from the parent bus. The base address corresponds to >> + bus zero, even though the "bus-range" property may specify >> + a different starting bus number. > > This sounds like very unusual behavior. If you have a system with faked > bus numbers where the registers only physically exist for a subset of the > buses, this requires defining a reg property that contains MMIO space > which is outside of the device and potentially contains other devices. The pci-host-generic driver only maps the ranges that correspond to the "bus-range" buses, so mapping of illegal address ranges should not be a problem. > > What would break if we instead defined it the expected way and only > list the registers for the bus numbers in the "bus-range" property? I'm not sure if we have the luxury of being able to change the definition, although the existing code only works with a starting bus number of zero. From this we might conclude that non-zero starting bus numbers cannot exist in the wild, so changing the the definition of "reg" so that it starts at the starting bus number might be possible. My reading of: http://www.o3one.org/hwdocs/openfirmware/pci_supplement_2_1.pdf Section 3.1.1, does not preclude your interpretation. Although that is for PCI-PCI bridges, and not this pci-host-generic root complex. If we really want to go with a different definition of what the "reg" property means, then actual code has to change, and we risk breaking something. David Daney