From patchwork Wed Dec 13 10:49:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 17969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7685043dys; Wed, 13 Dec 2023 02:49:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/BB+Yrv1NgcpUHtb5OGJ9M1PcdMvG9U9ORNcCr5AwzcFlwAQ+dACI+Lr0n9yWka2WsfNp X-Received: by 2002:aa7:91cc:0:b0:6ce:f6f2:2a8c with SMTP id z12-20020aa791cc000000b006cef6f22a8cmr6341761pfa.46.1702464582305; Wed, 13 Dec 2023 02:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702464582; cv=none; d=google.com; s=arc-20160816; b=Gf8bXBdPW3RhxxN/TaFJ67FxDHETZOYnX7WM8coiL8JsY7f6C2kicwIsdToJcWgGAD ZeBsIN/f9+bKnW2TtS7ajdyE+Ju9Gzafho0xnOtbBnQHB0orMnr0L5+SDOn0rTvDRXtM p1yaKsruOcnfpJeuijcGHfcKSvuHkmEXF+pQM/Wg84d7RSHr5SNe//o9nMy4fhSsJqL/ 3Nqf4g+ujUgPOPriMe+ncubPEsAQwhBQUFJmkm4T+FIkhj+6Fnzn2ylT+B5xbeVudBxe k8gSP6Dcc9cl95zWRk67U/xc156y0q7sC9sU66IvW4+m9FZ40QRnM0Zwf5HZp96TtA20 4q+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Jsenl4ryPejHUAvVnk0GRNLRuch6fMe21jriRXS4vNY=; fh=C7LQW+4J0BgiMGOKM1Hc288DqCJKKjCWWy6i3V6pGhc=; b=yzpjiAAr5p50t/DvZEGlbWHKq/bsrDwnETWzeh1ciZrJwGpMjKRSgWr1d0h02+V0oh 0mRJI5/uSkhq5t6BXxdVs3V0FuYDRmFsyUf1ulIiBvAlNa+vz+TiF947lkj1CcSkP8o7 cg1mcEZgCjDwNqFcphXjoiks2AnxInC66x6PfdfqPHNk64jw31fgPdOptSr7zfU8LsVX WoQ0VYcjN+ZYzvU5U89wbhRJw5pdtZCQCkP4FxW9/nnccOIOXDwsAonpLjH3DpN9E2GZ zJF/B5yT2zlizM0Pzrp5+JCizKqmJUB7mCH60dPzmNXbz2gCd0fQe29FoTVUwHwOjlRd lj0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RhlJT0Pv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q9-20020a63f949000000b005c1cc7273bcsi9417333pgk.731.2023.12.13.02.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:49:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RhlJT0Pv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BD77E806CC0C; Wed, 13 Dec 2023 02:49:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377845AbjLMKt3 (ORCPT + 99 others); Wed, 13 Dec 2023 05:49:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377827AbjLMKt2 (ORCPT ); Wed, 13 Dec 2023 05:49:28 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C3E99 for ; Wed, 13 Dec 2023 02:49:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702464571; 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=RhlJT0PvLGVVp0hI20MxX8lTSj2OwdZ/tT4k9Vsg6H5DfKawbQzlVOmo9fKRe5JJxoOFiD OUHpUR0mTVn+a9hTYRgm3IfRi2scMptAoqXfUyPL0Yc7uRx4pEat6wuaTpVMW7S4iv1X7h 4UoItnA864AirPOGX0lBSvOiJhiLAlM= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-494-2Ix3hmQgN62f22wRCIVUFQ-1; Wed, 13 Dec 2023 05:49:30 -0500 X-MC-Unique: 2Ix3hmQgN62f22wRCIVUFQ-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a1e27c6de0eso141068466b.1 for ; Wed, 13 Dec 2023 02:49:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702464569; x=1703069369; 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=LiHbuW5zvgSwy3qVMeiBVmEUE9htjqlmO9ehqH6VtMBNrr7WUqIyYi3moDGXnN+snw Dixhwxtlu+RIewRAHSdIU62zoL0yZ3yk5/rP6cqqhe/cnRNsiFRfSMyZWzfvnHygomLo MRhrjrITnRYdBksimKwdwP3v6uD4YCHWMfImUGQOidCm3BkzfiT5btmI5Xw4EmSEu7Yd MzR0SAXwIsdyiWHgUQZSTNGdx8GLg2paWqOi52BmjTkzM8mOY3FB6QJbF0C6CTnEmsr8 o89VuSaRmBhlu+UDthI5eHnS90EkBKzhjsdIpUUWMDzb2h9saaPDVILkStXaUmvN9zD9 9Hqg== X-Gm-Message-State: AOJu0YwnNxE6Pc1cRR8eK9qK+cj4YH3SvZnSi418UCnDIMQuX1yKIL9R 5+W2n6DfuaNaxx3XmmSAAW6fQ6pElkeAJDS6CdCUjY55Jt4cit/rLNffxle0UbnldP+m9bRe4iV agJ67rR2u3v1Dv0HFFRexII7q X-Received: by 2002:a17:906:99cf:b0:a1c:5944:29bb with SMTP id s15-20020a17090699cf00b00a1c594429bbmr8372971ejn.7.1702464568905; Wed, 13 Dec 2023 02:49:28 -0800 (PST) X-Received: by 2002:a17:906:99cf:b0:a1c:5944:29bb with SMTP id s15-20020a17090699cf00b00a1c594429bbmr8372945ejn.7.1702464568536; Wed, 13 Dec 2023 02:49:28 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2a01:599:914:ed27:4fa9:dbce:10f5:d0b9]) by smtp.gmail.com with ESMTPSA id vu8-20020a170907a64800b00a1d5c52d628sm7527135ejc.3.2023.12.13.02.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:49:28 -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 0/5] Regather scattered PCI-Code Date: Wed, 13 Dec 2023 11:49:17 +0100 Message-ID: <20231213104922.13894-1-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:49:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785163501833311750 X-GMAIL-MSGID: 1785163501833311750 @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%)