Skip to contentSkip to conversation

fbcon: use kvmalloc() for scrollback buffer

PATCH In review Konstantin Khorenko 2 participants 4 messages Nov 26, 2018 – Feb 8, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbcon: use kvmalloc() for scrollback buffer

Scrollback frame buffer is rather big - 32K,
so it requires 3rd order page, so let's use kvmalloc() instead of ordinary kmalloc() for it.

---
 drivers/video/fbdev/core/fbcon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/core/fbcon.c +3 -3
index 8958ccc8b1ac..2b1a34d3f5e2 100644
@@ -992,7 +992,7 @@ static const char *fbcon_startup(void)
 			if (!softback_buf) {
 				softback_buf =
 				    (unsigned long)
-				    kmalloc(fbcon_softback_size,
+				    kvmalloc(fbcon_softback_size,
 					    GFP_KERNEL);
 				if (!softback_buf) {
 					fbcon_softback_size = 0;
@@ -1001,7 +1001,7 @@ static const char *fbcon_startup(void)
 			}
 		} else {
 			if (softback_buf) {
-				kfree((void *) softback_buf);
+				kvfree((void *) softback_buf);
 				softback_buf = 0;
 				softback_top = 0;
 			}
@@ -3665,7 +3665,7 @@ static void fbcon_exit(void)
 	}
 #endif
 
-	kfree((void *)softback_buf);
+	kvfree((void *)softback_buf);
 	softback_buf = 0UL;
 
 	for_each_registered_fb(i) {
Signature · 1 line
2.15.1
#1 lore raw

Hi,

Quoted 3 lines · Konstantin Khorenko

Scrollback frame buffer is rather big - 32K,
so it requires 3rd order page, so let's use kvmalloc() instead of ordinary kmalloc() for it.

Is it actually safe to use non-contiguous memory for softback_buf?

Quoted 28 lines
---
 drivers/video/fbdev/core/fbcon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/core/fbcon.c +2 -2
index 8958ccc8b1ac..2b1a34d3f5e2 100644
@@ -992,7 +992,7 @@ static const char *fbcon_startup(void)
 			if (!softback_buf) {
 				softback_buf =
 				    (unsigned long)
-				    kmalloc(fbcon_softback_size,
+				    kvmalloc(fbcon_softback_size,
 					    GFP_KERNEL);
 				if (!softback_buf) {
 					fbcon_softback_size = 0;
@@ -1001,7 +1001,7 @@ static const char *fbcon_startup(void)
 			}
 		} else {
 			if (softback_buf) {
-				kfree((void *) softback_buf);
+				kvfree((void *) softback_buf);
 				softback_buf = 0;
 				softback_top = 0;
 			}

drivers/video/fbdev/core/fbcon.c static void fbcon_exit(void) · line 3671

Quoted 8 lines
drivers/video/fbdev/core/fbcon.c +1 -1
@@ -3665,7 +3665,7 @@ static void fbcon_exit(void)
 	}
 #endif
 
-	kfree((void *)softback_buf);
+	kvfree((void *)softback_buf);
 	softback_buf = 0UL;
 
 	for_each_registered_fb(i) {

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

#2 lore raw

Hi Bartlomiej,

Quoted 6 lines · Bartlomiej Zolnierkiewicz
Quoted 3 lines · Konstantin Khorenko

Scrollback frame buffer is rather big - 32K,
so it requires 3rd order page, so let's use kvmalloc() instead of ordinary kmalloc() for it.

Is it actually safe to use non-contiguous memory for softback_buf?

Well, that's why we need a review. :)

i've asked myself same question while fixing this,
i've dig sources a bit and did not find places when softback_buf is provided for DMA, all other places seems to work with virtual addresses, so there should be no problem.

Even more i saw a function which mentions that softback might be non-contigious:

/* As we might be inside of softback, we may work with non-contiguous buffer,
that's why we have to use a separate routine. */
static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)

So i think it's safe to use kvmalloc() here.

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

Quoted 42 lines
Quoted 28 lines
---
 drivers/video/fbdev/core/fbcon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/core/fbcon.c +2 -2
index 8958ccc8b1ac..2b1a34d3f5e2 100644
@@ -992,7 +992,7 @@ static const char *fbcon_startup(void)
 			if (!softback_buf) {
 				softback_buf =
 				    (unsigned long)
-				    kmalloc(fbcon_softback_size,
+				    kvmalloc(fbcon_softback_size,
 					    GFP_KERNEL);
 				if (!softback_buf) {
 					fbcon_softback_size = 0;
@@ -1001,7 +1001,7 @@ static const char *fbcon_startup(void)
 			}
 		} else {
 			if (softback_buf) {
-				kfree((void *) softback_buf);
+				kvfree((void *) softback_buf);
 				softback_buf = 0;
 				softback_top = 0;
 			}

drivers/video/fbdev/core/fbcon.c static void fbcon_exit(void) · line 3671

Quoted 8 lines
drivers/video/fbdev/core/fbcon.c +1 -1
@@ -3665,7 +3665,7 @@ static void fbcon_exit(void)
 	}
 #endif
 
-	kfree((void *)softback_buf);
+	kvfree((void *)softback_buf);
 	softback_buf = 0UL;
 
 	for_each_registered_fb(i) {

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

#3 lore raw
Quoted 11 lines · Konstantin Khorenko

Hi Bartlomiej,

Quoted 6 lines · Bartlomiej Zolnierkiewicz
Quoted 3 lines · Konstantin Khorenko

Scrollback frame buffer is rather big - 32K,
so it requires 3rd order page, so let's use kvmalloc() instead of ordinary kmalloc() for it.

Is it actually safe to use non-contiguous memory for softback_buf?

Well, that's why we need a review. :)

:)

Quoted 11 lines

i've asked myself same question while fixing this,
i've dig sources a bit and did not find places when softback_buf is provided for DMA, all other places seems to work with virtual addresses, so there should be no problem.

Even more i saw a function which mentions that softback might be non-contigious:

/* As we might be inside of softback, we may work with non-contiguous buffer,
that's why we have to use a separate routine. */
static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)

So i think it's safe to use kvmalloc() here.

Patch queued for v5.1, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics