Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3788689ioa; Tue, 26 Apr 2022 09:53:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9fGM4AyYlw/0vW7IWC5RVU+X/DSzDDsk/GSJO8r3pGPtpqbV1W24SCPh10vtTGaHS5Hb8 X-Received: by 2002:a17:902:9044:b0:15d:1c51:5bef with SMTP id w4-20020a170902904400b0015d1c515befmr10164858plz.170.1650992018609; Tue, 26 Apr 2022 09:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650992018; cv=none; d=google.com; s=arc-20160816; b=uRLXP4dBf/q/UiWlYqv7FT7I+ktDmFB+makAj4pF3K40b+7Ft6xhCM2K9/cPJdXCzv vYvuSfKLYQk4167J2eTV5fh6jr9XpYYEKJ0RrDAxpEjJwYiCsqOmmsYoHekjTzCATTqu AQW5WsF7TOo9oQSH9TUqHxvpMUkAXTBw3NEc+uvfMe+zyBAaA1chX0FVTF6XgmJ/00qc gaAjN/5GPkM4RaoagWu+gIh4CguwmEt74rjpWn6/4kJXSU3s2wXSRSt4KadHAnWTDMeb h++mHAGG9daZsw12jDzilkC8ljlkTenw3Ffi2GeasXp7dIMr0jryn61/UIdODf14f6V9 GVGQ== 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=Q4trkPH+NcCaiqrokLOPTour7LKww1q8MXI70oRGb58=; b=vvdxewMoXkhVW4HwcqpSi/+5zX8OwdM20xLZoyRftwqZWvS1Zg//pTnqmFio3qmFIj Js7kd7fai2m5E7aZjam5MSsQdbFtyxftvkYXFLGgr5uGojAiNgG0I5vIwIsEM3UYyWHl 750QoZonvbvdKA4S408oOMyeln0AOACGT2qVfiO28zatR0A/8jjrcsucEC/OPT0XEC/v iVJ06RnmQK8sfeAoXtoNctc99nGv14c00Mp4Q4G4k6224csj8FpGoO6vfaKTq9sG0krv 3ZU/tY+ptStkFxAsp4TOr/TeKAb2NuoRshlwMItkdyp3m21l1wYX5QpK/DBdE6svsNgx 5ocw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QImM3OXY; 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 j14-20020a056a00174e00b0050a5b06241bsi14966873pfc.95.2022.04.26.09.53.20; Tue, 26 Apr 2022 09:53:38 -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=QImM3OXY; 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 S230189AbiDYWdC (ORCPT + 99 others); Mon, 25 Apr 2022 18:33:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235531AbiDYWcr (ORCPT ); Mon, 25 Apr 2022 18:32:47 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 821635F4C for ; Mon, 25 Apr 2022 15:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650925727; x=1682461727; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1ugjOgr21LoYin4+k0APKTjfPQTfZoLklmrGidKyQsk=; b=QImM3OXY6yV3XkCZero2+mq/1tO0f7hnX5FdlB0/mm/1zvkjaAwjwZOE gpvG41xbsFQ1wnEZh3T+Mn/XQ6nVuplJfMllS0KAWA3Qkh9/sNeNDz+UG UI1MXkm5RQRXYNgpbiSZaRZynABcC+yP0+/sMA1wDVSvHDbIcYftzlGi6 92bmV72Zqgs/DJIN700LgzxmAY3cnw305EZD3yyf0c/y7O1/nnGHxPgCw KY9U4Bwtz3P5P+blgBZ5FwazjsWEPfwW4HyyEFHgMePMuPJJWvU7fwsh4 //9O5ImlVsqAgPfe2aNpc8s15Xv/3bXg7pj0XPx993WrYUMyeTA1csMDr A==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="262977222" X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="262977222" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 15:28:46 -0700 X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="729945823" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.198.157]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 15:28:46 -0700 Date: Mon, 25 Apr 2022 15:32:23 -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: <20220425153223.62a02645@jacob-builder> In-Reply-To: References: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> <20220425083444.00af5674@jacob-builder> 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=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 Hi Jean-Philippe, On Mon, 25 Apr 2022 17:13:02 +0100, Jean-Philippe Brucker wrote: > Hi Jacob, > > On Mon, Apr 25, 2022 at 08:34:44AM -0700, Jacob Pan wrote: > > 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"? > > Yes we do have that state, though I'm not sure we need to make it explicit > in the ioasid allocator. > IMHO, making it explicit would fail ioasid_get() on a "pending free" PASID. Making free a one-way trip and prevent further complications. > Could we move mm_pasid_drop() to __mmdrop() instead of __mmput()? For Arm > we do need to hold the mm_count until unbind(), and mmgrab()/mmdrop() is > also part of Lu's rework [1]. > Yes, I would agree. IIRC, Fenghua's early patch was doing pasid drop in mmdrop. Maybe I missed something. > Thanks, > Jean > > [1] > https://lore.kernel.org/linux-iommu/20220421052121.3464100-9-baolu.lu@linux.intel.com/ Thanks, Jacob