Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1152272pxb; Fri, 20 Nov 2020 02:27:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdUmARo0/SAogqLiQPzv8C0nw8QbW6E2dYNCwlkWuPQk9JWvzmCDW2zcK9aEpIf907DAGO X-Received: by 2002:a17:906:50f:: with SMTP id j15mr30954096eja.198.1605868075703; Fri, 20 Nov 2020 02:27:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605868075; cv=none; d=google.com; s=arc-20160816; b=HKqweY0yvORQVLd3ksn+IshtkVS4pGEZ0a39vWIdnluNuYpK9OwpFGKuIZn3PWRCrp VLScKBDu/rNm5Ml0HkC/o5QIEio3DgeDqAa/eRCLfRXU2JGM46Z82wS6yJKxeJUrHWLu oMSHlv8JFROOGnz4HTUtnDIeLEQTWrRrGW8ULmj1qbKahwi6GocwsqSv+flFV7CPNZUU 1/VujTvpl9psv4keu/Xknt1skBof5x8Qa01jVO2/4RBUk7omBB2CkQpGTJH4n/K+8Mjg a/9HMsaty/fd+Fuv4RIRD2e3c3Ke6PaWhkq+urh4G/r0CHxxQNCvUsbb/vGqIG5PywLC xT2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=49FPfutNK1zylZHjbd7kuF8FkVaj9jgmmrLW1uApZUA=; b=zKDCDf1my8rEKhRHPEzfISHJuLoQ4+u3LszEWU4id7ya1I4t84lqPAMLLM/53k354C TwIp6TUxsxfEolD7F/C+ntzeAwfYhofkkD736txXUEA9B6J0RH7ZpMTmziwXBkV5cd0N 6u/cz/s3BUXt612Kx+ar5TDKqMFepPV7KYxxcgAa9SyNaAJlYJDIpMfwJBVXgFWasdWt jrN86kll4mqydEMfojA6Q/RzGKLVakeCq/TFHXUmWpiCObYyQODhCT2DQYqjd286d7dD KjtHAtGrESZKMKoXk3Gv+bKK9cTiI0HrfSPEl0br+XLv0tEYHgbnRkx2yfRIUMEtevU7 1h/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si82242edv.131.2020.11.20.02.27.31; Fri, 20 Nov 2020 02:27:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727344AbgKTKYv (ORCPT + 99 others); Fri, 20 Nov 2020 05:24:51 -0500 Received: from mga12.intel.com ([192.55.52.136]:17833 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725797AbgKTKYv (ORCPT ); Fri, 20 Nov 2020 05:24:51 -0500 IronPort-SDR: DlKhuXPNq/taViYzym815djJfvA/ej1nNvjUYh6sKYfBgO1Y/hR3UBSs4UZynciH/dQuSAboCF bR0+fZX/Qotw== X-IronPort-AV: E=McAfee;i="6000,8403,9810"; a="150717606" X-IronPort-AV: E=Sophos;i="5.78,356,1599548400"; d="scan'208";a="150717606" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 02:24:50 -0800 IronPort-SDR: hN8MhrpTpINV5KH/rwVYRhPPn/vUGjrOphYoQlZOIUmPkqEZ+smU26kjf6MYIp95ZoD9btPmR1 en9yPiGjBz+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,356,1599548400"; d="scan'208";a="545393686" Received: from allen-box.sh.intel.com ([10.239.159.28]) by orsmga005.jf.intel.com with ESMTP; 20 Nov 2020 02:24:48 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Tom Murphy , David Woodhouse , Christoph Hellwig Cc: Ashok Raj , Tvrtko Ursulin , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu , Logan Gunthorpe Subject: [PATCH v5 4/7] iommu: Add quirk for Intel graphic devices in map_sg Date: Fri, 20 Nov 2020 18:17:16 +0800 Message-Id: <20201120101719.3172693-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120101719.3172693-1-baolu.lu@linux.intel.com> References: <20201120101719.3172693-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Combining the sg segments exposes a bug in the Intel i915 driver which causes visual artifacts and the screen to freeze. This is most likely because of how the i915 handles the returned list. It probably doesn't respect the returned value specifying the number of elements in the list and instead depends on the previous behaviour of the Intel iommu driver which would return the same number of elements in the output list as in the input list. Signed-off-by: Tom Murphy Signed-off-by: Lu Baolu Tested-by: Logan Gunthorpe --- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 10dafbc3d9e0..5591d6593583 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -879,6 +879,33 @@ static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents, unsigned int cur_len = 0, max_len = dma_get_max_seg_size(dev); int i, count = 0; + /* + * The Intel graphic driver is used to assume that the returned + * sg list is not combound. This blocks the efforts of converting + * Intel IOMMU driver to dma-iommu api's. Add this quirk to make the + * device driver work and should be removed once it's fixed in i915 + * driver. + */ + if (IS_ENABLED(CONFIG_DRM_I915) && dev_is_pci(dev) && + to_pci_dev(dev)->vendor == PCI_VENDOR_ID_INTEL && + (to_pci_dev(dev)->class >> 16) == PCI_BASE_CLASS_DISPLAY) { + for_each_sg(sg, s, nents, i) { + unsigned int s_iova_off = sg_dma_address(s); + unsigned int s_length = sg_dma_len(s); + unsigned int s_iova_len = s->length; + + s->offset += s_iova_off; + s->length = s_length; + sg_dma_address(s) = dma_addr + s_iova_off; + sg_dma_len(s) = s_length; + dma_addr += s_iova_len; + + pr_info_once("sg combining disabled due to i915 driver\n"); + } + + return nents; + } + for_each_sg(sg, s, nents, i) { /* Restore this segment's original unaligned fields first */ unsigned int s_iova_off = sg_dma_address(s); -- 2.25.1