From nobody Mon Feb 9 23:42:49 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 4CFE220E33E for ; Fri, 10 Jan 2025 13:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736516607; cv=none; b=kIN9iSArZ00GvaiTY5K9AROEmTIeY2+MLgmPpHhnHTPBnm1C72P/G9lk8W6iEOXEuwpJae/Gfh9OWfSHdq8Wf8RJlKgCr8uxxo606oqNCDE2p8JxeloWNf/FZiwMJHGYiM/R9AeAic1gFGpHwb0uZjbdAp56pw/oJhj5oqxKzZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736516607; c=relaxed/simple; bh=i9Tw6eantn3+BORtYG8iZLD/5FotCFM3LFSge0kQNK4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G3uo6/MJRqnc8/tZwYxrx3trza+W2dRFkW1ygaGDVs3M4iUNlBQjLYqhTC2tyVgh4V5JYEUUUjcfSojLPPEBzclAZgwfx2EbcPceL969RJ8bNXknHkDXDeSylO737gtwDSRkGrMy+P9/gQrqpoAZcKoWC0oZkcAwAgar4MDDhZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=YHUlhgMq; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YHUlhgMq" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4368a293339so24071205e9.3 for ; Fri, 10 Jan 2025 05:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736516604; x=1737121404; 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=ajo8u0kIl962rl2+ZgG5egD0kAGGvfs8eYYdpNWhY1I=; b=YHUlhgMqZwFDJEJ2oj7XDiXC0I3ss1T4F8jmX7hD91HwetwCQd1QofQ5SBWEtdtPpR +hGZusHiirikDf+kg20T0yZwNjnp330wYcRt9jxB6qm49auuabLcpfSFyBE3jXoetrT6 vooGBYDr7PqbX9USv/g9iECfh6wqNxF2OxBUqSfKHzNumiTsrIBWq5o0dINwA0QN4+RG VYJey3Oyyert+HUrYfwJ44GmTLLHqSQS4M+i8oCnhcsYpfrqY9Y4ZRfH1YIVBtzGJ1Ky uYh7H1TqkVg7s8VnQyOVOoHPhMjEbkoxrMU3odZKHCn4Ywoos8p1VsY/+NDTvaljR2D6 u1+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736516604; x=1737121404; 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=ajo8u0kIl962rl2+ZgG5egD0kAGGvfs8eYYdpNWhY1I=; b=p759pvlJqkLqphqHUPHKwPAn3T3GtScncDMJz01rvhThIOADN4cKUBYsnvNWL4w9YL XLRt35+Zgx5nmTYmyPr04RZW1bBmleb7BMtdvgTUxkkdxf0GT9G4OtuFeajeED96c/cf 22zFUkyBIMSxebzvJmILTiBskQLywhVhKp/umxCG/ARJgWxs9jnBZkUyXwblJNz66EzP Yy82y+SIiCH0fx+1vhsFNzhr5S5HLYVvrjWRs9OrnUVcH8Yilopn/NW2xupllSa5Ks+3 H2Kxxip5W2mf2LzqM91l5Q6sOWCtH7g/e30BxR+boI9A8zNsrGE5huPIBmnJZbPW20aV KP4w== X-Gm-Message-State: AOJu0Ywjo1b4IPzGTCdwWXr4QsYS1OZSK7XeX8ozLbajT5JttOgjUN9o IgKcd3aULeFjeTG1T5ByOPVwPpagBTDERp8F4A32dQ4kKNohX7piV0sERjwhOLA= X-Gm-Gg: ASbGncsLp8OqM9BUbFF3K+808LQvWzk6T2x90S1n0v3dIeeau3/Fa680EtAPIQ0v8tP CXb2vsqVLYgLx/7+cMi8WE41aMJqFDznuTEBBsu1pgFVsERk1tLTs0HIAhs+Iyl8K5DlgE5+lRz 1RUlt/AAMg/5Zn/H9myo8BIBr0xlt9zmIDHLpEcNBcGhZ5PpPUguA393SG64pjJOMbUWkIOrjGm I7XGjZmFn42RwKu+nJmvHKnqNm+vr6N6x5gkNgh65pHSaV71KXieZZM9EuqAYeOUAwjhja2YNvT m6nkFQ== X-Google-Smtp-Source: AGHT+IFaM50SSaS2GGHdg5lKMbH/liiYHBcYq/ww1UAzsj3ZSvh1bXen+CJXpb7/XJzWqujI3O2uHA== X-Received: by 2002:a05:600c:3b08:b0:436:18e5:6917 with SMTP id 5b1f17b1804b1-436e255ffd6mr110212225e9.0.1736516603626; Fri, 10 Jan 2025 05:43:23 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436dd11d8b4sm78168695e9.1.2025.01.10.05.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:43:23 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Ekansh Gupta , Dmitry Baryshkov , Srinivas Kandagatla Subject: [PATCH 1/2] misc: fastrpc: Add support for multiple PD from one process Date: Fri, 10 Jan 2025 13:43:07 +0000 Message-Id: <20250110134308.123739-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250110134308.123739-1-srinivas.kandagatla@linaro.org> References: <20250110134308.123739-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5419; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=5pjgljuPUGLpKCpBFb1JGP5NYVK+cBcdFYBSQIr6uCI=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBngSPs+Op7mulrHE4gelvAMsJvVRiEDmzAA2vtD ML7yMxN+iOJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZ4Ej7AAKCRB6of1ZxzRV N/kPB/47wmymvBn8c6w1HRmKrx2/Hd5oNfap/fbaudwnv9avEjxqVe0ZQm5oEquUUl/NOB1Z4et Iup2ivatKEORGlqEMWdZPxpEZilR8p9z/eHev7iA2Eqyt5uJGwsVt0M+Xd1V/YIm+yYj2T3XgTx BIdslh6BoJMk4Zbhb5K4BpfjhOIZS4nUHjs+x5Xk9K7q5JVauD2J0aRHaiCPU0lorXg6LyI5P3/ GoGD7c2fu7KZBu3Zeaubw5YzDBk30IfDRUlH7T7kqJJv6gkW5j5W0o3v9lvC30PxGxTOJd3OzwX 3LiiweJco4KlCKoYhpTeW0Ena2heP+o+s1wDSRxaTREP6Tdx X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ekansh Gupta Memory intensive applications(which requires more tha 4GB) that wants to offload tasks to DSP might have to split the tasks to multiple user PD to make the resources available. For every call to DSP, fastrpc driver passes the process tgid which works as an identifier for the DSP to enqueue the tasks to specific PD. With current design, if any process opens device node more than once and makes PD init request, same tgid will be passed to DSP which will be considered a bad request and this will result in failure as the same identifier cannot be used for multiple DSP PD. Assign and pass a client ID to DSP which would be assigned during device open and will be dependent on the index of session allocated for the PD. This will allow the same process to open the device more than once and spawn multiple dynamic PD for ease of processing. Signed-off-by: Ekansh Gupta Reviewed-by: Dmitry Baryshkov Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 74181b8c386b..9410b4b2eab7 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -299,7 +299,7 @@ struct fastrpc_user { struct fastrpc_session_ctx *sctx; struct fastrpc_buf *init_mem; =20 - int tgid; + int client_id; int pd; bool is_secure_dev; /* Lock for lists */ @@ -614,7 +614,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( ctx->sc =3D sc; ctx->retval =3D -1; ctx->pid =3D current->pid; - ctx->tgid =3D user->tgid; + ctx->tgid =3D user->client_id; ctx->cctx =3D cctx; init_completion(&ctx->work); INIT_WORK(&ctx->put_work, fastrpc_context_put_wq); @@ -1115,7 +1115,7 @@ static int fastrpc_invoke_send(struct fastrpc_session= _ctx *sctx, int ret; =20 cctx =3D fl->cctx; - msg->pid =3D fl->tgid; + msg->pid =3D fl->client_id; msg->tid =3D current->pid; =20 if (kernel) @@ -1293,7 +1293,7 @@ static int fastrpc_init_create_static_process(struct = fastrpc_user *fl, } } =20 - inbuf.pgid =3D fl->tgid; + inbuf.pgid =3D fl->client_id; inbuf.namelen =3D init.namelen; inbuf.pageslen =3D 0; fl->pd =3D USER_PD; @@ -1395,7 +1395,7 @@ static int fastrpc_init_create_process(struct fastrpc= _user *fl, goto err; } =20 - inbuf.pgid =3D fl->tgid; + inbuf.pgid =3D fl->client_id; inbuf.namelen =3D strlen(current->comm) + 1; inbuf.filelen =3D init.filelen; inbuf.pageslen =3D 1; @@ -1469,8 +1469,9 @@ static int fastrpc_init_create_process(struct fastrpc= _user *fl, } =20 static struct fastrpc_session_ctx *fastrpc_session_alloc( - struct fastrpc_channel_ctx *cctx) + struct fastrpc_user *fl) { + struct fastrpc_channel_ctx *cctx =3D fl->cctx; struct fastrpc_session_ctx *session =3D NULL; unsigned long flags; int i; @@ -1480,6 +1481,8 @@ static struct fastrpc_session_ctx *fastrpc_session_al= loc( if (!cctx->session[i].used && cctx->session[i].valid) { cctx->session[i].used =3D true; session =3D &cctx->session[i]; + /* any non-zero ID will work, session_idx + 1 is the simplest one */ + fl->client_id =3D i + 1; break; } } @@ -1504,7 +1507,7 @@ static int fastrpc_release_current_dsp_process(struct= fastrpc_user *fl) int tgid =3D 0; u32 sc; =20 - tgid =3D fl->tgid; + tgid =3D fl->client_id; args[0].ptr =3D (u64)(uintptr_t) &tgid; args[0].length =3D sizeof(tgid); args[0].fd =3D -1; @@ -1579,11 +1582,10 @@ static int fastrpc_device_open(struct inode *inode,= struct file *filp) INIT_LIST_HEAD(&fl->maps); INIT_LIST_HEAD(&fl->mmaps); INIT_LIST_HEAD(&fl->user); - fl->tgid =3D current->tgid; fl->cctx =3D cctx; fl->is_secure_dev =3D fdevice->secure; =20 - fl->sctx =3D fastrpc_session_alloc(cctx); + fl->sctx =3D fastrpc_session_alloc(fl); if (!fl->sctx) { dev_err(&cctx->rpdev->dev, "No session available\n"); mutex_destroy(&fl->mutex); @@ -1647,7 +1649,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *= fl, char __user *argp) static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) { struct fastrpc_invoke_args args[1]; - int tgid =3D fl->tgid; + int tgid =3D fl->client_id; u32 sc; =20 args[0].ptr =3D (u64)(uintptr_t) &tgid; @@ -1803,7 +1805,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_use= r *fl, struct fastrpc_buf * int err; u32 sc; =20 - req_msg.pgid =3D fl->tgid; + req_msg.pgid =3D fl->client_id; req_msg.size =3D buf->size; req_msg.vaddr =3D buf->raddr; =20 @@ -1889,7 +1891,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, = char __user *argp) return err; } =20 - req_msg.pgid =3D fl->tgid; + req_msg.pgid =3D fl->client_id; req_msg.flags =3D req.flags; req_msg.vaddr =3D req.vaddrin; req_msg.num =3D sizeof(pages); @@ -1978,7 +1980,7 @@ static int fastrpc_req_mem_unmap_impl(struct fastrpc_= user *fl, struct fastrpc_me return -EINVAL; } =20 - req_msg.pgid =3D fl->tgid; + req_msg.pgid =3D fl->client_id; req_msg.len =3D map->len; req_msg.vaddrin =3D map->raddr; req_msg.fd =3D map->fd; @@ -2031,7 +2033,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *f= l, char __user *argp) return err; } =20 - req_msg.pgid =3D fl->tgid; + req_msg.pgid =3D fl->client_id; req_msg.fd =3D req.fd; req_msg.offset =3D req.offset; req_msg.vaddrin =3D req.vaddrin; --=20 2.25.1