Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp354241pxu; Wed, 25 Nov 2020 05:05:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJSC9zfTuNEQ6UCaCG10onQdUwg0y7GQ9Bnb7hWutrRfITzNibI75+Zr4xYpv8s4bPmh7d X-Received: by 2002:a17:906:e4f:: with SMTP id q15mr3057951eji.220.1606309545818; Wed, 25 Nov 2020 05:05:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606309545; cv=none; d=google.com; s=arc-20160816; b=NsipL8T4lR27FGNIHD/KFGhU5XlkudLf5UYhNMfAcs0xxphy0unGMm+XSpe+Bgf9b/ G6ESwq5rS9M4UxFzKpQmPCbDYsfiJKqOwTxjZ75lBmhs4f7utYaphmSIlf1loznhEDgR THP7OcnB/e9EnR+E0IYOFEf3X5/knR+8+VVQhHEPdWYqjFCr4KUgSs/oCGJx8AE5oIKw 44qiQj/+df7UjQcgXSdU6guyMNDbD5QXaFvJzPG7YwHhaalyvvUEL2lBPiXWjvo7FS4O MBLEmjNu+aN7ttCbX9OeUSnHgzShbux6ynZEevRvXX6nFTQZ4b/uL/FPuvT/Ywd6GJa2 J+5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=irbsSXjHImcSLHJ6uxXDu2MKDqhSUoJJSkeWgL8xBoA=; b=AtZh9DEA0davVbsgYPn4kKW/l86+XeNVBLxktIsmMW9oeyd5CwLG/pAxFmiL8JxDmF 2uJ9pe6yDkODmDC5INhmOLZAK9jA7TCSOuf6Hv4863GKh0GUhD8kUjgORkj+j16V1h7e roNIDGl/qjxqBXTDIkS86YKAN3sgqWSGn05pmJyhE26il+rCwKR5qvVvAy+8UUxT7lKs 0lsoo5X2pFX/yWP3niLofcWv4BvcfxUTI7+pxbGgTEanlLpuifUF9Gak1rkbXod4iwKZ bI76w40pl/YPOsyFMFNm8lEKjlv+oX0PfaZ3NZY+hQF60VTGRORMltJlLCcA0aNMiu0+ d4vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJCg3v4S; 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 q12si1160822edn.458.2020.11.25.05.05.21; Wed, 25 Nov 2020 05:05:45 -0800 (PST) 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=AJCg3v4S; 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 S1729492AbgKYNBF (ORCPT + 99 others); Wed, 25 Nov 2020 08:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbgKYNBE (ORCPT ); Wed, 25 Nov 2020 08:01:04 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61F4FC0613D4 for ; Wed, 25 Nov 2020 05:01:04 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id a186so1937853wme.1 for ; Wed, 25 Nov 2020 05:01:04 -0800 (PST) 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=irbsSXjHImcSLHJ6uxXDu2MKDqhSUoJJSkeWgL8xBoA=; b=AJCg3v4STEBBRZaHLAE53XA3KcnbyMQzjsoXOCVgOtQnPzop3nkbwp553x5xqFIMQd wAz6sVvPFfpFQnS3UWtT5pbzYJCp/iLZQgo93d3RPzIX1uKyhzGCLaW1XPj8H5JMzljf bTLjMOMhE6N3+93TUjcobXv7XZUMubFPnW//4CSD1mYMfIzl852OCu6bhFaZHCmpxv8n 3eEDa5Sq/XkMZi4ZwK5/K94LmZte8lZ20pq4CHr2JpYBO42voDoKFnglO/RopT3FFhox la4/k7bEVHKdgIhEanahTj2Ms05JzrU+pv8jgMPxy2ZKKTJ6uOGdD/Iq+UY7g0vrXJk0 DV2w== 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=irbsSXjHImcSLHJ6uxXDu2MKDqhSUoJJSkeWgL8xBoA=; b=g0chBDBuN2ux9BwrCOMQxwvmRWyB8KYf+BK+fP3lqmByJ+cY9hseNf2NSIZahQk1lz YXnNoa18DlIyGEKlb+ai1K2cCHKS3mhaWH+dWbG9U2yi4XqhyTiquj4wuTV2Ab8V5dlB /y4piIDk1ZWSZ3YKfD9vtbnooGOkUFIIxl/Ux6ykLhT4YpHEMydEztIeXYWF65ahUPP5 9ItZfCHB0fRoJT+Y09puRUjOnSvrFa4llNjuANyEdPbx3QANYiLSW1thE7f4oIl1S6Ta SZRNbpqz+3nltS1U2vIWijwXJvomdr19bhpMORGojB8e5ZGPBfFmTQpFUX82K0btFSkC y5RQ== X-Gm-Message-State: AOAM532go+bzA+V367bIFUKVdesXXwjB1+zmULeFjTUH1ZWsPCxnLt94 YZ2VHRaC+/F2mqCIJOgGNs1fsg== X-Received: by 2002:a1c:e1c5:: with SMTP id y188mr3853828wmg.81.1606309263056; Wed, 25 Nov 2020 05:01:03 -0800 (PST) Received: from [192.168.0.3] (hst-221-27.medicom.bg. [84.238.221.27]) by smtp.googlemail.com with ESMTPSA id f18sm4686733wru.42.2020.11.25.05.01.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Nov 2020 05:01:02 -0800 (PST) Subject: Re: [PATCH 2/3] venus: Limit HFI sessions to the maximum supported To: Alexandre Courbot Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Vikash Garodia , Mansur Alisha Shaik , Dikshita Agarwal References: <20201120001037.10032-1-stanimir.varbanov@linaro.org> <20201120001037.10032-3-stanimir.varbanov@linaro.org> From: Stanimir Varbanov Message-ID: <8c6231b2-61c2-d432-aa47-ddc29de8da19@linaro.org> Date: Wed, 25 Nov 2020 15:01:01 +0200 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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/25/20 5:46 AM, Alexandre Courbot wrote: > On Fri, Nov 20, 2020 at 9:12 AM Stanimir Varbanov > wrote: >> >> Currently we rely on firmware to return error when we reach the maximum >> supported number of sessions. But this errors are happened at reqbuf >> time which is a bit later. The more reasonable way looks like is to >> return the error on driver open. >> >> To achieve that modify hfi_session_create to return error when we reach >> maximum count of sessions and thus refuse open. >> >> Signed-off-by: Stanimir Varbanov >> --- >> drivers/media/platform/qcom/venus/core.h | 1 + >> drivers/media/platform/qcom/venus/hfi.c | 19 +++++++++++++++---- >> .../media/platform/qcom/venus/hfi_parser.c | 3 +++ >> 3 files changed, 19 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h >> index db0e6738281e..3a477fcdd3a8 100644 >> --- a/drivers/media/platform/qcom/venus/core.h >> +++ b/drivers/media/platform/qcom/venus/core.h >> @@ -96,6 +96,7 @@ struct venus_format { >> #define MAX_CAP_ENTRIES 32 >> #define MAX_ALLOC_MODE_ENTRIES 16 >> #define MAX_CODEC_NUM 32 >> +#define MAX_SESSIONS 16 >> >> struct raw_formats { >> u32 buftype; >> diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c >> index 638ed5cfe05e..8420be6d3991 100644 >> --- a/drivers/media/platform/qcom/venus/hfi.c >> +++ b/drivers/media/platform/qcom/venus/hfi.c >> @@ -175,6 +175,7 @@ static int wait_session_msg(struct venus_inst *inst) >> int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops) >> { >> struct venus_core *core = inst->core; >> + int ret; >> >> if (!ops) >> return -EINVAL; >> @@ -183,12 +184,22 @@ int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops) >> init_completion(&inst->done); >> inst->ops = ops; >> >> - mutex_lock(&core->lock); >> - list_add_tail(&inst->list, &core->instances); >> - atomic_inc(&core->insts_count); >> + ret = mutex_lock_interruptible(&core->lock); >> + if (ret) >> + return ret; > > Why do we change to mutex_lock_interruptible() here? This makes this Because mutex_lock_interruptible is preferable in kernel docs, but I agree that changing mutex_lock with mutex_lock_interruptible should be subject of another lock related patches. I will drop this in next patch version. > function return an error even though we could obtain the lock just by > trying a bit harder. I didn't get that. The behavior of mutex_lock_interruptible is that same as mutex_lock, i.e. the it will sleep to acquire the lock. The difference is that the sleep could be interrupted by a signal. You might think about mutex_trylock? > >> + >> + ret = atomic_read(&core->insts_count); >> + if (ret + 1 > core->max_sessions_supported) { >> + ret = -EAGAIN; >> + } else { >> + atomic_inc(&core->insts_count); >> + list_add_tail(&inst->list, &core->instances); >> + ret = 0; >> + } >> + >> mutex_unlock(&core->lock); >> >> - return 0; >> + return ret; >> } >> EXPORT_SYMBOL_GPL(hfi_session_create); >> >> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c >> index 363ee2a65453..52898633a8e6 100644 >> --- a/drivers/media/platform/qcom/venus/hfi_parser.c >> +++ b/drivers/media/platform/qcom/venus/hfi_parser.c >> @@ -276,6 +276,9 @@ u32 hfi_parser(struct venus_core *core, struct venus_inst *inst, void *buf, >> words_count--; >> } >> >> + if (!core->max_sessions_supported) >> + core->max_sessions_supported = MAX_SESSIONS; >> + >> parser_fini(inst, codecs, domain); >> >> return HFI_ERR_NONE; >> -- >> 2.17.1 >> -- regards, Stan