Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2672072ybl; Thu, 19 Dec 2019 18:30:59 -0800 (PST) X-Google-Smtp-Source: APXvYqz26BIGdSeMcx85axJe0vIDklLacXZrePHoiv8NM858Ef2Edrvx/glQC+kwSwUx1pGhqM7Q X-Received: by 2002:a05:6830:595:: with SMTP id c21mr5881830oth.208.1576809059566; Thu, 19 Dec 2019 18:30:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576809059; cv=none; d=google.com; s=arc-20160816; b=HwAfVWkn4U4P0ssMYFehKONXa258daU9CUTpxnJv7DvTY6tB4hU4y/V5LVHapdrkwC 5Xe1AhRUmW0HYNy6u88tthYJJyFwxdzXPH8IpxgVtwUiwS5BGFNTEQUoJYs0hzoI/hs8 MidO7MYwmCIObNqxWES6AOs3OJ/CYmXUCucnEfP4E8329cZjarFh20C/2FmuOWPMyltu AOxvfct/OdhydBFim+qOhGRIBHlekzXHBE8FSkScXTlhGFPi8MCDR9ZImPKya2VKnb/d +MuvTaJS6wQsh7E8kWp07yTyfRAnmz2Z2Mfj/empnTB0/lHf63kIZfnJ9g7UGse6znxs wQXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=GIH49e1d1vvPgthviCOckmMPgiOeAYYS0fipvMyoNc4=; b=LGN+lfg73eBLMf9WnGhMzKcsStn73H+mEOEHE2r1+Vb+uDjt/SvAbFbC48ItoTzP5a 8OFUY9eXd0JS6QBZY2SjBp2D1uBhlvl6R2s/UmGHQtb3zeMEZBdwptG7qXg0mOI8xLpY qF7r71Q1F1OguCRgwSXQ0K9i8xWpteiWNi9MOXb95SrmnlaRmtm+npw4j2bQdc5K83in 9TbJLVMxZ8wryfYKyt9OiTLYSOeDnV4KStJkzziQrO+1Uw16WrB15Itop0VCkanwOBNM h2B4OCHSy+7vfoi8liu2M17qeGGyoEnbIspIwIFFd225TzeOaFHxsyrGoc5uGXowseFw ZSdA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si4411820oth.15.2019.12.19.18.30.48; Thu, 19 Dec 2019 18:30:59 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbfLTCaJ convert rfc822-to-8bit (ORCPT + 99 others); Thu, 19 Dec 2019 21:30:09 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:57893 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbfLTCaI (ORCPT ); Thu, 19 Dec 2019 21:30:08 -0500 Received: from mail-pj1-f69.google.com ([209.85.216.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ii7nn-00023n-Ad for linux-kernel@vger.kernel.org; Fri, 20 Dec 2019 02:14:03 +0000 Received: by mail-pj1-f69.google.com with SMTP id c31so4382492pje.9 for ; Thu, 19 Dec 2019 18:14:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VIcfiGu1E2yBl5t4KuBjAXACx3U5hMWofonCQDwGF90=; b=QUJ2VXdhTSRWxiONjVt+Kx9wZaG1HieWHk7p/l7tYgrUFqOICgtAGg/I4g8ZxpLQjE 7xwy3b7y8CISXtShYK8Qgjt0aHsjInbmBOWpbAoIgzJAKpHTwzuUrHkUEPfG6Rvd4tmx 46IwTtxqdn9on67OH9imE4m/aGWdWOK6GPd19sPrNU7i5XGXHaiqYFnERtLv+PcrXSTK KGG5Lqam+o5B2siNXF6XyWB8EKty2k7BrVO2FBJIy60FxPtSUVTlFXDgxx+IFqH5jDGF XWWAbs3kSz33s4YfJ+rASOjTZKMXMLE9Jr/FogVhzBhP7ARiFfOff0sLj8qhSiusyq2F 42hg== X-Gm-Message-State: APjAAAV0AFyq3p+uo8md7pSu4oGgG1fzQ838NwwjcT0vbOd0luAg7iKD +A6H6Ziu427wqyDVWzPGyMNanpX4iE7GF9PcAw94c8jXudyK3Cvj1BQeEBIlNKQU5s8PbTpz85K U8vjpsG0ZYLfYvcMXFRG6epOUym6EphZIUr3eyruTVw== X-Received: by 2002:a63:6f8a:: with SMTP id k132mr12636426pgc.70.1576808041798; Thu, 19 Dec 2019 18:14:01 -0800 (PST) X-Received: by 2002:a63:6f8a:: with SMTP id k132mr12636387pgc.70.1576808041225; Thu, 19 Dec 2019 18:14:01 -0800 (PST) Received: from 2001-b011-380f-35a3-1d28-698a-1c9a-9851.dynamic-ip6.hinet.net (2001-b011-380f-35a3-1d28-698a-1c9a-9851.dynamic-ip6.hinet.net. [2001:b011:380f:35a3:1d28:698a:1c9a:9851]) by smtp.gmail.com with ESMTPSA id i127sm10569559pfc.55.2019.12.19.18.13.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Dec 2019 18:14:00 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) Subject: Re: [PATCH v2] iommu/amd: Disable IOMMU on Stoney Ridge systems From: Kai-Heng Feng In-Reply-To: Date: Fri, 20 Dec 2019 10:13:58 +0800 Cc: Joerg Roedel , Christoph Hellwig , "iommu@lists.linux-foundation.org" , Kernel development list Content-Transfer-Encoding: 8BIT Message-Id: <84CFD1EE-2DB7-451F-98E4-58C4B0046A81@canonical.com> References: <20191129142154.29658-1-kai.heng.feng@canonical.com> <20191202170011.GC30032@infradead.org> <974A8EB3-70B6-4A33-B36C-CFF69464493C@canonical.com> <20191217095341.GG8689@8bytes.org> <6DC0EAB3-89B5-4A16-9A38-D7AD954DDF1C@canonical.com> To: "Deucher, Alexander" X-Mailer: Apple Mail (2.3608.40.2.2.4) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Dec 20, 2019, at 03:15, Deucher, Alexander wrote: > >> -----Original Message----- >> From: Kai-Heng Feng >> Sent: Wednesday, December 18, 2019 12:45 PM >> To: Joerg Roedel >> Cc: Christoph Hellwig ; Deucher, Alexander >> ; iommu@lists.linux-foundation.org; Kernel >> development list >> Subject: Re: [PATCH v2] iommu/amd: Disable IOMMU on Stoney Ridge >> systems >> >> >> >>> On Dec 17, 2019, at 17:53, Joerg Roedel wrote: >>> >>> On Fri, Dec 06, 2019 at 01:57:41PM +0800, Kai-Heng Feng wrote: >>>> Hi Joerg, >>>> >>>>> On Dec 3, 2019, at 01:00, Christoph Hellwig wrote: >>>>> >>>>> On Fri, Nov 29, 2019 at 10:21:54PM +0800, Kai-Heng Feng wrote: >>>>>> Serious screen flickering when Stoney Ridge outputs to a 4K monitor. >>>>>> >>>>>> According to Alex Deucher, IOMMU isn't enabled on Windows, so let's >>>>>> do the same here to avoid screen flickering on 4K monitor. >>>>> >>>>> Disabling the IOMMU entirely seem pretty severe. Isn't it enough to >>>>> identity map the GPU device? >>>> >>>> Ok, there's set_device_exclusion_range() to exclude the device from >> IOMMU. >>>> However I don't know how to generate range_start and range_length, >> which are read from ACPI. >>> >>> set_device_exclusion_range() is not the solution here. The best is if >>> the GPU device is put into a passthrough domain at boot, in which it >>> will be identity mapped. DMA still goes through the IOMMU in this >>> case, but it only needs to lookup the device-table, page-table walks >>> will not be done anymore. >>> >>> The best way to implement this is to put it into the >>> amd_iommu_add_device() in drivers/iommu/amd_iommu.c. There is this >>> check: >>> >>> if (dev_data->iommu_v2) >>> iommu_request_dm_for_dev(dev); >>> >>> The iommu_request_dm_for_dev() function causes the device to be >>> identity mapped. The check can be extended to also check for a device >>> white-list for devices that need identity mapping. >> >> My patch looks like this but the original behavior (4K screen flickering) is still >> the same: > > Does reverting the patch to disable ATS along with this patch help? Unfortunately it doesn't help. Kai-Heng > > Alex > >> >> diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c >> index bd25674ee4db..f913a25c9e92 100644 >> --- a/drivers/iommu/amd_iommu.c >> +++ b/drivers/iommu/amd_iommu.c >> @@ -42,6 +42,7 @@ >> #include >> #include >> #include >> +#include >> >> #include "amd_iommu_proto.h" >> #include "amd_iommu_types.h" >> @@ -2159,6 +2160,8 @@ static int amd_iommu_add_device(struct device >> *dev) >> struct iommu_domain *domain; >> struct amd_iommu *iommu; >> int ret, devid; >> + bool need_identity_mapping = false; >> + u32 header; >> >> if (!check_device(dev) || get_dev_data(dev)) >> return 0; >> @@ -2184,7 +2187,11 @@ static int amd_iommu_add_device(struct device >> *dev) >> >> BUG_ON(!dev_data); >> >> - if (dev_data->iommu_v2) >> + header = read_pci_config(0, PCI_BUS_NUM(devid), PCI_SLOT(devid), >> PCI_FUNC(devid)); >> + if ((header & 0xffff) == 0x1002 && (header >> 16) == 0x98e4) >> + need_identity_mapping = true; >> + >> + if (dev_data->iommu_v2 || need_identity_mapping) >> iommu_request_dm_for_dev(dev); >> >> /* Domains are initialized for this device - have a look what we ended up >> with */ >> >> >> $ dmesg | grep -i direct >> [ 0.011446] Using GB pages for direct mapping >> [ 0.703369] pci 0000:00:01.0: Using iommu direct mapping >> [ 0.703830] pci 0000:00:08.0: Using iommu direct mapping >> >> So the graphics device (pci 0000:00:01.0:) is using direct mapping after the >> change. >> >> Kai-Heng >> >>> >>> HTH, >>> >>> Joerg