Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2134683lqb; Mon, 27 May 2024 08:56:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUik/JnZNhfC7FXiXcLs5zjpB4J4Kj8uHekm29/20IU+czoDHmjjUe2PrnvKV8H97bdKT6iszW64ak/XU3gyLI4D/u/Wbhg8uiNG719Iw== X-Google-Smtp-Source: AGHT+IGowpumOw+Dqqw7IKXdAoBq2RjmJAKIorChuZxSueNvmGydW6uBX5WFGA+Hl4hgZiCF195j X-Received: by 2002:a05:6214:4a07:b0:6ab:7234:4c85 with SMTP id 6a1803df08f44-6abc7b9d839mr109885256d6.32.1716825401261; Mon, 27 May 2024 08:56:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716825401; cv=pass; d=google.com; s=arc-20160816; b=YP8AYNxXwIsQuOmalLOgXd2dOq7TMa9xgFu8Rex/FeGFa8vR5cgBY92rG/bQBoQs2I vYaVlqFB5YLZwMWVkbT9RwW4NNRR4GZUv5RXDo5qGwQxwjP/tiCPAFJ/+/4lYQAPEVN1 bU1yG0bq6RYrFsCyT/ywUuS/KJZjcdchAFBDkouhevoe979wJ9yWRxC4N1ppRUE7Xs0d O9jMk80THZ2KdZ+4gOx1sqV0CSIvkJu2x/LQiwwRrFZMWOKDNLuem+ObGbMdNwdKPu03 vNVuplJB1T59DXW9d60+BCNXKDrp0RhYNxPmIGBGZAB3+sXgU3UTtKwvZdFH72pe4eaU Bb+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Apws5MQciMACWfya9GFFoiN4XfHPunDRnqxlK3qdtYc=; fh=fLJgs4CLnD2udeePWycnnSRNo5Re/2E4T+juB9dm4gY=; b=Otzpn2HSyeauUTJUTNN8Op+vSFvk7HQEoHtiB7Thv5Bo6MevujKEHBJaky+edITlQu RXfzuPHZW3r35q2GFiYDxKw9FtKsCyUhMcTa806up2EGOJSVjZiJlzp5EZyAEU00jY5/ iptstReh05uG/IFWGhTeKGUzZrsiynk++bopvD1ZR7f7AREakRuTWcAJzxqK8dWBpfki 9mqgH6L88oLf4NCzGgB3E175msbGFR8OdhikmuQ7kq15cupCHl6jAnQHwmtPE6n1UW8n qymb8BVKyETtFghJo+YranHBkMboCpCWn6sLj+XTM4NjPWaMAzcGtwyT19wsxFJwHYa1 9qww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qJYh+veD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac070f1437si82753186d6.216.2024.05.27.08.56.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 08:56:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qJYh+veD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 061D31C223AE for ; Mon, 27 May 2024 15:56:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E12C51667F5; Mon, 27 May 2024 15:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qJYh+veD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0D15F1667E3; Mon, 27 May 2024 15:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825182; cv=none; b=tM5oQYNnyhiRuHHijDMykjD7pXZHGM7eRaXJqbqDJxM67Xqr8QnDpSu1bp4d+p9ILvRPg6yN/MKZLXkKqBua2uVdwj7CM18gqeidYzMmdl2/RouHloQyit7KuKbSjJKfSpHn6jcDKWABPp8rGskGl+8KWWCJEKvC7GtcFXU5Xyk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825182; c=relaxed/simple; bh=9O1/9N+pW9u9GQ2iwg/POokNTzd/48jaP6RProOYYSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SeaniQC3qv4hY306cBh7JtdneSeHn8i5k3rpIWxtScXlHjnXHbPk10N6WUaYyR4uxXQDTQk50gRduNHgSEa13Kz3rbq6/TyDsPAmcmkVe6M78VkrFZAFO6/3RCy6pOwANkeu0xOuRodo7tfYD44BUBh7S9zmZg/2IOpxIf44oaU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qJYh+veD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CEF2C4AF08; Mon, 27 May 2024 15:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716825181; bh=9O1/9N+pW9u9GQ2iwg/POokNTzd/48jaP6RProOYYSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJYh+veD6vhQBJz9+nLjnSnUhjjCUo3R/bMVErZj4rGep8SzcHVQ0zvQHU8BGhs9Q Y1b/aXM5KkZLPmfV1Ba/GE0tj8jiLSlUZv/MEbQINXAKAUVATOVztUNABUoFJ/x6w4 leGK072Bf97OE6C4lbZ8K3rIM4Beg3EJDCX/8Qn0ubULicReqEo4vo5roKHjAfRzdd FE5hJpoxuD4B1neS6L/McWzVM4Ih+agU+frnTsI4e62AZbEqvfDuJbO/1ENtYlqT2U XPYWTSIq+34q++MNIw6IsdiBvnuJbxjU/OMMCWeQ+qFmmhxt8NTrWrH9l/YvHuCtAa MrcqBHAeojnXw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ben Fradella , Andy Shevchenko , Klara Modin , Shin'ichiro Kawasaki , Hans de Goede , Sasha Levin , ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org Subject: [PATCH AUTOSEL 6.9 23/23] platform/x86: p2sb: Don't init until unassigned resources have been assigned Date: Mon, 27 May 2024 11:50:24 -0400 Message-ID: <20240527155123.3863983-23-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527155123.3863983-1-sashal@kernel.org> References: <20240527155123.3863983-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.2 Content-Transfer-Encoding: 8bit From: Ben Fradella [ Upstream commit 2c6370e6607663fc5fa0fd9ed58e2e01014898c7 ] 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 Link: https://lore.kernel.org/r/20240509164905.41016-1-bcfradella@proton.me Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede Signed-off-by: Sasha Levin --- 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 3d66e1d4eb1f5..1ac30034f3e59 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); -- 2.43.0