PCI/P2PDMA: Collect acs list in stack buffer to avoid sleeping

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>
This commit is contained in:
Logan Gunthorpe 2021-06-10 10:06:05 -06:00 committed by Bjorn Helgaas
parent 6389d43745
commit e4ece59abd

View 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;
}