From nobody Fri Nov 22 03:38:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729018351; cv=none; d=zohomail.com; s=zohoarc; b=fIqQa2THXxaQOSdaVmVshLzGhfR9WhjZj1JDQ9Yf3HL+dEH9rWAhbomCvhQTpSZ4BubjKOsFoMPxFp5oHBYLzOLZ3oAr+9fwSuAmcHtcmsmIXbFQpQK6P8sox/asIC4AH1lxXo7UZ6TrOO+8ZVLD/vsnPLYeciqr6CyqV8Azwfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729018351; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SU/PZdKXdnBqqSwxJC6QaxHUkhQ/Rh93i2Z0bgmQYHg=; b=V30BiBJgTj89mdQOdFPXh9v76JfhELHjQV7ZebH+hBJ2aO8dqSjmNSbbh2G5YhfcQELjl8tRz1U0Tb2K7q19OrYpWdbVJH9Fp68iwuAJww+csprye4LQrJlsVLiu2eXtSdei7pI4FHDD/krzrxTStVP19Pd9Su8VACwa2aZvOUE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1729018351483745.7743699949511; Tue, 15 Oct 2024 11:52:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.819318.1232613 (Exim 4.92) (envelope-from ) id 1t0me8-0006GM-JA; Tue, 15 Oct 2024 18:51:52 +0000 Received: by outflank-mailman (output) from mailman id 819318.1232613; Tue, 15 Oct 2024 18:51:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0me8-0006GF-Fr; Tue, 15 Oct 2024 18:51:52 +0000 Received: by outflank-mailman (input) for mailman id 819318; Tue, 15 Oct 2024 18:51:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0me8-0006G4-1O for xen-devel@lists.xenproject.org; Tue, 15 Oct 2024 18:51:52 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 87b3f433-8b26-11ef-a0be-8be0dac302b0; Tue, 15 Oct 2024 20:51:48 +0200 (CEST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-W4BbnW53NFSgTcugynJgoA-1; Tue, 15 Oct 2024 14:51:45 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a9a1b8d4563so63830766b.3 for ; Tue, 15 Oct 2024 11:51:45 -0700 (PDT) Received: from eisenberg.fritz.box (200116b82d5d5a0006e2615320d1d4db.dip.versatel-1u1.de. [2001:16b8:2d5d:5a00:6e2:6153:20d1:d4db]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c98d39a9a2sm974438a12.0.2024.10.15.11.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 11:51:42 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 87b3f433-8b26-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729018307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SU/PZdKXdnBqqSwxJC6QaxHUkhQ/Rh93i2Z0bgmQYHg=; b=Ejkq3oCeQzRplWK1Ber+4RfhZGByV6RiGnFDCSvpfXjLFY9pClZKGC52zyWsLdhvvB+s51 UHL1rnJZabAV7Pgveri2vCyOZkFysoN9r+n2GvI8cDIOPC6aI0Svd7pkwH1P/RA71e/uYW yZusZ581e2AesVmPmgLs1RwWx2grLUE= X-MC-Unique: W4BbnW53NFSgTcugynJgoA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729018304; x=1729623104; 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=SU/PZdKXdnBqqSwxJC6QaxHUkhQ/Rh93i2Z0bgmQYHg=; b=WMHhaNlRi6KX++9SC0pTxtrMWO/nayfpADdXmFCF6Li5ZESAhcZAVj3l07N7YKKW0I yu4qOaKCSu3cc3svWUPRm4iJJriq14Y5GYPCUaFaJRxcpaT5V2qjZivJge1TNN/TRRnf vkGAoZM/82TUQ49DAYho9u+kYfHVYWGIRkQPmh5n+3HHTsmBiygnmz4pPyRpg0RZATGz W4f0qieJn7g5LZg++q692VnZQTA3HP2x6O3ZjJjT4kKmhbE7rNNLfgT03lL5xVqiDokH ihn+3412fWR94bjGjaTfgGZfTHsdYBDtVV6yFUXpxe6t9pxs9+k406wmdM2xGMZRefgY Vu6w== X-Forwarded-Encrypted: i=1; AJvYcCWb8CTmH5B+60tAbf7n4q4h0rwa5yxrSFAocjm1x+ptX/xwkpu8/CGcT5umXvOEHjAnDjn7CpQO95Q=@lists.xenproject.org X-Gm-Message-State: AOJu0YxYBEXHoq13OxHpF/bj2IO2ddaHTgvkRl25S2/eDtjXVsAap0Rc N6tOqGY9u7UuRztLNi5T1ab2HTSmQMu+4be9WJ9MQNIZ+ztCBd4bvD5eaQW4ySgxlcmsB064hPF oxmAle1sF6DNPzBPofnCedy1nFohpDquxLSR0rSLpocKYCchMoJ4/nGRUfPlT4pO6 X-Received: by 2002:a05:6402:26d1:b0:5c5:da5e:68e with SMTP id 4fb4d7f45d1cf-5c95ac09876mr18284551a12.3.1729018303813; Tue, 15 Oct 2024 11:51:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZgBAdLrLu4wVCTKTVra2bi/zOy1A/yhu7xkqftgD6kovhQdMFl3ZjsIezqx0bvqyWUCvsqg== X-Received: by 2002:a05:6402:26d1:b0:5c5:da5e:68e with SMTP id 4fb4d7f45d1cf-5c95ac09876mr18284485a12.3.1729018303219; Tue, 15 Oct 2024 11:51:43 -0700 (PDT) From: Philipp Stanner To: Damien Le Moal , Niklas Cassel , Sergey Shtylyov , Basavaraj Natikar , Jiri Kosina , Benjamin Tissoires , Arnd Bergmann , Greg Kroah-Hartman , Alex Dubov , Sudarsana Kalluru , Manish Chopra , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rasesh Mody , GR-Linux-NIC-Dev@marvell.com, Igor Mitsyanko , Sergey Matyukevich , Kalle Valo , Sanjay R Mehta , Shyam Sundar S K , Jon Mason , Dave Jiang , Allen Hubbe , Bjorn Helgaas , Alex Williamson , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Jaroslav Kysela , Takashi Iwai , Chen Ni , Mario Limonciello , Philipp Stanner , Ricky Wu , Al Viro , Breno Leitao , Kevin Tian , Thomas Gleixner , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , Mostafa Saleh , Jason Gunthorpe , Yi Liu , Christian Brauner , Ankit Agrawal , Eric Auger , Reinette Chatre , Ye Bin , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Pierre-Louis Bossart , Peter Ujfalusi , Maarten Lankhorst , Kai Vehmanen , Rui Salvaterra Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, ntb@lists.linux.dev, linux-pci@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-sound@vger.kernel.org Subject: [PATCH 01/13] PCI: Prepare removing devres from pci_intx() Date: Tue, 15 Oct 2024 20:51:11 +0200 Message-ID: <20241015185124.64726-2-pstanner@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241015185124.64726-1-pstanner@redhat.com> References: <20241015185124.64726-1-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729018353203116600 Content-Type: text/plain; charset="utf-8"; x-default="true" pci_intx() is a hybrid function which sometimes performs devres operations, depending on whether pcim_enable_device() has been used to enable the pci_dev. This sometimes-managed nature of the function is problematic. Notably, it causes the function to allocate under some circumstances which makes it unusable from interrupt context. To, ultimately, remove the hybrid nature from pci_intx(), it is first necessary to provide an always-managed and a never-managed version of that function. Then, all callers of pci_intx() can be ported to the version they need, depending whether they use pci_enable_device() or pcim_enable_device(). An always-managed function exists, namely pcim_intx(), for which __pcim_intx(), a never-managed version of pci_intx() had been implemented. Make __pcim_intx() a public function under the name pci_intx_unmanaged(). Make pcim_intx() a public function. Signed-off-by: Philipp Stanner Reviewed-by: Damien Le Moal --- drivers/pci/devres.c | 24 +++--------------------- drivers/pci/pci.c | 28 ++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index b133967faef8..d32827a1f2f4 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -411,31 +411,12 @@ static inline bool mask_contains_bar(int mask, int ba= r) return mask & BIT(bar); } =20 -/* - * This is a copy of pci_intx() used to bypass the problem of recursive - * function calls due to the hybrid nature of pci_intx(). - */ -static void __pcim_intx(struct pci_dev *pdev, int enable) -{ - u16 pci_command, new; - - pci_read_config_word(pdev, PCI_COMMAND, &pci_command); - - if (enable) - new =3D pci_command & ~PCI_COMMAND_INTX_DISABLE; - else - new =3D pci_command | PCI_COMMAND_INTX_DISABLE; - - if (new !=3D pci_command) - pci_write_config_word(pdev, PCI_COMMAND, new); -} - static void pcim_intx_restore(struct device *dev, void *data) { struct pci_dev *pdev =3D to_pci_dev(dev); struct pcim_intx_devres *res =3D data; =20 - __pcim_intx(pdev, res->orig_intx); + pci_intx_unmanaged(pdev, res->orig_intx); } =20 static struct pcim_intx_devres *get_or_create_intx_devres(struct device *d= ev) @@ -472,10 +453,11 @@ int pcim_intx(struct pci_dev *pdev, int enable) return -ENOMEM; =20 res->orig_intx =3D !enable; - __pcim_intx(pdev, enable); + pci_intx_unmanaged(pdev, enable); =20 return 0; } +EXPORT_SYMBOL_GPL(pcim_intx); =20 static void pcim_disable_device(void *pdev_raw) { diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7d85c04fbba2..d7fd0772a885 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4476,6 +4476,34 @@ void pci_disable_parity(struct pci_dev *dev) } } =20 +/** + * pci_intx - enables/disables PCI INTx for device dev, unmanaged version + * @pdev: the PCI device to operate on + * @enable: boolean: whether to enable or disable PCI INTx + * + * Enables/disables PCI INTx for device @pdev + * + * This function behavios identically to pci_intx(), but is never managed = with + * devres. + */ +void pci_intx_unmanaged(struct pci_dev *pdev, int enable) +{ + u16 pci_command, new; + + pci_read_config_word(pdev, PCI_COMMAND, &pci_command); + + if (enable) + new =3D pci_command & ~PCI_COMMAND_INTX_DISABLE; + else + new =3D pci_command | PCI_COMMAND_INTX_DISABLE; + + if (new =3D=3D pci_command) + return; + + pci_write_config_word(pdev, PCI_COMMAND, new); +} +EXPORT_SYMBOL_GPL(pci_intx_unmanaged); + /** * pci_intx - enables/disables PCI INTx for device dev * @pdev: the PCI device to operate on diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be6..6b8cde76d564 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1353,6 +1353,7 @@ int __must_check pcim_set_mwi(struct pci_dev *dev); int pci_try_set_mwi(struct pci_dev *dev); void pci_clear_mwi(struct pci_dev *dev); void pci_disable_parity(struct pci_dev *dev); +void pci_intx_unmanaged(struct pci_dev *pdev, int enable); void pci_intx(struct pci_dev *dev, int enable); bool pci_check_and_mask_intx(struct pci_dev *dev); bool pci_check_and_unmask_intx(struct pci_dev *dev); @@ -2293,6 +2294,7 @@ static inline void pci_fixup_device(enum pci_fixup_pa= ss pass, struct pci_dev *dev) { } #endif =20 +int pcim_intx(struct pci_dev *pdev, int enabled); void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxl= en); void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar, const char *name); --=20 2.47.0