Skip to contentSkip to conversation

board_f: reserve noncached space below malloc area

PATCH New Vikas Manocha 2 participants 3 messages Aug 8, 2019 – Aug 9, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board_f: reserve noncached space below malloc area

Noncached area at present is being initialized to random space after malloc area. It works in most the cases as it goes to stack area & stack is not overwriting it being far from it.

---
 common/board_f.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
common/board_f.c +13 -0
index 59745d5..4910051 100644
@@ -439,12 +439,25 @@ static int reserve_uboot(void)
 	return 0;
 }
 
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+static int reserve_noncached(void)
+{
+	/* round down to SECTION SIZE (typicaly 1MB) limit */
+	gd->start_addr_sp &= ~(MMU_SECTION_SIZE - 1);
+	gd->start_addr_sp -= CONFIG_SYS_NONCACHED_MEMORY;
+	return 0;
+}
+#endif
+
 /* reserve memory for malloc() area */
 static int reserve_malloc(void)
 {
 	gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
 	debug("Reserving %dk for malloc() at: %08lx\n",
 	      TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+	reserve_noncached(void);
+#endif
 	return 0;
 }
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 board_f: reserve noncached space below malloc area

Hi Vikas,

Quoted 4 lines · Vikas Manocha

Noncached area at present is being initialized to random space after malloc area. It works in most the cases as it goes to stack area & stack is not overwriting it being far from it.

Please can you add a motivation for this patch and what it does.

Quoted 11 lines
---
 common/board_f.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
common/board_f.c +0 -0
index 59745d5..4910051 100644

common/board_f.c static int reserve_uboot(void) · line 447

Quoted 9 lines
common/board_f.c +6 -0
@@ -439,12 +439,25 @@ static int reserve_uboot(void)
        return 0;
 }
 
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+static int reserve_noncached(void)
+{
+       /* round down to SECTION SIZE (typicaly 1MB) limit */
+       gd->start_addr_sp &= ~(MMU_SECTION_SIZE - 1);
+       gd->start_addr_sp -= CONFIG_SYS_NONCACHED_MEMORY;

blank line before return.

common/board_f.c static int reserve_uboot(void) · line 460

Quoted 13 lines
common/board_f.c +7 -0
+       return 0;
+}
+#endif
+
 /* reserve memory for malloc() area */
 static int reserve_malloc(void)
 {
        gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
        debug("Reserving %dk for malloc() at: %08lx\n",
              TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+       reserve_noncached(void);
+#endif

How about a new function for this (with the #ifndef inside it), and a debug()?

Also I see noncached_init() calculates the size which seems brittle. Should it be added to gd?

Quoted 6 lines
common/board_f.c +0 -1
        return 0;
 }
 
--

2.7.4

Regards,
Simon

#2 lore raw

PATCH 1/1 board_f: reserve noncached space below malloc area

Hi Simon,

Quoted 12 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Friday, August 9, 2019 10:00 AM
To: Vikas MANOCHA <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Bin Meng <[email protected]>; CITOOLS <smet-aci-
reviews at lists.codex.cro.st.com>; Mario Six <[email protected]>; Patrick DELAUNAY <[email protected]>
Subject: Re: [PATCH] board_f: reserve noncached space below malloc area

Hi Vikas,

Quoted 8 lines
Quoted 4 lines · Vikas Manocha

Noncached area at present is being initialized to random space after malloc area. It works in most the cases as it goes to stack area & stack is not overwriting it being far from it.

Please can you add a motivation for this patch and what it does.

We are not reserving non-cached memory area (like for malloc, gd etc before relocation). With this patch we are reserving area just below memory area allocated to dynamic allocation.

Quoted 15 lines
Quoted 15 lines
---
 common/board_f.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
common/board_f.c index renamed from common/board_f.c +0 -0

59745d5..4910051 100644

common/board_f.c +0 -0
@@ -439,12 +439,25 @@ static int reserve_uboot(void)
        return 0;
 }
 
Quoted 8 lines

common/board_f.c static int reserve_uboot(void) · line 447

Quoted 6 lines
common/board_f.c +6 -0
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+static int reserve_noncached(void)
+{
+       /* round down to SECTION SIZE (typicaly 1MB) limit */
+       gd->start_addr_sp &= ~(MMU_SECTION_SIZE - 1);
+       gd->start_addr_sp -= CONFIG_SYS_NONCACHED_MEMORY;

blank line before return.

Sure, I will add it in v2.

Quoted 6 lines
Quoted 6 lines
common/board_f.c +4 -0
+       return 0;
+}
+#endif
+
 /* reserve memory for malloc() area */  static int
 reserve_malloc(void)  {
Quoted 8 lines

common/board_f.c static int reserve_uboot(void) · line 460

Quoted 6 lines
common/board_f.c +3 -0
        gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
        debug("Reserving %dk for malloc() at: %08lx\n",
              TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+       reserve_noncached(void);
+#endif

How about a new function for this (with the #ifndef inside it), and a debug()?

That is what I did first but this (non cached) memory area being tied to just below malloc, having it here enforces this contiguity.

Quoted 3 lines

Also I see noncached_init() calculates the size which seems brittle. Should it be added to gd?

Good point, creating new entry/ies in gd for it would make it bit cleaner but useless after initialization.
Static variables are used for this non cached memory init & allocation. It is just like for malloc, we don’t have entry in gd for it & I think the reason is same.

Cheers,
Vikas

Quoted 10 lines
Quoted 7 lines
common/board_f.c +0 -1
        return 0;
 }
 
--

2.7.4

Regards,
Simon