From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FAE737BE89 for ; Thu, 23 Apr 2026 16:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776962825; cv=none; b=bSXG/RSb/T0gs1DYf4mWmZIAfjH+l+PtL/bkF+HBNKsnWxBOOxZ+hdavSx8vsa8Ve1YvGCKE938dIpPfK80/scuRUEuj0CQdskbQ/Bn+/9FlnyDCIHP1PA4dwtEFmcBZ2xUN5eydvu38rzmBFJYDNgiSgr0Q1wt7aDMSdVx/oAQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776962825; c=relaxed/simple; bh=h+lptLSrwl6lS/910QxA/O1c+TuP9Gbsrz1YCOfUQf4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rOZuzfzpG4xIl77oUanwHfOrSV66SN6sUnYeKQBca5eCRlRBwDHeOjse8kOtklRFdvULlfdCvlh2djuGlQbybnvV7Oue4Axp8lxcylHDFYuqXPXADGGTfdHb1lOrxmGffy8+aU3jsYvhk3RIgk3RL2kobHMdCZEtAyNAuvIcz18= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=ibVHogOP; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="ibVHogOP" Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63N3a5xo3996471 for ; Thu, 23 Apr 2026 09:47:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2025-q2; bh=oVfOeV72AOJgq9KjWrZRAnrxVldfcZIMHauJXVMpJ7k=; b=ibVHogOPtzkR LCyiRdlxlYrnV8iqNCbo1hZCrnPS43Id8IO49FUT2Y9Pps3Ht3aesu1pzVaMkhSC FcwKOcymJk754TVvCkV39zogrdzIViG/UgSKtGLN9SyDMVhTGgwVW121LwXUEYKl 9dx4/SneEpdMsxmSZEb/cwnk5FYfQj1N9KP10nR8ph3Xwc2NlWQxoHK3iGExkPKH QRkTbRQaB25omw+8ZYnU5qQJ3yWGYCKr3TAj6IDN13Qbg3wBMEt+UEVkLzCyD6RW rQ9T7iCZsmBYO4vZbrs31ynaMbheuqlgKaIzdc2JtTobsTtIftw88mxc9f30M6ZB NUGWSyZwag== Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4dpepanv31-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 23 Apr 2026 09:47:03 -0700 (PDT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-2bda35eab74so6179924eec.0 for ; Thu, 23 Apr 2026 09:47:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776962822; x=1777567622; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message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K+Yb4Zpu387Js/Ge7pRtxTG3hpkjVkSdec5EzVMw7 4fYptq3YGQ0EIrHbrG6AsIqqfl0h8E6kXdwYCag9a X-Received: by 2002:a05:7300:3253:b0:2c0:df3b:ec1e with SMTP id 5a478bee46e88-2e42dc0732emr9944359eec.11.1776962822117; Thu, 23 Apr 2026 09:47:02 -0700 (PDT) X-Received: by 2002:a05:7300:3253:b0:2c0:df3b:ec1e with SMTP id 5a478bee46e88-2e42dc0732emr9944340eec.11.1776962821442; Thu, 23 Apr 2026 09:47:01 -0700 (PDT) Received: from [10.0.40.30] ([51.52.155.79]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53d2cfc1dsm27499552eec.22.2026.04.23.09.46.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2026 09:47:01 -0700 (PDT) Message-ID: <34d884a3-ae25-49b2-9063-8783ff50e095@meta.com> Date: Thu, 23 Apr 2026 17:46:57 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] PCI/P2PDMA: Avoid returning a provider for non_mappable_bars Content-Language: en-GB To: Alex Williamson Cc: Bjorn Helgaas , Logan Gunthorpe , Ankit Agrawal , Leon Romanovsky , Niklas Schnelle , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260421174351.3897842-1-mattev@meta.com> <20260422090146.6faf00f8@shazbot.org> From: Matt Evans In-Reply-To: <20260422090146.6faf00f8@shazbot.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIzMDE2NyBTYWx0ZWRfXySXT8XFncadn +W5O1KRpdvTLGe8XP1GfRtDEk7lc/rWtu/7oClwWKIsNov8jSdcDGWukjblInavlwxY+ZqW8KUA FoV6OO/6/dcfe+Zb+LCdXzzawLqfUUMdh3eQlMKnieArpv++qRiiU8+bEBlxeFcj/JgfMktxtl+ jrIpzXAvd2dsTd/4LlWEWIcCLEvlRSkizDd6ESZMBSeQ8UUGc4+iySUaKHE3N7saUupWDsgAxSD ZQUHabsoXB+x45PBMDBbO7qBsV6B+cYPLE4mRGamwMiCBZ6QzvaeQ1VufbvszkhDqvFJDfT71no RHxuLIQL6ubDcAtb6kKJb9g68tofkDndtU38PqNpqyShpcDTga5cjMdwqCHZHyyPaLZ6z1XnG5W LrXtHk47O8FV3/zA07K2eEhd3yksjyIpJ8H+LCV877V45WG17jR/aE1vzb+/WXYwzJBaBbWojcH KJEt8Z629LumL0c0OwA== X-Authority-Analysis: v=2.4 cv=B42JFutM c=1 sm=1 tr=0 ts=69ea4d07 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=2UbFsIa4v//lIgRL4kGwwA==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=JnKecZnUtZousrUlYMGU:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8 a=CK8SrSYdo2KBgkCwzU4A:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-GUID: iOAIFfPjwXUguHy2Qa9VCNZjO926IpFa X-Proofpoint-ORIG-GUID: iOAIFfPjwXUguHy2Qa9VCNZjO926IpFa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-23_03,2026-04-21_02,2025-10-01_01 Hi Alex, On 22/04/2026 16:01, Alex Williamson wrote: > > On Tue, 21 Apr 2026 10:43:51 -0700 > Matt Evans wrote: > >> Extend pcim_p2pdma_provider()'s checks to exclude functions that have >> pdev->non_mappable_bars set. >> >> Consumers such as VFIO were previously able to map these for access by >> the CPU or P2P. Update the comment on non_mappable_bars to show it >> refers to any access, not just userspace CPU access. >> >> Fixes: 372d6d1b8ae3c ("PCI/P2PDMA: Refactor to separate core P2P functionality from memory allocation") >> Signed-off-by: Matt Evans >> --- >> >> This arises from Alex Williamson's suggestion to test >> non_mappable_bars when getting the provider, with discussion here: >> >> https://lore.kernel.org/kvm/20260415181623.1021090-1-mattev@meta.com/ >> >> The goal was to prevent a hole where VFIO could export DMABUFs for >> BARs marked non-mappable, and to fix for all users of the provider >> rather than just VFIO. Alex observed that non_mappable_bars should be >> taken to mean BARs weren't usable by the CPU _or_ peers and, >> considering that, its comment about userspace access wasn't quite >> right. >> >> >> drivers/pci/p2pdma.c | 3 ++- >> include/linux/pci.h | 2 +- >> 2 files changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c >> index 7c898542af8d..4a783413f466 100644 >> --- a/drivers/pci/p2pdma.c >> +++ b/drivers/pci/p2pdma.c >> @@ -318,7 +318,8 @@ struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar) >> { >> struct pci_p2pdma *p2p; >> >> - if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) >> + if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM) || >> + pdev->non_mappable_bars) >> return NULL; >> >> p2p = rcu_dereference_protected(pdev->p2pdma, 1); >> diff --git a/include/linux/pci.h b/include/linux/pci.h >> index 2c4454583c11..1e6802017d6b 100644 >> --- a/include/linux/pci.h >> +++ b/include/linux/pci.h >> @@ -508,7 +508,7 @@ struct pci_dev { >> unsigned int no_command_memory:1; /* No PCI_COMMAND_MEMORY */ >> unsigned int rom_bar_overlap:1; /* ROM BAR disable broken */ >> unsigned int rom_attr_enabled:1; /* Display of ROM attribute enabled? */ >> - unsigned int non_mappable_bars:1; /* BARs can't be mapped to user-space */ >> + unsigned int non_mappable_bars:1; /* BARs can't be mapped by CPU or peers */ >> pci_dev_flags_t dev_flags; >> atomic_t enable_cnt; /* pci_enable_device has been called */ >> > > Should pcim_p2pdma_init() separately test pdev->non_mappable_bars > before the rcu-deref/kzalloc of the pci_p2pdma object and return > -EOPNOTSUPP? > > That then invokes the same error paths we'd see if we simply don't have > p2pdma in the kernel and handles the pci_p2pdma_add_resource() path > automatically as well. > > This pcim_p2pdma_provider() test is really then just suppressing the > WARN_ON that we'd otherwise see by not finding the p2p object on the > device. Thanks, That makes sense, yes, it'll avoid the WARN that'd otherwise occur in pci_p2pdma_add_resource(). I'll do a v2 adding this check to pcim_p2pdma_init() as well. Hopefully Logan & Niklas's R-B will still apply. Thanks, Matt