Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp480545pxv; Thu, 8 Jul 2021 07:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2a/wui6IWr9CuFWH/yGSnwYcbRaO5/9WDqj96QMO1cCyWwqvBLShXDxYp5+c9ULCXhp44 X-Received: by 2002:aa7:d38d:: with SMTP id x13mr38621983edq.23.1625752817583; Thu, 08 Jul 2021 07:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625752817; cv=none; d=google.com; s=arc-20160816; b=yo55QeWPLIvBBCT4pNfyD/Qfd0z1qyfF5jNVMxfZd640Yg2JLvC+5Eq17JgJLXkX8h NbG3IrVX1/CNW7kO+norqx966FSfcOk+LbzQY6CtARqo2BjmV+1PtwyTnAMRUD4uGVAW wR61Whw4QyfxL8qydeun5WnqXIDcshRj7OcrSikGGE1C0T6quYVCEnLwRHe24ZW7/Ipf SpEs6eYbMmkUSh56uLjVYkO3rIhELEXZcl6Msy/HVKm9T1kxs/MCywyg22yB9SmE3+Al ViD5Y4f3zahYh+DwmSCgyDvQzG0oCKf7+8o3+vOxcNSR+KHQXIGuCdKfxG4DXpLIh6Fo mjpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=VtIU2Y6iPu0EP7ecFsyW91ksyJ0R/0bAhIVleyNgs7A=; b=K+fSIZrHF8Epnouv5vsijoIA3HARRXF/p2+Xs9+3AQZkYS84fCzbHBrpZx49NloTII 7wLxwUP8j45lQf2MTmWJ53m1cWd+SUbwnM2gZQxCi0rvX+5wVgYJKVZJIUFFFNLSPK7d eWnUr1bRugO2l41G/Sb6bXzOW+2IvQqN+1HUofc7b0BWJWq1QTPskXStSaSSya6i8WAH VL5paNUa1oePFv3V/T4LrCj8KGmYH07I8PDVgnXGDgeyGAVuNpSfMKOhaJ29G24pZHd0 WRWuD7QhLHQabZudy7bA7Vdml12c9XoT3WCPOzppdDjrqUoH1PzjkBp1z+QNYYXPcayi D7Sw== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si2770537ejb.624.2021.07.08.06.59.54; Thu, 08 Jul 2021 07:00:17 -0700 (PDT) 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbhGHN7y (ORCPT + 99 others); Thu, 8 Jul 2021 09:59:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:41244 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbhGHN7y (ORCPT ); Thu, 8 Jul 2021 09:59:54 -0400 Received: from mail-ed1-f70.google.com ([209.85.208.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1m1UWd-0005KW-O9 for linux-kernel@vger.kernel.org; Thu, 08 Jul 2021 13:57:11 +0000 Received: by mail-ed1-f70.google.com with SMTP id w15-20020a05640234cfb02903951279f8f3so3335495edc.11 for ; Thu, 08 Jul 2021 06:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VtIU2Y6iPu0EP7ecFsyW91ksyJ0R/0bAhIVleyNgs7A=; b=NLVDkzc8eXVofbHS1IlBbFcfixzD3gpmU+NxDhnA4MMAWFdJEI+NVS7U/C0wVLPgDD Lij4+uvLkxjlgl1jYUOEOVwPiH4+CHoBprtt2UcresjBDA8+UGkR9VhnQ0vRVH2mlE+a hLJPVHjiLh7fJWz/6LPzLFkasYNu7j6gLbOwLU24O1wWpnlIXdZeJnd0LBBv3mddjCVg nbWt/f1YO0OXNY+0IDA++OWTjQRHQ0iiKvaeP5KdAcvR2Vd/F7ZJgmiwloxQMphQkv88 dtpcSP652B+VzuFf8PS9B9cxlysTgzaa60UTsyk/XNJUt3OENV+k3J9f8fqS4twUTg1O IN8g== X-Gm-Message-State: AOAM530ygZWDJ5u71ExThjtP9yIeDm0R3Fyo9uCFg9wRvxhe6XoYJ/BG 0tBUiXuhmLCET+f3fR/4i54pql3IG9wo+OpRxZowJzlALgBAL9k6Whhc1JQuUlMuck8lZPvYjyH FBS2fiSBJBquOmow6XWDPDf+Dvhj711NkqUWPUaVjZGoG/GKYYAGK9ysNQA== X-Received: by 2002:aa7:c9d8:: with SMTP id i24mr38792927edt.79.1625752631448; Thu, 08 Jul 2021 06:57:11 -0700 (PDT) X-Received: by 2002:aa7:c9d8:: with SMTP id i24mr38792888edt.79.1625752631156; Thu, 08 Jul 2021 06:57:11 -0700 (PDT) MIME-Version: 1.0 References: <20210708074232.924844-1-kai.heng.feng@canonical.com> In-Reply-To: From: Kai-Heng Feng Date: Thu, 8 Jul 2021 21:57:00 +0800 Message-ID: Subject: Re: [PATCH] iommu/amd: Enable swiotlb if any device supports iommu v2 and uses identity mapping To: Robin Murphy Cc: Joerg Roedel , will@kernel.org, "open list:AMD IOMMU (AMD-VI)" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 8, 2021 at 6:18 PM Robin Murphy wrote: > > On 2021-07-08 10:28, Joerg Roedel wrote: > > On Thu, Jul 08, 2021 at 03:42:32PM +0800, Kai-Heng Feng wrote: > >> @@ -344,6 +344,9 @@ static int iommu_init_device(struct device *dev) > >> > >> iommu = amd_iommu_rlookup_table[dev_data->devid]; > >> dev_data->iommu_v2 = iommu->is_iommu_v2; > >> + > >> + if (dev_data->iommu_v2) > >> + swiotlb = 1; > > > > This looks like the big hammer, as it will affect all other systems > > where the AMD GPUs are in their own group. > > > > What is needed here is an explicit check whether a non-iommu-v2 device > > is direct-mapped because it shares a group with the GPU, and only enable > > swiotlb in this case. > > Right, it's basically about whether any DMA-limited device might at any > time end up in an IOMMU_DOMAIN_IDENTITY domain. And given the > possibility of device hotplug and the user being silly with the sysfs > interface, I don't think we can categorically determine that at boot time. > > Also note that Intel systems are likely to be similarly affected (in > fact intel-iommu doesn't even have the iommu_default_passthough() check > so it's probably even easier to blow up). swiotlb is enabled by pci_swiotlb_detect_4gb() and intel-iommu doesn't disable it. I wonder if we can take the same approach in amd-iommu? Kai-Heng > > Robin.