From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5180CC3A59F for ; Sat, 17 Aug 2019 07:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2369C21744 for ; Sat, 17 Aug 2019 07:20:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=tcd-ie.20150623.gappssmtp.com header.i=@tcd-ie.20150623.gappssmtp.com header.b="iuaKaoZk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726120AbfHQHUH (ORCPT ); Sat, 17 Aug 2019 03:20:07 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:34108 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbfHQHUH (ORCPT ); Sat, 17 Aug 2019 03:20:07 -0400 Received: by mail-io1-f68.google.com with SMTP id s21so10795571ioa.1 for ; Sat, 17 Aug 2019 00:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3gnS0PBpeFma+nR0/93xLJSxk0RZjywB6TYlsGP6x54=; b=iuaKaoZkqD3jS65GkFRQXUesr+iHDQw7qZXVp3ez2fmCt49N//RMqfebteueaUoH+p 97zi714OqDL373xaRAuH3dX8FyF/Ggim5AtCytyMJbs8OW1HRJxUvrBWziOojWSjQyyv N8V4gNN86Fa2SkaukvBfzPcjbRwF05BDdxAP0vXBWYtOD0SIpiwB1xkPByOxsAsX+9h1 04BQeNXJdFWKxBekEW+jFClh2sgwRA/Wjk7i3VyRYr7XND2lelrmJe56TnoW4qN1h7sB KsNL/98KtTPtlpVSTykKF2Hed4ptAKREhBRKgytLAlnBDShNx9anmljZsQvOgXkrjk/s f08A== 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; bh=3gnS0PBpeFma+nR0/93xLJSxk0RZjywB6TYlsGP6x54=; b=K2e6xbem/TxjmSaP8CLR3klHcOzLY//k48L5eF+y6gT6uAfzWceBZbjS8zxjfn2gD+ oS4sRfbYEzIhsDTA6/L7V7izaKHhraTl+nInVB8fu3zJlIFzoPfeLWZuEDEbEfCQiZQu 4avxssZOK5y5Bg1YQSmQ2DzHgjGtlYKytHEApVZBvH0EgTcOZFbnjt79KHtJ0MA75I1f Mf717duBhh61OYRymy8G2Os9TBqHdxAhfZ4MyJwfIvgiEo9APkSjEaBK6nnfa6ds56pR 2b1xNQmPaBXsZzDOwD2vW1kAALqmBCymciEtwmdV0WSQcwYxUZgM3k0qUeIpA6WYIEBR 3AmQ== X-Gm-Message-State: APjAAAWqXkAGe70TcJEi/MsGA6UcpGAQJmNduS8k8hSSRj0phYy0xsqc 5bmPl5vie3QgfxEdYfanMV9ij/VnbYsCSOGaz0HqZg== X-Google-Smtp-Source: APXvYqzi3uE7FL/BNaGBwf9NcctQEJa1uqSCgIDdI7X8T4a271+rNn6qVr2H/9WkS8ckRMiROhEplUC0qpc0vOhpjPg= X-Received: by 2002:a02:a18e:: with SMTP id n14mr15977616jah.84.1566026405753; Sat, 17 Aug 2019 00:20:05 -0700 (PDT) MIME-Version: 1.0 References: <20190815110944.3579-1-murphyt7@tcd.ie> <20190817033914.4812-1-hdanton@sina.com> In-Reply-To: <20190817033914.4812-1-hdanton@sina.com> From: Tom Murphy Date: Sat, 17 Aug 2019 08:19:33 +0100 Message-ID: Subject: Re: [PATCH V5 3/5] iommu/dma-iommu: Handle deferred devices To: Hillf Danton Cc: Joerg Roedel , iommu@lists.linux-foundation.org, Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Andy Gross , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org Content-Type: text/plain; charset="UTF-8" Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Sat, 17 Aug 2019 at 04:39, Hillf Danton wrote: > > > On Thu, 15 Aug 2019 12:09:41 +0100 Tom Murphy wrote: > > > > Handle devices which defer their attach to the iommu in the dma-iommu api > > > > Signed-off-by: Tom Murphy > > --- > > drivers/iommu/dma-iommu.c | 27 ++++++++++++++++++++++++++- > > 1 file changed, 26 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > > index 2712fbc68b28..906b7fa14d3c 100644 > > --- a/drivers/iommu/dma-iommu.c > > +++ b/drivers/iommu/dma-iommu.c > > @@ -22,6 +22,7 @@ > > #include > > #include > > #include > > +#include > > > > struct iommu_dma_msi_page { > > struct list_head list; > > @@ -351,6 +352,21 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, > > return iova_reserve_iommu_regions(dev, domain); > > } > > > > +static int handle_deferred_device(struct device *dev, > > + struct iommu_domain *domain) > > +{ > > + const struct iommu_ops *ops = domain->ops; > > + > > + if (!is_kdump_kernel()) > > + return 0; > > + > > + if (unlikely(ops->is_attach_deferred && > > + ops->is_attach_deferred(domain, dev))) > > + return iommu_attach_device(domain, dev); > > + > > + return 0; > > +} > > + > > /** > > * dma_info_to_prot - Translate DMA API directions and attributes to IOMMU API > > * page flags. > > @@ -463,6 +479,9 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, > > size_t iova_off = iova_offset(iovad, phys); > > dma_addr_t iova; > > > > + if (unlikely(handle_deferred_device(dev, domain))) > > + return DMA_MAPPING_ERROR; > > + > > size = iova_align(iovad, size + iova_off); > > > > iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); > > iommu_map_atomic() is applied to __iommu_dma_map() in 2/5. > Is it an atomic context currently given the mutex_lock() in > iommu_attach_device()? I don't see your point here. __iommu_dma_map isn't called from iommu_attach_device, why would we care about a mutex in iommu_attach_device? __iommu_dma_map can be called from an atomic context (it isn't always but it does happen). __iommu_dma_map is called by iommu_dma_alloc which implements the iommu_dma_ops::alloc function which by design needs to be callable from an atomic context. Does that answer your question? >