All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Fancellu <luca.fancellu@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Penny Zheng <Penny.Zheng@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Penny Zheng <penny.zheng@arm.com>
Subject: [PATCH v2 02/13] xen/arm: avoid repetitive checking in process_shm_node
Date: Tue,  9 Apr 2024 12:45:32 +0100	[thread overview]
Message-ID: <20240409114543.3332150-3-luca.fancellu@arm.com> (raw)
In-Reply-To: <20240409114543.3332150-1-luca.fancellu@arm.com>

From: Penny Zheng <Penny.Zheng@arm.com>

Putting overlap and overflow checking in the loop is causing repetitive
operation, so this commit extracts both checking outside the loop.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
---
v2:
 - add Michal R-by
v1:
 - Rework of https://patchwork.kernel.org/project/xen-devel/patch/20231206090623.1932275-3-Penny.Zheng@arm.com/
 - use strncmp to match the branch above
 - drop Michal R-by given the change
---
---
 xen/arch/arm/static-shmem.c | 39 +++++++++++++++----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c
index cb268cd2edf1..40a0e860c79d 100644
--- a/xen/arch/arm/static-shmem.c
+++ b/xen/arch/arm/static-shmem.c
@@ -349,7 +349,7 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,
 {
     const struct fdt_property *prop, *prop_id, *prop_role;
     const __be32 *cell;
-    paddr_t paddr, gaddr, size;
+    paddr_t paddr, gaddr, size, end;
     struct meminfo *mem = &bootinfo.reserved_mem;
     unsigned int i;
     int len;
@@ -422,6 +422,13 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,
         return -EINVAL;
     }
 
+    end = paddr + size;
+    if ( end <= paddr )
+    {
+        printk("fdt: static shared memory region %s overflow\n", shm_id);
+        return -EINVAL;
+    }
+
     for ( i = 0; i < mem->nr_banks; i++ )
     {
         /*
@@ -441,30 +448,13 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,
                 return -EINVAL;
             }
         }
+        else if ( strncmp(shm_id, mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) != 0 )
+            continue;
         else
         {
-            paddr_t end = paddr + size;
-            paddr_t bank_end = mem->bank[i].start + mem->bank[i].size;
-
-            if ( (end <= paddr) || (bank_end <= mem->bank[i].start) )
-            {
-                printk("fdt: static shared memory region %s overflow\n", shm_id);
-                return -EINVAL;
-            }
-
-            if ( check_reserved_regions_overlap(paddr, size) )
-                return -EINVAL;
-            else
-            {
-                if ( strcmp(shm_id, mem->bank[i].shm_id) != 0 )
-                    continue;
-                else
-                {
-                    printk("fdt: different shared memory region could not share the same shm ID %s\n",
-                           shm_id);
-                    return -EINVAL;
-                }
-            }
+            printk("fdt: different shared memory region could not share the same shm ID %s\n",
+                   shm_id);
+            return -EINVAL;
         }
     }
 
@@ -472,6 +462,9 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,
     {
         if ( i < NR_MEM_BANKS )
         {
+            if ( check_reserved_regions_overlap(paddr, size) )
+                return -EINVAL;
+
             /* Static shared memory shall be reserved from any other use. */
             safe_strcpy(mem->bank[mem->nr_banks].shm_id, shm_id);
             mem->bank[mem->nr_banks].start = paddr;
-- 
2.34.1



  parent reply	other threads:[~2024-04-09 11:46 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 11:45 [PATCH v2 00/13] Static shared memory followup v2 - pt1 Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 01/13] xen/arm: remove stale addr_cells/size_cells in assign_shared_memory Luca Fancellu
2024-04-09 11:45 ` Luca Fancellu [this message]
2024-04-09 11:45 ` [PATCH v2 03/13] xen/arm: Pass struct kernel_info parameter to make_resv_memory_node Luca Fancellu
2024-04-09 13:18   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 04/13] xen/arm: Introduce a generic way to access memory bank structures Luca Fancellu
2024-04-09 13:24   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 05/13] xen/arm: Conditional compilation of kernel_info.shm_mem member Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 06/13] xen/arm: Avoid code duplication in find_unallocated_memory Luca Fancellu
2024-04-09 13:38   ` Michal Orzel
2024-04-09 14:37     ` Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 07/13] xen/arm: Avoid code duplication in check_reserved_regions_overlap Luca Fancellu
2024-04-10  7:40   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 08/13] xen/arm: Introduce helper for static memory pages Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 09/13] xen/arm: Reduce struct membank size on static shared memory Luca Fancellu
2024-04-10 10:01   ` Michal Orzel
2024-04-10 10:56     ` Luca Fancellu
2024-04-10 11:01       ` Michal Orzel
2024-04-10 11:19         ` Luca Fancellu
2024-04-10 11:23           ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 10/13] xen/arm: remove shm holes from extended regions Luca Fancellu
2024-04-10 11:15   ` Michal Orzel
2024-04-10 14:08     ` Luca Fancellu
2024-04-10 14:58       ` Michal Orzel
2024-04-10 14:12     ` Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 11/13] xen/arm: fix duplicate /reserved-memory node in Dom0 Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 12/13] xen/device_tree: Introduce function to merge overlapping intervals Luca Fancellu
2024-04-11  9:50   ` Luca Fancellu
2024-04-11 13:36     ` Luca Fancellu
2024-04-18  6:28   ` Jan Beulich
2024-04-18  7:44     ` Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 13/13] xen/arm: List static shared memory regions as /memory nodes Luca Fancellu
2024-04-15 18:41   ` Julien Grall
2024-04-16  6:27     ` Luca Fancellu
2024-04-16  8:50       ` Julien Grall
2024-04-16  8:57         ` Michal Orzel
2024-04-16  8:59         ` Luca Fancellu
2024-04-16  9:06           ` Julien Grall
2024-04-16 10:50             ` Luca Fancellu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240409114543.3332150-3-luca.fancellu@arm.com \
    --to=luca.fancellu@arm.com \
    --cc=Penny.Zheng@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.