From nobody Thu Oct 2 03:32:48 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6A61278165; Wed, 24 Sep 2025 07:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758699618; cv=none; b=K3sG9gOarZI7HYlKOOnpTpkx2FFB8JzniJSlTdmhoWyDjTbg5sHXKuhnWPwYqW7cMRyhRS341nuyCPhFOHw9lDt9rMp/cfhulidcZyNRC+x+rh5bPKI9SWVRCWtxXiNlsg0m0UgkOTsfhG1ZBGESBmgdHoiv0PSlovXk3y9YmSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758699618; c=relaxed/simple; bh=vjv0APeeoG1fWjX2XoSPj9yPRXUWX7UbrjgPR60waKc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nVAHJ+q30P4tAnSUAFP7v/rjSsI45lCAfJasS/9fQn0SVn7IYTSzEKb1eaDlOML2deCiqSPtZyULIcERPo53OxCC1/WTPM/QxiFiDLZXnJM42v4KDk1bnzLufF1eiic2bpYjxu0l2UzLsD+cHTNzjO/BgaKwF4EllVENmLVLuUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qRWUHvej; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qRWUHvej" Received: by smtp.kernel.org (Postfix) with ESMTPS id 82C09C116B1; Wed, 24 Sep 2025 07:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758699617; bh=vjv0APeeoG1fWjX2XoSPj9yPRXUWX7UbrjgPR60waKc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qRWUHvej3KrqHBSHrjNf00Y33uf0kQNbgScAbKcpsDFpx5f+xHH2CJnA3steXi9R6 3cJieJeW19dGpN6cML0jqHRc7H6bn81iLatuzGNE/jrvWiYSo+ebkgujkkFm0Wu6AH wIzYwMdxGo/jmHKjVMDTo3c3wWNgRUp4dnKPDem7CCZqQkvZbULSLSXPG1m2C/U+WR dwbvDLW2gF0vhzVkf/qmkqL5K2sFhogUD8JyOvp2e3JLFf+foiIhcZxoACkbGAHslt xbkBJrnkQ4KFM1fuvrN/48v93XB/NdTgTH224MC1AThOaozfHliUdeOc1PFo8SmJfx nmUIYc25waIVg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DDE0CAC59A; Wed, 24 Sep 2025 07:40:17 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Wed, 24 Sep 2025 15:39:50 +0800 Subject: [PATCH RESEND v6 1/4] firmware: stratix10-svc: Add mutex in stratix10 memory management 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250924-sip_svc_upstream-v6-1-c88ef68bf24e@altera.com> References: <20250924-sip_svc_upstream-v6-0-c88ef68bf24e@altera.com> In-Reply-To: <20250924-sip_svc_upstream-v6-0-c88ef68bf24e@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao , Richard Gong , Alan Tull , Greg Kroah-Hartman Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758699615; l=2636; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=J8C8plJk1PvTp7FsIIIEajn58AqxeR5Do+hcdH7Sil4=; b=qP9k+NFJ8Vjh1ho7xUbAVxL8sRldTBflS6e3WQp1AhTsLGAuK83fCdVOJztcODTBKonk52tSU GdVe/xXdPwACjWZauwTgdQMpB8rfF5WTtcCi2o75JwXftUglZRXli7F X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Add mutex lock to stratix10_svc_allocate_memory and stratix10_svc_free_memory for thread safety. This prevents race conditions and ensures proper synchronization during memory operations. This is required for parallel communication with the Stratix10 service channel. Fixes: 7ca5ce896524f ("firmware: add Intel Stratix10 service layer driver") Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach Signed-off-by: Dinh Nguyen --- drivers/firmware/stratix10-svc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index e3f990d888d71829f0ab22b8a59aa7af0316bea0..11285df8681bfac71c9bace6b7d= 39c1848f40f08 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #include @@ -172,6 +173,12 @@ struct stratix10_svc_chan { static LIST_HEAD(svc_ctrl); static LIST_HEAD(svc_data_mem); =20 +/** + * svc_mem_lock protects access to the svc_data_mem list for + * concurrent multi-client operations + */ +static DEFINE_MUTEX(svc_mem_lock); + /** * svc_pa_to_va() - translate physical address to virtual address * @addr: to be translated physical address @@ -184,6 +191,7 @@ static void *svc_pa_to_va(unsigned long addr) struct stratix10_svc_data_mem *pmem; =20 pr_debug("claim back P-addr=3D0x%016x\n", (unsigned int)addr); + guard(mutex)(&svc_mem_lock); list_for_each_entry(pmem, &svc_data_mem, node) if (pmem->paddr =3D=3D addr) return pmem->vaddr; @@ -990,6 +998,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan,= void *msg) p_data->flag =3D ct->flags; } } else { + guard(mutex)(&svc_mem_lock); list_for_each_entry(p_mem, &svc_data_mem, node) if (p_mem->vaddr =3D=3D p_msg->payload) { p_data->paddr =3D p_mem->paddr; @@ -1072,6 +1081,7 @@ void *stratix10_svc_allocate_memory(struct stratix10_= svc_chan *chan, if (!pmem) return ERR_PTR(-ENOMEM); =20 + guard(mutex)(&svc_mem_lock); va =3D gen_pool_alloc(genpool, s); if (!va) return ERR_PTR(-ENOMEM); @@ -1100,6 +1110,7 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kadd= r) { struct stratix10_svc_data_mem *pmem; + guard(mutex)(&svc_mem_lock); =20 list_for_each_entry(pmem, &svc_data_mem, node) if (pmem->vaddr =3D=3D kaddr) { --=20 2.35.3