Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp971959lqt; Fri, 7 Jun 2024 04:36:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7yUqObSQ7ap67Wl7Mbp5DtnTQdKCyZPSihin/bwS2Hg5RqLSzdCRY7bM+dc4LAScAKPdlTCAZdaWWD0qC9bN7pm/6qMFHqUugwpFpBQ== X-Google-Smtp-Source: AGHT+IGEXkBGrW7+a3/NKysZMl4A7lIwRNrBVvyL/jJTSsKqGNiAWAGuO6BrbKAgH4VCZgAJensl X-Received: by 2002:a17:90a:f0d6:b0:2c2:7dd6:97b with SMTP id 98e67ed59e1d1-2c2bcaf8895mr2091959a91.16.1717760169719; Fri, 07 Jun 2024 04:36:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717760169; cv=pass; d=google.com; s=arc-20160816; b=PbSwXZRpnEzJtrx9oMa0l/k5k/Nf9eIqvBFUc2QVp7BVNDBTOjyf/8Z/7hARSt+4Fr a9sVuUmul5qUhQ5EeQk+aqN4la2KKVtoYTnNnmZdcHaR64SYasPlhEMT/gV4sApGO6jJ m2p9mMOayDOY8Al1PsSqrEU3pAp+SKB4oQqY6tDnOctmc67YvwvMQPHesrv97rHYwOOP pX/xJgs6U4FDhjyckK1PJIrNST1FA9ueK60Yy4+2BxqfnUGUbj8gbEg8TPn23YW6E7AO BzaDsLD8G5JaxBsd7TFO2oXLw0pA6KiW0h0VRTUPjgfj/Xl5desWSdJWcHLQxckgzrP0 Js2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=TVtD+zV7wnja7KGiO0Z7oOp05pY2Z3I36kzwWL8xPYo=; fh=FJvYp4CH23oTr4FgY7v92HDigC7Hn/GNvyEsyIla1Ew=; b=nNAQMiUKtvu7N0XrRgA6V34BCe/I5MeiIxPK7bQkjP9Ys5vk9gI6eIZyehlEnIY79P 9hwo0NmZI9d70qUvu13Ik6EOJSUQOD79itkOG+Dd5TMMP7kq3Gn5Bl1CSv2YsLwvosrG glji1UvSI0Lhu5KGB1JH2UwjBv/paQxzywEAm48MffFjTvu+5vmyIFpnbbJrn5X45OA9 JyHpnoZXxVpKjEb0A8c20GkESPZr/8ysQCpMf7B9jZrGsYmivquhVOPzMgh6mtlGoEvJ I/99HGTpe1sFJ+NOusS6ONxjut64Kr1nQgAY/Qjl27OCVmnIBvSMlHdZunAldZYaNFSi PpoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dSa5D7Id; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-205928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2d117cd7dsi156131a91.168.2024.06.07.04.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 04:36:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dSa5D7Id; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-205928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 030AC2885E9 for ; Fri, 7 Jun 2024 11:36:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A9B918F2C9; Fri, 7 Jun 2024 11:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dSa5D7Id" Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 239702837F for ; Fri, 7 Jun 2024 11:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717760161; cv=none; b=HDoGQaBcaPt8wSFFkUCIJ6oCGP64rC89cuqWH/KW3pTlvqWPA1/Ga0vV2rKFAf1s/bjfyhzB21XmCCaVTD6aBvyvoRa9nAvFO+twUBN6p4r1Z4SYg9JqnRJT5nyCtVlaccjkV9uX+8PfBywWXBQUN7rc2JauLQEUF1hryVBJgss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717760161; c=relaxed/simple; bh=eBEctrNUyEClxD2W6RimZTw78rdqoYyFacmBE5J+XHs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mKvHM/O1oYXA3WLyP2n3posEu0OkKtDNDinuEVn+6aGS63DQ1e72KYBv/GAzlvsT1WgBGPDzZonvh++Pj6LwH4f7R/WqWwUduQq/W9YOnXQgnA9+tvTM1ZCVWSd3Lmhf9RD71RN8iyGMg1UNHbcqCWlr7DI4rUIKigzhu6ZZFyo= 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=dSa5D7Id; arc=none smtp.client-ip=209.85.167.51 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 Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-52bc3130ae6so82891e87.3 for ; Fri, 07 Jun 2024 04:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717760157; x=1718364957; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TVtD+zV7wnja7KGiO0Z7oOp05pY2Z3I36kzwWL8xPYo=; b=dSa5D7IdF/L8OUqGQ+IbTHljaPHi6Bv6CVyLb9DK9ipxhRBfGHwq23WR8PuVSSk8YU lI5i1GYephqgHd4HBJgzn6BD/+SNEjeUwOBwOFFCGPOCqU4HZ4hbwBbXoDyBuCqSPRm4 po6966bHtOgEFoPIjHyhDQXyoYLf6ysr0LzPeak+EJIZdyO80gax1I/9eBjw+pePkw6B BpmBNW+16zn9bJIMz14t54fFGkxdN28iWHLeO9xQpl1a9jM61V1XlVxoBdVuCbKk1xw5 YZ51yqL1oxtt5kWj8UKB5WjHWtHrn0wFT0K+SoSR04jXTBelrRj5opIIiebb9vIwMar/ gwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717760157; x=1718364957; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TVtD+zV7wnja7KGiO0Z7oOp05pY2Z3I36kzwWL8xPYo=; b=tGWH15GpybOJuTONU7uRqBpIIHcXFv35UDAPvJTAABZRCtt5wrfJKfkMBr72DWF2SY /a+ReLN7OiLEJYwzmFGNqtfbKKwogYZfYEm1KVhZ5WkqeYqjjoQKmwakC5KlRJvZ942o g3GTTU1H9ehVNawGktrCtTanjC0MGA7GwyS7cGMKY7TIG28dao+zsfrg40nZyJcHJhfy 85yOBQS0cZjoDsqgkShyNAItpmPDepdUVRApaktAqVN4uKljn7sTrscCcKa+PsGjfSct j/RZ6/eHuefo/0TPRHCkwten5qu/ivOCIq+KzGkZmsglSFQ5jqqsENCEr40BA4YdQaCD Kc3w== X-Forwarded-Encrypted: i=1; AJvYcCWNJe46wBOWi3+6eAx9g6k1+8b+9F7GFS/S3Q9rrksKoCg25uYpiyadXIaJBMOvXN+aqlRe5jFoyIXuFraJIF6taZUVBJsOai7PkyEI X-Gm-Message-State: AOJu0YwIj3VuLGOR8VknZfcOz77Hlipmfg8Fmk+cpViRX+NmhTz5o4AE zHmgxqqFt5Ls36fG0PB4vBfDPYz5zAHSdlzBlMm9zv7mff86Qxo9rSbNX1/SvdQ= X-Received: by 2002:a05:6512:34d4:b0:52b:8843:b084 with SMTP id 2adb3069b0e04-52bb9fc95a6mr1306467e87.47.1717760157125; Fri, 07 Jun 2024 04:35:57 -0700 (PDT) Received: from eriador.lumag.spb.ru (dzdbxzyyyyyyyyyyyykxt-3.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::227]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52bb423e1c0sm508994e87.230.2024.06.07.04.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 04:35:56 -0700 (PDT) Date: Fri, 7 Jun 2024 14:35:54 +0300 From: Dmitry Baryshkov To: Ekansh Gupta Cc: srinivas.kandagatla@linaro.org, linux-arm-msm@vger.kernel.org, gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com Subject: Re: [PATCH v4 07/11] misc: fastrpc: Redesign remote heap management Message-ID: References: <20240606165939.12950-1-quic_ekangupt@quicinc.com> <20240606165939.12950-8-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240606165939.12950-8-quic_ekangupt@quicinc.com> On Thu, Jun 06, 2024 at 10:29:27PM +0530, Ekansh Gupta wrote: > Current remote heap design is adding the memory to channel context > but here is also a possibility of audio daemon requesting new remote > heap memory using map ioctl. For this purpose, it's much easier to > maintain these types of static PD specific remote heap allocations > as a list. This remote heap memory is only getting freed during > rpmsg remove but it is also needed to be freed when static PD is > shutting down as this memory will no longed be used by static PDs. > For daemon kill cases where audio PD is still alive, the init IOCTL > will again take the same address and size to DSP which DSP would try > to map again which would result in mapping failure the PD might > already be using the memory. In Daemon kill cases, the address and > size is needed to be sent as zero and DSP will skip mapping in this > case. Are these two sentences describing the same usecase or two different cases? > Add changes to manage remote heap in a way that it can be added > and removed as per needed and the information is sent as zero in daemon > kill cases. > > Signed-off-by: Ekansh Gupta > --- > drivers/misc/fastrpc.c | 94 +++++++++++++++++++++++++++++++++--------- > 1 file changed, 75 insertions(+), 19 deletions(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index 7ee8bb3a9a6f..3686b2d34741 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -274,6 +274,7 @@ struct fastrpc_session_ctx { > }; > > struct fastrpc_static_pd { > + struct list_head rmaps; > char *servloc_name; > char *spdname; > void *pdrhandle; > @@ -299,7 +300,6 @@ struct fastrpc_channel_ctx { > u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; > struct fastrpc_device *secure_fdevice; > struct fastrpc_device *fdevice; > - struct fastrpc_buf *remote_heap; > struct list_head invoke_interrupted_mmaps; > bool secure; > bool unsigned_support; > @@ -1256,6 +1256,53 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques > return false; > } > > +static void fastrpc_mmap_remove_pdr(struct fastrpc_static_pd *spd) This isn't removing pdr. > +{ > + struct fastrpc_buf *buf, *b; > + struct fastrpc_channel_ctx *cctx; > + int err; > + > + if (!spd || !spd->fl) > + return; Any protection against concurrent spd->fl modification? > + > + cctx = spd->cctx; > + > + spin_lock(&spd->fl->lock); > + list_for_each_entry_safe(buf, b, &spd->rmaps, node) { > + list_del(&buf->node); > + spin_unlock(&spd->fl->lock); > + if (cctx->vmcount) { > + u64 src_perms = 0; > + struct qcom_scm_vmperm dst_perms; > + u32 i; > + > + for (i = 0; i < cctx->vmcount; i++) > + src_perms |= BIT(cctx->vmperms[i].vmid); > + > + dst_perms.vmid = QCOM_SCM_VMID_HLOS; > + dst_perms.perm = QCOM_SCM_PERM_RWX; > + err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, > + &src_perms, &dst_perms, 1); > + if (err) { > + pr_err("%s: Failed to assign memory phys 0x%llx size 0x%llx err %d\n", > + __func__, buf->phys, buf->size, err); dev_err, no __func__ > + return; > + } > + } > + fastrpc_buf_free(buf); > + spin_lock(&spd->fl->lock); > + } > + spin_unlock(&spd->fl->lock); > +} > + > +static void fastrpc_mmap_remove_ssr(struct fastrpc_channel_ctx *cctx) SSR? > +{ > + int i; > + > + for (i = 0; i < FASTRPC_MAX_SPD; i++) > + fastrpc_mmap_remove_pdr(&cctx->spd[i]); > +} > + > static struct fastrpc_static_pd *fastrpc_get_spd_session( > struct fastrpc_user *fl) > { > @@ -1282,7 +1329,9 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > struct fastrpc_init_create_static init; > struct fastrpc_invoke_args *args; > struct fastrpc_phy_page pages[1]; > + struct fastrpc_buf *buf = NULL; > struct fastrpc_static_pd *spd = NULL; > + u64 phys = 0, size = 0; > char *name; > int err; > struct { > @@ -1330,23 +1379,23 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > goto err_name; > } > fl->spd = spd; > - if (!fl->cctx->remote_heap) { > - err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, > - &fl->cctx->remote_heap); > + if (list_empty(&spd->rmaps)) { > + err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, &buf); > if (err) > goto err_name; > > + phys = buf->phys; > + size = buf->size; > /* Map if we have any heap VMIDs associated with this ADSP Static Process. */ > if (fl->cctx->vmcount) { > u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); > > - err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, > - (u64)fl->cctx->remote_heap->size, > - &src_perms, > - fl->cctx->vmperms, fl->cctx->vmcount); > + err = qcom_scm_assign_mem(phys, (u64)size, > + &src_perms, > + fl->cctx->vmperms, fl->cctx->vmcount); > if (err) { > dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d\n", > - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); > + phys, size, err); > goto err_map; > } > } > @@ -1365,8 +1414,8 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > args[1].length = inbuf.namelen; > args[1].fd = -1; > > - pages[0].addr = fl->cctx->remote_heap->phys; > - pages[0].size = fl->cctx->remote_heap->size; > + pages[0].addr = phys; > + pages[0].size = size; > > args[2].ptr = (u64)(uintptr_t) pages; > args[2].length = sizeof(*pages); > @@ -1382,6 +1431,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > kfree(args); > kfree(name); > > + if (buf) { > + spin_lock(&fl->lock); > + list_add_tail(&buf->node, &spd->rmaps); > + spin_unlock(&fl->lock); > + } > + > return 0; > err_invoke: > if (fl->cctx->vmcount) { > @@ -1394,15 +1449,15 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, > > dst_perms.vmid = QCOM_SCM_VMID_HLOS; > dst_perms.perm = QCOM_SCM_PERM_RWX; > - err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, > - (u64)fl->cctx->remote_heap->size, > - &src_perms, &dst_perms, 1); > + err = qcom_scm_assign_mem(phys, (u64)size, Why do you need to convert to u64? > + &src_perms, &dst_perms, 1); Maybe it can fit into a single line? > if (err) > dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", > - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); > + phys, size, err); > } > err_map: > - fastrpc_buf_free(fl->cctx->remote_heap); > + if (buf) > + fastrpc_buf_free(buf); > err_name: > kfree(name); > err: > @@ -2250,6 +2305,7 @@ static void fastrpc_pdr_cb(int state, char *service_path, void *priv) > spd->servloc_name, > domains[cctx->domain_id]); > spd->ispdup = false; > + fastrpc_mmap_remove_pdr(spd); > fastrpc_notify_pdr_drivers(cctx, spd->servloc_name); > break; > case SERVREG_SERVICE_STATE_UP: > @@ -2401,6 +2457,7 @@ static int fastrpc_setup_service_locator(struct fastrpc_channel_ctx *cctx, char > cctx->spd[spd_session].servloc_name = client_name; > cctx->spd[spd_session].spdname = service_path; > cctx->spd[spd_session].cctx = cctx; > + INIT_LIST_HEAD(&cctx->spd[spd_session].rmaps); > service = pdr_add_lookup(handle, service_name, service_path); > if (IS_ERR(service)) { > err = PTR_ERR(service); > @@ -2567,9 +2624,6 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) > list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node) > list_del(&buf->node); > > - if (cctx->remote_heap) > - fastrpc_buf_free(cctx->remote_heap); > - > for (i = 0; i < FASTRPC_MAX_SPD; i++) { > if (cctx->spd[i].pdrhandle) > pdr_handle_release(cctx->spd[i].pdrhandle); > @@ -2577,6 +2631,8 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) > > of_platform_depopulate(&rpdev->dev); > > + fastrpc_mmap_remove_ssr(cctx); > + > fastrpc_channel_ctx_put(cctx); > } > > -- > 2.43.0 > -- With best wishes Dmitry