Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp604789lqh; Fri, 31 May 2024 10:29:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5X5h8t4wOkRpLRQqyfSkKUwapL5yrbxHz5sDP794n73rr4FNQO79maLvrtn23i/UDkXrqGtzeCAQTkYpNqGSE9HwoGc6DXLa2gDh3QQ== X-Google-Smtp-Source: AGHT+IE8efApzszO0Lj7LiVRpE6ekUSroGDwTy8VOd62Cn/h7YfWYGDqseW9QAWHNhi6PXcJ+yxp X-Received: by 2002:a17:902:ea0f:b0:1f6:2623:7077 with SMTP id d9443c01a7336-1f636fe7218mr24236785ad.12.1717176598628; Fri, 31 May 2024 10:29:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717176598; cv=pass; d=google.com; s=arc-20160816; b=XX5OAjzv3vK0215S/I4My7078kyHft8FX0/bDNJQMXPJ8wsZgvMUwn7SteYk1etux5 Vho+GdoUwe2q3CSzPrQW/gD8/Op/V6q7AwWHADpiG+IalbcV1AF9O2TUUgfptedxiIoX mr39djrktlzcCbnZ9BQV2N9EyVifpVJlaKkS3Qcm9K9jRPfMV2wtlv/G/mFcLI3R3RNJ TaXDhgyWnJIGiniXZU4/GwCSomnLTZBzoa2h5lyA2B1lEDX6obnipvZIHt9jVkW6qWT4 wQZaTZf8PVTevN7gzyR2Hfo6gTQOvctauCIsgRTblOpMdcSpkVxaDpvqAyyjgneVzCt7 +oQw== 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=PIW/+d3pyitNysbRb4C74Z7GshTp0lM3THuiLkgE5rU=; fh=4K4Kk+4nKAFw1nFItABR+1ZaotZrF5SXagJBuEKCL4w=; b=JRDgIwCZgAgHnkGo4w1iXdWaZvn0ipztz2hf85WhmSYSvDLfZ46U3kg3MkyTGi/0aY MjoQcELnpdKV//DBt6BnXHTmrS40L7mTHzng8/7rZtoE6gPB/Lsw6Om0o+O7lflKxW7n gNUPOaPMnizJg01Makp0T4sAjoSBmbRxtEtgIzJmkld0784EVz0ZmgN3bmL2I1BO+5mu vkbODDT1TQN8aB10v9F3PXChqjIKOTSRn5RewSTgqao6ZKeG6FR5a84SChWeXQAZ9XJm ZQMrHV6oN5D+vtFEj1naLG2HDyFt0yPD5pmxMyt9JIPfUxjaXOdtXB2C6N8R2jrWbYJ4 0bEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HJCuDGtJ; 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-197249-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197249-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. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323eace3si19112915ad.349.2024.05.31.10.29.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 10:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197249-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HJCuDGtJ; 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-197249-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197249-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 1FD2128A865 for ; Fri, 31 May 2024 17:28:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4423178387; Fri, 31 May 2024 17:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HJCuDGtJ" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 7C7A37BAE7 for ; Fri, 31 May 2024 17:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717176519; cv=none; b=biNEAkNWaeZPaz00MB+1jW7h+VSOYQosnsTJZ/PR+AzwYIEnFa9yDSll8HBwZcReozJUlhXgMND5z7MV3UKoeSCjtdotKiQdKCxI9eEtspIBJvtCTC4NgFZx5FC9NK1TdOTyPWvHhpZL/FnDGKU6q819lKDH1Pqki+pn7EbG0Vw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717176519; c=relaxed/simple; bh=mE8SRr5pmWDgEPgzOnI666xlXsAzv9fUYw/yNBrhUXU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BhZW5skZpc1fl2EkTHJZwTRomKK5eVyWvxO45cK3cxJG6dwFwxYx1SUVSXCKR5ydFy4YF4tOsiXKVCdRUx+1CzUPUgMozuU70nVCCeUoMaYu12Iyr9w5QLl325GvBj1URgPtqn0F1E+Djj2fqfpxbPBl3g4mdpSL55o2fLdlSSw= 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=HJCuDGtJ; arc=none smtp.client-ip=209.85.214.180 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-pl1-f180.google.com with SMTP id d9443c01a7336-1f44b594deeso17484525ad.2 for ; Fri, 31 May 2024 10:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717176517; x=1717781317; 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=PIW/+d3pyitNysbRb4C74Z7GshTp0lM3THuiLkgE5rU=; b=HJCuDGtJtCzo4THLud6XJB5tCQfyEnAuCVMUMGcd+1UkrvLVWInuZ4NepimFc5Zy98 VzpAzXcS6K42un8YTixwH2pxJ8SAtRJRi3AQ9R2nP70j0NOcihDwGf36ZMn49/UKhRYA oAvbyW8DdsFe+6HYCODRgalDrCYdRAeo37IO9IUPHwNha5LUGXSkhOnMmq1kKc7aTeue 6YK0AGlXRY7OtoEFZvCHU2nPbQ01NegwbMfw1knl7eYUPziEm2Niuom9r1AYntSC/04S 3+zJ3jKVmFVRD1I/zVoL0pVeqEwq9JQhSWIZ6gV8NDlhjrXmSBE7ufzQQMR+/eY6DAQ6 n/5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717176517; x=1717781317; 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=PIW/+d3pyitNysbRb4C74Z7GshTp0lM3THuiLkgE5rU=; b=ioW4AW2wQm+UzxMaOHe7F7Urr3V5axhz4xtIs9QHpplKxFr1B0zMvaw/p8oxkmJeIQ vBIW+naC25xTOhFUWk95rif8BijpPPOHXk6U62ekD36Jmk3AhFPe51CaRSq1g8SIT2a2 aUhErniWVchbC6keG2AffEfkZhp0SKt/OKFBrMln7m2ex16QLWt0Gb4nTCkVH3ro3j34 pNKVzzmsjZwtXiVqruGdoo6ToeP2Dbwn2qlw+y087/I3Ih1npwqTt1ku3osdmEe9KHwq 5tPL6MonYYXB7klCRWJEUwXJfefi5YhPVCDcCTCz+Xctk2Cl68DMlIjnNwFOi3dkalDg sdBg== X-Forwarded-Encrypted: i=1; AJvYcCUvkrVFIy1TkqvXX/LKltzUcJnibsuzU9BTh7Ahs/3kncwfPWecr0tdybr4zn912nb9UpEhEPMew8pOhCoECCSKhvdedvgBxysFrBtG X-Gm-Message-State: AOJu0YyT4qVzdspEsK7ZFbKEMjWPczcoQErThYOibgx5PhdPlRkiGyqG A9UTHbGIQlv5niQqzMnqCftGuO385QeLuZrbfHung7xEWKgMhZU2FlX1gz9k+FXnFUO+Pqq/KrX 4 X-Received: by 2002:a17:902:d30d:b0:1f4:990c:5ef1 with SMTP id d9443c01a7336-1f6370250c8mr24670045ad.31.1717176516593; Fri, 31 May 2024 10:28:36 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:a236:3f96:dc60:48b4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ded40sm19286015ad.169.2024.05.31.10.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 10:28:36 -0700 (PDT) Date: Fri, 31 May 2024 11:28:33 -0600 From: Mathieu Poirier To: Arnaud POULIQUEN Cc: Bjorn Andersson , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH v5 5/7] remoteproc: core: support of the tee interface Message-ID: References: <20240521081001.2989417-1-arnaud.pouliquen@foss.st.com> <20240521081001.2989417-6-arnaud.pouliquen@foss.st.com> <5b3f8346-d6db-4da3-9613-20cf9f3c226b@foss.st.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: <5b3f8346-d6db-4da3-9613-20cf9f3c226b@foss.st.com> On Thu, May 30, 2024 at 09:42:26AM +0200, Arnaud POULIQUEN wrote: > Hello Mathieu, > > On 5/29/24 22:35, Mathieu Poirier wrote: > > On Wed, May 29, 2024 at 09:13:26AM +0200, Arnaud POULIQUEN wrote: > >> Hello Mathieu, > >> > >> On 5/28/24 23:30, Mathieu Poirier wrote: > >>> On Tue, May 21, 2024 at 10:09:59AM +0200, Arnaud Pouliquen wrote: > >>>> 1) on start: > >>>> - Using the TEE loader, the resource table is loaded by an external entity. > >>>> In such case the resource table address is not find from the firmware but > >>>> provided by the TEE remoteproc framework. > >>>> Use the rproc_get_loaded_rsc_table instead of rproc_find_loaded_rsc_table > >>>> - test that rproc->cached_table is not null before performing the memcpy > >>>> > >>>> 2)on stop > >>>> The use of the cached_table seems mandatory: > >>>> - during recovery sequence to have a snapshot of the resource table > >>>> resources used, > >>>> - on stop to allow for the deinitialization of resources after the > >>>> the remote processor has been shutdown. > >>>> However if the TEE interface is being used, we first need to unmap the > >>>> table_ptr before setting it to rproc->cached_table. > >>>> The update of rproc->table_ptr to rproc->cached_table is performed in > >>>> tee_remoteproc. > >>>> > >>>> Signed-off-by: Arnaud Pouliquen > >>>> --- > >>>> drivers/remoteproc/remoteproc_core.c | 31 +++++++++++++++++++++------- > >>>> 1 file changed, 23 insertions(+), 8 deletions(-) > >>>> > >>>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > >>>> index 42bca01f3bde..3a642151c983 100644 > >>>> --- a/drivers/remoteproc/remoteproc_core.c > >>>> +++ b/drivers/remoteproc/remoteproc_core.c > >>>> @@ -1267,6 +1267,7 @@ EXPORT_SYMBOL(rproc_resource_cleanup); > >>>> static int rproc_set_rsc_table_on_start(struct rproc *rproc, const struct firmware *fw) > >>>> { > >>>> struct resource_table *loaded_table; > >>>> + struct device *dev = &rproc->dev; > >>>> > >>>> /* > >>>> * The starting device has been given the rproc->cached_table as the > >>>> @@ -1276,12 +1277,21 @@ static int rproc_set_rsc_table_on_start(struct rproc *rproc, const struct firmwa > >>>> * this information to device memory. We also update the table_ptr so > >>>> * that any subsequent changes will be applied to the loaded version. > >>>> */ > >>>> - loaded_table = rproc_find_loaded_rsc_table(rproc, fw); > >>>> - if (loaded_table) { > >>>> - memcpy(loaded_table, rproc->cached_table, rproc->table_sz); > >>>> - rproc->table_ptr = loaded_table; > >>>> + if (rproc->tee_interface) { > >>>> + loaded_table = rproc_get_loaded_rsc_table(rproc, &rproc->table_sz); > >>>> + if (IS_ERR(loaded_table)) { > >>>> + dev_err(dev, "can't get resource table\n"); > >>>> + return PTR_ERR(loaded_table); > >>>> + } > >>>> + } else { > >>>> + loaded_table = rproc_find_loaded_rsc_table(rproc, fw); > >>>> } > >>>> > >>>> + if (loaded_table && rproc->cached_table) > >>>> + memcpy(loaded_table, rproc->cached_table, rproc->table_sz); > >>>> + > >>> > >>> Why is this not part of the else {} above as it was the case before this patch? > >>> And why was an extra check for ->cached_table added? > >> > >> Here we have to cover 2 use cases if rproc->tee_interface is set. > >> 1) The remote processor is in stop state > >> - loaded_table points to the resource table in the remote memory and > >> - rproc->cached_table is null > >> => no memcopy > >> 2) crash recovery > >> - loaded_table points to the resource table in the remote memory > >> - rproc-cached_table point to a copy of the resource table > > > > A cached_table exists because it was created in rproc_reset_rsc_table_on_stop(). > > But as the comment says [1], that part of the code was meant to be used for the > > attach()/detach() use case. Mixing both will become extremely confusing and > > impossible to maintain. > > i am not sure to understand your point here... the cached_table table was > already existing for the "normal" case[2]. Seems to me that the cache table is > needed on stop in all scenarios. > > [2] > https://elixir.bootlin.com/linux/v4.20.17/source/drivers/remoteproc/remoteproc_core.c#L1402 > > > > > I think the TEE scenario should be as similar as the "normal" one where TEE is > > not involved. To that end, I suggest to create a cached_table in > > tee_rproc_parse_fw(), exactly the same way it is done in > > rproc_elf_load_rsc_table(). That way the code path in > > rproc_set_rsc_table_on_start() become very similar and we have a cached_table to > > work with when the remote processor is recovered. In fact we may not need > > rproc_set_rsc_table_on_start() at all but that needs to be asserted. > > This is was I proposed in my V4 [3]. Could you please confirm that this aligns > with what you have in mind? After spending more time on this I have the following 3 observations: 1) We need a ->cached_table, otherwise the crash recovery path gets really messy. 2) It _might_ be a good idea to rename tee_rproc_get_loaded_rsc_table() to tee_rproc_find_loaded_rsc_table() to be aligned with the scenario where the firmware is loaded by the remoteproc core. I think you had tee_rproc_find_loaded_rsc_table() in the first place and I asked you to change it. If so, apologies - reviewing patches isn't an exact science. 3) The same way ->cached_table is created in rproc_elf_load_rsc_table(), which is essentially ops::parse_fw(), we should create one in tee_rproc_parse_fw() with a kmemdup(). Exactly the same as in rproc_elf_load_rsc_table(). In tee_rproc_parse_fw(), @rsc_table should be iounmap'ed right away so that we don't need to keep a local variable to free it later. In rproc_start() the call to rproc_find_loaded_rsc_table() will get another mapped handle to the resource table in memory. It might be a little unefficient but it sure beats doing a lot of modifications in the core. As I said above this isn't an exact science and we may need to changes more things but at least it should take us a little further. Thanks, Mathieu > In such a case, should I keep the updates below in > rproc_reset_rsc_table_on_stop(), or should I revert to using rproc->rsc_table to > store the pointer to the resource table in tee_remoteproc for the associated > memory map/unmap?" > > [3] > https://patchwork.kernel.org/project/linux-remoteproc/patch/20240308144708.62362-2-arnaud.pouliquen@foss.st.com/ > > Thanks, > Arnaud > > > > > [1]. https://elixir.bootlin.com/linux/v6.10-rc1/source/drivers/remoteproc/remoteproc_core.c#L1565 > > > >> => need to perform the memcpy to reapply settings in the resource table > >> > >> I can duplicate the memcpy in if{} and else{} but this will be similar code > >> as needed in both case. > >> Adding rproc->cached_table test if proc->tee_interface=NULL seems also > >> reasonable as a memcpy from 0 should not be performed. > >> > >> > >>> > >>> This should be a simple change, i.e introduce an if {} else {} block to take > >>> care of the two scenarios. Plus the comment is misplaced now. > >> > >> What about split it in 2 patches? > >> - one adding the test on rproc->cached_table for the memcpy > >> - one adding the if {} else {}? > >> > >> Thanks, > >> Arnaud > >> > >> > >>> > >>> More comments tomorrow. > >>> > >>> Thanks, > >>> Mathieu > >>> > >>>> + rproc->table_ptr = loaded_table; > >>>> + > >>>> return 0; > >>>> } > >>>> > >>>> @@ -1318,11 +1328,16 @@ static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) > >>>> kfree(rproc->clean_table); > >>>> > >>>> out: > >>>> - /* > >>>> - * Use a copy of the resource table for the remainder of the > >>>> - * shutdown process. > >>>> + /* If the remoteproc_tee interface is used, then we have first to unmap the resource table > >>>> + * before updating the proc->table_ptr reference. > >>>> */ > >>>> - rproc->table_ptr = rproc->cached_table; > >>>> + if (!rproc->tee_interface) { > >>>> + /* > >>>> + * Use a copy of the resource table for the remainder of the > >>>> + * shutdown process. > >>>> + */ > >>>> + rproc->table_ptr = rproc->cached_table; > >>>> + } > >>>> return 0; > >>>> } > >>>> > >>>> -- > >>>> 2.25.1 > >>>>