Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5869913ioo; Wed, 1 Jun 2022 14:32:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVSEPFB82nkRYWLR7N9DwYtWn+MIW9ZYEYoJTN9oDY931i332F4CbbX/OtqcpUTg2B8Zm8 X-Received: by 2002:a63:e43:0:b0:3fb:ca8e:616d with SMTP id 3-20020a630e43000000b003fbca8e616dmr1171121pgo.443.1654119142273; Wed, 01 Jun 2022 14:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654119142; cv=none; d=google.com; s=arc-20160816; b=B1EKs/NNbvIRTSYGh/npvBQJ/9ZnZgHGUgMA7v2DVA6ERelfhCeX6y7FxtdO4Ewc2o K+ZECu4k+kPNzll/9D/dI5wVvfjM06fhp6YDPoS4rF6Tu0osG4YeXCQhzcgqzWdRIYOG loeqM2wRbzpLeSRQ8iUEbh25vXOdezKop/Cmv3AcFKnOoAS5e816uOLt7ap5ZTdh/WGg mZeDThX7u4PVjvp1BA0Wyviat6Dbn7QfWoEvlZzVfKle9tkvRI/pnc4DnYgDDTreg9Bc D/KQOubEw1KdRoC4+X9O44RvXoJ0kJRbDPZSqx/047xKefMx9OiO8Rxmwo94i5ongcJu qp7Q== 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=Eu/fJ44OU8LM/u4KFmilheYeqNfaGGbjmm2xFNL1+ig=; b=E3zQNXkvImJS4JO794YT86SodThjVcIMgZkjBajDVFyMh50F+Vzr+NMcI3VQad6Rbk i27tJcFiTpuQWDRl7uiATnMAl8ML+V5jmPATLBDMh/K4q097tpX0NbvlBnkkQ5uOJuTL x93DcfZY2h6g/g7VcjVup95L8Dz5DgK4yJrha9SOoIWVKXm3lZyyDMzELrB0NjEMO6Xc bE5IWArt2sBQUKglJQlA3ZRyeSiuWovl7FHCOEMQT9d725WgdKXLlQ3fEtg2/r7zg9ac RHMpVzFPGFiHMz8vL2GVHcp1GOpVTS1djH5w78mAlD5vGfFlhr2c2f16w+hGZ9+/N/YK uCUw== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r5-20020a654985000000b003c626c711a8si3854747pgs.108.2022.06.01.14.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2331E252C05; Wed, 1 Jun 2022 13:20:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345436AbiEaPBS (ORCPT + 99 others); Tue, 31 May 2022 11:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345438AbiEaPBQ (ORCPT ); Tue, 31 May 2022 11:01:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE09E5C746 for ; Tue, 31 May 2022 08:01:14 -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 1597B23A; Tue, 31 May 2022 08:01:14 -0700 (PDT) Received: from [10.57.81.38] (unknown [10.57.81.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7F8D43F73D; Tue, 31 May 2022 08:01:11 -0700 (PDT) Message-ID: Date: Tue, 31 May 2022 16:01:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 01/12] iommu/vt-d: Use iommu_get_domain_for_dev() in debugfs Content-Language: en-GB To: Jason Gunthorpe , Baolu Lu Cc: Joerg Roedel , Kevin Tian , Ashok Raj , Christoph Hellwig , Will Deacon , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20220527063019.3112905-1-baolu.lu@linux.intel.com> <20220527063019.3112905-2-baolu.lu@linux.intel.com> <20220527145910.GQ1343366@nvidia.com> <20220530121412.GX1343366@nvidia.com> <42623a73-c288-1c0d-7021-93caff4ffb6f@linux.intel.com> <20220531131052.GD1343366@nvidia.com> <60318d83-e22f-f922-436f-6c31bce24d59@linux.intel.com> <20220531145301.GE1343366@nvidia.com> From: Robin Murphy In-Reply-To: <20220531145301.GE1343366@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-05-31 15:53, Jason Gunthorpe wrote: > On Tue, May 31, 2022 at 10:11:18PM +0800, Baolu Lu wrote: >> On 2022/5/31 21:10, Jason Gunthorpe wrote: >>> On Tue, May 31, 2022 at 11:02:06AM +0800, Baolu Lu wrote: >>> >>>> For case 2, it is a bit weird. I tried to add a rwsem lock to make the >>>> iommu_unmap() and dumping tables in debugfs exclusive. This does not >>>> work because debugfs may depend on the DMA of the devices to work. It >>>> seems that what we can do is to allow this race, but when we traverse >>>> the page table in debugfs, we will check the validity of the physical >>>> address retrieved from the page table entry. Then, the worst case is to >>>> print some useless information. >>> >>> Sounds horrible, don't you have locking around the IOPTEs of some >>> kind? How does updating them work reliably? >> >> There's no locking around updating the IOPTEs. The basic assumption is >> that at any time, there's only a single thread manipulating the mappings >> of the range specified in iommu_map/unmap() APIs. Therefore, the race >> only exists when multiple ranges share some high-level IOPTEs. The IOMMU >> driver updates those IOPTEs using the compare-and-exchange atomic >> operation. > > Oh? Did I miss where that was documented as part of the iommu API? > > Daniel posted patches for VFIO to multi-thread iommu_domin mapping. > > iommufd goes out of its way to avoid this kind of serialization so > that userspace can parallel map IOVA. > > I think if this is the requirement then the iommu API needs to > provide a lock around the domain for the driver.. Eww, no, we can't kill performance by forcing serialisation on the entire API just for one silly driver-internal debugfs corner :( Robin.