Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755213AbcKBNjc (ORCPT ); Wed, 2 Nov 2016 09:39:32 -0400 Received: from mga01.intel.com ([192.55.52.88]:10087 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752978AbcKBNjb (ORCPT ); Wed, 2 Nov 2016 09:39:31 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,583,1473145200"; d="scan'208";a="26586630" Message-ID: <5819EBAB.3070308@intel.com> Date: Wed, 02 Nov 2016 21:35:39 +0800 From: Jike Song User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Kirti Wankhede CC: Alexey Kardashevskiy , alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.tian@intel.com, qemu-devel@nongnu.org, bjsdjshi@linux.vnet.ibm.com Subject: Re: [Qemu-devel] [PATCH v9 04/12] vfio iommu: Add support for mediated devices References: <1476739332-4911-1-git-send-email-kwankhede@nvidia.com> <1476739332-4911-5-git-send-email-kwankhede@nvidia.com> <62ade373-6edc-c7f3-c205-200cf4fd211f@nvidia.com> <45b517de-3766-e96b-fec0-2b77da4dcf8d@nvidia.com> <695ca09f-b332-d33a-22fb-073f03dfaebf@ozlabs.ru> <5819DA45.9000200@intel.com> <64066f1a-3d25-fede-f383-078b5f8f0fa0@nvidia.com> <5819E358.4080706@intel.com> <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> In-Reply-To: <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1743 Lines: 44 On 11/02/2016 09:18 PM, Kirti Wankhede wrote: > On 11/2/2016 6:30 PM, Jike Song wrote: >> On 11/02/2016 08:41 PM, Kirti Wankhede wrote: >>> On 11/2/2016 5:51 PM, Jike Song wrote: >>>> On 11/02/2016 12:09 PM, Alexey Kardashevskiy wrote: >>>>> Or you could just reference and use @mm as KVM and others do. Or there is >>>>> anything else you need from @current than just @mm? >>>>> >>>> >>>> I agree. If @mm is the only thing needed, there is really no reason to >>>> refer to the @task :-) >>>> >>> >>> In vfio_lock_acct(), that is for page accounting, if mm->mmap_sem is >>> already held then page accounting is deferred, where task structure is >>> used to get mm and work is deferred only if mm exist: >>> mm = get_task_mm(task); >>> >>> That is where this module need task structure. >> >> Kirti, >> >> By calling get_task_mm you hold a ref on @mm and save it in iommu, >> whenever you want to do something like vfio_lock_acct(), use that mm >> (as you said, if mmap_sem not accessible then defer it to a work, but >> still @mm is the whole information), and put it after the usage. >> >> I still can't see any reason that the @task have to be saved. It's >> always the @mm all the time. Did I miss anything? >> > > If the process is terminated by SIGKILL, as Alexey mentioned in this > mail thread earlier exit_mm() is called first and then all files are > closed. From exit_mm(), task->mm is set to NULL. So from teardown path, > we should call get_task_mm(task) to get current status intsead of using > stale pointer. You have got the ref on a task->mm and stored it somewhere, then after that at some time the task->mm was set to NULL -- what's exactly the problem here? It's perfectly okay per my understanding ... -- Thanks, Jike