perf/x86/intel/uncore: Fix iounmap() leak on global_init failure
Subsystems (3)
PATCH v2 1/1 perf/x86/intel/uncore: Fix iounmap() leak on global_init failure
Kernel test robot reported:
Unverified Error/Warning (likely false positive, kindly check if interested):
arch/x86/events/intel/uncore_discovery.c:293:2-8:
ERROR: missing iounmap; ioremap on line 288 and execution via conditional on line 292
If domain->global_init() fails in __parse_discovery_table(), the ioremap'ed MMIO region is not released before returning, resulting in an MMIO mapping leak.
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/x86/events/intel/uncore_discovery.c +10 -5
@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,struct uncore_unit_discovery unit;void __iomem *io_addr;unsigned long size; +int ret =0 ;int i; size =UNCORE_DISCOVERY_GLOBAL_MAP_SIZE ;
@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,/* Read Global Discovery State */ memcpy_fromio (&global, io_addr,sizeof (struct uncore_global_discovery )); +iounmap (io_addr); +if (uncore_discovery_invalid_unit (global)) {pr_info ("Invalid Global Discovery State: 0x%llx 0x%llx 0x%llx\n" , global.table1, global.ctl, global.table3); -iounmap (io_addr);return -EINVAL ; } -iounmap (io_addr); size = (1 + global.max_units) * global.stride *8 ; io_addr =ioremap (addr, size);if (!io_addr)return -ENOMEM ; -if (domain->global_init && domain->global_init (global.ctl)) -return -ENODEV ; +if (domain->global_init && domain->global_init (global.ctl)) { + ret = -ENODEV ; + goto out; + }/* Parsing Unit Discovery State */ for (i =0 ; i < global.max_units; i++) {
@@ -307,8 +310,10 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, } *parsed = true; + +out:iounmap (io_addr); -return 0 ; +return ret; } static int parse_discovery_table(struct uncore_discovery_domain *domain,
Signature · 1 line
2.52.0
Quoted 1 line
Kernel test robot reported:
Is this duplicate information according to a known tag?
Quoted 5 lines
Unverified Error/Warning (likely false positive, kindly check if interested):
arch/x86/events/intel/uncore_discovery.c:293:2-8:
ERROR: missing iounmap; ioremap on line 288 and execution via conditional on line 292
See also:
https://elixir.bootlin.com/linux/v6.19-rc5/source/scripts/coccinelle/free/iounmap.cocci#L2-L8
Quoted 5 lines
If
domain->global_init()fails in__parse_discovery_table(), the ioremap'ed MMIO region is not released before returning, resulting in an MMIO mapping leak.Reported-by kernel test robot <[email protected]>
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94
Will another imperative wording approach become helpful for an improved change description?
…
Quoted 2 lines
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++-----
…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n310
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinements
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.carch/x86/events/intel/uncore_discovery.c +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,struct uncore_unit_discovery unit;void __iomem *io_addr;unsigned long size; +int ret =0 ;int i;
Would scope adjustments become helpful for any of these local variables?
Quoted 7 lines
arch/x86/events/intel/uncore_discovery.c +2
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,/* Read Global Discovery State */ memcpy_fromio (&global, io_addr,sizeof (struct uncore_global_discovery )); +iounmap (io_addr); +if (uncore_discovery_invalid_unit (global)) {
…
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 282
Quoted 2 lines
arch/x86/events/intel/uncore_discovery.c +0
-1} -iounmap (io_addr);
Can this modification part be interpreted as an optimisation?
…
Quoted 6 lines
arch/x86/events/intel/uncore_discovery.c +4
-2-if (domain->global_init && domain->global_init (global.ctl)) -return -ENODEV ; +if (domain->global_init && domain->global_init (global.ctl)) { + ret = -ENODEV ; + goto out; + }
…
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 314
Quoted 3 lines
arch/x86/events/intel/uncore_discovery.c +2
-0*parsed = true; + +out:
Would an other label be a bit clearer here?
unmap_io:
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 317
Quoted 4 lines
arch/x86/events/intel/uncore_discovery.c +1
-1iounmap (io_addr); -return 0 ; +return ret; }
…
Regards,
Markus
Quoted 3 lines · Markus Elfring
Quoted 1 line
Kernel test robot reported:
Is this duplicate information according to a known tag?
I was trying to follow some examples of how test robot reports are shown in commit messages, for example:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/173058261037.3137.8690137124888546964.tip-bot2@tip-bot2/
Quoted 14 lines
Quoted 5 lines
Unverified Error/Warning (likely false positive, kindly check if interested):
arch/x86/events/intel/uncore_discovery.c:293:2-8:
ERROR: missing iounmap; ioremap on line 288 and execution via conditional on line 292See also:
https://elixir.bootlin.com/linux/v6.19-rc5/source/scripts/coccinelle/free/iounmap.cocci#L2-L8Quoted 4 lines
If
domain->global_init()fails in__parse_discovery_table(), the ioremap'ed MMIO region is not released before returning, resulting in an MMIO mapping leak.
Quoted 6 lines
Quoted 1 line
Reported-by kernel test robot <[email protected]>See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
Quoted 8 lines
…
Quoted 2 lines
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++-----…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n310
Yes, that was the intention for v2.
V2:
- As suggested by Markus, add an out label and use goto-based error handling to reduce duplicated iounmap() code.
- Add the original warning from the kernel test robot to the commit message.
- Trivial rewording of the commit message.
Quoted 5 lines
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinements
It seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
Quoted 10 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 8 lines
+++
b/arch/x86/events/intel/uncore_discovery.carch/x86/events/intel/uncore_discovery.c +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,struct uncore_unit_discovery unit;void __iomem *io_addr;unsigned long size; +int ret =0 ;int i;Would scope adjustments become helpful for any of these local variables?
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
https://lore.kernel.org/all/[email protected]/T/#t
Quoted 8 lines
Quoted 7 lines
arch/x86/events/intel/uncore_discovery.c +2
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,/* Read Global Discovery State */ memcpy_fromio (&global, io_addr,sizeof (struct uncore_global_discovery )); +iounmap (io_addr); +if (uncore_discovery_invalid_unit (global)) {…
Quoted 4 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 282
Quoted 2 lines
arch/x86/events/intel/uncore_discovery.c +0
-1} -iounmap (io_addr);Can this modification part be interpreted as an optimisation?
Yes, this is technically an optimization. Since the patch is already refactoring the iounmap() handling, my thinking was that it would be reasonable to include it in the same patch.
Quoted 8 lines
…
Quoted 6 lines
arch/x86/events/intel/uncore_discovery.c +4
-2-if (domain->global_init && domain->global_init (global.ctl)) -return -ENODEV ; +if (domain->global_init && domain->global_init (global.ctl)) { + ret = -ENODEV ; + goto out; + }…
Quoted 5 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 314
Quoted 3 lines
arch/x86/events/intel/uncore_discovery.c +2
-0*parsed = true; + +out:Would an other label be a bit clearer here?
I’d suggest keeping the label name out for style consistency, as mentioned in my earlier reply.
https://lore.kernel.org/all/[email protected]/T/#t
Quoted 12 lines
unmap_io:arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 317
Quoted 4 lines
arch/x86/events/intel/uncore_discovery.c +1
-1iounmap (io_addr); -return 0 ; +return ret; }…
Regards,
Markus
Quoted 8 lines
Quoted 4 lines
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
I hope that the understanding will improve somehow also for a development communication requirement like “imperative mood”.
Quoted 7 lines
Quoted 7 lines
…
Quoted 2 lines
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++-----…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
…
Quoted 5 lines
Yes, that was the intention for v2.
V2:
- As suggested by Markus, add anoutlabel and use goto-based error handling to reduce duplicatediounmap()code.
We are still trying to discuss the corresponding identifier selection, aren't we?
Quoted 1 line
- Add the original warning from the kernel test robot to the commit message.
It is possible then to identify presented information in the way that it is probably coming from coccicheck.
Quoted 10 lines
- Trivial rewording of the commit message.
Quoted 5 lines
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinementsIt seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
I propose to apply a more detailed change granularity.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n81
Quoted 10 lines
Quoted 9 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.carch/x86/events/intel/uncore_discovery.c +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,struct uncore_unit_discovery unit;void __iomem *io_addr;unsigned long size; +int ret =0 ;int i;Would scope adjustments become helpful for any of these local variables?
Quoted 2 lines
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
Will development interests grow for related update steps?
Quoted 1 line
Re: [PATCH] perf/x86/intel/uncore: Fix iounmap() leak on global_init failure
Can the timing trigger special considerations?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
arch/x86/events/intel/uncore_discovery.c +2
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,/* Read Global Discovery State */ memcpy_fromio (&global, io_addr,sizeof (struct uncore_global_discovery )); +iounmap (io_addr); +if (uncore_discovery_invalid_unit (global)) {…
Quoted 6 lines
Quoted 4 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 282
Quoted 2 lines
arch/x86/events/intel/uncore_discovery.c +0
-1} -iounmap (io_addr);Can this modification part be interpreted as an optimisation?
Yes, this is technically an optimization.
Thanks that we can come to the same conclusion on this aspect.
Quoted 3 lines
Since the patch is already
refactoring theiounmap()handling, my thinking was that it would be reasonable to include it in the same patch.
I dare to point another opinion out.
I assume that backporting concerns can influence this detail also a bit more.
Quoted 14 lines
Quoted 8 lines
…
Quoted 6 lines
arch/x86/events/intel/uncore_discovery.c +4
-2-if (domain->global_init && domain->global_init (global.ctl)) -return -ENODEV ; +if (domain->global_init && domain->global_init (global.ctl)) { + ret = -ENODEV ; + goto out; + }…
Quoted 5 lines
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 314
Quoted 3 lines
arch/x86/events/intel/uncore_discovery.c +2
-0*parsed = true; + +out:Would an other label be a bit clearer here?
Quoted 13 lines
I’d suggest keeping the label name out for style consistency, as mentioned in my earlier reply.
https://lore.kernel.org/all/[email protected]/T/#t
Quoted 8 lines
unmap_io:Quoted 4 lines
arch/x86/events/intel/uncore_discovery.c +1
-1iounmap (io_addr); -return 0 ; +return ret; }…
By the way:
How do you think about to increase the application of scope-based resource management?
Regards,
Markus
Quoted 11 lines · Markus Elfring
Quoted 8 lines
Quoted 4 lines
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
I hope that the understanding will improve somehow also for a development communication requirement like “imperative mood”.
For the commit message itself, I’ve tried to improve it as much as I can based on the feedback so far. If there are still specific phrases or wording that should be adjusted, I’d really appreciate it if you could point them out.
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
…
Quoted 2 lines
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++-----…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22…
Quoted 5 lines
Yes, that was the intention for v2.
V2:
- As suggested by Markus, add anoutlabel and use goto-based error handling to reduce duplicatediounmap()code.
Quoted 8 lines
We are still trying to discuss the corresponding identifier selection, aren't we?
Quoted 1 line
- Add the original warning from the kernel test robot to the commit message.
It is possible then to identify presented information in the way that it is probably coming from coccicheck.
It was indeed from the kernel test robot report. I’m not familiar with the Intel kernel test robot internals, and I’m not sure whether it invokes coccicheck.
Quoted 5 lines
Quoted 5 lines
- Trivial rewording of the commit message.
Quoted 3 lines
Is there a need to perform desirable changes by a small patch series?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
* Specific fix
* Related refinementsIt seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
I propose to apply a more detailed change granularity.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n81
Thanks for the reference. I considered this a single logical fix, which is why I kept the changes together.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.c(quoted diff) +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, struct uncore_unit_discovery unit; void __iomem *io_addr; unsigned long size; + int ret = 0; int i;Would scope adjustments become helpful for any of these local variables?
Quoted 4 lines
Quoted 2 lines
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
Will development interests grow for related update steps?
Are you suggesting including this change in this patch? My understanding is that it isn’t directly related to the scope of this patch, so I would prefer not to include it here. Please let me know if you see it differently.
(quoted diff) +0 -0
b/arch/x86/events/intel/uncore_discovery.c
index efd1fc99a908..8ab8f778285a 100644
arch/x86/events/intel/uncore_discovery.c +0 -0
@@ -265,7 +265,6 @@ static int __parse_discovery_table(struct
uncore_discovery_domain *domain,
void __iomem *io_addr;
unsigned long size;
int ret = 0;- int i;
size = UNCORE_DISCOVERY_GLOBAL_MAP_SIZE;
io_addr = ioremap(addr, size);
@@ -293,7 +292,7 @@ static int __parse_discovery_table(struct
uncore_discovery_domain *domain,
}
/* Parsing Unit Discovery State */- for (i = 0; i < global.max_units; i++) {
+ for (int i = 0; i < global.max_units; i++) {
memcpy_fromio(&unit, io_addr + (i + 1) * (global.stride
* 8),
sizeof(struct uncore_unit_discovery));
Quoted 5 lines
Quoted 1 line
Re: [PATCH] perf/x86/intel/uncore: Fix
iounmap()leak onglobal_initfailureCan the timing trigger special considerations?
Sorry if I’m missing your point, but it seems to me that there are no special considerations involved here.
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
(quoted diff) +2
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, /* Read Global Discovery State */ memcpy_fromio(&global, io_addr, sizeof(struct uncore_global_discovery)); + iounmap(io_addr); + if (uncore_discovery_invalid_unit(global)) {…
Quoted 6 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +0
-1} - iounmap(io_addr);Can this modification part be interpreted as an optimisation?
Yes, this is technically an optimization.
Thanks that we can come to the same conclusion on this aspect.
Quoted 7 lines
Quoted 3 lines
Since the patch is already
refactoring theiounmap()handling, my thinking was that it would be reasonable to include it in the same patch.I dare to point another opinion out.
I assume that backporting concerns can influence this detail also a bit more.
Thanks for pointing that out. This patch is intended as a quick fix for a change that is still staging in perf/core, so I assume that backporting is unlikely to be needed.
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
…
Quoted 6 lines
(quoted diff) +4
-2- if (domain->global_init && domain->global_init(global.ctl)) - return -ENODEV; + if (domain->global_init && domain->global_init(global.ctl)) { + ret = -ENODEV; + goto out; + }…
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0*parsed = true; + +out:Would an other label be a bit clearer here?
I’d suggest keeping the label name out for style consistency, as mentioned in my earlier reply.
https://lore.kernel.org/all/[email protected]/T/#t
Quoted 3 lines
unmap_io:
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
(quoted diff) +1
-1iounmap(io_addr); - return 0; + return ret; }…
By the way:
How do you think about to increase the application of scope-based resource management?
That’s an interesting topic, but for this patch I’d like to keep the change minimal and focused.
Quoted 2 lines
Regards,
Markus
Quoted 121 lines · Zide
Quoted 9 lines · Markus Elfring
Quoted 7 lines
Quoted 4 lines
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
I hope that the understanding will improve somehow also for a development communication requirement like “imperative mood”.
For the commit message itself, I’ve tried to improve it as much as I can based on the feedback so far. If there are still specific phrases or wording that should be adjusted, I’d really appreciate it if you could point them out.
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
…
Quoted 2 lines
--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++-----…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22…
Quoted 5 lines
Yes, that was the intention for v2.
V2:
- As suggested by Markus, add anoutlabel and use goto-based error handling to reduce duplicatediounmap()code.Quoted 7 lines
We are still trying to discuss the corresponding identifier selection, aren't we?
Quoted 1 line
- Add the original warning from the kernel test robot to the commit message.
It is possible then to identify presented information in the way that it is probably coming from coccicheck.
It was indeed from the kernel test robot report. I’m not familiar with the Intel kernel test robot internals, and I’m not sure whether it invokes coccicheck.
Quoted 10 lines
Quoted 8 lines
- Trivial rewording of the commit message.
Quoted 4 lines
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinementsIt seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
I propose to apply a more detailed change granularity.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n81Thanks for the reference. I considered this a single logical fix, which is why I kept the changes together.
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Review static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.c(quoted diff) +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, struct uncore_unit_discovery unit; void __iomem *io_addr; unsigned long size; + int ret = 0; int i;Would scope adjustments become helpful for any of these local variables?
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
Will development interests grow for related update steps?
Are you suggesting including this change in this patch? My understanding is that it isn’t directly related to the scope of this patch, so I would prefer not to include it here. Please let me know if you see it differently.
arch/x86/events/intel/uncore_discovery.c +0
-1@@ -265,7 +265,6 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, void__iomem *io_addr;unsigned long size;int ret =0 ; -int i; size =UNCORE_DISCOVERY_GLOBAL_MAP_SIZE ;io_addr = ioremap(addr, size);arch/x86/events/intel/uncore_discovery.c +1
-1@@ -293,7 +292,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, }/* Parsing Unit Discovery State */ -for (i =0 ; i < global.max_units; i++) { +for (int i =0 ; i < global.max_units; i++) { memcpy_fromio(&unit, io_addr + (i + 1) * (global.stride * 8),sizeof(struct uncore_unit_discovery));Quoted 4 lines
Quoted 1 line
Re: [PATCH] perf/x86/intel/uncore: Fix
iounmap()leak onglobal_initfailureCan the timing trigger special considerations?
Sorry if I’m missing your point, but it seems to me that there are no special considerations involved here.
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
(quoted diff) +2
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, /* Read Global Discovery State */ memcpy_fromio(&global, io_addr, sizeof(struct uncore_global_discovery)); + iounmap(io_addr); + if (uncore_discovery_invalid_unit(global)) {…
Quoted 4 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +0
-1} - iounmap(io_addr);Can this modification part be interpreted as an optimisation?
Yes, this is technically an optimization.
Thanks that we can come to the same conclusion on this aspect.
Quoted 3 lines
Since the patch is already
refactoring theiounmap()handling, my thinking was that it would be reasonable to include it in the same patch.
Quoted 6 lines
Quoted 3 lines
I dare to point another opinion out.
I assume that backporting concerns can influence this detail also a bit more.
Thanks for pointing that out. This patch is intended as a quick fix for a change that is still staging in perf/core, so I assume that backporting is unlikely to be needed.
Agree.
IMO, we'd better keep this patch is simple and focused and then it can be reviewed and merged into perf/core tree quickly. So we can avoid to cause the subsequent backporting work.
About the further optimization, we can have an independent patchset to do it. :)
Thanks.
Quoted 32 lines
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
…
Quoted 6 lines
(quoted diff) +4
-2- if (domain->global_init && domain->global_init(global.ctl)) - return -ENODEV; + if (domain->global_init && domain->global_init(global.ctl)) { + ret = -ENODEV; + goto out; + }…
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0*parsed = true; + +out:Would an other label be a bit clearer here?
I’d suggest keeping the label name out for style consistency, as mentioned in my earlier reply.
https://lore.kernel.org/all/[email protected]/T/#t
Quoted 2 lines
unmap_io:Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
(quoted diff) +1
-1iounmap(io_addr); - return 0; + return ret; }…
By the way:
How do you think about to increase the application of scope-based resource management?That’s an interesting topic, but for this patch I’d like to keep the change minimal and focused.
Quoted 2 lines
Regards,
Markus
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
Quoted 7 lines
Quoted 2 lines
I hope that the understanding will improve somehow also for a development communication requirement like “imperative mood”.
For the commit message itself, I’ve tried to improve it as much as I can based on the feedback so far. If there are still specific phrases or wording that should be adjusted, I’d really appreciate it if you could point them out.
1. The mentioned source code analysis report is obviously helpful.
2. You added a custom explanation accordingly.
3. Which text part of your change description does contain “orders to the codebase to change its behaviour”?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinements
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
I propose to apply a more detailed change granularity.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n81Thanks for the reference. I considered this a single logical fix, which is why I kept the changes together.
I find this adjustment approach also “logical” (in principle).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.c(quoted diff) +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, struct uncore_unit_discovery unit; void __iomem *io_addr; unsigned long size; + int ret = 0; int i;Would scope adjustments become helpful for any of these local variables?
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
Will development interests grow for related update steps?
Are you suggesting including this change in this patch?
Does anything hinder you to take patch series better into account?
Quoted 3 lines
My understanding
is that it isn’t directly related to the scope of this patch, so I would prefer not to include it here.
Can we imagine further patch variations?
Quoted 1 line
Please let me know if you see it differently.
This is the case according to another evolving patch review.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Re: [PATCH] perf/x86/intel/uncore: Fix
iounmap()leak onglobal_initfailureCan the timing trigger special considerations?
Sorry if I’m missing your point, but it seems to me that there are no special considerations involved here.
1. You announced planned changes for an initial patch.
https://lore.kernel.org/linux-perf-users/[email protected]/
2. I offered review comments accordingly.
3. You published the second patch version.
https://lore.kernel.org/linux-perf-users/[email protected]/
4. You replied to the mentioned review approach three minutes later, didn't you?
https://lore.kernel.org/linux-perf-users/[email protected]/
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Since the patch is already
refactoring theiounmap()handling, my thinking was that it would be reasonable to include it in the same patch.I dare to point another opinion out.
I assume that backporting concerns can influence this detail also a bit more.
Thanks for pointing that out. This patch is intended as a quick fix for a change that is still staging in perf/core, so I assume that backporting is unlikely to be needed.
Will backporting be usually desirable for Linux software components?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/backporting.rst?h=v6.19-rc5#n14
It happened again that further change possibilities were noticed. Thus companion patches can be considered on demand.
The corresponding change recombination can occasionally become more interesting for selected development ideas.
Quoted 4 lines
Quoted 1 line
How do you think about to increase the application of scope-based resource management?
That’s an interesting topic, but for this patch I’d like to keep the change minimal and focused.
This software design technique influences also if we would still like to fiddle with goto chains (or not).
https://elixir.bootlin.com/linux/v6.19-rc5/source/include/linux/cleanup.h#L12-L17
Do you see opportunities fur further collateral evolution?
Regards,
Markus
Quoted 17 lines · Markus Elfring
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94Will another imperative wording approach become helpful for an improved change description?
My apologies — I did try to address the feedback, but I may still be missing something. Could you please point out what specifically could be improved?
Quoted 7 lines
Quoted 2 lines
I hope that the understanding will improve somehow also for a development communication requirement like “imperative mood”.
For the commit message itself, I’ve tried to improve it as much as I can based on the feedback so far. If there are still specific phrases or wording that should be adjusted, I’d really appreciate it if you could point them out.
Quoted 6 lines
1. The mentioned source code analysis report is obviously helpful.
2. You added a custom explanation accordingly.
3. Which text part of your change description does contain “orders to the codebase to change its behaviour”?
OK, I see your point. Yes, it's good to add one sentence to describe what the patches does. But I guess this patch is simple enough.
Quoted 27 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Is there a need to perform desirable changes by a small patch series?
* Specific fix
* Related refinementsQuoted 8 lines
Quoted 5 lines
Quoted 2 lines
It seems to me that the changes in this patch are small and closely related, so I wondered whether splitting it might be unnecessary.
I propose to apply a more detailed change granularity.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n81Thanks for the reference. I considered this a single logical fix, which is why I kept the changes together.
I find this adjustment approach also “logical” (in principle).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Review static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 268
Quoted 7 lines
+++
b/arch/x86/events/intel/uncore_discovery.c(quoted diff) +1
-0@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, struct uncore_unit_discovery unit; void __iomem *io_addr; unsigned long size; + int ret = 0; int i;Would scope adjustments become helpful for any of these local variables?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
As mentioned in my earlier reply, my suggestion was to avoid doing other unrelated optimizations in this patch.
Will development interests grow for related update steps?
Are you suggesting including this change in this patch?
Does anything hinder you to take patch series better into account?
This “optimization” is trivial and does not appear to be related to the issue this patch is trying to address.
I don’t think this change alone justifies a separate patch, as it would add review overhead without providing much practical benefit.
- int i;
- for (i = 0; i < global.max_units; i++) {
+ for (int i = 0; i < global.max_units; i++) {
Overall, the Intel perf driver largely follows a pre-C99 coding style. Updating a single instance in isolation does not seem very helpful; if there is interest, this could be handled as part of a broader, driver-wide cleanup.
Quoted 6 lines
Quoted 4 lines
My understanding
is that it isn’t directly related to the scope of this patch, so I would prefer not to include it here.Can we imagine further patch variations?
Ditto.
Quoted 18 lines
Quoted 2 lines
Please let me know if you see it differently.
This is the case according to another evolving patch review.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Re: [PATCH] perf/x86/intel/uncore: Fix
iounmap()leak onglobal_initfailureCan the timing trigger special considerations?
Sorry if I’m missing your point, but it seems to me that there are no special considerations involved here.
1. You announced planned changes for an initial patch.
https://lore.kernel.org/linux-perf-users/[email protected]/
Quoted 8 lines
2. I offered review comments accordingly.
3. You published the second patch version.
https://lore.kernel.org/linux-perf-users/[email protected]/4. You replied to the mentioned review approach three minutes later, didn't you?
https://lore.kernel.org/linux-perf-users/[email protected]/
Really appreciated for your review!
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Since the patch is already
refactoring theiounmap()handling, my thinking was that it would be reasonable to include it in the same patch.I dare to point another opinion out.
I assume that backporting concerns can influence this detail also a bit more.
Thanks for pointing that out. This patch is intended as a quick fix for a change that is still staging in perf/core, so I assume that backporting is unlikely to be needed.
Quoted 7 lines
Will backporting be usually desirable for Linux software components?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/backporting.rst?h=v6.19-rc5#n14It happened again that further change possibilities were noticed. Thus companion patches can be considered on demand.
The corresponding change recombination can occasionally become more interesting for selected development ideas.
Are you suggesting putting this into a separate patch?
My impression is that the change is simple and closely related, though I may be missing something. I understand others may see it differently.
@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,
/* Read Global Discovery State */ memcpy_fromio(&global, io_addr, sizeof(structuncore_global_discovery));
+ iounmap(io_addr);
+
if (uncore_discovery_invalid_unit(global)) {
pr_info("Invalid Global Discovery State: 0x%llx 0x%llx
0x%llx\n",
global.table1, global.ctl, global.table3);
- iounmap(io_addr);
return -EINVAL;
}- iounmap(io_addr);
Quoted 10 lines
Quoted 4 lines
Quoted 1 line
How do you think about to increase the application of scope-based resource management?
That’s an interesting topic, but for this patch I’d like to keep the change minimal and focused.
This software design technique influences also if we would still like to fiddle with goto chains (or not).
https://elixir.bootlin.com/linux/v6.19-rc5/source/include/linux/cleanup.h#L12-L17Do you see opportunities fur further collateral evolution?
Yes, there are some code cleanup/improvement ideas in mind.
Quoted 2 lines
Regards,
Markus
…
Quoted 5 lines
Quoted 2 lines
3. Which text part of your change description does contain “orders to the codebase to change its behaviour”?
OK, I see your point. Yes, it's good to add one sentence to describe what the patches does.
I became curious somehow if further contributors would be willing to care a bit more also for this wording requirement.
Quoted 1 line
But I guess this patch is simple enough.
But it seems that several technical details triggered special communication challenges.
Quoted 2 lines
I don’t think this change alone justifies a separate patch, as it would add review overhead without providing much practical benefit.
Will any other contributors dare to add related insights?
Quoted 5 lines
Quoted 2 lines
The corresponding change recombination can occasionally become more interesting for selected development ideas.
Are you suggesting putting this into a separate patch?
Yes.
I propose a stricter distinction between a “quick” fix and subsequent refinements at the discussed source code places.
Quoted 2 lines
My impression is that the change is simple and closely related, though I may be missing something. I understand others may see it differently.
It seems that we are struggling according to recurring factors of change resistance.
Quoted 6 lines
(quoted diff) +0
-0@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, /* Read Global Discovery State */ memcpy_fromio(&global, io_addr, sizeof(struct uncore_global_discovery));
Review static int __parse_discovery_table(struct · line 285
Quoted 10 lines
(quoted diff) +2
-2+ iounmap(io_addr); + if (uncore_discovery_invalid_unit(global)) { pr_info("Invalid Global Discovery State: 0x%llx 0x%llx 0x%llx\n", global.table1, global.ctl, global.table3); - iounmap(io_addr); return -EINVAL; } - iounmap(io_addr);
Regards,
Markus
Quoted 61 lines · Zide Chen
Kernel test robot reported:
Unverified Error/Warning (likely false positive, kindly check if interested):
arch/x86/events/intel/uncore_discovery.c:293:2-8:
ERROR: missing iounmap; ioremap on line 288 and execution via conditional on line 292If
domain->global_init()fails in__parse_discovery_table(), the ioremap'ed MMIO region is not released before returning, resulting in an MMIO mapping leak.Reported-by kernel test robot <[email protected]>Fixes b575fc0e3357 ("perf/x86/intel/uncore: Add domain global init callback")Signed-off-by Zide Chen <[email protected]>--- arch/x86/events/intel/uncore_discovery.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/x86/events/intel/uncore_discovery.c +7
-4@@ -264,6 +264,7 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,struct uncore_unit_discovery unit;void __iomem *io_addr;unsigned long size; +int ret =0 ;int i; size =UNCORE_DISCOVERY_GLOBAL_MAP_SIZE ;@@ -273,21 +274,23 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain,/* Read Global Discovery State */ memcpy_fromio (&global, io_addr,sizeof (struct uncore_global_discovery )); +iounmap (io_addr); +if (uncore_discovery_invalid_unit (global)) {pr_info ("Invalid Global Discovery State: 0x%llx 0x%llx 0x%llx\n" , global.table1, global.ctl, global.table3); -iounmap (io_addr);return -EINVAL ; } -iounmap (io_addr); size = (1 + global.max_units) * global.stride *8 ; io_addr =ioremap (addr, size);if (!io_addr)return -ENOMEM ; -if (domain->global_init && domain->global_init (global.ctl)) -return -ENODEV ; +if (domain->global_init && domain->global_init (global.ctl)) { + ret = -ENODEV ; + goto out; + }/* Parsing Unit Discovery State */ for (i =0 ; i < global.max_units; i++) {@@ -307,8 +310,10 @@ static int __parse_discovery_table(struct uncore_discovery_domain *domain, }
arch/x86/events/intel/uncore_discovery.c static int __parse_discovery_table(struct uncore_discovery_domain *domain, · line 319
Quoted 10 lines
arch/x86/events/intel/uncore_discovery.c +3
-1*parsed = true; + +out:iounmap (io_addr); -return 0 ; +return ret; } static int parse_discovery_table(struct uncore_discovery_domain *domain,
LGTM.