From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796193057; b=hS/toSabyjIG8b58jnJoodORGc/FcoHsEms3avLyn4g8w6y8htqmT1jKDl3lAPW29RRP EBZaJB0sMkRn8Ybvvv+1weyLNydxAG4Qk/T/oa2k19uG9sr4Dfn8CRymMK6nb4sFDwUdW 1BVCIqWWHsuXc1DOr3fEkh+lOMFFMKRdph53ZstUF13nG2OVtZj6hhtMlb4J4OGMw8pPJ MmbooQKtFe9zrBz6tZnAgHqrZtbKsqEPUdaWAOOaJ2FiQPfYvboI43yT3TULCafvSxp5N tUaLwiaKuI5PI8QdPACsrVchpL9PZLHM8tOqhXVnLYmA3PG+k6+k0nasVD9cuvXgs3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796193057; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vQUMqMuA61LkuXEC1Cy7Gjpl5Y5OlW2qfvHC7MdAt+E=; b=sV7R4t8GLRpEziZFs5mFVb6l9BZdXaWPry7uqcbsKjpvDmlEXdW7gRx6h3bK3hpTLaur CMf6KhK4V6ubr/k+AyE0D2PUU0GVmok0BnvQFMvnmotFBRUS+imI+x5gJTPKjLsw6fhwZ lyxK7gvT/NjNt5vsiUXRfIWb/kCtV0xQcL0924GFkhSvRSH5jtoFNZhFIpXgJvqfFljKm f2mPIgop0xNWjKh3GRN0bc0MbaYm3txivKhI4YUSN9rB587gA0ZUXlpGBHZ6MO1Zh7Abl Ry8tjxUVRf7nhh0GbzJU4zugavyncU/3XJgNebmuhw7VLaCbCXK3xABvYiKLLsudFKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eiT6Wxvi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 141E7606A322 for ; Wed, 2 Dec 2026 06:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eiT6Wxvi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BBD81F000C1; Wed, 2 Dec 2026 06:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796193056; bh=vQUMqMuA61LkuXEC1Cy7Gjpl5Y5OlW2qfvHC7MdAt+E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eiT6WxvieLIOT2I3Wwz7A3A5tICecXnRMmISIjJWvIFanuPRZrDIbcZ2UK0eLiPPL nhgfnOqz6qDUlAhR2tSYR8VAN0tSWOv05kCWnJmtNm8owICvAmHie6LnlZLrzvsUGi AikMKcCZu+Q/kb2bd8U2jUn95oVaVOxNolc6o9shD72GI0fqrq1FHgvCOqcm5fW7wH 9tqcKmMpZM+qKyu1q41IePTukiRkoG3Rri2GUPg6ZowYikDxPGJTQVN0D40XkBRvtG 9I8OWB3qOHDZQJ2aetEjFG1zjvpKYYL1XhG3/3fZrjlrM408hgFisjhNbaFJjDVLv/ U9QpUMiK4NZRA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] PCI: Don't move a window's start when it holds a non-power-of-2 resource Reply-To: sashiko-reviews@lists.linux.dev To: "Greg Lamberson" Cc: linux-pci@vger.kernel.org In-Reply-To: <179619168710.49678.17788537403657229665@lamco.io> References: <179619168710.49678.17788537403657229665@lamco.io> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 06:30:56 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] PCI: pbus_window_holds_npot() skips zero-sized optional child bridge windows - [Medium] PCI: pbus_window_holds_npot() ignores non-power-of-2 child bridge window size - [Medium] PCI: 32-bit truncation of resource_size_t in pbus_window_holds_npot() -- commit 1163e25233836400f5115858ab238a5b666670d4 Author: Greg Lamberson PCI: Don't move a window's start when it holds a non-power-of-2 resource This commit prevents pci_align_resource() from shifting a bridge window's start address down below its alignment boundary when the window contains a non-power-of-2 resource directly or behind child bridges. > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > index 376f09630a4ab..8b2b6d5ef5ed8 100644 > --- a/drivers/pci/setup-res.c > +++ b/drivers/pci/setup-res.c > @@ -260,10 +260,49 @@ resource_size_t pci_resource_alignment(const struct= pci_dev *dev, > return resource_alignment(res); > } > =20 > +/* > + * Whether @win of @bus->self holds, directly or behind child bridges, a > + * resource whose size isn't a power of 2. An IOV resource is the VF BAR= size > + * times TotalVFs, so it's a power of 2 only when TotalVFs is. > + */ > +static bool pbus_window_holds_npot(struct pci_bus *bus, > + const struct resource *win) > +{ > + struct pci_dev *dev; > + > + list_for_each_entry(dev, &bus->devices, bus_list) { > + struct resource *r; > + int i; > + > + pci_dev_for_each_resource(dev, r, i) { > + if (!r->flags || (r->flags & IORESOURCE_DISABLED) || > + !resource_size(r)) > + continue; [Severity: Medium] Does checking !resource_size(r) before pci_resource_is_bridge_win(i) skip child bridge windows that contain only optional SR-IOV resources? When all resources in a child bridge window are optional (such as a 64-bit prefetchable window holding only SR-IOV VF BARs), pbus_size_mem() sets the window's required size0 to 0, clears IORESOURCE_DISABLED, and defers adding the optional size via realloc_head until __assign_resources_sorted() runs on that bus: drivers/pci/setup-bus.c:pbus_size_mem() { ... resource_set_range(b_res, min_align, size0); b_res->flags |=3D IORESOURCE_STARTALIGN; if (bus->self && realloc_head && (size1 > size0 || add_align > min_align))= { b_res->flags &=3D ~IORESOURCE_DISABLED; add_size =3D size1 > size0 ? size1 - size0 : 0; pci_dev_res_add_to_list(realloc_head, bus->self, b_res, add_size, add_align); ... } Because top-down assignment in __pci_bus_assign_resources_one() aligns and assigns the ancestor bridge window before expanding realloc_head entries on child buses, resource_size(r) is still 0 here. pbus_window_holds_npot() never recurses into dev->subordinate, so the ancestor window's start is still shifted down and child window or SR-IOV BAR assignment can fail with -ENOMEM. > + if (pbus_select_window(bus, r) !=3D win) > + continue; > + if (pci_resource_is_bridge_win(i)) { > + if (dev->subordinate && > + pbus_window_holds_npot(dev->subordinate, r)) > + return true; > + continue; > + } [Severity: Medium] Should a child bridge window r also be checked with !is_power_of_2(resource_size(r)) instead of unconditionally continuing? Even when every leaf BAR behind a child bridge has a power-of-2 size, pbus_size_mem() sizes the child bridge window r to the sum of its children (for example, two 16 GiB BARs and one 8 GiB BAR produce a 40 GiB window), which must be allocated as a single contiguous range inside win. If the parent bus also has a higher-aligned sibling resource (such as a 32 GiB BAR), shifting win down lets the 32 GiB BAR land at the first 32 GiB boundary and split the remaining space into an 8 GiB head and a 32 GiB tail, so the 40 GiB child bridge window cannot fit in either half. > + if (!is_power_of_2(resource_size(r))) > + return true; [Severity: Medium] Can passing resource_size(r) to is_power_of_2() truncate 64-bit resource sizes on 32-bit kernels with CONFIG_PHYS_ADDR_T_64BIT=3Dy? is_power_of_2() takes an unsigned long (32 bits on 32-bit architectures), whereas resource_size() returns a 64-bit resource_size_t when CONFIG_PHYS_ADDR_T_64BIT=3Dy. Any resource >=3D 4 GiB loses its upper 32 b= its: a power-of-2 BAR >=3D 4 GiB truncates to 0 and is treated as non-power-of-2, while a non-power-of-2 resource such as 5 GiB (5 VFs * 1 GiB =3D 0x140000000ULL) truncates to 1 GiB and is misclassified as a power of 2. Using is_power_of_2_u64() avoids the truncation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179619168710.49678.= 17788537403657229665@lamco.io?part=3D1