From: Jianfeng Liu <liujianfeng1994@gmail.com>
To: dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org,
"Jessica Zhang" <jesszhan0024@gmail.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
linaro-mm-sig@lists.linaro.org,
"Christian König" <christian.koenig@amd.com>,
"Rob Clark" <robin.clark@oss.qualcomm.com>,
"Sean Paul" <sean@poorly.run>, "Simona Vetter" <simona@ffwll.ch>,
freedreno@lists.freedesktop.org,
"Marijn Suijten" <marijn.suijten@somainline.org>,
"David Airlie" <airlied@gmail.com>,
"Dmitry Baryshkov" <lumag@kernel.org>,
"Abhinav Kumar" <abhinav.kumar@linux.dev>,
"Jianfeng Liu" <liujianfeng1994@gmail.com>
Subject: [RFC PATCH v1 2/2] drm/msm: reject dma-buf imports without struct page info
Date: Wed, 23 Sep 2026 15:42:23 +0800 [thread overview]
Message-ID: <20260923074256.9357-3-liujianfeng1994@gmail.com> (raw)
In-Reply-To: <20260923074256.9357-1-liujianfeng1994@gmail.com>
msm_gem_import() fills the GEM object's page array with the deprecated
drm_prime_sg_to_page_array() and stores the attachment sg_table for
later mapping into the GPU's own pagetables via iommu_map_sgtable().
Both need the struct page of the sg_table:
- iommu_map_sg() maps sg_phys() of each entry, and
- drm_prime_sg_to_page_array() iterates with for_each_sgtable_page,
which walks sg->length.
When CONFIG_DMABUF_DEBUG=y, dma_buf_map_attachment() hands importers
a copy of the sg_table with the page pointers stripped and sg->length
zeroed. In that case drm_prime_sg_to_page_array() "succeeds" while
filling zero entries, leaving msm_obj->pages uninitialized garbage
(kvmalloc_objs() does not zero). The buffer is imported anyway, and
the first VM_BIND map of it fails asynchronously in the scheduler job
run - after userspace has already enqueued GPU work referencing the
mapping. Userspace then observes arm-smmu translation faults from
UCHE, e.g. hardware video decode in clapper/chromium:
gpu fault: ttbr0=000000088a889000 iova=000000010741c000 dir=READ
type=TRANSLATION source=UCHE
Replace the deprecated helper with an explicit loop so that a missing
or short page list is detected at import time and rejected with
-EINVAL. This turns the silent memory corruption into a clean import
error, letting userspace fall back instead of crashing the GPU.
Note that msm fundamentally cannot map a page-less sg_table into its
per-process GPU pagetables (it needs the physical addresses), so
imports of such buffers can never work until msm is converted to
build its GPU mappings from the attachment's DMA addresses.
Signed-off-by: Jianfeng Liu <liujianfeng1994@gmail.com>
---
drivers/gpu/drm/msm/msm_gem.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index c4cff3d53d81b..0d5a91181d05b 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -1307,7 +1307,8 @@ struct drm_gem_object *msm_gem_import(struct drm_device *dev,
struct msm_gem_object *msm_obj;
struct drm_gem_object *obj;
struct dma_buf *dmabuf = attach->dmabuf;
- size_t size, npages;
+ struct sg_page_iter piter;
+ size_t size, npages, filled = 0;
int ret;
size = PAGE_ALIGN(dmabuf->size);
@@ -1333,8 +1334,32 @@ struct drm_gem_object *msm_gem_import(struct drm_device *dev,
goto fail;
}
- ret = drm_prime_sg_to_page_array(sgt, msm_obj->pages, npages);
- if (ret) {
+ /*
+ * Fill the page array ourselves instead of using the deprecated
+ * drm_prime_sg_to_page_array(), so that we can detect sg_tables
+ * that carry no struct page at all. Those must be rejected:
+ * msm maps imported buffers into the GPU's own pagetables with
+ * iommu_map_sgtable(), which needs the physical pages, so an
+ * import without page information could never be mapped. The
+ * most prominent case is the page-stripping sg_table wrapper that
+ * dma_buf_map_attachment() hands out when CONFIG_DMABUF_DEBUG=y.
+ *
+ * drm_prime_sg_to_page_array() would "succeed" with zero entries
+ * filled in that case and leave msm_obj->pages uninitialized,
+ * which later blows up as arm-smmu translation faults from UCHE.
+ */
+ for_each_sgtable_page(sgt, &piter, 0) {
+ if (WARN_ON(filled >= npages)) {
+ ret = -EINVAL;
+ goto fail;
+ }
+ msm_obj->pages[filled++] = sg_page_iter_page(&piter);
+ }
+ if (filled != npages) {
+ DRM_DEV_ERROR(dev->dev,
+ "import of dmabuf from '%s' rejected: sg_table has no/misaligned struct page info\n",
+ dmabuf->exp_name ?: "?");
+ ret = -EINVAL;
goto fail;
}
--
2.47.3
prev parent reply other threads:[~2026-09-23 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 7:42 [RFC PATCH v1 0/2] Fix the v7.3-rc4 DMABUF_DEBUG regression breaking drm/msm hardware video decode Jianfeng Liu
2026-09-23 7:42 ` [RFC PATCH v1 1/2] dma-buf: keep DMABUF_DEBUG off by default Jianfeng Liu
2026-09-23 8:03 ` Christian König
2026-09-23 7:42 ` Jianfeng Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923074256.9357-3-liujianfeng1994@gmail.com \
--to=liujianfeng1994@gmail.com \
--cc=abhinav.kumar@linux.dev \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jesszhan0024@gmail.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®