From mboxrd@z Thu Jan 1 00:00:00 1970 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 DB4C815383C for ; Tue, 9 Jul 2024 08:56:32 +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=1720515394; cv=none; b=qV81rlaKifsIgb1awq3qYznxEX+m0kcNqbkMaUjxJ0kbNRMBCvte0/03ljVMWLp2VuFT4XQtaNzB3ic9qPwRgC4lFQMUuMMhDJAC+FzAeh+BaboHLMW1Hqtr8xl3vREywLO0ZXyF3cU/iXBOaLcuNL+DvtVU286s1di6zBbhDaI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720515394; c=relaxed/simple; bh=ZjleyqreNzd5N6niM8JfYISv9RvH3ugjN68S6yfTxpM=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=CvWGNvMIMxFyVhYfEa1w6QRrdqjyf+ul/R2QC2u0hSuOb4clTKZoutY+kSrlkL8Fr8l39nUNFLGqqd0WYz+/1LB9d6aNOXL8N5pt3F3i3hO9/aW2MDjQk/GF88VfZu18xDJSfacN9mqYXD/GFTmQd8gsRuVlrqluRPaeQt0wISE= 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=A/8c7ZnS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A/8c7ZnS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720515391; 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=mZo3i4FrLDziFrzuVJBLT1zQ9UdyZZW5nDEeprPuspY=; b=A/8c7ZnSyClGgmVZO6pefIL+cDKIHqkgZEpykFISNPy2BeoRpNJ+usyevLuQQLa9shwujs rurpoCS3XOdzoyuRWSjiZ57UheV3y2+hKsm904roSZCI1whV2xRQx6e6FzqQfk5L12YAMV 0e1WM7OGeF91pKcLMp+BHh/gS43PIV8= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-Ss3VSe__NV63Gf7sz7i1qg-1; Tue, 09 Jul 2024 04:56:29 -0400 X-MC-Unique: Ss3VSe__NV63Gf7sz7i1qg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-52e9df289b4so744505e87.2 for ; Tue, 09 Jul 2024 01:56:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720515388; x=1721120188; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mZo3i4FrLDziFrzuVJBLT1zQ9UdyZZW5nDEeprPuspY=; b=i2uNBViwZG4PuwCOToOwN95n3dKviijq7uqq5JzoRncTk5uLQ/4pxzXafnCwi/FlNY 8C4upFdRSbT7Yedkk9RNxmlqYZTnwK8zXpJKubO6XjHAUfwLgschOmYMHaJBE6HxLLWp yM9eq86YCIRTvv0Rt9JTEw3+budl7ryTmo5mAyjs3Fb5U07OenNGrlaeGWlCmneWHUsk sV8iSy7VMhFvST5W4O5TZt3qhNL+vqgrcAScGPndSb8ET/5UnXHqQrMBDzn7EZbfiKTK mDQZidbyeylua4QHxbJC4jpFRwbQzdH/18FEd6QxbwwuM+H0la/3fYI3rNcadHpKWSkW /Q8w== X-Forwarded-Encrypted: i=1; AJvYcCVr5Qzh93Zt2vpEUobcmkWActmSeLTk0f1HASMsD7fJtMFxNVL0A1DcZEzGO511xxwXyu8TAJlX5pSW46anbQ/UTKWFg12BdPQr7a/b X-Gm-Message-State: AOJu0YwlG/eUq+oxOM2dqwo8EASWforXQn7G5N75w426SpWbJLLLGevi h7JAU0c9NR0p7H3NVt2EGv2bvcFFS2NyYrLvQSuWZ5ZjO3oFtdbiMhyk9bhRCD3Fug8STOj0yGe 67FnazwwcxAwWkPGtr/aUZgM0WE8fwHkeynjA+0VpTuHRMtZ9Bm+xON0v3xgT1w== X-Received: by 2002:a2e:a594:0:b0:2ec:4287:26ac with SMTP id 38308e7fff4ca-2eeb3191af2mr13488351fa.4.1720515388427; Tue, 09 Jul 2024 01:56:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJFO85FdSpN/tGtIniVZthBrr5afzWmwuyHHpTqaBS39B1vWHCFm7f/iojSiOOVOD1vzLidg== X-Received: by 2002:a2e:a594:0:b0:2ec:4287:26ac with SMTP id 38308e7fff4ca-2eeb3191af2mr13488161fa.4.1720515387987; Tue, 09 Jul 2024 01:56:27 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266f741624sm29991115e9.41.2024.07.09.01.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 01:56:27 -0700 (PDT) Message-ID: <426645d40776198e0fcc942f4a6cac4433c7a9aa.camel@redhat.com> Subject: Re: [PATCH v9 10/13] PCI: Give pci_intx() its own devres callback From: Philipp Stanner To: Ashish Kalra Cc: airlied@gmail.com, bhelgaas@google.com, dakr@redhat.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, hdegoede@redhat.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, sam@ravnborg.org, tzimmermann@suse.de, thomas.lendacky@amd.com, mario.limonciello@amd.com Date: Tue, 09 Jul 2024 10:56:26 +0200 In-Reply-To: <20240708214656.4721-1-Ashish.Kalra@amd.com> References: <20240613115032.29098-11-pstanner@redhat.com> <20240708214656.4721-1-Ashish.Kalra@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 >From c24bd5b66e798a341caf183fb7cdbdf235502d90 Mon Sep 17 00:00:00 2001 From: Philipp Stanner Date: Tue, 9 Jul 2024 09:45:48 +0200 Subject: [PATCH] PCI: Fix pcim_intx() recursive calls pci_intx() calls into pcim_intx() in managed mode, i.e., when pcim_enable_device() had been called. This recursive call causes a bug by re-registering the device resource in the release callback. This is the same phenomenon that made it necessary to implement some functionality a second time, see __pcim_request_region(). Implement __pcim_intx() to bypass the hybrid nature of pci_intx() on driver detach. Fixes: https://lore.kernel.org/all/20240708214656.4721-1-Ashish.Kalra@amd.c= om/ Reported-by: Ashish Kalra Signed-off-by: Philipp Stanner --- Hi Ashish, I hacked down this fix that should be applyable on top. Could you maybe have a first quick look whether this fixes the issue? --- drivers/pci/devres.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 2f0379a4e58f..dcef049b72fe 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -408,12 +408,31 @@ 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 occuring + * 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 - pci_intx(pdev, res->orig_intx); + __pcim_intx(pdev, res->orig_intx); } =20 static struct pcim_intx_devres *get_or_create_intx_devres(struct device *d= ev) @@ -443,7 +462,6 @@ static struct pcim_intx_devres *get_or_create_intx_devr= es(struct device *dev) */ int pcim_intx(struct pci_dev *pdev, int enable) { - u16 pci_command, new; struct pcim_intx_devres *res; =20 res =3D get_or_create_intx_devres(&pdev->dev); @@ -451,16 +469,7 @@ int pcim_intx(struct pci_dev *pdev, int enable) return -ENOMEM; =20 res->orig_intx =3D !enable; - - 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); + __pcim_intx(pdev, enable); =20 return 0; } --=20 2.45.0