Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp253597lqp; Mon, 10 Jun 2024 03:05:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzHTiC+94aHNHBr9nrzfShkJmauUjgBL7bZ2Zz7VVDB52SG8rCivguW/x1HzoRaOhLsvWeCF0vCCFCM7RABQdAK4dsM40C/6DWsnfUKw== X-Google-Smtp-Source: AGHT+IGibZ0UsoNrkcN6avQQSLMyDrPpFJpGWK45cORBLToSgOmXg7Fjd/tQpjPF4wHX6EN7fvcc X-Received: by 2002:a17:902:f551:b0:1f2:fcc0:66f with SMTP id d9443c01a7336-1f6d01bbdc4mr111274645ad.31.1718013918572; Mon, 10 Jun 2024 03:05:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718013918; cv=pass; d=google.com; s=arc-20160816; b=F2MSg6NixQlyfeHdEJ1gQUDS+Xg5ipj+2KIsAdLOih4/Gz97ohti1w9xOSmiLdek5e KU8DSKOlC1upGIRhE1n6TK/bNP4YqBT7boHjHDjQJD67czgcZRiZRZwD/7Xv/mf6uyL8 KY/wKXHZ4tsbHfOXnO2U7q6mNSaTctwFeamBBnxNAFiUaM8uxqq+UFWMXw84uHnk7vA+ BZr4aOdlkxVJbad+0L20hWQAN6XRQY7IaM+QhovrYUSEecqYHKjUziZlASY5xBWFUlC+ 9f0xijrvpm8cPIoatlIo54oVOXTzZEvxBdotHhY11eik/dM1o5QLHDoQjoSHt0Zn/Hf5 otAw== 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=j9dFlyi1HoB9hw7OSY8YroyFypFphGOIBSX/wCz7lA0=; fh=o+wCs8SITfpcG7lVwTmr3l/LlVjbVhorbyIhJEDSBIY=; b=yw6Qn27U6dJ5jEK9CaSZHN7KAsS8wXsbQniZsvywGddHxLM/4StFH/VS2T0D8inkd0 b0W+AtvJ3KKpy0NEPd21uf+DRZPne+I10mgT1/T9v9mpse/5EVbPbmN53cyaC4x6YI4x nSTIRrlSo0KhL42e2EhyMRKB8z0Q4RU3bXmcbLFo3swvYZk6zfQBF69J+nVHyTIQ6gYE 1rHHBgjmZNUZKB+JiYNYeMKnfnh0uhO7t7Nsz+KRJFKvRhqYoXdTnEOJkvkUm9UPjywA OgXXg7fu60/QYzo9j+ED/3qH+Mqd1RR53jyfonfZOpK2f103pE4zKMxPCwr80naIAKsb kkuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e4EnQE0V; 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-207947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207947-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd75f9a4si38597475ad.51.2024.06.10.03.05.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 03:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207947-linux.lists.archive=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=e4EnQE0V; 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-207947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207947-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 524DBB25AE0 for ; Mon, 10 Jun 2024 09:33:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 438F47E58F; Mon, 10 Jun 2024 09:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e4EnQE0V" 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 2A7BC78C8B for ; Mon, 10 Jun 2024 09:32:13 +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=1718011934; cv=none; b=VKJRwLnT2NS5QO+w/gs+0dSLx10eHHxltM6ZHfNj+uu/WliFque218bCQ2KDTCY23XWz1gQiW36cK4gZJGPmEHe3qhVOO5nI/wp9a4wWbXX17ESN5Arq/ofivEH6I86E2KojyyZ/L5i0E70/AvgoF9cZP4NzOkbUOR3gG1k8Qgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718011934; c=relaxed/simple; bh=yZ5BKFpZwAyKkfsZmuzlsekm8L8yl3Htpr+3BjCRxJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SB8Xzpx+XD+VycDyauP/RAdrGMTDHKS/G/vgaYx1PilFSu4wYR0847HgP7WXx4id/3uwLZDYTvjvbDOzxoI4I8qe3rrybAeUkjqs8CFZzxhNEWPhzCLgTRMBtJnJtsLSAnHMps5L02Zw++XmOenLFj/0nDOWDDw1DlbNzt6btn4= 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=e4EnQE0V; 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=1718011932; 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=j9dFlyi1HoB9hw7OSY8YroyFypFphGOIBSX/wCz7lA0=; b=e4EnQE0V4bGIqeDkt4JCPzHV78J5STRBSe9mJ/5H+OWZJOKE2M5FTZzOs4kjejx+aGDqtE eAYoF4NOUK0rKXU+VPBUqGCWERntgAbuiwaGb4BxlPaOusLQjV2UQ5TmMSvZKEHWo6MTdL lTfe0/jHVrubtvHPEoiSOViasys17bI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-jcCLZEFjOGSzQlb4PF7fgA-1; Mon, 10 Jun 2024 05:32:07 -0400 X-MC-Unique: jcCLZEFjOGSzQlb4PF7fgA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-421920de031so1512105e9.0 for ; Mon, 10 Jun 2024 02:32:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718011926; x=1718616726; 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=j9dFlyi1HoB9hw7OSY8YroyFypFphGOIBSX/wCz7lA0=; b=vqFOE8gdnUExJtX6VK7zAZKSumC5/sGGM05LcgNdvl4No470wmJfCDk9hQQ0S0Lzap Ru4zj4NFKMw0oA7IxNZkRanamf7u1oiyooBMNtrefjRpVWc4SzkaDfkfnu2wMt+31YXi LgjiyWpIhjo3DS/+g+sWmArvDB7/zqMf6W3eYwjq7pNFObT4XzuHHcRljct4ZdYltOmc UONy9tSxeU3RIrblIq55AnCDw7LULF3ubY4guU/zdB+W7T2PVdWsxrCSD2zdbarSOnYB qKDyO9lnxE0IPGYDXnG1YQgA6LlFb59yXW5NO5bW1Qit/v1rIEL/R4JVmkkz5KVgt9mF Ni6A== X-Forwarded-Encrypted: i=1; AJvYcCXdMZDJ0FlFcKZ7Bqm5ryGGsYIVr6BEkrA0y8qwdgm+e2mlwvQjysgQGPgqzJobs/h4IKeKgLO8+5GvaBR27ecjqVpN+RETpE3I0jDy X-Gm-Message-State: AOJu0Yx0GrnqUyzJgWQqDrNtTSpYyb13Q/dzG0D93ig6MFDE49J3djts vCzOA5gFzidnY2VM8tiSfJqoz3CTuZzFFJC8e2XBGDmo2eWEuR/tAD8v9j8ZZMyd3y42w7Mi7dR sKNovC4KmaDVTrt0r6xxauk1nacLp3Nuld5pq680BvK/Jsn8laMXdE0blu+/RDQ== X-Received: by 2002:a05:6000:1449:b0:35f:2584:770e with SMTP id ffacd0b85a97d-35f258478fdmr1253733f8f.0.1718011926172; Mon, 10 Jun 2024 02:32:06 -0700 (PDT) X-Received: by 2002:a05:6000:1449:b0:35f:2584:770e with SMTP id ffacd0b85a97d-35f258478fdmr1253715f8f.0.1718011925874; Mon, 10 Jun 2024 02:32:05 -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 ffacd0b85a97d-35f0ce4b62fsm7257545f8f.80.2024.06.10.02.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:32:05 -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 v8 06/13] PCI: Warn users about complicated devres nature Date: Mon, 10 Jun 2024 11:31:28 +0200 Message-ID: <20240610093149.20640-7-pstanner@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240610093149.20640-1-pstanner@redhat.com> References: <20240610093149.20640-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