From patchwork Fri Mar 1 11:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 208804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1013420dyb; Fri, 1 Mar 2024 03:33:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVSAaVUBkUpIpOILj6/XmZlYoBhV+unlfRSbv9LlXv+R+f/yPizxBapyp4eXdbj/g4ifDquWLKBB0S+EZ4RoDnDv+seoQ== X-Google-Smtp-Source: AGHT+IGbjkKRqrHB/BFmuNVeE7n7B/PzwXxmHwYTzrfb0G7YDAcPCoI3Sm0gyVRgcuUoSBZ6vhR6 X-Received: by 2002:a17:902:d2d2:b0:1db:f6b0:92d with SMTP id n18-20020a170902d2d200b001dbf6b0092dmr1655322plc.6.1709292838308; Fri, 01 Mar 2024 03:33:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292838; cv=pass; d=google.com; s=arc-20160816; b=UWhQQOPyo5rSQ4jZ+Us6Eyjthoe0ot2pPjjceqXbh2ympFRW0oeOjUqIcrQb5btI4I dOYnjuZR0LhwxAd6yftAwrX5JnhTR3mksCvajs41qIChwOFQGrf/Xrzjkq2zNL/UGVCB 9jbPAeyGbi6h5r2EJ8NOQTxxvThwjc5cma2gWVt/2YsDGgo5nSK4lb4SwguGifCTFoda f5pcZ3CmJ802sLMqZwIDRVfS8MxI/DnK46zAGu3LagYIkr7AZzkDYdHj2yNjBkFoCv01 myoJSXLFxL59AglhjOuObaLf8JOQ14bqodTbfiQIFlOtPctgrrFJw/+LcZvOag/TWuD+ 2jMg== 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=x1vv8w5iQVUitgG0ysLWn1q06xCEf1/TkXPRyfO6KrE=; fh=BNXHJYv768d1XQMiFv/J6bafj6croq6+BTjiwCFYBQk=; b=nicEr3fPobV26tMFiHJMMxS3PtxRvRn4xTc82/mtLy74FpXNRS+oqLs64lVLFuSkJS a/1CjKYz1Aizt9XwWngA0Z4p74Y0y6WzcEoHua5xFHamr/PIwP+3BGNlidbdxnuXx3kS Pv3XROEEO6f9B9vF8T5lraWKEVqgjtLNE2lDTQGO6soVymsVxIeFZjmIsoKpnhuulsxC LmLbbB8o76mfHC9AirqmiHtoIktiYt3SLLSt1PUhxrUIKRFDH1RMMKh9YmHftrKne5O4 b4TwV3sBcTUZQXiUXLbep/8JqDim6+GUyTsmbIGwlThytHCow941jtKFVyLByBJ+Asfi sfpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d7LeEQPE; 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-88348-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88348-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c1-20020a170903234100b001dc652e9d71si3431867plh.206.2024.03.01.03.33.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88348-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d7LeEQPE; 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-88348-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88348-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 818FCB24D05 for ; Fri, 1 Mar 2024 11:32:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94FD66F085; Fri, 1 Mar 2024 11:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d7LeEQPE" 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 245FB6E2B3 for ; Fri, 1 Mar 2024 11:30:24 +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=1709292625; cv=none; b=PhtsGx3kYfijBpMchEz6Ehopr+kWcZ/HTPu/oBVkhJar0NDGOnv03dRgE09WmrNuMkBnLHtyybIUMyy53eTCT+ptGscLnG0dVDdbXpIpPXPuDR0nGrbnJ2ZFlkRp18KEKV8KcbXIfdVR0rj6haRREUW8/EbTuGiTWxSrl2AcXa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292625; c=relaxed/simple; bh=/AwlCpVAO2oHu0uUrBvoYcwSq48osNascDYif54npNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQprADlOBbYNCGPvEjXGz3ixhuFbX0f5SP+5ExVTzQwHE3a1wkwM7OIkW80sKB3vGcpkI0rbHsUFu4/X6SJ4kZ4QbwzX047bczOl9hjQWjKFQDDGSgguKS8C5VmFX7NaGMFVIBDr5qjdKCn1uhXIvbkhGivQDVzJshjfzs4veng= 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=d7LeEQPE; 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=1709292623; 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=x1vv8w5iQVUitgG0ysLWn1q06xCEf1/TkXPRyfO6KrE=; b=d7LeEQPENpPsI7mo609neFScX83J074D4aE42WjRJgbQtpTrr71J7WrX+He9VbXJpixJa2 rEUVWi0Fq+Ze6YBIGAAuudWC5e/851Jp+l/8bVQBdBVlG1JDPrKgghaoPFdPieFM8IcjwO vKGO9B6YEqXIGMztC3wNlQ4iCZjOQqg= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-puWEIfgnMsa8g3qqI_DHvw-1; Fri, 01 Mar 2024 06:30:22 -0500 X-MC-Unique: puWEIfgnMsa8g3qqI_DHvw-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6dde25ac92fso993590a34.0 for ; Fri, 01 Mar 2024 03:30:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709292621; x=1709897421; 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=x1vv8w5iQVUitgG0ysLWn1q06xCEf1/TkXPRyfO6KrE=; b=scLvjKbU6a2zverrwH0sTDTqdVD5tBmINaNxLqx/Vxqi1hSup8GyjjjACyeUr9dbSQ K3I9+0oTx2axLHsICKEHJ5fEuFl0ymmGtovZ9Mf3jfjG/OryuZQ1DzzM2YRxmFWt/VU3 VIsJQoxe71AR6RDA8zJnFcDXrSZemKLYXDPgXoKXRoip0yP83RDvi7whdcAWnuQvsuTq Maq5j9b1D6XuLIuolpaXPOfxgWPoTD/H2ZRgd8emUPHvHz1swiSZ/hbXV5GpaWSCNXTk Tj+WcKg3aSvr0bapaLSExfIFcWpC9NsmUZ72xOAsDO8fARsasmi5h9awO0yGeU9OB0Zm dSTg== X-Forwarded-Encrypted: i=1; AJvYcCWDVq3I0+wmOrHkbJ4ls6GOIN37Nxc3HYPDjOzIsuJc3/BodjlU3XYuVLS9otJcpuz+uKamI5TOu40vWgfrdznIWT30yZxaDeg+XLpT X-Gm-Message-State: AOJu0YzDDftJygCNZ6DnLhmyaN5mJBq9oLCYmPMzQMhqFhI0IVrdutg8 CntY2CZEjcBfJSW4IxfnjG+RUhguubi15kjTwyf8OCixxOw43vxc7UwIYb3dkYs6sQWwLSYhVvx ZC46wjk9Wqy88JI5DhpJK9eBKb6t40UwqJUFf+D5jF4fsdLddUt8HSCBQaz0O2w== X-Received: by 2002:a05:6870:1b89:b0:21e:be91:ae48 with SMTP id hm9-20020a0568701b8900b0021ebe91ae48mr1405857oab.1.1709292616340; Fri, 01 Mar 2024 03:30:16 -0800 (PST) X-Received: by 2002:a05:6870:1b89:b0:21e:be91:ae48 with SMTP id hm9-20020a0568701b8900b0021ebe91ae48mr1405843oab.1.1709292616009; Fri, 01 Mar 2024 03:30:16 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id b1-20020ac86781000000b0042eb46d15bbsm1596239qtp.88.2024.03.01.03.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:30:15 -0800 (PST) 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 v4 03/10] PCI: Warn users about complicated devres nature Date: Fri, 1 Mar 2024 12:29:51 +0100 Message-ID: <20240301112959.21947-4-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240301112959.21947-1-pstanner@redhat.com> References: <20240301112959.21947-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792323447171833034 X-GMAIL-MSGID: 1792323447171833034 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 e01e316de1c3..26179611587b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3887,6 +3887,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 @@ -3898,6 +3900,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) @@ -3946,6 +3955,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 @@ -3953,6 +3964,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) { @@ -3978,6 +3995,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) { @@ -4003,6 +4027,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) @@ -4011,6 +4043,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) { @@ -4028,7 +4074,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); @@ -4060,6 +4105,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. @@ -4069,6 +4116,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) { @@ -4400,6 +4453,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) {