]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
PCI/P2PDMA: Collect acs list in stack buffer to avoid sleeping
authorLogan Gunthorpe <logang@deltatee.com>
Thu, 10 Jun 2021 16:06:05 +0000 (10:06 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 10 Jun 2021 23:01:41 +0000 (18:01 -0500)
In order to call the calc_map_type_and_dist_warn() function from a dma_map
operation, the function must not sleep. The only reason it sleeps is to
allocate memory for the seq_buf to print a verbose warning telling the user
how to disable ACS for that path.

Instead of allocating the memory with kmalloc(), allocate a smaller buffer
on the stack. A 128 byte buffer is enough to print 10 PCI device names. A
system with 10 bridge ports between two devices that have ACS enabled would
be unusually large, so this should still be a reasonable limit.

This also cleans up the awkward (and broken) return with -ENOMEM which
contradicts the return type and the caller was not prepared for.

Link: https://lore.kernel.org/r/20210610160609.28447-3-logang@deltatee.com
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/p2pdma.c

index a860137fac89282b50b6959b1f4be78d8f5f7224..109bd73219629668a29aed9b3896589c2e2147ff 100644 (file)
@@ -502,11 +502,10 @@ calc_map_type_and_dist_warn(struct pci_dev *provider, struct pci_dev *client,
 {
        struct seq_buf acs_list;
        bool acs_redirects;
+       char buf[128];
        int ret;
 
-       seq_buf_init(&acs_list, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
-       if (!acs_list.buffer)
-               return -ENOMEM;
+       seq_buf_init(&acs_list, buf, sizeof(buf));
 
        ret = calc_map_type_and_dist(provider, client, dist, &acs_redirects,
                                     &acs_list);
@@ -524,8 +523,6 @@ calc_map_type_and_dist_warn(struct pci_dev *provider, struct pci_dev *client,
                         pci_name(provider));
        }
 
-       kfree(acs_list.buffer);
-
        return ret;
 }