Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firmware: stratix10-svc: Add mutex in stratix10 memory management

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")
Cc: stable@vger.kernel.org
Signed-off-by: Mahesh Rao <mahesh.rao@altera.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@altera.com>
Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>

authored by

Mahesh Rao and committed by
Dinh Nguyen
85f96cbb 4f49088c

+11
+11
drivers/firmware/stratix10-svc.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 3 * Copyright (C) 2017-2018, Intel Corporation 4 + * Copyright (C) 2025, Altera Corporation 4 5 */ 5 6 6 7 #include <linux/completion.h> ··· 174 173 static LIST_HEAD(svc_data_mem); 175 174 176 175 /** 176 + * svc_mem_lock protects access to the svc_data_mem list for 177 + * concurrent multi-client operations 178 + */ 179 + static DEFINE_MUTEX(svc_mem_lock); 180 + 181 + /** 177 182 * svc_pa_to_va() - translate physical address to virtual address 178 183 * @addr: to be translated physical address 179 184 * ··· 191 184 struct stratix10_svc_data_mem *pmem; 192 185 193 186 pr_debug("claim back P-addr=0x%016x\n", (unsigned int)addr); 187 + guard(mutex)(&svc_mem_lock); 194 188 list_for_each_entry(pmem, &svc_data_mem, node) 195 189 if (pmem->paddr == addr) 196 190 return pmem->vaddr; ··· 1010 1002 p_data->flag = ct->flags; 1011 1003 } 1012 1004 } else { 1005 + guard(mutex)(&svc_mem_lock); 1013 1006 list_for_each_entry(p_mem, &svc_data_mem, node) 1014 1007 if (p_mem->vaddr == p_msg->payload) { 1015 1008 p_data->paddr = p_mem->paddr; ··· 1093 1084 if (!pmem) 1094 1085 return ERR_PTR(-ENOMEM); 1095 1086 1087 + guard(mutex)(&svc_mem_lock); 1096 1088 va = gen_pool_alloc(genpool, s); 1097 1089 if (!va) 1098 1090 return ERR_PTR(-ENOMEM); ··· 1122 1112 void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) 1123 1113 { 1124 1114 struct stratix10_svc_data_mem *pmem; 1115 + guard(mutex)(&svc_mem_lock); 1125 1116 1126 1117 list_for_each_entry(pmem, &svc_data_mem, node) 1127 1118 if (pmem->vaddr == kaddr) {