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 7FE1B29D273 for ; Thu, 16 Apr 2026 18:03:45 +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=1776362627; cv=none; b=LgpD89WilKLck8zkZef0Ql3PW+r9INvkCWxnP09Kny/R6qWyvLoCABpFNm7w2eQ4G8LEpQbrJl1fv+ARSsvqzwSccMPUOBRzK/TwuGY/8PSykePXaLhOP2tMqgZHffKmwNAEMpVrlF7viMra8aadYIvo6Qsk+fbhYDvtNcq/1rk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776362627; c=relaxed/simple; bh=2GFL7VB0cRgFFnQbEkqUx5fd6HPHx7ACEWYneTUtHv8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HPy5MaUQcpmJtjRWjyzJhYS/OfVJwec1/xQ4hcFjYvC2s4udcINpwr7VEEVt3VDI7U3/O7a3IYa3eOpuZCKbwKbiFRHXBhu5ed5cE4EosQzICO4dOnyGnxTE8bWZLOfI0G0Q1rtqKsNb8rELLhClctcrlxqGcBGv2qcVzzETzUE= 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=EoLxV8Tt; 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="EoLxV8Tt" Received: from pps.filterd (m0528004.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63GHFOLw3246108 for ; Thu, 16 Apr 2026 11:03:44 -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=zCV6QPUTe0ssrZC3JFQw+rrD1aQfezLGRz11FC3KHW4=; b=EoLxV8TtXF+v y2CGmOD96u45PSbUUgbaSvdxJZomeK+msMnl6Pl6XMdlEdIwFS8yhKKS/Uay6T7s hVGgKV10OHDNXFnj2UPfnMaC0RuXYxuQ+lI9V7L2IDyf94kAjwz5yA8+Z/7rHiUU yuWs5FU8VIMvfL2fzhjRzz2mo33P95oHjMo7g7fiEb/wf0fsHfqnWdpn2VJbsOhJ ++DpbhMXneHucglec4BrRfTq4QLpm1P6zEaURoNLsM4QRpXtig8pMLOURg/bwWXf UHz9CKTvEK4y5OuHmrbxZrmJHlZZdh1RayuJsgrQKbllhZB4zRrwR4uMgfQsXpb1 L+IsVwfCBQ== Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4dh84tuy3y-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 16 Apr 2026 11:03:44 -0700 (PDT) Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4837b6f6b93so69286615e9.3 for ; Thu, 16 Apr 2026 11:03:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776362623; x=1776967423; 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-id :reply-to; bh=zCV6QPUTe0ssrZC3JFQw+rrD1aQfezLGRz11FC3KHW4=; b=s38ODlKABLH3PdaNILTuwS2eD/jlsIf/N6SjS6k6uFG+QD6Ac9pLm0L6WW/7cy9S9j RfDNw4gS8gAvJ0tyocId9dSDgX6xH3daEdBFuMX3VqqE7U4ivShN2EKstyt0xYItBJBo tbymSR939Quxg0X9MEIRT5/DyOim/7CFV1C/Rw7Sdg17mXwESKvjB2cajNajWNtCuJOd 9utK0qzNTBSdc7eVgn56OlovtifVD69JD1yAit/bTSZgRjAgXzyZ+oEYYkBliXScye+Y w23GgcAjxTha0eiZd9SH7inSsEATu+XxxnBOSStji99iI2uarKPOb5TbZcmchWMZQYSE Q67g== X-Forwarded-Encrypted: i=1; AFNElJ+Ez710Ma7GwrwoWNniU9Sy7nBVgnFvHr5WjrlSHq2BHmzzTIobllNGcXxwwO5n3In0UsBd1yKOWMW57uo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9KHSt0Syk9V3VAdlBcPwvlT5IQhkCrkxeVJlIXHTb2HMCSMlT 1eaj/Aw1lLJcO++khA5o6sNlatEvaq8f4LoE/nYWesXy405JA6dhPO8QMVQrVs4EiRMV7AVXSHe a3MUorzWoFZvAIMBExxxbbraT3zhKfanxjxVm7eGyuK6xS4PDEy3+tEQj8DGHlG7NsapLJHeB X-Gm-Gg: AeBDiesjxmdnjTLoOtHOXPsZozFZK642T01oXA30qGtVtfqtyojHtStlGUBxmCpa7Zk 5ki7TByzzvi8wNyY+yjby6ay49WVPnMSIgUxgPBYrbhbeximuFv/TaNZds59Q2kW/79N4jHonqG CDFZaicwteKIJe2QsZUjmL/10x1fn8R3DAuzTo1SIGpHhRU8uq6XDo02G9KFqdzEP4M/GIsteh+ gRL0Blg8vCEB3Cv0+/vsJRmJPfj3/62hJEB/m+ChaP5pWvVYIDlEs1zz8e6Wk2IXafnJfBkrAoq bbLjpS+/v2xUaKIh4P+q6ugA992XOqiTKc2nCMXexBTssnWDkX5+4k1K/ykEtuOo0KUYfn//Sou kA9h02m75rLyffRkSUuF2Cay5xzruLFbHIP+MkmiiDfemphtbUzYPMaGRVZ6c47sV0fskPCuD7f Jg5DNyc/GMLOTbMXAcK8f7pAcTY6EdSlO1cb/D1ulaB9MwBKe4vj8sVGaVwfGiS+FVcLwgbrutL mRNYUZkrhIZPmBGsacImceazFowR+DCRA== X-Received: by 2002:a05:600c:528c:b0:485:3a86:6392 with SMTP id 5b1f17b1804b1-488d68c2bc6mr343298105e9.20.1776362622782; Thu, 16 Apr 2026 11:03:42 -0700 (PDT) X-Received: by 2002:a05:600c:528c:b0:485:3a86:6392 with SMTP id 5b1f17b1804b1-488d68c2bc6mr343297615e9.20.1776362622276; Thu, 16 Apr 2026 11:03:42 -0700 (PDT) Received: from ?IPV6:2001:8b0:8b6:13d4:102e:f2af:e074:5cde? (e.d.c.5.4.7.0.e.f.a.2.f.e.2.0.1.4.d.3.1.6.b.8.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:8b6:13d4:102e:f2af:e074:5cde]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488f581b9fbsm68548305e9.5.2026.04.16.11.03.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Apr 2026 11:03:41 -0700 (PDT) Message-ID: Date: Thu, 16 Apr 2026 19:03:40 +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] vfio/pci: Don't export DMABUFs for unmappable BARs Content-Language: en-GB To: Leon Romanovsky Cc: Alex Williamson , Jason Gunthorpe , Kevin Tian , Vivek Kasireddy , Ankit Agrawal , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260415181623.1021090-1-mattev@meta.com> <20260416081138.GE361495@unreal> <2ea075f9-c80c-41e9-9f93-9b0a2858f68f@meta.com> <20260416131417.GF361495@unreal> From: Matt Evans In-Reply-To: <20260416131417.GF361495@unreal> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=DeknbPtW c=1 sm=1 tr=0 ts=69e12480 cx=c_pps a=Ech0Gv1thIkdqUNjVc2Ehg==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=GbPsI2Ihf5RTnMjR_gZv:22 a=c92rfblmAAAA:8 a=VabnemYjAAAA:8 a=lGc5rnHzrJZDjf1Vz5UA:9 a=QEXdDO2ut3YA:10 a=cZgK7WzY9ta9U-6s7oqD:22 a=GvGzcOZaWPEFPQC_NcjD:22 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDE2MDE3MiBTYWx0ZWRfXyG5ZBqfORXio XcLA3VJ5Jp58XUWrWe1GqM5Q8Z1MB6YQMYzBtpGktFVjn15LpbnnnDaZYTJwfb/qsmiAm9gJXUe 8mO/C+qD1jaR80thX1WupmUadMdpyq41Nt8SDEy2TrazttVSrzV4N746Vkm8FxqvK2/No66ddvS teEYCK+1gKJnzEj8TivxilLdkiqbhrNqr6ybRLTz0VSmKyVw3pPyp9gcBd7QN4s80WX8rGw67Gf sxz5LSEeLVDR0skfhD1UyeAqvqSxiByar1xeoE5iimcqBdJ331uVTDUpe+hJ99WYfgl05r6Ct7G wodtON9ZQ0OqUi9hzJ7cnva23jy4t/tK+2Pt2gBf+awNxhkMwsdtfRfe4QcEY8jkbgRmKzNIatj s0E+eNsdcHBcW/QyoLyULQAvSS/fpJgp6teGs1e+2NXCttfevDMBnNCmWCf1zyQgvUNeSOAh/3X sVq+BrXFBRggoCmPp7w== X-Proofpoint-GUID: 2i4Q-sxzhONMIDGC9as4nRdEdyMxe_6R X-Proofpoint-ORIG-GUID: 2i4Q-sxzhONMIDGC9as4nRdEdyMxe_6R 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-16_03,2026-04-16_03,2025-10-01_01 Hi Leon, On 16/04/2026 14:14, Leon Romanovsky wrote: > > On Thu, Apr 16, 2026 at 02:05:30PM +0100, Matt Evans wrote: >> Hi Leon, >> >> On 16/04/2026 09:11, Leon Romanovsky wrote: >>>> On Wed, Apr 15, 2026 at 11:16:23AM -0700, Matt Evans wrote: >>>> Although vfio_pci_core_feature_dma_buf() validates that both requested >>>> DMABUF ranges and the PCI resources being referenced are page-aligned, >>>> there may be reasons other than alignment that cause a BAR to be >>>> unmappable. >>>> >>>> Add a check for vdev->bar_mmap_supported[index], similar to the VFIO >>>> mmap path. >>>> >>>> Fixes: 5d74781ebc86c ("vfio/pci: Add dma-buf export support for MMIO regions") >>>> Signed-off-by: Matt Evans >>>> --- >>>> drivers/vfio/pci/vfio_pci_dmabuf.c | 3 +++ >>>> 1 file changed, 3 insertions(+) >>>> >>>> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c >>>> index f87fd32e4a01..4ccaf3531e02 100644 >>>> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c >>>> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c >>>> @@ -249,6 +249,9 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, >>>> if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX) >>>> return -ENODEV; >>>> + if (!vdev->bar_mmap_supported[get_dma_buf.region_index]) >>>> + return -EINVAL; >>>> + >>> >>> And it looks like AI has valid concern about this line too. >>> https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20260415181623.1021090-1-mattev@meta.com__;Iw!!Bt8RZUm9aw!5DxsN8cDUviPIZqEjG0pZ_VYYbl_RdmWucTGdTZ3ZzlVP_Ysb0n7ykr0eXwFXdpuqvZH2FK3$ >> >> Ah, Sashiko has a point, and I think its suggestion of checking lower down >> in the default .get_dmabuf_phys (vfio_pci_core_get_dmabuf_phys()) and >> preserving driver overrides is decent. Will revisit. >> >> To your other question: >>> I noticed this check in vfio_pci_core_mmap(). Isn't that sufficient? >> >> The scenario in mind is doing a DMABUF-export for BARs that you haven't >> necessarily noticed can't be mmap()ed, and both paths should be checking. > > I added the validation checks that matter on the kernel side, but mmap is > primarily important for callers. What I am missing is an explanation of > why the kernel should impose this restriction on itself. I don't understand your question, really sorry! Can you rephrase it please? I want to make sure I answer it fully. Although mmap() fails for BARs that are unmappable (for whatever reason), a DMABUF export for the same ones could in some slim cases succeed -- because the checks aren't identical. If export succeeds, it could potentially allow P2P (or CPU via a future DMABUF mmap()) access to something possibly unmappable, no? For the checks that vfio_pci_probe_mmaps() does (leading to bar_mmap_supported[] = false), most have corresponding-but-different checks reachable from DMABUF export: If a BAR is: Then DMABUF export...: size < pagesize vfio_pci_core_fill_phys_vec() catches it Not IORESOURCE_MEM pcim_p2pdma_provider() rejects it non_mappable_bars ... nothing? Export allowed As a quick test, if I hack in non_mappable_bars=1 for my function, it appears exporting a DMABUF from it works. We could add another check for non_mappable_bars, but my thinking was that we don't want to keep adding to an independent set of DMABUF checks, especially if a future quirk/etc. could create another scenario where BARs aren't mappable. I.e. we should reject DMABUF export in exactly the same scenarios as mmap() would be rejected, symmetrically, by testing bar_mmap_supported[]. Hope that goes some way to answering the Q, hopefully I haven't missed something! Thanks, Matt > > Thanks > >> >> Cheers, >> >> >> Matt >> >> >>> >>> Thanks >>> >>>> dma_ranges = memdup_array_user(&arg->dma_ranges, get_dma_buf.nr_ranges, >>>> sizeof(*dma_ranges)); >>>> if (IS_ERR(dma_ranges)) >>>> -- >>>> 2.47.3 >>>> >>