Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1747186iob; Fri, 29 Apr 2022 11:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqzRHqECGn1/5SshYl/lJwjtol1cpH1xh7xftS8FZ5isUs3Dn7xFp7zVnIGgCa/jD76C9o X-Received: by 2002:a19:fc0e:0:b0:471:ff7d:ab35 with SMTP id a14-20020a19fc0e000000b00471ff7dab35mr419016lfi.345.1651258278536; Fri, 29 Apr 2022 11:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651258278; cv=none; d=google.com; s=arc-20160816; b=FEPNsbqx0qa9VzuvcFglZLIGZiHVgFqT52W1ErSeH3Ltk0YWKGCVJscfcLYCCRO5rT 5phW8VaslR2yepFboCHruXARAVJZb9FB7+lN3cSfwFYmiQfSZLZgjUaqS9LQz1wgh4W5 pftgl20af/wXZ1UJnUgGdbLoi5oyBRNmqh5d5cD/Wmg+E1HcBpCgOhUNbaYPY41A+2aI 1yBgCTOIFA0xa81RFyFjhuaIMgKaVc8QVvJnlsTwAmpfaiZAGwTo+BHJBlzBUi3iqxiB fQE7AqlWRAaIL5K14czljG5cDMSi6BBG0mu6flqFrDJkPYGmTsRuk/mrZXYCa7lYAJPQ 2eZA== 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:dkim-signature; bh=brf9rcgOsFBmHAxW7cDBPdTWHrzWteYxEnAKRhOK7ho=; b=UoTrwzEvkjXRKBFg4iroCCHZ46lvigZkcc4xKV6zLPN9XVqOLmqOMlFTYp/c213bT+ Dz+WiuVNBhW5tmVPkCb1WEewvAougzIOKiHfHyPf4NYBTkPzmjcBPdkxSluAYFxyxzri rvgkS+MLzhk/HksVnR3aIs855Di3vft4THKxnclseig0yCOakqg1N+TrsEL+/XGt3sXt x2FXXFa2J1yKVgfd05XfmFdcrsrLtKof1UoUicc0kIVnzMAIlbyCBhwRp4fqbFgrfyTD acdqsUiZPW59A6qD1WhFSG4Xt4ZJXJeoYh7QowzfBBUfUT7McB/hzpmHFBNTQomwvIiO 5hmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XDY6thVH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a2e3e13000000b0024f0f4146c9si7530434lja.484.2022.04.29.11.50.51; Fri, 29 Apr 2022 11:51:18 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=XDY6thVH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354481AbiD2GUv (ORCPT + 99 others); Fri, 29 Apr 2022 02:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbiD2GUq (ORCPT ); Fri, 29 Apr 2022 02:20:46 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB1E82180A for ; Thu, 28 Apr 2022 23:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651213048; x=1682749048; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Ti68k/z1JomTVPNNM6IUrCDfU5XGG1j6rnK5v6KWG4c=; b=XDY6thVHodQGRImHhaWEKKwTJBSKmQpsFxKIQhEySnW7WbuUONNZQ2D/ /Uw0JaMn6noB4HJNaLzziWaIa+hyshudpxemtDdx0vLbo6UXI2BmtK3VO NaHBErH/r6xWn7qTViOVtQ0tMDDTptXBeNWFRUwpJbT4B7yA0u5l5B/VJ E0KEy/qONEYTPfKQEQ0xg2EnmYoZaul1wT+ZM6LvA7TyeIeQkgmeYAL9n S+st6mGHaVeXlfFOE3ZTtyiFQeUAGsWiEKU9G0YFGRWFPFugCm+UEOoxI KehViIHsWlMT7K1OkIa52nn0hLToowvEhJwMG+SIzhKNZRhRO/9nfmiuL A==; X-IronPort-AV: E=McAfee;i="6400,9594,10331"; a="253929554" X-IronPort-AV: E=Sophos;i="5.91,297,1647327600"; d="scan'208";a="253929554" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2022 23:17:28 -0700 X-IronPort-AV: E=Sophos;i="5.91,297,1647327600"; d="scan'208";a="581917186" Received: from lye4-mobl.ccr.corp.intel.com (HELO [10.249.170.95]) ([10.249.170.95]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2022 23:17:25 -0700 Message-ID: Date: Fri, 29 Apr 2022 14:17:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v4 10/12] iommu: Prepare IOMMU domain for IOPF Content-Language: en-US To: Jean-Philippe Brucker Cc: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20220421052121.3464100-1-baolu.lu@linux.intel.com> <20220421052121.3464100-11-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 Hi Jean, On 2022/4/28 22:47, Jean-Philippe Brucker wrote: > Hi Baolu, > > On Thu, Apr 21, 2022 at 01:21:19PM +0800, Lu Baolu wrote: >> +/* >> + * Get the attached domain for asynchronous usage, for example the I/O >> + * page fault handling framework. The caller get a reference counter >> + * of the domain automatically on a successful return and should put >> + * it with iommu_domain_put() after usage. >> + */ >> +struct iommu_domain * >> +iommu_get_domain_for_dev_pasid_async(struct device *dev, ioasid_t pasid) >> +{ >> + struct iommu_domain *domain; >> + struct iommu_group *group; >> + >> + if (!pasid_valid(pasid)) >> + return NULL; >> + >> + group = iommu_group_get(dev); >> + if (!group) >> + return NULL; >> + >> + mutex_lock(&group->mutex); > > There is a possible deadlock between unbind() and the fault handler: > > unbind() iopf_handle_group() > mutex_lock(&group->mutex) > iommu_detach_device_pasid() > iopf_queue_flush_dev() iommu_get_domain_for_dev_pasid_async() > ... waits for IOPF work mutex_lock(&group->mutex) > Yes, really. > I was wrong in my previous review: we do have a guarantee that the SVA > domain does not go away during IOPF handling, because unbind() waits for > pending faults with iopf_queue_flush_dev() before freeing the domain (or > for Arm stall, knows that there are no pending faults). So we can just get > rid of domain->async_users and the group->mutex in IOPF, I think? Agreed with you. The Intel code does the same thing in its unbind(). Thus, the sva domain's life cycle has already synchronized with IOPF handling, there's no need for domain->async. I will drop it in the next version. Thanks you! Best regards, baolu