From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51BAFC49361 for ; Thu, 17 Jun 2021 19:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 313DA613BA for ; Thu, 17 Jun 2021 19:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232564AbhFQTFp (ORCPT ); Thu, 17 Jun 2021 15:05:45 -0400 Received: from foss.arm.com ([217.140.110.172]:58672 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232447AbhFQTFn (ORCPT ); Thu, 17 Jun 2021 15:05:43 -0400 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 B459313A1; Thu, 17 Jun 2021 12:03:35 -0700 (PDT) Received: from [10.57.9.136] (unknown [10.57.9.136]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A150E3F694; Thu, 17 Jun 2021 12:03:33 -0700 (PDT) Subject: Re: [PATCH v13 4/6] iommu/vt-d: Add support for IOMMU default DMA mode build options To: John Garry , Lu Baolu , joro@8bytes.org, will@kernel.org, dwmw2@infradead.org, corbet@lwn.net Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linuxarm@huawei.com, thunder.leizhen@huawei.com, chenxiang66@hisilicon.com, linux-doc@vger.kernel.org References: <1623841437-211832-1-git-send-email-john.garry@huawei.com> <1623841437-211832-5-git-send-email-john.garry@huawei.com> <46dbce5c-1c2b-60d4-df56-d2b95a959425@linux.intel.com> From: Robin Murphy Message-ID: Date: Thu, 17 Jun 2021 20:03:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-17 09:00, John Garry wrote: > On 17/06/2021 08:32, Lu Baolu wrote: >> On 6/16/21 7:03 PM, John Garry wrote: >>> @@ -4382,9 +4380,9 @@ int __init intel_iommu_init(void) >>>            * is likely to be much lower than the overhead of >>> synchronizing >>>            * the virtual and physical IOMMU page-tables. >>>            */ >>> -        if (!intel_iommu_strict && cap_caching_mode(iommu->cap)) { >>> -            pr_warn("IOMMU batching is disabled due to >>> virtualization"); >>> -            intel_iommu_strict = 1; >>> +        if (cap_caching_mode(iommu->cap)) { >>> +            pr_warn("IOMMU batching disallowed due to >>> virtualization\n"); >>> +            iommu_set_dma_strict(true); >> >> With this change, VM guest will always show this warning. > > Would they have got it before also normally? > > I mean, default is intel_iommu_strict=0, so if > cap_caching_mode(iommu->cap) is true and intel_iommu_strict not set to 1 > elsewhere previously, then we would get this print. > >> How about >> removing this message? Users could get the same information through the >> kernel message added by "[PATCH v13 2/6] iommu: Print strict or lazy >> mode at init time". > > I think that the print from 2/6 should occur before this print. > > Regardless I would think that you would still like to be notified of > this change in policy, right? > > However I now realize that the print is in a loop per iommu, so we would > get it per iommu: > > for_each_active_iommu(iommu, drhd) { >     /* >      * The flush queue implementation does not perform >      * page-selective invalidations that are required for efficient >      * TLB flushes in virtual environments.  The benefit of batching >      * is likely to be much lower than the overhead of synchronizing >      * the virtual and physical IOMMU page-tables. >      */ >     if (!intel_iommu_strict && cap_caching_mode(iommu->cap)) { >         pr_warn("IOMMU batching is disabled due to virtualization"); >         intel_iommu_strict = 1; >     } >     ... > } > > I need to change that. How about this: > > bool print_warning = false; > > for_each_active_iommu(iommu, drhd) { >     /* >      * The flush queue implementation does not perform >      * page-selective invalidations that are required for efficient >      * TLB flushes in virtual environments.  The benefit of batching >      * is likely to be much lower than the overhead of synchronizing >      * the virtual and physical IOMMU page-tables. >      */ >     if (!print_warning && cap_caching_mode(iommu->cap)) { >         pr_warn("IOMMU batching disallowed due to virtualization\n"); >         iommu_set_dma_strict(true); >         print_warning = true; >     } >     ... > } > > or use pr_warn_once(). Maybe even downgrade it to pr_info_once(), since AIUI it's not really anything scary? I suppose you could technically fake up a domain on the stack to get the global setting out of iommu_get_dma_strict(), or perhaps give iommu_set_dma_strict() a cheeky return value to indicate what the previous setting was, in order to suppress the message entirely if strict is already set, but I'm not at all convinced it's worth the bother. Robin. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_RED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58F42C48BE5 for ; Thu, 17 Jun 2021 19:03:40 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14346613F2 for ; Thu, 17 Jun 2021 19:03:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14346613F2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id D0F71841CE; Thu, 17 Jun 2021 19:03:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NqXDlvAUxqqd; Thu, 17 Jun 2021 19:03:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9727A84183; Thu, 17 Jun 2021 19:03:38 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 63C25C000D; Thu, 17 Jun 2021 19:03:38 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A012C000B for ; Thu, 17 Jun 2021 19:03:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 51C7B60D74 for ; Thu, 17 Jun 2021 19:03:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GSU5Z7MbXv58 for ; Thu, 17 Jun 2021 19:03:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp3.osuosl.org (Postfix) with ESMTP id 6384F60633 for ; Thu, 17 Jun 2021 19:03:36 +0000 (UTC) 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 B459313A1; Thu, 17 Jun 2021 12:03:35 -0700 (PDT) Received: from [10.57.9.136] (unknown [10.57.9.136]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A150E3F694; Thu, 17 Jun 2021 12:03:33 -0700 (PDT) Subject: Re: [PATCH v13 4/6] iommu/vt-d: Add support for IOMMU default DMA mode build options To: John Garry , Lu Baolu , joro@8bytes.org, will@kernel.org, dwmw2@infradead.org, corbet@lwn.net References: <1623841437-211832-1-git-send-email-john.garry@huawei.com> <1623841437-211832-5-git-send-email-john.garry@huawei.com> <46dbce5c-1c2b-60d4-df56-d2b95a959425@linux.intel.com> From: Robin Murphy Message-ID: Date: Thu, 17 Jun 2021 20:03:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, iommu@lists.linux-foundation.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: base64 Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" T24gMjAyMS0wNi0xNyAwOTowMCwgSm9obiBHYXJyeSB3cm90ZToKPiBPbiAxNy8wNi8yMDIxIDA4 OjMyLCBMdSBCYW9sdSB3cm90ZToKPj4gT24gNi8xNi8yMSA3OjAzIFBNLCBKb2huIEdhcnJ5IHdy b3RlOgo+Pj4gQEAgLTQzODIsOSArNDM4MCw5IEBAIGludCBfX2luaXQgaW50ZWxfaW9tbXVfaW5p dCh2b2lkKQo+Pj4gwqDCoMKgwqDCoMKgwqDCoMKgwqAgKiBpcyBsaWtlb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