Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp110719ybv; Wed, 5 Feb 2020 02:12:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyHrKEi+3hi6VBI8WHpchyawGeSGyK/FAra4UbMcG8swkWqNTH1eaS9Q10pNSnm++FwdBNa X-Received: by 2002:a9d:6283:: with SMTP id x3mr24703311otk.367.1580897549283; Wed, 05 Feb 2020 02:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580897549; cv=none; d=google.com; s=arc-20160816; b=ORItOYIkrbpbcevaqW6c8wJ/Q4K+LxTaJHrxhfClXGH+PxqHmUkDHUjdWOehsknmqD KRawsZQ6oUfAeCK7i291LfZODSJXZNslaMyD1nny37iWEiNTw+Ai7QIvQrtYgOWwGhp3 DCiu3QhaucW9U9Y0h7V7KRcmhssBbvlIO0ZENRRH7O1+updjwF9peLhRMGi0ekBiy4Ul sMME9cpdzGQ825cIniaM+3hg1XhkelYudJX5u2o3jY3NMR4LWCt5rcLJqCpRz3o/nJF1 idrsu9rhcnKTtMCyhlb+9Kl4mee88/xg2XsLMW3lQcy+a0HsSAbYYTRj3wtGpdRfD73k 6Cjw== 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=2qTCAy81WX2YFtHs+IhBDdQnJpTINaJJOjXmO4RSkG0=; b=aiCk070B3DrMV0yAcxs1XdQLdKXOuRC+uVjcquA2IIPpziqvGik9pFJY0H1Ddcn119 XHpvEzWVv024BYIbGmz6vzpzx6X412Yac+Dgr0yZr2W+PL8VrhSUNo9wc0EEhCGmiBnG 0fHLAJjT/cDCyeZh20cx9F0oEq7VyaNVdmrmP0EOo7RKKLYwdoCyGyCWqLlTsjnFz4DN bcskN45et2A7NmP+7fJ59IZ+quOzHfXkK8vrpHtglA1g6Z0bUUdsdtFbYhWVuYItpkiQ exnsCRFYCgsg+J/OLSGRfFZcRy6YssHq7yzcM2fCFjjNlbGD376UbT9wdBLkGhYxdcb5 mBdA== 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 k2si11197479oij.97.2020.02.05.02.12.17; Wed, 05 Feb 2020 02:12:29 -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 S1727790AbgBEKKT convert rfc822-to-8bit (ORCPT + 99 others); Wed, 5 Feb 2020 05:10:19 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:53040 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbgBEKKS (ORCPT ); Wed, 5 Feb 2020 05:10:18 -0500 Received: from mail-pg1-f200.google.com ([209.85.215.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1izHdP-0007bL-Ol for linux-kernel@vger.kernel.org; Wed, 05 Feb 2020 10:10:15 +0000 Received: by mail-pg1-f200.google.com with SMTP id o21so911136pgm.11 for ; Wed, 05 Feb 2020 02:10:15 -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=b8Oi2WdDQGlnw0JZx35Y2ZoU7u/G+yblEF6ps+T1Z7A=; b=T4dpPbkO6vlO00Zi8gknlbMIZVmVgzmqxxiAu+kFTMX7caIzIDqXCsXP5SiS45CNBU L8FWvm2uwWLDtIKHapUP50bYEajAfSlrevpFICrZ7cEXPOMHDFdPG6TrjXyoJ2NQ/slJ kx0O7HEqn7BVpnGBP2/DTpkL+fLOnsZvarJHh7fUzs4dfAb4MWzbGRnPwZX2dedS9Onr JTmEQGasn4l6/XLANTYN7snGL5aFf3ckOdUBC/uGarMXRVxLLXfKCOF5jBMKXbs2e+IG 0j3SgVx71/hvId10FwfQIZH5imDYU1j+Fajml2sO3PEeUDkYYYLbSjfgKfXB+jrByhe/ 1hJg== X-Gm-Message-State: APjAAAU3oeIdzHsuUkWAfWaRdm/hnO/KQGwQaJCDTAW2Wqy5XAvjt4Ex qz9gWA3NkuBVEDaucouLhsgKLk0SUJ+fcg27+nD6thgov4Bk+1VptLPsn2ZmHwBYres3Uc2KpLB lKzpczIBTC8NsK7AQU0ImazRuQpCh3dZme4GcNKbDdQ== X-Received: by 2002:a62:828b:: with SMTP id w133mr34324165pfd.192.1580897414255; Wed, 05 Feb 2020 02:10:14 -0800 (PST) X-Received: by 2002:a62:828b:: with SMTP id w133mr34324136pfd.192.1580897413944; Wed, 05 Feb 2020 02:10:13 -0800 (PST) Received: from 2001-b011-380f-35a3-4cfd-361b-ac7d-6a8c.dynamic-ip6.hinet.net (2001-b011-380f-35a3-4cfd-361b-ac7d-6a8c.dynamic-ip6.hinet.net. [2001:b011:380f:35a3:4cfd:361b:ac7d:6a8c]) by smtp.gmail.com with ESMTPSA id 10sm28075377pfu.132.2020.02.05.02.10.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Feb 2020 02:10:13 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH v2] iommu/amd: Disable IOMMU on Stoney Ridge systems From: Kai-Heng Feng In-Reply-To: Date: Wed, 5 Feb 2020 18:10:11 +0800 Cc: Christoph Hellwig , "iommu@lists.linux-foundation.org" , Kernel development list Content-Transfer-Encoding: 8BIT Message-Id: <6B7AE45E-F1E0-4949-B3E6-B78658CD223F@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> <84CFD1EE-2DB7-451F-98E4-58C4B0046A81@canonical.com> To: Joerg Roedel , "Deucher, Alexander" X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joerg, > On Jan 6, 2020, at 16:37, Kai-Heng Feng wrote: > > > >> On Dec 20, 2019, at 10:13, Kai-Heng Feng wrote: >> >> >> >>> 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. > > Any further suggestion to let me try? Since using identity mapping with ATS doesn't help, Is it possible to merge this patch as is? Kai-Heng > > Kai-Heng > >> >> 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 >