Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp156213pxk; Fri, 11 Sep 2020 03:12:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx96xRy/CcQAcjllMfdcJux8/pTrkiBxvsuylbG/pNe8nxt48RIDiaWsewNM6NivgnNCjfS X-Received: by 2002:aa7:db85:: with SMTP id u5mr1119139edt.316.1599819177816; Fri, 11 Sep 2020 03:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599819177; cv=none; d=google.com; s=arc-20160816; b=Ek1qbCGfGGUi14lL9Ux8YUpjf8JMsthLf6UFuLb63UY+3as9DSgWVHEavbEmw37sCw wfztelwRcLbaElknmLeGEjeUnrdyd7jspb/OJ0+Eru9wnJ1e/7EIV5FnWt0T5EOrQnZF zv3DAD+7J5Vi87uTUbg8zEHt2RrcGrZVqPRtoAs+8T08K33CHRc94R9dzs16LXAguRp3 /MUrdMm1pTlqxa9MNoXGHQiDqLLnHCCkcpjLZjOKzLhA/mcKsD1C2Otm0Ug+6ha32zWt FH8EaSZi2aN1a81ynfyUmm6hJIxwjjX02x8tBdatVAO8B3Flt5GmNxOBZPjYPFiIUsY+ uCEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=34lVXXsxtskqjri1vjJe9bVZAHnv49AB0SP0UfxscAE=; b=sgidyNETPq1u5G/7+VXhANz/163mW0Pnyq+ShRdjINqhvViLV6PJoaefTHJDZVtDeP /C617fxh02UWsrKvLtgN9feOGDY2e+gp3RTjaur371huw7iV77ZMunfUP5trOvSvEH9U KY93sR+lDZsAHZ4GzOoDkSyBWTkEPHpGQc921xLxNu7HED04xN0QgXkJsorSNgsI+iV7 klY02eyd1wtKVyziCQHqsk0fJhs704lvA3SgSCUiqkCwdt6JI6HcS81pa/iK/DrtcuNI GQrIul7IZSOxkcB26q8yDgcZr8WUAuYpt2ab20iHxV3rXHxDCAknzX7VKCOYjhWlOstv Xn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ep6Ra3o7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si1016711ejj.33.2020.09.11.03.12.35; Fri, 11 Sep 2020 03:12:57 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Ep6Ra3o7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725866AbgIKKLK (ORCPT + 99 others); Fri, 11 Sep 2020 06:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbgIKKLC (ORCPT ); Fri, 11 Sep 2020 06:11:02 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90976C061757 for ; Fri, 11 Sep 2020 03:11:01 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id l17so9320412edq.12 for ; Fri, 11 Sep 2020 03:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=34lVXXsxtskqjri1vjJe9bVZAHnv49AB0SP0UfxscAE=; b=Ep6Ra3o7gNv7Sft87tKmodUvRTKK+yEtXMzzNto1Yt1KesamA6xMs/S8zhwDMqRqsy cj3Xa5rWmXFkJEe7xzlnmIgOsD7z66jKkNHSMokMcCKrVVp9+1zmIDltdzx6TwFgDYrq LU+HqA9msWRajaHgwLojKB8QzqVvOB8SEUGs6NiU6ZLnDPpDt6pExPXBwtY15fQilO0P HcvPgWWEQQPtnWxXe2sGuxjoDQI4zzcdIoTfMUlBVsawGUYH41ceY9cjxfJdBeJypwbg 8M8O8Kr+y5byUjtX2u5dU92/znvOXk9SWOBv842iUW6A3ys6nEz0JhaKnJ+Bilt7QaOc AaVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=34lVXXsxtskqjri1vjJe9bVZAHnv49AB0SP0UfxscAE=; b=pqmGel1h5nIUX1ucsGQYUe9EZ5ACvccUzkaYHSjYGZ5VFpfYdgyVJeEA/x6w/BNZSw itJ/K5VfKyfGVvwgwf6P0bDbtn5YXqjTSVXRvPjAFt7FcIwQfq2P5RteVz283pR/qKwI QgRO+DxxEF/5fNKEdTQyvWG7vai5g2zqGQLzEJWRNet3Ju4aERkifitHtZbkl3HMrhQQ C/Wadp45shiuhDPNiikSQdma/UgiUQCmYwf+Bhdf/O1SBMrWg6d+34qlw3CUOysDzChZ cpbyl1YLK/sf6w7N8qGVr/+YtU+nny8tX2OZebnZyrjJf4JQm0TqqhEyDwnq6FAcJsN+ Tbww== X-Gm-Message-State: AOAM533/OQf6LccOo145jEsI7MF4LDxcmnn4oo/rJBIhmFVD0PfQu0jz slEl6r3xZvbO8X9CPex0EWuQ4g== X-Received: by 2002:a05:6402:1109:: with SMTP id u9mr1212483edv.74.1599819059554; Fri, 11 Sep 2020 03:10:59 -0700 (PDT) Received: from [192.168.1.8] ([195.24.90.54]) by smtp.googlemail.com with ESMTPSA id v2sm1227241ejh.57.2020.09.11.03.10.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Sep 2020 03:10:58 -0700 (PDT) Subject: Re: [PATCH v2 1/3] venus: core: handle race condititon for core ops To: Mansur Alisha Shaik , linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org References: <1599741856-16239-1-git-send-email-mansur@codeaurora.org> <1599741856-16239-2-git-send-email-mansur@codeaurora.org> From: Stanimir Varbanov Message-ID: <313cf565-f69f-df84-6bff-8c9a77b9f642@linaro.org> Date: Fri, 11 Sep 2020 13:10:57 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1599741856-16239-2-git-send-email-mansur@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/10/20 3:44 PM, Mansur Alisha Shaik wrote: > 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 CPU > core, core->ops becoming NULL and in another CPU 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 > Acked-by: Stanimir Varbanov > --- > Changes in V2: > - Addressed review comments by stan by validating on top > - of https://lore.kernel.org/patchwork/project/lkml/list/?series=455962 > > drivers/media/platform/qcom/venus/hfi.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c > index a59022a..3137071 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 we are in system error recovery the session_init cannot pass successfully, so we exit early in the function. I'd suggest to make it: /* If core shutdown is in progress or we are in system error recovery, return an error */ mutex_lock(&core->lock); if (!core->ops || core->sys_error) { mutex_unclock(&core->lock); return -EIO; } mutex_unclock(&core->lock); > 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; > -- regards, Stan