From patchwork Thu May 9 16:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bcfradella@proton.me X-Patchwork-Id: 13659944 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88D6B4C70; Thu, 9 May 2024 16:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.77.79.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715273396; cv=none; b=qRXfPCn0gQfsiXvAibHiz6g+vzRETitmuPCJ58kY/yPd/d/mFIUCukER3qBB12lGDZUP9VWY9+3PbYAGTvxJ0FcQEe8cXVR6+c0rfIrLaN4pP9e8exXnZHxgJo/OCWA65481HNGWxCpalLRje2gwAgwQ3rYfi/uCSII35GfIt80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715273396; c=relaxed/simple; bh=Gf9y6jAuMcgqo9Gd+TKKg5IoxCdtOXzzseeLVLgbN/E=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=n7m6qN4FT1Hta53QVf2JoX/yCUBGg+5SnFCWG2dL3j5Z+29HyYJZcPwdz18fldfcLhdvNKeRutoIcCsfEXq2au1b6g/n+1L/OVlo9XGSwmEHvnnpmGQIU/H/wX/gFYOZ97FJjywEbGNB3FPCs9FNjMnTHJDQeD2xy2c2uva5LdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=CqCwZqh9; arc=none smtp.client-ip=51.77.79.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="CqCwZqh9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1715273380; x=1715532580; bh=C60PPXrDiM6US9HUzSb1J44PAIcjYzqF9scPyqWaHcQ=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=CqCwZqh98z416mS2XCKqzmuiyUHMyT0Y7GpREyNWr0KK8SXQJj9rtR148itRyPaUx cNn6GMjx1gIS5AuK1/E/BQIgB17tmnazOQypBfHRiWndN5EdDBtJXsBtPYHAX1/dkH vBkfA2BY6/lzqcHw8SssMw2/OqQjg/klxkHNqMPPnQFWejgh84NHN9E/3Z3w5PteyL IZwHYMZ+HcW/ZpuBxPW52JQmk2dVu0QJooQA4E9AOeLwsorToK0oRYk8DAx4i1f18Z 7vMqY2W0hBfb/SAuOxtIck6yLIQiX5PB+q3AIk8FvstCPM6O0SRcOTfRcUR8vS1w7/ kyrDRiw9GdxLw== Date: Thu, 09 May 2024 16:49:34 +0000 To: Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org From: bcfradella@proton.me Cc: Ben Fradella , Ranjan Dutta , Yifan2 Li , Jonathan Yong Subject: [PATCH] p2sb: Don't init until unassigned resources have been assigned. Message-ID: <20240509164905.41016-1-bcfradella@proton.me> Feedback-ID: 52522960:user:proton X-Pm-Message-ID: b9b1474f879f010a3fa2db3d7408df99edc412c6 Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Ben Fradella The P2SB could get an invalid BAR from the BIOS, and that won't be fixed up until pcibios_assign_resources(), which is an fs_initcall(). - Move p2sb_fs_init() to an fs_initcall_sync(). This is still early enough to avoid a race with any dependent drivers. - Add a check for IORESOURCE_UNSET in p2sb_valid_resource() to catch unset BARs going forward. - Return error values from p2sb_fs_init() so that the 'initcall_debug' cmdline arg provides useful data. Signed-off-by: Ben Fradella Acked-by: Andy Shevchenko Tested-by: Klara Modin Reviewed-by: Shin'ichiro Kawasaki --- drivers/platform/x86/p2sb.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c index 3d66e1d4eb1f..1938a3ef9480 100644 --- a/drivers/platform/x86/p2sb.c +++ b/drivers/platform/x86/p2sb.c @@ -56,12 +56,9 @@ static int p2sb_get_devfn(unsigned int *devfn) return 0; } -static bool p2sb_valid_resource(struct resource *res) +static bool p2sb_valid_resource(const struct resource *res) { - if (res->flags) - return true; - - return false; + return res->flags & ~IORESOURCE_UNSET; } /* Copy resource from the first BAR of the device in question */ @@ -220,16 +217,20 @@ EXPORT_SYMBOL_GPL(p2sb_bar); static int __init p2sb_fs_init(void) { - p2sb_cache_resources(); - return 0; + return p2sb_cache_resources(); } /* - * pci_rescan_remove_lock to avoid access to unhidden P2SB devices can - * not be locked in sysfs pci bus rescan path because of deadlock. To - * avoid the deadlock, access to P2SB devices with the lock at an early - * step in kernel initialization and cache required resources. This - * should happen after subsys_initcall which initializes PCI subsystem - * and before device_initcall which requires P2SB resources. + * pci_rescan_remove_lock() can not be locked in sysfs pci bus rescan path + * because of deadlock. To avoid the deadlock, access P2SB devices with the lock + * at an early step in kernel initialization and cache required resources. + * + * We want to run as early as possible. If the P2SB was assigned a bad BAR, + * we'll need to wait on pcibios_assign_resources() to fix it. So, our list of + * initcall dependencies looks something like this: + * + * ... + * subsys_initcall (pci_subsys_init) + * fs_initcall (pcibios_assign_resources) */ -fs_initcall(p2sb_fs_init); +fs_initcall_sync(p2sb_fs_init);