Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp870516pxp; Wed, 16 Mar 2022 19:40:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwybha2pT4XjIgc4vX3P3KRrkYf97/99ZbDTUicNRZaHW7AJSXte68oquP8IzFBo8P9xN5h X-Received: by 2002:a65:6cc7:0:b0:380:6a04:cecc with SMTP id g7-20020a656cc7000000b003806a04ceccmr1909583pgw.455.1647484837789; Wed, 16 Mar 2022 19:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647484837; cv=none; d=google.com; s=arc-20160816; b=CnyInh4Y8VGE2UcOMuGw6kfPiamapUkNYHYR0FHYMLp1a2r2+tNggcs0/5mVg3DSnV Ax+zcOxK3DMfJotF160Yxt4cJpCyKZDO/lM2DQP+M7MKuTadbLALbbY4a3Rx7oL1B4fT l71Zolkudy0WSd1lBDHV0Tl5WfPHhDEHQXIgQgsVVYMfXDkCZxx7vD3fSmI+4Xex14Ms yGpjwtw/jLH7PCLrYTm1YkbY3h9k92EZ1MFMzAb8nFaOLlzc93L0rx+pKt1GY+mL8Sij 9XAssJZQN9jWH9gd0+Z9GQIiw4n6Ot+J3MZMq6arLVJCA/U98cXMTkQLRR7Rvox4HxD4 4s0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=5WMtHNdldfBnyBrBR6P+6U3SpckdxPX66xW8I0ldrbM=; b=nNTyCnIUotMkbKGsD0ZqIkM4e0p5m6lnvLSfVCDMfQYVpekiZpeMktXD0FgPmHdCpB NMB8mdGrROUp1CyChEkaINiA6VsYjbpUPmt2D0luXSBkwXiXRJUAdW7H5UQTW9UAG6wc pqKvll+OSZ3CykEWZx1vyNtaxOjJi1kggOgQN4VRGSS8fHNdnDZ/BRs6F8GxhKkzXOAn IKK+N44/rjrtBn4lPRbIifbrER7o1OXdw7kgl5/bkfulqVfnELi+sYA1I5xPdG3k878a 2CyQ/sraYRMNn7DLWrpFUh69hnPN5ieI/9yV9/psPx+GUoMHWaTiN2AdJgVUim8Y7RE7 ay7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a654387000000b003816043ef62si861237pgp.343.2022.03.16.19.40.24; Wed, 16 Mar 2022 19:40:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350978AbiCOSJL (ORCPT + 99 others); Tue, 15 Mar 2022 14:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350970AbiCOSJI (ORCPT ); Tue, 15 Mar 2022 14:09:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94A0F6373; Tue, 15 Mar 2022 11:07:54 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A3A41474; Tue, 15 Mar 2022 11:07:54 -0700 (PDT) Received: from [10.57.42.204] (unknown [10.57.42.204]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6B68B3F73D; Tue, 15 Mar 2022 11:07:52 -0700 (PDT) Message-ID: <21d33a75-8c0e-7734-b3d1-dbe33cfe0ab0@arm.com> Date: Tue, 15 Mar 2022 18:07:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH 2/2] thunderbolt: Use pre-boot DMA protection on AMD systems Content-Language: en-GB To: "Limonciello, Mario" , Christoph Hellwig Cc: Michael Jamet , Mika Westerberg , "open list:THUNDERBOLT DRIVER" , open list , Yehezkel Bernat , "open list:AMD IOMMU (AMD-VI)" , Andreas Noever , Will Deacon References: <20220315162455.5190-1-mario.limonciello@amd.com> <20220315162455.5190-2-mario.limonciello@amd.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-03-15 16:54, Limonciello, Mario via iommu wrote: > [Public] > > >> On Tue, Mar 15, 2022 at 11:24:55AM -0500, Mario Limonciello wrote: >>> - * handled natively using IOMMU. It is enabled when IOMMU is >>> - * enabled and ACPI DMAR table has DMAR_PLATFORM_OPT_IN set. >>> + * handled natively using IOMMU. It is enabled when the IOMMU is >>> + * enabled and either: >>> + * ACPI DMAR table has DMAR_PLATFORM_OPT_IN set >>> + * or >>> + * ACPI IVRS table has DMA_REMAP bitset >>> */ >>> return sprintf(buf, "%d\n", >>> - iommu_present(&pci_bus_type) && >> dmar_platform_optin()); >>> + iommu_present(&pci_bus_type) && >>> + (dmar_platform_optin() || amd_ivrs_remap_support())); >> >> Yikes. No, the thunderbot code does not have any business poking into >> either dmar_platform_optin or amd_ivrs_remap_support. This needs >> a proper abstration from the IOMMU code. > > To make sure I follow your ask - it's to make a new generic iommu function > That would check dmar/ivrs, and switch out thunderbolt domain.c to use the > symbol? > > I'm happy to rework that if that is what you want. > Do you have a preferred proposed function name for that? But why? Either IOMMU translation is enabled or it isn't, and if it is, what's to gain from guessing at *why* it might have been? And even if the IOMMU's firmware table did tell the IOMMU driver to enable the IOMMU, why should that be Thunderbolt's business? Furthermore, looking at patch #1 I can only conclude that this is entirely meaningless anyway. AFAICS it's literally reporting whether the firmware flag was set or not. Not whether it's actually been honoured and the IOMMU is enforcing any kind of DMA protection at all. Even on Intel where the flag does at least have some effect on the IOMMU driver, that can still be overridden. I already have a patch refactoring this to get rid of iommu_present(), but at the time I wasn't looking to closely at what it's trying to *do* with the information. If it's supposed to accurately reflect whether the Thunderbolt device is subject to IOMMU translation and not bypassed, I can fix that too (and unexport dmar_platform_optin() in the process...) Robin.