Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7594664rdb; Thu, 4 Jan 2024 01:08:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGr4V8Ab2bQiUp8DaFY2EAY2qgTwcnqqVxpVEg78NU8qdBw3oHzGA3H5zaVamOQIz4ueozb X-Received: by 2002:a05:6870:ac95:b0:204:19c6:71bf with SMTP id ns21-20020a056870ac9500b0020419c671bfmr274699oab.91.1704359289964; Thu, 04 Jan 2024 01:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704359289; cv=none; d=google.com; s=arc-20160816; b=0gVyKE7Sh/vH9/45nN5Z5PuvnipNWo/OL3/7ZknvwDVdyvnZe9giPkCIRwR6mmxV4e rJf2pyb7GMRgcgJ3dzbr2+rdSUEF2dF2v1ZJTyX7fpdiciHdWMSEv11KJfHBW5/r1JpD Fab2IYPOVl9txHg10IQDvl0iI/UwFpJb4TSPoJAhJqb9nHL4b8O1Xp8CyQusGaKt9+A0 6JWwnC9mvh353xOq4kNh2HTH+bF5/12m/E05Da3CaiP2SnYL3TyRAIto0GTWeQY9fWoa o8jAJHHob6YeY7CyYqNdGdXoLlfX5MSVDettIHTdCZjMs9gA4q6LuA04+8ht2WygZkOl Eg2A== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=Jsenl4ryPejHUAvVnk0GRNLRuch6fMe21jriRXS4vNY=; fh=C7LQW+4J0BgiMGOKM1Hc288DqCJKKjCWWy6i3V6pGhc=; b=eBJ6GNOatPJ4Il2VJuY3+czE/48Uakk6oqArjX6aEWCK0skn/1pdFBfi8PGJ0N7nDN W2dT16LTctN+/H6S3ass8SkQf/PqH1kdIPlWi9dg2/AsVFZcL3x+LJDnBrc1odJ9eHmr TtpNKjeB2IpqKeiNRtZkJ8yhkoG+gATHBzDpmwvKh7VhIT+Ap7OlVOyTKiOsYN2oXHbk f3Fr/swdndNxOIoQvZIMFwtMjl1Exx1pTn1Nq5LPtnBgncdewmGbOEETS9xEWm0j5YCo iox1DcnnFj6US+h9dg4+0i8rZlhas+g1McEltdv8Cx7iWR7Mr7IavRyO9ybo6Yq5Jdsd HhzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VcRtJKhG; spf=pass (google.com: domain of linux-kernel+bounces-16420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16420-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ck1-20020a056a02090100b005ce054620cesi19635026pgb.826.2024.01.04.01.08.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:08:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VcRtJKhG; spf=pass (google.com: domain of linux-kernel+bounces-16420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16420-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 50A25286FAF for ; Thu, 4 Jan 2024 09:08:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B51D208DB; Thu, 4 Jan 2024 09:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VcRtJKhG" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 327692030A for ; Thu, 4 Jan 2024 09:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704359247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Jsenl4ryPejHUAvVnk0GRNLRuch6fMe21jriRXS4vNY=; b=VcRtJKhG5/TPNt/fwVgXDt4bpPdUYUR1ACnPoFx/gtj7jvXNmO4xrw/vfOVtbniHONnmTp 2mXim0Q4OEvp7D2jGTTtyz9du0tXdGcUaJZrYo/BUFKQnr6IFrndf0Df3p/7kiRrwv+oLA QLRjJUj8VTY9Y5Olehf1ZLIAN4SVmbw= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-DxSovwt1M3WYph6_8AdAnw-1; Thu, 04 Jan 2024 04:07:24 -0500 X-MC-Unique: DxSovwt1M3WYph6_8AdAnw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ccad9d7cdfso743921fa.0 for ; Thu, 04 Jan 2024 01:07:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704359241; x=1704964041; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Jsenl4ryPejHUAvVnk0GRNLRuch6fMe21jriRXS4vNY=; b=FKGeX4TAukizfW0LGyojn4/eBWPxaDOfcP5W7Anzmz5eTfwLOZOCg2LV4KiMtW/gaF dCgk5+K1e2/bl9SDHszeHgiwYGR3FJe1xY+HEUZMU+w+kr8a3K3Py96/ClqUReVmjnpg xWjqcc3uWmlI4vbdmGhKMA1hu4etmgP9fjFztpLBZAigydsx5f2qo6WU2TKrX5Uy8Cqc spNlOxbTmmTp6f1EPVIS6k1+K9+qgzR/W4bLOFjqCycEvd25nwjSOrUE1vCKs7hUYPw0 URWAM/v0mdH+PCIBrVsN09RdeIVzXvKXQ/QEmRXJCKXU3R/qZgD1XmVIMSZLh7WxwUwB EGlw== X-Gm-Message-State: AOJu0YyKsme7D+7TY5g+ti4I93Bu4Vy02B+DKGep+bkDXyJgPWwJf0KL 4cu+/T7YutxIOfViQ7nbdZw9hZVJ/CxdAtkp63tggg2z44oXmgDbqcRUqqQLbVZ9QMrV4j3F8+Q g8B1t1jp1yXOWzH2Gq85Dg7w51SQ7GDAV X-Received: by 2002:a2e:be8b:0:b0:2cd:11fe:b686 with SMTP id a11-20020a2ebe8b000000b002cd11feb686mr318521ljr.4.1704359241638; Thu, 04 Jan 2024 01:07:21 -0800 (PST) X-Received: by 2002:a2e:be8b:0:b0:2cd:11fe:b686 with SMTP id a11-20020a2ebe8b000000b002cd11feb686mr318504ljr.4.1704359241266; Thu, 04 Jan 2024 01:07:21 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id h15-20020a5d430f000000b0033740e109adsm8720864wrq.75.2024.01.04.01.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:07:20 -0800 (PST) From: Philipp Stanner To: Bjorn Helgaas , Arnd Bergmann , Johannes Berg , Randy Dunlap , NeilBrown , John Sanpe , Kent Overstreet , Niklas Schnelle , Philipp Stanner , Dave Jiang , Uladzislau Koshchanka , "Masami Hiramatsu (Google)" , David Gow , Kees Cook , Rae Moar , Geert Uytterhoeven , "wuqiang.matt" , Yury Norov , Jason Baron , Thomas Gleixner , Marco Elver , Andrew Morton , Ben Dooks , dakr@redhat.com Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v5 RESEND 0/5] Regather scattered PCI-Code Date: Thu, 4 Jan 2024 10:07:04 +0100 Message-ID: <20240104090708.10571-2-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit @Stable-Kernel: You receive this patch series because its first patch fixes leaks in PCI. Changes in v5: - Add forgotten update to MAINTAINERS file. Changes in v4: - Apply Arnd's Reviewed-by's - Add ifdef CONFIG_HAS_IOPORT_MAP guard in drivers/pci/iomap.c (build error on openrisc) - Fix typo in patch no.5 Changes in v3: - Create a separate patch for the leaks in lib/iomap.c. Make it the series' first patch. (Arnd) - Turns out the aforementioned bug wasn't just accidentally removing iounmap() with the ifdef, it was also missing ioport_unmap() to begin with. Add it. - Move the ARCH_WANTS_GENERIC_IOMEM_IS_IOPORT-mechanism from asm-generic/io.h to asm-generic/ioport.h. (Arnd) - Adjust the implementation of iomem_is_ioport() in asm-generic/io.h so that it matches exactly what pci_iounmap() previously did in lib/pci_iomap.c. (Arnd) - Move the CONFIG_HAS_IOPORT guard in asm-generic/io.h so that iomem_is_ioport() will always be compiled and just returns false if there are no ports. - Add TODOs to several places informing about the generic iomem_is_ioport() in lib/iomap.c not being generic. - Add TODO about the followup work to make drivers/pci/iomap.c's pci_iounmap() actually generic. Changes in v2: - Replace patch 4, previously extending the comment about pci_iounmap() in lib/iomap.c, with a patch that moves pci_iounmap() from that file to drivers/pci/iomap.c, creating a unified version there. (Arnd) - Implement iomem_is_ioport() as a new helper in asm-generic/io.h and lib/iomap.c. (Arnd) - Move the build rule in drivers/pci/Makefile for iomap.o under the guard of #if PCI. This had to be done because when just checking for GENERIC_PCI_IOMAP being defined, the functions don't disappear, which was the case previously in lib/pci_iomap.c, where the entire file was made empty if PCI was not set by the guard #ifdef PCI. (Intel's Bots) - Rephares all patches' commit messages a little bit. Sooooooooo. I reworked v1. Please review this carefully, the IO-Ranges are obviously a bit tricky, as is the build-system / ifdef-ery. Arnd has suggested that architectures defining a custom inb() need their own iomem_is_ioport(), as well. I've grepped for inb() and found the following list of archs that define their own: - alpha - arm - m68k <-- - parisc - powerpc - sh - sparc - x86 <-- All of those have their own definitons of pci_iounmap(). Therefore, they don't need our generic version in the first place and, thus, also need no iomem_is_ioport(). The two exceptions are x86 and m68k. The former uses lib/iomap.c through CONFIG_GENERIC_IOMAP, as Arnd pointed out in the previous discussion (thus, CONFIG_GENERIC_IOMAP is not really generic in this regard). So as I see it, only m68k WOULD need its own custom definition of iomem_is_ioport(). But as I understand it it doesn't because it uses the one from asm-generic/pci_iomap.h ?? I wasn't entirely sure how to deal with the address ranges for the generic implementation in asm-generic/io.h. It's marked with a TODO. Input appreciated. I removed the guard around define pci_iounmap in asm-generic/io.h. An alternative would be to have it be guarded by CONFIG_GENERIC_IOMAP and CONFIG_GENERIC_PCI_IOMAP, both. Without such a guard, there is no collision however, because generic pci_iounmap() from drivers/pci/iomap.c will only get pulled in when CONFIG_GENERIC_PCI_IOMAP is actually set. I cross-built this for a variety of architectures, including the usual suspects (s390, m68k). So far successfully. But let's see what Intel's robots say :O P. Original cover letter: Hi! So it seems that since ca. 2007 the PCI code has been scattered a bit. PCI's devres code, which is only ever used by users of the entire PCI-subsystem anyways, resides in lib/devres.c and is guarded by an ifdef PCI, just as the content of lib/pci_iomap.c is. It, thus, seems reasonable to move all of that. As I were at it, I moved as much of the devres-specific code from pci.c to devres.c, too. The only exceptions are four functions that are currently difficult to move. More information about that can be read here [1]. I noticed these scattered files while working on (new) PCI-specific devres functions. If we can get this here merged, I'll soon send another patch series that addresses some API-inconsistencies and could move the devres-part of the four remaining functions. I don't want to do that in this series as this here is only about moving code, whereas the next series would have to actually change API behavior. I successfully (cross-)built this for x86, x86_64, AARCH64 and ARM (allyesconfig). I booted a kernel with it on x86_64, with a Fedora desktop environment as payload. The OS came up fine I hope this is OK. If we can get it in, we'd soon have a very consistent PCI API again. Regards, P. Philipp Stanner (5): lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() lib: move pci_iomap.c to drivers/pci/ lib: move pci-specific devres code to drivers/pci/ pci: move devres code from pci.c to devres.c lib, pci: unify generic pci_iounmap() MAINTAINERS | 1 - drivers/pci/Kconfig | 5 + drivers/pci/Makefile | 3 +- drivers/pci/devres.c | 450 +++++++++++++++++++++++++ lib/pci_iomap.c => drivers/pci/iomap.c | 49 +-- drivers/pci/pci.c | 249 -------------- drivers/pci/pci.h | 24 ++ include/asm-generic/io.h | 27 +- include/asm-generic/iomap.h | 21 ++ lib/Kconfig | 3 - lib/Makefile | 1 - lib/devres.c | 208 +----------- lib/iomap.c | 28 +- 13 files changed, 566 insertions(+), 503 deletions(-) create mode 100644 drivers/pci/devres.c rename lib/pci_iomap.c => drivers/pci/iomap.c (75%) -- 2.43.0