From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751577AbdDMI4k (ORCPT ); Thu, 13 Apr 2017 04:56:40 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:36014 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbdDMI4i (ORCPT ); Thu, 13 Apr 2017 04:56:38 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9089F60BF7 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=nwatters@codeaurora.org From: Nate Watterson To: robin.murphy@arm.com, Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: shankerd@codeaurora.org, Nate Watterson Subject: [PATCH] iommu/dma: Setup iova_domain granule for IOMMU_DMA_MSI cookies Date: Thu, 13 Apr 2017 04:55:15 -0400 Message-Id: <1492073715-7811-1-git-send-email-nwatters@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the __iommu_dma_{map/free} functions call iova_{offset/align} making them unsuitable for use with iommu_domains having an IOMMU_DMA_MSI cookie since the cookie's iova_domain member, iovad, is uninitialized. Now that iommu_dma_get_msi_page() calls __iommu_dma_map() regardless of cookie type, failures are being seen when mapping MSI target addresses for devices attached to UNMANAGED domains. To work around this issue, the iova_domain granule for IOMMU_DMA_MSI cookies is initialized to the value returned by cookie_msi_granule(). Fixes: a44e6657585b ("iommu/dma: Clean up MSI IOVA allocation") Signed-off-by: Nate Watterson --- drivers/iommu/dma-iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 8348f366..d7b0816 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -127,6 +127,16 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base) cookie->msi_iova = base; domain->iova_cookie = cookie; + + /* + * Setup granule for compatibility with __iommu_dma_{alloc/free} and + * add a compile time check to ensure that writing granule won't + * clobber msi_iova. + */ + cookie->iovad.granule = cookie_msi_granule(cookie); + BUILD_BUG_ON(offsetof(struct iova_domain, granule) < + sizeof(cookie->msi_iova)); + return 0; } EXPORT_SYMBOL(iommu_get_msi_cookie); -- Qualcomm Datacenter Technologies, Inc. on behalf of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.