Skip to content

Commit ea5abb0

Browse files
sudeep-hollasmb49
authored andcommitted
firmware: arm_ffa: Fix FFA device names for logical partitions
BugLink: https://bugs.launchpad.net/bugs/2028701 commit 19b8766 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 990b777 commit ea5abb0

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

@@ -170,18 +173,24 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev)
170173

171174
struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id)
172175
{
173-
int ret;
176+
int id, ret;
174177
struct device *dev;
175178
struct ffa_device *ffa_dev;
176179

180+
id = ida_alloc_min(&ffa_bus_id, 1, GFP_KERNEL);
181+
if (id < 0)
182+
return NULL;
183+
177184
ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL);
178-
if (!ffa_dev)
185+
if (!ffa_dev) {
186+
ida_free(&ffa_bus_id, id);
179187
return NULL;
188+
}
180189

181190
dev = &ffa_dev->dev;
182191
dev->bus = &ffa_bus_type;
183192
dev->release = ffa_release_device;
184-
dev_set_name(&ffa_dev->dev, "arm-ffa-%04x", vm_id);
193+
dev_set_name(&ffa_dev->dev, "arm-ffa-%d", id);
185194

186195
ffa_dev->vm_id = vm_id;
187196
uuid_copy(&ffa_dev->uuid, uuid);
@@ -216,4 +225,5 @@ void arm_ffa_bus_exit(void)
216225
{
217226
ffa_devices_unregister();
218227
bus_unregister(&ffa_bus_type);
228+
ida_destroy(&ffa_bus_id);
219229
}

include/linux/arm_ffa.h

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

1414
/* FFA Bus/Device/Driver related */
1515
struct ffa_device {
16+
u32 id;
1617
int vm_id;
1718
bool mode_32bit;
1819
uuid_t uuid;

0 commit comments

Comments
 (0)