Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2558977lqz; Wed, 3 Apr 2024 01:20:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYm3mZQC+zsSpgFbdeL4D3RcgHU1+cqTb8/+EOxRTSWZTg71iSX29gOcH4uRDQor0ZPyBtlEE47Vd8MKxcY9EOu6YP3GXImCn7QKEwCA== X-Google-Smtp-Source: AGHT+IERKwr6eiMSdlmd1vLV83uIKZqex/MVgfUDgMW2c8qdEdnarTyeuKra+gfnyKPYP+BVCso4 X-Received: by 2002:a05:6358:338c:b0:183:bfed:e85f with SMTP id i12-20020a056358338c00b00183bfede85fmr1834183rwd.31.1712132421727; Wed, 03 Apr 2024 01:20:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712132421; cv=pass; d=google.com; s=arc-20160816; b=MQIBwByRRQc68dh03f5nqRTYLBX+0nHW7NI0W/3yLVw6zzKd7ILXQchoef82tLpcG4 BXj8wy1Is+ymAh9J8gfxzbGWVwLTBlDaY6bQI+L9EBOx8H8kVj1T3hCw/G89pEWjInuT 8R+uYXuvBfQ+XKbFOevDxA7Jjl+6ugO8JclwXfDZGhaVJyPpoI1NqxMcGzcVLu/VD/L1 PUBLSX4mrhY1x7llsri8T9lHtlQSOPc7fo4WEU2M/Li9q9/Bn1fmKVzTXvZPUaQ9bkaj NkSt5pACXHBQS8ZaoHShtxq+X2KVHPbe4SRyvRw4Tz5mjLNTjJQF3jGpLZEaMDwIxXSL Ukkw== 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=cqd0XV6NVHg28KpejWCVVeMq/IoUZp7GtZTIzYnrVC8=; fh=ddVKYfNcuGC8skyWEmft5kjsYsdkB3UdBkDrSVNFV6M=; b=nW3x4tTlLlSfuiy/mRi0GxehuIdxv0kLv5VCTv4tiZ8v/58AaBUNVWHDIKLaykb0yO +9XkmqJPcPY2UjmDwkJ4NZvvAsbeMLZSjlSS0U40k6lJ4AVEy8mQIEdQXeP0HlPufAJr YLQLqTHPkKu97y+b1VDWNDloqNauydHZrTARlP9sEr6TF7Hi0sOCuT9JN1HuVRyKPkbp eGA8fE1/OhCKCS5d1PqNsNCMkNIp5Qv7csxOT8NzDazg8QQYuLE952Y46sOK4MWzvIkK 1JnIjJ8BMkJK58ztCL+w/caKOmUs7LZs1rAErT49/C2kbKf4ub1eGbdXIUvmzc7jWb6/ EIEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TwSRCbg0; 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-129270-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129270-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 g6-20020a63fa46000000b005dc84ba3c3asi12565015pgk.287.2024.04.03.01.20.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129270-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=TwSRCbg0; 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-129270-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129270-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 3B453287229 for ; Wed, 3 Apr 2024 08:14:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC99A80BE5; Wed, 3 Apr 2024 08:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TwSRCbg0" 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 DF27A80611 for ; Wed, 3 Apr 2024 08:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131657; cv=none; b=hdMzQh/XhBLx3vlf1kjQagXYmMoZKzFWgVld3kWQjwxBIf4SjL7PQnC/BkUmoj97rS8EvnTc9lWHcDlDR8pxMAw9uTtoPGGG3VovaZpns0u72iAo3gvQtOD1X/UDcF0iWhGCl8su/5FdMVeWK3cq/mMnN0a1Ju1YCUpzLKBUUTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131657; c=relaxed/simple; bh=nBKWG5c5FhCBx7bhOlD5JxIgz1Oj/+3VoPRHxP5kZYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gPKAcXh6IPFu/OZMfHCMQW1U7aTHre7QHwgRoNE1Sv9uQlhYkMU3ScqhlN5uHJwvqw90/yE9pUpJa+attOckeixfa2wXmq4hCtlnAAUBEi19VKy5yQFZVfTnpnHSmEfG8isoASo2Q1BWF5/36WJXQna6yLiEQAXoAppmBjrB+yQ= 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=TwSRCbg0; arc=none smtp.client-ip=170.10.129.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=1712131652; 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=cqd0XV6NVHg28KpejWCVVeMq/IoUZp7GtZTIzYnrVC8=; b=TwSRCbg0xMM7fqPUj5l32DpTfMyhhwuEzRP5gxjmDHvYWf20qUVgPLfDaktxt4fGgJQi7C 2HfqlQdm+GVegUzwmg/C/vneUqko57klE8NyrlgV5IzHnwObcEF4l6KUdIBuLSVDRYS/1R FtlJ/poE4lJNfGVgKiqOV7a9LgDUuXM= 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-629-gHeuho0XNQKBRJ1jDE0kIw-1; Wed, 03 Apr 2024 04:07:31 -0400 X-MC-Unique: gHeuho0XNQKBRJ1jDE0kIw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-34370209778so339197f8f.1 for ; Wed, 03 Apr 2024 01:07:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712131650; x=1712736450; 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=cqd0XV6NVHg28KpejWCVVeMq/IoUZp7GtZTIzYnrVC8=; b=Hjm+zpXG0anxZrQLKRRGfLBmlpVaU3LEnuhROGXfe66u3x/YUe4x7z29TnMVOQQin4 tYHRcKUtdgLNil6J+EODfZcFlt9VLt5S9+FwHjRwKo/pMQ5B3/SQdpIdQcSuAZLTW3iG sstdBOqgm1E+d7anzQhRiRItGj0s06i2o5pIkauwC1RXhQJ82KAELl1eSNq+Xm6i+/XL 3U7m//bSqxoazwCqaCvzmNHt1G2ZB6LLJmH4n7e/wpkhrEQSX8tyS1XTP6BQljyW8wUw vqP57vhz2fGGE8445Dj8YcDL0/4txsO+Wgt11dgBsCtYKrg9m2N2VF7ZuIoJCJzlf2aQ rqig== X-Forwarded-Encrypted: i=1; AJvYcCVhKAapMBf6WsJ+0x1f8TuflteUCctoasBWbe9MIGLblue+Sxdkh76EClERNm0dmbJ6Akc5V7KWo/thcmc77aY51TSQXvJ1aFw5HIwr X-Gm-Message-State: AOJu0YwPiqXAHdXWCosf9lQxJJyXUmqQozx4TE/PRC8ucVww9jv3u/Fx JTs1c5W+T9rICE+JL24UX0UtJqIL4aGrgvNMyS9nd+30LFTrQB5KviWMP7oQEu8Z87YdPCwdc84 +gsfx0yYP/I5oWXs+aYHUrCeykTSDJ0VJ6+9cs3G0w3Kn/q17rzTPXzV7ebZcIA== X-Received: by 2002:a05:600c:5114:b0:414:8084:a2e7 with SMTP id o20-20020a05600c511400b004148084a2e7mr11598558wms.4.1712131649978; Wed, 03 Apr 2024 01:07:29 -0700 (PDT) X-Received: by 2002:a05:600c:5114:b0:414:8084:a2e7 with SMTP id o20-20020a05600c511400b004148084a2e7mr11598544wms.4.1712131649686; Wed, 03 Apr 2024 01:07:29 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id fa14-20020a05600c518e00b004159df274d5sm5504535wmb.6.2024.04.03.01.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:07:29 -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 v5 03/10] PCI: Warn users about complicated devres nature Date: Wed, 3 Apr 2024 10:07:04 +0200 Message-ID: <20240403080712.13986-6-pstanner@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240403080712.13986-2-pstanner@redhat.com> References: <20240403080712.13986-2-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 bugs by confusing users, who came to believe that all pci functions, such as pci_iomap_range(), suddenly are managed that way. This is not the case. Add comments to the relevant functions' docstrings that warn users about this behavior. Signed-off-by: Philipp Stanner --- drivers/pci/iomap.c | 18 ++++++++++++++ drivers/pci/pci.c | 60 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iomap.c b/drivers/pci/iomap.c index c9725428e387..ea3b9842132a 100644 --- a/drivers/pci/iomap.c +++ b/drivers/pci/iomap.c @@ -23,6 +23,11 @@ * * @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(). + * If you need automatic cleanup, use pcim_iomap_range(). * */ void __iomem *pci_iomap_range(struct pci_dev *dev, int bar, @@ -63,6 +68,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 +115,11 @@ 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 +141,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 b5d21d8207d6..9d9d09534efe 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3903,6 +3903,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 @@ -3914,6 +3916,13 @@ EXPORT_SYMBOL(pci_release_region); * * Returns 0 on success, or %EBUSY on error. A warning * message is also printed on failure. + * + * NOTE: + * This is a "hybrid" function: Its normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. + * This hybrid feature is DEPRECATED! If you need to implement a new pci + * function that does automatic cleanup, write a new pcim_* function that uses + * devres directly. */ static int __pci_request_region(struct pci_dev *pdev, int bar, const char *res_name, int exclusive) @@ -3962,6 +3971,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 @@ -3969,6 +3980,12 @@ 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: Its 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) { @@ -3994,6 +4011,13 @@ void pci_release_selected_regions(struct pci_dev *pdev, int bars) } EXPORT_SYMBOL(pci_release_selected_regions); +/* + * NOTE: + * This is a "hybrid" function: Its 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. + */ static int __pci_request_selected_regions(struct pci_dev *pdev, int bars, const char *res_name, int excl) { @@ -4019,6 +4043,14 @@ 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: Its 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) @@ -4027,6 +4059,20 @@ 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: Its 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) { @@ -4044,7 +4090,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); @@ -4076,6 +4121,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. @@ -4085,6 +4132,12 @@ 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: Its 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) { @@ -4416,6 +4469,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: Its 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.44.0