All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 1/3] kernel/resource: Allow region_intersects users to hold resource_lock
@ 2021-04-19  7:01 Alistair Popple
  2021-04-19  7:01 ` [PATCH v5 2/3] kernel/resource: Refactor __request_region to allow external locking Alistair Popple
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alistair Popple @ 2021-04-19  7:01 UTC (permalink / raw)
  To: akpm
  Cc: linux-mm, linux-kernel, david, daniel.vetter, dan.j.williams,
	gregkh, jhubbard, jglisse, bsingharora, smuchun, Alistair Popple

Introduce a version of region_intersects() that can be called with the
resource_lock already held. This is used in a future fix to
__request_free_mem_region().

Signed-off-by: Alistair Popple <apopple@nvidia.com>
---
 kernel/resource.c | 52 ++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 627e61b0c124..736768587d2d 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -523,6 +523,34 @@ int __weak page_is_ram(unsigned long pfn)
 }
 EXPORT_SYMBOL_GPL(page_is_ram);
 
+int __region_intersects(resource_size_t start, size_t size, unsigned long flags,
+			unsigned long desc)
+{
+	struct resource res;
+	int type = 0; int other = 0;
+	struct resource *p;
+
+	res.start = start;
+	res.end = start + size - 1;
+
+	for (p = iomem_resource.child; p ; p = p->sibling) {
+		bool is_type = (((p->flags & flags) == flags) &&
+				((desc == IORES_DESC_NONE) ||
+				 (desc == p->desc)));
+
+		if (resource_overlaps(p, &res))
+			is_type ? type++ : other++;
+	}
+
+	if (type == 0)
+		return REGION_DISJOINT;
+
+	if (other == 0)
+		return REGION_INTERSECTS;
+
+	return REGION_MIXED;
+}
+
 /**
  * region_intersects() - determine intersection of region with known resources
  * @start: region start address
@@ -546,31 +574,13 @@ EXPORT_SYMBOL_GPL(page_is_ram);
 int region_intersects(resource_size_t start, size_t size, unsigned long flags,
 		      unsigned long desc)
 {
-	struct resource res;
-	int type = 0; int other = 0;
-	struct resource *p;
-
-	res.start = start;
-	res.end = start + size - 1;
+	int ret;
 
 	read_lock(&resource_lock);
-	for (p = iomem_resource.child; p ; p = p->sibling) {
-		bool is_type = (((p->flags & flags) == flags) &&
-				((desc == IORES_DESC_NONE) ||
-				 (desc == p->desc)));
-
-		if (resource_overlaps(p, &res))
-			is_type ? type++ : other++;
-	}
+	ret = __region_intersects(start, size, flags, desc);
 	read_unlock(&resource_lock);
 
-	if (type == 0)
-		return REGION_DISJOINT;
-
-	if (other == 0)
-		return REGION_INTERSECTS;
-
-	return REGION_MIXED;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(region_intersects);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-20 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19  7:01 [PATCH v5 1/3] kernel/resource: Allow region_intersects users to hold resource_lock Alistair Popple
2021-04-19  7:01 ` [PATCH v5 2/3] kernel/resource: Refactor __request_region to allow external locking Alistair Popple
2021-04-20 14:43   ` David Hildenbrand
2021-04-19  7:01 ` [PATCH v5 3/3] kernel/resource: Fix locking in request_free_mem_region Alistair Popple
2021-04-20 14:48   ` David Hildenbrand
2021-04-19 14:18 ` [PATCH v5 1/3] kernel/resource: Allow region_intersects users to hold resource_lock David Hildenbrand

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.