From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932524AbcFIQh5 (ORCPT ); Thu, 9 Jun 2016 12:37:57 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:35896 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932066AbcFIQhz (ORCPT ); Thu, 9 Jun 2016 12:37:55 -0400 MIME-Version: 1.0 In-Reply-To: <20160609110424.GA19470@wunner.de> References: <82c2548dffc6cfbc484b9111b1073f407c946061.1464477483.git.lukas@wunner.de> <20160608200929.GA18981@wunner.de> <20160609064803.GA10996@gmail.com> <20160609110424.GA19470@wunner.de> From: Yinghai Lu Date: Thu, 9 Jun 2016 09:37:53 -0700 X-Google-Sender-Auth: 0Dwv-BnLwMuuzXhPxPBI1uOxgFg Message-ID: Subject: Re: [tip:x86/urgent] x86/quirks: Add early quirk to reset Apple AirPort card To: Lukas Wunner Cc: Ingo Molnar , Thomas Gleixner , cmilsted@redhat.com, "Rafa?? Mi??ecki" , Bjorn Helgaas , "H. Peter Anvin" , Matt Fleming , Peter Zijlstra , Linux Kernel Mailing List , Linus Torvalds , Matthew Garrett , m@bues.ch, "linux-tip-commits@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 9, 2016 at 4:04 AM, Lukas Wunner wrote: > Subject: [PATCH] x86/quirks: Validate secondary bus number > > We used to brute-force scan buses 0 to 31 until commit 8659c406ade3 > ("x86: only scan the root bus in early PCI quirks") constrained the scan > to the root bus, in part to shorten boot time. > > Commit 625a99d9bfd0 ("x86/quirks: Add early quirk to reset Apple AirPort > card") reintroduced scanning of secondary buses, but used a recursive > strategy to scan only buses that are actually present. > > However the secondary bus number read from a bridge's config space may > be invalid, in particular a value of 0 causes an infinite loop. The PCI > core goes beyond that and recurses to a child bus only if its bus number > is greater than the parent bus number (see pci_scan_bridge()). Since the > root bus is numbered 0, this implies that secondary buses may not be 0. > Do the same on early scanning. > > Suggested-by: Yinghai Lu > Fixes: 625a99d9bfd0 ("x86/quirks: Add early quirk to reset Apple AirPort card") > Signed-off-by: Lukas Wunner > --- > arch/x86/kernel/early-quirks.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c > index 4e4e499..c24070e 100644 > --- a/arch/x86/kernel/early-quirks.c > +++ b/arch/x86/kernel/early-quirks.c > @@ -747,7 +747,8 @@ static int __init check_dev_quirk(int num, int slot, int func) > > if ((type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) { > sec = read_pci_config_byte(num, slot, func, PCI_SECONDARY_BUS); > - early_pci_scan_bus(sec); > + if (sec > num) > + early_pci_scan_bus(sec); > } > > if (!(type & 0x80)) If two bridges have sec, then early_pci_scan_bus still could be called two times. Maybe we can add one static array to recorded scanned bus. static unsigned char scanned_bus[256]; and in early_pci_scan_bus check and set that before scanning. Thanks Yinghai