{"id":2225880,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225880/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260421174351.3897842-1-mattev@meta.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.1/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260421174351.3897842-1-mattev@meta.com>","date":"2026-04-21T17:43:51","name":"PCI/P2PDMA: Avoid returning a provider for non_mappable_bars","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1d13832a454badc6e0ce95e6f80f5ef8bc263f49","submitter":{"id":93208,"url":"http://patchwork.ozlabs.org/api/1.1/people/93208/?format=json","name":"Matt Evans","email":"mattev@meta.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260421174351.3897842-1-mattev@meta.com/mbox/","series":[{"id":500863,"url":"http://patchwork.ozlabs.org/api/1.1/series/500863/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=500863","date":"2026-04-21T17:43:51","name":"PCI/P2PDMA: Avoid returning a provider for non_mappable_bars","version":1,"mbox":"http://patchwork.ozlabs.org/series/500863/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225880/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225880/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pci+bounces-52866-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=meta.com header.i=@meta.com header.a=rsa-sha256\n header.s=s2048-2025-q2 header.b=QzNZFg6m;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-pci+bounces-52866-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com\n header.b=\"QzNZFg6m\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=67.231.153.30","smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=meta.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=meta.com"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0VFx1Cvqz1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 03:48:37 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id D6EBE3013FD8\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 17:48:34 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 65AE42D97B8;\n\tTue, 21 Apr 2026 17:48:33 +0000 (UTC)","from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com\n [67.231.153.30])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 09F6529CB24;\n\tTue, 21 Apr 2026 17:48:31 +0000 (UTC)","from pps.filterd (m0089730.ppops.net [127.0.0.1])\n\tby m0089730.ppops.net (8.18.1.11/8.18.1.11) with ESMTP id 63LH0rGJ2930348;\n\tTue, 21 Apr 2026 10:44:07 -0700","from mail.thefacebook.com ([163.114.134.16])\n\tby m0089730.ppops.net (PPS) with ESMTPS id 4dm5emj275-2\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT);\n\tTue, 21 Apr 2026 10:44:07 -0700 (PDT)","from localhost (2620:10d:c085:108::4) by mail.thefacebook.com\n (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 21 Apr\n 2026 17:44:05 +0000"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776793713; cv=none;\n b=IsN8MxERE8i+EjLc9knJ2s+M9tMukTilFb20D7/dFWt3aeJpL1lFu0xSPLFJuVaXZMHebSnpl5nWkciG2jLYW1uudgDdC7PVv2R/xJt2A7sg0lSoU5KcIj/qs0JpnmvD6txifljcGnWxWZJrVg67eTqG2tqZsw6EMaH9C/nRL1g=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776793713; c=relaxed/simple;\n\tbh=K23oW1r0/klN0f5vv2ruCFnMybzehjjymAzKaQCwHyI=;\n\th=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type;\n b=DR8hIQcJLKq+48+L4hyy9yiD7pNKqL5vRzG3+l51wu2te9tTOKuEydpD8uF2MtyaGIog0Q+sVBP4HNx+JE4jrojtnaYF2xkBt7CbAIZn8fPusGaMlJOWk1scDa11Yfr/YBYHK+9acdZ1sEQX3JPRcLQJZHcuEkZ3yXHkFQmznKE=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=meta.com;\n spf=pass smtp.mailfrom=meta.com;\n dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com\n header.b=QzNZFg6m; arc=none smtp.client-ip=67.231.153.30","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc\n\t:content-transfer-encoding:content-type:date:from:message-id\n\t:mime-version:subject:to; s=s2048-2025-q2; bh=97lJG01Ra6fETyE1mK\n\tK3yMzNQjXRpBT+P6Tyhf4twEE=; b=QzNZFg6mi6ILZBM7EqaGfNdqtn2ERpM1BH\n\tkECR9cYnM90vhQXLSwkE7ga+gOQP5qxJ5otVTq5jCoxYbCnoEswJJTaQEu7Ci6dQ\n\tDcdbJVPBNC2rxszvc0v74Ua88UMGzz6rF3iaLWJuuD/oF1aN+HfHeeCSErgOA/2L\n\t2M5gbENJcGgd6O8j/dJGYj0P96oqViniigj3Zca7yVhqjKZ1MOCftPco4GKRRmKx\n\tyL8JYUOWlA5rEkJhTbW3VE7rZ0Oo54WOmNhXX8OX3hnthTcmeIQM+vVO/MdBRL4Y\n\t7XYeoCJJgOoB+03bA9oNFpGCHD6Ky/eaBmCqLQIlMMl1AN7A9o0A==","From":"Matt Evans <mattev@meta.com>","To":"Bjorn Helgaas <bhelgaas@google.com>,\n        Logan Gunthorpe\n\t<logang@deltatee.com>,\n        Ankit Agrawal <ankita@nvidia.com>, Leon Romanovsky\n\t<leon@kernel.org>,\n        Alex Williamson <alex@shazbot.org>,\n        Niklas Schnelle\n\t<schnelle@linux.ibm.com>","CC":"<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>","Subject":"[PATCH] PCI/P2PDMA: Avoid returning a provider for non_mappable_bars","Date":"Tue, 21 Apr 2026 10:43:51 -0700","Message-ID":"<20260421174351.3897842-1-mattev@meta.com>","X-Mailer":"git-send-email 2.52.0","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain","X-Authority-Analysis":"v=2.4 cv=fcOdDUQF c=1 sm=1 tr=0 ts=69e7b767 cx=c_pps\n a=CB4LiSf2rd0gKozIdrpkBw==:117 a=CB4LiSf2rd0gKozIdrpkBw==:17\n a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22\n a=855S8uPTkML1Oy45N9_h:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8\n a=LxoKb0BkxeglHS5Ch2kA:9 a=gKebqoRLp9LExxC7YDUY:22","X-Proofpoint-GUID":"XHgDKY2zrfFiT5hrQpmjCjKg1w4BMaTc","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDIxMDE3NiBTYWx0ZWRfX7AcGpgQDDK2c\n 7m6OCbGHRL+4WfRekvAGK8k1Zr+flhGDrXAstQhVV9PRjGp51CkxRd7n9QtGqhTCasE60/ZPOig\n qOV+6KK43MUsGYaHRH30tGNKf2+bBKxMe8KMotBhv4ZHW0UIVYBESC+D8J81e5aLHTNY8zJdVBD\n KCfWcu4CY/MdHa3nou08CO/uJOhevFc1lYfnnzdKc6Jf1haqX4rnT106Q6F/rpCapLxgnky7721\n CgXUDE3VRkQDi0zYs7bO62xVnDSWzCfLiWHU7o0uBApQMrtGOfXjFhYsZ7KuZ5hoyFzyFCLLoce\n nvSC+ERyu1jya5dT4/jsMJrYUoeETcbHZKuq1R/LjC8igsY/dMODahqLw6oYkLUcnmxDnVLnzzX\n uc9VhpRy76Ufrm/mjHQXlYem8p2dev16vBodmeYBUXdAbh/AMVSKDuiInYQ8wrDcIU3DKnzOy0l\n 2NG1Mt3CPRBxa9qzQpg==","X-Proofpoint-ORIG-GUID":"XHgDKY2zrfFiT5hrQpmjCjKg1w4BMaTc","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-21_03,2026-04-21_02,2025-10-01_01"},"content":"Extend pcim_p2pdma_provider()'s checks to exclude functions that have\npdev->non_mappable_bars set.\n\nConsumers such as VFIO were previously able to map these for access by\nthe CPU or P2P.  Update the comment on non_mappable_bars to show it\nrefers to any access, not just userspace CPU access.\n\nFixes: 372d6d1b8ae3c (\"PCI/P2PDMA: Refactor to separate core P2P functionality from memory allocation\")\nSigned-off-by: Matt Evans <mattev@meta.com>\n---\n\nThis arises from Alex Williamson's suggestion to test\nnon_mappable_bars when getting the provider, with discussion here:\n\n https://lore.kernel.org/kvm/20260415181623.1021090-1-mattev@meta.com/\n\nThe goal was to prevent a hole where VFIO could export DMABUFs for\nBARs marked non-mappable, and to fix for all users of the provider\nrather than just VFIO.  Alex observed that non_mappable_bars should be\ntaken to mean BARs weren't usable by the CPU _or_ peers and,\nconsidering that, its comment about userspace access wasn't quite\nright.\n\n\n drivers/pci/p2pdma.c | 3 ++-\n include/linux/pci.h  | 2 +-\n 2 files changed, 3 insertions(+), 2 deletions(-)","diff":"diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c\nindex 7c898542af8d..4a783413f466 100644\n--- a/drivers/pci/p2pdma.c\n+++ b/drivers/pci/p2pdma.c\n@@ -318,7 +318,8 @@ struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar)\n {\n \tstruct pci_p2pdma *p2p;\n \n-\tif (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))\n+\tif (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM) ||\n+\t    pdev->non_mappable_bars)\n \t\treturn NULL;\n \n \tp2p = rcu_dereference_protected(pdev->p2pdma, 1);\ndiff --git a/include/linux/pci.h b/include/linux/pci.h\nindex 2c4454583c11..1e6802017d6b 100644\n--- a/include/linux/pci.h\n+++ b/include/linux/pci.h\n@@ -508,7 +508,7 @@ struct pci_dev {\n \tunsigned int\tno_command_memory:1;\t/* No PCI_COMMAND_MEMORY */\n \tunsigned int\trom_bar_overlap:1;\t/* ROM BAR disable broken */\n \tunsigned int\trom_attr_enabled:1;\t/* Display of ROM attribute enabled? */\n-\tunsigned int\tnon_mappable_bars:1;\t/* BARs can't be mapped to user-space  */\n+\tunsigned int\tnon_mappable_bars:1;\t/* BARs can't be mapped by CPU or peers */\n \tpci_dev_flags_t dev_flags;\n \tatomic_t\tenable_cnt;\t/* pci_enable_device has been called */\n \n","prefixes":[]}