genirq: Properly pair kobject_del with kobject_add
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
[email protected]
maintainerQuoted 22 lines · Michael Kelley
If
alloc_descsfails beforeirq_sysfs_inithas run,free_descin the cleanup path will callkobject_deleven though the kobject has not been added withkobject_add. Fix this by making the call tokobject_delconditional on whetherirq_sysfs_inithas run.This problem surfaced because commit
aa30f47cf666("kobject: Add support for default attribute groups tokobj_type") makeskobject_delstricter about pairing withkobject_add. If the pairing is incorrrect, a WARNING and backtrace occur insysfs_remove_groupbecause there is no parent.Fixes ecb3f394c5db ("genirq: Expose interrupt information through sysfs")Signed-off-by Michael Kelley <[email protected]>--- kernel/irq/irqdesc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/irq/irqdesc.c +0
-0
kernel/irq/irqdesc.c static void free_desc(unsigned int irq) · line 442
Quoted 6 lines
kernel/irq/irqdesc.c +2
-1@@ -438,7 +438,8 @@ static void free_desc(unsigned int irq)* The sysfs entry must be serialized against a concurrent * irq_sysfs_init() as well. */ -kobject_del (&desc->kobj); +if (irq_kobj_base) +kobject_del (&desc->kobj);
But now you leak the memory of desc as there is no chance it could be freed, because the kobject release function is never called :(
Relying on irq_kobj_bas to be present or not seems like an odd test here.
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): MWHPR21MB078463AB854A336842118405D7D90@MWHPR21MB0784.namprd21.prod.outlook.com
Quoted 50 lines · Michael Kelley
From: [email protected] <[email protected]> Sent: Thursday, August 1, 2019 11:34 PM
Quoted 18 lines · Michael Kelley
Quoted 17 lines
If
alloc_descsfails beforeirq_sysfs_inithas run,free_descin the cleanup path will callkobject_deleven though the kobject has not been added withkobject_add. Fix this by making the call tokobject_delconditional on whetherirq_sysfs_inithas run.This problem surfaced because commit
aa30f47cf666("kobject: Add support for default attribute groups tokobj_type") makeskobject_delstricter about pairing withkobject_add. If the pairing is incorrrect, a WARNING and backtrace occur insysfs_remove_groupbecause there is no parent.Fixes ecb3f394c5db ("genirq: Expose interrupt information through sysfs")Signed-off-by Michael Kelley <[email protected]>--- kernel/irq/irqdesc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
kernel/irq/irqdesc.c static void free_desc(unsigned int irq) · line 442
Quoted 11 lines
kernel/irq/irqdesc.c +2
-1@@ -438,7 +438,8 @@ static void free_desc(unsigned int irq)* The sysfs entry must be serialized against a concurrent * irq_sysfs_init() as well. */ -kobject_del (&desc->kobj); +if (irq_kobj_base) +kobject_del (&desc->kobj);But now you leak the memory of desc as there is no chance it could be freed, because the kobject release function is never called :(
In the
alloc_descserror path, whenirq_kobj_baseis still NULL, the kobject code sequence is:
kobject_init()[as called byalloc_desc]
kobject_put()[as called bydelayed_free_desc]So I don't think anything leaks.
If
irq_kobj_baseis not NULL, the kobject code sequence is:
kobject_init()[as called byalloc_desc]
kobject_add()[as called byirq_sysfs_add]
kobject_del()[as called byfree_desc]
kobject_put()[as called bydelayed_free_desc]Again, everything is paired up properly.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Relying on
irq_kobj_baseto be present or not seems like an odd test here.It's the same test that is used in
irq_sysfs_addto decide whether to callkobject_add. So it makes everything paired up and symmetrical.
Ugh, that's a tangled mess and totally not obvious at all. I'm sure there's a good reason for all of that, and I really don't want to know :)
Anyway, yes, you are right, the patch is fine, sorry for the noise.
greg k-h
Quoted 11 lines · On Sat, 3 Aug 2019, [email protected] wrote:
Quoted 6 lines · Michael Kelley
Quoted 3 lines
Relying on
irq_kobj_baseto be present or not seems like an odd test here.It's the same test that is used in
irq_sysfs_addto decide whether to callkobject_add. So it makes everything paired up and symmetrical.Ugh, that's a tangled mess and totally not obvious at all. I'm sure there's a good reason for all of that, and I really don't want to know :)
It's all your fault that the sysfs stuff does not work in very early boot.
/me runs
tip-bot for Michael Kelley
merge bot[tip:irq/urgent] genirq: Properly pair kobject_del() with kobject_add()
In reply to a message not in the archivegenirq: Properly pair kobject_del() with kobject_add()
Commit-ID: e1ee29624746fbf667f80e8ae3815a76e4d1bd5b Gitweb: https://git.kernel.org/tip/e1ee29624746fbf667f80e8ae3815a76e4d1bd5b Author: Michael Kelley <[email protected]> AuthorDate: Thu, 1 Aug 2019 23:53:53 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Mon, 19 Aug 2019 15:56:28 +0200
genirq: Properly pair kobject_del() with kobject_add()
If alloc_descs() fails before irq_sysfs_init() has run, free_desc() in the cleanup path will call kobject_del() even though the kobject has not been added with kobject_add().
Fix this by making the call to kobject_del() conditional on whether irq_sysfs_init() has run.
This problem surfaced because commit aa30f47cf666 ("kobject: Add support for default attribute groups to kobj_type") makes kobject_del() stricter about pairing with kobject_add(). If the pairing is incorrrect, a WARNING and backtrace occur in sysfs_remove_group() because there is no parent.
[ tglx: Add a comment to the code ]
--- kernel/irq/irqdesc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/irq/irqdesc.c +7 -1
@@ -437,8 +437,14 @@ static void free_desc(unsigned int irq)* * The sysfs entry must be serialized against a concurrent * irq_sysfs_init() as well. +* +* If irq_sysfs_init() has not yet been invoked (early boot), then +* irq_kobj_base is NULL and the descriptor was never added. +* kobject_del() complains about a object with no parent, so make +* it conditional. */ -kobject_del (&desc->kobj); +if (irq_kobj_base) +kobject_del (&desc->kobj);delete_irq_desc (irq);/*
A message that is not in the archive (sent off-list or not yet received): [email protected]
RE: [tip:irq/urgent] genirq: Properly pair kobject_del() with kobject_add()
From: Sasha Levin <[email protected]> Sent: Monday, August 19, 2019 2:28 PM
Quoted 18 lines
This commit has been processed because it contains a "Fixes:" tag, fixing commit:
ecb3f394c5dbgenirq: Expose interrupt information through sysfs.The bot has tested the following trees: v5.2.9, v4.19.67, v4.14.139, v4.9.189.
v5.2.9: Build failed! Errors:
kernel/irq/irqdesc.c:446:6: error: ‘irq_kobj_base’ undeclared (first use in this function);did you mean ‘irq_kobj_type’?
v4.19.67: Build failed! Errors:
kernel/irq/irqdesc.c:445:6: error: ‘irq_kobj_base’ undeclared (first use in this function);did you mean ‘irq_kobj_type’?
v4.14.139: Build failed! Errors:
kernel/irq/irqdesc.c:428:6: error: ‘irq_kobj_base’ undeclared (first use in this function);did you mean ‘irq_kobj_type’?
Quoted 8 lines
v4.9.189: Build failed! Errors:
kernel/irq/irqdesc.c:414:6: error: ‘irq_kobj_base’ undeclared (first use in this function);did you mean ‘irq_kobj_type’?
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Compile error occurs when CONFIG_SYSFS is not selected. It's probably cleanest to
revert the current patch. I'll send out a new version that fixes the problem.
Michael