Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3341090ioa; Tue, 26 Apr 2022 01:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzadspmlsO+6lKZ8N7Tp8vMBTZ4/dRqyVavGqcqVU2wgLgqSNbV6j4Xb88hjbF2qWnK8qr9 X-Received: by 2002:a65:6a07:0:b0:39d:8c35:426b with SMTP id m7-20020a656a07000000b0039d8c35426bmr18791999pgu.171.1650961966046; Tue, 26 Apr 2022 01:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650961966; cv=none; d=google.com; s=arc-20160816; b=vMaLoCvAa2FW/OlqVauwRkAMcSiDPpGKIEUu54lcWhz4MTk7f5j0bEC8zZoM6tucwE /9AdIVXqYmL/sczK3hdl3TttLqTaxoGHajqvS1g5Ezj7JIpYJeQfEX6SWtrKMZNPQaWw 8rc4mspW6TwbljB3v2B09KMWB5gz/eRrFzP1ao1wlDxIKKhLmQ7Z8yWxwbnsW4A7Q0JJ gbi+t1bqViWm2TlSM6RV9neok6x2jRklGE9YGSzrdA9KrA4YAsDBBxXCt3VYeAtXGnjZ N008X8EE+PIy9ICM8E/CXSm6CFJ0H1D83WF+Qtrd+UZxf63QXj/xjjW1ikkzPaB2+/vP uXjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=5yUZQImmKoI63KA9PDVyUV6x1eurzGWGymql6AtnKZ8=; b=BTkcCD7aNJEm46MIybDMrF/YTywJ2Pu53stExaAFzTgFnzvLQR5IGPa9eOZYS47kJY eoh7KisRiNfhiVpAvlPEF4NQ9ejGm4nbIMHM/PNWikJWOOC7ynwxQWuJP20sVEa8/nwA HqfLTIF0IbjnvVqQYHDiWPbSFugDBLfb2OmcKTH8PJVhrSu0ZOGZqB1jnSVaw3zRZn22 2wOlyqDnsAxM+GfQIfqQuMMqB6x2KB5qioankMcPvdlm8QXy4mCyDMvRKF82atCCGOtQ uBDwAPYSmN1gUj3pYnVJXKbuOkmBfjJCuxCs1l6gQ9WgOLVms4xkSD7gUNXMtsntJJVb N7Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nEFkiNRG; 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 d17-20020a63f251000000b003aad07ba5c7si11394368pgk.13.2022.04.26.01.32.31; Tue, 26 Apr 2022 01:32:46 -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=nEFkiNRG; 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 S240222AbiDYPeQ (ORCPT + 99 others); Mon, 25 Apr 2022 11:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233191AbiDYPeP (ORCPT ); Mon, 25 Apr 2022 11:34:15 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63BAF21E10 for ; Mon, 25 Apr 2022 08:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650900671; x=1682436671; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QmBvHFEL8jCRZp/04JCJNkoj3kFPY6FDP8vzsw7y6UI=; b=nEFkiNRGu6R/J+fU6DJzljwldao92uHfDZvnSuUkUcAsGFt5o+IE6upm bsXjlqRUMEe0SxyXKgH31TG/kCffDxRUBUP3OWRl5EBvcBpUaxrUnnrdf x6vz5BRfZdqWGLgomlrF0LXUMLU8fZjd+I1fv8+536f1/HOg2Fu+IiMJN tDuc++1cBxN+V7kNOg16DNl3mIvZjVYJATHq3Mbqv+W/5Pql2xx6E6zwV WaxYd7Hga2vCXpjw/frhl2AvN3iDR6IEXOw6dI/O3ti6fitR1kYaVx2t6 jO5J7tujm7qGr6Gmpr4MDhMIqOeg6fk+wz6avjmS7FRJ/tZmT9Os/FU/t Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="247208240" X-IronPort-AV: E=Sophos;i="5.90,288,1643702400"; d="scan'208";a="247208240" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 08:31:07 -0700 X-IronPort-AV: E=Sophos;i="5.90,288,1643702400"; d="scan'208";a="579340231" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.198.157]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 08:31:06 -0700 Date: Mon, 25 Apr 2022 08:34:44 -0700 From: Jacob Pan To: Jean-Philippe Brucker Cc: Dave Hansen , Fenghua Yu , Tony Luck , Ashok Raj , Ravi V Shankar , Peter Zijlstra , robin.murphy@arm.com, Dave Hansen , x86 , linux-kernel , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , zhangfei.gao@linaro.org, Thomas Gleixner , will@kernel.org, jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Message-ID: <20220425083444.00af5674@jacob-builder> In-Reply-To: References: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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-Philippe, On Mon, 25 Apr 2022 15:26:40 +0100, Jean-Philippe Brucker wrote: > On Mon, Apr 25, 2022 at 07:18:36AM -0700, Dave Hansen wrote: > > 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. > > In the case of uacce, it's tied to the fd lifetime: opening an accelerator > queue calls iommu_sva_bind_device(), which sets up the PASID context in > the IOMMU. Closing the queue calls iommu_sva_unbind_device() which > destroys the PASID context (after the device driver stopped all DMA for > this PASID). > For VT-d, it is essentially the same flow except managed by the individual drivers such as DSA. If free() happens before unbind(), we deactivate the PASIDs and suppress faults from the device. When the unbind finally comes, we finalize the PASID teardown. It seems we have a need for an intermediate state where PASID is "pending free"? > Thanks, > Jean > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu Thanks, Jacob