linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vt: don't use kmalloc() for the unicode screen buffer
@ 2020-03-28 21:59 Nicolas Pitre
  2020-03-28 23:35 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nicolas Pitre @ 2020-03-28 21:59 UTC (permalink / raw)
  To: gregkh
  Cc: Chen Wandun, Adam Borowski, jslaby, daniel.vetter, sam,
	b.zolnierkie, lukas, ghalat, linux-kernel

Even if the actual screen size is bounded in vc_do_resize(), the unicode 
buffer is still a little more than twice the size of the glyph buffer
and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
from user space.

Since there is no point having a physically contiguous buffer here, 
let's avoid the above issue as well as reducing pressure on high order
allocations by using vmalloc() instead.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Cc: <stable@vger.kernel.org>

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 15d2769805..7c10edb648 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -350,7 +350,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 	/* allocate everything in one go */
 	memsize = cols * rows * sizeof(char32_t);
 	memsize += rows * sizeof(char32_t *);
-	p = kmalloc(memsize, GFP_KERNEL);
+	p = vmalloc(memsize);
 	if (!p)
 		return NULL;
 
@@ -366,7 +366,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 
 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
 {
-	kfree(vc->vc_uni_screen);
+	vfree(vc->vc_uni_screen);
 	vc->vc_uni_screen = new_uniscr;
 }
 

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

* Re: [PATCH] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-28 21:59 [PATCH] vt: don't use kmalloc() for the unicode screen buffer Nicolas Pitre
@ 2020-03-28 23:35 ` kbuild test robot
  2020-03-29  0:13 ` kbuild test robot
  2020-03-29  2:25 ` [PATCH v2] " Nicolas Pitre
  2 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2020-03-28 23:35 UTC (permalink / raw)
  To: Nicolas Pitre
  Cc: kbuild-all, gregkh@linuxfoundation.org, Chen Wandun,
	Adam Borowski, jslaby, daniel.vetter, sam, b.zolnierkie, lukas,
	ghalat, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2712 bytes --]

Hi Nicolas,

I love your patch! Yet something to improve:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on v5.6-rc7 next-20200327]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Nicolas-Pitre/vt-don-t-use-kmalloc-for-the-unicode-screen-buffer/20200329-060123
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: mips-fuloong2e_defconfig (attached as .config)
compiler: mips64el-linux-gcc (GCC) 5.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=5.5.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/tty/vt/vt.c: In function 'vc_uniscr_alloc':
>> drivers/tty/vt/vt.c:353:6: error: implicit declaration of function 'vmalloc' [-Werror=implicit-function-declaration]
     p = vmalloc(memsize);
         ^
>> drivers/tty/vt/vt.c:353:4: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     p = vmalloc(memsize);
       ^
   drivers/tty/vt/vt.c: In function 'vc_uniscr_set':
>> drivers/tty/vt/vt.c:369:2: error: implicit declaration of function 'vfree' [-Werror=implicit-function-declaration]
     vfree(vc->vc_uni_screen);
     ^
   cc1: some warnings being treated as errors

vim +/vmalloc +353 drivers/tty/vt/vt.c

   343	
   344	static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
   345	{
   346		struct uni_screen *uniscr;
   347		void *p;
   348		unsigned int memsize, i;
   349	
   350		/* allocate everything in one go */
   351		memsize = cols * rows * sizeof(char32_t);
   352		memsize += rows * sizeof(char32_t *);
 > 353		p = vmalloc(memsize);
   354		if (!p)
   355			return NULL;
   356	
   357		/* initial line pointers */
   358		uniscr = p;
   359		p = uniscr->lines + rows;
   360		for (i = 0; i < rows; i++) {
   361			uniscr->lines[i] = p;
   362			p += cols * sizeof(char32_t);
   363		}
   364		return uniscr;
   365	}
   366	
   367	static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
   368	{
 > 369		vfree(vc->vc_uni_screen);
   370		vc->vc_uni_screen = new_uniscr;
   371	}
   372	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 19192 bytes --]

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

* Re: [PATCH] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-28 21:59 [PATCH] vt: don't use kmalloc() for the unicode screen buffer Nicolas Pitre
  2020-03-28 23:35 ` kbuild test robot
@ 2020-03-29  0:13 ` kbuild test robot
  2020-03-29  2:25 ` [PATCH v2] " Nicolas Pitre
  2 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2020-03-29  0:13 UTC (permalink / raw)
  To: Nicolas Pitre
  Cc: kbuild-all, gregkh@linuxfoundation.org, Chen Wandun,
	Adam Borowski, jslaby, daniel.vetter, sam, b.zolnierkie, lukas,
	ghalat, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2867 bytes --]

Hi Nicolas,

I love your patch! Yet something to improve:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on v5.6-rc7 next-20200327]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Nicolas-Pitre/vt-don-t-use-kmalloc-for-the-unicode-screen-buffer/20200329-060123
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: mips-nlm_xlp_defconfig (attached as .config)
compiler: mips64-linux-gcc (GCC) 9.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=9.2.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/tty/vt/vt.c: In function 'vc_uniscr_alloc':
>> drivers/tty/vt/vt.c:353:6: error: implicit declaration of function 'vmalloc'; did you mean 'kvmalloc'? [-Werror=implicit-function-declaration]
     353 |  p = vmalloc(memsize);
         |      ^~~~~~~
         |      kvmalloc
>> drivers/tty/vt/vt.c:353:4: warning: assignment to 'void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     353 |  p = vmalloc(memsize);
         |    ^
   drivers/tty/vt/vt.c: In function 'vc_uniscr_set':
>> drivers/tty/vt/vt.c:369:2: error: implicit declaration of function 'vfree'; did you mean 'kvfree'? [-Werror=implicit-function-declaration]
     369 |  vfree(vc->vc_uni_screen);
         |  ^~~~~
         |  kvfree
   cc1: some warnings being treated as errors

vim +353 drivers/tty/vt/vt.c

   343	
   344	static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
   345	{
   346		struct uni_screen *uniscr;
   347		void *p;
   348		unsigned int memsize, i;
   349	
   350		/* allocate everything in one go */
   351		memsize = cols * rows * sizeof(char32_t);
   352		memsize += rows * sizeof(char32_t *);
 > 353		p = vmalloc(memsize);
   354		if (!p)
   355			return NULL;
   356	
   357		/* initial line pointers */
   358		uniscr = p;
   359		p = uniscr->lines + rows;
   360		for (i = 0; i < rows; i++) {
   361			uniscr->lines[i] = p;
   362			p += cols * sizeof(char32_t);
   363		}
   364		return uniscr;
   365	}
   366	
   367	static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
   368	{
 > 369		vfree(vc->vc_uni_screen);
   370		vc->vc_uni_screen = new_uniscr;
   371	}
   372	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 21499 bytes --]

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

* [PATCH v2] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-28 21:59 [PATCH] vt: don't use kmalloc() for the unicode screen buffer Nicolas Pitre
  2020-03-28 23:35 ` kbuild test robot
  2020-03-29  0:13 ` kbuild test robot
@ 2020-03-29  2:25 ` Nicolas Pitre
  2020-03-30 19:07   ` Sam Ravnborg
  2 siblings, 1 reply; 7+ messages in thread
From: Nicolas Pitre @ 2020-03-29  2:25 UTC (permalink / raw)
  To: gregkh
  Cc: Chen Wandun, Adam Borowski, jslaby, daniel.vetter, sam,
	b.zolnierkie, lukas, ghalat, linux-kernel

Even if the actual screen size is bounded in vc_do_resize(), the unicode 
buffer is still a little more than twice the size of the glyph buffer
and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
from user space.

Since there is no point having a physically contiguous buffer here, 
let's avoid the above issue as well as reducing pressure on high order
allocations by using vmalloc() instead.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Cc: <stable@vger.kernel.org>

---

Changes since v1:

- Added missing include, found by kbuild test robot.
  Strange that my own build doesn't complain.

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 15d2769805..d9eb5661e9 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -81,6 +81,7 @@
 #include <linux/errno.h>
 #include <linux/kd.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
 #include <linux/major.h>
 #include <linux/mm.h>
 #include <linux/console.h>
@@ -350,7 +351,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 	/* allocate everything in one go */
 	memsize = cols * rows * sizeof(char32_t);
 	memsize += rows * sizeof(char32_t *);
-	p = kmalloc(memsize, GFP_KERNEL);
+	p = vmalloc(memsize);
 	if (!p)
 		return NULL;
 
@@ -366,7 +367,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 
 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
 {
-	kfree(vc->vc_uni_screen);
+	vfree(vc->vc_uni_screen);
 	vc->vc_uni_screen = new_uniscr;
 }
 

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

* Re: [PATCH v2] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-29  2:25 ` [PATCH v2] " Nicolas Pitre
@ 2020-03-30 19:07   ` Sam Ravnborg
  2020-03-31  8:43     ` Daniel Vetter
  0 siblings, 1 reply; 7+ messages in thread
From: Sam Ravnborg @ 2020-03-30 19:07 UTC (permalink / raw)
  To: Nicolas Pitre
  Cc: gregkh, Chen Wandun, Adam Borowski, jslaby, daniel.vetter,
	b.zolnierkie, lukas, ghalat, linux-kernel

Hi Nicolas

On Sat, Mar 28, 2020 at 10:25:11PM -0400, Nicolas Pitre wrote:
> Even if the actual screen size is bounded in vc_do_resize(), the unicode 
> buffer is still a little more than twice the size of the glyph buffer
> and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
> from user space.
> 
> Since there is no point having a physically contiguous buffer here, 
> let's avoid the above issue as well as reducing pressure on high order
> allocations by using vmalloc() instead.
> 
> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
> Cc: <stable@vger.kernel.org>
> 
> ---
> 
> Changes since v1:
> 
> - Added missing include, found by kbuild test robot.
>   Strange that my own build doesn't complain.

When I did the drmP.h removal vmalloc was one of the header files
that turned up missing in many cases - but only for some architectures.
I learned to include alpha in the build.
If it survived building for alpha then I had fixed the majority
of the issues related to random inherited includes.

The patch itself looks good.

Acked-by: Sam Ravnborg <sam@ravnborg.org>

> 
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 15d2769805..d9eb5661e9 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -81,6 +81,7 @@
>  #include <linux/errno.h>
>  #include <linux/kd.h>
>  #include <linux/slab.h>
> +#include <linux/vmalloc.h>
>  #include <linux/major.h>
>  #include <linux/mm.h>
>  #include <linux/console.h>
> @@ -350,7 +351,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
>  	/* allocate everything in one go */
>  	memsize = cols * rows * sizeof(char32_t);
>  	memsize += rows * sizeof(char32_t *);
> -	p = kmalloc(memsize, GFP_KERNEL);
> +	p = vmalloc(memsize);
>  	if (!p)
>  		return NULL;
>  
> @@ -366,7 +367,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
>  
>  static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
>  {
> -	kfree(vc->vc_uni_screen);
> +	vfree(vc->vc_uni_screen);
>  	vc->vc_uni_screen = new_uniscr;
>  }
>  

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

* Re: [PATCH v2] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-30 19:07   ` Sam Ravnborg
@ 2020-03-31  8:43     ` Daniel Vetter
  2020-03-31  9:30       ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2020-03-31  8:43 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Nicolas Pitre, Greg KH, Chen Wandun, Adam Borowski, Jiri Slaby,
	Bartlomiej Zolnierkiewicz, Lukas Wunner, ghalat,
	Linux Kernel Mailing List

On Mon, Mar 30, 2020 at 9:08 PM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Nicolas
>
> On Sat, Mar 28, 2020 at 10:25:11PM -0400, Nicolas Pitre wrote:
> > Even if the actual screen size is bounded in vc_do_resize(), the unicode
> > buffer is still a little more than twice the size of the glyph buffer
> > and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
> > from user space.
> >
> > Since there is no point having a physically contiguous buffer here,
> > let's avoid the above issue as well as reducing pressure on high order
> > allocations by using vmalloc() instead.
> >
> > Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
> > Cc: <stable@vger.kernel.org>
> >
> > ---
> >
> > Changes since v1:
> >
> > - Added missing include, found by kbuild test robot.
> >   Strange that my own build doesn't complain.
>
> When I did the drmP.h removal vmalloc was one of the header files
> that turned up missing in many cases - but only for some architectures.
> I learned to include alpha in the build.
> If it survived building for alpha then I had fixed the majority
> of the issues related to random inherited includes.
>
> The patch itself looks good.
>
> Acked-by: Sam Ravnborg <sam@ravnborg.org>

Greg, I'm assuming you'll pick this up through the tty tree? I kinda
want to stop the habit of merging vt patches, maybe then
get_maintainers will stop thinking I'm responsible somehow :-)
-Daniel

>
> >
> > diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> > index 15d2769805..d9eb5661e9 100644
> > --- a/drivers/tty/vt/vt.c
> > +++ b/drivers/tty/vt/vt.c
> > @@ -81,6 +81,7 @@
> >  #include <linux/errno.h>
> >  #include <linux/kd.h>
> >  #include <linux/slab.h>
> > +#include <linux/vmalloc.h>
> >  #include <linux/major.h>
> >  #include <linux/mm.h>
> >  #include <linux/console.h>
> > @@ -350,7 +351,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
> >       /* allocate everything in one go */
> >       memsize = cols * rows * sizeof(char32_t);
> >       memsize += rows * sizeof(char32_t *);
> > -     p = kmalloc(memsize, GFP_KERNEL);
> > +     p = vmalloc(memsize);
> >       if (!p)
> >               return NULL;
> >
> > @@ -366,7 +367,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
> >
> >  static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
> >  {
> > -     kfree(vc->vc_uni_screen);
> > +     vfree(vc->vc_uni_screen);
> >       vc->vc_uni_screen = new_uniscr;
> >  }
> >



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* Re: [PATCH v2] vt: don't use kmalloc() for the unicode screen buffer
  2020-03-31  8:43     ` Daniel Vetter
@ 2020-03-31  9:30       ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2020-03-31  9:30 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Sam Ravnborg, Nicolas Pitre, Chen Wandun, Adam Borowski,
	Jiri Slaby, Bartlomiej Zolnierkiewicz, Lukas Wunner, ghalat,
	Linux Kernel Mailing List

On Tue, Mar 31, 2020 at 10:43:11AM +0200, Daniel Vetter wrote:
> On Mon, Mar 30, 2020 at 9:08 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Nicolas
> >
> > On Sat, Mar 28, 2020 at 10:25:11PM -0400, Nicolas Pitre wrote:
> > > Even if the actual screen size is bounded in vc_do_resize(), the unicode
> > > buffer is still a little more than twice the size of the glyph buffer
> > > and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
> > > from user space.
> > >
> > > Since there is no point having a physically contiguous buffer here,
> > > let's avoid the above issue as well as reducing pressure on high order
> > > allocations by using vmalloc() instead.
> > >
> > > Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
> > > Cc: <stable@vger.kernel.org>
> > >
> > > ---
> > >
> > > Changes since v1:
> > >
> > > - Added missing include, found by kbuild test robot.
> > >   Strange that my own build doesn't complain.
> >
> > When I did the drmP.h removal vmalloc was one of the header files
> > that turned up missing in many cases - but only for some architectures.
> > I learned to include alpha in the build.
> > If it survived building for alpha then I had fixed the majority
> > of the issues related to random inherited includes.
> >
> > The patch itself looks good.
> >
> > Acked-by: Sam Ravnborg <sam@ravnborg.org>
> 
> Greg, I'm assuming you'll pick this up through the tty tree? I kinda
> want to stop the habit of merging vt patches, maybe then
> get_maintainers will stop thinking I'm responsible somehow :-)

Yes, I'll take it, and have been taking vt patches for a few releases
now so don't worry, you aren't responsible anymore :)

thanks,

greg k-h

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

end of thread, other threads:[~2020-03-31 10:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 21:59 [PATCH] vt: don't use kmalloc() for the unicode screen buffer Nicolas Pitre
2020-03-28 23:35 ` kbuild test robot
2020-03-29  0:13 ` kbuild test robot
2020-03-29  2:25 ` [PATCH v2] " Nicolas Pitre
2020-03-30 19:07   ` Sam Ravnborg
2020-03-31  8:43     ` Daniel Vetter
2020-03-31  9:30       ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).