Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1988932pxa; Thu, 6 Aug 2020 23:26:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz5beIYAcVLOhzfc6jrs4wqpaHWm+UNAGf35NwfKZQw2aLp6LT3EnlmcqGFSKDmmftXNst X-Received: by 2002:aa7:c889:: with SMTP id p9mr7528374eds.105.1596781584921; Thu, 06 Aug 2020 23:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596781584; cv=none; d=google.com; s=arc-20160816; b=wZu3OjTx/iwZ2bfXI73/YMLU/iqbXYyH4x4N/EUZvzXExpgkX5F8HIEFr/dBghvKgG sGSSd+LvsQknYFNInzDpgG9ZFX/9f+IM7xbM7+F5YFQGp7Kic81mElPq2nCsNZHXd+II yadtaArMVNHYB3U9+emhhH0McmLFjV7yMY17wBas4r2AVK2uvpN1/eaTTAqf2ISYm+T6 sLqT8caq2wv6YVISzxd9T9uuND8bp7rRs2WLRO4GfowqfFM6Pfcf9l2NMxjp5wohBNWh O0R34io6hqsB1dD4hZe+vsm4T/AvTui5r7BzK74b/tTtJStuYJrE8X/AugdRunKpMbU3 lpew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BqgqbcoO5/vw9aeBlq0HHq9qt0e00mXST3DxdXbjGv0=; b=J6lV/fP8AvosmMXS0H+SrAGcE8tuthMWb9BRf2wMSX1KmDUCFIagjyOgJZ5816Z3Zs trxZTWUV7VDJj8KdFtJXVJqVopoukfjzrLR/Ol2srlcs8Ofn+bNAY6pyiw2P2l68+pkL rCx7DfynQNoRBJfhKniW+hNifVgWTG+Es3n7x1MlCBU/hxWp0OW4rqBx/m5yAzVuNVVB BMkArcLQyrZe0oAuq7vrZURXJUi/zRsQ0BTkKPJ5qtnaFIY6IFkx7tMv0++DYjGQ9NnM QuHmn/kToNcLZZf84FbCLJq6ujG8XiQ2gfkT7nVRu65Y5XjBGQCEOSFBKyZRNpogB3e6 3YEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si4903056ejc.134.2020.08.06.23.26.02; Thu, 06 Aug 2020 23:26:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726624AbgHGGZO (ORCPT + 99 others); Fri, 7 Aug 2020 02:25:14 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:62166 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbgHGGZD (ORCPT ); Fri, 7 Aug 2020 02:25:03 -0400 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 06 Aug 2020 23:25:03 -0700 Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 06 Aug 2020 23:25:02 -0700 Received: from c-mansur-linux.qualcomm.com ([10.204.90.208]) by ironmsg01-blr.qualcomm.com with ESMTP; 07 Aug 2020 11:54:50 +0530 Received: by c-mansur-linux.qualcomm.com (Postfix, from userid 461723) id 06DEA21C70; Fri, 7 Aug 2020 11:54:49 +0530 (IST) From: Mansur Alisha Shaik To: linux-media@vger.kernel.org, stanimir.varbanov@linaro.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org, Mansur Alisha Shaik Subject: [RESEND 1/3] venus: core: handle race condititon for core ops Date: Fri, 7 Aug 2020 11:54:36 +0530 Message-Id: <1596781478-12216-2-git-send-email-mansur@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1596781478-12216-1-git-send-email-mansur@codeaurora.org> References: <1596781478-12216-1-git-send-email-mansur@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For core ops we are having only write protect but there is no read protect, because of this in multthreading and concurrency, one CPU core is reading without wait which is causing the NULL pointer dereferece crash. one such scenario is as show below, where in one core core->ops becoming NULL and in another core calling core->ops->session_init(). CPU: core-7: Call trace: hfi_session_init+0x180/0x1dc [venus_core] vdec_queue_setup+0x9c/0x364 [venus_dec] vb2_core_reqbufs+0x1e4/0x368 [videobuf2_common] vb2_reqbufs+0x4c/0x64 [videobuf2_v4l2] v4l2_m2m_reqbufs+0x50/0x84 [v4l2_mem2mem] v4l2_m2m_ioctl_reqbufs+0x2c/0x38 [v4l2_mem2mem] v4l_reqbufs+0x4c/0x5c __video_do_ioctl+0x2b0/0x39c CPU: core-0: Call trace: venus_shutdown+0x98/0xfc [venus_core] venus_sys_error_handler+0x64/0x148 [venus_core] process_one_work+0x210/0x3d0 worker_thread+0x248/0x3f4 kthread+0x11c/0x12c Signed-off-by: Mansur Alisha Shaik --- drivers/media/platform/qcom/venus/core.c | 2 +- drivers/media/platform/qcom/venus/hfi.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 203c653..fe99c83 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -64,8 +64,8 @@ static void venus_sys_error_handler(struct work_struct *work) pm_runtime_get_sync(core->dev); hfi_core_deinit(core, true); - hfi_destroy(core); mutex_lock(&core->lock); + hfi_destroy(core); venus_shutdown(core); pm_runtime_put_sync(core->dev); diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c index a211eb9..2eeb31f 100644 --- a/drivers/media/platform/qcom/venus/hfi.c +++ b/drivers/media/platform/qcom/venus/hfi.c @@ -195,7 +195,7 @@ EXPORT_SYMBOL_GPL(hfi_session_create); int hfi_session_init(struct venus_inst *inst, u32 pixfmt) { struct venus_core *core = inst->core; - const struct hfi_ops *ops = core->ops; + const struct hfi_ops *ops; int ret; if (inst->state != INST_UNINIT) @@ -204,10 +204,13 @@ int hfi_session_init(struct venus_inst *inst, u32 pixfmt) inst->hfi_codec = to_codec_type(pixfmt); reinit_completion(&inst->done); + mutex_lock(&core->lock); + ops = core->ops; ret = ops->session_init(inst, inst->session_type, inst->hfi_codec); if (ret) return ret; + mutex_unlock(&core->lock); ret = wait_session_msg(inst); if (ret) return ret; -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation