From nobody Mon Nov 25 19:56:51 2024 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 92B8218C935 for ; Fri, 25 Oct 2024 03:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729828006; cv=none; b=nitEs5NfIP3My/jFoWoiIERulFOYZ6x+s5req1+CajZEdsiNlGbmqH5PQyJkZvq5slLDrp9aNv4IJs3DCV9kcubVOIKhy53sm1vBe6Ida5gQtJfe9GnNrRwR8YzazyeJl9OXFW2EqKMZHhcgky+W7GHTL/pzC2UivGZM2VKJI4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729828006; c=relaxed/simple; bh=RveC5jacooImmHBxMnm+SqvD0OPds08xgXiCC+fcXwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OIgOzwNIpHfc+jsiHTcv9LhXLS3KOewSfY79iyQPFegZoOV2p8DxkBSNy51qJoXWPqkGyx5AT0nahOWLALueqjWiXUVgdNmAH4wFe/86HJaTzQL/jq6b8yB8srLjVtm2ba0JFHN9Fr9Qv2ANvMZPdsXX4JOV8utgojUhwCgGMi0= 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=YwR3rIDx; arc=none smtp.client-ip=209.85.166.53 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="YwR3rIDx" Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-83ab5b4b048so67759639f.2 for ; Thu, 24 Oct 2024 20:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729828002; x=1730432802; 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=YwR3rIDx6H3v5vaAmwICnAPpFKUDKeKxZmJ1a4wiMPJ8UkDOo2imzAW5hpRjDbG26n 6yaSWqwjwlEdRREwCelRyoLxrb3hqiJcImJBT4Wi4QpT+hO1Q/FVaEQedKbA+RbLWSl6 +tnuDboUEYrzAVP24kED6+hFlTjxZ6utLcqh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729828002; x=1730432802; 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=K8uKwjW/JBtN1BD29afubiJuDQcmKfHLwd2cDQVTGXD7tz7awcU52ezJsIfeThWqUd Lf1i31ZyTTI1Q5tT1nWX/0QdnVPSqsBNvDaJ353CKmcK5wKfhuJcqBLUo+m5iraQr+oR axnEX+iVah53/roSLoZge+dcdmedPluKH5N9n4bL3KIZeY1LFDWB0jttY+KdfT51bqal e/stoVxXxaxrQI7DkMp8XEv5mokI61/rFNOFEJNITSsMHKSK+XxgglHltywEAyNVdSh9 5ub1+wXv4NJRkQ3mwCdBuBLwiehySB85RPrkQV1iQY3djTTcFe1irjMdrGBSd5Pon+gL dZvw== X-Forwarded-Encrypted: i=1; AJvYcCXqVLM0jvy4lOUrNjmftyJ3EbD33IeEWRmfrTq/eurVtwFb0vhri0d/RoQkaDKusxF3hYsTnKaV0WJa2lo=@vger.kernel.org X-Gm-Message-State: AOJu0YyiVCZuTmUv/APUZ8119AUXc3Rx1sNc0z7mFv7y+0clq2DADfne LOR4413HhqQf1xkUlh6RU4RhQJdqY76rWXWCoGsvM5EKyKPdakXSc9N8j+3n3w== X-Google-Smtp-Source: AGHT+IGOPFQzDR92JPbaLzlIZmINd7ceSB06dZyb4vu4bdqgz6NHoI1NwRh9nQR+0y/T4/8AO6Q5DQ== X-Received: by 2002:a05:6e02:1b03:b0:3a3:4122:b56e with SMTP id e9e14a558f8ab-3a4de840a0bmr43776365ab.26.1729828002698; Thu, 24 Oct 2024 20:46:42 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:c7f5:2aa6:333b:bb6d]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc8696bbbsm185197a12.49.2024.10.24.20.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:42 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Tomasz Figa Subject: [PATCHv3 1/3] media: venus: fix enc/dec destruction order Date: Fri, 25 Oct 2024 12:46:12 +0900 Message-ID: <20241025034629.660047-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025034629.660047-1-senozhatsky@chromium.org> References: <20241025034629.660047-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 19:56:51 2024 Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (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 17A521B3940 for ; Fri, 25 Oct 2024 03:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729828008; cv=none; b=QoFkSrnX5lYisIjAO9JY4384vustTF4N+QgU1rt+bXxOXjjEyW4JUJrkHBP9wpa64oD/bB1Whua689Akfr+4PLc0oJcRyHyScY9/a/0IdzaO4w9km4jcqh5wCzlt892zj6VzLr2IS8Ru8xbOJ/e/zo/hEi7ndAMXPcUql6jmtTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729828008; c=relaxed/simple; bh=sK3GReGrrBIZCIcruu3To61mhXqDKeErWsYmv/yiG9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HI0h351j6nS83XoQ891IeqESihaFgWQiWBbjlUj2Y2GcFqCkKCuoWpmelSn4209FbCFRZCYlnWqyQpT7JG9wY8CbKxwbyM8ru3Psn6vve6mCRVhBNVg25tC72CT9FFNOYpQm9JLagdI1oC/9QJwNyxIuDEUnUdFULzYqGIRsE58= 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=YRQ2HTMu; arc=none smtp.client-ip=209.85.166.171 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="YRQ2HTMu" Received: by mail-il1-f171.google.com with SMTP id e9e14a558f8ab-3a4e30bffe3so2846715ab.3 for ; Thu, 24 Oct 2024 20:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729828005; x=1730432805; 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=MZm7zndLXna2WAoQucoUjtozEIUfuaspQMegms8BWLo=; b=YRQ2HTMuIkl274RjbOPHdF4O2yyy65Yws84DEz08blJvLOj31oCJL01TKZFXsk4DvK vlh92mRDQghUUp2SF8YMmIsI9cKf9S8sqPhZXxGTznvuGZc/vxOZi4tB55PoRd61UELq YRrOM8vpIFvEKGO6wNQtfQvb+Z1c9r6DR/ZaA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729828005; x=1730432805; 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=MZm7zndLXna2WAoQucoUjtozEIUfuaspQMegms8BWLo=; b=EiAGdOEk1xpLVPXjWRYrqBf3RwIQKtCO3THTvNAsDQcIyrAjDlLeRKArYpL9e3fqY9 bxrAU2Pvrn3CVcRDWMa1z2p8IBML8+iIQQ5r+YuDfRRSLd2MNqnbvRVzhbZqA8bSa9Px v0ir4yrbEoRw50ntMADTvDvbZweFQxYR3Cz+lNTBdI0gaeekAiVDHT4GgHISmCtwzqtw oXg5KDt0ZQ/t07gBzzaXnUplYyLYe/w8N8liKyph13KaRm8sS4+8Pqf1QWl4/7WYBBlQ oEbG3SLCCFfbC5cKNUp4ttNrWc83gNySImu0EP3OorAE7O6xdAbjWagbDxAdGCYP0erL zQ2A== X-Forwarded-Encrypted: i=1; AJvYcCVIGgs6U85nLvlP1t+l9DI/99LfHmX0MuPiP1lgcJUOD1UtXp+sR/tpiRdxnoFhhnAybCUadCvzSC7G0Z4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy67/sWAVE5wDk/uWVGBrNjBIomEoKzJkvJ6vFO2lBF4J5b4CyE /xm9kme+zoPz4qy5JKxj2ZFA17JUiM67A5iHRivvGwBe6plPvd3Nr5Hmkqp95A== X-Google-Smtp-Source: AGHT+IHdcS/vIpN3XVv+OeWemH4WjRZPATqKfxhRmZV7ToHVkIcJIB86Kny1wrH9TtF0foLLESWNUQ== X-Received: by 2002:a05:6e02:17cd:b0:3a3:be8a:8717 with SMTP id e9e14a558f8ab-3a4de7b8c56mr47800925ab.15.1729828005198; Thu, 24 Oct 2024 20:46:45 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:c7f5:2aa6:333b:bb6d]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc8696bbbsm185197a12.49.2024.10.24.20.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:44 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 2/3] media: venus: sync with threaded IRQ during inst destruction Date: Fri, 25 Oct 2024 12:46:13 +0900 Message-ID: <20241025034629.660047-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025034629.660047-1-senozhatsky@chromium.org> References: <20241025034629.660047-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 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 19:56:51 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 A00C51B4F3D for ; Fri, 25 Oct 2024 03:46:48 +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=1729828010; cv=none; b=RUqeBFAfcF6h4LlcwIexAXpg8sAVQd9mLMFd91JBoYVbqKPxBerkYFbeZeFDHk0Mp3/K2T2hLD2sOVHDtdoZFZphHsqOHm6K84PSDELj7B4UqmP5wOLQHYU4mi7jODVn3pXW71UWA9TR/SlRJ4kj1nr78PFvyh0uFAF/SXw6nW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729828010; c=relaxed/simple; bh=QpTD8hxED2wDX3dgk8VKfkgjXuRNcJok9NK/WVr5sVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VlOqAeN6jfI52rB8LjQyvbx807HMJbrWDyXGo9eiND3LUayn+8yQxdQCo8iB9VjrIq/IbAJK5vFQ0+0/AKyfsNib+5KbBRx0K/Y4+6VTH/SqOLxjI8B5tqG32wrfpKu0zQtK0j0tNVWr+nMKI6OPWEFjbohQyy9vN/x6b2GUfb4= 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=NU1GeQtH; 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="NU1GeQtH" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7ea7ad1e01fso1073320a12.0 for ; Thu, 24 Oct 2024 20:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729828008; x=1730432808; 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=YUNQUULke1pyOwStLzAxkmj+PTm04Zh/YHnvRV+y96k=; b=NU1GeQtHZzpmEyZgOSvOSod1WvSvYBx1Yw+Gp463Cw2LU9MyjbLifIaW7GGPD6vrY0 brfk/4lx/feEbBgoNBQa2FwCpL3GRshSxrbh4K0iLXM0XheArECJV/crGVg69lyNPnFw 5LurMuorvlRdKiws5DSDWPh2GMvA7XU11bzNE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729828008; x=1730432808; 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=YUNQUULke1pyOwStLzAxkmj+PTm04Zh/YHnvRV+y96k=; b=J1n3GnsebTHz6EOsnHXYRjnQZqJliaM+qs8WeVdwoiyZywN4LW3N1IxiQRQMeYVHK5 kF70jbrwbLzxzouelkMCeh6xeDOggxJK21tAyhCESfOOndlGUucL2e0Bm2w+JjDhtBWw /SzQEeLHxBiXO5W0ZCYMTlfW9LTUVqVpmdbg1lLe6WNxBCCKNN9782hGsAG4mC1DDvvM LN7LI8sROPoDAG46R6yAxoVNlkqDvbjN5OtLvkie+6KjVtj1do7iBMQQDEyh+wRB3rXM /FB4Suxc52cj0h215iXaZuYhfKSN9AYQdyHuk7aKsPQNRds3nzeDfkTnT374Qiy2y1of 6L5w== X-Forwarded-Encrypted: i=1; AJvYcCVesBa4E+dmxPWA7+1PxzdHfxzoHwOQLhvPhbYJRu9FapHu6oKx1k0gh+SsxkLf6bhITo2Pt7K+nBYbLfY=@vger.kernel.org X-Gm-Message-State: AOJu0YzzHRFUlscuyPERuADQS7p8eN9BrVbpB921UECRNg3dt1KziV4d vzkdUXWf/Y9x8nNQEa64Og6TNGFVN+VsAbJvZkT5I7wfnrKcs/AljzfcF2WpoA== X-Google-Smtp-Source: AGHT+IFvKAIEa9lu3NCBQ0y43n0tV2Gk5ztEQyDc1ntixz7J4b7NasqBqla8ruzfugcdmaFPPgyA5w== X-Received: by 2002:a05:6a20:1589:b0:1d4:e40b:3de6 with SMTP id adf61e73a8af0-1d98898dd86mr6793335637.16.1729828007834; Thu, 24 Oct 2024 20:46:47 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:c7f5:2aa6:333b:bb6d]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc8696bbbsm185197a12.49.2024.10.24.20.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:47 -0700 (PDT) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 3/3] media: venus: factor out inst destruction routine Date: Fri, 25 Oct 2024 12:46:14 +0900 Message-ID: <20241025034629.660047-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025034629.660047-1-senozhatsky@chromium.org> References: <20241025034629.660047-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 --- drivers/media/platform/qcom/venus/core.c | 25 +++++++++++++++++++ drivers/media/platform/qcom/venus/core.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 22 +--------------- drivers/media/platform/qcom/venus/vdec.h | 7 +++++- .../media/platform/qcom/venus/vdec_ctrls.c | 6 ----- drivers/media/platform/qcom/venus/venc.c | 22 +--------------- 6 files changed, 35 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platf= orm/qcom/venus/core.c index 423deb5e94dc..4d90fc1c21fe 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -26,6 +26,7 @@ #include "firmware.h" #include "pm_helpers.h" #include "hfi_venus_io.h" +#include "vdec.h" =20 static void venus_coredump(struct venus_core *core) { @@ -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); + vdec_ctrl_deinit(inst); + + 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..9a680402c711 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -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..2687255b1616 100644 --- a/drivers/media/platform/qcom/venus/vdec.h +++ b/drivers/media/platform/qcom/venus/vdec.h @@ -6,9 +6,14 @@ #ifndef __VENUS_VDEC_H__ #define __VENUS_VDEC_H__ =20 +#include + struct venus_inst; =20 int vdec_ctrl_init(struct venus_inst *inst); -void vdec_ctrl_deinit(struct venus_inst *inst); +static inline void vdec_ctrl_deinit(struct venus_inst *inst) +{ + v4l2_ctrl_handler_free(&inst->ctrl_handler); +} =20 #endif diff --git a/drivers/media/platform/qcom/venus/vdec_ctrls.c b/drivers/media= /platform/qcom/venus/vdec_ctrls.c index 7e0f29bf7fae..fa034a7fdbed 100644 --- a/drivers/media/platform/qcom/venus/vdec_ctrls.c +++ b/drivers/media/platform/qcom/venus/vdec_ctrls.c @@ -4,7 +4,6 @@ * Copyright (C) 2017 Linaro Ltd. */ #include -#include =20 #include "core.h" #include "helpers.h" @@ -187,8 +186,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..2ae22ba156bb 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -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); --=20 2.47.0.163.g1226f6d8fa-goog