Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp567112img; Thu, 28 Feb 2019 04:25:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IbgwxH9fIMs4LBmYHGiRBq2A1Dm74UknQIjzhcnjzGVKEmhb9Zy4MR+Bdlkq7sxo1COyonF X-Received: by 2002:a17:902:bcc7:: with SMTP id o7mr7791806pls.89.1551356755154; Thu, 28 Feb 2019 04:25:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551356755; cv=none; d=google.com; s=arc-20160816; b=YCyd9rWHU2eZsmC5/UEARTiyGlqMk1T/1wRjglY3qnGHwO3O5yQeTxnI+29Ymh7FtX zvViWMncjK9joTNrnBDOBeenB6FQpfjtpbTvXFmjZTs0x1pq6pLYkfCdn1YGLGJi/IuS Wlz+C3TMp5KfF+YIIyJIPZKb2f5YKQ45lHJwWhfhsK++yWxbF3BU2fQt/D0GgpppjwMW c4gvelJUD431/cb5VrglnUxvBNSdJey1hv63ZbOmRrH2+EMYR/pvaYBnHE5hO3Yqk8+9 RclgB+7PmbHPSCiyKfx2sDmLCBB8GSiv4hJpvwyQwMwXHwlXyMAYfIomRFga76bqj4PU HKAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8blFJhscGLjXIJ28WQMBVLibTbfner+LVpKcUjdu66Y=; b=yqzrGj0ECFAacYXsLu4DLVdvlS9MfbpXBf5plTfRXgUYpDK0s3CMGmiScaov0Myq1G W5eOO/e3dKB0ATSZPfuGXxonu/jArFgArlraEi/WRmidwQO20zOL5nmynaG0ouPq2SPH vP6/9AknVtgwjdxZKiAU/KVAHX6UJ0z5nuzRagdG7hoivS2zbsFyJXOXdKlfUckCv9GV Zs8vMxK7wCnTAQHHZp/k0lNwsMD0tNiGSD+zKJwzBp501wkRBU4Ru27IaD3uACbz/kHU H+5cFIevvQ08+otW6MR2N8UU1cciH8gh9clvB0Lm+t4u4jN9Ks5BDS3gqrNlMGADkRwW b74w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l2si17828907pfc.287.2019.02.28.04.25.38; Thu, 28 Feb 2019 04:25:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731201AbfB1MTy (ORCPT + 99 others); Thu, 28 Feb 2019 07:19:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35896 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfB1MTx (ORCPT ); Thu, 28 Feb 2019 07:19:53 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46C4112E517; Thu, 28 Feb 2019 12:19:53 +0000 (UTC) Received: from localhost (unknown [10.43.2.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id BECC618379; Thu, 28 Feb 2019 12:19:50 +0000 (UTC) Date: Thu, 28 Feb 2019 13:19:48 +0100 From: Stanislaw Gruszka To: Joerg Roedel Cc: Lorenzo Bianconi , Rosen Penev , linux-wireless , Samuel Sieb , Alexander Duyck , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: MT76x2U crashes XHCI driver on AMD Ryzen system Message-ID: <20190228121948.GD6072@redhat.com> References: <20190114091841.GA23045@localhost.localdomain> <20190115090400.GA2267@localhost.localdomain> <20190218143742.GA11872@redhat.com> <20190226100535.GA20740@8bytes.org> <20190226103450.GA2989@redhat.com> <20190226104413.GH20740@8bytes.org> <20190226112407.GB2989@redhat.com> <20190228090411.GA24938@redhat.com> <20190228104223.GA2749@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190228104223.GA2749@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 28 Feb 2019 12:19:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 28, 2019 at 11:42:24AM +0100, Stanislaw Gruszka wrote: > On Thu, Feb 28, 2019 at 10:04:12AM +0100, Stanislaw Gruszka wrote: > > On Tue, Feb 26, 2019 at 12:24:08PM +0100, Stanislaw Gruszka wrote: > > > On Tue, Feb 26, 2019 at 11:44:13AM +0100, Joerg Roedel wrote: > > > > On Tue, Feb 26, 2019 at 11:34:51AM +0100, Stanislaw Gruszka wrote: > > > > > On Tue, Feb 26, 2019 at 11:05:36AM +0100, Joerg Roedel wrote: > > > > > If sg->offset > PAGE_SIZE is fine then most likely we have problem with > > > > > alignment. > > > > > > > > The map_sg implementation in the AMD IOMMU driver uses sg_phys() which > > > > handles the sg->page + sg->offset calculation fine. > > > > > > > > > Note hat issue is with dma_map_sg(), switching to dma_map_single() > > > > > by using urb->transfer_buffer instead of urb->sg make things work > > > > > on AMD IOMMU. > > > > > > > > On the other hand this points to a bug in the driver, I'll look further > > > > if I can spot something there. > > > > > > I think so too. And I have done some changes that avoid strange allocation > > > scheme and use usb synchronous messages instead of allocating buffers > > > with unaligned sizes. However things work ok on Intel IOMMU and > > > there is no documentation what are dma_map_sg() requirement versus > > > dma_map_single() which works. I think there are some unwritten > > > requirements and things can work on some platforms and fails on others > > > (different IOMMUs, no-IOMMU on some ARCHes) > > > > For the record: we have another bug report with this issue: > > https://bugzilla.kernel.org/show_bug.cgi?id=202673 > > > > I provided there patch that change alignment for page_frag_alloc() and > > it did not fixed the problem. So this is not alignment issue. > > Now I think it could be page->refcount issue ... > > I looked at the map_sg() in amd_iommu.c code and one line looks suspicious > to me, seems we can use not correctly initialized s->dma_address (should be 0, > but I think can be non-zero if SG was reused). The code also seems do > not do correct thing if there is more than one SG with multiple pages > on individual segments. Something like in below patch seems to be more > appropriate to me (not tested nor compiled). Nevermind, the patch is wrong, s->dma_address is initalized in sg_num_pages(). Stanislaw