From patchwork Tue Dec 24 07:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 853513 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 2445A18EFDE for ; Tue, 24 Dec 2024 07:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735025098; cv=none; b=UHJ2i9L6BYbSx2XD+r+TJRXzi/WueD0isUdWn9yWbkd/uOi5hXtpDawfURJXEGeXuxiN7BdSMq0J38KNJCvlr2iU5xm+AajznqpdP5nyWoyXfXnVTNgKhyfskc1OfQttxM31+Y33tJF5iHO/lMVt4Jt33qHB8ARO8XaJeamRU1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735025098; c=relaxed/simple; bh=9cZLG5L2vkdEDHKnH31YZBkU40Mvvp2J/3ooo59x45Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c/XZgGF8Ll6boPOFju93Qdmdp3PyLDISajDInatgdhmXMrchBiIk51rDwWBGcwxgwEQRUeO8wGxq6CxNHb8mPmkWNRLzer/GE3kM18QUoM+53dOaOA+96Jk4rL5nNaOV0ss36p3Bw8tbGaS1ILnrDWuapJ6bVj4pqdM78c4e+S8= 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=JB/iyRvo; arc=none smtp.client-ip=209.85.214.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="JB/iyRvo" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21644aca3a0so55870345ad.3 for ; Mon, 23 Dec 2024 23:24:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1735025096; x=1735629896; 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=AE9nvfJslVj9qB/yCOxLUqgILFx3DJwfUeD0T7gDpl8=; b=JB/iyRvo9lcf0AJEefx2I49AOL80+IZ5EHaO8o+bsCBcOJvHOl2xdT/5KHUjWOOTT4 fs4KPmi1M1JvNuaN6PlPVZCIkOYPjBcVoMpRGsffS/3yBXIcbXxnPhKOnnVZO1wTSlVj boKUGTExYAd003Cgpg2d/D8Gj3gngY1dmRNKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735025096; x=1735629896; 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=AE9nvfJslVj9qB/yCOxLUqgILFx3DJwfUeD0T7gDpl8=; b=k9i2c26UI5gUxqOeb+GpDBjkyS5bkzGJDX6KC2e32C2p/LLLSSEKHdPc+NTJhiI1PO y7laFXb08pSkHz0isdiw9FQXuCw8Rczg2f/m2/F12vkzW6CYqe61z/apwS+CUKwzFboi Cc0YSkggej9Hb8o4cT5538zoUlanP1XIoVOf1Ze4Ln8MzlRtcBCLgjAgGUB869AqoKns zhdKIpOj4o17rN57ilB9baGHzH/wYlsCCtAVUh8fRFjsJ4/y+iEmzQCIcYHmZqVdIapZ 2Ji+wAb3lrby4arODf4eT5VVXhE3jtyEstN3PxD9raR44puiPhpCUwmGXJFRXv7lCKhr yXEg== X-Forwarded-Encrypted: i=1; AJvYcCUzdGkVgSEmCd2o9qa9rWLaDHvuixBunmG/GOmL1BP3GRsDU88MPez+/DOOARXtsup3L+XIg6Hts8LImQfe@vger.kernel.org X-Gm-Message-State: AOJu0YzXPigexUWMABehZRXworYL2xu6Q8KiTjuV3ccxwUL2VdI+w9TR gLxA2rTJj/0YY7In8/0F8/yLSZL8FvzS1OntGxYSn4rDlcgHAFRNgLH52YRbSg== X-Gm-Gg: ASbGnct/jZA3nod7ISmicXCWy5RBqta0XbX2HwCFzoWpatJIjM4i/oPQKw1pk8yxrh6 L+YyYBvLBcgdmkRTGWDyaauQvRkpNE6FtoFvNHPMkvPHpX0g8R4jSc01GUU//KsJpWHV6uRxwKA FwFTjiSmld/Ew6efu3V19ZDDQ9gK3QahOwyid9c3J4IHXDoHHcMk2zZ6dSJcgiVYp1DfodLtnuS BEan+HfP/iKIQsFn0mOS55uxBEhvHg6RBW2b6OQb6ZD+0q40eGLmzfd6Qc= X-Google-Smtp-Source: AGHT+IHKoKTL2NIALRxLrphqegLKe8K7HSq2hikZhf5VhPOyutofWJK6Rrh5cMHHc0VdChmeAIfuLw== X-Received: by 2002:a17:902:ccc7:b0:215:94b0:9df4 with SMTP id d9443c01a7336-219e6f283aemr251758405ad.54.1735025096549; Mon, 23 Dec 2024 23:24:56 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:de21:da72:a349:25b2]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-219dca02b77sm84195355ad.242.2024.12.23.23.24.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Dec 2024 23:24:56 -0800 (PST) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia , "Bryan O'Donoghue" , Dmitry Baryshkov Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , stable@vger.kernel.org, Nathan Hebert Subject: [PATCHv3 1/2] media: venus: destroy hfi session after m2m_ctx release Date: Tue, 24 Dec 2024 16:24:05 +0900 Message-ID: <20241224072444.2044956-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241224072444.2044956-1-senozhatsky@chromium.org> References: <20241224072444.2044956-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This partially reverts commit that made hfi_session_destroy() the first step of vdec/venc close(). The reason being is a regression report when, supposedly, encode/decoder is closed with still active streaming (no ->stop_streaming() call before close()) and pending pkts, so isr_thread cannot find instance and fails to process those pending pkts. This was the idea behind the original patch - make it impossible to use instance under destruction, because this is racy, but apparently there are uses cases that depend on that unsafe pattern. Return to the old (unsafe) behaviour for the time being (until a better fix is found). Fixes: 45b1a1b348ec1 ("media: venus: sync with threaded IRQ during inst destruction") Cc: stable@vger.kernel.org Reported-by: Nathan Hebert Signed-off-by: Sergey Senozhatsky --- drivers/media/platform/qcom/venus/core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 2d27c5167246..807487a1f536 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -506,18 +506,14 @@ static __maybe_unused int venus_runtime_suspend(struct device *dev) 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 + * 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); v4l2_ctrl_handler_free(&inst->ctrl_handler); From patchwork Tue Dec 24 07:24:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 853303 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 B3F57191F6D for ; Tue, 24 Dec 2024 07:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735025103; cv=none; b=RQew5Ydabthz07lZz/ZzQLZAgq7lBmDrErRuuvhGGZhMkClKzg4KcTn9LKFoXfVSmMx7OurZdKhXu8iOI4BGmRktRM7jfnOjMmpOIyOqNJYoPJQWZE7usC9IKZK3trJnB8H4gHgLoVtRd2jJjUryEVPoihB+kjy62W3hxkdeQfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735025103; c=relaxed/simple; bh=r71J1XTxvY9JHuEadXJXhCt6MvOmgQqaRuvpY/3Ig64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kj4001G4AmMgrmu7L/aA9Wu0lVkhLPfGeuBznBQ7Ow/Xtjq+VgtFNtcsFcw6QUMcHE7DEbKYjUUQMC4bSWWphK7LFLwaV8LEgOmSY0RIrSugAnSkgQ9mhWTNQp3tzyyPG4onywv+Bo9O/c5TIscWxJSO9VZmyd0LrHHRKEXkkKY= 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=mq4wJk6Q; arc=none smtp.client-ip=209.85.214.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="mq4wJk6Q" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2166651f752so53119875ad.3 for ; Mon, 23 Dec 2024 23:25:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1735025101; x=1735629901; 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=sHCCWOGWVzcRMki9j1D1cT+IzNg+cnlvfL1iBnozW5E=; b=mq4wJk6Qy2lFoc+4YTpEJ92HWYz1HYFG8lGYWvGt+W7uK8ViUM6+054a7XC1zucxwE 7F0BpZeUipnqI7Z09uNSEKtyfjdRLMVJfNnSAeG3oBWdESpDPtli/p0vbUdMqGpx/goC shnQmIRZA82PgrwkImfBJ2JNK59ipCXNff7b8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735025101; x=1735629901; 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=sHCCWOGWVzcRMki9j1D1cT+IzNg+cnlvfL1iBnozW5E=; b=rmePiEex+cZKWP+NDEzO2z1as8LD3NRNbM9qtmWSDz0mx+eqdhsLijEILaH4LCdDLj zWzzyPa4Jwji9xIXwR8eYRaclyhhxJJDlfTe8zkuBLGxuImFwqiVZb9YhaLfYOp6bfwf 4EUfM9ip/p1F3UXbwYZ9Gvmfg9T6ncmnniTIxa7bbtUzUSDWy39LtFmfj8n81grjGGlS uXhjTe9wPb7gQxntakpRS+Z/zY8oj8fCVQcKwuh3teis463NBzp+BWcdWVAUlese7XQI R3TU8bzoIyDkMp7R47aLa01FDBJdzPOL6q6rq7ad8+OFRHO8rWpH48611g0ZZxGTF9n6 LM/A== X-Forwarded-Encrypted: i=1; AJvYcCU9OWZoKtVrjrbtnOXhzLPgNjdE5j5d6oeGvwUYTDxMA3I4q8qAXDiFBF06wq2HgZwhuBMdQqUq1oSKBzs0@vger.kernel.org X-Gm-Message-State: AOJu0YyuKAomuMkRfdvLBDsplDtfGEDA9bSidO1KhXBfa6sRPb7BEXKd grvoEQ49QGaTK73C7bMUI9NoQ3RIx0rbNJvzkwqQY7ikzL8tZm8oP1M0b3e14A== X-Gm-Gg: ASbGncs3ugwybVRtt9r8hcHspsXCjafv2a7XcKAsgYFvnz00NEYRutgolD93qhrESun JCX9Ck2uXFOl6fgp6BRLidlRtBnytaoEvaweeMXPp1Q6Rzic7uhcbwKKLC+tl7g8XhXqgJw3unn 271LV8ijUlj6vKY5GhANABvXzo5FN0BHKzc3cIb4CPQLbAuIuhpsTTmpzW5LDsjOywRC/rQSSwN da6tiap2IG4yhLrtW2kJDi73Vls+a3OU/DnAwQSgpyDLydFSmIgT/ehplA= X-Google-Smtp-Source: AGHT+IGl9hn9Wwz/ecoWpCp/JPrwph2e+noe6flvRfLHj8P+fmm7DzkHqeYBo9FsiUo3Zhh0Rq7K5w== X-Received: by 2002:a05:6a00:4644:b0:728:fab1:eda0 with SMTP id d2e1a72fcca58-72abdebaae0mr20485234b3a.25.1735025100953; Mon, 23 Dec 2024 23:25:00 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:de21:da72:a349:25b2]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72aad830b05sm9038425b3a.52.2024.12.23.23.24.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Dec 2024 23:25:00 -0800 (PST) From: Sergey Senozhatsky To: Stanimir Varbanov , Vikash Garodia , "Bryan O'Donoghue" , Dmitry Baryshkov Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 2/2] media: venus: match instance creation and destruction order Date: Tue, 24 Dec 2024 16:24:06 +0900 Message-ID: <20241224072444.2044956-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241224072444.2044956-1-senozhatsky@chromium.org> References: <20241224072444.2044956-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Match order of instances' initialization in venc_open()/vdec_close() and order of destruction in venus_common_close(). Suggested-by: Bryan O'Donoghue Signed-off-by: Sergey Senozhatsky --- drivers/media/platform/qcom/venus/vdec.c | 18 +++++++++--------- drivers/media/platform/qcom/venus/venc.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 98c22b9f9372..9f82882b77bc 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1697,10 +1697,6 @@ static int vdec_open(struct file *file) if (ret) goto err_free; - ret = hfi_session_create(inst, &vdec_hfi_ops); - if (ret) - goto err_ctrl_deinit; - vdec_inst_init(inst); ida_init(&inst->dpb_ids); @@ -1712,15 +1708,19 @@ static int vdec_open(struct file *file) inst->m2m_dev = v4l2_m2m_init(&vdec_m2m_ops); if (IS_ERR(inst->m2m_dev)) { ret = PTR_ERR(inst->m2m_dev); - goto err_session_destroy; + goto err_ctrl_deinit; } inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); if (IS_ERR(inst->m2m_ctx)) { ret = PTR_ERR(inst->m2m_ctx); - goto err_m2m_release; + goto err_m2m_dev_release; } + ret = hfi_session_create(inst, &vdec_hfi_ops); + if (ret) + goto err_m2m_ctx_release; + v4l2_fh_init(&inst->fh, core->vdev_dec); inst->fh.ctrl_handler = &inst->ctrl_handler; @@ -1730,10 +1730,10 @@ static int vdec_open(struct file *file) return 0; -err_m2m_release: +err_m2m_ctx_release: + v4l2_m2m_ctx_release(inst->m2m_ctx); +err_m2m_dev_release: v4l2_m2m_release(inst->m2m_dev); -err_session_destroy: - hfi_session_destroy(inst); err_ctrl_deinit: v4l2_ctrl_handler_free(&inst->ctrl_handler); err_free: diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index c1c543535aaf..c7f8e37dba9b 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1492,10 +1492,6 @@ static int venc_open(struct file *file) if (ret) goto err_free; - ret = hfi_session_create(inst, &venc_hfi_ops); - if (ret) - goto err_ctrl_deinit; - venc_inst_init(inst); /* @@ -1505,15 +1501,19 @@ static int venc_open(struct file *file) inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); if (IS_ERR(inst->m2m_dev)) { ret = PTR_ERR(inst->m2m_dev); - goto err_session_destroy; + goto err_ctrl_deinit; } inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); if (IS_ERR(inst->m2m_ctx)) { ret = PTR_ERR(inst->m2m_ctx); - goto err_m2m_release; + goto err_m2m_dev_release; } + ret = hfi_session_create(inst, &venc_hfi_ops); + if (ret) + goto err_m2m_ctx_release; + v4l2_fh_init(&inst->fh, core->vdev_enc); inst->fh.ctrl_handler = &inst->ctrl_handler; @@ -1523,10 +1523,10 @@ static int venc_open(struct file *file) return 0; -err_m2m_release: +err_m2m_ctx_release: + v4l2_m2m_ctx_release(inst->m2m_ctx); +err_m2m_dev_release: v4l2_m2m_release(inst->m2m_dev); -err_session_destroy: - hfi_session_destroy(inst); err_ctrl_deinit: v4l2_ctrl_handler_free(&inst->ctrl_handler); err_free: