Skip to content

Commit 19b8766

Browse files
committed
firmware: arm_ffa: Fix FFA device names for logical partitions
Each physical partition can provide multiple services each with UUID. Each such service can be presented as logical partition with a unique combination of VM ID and UUID. The number of distinct UUID in a system will be less than or equal to the number of logical partitions. However, currently it fails to register more than one logical partition or service within a physical partition as the device name contains only VM ID while both VM ID and UUID are maintained in the partition information. The kernel complains with the below message: | sysfs: cannot create duplicate filename '/devices/arm-ffa-8001' | CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.3.0-rc7 #8 | Hardware name: FVP Base RevC (DT) | Call trace: | dump_backtrace+0xf8/0x118 | show_stack+0x18/0x24 | dump_stack_lvl+0x50/0x68 | dump_stack+0x18/0x24 | sysfs_create_dir_ns+0xe0/0x13c | kobject_add_internal+0x220/0x3d4 | kobject_add+0x94/0x100 | device_add+0x144/0x5d8 | device_register+0x20/0x30 | ffa_device_register+0x88/0xd8 | ffa_setup_partitions+0x108/0x1b8 | ffa_init+0x2ec/0x3a4 | do_one_initcall+0xcc/0x240 | do_initcall_level+0x8c/0xac | do_initcalls+0x54/0x94 | do_basic_setup+0x1c/0x28 | kernel_init_freeable+0x100/0x16c | kernel_init+0x20/0x1a0 | ret_from_fork+0x10/0x20 | kobject_add_internal failed for arm-ffa-8001 with -EEXIST, don't try to | register things with the same name in the same directory. | arm_ffa arm-ffa: unable to register device arm-ffa-8001 err=-17 | ARM FF-A: ffa_setup_partitions: failed to register partition ID 0x8001 By virtue of being random enough to avoid collisions when generated in a distributed system, there is no way to compress UUID keys to the number of bits required to identify each. We can eliminate '-' in the name but it is not worth eliminating 4 bytes and add unnecessary logic for doing that. Also v1.0 doesn't provide the UUID of the partitions which makes it hard to use the same for the device name. So to keep it simple, let us alloc an ID using ida_alloc() and append the same to "arm-ffa" to make up a unique device name. Also stash the id value in ffa_dev to help freeing the ID later when the device is destroyed. Fixes: e781858 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration") Reported-by: Lucian Paul-Trifu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent c6e0453 commit 19b8766

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

drivers/firmware/arm_ffa/bus.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "common.h"
1717

18+
static DEFINE_IDA(ffa_bus_id);
19+
1820
static int ffa_device_match(struct device *dev, struct device_driver *drv)
1921
{
2022
const struct ffa_device_id *id_table;
@@ -131,6 +133,7 @@ static void ffa_release_device(struct device *dev)
131133
{
132134
struct ffa_device *ffa_dev = to_ffa_dev(dev);
133135

136+
ida_free(&ffa_bus_id, ffa_dev->id);
134137
kfree(ffa_dev);
135138
}
136139

@@ -171,18 +174,24 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev)
171174
struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
172175
const struct ffa_ops *ops)
173176
{
174-
int ret;
177+
int id, ret;
175178
struct device *dev;
176179
struct ffa_device *ffa_dev;
177180

181+
id = ida_alloc_min(&ffa_bus_id, 1, GFP_KERNEL);
182+
if (id < 0)
183+
return NULL;
184+
178185
ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL);
179-
if (!ffa_dev)
186+
if (!ffa_dev) {
187+
ida_free(&ffa_bus_id, id);
180188
return NULL;
189+
}
181190

182191
dev = &ffa_dev->dev;
183192
dev->bus = &ffa_bus_type;
184193
dev->release = ffa_release_device;
185-
dev_set_name(&ffa_dev->dev, "arm-ffa-%04x", vm_id);
194+
dev_set_name(&ffa_dev->dev, "arm-ffa-%d", id);
186195

187196
ffa_dev->vm_id = vm_id;
188197
ffa_dev->ops = ops;
@@ -218,4 +227,5 @@ void arm_ffa_bus_exit(void)
218227
{
219228
ffa_devices_unregister();
220229
bus_unregister(&ffa_bus_type);
230+
ida_destroy(&ffa_bus_id);
221231
}

include/linux/arm_ffa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
/* FFA Bus/Device/Driver related */
9898
struct ffa_device {
99+
u32 id;
99100
int vm_id;
100101
bool mode_32bit;
101102
uuid_t uuid;

0 commit comments

Comments
 (0)