Skip to contentSkip to conversation

xen/privcmd-buf.c: Convert to use vm_insert_range_buggy

PATCH Superseded Souptick Joarder 2 participants 5 messages Jan 11, 2019 – Jan 15, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 9/9 xen/privcmd-buf.c: Convert to use vm_insert_range_buggy

Convert to use vm_insert_range_buggy() to map range of kernel memory to user vma.

This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/xen/privcmd-buf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/xen/privcmd-buf.c +2 -6
index de01a6d..a9d7e97 100644
@@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (vma_priv->n_pages != count)
 		ret = -ENOMEM;
 	else
-		for (i = 0; i < vma_priv->n_pages; i++) {
-			ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-					     vma_priv->pages[i]);
-			if (ret)
-				break;
-		}
+		ret = vm_insert_range_buggy(vma, vma_priv->pages,
+						vma_priv->n_pages);
 
 	if (ret)
 		privcmd_buf_vmapriv_free(vma_priv);
Signature · 1 line
1.9.1
Reviewed-by on v1 9/9
#1 lore raw
Quoted 19 lines · Souptick Joarder

Convert to use vm_insert_range_buggy() to map range of kernel memory to user vma.

This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/xen/privcmd-buf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/xen/privcmd-buf.c +0 -0
index de01a6d..a9d7e97 100644
@@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (vma_priv->n_pages != count)

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 170

Quoted 10 lines
drivers/xen/privcmd-buf.c +2 -6
 		ret = -ENOMEM;
 	else
-		for (i = 0; i < vma_priv->n_pages; i++) {
-			ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-					     vma_priv->pages[i]);
-			if (ret)
-				break;
-		}
+		ret = vm_insert_range_buggy(vma, vma_priv->pages,
+						vma_priv->n_pages);

This can use the non-buggy version. But since the original code was indeed buggy in this respect I can submit this as a separate patch later.

So

Quoted 3 lines
drivers/xen/privcmd-buf.c +0 -0
 	if (ret)
 		privcmd_buf_vmapriv_free(vma_priv);
Reviewed-by on v1 9/9
#4 lore raw
In reply to Souptick Joarder
Quoted 19 lines · Souptick Joarder

Convert to use vm_insert_range_buggy() to map range of kernel memory to user vma.

This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/xen/privcmd-buf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/xen/privcmd-buf.c +0 -0
index de01a6d..a9d7e97 100644
@@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (vma_priv->n_pages != count)

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 170

Quoted 10 lines
drivers/xen/privcmd-buf.c +2 -6
 		ret = -ENOMEM;
 	else
-		for (i = 0; i < vma_priv->n_pages; i++) {
-			ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-					     vma_priv->pages[i]);
-			if (ret)
-				break;
-		}
+		ret = vm_insert_range_buggy(vma, vma_priv->pages,
+						vma_priv->n_pages);

This can use the non-buggy version. But since the original code was indeed buggy in this respect I can submit this as a separate patch later.

So

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 173

Quoted 3 lines
drivers/xen/privcmd-buf.c +0 -0
 	if (ret)
 		privcmd_buf_vmapriv_free(vma_priv);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Boris Ostrovsky
Quoted 35 lines · Boris Ostrovsky
Quoted 19 lines · Souptick Joarder

Convert to use vm_insert_range_buggy() to map range of kernel memory to user vma.

This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/xen/privcmd-buf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/xen/privcmd-buf.c +0 -0
index de01a6d..a9d7e97 100644
@@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
      if (vma_priv->n_pages != count)

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 170

Quoted 10 lines
drivers/xen/privcmd-buf.c +2 -6
              ret = -ENOMEM;
      else
-             for (i = 0; i < vma_priv->n_pages; i++) {
-                     ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-                                          vma_priv->pages[i]);
-                     if (ret)
-                             break;
-             }
+             ret = vm_insert_range_buggy(vma, vma_priv->pages,
+                                             vma_priv->n_pages);

This can use the non-buggy version. But since the original code was indeed buggy in this respect I can submit this as a separate patch later.

Quoted 3 lines

So

Thanks Boris.

Quoted 6 lines
Quoted 5 lines
drivers/xen/privcmd-buf.c +0 -0
      if (ret)
              privcmd_buf_vmapriv_free(vma_priv);
#3 lore raw
In reply to Boris Ostrovsky
Quoted 35 lines · Boris Ostrovsky
Quoted 19 lines · Souptick Joarder

Convert to use vm_insert_range_buggy() to map range of kernel memory to user vma.

This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert.

---
 drivers/xen/privcmd-buf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/xen/privcmd-buf.c +0 -0
index de01a6d..a9d7e97 100644
@@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
      if (vma_priv->n_pages != count)

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 170

Quoted 10 lines
drivers/xen/privcmd-buf.c +2 -6
              ret = -ENOMEM;
      else
-             for (i = 0; i < vma_priv->n_pages; i++) {
-                     ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-                                          vma_priv->pages[i]);
-                     if (ret)
-                             break;
-             }
+             ret = vm_insert_range_buggy(vma, vma_priv->pages,
+                                             vma_priv->n_pages);

This can use the non-buggy version. But since the original code was indeed buggy in this respect I can submit this as a separate patch later.

Quoted 3 lines

So

Thanks Boris.

Quoted 6 lines

drivers/xen/privcmd-buf.c static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) · line 173

Quoted 5 lines
drivers/xen/privcmd-buf.c +0 -0
      if (ret)
              privcmd_buf_vmapriv_free(vma_priv);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel