Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5975261pxv; Thu, 29 Jul 2021 03:19:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQOBmBGug/dVeaNf86dt8TH2pPDhowQNQRItXyOrBcWCgoDWX0PRXAkxeEnltW4r7Xhp77 X-Received: by 2002:a17:906:c302:: with SMTP id s2mr3942828ejz.151.1627553961834; Thu, 29 Jul 2021 03:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627553961; cv=none; d=google.com; s=arc-20160816; b=UBEn1D+JCGVGsw/tSCqU0t3AmIaIJtjCYsPki22/GERVgHl/OZZhQGBPXkBbT2/CxX qhjgSJxQU8kE6hflrDDh20UmBnTRnNxdnj54oJefJ7+gWl/34atcekb0v1xud557U80K Cb6+Wd6Jq9bEqj49v8SAz4jvOHHkxPr3qRnOHfcB+ORmmPU7mSHEiJOPkxuK0AFOhjY6 SHFwDVz9bhMi12494p3Gx0YDHujm276WlfWDN1GfXh/E3Nj9OPbTCoer871aowBBi0/U bA8h5fKX+O0pHSeP0eSJhndjQNhrYWFwOI30lE8Z4CAz0ByBdXn8lBLpTdIGexeMvBdZ nZ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kXIpgpDKWbPbcNkG2dNNt5Cm/6h4seJQ12NmUxex3VI=; b=SEcslW0espL9dbvKjah7dOCN9EGX0nlLl+y2QabITNu4CfGNpFvaa1UnU4aIppO35h 5akrevB4tYm+OEALrYR+k/Od4F5bmkwIhcN1NYjT/reFxvwGHSr98xLDEWgQpkstjZHR /9/gzWsF1sevzsjq9N3deuPBuXBUZhliorh6X4cluwwiZRNNG2B80aFvZVCjMrm+vklF KjWNRH/LPaSavomXgvjtuFnTjywCjbIAh69jKTIhp2Ieb3FBZSSrvny9wA06IbakD3VB SP+VZaAAlniLRTMhLXztRFY4kW+xUKpvEBfHSj/5HO7CTCMlF15OvG2u1iTGHnF0P717 uFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ixDe9DEz; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo10si2517259ejb.582.2021.07.29.03.18.58; Thu, 29 Jul 2021 03:19:21 -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=@gmail.com header.s=20161025 header.b=ixDe9DEz; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235309AbhG2KR0 (ORCPT + 99 others); Thu, 29 Jul 2021 06:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235155AbhG2KRZ (ORCPT ); Thu, 29 Jul 2021 06:17:25 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0687C061757 for ; Thu, 29 Jul 2021 03:17:21 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id r17so10028661lfe.2 for ; Thu, 29 Jul 2021 03:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kXIpgpDKWbPbcNkG2dNNt5Cm/6h4seJQ12NmUxex3VI=; b=ixDe9DEzvJT3GNrG6sd8nZ0dMqhEBzRdvDa2qi1gcvZPMQuLiyUYGrBZkHMiYzDc4q MVK00Tch8pEyNp5CCkOL2juHmsHHMj/mGQ/r+yTIJy3ayEVmx9PrGDNjvybuMw6p0kAI KkALVoLLgisef8ftDy3kY+lF8dp4ec9xJs8ULTVhYu6kT93lxPnmH8kyRkqv0+b5CqxF Oll6V/zPYc2xFDbtBUsdC2cfW8Swe7F53sKGiESCTI+tgVnV3Ko3XTz6s6lbzEdCIfwN l3pxNMoUzl9ibAd9b7uxw5gc78FJK3uyfWVRMwaZS9VmWI8+x7cni/PHCcdvqmGE7B2M QpiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kXIpgpDKWbPbcNkG2dNNt5Cm/6h4seJQ12NmUxex3VI=; b=UHnkWnoUyO+5MPRMiUppjK/GXv71vmlN9XMODiIFrumPVHaRQTHDkOY1cNZt+LJAoL WrUNlMxh5yVG7X94EFJy8+yI5qO8NIHwKjpPrXO2Jzf5/e5wl6HGR9LSfuV9eeH17lFf 6UP/JXf1Q8FCkdJlyy8QdIxZB9H7hZSgxy2nwoaQxbEF1QwZvevLgILTuQIC/aG8DROM 5X+MRNcFUZqgXB3Q6NmytjnAVfsUJx90763LFRXnw9VSTOE6NRhD7hmA9QmLbC7vwj+E aZEXkaF3GNujTfxXQAZoaYX3daMhUi9o67mIvUJaH/09tFCmDU9EfegVvyPx2Scp/73z xVzQ== X-Gm-Message-State: AOAM5319yp44BMNU6jGFpp1aLbX708tQ9pnOmpdfek4isa/9y/Xv/YQx e24xlfMavPmiDrGAkqX2F/bPjUwd72LUeemlEVE= X-Received: by 2002:a05:6512:321c:: with SMTP id d28mr3190353lfe.203.1627553840300; Thu, 29 Jul 2021 03:17:20 -0700 (PDT) MIME-Version: 1.0 References: <957943ce-c50e-1560-6f1b-aea0a1c9a114@oracle.com> In-Reply-To: From: Roman Skakun Date: Thu, 29 Jul 2021 13:17:09 +0300 Message-ID: Subject: Re: [GIT PULL] dma-mapping fix for Linux 5.14 To: Stefano Stabellini Cc: Linus Torvalds , Christoph Hellwig , Linux Kernel Mailing List , iommu , Roman Skakun , Roman Skakun Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Stefano! > 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. Using Renesas R-car H3 platform. I have tested this case on 1:1 dom0 with < 4GB memory, but this case still exists. I'm still wondering why xen-swiotlb mapped vmalloc'ed addresses for low memory DMA addresses. =D0=BF=D0=BD, 26 =D0=B8=D1=8E=D0=BB. 2021 =D0=B3. =D0=B2 23:03, Stefano Sta= bellini : > > 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 i= n > > > 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= =3D83Bw@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=3Dxen-devel&m=3D158878173207775. > > > 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. --=20 Best Regards, Roman.