All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc/genwqe: ensure zero initialization
@ 2016-09-12 18:09 Sebastian Ott
  2016-09-22 13:19 ` Frank Haverkamp
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Ott @ 2016-09-12 18:09 UTC (permalink / raw)
  To: Frank Haverkamp, Greg Kroah-Hartman; +Cc: linux-kernel


Genwqe uses dma_alloc_coherent and depends on zero initialized memory. On
one occasion it ueses an explicit memset on others it uses un-initialized
memory.

This bug was covered because some archs actually return zero initialized
memory when using dma_alloc_coherent but this is by no means guaranteed.
Simply switch to dma_zalloc_coherent.

Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
---
 drivers/misc/genwqe/card_ddcb.c  | 2 --
 drivers/misc/genwqe/card_utils.c | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/genwqe/card_ddcb.c b/drivers/misc/genwqe/card_ddcb.c
index 353ee0c..ddfeefe 100644
--- a/drivers/misc/genwqe/card_ddcb.c
+++ b/drivers/misc/genwqe/card_ddcb.c
@@ -1048,8 +1048,6 @@ static int setup_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue)
 			"[%s] **err: could not allocate DDCB **\n", __func__);
 		return -ENOMEM;
 	}
-	memset(queue->ddcb_vaddr, 0, queue_size);
-
 	queue->ddcb_req = kzalloc(sizeof(struct ddcb_requ *) *
 				  queue->ddcb_max, GFP_KERNEL);
 	if (!queue->ddcb_req) {
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 222367c..8a679ec 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -220,8 +220,8 @@ void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size,
 	if (get_order(size) > MAX_ORDER)
 		return NULL;
 
-	return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle,
-				  GFP_KERNEL);
+	return dma_zalloc_coherent(&cd->pci_dev->dev, size, dma_handle,
+				   GFP_KERNEL);
 }
 
 void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size,
-- 
2.5.5

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

* Re: [PATCH] misc/genwqe: ensure zero initialization
  2016-09-12 18:09 [PATCH] misc/genwqe: ensure zero initialization Sebastian Ott
@ 2016-09-22 13:19 ` Frank Haverkamp
  2016-09-23 10:06   ` Sebastian Ott
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Haverkamp @ 2016-09-22 13:19 UTC (permalink / raw)
  To: Sebastian Ott; +Cc: Greg Kroah-Hartman, linux-kernel

Hi Sebastian,

> On 12.09.2016, at 20:09, Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:
> 
> 
> Genwqe uses dma_alloc_coherent and depends on zero initialized memory. On
> one occasion it ueses an explicit memset on others it uses un-initialized
> memory.
> 
> This bug was covered because some archs actually return zero initialized
> memory when using dma_alloc_coherent but this is by no means guaranteed.
> Simply switch to dma_zalloc_coherent.

Thanks for figuring this out. I hope you found all spots where this misassumption is done.

> 
> Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
> ---
> drivers/misc/genwqe/card_ddcb.c  | 2 --
> drivers/misc/genwqe/card_utils.c | 4 ++--
> 2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/misc/genwqe/card_ddcb.c b/drivers/misc/genwqe/card_ddcb.c
> index 353ee0c..ddfeefe 100644
> --- a/drivers/misc/genwqe/card_ddcb.c
> +++ b/drivers/misc/genwqe/card_ddcb.c
> @@ -1048,8 +1048,6 @@ static int setup_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue)
> 			"[%s] **err: could not allocate DDCB **\n", __func__);
> 		return -ENOMEM;
> 	}
> -	memset(queue->ddcb_vaddr, 0, queue_size);
> -
> 	queue->ddcb_req = kzalloc(sizeof(struct ddcb_requ *) *
> 				  queue->ddcb_max, GFP_KERNEL);
> 	if (!queue->ddcb_req) {
> diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
> index 222367c..8a679ec 100644
> --- a/drivers/misc/genwqe/card_utils.c
> +++ b/drivers/misc/genwqe/card_utils.c
> @@ -220,8 +220,8 @@ void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size,
> 	if (get_order(size) > MAX_ORDER)
> 		return NULL;
> 
> -	return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle,
> -				  GFP_KERNEL);
> +	return dma_zalloc_coherent(&cd->pci_dev->dev, size, dma_handle,
> +				   GFP_KERNEL);
> }
> 
> void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size,
> -- 
> 2.5.5
> 
I think this should be fine.

Signed-off-by: Frank Haverkamp <haver@linux.vnet.ibm.com>

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

* Re: [PATCH] misc/genwqe: ensure zero initialization
  2016-09-22 13:19 ` Frank Haverkamp
@ 2016-09-23 10:06   ` Sebastian Ott
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Ott @ 2016-09-23 10:06 UTC (permalink / raw)
  To: Frank Haverkamp; +Cc: Greg Kroah-Hartman, linux-kernel

On Thu, 22 Sep 2016, Frank Haverkamp wrote:
> > On 12.09.2016, at 20:09, Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:
> > Genwqe uses dma_alloc_coherent and depends on zero initialized memory. On
> > one occasion it ueses an explicit memset on others it uses un-initialized
> > memory.
> > 
> > This bug was covered because some archs actually return zero initialized
> > memory when using dma_alloc_coherent but this is by no means guaranteed.
> > Simply switch to dma_zalloc_coherent.
> 
> Thanks for figuring this out. I hope you found all spots where this misassumption is done.

Genwqe only uses the dma alloc API via a wrapper
(__genwqe_alloc_consistent) and I changed it there.

> I think this should be fine.
> 
> Signed-off-by: Frank Haverkamp <haver@linux.vnet.ibm.com>

I changed that into an Ack. Seems more fitting here. Also I fixed a typo
in the patch description.

Greg, would you please take this one via your drivers/misc tree.

Thanks,
Sebastian

-------->8
misc/genwqe: ensure zero initialization

Genwqe uses dma_alloc_coherent and depends on zero initialized memory. On
one occasion it uses an explicit memset on others it uses un-initialized
memory.

This bug was covered because some archs actually return zero initialized
memory when using dma_alloc_coherent but this is by no means guaranteed.
Simply switch to dma_zalloc_coherent.

Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Acked-by: Frank Haverkamp <haver@linux.vnet.ibm.com>
---
 drivers/misc/genwqe/card_ddcb.c  | 2 --
 drivers/misc/genwqe/card_utils.c | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/genwqe/card_ddcb.c b/drivers/misc/genwqe/card_ddcb.c
index 353ee0c..ddfeefe 100644
--- a/drivers/misc/genwqe/card_ddcb.c
+++ b/drivers/misc/genwqe/card_ddcb.c
@@ -1048,8 +1048,6 @@ static int setup_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue)
 			"[%s] **err: could not allocate DDCB **\n", __func__);
 		return -ENOMEM;
 	}
-	memset(queue->ddcb_vaddr, 0, queue_size);
-
 	queue->ddcb_req = kzalloc(sizeof(struct ddcb_requ *) *
 				  queue->ddcb_max, GFP_KERNEL);
 	if (!queue->ddcb_req) {
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 222367c..8a679ec 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -220,8 +220,8 @@ void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size,
 	if (get_order(size) > MAX_ORDER)
 		return NULL;
 
-	return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle,
-				  GFP_KERNEL);
+	return dma_zalloc_coherent(&cd->pci_dev->dev, size, dma_handle,
+				   GFP_KERNEL);
 }
 
 void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size,
-- 
2.5.5

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

end of thread, other threads:[~2016-09-23 10:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12 18:09 [PATCH] misc/genwqe: ensure zero initialization Sebastian Ott
2016-09-22 13:19 ` Frank Haverkamp
2016-09-23 10:06   ` Sebastian Ott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.