From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] swiotlb: Fix unexpected swiotlb_alloc_coherent() failures Date: Tue, 10 Apr 2018 19:07:46 +0200 Message-ID: References: <20180410170513.22834-1-tiwai@suse.de> <20180410170615.GA27589@lst.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20180410170615.GA27589-jcswGhMUV9g@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Christoph Hellwig Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Christian =?UTF-8?B?S8O2bmln?= , Konrad Rzeszutek Wilk List-Id: iommu@lists.linux-foundation.org On Tue, 10 Apr 2018 19:06:15 +0200, Christoph Hellwig wrote: > > On Tue, Apr 10, 2018 at 07:05:13PM +0200, Takashi Iwai wrote: > > The code refactoring by commit 0176adb00406 ("swiotlb: refactor > > coherent buffer allocation") made swiotlb_alloc_buffer() almost always > > failing due to a thinko: namely, the function evaluates the > > dma_coherent_ok() call incorrectly and dealing as if it's invalid. > > This ends up with weird errors like iwlwifi probe failure or amdgpu > > screen flickering. > > > > This patch corrects the logic error. > > This looks ok, although even hitting this code is a bad sign. Do you > know why the previous dma_direct_alloc didn't succeed? That I have no idea, sorry. I just figured out the regression just from the dmesg output of 4.16 kernel in bugzilla reports. Could you take a look at the bugzilla reports there? thanks, Takashi > > Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1088658 > > Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1088902 > > Fixes: 0176adb00406 ("swiotlb: refactor coherent buffer allocation") > > Cc: # v4.16+ > > Signed-off-by: Takashi Iwai > > --- > > lib/swiotlb.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/swiotlb.c b/lib/swiotlb.c > > index 47aeb04c1997..de7cc540450f 100644 > > --- a/lib/swiotlb.c > > +++ b/lib/swiotlb.c > > @@ -719,7 +719,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle, > > goto out_warn; > > > > *dma_handle = __phys_to_dma(dev, phys_addr); > > - if (dma_coherent_ok(dev, *dma_handle, size)) > > + if (!dma_coherent_ok(dev, *dma_handle, size)) > > goto out_unmap; > > > > memset(phys_to_virt(phys_addr), 0, size); > > -- > > 2.16.3 > ---end quoted text--- > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751966AbeDJRHt (ORCPT ); Tue, 10 Apr 2018 13:07:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:40833 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751367AbeDJRHs (ORCPT ); Tue, 10 Apr 2018 13:07:48 -0400 Date: Tue, 10 Apr 2018 19:07:46 +0200 Message-ID: From: Takashi Iwai To: Christoph Hellwig Cc: Christian =?UTF-8?B?S8O2bmln?= , Konrad Rzeszutek Wilk , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] swiotlb: Fix unexpected swiotlb_alloc_coherent() failures In-Reply-To: <20180410170615.GA27589@lst.de> References: <20180410170513.22834-1-tiwai@suse.de> <20180410170615.GA27589@lst.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 Apr 2018 19:06:15 +0200, Christoph Hellwig wrote: > > On Tue, Apr 10, 2018 at 07:05:13PM +0200, Takashi Iwai wrote: > > The code refactoring by commit 0176adb00406 ("swiotlb: refactor > > coherent buffer allocation") made swiotlb_alloc_buffer() almost always > > failing due to a thinko: namely, the function evaluates the > > dma_coherent_ok() call incorrectly and dealing as if it's invalid. > > This ends up with weird errors like iwlwifi probe failure or amdgpu > > screen flickering. > > > > This patch corrects the logic error. > > This looks ok, although even hitting this code is a bad sign. Do you > know why the previous dma_direct_alloc didn't succeed? That I have no idea, sorry. I just figured out the regression just from the dmesg output of 4.16 kernel in bugzilla reports. Could you take a look at the bugzilla reports there? thanks, Takashi > > Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1088658 > > Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1088902 > > Fixes: 0176adb00406 ("swiotlb: refactor coherent buffer allocation") > > Cc: # v4.16+ > > Signed-off-by: Takashi Iwai > > --- > > lib/swiotlb.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/swiotlb.c b/lib/swiotlb.c > > index 47aeb04c1997..de7cc540450f 100644 > > --- a/lib/swiotlb.c > > +++ b/lib/swiotlb.c > > @@ -719,7 +719,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle, > > goto out_warn; > > > > *dma_handle = __phys_to_dma(dev, phys_addr); > > - if (dma_coherent_ok(dev, *dma_handle, size)) > > + if (!dma_coherent_ok(dev, *dma_handle, size)) > > goto out_unmap; > > > > memset(phys_to_virt(phys_addr), 0, size); > > -- > > 2.16.3 > ---end quoted text--- >