Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21254757ybl; Mon, 6 Jan 2020 00:38:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzbfLWw/Gao1k3qJdGPupE9XcdqXmoc8FcDY2FYPkP9jr0zJTgNLRZ+wkeT15fYkWExylmx X-Received: by 2002:a9d:6c01:: with SMTP id f1mr108949113otq.133.1578299906426; Mon, 06 Jan 2020 00:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578299906; cv=none; d=google.com; s=arc-20160816; b=gh+lYFbUtj55fVAS5kswC4lvul8jQeCRNPaIg0J5Sv8Lv3uL984vdnl1qKyFv9wA9d Cvi3nD3hPthCecKx/4stTMtvos3I+HVhSRemD5FO3ehH3ugiTpU2cu7y/OXJE39UAuYY j6EsbenKyGCuW5VkPEO1l0h6jevnrEHDevfQ8Xsd16rypnklcXLlZgkCTijpk5xP+jGf ccs62iA2i/XmQ92vChdMmqzULXe7hbm8arMbVNBlqVu06GPeuZV24sP5D+CMy8FJ9l8X nfCB1AvYJMOU+ycqI3TfS+nNfePGse9MbA50oeOhBtfA7ZmnR3kYZfHqrFqoP2SLZ6FP jLfw== 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=mq/a/92RzGFTNn84qYTErvRXyGKjin4a072qc24+zSQ=; b=iIZGjmxsyicNcBAMuzk+bUb02asXit1vvwMyu8edB+v3pjvuZklYxRm5xKznE387Oc 9ORwhhcWCc39Ljt+OudHTlVoL0Fz0aYgkflEzN9ZFtbVc64wqfevjelfTvakkfXm6rwd gekqFnPPAB3xObvRW7z1RL8xfemwioMbRQuCxnBDc7hAViEHs87RcmHBdrNnXgWpmXCS gsDz5eip9W15sjO2aQhO9X0GJ2Pc6a/JHETDqAOkHub/2CR9X7VSxh39HhtCkhyIFJDr 0ZN1SLGkmq0/RFibVeH6T8ZYubqWfmKvZ9j7Db0e0uRsCZ9R+VLVIGq8cCJuroduKluI QxUQ== 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 l131si33445227oig.120.2020.01.06.00.38.14; Mon, 06 Jan 2020 00:38:26 -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 S1726487AbgAFIhL convert rfc822-to-8bit (ORCPT + 99 others); Mon, 6 Jan 2020 03:37:11 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:38255 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbgAFIhK (ORCPT ); Mon, 6 Jan 2020 03:37:10 -0500 Received: from mail-pj1-f72.google.com ([209.85.216.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ioNsq-0003OA-AZ for linux-kernel@vger.kernel.org; Mon, 06 Jan 2020 08:37:08 +0000 Received: by mail-pj1-f72.google.com with SMTP id 14so12203120pjo.3 for ; Mon, 06 Jan 2020 00:37:08 -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=SNXkADHZhyJy0Bp0apNiPJvlafdrd5bDbFyFMJQ4dXU=; b=WDJZI1IKwsc+InPUKE3Bh+wD9OV378EmKK9dZgVrLBrsII1zWSJSxUqOTSuzae3T1c +dF+RG/8LoEiB5k6FOsH0TYrEFzoszV0i3OXaZQHJ1scQyzR3MbIu16DlGTO3qqkbLKw eU2ixG+nQ6vux0L++H480v1HrNE1A6dCwOKv+ut8YzSNXGKlqKFPyZNyd+1Fjjqz+q9B LXr+sOVFPFhPs0WS52sRf30yRlItuChBsspNuxmyvBTL8vYiJncLeFz4LcWqrhP6ePPS 6lJTU1b21mcq9UDmJB+YKsTy14/eit/PubGj3ffMG022z/1lQEFRHdsF++7yv7Kim1Z8 Xrug== X-Gm-Message-State: APjAAAV/rax63HvlqJjP7zGAXz0L+lKqJ+MNANzCBb6Y7HwluJsJucgN 7gSvORLourlCAULzbFzkSft4fvgFvc+I8NUUHeFpqJ6gLGfvAOPkayWTk9maEH5Gb/IRS4VjBgD Z9xq2dSPqbraqEjiJPEL9sRzMrQVYs2S32HRQpCnqgA== X-Received: by 2002:a17:90a:d78f:: with SMTP id z15mr41730961pju.36.1578299826804; Mon, 06 Jan 2020 00:37:06 -0800 (PST) X-Received: by 2002:a17:90a:d78f:: with SMTP id z15mr41730949pju.36.1578299826569; Mon, 06 Jan 2020 00:37:06 -0800 (PST) Received: from 2001-b011-380f-35a3-2839-ccbd-36ed-2f4a.dynamic-ip6.hinet.net (2001-b011-380f-35a3-2839-ccbd-36ed-2f4a.dynamic-ip6.hinet.net. [2001:b011:380f:35a3:2839:ccbd:36ed:2f4a]) by smtp.gmail.com with ESMTPSA id o31sm72172458pgb.56.2020.01.06.00.37.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2020 00:37:06 -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: <84CFD1EE-2DB7-451F-98E4-58C4B0046A81@canonical.com> Date: Mon, 6 Jan 2020 16:37:04 +0800 Cc: Joerg Roedel , Christoph Hellwig , "iommu@lists.linux-foundation.org" , Kernel development list Content-Transfer-Encoding: 8BIT Message-Id: 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: "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 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? 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