Skip to content

Commit 6fe437c

Browse files
LeviYeoReumsudeep-holla
authored andcommitted
firmware: arm_ffa: Fix the race around setting ffa_dev->properties
Currently, ffa_dev->properties is set after the ffa_device_register() call return in ffa_setup_partitions(). This could potentially result in a race where the partition's properties is accessed while probing struct ffa_device before it is set. Update the ffa_device_register() to receive ffa_partition_info so all the data from the partition information received from the firmware can be updated into the struct ffa_device before the calling device_register() in ffa_device_register(). Fixes: e781858 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration") Signed-off-by: Levi Yun <[email protected]> Message-Id: <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 40384c8 commit 6fe437c

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

drivers/firmware/arm_ffa/bus.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,18 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev)
187187
return valid;
188188
}
189189

190-
struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
191-
const struct ffa_ops *ops)
190+
struct ffa_device *
191+
ffa_device_register(const struct ffa_partition_info *part_info,
192+
const struct ffa_ops *ops)
192193
{
193194
int id, ret;
195+
uuid_t uuid;
194196
struct device *dev;
195197
struct ffa_device *ffa_dev;
196198

199+
if (!part_info)
200+
return NULL;
201+
197202
id = ida_alloc_min(&ffa_bus_id, 1, GFP_KERNEL);
198203
if (id < 0)
199204
return NULL;
@@ -210,9 +215,11 @@ struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
210215
dev_set_name(&ffa_dev->dev, "arm-ffa-%d", id);
211216

212217
ffa_dev->id = id;
213-
ffa_dev->vm_id = vm_id;
218+
ffa_dev->vm_id = part_info->id;
219+
ffa_dev->properties = part_info->properties;
214220
ffa_dev->ops = ops;
215-
uuid_copy(&ffa_dev->uuid, uuid);
221+
import_uuid(&uuid, (u8 *)part_info->uuid);
222+
uuid_copy(&ffa_dev->uuid, &uuid);
216223

217224
ret = device_register(&ffa_dev->dev);
218225
if (ret) {

drivers/firmware/arm_ffa/driver.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,6 @@ static struct notifier_block ffa_bus_nb = {
13871387
static int ffa_setup_partitions(void)
13881388
{
13891389
int count, idx, ret;
1390-
uuid_t uuid;
13911390
struct ffa_device *ffa_dev;
13921391
struct ffa_dev_part_info *info;
13931392
struct ffa_partition_info *pbuf, *tpbuf;
@@ -1406,23 +1405,19 @@ static int ffa_setup_partitions(void)
14061405

14071406
xa_init(&drv_info->partition_info);
14081407
for (idx = 0, tpbuf = pbuf; idx < count; idx++, tpbuf++) {
1409-
import_uuid(&uuid, (u8 *)tpbuf->uuid);
1410-
14111408
/* Note that if the UUID will be uuid_null, that will require
14121409
* ffa_bus_notifier() to find the UUID of this partition id
14131410
* with help of ffa_device_match_uuid(). FF-A v1.1 and above
14141411
* provides UUID here for each partition as part of the
14151412
* discovery API and the same is passed.
14161413
*/
1417-
ffa_dev = ffa_device_register(&uuid, tpbuf->id, &ffa_drv_ops);
1414+
ffa_dev = ffa_device_register(tpbuf, &ffa_drv_ops);
14181415
if (!ffa_dev) {
14191416
pr_err("%s: failed to register partition ID 0x%x\n",
14201417
__func__, tpbuf->id);
14211418
continue;
14221419
}
14231420

1424-
ffa_dev->properties = tpbuf->properties;
1425-
14261421
if (drv_info->version > FFA_VERSION_1_0 &&
14271422
!(tpbuf->properties & FFA_PARTITION_AARCH64_EXEC))
14281423
ffa_mode_32bit_set(ffa_dev);

include/linux/arm_ffa.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,22 @@ static inline void *ffa_dev_get_drvdata(struct ffa_device *fdev)
166166
return dev_get_drvdata(&fdev->dev);
167167
}
168168

169+
struct ffa_partition_info;
170+
169171
#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
170-
struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
171-
const struct ffa_ops *ops);
172+
struct ffa_device *
173+
ffa_device_register(const struct ffa_partition_info *part_info,
174+
const struct ffa_ops *ops);
172175
void ffa_device_unregister(struct ffa_device *ffa_dev);
173176
int ffa_driver_register(struct ffa_driver *driver, struct module *owner,
174177
const char *mod_name);
175178
void ffa_driver_unregister(struct ffa_driver *driver);
176179
bool ffa_device_is_valid(struct ffa_device *ffa_dev);
177180

178181
#else
179-
static inline
180-
struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
181-
const struct ffa_ops *ops)
182+
static inline struct ffa_device *
183+
ffa_device_register(const struct ffa_partition_info *part_info,
184+
const struct ffa_ops *ops)
182185
{
183186
return NULL;
184187
}

0 commit comments

Comments
 (0)