Skip to contentSkip to conversation

auxdisplay/ht16k33.c: Convert to use vm_map_pages_zero()

PATCH In review Souptick Joarder 3 participants 9 messages May 20, 2019 – May 28, 2019

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

PATCH 2/2 auxdisplay/ht16k33.c: Convert to use vm_map_pages_zero()

While using mmap, the incorrect value of length and vm_pgoff are ignored and this driver go ahead with mapping fbdev.buffer to user vma.

Convert vm_insert_pages() to use vm_map_pages_zero(). We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _zero suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/auxdisplay/ht16k33.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/ht16k33.c +2 -2
index 21393ec..9c0bb77 100644
@@ -223,9 +223,9 @@ static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)
 static int ht16k33_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct ht16k33_priv *priv = info->par;
+	struct page *pages = virt_to_page(priv->fbdev.buffer);
 
-	return vm_insert_page(vma, vma->vm_start,
-			      virt_to_page(priv->fbdev.buffer));
+	return vm_map_pages_zero(vma, &pages, 1);
 }
 
 static struct fb_ops ht16k33_fb_ops = {
Signature · 1 line
1.9.1
maintainer Acked-by on v1 2/2
#1 lore raw
Quoted 20 lines · On Mon, 20 May 2019 21:00:58 +0530 Souptick Joarder <[email protected]>…

While using mmap, the incorrect value of length and vm_pgoff are ignored and this driver go ahead with mapping fbdev.buffer to user vma.

Convert vm_insert_pages() to use vm_map_pages_zero(). We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _zero suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/auxdisplay/ht16k33.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/ht16k33.c +0 -0
index 21393ec..9c0bb77 100644
@@ -223,9 +223,9 @@ static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)
 static int ht16k33_mmap(struct fb_info *info, struct vm_area_struct *vma)

drivers/auxdisplay/ht16k33.c static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi) · line 231

Quoted 10 lines
drivers/auxdisplay/ht16k33.c +2 -2
 {
 	struct ht16k33_priv *priv = info->par;
+	struct page *pages = virt_to_page(priv->fbdev.buffer);
 
-	return vm_insert_page(vma, vma->vm_start,
-			      virt_to_page(priv->fbdev.buffer));
+	return vm_map_pages_zero(vma, &pages, 1);
 }
 
 static struct fb_ops ht16k33_fb_ops = {
#2 lore raw
Quoted 28 lines · Robin van der Gracht
Quoted 24 lines · On Mon, 20 May 2019 21:00:58 +0530 Souptick Joarder <[email protected]>…

While using mmap, the incorrect value of length and vm_pgoff are ignored and this driver go ahead with mapping fbdev.buffer to user vma.

Convert vm_insert_pages() to use vm_map_pages_zero(). We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _zero suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/auxdisplay/ht16k33.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/ht16k33.c +1 -0
index 21393ec..9c0bb77 100644
@@ -223,9 +223,9 @@ static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)
 static int ht16k33_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
      struct ht16k33_priv *priv = info->par;
+     struct page *pages = virt_to_page(priv->fbdev.buffer);
 
Quoted 8 lines

drivers/auxdisplay/ht16k33.c static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi) · line 231

Quoted 6 lines
drivers/auxdisplay/ht16k33.c +1 -2
-     return vm_insert_page(vma, vma->vm_start,
-                           virt_to_page(priv->fbdev.buffer));
+     return vm_map_pages_zero(vma, &pages, 1);
 }
 
 static struct fb_ops ht16k33_fb_ops = {

Miguel, Ack from Robin is missing in linux-next-20190523 when applied.

#3 lore raw
Quoted 2 lines · Souptick Joarder

Miguel, Ack from Robin is missing in linux-next-20190523 when applied.

Thanks for the warning! I wanted to review first but didn't get to it yet.

Taking a quick look now, by the way, why does vm_map_pages_zero() (and __vm_map_pages() etc.) get a pointer to an array instead of a pointer to the first element?

Cheers,
Miguel

#7 lore raw
In reply to Souptick Joarder
Quoted 4 lines · Souptick Joarder

While using mmap, the incorrect value of length and vm_pgoff are ignored and this driver go ahead with mapping fbdev.buffer to user vma.

Typos: values*, goes* (same for the other patch)

Quoted 4 lines

Convert vm_insert_pages() to use vm_map_pages_zero(). We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _zero suffix on the function name and if that causes regressions, it gives us an easy way to revert.

Would it be possible to add a "Link:" to where these new functions are discussed/used (maybe a lore.kernel.org link?)?

Thanks for the patch!

Cheers,
Miguel

#4 lore raw
In reply to Miguel Ojeda
Quoted 4 lines · Miguel Ojeda

Taking a quick look now, by the way, why does vm_map_pages_zero() (and __vm_map_pages() etc.) get a pointer to an array instead of a pointer to the first element?

Also, in __vm_map_pages(), semantically w.r.t. to the comment, shouldn't the first check test for equality too? (i.e. for vm_pgoff == num)? (even if such case fails in the second test anyway).

Cheers,
Miguel

#5 lore raw
Quoted 10 lines · Miguel Ojeda
Quoted 7 lines · Miguel Ojeda

Taking a quick look now, by the way, why does vm_map_pages_zero() (and __vm_map_pages() etc.) get a pointer to an array instead of a pointer to the first element?

For this particular driver, one page is getting mapped into vma. But there are other
places where a entire page array ( with more than one pages) mapped into vma. That's the reason to pass pointer to an array and do rest of the operations inside __vm_map_pages().

https://lkml.org/lkml/2019/3/18/1265

Quoted 4 lines

Also, in __vm_map_pages(), semantically w.r.t. to the comment, shouldn't the first check test for equality too? (i.e. for vm_pgoff == num)? (even if such case fails in the second test anyway).

Sorry, didn't get it. Do you mean there should be a separate check for *vm_pgoff == num* ?

Quoted 2 lines

Cheers,
Miguel

#8 lore raw
In reply to Miguel Ojeda
Quoted 8 lines · Miguel Ojeda
Quoted 4 lines · Souptick Joarder

While using mmap, the incorrect value of length and vm_pgoff are ignored and this driver go ahead with mapping fbdev.buffer to user vma.

Typos: values*, goes* (same for the other patch)

Ok, will add it into v2.

Quoted 8 lines
Quoted 5 lines

Convert vm_insert_pages() to use vm_map_pages_zero(). We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _zero suffix on the function name and if that causes regressions, it gives us an easy way to revert.

Would it be possible to add a "Link:" to where these new functions are discussed/used (maybe a lore.kernel.org link?)?

This might be helpful.
https://lkml.org/lkml/2018/12/24/204

Quoted 5 lines

Thanks for the patch!

Cheers,
Miguel

#6 lore raw
In reply to Souptick Joarder
Quoted 10 lines · Souptick Joarder
Quoted 4 lines
Quoted 4 lines

Taking a quick look now, by the way, why does vm_map_pages_zero() (and __vm_map_pages() etc.) get a pointer to an array instead of a pointer to the first element?

For this particular driver, one page is getting mapped into vma. But there are other
places where a entire page array ( with more than one pages) mapped into vma. That's the reason to pass pointer to an array and do rest of the operations inside __vm_map_pages().

Ah, "pointer to array of source kernel pages" made me think the actual struct pages were the ones consecutive in memory, not the pointers. Maybe "array of page pointers" is more clear.

Quoted 6 lines
Quoted 3 lines

Also, in __vm_map_pages(), semantically w.r.t. to the comment, shouldn't the first check test for equality too? (i.e. for vm_pgoff == num)? (even if such case fails in the second test anyway).

Sorry, didn't get it. Do you mean there should be a separate check for *vm_pgoff == num* ?

No, that the first check should be widened. I will send a patch.

Cheers,
Miguel