Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp92990lqs; Thu, 13 Jun 2024 05:04:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkVRhu2Kn9xpKKxoS+IKi/odm39IucwkIDFn/i4E+JyBxPnihTN8KHmlI8MEXlfHgK65WlexJqTQwsArWp8Gz7Oi2V6YIkgZChZ83IEA== X-Google-Smtp-Source: AGHT+IEKrX9wlHSX0MmNXjyW2tik+u2V1nSY+geMQsLR2qurMWJETYodNR32ByLNWiu/FwgTogWr X-Received: by 2002:a17:906:3459:b0:a6f:1f67:9816 with SMTP id a640c23a62f3a-a6f5242bd4bmr178498566b.22.1718280278036; Thu, 13 Jun 2024 05:04:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718280278; cv=pass; d=google.com; s=arc-20160816; b=Lvnvmwt2sNNBGL3KXINz9wgexnBvQuvHdTNkfIL/QD9+8wqOkiX6sh8fHxBWAun9W6 0H+t72efP/NoX2fJigZfZVmlD0MfOKLRbCdZqIzIQ7y9HQSfxbx1ob3gA1tpuZMSZCKz 2AlffbiULQa/WSnjUXlVsLe2JVt4X8Bf+brbqb86C730nADtLhwoj+QPGbCrCWK9tyxE RZGGPpZJT9cztR6q6zzadI2h9oWWWz3Fe5Ri0vcKJZFMMDejFdI6wvodMDAPAdlz3X/C 5KnMEbWpQBxL48dTgzBlXjEtxTdRJpzZCTy6VP1/7opozg9sia1eJG12zqpFEuErS1rJ jGhg== ARC-Message-Signature: i=2; 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=QeDlmSjlnwr2O/aP5XCLyUukk4Ihvpzfb1AuxNmdg5k=; fh=ASDQqmmqKoOJ6pJZQ0FDOkXWFIM9ZSR2nlOXQrUREQU=; b=vNQP2DjiHUNoj7fXmNalF0ckA0mAeb+zVrbesq3zcqx+Qx0nPUOoJ1A4PEjEy2LutB lwNcOuobi+Pc4HAxRzpQUG8dIYBn/edK2T0u4NYo7IBgDli6yncR7+dRw9swsnLH9uVv +YtO5sCfg4IF9kld5KZHvWWRtI4lQgfrd9gEl5/ZHl13PDNywvWom28zi3XwdN07Z5Jd IxOa+yy7FlY2rBt/ZqdhscvA+LWUSPFTEQXtbWKH/ybtgbDt7Mwc8DDVMy6FOd6vmQ7W Cxil6I0c9FcYT8YBHyfWFLpGIlp5Rz55vzHn4sx1m2r5NY9NaPteY2c4cOm4MzWtsJSL 0z7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T/n41iVj"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-213138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213138-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56dd59a3si66316266b.431.2024.06.13.05.04.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 05:04:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213138-linux.lists.archive=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=@redhat.com header.s=mimecast20190719 header.b="T/n41iVj"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-213138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213138-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3908C1F2629B for ; Thu, 13 Jun 2024 11:55:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3072D148FF7; Thu, 13 Jun 2024 11:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="T/n41iVj" 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 D7F0F1487E7 for ; Thu, 13 Jun 2024 11:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279458; cv=none; b=VMONYe87OdxMSQlV/fMlRNSeAIVxV5pS3pfR1CM8AkTAhiWnszpXheKs2p4F2bPgzPANK0qp147441HAzQvYX/z9Equ/8wpErk3WmDzBuQC0tEH4HpEltQ6bHghUvkC9pTGUkuVSp/Tn4IrSEO7mDTMloG5f+xHb0+p03uBF7nI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279458; c=relaxed/simple; bh=5PE3+Mg+QJfwk/81MP4neUpiVdZJoI7gS0UJ6lgiki8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M9av5vIozgdEzOacHp8/PVjAOw94VFHfacdu/i+KRGhWOLxPm/kYs6dqyHsUPCUkVAv2voY6c+erz2FemKdl8+CwQPe/CEX+2w5aHE09/2s8WThN6ym8S5W1vKncP8AuhtPHP1Q/meATBButxmwV8z+uRCueCgtBRydkzEWxL0Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=T/n41iVj; arc=none smtp.client-ip=170.10.133.124 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=1718279456; 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: in-reply-to:in-reply-to:references:references; bh=QeDlmSjlnwr2O/aP5XCLyUukk4Ihvpzfb1AuxNmdg5k=; b=T/n41iVjh1P6aYCjsIKYID7ZZOeTnFD73SvMxRYW7yHb7wqVkqNq1CoL4kx9nc2vK6iDWc Q0uaHaiXod3YR5GVqd1SSZ1lpD7JvqvLzZoDT1ftTU3YjOMarBFpjrZOwuRtf0V9mhgELw zeQd926AFOaWKSlh8umc3vmhGA4TkhE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-oYDIUXGaM_yFJv6iZNi6Dw-1; Thu, 13 Jun 2024 07:50:52 -0400 X-MC-Unique: oYDIUXGaM_yFJv6iZNi6Dw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-35f291b147dso4584f8f.0 for ; Thu, 13 Jun 2024 04:50:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279451; x=1718884251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QeDlmSjlnwr2O/aP5XCLyUukk4Ihvpzfb1AuxNmdg5k=; b=h/lXtuYLaP/RIc30h5wmWMigdN2o4e28VhjgUhFkKcvJR+Dz1fZK2tncHvOvfPHeW3 RPMowjZiAguVypEe8oc9USWeGe0zL9LRjUWVLgGgC8QbOI6gBc896zw2bJOyZ0xBB4VE GkmNkfYP+Nxdl8bUIJZu0L97X/XPOr8Ntord7Hw+tUh34D97F/0f12H/FqaaklUexjDE yVSakJO2tEliy+jZhWm3+nXvsxM2iVsjDsEXo6/TikZasZjs2MrLT6ZEP8jQdllLiFtj FwW2HSYIc2TU2BHgq6hJ6MCQVtLSxv0SDjKC8Kr7lzQrsmcvdXtVClX6rNsnEFwqKay6 B4nw== X-Forwarded-Encrypted: i=1; AJvYcCVcbpBMgD7ZUpsHKJ6y36DaDAVDq+wHCpwxcKV9IiQb0LrutTvpGkDpa3Q7BEEQIIDLopGGUjL9Xk9EY4yglkwGum5gfBhyvjwGYCM7 X-Gm-Message-State: AOJu0YzMlODfx56QwdPfNkWpqojzqNQrKo61yiR0YNpoTg1i77DcmLua DP0HhEg4MUJ+2U3fdJGL0PcmqKMRlUXuSbbpHCMg9Ix212NodVJHT/D7W8UiBTE22eZuZtOhWDD W6F5wED1P1ku5LSbSYnjjSbu4gM/+oscOm9qBt56fWwe4mIAtUGnGEZpQzygUBg== X-Received: by 2002:a05:6000:1845:b0:35f:1f7e:892e with SMTP id ffacd0b85a97d-36079a5fdddmr172025f8f.7.1718279451485; Thu, 13 Jun 2024 04:50:51 -0700 (PDT) X-Received: by 2002:a05:6000:1845:b0:35f:1f7e:892e with SMTP id ffacd0b85a97d-36079a5fdddmr172006f8f.7.1718279451134; Thu, 13 Jun 2024 04:50:51 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c883sm1510620f8f.29.2024.06.13.04.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:50 -0700 (PDT) From: Philipp Stanner To: Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Sam Ravnborg , dakr@redhat.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Philipp Stanner Subject: [PATCH v9 06/13] PCI: Warn users about complicated devres nature Date: Thu, 13 Jun 2024 13:50:19 +0200 Message-ID: <20240613115032.29098-7-pstanner@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240613115032.29098-1-pstanner@redhat.com> References: <20240613115032.29098-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The PCI region-request functions become managed functions when pcim_enable_device() has been called previously instead of pci_enable_device(). This has already caused a bug (in 8558de401b5f) by confusing users, who came to believe that all PCI functions, such as pci_iomap_range(), suddenly are managed that way, which is not the case. Add comments to the relevant functions' docstrings that warn users about this behavior. Link: https://lore.kernel.org/r/20240605081605.18769-8-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/iomap.c | 16 ++++++++++++++++ drivers/pci/pci.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iomap.c b/drivers/pci/iomap.c index c9725428e387..a715a4803c95 100644 --- a/drivers/pci/iomap.c +++ b/drivers/pci/iomap.c @@ -23,6 +23,10 @@ * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR from offset to the end, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_range(struct pci_dev *dev, int bar, @@ -63,6 +67,10 @@ EXPORT_SYMBOL(pci_iomap_range); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR from offset to the end, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar, @@ -106,6 +114,10 @@ EXPORT_SYMBOL_GPL(pci_iomap_wc_range); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR without checking for its length first, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). If you need automatic cleanup, use pcim_iomap(). * */ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) { @@ -127,6 +139,10 @@ EXPORT_SYMBOL(pci_iomap); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR without checking for its length first, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen) { diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7013699db242..5e4f377411ec 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3900,6 +3900,8 @@ EXPORT_SYMBOL(pci_release_region); * @res_name: Name to be associated with resource. * @exclusive: whether the region access is exclusive or not * + * Returns: 0 on success, negative error code on failure. + * * Mark the PCI region associated with PCI device @pdev BAR @bar as * being reserved by owner @res_name. Do not access any * address inside the PCI regions unless this call returns @@ -3950,6 +3952,8 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, * @bar: BAR to be reserved * @res_name: Name to be associated with resource * + * Returns: 0 on success, negative error code on failure. + * * Mark the PCI region associated with PCI device @pdev BAR @bar as * being reserved by owner @res_name. Do not access any * address inside the PCI regions unless this call returns @@ -3957,6 +3961,11 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, * * Returns 0 on success, or %EBUSY on error. A warning * message is also printed on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) { @@ -4007,6 +4016,13 @@ static int __pci_request_selected_regions(struct pci_dev *pdev, int bars, * @pdev: PCI device whose resources are to be reserved * @bars: Bitmask of BARs to be requested * @res_name: Name to be associated with resource + * + * Returns: 0 on success, negative error code on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_selected_regions(struct pci_dev *pdev, int bars, const char *res_name) @@ -4015,6 +4031,19 @@ int pci_request_selected_regions(struct pci_dev *pdev, int bars, } EXPORT_SYMBOL(pci_request_selected_regions); +/** + * pci_request_selected_regions_exclusive - Request regions exclusively + * @pdev: PCI device to request regions from + * @bars: bit mask of BARs to request + * @res_name: name to be associated with the requests + * + * Returns: 0 on success, negative error code on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. + */ int pci_request_selected_regions_exclusive(struct pci_dev *pdev, int bars, const char *res_name) { @@ -4032,7 +4061,6 @@ EXPORT_SYMBOL(pci_request_selected_regions_exclusive); * successful call to pci_request_regions(). Call this function only * after all use of the PCI regions has ceased. */ - void pci_release_regions(struct pci_dev *pdev) { pci_release_selected_regions(pdev, (1 << PCI_STD_NUM_BARS) - 1); @@ -4064,6 +4092,8 @@ EXPORT_SYMBOL(pci_request_regions); * @pdev: PCI device whose resources are to be reserved * @res_name: Name to be associated with resource. * + * Returns: 0 on success, negative error code on failure. + * * Mark all PCI regions associated with PCI device @pdev as being reserved * by owner @res_name. Do not access any address inside the PCI regions * unless this call returns successfully. @@ -4073,6 +4103,11 @@ EXPORT_SYMBOL(pci_request_regions); * * Returns 0 on success, or %EBUSY on error. A warning message is also * printed on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name) { @@ -4404,6 +4439,11 @@ void pci_disable_parity(struct pci_dev *dev) * @enable: boolean: whether to enable or disable PCI INTx * * Enables/disables PCI INTx for device @pdev + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! */ void pci_intx(struct pci_dev *pdev, int enable) { -- 2.45.0