Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) (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 233CD331209 for ; Tue, 28 Jul 2026 05:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.204.34.129 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785217345; cv=none; b=XDfDCXceixIRg0e41XWdiFIUFxuy0hSLNhAMoMTN5k2Y0laeiKsISbcdkrEd/ah+/WWauJwUrcHyErBtV2XF8hwJk3A2FqVes4dfnCN/p23eY5u2S4snnMXsnPfcIiVvm9HH0gqB6fp+I3aNf+8w0b+OsD8fNpby6O1p0uOiTPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785217345; c=relaxed/simple; bh=t2TAKqSyJB2uf2IoAa0fgSme+6XE1fU5T8QiE8pbUsE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dZT70OjrQNm+eVbWHHS6WTqA8zYqzv1AVhyZSqsH8armKrqLN8rps+G9QbK7yaicaLbSGYRknkc1uyhXx9MR9QhEokh2DRjB07sl7IXkTuIjNmo1yvMbktND5KB9iWr19jyxkR6oQh0C64k3d4gmYIy3e8za0BYF3rb12DQCcJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=IH+IlSr4; arc=none smtp.client-ip=54.204.34.129 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="IH+IlSr4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1785217336; bh=wUN3O4Cjd2YkLgCBSrc7QiWQMRHH9tGXZA/AAXTLcYU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=IH+IlSr4fsD6oQ4OzO5KVeZjL/ss6CsdEqFK25mMNPSOUhRAq6qgHEdONCNRPGsCY h1KQOKL8k8nCAtsrMfaLStxcRqqXlRfYvDhssXgsVxLpqVSJfimN+2th4vLGRsmIAn vGTasOuCjsIWNLdgClh/h0nMDIr+JKcoJC9j2+QE= X-QQ-mid: esmtpgz15t1785217322t2610437e X-QQ-Originating-IP: Sls0RiQYBtOqLxTwckwD+CKNI4DVly88b/yLqvNA1Ic= Received: from localhost.localdomain ( [1.202.39.170]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 28 Jul 2026 13:41:55 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 13876092162116608539 EX-QQ-RecipientCnt: 12 From: ZhaoJinming To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , dri-devel@lists.freedesktop.org Cc: David Airlie , Simona Vetter , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Kees Cook , Thomas Zimmermann , ZhaoJinming Subject: [PATCH v2] drm/i915/userptr: Fix user pages leak on get_pages failure Date: Tue, 28 Jul 2026 13:41:52 +0800 Message-Id: <20260728054152.140524-1-zhaojinming@uniontech.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: esmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz4b-0 X-QQ-XMAILINFO: M9t1NOw+1P4G3I7b1Px2gzZGshH8hVDRmCO60t9PbbYSNLZsEf0w0cb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B5Ye7Aabb3ujjtK+gg== X-QQ-RECHKSPAM: 0 When ____i915_gem_object_get_pages() fails inside i915_gem_object_userptr_submit_init(), the pvec containing pages pinned by pin_user_pages_fast() was never freed: 1. obj->userptr.pvec was set to the pinned pages 2. The local pvec variable was NULLed 3. ____i915_gem_object_get_pages() failed, but its internal i915_gem_object_userptr_drop_ref() only decremented page_ref from 2 to 1, not triggering the pvec cleanup 4. The unconditional obj->userptr.page_ref-- brought page_ref to 0, but the pinned pages remained referenced only by obj->userptr.pvec with no path to reclaim them Additionally, the cache hit path could return success on a subsequent call despite page_ref being 0, leading to a GEM_BUG_ON(obj->userptr.page_ref < 0) crash in drop_ref when the pages were eventually invalidated. Fix by calling i915_gem_object_userptr_drop_ref() on the get_pages failure path, which properly decrements page_ref from 1 to 0, triggering the pvec cleanup. Make the page_ref-- after the if block conditional on success, since drop_ref already handles the refcount on failure. Signed-off-by: ZhaoJinming --- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c index 043095f93ac6..7d2750528485 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c @@ -292,9 +292,12 @@ int i915_gem_object_userptr_submit_init(struct drm_i915_gem_object *obj) obj->userptr.notifier_seq = notifier_seq; pvec = NULL; ret = ____i915_gem_object_get_pages(obj); + if (ret) + i915_gem_object_userptr_drop_ref(obj); } - obj->userptr.page_ref--; + if (!ret) + obj->userptr.page_ref--; out_unlock: i915_gem_object_unlock(obj); -- 2.20.1