| From ec01550542b437dd47cf51c03c119df269dc4708 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Sat, 20 Dec 2025 12:04:34 +0800 |
| Subject: PCI/P2PDMA: Release per-CPU pgmap ref when vm_insert_page() fails |
| |
| From: Hou Tao <houtao1@huawei.com> |
| |
| [ Upstream commit 6220694c52a5a04102b48109e4f24e958b559bd3 ] |
| |
| When vm_insert_page() fails in p2pmem_alloc_mmap(), p2pmem_alloc_mmap() |
| doesn't invoke percpu_ref_put() to free the per-CPU ref of pgmap acquired |
| after gen_pool_alloc_owner(), and memunmap_pages() will hang forever when |
| trying to remove the PCI device. |
| |
| Fix it by adding the missed percpu_ref_put(). |
| |
| Fixes: 7e9c7ef83d78 ("PCI/P2PDMA: Allow userspace VMA allocations through sysfs") |
| Signed-off-by: Hou Tao <houtao1@huawei.com> |
| Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> |
| Reviewed-by: Logan Gunthorpe <logang@deltatee.com> |
| Reviewed-by: Alistair Popple <apopple@nvidia.com> |
| Link: https://patch.msgid.link/20251220040446.274991-2-houtao@huaweicloud.com |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/pci/p2pdma.c | 1 + |
| 1 file changed, 1 insertion(+) |
| |
| diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c |
| index 4a2fc7ab42c34..218c1f5252b66 100644 |
| --- a/drivers/pci/p2pdma.c |
| +++ b/drivers/pci/p2pdma.c |
| @@ -152,6 +152,7 @@ static int p2pmem_alloc_mmap(struct file *filp, struct kobject *kobj, |
| ret = vm_insert_page(vma, vaddr, page); |
| if (ret) { |
| gen_pool_free(p2pdma->pool, (uintptr_t)kaddr, len); |
| + percpu_ref_put(ref); |
| return ret; |
| } |
| percpu_ref_get(ref); |
| -- |
| 2.51.0 |
| |