Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5737110ybp; Tue, 8 Oct 2019 07:34:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvX+vJfyWtuKg03bYFoKOSN/qTgoBG8JYyEQLtygmgTbBR2ZUtLQvgaObyP5m/jkM+iV3+ X-Received: by 2002:aa7:d7c9:: with SMTP id e9mr34176645eds.237.1570545288635; Tue, 08 Oct 2019 07:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570545288; cv=none; d=google.com; s=arc-20160816; b=z14WNNe1byBXO+aKxz4mbqWWfwBJ6030Pf3ifqJaqJVAQLtQQ2Ea+GVVJuBKXqnBc4 Lne+6GUfMI/6CPzLRdToYir0mcu2Wu8vg+aAIzCLlaB4zFuLLw3i2EI7CThkaro80g1C O08ciyxDCWK/Owg/88aHbS+tXYYpbl4LpgDx6kondVa9cz11oXb6vO30f6h8YKg3/rqf BVx8Hdkv+k480P3btiE1xzxUgGE6W07TT7Ym6f8BH4/yWQ9o1d4QrcptLo7xToNDTMOU 6PcHlMFueOSQIRVuyhbmJVM2jkM4OriZipFnYYFHt+YZMeGrlP3uW50Nqz6YqlOQQ4Pm F6uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=rEMMm6x48wipfHs8VZIqNwD7DIJGYzqO2JqQPWe5Vn4=; b=zPk1pnKYZWKHDZOx2lCALa0YOaARgwBHFkGE2UxYV4BaSEZC9AB2VlqCJjXl0BoMAd EeT0zdghBeVSpWz2G1j+J9R1AQbWsj4L0zg+Sg3GG0V8MfMgCtVIIDhHEZG/RMEETV2o cpnLasK2wJb1UKuc7qe6hDZpQR84gkKul1izTd65YsmGCAXsXxP1/uPY6A5yr/Hi1gnX MWTr18boDGQrMzkcPnU77io8l7sKFqgeSrO7wonmArEd/LvNSlHxtuCjOj6cWvBiYcyB C75rCrpncE/QoK7tCtz6UxfiReY485BOjfaqbnHlgdmsgyw5Ly9fuInz4lRmo38RhTlw 1VVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ov32si2958638ejb.411.2019.10.08.07.34.24; Tue, 08 Oct 2019 07:34:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726071AbfJHOeB (ORCPT + 99 others); Tue, 8 Oct 2019 10:34:01 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33290 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725839AbfJHOeB (ORCPT ); Tue, 8 Oct 2019 10:34:01 -0400 Received: by mail-qt1-f193.google.com with SMTP id r5so25676615qtd.0 for ; Tue, 08 Oct 2019 07:34:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=rEMMm6x48wipfHs8VZIqNwD7DIJGYzqO2JqQPWe5Vn4=; b=a1vueA6z5flhMIxxmIo3cauDbfAteqX0uHPypxye2h/yMYtKig22TyU6mrsXDuZLRK iCgVOoP2USA9bbeZzJ3ilj7r6WfZXqA9UGLBDU3qVaAzN5ApCG9HDCoEOFdB8lxfmMIc NYs4UED9+OPv2j19N5Hd25N6W/vTXzTxXQ8I6QsbCX2+lC2Yg2XxliyA8mJprzzBohJ6 7eEFr3gfBw6wy3JPJvDV7tqE6x5TF6u5f5wfPYe7NB7+J3xnlM3EEiQk4a4985MwBBUq 0SHFW+kWM4sM4B7t5UW/i27f3EXBTgUB49f2fi3SV1k3W/Vk+RO6u7SurUQQmEFsJOw7 9a+Q== X-Gm-Message-State: APjAAAW5MtdZyjP7yMDKOt3ZoEh+MFpbvbhGMvqEuS/aPtgx/dxa8zIL HYVBcGt8bY2SQ+WQ6disZja7H8E70/YmLg== X-Received: by 2002:ac8:75cd:: with SMTP id z13mr34932892qtq.87.1570545239704; Tue, 08 Oct 2019 07:33:59 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id q49sm13001806qta.60.2019.10.08.07.33.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Oct 2019 07:33:59 -0700 (PDT) Date: Tue, 8 Oct 2019 10:33:57 -0400 From: Arvind Sankar To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH] iommu/vt-d: Return the correct dma mask when we are bypassing the IOMMU Message-ID: <20191008143357.GA599223@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191008072949.GA9452@lst.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We must return a mask covering the full physical RAM when bypassing the IOMMU mapping. Also, in iommu_need_mapping, we need to check using dma_direct_get_required_mask to ensure that the device's dma_mask can cover physical RAM before deciding to bypass IOMMU mapping. Fixes: 249baa547901 ("dma-mapping: provide a better default ->get_required_mask") Reported-by: Arvind Sankar Tested-by: Arvind Sankar Originally-by: Christoph Hellwig Signed-off-by: Christoph Hellwig Fixed-by: Arvind Sankar Signed-off-by: Arvind Sankar --- drivers/iommu/intel-iommu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 3f974919d3bd..79e35b3180ac 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -3471,7 +3471,7 @@ static bool iommu_need_mapping(struct device *dev) if (dev->coherent_dma_mask && dev->coherent_dma_mask < dma_mask) dma_mask = dev->coherent_dma_mask; - if (dma_mask >= dma_get_required_mask(dev)) + if (dma_mask >= dma_direct_get_required_mask(dev)) return false; /* @@ -3775,6 +3775,13 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele return nelems; } +static u64 intel_get_required_mask(struct device *dev) +{ + if (!iommu_need_mapping(dev)) + return dma_direct_get_required_mask(dev); + return DMA_BIT_MASK(32); +} + static const struct dma_map_ops intel_dma_ops = { .alloc = intel_alloc_coherent, .free = intel_free_coherent, @@ -3787,6 +3794,7 @@ static const struct dma_map_ops intel_dma_ops = { .dma_supported = dma_direct_supported, .mmap = dma_common_mmap, .get_sgtable = dma_common_get_sgtable, + .get_required_mask = intel_get_required_mask, }; static void -- 2.21.0