From patchwork Fri Dec 22 12:28:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1025035dyi; Fri, 22 Dec 2023 04:30:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkal7+uT4iiota2HqwCEOXvpLipnlFvwhBa0jMXoF5ZiPrPgPQ2vUkWhDJjAiKrHRPR5j2 X-Received: by 2002:a05:6808:22a0:b0:3ae:1298:257a with SMTP id bo32-20020a05680822a000b003ae1298257amr1383731oib.1.1703248199810; Fri, 22 Dec 2023 04:29:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248199; cv=none; d=google.com; s=arc-20160816; b=Y5g6z+PxTJnd2LD7+tA430rJR1rNdBUbtPgtib/bHeoVNV4WpMf1wYqTzFf1g/8ul7 1EEY1VJouK+SyVmo2U5PghyxUWWqgKvVkgpet4WPPb310SmyNKjaM5fgiaQrnX4sLMRV 3dcBefk4tfzwZ/oQ0KLtNcIbIv29jXe55YeR4JgnAyV8Lf+tJkOzcZUogDmdheqmvzRP 7fhRtQITgQdYLk3wHk/yczSzRw+5zMLlT20tmAIkdLviTSHskWKrGlXNt/lDM2bXqLDX lv4Kn3T7vYuncZejiIRT5kGV7SDiTvX8zORMzDI4ErQNRIMTJVYEYCYmw4LiSqTDwFSC 4wZQ== ARC-Message-Signature: i=1; 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=gwEOFxbI2yDL2y6iq/2YGqhZ0x0H2WQKRKiCddsl91o=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=UWv4GATxaQdQHQtme9VaILfWCXGtSw9c35CHzO0LOLW1/nOPtFskL2G8EJcOqqJ99K puLzH94asG7qlsRo1wu3Vb8rljoM+z6VoYY62ujOHOQddTWWplq+LP7Xi9xgH7VAsdgD NaUEyNhc8Gz+OSxg28GHdCKYkBkPr36m9nULyx9sC0ugADDBEtQHRS2RQbi+w6kwdzyC TYBoEaWweO8y2oRmVcD0V+GEPaDeoHQQzF2+55EgKfpg+hWIpjZ2kBlrD2AB4x5OzwGg RnCs7yqRzpz4B+VTIP+I6fuLO4G9qX6y+wcSy0jLQhichp8WGX/mzkt5BEDa+rHbBC4w 3MnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=L7vgg2ex; spf=pass (google.com: domain of linux-kernel+bounces-9702-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9702-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w2-20020a0ce102000000b0067f89f0a735si2778821qvk.236.2023.12.22.04.29.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:29:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9702-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=L7vgg2ex; spf=pass (google.com: domain of linux-kernel+bounces-9702-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9702-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 862AB1C214AD for ; Fri, 22 Dec 2023 12:29:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5789A19BD3; Fri, 22 Dec 2023 12:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="L7vgg2ex" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 5B1A5199A1; Fri, 22 Dec 2023 12:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248168; x=1734784168; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LCe+OPVf6ypAOTjFWig95nNeJVsgngMAJh/hD3RJ254=; b=L7vgg2exjtHCbQFLj8azE2qQZPp1P/e1KlT2Bl+bdqyNxCM536S767yd lo1V9FNCaW3QkGUp3Ac5Bx74DlSs+nU2lNNJ5teENNfkO4nDJYI37TMqv Ua7XKpSF3Fsmx/K/uwpVI2jpbEwW6Njk5O3A3c9sgUsI83LMtffpttWQS YAB1GPE3Sqvfgb6cgN1CR1dsqfuLCILRd5P8yBOYcQ6aihXlQR10rwEf3 yj3z3fHWxDBKepEs1uboAtF41orgbZzJOziJETKAJ981e2UMOy2STU/5q 2oIQ8dDayblUVt6qDpZaowZ24LKAY7WTlbEddV2MDHY5VRU2Tnip9Dhy3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="17681298" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="17681298" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="950263952" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="950263952" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:22 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 1/7] PCI: Fix resource double counting on remove & rescan Date: Fri, 22 Dec 2023 14:28:55 +0200 Message-Id: <20231222122901.49538-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985184375764475 X-GMAIL-MSGID: 1785985184375764475 pbus_size_mem() keeps the size of the optional resources in children_add_size. When calculating the PCI bridge window size, calculate_memsize() lower bounds size by old_size before adding children_add_size and performing the window size alignment. This results in double counting for the resources in children_add_size because old_size may be based on the previous size of the bridge window after it has already included children_add_size (that is, size1 in pbus_size_mem() from an earlier invocation of that function). As a result, on repeated remove of the bus & rescan cycles the resource size keeps increasing when children_add_size is non-zero as can be seen from this extract: iomem0: 23fffd00000-23fffdfffff : PCI Bus 0000:03 iomem1: 20000000000-200001fffff : PCI Bus 0000:03 iomem2: 20000000000-200002fffff : PCI Bus 0000:03 iomem3: 20000000000-200003fffff : PCI Bus 0000:03 iomem4: 20000000000-200004fffff : PCI Bus 0000:03 Solve the double counting by moving old_size check later in calculate_memsize() so that children_add_size is already accounted for. After the patch, the bridge window retains its size as expected: iomem0: 23fffd00000-23fffdfffff : PCI Bus 0000:03 iomem1: 20000000000-200000fffff : PCI Bus 0000:03 iomem2: 20000000000-200000fffff : PCI Bus 0000:03 Fixes: a4ac9fea016f ("PCI : Calculate right add_size") Signed-off-by: Ilpo Järvinen --- drivers/pci/setup-bus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index fd74f1c99dba..e3e6ff8854a7 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -820,11 +820,9 @@ static resource_size_t calculate_memsize(resource_size_t size, size = min_size; if (old_size == 1) old_size = 0; - if (size < old_size) - size = old_size; - size = ALIGN(max(size, add_size) + children_add_size, align); - return size; + size = max(size, add_size) + children_add_size; + return ALIGN(max(size, old_size), align); } resource_size_t __weak pcibios_window_alignment(struct pci_bus *bus, From patchwork Fri Dec 22 12:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1025248dyi; Fri, 22 Dec 2023 04:30:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCaR+xxCsc0kiq85SMFvqS2md5rJJO0FihAXW+4z0/NXJxbIF9GBlGJw1kFKd/ZF53zzVE X-Received: by 2002:ad4:5963:0:b0:67f:2f17:e586 with SMTP id eq3-20020ad45963000000b0067f2f17e586mr1814873qvb.29.1703248219137; Fri, 22 Dec 2023 04:30:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248219; cv=none; d=google.com; s=arc-20160816; b=QMfD+yvVeVxYOO6PCE8mqqjIeTC7gTokM/XN754u5/yklK3/zVAtxu9QbNWA0trG4M idLGlEdzlFiA8HO+1GopYfYr+s6J2cz+biypjDjdJMxrqbXRM77ON1DTNzbJ7ZJgNxS7 PTLonFSqqIkC3yJ84FsGqCcTL+ixC/Agtwwl8dR+hRNGMNMro0toXPUzRrIauBeLBE/+ eyC5aTQyzzay8z0Hp+ZTw+eOGFNm00ys0QervH4K83pvnfsdDaXD00o0EsYtkM4NwD5N /MSR1pG1mWbsB2+TizZFoSNMBW5mvz9momoidr3SVhj/uzLltSH5wdxNd/0YYi6QOuHX jEVA== ARC-Message-Signature: i=1; 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=7E8yJdNIAjCM373VsAfPNBbwmjzSBgMf+0sKMRGWI7Y=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=xyrQy7t3GnRyueC0abLjx31Tfl2776EgMBokfTcuTOFuyyndj2G8oyKbexpTmSv+eN J2vdr7SWJCsuRlLQ23twHOkWr4o6+VTUvq2GoA9eXojT7wJSVG3H25C1udC8uq3+cULz 3Fq6TG4O3dlsYpCWMOWgMYyhpBZq8S4599Q2yBPLl3Xs8+3qWFaFkpRXRYqHp/eV8j/e qBPE8yj1paPPQ7ogI9kb4+r0bnJyuv8h2bXUaWEAu/G5EToZA/+4bnrYS31zvCLexwW5 sOdVB4el73Ju2kkYUeiW9gsPeEWQ24gqfomlviMOWVeEM+o0eWwBjCHD/MSCXdUTX1lP sdYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z6uTlkz8; spf=pass (google.com: domain of linux-kernel+bounces-9703-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9703-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r9-20020a0cb289000000b0067f94768e7bsi1516658qve.246.2023.12.22.04.30.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:30:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9703-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z6uTlkz8; spf=pass (google.com: domain of linux-kernel+bounces-9703-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9703-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 E7E8D1C21A0B for ; Fri, 22 Dec 2023 12:30:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D9761C6B6; Fri, 22 Dec 2023 12:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z6uTlkz8" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 52E9B18624; Fri, 22 Dec 2023 12:29:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248179; x=1734784179; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uopUxSQLxNwYXjsIbC+ClqKACsRbcTsdX+UmVSTtVOc=; b=Z6uTlkz8IxZ5uEJ+NrNTdjscP7v07R6PgYIsTQ5nClJX2uhJcTggcIWD JLE5giTh7LWP8g1VqlsD//WNokW03bSB6oVUfzP60/dHGHqXCsRXZJ16e iOJojXGbQLrdKfgVFy7bim7CMttIsDgOFrdloFLNHzale5hs60zHB1sEV /dItKDznMaVHHW2MjxEzCy3tV+Joo/Y4uNeLsdm34ZHOdJvPOJBwskyTw K7KKLEKrJQf8g7Zz9C/irq+BwqgHts5orfhe7E0jQZlj3ZraVJ+5VE8tO 7ohz6YXoFHKRAd9O3AhahwF6xtiOhNkXSi7tL98ZPYhmb3Q/zj14xyihS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="3195395" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="3195395" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="950263959" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="950263959" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:33 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 2/7] resource: Rename find_resource() to find_empty_resource_slot() Date: Fri, 22 Dec 2023 14:28:56 +0200 Message-Id: <20231222122901.49538-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985204109446173 X-GMAIL-MSGID: 1785985204109446173 Rename find_resource() to find_empty_resource_slot() to better describe what the functions does. This is a preparation for exposing it beyond resource.c which is needed by PCI core. Also rename the __ variant to match the names. Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- kernel/resource.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 866ef3663a0b..94f67005e1e2 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -574,10 +574,9 @@ static void resource_clip(struct resource *res, resource_size_t min, * Find empty slot in the resource tree with the given range and * alignment constraints */ -static int __find_resource(struct resource *root, struct resource *old, - struct resource *new, - resource_size_t size, - struct resource_constraint *constraint) +static int __find_empty_resource_slot(struct resource *root, struct resource *old, + struct resource *new, resource_size_t size, + struct resource_constraint *constraint) { struct resource *this = root->child; struct resource tmp = *new, avail, alloc; @@ -633,11 +632,11 @@ next: if (!this || this->end == root->end) /* * Find empty slot in the resource tree given range and alignment. */ -static int find_resource(struct resource *root, struct resource *new, - resource_size_t size, - struct resource_constraint *constraint) +static int find_empty_resource_slot(struct resource *root, struct resource *new, + resource_size_t size, + struct resource_constraint *constraint) { - return __find_resource(root, NULL, new, size, constraint); + return __find_empty_resource_slot(root, NULL, new, size, constraint); } /** @@ -660,7 +659,7 @@ static int reallocate_resource(struct resource *root, struct resource *old, write_lock(&resource_lock); - if ((err = __find_resource(root, old, &new, newsize, constraint))) + if ((err = __find_empty_resource_slot(root, old, &new, newsize, constraint))) goto out; if (resource_contains(&new, old)) { @@ -729,7 +728,7 @@ int allocate_resource(struct resource *root, struct resource *new, } write_lock(&resource_lock); - err = find_resource(root, new, size, &constraint); + err = find_empty_resource_slot(root, new, size, &constraint); if (err >= 0 && __request_resource(root, new)) err = -EBUSY; write_unlock(&resource_lock); From patchwork Fri Dec 22 12:28:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1026048dyi; Fri, 22 Dec 2023 04:31:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMAB7d3KI0mnRcpyzsiC7s7lrqWXPBKor+q4jCUqTFepXDLT1R7eJFiU0i60OeUaja/joj X-Received: by 2002:a05:6358:290b:b0:173:22a:635a with SMTP id y11-20020a056358290b00b00173022a635amr1458007rwb.30.1703248294856; Fri, 22 Dec 2023 04:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248294; cv=none; d=google.com; s=arc-20160816; b=V8CcIhI6gQp735LFBBtF155sIjJ4yHrXbkt8uVk+BwVsWHAJmGSMTsiyn/Rxkfc5z3 RqOG+k1X+x7UlX6Bznb8j1r73uNcoJOMs32ny9cbrywRyCfPs+ktJFAWXC7ozpqZQ2eX pz7BotzdNUhbOOy9v8XLj6z+t6LMBGBd16yOt3bmsXAKpNRVmJfFAzOja/Fx9PvXbYrM 4XpdE2lHNPjy/ofID07efcvZnfUMgYEaJLqdoxzk327+Sy2FWpH06JK5rj7/clvkhoUv bF2kZcJ2n16jzoS7E0oYez5cGPT+jmk8tphewWfTBnoZb7biPtATmxB06cAVPcI1Rz7u a4QA== ARC-Message-Signature: i=1; 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=TRtiGIc23qKmjrBNJ6QQXiMnNcX8EOgP8YFUxP6ho8Y=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=cSE00mBACNWviLNBw1Msl+4ucI2VOAH/zDJmxfYAGiMw7uRhpKviFfX4+xI/MWIDJU AXYRJvtQxcpe7xYmwijb30vtsEvqg9S55HnWWc6dwMq14KfxqC5WW8MT+91KmZd9oGtc tkkojJpcWWrmuY3bbFyER/aSBis6UVM8Um3jUNzWgCmKHA3Q5OG6d57cMxnpS7WEvHZU +dMwYv4UgSn9OOQumCIeckPKcFJ/mc97f2y7UCD6KbY//IT6HpiR18xjPfk9oyPo7REB 54omua0fWpHRmoyNrp09TsnzmphNX+2XTeMY4E0Z6lB7A1BBvgm/fpdW4cJ1LL6sp1KI MfMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JXXrO801; spf=pass (google.com: domain of linux-kernel+bounces-9704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9704-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jc8-20020a056a006c8800b006cd8cddf8c5si3296280pfb.14.2023.12.22.04.31.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:31:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JXXrO801; spf=pass (google.com: domain of linux-kernel+bounces-9704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9704-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 1552DB23BC6 for ; Fri, 22 Dec 2023 12:30:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A56FE199A1; Fri, 22 Dec 2023 12:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JXXrO801" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 AE6C218026; Fri, 22 Dec 2023 12:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248189; x=1734784189; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SPf7dIwu/u/tUoIaF73pw1QNlo/ef/Z/+GNbum46mDI=; b=JXXrO801MSdlKvcv99uRptsPnECD/eb/2tit8Cuquf9hTi9zMhTSYRaB +5n2Et2pIGDvsmov0XVqkWBQvygk80VzhU/CHFSaCS7oIaAyl1UvZDw39 cgI38674OliU7h9RlM7LI/xDCb0ofY54w9tKio4eqsC2V6rCOGPwmPpfB TDOraIWJjCeX8BuHuRnEmaQF49gzeaEtrm58Zwg8odGYNpo9IoUCl+x9C rhT/816JCeWNYoAPm/X+ZYYmUcCBd57aeQAD25UYa4SNfRr1NWwiRJu7L iPffobaqNuCBRgTjoDxkm36G2mq/EpOcWf3yKyZSDd8tmNCAwAtTOriQI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="3195422" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="3195422" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="950263970" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="950263970" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:44 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 3/7] resource: Document find_empty_resource_slot() and resource_constraint Date: Fri, 22 Dec 2023 14:28:57 +0200 Message-Id: <20231222122901.49538-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985283950215466 X-GMAIL-MSGID: 1785985283950215466 Document find_empty_resource_slot() and the struct resource_constraint as they are going to be exposed outside of resource.c. Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- kernel/resource.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 94f67005e1e2..ed4bb8ad701a 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -46,7 +46,18 @@ struct resource iomem_resource = { }; EXPORT_SYMBOL(iomem_resource); -/* constraints to be met while allocating resources */ +/** + * resource_constraint - constraints to be met while searching empty resource slots + * @min: The minimum address for the memory range + * @max: The maximum address for the memory range + * @align: Alignment for the start address of the empty slot + * @alignf: Additional alignment constraints callback + * @alignf_data: Data provided for @alignf callback + * + * Contains the range and alignment constraints that have to be met during + * find_empty_resource_slot(). @alignf can be NULL indicating no alignment + * beyond @align is necessary. + */ struct resource_constraint { resource_size_t min, max, align; resource_size_t (*alignf)(void *, const struct resource *, @@ -629,8 +640,19 @@ next: if (!this || this->end == root->end) return -EBUSY; } -/* - * Find empty slot in the resource tree given range and alignment. +/** + * find_empty_resource_slot - Find empty slot in the resource tree + * @root: Root resource descriptor + * @new: Resource descriptor awaiting an empty resource slot + * @size: The minimum size of the empty slot + * @constraint: The range and alignment constraints to be met + * + * Finds an empty slot under @root in the resource tree satisfying range and + * alignment @constraints. + * + * Return: + * * %0 - if successful, @new members start, end, and flags are altered. + * * %-EBUSY - if no empty slot was found. */ static int find_empty_resource_slot(struct resource *root, struct resource *new, resource_size_t size, From patchwork Fri Dec 22 12:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1025631dyi; Fri, 22 Dec 2023 04:30:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHu3R0AgqrBYSbDfeyCIDfd3DC8ZSPXBsGi/ppCnY1Zvya/HN8ofbIdDL2mKBE9v0NBp1oy X-Received: by 2002:a17:90a:d3c3:b0:28b:5ffe:2049 with SMTP id d3-20020a17090ad3c300b0028b5ffe2049mr998220pjw.94.1703248256656; Fri, 22 Dec 2023 04:30:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248256; cv=none; d=google.com; s=arc-20160816; b=Evb8nohUiXVBKydrcXMeoZurNYbXx/dabRSiZMeCUuBjwfvKbgLg/pmEnIMAKVbglm 6w0uoz7WVKw1ummLMAK62ZoINRwBmSBIw66ThZym2mEBwUcTIA9pJ7xONTrhW9QSYLqC kGl+ITMXmPkkAUtJkQMkFPYnE+S1Jzcp45RO7pzv7wCYHV89TcvycAjsa6xQp4kxEvRf 7K45lnwkKG6kcBne7ugqMf+BY5PPBzplRUIsuyI4MFmTqCo85byi5f3eoataB0y+zTtu XZq8cQQsfeuZWoRoK+L1qPlheTeO8z1JiEg5WNsOshHS3tGXMmGBUCs61CGydf89QZ2b EHZQ== ARC-Message-Signature: i=1; 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=VYCZncQ1sRVXlf8UbZ6jzi+BpF3dwvn7Bv/+aBHriHw=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=Dx8xqbhViXlefh1QJRh7pWCJBq6joUnYZu5MKzkM9lB6tNNvZoiiCB50ORHC5Ln06L /xebW+x8Sd9VkA76QTKDkrQR0Dh9xVITJLzJuE9SWA9IjQ4g3N9ng3Z8L+1hkHuCItKl mLEFGXY9ob0JOEd+cw55VKip6emxKINkcSt10vzfZJ2/Sus+TjUXz3hegckvE9RGsV7U 6qnTaHEbaHNqZqqYMak4jgr31GWwvYgDwxYBIfL4t6JVhcHkPfop8Ic0X3Ui/pDTPyzW 1n51V4jCAozEH7ZcJjKvwzapG34YOFD4CacHNcFDeRYliej1ZtI8c6QuFnlP6uYi9mWM lydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dhQ4ZZen; spf=pass (google.com: domain of linux-kernel+bounces-9705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ot5-20020a17090b3b4500b0028bc9c1cbccsi5352752pjb.58.2023.12.22.04.30.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:30:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dhQ4ZZen; spf=pass (google.com: domain of linux-kernel+bounces-9705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 705D1286857 for ; Fri, 22 Dec 2023 12:30:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 351AA1864D; Fri, 22 Dec 2023 12:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dhQ4ZZen" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 4974F18B15; Fri, 22 Dec 2023 12:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248205; x=1734784205; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PPHheHQqKFRdHphAUdQLWWFGLymh1CfDcRWQgsBvrnA=; b=dhQ4ZZenHgbXgJB1L3aKxB70rEJyZLXFvede+rvHLYDSfypKcPtGE+TB q6zAaF/8NIcqjPWZ9TeoShH/9BksuIE0rHJhXyHoXRbNmM/SQY/4mykSp 9XYaMm4OQPYDMmi4HwCoEoAtLEIc8cOrA95IyhheGVkVSyxS+9QvdITcd /TrRUrLjPPgp/qbMne5FDtVW8sJQRZNL+t91OsonLZsacMIBWc8Fz+1Fb FXCsAY4ZhoaMDQPO0A7LWzburbH48pQOzkKkKErnpwci4h4TuBL6O4JRu rGdD0dWCTfbwLlie3f9TuZPkdHFlN2XKfwKnIxHpkTwqI4zxqQE1OafRk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="2957159" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="2957159" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="19016836" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:29:59 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 4/7] resource: Use typedef for alignf callback Date: Fri, 22 Dec 2023 14:28:58 +0200 Message-Id: <20231222122901.49538-5-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985244092951622 X-GMAIL-MSGID: 1785985244092951622 To make it simpler to declare resource constraint alignf callbacks, add typedef for it and document it. Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- drivers/pci/bus.c | 10 ++-------- include/linux/ioport.h | 22 ++++++++++++++++++---- include/linux/pci.h | 5 +---- kernel/resource.c | 8 ++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 9c2137dae429..be5a4bb4d2fb 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -176,10 +176,7 @@ static void pci_clip_resource_to_region(struct pci_bus *bus, static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned long type_mask, - resource_size_t (*alignf)(void *, - const struct resource *, - resource_size_t, - resource_size_t), + resource_alignf alignf, void *alignf_data, struct pci_bus_region *region) { @@ -250,10 +247,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned long type_mask, - resource_size_t (*alignf)(void *, - const struct resource *, - resource_size_t, - resource_size_t), + resource_alignf alignf, void *alignf_data) { #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 14f5cfabbbc8..ce02f45e9c2c 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -188,6 +188,23 @@ enum { #define DEFINE_RES_DMA(_dma) \ DEFINE_RES_DMA_NAMED((_dma), NULL) +/** + * resource_alignf - Resource alignment callback + * @data: Private data used by the callback + * @res: Resource candidate range (an empty resource slot) + * @size: The minimum size of the empty slot + * @align: Alignment from the constraints + * + * Callback allows calculating resource placement and alignment beyond min, + * max, and align fields in the struct resource_constraint. + * + * Return: Start address for the resource. + */ +typedef resource_size_t (*resource_alignf)(void *data, + const struct resource *res, + resource_size_t size, + resource_size_t align); + /* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource; extern struct resource iomem_resource; @@ -207,10 +224,7 @@ extern void arch_remove_reservations(struct resource *avail); extern int allocate_resource(struct resource *root, struct resource *new, resource_size_t size, resource_size_t min, resource_size_t max, resource_size_t align, - resource_size_t (*alignf)(void *, - const struct resource *, - resource_size_t, - resource_size_t), + resource_alignf alignf, void *alignf_data); struct resource *lookup_resource(struct resource *root, resource_size_t start); int adjust_resource(struct resource *res, resource_size_t start, diff --git a/include/linux/pci.h b/include/linux/pci.h index 60ca768bc867..d635e64debd9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1546,10 +1546,7 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned long type_mask, - resource_size_t (*alignf)(void *, - const struct resource *, - resource_size_t, - resource_size_t), + resource_alignf alignf, void *alignf_data); diff --git a/kernel/resource.c b/kernel/resource.c index ed4bb8ad701a..9d7920104120 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -60,8 +60,7 @@ EXPORT_SYMBOL(iomem_resource); */ struct resource_constraint { resource_size_t min, max, align; - resource_size_t (*alignf)(void *, const struct resource *, - resource_size_t, resource_size_t); + resource_alignf alignf; void *alignf_data; }; @@ -725,10 +724,7 @@ static int reallocate_resource(struct resource *root, struct resource *old, int allocate_resource(struct resource *root, struct resource *new, resource_size_t size, resource_size_t min, resource_size_t max, resource_size_t align, - resource_size_t (*alignf)(void *, - const struct resource *, - resource_size_t, - resource_size_t), + resource_alignf alignf, void *alignf_data) { int err; From patchwork Fri Dec 22 12:28:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1025837dyi; Fri, 22 Dec 2023 04:31:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiXj5/CXPh90/2+Zb2LxTPSLgH1gq0H+TSTjyDIHB30t9ja5/jfgJU6w+MiT2WcrGkLD0a X-Received: by 2002:a05:6122:2d2:b0:4b6:ea3a:f87a with SMTP id k18-20020a05612202d200b004b6ea3af87amr335734vki.4.1703248275505; Fri, 22 Dec 2023 04:31:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248275; cv=none; d=google.com; s=arc-20160816; b=SHbrcVkYRD1xicoUKMQN2dDXiqRfeZjgdHMR5F5snQY1ySRYrPRg1oTgTF/5Mv1PEn HEQOb4qKc38/qrtDFp16XezmR11ai8ImT3dmXWtqY9CBafTiYN/593y5b8DNTKSJ0pv5 QJJvJ3oemmj6xJR+KTgkzI6OjtQsPhGOIQFTkLToT7trehFioWGE5uOE5PoHzJmwqDRy 4uIlW64ld/Muu35HiXzqXsgzGYhamJRD2nwamFJvZ+6zc50YM230haBc3saC32VjIf0j mJi+FEmRTspO3eDR4y1EwoV0si+gwuItUIDFrqg/EBlIJCtQz9VU+SyegjBfONS7knQt 5h0w== ARC-Message-Signature: i=1; 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=WcbAqW/PNrzRYLCNksnIRdgQ/ltM7aSdE/0wL8PnbPY=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=JW++hmE3qS3BeBQ1rhb67QTckBPCs+2NfhLm0/hdYMBDoQpUcONwdWcs62mJ4taJUI eLkgzaVY0yhwLFYB9cmZhQLyaIRZEteMNNx0DA3lgSCkZhwqbXPpaVoQGqlxRpjUWo1L nCdZk7VyYNBwrDBv+wwZufOLhMUuE9AHKHC8OYJFEuBh8BUWn4WtbtBXNEsrxrervMOh YoCatAhA3NOKrJFgNxljKabkl//aCI5kNPw7IJ/RpcECq4JaiwEwQnL076aKOZCktTpc yfSvIqFjpiXtdpIkinRTZtIVZT29gkmjNZiZFj2c+KlTGmsPv5ZfdDAE4pxKBQsCivLG /APg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aqHQFIXK; spf=pass (google.com: domain of linux-kernel+bounces-9706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9706-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x186-20020a1fc7c3000000b0049ab92b3667si766783vkf.215.2023.12.22.04.31.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:31:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aqHQFIXK; spf=pass (google.com: domain of linux-kernel+bounces-9706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9706-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 48F381C209A8 for ; Fri, 22 Dec 2023 12:31:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58FE0210F5; Fri, 22 Dec 2023 12:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aqHQFIXK" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 71FDC1A5A3; Fri, 22 Dec 2023 12:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248216; x=1734784216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tV8ZA6+9dVotj+4bWIAu5XQOfKl/tj4X1maAI3jCdoY=; b=aqHQFIXKctmYpZLQVTMnWNeFSGYbZ+cqyCFGWaTKGN6uytd+n4+xBZcA ttN1z12lwm/+oj1MSsXE2ZF4DnEdtRL/O6gzgBkMnFPE00hjU/hCcIQQ+ 8/EmYw9cLQMNHZEEQG1IS/V/ZP0Boj+HntTaDMv7KrLFFuIUwXIAqYXi0 ENzPsY39NcrKNHh9QrdbdWKTrxfEJnMB50Pq8DYt/22AdVMcoVwNvNHZ/ MYAymt0iPB6q2Cxz8P2TKlRSg9knwAfZb4/DhAZgjwDmAu686bxoKc+Im MOacT8iAM/E6QbPLychAXyY2VwEUmdsQnA9UmUpFY//R4527d/R2K80qY A==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="2957180" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="2957180" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="19016876" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:10 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 5/7] resource: Handle simple alignment inside __find_empty_resource_slot() Date: Fri, 22 Dec 2023 14:28:59 +0200 Message-Id: <20231222122901.49538-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985264066918551 X-GMAIL-MSGID: 1785985264066918551 allocate_resource() accepts alignf callback to perform custom alignment beyond constraint->align. If alignf is NULL, simple_align_resource() is used which only returns avail->start (no change). Using avail->start directly is natural and can be done with a conditional in __find_empty_resource_slot() instead which avoids unnecessarily using callback. It makes the code inside __find_empty_resource_slot() more obvious and removes the need for the caller to provide constraint->alignf unnecessarily. This is preparation for exporting find_empty_resource_slot(). Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- kernel/resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 9d7920104120..80d64b6467b3 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -563,14 +563,6 @@ void __weak arch_remove_reservations(struct resource *avail) { } -static resource_size_t simple_align_resource(void *data, - const struct resource *avail, - resource_size_t size, - resource_size_t align) -{ - return avail->start; -} - static void resource_clip(struct resource *res, resource_size_t min, resource_size_t max) { @@ -590,6 +582,7 @@ static int __find_empty_resource_slot(struct resource *root, struct resource *ol { struct resource *this = root->child; struct resource tmp = *new, avail, alloc; + resource_alignf alignf = constraint->alignf; tmp.start = root->start; /* @@ -618,8 +611,13 @@ static int __find_empty_resource_slot(struct resource *root, struct resource *ol avail.flags = new->flags & ~IORESOURCE_UNSET; if (avail.start >= tmp.start) { alloc.flags = avail.flags; - alloc.start = constraint->alignf(constraint->alignf_data, &avail, - size, constraint->align); + if (alignf) { + alloc.start = alignf(constraint->alignf_data, + &avail, size, + constraint->align); + } else { + alloc.start = avail.start; + } alloc.end = alloc.start + size - 1; if (alloc.start <= alloc.end && resource_contains(&avail, &alloc)) { @@ -730,9 +728,6 @@ int allocate_resource(struct resource *root, struct resource *new, int err; struct resource_constraint constraint; - if (!alignf) - alignf = simple_align_resource; - constraint.min = min; constraint.max = max; constraint.align = align; From patchwork Fri Dec 22 12:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1026050dyi; Fri, 22 Dec 2023 04:31:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdrlYfAP0EK1/vMw1lSzB54u9bT9X82n+fuE+rJkJKf2//leYC+3IppEEmJdYt+DEHv2E/ X-Received: by 2002:a50:9357:0:b0:554:71a6:2133 with SMTP id n23-20020a509357000000b0055471a62133mr109334eda.40.1703248294958; Fri, 22 Dec 2023 04:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248294; cv=none; d=google.com; s=arc-20160816; b=BciDtViafSUd+l6R0zIb5my5mCnbu5Has3Hs/mAZMzR+2p6NDtVW9dB9Cx4I812L96 FX3YXul44k69mCT55Ae70puUB9tfOt6/KD4SYHgpaYHGWPorZKdnIOMCC2d4Z+KToZEf UkMtR50CnTQSXJ5Scg5hQ7s8/uQoJGAthwYxMgGPV3mU8YCqHdTEWyhGPyv1yAW8sDtu c8pz59ojwkiFabKxjECCMj3yuPl//H/aYE1tvqa2i1uoGjhY5QuRtZKqxKF7hkWUWN/6 qP0/h4428CstJWkCbLGOr51OkMrJh972jtWsOjVK1W3xUuTdAdFCzCWlb83ceVn1ZzDT KWUw== ARC-Message-Signature: i=1; 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=3nhHjFxNkD0JRSoNuTHcT7g63m8P7RsmSMPbuOSQHJI=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=cFOp2b3MauL2Ijw44wDbAYJUnK+2LRrQiFuwqqIv/4LH+b5lFnIknFFGt2m5Vl5y0c nFoQVyFx/GYyp2nswjRfS0cVfA0QeCw8TV9GuaAH4w/BxST6B0Nckfa9RLiR0lRn4PHg cz0IwT/K3iiYsUaBLUVPLd6dmhgELf9QgUMEOFx3ijAcTh6DhhhMb0LQ0lv8qSRDcLbE dvgtakfWXhomQC5lAL9YgIl/3eL/YnoWmYXt8+gz5HwSfBZ7ztGu58VL5xkchpz4e3PY 49E87Q0Hld3WmV3kvPtwds58ddtegG/JtxLHDA238qMK24G9cklCuMljZQM+KUEPWs64 0Pcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="WFcOx/7N"; spf=pass (google.com: domain of linux-kernel+bounces-9707-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9707-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l18-20020a056402255200b00553a65b69f8si1838727edb.344.2023.12.22.04.31.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:31:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9707-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="WFcOx/7N"; spf=pass (google.com: domain of linux-kernel+bounces-9707-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9707-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6A9251F21D0A for ; Fri, 22 Dec 2023 12:31:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8400B2134B; Fri, 22 Dec 2023 12:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WFcOx/7N" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 A86B621A0A; Fri, 22 Dec 2023 12:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248226; x=1734784226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OiDZKkhIpM5IyGLuILWXJUYuEW8PKuPWXfxlEeVMsPQ=; b=WFcOx/7Nje4mHqlBkRjp/V3zyVwUE4XJ0e9iav94Cwxge/9JZXGjJiqr Uap3ls95og5Mgbp4zCPHsX+hRiJV2BoJt3l/g/zPc+6KEzVW3HVVzik6z c7S9RjtMYxTX7oAmTHgP1fsaE55eYbrBe2104RYlGwCTo6DmYxByHpHO0 cgsxLBvNn3LC+9uIWGcfnRV/Jna8h9H9fIMnMusp2L6ZQVK+MfI3uDrho v/s4m5DHCKIMqhF3wedVq0+M642xkhAV7GfbMDt33Ra0T9FapcwS5DSg4 ozNwxXa7ghwLy4r+nV8G0f0/3FIgS/ag1ZWe70v8jPU9Sh3BYqaz8JjVS w==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="2957186" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="2957186" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="19016951" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:20 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 6/7] resource: Export find_empty_resource_slot() Date: Fri, 22 Dec 2023 14:29:00 +0200 Message-Id: <20231222122901.49538-7-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985284293383792 X-GMAIL-MSGID: 1785985284293383792 PCI bridge window logic needs to find out in advance to the actual allocation if there is an empty slot big enough to fit the window. Export find_empty_resource_slot() for the purpose. Also move the struct resource_constraint into generic header to be able to use the new interface. Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- include/linux/ioport.h | 22 ++++++++++++++++++++++ kernel/resource.c | 25 ++++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index ce02f45e9c2c..0e911393dfb2 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -205,6 +205,24 @@ typedef resource_size_t (*resource_alignf)(void *data, resource_size_t size, resource_size_t align); +/** + * resource_constraint - constraints to be met while searching empty resource slots + * @min: The minimum address for the memory range + * @max: The maximum address for the memory range + * @align: Alignment for the start address of the empty slot + * @alignf: Additional alignment constraints callback + * @alignf_data: Data provided for @alignf callback + * + * Contains the range and alignment constraints that have to be met during + * find_empty_resource_slot(). @alignf can be NULL indicating no alignment + * beyond @align is necessary. + */ +struct resource_constraint { + resource_size_t min, max, align; + resource_alignf alignf; + void *alignf_data; +}; + /* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource; extern struct resource iomem_resource; @@ -278,6 +296,10 @@ static inline bool resource_union(const struct resource *r1, const struct resour return true; } +int find_empty_resource_slot(struct resource *root, struct resource *new, + resource_size_t size, + struct resource_constraint *constraint); + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) #define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED) diff --git a/kernel/resource.c b/kernel/resource.c index 80d64b6467b3..2dfe04ba24f3 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -46,24 +46,6 @@ struct resource iomem_resource = { }; EXPORT_SYMBOL(iomem_resource); -/** - * resource_constraint - constraints to be met while searching empty resource slots - * @min: The minimum address for the memory range - * @max: The maximum address for the memory range - * @align: Alignment for the start address of the empty slot - * @alignf: Additional alignment constraints callback - * @alignf_data: Data provided for @alignf callback - * - * Contains the range and alignment constraints that have to be met during - * find_empty_resource_slot(). @alignf can be NULL indicating no alignment - * beyond @align is necessary. - */ -struct resource_constraint { - resource_size_t min, max, align; - resource_alignf alignf; - void *alignf_data; -}; - static DEFINE_RWLOCK(resource_lock); static struct resource *next_resource(struct resource *p, bool skip_children) @@ -651,12 +633,13 @@ next: if (!this || this->end == root->end) * * %0 - if successful, @new members start, end, and flags are altered. * * %-EBUSY - if no empty slot was found. */ -static int find_empty_resource_slot(struct resource *root, struct resource *new, - resource_size_t size, - struct resource_constraint *constraint) +int find_empty_resource_slot(struct resource *root, struct resource *new, + resource_size_t size, + struct resource_constraint *constraint) { return __find_empty_resource_slot(root, NULL, new, size, constraint); } +EXPORT_SYMBOL_GPL(find_empty_resource_slot); /** * reallocate_resource - allocate a slot in the resource tree given range & alignment. From patchwork Fri Dec 22 12:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 182662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1026322dyi; Fri, 22 Dec 2023 04:31:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7Eme2vhrWp3ogTcqLcO0fWK7fMMp7Vjbu4+gsBeKFPUnY4BfwwJrII32x4pjjdmc0jmF8 X-Received: by 2002:a17:906:3bdb:b0:a23:195c:8aa7 with SMTP id v27-20020a1709063bdb00b00a23195c8aa7mr637790ejf.15.1703248319111; Fri, 22 Dec 2023 04:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703248319; cv=none; d=google.com; s=arc-20160816; b=xIRmAe+aslF8phvxCv0iHoOGCPOVNEAzTaFcOb/2hoiCxAqe0wygqLBSQhDpDv7+k1 PXPVYufC3kou2KBFfQuhP5gEpCH3oK9e84Q4IeDfWAXdaeTKt9LhMgUk2VGkIW5iYP5I KtK7ou22RAmEKHLyAJ88x2fsmK4kXgzKZLdDWYZ42vLfhXUGhOsaHYk3WcOV3g5bhzRQ KDH4CkaN5XRCOpKe/p63GvpIgjrCzmjtz5gF3QjJwUC9Sfdzo7C4DVUKTyfnaTS2zVqj GWmRkTk7FP/ZQVGQ4FjTaaZ+WYoCyAnw0zlYGolZL+OYuLXg1RwouRYdWEoGvfqvimTs GAvA== ARC-Message-Signature: i=1; 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=t+Pezo9p1Vb6+SyvBKmpAZxmAGhpRfXVj57SQDTAn8s=; fh=yqUIIgKqVOYsTyZW6w8zcpjOuZt/iZwb7E0FG62Kafw=; b=hB4A5fqogFxEGGB3ciZVA1LCwJtW8ve3Bv8/fNd+nxkSJmRzRSNnYx1DuNM1+uI/80 FBvszejhBg+XhIGA/6QZUVOVJ1WBi/xCbx76+yggzognEmomOol/+W6oKUfc+qVeXC3M dvqcNapknHzHJcPIOBqBqCTZ5N4Y6/bWaLc29WYjoGsa9oFsu40gKzmj/YvCxGHdkFvb Y+QzriEIi3CzmShZuSPYySdkmqefwkORDDpTJSMp/edruTdZeGxBH4hUQW8pz/a6e2vD VVFBorSwHkc9q/KJPP0ExxMIESJSxvBG2TA6pARtp3UwWyBUOuwoEjz2yHyXYIRfpraJ kl3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JktNcjou; spf=pass (google.com: domain of linux-kernel+bounces-9708-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s8-20020a170906c30800b00a233549825asi1595174ejz.974.2023.12.22.04.31.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 04:31:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9708-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JktNcjou; spf=pass (google.com: domain of linux-kernel+bounces-9708-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8C0A61F219DB for ; Fri, 22 Dec 2023 12:31:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAF6D1D53A; Fri, 22 Dec 2023 12:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JktNcjou" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 A810D182A8; Fri, 22 Dec 2023 12:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703248235; x=1734784235; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g31zhOf3uEGkxug+1goHgSFy2XIXHCgqzK5ThYw4wzA=; b=JktNcjouyQsxTZtxUYvi3NxuOv5U/tOJL/rpDRvbl61BJ6ryWT3q+CbI Dn0VKB+ZUT+h03HDxb5imKlgsgEdPtlXAL6jMyr5yvBgPYXyj161AJUG8 w7NAGRJgp/TEQy4NZhPgK36FZpqftFD3NXcFRylXOUatkZC48C0BuZLVB nmSfit0yfnK+QOoPWTVa94zXK0V1SvtS4SRFKHfXbl0MBIz16GtACaaYA iWibncvaU+7whKRyQil2TwTaYBuO1jH3ppDlH1rFN7SDmqluhlnsk1A/f 2LLc0unOM08J51QTXTjrhcAFuUDcPIK5pGnMkAFyv6/+Gvxn9t5UHpdg1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="14793584" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="14793584" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="1108452322" X-IronPort-AV: E=Sophos;i="6.04,296,1695711600"; d="scan'208";a="1108452322" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.248.105]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 04:30:30 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 7/7] PCI: Relax bridge window tail sizing rules Date: Fri, 22 Dec 2023 14:29:01 +0200 Message-Id: <20231222122901.49538-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> References: <20231222122901.49538-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785985309815701531 X-GMAIL-MSGID: 1785985309815701531 During remove & rescan cycle, PCI subsystem will recalculate and adjust the bridge window sizing that was initially done by "BIOS". The size calculation is based on the required alignment of the largest resource among the downstream resources as per pbus_size_mem() (unimportant or zero parameters marked with "..."): min_align = calculate_mem_align(aligns, max_order); size0 = calculate_memsize(size, ..., min_align); and then in calculate_memsize(): size = ALIGN(max(size, ...) + ..., align); If the original bridge window sizing tried to conserve space, this will lead to massive increase of the required bridge window size when the downstream has a large disparity in BAR sizes. E.g., with 16MiB and 16GiB BARs this results in 32GiB bridge window size even if 16MiB BAR does not require gigabytes of space to fit. When doing remove & rescan for a bus that contains such a PCI device, a larger bridge window is suddenly required on rescan but when there is a bridge window upstream that is already assigned based on the original size, it cannot be enlarged to the new requirement. This causes the allocation of the bridge window to fail (0x600000000 > 0x400ffffff): pci 0000:02:01.0: PCI bridge to [bus 03] pci 0000:02:01.0: bridge window [mem 0x40400000-0x405fffff] pci 0000:02:01.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] pci 0000:01:00.0: PCI bridge to [bus 02-04] pci 0000:01:00.0: bridge window [mem 0x40400000-0x406fffff] pci 0000:01:00.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] ... pci_bus 0000:03: busn_res: [bus 03] is released pci 0000:03:00.0: reg 0x10: [mem 0x6400000000-0x6400ffffff 64bit pref] pci 0000:03:00.0: reg 0x18: [mem 0x6000000000-0x63ffffffff 64bit pref] pci 0000:03:00.0: reg 0x30: [mem 0x40400000-0x405fffff pref] pci 0000:02:01.0: PCI bridge to [bus 03] pci 0000:02:01.0: bridge window [mem 0x40400000-0x405fffff] pci 0000:02:01.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] pci 0000:02:01.0: BAR 9: no space for [mem size 0x600000000 64bit pref] pci 0000:02:01.0: BAR 9: failed to assign [mem size 0x600000000 64bit pref] pci 0000:02:01.0: BAR 8: assigned [mem 0x40400000-0x405fffff] pci 0000:03:00.0: BAR 2: no space for [mem size 0x400000000 64bit pref] pci 0000:03:00.0: BAR 2: failed to assign [mem size 0x400000000 64bit pref] pci 0000:03:00.0: BAR 0: no space for [mem size 0x01000000 64bit pref] pci 0000:03:00.0: BAR 0: failed to assign [mem size 0x01000000 64bit pref] pci 0000:03:00.0: BAR 6: assigned [mem 0x40400000-0x405fffff pref] pci 0000:02:01.0: PCI bridge to [bus 03] pci 0000:02:01.0: bridge window [mem 0x40400000-0x405fffff] This is a major surprise for users who are suddenly left with a PCIe device that was working fine with the original bridge window sizing. Even if the already assigned bridge window could be enlarged by reallocation in some cases (something the current code does not attempt to do), it is not possible in general case and the large amount of wasted space at the tail of the bridge window may lead to other resource exhaustion problems on Root Complex level (think of multiple PCIe cards with VFs and BAR size disparity in a single system). PCI specifications only expect natural alignment for BARs (PCI Express Base Specification, rev. 6.1 sect. 7.5.1.2.1) and minimum of 1MiB alignment for the bridge window (PCI Express Base Specification, rev 6.1 sect. 7.5.1.3). The current bridge window tail alignment rule was introduced in the commit 5d0a8965aea9 ("[PATCH] 2.5.14: New PCI allocation code (alpha, arm, parisc) [2/2]") that only states: "pbus_size_mem: core stuff; tested with randomly generated sets of resources". It does not explain the motivation for the extra tail space allocated that is not truly needed by the downstream resources. As such, it is far from clear if it ever has been required by any HW. To prevent PCIe cards with BAR size disparity from becoming unusable after remove & rescan cycle, attempt to do a truly minimal allocation for memory resources if needed. First check if the normally calculated bridge window will not fit into an already assigned upstream resource. In such case, try with relaxed bridge window tail sizing rules instead where no extra tail space is requested beyond what the downstream resources require. Only enforce the alignment requirement of the bridge window itself (normally 1MiB). With this patch, the resources are successfully allocated: pci 0000:02:01.0: PCI bridge to [bus 03] pci 0000:02:01.0: bridge window [mem 0x40400000-0x405fffff] pci 0000:02:01.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] pci 0000:02:01.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] to [bus 03] requires relaxed alignment rules pci 0000:02:01.0: BAR 9: assigned [mem 0x6000000000-0x6400ffffff 64bit pref] pci 0000:02:01.0: BAR 8: assigned [mem 0x40400000-0x405fffff] pci 0000:03:00.0: BAR 2: assigned [mem 0x6000000000-0x63ffffffff 64bit pref] pci 0000:03:00.0: BAR 0: assigned [mem 0x6400000000-0x6400ffffff 64bit pref] pci 0000:03:00.0: BAR 6: assigned [mem 0x40400000-0x405fffff pref] pci 0000:02:01.0: PCI bridge to [bus 03] pci 0000:02:01.0: bridge window [mem 0x40400000-0x405fffff] pci 0000:02:01.0: bridge window [mem 0x6000000000-0x6400ffffff 64bit pref] This patch draws inspiration from the initial investigations and work by Mika Westerberg. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216795 Link: https://lore.kernel.org/linux-pci/20190812144144.2646-1-mika.westerberg@linux.intel.com/ Fixes: 5d0a8965aea9 ("[PATCH] 2.5.14: New PCI allocation code (alpha, arm, parisc) [2/2]") Signed-off-by: Ilpo Järvinen Cc: Mika Westerberg --- During our internal review, Andy Shevchenko noted that the check for ioport_resource & iomem_resource might not be needed. I've left them into pbus_upstream_assigned_limit() because I couldn't prove myself they're unnecessary and find_bus_resource_of_type() also does the same check. If the checks are not needed in pbus_upstream_assigned_limit() they should not be required in find_bus_resource_of_type() either. --- drivers/pci/setup-bus.c | 75 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index e3e6ff8854a7..cafc43a1512d 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -960,6 +960,63 @@ static inline resource_size_t calculate_mem_align(resource_size_t *aligns, return min_align; } +/** + * pbus_upstream_assigned_limit - Check no upstream resource limits allocation + * @bus: The bus + * @mask: Mask the resource flag, then compare it with type + * @type: The type of resource from bridge + * @size: The size required from the bridge window + * @align: Required alignment for the resource + * + * Checks that @size can fit inside the upstream bridge resources that are + * already assigned. + * + * Return: -ENOSPC if @size cannot fit into an already assigned resource + * upstream resource. + */ +static int pbus_upstream_assigned_limit(struct pci_bus *bus, unsigned long mask, + unsigned long type, resource_size_t size, + resource_size_t align) +{ + struct resource_constraint constraint = { .max = (resource_size_t)~0ULL, + .align = align }; + struct pci_bus *downstream = bus; + struct resource *r; + + while ((bus = bus->parent)) { + if (pci_is_root_bus(bus)) + break; + + pci_bus_for_each_resource(bus, r) { + if (!r || r == &ioport_resource || r == &iomem_resource) + continue; + + if (!r->parent || (r->flags & mask) != type) + continue; + + if (resource_size(r) >= size) { + struct resource gap = {}; + + if (!find_empty_resource_slot(r, &gap, size, &constraint)) + return 0; + } + + if (bus->self) { + pci_dbg(bus->self, + "Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s bridging to %pR\n", + r, &bus->busn_res, + (unsigned long long)size, + pci_name(downstream->self), + &downstream->busn_res); + } + + return -ENOSPC; + } + } + + return 0; +} + /** * pbus_size_mem() - Size the memory window of a given bus * @@ -986,7 +1043,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, struct list_head *realloc_head) { struct pci_dev *dev; - resource_size_t min_align, align, size, size0, size1; + resource_size_t min_align, win_align, align, size, size0, size1; resource_size_t aligns[24]; /* Alignments from 1MB to 8TB */ int order, max_order; struct resource *b_res = find_bus_resource_of_type(bus, @@ -1064,10 +1121,24 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, } } + win_align = window_alignment(bus, b_res->flags); min_align = calculate_mem_align(aligns, max_order); - min_align = max(min_align, window_alignment(bus, b_res->flags)); + min_align = max(min_align, win_align); size0 = calculate_memsize(size, min_size, 0, 0, resource_size(b_res), min_align); add_align = max(min_align, add_align); + + if (bus->self && size0 && + pbus_upstream_assigned_limit(bus, mask | IORESOURCE_PREFETCH, type, + size0, add_align)) { + min_align = 1ULL << (max_order + 20); + min_align = max(min_align, win_align); + size0 = calculate_memsize(size, min_size, 0, 0, + resource_size(b_res), win_align); + add_align = win_align; + pci_info(bus->self, "bridge window %pR to %pR requires relaxed alignment rules\n", + b_res, &bus->busn_res); + } + size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 : calculate_memsize(size, min_size, add_size, children_add_size, resource_size(b_res), add_align);