Devres (Managed Device Resource) for U-Boot
Get series with b4
b4 am 20150713191636.540aa501@lilithVersions newest first · linked by author and title
- v2 Latest posting 3/30 of 14 patches 0 repliesNew
- v2 posting 2/30 of 14 patches 0 repliesSuperseded
- v2 posting 1/30 of 14 patches 0 repliesSuperseded
Patches in v2 posting 3/3 No applies recorded yet
None of the 14 patches the cover letter announces are in this archive.
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [U-Boot] [PATCH v2 00/14] Devres (Managed Device Resource) for U-Boot
Hello Masahiro,
Quoted 82 lines · Masahiro Yamada
2015-07-13 19:55 GMT+09:00 Albert ARIBAUD <[email protected]>:
Quoted 73 lines
Hello Masahiro,
Quoted 63 lines · Masahiro Yamada
Hi Albert,
2015-07-13 15:51 GMT+09:00 Albert ARIBAUD <[email protected]>:
Quoted 38 lines
Hello Masahiro,
Quoted 3 lines · Masahiro Yamada
Please refer to the commit message of 06/14
for what this series wants to do.Remark: you could use "Series-notes:" in 6/14 to have patman directly include said notes here instead of referring the reader to the patch.
Quoted 7 lines
Masahiro Yamada (14):
x86: delete unneeded declarations ofdisable_irq()andenable_irq()
linux_compat: removecpu_relax()define
linux_compat: movevzalloc()to header file as an inline function
linux_compat: handle__GFP_ZEROinkmalloc()
dm: addDM_FLAG_BOUNDflag
devres: introduce Devres (Managed Device Resource) frameworkQuoted 8 lines
devres: add
devm_kmalloc()and friends (managed memory allocators)
dm: refactordevice_bind()anddevice_unbind()withdevm_kzalloc()
dm: mergefail_alloclabels
linux_compat: introduceGFP_DMAflag forkmalloc()
dm: refactordevice_probe()anddevice_remove()withdevm_kzalloc()
devres: add debug command to dump device resources
dm: remove redundantCONFIG_DMfrom driver/core/Makefile
devres: compile Devres iifCONFIG_DM_DEVICE_REMOVEis enabledI am still unsure why this is necessary. I had a discussion on the list with Simon, see last message here:
<https://www.mail-archive.com/[email protected]/msg177031.html>
Unless I'm mistaken, the only case where we actually have a leak that this series would fix is in some cases of binding USB devices / drivers multiple times, and even then, it would take a considerable amount of repeated bindings before U-Boot could become unable to boot a payload; a scenario that I find unlikely.
Quoted 4 lines
I do understand the general goal of fixing bugs when we ind them; but I question the global benefit of fixing this specific leak bug by adding a whole new feature with a lot of code to U-Boot, as opposed to fixing it in a more ad hoc way with much less less code volume and complexity.
You have a point.
What we really want to avoid is to make low-level drivers too complicated by leaving the correct memory management to each of them.
After all, there turned out to be two options to solve it.
[1] Simon's driver model: move allocating/freeing memory to the driver core by having only the needed memory size
specified in each driver
[2] Devres: we still have to allocate memory in each driver, but we
need not free it explicitly,
making our driver work much easierQuoted 3 lines
[1] and [2] are completely differently approach,
but what they solve is the same: easier memory (resource) management without leak.Understood.
Quoted 7 lines
IIUC, this adds a new leak scenario beside the multiple inits one such as for USB, but this new scenarion which is in failure paths where already allocated memory must be released, seems to me no more critical than the one I'd discussed with Simon, i.e., I'm not convinced we need a fix, and I'm not convinced we need a general memory management feature for that -- which does not mean I can't be convinced, though; I just need (more) convincing arguments (than I can currently read).
Quoted 4 lines
BTW, I am not following the USB-discussion between Simon and you. I have not checked the USB changes recently,
so I am not familiar enough with it to add my comment.
It was not actually a USB discussion. It was a discussion within v1 of this patch series. I'd asked when exactly there could be leaks in our current driver user scenarios and Simon said there was no leak case except in USB which could be bound several times in U-Boot between power-on and OS boot.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The only problem I see in [1] is that it is not controllable at run-time. The memory size for the auto-allocation must be specified at the compile time.
How in practice is that a problem?
At first, I thought (or expected) that .priv_auto_alloc_size and friends were generic enough to cover all the cases, but they were not.
I'm afraid I am still not seeing the problem.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
So, we need
calloc()andfree()in some low-level drivers. Simon might say they are only a few "exceptions",
(my impression is I often hear the logic such as "it is not a problem because we do not have many.")
Anyway, we had already lost the consistency as for memory allocation.Not sure I understand that last sentence. Which consistency exactly have we lost?
Quoted 7 lines
When I write drivers for Linux, I usually allocate memory for driver data with
devm_kzalloc().But, in U-boot, sometimes we specify .priv_auto_alloc_size, and sometimes we call
calloc()andfree().This is what I called lost-consistency.
Ok, now I get this point.
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
I imagined if [2] had been supported earlier, we would not have needed [1]. (at least, [2] seems more flexible to me.)
We already have many DM-based drivers, and I think we can live with [1] despite some exceptional drivers allocating memory on their own.
Quoted 6 lines
Quoted 2 lines
So, if Simon (and other developers) does not feel comfortable with this series, I do not mind discarding it.
Note that I'm not saying your patch series does not solve the issue of leaks. What I'm saying is i) do we need to solve this issue, and ii) if we do, is your series the best option ?
Quoted 8 lines
Sorry, if I am misunderstanding your questions.
If you are talking about the generic program guideline, I think leaks should be eliminated and this series should be helpful (but I wouldn't say as far as it is the best).
If you are asking if this series is the best for solving some particular issues, sorry, I can not comment on what I am not familiar with.
Let me recap :) as a series of simple yes/no sentences.
- Sometimes in driver code there are memory leaks.
- These leaks are bugs.
- These leaks do not prevent U-Boot from functioning properly.
- There are two methods to eliminate these leaks: Simon's method of allocating / freeing driver/device memory outside driver code per se, and your proposed method of dynamically tracking memory allocated by a driver / device, and freeing it when the driver gets 'unloaded' -- akin to freeing a process' resources when it terminates.
- Each method has advantages and disadvantages.
My opinion for now is that:
- We do not /need/ to fix the leaks, we /would like/ to.
- since we don't /need/ to fix the leaks, we can afford to be picky about how we will fix them, or even whether we will fix them at all if no solution pleases us.
- 'being picky' means we should consider the pros and cons of available methods, not only wrt the fix itself, but more generally too: Does it fix other issues? Does it hinder or encourage best practices? how much source code does it bring in? etc.
Right now, I'm not even certain we have a problem at all, in the sense that I don't recall seeing reports of a target failing to boot because of memory exhaustion in U-Boot -- which means that, to me, the 'pros' of any leak fix solution would start thin since they would solve a non-problem, or more precisely, a not-really-a-problem, and I fail to see the other pros (OTOH, the cons are not /that/ many either).
But I might be mistaken, so I'm asking for actual scenarios where a target did have problems doing its job due to memory allocation issues, and scenarios for other pros as well, and comments from anyone who would have a good idea of the cons and pros.
Quoted 3 lines
Signature · 2 lines
Best Regards Masahiro Yamada
Amicalement,
Signature · 1 line
Albert.