From nobody Mon Nov 25 16:48:39 2024 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 664211FB8BC for ; Fri, 25 Oct 2024 16:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875427; cv=none; b=OTlAMIRC72N4OmyU2MEEAR6BshHryGCd0xFK3fRAcpWl6J0uhaUiHlpPOnXq0bNJ+AMj08WcrnFCJAXGaalmA3bUQq9+EjOl2xufSH4gwbiFAwNXV1KLkA19iJq7WUrJgr/iECDqeZfSkDpxLloZpbib3OA9Fl6+kdMHiAXX5Hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875427; c=relaxed/simple; bh=RveC5jacooImmHBxMnm+SqvD0OPds08xgXiCC+fcXwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eb2wtBy2KJ3ukwcc21NW2t3GFuGLZnuN3Zimqklcj0wuLugV9Qu2ckM3USGxTwo6PB7FY7r/PI4TTfgXq1kWoK3rD8YT3Iv51p7jQCVL3fK53eJSbHWKMIJbjGKsdvNRn5S76DmOsZyBDAeTUlCmwhrNOXKDHHgPSbr7GxygkMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=dJC9tfZh; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dJC9tfZh" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7ea8de14848so1334099a12.2 for ; Fri, 25 Oct 2024 09:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729875425; x=1730480225; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8O+PQVPJ/vy+FUOPeA37d+cZZmUqt00r3pyhnqMSbPI=; b=dJC9tfZhS44WzqmnZqrGmUI34HmmcNlOYfKOhXa/vgD5xaLwbouWc0xz9+HAVMPGAm 7ybH9WQiZJdm+W9Pr9v3f6EBwPIatQKZTAIVDr7qYJ21O4uAiGzEq/BfFQbk/GoQ1jll p/Gl9uAvBAgZrEIm7kk3xU0OTXaa+xd64QY2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729875425; x=1730480225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8O+PQVPJ/vy+FUOPeA37d+cZZmUqt00r3pyhnqMSbPI=; b=lr6PFbZgywLhznUFj7UbfGec9wpsNAvj+BnBVUOoYMSAGRdoeb+FML6JAmYAacSZC/ EK8H6zcijZJJGE/ijDhi4aZ6CMIDKVyVqGyQGsnct+hYKFTasP518oVtohn+CnJogwVP UtqlXgGOUiP2yjwOR3/RS8vjyahaCVs50Hr0egFqVJIjXO99sKlggwWm3osNdbQERP3r eoPi21oFZXu2dS52USHKAW/wNbiTI5FNqVXDdaQU0nBwalhG8BSPW8gNo07sabbCQq9y pGO/yNzo5CvFghYfJeUa1SCHWN55ZEzkmRKfChkvQKzl12RjMwflg4Y3IUhg9v3IRbNv 8/fA== X-Forwarded-Encrypted: i=1; AJvYcCWTb4+M4Q7CSiwm0oAJnLRY8xhClVHjDpJ29tkVtiZutWZyT8gFtCHercfdRMPq2KaAcYsGMSrptfqQX8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxDtkMJdJTvVvkeOR278nhcPwllN8ZlE3wQHe8uZmra88dbAItP QIRNO+QN2HRpyXH1QstSogY6ojQeWkQLewGBbD7OIp1UHCWyytRdNzMlyJjYiw== X-Google-Smtp-Source: AGHT+IH7rfguzduKr1bcBWzJK7+v3a3TINoVQscqXJeQZUt3/8c4xIaOMv18ZR2WsqaNoVrM7t4Llw== X-Received: by 2002:a05:6a20:9f45:b0:1d9:111f:4b46 with SMTP id adf61e73a8af0-1d978b14665mr12866841637.12.1729875424739; Fri, 25 Oct 2024 09:57:04 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:bd37:bccf:f3e:a9ef]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7205791db5fsm1318970b3a.11.2024.10.25.09.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 09:57:04 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia Cc: Dikshita Agarwal , Bryan O'Donoghue , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Tomasz Figa Subject: [PATCHv6 1/3] media: venus: fix enc/dec destruction order Date: Sat, 26 Oct 2024 01:56:41 +0900 Message-ID: <20241025165656.778282-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025165656.778282-1-senozhatsky@chromium.org> References: <20241025165656.778282-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We destroy mutex-es too early as they are still taken in v4l2_fh_exit()->v4l2_event_unsubscribe()->v4l2_ctrl_find(). We should destroy mutex-es right before kfree(). Also do not vdec_ctrl_deinit() before v4l2_fh_exit(). Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files") Suggested-by: Tomasz Figa Signed-off-by: Sergey Senozhatsky Reviewed-by: Bryan O'Donoghue --- drivers/media/platform/qcom/venus/vdec.c | 7 ++++--- drivers/media/platform/qcom/venus/venc.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platf= orm/qcom/venus/vdec.c index 6252a6b3d4ba..0013c4704f03 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1752,13 +1752,14 @@ static int vdec_close(struct file *file) cancel_work_sync(&inst->delayed_process_work); v4l2_m2m_ctx_release(inst->m2m_ctx); v4l2_m2m_release(inst->m2m_dev); - vdec_ctrl_deinit(inst); ida_destroy(&inst->dpb_ids); hfi_session_destroy(inst); - mutex_destroy(&inst->lock); - mutex_destroy(&inst->ctx_q_lock); v4l2_fh_del(&inst->fh); v4l2_fh_exit(&inst->fh); + vdec_ctrl_deinit(inst); + + mutex_destroy(&inst->lock); + mutex_destroy(&inst->ctx_q_lock); =20 vdec_pm_put(inst, false); =20 diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platf= orm/qcom/venus/venc.c index 322a7737e2c7..6a26a6592424 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1519,14 +1519,14 @@ static int venc_close(struct file *file) =20 v4l2_m2m_ctx_release(inst->m2m_ctx); v4l2_m2m_release(inst->m2m_dev); - venc_ctrl_deinit(inst); hfi_session_destroy(inst); - mutex_destroy(&inst->lock); - mutex_destroy(&inst->ctx_q_lock); v4l2_fh_del(&inst->fh); v4l2_fh_exit(&inst->fh); + venc_ctrl_deinit(inst); =20 inst->enc_state =3D VENUS_ENC_STATE_DEINIT; + mutex_destroy(&inst->lock); + mutex_destroy(&inst->ctx_q_lock); =20 venc_pm_put(inst, false); =20 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 16:48:39 2024 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.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 E52AC20BB25 for ; Fri, 25 Oct 2024 16:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875430; cv=none; b=e0UKzLOUrbOp2/JJu9v3LZVR7aA0vgCYquoKF/RJdBwWARflM2CKlbAt6CcL0MkV/I2dQhaDFeU8o5e3EFIvVA5xud7obsva4KvzA+0bQIs/hS9dH+lOgx8OJgGZPptn0hft2PY0AYMzDlXLO/3e2tfOFjHOW+HjT84KfDUF0J8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875430; c=relaxed/simple; bh=bECNK6QwMba2Wqz2Ig6wjaW/pLjHaSwRnO7nvbae2bI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mSLIa3NTkt0MU57xJ8x52ljXNCNrxJhc9lca0o+fyWpXpr9YAVZO6EF7qKwIeimqCeMbxhFKLXqwlGlT4OErjP+hQW/NhfudrIk7c47fmOGuJoL/sOsl9hKsXGXIqtTUveG5mHMouNAx5XaXdxoTL8LWkqX0l6+Xr02D2DkEt0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=hcVIrHic; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hcVIrHic" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71ec12160f6so1611678b3a.3 for ; Fri, 25 Oct 2024 09:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729875427; x=1730480227; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gjW2cH/z7fgu+oD0u4Z3vPb6pLQlEe4zR/etcao0t7A=; b=hcVIrHicAVQcVpXcGTtMMcZoeQ0N7A96cDBJvBotABpvSZQZ73QLIYOd/egfkktwQa btHq6D2vNs7KztOInt/zbMkbdtXwtqLNS5ZSEaAg4E82p46mCKrY3Pa9ZMfuPKzsskuY qH5qbY6b+P9KBYHQ/X2WVQFrrkJPdZhOCPIdA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729875427; x=1730480227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gjW2cH/z7fgu+oD0u4Z3vPb6pLQlEe4zR/etcao0t7A=; b=FDBHUcJHhUj1W+ELSKlsXZ3IVFGoAnYuxzUOlg7Estx/Mt6q0AHumQqfOe8j+nrxfh IgyG56E9jJa244DQ9FBV0eA2xkiPQPwPvDU/TxHbUZ3obzojcUSmqCaMdoI++QlaLAQ/ BDsSjJrdXI/jSVAaKwQndov24zkO+SYDUtIkYyrlpXf6/V3HqcnWY6NwYq5hoJt+T19E la3S91Hev342sV0Qcwizb7vArlSnRkLwz9EU+Ro9YDK8y9JdxCoLmm/pa61eml/6SqVQ N67CxGLd1bUVIScJIUGNiAuNPsHmosxF+OZZTD/65nQGhigXxbC9Wmmwgw6lxLGvTWpX r5rA== X-Forwarded-Encrypted: i=1; AJvYcCVmAoi7Xmu97pvhpPEC0Vazxmn7IuGwN50TWROMh6FY8utWRvCmDSrNFJaL3FVy52cW5GDhr0YauBRE0qg=@vger.kernel.org X-Gm-Message-State: AOJu0YzQKojfJKv198+PPrdUOTfEnhkFm610tolbGHr5LAJ/+nE3gZmH y5hrf8cJmfiAleWp/bAvxZstOcAmfyWW5RHMGgg3bTwhemv107QifxywHTfkh81Ur9G+1bO+Inw = X-Google-Smtp-Source: AGHT+IEUiyLyvMrLtopKskNATR7KA0DR+kuqA2bjgdmXLbsHPU/pN/ntoNwqTWgJ5Sa0f+/64i+m+Q== X-Received: by 2002:a05:6a00:4606:b0:71e:68ae:aae1 with SMTP id d2e1a72fcca58-72063028d99mr249463b3a.19.1729875427268; Fri, 25 Oct 2024 09:57:07 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:bd37:bccf:f3e:a9ef]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7205791db5fsm1318970b3a.11.2024.10.25.09.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 09:57:06 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia Cc: Dikshita Agarwal , Bryan O'Donoghue , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv6 2/3] media: venus: sync with threaded IRQ during inst destruction Date: Sat, 26 Oct 2024 01:56:42 +0900 Message-ID: <20241025165656.778282-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025165656.778282-1-senozhatsky@chromium.org> References: <20241025165656.778282-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When destroying an inst we should make sure that we don't race against threaded IRQ (or pending IRQ), otherwise we can concurrently kfree() inst context and inst itself. BUG: KASAN: slab-use-after-free in vb2_queue_error+0x80/0x90 Call trace: dump_backtrace+0x1c4/0x1f8 show_stack+0x38/0x60 dump_stack_lvl+0x168/0x1f0 print_report+0x170/0x4c8 kasan_report+0x94/0xd0 __asan_report_load2_noabort+0x20/0x30 vb2_queue_error+0x80/0x90 venus_helper_vb2_queue_error+0x54/0x78 venc_event_notify+0xec/0x158 hfi_event_notify+0x878/0xd20 hfi_process_msg_packet+0x27c/0x4e0 venus_isr_thread+0x258/0x6e8 hfi_isr_thread+0x70/0x90 venus_isr_thread+0x34/0x50 irq_thread_fn+0x88/0x130 irq_thread+0x160/0x2c0 kthread+0x294/0x328 ret_from_fork+0x10/0x20 Allocated by task 20291: kasan_set_track+0x4c/0x80 kasan_save_alloc_info+0x28/0x38 __kasan_kmalloc+0x84/0xa0 kmalloc_trace+0x7c/0x98 v4l2_m2m_ctx_init+0x74/0x280 venc_open+0x444/0x6d0 v4l2_open+0x19c/0x2a0 chrdev_open+0x374/0x3f0 do_dentry_open+0x710/0x10a8 vfs_open+0x88/0xa8 path_openat+0x1e6c/0x2700 do_filp_open+0x1a4/0x2e0 do_sys_openat2+0xe8/0x508 do_sys_open+0x15c/0x1a0 __arm64_sys_openat+0xa8/0xc8 invoke_syscall+0xdc/0x270 el0_svc_common+0x1ec/0x250 do_el0_svc+0x54/0x70 el0_svc+0x50/0xe8 el0t_64_sync_handler+0x48/0x120 el0t_64_sync+0x1a8/0x1b0 Freed by task 20291: kasan_set_track+0x4c/0x80 kasan_save_free_info+0x3c/0x60 ____kasan_slab_free+0x124/0x1a0 __kasan_slab_free+0x18/0x28 __kmem_cache_free+0x134/0x300 kfree+0xc8/0x1a8 v4l2_m2m_ctx_release+0x44/0x60 venc_close+0x78/0x130 [venus_enc] v4l2_release+0x20c/0x2f8 __fput+0x328/0x7f0 ____fput+0x2c/0x48 task_work_run+0x1e0/0x280 get_signal+0xfb8/0x1190 do_notify_resume+0x34c/0x16a8 el0_svc+0x9c/0xe8 el0t_64_sync_handler+0x48/0x120 el0t_64_sync+0x1a8/0x1b0 Rearrange inst destruction. First remove the inst from the core->instances list, second synchronize IRQ/IRQ-thread to make sure that nothing else would see the inst while we take it down. Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files") Signed-off-by: Sergey Senozhatsky Reviewed-by: Bryan O'Donoghue --- drivers/media/platform/qcom/venus/vdec.c | 12 +++++++++++- drivers/media/platform/qcom/venus/venc.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platf= orm/qcom/venus/vdec.c index 0013c4704f03..b3192a36f388 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1750,10 +1750,20 @@ static int vdec_close(struct file *file) vdec_pm_get(inst); =20 cancel_work_sync(&inst->delayed_process_work); + /* + * First, remove the inst from the ->instances list, so that + * to_instance() will return NULL. + */ + hfi_session_destroy(inst); + /* + * Second, make sure we don't have IRQ/IRQ-thread currently running + * or pending execution, which would race with the inst destruction. + */ + synchronize_irq(inst->core->irq); + v4l2_m2m_ctx_release(inst->m2m_ctx); v4l2_m2m_release(inst->m2m_dev); ida_destroy(&inst->dpb_ids); - hfi_session_destroy(inst); v4l2_fh_del(&inst->fh); v4l2_fh_exit(&inst->fh); vdec_ctrl_deinit(inst); diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platf= orm/qcom/venus/venc.c index 6a26a6592424..36981ce448f5 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1517,9 +1517,19 @@ static int venc_close(struct file *file) =20 venc_pm_get(inst); =20 + /* + * First, remove the inst from the ->instances list, so that + * to_instance() will return NULL. + */ + hfi_session_destroy(inst); + /* + * Second, make sure we don't have IRQ/IRQ-thread currently running + * or pending execution, which would race with the inst destruction. + */ + synchronize_irq(inst->core->irq); + v4l2_m2m_ctx_release(inst->m2m_ctx); v4l2_m2m_release(inst->m2m_dev); - hfi_session_destroy(inst); v4l2_fh_del(&inst->fh); v4l2_fh_exit(&inst->fh); venc_ctrl_deinit(inst); --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 16:48:39 2024 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 95F7E20BB52 for ; Fri, 25 Oct 2024 16:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875432; cv=none; b=H6cm3I1C8hGNS5mdfEUQ5m4C5S9Nzv4RbUaWvqA28K+Ksm2NR7wjedoebaEDTW100AWXaDcZnWjBXlLqze6y8Ug5Fgj0I4Uylp/5qCNWWfJ6BjLBFl92dXb2gVY249Un+j/Iqr4idrnbtX/1+EqpFZ3kJcF1k9MYEjpfOIzTf6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729875432; c=relaxed/simple; bh=J/203IJWqybElMqVqw6BbzRbXrAvsQIbHr2j66uKx5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u7CUbZvLNVUuVFvyGx04/om1aMCU2BaMn1Wbp+q2ulKNSmqHw67YTXI46stIG8w0UDzaCw3l7dYcTivpTHX7Zof2ztzRFFBMp818i0QbMvhPA5ys8XvjyulHeam+b1gf+re7z9/nKNAausUd0dhJv74HAmTFI/bmzwxWcvuE9xs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Mxs6pVxQ; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Mxs6pVxQ" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-71e5ae69880so1583413b3a.2 for ; Fri, 25 Oct 2024 09:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729875430; x=1730480230; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5ERiY9G8dmIZsrZBWXNP+uvBiLRuBPY/kGmlm2qUoyA=; b=Mxs6pVxQuojTPj7jQ8yc9cvyqGcXOf5ARpj3kwNzDNiswFluueOlONBFnZ00IvL+4y XftmVQWU0N9dR+Gtkl3P8BRt3UXJXQYTnaTvyLyp1dOCe59gW4z0dXMNfIh4WMYALupn DqZEwqS2pkonmrEmpufbeEcHSRVXorq90h3Ts= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729875430; x=1730480230; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5ERiY9G8dmIZsrZBWXNP+uvBiLRuBPY/kGmlm2qUoyA=; b=e4K8vberzFDE0TobF17mJqxDwjx8PUHdEuzM7ccv39jov9JG2avvTnwVla24e6ghm3 VA/9k2AuJhWktkiLNR9d9s08EGZWxqK4F6QwqCgmKx+pSytyOwwjmtTF2xhhE+o+0Gqy wcjQpxURFNk4mmgX0Ze+meYs3SLonoJkClJZJ/4Ul8FmYz0KLTBYBU98e5oePXDy7I4V TFYamZgEaBPSKPepv0Ho90ra53+UynXY9DvD2DTj8Y/kxa9+njSoJxW5m4vxbXMcl3TN yaC7arOz3qcuMu/70IKnkXDqnnyMFKzIcRIswgi1IW3Q8mhsSuAm8mfhZWjzl4kqR8yE kgfw== X-Forwarded-Encrypted: i=1; AJvYcCXJAxtuHHe1S/nbHHl/IYjbsrY9FLrGVdsrGxdogUpiH7Ss1XqbcFYodz/g1iRmzbEAgv5hJ2iRDAwfO1c=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8WJWDZvbEP41AZqwuU0Zls5rYTq3HAHbTA7MMWvL8mAScHU+J 3vIEHFFJeBCevn60oRDKuTxO3YGjn8w3vM51/wv0LXLQMYJPuLHLJ2leNf+S6Q== X-Google-Smtp-Source: AGHT+IHT4VDxjmjOpU+jhqbokf98K9LDw93NZaNyC0fxX/vEGdUIqLKzWfI+XT5sCvubncdLNVEPhQ== X-Received: by 2002:a05:6a00:18a3:b0:71e:6fcb:7688 with SMTP id d2e1a72fcca58-7206309804bmr221030b3a.25.1729875429847; Fri, 25 Oct 2024 09:57:09 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:bd37:bccf:f3e:a9ef]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7205791db5fsm1318970b3a.11.2024.10.25.09.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 09:57:09 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia Cc: Dikshita Agarwal , Bryan O'Donoghue , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv6 3/3] media: venus: factor out inst destruction routine Date: Sat, 26 Oct 2024 01:56:43 +0900 Message-ID: <20241025165656.778282-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025165656.778282-1-senozhatsky@chromium.org> References: <20241025165656.778282-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out common instance destruction code into a common function. Suggested-by: Bryan O'Donoghue Signed-off-by: Sergey Senozhatsky Reviewed-by: Bryan O'Donoghue --- drivers/media/platform/qcom/venus/core.c | 25 +++++++++++++++++++ drivers/media/platform/qcom/venus/core.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 24 ++---------------- drivers/media/platform/qcom/venus/vdec.h | 1 - .../media/platform/qcom/venus/vdec_ctrls.c | 5 ---- drivers/media/platform/qcom/venus/venc.c | 24 ++---------------- drivers/media/platform/qcom/venus/venc.h | 1 - .../media/platform/qcom/venus/venc_ctrls.c | 5 ---- 8 files changed, 31 insertions(+), 56 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platf= orm/qcom/venus/core.c index 423deb5e94dc..ee6c2051a0c4 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include =20 @@ -502,6 +503,30 @@ static __maybe_unused int venus_runtime_suspend(struct= device *dev) return ret; } =20 +void venus_close_common(struct venus_inst *inst) +{ + /* + * First, remove the inst from the ->instances list, so that + * to_instance() will return NULL. + */ + hfi_session_destroy(inst); + /* + * Second, make sure we don't have IRQ/IRQ-thread currently running + * or pending execution, which would race with the inst destruction. + */ + synchronize_irq(inst->core->irq); + + v4l2_m2m_ctx_release(inst->m2m_ctx); + v4l2_m2m_release(inst->m2m_dev); + v4l2_fh_del(&inst->fh); + v4l2_fh_exit(&inst->fh); + v4l2_ctrl_handler_free(&inst->ctrl_handler); + + mutex_destroy(&inst->lock); + mutex_destroy(&inst->ctx_q_lock); +} +EXPORT_SYMBOL_GPL(venus_close_common); + static __maybe_unused int venus_runtime_resume(struct device *dev) { struct venus_core *core =3D dev_get_drvdata(dev); diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platf= orm/qcom/venus/core.h index 435325432922..7bb36a270e15 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -560,4 +560,6 @@ is_fw_rev_or_older(struct venus_core *core, u32 vmajor,= u32 vminor, u32 vrev) (core)->venus_ver.minor =3D=3D vminor && (core)->venus_ver.rev <=3D vrev); } + +void venus_close_common(struct venus_inst *inst); #endif diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platf= orm/qcom/venus/vdec.c index b3192a36f388..cba95dc492f1 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1737,7 +1737,7 @@ static int vdec_open(struct file *file) err_session_destroy: hfi_session_destroy(inst); err_ctrl_deinit: - vdec_ctrl_deinit(inst); + v4l2_ctrl_handler_free(&inst->ctrl_handler); err_free: kfree(inst); return ret; @@ -1748,29 +1748,9 @@ static int vdec_close(struct file *file) struct venus_inst *inst =3D to_inst(file); =20 vdec_pm_get(inst); - cancel_work_sync(&inst->delayed_process_work); - /* - * First, remove the inst from the ->instances list, so that - * to_instance() will return NULL. - */ - hfi_session_destroy(inst); - /* - * Second, make sure we don't have IRQ/IRQ-thread currently running - * or pending execution, which would race with the inst destruction. - */ - synchronize_irq(inst->core->irq); - - v4l2_m2m_ctx_release(inst->m2m_ctx); - v4l2_m2m_release(inst->m2m_dev); + venus_close_common(inst); ida_destroy(&inst->dpb_ids); - v4l2_fh_del(&inst->fh); - v4l2_fh_exit(&inst->fh); - vdec_ctrl_deinit(inst); - - mutex_destroy(&inst->lock); - mutex_destroy(&inst->ctx_q_lock); - vdec_pm_put(inst, false); =20 kfree(inst); diff --git a/drivers/media/platform/qcom/venus/vdec.h b/drivers/media/platf= orm/qcom/venus/vdec.h index 6b262d0bf561..0cf981108ff0 100644 --- a/drivers/media/platform/qcom/venus/vdec.h +++ b/drivers/media/platform/qcom/venus/vdec.h @@ -9,6 +9,5 @@ struct venus_inst; =20 int vdec_ctrl_init(struct venus_inst *inst); -void vdec_ctrl_deinit(struct venus_inst *inst); =20 #endif diff --git a/drivers/media/platform/qcom/venus/vdec_ctrls.c b/drivers/media= /platform/qcom/venus/vdec_ctrls.c index 7e0f29bf7fae..36ed955b0419 100644 --- a/drivers/media/platform/qcom/venus/vdec_ctrls.c +++ b/drivers/media/platform/qcom/venus/vdec_ctrls.c @@ -187,8 +187,3 @@ int vdec_ctrl_init(struct venus_inst *inst) =20 return 0; } - -void vdec_ctrl_deinit(struct venus_inst *inst) -{ - v4l2_ctrl_handler_free(&inst->ctrl_handler); -} diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platf= orm/qcom/venus/venc.c index 36981ce448f5..b9940da73772 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1505,7 +1505,7 @@ static int venc_open(struct file *file) err_session_destroy: hfi_session_destroy(inst); err_ctrl_deinit: - venc_ctrl_deinit(inst); + v4l2_ctrl_handler_free(&inst->ctrl_handler); err_free: kfree(inst); return ret; @@ -1516,28 +1516,8 @@ static int venc_close(struct file *file) struct venus_inst *inst =3D to_inst(file); =20 venc_pm_get(inst); - - /* - * First, remove the inst from the ->instances list, so that - * to_instance() will return NULL. - */ - hfi_session_destroy(inst); - /* - * Second, make sure we don't have IRQ/IRQ-thread currently running - * or pending execution, which would race with the inst destruction. - */ - synchronize_irq(inst->core->irq); - - v4l2_m2m_ctx_release(inst->m2m_ctx); - v4l2_m2m_release(inst->m2m_dev); - v4l2_fh_del(&inst->fh); - v4l2_fh_exit(&inst->fh); - venc_ctrl_deinit(inst); - + venus_close_common(inst); inst->enc_state =3D VENUS_ENC_STATE_DEINIT; - mutex_destroy(&inst->lock); - mutex_destroy(&inst->ctx_q_lock); - venc_pm_put(inst, false); =20 kfree(inst); diff --git a/drivers/media/platform/qcom/venus/venc.h b/drivers/media/platf= orm/qcom/venus/venc.h index 4ea37fdcd9b8..719d0f73b14b 100644 --- a/drivers/media/platform/qcom/venus/venc.h +++ b/drivers/media/platform/qcom/venus/venc.h @@ -9,6 +9,5 @@ struct venus_inst; =20 int venc_ctrl_init(struct venus_inst *inst); -void venc_ctrl_deinit(struct venus_inst *inst); =20 #endif diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media= /platform/qcom/venus/venc_ctrls.c index d9d2a293f3ef..c6d1d3675466 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -635,8 +635,3 @@ int venc_ctrl_init(struct venus_inst *inst) v4l2_ctrl_handler_free(&inst->ctrl_handler); return ret; } - -void venc_ctrl_deinit(struct venus_inst *inst) -{ - v4l2_ctrl_handler_free(&inst->ctrl_handler); -} --=20 2.47.0.163.g1226f6d8fa-goog