The patch titled Subject: resource: fix locking in find_next_iomem_res() has been added to the -mm tree. Its filename is resource-fix-locking-in-find_next_iomem_res.patch
This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/resource-fix-locking-in-find_next_i... and later at http://ozlabs.org/~akpm/mmotm/broken-out/resource-fix-locking-in-find_next_i...
Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------ From: Nadav Amit namit@vmware.com Subject: resource: fix locking in find_next_iomem_res()
Since resources can be removed, locking should ensure that the resource is not removed while accessing it. However, find_next_iomem_res() does not hold the lock while copying the data of the resource.
Keep holding the lock while the data is copied. While at it, change the return value to a more informative value. It is disregarded by the callers.
Link: http://lkml.kernel.org/r/20190613045903.4922-2-namit@vmware.com Fixes: ff3cc952d3f00 ("resource: Add remove_resource interface") Signed-off-by: Nadav Amit namit@vmware.com Reviewed-by: Andrew Morton akpm@linux-foundation.org Cc: Borislav Petkov bp@suse.de Cc: Toshi Kani toshi.kani@hpe.com Cc: Peter Zijlstra peterz@infradead.org Cc: Dave Hansen dave.hansen@linux.intel.com Cc: Dan Williams dan.j.williams@intel.com Cc: Bjorn Helgaas bhelgaas@google.com Cc: Ingo Molnar mingo@kernel.org Cc: stable@vger.kernel.org Signed-off-by: Andrew Morton akpm@linux-foundation.org ---
kernel/resource.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
--- a/kernel/resource.c~resource-fix-locking-in-find_next_iomem_res +++ a/kernel/resource.c @@ -365,16 +365,16 @@ static int find_next_iomem_res(resource_ break; }
- read_unlock(&resource_lock); - if (!p) - return -1; + if (p) { + /* copy data */ + res->start = max(start, p->start); + res->end = min(end, p->end); + res->flags = p->flags; + res->desc = p->desc; + }
- /* copy data */ - res->start = max(start, p->start); - res->end = min(end, p->end); - res->flags = p->flags; - res->desc = p->desc; - return 0; + read_unlock(&resource_lock); + return p ? 0 : -ENODEV; }
static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, _
Patches currently in -mm which might be from namit@vmware.com are
resource-fix-locking-in-find_next_iomem_res.patch resource-avoid-unnecessary-lookups-in-find_next_iomem_res.patch resource-introduce-resource-cache.patch