From patchwork Mon May 6 18:52:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10931833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAFC713AD for ; Mon, 6 May 2019 18:53:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC7362881C for ; Mon, 6 May 2019 18:53:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D03AB2882C; Mon, 6 May 2019 18:53:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 741302881C for ; Mon, 6 May 2019 18:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4d68tmh9Nd4H+1daqzHRFuIfRpH5c1nnziro32JkDxM=; b=fvHw7K7pmJQtArVBHJWRMDd30E svp+iA3P8BHzoPPhUZULF2pVlodYYDcie257DIKGwC7qiYitknTjg34xRnRuozNk1p4SUtzfXlzju hUl3NqQ+0+DK4+ElVf+sSIDe9VWRrAlKEFX73TP80VQunCzeryltvuy4Vr6S1YQDE0/rJ5DaSdVi7 esn80O0vCfR/D0WrTgGjggag5i8QMVeyvy+69dyIW6drtYkBYm1GxfRUdCfLEE7F2ctOSdwtqcZvc pBI4LJBR/1jqCnmM8HARJEt6SjqlsI+9YUUCaIcruG2CGB1WLQiey76u7rrF5Sgg+8W/355UoSGEH i+07eq0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNijz-0005LG-G0; Mon, 06 May 2019 18:53:31 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNijW-0004i8-PC for linux-arm-kernel@lists.infradead.org; Mon, 06 May 2019 18:53:14 +0000 Received: by mail-ed1-x542.google.com with SMTP id e24so16324571edq.6 for ; Mon, 06 May 2019 11:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ybQIpJHlWaFs/zU9bGDFvVwxe0GuybJKNVxIUx2IidQ=; b=JFf67WwYhFLm0sTPsKCR4MLJ0rPWCvtSCjSSI4/WRj/g9uerAOoO3YHngKXqV5XRDA BsbOZnljWpcXPUXX/jdN2xuHesc6zNY0itBP+Fnyyrju3F9JKQ0g/s7Ckwv7CC2oFl1z wI0b3z3GIBx6hJ/4s6XRLBTMGNolbKMrJ0Vb3tg01k29lvgmr+SxiJ/TBbe4Qq9DsrKF qQiEaIlqgSuvkr/cE/rrrDO7H+Q6t/rD5v/qYXgdM3iw1x5tIh+qOQo1qf2dmaa/9AK4 IrFWN83fIgwTfxZdeZHp0uHV/tDIwiIQrAP0r7XVNfccsjI2qQbvZKc+B08HsaVF6EPb B2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ybQIpJHlWaFs/zU9bGDFvVwxe0GuybJKNVxIUx2IidQ=; b=FZHZhdDTzxkS4azdwK3Y17Q9WisIzyNlWWKMqm+e+vV7ewSbG4MmeZTPv1isKYfz/V 2a6J6R2iVPtvHYNAE5RlYtPBE3qX6LTbkjMTwfb9uIthaqDeGG6XdSKJyg1Xo0IJzO0g zR58RCCu3thsBnb9bGyrPifKopgyWgs+yE3D6v+Vz/5OtBwyjSqc8Qx3XiqmhBP1lbst m5tRI7m41roE+xEbtsblPPI8BUP2QqCYPhg1vGJZ+8IzMdAmLeVJ4xyl1ON5LdOr5T0L Kqpd3VJjpcQ5TvO+3b7t613rpZxeuBcsNvBA+6T+Lz8FQtiYwp6RYDeshzSewph3yUXj dZJg== X-Gm-Message-State: APjAAAXNdgoQQXG9k3sSsVPNjIN3U/lmj3Nnptaksbv0w/h2sdw8eDUf TdPMKMagU9sUg8kOC1mgon7CNg== X-Google-Smtp-Source: APXvYqy6IgposVXar6I91KdFzVPePJ0WSHgH7cCqvKmX63+rZDsgMJaDXv+5YPJR8LEJQrNd+kLsNA== X-Received: by 2002:a17:907:1059:: with SMTP id oy25mr8017394ejb.118.1557168781318; Mon, 06 May 2019 11:53:01 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:a0:bc00:d9d9:922a:828d:a50e]) by smtp.gmail.com with ESMTPSA id e35sm3361412eda.2.2019.05.06.11.52.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 11:53:00 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH v3 2/4] iommu/dma-iommu: Handle deferred devices Date: Mon, 6 May 2019 19:52:04 +0100 Message-Id: <20190506185207.31069-3-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506185207.31069-1-tmurphy@arista.com> References: <20190506185207.31069-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_115303_289555_67869020 X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Will Deacon , David Brown , Thierry Reding , Marek Szyprowski , linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Joerg Roedel , Krzysztof Kozlowski , Jonathan Hunter , linux-rockchip@lists.infradead.org, Kukjin Kim , Gerald Schaefer , Andy Gross , linux-tegra@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org, Tom Murphy , Robin Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , David Woodhouse MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Handle devices which defer their attach to the iommu in the dma-iommu api Signed-off-by: Tom Murphy Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7a96c2c8f56b..b383498e2dc3 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; @@ -322,6 +323,22 @@ 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; + + if (!is_kdump_kernel()) + return 0; + + domain = iommu_get_domain_for_dev(dev); + ops = domain->ops; + if (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. @@ -835,7 +852,10 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, bool coherent = dev_is_dma_coherent(dev); dma_addr_t dma_handle; - dma_handle =__iommu_dma_map(dev, phys, size, + if (unlikely(handle_deferred_device(dev))) + return DMA_MAPPING_ERROR; + + dma_handle = __iommu_dma_map(dev, phys, size, dma_info_to_prot(dir, coherent, attrs), iommu_get_dma_domain(dev)); if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) && @@ -953,6 +973,9 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, unsigned long mask = dma_get_seg_boundary(dev); int i; + if (unlikely(handle_deferred_device(dev))) + return 0; + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) iommu_dma_sync_sg_for_device(dev, sg, nents, dir); @@ -1056,6 +1079,9 @@ static void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, static void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { + if (unlikely(handle_deferred_device(dev))) + return NULL; + gfp |= __GFP_ZERO; #ifdef CONFIG_DMA_DIRECT_REMAP