Patch "PCI: Restore original INTX_DISABLE bit by pcim_intx()" has been added to the 6.13-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    PCI: Restore original INTX_DISABLE bit by pcim_intx()

to the 6.13-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     pci-restore-original-intx_disable-bit-by-pcim_intx.patch
and it can be found in the queue-6.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit a2b38b54acdf05db9ad39f475292ffc647632b0e
Author: Takashi Iwai <tiwai@xxxxxxx>
Date:   Thu Oct 31 14:42:56 2024 +0100

    PCI: Restore original INTX_DISABLE bit by pcim_intx()
    
    [ Upstream commit d555ed45a5a10a813528c7685f432369d536ae3d ]
    
    pcim_intx() tries to restore the INTx bit at removal via devres, but there
    is a chance that it restores a wrong value.
    
    Because the value to be restored is blindly assumed to be the negative of
    the enable argument, when a driver calls pcim_intx() unnecessarily for the
    already enabled state, it'll restore to the disabled state in turn.  That
    is, the function assumes the case like:
    
      // INTx == 1
      pcim_intx(pdev, 0); // old INTx value assumed to be 1 -> correct
    
    but it might be like the following, too:
    
      // INTx == 0
      pcim_intx(pdev, 0); // old INTx value assumed to be 1 -> wrong
    
    Also, when a driver calls pcim_intx() multiple times with different enable
    argument values, the last one will win no matter what value it is.  This
    can lead to inconsistency, e.g.
    
      // INTx == 1
      pcim_intx(pdev, 0); // OK
      ...
      pcim_intx(pdev, 1); // now old INTx wrongly assumed to be 0
    
    This patch addresses those inconsistencies by saving the original INTx
    state at the first pcim_intx() call.  For that, get_or_create_intx_devres()
    is folded into pcim_intx() caller side; it allows us to simply check the
    already allocated devres and record the original INTx along with the
    devres_alloc() call.
    
    Link: https://lore.kernel.org/r/20241031134300.10296-1-tiwai@xxxxxxx
    Fixes: 25216afc9db5 ("PCI: Add managed pcim_intx()")
    Link: https://lore.kernel.org/87v7xk2ps5.wl-tiwai@xxxxxxx
    Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
    Signed-off-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
    Reviewed-by: Philipp Stanner <pstanner@xxxxxxxxxx>
    Cc: stable@xxxxxxxxxxxxxxx      # v6.11+
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index cc31951347210..1adebcb263bd0 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -419,19 +419,12 @@ static void pcim_intx_restore(struct device *dev, void *data)
 	pci_intx(pdev, res->orig_intx);
 }
 
-static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
+static void save_orig_intx(struct pci_dev *pdev, struct pcim_intx_devres *res)
 {
-	struct pcim_intx_devres *res;
-
-	res = devres_find(dev, pcim_intx_restore, NULL, NULL);
-	if (res)
-		return res;
+	u16 pci_command;
 
-	res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
-	if (res)
-		devres_add(dev, res);
-
-	return res;
+	pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
+	res->orig_intx = !(pci_command & PCI_COMMAND_INTX_DISABLE);
 }
 
 /**
@@ -447,12 +440,23 @@ static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
 int pcim_intx(struct pci_dev *pdev, int enable)
 {
 	struct pcim_intx_devres *res;
+	struct device *dev = &pdev->dev;
 
-	res = get_or_create_intx_devres(&pdev->dev);
-	if (!res)
-		return -ENOMEM;
+	/*
+	 * pcim_intx() must only restore the INTx value that existed before the
+	 * driver was loaded, i.e., before it called pcim_intx() for the
+	 * first time.
+	 */
+	res = devres_find(dev, pcim_intx_restore, NULL, NULL);
+	if (!res) {
+		res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL);
+		if (!res)
+			return -ENOMEM;
+
+		save_orig_intx(pdev, res);
+		devres_add(dev, res);
+	}
 
-	res->orig_intx = !enable;
 	pci_intx(pdev, enable);
 
 	return 0;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux