Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3414101imj; Tue, 19 Feb 2019 03:09:34 -0800 (PST) X-Google-Smtp-Source: AHgI3Iak3I0CASM0hI51I7cH19TkwDbrncezBkvhuYEl9pZ+epEgtMl3dXz4XJA/wAGs+V35JcNa X-Received: by 2002:a17:902:9885:: with SMTP id s5mr30772554plp.52.1550574574008; Tue, 19 Feb 2019 03:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550574573; cv=none; d=google.com; s=arc-20160816; b=h1wX4qjRV7PPPJHyiCDNcw+4OizwHH2GYA+sQzQw1sgx7e1M5s+28ffElop5pDRFEt xRg/Mt02Ox1zBYGUlZOPtVA9dr1+JnEgSVKMTANw9/7ypGHSCHvKKktUH9S0PAEElxZA 45011bE9iTv+Gvfz0YhWVR4tcuOarG7wUEHTZHYNiPdB8Vi9sRqjrbyl9k+NYEG2tZX3 RAVrOcUHcsGWk35bKf4R9ZFYI8OIwS4Sb1m3AKE22fy1oHvsUjdc5TQJtgRDMAMa56kL lPkLwu4dOsXETTdytYA91IeznV/35y0Qt5cza8ZWt2D/DqgFOigQ755zmbmKNmuZFtnt BSvg== 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=fUf0lQHShoCzKoTt0wYqxIJupMrn+hQ7e35OiTSVsBE=; b=KeQuZzPY79u3yJQDVP5MeBtNF/Rm+cKaqOb8b6WG8Ahrknz+ZKM0KaNM/Wy3nd9dds iKwhiPopT507DMF+Xw9St+9oT2iab+E3m0IxlPEXZEr5zOBEOZQDPZJ+Q1kzjtAPJlqq 5M/zMZwlo9bE4oTuARc6uMIhr/mc3CKe0mzWRcxFCCjc8sVMCrqrS9PyRDG71t9m0JAe LhQj7FefbCeQJScqObMbic3x1CZG1m41TVklsJd5i0kXwsI/VA8xuGKAwFuJwkltmq5v +w6RFjmpa4tqEDRjgA3cyG/N+OWxljMYXZG6hg/yGDdVwEYDuyTaud903iiQXwfhGhHa APIQ== 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 e189si15957646pfc.156.2019.02.19.03.09.18; Tue, 19 Feb 2019 03:09:33 -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 S1727233AbfBSLI5 (ORCPT + 99 others); Tue, 19 Feb 2019 06:08:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44036 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbfBSLI5 (ORCPT ); Tue, 19 Feb 2019 06:08:57 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2023AD885; Tue, 19 Feb 2019 11:08:56 +0000 (UTC) Received: from localhost (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18DFB60BE8; Tue, 19 Feb 2019 11:08:53 +0000 (UTC) Date: Tue, 19 Feb 2019 12:08:52 +0100 From: Stanislaw Gruszka To: Robin Murphy Cc: Lorenzo Bianconi , Samuel Sieb , linux-wireless , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Rosen Penev , Alexander Duyck Subject: Re: MT76x2U crashes XHCI driver on AMD Ryzen system Message-ID: <20190219110851.GA23223@redhat.com> References: <83A1D243-9073-48D1-9F26-5A2581DCB829@gmail.com> <1547404075.1582.0@smtp.gmail.com> <20190114091841.GA23045@localhost.localdomain> <20190115090400.GA2267@localhost.localdomain> <20190218143742.GA11872@redhat.com> <2cc5674a-a3a0-d8fe-65f5-4357da9b85d3@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2cc5674a-a3a0-d8fe-65f5-4357da9b85d3@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Feb 2019 11:08:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 18, 2019 at 05:01:59PM +0000, Robin Murphy wrote: > On 18/02/2019 14:37, Stanislaw Gruszka wrote: > [...] > >Another issue is that dma_map_sg() & dma_map_page() may require some > >constraints. I'm not sure about that and I want to clarify that with > >CCed mm maintainers. I think DMA drivers may expect sg->offset < PAGE_SIZE > >for both dma_map_sg() and dma_map_page(). Additionally dma_map_page() > >maight expect that offset & length specify buffer within one page. > > Luckily, this came up a while back[1] and we seemed to reach a > consensus that sg->offset >= PAGE_SIZE for dma_map_sg() was weird > but valid. IIRC it was only the Intel IOMMU code which failed to > handle that case appropriately (and which I fixed) - the AMD IOMMU > code always looked like it should be OK, but I'm not sure I've ever > seen definitive test results (and I don't have hardware to do so > myself). Funny that we have problems on AMD IOMMU and not with Intel IOMMU. > For dma_map_page(), length >= PAGE_SIZE should be perfectly valid > and handled correctly. The offset >= PAGE_SIZE case is a bit harder > to justify, but at the same time has less scope for the DMA API > backend to get it wrong, so either way is likely to be OK in > practice (in particular the AMD IOMMU code looks like it won't have > a problem, since its map_page() implementation converts page and > offset to a plain physical address before doing anything else). Thanks for clarify this. So my patch which do: - page = virt_to_head_page(data); + page = virt_to_page(data); offset = data - page_address(page); sg_set_page(&urb->sg[i], page, sglen, offset); should not be necessary as IOMMU driver do exactly the same internally. Are there any alignment requirement for offset for dma_map_{page,sg} ? It will work with let say sg->offset=113 or we have make sure it is aligned to some boundary. If so, what boundary ? Stanislaw