From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795780744; b=KYxXauOxbax9R9mgGzVeeZMdrrzY6iyNVcnMDTx8OZD0z3wJbtXyG/D2Ypm/mDlKOle1 vLAwfAQRxxwp5swKPgzb2PzQBSDORemV0VRtmlMZAiEhDRxrJ30uKb0IsmZVXngRcNzec gbKVbIlB0vp5VnwTftQLW9IANPz/Qk26TeQEVe5CQINZHYLCRu1k1rSBse9ozR+Hidb5A qHUXrQINH4VGa7Fzmywa90s7MNv7Z6gsGp9tV3qgodhxZ7fL4aMcJbx0d+mZNk99ShaDx XYEL2Eug8gJy3bhvgbaHidpmjM+RBjSQlbAoAn5UqwIMM6RbEp0QlKzfYJn+AFSmYmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795780744; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:MIME-Version: Content-Transfer-Encoding:X-CMS-MailID:X-Msg-Generator:Content-Type: X-RootMTR:X-EPHeader:X-CMS-RootMailID:References; bh=Id3upqDD1i+LHsGcQdVswyP8vuaFBxcYGp5N04HwHyM=; b=XtcVAnNDqjvnafdQ8OyP49Rc8BjY0VZBt4z0P2wlqeLV8Euv51nMbttofqiaSDQe7ynt qwFC2QLEawBxBiM60T7KyNaaKSR9kGWqEwZrw8EjNdYdcTQP7gMm5Ph9OoGYTVtvQIGdw attKeSpgPC+cq4HhDQqJP4KD2ChESd/a/gVjrGk4YsEFQisGl/SkSWAxGMnfvaNRxIFv6 lzQ2nnX9rG8B1p9CWASyorGqdQ3nOsLVeSORwYHzARt8AC9z9/6Pj4G45MSzeEU8ufyxG xqrymHAyZdbjv7PPZORu4kwE4tk4V+bONLANS7nHsEqjiBNwemkEZUKqkxsNu6ElazA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=eTDDdgdJ; arc=none smtp.remote-ip=210.118.77.12 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B3D2606A69C for ; Fri, 27 Nov 2026 11:59:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B3D2606A69C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=eTDDdgdJ Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20261127115902euoutp02f9fffcf65c65c6fc9e7220855c677a80~r5RIyFpYl1643816438euoutp02R for ; Fri, 27 Nov 2026 11:59:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20261127115902euoutp02f9fffcf65c65c6fc9e7220855c677a80~r5RIyFpYl1643816438euoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1795780742; bh=Id3upqDD1i+LHsGcQdVswyP8vuaFBxcYGp5N04HwHyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eTDDdgdJ9gPOOx7Xw2sMngNEd0oxJe1W9gj3acfWV4ZIIPZawecBhxm2tmZAPe5D4 Mr6d8NPXukg82mYDgdIh30MdUfPD8obx07k9USmhKVWCJuASlFHqGczPi3hRN6shuX 8wlZ3ncNeGtX/HG/xrhNoXuMLoemC0l92kG8WBFk= Received: from eusmtip1.samsung.com (unknown [203.254.199.221]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041~r5RH9qnN12876328763eucas1p2J; Fri, 27 Nov 2026 11:59:01 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20261127115900eusmtip1b004ba38c6e7a6b1daeab6d50a5c4eca~r5RG3wJIQ0138901389eusmtip1M; Fri, 27 Nov 2026 11:59:00 +0000 (GMT) From: Marek Szyprowski To: iommu@lists.linux.dev, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Will Deacon , Leon Romanovsky , Jason Gunthorpe , Sibi Sankar , Honglei Huang , prakash.gupta@oss.qualcomm.com, Alex Williamson , Vikash Garodia , Dikshita Agarwal , Abhinav Kumar , Bryan O'Donoghue , Mauro Carvalho Chehab , Hans Verkuil , stable@vger.kernel.org Subject: [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Date: Fri, 27 Nov 2026 12:58:47 +0100 Message-ID: <20261127115849.2780625-4-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261127115849.2780625-1-m.szyprowski@samsung.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMS-MailID: 20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041 X-EPHeader: CA X-CMS-RootMailID: 20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041 References: <20261127115849.2780625-1-m.szyprowski@samsung.com> dma_iova_state::__size uses its top bit to record that SWIOTLB was used for one of the linked ranges. Users that mask or validate sizes refer to DMA_IOVA_USE_SWIOTLB directly, so adding another flag would require updating all of them. Add DMA_IOVA_FLAGS covering all flags kept in __size and use it in dma_iova_size(), in the size check of dma_iova_try_alloc() and in the vfio-pci dma-buf length validation. No functional change. Cc: stable@vger.kernel.org # v7.3+ Signed-off-by: Marek Szyprowski --- drivers/iommu/dma-iommu.c | 8 ++++---- drivers/vfio/pci/vfio_pci_dmabuf.c | 2 +- include/linux/dma-mapping.h | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 78742aeba932..99eb382a1359 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1838,11 +1838,11 @@ bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state, return false; /* - * DMA_IOVA_USE_SWIOTLB is flag which is set by dma-iommu - * internals, make sure that caller didn't set it and/or - * didn't use this interface to map SIZE_MAX. + * DMA_IOVA_FLAGS are set by dma-iommu internals, make sure that + * caller didn't set them and/or didn't use this interface to map + * SIZE_MAX. */ - if (WARN_ON_ONCE((u64)size & DMA_IOVA_USE_SWIOTLB)) + if (WARN_ON_ONCE((u64)size & DMA_IOVA_FLAGS)) return false; addr = iommu_dma_alloc_iova(domain, diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c index c16f460c01d6..8bda610dd988 100644 --- a/drivers/vfio/pci/vfio_pci_dmabuf.c +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c @@ -211,7 +211,7 @@ static int validate_dmabuf_input(struct vfio_device_feature_dma_buf *dma_buf, * dma_iova_try_alloc() will WARN on if userspace proposes a size that * is too big, eg with lots of ranges. */ - if ((u64)(length) & DMA_IOVA_USE_SWIOTLB) + if ((u64)(length) & DMA_IOVA_FLAGS) return -EINVAL; *lengthp = length; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index efde0e5a58dc..0ebf3090ea0f 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -135,10 +135,16 @@ struct dma_iova_state { */ #define DMA_IOVA_USE_SWIOTLB (1ULL << 63) +/* + * All flags stored in the upper bits of dma_iova_state::__size. Sizes passed + * to dma_iova_try_alloc() must not overlap with them. + */ +#define DMA_IOVA_FLAGS DMA_IOVA_USE_SWIOTLB + static inline size_t dma_iova_size(struct dma_iova_state *state) { /* Casting is needed for 32-bits systems */ - return (size_t)(state->__size & ~DMA_IOVA_USE_SWIOTLB); + return (size_t)(state->__size & ~DMA_IOVA_FLAGS); } #ifdef CONFIG_DMA_API_DEBUG -- 2.43.0