Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 9A2873C1F5C for ; Thu, 4 Jun 2026 06:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780555364; cv=none; b=hopyydGzxOCNztYI9uf57pBgwirmnJ73zuaimzA2Wu5R/mCKuOKbtnRA10i9pkbIEjVtTcd+gd71SXtShwOt07SBoh+IM+SzTpC5sboagiWh89hzpIoKhFjTb9OvASEv7Vro7nWGsi1rEv7tHu5Lg3ettyvhFyI6Xd6ipMAUJwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780555364; c=relaxed/simple; bh=AL4aGc4tCN7Tn4HEt+BYMjvUVWRuAfNGMUk/4HcMmuE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PoKIh+RhRz7KoC/qpgJ15LYuvZXRvBVc+L1t3DXXw03790h0ryIS8OmNOA+PwfzfRL1nVhMmMDWaQARGrOBriT7wAUAmMLeUuBZ9LBESJsL0CXEbtkaZ8ti/bSXS7rhWDv4iRswdRdOvHfx+g5XquBTL68T8fdYMhyabbBC0sPM= 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=KpeF/vzh; arc=none smtp.client-ip=209.85.214.173 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="KpeF/vzh" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2c0c2c7d45eso3454085ad.1 for ; Wed, 03 Jun 2026 23:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780555362; x=1781160162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ERlLtZnynL1JYR1BCmWJV8DFDr7q66lNokSGTMbdgUo=; b=KpeF/vzhsWe3iA0R2MetW2W50PEfJCFSVHyyeEJ5RGyH9/zXiERcb0ozaVYvLgb2in OHcmngz8hbPDJRbpSQBKjrPGAgT7DST0p+TB6F3SU2ZJP6dV3wWUBRBZo7NA61+3tWEG j/oK218taNtQa3Vf9rSFwDg7RPtkluZPtaiYXwinOYNKyW34SNgzU+EskrCW7w6KDov4 xaftYSWMiollsPargTADuNt5H26OY6ZHEKTv0FQwjsUtmOSMd8LTsRHu6IK5wHlxSr46 w9H6Psc5xzar4UyeQQKwG8wMBmeo4wi0LbcfQuqYna0ic3kZDI7VDGyp8dvL9zxZU2YV Xo9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780555362; x=1781160162; h=content-transfer-encoding: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; bh=ERlLtZnynL1JYR1BCmWJV8DFDr7q66lNokSGTMbdgUo=; b=ZOOecBjqw4Y63lMu91MRg5KuwwQEBqOveKN230wyvdgDHTsl9hMfmnXjKPQxZtODGw JPXS/H80so/vUIuQo4K3VTtrql4ca7LzMCHFESLUMqzmuYME0m4AH7t/fhefCScj4L96 kY1J72kihlV0LBp0NSZZ/U/O21L0NY6h7G9/ZgpuNH9r2ryhY8F3/43PHbuzrLDSLxlw dER1Lczw/tj3TfkUZr4t7gWKmOZdHRuGyHP8e59ty3frJPZL/9UJ55eBDuSM6h6BjCX7 jB3YIGxqJKV1a7FjnLHsZ/gMpSORNVEzhn3tUQOU+b0SAD5zwgRaZ0Q4wQg3OU6cdaRF c39Q== X-Forwarded-Encrypted: i=1; AFNElJ9q3cPM6C2z/5qu5VqLL3dR0rhIv+CAaOAfZ4RL5eBjxna+dO51euzSAb9jevHlI827Q+NlPLhHv4I8qV0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzybq07F3ZTQutSLoTwnXdnLLKr9nx29Si6ajowz2cCmMtoJ1vX 8j/RLgUNv3MNWLIf9oWoXZgJ+plOPzmmWwiOM8PhREldw3WPVp2UEtEF X-Gm-Gg: Acq92OG/R4lG1INjGXmmx+b7t+PjNpRCMvRt+cDUpckb/6iJoU//aY88EQNY54A22er woTV0pjEo5WT72o7X+swZPjtAIEMxxW6KCsRQcIw7zLFlGI8r91n9XsLu5jlJQWoYKRHekRYh3T fgupCpobS5M8GYcZaGeQnANJHjlKxjuwVaTeni8QUG70UzECvef8Wtv6P38aWsXAOiMPa1LnBJh bgxTl74yc1yCx1rGH1BRSPAQ4xorTUyV+DGVHM8oEu3uiYMKdV9xKvFOKchIJAkB768hRnwrTQi k9+gwrbgdqGN0QpPhHpPb6EGA7bD7NHJ0NTSPdQJToy2xA65VrNhCJgqwr34H/uBjVUY+d3/X81 qKI3Dwc62TYmmTxaw05Qb2GNPAZFErjydzvelZKrk8HbMpJo/ODzwZfkw06b0i3n9oY70K1Q4l7 wgP84cmArLcd5Is2Jz X-Received: by 2002:a17:903:41cf:b0:2c0:ca93:1303 with SMTP id d9443c01a7336-2c1639ee9e7mr70998755ad.6.1780555361754; Wed, 03 Jun 2026 23:42:41 -0700 (PDT) Received: from lgs.. ([2001:250:5800:1000::f280]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6dc92sm43801515ad.13.2026.06.03.23.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 23:42:41 -0700 (PDT) From: Guangshuo Li To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Simona Vetter , Prike Liang , Sunil Khatri , "Jesse.Zhang" , Lijo Lazar , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li Subject: [PATCH] drm/amdgpu/userq: clean up VA state on create failure Date: Thu, 4 Jun 2026 14:39:43 +0800 Message-ID: <20260604063943.1412955-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-Transfer-Encoding: 8bit amdgpu_userq_input_va_validate() is not a side-effect-free validator. When it succeeds, it allocates a VA cursor, links it on queue->userq_va_list and marks the corresponding bo_va as userq mapped. The user queue create path validates queue_va, rptr_va and wptr_va with a short-circuit OR expression. If an earlier validation succeeds and a later validation fails, the error path frees the queue directly. The VA cursor added by the successful validation is leaked and bo_va->userq_va_mapped remains set even though no user queue was created. The same stale VA tracking state can also survive later create failures after all VA validations have succeeded, because those paths also free the queue without unwinding queue->userq_va_list. Route the create error paths through common unwind labels and call amdgpu_userq_buffer_vas_list_cleanup() before freeing the queue. This releases any VA cursors added during validation and clears the stale userq VA mapping state. Fixes: 9e46b8bb0539 ("drm/amdgpu: validate userq buffer virtual address and size") Signed-off-by: Guangshuo Li --- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index 0a1b93259887..dba0f786ae4a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -826,17 +826,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) amdgpu_userq_input_va_validate(adev, queue, args->in.rptr_va, AMDGPU_GPU_PAGE_SIZE) || amdgpu_userq_input_va_validate(adev, queue, args->in.wptr_va, AMDGPU_GPU_PAGE_SIZE)) { r = -EINVAL; - kfree(queue); - goto unlock; + goto free_queue; } /* Convert relative doorbell offset into absolute doorbell index */ index = amdgpu_userq_get_doorbell_index(uq_mgr, &db_info, filp); if (index == (uint64_t)-EINVAL) { drm_file_err(uq_mgr->file, "Failed to get doorbell for queue\n"); - kfree(queue); r = -EINVAL; - goto unlock; + goto free_queue; } queue->doorbell_index = index; @@ -844,15 +842,14 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) r = amdgpu_userq_fence_driver_alloc(adev, queue); if (r) { drm_file_err(uq_mgr->file, "Failed to alloc fence driver\n"); - goto unlock; + goto free_queue; } r = uq_funcs->mqd_create(queue, &args->in); if (r) { drm_file_err(uq_mgr->file, "Failed to create Queue\n"); amdgpu_userq_fence_driver_free(queue); - kfree(queue); - goto unlock; + goto free_queue; } /* drop this refcount during queue destroy */ @@ -862,21 +859,17 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) down_read(&adev->reset_domain->sem); r = xa_err(xa_store_irq(&adev->userq_doorbell_xa, index, queue, GFP_KERNEL)); if (r) { - kfree(queue); up_read(&adev->reset_domain->sem); - goto unlock; + goto free_queue; } r = xa_alloc(&uq_mgr->userq_xa, &qid, queue, XA_LIMIT(1, AMDGPU_MAX_USERQ_COUNT), GFP_KERNEL); if (r) { drm_file_err(uq_mgr->file, "Failed to allocate a queue id\n"); - amdgpu_userq_fence_driver_free(queue); - uq_funcs->mqd_destroy(queue); - kfree(queue); r = -ENOMEM; up_read(&adev->reset_domain->sem); - goto unlock; + goto free_queue; } up_read(&adev->reset_domain->sem); @@ -892,10 +885,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) if (r) { drm_file_err(uq_mgr->file, "Failed to map Queue\n"); xa_erase(&uq_mgr->userq_xa, qid); - amdgpu_userq_fence_driver_free(queue); - uq_funcs->mqd_destroy(queue); - kfree(queue); - goto unlock; + goto free_queue; } } @@ -915,7 +905,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) args->out.queue_id = qid; atomic_inc(&uq_mgr->userq_count[queue->queue_type]); + goto unlock; +free_mqd: + uq_funcs->mqd_destroy(queue); +free_fence_driver: + amdgpu_userq_fence_driver_free(queue); +free_queue: + amdgpu_userq_buffer_vas_list_cleanup(adev, queue); + kfree(queue); unlock: mutex_unlock(&uq_mgr->userq_mutex); -- 2.43.0