All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen: Fold exit paths in find_text_region()
@ 2023-04-13 19:22 Andrew Cooper
  2023-04-13 20:13 ` Julien Grall
  2023-04-17  9:00 ` Jan Beulich
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Cooper @ 2023-04-13 19:22 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné, Wei Liu

Despite rcu_read_unlock() being fully inlineable, the optimiser cannot fold
these exit paths, because of the various compiler barriers providing RCU
safety.  Help the compiler out.

This compiles to marginally better code in all cases.  No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
---
 xen/common/virtual_region.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c
index 30b0b4ab9c85..5ecdba9c08ed 100644
--- a/xen/common/virtual_region.c
+++ b/xen/common/virtual_region.c
@@ -40,20 +40,20 @@ static DEFINE_RCU_READ_LOCK(rcu_virtual_region_lock);
 
 const struct virtual_region *find_text_region(unsigned long addr)
 {
-    const struct virtual_region *region;
+    const struct virtual_region *iter, *region = NULL;
 
     rcu_read_lock(&rcu_virtual_region_lock);
-    list_for_each_entry_rcu( region, &virtual_region_list, list )
+    list_for_each_entry_rcu ( iter, &virtual_region_list, list )
     {
-        if ( (void *)addr >= region->start && (void *)addr < region->end )
+        if ( (void *)addr >= iter->start && (void *)addr < iter->end )
         {
-            rcu_read_unlock(&rcu_virtual_region_lock);
-            return region;
+            region = iter;
+            break;
         }
     }
     rcu_read_unlock(&rcu_virtual_region_lock);
 
-    return NULL;
+    return region;
 }
 
 void register_virtual_region(struct virtual_region *r)
-- 
2.30.2



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

end of thread, other threads:[~2023-04-17  9:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 19:22 [PATCH] xen: Fold exit paths in find_text_region() Andrew Cooper
2023-04-13 20:13 ` Julien Grall
2023-04-13 22:09   ` Andrew Cooper
2023-04-13 23:01     ` Stefano Stabellini
2023-04-17  9:00 ` Jan Beulich

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.