From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758690Ab1E0Bc1 (ORCPT ); Thu, 26 May 2011 21:32:27 -0400 Received: from relay3.sgi.com ([192.48.152.1]:37791 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758579Ab1E0BcZ (ORCPT ); Thu, 26 May 2011 21:32:25 -0400 Message-Id: <20110527013221.405688800@gulag1.americas.sgi.com> References: <20110527013221.231071058@gulag1.americas.sgi.com> User-Agent: quilt/0.46-1 Date: Thu, 26 May 2011 20:32:22 -0500 From: Mike Travis To: David Woodhouse , Chris Wright , Andrew Morton , Ingo Molnar Cc: Mike Habeck , Jesse Barnes , stable@kernel.org, iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] Intel pci: Check for identity mapping candidate using system dma mask Content-Disposition: inline; filename=check-against-reqd-mask.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The identity mapping code appears to make the assumption that if the devices dma_mask is greater than 32bits the device can use identity mapping. But that is not true, take the case where we have a 40bit device in a 44bit architecture. The device can potentially receive a physical address that it will truncate and cause incorrect addresses to be used. Instead check to see if the device's dma_mask is large enough to address the system's dma_mask. From: Chris Wright Signed-off-by: Mike Travis Reviewed-by: Mike Habeck --- drivers/pci/intel-iommu.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- linux.orig/drivers/pci/intel-iommu.c +++ linux/drivers/pci/intel-iommu.c @@ -2187,8 +2187,19 @@ static int iommu_should_identity_map(str * Assume that they will -- if they turn out not to be, then we can * take them out of the 1:1 domain later. */ - if (!startup) - return pdev->dma_mask > DMA_BIT_MASK(32); + if (!startup) { + /* + * If the device's dma_mask is less than the system's memory + * size then this is not a candidate for identity mapping. + */ + u64 dma_mask = pdev->dma_mask; + + if (pdev->dev.coherent_dma_mask && + pdev->dev.coherent_dma_mask < dma_mask) + dma_mask = pdev->dev.coherent_dma_mask; + + return dma_mask >= dma_get_required_mask(&pdev->dev); + } return 1; } --