From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EED7199FAB for ; Sat, 18 Jul 2026 07:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784358783; cv=none; b=uDEi8P9JEgazedlM2ExIqFbpgn8MgbgLGsca3L/hp81iisNYT5qxvbg5xmgJwVNQUyESZg9YEC/sCTeIg0n5v6aYiwfX+SUPNRzZOwEXhwMNKNMfX/cEiH6+jsuRp0tahy/saNItrH7KBbw4NBNaSYnQZiZYiosfxxH5Ych6ftw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784358783; c=relaxed/simple; bh=YSy7/tgbwqVh7i9JaYhDmwUgGjUuPOY5sfT8w5VRFAA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cWPb7X0WTWzPMdF6whJb4iZWX1ueiUXP2RM5ej/dGRPkDV8BA1+CoRv/vkMGB8T0UCoAGNVeGWoV3o4iooVuOeqQ2ogb1qZQKXG3VORunZcdrH704hsIdFU+SmGOx0vgTr4MXF4orKE/UA80EBncuoMdkQKDbBMSK46vWeGOTf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JcLDV507; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JcLDV507" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ced3386430so50166115ad.1 for ; Sat, 18 Jul 2026 00:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784358782; x=1784963582; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=LCvurZDj8ZNBgdcw/TmEFw/CVg2NYzhOj6T2ENk19L4=; b=JcLDV5075z1GdNldDT577AIgqzcQ7TADWc4XrEu7bfqbKK7ZsticZ/IO74onUsqbUb 8J2SVJ+tHSMxBT54jyqeJ2RCAnfg/SMY18B7s4Of5bzqzYqN/s2GNw/NTHWLuJeYChBn DuS/43qEFLqvVclFOB2jp5iHeCmupQCkL+H5Dx4+FKZp1WOtmS72p6N1HIrcJeQaKhTH gD5uiJiY6GF2bmP5qUkvic2s+SQhk1DdMbVWjnG3wzOGjKN3AsexP2LMFGh3gslktMxT SA6LzBEYrGrvXLyVbMQ8gm23ynaVHmpGAbdJSx+Gw69I6+98n5BI271cykcvc6rXJItK bmlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784358782; x=1784963582; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=LCvurZDj8ZNBgdcw/TmEFw/CVg2NYzhOj6T2ENk19L4=; b=kOn28sdzllWTGj3LT+xn5fcu2KQYwrLQLV5ZepPP6SVAXDoUgWXmZC6UNOPgL+ZP/C 9zJ87Ib3Ns4ykxewB9npnhhbGExQOCJHwM1Oobl/ifXWEaNBzXTRnKYPI0rWqns7F6Jl bg0DVE3x/BcJ67t2kJzEZga7x55+8mk/ZA2tqesPJudu/khK9oOoblaJO9XAztpquwYu fitWI2nIUs2pzv+SuNK4m1w0+o037pEzfaTzv4wIyjuvGxdXHjRrV2fqNHUtA9H/yGuC DtsIy3+jTcn5yZCAbPEHvu7hxDoyuv+/495QNowD6Wo/nMz6011NJvO9RX8FfUYPdwgt Rw5A== X-Forwarded-Encrypted: i=1; AHgh+RqwW0fHvBAtiq2UFfnqFEEEKI/p/WDJ2J9KUQ25cQ92t1UaFF2QY5ohw3iOeLblSlZXxTnXLwiIePWXiGs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxzd8YpWYlWt7QxEKzXe6ROPNlbPYZXrJuYv9+nAjBfJ+7Opb3+ 5TuVaIScq6NEa5cY6hYi6KN79f1bS0sF0FOMenoRhIvUbql+ULAT+rGs X-Gm-Gg: AfdE7cnPAul8srYB70wXdhPXoD1o0ZI4s5ytST6yGqP9ocNObAz9DKwsCpUYKcaYzhA 6jHAQ/ojle+winNyS0DitLvuVlomCKeBBEK4+9i9ll0KdFFqeN3qVNWiFQd7sQUFWVJ7qIaGkEi KapID8uB1Tc5N5724C8cMkU/Bq4JLENp3Dq8nc5gEWZWnax+PKo056COfyYUP/a/ujyG3bINS5n viq9PO60ISo1UbA8Uzkip1O4yWcyIw/EWf7lWtw68Xjw1X36RFXdi3laHSid+/Dd81zd+5sQc4m CfGlk/SOqAg6tUShLz6+x7snWJHatJUYePCI8Tcl1+jRorD7KYx+BB5MZAi9QQFEWZOoM/wGolR zXlLN/ZRut/dgY59jTMlX3NcdIbYcnGJrbqQMxgvjSTVazGcvSB5qLFA1QBBv X-Received: by 2002:a17:902:dcd5:b0:2ca:6d87:cda0 with SMTP id d9443c01a7336-2cf34804834mr41476345ad.6.1784358781780; Sat, 18 Jul 2026 00:13:01 -0700 (PDT) Received: from lgs.. ([2001:250:5800:1000::f280]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf344be458sm23372375ad.25.2026.07.18.00.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 00:13:00 -0700 (PDT) From: Guangshuo Li To: Melissa Wen , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Iago Toral Quiroga , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li Subject: [PATCH v3] drm/v3d: release CPU job resources on pre-init failures Date: Sat, 18 Jul 2026 15:10:45 +0800 Message-ID: <20260718071047.3037514-1-lgs201920130244@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=y Content-Transfer-Encoding: 8bit The changes referenced by the Fixes tags moved CPU job resource cleanup to v3d_cpu_job_free(), the CPU job kref destructor. However, CPU job extensions are parsed before v3d_job_init() has successfully installed that destructor. Timestamp and performance query arrays, their syncobj references, and the indirect CSD GEM reference can therefore be acquired before the CPU job is managed by the kref cleanup path. If a later pre-init validation fails, or if v3d_job_init() itself fails, the CPU job can be cleaned up or deallocated without running v3d_cpu_job_free(). Those extension resources are then leaked. Move the CPU-job-owned resource release into a helper and call it both from the normal CPU job destructor and from the pre-init error paths. Fixes: b0fe80c0b925 ("drm/v3d: Fix use-after-free of CPU job query arrays on error path") Fixes: 6eb6e5acafa4 ("drm/v3d: Release indirect CSD GEM reference on CPU job free") Signed-off-by: Guangshuo Li --- v3: - Do not call v3d_cpu_job_free_resources() after v3d_get_extensions() fails, since v3d_get_extensions() already handles the cleanup internally, as pointed out by Maíra Canal. v2: - Rebase onto drm-misc-fixes. - Fold the indirect CSD GEM pre-init failure fix into this patch. - Drop unnecessary pointer and count resets after releasing resources, as suggested by Maíra Canal. drivers/gpu/drm/v3d/v3d_submit.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c index 7682b24f13ec..77e94c25b2af 100644 --- a/drivers/gpu/drm/v3d/v3d_submit.c +++ b/drivers/gpu/drm/v3d/v3d_submit.c @@ -127,10 +127,8 @@ v3d_render_job_free(struct kref *ref) } static void -v3d_cpu_job_free(struct kref *ref) +v3d_cpu_job_free_resources(struct v3d_cpu_job *job) { - struct v3d_cpu_job *job = container_of(ref, struct v3d_cpu_job, - base.refcount); v3d_timestamp_query_info_free(&job->timestamp_query, job->timestamp_query.count); @@ -140,7 +138,15 @@ v3d_cpu_job_free(struct kref *ref) if (job->indirect_csd.indirect) drm_gem_object_put(job->indirect_csd.indirect); +} + +static void +v3d_cpu_job_free(struct kref *ref) +{ + struct v3d_cpu_job *job = container_of(ref, struct v3d_cpu_job, + base.refcount); + v3d_cpu_job_free_resources(job); v3d_job_free(ref); } @@ -1320,12 +1326,14 @@ v3d_submit_cpu_ioctl(struct drm_device *dev, void *data, /* Every CPU job must have a CPU job user extension */ if (!cpu_job->job_type) { drm_dbg(dev, "CPU job must have a CPU job user extension.\n"); + v3d_cpu_job_free_resources(cpu_job); ret = -EINVAL; goto fail; } if (args->bo_handle_count != cpu_job_bo_handle_count[cpu_job->job_type]) { drm_dbg(dev, "This CPU job was not submitted with the proper number of BOs.\n"); + v3d_cpu_job_free_resources(cpu_job); ret = -EINVAL; goto fail; } @@ -1335,6 +1343,7 @@ v3d_submit_cpu_ioctl(struct drm_device *dev, void *data, ret = v3d_job_init(v3d, file_priv, &cpu_job->base, v3d_cpu_job_free, 0, &se, V3D_CPU); if (ret) { + v3d_cpu_job_free_resources(cpu_job); v3d_job_deallocate((void *)&cpu_job); goto fail; } -- 2.43.0