public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pci-dma: Fix x86 dma_alloc_coherent to fully clear all pages returned
@ 2015-01-30 19:54 Tim Chen
  2015-01-30 19:58 ` Greg KH
  2015-01-30 21:03 ` Sergei Shtylyov
  0 siblings, 2 replies; 20+ messages in thread
From: Tim Chen @ 2015-01-30 19:54 UTC (permalink / raw)
  To: H. Peter Anvin, Akinobu Mita, Mathias Nyman
  Cc: Andi Kleen, Ingo Molnar, Andrew Morton, Marek Szyprowski,
	Thomas Gleixner, linux-kernel, x86, linux-usb


Commit d92ef66c4f8f ("x86: make dma_alloc_coherent() return zeroed memory
if CMA is enabled") changed the dma_alloc_coherent page clearance from
using an __GFP_ZERO in page allocation to not setting the flag but doing
an explicit memory clear at the end.

However the memory clear only covered the memory size that
was requested, but may not be up to the full extent of the
last page, if the total pages returned exceed the
memory size requested.  This behavior has caused problem with XHCI
and caused it to hang and froze usb:

kernel: xhci_hcd 0000:00:14.0: Stopped the command ring failed, maybe the host is dead
kernel: xhci_hcd 0000:00:14.0: Abort command ring failed
kernel: xhci_hcd 0000:00:14.0: HC died; cleaning up
kernel: xhci_hcd 0000:00:14.0: Error while assigning device slot ID
kernel: xhci_hcd 0000:00:14.0: Max number of devices this xHCI host supports is 64.

Other drivers may have similar issue if it assumes that the pages
allocated are completely zeroed.

This patch ensures that the pages returned are fully cleared.

Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
 arch/x86/kernel/pci-dma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a25e202..534470f 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -125,6 +125,8 @@ again:
 
 		return NULL;
 	}
+	/* round up to full page size */
+	size = (((size-1) >> PAGE_SHIFT) + 1) * PAGE_SIZE;
 	memset(page_address(page), 0, size);
 	*dma_addr = addr;
 	return page_address(page);
-- 
1.9.3



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

end of thread, other threads:[~2015-02-18 23:59 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-30 19:54 [PATCH] pci-dma: Fix x86 dma_alloc_coherent to fully clear all pages returned Tim Chen
2015-01-30 19:58 ` Greg KH
2015-01-30 22:01   ` Tim Chen
2015-01-30 22:07     ` Greg KH
2015-01-30 22:16       ` Tim Chen
2015-01-30 22:39       ` Andi Kleen
2015-01-31 17:14         ` Alan Stern
2015-01-30 21:03 ` Sergei Shtylyov
2015-01-30 21:54   ` Tim Chen
2015-02-02 14:02     ` Jiri Slaby
2015-02-02 16:39       ` Sergei Shtylyov
2015-02-04 18:30         ` Tim Chen
2015-02-18 19:40           ` Tim Chen
2015-02-18 19:53             ` Alan Stern
2015-02-18 20:19               ` Tim Chen
2015-02-18 20:36                 ` Greg Kroah-Hartman
2015-02-18 20:39                 ` Andi Kleen
2015-02-18 21:15                   ` Alan Stern
2015-02-18 20:45                 ` Alan Stern
2015-02-18 23:59                   ` Tim Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox