Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp361331rdb; Tue, 23 Jan 2024 01:47:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3LEw/QxmcftLQrE4TKb7O9hckm9W02lDD58WQ7jY/vsdV6QqhK1mdgVQ5dQtPQQ3tszfH X-Received: by 2002:a05:6512:3c91:b0:50e:abd1:bfba with SMTP id h17-20020a0565123c9100b0050eabd1bfbamr1534969lfv.15.1706003252689; Tue, 23 Jan 2024 01:47:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706003252; cv=pass; d=google.com; s=arc-20160816; b=LnYm1xKmeeG2lspKdwd8xLCCCiepUUHKb3GIiB9UTDrih91CGWxV+88am1F159N2fW wHheJRlGPYVbl7+0Z9CNJcAuJzOrcjcosT7POjEzvJpyMA2hmKxV0PYsiG/cKK/r+JJb gbAuxipXEYvhEJhMV8cStu6P1LMRawZdj1UiLgN5esVUHX0HH34OfakXF5plw8GNxgyn jQ4CKSkoNHUTlSOLysi0VC+gpaExycfbg3eEREbWPZ17OcGKAB9FThEdDjLhmX0gvgks ZwQMvmKYeZVU/N7U7LA/KqDKmB2YpwlHsODLsvQqpmQgnJoGINhc/b9dyOXnAakWUim1 CtRg== 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=3EoIsZMzaud9t26sivTeCHJdwdosgvCL2VSONhiwz3c=; fh=AY1J9PDScN0xrIvhrMJy8TMRSbPeq4owI1m0lsalYQU=; b=nyg2BJ6pbzwRrJBTZUgl46+UXa8vq9+4MZaYBW54ITurX/ZvX1dqC8Lj54iaHURPez dbOywqcuXOoGWjESWMbVLFWgEtr8pAfEvM0NxCJjwVP4qpt0mwafa/aqELbCJAX9lTe0 R96HCJ/Zw1a5hLgE44eNB8oiYV5iwmhXFlpBaolgHO+ZvGnOe5s1uueLL08hDLU4ismB GvvC3udVyL/po7x+MXh4Kt/53Hr91OcruczHg36PibMwbpDh+XWA5CrRAcdbsxgpBhas 5iyr9CltFSWSDcwOO9v/kUx4fYBatX3d6yOwDIRCzt3eL4g0wkwjJggBHU0hLdD701oW 1eug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZHUuyG0w; 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-35024-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35024-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 l21-20020a170906231500b00a27cc992b15si11731148eja.639.2024.01.23.01.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:47:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35024-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=ZHUuyG0w; 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-35024-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35024-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 459BF1F237A9 for ; Tue, 23 Jan 2024 09:47:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A6625C5E0; Tue, 23 Jan 2024 09:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZHUuyG0w" 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 6682E5A11C for ; Tue, 23 Jan 2024 09:44:55 +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=1706003097; cv=none; b=LBs0G2/fg7Qunm/serlBwq5EHSDgk6yM+mJ/0aYnIt3XydXlcHgF2IO6n+w0WoWCy7l6+8UtFEGrT1kA5xUFe2e0qLz8zoCqwkHAe+oMJBkjZvHhaWWQw7FVQDp2rL7oRgYvkISgYJAnnNB/fnEwAcGUmIM/C6hOSX5L/jfmbPw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003097; c=relaxed/simple; bh=rKqKx2xzj55JuQB/eV+Awt0kJSYANwr5bj8CjGzxCrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lDiwoNUHZItmoyXY+3BvBQ4cT8tRQlgJnYvWq6GKrtNUkVJbio564tNOTPgz0459bKErKesFN2CUjMwYgZZrBY+pW9AY1Pmx+kqWJNW9xPh57fM5IwbUVv0x+Dl2CFtvbxOFWErYyKyWiZDVjf8APXU6B9+/2JKUBG06ew9IatY= 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=ZHUuyG0w; 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=1706003094; 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=3EoIsZMzaud9t26sivTeCHJdwdosgvCL2VSONhiwz3c=; b=ZHUuyG0woi3ZmVxl6pijE5GKRGMPSlPTwaX+iaJtfM76UhVR2H9VwJ81XHZK8fLhCh92/g 4AEHvusqwFwyzul68/CXoer0VaNRrAGowa8cgOlLl1s3cTkaEhgbOue0yKNcjpSFpObv2h ujrrr+HYLSzeEnLUtAB9T29Sn74BXyc= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-p0ENHYEcM02UUw2Rx8KQzQ-1; Tue, 23 Jan 2024 04:44:52 -0500 X-MC-Unique: p0ENHYEcM02UUw2Rx8KQzQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7831a20711dso100520785a.0 for ; Tue, 23 Jan 2024 01:44:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706003092; x=1706607892; 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=3EoIsZMzaud9t26sivTeCHJdwdosgvCL2VSONhiwz3c=; b=eZYUf09VBUcmC+lI38A72wUrBff1yylLhRNwaXljwDVXHY2UUtuwwzSsh2d+3OhbKS MuhwQ11U6OOO142apbptGk5FET+Zfws2RrogdAQu1PWDZ1If9o1o/5Q/CYxtRm7Krnrf lIPh/NygOmI6+4om/d3uKUSrZ6lKsfG/We/aB7symcb05+adS8HZ8MHzvtSLbdWESxB2 KakQPRGlomHLGtJ00JUWNUpv77FYuVdHeWDUmNRuHkoiZ8eFJNPTVADo4MOGrcPflHJo +AXBDVRpqNn5Qtdxz97m52bjBgeuzlfYw5CtkXxvvbMXFwkI1sruGMGo9WmSIMeZcFKT wgBA== X-Gm-Message-State: AOJu0Ywx+EayO9LIHaxMVHVEvH/FoH0dkEc9KhR93GCPmfwuZ2RpfmcH oKgcTkWh3Oo2HJMyKzZamSyC1xWV0XTTLSUm6HN3HoJP3ICmkElMmyzv05nDurEplXa3McSfHKX nuNiUXCqrsB1Cwretpa9Rj7LOVdnC5sznCExiRiMq3ttR/UM0j9TpX1WfMRxDOA== X-Received: by 2002:a05:6214:c6e:b0:686:90f0:2a33 with SMTP id t14-20020a0562140c6e00b0068690f02a33mr5644872qvj.5.1706003091671; Tue, 23 Jan 2024 01:44:51 -0800 (PST) X-Received: by 2002:a05:6214:c6e:b0:686:90f0:2a33 with SMTP id t14-20020a0562140c6e00b0068690f02a33mr5644861qvj.5.1706003091343; Tue, 23 Jan 2024 01:44:51 -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 nc5-20020a0562142dc500b00685e2ffcaf5sm2958704qvb.38.2024.01.23.01.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:44:51 -0800 (PST) From: Philipp Stanner To: Jonathan Corbet , Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Philipp Stanner , Sam Ravnborg , 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 v2 03/10] PCI: warn users about complicated devres nature Date: Tue, 23 Jan 2024 10:43:00 +0100 Message-ID: <20240123094317.15958-4-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123094317.15958-1-pstanner@redhat.com> References: <20240123094317.15958-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 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 b7faf22ec8f5..0b7fcc2f7a49 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 2899df77a285..7ca860acf351 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3907,6 +3907,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 @@ -3918,6 +3920,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) @@ -3966,6 +3975,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 @@ -3973,6 +3984,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) { @@ -3998,6 +4015,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) { @@ -4023,6 +4047,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) @@ -4031,6 +4063,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) { @@ -4048,7 +4094,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); @@ -4080,6 +4125,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. @@ -4089,6 +4136,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) { @@ -4420,6 +4473,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.43.0