All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: Tim Chen <tim.c.chen@linux.intel.com>,
	Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Akinobu Mita <akinobu.mita@gmail.com>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Andi Kleen <andi@firstfloor.org>, Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	linux-usb@vger.kernel.org, stable <stable@vger.kernel.org>
Subject: Re: [PATCH] pci-dma: Fix x86 dma_alloc_coherent to fully clear all pages returned
Date: Mon, 02 Feb 2015 15:02:28 +0100	[thread overview]
Message-ID: <54CF8374.80704@suse.cz> (raw)
In-Reply-To: <1422654849.9530.8.camel@schen9-desk2.jf.intel.com>

On 01/30/2015, 10:54 PM, Tim Chen wrote:
> On Sat, 2015-01-31 at 00:03 +0300, Sergei Shtylyov wrote:
>> On 01/30/2015 10:54 PM, Tim Chen wrote:
> 
>>>
>>>   		return NULL;
>>>   	}
>>> +	/* round up to full page size */
>>> +	size = (((size-1) >> PAGE_SHIFT) + 1) * PAGE_SIZE;
>>
>>     This is quite suboptimal formula, we can do without shifts and 
>> multiplications (hopefully, still converted to shifts by gcc):
>>
>> 	size = (size + ~PAGE_MASK) & PAGE_MASK;
> 
> Agree.  I've updated patch below
> 
> Thanks.
> 
> Tim
> 
> --->8---
> 
> From: Tim Chen <tim.c.chen@linux.intel.com>
> Subject: [PATCH] pci-dma: Fix x86 dma_alloc_coherent to fully clear all pages returned
> 
> 
> 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:
> 
> 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>
> Cc: <stable@vger.kernel.org> # 3.16+
> 
> ---
>  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..e9d8dee 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 + ~PAGE_MASK) & PAGE_MASK;

Hi, is this an open-coded version of PAGE_ALIGN?

>  	memset(page_address(page), 0, size);
>  	*dma_addr = addr;
>  	return page_address(page);
> 


-- 
js
suse labs

  reply	other threads:[~2015-02-02 14:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54CF8374.80704@suse.cz \
    --to=jslaby@suse.cz \
    --cc=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mingo@elte.hu \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.