Message ID | 20240115144655.32046-2-pstanner@redhat.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-26124-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1747531dyc; Mon, 15 Jan 2024 06:47:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWPP9V7Ld/F5ezWNPGBx16vgKkMAc+JlrXyvr4qdCeZ449ZW6b6dpkQAj8BFvUJ2TFI5hD X-Received: by 2002:a17:906:3189:b0:a24:71bc:1aad with SMTP id 9-20020a170906318900b00a2471bc1aadmr2872810ejy.36.1705330055105; Mon, 15 Jan 2024 06:47:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330055; cv=none; d=google.com; s=arc-20160816; b=cuJcIKDJXW5fpKS2+qXOCPccwz3sCTd9ykUP05OX7MlAsBCpc0l+uEHoxHEr//rbbN c1ho7Edv/zgkQvSiHYwMuBQK3Xf9jA20j5Y5CpQp1hClT5xJdyaqsr2HtvgDDhLjMxT/ cCspJET9BlkJ8tBKC+XBCpCtymVnJM1/baRBwi8BDCa6m8R2L5Cc+KVL841zuO7rFbJ1 bSSDY4FcmJTW7345DKTLu6r8K4DzLuP4wfSa8IDJM4LXbwhpRntZGX8ICupqbGipsDNZ 2VOq8FQDxGWkLe5PAYksvqHnt/kMd2YY5b1Q+8JsTnZ3nXB3FYNsmYSt6gRvpJeYDm1y 1Bqg== 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=UrwJ0Dll5HmncyMrasdk757KsthsQI/A5KEU3nkZNh0=; fh=AY1J9PDScN0xrIvhrMJy8TMRSbPeq4owI1m0lsalYQU=; b=mO1SbuI2Yq+qnzTi+dW2zdA9hR9F+mFLm79MJhoPDyKQEt2n9xUIUp1bKAnzogxvb4 BQQ1AyYhFnJP19Tb0Wcrb0/iTCwX8Q+3rjkL/M4XTHIIQ1KuWaotUT/DjWl2YZYdZH+/ JoDoKTbuJmtozPTG4SZOThoIrutpX9ESuWFlE9G9s7B/y3/Mqdkg2kJ5IR338b1zqN9u Sq5mPE5eqwweCVc/JZor1fyu4wmuMpoY8BreRPa82UpLdK5Xs0nySmJ8p6Z3S5YtKHWk JKrQn0pLFwbgQ/PEI0L4VD57XUM6bGKFzklTxjjCRNHBuhXxtAPfVh/Ho6kvMiPwxhn7 hdSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PFOk4HYp; spf=pass (google.com: domain of linux-kernel+bounces-26124-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26124-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q4-20020a1709066b0400b00a29efb615c5si3828967ejr.613.2024.01.15.06.47.34 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:47:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26124-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PFOk4HYp; spf=pass (google.com: domain of linux-kernel+bounces-26124-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26124-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8C90B1F21F18 for <ouuuleilei@gmail.com>; Mon, 15 Jan 2024 14:47:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E36A617745; Mon, 15 Jan 2024 14:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PFOk4HYp" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 A395717735 for <linux-kernel@vger.kernel.org>; Mon, 15 Jan 2024 14:47:14 +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=1705330033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UrwJ0Dll5HmncyMrasdk757KsthsQI/A5KEU3nkZNh0=; b=PFOk4HYpqLALMZg3KyMLsrgiwixxsablXhB8Nivfv5MBxbO9RhjlYH6RDb52D5TmcWtJPk lRytrLEiCXiuD9517Hy+ZQwk+vV2CX/vhXIfnNWjRoz0Q9iCoKx9odYYEY8jj6GakoXK30 5kWjd4pV/bC4XTVpx6lP0gNGBYkpw5Y= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-320-Fj09ZgGYMTqQesgXy2X76g-1; Mon, 15 Jan 2024 09:47:12 -0500 X-MC-Unique: Fj09ZgGYMTqQesgXy2X76g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-67f826cc03dso24819496d6.1 for <linux-kernel@vger.kernel.org>; Mon, 15 Jan 2024 06:47:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705330032; x=1705934832; 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=UrwJ0Dll5HmncyMrasdk757KsthsQI/A5KEU3nkZNh0=; b=S3wmn1NZ2F9V0CZRQ7ADVmGgg7S3351F2plLzFKbUp/Dn1L1bb//0mKLYDWzzZ1zXb 262p5Ov/idWkA5+M/G8ACppgkKcSvT4mzrWm4RilxrPcP8vItP/jI9Om4bLpOnf6q55B erJ9NUVINcf+Jf0eXsJPkNcjMpFCGCzrI9iPx/x7DCwSTNVsH+bHxN1bMu0X5fObAdu2 J7JjNvZLiY+o94rEe1O09V8JCloiJ1lP2dsFm75EYmPCkrh28D705PbzTbvvKhaVc9iW HHDhr9o++O9S9Wic4KD6xLidIYOzDqRBYLHWlTqBWBnlfZKaTh861jmcqhLmcsv87pIy CGEQ== X-Gm-Message-State: AOJu0YwJjq4dNrwShDyknS3VT/LmPcUnV2rnc86KI9OfHH7X6ipeTBKL 0g/btma4PYbtcSNLuBpHyFLJ9B58UkEEMHyvYy3hg7LPKkW7RAtQ/nmE5mHJ72EnifpY7Qsf+Yz 9PTkU8hrCNoiqXTAsjI1BFQgrhKYNHORN X-Received: by 2002:a0c:ebc3:0:b0:681:5534:b42d with SMTP id k3-20020a0cebc3000000b006815534b42dmr6378817qvq.5.1705330031725; Mon, 15 Jan 2024 06:47:11 -0800 (PST) X-Received: by 2002:a0c:ebc3:0:b0:681:5534:b42d with SMTP id k3-20020a0cebc3000000b006815534b42dmr6378808qvq.5.1705330031444; Mon, 15 Jan 2024 06:47:11 -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 ne13-20020a056214424d00b006815cf9a644sm1020720qvb.55.2024.01.15.06.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:47:11 -0800 (PST) From: Philipp Stanner <pstanner@redhat.com> To: Jonathan Corbet <corbet@lwn.net>, Hans de Goede <hdegoede@redhat.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Bjorn Helgaas <bhelgaas@google.com>, Philipp Stanner <pstanner@redhat.com>, Sam Ravnborg <sam@ravnborg.org>, dakr@redhat.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 00/10] Make PCI's devres API more consistent Date: Mon, 15 Jan 2024 15:46:11 +0100 Message-ID: <20240115144655.32046-2-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788168167562526702 X-GMAIL-MSGID: 1788168167562526702 |
Series |
Make PCI's devres API more consistent
|
|
Message
Philipp Stanner
Jan. 15, 2024, 2:46 p.m. UTC
¡Hola! PCI's devres API suffers several weaknesses: 1. There are functions prefixed with pcim_. Those are always managed counterparts to never-managed functions prefixed with pci_ – or so one would like to think. There are some apparently unmanaged functions (all region-request / release functions, and pci_intx()) which suddenly become managed once the user has initialized the device with pcim_enable_device() instead of pci_enable_device(). This "sometimes yes, sometimes no" nature of those functions is confusing and therefore bug-provoking. In fact, it has already caused a bug in DRM. The last patch in this series fixes that bug. 2. iomappings: Instead of giving each mapping its own callback, the existing API uses a statically allocated struct tracking one mapping per bar. This is not extensible. Especially, you can't create _ranged_ managed mappings that way, which many drivers want. 3. Managed request functions only exist as "plural versions" with a bit-mask as a parameter. That's quite over-engineered considering that each user only ever mapps one, maybe two bars. This series: - add a set of new "singular" devres functions that use devres the way its intended, with one callback per resource. - deprecates the existing iomap-table mechanism. - deprecates the hybrid nature of pci_ functions. - preserves backwards compatibility so that drivers using the existing API won't notice any changes. - adds documentation, especially some warning users about the complicated nature of PCI's devres. Note that this series is based on my "unify pci_iounmap"-series from a few weeks ago. [1] I tested this on a x86 VM with a simple pci test-device with two regions. Operates and reserves resources as intended on my system. Kasan and kmemleak didn't find any problems. I believe this series cleans the API up as much as possible without having to port all existing drivers to the new API. Especially, I think that this implementation is easy to extend if the need for new managed functions arises :) Greetings, P. [1] https://lore.kernel.org/lkml/20240111085540.7740-1-pstanner@redhat.com/ Philipp Stanner (10): pci: add new set of devres functions pci: deprecate iomap-table functions pci: warn users about complicated devres nature pci: devres: make devres region requests consistent pci: move enabled status bit to pci_dev struct pci: move pinned status bit to pci_dev struct pci: devres: give mwi its own callback pci: devres: give pci(m)_intx its own callback pci: devres: remove legacy pcim_release() drm/vboxvideo: fix mapping leaks Documentation/driver-api/pci/pci.rst | 3 + drivers/gpu/drm/vboxvideo/vbox_main.c | 24 +- drivers/pci/devres.c | 996 ++++++++++++++++++++++---- drivers/pci/iomap.c | 18 + drivers/pci/pci.c | 124 +++- drivers/pci/pci.h | 24 - include/linux/pci.h | 17 + 7 files changed, 989 insertions(+), 217 deletions(-)
Comments
On Mon, Jan 15, 2024 at 03:46:11PM +0100, Philipp Stanner wrote: > ... > pci: add new set of devres functions > pci: deprecate iomap-table functions > pci: warn users about complicated devres nature > pci: devres: make devres region requests consistent > pci: move enabled status bit to pci_dev struct > pci: move pinned status bit to pci_dev struct > pci: devres: give mwi its own callback > pci: devres: give pci(m)_intx its own callback > pci: devres: remove legacy pcim_release() > drm/vboxvideo: fix mapping leaks If/when you update these, take a look at the drivers/pci/ subject line history and capitalize these to match. We haven't really used the "devres" prefix in drivers/pci. The de facto convention is: - "PCI/AER:" for major features defined by the PCIe base spec (AER, DPC, VGA, ASPM, PM, etc). - "PCI: iproc:" for controller drivers (iproc, dwc, qcom, mvebu, etc). - "PCI:" for everything else
Mon, Jan 15, 2024 at 03:46:11PM +0100, Philipp Stanner kirjoitti: > ¡Hola! i? Vim user? :-) > PCI's devres API suffers several weaknesses: > > 1. There are functions prefixed with pcim_. Those are always managed > counterparts to never-managed functions prefixed with pci_ – or so one > would like to think. There are some apparently unmanaged functions > (all region-request / release functions, and pci_intx()) which > suddenly become managed once the user has initialized the device with > pcim_enable_device() instead of pci_enable_device(). This "sometimes > yes, sometimes no" nature of those functions is confusing and > therefore bug-provoking. In fact, it has already caused a bug in DRM. > The last patch in this series fixes that bug. > 2. iomappings: Instead of giving each mapping its own callback, the > existing API uses a statically allocated struct tracking one mapping > per bar. This is not extensible. Especially, you can't create > _ranged_ managed mappings that way, which many drivers want. > 3. Managed request functions only exist as "plural versions" with a > bit-mask as a parameter. That's quite over-engineered considering > that each user only ever mapps one, maybe two bars. > > This series: > - add a set of new "singular" devres functions that use devres the way > its intended, with one callback per resource. > - deprecates the existing iomap-table mechanism. > - deprecates the hybrid nature of pci_ functions. > - preserves backwards compatibility so that drivers using the existing > API won't notice any changes. > - adds documentation, especially some warning users about the > complicated nature of PCI's devres. Instead of adding pcim_intx(), please provide proper one for pci_alloc_irq_vectors(). Ideally it would be nice to deprecate old IRQ management functions in PCI core and delete them in the future.
On Tue, 2024-01-16 at 23:17 +0200, andy.shevchenko@gmail.com wrote: > Mon, Jan 15, 2024 at 03:46:11PM +0100, Philipp Stanner kirjoitti: > > ¡Hola! > > i? Vim user? :-) The Dark Side of the Force is the path to many abilities, that some consider to be... unnatural https://www.neo-layout.org/ > > > PCI's devres API suffers several weaknesses: > > > > 1. There are functions prefixed with pcim_. Those are always > > managed > > counterparts to never-managed functions prefixed with pci_ – or > > so one > > would like to think. There are some apparently unmanaged > > functions > > (all region-request / release functions, and pci_intx()) which > > suddenly become managed once the user has initialized the device > > with > > pcim_enable_device() instead of pci_enable_device(). This > > "sometimes > > yes, sometimes no" nature of those functions is confusing and > > therefore bug-provoking. In fact, it has already caused a bug in > > DRM. > > The last patch in this series fixes that bug. > > 2. iomappings: Instead of giving each mapping its own callback, the > > existing API uses a statically allocated struct tracking one > > mapping > > per bar. This is not extensible. Especially, you can't create > > _ranged_ managed mappings that way, which many drivers want. > > 3. Managed request functions only exist as "plural versions" with a > > bit-mask as a parameter. That's quite over-engineered > > considering > > that each user only ever mapps one, maybe two bars. > > > > This series: > > - add a set of new "singular" devres functions that use devres the > > way > > its intended, with one callback per resource. > > - deprecates the existing iomap-table mechanism. > > - deprecates the hybrid nature of pci_ functions. > > - preserves backwards compatibility so that drivers using the > > existing > > API won't notice any changes. > > - adds documentation, especially some warning users about the > > complicated nature of PCI's devres. > > Instead of adding pcim_intx(), please provide proper one for > pci_alloc_irq_vectors(). Ideally it would be nice to deprecate > old IRQ management functions in PCI core and delete them in the > future. > In order to deprecate the intermingling with half-managed hyprid devres in pci.c, you need to have pci_intx() be backwards compatible. Unless you can remove it at once. And the least broken way to do that I thought would be pcim_intx(), because that's consistent with how I make pci_request_region() & Co. call into their managed counterparts. There are 25 users of pci_intx(). We'd have to look how many of them call pcim_enable_device() and how easy they would be to port to... pci_alloc_irq_vectors() you say? I haven't used that before. Would have to look into it and see how we could do that. P.
On Wed, 2024-01-17 at 10:59 +0100, Philipp Stanner wrote: > On Tue, 2024-01-16 at 23:17 +0200, andy.shevchenko@gmail.com wrote: > > Mon, Jan 15, 2024 at 03:46:11PM +0100, Philipp Stanner kirjoitti: [...] > > > > > > > PCI's devres API suffers several weaknesses: > > > > > > 1. There are functions prefixed with pcim_. Those are always > > > managed > > > counterparts to never-managed functions prefixed with pci_ – > > > or > > > so one > > > would like to think. There are some apparently unmanaged > > > functions > > > (all region-request / release functions, and pci_intx()) which > > > suddenly become managed once the user has initialized the > > > device > > > with > > > pcim_enable_device() instead of pci_enable_device(). This > > > "sometimes > > > yes, sometimes no" nature of those functions is confusing and > > > therefore bug-provoking. In fact, it has already caused a bug > > > in > > > DRM. > > > The last patch in this series fixes that bug. > > > 2. iomappings: Instead of giving each mapping its own callback, > > > the > > > existing API uses a statically allocated struct tracking one > > > mapping > > > per bar. This is not extensible. Especially, you can't create > > > _ranged_ managed mappings that way, which many drivers want. > > > 3. Managed request functions only exist as "plural versions" with > > > a > > > bit-mask as a parameter. That's quite over-engineered > > > considering > > > that each user only ever mapps one, maybe two bars. > > > > > > This series: > > > - add a set of new "singular" devres functions that use devres > > > the > > > way > > > its intended, with one callback per resource. > > > - deprecates the existing iomap-table mechanism. > > > - deprecates the hybrid nature of pci_ functions. > > > - preserves backwards compatibility so that drivers using the > > > existing > > > API won't notice any changes. > > > - adds documentation, especially some warning users about the > > > complicated nature of PCI's devres. > > > > Instead of adding pcim_intx(), please provide proper one for > > pci_alloc_irq_vectors(). Ideally it would be nice to deprecate > > old IRQ management functions in PCI core and delete them in the > > future. > > > > In order to deprecate the intermingling with half-managed hyprid > devres > in pci.c, you need to have pci_intx() be backwards compatible. Unless > you can remove it at once. > And the least broken way to do that I thought would be pcim_intx(), > because that's consistent with how I make pci_request_region() & Co. > call into their managed counterparts. > > There are 25 users of pci_intx(). > We'd have to look how many of them call pcim_enable_device() and how > easy they would be to port to... pci_alloc_irq_vectors() you say? I > haven't used that before. Would have to look into it and see how we > could do that. Alright, so I thought about that a bit. So pci_intx() is the old way to do it and you would like to deprecate it for good. Understood, makes sense This series, however, is about deprecating PCI's broken devres implementation – not about deprecating outdated PCI features in general. So I wouldn't like to touch anything here unless cleaning up devres demands it. Now the question would be: how can we solve this? My suggestion would be: Let's implement pcim_intx(), but only make it visible through drivers/pci/pci.h. So we won't make it usable for other drivers, don't EXPORT_SYMBOL() it and basically only have it as a tool to move the devres-part clearly and cleanly from pci.c to devres.c Further deprecating old PCI stuff could then be done in a separate series. ACK? P. > > > P.