Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp148644pxb; Mon, 25 Apr 2022 07:28:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk+OONbEMoo95XklbF5HoRJMrr+2aIHrkI5anjEYad7yqZaoveTqqyTyyzpOGU35fgIxeF X-Received: by 2002:a17:907:6e14:b0:6f0:1fc4:ff43 with SMTP id sd20-20020a1709076e1400b006f01fc4ff43mr16350794ejc.719.1650896921597; Mon, 25 Apr 2022 07:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650896921; cv=none; d=google.com; s=arc-20160816; b=PboZID2zA0xCI+XgkX6YzC/OhEUb7NsxhpoSzzlHcm7r7NRJhmi3upl0WbAW6CqYi4 DDpB61sojwCp4owakc229rVfjHViGD3gkiT7s1hugXkqnCTOp4s2FO4p4rbJXZ91lLvv CA9ykuJa6Q8LLGkwbAo4XPKOG3DX/0wBZQaJ/qdHx5NUNaU9QC1iMKMnORE8bJZUjUlj SBKq6fJnyg77LPlZaKEJAsQtpRSsbJLXvgP9tUXfCCzmSZu8U5pHH2dH/BxjMK3+y/WS ULdx/niyd35UsGGZngf6aofZJZQxc1emZPv4rLh44z50+tgMsA0CCtCUu4caVH3hRARe 4AhA== 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=6c3aet0vN7qGtKMl6s2c0/bYnshX6fpcEY6yEupqS/o=; b=h/VUs7ER9gTtppeh2uc7PNmBxV3CO5p3zBtUQJiV+RY5KxdG1+ss5ZgHBrfiqLCGie CQr7ud9MIUXTjLBBsr3BYKecvQAPjM5pr0BRxX9+A2UoXlV9MYSaiiDsSAPIJOpHOqhM nYLs2EJZTzToLq8IZJhF91TXBWqKbMOdTy4t/iYpkkYuf7xwh8cY1kMvL4BRMLUwznn/ hlDBE7DUbW1fOTv2yjuPX9n3l68VteoW4meQcw91yqcCCTP81mRs01VyM0Kap7Iirk75 b5pnI8Rc8FxrCyX8pahxcnxWgrNieb4VT16ynCK25atLVWTVSGcJXMU+ODl5WThI7jev oblQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gefvwP6r; 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 oy7-20020a170907104700b006f39b748c48si1958087ejb.229.2022.04.25.07.28.16; Mon, 25 Apr 2022 07:28:41 -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=gefvwP6r; 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 S242404AbiDYOTt (ORCPT + 99 others); Mon, 25 Apr 2022 10:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242378AbiDYOTs (ORCPT ); Mon, 25 Apr 2022 10:19:48 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE3CF1EEF6 for ; Mon, 25 Apr 2022 07:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650896204; x=1682432204; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=AAEEDt7xXTl7wGJqN1W/OSkx+JBqKQDu+fVaYieXLSM=; b=gefvwP6r1mZw50UfZMrTXr7xr5Y6X5vxgQesFgriQ/N3p+d3XzveoMZv 0Th/OJwNjY9nJZzcEoY6rD4K4rxRin2ZJ/cdbKd3K5EPrEca1vYu7k6mX BYTPLyPsfvAuX31V7T4vacrR2mxECno70k2blLl3nWA3UwwLXibmf24dB XsqnIp80cPTt3knafgtdAB6x8b8EL92UmrGUFBApy8d5wXsS4/9ioX1qH GiTxeHcclVC/As2KziAJN8ZxvtNl2SiBlPVjBvW2qHP6KDL1izHPJF1IE EYV8Ip+EMPTYEWcL+NFOWfhdG+iPdjXItfID9CyCbKNEAR3fr+pSv9Og2 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="265423517" X-IronPort-AV: E=Sophos;i="5.90,288,1643702400"; d="scan'208";a="265423517" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 07:16:44 -0700 X-IronPort-AV: E=Sophos;i="5.90,288,1643702400"; d="scan'208";a="595254808" Received: from bjkrist-mobl.amr.corp.intel.com (HELO [10.212.88.70]) ([10.212.88.70]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 07:16:43 -0700 Message-ID: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> Date: Mon, 25 Apr 2022 07:18:36 -0700 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 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Content-Language: en-US To: Jean-Philippe Brucker , "zhangfei.gao@foxmail.com" Cc: Fenghua Yu , Joerg Roedel , Ravi V Shankar , Tony Luck , Ashok Raj , Peter Zijlstra , Dave Hansen , x86 , linux-kernel , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , Thomas Gleixner , will@kernel.org, robin.murphy@arm.com, zhangfei.gao@linaro.org References: From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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 On 4/25/22 06:53, Jean-Philippe Brucker wrote: > On Sat, Apr 23, 2022 at 07:13:39PM +0800, zhangfei.gao@foxmail.com wrote: >>>> On 5.17 >>>> fops_release is called automatically, as well as iommu_sva_unbind_device. >>>> On 5.18-rc1. >>>> fops_release is not called, have to manually call close(fd) >>> Right that's weird >> Looks it is caused by the fix patch, via mmget, which may add refcount of >> fd. > Yes indirectly I think: when the process mmaps the queue, mmap_region() > takes a reference to the uacce fd. That reference is released either by > explicit close() or munmap(), or by exit_mmap() (which is triggered by > mmput()). Since there is an mm->fd dependency, we cannot add a fd->mm > dependency, so no mmget()/mmput() in bind()/unbind(). > > I guess we should go back to refcounted PASIDs instead, to avoid freeing > them until unbind(). Yeah, this is a bit gnarly for -rc4. Let's just make sure there's nothing else simple we can do. How does the IOMMU hardware know that all activity to a given PASID is finished? That activity should, today, be independent of an mm or a fd's lifetime.