Received: by 2002:ab2:6816:0:b0:1f8:1780:a4ed with SMTP id t22csp20345lqo; Thu, 9 May 2024 10:04:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNwAojCYtHoJokmXGVM+wRbEbNC5e1I74BdcTRfdEwKj3oEif45VR2AOs75dHNF3kWAn8gIxy6NgusyVIAh3gJEhrzyppQL0Jq+oVvNQ== X-Google-Smtp-Source: AGHT+IGDZdVJDkzFgb3r2qrpAFCTBNzlCBofBm8C+P/b+QZY3kggKFmkoA1f5kC2WREdLAQI3CWr X-Received: by 2002:a05:6e02:1565:b0:36c:4dab:7716 with SMTP id e9e14a558f8ab-36cc144b143mr3520665ab.11.1715274299669; Thu, 09 May 2024 10:04:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715274299; cv=pass; d=google.com; s=arc-20160816; b=jGGtwmtXsKLd41QHmb8vR0Yexo94oH3peA6QpjaONze/Y31gaKsk1Xay6S/dGKFIRg fxvXZQ1sfCnZCTX2yCGjId9e4SRgogHhiUd/SUBhedkklcUVBHo7nhcIXjGeLWGlQcjQ 7GQDZTZ7GqALjaxNWZene5P0lFdM4VtO8aEmh6eMzKWt5gO8CZWLOmkVmQDwayPLO46b 0zvwhi/Ur0fhvO947kyjKN3spnFcTyskbaIBWKegw3oRs7Yczky9s+0ZuTQr7N4+8GFm Q2ESu7GUGg1y9VO38cO/axTEV48Cmeh66MKwujly9UDYTMUE5lSdDjGkt9WD7G1Ypu5Q CuwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=L2uLGcvBxd2hLnESknxJAQI7DZuv7IeRCLTisqkwp88=; fh=WOR2py8z6jJwfzk6pPs+kywHuENTpy7+UK5tnRqxkJc=; b=VfcHul/lz/Uxg/GJH5p/zg/Gl7rHb8ZsTqUEg1YqFp+5MIM8SStlsyPDRUBE7QYI8+ wVvHgeYRL30aViafLQm3ek0KYI5B0VvX1w+KACO+3ISg5n9cxwwQ5FF8HJ2vsNR8umon kBtKV3ABSOLhtQ8grmNdj3d/T9Hr9sLwfVqhBDItdfX67oPwS6jWQSCJ4L3jXOc7Fy1E rLJ8iugZcluxrXPPtAlEDYTjeEPImBPcbjSU4WvjhvRWrlsdIEsaY1RT+0alwhF5+zRQ 1PQJ4NUNAc7QwPqvfe1xWF/2m45lqtup0WyOGhDRDiXl7qOqe461NUUBegKr4NvMm7At Xjlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-174712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174712-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6340b395601si1750338a12.245.2024.05.09.10.04.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:04:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-174712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174712-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 54548B21BE9 for ; Thu, 9 May 2024 17:04:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0116C132; Thu, 9 May 2024 17:04:46 +0000 (UTC) Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [83.223.95.100]) (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 C325C4C8B; Thu, 9 May 2024 17:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.223.95.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715274286; cv=none; b=IIcL7fEQduAR4njPxrqLRr7litDpKuecu7NO/me+64VghHivEUoFm/8TdxbWmWdTauox6q/jWoRBs8y07NQxUnfJ6pMjfl8oj6N0VpVsRL4l4KgM+z4O9D4rsulm4WD+JOdqTY/TAqFFKTobxV4HkZfKCJu+umkCNXJqLvtuHHA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715274286; c=relaxed/simple; bh=jRJENUshDFsZV0tAZUXv5gYyUnozVPD/3nComIwGvsw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gmNM+nVhPsEppvZP8TQ21GeEk5qtIR4/49wolTwymANOSS5lHj3TOVEKzhoWeaLNR8AdihHjxTbBZ0Zz7aVX1PLMhV/LWs1wwBNaQn2NRya6zlj9MeWPku9C7FQlj10Z6HSPEuzL3IvleWhf3armHOdDyawoJGEMInaOghTPivo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de; spf=none smtp.mailfrom=h08.hostsharing.net; arc=none smtp.client-ip=83.223.95.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id EF02830013CCC; Thu, 9 May 2024 19:04:32 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D919F3FCAA; Thu, 9 May 2024 19:04:32 +0200 (CEST) Date: Thu, 9 May 2024 19:04:32 +0200 From: Lukas Wunner To: bcfradella@proton.me, Shinichiro Kawasaki , Klara Modin , Andy Shevchenko , Danil Rybakov Cc: Hans de Goede , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Fradella , Ranjan Dutta , Yifan2 Li , Jonathan Yong Subject: Re: [PATCH] p2sb: Don't init until unassigned resources have been assigned. Message-ID: References: <20240509164905.41016-1-bcfradella@proton.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240509164905.41016-1-bcfradella@proton.me> [cc += Shin'ichiro, Klara, Andy, Danil] On Thu, May 09, 2024 at 04:49:34PM +0000, bcfradella@proton.me wrote: > 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 > --- > 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); > -- > 2.43.0