[SRU,Xenial,1/1] s390/qeth: use vzalloc for QUERY OAT buffer

Message ID f59c847a033cb3deedcc16d387f27b37fafe1725.1537259280.git.joseph.salisbury@canonical.com
State New
Headers show
Series
  • s390/qeth: use vzalloc for QUERY OAT buffer
Related show

Commit Message

Joseph Salisbury Sept. 20, 2018, 9:42 a.m.
From: Wenjia Zhang <wenjia@linux.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1793086

qeth_query_oat_command() currently allocates the kernel buffer for
the SIOC_QETH_QUERY_OAT ioctl with kzalloc. So on systems with
fragmented memory, large allocations may fail (eg. the qethqoat tool by
default uses 132KB).

Solve this issue by using vzalloc, backing the allocation with
non-contiguous memory.

Signed-off-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(backported from commit aec45e857c5538664edb76a60dd452e3265f37d1)
Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
---
 drivers/s390/net/qeth_core_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stefan Bader Sept. 27, 2018, 4:45 p.m. | #1
On 20.09.2018 11:42, Joseph Salisbury wrote:
> From: Wenjia Zhang <wenjia@linux.ibm.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1793086
> 
> qeth_query_oat_command() currently allocates the kernel buffer for
> the SIOC_QETH_QUERY_OAT ioctl with kzalloc. So on systems with
> fragmented memory, large allocations may fail (eg. the qethqoat tool by
> default uses 132KB).
> 
> Solve this issue by using vzalloc, backing the allocation with
> non-contiguous memory.
> 
> Signed-off-by: Wenjia Zhang <wenjia@linux.ibm.com>
> Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
> Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> (backported from commit aec45e857c5538664edb76a60dd452e3265f37d1)
> Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  drivers/s390/net/qeth_core_main.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> index 40284b4..f0a34a2 100644
> --- a/drivers/s390/net/qeth_core_main.c
> +++ b/drivers/s390/net/qeth_core_main.c
> @@ -19,6 +19,8 @@
>  #include <linux/mii.h>
>  #include <linux/kthread.h>
>  #include <linux/slab.h>
> +#include <linux/vmalloc.h>
> +
>  #include <net/iucv/af_iucv.h>
>  #include <net/dsfield.h>
>  
> @@ -4705,7 +4707,7 @@ int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
>  
>  	priv.buffer_len = oat_data.buffer_len;
>  	priv.response_len = 0;
> -	priv.buffer =  kzalloc(oat_data.buffer_len, GFP_KERNEL);
> +	priv.buffer = vzalloc(oat_data.buffer_len);
>  	if (!priv.buffer) {
>  		rc = -ENOMEM;
>  		goto out;
> @@ -4746,7 +4748,7 @@ int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
>  			rc = -EFAULT;
>  
>  out_free:
> -	kfree(priv.buffer);
> +	vfree(priv.buffer);
>  out:
>  	return rc;
>  }
>
Kleber Souza Sept. 28, 2018, 10:26 a.m. | #2
On 09/20/18 11:42, Joseph Salisbury wrote:
> From: Wenjia Zhang <wenjia@linux.ibm.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1793086
> 
> qeth_query_oat_command() currently allocates the kernel buffer for
> the SIOC_QETH_QUERY_OAT ioctl with kzalloc. So on systems with
> fragmented memory, large allocations may fail (eg. the qethqoat tool by
> default uses 132KB).
> 
> Solve this issue by using vzalloc, backing the allocation with
> non-contiguous memory.
> 
> Signed-off-by: Wenjia Zhang <wenjia@linux.ibm.com>
> Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
> Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> (backported from commit aec45e857c5538664edb76a60dd452e3265f37d1)
> Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

> ---
>  drivers/s390/net/qeth_core_main.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> index 40284b4..f0a34a2 100644
> --- a/drivers/s390/net/qeth_core_main.c
> +++ b/drivers/s390/net/qeth_core_main.c
> @@ -19,6 +19,8 @@
>  #include <linux/mii.h>
>  #include <linux/kthread.h>
>  #include <linux/slab.h>
> +#include <linux/vmalloc.h>
> +
>  #include <net/iucv/af_iucv.h>
>  #include <net/dsfield.h>
>  
> @@ -4705,7 +4707,7 @@ int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
>  
>  	priv.buffer_len = oat_data.buffer_len;
>  	priv.response_len = 0;
> -	priv.buffer =  kzalloc(oat_data.buffer_len, GFP_KERNEL);
> +	priv.buffer = vzalloc(oat_data.buffer_len);
>  	if (!priv.buffer) {
>  		rc = -ENOMEM;
>  		goto out;
> @@ -4746,7 +4748,7 @@ int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
>  			rc = -EFAULT;
>  
>  out_free:
> -	kfree(priv.buffer);
> +	vfree(priv.buffer);
>  out:
>  	return rc;
>  }
>

Patch

diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 40284b4..f0a34a2 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -19,6 +19,8 @@ 
 #include <linux/mii.h>
 #include <linux/kthread.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
+
 #include <net/iucv/af_iucv.h>
 #include <net/dsfield.h>
 
@@ -4705,7 +4707,7 @@  int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
 
 	priv.buffer_len = oat_data.buffer_len;
 	priv.response_len = 0;
-	priv.buffer =  kzalloc(oat_data.buffer_len, GFP_KERNEL);
+	priv.buffer = vzalloc(oat_data.buffer_len);
 	if (!priv.buffer) {
 		rc = -ENOMEM;
 		goto out;
@@ -4746,7 +4748,7 @@  int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
 			rc = -EFAULT;
 
 out_free:
-	kfree(priv.buffer);
+	vfree(priv.buffer);
 out:
 	return rc;
 }