* [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap()
@ 2019-08-22 14:26 Qian Cai
2019-09-05 12:26 ` Qian Cai
2019-09-05 13:39 ` Baoquan He
0 siblings, 2 replies; 3+ messages in thread
From: Qian Cai @ 2019-08-22 14:26 UTC (permalink / raw)
To: tglx, mingo, hpa; +Cc: bhe, x86, linux-kernel, Qian Cai
If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(),
even without the return statement the loop will not run anyway. The only
time it needs to set "memmap_too_large = true" in this situation is
"memmap_too_large" is "false" currently. Hence, the code could be
simplified.
Signed-off-by: Qian Cai <cai@lca.pw>
---
arch/x86/boot/compressed/kaslr.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 2e53c056ba20..35c6942fb95b 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
{
static int i;
- if (i >= MAX_MEMMAP_REGIONS)
- return;
-
while (str && (i < MAX_MEMMAP_REGIONS)) {
int rc;
unsigned long long start, size;
@@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
}
/* More than 4 memmaps, fail kaslr */
- if ((i >= MAX_MEMMAP_REGIONS) && str)
+ if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)
memmap_too_large = true;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap()
2019-08-22 14:26 [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap() Qian Cai
@ 2019-09-05 12:26 ` Qian Cai
2019-09-05 13:39 ` Baoquan He
1 sibling, 0 replies; 3+ messages in thread
From: Qian Cai @ 2019-09-05 12:26 UTC (permalink / raw)
To: tglx, mingo, hpa, Borislav Petkov; +Cc: bhe, x86, linux-kernel
Ping. Please take a look at this trivial patch.
On Thu, 2019-08-22 at 10:26 -0400, Qian Cai wrote:
> If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(),
> even without the return statement the loop will not run anyway. The only
> time it needs to set "memmap_too_large = true" in this situation is
> "memmap_too_large" is "false" currently. Hence, the code could be
> simplified.
>
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
> arch/x86/boot/compressed/kaslr.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/kaslr.c
> b/arch/x86/boot/compressed/kaslr.c
> index 2e53c056ba20..35c6942fb95b 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
> {
> static int i;
>
> - if (i >= MAX_MEMMAP_REGIONS)
> - return;
> -
> while (str && (i < MAX_MEMMAP_REGIONS)) {
> int rc;
> unsigned long long start, size;
> @@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
> }
>
> /* More than 4 memmaps, fail kaslr */
> - if ((i >= MAX_MEMMAP_REGIONS) && str)
> + if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)
> memmap_too_large = true;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap()
2019-08-22 14:26 [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap() Qian Cai
2019-09-05 12:26 ` Qian Cai
@ 2019-09-05 13:39 ` Baoquan He
1 sibling, 0 replies; 3+ messages in thread
From: Baoquan He @ 2019-09-05 13:39 UTC (permalink / raw)
To: Qian Cai; +Cc: tglx, mingo, hpa, x86, linux-kernel
On 08/22/19 at 10:26am, Qian Cai wrote:
> If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(),
> even without the return statement the loop will not run anyway. The only
> time it needs to set "memmap_too_large = true" in this situation is
> "memmap_too_large" is "false" currently. Hence, the code could be
> simplified.
It seems not improved much. If far more than MAX_MEMMAP_REGIONS 'memmap='
specified, the if condition checking looks more straightforward. Anyway,
it's not simplifying much, in my opinion.
Thanks
Baoquan
>
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
> arch/x86/boot/compressed/kaslr.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index 2e53c056ba20..35c6942fb95b 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
> {
> static int i;
>
> - if (i >= MAX_MEMMAP_REGIONS)
> - return;
> -
> while (str && (i < MAX_MEMMAP_REGIONS)) {
> int rc;
> unsigned long long start, size;
> @@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
> }
>
> /* More than 4 memmaps, fail kaslr */
> - if ((i >= MAX_MEMMAP_REGIONS) && str)
> + if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)
> memmap_too_large = true;
> }
>
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-05 13:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 14:26 [PATCH] x86/kaslr: simplify the code in mem_avoid_memmap() Qian Cai
2019-09-05 12:26 ` Qian Cai
2019-09-05 13:39 ` Baoquan He
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.