Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3821544pxv; Mon, 26 Jul 2021 13:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUmg9cGl93iRd0rwdzMyePAsyAqw+/s165dFb+u4kQ0BnjMF6icuNYfswhGli5ft1psAFa X-Received: by 2002:a05:6e02:12e1:: with SMTP id l1mr13920623iln.0.1627329912273; Mon, 26 Jul 2021 13:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627329912; cv=none; d=google.com; s=arc-20160816; b=dKHUSTQnXP2cOVoO+HCBzpDlPDlfz8GoCSP39HxnH6GUCIJsva09vlrji8IC+vEIu1 JuFw6t/JTcStWMpvBGrqQgvRXVbuH2I/AVsHPUbMgF7OCJ36t7pJNSEfBcTuSDOKHz1U fEDrBzImkfHUlKcVAjsN68T3GiZFliRCRZy2oAn6r9jb9GG9jNt7HFzZASGjlcdqFr1s fIPOYU6eYvQSfP5UTjfuF2HindIe8BowalKG/EL+bojV8rW7tTuFDVo+R5mwewru0SwI BmYvs87oThyTaBNOMGIKMxLmFTqsvfcU+zHbEcvTYuZQNQEueH1ZX4fkMSy969OsgOmh wwcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=hkvmb7z1QlrX9irsxYTL7DRXEFJ20vvu42EiYAEffXA=; b=cgRDl91+Rorn+u+r6McbfTe63MThVKlV4ypm+USrJIRZzMHUI8taiIIWoGrNgiuQFg Udgsi+CXHpbeCpAb7EMXS30hR7X04kuTytqpg92gLDMT8mybhzcGph00RZpZUlMLKiMp xeZu11WD7l33J6I+sGhBnK4dyxREk2/mCXd0N4CIhPDtYd1tlcDX45K4O/rGSpXEjzkQ NuopH92UZKaI+i94P2xqRMeHsFyZxXLHngwnqmSiKsUci3+GfhfdPLf4jf3VQP7Da2Xb 8O/Lj9SyrTjzHcIrIZFK/ppI/ez/UZmAXZOzmNRnlHOgkvnoezlUPr2pfY5sbeCeAa5R Ka3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItiA4mf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si793040ilk.74.2021.07.26.13.05.00; Mon, 26 Jul 2021 13:05:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItiA4mf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231857AbhGZTX2 (ORCPT + 99 others); Mon, 26 Jul 2021 15:23:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:41510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbhGZTX1 (ORCPT ); Mon, 26 Jul 2021 15:23:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA84E60F6E; Mon, 26 Jul 2021 20:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627329836; bh=Wz9/1UR+NNm1PWmlemY6+S+vta0TSAKrTaG4D9BMtVU=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=ItiA4mf5ZlUSB7NEffLS/Ciydpncc8l8pOdGbITmrzKgIJkUUPs7R7WnKNHCWStGr UMVpaQdvW8JE+VQFNBHDaQsB8mcFjo+olM/SYE0Nw3dBEBTSoPiE/kuP+51PJDAHbc 9LyxycyrPeKTiTHLQZXVMrTpXqm2vuSnU74u++9SnVjKnGi1ovv/O4P1G3bNRLhGZN xo9loHiTbvMdHtlivPsvwg5TqAsSJDlabH6OVICoR3gNqsT8O9DuLsOB+BvkpnwtBK 1uYAZioNvM3X2whk38QJIYZ8yKznb03/U39coBfHVAAtVt3g5neSe41arfYpzXCh+q 3xQ0VIy+aUH4g== Date: Mon, 26 Jul 2021 13:03:55 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Boris Ostrovsky cc: Linus Torvalds , Christoph Hellwig , Linux Kernel Mailing List , iommu , Stefano Stabellini , rm.skakun@gmail.com Subject: Re: [GIT PULL] dma-mapping fix for Linux 5.14 In-Reply-To: <957943ce-c50e-1560-6f1b-aea0a1c9a114@oracle.com> Message-ID: References: <957943ce-c50e-1560-6f1b-aea0a1c9a114@oracle.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 26 Jul 2021, Boris Ostrovsky wrote: > On 7/25/21 12:50 PM, Linus Torvalds wrote: > > On Sat, Jul 24, 2021 at 11:03 PM Christoph Hellwig wrote: > > > >> - handle vmalloc addresses in dma_common_{mmap,get_sgtable} > >> (Roman Skakun) > > I've pulled this, but my reaction is that we've tried to avoid this in > > the past. Why is Xen using vmalloc'ed addresses and passing those in > > to the dma mapping routines? > > > > It *smells* to me like a Xen-swiotlb bug, and it would have been > > better to try to fix it there. Was that just too painful? > > > Stefano will probably know better but this appears to have something to do with how Pi (and possibly more ARM systems?) manage DMA memory: https://lore.kernel.org/xen-devel/CADz_WD5Ln7Pe1WAFp73d2Mz9wxspzTE3WgAJusp5S8LX4=83Bw@mail.gmail.com/. The original issue was found on the Raspberry Pi 4, and the fix was in swiotlb-xen.c, commit 8b1e868f6. More recently, Roman realized that dma_common_mmap might also end up calling virt_to_page on a vmalloc address. This is the fix for that. Why is Xen using vmalloc'ed addresses with dma routines at all? Xen is actually just calling the regular dma_direct_alloc to allocate pages (xen_swiotlb_alloc_coherent -> xen_alloc_coherent_pages -> dma_direct_alloc). dma_direct_alloc is the generic implementation. Back when the original issue was found, dma_direct_alloc returned a vmalloc address on RPi4. The original analysis was "xen_alloc_coherent_pages() eventually calls arch_dma_alloc() in remap.c which successfully allocates pages from atomic pool." See https://marc.info/?l=xen-devel&m=158878173207775. I don't know on which platform Roman Skakun (CC'ed) found the problem. But if we look at arch/arm/mm/dma-mapping.c:__dma_alloc, one of the possible options is the "remap_allocator", which calls __alloc_remap_buffer, which calls dma_common_contiguous_remap, which calls vmap. So unfortunately it seems that on certain arch/platforms dma_alloc_coherent can return a vmap'ed address. So I would imagine this issue could also happen on native (without Xen), at least in theory.